ATLAS Offline Software
Public Member Functions | Private Attributes | List of all members
generate::experiment Class Reference

given a histogram, get a generator for the distribution in that histogram, then run some pseudo-experiments and collect the mean and rms
More...

#include <generate.h>

Collaboration diagram for generate::experiment:

Public Member Functions

 experiment (TH1D *h, int Nexperiments=10, int fevents=0)
 given a distribution, gnerate some number of pseudo experiments to estimate the uncertainties in the mean and rms more appropriately (root errors assume a gaussian approximation) More...
 
 experiment (const experiment &)=delete
 
experiment operator= (const experiment &)=delete
 
double hmean () const
 
double hrms () const
 
double mean () const
 
double mean_error () const
 
double rms () const
 
double rms_error () const
 
generator_basegen ()
 
TH1D * rmshisto ()
 

Private Attributes

int m_N
 
std::vector< double > m_mean
 number of experiments More...
 
std::vector< double > m_rms
 means from each experiment More...
 
double m_hmean
 rms from each experiment More...
 
double m_hrms
 actual histogram mean95 More...
 
double m_global_mean
 actual histogram rms95 More...
 
double m_global_mean_error
 
double m_global_rms
 
double m_global_rms_error
 
generator_basem_gen
 
TH1D * m_THrms
 

Detailed Description

given a histogram, get a generator for the distribution in that histogram, then run some pseudo-experiments and collect the mean and rms

Definition at line 132 of file generate.h.

Constructor & Destructor Documentation

◆ experiment() [1/2]

generate::experiment::experiment ( TH1D *  h,
int  Nexperiments = 10,
int  fevents = 0 
)

given a distribution, gnerate some number of pseudo experiments to estimate the uncertainties in the mean and rms more appropriately (root errors assume a gaussian approximation)

NB: Here we need to keep track of the number of events in the histogram. To correctly estimate the uncertainty on the rms, we should use the same number of entries N, for each pseudo-experiment but this can be computaionally very expensive and time consuming, so we generate in this case with fewer events, n, and estimate the uncertainty by scaling by sqrt( n/N )

std::cout << "generate() " << h->GetName() << " requested " << Nevents << " using default max of " << Nevent_max << std::endl;

set the correct error scaling to the correct number of events

loop over the pseudo experiments

Definition at line 302 of file generate.cxx.

