Commit 7fcf7621 authored by Christopher Andrew Garner's avatar Christopher Andrew Garner Committed by Nils Erik Krumnack
Browse files

Add support for large-R JER/JMS/JMR consolidated recommendations in AnalysisTop

parent d3260fd7
......@@ -17,12 +17,14 @@
// Jet include(s):
#include "JetCalibTools/JetCalibrationTool.h"
#include "JetUncertainties/JetUncertaintiesTool.h"
#include "JetUncertainties/FFJetSmearingTool.h"
#include "JetMomentTools/JetVertexTaggerTool.h"
#include "JetMomentTools/JetForwardJvtTool.h"
#include "JetSelectorTools/JetCleaningTool.h"
#include "JetJvtEfficiency/JetJvtEfficiency.h"
#include "JetSelectorTools/EventCleaningTool.h"
// MET include(s):
#include "METUtilities/METMaker.h"
#include "METUtilities/METSystematicsTool.h"
......@@ -69,6 +71,7 @@ namespace top {
declareProperty("JetCalibrationToolLargeR", m_jetCalibrationToolLargeR);
declareProperty("JetUncertaintiesTool", m_jetUncertaintiesTool);
declareProperty("FFJetSmearingTool", m_FFJetSmearingTool);
declareProperty("JetUncertaintiesToolReducedNPScenario1", m_jetUncertaintiesToolReducedNPScenario1);
declareProperty("JetUncertaintiesToolReducedNPScenario2", m_jetUncertaintiesToolReducedNPScenario2);
declareProperty("JetUncertaintiesToolReducedNPScenario3", m_jetUncertaintiesToolReducedNPScenario3);
......@@ -369,13 +372,13 @@ namespace top {
// erase "Jets" from the end
jetCalibrationNameLargeR.erase(jetCalibrationNameLargeR.length() - 4);
// Only a single calib config/sequence for MC and data
// so just put it here for now.
std::string calibConfigLargeR = "";
const std::string calibChoice = m_config->largeRJESJMSConfig();
if (asg::ToolStore::contains<IJetCalibrationTool>("JetCalibrationToolLargeR")) {
m_jetCalibrationToolLargeR = asg::ToolStore::get<IJetCalibrationTool>("JetCalibrationToolLargeR");
} else {
// Only a single calib config/sequence for MC and data
// so just put it here for now.
std::string calibConfigLargeR = "";
const std::string calibChoice = m_config->largeRJESJMSConfig();
if (m_config->isMC()) {
if (calibChoice == "CombMass") {
calibConfigLargeR = "JES_MC16recommendation_FatJet_Trimmed_JMS_comb_17Oct2018.config";
......@@ -394,7 +397,7 @@ namespace top {
}
} else { //Insitu calibration for Data
if ((calibChoice == "CombMass") || (calibChoice == "TAMass") || (calibChoice == "CaloMass")) {
calibConfigLargeR = "JES_MC16recommendation_FatJet_Trimmed_JMS_comb_3April2019.config"; //Data has only one
calibConfigLargeR = "JES_MC16recommendation_FatJet_Trimmed_JMS_comb_March2021.config"; //Data has only one
// config file
} else if (calibChoice == "TCCMass") {
calibConfigLargeR = "JES_MC16recommendation_FatJet_TCC_JMS_calo_30Oct2018.config"; //There's no insitu
......@@ -438,11 +441,12 @@ namespace top {
// names = "UJ_2016/Moriond2017/UJ2016_CombinedMass_strong.config" // strong,medium,weak
std::string configDir("");
std::string largeRJESJMS_config = m_config->largeRJetUncertainties_NPModel();
std::string largeRJESJERJMS_unc_config = m_config->largeRJetUncertainties_NPModel();
std::string largeRJMR_unc_config = m_config->largeRJetUncertainties_JMR_NPModel();
std::string calibArea = "None"; // Take the default JetUncertainties CalibArea tag
std::string MC_type = "MC16";
configDir = m_config->largeRJetUncertaintiesConfigDir();
configDir = m_config->largeRJetUncertaintiesConfigDir();
//This has zero impact on the JES uncertainties, but controls how the JER uncertainties (currently only for small-R
// jets) are applied
......@@ -452,12 +456,35 @@ namespace top {
m_jetUncertaintiesToolLargeR
= setupJetUncertaintiesTool("JetUncertaintiesToolLargeR",
jetCalibrationNameLargeR, MC_type, JERisMC,
configDir + "/R10_" + largeRJESJMS_config + ".config", nullptr, "", calibArea);
configDir + "/R10_" + largeRJESJERJMS_unc_config + ".config", nullptr, "", calibArea);
m_FFJetSmearingTool = setupFFJetSmearingTool(calibChoice,configDir + "/R10_" + largeRJMR_unc_config + ".config");
}
return StatusCode::SUCCESS;
}
ICPJetCorrectionTool * JetMETCPTools::setupFFJetSmearingTool(const std::string& mass_def, const std::string& config) {
// <cgarner@physics.utoronto.ca> Added Apr. 13th, 2021
// Function to setup FFJetSmearingTool needed for consolidated JMR uncertainties
const std::string ff_tool_name = "FFJetSmearingTool";
// erase "Mass" from the end
const std::string mass_def_name = mass_def.substr(0, mass_def.size()-4);
ICPJetCorrectionTool * tool = nullptr;
if (asg::ToolStore::contains<ICPJetCorrectionTool>(ff_tool_name)) {
tool = asg::ToolStore::get<ICPJetCorrectionTool>(ff_tool_name);
} else {
tool = new CP::FFJetSmearingTool(ff_tool_name);
top::check(asg::setProperty( tool, "MassDef", mass_def_name ), "Failed to set proper MassDef for FFJetSmearingTool" );
top::check(asg::setProperty( tool, "ConfigFile", config ), "Failed to set proper config file for FFJetSmearingTool" );
top::check(tool->initialize(), "Failed to initialize " + ff_tool_name );
}
return tool;
}
StatusCode JetMETCPTools::setupJetsScaleFactors() {
// <tom.neep@cern.ch> Added 16th Feb 2016.
// Jet JVT tool - can be used for both selection and for SFs
......
......@@ -19,6 +19,7 @@
// Jet include(s):
#include "JetCalibTools/IJetCalibrationTool.h"
#include "JetCPInterfaces/ICPJetUncertaintiesTool.h"
#include "JetCPInterfaces/ICPJetCorrectionTool.h"
#include "JetInterface/IJetUpdateJvt.h"
#include "JetInterface/IJetSelector.h"
#include "JetInterface/IJetModifier.h"
......@@ -29,6 +30,7 @@
#include "METInterface/IMETMaker.h"
#include "METInterface/IMETSystematicsTool.h"
namespace top {
class TopConfig;
......@@ -84,6 +86,7 @@ namespace top {
ToolHandle<ICPJetUncertaintiesTool> m_jetUncertaintiesToolLargeR;
ToolHandle<ICPJetUncertaintiesTool> m_jetUncertaintiesTool;
ToolHandle<ICPJetCorrectionTool> m_FFJetSmearingTool;
ToolHandle<ICPJetUncertaintiesTool> m_jetUncertaintiesToolReducedNPScenario1;
ToolHandle<ICPJetUncertaintiesTool> m_jetUncertaintiesToolReducedNPScenario2;
ToolHandle<ICPJetUncertaintiesTool> m_jetUncertaintiesToolReducedNPScenario3;
......@@ -112,6 +115,10 @@ namespace top {
StatusCode setupJetsScaleFactors();
StatusCode setupMET();
ICPJetCorrectionTool * setupFFJetSmearingTool(const std::string& mass_def,const std::string& config);
ICPJetUncertaintiesTool*
setupJetUncertaintiesTool(const std::string& name,
const std::string& jet_def,
......
......@@ -246,12 +246,15 @@ namespace top {
registerParameter("LargeRJetSubstructureVariables",
"List of substructure variables stored in the output separated by commas. By default no variable is added to output.",
" ");
registerParameter("LargeRJetUncertainties_NPModel",
"AllNuisanceParameters, CategoryReduction (default), GlobalReduction, - for LCTopo Large-R Jet Uncertainties or Scale_TCC_all - for TCC Large-R Jet Uncertainties",
"CategoryReduction");
registerParameter("LargeRJetUncertainties_JESJERJMS_NPModel",
"Input form: {A}JES_{B}JER_{C}JMS, see https://twiki.cern.ch/twiki/bin/view/AtlasProtected/JetUncertaintiesRel21ConsolidatedLargeRScaleRes for configuration options, - for LCTopo large-R jet energy scale, energy resolution, and mass scale uncertainties",
"CategoryJES_FullJER_FullJMS");
registerParameter("LargeRJetUncertainties_JMR_NPModel",
"Full (10 NP; aimed at the most precise jet-dependent measurements), Simple (1 NP; flat 20 percent uncertainty, as it was recommended in the past) - for LCTopo large-R jet mass resolution uncertainties",
"FullJMR");
registerParameter("AdvancedUsage_LargeRJetUncertaintiesConfigDir",
"Path to directory containing large-R jet uncertainties config",
"rel21/Summer2019");
"rel21/Winter2021");
registerParameter("LargeRJESJMSConfig",
"Calibration for large-R JES/JMS. CombMass, CaloMass, TCCMass or UFOSDMass (default CombMass).",
"CombMass");
......
......@@ -284,8 +284,9 @@ namespace top {
m_largeRJetPtcut(25000.),
m_largeRJetMasscut(0.),
m_largeRJetEtacut(2.5),
m_largeRJetUncertainties_NPModel("CategoryReduction"),
m_largeRJetUncertainties_NPModel("CategoryJES_FullJER_FullJMS"),
m_largeRJetUncertaintiesConfigDir("SetMe"),
m_largeRJetUncertainties_JMR_NPModel("FullJMR"),
m_largeRJESJMSConfig("SetMe"),
m_trackJetPtcut(7000.0),
......@@ -1402,7 +1403,8 @@ namespace top {
};
}
this->largeRJetUncertainties_NPModel(settings->value("LargeRJetUncertainties_NPModel"));
this->largeRJetUncertainties_NPModel(settings->value("LargeRJetUncertainties_JESJERJMS_NPModel"));
this->largeRJetUncertainties_JMR_NPModel(settings->value("LargeRJetUncertainties_JMR_NPModel"));
this->largeRJetUncertaintiesConfigDir(settings->value("AdvancedUsage_LargeRJetUncertaintiesConfigDir"));
this->largeRJESJMSConfig(settings->value("LargeRJESJMSConfig"));
......@@ -2414,7 +2416,7 @@ namespace top {
void TopConfig::systematicsJets(const std::list<CP::SystematicSet>& syst) {
if (!m_configFixed) {
for (auto s : syst) {
for (auto s : syst) {
m_systHashJets->insert(s.hash());
m_list_systHashAll->push_back(s.hash());
m_list_systHash_electronInJetSubtraction->push_back(s.hash());
......@@ -2430,7 +2432,7 @@ namespace top {
void TopConfig::systematicsLargeRJets(const std::list<CP::SystematicSet>& syst) {
if (!m_configFixed) {
for (auto s : syst) {
for (auto s : syst) {
m_systHashLargeRJets->insert(s.hash());
m_list_systHashAll->push_back(s.hash());
m_systMapLargeRJets->insert(std::make_pair(s.hash(), s));
......
......@@ -1199,7 +1199,13 @@ namespace top {
m_largeRJetUncertainties_NPModel = largeR_config;
}
}
inline virtual void largeRJetUncertainties_JMR_NPModel(const std::string& largeR_JMR_config) {
if (!m_configFixed) {
m_largeRJetUncertainties_JMR_NPModel = largeR_JMR_config;
}
}
inline virtual void largeRJetUncertaintiesConfigDir(const std::string& largeRConfigDir) {
if (!m_configFixed) {
m_largeRJetUncertaintiesConfigDir = largeRConfigDir;
......@@ -1217,6 +1223,7 @@ namespace top {
inline virtual float largeRJetEtacut() const {return m_largeRJetEtacut;}
inline virtual const std::map<std::string,std::string> largeRJetSubstructureVariables() const {return m_largeRJetSubstructureVariables;}
inline virtual const std::string& largeRJetUncertainties_NPModel() const {return m_largeRJetUncertainties_NPModel;}
inline virtual const std::string& largeRJetUncertainties_JMR_NPModel() const {return m_largeRJetUncertainties_JMR_NPModel;}
inline virtual const std::string& largeRJetUncertaintiesConfigDir() const {return m_largeRJetUncertaintiesConfigDir;}
inline virtual const std::string& largeRJESJMSConfig() const {return m_largeRJESJMSConfig;}
......@@ -2405,6 +2412,7 @@ namespace top {
float m_largeRJetEtacut; // large R jet object selection (abs) eta cut
std::map<std::string,std::string> m_largeRJetSubstructureVariables;
std::string m_largeRJetUncertainties_NPModel; //large R JES/(plus old JMS, JMR, JER) uncertainties configuration
std::string m_largeRJetUncertainties_JMR_NPModel; //large R JMR uncertainties configuration
std::string m_largeRJetUncertaintiesConfigDir; //Relative path to directory with large R JES config
// file
//See https://twiki.cern.ch/twiki/bin/view/AtlasProtected/JetUncertaintiesRel21Summer2019LargeR
......
......@@ -45,6 +45,7 @@ namespace top {
m_jetUncertaintiesToolReducedNPScenario3("JetUncertaintiesToolReducedNPScenario3"),
m_jetUncertaintiesToolReducedNPScenario4("JetUncertaintiesToolReducedNPScenario4"),
m_jetUncertaintiesToolLargeR("JetUncertaintiesToolLargeR"),
m_FFJetSmearingTool("FFJetSmearingTool"),
m_jetUpdateJvtTool("JetUpdateJvtTool"),
m_jetSelectfJvtTool("JetSelectfJvtTool"),
......@@ -68,6 +69,7 @@ namespace top {
declareProperty("JetUncertaintiesToolReducedNPScenario3", m_jetUncertaintiesToolReducedNPScenario3);
declareProperty("JetUncertaintiesToolReducedNPScenario4", m_jetUncertaintiesToolReducedNPScenario4);
declareProperty("JetUncertaintiesToolLargeR", m_jetUncertaintiesToolLargeR);
declareProperty("FFJetSmearingTool", m_FFJetSmearingTool);
declareProperty("JetUpdateJvtTool", m_jetUpdateJvtTool);
......@@ -92,6 +94,8 @@ namespace top {
if(m_config->largeRJESJMSConfig() != "UFOSDMass"){
top::check(m_jetUncertaintiesToolLargeR.retrieve(),
"Failed to retrieve JetUncertaintiesToolLargeR");
top::check(m_FFJetSmearingTool.retrieve(),
"Failed to retrieve FFJetSmearingTool");
}
}
......@@ -150,9 +154,12 @@ namespace top {
const std:: string& syststr = m_config->systematics();
std::set<std::string> syst, systLargeR;
if (!m_config->isSystNominal(syststr) && !m_config->isSystAll(syststr)) {
bool ok = m_config->getSystematicsList(syststr, syst);
bool okLargeR = m_config->getSystematicsList(syststr, systLargeR);
if (!ok || !okLargeR) {
ATH_MSG_ERROR(" top::JetObjectCollectionMaker could not determine systematic list");
return StatusCode::FAILURE;
......@@ -196,8 +203,11 @@ namespace top {
onlyJER);
}
}
///-- Large-R JES systematics --///
std::string largeRModName = getLargeRModName(m_config->largeRJetUncertainties_NPModel());
std::string largeRModNameJMR = getLargeRModName(m_config->largeRJetUncertainties_JMR_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
......@@ -209,12 +219,14 @@ namespace top {
// JMS/JMR
// for now
largeRsysts.insert(m_jetUncertaintiesToolLargeR->recommendedSystematics());
largeRsysts.insert(m_FFJetSmearingTool->recommendedSystematics());
} else {
ATH_MSG_WARNING(
"TA Mass & Calo Mass & UFO SD Mass are not supported for large-R jet uncertainties at the moment. Large-R jet systemtatics skipped!");
}
}
///-- Large R jet tagger scale factor uncertainties -- ///
if (m_config->isMC() && m_config->useLargeRJets()) {
for (const std::pair<std::string, std::string>& name : m_config->boostedTaggerSFnames()) {
......@@ -233,8 +245,7 @@ namespace top {
(sys.name().find("WTag") == std::string::npos) &&
(sys.name().find("ZTag") == std::string::npos) &&
(sys.name().find("JetTag") == std::string::npos) &&
(sys.name().find("bTag") == std::string::npos));
(sys.name().find("bTag") == std::string::npos));
res ? correlatedSys.insert(sys) : uncorrelatedSys.insert(sys);
}
......@@ -251,10 +262,12 @@ namespace top {
m_config->setBoostedTaggersSFSysNames(m_tagSFSysNames);
}
// add the merged set of systematics for large-R jets including the tagging SF systs
addSystematics(systLargeR, largeRsysts, m_systMap_LargeR, largeRModName, true);
addSystematics(systLargeR, largeRsysts, m_systMap_LargeR, largeRModName, true, false, largeRModNameJMR);
///-- Large R jet substructure --///
if (m_config->jetSubstructureName() == "Trimmer") m_jetSubstructure.reset(new top::LargeJetTrimmer);
......@@ -273,6 +286,7 @@ namespace top {
top::check(m_jetTruthLabelingTool->initialize(), "Failed to initialize m_jetTruthLabelingTool");
}
// set the systematics list
m_config->systematicsJets(specifiedSystematics());
m_config->systematicsLargeRJets(specifiedSystematicsLargeR());
......@@ -531,6 +545,7 @@ namespace top {
return StatusCode::SUCCESS;
}
StatusCode JetObjectCollectionMaker::applyTaggingSFSystematic() {
///-- Get calibrated jets --///
......@@ -553,8 +568,7 @@ namespace top {
for(auto& it : m_tagSFuncertTool) {
ToolHandle<ICPJetUncertaintiesTool>& tool = it.second;
const std::string& fullName=it.first;
const std::string& fullName=it.first;
const SG::AuxElement::Accessor< char > accRange("passedRangeCheck_" + fullName);
const std::string sfNameNominal = sfNames.at(fullName);
const SG::AuxElement::Accessor< float > accSF(sfNameNominal);
......@@ -599,15 +613,24 @@ namespace top {
m_nominalSystematicSet.hash())), "Failed to retrieve Jets");
}
///-- Loop over the systematics --///
///-- 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()) {
///-- Grab systematic name, check if systematic is JMR-type --///
bool isJMR = false;
CP::SystematicSet::iterator itr = (*syst).second.begin();
std::string systname = itr->name();
if (systname.find("JMR") != std::string::npos) isJMR = true;
///-- 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 (!isJMR) top::check(tool->applySystematicVariation((*syst).second),"Failed to applySystematicVariation");
else top::check(m_FFJetSmearingTool->applySystematicVariation((*syst).second),"Failed to applySystematicVariation");
if (isLargeR && m_config->isMC()) {
// for boosted tagging SFs, apply syst variation for all initialized WPs
......@@ -625,7 +648,9 @@ namespace top {
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
&& jet->pt() > 175e3 //lower than 200e3 to allow studying on migration
&& jet->pt() < 3000e3
&& jet->m() < 600e3);
std::string jetCalibrationNameLargeR = m_config->sgKeyLargeRJets();
if (jetCalibrationNameLargeR.find("TrackCaloCluster") != std::string::npos) { //TCC jet
calibratable_jet = (jet->m() / jet->pt() <= 1.
......@@ -635,24 +660,30 @@ namespace top {
&& jet->pt() < 3000e3);
}
if (!calibratable_jet) continue;
///-- Apply large-R jet tagging SF uncertainties --///
for (std::pair<const std::string, ToolHandle<ICPJetUncertaintiesTool> >& tagSF : m_tagSFuncertTool) {
std::string fullName=tagSF.first;
std::replace(std::begin(fullName),std::end(fullName),':','_');
const SG::AuxElement::Accessor< char > acc("passedRangeCheck_" + fullName);
if(acc.isAvailable(*jet) && acc(*jet)) {
top::check(tagSF.second->applyCorrection(*jet), "Failed to applyCorrection");
}
}
}
///-- Apply Corrrection --///
if (!(isLargeR && !m_config->isMC())) { //Large-R jet uncertainties don't apply to Data
top::check(tool->applyCorrection(*jet), "Failed to applyCorrection");
if (!isJMR) top::check(tool->applyCorrection(*jet), "Failed to applyCorrection");
else top::check(m_FFJetSmearingTool->applyCorrection(*jet), "Failed to applyCorrection");
}
///-- Update JVT --///
if (!isLargeR) jet->auxdecor<float>("AnalysisTop_JVT") = m_jetUpdateJvtTool->updateJvt(*jet);
......@@ -775,19 +806,21 @@ namespace top {
void JetObjectCollectionMaker::addSystematics(const std::set<std::string>& specifiedSystematics,
const CP::SystematicSet& recommendedSysts,
std::unordered_map<CP::SystematicSet, CP::SystematicSet>& map,
const std::string& modName, bool isLargeR, bool onlyJER) {
const std::string& modName, bool isLargeR, bool onlyJER, std::string modNameJMR) {
///-- 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) {
CP::SystematicSet::const_iterator ss = s.begin();
if(!m_config->getTreeFilter()->filterTree(modName + ss->name())) continue; // Applying tree filter
std::string nameMod = modName; ///
if (ss->name().find("JMR") != std::string::npos) nameMod = modNameJMR;
if(!m_config->getTreeFilter()->filterTree(nameMod + ss->name())) continue; // Applying tree filter
if (onlyJER && ss->name().find("JER") == std::string::npos) continue;
CP::SystematicSet modSet(modName + ss->name());
CP::SystematicSet modSet(nameMod + ss->name());
m_recommendedSystematics.push_back(modSet);
if (!m_config->isSystNominal(m_config->systematics())) {
......
......@@ -42,6 +42,7 @@
// CP Tool include(s):
#include "JetCalibTools/IJetCalibrationTool.h"
#include "JetCPInterfaces/ICPJetUncertaintiesTool.h"
#include "JetCPInterfaces/ICPJetCorrectionTool.h"
#include "JetInterface/IJetUpdateJvt.h"
#include "TopJetSubstructure/TopJetSubstructure.h"
......@@ -93,7 +94,7 @@ namespace top {
const CP::SystematicSet& recommendedSysts, std::unordered_map<CP::SystematicSet,
CP::SystematicSet>& map,
const std::string& modName, bool isLargeR = false,
bool onlyJER = false);
bool onlyJER = false, std::string modNameJMR = "SimpleJMR_");
StatusCode execute(const bool isLargeR, bool executeNominal);
......@@ -104,6 +105,7 @@ namespace top {
virtual StatusCode applyTaggingSFSystematic();
StatusCode printout(const bool isLargeR);
private:
......@@ -134,7 +136,7 @@ namespace top {
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;
ToolHandle<ICPJetCorrectionTool> m_FFJetSmearingTool;
// do decorate the large-R jets with the boosted-tagging flags
// and decorate jets with TAccept object containing detailed tag result informaiton
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment