Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | Friends | List of all members
ana::NDOscillatableSpectrum Class Reference

Spectrum with true L/E information, allowing it to be oscillated More...

#include "/cvmfs/nova-development.opensciencegrid.org/novasoft/releases/N21-05-06/CAFAna/Core/NDOscillatableSpectrum.h"

Inheritance diagram for ana::NDOscillatableSpectrum:
ana::ReweightableSpectrum

Public Member Functions

 NDOscillatableSpectrum (const std::string &label, const Binning &bins, SpectrumLoaderBase &loader, const Var &var, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 NDOscillatableSpectrum (SpectrumLoaderBase &loader, const HistAxis &axis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
 
 ~NDOscillatableSpectrum ()
 
 NDOscillatableSpectrum (const NDOscillatableSpectrum &rhs)
 Copy constructor. More...
 
 NDOscillatableSpectrum (NDOscillatableSpectrum &&rhs)
 
NDOscillatableSpectrumoperator= (const NDOscillatableSpectrum &rhs)
 Assignment operator. More...
 
NDOscillatableSpectrumoperator= (NDOscillatableSpectrum &&rhs)
 
Spectrum Oscillated (osc::IOscCalc *calc, int from, int to) const
 
void Scale (double x)
 
void SaveTo (TDirectory *dir, const std::string &name) const
 
void Fill (double x, double y, double w=1)
 
TH2D * ToTH2 (double pot) const
 
double POT () const
 
double Livetime () const
 
Spectrum UnWeighted () const
 
Spectrum WeightingVariable () const
 
Spectrum WeightedBy (const Ratio &weights) const
 Reco spectrum with truth weights applied. More...
 
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...
 
ReweightableSpectrumoperator+= (const ReweightableSpectrum &rhs)
 
ReweightableSpectrum operator+ (const ReweightableSpectrum &rhs) const
 
ReweightableSpectrumoperator-= (const ReweightableSpectrum &rhs)
 
ReweightableSpectrum operator- (const ReweightableSpectrum &rhs) const
 
void Clear ()
 
unsigned int NDimensions () const
 
const std::vector< std::string > & GetLabels () const
 
const std::vector< Binning > & GetBinnings () const
 
const std::vector< Binning > & GetTrueBinnings () const
 
Eigen::MatrixXd GetEigen (double pot) const
 

Static Public Member Functions

static NDOscillatableSpectrum Uninitialized ()
 
static std::unique_ptr< NDOscillatableSpectrumLoadFrom (TDirectory *dir, const std::string &name)
 

Protected Member Functions

 NDOscillatableSpectrum ()
 Constructor for Uninitialized() More...
 
ReweightableSpectrumPlusEqualsHelper (const ReweightableSpectrum &rhs, int sign)
 
void RemoveLoader (ReweightableSpectrum **)
 
void AddLoader (ReweightableSpectrum **)
 
void _SaveTo (TDirectory *dir, const std::string &name, const std::string &type) const
 

Protected Attributes

Eigen::MatrixXd fMat
 
double fPOT
 
double fLivetime
 
LabelsAndBins fAxisX
 
LabelsAndBins fAxisY
 
std::set< ReweightableSpectrum ** > fReferences
 

Friends

class SpectrumLoaderBase
 
class SpectrumLoader
 
class NullLoader
 

Detailed Description

Spectrum with true L/E information, allowing it to be oscillated

Definition at line 25 of file NDOscillatableSpectrum.h.

Constructor & Destructor Documentation

ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( 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 35 of file NDOscillatableSpectrum.cxx.

43  HistAxis("True Energy (GeV)", kTrueLOverTrueEBins, kTrueLOverTrueE),
44  cut, shift, wei)
45  {
46  }
const Binning kTrueLOverTrueEBins
Default true-energy bin edges.
Definition: Binning.cxx:62
var_value< double > var
Definition: StanTypedefs.h:14
const char * label
const Var kTrueLOverTrueE([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return 0.;const double trueE=sr->mc.nu[0].E;const double trueL=sr->mc.nu[0].L;return trueL/trueE;})
loader
Definition: demo0.py:10
const Binning bins
Definition: NumuCC_CPiBin.h:8
const Cut cut
Definition: exporter_fd.C:30
_HistAxis< Var > HistAxis
Definition: HistAxis.h:10
ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( SpectrumLoaderBase loader,
const HistAxis axis,
const Cut cut,
const SystShifts shift = kNoShift,
const Var wei = kUnweighted 
)

Definition at line 49 of file NDOscillatableSpectrum.cxx.

55  HistAxis("True Energy (GeV)", kTrueLOverTrueEBins, kTrueLOverTrueE),
56  cut, shift, wei)
57  {
58  }
const Binning kTrueLOverTrueEBins
Default true-energy bin edges.
Definition: Binning.cxx:62
const Var kTrueLOverTrueE([](const caf::SRProxy *sr){if(sr->mc.nnu==0) return 0.;const double trueE=sr->mc.nu[0].E;const double trueL=sr->mc.nu[0].L;return trueL/trueE;})
loader
Definition: demo0.py:10
const Cut cut
Definition: exporter_fd.C:30
_HistAxis< Var > HistAxis
Definition: HistAxis.h:10
ana::NDOscillatableSpectrum::~NDOscillatableSpectrum ( )

Definition at line 61 of file NDOscillatableSpectrum.cxx.

Referenced by Uninitialized().

62  {
63  }
ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( const NDOscillatableSpectrum rhs)

Copy constructor.

Definition at line 66 of file NDOscillatableSpectrum.cxx.

References ana::assert(), and ana::ReweightableSpectrum::fReferences.

68  {
69  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
70  }
assert(nhit_max >=nhit_nbins)
ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( NDOscillatableSpectrum &&  rhs)

Definition at line 74 of file NDOscillatableSpectrum.cxx.

References ana::assert().

76  {
77  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
78  }
assert(nhit_max >=nhit_nbins)
ana::NDOscillatableSpectrum::NDOscillatableSpectrum ( )
inlineprotected

Constructor for Uninitialized()

Definition at line 69 of file NDOscillatableSpectrum.h.

Referenced by Uninitialized().

70  {
71  }

Member Function Documentation

void ana::ReweightableSpectrum::_SaveTo ( TDirectory *  dir,
const std::string name,
const std::string type 
) const
protectedinherited

Definition at line 286 of file ReweightableSpectrum.cxx.

References dir, ana::ReweightableSpectrum::fAxisX, ana::ReweightableSpectrum::fAxisY, ana::ReweightableSpectrum::fLivetime, genie::utils::style::Format(), ana::ReweightableSpectrum::fPOT, ana::LabelsAndBins::GetBinnings(), ana::LabelsAndBins::GetLabels(), make_syst_table_plots::h, MECModelEnuComparisons::i, ana::LabelsAndBins::NDimensions(), tmp, ana::ReweightableSpectrum::ToTH2(), and Write().

Referenced by ana::ReweightableSpectrum::ReweightableSpectrum(), SaveTo(), ana::ReweightableSpectrum::SaveTo(), and ana::OscillatableSpectrum::SaveTo().

289  {
290  TDirectory* tmp = gDirectory;
291 
292  dir = dir->mkdir(name.c_str()); // switch to sbudir
293  dir->cd();
294 
295  TObjString(type.c_str()).Write("type");
296 
297  TH2* h = ToTH2(fPOT);
298  h->Write("hist");
299 
300  TH1D hPot("", "", 1, 0, 1);
301  hPot.Fill(.5, fPOT);
302  hPot.Write("pot");
303  TH1D hLivetime("", "", 1, 0, 1);
304  hLivetime.Fill(.5, fLivetime);
305  hLivetime.Write("livetime");
306 
307  for(unsigned int i = 0; i < fAxisX.NDimensions(); ++i){
308  TObjString(fAxisX.GetLabels()[i].c_str()).Write(TString::Format("label%d", i).Data());
309  fAxisX.GetBinnings()[i].SaveTo(dir, TString::Format("bins%d", i).Data());
310  }
311 
312  for(unsigned int i = 0; i < fAxisY.NDimensions(); ++i){
313  TObjString(fAxisY.GetLabels()[i].c_str()).Write(TString::Format("labely%d", i).Data());
314  fAxisY.GetBinnings()[i].SaveTo(dir, TString::Format("binsy%d", i).Data());
315  }
316 
317  dir->Write();
318  delete dir;
319 
320  delete h;
321 
322  tmp->cd();
323  }
const XML_Char * name
Definition: expat.h:151
Float_t tmp
Definition: plot.C:36
const std::vector< Binning > & GetBinnings() const
Definition: LabelsAndBins.h:69
unsigned int NDimensions() const
Definition: LabelsAndBins.h:66
TDirectory * dir
Definition: macro.C:5
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
const std::vector< std::string > & GetLabels() const
Definition: LabelsAndBins.h:68
TH2D * ToTH2(double pot) const
gm Write()
void ana::ReweightableSpectrum::AddLoader ( ReweightableSpectrum **  ref)
protectedinherited

Definition at line 274 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fReferences.

Referenced by ana::ReweightableSpectrum::ReweightableSpectrum().

275  {
276  fReferences.insert(ref);
277  }
std::set< ReweightableSpectrum ** > fReferences
void ana::ReweightableSpectrum::Clear ( void  )
inherited
void ana::ReweightableSpectrum::Fill ( double  x,
double  y,
double  w = 1 
)
inherited
const std::vector<Binning>& ana::ReweightableSpectrum::GetBinnings ( ) const
inlineinherited
Eigen::MatrixXd ana::ReweightableSpectrum::GetEigen ( double  pot) const
inlineinherited
const std::vector<std::string>& ana::ReweightableSpectrum::GetLabels ( ) const
inlineinherited
const std::vector<Binning>& ana::ReweightableSpectrum::GetTrueBinnings ( ) const
inlineinherited

Definition at line 83 of file ReweightableSpectrum.h.

References ana::ReweightableSpectrum::fAxisY, and ana::LabelsAndBins::GetBinnings().

83 {return fAxisY.GetBinnings();}
const std::vector< Binning > & GetBinnings() const
Definition: LabelsAndBins.h:69
double ana::ReweightableSpectrum::Livetime ( ) const
inlineinherited
std::unique_ptr< NDOscillatableSpectrum > ana::NDOscillatableSpectrum::LoadFrom ( TDirectory *  dir,
const std::string name 
)
static

Definition at line 121 of file NDOscillatableSpectrum.cxx.

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

Referenced by Scale().

122  {
123  dir = dir->GetDirectory(name.c_str()); // switch to subdir
124  assert(dir);
125 
126  DontAddDirectory guard;
127 
128  TObjString* tag = (TObjString*)dir->Get("type");
129  assert(tag);
130  assert(tag->GetString() == "NDOscillatableSpectrum");
131  delete tag;
132 
133  TH2D* spect = (TH2D*)dir->Get("hist");
134  assert(spect);
135  TH1* hPot = (TH1*)dir->Get("pot");
136  assert(hPot);
137  TH1* hLivetime = (TH1*)dir->Get("livetime");
138  assert(hLivetime);
139 
140  std::vector<std::string> labels;
141  std::vector<Binning> bins;
142 
143  for(int i = 0; ; ++i){
144  const std::string subname = TString::Format("bins%d", i).Data();
145  TDirectory* subdir = dir->GetDirectory(subname.c_str());
146  if(!subdir) break;
147  delete subdir;
148  bins.push_back(*Binning::LoadFrom(dir, subname));
149  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
150  labels.push_back(label ? label->GetString().Data() : "");
151  delete label;
152  }
153 
154  delete dir;
155 
156  auto ret = std::make_unique<NDOscillatableSpectrum>(kNullLoader,
157  HistAxis(labels, bins),
158  kNoCut);
159 
160  // ROOT histogram storage is row-major, but Eigen is column-major by
161  // default
162  typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen:: Dynamic, Eigen::RowMajor> MatRowMajor;
163  ret->fMat = Eigen::Map<MatRowMajor>(spect->GetArray(),
164  ret->fMat.rows(),
165  ret->fMat.cols());
166 
167  delete spect;
168 
169  ret->fPOT = hPot->Integral(0, -1);
170  ret->fLivetime = hLivetime->Integral(0, -1);
171 
172  delete hPot;
173  delete hLivetime;
174 
175  return ret;
176  }
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir, const std::string &name)
Definition: Binning.cxx:230
const XML_Char * name
Definition: expat.h:151
subdir
Definition: cvnie.py:7
const char * label
const Binning bins
Definition: NumuCC_CPiBin.h:8
TDirectory * dir
Definition: macro.C:5
assert(nhit_max >=nhit_nbins)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
Definition: Style.cxx:154
_HistAxis< Var > HistAxis
Definition: HistAxis.h:10
const Cut kNoCut
Definition: Cut.h:13
static NullLoader kNullLoader
Dummy loader that doesn&#39;t load any files.
enum BeamMode string
unsigned int ana::ReweightableSpectrum::NDimensions ( ) const
inlineinherited

