Public Types | Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
ana::PredictionSystNumu2017 Class Reference

Loads shifted spectra from files. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-02-16/CAFAna/Prediction/PredictionSystNumu2017.h"

Inheritance diagram for ana::PredictionSystNumu2017:
ana::PredictionInterp ana::IPrediction

Public Types

enum  EMode_t { kCombineSigns, kSplitBySign }
 
enum  CoeffsType {
  kNueApp, kNueSurv, kNumuSurv, kNC,
  kOther, kNCoeffTypes
}
 

Public Member Functions

 PredictionSystNumu2017 (ENumu2017ExtrapType extrap, osc::IOscCalculator *osc, int WhichQuant=1, const std::vector< const DummyNumu2017Syst * > &systs=kNumu2017Systs, const std::string fname="/nova/ana/nu_mu_ana/Ana2017/Predictions/provisional/pred_numu_reduced_v5.root")
 
virtual ~PredictionSystNumu2017 ()
 
void SaveTo (TDirectory *dir) const override
 
Spectrum Predict (osc::IOscCalculator *calc) const override
 
SpectrumStan Predict (osc::IOscCalculatorStan *calc) const override
 
Spectrum PredictSyst (osc::IOscCalculator *calc, const SystShifts &shift) const override
 
SpectrumStan PredictSyst (osc::IOscCalculatorStan *calc, const SystShifts &shift) const override
 
