Public Member Functions | Private Attributes | List of all members
fnex::Spectrum Class Reference

The Spectrum is the means for interaction with Event collections. More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N20-12-03/FNEX/core/Spectrum.h"

Public Member Functions

 Spectrum (EventList const &evts, Binning const *sb, std::string const &nm="")
 
const TH1 * Histogram (std::string const &varName)
 Prepare a histogram using the fnex::Event objects in the fnex::EventList this Spectrum is using. More...
 
std::vector< double > BaseVals (std::string const &varName) const
 Used for Unbinned Likelihood fits. More...
 
fnex::EventList const & Events () const
 Get the EventList that was supplied to this Spectrum. More...
 
std::string GetName () const
 
 Spectrum ()
 
 ~Spectrum ()
 
void Reconfigure (fhicl::ParameterSet const &pset)
 

Private Attributes

std::string fName
 
fnex::EventList fEvents
 fnex::Events from which the Spectrum draws. More...
 
std::unique_ptr< TH1D > fHist
 

Detailed Description

The Spectrum is the means for interaction with Event collections.

Spectrum objects provide a nicer interface to fnex::EventLists. They can produce aggregates of those Events, like histograms, and are designed to minimize reprocessing where possible.

Definition at line 29 of file Spectrum.h.

Constructor & Destructor Documentation

fnex::Spectrum::Spectrum ( EventList const &  evts,
Binning const *  sb,
std::string const &  nm = "" 
)

Definition at line 23 of file Spectrum.cxx.

References fnex::Binning::BinLowEdges(), fHist, compareCafs::histName, fnex::EventList::ListMetaData(), fnex::Binning::nBins(), Munits::nm, string, and fnex::MetaData::ToString().

26  : fName (nm)
27  , fEvents (evts)
28  {
29  std::string histName = evts.ListMetaData().ToString() + nm;
30 
31 // LOG_VERBATIM("Spectrum")
32 // << "Making spectrum for "
33 // << histName
34 // << " with "
35 // << sb->nBins();
36 // for(auto itr : sb->BinLowEdges())
37 // LOG_VERBATIM("Spectrum")
38 // << itr;
39 
40  fHist.reset(new TH1D(histName.c_str(),
41  ";;",
42  sb->nBins(),
43  &(sb->BinLowEdges()[0])));
44 
45  fHist->Sumw2();
46 
47  return;
48  }
static constexpr Double_t nm
Definition: Munits.h:133
fnex::EventList fEvents
fnex::Events from which the Spectrum draws.
Definition: Spectrum.h:64
std::string fName
Definition: Spectrum.h:59
std::unique_ptr< TH1D > fHist
Definition: Spectrum.h:65
enum BeamMode string
fnex::Spectrum::Spectrum ( )

Definition at line 5 of file Spectrum_False.cxx.

5  {
6 
7  }
fnex::Spectrum::~Spectrum ( )

Definition at line 9 of file Spectrum_False.cxx.

9  {
10 
11  }

Member Function Documentation

std::vector< double > fnex::Spectrum::BaseVals ( std::string const &  varName) const

Used for Unbinned Likelihood fits.

Definition at line 77 of file Spectrum.cxx.

References fEvents, r(), and fnex::VarNameToKey().

78  {
79 
80  std::vector<double> r;
81  for (auto & event : this->fEvents)
82  {
83  r.push_back(event->dataVals->val_at(fnex::VarNameToKey(varName),
84  fEvents.ListMetaData())
85  );
86  } // for (event)
87  return r;
88 
89  } // Spectrum::Histogram
unsigned char VarNameToKey(std::string const &name)
Definition: VarVals.h:279
fnex::EventList fEvents
fnex::Events from which the Spectrum draws.
Definition: Spectrum.h:64
TRandom3 r(0)
fnex::EventList const& fnex::Spectrum::Events ( ) const
inline

Get the EventList that was supplied to this Spectrum.

Definition at line 57 of file Spectrum.h.

References fEvents.

Referenced by fnex::SpectrumTest::InspectEventLists().