303  : m_N(Nexperiments) {
304 
305  std::vector<double>& mean = m_mean;
306  std::vector<double>& rms = m_rms;
307 
308  mean.clear();
309  rms.clear();
310 
311  double fnscale = 1;
312 
313 #if 0
314  std::cout << "mean " << h->GetMean() << " +- " << h->GetMeanError() << " (" << findMean(h,0.95) << ")"
315  << "\trms " << h->GetRMS() << " +- " << h->GetRMSError() << " (" << rms95(h) << ")"
316  << "\thistogram" << std::endl;
317 #endif
318 
319  // std::cout << "experiment() actual histogram " << std::endl;
320 
321  // m_hmean = h->GetMean();
322  // m_hrms = rms95(h, findMean(h,0.95) );
323  m_hmean = findMean(h, frac);
324  m_hrms = rmsFrac(h, frac, m_hmean );
325  // m_hrms = rms95(h, m_hmean );
326 
327  // std::cout << "central mean " << m_hmean << "\trms95 " << m_hrms << std::endl;
328 
329  h->GetXaxis()->SetRange(1,h->GetNbinsX());
330 
331  m_gen = new hist_generator( h );
332  generator_base& g = *m_gen;
333 
334 
335 
336  // int Nevents = Entries(h);
337  int Nevents = h->GetEffectiveEntries()+0.5; // Entries(h);
338 
339  // std::cout << "Nevents " << Nevents << "\tfevents " << fevents << std::endl;
340 
341  if ( fevents!=0 ) Nevents = fevents;
342 
343 
344  // std::cout << "Nevents: " << Entries(h) << "\tweights: " << Nevents << " ( max " << Nevent_max << " min " << Nevent_min << ")"; // << std::endl;
345 
353 
354  double _Nevents = Nevents;
355 
356  if ( Nevents>Nevent_max ) {
359  }
360 
362 
364  fnscale = std::sqrt( Nevents/_Nevents );
365 
366  // std::cout << "\tusing: " << Nevents << std::endl;
367 
368  TH1D* hmean = 0;
369  TH1D* hrms = 0;
370 
371  if ( printPad ) {
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);
377  }
378 
379  // std::cout << "experiment() pseudo data " << std::endl;
380 
382 
383  m_THrms = new TH1D("rms95", "", 50, 0.0006, 0.0009 );
384  m_THrms->SetDirectory(0);
385 
386  for ( int j=0 ; j<m_N ; j++ ) {
387 
388  TH1D* h3 = (TH1D*)h->Clone();
389  Zero( h3 );
390 
391  for ( int i=Nevents ; i-- ; ) h3->Fill( g.generate() );
392 
393  double _mean95 = findMean( h3, frac );
394  // double _rms95 = 1.1479538518*rmsFrac( h3, 0.95, _mean95 );
395  double _rms95 = rmsFrac( h3, frac, _mean95 );
396 
397 
398 #if 0
399  std::cout << j << "\texpt mean " << _mean95 << "\trms95 " << _rms95 << std::endl;
400 
401  if ( std::string(h->GetTitle()).find("[ 34.4747 - 42.1697 ]")!=std::string::npos ) {
402 
403  std::cout << "mean " << h3->GetMean() << " +- " << h3->GetMeanError()
404  << " (" << _mean95 << ") "
405  << "\trms " << h3->GetRMS() << " +- " << h3->GetRMSError()
406  << " (" << _rms95 << ") "
407  << "\t pseudo data (" << Nevents << " events)"
408  << std::endl;
409  }
410 
411 #endif
412 
413 
414  // mean.push_back( h3->GetMean() );
415  mean.push_back( _mean95 );
416  rms.push_back( _rms95 );
417 
418  m_THrms->Fill( _rms95 );
419 
420  delete h3;
421  }
422 
423  // std::cout << "averages" << std::endl;
424 
425 #if 0
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;
431 
433  std::cout << "mean " << get_mean(mean) << " +- " << get_rms(mean);
434  std::cout << "\trms " << get_mean(rms) << " +- " << get_rms(rms)
435  << " after " << Nexperiments << " experiment" << ( Nexperiments==1 ? "" : "s" )
436  << std::endl;
437  }
438 #endif
439 
441  m_global_mean_error = get_rms(mean)*fnscale;
442 
444  m_global_rms_error = get_rms(rms)*fnscale;
445  delete m_gen;
446 
447 
448  // std::cout << "\t\t mean " << m_global_mean << " +- " << m_global_mean_error
449  // << "\t mean " << m_global_rms << " +- " << m_global_rms_error
450  // << std::endl;
451 
452 }

◆ experiment() [2/2]

generate::experiment::experiment ( const experiment )
delete

Member Function Documentation

◆ gen()

generator_base* generate::experiment::gen ( )
inline

Definition at line 149 of file generate.h.

149 { return m_gen; }

◆ hmean()

double generate::experiment::hmean ( ) const
inline

Definition at line 140 of file generate.h.

140 { return m_hmean; }

◆ hrms()

double generate::experiment::hrms ( ) const
inline

Definition at line 141 of file generate.h.

141 { return m_hrms; }

◆ mean()

double generate::experiment::mean ( ) const
inline

Definition at line 143 of file generate.h.

143 { return m_global_mean; }

◆ mean_error()

double generate::experiment::mean_error ( ) const
inline

Definition at line 144 of file generate.h.

144 { return m_global_mean_error; }

◆ operator=()

experiment generate::experiment::operator= ( const experiment )
delete

◆ rms()

double generate::experiment::rms ( ) const
inline

Definition at line 146 of file generate.h.

146 { return m_global_rms; }

◆ rms_error()

double generate::experiment::rms_error ( ) const
inline

Definition at line 147 of file generate.h.

147 { return m_global_rms_error; }

