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