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");
226 m_Nentries =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/fractional uncertainty").c_str()));
227 m_mean =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/mean").c_str()));
228 m_sigma =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/sigma").c_str()));
229 m_chi2 =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/chi2").c_str()));
230 m_h2d =
new TH2D(*(TH2D*)gDirectory->Get((name+
"/2d").c_str()));
231 m_h1d =
new TH1D(*(TH1D*)gDirectory->Get((name+
"/1d").c_str()));
245 for (
int i=1 ; i<=
m_h2d->GetNbinsX() ; i++ ) {
247 sprintf(slicename,
"/slices/slice[%03d]", i);
249 m_slices.push_back((TH1D*)gDirectory->Get((name+slicename).c_str()));
260 int n1,
double a1,
double b1,
261 int n2,
double a2,
double b2);
264 int n1,
const double* a1,
265 int n2,
double a2,
double b2);
268 int n1,
const double* a1,
269 int n2,
const double* a2);
272 const std::vector<double>&
a,
273 int n2,
double a2,
double b2);
276 const std::vector<double>&
a,
277 const std::vector<double>& b );
281 int Fill(
double x,
double y,
double w=1) {
330 std::vector<double> d;
331 for (
int i=1 ; i<=
m_mean->GetNbinsX()+1 ; i++ ) d.push_back(
m_mean->GetBinLowEdge(i));
337 std::vector<double> d;
338 for (
int i=1 ; i<=
m_mean->GetNbinsX() ; i++ ) d.push_back(
m_mean->GetBinCenter(i));
344 const std::string&
Name(
const std::string& s) {
return m_name=s; }
388 static TF1*
FitInternal(TH1D* s,
double a=-999,
double b=-999, TF1* f1=0);
391 static TF1*
FitGaussian(TH1D* s,
double a=-999,
double b=-999);
394 static TF1*
FitRGaussian(TH1D* s,
double a=-999,
double b=-999);
397 static TF1*
FitBreit(TH1D* s,
double a=-999,
double b=-999);
400 static TF1*
FitRBreit(TH1D* s,
double a=-999,
double b=-999);
403 static TF1*
FitATan(TH1D* s,
double a=-999,
double b=-999);
406 static TF1*
FitNull(TH1D* s,
double a=-999,
double b=-999);
409 static TF1*
FitPoisson(TH1D* s,
double a=-999,
double b=-999);
412 static TF1*
FitXExp(TH1D* s,
double a=-999,
double b=-999);
420 static TF1*
FitNull95(TH1D* s,
double a=0,
double b=0);
422 static TF1*
FitNull95New(TH1D* s,
double frac=0.95,
bool useroot=
false);
433 int Finalise(TF1* (*func)(TH1D* s,
double a,
double b),
double a=-999,
double b=-999 ) {
437 int Fit(TF1* (*func)(TH1D* s,
double a,
double b) ) {
442 int Refit(TF1* (*func)(TH1D* s,
double a,
double b) ) {
454 Int_t
Write(
const char* =0, Int_t =0, Int_t =0)
const {
return DWrite(); }
455 Int_t
Write(
const char* =0, Int_t =0, Int_t =0) {
return DWrite(); }
456 Int_t
DWrite(TDirectory* g=0)
const;
474 if (
r.H1D()->GetNbinsX()!=
H1D()->GetNbinsX())
throw ResException(
"histogram limits do not match");
475 if (
r.H2D()->GetNbinsX()!=
H2D()->GetNbinsX())
throw ResException(
"histogram limits do not match");
476 if (
r.H2D()->GetNbinsY()!=
H2D()->GetNbinsY())
throw ResException(
"histogram limits do not match");
478 for (
int i=0 ; i<=
r.H2D()->GetNbinsX()+1 ; i++ ) {
479 for (
int j=0 ; j<=
r.H2D()->GetNbinsY()+1 ; j++ ) {
480 H2D()->SetBinContent( i, j,
H2D()->GetBinContent(i,j) +
r.H2D()->GetBinContent(i,j) );
481 H2D()->SetBinError( i, j, std::sqrt(
H2D()->GetBinError(i,j)*
H2D()->GetBinError(i,j) +
r.H2D()->GetBinError(i,j)*
r.H2D()->GetBinError(i,j) ) );
485 for (
int i=0 ; i<=
r.H1D()->GetNbinsX()+1 ; i++ ) {
486 H1D()->SetBinContent( i,
H1D()->GetBinContent(i) +
r.H1D()->GetBinContent(i) );
487 H1D()->SetBinError( i, std::sqrt(
H1D()->GetBinError(i)*
H1D()->GetBinError(i) +
r.H1D()->GetBinError(i)*
r.H1D()->GetBinError(i) ) );
506 std::cout <<
"Resplot::operator*= " <<
Name() <<
"\tH2D " <<
H2D() << std::endl;
510 std::cout <<
"Resplot::operator*= " <<
Name() <<
"\tDraw " << std::endl;
512 for (
int i=0 ; i<=
H2D()->GetNbinsX()+1 ; i++ ) {
513 for (
int j=0 ; j<=
H2D()->GetNbinsY()+1 ; j++ ) {
514 H2D()->SetBinContent( i, j,
H2D()->GetBinContent(i,j)*d);
515 H2D()->SetBinError( i, j,
H2D()->GetBinError(i,j)*d);
520 std::cout <<
"Resplot::operator*= " <<
Name() <<
"\tH1D " <<
H1D() << std::endl;
522 for (
int i=0 ; i<=
H1D()->GetNbinsX()+1 ; i++ ) {
523 H1D()->SetBinContent( i,
H1D()->GetBinContent(i)*d );
524 H1D()->SetBinError( i,
H1D()->GetBinError(i)*d );
529 std::cout <<
"Resplot::operator*= done" << std::endl;
560 static TH2D*
rotate(
const TH2*
h);
564 static TH2D*
combine(
const TH2*
h,
double x,
int N);
566 static TH1D*
combine(
const TH1*
h,
double x,
int N);
570 static TH2D*
combine(
const TH2*
h,
double epsilon);
571 static TH1D*
combine(
const TH1*
h,
double epsilon);
573 static std::vector<double>
findbins(
const TH1*
h,
double epsilon);
574 static TH1D*
rebin(
const TH1*
h,
const std::vector<double>&
bins);
576 static std::vector<double>
getbins(
const TH1*
h);
585 void skip(TH1D* t) {
if ( t ) t->SetDirectory(0); }
586 void delskip(TH1D* t) {
if ( t ) { t->SetDirectory(0);
delete t; } }
589 void skip(TH2D* t) {
if ( t ) t->SetDirectory(0); }
590 void delskip(TH2D* t) {
if ( t ) { t->SetDirectory(0);
delete t; } }
607 h->SetBinContent(i, v.value);
608 h->SetBinError(i, v.error);
613 h->SetBinContent(i, v.value);
614 h->SetBinError(i, v.error);
619 h->SetBinContent(i, v.value);
620 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.