14#include "CLHEP/Units/SystemOfUnits.h"
30 std::stringstream sSS(sInput);
32 while (std::getline(sSS, sItem, cDelim))
33 vOut.push_back(sItem);
39 std::stringstream sSS(rEnv.GetValue(sKey.c_str(),
""));
41 while (std::getline(sSS, sItem, cDelim))
42 vOut.push_back(sItem);
48 std::stringstream sSS(rEnv.GetValue(sKey.c_str(),
""));
50 while (std::getline(sSS, sItem, cDelim))
51 vOut.push_back(
size_t(stoi(sItem)));
57 std::stringstream sSS(rEnv.GetValue(sKey.c_str(),
""));
59 while (std::getline(sSS, sItem, cDelim))
60 vOut.push_back(stoi(sItem));
66 std::stringstream sSS(rEnv.GetValue(sKey.c_str(),
""));
68 while (std::getline(sSS, sItem, cDelim))
69 vOut.push_back(stoi(sItem));
75 std::stringstream sSS(rEnv.GetValue(sKey.c_str(),
""));
77 while (std::getline(sSS, sItem, cDelim))
78 vOut.push_back(stof(sItem));
84 std::stringstream sSS(rEnv.GetValue(sKey.c_str(),
""));
86 while (std::getline(sSS, sItem, cDelim))
87 vOut.push_back(stod(sItem));
120 if (xTruthTau!=
nullptr && accIsHadronicTau (*xTruthTau))
121 return (accPtVis(*xTruthTau)/
GeV);
133 if (xTruthTau!=
nullptr && accIsHadronicTau (*xTruthTau))
134 return std::abs(xTruthTau->
eta());
144 return static_cast<double>(iDecayMode);
153 if (xTruthTau!=
nullptr && accIsHadronicTau(*xTruthTau))
177 else if (iCharged == 3)
183 if (iCharged == 2 or iCharged == 4 or iCharged == 5)
185 if (iCharged == 0 or iCharged >=6)
199 Warning(
"TauAnalysisTools::getNTauDecayParticles",
"passed truth particle is not a truth tau, return 0");
203 for(
auto iPdgId2 : accDecayModeVector(xTruthTau))
204 if (!bCompareAbsoluteValues)
206 if (iPdgId2 == iPdgId) iNum++;
210 if (std::abs(iPdgId2) == std::abs(iPdgId)) iNum++;
221 std::ifstream fInputFile;
222 fInputFile.open(sFileName);
223 if(!fInputFile.is_open())
226 fInputFile.seekg(-1,fInputFile.end);
228 bool bKeepLooping =
true;
234 if(
static_cast<int>(fInputFile.tellg()) <= 1)
237 bKeepLooping =
false;
240 bKeepLooping =
false;
242 fInputFile.seekg(-2,fInputFile.cur);
245 std::string sLastLine;
246 getline(fInputFile,sLastLine);
249 return (sLastLine.size() == 0 or sLastLine[0] ==
'#');
262 size_t iNumPi0PFO = xTau->
nPi0PFOs();
268 Error(
"TauAnalysisTools::createPi0Vectors",
"Failed to retrieve panTauDetail decay mode.");
280 vPi0s.push_back(xPfo1->
p4() + xPfo2->
p4());
283 double dNewMomentum = std::sqrt(vPi0s[0].E() * vPi0s[0].E() - fMassPi0Squared);
284 vPi0s[0].SetPxPyPzE(vPi0s[0].Vect().Unit().Px() * dNewMomentum,
285 vPi0s[0].Vect().Unit().Py() * dNewMomentum,
286 vPi0s[0].Vect().Unit().Pz() * dNewMomentum,
294 vPi0s.push_back(xPfo->
p4());
297 double dNewMomentum = std::sqrt(vPi0s[0].E() / 2 * vPi0s[0].E() / 2 - vPi0s[0].M() / 2. * vPi0s[0].M() / 2.);
298 vPi0s[0].SetVectM(vPi0s[0].Vect() * (dNewMomentum / vPi0s[0].
P()), vPi0s[0].M() / 2.);
301 vPi0s.push_back(vPi0s[0]);
306 for (
size_t iPFO = 0; iPFO < iNumPi0PFO; iPFO++)
308 vPi0s.push_back(xTau->
pi0PFO(iPFO)->
p4());
317 correctedPi0s.clear();
323 Error(
"TauAnalysisTools::correctedPi0Vectors",
"Failed to retrieve panTauDetail decay mode.");
328 std::vector<TLorentzVector> vPi0s;
333 TLorentzVector Sum_vPi0s;
334 for(
unsigned int i = 0; i < vPi0s.size() ; i++){
335 Sum_vPi0s += vPi0s[i];
339 TLorentzVector Sum_ChrgPFOP4;
341 Sum_ChrgPFOP4 += track->track()->p4();
345 TLorentzVector FinalCalibP4 = xTau->
p4();
348 double px = FinalCalibP4.Px() - Sum_ChrgPFOP4.Px();
349 double py = FinalCalibP4.Py() - Sum_ChrgPFOP4.Py();
350 double pz = FinalCalibP4.Pz() - Sum_ChrgPFOP4.Pz();
352 double p_correctedPi0s = std::sqrt( std::pow(px,2.) + std::pow(py,2.) + std::pow(pz,2.) );
353 double p_vPi0s = Sum_vPi0s.P();
356 double X = p_correctedPi0s/p_vPi0s;
359 double px_scaled, py_scaled, pz_scaled, e;
361 for(
unsigned int i = 0; i < vPi0s.size() ; i++){
362 px_scaled = vPi0s[i].Px() * X;
363 py_scaled = vPi0s[i].Py() * X;
364 pz_scaled = vPi0s[i].Pz() * X;
365 e = std::sqrt( std::pow(px_scaled,2.) + std::pow(py_scaled,2.) + std::pow(pz_scaled,2.) + std::pow(mPi0,2.) );
368 TLorentzVector P4_correctedPi0s;
369 P4_correctedPi0s.SetPxPyPzE(px_scaled,py_scaled,pz_scaled,e);
370 correctedPi0s.push_back(P4_correctedPi0s);
373 correctedPi0s = std::move(vPi0s);
380 TF1 DeltaRdist(
"DeltaRdist",
"pol3", 0, 67500);
381 DeltaRdist.SetParameter(0, 0.07924);
382 DeltaRdist.SetParameter(1, -2.078/1000000.);
383 DeltaRdist.SetParameter(2, 2.619/100000000000.);
384 DeltaRdist.SetParameter(3, -1.238/10000000000000000.);
387 TLorentzVector SumPi0_P4;
388 for(
unsigned int i = 0 ; i < correctedPi0s.size() ; i++){
389 SumPi0_P4 += correctedPi0s[i];
392 float SumPi0_pt = SumPi0_P4.Pt();
396 if(SumPi0_pt >= 67500){
399 deltaR = DeltaRdist.Eval(SumPi0_pt);
402 TLorentzVector correctedPi0_0, correctedPi0_1;
403 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() );
404 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() );
406 std::vector<TLorentzVector> AngleCorrectedPi0s;
407 AngleCorrectedPi0s.push_back(correctedPi0_0);
408 AngleCorrectedPi0s.push_back(correctedPi0_1);
411 TLorentzVector PionCluster_angleCorrected = AngleCorrectedPi0s[0]+AngleCorrectedPi0s[1];
413 double dNewMomentum = std::sqrt(PionCluster_angleCorrected.E()/2. * PionCluster_angleCorrected.E()/2. - PionCluster_angleCorrected.M() / 2. * PionCluster_angleCorrected.M() / 2.);
414 correctedPi0s[0].SetVectM(PionCluster_angleCorrected.Vect() * (dNewMomentum / PionCluster_angleCorrected.P()), PionCluster_angleCorrected.M() / 2.);
415 correctedPi0s[1] = correctedPi0s[0];
420 TauP4 += track->track()->p4();
423 for(
unsigned int iPi0=0; iPi0 < correctedPi0s.size(); iPi0++) {
424 TauP4 += correctedPi0s[iPi0];
435 Error(
"TauAnalysisTools::getTruthParticleType",
"No truth match information available. Please run TauTruthMatchingTool first.");
440 if (xTruthParticle->
isTau())
443 if (
static_cast<bool>(accIsHadronicTau(*xTruthParticle)))
448 if (xTruthParticle->
isMuon())
458 if (lTruthParticleLink.
isValid())
468 Error(
"TauAnalysisTools::getTruthParticleType",
"No truth match information available. Please run DiTauTruthMatchingTool first");
472 if (accIsTruthHadronic(xDiTau))
475 return eTruthMatchedParticleType;
484int classifyAncestor(
const xAOD::TruthParticle* particle, std::set<const xAOD::TruthParticle *>& visited)
486 if (!particle || visited.count(particle))
488 visited.insert(particle);
493 if (particle->isBottomHadron())
495 else if (particle->isCharmHadron())
497 else if (particle->isLightHadron())
501 if (particle->nParents() == 0)
505 int bestClass = thisClass;
509 if (particle->nParents() == 1)
511 int ancClass = classifyAncestor(grandparent, visited);
513 if (ancClass > 0 && (bestClass == 0 || ancClass <= bestClass))
514 bestClass = ancClass;
526 Error(
"TauAnalysisTools::tauOrigin",
"No truth match information available. Please run TauTruthMatchingTool first.");
537 std::set<const xAOD::TruthParticle *> seen;
538 while (seen.insert(xTruthCandidate).second)
544 if (parent->pdgId() == xTruthCandidate->
pdgId())
545 xTruthCandidate = parent;
553 std::set<const xAOD::TruthParticle *> visited;
554 return classifyAncestor(xTruthCandidate, visited);
563 std::vector<const xAOD::TauJet*> taus_murm_vec(taus_muonRM->
begin(), taus_muonRM->
end());
564 std::vector<const xAOD::TauJet*> taus_combined;
566 originalTauJetAcc (
"originalTauJet");
568 auto replacement_itr = std::find_if(taus_murm_vec.begin(), taus_murm_vec.end(),
570 auto link_to_ori_tau = originalTauJetAcc (*tau_murm);
571 if (!link_to_ori_tau.isValid()) { return false; }
572 if (*link_to_ori_tau == tau_std){
return true; }
576 if (replacement_itr == taus_murm_vec.end()) { taus_combined.push_back(tau_std); }
580 taus_combined.push_back(*replacement_itr);
581 taus_murm_vec.erase(replacement_itr);
587 assert(taus_murm_vec.empty());
588 return taus_combined;
Scalar deltaR(const MatrixBase< Derived > &vec) const
ATLAS-specific HepMC functions.
ElementLink< xAOD::TruthParticleContainer > Link_t
A number of constexpr particle constants to avoid hardcoding them directly in various places.
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
bool isValid() const
Check if the element can be found.
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
virtual FourMom_t p4() const
The full 4-momentum of the particle.
double etaFinalCalib() const
const PFO * pi0PFO(size_t i) const
Get the pointer to a given pi0 PFO associated with this tau.
virtual FourMom_t p4() const
The full 4-momentum of the particle.
size_t nPi0PFOs() const
Get the number of pi0 PFO particles associated with this tau.
double ptFinalCalib() const
bool panTauDetail(TauJetParameters::PanTauDetails panTauDetail, int &value) const
Get and set values of pantau details variables via enum.
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.
int pdgId() const
PDG ID code.
const TruthParticle_v1 * parent(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
bool isElectron() const
Whether the particle is an electron (or positron).
virtual double eta() const override final
The pseudorapidity ( ) of the particle.
bool isTau() const
Whether the particle is a tau (or antitau).
bool isMuon() const
Whether the particle is a muon (or antimuon).
constexpr double piZeroMassInMeV
the mass of the pi zero (in MeV)
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle *, bool debug=false)
return the truthParticle associated to the given IParticle (if any)
PFO_v1 PFO
Definition of the current "pfo version".
TauTrack_v1 TauTrack
Definition of the current version.
TauJet_v3 TauJet
Definition of the current "tau version".
TruthParticle_v1 TruthParticle
Typedef to implementation.
DiTauJet_v1 DiTauJet
Definition of the current version.
TauJetContainer_v3 TauJetContainer
Definition of the current "taujet container version".