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-11-28/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
 
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 OscillatableSpectrum Uninitialized ()
 
static std::unique_ptr< OscillatableSpectrumLoadFrom (TDirectory *dir, const std::string &name)
 

Protected Member Functions

 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
 
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 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 39 of file OscillatableSpectrum.cxx.

47  HistAxis("True Energy (GeV)", kTrueEnergyBins, kTrueE),
48  kHasNu && cut, shift, wei)
49  {
50  }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
const char * label
const Var kTrueE([](const caf::SRProxy *sr){assert(sr->mc.nnu==1);return sr->mc.nu[0].E;})
Definition: Vars.cxx:85
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:14
loader
Definition: demo0.py:10
const Binning bins
Definition: NumuCC_CPiBin.h:8
const Cut cut
Definition: exporter_fd.C:30
const Cut kHasNu([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;assert(sr->mc.nnu==1);return true;})
Definition: TruthCuts.h:56
ana::OscillatableSpectrum::OscillatableSpectrum ( SpectrumLoaderBase loader,
const HistAxis axis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 53 of file OscillatableSpectrum.cxx.

59  HistAxis("True Energy (GeV)", kTrueEnergyBins, kTrueE),
60  kHasNu && cut, shift, wei)
61  {
62  }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
const Var kTrueE([](const caf::SRProxy *sr){assert(sr->mc.nnu==1);return sr->mc.nu[0].E;})
Definition: Vars.cxx:85
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:14
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
const Cut kHasNu([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return false;assert(sr->mc.nnu==1);return true;})
Definition: TruthCuts.h:56
ana::OscillatableSpectrum::OscillatableSpectrum ( const Eigen::MatrixXd &&  mat,
const HistAxis recoAxis,
double  pot,
double  livetime 
)

Definition at line 65 of file OscillatableSpectrum.cxx.

68  : ReweightableSpectrum(std::move(mat), recoAxis,
69  HistAxis("True Energy (GeV)", kTrueEnergyBins, kTrueE),
70  pot, livetime)
71  {
72  }
_HistAxis< Var > HistAxis
Definition: HistAxis.h:103
const Var kTrueE([](const caf::SRProxy *sr){assert(sr->mc.nnu==1);return sr->mc.nu[0].E;})
Definition: Vars.cxx:85
#define pot
const Binning kTrueEnergyBins
Default true-energy bin edges.
Definition: Binning.h:14
double livetime
Definition: saveFDMCHists.C:21
Eigen::MatrixXd mat
ana::OscillatableSpectrum::~OscillatableSpectrum ( )

Definition at line 75 of file OscillatableSpectrum.cxx.

76  {
77  }
ana::OscillatableSpectrum::OscillatableSpectrum ( const OscillatableSpectrum rhs)

Copy constructor.

Definition at line 80 of file OscillatableSpectrum.cxx.

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

82  {
83  if(rhs.fCache->hash){
84  fCache->spect = rhs.fCache->spect;
85  fCache->hash = std::make_unique<TMD5>(*rhs.fCache->hash);
86  }
87 
88  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
89  }
ThreadLocal< OscCache > fCache
assert(nhit_max >=nhit_nbins)
ana::OscillatableSpectrum::OscillatableSpectrum ( OscillatableSpectrum &&  rhs)

Definition at line 92 of file OscillatableSpectrum.cxx.

References ana::assert(), and fCache.

94  {
95  if(rhs.fCache->hash){
96  fCache->spect = std::move(rhs.fCache->spect);
97  fCache->hash = std::move(rhs.fCache->hash);
98  }
99 
100  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
101  }
ThreadLocal< OscCache > fCache
assert(nhit_max >=nhit_nbins)
ana::OscillatableSpectrum::OscillatableSpectrum ( )
inlineprotected

Constructor for Uninitialized()

Definition at line 103 of file OscillatableSpectrum.h.

104  {
105  }

Member Function Documentation

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

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

148  {
149  TMD5* hash = calc->GetParamsHash();
150  if(hash && fCache->hash && *hash == *fCache->hash){
151  delete hash;
152  return fCache->spect;
153  }
154 
155  const OscCurve curve(calc, from, to);
156  const Spectrum ret = WeightedBy(curve);
157  if(hash){
158  fCache->spect = ret;
159  fCache->hash.reset(hash);
160  }
161 
162  return ret;
163  }
ThreadLocal< OscCache > fCache
Spectrum WeightedBy(const Ratio &weights) const
Reco spectrum with truth weights applied.
std::vector< float > Spectrum
Definition: Constants.h:610
virtual TMD5 * GetParamsHash() const
Use to check two calculators are in the same state.
Definition: IOscCalc.h:39
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(), ana::NDOscillatableSpectrum::SaveTo(), ana::ReweightableSpectrum::SaveTo(), and 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< OscillatableSpectrum > ana::OscillatableSpectrum::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 224 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, string, cvnie::subdir, and getGoodRuns4SAM::tag.

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

