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

Spectrum with true energy information, allowing it to be oscillated More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-09-23/CAFAna/Core/OscillatableSpectrum.h"

Inheritance diagram for ana::OscillatableSpectrum:
ana::ReweightableSpectrum

Public Member Functions

 OscillatableSpectrum (const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 OscillatableSpectrum (SpectrumLoaderBase &loader, const HistAxis &axis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 OscillatableSpectrum (const Eigen::MatrixXd &&mat, const HistAxis &recoAxis, double pot, double livetime)
 
 ~OscillatableSpectrum ()
 
 OscillatableSpectrum (const OscillatableSpectrum &rhs)
 Copy constructor. More...
 
 OscillatableSpectrum (OscillatableSpectrum &&rhs)
 
OscillatableSpectrumoperator= (const OscillatableSpectrum &rhs)
 Assignment operator. More...
 
OscillatableSpectrumoperator= (OscillatableSpectrum &&rhs)
 
Spectrum Unoscillated () const
 
Spectrum TrueEnergy () const
 
Spectrum Oscillated (osc::IOscCalc *calc, int from, int to) const
 
Spectrum Oscillated (osc::IOscCalcStan *calc, int from, int to) const
 
OscillatableSpectrumoperator+= (const OscillatableSpectrum &rhs)
 
OscillatableSpectrum operator+ (const OscillatableSpectrum &rhs) const
 
OscillatableSpectrumoperator-= (const OscillatableSpectrum &rhs)
 
OscillatableSpectrum operator- (const OscillatableSpectrum &rhs) const
 
void SaveTo (TDirectory *dir, const std::string &name) const
 
const VarReweightVar () const
 The variable that will be used to fill the y-axis. More...
 
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
 
Binning GetTrueBinning () const
 
Eigen::MatrixXd GetEigen (double pot) const
 

Static Public Member Functions

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

Protected Member Functions

 OscillatableSpectrum (const HistAxis &recoAxis, const Binning &binsY, const Var &rwVar)
 
 OscillatableSpectrum ()
 Constructor for Uninitialized() More...
 
template<class T >
Spectrum _Oscillated (osc::_IOscCalc< T > *calc, int from, int to) const
 
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

ThreadLocal< OscCachefCache
 
Var fRWVar
 What goes on the y axis? More...
 
Eigen::MatrixXd fMat
 
double fPOT
 
double fLivetime
 
HistAxis fAxisX
 
Binning fBinsY
 
std::string fTrueLabel
 
std::set< ReweightableSpectrum ** > fReferences
 

Friends

class SpectrumLoaderBase
 
class SpectrumLoader
 
class NullLoader
 

Detailed Description

Spectrum with true energy information, allowing it to be oscillated

Definition at line 36 of file OscillatableSpectrum.h.

Constructor & Destructor Documentation

ana::OscillatableSpectrum::OscillatableSpectrum ( 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 29 of file OscillatableSpectrum.cxx.

37  HistAxis("True Energy (GeV)", kTrueEnergyBins, kTrueE),
38  cut, shift, wei)
39  {
40  }
const char * label
const Var kTrueE([](const caf::SRProxy *sr){return(sr->mc.nnu==0)?0.:float(sr->mc.nu[0].E);})
Definition: Vars.cxx:85
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:72
loader
Definition: demo0.py:10
const Binning bins
Definition: NumuCC_CPiBin.h:8
const Cut cut
Definition: exporter_fd.C:30
GenericHistAxis< Var > HistAxis
Definition: HistAxis.h:111
ana::OscillatableSpectrum::OscillatableSpectrum ( SpectrumLoaderBase loader,
const HistAxis axis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 43 of file OscillatableSpectrum.cxx.

49  HistAxis("True Energy (GeV)", kTrueEnergyBins, kTrueE),
50  cut, shift, wei)
51  {
52  }
const Var kTrueE([](const caf::SRProxy *sr){return(sr->mc.nnu==0)?0.:float(sr->mc.nu[0].E);})
Definition: Vars.cxx:85
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:72
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
GenericHistAxis< Var > HistAxis
Definition: HistAxis.h:111
ana::OscillatableSpectrum::OscillatableSpectrum ( const Eigen::MatrixXd &&  mat,
const HistAxis recoAxis,
double  pot,
double  livetime 
)

Definition at line 55 of file OscillatableSpectrum.cxx.

58  : ReweightableSpectrum(std::move(mat), recoAxis,
59  HistAxis("True Energy (GeV)", kTrueEnergyBins, kTrueE),
60  pot, livetime)
61  {
62  }
const Var kTrueE([](const caf::SRProxy *sr){return(sr->mc.nnu==0)?0.:float(sr->mc.nu[0].E);})
Definition: Vars.cxx:85
#define pot
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:72
double livetime
Definition: saveFDMCHists.C:21
GenericHistAxis< Var > HistAxis
Definition: HistAxis.h:111
Eigen::MatrixXd mat
ana::OscillatableSpectrum::~OscillatableSpectrum ( )

Definition at line 65 of file OscillatableSpectrum.cxx.

66  {
67  }
ana::OscillatableSpectrum::OscillatableSpectrum ( const OscillatableSpectrum rhs)

Copy constructor.

Definition at line 70 of file OscillatableSpectrum.cxx.

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

72  {
73  if(rhs.fCache->hash){
74  fCache->spect = rhs.fCache->spect;
75  fCache->hash = std::make_unique<TMD5>(*rhs.fCache->hash);
76  }
77 
78  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
79  }
ThreadLocal< OscCache > fCache
assert(nhit_max >=nhit_nbins)
ana::OscillatableSpectrum::OscillatableSpectrum ( OscillatableSpectrum &&  rhs)

Definition at line 82 of file OscillatableSpectrum.cxx.

References ana::assert(), and fCache.

84  {
85  if(rhs.fCache->hash){
86  fCache->spect = std::move(rhs.fCache->spect);
87  fCache->hash = std::move(rhs.fCache->hash);
88  }
89 
90  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
91  }
ThreadLocal< OscCache > fCache
assert(nhit_max >=nhit_nbins)
ana::OscillatableSpectrum::OscillatableSpectrum ( const HistAxis recoAxis,
const Binning binsY,
const Var rwVar 
)
inlineprotected

Definition at line 102 of file OscillatableSpectrum.h.

105  : ReweightableSpectrum(recoAxis, binsY, rwVar)
106  {
107  }
ana::OscillatableSpectrum::OscillatableSpectrum ( )
inlineprotected

Constructor for Uninitialized()

Definition at line 110 of file OscillatableSpectrum.h.

111  {
112  }

Member Function Documentation

template<class T >
Spectrum ana::OscillatableSpectrum::_Oscillated ( osc::_IOscCalc< T > *  calc,
int  from,
int  to 
) const
protected

Definition at line 137 of file OscillatableSpectrum.cxx.

References fCache, osc::_IOscCalc< T >::GetParamsHash(), samweb_client.utility::hash, runNovaSAM::ret, and ana::ReweightableSpectrum::WeightedBy().

Referenced by operator=(), and Oscillated().

138  {
139  TMD5* hash = calc->GetParamsHash();
140  if(hash && fCache->hash && *hash == *fCache->hash){
141  delete hash;
142  return fCache->spect;
143  }
144 
145  const OscCurve curve(calc, from, to);
146  const Spectrum ret = WeightedBy(curve);
147  if(hash){
148  fCache->spect = ret;
149  fCache->hash.reset(hash);
150  }
151 
152  return ret;
153  }
ThreadLocal< OscCache > fCache
Spectrum WeightedBy(const Ratio &weights) const
Reco spectrum with truth weights applied.
std::vector< float > Spectrum
Definition: Constants.h:527
virtual TMD5 * GetParamsHash() const
Use to check two calculators are in the same state.
Definition: IOscCalc.h:34
void ana::ReweightableSpectrum::_SaveTo ( TDirectory *  dir,
const std::string &  name,
const std::string &  type 
) const
protectedinherited

Definition at line 314 of file ReweightableSpectrum.cxx.

References dir, ana::ReweightableSpectrum::fAxisX, ana::ReweightableSpectrum::fLivetime, genie::utils::style::Format(), ana::ReweightableSpectrum::fPOT, ana::ReweightableSpectrum::fTrueLabel, ana::GenericHistAxis< T >::GetBinnings(), ana::GenericHistAxis< T >::GetLabels(), make_syst_table_plots::h, MECModelEnuComparisons::i, ana::GenericHistAxis< T >::NDimensions(), tmp, ana::ReweightableSpectrum::ToTH2(), and Write().

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

317  {
318  TDirectory* tmp = gDirectory;
319 
320  dir = dir->mkdir(name.c_str()); // switch to sbudir
321  dir->cd();
322 
323  TObjString(type.c_str()).Write("type");
324 
325  TH2* h = ToTH2(fPOT);
326  h->Write("hist");
327 
328  TH1D hPot("", "", 1, 0, 1);
329  hPot.Fill(.5, fPOT);
330  hPot.Write("pot");
331  TH1D hLivetime("", "", 1, 0, 1);
332  hLivetime.Fill(.5, fLivetime);
333  hLivetime.Write("livetime");
334 
335  for(unsigned int i = 0; i < fAxisX.NDimensions(); ++i){
336  TObjString(fAxisX.GetLabels()[i].c_str()).Write(TString::Format("label%d", i).Data());
337  fAxisX.GetBinnings()[i].SaveTo(dir, TString::Format("bins%d", i).Data());
338  }
339 
340  TObjString(fTrueLabel.c_str()).Write("true_label");
341 
342  dir->Write();
343  delete dir;
344 
345  delete h;
346 
347  tmp->cd();
348  }
const XML_Char * name
Definition: expat.h:151
unsigned int NDimensions() const
Definition: HistAxis.h:87
const std::vector< std::string > & GetLabels() const
Definition: HistAxis.h:90
Float_t tmp
Definition: plot.C:36
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< Binning > & GetBinnings() const
Definition: HistAxis.h:91
TH2D * ToTH2(double pot) const
gm Write()
void ana::ReweightableSpectrum::AddLoader ( ReweightableSpectrum **  ref)
protectedinherited

Definition at line 302 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fReferences.

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

303  {
304  fReferences.insert(ref);
305  }
std::set< ReweightableSpectrum ** > fReferences
void ana::ReweightableSpectrum::Clear ( )
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
Binning ana::ReweightableSpectrum::GetTrueBinning ( ) const
inlineinherited

Definition at line 88 of file ReweightableSpectrum.h.

References ana::ReweightableSpectrum::fBinsY.

double ana::ReweightableSpectrum::Livetime ( ) const
inlineinherited
std::unique_ptr< OscillatableSpectrum > ana::OscillatableSpectrum::LoadFrom ( TDirectory *  dir,
const std::string &  name 
)
static

Definition at line 214 of file OscillatableSpectrum.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, cvnie::subdir, and getGoodRuns4SAM::tag.

Referenced by ana::FluxReweight::LoadFrom(), ana::TrivialExtrap::LoadFrom(), ana::NoReweight::LoadFrom(), ana::TruthReweight::LoadFrom(), and ana::RecoReweight::LoadFrom().

215  {
216  dir = dir->GetDirectory(name.c_str()); // switch to subdir
217  assert(dir);
218 
219  DontAddDirectory guard;
220 
221  TObjString* tag = (TObjString*)dir->Get("type");
222  assert(tag);
223  assert(tag->GetString() == "OscillatableSpectrum");
224  delete tag;
225 
226  TH2D* spect = (TH2D*)dir->Get("hist");
227  assert(spect);
228  TH1* hPot = (TH1*)dir->Get("pot");
229  assert(hPot);
230  TH1* hLivetime = (TH1*)dir->Get("livetime");
231  assert(hLivetime);
232 
233  std::vector<std::string> labels;
234  std::vector<Binning> bins;
235 
236  for(int i = 0; ; ++i){
237  const std::string subname = TString::Format("bins%d", i).Data();
238  TDirectory* subdir = dir->GetDirectory(subname.c_str());
239  if(!subdir) break;
240  delete subdir;
241  bins.push_back(*Binning::LoadFrom(dir, subname));
242  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
243  labels.push_back(label ? label->GetString().Data() : "");
244  delete label;
245  }
246 
247  delete dir;
248 
249  auto ret = std::make_unique<OscillatableSpectrum>(kNullLoader,
250  HistAxis(labels, bins),
251  kNoCut);
252 
253  // ROOT histogram storage is row-major, but Eigen is column-major by
254  // default
255  typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen:: Dynamic, Eigen::RowMajor> MatRowMajor;
256  ret->fMat = Eigen::Map<MatRowMajor>(spect->GetArray(),
257  ret->fMat.rows(),
258  ret->fMat.cols());
259 
260  delete spect;
261 
262  ret->fPOT = hPot->Integral(0, -1);
263  ret->fLivetime = hLivetime->Integral(0, -1);
264 
265  delete hPot;
266  delete hLivetime;
267 
268  return ret;
269  }
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Binning.cxx:235
const XML_Char * name
Definition: expat.h:151
subdir
Definition: cvnie.py:7
const char * label
const Binning bins
Definition: NumuCC_CPiBin.h:8
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
TDirectory * dir
Definition: macro.C:5
GenericHistAxis< Var > HistAxis
Definition: HistAxis.h:111
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:117
static NullLoader kNullLoader
Dummy loader that doesn&#39;t load any files.
unsigned int ana::ReweightableSpectrum::NDimensions ( ) const
inlineinherited
ReweightableSpectrum ana::ReweightableSpectrum::operator+ ( const ReweightableSpectrum rhs) const
inherited

Definition at line 268 of file ReweightableSpectrum.cxx.

References runNovaSAM::ret.

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

269  {
270  ReweightableSpectrum ret = *this;
271  ret += rhs;
272  return ret;
273  }
OscillatableSpectrum ana::OscillatableSpectrum::operator+ ( const OscillatableSpectrum rhs) const

Definition at line 181 of file OscillatableSpectrum.cxx.

References runNovaSAM::ret.

182  {
183  OscillatableSpectrum ret = *this;
184  ret += rhs;
185  return ret;
186  }
OscillatableSpectrum()
Constructor for Uninitialized()
ReweightableSpectrum & ana::ReweightableSpectrum::operator+= ( const ReweightableSpectrum rhs)
inherited

Definition at line 262 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::PlusEqualsHelper().

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

263  {
264  return PlusEqualsHelper(rhs, +1);
265  }
ReweightableSpectrum & PlusEqualsHelper(const ReweightableSpectrum &rhs, int sign)
OscillatableSpectrum & ana::OscillatableSpectrum::operator+= ( const OscillatableSpectrum rhs)

Definition at line 170 of file OscillatableSpectrum.cxx.

References fCache, and ana::ReweightableSpectrum::operator+=().

171  {
173 
174  // invalidate
175  fCache->hash.reset(nullptr);
176 
177  return *this;
178  }
ReweightableSpectrum & operator+=(const ReweightableSpectrum &rhs)
ThreadLocal< OscCache > fCache
ReweightableSpectrum ana::ReweightableSpectrum::operator- ( const ReweightableSpectrum rhs) const
inherited

Definition at line 282 of file ReweightableSpectrum.cxx.

References runNovaSAM::ret.

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

283  {
284  ReweightableSpectrum ret = *this;
285  ret -= rhs;
286  return ret;
287  }
OscillatableSpectrum ana::OscillatableSpectrum::operator- ( const OscillatableSpectrum rhs) const

Definition at line 200 of file OscillatableSpectrum.cxx.

References runNovaSAM::ret.

201  {
202  OscillatableSpectrum ret = *this;
203  ret -= rhs;
204  return ret;
205  }
OscillatableSpectrum()
Constructor for Uninitialized()
ReweightableSpectrum & ana::ReweightableSpectrum::operator-= ( const ReweightableSpectrum rhs)
inherited

Definition at line 276 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::PlusEqualsHelper().

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

277  {
278  return PlusEqualsHelper(rhs, -1);
279  }
ReweightableSpectrum & PlusEqualsHelper(const ReweightableSpectrum &rhs, int sign)
OscillatableSpectrum & ana::OscillatableSpectrum::operator-= ( const OscillatableSpectrum rhs)

Definition at line 189 of file OscillatableSpectrum.cxx.

References fCache, and ana::ReweightableSpectrum::operator-=().

190  {
192 
193  // invalidate
194  fCache->hash.reset(nullptr);
195 
196  return *this;
197  }
ThreadLocal< OscCache > fCache
ReweightableSpectrum & operator-=(const ReweightableSpectrum &rhs)
OscillatableSpectrum & ana::OscillatableSpectrum::operator= ( const OscillatableSpectrum rhs)

Assignment operator.

Definition at line 94 of file OscillatableSpectrum.cxx.

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

95  {
96  if(this == &rhs) return *this;
97 
99 
100  if(rhs.fCache->hash){
101  fCache->spect = rhs.fCache->spect;
102  fCache->hash = std::make_unique<TMD5>(*rhs.fCache->hash);
103  }
104  else{
105  fCache->hash.reset();
106  }
107 
108  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
109  assert( fReferences.empty() ); // Copying with pending loads is unexpected
110 
111  return *this;
112  }
ThreadLocal< OscCache > fCache
std::set< ReweightableSpectrum ** > fReferences
ReweightableSpectrum & operator=(const ReweightableSpectrum &rhs)
assert(nhit_max >=nhit_nbins)
OscillatableSpectrum & ana::OscillatableSpectrum::operator= ( OscillatableSpectrum &&  rhs)

Definition at line 115 of file OscillatableSpectrum.cxx.

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

116  {
117  if(this == &rhs) return *this;
118 
120 
121  if(rhs.fCache->hash){
122  fCache->spect = std::move(rhs.fCache->spect);
123  fCache->hash = std::move(rhs.fCache->hash);
124  }
125  else{
126  fCache->hash.reset();
127  }
128 
129  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
130  assert( fReferences.empty() ); // Copying with pending loads is unexpected
131 
132  return *this;
133  }
ThreadLocal< OscCache > fCache
std::set< ReweightableSpectrum ** > fReferences
ReweightableSpectrum & operator=(const ReweightableSpectrum &rhs)
assert(nhit_max >=nhit_nbins)
Spectrum ana::OscillatableSpectrum::Oscillated ( osc::IOscCalc calc,
int  from,
int  to 
) const
Spectrum ana::OscillatableSpectrum::Oscillated ( osc::IOscCalcStan calc,
int  from,
int  to 
) const

Definition at line 163 of file OscillatableSpectrum.cxx.

References _Oscillated().

165  {
166  return _Oscillated(calc, from, to);
167  }
Spectrum _Oscillated(osc::_IOscCalc< T > *calc, int from, int to) const
ReweightableSpectrum & ana::ReweightableSpectrum::PlusEqualsHelper ( const ReweightableSpectrum rhs,
int  sign 
)
protectedinherited

Definition at line 191 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().

192  {
193  // In this case it would be OK to have no POT/livetime
194  if(rhs.fMat.sum() == 0) return *this;
195 
196 
197  if((!fPOT && !fLivetime) || (!rhs.fPOT && !rhs.fLivetime)){
198  std::cout << "Error: can't sum ReweightableSpectrum with no POT or livetime."
199  << fPOT << " " << rhs.fPOT
200  << std::endl;
201  // abort();
202  return *this;
203  }
204 
205  if(!fLivetime && !rhs.fPOT){
206  std::cout << "Error: can't sum ReweightableSpectrum with POT ("
207  << fPOT << ") but no livetime and ReweightableSpectrum with livetime ("
208  << rhs.fLivetime << " sec) but no POT." << std::endl;
209  abort();
210  }
211 
212  if(!fPOT && !rhs.fLivetime){
213  std::cout << "Error: can't sum ReweightableSpectrum with livetime ("
214  << fLivetime << " sec) but no POT and ReweightableSpectrum with POT ("
215  << rhs.fPOT << ") but no livetime." << std::endl;
216  abort();
217  }
218 
219  // And now there are still a bunch of good cases to consider
220 
221  if(fPOT && rhs.fPOT){
222  // Scale by POT when possible
223  fMat += rhs.fMat * sign*fPOT/rhs.fPOT;
224 
225  if(fLivetime && rhs.fLivetime){
226  // If POT/livetime ratios match, keep regular lifetime, otherwise zero
227  // it out.
228  if(AlmostEqual(fLivetime*rhs.fPOT, rhs.fLivetime*fPOT))
229  fLivetime = 0;
230  }
231  if(!fLivetime && rhs.fLivetime){
232  // If the RHS has a livetime and we don't, copy it in (suitably scaled)
233  fLivetime = rhs.fLivetime * fPOT/rhs.fPOT;
234  }
235  // Otherwise, keep our own livetime (if any)
236 
237  return *this;
238  }
239 
240  if(fLivetime && rhs.fLivetime){
241  // Scale by livetime, the only thing in common
242  fMat += rhs.fMat * sign*fLivetime/rhs.fLivetime;
243 
244  if(!fPOT && rhs.fPOT){
245  // If the RHS has a POT and we don't, copy it in (suitably scaled)
246  fPOT = rhs.fPOT * fLivetime/rhs.fLivetime;
247  }
248  // Otherwise, keep our own POT (if any)
249 
250  return *this;
251  }
252 
253  // That should have been all the cases. I definitely want to know what
254  // happened if it wasn't.
255  std::cout << "ReweightableSpectrum::operator+=(). How did we get here? "
256  << fPOT << " " << fLivetime << " "
257  << rhs.fPOT << " " << rhs.fLivetime << std::endl;
258  abort();
259  }
bool AlmostEqual(double a, double b, double eps)
Definition: Utilities.cxx:611
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 296 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fReferences.

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

297  {
298  fReferences.erase(ref);
299  }
std::set< ReweightableSpectrum ** > fReferences
void ana::ReweightableSpectrum::ReweightToRecoSpectrum ( const Spectrum target)
inherited

Recale bins so that Unweighted will return target.

Definition at line 180 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 Uninitialized().

181  {
182  // This is a big component of what extrapolations do, so it should be fast
183 
184  const Ratio ratio(target, UnWeighted());
185  // We want to multiply all the columns by this ratio
186 
187  fMat *= ratio.GetEigen().matrix().asDiagonal();
188  }
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 169 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 Uninitialized().

170  {
171  // This is a big component of what extrapolations do, so it should be fast
172 
173  const Ratio ratio(target, WeightingVariable());
174  // We want to multiply all the rows by this ratio, so left-multiply
175 
176  fMat = ratio.GetEigen().matrix().asDiagonal() * fMat;
177  }
const XML_Char * target
Definition: expat.h:268
TH1 * ratio(TH1 *h1, TH1 *h2)
const Var& ana::ReweightableSpectrum::ReweightVar ( ) const
inlineinherited

The variable that will be used to fill the y-axis.

By convention, return zero if the information can't be obtained, and this event will be skipped.

Definition at line 45 of file ReweightableSpectrum.h.

References ana::ReweightableSpectrum::Fill(), ana::ReweightableSpectrum::fRWVar, pot, ana::ReweightableSpectrum::ToTH2(), w, submit_syst::x, and submit_syst::y.

Referenced by ana::SpectrumLoaderBase::AddReweightableSpectrum().

45 {return fRWVar;}
Var fRWVar
What goes on the y axis?
void ana::OscillatableSpectrum::SaveTo ( TDirectory *  dir,
const std::string &  name 
) const

Definition at line 208 of file OscillatableSpectrum.cxx.

References ana::ReweightableSpectrum::_SaveTo().

Referenced by ana::TruthReweight::SavePlots(), ana::TrivialExtrap::SaveTo(), ana::NoReweight::SaveTo(), ana::TruthReweight::SaveTo(), and ana::RecoReweight::SaveTo().

209  {
210  _SaveTo(dir, name, "OscillatableSpectrum");
211  }
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
TH2D * ana::ReweightableSpectrum::ToTH2 ( double  pot) const
inherited

Definition at line 94 of file ReweightableSpectrum.cxx.

References ana::assert(), ana::ReweightableSpectrum::fAxisX, ana::ReweightableSpectrum::fBinsY, ana::ReweightableSpectrum::fMat, ana::ReweightableSpectrum::fPOT, ana::ReweightableSpectrum::fTrueLabel, ana::GenericHistAxis< T >::GetBins1D(), ana::GenericHistAxis< T >::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::ReweightableSpectrum::ReweightVar(), ana::MichelDecomp::SaveTempPlots(), ana::UnfoldSVD::Truth(), Unfold1D(), Unfold3D(), ana::UnfoldTikhonov::UnfoldTikhonov(), and Uninitialized().

95  {
96  // Could have a file temporarily open
97  DontAddDirectory guard;
98 
99  TH2D* ret = MakeTH2D(UniqueName().c_str(), "", fAxisX.GetBins1D(), fBinsY);
100 
101  for(int i = 0; i < fMat.rows(); ++i){
102  for(int j = 0; j < fMat.cols(); ++j){
103  ret->SetBinContent(j, i, fMat(i, j));
104  }
105  }
106 
107  if(fPOT){
108  ret->Scale(pot/fPOT);
109  }
110  else{
111  // How did it get events with no POT?
112  assert(ret->Integral() == 0);
113  }
114 
115  ret->GetXaxis()->SetTitle(fAxisX.GetLabel1D().c_str());
116  ret->GetYaxis()->SetTitle(fTrueLabel.c_str());
117 
118  return ret;
119  }
#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: Utilities.cxx:227
const std::string & GetLabel1D() const
Definition: HistAxis.cxx:80
assert(nhit_max >=nhit_nbins)
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
Definition: HistAxis.cxx:64
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
Spectrum ana::OscillatableSpectrum::TrueEnergy ( ) const
inline
static OscillatableSpectrum ana::OscillatableSpectrum::Uninitialized ( )
inlinestatic

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

Definition at line 63 of file OscillatableSpectrum.h.

References ana::ReweightableSpectrum::Clear(), ana::ReweightableSpectrum::Fill(), ana::ReweightableSpectrum::ReweightToRecoSpectrum(), ana::ReweightableSpectrum::ReweightToTrueSpectrum(), and ana::ReweightableSpectrum::ToTH2().

63 {return OscillatableSpectrum();}
OscillatableSpectrum()
Constructor for Uninitialized()
Spectrum ana::OscillatableSpectrum::Unoscillated ( ) const
inline
Spectrum ana::ReweightableSpectrum::UnWeighted ( ) const
inherited
Spectrum ana::ReweightableSpectrum::WeightedBy ( const Ratio weights) const
inherited

Reco spectrum with truth weights applied.

Definition at line 152 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 _Oscillated(), ana::ReweightableSpectrum::Livetime(), and ana::NDOscillatableSpectrum::Oscillated().

153  {
154  if(!ws.HasStan()){
155  const Eigen::VectorXd& vec = ws.GetEigen();
156 
157  return Spectrum(Hist::Adopt(Eigen::ArrayXd(vec.transpose() * fMat)),
158  fAxisX, fPOT, fLivetime);
159  }
160  else{
161  const Eigen::VectorXstan& vec = ws.GetEigenStan();
162 
163  return Spectrum(Hist::AdoptStan(vec.transpose() * fMat),
164  fAxisX, fPOT, fLivetime);
165  }
166  }
Eigen::Matrix< stan::math::var, Eigen::Dynamic, 1 > VectorXstan
Definition: Hist.h:21
Eigen::VectorXd vec
std::vector< float > Spectrum
Definition: Constants.h:527
static Hist AdoptStan(Eigen::ArrayXstan &&v)
Definition: Hist.cxx:138
static Hist Adopt(Eigen::ArrayXd &&v)
Definition: Hist.cxx:147
Spectrum ana::ReweightableSpectrum::WeightingVariable ( ) const
inherited

Friends And Related Function Documentation

friend class NullLoader
friend

Definition at line 41 of file OscillatableSpectrum.h.

friend class SpectrumLoader
friend

Definition at line 40 of file OscillatableSpectrum.h.

friend class SpectrumLoaderBase
friend

Definition at line 39 of file OscillatableSpectrum.h.

Member Data Documentation

HistAxis ana::ReweightableSpectrum::fAxisX
protectedinherited
Binning ana::ReweightableSpectrum::fBinsY
protectedinherited
ThreadLocal<OscCache> ana::OscillatableSpectrum::fCache
mutableprotected
double ana::ReweightableSpectrum::fLivetime
protectedinherited
Eigen::MatrixXd ana::ReweightableSpectrum::fMat
protectedinherited
double ana::ReweightableSpectrum::fPOT
protectedinherited
std::set<ReweightableSpectrum**> ana::ReweightableSpectrum::fReferences
protectedinherited
Var ana::ReweightableSpectrum::fRWVar
protectedinherited

What goes on the y axis?

Definition at line 117 of file ReweightableSpectrum.h.

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

std::string ana::ReweightableSpectrum::fTrueLabel
protectedinherited

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