57 { return this->fEvents; };
fnex::EventList fEvents
fnex::Events from which the Spectrum draws.
Definition: Spectrum.h:64
std::string fnex::Spectrum::GetName ( ) const
inline

Definition at line 59 of file Spectrum.h.

References fName, and string.

59 { return this->fName; };
std::string fName
Definition: Spectrum.h:59
const TH1 * fnex::Spectrum::Histogram ( std::string const &  varName)

Prepare a histogram using the fnex::Event objects in the fnex::EventList this Spectrum is using.

Create and return a ROOT histogram by looping through the fnex::EventList this Spectrum uses, plotting the variable indicated by varName. Optionally apply fnex::Shifters, fnex::Weighters, fnex::Cuts if desired to alter the resulting histogram.

Histogram() attempts to be intelligent and only loops through fnex::Events if the given combination of variable, fnex::ShiftCollection, and fnex::WeightCollection has not already been requested. Therefore, it returns a const histogram (to ensure that it is not changed between calls). The caller may copy it if they need to modify it.

WARNING: Histogram() currently always passes the 'central value' (unshifted) values of the fnex::Events' variables to Weighters. This is to avoid ballooning the storage requirements out of control.

TODO: really should be accepting a std::unordered_set<std::string>, so as to handle multiple variables simultaneously within a single event loop.

Definition at line 53 of file Spectrum.cxx.

References fEvents, fHist, fnex::ShifterAndWeighter::Instance(), fnex::EventList::ListMetaData(), fetch_tb_beamline_files::md, fnex::VarNameToKey(), fnex::ShifterAndWeighter::Weight(), and wgt.

Referenced by fnex::CorrSpec_MichelDecomp::AddSpectrumHistogram(), fnex::CorrSpec_SimpleNuMuExtrap::AddSpectrumHistogram(), fnex::CorrSpec_SimpleExtrap::AddSpectrumHistogram(), fnex::CorrSpec_PropDecomp::AddSpectrumHistogram(), fnex::CorrSpec_NoExtrapNuMu::AddSpectrumHistogram(), fnex::CorrSpec_NoExtrapNuE::AddSpectrumHistogram(), and fnex::CorrSpec_BENDecomp::AddSpectrumHistogram().

54  {
55  // reset the histogram to fill it again.
56  fHist->Reset();
57 
58  // ok. if we're still here we need to go to the event loop.
59  auto const& md = fEvents.ListMetaData();
60  for (auto & event : this->fEvents){
61 
62  // now handle the weight business.
64 
65  // Related to energy ranges - Use the Experiments.fcl to set the energy range
66  // instead of here.
67 
68  fHist->Fill(event->dataVals->val_at(fnex::VarNameToKey(varName), md), wgt);
69  } // for (event)
70 
71  return fHist.get();
72  } // Spectrum::Histogram
unsigned char VarNameToKey(std::string const &name)
Definition: VarVals.h:279
fnex::MetaData const & ListMetaData() const
Definition: Event.h:131
fnex::EventList fEvents
fnex::Events from which the Spectrum draws.
Definition: Spectrum.h:64
static ShifterAndWeighter * Instance()
double Weight(fnex::EventPtr const &curEvent, fnex::MetaData const &md, fnex::WeightType_t const wgtType=kAllWgt)
const ana::Var wgt
std::unique_ptr< TH1D > fHist
Definition: Spectrum.h:65
void fnex::Spectrum::Reconfigure ( fhicl::ParameterSet const &  pset)

Definition at line 14 of file Spectrum_False.cxx.

14  {
15  return;
16  }

Member Data Documentation

fnex::EventList fnex::Spectrum::fEvents
private

fnex::Events from which the Spectrum draws.

Definition at line 64 of file Spectrum.h.

Referenced by BaseVals(), Events(), and Histogram().

std::unique_ptr<TH1D> fnex::Spectrum::fHist
private

Definition at line 65 of file Spectrum.h.

Referenced by Histogram(), and Spectrum().

std::string fnex::Spectrum::fName
private

Definition at line 59 of file Spectrum.h.

Referenced by GetName().


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