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

Implements systematic errors by interpolation between shifted templates. More...

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

Inheritance diagram for ana::PredictionInterp:
ana::IPrediction ana::PredictionInterpTemplates ana::PredictionSystJoint2018 ana::PredictionSystJointDemo ana::PredictionSystNue2017 ana::PredictionSystNueSecondAna ana::PredictionSystNumu2017

Classes

struct  Coeffs
 
struct  Key_t
 
struct  ShiftedPreds
 
struct  Val_t
 

Public Types

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

Public Member Functions

 PredictionInterp (std::vector< const ISyst * > systs, osc::IOscCalculator *osc, const IPredictionGenerator &predGen, Loaders &loaders, const SystShifts &shiftMC=kNoShift, EMode_t mode=kCombineSigns)
 
virtual ~PredictionInterp ()
 
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
 
virtual void SaveTo (TDirectory *dir) 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
 
 PredictionInterp ()
 
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< PredictionInterpLoadFrom (TDirectory *dir)
 
static void LoadFromBody (TDirectory *dir, PredictionInterp *ret, std::vector< const ISyst * > veto={})
 

Protected Member Functions

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

Implements systematic errors by interpolation between shifted templates.

Definition at line 28 of file PredictionInterp.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::PredictionInterp::PredictionInterp ( std::vector< const ISyst * >  systs,
osc::IOscCalculator osc,
const IPredictionGenerator predGen,
Loaders loaders,
const SystShifts shiftMC = kNoShift,
EMode_t  mode = kCombineSigns 
)
Parameters
systsWhat systematics we should be capable of interpolating
oscThe oscillation point to expand around
predGenConstruct an IPrediction from the following information.
loadersThe loaders to be passed on to the underlying prediction
shiftMCUnderlying shift. Use with care. Mostly for PredictionNumuFAHadE. Should not contain any of of systs
modeIn FHC the wrong-sign has bad stats and probably the fits can't be split out reasonably. For RHC it's important not to conflate them.

Definition at line 62 of file PredictionInterp.cxx.

References fPredNom, fPreds, fSplitBySign, kSplitBySign, loaders, ana::SystShifts::SetShift(), ana::PredictionInterp::ShiftedPreds::shifts, plotSysts::syst, ana::PredictionInterp::ShiftedPreds::systName, and systs.

68  : fOscOrigin(osc ? osc->Copy() : 0),
69  fBinning(0, {}, {}, 0, 0),
71  {
72  for(const ISyst* syst: systs){
73  ShiftedPreds sp;
74  sp.systName = syst->ShortName();
75 
76  // Genie reweight shifts aren't able to provide +/-3 sigma
77  if(syst->IsGenieReweight())
78  sp.shifts = {-2, -1, 0, +1, +2};
79  else
80  sp.shifts = {-3, -2, -1, 0, +1, +2, +3};
81 
82  for(int sigma: sp.shifts){
83  SystShifts shiftHere = shiftMC;
84  shiftHere.SetShift(syst, sigma);
85  sp.preds.push_back(predGen.Generate(loaders, shiftHere).release());
86  }
87 
88  fPreds.emplace(syst, sp);
89  } // end for syst
90 
91  fPredNom = predGen.Generate(loaders, shiftMC);
92  }
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.
Spectrum fBinning
Dummy spectrum to provide binning.
std::vector< Loaders * > loaders
Definition: syst_header.h:385
string syst
Definition: plotSysts.py:176
std::unordered_map< const ISyst *, ShiftedPreds > fPreds
ana::PredictionInterp::~PredictionInterp ( )
virtual

Definition at line 95 of file PredictionInterp.cxx.

References fPredNom.

96  {
97  // for(auto it: fPreds) for(IPrediction* p: it.second.preds) delete p;
98  // delete fOscOrigin;
99 
100  // It isn't really a unique ptr when we use PredictionInterpTemplates
101  fPredNom.release();
102  }
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
ana::PredictionInterp::PredictionInterp ( )
inline

Definition at line 133 of file PredictionInterp.h.

References dir, and runNovaSAM::ret.

