ATLAS Offline Software
Loading...
Searching...
No Matches
computils.h
Go to the documentation of this file.
1/* emacs: this is -*- c++ -*- */
10
11// cppcheck-suppress-file stlIfStrFind; cannot use C++20 starts_with in this standalone code
12
13#ifndef COMPUTILS_H
14#define COMPUTILS_H
15
16#include <iostream>
17#include <string>
18#include <vector>
19#include <cstdio>
20#include <cstdlib>
21#include <exception>
22
23#include "label.h"
24#include "utils.h"
25#include "DrawLabel.h"
26
27#include "TStyle.h"
28#include "TPad.h"
29#include "TH1D.h"
30#include "TFile.h"
31#include "TH1.h"
32#include "TF1.h"
33#include "TGraphAsymmErrors.h"
34
35#include "TLegend.h"
36
37// #define JL
38
39extern bool JLflag;
40
41extern bool LINEF;
42extern bool LINES;
43
44
45void band_plot( TH1* h, double xlo, double xhi, double ylo=-999, double yhi=-999 );
46
47void ATLASFORAPP_LABEL( double x, double y, int color, double size=0.06 );
48
49void myText( Double_t x, Double_t y, Color_t color, const std::string& text, Double_t tsize);
50
51
53std::string stime();
54static std::string release;
55
56double integral( TH1* h );
57
58void Norm( TH1* h, double scale=1, double xmin=0, double xmax=0 );
59
60double Entries( TH1* h );
61
63bool contains( const std::string& s, const std::string& p);
64bool contains( const std::string& s, char p) noexcept;
65
67bool fcontains( const std::string& s, const std::string& p);
68
70bool exists( const std::string& filename );
71
73std::string tail( std::string s, const std::string& pattern );
74
76std::string head( std::string s, const std::string& pattern );
77
79std::string globbed( const std::string& s );
80
81void contents( std::vector<std::string>& keys,
82 TDirectory* td,
83 const std::string& directory="",
84 const std::string& pattern="",
85 const std::string& path="" );
86
87void contents( std::vector<std::string>& keys,
88 TDirectory* td,
89 const std::string& directory="",
90 const std::vector<std::string>& patterns=std::vector<std::string>(),
91 const std::string& path="" );
92
93
94double realmax( TH1* h, bool include_error=true, double lo=0, double hi=0 );
95double realmin( TH1* h, bool include_error=true, double lo=0, double hi=0 );
96
97std::string findcell( std::string name, const std::string& regex, const std::string& splitex="/" );
98
99std::string findrun( TFile *f );
100
101double plotable( TH1* h ); // , double xlo=-999, double xhi=-999 );
102
103
104class data_mismatch : public std::exception {
105public:
106 data_mismatch(const std::string& s) { std::cerr << "exception:" << data_mismatch::what() << " " << s << std::endl; };
107 virtual const char* what() const throw() { return "data don't match"; }
108};
109
110
111
112template<typename T>
113std::ostream& operator<<( std::ostream& s, std::vector<T>& v) {
114 for ( unsigned i=0 ; i<v.size() ; i++ ) s << "\t" << v[i];
115 return s;
116}
117
118
120std::vector<int> findxrange(TH1* h, bool symmetric=false );
121std::vector<double> findxrangeuser(TH1* h, bool symmetric=false );
122
123
124
125void trim_tgraph( TH1* h, TGraphAsymmErrors* t );
126
127
128void xrange(TH1* h, bool symmetric=true );
129
131void copyReleaseInfo( TFile* finput, TFile* foutdir );
132
133
134class true_mean {
135
136public:
137
138 true_mean( TH1F* h );
139
140 double mean() const { return m_mean; }
141 double error() const { return m_error; }
142
143private:
144
145 double m_mean;
146 double m_error;
147
148};
149
150
153
154class AxisInfo {
155
156public:
157
158 AxisInfo( const std::string& s ) :
159 m_info(s),
160 m_log(false),
161 m_autoset(false),
162 m_symmetric(false),
163 m_rangeset(false),
164 m_lo(0),
165 m_hi(0),
166 m_norm(false),
167 m_refnorm(false),
168 m_binwidth(false),
169 m_offset(0),
170 m_trim(false)
171 {
172 // std::cout << "AxisInfo::info" << m_info << std::endl;
173
174 std::vector<std::string> keys = split( s, ":" );
175
176 // std::cout << "\n\n" << s << "\nnkeys " << keys.size() << std::endl;
177
178 if ( keys.size()>0 ) m_tag = keys[0];
179
180 bool minset = false;
181 // bool maxset = false;
182
183 for ( size_t i=1 ; i<keys.size() ; i++ ) {
184
185 if ( keys[i]=="lin" ) m_log = false;
186 else if ( keys[i]=="log" ) m_log = true;
187 else if ( keys[i]=="sym" ) m_symmetric = true;
188 else if ( keys[i]=="norm" ) m_norm = true;
189 else if ( keys[i]=="refn" ) m_refnorm = true;
190 else if ( keys[i]=="width" ) m_binwidth = true;
191 else if ( keys[i]=="auto" ) m_autoset = true;
192 else if ( keys[i]=="trim" ) m_trim = true;
193 //cppcheck-suppress stlIfStrFind
194 else if ( keys[i].find("offset")==0 ) {
195
196 std::cout << "offset:" << std::endl;
197 std::cout << "\tkey: " << keys[i] << std::endl;
198 std::cout << "\tpos: " << keys[i].find("offset") << std::endl;
199
200 std::string offset = keys[i];
201 m_offset=std::atof(offset.substr(6,offset.size()-6).c_str());
202
203 std::cout << "m_offset: " << m_offset << std::endl;
204 }
205 else if ( keys[i]=="auton" ) {
206 m_autoset = true;
207 m_norm = true;
208 }
209 else if ( keys[i]=="autow" ) {
210 m_autoset = true;
211 m_binwidth = true;
212 }
213 else if ( keys[i]=="autown" || keys[i]=="autonw" ) {
214 m_autoset = true;
215 m_norm = true;
216 m_binwidth = true;
217 }
218 else if ( keys[i]=="autosym" ) {
219 m_autoset = true;
220 m_symmetric = true;
221 }
222 else if ( keys[i]=="normw" || keys[i]=="widthn" ) {
223 m_norm = true;
224 m_binwidth = true;
225 }
226 else if ( !minset ) {
227 m_lo = std::atof(keys[i].c_str());
228 i++;
229 if ( i<keys.size() ) m_hi = std::atof(keys[i].c_str());
230 else {
231 std::cerr << "not enough values for the axis range: " << s << std::endl;
232 std::exit(-1);
233 }
234 minset = true;
235 // maxset = true;
236 m_rangeset = true;
237 }
238 }
239
240#if 0
241 std::cout << "AxisInfo::info" << m_info << "\n";
242 std::cout << "\tlog " << m_log << "\n";
243 std::cout << "\tauto " << m_autoset << "\n";
244 std::cout << "\tsym " << m_symmetric << "\n";
245 std::cout << "\trange " << m_rangeset << " : " << m_lo << " - " << m_hi << std::endl;
246#endif
247
248 }
249
251
252 const std::string& tag() const { return m_tag; }
253
254 bool log() const { return m_log; }
255
256 bool autoset() const { return m_autoset; }
257
258 bool normset() const { return m_norm; }
259
260 bool refnormset() const { return m_refnorm; }
261
262 bool symmetric() const { return m_symmetric; }
263
264 bool rangeset() const { return m_rangeset; }
265
266 bool trim() const { return m_trim; }
267
268
269 double offset() const { return m_offset; }
270
271
272 double lo() const { return m_lo; }
273 double hi() const { return m_hi; }
274
275 double lo(double x) { return m_lo=x; }
276 double hi(double x) { return m_hi=x; }
277
278
279 double binwidth() const { return m_binwidth; }
280
281 const std::string& c_str() const { return m_info; }
282
283public:
284
285 static std::vector<std::string> split( const std::string& s, const std::string& t=":" ) {
286
287 std::string sc = s;
288 size_t pos = sc.find(t);
289
290 std::vector<std::string> tags;
291
292 while ( pos!=std::string::npos ) {
293 tags.push_back( chop(sc,t) );
294 pos = sc.find(t);
295 }
296
297 tags.push_back(sc);
298
299 return tags;
300 }
301
302
303public:
304
305 std::string m_info;
306
307 std::string m_tag;
308
309 bool m_log;
312
314 double m_lo;
315 double m_hi;
316
317 bool m_norm;
319
321
322 double m_offset;
323
324 bool m_trim;
325
326};
327
328
329inline std::ostream& operator<<( std::ostream& s, const AxisInfo& a ) {
330 s << "[ " << a.tag() << ( a.log() ? " : log" : "" ) << " ";
331 if ( a.autoset() ) s << " : auto";
332 else if ( a.rangeset() ) s << " : range " << a.lo() << " - " << a.hi();
333 s << " ]";
334 return s;
335}
336
337
338
339
340
341
342
344class Legend {
345
346public:
347
348 Legend() : m_leg(nullptr){
349 m_x[0]=0.0;
350 m_y[0]=0.0;
351 m_x[1]=0.0;
352 m_y[1]=0.0;
353 }
354
355 Legend(double x1, double x2, double y1, double y2): m_leg(nullptr) {
356 m_x[0]=x1;
357 m_y[0]=y1;
358 m_x[1]=x2;
359 m_y[1]=y2;
360 }
361
362
363 // Legend( const Legend& leg ) : mleg((TLegend*)leg.mleg->Clone()) { }
364
366 m_x{legend.m_x[0], legend.m_x[1]},
367 m_y{legend.m_y[0], legend.m_y[1]} { }
368
369 ~Legend() { }
370
371 TLegend* legend() { return m_leg; }
372
373 size_t size() const {
374 return m_entries.size();
375 }
376
377 double TextSize() const { return m_leg->GetTextSize(); }
378
379 int TextFont() const { return m_leg->GetTextFont(); }
380
381 double height() const { return m_y[1]-m_y[0]; }
382
383 double width() const { return m_x[1]-m_x[0]; }
384
385 void AddEntry( TObject* tobj, const std::string& s, const std::string& type="p" ) {
386 m_obj.push_back( tobj );
387 m_entries.push_back( s );
388 m_type.push_back( type );
389 }
390
391 void Draw() {
392
395
396 double y0 = 0;
397
398 if ( m_y[0]>0.5 ) {
399 y0 = m_y[1] - m_entries.size()*0.05;
400 }
401 else {
402 y0 = m_y[0];
403 m_y[1] = y0 + m_entries.size()*0.05;
404 }
405
406 m_leg = new TLegend( m_x[0], y0, m_x[1], m_y[1] );
407
408#if 1
409 m_leg->SetBorderSize(0);
410 m_leg->SetTextFont(42);
411 m_leg->SetTextSize(0.04);
412 m_leg->SetFillStyle(3000);
413 m_leg->SetFillColor(0);
414 m_leg->SetLineColor(0);
415#endif
416
417 for ( size_t i=0 ; i<m_entries.size() ; i++ ) {
418 m_leg->AddEntry( m_obj[i], m_entries[i].c_str(), m_type[i].c_str() );
419 }
420
421 m_leg->Draw();
422 }
423
424
425private:
426
427 TLegend* m_leg;
428
429 double m_x[2];
430 double m_y[2];
431
432 std::vector<TObject*> m_obj;
433 std::vector<std::string> m_entries;
434 std::vector<std::string> m_type;
435
436};
437
438
439extern int colours[6]; // = { 1, 2, kBlue-4, 6, kCyan-2, kMagenta+2 };
440extern int markers[6]; // = { 20, 24, 25, 26, 25, 22 };
441extern double msizes[6]; // = { 1, 1, 1, 1, 1, 1 };
442
443
444template<typename T>
445void setParameters( T* h, TGraphAsymmErrors* tg ) {
446 tg->SetLineColor( h->GetLineColor() );
447 tg->SetMarkerColor( h->GetMarkerColor() );
448 tg->SetMarkerStyle( h->GetMarkerStyle() );
449 tg->SetMarkerSize( h->GetMarkerSize() );
450 tg->SetLineWidth( h->GetLineWidth() );
451 tg->SetLineStyle( h->GetLineStyle() );
452}
453
454
455template<typename T>
456void zeroErrors( T* /* h */ ) {
457 // for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) h->SetBinError( i, 1e-100 );
458}
459
460
461
466template<typename T>
467class tPlotter {
468
469public:
470
471 tPlotter(T* fo_htest=0, T* fo_href=0, const std::string& s="", TGraphAsymmErrors* fo_tgtest=0, TGraphAsymmErrors* fo_tgref=0 ) :
472 m_htest(fo_htest), m_href(fo_href),
473 m_tgtest(fo_tgtest), m_tgref(fo_tgref),
475 m_max_entries(4),
476 m_entries(0),
477 m_trim_errors(false),
478 m_mc(false),
479 m_lo(-999), m_hi(-999),
480 m_xlo(-999), m_xhi(-999),
481 m_xaxis(0), m_yaxis(0) {
482 }
483
484
485 tPlotter(const tPlotter& p) :
490 m_entries(0),
492 m_mc(p.m_mc),
493 m_lo(p.m_lo), m_hi(p.m_hi),
494 m_xlo(-999), m_xhi(-999),
495 m_xaxis(0), m_yaxis(0) {
496 }
497
500 // ~tPlotter() { if ( m_tg ) delete m_tg; }
504
505
506 void xlo( double x ) { m_xlo = x; }
507 void xhi( double x ) { m_xhi = x; }
508
509 double xlo() const { return m_xlo; }
510 double xhi() const { return m_xhi; }
511
512 const std::string& plotfilename() const { return m_plotfilename; }
513
514 void trim_errors(bool b) { m_trim_errors=b; }
515
516 bool trim_errors() const { return m_trim_errors; }
517
518 void SetRange( double lo, double hi ) { m_lo=lo, m_hi=hi; }
519
520 void Draw( int i, Legend* lleg, bool mean=false, bool first=true, bool drawlegend=false ) {
521
522 std::cout << "Draw " << __LINE__ << std::endl;
523
524 double phibeam = 0;
525 double xbeam = 0;
526 double ybeam = 0;
527 double offbeam = 0;
528
529
530 if ( htest() ) {
531
532 gStyle->SetOptStat(0);
533
534#if 1
535 if ( first ) {
536
537 // double lo = xlo();
538 // double hi = xhi();
539
540 double lo = htest()->GetBinLowEdge(1);
541 double hi = htest()->GetBinLowEdge(htest()->GetNbinsX()+1);
542
543 std::cout << "aes lo: " << lo << std::endl;
544 std::cout << "ase hi: " << hi << std::endl;
545
546 std::cout << "ase m_lo: " << m_lo << std::endl;
547 std::cout << "ase m_hi: " << m_hi << std::endl;
548
549
550 if ( m_xaxis ) {
551 std::cout << "ase: " << *m_xaxis << std::endl;
552 std::cout << "ase: " << m_xaxis->m_lo << std::endl;
553 std::cout << "ase: " << m_xaxis->m_hi << std::endl;
554
555 if ( m_xaxis->m_lo!=0 || m_xaxis->m_hi!=0 ) {
556 // hnull->GetXaxis()->SetRangeUser( m_xaxis->m_lo, m_xaxis->m_hi!=0 );
557
558 // if ( lo>m_xaxis->m_lo ) lo = m_xaxis->m_lo;
559 // if ( hi<m_xaxis->m_hi ) hi = m_xaxis->m_hi;
560
561 lo = m_xaxis->m_lo;
562 hi = m_xaxis->m_hi;
563 }
564 else {
565 if ( m_lo!=m_hi ) {
566 if ( m_lo>lo ) lo = m_lo;
567 if ( m_hi<hi ) hi = m_hi;
568 }
569 }
570 }
571
572
573 std::cout << "fck lo: " << lo << std::endl;
574 std::cout << "fck hi: " << hi << std::endl;
575
576 TH1D* hnull = new TH1D("hnull", htest()->GetTitle(), 100, lo, hi ); // htest()->GetBinLowEdge(1), htest()->GetBinLowEdge(htest()->GetNbinsX()+1) );
577 hnull->SetDirectory(0);
578
579 hnull->SetMaximum(htest()->GetMaximum());
580 hnull->SetMinimum(htest()->GetMinimum());
581 hnull->GetXaxis()->SetMoreLogLabels(true);
582
583 hnull->GetXaxis()->SetTitle(htest()->GetXaxis()->GetTitle());
584 hnull->GetYaxis()->SetTitle(htest()->GetYaxis()->GetTitle());
585
586
587
588 for ( int ib=1 ; ib<101 ; ib++ ) hnull->SetBinContent(ib, hnull->GetMinimum()-1e10);
589
590 hnull->DrawCopy();
591
592 std::cout << htest()->GetTitle() << std::endl;
593 std::cout << hnull->GetXaxis()->GetTitle() << std::endl;
594 std::cout << hnull->GetYaxis()->GetTitle() << std::endl;
595
596 first = false;
597 }
598#endif
599
600 if ( href() ) {
601 href()->SetLineColor(colours[i%6]);
602 href()->SetLineStyle(2);
603 href()->SetMarkerStyle(0);
604 }
605
606 if ( LINEF ) htest()->SetLineColor(colours[i%6]);
607
608 if ( JLflag ) {
609 if ( contains( std::string(htest()->GetName()), "vs_mu") ) htest()->GetXaxis()->SetRangeUser( 18, 58 );
610 if ( contains( std::string(htest()->GetName()), "a0_eff") ) htest()->GetXaxis()->SetRangeUser( -200, 200 );
611
612 std::cout << "TEST: " << htest()->GetName() << " " << mc() << "\t" << std::endl;
613 }
614
615 htest()->SetLineStyle(1);
616
617 if ( LINEF ) htest()->SetMarkerColor(htest()->GetLineColor());
618
619 if ( LINEF ) htest()->SetMarkerStyle(markers[i%6]);
620 // if ( LINEF && htest()->GetMarkerStyle() == 20 )
621
622 if ( LINEF ) htest()->SetMarkerSize( msizes[i%6]*htest()->GetMarkerSize() );
623
624 if ( htest() ) std::cout << "\tentries: " << plotable( htest() );
625
626 std::cout << std::endl;
627
628
629 if ( first ) {
630
631 if ( !mc() ) {
632 if ( tgtest() ) {
633
634#if 0
635 TH1F* h = (TH1F*)htest()->Clone("h"); h->SetDirectory(0);
636
637 zeroErrors(h);
638 h->GetXaxis()->SetMoreLogLabels(true);
639 if ( trim_errors() ) trim_tgraph( h, tgtest() );
640
641 if ( m_xlo!=-999 && m_xhi!=-999 ) {
642 TH1D* hnull = nrew TH1D( "hnull", "", 100, m_xlo, m_xhi );
643 hnull->SetMinimum( h->GetMinimum() );
644 hnull->SetMaximum( h->GetMaximum() );
645 hnull->SetTitle( h->GetTitle() );
646 hnull->DrawCopy();
647 h->Draw("ep same");
648 }
649 else {
650 h->Draw("ep");
651 first = false;
652 }
653
654 if ( LINES ) h->Draw("lhistsame");
655 setParameters( h, tgtest() );
656 tgtest()->Draw("esame");
657#else
658 zeroErrors(htest());
659
660 std::cout << "shte lo: " << m_lo << std::endl;
661 std::cout << "shte hi: " << m_hi << std::endl;
662
663
664 htest()->GetXaxis()->SetMoreLogLabels(true);
665 if ( trim_errors() ) trim_tgraph( htest(), tgtest() );
666
667
668 htest()->Draw("ep");
669 if ( LINES ) htest()->Draw("lhistsame");
670 setParameters( htest(), tgtest() );
671 tgtest()->Draw("esame");
672 first = false;
673
674
675#endif
676 }
677 else {
678
679 std::cout << "cck lo: " << m_lo << std::endl;
680 std::cout << "cck hi: " << m_hi << std::endl;
681
682 htest()->GetXaxis()->SetMoreLogLabels(true);
683 htest()->Draw("ep");
684 first = false;
685 if ( LINES ) htest()->Draw("lhistsame");
686 }
687 }
688
689 }
690
691 if ( s_plotref && href() ) {
692 if ( contains(href()->GetName(),"_vs_") ||
693 contains(href()->GetName(),"sigma") ||
694 contains(href()->GetName(),"mean") ||
695 contains(href()->GetName(),"_eff") ||
696 contains(href()->GetName(),"Res_") ||
697 contains(href()->GetName(),"Eff_") ) href()->Draw("hist same][");
698 else href()->Draw("hist same");
699 }
700
701 if ( !mc() && tgtest() ) {
702 zeroErrors(htest());
703
704 if ( trim_errors() ) trim_tgraph( htest(), tgtest() );
705 setParameters( htest(), tgtest() );
706 tgtest()->Draw("e1same");
707 if ( LINES ) tgtest()->Draw("lsame");
708
709 }
710
711#if 0
713 if ( htest()->GetMarkerStyle()>23 ) {
714 TH1D* hnull = (TH1D*)htest()->Clone("duff"); hnull->SetDirectory(0);
715 zeroErrors( hnull );
716 hnull->SetLineColor(kWhite);
717 hnull->SetMarkerStyle( htest()->GetMarkerStyle()-4 );
718 // hnull->SetMarkerStyle( 0 );
719 hnull->SetMarkerColor(kWhite);
720 hnull->SetMarkerSize( htest()->GetMarkerSize()*0.75 );
721 // hnull->SetMarkerSize( 0 );
722 hnull->DrawCopy("l same");
723
724 std::cout << "cnt lo: " << m_lo << std::endl;
725 std::cout << "cnt hi: " << m_hi << std::endl;
726
727
728 delete hnull;
729 }
730#endif
731
732 std::cout << "TEST MC: " << htest()->GetName() << " " << mc() << std::endl;
733
734 TH1* h = htest();
735
736 TList* ccklist = h->GetListOfFunctions();
737
738 size_t tlsize = ccklist->GetSize();
739
740 std::cout << "tlsize: " << tlsize << std::endl;
741
742
743 for ( size_t icck=0 ; icck<tlsize ; icck++ ) {
744 std::cout << "tlist: " << icck << " " << ccklist->At(icck)->GetName() << std::endl;
745
746 TF1* cck = (TF1*)ccklist->At(icck);
747
748 cck->SetLineColor(htest()->GetLineColor());
749
750 if ( std::string(cck->GetName()) == "sinus" ) {
751 phibeam = cck->GetParameter(1);
752 xbeam = cck->GetParameter(0)*cos(phibeam);
753 ybeam = cck->GetParameter(0)*sin(phibeam);
754 offbeam = cck->GetParameter(2);
755
756 std::cout << "phi = " << phibeam
757 << "\nx = " << xbeam
758 << " mm\ny = " << ybeam
759 << " mm\noff = " << offbeam << " mm" << std::endl;
760
761 }
762
763 }
764
765 // if ( tlsize > 0 ) std::exit(0);
766
767
768 if ( !mc() ) {
769
770 std::cout << "TEST mtype " << htest()->GetMarkerStyle() << " " << htest()->GetMarkerColor() << std::endl;
771
772 if ( contains( std::string(h->GetName()), "a0_eff") ) {
773 // h->GetXaxis()->SetRangeUser( -200,200 );
774
776 std::cout << "STUFF" << std::endl;
777
778
779 for (int i=0 ; i<h->GetNbinsX() ; i++ ) {
780 if (h->GetBinCenter(i)<-200 ) {
781 h->SetBinContent(i,0);
782 h->SetBinError(i,0);
783 }
784 }
785 }
786
787 std::cout << "SHTE" << std::endl;
788
789 htest()->Draw("ep same");
790 if ( LINES ) htest()->Draw("lhist same");
791 }
792 else {
793
794 std::cout << "SHTE" << std::endl;
795
796
797#if 1
798 std::cout << "colour: " << htest()->GetMarkerColor() << std::endl;
799
800#if 1
802 htest()->SetFillStyle(455);
803 htest()->SetFillColor(htest()->GetMarkerColor());
804 htest()->SetMarkerStyle(0);
805#endif
806
808 if ( contains( std::string(h->GetName()), "vs_mu") ) h->GetXaxis()->SetRangeUser( 18, 58 );
809 if ( contains( std::string(h->GetName()), "a0_eff") ) {
810 h->GetXaxis()->SetRangeUser( -200,200 );
811
812 std::cout << "STUFF" << std::endl;
813
814 for (int i=0 ; i<h->GetNbinsX() ; i++ ) {
815 if (h->GetBinCenter(i)<-200 ) {
816 h->SetBinContent(i,0);
817 h->SetBinError(i,0);
818 }
819 }
820
821 }
822
823 htest()->Draw("e3lhistsame");
824 // htest()->Draw("e1same");
825
826 // std::cout << "band plot: " << m_lo << " " << m_hi << std::endl;
827
828 band_plot( htest(), m_lo, m_hi, htest()->GetMinimum(), htest()->GetMaximum() );
829 if ( LINES ) htest()->Draw("e3lhist same");
830#endif
831 }
832
833 // href()->Draw("lhistsame");
834 // htest()->Draw("lhistsame");
835
836 std::string key = m_plotfilename;
837
838 static TH1D* hnull = new TH1D("hnull", "", 1, 0, 1);
839 hnull->SetMarkerColor(kWhite);
840 hnull->SetLineColor(kWhite);
841 hnull->SetMarkerStyle(0);
842 hnull->SetLineStyle(0);
843 hnull->SetLineWidth(0);
844 hnull->SetMarkerSize(0);
845
846
847 if ( lleg ) {
848
849 Legend& leg = *lleg;
850
851 if ( mean ) {
852
853 char meanrefc[64];
854 bool displayref = false;
855 if ( s_meanplotref && href() ) {
856 displayref = true;
857 true_mean muref( href() );
858 std::snprintf( meanrefc, 64, " <t> = %3.2f #pm %3.2f ms (ref)", muref.mean(), muref.error() );
859 }
860 else {
861 std::snprintf( meanrefc, 64, "%s", "" );
862 }
863
864 true_mean mutest( htest() );
865 char meanc[64];
866 std::snprintf( meanc, 64, " <t> = %3.2f #pm %3.2f ms", mutest.mean(), mutest.error() );
867
868 std::string dkey = key;
869
870 std::string remove[7] = { "TIME_", "Time_", "All_", "Algorithm_", "Class_", "HLT_", "Chain_HLT_" };
871
872 if ( dkey.find("Chain")!=std::string::npos ) {
873 if ( dkey.find("__")!=std::string::npos ) dkey.erase( 0, dkey.find("__")+2 );
874 }
875
876
877 for ( int ir=0 ; ir<7 ; ir++ ) {
878 if ( dkey.find( remove[ir] )!=std::string::npos ) dkey.erase( dkey.find( remove[ir]), remove[ir].size() );
879 }
880
881 std::string rkey = dkey;
882
883
884 if ( LINEF || leg.size() < m_max_entries ) {
885 dkey += std::string(" : ");
886
887 if ( (dkey+meanc).size()>58 ) {
888 leg.AddEntry( htest(), dkey, "p" );
889 leg.AddEntry( hnull, meanc, "p" );
890 }
891 else {
892 leg.AddEntry( htest(), (dkey+meanc).c_str(), "p" );
893 }
894
895 if ( displayref ) {
896 rkey += std::string(" : ");
898 // leg.AddEntry( hnull, "", "l" );
899
900 if ( (rkey+meanrefc).size()>58 ) {
901 leg.AddEntry( href(), rkey, "l" );
902 leg.AddEntry( hnull, meanrefc, "l" );
903 }
904 else {
905 leg.AddEntry( href(), (rkey+meanrefc).c_str(), "l" );
906 }
907 }
908 }
909
910 }
911 else {
912 if ( !mc() ) {
913 if ( LINEF || leg.size()<m_max_entries ) leg.AddEntry( htest(), key, "p" );
914 }
915 else {
916 if ( LINEF || leg.size()<m_max_entries ) leg.AddEntry( htest(), key, "f" );
917 }
918 }
919
920 m_entries++;
921
922 if ( drawlegend ) leg.Draw();
923
924
925 if ( xbeam!=0 || ybeam!=0 ) {
926 // DrawLabel( 0.19, 0.24+i*0.085, label( "x_{beam} = %6.3lf mm", int(1000*xbeam + 0.5)*0.001), htest()->GetLineColor() );
927 // DrawLabel( 0.19, 0.20+i*0.085, label( "y_{beam} = %6.3lf mm", int(1000*ybeam + 0.5)*0.001), htest()->GetLineColor() );
928 DrawLabel( 0.19, 0.20+i*0.045, label( "x =%6.3lf mm y =%6.3lf mm off =%6.3lf mm", xbeam, ybeam, offbeam, 0 ), htest()->GetLineColor() );
929 // DrawLabel( 0.19, 0.20+i*0.045,
930 // int(1000*xbeam + 0.5)*0.001,
931 // int(1000*ybeam + 0.5)*0.001,
932 // int(1000*offbeam + 0.5)*0.001 ),
933 // htest()->GetLineColor() );
934 }
935
936 }
937
938 }
939 }
940
941
942
943 void DrawLegend( int i, Legend& leg, bool mean=false, bool first=true, bool drawlegend=false ) {
944
945 if ( htest() ) {
946 gStyle->SetOptStat(0);
947 if ( href() ) {
948 href()->SetLineColor(colours[i%6]);
949 href()->SetLineStyle(2);
950 href()->SetMarkerStyle(0);
951 }
952
953 if ( LINEF ) htest()->SetLineColor(colours[i%6]);
954 htest()->SetLineStyle(1);
955 if ( LINEF ) htest()->SetMarkerColor(htest()->GetLineColor());
956 if ( LINEF ) htest()->SetMarkerStyle(markers[i%6]);
957
958 if ( htest() ) std::cout << "\tentries: " << plotable( htest() );
959 std::cout << std::endl;
960
961 if ( first ) {
962
963 if ( tgtest() ) {
964 zeroErrors(htest());
965 htest()->GetXaxis()->SetMoreLogLabels(true);
966 if ( trim_errors() ) trim_tgraph( htest(), tgtest() );
967
968
969 // htest()->Draw("ep");
970 if ( LINES ) htest()->Draw("lhistsame");
971 setParameters( htest(), tgtest() );
972 // tgtest()->Draw("esame");
973 }
974 else {
975 htest()->GetXaxis()->SetMoreLogLabels(true);
976 // htest()->Draw("ep");
977 // if ( LINES ) htest()->Draw("lhistsame");
978 }
979
980 }
981
982
983#if 0
984 if ( s_plotref && href() ) {
985 if ( contains(href()->GetName(),"_vs_") ||
986 contains(href()->GetName(),"sigma") ||
987 contains(href()->GetName(),"mean") ||
988 contains(href()->GetName(),"_eff") ||
989 contains(href()->GetName(),"Res_") ||
990 contains(href()->GetName(),"Eff_") ) href()->Draw("hist same][");
991 else href()->Draw("hist same");
992 }
993
994 if ( tgtest() ) {
995 zeroErrors(htest());
996
997 if ( trim_errors() ) trim_tgraph( htest(), tgtest() );
998 setParameters( htest(), tgtest() );
999 tgtest()->Draw("e1same");
1000 if ( LINES ) tgtest()->Draw("lsame");
1001
1002 }
1003#endif
1004
1005
1006#if 0
1008 if ( htest()->GetMarkerStyle()>23 ) {
1009 TH1D* hnull = (TH1D*)htest()->Clone("duff"); hnull->SetDirectory(0);
1010 zeroErrors( hnull );
1011 hnull->SetLineColor(kWhite);
1012 hnull->SetMarkerStyle( htest()->GetMarkerStyle()-4 );
1013 // hnull->SetMarkerStyle( 0 );
1014 hnull->SetMarkerColor(kWhite);
1015 hnull->SetMarkerSize( htest()->GetMarkerSize()*0.75 );
1016 // hnull->SetMarkerSize( 0 );
1017 hnull->DrawCopy("l same");
1018 delete hnull;
1019 }
1020#endif
1021
1022 // htest()->Draw("ep same");
1023 // if ( LINES ) htest()->Draw("lhist same");
1024
1025 // href()->Draw("lhistsame");
1026 // htest()->Draw("lhistsame");
1027
1028 std::string key = m_plotfilename;
1029
1030 static TH1D* hnull = new TH1D("hnull", "", 1, 0, 1);
1031 hnull->SetMarkerColor(kWhite);
1032 hnull->SetLineColor(kWhite);
1033 hnull->SetMarkerStyle(0);
1034 hnull->SetLineStyle(0);
1035 hnull->SetLineWidth(0);
1036 hnull->SetMarkerSize(0);
1037
1038
1039 if ( mean ) {
1040
1041 char meanrefc[64];
1042 bool displayref = false;
1043 if ( s_meanplotref && href() ) {
1044 displayref = true;
1045 true_mean muref( href() );
1046 std::sprintf( meanrefc, " <t> = %3.2f #pm %3.2f ms (ref)", muref.mean(), muref.error() );
1047 }
1048 else {
1049 std::sprintf( meanrefc, "%s", "" );
1050 }
1051
1052
1053 true_mean mutest( htest() );
1054 char meanc[64];
1055 std::sprintf( meanc, " <t> = %3.2f #pm %3.2f ms", mutest.mean(), mutest.error() );
1056
1057 std::string dkey = key;
1058
1059 std::string remove[7] = { "TIME_", "Time_", "All_", "Algorithm_", "Class_", "HLT_", "Chain_HLT_" };
1060
1061 if ( dkey.find("Chain")!=std::string::npos ) {
1062 if ( dkey.find("__")!=std::string::npos ) dkey.erase( 0, dkey.find("__")+2 );
1063 }
1064
1065
1066 for ( int ir=0 ; ir<7 ; ir++ ) {
1067 if ( dkey.find( remove[ir] )!=std::string::npos ) dkey.erase( dkey.find( remove[ir]), remove[ir].size() );
1068 }
1069
1070 std::string rkey = dkey;
1071
1072
1073 if ( LINEF || leg.size() < m_max_entries ) {
1074 dkey += std::string(" : ");
1075
1076 if ( (dkey+meanc).size()>58 ) {
1077 leg.AddEntry( htest(), dkey, "p" );
1078 leg.AddEntry( hnull, meanc, "p" );
1079 }
1080 else {
1081 leg.AddEntry( htest(), (dkey+meanc).c_str(), "p" );
1082 }
1083
1084 if ( displayref ) {
1085 rkey += std::string(" : ");
1086 // leg.AddEntry( hnull, "", "l" );
1087
1088 if ( (rkey+meanrefc).size()>58 ) {
1089 leg.AddEntry( href(), rkey, "l" );
1090 leg.AddEntry( hnull, meanrefc, "l" );
1091 }
1092 else {
1093 leg.AddEntry( href(), (rkey+meanrefc).c_str(), "l" );
1094 }
1095 }
1096 }
1097
1098 }
1099 else {
1100 if ( !mc() ) {
1101 if ( LINEF || leg.size()<m_max_entries ) leg.AddEntry( htest(), key, "p" );
1102 }
1103 else {
1104 if ( LINEF || leg.size()<m_max_entries ) leg.AddEntry( htest(), key, "f" );
1105 }
1106 }
1107
1108 m_entries++;
1109
1110 if ( drawlegend ) leg.Draw();
1111
1112 }
1113 }
1114
1115
1116
1118 void Print(const std::string& s="") {
1119 if ( s!="" ) gPad->Print(s.c_str());
1120 else gPad->Print(m_plotfilename.c_str());
1121 }
1122
1123 T* htest() { return m_htest; }
1124 T* href() { return m_href; }
1125
1126 bool mc(bool b) { return m_mc=b; }
1127
1128 bool mc() const { return m_mc; }
1129
1130 TGraphAsymmErrors* tgtest() { return m_tgtest; }
1131 TGraphAsymmErrors* tgref() { return m_tgref; }
1132
1133 void max_entries( int i ) { m_max_entries = i; }
1134
1135public:
1136
1137 static void setplotref( bool b ) { s_plotref=s_meanplotref=b; }
1138 static void setmeanplotref( bool b ) { s_meanplotref=b; }
1139
1140 void xaxis( const AxisInfo* a ) { m_xaxis = a; }
1141 void yaxis( const AxisInfo* a ) { m_yaxis = a; }
1142
1143 const AxisInfo* xaxis() const { return m_xaxis; }
1144 const AxisInfo* yaxis() const { return m_yaxis; }
1145
1146private:
1147
1151
1152 TGraphAsymmErrors* m_tgtest;
1153 TGraphAsymmErrors* m_tgref;
1154
1155 std::string m_plotfilename;
1156
1157 static bool s_plotref;
1158 static bool s_meanplotref;
1159
1162
1164
1165 bool m_mc;
1166
1167 double m_lo;
1168 double m_hi;
1169
1170 double m_xlo;
1171 double m_xhi;
1172
1175
1176};
1177
1178
1180
1181
1183template<typename T>
1185
1186
1187template<typename T>
1189
1190
1191
1192bool empty( TH1* h );
1193
1194
1195
1196inline void hminus(TH1* h) {
1197 std::cout << __FUNCTION__ << std::endl;
1198 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
1199 double duff = h->GetBinContent(i);
1200 if ( duff<0 ) {
1201 std::cout<< "\t\t" << __FUNCTION__ << " " << h->GetName() << " " << i << " " << h->GetBinContent(i) << " " << (duff*1e6) << std::endl;
1202 }
1203 }
1204 h->DrawCopy();
1205 gPad->Print( (std::string("duff-")+h->GetName()+".pdf").c_str() );
1206}
1207
1208
1210class Plots : public std::vector<Plotter> {
1211
1212public:
1213
1214 Plots(const std::string& s="", bool errors=false ) :
1215 m_name(s),
1216 m_logx(false), m_logy(false),
1217 m_maxset(false), m_max(0),
1218 m_minset(false), m_min(0),
1219 m_rangeset(false),
1220 m_lo(0.0), m_hi(0.0),
1221 m_trim_errors(errors)
1222 { }
1223
1224 double realmin( double lo=0, double hi=0 ) {
1225 bool first = true;
1226 double min = 1000;
1227 for ( unsigned i=0 ; i<size() ; i++ ) {
1228 double rmtest = ::realmin( at(i).htest(), false, lo, hi );
1229 if ( rmtest!=0 && ( first || min>rmtest ) ) min = rmtest;
1230 if ( rmtest!=0 ) first = false;
1231 }
1232 return min;
1233 }
1234
1235 double realmax(double lo=0, double hi=0) {
1236 bool first = true;
1237 double max = 0;
1238 for ( unsigned i=0 ; i<size() ; i++ ) {
1239 // double rmref = realmin( at(i).href(), false );
1240 double rmtest = ::realmax( at(i).htest(), false, lo, hi );
1241 if ( rmtest!=0 && ( first || max<rmtest ) ) max = rmtest;
1242 if ( rmtest!=0 ) first = false;
1243 }
1244 return max;
1245 }
1246
1247
1248
1249 void MaxScale(double scale=1.1, double lo=0, double hi=0) {
1250
1251 if ( size()<1 ) return;
1252
1253 double tmax = realmax(lo,hi);
1254 double tmin = realmin(lo,hi);
1255
1256 m_max = scale*tmax;
1257
1258 if ( m_logy ) m_min = tmin;
1259
1260 for ( unsigned i=0 ; i<size() ; i++ ) {
1261 if ( at(i).href() ) at(i).href()->SetMaximum(scale*tmax);
1262 at(i).htest()->SetMaximum(scale*tmax);
1263 }
1264
1265 }
1266
1267
1268 void MinScale( double scale, double lo=0, double hi=0 ) {
1269
1270 if ( size()<1 ) return;
1271
1272 if ( scale==0 ) {
1273 for ( unsigned i=0 ; i<size() ; i++ ) {
1274 if ( at(i).href() ) at(i).href()->SetMinimum(0);
1275 at(i).htest()->SetMinimum(0);
1276 }
1277 return;
1278 }
1279
1280
1281 double tmin = 0;
1282
1283 if ( lo!=hi ) tmin = realmin( lo, hi );
1284 else tmin = realmin();
1285
1286 m_min = scale*tmin;
1287
1288 for ( unsigned i=0 ; i<size() ; i++ ) {
1289 if ( at(i).href() ) at(i).href()->SetMinimum(scale*tmin);
1290 at(i).htest()->SetMinimum(scale*tmin);
1291 }
1292 }
1293
1294
1295 void Min( double scale ) {
1296 m_minset = true;
1297 for ( unsigned i=0 ; i<size() ; i++ ) {
1298 if ( at(i).href() ) at(i).href()->SetMinimum(scale);
1299 at(i).htest()->SetMinimum(scale);
1300 if ( m_logy ) {
1301 if ( at(i).href() ) if ( at(i).href()->GetMinimum()<=0 ) at(i).href()->GetMinimum(1e-4);
1302 if ( at(i).htest()->GetMinimum()<=0 ) at(i).htest()->GetMinimum(1e-4);
1303 }
1304 }
1305 }
1306
1307
1308 void Max( double scale ) {
1309 m_maxset = true;
1310 for ( unsigned i=0 ; i<size() ; i++ ) {
1311 if ( at(i).href() ) at(i).href()->SetMaximum(scale);
1312 at(i).htest()->SetMaximum(scale);
1313 }
1314 }
1315
1316 std::vector<double> findxrange( bool symmetric=false ) {
1317
1320
1321 std::vector<double> v(2,0);
1322
1323 TH1F* hf = at(0).htest();
1324
1325 double vlo = 1e21;
1326 double vhi = -1e21;
1327
1328 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1329 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1330
1331 if ( size()>0 ) v = ::findxrangeuser( hf, symmetric );
1332
1333 bool first = false;
1334
1335 for ( unsigned i=1 ; i<size() ; i++ ) {
1336
1337 hf = at(i).htest();
1338
1339 if ( ::empty( hf ) ) continue;
1340
1341 if ( hf->GetBinLowEdge(1)<vlo ) vlo = hf->GetBinLowEdge(1);
1342 if ( hf->GetBinLowEdge(hf->GetNbinsX()+1)>vhi ) vhi = hf->GetBinLowEdge( hf->GetNbinsX()+1 );
1343
1344 std::vector<double> limits = ::findxrangeuser( hf, symmetric );
1345
1346 double lo = limits[0];
1347 double hi = limits[1];
1348
1349 if ( first ) {
1350 v[0] = lo;
1351 v[1] = hi;
1352 }
1353 else {
1354 if ( v[0]>lo ) v[0] = lo;
1355 if ( v[1]<hi ) v[1] = hi;
1356 }
1357
1358 first = false;
1359 }
1360
1361 double upper = ( v[1]-v[0] )*1.1 + v[0];
1362 double lower = v[0] - ( v[1]-v[0] )*0.1;
1363
1364 if ( m_logx ) {
1365 double dx = std::log10(v[1])-std::log10(v[0]);
1366 upper = std::pow(10,dx*1.1 + std::log10(v[0]));
1367 lower = std::pow(10,std::log10(v[0]) - dx*0.1);
1368 }
1369
1370 if ( lower<vlo ) lower = vlo;
1371 if ( upper>vhi ) upper = vhi;
1372
1373 v[0] = lower;
1374 v[1] = upper;
1375
1376 return v;
1377 }
1378
1379
1380
1381 void sortx( const AxisInfo& xinfo ) {
1382
1383 if ( xinfo.rangeset() ) {
1384 std::cout << "xr1: " << xinfo << std::endl;
1385 m_lo = xinfo.lo();
1386 m_hi = xinfo.hi();
1387 }
1388
1389 if ( xinfo.autoset() && size() > 0 ) {
1390 std::vector<double> limits = findxrange( xinfo.symmetric() );
1391 if ( xinfo.rangeset() ) {
1392 std::cout << "xr2: " << xinfo << std::endl;
1393 if ( limits[0]<m_lo ) m_lo = limits[0];
1394 if ( limits[1]>m_hi ) m_hi = limits[1];
1395 }
1396 else {
1397 std::cout << "xr3: " << xinfo << std::endl;
1398 m_lo = limits[0];
1399 m_hi = limits[1];
1400 }
1401 }
1402 else if (size() == 0)
1403 {
1404 std::cout<<"Warning in computils.h::sortx() size=0. Setting m_lo/m_hi to 0/1. You will probably have empty figures."<<std::endl;
1405 m_lo = 0;
1406 m_hi = 1;
1407 }
1408
1409 if ( xinfo.rangeset() || xinfo.autoset() ) {
1411 if ( xinfo.log() && m_lo>0 ) SetLogx(true);
1412 else SetLogx(false);
1413 }
1414
1415 }
1416
1417
1418 double lo() const { return m_lo; }
1419 double hi() const { return m_hi; }
1420
1421
1422 void xrange(bool symmetric=false) {
1423 m_rangeset = false;
1424 for ( unsigned i=0 ; i<size() ; i++ ) {
1425 if ( at(i).href() ) ::xrange( at(i).href(), symmetric );
1426 ::xrange( at(i).htest(), symmetric );
1427 }
1428 }
1429
1430 void SetRangeUser( double lo, double hi ){
1431 m_rangeset = true;
1432 m_lo = lo;
1433 m_hi = hi;
1434 for ( unsigned i=0 ; i<size() ; i++ ) {
1435 if ( at(i).href() ) at(i).href()->GetXaxis()->SetRangeUser( m_lo, m_hi );
1436 at(i).htest()->GetXaxis()->SetRangeUser( m_lo, m_hi );
1437 at(i).SetRange(m_lo, m_hi);
1438 }
1439 }
1440
1441
1442 void limits() {
1443 double rmax = realmax();
1444 double rmin = realmin();
1445 if ( rmin<0 ) {
1446 std::cout << "\tlimits \t" << m_name << "\tmin " << rmin << "\tmax " << rmax << std::endl;
1447 }
1448 }
1449
1450
1451
1452 void Draw( Legend& leg, bool means=false ) {
1453 Draw_i( leg, means );
1454 if ( LINES ) {
1455 LINES=false;
1456 Draw_i( leg, means );
1457 LINES=true;
1458 }
1459 }
1460
1461 void Draw_i( Legend& leg, bool means=false ) {
1462
1463 bool first = true;
1464
1465#if 1
1466 if ( m_logy ) {
1467 for ( unsigned i=0 ; i<size() ; i++, first=false ) {
1468 double ymax = at(i).htest()->GetMaximum();
1469 double ymin = at(i).htest()->GetMinimum();
1470 at(i).htest()->GetYaxis()->SetMoreLogLabels(true);
1471 if ( ymax/ymin>1e6 ) at(i).htest()->GetYaxis()->SetMoreLogLabels(false);
1472 break;
1473 }
1474 }
1475#endif
1476
1477#if 1
1478 for ( unsigned i=0 ; i<size() ; i++ ) at(i).trim_errors( m_trim_errors );
1479
1482
1483#endif
1484
1485 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).Draw( i, &leg, means, first, (i==size()-1) );
1486 // for ( unsigned i=size() ; i-- ; first=false ) at(i).Draw( i, &leg, means, first, i==0 );
1487
1488 for ( unsigned i=size() ; i-- ; first=false ) at(i).Draw( i, &leg, means, first, i==0 );
1489
1490 // dev versions ...
1491 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).DrawLegend( i, leg, means, first, (i==size()-1) );
1492 // for ( unsigned i=0 ; i<size() ; i++, first=false ) at(i).Draw( i, &leg, means, first, i==size() );
1493
1494
1495
1496 if ( s_watermark ) DrawLabel(0.1, 0.02, "built "+stime()+release, kBlack, 0.03 );
1497
1498 gPad->SetLogy(m_logy);
1499 gPad->SetLogx(m_logx);
1500
1501 }
1502
1503 void SetLogx( bool b=true ) { m_logx=b; }
1504 void SetLogy( bool b=true ) { m_logy=b; }
1505
1506 std::string GetXaxisTitle() {
1507 if ( size()>0 ) return at(0).htest()->GetXaxis()->GetTitle();
1508 return "";
1509 }
1510
1511 std::string GetYaxisTitle() {
1512 if ( size()>0 ) return at(0).htest()->GetYaxis()->GetTitle();
1513 return "";
1514 }
1515
1516 void SetXaxisTitle(const std::string& s) {
1517 if ( size()>0 ) at(0).htest()->GetXaxis()->SetTitle(s.c_str());
1518 }
1519
1520 void SetYaxisTitle(const std::string& s) {
1521 if ( size()>0 ) at(0).htest()->GetYaxis()->SetTitle(s.c_str());
1522 }
1523
1524
1527 void push_back(const Plotter& val) {
1528 std::vector<Plotter>::push_back( val );
1529 }
1530
1531public:
1532
1533 static void setwatermark(bool b) { s_watermark = b; }
1534
1535private:
1536
1537 std::string m_name;
1538
1542
1545 double m_max;
1546
1548 double m_min;
1549
1552 double m_lo;
1553 double m_hi;
1554
1556
1557private:
1558
1559 static bool s_watermark;
1560
1561};
1562
1563
1564
1565
1567
1569
1570public:
1571
1572 HistDetails( const std::vector<std::string>& v ) : m_extra(""), m_xinfo(v[2]), m_yinfo(v[4]) {
1573 if ( v.size() < 6 ) throw std::exception();
1574 m_details.reserve(6);
1575 for ( size_t i=0 ; i<6 ; i++ ) m_details.push_back(v[i]);
1576 getextra();
1577 }
1578
1579 HistDetails( const std::string* vp ) : m_extra(""), m_xinfo(vp[2]), m_yinfo(vp[4]) {
1580 m_details.reserve(6);
1581 for ( size_t i=0 ; i<6 ; i++ ) m_details.push_back(vp[i]);
1582 getextra();
1583 }
1584
1585 const std::string& name() const { return m_details[0]; }
1586
1587 const std::string& detail() const { return m_extra; }
1588
1589 const std::string& info() const { return m_details[1]; }
1590
1591 const std::string& xtitle() const { return m_details[3]; }
1592 const std::string& ytitle() const { return m_details[5]; }
1593
1594 const AxisInfo& xaxis() const { return m_xinfo; }
1595 const AxisInfo& yaxis() const { return m_yinfo; }
1596
1597private:
1598
1599 void getextra() {
1600 if ( contains( m_details[0], "-" ) ) {
1601 m_extra = m_details[0].substr( m_details[0].find('-'), m_details[0].size() );
1602 m_details[0] = m_details[0].substr( 0, m_details[0].find('-') );
1603 }
1604 if ( contains( m_details[0], "+" ) ) {
1605 m_extra = m_details[0].substr( m_details[0].find('+'), m_details[0].size() );
1606 m_details[0] = m_details[0].substr( 0, m_details[0].find('+') );
1607 }
1608 }
1609
1610private:
1611
1612 std::vector<std::string> m_details;
1613
1614 std::string m_extra;
1615
1618
1619};
1620
1621
1622
1623inline std::ostream& operator<<( std::ostream& s, const HistDetails& h ) {
1624 return s << "[ " << h.name() << " \tx: \"" << h.xtitle() << "\" " << h.xaxis() << "\t\ty: \"" << h.ytitle() << "\" " << h.yaxis() << " ]";
1625}
1626
1627
1628
1629// plot panel inforamtion
1630
1631class Panel {
1632
1633public:
1634
1637 Panel( const std::string& s, int nc ) :
1638 m_name(s), m_nhist(-1), m_nrows(-1), m_ncols(nc) {
1639 m_hist.reserve( nc );
1640 }
1641
1643 Panel( const std::string& s, int nr, int nc ) :
1644 m_name(s), m_nhist(nr*nc), m_nrows(nr), m_ncols(nc) {
1645 m_hist.reserve( m_nhist );
1646 }
1647
1648 void push_back( const HistDetails& h ) {
1649 m_hist.push_back( h );
1650 m_nhist = m_hist.size();
1651 m_nrows = m_nhist/m_ncols + (m_nhist%m_ncols ? 1 : 0 );
1652 }
1653
1654 const std::string& name() const { return m_name; }
1655
1656 size_t size() const { return m_hist.size(); }
1657
1658 const HistDetails& operator[](int i) const { return m_hist.at(i); }
1659 HistDetails& operator[](int i) { return m_hist.at(i); }
1660
1661 const HistDetails& back() const { return m_hist.back(); }
1662 HistDetails& back() { return m_hist.back(); }
1663
1664 int nrows() const { return m_nrows; }
1665 int ncols() const { return m_ncols; }
1666
1667private:
1668
1669 std::string m_name;
1670
1672
1675
1676 std::vector<HistDetails> m_hist;
1677
1678};
1679
1680
1681
1682inline std::ostream& operator<<( std::ostream& s, const Panel& p ) {
1683 s << "Panel: " << p.name();
1684 if ( p.size() == 1 ) s << "\t" << p[0];
1685 else for ( size_t i=0 ; i<p.size() ; i++ ) s << "\n\t" << p[i];
1686 return s;
1687}
1688
1689
1690
1691
1692
1693#endif // COMPUTILS_H
int DrawLabel(float xstart, float ystart, string label)
int upper(int c)
static Double_t a
static Double_t sc
size_t size() const
Number of registered mappings.
#define y
#define x
static const Attributes_t empty
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
Header file for AthHistogramAlgorithm.
class to store information about axes, limits, whether it is log or linear scale etc
Definition computils.h:154
bool m_binwidth
Definition computils.h:320
bool autoset() const
Definition computils.h:256
bool m_autoset
Definition computils.h:310
double m_lo
Definition computils.h:314
bool symmetric() const
Definition computils.h:262
double binwidth() const
Definition computils.h:279
bool rangeset() const
Definition computils.h:264
bool refnormset() const
Definition computils.h:260
bool trim() const
Definition computils.h:266
bool m_norm
Definition computils.h:317
double hi() const
Definition computils.h:273
double hi(double x)
Definition computils.h:276
bool log() const
Definition computils.h:254
AxisInfo(const std::string &s)
Definition computils.h:158
double m_offset
Definition computils.h:322
bool m_log
Definition computils.h:309
static std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition computils.h:285
bool m_symmetric
Definition computils.h:311
double offset() const
Definition computils.h:269
bool m_rangeset
Definition computils.h:313
double m_hi
Definition computils.h:315
const std::string & c_str() const
Definition computils.h:281
std::string m_info
Definition computils.h:305
const std::string & tag() const
accessors
Definition computils.h:252
double lo(double x)
Definition computils.h:275
bool normset() const
Definition computils.h:258
bool m_trim
Definition computils.h:324
double lo() const
Definition computils.h:272
std::string m_tag
Definition computils.h:307
bool m_refnorm
Definition computils.h:318
details of the histogram axes etc
Definition computils.h:1568
AxisInfo m_xinfo
Definition computils.h:1616
const AxisInfo & xaxis() const
Definition computils.h:1594
const std::string & info() const
Definition computils.h:1589
const std::string & ytitle() const
Definition computils.h:1592
std::vector< std::string > m_details
Definition computils.h:1612
std::string m_extra
Definition computils.h:1614
const std::string & name() const
Definition computils.h:1585
const std::string & xtitle() const
Definition computils.h:1591
HistDetails(const std::vector< std::string > &v)
Definition computils.h:1572
void getextra()
Definition computils.h:1599
const std::string & detail() const
Definition computils.h:1587
HistDetails(const std::string *vp)
Definition computils.h:1579
AxisInfo m_yinfo
Definition computils.h:1617
const AxisInfo & yaxis() const
Definition computils.h:1595
slightly more convenient legend class
Definition computils.h:344
std::vector< TObject * > m_obj
Definition computils.h:432
~Legend()
Definition computils.h:369
void Draw()
Definition computils.h:391
TLegend * m_leg
Definition computils.h:427
std::vector< std::string > m_entries
Definition computils.h:433
int TextFont() const
Definition computils.h:379
Legend(double x1, double x2, double y1, double y2)
Definition computils.h:355
double m_y[2]
Definition computils.h:430
double width() const
Definition computils.h:383
double TextSize() const
Definition computils.h:377
void AddEntry(TObject *tobj, const std::string &s, const std::string &type="p")
Definition computils.h:385
double height() const
Definition computils.h:381
size_t size() const
Definition computils.h:373
double m_x[2]
Definition computils.h:429
TLegend * legend()
Definition computils.h:371
Legend(const Legend &legend)
Definition computils.h:365
std::vector< std::string > m_type
Definition computils.h:434
void push_back(const HistDetails &h)
Definition computils.h:1648
HistDetails & back()
Definition computils.h:1662
int ncols() const
Definition computils.h:1665
Panel(const std::string &s, int nc)
don't know how many rows or total hists yet, but do know number of columns
Definition computils.h:1637
int m_nrows
Definition computils.h:1673
std::vector< HistDetails > m_hist
Definition computils.h:1676
size_t size() const
Definition computils.h:1656
const std::string & name() const
Definition computils.h:1654
HistDetails & operator[](int i)
Definition computils.h:1659
std::string m_name
Definition computils.h:1669
const HistDetails & operator[](int i) const
Definition computils.h:1658
int m_ncols
Definition computils.h:1674
Panel(const std::string &s, int nr, int nc)
know number of rows and columns
Definition computils.h:1643
int m_nhist
Definition computils.h:1671
const HistDetails & back() const
Definition computils.h:1661
int nrows() const
Definition computils.h:1664
void sortx(const AxisInfo &xinfo)
Definition computils.h:1381
double hi() const
Definition computils.h:1419
static bool s_watermark
Definition computils.h:1559
double m_hi
Definition computils.h:1553
void xrange(bool symmetric=false)
Definition computils.h:1422
double realmax(double lo=0, double hi=0)
Definition computils.h:1235
double m_lo
Definition computils.h:1552
void Max(double scale)
Definition computils.h:1308
double m_min
Definition computils.h:1548
void Draw_i(Legend &leg, bool means=false)
Definition computils.h:1461
void SetXaxisTitle(const std::string &s)
Definition computils.h:1516
void limits()
Definition computils.h:1442
void MaxScale(double scale=1.1, double lo=0, double hi=0)
Definition computils.h:1249
std::vector< double > findxrange(bool symmetric=false)
Definition computils.h:1316
double lo() const
Definition computils.h:1418
bool m_maxset
yaxis range setting
Definition computils.h:1544
void push_back(const Plotter &val)
this is so that we can update the stats as we go along, but no updating isn't done at the moment
Definition computils.h:1527
bool m_trim_errors
Definition computils.h:1555
void Min(double scale)
Definition computils.h:1295
Plots(const std::string &s="", bool errors=false)
Definition computils.h:1214
double realmin(double lo=0, double hi=0)
Definition computils.h:1224
void Draw(Legend &leg, bool means=false)
Definition computils.h:1452
std::string GetYaxisTitle()
Definition computils.h:1511
bool m_logy
Definition computils.h:1541
bool m_logx
canvas log setting
Definition computils.h:1540
void MinScale(double scale, double lo=0, double hi=0)
Definition computils.h:1268
bool m_rangeset
xaxis range setting
Definition computils.h:1551
double m_max
Definition computils.h:1545
void SetLogy(bool b=true)
Definition computils.h:1504
void SetLogx(bool b=true)
Definition computils.h:1503
void SetYaxisTitle(const std::string &s)
Definition computils.h:1520
std::string m_name
Definition computils.h:1537
bool m_minset
Definition computils.h:1547
std::string GetXaxisTitle()
Definition computils.h:1506
void SetRangeUser(double lo, double hi)
Definition computils.h:1430
static void setwatermark(bool b)
Definition computils.h:1533
virtual const char * what() const
Definition computils.h:107
data_mismatch(const std::string &s)
Definition computils.h:106
generic plotter class - better to have one of these - make sure it can be configured however you like...
Definition computils.h:467
~tPlotter()
sadly, root manages all the histograms (does it really?
Definition computils.h:503
const std::string & plotfilename() const
Definition computils.h:512
tPlotter(T *fo_htest=0, T *fo_href=0, const std::string &s="", TGraphAsymmErrors *fo_tgtest=0, TGraphAsymmErrors *fo_tgref=0)
Definition computils.h:471
bool mc() const
Definition computils.h:1128
bool trim_errors() const
Definition computils.h:516
double xhi() const
Definition computils.h:510
void Draw(int i, Legend *lleg, bool mean=false, bool first=true, bool drawlegend=false)
Definition computils.h:520
tPlotter(const tPlotter &p)
Definition computils.h:485
void xaxis(const AxisInfo *a)
Definition computils.h:1140
void DrawLegend(int i, Legend &leg, bool mean=false, bool first=true, bool drawlegend=false)
Definition computils.h:943
void xhi(double x)
Definition computils.h:507
const AxisInfo * m_yaxis
Definition computils.h:1174
void SetRange(double lo, double hi)
Definition computils.h:518
TGraphAsymmErrors * tgref()
Definition computils.h:1131
void max_entries(int i)
Definition computils.h:1133
std::string m_plotfilename
Definition computils.h:1155
static bool s_meanplotref
Definition computils.h:1158
void Print(const std::string &s="")
print the output
Definition computils.h:1118
const AxisInfo * yaxis() const
Definition computils.h:1144
TGraphAsymmErrors * m_tgtest
Definition computils.h:1152
static void setplotref(bool b)
Definition computils.h:1137
void yaxis(const AxisInfo *a)
Definition computils.h:1141
bool mc(bool b)
Definition computils.h:1126
T * href()
Definition computils.h:1124
T * htest()
Definition computils.h:1123
double xlo() const
Definition computils.h:509
static void setmeanplotref(bool b)
Definition computils.h:1138
static bool s_plotref
Definition computils.h:1157
TGraphAsymmErrors * tgtest()
Definition computils.h:1130
const AxisInfo * xaxis() const
Definition computils.h:1143
void trim_errors(bool b)
Definition computils.h:514
const AxisInfo * m_xaxis
Definition computils.h:1173
void xlo(double x)
Definition computils.h:506
TGraphAsymmErrors * m_tgref
Definition computils.h:1153
true_mean(TH1F *h)
double error() const
Definition computils.h:141
double m_mean
Definition computils.h:145
double m_error
Definition computils.h:146
double mean() const
Definition computils.h:140
bool LINES
Definition computils.cxx:41
int markers[6]
Definition computils.cxx:49
bool LINEF
Definition computils.cxx:40
int colours[6]
Definition computils.cxx:48
bool JLflag
Definition computils.cxx:44
double msizes[6]
Definition computils.cxx:50
double plotable(TH1 *h)
void xrange(TH1 *h, bool symmetric=true)
std::ostream & operator<<(std::ostream &s, std::vector< T > &v)
Definition computils.h:113
bool contains(const std::string &s, const std::string &p)
does a string contain the substring
Definition hcg.cxx:116
double realmin(TH1 *h, bool include_error=true, double lo=0, double hi=0)
void copyReleaseInfo(TFile *finput, TFile *foutdir)
copy the TTree of release info from one directory to another
bool LINES
Definition computils.cxx:41
void zeroErrors(T *)
Definition computils.h:456
void band_plot(TH1 *h, double xlo, double xhi, double ylo=-999, double yhi=-999)
std::string stime()
return the current data and time
bool empty(TH1 *h)
void Norm(TH1 *h, double scale=1, double xmin=0, double xmax=0)
std::string globbed(const std::string &s)
match a file name
double Entries(TH1 *h)
std::string findcell(std::string name, const std::string &regex, const std::string &splitex="/")
std::string findrun(TFile *f)
void ATLASFORAPP_LABEL(double x, double y, int color, double size=0.06)
bool exists(const std::string &filename)
does a file exist
std::string tail(std::string s, const std::string &pattern)
tail of a string
tPlotter< TH1F > Plotter
Definition computils.h:1179
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory="", const std::string &pattern="", const std::string &path="")
static std::string release
Definition computils.h:54
std::vector< int > findxrange(TH1 *h, bool symmetric=false)
automatically set the xrange on a histogram
double integral(TH1 *h)
double realmax(TH1 *h, bool include_error=true, double lo=0, double hi=0)
void trim_tgraph(TH1 *h, TGraphAsymmErrors *t)
void hminus(TH1 *h)
Definition computils.h:1196
void setParameters(T *h, TGraphAsymmErrors *tg)
Definition computils.h:445
void myText(Double_t x, Double_t y, Color_t color, const std::string &text, Double_t tsize)
std::string head(std::string s, const std::string &pattern)
head of a string
bool fcontains(const std::string &s, const std::string &p)
does a string contain the substring at the beginning of the string
std::vector< double > findxrangeuser(TH1 *h, bool symmetric=false)
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 ir
counter of the current depth
Definition fastadd.cxx:49
std::vector< std::string > tags
Definition hcg.cxx:107
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
std::string chop(std::string &s1, const std::string &s2)
Definition hcg.cxx:163
std::string label(const std::string &format, int i)
Definition label.h:19
double xmax
Definition listroot.cxx:61
double ymin
Definition listroot.cxx:63
double xmin
Definition listroot.cxx:60
std::vector< std::string > patterns
Definition listroot.cxx:187
double ymax
Definition listroot.cxx:64