00001 #ifndef JETUNCERTAINTIES_OPTIONHELPER_H
00002 #define JETUNCERTAINTIES_OPTIONHELPER_H
00003
00004 #include "AsgTools/AsgMessaging.h"
00005 #include <vector>
00006 #include <utility>
00007 #include "TString.h"
00008 #include "JetUncertainties/Helpers.h"
00009 #include "JetUncertainties/UncertaintyEnum.h"
00010
00011 namespace jet
00012 {
00013
00014 class OptionHelper : public asg::AsgMessaging
00015 {
00016 public:
00017
00018 OptionHelper(const std::string& name = "OptionHelper");
00019 ~OptionHelper() {}
00020 bool Initialize(const std::vector<TString>& options);
00021
00022
00023
00024
00025
00026
00027 bool IsPublicFormat() const { checkInit(); return m_isPublic; }
00028 bool IsEtaDepPileup() const { checkInit(); return m_isEtaDepPU; }
00029 bool IgnorePT() const { checkInit(); return m_ignorePT; }
00030 TString GetNamePrefix() const { checkInit(); return m_compNamePrefix; }
00031
00032
00033 bool DoATLASLabel() const { checkInit(); return m_doATLASLabel; }
00034 TString GetATLASLabel() const { checkInit(); return m_ATLASLabel; }
00035 TString GetBunchSpacing() const { checkInit(); return m_bunchSpacing; }
00036 bool DrawTotal() const { checkInit(); return m_doTotalUnc; }
00037 TString TotalUncName() const { checkInit(); return m_totalUncName; }
00038 bool SpecifyTagger() const { checkInit(); return m_specifyTagger; }
00039 double AxisMax() const { checkInit(); return m_axisMax < 0 ? (IsLargeR()? 0.2 : 0.1) : m_axisMax; }
00040 double AxisMin() const { checkInit(); return m_axisMin; }
00041 std::pair<double,double> xAxisRange() const { checkInit(); return m_xAxisRange; }
00042 bool AbsValue() const { checkInit(); return m_absVal; }
00043 bool LogPt() const { checkInit(); return m_logPt; }
00044 TString getMassType() const { checkInit(); return m_massType; }
00045
00046 std::vector<double> GetPtBins() const;
00047 std::vector<double> GetEtaBins() const;
00048 std::vector<double> GetFixedPtVals() const;
00049 std::vector<double> GetFixedEtaVals() const;
00050 std::vector<double> GetFixedMoverPtVals() const;
00051
00052
00053 bool IsSmallR() const { checkInit(); return m_isSmallR; }
00054 bool IsLargeR() const { checkInit(); return m_isLargeR; }
00055 bool IsJER() const { checkInit(); return m_isJER; }
00056 bool IsTLA() const { checkInit(); return m_isTLA; }
00057
00058
00059 bool IsUnknownComposition() const { checkInit(); return m_isUnknownComp; }
00060 bool IsDijetComposition() const { checkInit(); return m_isDijetComp; }
00061 bool IsGinosComposition() const { checkInit(); return m_isGinosComp; }
00062
00063
00064 bool CompareOnly() const { checkInit(); return m_onlyCompare; }
00065 TString DoCompare() const { checkInit(); return m_doCompare; }
00066 std::vector<TString> GetCompareVals() const { checkInit(); return m_compareVals; }
00067
00068
00069 std::vector<CompScaleVar::TypeEnum> GetScaleVars() const { checkInit(); return m_scaleVars; }
00070 const std::vector<std::string> VariablesToShift() const { checkInit(); return m_systFilters; }
00071
00072 private:
00073 bool m_isInit;
00074
00075 bool m_isPublic;
00076 bool m_isEtaDepPU;
00077 bool m_ignorePT;
00078 TString m_compNamePrefix;
00079
00080 bool m_doATLASLabel;
00081 TString m_ATLASLabel;
00082 TString m_bunchSpacing;
00083 bool m_doTotalUnc;
00084 TString m_totalUncName;
00085 bool m_specifyTagger;
00086 double m_axisMax;
00087 double m_axisMin;
00088 std::pair<double,double> m_xAxisRange;
00089 bool m_absVal;
00090 bool m_logPt;
00091 TString m_massType;
00092
00093 TString m_ptBins;
00094 TString m_etaBins;
00095 TString m_fixedPtVals;
00096 TString m_fixedEtaVals;
00097 TString m_fixedMoverPtVals;
00098
00099 bool m_isSmallR;
00100 bool m_isLargeR;
00101 bool m_isJER;
00102 bool m_isTLA;
00103
00104 bool m_isUnknownComp;
00105 bool m_isDijetComp;
00106 bool m_isGinosComp;
00107
00108 bool m_onlyCompare;
00109 TString m_doCompare;
00110 std::vector<TString> m_compareVals;
00111
00112 std::vector<CompScaleVar::TypeEnum> m_scaleVars;
00113 std::vector<std::string> m_systFilters;
00114
00115 TString getOptionValue(const std::vector<TString>& options, const TString optionName) const;
00116 template <typename T>
00117 T getOptionValueWithDefault(const std::vector<TString>& options, const TString optionName, const T defaultVal);
00118 std::vector<TString> getCompareVals(const std::vector<TString>& options) const;
00119
00120 void checkInit() const;
00121
00122 std::vector<double> getBins(const TString& toParse) const;
00123 };
00124
00125 OptionHelper::OptionHelper(const std::string& name)
00126 : asg::AsgMessaging(name)
00127 , m_isInit(false)
00128
00129 , m_isPublic(false)
00130 , m_isEtaDepPU(false)
00131 , m_ignorePT(false)
00132 , m_compNamePrefix("JET_")
00133
00134 , m_doATLASLabel(true)
00135 , m_ATLASLabel("Internal")
00136 , m_bunchSpacing("")
00137 , m_doTotalUnc(true)
00138 , m_totalUncName("Total uncertainty")
00139 , m_specifyTagger(true)
00140 , m_axisMax(-1)
00141 , m_axisMin(0)
00142 , m_xAxisRange(0,0)
00143 , m_absVal(true)
00144 , m_logPt(true)
00145 , m_massType("")
00146
00147 , m_ptBins("")
00148 , m_etaBins("")
00149 , m_fixedPtVals("")
00150 , m_fixedEtaVals("")
00151 , m_fixedMoverPtVals("")
00152
00153 , m_isSmallR(true)
00154 , m_isLargeR(false)
00155 , m_isJER(false)
00156 , m_isTLA(false)
00157
00158 , m_isUnknownComp(true)
00159 , m_isDijetComp(false)
00160 , m_isGinosComp(false)
00161
00162 , m_onlyCompare(false)
00163 , m_doCompare("")
00164 , m_compareVals()
00165
00166 , m_scaleVars()
00167 , m_systFilters()
00168 { }
00169
00170 bool OptionHelper::Initialize(const std::vector<TString>& options)
00171 {
00172 if (m_isInit)
00173 {
00174 ATH_MSG_ERROR("The tool has already been initialized, blocking re-initialization");
00175 return false;
00176 }
00177 m_isInit = true;
00178
00179
00180 if (!options.size()) return true;
00181
00182
00183 m_isPublic = getOptionValueWithDefault(options,"isPublic",m_isPublic);
00184 m_isEtaDepPU = getOptionValueWithDefault(options,"isEtaDepPileup",m_isEtaDepPU);
00185 m_ignorePT = getOptionValueWithDefault(options,"ignorePT",m_ignorePT);
00186 m_compNamePrefix = getOptionValueWithDefault(options,"prefix",m_compNamePrefix);
00187
00188 m_doATLASLabel = getOptionValueWithDefault(options,"DoATLASLabel",m_doATLASLabel);
00189 m_ATLASLabel = getOptionValueWithDefault(options,"ATLASLabel",m_ATLASLabel);
00190 m_bunchSpacing = getOptionValueWithDefault(options,"bunchSpacing",m_bunchSpacing);
00191 m_doTotalUnc = getOptionValueWithDefault(options,"drawTotal",m_doTotalUnc);
00192 m_totalUncName = getOptionValueWithDefault(options,"totalUncName",m_totalUncName).Strip(TString::kBoth,'"');
00193 m_specifyTagger = getOptionValueWithDefault(options,"specifyTagger",m_specifyTagger);
00194 m_axisMax = getOptionValueWithDefault(options,"axisMax",m_axisMax);
00195 m_axisMin = getOptionValueWithDefault(options,"axisMin",m_axisMin);
00196 TString xAxisRange = getOptionValue(options,"xAxisRange");
00197 if (xAxisRange != "")
00198 {
00199 std::vector<double> range = jet::utils::vectorize<double>(xAxisRange,"&");
00200 if (range.size() != 2)
00201 ATH_MSG_WARNING("xAxisRange doesn't match expected format of \"val1&val2\". Skipping.");
00202 else
00203 {
00204 const double lowX = range.at(0);
00205 const double highX = range.at(1);
00206 m_xAxisRange = std::make_pair(lowX,highX);
00207 }
00208 }
00209 m_absVal = getOptionValueWithDefault(options,"absVal",m_absVal);
00210 m_logPt = getOptionValueWithDefault(options,"logPt",m_logPt);
00211 m_massType = getOptionValueWithDefault(options,"massDef",m_massType);
00212
00213 m_ptBins = getOptionValueWithDefault(options,"ptBins",m_ptBins);
00214 m_etaBins = getOptionValueWithDefault(options,"etaBins",m_etaBins);
00215 m_fixedPtVals = getOptionValueWithDefault(options,"fixedPtVals",m_fixedPtVals);
00216 m_fixedEtaVals = getOptionValueWithDefault(options,"fixedEtaVals",m_fixedEtaVals);
00217 m_fixedMoverPtVals = getOptionValueWithDefault(options,"fixedMoverPtVals",m_fixedMoverPtVals);
00218
00219 m_isLargeR = getOptionValueWithDefault(options,"isLargeR",m_isLargeR);
00220 m_isJER = getOptionValueWithDefault(options,"isJER",m_isJER);
00221 m_isTLA = getOptionValueWithDefault(options,"isTLA",m_isTLA);
00222 m_isSmallR = !(m_isLargeR || m_isJER);
00223
00224 m_isDijetComp = getOptionValueWithDefault(options,"isDijet",m_isDijetComp);
00225 m_isGinosComp = getOptionValueWithDefault(options,"isGinos",m_isGinosComp);
00226 m_isUnknownComp = !m_isDijetComp;
00227 if (m_isGinosComp) {
00228 m_isDijetComp = false;
00229 m_isUnknownComp = false;
00230 }
00231
00232 m_onlyCompare = getOptionValueWithDefault(options,"compareOnly",m_onlyCompare);
00233 m_doCompare = getOptionValueWithDefault(options,"doCompare",m_doCompare);
00234 m_compareVals = getCompareVals(options);
00235
00236
00237 const TString localScaleVar = getOptionValue(options,"scaleVar");
00238 if (localScaleVar == "")
00239 {
00240 if (m_isSmallR || m_isJER) m_scaleVars.push_back(CompScaleVar::FourVec);
00241 else if (m_isLargeR) m_scaleVars.push_back(CompScaleVar::Pt);
00242 }
00243 else
00244 {
00245 std::vector<TString> localScaleVarVec = jet::utils::vectorize<TString>(localScaleVar,"&");
00246 for (size_t iVar = 0; iVar < localScaleVarVec.size(); ++iVar)
00247 m_scaleVars.push_back(CompScaleVar::stringToEnum(localScaleVarVec.at(iVar)));
00248 }
00249
00250 const TString systFilterString = getOptionValue(options,"VariablesToShift");
00251 if (systFilterString != "")
00252 m_systFilters = jet::utils::vectorize<std::string>(systFilterString,",");
00253
00254 return true;
00255 }
00256
00257
00258 TString OptionHelper::getOptionValue(const std::vector<TString>& options, const TString optionName) const
00259 {
00260 for (size_t iOpt = 0; iOpt < options.size(); ++iOpt)
00261 {
00262 std::vector<TString> option = jet::utils::vectorize<TString>(options.at(iOpt),"=");
00263 if (option.size() != 2)
00264 {
00265 printf("Bad option, check formatting: %s\n",options.at(iOpt).Data());
00266 exit(-1);
00267 }
00268 if (!option.at(0).CompareTo(optionName,TString::kIgnoreCase))
00269 return option.at(1);
00270 }
00271 return "";
00272 }
00273
00274 template <typename T>
00275 T OptionHelper::getOptionValueWithDefault(const std::vector<TString>& options, const TString optionName, const T defaultVal)
00276 {
00277 const TString optionVal = getOptionValue(options,optionName);
00278 if (optionVal == "")
00279 return defaultVal;
00280 return jet::utils::getTypeObjFromString<T>(optionVal);
00281 }
00282
00283 std::vector<TString> OptionHelper::getCompareVals(const std::vector<TString>& options) const
00284 {
00285 std::vector<TString> returnVal;
00286 for (int i=1; i> 0; i++) {
00287 TString optname = TString::Format("compareConfig%i",i);
00288 const TString thisname = getOptionValue(options,optname);
00289 if (thisname != "") returnVal.push_back(thisname);
00290 else break;
00291 }
00292 return returnVal;
00293 }
00294
00295
00296 void OptionHelper::checkInit() const
00297 {
00298 if (!m_isInit)
00299 {
00300 ATH_MSG_FATAL("Asked for a value before initializing the tool");
00301 throw std::string("Initialization failure");
00302 }
00303 }
00304
00305
00306
00307
00308
00309 std::vector<double> OptionHelper::getBins(const TString& toParse) const
00310 {
00311
00312
00313
00314 std::vector<TString> tokens = jet::utils::vectorize<TString>(toParse,"&");
00315
00316
00317 if (tokens.size() != 4)
00318 {
00319 ATH_MSG_FATAL("Unexpected format for bins: " << toParse.Data());
00320 throw std::string("Parse failure");
00321 }
00322
00323
00324 const bool isUniform = (tokens.at(0) == "U") || (tokens.at(0) == "u");
00325 const bool isLog = (tokens.at(0) == "L") || (tokens.at(0) == "l");
00326 if (!isUniform && !isLog)
00327 {
00328 ATH_MSG_FATAL("Unexpected binning type (token 0), only U/u and L/l are currently supported: " << toParse.Data());
00329 throw std::string("Parse failure");
00330 }
00331
00332
00333 unsigned numBins = 0;
00334 if (!jet::utils::getTypeObjFromString(tokens.at(1),numBins))
00335 {
00336 ATH_MSG_FATAL("Number of bins (token 1) was not an unsigned int: " << toParse.Data());
00337 throw std::string("Parse failure");
00338 }
00339
00340
00341 double minVal = 0, maxVal = 0;
00342 if (!jet::utils::getTypeObjFromString(tokens.at(2),minVal))
00343 {
00344 ATH_MSG_FATAL("Number of bins (token 2) was not a double: " << toParse.Data());
00345 throw std::string("Parse failure");
00346 }
00347 if (!jet::utils::getTypeObjFromString(tokens.at(3),maxVal))
00348 {
00349 ATH_MSG_FATAL("Number of bins (token 3) was not a double: " << toParse.Data());
00350 throw std::string("Parse failure");
00351 }
00352 if (maxVal < minVal)
00353 {
00354 ATH_MSG_FATAL("The maximum value is smaller than the minimum: " << toParse.Data());
00355 throw std::string("Parse failure");
00356 }
00357
00358
00359 if (isUniform)
00360 return jet::utils::getUniformBins(numBins,minVal,maxVal);
00361 return jet::utils::getLogBins(numBins,minVal,maxVal);
00362 }
00363
00364
00365
00366 std::vector<double> OptionHelper::GetPtBins() const
00367 {
00368 checkInit();
00369 std::vector<double> bins;
00370
00371
00372 if (m_ptBins == "")
00373 {
00374 if (IsLargeR())
00375 bins = jet::utils::getLogBins(2000,200,3000);
00376 else
00377 bins = jet::utils::getLogBins(2000,15,3000);
00378 }
00379 else
00380 bins = getBins(m_ptBins);
00381
00382 return bins;
00383 }
00384
00385 std::vector<double> OptionHelper::GetEtaBins() const
00386 {
00387 checkInit();
00388 std::vector<double> bins;
00389
00390
00391 if (m_etaBins == "")
00392 bins = jet::utils::getUniformBins(1800,-4.5,4.5);
00393 else
00394 bins = getBins(m_etaBins);
00395
00396 return bins;
00397 }
00398
00399 std::vector<double> OptionHelper::GetFixedPtVals() const
00400 {
00401 checkInit();
00402 std::vector<double> bins;
00403
00404 if (m_fixedPtVals != "")
00405 bins = jet::utils::vectorize<double>(m_fixedPtVals,",");
00406 else
00407 bins = jet::utils::vectorize<double>("25,40,60,80,120",",");
00408
00409 return bins;
00410 }
00411
00412 std::vector<double> OptionHelper::GetFixedEtaVals() const
00413 {
00414 checkInit();
00415 std::vector<double> bins;
00416
00417 if (m_fixedEtaVals != "")
00418 bins = jet::utils::vectorize<double>(m_fixedEtaVals,",");
00419 else if (IsLargeR())
00420 bins = jet::utils::vectorize<double>("0",",");
00421 else if (IsJER())
00422 bins = jet::utils::vectorize<double>("0,0.8,1.2,2.1,2.8,3.2,3.6",",");
00423 else
00424 bins = jet::utils::vectorize<double>("0,0.5,1,2,2.5,3,4",",");
00425
00426 return bins;
00427 }
00428
00429 std::vector<double> OptionHelper::GetFixedMoverPtVals() const
00430 {
00431 checkInit();
00432 std::vector<double> bins;
00433
00434 if (m_fixedMoverPtVals != "")
00435 bins = jet::utils::vectorize<double>(m_fixedMoverPtVals,",");
00436 else if (!IsLargeR())
00437 bins = jet::utils::vectorize<double>("0",",");
00438 else if (IsPublicFormat())
00439 bins = jet::utils::vectorize<double>("0.101",",");
00440 else
00441 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",",");
00442
00443 return bins;
00444 }
00445
00446
00447 }
00448
00449 #endif
00450