22#ifndef RESPLOT_RESPLOT_H
23#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=
"") :
168 Resplot(
const std::string&
name, TH2* hin,
const bool flip=
false) :
181 else h =
static_cast<TH2D*
>(hin);
184 std::vector<double> xlimits =
getLimits(
h->GetXaxis() );;
185 std::vector<double> ylimits =
getLimits(
h->GetYaxis() );
187 int n2 = ylimits.size()-1;;
188 double a2 = ylimits[0];;
189 double b2 = ylimits.back();
201 m_h1d->SetTitle(
"1d");
227 m_Nentries =
new TH1D(*(TH1D*)gDirectory->Get((
name+
"/fractional uncertainty").c_str()));
228 m_mean =
new TH1D(*(TH1D*)gDirectory->Get((
name+
"/mean").c_str()));
229 m_sigma =
new TH1D(*(TH1D*)gDirectory->Get((
name+
"/sigma").c_str()));
230 m_chi2 =
new TH1D(*(TH1D*)gDirectory->Get((
name+
"/chi2").c_str()));
231 m_h2d =
new TH2D(*(TH2D*)gDirectory->Get((
name+
"/2d").c_str()));
232 m_h1d =
new TH1D(*(TH1D*)gDirectory->Get((
name+
"/1d").c_str()));
246 for (
int i=1 ; i<=
m_h2d->GetNbinsX() ; i++ ) {
248 sprintf(slicename,
"/slices/slice[%03d]", i);
250 m_slices.push_back((TH1D*)gDirectory->Get((
name+slicename).c_str()));
263 void Initialise(
const std::string& name,
264 int n1,
double a1,
double b1,
265 int n2,
double a2,
double b2);
267 void Initialise(
const std::string& name,
268 int n1,
const double* a1,
269 int n2,
double a2,
double b2);
271 void Initialise(
const std::string& name,
272 int n1,
const double* a1,
273 int n2,
const double* a2);
275 void Initialise(
const std::string& name,
276 const std::vector<double>&
a,
277 int n2,
double a2,
double b2);
279 void Initialise(
const std::string& name,
280 const std::vector<double>&
a,
281 const std::vector<double>& b );
285 int Fill(
double x,
double y,
double w=1) {
306 TH1D* GetEfficiencies(
const std::string& hname,
double lower,
double upper);
312 TH1D* GetEfficiencies(
const std::string& hname,
double Nsigma);
334 std::vector<double> d;
335 for (
int i=1 ; i<=
m_mean->GetNbinsX()+1 ; i++ ) d.push_back(
m_mean->GetBinLowEdge(i));
341 std::vector<double> d;
342 for (
int i=1 ; i<=
m_mean->GetNbinsX() ; i++ ) d.push_back(
m_mean->GetBinCenter(i));
346 const std::string&
Name(
const std::string& s) {
return m_name=s; }
398 static std::vector<double>
getLimits(
const TAxis* axis ) {
399 std::vector<double> limits( axis->GetNbins()+1, 0 );
400 for (
size_t i=axis->GetNbins()+1 ; i-- ; ) limits[i] = axis->GetBinLowEdge(i+1);
410 static TH1D*
projectionY( TH2* h2d,
int col,
const std::vector<double>& ylimits,
const std::string&
tagname ) {
411 TH1D*
h =
new TH1D(
tagname.
c_str(),
"", ylimits.size()-1, &ylimits[0] );
h->SetDirectory(0);
413 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
414 double v = h2d->GetBinContent(col, i);
415 h->SetBinContent( i, v );
422 static TH1D*
projectionY( TH2* h2d,
int col0,
int col1,
const std::vector<double>& ylimits,
const std::string&
tagname ) {
423 TH1D*
h =
new TH1D(
tagname.
c_str(),
"", ylimits.size()-1, &ylimits[0] );
h->SetDirectory(0);
425 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
427 for (
int col=col0 ; col<=col1 ; col++ )
sum += h2d->GetBinContent(col, i);
428 h->SetBinContent( i,
sum );
435 static TH1D*
projectionX( TH2* h2d,
int row,
const std::vector<double>& xlimits,
const std::string&
tagname ) {
436 TH1D*
h =
new TH1D(
tagname.
c_str(),
"", xlimits.size()-1, &xlimits[0] );
h->SetDirectory(0);
438 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
439 double v = h2d->GetBinContent( i, row );
440 h->SetBinContent( i, v );
447 static TH1D*
projectionX( TH2* h2d,
int row0,
int row1,
const std::vector<double>& xlimits,
const std::string&
tagname ) {
448 TH1D*
h =
new TH1D(
tagname.
c_str(),
"", xlimits.size()-1, &xlimits[0] );
h->SetDirectory(0);
450 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ ) {
452 for (
int row=row0 ; row<=row1 ; row++ )
sum += h2d->GetBinContent(i, row);
453 h->SetBinContent( i,
sum );
462 for (
int i=1 ; i<=
h->GetNbinsX() ; i++ )
sum +=
h->GetBinContent(i);
471 int Finalise(
double a=-999,
double b=-999, TF1* (*func)(TH1D* s,
double a,
double b)=
FitGaussian);
473 int Finalise(TF1* (*func)(TH1D* s,
double a,
double b),
double a=-999,
double b=-999 ) {
477 int Fit(TF1* (*func)(TH1D* s,
double a,
double b) ) {
482 int Refit(TF1* (*func)(TH1D* s,
double a,
double b) ) {
496 Int_t
Write(
const char* =0, Int_t =0, Int_t =0)
const {
return DWrite(); }
497 Int_t
Write(
const char* =0, Int_t =0, Int_t =0) {
return DWrite(); }
498 Int_t DWrite(TDirectory* g=0)
const;
517 if (
r.H1D()->GetNbinsX()!=
H1D()->GetNbinsX())
throw ResException(
"histogram limits do not match");
518 if (
r.H2D()->GetNbinsX()!=
H2D()->GetNbinsX())
throw ResException(
"histogram limits do not match");
519 if (
r.H2D()->GetNbinsY()!=
H2D()->GetNbinsY())
throw ResException(
"histogram limits do not match");
521 for (
int i=0 ; i<=
r.H2D()->GetNbinsX()+1 ; i++ ) {
522 for (
int j=0 ; j<=
r.H2D()->GetNbinsY()+1 ; j++ ) {
523 H2D()->SetBinContent( i, j,
H2D()->GetBinContent(i,j) +
r.H2D()->GetBinContent(i,j) );
524 H2D()->SetBinError( i, j, std::sqrt(
H2D()->GetBinError(i,j)*
H2D()->GetBinError(i,j) +
r.H2D()->GetBinError(i,j)*
r.H2D()->GetBinError(i,j) ) );
528 for (
int i=0 ; i<=
r.H1D()->GetNbinsX()+1 ; i++ ) {
529 H1D()->SetBinContent( i,
H1D()->GetBinContent(i) +
r.H1D()->GetBinContent(i) );
530 H1D()->SetBinError( i, std::sqrt(
H1D()->GetBinError(i)*
H1D()->GetBinError(i) +
r.H1D()->GetBinError(i)*
r.H1D()->GetBinError(i) ) );
555 for (
int i=0 ; i<=
H2D()->GetNbinsX()+1 ; i++ ) {
556 for (
int j=0 ; j<=
H2D()->GetNbinsY()+1 ; j++ ) {
557 H2D()->SetBinContent( i, j,
H2D()->GetBinContent(i,j)*d);
558 H2D()->SetBinError( i, j,
H2D()->GetBinError(i,j)*d);
565 for (
int i=0 ; i<=
H1D()->GetNbinsX()+1 ; i++ ) {
566 H1D()->SetBinContent( i,
H1D()->GetBinContent(i)*d );
567 H1D()->SetBinError( i,
H1D()->GetBinError(i)*d );
600 static TH2D*
rotate(
const TH2*
h,
const std::string& s=
"" );
601 static TH2D* copy(
const TH2*
h,
const std::string& s=
"" );
603 static std::vector<double> findbins(
const TH1*
h,
double epsilon);
604 static TH1D* rebin(
const TH1*
h,
const std::vector<double>&
bins);
606 static std::vector<double> getbins(
const TH1*
h);
615 void skip(TH1D* t) {
if ( t ) t->SetDirectory(0); }
616 void delskip(TH1D* t) {
if ( t ) { t->SetDirectory(0);
delete t; } }
619 void skip(TH2D* t) {
if ( t ) t->SetDirectory(0); }
620 void delskip(TH2D* t) {
if ( t ) { t->SetDirectory(0);
delete t; } }
637 h->SetBinContent(i, v.value);
638 h->SetBinError(i, v.error);
643 h->SetBinContent(i, v.value);
644 h->SetBinError(i, v.error);
649 h->SetBinContent(i, v.value);
650 h->SetBinError(i, v.error);
728TF1*
FitInternal(TH1D* s,
double a=-999,
double b=-999, TF1* f1=0);
737TF1*
FitBreit(TH1D* s,
double a=-999,
double b=-999);
740TF1*
FitRBreit(TH1D* s,
double a=-999,
double b=-999);
743TF1*
FitATan(TH1D* s,
double a=-999,
double b=-999);
746TF1*
FitNull(TH1D* s,
double a=-999,
double b=-999);
749TF1*
FitPoisson(TH1D* s,
double a=-999,
double b=-999);
752TF1*
FitXExp(TH1D* s,
double a=-999,
double b=-999);
760TF1*
FitNull95(TH1D* s,
double a=0,
double b=0);
763TF1*
FitNull95New(TH1D* s,
double frac=0.95,
bool useroot=
false);
ElementConstReference operator*() const
Return a reference to the referenced element.
static const std::vector< std::string > bins
void clear()
Empty the pool.
void rotate(double angler, GeoTrf::Vector2D &vector)
Header file for AthHistogramAlgorithm.
ResException(const std::string &s)
static std::vector< double > getxLimits(TH2 *h)
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...
void SetDirectory(TDirectory *=0)
const TH1D * Chi2() const
void AddResolution(TH1D *h, int i)
static TH1D * projectionX(TH2 *h2d, int row0, int row1, const std::vector< double > &xlimits, const std::string &tagname)
Resplot(const Resplot &r, const std::string &tag="")
std::vector< double > GetPrimaryLimits() const
Resplot & operator=(const Resplot &)=delete
StatVal GetEfficiency(TH1D *h, double lower, double upper)
int Fit(TF1 *(*func)(TH1D *s, double a, double b))
void setUniform(bool t=false)
static TH2D * copy(const TH2 *h, const std::string &s="")
copy a TH2
Int_t Write(const char *=0, Int_t=0, Int_t=0)
const TH1D * Mean() const
static const std::string s_rversion
Resplot(const std::string &name, int n1, const double *a1, int n2, double a2, double b2, const std::string &xaxis="")
const std::string & FitName() const
int Finalise(TF1 *(*func)(TH1D *s, double a, double b), double a=-999, double b=-999)
void SetSecondary(int n, double a, double b)
Resplot(const std::string &name, const std::vector< double > &a, const std::vector< double > &b, const std::string &xaxis="")
Resplot & operator+=(const Resplot &r)
operators
static TH1D * projectionX(TH2 *h2d, int row, const std::vector< double > &xlimits, const std::string &tagname)
void SetYAxis(const std::string &yaxis)
Resplot operator+(const Resplot &r) const
Resplot operator*(double d) const
const std::vector< TH1D * > & Slices() const
void SetPrimary(int n, double, double)
static TH1D * projectionY(TH2 *h2d, int col, const std::vector< double > &ylimits, const std::string &tagname)
actual local projections ...
static std::vector< double > getLimits(const TAxis *axis)
projection utilities ... NB: In athena, for some reason the destuctors for histograms created using T...
const TH1D * Uncertainty() const
const std::string & Name(const std::string &s)
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...
static double sum(TH1 *h)
static const std::string & version()
const std::string & name() const
static bool AddDirectoryStatus()
void AddEfficiency(TH1D *h, int i, double lower, double upper)
Resplot(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2, const std::string &xaxis="")
int Fill(double x, double y, double w=1)
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=FitGaussian)
static TH1D * projectionY(TH2 *h2d, int col0, int col1, const std::vector< double > &ylimits, const std::string &tagname)
Resplot(const std::string &name)
static void AddDirectory(bool t=false)
void SetPrimary(int n, const double *)
Resplot(const std::string &name, TH2 *hin, const bool flip=false)
int Refit(TF1 *(*func)(TH1D *s, double a, double b))
static std::vector< double > getyLimits(TH2 *h)
std::vector< TH1D * > m_slices
std::vector< double > GetPrimaryCentres() const
Resplot & operator*=(double d)
void Initialise(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
const std::string & Name() const
StatVal GetGlobalEfficiency(double lower, double upper)
void SetXAxis(const std::string &xaxis)
void AddMean(TH1D *h, int i)
Resplot(const std::string &name, const std::vector< double > &a, int n2, double a2, double b2, const std::string &xaxis="")
simple struct to hold a value and it's associated uncertainty.
TF1 * FitRGaussian(TH1D *s, double a=-999, double b=-999)
TF1 * FitCentralGaussian(TH1D *s, double a=-999, double b=-999)
TF1 * FitInternal(TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
TF1 * FitNull95New(TH1D *s, double frac=0.95, bool useroot=false)
TF1 * FitGaussian(TH1D *s, double a=-999, double b=-999)
forward declation because we use this in the class ...
TF1 * FitRBreit(TH1D *s, double a=-999, double b=-999)
bool s_oldrms95
use the new error estimates
TF1 * FitNull95Central(TH1D *s)
TF1 * FitLandauGauss(TH1D *s, double a=-999, double b=-999)
TF1 * FitXExp(TH1D *s, double a=-999, double b=-999)
TF1 * FitNull(TH1D *s, double a=-999, double b=-999)
bool setscalerms95(bool b)
TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
TF1 * FitNull95(TH1D *s, double a=0, double b=0)
TF1 * FitPoisson(TH1D *s, double a=-999, double b=-999)
bool s_mAddDirectoryStatus
TF1 * FitATan(TH1D *s, double a=-999, double b=-999)
TF1 * FitBreit(TH1D *s, double a=-999, double b=-999)
const char * c_str() const