26 #include "Utilities/func/MathUtil.h" 50 TH1D* ratioHist =
nullptr;
53 for(
auto const& itr : dbs){
54 for(
auto const& sel : itr.Selections()){
57 if ((systName.substr(systName.length()-2, systName.length()) ==
"ND") |
58 (systName.substr(systName.length()-2, systName.length()) ==
"FD"))
59 strippedName = systName.substr(0, systName.length()-2);
62 ratioName = strippedName
69 ratioHist = (TH1D*)file->Get(ratioName.c_str());
71 if (ratioHist ==
nullptr)
75 <<
" not found in file " 79 for(
int i = 1;
i < ratioHist->GetNbinsX() + 1; ++
i){
80 fileSystVec[ratioName].push_back(ratioHist->GetBinContent(
i));
93 <<
"Calibration systematics file: " 95 <<
" cannot be found in FW_SEARCH_PATH. Bailing.";
102 <<
"Cannot open file: " 116 <<
"EShift systematics file: " 118 <<
" cannot be found in FW_SEARCH_PATH. Bailing.";
125 <<
"Cannot open file: " 136 std::vector<WeighterInfo> & weighters,
137 std::map<std::string, uint8_t> & shifters)
148 for(
auto const& itr : detLoc){
149 if(itr.second.IsOscPar())
continue;
150 systName = itr.first;
151 parType = itr.second.ParType();
153 if(systName.find(
"Shifter") != std::string::npos){
156 <<
"Adding shifter for " 184 <<
"Unable to determine weighting function for " 189 <<
"Adding weighter " 193 <<
"\nthe current weight type is " 196 weighters.push_back(weighter);
214 auto calcString = parset.
get<
std::string>(
"OscCalculatorType",
"PMNS");
218 auto weightString = parset.
get<
std::string>(
"WeightType",
"OscWeightsOnly");
223 if (calcString ==
"PMNS_NSI" ) calcType =
cmf::kNSI;
224 else if(calcString ==
"PMNS_Sterile") calcType =
cmf::kSterile;
267 <<
"Done initialising shifters and weighters";
277 else if(name.find(
"LepE") != std::string::npos) param =
cmf::kLep_RecoE;
278 else if(name.find(
"NuE" ) != std::string::npos) param =
cmf::kNu_RecoE;
288 <<
"Current shifter/weighter point:\n" 312 for(
size_t pv = 0; pv < pars.size(); ++pv){
330 if (itr.first ==
"L" )
fOscCalc->
SetL (itr.second.Value());
331 else if(itr.first ==
"Rho" )
fOscCalc->
SetRho (itr.second.Value());
337 else if(itr.first ==
"dCP" )
fOscCalc->
SetdCP (itr.second.Value());
388 <<
"Event does not have a valid MCVarVals unique_ptr, bail";
393 <<
"Event does not have a valid DataVarVals unique_ptr, bail";
410 uint8_t
const&
param)
413 float totalShift = 1.;
417 for(
auto const& itr : shifterMap){
419 if(itr.second != param)
continue;
421 auto const&
sigma = loc.find(itr.first)->second.Sigma();
425 shiftScale = 1. +
sigma * curShift;
440 totalShift *= shiftScale;
462 if(!curEvent->MCValsFilled() ||
489 <<
"Oscillation weight is " 516 for(
auto itr : weighters){
538 <<
"resetting oscillation calculator to type " 542 <<
" are you sure you meant to change types in this job?";
590 const int numTrueEnergyBins = 100;
593 const double N = numTrueEnergyBins-1;
594 const double A = N * 0.5;
621 E = 0.5 * (eUpper + eLower);
626 <<
" central bin energy " 640 std::map<float, float>
const& wgtsBySigma)
642 auto mapEnd = wgtsBySigma.end();
646 double badVal = -99999999999999.;
647 double minus2Val = (wgtsBySigma.find(-2.) != mapEnd) ? static_cast<double>(wgtsBySigma.find(-2.)->second) : badVal;
648 double minus1Val = (wgtsBySigma.find(-1.) != mapEnd) ? static_cast<double>(wgtsBySigma.find(-1.)->second) : badVal;
650 double zeroVal = (wgtsBySigma.find( 0.) != mapEnd) ? static_cast<double>(wgtsBySigma.find( 0.)->second) : 1.;
651 double plus1Val = (wgtsBySigma.find( 1.) != mapEnd) ? static_cast<double>(wgtsBySigma.find( 1.)->second) : badVal;
652 double plus2Val = (wgtsBySigma.find( 2.) != mapEnd) ? static_cast<double>(wgtsBySigma.find( 2.)->second) : badVal;
654 double intercept = 0.;
658 <<
"\tCalcLinearInterpWgt: " 659 <<
" -2:" << minus2Val
660 <<
", -1:" << minus1Val
662 <<
", 1:" << plus1Val
663 <<
", 2:" << plus2Val;
674 if(minus1Val == badVal ||
676 LOG_WARNING(
"ShifterAndWeighterCalcLinearInterpWgt")
677 <<
"No values associated with either -1 sigma or +1 sigma " 678 <<
"so we cannot calculate a weight, return 1.";
685 if(minus2Val != badVal){
686 slope = (minus1Val - minus2Val);
687 intercept = minus2Val - slope * (-2.);
690 slope = (zeroVal - minus1Val);
691 intercept = minus1Val - slope * (-1.);
694 else if(sigma > -1. && sigma <= 0.){
695 slope = (zeroVal - minus1Val);
696 intercept = minus1Val - slope * (-1.);
698 else if(sigma > 0. && sigma <= 1.){
699 slope = (plus1Val - zeroVal);
700 intercept = plus1Val - slope * 1.;
705 if(plus2Val != badVal){
706 slope = (plus2Val - plus1Val);
707 intercept = plus2Val - slope * 2.;
710 slope = (plus1Val - zeroVal);
711 intercept = plus1Val - slope * 1.;
715 double wgt = sigma * slope + intercept;
718 if(wgt < 0) wgt = 0.;
728 double oneSigmaWgt = 1.0;
730 double normPOT = 0.0055;
731 double normNDMass = 0.003;
732 double normFDMass = 0.003;
733 double normML = 0.008;
759 if (systName ==
"NormalizationPOT") oneSigmaWgt += normPOT;
760 else if (systName ==
"NormalizationNDMass" && isND) oneSigmaWgt += normNDMass;
761 else if (systName ==
"NormalizationFDMass" && isFD) oneSigmaWgt += normFDMass;
762 else if (systName ==
"NormalizationML" && isFD) oneSigmaWgt += normML;
763 else if (systName ==
"NormalizationFHCNuMuContext" && isND && isNuMu && isFHC) oneSigmaWgt += normNDNumuContext;
764 else if (systName ==
"NormalizationRHCNuMuContext" && isND && isNuMu && isRHC) oneSigmaWgt += normNDNumuContext;
765 else if (systName ==
"NormalizationFHCNuEContext" && isND && isNuE && isFHC) oneSigmaWgt += normNDNueContext;
766 else if (systName ==
"NormalizationRHCNuEContext" && isND && isNuE && isRHC) oneSigmaWgt += normNDNueContext;
767 else if (systName ==
"NormalizationFHCNCContext" && isND && isNC && isFHC) oneSigmaWgt += normNDNCContext;
768 else if (systName ==
"NormalizationRHCNCContext" && isND && isNC && isRHC) oneSigmaWgt += normNDNCContext;
771 return 1. - (1. - oneSigmaWgt) * sigShift;
778 bool isWrongDet =
false;
783 if ((systName.substr(systName.length()-2, systName.length()) ==
"ND") |
784 (systName.substr(systName.length()-2, systName.length()) ==
"FD"))
785 strippedName = systName.substr(0, systName.length()-2);
800 return 1. - (1. - oneSigmaWgt) * sigShift;
double OscillationWeight()
#define LOG_DEBUG(stream)
Optimized version of OscCalcPMNS.
void OscillationCalculatorToUse(cmf::CalcType_t calcType)
MCVarVals const & MCVals() const
virtual void SetL(double L)=0
std::unique_ptr< Event > EventPtr
cmf::Location fCurrentLoc
the current point in parameter space
double CalcLinearInterpWgt(double sigma, std::map< float, float > const &wgtsBySigma)
float ShiftForParameter(std::map< std::string, uint8_t > const &shifterMap, cmf::ParameterSpaceLoc const &loc, uint8_t const ¶m)
bool MCValsFilled() const
const std::string cSelectionType_Strings[12]
virtual void SetDmsq21(const T &dmsq21)=0
cmf::WeightType_t fWeightType
which type of weights to use - oscillation, systematic or both
std::set< double > fTrueEnergyBins
the true energy binning used by CAF
static SelectionUtility * Instance()
virtual void SetTh13(const T &th13)=0
Adapt the PMNS_Sterile calculator to standard interface.
std::map< float, float > SystVarWgts(uint8_t const &varkey) const
void SetCurrentEvent(cmf::EventPtr const &curEvent, cmf::MetaData const &md)
enum cmf::det_type DetType_t
::xsd::cxx::tree::exception< char > exception
double Weight(cmf::EventPtr const &curEvent, cmf::MetaData const &md)
std::string calibFileName
double OscillationWeightBinCenter()
void FillShifterInfo(std::string const &name, cmf::DetType_t const &det)
double NormSystWeight(std::string const &systName)
std::string find_file(std::string const &filename) const
void InitEShiftSystFile()
virtual void SetDmsq32(const T &dmsq32)=0
enum cmf::par_type ParType_t
std::map< std::string, uint8_t > fShiftersToUseFD
std::map< std::string, uint8_t > fShiftersToUseND
std::vector< WeighterInfo > fWeightersToUseND
double CMFSystVarWeight(std::string const &systName)
double OscillationWeightTrueE()
int EnergyToBin(double const &energy, cmf::MetaData const &md)
double XSecCVPPFXWeight()
static uint8_t VarNameToKey(std::string const &name)
cmf::ParameterSpaceLoc const & NDLocation() const
DataVarVals const & DataVals() const
void InitShiftsAndWeightsForDetector(cmf::DetType_t const &det, cmf::ParameterSpaceLoc const &detLoc, std::vector< WeighterInfo > &weighters, std::map< std::string, uint8_t > &shifters)
T get(std::string const &key) const
cmf::ParameterSpaceLoc const & FDLocation() const
static ShifterAndWeighter * gShifterAndWeighter
double const CurrentParameterValue(std::string const &parName)
void SetOscillationVals()
void SetRho(const float &r)
static ShifterAndWeighter * Instance()
std::function< double()> wgtFn
float val_at(uint8_t const &varkey, cmf::MetaData const &md) const
bool DataValsFilled() const
A re-optimized version of OscCalcPMNSOpt.
#define LOG_WARNING(category)
virtual T P(int flavBefore, int flavAfter, double E)=0
E in GeV; flavors as PDG codes (so, neg==>antinu)
Module to combine a set of results into a single file currently only does one data product type at a ...
cmf::Event * fCurrentEvent
the current event to weight/shift
std::map< std::string, std::vector< float > > fileSystVec
virtual void SetRho(double rho)=0
void InitShiftsAndWeightsToUse(cmf::Location const &loc, fhicl::ParameterSet const &parset)
cmf::CalcType_t fCalcType
type of oscillation calculator
cmf::MetaData fCurrentMD
the metadata for the current event
float val_at(uint8_t const &varkey) const
Access a Var by name.
std::string eshiftFileName
virtual void SetTh23(const T &th23)=0
std::vector< WeighterInfo > fWeightersToUseFD
bool fTrueEOscillationWeight
flag to calculate the oscillation weight at the true E_nu vs bin center
const DetBeamSelSet & SelectionsToUse()
std::map< std::string, Parameter > ParameterSpaceLoc
float FractionalShift(uint8_t const ¶m)
enum cmf::calc_type CalcType_t
void LoadRatiosFromFile(TFile *file, std::string systName)
#define LOG_VERBATIM(category)
const std::string cDetType_Strings[5]
const std::string cBeamType_Strings[4]
double FileSystWeight(std::string const &systName)
void SetCurrentVals(cmf::Location const &loc)
osc::IOscCalcAdjustable * fOscCalc
the oscillation calculator
void SetParameterValue(std::string const &parName, double const &value, cmf::DetType_t const &det)
double TotalWeightFromWeighters()
virtual void SetTh12(const T &th12)=0
virtual void SetdCP(const T &dCP)=0
static CovarianceBinUtility * Instance()