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

Representation of a spectrum in any variable, with associated POT. More...

#include "/cvmfs/nova.opensciencegrid.org/externals/cafanacore/v01.14/src/CAFAna/Core/Spectrum.h"

Inheritance diagram for ana::Spectrum:
ana::_preview::NewSpectrum

Public Types

enum  ESparse { kDense, kSparse }
 

Public Member Functions

template<class T >
 Spectrum (SpectrumLoaderBase &loader, const _HistAxis< _Var< T >> &axis, const _Cut< T > &cut, const SystShifts &shift=kNoShift, const _Var< T > &wei=Unweighted< T >(), ESparse sparse=kDense)
 One constructor to rule them all. More...
 
template<class T >
 Spectrum (const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const _Var< T > &var, const _Cut< T > &cut, const SystShifts &shift=kNoShift, const _Var< T > &wei=Unweighted< T >(), ESparse sparse=kDense)
 
template<class T >
 Spectrum (SpectrumLoaderBase &loader, const _HistAxis< _MultiVar< T >> &axis, const _Cut< T > &cut, const SystShifts &shift=kNoShift, const _Var< T > &wei=Unweighted< T >())
 The only MultiVar variant available. More...
 
 Spectrum (Eigen::ArrayXd &&h, const LabelsAndBins &axis, double pot, double livetime)
 Makes a spectrum from an eigen array. More...
 
 Spectrum (Eigen::ArrayXstan &&h, const LabelsAndBins &axis, double pot, double livetime)
 Makes a spectrum from an eigen array of stan vars. More...
 
template<class T >
 Spectrum (SpectrumLoaderBase &loader, const _HistAxis< _Var< T >> &xAxis, const _HistAxis< _Var< T >> &yAxis, const _Cut< T > &cut, const SystShifts &shift=kNoShift, const _Var< T > &wei=Unweighted< T >(), ESparse sparse=kDense)
 2D Spectrum taking 2 HistAxis More...
 
template<class T >
 Spectrum (const std::string &xLabel, const std::string &yLabel, SpectrumLoaderBase &loader, const Binning &binsx, const _Var< T > &varx, const Binning &binsy, const _Var< T > &vary, const _Cut< T > &cut, const SystShifts &shift=kNoShift, const _Var< T > &wei=Unweighted< T >(), ESparse sparse=kDense)
 2D Spectrum of two Vars More...
 
template<class T >
 Spectrum (SpectrumLoaderBase &loader, const _HistAxis< _Var< T >> &xAxis, const _HistAxis< _Var< T >> &yAxis, const _HistAxis< _Var< T >> &zAxis, const _Cut< T > &cut, const SystShifts &shift=kNoShift, const _Var< T > &wei=Unweighted< T >(), ESparse sparse=kDense)
 3D Spectrum taking 3 HistAxis More...
 
template<class T >
 Spectrum (const std::string &xLabel, const std::string &yLabel, const std::string &zLabel, SpectrumLoaderBase &loader, const Binning &binsx, const _Var< T > &varx, const Binning &binsy, const _Var< T > &vary, const Binning &binsz, const _Var< T > &varz, const _Cut< T > &cut, const SystShifts &shift=kNoShift, const _Var< T > &wei=Unweighted< T >(), ESparse sparse=kDense)
 3D Spectrum of three Vars More...
 
 Spectrum (Hist &&hist, const LabelsAndBins &axis, double pot, double livetime)
 Expert constructor for ReweightableSpectrum et al. More...
 
virtual ~Spectrum ()
 
 Spectrum (const Spectrum &rhs)
 
 Spectrum (Spectrum &&rhs)
 
Spectrumoperator= (const Spectrum &rhs)
 
Spectrumoperator= (Spectrum &&rhs)
 
void Fill (double x, double w=1)
 
TH1D * ToTH1 (double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
 Histogram made from this Spectrum, scaled to some exposure. More...
 
TH1D * ToTH1 (double exposure, EExposureType expotype, EBinType bintype=kBinContent) const
 Histogram made from this Spectrum, scaled to some exposure. More...
 
TH2 * ToTH2 (double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
 Spectrum must be 2D to obtain TH2. More...
 
TH3 * ToTH3 (double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
 Spectrum must be 3D to obtain TH3. More...
 
TH1 * ToTHX (double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
 
bool HasStan () const
 
const Eigen::ArrayXd & GetEigen () const
 NB these don't have POT scaling. For expert high performance ops only! More...
 
const Eigen::ArrayXstanGetEigenStan () const
 
Eigen::ArrayXd GetEigen (double exposure, EExposureType expotype=kPOT) const
 
Eigen::ArrayXstan GetEigenStan (double exposure, EExposureType expotype=kPOT) const
 
double Integral (double exposure, double *err=0, EExposureType expotype=kPOT) const
 Return total number of events scaled to pot. More...
 
double Mean () const
 Return mean of 1D histogram. More...
 
Spectrum MockData (double pot, int seed=0) const
 Mock data is FakeData with Poisson fluctuations applied. More...
 
Spectrum AsimovData (double pot) const
 Asimov data is a MC spectrum scaled to the POT expected in the data. More...
 
Spectrum AsimovData (double pot, double livetime) const
 
Spectrum FakeData (double pot) const
 Synonymous with AsimovData(). Retained for compatibility. More...
 
Spectrum FakeData (double pot, double livetime) const
 Synonymous with AsimovData(). Retained for compatibility. More...
 
double POT () const
 
double Livetime () const
 Seconds. For informational purposes only. No calculations use this. More...
 
void OverridePOT (double newpot)
 DO NOT USE UNLESS YOU ARE 110% CERTAIN THERE ISN'T A BETTER WAY! More...
 
void OverrideLivetime (double newlive)
 DO NOT USE UNLESS YOU ARE 110% CERTAIN THERE ISN'T A BETTER WAY! More...
 
void Clear ()
 
void Scale (double c)
 Multiply this spectrum by a constant c. More...
 
void Scale (const stan::math::var &v)
 
Spectrumoperator+= (const Spectrum &rhs)
 
Spectrum operator+ (const Spectrum &rhs) const
 
Spectrumoperator-= (const Spectrum &rhs)
 
Spectrum operator- (const Spectrum &rhs) const
 
Spectrumoperator*= (const Ratio &rhs)
 
Spectrum operator* (const Ratio &rhs) const
 
Spectrumoperator/= (const Ratio &rhs)
 
Spectrum operator/ (const Ratio &rhs) const
 
void SaveTo (TDirectory *dir, const std::string &name) const
 
unsigned int NDimensions () const
 
const std::vector< std::string > & GetLabels () const
 
const std::vector< Binning > & GetBinnings () const
 

Static Public Member Functions

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

Protected Member Functions

 Spectrum ()
 Constructor for Uninitialized() More...
 
 Spectrum (const LabelsAndBins &axis, ESparse sparse=kDense)
 Helper for constructors. More...
 
void RemoveLoader (Spectrum **)
 
void AddLoader (Spectrum **)
 
SpectrumPlusEqualsHelper (const Spectrum &rhs, int sign)
 Helper for operator+= and operator-=. More...
 

Protected Attributes

Hist fHist
 
double fPOT
 
double fLivetime
 
std::set< Spectrum ** > fReferences
 Things that point at this Spectrum. Maintained by SpectrumLoader. More...
 
LabelsAndBins fAxis
 

Friends

class SpectrumLoaderBase
 
class SpectrumSink
 
class SpectrumSinkBase< Spectrum >
 
class Ratio
 

Detailed Description

Representation of a spectrum in any variable, with associated POT.

Definition at line 40 of file Spectrum.h.

Member Enumeration Documentation

Enumerator
kDense 
kSparse 

Definition at line 48 of file Spectrum.h.

Constructor & Destructor Documentation

template<class T >
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const _HistAxis< _Var< T >> &  axis,
const _Cut< T > &  cut,
const SystShifts shift = kNoShift,
const _Var< T > &  wei = UnweightedT >(),
ESparse  sparse = kDense 
)

One constructor to rule them all.

template<class T >
ana::Spectrum::Spectrum ( const std::string label,
const Binning bins,
SpectrumLoaderBase loader,
const _Var< T > &  var,
const _Cut< T > &  cut,
const SystShifts shift = kNoShift,
const _Var< T > &  wei = UnweightedT >(),
ESparse  sparse = kDense 
)
template<class T >
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const _HistAxis< _MultiVar< T >> &  axis,
const _Cut< T > &  cut,
const SystShifts shift = kNoShift,
const _Var< T > &  wei = UnweightedT >() 
)

The only MultiVar variant available.

ana::Spectrum::Spectrum ( Eigen::ArrayXd &&  h,
const LabelsAndBins axis,
double  pot,
double  livetime 
)

Makes a spectrum from an eigen array.

Definition at line 38 of file Spectrum.cxx.

41  : fHist(Hist::Adopt(std::move(h))), fPOT(pot), fLivetime(livetime), fAxis(axis)
42  {
43  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
double fPOT
Definition: Spectrum.h:285
#define pot
double fLivetime
Definition: Spectrum.h:286
double livetime
Definition: saveFDMCHists.C:21
static Hist Adopt(Eigen::ArrayXd &&v)
Definition: Hist.cxx:149
ana::Spectrum::Spectrum ( Eigen::ArrayXstan &&  h,
const LabelsAndBins axis,
double  pot,
double  livetime 
)

Makes a spectrum from an eigen array of stan vars.

Definition at line 46 of file Spectrum.cxx.

50  {
51  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
double fPOT
Definition: Spectrum.h:285
#define pot
double fLivetime
Definition: Spectrum.h:286
static Hist AdoptStan(Eigen::ArrayXstan &&v)
Definition: Hist.cxx:140
double livetime
Definition: saveFDMCHists.C:21
template<class T >
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const _HistAxis< _Var< T >> &  xAxis,
const _HistAxis< _Var< T >> &  yAxis,
const _Cut< T > &  cut,
const SystShifts shift = kNoShift,
const _Var< T > &  wei = UnweightedT >(),
ESparse  sparse = kDense 
)

2D Spectrum taking 2 HistAxis

template<class T >
ana::Spectrum::Spectrum ( const std::string xLabel,
const std::string yLabel,
SpectrumLoaderBase loader,
const Binning binsx,
const _Var< T > &  varx,
const Binning binsy,
const _Var< T > &  vary,
const _Cut< T > &  cut,
const SystShifts shift = kNoShift,
const _Var< T > &  wei = UnweightedT >(),
ESparse  sparse = kDense 
)

2D Spectrum of two Vars

template<class T >
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const _HistAxis< _Var< T >> &  xAxis,
const _HistAxis< _Var< T >> &  yAxis,
const _HistAxis< _Var< T >> &  zAxis,
const _Cut< T > &  cut,
const SystShifts shift = kNoShift,
const _Var< T > &  wei = UnweightedT >(),
ESparse  sparse = kDense 
)

3D Spectrum taking 3 HistAxis

template<class T >
ana::Spectrum::Spectrum ( const std::string xLabel,
const std::string yLabel,
const std::string zLabel,
SpectrumLoaderBase loader,
const Binning binsx,
const _Var< T > &  varx,
const Binning binsy,
const _Var< T > &  vary,
const Binning binsz,
const _Var< T > &  varz,
const _Cut< T > &  cut,
const SystShifts shift = kNoShift,
const _Var< T > &  wei = UnweightedT >(),
ESparse  sparse = kDense 
)

3D Spectrum of three Vars

ana::Spectrum::Spectrum ( Hist &&  hist,
const LabelsAndBins axis,
double  pot,
double  livetime 
)
inline

Expert constructor for ReweightableSpectrum et al.

Definition at line 135 of file Spectrum.h.

139  : fHist(std::move(hist)), fPOT(pot), fLivetime(livetime), fAxis(axis)
140  {
141  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
double fPOT
Definition: Spectrum.h:285
#define pot
double fLivetime
Definition: Spectrum.h:286
double livetime
Definition: saveFDMCHists.C:21
ana::Spectrum::~Spectrum ( )
virtual

Definition at line 79 of file Spectrum.cxx.

References fReferences.

Referenced by Uninitialized().

80  {
81  // Unregister self from anything that might still want to fill us
82  for(Spectrum** ref: fReferences) *ref = 0;
83  }
std::set< Spectrum ** > fReferences
Things that point at this Spectrum. Maintained by SpectrumLoader.
Definition: Spectrum.h:289
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268
ana::Spectrum::Spectrum ( const Spectrum rhs)

Definition at line 54 of file Spectrum.cxx.

References ana::assert(), and fReferences.

54  :
55  fHist(rhs.fHist),
56  fPOT(rhs.fPOT),
57  fLivetime(rhs.fLivetime),
58  fAxis(rhs.fAxis)
59  {
60  assert(rhs.fReferences.empty()); // Copying with pending loads is unexpected
61  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
double fPOT
Definition: Spectrum.h:285
double fLivetime
Definition: Spectrum.h:286
assert(nhit_max >=nhit_nbins)
ana::Spectrum::Spectrum ( Spectrum &&  rhs)
ana::Spectrum::Spectrum ( )
inlineprotected

Constructor for Uninitialized()

Definition at line 268 of file Spectrum.h.

References AddLoader(), kDense, PlusEqualsHelper(), RemoveLoader(), and canMan::sign().

Referenced by Uninitialized().

270  fPOT(0), fLivetime(0),
271  fAxis(std::vector<std::string>(), std::vector<Binning>())
272  {
273  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
double fPOT
Definition: Spectrum.h:285
double fLivetime
Definition: Spectrum.h:286
static Hist Uninitialized()
Definition: Hist.h:30
ana::Spectrum::Spectrum ( const LabelsAndBins axis,
ESparse  sparse = kDense 
)
protected

Helper for constructors.

Definition at line 24 of file Spectrum.cxx.

References fAxis, fHist, ana::LabelsAndBins::GetBins1D(), kSparse, ana::Binning::NBins(), ana::Hist::Zero(), and ana::Hist::ZeroSparse().

26  {
27  const Binning bins1D = fAxis.GetBins1D();
28 
29  if(sparse == kSparse){
30  fHist = Hist::ZeroSparse(bins1D.NBins());
31  }
32  else{
33  fHist = Hist::Zero(bins1D.NBins());
34  }
35  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
double fPOT
Definition: Spectrum.h:285
static Hist ZeroSparse(int nbins)
Definition: Hist.cxx:51
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
double fLivetime
Definition: Spectrum.h:286
static Hist Zero(int nbins)
Definition: Hist.cxx:41
static Hist Uninitialized()
Definition: Hist.h:30

Member Function Documentation

void ana::Spectrum::AddLoader ( Spectrum **  ref)
protected

Definition at line 374 of file Spectrum.cxx.

References fReferences.

Referenced by Spectrum().

375  {
376  fReferences.insert(ref);
377  }
std::set< Spectrum ** > fReferences
Things that point at this Spectrum. Maintained by SpectrumLoader.
Definition: Spectrum.h:289
Spectrum ana::Spectrum::AsimovData ( double  pot) const

Asimov data is a MC spectrum scaled to the POT expected in the data.

Use for sensitivity plots and testing fit convergence

Definition at line 319 of file Spectrum.cxx.

References fHist, fPOT, pot, ana::Hist::ResetErrors(), runNovaSAM::ret, and ana::Hist::Scale().

Referenced by FakeData(), GetEigenStan(), and MakeFakeData().

320  {
321  Spectrum ret = *this;
322  if(fPOT > 0) ret.fHist.Scale(pot/fPOT);
323  ret.fPOT = pot;
324 
325  // Drop old errors, which are based on the MC statistics, and create new
326  // ones that are based on the prediction for the data
327  ret.fHist.ResetErrors();
328 
329  return ret;
330  }
double fPOT
Definition: Spectrum.h:285
#define pot
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268
Spectrum ana::Spectrum::AsimovData ( double  pot,
double  livetime 
) const

Use for sensitivity plots when fake cosmic data is needed. Fake cosmic spectra can be added to FakeData by desired livetime.

Definition at line 333 of file Spectrum.cxx.

References fHist, fLivetime, fPOT, livetime, pot, ana::Hist::ResetErrors(), runNovaSAM::ret, and ana::Hist::Scale().

334  {
335  Spectrum ret = *this;
336 
337  if(fPOT > 0) ret.fHist.Scale(pot/fPOT);
338  ret.fPOT = pot;
339 
340  // overwrite livetime for fake data
341  // PlusEqualsHelper will take over the rest
342  ret.fLivetime = livetime;
343 
344  ret.fHist.ResetErrors();
345 
346  return ret;
347  }
double fPOT
Definition: Spectrum.h:285
#define pot
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268
double livetime
Definition: saveFDMCHists.C:21
void ana::Spectrum::Clear ( void  )
Spectrum ana::Spectrum::FakeData ( double  pot) const
Spectrum ana::Spectrum::FakeData ( double  pot,
double  livetime 
) const

Synonymous with AsimovData(). Retained for compatibility.

Definition at line 356 of file Spectrum.cxx.

References AsimovData().

357  {
358  return AsimovData(pot, livetime);
359  }
Spectrum AsimovData(double pot) const
Asimov data is a MC spectrum scaled to the POT expected in the data.
Definition: Spectrum.cxx:319
#define pot
double livetime
Definition: saveFDMCHists.C:21
void ana::Spectrum::Fill ( double  x,
double  w = 1 
)

Definition at line 294 of file Spectrum.cxx.

References fAxis, fHist, ana::Hist::Fill(), ana::LabelsAndBins::GetBins1D(), w, and submit_syst::x.

Referenced by ana::SpectrumSink::HandleRecord(), ana::MultiVarSpectrumSink::HandleRecord(), ana::ReweightableSpectrumSink::HandleRecord(), and Uninitialized().

295  {
296  fHist.Fill(fAxis.GetBins1D(), x, w);
297  // TODO Pull binning out of Hist entirely and just update an index?
298  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
void Fill(const Binning &bins, double x, double w)
Definition: Hist.cxx:265
Float_t w
Definition: plot.C:20
const std::vector<Binning>& ana::Spectrum::GetBinnings ( ) const
inline
const Eigen::ArrayXd& ana::Spectrum::GetEigen ( ) const
inline
Eigen::ArrayXd ana::Spectrum::GetEigen ( double  exposure,
EExposureType  expotype = kPOT 
) const

Definition at line 220 of file Spectrum.cxx.

References fHist, fLivetime, fPOT, ana::Hist::GetEigen(), and ana::kPOT.

221  {
222  if(expotype == kPOT)
223  return (exposure/fPOT) * fHist.GetEigen();
224  else
225  return (exposure/fLivetime) * fHist.GetEigen();
226  }
const Eigen::ArrayXd & GetEigen() const
Definition: Hist.h:45
double fPOT
Definition: Spectrum.h:285
double fLivetime
Definition: Spectrum.h:286
const Eigen::ArrayXstan& ana::Spectrum::GetEigenStan ( ) const
inline
Eigen::ArrayXstan ana::Spectrum::GetEigenStan ( double  exposure,
EExposureType  expotype = kPOT 
) const

Definition at line 229 of file Spectrum.cxx.

References fHist, fLivetime, fPOT, ana::Hist::GetEigenStan(), and ana::kPOT.

230  {
231  if(expotype == kPOT)
232  return (exposure/fPOT) * fHist.GetEigenStan();
233  else
234  return (exposure/fLivetime) * fHist.GetEigenStan();
235  }
double fPOT
Definition: Spectrum.h:285
double fLivetime
Definition: Spectrum.h:286
const Eigen::ArrayXstan & GetEigenStan() const
Definition: Hist.h:46
const std::vector<std::string>& ana::Spectrum::GetLabels ( ) const
inline
bool ana::Spectrum::HasStan ( ) const
inline

Definition at line 187 of file Spectrum.h.

References fHist, and ana::Hist::HasStan().

Referenced by ana::SingleSampleExperiment::PredHistIncCosmics(), and ana::PredictionInterp::ShiftSpectrum().

187 {return fHist.HasStan();}
bool HasStan() const
Definition: Hist.h:44
double ana::Spectrum::Integral ( double  exposure,
double *  err = 0,
EExposureType  expotype = kPOT 
) const

Return total number of events scaled to pot.

Parameters
exposurePOT/livetime to scale to
errThe statistical error on this total (optional)
expotypeWhat the first parameter represents

Definition at line 250 of file Spectrum.cxx.

References fHist, fLivetime, fPOT, ana::Hist::GetBinError(), ana::Hist::GetNbinsX(), MECModelEnuComparisons::i, ana::Hist::Integral(), ana::kPOT, PandAna.reco_validation.prod5_pid_validation::ratio(), util::sqr(), and std::sqrt().

Referenced by BicountEllipse_dCP(), ana::CountingExperiment::ChiSq(), ComputeEfficiency(), ana::DataMCAreaNormalizedRatio(), demo_flat(), ana::SpectrumComponents::DrawLegend(), ana::DataMCPair::DrawMCNormSyst(), DataMCPair::DrawMCNormSyst(), FCContour(), ana::FluxMultiverseSyst::FindSigmaBoundaries(), FitParamEffectsAna(), FitSystEffectsAna(), GetEigenStan(), getHists_FNEX(), GetNueCosmics2017(), GetNueCosmics2018(), GetNueCosmics2019(), ana::GetNueCosmics2020(), GetNueCosmicsFuture(), GetNueData2017(), GetNueData2018(), GetNueData2019(), ana::GetNueData2020(), GetNuePrediction2017(), GetNuePrediction2018(), GetNuePrediction2019(), ana::GetNuePrediction2020(), GetNuePredictionFuture(), ana::GetNumuCosmics2020(), ana::GetNumuData2020(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly1D(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly3D(), Integral(), joint_fit_2017_make_fc_slice(), joint_fit_2017_make_fc_surf(), make_fc_mass_and_oct_nersc_2018(), make_fc_mass_and_oct_nersc_2019(), make_fc_mh_nersc_2018(), make_fc_mh_nersc_2019(), make_fc_oct_nersc_2018(), make_fc_oct_nersc_2019(), make_fc_slices_nersc_2018(), make_fc_slices_nersc_2018_stats(), make_fc_slices_nersc_2019(), make_fc_surfaces_nersc_2018(), make_fc_surfaces_nersc_2018_stats(), make_fc_surfaces_nersc_2019(), make_nominal_xs(), make_xs(), MakeHBar(), MakeTable(), MCCompPredictionTable(), ana::GenieMultiverseNormalizedSpectra::NormalizeSpectra(), PeripheralCuts(), ana::PlotWithAreaSystErrorBand(), predEventCountWithSystError(), SpectrumParamEffectsAna(), and ana::UnfoldSVD::Truth().

252  {
253  const double ratio = (expotype == kPOT) ? exposure/fPOT : exposure/fLivetime;
254 
255  if(err){
256  *err = 0;
257 
258  for(int i = 0; i < fHist.GetNbinsX()+2; ++i){
259  *err += util::sqr(fHist.GetBinError(i));
260  }
261  *err = sqrt(*err) * ratio;
262  }
263 
264  return fHist.Integral() * ratio;
265  }
double Integral() const
Definition: Hist.cxx:252
T sqrt(T number)
Definition: d0nt_math.hpp:156
int GetNbinsX() const
Definition: Hist.cxx:228
double fPOT
Definition: Spectrum.h:285
def ratio(spec1, spec2, nbins, pot, binrange=(0, 1))
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
double fLivetime
Definition: Spectrum.h:286
double GetBinError(int i) const
Definition: Hist.cxx:241
double ana::Spectrum::Livetime ( ) const
inline

Seconds. For informational purposes only. No calculations use this.

Definition at line 230 of file Spectrum.h.

References fLivetime.

Referenced by ApplyOscillations(), ana::FitInAnaBinsBkgdEstimator::Background(), ana::NumuCC2p2hBkgdEstimator::Background(), BlessedPlotsLoad(), CalcRWithSystsNus17(), Cumulative(), ana::TwoSampleDecomp::Decomp(), FCContour(), fd_plot(), FitParamEffectsAna(), FitSystEffectsAna(), getBNBPlots(), GetFluxError(), getHists_FNEX(), ana::Multiverse::GetNSigmaShift(), GetNueCosmics2017(), GetNueCosmics2018(), GetNueCosmics2019(), ana::GetNueCosmics2020(), GetNueCosmicsFuture(), GetNueData2017(), GetNueData2018(), GetNueData2019(), ana::GetNueData2020(), ana::GetNumuCosmics2020(), ana::GetNumuData2020(), ana::PredictionInterp::InitFits(), make_fc_nus_surfs_nersc_2018(), make_fc_nus_surfs_nersc_2019(), make_nus17_fc_surfs(), make_nus_fc_surfs(), make_xs(), make_xs_1D(), MakeExtrapSurface(), MakeHBar(), makeMatrixElementSurface(), MakeNusPrediction(), ana::MichelDecomp::MCToDCMPComp(), ana::PredictionExtendToPeripheral::MergePeripheral(), mrbrem_get_reweighted_spectra(), mrbrem_plots(), PlotNus17Prediction(), PlotNus17PredSystsData(), PlotNus18Sideband(), PlotNusSensAna01(), ana::PlotSpectra(), PlotSysts(), ana::SingleSampleExperiment::PredHistIncCosmics(), ana::PredictionExtendToPeripheral::ReduceHelperNC(), selection_story_plots(), ShiftedCosmics(), ana::PredictionInterp::ShiftSpectrum(), ana::SingleSampleExperiment::SingleSampleExperiment(), timingPeak(), ana::UnfoldSVD::Truth(), and ana::UnfoldTikhonov::Truth().

230 {return fLivetime;}
double fLivetime
Definition: Spectrum.h:286
std::unique_ptr< Spectrum > ana::Spectrum::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 536 of file Spectrum.cxx.

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

Referenced by Analyse_GetEfficiency(), Analyse_GetEfficiency_UseNEntries(), bdtstudyplotter(), BlessedPlotsAnaByPeriod(), CalcRWithSysts(), calculateComponentsNumu(), calculateWrongSignNue(), calculateWrongSignNumuQ1(), calculateWrongSignNumuQ2(), calculateWrongSignNumuQ3(), calculateWrongSignNumuQ4(), CalculateXSec(), ana::CompareNDDataMC(), ana::CompareNDDataOneMC(), ana::CompareNDDataTwoMC(), CutTableAna(), CVNphotonHist(), CVNphotonSplitHist(), demo2p5b(), DoThePlots(), doUnfolding(), EHadVisMECpairs(), example_plot(), FDDataMC(), FDDataMCSystBandAna(), FidOptHist(), FillFlavorContainers(), FitParamEffectsAna(), FitSystEffectsAna(), FOMCalc(), GeniePredictionToRoot(), get_data_histogram(), get_numu_data_histogram(), GetCosmics(), Plotter::GetDataPlots(), GetHist(), getHists_FNEX(), GetHistVectors(), Plotter::GetMCPlots(), ana::GetNDComponents(), ana::GetNDMCComponents(), ana::GetNumuCosmics2020(), GetNumuCosmicsFuture(), GetNumuData2017(), GetNumuData2018(), GetNumuData2019(), GetSpectToHist(), ana::InteractionSpectra::InteractionSpectra(), Load1DHistFromSpec(), LoadCosmic(), LoadFakeData(), ana::CountingExperiment::LoadFrom(), jw::TrivialPrediction::LoadFrom(), ana::CheatDecomp::LoadFrom(), ana::FluxReweight::LoadFrom(), ana::NCDecomp::LoadFrom(), ana::NueDecomp::LoadFrom(), ana::SingleSampleExperiment::LoadFrom(), ana::NumuDecomp::LoadFrom(), ana::CrossSectionSpectra::LoadFrom(), ana::TrivialPrediction::LoadFrom(), ana::ProportionalDecomp::LoadFrom(), ana::CutOptimization::LoadFrom(), ana::FakeDecomp::LoadFrom(), ana::TrivialExtrap::LoadFrom(), ana::TrivialCrossSectionAnalysis::LoadFrom(), ana::Multiverse::LoadFrom(), ana::TwoSampleDecomp::LoadFrom(), ana::SpectrumComponents::LoadFrom(), ana::FluxDecomp::LoadFrom(), ana::ModularExtrapSterile::LoadFrom(), ana::BENDecomp::LoadFrom(), ana::DataMCPair::LoadFrom(), ana::RecoReweight::LoadFrom(), ana::LoadFromUpDownSpectra(), LoadMaps(), make_dataMC(), make_eff_plots_areaNorm(), make_estimate_energy(), make_muonid_opt(), make_nominal_xs(), Make_NuMuCC_Inc_XS(), Make_NuMuCC_Inc_XS_v2(), make_vertex_optimiz(), MakeCutFlow(), makeEnergyEstimator(), makeFlatWeight(), MakePlots(), makeResolutionPlots(), MakeSurface(), MakeSurfaceBinningStudy(), MakeThePlots(), makeXSecPlots1D(), makeXSecPlots2D(), makeXSecPlots_TemplateFit(), meanWeight_plot(), mec_nux_tester_2020(), mec_tuning_fitter_2020(), MRDiFStudy_FHC_Step2(), MRDiFStudy_RHC_Step2(), multiverse_efficiency_plot(), MuonCatcherComp_ProdPlots(), nc_bkgd_by_interaction_mode(), NDDataMC(), NDDataMCSystBandAna(), nue_data_mc_validation(), nue_decomp_scales(), nue_fd_mc_validation(), numu_data_mc_validation(), OverrideLivetime(), plot_DataMCComp_numu(), plot_eff_purity(), plot_energy_res(), plot_estimate_energy(), plot_ND_DataMC(), plot_ND_DataMC_energybinning(), plot_nd_spectra_2018(), plot_recoE_numu(), plot_spectra_2dplots(), plot_uncertainty(), plotBinningResolution(), plotHist_SpectrumCVNID(), PlotResolution(), Plotsidebandfittest(), Plotting_Data2DataComp(), Plotting_Data2DataComp_SingleCanvas(), Plotting_DataAndPrediction(), Plotting_DataSpectra_MakeTGraph(), Plotting_OverlayStudies(), ppfx_smooth_weights_make(), preselection_cutflow(), ProduceCompPlots(), ReMIdHist(), resolutionplotter(), ana::ResolutionScan::ResolutionScan(), ShwZOptHist(), Spec2DToHist(), Spec2DtoHist(), SpecToHist(), SpectrumParamEffectsAna(), ana::TrivialPrediction::TrivialPrediction(), twodvtxcontplotter(), Unfold1D(), Unfold3D(), vertexstudyploter(), xsec_tot_uncert_optimization(), and xsec_uncertainty_per_bin().

537  {
538  dir = dir->GetDirectory(name.c_str()); // switch to subdir
539  assert(dir);
540 
541  DontAddDirectory guard;
542 
543  TObjString* tag = (TObjString*)dir->Get("type");
544  assert(tag);
545  assert(tag->GetString() == "Spectrum");
546  delete tag;
547 
548  TH1* hPot = (TH1*)dir->Get("pot");
549  assert(hPot);
550  TH1* hLivetime = (TH1*)dir->Get("livetime");
551  assert(hLivetime);
552 
553  std::vector<std::string> labels;
554  std::vector<Binning> bins;
555  for(int i = 0; ; ++i){
556  const std::string subname = TString::Format("bins%d", i).Data();
557  TDirectory* subdir = dir->GetDirectory(subname.c_str());
558  if(!subdir) break;
559  delete subdir;
560  bins.push_back(*Binning::LoadFrom(dir, subname));
561  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
562  labels.push_back(label ? label->GetString().Data() : "");
563  delete label;
564  }
565 
566  std::unique_ptr<Spectrum> ret = std::make_unique<Spectrum>(Eigen::ArrayXd(), LabelsAndBins(labels, bins), hPot->GetBinContent(1), hLivetime->GetBinContent(1));
567  ret->fHist = Hist::FromDirectory(dir);
568 
569  delete hPot;
570  delete hLivetime;
571 
572  delete dir;
573 
574  return ret;
575  }
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Binning.cxx:230
const XML_Char * name
Definition: expat.h:151
subdir
Definition: cvnie.py:7
static Hist FromDirectory(TDirectory *dir)
Definition: Hist.cxx:158
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
enum BeamMode string
double ana::Spectrum::Mean ( ) const

Return mean of 1D histogram.

Definition at line 268 of file Spectrum.cxx.

References ana::bins, om::cout, ana::Binning::Edges(), allTimeWatchdog::endl, fAxis, fHist, ana::Hist::GetBinContent(), ana::LabelsAndBins::GetBins1D(), MECModelEnuComparisons::i, extractScale::mean, ana::Binning::NBins(), w, W, and x1.

Referenced by ana::DataMCPair::CreateSystTable(), and GetEigenStan().

269  {
270  const Binning bins = fAxis.GetBins1D();
271 
272  if(fHist.GetBinContent(0) != 0){
273  std::cout << "Spectrum::Mean(): Warning ignoring underflow bin content " << fHist.GetBinContent(0) << std::endl;
274  }
275 
276  if(fHist.GetBinContent(bins.NBins()+1) != 0){
277  std::cout << "Spectrum::Mean(): Warning ignoring overflow bin content " << fHist.GetBinContent(bins.NBins()+1) << std::endl;
278  }
279 
280  double mean = 0;
281  double W = 0;
282  for(int i = 1; i <= bins.NBins(); ++i){
283  const double w = fHist.GetBinContent(i);
284  W += w;
285  const double x0 = bins.Edges()[i-1];
286  const double x1 = bins.Edges()[i];
287  mean += w * (x0+x1)/2;
288  }
289 
290  return mean/W;
291  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
Float_t x1[n_points_granero]
Definition: compare.C:5
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
OStream cout
Definition: OStream.cxx:6
const Binning bins
Definition: NumuCC_CPiBin.h:8
double GetBinContent(int i) const
Definition: Hist.cxx:349
Float_t w
Definition: plot.C:20
#define W(x)
Spectrum ana::Spectrum::MockData ( double  pot,
int  seed = 0 
) const

Mock data is FakeData with Poisson fluctuations applied.

Use for low-budget MDCs, or just getting a sense of the expected scale of statistical variation. NB seed = 0 is true random

Definition at line 301 of file Spectrum.cxx.

References FakeData(), fHist, ana::Hist::GetBinContent(), ana::Hist::GetNbinsX(), MECModelEnuComparisons::i, ana::Hist::ResetErrors(), runNovaSAM::ret, generate_hists::rnd, and ana::Hist::SetBinContent().

Referenced by demo4(), demo5(), FCTutorial2020(), fd_plot(), fill_col(), GenerateFutureData(), ana2019::fakedata::Get2019Prediction(), GetEigenStan(), GetMockData(), joint_fit_2017_make_fc_slice(), joint_fit_2017_make_fc_surf(), make_fc_mass_and_oct_nersc_2018(), make_fc_mass_and_oct_nersc_2019(), make_fc_mh_nersc_2018(), make_fc_mh_nersc_2019(), make_fc_nus_surfs_nersc_2018(), make_fc_nus_surfs_nersc_2019(), make_fc_oct_nersc_2018(), make_fc_oct_nersc_2019(), make_fc_slices_nersc_2018(), make_fc_slices_nersc_2018_stats(), make_fc_slices_nersc_2019(), make_fc_surfaces_2020_validation(), make_fc_surfaces_nersc_2018(), make_fc_surfaces_nersc_2018_stats(), make_fc_surfaces_nersc_2019(), make_mockdata_syst_contours(), make_nus17_fc_surfs(), make_nus_fc_surfs(), MakeFakeData(), selection_story_plots(), syst_plot_test(), and test_saloaders().

302  {
304 
305  TRandom3 rnd(seed); // zero seeds randomly
306 
307  for(int i = 0; i < ret.fHist.GetNbinsX()+2; ++i){
308  ret.fHist.SetBinContent(i, rnd.Poisson(ret.fHist.GetBinContent(i)));
309  }
310 
311  // Drop old errors, which are based on the MC statistics, and create new
312  // ones that are based on the prediction for the data
313  ret.fHist.ResetErrors();
314 
315  return ret;
316  }
unsigned int seed
Definition: runWimpSim.h:102
Spectrum FakeData(double pot) const
Synonymous with AsimovData(). Retained for compatibility.
Definition: Spectrum.cxx:350
#define pot
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268
unsigned int ana::Spectrum::NDimensions ( ) const
inline
Spectrum ana::Spectrum::operator* ( const Ratio rhs) const

Definition at line 484 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

485  {
486  Spectrum ret = *this;
487  ret *= rhs;
488  return ret;
489  }
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268
Spectrum & ana::Spectrum::operator*= ( const Ratio rhs)

Definition at line 477 of file Spectrum.cxx.

References ana::Ratio::fHist, fHist, and ana::Hist::Multiply().

Referenced by OverrideLivetime().

478  {
479  fHist.Multiply(rhs.fHist);
480  return *this;
481  }
void Multiply(const Hist &rhs)
Definition: Hist.cxx:479
Spectrum ana::Spectrum::operator+ ( const Spectrum rhs) const

Definition at line 455 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

456  {
457  Spectrum ret = *this;
458  ret += rhs;
459  return ret;
460  }
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268
Spectrum & ana::Spectrum::operator+= ( const Spectrum rhs)

Definition at line 449 of file Spectrum.cxx.

References PlusEqualsHelper().

Referenced by OverrideLivetime().

450  {
451  return PlusEqualsHelper(rhs, +1);
452  }
Spectrum & PlusEqualsHelper(const Spectrum &rhs, int sign)
Helper for operator+= and operator-=.
Definition: Spectrum.cxx:380
Spectrum ana::Spectrum::operator- ( const Spectrum rhs) const

Definition at line 469 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

470  {
471  Spectrum ret = *this;
472  ret -= rhs;
473  return ret;
474  }
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268
Spectrum & ana::Spectrum::operator-= ( const Spectrum rhs)

Definition at line 463 of file Spectrum.cxx.

References PlusEqualsHelper().

Referenced by OverrideLivetime().

464  {
465  return PlusEqualsHelper(rhs, -1);
466  }
Spectrum & PlusEqualsHelper(const Spectrum &rhs, int sign)
Helper for operator+= and operator-=.
Definition: Spectrum.cxx:380
Spectrum ana::Spectrum::operator/ ( const Ratio rhs) const

Definition at line 499 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

500  {
501  Spectrum ret = *this;
502  ret /= rhs;
503  return ret;
504  }
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268
Spectrum & ana::Spectrum::operator/= ( const Ratio rhs)

Definition at line 492 of file Spectrum.cxx.

References ana::Hist::Divide(), ana::Ratio::fHist, and fHist.

Referenced by OverrideLivetime().

493  {
494  fHist.Divide(rhs.fHist);
495  return *this;
496  }
void Divide(const Hist &rhs)
Definition: Hist.cxx:531
Spectrum & ana::Spectrum::operator= ( const Spectrum rhs)

Definition at line 64 of file Spectrum.cxx.

References ana::assert(), fAxis, fHist, fLivetime, fPOT, and fReferences.

Referenced by Uninitialized().

65  {
66  if(this == &rhs) return *this;
67 
68  fHist = rhs.fHist;
69  fPOT = rhs.fPOT;
70  fLivetime = rhs.fLivetime;
71  fAxis = rhs.fAxis;
72 
73  assert(fReferences.empty()); // Copying with pending loads is unexpected
74 
75  return *this;
76  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
std::set< Spectrum ** > fReferences
Things that point at this Spectrum. Maintained by SpectrumLoader.
Definition: Spectrum.h:289
double fPOT
Definition: Spectrum.h:285
double fLivetime
Definition: Spectrum.h:286
assert(nhit_max >=nhit_nbins)
Spectrum& ana::Spectrum::operator= ( Spectrum &&  rhs)
void ana::Spectrum::OverrideLivetime ( double  newlive)
inline
void ana::Spectrum::OverridePOT ( double  newpot)
inline
Spectrum & ana::Spectrum::PlusEqualsHelper ( const Spectrum rhs,
int  sign 
)
protected

Helper for operator+= and operator-=.

Definition at line 380 of file Spectrum.cxx.

References ana::Hist::Add(), ana::AlmostEqual(), om::cout, allTimeWatchdog::endl, fHist, fLivetime, fPOT, ana::Hist::Initialized(), and ana::Hist::Integral().

Referenced by operator+=(), operator-=(), and Spectrum().

381  {
382  // In this case it would be OK to have no POT/livetime
383  if(rhs.fHist.Initialized() && rhs.fHist.Integral() == 0) return *this;
384 
385  if((!fPOT && !fLivetime) || (!rhs.fPOT && !rhs.fLivetime)){
386  std::cout << "Error: can't sum Spectrum with no POT or livetime: "
387  << fPOT << " " << rhs.fPOT << " " << fLivetime << " " << rhs.fLivetime
388  << std::endl;
389  abort();
390  }
391 
392  if(!fLivetime && !rhs.fPOT){
393  std::cout << "Error: can't sum Spectrum with POT ("
394  << fPOT << ") but no livetime and Spectrum with livetime ("
395  << rhs.fLivetime << " sec) but no POT." << std::endl;
396  abort();
397  }
398 
399  if(!fPOT && !rhs.fLivetime){
400  std::cout << "Error: can't sum Spectrum with livetime ("
401  << fLivetime << " sec) but no POT and Spectrum with POT ("
402  << rhs.fPOT << ") but no livetime." << std::endl;
403  abort();
404  }
405 
406  // And now there are still a bunch of good cases to consider
407 
408  if(fPOT && rhs.fPOT){
409  // Scale by POT when possible
410  fHist.Add(rhs.fHist, sign*fPOT/rhs.fPOT);
411 
412  if(fLivetime && rhs.fLivetime){
413  // If POT/livetime ratios match, keep regular lifetime, otherwise zero
414  // it out.
415  if(AlmostEqual(fLivetime*rhs.fPOT, rhs.fLivetime*fPOT))
416  fLivetime = 0;
417  }
418  if(!fLivetime && rhs.fLivetime){
419  // If the RHS has a livetime and we don't, copy it in (suitably scaled)
420  fLivetime = rhs.fLivetime * fPOT/rhs.fPOT;
421  }
422  // Otherwise, keep our own livetime (if any)
423 
424  return *this;
425  }
426 
427  if(fLivetime && rhs.fLivetime){
428  // Scale by livetime, the only thing in common
429  fHist.Add(rhs.fHist, sign*fLivetime/rhs.fLivetime);
430 
431  if(!fPOT && rhs.fPOT){
432  // If the RHS has a POT and we don't, copy it in (suitably scaled)
433  fPOT = rhs.fPOT * fLivetime/rhs.fLivetime;
434  }
435  // Otherwise, keep our own POT (if any)
436 
437  return *this;
438  }
439 
440  // That should have been all the cases. I definitely want to know what
441  // happened if it wasn't.
442  std::cout << "Spectrum::operator+=(). How did we get here? "
443  << fPOT << " " << fLivetime << " "
444  << rhs.fPOT << " " << rhs.fLivetime << std::endl;
445  abort();
446  }
void Add(const Hist &rhs, double scale=1)
Definition: Hist.cxx:455
double fPOT
Definition: Spectrum.h:285
bool AlmostEqual(double a, double b, double eps)
Definition: UtilsExt.cxx:40
double fLivetime
Definition: Spectrum.h:286
OStream cout
Definition: OStream.cxx:6
def sign(x)
Definition: canMan.py:197
double ana::Spectrum::POT ( ) const
inline

Definition at line 227 of file Spectrum.h.

References fPOT.

Referenced by ana::nueccinc::NueCCIncCrossSectionAnalysis::AddEnhancedSample(), ana::DataMCPair::AddExposure(), ApplyOscillations(), CalcChi2(), CalcR(), CalcRWithSystsNus17(), calculateComponentsNumu(), calculateWrongSignNue(), calculateWrongSignNumuQ1(), calculateWrongSignNumuQ2(), calculateWrongSignNumuQ3(), calculateWrongSignNumuQ4(), ana::CountingExperiment::ChiSq(), ana::SingleSampleExperiment::ChiSq(), ana::CovMxExperiment::ChiSq(), CompareMissingLeptons(), ComputeEfficiency(), Cumulative(), ana::DataMCAreaNormalizedRatio(), ana::DataMCComparison(), Plotter::DataMCComparison(), ana::DataMCComparisonAreaNormalized(), ana::DataMCComparisonComponents(), ana::TwoSampleDecomp::Decomp(), demo6(), draw_decomp_plots(), ana::DataMCPair::DrawData(), ana::SpectrumComponents::DrawLegend(), ana::DataMCPair::DrawMCComponents(), ana::DataMCPair::DrawMCNormSyst(), DataMCPair::DrawMCNormSyst(), ana::DataMCPair::DrawMCSyst(), drawPlot(), DrawPreSelectionPlots(), ana::TwoSampleDecomp::DrawSigBkgOverlay(), ana::TwoSampleDecomp::DrawTwoSamplesWithRatios(), EHadVisMECpairs(), example_plot(), FCContour(), fd_plot(), fill_col(), ana::FluxMultiverseSyst::FindSigmaBoundaries(), FitParamEffectsAna(), FitSystEffectsAna(), GetExtrap(), getHists_FNEX(), ana::Multiverse::GetNSigmaShift(), GetNueData2017(), GetNueData2018(), GetNueData2019(), ana::GetNueData2020(), ana::GetNumuData2020(), ana::MichelDecomp::GetSum(), ana::MichelDecomp::GetTemplateContent(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly1D(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly3D(), ana::PredictionInterp::InitFits(), ana::SingleSampleExperiment::LogLikelihood(), Make2DPlot(), make_muonid_opt(), make_nus17_fc_surfs(), make_nus_fc_surfs(), make_plots(), make_vertex_optimiz(), make_xs(), make_xs_1D(), makeEnergyEstimator(), MakeFakeData(), makeFlatWeight(), MakeHBar(), makeMatrixElementSurface(), MakePlot(), MakePlots(), ana::MakeQuantileHistogram(), MakeSelectionPlots(), ana::FluxDecomp::MakeWeightsNumuFromKaon(), ana::BENDecomp::MakeWeightsNumuFromKaon(), ana::FluxDecomp::MakeWeightsNumuFromPion(), ana::BENDecomp::MakeWeightsNumuFromPion(), ana::MichelDecomp::MCToDCMPComp(), mec_nux_tester_2020(), mec_tuning_fitter_2020(), ana::PredictionExtendToPeripheral::MergePeripheral(), MichelDecompTest(), mrbrem_get_reweighted_spectra(), mrbrem_plots(), mre_blessed(), mre_comp_split(), multiverse_efficiency_plot(), multiverse_macro(), ana::GenieMultiverseNormalizedSpectra::NormalizeSpectra(), nue_decomp_scales(), nue_decomp_scales_for_make_decomp(), ana::FluxDecomp::NueEstimate(), ana::BENDecomp::NueEstimate(), ana::FluxDecomp::NueEstimateFromKa(), ana::FluxDecomp::NueEstimateFromPi(), ana::BENDecomp::NueEstimateFromPi(), ana::CutOptimization::OptimizedSigmaOverSigma(), plot(), plot_2d(), plot_2d_vars(), plot_3NDvsFD(), plot_3NDvsFD_FHC(), plot_3NDvsFD_RHC(), plot_datamc_ND_numu(), plot_datamc_ND_numu_REW(), plot_diff(), plot_ND_numu_NOMvsREW(), plot_NDvsFD_REW(), plot_NDvsFD_weights(), plot_NDvsFD_weights_FHC(), plot_NDvsFD_weights_RHC(), plot_predictions(), plot_recoE_numu(), plot_time(), ana::PlotAllSelectionDecomposition(), ana::PlotAllSignalEstimates(), ana::CrossSectionAnalysis::PlotBackgroundEstimate(), ana::NumuCCIncAnalysis::PlotBackgroundEstimate(), ana::SingleNucAnalysis::PlotBackgroundEstimate2D(), ana::NumuCC2p2hAnalysis::PlotBackgroundEstimate2D(), ana::CrossSectionAnalysis::PlotData(), ana::NumuCCIncAnalysis::PlotData(), ana::SingleNucAnalysis::PlotData2D(), ana::NumuCC2p2hAnalysis::PlotData2D(), ana::CutOptimization::PlotDebug(), PlotNueDecompFourBins(), PlotNus17PredSystsData(), PlotNus18Sideband(), PlotNusSensAna01(), ana::CrossSectionAnalysis::PlotRecoToTrueMatrix(), ana::SingleNucAnalysis::PlotRecoToTrueMatrix2D(), ana::NumuCC2p2hAnalysis::PlotRecoToTrueMatrix2D(), ana::CrossSectionAnalysis::PlotSignalEstimate(), ana::SingleNucAnalysis::PlotSignalEstimate2D(), ana::NumuCC2p2hAnalysis::PlotSignalEstimate2D(), ana::PlotSpectra(), PlotStack(), ana::PlotStack(), PlotSyst(), PlotSysts(), ana::CrossSectionAnalysis::PlotUnfoldedSignal(), ana::SingleNucAnalysis::PlotUnfoldedSignal2D(), ana::NumuCC2p2hAnalysis::PlotUnfoldedSignal2D(), PlotVertices(), PlotVisibleEnergy(), ana::SingleSampleExperiment::PredHistIncCosmics(), ana::NDPredictionSterile::Predict(), ana::NDPredictionSterile::PredictComponent(), ana::Ratio::Ratio(), ana::TwoSampleDecomp::RatioCalc(), reco_minus_true_panels(), ana::PredictionExtendToPeripheral::ReduceHelperNC(), ana::CrossSectionAnalysis::Result(), ana::NumuCCIncAnalysis::Result(), ana::NumuCC2p2hAnalysis::Result1DFluxInt(), ana::NumuCC2p2hAnalysis::Result2D(), ana::SingleNucAnalysis::Result2D(), ana::NumuCCIncAnalysis::Result2D(), ana::NumuCCIncAnalysis::ReturnHists(), ana::MichelDecomp::SaveCompPlots(), ana::FluxDecomp::SavePlots(), ana::BENDecomp::SavePlots(), ana::TruthReweight::SavePlots(), ana::RecoReweight::SavePlots(), ana::FluxDecomp::SavePlotsKa(), ana::BENDecomp::SavePlotsKa(), ana::FluxDecomp::SavePlotsPi(), ana::BENDecomp::SavePlotsPi(), saveS(), saveS1(), SaveSpectrum(), ana::MichelDecomp::SaveTempPlots(), selection_story_plots(), ShiftedCosmics(), ana::PredictionInterp::ShiftSpectrum(), ana::SimpleFOM(), SpectrumParamEffectsAna(), TableNueNDComponents(), TableNueNDDataMC(), test_beam_errorband(), test_micheldecomp(), test_sam(), test_sam_project(), test_stanfit_systpulls(), ana::Multiverse::ToHist(), ana::CutOptimization::ToHist(), ana::ICrossSectionAnalysis::ToHist(), ana::UnfoldIterative::Truth(), ana::UnfoldSVD::Truth(), and ana::UnfoldTikhonov::Truth().

227 {return fPOT;}
double fPOT
Definition: Spectrum.h:285
void ana::Spectrum::RemoveLoader ( Spectrum **  ref)
protected

Definition at line 368 of file Spectrum.cxx.

References fReferences.

Referenced by Spectrum().

369  {
370  fReferences.erase(ref);
371  }
std::set< Spectrum ** > fReferences
Things that point at this Spectrum. Maintained by SpectrumLoader.
Definition: Spectrum.h:289
void ana::Spectrum::SaveTo ( TDirectory *  dir,
const std::string name 
) const

Definition at line 507 of file Spectrum.cxx.

References dir, fAxis, fHist, fLivetime, genie::utils::style::Format(), fPOT, GetBinnings(), ana::LabelsAndBins::GetBins1D(), GetLabels(), MECModelEnuComparisons::i, NDimensions(), tmp, and ana::Hist::Write().

Referenced by Ana2017_box_opening_macro(), Ana2017_sb_opening_macro(), Ana2018_box_opening_macro(), angle(), bdtstudyspectrums(), BlessedPlotsLoad(), ccpiinc_mc_studies(), containmentstudy(), CosmicPred(), CutTableLoad(), CVNphoton(), CVNphotonSplit(), datamc_ND_numu_kinematics(), datamc_ND_numu_kinematics_FHC(), datamc_ND_numu_kinematics_FHC_pTBins(), datamc_ND_numu_kinematics_FHC_REW(), datamc_ND_numu_kinematics_FHC_REW_pTBins(), datamc_ND_numu_kinematics_REW(), datamc_ND_numu_kinematics_RHC(), datamc_ND_numu_kinematics_RHC_pTBins(), datamc_ND_numu_kinematics_RHC_REW(), datamc_ND_numu_kinematics_RHC_REW_pTBins(), dataprocess_numuccinc(), energy_resolution(), estimate_energy(), FDDataMCSystBandLoad(), FidOpt(), FidWShwCuts(), FillSpectra(), FitSystEffectsLoad(), get_cosmic_spectra(), get_data_and_cosmic(), get_data_histogram(), get_numi_data_histogram(), getData(), getFlatWeightSpectra(), getSpectra_ForFitting(), getTimePeakTotal(), make_mockdata_syst_contours(), make_pi0_xcheck(), make_pid(), MakeCosmics(), MakeFakeData(), makeFakeDataFluxes(), MakeNus17Prediction(), MakeNus18SidebandPred(), MakeNusPrediction(), makeRealDataFluxes(), makeXSecPlots_TemplateFit(), meanWeight_macro(), mrbrem_get_initial_spectra(), mrbrem_get_reweighted_spectra(), MRDiFStudy_FHC_Step1(), MRDiFStudy_RHC_Step1(), mre_blessed(), mre_comp_split(), ncpi0HistoGrid2(), ND_DataMC(), NDDataMCSystBandLoad(), nue_decomp_scales(), nus17_box_opening(), nus17_fd_cut_tables(), nus17_fd_cut_tables2D(), nus18_box_opening(), nus_ana01_box_opening(), nus_ana01_sideband_box_opening(), OverrideLivetime(), pion_multiverse(), ReMId(), resolutionscript(), resolutionstudy(), saveFDMCHists(), saveSpectraForUnf(), ana::xsec::UnfoldingVariable::SaveSpectrums(), ana::PredictionXSecTuning::SaveTo(), ana::CountingExperiment::SaveTo(), ana::PredictionNoOsc::SaveTo(), ana::FluxReweight::SaveTo(), ana::CheatDecomp::SaveTo(), jw::TrivialPrediction::SaveTo(), ana::FitInAnaBinsBkgdEstimator::SaveTo(), ana::NumuCC2p2hBkgdEstimator::SaveTo(), ana::nueccinc::NueCCIncMRECorrection::SaveTo(), ana::NCDecomp::SaveTo(), ana::NueDecomp::SaveTo(), ana::SingleSampleExperiment::SaveTo(), ana::NumuDecomp::SaveTo(), ana::CrossSectionSpectra::SaveTo(), ana::TrivialPrediction::SaveTo(), ana::PredictionScaleComp::SaveTo(), ana::ProportionalDecomp::SaveTo(), ana::CutOptimization::SaveTo(), ana::TrivialCrossSectionAnalysis::SaveTo(), ana::FakeDecomp::SaveTo(), ana::TrivialExtrap::SaveTo(), ana::CrossSectionAnalysis::SaveTo(), ana::TwoSampleDecomp::SaveTo(), ana::SpectrumComponents::SaveTo(), ana::NumuCCIncAnalysis::SaveTo(), ana::FluxDecomp::SaveTo(), ana::nueccinc::NueCCIncCrossSectionAnalysis::SaveTo(), ana::MichelDecomp::SaveTo(), ana::BENDecomp::SaveTo(), ana::DataMCPair::SaveTo(), ana::RecoReweight::SaveTo(), ana::nueccinc::NueCCIncEnhancedSamples::SaveTo(), mcmc::SaveToFile(), ShwZOpt(), sidebandfittest(), signal_count(), test_beam_errorband(), test_fluxhadr_prod_weights_Flux(), test_genieweights(), test_predictionscalecomp(), ana::TrivialPrediction::TrivialPrediction(), TrueNCSpectrum(), TrueSpectrumFromKaons(), twodstudyvtxcont(), validationscript(), and vertexstudy().

508  {
509  TDirectory* tmp = gDirectory;
510 
511  dir = dir->mkdir(name.c_str()); // switch to subdir
512  dir->cd();
513 
514  TObjString("Spectrum").Write("type");
515 
517  TH1D hPot("", "", 1, 0, 1);
518  hPot.Fill(.5, fPOT);
519  hPot.Write("pot");
520  TH1D hLivetime("", "", 1, 0, 1);
521  hLivetime.Fill(.5, fLivetime);
522  hLivetime.Write("livetime");
523 
524  for(unsigned int i = 0; i < NDimensions(); ++i){
525  TObjString(GetLabels()[i].c_str()).Write(TString::Format("label%d", i).Data());
526  GetBinnings()[i].SaveTo(dir, TString::Format("bins%d", i).Data());
527  }
528 
529  dir->Write();
530  delete dir;
531 
532  tmp->cd();
533  }
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:264
const XML_Char * name
Definition: expat.h:151
void Write(const Binning &bins) const
Definition: Hist.cxx:583
LabelsAndBins fAxis
Definition: Spectrum.h:291
double fPOT
Definition: Spectrum.h:285
Float_t tmp
Definition: plot.C:36
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
double fLivetime
Definition: Spectrum.h:286
unsigned int NDimensions() const
Definition: Spectrum.h:262
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: Spectrum.h:263
void ana::Spectrum::Scale ( double  c)
void ana::Spectrum::Scale ( const stan::math::var v)

Definition at line 244 of file Spectrum.cxx.

References fHist, and ana::Hist::Scale().

245  {
246  fHist.Scale(c);
247  }
void Scale(double s)
Definition: Hist.cxx:296
TH1D * ana::Spectrum::ToTH1 ( double  exposure,
Color_t  col = kBlack,
Style_t  style = kSolid,
EExposureType  expotype = kPOT,
EBinType  bintype = kBinContent 
) const

Histogram made from this Spectrum, scaled to some exposure.

Parameters
exposurePOT or livetime (seconds)
colHistogram color (default black)
styleHistogram line style (default solid)
expotypeHow to interpret exposure (kPOT (default) or kLivetime)

Definition at line 149 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by ana::nueccinc::NueCCIncCrossSectionAnalysis::AddEnhancedSample(), ana::AddErrorInQuadrature(), ana::PredictionSystJoint2018::AddNormSyst(), ana::PredictionSystJointDemo::AddNormSyst(), ana::PredictionSyst3Flavor2020::AddNormSyst(), ana::PredictionSystNue2017::AddNormSysts(), ana::PredictionSystNumu2017::AddNormSysts(), ana::CovMxManager::AddSystematic(), AnalyzeNus18Pred(), ana::NumuCC2p2hBkgdEstimator::Background(), bin_composition_pie_chart(), ana::covmx::CovarianceMatrix::BuildFullCovMx(), calcAlphaBetaEachBin(), CalcChi2(), ana::nueccinc::NueCCIncMRECorrection::CalcEfficiencyCorrection(), CalcR(), CalcRWithSystsNus17(), calculateComponentsNumu(), calculateWrongSignNue(), calculateWrongSignNumuQ1(), calculateWrongSignNumuQ2(), calculateWrongSignNumuQ3(), calculateWrongSignNumuQ4(), cc(), check_predinterp(), check_predinterp_numu(), ana::LikelihoodCovMxExperiment::ChiSq(), ana::OscCovMxExperiment::ChiSq(), Compare(), CompareBinningSchemes(), CompareDecompDataMC(), CompareMCCompPrediction(), CompareMissingLeptons(), ComparePredictions(), ana::ComparePredictions(), ana::ModularExtrapComponent::ComparisonPlot(), Cumulative(), CVNCuts(), ana::DataMCComparison(), Plotter::DataMCComparison(), ana::DataMCComparisonAreaNormalized(), ana::DataMCComparisonComponents(), ana::PredictionInterp::DebugPlot(), ana::TwoSampleDecomp::Decomp(), ana::MichelDecomp::Decompose(), demo1(), demo3(), demo5(), demo6(), demo_flat(), demo_nueNumuSysts(), DrawBackgrounds(), DrawBins(), ana::DataMCPair::DrawData(), drawPlot(), DrawPulls(), DrawSensitivityDip(), ana::TwoSampleDecomp::DrawSigBkgOverlay(), DrawSurface(), DrawSystShifts(), drawSystsShiftingNDdata(), drawSystsShiftingNDdata_updatedAna(), ana::TwoSampleDecomp::DrawTwoSamplesWithRatios(), efficiency(), efficiencySA(), EHadVisMECpairs(), example_plot(), FCContour(), fd_plot(), fill_col(), FitParamEffectsAna(), FitSystEffectsAna(), GenerateFutureData(), GeniePredictionToRoot(), GetBackgroundStatisticalUncertainty(), GetBackgroundSystematicUncertainty(), ana::GetBFSystBands(), GetBG(), ana::GetBG(), getBNBPlots(), getContProf(), getContProf_Sensitivity(), GetDenominator(), ana::nueccinc::NueCCIncMRECorrection::getEfficiency1D(), GetEfficiencyDenominator(), GetEfficiencySystematicUncertainty(), GetExtrap(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getFlux1D(), GetFluxError(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getFullTemplate(), getHists_FNEX(), GetNC(), ana::GetNC(), ana::GetNDComponents(), ana::GetNDCompsFromDecomp(), ana::GetNDDecompsFromDecomp(), ana::Multiverse::GetNSigmaShift(), GetNueCosmics2017(), GetNueCosmics2018(), GetNueCosmics2019(), GetNueCosmicsFuture(), GetNumuCosmicsFuture(), ana::nueccinc::NueCCIncMRECorrection::getPreselected1D(), GetQuantilePredictionHist(), ana::nueccinc::NueCCIncMRECorrection::getSelected1D(), GetSelectedStatisticalUncertainty(), GetSig(), GetSpectra(), ana::GetSpectrum(), ana::GetSystBands(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly1D(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly3D(), getTimePeakPlots(), Integral(), make_extrap_figure(), make_fc_nus_surfs_nersc_2018(), make_muonid_opt(), make_nus17_fc_surfs(), make_nus_fc_surfs(), make_plots(), make_vertex_optimiz(), make_xs_1D(), MakeCovMx(), makeEnergyEstimator(), makeFlatWeight(), makeMatrixElementSurface(), MakePeriCutPlot(), MakePlot(), MakePlots(), MakeResultPlot(), MakeSurface(), MakeSurfaceBinningStudy(), MakeTable(), ana::FluxDecomp::MakeWeightsNumuFromKaon(), ana::BENDecomp::MakeWeightsNumuFromKaon(), makeXSecPlots1D(), makeXSecPlots2D(), MatrixDeterminant(), MichelDecompTest(), mrbrem_get_reweighted_spectra(), mrbrem_plots(), mre_blessed(), mre_comp_split(), multiverse_efficiency_plot(), multiverse_macro(), NDHists(), nue_decomp_scales(), nue_decomp_scales_for_make_decomp(), nue_pid_effs(), nue_pid_effs_miniprod(), nue_pid_effs_paper_numu_neweff(), numu_cut_flow(), PeripheralCuts(), pi0_xcheck(), plot(), plot_3NDvsFD(), plot_3NDvsFD_FHC(), plot_3NDvsFD_RHC(), plot_datamc_ND_numu(), plot_datamc_ND_numu_REW(), plot_datamcpred(), plot_diff(), plot_kinematics_cafana(), plot_ND_numu_NOMvsREW(), plot_NDvsFD_REW(), plot_NDvsFD_weights(), plot_NDvsFD_weights_FHC(), plot_NDvsFD_weights_RHC(), plot_nue_xsec_pred(), plot_nueFD_Signal_REWvsNOM_FHC(), plot_nueFD_Signal_REWvsNOM_pTExtrap_FHC(), plot_nueFD_Signal_REWvsNOM_pTExtrap_RHC(), plot_nueFD_Signal_REWvsNOM_RHC(), plot_pi0_xcheck(), plot_pid(), plot_predictions(), plot_recoE_numu(), plot_time(), ana::PlotAllSelectionDecomposition(), ana::PlotAllSignalEstimates(), ana::CrossSectionAnalysis::PlotBackgroundEstimate(), ana::NumuCCIncAnalysis::PlotBackgroundEstimate(), PlotComp(), ana::CrossSectionAnalysis::PlotData(), ana::NumuCCIncAnalysis::PlotData(), ana::CutOptimization::PlotDebug(), ana::CrossSectionAnalysis::PlotFluxEstimate(), ana::SingleNucAnalysis::PlotFluxEstimate2D(), ana::NumuCC2p2hAnalysis::PlotFluxEstimate2D(), PlotNuePredictionFourBins(), PlotNumuPredData(), PlotNus17PredSystsData(), PlotNus18Sideband(), PlotNusSensAna01(), PlotPionPlots(), PlotPurEff(), ana::PlotPurEff(), plots(), ana::PlotSpectra(), PlotStack(), ana::PlotStack(), PlotSyst(), PlotSysts(), Plotting_DataAndPrediction(), ana::CrossSectionAnalysis::PlotUnfoldedSignal(), PlotVisibleEnergy(), ana::PlotWithSystErrorBand(), ana::PlotWithSystErrorBand_Quant(), ana::PlotWithSystErrorBandTwoPreds(), ana::covmx::CovarianceMatrix::Predict(), PredictCosmic(), ana::SpectrumComponents::Purity(), ana::TwoSampleDecomp::RatioCalc(), reco_minus_true_panels(), resolution2018(), ana::CrossSectionAnalysis::Result(), ana::NumuCCIncAnalysis::Result(), ana::NumuCC2p2hAnalysis::Result1DFluxInt(), ana::NumuCC2p2hAnalysis::Result2D(), ana::SingleNucAnalysis::Result2D(), ana::NumuCCIncAnalysis::Result2D(), ana::NumuCCIncAnalysis::ReturnHists(), Save(), ana::MichelDecomp::SaveCompPlots(), SaveDCMPPlots(), ana::FluxReweight::SavePlots(), ana::FluxDecomp::SavePlots(), ana::BENDecomp::SavePlots(), ana::TruthReweight::SavePlots(), ana::RecoReweight::SavePlots(), ana::FluxDecomp::SavePlotsKa(), ana::BENDecomp::SavePlotsKa(), ana::BENDecomp::SavePlotsPi(), saveS(), SaveSpectrum(), ScaleCovarianceMatrix(), Selection(), Selection_FOM(), Selection_InvMass(), Selection_Lite(), selection_story_plots(), ShiftedCosmics(), signal_count(), ana::SimpleFOM(), SpectrumParamEffectsAna(), sterile_demo(), syst_plot_test(), systematics_summary_from_pred_interp(), TableNuePredictionFourBins(), template_basic(), test_ana(), test_beam_errorband(), test_fluxhadr_prod_weights_Flux(), test_genie_systs(), test_genieweights(), test_micheldecomp(), test_nue2017Prediction(), test_nue2018_fitter(), test_nueextrapsyst(), test_nuwro(), test_saloaders(), test_sam(), test_sam_project(), test_stanfit_systpulls(), TestPred(), timingPeak(), ana::FluxMultiverseSyst::ToAreaNormalizedTH1(), ana::GenieMultiverseSpectra::ToAreaNormalizedTH1(), ana::Multiverse::ToHist(), ana::CutOptimization::ToHist(), ana::ICrossSectionAnalysis::ToHist(), ana::FluxMultiverseSyst::ToTH1(), ana::GenieMultiverseSpectra::ToTH1(), ana::ToTH2(), ana::ToTH3(), ToTHX(), Toy_analyses(), ana::UnfoldSVD::Truth(), ana::UnfoldTikhonov::Truth(), Unfold1D(), Unfold3D(), UnfoldInOut(), and Uninitialized().

152  {
153  // Could have a file temporarily open
154  DontAddDirectory guard;
155 
156  TH1D* ret = ToTH1(exposure, expotype, bintype);
157 
158  ret->SetLineColor(col);
159  ret->SetMarkerColor(col);
160  ret->SetLineStyle(style);
161 
162  return ret;
163  }
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:149
Int_t col[ntarg]
Definition: Style.C:29
TH1D * ana::Spectrum::ToTH1 ( double  exposure,
EExposureType  expotype,
EBinType  bintype = kBinContent 
) const

Histogram made from this Spectrum, scaled to some exposure.

Parameters
exposurePOT or livetime (seconds)
expotypeHow to interpret exposure (kPOT (default) or kLivetime)

Definition at line 86 of file Spectrum.cxx.

References om::cout, allTimeWatchdog::endl, fAxis, fHist, fLivetime, fPOT, ana::LabelsAndBins::GetBins1D(), ana::LabelsAndBins::GetLabel1D(), ana::kBinDensity, ana::kLivetime, ana::kPOT, livetime, pot, runNovaSAM::ret, and ana::Hist::ToTH1().

89  {
90  // Could have a file temporarily open
91  DontAddDirectory guard;
92 
93  TH1D* ret = fHist.ToTH1(fAxis.GetBins1D());
94 
95  ret->GetXaxis()->SetTitle(fAxis.GetLabel1D().c_str());
96  ret->GetYaxis()->SetTitle("Events");
97 
98  if(expotype == kPOT){
99  const double pot = exposure;
100  if(fPOT){
101  ret->Scale(pot/fPOT);
102  }
103  else{
104  // Allow zero POT if there are also zero events
105  if(ret->Integral() > 0){
106  std::cout << "Error: Spectrum with " << ret->Integral()
107  << " entries has zero POT, no way to scale to "
108  << exposure << " POT.";
109  if(fLivetime > 0){
110  std::cout << " Spectrum has " << fLivetime << " seconds livetime. "
111  << "Did you mean to pass kLivetime to ToTH1()?";
112  }
113  std::cout << std::endl;
114  abort();
115  }
116  }
117  }
118  if(expotype == kLivetime){
119  const double livetime = exposure;
120  if(fLivetime){
121  ret->Scale(livetime/fLivetime);
122  }
123  else{
124  // Allow zero exposure if there are also zero events
125  if(ret->Integral() > 0){
126  std::cout << "Error: Spectrum with " << ret->Integral()
127  << " entries has zero livetime, no way to scale to "
128  << livetime << " seconds.";
129  if(fPOT > 0){
130  std::cout << " Spectrum has " << fPOT << " POT. "
131  << "Did you mean to pass kPOT to ToTH1()?";
132  }
133  std::cout << std::endl;
134  abort();
135  }
136  }
137  }
138 
139  if(bintype == kBinDensity) ret->Scale(1, "width");
140 
141  // Allow GetMean() and friends to work even if this histogram never had any
142  // explicit Fill() calls made.
143  if(ret->GetEntries() == 0) ret->SetEntries(1);
144 
145  return ret;
146  }
LabelsAndBins fAxis
Definition: Spectrum.h:291
Divide bin contents by bin widths.
Definition: UtilsExt.h:31
TH1D * ToTH1(const Binning &bins) const
Definition: Hist.cxx:207
double fPOT
Definition: Spectrum.h:285
const std::string & GetLabel1D() const
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
#define pot
double fLivetime
Definition: Spectrum.h:286
OStream cout
Definition: OStream.cxx:6
double livetime
Definition: saveFDMCHists.C:21
TH2 * ana::Spectrum::ToTH2 ( double  exposure,
EExposureType  expotype = kPOT,
EBinType  bintype = kBinContent 
) const

Spectrum must be 2D to obtain TH2.

Definition at line 166 of file Spectrum.cxx.

References om::cout, allTimeWatchdog::endl, GetBinnings(), GetLabels(), ana::kBinDensity, NDimensions(), runNovaSAM::ret, and ana::ToTH2().

Referenced by ana::nueccinc::NueCCIncMRECorrection::CalcEfficiencyCorrection(), demo6(), ana::nueccinc::NueCCIncCrossSectionAnalysis::doUnfolding1D(), ana::nueccinc::NueCCIncCrossSectionAnalysis::doUnfolding2D(), drawLongTerm(), drawTimePlots(), drawVsPOT(), FD_Data_PosComp(), FD_plots(), GetHistsFD(), GetHistsND(), GetSpectra2D(), getTimePeakPlots(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getUnfoldingMatrix(), HadEFit(), Make2DPlot(), make_quantiles_histogram_2020(), makeEnergyEstimator(), MakePlots(), ana::MakeQuantileHistogram(), mec_nux_tester_2020(), mec_tuning(), mec_tuning_fitter_2020(), MichelDecompTest(), MuonFit(), plot_2d(), plot_2d_vars(), plot_pi0_xcheck(), ana::SingleNucAnalysis::PlotBackgroundEstimate2D(), ana::NumuCC2p2hAnalysis::PlotBackgroundEstimate2D(), ana::SingleNucAnalysis::PlotData2D(), ana::NumuCC2p2hAnalysis::PlotData2D(), ana::SingleNucAnalysis::PlotUnfoldedSignal2D(), ana::NumuCC2p2hAnalysis::PlotUnfoldedSignal2D(), PlotVertices(), PositionComparison(), print_tables(), PrintPlot(), Save(), saveS1(), signal_count(), ana::Multiverse::ToHist(), ana::CutOptimization::ToHist(), ana::ICrossSectionAnalysis::ToHist(), ana::GenieMultiverseSpectra::ToTH2(), ToTHX(), and Uninitialized().

167  {
168  if(NDimensions() != 2){
169  std::cout << "Error: This Spectrum does not appear to be 2D." << std::endl;
170  abort();
171  }
172 
173  TH2* ret = ana::ToTH2(*this, exposure, expotype, GetBinnings()[0], GetBinnings()[1]);
174 
175  ret->GetXaxis()->SetTitle(GetLabels()[0].c_str());
176  ret->GetYaxis()->SetTitle(GetLabels()[1].c_str());
177 
178  if(bintype == kBinDensity) ret->Scale(1, "width");
179 
180  // Allow GetMean() and friends to work even if this histogram never had any
181  // explicit Fill() calls made.
182  if(ret->GetEntries() == 0) ret->SetEntries(1);
183 
184  return ret;
185  }
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:264
Divide bin contents by bin widths.
Definition: UtilsExt.h:31
unsigned int NDimensions() const
Definition: Spectrum.h:262
OStream cout
Definition: OStream.cxx:6
const std::vector< std::string > & GetLabels() const
Definition: Spectrum.h:263
TH2 * ToTH2(const Spectrum &s, double exposure, ana::EExposureType expotype, const Binning &binsx, const Binning &binsy, ana::EBinType bintype)
For use with Var2D.
Definition: UtilsExt.cxx:115
TH3 * ana::Spectrum::ToTH3 ( double  exposure,
EExposureType  expotype = kPOT,
EBinType  bintype = kBinContent 
) const

Spectrum must be 3D to obtain TH3.

Definition at line 188 of file Spectrum.cxx.

References om::cout, allTimeWatchdog::endl, GetBinnings(), GetLabels(), ana::kBinDensity, NDimensions(), runNovaSAM::ret, and ana::ToTH3().

Referenced by ana::FluxDecomp::MakeWeightsNumuFromPion(), ana::BENDecomp::MakeWeightsNumuFromPion(), ana::FluxDecomp::NueEstimateFromPi(), ana::BENDecomp::NueEstimateFromPi(), plot_eff_purity(), Save(), ana::FluxDecomp::SavePlotsPi(), ana::BENDecomp::SavePlotsPi(), ana::Multiverse::ToHist(), ana::CutOptimization::ToHist(), ana::ICrossSectionAnalysis::ToHist(), ToTHX(), and Uninitialized().

189  {
190  if(NDimensions() != 3){
191  std::cout << "Error: This Spectrum does not appear to be 3D." << std::endl;
192  abort();
193  }
194 
195  TH3* ret = ana::ToTH3(*this, exposure, expotype,
196  GetBinnings()[0], GetBinnings()[1], GetBinnings()[2]);
197 
198  ret->GetXaxis()->SetTitle(GetLabels()[0].c_str());
199  ret->GetYaxis()->SetTitle(GetLabels()[1].c_str());
200  ret->GetZaxis()->SetTitle(GetLabels()[2].c_str());
201 
202  if(bintype == kBinDensity) ret->Scale(1, "width");
203 
204  // Allow GetMean() and friends to work even if this histogram never had any
205  // explicit Fill() calls made.
206  if(ret->GetEntries() == 0) ret->SetEntries(1);
207 
208  return ret;
209  }
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:264
Divide bin contents by bin widths.
Definition: UtilsExt.h:31
unsigned int NDimensions() const
Definition: Spectrum.h:262
OStream cout
Definition: OStream.cxx:6
const std::vector< std::string > & GetLabels() const
Definition: Spectrum.h:263
TH3 * ToTH3(const Spectrum &s, double exposure, ana::EExposureType expotype, const Binning &binsx, const Binning &binsy, const Binning &binsz, ana::EBinType bintype)
Same as ToTH2, but with 3 dimensions.
Definition: UtilsExt.cxx:162
TH1 * ana::Spectrum::ToTHX ( double  exposure,
EExposureType  expotype = kPOT,
EBinType  bintype = kBinContent 
) const

Definition at line 212 of file Spectrum.cxx.

References NDimensions(), ToTH1(), ToTH2(), and ToTH3().

Referenced by Uninitialized().

213  {
214  if(NDimensions() == 2) return ToTH2(exposure, expotype, bintype);
215  if(NDimensions() == 3) return ToTH3(exposure, expotype, bintype);
216  return ToTH1(exposure, expotype, bintype);
217  }
TH2 * ToTH2(double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Spectrum must be 2D to obtain TH2.
Definition: Spectrum.cxx:166
TH1D * ToTH1(double exposure, Color_t col=kBlack, Style_t style=kSolid, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Histogram made from this Spectrum, scaled to some exposure.
Definition: Spectrum.cxx:149
unsigned int NDimensions() const
Definition: Spectrum.h:262
TH3 * ToTH3(double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Spectrum must be 3D to obtain TH3.
Definition: Spectrum.cxx:188
static Spectrum ana::Spectrum::Uninitialized ( )
inlinestatic

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

Definition at line 145 of file Spectrum.h.

References col, Fill(), ana::kBinContent, ana::kPOT, operator=(), Spectrum(), ToTH1(), ToTH2(), ToTH3(), ToTHX(), w, submit_syst::x, and ~Spectrum().

Referenced by ana::PredictionAddRock::RockComponent().

145 {return Spectrum();}
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:268

Friends And Related Function Documentation

friend class Ratio
friend

Definition at line 46 of file Spectrum.h.

friend class SpectrumLoaderBase
friend

Definition at line 43 of file Spectrum.h.

friend class SpectrumSink
friend

Definition at line 44 of file Spectrum.h.

friend class SpectrumSinkBase< Spectrum >
friend

Definition at line 45 of file Spectrum.h.

Member Data Documentation

LabelsAndBins ana::Spectrum::fAxis
protected

Definition at line 291 of file Spectrum.h.

Referenced by Fill(), GetBinnings(), GetLabels(), Mean(), NDimensions(), operator=(), SaveTo(), Spectrum(), and ToTH1().

Hist ana::Spectrum::fHist
protected
double ana::Spectrum::fLivetime
protected
double ana::Spectrum::fPOT
protected
std::set<Spectrum**> ana::Spectrum::fReferences
protected

Things that point at this Spectrum. Maintained by SpectrumLoader.

Definition at line 289 of file Spectrum.h.

Referenced by AddLoader(), operator=(), RemoveLoader(), Spectrum(), and ~Spectrum().


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