ATLAS Offline Software
Loading...
Searching...
No Matches
HadronOriginClassifier.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
7
8namespace {
10 struct Sample {
12
14 Sample(int low, int high, GEN_id gen) :
15 low(low), high(high), gen(gen) {}
16
18 Sample(int id, GEN_id gen) :
19 Sample(id, id, gen) {}
20
21 int low{};
22 int high{};
23 GEN_id gen{GEN_id::Pythia6};
24 };
25}
26
27namespace DerivationFramework{
28
29 HadronOriginClassifier::HadronOriginClassifier(const std::string& t, const std::string& n, const IInterface* p):
30 AthAlgTool(t,n,p)
31 {
32 }
33
35
37 ATH_MSG_INFO("Initialize " );
38 ATH_MSG_INFO("DSID " << m_DSID );
39
40 ATH_CHECK(m_mcName.initialize());
41
42 static const std::vector<Sample> samples = {
43 // all Herwig++/Herwig7 showered samples
44 {346346, 346348, GEN_id::HerwigPP},
45 {410003, GEN_id::HerwigPP}, {410008, GEN_id::HerwigPP}, //aMC@NLO+Hpp
46 {410004, GEN_id::HerwigPP}, {410163, GEN_id::HerwigPP}, //Powheg+Hpp
47 {410232, 410233, GEN_id::HerwigPP}, //first attempt for Powheg+H7 / aMC@NLO+H7
48 {410525, 410530, GEN_id::HerwigPP}, //New Powheg+H7 samples
49 {407037, 407040, GEN_id::HerwigPP}, //Powheg+Hpp MET/HT sliced
50 {410536, 410537, GEN_id::HerwigPP}, {410245, GEN_id::HerwigPP}, //aMC@NLO+H++ , ttbb
51 {410557, 410559, GEN_id::HerwigPP}, // new Powheg+H7, mc16
52 {411082, 411090, GEN_id::HerwigPP}, //Powheg+H7 HF-filtered
53 {407354, 407356, GEN_id::HerwigPP}, //Powheg+H7 ttbar HT-filtered
54 {411233, 411234, GEN_id::HerwigPP}, //Powheg+H7.1.3 ttbar
55 {411316, GEN_id::HerwigPP}, //Powheg+H7 allhad ttbar
56 {411329, 411334, GEN_id::HerwigPP}, //Powheg+H7.1.3 ttbar HF-filtered
57 {411335, 411337, GEN_id::HerwigPP}, //Powheg+H7.1.3 ttbar HT-filtered
58 {412116, 412117, GEN_id::HerwigPP}, //amc@NLO+H7.1.3 ttbar
59 {504329, GEN_id::HerwigPP}, {504333, GEN_id::HerwigPP}, {504341, GEN_id::HerwigPP}, //amc@NLO+H7.2.1 refined ttZ
60 {601239, 601240, GEN_id::HerwigPP},
61 {601668, GEN_id::HerwigPP},
62 {603905, 603906, GEN_id::HerwigPP}, // ttbb Powheg+H7 dilep, ljet, allhad
63 {504337, GEN_id::HerwigPP}, {504345, GEN_id::HerwigPP}, // aMC@NLO+H7 ttZ
64 {526034, GEN_id::HerwigPP}, // aMC@NLO+H7 4tops
65 {600666, 600667, GEN_id::HerwigPP}, // Powheg+H7 ttbar H7UE
66 {601414, 601415, GEN_id::HerwigPP}, // Powheg+H7 ttbar A14
67 {602635, 602635, GEN_id::HerwigPP}, // Powheg+H7 ttH PDF4LHC21
68 {602846, 602849, GEN_id::HerwigPP}, // Powheg+H7 ttW NNPDF30NLO EW
69
70 // all Pythia8 showered samples
71 {304014, GEN_id::Pythia8}, // amc@NLO+P8 3top
72 {346229, 346234, GEN_id::Pythia8}, // amc@NLO+P8 tHjb
73 {410006, GEN_id::Pythia8}, //Powheg+P8 old main31
74 {410081, GEN_id::Pythia8}, //amc@NLO+P8 ttV
75 {410500, GEN_id::Pythia8}, //Powheg+P8 new main31, hdamp=mt
76 {410501, 410508, GEN_id::Pythia8}, //Powheg+P8 new main31, hdamp=1.5m // Boosted samples are included 410507 410508
77 {410511, 410524, GEN_id::Pythia8}, //Powheg+P8 new main31, hdamp=1.5mt, radiation systematics
78 {410531, 410535, GEN_id::Pythia8}, //Powheg+P8 allhad samples
79 {346343, 346345, GEN_id::Pythia8}, //Powheg+P8 ttH
80 {412123, GEN_id::Pythia8}, // MG+P8 ttW
81 {410155, GEN_id::Pythia8}, // aMC@NlO+P8 ttW
82 {410159, 410160, GEN_id::Pythia8}, //aMC@NLO+P8, old settings
83 {410218, 410220, GEN_id::Pythia8}, // aMC@NlO+P8 ttZ
84 {410276, 410278, GEN_id::Pythia8}, // aMC@NlO+P8 ttZ_lowMass
85 {410225, 410227, GEN_id::Pythia8}, {410274, 410275, GEN_id::Pythia8}, //aMC@NLO+P8, new settings
86 {410568, 410569, GEN_id::Pythia8}, // nonallhad boosted c-filtered
87 {410244, GEN_id::Pythia8}, //aMC@NLO+P8, ttbb (old)
88 {410441, 410442, GEN_id::Pythia8}, //new aMC@NLO+P8 mc16, new shower starting scale
89 {410464, 410466, GEN_id::Pythia8}, //new aMC@NLO+P8 mc16, new shower starting scale, no shower weights
90 {410470, 410472, GEN_id::Pythia8}, {410480, 410482, GEN_id::Pythia8}, //new Powheg+P8 mc16
91 {410452, GEN_id::Pythia8}, //new aMC@NLO+P8 FxFx mc16
92 {411073, 411081, GEN_id::Pythia8}, //Powheg+P8 HF-filtered
93 {412043, 412044, GEN_id::Pythia8}, {500326, GEN_id::Pythia8}, //aMC@NLO+P8 4top
94 {412066, 412074, GEN_id::Pythia8}, //aMC@NLO+P8 HF-filtered
95 {411068, 411070, GEN_id::Pythia8}, //Powheg+P8 ttbb
96 {410265, 410267, GEN_id::Pythia8}, //aMC@NLO+P8 ttbb
97 {411178, 411180, GEN_id::Pythia8}, {411275, GEN_id::Pythia8}, //Powheg+P8 ttbb OTF production - ATLMCPROD-7240
98 {501720, GEN_id::Pythia8}, // aMC@NLO+P8 FxFx ttW
99 {600791, 600792, GEN_id::Pythia8}, //Powheg+P8 ttbb - ATLMCPROD-9179
100 {600737, 600738, GEN_id::Pythia8}, //Powheg+P8 ttbb - ATLMCPROD-9179
101 {601226, 601228, GEN_id::Pythia8}, // Powheg+P8 ttbb bornzerodamp cut 5, ATLMCPROD-9694
102 {407342, 407344, GEN_id::Pythia8}, {411391, GEN_id::Pythia8}, //Powheg+P8 ttbar HT-filtered
103 {407345, 407347, GEN_id::Pythia8}, //Powheg+P8 ttbar MET-filtered
104 {407348, 407350, GEN_id::Pythia8}, //aMC@NLO+P8 ttbar HT-filtered
105 {504330, 504332, GEN_id::Pythia8}, {504334, 504336, GEN_id::Pythia8}, {504338, GEN_id::Pythia8}, {504342, 504344, GEN_id::Pythia8}, {504346, GEN_id::Pythia8}, //aMC@NLO+P8 refined ttZ
106 {601491, 601492, GEN_id::Pythia8}, //Pow+Py8 ttbar pTHard variations - ATLMCPROD-10168
107 {601495, 601498, GEN_id::Pythia8}, //Pow+Py8 ttbar pTHard variations - ATLMCPROD-10168
108 {601229, 601230, GEN_id::Pythia8}, // mc23 ttbar dilep, singlelep
109 {601237, GEN_id::Pythia8}, // mc23 ttbar allhad
110 {601398, 601399, GEN_id::Pythia8}, // mc23 ttbar dilep, singlelep hdamp517p5
111 {601491, GEN_id::Pythia8}, {601495, GEN_id::Pythia8}, {601497, GEN_id::Pythia8}, // mc23 ttbar pThard variations, dilep, singlelep, allhad
112 {601783, 601784, GEN_id::Pythia8}, // Powheg+P8 ttbb bornzerodamp cut 5 pThard variations - ATLMCPROD-10527
113 {603003, 603004, GEN_id::Pythia8}, // Powheg+P8 ttbb nominal and pthard1 allhad
114 {603190, 603193, GEN_id::Pythia8}, // Powheg+P8 ttbb nominal and pthard1 dilep, ljet
115 {604482, 604483, GEN_id::Pythia8}, // mc23 Powheg+P8 ttbar recoilToTop
116 {411369, 411374, GEN_id::Pythia8}, // PP8 ttbar Var1
117 {411290, GEN_id::Pythia8}, // PP8 ttbar rb1p05
118 {508792, GEN_id::Pythia8}, // aMC@NLO+P8 ttbar smeftsim
119 {510203, GEN_id::Pythia8}, // aMC@NLO+P8 4tops
120 {522035, 522038, GEN_id::Pythia8}, // aMC@NLO+P8 ttZqq
121 {523243, GEN_id::Pythia8}, // aMC@NLO+P8 4tops
122 {601356, 601357, GEN_id::Pythia8}, // PP8 ttbar Trec
123 {602067, 602072, GEN_id::Pythia8}, // PP8 ttH pthard1/2
124 {602637, GEN_id::Pythia8}, // PP8 ttH PDF4LHC21
125 {602852, 602853, GEN_id::Pythia8}, // PP8 ttH PDF4LHC21 pthard1
126 {602886, 602889, GEN_id::Pythia8}, // PP8 ttW NNPDF23
127 {603851, 603854, GEN_id::Pythia8}, // PP8 ggH
128 {604224, GEN_id::Pythia8}, // PP8 ttH allhad HTop
129
130 // all Sherpa showered samples
131 {410186, 410189, GEN_id::Sherpa}, //Sherpa 2.2.0
132 {410249, 410252, GEN_id::Sherpa}, //Sherpa 2.2.1
133 {410342, 410347, GEN_id::Sherpa}, //Sherpa 2.2.1 sys
134 {410350, 410355, GEN_id::Sherpa}, //Sherpa 2.2.1 sys
135 {410357, 410359, GEN_id::Sherpa}, //Sherpa 2.2.1 sys
136 {410361, 410367, GEN_id::Sherpa}, //Sherpa 2.2.1 sys
137 {410281, 410283, GEN_id::Sherpa}, //Sherpa BFilter
138 {410051, GEN_id::Sherpa}, //Sherpa ttbb (ICHEP sample)
139 {410323, 410325, GEN_id::Sherpa}, {410369, GEN_id::Sherpa}, //New Sherpa 2.2.1 ttbb
140 {364345, 364348, GEN_id::Sherpa}, //Sherpa 2.2.4 (test)
141 {410424, 410427, GEN_id::Sherpa}, //Sherpa 2.2.4
142 {410661, 410664, GEN_id::Sherpa}, //Sherpa 2.2.4 ttbb
143 {421152, 421158, GEN_id::Sherpa}, //Sherpa2.2.8 ttbar
144 {413023, GEN_id::Sherpa}, // sherpa 2.2.1 ttZ
145 {700000, GEN_id::Sherpa}, // Sherpa 2.2.8 ttW
146 {700168, GEN_id::Sherpa}, // Sherpa 2.2.10 ttW
147 {700205, GEN_id::Sherpa}, // Sherpa 2.2.10 ttW EWK
148 {700309, GEN_id::Sherpa}, // Sherpa 2.2.11 ttZ
149 {700051, 700054, GEN_id::Sherpa}, //Sherpa2.2.8 ttbb
150 {700121, 700124, GEN_id::Sherpa}, //Sherpa2.2.10 ttbar
151 {700164, 700167, GEN_id::Sherpa}, //Sherpa2.2.10 ttbb
152 {700807, 700809, GEN_id::Sherpa}, //Sherpa2.2.14 ttbar
153 {700659, 700662, GEN_id::Sherpa}, // Sherpa 2.2.12 ttbar maxHTavrgTopPT
154 {700712, GEN_id::Sherpa}, // Sherpa 2.2.14 4tops muQHT2
155 {700986, 700997, GEN_id::Sherpa}, // Sherpa 2.2.14 ttW
156 {701251, 701259, GEN_id::Sherpa}, // Sherpa ttW
157
158 // everything else from HFDSIDList
159 // and the mc20/mc23 central pages as of Sept 2025
160 {301528, 301532, GEN_id::Pythia6},
161 {301539, GEN_id::Sherpa},
162 {302910, 302924, GEN_id::Sherpa},
163 {303480, 303487, GEN_id::Sherpa},
164 {303722, 303726, GEN_id::Pythia6},
165 {306600, 306617, GEN_id::Sherpa},
166 {307479, 307502, GEN_id::Sherpa},
167 {343362, GEN_id::Pythia6},
168 {343431, 343434, GEN_id::Pythia8},
169 {343637, GEN_id::Pythia6},
170 {343852, 343854, GEN_id::Pythia8},
171 {344171, GEN_id::Pythia6},
172 {345935, GEN_id::Pythia8},
173 {345951, GEN_id::Pythia8},
174 {346031, GEN_id::Pythia8},
175 {407009, 407012, GEN_id::Pythia6},
176 {407029, 407036, GEN_id::Pythia6},
177 {407041, 407048, GEN_id::Pythia8},
178 {407200, 407204, GEN_id::Pythia8},
179 {407320, 407321, GEN_id::Pythia8},
180 {407322, 407323, GEN_id::Pythia6},
181 {407324, 407335, GEN_id::Pythia8},
182 {407351, 407353, GEN_id::Pythia8},
183 {407357, 407359, GEN_id::HerwigPP},
184 {410000, 410002, GEN_id::Pythia6},
185 {410007, GEN_id::Pythia6},
186 {410009, GEN_id::Pythia6},
187 {410021, 410024, GEN_id::Sherpa},
188 {410028, 410029, GEN_id::Pythia8},
189 {410037, 410046, GEN_id::Pythia6},
190 {410052, 410058, GEN_id::Sherpa},
191 {410060, GEN_id::HerwigPP},
192 {410066, 410070, GEN_id::Pythia8},
193 {410073, GEN_id::Pythia8},
194 {410075, GEN_id::Pythia8},
195 {410082, 410084, GEN_id::Pythia8},
196 {410087, 410089, GEN_id::Pythia8},
197 {410111, 410116, GEN_id::Pythia8},
198 {410120, 410121, GEN_id::Pythia6},
199 {410142, 410144, GEN_id::Sherpa},
200 {410156, 410157, GEN_id::Pythia8},
201 {410161, 410162, GEN_id::Pythia6},
202 {410175, 410176, GEN_id::Pythia8},
203 {410178, 410179, GEN_id::Pythia8},
204 {410181, 410182, GEN_id::Pythia8},
205 {410184, 410185, GEN_id::Sherpa},
206 {410190, 410213, GEN_id::Pythia8},
207 {410234, GEN_id::Pythia8},
208 {410248, GEN_id::Pythia8},
209 {410257, 410262, GEN_id::Pythia8},
210 {410284, 410322, GEN_id::Pythia8},
211 {410326, 410339, GEN_id::Sherpa},
212 {410368, GEN_id::Pythia8},
213 {410370, 410394, GEN_id::Pythia8},
214 {410395, 410396, GEN_id::HerwigPP},
215 {410397, 410399, GEN_id::Pythia8},
216 {410404, 410405, GEN_id::Pythia8},
217 {410410, 410413, GEN_id::Pythia8},
218 {410420, 410423, GEN_id::Sherpa},
219 {410428, 410431, GEN_id::Pythia8},
220 {410432, 410433, GEN_id::HerwigPP},
221 {410434, 410435, GEN_id::Pythia8},
222 {410444, 410445, GEN_id::Pythia8},
223 {410446, GEN_id::HerwigPP},
224 {410447, GEN_id::Pythia8},
225 {410467, GEN_id::Pythia8},
226 {410468, GEN_id::HerwigPP},
227 {410469, GEN_id::Pythia8},
228 {410491, 410498, GEN_id::Pythia8},
229 {410509, GEN_id::Pythia8},
230 {410542, GEN_id::Pythia8},
231 {410544, GEN_id::Pythia8},
232 {410545, 410546, GEN_id::HerwigPP},
233 {410555, GEN_id::HerwigPP},
234 {410633, 410637, GEN_id::Pythia8},
235 {410690, 410691, GEN_id::Pythia8},
236 {411000, 411005, GEN_id::Pythia8},
237 {411044, 411059, GEN_id::Pythia8},
238 {411125, 411142, GEN_id::HerwigPP},
239 {411143, 411160, GEN_id::Pythia8},
240 {411168, GEN_id::HerwigPP},
241 {411169, GEN_id::Pythia8},
242 {411235, 411268, GEN_id::Pythia8},
243 {411269, GEN_id::HerwigPP},
244 {411278, GEN_id::Pythia6},
245 {411279, 411281, GEN_id::Pythia8},
246 {411282, GEN_id::HerwigPP},
247 {411286, GEN_id::Pythia8},
248 {411288, 411289, GEN_id::Pythia8},
249 {411292, 411307, GEN_id::Pythia8},
250 {411310, GEN_id::Pythia8},
251 {412008, 412014, GEN_id::Pythia8},
252 {412017, 412025, GEN_id::Pythia8},
253 {412028, 412036, GEN_id::Pythia8},
254 {412039, 412040, GEN_id::Pythia8},
255 {412090, 412092, GEN_id::HerwigPP},
256 {412112, 412114, GEN_id::Pythia8},
257 {412175, GEN_id::HerwigPP},
258 {413005, GEN_id::Sherpa},
259 {413008, GEN_id::Sherpa},
260 {413022, GEN_id::Sherpa},
261 {426072, GEN_id::Pythia6},
262 {426075, 426078, GEN_id::Pythia6},
263 {426082, GEN_id::Pythia6},
264 {426085, 426088, GEN_id::Pythia6},
265 {426090, 426097, GEN_id::Pythia6},
266 {500462, 500463, GEN_id::Pythia8},
267 {500800, GEN_id::Pythia8},
268 {502957, 502958, GEN_id::Pythia8},
269 {504553, GEN_id::HerwigPP},
270 {504554, GEN_id::Pythia8},
271 {504689, GEN_id::HerwigPP},
272 {508772, 508773, GEN_id::Pythia8},
273 {508780, GEN_id::HerwigPP},
274 {508781, GEN_id::Pythia8},
275 {508985, 508986, GEN_id::Pythia8},
276 {510212, 510213, GEN_id::Pythia8},
277 {521379, 521380, GEN_id::Pythia8},
278 {521384, 521385, GEN_id::Pythia8},
279 {522023, 522026, GEN_id::Pythia8},
280 {522027, GEN_id::HerwigPP},
281 {522028, 522030, GEN_id::Pythia8},
282 {522031, GEN_id::HerwigPP},
283 {522032, 522034, GEN_id::Pythia8},
284 {522039, GEN_id::HerwigPP},
285 {522040, 522042, GEN_id::Pythia8},
286 {542859, 542860, GEN_id::Pythia8},
287 {542867, 542868, GEN_id::Pythia8},
288 {545023, 545024, GEN_id::Pythia8},
289 {545025, 545026, GEN_id::HerwigPP},
290 {545790, 545791, GEN_id::Pythia8},
291 {561980, GEN_id::Pythia8},
292 {561982, 561990, GEN_id::Pythia8},
293 {600031, GEN_id::Pythia8},
294 {600638, 600639, GEN_id::Pythia8},
295 {600642, 600643, GEN_id::Pythia8},
296 {600644, 600645, GEN_id::HerwigPP},
297 {600668, GEN_id::HerwigPP},
298 {600787, 600790, GEN_id::HerwigPP},
299 {600793, 600796, GEN_id::Pythia8},
300 {601284, GEN_id::Pythia8},
301 {601403, GEN_id::Pythia8},
302 {601407, GEN_id::Pythia8},
303 {601412, 601413, GEN_id::Pythia8},
304 {601607, GEN_id::HerwigPP},
305 {601656, GEN_id::Pythia8},
306 {601669, 601670, GEN_id::Pythia8},
307 {601672, GEN_id::Pythia8},
308 {601708, GEN_id::Pythia8},
309 {602423, GEN_id::Pythia8},
310 {602636, GEN_id::HerwigPP},
311 {602638, GEN_id::Pythia8},
312 {602646, 602647, GEN_id::Pythia8},
313 {602687, 602688, GEN_id::Pythia8},
314 {602843, 602844, GEN_id::Pythia8},
315 {602850, 602851, GEN_id::Pythia8},
316 {603011, 603013, GEN_id::Pythia8},
317 {603855, 603856, GEN_id::HerwigPP},
318 {603872, 603873, GEN_id::Pythia8},
319 {603986, 603989, GEN_id::Pythia8},
320 {604008, 604009, GEN_id::HerwigPP},
321 {604018, 604021, GEN_id::Pythia8},
322 {604468, 604481, GEN_id::Pythia8},
323 {700706, GEN_id::Sherpa},
324 {700737, 700756, GEN_id::Sherpa},
325 {700810, GEN_id::Sherpa},
326 {701260, 701262, GEN_id::Sherpa},
327 {701265, 701282, GEN_id::Sherpa},
328 {802380, 802381, GEN_id::Pythia8},
329 {950787, GEN_id::Pythia8},
330 };
331
332 // Linear search for sample and assign properties:
333 for (const auto& s : samples) {
334 if (m_DSID>=s.low && m_DSID<=s.high) {
335 m_GenUsed = s.gen;
336 return StatusCode::SUCCESS;
337 }
338 }
339
340 // the default is Pythia6, so no need to list the Pythia6 showered samples
341 // these are:
342 // 410000-410002
343 // 410007, 410009, 410120-410121
344 // 301528-301532
345 // 303722-303726
346 // 407009-407012
347 // 407029-407036
348 // 410120
349 // 426090-426097
350 // 429007
352
353 return StatusCode::SUCCESS;
354 }
355
356 /*
357 --------------------------------------------------------------------------------------------------------------------------------------
358 ------------------------------------------------------------- Hadron Map -------------------------------------------------------------
359 --------------------------------------------------------------------------------------------------------------------------------------
360 */
361
362 // Define the function GetOriginMap that determines the origin of the hadrons.
363 std::map<const xAOD::TruthParticle*, DerivationFramework::HadronOriginClassifier::HF_id> HadronOriginClassifier::GetOriginMap(const EventContext& ctx) const {
364 // Create a set of maps to store the information about the hadrons and the partons
365 std::map<const xAOD::TruthParticle*, int> mainHadronMap; // Map with main hadrons and their flavor.
366 std::map<const xAOD::TruthParticle*, HF_id> partonsOrigin; // Map with partons and their category (from top, W, H, MPI, FSR, extra).
367 std::map<const xAOD::TruthParticle*, const xAOD::TruthParticle*> hadronsPartons; // Map with hadrons and their matched parton.
368 std::map<const xAOD::TruthParticle*, HF_id> hadronsOrigin; // Map with hadrons and their category (from top, W, H, MPI, FSR, extra)
369 // Fill the maps mainHadronMap and partonsOrigin
370 buildPartonsHadronsMaps(ctx, mainHadronMap, partonsOrigin);
371 // Create two maps to know which partons and hadrons have already been matched.
372 std::vector<const xAOD::TruthParticle*> matched_partons;
373 std::vector<const xAOD::TruthParticle*> matched_hadrons;
374 // Use a while to go through the HF hadrons in mainHadronMap and partons in partonsOrigin.
375 while (matched_partons.size()<partonsOrigin.size() && matched_hadrons.size()<mainHadronMap.size()){
376 // Create a float variable to store the DeltaR between a parton and the closest hadron.
377 float dR=999.;
378 // Create two pointers for TruthParticle type to go through the partons and hadrons.
379 const xAOD::TruthParticle* hadron=nullptr;
380 const xAOD::TruthParticle* parton=nullptr;
381 // Use a for to go through the partonsOrigin.
382 for(std::map<const xAOD::TruthParticle*, HF_id>::iterator itr = partonsOrigin.begin(); itr!=partonsOrigin.end(); ++itr){
383 // Check if the parton has already been matched to an hadron.
384 if(std::find(matched_partons.begin(), matched_partons.end(), (*itr).first) != matched_partons.end()) continue;
385 // Extract the pt of the parton.
386 TVector3 v, vtmp;
387 if ((*itr).first->pt()>0.)
388 v.SetPtEtaPhi((*itr).first->pt(),(*itr).first->eta(),(*itr).first->phi());
389 else // Protection against FPE from eta and phi calculation
390 v.SetXYZ(0.,0.,(*itr).first->pz());
391 // Use a for to go through the HF hadrons in mainHadronMap.
392 for(std::map<const xAOD::TruthParticle*, int>::iterator it = mainHadronMap.begin(); it!=mainHadronMap.end(); ++it){
393 // Check if the hadron has already been matched to a parton.
394 if(std::find(matched_hadrons.begin(), matched_hadrons.end(), (*it).first) != matched_hadrons.end()) continue;
395 // Check if the hadron's flavour matches the one of the parton.
396 if((*it).second != (*itr).first->absPdgId()) continue;
397 // Extract the pt of the hadron.
398 vtmp.SetPtEtaPhi((*it).first->pt(),(*it).first->eta(),(*it).first->phi());
399 // Compute Delta R between hadron and parton and store in dR if it is smaller than the current value.
400 // Also store the parton and hadron in the pointers that have been previous created.
401 if(vtmp.DeltaR(v) < dR){
402 dR = vtmp.DeltaR(v);
403 hadron = (*it).first;
404 parton = (*itr).first;
405 }
406 }//loop hadrons
407 }//loop partons
408 // Add the matched part-hadron pair in the corresponding maps.
409 matched_partons.push_back(parton);
410 matched_hadrons.push_back(hadron);
411 hadronsPartons[ hadron ] = parton;
412 }
413
414 // Use a for to go through the HF hadrons in mainHadronMap.
415 for(std::map<const xAOD::TruthParticle*, int>::iterator it = mainHadronMap.begin(); it!=mainHadronMap.end(); ++it){
416 // Extract the current hadron.
417 const xAOD::TruthParticle* hadron = (*it).first;
418 // Check if the hadron has been matched to a parton.
419 // If it has been matched to any hadron, use it to determine the origin.
420 // Otherwise, the hadron is considered extra.
421 if(hadronsPartons.find(hadron)!=hadronsPartons.end()){
422 hadronsOrigin[hadron] = partonsOrigin[ hadronsPartons[hadron] ];
423 } else{
424 hadronsOrigin[hadron] = extrajet;
425 }
426 }
427 return hadronsOrigin;
428 }
429
430 // Define the function buildPartonsHadronsMaps that determines the flavour of the hadrons and the origin of the partons.
431 void HadronOriginClassifier::buildPartonsHadronsMaps(const EventContext& ctx, std::map<const xAOD::TruthParticle*,int>& mainHadronMap, std::map<const xAOD::TruthParticle*,HF_id>& partonsOrigin) const {
432 // Extract the TruthParticles container.
433 SG::ReadHandle<xAOD::TruthEventContainer> xTruthEventContainer(m_mcName, ctx);
434 if (!xTruthEventContainer.isValid()) {
435 ATH_MSG_WARNING("Could not retrieve " <<m_mcName);
436 }
437
438 // Create a container with TruthParticles to store the hadrons that has already been saved.
439 std::set<const xAOD::TruthParticle*> usedHadron;
440 for ( const auto* truthevent : *xTruthEventContainer ) {
441 // Use a for to go through the TruthParticles.
442 for(unsigned int i = 0; i < truthevent->nTruthParticles(); i++){
443 // Extract the i-th particle.
444 const xAOD::TruthParticle* part = truthevent->truthParticle(i);
445 if(!part) continue;
446 // Simulated particles are not considered.
447 if(HepMC::is_simulation_particle(part)) break;
448 // Create a set of boolean variables to indicate the type of particle.
449 bool isbquark = false; // The particle is a b-quark.
450 bool iscquark = false; // The particle is a c-quark.
451 bool isHFhadron = false; // The particle is a HF hadron.
452 // Extract the pdgid of the particle and use it to determine the type of particle.
453 int pdgid = part->absPdgId();
454 if( MC::isBottom(pdgid) ){
455 isbquark=true;
456 }
457 else if( MC::isCharm(pdgid) ){
458 iscquark=true;
459 }
460 else if(MC::isBottomHadron(part) || MC::isCharmHadron(part)){
461 isHFhadron=true;
462 }
463 else{
464 continue;
465 }
466 // For HF quarks (b or c), check their category.
467 // The category is determined looking for the parents.
468 if(isbquark){
469 // In this case, the parton is a b-quark.
470 // Check the category of the b-quark.
471 if(isDirectlyFromWTop(part)){
472 partonsOrigin[ part ] = b_from_W;
473 }
474 else if(isDirectlyFromTop(part)){
475 partonsOrigin[ part ] = b_from_top;
476 }
477 else if((IsHerwigPP()||IsSherpa())&&isDirectlyFSR(part)){
478 partonsOrigin[ part ] = b_FSR;
479 }
480 else if(IsPythia8()&&isDirectlyFSRPythia8(part)){
481 partonsOrigin[ part ] = b_FSR;
482 }
483 else if(IsPythia6()&&isDirectlyFSRPythia6(part)){
484 partonsOrigin[ part ] = b_FSR;
485 }
486 else if(IsPythia6()&&isDirectlyMPIPythia6(part)){
487 partonsOrigin[ part ] = b_MPI;
488 }
489 else if(IsPythia8()&&isDirectlyMPIPythia8(part)){
490 partonsOrigin[ part ] = b_MPI;
491 }
492 else if(IsSherpa()&&isDirectlyMPISherpa(part)){
493 partonsOrigin[ part ] = b_MPI;
494 }
495 }
496 if(iscquark){
497 // In this case, the parton is a c-quark.
498 // Check the category of the b-quark.
499 if(isDirectlyFromWTop(part)){
500 partonsOrigin[ part ] = c_from_W;
501 }
502 else if(isDirectlyFromTop(part)){
503 partonsOrigin[ part ] = c_from_top;
504 }
505 else if((IsHerwigPP()&&IsSherpa())&&isDirectlyFSR(part)){
506 partonsOrigin[ part ] = c_FSR;
507 }
508 else if(IsPythia8()&&isDirectlyFSRPythia8(part)){
509 partonsOrigin[ part ] = c_FSR;
510 }
511 else if(IsPythia6()&&isDirectlyFSRPythia6(part)){
512 partonsOrigin[ part ] = c_FSR;
513 }
514 else if(IsPythia6()&&isDirectlyMPIPythia6(part)){
515 partonsOrigin[ part ] = c_MPI;
516 }
517 else if(IsPythia8()&&isDirectlyMPIPythia8(part)){
518 partonsOrigin[ part ] = c_MPI;
519 }
520 else if(IsSherpa()&&isDirectlyMPISherpa(part)){
521 partonsOrigin[ part ] = c_MPI;
522 }
523 }
524 // The HF hadrons are stored in the map mainHadronMap if they are not repeated.
525 if(isHFhadron && !isCHadronFromB(part)){
526 // In this case, the particle is a HF hadron but not a C-Hadron from a B-hadron.
527 // If the hadron is not in usedHadron, then add it in mainHadronMap with fillHadronMap function.
528 if(usedHadron.insert(part).second) {
529 fillHadronMap(usedHadron, mainHadronMap,part,part);
530 }
531 }
532 }//loop on particles
533 }//loop on truthevent container
534 }
535
536 /*
537 ---------------------------------------------------------------------------------------------------------------------------------------
538 ------------------------------------------------------------ Particle Type ------------------------------------------------------------
539 ---------------------------------------------------------------------------------------------------------------------------------------
540 */
541 bool HadronOriginClassifier::isCHadronFromB(const xAOD::TruthParticle* part, std::shared_ptr<std::set<const xAOD::TruthParticle*>> checked ) const{
542 if(!MC::isCharmHadron(part)) return false;
543 if (!checked) checked = std::make_shared<std::set<const xAOD::TruthParticle*>>();
544 checked ->insert(part);
545
546 for(unsigned int i=0; i<part->nParents(); ++i){
547 const xAOD::TruthParticle* parent = part->parent(i);
548 if(!parent) continue;
549 if(checked->count(parent)) continue;
550 checked->insert(parent);
551 if( MC::isBottomHadron(parent) ){
552 return true;
553 }
554 if(MC::isCharmHadron(parent)){
555 if(isCHadronFromB(parent))return true;
556 }
557 }
558
559 return false;
560 }
561
562 // Define the function fillHadronMap that fills the map of hadrons with their flavour.
563 void HadronOriginClassifier::fillHadronMap(std::set<const xAOD::TruthParticle*>& usedHadron, std::map<const xAOD::TruthParticle*,int>& mainHadronMap, const xAOD::TruthParticle* mainhad, const xAOD::TruthParticle* ihad, bool decayed) const {
564 // Fist, check that the consdired hadron has a non-null pointer
565 if (!ihad) return;
566 usedHadron.insert(ihad);
567 // Create two variables to indicate the flavour of the parents and childrens particles that will be considered.
568 // Create a boolean to indicate if the particles considered are from the final state.
569 int parent_flav,child_flav;
570 bool isFinal = true;
571 // Check if the considered hadron has children.
572 if(!ihad->nChildren()) return;
573 // Use a for to go through the children.
574 for(unsigned int j=0; j<ihad->nChildren(); ++j){
575 // Extract the j-th children.
576 const xAOD::TruthParticle* child = ihad->child(j);
577 if(!child) continue;
578 if(decayed){
579 fillHadronMap(usedHadron, mainHadronMap,mainhad,child,true);
580 isFinal=false;
581 }
582 else{
583 child_flav = std::abs(MC::leadingQuark(child));
584 if(child_flav!=4 && child_flav!=5) continue;
585 parent_flav = std::abs(MC::leadingQuark(mainhad));
586 if(child_flav!=parent_flav) continue;
587 fillHadronMap(usedHadron, mainHadronMap,mainhad,child);
588 isFinal=false;
589 }
590 }
591
592 if(isFinal && !decayed){
593 mainHadronMap[mainhad]=std::abs(MC::leadingQuark(mainhad));
594 for(unsigned int j=0; j<ihad->nChildren(); ++j){
595 const xAOD::TruthParticle* child = ihad->child(j);
596 if(!child) continue;
597 fillHadronMap(usedHadron, mainHadronMap,mainhad,child,true);
598 }
599 }
600 }
601
602 /*
603 ---------------------------------------------------------------------------------------------------------------------------------------
604 ----------------------------------------------------------- Particle Origin -----------------------------------------------------------
605 ---------------------------------------------------------------------------------------------------------------------------------------
606 */
607
608 // Define the function isFromTop that indicates if a particle comes from top.
609
611 // Find the first parent of the considered particle that is different from the particle.
612 const xAOD::TruthParticle* initpart = findInitial(part);
613 // Check if this parent comes from the top with function isDirectlyFromTop.
614 return isDirectlyFromTop(initpart);
615 }
616
617 // Define the function isDirectlyFromTop that indicates if a particle comes from the direct decay of top.
619 // First, make sure the consdired particle has a non-null pointer and it has parents.
620 // Otherwise, return false.
621 if(!part || !part->nParents()) return false;
622 // Go through the parents of the particle.
623 for(unsigned int i=0; i<part->nParents(); ++i){
624 // Extract the i-th parent.
625 const xAOD::TruthParticle* parent = part->parent(i);
626 if(!parent) continue;
627 // If the i-th parent is a top, then return true
628 if( MC::isTop(parent) ) return true;
629 }
630 // If a top is no the parent, then return false.
631 return false;
632 }
633
634 // Define the function isFromWTop that indicates if a particle comes from the decay chain t->Wb.
635
637 // Find the first parent of the considered particle that is different from the particle.
638 const xAOD::TruthParticle* initpart = findInitial(part);
639 return isDirectlyFromWTop(initpart);
640 }
641
642 // Define the function isDirectlyFromWTop that indicates if a particle comes from the direct decay of a W from a top.
644 // First, make sure the consdired particle has a non-null pointer and it has parents.
645 // Otherwise, return false.
646 if(!part || !part->nParents()) return false;
647 // Use a for to go though the parents.
648 for(unsigned int i=0; i<part->nParents(); ++i){
649 // Get the i-th parent.
650 const xAOD::TruthParticle* parent = part->parent(i);
651 if(!parent) continue;
652 if( MC::isW(parent)){
653 if( isFromTop(parent) ) return true;
654 }
655 }
656 // In this case, none of the parents of the particle is a W from top.
657 // Hence, return false.
658 return false;
659 }
660
662 if(!part->nParents()) return false;
663 for(unsigned int i=0; i<part->nParents(); ++i){
664 const xAOD::TruthParticle* parent = part->parent(i);
665 if(!parent) continue;
666 if( MC::isPhoton(parent) || parent->absPdgId()<MC::BQUARK ) return true;
667 }
668 return false;
669 }
670
672 const xAOD::TruthParticle* initpart = findInitial(part);
673 return isDirectlyFromGluonQuark(initpart);
674 }
675
677 if(!part->nParents()) return false;
678 for(unsigned int i=0; i<part->nParents(); ++i){
679 const xAOD::TruthParticle* parent = part->parent(i);
680 if(!parent) continue;
681 if(!MC::isW(parent)) continue;
682 if(MC::isCharm(part)){
683 //trick to get at least 50% of PowhegPythia c from FSR
684 if(part->pdgId()==-(parent->pdgId())/6){
685 if( isFromGluonQuark(parent) ) return true;
686 }
687 }
688 else{
689 if( isFromGluonQuark(parent) ) return true;
690 }
691 }
692 return false;
693 }
694
696 if(!part->nParents()) return false;
697 for(unsigned int i=0; i<part->nParents(); ++i){
698 const xAOD::TruthParticle* parent = part->parent(i);
699 if(!parent) continue;
700 if( MC::isPhoton(parent) || MC::isGluon(parent) ){
701 if( isFromQuarkTop( parent ) ) return true;
702 }
703 }
704 return false;
705 }
706
708 if(!part->nParents()) return false;
709 for(unsigned int i=0; i<part->nParents(); ++i){
710 const xAOD::TruthParticle* parent = part->parent(i);
711 if(!parent) continue;
712 if( parent->absPdgId()<MC::TQUARK ) {
713 if(isFromTop(parent)){
714 return true;
715 }
716 else if(isFromWTop(parent)){
717 return true;
718 }
719 }
720 }
721
722 return false;
723 }
724
726 const xAOD::TruthParticle* initpart = findInitial(part);
727 return isDirectlyFromQuarkTop(initpart);
728 }
729
730 // Define the function isDirectlyFSRPythia8 that indicates if a particle comes from Final State Radiation in samples generated with Pythia8.
731
733 // First, check if the particle has parents and return false if it does not.
734 if(!part->nParents()) return false;
735 // Use a for to go through the parents.
736 for(unsigned int i=0; i<part->nParents(); ++i){
737
738 // Extract the i-th parent.
739
740 const xAOD::TruthParticle* parent = part->parent(i);
741 if(!parent) continue;
742 if( MC::isPhoton(parent) || MC::isGluon(parent) ){
743 if( isFromQuarkTopPythia8( parent ) ) return true;
744 }
745 }
746 // In this case, no parent from the particle is a gluon or a photon coming from a top
747 // Hence, the particle is not from FSR and false is not returned.
748 return false;
749 }
750
751 // Define the function isDirectlyFromQuarkTopPythia8 that indicates if a particle comes from direct decay of the top in samples generated with Pythia8.
753 // First, make sure the consdired particle has a non-null pointer and it has parents.
754 // Otherwise, return false.
755 if(!part->nParents()) return false;
756 // Use a for to go through the parents.
757 for(unsigned int i=0; i<part->nParents(); ++i){
758 // Extract the i-th parent.
759 const xAOD::TruthParticle* parent = part->parent(i);
760 if(!parent) continue;
761 // Check if the parent is a quark different from the top.
762 if( parent->absPdgId()<MC::TQUARK ) {
763 // In this case, the parent is a quark different from top.
764 // Check if it comes from the decay chain of the t->Wb.
765 // If it is the case, return true.
766 if(isFromWTop(parent)){
767 return true;
768 }
769 }
770 }
771 // In this case, any of the parents of the particle comes from t->Wb chaing.
772 // Hence, the particle does not come from the top directly and false is returned.
773 return false;
774 }
775
776 // Define the function isFromQuarkTopPythia8 that indicates if a particle comes from top in samples generated with Pythia8.
778 // Find the first parent of the considered particle that is different from the particle.
779 const xAOD::TruthParticle* initpart = findInitial(part);
780 // Check if this parent comes from the top with function isDirectlyFromQuarkTopPythia8.
781 return isDirectlyFromQuarkTopPythia8(initpart);
782 }
783
785 if(!part->nParents()) return false;
786 for(unsigned int i=0; i<part->nParents(); ++i){
787 const xAOD::TruthParticle* parent = part->parent(i);
788 if(!parent) continue;
789 if( parent->absPdgId() == MC::PROTON && MC::isPhysical(part) ) return true;
790 }
791 return false;
792 }
793
795 const xAOD::TruthParticle* initpart = findInitial(part);
796 return MC::Pythia8::isConditionC(initpart);
797 }
798
800 if(!part->hasProdVtx()) return false;
801 const xAOD::TruthVertex* vertex = part->prodVtx();
802 return HepMC::status(vertex) == 2;
803 }
804
805 /*
806 --------------------------------------------------------------------------------------------------------------------------------------
807 ---------------------------------------------------------- Particle Parents ----------------------------------------------------------
808 --------------------------------------------------------------------------------------------------------------------------------------
809 */
810
811 // Define the function findInitial which finds the first parent of a particle that is not the particle itself.
812 const xAOD::TruthParticle* HadronOriginClassifier::findInitial(const xAOD::TruthParticle* part, std::shared_ptr<std::set<const xAOD::TruthParticle*>> checked ) const{
813 // If the particle has no parent, return the particle.
814 if(!part->nParents()) return part;
815 if (!checked) checked = std::make_shared<std::set<const xAOD::TruthParticle*>>();
816 // Use a for to go through the parents.
817 for(unsigned int i=0; i<part->nParents(); ++i){
818 // Extract the i-th parent.
819 const xAOD::TruthParticle* parent = part->parent(i);
820 if(!parent) continue;
821 if(checked->count(parent)) continue;
822 checked->insert(parent);
823 // If the parent has the same pdgId as the particle, then it means that the parent is the same as the considered particle.
824 // This happens if the particle irradiates for example.
825 // In this case, try to look for the first parent of i-th parent that is being considered.
826 // Repeat the process until you find a particle different from the considred one or that has no parent.
827
828 if( part->pdgId() == parent->pdgId() ){
829 return findInitial(parent, std::move(checked));
830 }
831 }
832 // In this case, no parent different from the considered particle has been found.
833 // Hence, return the particle.
834 return part;
835 }
836
837}//namespace
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
ATLAS-specific HepMC functions.
Handle class for reading from StoreGate.
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
void buildPartonsHadronsMaps(const EventContext &ctx, std::map< const xAOD::TruthParticle *, int > &mainHadronMap, std::map< const xAOD::TruthParticle *, HF_id > &partonsOrigin) const
static bool isDirectlyMPIPythia6(const xAOD::TruthParticle *part)
bool isDirectlyFromQuarkTop(const xAOD::TruthParticle *part) const
static bool isDirectlyFromTop(const xAOD::TruthParticle *part)
HadronOriginClassifier(const std::string &t, const std::string &n, const IInterface *p)
bool isFromGluonQuark(const xAOD::TruthParticle *part) const
bool isCHadronFromB(const xAOD::TruthParticle *part, std::shared_ptr< std::set< const xAOD::TruthParticle * > > checked=nullptr) const
bool isFromQuarkTop(const xAOD::TruthParticle *part) const
const xAOD::TruthParticle * findInitial(const xAOD::TruthParticle *part, std::shared_ptr< std::set< const xAOD::TruthParticle * > > checked=nullptr) const
bool isDirectlyMPIPythia8(const xAOD::TruthParticle *part) const
bool isFromTop(const xAOD::TruthParticle *part) const
bool isDirectlyFSRPythia8(const xAOD::TruthParticle *part) const
static bool isDirectlyFromGluonQuark(const xAOD::TruthParticle *part)
bool isFromQuarkTopPythia8(const xAOD::TruthParticle *part) const
std::map< const xAOD::TruthParticle *, HF_id > GetOriginMap(const EventContext &ctx) const
bool isDirectlyFromWTop(const xAOD::TruthParticle *part) const
bool isDirectlyFSR(const xAOD::TruthParticle *part) const
SG::ReadHandleKey< xAOD::TruthEventContainer > m_mcName
bool isDirectlyFSRPythia6(const xAOD::TruthParticle *part) const
bool isFromWTop(const xAOD::TruthParticle *part) const
void fillHadronMap(std::set< const xAOD::TruthParticle * > &usedHadron, std::map< const xAOD::TruthParticle *, int > &mainHadronMap, const xAOD::TruthParticle *mainhad, const xAOD::TruthParticle *ihad, bool decayed=false) const
bool isDirectlyFromQuarkTopPythia8(const xAOD::TruthParticle *part) const
static bool isDirectlyMPISherpa(const xAOD::TruthParticle *part)
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const TruthParticle_v1 * child(size_t i) const
Retrieve the i-th mother (TruthParticle) of this TruthParticle.
size_t nChildren() const
Number of children of this particle.
THE reconstruction tool.
int status(const T &p)
bool is_simulation_particle(const T &p)
Method to establish if a particle (or barcode) was created during the simulation (TODO update to be s...
bool isConditionC(const T &p)
bool isCharmHadron(const T &p)
bool isCharm(const T &p)
bool isBottom(const T &p)
bool isPhoton(const T &p)
bool isW(const T &p)
static const int TQUARK
bool isBottomHadron(const T &p)
int leadingQuark(const T &p)
bool isTop(const T &p)
static const int BQUARK
bool isGluon(const T &p)
static const int PROTON
bool isPhysical(const T &p)
Identify if the particle is physical, i.e. is stable or decayed.
TruthVertex_v1 TruthVertex
Typedef to implementation.
Definition TruthVertex.h:15
TruthParticle_v1 TruthParticle
Typedef to implementation.