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