ATLAS Offline Software
Loading...
Searching...
No Matches
Resplot Class Reference

#include <Resplot.h>

Inheritance diagram for Resplot:
Collaboration diagram for Resplot:

Classes

class  ResException

Public Member Functions

 Resplot ()
 Resplot (const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2, const std::string &xaxis="")
 Resplot (const std::string &name, int n1, const double *a1, int n2, double a2, double b2, const std::string &xaxis="")
 Resplot (const std::string &name, const std::vector< double > &a, int n2, double a2, double b2, const std::string &xaxis="")
 Resplot (const std::string &name, const std::vector< double > &a, const std::vector< double > &b, const std::string &xaxis="")
 Resplot (const Resplot &r, const std::string &tag="")
 Resplot (const std::string &name, TH2 *hin, const bool flip=false)
 Resplot (const std::string &name)
virtual ~Resplot ()
void Initialise (const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
void Initialise (const std::string &name, int n1, const double *a1, int n2, double a2, double b2)
void Initialise (const std::string &name, int n1, const double *a1, int n2, const double *a2)
void Initialise (const std::string &name, const std::vector< double > &a, int n2, double a2, double b2)
void Initialise (const std::string &name, const std::vector< double > &a, const std::vector< double > &b)
int Fill (double x, double y, double w=1)
StatVal GetEfficiency (TH1D *h, double lower, double upper)
StatVal GetGlobalEfficiency (double lower, double upper)
TH1D * GetEfficiencies (const std::string &hname, double lower, double upper)
TH1D * GetEfficiencies (const std::string &hname, double Nsigma)
void SetXAxis (const std::string &xaxis)
void SetYAxis (const std::string &yaxis)
std::vector< double > GetPrimaryLimits () const
std::vector< double > GetPrimaryCentres () const
const std::string & Name () const
const std::string & Name (const std::string &s)
TH1D * Mean ()
const TH1D * Mean () const
TH1D * Sigma ()
TH1D * Chi2 ()
const TH1D * Chi2 () const
TH1D * H1D ()
const TH1D * H1D () const
TH2D * H2D ()
const TH2D * H2D () const
TH1D * Uncertainty ()
const TH1D * Uncertainty () const
bool finalised () const
const std::vector< TH1D * > & Slices () const
const std::string & FitName () const
int Finalise (double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=Resplot::FitGaussian)
int Finalise (TF1 *(*func)(TH1D *s, double a, double b), double a=-999, double b=-999)
int Fit (TF1 *(*func)(TH1D *s, double a, double b))
int Refit (TF1 *(*func)(TH1D *s, double a, double b))
TDirectory * Dir ()
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: should probably remove all of these so root can write out using the dictionary but I could never get that to work.
Int_t Write (const char *=0, Int_t=0, Int_t=0)
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 TObject::Write
void SetDirectory (TDirectory *=0)
Resplotoperator+= (const Resplot &r)
 operators
Resplotoperator*= (double d)
Resplot operator* (double d) const
Resplot operator+ (const Resplot &r) const
void Integrate ()
void setUniform (bool t=false)

Static Public Member Functions

static TF1 * FitInternal (TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
static TF1 * FitGaussian (TH1D *s, double a=-999, double b=-999)
static TF1 * FitRGaussian (TH1D *s, double a=-999, double b=-999)
static TF1 * FitBreit (TH1D *s, double a=-999, double b=-999)
static TF1 * FitRBreit (TH1D *s, double a=-999, double b=-999)
static TF1 * FitATan (TH1D *s, double a=-999, double b=-999)
static TF1 * FitNull (TH1D *s, double a=-999, double b=-999)
static TF1 * FitPoisson (TH1D *s, double a=-999, double b=-999)
static TF1 * FitXExp (TH1D *s, double a=-999, double b=-999)
static TF1 * FitLandauGauss (TH1D *s, double a=-999, double b=-999)
static TF1 * FitCentralGaussian (TH1D *s, double a=-999, double b=-999)
static TF1 * FitNull95 (TH1D *s, double a=0, double b=0)
static TF1 * FitNull95New (TH1D *s, double frac=0.95, bool useroot=false)
static TF1 * FitNull95Obsolete (TH1D *s, double frac=0.95, bool useroot=false)
static TF1 * FitNull95Central (TH1D *s)
static bool AddDirectoryStatus ()
static void AddDirectory (bool t=false)
static void setInterpolateFlag (bool b)
static const std::string & version ()
static bool setoldrms95 (bool b)
static bool setscalerms95 (bool b)
static bool setnofit (bool b)
static TH2D * rotate (const TH2 *h)
 flip the x and y axes
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
static TH1D * combine (const TH1 *h, double x, int N)
 after value x, combine each N bins into a single bin
static TH2D * combine (const TH2 *h, double epsilon)
 combine bins along the x axis combine bins such that the stat precision is better than epsilon
static TH1D * combine (const TH1 *h, double epsilon)
 combine bins in a 2D histogram it takes a value, x and all the bins with BinLowEdge > x get combined N bins at a time.
static std::vector< double > findbins (const TH1 *h, double epsilon)
static TH1D * rebin (const TH1 *h, const std::vector< double > &bins)
static std::vector< double > getbins (const TH1 *h)

Private Types

enum  ERROR { OK , HISTOWIDTH , BINWIDTH , EMPTY }

Private Member Functions

void MakeSlices ()
void skip (TH1D *t)
void delskip (TH1D *t)
void deletehist (TH1D *t)
void skip (TH2D *t)
void delskip (TH2D *t)
void deletehist (TH2D *t)
void SetPrimary (int n, const double *)
void SetPrimary (int n, double, double)
void SetSecondary (int n, double a, double b)
StatVal get_mean ()
StatVal get_sigma ()
void AddEfficiency (TH1D *h, int i, double lower, double upper)
void AddResolution (TH1D *h, int i)
void AddMean (TH1D *h, int i)
void clear ()

Private Attributes

bool m_Set
std::string m_name
TH1D * m_Nentries = 0
TH1D * m_mean = 0
TH1D * m_sigma = 0
TH1D * m_chi2 = 0
TH2D * m_h2d = 0
TH1D * m_h1d = 0
StatVal m_g_mean
StatVal m_g_sigma
TDirectory * m_dir = 0
int m_n_primary
int m_n_secondary
double m_a_secondary
double m_b_secondary
std::string m_xaxis
std::string m_yaxis
std::vector< TH1D * > m_slices
std::string m_fitname
bool m_finalised
TDirectory * m_slicedir = 0
bool m_uniform

Static Private Attributes

static bool s_mAddDirectoryStatus
static bool s_interpolate_flag
static const std::string s_rversion = "resplot-v29"
static bool s_oldrms95 = true
 temporarily allow toggeling between old and new rms95 error estimates
static bool s_scalerms95 = true
static bool s_nofit = false
static ERROR s_ErrorSet = Resplot::OK

Detailed Description

Definition at line 50 of file Resplot.h.

Member Enumeration Documentation

◆ ERROR

enum Resplot::ERROR
private
Enumerator
OK 
HISTOWIDTH 
BINWIDTH 
EMPTY 

Definition at line 59 of file Resplot.h.

@ BINWIDTH
Definition Resplot.h:59
@ HISTOWIDTH
Definition Resplot.h:59
@ EMPTY
Definition Resplot.h:59

Constructor & Destructor Documentation

◆ Resplot() [1/8]

Resplot::Resplot ( )
inline

Definition at line 70 of file Resplot.h.

70 :
71 m_Set(false), m_Nentries(NULL),
72 m_mean(NULL), m_sigma(NULL), m_chi2(NULL),
73 m_h2d(NULL), m_h1d(NULL),
74 m_dir(NULL),
75 m_n_primary(0),
77 m_a_secondary(0.0),
78 m_b_secondary(0.0),
79 m_xaxis(""), m_yaxis(""), m_fitname(""), m_finalised(false),
80 m_uniform(true)
81 { }
TH2D * m_h2d
Definition Resplot.h:649
std::string m_yaxis
Definition Resplot.h:663
bool m_Set
Definition Resplot.h:640
std::string m_xaxis
Definition Resplot.h:662
TH1D * m_mean
Definition Resplot.h:645
TH1D * m_h1d
Definition Resplot.h:650
TH1D * m_Nentries
Definition Resplot.h:644
double m_b_secondary
Definition Resplot.h:660
int m_n_primary
Definition Resplot.h:657
bool m_uniform
Definition Resplot.h:671
TH1D * m_sigma
Definition Resplot.h:646
TH1D * m_chi2
Definition Resplot.h:647
double m_a_secondary
Definition Resplot.h:660
std::string m_fitname
Definition Resplot.h:666
TDirectory * m_dir
Definition Resplot.h:655
int m_n_secondary
Definition Resplot.h:659
bool m_finalised
Definition Resplot.h:668

◆ Resplot() [2/8]

Resplot::Resplot ( const std::string & name,
int n1,
double a1,
double b1,
int n2,
double a2,
double b2,
const std::string & xaxis = "" )
inline

Definition at line 84 of file Resplot.h.

86 :
87 // TH2D( "2d", "2d", n1, a1, b1, n2, a2, b2),
88 m_Set(false), m_name(name),
89 m_Nentries(NULL),
90 m_mean(NULL), m_sigma(NULL), m_chi2(NULL),
91 m_h2d(NULL), m_h1d(NULL),
92 m_dir(NULL),
93 m_xaxis(xaxis), m_yaxis(""), m_fitname(""), m_finalised(false),
94 m_uniform(true)
95 { Initialise(name, n1, a1, b1, n2, a2, b2); }
std::string m_name
Definition Resplot.h:642
void Initialise(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
Definition Resplot.cxx:195

◆ Resplot() [3/8]

Resplot::Resplot ( const std::string & name,
int n1,
const double * a1,
int n2,
double a2,
double b2,
const std::string & xaxis = "" )
inline

Definition at line 98 of file Resplot.h.

100 :
101 // TH2D( "2d", "2d", n1, a1, n2, a2, b2),
102 m_Set(false), m_name(name),
103 m_Nentries(NULL),
104 m_mean(NULL), m_sigma(NULL), m_chi2(NULL),
105 m_h2d(NULL), m_h1d(NULL),
106 m_dir(NULL),
107 m_xaxis(xaxis), m_yaxis(""), m_fitname(""), m_finalised(false),
108 m_uniform(true)
109 { Initialise(name, n1, a1, n2, a2, b2); }

◆ Resplot() [4/8]

Resplot::Resplot ( const std::string & name,
const std::vector< double > & a,
int n2,
double a2,
double b2,
const std::string & xaxis = "" )
inline

Definition at line 111 of file Resplot.h.

113 :
114 m_Set(false), m_name(name),
115 m_Nentries(NULL),
116 m_mean(NULL), m_sigma(NULL), m_chi2(NULL),
117 m_h2d(NULL), m_h1d(NULL),
118 m_dir(NULL),
119 m_xaxis(xaxis), m_yaxis(""), m_slices(), m_fitname(""), m_finalised(false),
120 m_uniform(true)
121 { Initialise(name, a, n2, a2, b2); }
static Double_t a
std::vector< TH1D * > m_slices
Definition Resplot.h:665

◆ Resplot() [5/8]

Resplot::Resplot ( const std::string & name,
const std::vector< double > & a,
const std::vector< double > & b,
const std::string & xaxis = "" )
inline

Definition at line 124 of file Resplot.h.

127 :
128 m_Set(false), m_name(name),
129 m_Nentries(NULL),
130 m_mean(NULL), m_sigma(NULL), m_chi2(NULL),
131 m_h2d(NULL), m_h1d(NULL),
132 m_dir(NULL),
133 m_xaxis(xaxis), m_yaxis(""), m_slices(), m_fitname(""), m_finalised(false),
134 m_uniform(false)
135 { Initialise(name, a, b); }

◆ Resplot() [6/8]

Resplot::Resplot ( const Resplot & r,
const std::string & tag = "" )
inline

Definition at line 139 of file Resplot.h.

139 :
140 // TH2D( (TH2D)r ),
141 TObject(r),
142 m_Set(r.m_Set), m_name(r.m_name+tag),
143 m_Nentries(new TH1D(*r.m_Nentries)),
144 m_mean(new TH1D(*r.m_mean)), m_sigma(new TH1D(*r.m_sigma)), m_chi2(new TH1D(*r.m_chi2)),
145 m_h2d(new TH2D(*r.m_h2d)), m_h1d(new TH1D(*r.m_h1d)),
146 m_dir(NULL),
147 m_n_primary(r.m_n_primary), // a_primary(r.a_primary), b_primary(r.b_primary),
148 m_n_secondary(r.m_n_secondary), m_a_secondary(r.m_a_secondary), m_b_secondary(r.m_b_secondary),
149 m_xaxis(r.m_xaxis), m_yaxis(r.m_yaxis), m_fitname(""), m_finalised(false),
150 m_uniform(true)
151 {
152 // TH2D::SetDirectory(0);
153 skip(m_h2d);
154 skip(m_h1d);
155 skip(m_mean);
156 skip(m_sigma);
157 skip(m_chi2);
159 }
int r
Definition globals.cxx:22

◆ Resplot() [7/8]

Resplot::Resplot ( const std::string & name,
TH2 * hin,
const bool flip = false )
inline

Definition at line 161 of file Resplot.h.

161 :
162 m_Set(false), m_name(name),
163 m_Nentries(NULL),
164 m_mean(NULL), m_sigma(NULL), m_chi2(NULL),
165 m_h2d(NULL), m_h1d(NULL),
166 m_dir(NULL),
167 m_xaxis(""), m_yaxis(""), m_fitname(""), m_finalised(false),
168 m_uniform(true)
169 {
170
171 TH2D* h = 0;
172
173 if ( flip ) h = rotate( hin );
174 else h = static_cast<TH2D*>(hin);
175
176 // get the major bin edges
177 std::vector<double> a1;
178
179 TAxis* axe = h->GetXaxis();
180
181 for ( int i=1 ; i<=axe->GetNbins()+1 ; i++ ) a1.push_back(axe->GetBinLowEdge(i));
182
183 // get the y bin limits
184 TH1D* s = h->ProjectionY("_duff", 1, 1, "e");
185
186 int n2 = s->GetNbinsX();
187 double a2 = s->GetBinLowEdge(1);
188 double b2 = s->GetBinLowEdge(s->GetNbinsX()+1);
189
190 delete s;
191
192 Initialise(name, a1, n2, a2, b2 );
193
194 // replace default histograms
195 delete m_h2d;
196 m_h2d = (TH2D*)h->Clone("2d");
197 skip(m_h2d);
198
199 delete m_h1d;
200 m_h1d = h->ProjectionY("1d", 1, h->GetNbinsX(), "e");
201 m_h1d->SetTitle("1d");
202 skip(m_h1d);
203 }
static TH2D * rotate(const TH2 *h)
flip the x and y axes
Definition Resplot.cxx:565

◆ Resplot() [8/8]

Resplot::Resplot ( const std::string & name)
inline

Definition at line 209 of file Resplot.h.

209 :
210 m_Set(false),
211 m_name(name),
212 m_dir(NULL),
213 m_n_secondary(0),
214 m_a_secondary(0.0),
215 m_b_secondary(0.0),
216 m_xaxis(""), m_yaxis(""), m_fitname(""), m_finalised(true),
217 m_uniform(true)
218 // m_Nentries ( new TH1D(*(TH1D*)gDirectory->Get((name+"/fractional uncertainty").c_str())) ),
219 // m_mean ( new TH1D(*(TH1D*)gDirectory->Get((name+"/1d").c_str())) ),
220 // m_sigma ( new TH1D(*(TH1D*)gDirectory->Get((name+"/sigma").c_str())) ),
221 // m_chi2 ( new TH1D(*(TH1D*)gDirectory->Get((name+"/chi2").c_str())) ),
222 // m_h2d ( new TH2D(*(TH2D*)gDirectory->Get((name+"/2d").c_str())) ),
223 // m_h1d ( new TH1D(*(TH1D*)gDirectory->Get((name+"/1d").c_str())) )
224 {
225
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()));
232
233 skip(m_h2d);
234 skip(m_h1d);
235 skip(m_mean);
236 skip(m_sigma);
237 skip(m_chi2);
239
240 m_n_primary = m_h2d->GetNbinsX();
241
242 // std::cout << "Resplot(std::string)" << name << "\t m_n_primary " << m_n_primary << std::endl;
243
244 // deep copy
245 for ( int i=1 ; i<=m_h2d->GetNbinsX() ; i++ ) {
246 char slicename[512];
247 sprintf(slicename, "/slices/slice[%03d]", i);
248 // std::cout << i << " " << (name+slicename) << std::endl;
249 m_slices.push_back((TH1D*)gDirectory->Get((name+slicename).c_str()));
250 skip(m_slices.back()); //->SetDirectory(0);
251 }
252
253 }

◆ ~Resplot()

Resplot::~Resplot ( )
virtual

Definition at line 176 of file Resplot.cxx.

176 {
177 // std::cout << "Resplot::~Resplot() " << Name() << std::endl;
178
180 delskip( m_h2d );
181 delskip( m_h1d );
182 delskip( m_mean );
183 delskip( m_sigma );
184 delskip( m_chi2 );
185
186 // std::cout << "Resplot::~Resplot() deleteing slices" << Name() << std::endl;
187
188 for ( unsigned i=0 ; i<m_slices.size() ; i++ ) delskip(m_slices[i]);
189
190 // TH2D::SetDirectory(0);
191}
void delskip(TH1D *t)
Definition Resplot.h:586

Member Function Documentation

◆ AddDirectory()

void Resplot::AddDirectory ( bool t = false)
inlinestatic

Definition at line 459 of file Resplot.h.

◆ AddDirectoryStatus()

bool Resplot::AddDirectoryStatus ( )
inlinestatic

Definition at line 458 of file Resplot.h.

458{ return s_mAddDirectoryStatus; }

◆ AddEfficiency()

void Resplot::AddEfficiency ( TH1D * h,
int i,
double lower,
double upper )
inlineprivate

Definition at line 605 of file Resplot.h.

605 {
606 StatVal v = GetGlobalEfficiency( lower, upper);
607 h->SetBinContent(i, v.value);
608 h->SetBinError(i, v.error);
609 }
int upper(int c)
StatVal GetGlobalEfficiency(double lower, double upper)
Definition Resplot.h:295

◆ AddMean()

void Resplot::AddMean ( TH1D * h,
int i )
inlineprivate

Definition at line 617 of file Resplot.h.

617 {
618 StatVal v = get_mean();
619 h->SetBinContent(i, v.value);
620 h->SetBinError(i, v.error);
621 }
StatVal get_mean()
Definition Resplot.h:601

◆ AddResolution()

void Resplot::AddResolution ( TH1D * h,
int i )
inlineprivate

Definition at line 611 of file Resplot.h.

611 {
612 StatVal v = get_sigma();
613 h->SetBinContent(i, v.value);
614 h->SetBinError(i, v.error);
615 }
StatVal get_sigma()
Definition Resplot.h:602

◆ Chi2() [1/2]

TH1D * Resplot::Chi2 ( )
inline

Definition at line 354 of file Resplot.h.

354{ return m_chi2; }

◆ Chi2() [2/2]

const TH1D * Resplot::Chi2 ( ) const
inline

Definition at line 355 of file Resplot.h.

355{ return m_chi2; }

◆ clear()

void Resplot::clear ( )
inlineprivate

Definition at line 625 of file Resplot.h.

625 {
626 // std::cout << "clear " << m_slices.size() << std::endl;
627 m_finalised = false;
628 for ( int i=m_slices.size() ; i-- ; ) if ( m_slices[i] ) delete m_slices[i];
629 m_slices.clear();
630 // std::cout << "cleared" << std::endl;
631 }

◆ combine() [1/4]

TH1D * Resplot::combine ( const TH1 * h,
double epsilon )
static

combine bins in a 2D histogram it takes a value, x and all the bins with BinLowEdge > x get combined N bins at a time.

Definition at line 834 of file Resplot.cxx.

834 {
835 return rebin( h, findbins(h, inveps2) );
836}
static TH1D * rebin(const TH1 *h, const std::vector< double > &bins)
Definition Resplot.cxx:892
static std::vector< double > findbins(const TH1 *h, double epsilon)
Definition Resplot.cxx:839

◆ combine() [2/4]

TH1D * Resplot::combine ( const TH1 * h,
double x,
int N )
static

after value x, combine each N bins into a single bin

combine bins in a 2D histogram it takes a value, x and all the bins with BinLowEdge > x get combined N bins at a time.

Definition at line 668 of file Resplot.cxx.

668 {
669
670 if ( N==0 ) return 0;
671
672 std::vector<double> xbins;
673
674 for ( int i=0 ; i<=h->GetNbinsX()+1 ; i++ ) {
675 xbins.push_back( h->GetBinLowEdge(i+1) );
676 if ( h->GetBinLowEdge(i+1)>x ) for ( int k=1 ; k<N ; k++, i++ );
677 }
678
679 if ( xbins.size()==0 ) {
680 std::cerr << "Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << std::endl;
681 return 0;
682 }
683
684 std::cout << "x: " << xbins[0] << " - " << xbins.back() << std::endl;
685
686 TH1D* h2 = new TH1D( (std::string(h->GetName())+"-duff").c_str(),"duff", xbins.size()-1, &xbins[0] );
687 h2->SetDirectory(0);
688
689
690 int xbin = 1;
691 for ( int i=0 ; i<h->GetNbinsX() ; i++ ) {
692 double entries = h->GetBinContent(i+1);
693 double errorsq = h->GetBinError(i+1)*h->GetBinError(i+1);
694 if ( h->GetBinLowEdge(i+1)>x ) {
695 for ( int k=1 ; k<N ; k++, i++ ) {
696 entries += h->GetBinContent(i+2);
697 errorsq += h->GetBinError(i+2)*h->GetBinError(i+2);
698 }
699 }
700
701 h2->SetBinContent(xbin, entries);
702 h2->SetBinError(xbin++, std::sqrt(errorsq) );
703 }
704
705 h2->SetEntries( h->GetEntries() );
706
707 return h2;
708}
#define x
double entries
Definition listroot.cxx:49

◆ combine() [3/4]

TH2D * Resplot::combine ( const TH2 * h,
double epsilon )
static

combine bins along the x axis combine bins such that the stat precision is better than epsilon

combine bins in a 2D histogram it takes a value, x and all the bins with BinLowEdge > x get combined N bins at a time.

bin contentes

bin error

Definition at line 716 of file Resplot.cxx.

716 {
717
718 std::cout << "combine" << std::endl;
719
720 // if ( epsilon==0 ) return 0;
721
722 std::vector<double> xbins;
723 std::vector<double> ybins;
724
725 std::cout << "projection" << std::endl;
726
727 TH1D* hx = (TH1D*)h->ProjectionX("r1dx", 1, h->GetNbinsY());
728 hx->SetDirectory(0);
729
730
731 // hy->SetDirectory(0);
732 // hx->SetDirectory(0);
733
734 // double inveps2 = 1/(epsilon*epsilon);
735
736 double N = 0;
737
738 bool newbin = true;
739
740 std::cout << "combining bins " << std::endl;
741
742 for ( int i=1 ; i<=hx->GetNbinsX() ; i++ ) {
743
744 TH1D* hy = (TH1D*)h->ProjectionY("r1dy", i, i );
745 hy->SetDirectory(0);
746 N += generate::GetEntries(hy);
747 delete hy;
748
749 if ( xbins.size()==0 ) {
750 if ( N==0 ) continue;
751 else xbins.push_back( hx->GetBinLowEdge(i) );
752 }
753
754 if ( newbin ) xbins.push_back( hx->GetBinLowEdge(i+1) );
755 else xbins.back() = hx->GetBinLowEdge(i+1);
756
757 newbin = false;
758
759 if ( xbins.size()>0 ) std::cout << i << "\tN " << N << " " << " (" << inveps2 << ")" << "\t" << xbins.back() << std::endl;
760
761 if ( N >= inveps2 ) {
762 newbin = true;
763 N = 0;
764 }
765 }
766
767 std::cout << "finishsed " << xbins.size() << std::endl;
768
769 TH1D* hy = (TH1D*)h->ProjectionY("1dy", 1, h->GetNbinsX());
770 hy->SetDirectory(0);
771 for ( int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
772
773 std::cout << "combine" << std::endl;
774 std::cout << "x bins " << hx->GetNbinsX() << "\t y bins " << hy->GetNbinsX() << std::endl;
775
776 if ( xbins.size()==0 || ybins.size()==0 ) {
777 std::cerr << "Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << "\tN ybins: " << ybins.size() << std::endl;
778 return 0;
779 }
780
781 std::cout << "x: " << xbins.size() << " " << xbins[0] << " - " << xbins.back() << std::endl;
782 std::cout << "y: " << ybins.size() << " " << ybins[0] << " - " << ybins.back() << std::endl;
783
784 TH2D* h2 = new TH2D( (std::string(h->GetName())+"-duff").c_str(), "duff", xbins.size()-1, &xbins[0], ybins.size()-1, &ybins[0] );
785 h2->SetDirectory(0);
786
787
788 for ( int j=1 ; j<=hy->GetNbinsX() ; j++ ) {
789
790 unsigned xbin = 0;
791
792 for ( int i=1 ; i<=hx->GetNbinsX() ; i++ ) {
793
794 while ( hx->GetBinCenter(i)>xbins[xbin+1] && xbin<(xbins.size()-1) ) xbin++;
795
796 if ( hx->GetBinCenter(i)>=xbins[xbin] && hx->GetBinCenter(i)<xbins[xbin+1] ) {
797
799 double n = h->GetBinContent(i,j);
800 double nh = h2->GetBinContent(xbin+1, j);
801 h2->SetBinContent(xbin+1, j, nh+n);
802
804 double ne = h->GetBinError(i,j);
805 double nhe = h2->GetBinError(xbin+1, j);
806 h2->SetBinError(xbin+1, j, std::sqrt( ne*ne + nhe*nhe ) );
807
808 }
809 }
810
811 }
812
813 h2->SetEntries( h->GetEntries() );
814
815 delete hy;
816 delete hx;
817
818 return h2;
819}
float j(const xAOD::IParticle &, const xAOD::TrackMeasurementValidation &hit, const Eigen::Matrix3d &jab_inv)
double GetEntries(TH1D *h, int ilow, int ihi)
Definition rmsFrac.cxx:20

◆ combine() [4/4]

TH2D * Resplot::combine ( const TH2 * h,
double x,
int N )
static

combine bins along the x axis after value x, combine each N bins into a single bin

combine bins in a 2D histogram it takes a value, x and all the bins with BinLowEdge > x get combined N bins at a time.

Definition at line 607 of file Resplot.cxx.

607 {
608
609 if ( N==0 ) return 0;
610
611 std::vector<double> xbins;
612 std::vector<double> ybins;
613
614 TH1D* hx = (TH1D*)h->ProjectionX("r1dx", 1, h->GetNbinsY());
615 TH1D* hy = (TH1D*)h->ProjectionY("r1dy", 1, h->GetNbinsX());
616
617 hy->SetDirectory(0);
618 hx->SetDirectory(0);
619
620 for ( int i=0 ; i<=hx->GetNbinsX()+1 ; i++ ) {
621 xbins.push_back( hx->GetBinLowEdge(i+1) );
622 if ( hx->GetBinLowEdge(i+1)>x ) for ( int k=1 ; k<N ; k++, i++ );
623 }
624
625 for ( int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
626
627 if ( xbins.size()==0 || ybins.size()==0 ) {
628 std::cerr << "Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << "\tN ybins: " << ybins.size() << std::endl;
629 return 0;
630 }
631
632 std::cout << "x: " << xbins[0] << " - " << xbins.back() << std::endl;
633 std::cout << "y: " << ybins[0] << " - " << ybins.back() << std::endl;
634
635 TH2D* h2 = new TH2D("duff","duff", xbins.size()-1, &xbins[0], ybins.size()-1, &ybins[0] );
636 h2->SetDirectory(0);
637
638
639 for ( int j=0 ; j<hy->GetNbinsX() ; j++ ) {
640 int xbin = 1;
641 for ( int i=0 ; i<hx->GetNbinsX() ; i++ ) {
642 double entries = h->GetBinContent(i+1,j+1);
643 double errorsq = h->GetBinError(i+1,j+1)*h->GetBinError(i+1,j+1);
644 if ( hx->GetBinLowEdge(i+1)>x ) {
645 for ( int k=1 ; k<N ; k++, i++ ) {
646 entries += h->GetBinContent(i+2,j+1);
647 errorsq += h->GetBinError(i+2,j+1)*h->GetBinError(i+2,j+1);
648 }
649 }
650 h2->SetBinContent(xbin, j+1, entries);
651 h2->SetBinError(xbin++, j+1, std::sqrt(errorsq) );
652 }
653 }
654
655 h2->SetEntries( h->GetEntries() );
656
657 delete hy;
658 delete hx;
659
660 return h2;
661}

◆ deletehist() [1/2]

void Resplot::deletehist ( TH1D * t)
inlineprivate

Definition at line 587 of file Resplot.h.

587{ if ( t ) delete t; }

◆ deletehist() [2/2]

void Resplot::deletehist ( TH2D * t)
inlineprivate

Definition at line 591 of file Resplot.h.

591{ if ( t ) delete t; }

◆ delskip() [1/2]

void Resplot::delskip ( TH1D * t)
inlineprivate

Definition at line 586 of file Resplot.h.

586{ if ( t ) { t->SetDirectory(0); delete t; } }

◆ delskip() [2/2]

void Resplot::delskip ( TH2D * t)
inlineprivate

Definition at line 590 of file Resplot.h.

590{ if ( t ) { t->SetDirectory(0); delete t; } }

◆ Dir()

TDirectory * Resplot::Dir ( )
inline

Definition at line 448 of file Resplot.h.

448{ return m_dir; }

◆ DWrite()

Int_t Resplot::DWrite ( TDirectory * g = 0) const

boooo, need to use the stupid Int_t class because I foolishly gave this function the same name as TObject::Write

Definition at line 343 of file Resplot.cxx.

343 {
344
345 // std::cout << "Resplot::Write() Name " << Name() << "; " << gDirectory->GetName();
346
347 TDirectory* cwd = gDirectory;
348 if ( g ) g->cd();
349 Directory d(Name());
350 d.push();
351
352 // std::cout << "/" << gDirectory->GetName() << std::endl;
353
354 // TH2D::Write();
355 m_h2d->Write();
356 m_h1d->Write();
357 m_mean->Write();
358 m_sigma->Write();
359 m_chi2->Write();
360 m_Nentries->Write();
361 // std::cout << "Resplot::Write() Name() " << Name() << " " << m_slices.size() << std::endl;
362 gDirectory->mkdir("slices")->cd();
363 for ( unsigned i=0 ; i<m_slices.size() ; i++ ) m_slices[i]->Write();
364 d.pop();
365 cwd->cd();
366
367 return 0;
368}
const std::string & Name() const
Definition Resplot.h:342
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...
Definition Resplot.h:454
std::string cwd
Definition listroot.cxx:38

◆ Fill()

int Resplot::Fill ( double x,
double y,
double w = 1 )
inline

Definition at line 281 of file Resplot.h.

281 {
282 // m_h2d->Fill(x, y, w);
283 // TH2D::Fill(x, y, w);
284 m_h2d->Fill(x, y, w);
285 m_h1d->Fill(y, w);
286 return 0;
287 }
#define y

◆ Finalise() [1/2]

int Resplot::Finalise ( double a = -999,
double b = -999,
TF1 *(* func )(TH1D *s, double a, double b) = Resplot::FitGaussian )

Definition at line 389 of file Resplot.cxx.

389 {
390
391 // gDirectory->pwd();
392
393 s_ErrorSet = OK;
394
395 // std::cout << "Resplot::Finalise() Name " << Name() << "\tm_n_primary " << m_n_primary << std::endl;
396
397 gStyle->SetOptFit(1111);
398 gStyle->SetOptStat(2211);
399
400 if ( m_finalised ) {
401 std::cerr << "Resplot::Finalise() " << m_name << " already called" << std::endl;
402 return -1;
403 }
404
405 // std::cout << "Resplot::Finalise() " << m_name << std::endl;
406
407 clear();
408
409 m_mean->SetStats(false);
410 m_sigma->SetStats(false);
411
412#if 1
413
414 for ( int i=1 ; i<=m_n_primary ; i++ ) {
415
416 if ( i%1000==0 ) std::cout << "slice " << i << " of " << m_n_primary << std::endl;
417
418 // std::string projname = tagname(m_name,i).c_str();
419 double pllim = m_mean->GetBinLowEdge(i);
420 double pulim = m_mean->GetBinLowEdge(i+1);
421
422 // std::cout << "Finalise " << i << " : " << pllim << " - " << pulim << std::endl;
423
424 std::string projname;
425 if ( m_xaxis=="" ) projname = "[ " + number(pllim) + " - " + number(pulim) + " ]";
426 else projname = "[ " + number(pllim) + " < " + m_xaxis + " < " + number(pulim) + " ]";
427
428 TH1D* s;
429 if ( !m_finalised ) {
430 s = m_h2d->ProjectionY(tagname("slice",i), i, i, "e");
431
432 // std::cout << i << " fitnull " << getWeights( s ) << std::endl;
433
434 if ( !m_uniform ) binwidth(s);
435 s->SetTitle(projname.c_str());
436 if ( m_yaxis!="" ) s->SetXTitle(m_yaxis.c_str());
437 }
438 else s = (TH1D*)gDirectory->Get(tagname(m_name,i));
439 skip(s);
440
441 // ZeroErrors(s);
442
443 TF1* f1 = 0;
444
445
446 if ( !s_nofit ) f1 = func(s, a, b);
447
448 // std::cout << "nofit " << s_nofit << "\tf1 " << f1 << std::endl;
449
450
451 // unZeroErrors(s);
452
453
454 if ( f1!=0 ) {
455
456 f1->SetLineWidth(1);
457 f1->SetNpx(5000);
458 m_fitname = f1->GetName();
459
460 // double N = NCounter(s);
461 double N = s->GetEffectiveEntries();
462
463 if ( N!=0 ) {
464 m_Nentries->SetBinContent(i,1/sqrt(N));
465 m_Nentries->SetBinError(i,0);
466 }
467 else {
468 m_Nentries->SetBinContent(i,0);
469 m_Nentries->SetBinError(i,0);
470 }
471
472 m_mean->SetBinContent(i, f1->GetParameter(1) );
473 m_mean->SetBinError(i, f1->GetParError(1) );
474
475 m_sigma->SetBinContent(i, std::fabs(f1->GetParameter(2)) );
476 m_sigma->SetBinError(i, f1->GetParError(2) );
477
478 int Ndof = f1->GetNDF();
479 if ( Ndof ) m_chi2->SetBinContent( i, std::fabs(f1->GetChisquare())/Ndof );
480 m_chi2->SetBinError(i, 0 );
481 delete f1;
482 }
483 else {
484 m_Nentries->SetBinContent(i,0);
485 m_mean->SetBinContent(i,0);
486 m_mean->SetBinError(i,0);
487 m_sigma->SetBinContent(i,0);
488 m_sigma->SetBinError(i,0);
489 m_chi2->SetBinContent(i,0);
490 m_chi2->SetBinError(i,0);
491 }
492
493 // std::cout << "Resplot::Finalise() slice " << s->GetName() << std::endl;
494
495 m_slices.push_back(s);
496 }
497
498
499
500#endif
501
502
503 m_chi2->SetMinimum(1e-5);
504
505 // get the overall resolution and offset
506
507 if ( !m_uniform ) binwidth(m_h1d);
508
509 TF1* f2 = 0;
510
511 if ( !s_nofit ) {
513 f2 = func(m_h1d, a, b);
515 }
516
517 if ( f2!=0 ) {
518
519 // std::cout << " fit = " << f2 << std::endl;
520 f2->SetLineWidth(1);
521 f2->SetNpx(5000);
522
523 m_g_mean = StatVal( f2->GetParameter(1), f2->GetParError(1) );
524 m_g_sigma = StatVal( f2->GetParameter(2), f2->GetParError(2) );
525
526 // std::cout << gDirectory->GetName() << "\tgmean " << m_g_mean << "\tgsigma " << g_sigma << std::endl;
527
528 std::string mname = std::string(f2->GetParName(1));
529 std::string sname = std::string(f2->GetParName(2));
530
531 // if ( mname!=std::string("") ) { m_mean->SetName(mname.c_str()); m_mean->SetTitle(mname.c_str()); }
532 // if ( sname!=std::string("") ) { m_sigma->SetName(sname.c_str()); m_sigma->SetTitle(sname.c_str()); }
533 if ( mname!=std::string("") ) { m_mean->SetTitle(mname.c_str()); }
534 if ( sname!=std::string("") ) { m_sigma->SetTitle(sname.c_str()); }
535
536 delete f2;
537 }
538 else {
539 if ( !s_nofit ) std::cerr << "null overall fit Resplot:" << m_name << std::endl;
540 m_g_mean = StatVal(0,0);
541 m_g_sigma = StatVal(0,0);
542 }
543
544
545 if ( AddDirectoryStatus() ) SetDirectory(gDirectory);
546
547 m_finalised = true;
548
549 if ( s_ErrorSet!=OK ) {
550 if ( s_ErrorSet == HISTOWIDTH ) {
551 std::cerr << __FUNCTION__ << " for " << m_name
552 << " :\tdistribution wider than histogram width " << std::endl;
553 }
554 if ( s_ErrorSet == BINWIDTH ) {
555 std::cerr << __FUNCTION__ << " for " << m_name
556 << " :\tbins too wide: cannot calculate rms95 " << std::endl;
557 }
558 }
559
560 return 0;
561}
void ZeroErrors(TH1D *h)
Definition Resplot.cxx:66
void unZeroErrors(TH1D *h)
Definition Resplot.cxx:72
static bool s_nofit
Definition Resplot.h:678
StatVal m_g_mean
Definition Resplot.h:652
static bool AddDirectoryStatus()
Definition Resplot.h:458
void SetDirectory(TDirectory *=0)
Definition Resplot.h:461
StatVal m_g_sigma
Definition Resplot.h:653
void clear()
Definition Resplot.h:625
static ERROR s_ErrorSet
Definition Resplot.h:681
bool binwidth
Definition listroot.cxx:58
std::string number(const double &d, const std::string &s)
Definition utils.cxx:186

◆ Finalise() [2/2]

int Resplot::Finalise ( TF1 *(* func )(TH1D *s, double a, double b),
double a = -999,
double b = -999 )
inline

Definition at line 433 of file Resplot.h.

433 {
434 return Finalise( a, b, func);
435 }
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=Resplot::FitGaussian)
Definition Resplot.cxx:389

◆ finalised()

bool Resplot::finalised ( ) const
inline

Definition at line 369 of file Resplot.h.

369{ return m_finalised; }

◆ findbins()

std::vector< double > Resplot::findbins ( const TH1 * h,
double epsilon )
static

Definition at line 839 of file Resplot.cxx.

839 {
840
841 std::cout << "combine" << std::endl;
842
843 // if ( epsilon==0 ) return 0;
844
845 std::vector<double> xbins;
846
847
848 // hy->SetDirectory(0);
849 // hx->SetDirectory(0);
850
851 // double inveps2 = 1/(epsilon*epsilon);
852
853 double N = 0;
854
855 bool newbin = true;
856
857 std::cout << "combining bins " << std::endl;
858
859 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
860
861 N += h->GetBinContent(i);
862
863 if ( xbins.size()==0 ) {
864 if ( N==0 ) continue;
865 else xbins.push_back( h->GetBinLowEdge(i) );
866 }
867
868 if ( newbin ) xbins.push_back( h->GetBinLowEdge(i+1) );
869 else xbins.back() = h->GetBinLowEdge(i+1);
870
871 newbin = false;
872
873 if ( xbins.size()>0 ) std::cout << i << "\tN " << N << " " << " (" << inveps2 << ")" << "\t" << xbins.back() << std::endl;
874
875 if ( N >= inveps2 ) {
876 newbin = true;
877 N = 0;
878 }
879 }
880
881 std::cout << "finishsed " << xbins.size() << std::endl;
882
883 std::cout << "combine" << std::endl;
884 std::cout << "x bins " << h->GetNbinsX() << std::endl;
885
886 std::cout << "x: " << xbins.size() << " " << xbins[0] << " - " << xbins.back() << std::endl;
887
888 return xbins;
889}

◆ Fit()

int Resplot::Fit ( TF1 *(* func )(TH1D *s, double a, double b))
inline

Definition at line 437 of file Resplot.h.

437 {
438 if ( m_finalised ) return -1;
439 return Finalise( func );
440 }

◆ FitATan()

TF1 * Resplot::FitATan ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 1199 of file Resplot.cxx.

1199 {
1200 static int counter = 0;
1201
1202 std::cout << "Resplot::FitATan() " << s->GetName() << " " << s->GetTitle() << std::endl;
1203
1204 char name[8];
1205 sprintf(name,"atan_%02d", counter); counter++;
1206
1207 // Cannot use "M_PI" here as root does not replace M_PI in the string expressions for function in TF1 definition
1208 TF1* f1 = new TF1(name, "100*pow( (0.01*[3]-sqrt(0.0001*[2]*[2]))*(0.5-(1/3.14159)*atan( [1]*(x-[0]) ) )+sqrt(0.0001*[2]*[2]) , [4] ) ", -100, 100);
1209
1210 f1->SetParName(0, "Mean");
1211 f1->SetParName(1, "Gradient");
1212 f1->SetParName(2, "Pedestal");
1213 f1->SetParName(3, "Norm");
1214 f1->SetParName(4, "Power");
1215
1216 int maxn=1;
1217 for ( int i=1 ; i<=s->GetNbinsX() ; i++ ) if ( s->GetBinContent(maxn)<s->GetBinContent(i) ) maxn = i;
1218
1219
1220 // f1->SetParameter(0,s->GetBinContent(maxn) );
1221 // f1->SetParameter(1,s->GetBinCenter(s->GetNbinsX()/2) );
1222 // f1->SetParameter(2,0.25);
1223
1224 f1->SetParameter(0, 2 );
1225 f1->SetParameter(1, 10 );
1226 f1->SetParameter(2, 0.001 );
1227 f1->SetParameter(3, 100 );
1228 f1->SetParameter(4, 1 );
1229
1230 f1->FixParameter(2, 0);
1231 f1->FixParameter(3, 100);
1232 // f1->FixParameter(4, 1);
1233
1234 f1->SetNpx(5000);
1235 f1->SetLineWidth(1);
1236
1237
1238 // int nbins=0;
1239
1240
1241 // ZeroErrors(s);
1242 s->SetMarkerStyle(20);
1243
1244
1245 // int n=0;
1246 // for ( int i=1 ; i<=s->GetNbinsX() ; i++ ) if ( s->GetBinContent() ) n++;
1247 // if ( n>2 ) s->Fit(f1,"Q");
1248
1249 s->Fit(f1,"Q");
1250
1251 std::cout << "par0 = " << f1->GetParameter(0) << std::endl;
1252 std::cout << "par1 = " << f1->GetParameter(1) << std::endl;
1253 std::cout << "par2 = " << f1->GetParameter(2) << std::endl;
1254 std::cout << "par3 = " << f1->GetParameter(3) << std::endl;
1255 std::cout << "par4 = " << f1->GetParameter(4) << std::endl;
1256
1257
1258 // unZeroErrors(s);
1259 // s->SetMaximum(f1->GetParameter(0)*1.1);
1260 // double range = s->GetBinLowEdge(s->GetNbinsX()+1) - s->GetBinLowEdge(1) ;
1261
1262 return f1;
1263}

◆ FitBreit()

TF1 * Resplot::FitBreit ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 1160 of file Resplot.cxx.

1160 {
1161
1162 // TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))", -100, 100 );
1163 TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
1164
1165 f1->SetParName(0, "Maximum");
1166 f1->SetParName(1, "Median");
1167 f1->SetParName(2, "Gamma");
1168
1169 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1170 f1->SetParameter(1,s->GetMean());
1171 f1->SetParameter(2,s->GetRMS()*0.5);
1172
1173 f1->SetNpx(5000);
1174 f1->SetLineWidth(1);
1175
1176 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)==0) s->SetBinError(j, 1);
1177
1178
1179 int nbins=0;
1180 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1181
1182 if (nbins>2) {
1183 // std::cout << "fitting " << f1 << std::endl;
1184 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1185 else s->Fit(f1,"Q", "", a, b);
1186 }
1187 else {
1188 for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1189 }
1190
1191 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)==0) s->SetBinError(j, 0);
1192
1193 return f1;
1194}

