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

Spectrum with the value of a second variable, allowing for reweighting More...

#include "/cvmfs/nova.opensciencegrid.org/externals/cafanacore/v01.11/src/CAFAna/Core/ReweightableSpectrum.h"

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

Public Member Functions

template<class T >
 ReweightableSpectrum (SpectrumLoaderBase &loader, const _HistAxis< _Var< T >> &recoAxis, const _HistAxis< _Var< T >> &trueAxis, const _Cut< T > &cut, const SystShifts &shift=kNoShift, const _Var< T > &wei=Unweighted< T >())
 
 ReweightableSpectrum (const Eigen::MatrixXd &&mat, const LabelsAndBins &recoAxis, const LabelsAndBins &trueAxis, double pot, double livetime)
 
virtual ~ReweightableSpectrum ()
 
 ReweightableSpectrum (const ReweightableSpectrum &rhs)
 
ReweightableSpectrumoperator= (const ReweightableSpectrum &rhs)
 
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 ()
 
void SaveTo (TDirectory *dir, const std::string &name) const
 
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 ReweightableSpectrum Uninitialized ()
 
static std::unique_ptr< ReweightableSpectrumLoadFrom (TDirectory *dir, const std::string &name)
 

Protected Member Functions

 ReweightableSpectrum (const LabelsAndBins &axisX, const LabelsAndBins &axisY)
 
 ReweightableSpectrum ()
 
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 ReweightableSpectrumSink
 
class SpectrumSinkBase< ReweightableSpectrum >
 

Detailed Description

Spectrum with the value of a second variable, allowing for reweighting

Definition at line 19 of file ReweightableSpectrum.h.

Constructor & Destructor Documentation

template<class T >
ana::ReweightableSpectrum::ReweightableSpectrum ( SpectrumLoaderBase loader,
const _HistAxis< _Var< T >> &  recoAxis,
const _HistAxis< _Var< T >> &  trueAxis,
const _Cut< T > &  cut,
const SystShifts shift = kNoShift,
const _Var< T > &  wei = UnweightedT >() 
)
ana::ReweightableSpectrum::ReweightableSpectrum ( const Eigen::MatrixXd &&  mat,
const LabelsAndBins recoAxis,
const LabelsAndBins trueAxis,
double  pot,
double  livetime 
)

Definition at line 17 of file ReweightableSpectrum.cxx.

22  fAxisX(recoAxis), fAxisY(trueAxis)
23  {
24  }
#define pot
double livetime
Definition: saveFDMCHists.C:21
Eigen::MatrixXd mat
ana::ReweightableSpectrum::~ReweightableSpectrum ( )
virtual

Definition at line 27 of file ReweightableSpectrum.cxx.

References fReferences.

Referenced by Uninitialized().

28  {
29  for(ReweightableSpectrum** ref: fReferences) *ref = 0;
30  }
std::set< ReweightableSpectrum ** > fReferences
ana::ReweightableSpectrum::ReweightableSpectrum ( const ReweightableSpectrum rhs)

Definition at line 33 of file ReweightableSpectrum.cxx.

References ana::assert(), fLivetime, fMat, fPOT, and fReferences.

34  : fAxisX(rhs.fAxisX), fAxisY(rhs.fAxisY)
35  {
36  DontAddDirectory guard;
37 
38  fMat = rhs.fMat;
39  fPOT = rhs.fPOT;
40  fLivetime = rhs.fLivetime;
41 
42  assert( rhs.fReferences.empty() ); // Copying with pending loads is unexpected
43  }
assert(nhit_max >=nhit_nbins)
ana::ReweightableSpectrum::ReweightableSpectrum ( const LabelsAndBins axisX,
const LabelsAndBins axisY 
)
inlineprotected

Definition at line 89 of file ReweightableSpectrum.h.

ana::ReweightableSpectrum::ReweightableSpectrum ( )
inlineprotected

Definition at line 97 of file ReweightableSpectrum.h.

References _SaveTo(), AddLoader(), PlusEqualsHelper(), RemoveLoader(), canMan::sign(), and string.

Referenced by Uninitialized().

98  : fPOT(0), fLivetime(0),
99  fAxisX(std::vector<std::string>(), std::vector<Binning>()),
100  fAxisY(std::vector<std::string>(), std::vector<Binning>())
101  {
102  }

