NDPredictionNoOsc.cxx
Go to the documentation of this file.
2 
5 #include "CAFAna/Core/Spectrum.h"
6 #include "CAFAna/Core/Ratio.h"
12 #include "OscLib/IOscCalc.h"
13 #include "OscLib/OscCalcSterile.h"
14 
15 #include "TDirectory.h"
16 #include "TH1.h"
17 #include "TH2.h"
18 #include "TObjString.h"
19 
20 using std::make_unique;
21 using std::move;
22 using std::string;
23 using std::unique_ptr;
24 using std::vector;
25 
26 using osc::IOscCalc;
27 
28 namespace ana {
29 
30  REGISTER_LOADFROM("NDPredictionNoOsc", IPrediction, NDPredictionNoOsc);
31 
32  //----------------------------------------------------------------------
35  const HistAxis& axis,
36  const Cut& selection,
37  const SystShifts& shiftMC,
38  const Var& weight
39  )
40  {
42  loaders.GetLoader(
44  //loaders.GetLoader(
45  // caf::kNEARDET, Loaders::kMC, ana::kBeam, Loaders::kFluxSwap),
46  axis,
47  selection,
48  shiftMC,
49  weight
50  );
51  }
52 
54  SpectrumLoaderBase& nonswap,
55  //SpectrumLoaderBase& swap,
56  const HistAxis& axis,
57  const Cut& selection,
58  const SystShifts& shiftMC,
59  const Var& weight)
60  {
61  NDPredictionNoOsc extrap(nonswap, axis, selection, shiftMC, weight);
62  return extrap;
63  }
64 
65  //----------------------------------------------------------------------
66  NDPredictionNoOsc::NDPredictionNoOsc(vector<unique_ptr<Spectrum>>& spectra)
67  {
68  fSpecCCNuMu = move(spectra[0]);
69  fSpecCCNuE = move(spectra[1]);
70  fSpecCCAntiNuMu = move(spectra[2]);
71  fSpecCCAntiNuE = move(spectra[3]);
72 
73  fSpecNCNuMu = move(spectra[4]);
74  fSpecNCNuE = move(spectra[5]);
75  fSpecNCAntiNuMu = move(spectra[6]);
76  fSpecNCAntiNuE = move(spectra[7]);
77  }
78 
79  //----------------------------------------------------------------------
81  {
82 
83  Spectrum ret = *(fSpecCCNuMu.get());
84 
85  // Adding up the other components
86  ret += *(fSpecCCNuE.get());
87  ret += *(fSpecCCAntiNuMu.get());
88  ret += *(fSpecCCAntiNuE.get());
89 
90  ret += *(fSpecNCNuMu.get());
91  ret += *(fSpecNCNuE.get());
92  ret += *(fSpecNCAntiNuMu.get());
93  ret += *(fSpecNCAntiNuE.get());
94 
95  return ret;
96  }
97 
98  //----------------------------------------------------------------------
100  Flavors::Flavors_t flav,
102  Sign::Sign_t sign) const
103  {
104 
105  Spectrum ret = *(fSpecCCNuMu.get());
106  ret.Clear();
107 
108  // Here we also add up predictions - BUT we should check whether the
109  // user requested them first!
110  if(curr & Current::kCC) {
111  if(flav & Flavors::kNuEToNuE && sign & Sign::kNu) ret += *(fSpecCCNuE.get());
112  if(flav & Flavors::kNuEToNuE && sign & Sign::kAntiNu) ret += *(fSpecCCAntiNuE.get());
113 
114  if(flav & Flavors::kNuMuToNuMu && sign & Sign::kNu) ret += *(fSpecCCNuMu.get());
115  if(flav & Flavors::kNuMuToNuMu && sign & Sign::kAntiNu) ret += *(fSpecCCAntiNuMu.get());
116 
117  }
118 
119  if(curr & Current::kNC) {
120  ret += *(fSpecNCNuMu.get());
121  ret += *(fSpecNCAntiNuMu.get());
122  ret += *(fSpecNCNuE.get());
123  ret += *(fSpecNCAntiNuE.get());
124  }
125 
126  return ret;
127  }
128 
129  //----------------------------------------------------------------------
131  {
132  return Predict(calc).FakeData(POT);
133  }
134 
135  //----------------------------------------------------------------------
137  //SpectrumLoaderBase& swap,
138  const HistAxis& axis,
139  const Cut& selection,
140  const SystShifts& shiftMC,
141  const Var& weight)
142  : fPOT(0),
143  fSpecCCNuMu( new Spectrum(nonswap, axis, selection && kIsNumuCC && !kIsAntiNu, shiftMC, weight)),
144  fSpecCCNuE(new Spectrum(nonswap, axis, selection && kIsBeamNue && !kIsAntiNu, shiftMC, weight)),
145  fSpecCCAntiNuMu( new Spectrum(nonswap, axis, selection && kIsNumuCC && kIsAntiNu, shiftMC, weight)),
146  fSpecCCAntiNuE(new Spectrum(nonswap, axis, selection && kIsBeamNue && kIsAntiNu, shiftMC, weight)),
147  fSpecNCNuMu( new Spectrum(nonswap, axis, selection && kIsNumu && !kIsAntiNu && kIsNC, shiftMC, weight)),
148  fSpecNCNuE( new Spectrum(nonswap, axis, selection && kIsNue && !kIsAntiNu && kIsNC, shiftMC, weight)),
149  fSpecNCAntiNuMu( new Spectrum(nonswap, axis, selection && kIsNumu && kIsAntiNu && kIsNC , shiftMC, weight)),
150  fSpecNCAntiNuE( new Spectrum(nonswap, axis, selection && kIsNue && kIsAntiNu && kIsNC , shiftMC, weight)),
151  fNCCompSpec( new Spectrum(nonswap, axis, selection && kIsNC, shiftMC, weight)),
152  fSpecLoad(&nonswap)
153 
154  {
155  }
156 
157  //----------------------------------------------------------------------
158  void NDPredictionNoOsc::SaveTo(TDirectory* dir , const std::string& name) const
159  {
160  TDirectory* tmp = gDirectory;
161  dir = dir->mkdir(name.c_str()); // switch to subdir
162  dir->cd();
163  TObjString("NDPredictionNoOsc").Write("type");
164 
165  fSpecCCNuMu->SaveTo(dir->mkdir("spec_cc_numu"), "spec_cc_numu");
166  fSpecCCNuE->SaveTo(dir->mkdir("spec_cc_nue"), "spec_cc_nue");
167  fSpecCCAntiNuMu->SaveTo(dir->mkdir("spec_cc_anti_numu"), "spec_cc_anti_numu");
168  fSpecCCAntiNuE->SaveTo(dir->mkdir("spec_cc_anti_nue"), "spec_cc_anti_nue");
169 
170  fSpecNCNuMu->SaveTo(dir->mkdir("spec_nc_numu"), "spec_nc_numu");
171  fSpecNCNuE->SaveTo(dir->mkdir("spec_nc_nue"), "spec_nc_nue");
172  fSpecNCAntiNuMu->SaveTo(dir->mkdir("spec_nc_anti_numu"), "spec_nc_nue");
173  fSpecNCAntiNuE->SaveTo(dir->mkdir("spec_nc_anti_nue"), "spec_nc_anti_nue");
174 
175  tmp->cd();
176  }
177 
178  //----------------------------------------------------------------------
179  unique_ptr<NDPredictionNoOsc> NDPredictionNoOsc::LoadFrom(TDirectory* dir, const std::string& name)
180  {
181 
182  dir = dir->GetDirectory(name.c_str()); // switch to subdir
183  TObjString* tag = (TObjString*)dir->Get("type");
184  assert(tag);
185  assert(tag->GetString() == "NDPredictionNoOsc");
186 
187  vector<unique_ptr<Spectrum>> spectra;
188 
189  for (string current : { "cc", "nc" }) {
190  for (string flav : { "numu", "nue", "anti_numu", "anti_nue" }) {
191  string name = "spec_" + current + "_" + flav;
192  TDirectory* specDir = dir->GetDirectory(name.c_str());
193  spectra.push_back(move(ana::LoadFrom<Spectrum>(specDir, name)));
194  }
195  }
196 
197  return make_unique<NDPredictionNoOsc>(spectra);
198  }
199 
200 } // end of namespace
Near Detector underground.
Definition: SREnums.h:10
SpectrumLoaderBase * fSpecLoad
const XML_Char * name
Definition: expat.h:151
std::unique_ptr< Spectrum > fSpecNCAntiNuE
const Cut kIsNumuCC(CCFlavSel(14, 14))
Select CC .
std::unique_ptr< Spectrum > fSpecCCAntiNuE
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
std::unique_ptr< Spectrum > fSpecNCAntiNuMu
Antineutrinos-only.
Definition: IPrediction.h:50
const Var weight
virtual void SaveTo(TDirectory *dir, const std::string &name) const override
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
const Cut kIsNumu([](const caf::SRProxy *sr){return(sr->mc.nnu==1 &&abs(sr->mc.nu[0].pdg)==14);})
Definition: TruthCuts.h:10
(&#39;beam &#39;)
Definition: IPrediction.h:15
Collection of SpectrumLoaders for many configurations.
Definition: Loaders.h:23
const Cut kIsAntiNu([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;assert(sr->mc.nnu==1);return sr->mc.nu[0].pdg< 0;})
Is this truly an antineutrino?
Definition: TruthCuts.h:53
const Cut kIsBeamNue(CCFlavSel(12, 12))
Select CC .
Take the output of an extrapolation and oscillate it as required.
void Clear()
Definition: Spectrum.cxx:361
Float_t tmp
Definition: plot.C:36
std::unique_ptr< Spectrum > fNCCompSpec
osc::OscCalcDumb calc
_IOscCalc< double > IOscCalc
Definition: IOscCalc.h:41
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
std::unique_ptr< Spectrum > fSpecCCNuE
static NDPredictionNoOsc NDPredictionNoOsc_c(Loaders &loaders, const HistAxis &axis, const Cut &selection, const SystShifts &shiftMC=kNoShift, const Var &weight=kUnweighted)
std::unique_ptr< Spectrum > fSpecNCNuMu
Charged-current interactions.
Definition: IPrediction.h:39
std::unique_ptr< Spectrum > fSpecNCNuE
std::unique_ptr< Spectrum > fSpecCCAntiNuMu
const Cut kIsNC([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;assert(sr->mc.nnu==1);return!sr->mc.nu[0].iscc;})
Is this a Neutral Current event?
Definition: TruthCuts.h:8
Spectrum FakeData(double pot) const
Synonymous with AsimovData(). Retained for compatibility.
Definition: Spectrum.cxx:349
SpectrumLoaderBase & GetLoader(caf::Det_t det, DataMC datamc, DataSource src=kBeam, SwappingConfig swap=kNonSwap)
Retrieve a specific loader.
Definition: Loaders.cxx:129
const Cut kIsNue([](const caf::SRProxy *sr){return(sr->mc.nnu==1 &&abs(sr->mc.nu[0].pdg)==12);})
Definition: TruthCuts.h:9
virtual Spectrum FakeData(osc::IOscCalc *calc, double POT)
Neutrinos-only.
Definition: IPrediction.h:49
(&#39; survival&#39;)
Definition: IPrediction.h:19
std::vector< double > POT
std::unique_ptr< Spectrum > fSpecCCNuMu
Base class for the various types of spectrum loader.
TDirectory * dir
Definition: macro.C:5
REGISTER_LOADFROM("BENDecomp", IDecomp, BENDecomp)
std::vector< Loaders * > loaders
Definition: syst_header.h:386
Neutral-current interactions.
Definition: IPrediction.h:40
assert(nhit_max >=nhit_nbins)
virtual Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
static std::unique_ptr< NDPredictionNoOsc > LoadFrom(TDirectory *dir, const std::string &name)
virtual Spectrum Predict(osc::IOscCalc *calc) const override
def sign(x)
Definition: canMan.py:197
enum BeamMode string