◆ FitCentralGaussian()

TF1 * Resplot::FitCentralGaussian ( TH1D * s,
double a = -999,
double b = -999 )
static

if the fit is "bad" fit only to the central region

calculate difference from maximum of fit, and hist maximum

Definition at line 1081 of file Resplot.cxx.

1081 {
1082 TF1* f1 = new TF1("gausr", "gaus");
1083
1084 f1->SetNpx(5000);
1085 f1->SetLineWidth(1);
1086
1087 double mean = 0;
1088 double sigma = 0;
1089
1090
1091 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1092 f1->SetParameter(1,mean=s->GetBinCenter(s->GetMaximumBin()));
1093 f1->SetParameter(2,sigma=s->GetRMS());
1094
1095 int nbins=0;
1096 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
1097
1098 if (nbins>2) {
1099
1100 TH1D* s_tmp = (TH1D*)s->Clone("duff");
1101 s_tmp->SetDirectory(0);
1102 s_tmp->Fit(f1,"Q");
1103
1104
1106
1108
1109 // double sig = std::sqrt( f1->GetParError(0)*f1->GetParError(0) + s->GetBinError(s->GetMaximumBin())*s->GetBinError(s->GetMaximumBin()) );
1110 // double diff = std::fabs( (f1->GetParameter(0) - s->GetBinContent(s->GetMaximumBin()) ) )/sig;
1111
1112 // std::cout << "diff " << diff << "\tfit " << f1->GetParameter(0) << "\thist " << s->GetBinContent(s->GetMaximumBin()) << std::endl;
1113
1114 // if ( diff>2 ) {
1115
1116
1117 // double n = s->GetBinContent(s->GetMaximumBin());
1118
1119 double frac = 1.25;
1120
1121 // if ( n<25 ) {
1122 // frac = 1.2*n/25.0 + 4.0*(25.0-n)/25.0;
1123 // }
1124
1125 double llim = f1->GetParameter(1)-frac*f1->GetParameter(2);
1126 double ulim = f1->GetParameter(1)+frac*f1->GetParameter(2);
1127
1128
1129
1130 int nbins=0;
1131 for (int j=1 ; j<=s->GetNbinsX() ; j++) if ( s->GetBinCenter(j)>llim && s->GetBinCenter(j)<ulim ) nbins++;
1132
1133 if ( nbins>2 ) {
1134
1135 // if ( frac>3 ) s->Fit(f1,"Q");
1136 // else s->Fit(f1,"Q", "", llim, ulim);
1137
1138 if ( frac>3 ) s->Fit(f1,"Q");
1139 else s->Fit(f1,"Q", "", llim, ulim);
1140
1141 }
1142 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1143
1144 delete s_tmp;
1145
1146
1147
1148 // std::cout << "Resplot::Finalise() " << s->GetName() << "\trange " << lower << " - " << upper << std::endl;
1149
1150 }
1151 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1152
1153 return f1;
1154}
void mean(std::vector< double > &bins, std::vector< double > &values, const std::vector< std::string > &files, const std::string &histname, const std::string &tplotname, const std::string &label="")

