ATLAS Offline Software
Loading...
Searching...
No Matches
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
21namespace ST {
22
23
24bool SUSYObjDef_xAOD :: isPrompt(const xAOD::IParticle* part) const {
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 */
46 return (origin == MCTruthPartClassifier::top
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
76StatusCode 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
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 }
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
106StatusCode 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
126bool 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) {
151 if (MC::isSquark(tp) || MC::isSlepton(tp) || MC::isGaugino(tp)) {
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
210StatusCode 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
227bool 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
241 if (MC::isSquark(tp) || MC::isSlepton(tp) || MC::isGaugino(tp)) {
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
301bool 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}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
ATLAS-specific HepMC functions.
ServiceHandle< StoreGateSvc > & evtStore()
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
Helper class to provide type-safe access to aux data.
Definition Decorator.h:59
static bool FindSusyHardProc(const xAOD::TruthParticleContainer *truthP, int &pdgid1, int &pdgid2, bool isTruth3=false)
Definition Truth.cxx:126
StatusCode FindSusyHP(int &pdgid1, int &pdgid2) const
Definition Truth.cxx:76
bool IsTruthBJet(const xAOD::Jet &input) const override final
Definition Truth.cxx:301
Class providing the definition of the 4-vector interface.
const TruthParticle * truthParticle(size_t index) const
Get a pointer to one of the truth particles.
size_t nTruthParticles() const
Get the number of truth particles.
const TruthParticle_v1 * child(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
int pdgId() const
PDG ID code.
size_t nChildren() const
Number of children of this particle.
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:114
bool is_same_particle(const T1 &p1, const T2 &p2)
Method to establish if two particles in the GenEvent actually represent the same particle.
bool isSlepton(const T &p)
bool isSquark(const T &p)
PDG rule 11d Fundamental supersymmetric particles are identified by adding a nonzero n to the particl...
bool isSUSY(const T &p)
bool isGaugino(const T &p)
static const SG::Decorator< char > dec_bjet_jetunc("bjet_jetunc")
static const SG::ConstAccessor< int > acc_truthType("truthType")
static const SG::ConstAccessor< int > acc_truthOrigin("truthOrigin")
static const SG::ConstAccessor< int > acc_bkgTruthOrigin("bkgTruthOrigin")
static const SG::ConstAccessor< char > acc_signal("signal")
@ Muon
The object is a muon.
Definition ObjectType.h:48
@ Electron
The object is an electron.
Definition ObjectType.h:46
Jet_v1 Jet
Definition of the current "jet version".
TruthEvent_v1 TruthEvent
Typedef to implementation.
Definition TruthEvent.h:17
TruthParticle_v1 TruthParticle
Typedef to implementation.
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.