Member Function Documentation

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

Definition at line 285 of file ReweightableSpectrum.cxx.

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

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

288  {
289  TDirectory* tmp = gDirectory;
290 
291  dir = dir->mkdir(name.c_str()); // switch to sbudir
292  dir->cd();
293 
294  TObjString(type.c_str()).Write("type");
295 
296  TH2* h = ToTH2(fPOT);
297  h->Write("hist");
298 
299  TH1D hPot("", "", 1, 0, 1);
300  hPot.Fill(.5, fPOT);
301  hPot.Write("pot");
302  TH1D hLivetime("", "", 1, 0, 1);
303  hLivetime.Fill(.5, fLivetime);
304  hLivetime.Write("livetime");
305 
306  for(unsigned int i = 0; i < fAxisX.NDimensions(); ++i){
307  TObjString(fAxisX.GetLabels()[i].c_str()).Write(TString::Format("label%d", i).Data());
308  fAxisX.GetBinnings()[i].SaveTo(dir, TString::Format("bins%d", i).Data());
309  }
310 
311  for(unsigned int i = 0; i < fAxisY.NDimensions(); ++i){
312  TObjString(fAxisY.GetLabels()[i].c_str()).Write(TString::Format("labely%d", i).Data());
313  fAxisY.GetBinnings()[i].SaveTo(dir, TString::Format("binsy%d", i).Data());
314  }
315 
316  dir->Write();
317  delete dir;
318 
319  delete h;
320 
321  tmp->cd();
322  }
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)
protected

Definition at line 273 of file ReweightableSpectrum.cxx.

References fReferences.

Referenced by ReweightableSpectrum().

274  {
275  fReferences.insert(ref);
276  }
std::set< ReweightableSpectrum ** > fReferences
void ana::ReweightableSpectrum::Clear ( void  )

Definition at line 261 of file ReweightableSpectrum.cxx.

References fMat.

Referenced by ana::PredictionExtrapSum::ComponentCC(), Livetime(), and ana::OscillatableSpectrum::Uninitialized().

262  {
263  fMat.setZero();
264  }
void ana::ReweightableSpectrum::Fill ( double  x,
double  y,
double  w = 1 
)

Definition at line 93 of file ReweightableSpectrum.cxx.

References fAxisX, fAxisY, ana::Binning::FindBin(), fMat, and ana::LabelsAndBins::GetBins1D().

Referenced by Uninitialized(), and ana::OscillatableSpectrum::Uninitialized().

94  {
96  }
int FindBin(double x) const
Definition: Binning.cxx:155
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
Float_t w
Definition: plot.C:20
const std::vector<Binning>& ana::ReweightableSpectrum::GetBinnings ( ) const
inline
Eigen::MatrixXd ana::ReweightableSpectrum::GetEigen ( double  pot) const
inline
const std::vector<std::string>& ana::ReweightableSpectrum::GetLabels ( ) const
inline
const std::vector<Binning>& ana::ReweightableSpectrum::GetTrueBinnings ( ) const
inline

Definition at line 84 of file ReweightableSpectrum.h.

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

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

Definition at line 325 of file ReweightableSpectrum.cxx.

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

Referenced by Livetime(), ana::CrossSectionSpectra::LoadFrom(), Unfold1D(), and Unfold3D().

326  {
327  dir = dir->GetDirectory(name.c_str()); // switch to subdir
328  assert(dir);
329 
330  TObjString* tag = (TObjString*)dir->Get("type");
331  assert(tag);
332  assert(tag->GetString() == "ReweightableSpectrum");
333  delete tag;
334 
335  TH2D* spect = (TH2D*)dir->Get("hist");
336  assert(spect);
337  TH1* hPot = (TH1*)dir->Get("pot");
338  assert(hPot);
339  TH1* hLivetime = (TH1*)dir->Get("livetime");
340  assert(hLivetime);
341 
342  std::vector<std::string> labels, labelsy;
343  std::vector<Binning> bins, binsy;
344 
345  for(int i = 0; ; ++i){
346  const std::string subname = TString::Format("bins%d", i).Data();
347  TDirectory* subdir = dir->GetDirectory(subname.c_str());
348  if(!subdir) break;
349  delete subdir;
350  bins.push_back(*Binning::LoadFrom(dir, subname.c_str()));
351  TObjString* label = (TObjString*)dir->Get(TString::Format("label%d", i));
352  labels.push_back(label ? label->GetString().Data() : "");
353  }
354 
355  for(int i = 0; ; ++i){
356  const std::string subname = TString::Format("binsy%d", i).Data();
357  TDirectory* subdir = dir->GetDirectory(subname.c_str());
358  if(!subdir) break;
359  delete subdir;
360  binsy.push_back(*Binning::LoadFrom(dir, subname.c_str()));
361  TObjString* labely = (TObjString*)dir->Get(TString::Format("labely%d", i));
362  labelsy.push_back(labely ? labely->GetString().Data() : "");
363  }
364 
365  // Backwards compatibility
366  if(labelsy.empty()) labelsy.push_back(spect->GetYaxis()->GetTitle());
367  if(binsy.empty()) binsy.push_back(Binning::FromTAxis(spect->GetYaxis()));
368 
369  const LabelsAndBins xax(labels, bins);
370  const LabelsAndBins yax(labelsy, binsy);
371 
372  // ROOT histogram storage is row-major, but Eigen is column-major by
373  // default
374  typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen:: Dynamic, Eigen::RowMajor> MatRowMajor;
375  auto ret = std::make_unique<ReweightableSpectrum>(
376  Eigen::Map<MatRowMajor>(spect->GetArray(),
377  yax.GetBins1D().NBins()+2,
378  xax.GetBins1D().NBins()+2),
379  xax, yax, hPot->Integral(0, -1), hLivetime->Integral(0, -1));
380 
381  delete spect;
382 
383  delete hPot;
384  delete hLivetime;
385 
386  delete dir;
387 
388  return ret;
389  }
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
static Binning FromTAxis(const TAxis *ax)
Definition: Binning.cxx:173
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
enum BeamMode string
unsigned int ana::ReweightableSpectrum::NDimensions ( ) const
inline

Definition at line 81 of file ReweightableSpectrum.h.

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

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

Definition at line 239 of file ReweightableSpectrum.cxx.

References runNovaSAM::ret.

Referenced by Livetime().

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

Definition at line 233 of file ReweightableSpectrum.cxx.

References PlusEqualsHelper().

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

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

Definition at line 253 of file ReweightableSpectrum.cxx.

References runNovaSAM::ret.

Referenced by Livetime().

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

Definition at line 247 of file ReweightableSpectrum.cxx.

References PlusEqualsHelper().

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

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

Definition at line 46 of file ReweightableSpectrum.cxx.

References ana::assert(), fAxisX, fAxisY, fLivetime, fMat, fPOT, and fReferences.

Referenced by ana::NDOscillatableSpectrum::operator=(), ana::OscillatableSpectrum::operator=(), and Uninitialized().

47  {
48  if(this == &rhs) return *this;
49 
50  DontAddDirectory guard;
51 
52  fAxisX = rhs.fAxisX;
53  fAxisY = rhs.fAxisY;
54 
55  fMat = rhs.fMat;
56  fPOT = rhs.fPOT;
57  fLivetime = rhs.fLivetime;
58 
59  assert( fReferences.empty() ); // Copying with pending loads is unexpected
60 
61  return *this;
62  }
std::set< ReweightableSpectrum ** > fReferences
assert(nhit_max >=nhit_nbins)
ReweightableSpectrum & ana::ReweightableSpectrum::PlusEqualsHelper ( const ReweightableSpectrum rhs,
int  sign 
)
protected

Definition at line 162 of file ReweightableSpectrum.cxx.

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

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

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

Definition at line 267 of file ReweightableSpectrum.cxx.

References fReferences.

Referenced by ReweightableSpectrum().

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

Recale bins so that Unweighted will return target.

Definition at line 151 of file ReweightableSpectrum.cxx.

References fMat, ana::Ratio::GetEigen(), ratio(), and UnWeighted().

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

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

Rescale bins so that WeightingVariable will return target.

Definition at line 140 of file ReweightableSpectrum.cxx.

References fMat, ana::Ratio::GetEigen(), ratio(), and WeightingVariable().

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

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

Definition at line 279 of file ReweightableSpectrum.cxx.

References _SaveTo().