◆ FitGaussian()

TF1 * Resplot::FitGaussian ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 1026 of file Resplot.cxx.

1026 {
1027 TF1* f1 = new TF1("gausr", "gaus");
1028 return FitInternal( s, a, b, f1 );
1029 // s->GetXaxis()->SetRangeUser(-1, 1);
1030}
static TF1 * FitInternal(TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
Definition Resplot.cxx:1052

◆ FitInternal()

TF1 * Resplot::FitInternal ( TH1D * s,
double a = -999,
double b = -999,
TF1 * f1 = 0 )
static

Definition at line 1052 of file Resplot.cxx.

1052 {
1053
1054 if ( f1==0 ) return f1;
1055
1056 f1->SetNpx(5000);
1057 f1->SetLineWidth(1);
1058
1059 double mean = 0;
1060 double sigma = 0;
1061
1062
1063 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1064 f1->SetParameter(1,mean=s->GetBinCenter(s->GetMaximumBin()));
1065 f1->SetParameter(2,sigma=s->GetRMS());
1066
1067 int nbins=0;
1068 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
1069
1070 if (nbins>2) {
1071 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1072 else s->Fit(f1,"Q", "", a, b);
1073 }
1074 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1075
1076 return f1;
1077}

◆ FitLandauGauss()

TF1 * Resplot::FitLandauGauss ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 2061 of file Resplot.cxx.

2061 {
2062 // TF1* f1 = new TF1("landgaus", "landgaus");
2063 // root is STUPID and you have to specify the FIT RANGE if you
2064 // want to specify the number of fit parameters!!!
2065 TF1* f1 = new TF1("landgaus", langaufun, 0, 1, 4);
2066
2067 f1->SetNpx(5000);
2068 f1->SetLineWidth(1);
2069
2070 // parameter starting values
2071 double start_vals[4]; // = { 0.1, 3.0, 1.0, 0.3 };
2072
2073 start_vals[0] = s->GetEntries();
2074 start_vals[1] = s->GetBinCenter(s->GetMaximumBin());
2075 start_vals[2] = s->GetRMS();
2076 start_vals[3] = 0.5*start_vals[2];
2077
2078 f1->SetParNames("Area", "MP", "Width", "GSigma");
2079 f1->SetParameters(start_vals);
2080
2081 // parameter low and high values for the fit
2082 // double par_lo[4] = { 0.0, -20.0, 0.0, 0.00 };
2083 // double par_hi[4] = { 20000.0, 50000.0, 50.0, 0.01 };
2084 // for ( int i=0 ; i<4 ; i++ ) f1->SetParLimits(i, par_lo[i], par_hi[i]);
2085 f1->SetParLimits( 2, 0.1*start_vals[2], 10*start_vals[2] );
2086 f1->SetParLimits( 3, 0.0, 10*start_vals[2] );
2087
2088 int nbins=0;
2089 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
2090
2091 if (nbins>2) {
2092 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
2093 else s->Fit(f1,"Q", "", a, b);
2094 // if ( a==-999 || b==-999 ) s->Fit(f1);
2095 // else s->Fit(f1,"", "", a, b);
2096 }
2097 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
2098
2099 return f1;
2100}
Double_t langaufun(Double_t *x_par, Double_t *par)
Definition Resplot.cxx:1997

◆ FitName()

const std::string & Resplot::FitName ( ) const
inline

Definition at line 377 of file Resplot.h.

377{ return m_fitname; }

◆ FitNull()

TF1 * Resplot::FitNull ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 1267 of file Resplot.cxx.

1267 {
1268
1269 // unZeroErrors(s);
1270
1271 TF1* f=new TF1("null", "[0]+[1]+[2]");
1272
1273 f->SetParName(0, "Maximum");
1274 f->SetParName(1, "Mean");
1275 f->SetParName(2, "RMS");
1276
1277 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1278 f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1279 f->FixParameter(2, s->GetRMS()); f->SetParError(2, s->GetRMSError());
1280
1281 // std::cout << gDirectory->GetName() << " " << s->GetName() << "\tFitNull mean: " << f->GetParameter(1) << "\tsigma: " << f->GetParameter(2) << std::endl;
1282
1283 return f;
1284}

◆ FitNull95()

TF1 * Resplot::FitNull95 ( TH1D * s,
double a = 0,
double b = 0 )
static

use approximate root errors for speed

Definition at line 1652 of file Resplot.cxx.

1652 {
1653 // if ( s_oldrms95 ) return Resplot::FitNull95Obsolete(s, 0.95, true ); /// use approximate root errors for speed
1654 if ( s_oldrms95 ) return Resplot::FitNull95Obsolete( s, 0.95 );
1655 else return Resplot::FitNull95New(s);
1656}
static TF1 * FitNull95New(TH1D *s, double frac=0.95, bool useroot=false)
Definition Resplot.cxx:1666
static bool s_oldrms95
temporarily allow toggeling between old and new rms95 error estimates
Definition Resplot.h:675
static TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
Definition Resplot.cxx:1387

◆ FitNull95Central()

TF1 * Resplot::FitNull95Central ( TH1D * s)
static

NB: try to find with respect to maximum bin, rather than the mean. double m = s->GetMean();

double m = FindMean(s); int imax = s->GetXaxis()->FindBin(m);

root does not calculate the uncertainty on the rms correctly

Definition at line 1733 of file Resplot.cxx.

1733 {
1734
1735 TF1* f=new TF1("null", "[0]+[1]+[2]");
1736
1737 f->SetParName(0, "Maximum");
1738 f->SetParName(1, "Mean");
1739 f->SetParName(2, "RMS");
1740
1741 f->SetParameter(0, 0);
1742 f->SetParameter(1, 0);
1743 f->SetParameter(2, 0);
1744
1745 if ( s==0 ) { std::cerr << "Resplot::FitNull95() histogram s = " << s << std::endl; return 0; }
1746 if ( s->GetXaxis()==0) { std::cerr << "Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl; return 0; }
1747
1748 // std::cout << "FitNull " << s->GetName() << " " << generate::GetEntries(s) << std::endl;
1749
1750 if ( generate::GetEntries(s)<20 ) return f;
1751 // if ( s->GetEffectiveEntries<20 ) return f;
1752
1753 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1754 // s->GetXaxis()->UnZoom();
1755
1756
1759
1762
1763 int imax = findmax(s);
1764
1765 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1766 // f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1767
1768
1769 double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1770
1771 // double sumx = s->GetBinContent(imax)*s->GetBinCenter(imax);
1772 // double sumx2 = s->GetBinContent(imax)*s->GetBinCenter(imax)*s->GetBinCenter(imax);
1773 double sumn = s->GetBinContent(imax);
1774
1775 double frac = 0.95;
1776
1777 int upperbin = imax;
1778 int lowerbin = imax;
1779
1780 double uppersum = 0;
1781 double lowersum = 0;
1782
1783 if ( entries>0 ) {
1784
1785 int i=1;
1786 while ( true ) {
1787
1788 const int upperbin_i = imax+i;
1789 const int lowerbin_i = imax-i;
1790
1791 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1792
1793 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1794
1795 if ( tsum>entries*frac ) { uppersum = tsum/entries; break; }
1796
1797 lowersum = tsum/entries;
1798
1799 sumn = tsum;
1800
1801 upperbin = upperbin_i;
1802 lowerbin = lowerbin_i;
1803
1804 i++;
1805 }
1806 }
1807
1808 // std::cout << "FitNull95 " << s->GetName() << " " << upperbin << " " << lowerbin << std::endl;
1809
1810 // std::cout << "full rms " << s->GetRMS() << " +- " << s->GetRMSError() << "\t n=" << s->GetNbinsX()
1811 // << "\tfrac " << ( entries>0 ? sumn/entries : 0 ) << " - " << uppersum
1812 // << std::endl;
1813
1814 // std::cout << "upper " << upperbin << " " << lowerbin << " " << interpolate_flag << std::endl;
1815
1816 if ( upperbin!=lowerbin ) {
1817
1818 double llim = s->GetBinLowEdge(1);
1819 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1820
1821 double rms = 0;
1822 double erms = 0;
1823
1824 std::vector<double> stats;
1825
1826 if ( s_interpolate_flag ) {
1827 s->GetXaxis()->SetRange(lowerbin, upperbin);
1828
1829
1830 double rlower;
1831 double erlower;
1832
1833 double rupper;
1834 double erupper;
1835
1836
1838
1839 GetStats( s, stats );
1840 rlower = stats[2];
1841 erlower = stats[3];
1842
1843 // std::cout << "FitNULL95() " << s->GetName() << "\t lower rms " << rlower << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1844 // std::cout << s->GetName() << " " << s->GetTitle() << "\t lower 95% rms " << rlower << " +- " << erlower << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1845
1846 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1847
1848 GetStats( s, stats );
1849 rupper = stats[2];
1850 erupper = stats[3];
1851
1852 // std::cout << "FitNULL95() " << s->GetName() << "\t upper rms " << rupper << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1853
1854 // std::cout << s->GetName() << " " << s->GetTitle() << "\t upper 95% rms " << rupper << " +- " << erupper << "\t( " << lowerbin-1 << " - " << upperbin+1 << " )" << std::endl;
1855
1856 rms = rlower + (0.95-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1857 erms = erlower + (0.95-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1858
1859 }
1860 else {
1861 s->GetXaxis()->SetRange(lowerbin, upperbin);
1862 GetStats( s, stats );
1863 rms = stats[2];
1864 erms = stats[3];
1865
1866 }
1867
1868
1869 // f->FixParameter(2, s->GetRMS());
1870 // f->SetParError(2, s->GetRMSError());
1871 f->FixParameter(2, rms);
1872 f->SetParError(2, erms);
1873 f->FixParameter(1, s->GetMean());
1874 f->SetParError(1, s->GetMeanError());
1875 // std::cout << s->GetName() << " " << s->GetTitle() << "\t 95% inter rms " << rms << " +- " << erms << std::endl;
1876 s->GetXaxis()->SetRangeUser(llim, ulim);
1877 }
1878 else {
1879 f->FixParameter(1, 0);
1880 f->SetParError(1, 0);
1881 f->FixParameter(2, 0);
1882 f->SetParError(2, 0);
1883 // std::cout << " 95% rms " << 0 << " +- " << 0 << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1884 }
1885
1886 s->GetXaxis()->SetRange(1, s->GetNbinsX());
1887
1888 return f;
1889}
int findmax(TH1D *s)
Definition Resplot.cxx:1375
void GetStats(TH1D *h, std::vector< double > &stats)
Definition Resplot.cxx:112
int imax(int i, int j)
static bool s_interpolate_flag
Definition Resplot.h:636

◆ FitNull95New()

TF1 * Resplot::FitNull95New ( TH1D * s,
double frac = 0.95,
bool useroot = false )
static

calculate the

a "corrected" rms of the inner 0.95% of the data, corrected such that for a gaussian, will return 1.

Definition at line 1666 of file Resplot.cxx.

1666 { // double frac, bool useroot ) {
1667
1668 // std::cout << "---------------------------------------\nFN95 " << std::endl;
1669
1670 TF1* f=new TF1("null", "[0]+[1]+[2]");
1671
1672 f->SetParName(0, "Maximum");
1673 f->SetParName(1, "Mean");
1674 f->SetParName(2, "RMS");
1675
1676 f->SetParameter(0, 0);
1677 f->SetParameter(1, 0);
1678 f->SetParameter(2, 0);
1679
1680 if ( s->GetEffectiveEntries()==0 ) return f;
1681
1682
1683 // double _entries = getWeights( s );
1684 const double entries = s->GetEffectiveEntries();
1685
1686
1687 // int nexperiments = 20+int(800/std::sqrt(s->GetEntries()));
1688 // int nexperiments = 20+int(800/std::sqrt(s->GetEntries()));
1689 int nexperiments = 20+int(1000/entries);
1690
1691 if ( nexperiments_!=0 ) nexperiments = nexperiments_;
1692
1693
1694 if ( nexperiments>nexperiments_max ) nexperiments = nexperiments_max;
1695 if ( nexperiments<nexperiments_min ) nexperiments = nexperiments_min;
1696
1697 // std::cout << "FitNull95 entries " << entries << "\tnexperiments " << nexperiments << std::endl;
1698
1699 // std::cout << "experiments " << nexperiments_ << std::endl;
1700
1701 // std::cout << "h entries " << s->GetEntries() << "\tn experiments " << nexperiments << "\tN " << s->GetEntries()*nexperiments << std::endl;
1702
1704 generate::experiment e( s, nexperiments, entries );
1705
1708 double scale = 1;
1709 if ( s_scalerms95 ) scale = 1.1479538518;
1710
1711 // f->FixParameter( 1, s->GetMean() );
1712 f->FixParameter( 1, e.hmean() );
1713 f->SetParError( 1, e.mean_error() );
1714
1715 f->FixParameter( 2, scale*e.hrms() );
1716 f->SetParError( 2, scale*e.rms_error() );
1717
1718 // s->GetXaxis()->SetRange(1, s->GetNbinsX());
1719
1720 // s->GetXaxis()->SetRangeUser(-1, 1);
1721
1722 return f;
1723}
int nexperiments_max
Definition Resplot.cxx:1661
int nexperiments_
Definition Resplot.cxx:1660
int nexperiments_min
Definition Resplot.cxx:1662
static bool s_scalerms95
Definition Resplot.h:676

◆ FitNull95Obsolete()

TF1 * Resplot::FitNull95Obsolete ( TH1D * s,
double frac = 0.95,
bool useroot = false )
static

this line causes a crash, even though s->GetXaxis() returns the x axis ok

root does not calculate the uncertainty on the rms correctly

a "corrected" rms of the inner 0.95% of the data, corrected such that for a gaussian, will return 1.

Definition at line 1387 of file Resplot.cxx.

1387 {
1388
1389 TF1* f=new TF1("null", "[0]+[1]+[2]");
1390
1391 f->SetParName(0, "Maximum");
1392 f->SetParName(1, "Mean");
1393 f->SetParName(2, "RMS");
1394
1395 f->SetParameter(0, 0);
1396 f->SetParameter(1, 0);
1397 f->SetParameter(2, 0);
1398
1399 if ( s==0 ) { std::cerr << "Resplot::FitNull95() histogram s = " << s << std::endl; return 0; }
1400 if ( s->GetXaxis()==0) { std::cerr << "Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl; return 0; }
1401
1402 unZeroErrors(s);
1403
1404 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1405
1406#if 0
1407 std::cout << "FitNull95 " << s->GetName()
1408 << " " << generate::GetEntries(s)
1409 << " " << generate::GetEntries(s, 0, s->GetNbinsX()+1)
1410 << std::endl;
1411#endif
1412
1413
1414 if ( generate::GetEntries(s)<10 ) return f;
1415
1416 // std::cout << "---------------------------------------\nFN95O frac: " << frac << " " << s << std::endl;
1417
1418 // std::cout << __LINE__ << std::endl;
1419
1420
1421
1422 // std::cout << __LINE__ << " " << s->GetXaxis() << std::endl;
1423
1426 // s->GetXaxis()->UnZoom();
1427
1428 // std::cout << __LINE__ << std::endl;
1429
1430 // double m = s->GetMean();
1431 double m = FindMean(s,frac);
1432
1433 // std::cout << __LINE__ << std::endl;
1434
1435 int imax = s->GetXaxis()->FindBin(m);
1436
1437 // std::cout << "mean " << m << " " << imax << " max " << s->GetBinCenter(findmax(s)) << " " << findmax(s) << std::endl;
1438
1439 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, std::sqrt(s->GetMaximum()));
1440 // f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1441
1442 // double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1443 double entries = generate::GetEntries(s,0,(s->GetNbinsX()+1));
1444
1445 // std::cout << "entries: " << entries << "\t" << generate::GetEntries(s) << "\t" << generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1446
1447 // double sumx = s->GetBinContent(imax)*s->GetBinCenter(imax);
1448 // double sumx2 = s->GetBinContent(imax)*s->GetBinCenter(imax)*s->GetBinCenter(imax);
1449
1450 double sumn = s->GetBinContent(imax);
1451
1452 int upperbin = imax;
1453 int lowerbin = imax;
1454
1455 double uppersum = 0;
1456 double lowersum = 0;
1457
1458 if ( sumn>entries*frac ) {
1459 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1461 return f;
1462 }
1463
1464 if ( entries>0 ) {
1465
1466 int i=1;
1467 while ( true ) {
1468
1469 const int upperbin_i = imax+i;
1470 const int lowerbin_i = imax-i;
1471
1472 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1473
1474 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1475
1476 // std::cout << i << " frac: " << lowersum
1477 // << "\tx " << s->GetBinCenter(lowerbin)
1478 // << "\t " << s->GetBinCenter(upperbin)
1479 // << "\ttsum " << tsum
1480 // << "\tentries " << entries
1481 // << std::endl;
1482
1483 if ( tsum>entries*frac ) { uppersum = tsum/entries; break; }
1484
1485 lowersum = tsum/entries;
1486
1487 sumn = tsum;
1488
1489 upperbin = upperbin_i;
1490 lowerbin = lowerbin_i;
1491
1492 // if ( std::fabs(lowersum-frac)<0.1 )
1493
1494 i++;
1495 }
1496 }
1497
1498 if ( uppersum==0 ) {
1499 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1501 return f;
1502 }
1503
1504 // std::cout << "FitNull95 " << s->GetName() << "\tlower bin " << lowerbin << "\t upper bin " << upperbin << std::endl;
1505
1506 // std::cout << "full rms " << s->GetRMS() << " +- " << s->GetRMSError() << "\t n=" << s->GetNbinsX()
1507 // << "\tfrac " << ( entries>0 ? sumn/entries : 0 ) << " - " << uppersum
1508 // << std::endl;
1509
1510 // std::cout << "upper " << upperbin << " " << lowerbin << " " << interpolate_flag << std::endl;
1511
1512 // if ( upperbin!=lowerbin ) {
1513 if ( true ) { // technically wrong - 95% contained in only 3 bins, so RMS of the "central" bin is not defined
1514
1515 double llim = s->GetBinLowEdge(1);
1516 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1517
1518 double rms = 0;
1519 double erms = 0;
1520
1521 std::vector<double> stats;
1522
1523 // double sentries = generate::GetEntries(s);
1524
1525 // std::cout << "GetEntries " << s->GetName() << " " << sentries << std::endl;
1526
1527 if ( s_interpolate_flag ) {
1528 s->GetXaxis()->SetRange(lowerbin, upperbin);
1529
1530 // std::cout << "GetEntries " << s->GetName() << " " << generate::GetEntries(s,lowerbin,upperbin)/sentries << std::endl;
1531
1532 double rlower;
1533 double erlower;
1534
1535 double rupper;
1536 double erupper;
1537
1538
1540
1541 if ( !useroot ) {
1542 GetStats( s, stats );
1543 rlower = stats[2];
1544 erlower = stats[3];
1545 }
1546 // else {
1547 rlower = s->GetRMS();
1548 erlower = s->GetRMSError();
1549 // }
1550
1551 // std::cout << "FitNULL95() " << s->GetName() << "\tmean " << m << "\t lower rms " << rlower << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1552 // std::cout << s->GetName() << " " << s->GetTitle() << "\t lower 95% rms " << rlower << " +- " << erlower << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1553
1554 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1555
1556 // std::cout << "GetEntries " << s->GetName() << " " << generate::GetEntries(s,lowerbin-1,upperbin+1)/sentries << std::endl;
1557
1558 // std::cout << "Range " << s->GetBinLowEdge(lowerbin) << " - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1559
1560 if ( !useroot ) {
1561 GetStats( s, stats );
1562 rupper = stats[2];
1563 erupper = stats[3];
1564 }
1565 // else {
1566 rupper = s->GetRMS();
1567 erupper = s->GetRMSError();
1568 // }
1569
1570 // std::cout << "FitNULL95() " << s->GetName() << "\t upper rms " << rupper << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1571
1572 // std::cout << s->GetName() << " " << s->GetTitle() << "\t upper 95% rms " << rupper << " +- " << erupper << "\t( " << lowerbin-1 << " - " << upperbin+1 << " )" << std::endl;
1573
1574
1575
1576
1577 rms = rlower + (frac-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1578 erms = erlower + (frac-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1579
1580 }
1581 else {
1582 s->GetXaxis()->SetRange(lowerbin, upperbin);
1583 if ( !useroot ) {
1584 GetStats( s, stats );
1585 rms = stats[2];
1586 erms = stats[3];
1587 }
1588 else {
1589 rms = s->GetRMS();
1590 erms = s->GetRMSError();
1591 }
1592 }
1593
1594#if 0
1595
1596 std::cout << "numbers " << s->GetName()
1597 << " " << generate::GetEntries(s,lowerbin,upperbin)
1598 << " - " << generate::GetEntries(s,lowerbin-1,upperbin+1) << "\ttotal " << generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1599
1600 std::cout << "fractions " << s->GetName()
1601 << "\t" << generate::GetEntries(s,lowerbin,upperbin)/generate::GetEntries(s,0,s->GetNbinsX()+1)
1602 << " - " << generate::GetEntries(s,lowerbin-1,upperbin+1)/generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1603
1604 std::cout << "lowersum " << s->GetName() << "\t" << lowersum << "\tuppersum " << uppersum << std::endl;
1605
1606 std::cout << "limits " << s->GetName() << "\t" << s->GetBinLowEdge(lowerbin) << " - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1607
1608
1609
1610 std::cout << "FitNULL95Obsolete() " << s->GetName() << "\t rms " << rms << " +- " << erms << "\t inv " << 1/rms << std::endl;
1611
1612 printf("rms %12.10lf inv %12.10lf\n", rms, 1/rms );
1613
1614 printf("rms68 %12.10lf inv %12.10lf\n", rms/0.5369760683, rms*1.8622803865 );
1615#endif
1616
1617
1620 double scale = 1;
1621 if ( s_scalerms95 ) scale = 1.1479538518;
1622
1623
1624
1625 // f->FixParameter(2, s->GetRMS());
1626 // f->SetParError(2, s->GetRMSError());
1627 f->FixParameter(2, scale*rms);
1628 f->SetParError(2, scale*erms);
1629 f->FixParameter(1, s->GetMean());
1630 f->SetParError(1, s->GetMeanError());
1631 // std::cout << s->GetName() << " " << s->GetTitle() << "\t 95% inter rms " << rms << " +- " << erms << std::endl;
1632 s->GetXaxis()->SetRangeUser(llim, ulim);
1633
1634 }
1635 else {
1636 f->FixParameter(1, 0);
1637 f->SetParError(1, 0);
1638 f->FixParameter(2, 0);
1639 f->SetParError(2, 0);
1640 // std::cout << " 95% rms " << 0 << " +- " << 0 << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1641 }
1642
1643 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1644
1645 return f;
1646}
double FindMean(TH1D *s, double frac=0.95)
Definition Resplot.cxx:1288

◆ FitPoisson()

TF1 * Resplot::FitPoisson ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 1905 of file Resplot.cxx.

1905 {
1906
1907 char fstring[1024];
1908 sprintf(fstring, "sqrt([0]*[0])*pow(sqrt([1]*[1]*([2]*[2])),x*[2]-[3])*exp(-sqrt([1]*[1]*([2]*[2])))/TMath::Gamma((x*[2]-[3])+1)");
1909 TF1 *f1 = new TF1("poisson", fstring );
1910 // TF1* f1 = new TF1("poiss","[0]*TMath::Poisson(x*[2],[1])");
1911
1912 f1->SetParName(0, "Maximum");
1913 f1->SetParName(1, "Mean");
1914 f1->SetParName(2, "Scale");
1915 f1->SetParName(3, "Offset");
1916
1917 f1->SetNpx(5000);
1918 f1->SetLineWidth(1);
1919 f1->SetLineColor(s->GetLineColor());
1920
1921 int nbins=0;
1922 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1923
1924 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1925 f1->SetParameter(1,s->GetBinCenter(s->GetMaximumBin()));
1926 f1->SetParameter(2,1);
1927 f1->FixParameter(3,0);
1928
1929 if (nbins>2) {
1930 // std::cout << "fitting " << f1 << std::endl;
1931 // if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1932 // else s->Fit(f1,"Q", "", a, b);
1933 if ( a==-999 || b==-999 ) s->Fit(f1);
1934 else s->Fit(f1,"", "", a, b);
1935 }
1936 else {
1937 for ( int j=0 ; j<4 ; j++ ) f1->SetParameter(j,0);
1938 }
1939
1940 return f1;
1941}

◆ FitRBreit()

TF1 * Resplot::FitRBreit ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 1037 of file Resplot.cxx.

1037 {
1038 TF1* f1 = new TF1("rbreitr", "x*[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
1039
1040 f1->SetParName(0, "Maximum");
1041 f1->SetParName(1, "Median");
1042 f1->SetParName(2, "Gamma");
1043
1044 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1045 f1->SetParameter(1,s->GetMean());
1046 f1->SetParameter(2,s->GetRMS());
1047
1048 return FitInternal( s, a, b, f1 );
1049}

◆ FitRGaussian()

TF1 * Resplot::FitRGaussian ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 1032 of file Resplot.cxx.

1032 {
1033 TF1* f1 = new TF1("rgausr", "[0]*x*exp((x-[1])([1]-x)/(2*[2]*[2]))");
1034 return FitInternal( s, a, b, f1 );
1035}

◆ FitXExp()

TF1 * Resplot::FitXExp ( TH1D * s,
double a = -999,
double b = -999 )
static

Definition at line 1945 of file Resplot.cxx.

1945 {
1946
1947 // TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))", -100, 100 );
1948 // TF1* f1 = new TF1("xexpr", "[0]*(pow([2]*x,[1])*exp(-[2]*x))+[3]");
1949 // TF1* f1 = new TF1("xexpr", "[0]*(pow((1.0/[2])*(x-[3]),[1])*exp(-(1.0/[2])*(x-[3])))");
1950 TF1* f1 = new TF1("xexpr", "[0]*(pow((1.0/[2])*x,[1])*exp(-(1.0/[2])*x))+[3]");
1951
1952 f1->SetParName(0, "Normalisation");
1953 f1->SetParName(1, "Power");
1954 f1->SetParName(2, "Lifetime");
1955 f1->SetParName(3, "offset");
1956
1957 // f1->SetParameter(0, 1e-156);
1958 f1->SetParameter(0, s->GetBinContent(s->GetMaximumBin()) );
1959 // f1->SetParameter(1, -1*(s->GetBinCenter(s->GetMaximumBin())) );
1960 f1->SetParameter(2, s->GetRMS() );
1961 // f1->SetParameter(1, 0);
1962 f1->SetParameter(1, 0);
1963 f1->SetParameter(3, 0);
1964
1965 // f1->FixParameter(0, 1);
1966 // f1->FixParameter(1, 25);
1967 // f1->FixParameter(1, 0);
1968 // f1->FixParameter(3, 0);
1969
1970 f1->SetNpx(5000);
1971 f1->SetLineWidth(1);
1972
1973 int nbins=0;
1974 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1975
1976 // std::cout << "starting exp fit p1=" << f1->GetParameter(1) << std::endl;
1977
1978 if (nbins>2) {
1979 // std::cout << "fitting " << f1 << std::endl;
1980 if ( a==-999 || b==-999 ) s->Fit(f1, "Q");
1981 else s->Fit(f1, "Q", "", a, b);
1982 }
1983 else {
1984 for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1985 }
1986
1987 // std::cout << "done" << std::endl;
1988
1989 return f1;
1990}

◆ get_mean()

StatVal Resplot::get_mean ( )
inlineprivate

Definition at line 601 of file Resplot.h.

601{ return m_g_mean; }

◆ get_sigma()

StatVal Resplot::get_sigma ( )
inlineprivate

Definition at line 602 of file Resplot.h.

602{ return m_g_sigma; }

◆ getbins()

std::vector< double > Resplot::getbins ( const TH1 * h)
static

Definition at line 922 of file Resplot.cxx.

922 {
923 std::vector<double> bins(h->GetNbinsX()+1);
924 for ( int i=0 ; i<h->GetNbinsX()+1 ; i++ ) bins[i] = h->GetBinLowEdge(i+1);
925 return bins;
926}
static const std::vector< std::string > bins

◆ GetEfficiencies() [1/2]

TH1D * Resplot::GetEfficiencies ( const std::string & hname,
double lower,
double upper )

Definition at line 959 of file Resplot.cxx.

959 {
960 // TDirectory* cwd = cd();
961
962 // push();
963
964 TH1D* e = (TH1D*) m_mean->Clone();
965 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
966 if ( m_xaxis!="" ) e->SetXTitle(m_xaxis.c_str());
967
968
969 for ( int i=1 ; i<=m_n_primary ; i++ ) {
970 TH1D* s = m_h2d->ProjectionY(tagname(hname,i), i, i, "e");
971 StatVal v = GetEfficiency(s, lower, upper);
972 e->SetBinContent(i, v.value);
973 e->SetBinError(i, v.error);
974 delete s;
975 }
976
977 // cwd->cd();
978
979 // pop();
980
981 return e;
982}
StatVal GetEfficiency(TH1D *h, double lower, double upper)
Definition Resplot.cxx:933

◆ GetEfficiencies() [2/2]

TH1D * Resplot::GetEfficiencies ( const std::string & hname,
double Nsigma )

Definition at line 990 of file Resplot.cxx.

990 {
991 // TDirectory* cwd = cd();
992 // push();
993
994 // check that the fits have been done for this
995 // plot
996 if ( !m_finalised ) Finalise();
997
998 TH1D* e = (TH1D*) m_mean->Clone();
999 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
1000 if ( m_xaxis!="" ) e->SetXTitle(m_xaxis.c_str());
1001
1002
1003 for ( int i=1 ; i<=m_n_primary ; i++ ) {
1004
1005 double mean = m_mean->GetBinContent(i);
1006 double sigma = m_sigma->GetBinContent(i);
1007
1008 TH1D* s = m_h2d->ProjectionY(tagname(hname,i), i, i, "e");
1009 StatVal v = GetEfficiency(s, mean-Nsigma*sigma, mean+Nsigma*sigma);
1010 e->SetBinContent(i, v.value);
1011 e->SetBinError(i, v.error);
1012 delete s;
1013 }
1014
1015 // cwd->cd();
1016
1017 // pop();
1018
1019 return e;
1020}

◆ GetEfficiency()

StatVal Resplot::GetEfficiency ( TH1D * h,
double lower,
double upper )

Definition at line 933 of file Resplot.cxx.

933 {
934 double total = 0;
935 double good = 0;
936 StatVal v;
937
938 for (int i=0 ; i<=h->GetNbinsX()+1 ; i++ ) {
939 total += h->GetBinContent(i);
940 }
941 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
942 double x = h->GetBinCenter(i);
943 if ( x>lower && x<= upper ) {
944 good += h->GetBinContent(i);
945 }
946 }
947 if ( total>0 ) {
948 v.value = good/total;
949 v.error = sqrt(v.value*(1-v.value)/total);
950 }
951
952 return v;
953}

◆ GetGlobalEfficiency()

StatVal Resplot::GetGlobalEfficiency ( double lower,
double upper )
inline

Definition at line 295 of file Resplot.h.

295 {
296 return GetEfficiency(m_h1d, lower, upper);
297 }

◆ GetPrimaryCentres()

std::vector< double > Resplot::GetPrimaryCentres ( ) const
inline

Definition at line 336 of file Resplot.h.

336 {
337 std::vector<double> d;
338 for ( int i=1 ; i<=m_mean->GetNbinsX() ; i++ ) d.push_back(m_mean->GetBinCenter(i));
339 return d;
340 }

◆ GetPrimaryLimits()

std::vector< double > Resplot::GetPrimaryLimits ( ) const
inline

Definition at line 329 of file Resplot.h.

329 {
330 std::vector<double> d;
331 for ( int i=1 ; i<=m_mean->GetNbinsX()+1 ; i++ ) d.push_back(m_mean->GetBinLowEdge(i));
332 return d;
333 }

◆ H1D() [1/2]

TH1D * Resplot::H1D ( )
inline

Definition at line 358 of file Resplot.h.

358{ return m_h1d; }

◆ H1D() [2/2]

const TH1D * Resplot::H1D ( ) const
inline

Definition at line 359 of file Resplot.h.

359{ return m_h1d; }

◆ H2D() [1/2]

TH2D * Resplot::H2D ( )
inline

Definition at line 362 of file Resplot.h.

362{ return m_h2d; }

◆ H2D() [2/2]

const TH2D * Resplot::H2D ( ) const
inline

Definition at line 363 of file Resplot.h.

363{ return m_h2d; }

◆ Initialise() [1/5]

void Resplot::Initialise ( const std::string & name,
const std::vector< double > & a,
const std::vector< double > & b )

Definition at line 244 of file Resplot.cxx.

246 {
247 Initialise(name, a.size()-1, &a[0], b.size()-1, &b[0] );
248}

◆ Initialise() [2/5]

void Resplot::Initialise ( const std::string & name,
const std::vector< double > & a,
int n2,
double a2,
double b2 )

Definition at line 237 of file Resplot.cxx.

239 {
240 Initialise(name, a.size()-1, &a[0], n2, a2, b2);
241}

◆ Initialise() [3/5]

void Resplot::Initialise ( const std::string & name,
int n1,
const double * a1,
int n2,
const double * a2 )

Definition at line 297 of file Resplot.cxx.

299 {
300 SetPrimary(n1, a1);
301 SetSecondary(n2, a2[0], a2[n2+1]);
302
303 m_Set = true;
304
305 m_name = name;
306 const std::string name_2d = "2d";
307 const std::string name_1d = "1d";
308
309 // std::cout << "Resplot::Initialise() Name " << Name() << std::endl;
310
311 // TH2D::SetDirectory(0);
312
313 m_h2d = new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2 );
314 m_h1d = new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2 );
315 m_h1d->Sumw2();
316 skip(m_h2d);
317 skip(m_h1d);
318
319 const std::string name_mean = "mean";
320 const std::string name_sigma = "sigma";
321 const std::string name_chi2 = "chi2";
322
323 m_mean = new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
324 m_sigma = new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
325 m_chi2 = new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
326
327 skip(m_mean);
328 skip(m_sigma);
329 skip(m_chi2);
330
331 // const std::string name_entries = "significance";
332 const std::string name_entries = "fractional uncertainty";
333
334 m_Nentries = new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
336
337}
void SetSecondary(int n, double a, double b)
Definition Resplot.h:596
void SetPrimary(int n, const double *)
Definition Resplot.h:594

◆ Initialise() [4/5]

void Resplot::Initialise ( const std::string & name,
int n1,
const double * a1,
int n2,
double a2,
double b2 )

Definition at line 252 of file Resplot.cxx.

254 {
255 SetPrimary(n1, a1);
256 SetSecondary(n2, a2, b2);
257
258 m_Set = true;
259
260 m_name = name;
261 const std::string name_2d = "2d";
262 const std::string name_1d = "1d";
263
264 // std::cout << "Resplot::Initialise() Name " << Name() << std::endl;
265
266 // TH2D::SetDirectory(0);
267
268 m_h2d = new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2, b2);
269 m_h1d = new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
270 m_h1d->Sumw2();
271 skip(m_h2d);
272 skip(m_h1d);
273
274 const std::string name_mean = "mean";
275 const std::string name_sigma = "sigma";
276 const std::string name_chi2 = "chi2";
277
278 m_mean = new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
279 m_sigma = new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
280 m_chi2 = new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
281
282 skip(m_mean);
283 skip(m_sigma);
284 skip(m_chi2);
285
286 // const std::string name_entries = "significance";
287 const std::string name_entries = "fractional uncertainty";
288
289 m_Nentries = new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
291
292}

◆ Initialise() [5/5]

void Resplot::Initialise ( const std::string & name,
int n1,
double a1,
double b1,
int n2,
double a2,
double b2 )

Definition at line 195 of file Resplot.cxx.

197 {
198
199 SetPrimary(n1, a1, b1);
200 SetSecondary(n2, a2, b2);
201
202 m_Set = true;
203 // TH2D::SetDirectory(0);
204
205 m_name = name;
206 const std::string name_2d = "2d";
207 const std::string name_1d = "1d";
208
209 // std::cout << "Resplot::Initialise() Name " << Name() << std::endl;
210
211 m_h2d = new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, b1, n2, a2, b2);
212 m_h1d = new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
213 m_h1d->Sumw2();
214 skip(m_h2d);
215 skip(m_h1d);
216
217 const std::string name_mean = "mean";
218 const std::string name_sigma = "sigma";
219 const std::string name_chi2 = "chi2";
220 // const std::string name_entries = "significance";
221 const std::string name_entries = "fractional uncertainty";
222
223 m_Nentries = new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1, b1 );
225
226 m_mean = new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1, b1 );
227 m_sigma = new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1, b1 );
228 m_chi2 = new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1, b1 );
229 skip(m_mean);
230 skip(m_sigma);
231 skip(m_chi2);
232
233}