Definition at line 80 of file ReweightableSpectrum.h.

References ana::ReweightableSpectrum::fAxisX, and ana::LabelsAndBins::NDimensions().

80 {return fAxisX.NDimensions();}
unsigned int NDimensions() const
Definition: LabelsAndBins.h:66
ReweightableSpectrum ana::ReweightableSpectrum::operator+ ( const ReweightableSpectrum rhs) const
inherited

Definition at line 240 of file ReweightableSpectrum.cxx.

References runNovaSAM::ret.

Referenced by ana::ReweightableSpectrum::Livetime().

241  {
242  ReweightableSpectrum ret = *this;
243  ret += rhs;
244  return ret;
245  }
ReweightableSpectrum & ana::ReweightableSpectrum::operator+= ( const ReweightableSpectrum rhs)
inherited

Definition at line 234 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::PlusEqualsHelper().

Referenced by ana::ReweightableSpectrum::Livetime(), and ana::OscillatableSpectrum::operator+=().

235  {
236  return PlusEqualsHelper(rhs, +1);
237  }
ReweightableSpectrum & PlusEqualsHelper(const ReweightableSpectrum &rhs, int sign)
ReweightableSpectrum ana::ReweightableSpectrum::operator- ( const ReweightableSpectrum rhs) const
inherited

