ATLAS Offline Software
TopBoostedTaggingCPTools.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3  */
4 
6 
7 #include <map>
8 #include <string>
9 #include <algorithm>
10 #include <iterator>
11 
12 // Top includes
15 #include "TopEvent/EventTools.h"
16 
17 // JetUncertaintiesTool for the tagger SFs
19 
20 // Boosted tagging includes
23 
24 namespace top {
26  asg::AsgTool(name) {
27  declareProperty("config", m_config);
28  }
29 
31  ATH_MSG_INFO("top::BoostedTaggingCPTools initialize...");
32 
33  if (m_config->isTruthDxAOD()) {
34  ATH_MSG_INFO("top::BoostedTaggingCPTools: no need to initialise anything on truth DxAOD");
35  return StatusCode::SUCCESS;
36  }
37 
38  if (!m_config->useLargeRJets()) {
39  ATH_MSG_INFO("top::BoostedTaggingCPTools: no need to initialise anything since not using large-R jets");
40  return StatusCode::SUCCESS;
41  }
42 
43 
44  const std::vector<std::pair<std::string, std::string> >& boostedJetTaggers = m_config->boostedJetTaggers();
45  if (boostedJetTaggers.size() == 0) {
46  ATH_MSG_INFO("top::BoostedTaggingCPTools: boostedJetTagging not set. No need to initialise anything.");
47  return StatusCode::SUCCESS;
48  }
49 
51  initSFsMaps();
52 
54  "Error in BoostedTaggingCPTools: boosted jet taggers are not available for this large-R jet collection.");
55 
56  for (const std::pair<std::string, std::string>& name : boostedJetTaggers) {
57  const std::string& taggerType = name.first;
58  const std::string& taggerName = name.second;
59 
61  ("Error in BoostedTaggingCPTools: Unknown tagger in the config file: " + taggerName).c_str());
62 
63  top::check(std::find(m_taggersTypes.begin(), m_taggersTypes.end(), taggerType) != m_taggersTypes.end(),
64  "Error in BoostedTaggingCPTools: Unknown TAGGER_TYPE.");
65  if (taggerType == "JSSWTopTaggerDNN")
66  top::check(ASG_MAKE_ANA_TOOL(m_taggers[taggerName], JSSWTopTaggerDNN), "Failed to make " + taggerName);
67  else if (taggerType == "SmoothedWZTagger")
68  top::check(ASG_MAKE_ANA_TOOL(m_taggers[taggerName], SmoothedWZTagger), "Failed to make " + taggerName);
69 
70  m_taggers[taggerName].setName(taggerName);
71  top::check(m_taggers[taggerName].setProperty("ConfigFile", m_taggersConfigs[taggerName]),
72  "Failed to set ConfigFile for " + taggerName);
73  top::check(m_taggers[taggerName].setProperty("ContainerName", m_config->sgKeyLargeRJets()),
74  "Failed to set ContainerName " + taggerName);
75  top::check(m_taggers[taggerName].setProperty("CalibArea", m_taggersCalibAreas[taggerType]),
76  "Failed to set CalibArea for " + taggerName);
77  // not all BJT taggers implement IsMC property -- only those that have calibration SFs
78  // so we have to check here that we try to set this property only where applicable
79  if (taggerType == "JSSWTopTaggerDNN" || taggerType == "SmoothedWZTagger") {
80  top::check(m_taggers[taggerName].setProperty("IsMC", m_config->isMC()),
81  "Failed to set IsMC for " + taggerName);
82  }
83  top::check(m_taggers[taggerName].initialize(), "Failed to initialize " + taggerName);
84 
85  // initialize SF uncertainty tools for supported WPs
86  if (m_config->isMC()) {
87  std::string jet_def = m_config->sgKeyLargeRJets();
88  jet_def.erase(jet_def.length() - 4); // jet collection name sans 'Jets' suffix
89 
90  std::string mc_type = "MC20";
91 
92  // If we are in Run 3, we should use MC21 instead...
93  if (m_config->isRun3()) mc_type = "MC21";
94 
95  const std::string name = "JetSFuncert_" + taggerName;
96  try {
97  const std::string& cfg = m_taggerSFsConfigs.at(taggerName);
99 
100  top::check(jet_SF_tmp->setProperty("JetDefinition", jet_def), "Failed to set JetDefinition for " + name);
101  top::check(jet_SF_tmp->setProperty("MCType", mc_type), "Failed to set MCType for " + name);
102  top::check(jet_SF_tmp->setProperty("ConfigFile", cfg), "Failed to set ConfigFile for " + name);
103  top::check(jet_SF_tmp->setProperty("IsData", false), "Failed to set IsData for " + name);
104  top::check(jet_SF_tmp->initialize(), "Failed to initialize " + name);
105  m_tagSFuncertTool[taggerName] = jet_SF_tmp;
106  m_config->setCalibBoostedJetTagger(taggerName, m_taggerSFsNames[taggerName]);
107  } catch (std::out_of_range& e) {
108  // skip taggers which do not yet have SFs available
109  ATH_MSG_WARNING("Boosted jet tagger " + taggerName + " is not yet calibrated! No SFs are available.");
110  }
111  }
112  }
113 
114  return StatusCode::SUCCESS;
115  }
116 
118 
119  // Calib areas
120  m_taggersCalibAreas["JSSWTopTaggerANN"] = "JSSWTopTaggerANN/Rel21/March2023/";
121  m_taggersCalibAreas["JSSWTopTaggerDNN"] = "JSSWTopTaggerDNN/Rel21/February2022/";
122  m_taggersCalibAreas["SmoothedWZTagger"] = "SmoothedWZTaggers/Rel21/February2022/";
123 
124  // Supported tagger types
125  // (ANN tagger is not yet ported to R22)
126  m_taggersTypes = {
127  // "JSSWTopTaggerANN",
128  "JSSWTopTaggerDNN",
129  "SmoothedWZTagger",
130  };
131 
132  // Supported jet collections
133  m_jetCollections = {
134  "AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets",
135  };
136 
137 
138  auto setConfig = [this](const std::string& tagger, const std::string& configName) {
139  m_taggersConfigs[tagger] = configName;
140  };
141 
142  if (m_config->sgKeyLargeRJets() == "AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets") {
143  // https://twiki.cern.ch/twiki/bin/view/AtlasProtected/BoostedJetTaggingRecommendationFullRun2#UFO_jets
144 
145  // Top taggers
146  setConfig("DNNTaggerTopQuarkContained50", "DNNTagger_AntiKt10UFOSD_TopContained50_Oct30.dat");
147  setConfig("DNNTaggerTopQuarkContained80", "DNNTagger_AntiKt10UFOSD_TopContained80_Oct30.dat");
148  setConfig("DNNTaggerTopQuarkInclusive50", "DNNTagger_AntiKt10UFOSD_TopInclusive50_Oct30.dat");
149  setConfig("DNNTaggerTopQuarkInclusive80", "DNNTagger_AntiKt10UFOSD_TopInclusive80_Oct30.dat");
150 
151  // WZ taggers
152  // (ANN tagger is not yet ported to R22)
153  // setConfig("ANNTaggerWZContained50", "JSSANN50Tagger_AntiKt10UFOCSSKSoftDrop_Mar23pol3.dat");
154  // setConfig("ANNTaggerWZContained60", "JSSANN60Tagger_AntiKt10UFOCSSKSoftDrop_Mar23pol3.dat");
155  // setConfig("ANNTaggerWZContained70", "JSSANN70Tagger_AntiKt10UFOCSSKSoftDrop_Mar23pol3.dat");
156  // setConfig("ANNTaggerWZContained80", "JSSANN80Tagger_AntiKt10UFOCSSKSoftDrop_Mar23pol3.dat");
157  // setConfig("ANNTaggerWZContained90", "JSSANN90Tagger_AntiKt10UFOCSSKSoftDrop_Mar23pol3.dat");
158 
159  setConfig("SmoothWContained50", "SmoothedContainedWTagger_AntiKt10UFOCSSKSoftDrop_FixedSignalEfficiency50_20220221.dat");
160  setConfig("SmoothWContained80", "SmoothedContainedWTagger_AntiKt10UFOCSSKSoftDrop_FixedSignalEfficiency80_20220221.dat");
161  setConfig("SmoothZContained50", "SmoothedContainedZTagger_AntiKt10UFOCSSKSoftDrop_FixedSignalEfficiency50_20220221.dat");
162  setConfig("SmoothZContained80", "SmoothedContainedZTagger_AntiKt10UFOCSSKSoftDrop_FixedSignalEfficiency80_20220221.dat");
163 
164  // (DNN tagger is not yet ported to R22)
165  // setConfig("DNNTaggerWContained50", "JSSDNN50Tagger_AntiKt10UFOCSSKSoftDrop_Jan22.dat");
166  // setConfig("DNNTaggerWContained80", "JSSDNN80Tagger_AntiKt10UFOCSSKSoftDrop_Jan22.dat");
167  }
168  }
169 
171  // Here we initialize SFs maps
172 
173  // This lambda function is universal for all taggers
174  // (Commented out until SFs are available to suppress compilation warning)
175  // auto setMaps = [this](const std::string& configPath, const std::string& tagger, const std::string& configName) {
176  // m_taggerSFsConfigs[tagger] = configPath + "/" + configName;
177  // m_taggerSFsNames[tagger] = tagger + "_SF";
178  // };
179 
180  if (m_config->sgKeyLargeRJets() == "AntiKt10UFOCSSKSoftDropBeta100Zcut10Jets") {
181  ATH_MSG_WARNING("No Large-R jet tagging scale factors available yet!");
182 
183  // Leaving old R21 LCTopo-configs here for now to have some idea on how to apply the settings later on
184  // const std::string configPath="rel21/Fall2020";
185  // //Top taggers
186  // setMaps(configPath,"DNNTaggerTopQuarkContained50","R10_SF_LCTopo_TopTagContained_SigEff50.config");
187  // setMaps(configPath,"DNNTaggerTopQuarkContained80","R10_SF_LCTopo_TopTagContained_SigEff80.config");
188  // setMaps(configPath,"DNNTaggerTopQuarkInclusive50","R10_SF_LCTopo_TopTagInclusive_SigEff50.config");
189  // setMaps(configPath,"DNNTaggerTopQuarkInclusive80","R10_SF_LCTopo_TopTagInclusive_SigEff80.config");
190  // //WZ taggers
191  // setMaps(configPath,"SmoothWContained50","R10_SF_LCTopo_WTag_SigEff50.config");
192  // setMaps(configPath,"SmoothWContained80","R10_SF_LCTopo_WTag_SigEff80.config");
193  }
194  }
195 
196 } // namespace top
JetUncertaintiesTool::initialize
virtual StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: JetUncertaintiesTool.cxx:236
top
TopConfig A simple configuration that is NOT a singleton.
Definition: AnalysisTrackingHelper.cxx:58
ATH_MSG_INFO
#define ATH_MSG_INFO(x)
Definition: AthMsgStreamMacros.h:31
find
std::string find(const std::string &s)
return a remapped string
Definition: hcg.cxx:135
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
top::BoostedTaggingCPTools::m_taggersCalibAreas
std::unordered_map< std::string, std::string > m_taggersCalibAreas
Definition: TopBoostedTaggingCPTools.h:36
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
asg
Definition: DataHandleTestTool.h:28
top::BoostedTaggingCPTools::m_jetCollections
std::vector< std::string > m_jetCollections
Definition: TopBoostedTaggingCPTools.h:33
top::BoostedTaggingCPTools::m_taggersTypes
std::vector< std::string > m_taggersTypes
Definition: TopBoostedTaggingCPTools.h:34
JSSWTopTaggerDNN
Definition: JSSWTopTaggerDNN.h:14
top::BoostedTaggingCPTools::m_config
std::shared_ptr< top::TopConfig > m_config
Definition: TopBoostedTaggingCPTools.h:31
ASG_MAKE_ANA_TOOL
#define ASG_MAKE_ANA_TOOL(handle, type)
create the tool in the given tool handle
Definition: AnaToolHandle.h:690
top::BoostedTaggingCPTools::m_taggerSFsConfigs
std::unordered_map< std::string, std::string > m_taggerSFsConfigs
Definition: TopBoostedTaggingCPTools.h:37
top::BoostedTaggingCPTools::m_taggerSFsNames
std::unordered_map< std::string, std::string > m_taggerSFsNames
Definition: TopBoostedTaggingCPTools.h:38
EventTools.h
A few functions for doing operations on particles / events. Currently holds code for dR,...
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
top::BoostedTaggingCPTools::m_taggers
std::unordered_map< std::string, asg::AnaToolHandle< IJetDecorator > > m_taggers
Definition: TopBoostedTaggingCPTools.h:43
top::BoostedTaggingCPTools::initialize
StatusCode initialize()
Dummy implementation of the initialisation function.
Definition: TopBoostedTaggingCPTools.cxx:30
JetUncertaintiesTool
Definition: JetUncertaintiesTool.h:44
top::BoostedTaggingCPTools::m_tagSFuncertTool
std::unordered_map< std::string, ToolHandle< ICPJetUncertaintiesTool > > m_tagSFuncertTool
Definition: TopBoostedTaggingCPTools.h:44
JSSWTopTaggerDNN.h
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
SmoothedWZTagger
Definition: SmoothedWZTagger.h:11
top::BoostedTaggingCPTools::initTaggersMaps
void initTaggersMaps()
Definition: TopBoostedTaggingCPTools.cxx:117
top::check
void check(bool thingToCheck, const std::string &usefulFailureMessage)
Print an error message and terminate if thingToCheck is false.
Definition: EventTools.cxx:15
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
WriteCaloSwCorrections.cfg
cfg
Definition: WriteCaloSwCorrections.py:23
TopConfig.h
SmoothedWZTagger.h
DiTauMassTools::MaxHistStrategyV2::e
e
Definition: PhysicsAnalysis/TauID/DiTauMassTools/DiTauMassTools/HelperFunctions.h:26
top::BoostedTaggingCPTools::initSFsMaps
void initSFsMaps()
Definition: TopBoostedTaggingCPTools.cxx:170
TopBoostedTaggingCPTools.h
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
top::BoostedTaggingCPTools::m_taggersConfigs
std::unordered_map< std::string, std::string > m_taggersConfigs
Definition: TopBoostedTaggingCPTools.h:35
Tokenize.h
JetUncertaintiesTool.h
top::BoostedTaggingCPTools::BoostedTaggingCPTools
BoostedTaggingCPTools(const std::string &name)
Definition: TopBoostedTaggingCPTools.cxx:25