◆ Integrate()

void Resplot::Integrate ( )
inline

integrate all the slices and refit the mean etc. not yet ...

Definition at line 545 of file Resplot.h.

545 {
546 if ( !m_finalised ) return;
547
550 }

◆ MakeSlices()

void Resplot::MakeSlices ( )
inlineprivate

Definition at line 580 of file Resplot.h.

580{ }

◆ Mean() [1/2]

TH1D * Resplot::Mean ( )
inline

Definition at line 347 of file Resplot.h.

347{ return m_mean; }

◆ Mean() [2/2]

const TH1D * Resplot::Mean ( ) const
inline

Definition at line 348 of file Resplot.h.

348{ return m_mean; }

◆ Name() [1/2]

const std::string & Resplot::Name ( ) const
inline

Definition at line 342 of file Resplot.h.

342{ return m_name; }

◆ Name() [2/2]

const std::string & Resplot::Name ( const std::string & s)
inline

Definition at line 344 of file Resplot.h.

344{ return m_name=s; }

◆ operator*()

Resplot Resplot::operator* ( double d) const
inline

Definition at line 534 of file Resplot.h.

534 {
535 Resplot r(*this);
536 return (r*=d);
537 }
Resplot()
Definition Resplot.h:70

◆ operator*=()

Resplot & Resplot::operator*= ( double d)
inline