Referenced by Livetime(), ana::CrossSectionSpectra::SaveTo(), ana::CrossSectionAnalysis::SaveTo(), ana::NumuCCIncAnalysis::SaveTo(), and ana::MichelDecomp::SaveTo().

280  {
281  _SaveTo(dir, name, "ReweightableSpectrum");
282  }
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
TH2D * ana::ReweightableSpectrum::ToTH2 ( double  pot) const

Definition at line 65 of file ReweightableSpectrum.cxx.

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

Referenced by _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(), Uninitialized(), and ana::OscillatableSpectrum::Uninitialized().

66  {
67  // Could have a file temporarily open
68  DontAddDirectory guard;
69 
70  TH2D* ret = MakeTH2D(UniqueName().c_str(), "", fAxisX.GetBins1D(), fAxisY.GetBins1D());
71 
72  for(int i = 0; i < fMat.rows(); ++i){
73  for(int j = 0; j < fMat.cols(); ++j){
74  ret->SetBinContent(j, i, fMat(i, j));
75  }
76  }
77 
78  if(fPOT){
79  ret->Scale(pot/fPOT);
80  }
81  else{
82  // How did it get events with no POT?
83  assert(ret->Integral() == 0);
84  }
85 
86  ret->GetXaxis()->SetTitle(fAxisX.GetLabel1D().c_str());
87  ret->GetYaxis()->SetTitle(fAxisY.GetLabel1D().c_str());
88 
89  return ret;
90  }
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:29
static ReweightableSpectrum ana::ReweightableSpectrum::Uninitialized ( )
inlinestatic

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

Definition at line 40 of file ReweightableSpectrum.h.

References Fill(), operator=(), pot, ReweightableSpectrum(), ToTH2(), w, submit_syst::x, submit_syst::y, and ~ReweightableSpectrum().

Spectrum ana::ReweightableSpectrum::UnWeighted ( ) const

Definition at line 111 of file ReweightableSpectrum.cxx.

References ana::Hist::Adopt(), fAxisX, fLivetime, fMat, fPOT, and ana::ProjectionX().

Referenced by Livetime(), ReweightToRecoSpectrum(), and ana::UnfoldSVD::Truth().

112  {
114  }
Eigen::ArrayXd ProjectionX(const Eigen::MatrixXd &mat)
Helper for Unweighted.
std::vector< float > Spectrum
Definition: Constants.h:610
static Hist Adopt(Eigen::ArrayXd &&v)
Definition: Hist.cxx:149
Spectrum ana::ReweightableSpectrum::WeightedBy ( const Ratio weights) const

Reco spectrum with truth weights applied.

Definition at line 123 of file ReweightableSpectrum.cxx.

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

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

124  {
125  if(!ws.HasStan()){
126  const Eigen::VectorXd& vec = ws.GetEigen();
127 
128  return Spectrum(Hist::Adopt(Eigen::ArrayXd(vec.transpose() * fMat)),
129  fAxisX, fPOT, fLivetime);
130  }
131  else{
132  const Eigen::VectorXstan& vec = ws.GetEigenStan();
133 
134  return Spectrum(Hist::AdoptStan(vec.transpose() * fMat),
135  fAxisX, fPOT, fLivetime);
136  }
137  }
Eigen::Matrix< stan::math::var, Eigen::Dynamic, 1 > VectorXstan
Definition: Hist.h:22
Eigen::VectorXd vec
std::vector< float > Spectrum
Definition: Constants.h:610
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

Definition at line 117 of file ReweightableSpectrum.cxx.

References ana::Hist::Adopt(), fAxisY, fLivetime, fMat, fPOT, and ana::ProjectionY().

Referenced by Livetime(), ReweightToTrueSpectrum(), ana::UnfoldIterative::Truth(), and ana::UnfoldSVD::Truth().

118  {
120  }
std::vector< float > Spectrum
Definition: Constants.h:610
Eigen::ArrayXd ProjectionY(const Eigen::MatrixXd &mat)
Helper for WeightingVariable.
static Hist Adopt(Eigen::ArrayXd &&v)
Definition: Hist.cxx:149

Friends And Related Function Documentation

friend class ReweightableSpectrumSink
friend

Definition at line 22 of file ReweightableSpectrum.h.

friend class SpectrumSinkBase< ReweightableSpectrum >
friend

Definition at line 23 of file ReweightableSpectrum.h.

Member Data Documentation

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

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