ATLAS Offline Software
BTaggingEigenVectorRecompositionTool.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 
7 
8 
10  asg::AsgTool( name )
11 {
12  declareProperty("BTaggingEfficiencyTool", m_btageffTool);
13 }
14 
16 {
17 
18 }
19 
20 // Initialize BtaggingEfficiencyTool handle and retrieve coefficient map for
21 // all flavours. Also initialize vectors which contains all original sources
22 // uncertainties' names. One vector for each flavour.
24 {
25  ATH_MSG_INFO("Hello BTaggingEigenVectorRecompositionTool user... initializing");
26  ATH_CHECK(m_btageffTool.retrieve());
27 
28  if (m_btageffTool.empty()) {
29  ATH_MSG_ERROR("Failed to retrieve BTaggingEfficiencyTool handle");
30  return StatusCode::FAILURE;
31  }
32  CP::CorrectionCode code1 = m_btageffTool->getEigenRecompositionCoefficientMap("B", m_coefficientMapB);
33  CP::CorrectionCode code2 = m_btageffTool->getEigenRecompositionCoefficientMap("C", m_coefficientMapC);
34  CP::CorrectionCode code3 = m_btageffTool->getEigenRecompositionCoefficientMap("T", m_coefficientMapT);
35  CP::CorrectionCode code4 = m_btageffTool->getEigenRecompositionCoefficientMap("Light", m_coefficientMapLight);
36 
37  if(code1 != CP::CorrectionCode::Ok) {
38  ATH_MSG_ERROR("Failed to retrieve coefficient map of B");
39  return StatusCode::FAILURE;
40  }
41  if(code2 != CP::CorrectionCode::Ok) {
42  ATH_MSG_ERROR("Failed to retrieve coefficient map of C");
43  return StatusCode::FAILURE;
44  }
45  if(code3 != CP::CorrectionCode::Ok) {
46  ATH_MSG_ERROR("Failed to retrieve coefficient map of T");
47  return StatusCode::FAILURE;
48  }
49  if(code4 != CP::CorrectionCode::Ok) {
50  ATH_MSG_ERROR("Failed to retrieve coefficient map of Light");
51  return StatusCode::FAILURE;
52  }
53 
54  std::map<std::string, std::map<std::string, float>>::iterator outter;
55 
56  outter = m_coefficientMapB.begin();
57  for (std::map<std::string, float>::iterator inner=outter->second.begin();
58  inner!=outter->second.end(); ++inner){
59  m_NPnameListB.push_back(inner->first);
60  }
61  outter = m_coefficientMapC.begin();
62  for (std::map<std::string, float>::iterator inner=outter->second.begin();
63  inner!=outter->second.end(); ++inner){
64  m_NPnameListC.push_back(inner->first);
65  }
66  outter = m_coefficientMapT.begin();
67  for (std::map<std::string, float>::iterator inner=outter->second.begin();
68  inner!=outter->second.end(); ++inner){
69  m_NPnameListT.push_back(inner->first);
70  }
71  outter = m_coefficientMapLight.begin();
72  for (std::map<std::string, float>::iterator inner=outter->second.begin();
73  inner!=outter->second.end(); ++inner){
74  m_NPnameListLight.push_back(inner->first);
75  }
76 
77  return StatusCode::SUCCESS;
78 
79 }
80 
81 // Return a vector which contains a list of original vector uncertainties names.
82 // vector list is for the chosen flavour label. The order of the names is the same
83 // as the coefficient values given by getCoefficients()
84 std::vector<std::string> BTaggingEigenVectorRecompositionTool::getListOfOriginalNuisanceParameters(const std::string & label) const
85 {
86  ATH_MSG_INFO("getListOfOriginalNuisanceParameters()");
87 
88  std::vector<std::string> dummy;
89  if(label.compare("B") == 0)
90  return m_NPnameListB;
91  else if(label.compare("C") == 0)
92  return m_NPnameListC;
93  else if(label.compare("T") == 0)
94  return m_NPnameListT;
95  else if(label.compare("Light") == 0)
96  return m_NPnameListLight;
97  else{
98  ATH_MSG_ERROR("Label is illegal! Available label: B, C, T and Light.");
99  return dummy;
100  }
101 
102  return dummy;
103 }
104 
105 // Produce a coefficient map contains only eigenvectors that is showing in
106 // eigenIdxList and return it to user. If given empty evIdxList, the function
107 // returns a full map. Produced map is for the chosen flavour label.
108 std::map<std::string, std::map<std::string, float>> BTaggingEigenVectorRecompositionTool::getCoefficientMap(const std::string & label, const std::vector<unsigned int>& evIdxList) const
109 {
110  ATH_MSG_INFO("getCoefficientMap()");
111 
112  std::map<std::string, std::map<std::string, float>> fullMap;
113  if(label.compare("B") == 0)
114  fullMap = m_coefficientMapB;
115  else if(label.compare("C") == 0)
116  fullMap = m_coefficientMapC;
117  else if(label.compare("T") == 0)
118  fullMap = m_coefficientMapT;
119  else if(label.compare("Light") == 0)
120  fullMap = m_coefficientMapLight;
121  else{
122  ATH_MSG_ERROR("Label is illegal! Available label: B, C, T and Light.");
123  return fullMap;
124  }
125 
126  std::vector<std::string> evNameList;
127  for(unsigned int i : evIdxList){
128  // Note: This eigenvector name convention has to be same with that in CalibrationDataEigenVariations. One way to avoid the naming convention is to change coefficient map structure into: map<unsigned int, map<string, float>>
129  evNameList.push_back("Eigen_"+label+"_"+std::to_string(i));
130  }
131 
132  std::map<std::string, std::map<std::string, float>> resultMap;
133  for (std::map<std::string, std::map<std::string, float>>::iterator iter = fullMap.begin();
134  iter != fullMap.end(); ++iter){
135  if (evNameList.end() != std::find(evNameList.begin(), evNameList.end(), iter->first) ||
136  evNameList.empty())
137  resultMap[iter->first] = iter->second;
138  }
139  return resultMap;
140 }
141 
142 // Returns a vector contains the coefficients value of the chosen label
143 // and the chosen eigenvector. The order of the value is the same as
144 // the order of original uncertainty names given by
145 // getListOfOriginalNuisanceParameters()
146 std::vector<float> BTaggingEigenVectorRecompositionTool::getCoefficients(const std::string & label, const unsigned int evIdx) const
147 {
148  ATH_MSG_INFO("getCoefficients()");
149  std::vector<float> coefficients; // dummy to be replaced
150  std::map<std::string, std::map<std::string, float>> fullMap;
151  std::vector<std::string> NPnameList;
152  if(label.compare("B") == 0){
153  fullMap = m_coefficientMapB;
154  NPnameList = m_NPnameListB;
155  }
156  else if(label.compare("C") == 0){
157  fullMap = m_coefficientMapC;
158  NPnameList = m_NPnameListC;
159  }
160  else if(label.compare("T") == 0){
161  fullMap = m_coefficientMapT;
162  NPnameList = m_NPnameListT;
163  }
164  else if(label.compare("Light") == 0){
165  fullMap = m_coefficientMapLight;
166  NPnameList = m_NPnameListLight;
167  }
168  else{
169  ATH_MSG_ERROR("Label is illegal! Available label: B, C, T and Light.");
170  return coefficients;
171  }
172 
173  std::string evName = "Eigen_"+label+"_"+std::to_string(evIdx);
174  if(fullMap.count(evName) <= 0){
175  ATH_MSG_ERROR("Cannot find " << evName <<" in Eigen Vector coefficient map.");
176  return coefficients;
177  }
178 
179  std::map<std::string, float> oneEVmap = fullMap[evName];
180  for(std::string NPname : NPnameList){
181  coefficients.push_back(oneEVmap[NPname]);
182  }
183  return coefficients;
184 }
185 
186 // Return number of eigenvectors used for the chosen label.
188  std::map<std::string, std::map<std::string, float>> fullMap;
189  if(label.compare("B") == 0)
190  fullMap = m_coefficientMapB;
191  else if(label.compare("C") == 0)
192  fullMap = m_coefficientMapC;
193  else if(label.compare("T") == 0)
194  fullMap = m_coefficientMapT;
195  else if(label.compare("Light") == 0)
196  fullMap = m_coefficientMapLight;
197  else{
198  ATH_MSG_ERROR("Label is illegal! Available label: B, C, T and Light.");
199  return -1;
200  }
201  return fullMap.size();
202 }
203 
204 // this returns a list of eigen vector systematics supported by the btaggingEfficiency tool handle
206  return m_btageffTool->affectingSystematics();
207 }
208 
209 // it indicates which systematic shifts are to be applied for all future calls
210 // no systematics for now, proxy for later
212 {
213  for (auto syst : systConfig) {
214  CP::SystematicSet myset;
215  ATH_MSG_WARNING("applySystematicVariation was called for " << syst.name() << " but BTaggingEigenVectorRecompositionTool does not apply Systematic Variations");
216  //the truth tagging tool provides results for all possible systematic variations in its results objects, the user does not need to call each one seperatly.
217  }
218  return StatusCode::SUCCESS;
219 }
220 
221 // returns true if the argument systematic is supported by the
222 // btaggingEfficiency tool handle
224 {
226  return sys.find(systematic) != sys.end();
227 }
228 
229 // subset of Eigenvector systeamtics that are recommended by the
230 // btaggingEfficiency tool handle
232  return affectingSystematics();
233 }
xAOD::iterator
JetConstituentVector::iterator iterator
Definition: JetConstituentVector.cxx:68
BTaggingEigenVectorRecompositionTool::m_coefficientMapT
std::map< std::string, std::map< std::string, float > > m_coefficientMapT
Definition: BTaggingEigenVectorRecompositionTool.h:114
BTaggingEigenVectorRecompositionTool::recommendedSystematics
CP::SystematicSet recommendedSystematics() const
subset of systematics that are recommended by the btaggingEfficiency tool handle
Definition: BTaggingEigenVectorRecompositionTool.cxx:231
BTaggingEigenVectorRecompositionTool::isAffectedBySystematic
bool isAffectedBySystematic(const CP::SystematicVariation &systematic) const
returns true if the argument systematic is supported by the btaggingEfficiency tool handle
Definition: BTaggingEigenVectorRecompositionTool.cxx:223
BTaggingEigenVectorRecompositionTool.h
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
PlotCalibFromCool.label
label
Definition: PlotCalibFromCool.py:78
BTaggingEigenVectorRecompositionTool::m_NPnameListT
std::vector< std::string > m_NPnameListT
Definition: BTaggingEigenVectorRecompositionTool.h:122
asg
Definition: DataHandleTestTool.h:28
CP::SystematicSet
Class to wrap a set of SystematicVariations.
Definition: SystematicSet.h:31
CP::SystematicVariation
Definition: SystematicVariation.h:47
BTaggingEigenVectorRecompositionTool::m_NPnameListC
std::vector< std::string > m_NPnameListC
Definition: BTaggingEigenVectorRecompositionTool.h:121
BTaggingEigenVectorRecompositionTool::m_coefficientMapC
std::map< std::string, std::map< std::string, float > > m_coefficientMapC
Definition: BTaggingEigenVectorRecompositionTool.h:113
mapkey::sys
@ sys
Definition: TElectronEfficiencyCorrectionTool.cxx:42
BTaggingEigenVectorRecompositionTool::m_coefficientMapB
std::map< std::string, std::map< std::string, float > > m_coefficientMapB
Definition: BTaggingEigenVectorRecompositionTool.h:112
BTaggingEigenVectorRecompositionTool::m_coefficientMapLight
std::map< std::string, std::map< std::string, float > > m_coefficientMapLight
Definition: BTaggingEigenVectorRecompositionTool.h:115
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
BTaggingEigenVectorRecompositionTool::applySystematicVariation
StatusCode applySystematicVariation(const CP::SystematicSet &systConfig)
it indicates which systematic shifts are to be applied for all future calls no systematics for now,...
Definition: BTaggingEigenVectorRecompositionTool.cxx:211
lumiFormat.i
int i
Definition: lumiFormat.py:92
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
BTaggingEigenVectorRecompositionTool::BTaggingEigenVectorRecompositionTool
BTaggingEigenVectorRecompositionTool(const std::string &name)
Create a proper constructor for Athena.
Definition: BTaggingEigenVectorRecompositionTool.cxx:9
BTaggingEigenVectorRecompositionTool::getCoefficientMap
std::map< std::string, std::map< std::string, float > > getCoefficientMap(const std::string &label, const std::vector< unsigned int > &eigenIdxList=std::vector< unsigned int >()) const
Produce a coefficient map contains only eigenvectors that is showing in eigenIdxList and return it to...
Definition: BTaggingEigenVectorRecompositionTool.cxx:108
BTaggingEigenVectorRecompositionTool::m_NPnameListLight
std::vector< std::string > m_NPnameListLight
Definition: BTaggingEigenVectorRecompositionTool.h:123
python.xAODType.dummy
dummy
Definition: xAODType.py:4
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
BTaggingEigenVectorRecompositionTool::affectingSystematics
CP::SystematicSet affectingSystematics() const
the list of all systematics this tool can be affected by
Definition: BTaggingEigenVectorRecompositionTool.cxx:205
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:192
ActsTrk::to_string
std::string to_string(const DetectorType &type)
Definition: GeometryDefs.h:34
BTaggingEigenVectorRecompositionTool::~BTaggingEigenVectorRecompositionTool
virtual ~BTaggingEigenVectorRecompositionTool()
Create a constructor for standalone usage.
Definition: BTaggingEigenVectorRecompositionTool.cxx:15
BTaggingEigenVectorRecompositionTool::getCoefficients
std::vector< float > getCoefficients(const std::string &label, const unsigned int evIdx) const
Returns a vector contains the coefficients value of the chosen label and the chosen eigenvector.
Definition: BTaggingEigenVectorRecompositionTool.cxx:146
CP::CorrectionCode::Ok
@ Ok
The correction was done successfully.
Definition: CorrectionCode.h:38
BTaggingEigenVectorRecompositionTool::m_NPnameListB
std::vector< std::string > m_NPnameListB
Definition: BTaggingEigenVectorRecompositionTool.h:120
BTaggingEigenVectorRecompositionTool::getListOfOriginalNuisanceParameters
std::vector< std::string > getListOfOriginalNuisanceParameters(const std::string &label) const
Return a vector which contains a list of original vector uncertainties names.
Definition: BTaggingEigenVectorRecompositionTool.cxx:84
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
BTaggingEigenVectorRecompositionTool::m_btageffTool
ToolHandle< IBTaggingEfficiencyTool > m_btageffTool
Definition: BTaggingEigenVectorRecompositionTool.h:126
BTaggingEigenVectorRecompositionTool::getNumEigenVectors
int getNumEigenVectors(const std::string &label) const
Definition: BTaggingEigenVectorRecompositionTool.cxx:187
CP::CorrectionCode
Return value from object correction CP tools.
Definition: CorrectionCode.h:31
BTaggingEigenVectorRecompositionTool::initialize
StatusCode initialize()
Initialize BtaggingEfficiencyTool handle and retrieve coefficient map for all flavours.
Definition: BTaggingEigenVectorRecompositionTool.cxx:23