Definition at line 254 of file ReweightableSpectrum.cxx.

References runNovaSAM::ret.

Referenced by ana::ReweightableSpectrum::Livetime().

255  {
256  ReweightableSpectrum ret = *this;
257  ret -= rhs;
258  return ret;
259  }
ReweightableSpectrum & ana::ReweightableSpectrum::operator-= ( const ReweightableSpectrum rhs)
inherited

Definition at line 248 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::PlusEqualsHelper().

Referenced by ana::ReweightableSpectrum::Livetime(), and ana::OscillatableSpectrum::operator-=().

249  {
250  return PlusEqualsHelper(rhs, -1);
251  }
ReweightableSpectrum & PlusEqualsHelper(const ReweightableSpectrum &rhs, int sign)
NDOscillatableSpectrum & ana::NDOscillatableSpectrum::operator= ( const NDOscillatableSpectrum rhs)

Assignment operator.

Definition at line 81 of file NDOscillatableSpectrum.cxx.

References ana::assert(), ana::ReweightableSpectrum::fReferences, and ana::ReweightableSpectrum::operator=().

Referenced by Uninitialized().

82  {
83  if(this == &rhs) return *this;
84 
86 
87  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
88  assert( fReferences.empty() ); // Copying with pending loads is unexpected
89 
90  return *this;
91  }
std::set< ReweightableSpectrum ** > fReferences
ReweightableSpectrum & operator=(const ReweightableSpectrum &rhs)
assert(nhit_max >=nhit_nbins)
NDOscillatableSpectrum & ana::NDOscillatableSpectrum::operator= ( NDOscillatableSpectrum &&  rhs)

