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;
40  std::set_difference(
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
reco::tau::xclean::CrossCleanPiZeros
Transform a pizero to remove given candidates.
Definition: RecoTauCrossCleaning.h:14
reco::tau::xclean::FilterCandByAbsPdgId::id_
int id_
Definition: RecoTauCrossCleaning.h:121
reco::tau::xclean::CrossCleanPtrs::initialize
void initialize(const PtrIter &particlesBegin, const PtrIter &particlesEnd)
Definition: RecoTauCrossCleaning.h:80
input
static const std::string input
Definition: EdmProvDump.cc:48
reco::tau::xclean::CrossCleanPiZeros::kRemoveChargedAndNeutralDaughterOverlaps
Definition: RecoTauCrossCleaning.h:64
reco::tau::xclean::PredicateAND::p2_
const P2 & p2_
Definition: RecoTauCrossCleaning.h:137
convertSQLitetoXML_cfg.output
output
Definition: convertSQLitetoXML_cfg.py:32
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
reco::tau::xclean::PredicateAND::PredicateAND
PredicateAND(const P1 &p1, const P2 &p2)
Definition: RecoTauCrossCleaning.h:128
cms::cuda::assert
assert(be >=bs)
reco::tau::xclean::FilterPFCandByParticleId::FilterPFCandByParticleId
FilterPFCandByParticleId(int particleId)
Definition: RecoTauCrossCleaning.h:101
reco::tau::xclean::CrossCleanPiZeros::kRemoveChargedDaughterOverlaps
Definition: RecoTauCrossCleaning.h:64
reco::tau::xclean::FilterPFCandByParticleId::operator()
bool operator()(const PFCandCompatiblePtrType &ptr) const
Definition: RecoTauCrossCleaning.h:103
RecoTauPiZero.h
CompositePtrCandidate.h
BPhysicsValidation_cfi.daughters
daughters
Definition: BPhysicsValidation_cfi.py:11
reco::tau::xclean::CrossCleanPtrs::CrossCleanPtrs
CrossCleanPtrs(const PtrIter &particlesBegin, const PtrIter &particlesEnd)
Definition: RecoTauCrossCleaning.h:76
reco::tau::xclean::CrossCleanPiZeros::PiZeroList
std::vector< RecoTauPiZero > PiZeroList
Definition: RecoTauCrossCleaning.h:16
p2
double p2[4]
Definition: TauolaWrapper.h:90
reco::tau::xclean
Definition: RecoTauCrossCleaning.h:10
reco::tau::xclean::makePredicateAND
PredicateAND< P1, P2 > makePredicateAND(const P1 &p1, const P2 &p2)
Definition: RecoTauCrossCleaning.h:142
reco::tau::xclean::CrossCleanPtrs
Definition: RecoTauCrossCleaning.h:74
reco::tau::xclean::FilterCandByAbsPdgId::FilterCandByAbsPdgId
FilterCandByAbsPdgId(int pdgId)
Definition: RecoTauCrossCleaning.h:114
reco::tau::xclean::CrossCleanPiZeros::operator()
PiZeroList operator()(const std::vector< RecoTauPiZero > &input) const
Definition: RecoTauCrossCleaning.h:33
reco::tau::xclean::FilterPFCandByParticleId::id_
int id_
Definition: RecoTauCrossCleaning.h:108
reco::tau::xclean::FilterCandByAbsPdgId
Definition: RecoTauCrossCleaning.h:112
reco::tau::xclean::CrossCleanPiZeros::p4Builder_
AddFourMomenta p4Builder_
Definition: RecoTauCrossCleaning.h:68
reco::tau::xclean::CrossCleanPiZeros::toRemove_
std::set< reco::CandidatePtr > toRemove_
Definition: RecoTauCrossCleaning.h:69
AddFourMomenta.h
p1
double p1[4]
Definition: TauolaWrapper.h:89
EgammaValidation_cff.pdgId
pdgId
Definition: EgammaValidation_cff.py:118
reco::CompositePtrCandidate::clearDaughters
virtual void clearDaughters()
clear daughter references
Definition: CompositePtrCandidate.h:59
reco::tau::xclean::PredicateAND::operator()
bool operator()(const AnyPtr &ptr) const
Definition: RecoTauCrossCleaning.h:131
reco::tau::xclean::FilterPFCandByParticleId
Definition: RecoTauCrossCleaning.h:99
reco::tau::xclean::CrossCleanPiZeros::mode_
int mode_
Definition: RecoTauCrossCleaning.h:67
reco::CompositePtrCandidate::daughters
std::vector< CandidatePtr > daughters
collection of references to daughters
Definition: CompositePtrCandidate.h:20
reco::CompositePtrCandidate::numberOfDaughters
size_t numberOfDaughters() const override
number of daughters
Definition: CompositePtrCandidate.cc:18
edm::Ptr< Candidate >
reco::RecoTauPiZero
Definition: RecoTauPiZero.h:7
AddFourMomenta::set
void set(reco::Candidate &c) const
set up a candidate
Definition: AddFourMomenta.cc:6
reco::tau::xclean::PredicateAND::p1_
const P1 & p1_
Definition: RecoTauCrossCleaning.h:136
PFRecoTauChargedHadron.h
AddFourMomenta
Definition: AddFourMomenta.h:18
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
reco::tau::xclean::CrossCleanPtrs::toRemove_
std::set< CandidatePtr > toRemove_
Definition: RecoTauCrossCleaning.h:94
reco::tau::xclean::PredicateAND
Definition: RecoTauCrossCleaning.h:126
reco::tau::xclean::CrossCleanPtrs::operator()
bool operator()(const AnyPtr &ptr) const
Definition: RecoTauCrossCleaning.h:86
reco::CompositePtrCandidate::addDaughter
void addDaughter(const CandidatePtr &)
add a daughter via a reference
Definition: CompositePtrCandidate.h:84
reco::tau::xclean::CrossCleanPiZeros::CrossCleanPiZeros
CrossCleanPiZeros(const PtrIter &chargedHadronsBegin, const PtrIter &chargedHadronsEnd, int mode=kRemoveChargedAndNeutralDaughterOverlaps)
Definition: RecoTauCrossCleaning.h:18
reco::tau::xclean::CrossCleanPiZeros::initialize
void initialize(const PtrIter &chargedHadronsBegin, const PtrIter &chargedHadronsEnd)
Definition: RecoTauCrossCleaning.h:25
PFCandidateFwd.h
reco::tau::xclean::FilterCandByAbsPdgId::operator()
bool operator()(const CandCompatiblePtrType &ptr) const
Definition: RecoTauCrossCleaning.h:116