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 
8 
9 namespace reco { namespace tau { namespace xclean {
10 
12 template<typename PtrIter>
14  public:
15  typedef std::vector<RecoTauPiZero> PiZeroList;
16 
17  CrossCleanPiZeros(PtrIter signalTracksBegin, PtrIter signalTracksEnd) {
18  // Get the list of objects we need to clean
19  for (PtrIter i = signalTracksBegin; i != signalTracksEnd; ++i) {
20  toRemove_.insert(reco::CandidatePtr(*i));
21  }
22  }
23 
27  PiZeroList operator()(const std::vector<RecoTauPiZero> &input) const {
29  output.reserve(input.size());
30  BOOST_FOREACH(const RecoTauPiZero& piZero, input) {
31  const RecoTauPiZero::daughters& daughters = piZero.daughterPtrVector();
32  std::set<reco::CandidatePtr> toCheck(daughters.begin(), daughters.end());
33  std::vector<reco::CandidatePtr> cleanDaughters;
34  std::set_difference(toCheck.begin(), toCheck.end(),
35  toRemove_.begin(), toRemove_.end(), std::back_inserter(cleanDaughters));
36  if (cleanDaughters.size() == daughters.size()) {
37  // We don't need to clean anything, just add a pointer to current cnad
38  output.push_back(piZero);
39  } else {
40  // Otherwise rebuild
41  RecoTauPiZero newPiZero = piZero;
42  newPiZero.clearDaughters();
43  // Add our cleaned daughters.
44  BOOST_FOREACH(const reco::CandidatePtr& ptr, cleanDaughters) {
45  newPiZero.addDaughter(ptr);
46  }
47  // Check if the pizero is not empty. If empty, forget it.
48  if (newPiZero.numberOfDaughters()) {
49  p4Builder_.set(newPiZero);
50  // Make our ptr container take ownership.
51  output.push_back(newPiZero);
52  }
53  }
54  }
55  return output;
56  }
57 
58  private:
60  std::set<reco::CandidatePtr> toRemove_;
61 };
62 
63 // Predicate to filter PFCandPtrs (and those compatible to this type) by the
64 // particle id
66  public:
67  FilterPFCandByParticleId(int particleId):
68  id_(particleId){};
69  template<typename PFCandCompatiblePtrType>
70  bool operator()(const PFCandCompatiblePtrType& ptr) const {
71  PFCandidatePtr pfptr(ptr);
72  return ptr->particleId() == id_;
73  }
74  private:
75  int id_;
76 };
77 
78 // Determine if a candidate is contained in a collection of PiZeros.
80  public:
81  CrossCleanPtrs(const std::vector<reco::RecoTauPiZero> &piZeros) {
82  BOOST_FOREACH(const PFCandidatePtr &ptr, flattenPiZeros(piZeros)) {
83  toRemove_.insert(CandidatePtr(ptr));
84  }
85  }
86 
87  template<typename AnyPtr>
88  bool operator() (const AnyPtr& ptr) const {
89  if (toRemove_.count(CandidatePtr(ptr)))
90  return false;
91  else
92  return true;
93  }
94  private:
95  std::set<CandidatePtr> toRemove_;
96 };
97 
98 // Create the AND of two predicates
99 template<typename P1, typename P2>
101  public:
102  PredicateAND(const P1& p1, const P2& p2):
103  p1_(p1),p2_(p2){}
104 
105  template<typename AnyPtr>
106  bool operator() (const AnyPtr& ptr) const {
107  return p1_(ptr) && p2_(ptr);
108  }
109  private:
110  const P1& p1_;
111  const P2& p2_;
112 };
113 
114 // Helper function to infer template type
115 template<typename P1, typename P2>
117  return PredicateAND<P1, P2>(p1, p2);
118 }
119 
120 }}}
121 #endif
std::vector< RecoTauPiZero > PiZeroList
int i
Definition: DBlmapReader.cc:9
std::vector< PFCandidatePtr > flattenPiZeros(const std::vector< RecoTauPiZero > &)
Flatten a list of pi zeros into a list of there constituent PFCandidates.
bool operator()(const AnyPtr &ptr) const
CrossCleanPtrs(const std::vector< reco::RecoTauPiZero > &piZeros)
PiZeroList operator()(const std::vector< RecoTauPiZero > &input) const
virtual size_t numberOfDaughters() const
number of daughters
double p2[4]
Definition: TauolaWrapper.h:90
std::vector< CandidatePtr > daughters
collection of references to daughters
edm::Ptr< Candidate > CandidatePtr
persistent reference to an object in a collection of Candidate objects
Definition: CandidateFwd.h:25
CrossCleanPiZeros(PtrIter signalTracksBegin, PtrIter signalTracksEnd)
bool operator()(const AnyPtr &ptr) const
void clearDaughters()
clear daughter references
double p1[4]
Definition: TauolaWrapper.h:89
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
std::set< CandidatePtr > toRemove_
std::set< reco::CandidatePtr > toRemove_
Transform a pizero to remove given candidates.
PredicateAND< P1, P2 > makePredicateAND(const P1 &p1, const P2 &p2)