Definition at line 94 of file NDOscillatableSpectrum.cxx.

References ana::assert(), ana::ReweightableSpectrum::fReferences, and ana::ReweightableSpectrum::operator=().

95  {
96  if(this == &rhs) return *this;
97 
99 
100  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
101  assert( fReferences.empty() ); // Copying with pending loads is unexpected
102 
103  return *this;
104  }
std::set< ReweightableSpectrum ** > fReferences
ReweightableSpectrum & operator=(const ReweightableSpectrum &rhs)
assert(nhit_max >=nhit_nbins)
Spectrum ana::NDOscillatableSpectrum::Oscillated ( osc::IOscCalc calc,
int  from,
int  to 
) const

Definition at line 107 of file NDOscillatableSpectrum.cxx.

References ana::ReweightableSpectrum::WeightedBy().

Referenced by ana::NDPredictionSterile::Predict(), ana::NDPredictionSterile::PredictComponent(), and Uninitialized().

109  {
110  const NDOscCurve curve(calc, from, to);
111  return WeightedBy(curve);
112  }
Spectrum WeightedBy(const Ratio &weights) const
Reco spectrum with truth weights applied.
ReweightableSpectrum & ana::ReweightableSpectrum::PlusEqualsHelper ( const ReweightableSpectrum rhs,
int  sign 
)
protectedinherited

Definition at line 163 of file ReweightableSpectrum.cxx.

References ana::AlmostEqual(), om::cout, allTimeWatchdog::endl, ana::ReweightableSpectrum::fLivetime, ana::ReweightableSpectrum::fMat, and ana::ReweightableSpectrum::fPOT.

Referenced by ana::ReweightableSpectrum::operator+=(), ana::ReweightableSpectrum::operator-=(), and ana::ReweightableSpectrum::ReweightableSpectrum().

164  {
165  // In this case it would be OK to have no POT/livetime
166  if(rhs.fMat.sum() == 0) return *this;
167 
168 
169  if((!fPOT && !fLivetime) || (!rhs.fPOT && !rhs.fLivetime)){
170  std::cout << "Error: can't sum ReweightableSpectrum with no POT or livetime."
171  << fPOT << " " << rhs.fPOT
172  << std::endl;
173  // abort();
174  return *this;
175  }
176 
177  if(!fLivetime && !rhs.fPOT){
178  std::cout << "Error: can't sum ReweightableSpectrum with POT ("
179  << fPOT << ") but no livetime and ReweightableSpectrum with livetime ("
180  << rhs.fLivetime << " sec) but no POT." << std::endl;
181  abort();
182  }
183 
184  if(!fPOT && !rhs.fLivetime){
185  std::cout << "Error: can't sum ReweightableSpectrum with livetime ("
186  << fLivetime << " sec) but no POT and ReweightableSpectrum with POT ("
187  << rhs.fPOT << ") but no livetime." << std::endl;
188  abort();
189  }
190 
191  // And now there are still a bunch of good cases to consider
192 
193  if(fPOT && rhs.fPOT){
194  // Scale by POT when possible
195  fMat += rhs.fMat * sign*fPOT/rhs.fPOT;
196 
197  if(fLivetime && rhs.fLivetime){
198  // If POT/livetime ratios match, keep regular lifetime, otherwise zero
199  // it out.
200  if(AlmostEqual(fLivetime*rhs.fPOT, rhs.fLivetime*fPOT))
201  fLivetime = 0;
202  }
203  if(!fLivetime && rhs.fLivetime){
204  // If the RHS has a livetime and we don't, copy it in (suitably scaled)
205  fLivetime = rhs.fLivetime * fPOT/rhs.fPOT;
206  }
207  // Otherwise, keep our own livetime (if any)
208 
209  return *this;
210  }
211 
212  if(fLivetime && rhs.fLivetime){
213  // Scale by livetime, the only thing in common
214  fMat += rhs.fMat * sign*fLivetime/rhs.fLivetime;
215 
216  if(!fPOT && rhs.fPOT){
217  // If the RHS has a POT and we don't, copy it in (suitably scaled)
218  fPOT = rhs.fPOT * fLivetime/rhs.fLivetime;
219  }
220  // Otherwise, keep our own POT (if any)
221 
222  return *this;
223  }
224 
225  // That should have been all the cases. I definitely want to know what
226  // happened if it wasn't.
227  std::cout << "ReweightableSpectrum::operator+=(). How did we get here? "
228  << fPOT << " " << fLivetime << " "
229  << rhs.fPOT << " " << rhs.fLivetime << std::endl;
230  abort();
231  }
bool AlmostEqual(double a, double b, double eps)
Definition: UtilsExt.cxx:40
OStream cout
Definition: OStream.cxx:6
def sign(x)
Definition: canMan.py:197
double ana::ReweightableSpectrum::POT ( ) const
inlineinherited
void ana::ReweightableSpectrum::RemoveLoader ( ReweightableSpectrum **  ref)
protectedinherited

Definition at line 268 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fReferences.

Referenced by ana::ReweightableSpectrum::ReweightableSpectrum().

269  {
270  fReferences.erase(ref);
271  }
std::set< ReweightableSpectrum ** > fReferences
void ana::ReweightableSpectrum::ReweightToRecoSpectrum ( const Spectrum target)
inherited

Recale bins so that Unweighted will return target.

