3 #include "CAFAna/Core/Binning.h" 7 #include "TDirectory.h" 9 #include "TObjString.h" 23 fAxisX(recoAxis), fAxisY(trueAxis)
49 if(
this == &rhs)
return *
this;
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));
84 assert(ret->Integral() == 0);
102 return Eigen::RowVectorXd::Ones(mat.rows()) * mat;
108 return mat * Eigen::VectorXd::Ones(mat.cols());
127 const Eigen::VectorXd& vec = ws.
GetEigen();
166 if(rhs.
fMat.sum() == 0)
return *
this;
170 std::cout <<
"Error: can't sum ReweightableSpectrum with no POT or livetime." 178 std::cout <<
"Error: can't sum ReweightableSpectrum with POT (" 179 <<
fPOT <<
") but no livetime and ReweightableSpectrum with livetime (" 185 std::cout <<
"Error: can't sum ReweightableSpectrum with livetime (" 186 <<
fLivetime <<
" sec) but no POT and ReweightableSpectrum with POT (" 227 std::cout <<
"ReweightableSpectrum::operator+=(). How did we get here? " 282 _SaveTo(dir, name,
"ReweightableSpectrum");
290 TDirectory*
tmp = gDirectory;
292 dir = dir->mkdir(name.c_str());
295 TObjString(type.c_str()).
Write(
"type");
300 TH1D hPot(
"",
"", 1, 0, 1);
303 TH1D hLivetime(
"",
"", 1, 0, 1);
305 hLivetime.Write(
"livetime");
328 dir = dir->GetDirectory(name.c_str());
331 TObjString*
tag = (TObjString*)dir->Get(
"type");
333 assert(tag->GetString() ==
"ReweightableSpectrum");
336 TH2D* spect = (TH2D*)dir->Get(
"hist");
338 TH1* hPot = (TH1*)dir->Get(
"pot");
340 TH1* hLivetime = (TH1*)dir->Get(
"livetime");
343 std::vector<std::string>
labels, labelsy;
344 std::vector<Binning>
bins, binsy;
346 for(
int i = 0; ; ++
i){
348 TDirectory*
subdir = dir->GetDirectory(subname.c_str());
353 labels.push_back(label ? label->GetString().Data() :
"");
356 for(
int i = 0; ; ++
i){
358 TDirectory*
subdir = dir->GetDirectory(subname.c_str());
363 labelsy.push_back(labely ? labely->GetString().Data() :
"");
367 if(labelsy.empty()) labelsy.push_back(spect->GetYaxis()->GetTitle());
375 typedef Eigen::Matrix<double, Eigen::Dynamic, Eigen:: Dynamic, Eigen::RowMajor> MatRowMajor;
376 auto ret = std::make_unique<ReweightableSpectrum>(
377 Eigen::Map<MatRowMajor>(spect->GetArray(),
380 xax, yax, hPot->Integral(0, -1), hLivetime->Integral(0, -1));
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir, const std::string &name)
ReweightableSpectrum & operator+=(const ReweightableSpectrum &rhs)
Spectrum UnWeighted() const
Cuts and Vars for the 2020 FD DiF Study.
const Eigen::ArrayXd & GetEigen() const
Eigen::ArrayXd ProjectionX(const Eigen::MatrixXd &mat)
Helper for Unweighted.
const SpillVar fPOT([](const caf::SRSpillProxy *spill){return spill->spillpot;})
void Fill(double x, double y, double w=1)
virtual ~ReweightableSpectrum()
static Binning FromTAxis(const TAxis *ax)
int FindBin(double x) const
Eigen::Matrix< stan::math::var, Eigen::Dynamic, 1 > VectorXstan
Spectrum with the value of a second variable, allowing for reweighting
std::vector< double > Spectrum
static std::unique_ptr< ReweightableSpectrum > LoadFrom(TDirectory *dir, const std::string &name)
void ReweightToRecoSpectrum(const Spectrum &target)
Recale bins so that Unweighted will return target.
def ratio(spec1, spec2, nbins, pot, binrange=(0, 1))
ReweightableSpectrum operator-(const ReweightableSpectrum &rhs) const
Representation of a spectrum in any variable, with associated POT.
void RemoveLoader(ReweightableSpectrum **)
const std::string & GetLabel1D() const
bool AlmostEqual(double a, double b, double eps)
ReweightableSpectrum & operator-=(const ReweightableSpectrum &rhs)
const Binning & GetBins1D() const
Appropriate binning and labelling for that 1D Var.
Spectrum WeightedBy(const Ratio &weights) const
Reco spectrum with truth weights applied.
const Eigen::ArrayXstan & GetEigenStan() const
Represent the ratio between two spectra.
ReweightableSpectrum operator+(const ReweightableSpectrum &rhs) const
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.
const std::vector< Binning > & GetBinnings() const
std::set< ReweightableSpectrum ** > fReferences
unsigned int NDimensions() const
static Hist AdoptStan(Eigen::ArrayXstan &&v)
void _SaveTo(TDirectory *dir, const std::string &name, const std::string &type) const
ReweightableSpectrum & PlusEqualsHelper(const ReweightableSpectrum &rhs, int sign)
ReweightableSpectrum & operator=(const ReweightableSpectrum &rhs)
Eigen::ArrayXd ProjectionY(const Eigen::MatrixXd &mat)
Helper for WeightingVariable.
void SaveTo(TDirectory *dir, const std::string &name) const
static Hist Adopt(Eigen::ArrayXd &&v)
void AddLoader(ReweightableSpectrum **)
assert(nhit_max >=nhit_nbins)
void Format(TGraph *gr, int lcol, int lsty, int lwid, int mcol, int msty, double msiz)
void ReweightToTrueSpectrum(const Spectrum &target)
Rescale bins so that WeightingVariable will return target.
Prevent histograms being added to the current directory.
std::string UniqueName()
Return a different string each time, for creating histograms.
const std::vector< std::string > & GetLabels() const
Spectrum WeightingVariable() const
TH2D * ToTH2(double pot) const