Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
Truth.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 // This source file implements all of the functions related to Truth
6 // in the SUSYObjDef_xAOD class
7 
8 // Local include(s):
10 
11 // For using the MCTruthClassifier definitions
13 
16 
17 #ifndef XAOD_STANDALONE // For now metadata is Athena-only
19 #endif
20 
21 namespace ST {
22 
23 
25 
26  const int type = acc_truthType(*part);
27  int origin = acc_truthOrigin(*part);
28  int originbkg = 0;
29  if(acc_bkgTruthOrigin.isAvailable(*part)){ //only in SUSY2,3,5 for the moment!
30  originbkg = acc_bkgTruthOrigin(*part);
31  }
32  else{
33  ATH_MSG_DEBUG("::isPrompt() : No bkgTruthOrigin decoration available. Returning false by default.");
34  return false;
35  }
36 
37  //Electrons
38  if( part->type() == xAOD::Type::Electron ){
39  switch(type){
41  if(origin != MCTruthPartClassifier::PhotonConv) return false;
42  if(originbkg == MCTruthPartClassifier::FSRPhot || originbkg == MCTruthPartClassifier::BremPhot) return true;
43  origin = originbkg;
44  /* FALLTHRU */
45  case MCTruthPartClassifier::IsoElectron:
46  return (origin == MCTruthPartClassifier::top
49  || origin == MCTruthPartClassifier::Higgs
54  || origin == MCTruthPartClassifier::NuRMu
56  || origin == MCTruthPartClassifier::LQ
57  || origin == MCTruthPartClassifier::SUSY);
58  default:
59  return false;
60  }
61  // NB: will classify a few muon/quark brems as prompt electrons, but a small effect
62  }
63  if( part->type() == xAOD::Type::Muon ){
65  }
66  else{
67  ATH_MSG_DEBUG("::isPrompt() : Only Electrons supported at the moment!");
68  }
69 
70  //Photons ... ?
71  //Taus ... ?
72  return false;
73 }
74 
75 
76 StatusCode SUSYObjDef_xAOD::FindSusyHP(int& pdgid1, int& pdgid2) const {
77 
78  const xAOD::TruthParticleContainer* truthP = nullptr;
79  bool isTruth3 = false;
80  std::string key_T1 = "TruthParticles";
81  std::string key_T3 = "TruthBSM";
82 
83  ATH_MSG_DEBUG("Contains " << key_T1 << ": " << ((evtStore()->contains<xAOD::TruthParticleContainer>( key_T1 ))?1:0));
84  ATH_MSG_DEBUG("Contains " << key_T3 << ": " << ((evtStore()->contains<xAOD::TruthParticleContainer>( key_T3 ))?1:0));
85 
86  if(evtStore()->contains<xAOD::TruthParticleContainer>( key_T1 )){
87  ATH_CHECK( evtStore()->retrieve(truthP, key_T1) );
88  ATH_MSG_DEBUG("Retrieved " << key_T1 << " : size = " << truthP->size());
89  if (truthP->empty()) { ATH_MSG_WARNING(key_T1 << " is empty. Skipping FindSusyHP."); return StatusCode::SUCCESS; }
90  }
91  else if(evtStore()->contains<xAOD::TruthParticleContainer>( key_T3 )){
92  isTruth3=true;
93  ATH_CHECK( evtStore()->retrieve(truthP, key_T3) );
94  ATH_MSG_DEBUG("Retrieved " << key_T3 << " : size = " << truthP->size());
95  if (truthP->empty()) { ATH_MSG_WARNING(key_T3 << " is empty. Skipping FindSusyHP."); return StatusCode::SUCCESS; }
96  }
97  else {
98  ATH_MSG_WARNING("Neither " << key_T1 << " nor " << key_T3 << " are avaible. Skipping FindSusyHP.");
99  return StatusCode::SUCCESS;
100  }
101 
102  return SUSYObjDef_xAOD::FindSusyHP(truthP, pdgid1, pdgid2, isTruth3);
103 }
104 
105 
106 StatusCode SUSYObjDef_xAOD::FindSusyHP(const xAOD::TruthParticleContainer *truthP, int& pdgid1, int& pdgid2, bool isTruth3) const {
107  if (!truthP) {
108  ATH_MSG_ERROR("Null TruthParticleContainer pointer!!");
109  return StatusCode::FAILURE;
110  }
111  if (truthP->empty()) {
112  ATH_MSG_ERROR("Empty TruthParticleContainer!!");
113  return StatusCode::FAILURE;
114  }
115  if ( !SUSYObjDef_xAOD::FindSusyHardProc(truthP, pdgid1, pdgid2, isTruth3) ) {
116  ATH_MSG_ERROR("Problem finding SUSY hard process");
117  return StatusCode::FAILURE;
118  }
119  if (pdgid1 == 0 || pdgid2 == 0) {
120  ATH_MSG_DEBUG("No sparticles found!");
121  }
122  return StatusCode::SUCCESS;
123 }
124 
125 
126 bool SUSYObjDef_xAOD::FindSusyHardProc(const xAOD::TruthParticleContainer *truthP, int& pdgid1, int& pdgid2, bool isTruth3) {
127 
128  pdgid1 = 0;
129  pdgid2 = 0;
130 
131  //check for TRUTH3 structure first
132  if(isTruth3){
133  if(!truthP || truthP->size()<2){
134  return false;
135  }
136 
137  //get ID of first two BSM particles
138  pdgid1 = (*truthP)[0]->pdgId();
139  pdgid2 = (*truthP)[1]->pdgId();
140  return true;
141  }
142 
143  //go for TRUTH1-like if not...
144  const xAOD::TruthParticle* firstsp(nullptr);
145  const xAOD::TruthParticle* secondsp(nullptr);
146 
147  if (!truthP || truthP->empty()) {
148  return false;
149  }
150  for (const xAOD::TruthParticle* tp : *truthP) {
152 
153  if (tp->nParents() != 0) {
154 
155  if ( !MC::isSUSY(tp->parent(0))) {
156  if (!firstsp) {
157  firstsp = tp;
158  } else if (!secondsp) {
159  secondsp = tp;
160  } else {
161  if (firstsp->nChildren() != 0 && HepMC::is_same_particle(tp,firstsp->child(0))) {
162  firstsp = tp;
163  }
164  else if (secondsp->nChildren() != 0 && HepMC::is_same_particle(tp,secondsp->child(0))) {
165  secondsp = tp;
166  }
167  else if (firstsp->nChildren() != 0 && HepMC::is_same_particle(firstsp->child(0),secondsp)) {
168  firstsp = secondsp;
169  secondsp = tp;
170  }
171  else if (secondsp->nChildren() != 0 && HepMC::is_same_particle(secondsp->child(0),firstsp)) {
172  secondsp = firstsp;
173  firstsp = tp;
174  }
175  }
176  }
177  }
178  }
179  }
180 
181  // quit if no sparticles found
182  if (!firstsp && !secondsp) return true; // should find none or two
183 
184  if (firstsp->nChildren() == 1) {
185  for (const xAOD::TruthParticle* tp : *truthP) {
186  if (HepMC::is_same_particle(tp,firstsp->child(0)) && tp->pdgId() != firstsp->pdgId()) {
187  firstsp = tp;
188  break;
189  }
190  }
191  }
192 
193  if (secondsp->nChildren() == 1) {
194  for (const xAOD::TruthParticle* tp : *truthP) {
195  if (HepMC::is_same_particle(tp,secondsp->child(0)) && tp->pdgId() != secondsp->pdgId()) {
196  secondsp = tp;
197  break;
198  }
199  }
200  }
201 
202  if (MC::isSUSY(firstsp)) pdgid1 = firstsp->pdgId();
203  if (MC::isSUSY(secondsp)) pdgid2 = secondsp->pdgId();
204 
205  // Return gracefully:
206  return true;
207 }
208 
209 
210 StatusCode SUSYObjDef_xAOD::FindSusyHP(const xAOD::TruthEvent *truthE, int& pdgid1, int& pdgid2) const {
211 
212  if (!truthE) {
213  ATH_MSG_ERROR("Null TruthEvent pointer!!");
214  return StatusCode::FAILURE;
215  }
216  if ( !SUSYObjDef_xAOD::FindSusyHardProc(truthE, pdgid1, pdgid2) ) {
217  ATH_MSG_ERROR("Problem finding SUSY hard process");
218  return StatusCode::FAILURE;
219  }
220  if (pdgid1 == 0 || pdgid2 == 0) {
221  ATH_MSG_DEBUG("No sparticles found!");
222  }
223  return StatusCode::SUCCESS;
224 }
225 
226 
227 bool SUSYObjDef_xAOD::FindSusyHardProc(const xAOD::TruthEvent *truthE, int& pdgid1, int& pdgid2) {
228 
229  pdgid1 = 0;
230  pdgid2 = 0;
231 
232  //go for TRUTH1-like ...
233  const xAOD::TruthParticle* firstsp(nullptr);
234  const xAOD::TruthParticle* secondsp(nullptr);
235 
236  for (unsigned int p=0; p < truthE->nTruthParticles(); ++p){
237 
238  const xAOD::TruthParticle* tp = truthE->truthParticle(p);
239 
240  //check ifSUSY particle
242 
243  if (tp->nParents() != 0) {
244  if ( !MC::isSUSY(tp->parent(0))) {
245  if (!firstsp) {
246  firstsp = tp;
247  } else if (!secondsp) {
248  secondsp = tp;
249  } else {
250  if (firstsp->nChildren() != 0 && HepMC::is_same_particle(tp,firstsp->child(0))) {
251  firstsp = tp;
252  }
253  else if (secondsp->nChildren() != 0 && HepMC::is_same_particle(tp,secondsp->child(0))) {
254  secondsp = tp;
255  }
256  else if (firstsp->nChildren() != 0 && HepMC::is_same_particle(firstsp->child(0),secondsp)) {
257  firstsp = secondsp;
258  secondsp = tp;
259  }
260  else if (secondsp->nChildren() != 0 && HepMC::is_same_particle(secondsp->child(0),firstsp)) {
261  secondsp = firstsp;
262  firstsp = tp;
263  }
264  }
265  }
266  }
267  }
268  }
269 
270  // quit if no sparticles found
271  if (!firstsp && !secondsp) return true; // should find none or two
272 
273  if (firstsp->nChildren() == 1) {
274  for (unsigned int p=0; p < truthE->nTruthParticles(); ++p){
275  const xAOD::TruthParticle* tp = truthE->truthParticle(p);
276  if (HepMC::is_same_particle(tp,firstsp->child(0)) && tp->pdgId() != firstsp->pdgId()) {
277  firstsp = tp;
278  break;
279  }
280  }
281  }
282 
283  if (secondsp->nChildren() == 1) {
284  for (unsigned int p=0; p < truthE->nTruthParticles(); ++p){
285  const xAOD::TruthParticle* tp = truthE->truthParticle(p);
286  if (HepMC::is_same_particle(tp,secondsp->child(0)) && tp->pdgId() != secondsp->pdgId()) {
287  secondsp = tp;
288  break;
289  }
290  }
291  }
292 
293  if (MC::isSUSY(firstsp)) pdgid1 = firstsp->pdgId();
294  if (MC::isSUSY(secondsp)) pdgid2 = secondsp->pdgId();
295 
296  // Return gracefully:
297  return true;
298 }
299 
300 
301 bool SUSYObjDef_xAOD::IsTruthBJet(const xAOD::Jet& input) const {
302  //Method to set correctly the IsBjet decoration needed by the JetUncertainties tool
303  bool isBjet = false;
304  if (acc_signal(input)) {
305 
306  int truthlabel(-1);
307  if (!input.getAttribute("HadronConeExclTruthLabelID", truthlabel)) {
308  ATH_MSG_ERROR("Failed to get jet truth label!");
309  }
310 
311  isBjet = std::abs(truthlabel) == 5;
312  }
313 
314  const static SG::Decorator<char> dec_bjet_jetunc("bjet_jetunc"); //added for JetUncertainties usage
315  dec_bjet_jetunc(input) = isBjet;
316 
317  return isBjet;
318 }
319 
320 }
python.PyKernel.retrieve
def retrieve(aClass, aKey=None)
Definition: PyKernel.py:110
LArG4FSStartPointFilter.part
part
Definition: LArG4FSStartPointFilter.py:21
ST::SUSYObjDef_xAOD::isPrompt
bool isPrompt(const xAOD::IParticle *part) const override final
Definition: Truth.cxx:24
NuRMu
@ NuRMu
Definition: TruthClasses.h:73
isGaugino
bool isGaugino(const T &p)
Definition: AtlasPID.h:483
ST::SUSYObjDef_xAOD::IsTruthBJet
bool IsTruthBJet(const xAOD::Jet &input) const override final
Definition: Truth.cxx:301
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
NuREle
@ NuREle
Definition: TruthClasses.h:72
WBosonLRSM
@ WBosonLRSM
Definition: TruthClasses.h:71
ST
Definition: Electrons.cxx:41
xAOD::TruthEventBase_v1::truthParticle
const TruthParticle * truthParticle(size_t index) const
Get a pointer to one of the truth particles.
Definition: TruthEventBase_v1.cxx:50
ParticleTest.tp
tp
Definition: ParticleTest.py:25
PhotonConv
@ PhotonConv
Definition: TruthClasses.h:59
SUSYObjDef_xAOD.h
isSquark
bool isSquark(const T &p)
Definition: AtlasPID.h:434
NuRTau
@ NuRTau
Definition: TruthClasses.h:74
ZBoson
@ ZBoson
Definition: TruthClasses.h:67
xAOD::IParticle
Class providing the definition of the 4-vector interface.
Definition: Event/xAOD/xAODBase/xAODBase/IParticle.h:41
HepMC::is_same_particle
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
Definition: MagicNumbers.h:367
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
WBoson
@ WBoson
Definition: TruthClasses.h:66
FSRPhot
@ FSRPhot
Definition: TruthClasses.h:96
HiggsMSSM
@ HiggsMSSM
Definition: TruthClasses.h:69
AthCommonDataStore< AthCommonMsg< AlgTool > >::evtStore
ServiceHandle< StoreGateSvc > & evtStore()
The standard StoreGateSvc (event store) Returns (kind of) a pointer to the StoreGateSvc.
Definition: AthCommonDataStore.h:85
MCTruthClassifierDefs.h
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
SG::Decorator< char >
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
xAOD::TruthEvent_v1
Class describing a signal truth event in the MC record.
Definition: TruthEvent_v1.h:35
LQ
@ LQ
Definition: TruthClasses.h:75
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
IsoMuon
@ IsoMuon
Definition: TruthClasses.h:15
DataVector
Derived DataVector<T>.
Definition: DataVector.h:794
isSUSY
bool isSUSY(const T &p)
PDG rule 11d Fundamental supersymmetric particles are identified by adding a nonzero n to the particl...
Definition: AtlasPID.h:428
xAOD::TruthParticle_v1::nChildren
size_t nChildren() const
Number of children of this particle.
Definition: TruthParticle_v1.cxx:140
MagicNumbers.h
SUSY
@ SUSY
Definition: TruthClasses.h:77
HeavyBoson
@ HeavyBoson
Definition: TruthClasses.h:70
xAOD::TruthEventBase_v1::nTruthParticles
size_t nTruthParticles() const
Get the number of truth particles.
xAOD::TruthParticle_v1::child
const TruthParticle_v1 * child(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
Definition: TruthParticle_v1.cxx:149
isSlepton
bool isSlepton(const T &p)
Definition: AtlasPID.h:465
Muon
struct TBPatternUnitContext Muon
AthAnalysisHelper.h
xAOD::Jet_v1
Class describing a jet.
Definition: Jet_v1.h:57
ST::SUSYObjDef_xAOD::FindSusyHP
StatusCode FindSusyHP(int &pdgid1, int &pdgid2) const
Definition: Truth.cxx:76
ST::SUSYObjDef_xAOD::FindSusyHardProc
static bool FindSusyHardProc(const xAOD::TruthParticleContainer *truthP, int &pdgid1, int &pdgid2, bool isTruth3=false)
Definition: Truth.cxx:126
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Higgs
@ Higgs
Definition: TruthClasses.h:68
top
@ top
Definition: TruthClasses.h:64
xAOD::TruthParticle_v1::pdgId
int pdgId() const
PDG ID code.
DataVector::size
size_type size() const noexcept
Returns the number of elements in the collection.
BkgElectron
@ BkgElectron
Definition: TruthClasses.h:13
DataVector::empty
bool empty() const noexcept
Returns true if the collection is empty.
HepMCHelpers.h
BremPhot
@ BremPhot
Definition: TruthClasses.h:92