◆ rmshisto()

TH1D* generate::experiment::rmshisto ( )
inline

Definition at line 151 of file generate.h.

151 { return m_THrms; }

Member Data Documentation

◆ m_gen

generator_base* generate::experiment::m_gen
private

Definition at line 170 of file generate.h.

◆ m_global_mean

double generate::experiment::m_global_mean
private

actual histogram rms95

overall mean and rms from the pseudo experiments

Definition at line 164 of file generate.h.

◆ m_global_mean_error

double generate::experiment::m_global_mean_error
private

Definition at line 165 of file generate.h.

◆ m_global_rms

double generate::experiment::m_global_rms
private

Definition at line 167 of file generate.h.

◆ m_global_rms_error

double generate::experiment::m_global_rms_error
private

Definition at line 168 of file generate.h.

◆ m_hmean

double generate::experiment::m_hmean
private

rms from each experiment

Definition at line 160 of file generate.h.

◆ m_hrms

double generate::experiment::m_hrms
private

actual histogram mean95

Definition at line 161 of file generate.h.

◆ m_mean

std::vector<double> generate::experiment::m_mean
private

number of experiments

Definition at line 157 of file generate.h.

◆ m_N

int generate::experiment::m_N
private

Definition at line 155 of file generate.h.

◆ m_rms

std::vector<double> generate::experiment::m_rms
private

means from each experiment

Definition at line 158 of file generate.h.

◆ m_THrms

TH1D* generate::experiment::m_THrms
private

Definition at line 172 of file generate.h.


The documentation for this class was generated from the following files:
generate::experiment::hmean
double hmean() const
Definition: generate.h:140
generate::experiment::m_THrms
TH1D * m_THrms
Definition: generate.h:172
generate::experiment::m_global_mean
double m_global_mean
actual histogram rms95
Definition: generate.h:164
generate::experiment::m_global_rms_error
double m_global_rms_error
Definition: generate.h:168
generate::frac
const double frac
Definition: generate.cxx:295
generate::rms95
double rms95(TH1D *s, double mean)
get the fraction of the rms95 value with respect to the rms95 value of a gaussian
Definition: rmsFrac.cxx:285
generate::get_mean
double get_mean(const std::vector< double > &m)
mean and rms
Definition: generate.cxx:47
lumiFormat.i
int i
Definition: lumiFormat.py:85
python.CaloCondTools.g
g
Definition: CaloCondTools.py:15
generate::experiment::m_hmean
double m_hmean
rms from each experiment
Definition: generate.h:160
generate::experiment::m_mean
std::vector< double > m_mean
number of experiments
Definition: generate.h:157
generate::experiment::mean
double mean() const
Definition: generate.h:143
generate::experiment::m_N
int m_N
Definition: generate.h:155
generate::experiment::rms
double rms() const
Definition: generate.h:146
generate::experiment::m_global_rms
double m_global_rms
Definition: generate.h:167
generate::experiment::hrms
double hrms() const
Definition: generate.h:141
LArHVCorrMonAlg.Nevents
int Nevents
Definition: LArHVCorrMonAlg.py:212
generate::Nevent_min
int Nevent_min
Definition: generate.cxx:292
generate::experiment::m_hrms
double m_hrms
actual histogram mean95
Definition: generate.h:161
generate::Nevent_max
int Nevent_max
Definition: generate.cxx:293
generate::get_rms
double get_rms(const std::vector< double > &m)
Definition: generate.cxx:54
h
generate::experiment::m_gen
generator_base * m_gen
Definition: generate.h:170
generate::experiment::m_global_mean_error
double m_global_mean_error
Definition: generate.h:165
generate::experiment::m_rms
std::vector< double > m_rms
means from each experiment
Definition: generate.h:158
generate::rmsFrac
double rmsFrac(TH1D *s, double frac, double mean)
Definition: rmsFrac.cxx:193
generate::Zero
void Zero(TH1D *hin)
Definition: generate.cxx:32
generate::findMean
double findMean(TH1D *s, double frac=0.95)
Definition: rmsFrac.cxx:84