given a histogram, get a generator for the distribution in that histogram, then run some pseudo-experiments and collect the mean and rms
More...
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.
| 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
307
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
320
321
322
325
326
327
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
337 int Nevents =
h->GetEffectiveEntries()+0.5;
338
339
340
341 if ( fevents!=0 )
Nevents = fevents;
342
343
344
345
353
355
359 }
360
362
364 fnscale = std::sqrt( Nevents/Nevents_ );
365
366
367
370
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
380
382
383 m_THrms =
new TH1D(
"rms95",
"", 50, 0.0006, 0.0009 );
385
386 for (
int j=0 ; j<
m_N ; j++ ) {
387
388 TH1D* h3 = (TH1D*)
h->Clone();
390
391 for (
int i=Nevents ;
i-- ; ) h3->Fill(
g.generate() );
392
394
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
415 mean.push_back( mean95_ );
416 rms.push_back( rms95_ );
417
419
420 delete h3;
421 }
422
423
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
435 << " after " << Nexperiments << " experiment" << ( Nexperiments==1 ? "" : "s" )
436 << std::endl;
437 }
438#endif
439
442
446
447
448
449
450
451
452}
std::vector< double > m_mean
number of experiments
double m_global_mean_error
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
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 rmsFrac(TH1D *s, double frac, double mean)
static const bool printPad