33 for (
int i=0 ; i<=hin->GetNbinsX()+1 ; i++ ) {
34 hin->SetBinContent(i, 0);
35 hin->SetBinError(i, 0);
42 for (
int i=1 ; i<=hin->GetNbinsX() ; i++ ) N += hin->GetBinContent(i);
47double get_mean(
const std::vector<double>& m ) {
49 for (
unsigned i=0 ; i<m.size() ; i++ )
mean += m[i];
54double get_rms(
const std::vector<double>& m ) {
57 for (
unsigned i=0 ; i<m.size() ; i++ ) {
58 double r = (m[i]-
mean);
61 return std::sqrt( rms/m.size() );
70 TH1D* hint = (TH1D*)hin->Clone( (std::string(hin->GetName())+
"-cumulative").c_str() );
74 hint->SetBinContent(0,0);
75 hint->SetBinContent(hin->GetNbinsX()+1,0);
77 for (
int i=1 ; i<=hin->GetNbinsX()+1 ; i++ ) {
78 double c = hin->GetBinContent(i) + hint->GetBinContent(i-1);
79 hint->SetBinContent(i, c);
80 hint->SetBinError(i, std::sqrt(c) );
83 hint->SetBinContent(hin->GetNbinsX()+1, hint->GetBinContent(hin->GetNbinsX()) );
94 double N = hin->GetBinContent(hin->GetNbinsX());
96 for (
int i=0 ; i<=hin->GetNbinsX()+1 ; i++ ) {
98 double n = hin->GetBinContent(i);
102 double ee = std::sqrt(e*(1-e)/N);
104 hin->SetBinContent(i, e);
105 hin->SetBinError(i, ee);
124 for (
int i=2 ; i<hin->GetNbinsX() ; i++ ) {
125 double g = hin->GetBinContent(i+1)-hin->GetBinContent(i-1);
126 if ( std::fabs(gmax)<std::fabs(g) ) {
131 return gmax/hin->GetBinError(
imax);
139 for (
int i=2 ; i<hin->GetNbinsX() ; i++ ) {
140 double g = hin->GetBinContent(i+1)-hin->GetBinContent(i-1);
141 if ( std::fabs(gmax)<std::fabs(g) ) {
160 TH1D* hsmooth = (TH1D*)hin->Clone( (std::string(hin->GetName())+
"-smooth").c_str() );
161 hsmooth->SetDirectory(0);
176 hint->SetDirectory(0);
178 for (
int i=2 ; i<hsmooth->GetNbinsX() ; i++ ) {
179 double gradient = std::fabs(0.5*(hint->GetBinContent(i+1) - hint->GetBinContent(i-1)));
191 const double sfac = 0.1;
195 for (
int i=1 ; i<=hsmooth->GetNbinsX() ; i++ ) {
198 int Nbins = 2*sfac*std::fabs( i-img );
207 for (
int j=i-Nbins ; j<=i+Nbins ; j++ ) {
209 if ( j>hin->GetNbinsX() )
break;
210 sum += hin->GetBinContent(j);
214 if ( wsum>0 ) sum /= wsum;
218 hsmooth->SetBinContent(i, sum);
219 hsmooth->SetBinError(i, 0 );
242 m_smooth = (TH1D*)
h->Clone( (std::string(
h->GetName())+
"-smooth").c_str() );
255 m_x.push_back(
m_s->GetBinLowEdge(1) );
258 for (
int i=1 ; i<=
m_s->GetNbinsX() ; i++ ) {
259 m_x.push_back(
m_s->GetBinLowEdge(i+1) );
260 m_y.push_back(
m_s->GetBinContent(i) );
269 for (
unsigned i=0 ; i<
m_y.size()-1 ; i++ ) {
270 double dy =
m_y[i+1] -
m_y[i];
271 double dx =
m_x[i+1] -
m_x[i];
303 :
m_N(Nexperiments) {
314 std::cout <<
"mean " <<
h->GetMean() <<
" +- " <<
h->GetMeanError() <<
" (" <<
findMean(
h,0.95) <<
")"
315 <<
"\trms " <<
h->GetRMS() <<
" +- " <<
h->GetRMSError() <<
" (" <<
rms95(
h) <<
")"
316 <<
"\thistogram" << std::endl;
329 h->GetXaxis()->SetRange(1,
h->GetNbinsX());
337 int Nevents =
h->GetEffectiveEntries()+0.5;
341 if ( fevents!=0 ) Nevents = fevents;
354 double Nevents_ = Nevents;
364 fnscale = std::sqrt( Nevents/Nevents_ );
372 gStyle->SetOptStat(1111);
373 hmean =
new TH1D(
"mean",
"", 500, -0.001, 0.001);
374 hrms =
new TH1D(
"rms",
"", 500, 0.001, 0.01);
375 hmean->SetDirectory(0);
376 hrms->SetDirectory(0);
383 m_THrms =
new TH1D(
"rms95",
"", 50, 0.0006, 0.0009 );
386 for (
int j=0 ; j<
m_N ; j++ ) {
388 TH1D* h3 = (TH1D*)
h->Clone();
391 for (
int i=Nevents ; i-- ; ) h3->Fill( g.generate() );
399 std::cout << j <<
"\texpt mean " << mean95_ <<
"\trms95 " << rms95_ << std::endl;
401 if ( std::string(
h->GetTitle()).find(
"[ 34.4747 - 42.1697 ]")!=std::string::npos ) {
403 std::cout <<
"mean " << h3->GetMean() <<
" +- " << h3->GetMeanError()
404 <<
" (" << mean95_ <<
") "
405 <<
"\trms " << h3->GetRMS() <<
" +- " << h3->GetRMSError()
406 <<
" (" << rms95_ <<
") "
407 <<
"\t pseudo data (" << Nevents <<
" events)"
415 mean.push_back( mean95_ );
416 rms.push_back( rms95_ );
426 if ( std::string(
h->GetTitle()).find(
"[ 34.4747 - 42.1697 ]")!=std::string::npos ) {
428 std::cout <<
"mean " <<
h->GetMean() <<
" +- " <<
h->GetMeanError() <<
" (" <<
findMean(
h,0.95) <<
")"
429 <<
"\trms " <<
h->GetRMS() <<
" +- " <<
h->GetRMSError() <<
" (" <<
rms95(
h) <<
")"
430 <<
"\thistogram" << std::endl;
435 <<
" after " << Nexperiments <<
" experiment" << ( Nexperiments==1 ?
"" :
"s" )
a Randomnumber generator with a data member TRandom3 so that we can either use a shared generator or ...
Header file for AthHistogramAlgorithm.
std::vector< double > m_mean
number of experiments
double m_global_mean_error
experiment(TH1D *h, int Nexperiments=10, int fevents=0)
given a distribution, gnerate some number of pseudo experiments to estimate the uncertainties in the ...
double m_hmean
rms from each experiment
double m_global_rms_error
double m_hrms
actual histogram mean95
double m_global_mean
actual histogram rms95
std::vector< double > m_rms
means from each experiment
base class for a "generator" class
generate a distribution according to an input histogram (after smoothing)
std::vector< double > m_y
std::vector< double > m_x
std::vector< double > m_dy
hist_generator(TH1D *h, bool smooth_=true)
std::vector< double > m_dxdy
std::vector< double > m_dx
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="")
TH1D * smooth(TH1D *hin, bool sym)
smooth a distribution about the maximum NB: maximum is not smoothed
TH1D * integrate(TH1D *hin)
generate an integrated distribution
void ScaleIntegral(TH1D *hin)
scale a distribution by the integral
double Entries(TH1D *hin)
TH1D * PDF(TH1D *hin)
generate a (normalised) pdf from a distribution
double get_rms(const std::vector< double > &m)
double rms95(TH1D *s, double mean)
get the fraction of the rms95 value with respect to the rms95 value of a gaussian
double findMean(TH1D *s, double frac=0.95)
double get_mean(const std::vector< double > &m)
mean and rms
double Gradient(TH1D *hin)
double rmsFrac(TH1D *s, double frac, double mean)
static const bool printPad