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.06/src/CAFAna/Core/Spectrum.h"

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...
 
TH2 * ToTH2NormX (double exposure, EExposureType expotype=kPOT) const
 Spectrum must be 2D to obtain TH2. Normalized to X axis. More...
 
TH3 * ToTH3 (double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
 Spectrum must be 3D to obtain TH3. More...
 
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 idx=0) const
 Mock data is FakeData with Poisson fluctuations applied. More...
 
Spectrum FakeData (double pot) const
 Fake data is a MC spectrum scaled to the POT expected in the data. More...
 
Spectrum FakeData (double pot, double livetime) const
 
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 37 of file Spectrum.cxx.

40  : fHist(Hist::Adopt(std::move(h))), fPOT(pot), fLivetime(livetime), fAxis(axis)
41  {
42  }
LabelsAndBins fAxis
Definition: Spectrum.h:283
double fPOT
Definition: Spectrum.h:277
#define pot
double fLivetime
Definition: Spectrum.h:278
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 45 of file Spectrum.cxx.

49  {
50  }
LabelsAndBins fAxis
Definition: Spectrum.h:283
double fPOT
Definition: Spectrum.h:277
#define pot
double fLivetime
Definition: Spectrum.h:278
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:283
double fPOT
Definition: Spectrum.h:277
#define pot
double fLivetime
Definition: Spectrum.h:278
double livetime
Definition: saveFDMCHists.C:21
ana::Spectrum::~Spectrum ( )
virtual

Definition at line 78 of file Spectrum.cxx.

References fReferences.

Referenced by Uninitialized().

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

Definition at line 53 of file Spectrum.cxx.

References ana::assert(), and fReferences.

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

Constructor for Uninitialized()

Definition at line 260 of file Spectrum.h.

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

Referenced by Uninitialized().

262  fPOT(0), fLivetime(0),
263  fAxis(std::vector<std::string>(), std::vector<Binning>())
264  {
265  }
LabelsAndBins fAxis
Definition: Spectrum.h:283
double fPOT
Definition: Spectrum.h:277
double fLivetime
Definition: Spectrum.h:278
static Hist Uninitialized()
Definition: Hist.h:38
ana::Spectrum::Spectrum ( const LabelsAndBins axis,
ESparse  sparse = kDense 
)
protected

Helper for constructors.

Definition at line 23 of file Spectrum.cxx.

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

25  {
26  const Binning bins1D = fAxis.GetBins1D();
27 
28  if(sparse == kSparse){
29  fHist = Hist::ZeroSparse(bins1D.NBins());
30  }
31  else{
32  fHist = Hist::Zero(bins1D.NBins());
33  }
34  }
LabelsAndBins fAxis
Definition: Spectrum.h:283
double fPOT
Definition: Spectrum.h:277
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:278
static Hist Zero(int nbins)
Definition: Hist.cxx:41
static Hist Uninitialized()
Definition: Hist.h:38

Member Function Documentation

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

Definition at line 384 of file Spectrum.cxx.

References fReferences.

Referenced by Spectrum().

385  {
386  fReferences.insert(ref);
387  }
std::set< Spectrum ** > fReferences
Things that point at this Spectrum. Maintained by SpectrumLoader.
Definition: Spectrum.h:281
void ana::Spectrum::Clear ( void  )
Spectrum ana::Spectrum::FakeData ( double  pot) const

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

Use for sensitivity plots and testing fit convergence

Definition at line 341 of file Spectrum.cxx.

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

Referenced by BlessedPlotsLoad(), caf_numu_sensitivity(), caf_numu_sensitivity_no_tau(), cc(), demo_CPT(), ana::FDPredictionSterile::FakeData(), ana::NDPredictionSterile::FakeData(), futureSig_reach_singlePOTcombo_syst(), GenerateFutureData(), ana2019::fakedata::Get2019Prediction(), getContProf_Sensitivity(), GetEigenStan(), GetFakeData(), getSensitivity(), make_plots(), MakeExtrapSurface(), MakeFakeData(), MakeNusPrediction(), makeSystTable(), makeSystTable_reduced(), MichelDecompTest(), MockData(), NDDataMCSystBandAna(), numu_sig_nonmax(), PlotNus17Prediction(), plots(), saveContours_addExpt(), saveContours_complete(), saveContours_oscpar(), saveContours_simple(), saveContours_systs(), starPlot(), syst_test(), template_basic(), template_GENIE_systs(), template_nonGENIE_systs(), test_ana(), test_stanfit_statsonly(), test_stanfit_systpulls(), test_stanfit_withsysts(), and ana::UnfoldIterative::Truth().

