Public Member Functions | Private Member Functions | Private Attributes | List of all members
ana::SpectrumStan Class Reference

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-02-16/CAFAna/Core/SpectrumStan.h"

Public Member Functions

 SpectrumStan (const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
 SpectrumStan (std::vector< stan::math::var > &&binContents, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
 SpectrumStan (double *binContents, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
 SpectrumStan (const SpectrumStan &rhs)
 
 SpectrumStan (SpectrumStan &&rhs)
 
 SpectrumStan (const Spectrum &rhs)
 Copy conversion from the normal kind of spectrum. More...
 
SpectrumStanoperator= (const SpectrumStan &rhs)
 
SpectrumStanoperator= (SpectrumStan &&rhs)
 
void Clear ()
 
const std::vector< Binning > & GetBinnings () const
 
const std::vector< std::string > & GetLabels () const
 
double Livetime () const
 
double POT () const
 
std::vector< stan::math::varToBins (double pot) const
 
SpectrumStanoperator+= (const SpectrumStan &rhs)
 
SpectrumStan operator+ (const SpectrumStan &rhs) const
 
SpectrumStanoperator-= (const SpectrumStan &rhs)
 
SpectrumStan operator- (const SpectrumStan &rhs) const
 
SpectrumStanoperator= (const Spectrum &rhs)
 Assignment conversion from the normal kind of spectrum. More...
 

Private Member Functions

SpectrumStanPlusEqualsHelper (const SpectrumStan &rhs, int sign)
 Helper for operator+= and operator-=. More...
 

Private Attributes

std::vector< stan::math::varfBinContents
 Contents of the bins. More...
 
double fPOT
 
double fLivetime
 
std::vector< std::string > fLabels
 
std::vector< BinningfBins
 

Detailed Description

Definition at line 13 of file SpectrumStan.h.

Constructor & Destructor Documentation

ana::SpectrumStan::SpectrumStan ( const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
double  pot,
double  livetime 
)

Definition at line 13 of file SpectrumStan.cxx.

References Clear().

Referenced by operator=().

17  {
18  this->Clear();
19  }
std::vector< std::string > fLabels
Definition: SpectrumStan.h:72
std::vector< Binning > fBins
Definition: SpectrumStan.h:73
#define pot
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67
const Binning bins
Definition: NumuCC_CPiBin.h:8
ana::SpectrumStan::SpectrumStan ( std::vector< stan::math::var > &&  binContents,
const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
double  pot,
double  livetime 
)

Definition at line 22 of file SpectrumStan.cxx.

References fBinContents, fBins, and fLabels.

28  {
29  // only support 1D for now
30  assert (fBins.size() <= 1 && fBins.size() == fLabels.size());
31  assert(int(binContents.size()) == fBins[0].NBins()+2);
32 
33  fBinContents.reserve(binContents.size());
34  for (auto & binPtr : binContents)
35  fBinContents.emplace_back(std::move(binPtr));
36  binContents.clear();
37  }
std::vector< std::string > fLabels
Definition: SpectrumStan.h:72
std::vector< Binning > fBins
Definition: SpectrumStan.h:73
#define pot
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67
const Binning bins
Definition: NumuCC_CPiBin.h:8
ana::SpectrumStan::SpectrumStan ( double *  binContents,
const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
double  pot,
double  livetime 
)

Definition at line 40 of file SpectrumStan.cxx.

References fBinContents, fBins, and fLabels.

46  {
47  // only support 1D for now; 0-size is the equivalent of null constructor
48  assert ((!binContents || fBins.size() == 1) && fBins.size() == fLabels.size());
49  if (!binContents)
50  return;
51 
52  fBinContents.reserve(bins[0].NBins()+2);
53  for (int binIdx = 0; binIdx < bins[0].NBins()+2; binIdx++)
54  fBinContents.emplace_back(binContents[binIdx]);
55  }
std::vector< std::string > fLabels
Definition: SpectrumStan.h:72
std::vector< Binning > fBins
Definition: SpectrumStan.h:73
#define pot
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67
const Binning bins
Definition: NumuCC_CPiBin.h:8
int NBins() const
Definition: Binning.h:25
ana::SpectrumStan::SpectrumStan ( const SpectrumStan rhs)

Definition at line 58 of file SpectrumStan.cxx.

References fBinContents.

59  : fPOT(rhs.fPOT), fLivetime(rhs.fLivetime),
60  fLabels(rhs.fLabels), fBins(rhs.fBins)
61  {
62  fBinContents.reserve(rhs.fBinContents.size());
63  fBinContents = rhs.fBinContents;
64  }
std::vector< std::string > fLabels
Definition: SpectrumStan.h:72
std::vector< Binning > fBins
Definition: SpectrumStan.h:73
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67
ana::SpectrumStan::SpectrumStan ( ana::SpectrumStan &&  rhs)

Definition at line 82 of file SpectrumStan.cxx.

83  : fBinContents(std::move(rhs.fBinContents)),
84  fPOT(rhs.fPOT), fLivetime(rhs.fLivetime),
85  fLabels(std::move(rhs.fLabels)), fBins(std::move(rhs.fBins))
86  {}
std::vector< std::string > fLabels
Definition: SpectrumStan.h:72
std::vector< Binning > fBins
Definition: SpectrumStan.h:73
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67
ana::SpectrumStan::SpectrumStan ( const Spectrum rhs)

Copy conversion from the normal kind of spectrum.

Definition at line 67 of file SpectrumStan.cxx.

References ana::HistCache::Delete(), fBinContents, ana::Spectrum::fLoaderCount, ana::Spectrum::GetBinnings(), analysePickle::hist, ana::Spectrum::POT(), and ana::Spectrum::ToTH1().

68  : fPOT(rhs.POT()), fLivetime(rhs.Livetime()),
69  fLabels(rhs.GetLabels()), fBins(rhs.GetBinnings())
70  {
71  assert(rhs.GetBinnings().size() == 1);
72  assert( rhs.fLoaderCount.empty() );
73  auto hist = rhs.ToTH1(rhs.POT());
74  fBinContents.resize(rhs.GetBinnings()[0].NBins()+2);
75  for (int binIdx = 0; binIdx < rhs.GetBinnings()[0].NBins()+2; binIdx++)
76  fBinContents[binIdx] = stan::math::var(hist->GetBinContent(binIdx));
77 
78  HistCache::Delete(hist);
79  }
std::vector< std::string > fLabels
Definition: SpectrumStan.h:72
std::vector< Binning > fBins
Definition: SpectrumStan.h:73
static void Delete(TH1D *&h)
Definition: HistCache.cxx:215
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67

Member Function Documentation

void ana::SpectrumStan::Clear ( )

Definition at line 144 of file SpectrumStan.cxx.

References fBinContents, and fBins.

Referenced by SpectrumStan().

145  {
146  fBinContents.resize(fBins[0].NBins()+2);
147  for (auto & binValPtr : this->fBinContents)
148  binValPtr = stan::math::var(0.0);
149  }
var
std::vector< Binning > fBins
Definition: SpectrumStan.h:73
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67
const std::vector<Binning>& ana::SpectrumStan::GetBinnings ( ) const
inline

Definition at line 43 of file SpectrumStan.h.

References fBins.

Referenced by ana::PredictionInterp::ShiftSpectrum(), and ana::Spectrum::Spectrum().

43 { return fBins; }
std::vector< Binning > fBins
Definition: SpectrumStan.h:73
const std::vector<std::string>& ana::SpectrumStan::GetLabels ( ) const
inline

Definition at line 44 of file SpectrumStan.h.

References fLabels.

Referenced by ana::PredictionInterp::ShiftSpectrum().

44 { return fLabels; }
std::vector< std::string > fLabels
Definition: SpectrumStan.h:72
double ana::SpectrumStan::Livetime ( ) const
inline

Definition at line 46 of file SpectrumStan.h.

References fLivetime.

Referenced by ana::PredictionInterp::ShiftSpectrum().

46 { return fLivetime; }
SpectrumStan ana::SpectrumStan::operator+ ( const SpectrumStan rhs) const

Definition at line 96 of file SpectrumStan.cxx.

References runNovaSAM::ret.

Referenced by POT().

97  {
98  SpectrumStan ret(*this);
99  ret += rhs;
100  return std::move(ret);
101  }
SpectrumStan(const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
SpectrumStan & ana::SpectrumStan::operator+= ( const SpectrumStan rhs)

Definition at line 89 of file SpectrumStan.cxx.

References PlusEqualsHelper().

Referenced by POT().

90  {
91  PlusEqualsHelper(rhs, +1);
92  return *this;
93  }
SpectrumStan & PlusEqualsHelper(const SpectrumStan &rhs, int sign)
Helper for operator+= and operator-=.
SpectrumStan ana::SpectrumStan::operator- ( const SpectrumStan rhs) const

Definition at line 111 of file SpectrumStan.cxx.

References runNovaSAM::ret.

Referenced by POT().

112  {
113  SpectrumStan ret(*this);
114  ret -= rhs;
115  return std::move(ret);
116  }
SpectrumStan(const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
SpectrumStan & ana::SpectrumStan::operator-= ( const SpectrumStan rhs)

Definition at line 104 of file SpectrumStan.cxx.

References PlusEqualsHelper().

Referenced by POT().

105  {
106  PlusEqualsHelper(rhs, -1);
107  return *this;
108  }
SpectrumStan & PlusEqualsHelper(const SpectrumStan &rhs, int sign)
Helper for operator+= and operator-=.
SpectrumStan & ana::SpectrumStan::operator= ( const SpectrumStan rhs)

Definition at line 119 of file SpectrumStan.cxx.

References SpectrumStan().

Referenced by POT().

120  {
121  this->~SpectrumStan();
122  new (this) SpectrumStan(rhs);
123  return *this;
124  }
SpectrumStan(const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
SpectrumStan & ana::SpectrumStan::operator= ( SpectrumStan &&  rhs)

Definition at line 127 of file SpectrumStan.cxx.

References SpectrumStan().

128  {
129  this->~SpectrumStan();
130  new (this) SpectrumStan(std::move(rhs));
131  return *this;
132  }
SpectrumStan(const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
SpectrumStan & ana::SpectrumStan::operator= ( const Spectrum rhs)

Assignment conversion from the normal kind of spectrum.

Definition at line 135 of file SpectrumStan.cxx.

References SpectrumStan().

136  {
137  // abuse (?) placement new to overwrite this object using the copy constructor
138  this->~SpectrumStan();
139  new (this) SpectrumStan(rhs);
140  return *this;
141  }
SpectrumStan(const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
SpectrumStan & ana::SpectrumStan::PlusEqualsHelper ( const SpectrumStan rhs,
int  sign 
)
private

Helper for operator+= and operator-=.

Definition at line 168 of file SpectrumStan.cxx.

References ana::AlmostEqual(), om::cerr, om::cout, allTimeWatchdog::endl, fBinContents, fLivetime, and fPOT.

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

169  {
170  assert (fBinContents.size() == rhs.fBinContents.size());
171 
172  if((!fPOT && !fLivetime) || (!rhs.fPOT && !rhs.fLivetime)){
173  std::cerr << "Error: can't sum SpectrumStan with no POT or livetime."
174  << std::endl;
175  abort();
176  }
177 
178  if(!fLivetime && !rhs.fPOT){
179  std::cerr << "Error: can't sum SpectrumStan with POT ("
180  << fPOT << ") but no livetime and SpectrumStan with livetime ("
181  << rhs.fLivetime << " sec) but no POT." << std::endl;
182  abort();
183  }
184 
185  if(!fPOT && !rhs.fLivetime){
186  std::cout << "Error: can't sum SpectrumStan with livetime ("
187  << fLivetime << " sec) but no POT and SpectrumStan with POT ("
188  << rhs.fPOT << ") but no livetime." << std::endl;
189  abort();
190  }
191 
192  // And now there are still a bunch of good cases to consider
193 
194  if(fPOT && rhs.fPOT){
195  // Scale by POT when possible
196  for (std::size_t binIdx = 0; binIdx < fBinContents.size(); binIdx++)
197  fBinContents[binIdx] += sign * fPOT / rhs.fPOT * rhs.fBinContents[binIdx];
198 
199  if(fLivetime && rhs.fLivetime){
200  // If POT/livetime ratios match, keep regular lifetime, otherwise zero
201  // it out.
202  if(AlmostEqual(fLivetime*rhs.fPOT, rhs.fLivetime*fPOT))
203  fLivetime = 0;
204  }
205  if(!fLivetime && rhs.fLivetime){
206  // If the RHS has a livetime and we don't, copy it in (suitably scaled)
207  fLivetime = rhs.fLivetime * fPOT/rhs.fPOT;
208  }
209  // Otherwise, keep our own livetime (if any)
210 
211  return *this;
212  }
213 
214  if(fLivetime && rhs.fLivetime){
215  // Scale by livetime, the only thing in common
216  for (std::size_t binIdx = 0; binIdx < fBinContents.size(); binIdx++)
217  fBinContents[binIdx] += sign * fLivetime / rhs.fLivetime * rhs.fBinContents[binIdx];
218 
219  if(!fPOT && rhs.fPOT){
220  // If the RHS has a POT and we don't, copy it in (suitably scaled)
221  fPOT = rhs.fPOT * fLivetime/rhs.fLivetime;
222  }
223  // Otherwise, keep our own POT (if any)
224 
225  return *this;
226  }
227 
228  // That should have been all the cases. I definitely want to know what
229  // happened if it wasn't.
230  std::cout << "SpectrumStan::PlusEqualsHelper(). How did we get here? "
231  << fPOT << " " << fLivetime << " "
232  << rhs.fPOT << " " << rhs.fLivetime << std::endl;
233  abort();
234  }
OStream cerr
Definition: OStream.cxx:7
bool AlmostEqual(double a, double b)
Definition: Utilities.cxx:732
def sign(x)
Definition: canMan.py:204
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67
OStream cout
Definition: OStream.cxx:6
double ana::SpectrumStan::POT ( ) const
inline
std::vector< stan::math::var > ana::SpectrumStan::ToBins ( double  pot) const

Definition at line 152 of file SpectrumStan.cxx.

References std::abs(), fBinContents, fPOT, runNovaSAM::ret, and febshutoff_auto::val.

Referenced by POT(), ana::PredictionInterp::ShiftSpectrum(), ana::Spectrum::Spectrum(), and test_stanfit_systpulls().

153  {
154  assert(fPOT > 0);
155 
156  std::vector<stan::math::var> ret = fBinContents;
157 
158  if (std::abs(pot - fPOT) < 1e12) // that's approximately one proton pulse. can't go smaller
159  return ret;
160 
161  for (auto & val : ret)
162  val *= pot / fPOT;
163 
164  return ret;
165  }
float abs(float number)
Definition: d0nt_math.hpp:39
#define pot
std::vector< stan::math::var > fBinContents
Contents of the bins.
Definition: SpectrumStan.h:67

Member Data Documentation

std::vector<stan::math::var> ana::SpectrumStan::fBinContents
private

Contents of the bins.

Definition at line 67 of file SpectrumStan.h.

Referenced by Clear(), PlusEqualsHelper(), SpectrumStan(), and ToBins().

std::vector<Binning> ana::SpectrumStan::fBins
private

Definition at line 73 of file SpectrumStan.h.

Referenced by Clear(), GetBinnings(), and SpectrumStan().

std::vector<std::string> ana::SpectrumStan::fLabels
private

Definition at line 72 of file SpectrumStan.h.

Referenced by GetLabels(), and SpectrumStan().

double ana::SpectrumStan::fLivetime
private

Definition at line 70 of file SpectrumStan.h.

Referenced by Livetime(), and PlusEqualsHelper().

double ana::SpectrumStan::fPOT
private

Definition at line 69 of file SpectrumStan.h.

Referenced by PlusEqualsHelper(), POT(), and ToBins().


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