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 PFCandidateRef& 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 
60 {
61  const PFCandidateRef& mainTrackRef = mainTrack(tau);
63  output.reserve(tau.signalPFChargedHadrCands().size() - 1);
64  BOOST_FOREACH(const PFCandidateRef& ref, tau.signalPFChargedHadrCands()) {
65  if (ref != mainTrackRef)
66  output.push_back(ref);
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(PFCandidateRef 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::PFCandidateRef& 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::PFCandidateRef& 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 PFCandidateRefVector& 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  PFCandidateRef theMainTrack = mainTrack(tau);
189  PFCandidateRefVector 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(PFCandidateRef 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::PFCandidateRef& 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::PFCandidateRef 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::PFCandidateRef 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  PFCandidateRef trk = mainTrack(tau);
306  return (!trk) ? 0.0 : trk->pt();
307 }
308 
310  PFCandidateRef trk = mainTrack(tau);
311  return (!trk) ? 0.0 : trk->eta();
312 }
313 
315  PFCandidateRef 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:151
const PFCandidateRefVector & isolationPFCands() const
PFCandidates in isolation region.
Definition: PFTau.cc:82
const PFJetRef & jetRef() const
Definition: PFTau.cc:50
float isolationPFChargedHadrCandsPtSum() const
Definition: PFTau.cc:148
std::vector< double > VDouble
double IsolationECALSumHard(Tau tau)
#define abs(x)
Definition: mlp_lapack.h:159
double IsolationChargedSumSoftRelative(Tau tau)
const PFCandidateRefVector & signalPFChargedHadrCands() const
Charged hadrons in signal region.
Definition: PFTau.cc:75
double IsolationChargedPtFraction(Tau tau)
virtual double eta() const
momentum pseudorapidity
const PFCandidateRefVector & signalPFCands() const
PFCandidates in signal region.
Definition: PFTau.cc:73
double ScaledEtaJetCollimation(Tau tau)
double deltaR(double eta1, double phi1, double eta2, double phi2)
Definition: deltaR.h:19
double ImpactParameterSignificance(Tau tau)
hadronicDecayMode decayMode() const
Definition: PFTau.cc:130
virtual double mass() const
mass
void dump(std::ostream &out=std::cout) const
prints information on this PFTau
Definition: PFTau.cc:209
PFCandidateRef mainTrack(const PFTau &tau)
PFCandidateRefVector notMainTrack(Tau tau)
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:92
T sqrt(T t)
Definition: SSEVec.h:46
double p4[4]
Definition: TauolaWrapper.h:92
double IsolationChargedSumHard(Tau tau)
const PFCandidateRefVector & isolationPFGammaCands() const
Gamma candidates in isolation region.
Definition: PFTau.cc:88
tuple result
Definition: query.py:137
double IsolationChargedAveragePtFraction(Tau tau)
virtual int charge() const
electric charge
const reco::Candidate::LorentzVector & axis_
int j
Definition: DBlmapReader.cc:9
double IsolationECALPtFraction(Tau tau)
edm::Ref< PFCandidateCollection > PFCandidateRef
persistent reference to a PFCandidate
void reserve(size_type n)
Reserve space for RefVector.
Definition: RefVector.h:95
VDouble InvariantMassOfSignalWithFiltered(Tau)
float leadPFChargedHadrCandsignedSipt() const
Definition: PFTau.cc:70
int extract(std::vector< int > *output, const std::string &dati)
const PFCandidateRef & leadPFChargedHadrCand() const
Definition: PFTau.cc:62
const PFCandidateRefVector & signalPFGammaCands() const
Gamma candidates in signal region.
Definition: PFTau.cc:79
double IsolationChargedSumHardRelative(Tau tau)
virtual double pt() const
transverse momentum
key_type key() const
Accessor for product key.
Definition: Ref.h:266
double IsolationECALSumSoftRelative(Tau tau)
double IsolationChargedSumSoft(Tau tau)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:38
double IsolationNeutralHadronPtFraction(Tau tau)
double IsolationECALSumSoft(Tau tau)
double InvariantMassOfSignal(Tau tau)
void push_back(value_type const &ref)
Add a Ref&lt;C, T&gt; to the RefVector.
Definition: RefVector.h:64
size_type size() const
Size of the RefVector.
Definition: RefVector.h:89
tuple cout
Definition: gather_cfg.py:121
virtual const LorentzVector & p4() const
four-momentum Lorentz vector
const PFCandidateRefVector & isolationPFNeutrHadrCands() const
Definition: PFTau.cc:86
const PFCandidateRefVector & isolationPFChargedHadrCands() const
Charged candidates in isolation region.
Definition: PFTau.cc:84
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11