ATLAS Offline Software
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | List of all members
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, const 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. More...
 
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 More...
 
void SetDirectory (TDirectory *=0)
 
Resplotoperator+= (const Resplot &r)
 operators More...
 
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 More...
 
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 More...
 
static TH1D * combine (const TH1 *h, double x, int N)
 after value x, combine each N bins into a single bin More...
 
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 More...
 
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. More...
 
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 More...
 
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.

59 { OK, HISTOWIDTH, BINWIDTH, EMPTY };

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),
76  m_n_secondary(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  { }

◆ 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); }

◆ 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); }

◆ 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);
158  skip(m_Nentries);
159  }

◆ Resplot() [7/8]

Resplot::Resplot ( const std::string &  name,
const 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 = (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  }

◆ Resplot() [8/8]

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

Definition at line 209 of file Resplot.h.

209  :
210  m_name(name)
211  // m_Nentries ( new TH1D(*(TH1D*)gDirectory->Get((name+"/fractional uncertainty").c_str())) ),
212  // m_mean ( new TH1D(*(TH1D*)gDirectory->Get((name+"/1d").c_str())) ),
213  // m_sigma ( new TH1D(*(TH1D*)gDirectory->Get((name+"/sigma").c_str())) ),
214  // m_chi2 ( new TH1D(*(TH1D*)gDirectory->Get((name+"/chi2").c_str())) ),
215  // m_h2d ( new TH2D(*(TH2D*)gDirectory->Get((name+"/2d").c_str())) ),
216  // m_h1d ( new TH1D(*(TH1D*)gDirectory->Get((name+"/1d").c_str())) )
217  {
218 
219  m_Nentries = new TH1D(*(TH1D*)gDirectory->Get((name+"/fractional uncertainty").c_str()));
220  m_mean = new TH1D(*(TH1D*)gDirectory->Get((name+"/mean").c_str()));
221  m_sigma = new TH1D(*(TH1D*)gDirectory->Get((name+"/sigma").c_str()));
222  // m_sigma = new TH1D(*(TH1D*)gDirectory->Get((name+"/RMS").c_str()));
223  m_chi2 = new TH1D(*(TH1D*)gDirectory->Get((name+"/chi2").c_str()));
224  m_h2d = new TH2D(*(TH2D*)gDirectory->Get((name+"/2d").c_str()));
225  m_h1d = new TH1D(*(TH1D*)gDirectory->Get((name+"/1d").c_str()));
226 
227  skip(m_h2d);
228  skip(m_h1d);
229  skip(m_mean);
230  skip(m_sigma);
231  skip(m_chi2);
232  skip(m_Nentries);
233 
234  m_n_primary = m_h2d->GetNbinsX();
235 
236  m_finalised = true;
237 
238  m_uniform = true;
239 
240  // std::cout << "Resplot(std::string)" << name << "\t m_n_primary " << m_n_primary << std::endl;
241 
242  // deep copy
243  for ( int i=1 ; i<=m_h2d->GetNbinsX() ; i++ ) {
244  char slicename[512];
245  sprintf(slicename, "/slices/slice[%03d]", i);
246  // std::cout << i << " " << (name+slicename) << std::endl;
247  m_slices.push_back((TH1D*)gDirectory->Get((name+slicename).c_str()));
248  skip(m_slices.back()); //->SetDirectory(0);
249  }
250 
251  }

◆ ~Resplot()

Resplot::~Resplot ( )
virtual

Definition at line 174 of file Resplot.cxx.

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

Member Function Documentation

◆ AddDirectory()

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

Definition at line 457 of file Resplot.h.

◆ AddDirectoryStatus()

static bool Resplot::AddDirectoryStatus ( )
inlinestatic

Definition at line 456 of file Resplot.h.

456 { return s_mAddDirectoryStatus; }

◆ AddEfficiency()

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

Definition at line 603 of file Resplot.h.

603  {
604  StatVal v = GetGlobalEfficiency( lower, upper);
605  h->SetBinContent(i, v.value);
606  h->SetBinError(i, v.error);
607  }

◆ AddMean()

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

Definition at line 615 of file Resplot.h.

615  {
616  StatVal v = get_mean();
617  h->SetBinContent(i, v.value);
618  h->SetBinError(i, v.error);
619  }

◆ AddResolution()

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

Definition at line 609 of file Resplot.h.

609  {
610  StatVal v = get_sigma();
611  h->SetBinContent(i, v.value);
612  h->SetBinError(i, v.error);
613  }

◆ Chi2() [1/2]

TH1D* Resplot::Chi2 ( )
inline

Definition at line 352 of file Resplot.h.

352 { return m_chi2; }

◆ Chi2() [2/2]

const TH1D* Resplot::Chi2 ( ) const
inline

Definition at line 353 of file Resplot.h.

353 { return m_chi2; }

◆ clear()

void Resplot::clear ( )
inlineprivate

Definition at line 623 of file Resplot.h.

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

◆ combine() [1/4]

TH1D * Resplot::combine ( const TH1 *  h,
double  inveps2 
)
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 833 of file Resplot.cxx.

833  {
834  return rebin( h, findbins(h, inveps2) );
835 }

◆ 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 667 of file Resplot.cxx.

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

◆ combine() [3/4]

TH2D * Resplot::combine ( const TH2 *  h,
double  inveps2 
)
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 715 of file Resplot.cxx.

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

◆ 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 606 of file Resplot.cxx.

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

◆ deletehist() [1/2]

void Resplot::deletehist ( TH1D *  t)
inlineprivate

Definition at line 585 of file Resplot.h.

585 { if ( t ) delete t; }

◆ deletehist() [2/2]

void Resplot::deletehist ( TH2D *  t)
inlineprivate

Definition at line 589 of file Resplot.h.

589 { if ( t ) delete t; }

◆ delskip() [1/2]

void Resplot::delskip ( TH1D *  t)
inlineprivate

Definition at line 584 of file Resplot.h.

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

◆ delskip() [2/2]

void Resplot::delskip ( TH2D *  t)
inlineprivate

Definition at line 588 of file Resplot.h.

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

◆ Dir()

TDirectory* Resplot::Dir ( )
inline

Definition at line 446 of file Resplot.h.

446 { 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 342 of file Resplot.cxx.

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

◆ Fill()

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

Definition at line 279 of file Resplot.h.

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

◆ Finalise() [1/2]

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

Definition at line 388 of file Resplot.cxx.

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

◆ Finalise() [2/2]

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

Definition at line 431 of file Resplot.h.

431  {
432  return Finalise( a, b, func);
433  }

◆ finalised()

bool Resplot::finalised ( ) const
inline

Definition at line 367 of file Resplot.h.

367 { return m_finalised; }

◆ findbins()

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

Definition at line 838 of file Resplot.cxx.

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

◆ Fit()

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

Definition at line 435 of file Resplot.h.

435  {
436  if ( m_finalised ) return -1;
437  return Finalise( func );
438  }

◆ FitATan()

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

Definition at line 1220 of file Resplot.cxx.

1220  {
1221  static int counter = 0;
1222 
1223  std::cout << "Resplot::FitATan() " << s->GetName() << " " << s->GetTitle() << std::endl;
1224 
1225  char name[8];
1226  sprintf(name,"atan_%02d", counter); counter++;
1227 
1228  // Cannot use "M_PI" here as root does not replace M_PI in the string expressions for function in TF1 definition
1229  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);
1230 
1231  f1->SetParName(0, "Mean");
1232  f1->SetParName(1, "Gradient");
1233  f1->SetParName(2, "Pedestal");
1234  f1->SetParName(3, "Norm");
1235  f1->SetParName(4, "Power");
1236 
1237  int maxn=1;
1238  for ( int i=1 ; i<=s->GetNbinsX() ; i++ ) if ( s->GetBinContent(maxn)<s->GetBinContent(i) ) maxn = i;
1239 
1240 
1241  // f1->SetParameter(0,s->GetBinContent(maxn) );
1242  // f1->SetParameter(1,s->GetBinCenter(s->GetNbinsX()/2) );
1243  // f1->SetParameter(2,0.25);
1244 
1245  f1->SetParameter(0, 2 );
1246  f1->SetParameter(1, 10 );
1247  f1->SetParameter(2, 0.001 );
1248  f1->SetParameter(3, 100 );
1249  f1->SetParameter(4, 1 );
1250 
1251  f1->FixParameter(2, 0);
1252  f1->FixParameter(3, 100);
1253  // f1->FixParameter(4, 1);
1254 
1255  f1->SetNpx(5000);
1256  f1->SetLineWidth(1);
1257 
1258 
1259  // int nbins=0;
1260 
1261 
1262  // ZeroErrors(s);
1263  s->SetMarkerStyle(20);
1264 
1265 
1266  // int n=0;
1267  // for ( int i=1 ; i<=s->GetNbinsX() ; i++ ) if ( s->GetBinContent() ) n++;
1268  // if ( n>2 ) s->Fit(f1,"Q");
1269 
1270  s->Fit(f1,"Q");
1271 
1272  std::cout << "par0 = " << f1->GetParameter(0) << std::endl;
1273  std::cout << "par1 = " << f1->GetParameter(1) << std::endl;
1274  std::cout << "par2 = " << f1->GetParameter(2) << std::endl;
1275  std::cout << "par3 = " << f1->GetParameter(3) << std::endl;
1276  std::cout << "par4 = " << f1->GetParameter(4) << std::endl;
1277 
1278 
1279  // unZeroErrors(s);
1280  // s->SetMaximum(f1->GetParameter(0)*1.1);
1281  // double range = s->GetBinLowEdge(s->GetNbinsX()+1) - s->GetBinLowEdge(1) ;
1282 
1283  return f1;
1284 }

◆ FitBreit()

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

Definition at line 1159 of file Resplot.cxx.

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

◆ 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 1080 of file Resplot.cxx.

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

◆ FitGaussian()

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

Definition at line 1025 of file Resplot.cxx.

1025  {
1026  TF1* f1 = new TF1("gausr", "gaus");
1027  return FitInternal( s, a, b, f1 );
1028  // s->GetXaxis()->SetRangeUser(-1, 1);
1029 }

◆ FitInternal()

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

Definition at line 1051 of file Resplot.cxx.

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

◆ FitLandauGauss()

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

Definition at line 2082 of file Resplot.cxx.

2082  {
2083  // TF1* f1 = new TF1("landgaus", "landgaus");
2084  // root is STUPID and you have to specify the FIT RANGE if you
2085  // want to specify the number of fit parameters!!!
2086  TF1* f1 = new TF1("landgaus", langaufun, 0, 1, 4);
2087 
2088  f1->SetNpx(5000);
2089  f1->SetLineWidth(1);
2090 
2091  // parameter starting values
2092  double start_vals[4]; // = { 0.1, 3.0, 1.0, 0.3 };
2093 
2094  start_vals[0] = s->GetEntries();
2095  start_vals[1] = s->GetBinCenter(s->GetMaximumBin());
2096  start_vals[2] = s->GetRMS();
2097  start_vals[3] = 0.5*start_vals[2];
2098 
2099  f1->SetParNames("Area", "MP", "Width", "GSigma");
2100  f1->SetParameters(start_vals);
2101 
2102  // parameter low and high values for the fit
2103  // double par_lo[4] = { 0.0, -20.0, 0.0, 0.00 };
2104  // double par_hi[4] = { 20000.0, 50000.0, 50.0, 0.01 };
2105  // for ( int i=0 ; i<4 ; i++ ) f1->SetParLimits(i, par_lo[i], par_hi[i]);
2106  f1->SetParLimits( 2, 0.1*start_vals[2], 10*start_vals[2] );
2107  f1->SetParLimits( 3, 0.0, 10*start_vals[2] );
2108 
2109  int nbins=0;
2110  for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
2111 
2112  if (nbins>2) {
2113  if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
2114  else s->Fit(f1,"Q", "", a, b);
2115  // if ( a==-999 || b==-999 ) s->Fit(f1);
2116  // else s->Fit(f1,"", "", a, b);
2117  }
2118  else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
2119 
2120  return f1;
2121 }

◆ FitName()

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

Definition at line 375 of file Resplot.h.

375 { return m_fitname; }

◆ FitNull()

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

Definition at line 1288 of file Resplot.cxx.

1288  {
1289 
1290  // unZeroErrors(s);
1291 
1292  TF1* f=new TF1("null", "[0]+[1]+[2]");
1293 
1294  f->SetParName(0, "Maximum");
1295  f->SetParName(1, "Mean");
1296  f->SetParName(2, "RMS");
1297 
1298  f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1299  f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1300  f->FixParameter(2, s->GetRMS()); f->SetParError(2, s->GetRMSError());
1301 
1302  // std::cout << gDirectory->GetName() << " " << s->GetName() << "\tFitNull mean: " << f->GetParameter(1) << "\tsigma: " << f->GetParameter(2) << std::endl;
1303 
1304  return f;
1305 }

◆ FitNull95()

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

use approximate root errors for speed

Definition at line 1673 of file Resplot.cxx.

1673  {
1674  // if ( s_oldrms95 ) return Resplot::FitNull95Obsolete(s, 0.95, true ); /// use approximate root errors for speed
1675  if ( s_oldrms95 ) return Resplot::FitNull95Obsolete( s, 0.95 );
1676  else return Resplot::FitNull95New(s);
1677 }

◆ 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 1754 of file Resplot.cxx.

1754  {
1755 
1756  TF1* f=new TF1("null", "[0]+[1]+[2]");
1757 
1758  f->SetParName(0, "Maximum");
1759  f->SetParName(1, "Mean");
1760  f->SetParName(2, "RMS");
1761 
1762  f->SetParameter(0, 0);
1763  f->SetParameter(1, 0);
1764  f->SetParameter(2, 0);
1765 
1766  if ( s==0 ) { std::cerr << "Resplot::FitNull95() histogram s = " << s << std::endl; return 0; }
1767  if ( s->GetXaxis()==0) { std::cerr << "Resplot::FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl; return 0; }
1768 
1769  // std::cout << "FitNull " << s->GetName() << " " << generate::GetEntries(s) << std::endl;
1770 
1771  if ( generate::GetEntries(s)<20 ) return f;
1772  // if ( s->GetEffectiveEntries<20 ) return f;
1773 
1774  s->GetXaxis()->SetRange(1,s->GetNbinsX());
1775  // s->GetXaxis()->UnZoom();
1776 
1777 
1780 
1783 
1784  int imax = findmax(s);
1785 
1786  f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1787  // f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1788 
1789 
1790  double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1791 
1792  // double sumx = s->GetBinContent(imax)*s->GetBinCenter(imax);
1793  // double sumx2 = s->GetBinContent(imax)*s->GetBinCenter(imax)*s->GetBinCenter(imax);
1794  double sumn = s->GetBinContent(imax);
1795 
1796  double frac = 0.95;
1797 
1798  int upperbin = imax;
1799  int lowerbin = imax;
1800 
1801  double uppersum = 0;
1802  double lowersum = 0;
1803 
1804  if ( entries>0 ) {
1805 
1806  int i=1;
1807  while ( true ) {
1808 
1809  const int upperbin_i = imax+i;
1810  const int lowerbin_i = imax-i;
1811 
1812  if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1813 
1814  double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1815 
1816  if ( tsum>entries*frac ) { uppersum = tsum/entries; break; }
1817 
1818  lowersum = tsum/entries;
1819 
1820  sumn = tsum;
1821 
1822  upperbin = upperbin_i;
1823  lowerbin = lowerbin_i;
1824 
1825  i++;
1826  }
1827  }
1828 
1829  // std::cout << "FitNull95 " << s->GetName() << " " << upperbin << " " << lowerbin << std::endl;
1830 
1831  // std::cout << "full rms " << s->GetRMS() << " +- " << s->GetRMSError() << "\t n=" << s->GetNbinsX()
1832  // << "\tfrac " << ( entries>0 ? sumn/entries : 0 ) << " - " << uppersum
1833  // << std::endl;
1834 
1835  // std::cout << "upper " << upperbin << " " << lowerbin << " " << interpolate_flag << std::endl;
1836 
1837  if ( upperbin!=lowerbin ) {
1838 
1839  double llim = s->GetBinLowEdge(1);
1840  double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1841 
1842  double rms = 0;
1843  double erms = 0;
1844 
1845  std::vector<double> stats;
1846 
1847  if ( s_interpolate_flag ) {
1848  s->GetXaxis()->SetRange(lowerbin, upperbin);
1849 
1850 
1851  double rlower;
1852  double erlower;
1853 
1854  double rupper;
1855  double erupper;
1856 
1857 
1859 
1860  GetStats( s, stats );
1861  rlower = stats[2];
1862  erlower = stats[3];
1863 
1864  // std::cout << "FitNULL95() " << s->GetName() << "\t lower rms " << rlower << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1865  // std::cout << s->GetName() << " " << s->GetTitle() << "\t lower 95% rms " << rlower << " +- " << erlower << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1866 
1867  s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1868 
1869  GetStats( s, stats );
1870  rupper = stats[2];
1871  erupper = stats[3];
1872 
1873  // std::cout << "FitNULL95() " << s->GetName() << "\t upper rms " << rupper << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1874 
1875  // std::cout << s->GetName() << " " << s->GetTitle() << "\t upper 95% rms " << rupper << " +- " << erupper << "\t( " << lowerbin-1 << " - " << upperbin+1 << " )" << std::endl;
1876 
1877  rms = rlower + (0.95-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1878  erms = erlower + (0.95-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1879 
1880  }
1881  else {
1882  s->GetXaxis()->SetRange(lowerbin, upperbin);
1883  GetStats( s, stats );
1884  rms = stats[2];
1885  erms = stats[3];
1886 
1887  }
1888 
1889 
1890  // f->FixParameter(2, s->GetRMS());
1891  // f->SetParError(2, s->GetRMSError());
1892  f->FixParameter(2, rms);
1893  f->SetParError(2, erms);
1894  f->FixParameter(1, s->GetMean());
1895  f->SetParError(1, s->GetMeanError());
1896  // std::cout << s->GetName() << " " << s->GetTitle() << "\t 95% inter rms " << rms << " +- " << erms << std::endl;
1897  s->GetXaxis()->SetRangeUser(llim, ulim);
1898  }
1899  else {
1900  f->FixParameter(1, 0);
1901  f->SetParError(1, 0);
1902  f->FixParameter(2, 0);
1903  f->SetParError(2, 0);
1904  // std::cout << " 95% rms " << 0 << " +- " << 0 << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1905  }
1906 
1907  s->GetXaxis()->SetRange(1, s->GetNbinsX());
1908 
1909  return f;
1910 }

◆ 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 1687 of file Resplot.cxx.

1687  { // double frac, bool useroot ) {
1688 
1689  // std::cout << "---------------------------------------\nFN95 " << std::endl;
1690 
1691  TF1* f=new TF1("null", "[0]+[1]+[2]");
1692 
1693  f->SetParName(0, "Maximum");
1694  f->SetParName(1, "Mean");
1695  f->SetParName(2, "RMS");
1696 
1697  f->SetParameter(0, 0);
1698  f->SetParameter(1, 0);
1699  f->SetParameter(2, 0);
1700 
1701  if ( s->GetEffectiveEntries()==0 ) return f;
1702 
1703 
1704  // double _entries = getWeights( s );
1705  const double entries = s->GetEffectiveEntries();
1706 
1707 
1708  // int nexperiments = 20+int(800/std::sqrt(s->GetEntries()));
1709  // int nexperiments = 20+int(800/std::sqrt(s->GetEntries()));
1710  int nexperiments = 20+int(1000/entries);
1711 
1712  if ( nexperiments_!=0 ) nexperiments = nexperiments_;
1713 
1714 
1715  if ( nexperiments>nexperiments_max ) nexperiments = nexperiments_max;
1716  if ( nexperiments<nexperiments_min ) nexperiments = nexperiments_min;
1717 
1718  // std::cout << "FitNull95 entries " << entries << "\tnexperiments " << nexperiments << std::endl;
1719 
1720  // std::cout << "experiments " << nexperiments_ << std::endl;
1721 
1722  // std::cout << "h entries " << s->GetEntries() << "\tn experiments " << nexperiments << "\tN " << s->GetEntries()*nexperiments << std::endl;
1723 
1725  generate::experiment e( s, nexperiments, entries );
1726 
1729  double scale = 1;
1730  if ( s_scalerms95 ) scale = 1.1479538518;
1731 
1732  // f->FixParameter( 1, s->GetMean() );
1733  f->FixParameter( 1, e.hmean() );
1734  f->SetParError( 1, e.mean_error() );
1735 
1736  f->FixParameter( 2, scale*e.hrms() );
1737  f->SetParError( 2, scale*e.rms_error() );
1738 
1739  // s->GetXaxis()->SetRange(1, s->GetNbinsX());
1740 
1741  // s->GetXaxis()->SetRangeUser(-1, 1);
1742 
1743  return f;
1744 }

◆ 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 1408 of file Resplot.cxx.

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

◆ FitPoisson()

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

Definition at line 1926 of file Resplot.cxx.

1926  {
1927 
1928  char fstring[1024];
1929  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)");
1930  TF1 *f1 = new TF1("poisson", fstring );
1931  // TF1* f1 = new TF1("poiss","[0]*TMath::Poisson(x*[2],[1])");
1932 
1933  f1->SetParName(0, "Maximum");
1934  f1->SetParName(1, "Mean");
1935  f1->SetParName(2, "Scale");
1936  f1->SetParName(3, "Offset");
1937 
1938  f1->SetNpx(5000);
1939  f1->SetLineWidth(1);
1940  f1->SetLineColor(s->GetLineColor());
1941 
1942  int nbins=0;
1943  for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1944 
1945  f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1946  f1->SetParameter(1,s->GetBinCenter(s->GetMaximumBin()));
1947  f1->SetParameter(2,1);
1948  f1->FixParameter(3,0);
1949 
1950  if (nbins>2) {
1951  // std::cout << "fitting " << f1 << std::endl;
1952  // if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1953  // else s->Fit(f1,"Q", "", a, b);
1954  if ( a==-999 || b==-999 ) s->Fit(f1);
1955  else s->Fit(f1,"", "", a, b);
1956  }
1957  else {
1958  for ( int j=0 ; j<4 ; j++ ) f1->SetParameter(j,0);
1959  }
1960 
1961  return f1;
1962 }

◆ FitRBreit()

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

Definition at line 1036 of file Resplot.cxx.

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

◆ FitRGaussian()

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

Definition at line 1031 of file Resplot.cxx.

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

◆ FitXExp()

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

Definition at line 1966 of file Resplot.cxx.

1966  {
1967 
1968  // TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))", -100, 100 );
1969  // TF1* f1 = new TF1("xexpr", "[0]*(pow([2]*x,[1])*exp(-[2]*x))+[3]");
1970  // TF1* f1 = new TF1("xexpr", "[0]*(pow((1.0/[2])*(x-[3]),[1])*exp(-(1.0/[2])*(x-[3])))");
1971  TF1* f1 = new TF1("xexpr", "[0]*(pow((1.0/[2])*x,[1])*exp(-(1.0/[2])*x))+[3]");
1972 
1973  f1->SetParName(0, "Normalisation");
1974  f1->SetParName(1, "Power");
1975  f1->SetParName(2, "Lifetime");
1976  f1->SetParName(3, "offset");
1977 
1978  // f1->SetParameter(0, 1e-156);
1979  f1->SetParameter(0, s->GetBinContent(s->GetMaximumBin()) );
1980  // f1->SetParameter(1, -1*(s->GetBinCenter(s->GetMaximumBin())) );
1981  f1->SetParameter(2, s->GetRMS() );
1982  // f1->SetParameter(1, 0);
1983  f1->SetParameter(1, 0);
1984  f1->SetParameter(3, 0);
1985 
1986  // f1->FixParameter(0, 1);
1987  // f1->FixParameter(1, 25);
1988  // f1->FixParameter(1, 0);
1989  // f1->FixParameter(3, 0);
1990 
1991  f1->SetNpx(5000);
1992  f1->SetLineWidth(1);
1993 
1994  int nbins=0;
1995  for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1996 
1997  // std::cout << "starting exp fit p1=" << f1->GetParameter(1) << std::endl;
1998 
1999  if (nbins>2) {
2000  // std::cout << "fitting " << f1 << std::endl;
2001  if ( a==-999 || b==-999 ) s->Fit(f1, "Q");
2002  else s->Fit(f1, "Q", "", a, b);
2003  }
2004  else {
2005  for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
2006  }
2007 
2008  // std::cout << "done" << std::endl;
2009 
2010  return f1;
2011 }

◆ get_mean()

StatVal Resplot::get_mean ( )
inlineprivate

Definition at line 599 of file Resplot.h.

599 { return m_g_mean; }

◆ get_sigma()

StatVal Resplot::get_sigma ( )
inlineprivate

Definition at line 600 of file Resplot.h.

600 { return m_g_sigma; }

◆ getbins()

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

Definition at line 921 of file Resplot.cxx.

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

◆ GetEfficiencies() [1/2]

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

Definition at line 958 of file Resplot.cxx.

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

◆ GetEfficiencies() [2/2]

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

Definition at line 989 of file Resplot.cxx.

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

◆ GetEfficiency()

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

Definition at line 932 of file Resplot.cxx.

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

◆ GetGlobalEfficiency()

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

Definition at line 293 of file Resplot.h.

293  {
294  return GetEfficiency(m_h1d, lower, upper);
295  }

◆ GetPrimaryCentres()

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

Definition at line 334 of file Resplot.h.

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

◆ GetPrimaryLimits()

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

Definition at line 327 of file Resplot.h.

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

◆ H1D() [1/2]

TH1D* Resplot::H1D ( )
inline

Definition at line 356 of file Resplot.h.

356 { return m_h1d; }

◆ H1D() [2/2]

const TH1D* Resplot::H1D ( ) const
inline

Definition at line 357 of file Resplot.h.

357 { return m_h1d; }

◆ H2D() [1/2]

TH2D* Resplot::H2D ( )
inline

Definition at line 360 of file Resplot.h.

360 { return m_h2d; }

◆ H2D() [2/2]

const TH2D* Resplot::H2D ( ) const
inline

Definition at line 361 of file Resplot.h.

361 { 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 243 of file Resplot.cxx.

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

◆ Initialise() [2/5]

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

Definition at line 236 of file Resplot.cxx.

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

◆ Initialise() [3/5]

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

Definition at line 296 of file Resplot.cxx.

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

◆ Initialise() [4/5]

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

Definition at line 251 of file Resplot.cxx.

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

◆ 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 194 of file Resplot.cxx.

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

◆ Integrate()

void Resplot::Integrate ( )
inline

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

Definition at line 543 of file Resplot.h.

543  {
544  if ( !m_finalised ) return;
545 
548  }

◆ MakeSlices()

void Resplot::MakeSlices ( )
inlineprivate

Definition at line 578 of file Resplot.h.

578 { }

◆ Mean() [1/2]

TH1D* Resplot::Mean ( )
inline

Definition at line 345 of file Resplot.h.

345 { return m_mean; }

◆ Mean() [2/2]

const TH1D* Resplot::Mean ( ) const
inline

Definition at line 346 of file Resplot.h.

346 { return m_mean; }

◆ Name() [1/2]

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

Definition at line 340 of file Resplot.h.

340 { return m_name; }

◆ Name() [2/2]

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

Definition at line 342 of file Resplot.h.

342 { return m_name=s; }

◆ operator*()

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

Definition at line 532 of file Resplot.h.

532  {
533  Resplot r(*this);
534  return (r*=d);
535  }

◆ operator*=()

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

Definition at line 497 of file Resplot.h.

497  {
498 
499  std::cout << "Resplot::operator*= " << Name() << " " << m_finalised << " " << m_slices.size() << std::endl;
500 
501  clear();
502 
503  std::cout << "Resplot::operator*= " << Name() << " " << m_finalised << " " << m_slices.size() << std::endl;
504  std::cout << "Resplot::operator*= " << Name() << "\tH2D " << H2D() << std::endl;
505 
506  H2D()->DrawCopy();
507 
508  std::cout << "Resplot::operator*= " << Name() << "\tDraw " << std::endl;
509 
510  for ( int i=0 ; i<=H2D()->GetNbinsX()+1 ; i++ ) {
511  for ( int j=0 ; j<=H2D()->GetNbinsY()+1 ; j++ ) {
512  H2D()->SetBinContent( i, j, H2D()->GetBinContent(i,j)*d);
513  H2D()->SetBinError( i, j, H2D()->GetBinError(i,j)*d);
514  }
515  }
516 
517 
518  std::cout << "Resplot::operator*= " << Name() << "\tH1D " << H1D() << std::endl;
519 
520  for ( int i=0 ; i<=H1D()->GetNbinsX()+1 ; i++ ) {
521  H1D()->SetBinContent( i, H1D()->GetBinContent(i)*d );
522  H1D()->SetBinError( i, H1D()->GetBinError(i)*d );
523  }
524 
525  m_finalised = false;
526 
527  std::cout << "Resplot::operator*= done" << std::endl;
528 
529  return *this;
530  }

◆ operator+()

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

Definition at line 537 of file Resplot.h.

537  {
538  Resplot r0(*this);
539  return (r0+=r);
540  }

◆ operator+=()

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

operators

Definition at line 466 of file Resplot.h.

466  {
467 
468  clear();
469 
470  // std::cout << "Resplot::operator+= " << Name() << std::endl;
471 
472  if ( r.H1D()->GetNbinsX()!=H1D()->GetNbinsX()) throw ResException("histogram limits do not match");
473  if ( r.H2D()->GetNbinsX()!=H2D()->GetNbinsX()) throw ResException("histogram limits do not match");
474  if ( r.H2D()->GetNbinsY()!=H2D()->GetNbinsY()) throw ResException("histogram limits do not match");
475 
476  for ( int i=0 ; i<=r.H2D()->GetNbinsX()+1 ; i++ ) {
477  for ( int j=0 ; j<=r.H2D()->GetNbinsY()+1 ; j++ ) {
478  H2D()->SetBinContent( i, j, H2D()->GetBinContent(i,j) + r.H2D()->GetBinContent(i,j) );
479  H2D()->SetBinError( i, j, std::sqrt(H2D()->GetBinError(i,j)*H2D()->GetBinError(i,j) + r.H2D()->GetBinError(i,j)*r.H2D()->GetBinError(i,j) ) );
480  }
481  }
482 
483  for ( int i=0 ; i<=r.H1D()->GetNbinsX()+1 ; i++ ) {
484  H1D()->SetBinContent( i, H1D()->GetBinContent(i) + r.H1D()->GetBinContent(i) );
485  H1D()->SetBinError( i, std::sqrt(H1D()->GetBinError(i)*H1D()->GetBinError(i) + r.H1D()->GetBinError(i)*r.H1D()->GetBinError(i) ) );
486  }
487 
488  m_finalised = false;
489 
490  // std::cout << "Resplot::operator+= done" << std::endl;
491 
492  return *this;
493  }

◆ rebin()

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

Definition at line 891 of file Resplot.cxx.

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

◆ Refit()

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

Definition at line 440 of file Resplot.h.

440  {
441  clear();
442  return Finalise( func );
443  }

◆ rotate()

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

flip the x and y axes

rotate a TH2D

Definition at line 564 of file Resplot.cxx.

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

◆ SetDirectory()

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

Definition at line 459 of file Resplot.h.

459 { }

◆ setInterpolateFlag()

static void Resplot::setInterpolateFlag ( bool  b)
inlinestatic

Definition at line 461 of file Resplot.h.

461 { s_interpolate_flag = b; }

◆ setnofit()

static bool Resplot::setnofit ( bool  b)
inlinestatic

Definition at line 555 of file Resplot.h.

555 { return s_nofit=b; }

◆ setoldrms95()

static bool Resplot::setoldrms95 ( bool  b)
inlinestatic

Definition at line 553 of file Resplot.h.

553 { return s_oldrms95=b; }

◆ SetPrimary() [1/2]

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

Definition at line 592 of file Resplot.h.

592 { m_n_primary=n; }

◆ SetPrimary() [2/2]

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

Definition at line 593 of file Resplot.h.

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

◆ setscalerms95()

static bool Resplot::setscalerms95 ( bool  b)
inlinestatic

Definition at line 554 of file Resplot.h.

554 { return s_scalerms95=b; }

◆ SetSecondary()

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

Definition at line 594 of file Resplot.h.

◆ setUniform()

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

Definition at line 550 of file Resplot.h.

550 { m_uniform=t; }

◆ SetXAxis()

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

Definition at line 309 of file Resplot.h.

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

◆ SetYAxis()

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

Definition at line 320 of file Resplot.h.

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

◆ Sigma()

TH1D* Resplot::Sigma ( )
inline

Definition at line 349 of file Resplot.h.

349 { return m_sigma; }

◆ skip() [1/2]

void Resplot::skip ( TH1D *  t)
inlineprivate

Definition at line 583 of file Resplot.h.

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

◆ skip() [2/2]

void Resplot::skip ( TH2D *  t)
inlineprivate

Definition at line 587 of file Resplot.h.

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

◆ Slices()

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

Definition at line 370 of file Resplot.h.

370 { return m_slices; }

◆ Uncertainty() [1/2]

TH1D* Resplot::Uncertainty ( )
inline

Definition at line 364 of file Resplot.h.

364 { return m_Nentries; }

◆ Uncertainty() [2/2]

const TH1D* Resplot::Uncertainty ( ) const
inline

Definition at line 365 of file Resplot.h.

365 { return m_Nentries; }

◆ version()

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

Definition at line 552 of file Resplot.h.

552 { return s_rversion; }

◆ Write() [1/2]

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

Definition at line 453 of file Resplot.h.

453 { return DWrite(); }

◆ 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 452 of file Resplot.h.

452 { return DWrite(); }

Member Data Documentation

◆ m_a_secondary

double Resplot::m_a_secondary
private

Definition at line 659 of file Resplot.h.

◆ m_b_secondary

double Resplot::m_b_secondary
private

Definition at line 659 of file Resplot.h.

◆ m_chi2

TH1D* Resplot::m_chi2 = 0
private

Definition at line 645 of file Resplot.h.

◆ m_dir

TDirectory* Resplot::m_dir = 0
private

Definition at line 653 of file Resplot.h.

◆ m_finalised

bool Resplot::m_finalised
private

Definition at line 667 of file Resplot.h.

◆ m_fitname

std::string Resplot::m_fitname
private

Definition at line 665 of file Resplot.h.

◆ m_g_mean

StatVal Resplot::m_g_mean
private

Definition at line 650 of file Resplot.h.

◆ m_g_sigma

StatVal Resplot::m_g_sigma
private

Definition at line 651 of file Resplot.h.

◆ m_h1d

TH1D* Resplot::m_h1d = 0
private

Definition at line 648 of file Resplot.h.

◆ m_h2d

TH2D* Resplot::m_h2d = 0
private

Definition at line 647 of file Resplot.h.

◆ m_mean

TH1D* Resplot::m_mean = 0
private

Definition at line 643 of file Resplot.h.

◆ m_n_primary

int Resplot::m_n_primary
private

Definition at line 655 of file Resplot.h.

◆ m_n_secondary

int Resplot::m_n_secondary
private

Definition at line 658 of file Resplot.h.

◆ m_name

std::string Resplot::m_name
private

Definition at line 640 of file Resplot.h.

◆ m_Nentries

TH1D* Resplot::m_Nentries = 0
private

Definition at line 642 of file Resplot.h.

◆ m_Set

bool Resplot::m_Set
private

Definition at line 638 of file Resplot.h.

◆ m_sigma

TH1D* Resplot::m_sigma = 0
private

Definition at line 644 of file Resplot.h.

◆ m_slicedir

TDirectory* Resplot::m_slicedir = 0
private

Definition at line 668 of file Resplot.h.

◆ m_slices

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

Definition at line 664 of file Resplot.h.

◆ m_uniform

bool Resplot::m_uniform
private

Definition at line 670 of file Resplot.h.

◆ m_xaxis

std::string Resplot::m_xaxis
private

Definition at line 661 of file Resplot.h.

◆ m_yaxis

std::string Resplot::m_yaxis
private

Definition at line 662 of file Resplot.h.

◆ s_ErrorSet

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

Definition at line 680 of file Resplot.h.

◆ s_interpolate_flag

bool Resplot::s_interpolate_flag
staticprivate

Definition at line 634 of file Resplot.h.

◆ s_mAddDirectoryStatus

bool Resplot::s_mAddDirectoryStatus
staticprivate

Definition at line 633 of file Resplot.h.

◆ s_nofit

bool Resplot::s_nofit = false
staticprivate

Definition at line 677 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 674 of file Resplot.h.

◆ s_rversion

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

Definition at line 636 of file Resplot.h.

◆ s_scalerms95

bool Resplot::s_scalerms95 = true
staticprivate

Definition at line 675 of file Resplot.h.


The documentation for this class was generated from the following files:
AllowedVariables::e
e
Definition: AsgElectronSelectorTool.cxx:37
beamspotman.r
def r
Definition: beamspotman.py:676
FindMean
double FindMean(TH1D *s, double frac=0.95)
Definition: Resplot.cxx:1309
Resplot::AddDirectoryStatus
static bool AddDirectoryStatus()
Definition: Resplot.h:456
nexperiments_max
int nexperiments_max
Definition: Resplot.cxx:1682
pdg_comparison.sigma
sigma
Definition: pdg_comparison.py:324
python.SystemOfUnits.s
int s
Definition: SystemOfUnits.py:131
mean
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="")
Definition: dependence.cxx:254
Resplot::m_name
std::string m_name
Definition: Resplot.h:640
Resplot::m_mean
TH1D * m_mean
Definition: Resplot.h:643
python.SystemOfUnits.m
int m
Definition: SystemOfUnits.py:91
langaufun
Double_t langaufun(Double_t *x_par, Double_t *par)
Definition: Resplot.cxx:2018
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
Resplot::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:342
Resplot::SetDirectory
void SetDirectory(TDirectory *=0)
Definition: Resplot.h:459
dqt_zlumi_pandas.hname
string hname
Definition: dqt_zlumi_pandas.py:279
hist_file_dump.d
d
Definition: hist_file_dump.py:137
Resplot::m_finalised
bool m_finalised
Definition: Resplot.h:667
ZeroErrors
void ZeroErrors(TH1D *h)
Definition: Resplot.cxx:67
number
std::string number(const double &x)
Definition: Resplot.cxx:373
Resplot::m_Set
bool m_Set
Definition: Resplot.h:638
Resplot::s_scalerms95
static bool s_scalerms95
Definition: Resplot.h:675
Directory
Definition: Directory.h:29
PixelAthClusterMonAlgCfg.ybins
ybins
Definition: PixelAthClusterMonAlgCfg.py:169
generate::experiment
given a histogram, get a generator for the distribution in that histogram, then run some pseudo-exper...
Definition: generate.h:132
Resplot::m_h1d
TH1D * m_h1d
Definition: Resplot.h:648
Resplot::m_Nentries
TH1D * m_Nentries
Definition: Resplot.h:642
Resplot::m_sigma
TH1D * m_sigma
Definition: Resplot.h:644
upper
int upper(int c)
Definition: LArBadChannelParser.cxx:49
JetTiledMap::N
@ N
Definition: TiledEtaPhiMap.h:44
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Resplot::m_dir
TDirectory * m_dir
Definition: Resplot.h:653
yodamerge_tmp.scale
scale
Definition: yodamerge_tmp.py:138
trigbs_dumpHLTContentInBS.stats
stats
Definition: trigbs_dumpHLTContentInBS.py:91
Resplot::GetGlobalEfficiency
StatVal GetGlobalEfficiency(double lower, double upper)
Definition: Resplot.h:293
Resplot::m_a_secondary
double m_a_secondary
Definition: Resplot.h:659
x
#define x
read_hist_ntuple.f2
f2
Definition: read_hist_ntuple.py:20
unZeroErrors
void unZeroErrors(TH1D *h)
Definition: Resplot.cxx:73
Resplot::SetSecondary
void SetSecondary(int n, double a, double b)
Definition: Resplot.h:594
Resplot::FitInternal
static TF1 * FitInternal(TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
Definition: Resplot.cxx:1051
Resplot::Initialise
void Initialise(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
Definition: Resplot.cxx:194
fitman.hy
def hy
Definition: fitman.py:515
GetStats
void GetStats(TH1D *h, std::vector< double > &stats)
Definition: Resplot.cxx:113
Resplot::m_uniform
bool m_uniform
Definition: Resplot.h:670
Resplot::FitNull95Obsolete
static TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
Definition: Resplot.cxx:1408
defineDB.tagname
string tagname
Definition: JetTagCalibration/share/defineDB.py:19
ParseInputs.gDirectory
gDirectory
Definition: Final2012/ParseInputs.py:133
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
beamspotman.n
n
Definition: beamspotman.py:731
checkxAOD.frac
frac
Definition: Tools/PyUtils/bin/checkxAOD.py:259
Resplot::FitNull95New
static TF1 * FitNull95New(TH1D *s, double frac=0.95, bool useroot=false)
Definition: Resplot.cxx:1687
Resplot::m_slices
std::vector< TH1D * > m_slices
Definition: Resplot.h:664
TRT_PAI_physicsConstants::r0
const double r0
electron radius{cm}
Definition: TRT_PAI_physicsConstants.h:20
Resplot::m_b_secondary
double m_b_secondary
Definition: Resplot.h:659
Resplot::s_oldrms95
static bool s_oldrms95
temporarily allow toggeling between old and new rms95 error estimates
Definition: Resplot.h:674
Resplot::findbins
static std::vector< double > findbins(const TH1 *h, double epsilon)
Definition: Resplot.cxx:838
Resplot::Name
const std::string & Name() const
Definition: Resplot.h:340
hist_file_dump.f
f
Definition: hist_file_dump.py:135
plotting.yearwise_luminosity_vs_mu.bins
bins
Definition: yearwise_luminosity_vs_mu.py:30
Resplot
Definition: Resplot.h:50
Resplot::GetEfficiency
StatVal GetEfficiency(TH1D *h, double lower, double upper)
Definition: Resplot.cxx:932
Resplot::rotate
static TH2D * rotate(const TH2 *h)
flip the x and y axes
Definition: Resplot.cxx:564
imax
int imax(int i, int j)
Definition: TileLaserTimingTool.cxx:33
findmax
int findmax(TH1D *s)
Definition: Resplot.cxx:1396
Resplot::get_mean
StatVal get_mean()
Definition: Resplot.h:599
Resplot::m_yaxis
std::string m_yaxis
Definition: Resplot.h:662
Resplot::H1D
TH1D * H1D()
Definition: Resplot.h:356
Resplot::Write
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:452
Resplot::OK
@ OK
Definition: Resplot.h:59
Resplot::m_g_mean
StatVal m_g_mean
Definition: Resplot.h:650
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
Resplot::EMPTY
@ EMPTY
Definition: Resplot.h:59
Resplot::skip
void skip(TH1D *t)
Definition: Resplot.h:583
Resplot::m_n_primary
int m_n_primary
Definition: Resplot.h:655
Resplot::get_sigma
StatVal get_sigma()
Definition: Resplot.h:600
Resplot::m_h2d
TH2D * m_h2d
Definition: Resplot.h:647
Resplot::Finalise
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=Resplot::FitGaussian)
Definition: Resplot.cxx:388
SCT_CalibAlgs::nbins
@ nbins
Definition: SCT_CalibNumbers.h:10
Resplot::BINWIDTH
@ BINWIDTH
Definition: Resplot.h:59
LArCellBinning.xbins
int xbins
Definition: LArCellBinning.py:163
Resplot::s_interpolate_flag
static bool s_interpolate_flag
Definition: Resplot.h:634
Rtt_histogram.n1
n1
Definition: Rtt_histogram.py:21
nexperiments_
int nexperiments_
Definition: Resplot.cxx:1681
cwd
std::string cwd
Definition: listroot.cxx:38
python.PyAthena.v
v
Definition: PyAthena.py:154
Resplot::H2D
TH2D * H2D()
Definition: Resplot.h:360
Resplot::m_n_secondary
int m_n_secondary
Definition: Resplot.h:658
ReadBchFromCool.good
good
Definition: ReadBchFromCool.py:433
a
TList * a
Definition: liststreamerinfos.cxx:10
y
#define y
h
Resplot::clear
void clear()
Definition: Resplot.h:623
StatVal
simple struct to hold a value and it's associated uncertainty.
Definition: StatVal.h:26
Resplot::m_xaxis
std::string m_xaxis
Definition: Resplot.h:661
Resplot::m_fitname
std::string m_fitname
Definition: Resplot.h:665
generate::GetEntries
double GetEntries(TH1D *h, int ilow, int ihi)
Definition: rmsFrac.cxx:20
Resplot::s_ErrorSet
static ERROR s_ErrorSet
Definition: Resplot.h:680
beamspotnt.rms
rms
Definition: bin/beamspotnt.py:1266
fitman.hx
def hx
Definition: fitman.py:514
entries
double entries
Definition: listroot.cxx:49
tagname
Definition: tagname.h:29
Resplot::m_chi2
TH1D * m_chi2
Definition: Resplot.h:645
nexperiments_min
int nexperiments_min
Definition: Resplot.cxx:1683
Resplot::s_nofit
static bool s_nofit
Definition: Resplot.h:677
Resplot::delskip
void delskip(TH1D *t)
Definition: Resplot.h:584
Resplot::s_mAddDirectoryStatus
static bool s_mAddDirectoryStatus
Definition: Resplot.h:633
Resplot::SetPrimary
void SetPrimary(int n, const double *)
Definition: Resplot.h:592
Resplot::s_rversion
static const std::string s_rversion
Definition: Resplot.h:636
CaloCondBlobAlgs_fillNoiseFromASCII.tag
string tag
Definition: CaloCondBlobAlgs_fillNoiseFromASCII.py:24
Resplot::rebin
static TH1D * rebin(const TH1 *h, const std::vector< double > &bins)
Definition: Resplot.cxx:891
python.IoTestsLib.w
def w
Definition: IoTestsLib.py:200
Resplot::HISTOWIDTH
@ HISTOWIDTH
Definition: Resplot.h:59
binwidth
void binwidth(TH1D *h)
Definition: Resplot.cxx:50
test_pyathena.counter
counter
Definition: test_pyathena.py:15
fitman.k
k
Definition: fitman.py:528
Resplot::m_g_sigma
StatVal m_g_sigma
Definition: Resplot.h:651
read_hist_ntuple.f1
f1
Definition: read_hist_ntuple.py:4