Definition at line 499 of file Resplot.h.

499 {
500
501 std::cout << "Resplot::operator*= " << Name() << " " << m_finalised << " " << m_slices.size() << std::endl;
502
503 clear();
504
505 std::cout << "Resplot::operator*= " << Name() << " " << m_finalised << " " << m_slices.size() << std::endl;
506 std::cout << "Resplot::operator*= " << Name() << "\tH2D " << H2D() << std::endl;
507
508 H2D()->DrawCopy();
509
510 std::cout << "Resplot::operator*= " << Name() << "\tDraw " << std::endl;
511
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);
516 }
517 }
518
519
520 std::cout << "Resplot::operator*= " << Name() << "\tH1D " << H1D() << std::endl;
521
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 );
525 }
526
527 m_finalised = false;
528
529 std::cout << "Resplot::operator*= done" << std::endl;
530
531 return *this;
532 }
TH1D * H1D()
Definition Resplot.h:358
TH2D * H2D()
Definition Resplot.h:362

◆ operator+()

Resplot Resplot::operator+ ( const Resplot & r) const
inline

Definition at line 539 of file Resplot.h.

539 {
540 Resplot r0(*this);
541 return (r0+=r);
542 }
const double r0
electron radius{cm}

◆ operator+=()

Resplot & Resplot::operator+= ( const Resplot & r)
inline