133 : fOscOrigin(nullptr), fBinning(0, {}, {}, 0, 0), fSplitBySign(false) {}
osc::IOscCalculator * fOscOrigin
The oscillation values we assume when evaluating the coefficients.
Spectrum fBinning
Dummy spectrum to provide binning.

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
protected

Templated helper for PredictComponentSyst.

Definition at line 615 of file PredictionInterp.cxx.

References ana::SystShifts::ActiveSysts(), om::cerr, ana::Spectrum::Clear(), allTimeWatchdog::endl, fBinning, fPreds, osc::_IOscCalculator< T >::GetParamsHash(), samweb_client.utility::hash, InitFits(), ana::Flavors::kAll, ana::Current::kCC, ana::Current::kNC, kNC, kNueApp, kNueSurv, ana::Flavors::kNuEToNuE, ana::Flavors::kNuEToNuMu, ana::Flavors::kNuEToNuTau, kNumuSurv, ana::Flavors::kNuMuToNuE, ana::Flavors::kNuMuToNuMu, ana::Flavors::kNuMuToNuTau, kOther, runNovaSAM::ret, 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
protected

Templated helper for ShiftedComponent.

Definition at line 563 of file PredictionInterp.cxx.

References febshutoff_auto::curr, fNomCache, fPredNom, fSplitBySign, samweb_client.utility::hash, it, ana::Sign::kAntiNu, ana::Sign::kBoth, findDuplicateFiles::key, ana::Sign::kNu, ShiftedComponent(), and 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
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
protected

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, fPreds, fSplitBySign, ana::SystShifts::GetShift(), demo3::h, it, ana::Sign::kAntiNu, ana::Sign::kBoth, ana::Sign::kNu, std::max(), std::min(), getGoodRuns4SAM::n, PredictComponentSyst(), util::sqr(), plotSysts::syst, ana::Spectrum::ToTH1(), and submit_syst::x.

Referenced by 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

Definition at line 920 of file PredictionInterp.cxx.

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

Referenced by 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

Definition at line 1029 of file PredictionInterp.cxx.

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

Referenced by 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

Definition at line 1012 of file PredictionInterp.cxx.

References DebugPlot(), genie::utils::style::Format(), 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

Definition at line 1064 of file PredictionInterp.cxx.

References DebugPlotColz(), genie::utils::style::Format(), fPreds, 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
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 744 of file PredictionInterp.cxx.

References om::cerr, ComponentDerivative(), allTimeWatchdog::endl, fPreds, InitFits(), it, ana::Flavors::kAll, ana::Sign::kBoth, ana::Current::kCC, ana::Current::kNC, kNC, kNueApp, kNueSurv, ana::Flavors::kNuEToNuE, ana::Flavors::kNuEToNuMu, ana::Flavors::kNuEToNuTau, kNumuSurv, ana::Flavors::kNuMuToNuE, ana::Flavors::kNuMuToNuMu, ana::Flavors::kNuMuToNuTau, and 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

Find coefficients describing the ratios from this component.

Definition at line 198 of file PredictionInterp.cxx.

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

Referenced by 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

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 FitComponent(), and 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
protected

Definition at line 239 of file PredictionInterp.cxx.

References bin, ana::HistCache::Copy(), ana::HistCache::Delete(), FitRatios(), 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 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
protected

Definition at line 338 of file PredictionInterp.cxx.

References ana::Spectrum::Clear(), om::cout, allTimeWatchdog::endl, fBinning, ana::PredictionInterp::ShiftedPreds::FillRemaps(), ana::PredictionInterp::ShiftedPreds::fits, ana::PredictionInterp::ShiftedPreds::fitsNubar, fOscOrigin, fPredNom, fPreds, fSplitBySign, fSummedsp, fSumPreds, InitFitsHelper(), 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 _PredictComponentSyst(), DebugPlot(), DebugPlotColz(), DebugPlotsColz(), Derivative(), ana::PredictionSystJoint2018::PredictionSystJoint2018(), ana::PredictionSystJointDemo::PredictionSystJointDemo(), ana::PredictionSystNue2017::PredictionSystNue2017(), ana::PredictionSystNueSecondAna::PredictionSystNueSecondAna(), ana::PredictionSystNumu2017::PredictionSystNumu2017(), PredictSyst(), SaveTo(), and 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
protected

Definition at line 308 of file PredictionInterp.cxx.

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

