CMS 3D CMS Logo

RecoTauCrossCleaning.h
Go to the documentation of this file.
1 #ifndef RecoTauTag_RecoTau_RecoTauCrossCleaning_h
2 #define RecoTauTag_RecoTau_RecoTauCrossCleaning_h
3 
9 
10 namespace reco::tau::xclean {
11 
13  template <typename PtrIter>
15  public:
16  typedef std::vector<RecoTauPiZero> PiZeroList;
17 
18  CrossCleanPiZeros(const PtrIter& chargedHadronsBegin,
19  const PtrIter& chargedHadronsEnd,
21  : mode_(mode) {
22  initialize(chargedHadronsBegin, chargedHadronsEnd);
23  }
24 
25  void initialize(const PtrIter& chargedHadronsBegin, const PtrIter& chargedHadronsEnd) {
26  // CV: make sure this never gets called.
27  assert(0);
28  }
29 
33  PiZeroList operator()(const std::vector<RecoTauPiZero>& input) const {
35  output.reserve(input.size());
36  for (auto const& piZero : input) {
37  const RecoTauPiZero::daughters& daughters = piZero.daughterPtrVector();
38  std::set<reco::CandidatePtr> toCheck(daughters.begin(), daughters.end());
39  std::vector<reco::CandidatePtr> cleanDaughters;
41  toCheck.begin(), toCheck.end(), toRemove_.begin(), toRemove_.end(), std::back_inserter(cleanDaughters));
42  if (cleanDaughters.size() == daughters.size()) {
43  // We don't need to clean anything, just add a pointer to current pizero
44  output.push_back(piZero);
45  } else {
46  // Otherwise rebuild
47  RecoTauPiZero newPiZero = piZero;
48  newPiZero.clearDaughters();
49  // Add our cleaned daughters.
50  for (auto const& ptr : cleanDaughters) {
51  newPiZero.addDaughter(ptr);
52  }
53  // Check if the pizero is not empty. If empty, forget it.
54  if (newPiZero.numberOfDaughters()) {
55  p4Builder_.set(newPiZero);
56  // Make our ptr container take ownership.
57  output.push_back(newPiZero);
58  }
59  }
60  }
61  return output;
62  }
63 
65 
66  private:
67  int mode_;
69  std::set<reco::CandidatePtr> toRemove_;
70  };
71 
72  // Determine if a candidate is contained in a collection of charged hadrons or pizeros.
73  template <typename PtrIter>
75  public:
76  CrossCleanPtrs(const PtrIter& particlesBegin, const PtrIter& particlesEnd) {
77  initialize(particlesBegin, particlesEnd);
78  }
79 
80  void initialize(const PtrIter& particlesBegin, const PtrIter& particlesEnd) {
81  // CV: make sure this never gets called.
82  assert(0);
83  }
84 
85  template <typename AnyPtr>
86  bool operator()(const AnyPtr& ptr) const {
87  if (toRemove_.count(CandidatePtr(ptr)))
88  return false;
89  else
90  return true;
91  }
92 
93  private:
94  std::set<CandidatePtr> toRemove_;
95  };
96 
97  // Predicate to filter PFCandPtrs (and those compatible to this type) by the
98  // particle id
100  public:
101  FilterPFCandByParticleId(int particleId) : id_(particleId){};
102  template <typename PFCandCompatiblePtrType>
103  bool operator()(const PFCandCompatiblePtrType& ptr) const {
104  return ptr->particleId() == id_;
105  }
106 
107  private:
108  int id_;
109  };
110 
111  // Predicate to filter CandPtrs by the abs(pdgId)
113  public:
115  template <typename CandCompatiblePtrType>
116  bool operator()(const CandCompatiblePtrType& ptr) const {
117  return std::abs(ptr->pdgId()) == id_;
118  }
119 
120  private:
121  int id_;
122  };
123 
124  // Create the AND of two predicates
125  template <typename P1, typename P2>
126  class PredicateAND {
127  public:
128  PredicateAND(const P1& p1, const P2& p2) : p1_(p1), p2_(p2) {}
129 
130  template <typename AnyPtr>
131  bool operator()(const AnyPtr& ptr) const {
132  return (p1_(ptr) && p2_(ptr));
133  }
134 
135  private:
136  const P1& p1_;
137  const P2& p2_;
138  };
139 
140  // Helper function to infer template type
141  template <typename P1, typename P2>
142  PredicateAND<P1, P2> makePredicateAND(const P1& p1, const P2& p2) {
143  return PredicateAND<P1, P2>(p1, p2);
144  }
145 
146 } // namespace reco::tau::xclean
147 
148 #endif
std::vector< RecoTauPiZero > PiZeroList
void set(reco::Candidate &c) const
set up a candidate
bool operator()(const PFCandCompatiblePtrType &ptr) const
bool operator()(const AnyPtr &ptr) const
assert(be >=bs)
static std::string const input
Definition: EdmProvDump.cc:47
CrossCleanPtrs(const PtrIter &particlesBegin, const PtrIter &particlesEnd)
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::set< CandidatePtr > toRemove_
virtual void clearDaughters()
clear daughter references
void initialize(const PtrIter &chargedHadronsBegin, const PtrIter &chargedHadronsEnd)
std::vector< CandidatePtr > daughters
collection of references to daughters
size_t numberOfDaughters() const override
number of daughters
bool operator()(const AnyPtr &ptr) const
PiZeroList operator()(const std::vector< RecoTauPiZero > &input) const
CrossCleanPiZeros(const PtrIter &chargedHadronsBegin, const PtrIter &chargedHadronsEnd, int mode=kRemoveChargedAndNeutralDaughterOverlaps)
bool operator()(const CandCompatiblePtrType &ptr) const
void addDaughter(const CandidatePtr &)
add a daughter via a reference
PredicateAND(const P1 &p1, const P2 &p2)
void initialize(const PtrIter &particlesBegin, const PtrIter &particlesEnd)
std::set< reco::CandidatePtr > toRemove_
std::vector< std::string > set_difference(std::vector< std::string > const &v1, std::vector< std::string > const &v2)
Transform a pizero to remove given candidates.
PredicateAND< P1, P2 > makePredicateAND(const P1 &p1, const P2 &p2)