operators

Definition at line 468 of file Resplot.h.

468 {
469
470 clear();
471
472 // std::cout << "Resplot::operator+= " << Name() << std::endl;
473
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");
477
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) ) );
482 }
483 }
484
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) ) );
488 }
489
490 m_finalised = false;
491
492 // std::cout << "Resplot::operator+= done" << std::endl;
493
494 return *this;
495 }

◆ rebin()

TH1D * Resplot::rebin ( const TH1 * h,
const std::vector< double > & bins )
static

Definition at line 892 of file Resplot.cxx.

892 {
893
894 if ( xbins.size()==0 ) {
895 std::cerr << "Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << std::endl;
896 return 0;
897 }
898
899 TH1D* h2 = new TH1D("duff","duff", xbins.size()-1, &xbins[0] );
900 h2->SetDirectory(0);
901
902 unsigned xbin = 0;
903 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
904
905 while ( h->GetBinCenter(i)>xbins[xbin+1] && xbin<(xbins.size()-1) ) xbin++;
906
907 if ( h->GetBinCenter(i)>=xbins[xbin] && h->GetBinCenter(i)<xbins[xbin+1] ) {
908 double n = h->GetBinContent(i);
909 double nh = h2->GetBinContent(xbin+1);
910 h2->SetBinContent(xbin+1, nh+n);
911 }
912 }
913
914 return h2;
915}

