ATLAS Offline Software
Loading...
Searching...
No Matches
JetTruthLabelingTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
13
15 asg::AsgTool(name)
16{}
17
19JetTruthLabelingTool::parseLabel(const std::string& name) {
20 static const std::map<std::string, TruthLabelConfiguration> labels{
21 {"R10TruthLabel_R21Precision_2022v1", TruthLabelConfiguration::R21Precision_2022v1},
22 {"R10TruthLabel_R22v1", TruthLabelConfiguration::R10TruthLabel_R22v1},
23 {"R10WZTruthLabel_R22v1", TruthLabelConfiguration::R10WZTruthLabel_R22v1},
25 {"R4TruthDressedWZLabel", TruthLabelConfiguration::R4TruthDressedWZLabel},
26 {"R4InTimeTruthLabel", TruthLabelConfiguration::R4InTimeTruthLabel},
27 {"R4OutOfTimeTruthLabel", TruthLabelConfiguration::R4OutOfTimeTruthLabel},
28 };
29 auto it = labels.find(name);
30 return it != labels.end() ? it->second : TruthLabelConfiguration::Unknown;
31}
32
34
35 ATH_MSG_INFO("Initializing " << name());
36
38
41 ATH_MSG_ERROR("TruthLabelName " << m_truthLabelName << " is not supported. Exiting...");
42 return StatusCode::FAILURE;
43 }
44
45 print();
46
51
53
54 if(!m_isTruthJetCol){
57 m_truthSplit12_recoKey = m_jetContainerName + "." + m_truthLabelName + "_TruthJetSplit12";
58 m_truthSplit23_recoKey = m_jetContainerName + "." + m_truthLabelName + "_TruthJetSplit23";
59
67
68 if (!m_doLargeRLabels) { //Simple naming for small R
69 m_matchedTruthJet_recoKey = m_jetContainerName + "." + "TruthMatch_Jet";
71 m_matchedTruthJetPt_recoKey = m_jetContainerName + "." + "TruthMatch_pt";
72 m_matchedTruthJetRapidity_recoKey = m_jetContainerName + "." + "TruthMatch_rapidity";
73 m_matchedTruthJetPhi_recoKey = m_jetContainerName + "." + "TruthMatch_phi";
74 m_matchedTruthJetIso_recoKey = m_jetContainerName + "." + "TruthMatch_iso";
75 m_matchedTruthJetDR_recoKey = m_jetContainerName + "." + "TruthMatch_dR";
76 m_matchedPileupTag_recoKey = m_jetContainerName + "." + "TruthMatch_PileupLabel";
77 m_sumPtMatchedHSJets_recoKey = m_jetContainerName + "." + "TruthMatch_HSSumPt";
78 m_sumPtMatchedOOTJets_recoKey = m_jetContainerName + "." + "TruthMatch_OOTSumPt";
79 m_sumPtMatchedITJets_recoKey = m_jetContainerName + "." + "TruthMatch_ITSumPt";
80 }
81
82 m_matchedTruthGroomedJetMass_recoKey = m_jetContainerName + "." + m_truthLabelName + "_TruthMatch_GroomedJetMass";
83 m_matchedTruthGroomedJetPt_recoKey = m_jetContainerName + "." + m_truthLabelName + "_TruthMatch_GroomedJetPt";
84 }
85
86 ATH_CHECK(m_evtInfoKey.initialize());
89
92
93 ATH_CHECK(m_label_truthKey.initialize());
94 ATH_CHECK(m_NB_truthKey.initialize());
95
98
99 ATH_CHECK(m_jetTruthIsolKey.initialize());
100
105
113
118
121
122 return StatusCode::SUCCESS;
123}
124
126 ATH_MSG_INFO("Parameters for " << name());
127
128 ATH_MSG_INFO("xAOD information:");
129 ATH_MSG_INFO("TruthLabelName: " << m_truthLabelName);
130 ATH_MSG_INFO("TruthJetCollectionName: " << m_truthJetCollectionKey.key());
131 ATH_MSG_INFO("dRTruthJet: " << std::to_string(m_dRTruthJet));
132
134 ATH_MSG_INFO("truthGroomedJetCollectionName: " << m_truthGroomedJetCollectionKey.key());
135 }
136}
137
138
140 (const JetTruthLabelingTool& tool, const EventContext& ctx)
141{
142 auto maybeInit = [&] (auto& h,
144 {
145 if (!k.key().empty()) h.emplace (k, ctx);
146 };
147 maybeInit (labelHandle, tool.m_label_truthKey);
148 maybeInit (nbHandle, tool.m_NB_truthKey);
149 maybeInit (labelRecoHandle, tool.m_label_recoKey);
150 maybeInit (nbRecoHandle, tool.m_NB_recoKey);
151 maybeInit (split23Handle, tool.m_truthSplit23_recoKey);
152 maybeInit (split12Handle, tool.m_truthSplit12_recoKey);
153
154 maybeInit (matchedTruthJetHandle, tool.m_matchedTruthJet_recoKey);
155 maybeInit (matchedTruthJetMassHandle, tool.m_matchedTruthJetMass_recoKey);
156 maybeInit (matchedTruthJetPtHandle, tool.m_matchedTruthJetPt_recoKey);
157 maybeInit (matchedTruthJetRapidityHandle, tool.m_matchedTruthJetRapidity_recoKey);
158 maybeInit (matchedTruthJetPhiHandle, tool.m_matchedTruthJetPhi_recoKey);
159 maybeInit (matchedTruthJetIsoHandle, tool.m_matchedTruthJetIso_recoKey);
160 maybeInit (matchedTruthJetDRHandle, tool.m_matchedTruthJetDR_recoKey);
161
162 maybeInit (matchedPileupTagHandle, tool.m_matchedPileupTag_recoKey);
163 maybeInit (sumPtMatchedHSJetsHandle, tool.m_sumPtMatchedHSJets_recoKey);
164 maybeInit (sumPtMatchedOOTJetsHandle, tool.m_sumPtMatchedOOTJets_recoKey);
165 maybeInit (sumPtMatchedITJetsHandle, tool.m_sumPtMatchedITJets_recoKey);
166
167 maybeInit (matchedTruthGroomedMassHandle, tool.m_matchedTruthGroomedJetMass_recoKey);
168 maybeInit (matchedTruthGroomedPtHandle, tool.m_matchedTruthGroomedJetPt_recoKey);
169}
170
172 const xAOD::Jet &jet,
173 const EventContext& ctx ) const
174{
176 bool matchW = false;
177 bool matchZ = false;
178 bool matchH = false;
179 bool matchTop = false;
180
182 int nMatchW = getNGhostParticles( jet, "GhostWBosons" );
183
184 if ( nMatchW ) {
185 matchW = true;
186 }
187
189 int nMatchZ = getNGhostParticles( jet, "GhostZBosons" );
190
191 if ( nMatchZ ) {
192 matchZ = true;
193 }
194
196 int nMatchH = getNGhostParticles( jet, "GhostHBosons" );
197
198 if ( nMatchH ) {
199 matchH = true;
200 }
201
203 int nMatchTop = getNGhostParticles( jet, "GhostTQuarksFinal" );
204
205 if ( nMatchTop ) {
206 matchTop = true;
207 }
208
209 return getLabel( dh, jet, matchH, matchW, matchZ, matchTop, ctx );
210
211}
212
214 const EventContext& ctx = Gaudi::Hive::currentContext();
215 DecorHandles dh (*this, ctx);
216
218 if(m_isTruthJetCol) {
219 return labelTruthJets(dh, jets, ctx);
220 }
221
222 else if (!m_isTruthJetCol && !m_doLargeRLabels) {
223 return labelRecoJets(dh, jets, ctx);
224 }
225
227 else {
228 ATH_CHECK( labelTruthJets(dh, ctx) );
229 return labelRecoJets(dh, jets, ctx);
230 }
231
232 return StatusCode::SUCCESS;
233}
234
236 const xAOD::JetContainer& jets,
237 const EventContext& ctx) const {
238
240
241 bool usePileupJets = true;
242
244 SG::ReadHandle<xAOD::JetContainer> outOfTimeTruthJets;
245 if (!m_doLargeRLabels) {
246 inTimeTruthJets = SG::makeHandle(m_ITJetName, ctx);
247 outOfTimeTruthJets = SG::makeHandle(m_OOTJetName, ctx);
248
249 if (!inTimeTruthJets.isValid() || !outOfTimeTruthJets.isValid()) {
250 ATH_MSG_WARNING("Pileup jet collections unavailable for " << m_truthJetCollectionKey << ". Running without pileup tagger.");
251 usePileupJets = false;
252 }
253 }
254
256
257 SG::ReadHandle<xAOD::JetContainer> truthGroomedJets;
259 truthGroomedJets = SG::makeHandle(m_truthGroomedJetCollectionKey, ctx);
260 }
261
262 const SG::Accessor<int> nbAcc (m_truthLabelName + "_NB");
263 static const SG::ConstAccessor< ElementLink< xAOD::JetContainer > > ParentAcc ("Parent");
264
265 for(const xAOD::Jet *jet : jets) {
266
268 const xAOD::Jet* parent = nullptr;
270 ElementLink<xAOD::JetContainer> element_link = ParentAcc (*jet);
271 if ( element_link.isValid() ) {
272 parent = *element_link;
273 }
274 else {
275 ATH_MSG_ERROR("Unable to get a link to the parent jet! Returning a NULL pointer.");
276 return StatusCode::FAILURE;
277 }
278 }
280 float dRmin = 9999;
281 float oot_dRmin = 9999;
282 float it_dRmin = 9999;
283 float ghostFracNominal = 9;
284 const xAOD::Jet* matchTruthJet = nullptr;
285 const xAOD::Jet* oot_matchTruthJet = nullptr;
286 const xAOD::Jet* it_matchTruthJet = nullptr;
288 float dRminGroomed = 9999;
289 const xAOD::Jet* matchTruthGroomedJet = nullptr;
291 float sumPtMatchedHSJets = 0;
292 float sumPtMatchedOOTJets = 0;
293 float sumPtMatchedITJets = 0;
294 float bestHSpT = -9999;
295 float bestOOTpT = -9999;
296 float bestITpT = -9999;
297 float bestHSpTRatio = -9;
298 float bestOOTpTRatio = -9;
299 float bestITpTRatio = -9;
300 int nMatchedHSJets = 0;
301 int nMatchedOOTJets = 0;
302 int nMatchedITJets = 0;
304 //coverity[UNNECESSARY_STRING_COPY:FALSE]
305 static const SG::ConstAccessor<float> accGhostTruthPt("GhostTruthPt");
306
307 // Ensure that the reco jet has at least one constituent
308 // (and thus a well-defined four-vector)
309 if (jet->numConstituents() > 0) {
310 for (const xAOD::Jet* truthJet : *truthJets) { // Truth jet loop
311
312 // Calculate DR
313 float dR = jet->p4().DeltaR(truthJet->p4(),true);
314 // If parent jet has been retrieved, calculate dR w.r.t. it instead
315 if (parent) dR = parent->p4().DeltaR(truthJet->p4(),true);
316 // Calculate GF
317 if (m_useGhostJetMatch) { // GA matching. Upper bound applied for completeness, but realistically not needed.
318 // Access ghostTruthPt now so it is available for pileup jets
319 float ghostTruthPt = accGhostTruthPt(*jet);
320 float ghostPtFraction = (ghostTruthPt / (truthJet->pt()));
321 if ((ghostPtFraction >= m_recoGhostFrac) && (ghostPtFraction <= (2 - m_recoGhostFrac))) { // All matches
322 nMatchedHSJets += 1;
323 sumPtMatchedHSJets += truthJet->pt();
324 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) { // Best match
325 matchTruthJet = truthJet;
326 ghostFracNominal = ghostPtFraction;
327 }
328 }
329 }
330 else { // If m_dRTruthJet < 0, the closest truth jet is used as matched jet. Otherwise, only match if dR < m_dRTruthJet
331 if (m_dRTruthJet < 0 || dR < m_dRTruthJet) { // All matches
332 nMatchedHSJets += 1;
333 sumPtMatchedHSJets += truthJet->pt();
334 if (dR < dRmin) { // Best match
335 dRmin = dR;
336 matchTruthJet = truthJet;
337 }
338 }
339 }
340 }
341 if (!m_doLargeRLabels && usePileupJets) {
342 for (const xAOD::Jet* ootJet : *outOfTimeTruthJets) { // Out of time pileup truth jet loop
343 float dR = jet->p4().DeltaR(ootJet->p4(), true);
344 if (m_useGhostJetMatch) {
345 float ghostTruthPt = accGhostTruthPt(*jet);
346 float ghostPtFraction = (ghostTruthPt / (ootJet->pt()));
347 if ((ghostPtFraction >= m_recoGhostFrac) && (ghostPtFraction <= (2 - m_recoGhostFrac))) { // All matches
348 nMatchedOOTJets += 1;
349 sumPtMatchedOOTJets += ootJet->pt();
350 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) { // Best match
351 oot_matchTruthJet = ootJet;
352 }
353 }
354 }
355 else {
356 if (dR < m_dRTruthJet) { // All matches
357 nMatchedOOTJets += 1;
358 sumPtMatchedOOTJets += ootJet->pt();
359 if (dR < oot_dRmin) { // Best match
360 oot_dRmin = dR;
361 oot_matchTruthJet = ootJet;
362 }
363 }
364 }
365 }
366 for (const xAOD::Jet* itJet : *inTimeTruthJets) { // In time pileup truth jet loop
367 float dR = jet->p4().DeltaR(itJet->p4(), true);
368 if (m_useGhostJetMatch) {
369 float ghostTruthPt = accGhostTruthPt(*jet);
370 float ghostPtFraction = (ghostTruthPt / (itJet->pt()));
371 if ((ghostPtFraction >= m_recoGhostFrac) && (ghostPtFraction <= (2 - m_recoGhostFrac))) { // All matches
372 nMatchedITJets += 1;
373 sumPtMatchedITJets += itJet->pt();
374 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) { // Best match
375 it_matchTruthJet = itJet;
376 }
377 }
378 }
379 else {
380 if (dR < m_dRTruthJet) { // All matches
381 nMatchedITJets += 1;
382 sumPtMatchedITJets += itJet->pt();
383 if (dR < it_dRmin) { // Best match
384 it_dRmin = dR;
385 it_matchTruthJet = itJet;
386 }
387 }
388 }
389 }
390
391 //#######################################################################################
392 //# PILEUP TAGGER KEY #
393 //# 0: Hard scatter ------------- Best truth jet match has >90% of the total matched pT #
394 //# 1: Mixed hard scatter-------- Match with multiple truth jets, none >90% (no PU) #
395 //# 2: Hard scatter with pileup - Best truth jet <90%, also has pileup matches #
396 //# 3: In time pileup---------- - Best it jet match has > 90 % of the total matched pT #
397 //# 4: Mixed pileup ------------- Match with multiple pileup jets, none >90% (no HS) #
398 //# 5: Out of time pileup------ - Best oot jet match has > 90 % of the total matched pT #
399 //# 6: Other/unknown ------------ Fails all above cases #
400 //#######################################################################################
401
402 //NOTE: HS has 5 GeV pT threshold, 10 GeV and 15 GeV for IT and OOT pileup.
403
404 int nMatchedPUJets = nMatchedOOTJets + nMatchedITJets;
405
406 float totalMatchedpT = sumPtMatchedHSJets + sumPtMatchedOOTJets + sumPtMatchedITJets;
407
408 if (matchTruthJet) {
409 bestHSpT = matchTruthJet->pt();
410 bestHSpTRatio = bestHSpT / totalMatchedpT;
411 }
412 if (oot_matchTruthJet) {
413 bestOOTpT = oot_matchTruthJet->pt();
414 bestOOTpTRatio = bestOOTpT / totalMatchedpT;
415 }
416 if (it_matchTruthJet) {
417 bestITpT = it_matchTruthJet->pt();
418 bestITpTRatio = bestITpT / totalMatchedpT;
419 }
420
421 if (bestHSpTRatio >= 0.9) { //HS
422 pileupTag = SmallRJetPileupLabel::HS;
423 }
424 else if (bestITpTRatio >= 0.9) { //IT
425 pileupTag = SmallRJetPileupLabel::ITPU;
426 }
427 else if (bestOOTpTRatio >= 0.9) { //OOT
428 pileupTag = SmallRJetPileupLabel::OOTPU;
429 }
430 else if (nMatchedPUJets == 0 && nMatchedHSJets > 1) { //Mixed HS
431 pileupTag = SmallRJetPileupLabel::MixHS;
432 }
433 else if (nMatchedPUJets > 0 && nMatchedHSJets > 0) { //HS with pileup
434 pileupTag = SmallRJetPileupLabel::HSPU;
435 }
436 else if (nMatchedPUJets > 1) {//Mixed PU
437 pileupTag = SmallRJetPileupLabel::MixPU;
438 }
439 else { //No match
441 }
442
443 }
444
445 }
446
448 int truthJetNB = -1;
449 float truthJetSplit12 = -9999;
450 float truthJetSplit23 = -9999;
451
452 // Defaults to null EL
454 float truthJetMass = -9999;
455 float truthJetPt = -9999;
456 float truthJetRapidity = -9;
457 float truthJetPhi = -9999;
458 float truthJetIso = -2;
459 float deltaR = -2;
460
461 const xAOD::JetContainer* truthJetCont = truthJets.cptr();
462
463 //If the best match is PU, reassign the truth jet to take variables from
464 switch(pileupTag) {
466 matchTruthJet = it_matchTruthJet;
467 truthJetCont = inTimeTruthJets.cptr();
468 break;
469 }
471 matchTruthJet = oot_matchTruthJet;
472 truthJetCont = outOfTimeTruthJets.cptr();
473 break;
474 }
476 if (bestITpTRatio >= bestOOTpTRatio) {
477 matchTruthJet = it_matchTruthJet;
478 truthJetCont = inTimeTruthJets.cptr();
479 }
480 else {
481 matchTruthJet = oot_matchTruthJet;
482 truthJetCont = outOfTimeTruthJets.cptr();
483 }
484 }
485 default:
486 break;
487 }
488
489 if ( matchTruthJet ) {
490
491 // Can't use the WriteDecorHandle to read --- the decoration may have
492 // been added and locked by a previous algorithm.
493 // Not saving Truth jet decorations for small R
494 if (m_doLargeRLabels) {
495 SG::ConstAccessor<int> labelAcc(dh.labelHandle->auxid());
496 label = labelAcc(*matchTruthJet);
499 if (split23Handle.isAvailable()) truthJetSplit23 = split23Handle(*matchTruthJet);
501 if (split12Handle.isAvailable()) truthJetSplit12 = split12Handle(*matchTruthJet);
502 }
503 if (nbAcc.isAvailable(*matchTruthJet)) truthJetNB = nbAcc(*matchTruthJet);
504 }
505 ATH_MSG_VERBOSE("For reco jet " << jet->index() << ", matched truth jet index " << matchTruthJet->index());
506 truthJetEL = ElementLink<xAOD::JetContainer>(*truthJetCont, matchTruthJet->index(), ctx);
507 truthJetMass = matchTruthJet->m();
508 truthJetPt = matchTruthJet->pt();
509 truthJetRapidity = matchTruthJet->rapidity();
510 truthJetPhi = matchTruthJet->phi();
511 deltaR = dRmin;
512 if (!m_doLargeRLabels) {
513 if (pileupTag <= 2) {
514 truthJetIso = jetTruthIsolHandle(*matchTruthJet);
515 }
516 }
517 }
518
519 // Save Groomed Truth Jet variables
520 float truthGroomedJetMass = -9999;
521 float truthGroomedJetPt = -9999;
523 if ( matchTruthJet ) {
524 for ( const xAOD::Jet* truthGroomedJet : *truthGroomedJets ) {
525 ElementLink<xAOD::JetContainer> element_link = ParentAcc (*truthGroomedJet);
526 if ( !element_link.isValid() ) { continue; }
527 if ( matchTruthJet == *element_link ) {
528 matchTruthGroomedJet = truthGroomedJet;
529 break;
530 }
531 }
532 }
533 // If no matched jet found or matched jet has no corresponding groomed jet, use dR matching
534 if ( !matchTruthGroomedJet && parent != nullptr) {
535 for ( const xAOD::Jet* truthGroomedJet : *truthGroomedJets ) {
536 float dR = parent->p4().DeltaR(truthGroomedJet->p4(),true);
538 if ( m_dRTruthJet < 0 || dR < m_dRTruthJet ) {
539 if ( dR < dRminGroomed ) {
540 dRminGroomed = dR;
541 matchTruthGroomedJet = truthGroomedJet;
542 }
543 }
544 }
545 }
546 if ( matchTruthGroomedJet ) {
547 truthGroomedJetMass = matchTruthGroomedJet->m();
548 truthGroomedJetPt = matchTruthGroomedJet->pt();
549 }
550 }
551
553 if (m_doLargeRLabels) {
554 (*dh.labelRecoHandle)(*jet) = label;
557 (*dh.split23Handle)(*jet) = truthJetSplit23;
558 (*dh.split12Handle)(*jet) = truthJetSplit12;
559 }
560
561 (*dh.nbRecoHandle)(*jet) = truthJetNB;
562 }
563
564 (*dh.matchedTruthJetHandle)(*jet) = truthJetEL;
565 (*dh.matchedTruthJetMassHandle)(*jet) = truthJetMass;
566 (*dh.matchedTruthJetPtHandle)(*jet) = truthJetPt;
567 (*dh.matchedTruthJetRapidityHandle)(*jet) = truthJetRapidity;
568 (*dh.matchedTruthJetPhiHandle)(*jet) = truthJetPhi;
570
571 if (!m_doLargeRLabels && usePileupJets) {
572 (*dh.matchedTruthJetIsoHandle)(*jet) = truthJetIso;
573 (*dh.matchedPileupTagHandle)(*jet) = pileupTag;
574 (*dh.sumPtMatchedHSJetsHandle)(*jet) = sumPtMatchedHSJets;
575 (*dh.sumPtMatchedOOTJetsHandle)(*jet) = sumPtMatchedOOTJets;
576 (*dh.sumPtMatchedITJetsHandle)(*jet) = sumPtMatchedITJets;
577 }
578
580 (*dh.matchedTruthGroomedMassHandle)(*jet) = truthGroomedJetMass;
581 (*dh.matchedTruthGroomedPtHandle)(*jet) = truthGroomedJetPt;
582 }
583 }
584
585 return StatusCode::SUCCESS;
586}
587
589 const EventContext& ctx) const {
590
593
595 if ( !truthJets.isValid() ) {
596 ATH_MSG_ERROR("No truth jet container retrieved. Please make sure you are using a supported TruthLabelName.");
597 return StatusCode::FAILURE;
598 }
599
600 return labelTruthJets(dh, *truthJets, ctx);
601
602}
603
605 const xAOD::JetContainer &truthJets,
606 const EventContext& ctx) const
607{
609 if ( !(truthJets.size()) ) return StatusCode::SUCCESS;
610
612 if(dh.labelHandle->isAvailable()){
613 // Beware: if we get here, the configuration is probably not MT-compatible.
614 ATH_MSG_DEBUG("labelTruthJets: Truth jet collection already labelled with " << m_truthLabelName);
615 return StatusCode::SUCCESS;
616 }
617
620 if(!eventInfo.isValid()){
621 ATH_MSG_ERROR("Failed to retrieve event information.");
622 return StatusCode::FAILURE;
623 }
624
625 if(m_doLargeRLabels) {
628 for ( const xAOD::Jet *jet : truthJets ) {
629 ATH_MSG_DEBUG("Getting truth label using ghost-association");
630 label = getTruthJetLabelGA(dh, *jet, ctx);
631 (*dh.labelHandle)(*jet) = label;
632 }
633 }
634
635 return StatusCode::SUCCESS;
636}
637
639
642
643 float split12 = -999.0;
644
646 const float c0 = 55.25;
647 const float c1 = -2.34e-3;
648
649 split12 = c0 * std::exp( c1 * pt );
650 }
651
652 return split12;
653
654}
655
657
660
661 float split23 = -999.0;
662
666
667 const float c0 = 3.3;
668 const float c1 = -6.98e-4;
669
670 split23 = std::exp( c0 + c1 * pt );
671
672 }
673
674 return split23;
675}
676
677int JetTruthLabelingTool::getNGhostParticles( const xAOD::Jet &jet, const std::string & collection ) const {
678
679 int nMatchPart = 0;
680
681 if( !jet.getAttribute<int>( collection+"Count", nMatchPart ) ){
682
683 std::vector<const xAOD::TruthParticle*> ghostParts;
684 if( !jet.getAssociatedObjects<xAOD::TruthParticle>( collection, ghostParts ) ){
685 ATH_MSG_ERROR( collection + " cannot be retrieved! Truth label definition might be wrong" );
686 }
687 nMatchPart = ghostParts.size();
688 }
689
690 return nMatchPart;
691}
692
694 const xAOD::Jet &jet,
695 bool matchH,
696 bool matchW,
697 bool matchZ,
698 bool matchTop,
699 const EventContext& ctx) const {
700
701 // store GhostBHadronsFinal count
702 int nMatchB = getNGhostParticles( jet, "GhostBHadronsFinal" );
703 (*dh.nbHandle)(jet) = nMatchB;
704
706 bool is_bb = false;
707 bool is_cc = false;
708 bool is_tautauEl = false;
709 bool is_tautauMu = false;
710 bool is_tautauHad = false;
711 bool isTop = false;
712 bool isW = false;
713 bool isZ = false;
714
715 // Use R21Precision_2022v1 definition
719 is_bb = ( nMatchB > 1 );
720 isTop = ( matchTop && matchW && nMatchB > 0 && jet.m() / 1000. > m_mLowTop && split23Handle(jet) / 1000. > getTopSplit23Cut( jet.pt() / 1000. ) );
721 isW = matchW && nMatchB == 0 && jet.m() / 1000. > m_mLowW && split12Handle(jet) / 1000. > getWZSplit12Cut( jet.pt() / 1000. );
722 isZ = matchZ && jet.m() / 1000. > m_mLowZ && split12Handle(jet) / 1000. > getWZSplit12Cut( jet.pt() / 1000. );
723 }
724
725 // Use R10TruthLabel_R22v1 definition
727 // get extended ghost associated truth label
728 int extended_GA_label = -1;
729 if (not jet.getAttribute("HadronGhostExtendedTruthLabelID", extended_GA_label)) {
730 ATH_MSG_ERROR( "HadronGhostExtendedTruthLabelID not available for " + m_truthJetCollectionKey.key() );
731 }
732
735 is_bb = ( extended_GA_label == 55 );
736 is_cc = ( extended_GA_label == 44 );
737 is_tautauEl = ( extended_GA_label == 151511 );
738 is_tautauMu = ( extended_GA_label == 151513 );
739 is_tautauHad = ( extended_GA_label == 1515 );
740 isTop = ( matchTop && matchW && nMatchB > 0 && jet.m() / 1000. > m_mLowTop && split23Handle(jet) / 1000. > getTopSplit23Cut( jet.pt() / 1000. ) );
741 isW = matchW && nMatchB == 0 && jet.m() / 1000. > m_mLowW && split12Handle(jet) / 1000. > getWZSplit12Cut( jet.pt() / 1000. );
742 isZ = matchZ && jet.m() / 1000. > m_mLowZ && split12Handle(jet) / 1000. > getWZSplit12Cut( jet.pt() / 1000. );
743 }
744
745
747
748 /* The default priority of labels is:
749 * 1) Hbb/cc/tautau
750 * 2) Contained top
751 * 3) Contained W
752 * 4) Contained Zbb/cc/qq/tautau
753 * 5) Uncontained top
754 * 6) Uncontained V
755 */
756
758 if( !(matchTop || matchW || matchZ || matchH) ) {
760 }
761
762 // Higgs
763 if ( matchH ) {
765 if ( is_bb ) return LargeRJetTruthLabel::Hbb;
767 if ( is_cc ) return LargeRJetTruthLabel::Hcc;
769 if ( is_tautauEl ) return LargeRJetTruthLabel::HtautauEl;
770 if ( is_tautauMu ) return LargeRJetTruthLabel::HtautauMu;
771 if ( is_tautauHad ) return LargeRJetTruthLabel::HtautauHad;
774 }
775
777 if ( isTop ) return LargeRJetTruthLabel::tqqb;
778
779 if ( isW ) {
781 if ( matchTop ) return LargeRJetTruthLabel::Wqq_From_t;
784 }
785
786 if ( matchZ ) {
788 if ( is_bb ) return LargeRJetTruthLabel::Zbb;
790 if ( is_cc ) return LargeRJetTruthLabel::Zcc;
792 if ( is_tautauEl ) return LargeRJetTruthLabel::ZtautauEl;
793 if ( is_tautauMu ) return LargeRJetTruthLabel::ZtautauMu;
794 if ( is_tautauHad ) return LargeRJetTruthLabel::ZtautauHad;
795 }
796 if ( isZ ) {
799 }
800
802 if ( matchTop ) return LargeRJetTruthLabel::other_From_t;
803
806
807}
Scalar deltaR(const MatrixBase< Derived > &vec) const
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x,...)
#define ATH_MSG_ERROR(x,...)
#define ATH_MSG_WARNING(x,...)
#define ATH_MSG_VERBOSE(x,...)
#define ATH_MSG_INFO(x,...)
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
bool isW(const T &p)
Definition AtlasPID.h:415
bool isZ(const T &p)
Definition AtlasPID.h:412
bool isTop(const T &p)
Definition AtlasPID.h:206
Helper class to provide constant type-safe access to aux data.
ATLAS-specific HepMC functions.
Header file for AthHistogramAlgorithm.
size_type size() const noexcept
Returns the number of elements in the collection.
Gaudi::Property< std::string > m_jetContainerName
Gaudi::Property< std::string > m_truthLabelName
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthJetDR_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_NB_truthKey
StatusCode labelRecoJets(DecorHandles &dh, const xAOD::JetContainer &jets, const EventContext &ctx) const
Apply labels to all jets in a container.
float getTopSplit23Cut(float pt) const
Get top label Split23 cut.
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthJetPt_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_label_recoKey
StatusCode labelTruthJets(DecorHandles &dh, const EventContext &ctx) const
Label truth jet collection.
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthJetPhi_recoKey
virtual StatusCode initialize() override
Dummy implementation of the initialisation function.
SG::ReadHandleKey< xAOD::JetContainer > m_truthGroomedJetCollectionKey
Gaudi::Property< bool > m_doLargeRLabels
void print() const override
Print configured parameters.
int getTruthJetLabelGA(DecorHandles &dh, const xAOD::Jet &jet, const EventContext &ctx) const
Get truth label using ghost-associated particles.
Gaudi::Property< bool > m_matchUngroomedParent
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthJetMass_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthJet_recoKey
Gaudi::Property< bool > m_isTruthJetCol
TruthLabelConfiguration m_truthLabelConfig
int getLabel(DecorHandles &dh, const xAOD::Jet &jet, bool matchH, bool matchW, bool matchZ, bool matchTop, const EventContext &ctx) const
Get label based on matching and containment criteria.
SG::WriteDecorHandleKey< xAOD::JetContainer > m_truthSplit23_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedPileupTag_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_sumPtMatchedOOTJets_recoKey
SG::ReadHandleKey< xAOD::JetContainer > m_ITJetName
float getWZSplit12Cut(float pt) const
Get W/Z label Split12 cut.
Gaudi::Property< double > m_mLowW
Gaudi::Property< double > m_mLowZ
Gaudi::Property< double > m_recoGhostFrac
Gaudi::Property< bool > m_getTruthGroomedJetValues
SG::ReadDecorHandleKey< xAOD::JetContainer > m_split23_truthKey
Gaudi::Property< double > m_dRTruthJet
SG::ReadDecorHandleKey< xAOD::JetContainer > m_split12_truthKey
int getNGhostParticles(const xAOD::Jet &jet, const std::string &collection) const
Get number of ghost associated particles.
SG::ReadHandleKey< xAOD::JetContainer > m_OOTJetName
parameters for truth labeling
SG::WriteDecorHandleKey< xAOD::JetContainer > m_truthSplit12_recoKey
SG::ReadHandleKey< xAOD::EventInfo > m_evtInfoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthGroomedJetMass_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthJetIso_recoKey
TruthLabelConfiguration parseLabel(const std::string &label)
JetTruthLabelingTool(const std::string &name="JetTruthLabelingTool")
default constructor - to be used in all derived classes
Gaudi::Property< double > m_mLowTop
Large R containment cuts [GeV].
SG::WriteDecorHandleKey< xAOD::JetContainer > m_label_truthKey
StatusCode decorate(const xAOD::JetContainer &jets) const override
decorate truth label to a jet collection
SG::ReadHandleKey< xAOD::JetContainer > m_truthJetCollectionKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_NB_recoKey
Gaudi::Property< bool > m_useGhostJetMatch
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthGroomedJetPt_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_matchedTruthJetRapidity_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_sumPtMatchedHSJets_recoKey
SG::WriteDecorHandleKey< xAOD::JetContainer > m_sumPtMatchedITJets_recoKey
SG::ReadDecorHandleKey< xAOD::JetContainer > m_jetTruthIsolKey
Helper class to provide type-safe access to aux data.
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.
Property holding a SG store/key/clid/attr name from which a ReadDecorHandle is made.
Handle class for reading a decoration on an object.
bool isAvailable()
Test to see if this variable exists in the store, for the referenced object.
virtual bool isValid() override final
Can the handle be successfully dereferenced?
const_pointer_type cptr()
Dereference the pointer.
Property holding a SG store/key/clid/attr name from which a WriteDecorHandle is made.
AsgTool(const std::string &name)
Constructor specifying the tool instance's name.
Definition AsgTool.cxx:58
virtual double phi() const
The azimuthal angle ( ) of the particle.
Definition Jet_v1.cxx:54
virtual double pt() const
The transverse momentum ( ) of the particle.
Definition Jet_v1.cxx:44
virtual double rapidity() const
The true rapidity (y) of the particle.
Definition Jet_v1.cxx:67
virtual double m() const
The invariant mass of the particle.
Definition Jet_v1.cxx:59
std::string label(const std::string &format, int i)
Definition label.h:19
int enumToInt(const TypeEnum type)
SG::ReadCondHandle< T > makeHandle(const SG::ReadCondHandleKey< T > &key, const EventContext &ctx=Gaudi::Hive::currentContext())
int enumToInt(const TypeEnum type)
Jet_v1 Jet
Definition of the current "jet version".
TruthParticle_v1 TruthParticle
Typedef to implementation.
JetContainer_v1 JetContainer
Definition of the current "jet container version".
DecorHandles(const JetTruthLabelingTool &tool, const EventContext &ctx)