Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ana::NDOscillatableSpectrum Class Reference

Spectrum with true L/E information, allowing it to be oscillated More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-11-30/CAFAna/Core/NDOscillatableSpectrum.h"

Inheritance diagram for ana::NDOscillatableSpectrum:
ana::ReweightableSpectrum

Public Member Functions

 NDOscillatableSpectrum (const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 NDOscillatableSpectrum (SpectrumLoaderBase &loader, const HistAxis &axis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 ~NDOscillatableSpectrum ()
 
 NDOscillatableSpectrum (const NDOscillatableSpectrum &rhs)
 Copy constructor. More...
 
 NDOscillatableSpectrum (NDOscillatableSpectrum &&rhs)
 
NDOscillatableSpectrumoperator= (const NDOscillatableSpectrum &rhs)
 Assignment operator. More...
 
NDOscillatableSpectrumoperator= (NDOscillatableSpectrum &&rhs)
 
Spectrum Oscillated (osc::IOscCalc *calc, int from, int to) const
 
void Scale (double x)
 
void SaveTo (TDirectory *dir, const std::string &name) const
 
void Fill (double x, double y, double w=1)
 
TH2D * ToTH2 (double pot) const
 
double POT () const
 
double Livetime () const
 
Spectrum UnWeighted () const
 
Spectrum WeightingVariable () const
 
Spectrum WeightedBy (const Ratio &weights) const
 Reco spectrum with truth weights applied. More...
 
void ReweightToTrueSpectrum (const Spectrum &target)
 Rescale bins so that WeightingVariable will return target. More...
 
void ReweightToRecoSpectrum (const Spectrum &target)
 Recale bins so that Unweighted will return target. More...
 
ReweightableSpectrumoperator+= (const ReweightableSpectrum &rhs)
 
ReweightableSpectrum operator+ (const ReweightableSpectrum &rhs) const
 
ReweightableSpectrumoperator-= (const ReweightableSpectrum &rhs)
 
ReweightableSpectrum operator- (const ReweightableSpectrum &rhs) const
 
void Clear ()
 
unsigned int NDimensions () const
 
const std::vector< std::string > & GetLabels () const
 
const std::vector< Binning > & GetBinnings () const
 
const std::vector< Binning > & GetTrueBinnings () const
 
Eigen::MatrixXd GetEigen (double pot) const
 

Static Public Member Functions

static NDOscillatableSpectrum Uninitialized ()
 
static std::unique_ptr< NDOscillatableSpectrumLoadFrom (TDirectory *dir, const std::string &name)
 

Protected Member Functions

 NDOscillatableSpectrum ()
 Constructor for Uninitialized() More...
 
ReweightableSpectrumPlusEqualsHelper (const ReweightableSpectrum &rhs, int sign)
 
void RemoveLoader (ReweightableSpectrum **)
 
void AddLoader (ReweightableSpectrum **)
 
void _SaveTo (TDirectory *dir, const std::string &name, const std::string &type) const
 

Protected Attributes

Eigen::MatrixXd fMat
 
double fPOT
 
double fLivetime
 
LabelsAndBins fAxisX
 
LabelsAndBins fAxisY
 
std::set< ReweightableSpectrum ** > fReferences
 

Friends

class SpectrumLoaderBase
 
class SpectrumLoader
 
class NullLoader
 

Detailed Description

Spectrum with true L/E information, allowing it to be oscillated

Definition at line 25 of file NDOscillatableSpectrum.h.

Constructor & Destructor Documentation

ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( const std::string label,
const Binning bins,
SpectrumLoaderBase loader,
const Var var,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 35 of file NDOscillatableSpectrum.cxx.

43  HistAxis("True Energy (GeV)", kTrueLOverTrueEBins, kTrueLOverTrueE),
44  cut, shift, wei)
45  {
46  }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
const Binning kTrueLOverTrueEBins
Default true-energy bin edges.
Definition: Binning.cxx:62
const char * label
const Var kTrueLOverTrueE([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return 0.;const double trueE=sr->mc.nu[0].E;const double trueL=sr->mc.nu[0].L;return trueL/trueE;})
loader
Definition: demo0.py:10
const Binning bins
Definition: NumuCC_CPiBin.h:8
const Cut cut
Definition: exporter_fd.C:30
ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( SpectrumLoaderBase loader,
const HistAxis axis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 49 of file NDOscillatableSpectrum.cxx.

55  HistAxis("True Energy (GeV)", kTrueLOverTrueEBins, kTrueLOverTrueE),
56  cut, shift, wei)
57  {
58  }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
const Binning kTrueLOverTrueEBins
Default true-energy bin edges.
Definition: Binning.cxx:62
const Var kTrueLOverTrueE([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return 0.;const double trueE=sr->mc.nu[0].E;const double trueL=sr->mc.nu[0].L;return trueL/trueE;})
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
ana::NDOscillatableSpectrum::~NDOscillatableSpectrum ( )

Definition at line 61 of file NDOscillatableSpectrum.cxx.

Referenced by Uninitialized().

62  {
63  }
ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( const NDOscillatableSpectrum rhs)

Copy constructor.

Definition at line 66 of file NDOscillatableSpectrum.cxx.

References ana::assert(), and ana::ReweightableSpectrum::fReferences.

68  {
69  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
70  }
assert(nhit_max >=nhit_nbins)
ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( NDOscillatableSpectrum &&  rhs)

Definition at line 74 of file NDOscillatableSpectrum.cxx.

References ana::assert().

76  {
77  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
78  }
assert(nhit_max >=nhit_nbins)
ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( )
inlineprotected

Constructor for Uninitialized()

Definition at line 69 of file NDOscillatableSpectrum.h.

Referenced by Uninitialized().

70  {
71  }

Member Function Documentation

void ana::ReweightableSpectrum::_SaveTo ( TDirectory *  dir,
const std::string name,
const std::string type 
) const
protectedinherited

Definition at line 285 of file ReweightableSpectrum.cxx.

References dir, ana::ReweightableSpectrum::fAxisX, ana::ReweightableSpectrum::fAxisY, ana::ReweightableSpectrum::fLivetime, genie::utils::style::Format(), ana::ReweightableSpectrum::fPOT, ana::LabelsAndBins::GetBinnings(), ana::LabelsAndBins::GetLabels(), make_syst_table_plots::h, MECModelEnuComparisons::i, ana::LabelsAndBins::NDimensions(), tmp, ana::ReweightableSpectrum::ToTH2(), and Write().

Referenced by ana::ReweightableSpectrum::ReweightableSpectrum(), SaveTo(), ana::ReweightableSpectrum::SaveTo(), and ana::OscillatableSpectrum::SaveTo().

288  {
289  TDirectory* tmp = gDirectory;
290 
291  dir = dir->mkdir(name.c_str()); // switch to sbudir
292  dir->cd();
293 
294  TObjString(type.c_str()).Write("type");
295 
296  TH2* h = ToTH2(fPOT);
297  h->Write("hist");
298 
299  TH1D hPot("", "", 1, 0, 1);
300  hPot.Fill(.5, fPOT);
301  hPot.Write("pot");
302  TH1D hLivetime("", "", 1, 0, 1);
303  hLivetime.Fill(.5, fLivetime);
304  hLivetime.Write("livetime");
305 
306  for(unsigned int i = 0; i < fAxisX.NDimensions(); ++i){
307  TObjString(fAxisX.GetLabels()[i].c_str()).Write(TString::Format("label%d", i).Data());
308  fAxisX.GetBinnings()[i].SaveTo(dir, TString::Format("bins%d", i).Data());
309  }
310 
311  for(unsigned int i = 0; i < fAxisY.NDimensions(); ++i){
312  TObjString(fAxisY.GetLabels()[i].c_str()).Write(TString::Format("labely%d", i).Data());
313  fAxisY.GetBinnings()[i].SaveTo(dir, TString::Format("binsy%d", i).Data());
314  }
315 
316  dir->Write();
317  delete dir;
318 
319  delete h;
320 
321  tmp->cd();
322  }
const XML_Char * name
Definition: expat.h:151
Float_t tmp
Definition: plot.C:36
const std::vector< Binning > & GetBinnings() const
Definition: LabelsAndBins.h:69
unsigned int NDimensions() const
Definition: LabelsAndBins.h:66
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
const std::vector< std::string > & GetLabels() const
Definition: LabelsAndBins.h:68
TH2D * ToTH2(double pot) const
gm Write()
void ana::ReweightableSpectrum::AddLoader ( ReweightableSpectrum **  ref)
protectedinherited

Definition at line 273 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fReferences.

Referenced by ana::ReweightableSpectrum::ReweightableSpectrum().

274  {
275  fReferences.insert(ref);
276  }
std::set< ReweightableSpectrum ** > fReferences
void ana::ReweightableSpectrum::Clear ( void  )
inherited
void ana::ReweightableSpectrum::Fill ( double  x,
double  y,
double  w = 1 
)
inherited
const std::vector<Binning>& ana::ReweightableSpectrum::GetBinnings ( ) const
inlineinherited
Eigen::MatrixXd ana::ReweightableSpectrum::GetEigen ( double  pot) const
inlineinherited
const std::vector<std::string>& ana::ReweightableSpectrum::GetLabels ( ) const
inlineinherited
const std::vector<Binning>& ana::ReweightableSpectrum::GetTrueBinnings ( ) const
inlineinherited

Definition at line 84 of file ReweightableSpectrum.h.

References ana::ReweightableSpectrum::fAxisY, and ana::LabelsAndBins::GetBinnings().

84 {return fAxisY.GetBinnings();}
const std::vector< Binning > & GetBinnings() const
Definition: LabelsAndBins.h:69
double ana::ReweightableSpectrum::Livetime ( ) const
inlineinherited
std::unique_ptr< NDOscillatableSpectrum > ana::NDOscillatableSpectrum::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 121 of file NDOscillatableSpectrum.cxx.

References ana::assert(), ana::bins, dir, genie::utils::style::Format(), MECModelEnuComparisons::i, ana::kNoCut, ana::kNullLoader, label, PandAna.Demos.pi0_spectra::labels, ana::Binning::LoadFrom(), runNovaSAM::ret, string, cvnie::subdir, and getGoodRuns4SAM::tag.

Referenced by Scale().

122  {
123  dir = dir->GetDirectory(name.c_str()); // switch to subdir
124  assert(dir);
125 
126  DontAddDirectory guard;
127 
128  TObjString* tag = (TObjString*)dir->Get("type");
129  assert(tag);
130  assert(tag->GetString() == "NDOscillatableSpectrum");
131  delete tag;
132 
133  TH2D* spect = (TH2D*)dir->Get("hist");
134  assert(spect);
135  TH1* hPot = (TH1*)dir->Get("pot");
136  assert(hPot);
137  TH1* hLivetime = (TH1*)dir->Get("livetime");
138  assert(hLivetime);
139 
140  std::vector<std::string> labels;
141  std::vector<Binning> bins;
142 
143  for(int i = 0; ; ++i){
144  const std::string subname = TString::Format("bins%d", i).Data();
145  TDirectory* subdir = dir->GetDirectory(subname.c_str());
146  if(!subdir) break;
147  delete subdir;
148  bins.push_back(*Binning::LoadFrom(dir, subname));
149  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
150  labels.push_back(label ? label->GetString().Data() : "");
151  delete label;
152  }
153 
154  delete dir;
155 
156  auto ret = std::make_unique<NDOscillatableSpectrum>(kNullLoader,
157  HistAxis(labels, bins),
158  kNoCut);
159 
160  // ROOT histogram storage is row-major, but Eigen is column-major by
161  // default
162  typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen:: Dynamic, Eigen::RowMajor> MatRowMajor;
163  ret->fMat = Eigen::Map<MatRowMajor>(spect->GetArray(),
164  ret->fMat.rows(),
165  ret->fMat.cols());
166 
167  delete spect;
168 
169  ret->fPOT = hPot->Integral(0, -1);
170  ret->fLivetime = hLivetime->Integral(0, -1);
171 
172  delete hPot;
173  delete hLivetime;
174 
175  return ret;
176  }
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Binning.cxx:230
const XML_Char * name
Definition: expat.h:151
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
subdir
Definition: cvnie.py:7
const char * label
const Binning bins
Definition: NumuCC_CPiBin.h:8
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
const Cut kNoCut
The simplest possible cut: pass everything, used as a default.
Definition: Cut.h:109
static NullLoader kNullLoader
Dummy loader that doesn&#39;t load any files.
enum BeamMode string
unsigned int ana::ReweightableSpectrum::NDimensions ( ) const
inlineinherited

Definition at line 81 of file ReweightableSpectrum.h.

References ana::ReweightableSpectrum::fAxisX, and ana::LabelsAndBins::NDimensions().

81 {return fAxisX.NDimensions();}
unsigned int NDimensions() const
Definition: LabelsAndBins.h:66
ReweightableSpectrum ana::ReweightableSpectrum::operator+ ( const ReweightableSpectrum rhs) const
inherited

Definition at line 239 of file ReweightableSpectrum.cxx.

References runNovaSAM::ret.

Referenced by ana::ReweightableSpectrum::Livetime().

240  {
241  ReweightableSpectrum ret = *this;
242  ret += rhs;
243  return ret;
244  }
ReweightableSpectrum & ana::ReweightableSpectrum::operator+= ( const ReweightableSpectrum rhs)
inherited

Definition at line 233 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::PlusEqualsHelper().

Referenced by ana::ReweightableSpectrum::Livetime(), and ana::OscillatableSpectrum::operator+=().

234  {
235  return PlusEqualsHelper(rhs, +1);
236  }
ReweightableSpectrum & PlusEqualsHelper(const ReweightableSpectrum &rhs, int sign)
ReweightableSpectrum ana::ReweightableSpectrum::operator- ( const ReweightableSpectrum rhs) const
inherited

Definition at line 253 of file ReweightableSpectrum.cxx.

References runNovaSAM::ret.

Referenced by ana::ReweightableSpectrum::Livetime().

254  {
255  ReweightableSpectrum ret = *this;
256  ret -= rhs;
257  return ret;
258  }
ReweightableSpectrum & ana::ReweightableSpectrum::operator-= ( const ReweightableSpectrum rhs)
inherited

Definition at line 247 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::PlusEqualsHelper().

Referenced by ana::ReweightableSpectrum::Livetime(), and ana::OscillatableSpectrum::operator-=().

248  {
249  return PlusEqualsHelper(rhs, -1);
250  }
ReweightableSpectrum & PlusEqualsHelper(const ReweightableSpectrum &rhs, int sign)
NDOscillatableSpectrum & ana::NDOscillatableSpectrum::operator= ( const NDOscillatableSpectrum rhs)

Assignment operator.

Definition at line 81 of file NDOscillatableSpectrum.cxx.

References ana::assert(), ana::ReweightableSpectrum::fReferences, and ana::ReweightableSpectrum::operator=().

Referenced by Uninitialized().

82  {
83  if(this == &rhs) return *this;
84 
86 
87  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
88  assert( fReferences.empty() ); // Copying with pending loads is unexpected
89 
90  return *this;
91  }
std::set< ReweightableSpectrum ** > fReferences
ReweightableSpectrum & operator=(const ReweightableSpectrum &rhs)
assert(nhit_max >=nhit_nbins)
NDOscillatableSpectrum & ana::NDOscillatableSpectrum::operator= ( NDOscillatableSpectrum &&  rhs)

Definition at line 94 of file NDOscillatableSpectrum.cxx.

References ana::assert(), ana::ReweightableSpectrum::fReferences, and ana::ReweightableSpectrum::operator=().

95  {
96  if(this == &rhs) return *this;
97 
99 
100  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
101  assert( fReferences.empty() ); // Copying with pending loads is unexpected
102 
103  return *this;
104  }
std::set< ReweightableSpectrum ** > fReferences
ReweightableSpectrum & operator=(const ReweightableSpectrum &rhs)
assert(nhit_max >=nhit_nbins)
Spectrum ana::NDOscillatableSpectrum::Oscillated ( osc::IOscCalc calc,
int  from,
int  to 
) const

Definition at line 107 of file NDOscillatableSpectrum.cxx.

References ana::ReweightableSpectrum::WeightedBy().

Referenced by ana::NDPredictionSterile::Predict(), ana::NDPredictionSterile::PredictComponent(), and Uninitialized().

109  {
110  const NDOscCurve curve(calc, from, to);
111  return WeightedBy(curve);
112  }
Spectrum WeightedBy(const Ratio &weights) const
Reco spectrum with truth weights applied.
ReweightableSpectrum & ana::ReweightableSpectrum::PlusEqualsHelper ( const ReweightableSpectrum rhs,
int  sign 
)
protectedinherited

Definition at line 162 of file ReweightableSpectrum.cxx.

References ana::AlmostEqual(), om::cout, allTimeWatchdog::endl, ana::ReweightableSpectrum::fLivetime, ana::ReweightableSpectrum::fMat, and ana::ReweightableSpectrum::fPOT.

Referenced by ana::ReweightableSpectrum::operator+=(), ana::ReweightableSpectrum::operator-=(), and ana::ReweightableSpectrum::ReweightableSpectrum().

163  {
164  // In this case it would be OK to have no POT/livetime
165  if(rhs.fMat.sum() == 0) return *this;
166 
167 
168  if((!fPOT && !fLivetime) || (!rhs.fPOT && !rhs.fLivetime)){
169  std::cout << "Error: can't sum ReweightableSpectrum with no POT or livetime."
170  << fPOT << " " << rhs.fPOT
171  << std::endl;
172  // abort();
173  return *this;
174  }
175 
176  if(!fLivetime && !rhs.fPOT){
177  std::cout << "Error: can't sum ReweightableSpectrum with POT ("
178  << fPOT << ") but no livetime and ReweightableSpectrum with livetime ("
179  << rhs.fLivetime << " sec) but no POT." << std::endl;
180  abort();
181  }
182 
183  if(!fPOT && !rhs.fLivetime){
184  std::cout << "Error: can't sum ReweightableSpectrum with livetime ("
185  << fLivetime << " sec) but no POT and ReweightableSpectrum with POT ("
186  << rhs.fPOT << ") but no livetime." << std::endl;
187  abort();
188  }
189 
190  // And now there are still a bunch of good cases to consider
191 
192  if(fPOT && rhs.fPOT){
193  // Scale by POT when possible
194  fMat += rhs.fMat * sign*fPOT/rhs.fPOT;
195 
196  if(fLivetime && rhs.fLivetime){
197  // If POT/livetime ratios match, keep regular lifetime, otherwise zero
198  // it out.
199  if(AlmostEqual(fLivetime*rhs.fPOT, rhs.fLivetime*fPOT))
200  fLivetime = 0;
201  }
202  if(!fLivetime && rhs.fLivetime){
203  // If the RHS has a livetime and we don't, copy it in (suitably scaled)
204  fLivetime = rhs.fLivetime * fPOT/rhs.fPOT;
205  }
206  // Otherwise, keep our own livetime (if any)
207 
208  return *this;
209  }
210 
211  if(fLivetime && rhs.fLivetime){
212  // Scale by livetime, the only thing in common
213  fMat += rhs.fMat * sign*fLivetime/rhs.fLivetime;
214 
215  if(!fPOT && rhs.fPOT){
216  // If the RHS has a POT and we don't, copy it in (suitably scaled)
217  fPOT = rhs.fPOT * fLivetime/rhs.fLivetime;
218  }
219  // Otherwise, keep our own POT (if any)
220 
221  return *this;
222  }
223 
224  // That should have been all the cases. I definitely want to know what
225  // happened if it wasn't.
226  std::cout << "ReweightableSpectrum::operator+=(). How did we get here? "
227  << fPOT << " " << fLivetime << " "
228  << rhs.fPOT << " " << rhs.fLivetime << std::endl;
229  abort();
230  }
bool AlmostEqual(double a, double b, double eps)
Definition: UtilsExt.cxx:40
OStream cout
Definition: OStream.cxx:6
def sign(x)
Definition: canMan.py:197
double ana::ReweightableSpectrum::POT ( ) const
inlineinherited
void ana::ReweightableSpectrum::RemoveLoader ( ReweightableSpectrum **  ref)
protectedinherited

Definition at line 267 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fReferences.

Referenced by ana::ReweightableSpectrum::ReweightableSpectrum().

268  {
269  fReferences.erase(ref);
270  }
std::set< ReweightableSpectrum ** > fReferences
void ana::ReweightableSpectrum::ReweightToRecoSpectrum ( const Spectrum target)
inherited

Recale bins so that Unweighted will return target.

Definition at line 151 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fMat, ana::Ratio::GetEigen(), ratio(), and ana::ReweightableSpectrum::UnWeighted().

Referenced by ana::FluxReweight::Eval(), ana::TruthReweight::Eval(), ana::RecoReweight::Eval(), ana::PredictionExtendToPeripheral::ExtendRecoWeightOscillatable(), ana::ReweightableSpectrum::Livetime(), ana::TruthReweight::SavePlots(), ana::UnfoldIterative::Truth(), and ana::OscillatableSpectrum::Uninitialized().

152  {
153  // This is a big component of what extrapolations do, so it should be fast
154 
155  const Ratio ratio(target, UnWeighted());
156  // We want to multiply all the columns by this ratio
157 
158  fMat *= ratio.GetEigen().matrix().asDiagonal();
159  }
const XML_Char * target
Definition: expat.h:268
TH1 * ratio(TH1 *h1, TH1 *h2)
void ana::ReweightableSpectrum::ReweightToTrueSpectrum ( const Spectrum target)
inherited

Rescale bins so that WeightingVariable will return target.

Definition at line 140 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fMat, ana::Ratio::GetEigen(), ratio(), and ana::ReweightableSpectrum::WeightingVariable().

Referenced by ana::TruthReweight::Eval(), ana::ReweightableSpectrum::Livetime(), ana::UnfoldIterative::Truth(), and ana::OscillatableSpectrum::Uninitialized().

141  {
142  // This is a big component of what extrapolations do, so it should be fast
143 
144  const Ratio ratio(target, WeightingVariable());
145  // We want to multiply all the rows by this ratio, so left-multiply
146 
147  fMat = ratio.GetEigen().matrix().asDiagonal() * fMat;
148  }
const XML_Char * target
Definition: expat.h:268
TH1 * ratio(TH1 *h1, TH1 *h2)
void ana::NDOscillatableSpectrum::SaveTo ( TDirectory *  dir,
const std::string name 
) const

Definition at line 115 of file NDOscillatableSpectrum.cxx.

References ana::ReweightableSpectrum::_SaveTo().

Referenced by Scale().

116  {
117  _SaveTo(dir, name, "NDOscillatableSpectrum");
118  }
const XML_Char * name
Definition: expat.h:151
void _SaveTo(TDirectory *dir, const std::string &name, const std::string &type) const
TDirectory * dir
Definition: macro.C:5
void ana::NDOscillatableSpectrum::Scale ( double  x)
inline
TH2D * ana::ReweightableSpectrum::ToTH2 ( double  pot) const
inherited

Definition at line 65 of file ReweightableSpectrum.cxx.

References ana::assert(), ana::ReweightableSpectrum::fAxisX, ana::ReweightableSpectrum::fAxisY, ana::ReweightableSpectrum::fMat, ana::ReweightableSpectrum::fPOT, ana::LabelsAndBins::GetBins1D(), ana::LabelsAndBins::GetLabel1D(), MECModelEnuComparisons::i, calib::j, ana::MakeTH2D(), runNovaSAM::ret, and ana::UniqueName().

Referenced by ana::ReweightableSpectrum::_SaveTo(), demo2(), demo3(), ana::MichelDecomp::GetSum(), ana::MichelDecomp::GetTemplateContent(), ana::MichelDecomp::MDCMPLogLikelihood(), ana::PlotAllRecoTrue(), ana::CrossSectionAnalysis::PlotRecoToTrueMatrix(), ana::SingleNucAnalysis::PlotRecoToTrueMatrix2D(), ana::NumuCC2p2hAnalysis::PlotRecoToTrueMatrix2D(), ana::MichelDecomp::SaveTempPlots(), ana::UnfoldSVD::Truth(), Unfold1D(), Unfold3D(), ana::UnfoldTikhonov::UnfoldTikhonov(), ana::ReweightableSpectrum::Uninitialized(), and ana::OscillatableSpectrum::Uninitialized().

66  {
67  // Could have a file temporarily open
68  DontAddDirectory guard;
69 
70  TH2D* ret = MakeTH2D(UniqueName().c_str(), "", fAxisX.GetBins1D(), fAxisY.GetBins1D());
71 
72  for(int i = 0; i < fMat.rows(); ++i){
73  for(int j = 0; j < fMat.cols(); ++j){
74  ret->SetBinContent(j, i, fMat(i, j));
75  }
76  }
77 
78  if(fPOT){
79  ret->Scale(pot/fPOT);
80  }
81  else{
82  // How did it get events with no POT?
83  assert(ret->Integral() == 0);
84  }
85 
86  ret->GetXaxis()->SetTitle(fAxisX.GetLabel1D().c_str());
87  ret->GetYaxis()->SetTitle(fAxisY.GetLabel1D().c_str());
88 
89  return ret;
90  }
const std::string & GetLabel1D() const
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
#define pot
const double j
Definition: BetheBloch.cxx:29
TH2D * MakeTH2D(const char *name, const char *title, const Binning &binsx, const Binning &binsy)
Utility function to avoid 4-way combinatorial explosion on the bin types.
Definition: UtilsExt.cxx:86
assert(nhit_max >=nhit_nbins)
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:29
static NDOscillatableSpectrum ana::NDOscillatableSpectrum::Uninitialized ( )
inlinestatic

The only valid thing to do with such a spectrum is to assign something else into it.

Definition at line 48 of file NDOscillatableSpectrum.h.

References calc, NDOscillatableSpectrum(), operator=(), Oscillated(), and ~NDOscillatableSpectrum().

48 {return NDOscillatableSpectrum();}
NDOscillatableSpectrum()
Constructor for Uninitialized()
Spectrum ana::ReweightableSpectrum::UnWeighted ( ) const
inherited
Spectrum ana::ReweightableSpectrum::WeightedBy ( const Ratio weights) const
inherited

Reco spectrum with truth weights applied.

Definition at line 123 of file ReweightableSpectrum.cxx.

References ana::Hist::Adopt(), ana::Hist::AdoptStan(), ana::ReweightableSpectrum::fAxisX, ana::ReweightableSpectrum::fLivetime, ana::ReweightableSpectrum::fMat, ana::ReweightableSpectrum::fPOT, ana::Ratio::GetEigen(), ana::Ratio::GetEigenStan(), and ana::Ratio::HasStan().

Referenced by ana::OscillatableSpectrum::_Oscillated(), ana::ReweightableSpectrum::Livetime(), and Oscillated().

124  {
125  if(!ws.HasStan()){
126  const Eigen::VectorXd& vec = ws.GetEigen();
127 
128  return Spectrum(Hist::Adopt(Eigen::ArrayXd(vec.transpose() * fMat)),
129  fAxisX, fPOT, fLivetime);
130  }
131  else{
132  const Eigen::VectorXstan& vec = ws.GetEigenStan();
133 
134  return Spectrum(Hist::AdoptStan(vec.transpose() * fMat),
135  fAxisX, fPOT, fLivetime);
136  }
137  }
Eigen::Matrix< stan::math::var, Eigen::Dynamic, 1 > VectorXstan
Definition: Hist.h:22
Eigen::VectorXd vec
std::vector< float > Spectrum
Definition: Constants.h:610
static Hist AdoptStan(Eigen::ArrayXstan &&v)
Definition: Hist.cxx:140
static Hist Adopt(Eigen::ArrayXd &&v)
Definition: Hist.cxx:149
Spectrum ana::ReweightableSpectrum::WeightingVariable ( ) const
inherited

Friends And Related Function Documentation

friend class NullLoader
friend

Definition at line 30 of file NDOscillatableSpectrum.h.

friend class SpectrumLoader
friend

Definition at line 29 of file NDOscillatableSpectrum.h.

friend class SpectrumLoaderBase
friend

Definition at line 28 of file NDOscillatableSpectrum.h.

Member Data Documentation

LabelsAndBins ana::ReweightableSpectrum::fAxisX
protectedinherited
LabelsAndBins ana::ReweightableSpectrum::fAxisY
protectedinherited
double ana::ReweightableSpectrum::fLivetime
protectedinherited
Eigen::MatrixXd ana::ReweightableSpectrum::fMat
protectedinherited
double ana::ReweightableSpectrum::fPOT
protectedinherited
std::set<ReweightableSpectrum**> ana::ReweightableSpectrum::fReferences
protectedinherited

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