All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ana::OscillatableSpectrum Class Reference

Spectrum with true energy information, allowing it to be oscillated More...

#include <OscillatableSpectrum.h>

Inheritance diagram for ana::OscillatableSpectrum:
ana::ReweightableSpectrum

Public Member Functions

 OscillatableSpectrum (const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 OscillatableSpectrum (SpectrumLoaderBase &loader, const HistAxis &axis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 OscillatableSpectrum (SpectrumLoaderBase &loader, const HistAxis &axis, const SpillCut &spillcut, const SliceCut &slicecut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 OscillatableSpectrum (const std::string &label, const Binning &bins)
 
 OscillatableSpectrum (const std::string &label, double pot, double livetime, const Binning &bins)
 
 OscillatableSpectrum (TH2 *h, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
 OscillatableSpectrum (std::unique_ptr< TH2D > h, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
 ~OscillatableSpectrum ()
 
 OscillatableSpectrum (const OscillatableSpectrum &rhs)
 Copy constructor. More...
 
 OscillatableSpectrum (OscillatableSpectrum &&rhs)
 
OscillatableSpectrumoperator= (const OscillatableSpectrum &rhs)
 Assignment operator. More...
 
OscillatableSpectrumoperator= (OscillatableSpectrum &&rhs)
 
Spectrum Unoscillated () const
 
Spectrum TrueEnergy () const
 
Spectrum Oscillated (osc::IOscCalc *calc, int from, int to) const
 
OscillatableSpectrumoperator+= (const OscillatableSpectrum &rhs)
 
OscillatableSpectrum operator+ (const OscillatableSpectrum &rhs) const
 
OscillatableSpectrumoperator-= (const OscillatableSpectrum &rhs)
 
OscillatableSpectrum operator- (const OscillatableSpectrum &rhs) const
 
void SaveTo (TDirectory *dir) const
 
- Public Member Functions inherited from ana::ReweightableSpectrum
 ReweightableSpectrum (SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 ReweightableSpectrum (SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const SpillCut &spillcut, const SliceCut &slicecut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 ReweightableSpectrum (const Var &rwVar, const std::string &xlabel, const std::string &ylabel, double pot, int nbinsx, double xmin, double xmax, int nbinsy, double ymin, double ymax)
 
 ReweightableSpectrum (const Var &rwVar, TH2 *h, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
 ReweightableSpectrum (const Var &rwVar, std::unique_ptr< TH2D > h, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
virtual ~ReweightableSpectrum ()
 
 ReweightableSpectrum (const ReweightableSpectrum &rhs)
 
ReweightableSpectrumoperator= (const ReweightableSpectrum &rhs)
 
const VarReweightVar () const
 The variable that will be used to fill the y-axis. More...
 
void Fill (double x, double y, double w=1)
 
TH2D * ToTH2 (double pot) const
 
Spectrum UnWeighted () const
 
Spectrum WeightingVariable () const
 
Spectrum WeightedBy (const TH1 *weights) const
 
void ReweightToTrueSpectrum (const Spectrum &target)
 Rescale bins so that WeightingVariable will return target. More...
 
void ReweightToRecoSpectrum (const Spectrum &target)
 Recale bins so that Unweighted will return target. More...
 
void Clear ()
 
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
< OscillatableSpectrum
LoadFrom (TDirectory *dir)
 
- Static Public Member Functions inherited from ana::ReweightableSpectrum
static std::unique_ptr
< ReweightableSpectrum
LoadFrom (TDirectory *dir)
 

Protected Member Functions

 OscillatableSpectrum (const std::vector< std::string > &labels, const std::vector< Binning > &bins, const Var &rwVar)
 
 fCachedHash (0)
 
 OscillatableSpectrum (const std::string &label, const Binning &bins, const Var &rwVar)
 
 fCachedHash (0)
 
- Protected Member Functions inherited from ana::ReweightableSpectrum
 ReweightableSpectrum (const std::vector< std::string > &labels, const std::vector< Binning > &bins, const Var &rwVar)
 
 ReweightableSpectrum (const std::string &label, const Binning &bins, const Var &rwVar)
 
 ReweightableSpectrum (TH2 *h, const std::vector< std::string > &labels, const std::vector< Binning > &bins, double pot, double livetime)
 
void RemoveLoader (SpectrumLoaderBase *)
 
void AddLoader (SpectrumLoaderBase *)
 

Protected Attributes

Spectrum fCachedOsc
 
TMD5 * fCachedHash
 
- Protected Attributes inherited from ana::ReweightableSpectrum
Var fRWVar
 What goes on the y axis? More...
 
TH2D * fHist
 
double fPOT
 
double fLivetime
 
std::vector< std::string > fLabels
 
std::vector< BinningfBins
 
std::string fTrueLabel
 
std::set< SpectrumLoaderBase * > fLoaderCount
 This count is maintained by SpectrumLoader, as a sanity check. More...
 

Friends

class SpectrumLoaderBase
 
class SpectrumLoader
 
class NullLoader
 

Detailed Description

Spectrum with true energy information, allowing it to be oscillated

Definition at line 24 of file OscillatableSpectrum.h.

Constructor & Destructor Documentation

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

Definition at line 34 of file OscillatableSpectrum.cxx.

40  : ReweightableSpectrum(label, bins, kTrueLOverE),
41  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const Var kTrueLOverE
ana::OscillatableSpectrum::OscillatableSpectrum ( SpectrumLoaderBase loader,
const HistAxis axis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 54 of file OscillatableSpectrum.cxx.

59  : OscillatableSpectrum(loader, axis, kNoSpillCut, cut, shift, wei)
60  {
61  }
tuple loader
Definition: demo.py:7
shift
Definition: fcl_checks.sh:26
OscillatableSpectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const SpillCut kNoSpillCut([](const caf::SRSpillProxy *){return true;})
The simplest possible cut: pass everything, used as a default.
ana::OscillatableSpectrum::OscillatableSpectrum ( SpectrumLoaderBase loader,
const HistAxis axis,
const SpillCut spillcut,
const SliceCut slicecut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 64 of file OscillatableSpectrum.cxx.

70  : ReweightableSpectrum(axis.GetLabels(), axis.GetBinnings(), kTrueLOverE),
71  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const Var kTrueLOverE
ana::OscillatableSpectrum::OscillatableSpectrum ( const std::string &  label,
const Binning bins 
)

Definition at line 104 of file OscillatableSpectrum.cxx.

106  : ReweightableSpectrum(label, bins, kTrueLOverE),
107  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const Var kTrueLOverE
ana::OscillatableSpectrum::OscillatableSpectrum ( const std::string &  label,
double  pot,
double  livetime,
const Binning bins 
)

Definition at line 121 of file OscillatableSpectrum.cxx.

123  : ReweightableSpectrum(label, bins, kTrueLOverE),
124  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const Var kTrueLOverE
ana::OscillatableSpectrum::OscillatableSpectrum ( TH2 *  h,
const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
double  pot,
double  livetime 
)

Definition at line 138 of file OscillatableSpectrum.cxx.

142  : ReweightableSpectrum(kTrueLOverE, h, labels, bins, pot, livetime),
143  fCachedOsc(0, {}, {}, 0, 0),
while getopts h
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const Var kTrueLOverE
ana::OscillatableSpectrum::OscillatableSpectrum ( std::unique_ptr< TH2D >  h,
const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
double  pot,
double  livetime 
)

Definition at line 150 of file OscillatableSpectrum.cxx.

154  : ReweightableSpectrum(kTrueLOverE, std::move(h), labels, bins, pot, livetime),
155  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const Var kTrueLOverE
ana::OscillatableSpectrum::~OscillatableSpectrum ( )

Definition at line 162 of file OscillatableSpectrum.cxx.

163  {
164  // Nulls fHist out, so it's safe that ~ReweightableSpectrum tries too
166 
168  { loader->RemoveReweightableSpectrum(this); }
169 
170  delete fCachedHash;
171  }
tuple loader
Definition: demo.py:7
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
ana::OscillatableSpectrum::OscillatableSpectrum ( const OscillatableSpectrum rhs)

Copy constructor.

Definition at line 174 of file OscillatableSpectrum.cxx.

175  : ReweightableSpectrum(rhs.fLabels, rhs.fBins, kTrueLOverE),
176  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const Var kTrueLOverE
ana::OscillatableSpectrum::OscillatableSpectrum ( OscillatableSpectrum &&  rhs)

Definition at line 195 of file OscillatableSpectrum.cxx.

196  : ReweightableSpectrum(rhs.fLabels, rhs.fBins, kTrueLOverE),
197  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
const Var kTrueLOverE
ana::OscillatableSpectrum::OscillatableSpectrum ( const std::vector< std::string > &  labels,
const std::vector< Binning > &  bins,
const Var rwVar 
)
inlineprotected

Definition at line 101 of file OscillatableSpectrum.h.

104  : ReweightableSpectrum(labels, bins, rwVar),
105  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
ana::OscillatableSpectrum::OscillatableSpectrum ( const std::string &  label,
const Binning bins,
const Var rwVar 
)
inlineprotected

Definition at line 110 of file OscillatableSpectrum.h.

113  : ReweightableSpectrum(label, bins, rwVar),
114  fCachedOsc(0, {}, {}, 0, 0),
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)

Member Function Documentation

ana::OscillatableSpectrum::fCachedHash ( )
inlineprotected

Definition at line 106 of file OscillatableSpectrum.h.

107  {
108  }
ana::OscillatableSpectrum::fCachedHash ( )
inlineprotected

Definition at line 115 of file OscillatableSpectrum.h.

116  {
117  }
std::unique_ptr< OscillatableSpectrum > ana::OscillatableSpectrum::LoadFrom ( TDirectory *  dir)
static

Definition at line 385 of file OscillatableSpectrum.cxx.

386  {
387  DontAddDirectory guard;
388 
389  TObjString* tag = (TObjString*)dir->Get("type");
390  assert(tag);
391  assert(tag->GetString() == "OscillatableSpectrum");
392  delete tag;
393 
394  TH2D* spect = (TH2D*)dir->Get("hist");
395  assert(spect);
396  TH1* hPot = (TH1*)dir->Get("pot");
397  assert(hPot);
398  TH1* hLivetime = (TH1*)dir->Get("livetime");
399  assert(hLivetime);
400 
401  std::vector<std::string> labels;
402  std::vector<Binning> bins;
403 
404  for(int i = 0; ; ++i){
405  TDirectory* subdir = dir->GetDirectory(TString::Format("bins%d", i));
406  if(!subdir) break;
407  bins.push_back(*Binning::LoadFrom(subdir));
408  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
409  labels.push_back(label ? label->GetString().Data() : "");
410  delete subdir;
411  delete label;
412  }
413 
414  if(bins.empty() && labels.empty()){
415  // Must be an old file. Make an attempt at backwards compatibility.
416  bins.push_back(Binning::FromTAxis(spect->GetXaxis()));
417  labels.push_back(spect->GetXaxis()->GetTitle());
418  }
419 
420  auto ret = std::make_unique<OscillatableSpectrum>(std::unique_ptr<TH2D>(spect),
421  labels, bins,
422  hPot->GetBinContent(1),
423  hLivetime->GetBinContent(1));
424 
425  delete hPot;
426  delete hLivetime;
427  return ret;
428  }
* labels
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:122
tuple dir
Definition: dropbox.py:28
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir)
Definition: Binning.cxx:229
OscillatableSpectrum ana::OscillatableSpectrum::operator+ ( const OscillatableSpectrum rhs) const

Definition at line 328 of file OscillatableSpectrum.cxx.

329  {
330  OscillatableSpectrum ret = *this;
331  ret += rhs;
332  return ret;
333  }
OscillatableSpectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
OscillatableSpectrum & ana::OscillatableSpectrum::operator+= ( const OscillatableSpectrum rhs)

Definition at line 308 of file OscillatableSpectrum.cxx.

309  {
310  // If someone actually needs this we can go in and fix the behaviour
311  assert(fPOT);
312 
313  if(rhs.fPOT){
314  fHist->Add(rhs.fHist, fPOT/rhs.fPOT);
315  }
316  else{
317  // How can it have events but no POT?
318  assert(rhs.fHist->Integral() == 0);
319  }
320 
321  delete fCachedHash;
322  fCachedHash = 0; // Invalidate
323 
324  return *this;
325  }
OscillatableSpectrum ana::OscillatableSpectrum::operator- ( const OscillatableSpectrum rhs) const

Definition at line 353 of file OscillatableSpectrum.cxx.

354  {
355  OscillatableSpectrum ret = *this;
356  ret -= rhs;
357  return ret;
358  }
OscillatableSpectrum(const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
OscillatableSpectrum & ana::OscillatableSpectrum::operator-= ( const OscillatableSpectrum rhs)

Definition at line 336 of file OscillatableSpectrum.cxx.

337  {
338  if(rhs.fPOT){
339  fHist->Add(rhs.fHist, -fPOT/rhs.fPOT);
340  }
341  else{
342  // How can it have events but no POT?
343  assert(rhs.fHist->Integral() == 0);
344  }
345 
346  delete fCachedHash;
347  fCachedHash = 0; // Invalidate
348 
349  return *this;
350  }
OscillatableSpectrum & ana::OscillatableSpectrum::operator= ( const OscillatableSpectrum rhs)

Assignment operator.

Definition at line 218 of file OscillatableSpectrum.cxx.

219  {
220  if(this == &rhs) return *this;
221 
222  DontAddDirectory guard;
223 
225  fHist = HistCache::Copy(rhs.fHist);
226  fPOT = rhs.fPOT;
227  fLivetime = rhs.fLivetime;
228  fLabels = rhs.fLabels;
229  fBins = rhs.fBins;
230 
231  if(rhs.fCachedHash){
232  fCachedOsc = rhs.fCachedOsc;
233  delete fCachedHash;
234  fCachedHash = new TMD5(*rhs.fCachedHash);
235  }
236 
237  assert( rhs.fLoaderCount.empty() ); // Copying with pending loads is unexpected
238  assert( fLoaderCount.empty() ); // Copying with pending loads is unexpected
239 
240  return *this;
241  }
static TH1D * Copy(const TH1D *h)
Definition: HistCache.cxx:76
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
std::vector< std::string > fLabels
std::vector< Binning > fBins
OscillatableSpectrum & ana::OscillatableSpectrum::operator= ( OscillatableSpectrum &&  rhs)

Definition at line 244 of file OscillatableSpectrum.cxx.

245  {
246  if(this == &rhs) return *this;
247 
248  DontAddDirectory guard;
249 
251  fHist = rhs.fHist;
252  rhs.fHist = 0;
253  fPOT = rhs.fPOT;
254  fLivetime = rhs.fLivetime;
255  fLabels = rhs.fLabels;
256  fBins = rhs.fBins;
257 
258  if(rhs.fCachedHash){
259  fCachedOsc = rhs.fCachedOsc;
260  delete fCachedHash;
261  fCachedHash = rhs.fCachedHash;
262  rhs.fCachedHash = 0;
263  }
264 
265  assert( rhs.fLoaderCount.empty() ); // Copying with pending loads is unexpected
266  assert( fLoaderCount.empty() ); // Copying with pending loads is unexpected
267 
268  return *this;
269  }
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
std::vector< std::string > fLabels
std::vector< Binning > fBins
Spectrum ana::OscillatableSpectrum::Oscillated ( osc::IOscCalc calc,
int  from,
int  to 
) const

Definition at line 272 of file OscillatableSpectrum.cxx.

274  {
275  // TODO remove this check in a little while, once no one is using old state
276  // files anymore (comment from Feb 2020).
277  const bool isLoverE = (fHist->GetYaxis()->GetXmax() == 2);
278  static bool once = true;
279  if(once && !isLoverE){
280  once = false;
281  std::cout << "\nWarning: OscillatableSpectrum with legacy non-L/E y-axis detected. Will oscillate correctly for now, but this code will eventually be removed\n" << std::endl;
282  }
283 
284  // POT = 0 implies empty spectrum and oscillated result will also always be
285  // empty
286  if(fCachedHash && fPOT == 0) return fCachedOsc;
287 
288  TMD5* hash = calc->GetParamsHash();
289  if(hash && fCachedHash && *hash == *fCachedHash){
290  delete hash;
291  return fCachedOsc;
292  }
293 
294  const OscCurve curve(calc, from, to, isLoverE);
295  TH1D* Ps = curve.ToTH1();
296 
297  const Spectrum ret = WeightedBy(Ps);
298  if(hash){
299  fCachedOsc = ret;
300  delete fCachedHash;
301  fCachedHash = hash;
302  }
303  HistCache::Delete(Ps);
304  return ret;
305  }
static void Delete(TH1D *&h)
Definition: HistCache.cxx:92
Spectrum WeightedBy(const TH1 *weights) const
BEGIN_PROLOG could also be cout
void ana::OscillatableSpectrum::SaveTo ( TDirectory *  dir) const

Definition at line 361 of file OscillatableSpectrum.cxx.

362  {
363  TDirectory* tmp = gDirectory;
364  dir->cd();
365 
366  TObjString("OscillatableSpectrum").Write("type");
367 
368  fHist->Write("hist");
369  TH1D hPot("", "", 1, 0, 1);
370  hPot.Fill(.5, fPOT);
371  hPot.Write("pot");
372  TH1D hLivetime("", "", 1, 0, 1);
373  hLivetime.Fill(.5, fLivetime);
374  hLivetime.Write("livetime");
375 
376  for(unsigned int i = 0; i < fBins.size(); ++i){
377  TObjString(fLabels[i].c_str()).Write(TString::Format("label%d", i).Data());
378  fBins[i].SaveTo(dir->mkdir(TString::Format("bins%d", i)));
379  }
380 
381  tmp->cd();
382  }
std::vector< std::string > fLabels
tuple dir
Definition: dropbox.py:28
std::vector< Binning > fBins
Spectrum ana::OscillatableSpectrum::TrueEnergy ( ) const
inline

Definition at line 86 of file OscillatableSpectrum.h.

86 {return WeightingVariable();}
Spectrum ana::OscillatableSpectrum::Unoscillated ( ) const
inline

Definition at line 85 of file OscillatableSpectrum.h.

85 {return UnWeighted();}

Friends And Related Function Documentation

friend class NullLoader
friend

Definition at line 29 of file OscillatableSpectrum.h.

friend class SpectrumLoader
friend

Definition at line 28 of file OscillatableSpectrum.h.

friend class SpectrumLoaderBase
friend

Definition at line 27 of file OscillatableSpectrum.h.

Member Data Documentation

TMD5* ana::OscillatableSpectrum::fCachedHash
mutableprotected

Definition at line 120 of file OscillatableSpectrum.h.

Spectrum ana::OscillatableSpectrum::fCachedOsc
mutableprotected

Definition at line 119 of file OscillatableSpectrum.h.


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