10 #include "TDirectory.h"
12 #include "TObjString.h"
40 trueAxis.GetVars()[0])
65 fHist =
new TH2D(name.c_str(),
"",
70 fHist =
new TH2D(name.c_str(),
"",
75 fHist =
new TH2D(name.c_str(),
"",
80 fHist =
new TH2D(name.c_str(),
"",
89 const std::string& xlabel,
const std::string& ylabel,
91 int nbinsx,
double xmin,
double xmax,
92 int nbinsy,
double ymin,
double ymax)
94 Binning::Simple(nbinsx, xmin, xmax),
100 nbinsx, xmin, xmax, nbinsy, ymin, ymax);
110 const std::vector<std::string>&
labels,
111 const std::vector<Binning>& bins,
112 double pot,
double livetime)
125 const TString className = h->ClassName();
127 if(className ==
"TH2D"){
129 fHist =
new TH2D(*((TH2D*)h));
132 const TAxis* ax = h->GetXaxis();
133 const TAxis* ay = h->GetYaxis();
135 assert(
bool(ax->GetXbins()->GetArray()) ==
bool(ay->GetXbins()->GetArray()));
137 if(ax->GetXbins()->GetArray()){
139 ax->GetNbins(), ax->GetXbins()->GetArray(),
140 ay->GetNbins(), ay->GetXbins()->GetArray());
144 ax->GetNbins(), ax->GetXmin(), ax->GetXmax(),
145 ay->GetNbins(), ay->GetXmin(), ay->GetXmax());
156 std::unique_ptr<TH2D>
h,
157 const std::vector<std::string>&
labels,
158 const std::vector<Binning>& bins,
159 double pot,
double livetime)
173 static bool once =
true;
176 std::cerr <<
"ReweightableSpectrum's fHist is associated with a directory. How did that happen?" << std::endl;
189 : fRWVar(rhs.fRWVar), fLabels(rhs.fLabels),
fBins(rhs.
fBins)
204 if(
this == &rhs)
return *
this;
228 TH2D* ret =
new TH2D(*
fHist);
231 ret->Scale(pot/
fPOT);
235 assert(ret->Integral() == 0);
240 for(
const std::string& l:
fLabels) label += l +
" and ";
241 label.resize(label.size()-5);
242 ret->GetXaxis()->SetTitle(label.c_str());
243 ret->GetYaxis()->SetTitle(
fTrueLabel.c_str());
251 fHist->Fill(x, y, w);
257 const int Nx = from->GetNbinsX();
258 const int Ny = from->GetNbinsY();
261 double* fromArr = from->GetArray();
262 double* toArr = to->GetArray();
265 for(
int y = 0;
y < Ny+2; ++
y){
266 for(
int x = 0;
x < Nx+2; ++
x){
272 const double z = fromArr[fromBin];
296 const int Nx = from->GetNbinsX();
297 const int Ny = from->GetNbinsY();
300 double* fromArr = from->GetArray();
301 double* toArr = to->GetArray();
304 for(
int y = 0;
y < Ny+2; ++
y){
305 for(
int x = 0;
x < Nx+2; ++
x){
311 const double z = fromArr[fromBin];
340 assert(ws->GetNbinsX() ==
fHist->GetNbinsY());
342 TAxis* ax =
fHist->GetXaxis();
345 const int X =
fHist->GetNbinsX();
346 const int Y =
fHist->GetNbinsY();
349 double* retArr = hRet->GetArray();
350 double* histArr =
fHist->GetArray();
353 for(
int y = 0;
y < Y+2; ++
y){
354 const double w = ws->GetBinContent(
y);
355 for(
int x = 0;
x < X+2; ++
x){
362 retArr[
x] += histArr[
bin]*
w;
379 std::unique_ptr<TH1D> hcorr(corr.
ToTH1());
381 assert(hcorr->GetNbinsX() ==
fHist->GetNbinsY());
383 const int X =
fHist->GetNbinsX();
384 const int Y =
fHist->GetNbinsY();
387 double* histArr =
fHist->GetArray();
388 double* corrArr = hcorr->GetArray();
391 for(
int y = 0;
y < Y+2; ++
y){
392 const double w = corrArr[
y];
393 for(
int x = 0;
x < X+2; ++
x){
405 TH1D* todel = hcorr.release();
416 std::unique_ptr<TH1D> hcorr(corr.
ToTH1());
418 assert(hcorr->GetNbinsX() ==
fHist->GetNbinsX());
420 const int X =
fHist->GetNbinsX();
421 const int Y =
fHist->GetNbinsY();
424 double* histArr =
fHist->GetArray();
425 double* corrArr = hcorr->GetArray();
428 for(
int y = 0;
y < Y+2; ++
y){
429 for(
int x = 0;
x < X+2; ++
x){
436 histArr[
bin] *= corrArr[
x];
441 TH1D* todel = hcorr.release();
462 TDirectory* tmp = gDirectory;
465 TObjString(
"ReweightableSpectrum").Write(
"type");
468 fHist->Write(
"hist");
469 TH1D hPot(
"",
"", 1, 0, 1);
472 TH1D hLivetime(
"",
"", 1, 0, 1);
474 hLivetime.Write(
"livetime");
476 for(
unsigned int i = 0; i <
fBins.size(); ++i){
477 TObjString(
fLabels[i].c_str()).Write(TString::Format(
"label%d", i).
Data());
478 fBins[i].SaveTo(dir->mkdir(TString::Format(
"bins%d", i)));
487 TObjString* tag = (TObjString*)dir->Get(
"type");
489 assert(tag->GetString() ==
"ReweightableSpectrum");
491 TH2D* spect = (TH2D*)dir->Get(
"hist");
493 TH1* hPot = (TH1*)dir->Get(
"pot");
495 TH1* hLivetime = (TH1*)dir->Get(
"livetime");
498 std::vector<std::string>
labels;
499 std::vector<Binning> bins;
501 for(
int i = 0; ; ++i){
502 TDirectory* subdir = dir->GetDirectory(TString::Format(
"bins%d", i));
505 TObjString* label = (TObjString*)dir->Get(TString::Format(
"label%d", i));
506 labels.push_back(label ? label->GetString().Data() :
"");
509 if(bins.empty() && labels.empty()){
512 labels.push_back(spect->GetXaxis()->GetTitle());
515 return std::make_unique<ReweightableSpectrum>(
kUnweighted,
518 hPot->GetBinContent(1),
519 hLivetime->GetBinContent(1));
process_name opflash particleana ie ie ie z
Spectrum UnWeighted() const
Represent the binning of a Spectrum's x-axis.
TH1D * ToTH1(Color_t col=kBlack, Style_t style=kSolid) const
process_name opflash particleana ie x
BEGIN_PROLOG could also be cerr
void Fill(double x, double y, double w=1)
virtual ~ReweightableSpectrum()
Simple record of shifts applied to systematic parameters.
static Binning FromTAxis(const TAxis *ax)
Var fRWVar
What goes on the y axis?
Spectrum with the value of a second variable, allowing for reweighting
void ReweightToRecoSpectrum(const Spectrum &target)
Recale bins so that Unweighted will return target.
process_name opflashCryoW ana
then echo echo For and will not be changed by echo further linking echo echo B echo The symbol is in the uninitialized data multiple common symbols may appear with the echo same name If the symbol is defined the common echo symbols are treated as undefined references For more echo details on common see the discussion of warn common echo in *Note Linker see the discussion of warn common echo in *Note Linker such as a global int variable echo as opposed to a large global array echo echo I echo The symbol is an indirect reference to another symbol This echo is a GNU extension to the a out object file format which is echo rarely used echo echo N echo The symbol is a debugging symbol echo echo R echo The symbol is in a read only data section echo echo S echo The symbol is in an uninitialized data section for small echo objects echo echo T echo The symbol is in the the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo W echo The symbol is a weak symbol that has not been specifically echo tagged as a weak object symbol When a weak defined symbol echo is linked with a normal defined the normal defined echo symbol is used with no error When a weak undefined symbol echo is linked and the symbol is not the value of the echo weak symbol becomes zero with no error echo echo echo The symbol is a stabs symbol in an a out object file In echo this the next values printed are the stabs other echo the stabs desc and the stab type Stabs symbols are echo used to hold debugging information For more echo see *Note or object file format specific echo echo For Mac OS X
void ProjectionY(TH2D *from, TH1D *to)
Helper for WeightingVariable.
Representation of a spectrum in any variable, with associated POT.
void RemoveLoader(SpectrumLoaderBase *)
constexpr details::BinObj< T > bin(T value)
Returns a wrapper to print the specified data in binary format.
process_name pandoraGausCryo1 vertexChargeCryo1 vertexStubCryo1 xmin
std::vector< Binning > GetBinnings() const
process_name opflash particleana ie ie y
unsigned int NDimensions() const
virtual void AddReweightableSpectrum(ReweightableSpectrum &spect, const Var &var, const Cut &cut, const SystShifts &shift, const Var &wei)
For use by the constructors of ReweightableSpectrum subclasses.
static void Delete(TH1D *&h)
std::vector< std::string > GetLabels() const
void SaveTo(TDirectory *dir) const
std::set< SpectrumLoaderBase * > fLoaderCount
This count is maintained by SpectrumLoader, as a sanity check.
const SpillCut kNoSpillCut([](const caf::SRSpillProxy *){return true;})
The simplest possible cut: pass everything, used as a default.
std::vector< std::string > fLabels
void ProjectionX(TH2D *from, TH1D *to)
Helper for Unweighted.
Represent the ratio between two spectra.
const std::vector< double > & Edges() const
Base class for the various types of spectrum loader.
ReweightableSpectrum & operator=(const ReweightableSpectrum &rhs)
const Var kUnweighted([](const caf::SRSliceProxy *){return 1;})
The simplest possible Var, always 1. Used as a default weight.
Spectrum WeightedBy(const TH1 *weights) const
static std::unique_ptr< ReweightableSpectrum > LoadFrom(TDirectory *dir)
static TH1D * New(const std::string &title, const Binning &bins)
std::vector< Binning > fBins
void ReweightToTrueSpectrum(const Spectrum &target)
Rescale bins so that WeightingVariable will return target.
ReweightableSpectrum(SpectrumLoaderBase &loader, const HistAxis &recoAxis, const HistAxis &trueAxis, const Cut &cut, const SystShifts &shift=kNoShift, const Var &wei=kUnweighted)
Prevent histograms being added to the current directory.
void AddLoader(SpectrumLoaderBase *)
static Binning Simple(int n, double lo, double hi, const std::vector< std::string > &labels={})
static std::unique_ptr< Binning > LoadFrom(TDirectory *dir)
std::string UniqueName()
Return a different string each time, for creating histograms.
Spectrum WeightingVariable() const
TH2D * ToTH2(double pot) const