◆ Refit()

int Resplot::Refit ( TF1 *(* func )(TH1D *s, double a, double b))
inline

Definition at line 442 of file Resplot.h.

442 {
443 clear();
444 return Finalise( func );
445 }

◆ rotate()

TH2D * Resplot::rotate ( const TH2 * h)
static

flip the x and y axes

rotate a TH2D

Definition at line 565 of file Resplot.cxx.

565 {
566
567 std::vector<double> xbins;
568 std::vector<double> ybins;
569
570 TH1D* hy = (TH1D*)h->ProjectionX("1dx", 1, h->GetNbinsY());
571 TH1D* hx = (TH1D*)h->ProjectionY("1dy", 1, h->GetNbinsX());
572
573 hy->SetDirectory(0);
574 hx->SetDirectory(0);
575
576 for ( int i=0 ; i<=hx->GetNbinsX()+1 ; i++ ) xbins.push_back( hx->GetBinLowEdge(i+1) );
577 for ( int i=0 ; i<=hy->GetNbinsX()+1 ; i++ ) ybins.push_back( hy->GetBinLowEdge(i+1) );
578
579 std::cout << "rotate:" << std::endl;
580
581 std::cout << "x: " << xbins[0] << " - " << xbins.back() << std::endl;
582 std::cout << "y: " << ybins[0] << " - " << ybins.back() << std::endl;
583
584 TH2D* h2 = new TH2D("duff","duff", hx->GetNbinsX(), &xbins[0], hy->GetNbinsX(), &ybins[0] );
585
586 for ( int i=0 ; i<hx->GetNbinsX() ; i++ ) {
587 for ( int j=0 ; j<hy->GetNbinsX() ; j++ ) {
588 h2->SetBinContent(j+1,i+1, h->GetBinContent(i+1,j+1));
589 h2->SetBinError(j+1,i+1, h->GetBinError(i+1,j+1));
590 }
591 }
592
593 h2->SetEntries( h->GetEntries() );
594
595 delete hy;
596 delete hx;
597
598 return h2;
599}

