20 static const std::map<std::string, TruthLabelConfiguration> labels{
29 auto it = labels.find(name);
42 return StatusCode::FAILURE;
115 return StatusCode::SUCCESS;
135 auto maybeInit = [&] (
auto&
h,
138 if (!k.key().empty())
h.emplace (k, ctx);
141 maybeInit (
nbHandle, tool.m_NB_truthKey);
165 const EventContext& ctx )
const
171 bool matchTop =
false;
201 return getLabel( dh,
jet, matchH, matchW, matchZ, matchTop, ctx );
206 const EventContext& ctx = Gaudi::Hive::currentContext();
224 return StatusCode::SUCCESS;
229 const EventContext& ctx)
const {
233 bool usePileupJets =
true;
241 if (!inTimeTruthJets.
isValid() || !outOfTimeTruthJets.
isValid()) {
243 usePileupJets =
false;
261 if ( element_link.
isValid() ) {
262 parent = *element_link;
265 ATH_MSG_ERROR(
"Unable to get a link to the parent jet! Returning a NULL pointer.");
266 return StatusCode::FAILURE;
271 float oot_dRmin = 9999;
272 float it_dRmin = 9999;
273 float ghostFracNominal = 9;
274 const xAOD::Jet* matchTruthJet =
nullptr;
275 const xAOD::Jet* oot_matchTruthJet =
nullptr;
276 const xAOD::Jet* it_matchTruthJet =
nullptr;
278 float dRminGroomed = 9999;
279 const xAOD::Jet* matchTruthGroomedJet =
nullptr;
281 float sumPtMatchedHSJets = 0;
282 float sumPtMatchedOOTJets = 0;
283 float sumPtMatchedITJets = 0;
284 float bestHSpT = -9999;
285 float bestOOTpT = -9999;
286 float bestITpT = -9999;
287 float bestHSpTRatio = -9;
288 float bestOOTpTRatio = -9;
289 float bestITpTRatio = -9;
290 int nMatchedHSJets = 0;
291 int nMatchedOOTJets = 0;
292 int nMatchedITJets = 0;
299 if (
jet->numConstituents() > 0) {
300 for (
const xAOD::Jet* truthJet : *truthJets) {
302 float dR =
jet->p4().DeltaR(truthJet->p4(),
true);
304 if (parent) dR = parent->p4().DeltaR(truthJet->p4(),
true);
308 float ghostTruthPt = accGhostTruthPt(*
jet);
309 float ghostPtFraction = (ghostTruthPt / (truthJet->pt()));
312 sumPtMatchedHSJets += truthJet->pt();
313 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) {
314 matchTruthJet = truthJet;
315 ghostFracNominal = ghostPtFraction;
322 sumPtMatchedHSJets += truthJet->pt();
325 matchTruthJet = truthJet;
331 for (
const xAOD::Jet* ootJet : *outOfTimeTruthJets) {
332 float dR =
jet->p4().DeltaR(ootJet->p4(),
true);
334 float ghostTruthPt = accGhostTruthPt(*
jet);
335 float ghostPtFraction = (ghostTruthPt / (ootJet->pt()));
337 nMatchedOOTJets += 1;
338 sumPtMatchedOOTJets += ootJet->pt();
339 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) {
340 oot_matchTruthJet = ootJet;
346 nMatchedOOTJets += 1;
347 sumPtMatchedOOTJets += ootJet->pt();
348 if (dR < oot_dRmin) {
350 oot_matchTruthJet = ootJet;
355 for (
const xAOD::Jet* itJet : *inTimeTruthJets) {
356 float dR =
jet->p4().DeltaR(itJet->p4(),
true);
358 float ghostTruthPt = accGhostTruthPt(*
jet);
359 float ghostPtFraction = (ghostTruthPt / (itJet->pt()));
362 sumPtMatchedITJets += itJet->pt();
363 if (std::abs(1 - ghostPtFraction) < std::abs(1 - ghostFracNominal)) {
364 it_matchTruthJet = itJet;
371 sumPtMatchedITJets += itJet->pt();
374 it_matchTruthJet = itJet;
393 int nMatchedPUJets = nMatchedOOTJets + nMatchedITJets;
395 float totalMatchedpT = sumPtMatchedHSJets + sumPtMatchedOOTJets + sumPtMatchedITJets;
398 bestHSpT = matchTruthJet->
pt();
399 bestHSpTRatio = bestHSpT / totalMatchedpT;
401 if (oot_matchTruthJet) {
402 bestOOTpT = oot_matchTruthJet->
pt();
403 bestOOTpTRatio = bestOOTpT / totalMatchedpT;
405 if (it_matchTruthJet) {
406 bestITpT = it_matchTruthJet->
pt();
407 bestITpTRatio = bestITpT / totalMatchedpT;
410 if (bestHSpTRatio >= 0.9) {
413 else if (bestITpTRatio >= 0.9) {
416 else if (bestOOTpTRatio >= 0.9) {
419 else if (nMatchedPUJets == 0 && nMatchedHSJets > 1) {
422 else if (nMatchedPUJets > 0 && nMatchedHSJets > 0) {
425 else if (nMatchedPUJets > 1) {
438 float truthJetSplit12 = -9999;
439 float truthJetSplit23 = -9999;
443 float truthJetMass = -9999;
444 float truthJetPt = -9999;
445 float truthJetRapidity = -9;
446 float truthJetPhi = -9999;
454 matchTruthJet = it_matchTruthJet;
455 truthJetCont = inTimeTruthJets.
cptr();
459 matchTruthJet = oot_matchTruthJet;
460 truthJetCont = outOfTimeTruthJets.
cptr();
464 if (bestITpTRatio >= bestOOTpTRatio) {
465 matchTruthJet = it_matchTruthJet;
466 truthJetCont = inTimeTruthJets.
cptr();
469 matchTruthJet = oot_matchTruthJet;
470 truthJetCont = outOfTimeTruthJets.
cptr();
477 if ( matchTruthJet ) {
484 label = labelAcc(*matchTruthJet);
487 if (split23Handle.
isAvailable()) truthJetSplit23 = split23Handle(*matchTruthJet);
489 if (split12Handle.
isAvailable()) truthJetSplit12 = split12Handle(*matchTruthJet);
491 if (nbAcc.
isAvailable(*matchTruthJet)) truthJetNB = nbAcc(*matchTruthJet);
493 ATH_MSG_VERBOSE(
"For reco jet " <<
jet->index() <<
", matched truth jet index " << matchTruthJet->index());
495 truthJetMass = matchTruthJet->
m();
496 truthJetPt = matchTruthJet->
pt();
497 truthJetRapidity = matchTruthJet->
rapidity();
498 truthJetPhi = matchTruthJet->
phi();
503 float truthGroomedJetMass = -9999;
504 float truthGroomedJetPt = -9999;
506 if ( matchTruthJet ) {
507 for (
const xAOD::Jet* truthGroomedJet : *truthGroomedJets ) {
509 if ( !element_link.
isValid() ) {
continue; }
510 if ( matchTruthJet == *element_link ) {
511 matchTruthGroomedJet = truthGroomedJet;
517 if ( !matchTruthGroomedJet && parent !=
nullptr) {
518 for (
const xAOD::Jet* truthGroomedJet : *truthGroomedJets ) {
519 float dR = parent->p4().DeltaR(truthGroomedJet->p4(),
true);
522 if ( dR < dRminGroomed ) {
524 matchTruthGroomedJet = truthGroomedJet;
529 if ( matchTruthGroomedJet ) {
530 truthGroomedJetMass = matchTruthGroomedJet->
m();
531 truthGroomedJetPt = matchTruthGroomedJet->
pt();
567 return StatusCode::SUCCESS;
571 const EventContext& ctx)
const {
578 ATH_MSG_ERROR(
"No truth jet container retrieved. Please make sure you are using a supported TruthLabelName.");
579 return StatusCode::FAILURE;
588 const EventContext& ctx)
const
591 if ( !(truthJets.
size()) )
return StatusCode::SUCCESS;
597 return StatusCode::SUCCESS;
604 return StatusCode::FAILURE;
611 ATH_MSG_DEBUG(
"Getting truth label using ghost-association");
617 return StatusCode::SUCCESS;
625 float split12 = -999.0;
628 const float c0 = 55.25;
629 const float c1 = -2.34e-3;
631 split12 = c0 * std::exp( c1 * pt );
643 float split23 = -999.0;
649 const float c0 = 3.3;
650 const float c1 = -6.98e-4;
652 split23 = std::exp( c0 + c1 * pt );
663 if( !
jet.getAttribute<
int>( collection+
"Count", nMatchPart ) ){
665 std::vector<const xAOD::TruthParticle*> ghostParts;
667 ATH_MSG_ERROR( collection +
" cannot be retrieved! Truth label definition might be wrong" );
669 nMatchPart = ghostParts.size();
681 const EventContext& ctx)
const {
690 bool is_tautauEl =
false;
691 bool is_tautauMu =
false;
692 bool is_tautauHad =
false;
701 is_bb = ( nMatchB > 1 );
710 int extended_GA_label = -1;
711 if (not
jet.getAttribute(
"HadronGhostExtendedTruthLabelID", extended_GA_label)) {
717 is_bb = ( extended_GA_label == 55 );
718 is_cc = ( extended_GA_label == 44 );
719 is_tautauEl = ( extended_GA_label == 151511 );
720 is_tautauMu = ( extended_GA_label == 151513 );
721 is_tautauHad = ( extended_GA_label == 1515 );
740 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.
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".