CrossSectionSpectra.cxx
Go to the documentation of this file.
2 #include "TObjString.h"
3 #include "CAFAna/XSec/Flux.h"
4 
5 namespace ana
6 {
7  ///////////////////////////////////////////////////////////////////////
9  {
10  this->fRecoTrue = rhs.fRecoTrue;
11  this->fSignalEst = rhs.fSignalEst;
12  this->fFlux = rhs.fFlux;
13  this->fMCSelectedSignalTrueSpace = rhs.fMCSelectedSignalTrueSpace;
14  this->fMCSelectedSignalRecoSpace = rhs.fMCSelectedSignalRecoSpace;
15  this->fMCTrueSignalTrueSpace = rhs.fMCTrueSignalTrueSpace;
16  this->fMCSelectedAllRecoSpace = rhs.fMCSelectedAllRecoSpace;
17 
18  // remove reference to existing objects so they don't get deleted
19  // when these pointers go out of scope
20  rhs.fRecoTrue = NULL;
21  rhs.fSignalEst = NULL;
22  rhs.fMCSelectedSignalTrueSpace = NULL;
23  rhs.fMCSelectedSignalRecoSpace = NULL;
24  rhs.fMCTrueSignalTrueSpace = NULL;
25  rhs.fMCSelectedAllRecoSpace = NULL;
26  }
27 
28  ///////////////////////////////////////////////////////////////////////
31  {
32  if ( this == &rhs )
33  return *this;
34  this->fRecoTrue = rhs.fRecoTrue;
35  this->fSignalEst = rhs.fSignalEst;
36  this->fFlux = rhs.fFlux;
37  this->fMCSelectedSignalTrueSpace = rhs.fMCSelectedSignalTrueSpace;
38  this->fMCSelectedSignalRecoSpace = rhs.fMCSelectedSignalRecoSpace;
39  this->fMCTrueSignalTrueSpace = rhs.fMCTrueSignalTrueSpace;
40  this->fMCSelectedAllRecoSpace = rhs.fMCSelectedAllRecoSpace;
41 
42  // remove reference to existing objects so they don't get deleted
43  // when these pointers go out of scope
44  rhs.fRecoTrue = NULL;
45  rhs.fSignalEst = NULL;
46  rhs.fMCSelectedSignalTrueSpace = NULL;
47  rhs.fMCSelectedSignalRecoSpace = NULL;
48  rhs.fMCTrueSignalTrueSpace = NULL;
49  rhs.fMCSelectedAllRecoSpace = NULL;
50  return *this;
51  }
52 
53  ///////////////////////////////////////////////////////////////////////
56  {
57  if ( this == &rhs )
58  return *this;
59  this->fRecoTrue = new ReweightableSpectrum(*rhs.fRecoTrue);
60  this->fSignalEst = rhs.fSignalEst->Clone();
61  this->fFlux = std::make_shared<Spectrum>(*rhs.fFlux);
66  return *this;
67  }
68 
69  ///////////////////////////////////////////////////////////////////////
71  {
72  this->fRecoTrue = new ReweightableSpectrum(*rhs.fRecoTrue);
73  this->fSignalEst = rhs.fSignalEst->Clone();
74  this->fFlux = std::make_shared<Spectrum>(*rhs.fFlux);
79  }
80 
81  ///////////////////////////////////////////////////////////////////////
83  {
84  delete fRecoTrue;
85  delete fSignalEst;
88  delete fMCTrueSignalTrueSpace;
90  }
91 
92  ///////////////////////////////////////////////////////////////////////
93  void
94  CrossSectionSpectra::SaveTo(TDirectory * dir, const std::string& name) const
95  {
96  TDirectory* tmp = gDirectory;
97 
98  dir = dir->mkdir(name.c_str()); // switch to subdir
99  dir->cd();
100 
101  TObjString("CrossSectionSpectra").Write("type");
102  fRecoTrue->SaveTo(dir, "fRecoTrue");
103  fSignalEst->SaveTo(dir, "fSignalEst");
104  fFlux->SaveTo(dir, "fFlux");
105  fMCSelectedSignalTrueSpace->SaveTo(dir, "fMCSelectedSignalTrueSpace");
106  fMCSelectedSignalRecoSpace->SaveTo(dir, "fMCSelectedSignalRecoSpace");
107  fMCTrueSignalTrueSpace->SaveTo(dir, "fMCTrueSignalTrueSpace");
108  fMCSelectedAllRecoSpace->SaveTo(dir, "fMCSelectedAllRecoSpace");
109 
110  dir->Write();
111  delete dir;
112 
113  tmp->cd();
114  }
115 
116  ///////////////////////////////////////////////////////////////////////
117  std::unique_ptr<CrossSectionSpectra>
119  {
120  dir = dir->GetDirectory(name.c_str()); // switch to subdir
121  assert(dir);
122 
123  TObjString* tag = (TObjString*) dir->Get("type");
124  assert(tag);
125  assert(tag->GetString() == "CrossSectionSpectra" && "Type does not match CrossSectionSpectra");
126  delete tag;
127 
128  ReweightableSpectrum * recotrue = ReweightableSpectrum::LoadFrom(dir, "fRecoTrue").release();
129  ISignalEstimator * signalest = ISignalEstimator::LoadFrom(dir, "fSignalEst").release();
130  Spectrum * flux = Spectrum::LoadFrom(dir, "fFlux").release();
131  Spectrum * sig_selected_truth = Spectrum::LoadFrom(dir, "fMCSelectedSignalTrueSpace").release();
132  Spectrum * sig_selected_reco = Spectrum::LoadFrom(dir, "fMCSelectedSignalRecoSpace").release();
133  Spectrum * sig_truth = Spectrum::LoadFrom(dir, "fMCTrueSignalTrueSpace").release();
134  Spectrum * mc_selected = Spectrum::LoadFrom(dir, "fMCSelectedAllRecoSpace").release();
135 
136  delete dir;
137 
138  return std::unique_ptr<CrossSectionSpectra>
139  ( new CrossSectionSpectra(recotrue,
140  signalest,
141  flux,
142  mc_selected,
143  sig_selected_truth,
144  sig_selected_reco,
145  sig_truth));
146  }
147 
148  ///////////////////////////////////////////////////////////////////////
150  ISignalEstimator * signalest,
151  Spectrum * flux,
152  Spectrum * mc_selected,
153  Spectrum * sig_selected_truth,
154  Spectrum * sig_selected_reco,
155  Spectrum * sig_truth)
156  : fRecoTrue(recotrue),
157  fSignalEst(signalest),
158  fFlux(flux),
159  fMCSelectedAllRecoSpace(mc_selected),
160  fMCSelectedSignalRecoSpace(sig_selected_reco),
161  fMCSelectedSignalTrueSpace(sig_selected_truth),
162  fMCTrueSignalTrueSpace(sig_truth)
163  {}
164 
165  ///////////////////////////////////////////////////////////////////////
167  const HistAxis reco_axis,
168  const NuTruthHistAxis truth_axis,
169  const Cut & selection,
170  const NuTruthCut & signal,
171  ISignalEstimator * signal_est,
172  const TVector3 & fidmax,
173  const TVector3 & fidmin,
174  const Binning & flux_binning,
175  double pdg,
176  const Var & weight,
177  const NuTruthVar & nt_weight,
178  const SystShifts & shift)
180  reco_axis,
181  HistAxisFromNuTruthHistAxis(truth_axis),
182  selection && CutFromNuTruthCut(signal),
183  shift,
184  VarFromNuTruthVar(nt_weight))),
185  fSignalEst(signal_est),
186  fFlux(DeriveFlux(loader,
187  flux_binning,
188  pdg,
189  &fidmin,
190  &fidmax,
191  shift,
192  nt_weight)),
194  reco_axis,
195  selection,
196  shift,
197  weight)),
199  reco_axis,
200  selection && CutFromNuTruthCut(signal),
201  shift,
202  weight)),
204  HistAxisFromNuTruthHistAxis(truth_axis),
205  selection && CutFromNuTruthCut(signal),
206  shift,
207  VarFromNuTruthVar(nt_weight))),
209  truth_axis,
210  signal,
211  shift,
212  nt_weight))
213  {}
214 
215  ///////////////////////////////////////////////////////////////////////
217  const HistAxis reco_axis,
218  const NuTruthHistAxis truth_axis,
219  const Cut & selection,
220  const NuTruthCut & signal,
221  ISignalEstimator * signal_est,
222  std::shared_ptr<Spectrum> flux,
223  const Var & weight,
224  const NuTruthVar & nt_weight,
225  const SystShifts & shift)
227  reco_axis,
228  HistAxisFromNuTruthHistAxis(truth_axis),
229  selection && CutFromNuTruthCut(signal),
230  shift,
231  VarFromNuTruthVar(nt_weight))),
232  fSignalEst(signal_est),
233  fFlux(flux),
235  reco_axis,
236  selection,
237  shift,
238  weight)),
240  reco_axis,
241  selection && CutFromNuTruthCut(signal),
242  shift,
243  weight)),
245  HistAxisFromNuTruthHistAxis(truth_axis),
246  selection && CutFromNuTruthCut(signal),
247  shift,
248  VarFromNuTruthVar(nt_weight))),
250  truth_axis,
251  signal,
252  shift,
253  nt_weight))
254  {}
255 }
256 
const XML_Char * name
Definition: expat.h:151
Represent the binning of a Spectrum&#39;s x-axis.
Definition: Binning.h:16
Cuts and Vars for the 2020 FD DiF Study.
Definition: vars.h:6
const Var weight
Simple record of shifts applied to systematic parameters.
Definition: SystShifts.h:20
CrossSectionSpectra(SpectrumLoaderBase &, const HistAxis, const NuTruthHistAxis, const Cut &, const NuTruthCut &, ISignalEstimator *, const TVector3 &, const TVector3 &, const Binning &, double, const Var &=kUnweighted, const NuTruthVar &=kNuTruthUnweighted, const SystShifts &=kNoShift)
Constructor that makes a unique flux object.
Spectrum with the value of a second variable, allowing for reweighting
virtual ISignalEstimator * Clone()=0
Float_t tmp
Definition: plot.C:36
static std::unique_ptr< ReweightableSpectrum > LoadFrom(TDirectory *dir, const std::string &name)
static std::unique_ptr< ISignalEstimator > LoadFrom(TDirectory *dir, const std::string &name)
void SaveTo(TDirectory *, const std::string &) const
ISignalEstimator * fSignalEst
Loaders::FluxType flux
Representation of a spectrum in any variable, with associated POT.
Definition: Spectrum.h:40
static std::unique_ptr< CrossSectionSpectra > LoadFrom(TDirectory *, const std::string &)
static std::unique_ptr< Spectrum > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Spectrum.cxx:546
HistAxis HistAxisFromNuTruthHistAxis(NuTruthHistAxis ntha, double _default)
Definition: HistAxis.cxx:9
void SaveTo(TDirectory *dir, const std::string &name) const
Definition: Spectrum.cxx:517
loader
Definition: demo0.py:10
std::vector< float > Spectrum
Definition: Constants.h:570
std::shared_ptr< Spectrum > fFlux
ReweightableSpectrum * fRecoTrue
Base class for the various types of spectrum loader.
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
Var VarFromNuTruthVar(const NuTruthVar &stv, double _default)
Definition: Var.cxx:7
Spectrum * DeriveFlux(SpectrumLoaderBase &loader, const Binning &bins, int pdg, const TVector3 *min, const TVector3 *max, const SystShifts &shift, const NuTruthVar weight)
Definition: Flux.cxx:56
virtual void SaveTo(TDirectory *dir, const std::string &name) const =0
TDirectory * dir
Definition: macro.C:5
CrossSectionSpectra & operator=(const CrossSectionSpectra &)
void SaveTo(TDirectory *dir, const std::string &name) const
assert(nhit_max >=nhit_nbins)
Cut CutFromNuTruthCut(const NuTruthCut &stc)
Definition: Cut.cxx:7