30 m_doFull_JER_Pseudodata(false),
31 m_doFull_JER_largeR(false),
32 m_doFull_JER_largeR_Pseudodata(false),
34 m_doMultipleJES(false),
36 m_specifiedSystematics(),
37 m_specifiedSystematicsLargeR(),
38 m_specifiedSystematicsTrackJets(),
39 m_recommendedSystematics(),
40 m_nominalSystematicSet(),
42 m_jetCalibrationTool(
"JetCalibrationTool"),
43 m_jetCalibrationToolLargeR(
"JetCalibrationToolLargeR"),
45 m_jetUncertaintiesTool(
"JetUncertaintiesTool"),
46 m_jetUncertaintiesToolPseudoData(
"JetUncertaintiesToolPseudoData"),
47 m_jetUncertaintiesToolReducedNPScenario1(
"JetUncertaintiesToolReducedNPScenario1"),
48 m_jetUncertaintiesToolReducedNPScenario2(
"JetUncertaintiesToolReducedNPScenario2"),
49 m_jetUncertaintiesToolReducedNPScenario3(
"JetUncertaintiesToolReducedNPScenario3"),
50 m_jetUncertaintiesToolReducedNPScenario4(
"JetUncertaintiesToolReducedNPScenario4"),
51 m_jetUncertaintiesToolLargeR(
"JetUncertaintiesToolLargeR"),
52 m_jetUncertaintiesToolLargeRPseudoData(
"JetUncertaintiesToolLargeRPseudoData"),
53 m_FFJetSmearingTool(
"FFJetSmearingTool"),
55 m_jetJvtEfficiencyTool(
"JetJvtEfficiencyTool"),
56 m_jetSelectfJvtTool(
"JetSelectfJvtTool"),
58 m_jetSubstructure(nullptr),
61 m_systMap_JERPseudo(),
62 m_systMap_ReducedNPScenario1(),
63 m_systMap_ReducedNPScenario2(),
64 m_systMap_ReducedNPScenario3(),
65 m_systMap_ReducedNPScenario4(),
67 m_systMap_LargeR_JERPseudo() {
89 ATH_MSG_INFO(
" top::JetObjectCollectionMaker initialize");
102 "Failed to retrieve JetCalibrationToolLargeR");
119 if (
m_config->jetJERSmearingModel() ==
"Full_PseudoData" ||
124 if (!
m_config->isMC() && (
m_config->largeRJetUncertainties_NPModel()).find(
"_SimpleJER_") == std::string::npos)
127 if (
m_config->isMC() &&
m_config->doLargeRPseudodataJER() && (
m_config->largeRJetUncertainties_NPModel()).find(
"_SimpleJER_") == std::string::npos)
144 "Failed to retrieve JetUncertaintiesToolReducedNPScenario1");
147 "Failed to retrieve JetUncertaintiesToolReducedNPScenario2");
150 "Failed to retrieve JetUncertaintiesToolReducedNPScenario3");
153 "Failed to retrieve JetUncertaintiesToolReducedNPScenario4");
167 const std:: string& syststr =
m_config->systematics();
168 std::set<std::string> syst, systLargeR;
172 bool ok =
m_config->getSystematicsList(syststr, syst);
173 bool okLargeR =
m_config->getSystematicsList(syststr, systLargeR);
176 if (!ok || !okLargeR) {
177 ATH_MSG_ERROR(
" top::JetObjectCollectionMaker could not determine systematic list");
178 return StatusCode::FAILURE;
182 if (
m_config->contains(syst,
"AllJets")) {
186 if (
m_config->contains(syst,
"AllSmallRJets")) {
189 if (
m_config->contains(systLargeR,
"AllLargeRJets")) {
196 std::string allNP(
""),
197 np1(
"SR_Scenario1_"), np2(
"SR_Scenario2_"), np3(
"SR_Scenario3_"), np4(
"SR_Scenario4_");
230 ATH_MSG_WARNING(
"No Large-R jet systematic recommendations are available yet! Large-R jet systematics skipped!");
239 for (
const auto&
name :
m_config->boostedTaggerSFnames()) {
240 ToolHandle<ICPJetUncertaintiesTool> tmp_SF_uncert_tool(
"JetSFuncert_" +
name.first);
241 if (tmp_SF_uncert_tool.retrieve()) {
245 const CP::SystematicSet& recommendedSys = tmp_SF_uncert_tool->recommendedSystematics();
251 bool res = ((
sys.name().find(
"TopTag") == std::string::npos) &&
252 (
sys.name().find(
"WTag") == std::string::npos) &&
253 (
sys.name().find(
"ZTag") == std::string::npos) &&
254 (
sys.name().find(
"JetTag") == std::string::npos) &&
255 (
sys.name().find(
"bTag") == std::string::npos));
263 largeRsysts.
insert(correlatedSys);
274 std::string allNPlargeR(
"");
304 for (
const auto& algo :
m_config->bTagAlgos()) {
306 top::check(
m_btagSelToolsDL1Decor[algo.first].retrieve(),
"Failed to retrieve " + algo.first +
" btagging selector for " +
m_config->sgKeyJets() +
". This is required for b-tagging score decorations in EventSaver!");
311 for (
const auto& algo :
m_config->bTagAlgos_trkJet()) {
321 for (
const std::pair<std::string, std::string>&
name :
m_config->boostedJetTaggers()) {
327 return StatusCode::SUCCESS;
331 bool isLargeR(
false);
333 return execute(isLargeR, executeNominal);
339 return execute(isLargeR, executeNominal);
344 if (executeNominal) {
349 "Failed to decorate jets with truth info of which are HS - this is needed for JVT scale-factors!");
365 return StatusCode::SUCCESS;
398 true),
"Failed to apply large-R syst.");
401 true),
"Failed to apply large-R pseudodata JER.");
405 return StatusCode::SUCCESS;
410 std::string sgKey = isLargeR ?
m_config->sgKeyLargeRJets() :
m_config->sgKeyJets();
422 "Failed to do applyCalibration on large-R jets");
429 "Failed to do applyCalibration on small-R jets");
433 for (
const auto jet : *(shallow_xaod_copy.first)) {
439 if (JSF != 1.0 || bJSF != 1.0) {
441 if (
jet->isAvailable<
int>(
"PartonTruthLabelID")) {
442 jet->getAttribute(
"PartonTruthLabelID", truthflav);
446 if (truthflav == 5) jet_p4 = jet_p4 * bJSF;
448 jet->setJetP4(jet_p4);
463 float tau3 =
jet->getAttribute<
float>(
"Tau3_wta");
464 float tau2 =
jet->getAttribute<
float>(
"Tau2_wta");
465 float tau1 =
jet->getAttribute<
float>(
"Tau1_wta");
466 float ECF1 =
jet->getAttribute<
float>(
"ECF1");
467 float ECF2 =
jet->getAttribute<
float>(
"ECF2");
468 float ECF3 =
jet->getAttribute<
float>(
"ECF3");
470 jet->auxdecor<
float>(
"Tau32_wta") = fabs(tau2) > 1.e-6 ? (tau3 / tau2) : -999;
472 jet->auxdecor<
float>(
"Tau21_wta") = fabs(tau1) > 1.e-6 ? (tau2 / tau1) : -999;
475 jet->auxdecor<
float>(
"D2") = (ECF2 > 1
e-8) ? (ECF3*ECF1*ECF1*ECF1) / (ECF2*ECF2*ECF2) : -999;
476 jet->auxdecor<
float>(
"C2") = (ECF2 > 1
e-8) ? (ECF3*ECF1) / (ECF2*ECF2) : -999;
477 jet->auxdecor<
float>(
"E3") = (ECF1 > 1
e-8) ? ECF3 / (ECF1*ECF1*ECF1) : -999;
481 const std::string calibChoice =
m_config->largeRJESJMSConfig();
483 if (calibChoice ==
"TAMass") {
486 jet->setJetP4(jet_calib_p4);
489 if (calibChoice ==
"CaloMass") {
492 jet->setJetP4(jetInsituP4_calo);
493 }
else if (calibChoice ==
"TAMass") {
496 jet->setJetP4(jetInsituP4_ta);
506 "Failed to recalculate JVT scores");
512 if (!isLargeR && (
m_config->doForwardJVTinMET() ||
m_config->getfJVTWP() !=
"None")) {
513 static bool checked_track_MET =
false;
514 if (!checked_track_MET) {
515 if (
evtStore()->contains<xAOD::MissingETContainer>(
"MET_Track")) {
518 ATH_MSG_ERROR(
" Cannot retrieve MET_Track, fJVT values can't be calculated correctly!!");
519 return StatusCode::FAILURE;
521 checked_track_MET =
true;
528 "Failed to apply fJVT decoration");
539 "Failed to retrieve uncalibrated Jets for METMaker!");
540 if (!xaod_original || !shallow_xaod_copy.first) {
541 ATH_MSG_ERROR(
"Cannot retrieve the original jet collection!");
542 return StatusCode::FAILURE;
545 if (!setLinks)
ATH_MSG_ERROR(
" Cannot set original object links for jets, MET recalculation may struggle");
549 std::string outputSGKey;
557 std::string outputSGKeyAux = outputSGKey +
"Aux.";
560 StatusCode saveAux =
evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux);
561 if (!
save || !saveAux) {
562 return StatusCode::FAILURE;
565 return StatusCode::SUCCESS;
575 const size_t njets = ljets->
size();
577 const std::unordered_map<std::string,std::string>& sfNames =
m_config->boostedTaggerSFnames();
580 ToolHandle<ICPJetUncertaintiesTool>&
tool =
it.second;
583 const std::string sfNameNominal = sfNames.at(
fullName);
586 std::string taggerName = sfNameNominal;
587 taggerName.erase(taggerName.length()-3);
595 std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* >
597 auto shallowJets = std::make_pair(std::unique_ptr<xAOD::JetContainer>{shallow_xaod_copy.first},
598 std::unique_ptr<xAOD::ShallowAuxContainer>{shallow_xaod_copy.second});
600 top::check(
tool->applySystematicVariation(
sys),
"Failed to applySystematicVariation");
602 const std::string sfNameShifted =
fullName +
"_" +
sys.name();
604 top::check(
tool->applyContainerCorrection(*shallow_xaod_copy.first),
605 "Failed to apply large-R jet SF uncertainties in nominal TTree");
607 for(
size_t i = 0;
i < njets;
i++) {
608 xAOD::Jet* shallowJet = shallowJets.first->at(
i);
611 float sf = accSF.
isAvailable(*shallowJet) ? accSF(*shallowJet) : -999.;
612 jet->auxdecor<
float>(sfNameShifted.c_str()) =
sf;
615 if (
sys.name().find(
"TagEffUnc") != std::string::npos) {
617 jet->auxdecor<
float>(
fullName +
"_" +
sys.name() +
"_efficiency") = accEff(*shallowJet);
624 return StatusCode::SUCCESS;
636 const std::string msg_jet_collection = isLargeR ?
"large-R jets" :
"small-R jets";
647 for (
Itr syst = map.begin(); syst != map.end(); ++syst) {
655 std::string systname = itr->name();
656 if (systname.find(
"JMR") != std::string::npos) isJMR =
true;
662 "Failed to applySystematicVariation for " + msg_jet_collection);
665 "Failed to applySystematicVariation (JMR) for " + msg_jet_collection);
670 for (std::pair<
const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF :
m_tagSFuncertTool) {
671 top::check(tagSF.second->applySystematicVariation((*syst).second),
672 "Failed to applySystematicVariation for " + msg_jet_collection);
677 std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* >
682 for (std::pair<
const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF :
m_tagSFuncertTool) {
683 top::check(tagSF.second->applyContainerCorrection(*shallow_xaod_copy.first),
684 "Failed to apply large-R jet tagging SF uncertainties");
691 top::check(
tool->applyContainerCorrection(*shallow_xaod_copy.first),
692 "Failed to apply JES/JER uncertainties for " + msg_jet_collection);
695 "Failed to JMR uncertainties for " + msg_jet_collection);
701 "Failed to recalculate JVT scores");
707 if (!isLargeR && (
m_config->doForwardJVTinMET() ||
m_config->getfJVTWP() !=
"None")) {
708 static bool checked_track_MET =
false;
709 if (!checked_track_MET) {
710 if (
evtStore()->contains<xAOD::MissingETContainer>(
"MET_Track")) {
713 ATH_MSG_ERROR(
" Cannot retrieve MET_Track, fJVT values can't be calculated correctly!!");
714 return StatusCode::FAILURE;
716 checked_track_MET =
true;
723 "Failed to apply fJVT decoration");
728 *shallow_xaod_copy.first);
729 if (!setLinks)
ATH_MSG_ERROR(
" Cannot set original object links"
730 " for jets, MET recalculation may struggle");
735 std::string outputSGKey;
737 outputSGKey =
m_config->sgKeyLargeRJets((*syst).first.hash());
739 outputSGKey =
m_config->sgKeyJetsStandAlone((*syst).first.hash());
741 std::string outputSGKeyAux = outputSGKey +
"Aux.";
744 StatusCode saveAux =
evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux);
745 if (!
save || !saveAux) {
746 return StatusCode::FAILURE;
750 return StatusCode::SUCCESS;
756 if (!executeNominal)
return StatusCode::SUCCESS;
771 if (!setLinks)
ATH_MSG_ERROR(
" Cannot set original object links for track jets");
774 std::string outputSGKey =
m_config->sgKeyTrackJets(
m_config->nominalHashValue());
775 std::string outputSGKeyAux = outputSGKey +
"Aux.";
778 StatusCode saveAux =
evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux);
779 if (!
save || !saveAux) {
780 return StatusCode::FAILURE;
782 return StatusCode::SUCCESS;
786 bool isLargeR(
false);
800 std::string sgKey = isLargeR ?
m_config->sgKeyLargeRJets() :
m_config->sgKeyJets();
806 for (
auto x : *xaod) {
811 return StatusCode::SUCCESS;
815 if (NPModel.find(
"CategoryReduction")!=std::string::npos)
return "CategoryReduction_";
821 std::unordered_map<CP::SystematicSet, CP::SystematicSet>& map,
827 if (isPseudoData &&
m_config->isSystNominal(
m_config->systematics()))
return;
833 if (
s.size() != 1)
continue;
838 if (onlyJER &&
ss->name().find(
"JER") == std::string::npos)
continue;
849 map.insert(std::make_pair(modSet,
s));
856 map.insert(std::make_pair(modSet,
s));
878 "Failed to retrieve nominal calibrated large-R jets");
881 return StatusCode::SUCCESS;
886 for (
const std::pair<std::string, std::string>&
name :
m_config->boostedJetTaggers()) {
893 if (validPtRangeLowDec(*
jet) && validPtRangeHighDec(*
jet) && validEtaRangeDec(*
jet)) {
894 passedRangeCheckDec(*
jet) = 1;
896 passedRangeCheckDec(*
jet) = 0;
900 return StatusCode::SUCCESS;
906 static const std::string labelB =
"PartonTruthLabelID";
910 isbjet(
jet) = (
jet.pt() > 15000. && truth_label(
jet) == 5);
912 return StatusCode::SUCCESS;
924 "Failed to retrieve small-R jet collection" +
m_config->sgKeyJets());
931 " - this is needed to define HS jets for application of JVT");
933 for (
const auto *
jet : *
jets) {
935 for (
const auto *tjet : *truthJets) {
936 if (tjet->p4().DeltaR(
jet->p4()) < 0.3 && tjet->pt() > 10
e3) ishs =
true;
941 return StatusCode::SUCCESS;
951 "Failed to retrieve small-R jet collection" +
m_config->sgKeyJets());
956 const xAOD::Jet* matchedTruthJet =
nullptr;
959 for (
const auto *
jet : *
jets) {
961 for (
const auto *iTruthJet : *truthJets) {
962 TLorentzVector truthJetTLV;
963 truthJetTLV.SetPtEtaPhiE(iTruthJet->pt(),iTruthJet->eta(),iTruthJet->phi(),iTruthJet->e());
966 if(!matchedTruthJet) {
967 matchedTruthJet = iTruthJet;
969 const double newdR =
jet->p4().DeltaR(iTruthJet->p4());
972 matchedTruthJet = iTruthJet;
977 matchedPt(*
jet) = -9999;
980 if (!matchedTruthJet) {
981 matchedPt(*
jet) = -9999;
984 matchedPt(*
jet) = matchedTruthJet->
pt();
987 return StatusCode::SUCCESS;
997 "Failed to retrieve track jet collection" +
m_config->sgKeyTrackJets());
1001 "Failed to retrieve small-R jet collection" +
m_config->sgKeyJets());
1004 for (
const auto *
jet : *
jets) {
1006 const std::unordered_map<std::string, ToolHandle<IBTaggingSelectionTool>>& btagDecorTools \
1008 for (std::pair<std::string, ToolHandle<IBTaggingSelectionTool>> algo : btagDecorTools) {
1009 double DL1_weight = -999.;
1010 double dl1_pb = -10.;
1011 double dl1_pc = -10.;
1012 double dl1_pu = -10.;
1013 double dl1_ptau = 0.;
1016 std::string taggerName = algo.first;
1017 if(taggerName ==
"GN2v00LegacyWP" || taggerName ==
"GN2v00NewAliasWP"){
1018 taggerName =
"GN2v00";
1025 if (!algo.second->getTaggerWeight(dl1_pb, dl1_pc, dl1_pu, DL1_weight, dl1_ptau)) {
1031 DLx.at(algo.first)(*jet) = DL1_weight;
1035 return StatusCode::SUCCESS;