20 static const std::map<std::string, TruthLabelConfiguration> labels{
29 auto it = labels.find(name);
42 return StatusCode::FAILURE;
122 return StatusCode::SUCCESS;
142 auto maybeInit = [&] (
auto&
h,
145 if (!k.key().empty())
h.emplace (k, ctx);
148 maybeInit (
nbHandle, tool.m_NB_truthKey);
173 const EventContext& ctx )
const
179 bool matchTop =
false;
209 return getLabel( dh,
jet, matchH, matchW, matchZ, matchTop, ctx );
214 const EventContext& ctx = Gaudi::Hive::currentContext();
232 return StatusCode::SUCCESS;
237 const EventContext& ctx)
const {
241 bool usePileupJets =
true;
249 if (!inTimeTruthJets.
isValid() || !outOfTimeTruthJets.
isValid()) {
251 usePileupJets =
false;
271 if ( element_link.
isValid() ) {
272 parent = *element_link;
275 ATH_MSG_ERROR(
"Unable to get a link to the parent jet! Returning a NULL pointer.");
276 return StatusCode::FAILURE;
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;
309 if (
jet->numConstituents() > 0) {
310 for (
const xAOD::Jet* truthJet : *truthJets) {
313 float dR =
jet->p4().DeltaR(truthJet->p4(),
true);
315 if (parent) dR = parent->p4().DeltaR(truthJet->p4(),
true);
319 float ghostTruthPt = accGhostTruthPt(*
jet);
320 float ghostPtFraction = (ghostTruthPt / (truthJet->pt()));
323 sumPtMatchedHSJets += truthJet->pt();
324 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) {
325 matchTruthJet = truthJet;
326 ghostFracNominal = ghostPtFraction;
333 sumPtMatchedHSJets += truthJet->pt();
336 matchTruthJet = truthJet;
342 for (
const xAOD::Jet* ootJet : *outOfTimeTruthJets) {
343 float dR =
jet->p4().DeltaR(ootJet->p4(),
true);
345 float ghostTruthPt = accGhostTruthPt(*
jet);
346 float ghostPtFraction = (ghostTruthPt / (ootJet->pt()));
348 nMatchedOOTJets += 1;
349 sumPtMatchedOOTJets += ootJet->pt();
350 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) {
351 oot_matchTruthJet = ootJet;
357 nMatchedOOTJets += 1;
358 sumPtMatchedOOTJets += ootJet->pt();
359 if (dR < oot_dRmin) {
361 oot_matchTruthJet = ootJet;
366 for (
const xAOD::Jet* itJet : *inTimeTruthJets) {
367 float dR =
jet->p4().DeltaR(itJet->p4(),
true);
369 float ghostTruthPt = accGhostTruthPt(*
jet);
370 float ghostPtFraction = (ghostTruthPt / (itJet->pt()));
373 sumPtMatchedITJets += itJet->pt();
374 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) {
375 it_matchTruthJet = itJet;
382 sumPtMatchedITJets += itJet->pt();
385 it_matchTruthJet = itJet;
404 int nMatchedPUJets = nMatchedOOTJets + nMatchedITJets;
406 float totalMatchedpT = sumPtMatchedHSJets + sumPtMatchedOOTJets + sumPtMatchedITJets;
409 bestHSpT = matchTruthJet->
pt();
410 bestHSpTRatio = bestHSpT / totalMatchedpT;
412 if (oot_matchTruthJet) {
413 bestOOTpT = oot_matchTruthJet->
pt();
414 bestOOTpTRatio = bestOOTpT / totalMatchedpT;
416 if (it_matchTruthJet) {
417 bestITpT = it_matchTruthJet->
pt();
418 bestITpTRatio = bestITpT / totalMatchedpT;
421 if (bestHSpTRatio >= 0.9) {
424 else if (bestITpTRatio >= 0.9) {
427 else if (bestOOTpTRatio >= 0.9) {
430 else if (nMatchedPUJets == 0 && nMatchedHSJets > 1) {
433 else if (nMatchedPUJets > 0 && nMatchedHSJets > 0) {
436 else if (nMatchedPUJets > 1) {
449 float truthJetSplit12 = -9999;
450 float truthJetSplit23 = -9999;
454 float truthJetMass = -9999;
455 float truthJetPt = -9999;
456 float truthJetRapidity = -9;
457 float truthJetPhi = -9999;
458 float truthJetIso = -2;
466 matchTruthJet = it_matchTruthJet;
467 truthJetCont = inTimeTruthJets.
cptr();
471 matchTruthJet = oot_matchTruthJet;
472 truthJetCont = outOfTimeTruthJets.
cptr();
476 if (bestITpTRatio >= bestOOTpTRatio) {
477 matchTruthJet = it_matchTruthJet;
478 truthJetCont = inTimeTruthJets.
cptr();
481 matchTruthJet = oot_matchTruthJet;
482 truthJetCont = outOfTimeTruthJets.
cptr();
489 if ( matchTruthJet ) {
496 label = labelAcc(*matchTruthJet);
499 if (split23Handle.
isAvailable()) truthJetSplit23 = split23Handle(*matchTruthJet);
501 if (split12Handle.
isAvailable()) truthJetSplit12 = split12Handle(*matchTruthJet);
503 if (nbAcc.
isAvailable(*matchTruthJet)) truthJetNB = nbAcc(*matchTruthJet);
505 ATH_MSG_VERBOSE(
"For reco jet " <<
jet->index() <<
", matched truth jet index " << matchTruthJet->index());
507 truthJetMass = matchTruthJet->
m();
508 truthJetPt = matchTruthJet->
pt();
509 truthJetRapidity = matchTruthJet->
rapidity();
510 truthJetPhi = matchTruthJet->
phi();
513 if (pileupTag <= 2) {
514 truthJetIso = jetTruthIsolHandle(*matchTruthJet);
520 float truthGroomedJetMass = -9999;
521 float truthGroomedJetPt = -9999;
523 if ( matchTruthJet ) {
524 for (
const xAOD::Jet* truthGroomedJet : *truthGroomedJets ) {
526 if ( !element_link.
isValid() ) {
continue; }
527 if ( matchTruthJet == *element_link ) {
528 matchTruthGroomedJet = truthGroomedJet;
534 if ( !matchTruthGroomedJet && parent !=
nullptr) {
535 for (
const xAOD::Jet* truthGroomedJet : *truthGroomedJets ) {
536 float dR = parent->p4().DeltaR(truthGroomedJet->p4(),
true);
539 if ( dR < dRminGroomed ) {
541 matchTruthGroomedJet = truthGroomedJet;
546 if ( matchTruthGroomedJet ) {
547 truthGroomedJetMass = matchTruthGroomedJet->
m();
548 truthGroomedJetPt = matchTruthGroomedJet->
pt();
585 return StatusCode::SUCCESS;
589 const EventContext& ctx)
const {
596 ATH_MSG_ERROR(
"No truth jet container retrieved. Please make sure you are using a supported TruthLabelName.");
597 return StatusCode::FAILURE;
606 const EventContext& ctx)
const
609 if ( !(truthJets.
size()) )
return StatusCode::SUCCESS;
615 return StatusCode::SUCCESS;
622 return StatusCode::FAILURE;
629 ATH_MSG_DEBUG(
"Getting truth label using ghost-association");
635 return StatusCode::SUCCESS;
643 float split12 = -999.0;
646 const float c0 = 55.25;
647 const float c1 = -2.34e-3;
649 split12 = c0 * std::exp( c1 * pt );
661 float split23 = -999.0;
667 const float c0 = 3.3;
668 const float c1 = -6.98e-4;
670 split23 = std::exp( c0 + c1 * pt );
681 if( !
jet.getAttribute<
int>( collection+
"Count", nMatchPart ) ){
683 std::vector<const xAOD::TruthParticle*> ghostParts;
685 ATH_MSG_ERROR( collection +
" cannot be retrieved! Truth label definition might be wrong" );
687 nMatchPart = ghostParts.size();
699 const EventContext& ctx)
const {
708 bool is_tautauEl =
false;
709 bool is_tautauMu =
false;
710 bool is_tautauHad =
false;
719 is_bb = ( nMatchB > 1 );
728 int extended_GA_label = -1;
729 if (not
jet.getAttribute(
"HadronGhostExtendedTruthLabelID", extended_GA_label)) {
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 );
758 if( !(matchTop || matchW || matchZ || matchH) ) {
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,...)
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.
ElementLink implementation for ROOT usage.
bool isValid() const
Check if the element can be found.
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.
virtual double phi() const
The azimuthal angle ( ) of the particle.
virtual double pt() const
The transverse momentum ( ) of the particle.
virtual double rapidity() const
The true rapidity (y) of the particle.
virtual double m() const
The invariant mass of the particle.
std::string label(const std::string &format, int i)
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".