Spectrum PredictComponent (osc::IOscCalculator *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
 
SpectrumStan PredictComponent (osc::IOscCalculatorStan *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
 
Spectrum PredictComponentSyst (osc::IOscCalculator *calc, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
 
SpectrumStan PredictComponentSyst (osc::IOscCalculatorStan *calc, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
 
void Derivative (osc::IOscCalculator *calc, const SystShifts &shift, double pot, std::unordered_map< const ISyst *, std::vector< double >> &dp) const override
 
void MinimizeMemory ()
 
void DebugPlot (const ISyst *syst, osc::IOscCalculator *calc, Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
 
void DebugPlots (osc::IOscCalculator *calc, const std::string &savePattern="", Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
 
void SetOscSeed (osc::IOscCalculator *oscSeed)
 
void DebugPlotColz (const ISyst *syst, osc::IOscCalculator *calc, Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
 
void DebugPlotsColz (osc::IOscCalculator *calc, const std::string &savePattern="", Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
 
bool SplitBySign () const
 
std::vector< std::vector< Coeffs > > FitRatios (const std::vector< double > &shifts, const std::vector< std::unique_ptr< TH1 >> &ratios) const
 Find coefficients describing this set of shifts. More...
 
std::vector< std::vector< Coeffs > > FitComponent (const std::vector< double > &shifts, const std::vector< IPrediction * > &preds, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
 Find coefficients describing the ratios from this component. More...
 
Spectrum ShiftSpectrum (const Spectrum &s, CoeffsType type, bool nubar, const SystShifts &shift) const
 
SpectrumStan ShiftSpectrum (const SpectrumStan &s, CoeffsType type, bool nubar, const SystShifts &shift) const
 
Spectrum ShiftedComponent (osc::IOscCalculator *calc, const TMD5 *hash, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign, CoeffsType type) const
 Helper for PredictComponentSyst. More...
 
SpectrumStan ShiftedComponent (osc::_IOscCalculator< stan::math::var > *calc, const TMD5 *hash, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign, CoeffsType type) const
 
virtual Spectrum PredictUnoscillated () const
 
virtual OscillatableSpectrum ComponentCC (int from, int to) const
 
virtual Spectrum ComponentNCTotal () const
 
virtual Spectrum ComponentNC () const
 
virtual Spectrum ComponentNCAnti () const
 

Static Public Member Functions

static std::unique_ptr< PredictionSystNumu2017LoadFrom (TDirectory *dir)
 
static void LoadFromBody (TDirectory *dir, PredictionInterp *ret, std::vector< const ISyst * > veto={})
 

Protected Member Functions

 PredictionSystNumu2017 ()
 
void AddNormSysts (const std::vector< const DummyNumu2017Syst * > &systs)
 
std::vector< std::vector< Coeffs > > FitSumComponent (const std::vector< ShiftedPreds > &spf, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
 
void InitFits () const
 
void InitFitsHelper (ShiftedPreds &sp, std::vector< std::vector< std::vector< Coeffs >>> &fits, Sign::Sign_t sign) const
 
void InitFitsSumHelper (std::vector< ShiftedPreds > &sps, std::vector< std::vector< std::vector< Coeffs >>> &fits, Sign::Sign_t sign) const
 
void ComponentDerivative (osc::IOscCalculator *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign, CoeffsType type, const SystShifts &shift, double pot, std::unordered_map< const ISyst *, std::vector< double >> &dp) const
 Helper for Derivative. More...
 
template<typename U , typename T >
_ShiftedComponent (osc::_IOscCalculator< T > *calc, const TMD5 *hash, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign, CoeffsType type) const
 Templated helper for ShiftedComponent. More...
 
template<typename U , typename T >
_PredictComponentSyst (osc::_IOscCalculator< T > *calc, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
 Templated helper for PredictComponentSyst. More...
 
template<typename T >
void ShiftBins (unsigned int N, T *arr, CoeffsType type, bool nubar, const SystShifts &shift) const
 Helper for ShiftSpectrum. More...
 

Protected Attributes

std::unique_ptr< IPredictionfPredNom
 The nominal prediction. More...
 
std::unordered_map< const ISyst *, ShiftedPredsfPreds
 
std::unordered_map< const ISyst *, ShiftedPredsfSumPreds
 
ShiftedPreds fSummedsp
 
osc::IOscCalculatorfOscOrigin
 The oscillation values we assume when evaluating the coefficients. More...
 
Spectrum fBinning
 Dummy spectrum to provide binning. More...
 
std::map< Key_t, Val_tfNomCache
 
bool fSplitBySign
 

Detailed Description

Loads shifted spectra from files.

Definition at line 117 of file PredictionSystNumu2017.h.

Member Enumeration Documentation

Enumerator
kNueApp 
kNueSurv 
kNumuSurv 
kNC 
kOther 

Taus, numu appearance.

kNCoeffTypes 

Definition at line 127 of file PredictionInterp.h.

Enumerator
kCombineSigns 
kSplitBySign 

Definition at line 31 of file PredictionInterp.h.

Constructor & Destructor Documentation

ana::PredictionSystNumu2017::PredictionSystNumu2017 ( ENumu2017ExtrapType  extrap,
osc::IOscCalculator osc,
int  WhichQuant = 1,
const std::vector< const DummyNumu2017Syst * > &  systs = kNumu2017Systs,
const std::string  fname = "/nova/ana/nu_mu_ana/Ana2017/Predictions/provisional/pred_numu_reduced_v5.root" 
)

Definition at line 51 of file PredictionSystNumu2017.cxx.

References AddNormSysts(), osc::_IOscCalculator< T >::Copy(), om::cout, allTimeWatchdog::endl, plot_validation_datamc::fname, ana::PredictionInterp::fOscOrigin, ana::PredictionInterp::fPredNom, ana::PredictionInterp::fPreds, ana::PredictionInterp::InitFits(), ana::kNuMu, ana::kNumu2017NormSystBkg, ana::kNumu2017NormSystBoth, ana::kNumu2017NormSystSig, ana::kNumuNoExtrap, ana::PredictionInterp::ShiftedPreds::preds, runNovaSAM::release, ana::PredictionInterp::ShiftedPreds::shifts, plotSysts::syst, ana::PredictionInterp::ShiftedPreds::systName, and art::to_string().

57  {
58  fOscOrigin = osc->Copy();
59 
60  std::string extrapStr = "pred_";
61  if (extrap == ENumu2017ExtrapType::kNuMu) extrapStr += "xp_numu";
62  if (extrap == ENumu2017ExtrapType::kNumuNoExtrap) extrapStr += "nxp";
63  extrapStr += "_";
64 
65  std::string VarName = "numu_pred_Energy_Quant"+std::to_string(WhichQuant);
66 
67  std::cout << "\nLooking at VarName " << VarName << " --> Loading nominals now..." << std::endl;
68 
69  IPrediction *nom;
70  std::string NomVar = extrapStr+"Nominal/noShift/"+VarName;
71  fPredNom = LoadFromFile<IPrediction>(fname, NomVar);
72  nom = LoadFromFile<IPrediction>(fname, NomVar).release();
73  // --- The light level syst uses an alternative nominal. Grab that now.
74  std::string LNomVar = extrapStr+"Lightlevel/noShift/"+VarName;
75  IPrediction* nomLightLevel = LoadFromFile<IPrediction>(fname, LNomVar).release();
76 
77  for(const DummyNumu2017Syst* syst: systs){
78  if(syst == &kNumu2017NormSystBoth ||
80  syst == &kNumu2017NormSystBkg) continue;
81 
82  // Hack. For sake of distinct names, every syst's fist 8 characters are numu2017
83  std::string systName = syst->ShortName();
84  systName.erase(0,8);
85 
86  std::cout << "Loading " << systName << "..." << std::endl;
87 
88  ShiftedPreds sp;
89  sp.systName = systName;
90 
91  for(int sigma: syst->Shifts()){
92  sp.shifts.push_back(sigma);
93 
94  if (sigma == 0){
95  if (systName == "Lightlevel" || systName == "Cherenkov") {
96  std::cout << "\tLooking at systName " << systName << ", so pushing back nomLightLevel " << std::endl;
97  sp.preds.push_back(nomLightLevel);
98  } else {
99  sp.preds.push_back(nom);
100  }
101  continue;
102  }
103 
104  std::string sigmaStr = "/";
105  if(sigma == -2) sigmaStr += "minusTwo/";
106  if(sigma == -1) sigmaStr += "minusOne/";
107  if(sigma == +1) sigmaStr += "plusOne/";
108  if(sigma == +2) sigmaStr += "plusTwo/";
109 
110 
111  auto shCore = LoadFromFile<PredictionExtrap> (fname, extrapStr + systName + sigmaStr +VarName).release();
112  sp.preds.push_back(shCore);
113  } // end for sigma
114 
115  fPreds.emplace(syst, sp);
116  } // end for syst
117 
118  // Calculate all the ratios etc
119  InitFits();
120 
121  AddNormSysts(systs);
122  }
const DummyNumu2017Syst kNumu2017NormSystSig("numu2017normSig","Sig. Norm.",{0,+1}, false)
const DummyNumu2017Syst kNumu2017NormSystBoth("numu2017NormBoth","Sig+Bkg Norm.",{0,+1}, false)
std::vector< SystGroupDef > systs
Definition: syst_header.h:384
virtual _IOscCalculator * Copy() const =0
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
osc::IOscCalculator * fOscOrigin
The oscillation values we assume when evaluating the coefficients.
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
string syst
Definition: plotSysts.py:176
const DummyNumu2017Syst kNumu2017NormSystBkg("numu2017normBkg","Bkg. Norm.",{0,+1}, false)
void AddNormSysts(const std::vector< const DummyNumu2017Syst * > &systs)
std::string to_string(ModuleType mt)
Definition: ModuleType.h:32
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
ana::PredictionSystNumu2017::~PredictionSystNumu2017 ( )
virtual

Definition at line 125 of file PredictionSystNumu2017.cxx.

126  {
127  }
ana::PredictionSystNumu2017::PredictionSystNumu2017 ( )
inlineprotected

Definition at line 132 of file PredictionSystNumu2017.h.

References systs.

132 {}

Member Function Documentation

template<typename U , typename T >
U ana::PredictionInterp::_PredictComponentSyst ( osc::_IOscCalculator< T > *  calc,
const SystShifts shift,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
protectedinherited

Templated helper for PredictComponentSyst.

Definition at line 615 of file PredictionInterp.cxx.

References ana::SystShifts::ActiveSysts(), om::cerr, ana::Spectrum::Clear(), allTimeWatchdog::endl, ana::PredictionInterp::fBinning, ana::PredictionInterp::fPreds, osc::_IOscCalculator< T >::GetParamsHash(), samweb_client.utility::hash, ana::PredictionInterp::InitFits(), ana::Flavors::kAll, ana::Current::kCC, ana::Current::kNC, ana::PredictionInterp::kNC, ana::PredictionInterp::kNueApp, ana::PredictionInterp::kNueSurv, ana::Flavors::kNuEToNuE, ana::Flavors::kNuEToNuMu, ana::Flavors::kNuEToNuTau, ana::PredictionInterp::kNumuSurv, ana::Flavors::kNuMuToNuE, ana::Flavors::kNuMuToNuMu, ana::Flavors::kNuMuToNuTau, ana::PredictionInterp::kOther, runNovaSAM::ret, ana::PredictionInterp::ShiftedComponent(), and plotSysts::syst.

620  {
621  InitFits();
622 
623  U ret = fBinning;
624  ret.Clear();
625 
626  // Check that we're able to handle all the systs we were passed
627  for(const ISyst* syst: shift.ActiveSysts()){
628  if(fPreds.find(syst) == fPreds.end()){
629  std::cerr << "This PredictionInterp is not set up to handle the requested systematic: " << syst->ShortName() << std::endl;
630  abort();
631  }
632  } // end for syst
633 
634 
635  const TMD5* hash = calc ? calc->GetParamsHash() : 0;
636 
637  if(curr & Current::kCC){
638  if(flav & Flavors::kNuEToNuE) ret += ShiftedComponent(calc, hash, shift, Flavors::kNuEToNuE, Current::kCC, sign, kNueSurv);
639  if(flav & Flavors::kNuEToNuMu) ret += ShiftedComponent(calc, hash, shift, Flavors::kNuEToNuMu, Current::kCC, sign, kOther );
640  if(flav & Flavors::kNuEToNuTau) ret += ShiftedComponent(calc, hash, shift, Flavors::kNuEToNuTau, Current::kCC, sign, kOther );
641 
642  if(flav & Flavors::kNuMuToNuE) ret += ShiftedComponent(calc, hash, shift, Flavors::kNuMuToNuE, Current::kCC, sign, kNueApp );
643  if(flav & Flavors::kNuMuToNuMu) ret += ShiftedComponent(calc, hash, shift, Flavors::kNuMuToNuMu, Current::kCC, sign, kNumuSurv);
644  if(flav & Flavors::kNuMuToNuTau) ret += ShiftedComponent(calc, hash, shift, Flavors::kNuMuToNuTau, Current::kCC, sign, kOther );
645  }
646  if(curr & Current::kNC){
647  assert(flav == Flavors::kAll); // Don't know how to calculate anything else
648 
649  ret += ShiftedComponent(calc, hash, shift, Flavors::kAll, Current::kNC, sign, kNC);
650  }
651 
652  delete hash;
653 
654  return ret;
655  }
(&#39; appearance&#39;)
Definition: IPrediction.h:18
(&#39;beam &#39;)
Definition: IPrediction.h:15
OStream cerr
Definition: OStream.cxx:7
void Clear()
Definition: Spectrum.cxx:878
Charged-current interactions.
Definition: IPrediction.h:39
virtual TMD5 * GetParamsHash() const
Use to check two calculators are in the same state.
Spectrum fBinning
Dummy spectrum to provide binning.
Spectrum ShiftedComponent(osc::IOscCalculator *calc, const TMD5 *hash, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign, CoeffsType type) const
Helper for PredictComponentSyst.
def sign(x)
Definition: canMan.py:204
(&#39; survival&#39;)
Definition: IPrediction.h:19
Taus, numu appearance.
string syst
Definition: plotSysts.py:176
Neutral-current interactions.
Definition: IPrediction.h:40
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
All neutrinos, any flavor.
Definition: IPrediction.h:26
(&#39; appearance&#39;)
Definition: IPrediction.h:16
template<typename U , typename T >
U ana::PredictionInterp::_ShiftedComponent ( osc::_IOscCalculator< T > *  calc,
const TMD5 *  hash,
const SystShifts shift,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign,
CoeffsType  type 
) const
protectedinherited

Templated helper for ShiftedComponent.

Definition at line 563 of file PredictionInterp.cxx.

References febshutoff_auto::curr, ana::PredictionInterp::fNomCache, ana::PredictionInterp::fPredNom, ana::PredictionInterp::fSplitBySign, samweb_client.utility::hash, it, ana::Sign::kAntiNu, ana::Sign::kBoth, findDuplicateFiles::key, ana::Sign::kNu, ana::PredictionInterp::ShiftedComponent(), and ana::PredictionInterp::ShiftSpectrum().

570  {
572  "PredictionInterp::ShiftedComponent() can only be called using doubles or stan::math::vars");
573 
574  if(fSplitBySign && sign == Sign::kBoth){
575  return (ShiftedComponent(calc, hash, shift, flav, curr, Sign::kAntiNu, type)+
576  ShiftedComponent(calc, hash, shift, flav, curr, Sign::kNu, type));
577  }
578 
579  // Must be the base case of the recursion to use the cache. Otherwise we
580  // can cache systematically shifted versions of our children, which is
581  // wrong. Also, some calculators won't hash themselves.
582  // Moreover, caching is not going to work with stan::math::vars
583  // since they get reset every time Stan's log_prob() is called.
584  const bool canCache = (hash != 0) && !std::is_same<T, stan::math::var>::value;
585 
586  const Key_t key = {flav, curr, sign};
587  auto it = fNomCache.find(key);
588 
589  // Should the interpolation use the nubar fits?
590  const bool nubar = (fSplitBySign && sign == Sign::kAntiNu);
591 
592  // We have the nominal for this exact combination of flav, curr, sign, calc
593  // stored. Shift it and return.
594  if(canCache && it != fNomCache.end() && it->second.hash == *hash){
595  return ShiftSpectrum(it->second.nom, type, nubar, shift);
596  }
597 
598  // We need to compute the nominal again for whatever reason
599  const auto nom = fPredNom->PredictComponent(calc, flav, curr, sign);
600 
601  if(canCache){
602  // Insert into the cache if not already there, or update if there but
603  // with old oscillation parameters.
604  if(it == fNomCache.end())
605  fNomCache.emplace(key, Val_t({*hash, nom}));
606  else
607  it->second = {*hash, nom};
608  }
609 
610  return ShiftSpectrum(nom, type, nubar, shift);
611  }
set< int >::iterator it
Antineutrinos-only.
Definition: IPrediction.h:50
::xsd::cxx::tree::type type
Definition: Database.h:110
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
std::map< Key_t, Val_t > fNomCache
const XML_Char int const XML_Char * value
Definition: expat.h:331
Spectrum ShiftedComponent(osc::IOscCalculator *calc, const TMD5 *hash, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign, CoeffsType type) const
Helper for PredictComponentSyst.
Neutrinos-only.
Definition: IPrediction.h:49
def sign(x)
Definition: canMan.py:204
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
Spectrum ShiftSpectrum(const Spectrum &s, CoeffsType type, bool nubar, const SystShifts &shift) const
void ana::PredictionSystNumu2017::AddNormSysts ( const std::vector< const DummyNumu2017Syst * > &  systs)
protected

Definition at line 130 of file PredictionSystNumu2017.cxx.

References coeff(), ana::PredictionInterp::ShiftedPreds::FillRemaps(), ana::PredictionInterp::ShiftedPreds::fits, ana::PredictionInterp::fOscOrigin, ana::PredictionInterp::fPredNom, ana::PredictionInterp::fPreds, demo3::h, ana::PredictionInterp::kNCoeffTypes, ana::kNumu2017NormSystBkg, ana::kNumu2017NormSystBoth, ana::kNumu2017NormSystSig, ana::PredictionInterp::kNumuSurv, plotROC::nBins, ana::PredictionInterp::Predict(), ana::PredictionInterp::ShiftedPreds::preds, ana::PredictionInterp::ShiftedPreds::shifts, ana::PredictionInterp::ShiftedPreds::systName, and ana::Spectrum::ToTH1().

Referenced by PredictionSystNumu2017().

131  {
132  TH1* h = Predict(fOscOrigin).ToTH1(1);
133  const int nBins = h->GetNbinsX();
134  delete h;
135 
136 
137  // Got this from Alex. TODO add reference
138  // pythag == sum in quadrature
139  // leaving Sig and bkg hooks in place, but they are not used anywhere
140  const double normBothSyst = 3.5/100;
141  const double normBkgSyst = 3.5/100;
142  const double normSigSyst = 3.5/100;
143 
144  // TODO find a way to write these three norm systs as a loop
145  // if(std::count(systs.begin(), systs.end(), &kNumu2017NormSystBoth)){
146  if(std::count_if(systs.begin(), systs.end(),
147  [](const ISyst* s){return s->ShortName() == "numu2017NormBoth";})){
148  ShiftedPreds normsp;
149  normsp.systName = "NormBoth";
150  normsp.shifts = {0};
151  normsp.preds = {fPredNom.get()};
152  for(int coeff = 0; coeff < kNCoeffTypes; ++coeff){
153  normsp.fits[coeff].resize(nBins+2);
154  for(int binIdx = 0; binIdx < nBins+2; ++binIdx){
155  normsp.fits[coeff][binIdx].push_back(Coeffs(0, 0, normBothSyst, 1));
156  }
157  }
158  normsp.FillRemaps();
159  fPreds.emplace(&kNumu2017NormSystBoth, normsp);
160  }
161 
162 
163  // if(std::count(systs.begin(), systs.end(), &kNumu2017NormSystBkg)){
164  if(std::count_if(systs.begin(), systs.end(),
165  [](const ISyst* s){return s->ShortName() == "numu2017normBkg";})){
166  ShiftedPreds normbksp;
167  normbksp.systName = "NumuNormBkg";
168  normbksp.shifts = {0};
169  normbksp.preds = {fPredNom.get()};
170  for(int coeff = 0; coeff < kNCoeffTypes; ++coeff){
171  normbksp.fits[coeff].resize(nBins+2);
172  for(int binIdx = 0; binIdx < nBins+2; ++binIdx){
173  normbksp.fits[coeff][binIdx].push_back(Coeffs(0, 0, (coeff != kNumuSurv) ? normBkgSyst : 0, 1));
174  }
175  }
176  normbksp.FillRemaps();
177  fPreds.emplace(&kNumu2017NormSystBkg, normbksp);
178  }
179 
180 
181  // if(std::count(systs.begin(), systs.end(), &kNumu2017NormSystSig)){
182  if(std::count_if(systs.begin(), systs.end(),
183  [](const ISyst* s){return s->ShortName() == "numu2017normSig";})){
184  ShiftedPreds normsigsp;
185  normsigsp.systName = "NumuNormSig";
186  normsigsp.shifts ={0};
187  normsigsp.preds = {fPredNom.get()};
188  for(int coeff = 0; coeff < kNCoeffTypes; ++coeff){
189  normsigsp.fits[coeff].resize(nBins+2);
190  for(int binIdx = 0; binIdx < nBins+2; ++binIdx){
191  normsigsp.fits[coeff][binIdx].push_back(Coeffs(0, 0, (coeff == kNumuSurv) ? normSigSyst : 0, 1));
192  }
193  }
194  normsigsp.FillRemaps();
195  fPreds.emplace(&kNumu2017NormSystSig, normsigsp);
196  }
197  }
int nBins
Definition: plotROC.py:16
const DummyNumu2017Syst kNumu2017NormSystSig("numu2017normSig","Sig. Norm.",{0,+1}, false)
const DummyNumu2017Syst kNumu2017NormSystBoth("numu2017NormBoth","Sig+Bkg Norm.",{0,+1}, false)
std::vector< SystGroupDef > systs
Definition: syst_header.h:384
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:553
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
const XML_Char * s
Definition: expat.h:262
osc::IOscCalculator * fOscOrigin
The oscillation values we assume when evaluating the coefficients.
double coeff(double W, int m, int l, bool real)
Spectrum Predict(osc::IOscCalculator *calc) const override
const DummyNumu2017Syst kNumu2017NormSystBkg("numu2017normBkg","Bkg. Norm.",{0,+1}, false)
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
h
Definition: demo3.py:41
virtual OscillatableSpectrum ana::IPrediction::ComponentCC ( int  from,
int  to 
) const
inlinevirtualinherited
void ana::PredictionInterp::ComponentDerivative ( osc::IOscCalculator calc,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign,
CoeffsType  type,
const SystShifts shift,
double  pot,
std::unordered_map< const ISyst *, std::vector< double >> &  dp 
) const
protectedinherited

Helper for Derivative.

Definition at line 679 of file PredictionInterp.cxx.

References ana::PredictionInterp::Coeffs::a, ana::PredictionInterp::Coeffs::b, ana::PredictionInterp::Coeffs::c, calib::corr(), util::cube(), ana::PredictionInterp::Coeffs::d, ana::HistCache::Delete(), release_diff::diff, MakeMiniprodValidationCuts::f, fits, ana::PredictionInterp::fPreds, ana::PredictionInterp::fSplitBySign, ana::SystShifts::GetShift(), demo3::h, it, ana::Sign::kAntiNu, ana::Sign::kBoth, ana::Sign::kNu, std::max(), std::min(), getGoodRuns4SAM::n, ana::PredictionInterp::PredictComponentSyst(), util::sqr(), plotSysts::syst, ana::Spectrum::ToTH1(), and submit_syst::x.

Referenced by ana::PredictionInterp::Derivative().

687  {
688  if(fSplitBySign && sign == Sign::kBoth){
689  ComponentDerivative(calc, flav, curr, Sign::kNu, type, shift, pot, dp);
690  ComponentDerivative(calc, flav, curr, Sign::kAntiNu, type, shift, pot, dp);
691  return;
692  }
693 
694  // this method is only ever going to be used by the "Frequentist" version of the class.
695  // don't bother templating.
696  const Spectrum base = PredictComponentSyst(calc, shift, flav, curr, sign);
697  TH1D* h = base.ToTH1(pot);
698  double* arr = h->GetArray();
699  const unsigned int N = h->GetNbinsX()+2;
700 
701 
702  // Should the interpolation use the nubar fits?
703  const bool nubar = (fSplitBySign && sign == Sign::kAntiNu);
704 
705  for(auto& it: dp){
706  const ISyst* syst = it.first;
707  std::vector<double>& diff = it.second;
708  if(diff.empty()) diff.resize(N);
709  assert(diff.size() == N);
710  assert(fPreds.find(syst) != fPreds.end());
711  const ShiftedPreds& sp = fPreds[syst];
712 
713  // not instrumenting this method for stan::math::vars
714  // since we're using autodiff anyway
715  double x = util::GetValAs<double>(shift.GetShift(syst));
716 
717  int shiftBin = (x - sp.shifts[0])/sp.Stride();
718  shiftBin = std::max(0, shiftBin);
719  shiftBin = std::min(shiftBin, sp.nCoeffs-1);
720 
721  const Coeffs* fits = nubar ? &sp.fitsNubarRemap[type][shiftBin].front() : &sp.fitsRemap[type][shiftBin].front();
722 
723  x -= sp.shifts[shiftBin];
724 
725  const double x_cube = util::cube(x);
726  const double x_sqr = util::sqr(x);
727 
728  for(unsigned int n = 0; n < N; ++n){
729  // Uncomment to debug crashes in this function
730  // assert(type < fits.size());
731  // assert(n < sp.fits[type].size());
732  // assert(shiftBin < int(sp.fits[type][n].size()));
733  const Coeffs& f = fits[n];
734 
735  const double corr = f.a*x_cube + f.b*x_sqr + f.c*x + f.d;
736  if(corr > 0) diff[n] += (3*f.a*x_sqr + 2*f.b*x + f.c)/corr*arr[n];
737  } // end for n
738  } // end for syst
739 
741  }
T max(const caf::Proxy< T > &a, T b)
set< int >::iterator it
Antineutrinos-only.
Definition: IPrediction.h:50
double corr(TGraph *g, double thresh)
T cube(T x)
More efficient cube function than pow(x,3)
Definition: MathUtil.h:26
void ComponentDerivative(osc::IOscCalculator *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign, CoeffsType type, const SystShifts &shift, double pot, std::unordered_map< const ISyst *, std::vector< double >> &dp) const
Helper for Derivative.
const XML_Char int const XML_Char int const XML_Char * base
Definition: expat.h:331
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
::xsd::cxx::tree::type type
Definition: Database.h:110
static void Delete(TH1D *&h)
Definition: HistCache.cxx:215
#define pot
Neutrinos-only.
Definition: IPrediction.h:49
def sign(x)
Definition: canMan.py:204
string syst
Definition: plotSysts.py:176
std::vector< std::string > fits
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
T min(const caf::Proxy< T > &a, T b)
Spectrum PredictComponentSyst(osc::IOscCalculator *calc, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
h
Definition: demo3.py:41
virtual Spectrum ana::IPrediction::ComponentNC ( ) const
inlinevirtualinherited

Reimplemented in ana::PredictionExtendToPeripheral, ana::PredictionAddRock, ana::PredictionCombinePeriods, and ana::PredictionExtrap.

Definition at line 111 of file IPrediction.h.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::PredictionAddRock::ComponentNC(), and ana::PredictionExtendToPeripheral::PredictionExtendToPeripheral().

112  {std::cout << "WARNING! ComponentNC is unimplemented in IPrediction" << std::endl; abort();}
OStream cout
Definition: OStream.cxx:6
virtual Spectrum ana::IPrediction::ComponentNCAnti ( ) const
inlinevirtualinherited

Reimplemented in ana::PredictionExtendToPeripheral, ana::PredictionAddRock, ana::PredictionCombinePeriods, and ana::PredictionExtrap.

Definition at line 113 of file IPrediction.h.

References om::cout, dir, allTimeWatchdog::endl, and ana::SaveTo().

Referenced by ana::PredictionAddRock::ComponentNCAnti(), and ana::PredictionExtendToPeripheral::PredictionExtendToPeripheral().

114  {std::cout << "WARNING! ComponentNCAnti is unimplemented in IPrediction" << std::endl; abort();}
OStream cout
Definition: OStream.cxx:6
virtual Spectrum ana::IPrediction::ComponentNCTotal ( ) const
inlinevirtualinherited

Reimplemented in ana::PredictionExtendToPeripheral, ana::PredictionAddRock, ana::PredictionCombinePeriods, and ana::PredictionExtrap.

Definition at line 109 of file IPrediction.h.

References om::cout, and allTimeWatchdog::endl.

Referenced by ana::PredictionAddRock::ComponentNCTotal(), and ana::PredictionExtendToPeripheral::PredictionExtendToPeripheral().

110  {std::cout << "WARNING! ComponentNCTotal is unimplemented in IPrediction" << std::endl; abort();}
OStream cout
Definition: OStream.cxx:6
void ana::PredictionInterp::DebugPlot ( const ISyst syst,
osc::IOscCalculator calc,
Flavors::Flavors_t  flav = Flavors::kAll,
Current::Current_t  curr = Current::kBoth,
Sign::Sign_t  sign = Sign::kBoth 
) const
inherited

Definition at line 920 of file PredictionInterp.cxx.

References bin, plot_validation_datamc::c, om::cout, Draw(), allTimeWatchdog::endl, genie::utils::style::Format(), ana::PredictionInterp::fPredNom, ana::PredictionInterp::fPreds, demo3::h, MECModelEnuComparisons::i, ana::PredictionInterp::InitFits(), makeTrainCVSamples::int, std::isnan(), it, nbins, ana::IPrediction::PredictComponent(), ana::PredictionInterp::PredictComponentSyst(), plotSysts::ratio, ana::ISyst::ShortName(), std::sqrt(), ss, and submit_syst::x.

Referenced by ana::PredictionInterp::DebugPlots().

925  {
926  InitFits();
927 
928  auto it = fPreds.find(syst);
929  if(it == fPreds.end()){
930  std::cout << "PredictionInterp::DebugPlots(): "
931  << syst->ShortName() << " not found" << std::endl;
932  return;
933  }
934 
935 
936  // force-convert to _Spectrum<double> for ease here since in DebugPlots()
937  // we're not concerned with preserving autodiff or speed.
938  // (more instances further below.)
939  std::unique_ptr<TH1> nom(Spectrum(fPredNom->PredictComponent(calc, flav, curr, sign)).ToTH1(18e20));
940  const int nbins = nom->GetNbinsX();
941 
942  TGraph* curves[nbins];
943  TGraph* points[nbins];
944 
945  for(int i = 0; i <= 80; ++i){
946  const double x = .1*i-4;
947  const SystShifts ss(it->first, x);
948  std::unique_ptr<TH1> h(Spectrum(PredictComponentSyst(calc, ss, flav, curr, sign)).ToTH1(18e20));
949 
950  for(int bin = 0; bin < nbins; ++bin){
951  if(i == 0){
952  curves[bin] = new TGraph;
953  points[bin] = new TGraph;
954  }
955 
956  const double ratio = h->GetBinContent(bin+1)/nom->GetBinContent(bin+1);
957 
958  if(!std::isnan(ratio)) curves[bin]->SetPoint(curves[bin]->GetN(), x, ratio);
959  else curves[bin]->SetPoint(curves[bin]->GetN(), x, 1);
960  } // end for bin
961  } // end for i (x)
962 
963  // As elswhere, to allow BirksC etc that need a different nominal to plot
964  // right.
965  IPrediction* pNom = 0;
966  for(unsigned int shiftIdx = 0; shiftIdx < it->second.shifts.size(); ++shiftIdx){
967  if(it->second.shifts[shiftIdx] == 0) pNom = it->second.preds[shiftIdx];
968  }
969  if(pNom){ // if not, probably MinimizeMemory() was called
970  std::unique_ptr<TH1> hnom(Spectrum(pNom->PredictComponent(calc, flav, curr, sign)).ToTH1(18e20));
971 
972  for(unsigned int shiftIdx = 0; shiftIdx < it->second.shifts.size(); ++shiftIdx){
973  if(!it->second.preds[shiftIdx]) continue; // Probably MinimizeMemory()
974  std::unique_ptr<TH1> h;
975  h = std::move(std::unique_ptr<TH1>(Spectrum(it->second.preds[shiftIdx]->PredictComponent(calc, flav, curr, sign)).ToTH1(18e20)));
976 
977  for(int bin = 0; bin < nbins; ++bin){
978  const double ratio = h->GetBinContent(bin+1)/hnom->GetBinContent(bin+1);
979  if(!std::isnan(ratio)) points[bin]->SetPoint(points[bin]->GetN(), it->second.shifts[shiftIdx], ratio);
980  else points[bin]->SetPoint(points[bin]->GetN(), it->second.shifts[shiftIdx], 1);
981  }
982  } // end for shiftIdx
983  } // end if pNom
984 
985 
986  int nx = int(sqrt(nbins));
987  int ny = int(sqrt(nbins));
988  if(nx*ny < nbins) ++nx;
989  if(nx*ny < nbins) ++ny;
990 
991  TCanvas* c = new TCanvas;
992  c->Divide(nx, ny);
993 
994  for(int bin = 0; bin < nbins; ++bin){
995  c->cd(bin+1);
996  (new TH2F("",
997  TString::Format("%s %g < %s < %g;Shift;Ratio",
998  it->second.systName.c_str(),
999  nom->GetXaxis()->GetBinLowEdge(bin+1),
1000  nom->GetXaxis()->GetTitle(),
1001  nom->GetXaxis()->GetBinUpEdge(bin+1)),
1002  100, -4, +4, 100, .5, 1.5))->Draw();
1003  curves[bin]->Draw("l same");
1004  points[bin]->SetMarkerStyle(kFullDotMedium);
1005  points[bin]->Draw("p same");
1006  } // end for bin
1007 
1008  c->cd(0);
1009  }
set< int >::iterator it
T sqrt(T number)
Definition: d0nt_math.hpp:156
Float_t ss
Definition: plot.C:24
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
const int nbins
Definition: cellShifts.C:15
float bin[41]
Definition: plottest35.C:14
def sign(x)
Definition: canMan.py:204
OStream cout
Definition: OStream.cxx:6
string syst
Definition: plotSysts.py:176
recTree Draw("energy.numu.trkccE>>precosmics","fdcuts&&preshutdown")
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
Spectrum PredictComponentSyst(osc::IOscCalculator *calc, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
h
Definition: demo3.py:41
void ana::PredictionInterp::DebugPlotColz ( const ISyst syst,
osc::IOscCalculator calc,
Flavors::Flavors_t  flav = Flavors::kAll,
Current::Current_t  curr = Current::kBoth,
Sign::Sign_t  sign = Sign::kBoth 
) const
inherited

Definition at line 1029 of file PredictionInterp.cxx.

References bin, ana::PredictionInterp::fPredNom, demo3::h, h2, MECModelEnuComparisons::i, ana::PredictionInterp::InitFits(), std::isinf(), std::isnan(), ana::ISyst::LatexName(), nbins, ana::PredictionInterp::PredictComponentSyst(), plotSysts::ratio, ss, and submit_syst::y.

Referenced by ana::PredictionInterp::DebugPlotsColz().

1034  {
1035  InitFits();
1036 
1037  std::unique_ptr<TH1> nom(fPredNom->PredictComponent(calc, flav, curr, sign).ToTH1(18e20));
1038  const int nbins = nom->GetNbinsX();
1039 
1040  TH2* h2 = new TH2F("", (syst->LatexName()+";;#sigma").c_str(),
1041  nbins, nom->GetXaxis()->GetXmin(), nom->GetXaxis()->GetXmax(),
1042  80, -4, +4);
1043  h2->GetXaxis()->SetTitle(nom->GetXaxis()->GetTitle());
1044 
1045  for(int i = 1; i <= 80; ++i){
1046  const double y = h2->GetYaxis()->GetBinCenter(i);
1047  const SystShifts ss(syst, y);
1048  std::unique_ptr<TH1> h(PredictComponentSyst(calc, ss, flav, curr, sign).ToTH1(18e20));
1049 
1050  for(int bin = 0; bin < nbins; ++bin){
1051  const double ratio = h->GetBinContent(bin+1)/nom->GetBinContent(bin+1);
1052 
1053  if(!isnan(ratio) && !isinf(ratio))
1054  h2->Fill(h2->GetXaxis()->GetBinCenter(bin), y, ratio);
1055  } // end for bin
1056  } // end for i (x)
1057 
1058  h2->Draw("colz");
1059  h2->SetMinimum(0.5);
1060  h2->SetMaximum(1.5);
1061  }
int isinf(const stan::math::var &a)
Definition: std_isinf.hpp:16
Float_t ss
Definition: plot.C:24
int isnan(const stan::math::var &a)
Definition: std_isnan.hpp:18
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
const int nbins
Definition: cellShifts.C:15
float bin[41]
Definition: plottest35.C:14
def sign(x)
Definition: canMan.py:204
TH1F * h2
Definition: plot.C:45
string syst
Definition: plotSysts.py:176
Spectrum PredictComponentSyst(osc::IOscCalculator *calc, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
h
Definition: demo3.py:41
void ana::PredictionInterp::DebugPlots ( osc::IOscCalculator calc,
const std::string &  savePattern = "",
Flavors::Flavors_t  flav = Flavors::kAll,
Current::Current_t  curr = Current::kBoth,
Sign::Sign_t  sign = Sign::kBoth 
) const
inherited

Definition at line 1012 of file PredictionInterp.cxx.

References ana::PredictionInterp::DebugPlot(), genie::utils::style::Format(), ana::PredictionInterp::fPreds, and it.

Referenced by check_predinterp(), check_predinterp_numu(), and test_prediction_interp().

1017  {
1018  for(auto& it: fPreds){
1019  DebugPlot(it.first, calc, flav, curr, sign);
1020 
1021  if(!savePattern.empty()){
1022  assert(savePattern.find("%s") != std::string::npos);
1023  gPad->Print(TString::Format(savePattern.c_str(), it.second.systName.c_str()).Data());
1024  }
1025  } // end for it
1026  }
void DebugPlot(const ISyst *syst, osc::IOscCalculator *calc, Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
set< int >::iterator it
def sign(x)
Definition: canMan.py:204
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
void ana::PredictionInterp::DebugPlotsColz ( osc::IOscCalculator calc,
const std::string &  savePattern = "",
Flavors::Flavors_t  flav = Flavors::kAll,
Current::Current_t  curr = Current::kBoth,
Sign::Sign_t  sign = Sign::kBoth 
) const
inherited

Definition at line 1064 of file PredictionInterp.cxx.

References ana::PredictionInterp::DebugPlotColz(), genie::utils::style::Format(), ana::PredictionInterp::fPreds, ana::PredictionInterp::InitFits(), and it.

1069  {
1070  InitFits();
1071 
1072  for(auto it: fPreds){
1073  new TCanvas;
1074  DebugPlotColz(it.first, calc, flav, curr, sign);
1075 
1076  if(!savePattern.empty()){
1077  assert(savePattern.find("%s") != std::string::npos);
1078  gPad->Print(TString::Format(savePattern.c_str(), it.second.systName.c_str()).Data());
1079  }
1080  } // end for it
1081  }
set< int >::iterator it
void DebugPlotColz(const ISyst *syst, osc::IOscCalculator *calc, Flavors::Flavors_t flav=Flavors::kAll, Current::Current_t curr=Current::kBoth, Sign::Sign_t sign=Sign::kBoth) const
def sign(x)
Definition: canMan.py:204
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
void ana::PredictionInterp::Derivative ( osc::IOscCalculator calc,
const SystShifts shift,
double  pot,
std::unordered_map< const ISyst *, std::vector< double >> &  dp 
) const
overridevirtualinherited

Reimplemented from ana::IPrediction.

Definition at line 744 of file PredictionInterp.cxx.

References om::cerr, ana::PredictionInterp::ComponentDerivative(), allTimeWatchdog::endl, ana::PredictionInterp::fPreds, ana::PredictionInterp::InitFits(), it, ana::Flavors::kAll, ana::Sign::kBoth, ana::Current::kCC, ana::Current::kNC, ana::PredictionInterp::kNC, ana::PredictionInterp::kNueApp, ana::PredictionInterp::kNueSurv, ana::Flavors::kNuEToNuE, ana::Flavors::kNuEToNuMu, ana::Flavors::kNuEToNuTau, ana::PredictionInterp::kNumuSurv, ana::Flavors::kNuMuToNuE, ana::Flavors::kNuMuToNuMu, ana::Flavors::kNuMuToNuTau, and ana::PredictionInterp::kOther.

748  {
749  InitFits();
750 
751  // Check that we're able to handle all the systs we were passed
752  for(auto& it: dp){
753  if(fPreds.find(it.first) == fPreds.end()){
754  std::cerr << "This PredictionInterp is not set up to handle the requested systematic: " << it.first->ShortName() << std::endl;
755  abort();
756  }
757  it.second.clear();
758  } // end for syst
759 
763 
767 
769 
770  // Simpler (much slower) implementation in terms of finite differences for
771  // test purposes
772  /*
773  const Spectrum p0 = PredictSyst(calc, shift);
774  TH1D* h0 = p0.ToTH1(pot);
775 
776  const double dx = 1e-9;
777  for(auto& it: dp){
778  const ISyst* s = it.first;
779  std::vector<double>& v = it.second;
780  SystShifts s2 = shift;
781  s2.SetShift(s, s2.GetShift(s)+dx);
782 
783  const Spectrum p1 = PredictSyst(calc, s2);
784 
785  TH1D* h1 = p1.ToTH1(pot);
786 
787  v.resize(h1->GetNbinsX()+2);
788  for(int i = 0; i < h1->GetNbinsX()+2; ++i){
789  v[i] = (h1->GetBinContent(i) - h0->GetBinContent(i))/dx;
790  }
791 
792  HistCache::Delete(h1);
793  }
794 
795  HistCache::Delete(h0);
796  */
797  }
set< int >::iterator it
(&#39; appearance&#39;)
Definition: IPrediction.h:18
(&#39;beam &#39;)
Definition: IPrediction.h:15
OStream cerr
Definition: OStream.cxx:7
void ComponentDerivative(osc::IOscCalculator *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign, CoeffsType type, const SystShifts &shift, double pot, std::unordered_map< const ISyst *, std::vector< double >> &dp) const
Helper for Derivative.
Charged-current interactions.
Definition: IPrediction.h:39
#define pot
(&#39; survival&#39;)
Definition: IPrediction.h:19
Taus, numu appearance.
Neutral-current interactions.
Definition: IPrediction.h:40
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
All neutrinos, any flavor.
Definition: IPrediction.h:26
(&#39; appearance&#39;)
Definition: IPrediction.h:16
std::vector< std::vector< PredictionInterp::Coeffs > > ana::PredictionInterp::FitComponent ( const std::vector< double > &  shifts,
const std::vector< IPrediction * > &  preds,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
inherited

Find coefficients describing the ratios from this component.

Definition at line 198 of file PredictionInterp.cxx.

References om::cout, allTimeWatchdog::endl, ana::PredictionInterp::FitRatios(), ana::PredictionInterp::fOscOrigin, MECModelEnuComparisons::i, ana::IPrediction::PredictComponent(), r(), plotSysts::ratios, and submit_syst::y.

Referenced by ana::PredictionInterp::InitFitsHelper().

203  {
204  IPrediction* pNom = 0;
205  for(unsigned int i = 0; i < shifts.size(); ++i){
206  if(shifts[i] == 0) pNom = preds[i];
207  }
208  assert(pNom);
209 
210  // Do it this way rather than via fPredNom so that systematics evaluated
211  // relative to some alternate nominal (eg Birks C where the appropriate
212  // nominal is no-rock) can work.
213  const Spectrum nom = pNom->PredictComponent(fOscOrigin,
214  flav, curr, sign);
215 
216  std::vector<std::unique_ptr<TH1>> ratios;
217  for(auto& p: preds){
218  ratios.emplace_back(Ratio(p->PredictComponent(fOscOrigin,
219  flav, curr, sign),
220  nom).ToTH1());
221 
222  // Check none of the ratio values is utterly crazy
223  std::unique_ptr<TH1>& r = ratios.back();
224  for(int i = 0; i < r->GetNbinsX()+2; ++i){
225  const double y = r->GetBinContent(i);
226  if(y > 500){
227  std::cout << "PredictionInterp: WARNING, ratio in bin "
228  << i << " is " << y << ". Ignoring." << std::endl;
229  r->SetBinContent(i, 1);
230  }
231  }
232  }
233 
234  return FitRatios(shifts, ratios);
235  }
const char * p
Definition: xmltok.h:285
std::vector< std::vector< Coeffs > > FitRatios(const std::vector< double > &shifts, const std::vector< std::unique_ptr< TH1 >> &ratios) const
Find coefficients describing this set of shifts.
osc::IOscCalculator * fOscOrigin
The oscillation values we assume when evaluating the coefficients.
def sign(x)
Definition: canMan.py:204
OStream cout
Definition: OStream.cxx:6
TRandom3 r(0)
std::vector< std::vector< PredictionInterp::Coeffs > > ana::PredictionInterp::FitRatios ( const std::vector< double > &  shifts,
const std::vector< std::unique_ptr< TH1 >> &  ratios 
) const
inherited

Find coefficients describing this set of shifts.

Definition at line 106 of file PredictionInterp.cxx.

References plot_validation_datamc::c, lem_server::cs, util::cube(), e, stan::math::fabs(), MECModelEnuComparisons::i, m, plotSysts::ratios, res, runNovaSAM::ret, util::sqr(), update_sam_good_runs_metadata::stride, registry_explorer::v, y1, and submit_syst::y2.

Referenced by ana::PredictionInterp::FitComponent(), and ana::PredictionInterp::FitSumComponent().

108  {
109  assert(shifts.size() == ratios.size());
110  std::vector<std::vector<Coeffs>> ret;
111 
112  const int binMax = ratios[0]->GetNbinsX();
113 
114  for(int binIdx = 0; binIdx < binMax+2; ++binIdx){
115  ret.push_back({});
116  // This is cubic interpolation. For each adjacent set of four points we
117  // determine coefficients for a cubic which will be the curve between the
118  // center two. We constrain the function to match the two center points
119  // and to have the right mean gradient at them. This causes this patch to
120  // match smoothly with the next one along. The resulting function is
121  // continuous and first and second differentiable. At the ends of the
122  // range we fit a quadratic instead with only one constraint on the
123  // slope. The coordinate conventions are that point y1 sits at x=0 and y2
124  // at x=1. The matrices are simply the inverses of writing out the
125  // constraints expressed above.
126 
127  // Special-case for linear interpolation
128  if(ratios.size() == 2){
129  const double y0 = ratios[0]->GetBinContent(binIdx);
130  const double y1 = ratios[1]->GetBinContent(binIdx);
131 
132  ret.back().emplace_back(0, 0, y1-y0, y0);
133  continue;
134  }
135 
136  {
137  const double y1 = ratios[0]->GetBinContent(binIdx);
138  const double y2 = ratios[1]->GetBinContent(binIdx);
139  const double y3 = ratios[2]->GetBinContent(binIdx);
140  const double v[3] = {y1, y2, (y3-y1)/2};
141  const double m[9] = { 1, -1, 1,
142  -2, 2, -1,
143  1, 0, 0};
144  const TVectorD res = TMatrixD(3, 3, m) * TVectorD(3, v);
145  ret.back().emplace_back(0, res(0), res(1), res(2));
146  }
147 
148  // We're assuming here that the shifts are separated by exactly 1 sigma.
149  for(unsigned int shiftIdx = 1; shiftIdx < ratios.size()-2; ++shiftIdx){
150  const double y0 = ratios[shiftIdx-1]->GetBinContent(binIdx);
151  const double y1 = ratios[shiftIdx ]->GetBinContent(binIdx);
152  const double y2 = ratios[shiftIdx+1]->GetBinContent(binIdx);
153  const double y3 = ratios[shiftIdx+2]->GetBinContent(binIdx);
154 
155  const double v[4] = {y1, y2, (y2-y0)/2, (y3-y1)/2};
156  const double m[16] = { 2, -2, 1, 1,
157  -3, 3, -2, -1,
158  0, 0, 1, 0,
159  1, 0, 0, 0};
160  const TVectorD res = TMatrixD(4, 4, m) * TVectorD(4, v);
161  ret.back().emplace_back(res(0), res(1), res(2), res(3));
162  } // end for shiftIdx
163 
164  {
165  const int N = ratios.size()-3;
166  const double y0 = ratios[N ]->GetBinContent(binIdx);
167  const double y1 = ratios[N+1]->GetBinContent(binIdx);
168  const double y2 = ratios[N+2]->GetBinContent(binIdx);
169  const double v[3] = {y1, y2, (y2-y0)/2};
170  const double m[9] = {-1, 1, -1,
171  0, 0, 1,
172  1, 0, 0};
173  const TVectorD res = TMatrixD(3, 3, m) * TVectorD(3, v);
174  ret.back().emplace_back(0, res(0), res(1), res(2));
175  }
176  } // end for binIdx
177 
178  double stride = -1;
179  for(unsigned int i = 0; i < shifts.size()-1; ++i){
180  const double newStride = shifts[i+1]-shifts[i];
181  assert((stride < 0 || fabs(stride-newStride) < 1e-3) &&
182  "Variably-spaced syst templates are unsupported");
183  stride = newStride;
184  }
185 
186  // If the stride is actually not 1, need to rescale all the coefficients
187  for(std::vector<Coeffs>& cs: ret)
188  for(Coeffs& c: cs){
189  c = Coeffs(c.a/util::cube(stride),
190  c.b/util::sqr(stride),
191  c.c/stride,
192  c.d);}
193  return ret;
194  }
fvar< T > fabs(const fvar< T > &x)
Definition: fabs.hpp:15
Float_t y1[n_points_granero]
Definition: compare.C:5
T cube(T x)
More efficient cube function than pow(x,3)
Definition: MathUtil.h:26
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
TVectorT< double > TVectorD
Definition: Utilities.h:18
TMatrixT< double > TMatrixD
Definition: Utilities.h:16
Float_t e
Definition: plot.C:35
std::vector< std::vector< PredictionInterp::Coeffs > > ana::PredictionInterp::FitSumComponent ( const std::vector< ShiftedPreds > &  spf,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
protectedinherited

Definition at line 239 of file PredictionInterp.cxx.

References bin, ana::HistCache::Copy(), ana::HistCache::Delete(), ana::PredictionInterp::FitRatios(), ana::PredictionInterp::fOscOrigin, ana::Spectrum::GetBinnings(), chisquared::hpred, MECModelEnuComparisons::i, ana::HistCache::New(), pot, ana::Spectrum::POT(), ana::IPrediction::PredictComponent(), std::sqrt(), and ana::Spectrum::ToTH1().

Referenced by ana::PredictionInterp::InitFitsSumHelper().

243  {
244  IPrediction* pNom = 0;
245  //take 1st one as template
246  std::vector<double> shifts = sps[0].shifts;
247  std::vector<IPrediction*> preds = sps[0].preds;
248 
249  //for now, genie only take +-2
250  assert(shifts[2] == 0 && "PredictionSumInterp only implemented for +-2 shifts");
251 
252  for(unsigned int i = 0; i < shifts.size(); ++i){
253  if(shifts[i] == 0) pNom = preds[i];
254  }
255  assert(pNom);
256 
257  const Spectrum nom = pNom->PredictComponent(fOscOrigin,
258  flav, curr, sign);
259 
260  std::vector<std::unique_ptr<TH1>> sumratios;
261 
262  double pot = nom.POT();
263  const Binning binning = nom.GetBinnings()[0];
264  DontAddDirectory guard;
265  TH1D* hnom = nom.ToTH1(pot);
266  TH1D* hsummed = HistCache::Copy(hnom);
267 
268  double* quads = hsummed->GetArray();
269  int nbin = hnom->GetNbinsX();
270  double* from = hnom->GetArray();
271 
272  for(unsigned int i = 0; i < shifts.size(); i++){
273  for(auto& sp: sps){
274 
275  IPrediction* p = sp.preds[i];
276  // force-convert to _Spectrum<double> since we don't need autodiff here
277  TH1D* hpred = Spectrum(p->PredictComponent(fOscOrigin, flav, curr, sign)).ToTH1(pot);
278 
279  double* to = hpred->GetArray();
280  for(int bin = 0; bin < nbin+2; ++bin){
281  to[bin] -= from[bin];
282  to[bin] *= to[bin];
283  quads[bin] += to[bin];
284  }//end all bins
285  HistCache::Delete(hpred);
286  }//end all systpreds
287 
288  //sqrt of sum of diff
289  for(int bin = 0; bin < nbin+2; ++bin){
290  quads[bin] = sqrt(quads[bin]);
291  if(shifts[i]<0) quads[bin] *= -1.0;
292  quads[bin] += from[bin];
293  quads[bin] /= from[bin];
294  }
295 
296  std::unique_ptr<TH1> hret(HistCache::New("", binning));
297 
298  for( int i = 0; i< nbin+2; ++i){ hret->SetBinContent( i, quads[i]);}
299 
300  sumratios.emplace_back(std::move(hret));
301  } //end shifts
302  HistCache::Delete(hsummed);
303  HistCache::Delete(hnom);
304  return FitRatios(shifts, sumratios);
305  }
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:175
const char * p
Definition: xmltok.h:285
T sqrt(T number)
Definition: d0nt_math.hpp:156
std::vector< std::vector< Coeffs > > FitRatios(const std::vector< double > &shifts, const std::vector< std::unique_ptr< TH1 >> &ratios) const
Find coefficients describing this set of shifts.
static void Delete(TH1D *&h)
Definition: HistCache.cxx:215
#define pot
osc::IOscCalculator * fOscOrigin
The oscillation values we assume when evaluating the coefficients.
float bin[41]
Definition: plottest35.C:14
def sign(x)
Definition: canMan.py:204
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:24
void ana::PredictionInterp::InitFits ( ) const
protectedinherited

Definition at line 338 of file PredictionInterp.cxx.

References ana::Spectrum::Clear(), om::cout, allTimeWatchdog::endl, ana::PredictionInterp::fBinning, ana::PredictionInterp::ShiftedPreds::FillRemaps(), ana::PredictionInterp::ShiftedPreds::fits, ana::PredictionInterp::ShiftedPreds::fitsNubar, ana::PredictionInterp::fOscOrigin, ana::PredictionInterp::fPredNom, ana::PredictionInterp::fPreds, ana::PredictionInterp::fSplitBySign, ana::PredictionInterp::fSummedsp, ana::PredictionInterp::fSumPreds, ana::PredictionInterp::InitFitsHelper(), ana::PredictionInterp::InitFitsSumHelper(), it, ana::Sign::kAntiNu, ana::Sign::kBoth, ana::Sign::kNu, ana::kSummedSyst, ana::Spectrum::Livetime(), ana::PredictionInterp::ShiftedPreds::nCoeffs, ana::Spectrum::POT(), ana::PredictionInterp::ShiftedPreds::shifts, and ana::PredictionInterp::ShiftedPreds::systName.

Referenced by ana::PredictionInterp::_PredictComponentSyst(), ana::PredictionInterp::DebugPlot(), ana::PredictionInterp::DebugPlotColz(), ana::PredictionInterp::DebugPlotsColz(), ana::PredictionInterp::Derivative(), ana::PredictionSystJoint2018::PredictionSystJoint2018(), ana::PredictionSystJointDemo::PredictionSystJointDemo(), ana::PredictionSystNue2017::PredictionSystNue2017(), ana::PredictionSystNueSecondAna::PredictionSystNueSecondAna(), PredictionSystNumu2017(), ana::PredictionInterp::PredictSyst(), ana::PredictionInterp::SaveTo(), and ana::PredictionInterp::SetOscSeed().

339  {
340 
341  // No systs
342  if(fPreds.empty() && fSumPreds.empty()){
343  if(fBinning.POT() > 0 || fBinning.Livetime() > 0) return;
344  }
345  // Already initialized, Summed merged to fPreds
346  else if(!fPreds.empty() && !fPreds.begin()->second.fits.empty()) return;
347 
348  for(auto& it: fPreds){
349  ShiftedPreds& sp = it.second;
350 
351  if(fSplitBySign){
352  InitFitsHelper(sp, sp.fits, Sign::kNu);
353  InitFitsHelper(sp, sp.fitsNubar, Sign::kAntiNu);
354  }
355  else{
356  InitFitsHelper(sp, sp.fits, Sign::kBoth);
357  }
358  sp.nCoeffs = sp.fits[0][0].size();
359 
360  // Copy the outputs into the remapped indexing order. TODO this is very
361  // ugly. Best would be to generate things in this order natively.
362  sp.FillRemaps();
363  }
364 
365  if(!fSumPreds.empty()){
366  std::cout<<"PredictionInterp: Summing "<<fSumPreds.size()<<
367  " systematics..."<<std::endl;
368  std::vector<ShiftedPreds> sp;
369  for(auto& it: fSumPreds) sp.push_back( it.second);
370 
371  fSummedsp.systName = "Summed Syst";
372  fSummedsp.shifts = {-2, -1, 0, 1, 2};
373 
374  if(fSplitBySign){
377  }
378  else{
380  }
381  fSummedsp.nCoeffs = fSummedsp.fits[0][0].size();
382 
383  fPreds.emplace(&kSummedSyst, fSummedsp);
384  }
385 
386  // Predict something, anything, so that we can know what binning to use
387  fBinning = fPredNom->Predict(fOscOrigin);
388  fBinning.Clear();
389  }
set< int >::iterator it
Antineutrinos-only.
Definition: IPrediction.h:50
std::string systName
What systematic we&#39;re interpolating.
std::vector< std::vector< std::vector< Coeffs > > > fitsNubar
Will be filled if signs are separated, otherwise not.
void Clear()
Definition: Spectrum.cxx:878
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
std::vector< double > shifts
Shift values sampled.
osc::IOscCalculator * fOscOrigin
The oscillation values we assume when evaluating the coefficients.
const DummyAnaSyst kSummedSyst("SummedSyst","Summed Syst.")
Spectrum fBinning
Dummy spectrum to provide binning.
std::unordered_map< const ISyst *, ShiftedPreds > fSumPreds
double POT() const
Definition: Spectrum.h:263
Neutrinos-only.
Definition: IPrediction.h:49
OStream cout
Definition: OStream.cxx:6
void InitFitsSumHelper(std::vector< ShiftedPreds > &sps, std::vector< std::vector< std::vector< Coeffs >>> &fits, Sign::Sign_t sign) const
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
void InitFitsHelper(ShiftedPreds &sp, std::vector< std::vector< std::vector< Coeffs >>> &fits, Sign::Sign_t sign) const
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
double Livetime() const
Seconds. For informational purposes only. No calculations use this.
Definition: Spectrum.h:266
std::vector< std::vector< std::vector< Coeffs > > > fits
Indices: [type][histogram bin][shift bin].
void ana::PredictionInterp::InitFitsHelper ( ShiftedPreds sp,
std::vector< std::vector< std::vector< Coeffs >>> &  fits,
Sign::Sign_t  sign 
) const
protectedinherited

Definition at line 308 of file PredictionInterp.cxx.

References ana::PredictionInterp::FitComponent(), fits, ana::Flavors::kAll, ana::Flavors::kAllNuTau, ana::Current::kCC, ana::Current::kNC, ana::PredictionInterp::kNC, ana::PredictionInterp::kNCoeffTypes, ana::PredictionInterp::kNueApp, ana::PredictionInterp::kNueSurv, ana::Flavors::kNuEToNuE, ana::Flavors::kNuEToNuMu, ana::PredictionInterp::kNumuSurv, ana::Flavors::kNuMuToNuE, ana::Flavors::kNuMuToNuMu, ana::PredictionInterp::kOther, ana::PredictionInterp::ShiftedPreds::preds, and ana::PredictionInterp::ShiftedPreds::shifts.

Referenced by ana::PredictionInterp::InitFits().

311  {
312  fits.resize(kNCoeffTypes);
313 
314  fits[kNueApp] = FitComponent(sp.shifts, sp.preds, Flavors::kNuMuToNuE, Current::kCC, sign);
315  fits[kNueSurv] = FitComponent(sp.shifts, sp.preds, Flavors::kNuEToNuE, Current::kCC, sign);
317 
318  fits[kNC] = FitComponent(sp.shifts, sp.preds, Flavors::kAll, Current::kNC, sign);
319 
321  }
(&#39; appearance&#39;)
Definition: IPrediction.h:18
(&#39;beam &#39;)
Definition: IPrediction.h:15
Charged-current interactions.
Definition: IPrediction.h:39
def sign(x)
Definition: canMan.py:204
(&#39; survival&#39;)
Definition: IPrediction.h:19
Taus, numu appearance.
std::vector< std::vector< Coeffs > > FitComponent(const std::vector< double > &shifts, const std::vector< IPrediction * > &preds, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
Find coefficients describing the ratios from this component.
std::vector< std::string > fits
Neutral-current interactions.
Definition: IPrediction.h:40
All neutrinos, any flavor.
Definition: IPrediction.h:26
(&#39; appearance&#39;)
Definition: IPrediction.h:16
void ana::PredictionInterp::InitFitsSumHelper ( std::vector< ShiftedPreds > &  sps,
std::vector< std::vector< std::vector< Coeffs >>> &  fits,
Sign::Sign_t  sign 
) const
protectedinherited

Definition at line 324 of file PredictionInterp.cxx.

References fits, ana::PredictionInterp::FitSumComponent(), ana::Flavors::kAll, ana::Flavors::kAllNuTau, ana::Current::kCC, ana::Current::kNC, ana::PredictionInterp::kNC, ana::PredictionInterp::kNCoeffTypes, ana::PredictionInterp::kNueApp, ana::PredictionInterp::kNueSurv, ana::Flavors::kNuEToNuE, ana::Flavors::kNuEToNuMu, ana::PredictionInterp::kNumuSurv, ana::Flavors::kNuMuToNuE, ana::Flavors::kNuMuToNuMu, and ana::PredictionInterp::kOther.

Referenced by ana::PredictionInterp::InitFits().

327  {
328  fits.resize(kNCoeffTypes);
332 
334 
336  }
(&#39; appearance&#39;)
Definition: IPrediction.h:18
(&#39;beam &#39;)
Definition: IPrediction.h:15
std::vector< std::vector< Coeffs > > FitSumComponent(const std::vector< ShiftedPreds > &spf, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
Charged-current interactions.
Definition: IPrediction.h:39
def sign(x)
Definition: canMan.py:204
(&#39; survival&#39;)
Definition: IPrediction.h:19
Taus, numu appearance.
std::vector< std::string > fits
Neutral-current interactions.
Definition: IPrediction.h:40
All neutrinos, any flavor.
Definition: IPrediction.h:26
(&#39; appearance&#39;)
Definition: IPrediction.h:16
std::unique_ptr< PredictionSystNumu2017 > ana::PredictionSystNumu2017::LoadFrom ( TDirectory *  dir)
static

Definition at line 200 of file PredictionSystNumu2017.cxx.

References ana::kNumu2017NormSystBkg, ana::kNumu2017NormSystBoth, ana::kNumu2017NormSystSig, ana::PredictionInterp::LoadFromBody(), runNovaSAM::ret, and getGoodRuns4SAM::tag.

201  {
202  TObjString* tag = (TObjString*)dir->Get("type");
203  assert(tag);
204 
205  assert(tag->GetString() == "PredictionSystNumu2017");
206 
207  std::unique_ptr<PredictionSystNumu2017> ret(new PredictionSystNumu2017);
209 
210  // Just enable all norm systs unconditionally. Way too hard to do otherwise
212 
213  return ret;
214  }
const DummyNumu2017Syst kNumu2017NormSystSig("numu2017normSig","Sig. Norm.",{0,+1}, false)
const DummyNumu2017Syst kNumu2017NormSystBoth("numu2017NormBoth","Sig+Bkg Norm.",{0,+1}, false)
TDirectory * dir
Definition: macro.C:5
const DummyNumu2017Syst kNumu2017NormSystBkg("numu2017normBkg","Bkg. Norm.",{0,+1}, false)
static void LoadFromBody(TDirectory *dir, PredictionInterp *ret, std::vector< const ISyst * > veto={})
void ana::PredictionInterp::LoadFromBody ( TDirectory *  dir,
PredictionInterp ret,
std::vector< const ISyst * >  veto = {} 
)
staticinherited

Definition at line 864 of file PredictionInterp.cxx.

References genie::utils::style::Format(), ana::PredictionInterp::fOscOrigin, ana::PredictionInterp::fPredNom, ana::PredictionInterp::fPreds, ana::LoadFrom< IPrediction >(), plot_validation_datamc::pred, ana::PredictionInterp::ShiftedPreds::preds, runNovaSAM::release, plotSysts::shift, ana::PredictionInterp::ShiftedPreds::shifts, ana::Registry< T >::ShortNameToPtr(), plotSysts::syst, and ana::PredictionInterp::ShiftedPreds::systName.

Referenced by ana::PredictionSystJoint2018::LoadFrom(), ana::PredictionSystJointDemo::LoadFrom(), ana::PredictionInterp::LoadFrom(), ana::PredictionSystNueSecondAna::LoadFrom(), ana::PredictionSystNue2017::LoadFrom(), and LoadFrom().

866  {
867  ret->fPredNom = ana::LoadFrom<IPrediction>(dir->GetDirectory("pred_nom"));
868 
869  TH1* hSystNames = (TH1*)dir->Get("syst_names");
870  if(hSystNames){
871  for(int systIdx = 0; systIdx < hSystNames->GetNbinsX(); ++systIdx){
872  ShiftedPreds sp;
873  sp.systName = hSystNames->GetXaxis()->GetBinLabel(systIdx+1);
874 
875  auto syst = Registry<ISyst>::ShortNameToPtr(sp.systName);
876 
877  if(std::find(veto.begin(), veto.end(), syst) != veto.end()) continue;
878 
879  for(int shift = -3; shift <= +3; ++shift){
880  TDirectory* preddir = dir->GetDirectory(TString::Format("pred_%s_%+d", sp.systName.c_str(), shift).Data());
881  if(!preddir) continue; // Can happen for genie systs
882 
883  IPrediction* pred = ana::LoadFrom<IPrediction>(preddir).release();
884 
885  sp.shifts.push_back(shift);
886  sp.preds.push_back(pred);
887  } // end for shift
888 
889  ret->fPreds.emplace(syst, sp);
890  } // end for systIdx
891  } // end if hSystNames
892 
893  ret->fOscOrigin = ana::LoadFrom<osc::IOscCalculator>(dir->GetDirectory("osc_origin")).release();
894  }
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir)
Definition: IPrediction.cxx:38
TDirectory * dir
Definition: macro.C:5
string syst
Definition: plotSysts.py:176
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
static const T * ShortNameToPtr(const std::string &s, bool allowFail=false)
Definition: Registry.cxx:60
void ana::PredictionInterp::MinimizeMemory ( )
inherited

After calling this DebugPlots won't work fully and SaveTo won't work at all.

Definition at line 897 of file PredictionInterp.cxx.

References ana::PredictionInterp::fPredNom, ana::PredictionInterp::fPreds, MECModelEnuComparisons::i, and it.

Referenced by ana::PredictionSystJoint2018::PredictionSystJoint2018(), and ana::PredictionSystJointDemo::PredictionSystJointDemo().

898  {
899  std::set<IPrediction*> todel;
900  for(auto& it: fPreds){
901  std::vector<IPrediction*>& preds = it.second.preds;
902  for(unsigned int i = 0; i < preds.size(); ++i){
903  if(preds[i] != fPredNom.get()){
904  todel.insert(preds[i]);
905  preds[i] = 0;
906  }
907  }
908  }
909 
910  for(IPrediction* p: todel) delete p;
911 
912  // We probably just freed up a lot of memory, but malloc by default hangs
913  // on to all of it as cache.
914  #ifndef DARWINBUILD
915  malloc_trim(0);
916  #endif
917  }
set< int >::iterator it
const char * p
Definition: xmltok.h:285
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
Spectrum ana::PredictionInterp::Predict ( osc::IOscCalculator calc) const
overridevirtualinherited
SpectrumStan ana::PredictionInterp::Predict ( osc::IOscCalculatorStan calc) const
overridevirtualinherited

Reimplemented from ana::IPrediction.

Definition at line 405 of file PredictionInterp.cxx.

References ana::PredictionInterp::fPredNom.

406  {
407  return fPredNom->Predict(calc);
408  }
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
Spectrum ana::PredictionInterp::PredictComponent ( osc::IOscCalculator calc,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
overridevirtualinherited

Implements ana::IPrediction.

Definition at line 411 of file PredictionInterp.cxx.

References ana::PredictionInterp::fPredNom.

Referenced by compare_pid_cut_sens(), fa_fd_data_mc_systs(), syst_plot_test(), systematics_table(), and systematics_table_from_pred_interp().

415  {
416  return fPredNom->PredictComponent(calc, flav, curr, sign);
417  }
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
def sign(x)
Definition: canMan.py:204
SpectrumStan ana::PredictionInterp::PredictComponent ( osc::IOscCalculatorStan calc,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
overridevirtualinherited

Reimplemented from ana::IPrediction.

Definition at line 420 of file PredictionInterp.cxx.

References ana::PredictionInterp::fPredNom.

424  {
425  return fPredNom->PredictComponent(calc, flav, curr, sign);
426  }
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
def sign(x)
Definition: canMan.py:204
Spectrum ana::PredictionInterp::PredictComponentSyst ( osc::IOscCalculator calc,
const SystShifts shift,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
overridevirtualinherited
SpectrumStan ana::PredictionInterp::PredictComponentSyst ( osc::IOscCalculatorStan calc,
const SystShifts shift,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
overridevirtualinherited

Reimplemented from ana::IPrediction.

Definition at line 669 of file PredictionInterp.cxx.

References calc, febshutoff_auto::curr, plotSysts::shift, and canMan::sign().

674  {
675  return _PredictComponentSyst<SpectrumStan>(calc, shift, flav, curr, sign);
676  }
osc::OscCalculatorDumb calc
def sign(x)
Definition: canMan.py:204
Spectrum ana::PredictionInterp::PredictSyst ( osc::IOscCalculator calc,
const SystShifts shift 
) const
overridevirtualinherited

Reimplemented from ana::IPrediction.

Definition at line 429 of file PredictionInterp.cxx.

References ana::PredictionInterp::InitFits(), ana::Flavors::kAll, ana::Current::kBoth, ana::Sign::kBoth, and ana::PredictionInterp::PredictComponentSyst().

Referenced by check_predinterp(), check_predinterp_numu(), demo::DrawUpDownRatioCanvas(), mec_tuning(), mec_tuning_fitter_2020(), starPlot(), test_stanfit_systpulls(), and TestPred().

431  {
432  InitFits();
433 
434  return PredictComponentSyst(calc,
435  shift,
438  Sign::kBoth);
439  }
Interactions of both types.
Definition: IPrediction.h:42
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
All neutrinos, any flavor.
Definition: IPrediction.h:26
Spectrum PredictComponentSyst(osc::IOscCalculator *calc, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
SpectrumStan ana::PredictionInterp::PredictSyst ( osc::IOscCalculatorStan calc,
const SystShifts shift 
) const
overridevirtualinherited

Reimplemented from ana::IPrediction.

Definition at line 442 of file PredictionInterp.cxx.

References ana::PredictionInterp::InitFits(), ana::Flavors::kAll, ana::Current::kBoth, ana::Sign::kBoth, and ana::PredictionInterp::PredictComponentSyst().

444  {
445  InitFits();
446 
447  return PredictComponentSyst(calc,
448  shift,
451  Sign::kBoth);
452  }
Interactions of both types.
Definition: IPrediction.h:42
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
All neutrinos, any flavor.
Definition: IPrediction.h:26
Spectrum PredictComponentSyst(osc::IOscCalculator *calc, const SystShifts &shift, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
Spectrum ana::IPrediction::PredictUnoscillated ( ) const
virtualinherited

Reimplemented in ana::PredictionSterile.

Definition at line 82 of file IPrediction.cxx.

References noosc, and ana::IPrediction::Predict().

Referenced by cc(), demo5(), demo::DrawUpDownRatioCanvas(), Efficiency(), efficiency(), efficiencySA(), fa_fd_data_mc_systs(), GetSpectra(), numu_demo_split_plot(), plot_nd_data_mc(), template_basic(), and test_ana().

83  {
84  // Default implementation
86  return Predict(&noosc);
87  }
Pass neutrinos through unchanged.
virtual Spectrum Predict(osc::IOscCalculator *calc) const =0
osc::NoOscillations noosc
Definition: NueSystFuncs.h:44
void ana::PredictionSystNumu2017::SaveTo ( TDirectory *  dir) const
overridevirtual

Reimplemented from ana::PredictionInterp.

Definition at line 217 of file PredictionSystNumu2017.cxx.

References ana::PredictionInterp::SaveTo(), and tmp.

218  {
220 
221  TDirectory* tmp = gDirectory;
222 
223  dir->cd();
224  // Overwrite "IPrediction"
225  TObjString("PredictionSystNumu2017").Write("type");
226 
227  tmp->cd();
228  }
Float_t tmp
Definition: plot.C:36
virtual void SaveTo(TDirectory *dir) const override
TDirectory * dir
Definition: macro.C:5
void ana::PredictionInterp::SetOscSeed ( osc::IOscCalculator oscSeed)
inherited

Definition at line 392 of file PredictionInterp.cxx.

References osc::_IOscCalculator< T >::Copy(), ana::PredictionInterp::fOscOrigin, ana::PredictionInterp::fPreds, ana::PredictionInterp::InitFits(), and it.

392  {
393  fOscOrigin = oscSeed->Copy();
394  for(auto& it: fPreds) it.second.fits.clear();
395  InitFits();
396  }
set< int >::iterator it
virtual _IOscCalculator * Copy() const =0
osc::IOscCalculator * fOscOrigin
The oscillation values we assume when evaluating the coefficients.
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
template<typename T >
void ana::PredictionInterp::ShiftBins ( unsigned int  N,
T arr,
CoeffsType  type,
bool  nubar,
const SystShifts shift 
) const
protectedinherited

Helper for ShiftSpectrum.

Definition at line 484 of file PredictionInterp.cxx.

References ana::PredictionInterp::Coeffs::a, ana::PredictionInterp::Coeffs::b, ana::PredictionInterp::Coeffs::c, calib::corr(), util::cube(), ana::PredictionInterp::Coeffs::d, MakeMiniprodValidationCuts::f, fits, ana::PredictionInterp::ShiftedPreds::fitsNubarRemap, ana::PredictionInterp::ShiftedPreds::fitsRemap, ana::PredictionInterp::fPreds, ana::PredictionInterp::fSplitBySign, ana::SystShifts::GetShift(), MECModelEnuComparisons::i, it, std::max(), std::min(), getGoodRuns4SAM::n, ana::PredictionInterp::ShiftedPreds::nCoeffs, ana::PredictionInterp::ShiftedPreds::shifts, util::sqr(), ana::PredictionInterp::ShiftedPreds::Stride(), plotSysts::syst, T, and submit_syst::x.

Referenced by ana::PredictionInterp::ShiftSpectrum().

489  {
491  "PredictionInterp::ShiftBins() can only be called using doubles or stan::math::vars");
492  if(nubar) assert(fSplitBySign);
493 
494  T corr[N];
495  for(unsigned int i = 0; i < N; ++i) corr[i] = 1;
496 
497  for(auto& it: fPreds){
498  const ISyst* syst = it.first;
499  const ShiftedPreds& sp = it.second;
500 
501  T x = shift.GetShift<T>(syst);
502 
503  // need to actually do the calculation for the autodiff version
504  // to make sure the gradient is computed correctly
505  if(x == 0 && !std::is_same<T, stan::math::var>::value) continue;
506 
507  int shiftBin = (util::GetValAs<double>(x) - sp.shifts[0])/sp.Stride();
508  shiftBin = std::max(0, shiftBin);
509  shiftBin = std::min(shiftBin, sp.nCoeffs-1);
510 
511  const Coeffs* fits = nubar ? &sp.fitsNubarRemap[type][shiftBin].front() : &sp.fitsRemap[type][shiftBin].front();
512 
513  x -= sp.shifts[shiftBin];
514 
515  const T x_cube = util::cube(x);
516  const T x_sqr = util::sqr(x);
517 
518  for(unsigned int n = 0; n < N; ++n){
519  // Uncomment to debug crashes in this function
520  // assert(type < fits.size());
521  // assert(n < sp.fits[type].size());
522  // assert(shiftBin < int(sp.fits[type][n].size()));
523 
524  const Coeffs& f = fits[n];
525 
526  corr[n] *= f.a*x_cube + f.b*x_sqr + f.c*x + f.d;
527  } // end for n
528  } // end for syst
529 
530  for(unsigned int n = 0; n < N; ++n){
531  // std::max() doesn't work with stan::math::var
532  arr[n] *= (corr[n] > 0.) ? corr[n] : 0.;
533  }
534 
535  }
T max(const caf::Proxy< T > &a, T b)
set< int >::iterator it
double corr(TGraph *g, double thresh)
T cube(T x)
More efficient cube function than pow(x,3)
Definition: MathUtil.h:26
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
::xsd::cxx::tree::type type
Definition: Database.h:110
const XML_Char int const XML_Char * value
Definition: expat.h:331
string syst
Definition: plotSysts.py:176
std::vector< std::string > fits
double T
Definition: Xdiff_gwt.C:5
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
T min(const caf::Proxy< T > &a, T b)
Spectrum ana::PredictionInterp::ShiftedComponent ( osc::IOscCalculator calc,
const TMD5 *  hash,
const SystShifts shift,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign,
CoeffsType  type 
) const
inherited

Helper for PredictComponentSyst.

Definition at line 538 of file PredictionInterp.cxx.

References calc, febshutoff_auto::curr, samweb_client.utility::hash, plotSysts::shift, and canMan::sign().

Referenced by ana::PredictionInterp::_PredictComponentSyst(), and ana::PredictionInterp::_ShiftedComponent().

545  {
546  return _ShiftedComponent<Spectrum>(calc, hash, shift, flav, curr, sign, type);
547  }
osc::OscCalculatorDumb calc
::xsd::cxx::tree::type type
Definition: Database.h:110
def sign(x)
Definition: canMan.py:204
SpectrumStan ana::PredictionInterp::ShiftedComponent ( osc::_IOscCalculator< stan::math::var > *  calc,
const TMD5 *  hash,
const SystShifts shift,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign,
CoeffsType  type 
) const
inherited

Definition at line 550 of file PredictionInterp.cxx.

References calc, febshutoff_auto::curr, samweb_client.utility::hash, plotSysts::shift, and canMan::sign().

557  {
558  return _ShiftedComponent<SpectrumStan>(calc, hash, shift, flav, curr, sign, type);
559  }
osc::OscCalculatorDumb calc
::xsd::cxx::tree::type type
Definition: Database.h:110
def sign(x)
Definition: canMan.py:204
Spectrum ana::PredictionInterp::ShiftSpectrum ( const Spectrum s,
CoeffsType  type,
bool  nubar,
const SystShifts shift 
) const
inherited

Definition at line 455 of file PredictionInterp.cxx.

References ana::Spectrum::GetBinnings(), ana::Spectrum::GetLabels(), demo3::h, ana::Spectrum::Livetime(), ana::Spectrum::POT(), plotSysts::shift, ana::PredictionInterp::ShiftBins(), and ana::Spectrum::ToTH1().

Referenced by ana::PredictionInterp::_ShiftedComponent().

459  {
460  // TODO histogram operations could be too slow
461  TH1D *h = s.ToTH1(s.POT());
462 
463  ShiftBins(h->GetNbinsX()+2, h->GetArray(), type, nubar, shift);
464 
465  return Spectrum(std::unique_ptr<TH1D>(h), s.GetLabels(), s.GetBinnings(), s.POT(), s.Livetime());
466  }
void ShiftBins(unsigned int N, T *arr, CoeffsType type, bool nubar, const SystShifts &shift) const
Helper for ShiftSpectrum.
::xsd::cxx::tree::type type
Definition: Database.h:110
const XML_Char * s
Definition: expat.h:262
h
Definition: demo3.py:41
SpectrumStan ana::PredictionInterp::ShiftSpectrum ( const SpectrumStan s,
CoeffsType  type,
bool  nubar,
const SystShifts shift 
) const
inherited

Definition at line 469 of file PredictionInterp.cxx.

References ana::SpectrumStan::GetBinnings(), ana::SpectrumStan::GetLabels(), ana::SpectrumStan::Livetime(), ana::SpectrumStan::POT(), plotSysts::shift, ana::PredictionInterp::ShiftBins(), and ana::SpectrumStan::ToBins().

473  {
474 
475  auto binContents = s.ToBins(s.POT());
476 
477  ShiftBins(binContents.size(), &binContents.front(), type, nubar, shift);
478 
479  return SpectrumStan(std::move(binContents), s.GetLabels(), s.GetBinnings(), s.POT(), s.Livetime());
480  }
void ShiftBins(unsigned int N, T *arr, CoeffsType type, bool nubar, const SystShifts &shift) const
Helper for ShiftSpectrum.
::xsd::cxx::tree::type type
Definition: Database.h:110
const XML_Char * s
Definition: expat.h:262
bool ana::PredictionInterp::SplitBySign ( ) const
inlineinherited

Definition at line 126 of file PredictionInterp.h.

126 {return fSplitBySign;}

Member Data Documentation

Spectrum ana::PredictionInterp::fBinning
mutableprotectedinherited

Dummy spectrum to provide binning.

Definition at line 223 of file PredictionInterp.h.

Referenced by ana::PredictionInterp::_PredictComponentSyst(), and ana::PredictionInterp::InitFits().

std::map<Key_t, Val_t> ana::PredictionInterp::fNomCache
mutableprotectedinherited

Definition at line 241 of file PredictionInterp.h.

Referenced by ana::PredictionInterp::_ShiftedComponent().

osc::IOscCalculator* ana::PredictionInterp::fOscOrigin
protectedinherited
std::unique_ptr<IPrediction> ana::PredictionInterp::fPredNom
protectedinherited
std::unordered_map<const ISyst*, ShiftedPreds> ana::PredictionInterp::fPreds
mutableprotectedinherited
bool ana::PredictionInterp::fSplitBySign
protectedinherited
ShiftedPreds ana::PredictionInterp::fSummedsp
mutableprotectedinherited
std::unordered_map<const ISyst*, ShiftedPreds> ana::PredictionInterp::fSumPreds
mutableprotectedinherited

The documentation for this class was generated from the following files: