CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
RecoTauDiscriminantFunctions.cc
Go to the documentation of this file.
4 #include <algorithm>
8 #include <boost/foreach.hpp>
9 
10 namespace reco { namespace tau { namespace disc {
11 
12 // Helper functions
13 namespace {
14 
15 const PFCandidate& removeRef(const PFCandidatePtr& pfRef) {
16  return *pfRef;
17 }
18 
19 const RecoTauPiZero& removeRef(const RecoTauPiZero& piZero) {
20  return piZero;
21 }
22 
23 // Function = A PFTau member function
24 template<typename Collection, typename Function>
25 VDouble extract(const Collection& cands, Function func) {
26  // #define CALL_MEMBER_FN(object,ptrToMember) ((object).*(ptrToMember))
28  output.reserve(cands.size());
29  for(typename Collection::const_iterator cand = cands.begin();
30  cand != cands.end(); ++cand) {
31  output.push_back(func(removeRef(*cand)));
32  }
33  return output;
34 }
35 
36 class DeltaRToAxis {
37  public:
38  DeltaRToAxis(const reco::Candidate::LorentzVector& axis):axis_(axis){}
39  double operator()(const Candidate& cand)
40  {
41  return deltaR(cand.p4(), axis_);
42  }
43  private:
45 };
46 
47 } // end helper functions
48 
50  if (tau.signalPFChargedHadrCands().size() == 3) {
51  for (size_t itrk = 0; itrk < 3; ++itrk) {
52  if (tau.signalPFChargedHadrCands()[itrk]->charge() * tau.charge() < 0)
53  return tau.signalPFChargedHadrCands()[itrk];
54  }
55  }
56  return tau.leadPFChargedHadrCand();
57 }
58 
59 std::vector<PFCandidatePtr> notMainTrack(Tau tau)
60 {
61  const PFCandidatePtr& mainTrackPtr = mainTrack(tau);
62  std::vector<PFCandidatePtr> output;
63  output.reserve(tau.signalPFChargedHadrCands().size() - 1);
64  BOOST_FOREACH(const PFCandidatePtr& ptr, tau.signalPFChargedHadrCands()) {
65  if (ptr != mainTrackPtr)
66  output.push_back(ptr);
67  }
68  return output;
69 }
70 
71 double Pt(Tau tau) { return tau.pt(); }
72 double Eta(Tau tau) { return tau.eta(); }
73 double AbsEta(Tau tau) { return std::abs(tau.eta()); }
74 double Mass(Tau tau) { return tau.mass(); }
75 double DecayMode(Tau tau) { return tau.decayMode(); }
76 double InvariantMassOfSignal(Tau tau) { return tau.mass(); }
77 
78 /*
79  * HPStanc variables
80  */
81 
82 double JetPt(Tau tau) {
83  return tau.jetRef()->pt();
84 }
85 
86 double JetEta(Tau tau) {
87  return tau.jetRef()->eta();
88 }
89 
90 double AbsJetEta(Tau tau) {
91  return std::abs(tau.jetRef()->eta());
92 }
93 
94 double JetWidth(Tau tau) {
95  return std::sqrt(
96  std::abs(tau.jetRef()->etaetaMoment()) +
97  std::abs(tau.jetRef()->phiphiMoment()));
98 }
99 
100 double JetTauDR(Tau tau) {
101  return reco::deltaR(tau.p4(), tau.jetRef()->p4());
102 }
103 
105  return tau.pt()/tau.jetRef()->pt();
106 }
107 
109  return tau.isolationPFChargedHadrCandsPtSum()/tau.jetRef()->pt();
110 }
111 
113  return tau.isolationPFGammaCandsEtSum()/tau.jetRef()->pt();
114 }
115 
117  double sum = 0.0;
118  BOOST_FOREACH(PFCandidatePtr cand, tau.isolationPFNeutrHadrCands()) {
119  sum += cand->pt();
120  }
121  return sum/tau.jetRef()->pt();
122 }
123 
125  return tau.jetRef()->pt()*sqrt(std::abs(
126  tau.jetRef()->etaetaMoment()));
127 }
128 
130  double sumEt = 0;
131  double weightedDeltaR = 0;
132  BOOST_FOREACH(const reco::PFCandidatePtr& cand, tau.signalPFCands()) {
133  double candEt = cand->et();
134  double candDeltaR = reco::deltaR(cand->p4(), tau.p4());
135  sumEt += candEt;
136  weightedDeltaR += candDeltaR*candEt;
137  }
138  return (sumEt > 0) ? weightedDeltaR/sumEt : 0.0;
139 }
140 
142  double sumE = 0;
143  double weightedAngle = 0;
144  BOOST_FOREACH(const reco::PFCandidatePtr& cand, tau.signalPFCands()) {
145  double candE = cand->energy();
146  double candAngle = angle(cand->p4(), tau.p4());
147  sumE += candE;
148  weightedAngle += candAngle*candE;
149  }
150  return (sumE > 0) ? weightedAngle/sumE : 0.0;
151 }
152 
154  double max = 0.0;
155  const std::vector<PFCandidatePtr>& cands = tau.signalPFCands();
156  for (size_t i = 0; i < cands.size()-1; ++i) {
157  for (size_t j = i+1; j < cands.size(); ++j) {
158  double deltaRVal = deltaR(cands[i]->p4(), cands[j]->p4());
159  if (deltaRVal > max) {
160  max = deltaRVal;
161  }
162  }
163  }
164  // Correct for resolution
165  if ( max < 0.05 )
166  max = 0.05;
167  // Make invariant of PT
168  return max*tau.pt();;
169 }
170 
172  return tau.jetRef()->pt()*sqrt(std::abs(
173  tau.jetRef()->phiphiMoment()));
174 }
175 
177  size_t nIsoCharged = tau.isolationPFChargedHadrCands().size();
178  double averagePt = (nIsoCharged) ?
179  tau.isolationPFChargedHadrCandsPtSum()/nIsoCharged : 0;
180  return averagePt/tau.leadPFChargedHadrCand()->pt();
181 }
182 
184  return mainTrack(tau)->pt()/tau.jetRef()->pt();
185 }
186 
188  PFCandidatePtr theMainTrack = mainTrack(tau);
189  std::vector<PFCandidatePtr> otherSignalTracks = notMainTrack(tau);
190  const std::vector<RecoTauPiZero> &pizeros = tau.signalPiZeroCandidates();
191  VDouble output;
192  output.reserve(otherSignalTracks.size() + pizeros.size());
193  // Add combos with tracks
194  BOOST_FOREACH(PFCandidatePtr trk, otherSignalTracks) {
195  reco::Candidate::LorentzVector p4 = theMainTrack->p4() + trk->p4();
196  output.push_back(p4.mass());
197  }
198  // Add combos with pizeros
199  BOOST_FOREACH(const RecoTauPiZero &pizero, pizeros) {
200  reco::Candidate::LorentzVector p4 = theMainTrack->p4() + pizero.p4();
201  output.push_back(p4.mass());
202  }
203  return output;
204 }
205 
208  std::mem_fun_ref(&PFCandidate::pt));
209  double output = 0.0;
210  BOOST_FOREACH(double pt, isocands) {
211  if (pt > 1.0)
212  output += pt;
213  }
214  return output;
215 }
216 
219  std::mem_fun_ref(&PFCandidate::pt));
220  double output = 0.0;
221  BOOST_FOREACH(double pt, isocands) {
222  if (pt < 1.0)
223  output += pt;
224  }
225  return output;
226 }
227 
228 // Relative versions.
230  return IsolationChargedSumHard(tau)/tau.jetRef()->pt();
231 }
232 
234  return IsolationChargedSumSoft(tau)/tau.jetRef()->pt();
235 }
236 
238  VDouble isocands = extract(tau.isolationPFGammaCands(),
239  std::mem_fun_ref(&PFCandidate::pt));
240  double output = 0.0;
241  BOOST_FOREACH(double pt, isocands) {
242  if (pt > 1.5)
243  output += pt;
244  }
245  return output;
246 }
247 
249  VDouble isocands = extract(tau.isolationPFGammaCands(),
250  std::mem_fun_ref(&PFCandidate::pt));
251  double output = 0.0;
252  BOOST_FOREACH(double pt, isocands) {
253  if (pt < 1.5)
254  output += pt;
255  }
256  return output;
257 }
258 
259 // Relative versions.
261  return IsolationECALSumHard(tau)/tau.jetRef()->pt();
262 }
264  return IsolationECALSumSoft(tau)/tau.jetRef()->pt();
265 }
266 
267 double EMFraction(Tau tau) {
268  //double result = tau.emFraction();
270  BOOST_FOREACH(const reco::PFCandidatePtr& gamma, tau.signalPFGammaCands()) {
271  gammaP4 += gamma->p4();
272  }
273  double result = gammaP4.pt()/tau.pt();
274 
275  if (result > 0.99) {
276  std::cout << "EM fraction = " << result
277  << tau << std::endl;
278  tau.dump(std::cout);
279  std::cout << "charged" << std::endl;
280  BOOST_FOREACH(const reco::PFCandidatePtr cand, tau.signalPFChargedHadrCands()) {
281  std::cout << " pt: " << cand->pt() << " type: " << cand->particleId() << " key: " << cand.key() << std::endl;
282  }
283  std::cout << "gammas" << std::endl;
284  BOOST_FOREACH(const reco::PFCandidatePtr cand, tau.signalPFGammaCands()) {
285  std::cout << " pt: " << cand->pt() << " type: " << cand->particleId() << " key: " << cand.key() << std::endl;
286  }
287  }
288  return result;
289 }
290 
293 }
294 
295 double OutlierN(Tau tau) {
296  return tau.isolationPFChargedHadrCands().size() +
297  tau.isolationPFGammaCands().size();
298 }
299 
301  return tau.isolationPFChargedHadrCands().size();
302 }
303 
304 double MainTrackPt(Tau tau) {
305  PFCandidatePtr trk = mainTrack(tau);
306  return (!trk) ? 0.0 : trk->pt();
307 }
308 
310  PFCandidatePtr trk = mainTrack(tau);
311  return (!trk) ? 0.0 : trk->eta();
312 }
313 
315  PFCandidatePtr trk = mainTrack(tau);
316  return (!trk) ? 0.0 : deltaR(trk->p4(), tau.p4());
317 }
318 
320  return tau.isolationPFChargedHadrCandsPtSum() +
322 }
323 
326 }
327 
329  return tau.isolationPFGammaCandsEtSum();
330 }
331 
332 // Quantities associated to tracks - that are not the main track
334  return extract(notMainTrack(tau), std::mem_fun_ref(&PFCandidate::pt));
335 }
336 
338  return extract(notMainTrack(tau), std::mem_fun_ref(&PFCandidate::eta));
339 }
340 
342  return extract(notMainTrack(tau), DeltaRToAxis(tau.p4()));
343 }
344 
345 // Quantities associated to PiZeros
347  return extract(tau.signalPiZeroCandidates(), std::mem_fun_ref(&RecoTauPiZero::pt));
348 }
349 
351  return extract(tau.signalPiZeroCandidates(), std::mem_fun_ref(&RecoTauPiZero::eta));
352 }
353 
355  return extract(tau.signalPiZeroCandidates(), DeltaRToAxis(tau.p4()));
356 }
357 
358 // Isolation quantities
360  return extract(tau.isolationPFCands(), std::mem_fun_ref(&PFCandidate::pt));
361 }
362 
364  return extract(tau.isolationPFCands(), DeltaRToAxis(tau.p4()));
365 }
366 
369  std::mem_fun_ref(&PFCandidate::pt));
370 }
371 
373  return extract(tau.isolationPFChargedHadrCands(), DeltaRToAxis(tau.p4()));
374 }
375 
377  return extract(tau.isolationPFGammaCands(),
378  std::mem_fun_ref(&PFCandidate::pt));
379 }
380 
382  return extract(tau.isolationPFGammaCands(), DeltaRToAxis(tau.p4()));
383 }
384 
385 // Invariant mass of main track with other combinations
387  return Dalitz2(tau);
388 }
389 
390 // The below functions are deprecated.
391 // Not used, for backwards compatability
394 VDouble GammaPt(Tau tau) { return VDouble(); }
398 
399 }}} // end reco::tau::disc namespace
400 
int i
Definition: DBlmapReader.cc:9
double IsolationECALSumHardRelative(Tau tau)
double ScaledPhiJetCollimation(Tau tau)
float isolationPFGammaCandsEtSum() const
Definition: PFTau.cc:196
const PFJetRef & jetRef() const
Definition: PFTau.cc:52
const std::vector< reco::PFCandidatePtr > & isolationPFCands() const
PFCandidates in isolation region.
Definition: PFTau.cc:81
float isolationPFChargedHadrCandsPtSum() const
Definition: PFTau.cc:193
const PFCandidatePtr & leadPFChargedHadrCand() const
Definition: PFTau.cc:61
virtual const LorentzVector & p4() const GCC11_FINAL
four-momentum Lorentz vector
std::vector< double > VDouble
const std::vector< reco::PFCandidatePtr > & signalPFGammaCands() const
Gamma candidates in signal region.
Definition: PFTau.cc:78
double IsolationECALSumHard(Tau tau)
double IsolationChargedSumSoftRelative(Tau tau)
double IsolationChargedPtFraction(Tau tau)
const std::vector< reco::PFCandidatePtr > & signalPFCands() const
PFCandidates in signal region.
Definition: PFTau.cc:72
const std::vector< reco::PFCandidatePtr > & isolationPFGammaCands() const
Gamma candidates in isolation region.
Definition: PFTau.cc:87
std::vector< PFCandidatePtr > notMainTrack(Tau tau)
double ScaledEtaJetCollimation(Tau tau)
double ImpactParameterSignificance(Tau tau)
hadronicDecayMode decayMode() const
Definition: PFTau.cc:176
void dump(std::ostream &out=std::cout) const
prints information on this PFTau
Definition: PFTau.cc:252
const T & max(const T &a, const T &b)
const std::vector< RecoTauPiZero > & signalPiZeroCandidates() const
Retrieve the association of signal region gamma candidates into candidate PiZeros.
Definition: PFTau.cc:91
T sqrt(T t)
Definition: SSEVec.h:48
double p4[4]
Definition: TauolaWrapper.h:92
double IsolationChargedSumHard(Tau tau)
tuple result
Definition: query.py:137
double IsolationChargedAveragePtFraction(Tau tau)
const reco::Candidate::LorentzVector & axis_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:30
const std::vector< reco::PFCandidatePtr > & isolationPFNeutrHadrCands() const
Definition: PFTau.cc:85
double IsolationECALPtFraction(Tau tau)
const std::vector< reco::PFCandidatePtr > & isolationPFChargedHadrCands() const
Charged candidates in isolation region.
Definition: PFTau.cc:83
VDouble InvariantMassOfSignalWithFiltered(Tau)
float leadPFChargedHadrCandsignedSipt() const
Definition: PFTau.cc:69
virtual float eta() const GCC11_FINAL
momentum pseudorapidity
int extract(std::vector< int > *output, const std::string &dati)
virtual float mass() const GCC11_FINAL
mass
key_type key() const
Definition: Ptr.h:169
double IsolationChargedSumHardRelative(Tau tau)
virtual int charge() const GCC11_FINAL
electric charge
double IsolationECALSumSoftRelative(Tau tau)
double IsolationChargedSumSoft(Tau tau)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:41
double IsolationNeutralHadronPtFraction(Tau tau)
double IsolationECALSumSoft(Tau tau)
double InvariantMassOfSignal(Tau tau)
string func
Definition: statics.py:48
tuple cout
Definition: gather_cfg.py:121
virtual float pt() const GCC11_FINAL
transverse momentum
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
PFCandidatePtr mainTrack(const PFTau &tau)
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
Charged hadrons in signal region.
Definition: PFTau.cc:74
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11