ATLAS Offline Software
PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include <fstream>
6 
7 // local include(s)
11 #include "TF1.h"
12 
13 #ifdef ASGTOOL_ATHENA
14 #include "CLHEP/Units/SystemOfUnits.h"
15 using CLHEP::GeV;
16 #else
17 #define GeV 1000
18 #endif
19 
20 using namespace TauAnalysisTools;
21 
22 //______________________________________________________________________________
23 void TauAnalysisTools::split(const std::string& sInput, const char cDelim, std::vector<std::string>& vOut)
24 {
25  std::stringstream sSS(sInput);
26  std::string sItem;
27  while (std::getline(sSS, sItem, cDelim))
28  vOut.push_back(sItem);
29 }
30 
31 //______________________________________________________________________________
32 void TauAnalysisTools::split(TEnv& rEnv, const std::string& sKey, const char cDelim, std::vector<std::string>& vOut)
33 {
34  std::stringstream sSS(rEnv.GetValue(sKey.c_str(),""));
35  std::string sItem;
36  while (std::getline(sSS, sItem, cDelim))
37  vOut.push_back(sItem);
38 }
39 
40 //______________________________________________________________________________
41 void TauAnalysisTools::split(TEnv& rEnv, const std::string& sKey, const char cDelim, std::vector<size_t>& vOut)
42 {
43  std::stringstream sSS(rEnv.GetValue(sKey.c_str(),""));
44  std::string sItem;
45  while (std::getline(sSS, sItem, cDelim))
46  vOut.push_back(size_t(stoi(sItem)));
47 }
48 
49 //______________________________________________________________________________
50 void TauAnalysisTools::split(TEnv& rEnv, const std::string& sKey, const char cDelim, std::vector<int>& vOut)
51 {
52  std::stringstream sSS(rEnv.GetValue(sKey.c_str(),""));
53  std::string sItem;
54  while (std::getline(sSS, sItem, cDelim))
55  vOut.push_back(stoi(sItem));
56 }
57 
58 //______________________________________________________________________________
59 void TauAnalysisTools::split(TEnv& rEnv, const std::string& sKey, const char cDelim, std::vector<unsigned>& vOut)
60 {
61  std::stringstream sSS(rEnv.GetValue(sKey.c_str(),""));
62  std::string sItem;
63  while (std::getline(sSS, sItem, cDelim))
64  vOut.push_back(stoi(sItem));
65 }
66 
67 //______________________________________________________________________________
68 void TauAnalysisTools::split(TEnv& rEnv, const std::string& sKey, const char cDelim, std::vector<float>& vOut)
69 {
70  std::stringstream sSS(rEnv.GetValue(sKey.c_str(),""));
71  std::string sItem;
72  while (std::getline(sSS, sItem, cDelim))
73  vOut.push_back(stof(sItem));
74 }
75 
76 //______________________________________________________________________________
77 void TauAnalysisTools::split(TEnv& rEnv, const std::string& sKey, const char cDelim, std::vector<double>& vOut)
78 {
79  std::stringstream sSS(rEnv.GetValue(sKey.c_str(),""));
80  std::string sItem;
81  while (std::getline(sSS, sItem, cDelim))
82  vOut.push_back(stod(sItem));
83 }
84 //______________________________________________________________________________
86 {
87  // return tau pt in GeV
88  return xTau.pt()/1000.;
89 }
90 
91 //______________________________________________________________________________
93 {
94  // return tau P in GeV
95  return xTau.p4().P()/1000.;
96 }
97 
98 //______________________________________________________________________________
100 {
101  // return tau eta
102  return xTau.eta();
103 }
104 
105 //______________________________________________________________________________
107 {
108  // return absolute tau eta
109  return std::abs(xTau.eta());
110 }
111 
112 //______________________________________________________________________________
114 {
115  // return MVA based tau pt in GeV
116  return xTau.ptFinalCalib()/GeV;
117 }
118 
119 //______________________________________________________________________________
121 {
122  // return MVA based tau eta
123  return xTau.etaFinalCalib();
124 }
125 
126 //______________________________________________________________________________
128 {
129  // return MVA based absolute tau eta
130  return std::abs(xTau.etaFinalCalib());
131 }
132 
133 //______________________________________________________________________________
135 {
136  // return tau P in GeV
137  return xTau.p4(xAOD::TauJetParameters::FinalCalib).P()/GeV;
138 }
139 
140 //______________________________________________________________________________
142 {
143  // return leading charge tau track eta
144  double dTrackEta = 0.;
145  double dTrackMaxPt = 0.;
146  for( unsigned int iNumTrack = 0; iNumTrack < xTau.nTracks(); iNumTrack++)
147  {
148  if (xTau.track(iNumTrack)->pt() > dTrackMaxPt)
149  {
150  dTrackMaxPt = xTau.track(iNumTrack)->pt();
151  dTrackEta = xTau.track(iNumTrack)->eta();
152  }
153  }
154  return dTrackEta;
155 }
156 
157 //______________________________________________________________________________
159 {
160  // return truth tau Pt in GeV
161  const xAOD::TruthParticle* xTruthTau = getTruth(xTau);
162 
163  // if there is a truth tau return pT, otherwise return 0 (getTruth will print an error)
164  static const SG::ConstAccessor<char> accIsHadronicTau ("IsHadronicTau");
165  if (xTruthTau!=nullptr && accIsHadronicTau (*xTruthTau))
166  return xTruthTau->pt()/GeV;
167  else
168  return 0.;
169 }
170 
171 //______________________________________________________________________________
173 {
174  // return truth tau absolute eta
175  const xAOD::TruthParticle* xTruthTau = getTruth(xTau);
176 
177  // if there is a truth tau return absolute eta, otherwise return -5 (getTruth will print an error)
178  static const SG::ConstAccessor<char> accIsHadronicTau ("IsHadronicTau");
179  if (xTruthTau!=nullptr && accIsHadronicTau (*xTruthTau))
180  return std::abs(xTruthTau->eta());
181  else
182  return -5.;
183 }
184 
185 //______________________________________________________________________________
187 {
188  // return truth tau decay mode.
189  int iDecayMode = getTruthDecayMode(xTau);
190  return static_cast<double>(iDecayMode);
191 }
192 
193 //______________________________________________________________________________
195 {
197  static const SG::ConstAccessor<Link_t> accTruthParticleLink("truthParticleLink");
198  if (!accTruthParticleLink(xTau))
199  {
200  Error("TauAnalysisTools::getTruth", "No truth match information available. Please run TauTruthMatchingTool first");
201  }
202 
203  const Link_t xTruthTauLink = accTruthParticleLink(xTau);
204  const xAOD::TruthParticle* xTruthTau = xTruthTauLink.cachedElement();
205 
206  return xTruthTau;
207 }
208 
209 
210 //______________________________________________________________________________
212 {
213  const xAOD::TruthParticle* xTruthTau = getTruth(xTau);
214 
215  static const SG::ConstAccessor<char> accIsHadronicTau ("IsHadronicTau");
216  if (xTruthTau!=nullptr && accIsHadronicTau(*xTruthTau))
217  return getTruthDecayMode(*xTruthTau);
218  else
220 }
221 
222 //______________________________________________________________________________
224 {
225  static const SG::ConstAccessor<size_t> accNumCharged ("numCharged");
226  if (!(accNumCharged.isAvailable(xTruthTau)))
227  {
228  // passed truth particle is not a truth tau
230  }
231 
232  int iCharged = getNTauDecayParticles(xTruthTau,MC::PIPLUS, true) + getNTauDecayParticles(xTruthTau,MC::KPLUS, true);
233  int iNeutral = getNTauDecayParticles(xTruthTau,MC::PI0, true);
234  if (iCharged == 1)
235  {
236  if (iNeutral == 0) return xAOD::TauJetParameters::DecayMode::Mode_1p0n;
237  if (iNeutral == 1) return xAOD::TauJetParameters::DecayMode::Mode_1p1n;
238  if (iNeutral >= 2) return xAOD::TauJetParameters::DecayMode::Mode_1pXn;
239  }
240  else if (iCharged == 3)
241  {
242  if (iNeutral == 0) return xAOD::TauJetParameters::DecayMode::Mode_3p0n;
243  if (iNeutral >= 1) return xAOD::TauJetParameters::DecayMode::Mode_3pXn;
244  }
245 
246  if (iCharged == 2 or iCharged == 4 or iCharged == 5)
248  if (iCharged == 0 or iCharged >=6)
250 
251  // if you got here, something should have gone wrong
253 }
254 
255 //______________________________________________________________________________
256 int TauAnalysisTools::getNTauDecayParticles(const xAOD::TruthParticle& xTruthTau, int iPdgId, bool bCompareAbsoluteValues)
257 {
258  int iNum = 0;
259  static const SG::ConstAccessor<std::vector<int> > accDecayModeVector("DecayModeVector");
260  if (!accDecayModeVector.isAvailable(xTruthTau))
261  {
262  Warning("TauAnalysisTools::getNTauDecayParticles", "passed truth particle is not a truth tau, return 0");
263  return 0;
264  }
265 
266  for(auto iPdgId2 : accDecayModeVector(xTruthTau))
267  if (!bCompareAbsoluteValues)
268  {
269  if (iPdgId2 == iPdgId) iNum++;
270  }
271  else
272  {
273  if (std::abs(iPdgId2) == std::abs(iPdgId)) iNum++;
274  }
275  return iNum;
276 }
277 
278 //______________________________________________________________________________
279 bool TauAnalysisTools::testFileForEOFContainsCharacters(const std::string& sFileName)
280 {
281  // returns true if last line in file is empty or the line starts with the
282  // number sign #
283 
284  std::ifstream fInputFile;
285  fInputFile.open(sFileName);
286  if(!fInputFile.is_open())
287  return true;
288 
289  fInputFile.seekg(-1,fInputFile.end);
290 
291  bool bKeepLooping = true;
292  while(bKeepLooping)
293  {
294  char ch;
295  fInputFile.get(ch);
296 
297  if((int)fInputFile.tellg() <= 1)
298  {
299  fInputFile.seekg(0);
300  bKeepLooping = false;
301  }
302  else if(ch == '\n')
303  bKeepLooping = false;
304  else
305  fInputFile.seekg(-2,fInputFile.cur);
306  }
307 
308  std::string sLastLine;
309  getline(fInputFile,sLastLine);
310  fInputFile.close();
311 
312  return (sLastLine.size() == 0 or sLastLine[0] == '#');
313 }
314 
315 //______________________________________________________________________________
316 void TauAnalysisTools::createPi0Vectors(const xAOD::TauJet* xTau, std::vector<TLorentzVector>& vPi0s)
317 {
318  // reset the pi0s
319  vPi0s.clear();
320 
321  // Since the PFO links as they come out of reconstruction, only correspond to
322  // calorimeter clusters, whereas we want the consts_pi0 vectors to correspond
323  // to real pi0s, we need to be careful to collect the PFOs correctly to pi0s
324  // for the cases where number of pi0s does not match to the decay mode:
325  size_t iNumPi0PFO = xTau->nPi0PFOs();
326 
327  int iDecayMode = -1;
328 
330  {
331  Error("TauAnalysisTools::createPi0Vectors", "Failed to retrieve panTauDetail decay mode.");
332  return;
333  }
334 
335  if (iDecayMode == xAOD::TauJetParameters::DecayMode::Mode_1p1n && iNumPi0PFO > 1)
336  {
337  // TODO: find out if the pi0 mass is defined elsewhere in atlas code!
338  // float fMassPi0 = 134.98;
339  float fMassPi0Squared = 18219.6004;
340 
341  // combine both photons (with 0 mass from Pantau) to one pi0 vector:
342  const xAOD::PFO* xPfo1 = xTau->pi0PFO(0);
343  const xAOD::PFO* xPfo2 = xTau->pi0PFO(1);
344  vPi0s.push_back(xPfo1->p4() + xPfo2->p4());
345 
346  // re-set the mass to one pi0:
347  double dNewMomentum = std::sqrt(vPi0s[0].E() * vPi0s[0].E() - fMassPi0Squared);
348  vPi0s[0].SetPxPyPzE(vPi0s[0].Vect().Unit().Px() * dNewMomentum,
349  vPi0s[0].Vect().Unit().Py() * dNewMomentum,
350  vPi0s[0].Vect().Unit().Pz() * dNewMomentum,
351  vPi0s[0].E());
352  }
353  else if (iDecayMode == xAOD::TauJetParameters::DecayMode::Mode_1pXn && iNumPi0PFO == 1)
354  {
355  // make a single pi0 from a PFO that contains two pi0s:
356  const xAOD::PFO* xPfo = xTau->pi0PFO(0);
357  // add the 2-pi0 vector preliminarily to the pi0vector:
358  vPi0s.push_back(xPfo->p4());
359 
360  // re-set the mass back to one pi0:
361  double dNewMomentum = std::sqrt(vPi0s[0].E() / 2 * vPi0s[0].E() / 2 - vPi0s[0].M() / 2. * vPi0s[0].M() / 2.);
362  vPi0s[0].SetVectM(vPi0s[0].Vect() * (dNewMomentum / vPi0s[0].P()), vPi0s[0].M() / 2.);
363 
364  // create another pi0 from the same vector:
365  vPi0s.push_back(vPi0s[0]);
366  }
367  else
368  {
369  // if it's not any of the special cases above then just collect the PFOs:
370  for (size_t iPFO = 0; iPFO < iNumPi0PFO; iPFO++)
371  {
372  vPi0s.push_back(xTau->pi0PFO(iPFO)->p4());
373  }
374  }
375 }
376 
377 
378 //______________________________________________________________________________
379 void TauAnalysisTools::correctedPi0Vectors(const xAOD::TauJet* xTau, std::vector<TLorentzVector>& correctedPi0s, TLorentzVector& TauP4){
380  //reset the pi0s
381  correctedPi0s.clear();
382 
383  int iDecayMode = -1;
384 
386  {
387  Error("TauAnalysisTools::correctedPi0Vectors", "Failed to retrieve panTauDetail decay mode.");
388  return;
389  }
390 
391  //Reading in the pi0 vector from createPi0Vectors
392  std::vector<TLorentzVector> vPi0s;
393  createPi0Vectors(xTau,vPi0s);
394 
396  //Adding up Pi0 P4s from createPi0Vectors
397  TLorentzVector Sum_vPi0s;
398  for(unsigned int i = 0; i < vPi0s.size() ; i++){
399  Sum_vPi0s += vPi0s[i];
400  }
401 
402  //Get sum of the chargedPFO (i.e. tau track) p4
403  TLorentzVector Sum_ChrgPFOP4;
404  for(const xAOD::TauTrack* track : xTau->tracks()) {
405  Sum_ChrgPFOP4 += track->p4();
406  }
407 
408  //Get tau FinalCalib P4 (explicitly requiring p4(xAOD::TauJetParameters::TauCalibType::FinalCalib) should be superfluous, as FinalCalib is the default p4)
409  TLorentzVector FinalCalibP4 = xTau->p4();
410 
411  //Calculate the difference 3-vector between FinalCalib and Sum of chargedPFOP4
412  double px = FinalCalibP4.Px() - Sum_ChrgPFOP4.Px();
413  double py = FinalCalibP4.Py() - Sum_ChrgPFOP4.Py();
414  double pz = FinalCalibP4.Pz() - Sum_ChrgPFOP4.Pz();
415 
416  double p_correctedPi0s = std::sqrt( std::pow(px,2.) + std::pow(py,2.) + std::pow(pz,2.) );
417  double p_vPi0s = Sum_vPi0s.P();
418 
419  //Calucate scale factor for the pi0 3-vector momentum
420  double X = p_correctedPi0s/p_vPi0s;
421 
422  //Scale the pi0s with X and recalculate the new pi0 energy
423  double px_scaled, py_scaled, pz_scaled, e;
424  double mPi0 = 134.977;
425  for(unsigned int i = 0; i < vPi0s.size() ; i++){
426  px_scaled = vPi0s[i].Px() * X;
427  py_scaled = vPi0s[i].Py() * X;
428  pz_scaled = vPi0s[i].Pz() * X;
429  e = std::sqrt( std::pow(px_scaled,2.) + std::pow(py_scaled,2.) + std::pow(pz_scaled,2.) + std::pow(mPi0,2.) );
430 
431  //Append the corrected pi0P4 to correctedPi0s
432  TLorentzVector P4_correctedPi0s;
433  P4_correctedPi0s.SetPxPyPzE(px_scaled,py_scaled,pz_scaled,e);
434  correctedPi0s.push_back(P4_correctedPi0s);
435  }
436  }else{
437  correctedPi0s = vPi0s;
438  }
439 
440  //Correct angles between pi0s for 1pXn decays with 1 cluster
441  if(iDecayMode == xAOD::TauJetParameters::DecayMode::Mode_1pXn && xTau->nPi0PFOs() == 1){
442 
443  //Get Function of Delta R between the two Pi0s
444  TF1 DeltaRdist("DeltaRdist", "pol3", 0, 67500);
445  DeltaRdist.SetParameter(0, 0.07924);
446  DeltaRdist.SetParameter(1, -2.078/1000000.);
447  DeltaRdist.SetParameter(2, 2.619/100000000000.);
448  DeltaRdist.SetParameter(3, -1.238/10000000000000000.);
449 
450  //Get Sum of pi0 P4.Pt()
451  TLorentzVector SumPi0_P4;
452  for( unsigned int i = 0 ; i < correctedPi0s.size() ; i++){
453  SumPi0_P4 += correctedPi0s[i];
454  }
455 
456  float SumPi0_pt = SumPi0_P4.Pt();
457 
458  //Get delta R value (mean of true DeltaR distribution)
459  float deltaR;
460  if(SumPi0_pt >= 67500){
461  deltaR = 0.020; // = DeltaRdist.Eval(67500);
462  } else{
463  deltaR = DeltaRdist.Eval(SumPi0_pt);
464  }
465 
466  TLorentzVector correctedPi0_0, correctedPi0_1;
467  correctedPi0_0.SetPtEtaPhiM( correctedPi0s[0].Pt()/cos(0.5*deltaR/std::sqrt(2.0)), correctedPi0s[0].Eta()+0.5*deltaR/std::sqrt(2.0), correctedPi0s[0].Phi()+0.5*deltaR/std::sqrt(2.0), correctedPi0s[0].M() );
468  correctedPi0_1.SetPtEtaPhiM( correctedPi0s[1].Pt()/cos(0.5*deltaR/std::sqrt(2.0)), correctedPi0s[1].Eta()-0.5*deltaR/std::sqrt(2.0), correctedPi0s[1].Phi()-0.5*deltaR/std::sqrt(2.0), correctedPi0s[1].M() );
469 
470  std::vector<TLorentzVector> AngleCorrectedPi0s;
471  AngleCorrectedPi0s.push_back(correctedPi0_0);
472  AngleCorrectedPi0s.push_back(correctedPi0_1);
473 
474  //Reparametrise: Delta R -> mass of pi0 Cluster
475  TLorentzVector PionCluster_angleCorrected = AngleCorrectedPi0s[0]+AngleCorrectedPi0s[1];
476 
477  double dNewMomentum = std::sqrt(PionCluster_angleCorrected.E()/2. * PionCluster_angleCorrected.E()/2. - PionCluster_angleCorrected.M() / 2. * PionCluster_angleCorrected.M() / 2.);
478  correctedPi0s[0].SetVectM(PionCluster_angleCorrected.Vect() * (dNewMomentum / PionCluster_angleCorrected.P()), PionCluster_angleCorrected.M() / 2.);
479  correctedPi0s[1] = correctedPi0s[0];
480  }
481 
482  //Calculate the new tau P4
483  for(const xAOD::TauTrack* track : xTau->tracks()) {
484  TauP4 += track->p4();
485  }
486 
487  for(unsigned int iPi0=0; iPi0 < correctedPi0s.size(); iPi0++) {
488  TauP4 += correctedPi0s[iPi0];
489  }
490 
491 }
492 
493 //______________________________________________________________________________
494 void TauAnalysisTools::truthHadrons(const xAOD::TruthParticle* xTruthTau, std::vector<const xAOD::TruthParticle*>& vChargedHadrons, std::vector<const xAOD::TruthParticle*>& vNeutralHadrons)
495 {
496  vChargedHadrons.clear();
497  vNeutralHadrons.clear();
498 
499  // skip this tau if it has no decay vertex
500  if ( !xTruthTau->hasDecayVtx() )
501  {
502  Warning("TauAnalysisTools::truthHadrons", "Passed truth particle has no decay vertex.");
503  return;
504  }
505 
506  // get vertex and check if it is valid
507  const xAOD::TruthVertex* xDecayVertex = xTruthTau->decayVtx();
508  if (!xDecayVertex)
509  {
510  Warning("TauAnalysisTools::truthHadrons", "Passed truth particle has no valid decay vertex.");
511  return;
512  }
513 
514  // loop over outgoing particles
515  for ( size_t iOutgoingParticle = 0; iOutgoingParticle < xDecayVertex->nOutgoingParticles(); ++iOutgoingParticle )
516  {
517  const xAOD::TruthParticle* xTruthDaughter = xDecayVertex->outgoingParticle(iOutgoingParticle);
518  if (!xTruthDaughter)
519  {
520  Warning("TauAnalysisTools::truthHadrons", "Truth daughter of tau decay was not found. Please ensure that this container has the full tau decay information or produce the TruthTaus container in AtlasDerivation.\nInformation on how to do this can be found here:\nhttps://twiki.cern.ch/twiki/bin/viewauth/AtlasProtected/TauPreRecommendations2015#Accessing_Tau_Truth_Information");
521  return;
522  }
523 
524  // if tau decays into tau this is not a proper tau decay
525  if ( xTruthDaughter->isTau() )
526  {
527  Warning("TauAnalysisTools::truthHadrons", "Tau decays into a tau itself. Skip this decay");
528  return;
529  }
530 
531  // ignore electrons, muons and neutrinos
532  if (xTruthDaughter->isElectron() or xTruthDaughter->isMuon() or xTruthDaughter->isNeutrino())
533  continue;
534 
535  if (xTruthDaughter->isCharged())
536  vChargedHadrons.push_back(xTruthDaughter);
537  else
538  vNeutralHadrons.push_back(xTruthDaughter);
539  }
540 
541  return;
542 
543 }
544 
545 //______________________________________________________________________________
546 void TauAnalysisTools::truthHadrons(const xAOD::TauJet* xTau, std::vector<const xAOD::TruthParticle*>& vChargedHadrons, std::vector<const xAOD::TruthParticle*>& vNeutralHadrons)
547 {
548  vChargedHadrons.clear();
549  vNeutralHadrons.clear();
550 
551  // check if reco tau is a truth hadronic tau
553  static const SG::ConstAccessor<Link_t> accTruthParticleLink("truthParticleLink");
554  if (!accTruthParticleLink.isAvailable(*xTau))
555  {
556  Error("TauAnalysisTools::truthHadrons", "No truth match information available. Please run TauTruthMatchingTool first");
557  }
558 
559  const Link_t xTruthTauLink = accTruthParticleLink(*xTau);
560  const xAOD::TruthParticle* xTruthTau = xTruthTauLink.cachedElement();
561 
562  static const SG::ConstAccessor<char> accIsHadronicTau("IsHadronicTau");
563  if (xTruthTau!=nullptr && accIsHadronicTau(*xTruthTau))
564  {
565  truthHadrons(xTruthTau, vChargedHadrons, vNeutralHadrons);
566  }
567 
568  return;
569 }
570 
571 //______________________________________________________________________________
573 {
575  static const SG::ConstAccessor< Link_t > accTruthParticleLink("truthParticleLink");
576  if (!accTruthParticleLink.isAvailable(xTau))
577  Error("TauAnalysisTools::getTruthParticleType", "No truth match information available. Please run TauTruthMatchingTool first.");
578 
579  const xAOD::TruthParticle* xTruthParticle = xAOD::TauHelpers::getTruthParticle(&xTau);
580  if (xTruthParticle)
581  {
582  if (xTruthParticle->isTau())
583  {
584  static const SG::ConstAccessor<char> accIsHadronicTau("IsHadronicTau");
585  if ((bool)accIsHadronicTau(*xTruthParticle))
586  return TruthHadronicTau;
587  else
588  return TruthLeptonicTau;
589  }
590  if (xTruthParticle->isMuon())
591  return TruthMuon;
592  if (xTruthParticle->isElectron())
593  return TruthElectron;
594  }
595 
596  // TODO: use const xAOD::Jet* xTruthJet = xAOD::TauHelpers::getLink<xAOD::Jet>(&xTau, "truthJetLink");
597  // currently it is unavailable as templated class is not in icc file
598  static const SG::ConstAccessor< ElementLink< xAOD::JetContainer > > accTruthJetLink("truthJetLink");
599  const ElementLink< xAOD::JetContainer > lTruthParticleLink = accTruthJetLink(xTau);
600  if (lTruthParticleLink.isValid())
601  return TruthJet;
602 
603  return Unknown;
604 }
605 
607 {
608  static const SG::ConstAccessor<char> accIsTruthHadronic("IsTruthHadronic");
609  if (!accIsTruthHadronic.isAvailable(xDiTau))
610  Error("TauAnalysisTools::getTruthParticleType", "No truth match information available. Please run DiTauTruthMatchingTool first");
611 
612  TruthMatchedParticleType eTruthMatchedParticleType = Unknown;
613 
614  if (accIsTruthHadronic(xDiTau))
615  eTruthMatchedParticleType = TruthHadronicDiTau;
616 
617  return eTruthMatchedParticleType;
618 }
619 
620 std::vector<const xAOD::TauJet*> TauAnalysisTools::combineTauJetsWithMuonRM(const xAOD::TauJetContainer* taus_std, const xAOD::TauJetContainer* taus_muonRM){
624  // std::string message = "found " + std::to_string(taus_muonRM->size()) + " muon-removal taus";
625  // Info("TauAnalysisTools::getTauJetsWithMuonRM", message.c_str());
626  std::vector<const xAOD::TauJet*> taus_murm_vec(taus_muonRM->begin(), taus_muonRM->end());
627  std::vector<const xAOD::TauJet*> taus_combined;
629  originalTauJetAcc ("originalTauJet");
630  for(const xAOD::TauJet* tau_std : *taus_std){
631  auto replacement_itr = std::find_if(taus_murm_vec.begin(), taus_murm_vec.end(),
632  [&](const xAOD::TauJet* tau_murm){
633  auto link_to_ori_tau = originalTauJetAcc (*tau_murm);
634  if (!link_to_ori_tau.isValid()) { return false; }
635  if (*link_to_ori_tau == tau_std){ return true; }
636  return false;
637  }
638  );
639  if (replacement_itr == taus_murm_vec.end()) { taus_combined.push_back(tau_std); }
640  else {
641  // message = "replacement found at TauJets_MuonRM index " + std::to_string((*replacement_itr)->index()) + " for TauJets index " + std::to_string(tau_std->index());
642  // Info("TauAnalysisTools::getTauJetsWithMuonRM", message.c_str());
643  taus_combined.push_back(*replacement_itr);
644  taus_murm_vec.erase(replacement_itr);
645  // message = std::to_string(taus_murm_vec.size()) + " muon-removal taus left";
646  // Info("TauAnalysisTools::getTauJetsWithMuonRM", message.c_str());
647  }
648  }
649  // Every muon-removal tau should have been used, otherwise there is a problem.
650  assert(taus_murm_vec.empty());
651  return taus_combined;
652 }
xAOD::TruthVertex_v1::nOutgoingParticles
size_t nOutgoingParticles() const
Get the number of outgoing particles.
xAOD::TauJetParameters::Mode_1p0n
@ Mode_1p0n
Definition: TauDefs.h:386
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
TauAnalysisTools
Definition: TruthCollectionMakerTau.h:16
xAOD::TauJetParameters::PanTau_DecayMode
@ PanTau_DecayMode
Definition: TauDefs.h:360
TauAnalysisTools::TruthElectron
@ TruthElectron
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:100
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
sendEI_SPB.ch
ch
Definition: sendEI_SPB.py:35
xAOD::TauJetParameters::Mode_1p1n
@ Mode_1p1n
Definition: TauDefs.h:387
TauAnalysisTools::getTruthDecayMode
xAOD::TauJetParameters::DecayMode getTruthDecayMode(const xAOD::TruthParticle &xTruthTau)
Get the Truth Decay Mode from TruthTau particle.
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:223
TauAnalysisTools::getTruth
const xAOD::TruthParticle * getTruth(const xAOD::TauJet &xTau)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:194
test_pyathena.px
px
Definition: test_pyathena.py:18
xAOD::TruthParticle_v1::isElectron
bool isElectron() const
Whether the particle is an electron (or positron)
TauAnalysisTools::createPi0Vectors
void createPi0Vectors(const xAOD::TauJet *xTau, std::vector< TLorentzVector > &vPi0s)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:316
TauAnalysisTools::truthTauAbsEta
double truthTauAbsEta(const xAOD::TauJet &xTau)
return truth match tau eta (if hadronic truth tau match)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:172
TauAnalysisTools::tauEta
double tauEta(const xAOD::TauJet &xTau)
return tau eta
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:99
xAOD::TauJet_v3::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
TauAnalysisTools::TruthHadronicTau
@ TruthHadronicTau
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:97
TauAnalysisTools::tauPt
double tauPt(const xAOD::TauJet &xTau)
return tau pt in GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:85
TauAnalysisTools::truthTauPt
double truthTauPt(const xAOD::TauJet &xTau)
return truth match tau pt in GeV (if hadronic truth tau match)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:158
DMTest::P
P_v1 P
Definition: P.h:23
xAOD::TauTrack_v1::eta
virtual double eta() const
The pseudorapidity ( ) of the particle.
xAOD::TauJet_v3::etaFinalCalib
double etaFinalCalib() const
xAOD::TauJet_v3::nTracks
size_t nTracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Definition: TauJet_v3.cxx:526
TauAnalysisTools::getNTauDecayParticles
int getNTauDecayParticles(const xAOD::TruthParticle &xTruthTau, int iPdgId, bool bCompareAbsoluteValues)
Count truth matched decay particles of a particular PDGID.
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:256
TauAnalysisTools::tauAbsEta
double tauAbsEta(const xAOD::TauJet &xTau)
return absolute tau eta
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:106
xAOD::TauJet_v3::panTauDetail
bool panTauDetail(TauJetParameters::PanTauDetails panTauDetail, int &value) const
Get and set values of pantau details variables via enum.
Definition: TauJet_v3.cxx:367
Phi
@ Phi
Definition: RPCdef.h:8
SG::ConstAccessor< char >
drawFromPickle.cos
cos
Definition: drawFromPickle.py:36
TauAnalysisTools::finalTauPt
double finalTauPt(const xAOD::TauJet &xTau)
return MVA based tau pt in GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:113
TauAnalysisTools::TruthJet
@ TruthJet
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:101
TauAnalysisTools::Unknown
@ Unknown
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:96
TauAnalysisTools::testFileForEOFContainsCharacters
bool testFileForEOFContainsCharacters(const std::string &sFileName)
returns true if last line in file is empty or the line starts with the number sign
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:279
xAOD::TauJet_v3::nPi0PFOs
size_t nPi0PFOs() const
Get the number of pi0 PFO particles associated with this tau.
Definition: TauJet_v3.cxx:880
TauAnalysisTools::TruthLeptonicTau
@ TruthLeptonicTau
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:98
Monitored::X
@ X
Definition: HistogramFillerUtils.h:24
xAOD::TauJetParameters::Mode_1pXn
@ Mode_1pXn
Definition: TauDefs.h:388
xAOD::TauJet_v3::pi0PFO
const PFO * pi0PFO(size_t i) const
Get the pointer to a given pi0 PFO associated with this tau.
TauAnalysisTools::tauP
double tauP(const xAOD::TauJet &xTau)
return tau P in GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:92
xAOD::TauJetParameters::DecayMode
DecayMode
Definition: TauDefs.h:385
xAOD::TauJet_v3::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
TauAnalysisTools::finalTauP
double finalTauP(const xAOD::TauJet &xTau)
return MVA based tau P in GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:134
TauAnalysisTools::truthDecayMode
double truthDecayMode(const xAOD::TauJet &xTau)
return truth decay mode (if hadronic truth tau match)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:186
xAOD::TruthParticle_v1::hasDecayVtx
bool hasDecayVtx() const
Check for a decay vertex on this particle.
xAOD::TauHelpers::getTruthParticle
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle *, bool debug=false)
return the truthParticle associated to the given IParticle (if any)
Definition: TauxAODHelpers.cxx:10
lumiFormat.i
int i
Definition: lumiFormat.py:85
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAOD::TauJet_v3
Class describing a tau jet.
Definition: TauJet_v3.h:41
Amg::pz
@ pz
Definition: GeoPrimitives.h:40
xAOD::TauJet_v3::track
const TauTrack * track(size_t i, TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged, int *container_index=0) const
Get the pointer to a given tauTrack associated with this tau /*container index needed by trackNonCons...
Definition: TauJet_v3.cxx:450
xAOD::PFO_v1::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: PFO_v1.cxx:95
TauAnalysisTools::truthHadrons
void truthHadrons(const xAOD::TruthParticle *xTruthTau, std::vector< const xAOD::TruthParticle * > &vChargedHadrons, std::vector< const xAOD::TruthParticle * > &vNeutralHadrons)
return charged and neutral daughters of truth tau
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:494
xAOD::TruthParticle_v1::isTau
bool isTau() const
Whether the particle is a tau (or antitau)
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
xAOD::TruthParticle_v1::isCharged
bool isCharged() const
Whether the particle is electrically charged.
xAOD::TauJetParameters::Mode_3p0n
@ Mode_3p0n
Definition: TauDefs.h:389
TauAnalysisTools::TruthMuon
@ TruthMuon
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:99
xAOD::TruthParticle_v1::decayVtx
const TruthVertex_v1 * decayVtx() const
The decay vertex of this particle.
xAOD::TruthVertex_v1
Class describing a truth vertex in the MC record.
Definition: TruthVertex_v1.h:37
Amg::py
@ py
Definition: GeoPrimitives.h:39
xAOD::PFO_v1
Class describing a particle flow object.
Definition: PFO_v1.h:35
TauAnalysisTools::TruthMatchedParticleType
TruthMatchedParticleType
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:95
xAOD::TauTrack_v1::pt
virtual double pt() const
The transverse momentum ( ) of the particle.
VP1PartSpect::E
@ E
Definition: VP1PartSpectFlags.h:21
TauAnalysisTools::correctedPi0Vectors
void correctedPi0Vectors(const xAOD::TauJet *xTau, std::vector< TLorentzVector > &correctedPi0s, TLorentzVector &TauP4)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:379
xAOD::TruthParticle_v1::eta
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
Definition: TruthParticle_v1.cxx:174
DataVector::end
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
Prompt::Def::Pt
@ Pt
Definition: VarHolder.h:76
TauAnalysisTools::finalTauAbsEta
double finalTauAbsEta(const xAOD::TauJet &xTau)
return MVA based absolute tau eta
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:127
xAOD::TauTrack_v1
Definition: TauTrack_v1.h:27
xAOD::TauJet_v3::p4
virtual FourMom_t p4() const
The full 4-momentum of the particle.
Definition: TauJet_v3.cxx:97
TauAnalysisTools::tauLeadTrackEta
double tauLeadTrackEta(const xAOD::TauJet &xTau)
return leading charge tau track eta
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:141
xAOD::TruthParticle_v1::isMuon
bool isMuon() const
Whether the particle is a muon (or antimuon)
TauAnalysisTools::getTruthParticleType
TruthMatchedParticleType getTruthParticleType(const xAOD::TauJet &xTau)
return TauJet match type
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:572
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
xAOD::DiTauJet_v1
Definition: DiTauJet_v1.h:31
xAOD::TauJetParameters::Mode_3pXn
@ Mode_3pXn
Definition: TauDefs.h:390
xAOD::TruthParticle_v1::pt
virtual double pt() const override final
The transverse momentum ( ) of the particle.
Definition: TruthParticle_v1.cxx:166
SG::ConstAccessor::isAvailable
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
xAOD::TruthParticle_v1::isNeutrino
bool isNeutrino() const
Whether the particle is a neutrino (or antineutrino)
xAOD::TauJetParameters::Mode_Error
@ Mode_Error
Definition: TauDefs.h:393
xAOD::track
@ track
Definition: TrackingPrimitives.h:512
ConstAccessor.h
Helper class to provide constant type-safe access to aux data.
xAOD::TauJetParameters::Mode_NotSet
@ Mode_NotSet
Definition: TauDefs.h:392
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
xAOD::TauJetParameters::FinalCalib
@ FinalCalib
Definition: TauDefs.h:346
xAOD::TauJet_v3::ptFinalCalib
double ptFinalCalib() const
makeComparison.deltaR
float deltaR
Definition: makeComparison.py:36
TauAnalysisTools::combineTauJetsWithMuonRM
std::vector< const xAOD::TauJet * > combineTauJetsWithMuonRM(const xAOD::TauJetContainer *taus_std, const xAOD::TauJetContainer *taus_muonRM)
combine the standard taujets container with the muon removal container
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:620
xAOD::TruthVertex_v1::outgoingParticle
const TruthParticle_v1 * outgoingParticle(size_t index) const
Get one of the outgoing particles.
Definition: TruthVertex_v1.cxx:119
xAOD::TauJet_v3::tracks
std::vector< const TauTrack * > tracks(TauJetParameters::TauTrackFlag flag=TauJetParameters::TauTrackFlag::classifiedCharged) const
Get the v<const pointer> to a given tauTrack collection associated with this tau.
Definition: TauJet_v3.cxx:493
HelperFunctions.h
Eta
@ Eta
Definition: RPCdef.h:8
TauAnalysisTools::TruthHadronicDiTau
@ TruthHadronicDiTau
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/TauAnalysisTools/Enums.h:102
HepMCHelpers.h
TauAnalysisTools::finalTauEta
double finalTauEta(const xAOD::TauJet &xTau)
return MVA based tau eta
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:120
DataVector::begin
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
xAOD::TauJetParameters::Mode_Other
@ Mode_Other
Definition: TauDefs.h:391
TauAnalysisTools::split
void split(const std::string &sInput, const char cDelim, std::vector< std::string > &vOut)
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:23