◆ SetDirectory()

void Resplot::SetDirectory ( TDirectory * = 0)
inline

Definition at line 461 of file Resplot.h.

461{ }

◆ setInterpolateFlag()

void Resplot::setInterpolateFlag ( bool b)
inlinestatic

Definition at line 463 of file Resplot.h.

◆ setnofit()

bool Resplot::setnofit ( bool b)
inlinestatic

Definition at line 557 of file Resplot.h.

557{ return s_nofit=b; }

◆ setoldrms95()

bool Resplot::setoldrms95 ( bool b)
inlinestatic

Definition at line 555 of file Resplot.h.

555{ return s_oldrms95=b; }

◆ SetPrimary() [1/2]

void Resplot::SetPrimary ( int n,
const double *  )
inlineprivate

Definition at line 594 of file Resplot.h.

594{ m_n_primary=n; }

◆ SetPrimary() [2/2]

void Resplot::SetPrimary ( int n,
double ,
double  )
inlineprivate

Definition at line 595 of file Resplot.h.

595{ m_n_primary=n; } // a_primary=a; b_primary=b; }

◆ setscalerms95()

bool Resplot::setscalerms95 ( bool b)
inlinestatic

Definition at line 556 of file Resplot.h.

556{ return s_scalerms95=b; }

◆ SetSecondary()

void Resplot::SetSecondary ( int n,
double a,
double b )
inlineprivate

Definition at line 596 of file Resplot.h.

◆ setUniform()

void Resplot::setUniform ( bool t = false)
inline

Definition at line 552 of file Resplot.h.

552{ m_uniform=t; }

◆ SetXAxis()

void Resplot::SetXAxis ( const std::string & xaxis)
inline

Definition at line 311 of file Resplot.h.

311 {
312 m_xaxis = xaxis;
313 m_mean->SetXTitle(m_xaxis.c_str());
314 m_sigma->SetXTitle(m_xaxis.c_str());
315 m_chi2->SetXTitle(m_xaxis.c_str());
316 m_Nentries->SetXTitle(m_xaxis.c_str());
317 m_h2d->SetXTitle(m_xaxis.c_str());
318 m_h1d->SetXTitle(m_xaxis.c_str());
319 }

◆ SetYAxis()

void Resplot::SetYAxis ( const std::string & yaxis)
inline

Definition at line 322 of file Resplot.h.

322 {
323 m_yaxis = yaxis;
324 m_h2d->SetXTitle(m_yaxis.c_str());
325 m_h1d->SetXTitle(m_yaxis.c_str());
326 }

◆ Sigma()

TH1D * Resplot::Sigma ( )
inline

Definition at line 351 of file Resplot.h.

351{ return m_sigma; }

◆ skip() [1/2]

void Resplot::skip ( TH1D * t)
inlineprivate

Definition at line 585 of file Resplot.h.

585{ if ( t ) t->SetDirectory(0); }

◆ skip() [2/2]

void Resplot::skip ( TH2D * t)
inlineprivate

Definition at line 589 of file Resplot.h.

589{ if ( t ) t->SetDirectory(0); }

◆ Slices()

const std::vector< TH1D * > & Resplot::Slices ( ) const
inline

Definition at line 372 of file Resplot.h.

372{ return m_slices; }

◆ Uncertainty() [1/2]

TH1D * Resplot::Uncertainty ( )
inline

Definition at line 366 of file Resplot.h.

366{ return m_Nentries; }

◆ Uncertainty() [2/2]

const TH1D * Resplot::Uncertainty ( ) const
inline

Definition at line 367 of file Resplot.h.

367{ return m_Nentries; }

◆ version()

const std::string & Resplot::version ( )
inlinestatic

Definition at line 554 of file Resplot.h.

554{ return s_rversion; }
static const std::string s_rversion
Definition Resplot.h:638

◆ Write() [1/2]

Int_t Resplot::Write ( const char * = 0,
Int_t = 0,
Int_t = 0 )
inline

Definition at line 455 of file Resplot.h.

455{ return DWrite(); }
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...
Definition Resplot.cxx:343

◆ Write() [2/2]

Int_t Resplot::Write ( const char * = 0,
Int_t = 0,
Int_t = 0 ) const
inline

Hooray, this stupidity is to overwride both the const and non-const TObject Write methods Fixme: should probably remove all of these so root can write out using the dictionary but I could never get that to work.

Definition at line 454 of file Resplot.h.

454{ return DWrite(); }

Member Data Documentation

◆ m_a_secondary

double Resplot::m_a_secondary
private

Definition at line 660 of file Resplot.h.

◆ m_b_secondary

double Resplot::m_b_secondary
private

Definition at line 660 of file Resplot.h.

◆ m_chi2

TH1D* Resplot::m_chi2 = 0
private

Definition at line 647 of file Resplot.h.

◆ m_dir

TDirectory* Resplot::m_dir = 0
private

Definition at line 655 of file Resplot.h.

◆ m_finalised

bool Resplot::m_finalised
private

Definition at line 668 of file Resplot.h.

◆ m_fitname

std::string Resplot::m_fitname
private

Definition at line 666 of file Resplot.h.

◆ m_g_mean

StatVal Resplot::m_g_mean
private

Definition at line 652 of file Resplot.h.

◆ m_g_sigma

StatVal Resplot::m_g_sigma
private

Definition at line 653 of file Resplot.h.

◆ m_h1d

TH1D* Resplot::m_h1d = 0
private

Definition at line 650 of file Resplot.h.

◆ m_h2d

TH2D* Resplot::m_h2d = 0
private

Definition at line 649 of file Resplot.h.

◆ m_mean

TH1D* Resplot::m_mean = 0
private

Definition at line 645 of file Resplot.h.

◆ m_n_primary

int Resplot::m_n_primary
private

Definition at line 657 of file Resplot.h.

◆ m_n_secondary

int Resplot::m_n_secondary
private

Definition at line 659 of file Resplot.h.

◆ m_name

std::string Resplot::m_name
private

Definition at line 642 of file Resplot.h.

◆ m_Nentries

TH1D* Resplot::m_Nentries = 0
private

Definition at line 644 of file Resplot.h.

◆ m_Set

bool Resplot::m_Set
private

Definition at line 640 of file Resplot.h.

◆ m_sigma

TH1D* Resplot::m_sigma = 0
private

Definition at line 646 of file Resplot.h.

◆ m_slicedir

TDirectory* Resplot::m_slicedir = 0
private

Definition at line 669 of file Resplot.h.

◆ m_slices

std::vector<TH1D*> Resplot::m_slices
private

Definition at line 665 of file Resplot.h.

◆ m_uniform

bool Resplot::m_uniform
private

Definition at line 671 of file Resplot.h.

◆ m_xaxis

std::string Resplot::m_xaxis
private

Definition at line 662 of file Resplot.h.

◆ m_yaxis

std::string Resplot::m_yaxis
private

Definition at line 663 of file Resplot.h.

◆ s_ErrorSet

Resplot::ERROR Resplot::s_ErrorSet = Resplot::OK
staticprivate

Definition at line 681 of file Resplot.h.

◆ s_interpolate_flag

bool Resplot::s_interpolate_flag
staticprivate

Definition at line 636 of file Resplot.h.

◆ s_mAddDirectoryStatus

bool Resplot::s_mAddDirectoryStatus
staticprivate

Definition at line 635 of file Resplot.h.

◆ s_nofit

bool Resplot::s_nofit = false
staticprivate

Definition at line 678 of file Resplot.h.

◆ s_oldrms95

bool Resplot::s_oldrms95 = true
staticprivate

temporarily allow toggeling between old and new rms95 error estimates

use the new error estimates

Definition at line 675 of file Resplot.h.

◆ s_rversion

const std::string Resplot::s_rversion = "resplot-v29"
staticprivate

Definition at line 638 of file Resplot.h.

◆ s_scalerms95

bool Resplot::s_scalerms95 = true
staticprivate

Definition at line 676 of file Resplot.h.


The documentation for this class was generated from the following files: