ATLAS Offline Software
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 
12 namespace jet
13 {
14 
16 // //
17 // ComponentHelper constructor //
18 // //
20 
22  : energyScale(0)
23  , name(name)
24 { }
25 
26 ComponentHelper::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
67  parametrization (CompParametrization::stringToEnum(param)),
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 
90  LargeRJetTruthLabelStrs = utils::vectorize<TString>(LargeRJetTruthLabelStr,",");
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  }
102  LargeRJetTruthLabelsForSFstrs = utils::vectorize<TString>(LargeRJetTruthLabelsForSFstr, ",");
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 
126 GroupHelper::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 
172 ConfigHelper::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 
183 {
186 }
187 
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 
281 {
282  enforceGroupNamePrefix(TString(prefix.c_str()));
283 }
284 
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 
305 {
306  setComponentJetDefSuffix(TString(suffix.c_str()));
307 }
308 
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 != "")
322 }
323 
325 {
326  addValidityHistogram(TString(histName.c_str()));
327 }
328 
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
341  }
342 }
343 
344 
345 } // end jet namespace
346 
jet::GroupHelper::name
TString name
Definition: ConfigHelper.h:91
jet::GroupHelper
Definition: ConfigHelper.h:84
jet::ConfigHelper::setComponentJetDefSuffix
void setComponentJetDefSuffix(const std::string &suffix)
Definition: ConfigHelper.cxx:304
jet::ComponentHelper::groupNum
int groupNum
Definition: ConfigHelper.h:46
hotSpotInTAG.suffix
string suffix
Definition: hotSpotInTAG.py:186
AddEmptyComponent.histName
string histName
Definition: AddEmptyComponent.py:64
jet::ConfigHelper::m_cInfo
ComponentHelper * m_cInfo
Definition: ConfigHelper.h:140
LargeRJetTruthLabel::UNKNOWN
@ UNKNOWN
Definition: LargeRJetLabelEnum.h:15
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Data
@ Data
Definition: BaseObject.h:11
jet::ComponentHelper::LargeRJetTruthLabelsForSF
std::vector< CompFlavorLabelVar::TypeEnum > LargeRJetTruthLabelsForSF
Definition: ConfigHelper.h:79
jet::CompTaggerRegionVar::stringToEnum
TypeEnum stringToEnum(const TString &type)
Definition: UncertaintyEnum.cxx:462
LargeRJetTruthLabel::stringToEnum
TypeEnum stringToEnum(const TString &name)
Definition: LargeRJetLabelEnum.h:81
asg
Definition: DataHandleTestTool.h:28
jet::ComponentHelper
Definition: ConfigHelper.h:24
jet::ConfigHelper::ConfigHelper
ConfigHelper()
Definition: ConfigHelper.cxx:160
jet::ComponentHelper::uncNames
std::vector< TString > uncNames
Definition: ConfigHelper.h:72
jet::ConfigHelper::getGroupInfo
const GroupHelper * getGroupInfo() const
Definition: ConfigHelper.cxx:270
jet::ComponentHelper::LargeRJetTruthLabelStrs
std::vector< TString > LargeRJetTruthLabelStrs
Definition: ConfigHelper.h:76
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
Helpers.h
jet::ConfigHelper::isCompGroup
bool isCompGroup() const
Definition: ConfigHelper.cxx:214
jet::ComponentHelper::ComponentHelper
ComponentHelper(const TString &name="")
Definition: ConfigHelper.cxx:21
jet
Definition: JetCalibTools_PlotJESFactors.cxx:23
jet::ConfigHelper::isGroup
bool isGroup() const
Definition: ConfigHelper.cxx:246
CaloCondBlobAlgs_fillNoiseFromASCII.desc
desc
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:54
JESUNC_SAFE_DELETE
#define JESUNC_SAFE_DELETE(T)
Definition: Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:25
jet::CompFlavorLabelVar::stringToEnum
TypeEnum stringToEnum(const TString &type)
Definition: UncertaintyEnum.cxx:419
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ReweightUtils.category
category
Definition: ReweightUtils.py:15
checkCorrelInHIST.prefix
dictionary prefix
Definition: checkCorrelInHIST.py:391
jet::ComponentHelper::LargeRJetTruthLabels
std::vector< LargeRJetTruthLabel::TypeEnum > LargeRJetTruthLabels
Definition: ConfigHelper.h:77
JCT::utils::getTypeObjFromString
bool getTypeObjFromString(const std::string &str, T &obj)
Definition: PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/Helpers.h:83
jet::ComponentHelper::LargeRJetTruthLabelsForSFstrs
std::vector< TString > LargeRJetTruthLabelsForSFstrs
Definition: ConfigHelper.h:78
jet::ConfigHelper::m_MCtype
const TString m_MCtype
Definition: ConfigHelper.h:136
jet::ComponentHelper::validName
TString validName
Definition: ConfigHelper.h:43
jet::ConfigHelper::enforceGroupNamePrefix
void enforceGroupNamePrefix(const std::string &prefix)
Definition: ConfigHelper.cxx:280
jet::GroupHelper::groupNum
int groupNum
Definition: ConfigHelper.h:96
jet::ComponentHelper::name
TString name
Definition: ConfigHelper.h:34
jet::ConfigHelper::m_confPrefix
const TString m_confPrefix
Definition: ConfigHelper.h:135
jet::ConfigHelper::addValidityHistogram
void addValidityHistogram(const std::string &histName)
Definition: ConfigHelper.cxx:324
jet::ConfigHelper::m_isInit
bool m_isInit
Definition: ConfigHelper.h:132
jet::ComponentHelper::LargeRJetTruthLabelStr
TString LargeRJetTruthLabelStr
Definition: ConfigHelper.h:56
jet::ConfigHelper::m_energyScale
const float m_energyScale
Definition: ConfigHelper.h:137
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:195
jet::ConfigHelper::getComponentInfo
const ComponentHelper * getComponentInfo() const
Definition: ConfigHelper.cxx:260
jet::ConfigHelper::~ConfigHelper
virtual ~ConfigHelper()
Definition: ConfigHelper.cxx:182
jet::ComponentHelper::LargeRJetTruthLabelsForSFstr
TString LargeRJetTruthLabelsForSFstr
Definition: ConfigHelper.h:57
JESUNC_NO_DEFAULT_CONSTRUCTOR
#define JESUNC_NO_DEFAULT_CONSTRUCTOR
Definition: Reconstruction/Jet/JetUncertainties/JetUncertainties/Helpers.h:24
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
jet::ComponentHelper::RegionForSFstr
TString RegionForSFstr
Definition: ConfigHelper.h:58
jet::ConfigHelper::initialize
virtual StatusCode initialize(TEnv &settings)
Definition: ConfigHelper.cxx:188
utils
Definition: Trigger/TrigMonitoring/TrigMinBiasMonitoring/python/utils.py:1
CaloClusterCorr::interpolate
float interpolate(const CaloRec::Array< 2 > &a, float x, unsigned int degree, unsigned int ycol=1, const CaloRec::Array< 1 > &regions=CaloRec::Array< 1 >(), int n_points=-1, bool fixZero=false)
Polynomial interpolation in a table.
Definition: interpolate.cxx:75
jet::ConfigHelper::m_gInfo
GroupHelper * m_gInfo
Definition: ConfigHelper.h:141
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:569
jet::GroupHelper::GroupHelper
GroupHelper(const TString &name="")
Definition: ConfigHelper.cxx:122
jet::CompFlavorLabelVar::UNKNOWN
@ UNKNOWN
Definition: UncertaintyEnum.h:132
jet::ComponentHelper::RegionForSF
CompTaggerRegionVar::TypeEnum RegionForSF
Definition: ConfigHelper.h:80
jet::ConfigHelper::isComponent
bool isComponent() const
Definition: ConfigHelper.cxx:232
xAOD::bool
setBGCode setTAP setLVL2ErrorBits bool
Definition: TrigDecision_v1.cxx:60
LArG4GenerateShowerLib.parametrization
parametrization
Definition: LArG4GenerateShowerLib.py:19
jet::ComponentHelper::subComps
std::vector< TString > subComps
Definition: ConfigHelper.h:73
TRT_PAI_utils::Interpolate
float Interpolate(const float &xval, const std::vector< float > &xtabulated, const std::vector< float > &ytabulated)
Interpolation function.
Definition: TRT_PAI_utils.cxx:14
ConfigHelper.h
JCT::utils::vectorize
bool vectorize(const TString &str, const TString &sep, std::vector< T > &result)
Definition: PhysicsAnalysis/JetMissingEtID/JetSelectorTools/JetSelectorTools/Helpers.h:114