ATLAS Offline Software
Loading...
Searching...
No Matches
OptionHelper.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2020 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef JETUNCERTAINTIES_OPTIONHELPER_H
6#define JETUNCERTAINTIES_OPTIONHELPER_H
7
9#include <vector>
10#include <utility>
11#include <stdexcept>
12#include "TString.h"
16// TODO: enable when available
17// #include "BoostedJetTaggers/TagResultEnum.h"
18
19namespace jet
20{
21
23{
24 public:
25 // Constructor/destructor/initialization
26 OptionHelper(const std::string& name = "OptionHelper");
28 bool Initialize(const std::vector<TString>& options);
29
30 //
31 // Info retrieval
32 //
33
34 // General control
35 bool IsPublicFormat() const { checkInit(); return m_isPublic; }
36 bool IsEtaDepPileup() const { checkInit(); return m_isEtaDepPU; }
37 bool IgnorePT() const { checkInit(); return m_ignorePT; }
38 TString GetNamePrefix() const { checkInit(); return m_compNamePrefix; }
39 TString GetCalibArea() const { checkInit(); return m_calibArea; }
40 TString GetPath() const { checkInit(); return m_path; }
41 bool GetIsData() const { checkInit(); return m_isData; }
42 bool IgnoreNoMatch() const { checkInit(); return m_ignoreNoMatch; }
43
44 // Plot control
45 bool DoATLASLabel() const { checkInit(); return m_doATLASLabel; }
46 TString GetATLASLabel() const { checkInit(); return m_ATLASLabel; }
47 TString GetBunchSpacing() const { checkInit(); return m_bunchSpacing; }
48 bool DrawTotal() const { checkInit(); return m_doTotalUnc; }
49 TString TotalUncName() const { checkInit(); return m_totalUncName; }
50 bool SpecifyTagger() const { checkInit(); return m_specifyTagger; }
51 double AxisMax() const { checkInit(); return m_axisMax < 0 ? (IsLargeR()? 0.2 : 0.1) : m_axisMax; }
52 double AxisMin() const { checkInit(); return m_axisMin; }
53 std::pair<double,double> xAxisRange() const { checkInit(); return m_xAxisRange; }
54 bool AbsValue() const { checkInit(); return m_absVal; }
55 bool LogPt() const { checkInit(); return m_logPt; }
56 TString getMassType() const { checkInit(); return m_massType; }
57 std::pair<double,double> fillShift() const { checkInit(); return m_fillShift; }
58 bool TwoColumnLegend() const { checkInit(); return m_twoColumnLegend; }
59
60 std::vector<double> GetPtBins() const;
61 std::vector<double> GetEtaBins() const;
62 std::vector<double> GetFixedPtVals() const;
63 std::vector<double> GetFixedEtaVals() const;
64 std::vector<double> GetFixedMoverPtVals() const;
65 std::vector<double> GetFixedMassVals() const;
66
67 // Uncertainty types
68 bool IsSmallR() const { checkInit(); return m_isSmallR; }
69 bool IsLargeR() const { checkInit(); return m_isLargeR; }
70 bool IsJER() const { checkInit(); return m_isJER; }
71 bool IsTLA() const { checkInit(); return m_isTLA; }
72
73 // Compositions
74 bool IsSpecialComposition() const { checkInit(); return m_composition != ""; }
75 TString GetCompositionPath() const;
76 TString GetCompositionName() const;
77 int GetNjetFlavour() const { checkInit(); return m_nJetFlavour; }
78 int FixedTruthLabel() const { checkInit(); return m_truthLabel; }
80 TString TruthLabelMoment() const {checkInit(); return m_truthLabelMoment; }
81
82
83 // Tagging SFs
84 TString TagScaleFactorName() const { checkInit(); return m_tagSFname; }
87
88 // Comparison helpers
89 bool CompareOnly() const { checkInit(); return m_onlyCompare; }
90 TString DoCompare() const { checkInit(); return m_doCompare; }
91 std::vector<TString> GetCompareVals() const { checkInit(); return m_compareVals; }
92
93 // Variable control
94 std::vector<CompScaleVar::TypeEnum> GetScaleVars() const { checkInit(); return m_scaleVars; }
95 const std::vector<std::string> VariablesToShift() const { checkInit(); return m_systFilters; }
97
98 // Layout control
99 TString GetInputsDir() const { checkInit(); return m_inputsDir; }
100
101 // Debug/similar control
102 TString GetDumpFile() const { checkInit(); return m_dumpFile; }
103
104 private:
106
111 TString m_calibArea;
112 TString m_path;
115
122 double m_axisMax;
123 double m_axisMin;
124 std::pair<double,double> m_xAxisRange;
127 TString m_massType;
128 std::pair<double,double> m_fillShift;
130
131 TString m_ptBins;
132 TString m_etaBins;
137
142
148 bool m_isDijet; // legacy support
149
150 TString m_tagSFname;
153
155 TString m_doCompare;
156 std::vector<TString> m_compareVals;
157
158 std::vector<CompScaleVar::TypeEnum> m_scaleVars;
159 std::vector<std::string> m_systFilters;
161
162 // allowing MakeUncertaintyPlots to be run from outside
163 // of the testInputs/run/ directory
164 TString m_inputsDir;
165
166 TString m_dumpFile;
167
168 TString getOptionValue(const std::vector<TString>& options, const TString optionName) const;
169 template <typename T>
170 T getOptionValueWithDefault(const std::vector<TString>& options, const TString optionName, const T defaultVal);
171 std::vector<TString> getCompareVals(const std::vector<TString>& options) const;
172
173 void checkInit() const;
174
175 std::vector<double> getBins(const TString& toParse) const;
176};
177
178OptionHelper::OptionHelper(const std::string& name)
179 : asg::AsgMessaging(name)
180 , m_isInit(false)
181
182 , m_isPublic(false)
183 , m_isEtaDepPU(false)
184 , m_ignorePT(false)
185 , m_compNamePrefix("JET_")
186 , m_calibArea("")
187 , m_path("")
188 , m_isData(false)
189 , m_ignoreNoMatch(false)
190
191 , m_doATLASLabel(true)
192 , m_ATLASLabel("Internal")
193 , m_bunchSpacing("")
194 , m_doTotalUnc(true)
195 , m_totalUncName("Total uncertainty")
196 , m_specifyTagger(true)
197 , m_axisMax(-1)
198 , m_axisMin(0)
199 , m_xAxisRange(0,0)
200 , m_absVal(true)
201 , m_logPt(true)
202 , m_massType("")
203 , m_fillShift(0,0)
204 , m_twoColumnLegend(false)
205
206 , m_ptBins("")
207 , m_etaBins("")
208 , m_fixedPtVals("")
209 , m_fixedEtaVals("")
211 , m_fixedMassVals("")
212
213 , m_isSmallR(true)
214 , m_isLargeR(false)
215 , m_isJER(false)
216 , m_isTLA(false)
217
218 , m_composition("")
219 , m_nJetFlavour(-1)
220 , m_truthLabel(0)
223 , m_isDijet(false)
224
225 , m_tagSFname("")
228
229 , m_onlyCompare(false)
230 , m_doCompare("")
231 , m_compareVals()
232
233 , m_scaleVars()
234 , m_systFilters()
235 , m_topology(JetTopology::UNKNOWN)
236
237 , m_inputsDir("/eos/atlas/atlascerngroupdisk/perf-jets/JetUncertainties/Inputs/")
238
239 , m_dumpFile("")
240{ }
241
242bool OptionHelper::Initialize(const std::vector<TString>& options)
243{
244 if (m_isInit)
245 {
246 ATH_MSG_ERROR("The tool has already been initialized, blocking re-initialization");
247 return false;
248 }
249 m_isInit = true;
250
251 // Check for the no-options case
252 if (!options.size()) return true;
253
254 // Options exist, let's parse them
255 m_isPublic = getOptionValueWithDefault(options,"isPublic",m_isPublic);
256 m_isEtaDepPU = getOptionValueWithDefault(options,"isEtaDepPileup",m_isEtaDepPU);
257 m_ignorePT = getOptionValueWithDefault(options,"ignorePT",m_ignorePT);
260 m_path = getOptionValueWithDefault(options,"Path",m_path);
261 m_isData = getOptionValueWithDefault(options,"IsData",m_isData);
263
266 if (m_ATLASLabel == "PUBLIC") m_ATLASLabel = "";
269 m_totalUncName = getOptionValueWithDefault(options,"totalUncName",m_totalUncName).Strip(TString::kBoth,'"');
271 m_axisMax = getOptionValueWithDefault(options,"axisMax",m_axisMax);
272 m_axisMin = getOptionValueWithDefault(options,"axisMin",m_axisMin);
273 TString xAxisRange = getOptionValue(options,"xAxisRange");
274 if (xAxisRange != "")
275 {
276 std::vector<double> range = jet::utils::vectorize<double>(xAxisRange,"&");
277 if (range.size() != 2)
278 ATH_MSG_WARNING("xAxisRange doesn't match expected format of \"val1&val2\". Skipping.");
279 else
280 {
281 const double lowX = range.at(0);
282 const double highX = range.at(1);
283 m_xAxisRange = std::make_pair(lowX,highX);
284 }
285 }
286 m_absVal = getOptionValueWithDefault(options,"absVal",m_absVal);
287 m_logPt = getOptionValueWithDefault(options,"logPt",m_logPt);
289 TString fillShift = getOptionValue(options,"FillLabelShift");
290 if (fillShift != "")
291 {
292 std::vector<double> shift = jet::utils::vectorize<double>(fillShift,"&");
293 if (shift.size() != 2)
294 ATH_MSG_WARNING("FillLabelShift doesn't match expected format of \"val1&val2\". Skipping.");
295 else
296 {
297 const double lowShift = shift.at(0);
298 const double highShift = shift.at(1);
299 m_fillShift = std::make_pair(lowShift,highShift);
300 }
301 }
303
304 m_ptBins = getOptionValueWithDefault(options,"ptBins",m_ptBins);
305 m_etaBins = getOptionValueWithDefault(options,"etaBins",m_etaBins);
310
311 m_isLargeR = getOptionValueWithDefault(options,"isLargeR",m_isLargeR);
312 m_isJER = getOptionValueWithDefault(options,"isJER",m_isJER);
313 m_isTLA = getOptionValueWithDefault(options,"isTLA",m_isTLA);
315
319 TString largeRJetTruthLabelStr = getOptionValue(options,"LargeRJetTruthLabel");
320 if (largeRJetTruthLabelStr != "")
321 {
324 {
325 ATH_MSG_WARNING("LargeRJetTruthLabel is UNKNOWN value, skipping usage: " << largeRJetTruthLabelStr.Data());
326 }
327 }
329 m_isDijet = getOptionValueWithDefault(options,"isDijet",m_isDijet);
330 if (m_isDijet)
331 {
332 if (m_composition == "")
333 m_composition = "Dijet";
334 else
335 {
336 ATH_MSG_ERROR("The composition was double-specified, please check that you don't specify both \"Composition\" and \"isDijet\"");
337 throw std::runtime_error("Double composition failure");
338 }
339 }
340
343 if (m_largeRjetTagResultName != "")
344 {
345 m_largeRjetTagAccept = getOptionValueWithDefault(options,"TagAcceptResult",0);
346 // TODO: enable when available
347 // if (TagResult::intToEnum(m_largeRjetTagAccept) == TagResult::UNKNOWN)
348 // {
349 // ATH_MSG_ERROR("The specified tag result doesn't match any expected value");
350 // throw std::runtime_error("Bad tag result value");
351 // }
352 }
353
356 m_compareVals = getCompareVals(options);
357
359
360 m_dumpFile = getOptionValueWithDefault(options,"dumpFile",m_dumpFile);
361
362 const TString localScaleVar = getOptionValue(options,"scaleVar");
363 if (localScaleVar == "")
364 {
366 else if (m_isLargeR) m_scaleVars.push_back(CompScaleVar::Pt);
367 }
368 else
369 {
370 std::vector<TString> localScaleVarVec = jet::utils::vectorize<TString>(localScaleVar,"&");
371 for (size_t iVar = 0; iVar < localScaleVarVec.size(); ++iVar)
372 m_scaleVars.push_back(CompScaleVar::stringToEnum(localScaleVarVec.at(iVar)));
373 }
374 const TString jetTopology = getOptionValue(options,"topology");
375 if (jetTopology != "")
376 {
379 {
380 ATH_MSG_ERROR("The topology specified is invalid: " << jetTopology.Data());
381 throw std::runtime_error("Topology failure");
382 }
383 }
384
385 const TString systFilterString = getOptionValue(options,"VariablesToShift");
386 if (systFilterString != "")
388
389 return true;
390}
391
392
393TString OptionHelper::getOptionValue(const std::vector<TString>& options, const TString optionName) const
394{
395 for (size_t iOpt = 0; iOpt < options.size(); ++iOpt)
396 {
397 std::vector<TString> option = jet::utils::vectorize<TString>(options.at(iOpt),"=");
398 if (option.size() != 2)
399 {
400 printf("Bad option, check formatting: %s\n",options.at(iOpt).Data());
401 exit(-1);
402 }
403 if (!option.at(0).CompareTo(optionName,TString::kIgnoreCase))
404 return option.at(1);
405 }
406 return "";
407}
408
409template <typename T>
410T OptionHelper::getOptionValueWithDefault(const std::vector<TString>& options, const TString optionName, const T defaultVal)
411{
412 const TString optionVal = getOptionValue(options,optionName);
413 if (optionVal == "")
414 return defaultVal;
415 return jet::utils::getTypeObjFromString<T>(optionVal);
416}
417
418std::vector<TString> OptionHelper::getCompareVals(const std::vector<TString>& options) const
419{
420 std::vector<TString> returnVal;
421 for (int i=1; i> 0; i++) {
422 TString optname = TString::Format("compareConfig%i",i);
423 const TString thisname = getOptionValue(options,optname);
424 if (thisname != "") returnVal.push_back(thisname);
425 else break;
426 }
427 return returnVal;
428}
429
430
432{
433 if (!m_isInit)
434 {
435 ATH_MSG_FATAL("Asked for a value before initializing the tool");
436 throw std::runtime_error("Initialization failure");
437 }
438}
439
440
441
442
443
444std::vector<double> OptionHelper::getBins(const TString& toParse) const
445{
446 // Ensure this is in the expected format
447 // type&numBins&minVal&maxVal
448 // type is either "U" for uniform or "L" for logarithmic
449 std::vector<TString> tokens = jet::utils::vectorize<TString>(toParse,"&");
450
451 // Check the number of tokens
452 if (tokens.size() != 4)
453 {
454 ATH_MSG_FATAL("Unexpected format for bins: " << toParse.Data());
455 throw std::runtime_error("Parse failure");
456 }
457
458 // Check the type
459 const bool isUniform = (tokens.at(0) == "U") || (tokens.at(0) == "u");
460 const bool isLog = (tokens.at(0) == "L") || (tokens.at(0) == "l");
461 if (!isUniform && !isLog)
462 {
463 ATH_MSG_FATAL("Unexpected binning type (token 0), only U/u and L/l are currently supported: " << toParse.Data());
464 throw std::runtime_error("Parse failure");
465 }
466
467 // Check the number of bins
468 unsigned numBins = 0;
469 if (!jet::utils::getTypeObjFromString(tokens.at(1),numBins))
470 {
471 ATH_MSG_FATAL("Number of bins (token 1) was not an unsigned int: " << toParse.Data());
472 throw std::runtime_error("Parse failure");
473 }
474
475 // Check the min and max
476 double minVal = 0, maxVal = 0;
477 if (!jet::utils::getTypeObjFromString(tokens.at(2),minVal))
478 {
479 ATH_MSG_FATAL("Number of bins (token 2) was not a double: " << toParse.Data());
480 throw std::runtime_error("Parse failure");
481 }
482 if (!jet::utils::getTypeObjFromString(tokens.at(3),maxVal))
483 {
484 ATH_MSG_FATAL("Number of bins (token 3) was not a double: " << toParse.Data());
485 throw std::runtime_error("Parse failure");
486 }
487 if (maxVal < minVal)
488 {
489 ATH_MSG_FATAL("The maximum value is smaller than the minimum: " << toParse.Data());
490 throw std::runtime_error("Parse failure");
491 }
492
493 // Done checking, finally return the bins
494 if (isUniform)
495 return jet::utils::getUniformBins(numBins,minVal,maxVal);
496 return jet::utils::getLogBins(numBins,minVal,maxVal);
497}
498
499
500
501std::vector<double> OptionHelper::GetPtBins() const
502{
503 checkInit();
504 std::vector<double> bins;
505
506 // Check if the user has provided something
507 if (m_ptBins == "")
508 {
509 if (IsLargeR())
510 bins = jet::utils::getLogBins(2000,200,3000);
511 else
512 bins = jet::utils::getLogBins(2000,15,3000);
513 }
514 else
516
517 return bins;
518}
519
520std::vector<double> OptionHelper::GetEtaBins() const
521{
522 checkInit();
523 std::vector<double> bins;
524
525 // Check if the user has provided something
526 if (m_etaBins == "")
527 bins = jet::utils::getUniformBins(1800,-4.5,4.5);
528 else
530
531 return bins;
532}
533
534std::vector<double> OptionHelper::GetFixedPtVals() const
535{
536 checkInit();
537 std::vector<double> bins;
538
539 if (m_fixedPtVals != "")
540 {
541 if (m_fixedPtVals != "NONE")
543 }
544 else
545 bins = jet::utils::vectorize<double>("25,40,60,80,120",",");
546
547 return bins;
548}
549
550std::vector<double> OptionHelper::GetFixedEtaVals() const
551{
552 checkInit();
553 std::vector<double> bins;
554
555 if (m_fixedEtaVals != "")
556 {
557 if (m_fixedEtaVals != "NONE")
559 }
560 else if (IsLargeR())
562 else if (IsJER())
563 bins = jet::utils::vectorize<double>("0,0.8,1.2,2.1,2.8,3.2,3.6",",");
564 else
565 bins = jet::utils::vectorize<double>("0,0.5,1,2,2.5,3,4",",");
566
567 return bins;
568}
569
570std::vector<double> OptionHelper::GetFixedMoverPtVals() const
571{
572 checkInit();
573 std::vector<double> bins;
574
575 if (m_fixedMoverPtVals != "")
576 {
577 if (m_fixedMoverPtVals != "NONE")
579 }
580 else if (!IsLargeR())
582 else if (IsPublicFormat())
583 bins = jet::utils::vectorize<double>("0.101",",");
584 else
585 bins = jet::utils::vectorize<double>("0.001,0.05,0.101,0.15,0.201,0.25,0.301,0.35,0.401,0.45,0.501,0.55,0.601,0.65,0.701,0.75,0.801,0.85,0.901,0.95,1.001",",");
586
587 return bins;
588}
589
590std::vector<double> OptionHelper::GetFixedMassVals() const
591{
592 checkInit();
593 std::vector<double> bins;
594
595 if (m_fixedMassVals != "" && m_fixedMassVals != "NONE")
597
598 return bins;
599}
600
602{
603 checkInit();
604
605 // Trivial case (unknown composition)
606 if (m_composition == "")
607 return "";
608 // Path-based case (user specified file path, return it)
609 if (m_composition.Contains(".root"))
610 return m_composition;
611 // Name-based case (user specified name, return expected path)
612 else
613 {
614 if (!m_composition.CompareTo("Unknown",TString::kIgnoreCase))
615 return "";
616 if (!m_composition.CompareTo("Dijet",TString::kIgnoreCase))
617 return GetInputsDir()+"/DijetFlavourComp_13TeV.root";
618 if (!m_composition.CompareTo("Gino",TString::kIgnoreCase))
619 return GetInputsDir()+"/GinoComposition.root";
620 }
621
622 ATH_MSG_FATAL("Unable to interpret special composition path: " << m_composition);
623 throw std::runtime_error("Composition path failure");
624 return "";
625}
626
628{
629 checkInit();
630
631 // Trivial case (unknown composition)
632 if (m_composition == "")
633 return "unknown composition";
634 // Path-based case (user specified the file path, return "custom" as name)
635 if (m_composition.Contains(".root"))
636 {
637 return "custom composition";
638 }
639 // Name-based case (user specified name, interpret or return it)
640 if (!m_composition.Contains(".root"))
641 {
642 if (!m_composition.CompareTo("Unknown",TString::kIgnoreCase))
643 return "unknown composition";
644 if (!m_composition.CompareTo("Dijet",TString::kIgnoreCase))
645 return "inclusive jets";
646 if (!m_composition.CompareTo("Gino",TString::kIgnoreCase))
647 return "Gino's composition";
648 return m_composition + " composition";
649 }
650
651 ATH_MSG_FATAL("Unable to interpret special composition name: " << m_composition);
652 throw std::runtime_error("Composition name failure");
653 return "";
654}
655
656
657} // end jet namespace
658
659#endif
660
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_WARNING(x)
static const std::vector< std::string > bins
Class mimicking the AthMessaging class from the offline software.
AsgMessaging(const std::string &name)
Constructor with a name.
TString GetCompositionName() const
TString GetCalibArea() const
T getOptionValueWithDefault(const std::vector< TString > &options, const TString optionName, const T defaultVal)
TString GetCompositionPath() const
TString getMassType() const
TString m_truthLabelMoment
bool IgnoreNoMatch() const
TString GetPath() const
bool IsSpecialComposition() const
std::pair< double, double > m_fillShift
double AxisMax() const
std::vector< TString > m_compareVals
bool IsJER() const
void checkInit() const
TString m_fixedMoverPtVals
std::vector< double > GetFixedEtaVals() const
bool SpecifyTagger() const
bool IsPublicFormat() const
std::pair< double, double > m_xAxisRange
std::pair< double, double > fillShift() const
bool AbsValue() const
bool LogPt() const
double AxisMin() const
bool IsLargeR() const
std::vector< TString > getCompareVals(const std::vector< TString > &options) const
TString DoCompare() const
bool GetIsData() const
JetTopology::TypeEnum GetTopology() const
std::vector< double > GetEtaBins() const
std::vector< CompScaleVar::TypeEnum > m_scaleVars
std::vector< TString > GetCompareVals() const
TString GetNamePrefix() const
TString GetInputsDir() const
bool Initialize(const std::vector< TString > &options)
std::vector< double > GetFixedMoverPtVals() const
std::vector< double > GetFixedMassVals() const
int GetNjetFlavour() const
OptionHelper(const std::string &name="OptionHelper")
std::vector< std::string > m_systFilters
int FixedLargeRJetTagAccept() const
bool IsSmallR() const
TString GetDumpFile() const
int FixedTruthLabel() const
bool DoATLASLabel() const
std::vector< double > GetPtBins() const
bool CompareOnly() const
TString GetBunchSpacing() const
std::vector< double > GetFixedPtVals() const
JetTopology::TypeEnum m_topology
LargeRJetTruthLabel::TypeEnum m_largeRJetTruthLabel
bool IsTLA() const
const std::vector< std::string > VariablesToShift() const
LargeRJetTruthLabel::TypeEnum FixedLargeRJetTruthLabel() const
std::vector< CompScaleVar::TypeEnum > GetScaleVars() const
TString m_largeRjetTagResultName
bool DrawTotal() const
std::pair< double, double > xAxisRange() const
bool TwoColumnLegend() const
TString TagScaleFactorName() const
TString TruthLabelMoment() const
bool IgnorePT() const
TString GetATLASLabel() const
std::vector< double > getBins(const TString &toParse) const
TString getOptionValue(const std::vector< TString > &options, const TString optionName) const
bool IsEtaDepPileup() const
TString FixedLargeRJetTagResultName() const
TString TotalUncName() const
TypeEnum stringToEnum(const TString &name)
TypeEnum stringToEnum(const TString &type)
TypeEnum stringToEnum(const TString &type)
std::vector< double > getLogBins(const size_t numBins, const double minVal, const double maxVal)
bool getTypeObjFromString(const std::string &str, T &obj)
bool vectorize(const TString &str, const TString &sep, std::vector< T > &result)
std::vector< double > getUniformBins(const size_t numBins, const double minVal, const double maxVal)