ATLAS Offline Software
TruthTools.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3  */
4 
5 // Filename: TruthTools.h
6 // Description:
7 // Author: Fabian Wilk
8 // Created: Wed Feb 4 11:04:23 2015
9 
10 #ifndef _TOP_PARTICLE_LEVEL_TRUTHTOOLS_H_
11 #define _TOP_PARTICLE_LEVEL_TRUTHTOOLS_H_
12 
13 #include <ostream>
14 #include <iostream>
15 #include <string>
16 
18 #include "xAODMuon/MuonContainer.h"
19 #include "TopEvent/EventTools.h"
21 #include "xAODBase/IParticle.h"
22 
23 namespace top {
24  namespace truth {
25  //Functions to decorate a muon with information on its truth-origin. Particle-level origin added on softmuons if config options SoftMuonAdditionalTruthInfo is True.
26  //Its output should be regarded as experimental and thoroughly tested by analyzers before officially including it in the analysis.
27  //It is strongly suggested to check its output against the true_origin (calculated by the MCTruthClassifier) to ensure behaviour is as expected.
28  //Parton-level added if SoftMuonAdditionalTruthInfo is True and SoftMuonAdditionalTruthInfoCheckPartonOrigin is True.
29  //Parton-level currently only usable on pythia8 and herwig7, will be automatically disabled for other PS generators.
30  //Some decorations are already written in the default output ntuple, check EventSaverFlatNtuple.cxx
31  //Some other are available for usage in custom savers:
32  //<const xAOD::TruthParticle*>("truthMuonLink") -> link to the truth muon associated with reco (can be null if not found)
33  //<top::LepParticleOriginFlag>("LepParticleOriginFlag") -> flag defined in TopEvent/EventTools.h
34  //<top::LepPartonOriginFlag>("LepPartonOriginFlag") -> flag defined in TopEvent/EventTools.h
35  //Then several <const xAOD::TruthParticle*>(...) decorations are also added (pointers are 0 when corresponding particle is not available):
36  //truthMotherLink -> first direct mother of the truth muon
37  //truthFirstNonLeptonMotherLink -> self-explanatory, will be different from truthMotherLink if the muon is from a Tau
38  //truthBMotherLink -> first B-hadron encountered when going back through the chain of ancestors
39  //truthCMotherLink -> first C-hadron encountered when going back through the chain of ancestors
40  //The following are added when using the parton-level flag
41  //truthPartonMotherLink -> link to first b/c quark encountered when going back through the chain of ancestors for muons from Heavy Flavour hadrons decays
42  //truthTopMotherLink, truthWMotherLink, truthZMotherLink, truthPhotonMotherLink, truthHiggsMotherLink, truthBSMMotherLink -> link to first Top/W/Z/gamma*/Higgs/BSM-particle encountered when going back through the chain of ancestors
43 
44  void getTruthMuonHistory(const xAOD::TruthParticle* truth_muon, bool doPartonHistory, SampleXsection::showering shAlgo, bool verbose=false);
45  void getTruthMuonPartonHistory(const xAOD::TruthParticle* truthmu, top::LepParticleOriginFlag lepParticleOriginFlag, const xAOD::TruthParticle* truthmu_Bmother, const xAOD::TruthParticle* truthmu_Cmother, const xAOD::TruthParticle* truthmu_firstNonLeptonMother, SampleXsection::showering shAlgo, bool verbose=false);
46  //helper methods
47  top::LepParticleOriginFlag getTruthMuonFromTauHistory(const xAOD::TruthParticle* tauMother, const xAOD::TruthParticle* &truthmu_Bmother, const xAOD::TruthParticle* &truthmu_Cmother, const xAOD::TruthParticle* &truthmu_firstNonLeptonMother, bool verbose=false);
48  top::LepParticleOriginFlag getTruthMuonFromCharmHistory(const xAOD::TruthParticle* &truthmu_Bmother, const xAOD::TruthParticle* truthmu_Cmother, bool verbose=false);
49 
50  //function that gets the truth muon associated from a reco muon, runs getTruthMuonHistory on it, and then takes care of propagating the decorations
51  void getRecoMuonHistory(const xAOD::Muon* muon, bool doPartonHistory, SampleXsection::showering shAlgo, bool verbose=false);
52 
53  //helper methods
54  const xAOD::TruthParticle* getInitialStateParticle(const xAOD::TruthParticle* truthParticle, bool verbose=false);
55  const xAOD::TruthParticle* getFirstHFHadronOfSameFlavour(const xAOD::TruthParticle* truthParticle, bool verbose=false);
57  //to initialize correctly all decorations to default values
58  void initTruthMuonHistoryInfo(const xAOD::TruthParticle* truth_muon, bool doPartonHistory);
59  void initRecoMuonHistoryInfo(const xAOD::Muon* muon, bool doPartonHistory);
60  //additional method to share common code between the two methods above
61  void initCommonMuonHistoryInfo(const xAOD::IParticle* muon, bool doPartonHistory);
62  //helper methods to copy info from one muon to another
63  void copyTruthMuonHistoryInfo(const xAOD::TruthParticle* tm_origin, const xAOD::TruthParticle* tm_target);
64  void copyRecoMuonHistoryInfo(const xAOD::Muon* m_origin, const xAOD::Muon* m_target);
65  //additional method to share common code between the two methods above
66  void copyCommonMuonHistoryInfo(const xAOD::IParticle* m_origin, const xAOD::IParticle* m_target);
67 
78  std::ostream& os = std::cout,
79  const std::string& prefix = "");
80 
105  inline bool isBHadron(int pdgId) {
106  return((510 < pdgId && pdgId < 555) || // Check for (normal) Mesons / Diquarks
107  (5100 < pdgId && pdgId < 5555) ||// Check for (normal) Baryons
108  (pdgId / 100) % 10 == 5 || // Check exited Mesons (and Baryons with double beauty)
109  (pdgId / 1000) % 10 == 5); // Check exited Baryons
110  }
111 
140  bool isFrom(const xAOD::TruthParticle* truthParticle,
141  const std::vector<int>& parentPDGIds,
142  bool bOnlyDirect = false);
143 
177  bool isFromWZDecay(const xAOD::TruthParticle* truthParticle,
178  bool bOnlyDirect = false);
179 
190  bool isLeptonFromTau(const xAOD::TruthParticle* truthParticle);
191 
197  inline bool isLepton(const xAOD::TruthParticle* truthParticle) {
198  return(10 < truthParticle->absPdgId() && truthParticle->absPdgId() < 17);
199  }
200 
218  bool isNotFromHadron(const xAOD::TruthParticle* truthParticle,
219  bool bOnlyDirect = false, bool bTauIsHadron = false);
220  }
221 }
222 
223 #endif /* _TOP_PARTICLE_LEVEL_TRUTHTOOLS_H_ */
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
top::truth::isNotFromHadron
bool isNotFromHadron(const xAOD::TruthParticle *truthParticle, bool bOnlyDirect, bool bTauIsHadron)
Check whether a given truth particle is not produced in the decay of physical hadrons or their descen...
Definition: TruthTools.cxx:1053
xAOD::muon
@ muon
Definition: TrackingPrimitives.h:195
xAOD::TruthParticle_v1::absPdgId
int absPdgId() const
Absolute PDG ID code (often useful)
top::truth::getFirstHFHadronOfSameFlavour
const xAOD::TruthParticle * getFirstHFHadronOfSameFlavour(const xAOD::TruthParticle *truthParticle, bool verbose)
Definition: TruthTools.cxx:692
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
top::truth::isFrom
bool isFrom(const xAOD::TruthParticle *truthParticle, const std::vector< int > &parentPDGIds, bool bOnlyDirect)
Function to determine whether the input particle was produced in the physical decay of a particle of ...
Definition: TruthTools.cxx:841
IParticle.h
top::truth::copyCommonMuonHistoryInfo
void copyCommonMuonHistoryInfo(const xAOD::IParticle *m_origin, const xAOD::IParticle *m_target)
Definition: TruthTools.cxx:84
SampleXsection.h
top::LepParticleOriginFlag
LepParticleOriginFlag
this enum defines a flag used to understand the particle origin of a lepton (tipically a soft muon),...
Definition: EventTools.h:57
top::truth::getTruthMuonAssociatedToRecoMuon
const xAOD::TruthParticle * getTruthMuonAssociatedToRecoMuon(const xAOD::Muon *muon)
Definition: TruthTools.cxx:110
TruthParticleContainer.h
SampleXsection::showering
showering
Definition: SampleXsection.h:21
top::truth::getTruthMuonFromCharmHistory
top::LepParticleOriginFlag getTruthMuonFromCharmHistory(const xAOD::TruthParticle *&truthmu_Bmother, const xAOD::TruthParticle *truthmu_Cmother, bool verbose)
Definition: TruthTools.cxx:587
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:40
PowhegPy8EG_H2a.pdgId
dictionary pdgId
Definition: PowhegPy8EG_H2a.py:128
xAOD::Muon_v1
Class describing a Muon.
Definition: Muon_v1.h:38
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
top::truth::getTruthMuonFromTauHistory
top::LepParticleOriginFlag getTruthMuonFromTauHistory(const xAOD::TruthParticle *tau, const xAOD::TruthParticle *&truthmu_Bmother, const xAOD::TruthParticle *&truthmu_Cmother, const xAOD::TruthParticle *&truthmu_firstNonLeptonMother, bool verbose)
Definition: TruthTools.cxx:613
top::truth::initTruthMuonHistoryInfo
void initTruthMuonHistoryInfo(const xAOD::TruthParticle *truthmu, bool doPartonHistory)
Definition: TruthTools.cxx:62
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:41
top::truth::initRecoMuonHistoryInfo
void initRecoMuonHistoryInfo(const xAOD::Muon *muon, bool doPartonHistory)
Definition: TruthTools.cxx:56
top::truth::isBHadron
bool isBHadron(int pdgId)
Check if a certain pdg ID corresponds to a B hadron.
Definition: TruthTools.h:105
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
top::truth::getTruthMuonHistory
void getTruthMuonHistory(const xAOD::TruthParticle *truthmu, bool doPartonHistory, SampleXsection::showering shAlgo, bool verbose)
Definition: TruthTools.cxx:200
top::truth::isLepton
bool isLepton(const xAOD::TruthParticle *truthParticle)
Check whether a given truth particle is a lepton.
Definition: TruthTools.h:197
top::truth::getRecoMuonHistory
void getRecoMuonHistory(const xAOD::Muon *muon, bool doPartonHistory, SampleXsection::showering shAlgo, bool verbose)
Definition: TruthTools.cxx:128
ReadFromCoolCompare.os
os
Definition: ReadFromCoolCompare.py:231
top::truth::getInitialStateParticle
const xAOD::TruthParticle * getInitialStateParticle(const xAOD::TruthParticle *truthParticle, bool verbose)
Definition: TruthTools.cxx:752
top::truth::initCommonMuonHistoryInfo
void initCommonMuonHistoryInfo(const xAOD::IParticle *muon, bool doPartonHistory)
Definition: TruthTools.cxx:35
MuonContainer.h
top::truth::isLeptonFromTau
bool isLeptonFromTau(const xAOD::TruthParticle *truthParticle)
Function the check if a particle is a lepton which was produced in the decay of a tau lepton.
Definition: TruthTools.cxx:1044
python.TriggerHandler.verbose
verbose
Definition: TriggerHandler.py:297
top::truth::getTruthMuonPartonHistory
void getTruthMuonPartonHistory(const xAOD::TruthParticle *truthmu, top::LepParticleOriginFlag lepParticleOriginFlag, const xAOD::TruthParticle *truthmu_Bmother, const xAOD::TruthParticle *truthmu_Cmother, const xAOD::TruthParticle *truthmu_firstNonLeptonMother, SampleXsection::showering shAlgo, bool verbose)
Definition: TruthTools.cxx:311
top::truth::isFromWZDecay
bool isFromWZDecay(const xAOD::TruthParticle *truthParticle, bool bOnlyDirect)
Function to determine whether a given truth particle is a result of a decay chain that started in the...
Definition: TruthTools.cxx:924
top::truth::printDecayChain
void printDecayChain(const xAOD::TruthParticle *truthPart, std::ostream &os, const std::string &prefix)
Prints the decay chain leading up to a certain particle to a std::ostream.
Definition: TruthTools.cxx:783
top::truth::copyTruthMuonHistoryInfo
void copyTruthMuonHistoryInfo(const xAOD::TruthParticle *tm_origin, const xAOD::TruthParticle *tm_target)
Definition: TruthTools.cxx:77
top::truth::copyRecoMuonHistoryInfo
void copyRecoMuonHistoryInfo(const xAOD::Muon *m_origin, const xAOD::Muon *m_target)
Definition: TruthTools.cxx:70