PredictionAddRock.cxx
Go to the documentation of this file.
3 
7 #include "CAFAna/Core/Stan.h"
8 
9 #include "TDirectory.h"
10 #include "TObjString.h"
11 
12 #include "TH1.h"
13 #include "TVectorD.h"
15 
16 namespace ana
17 {
18  REGISTER_LOADFROM("PredictionAddRock", IPrediction, PredictionAddRock);
19 
20  //----------------------------------------------------------------------
21 
23  PredictionNoExtrap *predRock)
24  : fPredFid(predFid),
25  fPredRock(predRock)
26  {
27  }
28 
29  //----------------------------------------------------------------------
31  {
32  delete fPredFid;
33  delete fPredRock;
34  }
35 
36  //----------------------------------------------------------------------
38  {
39  return PredictComponent(calc,
42  Sign::kBoth);
43  }
44 
45  //----------------------------------------------------------------------
47  {
48  return PredictComponent(calc,
51  Sign::kBoth);
52  }
53 
54  //----------------------------------------------------------------------
56  const SystShifts& syst) const
57  {
58  return PredictComponentSyst(calc, syst,
61  Sign::kBoth);
62  }
63 
64  //----------------------------------------------------------------------
66  const SystShifts& syst) const
67  {
68  return PredictComponentSyst(calc, syst,
71  Sign::kBoth);
72  }
73 
74 
75  //----------------------------------------------------------------------
77  Flavors::Flavors_t flav,
79  Sign::Sign_t sign) const
80  {
81  return PredictComponentSyst(calc,kNoShift,flav,curr,sign);
82  }
83 
84  //----------------------------------------------------------------------
86  Flavors::Flavors_t flav,
88  Sign::Sign_t sign) const
89  {
90  return PredictComponentSyst(calc,kNoShift,flav,curr,sign);
91  }
92 
93  //----------------------------------------------------------------------
95  const SystShifts& syst,
96  Flavors::Flavors_t flav,
98  Sign::Sign_t sign) const
99  {
100  return _PredictComponentSyst(calc, syst, flav, curr, sign);
101  }
102 
103  //----------------------------------------------------------------------
105  const SystShifts& syst,
106  Flavors::Flavors_t flav,
108  Sign::Sign_t sign) const
109  {
110  return _PredictComponentSyst(calc, syst, flav, curr, sign);
111  }
112 
113 
114  //----------------------------------------------------------------------
115  template <typename T>
117  const SystShifts& syst,
118  Flavors::Flavors_t flav,
120  Sign::Sign_t sign) const
121  {
122  // Clone the systs
123  SystShifts systClone = syst;
124 
125  // First Check for RockScaleSyst
126  auto systScale = 1 + systClone.GetShift<T>(&kRockScaleSyst);
127  if(systScale < 0) systScale = 0;
128 
129  // the fiducial prediction definitely won't support the rock scale syst
130  systClone.RemoveShift(&kRockScaleSyst);
131 
132  // Strategy: assume PredictComponentSyst is properly implemented for the
133  // fiducial prediction, so start with that. Treat the rock as a series of
134  // delta's to that distribution, all predicted without syst shifts.
135  Spectrum ret = fPredFid->PredictComponentSyst(calc,systClone,
136  flav,curr,sign);
137 
138  if (systScale > 0)
139  {
140  Spectrum rock = RockComponent(calc, flav, curr, sign);
141  rock.Scale(systScale);
142  ret += rock;
143  }
144 
145  return ret;
146  }
147 
149  const SystShifts& syst,
150  Flavors::Flavors_t flav,
152  Sign::Sign_t sign) const;
154  const SystShifts& syst,
155  Flavors::Flavors_t flav,
156  Current::Current_t curr,
157  Sign::Sign_t sign) const;
158 
159  //----------------------------------------------------------------------
160  template <typename T>
162  Flavors::Flavors_t flav,
163  Current::Current_t curr,
164  Sign::Sign_t sign) const
165  {
167 
168  if(curr & Current::kNC){
169  assert(flav == Flavors::kAll); // Don't know how to calculate anything else
170 
171  // Predict the NC part
172  ret = fPredRock->PredictComponent(calc, flav, Current::kNC, sign);
173  }
174  else{
175  // Otherwise, still need to calculate something to get a suitably-binned
176  // Spectrum, but shouldn't keep in the total.
177  ret = fPredRock->PredictComponent(calc, Flavors::kAll, Current::kNC, Sign::kBoth);
178  ret.Clear();
179  }
180 
181 
182  if(curr & Current::kCC){
183  if (flav & Flavors::kNuEToNuE){
184  ret += fPredRock->PredictComponent(calc,
185  Flavors::kNuEToNuE,
186  Current::kCC, sign);
187  }
188  if (flav & Flavors::kNuEToNuMu){
189  ret += fPredRock->PredictComponent(calc,
190  Flavors::kNuEToNuMu,
191  Current::kCC, sign);
192  }
193  // If you're astute, you'll realize we don't do anything for tauswap.
194  // We never had tauswap rock files made, so it doesn't make sense to sum
195  // them in.
196 
197  if (flav & Flavors::kNuMuToNuE){
198  ret += fPredRock->PredictComponent(calc,
199  Flavors::kNuMuToNuE,
200  Current::kCC, sign);
201  }
202  if (flav & Flavors::kNuMuToNuMu){
203  ret += fPredRock->PredictComponent(calc,
204  Flavors::kNuMuToNuMu,
205  Current::kCC, sign);
206  }
207  }
208 
209  return ret;
210  }
211 
213  Flavors::Flavors_t flav,
214  Current::Current_t curr,
215  Sign::Sign_t sign) const;
217  Flavors::Flavors_t flav,
218  Current::Current_t curr,
219  Sign::Sign_t sign) const;
220 
221  //----------------------------------------------------------------------
223  {
224  return fPredFid->ComponentCC(from, to) + fPredRock->ComponentCC(from, to);
225  }
226 
227  //----------------------------------------------------------------------
228  //nc
230  {
232  }
233 
235  {
236  return fPredFid->ComponentNC() + fPredRock->ComponentNC();
237  }
238 
240  {
242  }
243  //end nc
244  //----------------------------------------------------------------------
245  void PredictionAddRock::SaveTo(TDirectory* dir, const std::string& name) const
246  {
247  TDirectory* tmp = gDirectory;
248 
249  dir = dir->mkdir(name.c_str()); // switch to subdir
250  dir->cd();
251 
252  TObjString("PredictionAddRock").Write("type");
253 
254  fPredFid->SaveTo(dir, "predFid");
255  fPredRock->SaveTo(dir, "predRock");
256 
257  dir->Write();
258  delete dir;
259 
260  tmp->cd();
261  }
262 
263  //----------------------------------------------------------------------
264  std::unique_ptr<PredictionAddRock> PredictionAddRock::LoadFrom(TDirectory* dir, const std::string& name)
265  {
266  dir = dir->GetDirectory(name.c_str()); // switch to subdir
267  assert(dir);
268 
269  auto predFid = ana::LoadFrom<IPrediction>(dir, "predFid").release();
270  auto predRock = ana::LoadFrom<PredictionNoExtrap>(dir, "predRock").release();
271 
272  delete dir;
273 
274  return std::unique_ptr<PredictionAddRock>(new PredictionAddRock(predFid,predRock));
275  }
276 }
OscillatableSpectrum ComponentCC(int from, int to) const override
Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
const XML_Char * name
Definition: expat.h:151
Spectrum ComponentNC() const override
virtual Spectrum ComponentNCAnti() const
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
Spectrum ComponentNCTotal() const override
Spectrum _PredictComponentSyst(osc::_IOscCalc< T > *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
Spectrum ComponentNCTotal() const override
(&#39; appearance&#39;)
Definition: IPrediction.h:18
virtual Spectrum PredictSyst(osc::IOscCalc *calc, const SystShifts &syst) const override
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
(&#39;beam &#39;)
Definition: IPrediction.h:15
General interface to oscillation calculators.
Definition: StanTypedefs.h:23
Spectrum RockComponent(osc::_IOscCalc< T > *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
virtual Spectrum PredictComponentSyst(osc::IOscCalc *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const
Definition: IPrediction.cxx:79
virtual Spectrum PredictComponentSyst(osc::IOscCalc *calc, const SystShifts &syst, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
virtual void SaveTo(TDirectory *dir, const std::string &name) const override
void Clear()
Definition: Spectrum.cxx:362
static std::unique_ptr< PredictionAddRock > LoadFrom(TDirectory *dir, const std::string &name)
Float_t tmp
Definition: plot.C:36
virtual void SaveTo(TDirectory *dir, const std::string &name) const
osc::OscCalcDumb calc
void Scale(double c)
Multiply this spectrum by a constant c.
Definition: Spectrum.cxx:238
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
virtual Spectrum ComponentNC() const
Spectrum ComponentNCAnti() const override
Charged-current interactions.
Definition: IPrediction.h:39
Interactions of both types.
Definition: IPrediction.h:42
static Spectrum Uninitialized()
Definition: Spectrum.h:145
OscillatableSpectrum ComponentCC(int from, int to) const override
T GetShift(const ISyst *syst) const
virtual OscillatableSpectrum ComponentCC(int from, int to) const
std::unique_ptr< IPrediction > LoadFrom< IPrediction >(TDirectory *dir, const std::string &label)
Definition: IPrediction.cxx:18
virtual void SaveTo(TDirectory *dir, const std::string &name) const override
const SystShifts kNoShift
Definition: SystShifts.cxx:22
(&#39; survival&#39;)
Definition: IPrediction.h:19
virtual Spectrum PredictComponent(osc::IOscCalc *calc, Flavors::Flavors_t flav, Current::Current_t curr, Sign::Sign_t sign) const override
PredictionNoExtrap * fPredRock
TDirectory * dir
Definition: macro.C:5
virtual Spectrum ComponentNCTotal() const
REGISTER_LOADFROM("BENDecomp", IDecomp, BENDecomp)
Neutral-current interactions.
Definition: IPrediction.h:40
assert(nhit_max >=nhit_nbins)
Spectrum ComponentNCAnti() const override
Both neutrinos and antineutrinos.
Definition: IPrediction.h:52
Standard interface to all prediction techniques.
Definition: IPrediction.h:57
double T
Definition: Xdiff_gwt.C:5
Prediction that just uses FD MC, with no extrapolation.
All neutrinos, any flavor.
Definition: IPrediction.h:26
(&#39; appearance&#39;)
Definition: IPrediction.h:16
Spectrum with true energy information, allowing it to be oscillated
void RemoveShift(const ISyst *syst)
Definition: SystShifts.cxx:74
virtual Spectrum Predict(osc::IOscCalc *calc) const override
void rock(std::string suffix="full")
Definition: rock.C:28
Spectrum ComponentNC() const override
def sign(x)
Definition: canMan.py:197
const DummyRockScaleSyst kRockScaleSyst
enum BeamMode string