ATLAS Offline Software
Loading...
Searching...
No Matches
Resplot.cxx
Go to the documentation of this file.
1
18
19#include <sstream>
20#include <cmath>
21
22
23#include "Directory.h"
24#include "tagname.h"
25
26#include "Resplot/Resplot.h"
27
28#include "TCanvas.h"
29#include "TStyle.h"
30#include "TMath.h"
31
32#include "generate.h"
33#include "rmsFrac.h"
34
35namespace Resplot {
36
37// ClassImp(Resplot)
38
39
41
43bool s_nofit = false;
44
46bool s_oldrms95 = true;
47bool s_scalerms95 = true;
48
49// const Resplot::ERROR Resplot::s_ErrorSet = Resplot::OK;
50
51
52void binwidth(TH1D* h) {
53
54 for (int i=1 ; i<=h->GetNbinsX() ; i++ ) {
55 double d = h->GetBinLowEdge(i+1) - h->GetBinLowEdge(i);
56
57 h->SetBinContent(i, h->GetBinContent(i)/d );
58 h->SetBinError(i, h->GetBinError(i)/d );
59 }
60
61}
62
63
64// set the errors on bins with zero entries to be one so they
65// are not ignored in the fit
66// USE WITH CARE - root screws up the mean and rms error calculation
67// if these are used
68
69void ZeroErrors(TH1D* h) {
70 for (int i=1 ; i<=h->GetNbinsX() ; i++ ) if (h->GetBinContent(i)==0) h->SetBinError(i,1);
71}
72
73// and put them back to zero again afterwards
74
75void unZeroErrors(TH1D* h) {
76 for (int i=1 ; i<=h->GetNbinsX() ; i++ ) if (h->GetBinContent(i)==0) h->SetBinError(i,0);
77}
78
79
80
81double getWeights(TH1D* h) {
82 double sum = 0;
83 double sume2 = 0;
84 for ( int i=0 ; i<h->GetNbinsX()+1 ; i++ ) {
85 sum += h->GetBinContent(i);
86 sume2 += h->GetBinError(i)*h->GetBinError(i);
87 }
88 if ( sume2!=0 ) return sum*sum/sume2;
89 return 0;
90}
91
92
93double getWeights(TH2D* h) {
94
95 double sum = 0;
96 double sume2 = 0;
97
98 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
99 for ( int j=1 ; j<=h->GetNbinsY() ; j++ ) {
100 sum += h->GetBinContent(i,j);
101 sume2 += h->GetBinError(i,j)*h->GetBinError(i,j);
102 }
103 }
104
105 if ( sume2!=0 ) return sum*sum/sume2;
106
107 return 0;
108}
109
110
111
112
113const std::string Resplot::s_rversion = "resplot-v29";
114
115int GetStats( TH1D* h, std::vector<double>& stats ) {
116
117 int errorstate = 0;
118
119 stats.assign(4,0);
120
121 TAxis& fXaxis = *h->GetXaxis();
122
125
126 Int_t firstBinX = fXaxis.GetFirst();
127 Int_t lastBinX = fXaxis.GetLast();
128
129 int del = lastBinX - firstBinX;
130
131 if ( del<1 ) return errorstate = 1;
132
133 double s = 0;
134 double sx = 0;
135
136 double sr2 = 0;
137 double sr4 = 0;
138
139 // if ( fXaxis.TestBit(TAxis::kAxisRange) ) {
140 // for (bin=0;bin<4;bin++) stats[bin] = 0;
141
142 // include underflow/overflow if TH1::StatOverflows(kTRUE) in case no range is set on the axis
143 // if (fgStatOverflows && !fXaxis.TestBit(TAxis::kAxisRange)) {
144 // if (firstBinX == 1) firstBinX = 0;
145 // if (lastBinX == fXaxis.GetNbins() ) lastBinX += 1;
146 // }
147
148 for (int binx = firstBinX; binx <= lastBinX; binx++) {
149 double x = fXaxis.GetBinCenter(binx);
150 double w = TMath::Abs(h->GetBinContent(binx));
151 s += w;
152 sx += w*x;
153 }
154
155 if (s<=0){
156 std::cerr << "\tUnphysical denominator zero or less in GetStats()\n";
157 return errorstate = 2;
158 }
159
160 double mu = sx/s;
161
162 for (int binx = firstBinX; binx <= lastBinX; binx++) {
163 double x = fXaxis.GetBinCenter(binx);
164 double w = TMath::Abs(h->GetBinContent(binx));
165 double r = (x-mu);
166 sr2 += w*r*r;
167 sr4 += w*r*r*r*r;
168 }
169
170
171 double v = sr2/s;
172
173 double rms = 0;
174 double rmserror = 0;
175
177
178 if ( v<=0 ) return errorstate = 3;
179
180 double rms0 = std::sqrt(v);
181
182 rms = rms0;
183 double r2 = 0.25*(sr4/v-sr2);
184
185 if ( r2>0 ) rmserror = std::sqrt(r2)/s;
186 else errorstate = 4;
187
188 // prepare return values ...
189
190 stats[0] = mu;
191 stats[1] = std::sqrt(v/s);
192
193 stats[2] = rms;
194 stats[3] = rmserror;
195
196#if 0
197 std::cout << "GetStats() "
198 // << "\tmean " << stats[0] << " +- " << stats[1]
199 << "\trms " << stats[2] << " +- " << stats[3] << "\t(" << rmserror1 << ")" << "\t root " << duff << std::endl;
200#endif
201
202 return errorstate;
203}
204
205
206// #include "simpletimer.h"
207
209
210 // struct timeval st = simpletimer_start();
211
213 delskip( m_h2d );
214 delskip( m_h1d );
215 delskip( m_mean );
216 delskip( m_sigma );
217 delskip( m_chi2 );
218
219 for ( unsigned i=0 ; i<m_slices.size() ; i++ ) delskip(m_slices[i]);
220
221 // TH2D::SetDirectory(0);
222}
223
224
225
226void Resplot::Initialise(const std::string& name,
227 int n1, double a1, double b1,
228 int n2, double a2, double b2) {
229
230 SetPrimary(n1, a1, b1);
231 SetSecondary(n2, a2, b2);
232
233 m_Set = true;
234 // TH2D::SetDirectory(0);
235
236 m_name = name;
237 const std::string name_2d = "2d";
238 const std::string name_1d = "1d";
239
240 // std::cout << "Resplot::Initialise() Name " << Name() << std::endl;
241
242 m_h2d = new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, b1, n2, a2, b2);
243 m_h1d = new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
244 m_h1d->Sumw2();
245 skip(m_h2d);
246 skip(m_h1d);
247
248 const std::string name_mean = "mean";
249 const std::string name_sigma = "sigma";
250 const std::string name_chi2 = "chi2";
251 // const std::string name_entries = "significance";
252 const std::string name_entries = "fractional uncertainty";
253
254 m_Nentries = new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1, b1 );
256
257 m_mean = new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1, b1 );
258 m_sigma = new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1, b1 );
259 m_chi2 = new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1, b1 );
260 skip(m_mean);
261 skip(m_sigma);
262 skip(m_chi2);
263
264}
265
266
267
268void Resplot::Initialise(const std::string& name,
269 const std::vector<double>& a,
270 int n2, double a2, double b2) {
271 Initialise(name, a.size()-1, &a[0], n2, a2, b2);
272}
273
274
275void Resplot::Initialise(const std::string& name,
276 const std::vector<double>& a,
277 const std::vector<double>& b ) {
278 Initialise(name, a.size()-1, &a[0], b.size()-1, &b[0] );
279}
280
281
282
283void Resplot::Initialise(const std::string& name,
284 int n1, const double* a1,
285 int n2, double a2, double b2) {
286 SetPrimary(n1, a1);
287 SetSecondary(n2, a2, b2);
288
289 m_Set = true;
290
291 m_name = name;
292 const std::string name_2d = "2d";
293 const std::string name_1d = "1d";
294
295 // std::cout << "Resplot::Initialise() Name " << Name() << std::endl;
296
297 // TH2D::SetDirectory(0);
298
299 m_h2d = new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2, b2);
300 m_h1d = new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2, b2);
301 m_h1d->Sumw2();
302 skip(m_h2d);
303 skip(m_h1d);
304
305 const std::string name_mean = "mean";
306 const std::string name_sigma = "sigma";
307 const std::string name_chi2 = "chi2";
308
309 m_mean = new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
310 m_sigma = new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
311 m_chi2 = new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
312
313 skip(m_mean);
314 skip(m_sigma);
315 skip(m_chi2);
316
317 // const std::string name_entries = "significance";
318 const std::string name_entries = "fractional uncertainty";
319
320 m_Nentries = new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
322
323}
324
325
326
327
328void Resplot::Initialise(const std::string& name,
329 int n1, const double* a1,
330 int n2, const double* a2) {
331 SetPrimary(n1, a1);
332 SetSecondary(n2, a2[0], a2[n2+1]);
333
334 m_Set = true;
335
336 m_name = name;
337 const std::string name_2d = "2d";
338 const std::string name_1d = "1d";
339
340 // std::cout << "Resplot::Initialise() Name " << Name() << std::endl;
341
342 // TH2D::SetDirectory(0);
343
344 m_h2d = new TH2D( name_2d.c_str(), name_2d.c_str(), n1, a1, n2, a2 );
345 m_h1d = new TH1D( name_1d.c_str(), name_1d.c_str(), n2, a2 );
346 m_h1d->Sumw2();
347 skip(m_h2d);
348 skip(m_h1d);
349
350 const std::string name_mean = "mean";
351 const std::string name_sigma = "sigma";
352 const std::string name_chi2 = "chi2";
353
354 m_mean = new TH1D( name_mean.c_str(), name_mean.c_str(), n1, a1 );
355 m_sigma = new TH1D( name_sigma.c_str(), name_sigma.c_str(), n1, a1 );
356 m_chi2 = new TH1D( name_chi2.c_str(), name_chi2.c_str(), n1, a1);
357
358 skip(m_mean);
359 skip(m_sigma);
360 skip(m_chi2);
361
362 // const std::string name_entries = "significance";
363 const std::string name_entries = "fractional uncertainty";
364
365 m_Nentries = new TH1D( name_entries.c_str(), name_entries.c_str(), n1, a1 );
367
368}
369
370
371// #if 0
372
375
376Int_t Resplot::DWrite(TDirectory* g) const {
377
378 // std::cout << "Resplot::Write() Name " << Name() << "; " << gDirectory->GetName();
379
380 TDirectory* cwd = gDirectory;
381 if ( g ) g->cd();
382 Directory d(Name());
383 d.push();
384
385 // std::cout << "/" << gDirectory->GetName() << std::endl;
386
387 // TH2D::Write();
388 m_h2d->Write();
389 m_h1d->Write();
390 m_mean->Write();
391 m_sigma->Write();
392 m_chi2->Write();
393 m_Nentries->Write();
394 // std::cout << "Resplot::Write() Name() " << Name() << " " << m_slices.size() << std::endl;
395 gDirectory->mkdir("slices")->cd();
396 for ( unsigned i=0 ; i<m_slices.size() ; i++ ) m_slices[i]->Write();
397 d.pop();
398 cwd->cd();
399
400 return 0;
401}
402
403
404// #endif
405
406
407
408// Fill the helper histograms
409
410std::string number(const double& x) {
411 std::ostringstream s;
412 s << x;
413 return s.str();
414}
415
416
417double NCounter(TH1D* h) {
418 double N=0;
419 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) N += h->GetBinContent(i);
420 return N;
421}
422
423
424// Get the offsets and resolutions overall and for each slice
425int Resplot::Finalise(double a, double b, TF1* (*func)(TH1D* s, double a, double b)) {
426
427 // gDirectory->pwd();
428 // std::cout << "Resplot::Finalise() Name " << Name() << "\tm_n_primary " << m_n_primary << std::endl;
429
430 // gStyle->SetOptFit(1111);
431 // gStyle->SetOptStat(2211);
432
433 if ( m_finalised ) {
434 std::cerr << "Resplot::Finalise() " << m_name << " already called" << std::endl;
435 return -1;
436 }
437
438 // std::cout << "Resplot::Finalise() " << m_name << std::endl;
439
440 clear();
441
442 m_mean->SetStats(false);
443 m_sigma->SetStats(false);
444
445#if 1
446
447 std::vector<double> ylimits = getLimits( m_h2d->GetYaxis() );
448
449 for ( int i=1 ; i<=m_n_primary ; i++ ) {
450
451 if ( i%1000==0 ) std::cout << "slice " << i << " of " << m_n_primary << std::endl;
452
453 // std::string projname = tagname(m_name,i).c_str();
454 double pllim = m_mean->GetBinLowEdge(i);
455 double pulim = m_mean->GetBinLowEdge(i+1);
456
457 // std::cout << "Finalise " << i << " : " << pllim << " - " << pulim << std::endl;
458
459 std::string projname;
460 if ( m_xaxis=="" ) projname = "[ " + number(pllim) + " - " + number(pulim) + " ]";
461 else projname = "[ " + number(pllim) + " < " + m_xaxis + " < " + number(pulim) + " ]";
462
463 TH1D* s;
464 if ( !m_finalised ) {
465 // s = m_h2d->ProjectionY(tagname("slice",i), i, i, "e");
466
467 s = projectionY( m_h2d, i, ylimits, tagname("slice", i) );
468
469 // std::cout << i << " fitnull " << getWeights( s ) << std::endl;
470
471 if ( !m_uniform ) binwidth(s);
472 s->SetTitle(projname.c_str());
473 if ( m_yaxis!="" ) s->SetXTitle(m_yaxis.c_str());
474 }
475 else s = (TH1D*)gDirectory->Get(tagname(m_name,i));
476 skip(s);
477
478 // ZeroErrors(s);
479
480 TF1* f1 = 0;
481
482
483 if ( !s_nofit ) f1 = func(s, a, b);
484
485 // std::cout << "nofit " << s_nofit << "\tf1 " << f1 << std::endl;
486
487
488 // unZeroErrors(s);
489
490
491 if ( f1!=0 ) {
492
493 f1->SetLineWidth(1);
494 f1->SetNpx(5000);
495 m_fitname = f1->GetName();
496
497 // double N = NCounter(s);
498 double N = s->GetEffectiveEntries();
499
500 if ( N!=0 ) {
501 m_Nentries->SetBinContent(i,1/sqrt(N));
502 m_Nentries->SetBinError(i,0);
503 }
504 else {
505 m_Nentries->SetBinContent(i,0);
506 m_Nentries->SetBinError(i,0);
507 }
508
509 m_mean->SetBinContent(i, f1->GetParameter(1) );
510 m_mean->SetBinError(i, f1->GetParError(1) );
511
512 m_sigma->SetBinContent(i, std::fabs(f1->GetParameter(2)) );
513 m_sigma->SetBinError(i, f1->GetParError(2) );
514
515 int Ndof = f1->GetNDF();
516 if ( Ndof ) m_chi2->SetBinContent( i, std::fabs(f1->GetChisquare())/Ndof );
517 m_chi2->SetBinError(i, 0 );
518 delete f1;
519 }
520 else {
521 m_Nentries->SetBinContent(i,0);
522 m_mean->SetBinContent(i,0);
523 m_mean->SetBinError(i,0);
524 m_sigma->SetBinContent(i,0);
525 m_sigma->SetBinError(i,0);
526 m_chi2->SetBinContent(i,0);
527 m_chi2->SetBinError(i,0);
528 }
529
530 // std::cout << "Resplot::Finalise() slice " << s->GetName() << std::endl;
531
532 m_slices.push_back(s);
533 }
534
535
536#endif
537
538
539 m_chi2->SetMinimum(1e-5);
540
541 // get the overall resolution and offset
542
543 if ( !m_uniform ) binwidth(m_h1d);
544
545 TF1* f2 = 0;
546
547 if ( !s_nofit ) {
549 f2 = func(m_h1d, a, b);
551 }
552
553 if ( f2!=0 ) {
554
555 // std::cout << " fit = " << f2 << std::endl;
556 f2->SetLineWidth(1);
557 f2->SetNpx(5000);
558
559 m_g_mean = StatVal( f2->GetParameter(1), f2->GetParError(1) );
560 m_g_sigma = StatVal( f2->GetParameter(2), f2->GetParError(2) );
561
562 // std::cout << gDirectory->GetName() << "\tgmean " << m_g_mean << "\tgsigma " << g_sigma << std::endl;
563
564 std::string mname = std::string(f2->GetParName(1));
565 std::string sname = std::string(f2->GetParName(2));
566
567 // if ( mname!=std::string("") ) { m_mean->SetName(mname.c_str()); m_mean->SetTitle(mname.c_str()); }
568 // if ( sname!=std::string("") ) { m_sigma->SetName(sname.c_str()); m_sigma->SetTitle(sname.c_str()); }
569 if ( mname!=std::string("") ) { m_mean->SetTitle(mname.c_str()); }
570 if ( sname!=std::string("") ) { m_sigma->SetTitle(sname.c_str()); }
571
572 delete f2;
573 }
574 else {
575 if ( !s_nofit ) std::cerr << "\tnull overall fit Resplot:" << m_name << std::endl;
576 m_g_mean = StatVal(0,0);
577 m_g_sigma = StatVal(0,0);
578 }
579
580
581 // if ( AddDirectoryStatus() ) SetDirectory(gDirectory);
582
583 m_finalised = true;
584
585
586#if 0
587 if ( s_ErrorSet!=OK ) {
588 if ( s_ErrorSet == HISTOWIDTH ) {
589 std::cerr << __FUNCTION__ << " for " << m_name
590 << " :\tdistribution wider than histogram width " << std::endl;
591 }
592 if ( s_ErrorSet == BINWIDTH ) {
593 std::cerr << __FUNCTION__ << " for " << m_name
594 << " :\tbins too wide: cannot calculate rms95 " << std::endl;
595 }
596 }
597#endif
598
599 return 0;
600}
601
602
604TH2D* Resplot::rotate(const TH2* h, const std::string& s) {
605
606 std::vector<double> xbins = getLimits( h->GetXaxis() );
607 std::vector<double> ybins = getLimits( h->GetYaxis() );
608
609 // std::cout << "rotate:" << std::endl;
610 // std::cout << "x: " << xbins[0] << " - " << xbins.back() << std::endl;
611 // std::cout << "y: " << ybins[0] << " - " << ybins.back() << std::endl;
612
613 std::string name = s;
614 if ( s.empty() ) name = "duff";
615
616 TH2D* h2 = new TH2D( name.c_str(),"", ybins.size()-1, &ybins[0], xbins.size()-1, &xbins[0] );
617 h2->SetDirectory(0);
618
619 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
620 for ( int j=1 ; j<=h->GetNbinsY() ; j++ ) {
621 h2->SetBinContent(j,i, h->GetBinContent(i,j));
622 h2->SetBinError(j,i, h->GetBinError(i,j));
623 }
624 }
625
626 h2->SetEntries( h->GetEntries() );
627
628 return h2;
629}
630
631
633TH2D* Resplot::copy(const TH2* h, const std::string& s) {
634
635 std::vector<double> xbins = getLimits( h->GetXaxis() );
636 std::vector<double> ybins = getLimits( h->GetYaxis() );
637
638 // std::cout << "copy:" << std::endl;
639 // std::cout << "x: " << xbins[0] << " - " << xbins.back() << std::endl;
640 // std::cout << "y: " << ybins[0] << " - " << ybins.back() << std::endl;
641
642 std::string name = s;
643 if ( s.empty() ) name = "duff";
644
645 TH2D* h2 = new TH2D( name.c_str(), "", xbins.size()-1, &xbins[0], ybins.size()-1, &ybins[0] );
646 h2->SetDirectory(0);
647
648 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
649 for ( int j=1 ; j<=h->GetNbinsY() ; j++ ) {
650 h2->SetBinContent(i,j, h->GetBinContent(i,j));
651 h2->SetBinError(i,j, h->GetBinError(i,j));
652 }
653 }
654
655 h2->SetEntries( h->GetEntries() );
656
657 return h2;
658}
659
660
661
662std::vector<double> Resplot::findbins(const TH1* h, double inveps2) {
663
664 // std::cout << "findbins" << std::endl;
665
666 // if ( epsilon==0 ) return 0;
667
668 std::vector<double> xbins;
669
670 // hy->SetDirectory(0);
671 // hx->SetDirectory(0);
672
673 // double inveps2 = 1/(epsilon*epsilon);
674
675 double N = 0;
676
677 bool newbin = true;
678
679 // std::cout << "combining bins " << std::endl;
680
681 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
682
683 N += h->GetBinContent(i);
684
685 if ( xbins.size()==0 ) {
686 if ( N==0 ) continue;
687 else xbins.push_back( h->GetBinLowEdge(i) );
688 }
689
690 if ( newbin ) xbins.push_back( h->GetBinLowEdge(i+1) );
691 else xbins.back() = h->GetBinLowEdge(i+1);
692
693 newbin = false;
694
695 //if ( xbins.size()>0 ) std::cout << i << "\tN " << N << " " << " (" << inveps2 << ")" << "\t" << xbins.back() << std::endl;
696
697 if ( N >= inveps2 ) {
698 newbin = true;
699 N = 0;
700 }
701 }
702
703 // std::cout << "finishsed " << xbins.size() << std::endl;
704
705 // std::cout << "combine" << std::endl;
706 // std::cout << "x bins " << h->GetNbinsX() << std::endl;
707
708 //std::cout << "x: " << xbins.size() << " " << xbins[0] << " - " << xbins.back() << std::endl;
709
710 return xbins;
711}
712
713
714TH1D* Resplot::rebin( const TH1* h, const std::vector<double>& xbins ) {
715
716 if ( xbins.size()==0 ) {
717 std::cerr << "Resplot::combine() bad limits for histogram: N xbins: " << xbins.size() << std::endl;
718 return 0;
719 }
720
721 TH1D* h2 = new TH1D("duff","duff", xbins.size()-1, &xbins[0] );
722 h2->SetDirectory(0);
723
724 unsigned xbin = 0;
725 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
726
727 while ( h->GetBinCenter(i)>xbins[xbin+1] && xbin<(xbins.size()-1) ) xbin++;
728
729 if ( h->GetBinCenter(i)>=xbins[xbin] && h->GetBinCenter(i)<xbins[xbin+1] ) {
730 double n = h->GetBinContent(i);
731 double nh = h2->GetBinContent(xbin+1);
732 h2->SetBinContent(xbin+1, nh+n);
733 }
734 }
735
736 return h2;
737}
738
739
740
741
742
743
744std::vector<double> Resplot::getbins(const TH1* h) {
745 std::vector<double> bins(h->GetNbinsX()+1);
746 for ( int i=0 ; i<h->GetNbinsX()+1 ; i++ ) bins[i] = h->GetBinLowEdge(i+1);
747 return bins;
748}
749
750
751
752
753// Get the efficiency for a single slice of the major ordinate
754
755StatVal Resplot::GetEfficiency(TH1D* h, double lower, double upper) {
756 double total = 0;
757 double good = 0;
758 StatVal v;
759
760 for (int i=0 ; i<=h->GetNbinsX()+1 ; i++ ) {
761 total += h->GetBinContent(i);
762 }
763 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
764 double x = h->GetBinCenter(i);
765 if ( x>lower && x<= upper ) {
766 good += h->GetBinContent(i);
767 }
768 }
769 if ( total>0 ) {
770 v.value = good/total;
771 v.error = sqrt(v.value*(1-v.value)/total);
772 }
773
774 return v;
775}
776
777
778
779// Get all efficiencies for all the major bins
780
781TH1D* Resplot::GetEfficiencies(const std::string& hname, double lower, double upper) {
782 // TDirectory* cwd = cd();
783
784 // push();
785
786 TH1D* e = (TH1D*) m_mean->Clone();
787 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
788 if ( m_xaxis!="" ) e->SetXTitle(m_xaxis.c_str());
789
790 std::vector<double> ylimits = getLimits( m_h2d->GetYaxis() );
791
792 for ( int i=1 ; i<=m_n_primary ; i++ ) {
793 // TH1D* s = m_h2d->ProjectionY(tagname(hname,i), i, i, "e");
794 TH1D* s = projectionY( m_h2d, i, ylimits, tagname(hname, i) );
795 StatVal v = GetEfficiency(s, lower, upper);
796 e->SetBinContent(i, v.value);
797 e->SetBinError(i, v.error);
798 delete s;
799 }
800
801 // cwd->cd();
802
803 // pop();
804
805 return e;
806}
807
808
809
810
811
812// Get all efficiencies for all the major bins
813
814TH1D* Resplot::GetEfficiencies(const std::string& hname, double Nsigma ) {
815 // TDirectory* cwd = cd();
816 // push();
817
818 // check that the fits have been done for this
819 // plot
820 if ( !m_finalised ) Finalise();
821
822 TH1D* e = (TH1D*) m_mean->Clone();
823 e->SetName(hname.c_str()); e->SetMarkerStyle(20);
824 if ( m_xaxis!="" ) e->SetXTitle(m_xaxis.c_str());
825
826 std::vector<double> ylimits = getLimits( m_h2d->GetYaxis() );
827
828 for ( int i=1 ; i<=m_n_primary ; i++ ) {
829
830 double mean = m_mean->GetBinContent(i);
831 double sigma = m_sigma->GetBinContent(i);
832
833 // TH1D* s = m_h2d->ProjectionY(tagname(hname,i), i, i, "e");
834 TH1D* s = projectionY( m_h2d, i, ylimits, tagname(hname, i) );
835 StatVal v = GetEfficiency(s, mean-Nsigma*sigma, mean+Nsigma*sigma);
836 e->SetBinContent(i, v.value);
837 e->SetBinError(i, v.error);
838 delete s;
839 }
840
841 // cwd->cd();
842
843 // pop();
844
845 return e;
846}
847
848
849
850// fit Gaussian to histogram
851
852TF1* FitGaussian(TH1D* s, double a, double b) {
853 TF1* f1 = new TF1("gausr", "gaus");
854 return FitInternal( s, a, b, f1 );
855 // s->GetXaxis()->SetRangeUser(-1, 1);
856}
857
858TF1* FitRGaussian(TH1D* s, double a, double b) {
859 TF1* f1 = new TF1("rgausr", "[0]*x*exp((x-[1])([1]-x)/(2*[2]*[2]))");
860 return FitInternal( s, a, b, f1 );
861}
862
863TF1* FitRBreit(TH1D* s, double a, double b) {
864 TF1* f1 = new TF1("rbreitr", "x*[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
865
866 f1->SetParName(0, "Maximum");
867 f1->SetParName(1, "Median");
868 f1->SetParName(2, "Gamma");
869
870 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
871 f1->SetParameter(1,s->GetMean());
872 f1->SetParameter(2,s->GetRMS());
873
874 return FitInternal( s, a, b, f1 );
875}
876
877
878TF1* FitInternal(TH1D* s, double a, double b, TF1* f1) {
879
880 if ( f1==0 ) return f1;
881
882 f1->SetNpx(5000);
883 f1->SetLineWidth(1);
884
885 double mean = 0;
886 double sigma = 0;
887
888
889 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
890 f1->SetParameter(1,mean=s->GetBinCenter(s->GetMaximumBin()));
891 f1->SetParameter(2,sigma=s->GetRMS());
892
893 int nbins=0;
894 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
895
896 if (nbins>2) {
897 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
898 else s->Fit(f1,"Q", "", a, b);
899 }
900 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
901
902 return f1;
903}
904
905
906
907TF1* FitCentralGaussian(TH1D* s, double , double ) {
908 TF1* f1 = new TF1("gausr", "gaus");
909
910 f1->SetNpx(5000);
911 f1->SetLineWidth(1);
912
913 double mean = 0;
914 double sigma = 0;
915
916
917 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
918 f1->SetParameter(1,mean=s->GetBinCenter(s->GetMaximumBin()));
919 f1->SetParameter(2,sigma=s->GetRMS());
920
921 int nbins=0;
922 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
923
924 if (nbins>2) {
925
926 TH1D* s_tmp = (TH1D*)s->Clone("duff");
927 s_tmp->SetDirectory(0);
928 s_tmp->Fit(f1,"Q");
929
930
932
934
935 // double sig = std::sqrt( f1->GetParError(0)*f1->GetParError(0) + s->GetBinError(s->GetMaximumBin())*s->GetBinError(s->GetMaximumBin()) );
936 // double diff = std::fabs( (f1->GetParameter(0) - s->GetBinContent(s->GetMaximumBin()) ) )/sig;
937
938 // std::cout << "diff " << diff << "\tfit " << f1->GetParameter(0) << "\thist " << s->GetBinContent(s->GetMaximumBin()) << std::endl;
939
940 // if ( diff>2 ) {
941
942
943 // double n = s->GetBinContent(s->GetMaximumBin());
944
945 double frac = 1.25;
946
947 // if ( n<25 ) {
948 // frac = 1.2*n/25.0 + 4.0*(25.0-n)/25.0;
949 // }
950
951 double llim = f1->GetParameter(1)-frac*f1->GetParameter(2);
952 double ulim = f1->GetParameter(1)+frac*f1->GetParameter(2);
953
954
955
956 int nbins=0;
957 for (int j=1 ; j<=s->GetNbinsX() ; j++) if ( s->GetBinCenter(j)>llim && s->GetBinCenter(j)<ulim ) nbins++;
958
959 if ( nbins>2 ) {
960
961 // if ( frac>3 ) s->Fit(f1,"Q");
962 // else s->Fit(f1,"Q", "", llim, ulim);
963
964 if ( frac>3 ) s->Fit(f1,"Q");
965 else s->Fit(f1,"Q", "", llim, ulim);
966
967 }
968 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
969
970 delete s_tmp;
971
972
973
974 // std::cout << "Resplot::Finalise() " << s->GetName() << "\trange " << lower << " - " << upper << std::endl;
975
976 }
977 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
978
979 return f1;
980}
981
982
983
984// or fit a Breit Wigner
985
986TF1* FitBreit(TH1D* s, double a, double b) {
987
988 // TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))", -100, 100 );
989 TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))");
990
991 f1->SetParName(0, "Maximum");
992 f1->SetParName(1, "Median");
993 f1->SetParName(2, "Gamma");
994
995 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
996 f1->SetParameter(1,s->GetMean());
997 f1->SetParameter(2,s->GetRMS()*0.5);
998
999 f1->SetNpx(5000);
1000 f1->SetLineWidth(1);
1001
1002 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)==0) s->SetBinError(j, 1);
1003
1004
1005 int nbins=0;
1006 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1007
1008 if (nbins>2) {
1009 // std::cout << "fitting " << f1 << std::endl;
1010 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1011 else s->Fit(f1,"Q", "", a, b);
1012 }
1013 else {
1014 for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1015 }
1016
1017 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)==0) s->SetBinError(j, 0);
1018
1019 return f1;
1020}
1021
1022
1023
1024
1025TF1* FitATan(TH1D* s, double , double ) {
1026 // static int counter = 0;
1027
1028 std::cout << "FitATan() " << s->GetName() << " " << s->GetTitle() << std::endl;
1029
1030 char name[8];
1031 // sprintf(name,"atan_%02d", counter); counter++;
1032
1033 // Cannot use "M_PI" here as root does not replace M_PI in the string expressions for function in TF1 definition
1034 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);
1035
1036 f1->SetParName(0, "Mean");
1037 f1->SetParName(1, "Gradient");
1038 f1->SetParName(2, "Pedestal");
1039 f1->SetParName(3, "Norm");
1040 f1->SetParName(4, "Power");
1041
1042 int maxn=1;
1043 for ( int i=1 ; i<=s->GetNbinsX() ; i++ ) if ( s->GetBinContent(maxn)<s->GetBinContent(i) ) maxn = i;
1044
1045
1046 // f1->SetParameter(0,s->GetBinContent(maxn) );
1047 // f1->SetParameter(1,s->GetBinCenter(s->GetNbinsX()/2) );
1048 // f1->SetParameter(2,0.25);
1049
1050 f1->SetParameter(0, 2 );
1051 f1->SetParameter(1, 10 );
1052 f1->SetParameter(2, 0.001 );
1053 f1->SetParameter(3, 100 );
1054 f1->SetParameter(4, 1 );
1055
1056 f1->FixParameter(2, 0);
1057 f1->FixParameter(3, 100);
1058 // f1->FixParameter(4, 1);
1059
1060 f1->SetNpx(5000);
1061 f1->SetLineWidth(1);
1062
1063
1064 // int nbins=0;
1065
1066
1067 // ZeroErrors(s);
1068 s->SetMarkerStyle(20);
1069
1070
1071 // int n=0;
1072 // for ( int i=1 ; i<=s->GetNbinsX() ; i++ ) if ( s->GetBinContent() ) n++;
1073 // if ( n>2 ) s->Fit(f1,"Q");
1074
1075 s->Fit(f1,"Q");
1076
1077 std::cout << "par0 = " << f1->GetParameter(0) << std::endl;
1078 std::cout << "par1 = " << f1->GetParameter(1) << std::endl;
1079 std::cout << "par2 = " << f1->GetParameter(2) << std::endl;
1080 std::cout << "par3 = " << f1->GetParameter(3) << std::endl;
1081 std::cout << "par4 = " << f1->GetParameter(4) << std::endl;
1082
1083
1084 // unZeroErrors(s);
1085 // s->SetMaximum(f1->GetParameter(0)*1.1);
1086 // double range = s->GetBinLowEdge(s->GetNbinsX()+1) - s->GetBinLowEdge(1) ;
1087
1088 return f1;
1089}
1090
1091
1092
1093TF1* FitNull(TH1D* s, double , double ) {
1094
1095 // unZeroErrors(s);
1096
1097 TF1* f=new TF1("null", "[0]+[1]+[2]");
1098
1099 f->SetParName(0, "Maximum");
1100 f->SetParName(1, "Mean");
1101 f->SetParName(2, "RMS");
1102
1103 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1104 f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1105 f->FixParameter(2, s->GetRMS()); f->SetParError(2, s->GetRMSError());
1106
1107 // std::cout << gDirectory->GetName() << " " << s->GetName() << "\tFitNull mean: " << f->GetParameter(1) << "\tsigma: " << f->GetParameter(2) << std::endl;
1108
1109 return f;
1110}
1111
1112
1113
1114double FindMean(TH1D* s, double frac=0.95) {
1115
1116 // double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1117 double entries = generate::GetEntries(s,0,s->GetNbinsX()+1);
1118
1119 // std::cout << s->GetName() << "\tentries: " << entries << std::endl;
1120
1121 if ( entries==0 ) return 0;
1122
1123 // s->GetXaxis()->SetRangeUser(-100, 100);
1124 // s->GetXaxis()->UnZoom();
1125 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1126
1127 double mean = s->GetMean();
1128 double meane = s->GetMeanError();
1129
1130 int upperbin = 0;
1131 int lowerbin = 0;
1132
1133
1134 for ( int it=0 ; it<20 ; it++ ) {
1135
1136 // std::cout << it << "\tmean " << mean << " +- " << meane << std::endl;
1137
1138 int imax = s->GetXaxis()->FindBin(mean);
1139
1140 double sumn = s->GetBinContent(imax);
1141
1142 // double uppersum = 0;
1143 // double lowersum = 0;
1144
1145 upperbin = imax;
1146 lowerbin = imax;
1147
1148
1149 int i=1;
1150 while ( true ) {
1151
1152 const int upperbin_i = imax+i;
1153 const int lowerbin_i = imax-i;
1154
1155 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1156
1157 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1158
1159 if ( tsum>entries*frac ) {
1160 // uppersum = tsum/entries;
1161 break;
1162 }
1163
1164 // lowersum = tsum/entries;
1165
1166 sumn = tsum;
1167
1168 upperbin = upperbin_i;
1169 lowerbin = lowerbin_i;
1170
1171 i++;
1172 }
1173
1174 s->GetXaxis()->SetRange(lowerbin, upperbin);
1175
1176 double m = s->GetMean();
1177 double me = s->GetMeanError();
1178
1179 if ( it>0 ) {
1180 if ( mean==m ||
1181 std::fabs(mean-m)<me*1e-5 ||
1182 std::fabs(mean-m)<meane*1e-5 ) {
1183 mean = m;
1184 meane = me;
1185 break;
1186 }
1187 }
1188
1189 mean = m;
1190 meane = me;
1191
1192 }
1193
1194 // std::cout << "mean " << mean << " +- " << meane << "\tentries: " << generate::GetEntries(s) << "\tlower " << lowerbin << " - " << upperbin << std::endl;
1195
1196
1197 return mean;
1198}
1199
1200
1201int findmax(TH1D* s) {
1202 int imax = 1;
1203 for ( int i=2 ; i<=s->GetNbinsX() ; i++ ) {
1205 if ( s->GetBinContent(i)>s->GetBinContent(imax) ) imax = i;
1206 }
1207 return imax;
1208}
1209
1210
1211
1212// TF1* FitNull95Obsolete(TH1D* s, double frac, bool useroot ) {
1213TF1* FitNull95Obsolete(TH1D* s, double frac, bool useroot ) {
1214
1215 TF1* f=new TF1("null", "[0]+[1]+[2]");
1216
1217 f->SetParName(0, "Maximum");
1218 f->SetParName(1, "Mean");
1219 f->SetParName(2, "RMS");
1220
1221 f->SetParameter(0, 0);
1222 f->SetParameter(1, 0);
1223 f->SetParameter(2, 0);
1224
1225 if ( s==0 ) { std::cerr << "FitNull95() histogram s = " << s << std::endl; return 0; }
1226 if ( s->GetXaxis()==0) { std::cerr << "FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl; return 0; }
1227
1228 unZeroErrors(s);
1229
1230 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1231
1232#if 0
1233 std::cout << "FitNull95 " << s->GetName()
1234 << " " << generate::GetEntries(s)
1235 << " " << generate::GetEntries(s, 0, s->GetNbinsX()+1)
1236 << std::endl;
1237#endif
1238
1239
1240 if ( generate::GetEntries(s)<10 ) return f;
1241
1242 // std::cout << "---------------------------------------\nFN95O frac: " << frac << " " << s << std::endl;
1243
1244 // std::cout << __LINE__ << std::endl;
1245
1246
1247
1248 // std::cout << __LINE__ << " " << s->GetXaxis() << std::endl;
1249
1252 // s->GetXaxis()->UnZoom();
1253
1254 // std::cout << __LINE__ << std::endl;
1255
1256 // double m = s->GetMean();
1257 double m = FindMean(s,frac);
1258
1259 // std::cout << __LINE__ << std::endl;
1260
1261 int imax = s->GetXaxis()->FindBin(m);
1262
1263 // std::cout << "mean " << m << " " << imax << " max " << s->GetBinCenter(findmax(s)) << " " << findmax(s) << std::endl;
1264
1265 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, std::sqrt(s->GetMaximum()));
1266 // f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1267
1268 // double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1269 double entries = generate::GetEntries(s,0,(s->GetNbinsX()+1));
1270
1271 // std::cout << "entries: " << entries << "\t" << generate::GetEntries(s) << "\t" << generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1272
1273 // double sumx = s->GetBinContent(imax)*s->GetBinCenter(imax);
1274 // double sumx2 = s->GetBinContent(imax)*s->GetBinCenter(imax)*s->GetBinCenter(imax);
1275
1276 double sumn = s->GetBinContent(imax);
1277
1278 int upperbin = imax;
1279 int lowerbin = imax;
1280
1281 double uppersum = 0;
1282 double lowersum = 0;
1283
1284 if ( sumn>entries*frac ) {
1285 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1286 // ErrorSet = BINWIDTH;
1287 return f;
1288 }
1289
1290 if ( entries>0 ) {
1291
1292 int i=1;
1293 while ( true ) {
1294
1295 const int upperbin_i = imax+i;
1296 const int lowerbin_i = imax-i;
1297
1298 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1299
1300 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1301
1302 // std::cout << i << " frac: " << lowersum
1303 // << "\tx " << s->GetBinCenter(lowerbin)
1304 // << "\t " << s->GetBinCenter(upperbin)
1305 // << "\ttsum " << tsum
1306 // << "\tentries " << entries
1307 // << std::endl;
1308
1309 if ( tsum>entries*frac ) { uppersum = tsum/entries; break; }
1310
1311 lowersum = tsum/entries;
1312
1313 sumn = tsum;
1314
1315 upperbin = upperbin_i;
1316 lowerbin = lowerbin_i;
1317
1318 // if ( std::fabs(lowersum-frac)<0.1 )
1319
1320 i++;
1321 }
1322 }
1323
1324 if ( uppersum==0 ) {
1325 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1326 // ErrorSet = HISTOWIDTH;
1327 return f;
1328 }
1329
1330 // std::cout << "FitNull95 " << s->GetName() << "\tlower bin " << lowerbin << "\t upper bin " << upperbin << std::endl;
1331
1332 // std::cout << "full rms " << s->GetRMS() << " +- " << s->GetRMSError() << "\t n=" << s->GetNbinsX()
1333 // << "\tfrac " << ( entries>0 ? sumn/entries : 0 ) << " - " << uppersum
1334 // << std::endl;
1335
1336 // std::cout << "upper " << upperbin << " " << lowerbin << " " << interpolate_flag << std::endl;
1337
1338 // if ( true ) { // technically wrong - 95% contained in only 3 bins, so RMS of the "central" bin is not defined
1339 if ( upperbin!=lowerbin ) {
1340
1341 double llim = s->GetBinLowEdge(1);
1342 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1343
1344 double rms = 0;
1345 double erms = 0;
1346
1347 std::vector<double> stats;
1348
1349 // double sentries = generate::GetEntries(s);
1350
1351 // std::cout << "GetEntries " << s->GetName() << " " << sentries << std::endl;
1352
1353 if ( s_interpolate_flag ) {
1354 s->GetXaxis()->SetRange(lowerbin, upperbin);
1355
1356 // std::cout << "GetEntries " << s->GetName() << " " << generate::GetEntries(s,lowerbin,upperbin)/sentries << std::endl;
1357
1358 double rlower;
1359 double erlower;
1360
1361 double rupper;
1362 double erupper;
1363
1364 int errorflag = 0;
1365
1367 //certain values (rlower, erlower, rupper, erupper) are overwritten before they are used
1368 //due to the commented 'else'; add notation to indicate this is intentional.
1369 if ( !useroot ) {
1370 errorflag = GetStats( s, stats );
1371 rlower = stats[2];
1372 erlower = stats[3];
1373 // std::cout << "mu: " << stats[0] << " " << s->GetMean() << "\trlower: " << rlower << "\t+- " << erlower << "\troot: " << s->GetRMS() << " +- " << s->GetRMSError() << "\t(errorflags: " << errorflag << ")" << std::endl;
1374 }
1375 else {
1376 rlower = s->GetRMS();
1377 erlower = s->GetRMSError();
1378 }
1379
1380 if ( errorflag==0 ) {
1381 // std::cout << "FitNULL95() " << s->GetName() << "\tmean " << m << "\t lower rms " << rlower << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1382 // std::cout << s->GetName() << " " << s->GetTitle() << "\t lower 95% rms " << rlower << " +- " << erlower << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1383
1384 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1385
1386 // std::cout << "GetEntries " << s->GetName() << " " << generate::GetEntries(s,lowerbin-1,upperbin+1)/sentries << std::endl;
1387 // std::cout << "Range " << s->GetBinLowEdge(lowerbin) << " - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1388
1389 if ( !useroot ) {
1390 errorflag = GetStats( s, stats );
1391 rupper = stats[2];
1392 erupper = stats[3];
1393 // std::cout << "mu: " << stats[0] << " " << s->GetMean() << "\trlower: " << rupper << "\t+- " << erupper << "\troot: " << s->GetRMS() << " +- " << s->GetRMSError() << "\t(errorflag: " << errorflag << ") II" << std::endl;
1394 }
1395 else {
1396 rupper = s->GetRMS();
1397 erupper = s->GetRMSError();
1398 }
1399
1400 // std::cout << "FitNULL95() " << s->GetName() << "\t upper rms " << rupper << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1401 // std::cout << s->GetName() << " " << s->GetTitle() << "\t upper 95% rms " << rupper << " +- " << erupper << "\t( " << lowerbin-1 << " - " << upperbin+1 << " )" << std::endl;
1402
1403 rms = rlower + (frac-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1404 erms = erlower + (frac-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1405 }
1406 }
1407 else {
1408 s->GetXaxis()->SetRange(lowerbin, upperbin);
1409 if ( !useroot ) {
1410 GetStats( s, stats );
1411 rms = stats[2];
1412 erms = stats[3];
1413 }
1414 else {
1415 rms = s->GetRMS();
1416 erms = s->GetRMSError();
1417 }
1418 }
1419
1420#if 0
1421
1422 std::cout << "numbers " << s->GetName()
1423 << " " << generate::GetEntries(s,lowerbin,upperbin)
1424 << " - " << generate::GetEntries(s,lowerbin-1,upperbin+1) << "\ttotal " << generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1425
1426 std::cout << "fractions " << s->GetName()
1427 << "\t" << generate::GetEntries(s,lowerbin,upperbin)/generate::GetEntries(s,0,s->GetNbinsX()+1)
1428 << " - " << generate::GetEntries(s,lowerbin-1,upperbin+1)/generate::GetEntries(s,0,s->GetNbinsX()+1) << std::endl;
1429
1430 std::cout << "lowersum " << s->GetName() << "\t" << lowersum << "\tuppersum " << uppersum << std::endl;
1431
1432 std::cout << "limits " << s->GetName() << "\t" << s->GetBinLowEdge(lowerbin) << " - " << s->GetBinLowEdge(upperbin+1) << std::endl;
1433
1434 std::cout << "FitNULL95Obsolete() " << s->GetName() << "\t rms " << rms << " +- " << erms << "\t inv " << 1/rms << std::endl;
1435
1436 printf("rms %12.10lf inv %12.10lf\n", rms, 1/rms );
1437
1438 printf("rms68 %12.10lf inv %12.10lf\n", rms/0.5369760683, rms*1.8622803865 );
1439#endif
1440
1441
1444 double scale = 1;
1445 if ( s_scalerms95 ) scale = 1.1479538518;
1446
1447 // f->FixParameter(2, s->GetRMS());
1448 // f->SetParError(2, s->GetRMSError());
1449 f->FixParameter(2, scale*rms);
1450 f->SetParError(2, scale*erms);
1451 f->FixParameter(1, s->GetMean());
1452 f->SetParError(1, s->GetMeanError());
1453 s->GetXaxis()->SetRangeUser(llim, ulim);
1454
1455 }
1456 else {
1457 f->FixParameter(1, 0);
1458 f->SetParError(1, 0);
1459 f->FixParameter(2, 0);
1460 f->SetParError(2, 0);
1461 }
1462
1463 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1464
1465 return f;
1466}
1467
1468
1469
1470
1471
1472TF1* FitNull95(TH1D* s, double , double ) {
1473 if ( s_oldrms95 ) return FitNull95Obsolete( s, 0.95 );
1474 else return FitNull95New(s);
1475}
1476
1477
1478
1479
1480TF1* FitNull95New(TH1D* s, double, bool ) { // double frac, bool useroot ) {
1481
1482 // std::cout << "---------------------------------------\nFN95 " << std::endl;
1483
1484 TF1* f=new TF1("null", "[0]+[1]+[2]");
1485
1486 f->SetParName(0, "Maximum");
1487 f->SetParName(1, "Mean");
1488 f->SetParName(2, "RMS");
1489
1490 f->SetParameter(0, 0);
1491 f->SetParameter(1, 0);
1492 f->SetParameter(2, 0);
1493
1494 if ( s->GetEffectiveEntries()==0 ) return f;
1495
1496
1497 // double _entries = getWeights( s );
1498 const double entries = s->GetEffectiveEntries();
1499
1500 int nexperiments_ = 0;
1501 int nexperiments_max = 40;
1502 int nexperiments_min = 20;
1503
1504
1505 // int nexperiments = 20+int(800/std::sqrt(s->GetEntries()));
1506 // int nexperiments = 20+int(800/std::sqrt(s->GetEntries()));
1507 int nexperiments = 20+int(1000/entries);
1508
1509
1510
1511 if ( nexperiments_!=0 ) nexperiments = nexperiments_;
1512
1513
1514 if ( nexperiments>nexperiments_max ) nexperiments = nexperiments_max;
1515 if ( nexperiments<nexperiments_min ) nexperiments = nexperiments_min;
1516
1517 // std::cout << "FitNull95 entries " << entries << "\tnexperiments " << nexperiments << std::endl;
1518
1519 // std::cout << "experiments " << nexperiments_ << std::endl;
1520
1521 // std::cout << "h entries " << s->GetEntries() << "\tn experiments " << nexperiments << "\tN " << s->GetEntries()*nexperiments << std::endl;
1522
1524 generate::experiment e( s, nexperiments, entries );
1525
1528 double scale = 1;
1529 if ( s_scalerms95 ) scale = 1.1479538518;
1530
1531 // f->FixParameter( 1, s->GetMean() );
1532 f->FixParameter( 1, e.hmean() );
1533 f->SetParError( 1, e.mean_error() );
1534
1535 f->FixParameter( 2, scale*e.hrms() );
1536 f->SetParError( 2, scale*e.rms_error() );
1537
1538 // s->GetXaxis()->SetRange(1, s->GetNbinsX());
1539
1540 // s->GetXaxis()->SetRangeUser(-1, 1);
1541
1542 return f;
1543}
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553TF1* FitNull95Central(TH1D* s) {
1554
1555 TF1* f=new TF1("null", "[0]+[1]+[2]");
1556
1557 f->SetParName(0, "Maximum");
1558 f->SetParName(1, "Mean");
1559 f->SetParName(2, "RMS");
1560
1561 f->SetParameter(0, 0);
1562 f->SetParameter(1, 0);
1563 f->SetParameter(2, 0);
1564
1565 if ( s==0 ) { std::cerr << "FitNull95() histogram s = " << s << std::endl; return 0; }
1566 if ( s->GetXaxis()==0) { std::cerr << "FitNull95() histogram s->GetXaxis() not definied for histogram " << s->GetName() << std::endl; return 0; }
1567
1568 // std::cout << "FitNull " << s->GetName() << " " << generate::GetEntries(s) << std::endl;
1569
1570 if ( generate::GetEntries(s)<20 ) return f;
1571 // if ( s->GetEffectiveEntries<20 ) return f;
1572
1573 s->GetXaxis()->SetRange(1,s->GetNbinsX());
1574 // s->GetXaxis()->UnZoom();
1575
1576
1579
1582
1583 int imax = findmax(s);
1584
1585 f->FixParameter(0, s->GetMaximum()); f->SetParError(0, sqrt(s->GetMaximum()));
1586 // f->FixParameter(1, s->GetMean()); f->SetParError(1, s->GetMeanError());
1587
1588
1589 double entries = s->GetEntries() + s->GetBinContent(0) + s->GetBinContent(s->GetNbinsX()+1);
1590
1591 // double sumx = s->GetBinContent(imax)*s->GetBinCenter(imax);
1592 // double sumx2 = s->GetBinContent(imax)*s->GetBinCenter(imax)*s->GetBinCenter(imax);
1593 double sumn = s->GetBinContent(imax);
1594
1595 double frac = 0.95;
1596
1597 int upperbin = imax;
1598 int lowerbin = imax;
1599
1600 double uppersum = 0;
1601 double lowersum = 0;
1602
1603 if ( entries>0 ) {
1604
1605 int i=1;
1606 while ( true ) {
1607
1608 const int upperbin_i = imax+i;
1609 const int lowerbin_i = imax-i;
1610
1611 if ( upperbin_i>s->GetNbinsX() || lowerbin_i<1 ) break;
1612
1613 double tsum = sumn + s->GetBinContent(upperbin_i) + s->GetBinContent(lowerbin_i);
1614
1615 if ( tsum>entries*frac ) { uppersum = tsum/entries; break; }
1616
1617 lowersum = tsum/entries;
1618
1619 sumn = tsum;
1620
1621 upperbin = upperbin_i;
1622 lowerbin = lowerbin_i;
1623
1624 i++;
1625 }
1626 }
1627
1628 // std::cout << "FitNull95 " << s->GetName() << " " << upperbin << " " << lowerbin << std::endl;
1629
1630 // std::cout << "full rms " << s->GetRMS() << " +- " << s->GetRMSError() << "\t n=" << s->GetNbinsX()
1631 // << "\tfrac " << ( entries>0 ? sumn/entries : 0 ) << " - " << uppersum
1632 // << std::endl;
1633
1634 // std::cout << "upper " << upperbin << " " << lowerbin << " " << interpolate_flag << std::endl;
1635
1636 if ( upperbin!=lowerbin ) {
1637
1638 double llim = s->GetBinLowEdge(1);
1639 double ulim = s->GetBinLowEdge(s->GetNbinsX()+1);
1640
1641 double rms = 0;
1642 double erms = 0;
1643
1644 std::vector<double> stats;
1645
1646 if ( s_interpolate_flag ) {
1647 s->GetXaxis()->SetRange(lowerbin, upperbin);
1648
1649
1650 double rlower;
1651 double erlower;
1652
1653 double rupper;
1654 double erupper;
1655
1656
1658
1659 GetStats( s, stats );
1660 rlower = stats[2];
1661 erlower = stats[3];
1662
1663 // std::cout << "FitNULL95() " << s->GetName() << "\t lower rms " << rlower << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1664 // std::cout << s->GetName() << " " << s->GetTitle() << "\t lower 95% rms " << rlower << " +- " << erlower << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1665
1666 s->GetXaxis()->SetRange(lowerbin-1, upperbin+1);
1667
1668 GetStats( s, stats );
1669 rupper = stats[2];
1670 erupper = stats[3];
1671
1672 // std::cout << "FitNULL95() " << s->GetName() << "\t upper rms " << rupper << " +- " << s->GetRMSError() << " (wrong)\t " << stats[2] << " +- " << stats[3] << " (correct)" << std::endl;
1673
1674 // std::cout << s->GetName() << " " << s->GetTitle() << "\t upper 95% rms " << rupper << " +- " << erupper << "\t( " << lowerbin-1 << " - " << upperbin+1 << " )" << std::endl;
1675
1676 rms = rlower + (0.95-lowersum)*(rupper-rlower)/(uppersum-lowersum);
1677 erms = erlower + (0.95-lowersum)*(erupper-erlower)/(uppersum-lowersum);
1678
1679 }
1680 else {
1681 s->GetXaxis()->SetRange(lowerbin, upperbin);
1682 GetStats( s, stats );
1683
1684 rms = stats[2];
1685 erms = stats[3];
1686
1687 }
1688
1689
1690 // f->FixParameter(2, s->GetRMS());
1691 // f->SetParError(2, s->GetRMSError());
1692 f->FixParameter(2, rms);
1693 f->SetParError(2, erms);
1694 f->FixParameter(1, s->GetMean());
1695 f->SetParError(1, s->GetMeanError());
1696 // std::cout << s->GetName() << " " << s->GetTitle() << "\t 95% inter rms " << rms << " +- " << erms << std::endl;
1697 s->GetXaxis()->SetRangeUser(llim, ulim);
1698 }
1699 else {
1700 f->FixParameter(1, 0);
1701 f->SetParError(1, 0);
1702 f->FixParameter(2, 0);
1703 f->SetParError(2, 0);
1704 // std::cout << " 95% rms " << 0 << " +- " << 0 << "\t( " << lowerbin << " - " << upperbin << " )" << std::endl;
1705 }
1706
1707 s->GetXaxis()->SetRange(1, s->GetNbinsX());
1708
1709 return f;
1710}
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724// or fit a Poissonian
1725
1726TF1* FitPoisson(TH1D* s, double a, double b) {
1727
1728 char fstring[1024];
1729 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)");
1730 TF1 *f1 = new TF1("poisson", fstring );
1731 // TF1* f1 = new TF1("poiss","[0]*TMath::Poisson(x*[2],[1])");
1732
1733 f1->SetParName(0, "Maximum");
1734 f1->SetParName(1, "Mean");
1735 f1->SetParName(2, "Scale");
1736 f1->SetParName(3, "Offset");
1737
1738 f1->SetNpx(5000);
1739 f1->SetLineWidth(1);
1740 f1->SetLineColor(s->GetLineColor());
1741
1742 int nbins=0;
1743 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1744
1745 f1->SetParameter(0,s->GetBinContent(s->GetMaximumBin()) );
1746 f1->SetParameter(1,s->GetBinCenter(s->GetMaximumBin()));
1747 f1->SetParameter(2,1);
1748 f1->FixParameter(3,0);
1749
1750 if (nbins>2) {
1751 // std::cout << "fitting " << f1 << std::endl;
1752 // if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1753 // else s->Fit(f1,"Q", "", a, b);
1754 if ( a==-999 || b==-999 ) s->Fit(f1);
1755 else s->Fit(f1,"", "", a, b);
1756 }
1757 else {
1758 for ( int j=0 ; j<4 ; j++ ) f1->SetParameter(j,0);
1759 }
1760
1761 return f1;
1762}
1763
1764
1765
1766TF1* FitXExp(TH1D* s, double a, double b) {
1767
1768 // TF1* f1 = new TF1("breitr", "[0]*[2]*[2]/([2]*[2]+(x-[1])*(x-[1]))", -100, 100 );
1769 // TF1* f1 = new TF1("xexpr", "[0]*(pow([2]*x,[1])*exp(-[2]*x))+[3]");
1770 // TF1* f1 = new TF1("xexpr", "[0]*(pow((1.0/[2])*(x-[3]),[1])*exp(-(1.0/[2])*(x-[3])))");
1771 TF1* f1 = new TF1("xexpr", "[0]*(pow((1.0/[2])*x,[1])*exp(-(1.0/[2])*x))+[3]");
1772
1773 f1->SetParName(0, "Normalisation");
1774 f1->SetParName(1, "Power");
1775 f1->SetParName(2, "Lifetime");
1776 f1->SetParName(3, "offset");
1777
1778 // f1->SetParameter(0, 1e-156);
1779 f1->SetParameter(0, s->GetBinContent(s->GetMaximumBin()) );
1780 // f1->SetParameter(1, -1*(s->GetBinCenter(s->GetMaximumBin())) );
1781 f1->SetParameter(2, s->GetRMS() );
1782 // f1->SetParameter(1, 0);
1783 f1->SetParameter(1, 0);
1784 f1->SetParameter(3, 0);
1785
1786 // f1->FixParameter(0, 1);
1787 // f1->FixParameter(1, 25);
1788 // f1->FixParameter(1, 0);
1789 // f1->FixParameter(3, 0);
1790
1791 f1->SetNpx(5000);
1792 f1->SetLineWidth(1);
1793
1794 int nbins=0;
1795 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)>0) nbins++;
1796
1797 // std::cout << "starting exp fit p1=" << f1->GetParameter(1) << std::endl;
1798
1799 if (nbins>2) {
1800 // std::cout << "fitting " << f1 << std::endl;
1801 if ( a==-999 || b==-999 ) s->Fit(f1, "Q");
1802 else s->Fit(f1, "Q", "", a, b);
1803 }
1804 else {
1805 for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j,0);
1806 }
1807
1808 // std::cout << "done" << std::endl;
1809
1810 return f1;
1811}
1812
1813
1814
1815
1816
1817
1818Double_t langaufun(Double_t *x_par, Double_t *par) {
1819
1820 //Fit parameters:
1821 //par[0]=Total area (integral -inf to inf, normalization constant)
1822 //par[1]=Most Probable (MP, location) parameter of Landau density
1823 //par[2]=Width (scale) parameter of Landau density
1824 //par[3]=Width (sigma) of convoluted Gaussian function
1825 //
1826 //In the Landau distribution (represented by the CERNLIB approximation),
1827 //the maximum is located at x=-0.22278298 with the location parameter=0.
1828 //This shift is corrected within this function, so that the actual
1829 //maximum is identical to the MP parameter.
1830
1831 // Numeric constants
1832 Double_t invsq2pi = 0.3989422804014; // (2 pi)^(-1/2)
1833 Double_t mpshift = -0.22278298; // Landau maximum location
1834
1835 // Control constants
1836 Double_t np = 500; // number of convolution steps
1837 Double_t sc = 5; // convolution extends to +-sc Gaussian sigmas
1838
1839 double& x = x_par[0];
1840
1841 // Variables
1842 Double_t xx;
1843 Double_t mpc;
1844 Double_t fland;
1845 Double_t sum = 0.0;
1846 Double_t xlow,xupp;
1847 Double_t step;
1848 Double_t i;
1849
1850 // if ( par[2]<0.1*par[3] ) return 0;
1851
1852 // correct the most probable bin position as described above
1853 mpc = par[1] - mpshift*par[2];
1854
1855 // Range of convolution integral
1856
1857 // if ( par[3]<par[2] ) np = np*par[2]/par[3];
1858
1859 xlow = x - sc * par[3];
1860 xupp = x + sc * par[3];
1861
1862 step = (xupp-xlow) / np;
1863
1864 // Convolution integral of Landau and Gaussian by sum
1865 for(i=1.0; i<=np/2; i++) {
1866 xx = xlow + (i-0.5)*step;
1867 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
1868 sum += fland * TMath::Gaus(x,xx,par[3]);
1869
1870 xx = xupp - (i-0.5)*step;
1871 fland = TMath::Landau(xx,mpc,par[2]) / par[2];
1872 sum += fland * TMath::Gaus(x,xx,par[3]);
1873 }
1874
1875 return (par[0] * step * sum * invsq2pi / par[3]);
1876}
1877
1878
1879
1880// fit Gaussian to histogram
1881
1882TF1* FitLandauGauss(TH1D* s, double a, double b) {
1883 // TF1* f1 = new TF1("landgaus", "landgaus");
1884 // root is STUPID and you have to specify the FIT RANGE if you
1885 // want to specify the number of fit parameters!!!
1886 TF1* f1 = new TF1("landgaus", langaufun, 0, 1, 4);
1887
1888 f1->SetNpx(5000);
1889 f1->SetLineWidth(1);
1890
1891 // parameter starting values
1892 double start_vals[4]; // = { 0.1, 3.0, 1.0, 0.3 };
1893
1894 start_vals[0] = s->GetEntries();
1895 start_vals[1] = s->GetBinCenter(s->GetMaximumBin());
1896 start_vals[2] = s->GetRMS();
1897 start_vals[3] = 0.5*start_vals[2];
1898
1899 f1->SetParNames("Area", "MP", "Width", "GSigma");
1900 f1->SetParameters(start_vals);
1901
1902 // parameter low and high values for the fit
1903 // double par_lo[4] = { 0.0, -20.0, 0.0, 0.00 };
1904 // double par_hi[4] = { 20000.0, 50000.0, 50.0, 0.01 };
1905 // for ( int i=0 ; i<4 ; i++ ) f1->SetParLimits(i, par_lo[i], par_hi[i]);
1906 f1->SetParLimits( 2, 0.1*start_vals[2], 10*start_vals[2] );
1907 f1->SetParLimits( 3, 0.0, 10*start_vals[2] );
1908
1909 int nbins=0;
1910 for (int j=1 ; j<=s->GetNbinsX() ; j++) if (s->GetBinContent(j)) nbins++;
1911
1912 if (nbins>2) {
1913 if ( a==-999 || b==-999 ) s->Fit(f1,"Q");
1914 else s->Fit(f1,"Q", "", a, b);
1915 // if ( a==-999 || b==-999 ) s->Fit(f1);
1916 // else s->Fit(f1,"", "", a, b);
1917 }
1918 else for ( int j=0 ; j<3 ; j++ ) f1->SetParameter(j, 0);
1919
1920 return f1;
1921}
1922
1923} // namespace Resplot
1924
int upper(int c)
static Double_t a
static Double_t sc
static const std::vector< std::string > bins
void clear()
Empty the pool.
int imax(int i, int j)
#define x
Header file for AthHistogramAlgorithm.
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:376
static TH2D * rotate(const TH2 *h, const std::string &s="")
flip the x and y axes
Definition Resplot.cxx:604
StatVal GetEfficiency(TH1D *h, double lower, double upper)
Definition Resplot.cxx:755
TH1D * GetEfficiencies(const std::string &hname, double lower, double upper)
Definition Resplot.cxx:781
static std::vector< double > findbins(const TH1 *h, double epsilon)
Definition Resplot.cxx:662
static TH2D * copy(const TH2 *h, const std::string &s="")
copy a TH2
Definition Resplot.cxx:633
std::string m_xaxis
Definition Resplot.h:689
static const std::string s_rversion
Definition Resplot.h:665
void delskip(TH1D *t)
Definition Resplot.h:616
TH1D * m_Nentries
Definition Resplot.h:671
static TH1D * rebin(const TH1 *h, const std::vector< double > &bins)
Definition Resplot.cxx:714
void SetSecondary(int n, double a, double b)
Definition Resplot.h:626
std::string m_fitname
Definition Resplot.h:693
StatVal m_g_sigma
Definition Resplot.h:680
static std::vector< double > getbins(const TH1 *h)
Definition Resplot.cxx:744
std::string m_name
Definition Resplot.h:669
static TH1D * projectionY(TH2 *h2d, int col, const std::vector< double > &ylimits, const std::string &tagname)
actual local projections ...
Definition Resplot.h:410
static std::vector< double > getLimits(const TAxis *axis)
projection utilities ... NB: In athena, for some reason the destuctors for histograms created using T...
Definition Resplot.h:398
std::string m_yaxis
Definition Resplot.h:690
const std::string & Name(const std::string &s)
Definition Resplot.h:346
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:496
virtual ~Resplot()
Definition Resplot.cxx:208
const std::string & name() const
Definition Resplot.h:349
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=FitGaussian)
Definition Resplot.cxx:425
void SetPrimary(int n, const double *)
Definition Resplot.h:624
StatVal m_g_mean
Definition Resplot.h:679
std::vector< TH1D * > m_slices
Definition Resplot.h:692
void Initialise(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
Definition Resplot.cxx:226
simple struct to hold a value and it's associated uncertainty.
Definition StatVal.h:27
given a histogram, get a generator for the distribution in that histogram, then run some pseudo-exper...
Definition generate.h:134
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="")
int r
Definition globals.cxx:22
std::string cwd
Definition listroot.cxx:38
double entries
Definition listroot.cxx:49
bool binwidth
Definition listroot.cxx:58
double GetEntries(TH1D *h, int ilow, int ihi)
Definition rmsFrac.cxx:20
bool s_nofit
Definition Resplot.cxx:43
TF1 * FitRGaussian(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:858
TF1 * FitCentralGaussian(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:907
int GetStats(TH1D *h, std::vector< double > &stats)
Definition Resplot.cxx:115
TF1 * FitInternal(TH1D *s, double a=-999, double b=-999, TF1 *f1=0)
Definition Resplot.cxx:878
TF1 * FitNull95New(TH1D *s, double frac=0.95, bool useroot=false)
Definition Resplot.cxx:1480
void unZeroErrors(TH1D *h)
Definition Resplot.cxx:75
TF1 * FitGaussian(TH1D *s, double a=-999, double b=-999)
forward declation because we use this in the class ...
Definition Resplot.cxx:852
TF1 * FitRBreit(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:863
bool s_oldrms95
use the new error estimates
Definition Resplot.cxx:46
TF1 * FitNull95Central(TH1D *s)
Definition Resplot.cxx:1553
double NCounter(TH1D *h)
Definition Resplot.cxx:417
TF1 * FitLandauGauss(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:1882
TF1 * FitXExp(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:1766
void ZeroErrors(TH1D *h)
Definition Resplot.cxx:69
TF1 * FitNull(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:1093
bool s_interpolate_flag
Definition Resplot.cxx:42
int findmax(TH1D *s)
Definition Resplot.cxx:1201
double getWeights(TH1D *h)
Definition Resplot.cxx:81
Double_t langaufun(Double_t *x_par, Double_t *par)
Definition Resplot.cxx:1818
std::string number(const double &x)
Definition Resplot.cxx:410
TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
Definition Resplot.cxx:1213
double FindMean(TH1D *s, double frac=0.95)
Definition Resplot.cxx:1114
TF1 * FitNull95(TH1D *s, double a=0, double b=0)
Definition Resplot.cxx:1472
bool s_scalerms95
Definition Resplot.cxx:47
TF1 * FitPoisson(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:1726
bool s_mAddDirectoryStatus
Definition Resplot.cxx:40
TF1 * FitATan(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:1025
TF1 * FitBreit(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:986