Referenced by 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
protected

Definition at line 324 of file PredictionInterp.cxx.

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

Referenced by 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< PredictionInterp > ana::PredictionInterp::LoadFrom ( TDirectory *  dir)
static

Definition at line 845 of file PredictionInterp.cxx.

References LoadFromBody(), runNovaSAM::ret, and getGoodRuns4SAM::tag.

Referenced by CalcRWithSystsNus17(), FCContour(), futureSig_reach_singlePOTcombo_syst(), genie_contours(), get_sa_syst_mags(), get_sa_systs_mags_v2(), get_univ_chisq(), getHists_FNEX(), joint_fit_make_experiments(), joint_fit_make_fc_slice(), joint_fit_make_fc_surf(), ana::LoadFrom< IPrediction >(), LoadPrediction(), make_fc_points(), make_nus17_fc_surfs(), make_nus_fc_surfs(), makeMatrixElementSurface(), plot_extrap_syst_fa(), plot_sa_results(), plot_sa_results_nodata(), PlotNus17PredSystsData(), and PlotNusSensAna01().

846  {
847  TObjString* tag = (TObjString*)dir->Get("type");
848  assert(tag);
849  assert(tag->GetString() == "PredictionInterp" ||
850  tag->GetString() == "PredictionInterp2"); // backwards compatibility
851 
852  auto ret = std::make_unique<PredictionInterp>();
853 
854  LoadFromBody(dir, ret.get());
855 
856  TObjString* split_sign = (TObjString*)dir->Get("split_sign");
857  // Can be missing from old files
858  ret->fSplitBySign = (split_sign && split_sign->String() == "yes");
859 
860  return ret;
861  }
TDirectory * dir
Definition: macro.C:5
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 = {} 
)
static

Definition at line 864 of file PredictionInterp.cxx.

References genie::utils::style::Format(), fOscOrigin, fPredNom, 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(), LoadFrom(), ana::PredictionSystNueSecondAna::LoadFrom(), ana::PredictionSystNue2017::LoadFrom(), and ana::PredictionSystNumu2017::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 ( )

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

Definition at line 897 of file PredictionInterp.cxx.

References fPredNom, 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
overridevirtual
SpectrumStan ana::PredictionInterp::Predict ( osc::IOscCalculatorStan calc) const
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 405 of file PredictionInterp.cxx.

References 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
overridevirtual

Implements ana::IPrediction.

Definition at line 411 of file PredictionInterp.cxx.

References 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
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 420 of file PredictionInterp.cxx.

References 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
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 659 of file PredictionInterp.cxx.

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

Referenced by check_predinterp(), check_predinterp_numu(), ComponentDerivative(), DebugPlot(), DebugPlotColz(), plot_datamcpred(), PredictSyst(), systematics_table(), and systematics_table_from_pred_interp().

664  {
665  return _PredictComponentSyst<Spectrum>(calc, shift, flav, curr, sign);
666  }
osc::OscCalculatorDumb calc
def sign(x)
Definition: canMan.py:204
SpectrumStan ana::PredictionInterp::PredictComponentSyst ( osc::IOscCalculatorStan calc,
const SystShifts shift,
Flavors::Flavors_t  flav,
Current::Current_t  curr,
Sign::Sign_t  sign 
) const
overridevirtual

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
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 429 of file PredictionInterp.cxx.

References InitFits(), ana::Flavors::kAll, ana::Current::kBoth, ana::Sign::kBoth, and 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
overridevirtual

Reimplemented from ana::IPrediction.

Definition at line 442 of file PredictionInterp.cxx.

References InitFits(), ana::Flavors::kAll, ana::Current::kBoth, ana::Sign::kBoth, and 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::PredictionInterp::SaveTo ( TDirectory *  dir) const
overridevirtual

Reimplemented from ana::IPrediction.

Reimplemented in ana::PredictionSystNumu2017, ana::PredictionSystNue2017, ana::PredictionSystNueSecondAna, ana::PredictionSystJointDemo, and ana::PredictionSystJoint2018.

Definition at line 800 of file PredictionInterp.cxx.