342  {
343  Spectrum ret = *this;
344  if(fPOT > 0) ret.fHist.Scale(pot/fPOT);
345  ret.fPOT = pot;
346 
347  // Drop old errors, which are based on the MC statistics, and create new
348  // ones that are based on the prediction for the data
349  ret.fHist.ResetErrors();
350 
351  return ret;
352  }
double fPOT
Definition: Spectrum.h:277
#define pot
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:260
Spectrum ana::Spectrum::FakeData ( 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 355 of file Spectrum.cxx.

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

356  {
357  Spectrum ret = *this;
358 
359  if(fPOT > 0) ret.fHist.Scale(pot/fPOT);
360  ret.fPOT = pot;
361 
362  // overwrite livetime for fake data
363  // PlusEqualsHelper will take over the rest
364  ret.fLivetime = livetime;
365 
366  ret.fHist.ResetErrors();
367 
368  return ret;
369  }
double fPOT
Definition: Spectrum.h:277
#define pot
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:260
double livetime
Definition: saveFDMCHists.C:21
void ana::Spectrum::Fill ( double  x,
double  w = 1 
)

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

317  {
318  fHist.Fill(fAxis.GetBins1D(), x, w);
319  // TODO Pull binning out of Hist entirely and just update an index?
320  }
LabelsAndBins fAxis
Definition: Spectrum.h:283
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 242 of file Spectrum.cxx.

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

243  {
244  if(expotype == kPOT)
245  return (exposure/fPOT) * fHist.GetEigen();
246  else
247  return (exposure/fLivetime) * fHist.GetEigen();
248  }
const Eigen::ArrayXd & GetEigen() const
Definition: Hist.h:53
double fPOT
Definition: Spectrum.h:277
double fLivetime
Definition: Spectrum.h:278
const Eigen::ArrayXstan& ana::Spectrum::GetEigenStan ( ) const
inline
Eigen::ArrayXstan ana::Spectrum::GetEigenStan ( double  exposure,
EExposureType  expotype = kPOT 
) const

Definition at line 251 of file Spectrum.cxx.

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

252  {
253  if(expotype == kPOT)
254  return (exposure/fPOT) * fHist.GetEigenStan();
255  else
256  return (exposure/fLivetime) * fHist.GetEigenStan();
257  }
double fPOT
Definition: Spectrum.h:277
double fLivetime
Definition: Spectrum.h:278
const Eigen::ArrayXstan & GetEigenStan() const
Definition: Hist.h:54
const std::vector<std::string>& ana::Spectrum::GetLabels ( ) const
inline
bool ana::Spectrum::HasStan ( ) const
inline

Definition at line 186 of file Spectrum.h.

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

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

186 {return fHist.HasStan();}
bool HasStan() const
Definition: Hist.h:52
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 272 of file Spectrum.cxx.

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

Referenced by BicountEllipse_dCP(), ana::CountingExperiment::ChiSq(), ComputeEfficiency(), ana::DataMCAreaNormalizedRatio(), 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().

274  {
275  const double ratio = (expotype == kPOT) ? exposure/fPOT : exposure/fLivetime;
276 
277  if(err){
278  *err = 0;
279 
280  for(int i = 0; i < fHist.GetNbinsX()+2; ++i){
281  *err += util::sqr(fHist.GetBinError(i));
282  }
283  *err = sqrt(*err) * ratio;
284  }
285 
286  return fHist.Integral() * ratio;
287  }
double Integral() const
Definition: Hist.cxx:252
T sqrt(T number)
Definition: d0nt_math.hpp:156
TH1 * ratio(TH1 *h1, TH1 *h2)
int GetNbinsX() const
Definition: Hist.cxx:228
double fPOT
Definition: Spectrum.h:277
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
double fLivetime
Definition: Spectrum.h:278
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 222 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().

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

Definition at line 546 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, 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(), 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(), LoadFakeData(), ana::CountingExperiment::LoadFrom(), jw::TrivialPrediction::LoadFrom(), ana::CheatDecomp::LoadFrom(), ana::FluxReweight::LoadFrom(), ana::NCDecomp::LoadFrom(), ana::NueDecomp::LoadFrom(), ana::SingleSampleExperiment::LoadFrom(), ana::TrivialPrediction::LoadFrom(), ana::NumuDecomp::LoadFrom(), ana::CrossSectionSpectra::LoadFrom(), ana::ProportionalDecomp::LoadFrom(), ana::CutOptimization::LoadFrom(), ana::TrivialExtrap::LoadFrom(), ana::FakeDecomp::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(), mec_tuning_fitter_2020(), MRDiFStudy_FHC_Step2(), MRDiFStudy_RHC_Step2(), 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_ND_DataMC(), plot_ND_DataMC_energybinning(), plot_nd_spectra_2018(), plot_recoE_numu(), plot_spectra_2dplots(), plot_uncertainty(), 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(), twodvtxcontplotter(), Unfold1D(), Unfold3D(), vertexstudyploter(), xsec_tot_uncert_optimization(), and xsec_uncertainty_per_bin().

547  {
548  dir = dir->GetDirectory(name.c_str()); // switch to subdir
549  assert(dir);
550 
551  DontAddDirectory guard;
552 
553  TObjString* tag = (TObjString*)dir->Get("type");
554  assert(tag);
555  assert(tag->GetString() == "Spectrum");
556  delete tag;
557 
558  TH1* hPot = (TH1*)dir->Get("pot");
559  assert(hPot);
560  TH1* hLivetime = (TH1*)dir->Get("livetime");
561  assert(hLivetime);
562 
563  std::vector<std::string> labels;
564  std::vector<Binning> bins;
565  for(int i = 0; ; ++i){
566  const std::string subname = TString::Format("bins%d", i).Data();
567  TDirectory* subdir = dir->GetDirectory(subname.c_str());
568  if(!subdir) break;
569  delete subdir;
570  bins.push_back(*Binning::LoadFrom(dir, subname));
571  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
572  labels.push_back(label ? label->GetString().Data() : "");
573  delete label;
574  }
575 
576  std::unique_ptr<Spectrum> ret = std::make_unique<Spectrum>(Eigen::ArrayXd(), LabelsAndBins(labels, bins), hPot->GetBinContent(1), hLivetime->GetBinContent(1));
577  ret->fHist = Hist::FromDirectory(dir);
578 
579  delete hPot;
580  delete hLivetime;
581 
582  delete dir;
583 
584  return ret;
585  }
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Binning.cxx:264
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
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
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
double ana::Spectrum::Mean ( ) const

Return mean of 1D histogram.

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

291  {
292  const Binning bins = fAxis.GetBins1D();
293 
294  if(fHist.GetBinContent(0) != 0){
295  std::cout << "Spectrum::Mean(): Warning ignoring underflow bin content " << fHist.GetBinContent(0) << std::endl;
296  }
297 
298  if(fHist.GetBinContent(bins.NBins()+1) != 0){
299  std::cout << "Spectrum::Mean(): Warning ignoring overflow bin content " << fHist.GetBinContent(bins.NBins()+1) << std::endl;
300  }
301 
302  double mean = 0;
303  double W = 0;
304  for(int i = 1; i <= bins.NBins(); ++i){
305  const double w = fHist.GetBinContent(i);
306  W += w;
307  const double x0 = bins.Edges()[i-1];
308  const double x1 = bins.Edges()[i];
309  mean += w * (x0+x1)/2;
310  }
311 
312  return mean/W;
313  }
LabelsAndBins fAxis
Definition: Spectrum.h:283
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  idx = 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

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

324  {
326 
327  TRandom3 rnd(idx); // zero seeds randomly
328 
329  for(int i = 0; i < ret.fHist.GetNbinsX()+2; ++i){
330  ret.fHist.SetBinContent(i, rnd.Poisson(ret.fHist.GetBinContent(i)));
331  }
332 
333  // Drop old errors, which are based on the MC statistics, and create new
334  // ones that are based on the prediction for the data
335  ret.fHist.ResetErrors();
336 
337  return ret;
338  }
Spectrum FakeData(double pot) const
Fake data is a MC spectrum scaled to the POT expected in the data.
Definition: Spectrum.cxx:341
#define pot
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:260
unsigned int ana::Spectrum::NDimensions ( ) const
inline
Spectrum ana::Spectrum::operator* ( const Ratio rhs) const

Definition at line 494 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

495  {
496  Spectrum ret = *this;
497  ret *= rhs;
498  return ret;
499  }
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:260
Spectrum & ana::Spectrum::operator*= ( const Ratio rhs)

Definition at line 487 of file Spectrum.cxx.

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

Referenced by OverrideLivetime().

488  {
489  fHist.Multiply(rhs.fHist);
490  return *this;
491  }
void Multiply(const Hist &rhs)
Definition: Hist.cxx:479
Spectrum ana::Spectrum::operator+ ( const Spectrum rhs) const

Definition at line 465 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

466  {
467  Spectrum ret = *this;
468  ret += rhs;
469  return ret;
470  }
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:260
Spectrum & ana::Spectrum::operator+= ( const Spectrum rhs)

Definition at line 459 of file Spectrum.cxx.

References PlusEqualsHelper().

Referenced by OverrideLivetime().

460  {
461  return PlusEqualsHelper(rhs, +1);
462  }
Spectrum & PlusEqualsHelper(const Spectrum &rhs, int sign)
Helper for operator+= and operator-=.
Definition: Spectrum.cxx:390
Spectrum ana::Spectrum::operator- ( const Spectrum rhs) const

Definition at line 479 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

480  {
481  Spectrum ret = *this;
482  ret -= rhs;
483  return ret;
484  }
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:260
Spectrum & ana::Spectrum::operator-= ( const Spectrum rhs)

Definition at line 473 of file Spectrum.cxx.

References PlusEqualsHelper().

Referenced by OverrideLivetime().

474  {
475  return PlusEqualsHelper(rhs, -1);
476  }
Spectrum & PlusEqualsHelper(const Spectrum &rhs, int sign)
Helper for operator+= and operator-=.
Definition: Spectrum.cxx:390
Spectrum ana::Spectrum::operator/ ( const Ratio rhs) const

Definition at line 509 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

510  {
511  Spectrum ret = *this;
512  ret /= rhs;
513  return ret;
514  }
Spectrum()
Constructor for Uninitialized()
Definition: Spectrum.h:260
Spectrum & ana::Spectrum::operator/= ( const Ratio rhs)

Definition at line 502 of file Spectrum.cxx.

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

Referenced by OverrideLivetime().

503  {
504  fHist.Divide(rhs.fHist);
505  return *this;
506  }
void Divide(const Hist &rhs)
Definition: Hist.cxx:531
Spectrum & ana::Spectrum::operator= ( const Spectrum rhs)

Definition at line 63 of file Spectrum.cxx.

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

Referenced by Uninitialized().

64  {
65  if(this == &rhs) return *this;
66 
67  fHist = rhs.fHist;
68  fPOT = rhs.fPOT;
69  fLivetime = rhs.fLivetime;
70  fAxis = rhs.fAxis;
71 
72  assert(fReferences.empty()); // Copying with pending loads is unexpected
73 
74  return *this;
75  }
LabelsAndBins fAxis
Definition: Spectrum.h:283
std::set< Spectrum ** > fReferences
Things that point at this Spectrum. Maintained by SpectrumLoader.
Definition: Spectrum.h:281
double fPOT
Definition: Spectrum.h:277
double fLivetime
Definition: Spectrum.h:278
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 390 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().

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

Definition at line 219 of file Spectrum.h.

References fPOT.

Referenced by ana::nueccinc::NueCCIncCrossSectionAnalysis::AddEnhancedSample(), ana::DataMCPair::AddExposure(), ApplyOscillations(), caf_numu_fd_validation_data(), 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(), 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(), makeFlatWeight(), MakeHBar(), makeMatrixElementSurface(), MakePlot(), MakePlots(), ana::MakeQuantileHistogram(), MakeSelectionPlots(), ana::FluxDecomp::MakeWeightsNumuFromKaon(), ana::BENDecomp::MakeWeightsNumuFromKaon(), ana::FluxDecomp::MakeWeightsNumuFromPion(), ana::BENDecomp::MakeWeightsNumuFromPion(), ana::MichelDecomp::MCToDCMPComp(), mec_tuning_fitter_2020(), ana::PredictionExtendToPeripheral::MergePeripheral(), MichelDecompTest(), mrbrem_get_reweighted_spectra(), mrbrem_plots(), mre_blessed(), mre_comp_split(), 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_data_mc(), 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(), 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::SingleNucAnalysis::Result2D(), ana::NumuCC2p2hAnalysis::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(), 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().

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

Definition at line 378 of file Spectrum.cxx.

References fReferences.

Referenced by Spectrum().

379  {
380  fReferences.erase(ref);
381  }
std::set< Spectrum ** > fReferences
Things that point at this Spectrum. Maintained by SpectrumLoader.
Definition: Spectrum.h:281
void ana::Spectrum::SaveTo ( TDirectory *  dir,
const std::string &  name 
) const

Definition at line 517 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(), caf_nue_data_mc(), 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(), 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(), make_mockdata_syst_contours(), make_pi0_xcheck(), make_pid(), MakeCosmics(), MakeFakeData(), makeFakeDataFluxes(), MakeNus17Prediction(), MakeNus18SidebandPred(), MakeNusPrediction(), makeRealDataFluxes(), makeXSecPlots_TemplateFit(), 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(), preselection_cutflow(), 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::TrivialPrediction::SaveTo(), ana::NumuDecomp::SaveTo(), ana::CrossSectionSpectra::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(), TrueNCSpectrum(), TrueSpectrumFromKaons(), twodstudyvtxcont(), validationscript(), and vertexstudy().

518  {
519  TDirectory* tmp = gDirectory;
520 
521  dir = dir->mkdir(name.c_str()); // switch to subdir
522  dir->cd();
523 
524  TObjString("Spectrum").Write("type");
525 
527  TH1D hPot("", "", 1, 0, 1);
528  hPot.Fill(.5, fPOT);
529  hPot.Write("pot");
530  TH1D hLivetime("", "", 1, 0, 1);
531  hLivetime.Fill(.5, fLivetime);
532  hLivetime.Write("livetime");
533 
534  for(unsigned int i = 0; i < NDimensions(); ++i){
535  TObjString(GetLabels()[i].c_str()).Write(TString::Format("label%d", i).Data());
536  GetBinnings()[i].SaveTo(dir, TString::Format("bins%d", i).Data());
537  }
538 
539  dir->Write();
540  delete dir;
541 
542  tmp->cd();
543  }
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:256
const XML_Char * name
Definition: expat.h:151
void Write(const Binning &bins) const
Definition: Hist.cxx:583
LabelsAndBins fAxis
Definition: Spectrum.h:283
double fPOT
Definition: Spectrum.h:277
Float_t tmp
Definition: plot.C:36
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
double fLivetime
Definition: Spectrum.h:278
unsigned int NDimensions() const
Definition: Spectrum.h:254
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:255
void ana::Spectrum::Scale ( double  c)
void ana::Spectrum::Scale ( const stan::math::var v)

Definition at line 266 of file Spectrum.cxx.

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

267  {
268  fHist.Scale(c);
269  }
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 148 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(), caf_numu_fd_validation_data(), caf_numu_fd_validation_MC(), caf_numu_fd_validation_MC_no_tau(), calcAlphaBetaEachBin(), CalcChi2(), ana::nueccinc::NueCCIncMRECorrection::CalcEfficiencyCorrection(), CalcR(), CalcRWithSystsNus17(), calculateComponentsNumu(), calculateWrongSignNue(), calculateWrongSignNumuQ1(), calculateWrongSignNumuQ2(), calculateWrongSignNumuQ3(), calculateWrongSignNumuQ4(), cc(), check_predinterp(), check_predinterp_numu(), ana::OscCovMxExperiment::ChiSq(), ana::LikelihoodCovMxExperiment::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(), 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(), MakeFakeData(), 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(), 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_data_mc(), 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(), ana::PlotWithSystErrorBand(), ana::PlotWithSystErrorBand_Quant(), ana::PlotWithSystErrorBandTwoPreds(), ana::covmx::CovarianceMatrix::Predict(), PredictCosmic(), preselection_cutflow(), ana::SpectrumComponents::Purity(), ana::TwoSampleDecomp::RatioCalc(), reco_minus_true_panels(), resolution2018(), ana::CrossSectionAnalysis::Result(), ana::NumuCCIncAnalysis::Result(), ana::NumuCC2p2hAnalysis::Result1DFluxInt(), ana::SingleNucAnalysis::Result2D(), ana::NumuCC2p2hAnalysis::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(), ScaleCovarianceMatrix(), 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(), Toy_analyses(), ana::UnfoldSVD::Truth(), ana::UnfoldTikhonov::Truth(), Unfold1D(), Unfold3D(), UnfoldInOut(), and Uninitialized().

151  {
152  // Could have a file temporarily open
153  DontAddDirectory guard;
154 
155  TH1D* ret = ToTH1(exposure, expotype, bintype);
156 
157  ret->SetLineColor(col);
158  ret->SetMarkerColor(col);
159  ret->SetLineStyle(style);
160 
161  return ret;
162  }
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:148
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 85 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().

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

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

Spectrum must be 2D to obtain TH2. Normalized to X axis.

If no entries in the column, skip normalization

Definition at line 187 of file Spectrum.cxx.

References GetBinnings(), MECModelEnuComparisons::i, calib::j, nbinsx, norm, and ToTH2().

Referenced by Uninitialized().

188  {
189  TH2* xyhist = ToTH2(exposure, expotype);
190  if(!xyhist) return nullptr;
191 
192  const int nbinsx = GetBinnings()[0].NBins();
193  const int nbinsy = GetBinnings()[1].NBins();
194 
195  // Normalize 2D histogram to X-axis spectrum
196  for(int i=1; i<=nbinsx; ++i){
197  double norm = 0.0;
198  for(int j=1; j<=nbinsy; ++j){
199  norm += xyhist->GetBinContent(i, j);
200  }
201  /// If no entries in the column, skip normalization
202  if(norm < 0.0000001) continue;
203 
204  norm = 1.0 / norm;
205  for(int j=1; j<=nbinsy; ++j){
206  xyhist->SetBinContent(i,j, xyhist->GetBinContent(i, j) * norm);
207  }
208  }
209 
210  // Allow GetMean() and friends to work even if this histogram never had any
211  // explicit Fill() calls made.
212  if(xyhist->GetEntries() == 0) xyhist->SetEntries(1);
213 
214  return xyhist;
215  }
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:256
TH2 * ToTH2(double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Spectrum must be 2D to obtain TH2.
Definition: Spectrum.cxx:165
const double j
Definition: BetheBloch.cxx:29
Float_t norm
Int_t nbinsx
Definition: plot.C:23
TH3 * ana::Spectrum::ToTH3 ( double  exposure,
EExposureType  expotype = kPOT,
EBinType  bintype = kBinContent 
) const

Spectrum must be 3D to obtain TH3.

Definition at line 218 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(), Save(), ana::FluxDecomp::SavePlotsPi(), ana::BENDecomp::SavePlotsPi(), ana::Multiverse::ToHist(), ana::CutOptimization::ToHist(), ana::ICrossSectionAnalysis::ToHist(), and Uninitialized().

219  {
220  if(NDimensions() != 3){
221  std::cout << "Error: This Spectrum does not appear to be 3D." << std::endl;
222  abort();
223  }
224 
225  TH3* ret = ana::ToTH3(*this, exposure, expotype,
226  GetBinnings()[0], GetBinnings()[1], GetBinnings()[2]);
227 
228  ret->GetXaxis()->SetTitle(GetLabels()[0].c_str());
229  ret->GetYaxis()->SetTitle(GetLabels()[1].c_str());
230  ret->GetZaxis()->SetTitle(GetLabels()[2].c_str());
231 
232  if(bintype == kBinDensity) ret->Scale(1, "width");
233 
234  // Allow GetMean() and friends to work even if this histogram never had any
235  // explicit Fill() calls made.
236  if(ret->GetEntries() == 0) ret->SetEntries(1);
237 
238  return ret;
239  }
const std::vector< Binning > & GetBinnings() const
Definition: Spectrum.h:256
Divide bin contents by bin widths.
Definition: UtilsExt.h:31
unsigned int NDimensions() const
Definition: Spectrum.h:254
OStream cout
Definition: OStream.cxx:6
const std::vector< std::string > & GetLabels() const
Definition: Spectrum.h:255
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
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(), ToTH2NormX(), ToTH3(), w, submit_syst::x, and ~Spectrum().

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

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

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 283 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 281 of file Spectrum.h.

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


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