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