test
CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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  {
39  output.reserve(input.size());
40  BOOST_FOREACH( const RecoTauPiZero& piZero, input ) {
41  const RecoTauPiZero::daughters& daughters = piZero.daughterPtrVector();
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  PFCandidatePtr pfptr(ptr);
110  return ptr->particleId() == id_;
111  }
112  private:
113  int id_;
114 };
115 
116 // Create the AND of two predicates
117 template<typename P1, typename P2>
119  public:
120  PredicateAND(const P1& p1, const P2& p2):
121  p1_(p1),p2_(p2){}
122 
123  template<typename AnyPtr>
124  bool operator() (const AnyPtr& ptr) const {
125  return (p1_(ptr) && p2_(ptr));
126  }
127  private:
128  const P1& p1_;
129  const P2& p2_;
130 };
131 
132 // Helper function to infer template type
133 template<typename P1, typename P2>
135  return PredicateAND<P1, P2>(p1, p2);
136 }
137 
138 }}}
139 
140 #endif
std::vector< RecoTauPiZero > PiZeroList
bool operator()(const AnyPtr &ptr) const
PiZeroList operator()(const std::vector< RecoTauPiZero > &input) const
static std::string const input
Definition: EdmProvDump.cc:44
virtual size_t numberOfDaughters() const
number of daughters
CrossCleanPtrs(const PtrIter &particlesBegin, const PtrIter &particlesEnd)
std::set< CandidatePtr > toRemove_
double p2[4]
Definition: TauolaWrapper.h:90
void initialize(const PtrIter &chargedHadronsBegin, const PtrIter &chargedHadronsEnd)
std::vector< CandidatePtr > daughters
collection of references to daughters
bool operator()(const AnyPtr &ptr) const
void clearDaughters()
clear daughter references
double p1[4]
Definition: TauolaWrapper.h:89
CrossCleanPiZeros(const PtrIter &chargedHadronsBegin, const PtrIter &chargedHadronsEnd, int mode=kRemoveChargedAndNeutralDaughterOverlaps)
const daughters & daughterPtrVector() const
references to daughtes
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)