diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverFlatNtuple.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverFlatNtuple.cxx index dc80489e46c1e17d6dcd18f3b1f546fff677e4cc..5c27a50c282893762535818f87a5ceb700b841ef 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverFlatNtuple.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/Root/EventSaverFlatNtuple.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "TopAnalysis/EventSaverFlatNtuple.h" @@ -385,9 +385,10 @@ namespace top { } if (m_config->useLargeRJets()) { - for (const std::pair<std::string, std::string>& taggerName : m_config->boostedJetTaggers()) { - m_boostedJetTaggersNames.push_back(taggerName.first + "_" + taggerName.second); - } + for (const std::pair<std::string, std::string>& taggerName : m_config->boostedJetTaggers()) + m_boostedJetTaggersNames.push_back(taggerName.second); + for (const std::pair<std::string, std::string>& taggerSF : m_config->boostedTaggerSFnames()) + m_boostedJetTaggersNamesCalibrated.push_back(taggerSF.first); } if (m_config->useJets()) { @@ -1080,13 +1081,20 @@ namespace top { for (const std::string& taggerName : m_boostedJetTaggersNames) { systematicTree->makeOutputVariable(m_ljet_isTagged[taggerName], "ljet_isTagged_" + taggerName); + systematicTree->makeOutputVariable(m_ljet_taggingPassedRangeCheck[taggerName], "ljet_passedRangeCheck_" + taggerName); } if (m_config->isMC()) { systematicTree->makeOutputVariable(m_ljet_truthLabel, "ljet_truthLabel"); - for (const std::string& taggerName : m_boostedJetTaggersNames) { + for (const std::string& taggerName : m_boostedJetTaggersNamesCalibrated) { systematicTree->makeOutputVariable(m_ljet_tagSF[taggerName], "ljet_tagSF_" + taggerName); } + + if (systematicTree->name() == nominalTTreeName || systematicTree->name() == nominalLooseTTreeName) { + for (const std::string& taggerName : m_boostedJetTaggersNamesCalibrated) { + systematicTree->makeOutputVariable(m_ljet_tagSFSysVars[taggerName],"ljet_tagSF_" + taggerName + "_variations"); + } + } } } @@ -3194,13 +3202,17 @@ namespace top { for (const std::string& taggerName : m_boostedJetTaggersNames) { m_ljet_isTagged[taggerName].resize(nLargeRJets); + m_ljet_taggingPassedRangeCheck[taggerName].resize(nLargeRJets); } if (m_config->isMC()) { m_ljet_truthLabel.resize(nLargeRJets); - for (const std::string& taggerName : m_boostedJetTaggersNames) { + for (const std::string& taggerName : m_boostedJetTaggersNamesCalibrated) { m_ljet_tagSF[taggerName].resize(nLargeRJets); + if (event.m_hashValue == m_config->nominalHashValue()) { + m_ljet_tagSFSysVars[taggerName].resize(nLargeRJets); + } } - } + } // end isMC() for (const auto* const jetPtr : event.m_largeJets) { m_ljet_pt[i] = jetPtr->pt(); @@ -3213,20 +3225,32 @@ namespace top { m_ljet_substructure[it.first][i] = jetPtr->isAvailable<float>(it.second) ? jetPtr->auxdata<float>(it.second) : -999; } - for (const std::pair<std::string, std::string>& taggerName : m_config->boostedJetTaggers()) { - const std::string decorationNameTag = taggerName.second+"_Tagged"; - const std::string decorationNameSF = taggerName.second+"_SF"; - const std::string tagger = taggerName.first+"_"+taggerName.second; - m_ljet_isTagged[tagger][i] = jetPtr->getAttribute<bool>(decorationNameTag); - if (m_config->isMC()) { - m_ljet_truthLabel[i] = jetPtr->auxdata<int>("R10TruthLabel_R21Consolidated"); - if (jetPtr->isAvailable<float>(decorationNameSF)) { - m_ljet_tagSF[tagger][i] = jetPtr->auxdata<float>(decorationNameSF); - } else { - m_ljet_tagSF[tagger][i] = -9999; - } - } + for (const std::string& taggerName : m_boostedJetTaggersNames) { + m_ljet_isTagged[taggerName][i] = jetPtr->getAttribute<bool>(taggerName + "_Tagged"); + m_ljet_taggingPassedRangeCheck[taggerName][i] = jetPtr->auxdata<char>(taggerName + "_passedRangeCheck"); } + + if (m_config->isMC()) { + m_ljet_truthLabel[i] = jetPtr->auxdata<int>("R10TruthLabel_R21Consolidated"); + for (const std::pair<std::string, std::string>& tagSF : m_config->boostedTaggerSFnames()) { + const std::string& taggerName = tagSF.first; + const std::string& sfNameNominal = tagSF.second; + + m_ljet_tagSF[taggerName][i] = jetPtr->isAvailable<float>(sfNameNominal) ? jetPtr->auxdata<float>(sfNameNominal) : -999; + + if (event.m_hashValue == m_config->nominalHashValue()) { + const std::vector<std::string>& sysNames = m_config->boostedTaggersSFSysNames().at(taggerName); + m_ljet_tagSFSysVars[taggerName][i].resize(sysNames.size()); + for(size_t iname = 0; iname<sysNames.size();iname++) { + if (jetPtr->isAvailable<float>(sysNames[iname])) { + m_ljet_tagSFSysVars[taggerName][i][iname] = jetPtr->auxdata<float>(sysNames[iname]); + } else { + m_ljet_tagSFSysVars[taggerName][i][iname] = -999; + } + } // end loop over SF variations in nominal TTree + } // end if nominal TTree + } // end loop over taggers + } // end isMC ++i; } } diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/TopAnalysis/EventSaverFlatNtuple.h b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/TopAnalysis/EventSaverFlatNtuple.h index c19900f4be4c4451eedc780c1f9a1ba28c3e165a..7e208ab98a9c23b281789b235210b0faa8c395ad 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/TopAnalysis/EventSaverFlatNtuple.h +++ b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/TopAnalysis/EventSaverFlatNtuple.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef EVENTSAVERFLATNTUPLE_H_ @@ -279,6 +279,7 @@ namespace top { // Store boosted jet tagger names std::vector<std::string> m_boostedJetTaggersNames; + std::vector<std::string> m_boostedJetTaggersNamesCalibrated; //some event weights float m_weight_mc; @@ -731,7 +732,9 @@ namespace top { std::unordered_map<std::string, std::vector<float> > m_ljet_substructure; std::unordered_map<std::string, std::vector<char> > m_ljet_isTagged; + std::unordered_map<std::string, std::vector<char> > m_ljet_taggingPassedRangeCheck; std::unordered_map<std::string, std::vector<float> > m_ljet_tagSF; + std::unordered_map<std::string, std::vector<std::vector<float>> > m_ljet_tagSFSysVars; //track jets std::vector<float> m_tjet_pt; @@ -1396,6 +1399,7 @@ namespace top { const std::unordered_map<std::string, std::vector<float> >& ljet_substructure() const {return m_ljet_substructure;} const std::unordered_map<std::string, std::vector<char> >& ljet_isTagged() const {return m_ljet_isTagged;} + const std::unordered_map<std::string, std::vector<char> >& ljet_taggingPassedRangeCheck() const {return m_ljet_taggingPassedRangeCheck;} const std::vector<char>& ljet_isTagged(const std::string& taggerName) {return m_ljet_isTagged[taggerName];} //track jets diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/util/top-xaod.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/util/top-xaod.cxx index cd41597bc8ba7735161136d90a99a543eb8066b0..8489873cba17fb7463e5bc48469cec21c935ad22 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/util/top-xaod.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopAnalysis/util/top-xaod.cxx @@ -500,6 +500,8 @@ int main(int argc, char** argv) { std::string AMITag = topConfig->getAMITag(); ULong64_t totalEvents = 0; ULong64_t totalEventsInFiles = 0; + std::unordered_map<std::string, std::vector<std::string>> boostedTaggersSFSysNames = topConfig->boostedTaggersSFSysNames(); + sumWeights->Branch("dsid", &dsid); sumWeights->Branch("isAFII", &isAFII); sumWeights->Branch("AMITag", &AMITag); @@ -510,6 +512,10 @@ int main(int argc, char** argv) { } sumWeights->Branch("totalEvents", &totalEvents, "totalEvents/l"); + for(auto& it : boostedTaggersSFSysNames) { + sumWeights->Branch(("sysNames_"+it.first).c_str(),&it.second); + } + TTree* sumPdfWeights = 0; std::unordered_map<std::string, std::vector<float>*> totalEventsPdfWeighted; int dsidPdf = topConfig->getDSID(); diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopCPTools/Root/TopBoostedTaggingCPTools.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopCPTools/Root/TopBoostedTaggingCPTools.cxx index 675d043cb41eef0070843886b5027bf8d8520bb5..3ddc2502f3f1620724e977c3ef33081904c1bea8 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopCPTools/Root/TopBoostedTaggingCPTools.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopCPTools/Root/TopBoostedTaggingCPTools.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #include "TopCPTools/TopBoostedTaggingCPTools.h" @@ -41,130 +41,154 @@ namespace top { } - std::vector<std::pair<std::string, std::string> > boostedJetTaggers = m_config->boostedJetTaggers(); + const std::vector<std::pair<std::string, std::string> >& boostedJetTaggers = m_config->boostedJetTaggers(); if (boostedJetTaggers.size() == 0) { ATH_MSG_INFO("top::BoostedTaggingCPTools: boostedJetTagging not set. No need to initialise anything."); return StatusCode::SUCCESS; } + initTaggersMaps(); + if (m_config->applyBoostedJetTaggersUncertainties()) + initSFsMaps(); - top::check( - m_config->sgKeyLargeRJets() == "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets" || m_config->sgKeyLargeRJets() == "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets", + top::check(std::find(std::begin(m_jetCollections),std::end(m_jetCollections),m_config->sgKeyLargeRJets())!=std::end(m_jetCollections), "Error in BoostedTaggingCPTools: boosted jet taggers are not available for this large-R jet collection."); - std::unordered_map<std::string, std::string > taggersConfigs; - std::unordered_map<std::string, std::string > taggerSFconfigs; - std::unordered_map<std::string, std::string > taggerSFnames; - std::unordered_map<std::string, std::string > taggersCalibAreas; - - std::vector<std::string > taggersTypes = { - "JSSWTopTaggerDNN", "SmoothedWZTagger" - }; - - taggersCalibAreas["JSSWTopTaggerDNN"] = "JSSWTopTaggerDNN/Rel21/"; - taggersCalibAreas["SmoothedWZTagger"] = "SmoothedWZTaggers/Rel21/"; - - if (m_config->sgKeyLargeRJets() == "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets") { - taggersConfigs["JSSWTopTaggerDNN:DNNTaggerTopQuarkContained50"] = - "JSSDNNTagger_AntiKt10LCTopoTrimmed_TopQuarkContained_MC16d_20190405_50Eff.dat"; - taggersConfigs["JSSWTopTaggerDNN:DNNTaggerTopQuarkContained80"] = - "JSSDNNTagger_AntiKt10LCTopoTrimmed_TopQuarkContained_MC16d_20190827_80Eff.dat"; - taggersConfigs["JSSWTopTaggerDNN:DNNTaggerTopQuarkInclusive50"] = - "JSSDNNTagger_AntiKt10LCTopoTrimmed_TopQuarkInclusive_MC16d_20190405_50Eff.dat"; - taggersConfigs["JSSWTopTaggerDNN:DNNTaggerTopQuarkInclusive80"] = - "JSSDNNTagger_AntiKt10LCTopoTrimmed_TopQuarkInclusive_MC16d_20190405_80Eff.dat"; - - taggersConfigs["SmoothedWZTagger:SmoothWContained50"] = - "SmoothedContainedWTagger_AntiKt10LCTopoTrimmed_FixedSignalEfficiency50_MC16d_20190410.dat"; - taggersConfigs["SmoothedWZTagger:SmoothWContained80"] = - "SmoothedContainedWTagger_AntiKt10LCTopoTrimmed_FixedSignalEfficiency80_MC16d_20190410.dat"; - - taggersConfigs["SmoothedWZTagger:SmoothZContained50"] = - "SmoothedContainedZTagger_AntiKt10LCTopoTrimmed_FixedSignalEfficiency50_MC16d_20190410.dat"; - taggersConfigs["SmoothedWZTagger:SmoothZContained80"] = - "SmoothedContainedZTagger_AntiKt10LCTopoTrimmed_FixedSignalEfficiency80_MC16d_20190410.dat"; - - // tagger SF uncertainties - taggerSFconfigs["JSSWTopTaggerDNN:DNNTaggerTopQuarkContained80"] = - "rel21/Summer2019/R10_SF_LC_DNNContained80_TopTag.config"; - taggerSFnames["JSSWTopTaggerDNN:DNNTaggerTopQuarkContained80"] = "DNNTaggerTopQuarkContained80_SF"; - } else if (m_config->sgKeyLargeRJets() == "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets") { - taggersConfigs["SmoothedWZTagger:SmoothWContained2VarMaxSig"] = - "SmoothedWTagger_AntiKt10TrackCaloClusterTrimmed_MaxSignificance_2Var_MC16d_20190809.dat"; - taggersConfigs["SmoothedWZTagger:SmoothZContained2VarMaxSig"] = - "SmoothedZTagger_AntiKt10TrackCaloClusterTrimmed_MaxSignificance_2Var_MC16d_20190809.dat"; - - taggersConfigs["SmoothedWZTagger:SmoothW3VarMaxSig"] = - "SmoothedContainedWTagger_AntiKt10TrackCaloClusterTrimmed_MaxSignificance_3Var_MC16d_20190410.dat"; - taggersConfigs["SmoothedWZTagger:SmoothZ3VarMaxSig"] = - "SmoothedContainedZTagger_AntiKt10TrackCaloClusterTrimmed_MaxSignificance_3Var_MC16d_20190410.dat"; - - // tagger SF uncertainties - taggerSFconfigs["SmoothedWZTagger:SmoothWContained2VarMaxSig"] = - "rel21/Summer2019/R10_SF_TCC_2VarSmooth_WTag.config"; - taggerSFnames["SmoothedWZTagger:SmoothWContained2VarMaxSig"] = "SmoothWContained2VarMaxSig_SF"; - taggerSFconfigs["SmoothedWZTagger:SmoothZContained2VarMaxSig"] = - "rel21/Summer2019/R10_SF_TCC_2VarSmooth_ZTag.config"; - taggerSFnames["SmoothedWZTagger:SmoothZContained2VarMaxSig"] = "SmoothZContained2VarMaxSig_SF"; - } - for (const std::pair<std::string, std::string>& name : boostedJetTaggers) { const std::string& taggerType = name.first; - const std::string& shortName = name.second; - const std::string fullName = taggerType + "_" + shortName; // Name to idendify tagger - const std::string origName = taggerType + ":" + shortName; // Original name set in the top config - - top::check(taggersConfigs.find(origName) != taggersConfigs.end(), - ("Error in BoostedTaggingCPTools: Unknown tagger in the config file: " + origName).c_str()); - - top::check(std::find(taggersTypes.begin(), taggersTypes.end(), - taggerType) != taggersTypes.end(), "Error in BoostedTaggingCPTools: Unknown TAGGER_TYPE."); - if (taggerType == "JSSWTopTaggerDNN") top::check(ASG_MAKE_ANA_TOOL(m_taggers[fullName], - JSSWTopTaggerDNN), - "Failed to make " + origName); - else if (taggerType == "SmoothedWZTagger") top::check(ASG_MAKE_ANA_TOOL(m_taggers[fullName], - SmoothedWZTagger), - "Failed to make " + origName); - - m_taggers[fullName].setName(fullName); - top::check(m_taggers[fullName].setProperty("ConfigFile", - taggersConfigs[origName]), "Failed to set ConfigFile for " + origName); - top::check(m_taggers[fullName].setProperty("ContainerName", - m_config->sgKeyLargeRJets()), "Failed to set ContainerName " + origName); - top::check(m_taggers[fullName].setProperty("CalibArea", - taggersCalibAreas[taggerType]), - "Failed to set CalibArea for " + origName); + const std::string& taggerName = name.second; + + top::check(m_taggersConfigs.find(taggerName) != std::end(m_taggersConfigs), + ("Error in BoostedTaggingCPTools: Unknown tagger in the config file: " + taggerName).c_str()); + + top::check(std::find(m_taggersTypes.begin(), m_taggersTypes.end(), taggerType) != m_taggersTypes.end(), + "Error in BoostedTaggingCPTools: Unknown TAGGER_TYPE."); + if (taggerType == "JSSWTopTaggerDNN") + top::check(ASG_MAKE_ANA_TOOL(m_taggers[taggerName], JSSWTopTaggerDNN), "Failed to make " + taggerName); + else if (taggerType == "SmoothedWZTagger") + top::check(ASG_MAKE_ANA_TOOL(m_taggers[taggerName], SmoothedWZTagger), "Failed to make " + taggerName); + + m_taggers[taggerName].setName(taggerName); + top::check(m_taggers[taggerName].setProperty("ConfigFile", m_taggersConfigs[taggerName]), + "Failed to set ConfigFile for " + taggerName); + top::check(m_taggers[taggerName].setProperty("ContainerName", m_config->sgKeyLargeRJets()), + "Failed to set ContainerName " + taggerName); + top::check(m_taggers[taggerName].setProperty("CalibArea", m_taggersCalibAreas[taggerType]), + "Failed to set CalibArea for " + taggerName); // not all BJT taggers implement IsMC property -- only those that have calibration SFs // so we have to check here that we try to set this property only where applicable if (taggerType == "JSSWTopTaggerDNN" || taggerType == "SmoothedWZTagger") { - top::check(m_taggers[fullName].setProperty("IsMC", m_config->isMC()), "Failed to set IsMC for " + origName); + top::check(m_taggers[taggerName].setProperty("IsMC", m_config->isMC()), + "Failed to set IsMC for " + taggerName); } - top::check(m_taggers[fullName].initialize(), "Failed to initialize " + origName); + top::check(m_taggers[taggerName].initialize(), "Failed to initialize " + taggerName); // initialize SF uncertainty tools for supported WPs - if (m_config->isMC()) { + if (m_config->isMC() && m_config->applyBoostedJetTaggersUncertainties()) { std::string jet_def = m_config->sgKeyLargeRJets(); jet_def.erase(jet_def.length() - 4); // jet collection name sans 'Jets' suffix - const std::string name = "JetSFuncert_" + fullName; + const std::string name = "JetSFuncert_" + taggerName; try { - const std::string& cfg = taggerSFconfigs.at(origName); + const std::string& cfg = m_taggerSFsConfigs.at(taggerName); JetUncertaintiesTool* jet_SF_tmp = new JetUncertaintiesTool(name); top::check(jet_SF_tmp->setProperty("JetDefinition", jet_def), "Failed to set JetDefinition for " + name); top::check(jet_SF_tmp->setProperty("MCType", "MC16"), "Failed to set MCType for " + name); - top::check(jet_SF_tmp->setProperty("ConfigFile", cfg), "Failed to set MCType for " + name); + top::check(jet_SF_tmp->setProperty("ConfigFile", cfg), "Failed to set ConfigFile for " + name); top::check(jet_SF_tmp->setProperty("IsData", false), "Failed to set IsData for " + name); top::check(jet_SF_tmp->initialize(), "Failed to initialize " + name); - m_tagSFuncertTool[fullName] = jet_SF_tmp; - m_config->setCalibBoostedJetTagger(fullName, taggerSFnames[origName]); + m_tagSFuncertTool[taggerName] = jet_SF_tmp; + m_config->setCalibBoostedJetTagger(taggerName, m_taggerSFsNames[taggerName]); } catch (std::out_of_range& e) { // skip taggers which do not yet have SFs available - ATH_MSG_WARNING("Boosted jet tagger " + fullName + " is not yet calibrated! No SFs are available."); + ATH_MSG_WARNING("Boosted jet tagger " + taggerName + " is not yet calibrated! No SFs are available."); } } } return StatusCode::SUCCESS; } + + void BoostedTaggingCPTools::initTaggersMaps() { + + // Calib areas + m_taggersCalibAreas["JSSWTopTaggerDNN"] = "JSSWTopTaggerDNN/Rel21/"; + m_taggersCalibAreas["SmoothedWZTagger"] = "SmoothedWZTaggers/Rel21/"; + + // Supported tagger types + m_taggersTypes = { + "JSSWTopTaggerDNN", "SmoothedWZTagger" + }; + + // Supported jet collections + m_jetCollections = { + "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets", + "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets" + }; + + + auto setConfig = [this](const std::string& tagger, const std::string& configName) { + m_taggersConfigs[tagger] = configName; + }; + + if (m_config->sgKeyLargeRJets() == "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets") { + + // Top taggers + setConfig("DNNTaggerTopQuarkContained50","JSSDNNTagger_AntiKt10LCTopoTrimmed_TopQuarkContained_MC16_20201216_50Eff.dat"); + setConfig("DNNTaggerTopQuarkContained80","JSSDNNTagger_AntiKt10LCTopoTrimmed_TopQuarkContained_MC16_20201216_80Eff.dat"); + setConfig("DNNTaggerTopQuarkInclusive50","JSSDNNTagger_AntiKt10LCTopoTrimmed_TopQuarkInclusive_MC16_20201216_50Eff.dat"); + setConfig("DNNTaggerTopQuarkInclusive80","JSSDNNTagger_AntiKt10LCTopoTrimmed_TopQuarkInclusive_MC16_20201216_80Eff.dat"); + + // WZ taggers + setConfig("SmoothWContained50","SmoothedContainedWTagger_AntiKt10LCTopoTrimmed_FixedSignalEfficiency50_MC16_20201216.dat"); + setConfig("SmoothWContained80","SmoothedContainedWTagger_AntiKt10LCTopoTrimmed_FixedSignalEfficiency80_MC16_20201216.dat"); + setConfig("SmoothZContained50","SmoothedContainedZTagger_AntiKt10LCTopoTrimmed_FixedSignalEfficiency50_MC16_20201216.dat"); + setConfig("SmoothZContained80","SmoothedContainedZTagger_AntiKt10LCTopoTrimmed_FixedSignalEfficiency80_MC16_20201216.dat"); + + } else if (m_config->sgKeyLargeRJets() == "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets") { + // WZ taggers + setConfig("SmoothWContained2VarMaxSig","SmoothedWTagger_AntiKt10TrackCaloClusterTrimmed_MaxSignificance_2Var_MC16d_20190809.dat"); + setConfig("SmoothZContained2VarMaxSig","SmoothedZTagger_AntiKt10TrackCaloClusterTrimmed_MaxSignificance_2Var_MC16d_20190809.dat"); + setConfig("SmoothW3VarMaxSig","SmoothedContainedWTagger_AntiKt10TrackCaloClusterTrimmed_MaxSignificance_3Var_MC16d_20190410.dat"); + setConfig("SmoothZ3VarMaxSig","SmoothedContainedZTagger_AntiKt10TrackCaloClusterTrimmed_MaxSignificance_3Var_MC16d_20190410.dat"); + } + + } + + + + void BoostedTaggingCPTools::initSFsMaps() { + // Here we initialize SFs maps + + // This lambda function is universal for all taggers + auto setMaps = [this](const std::string& configPath, const std::string& tagger, const std::string& configName) { + m_taggerSFsConfigs[tagger] = configPath + "/" + configName; + m_taggerSFsNames[tagger] = tagger+"_SF"; + }; + + if (m_config->sgKeyLargeRJets() == "AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets") { + // Tagging scale factors availabel for AntiKt10LCTopoTrimmedPtFrac5SmallR20Jets + + const std::string configPath="rel21/Fall2020"; + //Top taggers + setMaps(configPath,"DNNTaggerTopQuarkContained50","R10_SF_LCTopo_TopTagContained_SigEff50.config"); + setMaps(configPath,"DNNTaggerTopQuarkContained80","R10_SF_LCTopo_TopTagContained_SigEff80.config"); + setMaps(configPath,"DNNTaggerTopQuarkInclusive50","R10_SF_LCTopo_TopTagInclusive_SigEff50.config"); + setMaps(configPath,"DNNTaggerTopQuarkInclusive80","R10_SF_LCTopo_TopTagInclusive_SigEff80.config"); + //WZ taggers + setMaps(configPath,"SmoothWContained50","R10_SF_LCTopo_WTag_SigEff50.config"); + setMaps(configPath,"SmoothWContained80","R10_SF_LCTopo_WTag_SigEff80.config"); + + } else if (m_config->sgKeyLargeRJets() == "AntiKt10TrackCaloClusterTrimmedPtFrac5SmallR20Jets") { + // Tagging scale factors available for some of the taggers for TCC jets + + const std::string configPath="rel21/Summer2019/"; + //WZ taggers + setMaps(configPath,"SmoothWContained2VarMaxSig","R10_SF_TCC_2VarSmooth_WTag.config"); + setMaps(configPath,"SmoothZContained2VarMaxSig","R10_SF_TCC_2VarSmooth_ZTag.config"); + } + } + + } // namespace top diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopCPTools/TopCPTools/TopBoostedTaggingCPTools.h b/PhysicsAnalysis/TopPhys/xAOD/TopCPTools/TopCPTools/TopBoostedTaggingCPTools.h index 9cb78b2eef405caf305f5ce6fb94cbb54a16d41f..6a0a939fb61dbd9d9e43fd55c8dd9cc07b56ecfb 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopCPTools/TopCPTools/TopBoostedTaggingCPTools.h +++ b/PhysicsAnalysis/TopPhys/xAOD/TopCPTools/TopCPTools/TopBoostedTaggingCPTools.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2017 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ #ifndef TOPCPTOOLS_TOPBOOSTEDTAGGINGCPTOOLS_H_ @@ -8,7 +8,7 @@ // Include what you use #include <vector> #include <string> -#include <map> +#include <unordered_map> // Framework include(s): #include "AsgTools/AsgTool.h" @@ -30,6 +30,16 @@ namespace top { private: std::shared_ptr<top::TopConfig> m_config; + std::vector<std::string> m_jetCollections; + std::vector<std::string> m_taggersTypes; + std::unordered_map<std::string, std::string > m_taggersConfigs; + std::unordered_map<std::string, std::string > m_taggersCalibAreas; + std::unordered_map<std::string, std::string > m_taggerSFsConfigs; + std::unordered_map<std::string, std::string > m_taggerSFsNames; + + void initTaggersMaps(); + void initSFsMaps(); + std::unordered_map<std::string, asg::AnaToolHandle<IJetDecorator> > m_taggers; std::unordered_map<std::string, ToolHandle<ICPJetUncertaintiesTool> > m_tagSFuncertTool; }; diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/Root/ConfigurationSettings.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/Root/ConfigurationSettings.cxx index 1ffdb9d04f94b97475847d4de9f30690657b081c..5b6b88676a03f0a3546f1b4d8c86e74a6f9bbbfb 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/Root/ConfigurationSettings.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/Root/ConfigurationSettings.cxx @@ -233,6 +233,7 @@ namespace top { "Boosted jet taggers to use in the analysis, separated by commas or white spaces." " By default, no tagger is used.", " "); + registerParameter("BoostedJetTaggingUncertainties", "Whether to enable BoostedJetTaggers SF systematics. Temporary to test JetUncertainties in r22.", "False", {"True", "False"}); registerParameter("TrackJetPt", "Track Jet pT cut for object selection (in MeV). Default 10 GeV.", "10000."); registerParameter("TrackJetEta", "Absolute Track Jet eta cut for object selection. Default 2.5.", "2.5"); diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/Root/TopConfig.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/Root/TopConfig.cxx index 91133e26c41b22e39be67ba7ad99564e59fa9fef..e12343053ea996d338d6a27c1943abeed8f74012 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/Root/TopConfig.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/Root/TopConfig.cxx @@ -1525,6 +1525,8 @@ namespace top { m_chosen_boostedJetTaggers.push_back(std::make_pair(helpvec[0], helpvec[1])); } + m_applyBoostedTaggerUncertainties = (settings->value("BoostedJetTaggingUncertainties") == "True"); + m_btagging_cdi_path = settings->value("BTagCDIPath"); // now get all Btagging WP from the config file, and store them properly in a map. @@ -2073,6 +2075,11 @@ namespace top { m_boostedTaggerSFnames[WP] = SFname; } + void TopConfig::applyBoostedJetTaggersUncertainties(bool flag) { + if (!m_configFixed) + m_applyBoostedTaggerUncertainties = flag; + } + std::string TopConfig::FormatedWP(std::string raw_WP) { // just to have some backward compatibility... if (raw_WP == "60%") return "FixedCutBEff_60"; diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/TopConfiguration/TopConfig.h b/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/TopConfiguration/TopConfig.h index d267cc43cfce5591cb2803c8e804f19150c3073a..3e31989abb488bf2c7c789cc209b47df150a47de 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/TopConfiguration/TopConfig.h +++ b/PhysicsAnalysis/TopPhys/xAOD/TopConfiguration/TopConfiguration/TopConfig.h @@ -1721,9 +1721,16 @@ namespace top { inline virtual unsigned int trkjet_btagging_num_Light_eigenvars(std::string WP) const {return bTag_eigen_light_trkJet.at(WP);} - const std::vector<std::pair<std::string, std::string> > boostedJetTaggers() const {return m_chosen_boostedJetTaggers;} - const std::unordered_map<std::string, std::string> boostedTaggerSFnames() const {return m_boostedTaggerSFnames;} + const std::vector<std::pair<std::string, std::string> >& boostedJetTaggers() const {return m_chosen_boostedJetTaggers;} + const std::unordered_map<std::string, std::string>& boostedTaggerSFnames() const {return m_boostedTaggerSFnames;} + const std::unordered_map<std::string, std::vector<std::string>>& boostedTaggersSFSysNames() const {return m_boostedTaggersSFSysNames;} void setCalibBoostedJetTagger(const std::string& WP, const std::string& SFname); + void setBoostedTaggersSFSysNames(const std::unordered_map<std::string, std::vector<std::string>>& sysNames) {m_boostedTaggersSFSysNames=sysNames;} + // TEMPORARY methods to enable/disable boosted tagging SF uncertainties + // TODO implemented for testing of JetUncertainties in r22 until porting is fully done + inline bool applyBoostedJetTaggersUncertainties() const { return m_applyBoostedTaggerUncertainties; } + void applyBoostedJetTaggersUncertainties(bool flag); + // B-tagging WPs requested by user (updated to pair of strings to hold algorithm and WP) const std::vector<std::pair<std::string, std::string> > bTagWP() const {return m_chosen_btaggingWP_caloJet;} const std::vector<std::pair<std::string, std::string> > bTagWP_trkJet() const {return m_chosen_btaggingWP_trkJet;} @@ -2465,6 +2472,8 @@ namespace top { // Boosted jet taggers requested by user std::vector<std::pair<std::string, std::string> > m_chosen_boostedJetTaggers; std::unordered_map<std::string, std::string> m_boostedTaggerSFnames; + std::unordered_map<std::string, std::vector<std::string>> m_boostedTaggersSFSysNames; + bool m_applyBoostedTaggerUncertainties; // B-tagging WPs requested by the user (updated to pair of string to hold algorithm and WP) std::vector<std::pair<std::string, std::string> > m_chosen_btaggingWP; diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/Root/JetObjectCollectionMaker.cxx b/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/Root/JetObjectCollectionMaker.cxx index fee4bb13a6e5666423be5e25296bbe2bab7c7d45..6c344ed080905379fc170e7b9170a9c25926a937 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/Root/JetObjectCollectionMaker.cxx +++ b/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/Root/JetObjectCollectionMaker.cxx @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ // $Id: JetObjectCollectionMaker.cxx 809674 2017-08-23 14:10:24Z iconnell $ @@ -202,14 +202,8 @@ namespace top { std::string largeRModName = getLargeRModName(m_config->largeRJetUncertainties_NPModel()); CP::SystematicSet largeRsysts; if (m_config->useLargeRJets() && m_config->isMC()) { //No JES uncertainties for Data at the moment - if ((m_config->largeRJESJMSConfig() == "CombMass") || (m_config->largeRJESJMSConfig() == "TCCMass")) { //TA mass - // and - // combined - // mass not - // supported - // for - // JMS/JMR - // for now + if ((m_config->largeRJESJMSConfig() == "CombMass") + || (m_config->largeRJESJMSConfig() == "TCCMass")) { largeRsysts.insert(m_jetUncertaintiesToolLargeR->recommendedSystematics()); } else { ATH_MSG_WARNING( @@ -218,14 +212,39 @@ namespace top { } ///-- Large R jet tagger scale factor uncertainties -- /// - if (m_config->isMC() && m_config->useLargeRJets()) { + if (m_config->isMC() && m_config->useLargeRJets() && m_config->applyBoostedJetTaggersUncertainties()) { for (const auto& name : m_config->boostedTaggerSFnames()) { ToolHandle<ICPJetUncertaintiesTool> tmp_SF_uncert_tool("JetSFuncert_" + name.first); if (tmp_SF_uncert_tool.retrieve()) { - largeRsysts.insert(tmp_SF_uncert_tool->recommendedSystematics()); + + m_tagSFUncorrelatedSystematics[name.first].clear(); + CP::SystematicSet correlatedSys,uncorrelatedSys; + const CP::SystematicSet& recommendedSys = tmp_SF_uncert_tool->recommendedSystematics(); + + for (const CP::SystematicVariation& sys : recommendedSys) { + bool res = ((sys.name().find("TopTag") == std::string::npos) && + (sys.name().find("WTag") == std::string::npos) && + (sys.name().find("ZTag") == std::string::npos) && + (sys.name().find("JetTag") == std::string::npos)); + + if(res) { + correlatedSys.insert(sys); + } + else { + uncorrelatedSys.insert(sys); + } + } + + m_tagSFUncorrelatedSystematics[name.first] = CP::make_systematics_vector(uncorrelatedSys); + for(const CP::SystematicSet& sys : m_tagSFUncorrelatedSystematics[name.first]) { + if(sys.name()!="") m_tagSFSysNames[name.first].push_back(name.first + "_" + sys.name()); + } + largeRsysts.insert(correlatedSys); m_tagSFuncertTool[name.first] = tmp_SF_uncert_tool; } } + m_config->setBoostedTaggersSFSysNames(m_tagSFSysNames); + } // add the merged set of systematics for large-R jets including the tagging SF systs @@ -245,7 +264,7 @@ namespace top { top::check(m_jetTruthLabelingTool->setProperty("TruthBosonContainerName", "TruthBoson"), "Failed to set truth container name for m_jetTruthLabelingTool"); top::check(m_jetTruthLabelingTool->setProperty("TruthTopQuarkContainerName", "TruthTop"), "Failed to set truth container name for m_jetTruthLabelingTool"); top::check(m_jetTruthLabelingTool->initialize(), "Failed to initialize m_jetTruthLabelingTool"); - } + } // set the systematics list m_config->systematicsJets(specifiedSystematics()); @@ -275,9 +294,8 @@ namespace top { // because we have to apply tagger inbetween JES uncertainty tool and the tagging SF tool if (m_config->useLargeRJets()) { for (const std::pair<std::string, std::string>& name : m_config->boostedJetTaggers()) { - std::string fullName = name.first + "_" + name.second; - m_boostedJetTaggers[fullName] = ToolHandle<IJetDecorator>(fullName); - top::check(m_boostedJetTaggers[fullName].retrieve(), "Failed to retrieve " + fullName); + m_boostedJetTaggers[name.second] = ToolHandle<IJetDecorator>(name.second); + top::check(m_boostedJetTaggers[name.second].retrieve(), "Failed to retrieve " + name.second); } } @@ -315,6 +333,8 @@ namespace top { ///-- First calibrate the nominal jets, everything else comes from this, so let's only do it once not 3000 times // --/// top::check(calibrate(isLargeR), "Failed to calibrate jets"); + if (isLargeR) + top::check(tagNominalLargeRJets(), "Failed to tag large-R jets"); ///-- Return after calibrating the nominal --/// return StatusCode::SUCCESS; @@ -345,6 +365,8 @@ namespace top { // for systematically-shifted shallow copies as well top::check(tagNominalLargeRJets(), "Failed to tag large-R jets"); if (m_config->isMC()) { + if (m_config->applyBoostedJetTaggersUncertainties()) + top::check(applyTaggingSFSystematic(),"Failed to apply large-R tagging SFs syst."); top::check(applySystematic(m_jetUncertaintiesToolLargeR, m_systMap_LargeR, true), "Failed to apply large-R syst."); } @@ -507,6 +529,60 @@ namespace top { return StatusCode::SUCCESS; } + StatusCode JetObjectCollectionMaker::applyTaggingSFSystematic() { + + ///-- Get calibrated jets --/// + const xAOD::JetContainer* ljets(nullptr); + top::check(evtStore()->retrieve(ljets, m_config->sgKeyLargeRJets( + m_nominalSystematicSet.hash())), "Failed to retrieve Jets"); + + + ///-- Shallow copy of the xAOD --/// + std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > + shallow_xaod_copy = xAOD::shallowCopyContainer(*ljets); + + const size_t njets = ljets->size(); + + const std::unordered_map<std::string,std::string>& sfNames = m_config->boostedTaggerSFnames(); + + for(auto& it : m_tagSFuncertTool) { + ToolHandle<ICPJetUncertaintiesTool>& tool = it.second; + const std::string& fullName=it.first; + + const std::string sfNameNominal = sfNames.at(fullName); + const SG::AuxElement::Accessor<float> accSF(sfNameNominal); + const SG::AuxElement::Decorator<float> decNominalSF(sfNameNominal); + + for(const CP::SystematicSet& sys : m_tagSFUncorrelatedSystematics[fullName]) { + + top::check(tool->applySystematicVariation(sys), "Failed to applySystematicVariation"); + + const std::string sfNameShifted = fullName + "_" + sys.name(); + + // first reset the shallow-copy SF to nominal value from the original calibrated jet container + // this is because some of the uncertainties are a (1+/-delta) correction for already decorated SF + for (size_t i = 0; i < njets; ++i) { + xAOD::Jet* shallowJet = shallow_xaod_copy.first->at(i); + const xAOD::Jet* jet = ljets->at(i); + decNominalSF(*shallowJet) = accSF(*jet); + } + + top::check(tool->applyContainerCorrection(*shallow_xaod_copy.first), + "Failed to apply large-R jet SF uncertainties in nominal TTree"); + + for(size_t i = 0; i < njets; i++) { + xAOD::Jet* shallowJet = shallow_xaod_copy.first->at(i); + const xAOD::Jet* jet = ljets->at(i); + + float sf = accSF.isAvailable(*shallowJet) ? accSF(*shallowJet) : -999.; + jet->auxdecor<float>(sfNameShifted.c_str()) = sf; + } // end loop over jets + } // end loop over SF systs + } // end loop over tagging WP + + return StatusCode::SUCCESS; + } + StatusCode JetObjectCollectionMaker::applySystematic(ToolHandle<ICPJetUncertaintiesTool>& tool, const std::unordered_map<CP::SystematicSet, CP::SystematicSet>& map, @@ -514,109 +590,105 @@ namespace top { ///-- Get calibrated jets --/// const xAOD::JetContainer* xaod(nullptr); + // helper string for error messages, so we know if we are running over + // small-R or large-R jets + const std::string msg_jet_collection = isLargeR ? "large-R jets" : "small-R jets"; + if (!isLargeR) { top::check(evtStore()->retrieve(xaod, m_config->sgKeyJetsStandAlone( - m_nominalSystematicSet.hash())), "Failed to retrieve Jets"); + m_nominalSystematicSet.hash())), "Failed to retrieve " + msg_jet_collection); } else { top::check(evtStore()->retrieve(xaod, m_config->sgKeyLargeRJets( - m_nominalSystematicSet.hash())), "Failed to retrieve Jets"); + m_nominalSystematicSet.hash())), "Failed to retrieve " + msg_jet_collection); } ///-- Loop over the systematics --/// for (Itr syst = map.begin(); syst != map.end(); ++syst) { ///-- Don't do the nominal, we've already done that --/// - if ((*syst).second.hash() != m_nominalSystematicSet.hash()) { - ///-- Tell the tool which systematic to use --/// - ///-- Here we use the second, original CP::SystematicSet --/// - top::check(tool->applySystematicVariation((*syst).second), - "Failed to applySystematicVariation"); - - if (isLargeR && m_config->isMC()) { - // for boosted tagging SFs, apply syst variation for all initialized WPs - for (std::pair<const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF : m_tagSFuncertTool) { - top::check(tagSF.second->applySystematicVariation((*syst).second), "Failed to applySystematicVariation"); - } + if ((*syst).second.hash() == m_nominalSystematicSet.hash()) + continue; + ///-- Tell the tool which systematic to use --/// + ///-- Here we use the second, original CP::SystematicSet --/// + top::check(tool->applySystematicVariation((*syst).second), + "Failed to applySystematicVariation for " + msg_jet_collection); + + if (isLargeR && m_config->isMC()) { + // for boosted tagging SFs, apply syst variation for all initialized WPs + for (std::pair<const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF : m_tagSFuncertTool) { + top::check(tagSF.second->applySystematicVariation((*syst).second), + "Failed to applySystematicVariation for " + msg_jet_collection); } + } - ///-- Shallow copy of the xAOD --/// - std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > - shallow_xaod_copy = xAOD::shallowCopyContainer(*xaod); - - ///-- Loop over the xAOD Container --/// - for (auto jet : *(shallow_xaod_copy.first)) { - if (isLargeR && m_config->isMC()) { //JES for large-R jets only exist for MC - ///-- Only large R jets with the following properties can be calibrated.--/// - bool calibratable_jet = (std::fabs(jet->eta()) <= 2.0 - && jet->pt() > 175e3); //lower than 200e3 to allow studying on migration - std::string jetCalibrationNameLargeR = m_config->sgKeyLargeRJets(); - if (jetCalibrationNameLargeR.find("TrackCaloCluster") != std::string::npos) { //TCC jet - calibratable_jet = (jet->m() / jet->pt() <= 1. - && jet->m() / jet->pt() >= 0. - && std::fabs(jet->eta()) <= 2.0 - && jet->pt() > 150e3 - && jet->pt() < 3000e3); - } - if (!calibratable_jet) continue; - } - ///-- Apply Corrrection --/// - if (!(isLargeR && !m_config->isMC())) { //Large-R jet uncertainties don't apply to Data - top::check(tool->applyCorrection(*jet), "Failed to applyCorrection"); - } - ///-- Update JVT --/// - if (!isLargeR) jet->auxdecor<float>("AnalysisTop_JVT") = m_jetUpdateJvtTool->updateJvt(*jet); - - ///-- Decorate fJVT for systematics too --/// - // Check if the derivation we are running on contains - // MET_Track (once) before applying the fJVT decoration - if (!isLargeR && (m_config->doForwardJVTinMET() || m_config->getfJVTWP() != "None")) { - static bool checked_track_MET = false; - if (!checked_track_MET) { - if (evtStore()->contains<xAOD::MissingETContainer>("MET_Track")) { - m_do_fjvt = true; - } else { - ATH_MSG_ERROR(" Cannot retrieve MET_Track, fJVT values can't be calculated correctly!!"); - return StatusCode::FAILURE; - } - checked_track_MET = true; - } - } - if (m_do_fjvt) { - top::check(!m_jetSelectfJvtTool->modify(*shallow_xaod_copy.first), - "Failed to apply fJVT decoration"); - } + ///-- Shallow copy of the xAOD --/// + std::pair< xAOD::JetContainer*, xAOD::ShallowAuxContainer* > + shallow_xaod_copy = xAOD::shallowCopyContainer(*xaod); + + // apply large-R jet tagging SF uncertainties + if (isLargeR && m_config->isMC()) { + for (std::pair<const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF : m_tagSFuncertTool) { + top::check(tagSF.second->applyContainerCorrection(*shallow_xaod_copy.first), + "Failed to apply large-R jet tagging SF uncertainties"); + } + } + // apply JES/JER uncertainties -- for large-R jets only on MC + if ((isLargeR && m_config->isMC()) || (!isLargeR)) { + top::check(tool->applyContainerCorrection(*shallow_xaod_copy.first), + "Failed to apply JES/JER uncertainties for " + msg_jet_collection); + } - ///-- Apply large-R jet tagging SF uncertainties --/// - if (isLargeR && m_config->isMC()) { - for (std::pair<const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF : m_tagSFuncertTool) { - top::check(tagSF.second->applyCorrection(*jet), "Failed to applyCorrection"); + ///-- Loop over the xAOD Container --/// + //FIXME -- update JVT tools to container interface + for (auto jet : *(shallow_xaod_copy.first)) { + + ///-- Apply Corrrection --/// + ///-- Update JVT --/// + if (!isLargeR) jet->auxdecor<float>("AnalysisTop_JVT") = m_jetUpdateJvtTool->updateJvt(*jet); + + ///-- Decorate fJVT for systematics too --/// + // Check if the derivation we are running on contains + // MET_Track (once) before applying the fJVT decoration + if (!isLargeR && (m_config->doForwardJVTinMET() || m_config->getfJVTWP() != "None")) { + static bool checked_track_MET = false; + if (!checked_track_MET) { + if (evtStore()->contains<xAOD::MissingETContainer>("MET_Track")) { + m_do_fjvt = true; + } else { + ATH_MSG_ERROR(" Cannot retrieve MET_Track, fJVT values can't be calculated correctly!!"); + return StatusCode::FAILURE; } + checked_track_MET = true; } } - - ///-- set links to original objects- needed for MET calculation --/// - bool setLinks = xAOD::setOriginalObjectLink(*xaod, - *shallow_xaod_copy.first); - if (!setLinks) ATH_MSG_ERROR(" Cannot set original object links" - " for jets, MET recalculation may struggle"); - - ///-- Save corrected xAOD Container to StoreGate / TStore --/// - ///-- Here we use the first, AnalysisTop modified CP::SystematicSer --/// - ///-- This allows us to run multiple JES scenarios, which all have the same hash values --/// - std::string outputSGKey; - if (isLargeR) { - outputSGKey = m_config->sgKeyLargeRJets((*syst).first.hash()); - } else { - outputSGKey = m_config->sgKeyJetsStandAlone((*syst).first.hash()); + if (m_do_fjvt) { + top::check(!m_jetSelectfJvtTool->modify(*shallow_xaod_copy.first), + "Failed to apply fJVT decoration"); } - std::string outputSGKeyAux = outputSGKey + "Aux."; + } - StatusCode save = evtStore()->tds()->record(shallow_xaod_copy.first, outputSGKey); - StatusCode saveAux = evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux); - if (!save || !saveAux) { - return StatusCode::FAILURE; - } + ///-- set links to original objects- needed for MET calculation --/// + bool setLinks = xAOD::setOriginalObjectLink(*xaod, + *shallow_xaod_copy.first); + if (!setLinks) ATH_MSG_ERROR(" Cannot set original object links" + " for jets, MET recalculation may struggle"); + + ///-- Save corrected xAOD Container to StoreGate / TStore --/// + ///-- Here we use the first, AnalysisTop modified CP::SystematicSer --/// + ///-- This allows us to run multiple JES scenarios, which all have the same hash values --/// + std::string outputSGKey; + if (isLargeR) { + outputSGKey = m_config->sgKeyLargeRJets((*syst).first.hash()); + } else { + outputSGKey = m_config->sgKeyJetsStandAlone((*syst).first.hash()); + } + std::string outputSGKeyAux = outputSGKey + "Aux."; + + StatusCode save = evtStore()->tds()->record(shallow_xaod_copy.first, outputSGKey); + StatusCode saveAux = evtStore()->tds()->record(shallow_xaod_copy.second, outputSGKeyAux); + if (!save || !saveAux) { + return StatusCode::FAILURE; } } @@ -695,7 +767,6 @@ namespace top { const std::string& modName, bool isLargeR, bool onlyJER) { ///-- Get the recommended systematics from the tool, in std::vector format --/// const std::vector<CP::SystematicSet> systList = CP::make_systematics_vector(recommendedSysts); - for (const CP::SystematicSet& s : systList) { if (s.size() == 1) { @@ -743,15 +814,25 @@ namespace top { m_nominalSystematicSet.hash())), "Failed to retrieve nominal calibrated large-R jets"); - top::check(tagLargeRJet(*xaod_calibrated_jets), "Failed to tag large-R jet"); + top::check(tagLargeRJets(*xaod_calibrated_jets), "Failed to tag large-R jet"); return StatusCode::SUCCESS; } - StatusCode JetObjectCollectionMaker::tagLargeRJet(const xAOD::JetContainer& container) { + StatusCode JetObjectCollectionMaker::tagLargeRJets(const xAOD::JetContainer& container) { //decorate with boosted-tagging flags for (const std::pair<std::string, std::string>& name : m_config->boostedJetTaggers()) { - const std::string fullName = name.first + "_" + name.second; - top::check(m_boostedJetTaggers[fullName]->decorate(container), "Failed to decorate jets with booster tagger"); + top::check(m_boostedJetTaggers[name.second]->decorate(container), "Failed to decorate jets with booster tagger"); + SG::AuxElement::Decorator<char> passedRangeCheckDec(name.second + "_passedRangeCheck"); + SG::AuxElement::Accessor<bool> validPtRangeLowDec(name.second + "_ValidPtRangeLow"); + SG::AuxElement::Accessor<bool> validPtRangeHighDec(name.second + "_ValidPtRangeHigh"); + SG::AuxElement::Accessor<bool> validEtaRangeDec(name.second + "_ValidEtaRange"); + for (const xAOD::Jet *jet : container) { + if (validPtRangeLowDec(*jet) && validPtRangeHighDec(*jet) && validEtaRangeDec(*jet)) { + passedRangeCheckDec(*jet) = 1; + } else { + passedRangeCheckDec(*jet) = 0; + } + } } return StatusCode::SUCCESS; } diff --git a/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/TopSystematicObjectMaker/JetObjectCollectionMaker.h b/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/TopSystematicObjectMaker/JetObjectCollectionMaker.h index e36b38332365e7b761bcda6a23e465e931b70400..216f81c0981ddbc2bc3b8424031cbbb7070dcab2 100644 --- a/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/TopSystematicObjectMaker/JetObjectCollectionMaker.h +++ b/PhysicsAnalysis/TopPhys/xAOD/TopSystematicObjectMaker/TopSystematicObjectMaker/JetObjectCollectionMaker.h @@ -1,5 +1,5 @@ /* - Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration + Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration */ // $Id: JetObjectCollectionMaker.h 809674 2017-08-23 14:10:24Z iconnell $ @@ -90,8 +90,8 @@ namespace top { virtual std::string getLargeRModName(const std::string& NPModel) const; // specify Systematic virtual void addSystematics(const std::set<std::string>& specifiedSystematics, - const CP::SystematicSet& recommendedSysts, std::unordered_map<CP::SystematicSet, - CP::SystematicSet>& map, + const CP::SystematicSet& recommendedSysts, + std::unordered_map<CP::SystematicSet, CP::SystematicSet>& map, const std::string& modName, bool isLargeR = false, bool onlyJER = false); @@ -102,6 +102,8 @@ namespace top { const std::unordered_map<CP::SystematicSet, CP::SystematicSet>& map, bool isLargeR = false); + virtual StatusCode applyTaggingSFSystematic(); + StatusCode printout(const bool isLargeR); private: @@ -130,6 +132,9 @@ namespace top { ToolHandle<ICPJetUncertaintiesTool> m_jetUncertaintiesToolLargeR; std::unordered_map<std::string, ToolHandle<ICPJetUncertaintiesTool> > m_tagSFuncertTool; + std::unordered_map<std::string, std::vector<CP::SystematicSet>> m_tagSFUncorrelatedSystematics; // Uncertainties name fo + std::unordered_map<std::string, std::vector<std::string>> m_tagSFSysNames; + // do decorate the large-R jets with the boosted-tagging flags // and decorate jets with TAccept object containing detailed tag result informaiton @@ -155,7 +160,7 @@ namespace top { StatusCode decorateBJets(xAOD::Jet& jet); StatusCode decorateHSJets(); StatusCode decorateMatchedTruth(); - StatusCode tagLargeRJet(const xAOD::JetContainer& jet); + StatusCode tagLargeRJets(const xAOD::JetContainer& jet); StatusCode tagNominalLargeRJets(); ///-- Large R jet truth labeling --///