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  LogDebug("TauDiscFunctions") << "EM fraction = " << result
277  << tau ;
278  LogDebug("TauDiscFunctions") << "charged" ;
279  BOOST_FOREACH(const reco::PFCandidatePtr cand, tau.signalPFChargedHadrCands()) {
280  LogDebug("TauDiscFunctions") << " pt: " << cand->pt() << " type: " << cand->particleId() << " key: " << cand.key() ;
281  }
282  LogDebug("TauDiscFunctions") << "gammas" ;
283  BOOST_FOREACH(const reco::PFCandidatePtr cand, tau.signalPFGammaCands()) {
284  LogDebug("TauDiscFunctions") << " pt: " << cand->pt() << " type: " << cand->particleId() << " key: " << cand.key() ;
285  }
286  }
287  return result;
288 }
289 
292 }
293 
294 double OutlierN(Tau tau) {
295  return tau.isolationPFChargedHadrCands().size() +
296  tau.isolationPFGammaCands().size();
297 }
298 
300  return tau.isolationPFChargedHadrCands().size();
301 }
302 
303 double MainTrackPt(Tau tau) {
304  PFCandidatePtr trk = mainTrack(tau);
305  return (!trk) ? 0.0 : trk->pt();
306 }
307 
309  PFCandidatePtr trk = mainTrack(tau);
310  return (!trk) ? 0.0 : trk->eta();
311 }
312 
314  PFCandidatePtr trk = mainTrack(tau);
315  return (!trk) ? 0.0 : deltaR(trk->p4(), tau.p4());
316 }
317 
319  return tau.isolationPFChargedHadrCandsPtSum() +
321 }
322 
325 }
326 
328  return tau.isolationPFGammaCandsEtSum();
329 }
330 
331 // Quantities associated to tracks - that are not the main track
333  return extract(notMainTrack(tau), std::mem_fun_ref(&PFCandidate::pt));
334 }
335 
337  return extract(notMainTrack(tau), std::mem_fun_ref(&PFCandidate::eta));
338 }
339 
341  return extract(notMainTrack(tau), DeltaRToAxis(tau.p4()));
342 }
343 
344 // Quantities associated to PiZeros
346  return extract(tau.signalPiZeroCandidates(), std::mem_fun_ref(&RecoTauPiZero::pt));
347 }
348 
350  return extract(tau.signalPiZeroCandidates(), std::mem_fun_ref(&RecoTauPiZero::eta));
351 }
352 
354  return extract(tau.signalPiZeroCandidates(), DeltaRToAxis(tau.p4()));
355 }
356 
357 // Isolation quantities
359  return extract(tau.isolationPFCands(), std::mem_fun_ref(&PFCandidate::pt));
360 }
361 
363  return extract(tau.isolationPFCands(), DeltaRToAxis(tau.p4()));
364 }
365 
368  std::mem_fun_ref(&PFCandidate::pt));
369 }
370 
372  return extract(tau.isolationPFChargedHadrCands(), DeltaRToAxis(tau.p4()));
373 }
374 
376  return extract(tau.isolationPFGammaCands(),
377  std::mem_fun_ref(&PFCandidate::pt));
378 }
379 
381  return extract(tau.isolationPFGammaCands(), DeltaRToAxis(tau.p4()));
382 }
383 
384 // Invariant mass of main track with other combinations
386  return Dalitz2(tau);
387 }
388 
389 // The below functions are deprecated.
390 // Not used, for backwards compatability
393 VDouble GammaPt(Tau tau) { return VDouble(); }
397 
398 }}} // end reco::tau::disc namespace
399 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
double IsolationECALSumHardRelative(Tau tau)
double ScaledPhiJetCollimation(Tau tau)
float isolationPFGammaCandsEtSum() const
Definition: PFTau.cc:190
const PFJetRef & jetRef() const
Definition: PFTau.cc:58
const std::vector< reco::PFCandidatePtr > & isolationPFCands() const
PFCandidates in isolation region.
Definition: PFTau.cc:87
float isolationPFChargedHadrCandsPtSum() const
Definition: PFTau.cc:187
const PFCandidatePtr & leadPFChargedHadrCand() const
Definition: PFTau.cc:67
key_type key() const
Definition: Ptr.h:169
std::vector< double > VDouble
const std::vector< reco::PFCandidatePtr > & signalPFGammaCands() const
Gamma candidates in signal region.
Definition: PFTau.cc:84
double IsolationECALSumHard(Tau tau)
double IsolationChargedSumSoftRelative(Tau tau)
double deltaR(const T1 &t1, const T2 &t2)
Definition: deltaR.h:48
double IsolationChargedPtFraction(Tau tau)
const std::vector< reco::PFCandidatePtr > & signalPFCands() const
PFCandidates in signal region.
Definition: PFTau.cc:78
virtual double eta() const
momentum pseudorapidity
virtual double pt() const
transverse momentum
const std::vector< reco::PFCandidatePtr > & isolationPFGammaCands() const
Gamma candidates in isolation region.
Definition: PFTau.cc:93
std::vector< PFCandidatePtr > notMainTrack(Tau tau)
double ScaledEtaJetCollimation(Tau tau)
double ImpactParameterSignificance(Tau tau)
hadronicDecayMode decayMode() const
Definition: PFTau.cc:182
virtual double mass() const
mass
const std::vector< RecoTauPiZero > & signalPiZeroCandidates() const
Retrieve the association of signal region gamma candidates into candidate PiZeros.
Definition: PFTau.cc:97
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)
virtual int charge() const
electric charge
Definition: LeafCandidate.h:91
const reco::Candidate::LorentzVector & axis_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
const std::vector< reco::PFCandidatePtr > & isolationPFNeutrHadrCands() const
Definition: PFTau.cc:91
double IsolationECALPtFraction(Tau tau)
const std::vector< reco::PFCandidatePtr > & isolationPFChargedHadrCands() const
Charged candidates in isolation region.
Definition: PFTau.cc:89
VDouble InvariantMassOfSignalWithFiltered(Tau)
float leadPFChargedHadrCandsignedSipt() const
Definition: PFTau.cc:75
int extract(std::vector< int > *output, const std::string &dati)
double IsolationChargedSumHardRelative(Tau tau)
double IsolationECALSumSoftRelative(Tau tau)
double IsolationChargedSumSoft(Tau tau)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
double IsolationNeutralHadronPtFraction(Tau tau)
double IsolationECALSumSoft(Tau tau)
double InvariantMassOfSignal(Tau tau)
edm::Ptr< PFCandidate > PFCandidatePtr
persistent Ptr to a PFCandidate
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
PFCandidatePtr mainTrack(const PFTau &tau)
const std::vector< reco::PFCandidatePtr > & signalPFChargedHadrCands() const
Charged hadrons in signal region.
Definition: PFTau.cc:80
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11