225  {
226  dir = dir->GetDirectory(name.c_str()); // switch to subdir
227  assert(dir);
228 
229  DontAddDirectory guard;
230 
231  TObjString* tag = (TObjString*)dir->Get("type");
232  assert(tag);
233  assert(tag->GetString() == "OscillatableSpectrum");
234  delete tag;
235 
236  TH2D* spect = (TH2D*)dir->Get("hist");
237  assert(spect);
238  TH1* hPot = (TH1*)dir->Get("pot");
239  assert(hPot);
240  TH1* hLivetime = (TH1*)dir->Get("livetime");
241  assert(hLivetime);
242 
243  std::vector<std::string> labels;
244  std::vector<Binning> bins;
245 
246  for(int i = 0; ; ++i){
247  const std::string subname = TString::Format("bins%d", i).Data();
248  TDirectory* subdir = dir->GetDirectory(subname.c_str());
249  if(!subdir) break;
250  delete subdir;
251  bins.push_back(*Binning::LoadFrom(dir, subname));
252  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
253  labels.push_back(label ? label->GetString().Data() : "");
254  delete label;
255  }
256 
257  delete dir;
258 
259  auto ret = std::make_unique<OscillatableSpectrum>(kNullLoader,
260  HistAxis(labels, bins),
261  kNoCut);
262 
263  // ROOT histogram storage is row-major, but Eigen is column-major by
264  // default
265  typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen:: Dynamic, Eigen::RowMajor> MatRowMajor;
266  ret->fMat = Eigen::Map<MatRowMajor>(spect->GetArray(),
267  ret->fMat.rows(),
268  ret->fMat.cols());
269 
270  delete spect;
271 
272  ret->fPOT = hPot->Integral(0, -1);
273  ret->fLivetime = hLivetime->Integral(0, -1);
274 
275  delete hPot;
276  delete hLivetime;
277 
278  return ret;
279  }
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  }
OscillatableSpectrum ana::OscillatableSpectrum::operator+ ( const OscillatableSpectrum rhs) const

Definition at line 191 of file OscillatableSpectrum.cxx.

References runNovaSAM::ret.

192  {
193  OscillatableSpectrum ret = *this;
194  ret += rhs;
195  return ret;
196  }
OscillatableSpectrum()
Constructor for Uninitialized()
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 operator+=().

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

Definition at line 180 of file OscillatableSpectrum.cxx.

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

181  {
183 
184  // invalidate
185  fCache->hash.reset(nullptr);
186 
187  return *this;
188  }
ReweightableSpectrum & operator+=(const ReweightableSpectrum &rhs)
ThreadLocal< OscCache > fCache
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  }
OscillatableSpectrum ana::OscillatableSpectrum::operator- ( const OscillatableSpectrum rhs) const

Definition at line 210 of file OscillatableSpectrum.cxx.

References runNovaSAM::ret.

211  {
212  OscillatableSpectrum ret = *this;
213  ret -= rhs;
214  return ret;
215  }
OscillatableSpectrum()
Constructor for Uninitialized()
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 operator-=().

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

Definition at line 199 of file OscillatableSpectrum.cxx.

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

200  {
202 
203  // invalidate
204  fCache->hash.reset(nullptr);
205 
206  return *this;
207  }
ThreadLocal< OscCache > fCache
ReweightableSpectrum & operator-=(const ReweightableSpectrum &rhs)
OscillatableSpectrum & ana::OscillatableSpectrum::operator= ( const OscillatableSpectrum rhs)

Assignment operator.

Definition at line 104 of file OscillatableSpectrum.cxx.

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

105  {
106  if(this == &rhs) return *this;
107 
109 
110  if(rhs.fCache->hash){
111  fCache->spect = rhs.fCache->spect;
112  fCache->hash = std::make_unique<TMD5>(*rhs.fCache->hash);
113  }
114  else{
115  fCache->hash.reset();
116  }
117 
118  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
119  assert( fReferences.empty() ); // Copying with pending loads is unexpected
120 
121  return *this;
122  }
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 125 of file OscillatableSpectrum.cxx.

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

126  {
127  if(this == &rhs) return *this;
128 
130 
131  if(rhs.fCache->hash){
132  fCache->spect = std::move(rhs.fCache->spect);
133  fCache->hash = std::move(rhs.fCache->hash);
134  }
135  else{
136  fCache->hash.reset();
137  }
138 
139  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
140  assert( fReferences.empty() ); // Copying with pending loads is unexpected
141 
142  return *this;
143  }
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 173 of file OscillatableSpectrum.cxx.

References _Oscillated().

175  {
176  return _Oscillated(calc, from, to);
177  }
Spectrum _Oscillated(osc::_IOscCalc< T > *calc, int from, int to) const
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 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 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::OscillatableSpectrum::SaveTo ( TDirectory *  dir,
const std::string name 
) const

Definition at line 218 of file OscillatableSpectrum.cxx.

References ana::ReweightableSpectrum::_SaveTo().

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

219  {
220  _SaveTo(dir, name, "OscillatableSpectrum");
221  }
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 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 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
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 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 _Oscillated(), ana::ReweightableSpectrum::Livetime(), and ana::NDOscillatableSpectrum::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 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

LabelsAndBins ana::ReweightableSpectrum::fAxisX
protectedinherited
LabelsAndBins ana::ReweightableSpectrum::fAxisY
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

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