ATLAS Offline Software
JetTagCalibCondData.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
6 
7 #include "TObject.h"
8 #include "TH1.h"
9 #include "TTree.h"
10 
17 namespace Analysis {
18 
20  AthMessaging("JetTagCalibCondData") {
21  ATH_MSG_DEBUG("#BTAG# addChannelAlias : map size" << m_channelAliasesMap.size());
22  m_channelAliasesMap.clear();
23 }
24 
26  m_histos.clear();
27  m_bdts.clear();
28 }
29 
30 void JetTagCalibCondData::resize(const std::vector<std::string>& taggers) {
31  m_histos.resize(taggers.size());
32  for(const std::string& t : taggers) {
33  m_taggers.push_back(t);
34  }
35 }
36 
38  m_channelAliasesMap.clear();
39 }
40 
41 void JetTagCalibCondData::addHisto(const unsigned int indexTagger, const std::string& name, std::unique_ptr<TH1> obj) {
42  m_histos[indexTagger].insert(std::make_pair(name, std::move(obj)));
43  ATH_MSG_DEBUG("#BTAG# histo added " << name << " with pointer " << obj.get()
44  << ", m_histos size " << m_histos.size());
45 }
46 
47 void JetTagCalibCondData::addBdt(const std::string&tagger, const std::string& channel, std::unique_ptr<MVAUtils::BDT> bdt) {
48  m_bdts[tagger].insert(std::make_pair(channel, std::move(bdt)));
49  ATH_MSG_DEBUG("#BTAG# Adding BDT of " << tagger << " in cond data for channel " << channel
50  << ", m_bdts size " << m_bdts.size());
51 }
52 
53 void JetTagCalibCondData::addIPRNN(const std::string& tagger, const std::string& channel, const std::string& calstring) {
54  ATH_MSG_DEBUG("#BTAG# Adding RNN of " << tagger << " in cond data for channel " << channel);
55  m_IP_RNNConfig[tagger].insert(std::make_pair(channel, calstring));
56 }
57 
58 void JetTagCalibCondData::addInputVars(const std::string&tagger, const std::string& name, const std::vector<std::string> &input) {
59 
60  m_inputVars[tagger].insert(std::make_pair(name, input));
61  ATH_MSG_DEBUG("#BTAG# Adding input variables of the BDT for " << tagger << " in cond data for " << name
62  << ", m_inputVars size " << m_inputVars.size());
63 }
64 
65 void JetTagCalibCondData::addDL1NN(const std::string&tagger, const std::string& channel, const lwt::JSONConfig& obj) {
66  m_DL1_NNConfig[tagger].insert(std::make_pair(channel, obj));
67  ATH_MSG_DEBUG("#BTAG# JSONConfig in cond data with " << obj.layers.size() << " layers"
68  << " for tagger " << tagger << " and channel " << channel
69  << ", m_DL1_NNConfig size " << m_DL1_NNConfig.size());
70 }
71 
72 void JetTagCalibCondData::addChannelAlias(const std::string& channel, const std::string& alias) {
73  ATH_MSG_DEBUG("#BTAG# addChannelAlias : " << channel << " : " << alias);
74  std::pair<std::string,std::string> chan = std::make_pair(channel,alias);
75  m_channelAliasesMap.insert(chan);
76 }
77 
78 std::string JetTagCalibCondData::getChannelAlias(const std::string& originalChannel) const {
79  std::string alias = originalChannel;
80  std::map< std::string, std::string>::const_iterator pos;
81  pos = m_channelAliasesMap.find(originalChannel);
82  if (pos != m_channelAliasesMap.end()) alias = pos->second;
83  return alias;
84 }
85 
87  msg() << MSG::DEBUG << "#BTAG# final registered aliases ";
88  std::map<std::string,std::string>::const_iterator iter = m_channelAliasesMap.begin();
89  for(;iter!=m_channelAliasesMap.end();++iter) {
90  msg() << MSG::DEBUG << "#BTAG# Channel alias " << iter->first <<"->"<<iter->second;
91  }
92  msg() << endmsg;
93 }
94 
96  msg() << MSG::DEBUG << "#BTAG# histograms retrieved from DB" << endmsg;
97  for( const auto& hists : m_histos ) {
98  for( const auto& [name, hist] : hists) {
99  msg() << MSG::DEBUG << "#BTAG# histogram name: "<< name << " with pointer " << hist.get() << endmsg;
100  }
101  }
102 }
103 
105  msg() << MSG::DEBUG << "#BTAG# There are " << m_bdts.size() << " BDTs build with TTree retrieved from DB" << endmsg;
106  for( auto const &tagger : m_bdts) {
107  msg() << MSG::DEBUG << "#BTAG# BDT for Tagger " << tagger.first << endmsg;
108  for( auto const &channel : tagger.second) {
109  msg() << MSG::DEBUG << "#BTAG# Channel "<< channel.first << " has many trees " << channel.second->GetNTrees() << endmsg;
110  }
111  }
112 }
113 
114 TH1* JetTagCalibCondData::retrieveHistogram(const std::string& folder, const std::string& channel, const std::string& hname) const {
115  return this->retrieveTObject<TH1>(folder,channel,hname);
116 }
117 
118 MVAUtils::BDT* JetTagCalibCondData::retrieveBdt(const std::string& tagger, const std::string& channel) const {
119  MVAUtils::BDT* bdt(nullptr);
120  std::string channelAlias = this->getChannelAlias(channel);
121 
122  ATH_MSG_DEBUG("#BTAG# retrieving BDT for " << tagger
123  << " (channel " << channel << " -> " << channelAlias << ")");
124 
125  auto mI = m_bdts.find(tagger);
126  if (mI != m_bdts.end()) {
127  ATH_MSG_DEBUG("#BTAG# " << tagger << " BDT config found");
128  auto mJ = mI->second.find(channelAlias);
129  if (mJ != mI->second.end()) {
130  ATH_MSG_DEBUG("#BTAG# "<< tagger << " BDT config found for jet collection " << channel);
131  bdt = mJ->second.get();
132  }
133  else {
134  ATH_MSG_DEBUG("#BTAG# "<< tagger << " BDT config not found for jet collection " << channel);
135  }
136  }
137  else {
138  ATH_MSG_DEBUG("#BTAG# " << tagger << " BDT config not found");
139  }
140 
141  return bdt;
142 }
143 
144 std::vector<std::string> JetTagCalibCondData::retrieveInputVars(const std::string& tagger, const std::string& channel, const std::string& hname) const {
145  std::vector<std::string> inputVars;
146  std::string channelAlias = this->getChannelAlias(channel);
147  std::string fname = this->fullHistoName(channelAlias,hname);
148 
149  ATH_MSG_DEBUG("#BTAG# retrieving input variables of BDT for " << tagger <<
150  " channel " << channel << " and hname " << fname);
151  std::map< std::string , std::map<std::string, std::vector<std::string>>>::const_iterator mI;
152  mI = m_inputVars.find(tagger);
153  if (mI != m_inputVars.end()) {
154  ATH_MSG_DEBUG("#BTAG# " << tagger << " BDT config found");
155  std::map<std::string, std::vector<std::string>>::const_iterator mJ = mI->second.find(fname);
156  if (mJ != mI->second.end()) {
157  ATH_MSG_DEBUG("#BTAG# "<< tagger << " BDT config found for jet collection " << channel);
158  inputVars = mJ->second;
159  }
160  else {
161  ATH_MSG_DEBUG("#BTAG# "<< tagger << " BDT config not found for jet collection " << channel);
162  }
163  }
164  else {
165  ATH_MSG_DEBUG("#BTAG# " << tagger << " BDT config not found");
166  }
167 
168  return inputVars;
169 }
170 
171 lwt::JSONConfig JetTagCalibCondData::retrieveDL1NN(const std::string& tagger, const std::string& channel) const {
172  lwt::JSONConfig config;
173  std::map< std::string , std::map<std::string, lwt::JSONConfig>>::const_iterator mI;
174  mI = m_DL1_NNConfig.find(tagger);
175  if (mI != m_DL1_NNConfig.end()) {
176  ATH_MSG_DEBUG("#BTAG# " << tagger << " NN config found");
177  std::map<std::string, lwt::JSONConfig>::const_iterator mJ = mI->second.find(channel);
178  if (mJ != mI->second.end()) {
179  ATH_MSG_DEBUG("#BTAG# "<< tagger << " NN config found for jet collection " << channel);
180  config = mJ->second;
181  }
182  else {
183  ATH_MSG_DEBUG("#BTAG# "<< tagger << " NN config not found for jet collection " << channel);
184  }
185  }
186  else {
187  ATH_MSG_DEBUG("#BTAG# " << tagger << " NN config not found");
188  }
189 
190  return config;
191 }
192 
193 std::string JetTagCalibCondData::retrieveIPRNN(const std::string& tagger, const std::string& channel) const {
194  std::string config;
195  std::map< std::string , std::map<std::string, std::string>>::const_iterator mI;
196  mI = m_IP_RNNConfig.find(tagger);
197  if (mI != m_IP_RNNConfig.end()) {
198  ATH_MSG_DEBUG("#BTAG# " << tagger << "RNN config found");
199  std::map<std::string, std::string>::const_iterator mJ = mI->second.find(channel);
200  if (mJ != mI->second.end()) {
201  ATH_MSG_DEBUG("#BTAG# "<< tagger << " RNN config found for jet collection " << channel);
202  config = mJ->second;
203  }
204  else {
205  ATH_MSG_DEBUG("#BTAG# "<< tagger << " RNN config not found for jet collection " << channel);
206  }
207  }
208  else {
209  ATH_MSG_DEBUG("#BTAG# " << tagger << " RNN config not found");
210  }
211 
212  return config;
213 }
214 
215 std::string JetTagCalibCondData::channelName(const std::string& fname) const {
216  const std::string delim("#");
217  std::string::size_type sPos;
218  sPos = fname.find_first_of(delim);
219  std::string channel = fname.substr(0,sPos);
220  return channel;
221 }
222 
223 std::string JetTagCalibCondData::histoName(const std::string& fname) const {
224  const std::string delim("#");
225  std::string::size_type sPos;
226  sPos = fname.find_first_of(delim);
227  std::string hname = fname.substr(sPos+1);
228  return hname;
229 }
230 
231 std::string JetTagCalibCondData::fullHistoName(const std::string& channel, const std::string& histoName) const {
232  std::string fname = channel + "#" + histoName;
233  return fname;
234 }
235 
236 }
237 
238 
239 
240 
Analysis::JetTagCalibCondData::printBdtsStatus
void printBdtsStatus() const
Definition: JetTagCalibCondData.cxx:104
Analysis::JetTagCalibCondData::m_histos
std::vector< std::map< std::string, std::unique_ptr< TH1 > > > m_histos
Definition: JetTagCalibCondData.h:70
Analysis::JetTagCalibCondData::m_channelAliasesMap
std::map< std::string, std::string > m_channelAliasesMap
Definition: JetTagCalibCondData.h:71
Analysis::JetTagCalibCondData::retrieveHistogram
TH1 * retrieveHistogram(const std::string &folder, const std::string &channel, const std::string &hname) const
Definition: JetTagCalibCondData.cxx:114
plotting.yearwise_efficiency.channel
channel
Definition: yearwise_efficiency.py:28
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:272
Analysis::JetTagCalibCondData::printAliasesStatus
void printAliasesStatus() const
Definition: JetTagCalibCondData.cxx:86
JetTagCalibCondData.h
plotmaker.hist
hist
Definition: plotmaker.py:148
Analysis::JetTagCalibCondData::addInputVars
void addInputVars(const std::string &tagger, const std::string &name, const std::vector< std::string > &input)
Definition: JetTagCalibCondData.cxx:58
Analysis::JetTagCalibCondData::JetTagCalibCondData
JetTagCalibCondData()
Definition: JetTagCalibCondData.cxx:19
Analysis::JetTagCalibCondData::getChannelAlias
std::string getChannelAlias(const std::string &originalChannel) const
Definition: JetTagCalibCondData.cxx:78
MVAUtils::BDT
Simplified Boosted Regression Tree, support TMVA, lgbm, and xgboost.
Definition: BDT.h:34
Analysis::JetTagCalibCondData::m_DL1_NNConfig
std::map< std::string, std::map< std::string, lwt::JSONConfig > > m_DL1_NNConfig
Definition: JetTagCalibCondData.h:79
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Analysis::JetTagCalibCondData::addDL1NN
void addDL1NN(const std::string &tagger, const std::string &channel, const lwt::JSONConfig &)
Definition: JetTagCalibCondData.cxx:65
config
Definition: PhysicsAnalysis/AnalysisCommon/AssociationUtils/python/config.py:1
Analysis::JetTagCalibCondData::m_inputVars
std::map< std::string, std::map< std::string, std::vector< std::string > > > m_inputVars
Definition: JetTagCalibCondData.h:77
Analysis::JetTagCalibCondData::resize
void resize(const std::vector< std::string > &sizeHisto)
Resize the data members.
Definition: JetTagCalibCondData.cxx:30
Analysis::JetTagCalibCondData::addIPRNN
void addIPRNN(const std::string &tagger, const std::string &channel, const std::string &)
Definition: JetTagCalibCondData.cxx:53
Analysis::JetTagCalibCondData::histoName
std::string histoName(const std::string &fullHistoName) const
Definition: JetTagCalibCondData.cxx:223
ReadCellNoiseFromCool.chan
chan
Definition: ReadCellNoiseFromCool.py:52
endmsg
#define endmsg
Definition: AnalysisConfig_Ntuple.cxx:63
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
Analysis::JetTagCalibCondData::~JetTagCalibCondData
~JetTagCalibCondData()
Definition: JetTagCalibCondData.cxx:25
COOLRates.alias
alias
Definition: COOLRates.py:1172
PlotPulseshapeFromCool.input
input
Definition: PlotPulseshapeFromCool.py:106
AthMessaging
Class to provide easy MsgStream access and capabilities.
Definition: AthMessaging.h:55
Analysis::JetTagCalibCondData::m_IP_RNNConfig
std::map< std::string, std::map< std::string, std::string > > m_IP_RNNConfig
Definition: JetTagCalibCondData.h:81
MakeTH3DFromTH2Ds.hists
hists
Definition: MakeTH3DFromTH2Ds.py:72
AthMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AthMessaging.h:164
Analysis::JetTagCalibCondData::retrieveDL1NN
lwt::JSONConfig retrieveDL1NN(const std::string &tagger, const std::string &channel) const
Definition: JetTagCalibCondData.cxx:171
Analysis::JetTagCalibCondData::addBdt
void addBdt(const std::string &tagger, const std::string &name, std::unique_ptr< MVAUtils::BDT >)
Definition: JetTagCalibCondData.cxx:47
Analysis
The namespace of all packages in PhysicsAnalysis/JetTagging.
Definition: BTaggingCnvAlg.h:20
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:18
Analysis::JetTagCalibCondData::retrieveBdt
MVAUtils::BDT * retrieveBdt(const std::string &tagger, const std::string &channel) const
Definition: JetTagCalibCondData.cxx:118
python.AthDsoLogger.fname
string fname
Definition: AthDsoLogger.py:67
Analysis::JetTagCalibCondData::m_bdts
std::map< std::string, std::map< std::string, std::unique_ptr< MVAUtils::BDT > > > m_bdts
Definition: JetTagCalibCondData.h:75
Analysis::JetTagCalibCondData::channelName
std::string channelName(const std::string &fullHistoName) const
Definition: JetTagCalibCondData.cxx:215
TH1
Definition: rootspy.cxx:268
DEBUG
#define DEBUG
Definition: page_access.h:11
config
std::vector< std::string > config
Definition: fbtTestBasics.cxx:72
Analysis::JetTagCalibCondData::m_taggers
std::vector< std::string > m_taggers
Definition: JetTagCalibCondData.h:72
CaloCondBlobAlgs_fillNoiseFromASCII.folder
folder
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:56
python.PyAthena.obj
obj
Definition: PyAthena.py:135
Analysis::JetTagCalibCondData::fullHistoName
std::string fullHistoName(const std::string &channel, const std::string &histoName) const
Definition: JetTagCalibCondData.cxx:231
Analysis::JetTagCalibCondData::retrieveInputVars
std::vector< std::string > retrieveInputVars(const std::string &tagger, const std::string &channel, const std::string &hname) const
Definition: JetTagCalibCondData.cxx:144
Analysis::JetTagCalibCondData::printHistosStatus
void printHistosStatus() const
Definition: JetTagCalibCondData.cxx:95
Analysis::JetTagCalibCondData::retrieveIPRNN
std::string retrieveIPRNN(const std::string &tagger, const std::string &channel) const
Definition: JetTagCalibCondData.cxx:193
Analysis::JetTagCalibCondData::addHisto
void addHisto(const unsigned int indexTagger, const std::string &name, std::unique_ptr< TH1 >)
Definition: JetTagCalibCondData.cxx:41
Analysis::JetTagCalibCondData::clear
void clear()
Definition: JetTagCalibCondData.cxx:37
Analysis::JetTagCalibCondData::addChannelAlias
void addChannelAlias(const std::string &channel, const std::string &alias)
Definition: JetTagCalibCondData.cxx:72