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-development.opensciencegrid.org/novasoft/releases/N20-01-22/CAFAna/Core/Spectrum.h"

Public Types

enum  ESparse { kDense, kSparse, kFloat }
 

Public Member Functions

 Spectrum (const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 Spectrum (const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const MultiVar &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 Spectrum (const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const NuTruthVar &var, const NuTruthCut &cut, const SystShifts &shifts=kNoShift, const NuTruthVar &wei=kNuTruthUnweighted)
 
 Spectrum (const std::string &label, SpectrumLoaderBase &loader, const Binning &binsx, const NuTruthVar &varx, const Binning &binsy, const NuTruthVar &vary, const NuTruthCut &cut, const SystShifts &shifts=kNoShift, const NuTruthVar &wei=kNuTruthUnweighted)
 
 Spectrum (SpectrumLoaderBase &loader, const HistAxis &axis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 Spectrum (SpectrumLoaderBase &loader, const MultiVarHistAxis &axis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 Spectrum (SpectrumLoaderBase &loader, const NuTruthHistAxis &axis, const NuTruthCut &cut, const SystShifts &shifts=kNoShift, const NuTruthVar &weight=kNuTruthUnweighted)
 
 Spectrum (const std::string &label, const Binning &bins, ESparse sparse=kDense)
 
 Spectrum (const std::string &label, double pot, double livetime, const Binning &bins)
 
 Spectrum (TH1 *h, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 Copies h. More...
 
 Spectrum (TH1 *h, double pot, double livetime)
 
 Spectrum (std::unique_ptr< TH1D > h, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 Takes possession of h. More...
 
 Spectrum (std::unique_ptr< TH1F > h, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
 Spectrum (const std::string &label, SpectrumLoaderBase &loader, const Binning &binsx, const Var &varx, const Binning &binsy, const Var &vary, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 2D Spectrum of two Vars More...
 
 Spectrum (const std::string &label, SpectrumLoaderBase &loader, const Binning &binsx, const MultiVar &varx, const Binning &binsy, const MultiVar &vary, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 2D Spectrum of two MultiVars More...
 
 Spectrum (SpectrumLoaderBase &loader, const HistAxis &xAxis, const HistAxis &yAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 2D Spectrum taking 2 HistAxis More...
 
 Spectrum (const std::string &xLabel, const std::string &yLabel, SpectrumLoaderBase &loader, const Binning &binsx, const Var &varx, const Binning &binsy, const Var &vary, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 Spectrum (const std::string &xLabel, const std::string &yLabel, SpectrumLoaderBase &loader, const Binning &binsx, const MultiVar &varx, const Binning &binsy, const MultiVar &vary, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 Spectrum (const std::string &label, SpectrumLoaderBase &loader, const Binning &binsx, const Var &varx, const Binning &binsy, const Var &vary, const Binning &binsz, const Var &varz, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted, ESparse sparse=kDense)
 3D Spectrum of three Vars More...
 
 Spectrum (const std::string &xLabel, const std::string &yLabel, const std::string &zLabel, SpectrumLoaderBase &loader, const Binning &binsx, const Var &varx, const Binning &binsy, const Var &vary, const Binning &binsz, const Var &varz, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted, ESparse sparse=kDense)
 
 Spectrum (SpectrumLoaderBase &loader, const HistAxis &xAxis, const HistAxis &yAxis, const HistAxis &zAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted, ESparse sparse=kDense)
 3D Spectrum taking 3 HistAxis More...
 
virtual ~Spectrum ()
 
 Spectrum (const Spectrum &rhs)
 
 Spectrum (Spectrum &&rhs)
 
Spectrumoperator= (const Spectrum &rhs)
 
Spectrumoperator= (Spectrum &&rhs)
 
 Spectrum (const SpectrumStan &rhs)
 Copy conversion from SpectrumStan. More...
 
Spectrumoperator= (const SpectrumStan &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...
 
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...
 
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
 
unsigned int NDimensions () const
 
std::vector< std::string > GetLabels () const
 
std::vector< BinningGetBinnings () const
 

Static Public Member Functions

static std::unique_ptr< SpectrumLoadFrom (TDirectory *dir)
 

Protected Member Functions

 Spectrum (const std::vector< std::string > &labels, const std::vector< Binning > &bins, ESparse sparse=kDense)
 
void ConstructHistogram (ESparse sparse=kDense)
 
void RemoveLoader (SpectrumLoaderBase *)
 
void AddLoader (SpectrumLoaderBase *)
 
SpectrumPlusEqualsHelper (const Spectrum &rhs, int sign)
 Helper for operator+= and operator-=. More...
 

Protected Attributes

TH1D * fHistD
 
TH1F * fHistF
 
THnSparseDfHistSparse
 
double fPOT
 
double fLivetime
 
std::set< SpectrumLoaderBase * > fLoaderCount
 This count is maintained by SpectrumLoader, as a sanity check. More...
 
std::vector< std::string > fLabels
 
std::vector< BinningfBins
 

Friends

class SpectrumStan
 
class SpectrumLoaderBase
 
class SpectrumLoader
 
class NullLoader
 

Detailed Description

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

Definition at line 37 of file Spectrum.h.

Member Enumeration Documentation

Enumerator
kDense 
kSparse 
kFloat 

Definition at line 45 of file Spectrum.h.

Constructor & Destructor Documentation

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

Definition at line 47 of file Spectrum.cxx.

References ana::SpectrumLoaderBase::AddSpectrum().

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

53  : Spectrum(label, bins)
54  {
55  loader.AddSpectrum(*this, var, cut, shift, wei);
56  }
var
const char * label
loader
Definition: demo0.py:10
const Binning bins
Definition: NumuCC_CPiBin.h:8
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  label,
const Binning bins,
SpectrumLoaderBase loader,
const MultiVar var,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 59 of file Spectrum.cxx.

References ana::SpectrumLoaderBase::AddSpectrum().

65  : Spectrum(label, bins)
66  {
67  loader.AddSpectrum(*this, var, cut, shift, wei);
68  }
var
const char * label
loader
Definition: demo0.py:10
const Binning bins
Definition: NumuCC_CPiBin.h:8
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  label,
const Binning bins,
SpectrumLoaderBase loader,
const NuTruthVar var,
const NuTruthCut cut,
const SystShifts shifts = kNoShift,
const NuTruthVar wei = kNuTruthUnweighted 
)

Definition at line 71 of file Spectrum.cxx.

References ana::SpectrumLoaderBase::AddSpectrum().

77  : Spectrum(label, bins)
78  {
79  loader.AddSpectrum(*this, var, cut, shifts, wei);
80  }
var
const char * label
loader
Definition: demo0.py:10
const Binning bins
Definition: NumuCC_CPiBin.h:8
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  label,
SpectrumLoaderBase loader,
const Binning binsx,
const NuTruthVar varx,
const Binning binsy,
const NuTruthVar vary,
const NuTruthCut cut,
const SystShifts shifts = kNoShift,
const NuTruthVar wei = kNuTruthUnweighted 
)

Definition at line 83 of file Spectrum.cxx.

References cut, label, demo0::loader, and ana::Var2D().

89  : Spectrum({label, ""}, {binsx, binsy}) // TODO why no labelY?
90  {
91  loader.AddSpectrum(*this, Var2D(varx, binsx, vary, binsy), cut, shifts, wei);
92  }
const char * label
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
GenericVar< T > Var2D(const GenericVar< T > &a, const Binning &binsa, const GenericVar< T > &b, const Binning &binsb)
Variable formed from two input variables.
Definition: Var.cxx:245
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const HistAxis axis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 95 of file Spectrum.cxx.

References ana::SpectrumLoaderBase::AddSpectrum(), cut, ana::GenericHistAxis< T >::GetMultiDVar(), and plotSysts::shift.

100  : Spectrum(axis.GetLabels(), axis.GetBinnings())
101  {
102  loader.AddSpectrum(*this, axis.GetMultiDVar(), cut, shift, wei);
103  }
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const MultiVarHistAxis axis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 106 of file Spectrum.cxx.

References ana::SpectrumLoaderBase::AddSpectrum(), cut, ana::GenericHistAxis< T >::GetMultiDVar(), and plotSysts::shift.

111  : Spectrum(axis.GetLabels(), axis.GetBinnings())
112  {
113  loader.AddSpectrum(*this, axis.GetMultiDVar(), cut, shift, wei);
114  }
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const NuTruthHistAxis axis,
const NuTruthCut cut,
const SystShifts shifts = kNoShift,
const NuTruthVar weight = kNuTruthUnweighted 
)

Definition at line 117 of file Spectrum.cxx.

References ana::SpectrumLoaderBase::AddSpectrum(), cut, ana::GenericHistAxis< T >::GetMultiDVar(), and ana::weight.

122  : Spectrum(axis.GetLabels(), axis.GetBinnings())
123  {
124  loader.AddSpectrum(*this, axis.GetMultiDVar(), cut, shifts, weight);
125  }
const Var weight
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  label,
const Binning bins,
ESparse  sparse = kDense 
)

Definition at line 37 of file Spectrum.cxx.

References ConstructHistogram().

40  : fHistD(0), fHistF(0), fHistSparse(0), fPOT(0), fLivetime(0),
41  fLabels(1, label), fBins(1, bins)
42  {
43  ConstructHistogram(sparse);
44  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
void ConstructHistogram(ESparse sparse=kDense)
Definition: Spectrum.cxx:508
double fPOT
Definition: Spectrum.h:317
const char * label
std::vector< std::string > fLabels
Definition: Spectrum.h:323
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::vector< Binning > fBins
Definition: Spectrum.h:324
ana::Spectrum::Spectrum ( const std::string &  label,
double  pot,
double  livetime,
const Binning bins 
)

Definition at line 128 of file Spectrum.cxx.

References fLivetime, fPOT, livetime, and pot.

130  : Spectrum(label, bins)
131  {
132  fPOT = pot;
134  }
double fPOT
Definition: Spectrum.h:317
const char * label
#define pot
double fLivetime
Definition: Spectrum.h:318
const Binning bins
Definition: NumuCC_CPiBin.h:8
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( TH1 *  h,
const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
double  pot,
double  livetime 
)

Copies h.

Definition at line 137 of file Spectrum.cxx.

References ana::HistCache::Copy(), fHistD, fHistF, and ana::HistCache::New().

142  {
143  if(!h){
144  fHistD = 0;
145  fHistF = 0;
146  return;
147  }
148 
149  DontAddDirectory guard;
150 
151  const TString className = h->ClassName();
152 
153  if(className == "TH1D"){
154  // Shortcut if types match
155  fHistD = HistCache::Copy((TH1D*)h);
156  }
157  else if(className == "TH1F"){
158  fHistF = HistCache::Copy((TH1F*)h);
159  }
160  else{
161  fHistD = HistCache::New("", h->GetXaxis());
162  fHistD->Add(h);
163  }
164  }
TH1D * fHistD
Definition: Spectrum.h:314
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:175
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
#define pot
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::vector< Binning > fBins
Definition: Spectrum.h:324
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:24
h
Definition: demo3.py:41
ana::Spectrum::Spectrum ( TH1 *  h,
double  pot,
double  livetime 
)

Definition at line 167 of file Spectrum.cxx.

168  : Spectrum(h,
169  std::vector<std::string>(1, h->GetXaxis()->GetTitle()),
170  std::vector<Binning>(1, Binning::FromTAxis(h->GetXaxis())),
171  pot, livetime)
172  {
173  }
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
#define pot
h
Definition: demo3.py:41
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( std::unique_ptr< TH1D >  h,
const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
double  pot,
double  livetime 
)

Takes possession of h.

Definition at line 176 of file Spectrum.cxx.

180  : fHistD(h.release()), fHistF(0), fHistSparse(0), fPOT(pot), fLivetime(livetime), fLabels(labels), fBins(bins)
181  {
182  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
#define pot
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::vector< Binning > fBins
Definition: Spectrum.h:324
h
Definition: demo3.py:41
ana::Spectrum::Spectrum ( std::unique_ptr< TH1F >  h,
const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
double  pot,
double  livetime 
)

Definition at line 185 of file Spectrum.cxx.

189  : fHistD(0), fHistF(h.release()), fHistSparse(0), fPOT(pot), fLivetime(livetime), fLabels(labels), fBins(bins)
190  {
191  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
#define pot
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::vector< Binning > fBins
Definition: Spectrum.h:324
h
Definition: demo3.py:41
ana::Spectrum::Spectrum ( const std::string &  label,
SpectrumLoaderBase loader,
const Binning binsx,
const Var varx,
const Binning binsy,
const Var vary,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

2D Spectrum of two Vars

Definition at line 194 of file Spectrum.cxx.

200  : Spectrum(label, "", loader, binsx, varx, binsy, vary, cut, shift, wei)
201  {
202  // TODO do we want this variant when there's one with a labelY just below?
203  }
const char * label
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  label,
SpectrumLoaderBase loader,
const Binning binsx,
const MultiVar varx,
const Binning binsy,
const MultiVar vary,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

2D Spectrum of two MultiVars

Definition at line 206 of file Spectrum.cxx.

212  : Spectrum(label, "", loader, binsx, varx, binsy, vary, cut, shift, wei)
213  {
214  }
const char * label
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const HistAxis xAxis,
const HistAxis yAxis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

2D Spectrum taking 2 HistAxis

Definition at line 217 of file Spectrum.cxx.

References ana::GenericHistAxis< T >::NDimensions().

223  : Spectrum(xAxis.GetLabels()[0], yAxis.GetLabels()[0],
224  loader,
225  xAxis.GetBinnings()[0], xAxis.GetVars()[0],
226  yAxis.GetBinnings()[0], yAxis.GetVars()[0],
227  cut, shift, wei)
228  {
229  // TODO - do we want to keep this variant around?
230  assert(xAxis.NDimensions() == 1);
231  assert(yAxis.NDimensions() == 1);
232  }
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  xLabel,
const std::string &  yLabel,
SpectrumLoaderBase loader,
const Binning binsx,
const Var varx,
const Binning binsy,
const Var vary,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 235 of file Spectrum.cxx.

References cut, demo0::loader, plotSysts::shift, and ana::Var2D().

243  : Spectrum({xLabel, yLabel}, {binsx, binsy})
244  {
245  Var multiDVar = Var2D(varx, binsx, vary, binsy);
246 
247  loader.AddSpectrum(*this, multiDVar, cut, shift, wei);
248  }
GenericVar< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Definition: Var.h:76
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
GenericVar< T > Var2D(const GenericVar< T > &a, const Binning &binsa, const GenericVar< T > &b, const Binning &binsb)
Variable formed from two input variables.
Definition: Var.cxx:245
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  xLabel,
const std::string &  yLabel,
SpectrumLoaderBase loader,
const Binning binsx,
const MultiVar varx,
const Binning binsy,
const MultiVar vary,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 251 of file Spectrum.cxx.

References cut, demo0::loader, ana::MultiVar2D(), and plotSysts::shift.

259  : Spectrum({xLabel, yLabel}, {binsx, binsy})
260  {
261  MultiVar multiDVar = MultiVar2D(varx, binsx, vary, binsy);
262 
263  loader.AddSpectrum(*this, multiDVar, cut, shift, wei);
264  }
MultiVar MultiVar2D(const MultiVar &a, const Binning &binsa, const MultiVar &b, const Binning &binsb)
Definition: MultiVar.cxx:57
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  label,
SpectrumLoaderBase loader,
const Binning binsx,
const Var varx,
const Binning binsy,
const Var vary,
const Binning binsz,
const Var varz,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted,
ESparse  sparse = kDense 
)

3D Spectrum of three Vars

Definition at line 267 of file Spectrum.cxx.

275  : Spectrum(label, "", "", loader, binsx, varx, binsy, vary, binsz, varz, cut, shift, wei, sparse)
276  {
277  // TODO do we want this variant when there's one with a labelY and labelZ
278  // just below?
279  }
const char * label
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( const std::string &  xLabel,
const std::string &  yLabel,
const std::string &  zLabel,
SpectrumLoaderBase loader,
const Binning binsx,
const Var varx,
const Binning binsy,
const Var vary,
const Binning binsz,
const Var varz,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted,
ESparse  sparse = kDense 
)

Definition at line 282 of file Spectrum.cxx.

References cut, demo0::loader, plotSysts::shift, and ana::Var3D().

293  : Spectrum({xLabel, yLabel, zLabel}, {binsx, binsy, binsz}, sparse)
294  {
295  Var multiDVar = Var3D(varx, binsx, vary, binsy, varz, binsz);
296 
297  loader.AddSpectrum(*this, multiDVar, cut, shift, wei);
298  }
GenericVar< caf::SRProxy > Var
Representation of a variable to be retrieved from a caf::StandardRecord object.
Definition: Var.h:76
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
GenericVar< T > Var3D(const GenericVar< T > &a, const Binning &binsa, const GenericVar< T > &b, const Binning &binsb, const GenericVar< T > &c, const Binning &binsc)
This is just like a Var2D, but useful for 3D Spectra.
Definition: Var.cxx:271
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::Spectrum ( SpectrumLoaderBase loader,
const HistAxis xAxis,
const HistAxis yAxis,
const HistAxis zAxis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted,
ESparse  sparse = kDense 
)

3D Spectrum taking 3 HistAxis

Definition at line 301 of file Spectrum.cxx.

References ana::GenericHistAxis< T >::NDimensions().

309  : Spectrum(xAxis.GetLabels()[0], loader,
310  xAxis.GetBinnings()[0], xAxis.GetVars()[0],
311  yAxis.GetBinnings()[0], yAxis.GetVars()[0],
312  zAxis.GetBinnings()[0], zAxis.GetVars()[0],
313  cut, shift, wei, sparse)
314  {
315  // TODO - do we want to keep this variant around?
316  assert(xAxis.NDimensions() == 1);
317  assert(yAxis.NDimensions() == 1);
318  assert(zAxis.NDimensions() == 1);
319  }
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
ana::Spectrum::~Spectrum ( )
virtual

Definition at line 322 of file Spectrum.cxx.

References om::cerr, ana::HistCache::Delete(), allTimeWatchdog::endl, fHistD, fHistF, fHistSparse, fLoaderCount, and demo0::loader.

Referenced by operator=().

323  {
324  if(fHistD && fHistD->GetDirectory()){
325  static bool once = true;
326  if(once){
327  once = false;
328  std::cerr << "Spectrum's fHist (" << fHistD << ") is associated with a directory (" << fHistD->GetDirectory() << ". How did that happen?" << std::endl;
329  }
330  }
331 
333  { loader->RemoveSpectrum(this); }
334 
337 
338  delete fHistSparse;
339  }
TH1D * fHistD
Definition: Spectrum.h:314
friend class SpectrumLoaderBase
Definition: Spectrum.h:41
TH1F * fHistF
Definition: Spectrum.h:315
OStream cerr
Definition: OStream.cxx:7
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
Definition: Spectrum.h:321
static void Delete(TH1D *&h)
Definition: HistCache.cxx:215
loader
Definition: demo0.py:10
THnSparseD * fHistSparse
Definition: Spectrum.h:316
ana::Spectrum::Spectrum ( const Spectrum rhs)

Definition at line 342 of file Spectrum.cxx.

References ana::HistCache::Copy(), fHistD, fHistF, fHistSparse, and fLoaderCount.

342  :
343  fHistD(0),
344  fHistF(0),
345  fHistSparse(0),
346  fPOT(rhs.fPOT),
347  fLivetime(rhs.fLivetime),
348  fLabels(rhs.fLabels),
349  fBins(rhs.fBins)
350  {
351  DontAddDirectory guard;
352 
353  assert(rhs.fHistD || rhs.fHistF || rhs.fHistSparse);
354  if(rhs.fHistD)
355  fHistD = HistCache::Copy(rhs.fHistD);
356  if(rhs.fHistF)
357  fHistF = HistCache::Copy(rhs.fHistF);
358  if(rhs.fHistSparse){
359  // Doesn't exist?
360  // fHistSparse = new THnSparseD(*rhs.fHistSparse);
361  fHistSparse = (THnSparseD*)rhs.fHistSparse->Clone();
362  }
363 
364  assert( rhs.fLoaderCount.empty() ); // Copying with pending loads is unexpected
365  }
TH1D * fHistD
Definition: Spectrum.h:314
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:175
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
std::vector< Binning > fBins
Definition: Spectrum.h:324
ana::Spectrum::Spectrum ( Spectrum &&  rhs)

Definition at line 368 of file Spectrum.cxx.

References fHistD, fHistF, fHistSparse, fLoaderCount, and demo0::loader.

368  :
369  fHistD(0),
370  fHistF(0),
371  fHistSparse(0),
372  fPOT(rhs.fPOT),
373  fLivetime(rhs.fLivetime),
374  fLabels(rhs.fLabels),
375  fBins(rhs.fBins)
376  {
377  assert(rhs.fHistD || rhs.fHistF || rhs.fHistSparse);
378 
379  if(rhs.fHistD){
380  fHistD = rhs.fHistD;
381  rhs.fHistD = 0;
382  }
383  if(rhs.fHistF){
384  fHistF = rhs.fHistF;
385  rhs.fHistF = 0;
386  }
387  if(rhs.fHistSparse){
388  fHistSparse = rhs.fHistSparse;
389  rhs.fHistSparse = 0;
390  }
391 
392  for (auto & loader : rhs.fLoaderCount)
393  {
394  loader->ReplaceSpectrum(&rhs, this);
395  fLoaderCount.insert(loader);
396  }
397  rhs.fLoaderCount.clear();
398 
399  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
Definition: Spectrum.h:321
double fLivetime
Definition: Spectrum.h:318
loader
Definition: demo0.py:10
THnSparseD * fHistSparse
Definition: Spectrum.h:316
std::vector< Binning > fBins
Definition: Spectrum.h:324
ana::Spectrum::Spectrum ( const SpectrumStan rhs)

Copy conversion from SpectrumStan.

Definition at line 402 of file Spectrum.cxx.

References ConstructHistogram(), fHistD, fHistF, ana::SpectrumStan::GetBinnings(), ana::gFloatMode, ana::SpectrumStan::POT(), ana::SpectrumStan::ToBins(), and febshutoff_auto::val.

403  : fHistD(nullptr), fHistF(nullptr), fHistSparse(nullptr),
404  fPOT(rhs.POT()), fLivetime(rhs.Livetime()),
405  fLabels(rhs.GetLabels()), fBins(rhs.GetBinnings())
406  {
407  // for now we don't have any other use cases besides 1D...
408  assert(rhs.GetBinnings().size() == 1);
409 
411 
412  // now fill in the bin content...
413  auto binC = rhs.ToBins(rhs.POT());
414  for (int binIdx = 0; binIdx < rhs.GetBinnings()[0].NBins()+2; binIdx++) // be sure to get under- and overflow
415  {
416  if (gFloatMode)
417  fHistF->SetBinContent(binIdx, binC[binIdx].val());
418  else
419  fHistD->SetBinContent(binIdx, binC[binIdx].val());
420  }
421  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
void ConstructHistogram(ESparse sparse=kDense)
Definition: Spectrum.cxx:508
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
double fLivetime
Definition: Spectrum.h:318
const HistogramTypePolicy gFloatMode
THnSparseD * fHistSparse
Definition: Spectrum.h:316
std::vector< Binning > fBins
Definition: Spectrum.h:324
ana::Spectrum::Spectrum ( const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
ESparse  sparse = kDense 
)
protected

Definition at line 26 of file Spectrum.cxx.

References ConstructHistogram().

29  : fHistD(0), fHistF(0), fHistSparse(0), fPOT(0), fLivetime(0),
31  {
32  ConstructHistogram(sparse);
33  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
void ConstructHistogram(ESparse sparse=kDense)
Definition: Spectrum.cxx:508
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
const Binning bins
Definition: NumuCC_CPiBin.h:8
std::vector< Binning > fBins
Definition: Spectrum.h:324

Member Function Documentation

void ana::Spectrum::AddLoader ( SpectrumLoaderBase p)
protected

Definition at line 890 of file Spectrum.cxx.

References fLoaderCount.

Referenced by ana::SpectrumLoaderBase::AddSpectrum(), and GetBinnings().

891  { fLoaderCount.insert(p); }
const char * p
Definition: xmltok.h:285
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
Definition: Spectrum.h:321
void ana::Spectrum::Clear ( )
void ana::Spectrum::ConstructHistogram ( ESparse  sparse = kDense)
protected

Definition at line 508 of file Spectrum.cxx.

References b, fBins, fHistD, fHistF, fHistSparse, ana::gFloatMode, ana::Binning::IsSimple(), kDense, kFloat, kSparse, ana::Binning::Max(), ana::Binning::Min(), getGoodRuns4SAM::n, nbins, ana::Binning::NBins(), ana::HistCache::New(), ana::HistCache::NewF(), ana::Binning::Simple(), ana::UniqueName(), make_mec_shifts_plots::xmax, and make_mec_shifts_plots::xmin.

Referenced by GetBinnings(), and Spectrum().

509  {
510  DontAddDirectory guard;
511 
512  assert(!fHistD && !fHistF && !fHistSparse);
513 
514  Binning bins1D = fBins[0];
515  if(fBins.size() > 1){
516  int n = 1;
517  for(const Binning& b: fBins) n *= b.NBins();
518  bins1D = Binning::Simple(n, 0, n);
519  }
520 
521  if(sparse == kSparse){
522  assert(bins1D.IsSimple());
523  const int nbins = bins1D.NBins();
524  const double xmin = bins1D.Min();
525  const double xmax = bins1D.Max();
526  fHistSparse = new THnSparseD(UniqueName().c_str(), UniqueName().c_str(),
527  1, &nbins, &xmin, &xmax);
528 
529  // Ensure errors get accumulated properly
530  fHistSparse->Sumw2();
531  }
532  else if(sparse == kDense && !gFloatMode){
533  fHistD = HistCache::New("", bins1D);
534  fHistF = 0;
535 
536  // first clear the sum-of-weights.
537  // can be pre-filled with 0s if you happen to have made several Spectra
538  // out of the same Binning and a preceding one is still in the cache.
539  fHistD->Sumw2(false);
540  fHistD->Sumw2(); // Ensure errors get accumulated properly
541  }
542  else if(sparse == kFloat || gFloatMode){
543  fHistF = HistCache::NewF("", bins1D);
544  fHistD = 0;
545 
546  // see above
547  fHistF->Sumw2(false);
548  fHistF->Sumw2(); // Ensure errors get accumulated properly
549  }
550  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
const int nbins
Definition: cellShifts.C:15
THnSparseT< TArrayD > THnSparseD
Definition: Spectrum.h:24
const HistogramTypePolicy gFloatMode
THnSparseD * fHistSparse
Definition: Spectrum.h:316
static TH1F * NewF(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:46
std::vector< Binning > fBins
Definition: Spectrum.h:324
const hit & b
Definition: hits.cxx:21
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:24
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
Definition: Binning.cxx:38
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:30
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 819 of file Spectrum.cxx.

References fHistD, fHistF, fHistSparse, fPOT, pot, and runNovaSAM::ret.

Referenced by BlessedPlotsLoad(), caf_numu_sensitivity(), caf_numu_sensitivity_no_tau(), cc(), compare_pid_cut_sens(), contours(), cpv(), delta_precision(), delta_slices(), demo_CPT(), extrap_syst_fa(), fa_numuContours(), ana::FDPredictionSterile::FakeData(), ana::NDPredictionSterile::FakeData(), futureSig_reach_singlePOTcombo_syst(), ana2019::fakedata::Get2019Prediction(), get_sa_syst_mags(), get_sa_systs_mags_v2(), getContProf_Sensitivity(), GetFakeData(), getSensitivity(), hierarchy(), joint_fit_make_fc_slice(), joint_fit_make_fc_surf(), make_fa_pred(), make_plots(), ana::NumuAnalysis::MakeExperiment(), MakeExtrapSurface(), MakeFakeData(), MakeNusPrediction(), makeSystTable(), makeSystTable_reduced(), MichelDecompTest(), MockData(), NDDataMCSystBandAna(), nue_ana_basic(), numu_demo_split_plot(), numu_sig_nonmax(), octant(), plot_extrap_syst_fa(), plot_fa_results(), plot_sa_results_nodata(), PlotNus17Prediction(), plots(), saTestContours(), saveContours_addExpt(), saveContours_complete(), saveContours_oscpar(), saveContours_simple(), saveContours_systs(), sensitivity(), sensitivity_slices(), starPlot(), syst_test(), template_basic(), template_GENIE_systs(), template_nonGENIE_systs(), test_ana(), test_stanfit_statsonly(), test_stanfit_systpulls(), test_stanfit_withsysts(), th23_delta_contour(), ToTH1(), and ana::UnfoldIterative::Truth().

820  {
821  Spectrum ret = *this;
822  if(fPOT > 0){
823  if(ret.fHistD)
824  ret.fHistD->Scale(pot/fPOT);
825  if(ret.fHistF)
826  ret.fHistF->Scale(pot/fPOT);
827  if(ret.fHistSparse)
828  ret.fHistSparse->Scale(pot/fPOT);
829  }
830  ret.fPOT = pot;
831 
832  // Drop old errors, which are based on the MC statistics, and create new
833  // ones that are based on the prediction for the data
834  if(ret.fHistD){
835  ret.fHistD->Sumw2(false);
836  ret.fHistD->Sumw2();
837  }
838  if(ret.fHistF){
839  ret.fHistF->Sumw2(false);
840  ret.fHistF->Sumw2();
841  }
842 
843  return ret;
844  }
double fPOT
Definition: Spectrum.h:317
#define pot
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
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 847 of file Spectrum.cxx.

References fHistD, fHistF, fHistSparse, fLivetime, fPOT, livetime, pot, and runNovaSAM::ret.

848  {
849  Spectrum ret = *this;
850 
851  if(fPOT > 0){
852  if(ret.fHistD)
853  ret.fHistD->Scale(pot/fPOT);
854  if(ret.fHistF)
855  ret.fHistF->Scale(pot/fPOT);
856  if(ret.fHistSparse)
857  ret.fHistSparse->Scale(pot/fPOT);
858  }
859  ret.fPOT = pot;
860 
861  // overwrite livetime for fake data
862  // PlusEqualsHelper will take over the rest
863  ret.fLivetime = livetime;
864 
865  if(ret.fHistD){
866  ret.fHistD->Sumw2(false);
867  ret.fHistD->Sumw2();
868  }
869  if(ret.fHistF){
870  ret.fHistF->Sumw2(false);
871  ret.fHistF->Sumw2();
872  }
873 
874  return ret;
875  }
double fPOT
Definition: Spectrum.h:317
#define pot
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
void ana::Spectrum::Fill ( double  x,
double  w = 1 
)

Definition at line 774 of file Spectrum.cxx.

References fHistD, fHistF, and fHistSparse.

Referenced by first_ana_proj(), and ana::SpectrumLoader::HandleRecord().

775  {
776  assert( (fHistD || fHistF || fHistSparse) && "Somehow both fHist and fHistSparse are null in Spectrum::Fill" );
777 
778  if(fHistD)
779  fHistD->Fill(x, w);
780  else if(fHistF)
781  fHistF->Fill(x, w);
782  else if(fHistSparse)
783  fHistSparse->Fill(&x, w);
784  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
THnSparseD * fHistSparse
Definition: Spectrum.h:316
Float_t w
Definition: plot.C:20
std::vector<Binning> ana::Spectrum::GetBinnings ( ) const
inline
std::vector<std::string> ana::Spectrum::GetLabels ( ) const
inline
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 742 of file Spectrum.cxx.

References fHistD, fHistF, fLivetime, fPOT, demo3::h, MECModelEnuComparisons::i, ana::kPOT, plotSysts::ratio, and util::sqr().

Referenced by BicountEllipse_dCP(), ana::CountingExperiment::ChiSq(), compare_pid_cut_sens(), ComputeEfficiency(), contours(), ana::DataMCAreaNormalizedRatio(), ana::SpectrumComponents::DrawLegend(), ana::DataMCPair::DrawMCNormSyst(), DataMCPair::DrawMCNormSyst(), Efficiency(), FCContour(), ana::FluxMultiverseSyst::FindSigmaBoundaries(), FitParamEffectsAna(), FitSystEffectsAna(), getHists_FNEX(), GetNueCosmics2017(), GetNueCosmics2018(), GetNueCosmics2019(), GetNueData2017(), GetNueData2018(), GetNueData2019(), GetNuePrediction2017(), GetNuePrediction2018(), GetNuePrediction2019(), GetSpectra(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly1D(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly3D(), Integral(), joint_fit_2017_make_fc_slice(), joint_fit_2017_make_fc_surf(), joint_fit_make_experiments(), joint_fit_make_fc_slice(), joint_fit_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_slice(), make_fc_slices_nersc_2018(), make_fc_slices_nersc_2018_stats(), make_fc_slices_nersc_2019(), make_fc_surf(), make_fc_surfaces_nersc_2018(), make_fc_surfaces_nersc_2018_stats(), make_fc_surfaces_nersc_2019(), make_nominal_xs(), make_xs(), MakeHBar(), MakeTable(), MCCompPredictionTable(), monoprob_plot(), ana::GenieMultiverseNormalizedSpectra::NormalizeSpectra(), PeripheralCuts(), ana::PlotWithAreaSystErrorBand(), predEventCountWithSystError(), PrintCount(), PrintEventCounts(), sensitivity(), sensitivity_slices(), slices(), slices_paper(), SpectrumParamEffectsAna(), ToTH1(), and ana::UnfoldSVD::Truth().

744  {
745  const double ratio = (expotype == kPOT) ? exposure/fPOT : exposure/fLivetime;
746 
747  TH1* h = fHistD ? (TH1*)fHistD : (TH1*)fHistF;
748 
749  if(err){
750  *err = 0;
751 
752  for(int i = 0; i < h->GetNbinsX()+2; ++i){
753  *err += util::sqr(h->GetBinError(i));
754  }
755  *err = sqrt(*err) * ratio;
756  }
757 
758  // TODO how to integrate fHistSparse?
759 
760  return h->Integral(0, -1) * ratio;
761  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
T sqr(T x)
More efficient square function than pow(x,2)
Definition: MathUtil.h:23
if(dump)
double fLivetime
Definition: Spectrum.h:318
h
Definition: demo3.py:41
double ana::Spectrum::Livetime ( ) const
inline

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

Definition at line 266 of file Spectrum.h.

References fLivetime.

Referenced by ana::FitInAnaBinsBkgdEstimator::Background(), ana::NumuCC2p2hBkgdEstimator::Background(), BlessedPlotsLoad(), CalcRWithSystsNus17(), contours(), Cumulative(), ana::TwoSampleDecomp::Decomp(), ana::FakeDecomp::Decompose(), FCContour(), fd_plot(), fd_plot_bless(), ana::FluxMultiverseSyst::FindSigmaBoundaries(), FitParamEffectsAna(), FitSystEffectsAna(), getBNBPlots(), GetFluxError(), getHists_FNEX(), ana::Multiverse::GetNSigmaShift(), GetNueCosmics2017(), GetNueCosmics2018(), GetNueCosmics2019(), GetNueData2017(), GetNueData2018(), GetNueData2019(), ana::PredictionInterp::InitFits(), joint_fit_make_experiments(), joint_fit_make_fc_slice(), joint_fit_make_fc_surf(), make_fc_nus_surfs_nersc_2018(), make_fc_nus_surfs_nersc_2019(), make_fc_points(), make_fc_slice(), make_fc_surf(), make_nus17_fc_surfs(), make_nus_fc_surfs(), make_xs(), make_xs_1D(), MakeExtrapSurface(), MakeHBar(), makeMatrixElementSurface(), MakeNusPrediction(), ana::MichelDecomp::MCToDCMPComp(), ana::PredictionExtendToPeripheral::MergePeripheral(), monoprob_plot(), plot_datamcpred(), PlotNus17Prediction(), PlotNus17PredSystsData(), PlotNus18Sideband(), PlotNusSensAna01(), ana::PlotSpectra(), PlotSysts(), ana::PredictionNumuFAHadE::PredictComponentSyst(), ana::PredictionExtendToPeripheral::ReduceHelperNC(), selection_story_plots(), sensitivity(), sensitivity_slices(), ana::PredictionInterp::ShiftSpectrum(), slices(), slices_paper(), timingPeak(), ana::UnfoldSVD::Truth(), ana::UnfoldTikhonov::Truth(), and ana::PredictionTemplateShift::Weight().

266 {return fLivetime;}
double fLivetime
Definition: Spectrum.h:318
std::unique_ptr< Spectrum > ana::Spectrum::LoadFrom ( TDirectory *  dir)
static

Definition at line 1055 of file Spectrum.cxx.

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

Referenced by bdtstudyplotter(), BlessedPlotsAnaByPeriod(), CalcRWithSysts(), calculateComponentsNumu(), calculateWrongSignNue(), calculateWrongSignNumuQ1(), calculateWrongSignNumuQ2(), calculateWrongSignNumuQ3(), calculateWrongSignNumuQ4(), CalculateXSec(), ana::CompareNDDataOneMC(), ana::CompareNDDataTwoMC(), ana::ComparisonTable(), ana::CovMxManager::CovMxManager(), CutTableAna(), CVNphotonHist(), CVNphotonSplitHist(), demo2p5b(), DoThePlots(), doUnfolding(), EHadVisMECpairs(), FDDataMC(), FDDataMCSystBandAna(), FidOptHist(), FillFlavorContainers(), FitParamEffectsAna(), FitSystEffectsAna(), FOMCalc(), get_data_histogram(), get_numu_data_histogram(), GetCosmics(), Plotter::GetDataPlots(), getHists_FNEX(), GetHistVectors(), Plotter::GetMCPlots(), ana::GetNDComponents(), GetNumuData2017(), GetNumuData2018(), GetNumuData2019(), GetSpectToHist(), ana::InteractionSpectra::InteractionSpectra(), joint_fit_make_experiments(), ana::CountingExperiment::LoadFrom(), jw::TrivialPrediction::LoadFrom(), ana::TrivialPrediction::LoadFrom(), ana::CrossSectionSpectra::LoadFrom(), ana::SingleSampleExperiment::LoadFrom(), ana::Multiverse::LoadFrom(), ana::TrivialCrossSectionAnalysis::LoadFrom(), ana::SpectrumComponents::LoadFrom(), ana::DataMCPair::LoadFrom(), ana::RecoReweight::LoadFrom(), ana::FluxReweight::LoadFrom(), LoadMaps(), make_dataMC(), make_estimate_energy(), make_fc_points(), make_muonid_opt(), make_nominal_xs(), Make_NuMuCC_Inc_XS(), Make_NuMuCC_Inc_XS_v2(), make_vertex_optimiz(), MakeCutFlow(), makeEnergyEstimator(), makeFlatWeight(), MakePlots(), makeResolutionPlots(), MakeSurface(), MakeThePlots(), makeXSecPlots1D(), makeXSecPlots2D(), makeXSecPlots_TemplateFit(), mec_tuning_fitter_2020(), MuonCatcherComp_ProdPlots(), NDDataMC(), NDDataMCSystBandAna(), nue_bg_stat_err_calc(), nue_data_mc_validation(), nue_fd_mc_validation(), numu_data_mc_validation(), OverrideLivetime(), plot_nd_spectra_2018(), plot_paper_nd_datamc(), plot_sa_results(), plot_uncertainty(), plotHist_SpectrumCVNID(), PlotResolution(), Plotsidebandfittest(), Plotting_Data2DataComp(), Plotting_Data2DataComp_SingleCanvas(), Plotting_DataAndPrediction(), Plotting_DataSpectra_MakeTGraph(), ppfx_smooth_weights_make(), ProduceCompPlots(), ReMIdHist(), resolutionplotter(), ana::ResolutionScan::ResolutionScan(), SaveHistogramsFD(), SaveHistogramsND(), ShwZOptHist(), Spec2DToHist(), Spec2DtoHist(), SpecToHist(), SpectrumParamEffectsAna(), twodvtxcontplotter(), Unfold1D(), Unfold3D(), UnfoldXSec(), vertexstudyploter(), xsec_tot_uncert_optimization(), and xsec_uncertainty_per_bin().

1056  {
1057  DontAddDirectory guard;
1058 
1059  TObjString* tag = (TObjString*)dir->Get("type");
1060  assert(tag);
1061  assert(tag->GetString() == "Spectrum");
1062  delete tag;
1063 
1064  TH1D* spectD = 0;
1065  TH1F* spectF = 0;
1066  dir->GetObject("hist", spectD);
1067  dir->GetObject("hist", spectF);
1068  THnSparseD* spectSparse = (THnSparseD*)dir->Get("hist_sparse");
1069  assert(spectD || spectF || spectSparse);
1070  TH1* hPot = (TH1*)dir->Get("pot");
1071  assert(hPot);
1072  TH1* hLivetime = (TH1*)dir->Get("livetime");
1073  assert(hLivetime);
1074 
1075  std::vector<std::string> labels;
1076  std::vector<Binning> bins;
1077  for(int i = 0; ; ++i){
1078  TDirectory* subdir = dir->GetDirectory(TString::Format("bins%d", i));
1079  if(!subdir) break;
1080  bins.push_back(*Binning::LoadFrom(subdir));
1081  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
1082  labels.push_back(label ? label->GetString().Data() : "");
1083  delete subdir;
1084  delete label;
1085  }
1086 
1087  if(bins.empty() && labels.empty()){
1088  // Must be an old file. Make an attempt at backwards compatibility.
1089  if(spectD){
1090  bins.push_back(Binning::FromTAxis(spectD->GetXaxis()));
1091  labels.push_back(spectD->GetXaxis()->GetTitle());
1092  }
1093  else{
1094  bins.push_back(Binning::FromTAxis(spectSparse->GetAxis(0)));
1095  labels.push_back(spectSparse->GetAxis(0)->GetTitle());
1096  }
1097  }
1098 
1099  if(spectSparse){
1100  std::unique_ptr<Spectrum> ret = std::make_unique<Spectrum>((TH1*)0, labels, bins, hPot->GetBinContent(1), hLivetime->GetBinContent(1));
1101  ret->fHistSparse = spectSparse;
1102 
1103  delete spectD;
1104  delete spectF;
1105  delete hPot;
1106  delete hLivetime;
1107  return ret;
1108  }
1109  else{
1110  std::unique_ptr<Spectrum> ret;
1111  if(spectD)
1112  ret = std::make_unique<Spectrum>(std::unique_ptr<TH1D>(spectD), labels, bins, hPot->GetBinContent(1), hLivetime->GetBinContent(1));
1113  else
1114  ret = std::make_unique<Spectrum>(std::unique_ptr<TH1F>(spectF), labels, bins, hPot->GetBinContent(1), hLivetime->GetBinContent(1));
1115  delete spectSparse;
1116  delete hPot;
1117  delete hLivetime;
1118  return ret;
1119  }
1120  }
subdir
Definition: cvnie.py:7
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
const char * label
const Binning bins
Definition: NumuCC_CPiBin.h:8
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
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir)
Definition: Binning.cxx:221
double ana::Spectrum::Mean ( ) const

Return mean of 1D histogram.

Definition at line 764 of file Spectrum.cxx.

References fHistD, fHistF, and demo3::h.

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

765  {
766  // Allow GetMean() to work even if this histogram never had any explicit
767  // Fill() calls made.
768  TH1* h = fHistD ? (TH1*)fHistD : (TH1*)fHistF;
769  if(h->GetEntries() == 0) h->SetEntries(1);
770  return h->GetMean();
771  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
cout<< t1-> GetEntries()
Definition: plottest35.C:29
if(dump)
h
Definition: demo3.py:41
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 787 of file Spectrum.cxx.

References FakeData(), fHistD, fHistF, fHistSparse, demo3::h, MECModelEnuComparisons::i, runNovaSAM::ret, and generate_hists::rnd.

Referenced by demo4(), demo5(), fd_plot(), fill_col(), ana2019::fakedata::Get2019Prediction(), GetMockData(), goodness_of_fit(), joint_fit_2017_make_fc_slice(), joint_fit_2017_make_fc_surf(), joint_fit_make_fc_slice(), joint_fit_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_points(), make_fc_slice(), make_fc_slices_nersc_2018(), make_fc_slices_nersc_2018_stats(), make_fc_slices_nersc_2019(), make_fc_surf(), 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(), selection_story_plots(), syst_plot_test(), test_saloaders(), and ToTH1().

788  {
790 
791  TRandom3 rnd(idx); // zero seeds randomly
792 
793  if(ret.fHistD || ret.fHistF){
794  TH1* h = ret.fHistD ? (TH1*)ret.fHistD : (TH1*)ret.fHistF;
795  for(int i = 0; i < h->GetNbinsX()+2; ++i){
796  h->SetBinContent(i, rnd.Poisson(h->GetBinContent(i)));
797  }
798  }
799  if(ret.fHistSparse){
800  for(int i = 0; i < ret.fHistSparse->GetNbins(); ++i)
801  ret.fHistSparse->SetBinContent(i, rnd.Poisson(ret.fHistSparse->GetBinContent(i)));
802  }
803 
804  // Drop old errors, which are based on the MC statistics, and create new
805  // ones that are based on the prediction for the data
806  if(ret.fHistD){
807  ret.fHistD->Sumw2(false);
808  ret.fHistD->Sumw2();
809  }
810  if(ret.fHistF){
811  ret.fHistF->Sumw2(false);
812  ret.fHistF->Sumw2();
813  }
814 
815  return ret;
816  }
Spectrum FakeData(double pot) const
Fake data is a MC spectrum scaled to the POT expected in the data.
Definition: Spectrum.cxx:819
#define pot
h
Definition: demo3.py:41
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
unsigned int ana::Spectrum::NDimensions ( ) const
inline

Definition at line 297 of file Spectrum.h.

References fLabels.

Referenced by ana::SpectrumComponents::NDimensions().

297 {return fLabels.size();}
std::vector< std::string > fLabels
Definition: Spectrum.h:323
Spectrum ana::Spectrum::operator* ( const Ratio rhs) const

Definition at line 1005 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

1006  {
1007  Spectrum ret = *this;
1008  ret *= rhs;
1009  return ret;
1010  }
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
Spectrum & ana::Spectrum::operator*= ( const Ratio rhs)

Definition at line 997 of file Spectrum.cxx.

References ana::Ratio::fHist, fHistD, fHistF, and demo3::h.

Referenced by OverrideLivetime().

998  {
999  TH1* h = fHistD ? (TH1*)fHistD : (TH1*)fHistF;
1000  h->Multiply(rhs.fHist);
1001  return *this;
1002  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
h
Definition: demo3.py:41
Spectrum ana::Spectrum::operator+ ( const Spectrum rhs) const

Definition at line 975 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

976  {
977  Spectrum ret = *this;
978  ret += rhs;
979  return ret;
980  }
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
Spectrum & ana::Spectrum::operator+= ( const Spectrum rhs)

Definition at line 969 of file Spectrum.cxx.

References PlusEqualsHelper().

Referenced by OverrideLivetime().

970  {
971  return PlusEqualsHelper(rhs, +1);
972  }
Spectrum & PlusEqualsHelper(const Spectrum &rhs, int sign)
Helper for operator+= and operator-=.
Definition: Spectrum.cxx:894
Spectrum ana::Spectrum::operator- ( const Spectrum rhs) const

Definition at line 989 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

990  {
991  Spectrum ret = *this;
992  ret -= rhs;
993  return ret;
994  }
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
Spectrum & ana::Spectrum::operator-= ( const Spectrum rhs)

Definition at line 983 of file Spectrum.cxx.

References PlusEqualsHelper().

Referenced by OverrideLivetime().

984  {
985  return PlusEqualsHelper(rhs, -1);
986  }
Spectrum & PlusEqualsHelper(const Spectrum &rhs, int sign)
Helper for operator+= and operator-=.
Definition: Spectrum.cxx:894
Spectrum ana::Spectrum::operator/ ( const Ratio rhs) const

Definition at line 1021 of file Spectrum.cxx.

References runNovaSAM::ret.

Referenced by OverrideLivetime().

1022  {
1023  Spectrum ret = *this;
1024  ret /= rhs;
1025  return ret;
1026  }
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
Spectrum & ana::Spectrum::operator/= ( const Ratio rhs)

Definition at line 1013 of file Spectrum.cxx.

References ana::Ratio::fHist, fHistD, fHistF, and demo3::h.

Referenced by OverrideLivetime().

1014  {
1015  TH1* h = fHistD ? (TH1*)fHistD : (TH1*)fHistF;
1016  h->Divide(rhs.fHist);
1017  return *this;
1018  }
TH1D * fHistD
Definition: Spectrum.h:314
ratio_hxv Divide(hxv, goal_hxv)
TH1F * fHistF
Definition: Spectrum.h:315
h
Definition: demo3.py:41
Spectrum & ana::Spectrum::operator= ( const Spectrum rhs)

Definition at line 424 of file Spectrum.cxx.

References ana::HistCache::Copy(), ana::HistCache::Delete(), fBins, fHistD, fHistF, fHistSparse, fLabels, fLivetime, fLoaderCount, and fPOT.

425  {
426  if(this == &rhs) return *this;
427 
428  DontAddDirectory guard;
429 
432  delete fHistSparse;
433 
434  assert(rhs.fHistD || rhs.fHistF || rhs.fHistSparse);
435 
436  if(rhs.fHistD){
437  fHistD = HistCache::Copy(rhs.fHistD);
438  fHistF = 0;
439  fHistSparse = 0;
440  }
441 
442  if(rhs.fHistF){
443  fHistF = HistCache::Copy(rhs.fHistF);
444  fHistD = 0;
445  fHistSparse = 0;
446  }
447 
448  if(rhs.fHistSparse){
449  fHistSparse = (THnSparseD*)rhs.fHistSparse->Clone();
450  fHistD = 0;
451  fHistF = 0;
452  }
453 
454  fPOT = rhs.fPOT;
455  fLivetime = rhs.fLivetime;
456  fLabels = rhs.fLabels;
457  fBins = rhs.fBins;
458 
459  assert( fLoaderCount.empty() ); // Copying with pending loads is unexpected
460 
461  return *this;
462  }
TH1D * fHistD
Definition: Spectrum.h:314
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:175
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
Definition: Spectrum.h:321
static void Delete(TH1D *&h)
Definition: HistCache.cxx:215
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
std::vector< Binning > fBins
Definition: Spectrum.h:324
Spectrum & ana::Spectrum::operator= ( Spectrum &&  rhs)

Definition at line 465 of file Spectrum.cxx.

References ana::HistCache::Delete(), fBins, fHistD, fHistF, fHistSparse, fLabels, fLivetime, fLoaderCount, fPOT, and demo0::loader.

466  {
467  if(this == &rhs) return *this;
468 
471  delete fHistSparse;
472 
473  assert(rhs.fHistD || rhs.fHistF || rhs.fHistSparse);
474 
475  fHistD = rhs.fHistD;
476  fHistF = rhs.fHistF;
477  fHistSparse = rhs.fHistSparse;
478 
479  fPOT = rhs.fPOT;
480  fLivetime = rhs.fLivetime;
481  fLabels = rhs.fLabels;
482  fBins = rhs.fBins;
483 
484  rhs.fHistD = 0;
485  rhs.fHistF = 0;
486  rhs.fHistSparse = 0;
487 
488  for (auto & loader : rhs.fLoaderCount)
489  {
490  loader->ReplaceSpectrum(&rhs, this);
491  fLoaderCount.insert(loader);
492  }
493  rhs.fLoaderCount.clear();
494 
495  return *this;
496  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
std::vector< std::string > fLabels
Definition: Spectrum.h:323
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
Definition: Spectrum.h:321
static void Delete(TH1D *&h)
Definition: HistCache.cxx:215
double fLivetime
Definition: Spectrum.h:318
loader
Definition: demo0.py:10
THnSparseD * fHistSparse
Definition: Spectrum.h:316
std::vector< Binning > fBins
Definition: Spectrum.h:324
Spectrum & ana::Spectrum::operator= ( const SpectrumStan rhs)

Definition at line 499 of file Spectrum.cxx.

References Spectrum(), and ~Spectrum().

500  {
501  // use placement new to just overwrite this object using the relevant constructor
502  this->~Spectrum();
503  new (this) Spectrum(rhs);
504  return *this;
505  }
virtual ~Spectrum()
Definition: Spectrum.cxx:322
Spectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Definition: Spectrum.cxx:47
void ana::Spectrum::OverrideLivetime ( double  newlive)
inline

DO NOT USE UNLESS YOU ARE 110% CERTAIN THERE ISN'T A BETTER WAY!

Definition at line 272 of file Spectrum.h.

References plot_validation_datamc::c, Clear(), dir, fLivetime, LoadFrom(), operator*(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator/(), operator/=(), SaveTo(), and Scale().

Referenced by getBNBPlots(), make_fc_nus_surfs_nersc_2019(), make_fc_points(), sensitivity(), sensitivity_slices(), and timingPeak().

272 {fLivetime = newlive;}
double fLivetime
Definition: Spectrum.h:318
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 894 of file Spectrum.cxx.

References ana::AlmostEqual(), om::cout, allTimeWatchdog::endl, fHistD, fHistF, fHistSparse, fLivetime, fPOT, demo3::h, and rh.

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

895  {
896  // In this case it would be OK to have no POT/livetime
897  if(rhs.fHistD && rhs.fHistD->Integral(0, -1) == 0) return *this;
898  if(rhs.fHistF && rhs.fHistF->Integral(0, -1) == 0) return *this;
899 
900  if((!fPOT && !fLivetime) || (!rhs.fPOT && !rhs.fLivetime)){
901  std::cout << "Error: can't sum Spectrum with no POT or livetime."
902  << std::endl;
903  abort();
904  }
905 
906  if(!fLivetime && !rhs.fPOT){
907  std::cout << "Error: can't sum Spectrum with POT ("
908  << fPOT << ") but no livetime and Spectrum with livetime ("
909  << rhs.fLivetime << " sec) but no POT." << std::endl;
910  abort();
911  }
912 
913  if(!fPOT && !rhs.fLivetime){
914  std::cout << "Error: can't sum Spectrum with livetime ("
915  << fLivetime << " sec) but no POT and Spectrum with POT ("
916  << rhs.fPOT << ") but no livetime." << std::endl;
917  abort();
918  }
919 
920  // And now there are still a bunch of good cases to consider
921 
922  if(fPOT && rhs.fPOT){
923  // Scale by POT when possible
924  TH1* h = fHistD ? (TH1*)fHistD : (TH1*)fHistF;
925  TH1* rh = rhs.fHistD ? (TH1*)rhs.fHistD : (TH1*)rhs.fHistF;
926  if(rh) h->Add(rh, sign*fPOT/rhs.fPOT);
927  if(rhs.fHistSparse) fHistSparse->Add(rhs.fHistSparse, sign*fPOT/rhs.fPOT);
928 
929  if(fLivetime && rhs.fLivetime){
930  // If POT/livetime ratios match, keep regular lifetime, otherwise zero
931  // it out.
932  if(AlmostEqual(fLivetime*rhs.fPOT, rhs.fLivetime*fPOT))
933  fLivetime = 0;
934  }
935  if(!fLivetime && rhs.fLivetime){
936  // If the RHS has a livetime and we don't, copy it in (suitably scaled)
937  fLivetime = rhs.fLivetime * fPOT/rhs.fPOT;
938  }
939  // Otherwise, keep our own livetime (if any)
940 
941  return *this;
942  }
943 
944  if(fLivetime && rhs.fLivetime){
945  // Scale by livetime, the only thing in common
946  TH1* h = fHistD ? (TH1*)fHistD : (TH1*)fHistF;
947  TH1* rh = rhs.fHistD ? (TH1*)rhs.fHistD : (TH1*)rhs.fHistF;
948  if(rh) h->Add(rh, sign*fLivetime/rhs.fLivetime);
949  if(rhs.fHistSparse) fHistSparse->Add(rhs.fHistSparse, sign*fLivetime/rhs.fLivetime);
950 
951  if(!fPOT && rhs.fPOT){
952  // If the RHS has a POT and we don't, copy it in (suitably scaled)
953  fPOT = rhs.fPOT * fLivetime/rhs.fLivetime;
954  }
955  // Otherwise, keep our own POT (if any)
956 
957  return *this;
958  }
959 
960  // That should have been all the cases. I definitely want to know what
961  // happened if it wasn't.
962  std::cout << "Spectrum::operator+=(). How did we get here? "
963  << fPOT << " " << fLivetime << " "
964  << rhs.fPOT << " " << rhs.fLivetime << std::endl;
965  abort();
966  }
TH1D * fHistD
Definition: Spectrum.h:314
TH2 * rh
Definition: drawXsec.C:5
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
if(dump)
double fLivetime
Definition: Spectrum.h:318
bool AlmostEqual(double a, double b)
Definition: Utilities.cxx:732
THnSparseD * fHistSparse
Definition: Spectrum.h:316
def sign(x)
Definition: canMan.py:204
OStream cout
Definition: OStream.cxx:6
h
Definition: demo3.py:41
double ana::Spectrum::POT ( ) const
inline

Definition at line 263 of file Spectrum.h.

References fPOT.

Referenced by ana::nueccinc::NueCCIncCrossSectionAnalysis::AddEnhancedSample(), ana::DataMCPair::AddExposure(), ana::SpectrumLoaderMockData::AddSpectrum(), alternate_cosrej_table(), caf_numu_fd_validation_data(), CalcChi2(), CalcR(), CalcRWithSystsNus17(), calculate_avg_nslcs(), calculateComponentsNumu(), calculateWrongSignNue(), calculateWrongSignNumuQ1(), calculateWrongSignNumuQ2(), calculateWrongSignNumuQ3(), calculateWrongSignNumuQ4(), ana::CountingExperiment::ChiSq(), ana::SingleSampleExperiment::ChiSq(), ana::CovMxExperiment::ChiSq(), compare_pid_cut_sens(), CompareDecompDataMC(), ComputeEfficiency(), Cumulative(), ana::DataMCAreaNormalizedRatio(), ana::DataMCComparison(), Plotter::DataMCComparison(), ana::DataMCComparisonAreaNormalized(), ana::DataMCComparisonComponents(), ana::TwoSampleDecomp::Decomp(), ana::FakeDecomp::Decompose(), demo6(), ana::SingleSampleExperiment::Derivative(), draw_decomp_plots(), ana::DataMCPair::DrawData(), ana::SpectrumComponents::DrawLegend(), ana::DataMCPair::DrawMCComponents(), ana::DataMCPair::DrawMCNormSyst(), DataMCPair::DrawMCNormSyst(), ana::DataMCPair::DrawMCSyst(), drawPlot(), ana::TwoSampleDecomp::DrawSigBkgOverlay(), ana::TwoSampleDecomp::DrawTwoSamplesWithRatios(), EHadVisMECpairs(), fa_nd_mc_prediction_full_syst(), FCContour(), fd_plot(), fd_plot_bless(), fill_col(), ana::FluxMultiverseSyst::FindSigmaBoundaries(), FitParamEffectsAna(), ana::PredictionInterp::FitSumComponent(), FitSystEffectsAna(), GetExtrap(), getHists_FNEX(), ana::Multiverse::GetNSigmaShift(), GetNueData2017(), GetNueData2018(), GetNueData2019(), GetSpectra(), ana::MichelDecomp::GetSum(), ana::MichelDecomp::GetTemplateContent(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly1D(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly3D(), ana::PredictionNueRebinSA::Inflate(), ana::PredictionInterp::InitFits(), joint_fit_make_fc_slice(), joint_fit_make_fc_surf(), ana::BinnedLkhdExperiment::LogLikelihood(), Make2DPlot(), make_fc_points(), make_fc_slice(), make_fc_surf(), make_muonid_opt(), make_nus17_fc_surfs(), make_nus_fc_surfs(), make_plots(), make_quantiles_histogram_2020(), make_vertex_optimiz(), make_xs(), make_xs_1D(), makeEnergyEstimator(), makeFlatWeight(), MakeHBar(), makeMatrixElementSurface(), MakePlot(), MakePlots(), ana::MakeQuantileHistogram(), ana::FluxDecomp::MakeWeightsNumuFromKaon(), ana::BENDecomp::MakeWeightsNumuFromKaon(), ana::FluxDecomp::MakeWeightsNumuFromPion(), ana::BENDecomp::MakeWeightsNumuFromPion(), ana::MichelDecomp::MCToDCMPComp(), mec_tuning_fitter_2020(), ana::PredictionExtendToPeripheral::MergePeripheral(), MichelDecompTest(), mre_blessed(), mre_comp_split(), mre_example(), nd_plot_bless(), ana::GenieMultiverseNormalizedSpectra::NormalizeSpectra(), nue_bg_stat_err_calc(), nue_cosrej_study(), ana::FluxDecomp::NueEstimate(), ana::BENDecomp::NueEstimate(), ana::FluxDecomp::NueEstimateFromKa(), ana::BENDecomp::NueEstimateFromKa(), ana::FluxDecomp::NueEstimateFromPi(), ana::BENDecomp::NueEstimateFromPi(), plot(), plot_2d(), plot_2d_vars(), plot_3NDvsFD(), plot_3NDvsFD_FHC(), plot_3NDvsFD_RHC(), plot_datamc_ND_numu(), plot_datamc_ND_numu_REW(), plot_datamcpred(), plot_diff(), plot_fa_results(), plot_nd_data_mc(), plot_ND_numu_NOMvsREW(), plot_NDvsFD_REW(), plot_NDvsFD_weights(), plot_NDvsFD_weights_FHC(), plot_NDvsFD_weights_RHC(), 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(), 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::PredictionNumuFAHadE::PredictComponentSyst(), PrintEventCounts(), ana::TwoSampleDecomp::RatioCalc(), reco_minus_true_panels(), ana::PredictionNueRebinSA::Reduce(), 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(), sensitivity(), ana::PredictionInterp::ShiftSpectrum(), ana::SimpleFOM(), SpectrumParamEffectsAna(), ana::SpectrumStan::SpectrumStan(), TableNueNDComponents(), TableNueNDDataMC(), test_beam_errorband(), test_micheldecomp(), test_sam(), test_sam_project(), test_stanfit_systpulls(), ana::Multiverse::ToHist(), ana::ICrossSectionAnalysis::ToHist(), ana::UnfoldIterative::Truth(), ana::UnfoldSVD::Truth(), ana::UnfoldTikhonov::Truth(), and ana::PredictionTemplateShift::Weight().

263 {return fPOT;}
double fPOT
Definition: Spectrum.h:317
void ana::Spectrum::RemoveLoader ( SpectrumLoaderBase p)
protected

Definition at line 886 of file Spectrum.cxx.

References fLoaderCount.

Referenced by GetBinnings().

887  { fLoaderCount.erase(p); }
const char * p
Definition: xmltok.h:285
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
Definition: Spectrum.h:321
void ana::Spectrum::SaveTo ( TDirectory *  dir) const

Definition at line 1029 of file Spectrum.cxx.

References fBins, fHistD, fHistF, fHistSparse, fLabels, fLivetime, genie::utils::style::Format(), fPOT, MECModelEnuComparisons::i, and tmp.

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(), ana::CovMxManager::CovMxManager(), CutTableLoad(), CVNphoton(), CVNphotonSplit(), datamc_ND_numu_kinematics(), datamc_ND_numu_kinematics_FHC(), datamc_ND_numu_kinematics_FHC_REW(), datamc_ND_numu_kinematics_REW(), datamc_ND_numu_kinematics_RHC(), datamc_ND_numu_kinematics_RHC_REW(), dataprocess_numuccinc(), estimate_energy(), fd_data_mc(), FDDataMCSystBandLoad(), FidOpt(), FidWShwCuts(), FillSpectra(), FitSystEffectsLoad(), get_cosmic_spectra(), get_data_and_cosmic(), get_data_histogram(), getData(), getFlatWeightSpectra(), GetNDDataMC(), getSpectra_ForFitting(), make_fd_data_spec(), make_mockdata_syst_contours(), make_nue_fd_datamc(), make_nue_firstana_exposure(), make_pi0_xcheck(), make_pid(), MakeCosmics(), MakeFakeData(), makeFakeDataFluxes(), MakeNus17Prediction(), MakeNus18SidebandPred(), MakeNusPrediction(), makeRealDataFluxes(), makeXSecPlots_TemplateFit(), mre_blessed(), mre_comp_split(), mre_sel_efficiency(), ncpi0HistoGrid2(), nd_data_mc(), NDDataMCSystBandLoad(), nue_bg_stat_errs_load(), 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(), plot_fa_results(), ReMId(), resolutionscript(), resolutionstudy(), sa_box_opening_macro(), sa_fd_cut_tables(), sa_hesideband_box_opening_macro(), saveFDMCHists(), saveSpectraForUnf(), ana::xsec::UnfoldingVariable::SaveSpectrums(), ana::PredictionXSecTuning::SaveTo(), ana::CountingExperiment::SaveTo(), ana::PredictionNoOsc::SaveTo(), ana::PredictionNueRebinSA::SaveTo(), ana::CheatDecomp::SaveTo(), jw::TrivialPrediction::SaveTo(), ana::FitInAnaBinsBkgdEstimator::SaveTo(), ana::NumuCC2p2hBkgdEstimator::SaveTo(), ana::nueccinc::NueCCIncMRECorrection::SaveTo(), ana::NCDecomp::SaveTo(), ana::NueDecomp::SaveTo(), ana::TrivialPrediction::SaveTo(), ana::NumuDecomp::SaveTo(), ana::CrossSectionSpectra::SaveTo(), ana::SingleSampleExperiment::SaveTo(), ana::PredictionScaleComp::SaveTo(), ana::ProportionalDecomp::SaveTo(), ana::TrivialCrossSectionAnalysis::SaveTo(), ana::TrivialExtrap::SaveTo(), ana::FakeDecomp::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(), ana::FluxReweight::SaveTo(), ShwZOpt(), sidebandfittest(), test_beam_errorband(), test_fluxhadr_prod_weights_Flux(), test_genieweights(), test_predictionscalecomp(), twodstudyvtxcont(), validationscript(), and vertexstudy().

1030  {
1031  TDirectory* tmp = gDirectory;
1032  dir->cd();
1033 
1034  TObjString("Spectrum").Write("type");
1035 
1036  if(fHistD) fHistD->Write("hist");
1037  if(fHistF) fHistF->Write("hist");
1038  if(fHistSparse) fHistSparse->Write("hist_sparse");
1039  TH1D hPot("", "", 1, 0, 1);
1040  hPot.Fill(.5, fPOT);
1041  hPot.Write("pot");
1042  TH1D hLivetime("", "", 1, 0, 1);
1043  hLivetime.Fill(.5, fLivetime);
1044  hLivetime.Write("livetime");
1045 
1046  for(unsigned int i = 0; i < fBins.size(); ++i){
1047  TObjString(fLabels[i].c_str()).Write(TString::Format("label%d", i).Data());
1048  fBins[i].SaveTo(dir->mkdir(TString::Format("bins%d", i)));
1049  }
1050 
1051  tmp->cd();
1052  }
TH1D * fHistD
Definition: Spectrum.h:314
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
Float_t tmp
Definition: plot.C:36
std::vector< std::string > fLabels
Definition: Spectrum.h:323
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
TDirectory * dir
Definition: macro.C:5
std::vector< Binning > fBins
Definition: Spectrum.h:324
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
void ana::Spectrum::Scale ( double  c)
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 553 of file Spectrum.cxx.

References ana::HistCache::Copy(), om::cout, allTimeWatchdog::endl, fBins, fHistD, fHistF, fHistSparse, fLabels, fLivetime, fPOT, MECModelEnuComparisons::i, ana::kBinDensity, ana::kLivetime, ana::kPOT, submit_hadd::l, label, livetime, ana::HistCache::New(), pot, and runNovaSAM::ret.

Referenced by ana::nueccinc::NueCCIncCrossSectionAnalysis::AddEnhancedSample(), ana::AddErrorInQuadrature(), ana::PredictionSystJoint2018::AddNormSyst(), ana::PredictionSystJointDemo::AddNormSyst(), ana::PredictionSystNueSecondAna::AddNormSysts(), ana::PredictionSystNue2017::AddNormSysts(), ana::PredictionSystNumu2017::AddNormSysts(), alternate_cosrej_table(), AnalyzeNus18Pred(), ana::FitInAnaBinsBkgdEstimator::Background(), ana::NumuCC2p2hBkgdEstimator::Background(), bin_composition_pie_chart(), 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(), calculate_avg_nslcs(), calculateComponentsNumu(), calculateWrongSignNue(), calculateWrongSignNumuQ1(), calculateWrongSignNumuQ2(), calculateWrongSignNumuQ3(), calculateWrongSignNumuQ4(), cc(), check_predinterp(), check_predinterp_numu(), ana::OscCovMxExperiment::ChiSq(), ana::SingleSampleExperiment::ChiSq(), ana::CovMxExperiment::ChiSq(), Compare(), compare_pid_cut_sens(), CompareDecompDataMC(), CompareMCCompPrediction(), ComparePredictions(), ana::ComparePredictions(), ana::ModularExtrapComponent::ComparisonPlot(), ana::ComparisonTable(), ana::PredictionInterp::ComponentDerivative(), Cumulative(), CVNCuts(), ana::DataMCComparison(), Plotter::DataMCComparison(), ana::DataMCComparisonAreaNormalized(), ana::DataMCComparisonComponents(), ana::TwoSampleDecomp::Decomp(), ana::FakeDecomp::Decompose(), ana::MichelDecomp::Decompose(), demo1(), demo3(), demo5(), demo6(), demo_flat(), demo_nueNumuSysts(), ana::PredictionAddRock::Derivative(), ana::SingleSampleExperiment::Derivative(), ana::DataMCPair::DrawData(), drawPlot(), ana::TwoSampleDecomp::DrawSigBkgOverlay(), DrawSurface(), drawSystsShiftingNDdata(), drawSystsShiftingNDdata_updatedAna(), ana::TwoSampleDecomp::DrawTwoSamplesWithRatios(), efficiency(), efficiencySA(), EHadVisMECpairs(), fa_fd_data_mc_systs(), fa_nd_mc_prediction_full_syst(), FCContour(), fd_plot(), fd_plot_bless(), fill_col(), ana::FluxMultiverseSyst::FindSigmaBoundaries(), first_ana_proj(), FitParamEffectsAna(), ana::PredictionInterp::FitSumComponent(), FitSystEffectsAna(), ana::ModularExtrapComponent::FormSmartRatio(), GetBackgroundStatisticalUncertainty(), GetBackgroundSystematicUncertainty(), 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::Multiverse::GetNSigmaShift(), GetNueCosmics2017(), GetNueCosmics2018(), GetNueCosmics2019(), ana::nueccinc::NueCCIncMRECorrection::getPreselected1D(), GetQuantilePredictionHist(), ana::nueccinc::NueCCIncMRECorrection::getSelected1D(), GetSelectedStatisticalUncertainty(), GetSig(), GetSpectra(), ana::GetSpectrum(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly1D(), ana::nueccinc::NueCCIncCrossSectionAnalysis::getTemplateShapeOnly3D(), getTimePeakPlots(), ana::PredictionNueRebinSA::Inflate(), Integral(), joint_fit_make_fc_slice(), joint_fit_make_fc_surf(), ana::BinnedLkhdExperiment::LogLikelihood(), make_extrap_figure(), make_fc_nus_surfs_nersc_2018(), make_fc_points(), make_fc_slice(), make_fc_surf(), 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(), MakeTable(), ana::FluxDecomp::MakeWeightsNumuFromKaon(), ana::BENDecomp::MakeWeightsNumuFromKaon(), makeXSecPlots1D(), makeXSecPlots2D(), ana::MichelDecomp::MCToDCMPComp(), ana::PredictionExtendToPeripheral::MergePeripheral(), MichelDecompTest(), mre_blessed(), mre_comp_split(), myPlotWithSystErrorBand(), nd_plot_bless(), NDHists(), nhits(), nue_ana_basic(), nue_bg_stat_err_calc(), nue_cosrej_study(), nue_pid_effs(), nue_pid_effs_miniprod(), nue_pid_effs_paper_numu_neweff(), ana::FluxDecomp::NueEstimate(), ana::BENDecomp::NueEstimate(), ana::BENDecomp::NueEstimateFromKa(), numu_cut_flow(), numu_demo_split_plot(), 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_fa_results(), plot_fd_datamc(), 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_pi0_xcheck(), plot_pid(), plot_sa_results(), plot_time(), ana::PlotAllSelectionDecomposition(), ana::PlotAllSignalEstimates(), ana::CrossSectionAnalysis::PlotBackgroundEstimate(), ana::NumuCCIncAnalysis::PlotBackgroundEstimate(), PlotComp(), ana::CrossSectionAnalysis::PlotData(), ana::NumuCCIncAnalysis::PlotData(), 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(), ana::CrossSectionAnalysis::PlotUnfoldedSignal(), ana::PlotWithSystErrorBand(), ana::PlotWithSystErrorBand_Quant(), ana::PlotWithSystErrorBandTwoPreds(), ana::SingleSampleExperiment::PredHistIncCosmics(), ana::PredictionCombinePeriods::PredictComponentSyst(), ana::PredictionNumuFAHadE::PredictComponentSyst(), PredictCosmic(), printline(), ana::SpectrumComponents::Purity(), ana::Ratio::Ratio(), ratio(), ana::TwoSampleDecomp::RatioCalc(), reco_minus_true_panels(), ana::PredictionNueRebinSA::Reduce(), ana::PredictionExtendToPeripheral::ReduceHelperNC(), resolution2018(), ana::CrossSectionAnalysis::Result(), ana::NumuCCIncAnalysis::Result(), ana::NumuCC2p2hAnalysis::Result1DFluxInt(), ana::SingleNucAnalysis::Result2D(), ana::NumuCC2p2hAnalysis::Result2D(), ana::NumuCCIncAnalysis::Result2D(), ana::NumuCCIncAnalysis::ReturnHists(), rhc_sensitivity(), ana::MichelDecomp::SaveCompPlots(), SaveDCMPPlots(), SaveOscPrediction(), ana::FluxDecomp::SavePlots(), ana::BENDecomp::SavePlots(), ana::TruthReweight::SavePlots(), ana::RecoReweight::SavePlots(), ana::FluxReweight::SavePlots(), ana::FluxDecomp::SavePlotsKa(), ana::BENDecomp::SavePlotsKa(), ana::BENDecomp::SavePlotsPi(), saveS(), selection_story_plots(), ana::PredictionInterp::ShiftSpectrum(), ana::SimpleFOM(), SpectrumParamEffectsAna(), ana::SpectrumStan::SpectrumStan(), spects(), sterile_demo(), syst_plot_test(), 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::ICrossSectionAnalysis::ToHist(), ana::FluxMultiverseSyst::ToTH1(), ana::GenieMultiverseSpectra::ToTH1(), ToTH1(), ana::ToTH2(), ana::ToTH3(), Toy_analyses(), ana::UnfoldSVD::Truth(), ana::UnfoldTikhonov::Truth(), Unfold1D(), Unfold3D(), UnfoldInOut(), and ana::PredictionTemplateShift::Weight().

556  {
557  // Could have a file temporarily open
558  DontAddDirectory guard;
559 
560  TH1D* ret = 0;
561  if(fHistD){
562  ret = HistCache::Copy(fHistD);
563  }
564  else if(fHistF){
565  ret = HistCache::New(fHistF->GetTitle(), fHistF->GetXaxis());
566  ret->Add(fHistF);
567  }
568  else{
569  ret = fHistSparse->Projection(0);
570  }
571 
572  if(expotype == kPOT){
573  const double pot = exposure;
574  if(fPOT){
575  ret->Scale(pot/fPOT);
576  }
577  else{
578  // Allow zero POT if there are also zero events
579  if(ret->Integral() > 0){
580  std::cout << "Error: Spectrum with " << ret->Integral()
581  << " entries has zero POT, no way to scale to "
582  << exposure << " POT.";
583  if(fLivetime > 0){
584  std::cout << " Spectrum has " << fLivetime << " seconds livetime. "
585  << "Did you mean to pass kLivetime to ToTH1()?";
586  }
587  std::cout << std::endl;
588  abort();
589  }
590  }
591  }
592  if(expotype == kLivetime){
593  const double livetime = exposure;
594  if(fLivetime){
595  ret->Scale(livetime/fLivetime);
596  }
597  else{
598  // Allow zero exposure if there are also zero events
599  if(ret->Integral() > 0){
600  std::cout << "Error: Spectrum with " << ret->Integral()
601  << " entries has zero livetime, no way to scale to "
602  << livetime << " seconds.";
603  if(fPOT > 0){
604  std::cout << " Spectrum has " << fPOT << " POT. "
605  << "Did you mean to pass kPOT to ToTH1()?";
606  }
607  std::cout << std::endl;
608  abort();
609  }
610  }
611  }
612 
614  for(const std::string& l: fLabels) label += l + " and ";
615  label.resize(label.size()-5); // drop the last "and"
616  ret->GetXaxis()->SetTitle(label.c_str());
617 
618  if(fBins.size() == 1){
619  for(unsigned int i = 0; i < fBins[0].Labels().size(); ++i){
620  ret->GetXaxis()->SetBinLabel(i+1, fBins[0].Labels()[i].c_str());
621  }
622  }
623 
624  ret->GetYaxis()->SetTitle("Events");
625 
626 
627  ret->SetLineColor(col);
628  ret->SetMarkerColor(col);
629  ret->SetLineStyle(style);
630 
631  if(bintype == kBinDensity) ret->Scale(1, "width");
632 
633  // Allow GetMean() and friends to work even if this histogram never had any
634  // explicit Fill() calls made.
635  if(ret->GetEntries() == 0) ret->SetEntries(1);
636 
637  return ret;
638  }
TH1D * fHistD
Definition: Spectrum.h:314
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:175
Divide bin contents by bin widths.
Definition: Utilities.h:49
TH1F * fHistF
Definition: Spectrum.h:315
double fPOT
Definition: Spectrum.h:317
const char * label
std::vector< std::string > fLabels
Definition: Spectrum.h:323
Int_t col[ntarg]
Definition: Style.C:29
#define pot
double fLivetime
Definition: Spectrum.h:318
THnSparseD * fHistSparse
Definition: Spectrum.h:316
OStream cout
Definition: OStream.cxx:6
::xsd::cxx::tree::string< char, simple_type > string
Definition: Database.h:154
std::vector< Binning > fBins
Definition: Spectrum.h:324
static TH1D * New(const std::string &title, const Binning &bins)
Definition: HistCache.cxx:24
TH1D* ana::Spectrum::ToTH1 ( double  exposure,
EExposureType  expotype,
EBinType  bintype = kBinContent 
) const
inline

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

References FakeData(), compare_h5_caf::idx, Integral(), ana::kBinContent, ana::kPOT, Mean(), MockData(), ToTH1(), ToTH2(), ToTH2NormX(), and ToTH3().

224  {
225  return ToTH1(exposure, kBlack, kSolid, expotype, bintype);
226  }
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:553
TH2 * ana::Spectrum::ToTH2 ( double  exposure,
EExposureType  expotype = kPOT,
EBinType  bintype = kBinContent 
) const

Spectrum must be 2D to obtain TH2.

Definition at line 641 of file Spectrum.cxx.

References visualisationForPaperMasterPlot::ax, om::cout, allTimeWatchdog::endl, fBins, fLabels, MECModelEnuComparisons::i, ana::kBinDensity, 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(), mre_example(), 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(), saveS1(), ana::Multiverse::ToHist(), ana::ICrossSectionAnalysis::ToHist(), ToTH1(), ana::GenieMultiverseSpectra::ToTH2(), and ToTH2NormX().

642  {
643  if(fBins.size() != 2){
644  std::cout << "Error: This Spectrum does not appear to be 2D." << std::endl;
645  abort();
646  }
647 
648  TH2* ret = ana::ToTH2(*this, exposure, expotype, fBins[0], fBins[1]);
649 
650  for(int iax = 0; iax < 2; ++iax){
651  TAxis* ax = ret->GetXaxis();
652  if(iax == 1) ax = ret->GetYaxis();
653 
654  ax->SetTitle(fLabels[iax].c_str());
655 
656  for(unsigned int i = 0; i < fBins[iax].Labels().size(); ++i){
657  ax->SetBinLabel(i+1, fBins[iax].Labels()[i].c_str());
658  }
659  }
660 
661  if(bintype == kBinDensity) ret->Scale(1, "width");
662 
663  // Allow GetMean() and friends to work even if this histogram never had any
664  // explicit Fill() calls made.
665  if(ret->GetEntries() == 0) ret->SetEntries(1);
666 
667  return ret;
668  }
Divide bin contents by bin widths.
Definition: Utilities.h:49
std::vector< std::string > fLabels
Definition: Spectrum.h:323
TH2 * ToTH2(const Spectrum &s, double exposure, ana::EExposureType expotype, const Binning &binsx, const Binning &binsy, ana::EBinType bintype)
Definition: Utilities.cxx:374
OStream cout
Definition: OStream.cxx:6
std::vector< Binning > fBins
Definition: Spectrum.h:324
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 671 of file Spectrum.cxx.

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

Referenced by ToTH1().

672  {
673  TH2* xyhist = ToTH2(exposure, expotype);
674  if(!xyhist) return nullptr;
675 
676  const int nbinsx = fBins[0].NBins();
677  const int nbinsy = fBins[1].NBins();
678 
679  // Normalize 2D histogram to X-axis spectrum
680  for(int i=1; i<=nbinsx; ++i){
681  double norm = 0.0;
682  for(int j=1; j<=nbinsy; ++j){
683  norm += xyhist->GetBinContent(i, j);
684  }
685  /// If no entries in the column, skip normalization
686  if(norm < 0.0000001) continue;
687 
688  norm = 1.0 / norm;
689  for(int j=1; j<=nbinsy; ++j){
690  xyhist->SetBinContent(i,j, xyhist->GetBinContent(i, j) * norm);
691  }
692  }
693 
694  // Allow GetMean() and friends to work even if this histogram never had any
695  // explicit Fill() calls made.
696  if(xyhist->GetEntries() == 0) xyhist->SetEntries(1);
697 
698  return xyhist;
699  }
TH2 * ToTH2(double exposure, EExposureType expotype=kPOT, EBinType bintype=kBinContent) const
Spectrum must be 2D to obtain TH2.
Definition: Spectrum.cxx:641
const double j
Definition: BetheBloch.cxx:29
Float_t norm
Int_t nbinsx
Definition: plot.C:23
std::vector< Binning > fBins
Definition: Spectrum.h:324
TH3 * ana::Spectrum::ToTH3 ( double  exposure,
EExposureType  expotype = kPOT,
EBinType  bintype = kBinContent 
) const

Spectrum must be 3D to obtain TH3.

Definition at line 702 of file Spectrum.cxx.

References visualisationForPaperMasterPlot::ax, om::cout, allTimeWatchdog::endl, fBins, fLabels, MECModelEnuComparisons::i, ana::kBinDensity, runNovaSAM::ret, and ana::ToTH3().

Referenced by ana::FluxDecomp::MakeWeightsNumuFromPion(), ana::BENDecomp::MakeWeightsNumuFromPion(), ana::FluxDecomp::NueEstimateFromPi(), ana::BENDecomp::NueEstimateFromPi(), ana::FluxDecomp::SavePlotsPi(), ana::BENDecomp::SavePlotsPi(), ana::Multiverse::ToHist(), ana::ICrossSectionAnalysis::ToHist(), and ToTH1().

703  {
704  if(fBins.size() != 3){
705  std::cout << "Error: This Spectrum does not appear to be 3D." << std::endl;
706  abort();
707  }
708 
709  TH3* ret = ana::ToTH3(*this, exposure, expotype,
710  fBins[0], fBins[1], fBins[2]);
711 
712  for(int iax = 0; iax < 3; ++iax){
713  TAxis* ax = ret->GetXaxis();
714  if(iax == 1) ax = ret->GetYaxis();
715  if(iax == 2) ax = ret->GetZaxis();
716 
717  ax->SetTitle(fLabels[iax].c_str());
718 
719  for(unsigned int i = 0; i < fBins[iax].Labels().size(); ++i){
720  ax->SetBinLabel(i+1, fBins[iax].Labels()[i].c_str());
721  }
722  }
723 
724  if(bintype == kBinDensity) ret->Scale(1, "width");
725 
726  // Allow GetMean() and friends to work even if this histogram never had any
727  // explicit Fill() calls made.
728  if(ret->GetEntries() == 0) ret->SetEntries(1);
729 
730  return ret;
731  }
Divide bin contents by bin widths.
Definition: Utilities.h:49
std::vector< std::string > fLabels
Definition: Spectrum.h:323
OStream cout
Definition: OStream.cxx:6
std::vector< Binning > fBins
Definition: Spectrum.h:324
TH3 * ToTH3(const Spectrum &s, double exposure, ana::EExposureType expotype, const Binning &binsx, const Binning &binsy, const Binning &binsz, ana::EBinType bintype)
Definition: Utilities.cxx:424

Friends And Related Function Documentation

friend class NullLoader
friend

Definition at line 43 of file Spectrum.h.

friend class SpectrumLoader
friend

Definition at line 42 of file Spectrum.h.

friend class SpectrumLoaderBase
friend

Definition at line 41 of file Spectrum.h.

friend class SpectrumStan
friend

Definition at line 40 of file Spectrum.h.

Member Data Documentation

std::vector<Binning> ana::Spectrum::fBins
protected
TH1D* ana::Spectrum::fHistD
protected
TH1F* ana::Spectrum::fHistF
protected
THnSparseD* ana::Spectrum::fHistSparse
protected
std::vector<std::string> ana::Spectrum::fLabels
protected

Definition at line 323 of file Spectrum.h.

Referenced by GetLabels(), NDimensions(), operator=(), SaveTo(), ToTH1(), ToTH2(), and ToTH3().

double ana::Spectrum::fLivetime
protected
std::set<SpectrumLoaderBase*> ana::Spectrum::fLoaderCount
protected

This count is maintained by SpectrumLoader, as a sanity check.

Definition at line 321 of file Spectrum.h.

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

double ana::Spectrum::fPOT
protected

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