ATLAS Offline Software
Loading...
Searching...
No Matches
Resplot.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
21
22#ifndef RESPLOT_RESPLOT_H
23#define RESPLOT_RESPLOT_H
24
25#include <stdlib.h>
26
27#include <iostream>
28#include <string>
29#include <vector>
30
31#include "TROOT.h"
32#include "TH1D.h"
33#include "TH2D.h"
34#include "TF1.h"
35#include "TFile.h"
36#include "TString.h"
37
38#include "Resplot/StatVal.h"
39
40namespace Resplot {
41
42
44TF1* FitGaussian(TH1D* s, double a=-999, double b=-999);
45
46extern bool s_mAddDirectoryStatus;
47// bool s_interpolate_flag;
48
49
50class Resplot { // : public TObject {
51
52private:
53
54 class ResException {
55 public:
56 ResException(const std::string& s) { std::cerr<<s<<std::endl; }
57 };
58
60
61public:
62
63 // NB, the destructor MUST NOT delete all the histograms, since root will
64 // when closing the file, and it will crash if we let the destructor
65 // try to clean up properly afterwards - LIKE WE SHOULD BE ABLE TO!
66 // NB: NB!! Actually, now we explicitly *remove* them from root managerment
67 // so we can do *proper* garbage collection, not like the
68 // alleged garbage collection in root
69
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),
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 { }
82
83
84 Resplot(const std::string& name,
85 int n1, double a1, double b1,
86 int n2, double a2, double b2, const std::string& xaxis="") :
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); }
96
97
98 Resplot(const std::string& name,
99 int n1, const double* a1,
100 int n2, double a2, double b2, const std::string& xaxis="") :
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); }
110
111 Resplot(const std::string& name,
112 const std::vector<double>& a,
113 int n2, double a2, double b2, const std::string& xaxis="") :
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); }
122
123
124 Resplot(const std::string& name,
125 const std::vector<double>& a,
126 const std::vector<double>& b,
127 const std::string& xaxis="") :
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); }
136
137
138 // Resplot(const Resplot& r, const std::string& tag="") = delete;
139
140 // Resplot(const Resplot& r ) = delete;
141
142 Resplot& operator=(const Resplot&) = delete;
143
144 //#if 0
145 Resplot(const Resplot& r, const std::string& tag="") :
146 // TH2D( (TH2D)r ),
147 // TObject(r),
148 m_Set(r.m_Set), m_name(r.m_name+tag),
149 m_Nentries(new TH1D(*r.m_Nentries)),
150 m_mean(new TH1D(*r.m_mean)), m_sigma(new TH1D(*r.m_sigma)), m_chi2(new TH1D(*r.m_chi2)),
151 m_h2d(new TH2D(*r.m_h2d)), m_h1d(new TH1D(*r.m_h1d)),
152 m_dir(NULL),
153 m_n_primary(r.m_n_primary), // a_primary(r.a_primary), b_primary(r.b_primary),
156 m_uniform(true)
157 {
158 // TH2D::SetDirectory(0);
159 skip(m_h2d);
160 skip(m_h1d);
161 skip(m_mean);
162 skip(m_sigma);
163 skip(m_chi2);
165 }
166 //#endif
167
168 Resplot(const std::string& name, TH2* hin, const bool flip=false) :
169 m_Set(false), m_name(name),
170 m_Nentries(NULL),
171 m_mean(NULL), m_sigma(NULL), m_chi2(NULL),
172 m_h2d(NULL), m_h1d(NULL),
173 m_dir(NULL),
174 m_xaxis(""), m_yaxis(""), m_fitname(""), m_finalised(false),
175 m_uniform(true)
176 {
177
178 TH2D* h = 0;
179
180 if ( flip ) h = rotate( hin );
181 else h = static_cast<TH2D*>(hin);
182
183 // get the major bin edges
184 std::vector<double> xlimits = getLimits( h->GetXaxis() );;
185 std::vector<double> ylimits = getLimits( h->GetYaxis() );
186
187 int n2 = ylimits.size()-1;;
188 double a2 = ylimits[0];;
189 double b2 = ylimits.back();
190
191 Initialise(name, xlimits, n2, a2, b2 );
192
193 // replace default histograms
194 delete m_h2d;
195 m_h2d = copy(h, "2d");
196 skip(m_h2d);
197
198 delete m_h1d;
199 // m_h1d = h->ProjectionY("1d", 1, h->GetNbinsX(), "e");
200 m_h1d = projectionY( h, 1, h->GetNbinsX(), ylimits, "1d" );
201 m_h1d->SetTitle("1d");
202
203 skip(m_h1d);
204 }
205
206
207 // hmmmm, this constructor doesn't work for some
208 // reason. Can't work out why, must be due to root directory
209 // object ownership, I shouldn't wonder
210 Resplot(const std::string& name) :
211 m_Set(false),
212 m_name(name),
213 m_dir(NULL),
214 m_n_secondary(0),
215 m_a_secondary(0.0),
216 m_b_secondary(0.0),
217 m_xaxis(""), m_yaxis(""), m_fitname(""), m_finalised(true),
218 m_uniform(true)
219 // m_Nentries ( new TH1D(*(TH1D*)gDirectory->Get((name+"/fractional uncertainty").c_str())) ),
220 // m_mean ( new TH1D(*(TH1D*)gDirectory->Get((name+"/1d").c_str())) ),
221 // m_sigma ( new TH1D(*(TH1D*)gDirectory->Get((name+"/sigma").c_str())) ),
222 // m_chi2 ( new TH1D(*(TH1D*)gDirectory->Get((name+"/chi2").c_str())) ),
223 // m_h2d ( new TH2D(*(TH2D*)gDirectory->Get((name+"/2d").c_str())) ),
224 // m_h1d ( new TH1D(*(TH1D*)gDirectory->Get((name+"/1d").c_str())) )
225 {
226
227 m_Nentries = new TH1D(*(TH1D*)gDirectory->Get((name+"/fractional uncertainty").c_str()));
228 m_mean = new TH1D(*(TH1D*)gDirectory->Get((name+"/mean").c_str()));
229 m_sigma = new TH1D(*(TH1D*)gDirectory->Get((name+"/sigma").c_str()));
230 m_chi2 = new TH1D(*(TH1D*)gDirectory->Get((name+"/chi2").c_str()));
231 m_h2d = new TH2D(*(TH2D*)gDirectory->Get((name+"/2d").c_str()));
232 m_h1d = new TH1D(*(TH1D*)gDirectory->Get((name+"/1d").c_str()));
233
234 skip(m_h2d);
235 skip(m_h1d);
236 skip(m_mean);
237 skip(m_sigma);
238 skip(m_chi2);
240
241 m_n_primary = m_h2d->GetNbinsX();
242
243 // std::cout << "Resplot(std::string)" << name << "\t m_n_primary " << m_n_primary << std::endl;
244
245 // deep copy
246 for ( int i=1 ; i<=m_h2d->GetNbinsX() ; i++ ) {
247 char slicename[512];
248 sprintf(slicename, "/slices/slice[%03d]", i);
249 // std::cout << i << " " << (name+slicename) << std::endl;
250 m_slices.push_back((TH1D*)gDirectory->Get((name+slicename).c_str()));
251 skip(m_slices.back()); //->SetDirectory(0);
252 }
253
254 }
255
256 // Resplot( const Resplot& r ) = delete;
257
258 // Resplot& operator=( const Resplot& r) = delete;
259
260 virtual ~Resplot();
261
262
263 void Initialise(const std::string& name,
264 int n1, double a1, double b1,
265 int n2, double a2, double b2);
266
267 void Initialise(const std::string& name,
268 int n1, const double* a1,
269 int n2, double a2, double b2);
270
271 void Initialise(const std::string& name,
272 int n1, const double* a1,
273 int n2, const double* a2);
274
275 void Initialise(const std::string& name,
276 const std::vector<double>& a,
277 int n2, double a2, double b2);
278
279 void Initialise(const std::string& name,
280 const std::vector<double>& a,
281 const std::vector<double>& b );
282
283
284 // Fill the helper histograms
285 int Fill(double x, double y, double w=1) {
286 // m_h2d->Fill(x, y, w);
287 // TH2D::Fill(x, y, w);
288 m_h2d->Fill(x, y, w);
289 m_h1d->Fill(y, w);
290 return 0;
291 }
292
293
294 // Get the efficiency for a single slice of the major ordinate
295 StatVal GetEfficiency(TH1D* h, double lower, double upper);
296
297
298 // Get the global efficiency
299 StatVal GetGlobalEfficiency(double lower, double upper) {
300 return GetEfficiency(m_h1d, lower, upper);
301 }
302
303
304 // Get all efficiencies for all the major bins
305 // within the range lower .. upper
306 TH1D* GetEfficiencies(const std::string& hname, double lower, double upper);
307
308 // Get all efficiencies for all the major bins
309 // within the range += Nsigma*sigma about the fitted
310 // mean, where the mean and sigma are taken from the fit,
311 // either gaussian of cauchy
312 TH1D* GetEfficiencies(const std::string& hname, double Nsigma);
313
314 // set the name of the x axis variable
315 void SetXAxis(const std::string& xaxis) {
316 m_xaxis = xaxis;
317 m_mean->SetXTitle(m_xaxis.c_str());
318 m_sigma->SetXTitle(m_xaxis.c_str());
319 m_chi2->SetXTitle(m_xaxis.c_str());
320 m_Nentries->SetXTitle(m_xaxis.c_str());
321 m_h2d->SetXTitle(m_xaxis.c_str());
322 m_h1d->SetXTitle(m_xaxis.c_str());
323 }
324
325 // and the y axis variable
326 void SetYAxis(const std::string& yaxis) {
327 m_yaxis = yaxis;
328 m_h2d->SetXTitle(m_yaxis.c_str());
329 m_h1d->SetXTitle(m_yaxis.c_str());
330 }
331
332 // get the limits of the slices in the x coordinate
333 std::vector<double> GetPrimaryLimits() const {
334 std::vector<double> d;
335 for ( int i=1 ; i<=m_mean->GetNbinsX()+1 ; i++ ) d.push_back(m_mean->GetBinLowEdge(i));
336 return d;
337 }
338
339 // get the central values for each slice in the x coordinate
340 std::vector<double> GetPrimaryCentres() const {
341 std::vector<double> d;
342 for ( int i=1 ; i<=m_mean->GetNbinsX() ; i++ ) d.push_back(m_mean->GetBinCenter(i));
343 return d;
344 }
345
346 const std::string& Name(const std::string& s) { return m_name=s; }
347
348 const std::string& Name() const { return m_name; }
349 const std::string& name() const { return m_name; }
350
351 // get the histogram of the mean of the distributions
352 TH1D* Mean() { return m_mean; }
353 const TH1D* Mean() const { return m_mean; }
354
355 // and the "width"
356 TH1D* Sigma() { return m_sigma; }
357
358 // and the chi2
359 TH1D* Chi2() { return m_chi2; }
360 const TH1D* Chi2() const { return m_chi2; }
361
362 // and the overall projection in y
363 TH1D* H1D() { return m_h1d; }
364 const TH1D* H1D() const { return m_h1d; }
365
366 // and the overall 2D histo
367 TH2D* H2D() { return m_h2d; }
368 const TH2D* H2D() const { return m_h2d; }
369
370 // return 1/sqrt(Nentries) approximate stat precision
371 TH1D* Uncertainty() { return m_Nentries; }
372 const TH1D* Uncertainty() const { return m_Nentries; }
373
374 bool finalised() const { return m_finalised; }
375
376 // and the fitted slices
377 const std::vector<TH1D*>& Slices() const { return m_slices; }
378
379 // and the name of the fitted function
380 // NB. this is useful for setting plot paramaters
381 // of the fit for plotting, such as the line colour etc
382 const std::string& FitName() const { return m_fitname; }
383
384 // Static fit functions!!!!
385 // NB. *Any* fit function can be used to fit the distributions
386 // as long as it has this form of method, it does not need
387 // to be a member of the class Resplot, but using static
388 // member functions here, gaurantees there are a few simple
389 // examples that will be safely encapsulated inside the
390 // class so there will be no interference with other functions
391
392
397
398 static std::vector<double> getLimits( const TAxis* axis ) {
399 std::vector<double> limits( axis->GetNbins()+1, 0 );
400 for ( size_t i=axis->GetNbins()+1 ; i-- ; ) limits[i] = axis->GetBinLowEdge(i+1);
401 return limits;
402 }
403
404 static std::vector<double> getxLimits( TH2* h ) { return getLimits( h->GetXaxis() ); }
405
406 static std::vector<double> getyLimits( TH2* h ) { return getLimits( h->GetYaxis() ); }
407
409
410 static TH1D* projectionY( TH2* h2d, int col, const std::vector<double>& ylimits, const std::string& tagname ) {
411 TH1D* h = new TH1D( tagname.c_str(), "", ylimits.size()-1, &ylimits[0] ); h->SetDirectory(0);
412 double entries = 0;
413 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
414 double v = h2d->GetBinContent(col, i);
415 h->SetBinContent( i, v );
416 entries += v;
417 }
418 h->SetEntries(entries);
419 return h;
420 }
421
422 static TH1D* projectionY( TH2* h2d, int col0, int col1, const std::vector<double>& ylimits, const std::string& tagname ) {
423 TH1D* h = new TH1D( tagname.c_str(), "", ylimits.size()-1, &ylimits[0] ); h->SetDirectory(0);
424 double entries = 0;
425 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
426 double sum = 0;
427 for ( int col=col0 ; col<=col1 ; col++ ) sum += h2d->GetBinContent(col, i);
428 h->SetBinContent( i, sum );
429 entries += sum;
430 }
431 h->SetEntries(entries);
432 return h;
433 }
434
435 static TH1D* projectionX( TH2* h2d, int row, const std::vector<double>& xlimits, const std::string& tagname ) {
436 TH1D* h = new TH1D( tagname.c_str(), "", xlimits.size()-1, &xlimits[0] ); h->SetDirectory(0);
437 double entries = 0;
438 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
439 double v = h2d->GetBinContent( i, row );
440 h->SetBinContent( i, v );
441 entries += v;
442 }
443 h->SetEntries(entries);
444 return h;
445 }
446
447 static TH1D* projectionX( TH2* h2d, int row0, int row1, const std::vector<double>& xlimits, const std::string& tagname ) {
448 TH1D* h = new TH1D( tagname.c_str(), "", xlimits.size()-1, &xlimits[0] ); h->SetDirectory(0);
449 double entries = 0;
450 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
451 double sum = 0;
452 for ( int row=row0 ; row<=row1 ; row++ ) sum += h2d->GetBinContent(i, row);
453 h->SetBinContent( i, sum );
454 entries += sum;
455 }
456 h->SetEntries(entries);
457 return h;
458 }
459
460 static double sum( TH1* h ) {
461 double sum = 0;
462 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) sum += h->GetBinContent(i);
463 //std::cout << "sum: " << sum << std::endl;
464 return sum;
465 }
466
467
468 // Get the offsets and resolutions overall and for each slice
469 // int Finalise(double a=-999, double b=-999, TF1* (*func)(TH1D* s, double a, double b)=Resplot::FitGaussian);
470
471 int Finalise(double a=-999, double b=-999, TF1* (*func)(TH1D* s, double a, double b)=FitGaussian);
472
473 int Finalise(TF1* (*func)(TH1D* s, double a, double b), double a=-999, double b=-999 ) {
474 return Finalise( a, b, func);
475 }
476
477 int Fit(TF1* (*func)(TH1D* s, double a, double b) ) {
478 if ( m_finalised ) return -1;
479 return Finalise( func );
480 }
481
482 int Refit(TF1* (*func)(TH1D* s, double a, double b) ) {
483 clear();
484 return Finalise( func );
485 }
486
487
488 TDirectory* Dir() { return m_dir; }
489
490#if 1
491
496 Int_t Write(const char* =0, Int_t =0, Int_t =0) const { return DWrite(); }
497 Int_t Write(const char* =0, Int_t =0, Int_t =0) { return DWrite(); }
498 Int_t DWrite(TDirectory* g=0) const;
499
501 static void AddDirectory(bool t=false) { s_mAddDirectoryStatus=t; }
502
503 void SetDirectory(TDirectory* =0) { }
504#endif
505
506 // static void setInterpolateFlag(bool b) { s_interpolate_flag = b; }
507
508
510
512
513 clear();
514
515 // std::cout << "Resplot::operator+= " << Name() << std::endl;
516
517 if ( r.H1D()->GetNbinsX()!=H1D()->GetNbinsX()) throw ResException("histogram limits do not match");
518 if ( r.H2D()->GetNbinsX()!=H2D()->GetNbinsX()) throw ResException("histogram limits do not match");
519 if ( r.H2D()->GetNbinsY()!=H2D()->GetNbinsY()) throw ResException("histogram limits do not match");
520
521 for ( int i=0 ; i<=r.H2D()->GetNbinsX()+1 ; i++ ) {
522 for ( int j=0 ; j<=r.H2D()->GetNbinsY()+1 ; j++ ) {
523 H2D()->SetBinContent( i, j, H2D()->GetBinContent(i,j) + r.H2D()->GetBinContent(i,j) );
524 H2D()->SetBinError( i, j, std::sqrt(H2D()->GetBinError(i,j)*H2D()->GetBinError(i,j) + r.H2D()->GetBinError(i,j)*r.H2D()->GetBinError(i,j) ) );
525 }
526 }
527
528 for ( int i=0 ; i<=r.H1D()->GetNbinsX()+1 ; i++ ) {
529 H1D()->SetBinContent( i, H1D()->GetBinContent(i) + r.H1D()->GetBinContent(i) );
530 H1D()->SetBinError( i, std::sqrt(H1D()->GetBinError(i)*H1D()->GetBinError(i) + r.H1D()->GetBinError(i)*r.H1D()->GetBinError(i) ) );
531 }
532
533 m_finalised = false;
534
535 // std::cout << "Resplot::operator+= done" << std::endl;
536
537 return *this;
538 }
539
540
541
542 Resplot& operator*=(double d) {
543
544 // std::cout << "Resplot::operator*= " << Name() << " " << m_finalised << " " << m_slices.size() << std::endl;
545
546 clear();
547
548 // std::cout << "Resplot::operator*= " << Name() << " " << m_finalised << " " << m_slices.size() << std::endl;
549 // std::cout << "Resplot::operator*= " << Name() << "\tH2D " << H2D() << std::endl;
550
551 // H2D()->DrawCopy();
552
553 // std::cout << "Resplot::operator*= " << Name() << "\tDraw " << std::endl;
554
555 for ( int i=0 ; i<=H2D()->GetNbinsX()+1 ; i++ ) {
556 for ( int j=0 ; j<=H2D()->GetNbinsY()+1 ; j++ ) {
557 H2D()->SetBinContent( i, j, H2D()->GetBinContent(i,j)*d);
558 H2D()->SetBinError( i, j, H2D()->GetBinError(i,j)*d);
559 }
560 }
561
562
563 // std::cout << "Resplot::operator*= " << Name() << "\tH1D " << H1D() << std::endl;
564
565 for ( int i=0 ; i<=H1D()->GetNbinsX()+1 ; i++ ) {
566 H1D()->SetBinContent( i, H1D()->GetBinContent(i)*d );
567 H1D()->SetBinError( i, H1D()->GetBinError(i)*d );
568 }
569
570 m_finalised = false;
571
572 // std::cout << "Resplot::operator*= done" << std::endl;
573
574 return *this;
575 }
576
577 Resplot operator*(double d) const {
578 Resplot r(*this);
579 return (r*=d);
580 }
581
582 Resplot operator+(const Resplot& r) const {
583 Resplot r0(*this);
584 return (r0+=r);
585 }
586
587
588 void Integrate() {
589 if ( !m_finalised ) return;
590
593 }
594
595 void setUniform(bool t=false) { m_uniform=t; }
596
597 static const std::string& version() { return s_rversion; }
598
600 static TH2D* rotate(const TH2* h, const std::string& s="" );
601 static TH2D* copy(const TH2* h, const std::string& s="" );
602
603 static std::vector<double> findbins(const TH1* h, double epsilon);
604 static TH1D* rebin(const TH1* h, const std::vector<double>& bins);
605
606 static std::vector<double> getbins(const TH1* h);
607
608private:
609
610 void MakeSlices() { }
611
612private:
613
614 // stop the root default histogram ownership nonsense
615 void skip(TH1D* t) { if ( t ) t->SetDirectory(0); }
616 void delskip(TH1D* t) { if ( t ) { t->SetDirectory(0); delete t; } }
617 void deletehist(TH1D* t) { if ( t ) delete t; }
618
619 void skip(TH2D* t) { if ( t ) t->SetDirectory(0); }
620 void delskip(TH2D* t) { if ( t ) { t->SetDirectory(0); delete t; } }
621 void deletehist(TH2D* t) { if ( t ) delete t; }
622
623
624 void SetPrimary(int n, const double* ) { m_n_primary=n; }
625 void SetPrimary(int n, double , double ) { m_n_primary=n; } // a_primary=a; b_primary=b; }
626 void SetSecondary(int n, double a, double b) { m_n_secondary=n; m_a_secondary=a; m_b_secondary=b; }
627
628
629 // stuff for calculating efficiencies
630
633
634
635 void AddEfficiency(TH1D* h, int i, double lower, double upper) {
636 StatVal v = GetGlobalEfficiency( lower, upper);
637 h->SetBinContent(i, v.value);
638 h->SetBinError(i, v.error);
639 }
640
641 void AddResolution(TH1D* h, int i) {
642 StatVal v = get_sigma();
643 h->SetBinContent(i, v.value);
644 h->SetBinError(i, v.error);
645 }
646
647 void AddMean(TH1D* h, int i) {
648 StatVal v = get_mean();
649 h->SetBinContent(i, v.value);
650 h->SetBinError(i, v.error);
651 }
652
653private:
654
655 void clear() {
656 // std::cout << "clear " << m_slices.size() << std::endl;
657 m_finalised = false;
658 for ( int i=m_slices.size() ; i-- ; ) if ( m_slices[i] ) delete m_slices[i];
659 m_slices.clear();
660 // std::cout << "cleared" << std::endl;
661 }
662
663private:
664
665 static const std::string s_rversion;
666
667 bool m_Set;
668
669 std::string m_name;
670
671 TH1D* m_Nentries = 0;
672 TH1D* m_mean = 0;
673 TH1D* m_sigma = 0;
674 TH1D* m_chi2 = 0;
675
676 TH2D* m_h2d = 0;
677 TH1D* m_h1d = 0;
678
681
682 TDirectory* m_dir = 0;
683
685
688
689 std::string m_xaxis;
690 std::string m_yaxis;
691
692 std::vector<TH1D*> m_slices;
693 std::string m_fitname;
694
696 // TDirectory* m_slicedir = 0;
697
699
702 // static const bool s_oldrms95;
703 // static const bool s_scalerms95;
704
705 // static const bool s_nofit;
706
707
708 // static const ERROR s_ErrorSet; //! don't persistify this
709
710 // ClassDef(Resplot, 1)
711
712};
713
714
715extern bool s_interpolate_flag;
716extern bool s_nofit;
717
719extern bool s_oldrms95;
720extern bool s_scalerms95;
721
722inline bool setoldrms95(bool b) { return s_oldrms95=b; }
723inline bool setscalerms95(bool b) { return s_scalerms95=b; }
724inline bool setnofit(bool b) { return s_nofit=b; }
725
726
727// fit Generic to histogram
728TF1* FitInternal(TH1D* s, double a=-999, double b=-999, TF1* f1=0);
729
730// fit Gaussian to histogram
731// TF1* FitGaussian(TH1D* s, double a=-999, double b=-999);
732
733// fit Gaussian with radial dependence to histogram
734TF1* FitRGaussian(TH1D* s, double a=-999, double b=-999);
735
736// or fit a Breit Wigner
737TF1* FitBreit(TH1D* s, double a=-999, double b=-999);
738
739// or fit a Breit Wigner with radial dependence
740TF1* FitRBreit(TH1D* s, double a=-999, double b=-999);
741
742// or fit an inverse tan turn on curve
743TF1* FitATan(TH1D* s, double a=-999, double b=-999);
744
745// use histo mean and rms
746TF1* FitNull(TH1D* s, double a=-999, double b=-999);
747
748// fit a poisson distribution
749TF1* FitPoisson(TH1D* s, double a=-999, double b=-999);
750
751// fit a ax^b exp(c*x)+d distribution
752TF1* FitXExp(TH1D* s, double a=-999, double b=-999);
753
754TF1* FitLandauGauss(TH1D* s, double a=-999, double b=-999);
755
756// fit Central Gaussian to histogram
757TF1* FitCentralGaussian(TH1D* s, double a=-999, double b=-999);
758
759// fit histo mean and rms only to central 95% of histogram
760TF1* FitNull95(TH1D* s, double a=0, double b=0);
761
762// static TF1* FitNull95(TH1D* s, double frac=0.95, bool useroot=false);
763TF1* FitNull95New(TH1D* s, double frac=0.95, bool useroot=false);
764TF1* FitNull95Obsolete(TH1D* s, double frac=0.95, bool useroot=false);
765
766TF1* FitNull95Central(TH1D* s);
767
768
769
770inline Resplot operator*(double d, Resplot r) { return (r*=d); }
771
772}
773
774#endif /* RESPLOT_RESPLOT_H */
775
int upper(int c)
static Double_t a
static const std::vector< std::string > bins
void clear()
Empty the pool.
void rotate(double angler, GeoTrf::Vector2D &vector)
#define y
#define x
Header file for AthHistogramAlgorithm.
ResException(const std::string &s)
Definition Resplot.h:56
static std::vector< double > getxLimits(TH2 *h)
Definition Resplot.h:404
TH1D * Sigma()
Definition Resplot.h:356
void deletehist(TH1D *t)
Definition Resplot.h:617
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
void SetDirectory(TDirectory *=0)
Definition Resplot.h:503
TDirectory * m_dir
Definition Resplot.h:682
const TH1D * Chi2() const
Definition Resplot.h:360
StatVal get_sigma()
Definition Resplot.h:632
const TH2D * H2D() const
Definition Resplot.h:368
TH1D * Mean()
Definition Resplot.h:352
void AddResolution(TH1D *h, int i)
Definition Resplot.h:641
static TH1D * projectionX(TH2 *h2d, int row0, int row1, const std::vector< double > &xlimits, const std::string &tagname)
Definition Resplot.h:447
Resplot(const Resplot &r, const std::string &tag="")
Definition Resplot.h:145
TH1D * Chi2()
Definition Resplot.h:359
std::vector< double > GetPrimaryLimits() const
Definition Resplot.h:333
Resplot & operator=(const Resplot &)=delete
StatVal GetEfficiency(TH1D *h, double lower, double upper)
Definition Resplot.cxx:755
void skip(TH2D *t)
Definition Resplot.h:619
int Fit(TF1 *(*func)(TH1D *s, double a, double b))
Definition Resplot.h:477
void MakeSlices()
Definition Resplot.h:610
double m_a_secondary
Definition Resplot.h:687
void setUniform(bool t=false)
Definition Resplot.h:595
static TH2D * copy(const TH2 *h, const std::string &s="")
copy a TH2
Definition Resplot.cxx:633
Int_t Write(const char *=0, Int_t=0, Int_t=0)
Definition Resplot.h:497
const TH1D * Mean() const
Definition Resplot.h:353
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
Resplot(const std::string &name, int n1, const double *a1, int n2, double a2, double b2, const std::string &xaxis="")
Definition Resplot.h:98
TH1D * m_Nentries
Definition Resplot.h:671
void deletehist(TH2D *t)
Definition Resplot.h:621
const std::string & FitName() const
Definition Resplot.h:382
int Finalise(TF1 *(*func)(TH1D *s, double a, double b), double a=-999, double b=-999)
Definition Resplot.h:473
void SetSecondary(int n, double a, double b)
Definition Resplot.h:626
double m_b_secondary
Definition Resplot.h:687
std::string m_fitname
Definition Resplot.h:693
StatVal m_g_sigma
Definition Resplot.h:680
Resplot(const std::string &name, const std::vector< double > &a, const std::vector< double > &b, const std::string &xaxis="")
Definition Resplot.h:124
TDirectory * Dir()
Definition Resplot.h:488
Resplot & operator+=(const Resplot &r)
operators
Definition Resplot.h:511
static TH1D * projectionX(TH2 *h2d, int row, const std::vector< double > &xlimits, const std::string &tagname)
Definition Resplot.h:435
void SetYAxis(const std::string &yaxis)
Definition Resplot.h:326
void delskip(TH2D *t)
Definition Resplot.h:620
bool finalised() const
Definition Resplot.h:374
Resplot operator+(const Resplot &r) const
Definition Resplot.h:582
void Integrate()
Definition Resplot.h:588
Resplot operator*(double d) const
Definition Resplot.h:577
TH1D * Uncertainty()
Definition Resplot.h:371
std::string m_name
Definition Resplot.h:669
const std::vector< TH1D * > & Slices() const
Definition Resplot.h:377
void SetPrimary(int n, double, double)
Definition Resplot.h:625
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
const TH1D * Uncertainty() const
Definition Resplot.h:372
StatVal get_mean()
Definition Resplot.h:631
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
static double sum(TH1 *h)
Definition Resplot.h:460
static const std::string & version()
Definition Resplot.h:597
const std::string & name() const
Definition Resplot.h:349
static bool AddDirectoryStatus()
Definition Resplot.h:500
void AddEfficiency(TH1D *h, int i, double lower, double upper)
Definition Resplot.h:635
Resplot(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2, const std::string &xaxis="")
Definition Resplot.h:84
int Fill(double x, double y, double w=1)
Definition Resplot.h:285
TH1D * H1D()
Definition Resplot.h:363
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=FitGaussian)
Definition Resplot.cxx:425
static TH1D * projectionY(TH2 *h2d, int col0, int col1, const std::vector< double > &ylimits, const std::string &tagname)
Definition Resplot.h:422
TH2D * H2D()
Definition Resplot.h:367
Resplot(const std::string &name)
Definition Resplot.h:210
static void AddDirectory(bool t=false)
Definition Resplot.h:501
void SetPrimary(int n, const double *)
Definition Resplot.h:624
Resplot(const std::string &name, TH2 *hin, const bool flip=false)
Definition Resplot.h:168
const TH1D * H1D() const
Definition Resplot.h:364
int Refit(TF1 *(*func)(TH1D *s, double a, double b))
Definition Resplot.h:482
static std::vector< double > getyLimits(TH2 *h)
Definition Resplot.h:406
StatVal m_g_mean
Definition Resplot.h:679
std::vector< TH1D * > m_slices
Definition Resplot.h:692
std::vector< double > GetPrimaryCentres() const
Definition Resplot.h:340
Resplot & operator*=(double d)
Definition Resplot.h:542
void Initialise(const std::string &name, int n1, double a1, double b1, int n2, double a2, double b2)
Definition Resplot.cxx:226
const std::string & Name() const
Definition Resplot.h:348
StatVal GetGlobalEfficiency(double lower, double upper)
Definition Resplot.h:299
void skip(TH1D *t)
Definition Resplot.h:615
void SetXAxis(const std::string &xaxis)
Definition Resplot.h:315
void AddMean(TH1D *h, int i)
Definition Resplot.h:647
Resplot(const std::string &name, const std::vector< double > &a, int n2, double a2, double b2, const std::string &xaxis="")
Definition Resplot.h:111
simple struct to hold a value and it's associated uncertainty.
Definition StatVal.h:27
int r
Definition globals.cxx:22
double entries
Definition listroot.cxx:49
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
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
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
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
TF1 * FitNull(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:1093
bool setoldrms95(bool b)
Definition Resplot.h:722
bool s_interpolate_flag
Definition Resplot.cxx:42
bool setscalerms95(bool b)
Definition Resplot.h:723
TF1 * FitNull95Obsolete(TH1D *s, double frac=0.95, bool useroot=false)
Definition Resplot.cxx:1213
TF1 * FitNull95(TH1D *s, double a=0, double b=0)
Definition Resplot.cxx:1472
bool setnofit(bool b)
Definition Resplot.h:724
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
const char * c_str() const
Definition tagname.h:64