ATLAS Offline Software
Loading...
Searching...
No Matches
ConfigHelper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
4
5
8#include <stdexcept>
9
10#include "TEnv.h"
11
12namespace jet
13{
14
16// //
17// ComponentHelper constructor //
18// //
20
22 : energyScale(0)
23 , name(name)
24{ }
25
26ComponentHelper::ComponentHelper(TEnv& settings, const TString& compPrefix, const TString& MCtype, const float energyScaleVal)
27 : energyScale(energyScaleVal),
28 // Read in information on the uncertainty component
29 // - Name: component name
30 // - Param: parametrization
31 // - MassDef: mass definition (default, calo, TA, comb)
32 // - Scale: the variable to scale (fourvec, pt, D12, etc), default fourvec
33 // - Interp: If false, uses fixed bin content insted of interpolation
34 // - Special: Whether this component requires special treatment, "false" if not specified
35 // - Hists: histogram name(s), comma/space-separated list (if not specified, uses name)
36 // - VHist: validity histogram name (optional)
37 // - SubComp: sub-components for simple groups
38 // - Group: the number of the group this component belongs to (0 == single-component group)
39 // Overwrite MCTYPE with the specified type if applicable
40 name (TString(settings.GetValue(compPrefix+"Name","")).ReplaceAll("MCTYPE",MCtype)),
41 param (settings.GetValue(compPrefix+"Param","")),
42 massDefStr (settings.GetValue(compPrefix+"MassDef","")),
43 scale (settings.GetValue(compPrefix+"Scale","FourVec")),
44 topologyStr (settings.GetValue(compPrefix+"Topology","")),
45 interpolStr (settings.GetValue(compPrefix+"Interp","true")),
46 special (settings.GetValue(compPrefix+"Special","")),
47 uncNameList (TString(settings.GetValue(compPrefix+"Hists","")).ReplaceAll("MCTYPE",MCtype)),
48 validName (TString(settings.GetValue(compPrefix+"VHist","")).ReplaceAll("MCTYPE",MCtype)),
49 subCompList (TString(settings.GetValue(compPrefix+"SubComp","")).ReplaceAll("MCTYPE",MCtype)),
50 splitNum (settings.GetValue(compPrefix+"Split",0)),
51 groupNum (settings.GetValue(compPrefix+"Group",0)),
52 combMassStr (settings.GetValue(compPrefix+"CombMassType","")),
53 caloMassTerm(settings.GetValue(compPrefix+"CaloMassTerm","")),
54 TAMassTerm (settings.GetValue(compPrefix+"TAMassTerm","")),
55 caloMassDef (settings.GetValue(compPrefix+"CaloMassDef","")),
56 TAMassDef (settings.GetValue(compPrefix+"TAMassDef","")),
57 truthLabelStr (settings.GetValue(compPrefix+"TruthLabels","")),
58 constrainZresponseStr (settings.GetValue(compPrefix+"ConstrainZresponse","")),
59 constrainZresponseFunc (settings.GetValue(compPrefix+"ConstrainZresponseFunc","")),
60 LargeRJetTruthLabelName (settings.GetValue(compPrefix+"LargeRJetTruthLabelName","R10TruthLabel_R21Consolidated")),
61 LargeRJetTruthLabelsForSFstr (settings.GetValue(compPrefix+"LargeRJetTruthLabelForSF","")),
62 RegionForSFstr (settings.GetValue(compPrefix+"RegionForSF","")),
63 ResultName (settings.GetValue(compPrefix+"ResultName","")),
64
65 // Get enums where appropriate
66 // Leave interpreting/checking the enums to others
68 massDef (CompMassDef::stringToEnum(massDefStr)),
69 scaleVar (CompScaleVar::stringToEnum(scale)),
70 topology (JetTopology::stringToEnum(topologyStr)),
71 isSpecial ((!special.CompareTo("true",TString::kIgnoreCase)) || (!special.CompareTo("yes",TString::kIgnoreCase))),
72 pileupType (PileupComp::stringToEnum(name)),
73 flavourType (FlavourComp::stringToEnum(name)),
74 combMassType (CombMassComp::stringToEnum(combMassStr)),
75 interpolate (Interpolate::stringToEnum(interpolStr)),
76 uncNames (utils::vectorize<TString>(uncNameList,", ")),
77 subComps (utils::vectorize<TString>(subCompList,", ")),
78 truthLabels (utils::vectorize<int>(truthLabelStr,", ")),
79 constrainZresponse ((!constrainZresponseStr.CompareTo("true",TString::kIgnoreCase)) || (!constrainZresponseStr.CompareTo("yes",TString::kIgnoreCase)))
80{
81 TString LargeRJetTruthLabelStrOld (settings.GetValue(compPrefix+"FatjetTruthLabels",""));
82 TString LargeRJetTruthLabelStrNew = settings.GetValue(compPrefix+"LargeRJetTruthLabels","");
83 if (LargeRJetTruthLabelStrOld != "" && LargeRJetTruthLabelStrNew != "")
84 throw std::runtime_error("ERROR: double-specification of the LargeRJetTruthLabels/FatjetTruthLabels property");
85 else if (LargeRJetTruthLabelStrNew != "")
86 LargeRJetTruthLabelStr = LargeRJetTruthLabelStrNew;
87 else
88 LargeRJetTruthLabelStr = LargeRJetTruthLabelStrOld;
89
91 for (const TString& aVal : LargeRJetTruthLabelStrs)
92 {
94 {
95 // Note: throwing an exception here because we can't return StatusCode::FAILURE or similar and this doesn't inherit from a class with such functionality
96 // This error message should anyways only occur if the CP group provides a bad config file, so this error will only be printed when we are debugging our inputs and before it gets to users
97 throw std::runtime_error(Form("ERROR: Unable to convert specified LargeRJetTruthLabel to a recognized enum value, please check the configuration file for mistakes: %s",aVal.Data()));
98 }
99 else
101 }
103 for (const TString& aVal : LargeRJetTruthLabelsForSFstrs)
104 {
106 {
107 throw std::runtime_error(Form("ERROR: Unable to convert specified LargeRJetTruthLabelForSF to a recognized enum value, please check the configuration file for mistakes: %s",aVal.Data()));
108 }
109 else
111 }
113}
114
115
117// //
118// GroupHelper constructor //
119// //
121
123 : name(name)
124{ }
125
126GroupHelper::GroupHelper(TEnv& settings, const TString& groupPrefix, const TString& MCtype) :
127 // Read in information on the uncertainty group
128 // - Name: group name
129 // - Desc: description
130 // - Type: category
131 // - Corr: correlation type (only need to specify if >1 histogram)
132 // - Split: Number of sub-components to split this component into (default 1, no split)
133 // - Reduce: Whether or not a given group is safe for eigenvector reduction
134 // - Group: The group number to link relevant components to this information
135 // - SubGroup: subgroup number(s), comma/space-separated list (if not specified, no subgroup)
136 // Overwrite MCTYPE with the specified type if applicable
137 name (TString(settings.GetValue(groupPrefix+"Name","")).ReplaceAll("MCTYPE",MCtype)),
138 desc (settings.GetValue(groupPrefix+"Desc","")),
139 cat (settings.GetValue(groupPrefix+"Type","")),
140 corr (settings.GetValue(groupPrefix+"Corr","")),
141 isRed (settings.GetValue(groupPrefix+"Reducible","true")),
142 groupNum (settings.GetValue(groupPrefix+"Group",0)),
143 subgroupNum (settings.GetValue(groupPrefix+"SubGroup",0)),
144
145 // Get enums where appropriate
146 // Leave interpreting/checking the enums to others
147 category (CompCategory::stringToEnum(cat)),
148 correlation (CompCorrelation::stringToEnum(corr)),
149 reducible (utils::getTypeObjFromString<bool>(isRed))
150{
151}
152
153
155// //
156// ConfigHelper constructor and methods //
157// //
159
161 : asg::AsgMessaging("")
162 , m_isInit(false)
163 , m_confPrefix("")
164 , m_MCtype("")
165 , m_energyScale(0)
166 , m_cInfo(nullptr)
167 , m_gInfo(nullptr)
168{
170}
171
172ConfigHelper::ConfigHelper(const TString& confPrefix, const TString& MCtype, const float energyScaleVal)
173 : asg::AsgMessaging(confPrefix.Data())
174 , m_isInit(false)
175 , m_confPrefix(confPrefix)
176 , m_MCtype(MCtype)
177 , m_energyScale(energyScaleVal)
178 , m_cInfo(nullptr)
179 , m_gInfo(nullptr)
180{ }
181
187
188StatusCode ConfigHelper::initialize(TEnv& settings)
189{
190 if (m_isInit)
191 {
192 ATH_MSG_ERROR("Blocking double-initialization: " << m_confPrefix.Data());
193 return StatusCode::FAILURE;
194 }
195
197 if (!m_cInfo)
198 {
199 ATH_MSG_ERROR("Failed to create ComponentHelper: " << m_confPrefix.Data());
200 return StatusCode::FAILURE;
201 }
202
203 m_gInfo = new GroupHelper(settings, m_confPrefix, m_MCtype);
204 if (!m_gInfo)
205 {
206 ATH_MSG_ERROR("Failed to create GroupHelper: " << m_confPrefix.Data());
207 return StatusCode::FAILURE;
208 }
209
210 m_isInit = true;
211 return StatusCode::SUCCESS;
212}
213
215{
216 if (!m_isInit)
217 {
218 ATH_MSG_ERROR("ConfigHelper has not yet been initialized: " << m_confPrefix.Data());
219 return false;
220 }
221
222 // Simple group possibilities:
223 // Single-component with all group info specified on the component, "Group" == 0 (or unspec)
224 // Multi-component "SubComp" with all group info specified on the component, "Group" == 0
225 // So the defining factor of simple groups is "Group" == 0 (== unspecified)
226 // It also has to have a name to ensure it's not just empty (it will be if this is a group)
227 if (m_cInfo->groupNum == 0 && m_cInfo->name != "")
228 return true;
229 return false;
230}
231
233{
234 if (!m_isInit)
235 {
236 ATH_MSG_ERROR("ConfigHelper has not yet been initialized: " << m_confPrefix.Data());
237 return false;
238 }
239
240 // Component means that it has a component name and that the group is specified
241 if (m_cInfo->groupNum != 0 && m_cInfo->name != "")
242 return true;
243 return false;
244}
245
247{
248 if (!m_isInit)
249 {
250 ATH_MSG_ERROR("ConfigHelper has not yet been initialized: " << m_confPrefix.Data());
251 return false;
252 }
253
254 // Group means that it has a group name and the group is specified
255 if (m_gInfo->groupNum != 0 && m_gInfo->name != "")
256 return true;
257 return false;
258}
259
261{
262 if (!m_isInit)
263 {
264 ATH_MSG_ERROR("ConfigHelper has not yet been initialized: " << m_confPrefix.Data());
265 return nullptr;
266 }
267 return m_cInfo;
268}
269
271{
272 if (!m_isInit)
273 {
274 ATH_MSG_ERROR("ConfigHelper has not yet been initialized: " << m_confPrefix.Data());
275 return nullptr;
276 }
277 return m_gInfo;
278}
279
280void ConfigHelper::enforceGroupNamePrefix(const std::string& prefix)
281{
282 enforceGroupNamePrefix(TString(prefix.c_str()));
283}
284
285void ConfigHelper::enforceGroupNamePrefix(const TString& prefix)
286{
287 // Special config file string must exactly match this to activate the condition
288 const TString NOPREFIX = "NOPREFIX_";
289
290 // Check for a special NOPREFIX string
291 // This is to support parameters from other groups we have propagated into our uncertainties
292 // NPs can now have the same name, so tools will coherently scale different properties for the same uncertainty name
293 if (m_gInfo->name.BeginsWith(NOPREFIX))
294 m_gInfo->name = m_gInfo->name.ReplaceAll(NOPREFIX,"");
295
296 // Doesn't have the prefix
297 else if (!m_gInfo->name.BeginsWith(prefix,TString::kIgnoreCase))
298 m_gInfo->name = Form("%s%s",prefix.Data(),m_gInfo->name.Data());
299 // Has the right prefix, but not the right case (enforce identical prefix)
300 else if (!m_gInfo->name.BeginsWith(prefix))
301 m_gInfo->name.Replace(0,prefix.Length(),prefix);
302}
303
304void ConfigHelper::setComponentJetDefSuffix(const std::string& suffix)
305{
306 setComponentJetDefSuffix(TString(suffix.c_str()));
307}
308
309void ConfigHelper::setComponentJetDefSuffix(const TString& suffix)
310{
311 if (m_cInfo->uncNames.empty() && m_cInfo->subComps.empty())
312 m_cInfo->uncNames.push_back(m_cInfo->name+"_"+suffix);
313 else if (!m_cInfo->uncNames.empty())
314 for (size_t iName = 0; iName < m_cInfo->uncNames.size(); ++iName)
315 m_cInfo->uncNames[iName] = m_cInfo->uncNames[iName] + "_" + suffix;
316 else if (!m_cInfo->subComps.empty())
317 for (size_t iSubComp = 0; iSubComp < m_cInfo->subComps.size(); ++iSubComp)
318 m_cInfo->subComps[iSubComp] = m_cInfo->subComps[iSubComp] + "_" + suffix;
319
320 if (m_cInfo->validName != "")
321 m_cInfo->validName = m_cInfo->validName+"_"+suffix;
322}
323
324void ConfigHelper::addValidityHistogram(const std::string& histName)
325{
326 addValidityHistogram(TString(histName.c_str()));
327}
328
329void ConfigHelper::addValidityHistogram(const TString& histName)
330{
331 if (histName != "")
332 {
333 if (m_cInfo->validName != "")
334 {
335 ATH_MSG_WARNING(Form("Ignoring request to add validity histogram to: %s",m_cInfo->name.Data()));
336 ATH_MSG_WARNING(Form("The following validity histogram was already specified: %s",m_cInfo->validName.Data()));
337 ATH_MSG_WARNING(Form("Blocking overwrite with a new validity histogram: %s",histName.Data()));
338 }
339 else
340 m_cInfo->validName = histName;
341 }
342}
343
344
345} // end jet namespace
346
#define ATH_MSG_ERROR(x)
#define ATH_MSG_WARNING(x)
@ Data
Definition BaseObject.h:11
AsgMessaging(const std::string &name)
Constructor with a name.
PileupComp::TypeEnum pileupType
std::vector< TString > LargeRJetTruthLabelStrs
const float energyScale
CompTaggerRegionVar::TypeEnum RegionForSF
std::vector< int > truthLabels
CompScaleVar::TypeEnum scaleVar
CompMassDef::TypeEnum massDef
TString constrainZresponseFunc
std::vector< CompFlavorLabelVar::TypeEnum > LargeRJetTruthLabelsForSF
JetTopology::TypeEnum topology
std::vector< TString > uncNames
std::vector< LargeRJetTruthLabel::TypeEnum > LargeRJetTruthLabels
FlavourComp::TypeEnum flavourType
ComponentHelper(const TString &name="")
CompParametrization::TypeEnum parametrization
CombMassComp::TypeEnum combMassType
TString constrainZresponseStr
std::vector< TString > subComps
TString LargeRJetTruthLabelStr
TString LargeRJetTruthLabelName
std::vector< TString > LargeRJetTruthLabelsForSFstrs
Interpolate::TypeEnum interpolate
TString LargeRJetTruthLabelsForSFstr
ComponentHelper * m_cInfo
const TString m_confPrefix
bool isGroup() const
bool isComponent() const
GroupHelper * m_gInfo
const ComponentHelper * getComponentInfo() const
void addValidityHistogram(const std::string &histName)
virtual StatusCode initialize(TEnv &settings)
const TString m_MCtype
void enforceGroupNamePrefix(const std::string &prefix)
bool isCompGroup() const
void setComponentJetDefSuffix(const std::string &suffix)
const GroupHelper * getGroupInfo() const
const float m_energyScale
GroupHelper(const TString &name="")
CompCorrelation::TypeEnum correlation
CompCategory::TypeEnum category
TypeEnum stringToEnum(const TString &name)
TypeEnum stringToEnum(const TString &type)
TypeEnum stringToEnum(const TString &type)
bool vectorize(const TString &str, const TString &sep, std::vector< T > &result)