Definition at line 152 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fMat, ana::Ratio::GetEigen(), PandAna.reco_validation.prod5_pid_validation::ratio(), and ana::ReweightableSpectrum::UnWeighted().

Referenced by ana::FluxReweight::Eval(), ana::TruthReweight::Eval(), ana::RecoReweight::Eval(), ana::PredictionExtendToPeripheral::ExtendRecoWeightOscillatable(), ana::ReweightableSpectrum::Livetime(), ana::TruthReweight::SavePlots(), ana::UnfoldIterative::Truth(), and ana::OscillatableSpectrum::Uninitialized().

153  {
154  // This is a big component of what extrapolations do, so it should be fast
155 
156  const Ratio ratio(target, UnWeighted());
157  // We want to multiply all the columns by this ratio
158 
159  fMat *= ratio.GetEigen().matrix().asDiagonal();
160  }
const XML_Char * target
Definition: expat.h:268
def ratio(spec1, spec2, nbins, pot, binrange=(0, 1))
void ana::ReweightableSpectrum::ReweightToTrueSpectrum ( const Spectrum target)
inherited

Rescale bins so that WeightingVariable will return target.

Definition at line 141 of file ReweightableSpectrum.cxx.

References ana::ReweightableSpectrum::fMat, ana::Ratio::GetEigen(), PandAna.reco_validation.prod5_pid_validation::ratio(), and ana::ReweightableSpectrum::WeightingVariable().

Referenced by ana::TruthReweight::Eval(), ana::ReweightableSpectrum::Livetime(), ana::UnfoldIterative::Truth(), and ana::OscillatableSpectrum::Uninitialized().

142  {
143  // This is a big component of what extrapolations do, so it should be fast
144 
145  const Ratio ratio(target, WeightingVariable());
146  // We want to multiply all the rows by this ratio, so left-multiply
147 
148  fMat = ratio.GetEigen().matrix().asDiagonal() * fMat;
149  }
const XML_Char * target
Definition: expat.h:268
def ratio(spec1, spec2, nbins, pot, binrange=(0, 1))
void ana::NDOscillatableSpectrum::SaveTo ( TDirectory *  dir,
const std::string name 
) const

Definition at line 115 of file NDOscillatableSpectrum.cxx.

References ana::ReweightableSpectrum::_SaveTo().

Referenced by Scale().

116  {
117  _SaveTo(dir, name, "NDOscillatableSpectrum");
118  }
const XML_Char * name
Definition: expat.h:151
void _SaveTo(TDirectory *dir, const std::string &name, const std::string &type) const
TDirectory * dir
Definition: macro.C:5
void ana::NDOscillatableSpectrum::Scale ( double  x)
inline
TH2D * ana::ReweightableSpectrum::ToTH2 ( double  pot) const
inherited

Definition at line 66 of file ReweightableSpectrum.cxx.

References ana::assert(), ana::ReweightableSpectrum::fAxisX, ana::ReweightableSpectrum::fAxisY, ana::ReweightableSpectrum::fMat, ana::ReweightableSpectrum::fPOT, ana::LabelsAndBins::GetBins1D(), ana::LabelsAndBins::GetLabel1D(), MECModelEnuComparisons::i, calib::j, ana::MakeTH2D(), runNovaSAM::ret, and ana::UniqueName().

Referenced by ana::ReweightableSpectrum::_SaveTo(), demo2(), demo3(), ana::MichelDecomp::GetSum(), ana::MichelDecomp::GetTemplateContent(), ana::MichelDecomp::MDCMPLogLikelihood(), ana::PlotAllRecoTrue(), ana::CrossSectionAnalysis::PlotRecoToTrueMatrix(), ana::SingleNucAnalysis::PlotRecoToTrueMatrix2D(), ana::NumuCC2p2hAnalysis::PlotRecoToTrueMatrix2D(), ana::MichelDecomp::SaveTempPlots(), ana::UnfoldSVD::Truth(), Unfold1D(), Unfold3D(), ana::UnfoldTikhonov::UnfoldTikhonov(), ana::ReweightableSpectrum::Uninitialized(), and ana::OscillatableSpectrum::Uninitialized().

