23#ifndef RESPLOT_RESPLOT_H
24#define RESPLOT_RESPLOT_H
85 int n1,
double a1,
double b1,
86 int n2,
double a2,
double b2,
const std::string& xaxis=
"") :
99 int n1,
const double* a1,
100 int n2,
double a2,
double b2,
const std::string& xaxis=
"") :
112 const std::vector<double>&
a,
113 int n2,
double a2,
double b2,
const std::string& xaxis=
"") :
125 const std::vector<double>&
a,
126 const std::vector<double>& b,
127 const std::string& xaxis=
"") :
161 Resplot(
const std::string& name, TH2* hin,
const bool flip=
false) :
174 else h =
static_cast<TH2D*
>(hin);
177 std::vector<double> a1;
179 TAxis* axe =
h->GetXaxis();
181 for (
int i=1 ; i<=axe->GetNbins()+1 ; i++ ) a1.push_back(axe->GetBinLowEdge(i));
184 TH1D* s =
h->ProjectionY(
"_duff", 1, 1,
"e");
186 int n2 = s->GetNbinsX();
187 double a2 = s->GetBinLowEdge(1);
188 double b2 = s->GetBinLowEdge(s->GetNbinsX()+1);
196 m_h2d = (TH2D*)
h->Clone(
"2d");
200 m_h1d =
h->ProjectionY(
"1d", 1,
h->GetNbinsX(),
"e");
201 m_h1d->SetTitle(
"1d");
219 m_Nentries =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/fractional uncertainty").c_str()));
220 m_mean =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/mean").c_str()));
221 m_sigma =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/sigma").c_str()));
223 m_chi2 =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/chi2").c_str()));
224 m_h2d =
new TH2D(*(TH2D*)gDirectory->Get((name+
"/2d").c_str()));
225 m_h1d =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/1d").c_str()));
243 for (
int i=1 ; i<=
m_h2d->GetNbinsX() ; i++ ) {
245 sprintf(slicename,
"/slices/slice[%03d]", i);
247 m_slices.push_back((TH1D*)gDirectory->Get((name+slicename).c_str()));
258 int n1,
double a1,
double b1,
259 int n2,
double a2,
double b2);
262 int n1,
const double* a1,
263 int n2,
double a2,
double b2);
266 int n1,
const double* a1,
267 int n2,
const double* a2);
270 const std::vector<double>&
a,
271 int n2,
double a2,
double b2);
274 const std::vector<double>&
a,
275 const std::vector<double>& b );
279 int Fill(
double x,
double y,
double w=1) {
328 std::vector<double> d;
329 for (
int i=1 ; i<=
m_mean->GetNbinsX()+1 ; i++ ) d.push_back(
m_mean->GetBinLowEdge(i));
335 std::vector<double> d;
336 for (
int i=1 ; i<=
m_mean->GetNbinsX() ; i++ ) d.push_back(
m_mean->GetBinCenter(i));
342 const std::string&
Name(
const std::string& s) {
return m_name=s; }
386 static TF1*
FitInternal(TH1D* s,
double a=-999,
double b=-999, TF1* f1=0);
389 static TF1*
FitGaussian(TH1D* s,
double a=-999,
double b=-999);
392 static TF1*
FitRGaussian(TH1D* s,
double a=-999,
double b=-999);
395 static TF1*
FitBreit(TH1D* s,
double a=-999,
double b=-999);
398 static TF1*
FitRBreit(TH1D* s,
double a=-999,
double b=-999);
401 static TF1*
FitATan(TH1D* s,
double a=-999,
double b=-999);
404 static TF1*
FitNull(TH1D* s,
double a=-999,
double b=-999);
407 static TF1*
FitPoisson(TH1D* s,
double a=-999,
double b=-999);
410 static TF1*
FitXExp(TH1D* s,
double a=-999,
double b=-999);
418 static TF1*
FitNull95(TH1D* s,
double a=0,
double b=0);
420 static TF1*
FitNull95New(TH1D* s,
double frac=0.95,
bool useroot=
false);
431 int Finalise(TF1* (*func)(TH1D* s,
double a,
double b),
double a=-999,
double b=-999 ) {
435 int Fit(TF1* (*func)(TH1D* s,
double a,
double b) ) {
440 int Refit(TF1* (*func)(TH1D* s,
double a,
double b) ) {
452 Int_t
Write(
const char* =0, Int_t =0, Int_t =0)
const {
return DWrite(); }
453 Int_t
Write(
const char* =0, Int_t =0, Int_t =0) {
return DWrite(); }
454 Int_t
DWrite(TDirectory* g=0)
const;
472 if (
r.H1D()->GetNbinsX()!=
H1D()->GetNbinsX())
throw ResException(
"histogram limits do not match");
473 if (
r.H2D()->GetNbinsX()!=
H2D()->GetNbinsX())
throw ResException(
"histogram limits do not match");
474 if (
r.H2D()->GetNbinsY()!=
H2D()->GetNbinsY())
throw ResException(
"histogram limits do not match");
476 for (
int i=0 ; i<=
r.H2D()->GetNbinsX()+1 ; i++ ) {
477 for (
int j=0 ; j<=
r.H2D()->GetNbinsY()+1 ; j++ ) {
478 H2D()->SetBinContent( i, j,
H2D()->GetBinContent(i,j) +
r.H2D()->GetBinContent(i,j) );
479 H2D()->SetBinError( i, j, std::sqrt(
H2D()->GetBinError(i,j)*
H2D()->GetBinError(i,j) +
r.H2D()->GetBinError(i,j)*
r.H2D()->GetBinError(i,j) ) );
483 for (
int i=0 ; i<=
r.H1D()->GetNbinsX()+1 ; i++ ) {
484 H1D()->SetBinContent( i,
H1D()->GetBinContent(i) +
r.H1D()->GetBinContent(i) );
485 H1D()->SetBinError( i, std::sqrt(
H1D()->GetBinError(i)*
H1D()->GetBinError(i) +
r.H1D()->GetBinError(i)*
r.H1D()->GetBinError(i) ) );
504 std::cout <<
"Resplot::operator*= " <<
Name() <<
"\tH2D " <<
H2D() << std::endl;
508 std::cout <<
"Resplot::operator*= " <<
Name() <<
"\tDraw " << std::endl;
510 for (
int i=0 ; i<=
H2D()->GetNbinsX()+1 ; i++ ) {
511 for (
int j=0 ; j<=
H2D()->GetNbinsY()+1 ; j++ ) {
512 H2D()->SetBinContent( i, j,
H2D()->GetBinContent(i,j)*d);
513 H2D()->SetBinError( i, j,
H2D()->GetBinError(i,j)*d);
518 std::cout <<
"Resplot::operator*= " <<
Name() <<
"\tH1D " <<
H1D() << std::endl;
520 for (
int i=0 ; i<=
H1D()->GetNbinsX()+1 ; i++ ) {
521 H1D()->SetBinContent( i,
H1D()->GetBinContent(i)*d );
522 H1D()->SetBinError( i,
H1D()->GetBinError(i)*d );
527 std::cout <<
"Resplot::operator*= done" << std::endl;
558 static TH2D*
rotate(
const TH2*
h);
562 static TH2D*
combine(
const TH2*
h,
double x,
int N);
564 static TH1D*
combine(
const TH1*
h,
double x,
int N);
568 static TH2D*
combine(
const TH2*
h,
double epsilon);
569 static TH1D*
combine(
const TH1*
h,
double epsilon);
571 static std::vector<double>
findbins(
const TH1*
h,
double epsilon);
572 static TH1D*
rebin(
const TH1*
h,
const std::vector<double>&
bins);
574 static std::vector<double>
getbins(
const TH1*
h);
583 void skip(TH1D* t) {
if ( t ) t->SetDirectory(0); }
584 void delskip(TH1D* t) {
if ( t ) { t->SetDirectory(0);
delete t; } }
587 void skip(TH2D* t) {
if ( t ) t->SetDirectory(0); }
588 void delskip(TH2D* t) {
if ( t ) { t->SetDirectory(0);
delete t; } }
605 h->SetBinContent(i, v.value);
606 h->SetBinError(i, v.error);
611 h->SetBinContent(i, v.value);
612 h->SetBinError(i, v.error);
617 h->SetBinContent(i, v.value);
618 h->SetBinError(i, v.error);
static const std::vector< std::string > bins
Resplot operator*(double d, Resplot r)
Header file for AthHistogramAlgorithm.
ResException(const std::string &s)
static TH2D * rotate(const TH2 *h)
flip the x and y axes
std::vector< double > GetPrimaryLimits() const
static TF1 * FitRGaussian(TH1D *s, double a=-999, double b=-999)
static std::vector< double > getbins(const TH1 *h)
const std::string & Name() const
static TF1 * FitCentralGaussian(TH1D *s, double a=-999, double b=-999)
Int_t Write(const char *=0, Int_t=0, Int_t=0)
std::vector< TH1D * > m_slices
static TF1 * FitInternal(TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
static TH1D * rebin(const TH1 *h, const std::vector< double > &bins)
static TF1 * FitNull95New(TH1D *s, double frac=0.95, bool useroot=false)
void SetXAxis(const std::string &xaxis)
static const std::string s_rversion
static TF1 * FitGaussian(TH1D *s, double a=-999, double b=-999)
static TF1 * FitRBreit(TH1D *s, double a=-999, double b=-999)
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=Resplot::FitGaussian)
const std::string & Name(const std::string &s)
Resplot & operator+=(const Resplot &r)
operators
static bool setscalerms95(bool b)
Int_t Write(const char *=0, Int_t=0, Int_t=0) const
Hooray, this stupidity is to overwride both the const and non-const TObject Write methods Fixme: shou...
Resplot(const std::string &name)
std::vector< double > GetPrimaryCentres() const
void AddMean(TH1D *h, int i)
void SetYAxis(const std::string &yaxis)
static TF1 * FitBreit(TH1D *s, double a=-999, double b=-999)
static bool AddDirectoryStatus()
Resplot(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2, const std::string &xaxis="")
void SetSecondary(int n, double a, double b)
static TF1 * FitLandauGauss(TH1D *s, double a=-999, double b=-999)
static TF1 * FitXExp(TH1D *s, double a=-999, double b=-999)
Resplot(const std::string &name, const std::vector< double > &a, const std::vector< double > &b, const std::string &xaxis="")
int Refit(TF1 *(*func)(TH1D *s, double a, double b))
static bool s_oldrms95
temporarily allow toggeling between old and new rms95 error estimates
static void AddDirectory(bool t=false)
void SetDirectory(TDirectory *=0)
Resplot(const std::string &name, TH2 *hin, const bool flip=false)
const std::string & FitName() const
static const std::string & version()
static TF1 * FitNull(TH1D *s, double a=-999, double b=-999)
static TF1 * FitNull95(TH1D *s, double a=0, double b=0)
static bool s_interpolate_flag
Resplot & operator*=(double d)
void AddEfficiency(TH1D *h, int i, double lower, double upper)
void SetPrimary(int n, double, double)
int Finalise(TF1 *(*func)(TH1D *s, double a, double b), double a=-999, double b=-999)
static TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
const TH1D * Uncertainty() const
static bool setoldrms95(bool b)
Resplot(const std::string &name, const std::vector< double > &a, int n2, double a2, double b2, const std::string &xaxis="")
StatVal GetEfficiency(TH1D *h, double lower, double upper)
Resplot(const std::string &name, int n1, const double *a1, int n2, double a2, double b2, const std::string &xaxis="")
StatVal GetGlobalEfficiency(double lower, double upper)
void SetPrimary(int n, const double *)
void Initialise(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
Resplot(const Resplot &r, const std::string &tag="")
static TH2D * combine(const TH2 *h, double x, int N)
combine bins along the x axis after value x, combine each N bins into a single bin
const TH1D * Mean() const
Resplot operator+(const Resplot &r) const
void AddResolution(TH1D *h, int i)
static TF1 * FitPoisson(TH1D *s, double a=-999, double b=-999)
Int_t DWrite(TDirectory *g=0) const
boooo, need to use the stupid Int_t class because I foolishly gave this function the same name as TOb...
static void setInterpolateFlag(bool b)
int Fit(TF1 *(*func)(TH1D *s, double a, double b))
Resplot operator*(double d) const
int Fill(double x, double y, double w=1)
static bool s_mAddDirectoryStatus
const TH1D * Chi2() const
void setUniform(bool t=false)
static TF1 * FitATan(TH1D *s, double a=-999, double b=-999)
static TF1 * FitNull95Central(TH1D *s)
TH1D * GetEfficiencies(const std::string &hname, double lower, double upper)
const std::vector< TH1D * > & Slices() const
static bool setnofit(bool b)
static std::vector< double > findbins(const TH1 *h, double epsilon)
simple struct to hold a value and it's associated uncertainty.