ATLAS Offline Software
CheckConfig.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2018 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 // contact: jmaurer@cern.ch
6 
10 #include <boost/container/flat_set.hpp>
11 template<typename Key> using flat_set = boost::container::flat_set<Key>;
12 
13 #include <cctype>
14 
17 
18 
20  asg::AsgMessaging(&parent), m_parent(parent)
21 {
22  msg().setLevel(parent.msg().level());
23 }
24 
25 
26 template<class CPTool>
27 ToolHandle<CPTool>* CheckConfig::findToolByName(ToolHandleArray<CPTool>& suppliedTools, const std::string& name)
28 {
29  for(auto& tool : suppliedTools)
30  {
31  if(tool.name()==name || tool->name()==name) // athena: not always the same
32  {
33  return &tool;
34  }
35  }
36  return nullptr;
37 }
38 
40 {
41  bool success = true;
42 
44  {
45  ATH_MSG_ERROR("The numbers of electron tools supplied via the 'ElectronEfficiencyTools' and 'ElectronScaleFactorTools' properties should be identical");
46  return false;
47  }
48 
50  {
51  ATH_MSG_ERROR("The numbers of photon tools supplied via the 'PhotonEfficiencyTools' and 'PhotonScaleFactorTools' properties should be identical");
52  return false;
53  }
54 
56  for(auto& kv : m_parent.m_legsPerTool)
57  {
58  auto& name = kv.first;
64  ) continue;
65  success = false;
67  {
68  ATH_MSG_ERROR("Muon tool " << name << " mentioned in property 'ListOfLegsPerTool', which is only aimed at electron and photon tools");
69  }
70  else
71  {
72  std::string known_tools = "; the known tools are";
73  for(auto& tool : m_parent.m_suppliedElectronEfficiencyTools) known_tools += " " + tool.name();
74  for(auto& tool : m_parent.m_suppliedElectronScaleFactorTools) known_tools += " " + tool.name();
75  for(auto& tool : m_parent.m_suppliedPhotonEfficiencyTools) known_tools += " " + tool.name();
76  for(auto& tool : m_parent.m_suppliedPhotonScaleFactorTools) known_tools += " " + tool.name();
77  ATH_MSG_ERROR("Unknown tool " << name << " mentioned in property 'ListOfLegsPerTool'" << known_tools);
78  }
79  }
80  if(!success) return false;
81 
83  auto toolsHaveLegInfo = [this](auto& effTools, auto& sfTools, const char* type)
84  {
85  if(effTools.size() < 2) return true;
86  bool success = true;
87  for(int i=0;i<2;++i)
88  {
89  for(auto& tool : (i? effTools: sfTools))
90  {
91  const std::string& name = tool.name();
93  {
94  ATH_MSG_ERROR(type << " tool " << name << " associated trigger legs are not indicated in 'ListOfLegsPerTool', "
95  "doing so is mandatory when several tools are used");
96  success = false;
97  }
98  }
99  }
100  return success;
101  };
104  if(!success) return false;
105 
109 
111  {
113  || m_parent.m_legsPerTag.size() || m_parent.m_tagsPerTool.size())
114  {
115  ATH_MSG_ERROR("the property 'LeptonTagDecorations' must be filled when any of 'ListOfTagsPerTool'"
116  " / 'ListOfLegsPerTag' / 'MuonLegsPerTag' / 'ElectronLegsPerTag' is.");
117  return false;
118  }
119  return true;
120  }
121 
123  unsigned nElectronToolsWithTags = 0, nMuonToolsWithTags = 0, nPhotonToolsWithTags = 0;
124  for(auto& kv : m_parent.m_tagsPerTool)
125  {
126  auto& name = kv.first;
128  || findToolByName(m_parent.m_suppliedElectronScaleFactorTools, name)) ++nElectronToolsWithTags;
129  else if(findToolByName(m_parent.m_suppliedMuonTools, name)) ++nMuonToolsWithTags;
131  || findToolByName(m_parent.m_suppliedPhotonScaleFactorTools, name)) ++nPhotonToolsWithTags;
132  else
133  {
134  success = false;
135  std::string all_tools = "; the known tools are";
136  for(auto& tool : m_parent.m_suppliedElectronEfficiencyTools) all_tools += " " + tool.name();
137  for(auto& tool : m_parent.m_suppliedElectronScaleFactorTools) all_tools += " " + tool.name();
138  for(auto& tool : m_parent.m_suppliedPhotonEfficiencyTools) all_tools += " " + tool.name();
139  for(auto& tool : m_parent.m_suppliedPhotonScaleFactorTools) all_tools += " " + tool.name();
140  ATH_MSG_ERROR("Unknown tool " << name << " mentioned in property 'ListOfTagsPerTool'");
141  }
142  }
144  if(nMuonToolsWithTags && (nMuonToolsWithTags != m_parent.m_suppliedMuonTools.size()))
145  {
146  ATH_MSG_ERROR("Not all muon tools have been associated with tags in the 'ListOfTagsPerTool' property");
147  success = false;
148  }
151  if(nElectronToolsWithTags && (nElectronToolsWithTags!=nSupplied))
152  {
153  ATH_MSG_ERROR("Not all electron tools have been associated with tags in the 'ListOfTagsPerTool' property");
154  success = false;
155  }
156  if(!success) return false;
159  if(nPhotonToolsWithTags && (nPhotonToolsWithTags!=nSupplied))
160  {
161  ATH_MSG_ERROR("Not all photon tools have been associated with tags in the 'ListOfTagsPerTool' property");
162  success = false;
163  }
164  if(!success) return false;
165 
166  /*
167  * More checks that are done in other places (or still need to be implemented!):
168  *
169  * - [advancedConfigChecks()] for each entry in ListOfLegsPerTag there must be a suitable tool for that tag and leg(s)
170  * - [enumerateTools()] no two electron/photon tools share the same {leg,tag} combination
171  * - [enumerateTools()] no two muon tools share the same tag
172  * - [advancedConfigChecks()] electron efficiency and scale factors have identical configurations: for each eff. tool leg/tag we must find a SF tool, and the other leg/tag pairs associated to those tools must be identical.
173  * - [UNCHECKED] if tags are used with electron (resp. muon, photon) tools, then all electron (muon, photon) tools must have an entry in ListOfTagsPerTool. Done partially in this function, but the case where no tools are tagged (yet tags are used, according to ListOfLegsPerTag or LeptonTagDecorations) escapes detection.
174  * - [loadTagsConfiguration()] each entry of ListOfLegsPerTag can be matched to a suitable tool
175  * - [UNCHECKED] suffixed tag read from a lepton must correspond to a know tag
176  * - [enumerateTools()] list of legs associated to each tool contains only known legs
177  * - [UNCHECKED TrigGlobEffCorrImportData import* functions] various consistency checks of the configuration files
178  * - [advancedConfigChecks()] user-specified periods are orthogonal
179  * - [ImportData::parseTriggerString()] no duplicated triggers in the combination
180  * - [UNCHECKED] for each configured electron/photon tool there is at least one associated tag^leg pair in 'ListOfLegsPerTag' (unless no electron/photon tags used)
181  * - [UNCHECKED] for each configured muon tool there is at least one associated tag in 'MuonLegsPerTag' (unless empty)
182  * - [enumerateTools()] electron tools can't be associated to photon legs; and reciprocally
183  */
184 
185  return success;
186 }
187 
189 {
192  bool success = true;
193 
195 
198  auto checkConsistency = [this](auto& effToolIndex, auto& sfToolIndex, const char* type)
199  {
200  bool mismatch = (effToolIndex.size() != sfToolIndex.size());
201  if(!mismatch)
202  {
203  for(auto& kv : sfToolIndex)
204  {
205  auto itr = effToolIndex.find(kv.first);
206  if(itr != effToolIndex.end())
207  {
208  std::size_t index1 = kv.second, index2 = itr->second;
209  flat_set<ToolKey> pairs1, pairs2;
210  for(auto& kv : sfToolIndex) if(kv.second==index1) pairs1.insert(kv.first);
211  for(auto& kv : effToolIndex) if(kv.second==index2) pairs2.insert(kv.first);
212  if(pairs1 != pairs2) mismatch = true;
213  }
214  else mismatch = true;
215  }
216  }
217  if(mismatch)
218  {
219  ATH_MSG_ERROR("There must be a one-to-one correspondence between the " << type << " efficiency and scale factor tools "
220  "(including their associated trigger legs and selection tags)");
221  return false;
222  }
223  return true;
224  };
225  if(!checkConsistency(m_parent.m_electronEffToolIndex, m_parent.m_electronSfToolIndex, "electron")) return false;
226  if(!checkConsistency(m_parent.m_photonEffToolIndex, m_parent.m_photonSfToolIndex, "photon")) return false;
227 
229  for(auto& kv : m_parent.m_legsPerTag)
230  {
231  std::size_t tag = (kv.first!="*")? m_parent.m_hasher(kv.first) : 0;
232  for(std::size_t leg : m_parent.listNonOrderedCSValues(kv.second,success))
233  {
236  {
238  {
239  ATH_MSG_ERROR("No electron tool provided for the combination of trigger leg '" << m_parent.m_dictionary[leg]
240  << "' and selection tag '" << kv.first << "' mentioned in the property 'ListOfLegsPerTag'");
241  success = false;
242  }
243  }
244  else if(type == xAOD::Type::Muon)
245  {
246  if(m_parent.m_muonToolIndex.find(ToolKey(0, tag)) == m_parent.m_muonToolIndex.end())
247  {
248  ATH_MSG_ERROR("No muon tool provided for the combination of trigger leg '" << m_parent.m_dictionary[leg]
249  << "' and selection tag '" << kv.first << "' mentioned in the property 'ListOfLegsPerTag'");
250  success = false;
251  }
252  }
253  else if(type == xAOD::Type::Photon)
254  {
256  {
257  ATH_MSG_ERROR("No photon tool provided for the combination of trigger leg '" << m_parent.m_dictionary[leg]
258  << "' and selection tag '" << kv.first << "' mentioned in the property 'ListOfLegsPerTag'");
259  success = false;
260  }
261  }
262  else
263  {
264  ATH_MSG_ERROR("Unable to determine which lepton flavour is associated to the trigger leg '" << m_parent.m_dictionary[leg] << "' in the property 'ListOfLegsPerTag'");
265  success = false;
266  }
267  }
268  }
269  if(!success) return false;
270 
272  auto periods = m_parent.m_calculator->m_periods;
273  const auto periods_end = periods.end();
274  for(auto itr1=periods.begin(); itr1!=periods_end; ++itr1)
275  {
276  auto& x = itr1->m_boundaries;
277  if(x.second < x.first)
278  {
279  ATH_MSG_ERROR("One of the periods specified in TriggerCombination has runMin (" << x.first << ") > runMax (" << x.second << ")");
280  success = false;
281  }
282  for(auto itr2=itr1+1; itr2!=periods_end; ++itr2)
283  {
284  auto& y = itr2->m_boundaries;
285  if((x.first>=y.first && x.first<=y.second) || (x.second>=y.first && x.second<=y.second))
286  {
287  ATH_MSG_ERROR("The periods specified in TriggerCombination overlap");
288  success = false;
289  }
290  }
291  }
292  if(!success) return false;
293 
294  return success;
295 }
CheckConfig.h
xAOD::Electron
Electron_v1 Electron
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Electron.h:17
TrigGlobalEfficiencyCorrectionTool::listNonOrderedCSValues
flat_set< std::size_t > listNonOrderedCSValues(const std::string &s, bool &success)
Calculator.h
ImportData
TrigGlobEffCorr::ImportData ImportData
Definition: CheckConfig.cxx:16
TrigGlobalEfficiencyCorrectionTool::m_legsPerTool
std::map< std::string, std::string > m_legsPerTool
Definition: TrigGlobalEfficiencyCorrectionTool.h:114
TrigGlobalEfficiencyCorrectionTool::m_suppliedPhotonEfficiencyTools
ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > m_suppliedPhotonEfficiencyTools
Definition: TrigGlobalEfficiencyCorrectionTool.h:111
TrigGlobalEfficiencyCorrectionTool::m_muonLegsPerTag
std::map< std::string, std::string > m_muonLegsPerTag
deprecated
Definition: TrigGlobalEfficiencyCorrectionTool.h:120
TrigGlobEffCorr::CheckConfig::basicConfigChecks
bool basicConfigChecks()
Definition: CheckConfig.cxx:39
TrigGlobEffCorr::CheckConfig::findToolByName
static ToolHandle< CPTool > * findToolByName(ToolHandleArray< CPTool > &suppliedTools, const std::string &name)
Definition: CheckConfig.cxx:27
asg
Definition: DataHandleTestTool.h:28
TrigGlobalEfficiencyCorrectionTool::m_suppliedElectronScaleFactorTools
ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > m_suppliedElectronScaleFactorTools
Definition: TrigGlobalEfficiencyCorrectionTool.h:110
TrigGlobalEfficiencyCorrectionTool::m_calculator
std::unique_ptr< TrigGlobEffCorr::Calculator > m_calculator
Definition: TrigGlobalEfficiencyCorrectionTool.h:152
TrigGlobalEfficiencyCorrectionTool::m_legsPerTag
std::map< std::string, std::string > m_legsPerTag
deprecated
Definition: TrigGlobalEfficiencyCorrectionTool.h:121
TrigGlobalEfficiencyCorrectionTool::ToolKey
Definition: TrigGlobalEfficiencyCorrectionTool.h:97
x
#define x
TrigGlobEffCorr::CheckConfig::m_parent
TrigGlobalEfficiencyCorrectionTool & m_parent
Definition: CheckConfig.h:28
TrigGlobalEfficiencyCorrectionTool::m_leptonTagDecorations
std::string m_leptonTagDecorations
Definition: TrigGlobalEfficiencyCorrectionTool.h:117
flat_set
boost::container::flat_set< Key > flat_set
Definition: CheckConfig.cxx:11
ImportData.h
TrigGlobalEfficiencyCorrectionTool::m_electronLegsPerTag
std::map< std::string, std::string > m_electronLegsPerTag
Definition: TrigGlobalEfficiencyCorrectionTool.h:119
TrigGlobalEfficiencyCorrectionTool::m_muonToolIndex
std::map< ToolKey, std::size_t > m_muonToolIndex
Definition: TrigGlobalEfficiencyCorrectionTool.h:134
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Trk::index1
@ index1
Definition: BoundarySurfaceFace.h:48
lumiFormat.i
int i
Definition: lumiFormat.py:85
TrigGlobEffCorr::ImportData::associatedLeptonFlavour
xAOD::Type::ObjectType associatedLeptonFlavour(std::size_t leg, bool &success)
Definition: ImportData.cxx:526
TrigGlobEffCorr::ImportData
Definition: ImportData.h:88
TrigGlobalEfficiencyCorrectionTool::m_photonEffToolIndex
std::map< ToolKey, std::size_t > m_photonEffToolIndex
Definition: TrigGlobalEfficiencyCorrectionTool.h:133
asg::AsgMessaging::msg
MsgStream & msg() const
The standard message stream.
Definition: AsgMessaging.cxx:49
test_pyathena.parent
parent
Definition: test_pyathena.py:15
TrigGlobEffCorr::CheckConfig
Definition: CheckConfig.h:20
compute_lumi.leg
leg
Definition: compute_lumi.py:95
TrigGlobalEfficiencyCorrectionTool::m_suppliedPhotonScaleFactorTools
ToolHandleArray< IAsgPhotonEfficiencyCorrectionTool > m_suppliedPhotonScaleFactorTools
Definition: TrigGlobalEfficiencyCorrectionTool.h:112
TrigGlobEffCorr::CheckConfig::CheckConfig
CheckConfig(TrigGlobalEfficiencyCorrectionTool &parent)
Definition: CheckConfig.cxx:19
TrigGlobalEfficiencyCorrectionTool::m_tagsPerTool
std::map< std::string, std::string > m_tagsPerTool
Definition: TrigGlobalEfficiencyCorrectionTool.h:118
Trk::index2
@ index2
Definition: BoundarySurfaceFace.h:49
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:221
AtlCoolConsole.tool
tool
Definition: AtlCoolConsole.py:453
TrigGlobalEfficiencyCorrectionTool
Definition: TrigGlobalEfficiencyCorrectionTool.h:39
TrigGlobEffCorr::CheckConfig::advancedConfigChecks
bool advancedConfigChecks()
Definition: CheckConfig.cxx:188
xAOD::Photon
Photon_v1 Photon
Definition of the current "egamma version".
Definition: Event/xAOD/xAODEgamma/xAODEgamma/Photon.h:17
Muon
struct TBPatternUnitContext Muon
TrigGlobalEfficiencyCorrectionTool::m_photonSfToolIndex
std::map< ToolKey, std::size_t > m_photonSfToolIndex
Definition: TrigGlobalEfficiencyCorrectionTool.h:132
y
#define y
TrigGlobalEfficiencyCorrectionTool::m_suppliedMuonTools
ToolHandleArray< CP::IMuonTriggerScaleFactors > m_suppliedMuonTools
Definition: TrigGlobalEfficiencyCorrectionTool.h:113
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
ITrigGlobalEfficiencyCorrectionTool::toolnameForDefaultScaleFactor
static std::string toolnameForDefaultScaleFactor()
To be used with the ListOfLegsPerTool property:
Definition: ITrigGlobalEfficiencyCorrectionTool.h:56
TrigGlobalEfficiencyCorrectionTool::m_electronEffToolIndex
std::map< ToolKey, std::size_t > m_electronEffToolIndex
Definition: TrigGlobalEfficiencyCorrectionTool.h:131
TrigGlobalEfficiencyCorrectionTool::m_suppliedElectronEfficiencyTools
ToolHandleArray< IAsgElectronEfficiencyCorrectionTool > m_suppliedElectronEfficiencyTools
Properties:
Definition: TrigGlobalEfficiencyCorrectionTool.h:109
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
CheckConfig
TrigGlobEffCorr::CheckConfig CheckConfig
Definition: CheckConfig.cxx:15
TrigGlobalEfficiencyCorrectionTool::m_electronSfToolIndex
std::map< ToolKey, std::size_t > m_electronSfToolIndex
Definition: TrigGlobalEfficiencyCorrectionTool.h:130
TrigGlobalEfficiencyCorrectionTool::m_dictionary
std::map< std::size_t, std::string > m_dictionary
Definition: TrigGlobalEfficiencyCorrectionTool.h:139
TrigGlobalEfficiencyCorrectionTool::m_hasher
std::hash< std::string > m_hasher
Definition: TrigGlobalEfficiencyCorrectionTool.h:127