CMS 3D CMS Logo

RecoTauDiscriminantFunctions.cc
Go to the documentation of this file.
7 
8 #include <algorithm>
9 #include <functional>
10 
11 namespace reco::tau::disc {
12 
13 // Helper functions
14 namespace {
15 
16 template<class T> T const& removePtr(T const& t) { return t; }
17 template<class T> T const& removePtr(edm::Ptr<T> const& t) { return *t; }
18 
19 template<class T, class F>
20 VDouble extract(std::vector<T> const& cands, F f) {
21  VDouble output( cands.size() );
22  for(auto const& x : cands) output.push_back(f(removePtr(x)));
23  return output;
24 }
25 
26 class DeltaRToAxis {
27  public:
28  DeltaRToAxis(const reco::Candidate::LorentzVector& axis):axis_(axis){}
29  double operator()(const Candidate& cand)
30  {
31  return deltaR(cand.p4(), axis_);
32  }
33  private:
35 };
36 
37 } // end helper functions
38 
40  if (tau.signalChargedHadrCands().size() == 3) {
41  for (size_t itrk = 0; itrk < 3; ++itrk) {
42  if (tau.signalChargedHadrCands()[itrk]->charge() * tau.charge() < 0)
43  return tau.signalChargedHadrCands()[itrk];
44  }
45  }
46  return tau.leadChargedHadrCand();
47 }
48 
49 std::vector<CandidatePtr> notMainTrack(Tau tau)
50 {
51  const CandidatePtr& mainTrackPtr = mainTrack(tau);
52  std::vector<CandidatePtr> output;
53  output.reserve(tau.signalChargedHadrCands().size() - 1);
54  for(auto const& ptr : tau.signalChargedHadrCands()) {
55  if (ptr != mainTrackPtr)
56  output.push_back(ptr);
57  }
58  return output;
59 }
60 
61 double Pt(Tau tau) { return tau.pt(); }
62 double Eta(Tau tau) { return tau.eta(); }
63 double AbsEta(Tau tau) { return std::abs(tau.eta()); }
64 double Mass(Tau tau) { return tau.mass(); }
65 double DecayMode(Tau tau) { return tau.decayMode(); }
66 double InvariantMassOfSignal(Tau tau) { return tau.mass(); }
67 
68 /*
69  * HPStanc variables
70  */
71 
72 double JetPt(Tau tau) {
73  return tau.jetRef()->pt();
74 }
75 
76 double JetEta(Tau tau) {
77  return tau.jetRef()->eta();
78 }
79 
80 double AbsJetEta(Tau tau) {
81  return std::abs(tau.jetRef()->eta());
82 }
83 
84 double JetWidth(Tau tau) {
85  return std::sqrt(
86  std::abs(tau.jetRef()->etaetaMoment()) +
87  std::abs(tau.jetRef()->phiphiMoment()));
88 }
89 
90 double JetTauDR(Tau tau) {
91  return reco::deltaR(tau.p4(), tau.jetRef()->p4());
92 }
93 
95  return tau.pt()/tau.jetRef()->pt();
96 }
97 
99  return tau.isolationPFChargedHadrCandsPtSum()/tau.jetRef()->pt();
100 }
101 
103  return tau.isolationPFGammaCandsEtSum()/tau.jetRef()->pt();
104 }
105 
107  double sum = 0.0;
108  for(auto const& cand : tau.isolationNeutrHadrCands()) {
109  sum += cand->pt();
110  }
111  return sum/tau.jetRef()->pt();
112 }
113 
115  return tau.jetRef()->pt()*sqrt(std::abs(
116  tau.jetRef()->etaetaMoment()));
117 }
118 
120  double sumEt = 0;
121  double weightedDeltaR = 0;
122  for(auto const& cand : tau.signalCands()) {
123  double candEt = cand->et();
124  double candDeltaR = reco::deltaR(cand->p4(), tau.p4());
125  sumEt += candEt;
126  weightedDeltaR += candDeltaR*candEt;
127  }
128  return (sumEt > 0) ? weightedDeltaR/sumEt : 0.0;
129 }
130 
132  double sumE = 0;
133  double weightedAngle = 0;
134  for(auto const& cand : tau.signalCands()) {
135  double candE = cand->energy();
136  double candAngle = angle(cand->p4(), tau.p4());
137  sumE += candE;
138  weightedAngle += candAngle*candE;
139  }
140  return (sumE > 0) ? weightedAngle/sumE : 0.0;
141 }
142 
144  double max = 0.0;
145  const std::vector<CandidatePtr>& cands = tau.signalCands();
146  for (size_t i = 0; i < cands.size()-1; ++i) {
147  for (size_t j = i+1; j < cands.size(); ++j) {
148  double deltaRVal = deltaR(cands[i]->p4(), cands[j]->p4());
149  if (deltaRVal > max) {
150  max = deltaRVal;
151  }
152  }
153  }
154  // Correct for resolution
155  if ( max < 0.05 )
156  max = 0.05;
157  // Make invariant of PT
158  return max*tau.pt();;
159 }
160 
162  return tau.jetRef()->pt()*sqrt(std::abs(
163  tau.jetRef()->phiphiMoment()));
164 }
165 
167  size_t nIsoCharged = tau.isolationChargedHadrCands().size();
168  double averagePt = (nIsoCharged) ?
169  tau.isolationPFChargedHadrCandsPtSum()/nIsoCharged : 0;
170  return averagePt/tau.leadChargedHadrCand()->pt();
171 }
172 
174  return mainTrack(tau)->pt()/tau.jetRef()->pt();
175 }
176 
178  CandidatePtr theMainTrack = mainTrack(tau);
179  std::vector<CandidatePtr> otherSignalTracks = notMainTrack(tau);
180  const std::vector<RecoTauPiZero> &pizeros = tau.signalPiZeroCandidates();
181  VDouble output;
182  output.reserve(otherSignalTracks.size() + pizeros.size());
183  // Add combos with tracks
184  for(auto const& trk : otherSignalTracks) {
185  reco::Candidate::LorentzVector p4 = theMainTrack->p4() + trk->p4();
186  output.push_back(p4.mass());
187  }
188  // Add combos with pizeros
189  for(auto const& pizero : pizeros) {
190  reco::Candidate::LorentzVector p4 = theMainTrack->p4() + pizero.p4();
191  output.push_back(p4.mass());
192  }
193  return output;
194 }
195 
197  VDouble isocands = extract(tau.isolationChargedHadrCands(), std::mem_fn(&Candidate::pt));
198  double output = 0.0;
199  for(double pt : isocands) {
200  if (pt > 1.0)
201  output += pt;
202  }
203  return output;
204 }
205 
207  VDouble isocands = extract(tau.isolationChargedHadrCands(), std::mem_fn(&Candidate::pt));
208  double output = 0.0;
209  for(double pt : isocands) {
210  if (pt < 1.0)
211  output += pt;
212  }
213  return output;
214 }
215 
216 // Relative versions.
218  return IsolationChargedSumHard(tau)/tau.jetRef()->pt();
219 }
220 
222  return IsolationChargedSumSoft(tau)/tau.jetRef()->pt();
223 }
224 
226  VDouble isocands = extract(tau.isolationGammaCands(), std::mem_fn(&Candidate::pt));
227  double output = 0.0;
228  for(double pt : isocands) {
229  if (pt > 1.5)
230  output += pt;
231  }
232  return output;
233 }
234 
236  VDouble isocands = extract(tau.isolationGammaCands(), std::mem_fn(&Candidate::pt));
237  double output = 0.0;
238  for(double pt : isocands) {
239  if (pt < 1.5)
240  output += pt;
241  }
242  return output;
243 }
244 
245 // Relative versions.
247  return IsolationECALSumHard(tau)/tau.jetRef()->pt();
248 }
250  return IsolationECALSumSoft(tau)/tau.jetRef()->pt();
251 }
252 
253 double EMFraction(Tau tau) {
254  //double result = tau.emFraction();
256  for(auto const& gamma : tau.signalGammaCands()) {
257  gammaP4 += gamma->p4();
258  }
259  double result = gammaP4.pt()/tau.pt();
260 
261  if (result > 0.99) {
262  LogDebug("TauDiscFunctions") << "EM fraction = " << result
263  << tau ;
264  LogDebug("TauDiscFunctions") << "charged" ;
265  for(auto const& cand : tau.signalChargedHadrCands()) {
266  LogDebug("TauDiscFunctions") << " pt: " << cand->pt() << " pdgId: " << cand->pdgId() << " key: " << cand.key() ;
267  }
268  LogDebug("TauDiscFunctions") << "gammas" ;
269  for(auto const& cand : tau.signalGammaCands()) {
270  LogDebug("TauDiscFunctions") << " pt: " << cand->pt() << " pdgId: " << cand->pdgId() << " key: " << cand.key() ;
271  }
272  }
273  return result;
274 }
275 
278 }
279 
280 double OutlierN(Tau tau) {
281  return tau.isolationChargedHadrCands().size() +
282  tau.isolationGammaCands().size();
283 }
284 
286  return tau.isolationChargedHadrCands().size();
287 }
288 
289 double MainTrackPt(Tau tau) {
290  CandidatePtr trk = mainTrack(tau);
291  return (!trk) ? 0.0 : trk->pt();
292 }
293 
295  CandidatePtr trk = mainTrack(tau);
296  return (!trk) ? 0.0 : trk->eta();
297 }
298 
300  CandidatePtr trk = mainTrack(tau);
301  return (!trk) ? 0.0 : deltaR(trk->p4(), tau.p4());
302 }
303 
305  return tau.isolationPFChargedHadrCandsPtSum() +
307 }
308 
311 }
312 
314  return tau.isolationPFGammaCandsEtSum();
315 }
316 
317 // Quantities associated to tracks - that are not the main track
319  return extract(notMainTrack(tau), std::mem_fn(&Candidate::pt));
320 }
321 
323  return extract(notMainTrack(tau), std::mem_fn(&Candidate::eta));
324 }
325 
327  return extract(notMainTrack(tau), DeltaRToAxis(tau.p4()));
328 }
329 
330 // Quantities associated to PiZeros
332  return extract(tau.signalPiZeroCandidates(), std::mem_fn(&RecoTauPiZero::pt));
333 }
334 
336  return extract(tau.signalPiZeroCandidates(), std::mem_fn(&RecoTauPiZero::eta));
337 }
338 
340  return extract(tau.signalPiZeroCandidates(), DeltaRToAxis(tau.p4()));
341 }
342 
343 // Isolation quantities
345  return extract(tau.isolationCands(), std::mem_fn(&Candidate::pt));
346 }
347 
349  return extract(tau.isolationCands(), DeltaRToAxis(tau.p4()));
350 }
351 
353  return extract(tau.isolationChargedHadrCands(), std::mem_fn(&Candidate::pt));
354 }
355 
357  return extract(tau.isolationChargedHadrCands(), DeltaRToAxis(tau.p4()));
358 }
359 
361  return extract(tau.isolationGammaCands(), std::mem_fn(&Candidate::pt));
362 }
363 
365  return extract(tau.isolationGammaCands(), DeltaRToAxis(tau.p4()));
366 }
367 
368 // Invariant mass of main track with other combinations
370  return Dalitz2(tau);
371 }
372 
373 // The below functions are deprecated.
374 // Not used, for backwards compatability
377 VDouble GammaPt(Tau tau) { return VDouble(); }
381 
382 } // end reco::tau::disc namespace
383 
#define LogDebug(id)
double IsolationECALSumHardRelative(Tau tau)
double ScaledPhiJetCollimation(Tau tau)
float isolationPFGammaCandsEtSum() const
Definition: PFTau.cc:323
double eta() const final
momentum pseudorapidity
float isolationPFChargedHadrCandsPtSum() const
Definition: PFTau.cc:320
std::vector< double > VDouble
double IsolationECALSumHard(Tau tau)
double pt() const final
transverse momentum
double IsolationChargedSumSoftRelative(Tau tau)
int charge() const final
electric charge
Definition: LeafCandidate.h:91
const std::vector< reco::CandidatePtr > & signalGammaCands() const
Gamma candidates in signal region.
Definition: PFTau.cc:84
double IsolationChargedPtFraction(Tau tau)
const std::vector< reco::CandidatePtr > & isolationGammaCands() const
Gamma candidates in isolation region.
Definition: PFTau.cc:93
double ScaledEtaJetCollimation(Tau tau)
double ImpactParameterSignificance(Tau tau)
hadronicDecayMode decayMode() const
Definition: PFTau.cc:315
const CandidatePtr & leadChargedHadrCand() const
Definition: PFTau.cc:67
const std::vector< RecoTauPiZero > & signalPiZeroCandidates() const
Retrieve the association of signal region gamma candidates into candidate PiZeros.
Definition: PFTau.cc:230
T sqrt(T t)
Definition: SSEVec.h:18
double p4[4]
Definition: TauolaWrapper.h:92
double IsolationChargedSumHard(Tau tau)
const JetBaseRef & jetRef() const
Definition: PFTau.cc:58
double IsolationChargedAveragePtFraction(Tau tau)
const reco::Candidate::LorentzVector & axis_
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
double f[11][100]
const LorentzVector & p4() const final
four-momentum Lorentz vector
Definition: LeafCandidate.h:99
double IsolationECALPtFraction(Tau tau)
std::vector< CandidatePtr > notMainTrack(Tau tau)
VDouble InvariantMassOfSignalWithFiltered(Tau)
float leadPFChargedHadrCandsignedSipt() const
Definition: PFTau.cc:75
constexpr auto deltaR(const T1 &t1, const T2 &t2) -> decltype(t1.eta())
Definition: deltaR.h:28
int extract(std::vector< int > *output, const std::string &dati)
const std::vector< reco::CandidatePtr > & isolationChargedHadrCands() const
Charged candidates in isolation region.
Definition: PFTau.cc:89
Definition: Tau.py:1
virtual double eta() const =0
momentum pseudorapidity
double IsolationChargedSumHardRelative(Tau tau)
virtual double pt() const =0
transverse momentum
double IsolationECALSumSoftRelative(Tau tau)
double IsolationChargedSumSoft(Tau tau)
math::XYZTLorentzVector LorentzVector
Lorentz vector.
Definition: Candidate.h:37
const std::vector< reco::CandidatePtr > & signalChargedHadrCands() const
Charged hadrons in signal region.
Definition: PFTau.cc:80
CandidatePtr mainTrack(const PFTau &tau)
double IsolationNeutralHadronPtFraction(Tau tau)
double IsolationECALSumSoft(Tau tau)
double InvariantMassOfSignal(Tau tau)
const std::vector< reco::CandidatePtr > & isolationNeutrHadrCands() const
Definition: PFTau.cc:91
const std::vector< reco::CandidatePtr > & isolationCands() const
Candidates in isolation region.
Definition: PFTau.cc:87
const std::vector< reco::CandidatePtr > & signalCands() const
Candidates in signal region.
Definition: PFTau.cc:78
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
long double T
double mass() const final
mass
T angle(T x1, T y1, T z1, T x2, T y2, T z2)
Definition: angle.h:11