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