References om::cout, allTimeWatchdog::endl, genie::utils::style::Format(), fOscOrigin, fPredNom, fPreds, fSplitBySign, MECModelEnuComparisons::i, InitFits(), makeTrainCVSamples::int, it, ana::PredictionInterp::ShiftedPreds::preds, ana::SaveTo(), ana::PredictionInterp::ShiftedPreds::shifts, ana::PredictionInterp::ShiftedPreds::systName, and tmp.

Referenced by extrap_syst_fa(), FDDataMCSystBandLoad(), getPredictions(), getPredictions_updatedAna(), joint_fit_make_sa_pred_numu(), make_nue_fd_datamc(), make_nue_firstana_extrap(), make_prediction_rhc(), make_sa_pred(), MakeCovarSim(), MakeNus17PredictionSysts(), MakeNusPredictionSystsAna01(), makePred(), mec_tuning_preds_2020(), saTestContours(), SavePrediction(), savePrediction_complete(), savePrediction_extrap(), savePrediction_systs(), ana::PredictionSystJoint2018::SaveTo(), ana::PredictionSystJointDemo::SaveTo(), ana::PredictionSystNueSecondAna::SaveTo(), ana::PredictionSystNue2017::SaveTo(), and ana::PredictionSystNumu2017::SaveTo().

801  {
802  InitFits();
803 
804  TDirectory* tmp = gDirectory;
805 
806  dir->cd();
807  TObjString("PredictionInterp").Write("type");
808 
809 
810  fPredNom->SaveTo(dir->mkdir("pred_nom"));
811 
812 
813  for(auto it: fPreds){
814  const ShiftedPreds& sp = it.second;
815 
816  for(unsigned int i = 0; i < sp.shifts.size(); ++i){
817  if(!sp.preds[i]){
818  std::cout << "Can't save a PredictionInterp after MinimizeMemory()" << std::endl;
819  abort();
820  }
821  sp.preds[i]->SaveTo(dir->mkdir(TString::Format("pred_%s_%+d",
822  sp.systName.c_str(),
823  int(sp.shifts[i])).Data()));
824  } // end for i
825  } // end for it
826 
827  ana::SaveTo(*fOscOrigin, dir->mkdir("osc_origin"));
828 
829  if(!fPreds.empty()){
830  TH1F hSystNames("syst_names", ";Syst names", fPreds.size(), 0, fPreds.size());
831  int binIdx = 1;
832  for(auto it: fPreds){
833  hSystNames.GetXaxis()->SetBinLabel(binIdx++, it.second.systName.c_str());
834  }
835  hSystNames.Write("syst_names");
836  }
837 
838  TObjString split_sign = fSplitBySign ? "yes" : "no";
839  split_sign.Write("split_sign");
840 
841  tmp->cd();
842  }
set< int >::iterator it
Float_t tmp
Definition: plot.C:36
std::unique_ptr< IPrediction > fPredNom
The nominal prediction.
void SaveTo(const osc::IOscCalculator &x, TDirectory *dir)
osc::IOscCalculator * fOscOrigin
The oscillation values we assume when evaluating the coefficients.
OStream cout
Definition: OStream.cxx:6
TDirectory * dir
Definition: macro.C:5
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::SetOscSeed ( osc::IOscCalculator oscSeed)

Definition at line 392 of file PredictionInterp.cxx.

References osc::_IOscCalculator< T >::Copy(), fOscOrigin, fPreds, 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
protected

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, fPreds, 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 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

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 _PredictComponentSyst(), and _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

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

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, ShiftBins(), and ana::Spectrum::ToTH1().

Referenced by _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

Definition at line 469 of file PredictionInterp.cxx.

References ana::SpectrumStan::GetBinnings(), ana::SpectrumStan::GetLabels(), ana::SpectrumStan::Livetime(), ana::SpectrumStan::POT(), plotSysts::shift, 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
inline

Definition at line 126 of file PredictionInterp.h.

126 {return fSplitBySign;}

Member Data Documentation

Spectrum ana::PredictionInterp::fBinning
mutableprotected

Dummy spectrum to provide binning.

Definition at line 223 of file PredictionInterp.h.

Referenced by _PredictComponentSyst(), and InitFits().

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

Definition at line 241 of file PredictionInterp.h.

Referenced by _ShiftedComponent().

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

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