67  {
68  // Could have a file temporarily open
69  DontAddDirectory guard;
70 
71  TH2D* ret = MakeTH2D(UniqueName().c_str(), "", fAxisX.GetBins1D(), fAxisY.GetBins1D());
72 
73  for(int i = 0; i < fMat.rows(); ++i){
74  for(int j = 0; j < fMat.cols(); ++j){
75  ret->SetBinContent(j, i, fMat(i, j));
76  }
77  }
78 
79  if(fPOT){
80  ret->Scale(pot/fPOT);
81  }
82  else{
83  // How did it get events with no POT?
84  assert(ret->Integral() == 0);
85  }
86 
87  ret->GetXaxis()->SetTitle(fAxisX.GetLabel1D().c_str());
88  ret->GetYaxis()->SetTitle(fAxisY.GetLabel1D().c_str());
89 
90  return ret;
91  }
const std::string & GetLabel1D() const
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
#define pot
const double j
Definition: BetheBloch.cxx:29
TH2D * MakeTH2D(const char *name, const char *title, const Binning &binsx, const Binning &binsy)
Utility function to avoid 4-way combinatorial explosion on the bin types.
Definition: UtilsExt.cxx:86
assert(nhit_max >=nhit_nbins)
std::string UniqueName()
Return a different string each time, for creating histograms.
Definition: Utilities.cxx:28
static NDOscillatableSpectrum ana::NDOscillatableSpectrum::Uninitialized ( )
inlinestatic

The only valid thing to do with such a spectrum is to assign something else into it.

Definition at line 48 of file NDOscillatableSpectrum.h.

References calc, NDOscillatableSpectrum(), operator=(), Oscillated(), and ~NDOscillatableSpectrum().

48 {return NDOscillatableSpectrum();}
NDOscillatableSpectrum()
Constructor for Uninitialized()
Spectrum ana::ReweightableSpectrum::UnWeighted ( ) const
inherited
Spectrum ana::ReweightableSpectrum::WeightedBy ( const Ratio weights) const
inherited

Reco spectrum with truth weights applied.

Definition at line 124 of file ReweightableSpectrum.cxx.

References ana::Hist::Adopt(), ana::Hist::AdoptStan(), ana::ReweightableSpectrum::fAxisX, ana::ReweightableSpectrum::fLivetime, ana::ReweightableSpectrum::fMat, ana::ReweightableSpectrum::fPOT, ana::Ratio::GetEigen(), ana::Ratio::GetEigenStan(), and ana::Ratio::HasStan().

Referenced by ana::OscillatableSpectrum::_Oscillated(), ana::ReweightableSpectrum::Livetime(), and Oscillated().

125  {
126  if(!ws.HasStan()){
127  const Eigen::VectorXd& vec = ws.GetEigen();
128 
129  return Spectrum(Hist::Adopt(Eigen::ArrayXd(vec.transpose() * fMat)),
130  fAxisX, fPOT, fLivetime);
131  }
132  else{
133  const Eigen::VectorXstan& vec = ws.GetEigenStan();
134 
135  return Spectrum(Hist::AdoptStan(vec.transpose() * fMat),
136  fAxisX, fPOT, fLivetime);
137  }
138  }
Eigen::Matrix< stan::math::var, Eigen::Dynamic, 1 > VectorXstan
Definition: Hist.h:14
std::vector< double > Spectrum
Definition: Constants.h:746
static Hist AdoptStan(Eigen::ArrayXstan &&v)
Definition: Hist.cxx:140
static Hist Adopt(Eigen::ArrayXd &&v)
Definition: Hist.cxx:149
Spectrum ana::ReweightableSpectrum::WeightingVariable ( ) const
inherited

Friends And Related Function Documentation

friend class NullLoader
friend

Definition at line 30 of file NDOscillatableSpectrum.h.

friend class SpectrumLoader
friend

Definition at line 29 of file NDOscillatableSpectrum.h.

friend class SpectrumLoaderBase
friend

Definition at line 28 of file NDOscillatableSpectrum.h.

Member Data Documentation

LabelsAndBins ana::ReweightableSpectrum::fAxisX
protectedinherited
LabelsAndBins ana::ReweightableSpectrum::fAxisY
protectedinherited
double ana::ReweightableSpectrum::fLivetime
protectedinherited
Eigen::MatrixXd ana::ReweightableSpectrum::fMat
protectedinherited
double ana::ReweightableSpectrum::fPOT
protectedinherited
std::set<ReweightableSpectrum**> ana::ReweightableSpectrum::fReferences
protectedinherited

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