MECTuningUtils.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "CAFAna/Core/Loaders.h"
4 #include "TObjString.h"
5 
6 namespace jw
7 {
8  // this thing basically needs to be an IPrediction that gives
9  // the correct components of the spectrum.
10  // or at least have a PredictComponent() that can do
11  // (Flavors::kAll, Current::kBoth, Sign::kBoth)
12  // when asked, since that's the one that you need
13  // to get PredictSyst() to work.
15  {
16  public:
18  const ana::HistAxis& axis,
19  const ana::Cut& cut,
20  const ana::SystShifts& shift = ana::kNoShift,
21  const ana::Var& wei = ana::kUnweighted)
22  : fSpec(loaders.GetLoader(caf::kNEARDET, ana::Loaders::kMC),
23  axis, cut, shift, wei)
24  {};
25 
27  : fSpec(spec)
28  {};
29 
30  ana::Spectrum Predict(osc::IOscCalc* calc) const override;
31 
35  ana::Sign::Sign_t sign) const override;
36 
37  void SaveTo(TDirectory* dir, const std::string& name) const override;
38  static std::unique_ptr<TrivialPrediction> LoadFrom(TDirectory* dir, const std::string& name);
39 
40 
41  private:
43  };
45  {
46  return fSpec;
47  }
51  ana::Sign::Sign_t sign) const
52  {
53  // basically the whole prediction is regarded as being one component
54  if (flav == ana::Flavors::kNuMuToNuMu && curr == ana::Current::kCC && sign == ana::Sign::kBoth)
55  {
56  return fSpec;
57  }
58  else
59  {
60  auto spec = ana::Spectrum(fSpec);
61  spec.Clear();
62  return std::move(spec);
63  }
64  }
65  void TrivialPrediction::SaveTo(TDirectory* dir, const std::string& name) const
66  {
67  TDirectory* tmp = gDirectory;
68 
69  dir = dir->mkdir(name.c_str()); // switch to subdir
70  dir->cd();
71 
72  TObjString("TrivialPrediction").Write("type", TObject::kOverwrite);
73  fSpec.SaveTo(dir, "spec");
74 
75  dir->Write();
76  delete dir;
77 
78  tmp->cd();
79  }
80  std::unique_ptr<TrivialPrediction> TrivialPrediction::LoadFrom(TDirectory* dir, const std::string& name)
81  {
82  dir = dir->GetDirectory(name.c_str()); // switch to subdir
83  assert(dir);
84 
85  return std::make_unique<TrivialPrediction>(*ana::Spectrum::LoadFrom(dir, "spec"));
86  }
87 
88  //----------------------------------------------------------------------
89 
91  {
92  public:
94  : fAxis(axis), fCut(cut), fWei(wei)
95  {};
96 
97  virtual ~NDPredGenerator() {};
98 
99  std::unique_ptr<ana::IPrediction> Generate(
101  const ana::SystShifts& shiftMC = ana::kNoShift ) const override;
102 
103  private:
105  const ana::Cut fCut;
106  const ana::Var fWei;
107  };
108  std::unique_ptr<ana::IPrediction> NDPredGenerator::Generate(
110  const ana::SystShifts& shiftMC ) const
111  {
112  return std::unique_ptr<ana::IPrediction>( new TrivialPrediction(
113  loaders, fAxis, fCut, shiftMC, fWei ) );
114  }
115 
116 
117 }
const ana::Cut fCut
const XML_Char * name
Definition: expat.h:151
const ana::Var fWei
const ana::HistAxis fAxis
std::unique_ptr< ana::IPrediction > Generate(ana::Loaders &loaders, const ana::SystShifts &shiftMC=ana::kNoShift) const override
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
ana::Spectrum Predict(osc::IOscCalc *calc) const override
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
General interface to oscillation calculators.
Definition: StanTypedefs.h:22
const Color_t kMC
Float_t tmp
Definition: plot.C:36
TrivialPrediction(const ana::Spectrum &spec)
osc::OscCalcDumb calc
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
void SaveTo(TDirectory *dir, const std::string &name) const override
Charged-current interactions.
Definition: IPrediction.h:39
virtual ~NDPredGenerator()
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:546
NDPredGenerator(const ana::HistAxis axis, const ana::Cut cut, const ana::Var wei=ana::kUnweighted)
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
std::vector< float > Spectrum
Definition: Constants.h:570
const SystShifts kNoShift
Definition: SystShifts.cxx:21
(&#39; survival&#39;)
Definition: IPrediction.h:19
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
const Cut cut
Definition: exporter_fd.C:30
TrivialPrediction(ana::Loaders &loaders, const ana::HistAxis &axis, const ana::Cut &cut, const ana::SystShifts &shift=ana::kNoShift, const ana::Var &wei=ana::kUnweighted)
TDirectory * dir
Definition: macro.C:5
std::vector< Loaders * > loaders
Definition: syst_header.h:386
assert(nhit_max >=nhit_nbins)
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
Given loaders and an MC shift, Generate() generates an IPrediction.
This module creates Common Analysis Files.
Definition: FileReducer.h:10
static std::unique_ptr< TrivialPrediction > LoadFrom(TDirectory *dir, const std::string &name)
ana::Spectrum PredictComponent(osc::IOscCalc *calc, ana::Flavors::Flavors_t flav, ana::Current::Current_t curr, ana::Sign::Sign_t sign) const override
const Var kUnweighted
The simplest possible Var, always 1. Used as a default weight.
Definition: Var.h:96
def sign(x)
Definition: canMan.py:197