ATLAS Offline Software
Loading...
Searching...
No Matches
comparitor.cxx
Go to the documentation of this file.
1
9
10// cppcheck-suppress-file stlIfStrFind; cannot use C++20 starts_with in this standalone code
11
12
13#include <cstdio>
14#include <cmath>
15#include <cstdlib>
16#include <sys/time.h>
17#include <sys/stat.h>
18#include <sys/types.h>
19
20#include <iostream>
21#include <string>
22#include <vector>
23#include <set>
24#include <algorithm>
25#include <regex>
26
28
29#include "ReadCards.h"
30
31#include "Resplot.h"
32#include "utils.h"
33#include "label.h"
34#include "DrawLabel.h"
35
36#include "TFile.h"
37#include "TTree.h"
38#include "TString.h"
39#include "TH2F.h"
40#include "TH1D.h"
41#include "TPad.h"
42#include "TCanvas.h"
43#include "TLegend.h"
44#include "TStyle.h"
45#include "TF1.h"
46#include "TPave.h"
47#include "TPaveStats.h"
48#include "TEfficiency.h"
49#include "TColor.h"
50
51#include "computils.h"
52
53#include "AtlasStyle.h"
54#include "AtlasLabels.h"
55
56#include "default_panels.h"
57
58#include "TError.h"
59
60
61const std::string reset = "\033[0m";
62const std::string red = "\033[0;31m";
63const std::string green = "\033[0;32m";
64
65bool fulldbg = false;
66
67extern bool LINEF;
68extern bool LINES;
69
70bool EPS = false;
71
72
73
74void normaliseBinWidth( TH1* h ) {
75
76 if ( !h ) return;
77
78 int nbins = h->GetNbinsX();
79 double width = h->GetBinWidth(1);
80
81 double eps = 1e-12;
82
83 bool variable = false;
84
85 for ( int i=2 ; i<=nbins ; i++ ) {
86 if ( std::fabs( h->GetBinWidth(i)-width )>eps ) {
87 variable = true;
88 break;
89 }
90 }
91
92 if ( !variable ) return;
93
94 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
95 double w = h->GetBinWidth(i);
96 h->SetBinContent( i, h->GetBinContent(i)/w );
97 h->SetBinError( i, h->GetBinError(i)/w );
98 }
99
100}
101
102
103
104
105void testfit( TH1* htest, const std::string& s ) {
106
107 if ( htest && s.find("invmass")!=std::string::npos ) {
108
109 TVirtualPad* p = gPad;
110
111 TCanvas canv("canv", "", 700, 600 );
112 canv.cd();
113
114 std::cout << "testfit: s" << s << "\t" << htest << std::endl;
115
116 // TF1 finv( "inv", "pow([0]*exp( (x-[1])*([1]-x)/([2]*[2]) ), [6]) + [3]+x*([4]+x*[5])" );
117 TF1 finv( "inv", "pow([0]/([2]+([1]-x)*([1]-x)), [6]) + [3]+x*([4]+x*[5])" );
118
119 finv.SetParameter(0, 10000);
120 finv.SetParameter(1, 91);
121 finv.SetParameter(2, 7);
122 finv.SetParameter(3, 1000);
123 finv.SetParameter(4, 0.01);
124 finv.SetParameter(5, 0);
125 finv.SetParameter(6, 1);
126
127 finv.SetLineWidth(1);
128
129 htest->Fit( &finv, "", "", 55, 130 );
130
131 static int i = 0;
132
133 htest->GetXaxis()->SetRangeUser(55,125);
134 htest->DrawCopy("e1");
135
136 gPad->Print( ("invmass-"+std::to_string(i++)+".pdf").c_str() );
137
138 std::cout << "inv mass: " << finv.GetParameter(1) << " +- " << finv.GetParError(1) << std::endl;
139
140 p->cd();
141
142 }
143
144}
145
146
147double total_eff( TH1* hn, TH1* hd ) {
148 double n = 0;
149 double d = 0;
150
151 for ( int i=0 ; i<=hn->GetNbinsX()+1 ; i++ ) n += hn->GetBinContent(i);
152 for ( int i=0 ; i<=hd->GetNbinsX()+1 ; i++ ) d += hd->GetBinContent(i);
153
154 std::cout << "num: " << n << "\tden: " << d << "\t";
155
156 if ( d!=0 ) return (n/d);
157
158 return 0;
159}
160
161
162
163extern int colours[6];
164extern int markers[6];
165
166TCanvas* fitcanvas = 0;
167TCanvas* fitcanvas_rec = 0;
168
169std::string eround( double x, int decfigs=4 ) {
170 char ss[1024];
171 std::string s= "%" + std::to_string(decfigs+2) + "." + std::to_string(decfigs) + "lf";
172 std::sprintf( ss, s.c_str(), x );
173 return ss;
174}
175
176
177void arsaway( std::string& s, const std::string& pattern, const std::string& rep ) {
178 std::regex regexPattern(pattern);
179 s = std::regex_replace( s, regexPattern, rep );
180}
181
182
183
184
185TH1F* trans( TH1F* h, bool t=false ) {
186
187 std::cout << "trans in" << std::endl;
188
189 if ( !t ) return h;
190
191 std::cout << "trans processing ..." << std::endl;
192
193 h->SetDirectory(0);
194
195 std::vector<double> xlim( h->GetNbinsX()+1 );
196
197 for ( int i=0 ; i<h->GetNbinsX()+1 ; i++ ) {
198 xlim[i] = h->GetBinLowEdge(i+1)*(1-0.054);
199 }
200
201 TH1F* hn = new TH1F( (std::string(h->GetName())+"-transx").c_str(), h->GetTitle(), h->GetNbinsX(), &xlim[0] );
202 hn->SetDirectory(0);
203
204 hn->SetLineStyle(h->GetLineStyle());
205 hn->SetLineColor(h->GetLineColor());
206 hn->SetLineWidth(h->GetLineWidth());
207 hn->SetMarkerStyle(h->GetMarkerStyle());
208 hn->SetMarkerColor(h->GetMarkerColor());
209 hn->SetMarkerSize(h->GetMarkerSize());
210
211 for ( int i=0 ; i<h->GetNbinsX() ; i++ ) {
212 if ( hn->GetBinLowEdge(i)<14 ) continue;
213 hn->SetBinContent( i+1, h->GetBinContent( i+1 ) );
214 hn->SetBinError( i+1, h->GetBinError( i+1 ) );
215 }
216
217 delete h;
218
219 return hn;
220
221}
222
223
224
225
226void SetZeros( TH2D* h ) {
227 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
228 for ( int j=1 ; j<=h->GetNbinsY() ; j++ ) {
229 int ibin = h->GetBin( i, j );
230 if ( h->GetBinContent(ibin)==0 ) h->SetBinContent(ibin, 0.1);
231 }
232 }
233}
234
235void Scale( TH1* h, double d=1 ) {
236 if ( d==1 ) return;
237 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
238 h->SetBinContent( i, h->GetBinContent(i)*d );
239 h->SetBinError( i, h->GetBinError(i)*d );
240 }
241}
242
243
244TH1F* Rebin( TH1F* h, double f ) {
245
246 std::cout << "\nREBIN: " << h->GetName() << " :: " << f << std::endl;
247
248 if ( int(f) == f ) {
249 TH1F* n = (TH1F*)h->Clone((std::string(h->GetName())+"-foeda").c_str()); n->SetDirectory(0);
250 n->Rebin(int(f));
251 return n;
252 }
253
254 int fi=int(f);
255 double fb=(f-fi);
256
257 for ( int i=0 ; i<10 ; i++ ) {
258 fb *= 10;
259 if ( std::fabs(int(fb)-fb)<1e-6 ) break;
260 }
261
262 std::vector<double> limits;
263 std::vector<double> contents;
264
265 for ( int i=1 ; i<=h->GetNbinsX()+1 ; i++ ) {
266 limits.push_back( h->GetBinLowEdge(i) );
267 contents.push_back( h->GetBinContent(i) );
268 if ( i<fb ) {
269 for ( int ib=1 ; ib<fi ; ib++ ) contents.back() += h->GetBinContent(++i);
270 }
271 }
272
273 TH1F* n = new TH1F( "foeda", h->GetTitle(), limits.size()-1, &limits[0] ); n->SetDirectory(0);
274
275 for ( size_t i=0 ; i<contents.size() ; i++ ) n->SetBinContent( i+1, contents[i] );
276
277 return n;
278}
279
280
281
282
283TH1F* rebin_log( TH1F* h, bool low=false ) {
284
285 double limits[40] = {
286 0.5, 1.5, 2.5, 3.5, 4.5,
287 5.5, 6.5, 7.5, 8.5, 9.5,
288 10.5, 11.5, 12.5, 13.5, 14.5,
289 15.5, 16.5, 17.5, 18.5, 19.5,
290 20.5, 21.5, 22.5, 23.5, 24.5,
291 25.5, 26.5, 28.5, 30.5, 32.5,
292 35.5, 38.5, 42.5, 46.5, 50.5,
293 55.5, 60.5, 66.5, 72.5, 78.5
294 };
295
296 double lowlimits[24] = {
297 0.5, 1.5, 2.5, 3.5, 4.5,
298 5.5, 6.5, 7.5, 8.5, 9.5,
299 10.5, 11.5, 12.5, 14.5, 17.5,
300 20.5, 24.5, 29.5, 35.5, 42.5,
301 50.5, 60.5, 72.5, 86.5,
302 };
303
304 TH1F* n;
305
306 if ( low ) n = new TH1F( "foeda", h->GetTitle(), 39, limits );
307 else n = new TH1F( "foeda", h->GetTitle(), 23, lowlimits );
308
309 n->SetDirectory(0);
310
311 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
312 n->Fill( h->GetBinCenter(i), h->GetBinContent(i) );
313 }
314
315
316 for ( int i=1 ; i<=n->GetNbinsX() ; i++ ) {
317 n->SetBinError(i, std::sqrt( n->GetBinContent(i) ) );
318 }
319
320 return n;
321}
322
323
328
329typedef std::map<std::string,std::string> chainmap_t;
330
331
335
336template<typename T=TH1F>
337T* Get( TFile& f, const std::string& n, const std::string& dir="",
338 const chainmap_t* chainmap=0, std::vector<std::string>* saved=0 ) {
339
340 std::cout << "\n\nGet: " << n << "\tdir: " << dir << "\tchainmap: " << chainmap << std::endl;
341
342 std::string name;
343
344 size_t pos = n.find('+');
345 if ( pos!=std::string::npos ) name = n.substr( 0, pos );
346 else name = n;
347
348 std::cout << "name: " << name << "\t(file: " << f.GetName() << ")" << std::endl;
349
350 T* h = (T*)f.Get( name.c_str() );
351
352 bool printed = false;
353
354 if ( h || dir.empty() || name.find(dir)!=std::string::npos ) {
355 std::cout << "Get() name 0 " << name << " :: " << h << std::endl;
356 printed = true;
357 }
358 else {
359 std::string fname = dir+'/'+name;
360 h = (T*)f.Get( fname.c_str() );
361 // std::cout << "Get() name 1 " << name << " :: " << h << std::endl;
362 }
363
364 if ( h == 0 ) {
365 if ( chainmap && chainmap->size()!=0 ) {
366 for ( chainmap_t::const_iterator itr=chainmap->begin() ; itr!=chainmap->end() ; itr++ ) { //cppcheck-suppress postfixOperator
367 if ( contains( name, itr->first ) ) {
368
369 std::cout << "\tmatch: " << itr->first << " -> " << itr->second << std::endl;
370
371 name.replace( name.find(itr->first), itr->first.size(), itr->second );
372
373 h = (T*)f.Get( name.c_str() );
374
375 if ( h==0 ) {
376 if ( name.find(dir)==std::string::npos ) name = dir + "/" + name;
377
378 h = (T*)f.Get( name.c_str() );
379 }
380
381 break;
382 }
383 }
384 }
385 }
386
387
388 if ( ! printed ) {
389 std::cout << "Get() name 1 " << name << " :: " << h << std::endl;
390 }
391
392
393 if ( saved ) saved->push_back( name );
394
395
396 if ( h && std::string(h->ClassName()).find("TEfficiency")==std::string::npos ) {
397 std::cout << "TH " << h->GetName() << std::endl;
398 if ( h ) h->SetDirectory(0);
399 }
400
401
402 return h;
403}
404
405
406template<typename T>
407bool isTEfficiency( T* h ) {
408 if ( h && std::string(h->ClassName()).find("TEfficiency")!=std::string::npos ) return true;
409 return false;
410}
411
412
413
414class bands {
415
416public:
417
418 bands() { }
419
420 bands( const bands& b ) = default;
421 bands& operator= ( const bands& b ) = default;
422
423 bands( const std::vector<double>& limits, const std::vector<std::string>& labels )
424 : m_limits(limits), m_labels(labels)
425 { }
426
427 void range( const std::string& chain, TH1F* h ) {
428 for ( size_t i=0 ; i<m_labels.size() ; i++ ) {
429 if ( chain.find(m_labels[i])!=std::string::npos ) return range( i, h );
430 }
431 return range( m_labels.size(), h );
432 }
433
434
435 void range( size_t i, TH1F* h ) {
436
437 double minx = h->GetBinLowEdge(1);
438 double maxx = h->GetBinLowEdge(h->GetNbinsX()+1);
439
440 if ( i>=m_limits.size() ) { maxx+=1; minx=maxx; }
441 else if ( (i+1)==m_limits.size() ) minx=m_limits[i];
442 else {
443 minx = m_limits[i];
444 maxx = m_limits[i+1];
445 }
446
447
448 for ( int j=1 ; j<=h->GetNbinsX() ; j++ ) {
449
450 std::cout << "range: " << j << "\tminx: " << minx << "\t" << maxx << std::endl;
451 if ( ! ( h->GetBinCenter(j)>=minx && h->GetBinCenter(j)<maxx ) ) {
452 h->SetBinContent(j,0);
453 h->SetBinError(j,0);
454 }
455 }
456 }
457
458
459private:
460
461 std::vector<double> m_limits;
462 std::vector<std::string> m_labels;
463
464};
465
466
467TH1F* d0rebin( TH1F* h ) {
468
469 return h;
470
471 std::vector<double> limits;
472
473 for ( int i=1 ; i<h->GetNbinsX() ; i++ ) {
474 limits.push_back( h->GetBinLowEdge(i) );
475 }
476
477 std::vector<double> alimits;
478 std::vector<double> nlimits;
479
480 double x = 0;
481
482 // for ( int i=0 ; x<20 ; i++ ) {
483 while ( x<20 ) {
484
485 alimits.push_back(x);
486
487#if 0
488 if ( x<0.5 ) x+=0.2;
489 else if ( x<1.0 ) x+=0.2;
490 else if ( x<1.5 ) x+=0.3;
491 else if ( x<2.0 ) x+=0.4;
492 else if ( x<2.5 ) x+=0.5;
493 else x+=0.6;
494#else
495 if ( x<0.5 ) x+=0.1;
496 else if ( x<1.0 ) x+=0.2;
497 else if ( x<1.5 ) x+=0.2;
498 else if ( x<2.0 ) x+=0.2;
499 else if ( x<2.5 ) x+=0.2;
500 else if ( x<3.0 ) x+=0.3;
501 else x+=0.3;
502#endif
503
504 }
505
506 for ( size_t i=alimits.size() ; i-- ; ) {
507 if ( alimits[i]<=15 ) nlimits.push_back( -alimits[i] );
508 }
509
510 for ( size_t i=1 ; i<alimits.size() ; i++ ) {
511 if ( alimits[i]<=15 ) nlimits.push_back( alimits[i] );
512 }
513
514 std::cout << "limits: " << limits.size() << " " << nlimits.size() << std::endl;
515
516 TH1F* hnew = new TH1F( "h", h->GetTitle(), nlimits.size()-1, &nlimits[0] );
517
518 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
519 double d = h->GetBinCenter(i);
520 int j = hnew->FindBin( d );
521 hnew->SetBinContent( j, hnew->GetBinContent(j)+h->GetBinContent(i) );
522 }
523
524 return hnew;
525}
526
527
528
529
530int usage(const std::string& name, int status, const std::string& err_msg="" ) {
531 if ( err_msg != "" ) std::cerr << err_msg << "\n" << std::endl;
532 std::ostream& s = std::cout;
533 s << "Usage: " << name << "\t [OPTIONS] test.root reference.root chain1 chain2 chain2 ...\n\n";
534 s << "\t" << " plots comparison histograms";
535 s << " - compiled on " << __DATE__ << " at " << __TIME__ << "\n\n";
536 s << "Options: \n";
537 s << " -c, --config value \t configure which histograms to plot from config file,\n\n";
538 s << " -t, --tag value \t appends tag 'value' to the end of output plot names, \n";
539 s << " -k, --key value \t prepends key 'value' to the front of output plots name, \n";
540 s << " -t, --tag value \t post pend tag 'value' to the end of output plots name, \n";
541 s << " -d, --dir value \t creates output files into directory, \"value\" \n\n";
542 s << " --ncols value \t creates panels with \"value\" columns\n\n";
543
544 s << " -e, --efficiencies \t make test efficiencies with respect to reference \n";
545 s << " -es, --effscale value \t scale efficiencies to value\n";
546 s << " -er, --effscaleref value \t scale reference efficiencies to value\n";
547 s << " -nb --nobayes \t do not calculate Basyesian efficiency uncertaintiesr\n\n";
548
549 s << " -r, --refit \t refit all test resplots\n";
550 s << " -rr, --refitref \t also refit all reference resplots\n";
551 s << " --oldrms \t use fast rms95 when refitting resplots\n\n";
552
553 s << " -as, --atlasstyle \t use ATLAS style\n";
554 s << " -l, --labels values\t use specified labels for key\n";
555 s << " --taglabels values\t use specified additional labels \n";
556 s << " -al, --atlaslable value \t set value for atlas label\n";
557 s << " -sx, --swapaxtitles exp pattern\t swap the expression \"exp \" in the axis titles with \"pattern\"\n";
558 s << " -ac, --addchains \t if possible, add chain names histogram labels \n\n";
559
560 s << " -m, --mapfile \t remap file for reference histograms \n\n";
561
562 s << " -rc, --refchains values ..\t allow different reference chains for comparison\n";
563 s << " -s, --swap pattern regex \t swap \"pattern\" in the chain names by \"regex\"\n";
564 s << " --swapr pattern regex \t swap \"pattern\" in the ref chain names by \"regex\"\n";
565 s << " --swapt pattern regex \t swap \"pattern\" in the test chain names by \"regex\"\n";
566 s << " -nr, --noref \t do not plot reference histograms\n";
567 s << " --normref \t normalise the reference counting histograms to test histograms\n";
568 s << " -us, --usechainref \t use the histograms from chain definied in the \"Chain\" histogram as reference\n\n";
569 s << " --lumi \t scale pile-up mu values down by 5.4%\n";
570 s << " --lumitest \t scale pile-up mu values down by 5.4% for test histograms\n";
571 s << " --lumiref \t ecale pile-up mu values down by 5.4% for reference histograms\n\n";
572
573 s << " -ns, --nostats \t do not show stats for mean and rms\n";
574 s << " -nm, --nomeans \t do not show stats for the means\n";
575 s << " --means \t show stats for the means\n";
576 s << " --chi2 \t show the chi2 with respect to the reference\n\n";
577
578 s << " -np, --noplots \t do not actually make any plot\n";
579 s << " -q, --quiet \t make the plots but do not print them out\n\n";
580
581 s << " --unscalepix \t do not scale the number of pixels by 0.5 (unscaled by default)\n";
582 s << " --scalepix \t do scale the number of pixels by 0.5 (unscaled by default)\n";
583 s << " --yrange min max \t use specified y axis range\n";
584 s << " -xo, --xoffset value \t relative x offset for the key\n";
585 s << " -yp, --ypos value \t relative yposition for the key\n";
586 s << " -xe, --xerror value \t size of the x error tick marks\n";
587 s << " -nw, --nowatermark \t do not plot the release watermark\n\n";
588
589 s << " -C, --Cfiles \t write C files also\n";
590 s << " --eps \t create eps files\n";
591 s << " --nopng \t do not print png files\n";
592 s << " --nopdf \t do not print pdf files\n";
593 s << " --deleteref \t delete unused reference histograms\n\n";
594
595 s << " --printconfig \t print the configuration being used in the form useable as an input file\n\n";
596
597 s << " --run value \t print the run number on the plot\n\n";
598
599 s << " -h, --help \t this help\n";
600 // s << "\nSee " << PACKAGE_URL << " for more details\n";
601 // s << "\nReport bugs to <" << PACKAGE_BUGREPORT << ">";
602 s << std::endl;
603 return status;
604}
605
606
607void binwidth( TH1F* h ) {
608 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
609 double w = h->GetBinLowEdge(i+1) - h->GetBinLowEdge(i);
610 h->SetBinContent( i, h->GetBinContent(i)/w );
611 h->SetBinError( i, h->GetBinError(i)/w );
612 }
613}
614
615void ascale( TH1F* h, double s_ ) {
616 for ( int i=1 ; i<=h->GetNbinsX() ; i++ ) {
617 h->SetBinContent( i, h->GetBinContent(i)*s_ );
618 h->SetBinError( i, h->GetBinError(i)*s_ );
619 }
620}
621
622
623
624// replace from a string
625std::string fullreplace( std::string s, const std::string& s2, const std::string& s3) {
626 if ( s2=="" || s2==s3 ) return s;
627 std::string::size_type pos;
628 while ( (pos=s.find(s2)) != std::string::npos ) s.replace(pos, s2.size(), s3);
629 return s;
630}
631
632void print_pad( const std::string& s ) {
633 std::cout << green << "Printing " << s << reset << std::endl;
634 gPad->Print( s.c_str() );
635 if ( EPS ) gPad->Print( (s+".eps").c_str() );
636}
637
638
639TH1F* makeplot( TObject* hreft ) {
640
641 TH1F* href = 0; // (TH1F*)hreft->Clone();
642
643 if ( isTEfficiency( hreft ) ) {
644
645 TH1F* hn = (TH1F*)dynamic_cast<TEfficiency*>(hreft)->GetPassedHistogram();
646 TH1F* hd = (TH1F*)dynamic_cast<TEfficiency*>(hreft)->GetTotalHistogram();
648 // TH1F* hn = (TH1F*)((TEfficiency*)hreft)->GetPassedHistogram();
649 // TH1F* hd = (TH1F*)((TEfficiency*)hreft)->GetTotalHistogram();
650
651 // hd->DrawCopy();
652 // gPad->SetLogy(true);
653 // gPad->Print("den.pdf");
654
655 // hn->DrawCopy("same");
656 // gPad->SetLogy(true);
657 // gPad->Print("num.pdf");
658
659 href = (TH1F*)hn->Clone("ars"); href->SetDirectory(0);
660 for ( int ie=1 ; ie<=href->GetNbinsX() ; ie++ ) {
661 if ( hd->GetBinContent(ie)==0 ) { href->SetBinContent( ie, 0 ); href->SetBinError( ie, 0 ); }
662 else {
663 double e = hn->GetBinContent(ie)/hd->GetBinContent(ie);
664 double ee = e*(1-e)/hn->GetBinContent(ie);
665 //if (e>1) e=1;
666 href->SetBinContent( ie, e );
667 href->SetBinError( ie, ee );
668 }
669 }
670 }
671
672 // if ( href) href->DrawCopy();
673 // gPad->SetLogy(false);
674 // gPad->Print("plot.pdf");
675
676 return href;
677}
678
679
680
681
683void zero( TH2* h ) {
684 int Nx = h->GetNbinsX();
685 int Ny = h->GetNbinsY();
686 for ( int i=1 ; i<=Nx ; i++ ) {
687 for ( int j=1 ; j<=Ny ; j++ ) {
688 if ( h->GetBinContent( i, j )==0 ) {
689 h->SetBinContent( i, j, 1e-10 );
690 h->SetBinError( i, j, 1e-10 );
691 }
692 }
693 }
694}
695
696
698void normy( TH2* h ) {
699 int Nx = h->GetNbinsX();
700 int Ny = h->GetNbinsY();
701 for ( int i=1 ; i<=Nx ; i++ ) {
702 double n = 0;
703 for ( int j=1 ; j<=Ny ; j++ ) n += h->GetBinContent(i,j);
704 if ( n>0 ) for ( int j=1 ; j<=Ny ; j++ ) h->SetBinContent( i, j, h->GetBinContent(i,j)/n );
705 }
706}
707
708
710void autox( TH2* h, bool t=false ) {
711
712 int Nx = h->GetNbinsX();
713 int Ny = h->GetNbinsY();
714
715 double xhi = h->GetXaxis()->GetBinLowEdge(1);
716 double xlo = h->GetXaxis()->GetBinLowEdge( h->GetXaxis()->GetNbins() );
717
718 for ( int i=1 ; i<=Nx ; i++ ) {
719 double x = h->GetXaxis()->GetBinLowEdge(i);
720 for ( int j=1 ; j<=Ny ; j++ ) {
721 double n = h->GetBinContent(i,j);
722 if ( n!=0 ) {
723 if ( x<xlo ) {
724 if ( i>1 ) xlo = h->GetXaxis()->GetBinLowEdge(i-1);
725 else xlo = x;
726 }
727 if ( x>xhi ) {
728 if ( i<h->GetXaxis()->GetNbins() ) xhi = h->GetXaxis()->GetBinLowEdge(i+1);
729 else xhi = x;
730 }
731 }
732 }
733 }
734
735 if ( t ) {
736 xlo -= 5.4;
737 xhi -= 5.4;
738 }
739
740 h->GetXaxis()->SetRangeUser( xlo, xhi );
741}
742
743
745void autoy( TH2* h ) {
746
747 int Nx = h->GetNbinsX();
748 int Ny = h->GetNbinsY();
749
750 double yhi = h->GetYaxis()->GetBinLowEdge(1);
751 double ylo = h->GetYaxis()->GetBinLowEdge( h->GetYaxis()->GetNbins() );
752
753 for ( int i=1 ; i<=Ny ; i++ ) {
754 double y = h->GetYaxis()->GetBinLowEdge(i);
755 for ( int j=1 ; j<=Nx ; j++ ) {
756 double n = h->GetBinContent(j,i);
757 if ( n!=0 ) {
758 if ( y<ylo ) {
759 if ( i>1 ) ylo = h->GetYaxis()->GetBinLowEdge(i-1);
760 else ylo = y;
761 }
762 if ( y>yhi ) {
763 if ( i<h->GetYaxis()->GetNbins() ) yhi = h->GetYaxis()->GetBinLowEdge(i+1);
764 else yhi = y;
765 }
766 }
767 }
768 }
769
770 h->GetYaxis()->SetRangeUser( ylo, yhi );
771}
772
773
774
775double chi2( TH1* h0, TH1* h1 ) {
776
777 std::cout << "chi2" << std::endl;
778
779 double c2 = 0;
780
781 std::cout << "h: " << h0 << " " << h1 << std::endl;
782
783 if ( h0==0 || h1==0 ) {
784 std::cerr << "histogram not found: h0: " << h0 << "\th1: " << h1 << std::endl;
785 return 999;
786 }
787
788 std::cout << "h: " << h0->GetName() << std::endl;
789 std::cout << "h: " << h1->GetName() << std::endl;
790
791 std::cout << "h0->GetNbinsX() " << h0->GetNbinsX() << std::endl;
792 std::cout << "h0->GetNbinsX() " << h1->GetNbinsX() << std::endl;
793
794 for ( int i=0 ; i<h0->GetNbinsX() ; i++ ) {
795
796 double d0 = h0->GetBinContent(i+1);
797 double d1 = h1->GetBinContent(i+1);
798
799 double e0 = h0->GetBinError(i+1);
800 double e1 = h1->GetBinError(i+1);
801
802 double e2 = e0*e0+e1*e1;
803
804 if ( e2>0 ) c2 += (d0-d1)*(d0-d1)/e2;
805
806 }
807
808 return c2;
809}
810
811void ifdbg( const std::string& /* s */ ) {
812 // std::cout << "if dbg: " << s << std::endl;
813}
814
815
816
817
818int main(int argc, char** argv) {
819
820 gErrorIgnoreLevel = kError;
821
822 std::cout << "\n---------------------------------\n";
823 std::cout << "\n comparitor is off ...\n";
824
825 if ( argc<4 ) return usage(argv[0], -1, "too few arguments");
826
828
829 std::string tag = "";
830 std::string key = "";
831
832 std::string dir = "";
833
834 std::string ftestname = "";
835 std::string frefname = "";
836
837 TFile* ftest_ = 0;
838 TFile* fref_ = 0;
839
840 bool effset = false;
841 double effmin = 90;
842 double effmax = 102;
843
844 std::string defreflabel = "";
845
847
848 std::vector<std::string> usrlabels;
849 bool uselabels = false;
850 bool addinglabels = false;
851
852 std::vector<std::string> taglabels;
853 std::vector<std::string> taglabels2;
854 bool addingtags = false;
855 bool addingtags2 = false;
856
857 bool lumiref_trans = false;
858 bool lumitest_trans = false;
859
860 bool make_efficiencies = true;
861
862 bool make_ref_efficiencies = false;
863 bool refit_resplots = false;
864 bool refitref_resplots = false;
865 bool bayes = true;
866 bool nostats = false;
867 bool nomeans = false;
868 bool means = false;
869 bool noref = false;
870 bool atlasstyle = false;
871 bool deleteref = false;
872 bool nowatermark = false;
873 bool noplots = false;
874 bool nopng = false;
875 bool nopdf = false;
876 bool Cfile = false;
877 bool notitle = true;
878 bool dochi2 = false;
879 bool normref = false;
880 bool scalepix = false;
881 bool oldrms = false;
882 bool addchains = false;
883 bool usechainref = false;
884 bool quiet = false;
885
886 bool RANGEMAP = false;
887 bool ALLRANGEMAP = false;
888
889 double xerror = 0;
890
891 std::string atlaslabel_tmp = "Internal";
892
893
894 double scale_eff = -1;
895 double scale_eff_ref = -1;
896
897 std::string configfile = "";
898
899 double xoffset = 0;
900
901
902 double ypos_in = 0;
903
904 std::string pattern = "";
905 std::string regex = "";
906
907 std::string patternr = "";
908 std::string regexr = "";
909
910 std::string patternt = "";
911 std::string regext = "";
912
913 std::string basedir = "";
914
915 std::string xpattern = "";
916 std::string xregex = "";
917
918 std::vector<std::string> chains;
919 std::vector<std::string> refchains;
920
921 bool addingrefchains = false;
922
923 std::string mapfile = "";
924
925 std::vector<std::string> chainfiles;
926
927 int ncols = 2;
928
929 std::string runnumber = "";
930
931
932 for(int i=1; i<argc; i++){
933 std::string arg = argv[i];
934
935 ifdbg( "\ncnt: " + arg );
936
937
938 if ( arg.find('-')!=0 && addinglabels ) {
939 std::string label = arg;
940 fullreplace( label, "__", " " );
941 replace( label, '#', ' ' );
942 usrlabels.push_back( label );
943 continue;
944 }
945 else addinglabels = false;
946
947 if ( arg.find('-')!=0 && addingrefchains ) {
948 refchains.push_back( arg );
949 continue;
950 }
951 else addingrefchains = false;
952
953 if ( arg.find('-')!=0 && addingtags ) {
954 taglabels.push_back( fullreplace( arg, "__", " " ) );
955 std::cout << "\tadding tag label: " << taglabels.back() << std::endl;
956 continue;
957 }
958 else addingtags = false;
959
960 if ( arg.find('-')!=0 && addingtags2 ) {
961 taglabels2.push_back( fullreplace( arg, "__", " " ) );
962 std::cout << "\tadding tag label: " << taglabels2.back() << std::endl;
963 continue;
964 }
965 else addingtags2 = false;
966
967 ifdbg( "starting if cascade: "+arg );
968
969 if ( arg=="-h" || arg=="--help" ) {
970 return usage(argv[0], 0);
971 }
972 else if ( arg=="-c" || arg=="--config" ) {
973 if ( ++i<argc ) configfile=argv[i];
974 else return usage(argv[0], -1, "no config file provided");
975 ifdbg("-c");
976 }
977 else if ( arg=="--jl" ) {
978 JLflag = true;
979 ifdbg("--jl");
980 }
981 else if ( arg=="--eps" ) {
982 EPS = true;
983 ifdbg("--eps");
984 }
985 else if ( arg=="-t" || arg=="--tag" ) {
986 if ( ++i<argc ) tag=std::string("-")+argv[i];
987 else return usage(argv[0], -1, "no tag provided");
988 ifdbg("--tag");
989 }
990 else if ( arg=="-l" || arg=="--labels" ) {
991 addinglabels = true;
992 ifdbg("--labels");
993 }
994 else if ( arg=="-el" ) {
995 LINES = true;
996 ifdbg("-el");
997 }
998 else if ( arg=="-k" || arg=="--key" ) {
999 if ( ++i<argc ) key=argv[i];
1000 else return usage(argv[0], -1, "no key provided");
1001 ifdbg("--key");
1002 }
1003 else if ( arg=="--run" ) {
1004 if ( ++i<argc ) runnumber=argv[i];
1005 else return usage(argv[0], -1, "no run number provided");
1006 ifdbg("--run");
1007 }
1008 else if ( arg=="-m" || arg=="--mapfile" ) {
1009 if ( ++i<argc ) mapfile=argv[i];
1010 else return usage(argv[0], -1, "no mapfile provided");
1011 ifdbg("--mapfile");
1012 }
1013 else if ( arg=="-d" || arg=="--dir" ) {
1014 if ( ++i<argc ) dir=argv[i];
1015 else return usage(argv[0], -1, "no directory provided");
1016 ifdbg("--dir");
1017 }
1018 else if ( arg=="--lumi" ) {
1019 lumitest_trans = true;
1020 lumiref_trans = true;
1021 ifdbg("--lumi");
1022 }
1023 else if ( arg=="--lumitest" ) {
1024 lumitest_trans = true;
1025 ifdbg("--lumitest");
1026 }
1027 else if ( arg=="--lumiref" ) {
1028 lumiref_trans = true;
1029 ifdbg("--lumiref");
1030 }
1031 else if ( arg=="-b" || arg=="--bdir" ) {
1032 if ( ++i<argc ) basedir=argv[i];
1033 else return usage(argv[0], -1, "no directory provided");
1034 ifdbg("--bdir");
1035 }
1036 else if ( arg=="--taglabels" ) {
1037 addingtags = true;
1038 ifdbg("--taglabels");
1039 }
1040 else if ( arg=="--taglabels2" ) {
1041 addingtags2 = true;
1042 ifdbg("--taglabels2");
1043 }
1044 else if ( arg=="--unscalepix" ) {
1045 scalepix = false;
1046 ifdbg("--unscalepix");
1047 }
1048 else if ( arg=="--scalepix" ) {
1049 scalepix = true;
1050 ifdbg("--scalepix");
1051 }
1052 else if ( arg=="-ac" || arg=="--addchains" ) {
1053 addchains = true;
1054 ifdbg("--sddchains");
1055 }
1056 else if ( arg=="-yrange" ) {
1057 effset = true;
1058 if ( ++i<argc ) effmin=std::atof(argv[i]);
1059 else return usage(argv[0], -1, "no range specified");
1060 if ( ++i<argc ) effmax=std::atof(argv[i]);
1061 else return usage(argv[0], -1, "no upper y limit specified");
1062 ifdbg("-yrange");
1063 }
1064 else if ( arg=="-e" || arg=="--efficiencies" ) {
1065 make_ref_efficiencies = true;
1066 ifdbg("--efficiencies");
1067 }
1068 else if ( arg=="-r" || arg=="--refit" ) {
1069 refit_resplots = true;
1070 ifdbg("--refit");
1071 }
1072 else if ( arg=="-rr" || arg=="--refitref" ) {
1073 refitref_resplots = true;
1074 ifdbg("--refitref");
1075 }
1076 else if ( arg=="--oldrms" ) {
1077 oldrms = true;
1078 ifdbg("--oldrms");
1079 }
1080 else if ( arg=="-nw" || arg=="--nowatermark" ) {
1081 nowatermark = true;
1082 Plots::setwatermark(!nowatermark);
1083 ifdbg("--nowatermark");
1084 }
1085 else if ( arg=="--chi2" ) {
1086 dochi2 = true;
1087 ifdbg("--chi2");
1088 }
1089 else if ( arg=="-ns" || arg=="--nostats" ) {
1090 nostats = true;
1091 ifdbg("--nostats");
1092 }
1093 else if ( arg=="-nm" || arg=="--nomeans" ) {
1094 nomeans = true;
1095 ifdbg("--nomeans");
1096 }
1097 else if ( arg=="--means" ) {
1098 means = true;
1099 ifdbg("--means");
1100 }
1101 else if ( arg=="-nt" || arg=="--notitle" ) {
1102 notitle = true;
1103 ifdbg("--notitle");
1104 }
1105 else if ( arg=="-nr" || arg=="--noref" ) {
1106 Plotter::setplotref(false);
1107 noref = true;
1108 ifdbg("--noref");
1109 }
1110 else if ( arg=="--normref" ) {
1111 normref = true;
1112 ifdbg("--normref");
1113 }
1114 else if ( arg=="-rc" || arg=="--refchains" ) {
1115 addingrefchains = true;
1116 ifdbg("--refchains");
1117 }
1118 else if ( arg=="-uc" || arg=="--usechainref" ) {
1119 usechainref = true;
1120 ifdbg("--usechainref");
1121 }
1122 else if ( arg=="-nb" || arg=="--nobayes" ) {
1123 bayes = false;
1124 ifdbg("--nobayes");
1125 }
1126 else if ( arg=="-es" || arg=="--effscale" ) {
1127 if ( ++i<argc ) scale_eff=std::atof(argv[i]);
1128 else return usage(argv[0], -1, "no efficiency scale provided");
1129 ifdbg("--effscale");
1130 }
1131 else if ( arg=="-er" || arg=="--effscaleref" ) {
1132 if ( ++i<argc ) scale_eff_ref=std::atof(argv[i]);
1133 else return usage(argv[0], -1, "no efficiency scale for the reference histograms provided");
1134 ifdbg("--effscaleref");
1135 }
1136 else if ( arg=="--ncols" ) {
1137 if ( ++i<argc ) ncols=std::atoi(argv[i]);
1138 else return usage(argv[0], -1, "no number of columns provided");
1139 ifdbg("--ncols");
1140 }
1141 else if ( arg=="-np" || arg=="--noplots" ) {
1142 noplots = true;
1143 ifdbg("--noplots");
1144 }
1145 else if ( arg=="-C" || arg=="--Cfiles" ) {
1146 Cfile = true;
1147 ifdbg("--Cfiles");
1148 }
1149 else if ( arg=="--deleteref" ) {
1150 deleteref = true;
1151 ifdbg("--deleteref");
1152 }
1153 else if ( arg=="--nopng" ) {
1154 nopng = true;
1155 ifdbg("--nopng");
1156 }
1157 else if ( arg=="--nopdf" ) {
1158 nopdf = true;
1159 ifdbg("--nopdf");
1160 }
1161 else if ( arg=="-as" || arg=="--atlasstyle" ) {
1162 atlasstyle = true;
1163 // std::cout << "atlas style" << std::endl;
1164 ifdbg("--atlasstyle");
1165 }
1166 else if ( arg=="--tp" ) {
1167 make_efficiencies = false;
1168 ifdbg("--tp");
1169 }
1170 else if ( arg=="-q" || arg=="--quiet" ) {
1171 quiet = true;
1172 ifdbg("--quiet");
1173 }
1174 else if ( arg=="-al" || arg=="--atlaslabel" ) {
1175 if ( ++i<argc ) atlaslabel_tmp=argv[i];
1176 else return usage(argv[0], -1, "no label provided");
1177 ifdbg("--atlaslabel");
1178 }
1179 else if ( arg=="-xo" || arg=="--xoffset" ) {
1180 if ( ++i<argc ) xoffset=std::atof(argv[i]);
1181 else return usage(argv[0], -1, "no xoffset provided");
1182 ifdbg("--xoffset");
1183 }
1184 else if ( arg=="-yp" || arg=="--ypos" ) {
1185 if ( ++i<argc ) ypos_in=std::atof(argv[i]);
1186 else return usage(argv[0], -1, "no y position provided");
1187 ifdbg("--ypos");
1188 }
1189 else if ( arg=="-xe" || arg=="--xerror" ) {
1190 if ( ++i<argc ) xerror=std::atof(argv[i]);
1191 else return usage(argv[0], -1, "no x error provided");
1192 ifdbg("--xerror");
1193 }
1194 else if ( arg=="-s" || arg=="--swap" ) {
1195 if ( ++i<argc ) pattern=argv[i];
1196 else return usage(argv[0], -1, "no patterns provided");
1197 if ( ++i<argc ) regex=argv[i];
1198 else return usage(argv[0], -1, "no target pattern provided");
1199 ifdbg("--swap");
1200 }
1201 else if ( arg=="--swapt" ) {
1202 if ( ++i<argc ) patternt=argv[i];
1203 else return usage(argv[0], -1, "no patterns provided");
1204 if ( ++i<argc ) regext=argv[i];
1205 else return usage(argv[0], -1, "no target pattern provided");
1206 ifdbg("--swapt");
1207 }
1208 else if ( arg=="--swapr" ) {
1209 if ( ++i<argc ) patternr=argv[i];
1210 else return usage(argv[0], -1, "no patterns provided");
1211 if ( ++i<argc ) regexr=argv[i];
1212 else return usage(argv[0], -1, "no target pattern provided");
1213 ifdbg("--swapr");
1214 }
1215 else if ( arg=="-sx" || arg=="--swapaxtitles" ) {
1216 if ( ++i<argc ) xregex=argv[i];
1217 else return usage(argv[0], -1, "no target pattern provided");
1218 if ( ++i<argc ) xpattern=argv[i];
1219 else return usage(argv[0], -1, "no patterns provided");
1220 ifdbg("--swapxtitles");
1221 }
1222 else if ( arg.find('-')==0 ) {
1223 std::cerr << "unknown option: " << arg << "\n" << std::endl;
1224 return usage(argv[0], -4);
1225 }
1226 else {
1227 ifdbg("arg: + "+arg);
1228 if ( ftestname=="" ) ftestname = arg;
1229 else if ( frefname=="" ) frefname = arg;
1230 else {
1231 std::string file = "";
1232
1233 if ( arg.find(":file:")!=std::string::npos ) {
1234 file = arg.substr( 0, arg.find(":file:") );
1235 chainfiles.push_back( file );
1236 arg = arg.substr(arg.find(":file:")+6,arg.size());
1237 }
1238
1239 std::string chain = arg;
1240
1241 replace ( chain, ':', '_' );
1242 replace ( chain, ';', '_' );
1243 chains.push_back(chain);
1244
1245 std::cout << "file: " << file << "\tchain: " << chain << std::endl;
1246
1247 }
1248 }
1249 }
1250
1251 if ( ftestname.empty() ) {
1252 std::cerr << "main(): test file not specified " << std::endl;
1253 return -1;
1254 }
1255
1256 if ( !exists(ftestname) ) {
1257 std::cerr << "main(): test file " << ftestname << " does not exist" << std::endl;
1258 return -1;
1259 }
1260
1261 std::vector<TFile*> chainTFiles;
1262
1263 if ( chainfiles.size()==0 ) ftest_ = TFile::Open( ftestname.c_str() );
1264 else {
1265 noref=true;
1266 chainTFiles.resize(chainfiles.size());
1267 for ( size_t i=0 ; i<chainfiles.size() ; i++ ) {
1268 chainTFiles[i] = TFile::Open( chainfiles[i].c_str() );
1269 if ( chainTFiles[i] == 0 ) {
1270 std::cerr << "\tfile: " << chainfiles[i] << " could not be opened" << std::endl;
1271 return -1;
1272 }
1273 else std::cout << "\tchainfiles: " << chainfiles[i] << " " << chainTFiles[i] << std::endl;
1274 }
1275 }
1276
1277
1278 if ( noref==false ) {
1279 if ( frefname.empty() ) {
1280 std::cerr << "main(): ref file not specified " << std::endl;
1281 Plotter::setplotref(false);
1282 noref = true;
1287 // return -1;
1288 }
1289
1290 if ( frefname==ftestname ) fref_ = ftest_;
1291 else if ( exists(frefname) ) fref_ = TFile::Open( frefname.c_str() );
1292 else {
1293 std::cerr << "main(): ref file " << frefname << " does not exist" << std::endl;
1294 // return -1;
1295 Plotter::setplotref(false);
1296 noref=true;
1297 }
1298 }
1299 else fref_ = ftest_;
1300
1301 if ( chainfiles.size()==0 ) {
1302 if ( ftest_==0 ) {
1303 std::cerr << "could not open test file " << ftestname << std::endl;
1304 return -1;
1305 }
1306
1307 if ( noref==false && fref_==0 ) {
1308 std::cerr << "could not open files " << std::endl;
1312 noref=true;
1313 fref_=ftest_;
1314 defreflabel = "failed to open reference file";
1315 }
1316
1317 }
1318
1319 if ( scale_eff == -1 ) scale_eff = 100;
1320 if ( scale_eff_ref == -1 ) scale_eff_ref = scale_eff;
1321
1322
1323 bool noreftmp = noref;
1324
1325 if ( chains.size()==0 ) return usage(argv[0], -1, "no chains specified");
1326
1327
1328 if ( basedir.size()>0 ) {
1329 if ( basedir[basedir.size()-1]!='/' ) basedir += "/";
1330 for ( size_t ic=chains.size() ; ic-- ; ) chains[ic] = basedir+chains[ic];
1331 }
1332
1333 if ( refchains.size()>0 && refchains.size()!=chains.size() ) return usage(argv[0], -1, "not enough chains specified");
1334
1335 if ( refchains.size()==0 ) refchains = chains;
1336
1337 std::vector<std::string> chainref(chains.size(),"");
1338 std::vector<std::string> chain_name(chains.size(),"");
1339
1340 std::vector<std::string> refchain(chainref.size(),"");
1341
1342
1343
1344 std::cout << argv[0] << " options:" << std::endl;
1345 std::cout << "\tATLAS style: " << ( atlasstyle ? "true" : "false" ) << std::endl;
1346 std::cout << "\tBayesian uncertainties: " << ( bayes ? "true" : "false" ) << std::endl;
1347 std::cout << "\trefit resplot uncertainties: " << ( refit_resplots ? "true" : "false" ) << std::endl;
1348 std::cout << "\tsuppress mean and rms stats: " << ( nostats ? "true" : "false" ) << std::endl;
1349 if ( !nostats ) std::cout << "\tsuppress meanstats: " << ( nomeans ? "true" : "false" ) << std::endl;
1350 std::cout << "\tsuppress png output: " << ( nopng ? "true" : "false" ) << std::endl;
1351 std::cout << "\tsuppress pdf output: " << ( nopdf ? "true" : "false" ) << std::endl;
1352 std::cout << "\tsuppress reference output: " << ( noref ? "true" : "false" ) << std::endl;
1353 std::cout << "\tuse chain references: " << ( usechainref ? "true" : "false" ) << std::endl;
1354 std::cout << "\tpanel ncols: " << ncols << std::endl;
1355
1356 if ( usrlabels.size()>0 ) std::cout << "\tlabels: " << usrlabels.size() << std::endl;
1357 if ( taglabels.size()>0 ) std::cout << "\textra text: " << taglabels << std::endl;
1358 if ( taglabels2.size()>0 ) std::cout << "\textra text: " << taglabels2 << std::endl;
1359
1360
1361 for ( size_t il=0 ; il<usrlabels.size() ; il++ ) {
1362 std::cout << "usr label[" << il << "] : " << usrlabels[il] << std::endl;
1363 }
1364
1365 std::cout << "atlas style : " << atlasstyle << std::endl;
1366
1367 if ( atlasstyle ) {
1368 SetAtlasStyle();
1369 gStyle = AtlasStyle();
1370 gStyle->cd();
1371 }
1372 else {
1373 gROOT->SetStyle("Plain");
1374 gStyle->cd();
1375 gStyle->SetLineScalePS(1);
1376 xoffset += 0.02;
1377 }
1378
1379 gStyle->SetErrorX(xerror);
1380
1381 gStyle->SetPadLeftMargin(0.15);
1382 gStyle->SetPadBottomMargin(0.15);
1383
1384 gStyle->SetPadRightMargin(0.02);
1385 gStyle->SetPadTopMargin(0.05);
1386
1387 std::cout << "Chains: " << std::endl;
1388 for ( unsigned ic=0 ; ic<chains.size() ; ic++ ) std::cout << "\t" << chains[ic] << std::endl;
1389
1390 if ( usrlabels.size()>0 ) std::cout << "labels: " << usrlabels << std::endl;
1391
1392 if ( usrlabels.size()>0 && usrlabels.size()==chains.size() ) uselabels = true;
1393
1395
1396 TTree* dataTree = 0;
1397 TString* releaseData = new TString("");
1398 std::vector<std::string> release_data;
1399
1400
1401 if ( !nowatermark && ftest_ ) {
1402
1403 dataTree = (TTree*)ftest_->Get("dataTree");
1404
1405 if ( dataTree ) {
1406 dataTree->SetBranchAddress( "ReleaseMetaData", &releaseData);
1407
1408 for (unsigned int i=0; i<dataTree->GetEntries() ; i++ ) {
1409 dataTree->GetEntry(i);
1410 release_data.push_back( releaseData->Data() );
1411 std::cout << "main() release data: " << release_data.back() << " : " << *releaseData << std::endl;
1412 }
1413 }
1414
1415 std::cout << "\n\n\n\n\n" << std::endl;
1416
1417 std::cout << "\n\nrd size " << release_data.size() << std::endl;
1418
1419
1420 if ( release_data.size()>0 ) {
1421 if ( release_data.size()>1 ) std::cerr << "main() more than one release - using only the first" << std::endl;
1422
1423 // std::cout << "release: " << chop(release_data[0], " " ) << std::endl;
1424
1425 std::string rd = release_data[0];
1426
1427 while ( rd.size()>0 ) {
1428
1429 std::string nightly = chop(rd, " " );
1430
1431 if ( contains(nightly,"private" ) ) {
1432 for ( int ic=0 ; ic<4 ; ic++ ) chop(release_data[0], " " );
1433 release += " (" + release_data[0]+")";
1434 break;
1435 }
1436 else {
1437
1438 if ( contains(nightly,"nightly") ) {
1439 chop( nightly,"/" );
1440 release += " ( " + chop( nightly,"/");
1441 release += " " + chop(nightly, "/" ) + " )";
1442 break;
1443 }
1444
1445 }
1446 }
1447 }
1448 }
1449
1450 std::cout << "release: " << release << std::endl;
1451
1452
1453 // Make output directory
1454 if (!dir.empty()) {
1455
1456 gDirectory->pwd();
1457
1458 std::cout << "trying to make directory" << std::endl;
1459 dir += '/';
1460 if ( !quiet && !noplots && !exists(dir) ) {
1461 if ( mkdir( dir.c_str(), 0777 ) ) std::cerr << "main() couldn't create directory " << dir << std::endl;
1462 else std::cout << "main() output will be sent to directory " << dir << std::endl;
1463 }
1464 }
1465
1466 if ( ftest_==0 && chainTFiles.size()>0 ) fref_ = ftest_ = chainTFiles[0];
1467
1468 TFile* ftest = ftest_;
1469 TFile* fref = fref_;
1470
1471 std::string testrun = findrun( ftest );
1472
1473 std::string rawrefrun = "";
1474 std::string refrun = "";
1475
1476 if ( fref_ ) refrun = rawrefrun = findrun( fref );
1477
1478 std::cout << "testrun: " << testrun << "\nrefrun: " << refrun << std::endl;
1479
1480 if ( !testrun.empty() && refrun != testrun ) {
1481 if ( pattern.empty() ) {
1482 pattern = testrun;
1483 regex = refrun;
1484 }
1485
1486 }
1487
1488 if ( !refrun.empty() ) {
1489
1490 std::string newtag = "Reference: ";
1491
1492 std::cout << "refrun: " << refrun << std::endl;
1493
1494 size_t pos;
1495 while ( (pos=refrun.find('_'))!=std::string::npos ) refrun.replace( pos, 1, " " );
1496 newtag += refrun;
1497
1498 std::string rawrun = refrun.erase( refrun.find("run"), 4 );
1499
1500 if ( contains(frefname, rawrun) ) {
1501
1502 std::string release = frefname;
1503
1504 release.erase( 0, release.find(rawrun) );
1505
1506 if ( contains(release,"HIST") ) release.erase( 0, release.find("HIST")+5 );
1507 while ( contains(release,".") ) release.erase( release.find('.'), release.size() );
1508 while ( contains(release,"-") ) release.erase( release.find('-'), release.size() );
1509 while ( contains(release,"_p") ) release.erase( release.find("_p"), release.size() );
1510 while ( contains(release,"_t") ) release.erase( release.find("_t"), release.size() );
1511
1512 newtag += " ";
1513 newtag += release;
1514
1515 }
1516
1517 taglabels.push_back( newtag );
1518
1519 std::cout << "tag labels: " << taglabels << std::endl;
1520
1521 }
1522
1527 int NeventTest = 1;
1528 int NeventRef = 1;
1529
1530
1531 std::vector<std::string> savedhistos;
1532
1533
1534 if ( !nowatermark ) {
1535
1536
1537 TH1D* htestev = (TH1D*)ftest->Get("event") ;
1538 TH1D* hrefev = (TH1D*)fref->Get("event") ;
1539
1540
1541
1542 std::cout << "htestev " << htestev << " " << hrefev << std::endl;
1543
1544 if ( htestev ) NeventTest = htestev->GetEntries();
1545 if ( hrefev ) NeventRef = hrefev->GetEntries();
1546
1547 savedhistos.push_back("event");
1548 }
1549 else {
1550 NeventTest = 1;
1551 NeventRef = 1;
1552 }
1553
1554
1555 if ( NeventTest>1 ) std::cout << "Nevents Test: " << NeventTest << std::endl;
1556 if ( NeventRef>1 ) std::cout << "Nevents Ref: " << NeventRef << std::endl;
1557
1558 chainmap_t* chainmap = nullptr;
1559
1560 if ( mapfile.empty() ) mapfile = configfile;
1561
1562
1563 std::cout << "mapfile: " << mapfile << std::endl;
1564
1565 if ( !mapfile.empty() ) {
1566
1567 ReadCards m( mapfile );
1568
1569 if ( m.isTagDefined( "ChainMap" ) ) {
1570
1571 std::vector<std::string> chains = m.GetStringVector( "ChainMap" );
1572
1573 for ( size_t i=0 ; i<chains.size() ; i+=2 ) std::cout << "map: " << chains[i] << " -> " << chains[i+1] << std::endl;
1574
1575 chainmap = new chainmap_t();
1576
1577 for ( size_t i=0 ; i<chains.size() ; i+=2 ) {
1578 chainmap->insert( chainmap_t::value_type( chains[i], chains[i+1] ) );
1579 }
1580
1581 std::cout << "\nusing chain map:" << std::endl;
1582
1583 for ( chainmap_t::iterator itr=chainmap->begin() ; itr!=chainmap->end() ; itr++ ) { //cppcheck-suppress postfixOperator
1584 std::cout << "\t" << itr->first << "\t" << itr->second << std::endl;
1585 }
1586 }
1587 }
1588
1590
1591 std::cout << "\ncreating chain and reference information ..." << std::endl;
1592
1593 for ( size_t j=0; j<chains.size(); j++) {
1594
1595 if ( !regex.empty() ) chains[j] = fullreplace( chains[j], pattern, regex );
1596 if ( !regext.empty() ) chains[j] = fullreplace( chains[j], patternt, regext );
1597
1599
1601 std::cout << "chain: " << chains[j] << "\taddchains: " << addchains << std::endl;
1602
1603 if ( addchains && ( contains(chains[j],"Shifter") || ( !contains(chains[j],"HLT_") && !contains(chains[j], "Fullscan" ) ) ) ) {
1604
1605 TFile* fftest = ftest;
1606
1607 if ( chainfiles.size()>0 && chainfiles.size()>j ) fftest = chainTFiles[j];
1608
1609 TH1F* hchain = Get( *fftest, chains[j]+"/Chain", testrun );
1610
1611 if ( hchain ) {
1612
1613 std::string name = hchain->GetTitle();
1614
1615 if ( usechainref && !contains(chains[j],"Purity") ) {
1616
1617 chainref[j] = name;
1618
1619 std::cout << "new chainref: " << chainref[j] << std::endl;
1620
1621 std::string::size_type pos = chainref[j].find(":for");
1622 if ( pos!=std::string::npos ) chainref[j].replace( pos, 4, "_for" );
1623 std::replace( chainref[j].begin(), chainref[j].end(), ':', '/');
1624 std::string newchain = dirname( dirname( chains[j]) ) + "/Expert/" + chainref[j];
1625 chainref[j] = newchain;
1626
1627 std::cout << "final chainref: " << chainref[j] << std::endl;
1628
1629 }
1630
1631 std::cout << "chainref: " << chainref[j] << std::endl;
1632
1633 while ( contains( name, "HLT_" ) ) name = name.erase( name.find("HLT_"), 4 );
1634
1635 std::cout << "name: " << name << std::endl;
1636
1637 if ( contains( name, ":" ) ) chain_name[j] = name.substr( 0, name.find(':') ) + " : ";
1638 else chain_name[j] = name;
1639
1640 if ( chain_name[j] == " : " ) chain_name[j] = "";
1641
1642 std::cout << "chain_name: " << chain_name[j] << std::endl;
1643 }
1644 }
1645 }
1646
1647 std::cout << "chainref size: " << chainref.size() << " " << refchains.size() << std::endl;
1648
1649 for ( size_t j=0 ; j<chainref.size() ; j++ ) {
1650 std::cout << "chainref: " << chainref[j] << " :: " << refchains[j] << std::endl;
1651
1653 if ( chainref[j]!="" ) refchain[j] = fullreplace( chainref[j], pattern, regex );
1654 else refchain[j] = fullreplace( refchains[j], pattern, regex );
1655
1656 if ( !patternr.empty() ) {
1657 if ( chainref[j]!="" ) refchain[j] = fullreplace( chainref[j], patternr, regexr );
1658 else refchain[j] = fullreplace( refchains[j], patternr, regexr );
1659 }
1660
1661 std::cout << "refchain: " << refchain[j] << std::endl;
1662 }
1663
1664 std::cout << "done chains" << std::endl;
1665
1667
1668 std::vector<Panel> panels;
1669
1671
1672 bands bnd;
1673
1674
1675 std::vector<int> ccolours;
1676 std::vector<int> cstyles;
1677
1678 std::vector<std::string> ctags;
1679 std::vector<std::string> ctaglabels;
1680
1681
1682 std::cout << "\n" << argv[0] << "\tconfigfile: " << configfile << std::endl;
1683
1684 bool use_file_config = false;
1685
1686 if ( configfile!="" ) {
1687
1688 if ( exists(configfile) ) {
1689
1690 std::cout << argv[0] << ":\treading configuration file " << configfile << std::endl;
1691
1692 ReadCards rc(configfile);
1693
1694
1696
1697 if ( rc.isTagDefined( "histos" ) ) {
1698
1699 std::cout << argv[0] << ":\treading histogram configuration from file " << configfile << std::endl;
1700
1701 use_file_config = true;
1702
1703 std::vector<std::string> raw_input = rc.GetStringVector( "histos" );
1704
1705 for ( size_t iraw=0 ; iraw<raw_input.size() ; iraw += 6) {
1706 HistDetails h( &(raw_input[iraw]) );
1707 Panel p( h.name(), 1 );
1708 p.push_back( h );
1709 panels.push_back( p );
1710 }
1711
1712 }
1713
1714 std::cout << "searching for panels" << std::endl;
1715
1717
1718 if ( rc.isTagDefined( "panels" ) ) {
1719
1720 std::cout << argv[0] << ":\treading histogram panel configuration from file " << configfile << std::endl;
1721
1722 use_file_config = true;
1723
1724 std::vector<std::string> panel_config = rc.GetStringVector( "panels" );
1725
1726 std::vector<string> panel_columns;
1727
1728 if ( rc.isTagDefined("panel_columns") ) {
1729 panel_columns = rc.GetStringVector( "panel_columns" );
1730 if ( panel_columns.size()%2 ) return usage( argv[0], -1, "incorrect panel settings" );
1731 }
1732
1733
1734 for ( size_t ipanel=panel_config.size() ; ipanel-- ; ) {
1735
1736 std::vector<std::string> raw_input = rc.GetStringVector( panel_config[ipanel] );
1737
1738 int tncols = ncols;
1739
1740 if ( panel_columns.size() ) {
1741 std::vector<string>::iterator itr = find( panel_columns.begin(), panel_columns.end(), panel_config[ipanel] );
1742 if ( itr!=panel_columns.end() ) tncols = std::atoi( (++itr)->c_str() );
1743 }
1744
1745 Panel p( panel_config[ipanel], tncols );
1746
1747 if ( raw_input.empty() ) {
1748 std::cerr << "no plots provided" << std::endl;
1749 return 1;
1750 }
1751
1752 for ( size_t iraw=0 ; iraw<raw_input.size() ; iraw += 6 ) p.push_back( HistDetails( &(raw_input[iraw]) ) );
1753
1754 panels.push_back( p );
1755
1756 }
1757
1758 }
1759
1760 if ( rc.isTagDefined( "Bands" ) && rc.isTagDefined( "Labels" ) ) {
1761 bnd = bands( rc.GetVector( "Bands"), rc.GetStringVector( "Labels" ) );
1762 }
1763
1764
1765 if ( rc.isTagDefined("Colours") ) {
1766
1767 std::vector<int> ccolours = rc.GetIntVector("Colours");
1768
1769 std::cout << "remap colours: " << ccolours << std::endl;
1770
1771 int new_colours[6];
1772
1773 for ( size_t i=6 ; i-- ; ) new_colours[i] = colours[i];
1774
1775 for ( size_t i=0 ; i<ccolours.size() && i<6 ; i++ ) {
1776 if ( ccolours[i]<6 ) new_colours[i] = colours[ccolours[i]];
1777 }
1778
1779 for ( size_t i=6 ; i-- ; ) colours[i] = new_colours[i];
1780
1781 }
1782
1783
1784 if ( rc.isTagDefined("Styles") ) {
1785
1786 std::vector<int> cstyles = rc.GetIntVector("Styles");
1787
1788 std::cout << "remap markers: " << cstyles << std::endl;
1789
1790 int new_markers[6];
1791
1792 for ( size_t i=6 ; i-- ; ) new_markers[i] = markers[i];
1793
1794 for ( size_t i=0 ; i<cstyles.size() && i<6 ; i++ ) {
1795 if ( cstyles[i]<6 ) new_markers[i] = markers[cstyles[i]];
1796 }
1797
1798 for ( size_t i=6 ; i-- ; ) markers[i] = new_markers[i];
1799
1800 }
1801
1802 if ( fulldbg ) {
1803 for ( int i=6 ; i-- ; ) std::cout << "\tcolours[" << i << "] = " << colours[i] << std::endl;
1804 for ( int i=6 ; i-- ; ) std::cout << "\tmarkers[" << i << "] = " << markers[i] << std::endl;
1805 }
1806
1807 if ( rc.isTagDefined("Tags") ) ctags = rc.GetStringVector("Tags");
1808 if ( rc.isTagDefined("TagLabels") ) ctaglabels = rc.GetStringVector("TagLabels");
1809 if ( rc.isTagDefined("TagLabels") ) usrlabels = rc.GetStringVector("TagLabels");
1810
1811
1812 if ( rc.isTagDefined("Styles") ) {
1813 for ( size_t is=0 ; is<cstyles.size() && is<6 ; is++ ) {
1814 markers[is] = cstyles[is];
1815 }
1816 }
1817
1818
1819 uselabels = true;
1820
1821
1822 std::cout << argv[0] << "\tuserlabels :" << usrlabels << ":" << std::endl;
1823
1824
1825
1826 if ( rc.isTagDefined("RANGEMAP") ) RANGEMAP = true;
1827 if ( rc.isTagDefined("ALLRANGEMAP") ) ALLRANGEMAP = true;
1828
1829 std::cout << "Extra: " << rc.isTagDefined("Extra") << std::endl;
1830
1831 if ( rc.isTagDefined("Extra") ) taglabels.push_back( fullreplace( rc.GetString("Extra"), "__", " " ) );
1832
1833
1834 }
1835 else {
1836 std::cerr << argv[0] << ":\t config file not found: " << configfile << std::endl;
1837 return -1;
1838 }
1839
1840 }
1841
1842 if ( !use_file_config ) {
1843
1844 std::cout << "using default panels" << std::endl;
1845
1847
1848 // for ( size_t iraw=0 ; iraw<Nhistos ; iraw++ ) {
1849 // Panel p( histos_default[iraw][0], 1 );
1850 // p.push_back( histos_default[iraw] );
1851 // panels.push_back( p );
1852 // }
1853
1854 // default panel efficiencies plotted from 0 to 100,
1855 // so scale efficiencies no matter what
1856
1857 scale_eff = 100;
1858 scale_eff_ref = 100;
1859
1861
1862 std::string (*inpanels[3])[6] = { eff_panel, res_panel, diff_panel };
1863
1864 size_t nphist[3] = { 4, 4, 10 };
1865
1866 std::string pnames[3] = { "eff", "res", "diff" };
1867
1868 for ( size_t ip=0 ; ip<3 ; ip++ ) {
1869 Panel p( pnames[ip]+"_panel", 2 );
1870 for ( size_t iraw=0 ; iraw<nphist[ip] ; iraw++ ) p.push_back( HistDetails( inpanels[ip][iraw] ) );
1871 panels.push_back( p );
1872 }
1873
1874 }
1875
1876
1877 std::cout << "taglabels" << std::endl;
1878
1879 for ( size_t it=0 ; it<taglabels.size() ; it++ ) std::cout << taglabels[it] << std::endl;
1880 for ( size_t it=0 ; it<taglabels2.size() ; it++ ) std::cout << taglabels2[it] << std::endl;
1881
1882
1883 std::cout << "\npanels: " << panels.size() << std::endl;
1884
1885 if ( panels.size()==0 ) return usage(argv[0], -1, "no panels to plot");
1886
1887 for ( size_t ip=0 ; ip<panels.size() ; ip++ ) std::cout << panels[ip] << std::endl;
1888
1889
1891 if ( true ) {
1892 gStyle->SetPadRightMargin(0.05);
1893 gStyle->SetPadTopMargin(0.05);
1894
1895 const Int_t Number = 3;
1896 Double_t Red[Number] = { 0.00, 0.00, 1.00};
1897 Double_t Green[Number] = { 0.00, 5.00, 1.00};
1898 Double_t Blue[Number] = { 0.00, 0.50, 0.00};
1899 Double_t Length[Number] = { 0.00, 0.50, 1.00 };
1900 Int_t nb=50;
1901 TColor::CreateGradientColorTable(Number,Length,Red,Green,Blue,nb);
1902 }
1903 else gStyle->SetPalette(1);
1904
1905 if ( fulldbg ) std::cout << __LINE__ << std::endl;
1906
1907 double rightmargin = gStyle->GetPadRightMargin();
1908 gStyle->SetPadRightMargin(0.1);
1909
1911
1912 gStyle->SetPadRightMargin(rightmargin);
1913
1914 // gStyle->SetLineScalePS(1);
1915
1916 for ( size_t ipanel=0 ; ipanel<panels.size() ; ipanel++ ) {
1917
1918 Panel& panel = panels[ipanel];
1919
1920 std::cout << "\n\n---------------------------------------------\n";
1921
1922 std::cout << panel << "\n" << std::endl;
1923
1924 int ncolsp = panel.ncols();
1925 int nrowsp = panel.nrows();
1926
1927 double extraw = 1;
1928
1929 std::cout << "\nncols: " << ncolsp << "\tnrows: " << nrowsp << std::endl;
1930
1931 bool multipanel = ( panel.size() > 1 );
1932
1933 if ( panel.size()==0 ) {
1934 std::cout << "panel empty: " << panel.name() << std::endl;
1935 continue;
1936 }
1937
1938 gStyle->cd();
1939
1940 if ( panel.size()>4 ) gStyle->SetLineScalePS(0.5);
1941
1942 if ( multipanel ) extraw = 1.05;
1943
1944 TCanvas* tc = new TCanvas( "tc", "", extraw*ncolsp*800, nrowsp*600 );
1945
1946 tc->cd();
1947
1948 const std::string& atlaslabel = atlaslabel_tmp;
1949
1950 if ( multipanel ) {
1951
1952 gStyle->SetLineScalePS(1);
1953
1956
1964
1967
1968 tc->Divide( ncolsp, nrowsp, 0.0001, 0.0003 );
1969 // atlaslabel = " " + atlaslabel_tmp;
1970 }
1971
1973
1974 std::string plotname = "";
1975
1976 for ( size_t i=0 ; i<panel.size() ; i++ ) {
1977
1978 HistDetails histo = panel[i];
1979
1980 bool drawmeans = false;
1981 bool drawresiduals = true;
1982
1983 // if ( contains(histo.detail(), "+mean" ) || means ) drawmeans = true;
1984 if ( contains(histo.detail(), "+mean" ) ) drawmeans = true;
1985 if ( contains(histo.detail(), "-residual") ) drawresiduals = false;
1986
1987 std::string xaxis = histo.xtitle();
1988 std::string yaxis = histo.ytitle();
1989
1990 if ( !xregex.empty() ) {
1991 size_t pos = xaxis.find(xregex);
1992 if ( pos!=std::string::npos ) xaxis.replace( pos, xregex.size(), xpattern );
1993 pos = yaxis.find(xregex);
1994 if ( pos!=std::string::npos ) yaxis.replace( pos, xregex.size(), xpattern );
1995 }
1996
1997 const AxisInfo& xinfo = histo.xaxis();
1998 const AxisInfo& yinfo = histo.yaxis();
1999
2000 // AxisInfo xinfo = histo.xaxis();
2001 // AxisInfo yinfo = histo.yaxis();
2002
2003 std::string hname = histo.name();
2004 std::string detail = histo.detail();
2005
2006 bool translate_x = false;
2007
2008 if ( ( lumiref_trans || lumitest_trans ) && contains(histo.xtitle(), "Pile-up" ) ) translate_x = true;
2009
2010#if 0
2012 if ( translate_x ) {
2013 xinfo.lo( xinfo.lo()*(1-0.054) );
2014 xinfo.lo(10);
2015 xinfo.hi( xinfo.hi()*(1-0.054) );
2016 }
2017#endif
2018
2019 double rebin = 1;
2020
2021#ifdef D0REBIN
2022 bool d0rebin_flag = false;
2023
2024 if ( contains( detail, "+d0rebin" ) ) d0rebin_flag = true;
2025#endif
2026
2027 if ( contains( detail, "+Rebin" ) ) {
2028 rebin = std::atof( detail.substr( detail.find("+Rebin")+6, detail.size() ).c_str() );
2029 }
2030
2031 if ( contains( detail, "+rebin" ) ) {
2032 rebin = std::atof( detail.substr( detail.find("+rebin")+6, detail.size() ).c_str() );
2033 }
2034
2035 int labelcolour = kBlack;
2036
2037 int npanel = nrowsp*(i/nrowsp) + i%nrowsp + 1 ;
2038
2039 std::cout << "panel: panel: " << panel.name() << "\tsubpanel: " << npanel << std::endl;
2040
2041 if ( multipanel ) tc->cd( npanel );
2042
2043 SetAtlasStyle();
2044
2045 noreftmp = noref;
2046
2047 Plotter::setplotref(!noreftmp);
2048
2049 if ( fulldbg ) std::cout << __LINE__ << std::endl;
2050
2051 std::cout << "main() processing histo[" << i << "] " << (i<10 ? " " : "" ) << histo.name() << "\t" << histo.xaxis() << std::endl;
2052
2053 Plots plots_eff( "", yinfo.trim() );
2054 plots_eff.clear();
2055
2056 Plots plots( "", yinfo.trim() );
2057 plots.clear();
2058
2059 std::string noreflabel=defreflabel;
2060
2061 double xpos = 0.18;
2062 double ypos = 0.91;
2063
2064 if ( contains(histo.name(),"eff") || contains(histo.name(),"Eff_") ) ypos = 0.19;
2065
2066 // ypos = 0.19;
2067
2070
2071 if ( atlasstyle ) {
2072 xpos = 0.18;
2073 if ( ypos>0.5 ) ypos = 0.85;
2074 else ypos = 0.18;
2075 }
2076
2077 if ( ypos_in!=0 ) ypos = ypos_in;
2078
2079 double xpos_original = xpos;
2080
2081 xpos += xoffset;
2082
2083 if ( xinfo.offset() != 0 ) {
2084
2085 std::cout << "HA ! xinfo.offset: " << xinfo.offset() << std::endl;
2086
2087 xpos = xinfo.offset();
2088
2089 }
2090
2091
2092 if ( yinfo.offset() != 0 ) {
2093
2094 std::cout << "HA ! yinfo.offset: " << yinfo.offset() << std::endl;
2095
2096 ypos = yinfo.offset();
2097
2098 }
2099
2100
2101
2103
2104 size_t Nrows = chains.size();
2105
2106 if ( ALLRANGEMAP || (RANGEMAP && xaxis.find("p_{T}")!=std::string::npos && ccolours.size() ) ) {
2107 Nrows = ( Nrows < ccolours.size() ? Nrows : ccolours.size() );
2108 }
2109
2110 int Nlines = Nrows + taglabels.size();
2111
2112 std::vector<double> ypositions;
2113 std::vector<double> ypositions2;
2114
2115 double deltay = (Nrows*0.055-0.005)/Nrows;
2116
2117 double ylo = ypos;
2118 double yhi = ypos-0.01;
2119
2120 if ( ypos>0.5 ) ylo -= Nlines*deltay;
2121 else yhi += Nlines*deltay;
2122
2123 ypositions.reserve(Nlines);
2124 for ( int ilines=0 ; ilines<Nlines ; ilines++ ) {
2125 ypositions.push_back( yhi - deltay*(ilines+0.5) );
2126 ypositions2.push_back( yhi - deltay*(ilines-0.5) );
2127 }
2128
2129 // specify different legends for efficiencies or residuals?
2130
2132
2133 if ( JLflag ) {
2134 ylo -= 0.02;
2135 }
2136 else {
2137 if ( !contains(histo.name(),"eff") && !contains(histo.name(),"Eff_") ) ylo -= 0.02;
2138 }
2139
2140 Legend legend( xpos, xpos+0.1, ylo, ylo+Nrows*0.06-0.005 );
2141 Legend legend_eff( xpos, xpos+0.1, ylo, ylo+Nrows*0.06-0.005 );
2142
2143
2144 std::vector<std::string> Mean;
2145 std::vector<std::string> MeanLF;
2146 std::vector<std::string> RMS;
2147
2148 Mean.clear();
2149 MeanLF.clear();
2150 RMS.clear();
2151
2152 std::vector<std::string> Chi2;
2153 std::vector<std::string> MeanRef;
2154 std::vector<std::string> RMSRef;
2155
2156 // int colours[6] = { 1, 2, 4, 6, 7, 8 };
2157
2158 Chi2.clear();
2159 MeanRef.clear();
2160 RMSRef.clear();
2161
2162 int mean_power = 0;
2163 int rms_power = 0;
2164 bool power_set = false;
2165
2166 LINEF = true;
2167
2169 // bool uselogx = xinfo.log();
2170 // bool uselogy = yinfo.log();
2171
2172 for ( unsigned int j=0; j<chains.size(); j++) {
2173
2174 TFile* fftest = ftest;
2175 TFile* ffref = fref;
2176
2177 std::string cc = ftest->GetName();
2178 std::string cr = "";
2179
2180 if ( fref ) cr = fref->GetName();
2181
2182 if ( chainfiles.size()>0 && chainfiles.size()>j ) ffref = fftest = chainTFiles[j];
2183
2186
2187 std::cout << "chain: " << chains[j] << "\taddchains: " << addchains << std::endl;
2188 std::cout << "chainref: " << chainref[j] << std::endl;
2189
2190 noreftmp = noref;
2191 Plotter::setplotref(!noreftmp);
2192
2193 TH1F* htest = 0;
2194 TH1F* href = 0;
2195
2196 TH1F* htestnum = 0;
2197 TH1F* htestden = 0;
2198 TH1F* hrefnum = 0;
2199
2200 TH2D* h2test = 0;
2201
2202
2203 TGraphAsymmErrors* tgtest = 0;
2204
2205 std::cout << "refchain.size() " << refchain.size() << std::endl;
2206
2207 std::cout << "refchain: " << refchain[j] << std::endl;
2208
2210
2211 gPad->SetRightMargin(0.03);
2212
2213 bool do2D = false;
2214
2215 labelcolour = kBlack;
2216
2217
2218 if ( contains(histo.name(),"/2d") ) {
2219
2220 do2D = true;
2221 labelcolour = kWhite;
2222
2223 gPad->SetRightMargin(0.13);
2224
2225 std::cout << "\n\nsee! it is a 2d histograms !!! " << histo.name() << "\n\n" << std::endl;
2226
2227 h2test = Get<TH2D>( *fftest, chains[j]+"/"+histo.name(), testrun, 0, &savedhistos );
2228
2229 std::cout << "\t2d: " << h2test << std::endl;
2230
2231 DrawLabel( 0.5, 0.5, "a test" );
2232
2233 h2test->GetYaxis()->SetTitleOffset(1.55);
2234 h2test->GetXaxis()->SetTitleOffset(1.5);
2235 h2test->GetXaxis()->SetTitle(xaxis.c_str());
2236 h2test->GetYaxis()->SetTitle(yaxis.c_str());
2237
2238 const AxisInfo& xinfo = histo.xaxis();
2239 const AxisInfo& yinfo = histo.yaxis();
2240
2241 std::cout << xinfo << std::endl;
2242 std::cout << yinfo << std::endl;
2243
2244 if ( yinfo.rangeset() ) {
2245 h2test->GetYaxis()->SetRangeUser( yinfo.lo(), yinfo.hi() );
2246 }
2247
2248 if ( yinfo.normset() ) normy( h2test );
2249
2250 if ( xinfo.rangeset() ) {
2251 h2test->GetXaxis()->SetRangeUser( xinfo.lo(), xinfo.hi() );
2252 }
2253
2254 if ( xinfo.autoset() ) autox( h2test );
2255 if ( yinfo.autoset() ) autoy( h2test );
2256
2257 SetZeros( h2test );
2258
2259 h2test->DrawCopy("colz");
2260
2261 if ( histo.detail().find("logz")!=std::string::npos ) gPad->SetLogz(true);
2262 else gPad->SetLogz(false);
2263
2264
2265 }
2266 else if ( refit_resplots && ( contains(histo.name(),"/sigma") || contains(histo.name(),"/mean") ) ) {
2267
2268 std::cout << "\n\n2d: " << histo.name() << "\n\n" << std::endl;
2269
2270 bool bsigma = false;
2271 if ( contains(histo.name(),"/sigma") ) bsigma = true;
2272
2273 bool bmean = false;
2274 if ( contains(histo.name(),"/mean") ) bmean = true;
2275
2276 std::cout << "\trefitting: " << histo.name() << std::endl;
2277
2278 Resplot::setoldrms95(oldrms);
2280
2281 std::string tmp_ = histo.name();
2282 std::string base;
2283
2284 if ( bsigma ) base = chop( tmp_, "/sigma" );
2285 if ( bmean ) base = chop( tmp_, "/mean" );
2286
2287 TH2D* htest2d_ = Get<TH2D>( *fftest, chains[j]+"/"+base+"/2d", testrun, 0, &savedhistos );
2288
2289 std::cout << "ffref " << ffref << " :: " << base << std::endl;
2290
2291 TH2D* href2d_ = 0;
2292
2293 if ( ffref ) href2d_ = Get<TH2D>( *ffref, chains[j]+"/"+base+"/2d", testrun, chainmap );
2294
2295 std::cout << "htest2d_ : " << htest2d_ << std::endl;
2296
2297 if ( htest2d_==0 ) continue;
2298 if ( !noreftmp && href2d_==0 ) noreftmp = true;
2299
2300 std::cout << "href2d_ : " << href2d_ << std::endl;
2301
2302 Plotter::setplotref(!noreftmp);
2303
2304 std::cout << "plotter" << std::endl;
2305
2307
2308 Resplot rtest("tmp", htest2d_ );
2309
2310 std::cout << "Resplot rtest" << std::endl;
2311
2312 if ( rtest.finalised() ) {
2313 std::cout << "refitting ..." << std::endl;
2314 if ( contains(histo.name(),"npix") || contains(histo.name(),"nsct") || contains(histo.name(),"nsi") || contains(histo.name(),"nbl") ) rtest.Refit(Resplot::FitNull);
2315 else rtest.Refit(Resplot::FitNull95);
2316 }
2317 else {
2318 std::cout << "refitting (finalising) ..." << std::endl;
2319 if ( contains(histo.name(),"npix") || contains(histo.name(),"nsct") || contains(histo.name(),"nsi") || contains(histo.name(),"nbl") ) rtest.Finalise(Resplot::FitNull);
2320 else rtest.Finalise(Resplot::FitNull95);
2321
2322 rtest.Mean()->DrawCopy();
2323 gPad->Print("Duff.pdf");
2324 }
2325
2326 std::cout << "bsigma: " << bsigma << std::endl;
2327 std::cout << "bmean: " << bmean << std::endl;
2328
2329 if ( bsigma ) { htest = (TH1F*)rtest.Sigma()->Clone("rtest_sigma"); htest->SetDirectory(0); }
2330 if ( bmean ) { htest = (TH1F*)rtest.Mean()->Clone("rtest_mean"); htest->SetDirectory(0); }
2331
2332 if ( htest==0 ) {
2333 std::cerr << red << "missing test histogram: " << (refchain[j]+" / "+histo.name()) << " " << htest
2334 << "(test)" << reset << std::endl;
2335 continue;
2336 }
2337 else {
2338 std::cout << green << "htest: " << htest->GetName() << reset << std::endl;
2339 }
2340
2341 std::cout << "\nhisto.name(): " << histo.name() << std::endl;
2342
2343
2344 if ( true && histo.name().find("d0_vs_phi")!=std::string::npos ) {
2345
2346 TVirtualPad* old = gPad;
2347
2348 std::cout << "old canvas: " << gPad << std::endl;
2349
2350 std::cout << "dbg histo name: " << histo.name() << std::endl;
2351
2352 bool first = false;
2353
2354 TCanvas* tc = 0;
2355
2356 if ( histo.name().find("_rec")!=std::string::npos ) {
2357 //if ( fitcanvas_rec == 0 ) {
2358 fitcanvas_rec = new TCanvas( "fit_rec", "", 700, 600 );
2359 first = true;
2360 // }
2361 tc = fitcanvas_rec;
2362 }
2363
2364 if ( histo.name().find("_rec")==std::string::npos ) {
2365 //if ( fitcanvas == 0 ) {
2366 fitcanvas = new TCanvas( "fit", "", 700, 600 );
2367 first = true;
2368 //}
2369 tc = fitcanvas;
2370 }
2371
2372 TVirtualPad* tp = gPad;
2373
2374 if ( tc ) tc->cd();
2375
2377 // TH1D* hf = (TH1D*)rtest.Mean()->Clone("cck");
2378 // TH1D* hf = rtest.Mean();
2379
2380 rtest.Mean()->SetDirectory(0);
2381
2382 TH1* hf = htest;
2383
2384 if ( histo.name().find("_rec")!=std::string::npos ) hf->SetTitle(";Trigger #phi;Trigger d_{0} [mm]");
2385 else hf->SetTitle(";Offline #phi;Offline d_{0} [mm]");
2386
2387 TF1* tf = new TF1( "sinus", "[0]*sin(x+[1])+[2]" );
2388
2389 tf->SetLineWidth(1);
2390
2391 hf->GetYaxis()->SetTitleOffset( hf->GetYaxis()->GetTitleOffset()*1.1 );
2392
2393 {
2394 TCanvas* tfc = new TCanvas( "tmp", "", 700, 600 );
2395 tfc->cd();
2396 hf->Fit( tf );
2397 delete tfc;
2398 }
2399
2400 double phi0 = tf->GetParameter(1);
2401 // double x = 0.0001*int(tf->GetParameter(0)*cos(phi0)*10000);
2402 // double y = 0.0001*int(tf->GetParameter(0)*sin(phi0)*10000);
2403 double x = tf->GetParameter(0)*cos(phi0);
2404 double y = tf->GetParameter(0)*sin(phi0);
2405 double off = tf->GetParameter(2);
2406
2407 std::cout << "\tx = " << x << std::endl;
2408 std::cout << "\ty = " << y << std::endl;
2409 std::cout << "\toffset = " << off << std::endl;
2410
2411 std::string cckstr = chains[j];
2412
2413 cckstr = cckstr.substr( cckstr.find("HLT_IDTrack") );
2414
2415 std::string vstr = chains[j];
2416
2417 vstr.resize(vstr.find("_boffperf"));
2418 vstr.resize(vstr.find("_L1"));
2419
2420 hf->SetMinimum( -0.03 );
2421 hf->SetMaximum( 0.03 );
2422
2423 tc->cd();
2424
2425 if ( first ) hf->DrawCopy();
2426
2427 hf->DrawCopy("same");
2428 hf->DrawCopy("samee");
2429
2430
2431 DrawLabel( 0.2, 0.89, cckstr );
2432 DrawLabel( 0.2, 0.85, vstr );
2433
2434 DrawLabel( 0.2, 0.81, "x = " + eround(x) + " mm" );
2435 DrawLabel( 0.2, 0.77, "y = " + eround(y) + " mm" );
2436 DrawLabel( 0.2, 0.73, "offset = " + eround(off) + " mm" );
2437
2438 std::string sht = chains[j]+"-"+histo.name()+"-fit.pdf";
2439
2440 size_t p = sht.find("/");
2441
2442 while ( p!=std::string::npos ) {
2443 sht.erase( p, 1 );
2444 p = sht.find("/");
2445 }
2446
2447
2448 gPad->Print( sht.c_str() );
2449 gPad->Print( "sht.pdf" );
2450
2451 std::cout << "CNT !!!" << std::endl;
2452
2453 delete tf;
2454
2455 tp->cd();
2456
2457 gPad = old;
2458
2459 }
2460
2461
2464
2465 TH1F* hreft = 0;
2466
2467 std::cout << "Resplot hreft " << noreftmp << " ... " << std::endl;
2468
2469 if ( !noreftmp ) {
2470 if ( refitref_resplots ) {
2471
2472
2473 std::cout << "Resplot rref: " << href2d_ << std::endl;
2474
2475
2476 Resplot rref("tmp", href2d_ );
2477
2478
2479 std::cout << "Resplot rref: " << href2d_ << " (2)" << std::endl;
2480
2481
2482 if ( rref.finalised() ) {
2483 std::cout << "refitting (2) ..." << std::endl;
2484 if ( contains(histo.name(),"npix") || contains(histo.name(),"nsct") ) rref.Refit(Resplot::FitNull);
2485 else rref.Refit(Resplot::FitNull95);
2486 }
2487 else {
2488 std::cout << "refitting (2 - finalising) ..." << std::endl;
2489 if ( contains(histo.name(),"npix") || contains(histo.name(),"nsct") ) rref.Finalise(Resplot::FitNull);
2490 else rref.Finalise(Resplot::FitNull95);
2491 }
2492
2493 std::cout << "Resplot rref: " << href2d_ << " (3)" << std::endl;
2494
2495
2496 if ( bsigma ) { hreft = (TH1F*)rref.Sigma()->Clone("rref_sigma"); hreft->SetDirectory(0); }
2497 if ( bmean ) { hreft = (TH1F*)rref.Mean()->Clone("rref_mean"); hreft->SetDirectory(0); }
2498
2499 std::cout << "Resplot rref: " << href2d_ << " (4)" << std::endl;
2500
2501
2502 }
2503 else {
2504
2505 std::cout << "Resplot rref: " << href2d_ << " (5)" << std::endl;
2506
2507
2508 hreft = Get( *ffref, refchain[j]+"/"+histo.name(), rawrefrun, chainmap );
2509 if ( hreft==0 ) {
2510 std::cerr << "ERROR: could not find " << (refchain[j]+"/"+histo.name()) << std::endl;
2511 }
2512
2513
2514 }
2515 }
2516
2517 std::cout << "Resplot rref: " << href2d_ << " (6)" << std::endl;
2518
2519
2520 if ( !noreftmp && hreft==0 ) {
2521
2522 std::cerr << "missing ref histogram: " << (refchain[j]+" / "+histo.name()) << " " << htest << "(ref)" << std::endl;
2523
2524 noreftmp = true;
2525 Plotter::setplotref(!noreftmp);
2526 noreflabel="reference not found";
2529 // std::exit(-1);
2530 }
2531
2532 if ( !noreftmp ) {
2533
2534 std::cout << "Resplot rref: " << href2d_ << " (7)" << std::endl;
2535
2536 href = (TH1F*)hreft->Clone();
2537 href->SetDirectory(0);
2538
2539 std::cout << "Resplot href: " << href << " (7a)" << std::endl;
2540
2541 }
2542
2543 std::cout << "Resplot rref: " << href2d_ << " (8)" << std::endl;
2544
2545
2547 // std::cout << "\tget " << (refchain[j]+"/"+histos[i]) << "\t" << href << std::endl;
2548
2549 savedhistos.push_back( refchain[j]+"/"+histo.name() );
2550
2551 std::cout << "Resplot rref: " << href2d_ << " (9)" << std::endl;
2552
2553 }
2554 else {
2555
2557
2558 std::string reghist = histo.name();
2559
2560 std::cout << "hist: " << (chains[j]+"/"+reghist) << "\tftest " << ftest << std::endl;
2561
2562
2563
2564 htest = Get( *fftest, chains[j]+"/"+reghist, testrun, 0, &savedhistos );
2565
2566 std::cout << "\nhist: " << htest << std::endl;
2567
2568 std::cout << "fftest: " << fftest->GetName() << std::endl;
2569
2570
2571 if ( contains( fftest->GetName(), "-mc" ) ) translate_x = false;
2572
2573 if ( lumitest_trans && translate_x && !contains( cc, "-mc" ) ) htest = trans( htest, translate_x );
2574
2575 std::cout << xaxis << std::endl;
2576
2577 if ( htest==0 ) {
2578 std::cerr << "missing test histogram: " << (chains[j]+" / "+reghist) << " " << htest<< std::endl;
2579 continue;
2580 }
2581
2582 testfit( htest, htest->GetName() );
2583
2584
2585 TH1F* hreft = 0;
2586
2587 // std::cout << "hreft: " << hreft << std::endl;
2588
2589
2590 if ( ffref ) hreft = Get( *ffref, refchain[j]+"/"+reghist, rawrefrun, chainmap );
2591 else noreftmp = true;
2592
2593 if ( hreft && lumiref_trans && translate_x && !contains( cr, "-mc" ) ) hreft = trans( hreft, translate_x );
2594
2595 std::cout << "hreft: " << hreft << std::endl;
2596
2597 if ( std::string(htest->ClassName()).find("TH2")!=std::string::npos ) {
2598 std::cout << "Class TH2: " << htest->GetName() << std::endl;
2599 continue;
2600 }
2601
2602
2603 // std::cout << "\n\n\n\n\n!! " << __LINE__ << std::endl;
2604
2605 if ( std::string(htest->ClassName()).find("TH1")!=std::string::npos ) {
2606 std::cout << "Class TH1: " << htest->GetName() << std::endl;
2607 }
2608 else if ( std::string(htest->ClassName()).find("TProfile")!=std::string::npos ) {
2609 std::cout << "Class TProf: " << htest->GetName() << std::endl;
2610 }
2611 else if ( std::string(htest->ClassName()).find("TEfficiency")!=std::string::npos ) {
2612 std::cout << "Class TEff: " << htest->GetName() << std::endl;
2613 }
2614
2615
2616 std::cout << "Resplot hreft: " << hreft << " (10)" << " " << noreftmp << std::endl;
2617
2618 if ( !noreftmp && hreft==0 ) {
2619 std::cerr << "missing ref histogram: " << (refchain[j]+" / "+reghist)
2620 << " " << hreft << std::endl;
2621
2622 noreftmp = true;
2623 Plotter::setplotref(false);
2624 noreflabel="reference not found";
2627 // std::exit(-1);
2628
2629 }
2630
2631 std::cout << "Resplot hreft: " << hreft << " (10)" << std::endl;
2632
2633
2634 if ( hreft!=0 ) {
2635
2636 std::cout << "Resplot hreft: " << hreft->ClassName() << " (11)" << std::endl;
2637
2638 if ( std::string(hreft->ClassName()).find("TH1")!=std::string::npos ) {
2639 href = (TH1F*)hreft->Clone();
2640 href->SetDirectory(0);
2641 }
2642 else if ( isTEfficiency(hreft) ) {
2643 href = makeplot( hreft );
2644 }
2645 }
2646 else {
2647 noreftmp = true;
2648 href = 0;
2649 }
2650
2651 std::cout << " \tget " << (chains[j]+"/"+reghist) << "\thtest " << htest << std::endl;
2652 std::cout << " \tget " << (refchain[j]+"/"+reghist) << "\thref " << href << std::endl;
2653
2654 if ( htest==0 ) continue;
2655
2656 if ( !noreftmp && href==0 ) {
2657 noreftmp = true;
2658 Plotter::setplotref(!noreftmp);
2659 }
2660
2661 if ( fulldbg ) std::cout << __LINE__ << std::endl;
2662
2663
2664 if ( rebin!=1 ) {
2665 std::cout << "rebin: " << hname << "\t" << rebin << std::endl;
2666 if ( htest ) htest->Rebin(rebin);
2667 if ( href ) href->Rebin(rebin);
2668 for ( int ip=0 ; ip<10 ; ip++ ) std::cout << std::endl;
2669 }
2670
2671#if 0
2673 if ( !contains( histo.name(), "rdz_vs_zed" ) && contains( histo.name(), "1d") ) {
2674 std::cout << "Rebinning histogram: " << histo.name() << std::endl;
2675 if ( htest->GetNbinsX()>500 ) htest->Rebin(10);
2676 if ( href && href->GetNbinsX()>500 ) href->Rebin(10);
2677 }
2678#endif
2679
2680
2681 if ( make_efficiencies && histo.name().find("zed_eff")!=std::string::npos ) {
2682 if ( htest->GetNbinsX()>100 ) htest->Rebin(5);
2683 if ( href && href->GetNbinsX()>100 ) href->Rebin(5);
2684 }
2685
2686
2687 if ( fulldbg ) std::cout << __LINE__ << std::endl;
2688
2689 if ( scalepix && std::string(htest->GetName()).find("npix")!=std::string::npos ) Scale(htest,0.5);
2690 if ( scalepix && href && std::string(htest->GetName()).find("npix")!=std::string::npos ) Scale(href,0.5);
2691
2692 if ( fulldbg ) std::cout << __LINE__ << std::endl;
2693
2694 if ( notitle ) {
2695 htest->SetTitle("");
2696 if( href ) href->SetTitle("");
2697 }
2698
2699 if ( fulldbg ) std::cout << __LINE__ << std::endl;
2700
2701 }
2702
2703
2704 std::cout << "done else" << std::endl;
2705
2706 if ( do2D ) continue;
2707
2708 std::cout << "done else:\t" << htest << std::endl;
2709 std::cout << "done else:\t" << htest->GetName() << std::endl;
2710
2711 if ( fulldbg ) std::cout << __LINE__ << std::endl;
2712
2713 if ( !do2D && make_ref_efficiencies ) {
2714
2715 std::cout << "make ref efficiencies" << std::endl;
2716
2717 if ( htest && href ) {
2718
2720 // std::cout << "contains _eff " << contains( std::string(htest->GetName()), "eff" ) << std::endl;
2721
2722 if ( contains( std::string(htest->GetName()), "eff" ) && !contains( std::string(htest->GetName()), "_d" ) ){
2723
2724 std::string effhist = histo.name();
2725
2726
2727
2728 htestnum = Get( *fftest, chains[j]+"/"+effhist+"_n", testrun, 0, &savedhistos );
2729
2730
2731
2732 TH1F* hrefnumt = Get( *ffref, refchain[j]+"/"+effhist+"_n", rawrefrun, chainmap, &savedhistos );
2733
2734
2735
2736 if ( !noreftmp && hrefnumt!=0 ) {
2737 hrefnum = (TH1F*)hrefnumt->Clone();
2738 hrefnum->SetDirectory(0);
2739 }
2740
2741 }
2742 }
2743
2744 }
2745
2746
2747 // std::cout << "done effs ? " << bayes << "\t" << htest->GetName() << std::endl;
2748 std::cout << "done effs ? " << bayes << "\thtest: " << htest << std::endl;
2749
2750 std::cout << "done effs ? " << bayes << "\t" << htest << " :: " << htest->GetName() << std::endl;
2751
2752 if ( bayes ) {
2753
2754 std::cout << "make ref efficiencies" << std::endl;
2755 std::cout << "make ref efficiencies " << htest->GetName() << std::endl;
2756
2757 if ( make_efficiencies && htest && contains( std::string(htest->GetName()), "eff" ) && !contains( std::string(htest->GetName()), "_d" ) ) {
2758
2759 std::string effhist = histo.name();
2760
2762
2763 if ( rebin!=1 ) std::cout << effhist << "\trebin: " << rebin << std::endl;
2764
2765
2766 htestnum = Get( *fftest, chains[j]+"/"+effhist+"_n", testrun, 0, &savedhistos ) ;
2767 htestden = Get( *fftest, chains[j]+"/"+effhist+"_d", testrun, 0, &savedhistos ) ;
2768
2769 if ( htestnum==0 && htestden==0 ) {
2770 TEfficiency* eff = 0;
2771
2772 eff = Get<TEfficiency>( *fftest, chains[j]+"/"+effhist, testrun, 0, &savedhistos ) ;
2773
2774 if ( eff ) {
2775 htestnum = (TH1F*)eff->GetPassedHistogram();
2776 htestden = (TH1F*)eff->GetTotalHistogram();
2777 }
2778
2779 }
2780
2781 std::cout << "eff: htestnum: " << htestnum << "\thtestden: " << htestden << std::endl;
2782
2783
2784 double ars = total_eff( htestnum, htestden );
2785
2786 std::cout << "heff: " << effhist << "\t" << ars << std::endl;
2787
2788
2789 std::cout << "1: Bayesian error calculation " << htestnum << " " << htestden << "\tscale " << scale_eff << std::endl;
2790
2791 if ( htestnum && htestden ) {
2792
2793#ifdef D0REBIN
2796 if ( d0rebin_flag ) {
2797 htestnum = d0rebin( htestnum );
2798 htestden = d0rebin( htestden );
2799 }
2800 else if ( rebin!=1 ) {
2801 htestnum = Rebin(htestnum, rebin );
2802 htestden = Rebin(htestden, rebin );
2803 }
2804#endif
2805 std::cout << "test histogram name: : " << htestnum->GetName() << "\txaxis: " << xaxis << "\t" << std::endl;
2806
2807 if ( make_efficiencies && std::string(htestnum->GetName()).find("ntrax_eff")!=std::string::npos ) {
2808
2809 bool low = true;
2810
2811 htestnum = rebin_log( htestnum, low );
2812 htestden = rebin_log( htestden, low );
2813 }
2814
2815#if 0
2818 if ( contains( htest->GetName(), "_vs_lb" ) ) {
2819 std::cout << "rebin " << histo.name() << std::endl;
2820 htestnum->Rebin(3);
2821 htestden->Rebin(3);
2822 }
2823
2824 if ( make_efficiencies && contains( htest->GetName(), "eta_eff" ) ) {
2825 std::cout << "rebin " << histo.name() << std::endl;
2826 htestnum->Rebin(2);
2827 htestden->Rebin(2);
2828 }
2829
2830#endif
2831
2832 // if ( RANGEMAP && (effhist.find("pT")!=std::string::npos || effhist.find("pt")!=std::string::npos ) ) {
2833 if ( RANGEMAP && (effhist.find("ET")!=std::string::npos ) ) {
2834 std::cout << "\trange: " << j << " " << htest << std::endl;
2835 bnd.range( chains[j], htestnum );
2836 bnd.range( chains[j], htestden );
2837 }
2838
2839 if ( lumitest_trans && translate_x && !contains( cc, "-mc" ) ) {
2840 htestnum = trans( htestnum, translate_x );
2841 htestden = trans( htestden, translate_x );
2842 }
2843
2844 Efficiency1D e( htestnum, htestden, "", scale_eff );
2845
2846 tgtest = e.Bayes(scale_eff);
2847
2848 htest = e.Hist();
2849
2850 htest->SetName( (std::string(htestnum->GetName())+"_eff").c_str() );
2851
2852 std::cout << "effhist: " << effhist << std::endl;
2853
2854 }
2855
2857
2858 std::cout << "recalculating reference efficiencies ..." << std::endl;
2859
2860 if ( href ) {
2861
2862 std::cout << "doin ..." << std::endl;
2863
2864
2865 TH1F* hrefnum = Get( *ffref, refchain[j]+"/"+histo.name()+"_n", rawrefrun, chainmap );
2866 TH1F* hrefden = Get( *ffref, refchain[j]+"/"+histo.name()+"_d", rawrefrun, chainmap );
2867
2868
2869 if ( hrefnum==0 && hrefden==0 ) {
2870 TEfficiency* eff = 0;
2871
2872 eff = Get<TEfficiency>( *ffref, refchain[j]+"/"+histo.name(), rawrefrun, chainmap ) ;
2873
2874 if ( eff ) {
2875 hrefnum = (TH1F*)eff->GetPassedHistogram();
2876 hrefden = (TH1F*)eff->GetTotalHistogram();
2877 }
2878
2879 }
2880
2881
2882
2883 std::cout << "2. Bayesian error calculation " << htestnum << " " << htestden << "\tscale " << scale_eff << std::endl;
2884 std::cout << "3. Bayesian error calculation " << hrefnum << " " << hrefden << "\tscale " << scale_eff_ref << std::endl;
2885
2886
2887 if ( hrefnum && hrefden ) {
2888
2889 if ( lumiref_trans && translate_x && !contains( cr, "-mc" ) ) {
2890 hrefnum = trans( hrefnum, translate_x );
2891 hrefden = trans( hrefden, translate_x );
2892 }
2893
2894#ifdef D0REBIN
2897 if ( d0rebin_flag ) {
2898 hrefnum = d0rebin( hrefnum );
2899 hrefden = d0rebin( hrefden );
2900 }
2901 else if ( rebin!=1 ) {
2902 hrefnum = Rebin(hrefnum, rebin );
2903 hrefden = Rebin(hrefden, rebin );
2904 }
2905#endif
2906
2907 std::cout << hrefnum << " " << hrefden << std::endl;
2908
2909 Efficiency1D e( hrefnum, hrefden, "", scale_eff_ref );
2911 // tgref = e.Bayes(scale_eff);
2912
2913 href = e.Hist();
2914
2915 }
2916 }
2917 }
2918
2919 std::cout << "dbg: htest: " << htest << std::endl;
2920 std::cout << "dbg: htest name " << htest->GetName() << std::endl;
2921
2922 if ( true && histo.name().find("invmass")!=std::string::npos ) {
2923 testfit( htest, histo.name() );
2924 }
2925
2926
2927 }
2928
2929
2930 std::cout << "chains[j] " << chains[j] << std::endl;
2931 std::cout << "histo.name() " << histo.name() << std::endl;
2932 std::cout << "href " << href << "\t (TEfficiency " << isTEfficiency(href) << ")" << std::endl;
2933
2934 if ( isTEfficiency(href) ) {
2935 // TH1F* hrefeff = makeplot<TEfficiency>(href);
2936 TH1F* hrefeff = makeplot(href);
2937 href = hrefeff;
2938 std::cout << "efficiency" << std::endl;
2939 }
2940
2941 std::cout << "href " << href << "\t (TEfficiency " << isTEfficiency(href) << ")" << std::endl;
2942
2943
2944 if ( htest==0 ) {
2945 std::cout << " no test histogram : " << (chains[j]+"/"+histo.name()) << std::endl;
2946 continue;
2947 }
2948
2949
2950 if ( !noreftmp && href==0 ) {
2951 std::cout << " no ref histogram : " << (chains[j]+"/"+histo.name()) << std::endl;
2952 noreftmp = true;
2953 Plotter::setplotref(!noreftmp);
2954 noreflabel="reference not found";
2957 // continue;
2958 }
2959
2960 std::cout << "htest: " << isTEfficiency(htest) << std::endl;
2961
2962 if ( isTEfficiency(htest) ) htest = makeplot(htest);
2963
2964 htest->GetYaxis()->SetTitleOffset(1.55);
2965 htest->GetXaxis()->SetTitleOffset(1.5);
2966 htest->GetXaxis()->SetTitle(xaxis.c_str());
2967 htest->GetYaxis()->SetTitle(yaxis.c_str());
2968
2969 std::cout << "htest: " << htest << "\t" << __LINE__ << std::endl;
2970
2971
2972 if ( !noreftmp ) {
2973
2974 std::cout << "cck: " << -1 << std::endl;
2975
2976 href->GetYaxis()->SetTitleOffset(1.5);
2977
2978 href->GetXaxis()->SetTitleOffset(1.5);
2979
2980 std::cout << "xaxis: " << xaxis << std::endl;
2981
2982 std::cout << "xaxis: " << href->GetXaxis()->GetTitle() << std::endl;
2983
2984 }
2985
2986 std::cout << "cck: " << htest << " CNT" << std::endl;
2987
2988
2989 if ( fulldbg ) std::cout << __LINE__ << std::endl;
2990
2991#if 0
2992 if ( !contains(histo.name(),"vtx_eff") && contains(histo.name(),"ntracks") ) {
2993
2994 double xm = htest->GetMean();
2995
2996 if ( xm>=10 ) {
2997 double lxm = std::log10(xm);
2998 int newbins = int(0.5+xm/std::pow(10,int(lxm)))*pow(10,int(lxm));
2999 int nrebin = int( (newbins+5)/10 );
3000
3001 if ( nrebin>1 ) {
3002 std::cout << "rebin: " << htest->GetName() << "\tbins: " << nrebin << std::endl;
3003 htest->Rebin(nrebin);
3004 htest->Sumw2();
3005 if ( !noreftmp ) {
3006 href->Rebin(nrebin);
3007 href->Sumw2();
3008 }
3009 }
3010 }
3011 }
3012#endif
3013
3014 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3015
3016
3018 if ( plotname == "" ) {
3019
3020 if ( key!="" ) {
3021 htest->SetTitle("");
3022 if ( href ) href->SetTitle("");
3023 plotname = key+"_";
3024 }
3025 else if (fcontains(chains[j],"HLT_")) {
3026 htest->SetTitle("");
3027 if ( href ) href->SetTitle("");
3028 plotname = "HLT_";
3029 }
3030 else if (fcontains(chains[j],"EF_")) {
3031 htest->SetTitle("");
3032 if ( href ) href->SetTitle("");
3033 plotname = "EF_";
3034 }
3035 else if (fcontains(chains[j],"L2_")) {
3036 htest->SetTitle("");
3037 if ( href ) href->SetTitle("");
3038 plotname = "L2_";
3039 }
3040 else if (contains(chains[j],"FTK") && ! contains(chains[j],"HLT_") ) {
3041 htest->SetTitle(("FTK "+ histo.name()).c_str());
3042 if ( href ) href->SetTitle(("FTK "+ histo.name()).c_str());
3043 plotname = "FTK_";
3044 }
3045
3046 plotname += histo.name();
3047
3050 replace(plotname, '/', '_');
3051
3052 }
3053
3054
3055 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3056
3057 bool residual = false;
3058
3059 if ( contains(histo.name(),"_res") || contains(histo.name(),"residual_") || contains(histo.name(),"1d") ) residual = true;
3060
3061 std::string collection = basename( chains[j] );
3062
3063 std::string actual_chain = basename( dirname( chains[j] ) );
3064
3065 if ( collection.find("_InDet")!=std::string::npos ) collection.erase( 0, collection.find("_InDet")+1 );
3066 if ( actual_chain.find("_InDet")!=std::string::npos ) actual_chain.erase( actual_chain.find("_InDet") );
3067
3068
3069 std::cout << "raw: " << chains[j] << std::endl;
3070
3071 std::cout << "track collection: " << collection << std::endl;
3072 std::cout << "actual chain: " << actual_chain << std::endl;
3073
3074 std::regex rx("_HLT_[^_]*RoI.*");
3075 std::regex rx1("_HLT_[^_]*_RoI.*");
3076
3077 std::cout << "\n\n\nactual_chain: " << actual_chain << std::endl;
3078
3079 arsaway( actual_chain, "_L1.*", "" );
3080 arsaway( actual_chain, "L1.*", "" );
3081
3082 actual_chain = std::regex_replace( actual_chain, std::regex( "L1.*:" ), "" );
3083
3084 if ( actual_chain.find("jvt")!=std::string::npos ) actual_chain.erase(
3085 actual_chain.find("jvt"),
3086 actual_chain.find("HLT_IDTrack")-actual_chain.find("jvt") );
3087
3088 std::cout << " : " << actual_chain << "\n\n\n" << std::endl;
3089
3090
3091 actual_chain = std::regex_replace( actual_chain, std::regex( "_HLT_IDTrack.*" ), "" );
3092
3093
3094 collection = std::regex_replace( collection, std::regex(".*HLT_IDTrack_"), "IDTrack " );
3095 collection = std::regex_replace( collection, std::regex("IDTrack "), "" );
3096 collection = std::regex_replace( std::regex_replace( collection, rx, "" ), rx1, "" );
3097
3098 if ( actual_chain.find("HLT_IDTrack_")!=std::string::npos ) actual_chain.erase( actual_chain.find("HLT_IDTrack_"), 12 );
3099 if ( actual_chain.find("_IDTrack_")!=std::string::npos ) actual_chain.erase( actual_chain.find("_IDTrack_"), 9 );
3100 if ( actual_chain.find("IDTrack")!=std::string::npos ) actual_chain.erase( actual_chain.find("IDTrack"), 7 );
3101 if ( actual_chain.find("_idperf")!=std::string::npos ) actual_chain.erase( actual_chain.find("_idperf"), 7 );
3102 if ( actual_chain.find("_bperf")!=std::string::npos ) actual_chain.erase( actual_chain.find("_bperf"), 6 );
3103 if ( actual_chain.find("_boffperf")!=std::string::npos ) actual_chain.erase( actual_chain.find("_boffperf"), 9 );
3104 if ( actual_chain.find("_HLT_")!=std::string::npos ) actual_chain.replace( actual_chain.find("_HLT_"), 5, " " );
3105 if ( actual_chain.find("HLT_")!=std::string::npos ) actual_chain.erase( actual_chain.find("HLT_"), 4 );
3106
3107
3108
3109 if ( collection.find("_IDTrkNoCut")!=std::string::npos ) collection.erase( collection.find("_IDTrkNoCut"), 11 );
3110 if ( collection.find("xAODCnv")!=std::string::npos ) collection.erase( collection.find("xAODCnv"), 7 );
3111 if ( collection.find("HLT_IDTrack_")!=std::string::npos ) collection.erase( collection.find("HLT_IDTrack_"), 12 );
3112 if ( collection.find("HLT_IDTrack")!=std::string::npos ) collection.erase( collection.find("HLT_IDTrack"), 11 );
3113 if ( collection.find("Tracking")!=std::string::npos ) collection.replace( collection.find("Tracking"), 8, "Trk" );
3114 if ( collection.find("InDetTrigTrk_")!=std::string::npos ) collection.erase( collection.find("InDetTrigTrk_"), 13 );
3115 if ( collection.find("HLT_xAODTracks_")!=std::string::npos ) collection.erase( collection.find("HLT_xAODTracks_"), 15 );
3116 if ( collection.find("_HLT_")!=std::string::npos ) collection.replace( collection.find("_HLT_"), 5, " " );
3117 if ( collection.find("HLT_")!=std::string::npos ) collection.erase( collection.find("HLT_"), 4 );
3118
3119 std::string c = actual_chain + " : " + collection;
3120
3121 std::cout << "track collection: " << collection << " <-" << std::endl;
3122 std::cout << "actual chain: " << actual_chain << " <-" << std::endl;
3123
3124 replace( c, "_In", " : " );
3125
3126 c = " " + c;
3127
3128 std::cout << "use label: " << c << "\tchains size " << chains.size() << "\t" << usrlabels.size() << std::endl;
3129
3130 std::cout << "chains.size() " << chains.size() << " " << j << std::endl;
3131 std::cout << "chains.size() " << chains.size() << " " << j << std::endl;
3132
3133 std::cout << "chains[j] : " << j << " " << chains[j] << std::endl;
3134
3135 std::cout << "userlabels.size() " << usrlabels.size() << std::endl;
3136
3137 if ( usrlabels.size() < j+1 ) {
3138 if ( usrlabels.size()!=0 ) std::cerr << "userlabels not large enough - not using userlabels" << std::endl;
3139 }
3140 else c = usrlabels[ j ];
3141
3142 std::cout << "use label: c: " << c << std::endl;
3143
3145
3146 // std::cout << "adding plot " << histos[i] << " " << htest->GetName() << std::endl;
3147
3148 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3149
3150
3151
3152 std::cout << "\n\n\n\nxaxis: " << xaxis << std::endl;
3153
3154
3155
3156 if ( ALLRANGEMAP || xaxis.find("p_{T}")!=std::string::npos || xaxis.find("E_{T}")!=std::string::npos ) {
3157
3158 if ( RANGEMAP && xaxis.find("p_{T}")!=std::string::npos ) {
3159 bnd.range( chains[j], htest );
3160 if ( href ) bnd.range( chains[j], href );
3161 }
3162
3163 if ( RANGEMAP || ALLRANGEMAP ) {
3164
3165 LINEF = false;
3166
3167 std::cout << "\n\n\nctags " << ctags.size() << "\n\n" << std::endl;
3168
3169 for ( size_t ic=0 ; ic<ctags.size() ; ic++ ) {
3170
3171 // std::cout << "\tctags[" << ic << "] = " << ctags[ic] << std::endl;
3172
3173 std::cout << "\n\nic: " << ic << " " << ctags[ic] << " " << ccolours[ic] << "\n\n" << std::endl;
3174
3175 if ( chains[j].find(ctags[ic])!=std::string::npos ) {
3176 std::cout << "\ttag " << ctags[ic] << " \tcolour: " << ccolours[ic] << "\tstyle: " << cstyles[ic] << std::endl;
3177 htest->SetLineColor( ccolours[ic] );
3178 htest->SetMarkerColor( ccolours[ic] );
3179 htest->SetMarkerStyle( cstyles[ic] );
3180 c = ctaglabels[ic];
3181 if ( tgtest ) {
3182 tgtest->SetLineColor(htest->GetMarkerColor());
3183 tgtest->SetMarkerStyle(htest->GetMarkerStyle());
3184 tgtest->SetMarkerColor(htest->GetMarkerColor());
3185 }
3186 break;
3187 }
3188 }
3189
3190 }
3191
3192 std::cout << "test: " << chains[j] << "chains colour: " << htest->GetMarkerColor() << std::endl;
3193
3194 }
3195
3196
3197
3198 std::cout << "movin' on ..." << std::endl;
3199
3200 std::cout << "chain: " << chains[j] << " \t marker colour: " << htest->GetMarkerColor() << std::endl;
3201
3202 // std::exit(0);
3203
3204 std::cout << "Plotter marker : " << htest->GetMarkerColor() << " " << htest->GetMarkerStyle() << std::endl;
3205
3206 std::cout << "SHT CNT " << htest << std::endl;
3207
3208 // if ( uselabels ) plots.push_back( Plotter( htest, href, chain_name+usrlabels[j], tgtest ) );
3209 if ( uselabels ) plots.push_back( Plotter( htest, href, " " + chain_name[j] + c, tgtest ) );
3210 else {
3211 std::cout << "using label: " << c << std::endl;
3212 plots.push_back( Plotter( htest, href, c, tgtest ) );
3213 }
3214
3215 std::cout << "AxisInfo: " << xaxis << std::endl;
3216
3217 plots.back().xaxis( &(histo.xaxis()) );
3218 plots.back().yaxis( &(histo.yaxis()) );
3219
3220 std::cout << "c: " << c << "\t" << ftest->GetName() << std::endl;
3221
3222 if ( contains( c, "MC" ) || contains( ftest->GetName(), "-mc") ) {
3223 plots.back().mc( true );
3224 translate_x = false;
3225 }
3226
3227
3228
3229 if ( ALLRANGEMAP || ( RANGEMAP && xaxis.find("p_{T}")!=std::string::npos ) ) plots.back().max_entries( ccolours.size() );
3230
3231 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3232
3233 if ( make_ref_efficiencies ) {
3234
3235 if ( htestnum && hrefnum ) {
3236 Efficiency1D e( htestnum, hrefnum, "", scale_eff );
3237
3238 TH1* h = e.Hist();
3239
3240 double range = h->GetMaximum()-h->GetMinimum();
3241
3242 if ( range<0.2*scale_eff ) {
3243
3244 double fmax = int( (h->GetMaximum() + 20)*0.1 )*0.1*scale_eff;
3245 double fmin = int( (h->GetMinimum() - 10)*0.1 )*0.1*scale_eff;
3246
3247 if ( fmax>1*scale_eff ) fmax = 1.02*scale_eff;
3248 if ( fmin<0 ) fmin = 0;
3249
3250 h->SetMinimum(fmin);
3251 h->SetMaximum(fmax);
3252
3253 }
3254
3255 plots_eff.push_back( Plotter( e.Hist(), 0, c ) );
3256
3257 }
3258 }
3259
3260
3261 std::cout << "means: " << drawmeans << " " << means << std::endl;
3262
3263 std::cout << "chi2: " << std::endl;
3264
3265 std::cout << "htest " << htest << std::endl;
3266 std::cout << "href " << href << std::endl;
3267
3268 std::cout << "chi2: " << chi2( htest, href ) << "\t histo name: " << histo.name() << std::endl;
3269
3270 testfit( htest, histo.name() );
3271
3272
3273 if ( href ) Chi2.push_back( label( "chi2 = %5.2lf / %2.0lf", chi2( htest, href ), double(htest->GetNbinsX()) ) );
3274
3275 std::cout << "Chi2.push_back()" << std::endl;
3276
3277 if ( drawmeans || means ) {
3278
3279 double mean_95 = htest->GetMean();
3280 double dmean_95 = htest->GetMeanError();
3281 double rms_95 = htest->GetRMS();
3282 double drms_95 = htest->GetRMSError();
3283
3284 Mean.push_back(label(" mean = %4.2lf #pm %4.2lf", mean_95, dmean_95) );
3285 // MeanLF.push_back(label(" mean = %6.4lf #pm %6.4lf", mean_95, dmean_95) );
3286 MeanLF.push_back(label("mean = %6.4lf #pm %6.4lf", mean_95, dmean_95) );
3287 RMS.push_back(label( " rms = %4.2lf #pm %4.2lf", rms_95, drms_95 ) );
3288
3289 }
3290
3291 std::cout << "residual: " << residual << " " << drawresiduals << std::endl;
3292
3293 if ( residual && drawresiduals ) {
3294
3296
3297 xpos = xpos_original;
3298
3299 std::cout << "calculating resolutions : " << histo.name() << " " << htest->GetName() << std::endl;
3300
3301 TF1* d95 = Resplot::FitNull95(reinterpret_cast<TH1D*>(htest));
3302
3303 double mean_95 = d95->GetParameter(1);
3304 double dmean_95 = d95->GetParError(1);
3305 double rms_95 = d95->GetParameter(2);
3306 double drms_95 = d95->GetParError(2);
3307
3308 std::cout << "\t\t" << histo.name()
3309 << "\tmean: " << mean_95 << " +- " << dmean_95
3310 << "\trms: " << rms_95 << " +- " << drms_95 << std::endl;
3311
3313
3314 if ( !power_set ) {
3315 for ( int ip=-2 ; ip<9 ; ip++ ) {
3316 if ( std::fabs(mean_95) >= std::pow( 10., double(-ip) ) ) {
3317 mean_power = ip;
3318 break;
3319 }
3320 }
3321
3322 for ( int ip=-2 ; ip<9 ; ip++ ) {
3323 if ( std::fabs(rms_95) >= std::pow( 10., double(-ip) ) ) {
3324 rms_power = ip;
3325 break;
3326 }
3327 }
3328 }
3329
3330 power_set = true;
3331
3332 std::cout << "\t\t" << histo.name()
3333 << "\tmean: " << mean_95 << " +- " << dmean_95 << " : pow " << mean_power
3334 << "\trms: " << rms_95 << " +- " << drms_95 << " : pow " << rms_power << std::endl;
3335
3336
3337 if ( mean_power == 0 ) {
3338 Mean.push_back(label("mean_{95} = %4.2lf #pm %4.2lf", mean_95, dmean_95) );
3339 }
3340 else {
3341 Mean.push_back(label("mean_{95} = ( %4.2lf #pm %4.2lf ) #times 10^{%d}",
3342 mean_95*std::pow(10.,double(mean_power)), dmean_95*std::pow(10,double(mean_power)), -mean_power ) );
3343
3344 }
3345
3346 if ( rms_power == 0 ) {
3347 RMS.push_back(label( "rms_{95} = %4.2lf #pm %4.2lf", rms_95, drms_95 ) );
3348 }
3349 else {
3350 RMS.push_back(label( "rms_{95} = ( %4.2lf #pm %4.2lf ) #times 10^{%d}",
3351 rms_95*std::pow(10.,double(rms_power)), drms_95*std::pow(10,double(rms_power)), -rms_power ) );
3352 }
3353
3354 if ( href ) {
3355 TF1* d95ref = Resplot::FitNull95(reinterpret_cast<TH1D*>(href));
3356
3357 double mean_95ref = d95ref->GetParameter(1);
3358 double dmean_95ref = d95ref->GetParError(1);
3359 double rms_95ref = d95ref->GetParameter(2);
3360 double drms_95ref = d95ref->GetParError(2);
3361
3362 std::cout << "\t\t" << histo.name()
3363 << "\tmean ref: " << mean_95ref << " +- " << dmean_95ref << " : pow " << mean_power
3364 << "\trms ref: " << rms_95ref << " +- " << drms_95ref << " : pow " << rms_power << std::endl;
3365
3366 if ( mean_power == 0 ) {
3367 MeanRef.push_back(label("mean_{95} ref = %4.2lf #pm %4.2lf", mean_95ref, dmean_95ref) );
3368 }
3369 else {
3370 MeanRef.push_back(label("mean_{95} ref = ( %4.2lf #pm %4.2lf ) #times 10^{%d}",
3371 mean_95ref*std::pow(10,double(mean_power)), dmean_95ref*std::pow(10,double(mean_power)), -mean_power ) );
3372
3373 }
3374
3375
3376 if ( rms_power == 0 ) {
3377 RMSRef.push_back(label( "rms_{95} ref = %4.2lf #pm %4.2lf", rms_95ref, drms_95ref ) );
3378 }
3379 else {
3380 RMSRef.push_back(label( "rms_{95} ref = ( %4.2lf #pm %4.2lf ) #times 10^{%d}",
3381 rms_95ref*std::pow(10,double(rms_power)), drms_95ref*std::pow(10,double(rms_power)), -rms_power ) );
3382 }
3383 }
3384
3385 htest->Sumw2();
3386 if ( href ) href->Sumw2();
3387 }
3388
3389 if ( yinfo.normset() ) {
3390 Norm( htest );
3391 if ( href ) Norm( href );
3392 if ( xinfo.rangeset() ) {
3393 Norm( htest, 1, xinfo.lo(), xinfo.hi() );
3394 if ( href ) Norm( href, 1, xinfo.lo(), xinfo.hi() );
3395 }
3396 }
3397 else if ( yinfo.refnormset() ) {
3398 if ( href ) {
3399 Norm( href, Entries(htest) );
3400 if ( xinfo.rangeset() ) {
3401 Norm( href, 1, xinfo.lo(), xinfo.hi() );
3402 }
3403 }
3404 }
3405
3406 if ( yinfo.binwidth() ) {
3407 binwidth( htest );
3408 if ( href ) binwidth( href );
3409 }
3410
3411 if ( !noreftmp && normref &&
3412 !contains( histo.name(), "mean") && !contains( histo.name(), "sigma" ) &&
3413 !contains( histo.name(), "Eff") && !contains( histo.name(), "eff") &&
3414 !contains( histo.name(), "Res") && !contains( histo.name(), "vs") && !contains( histo.name(), "_lb") ) {
3415 Norm( href, Entries( htest ) );
3416 }
3417
3418 }
3419
3420 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3421
3422 if ( !noplots ) {
3423
3426
3427 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3428
3429 std::cout << "duff: " << xinfo << std::endl;
3430
3432 plots.sortx( xinfo );
3433
3434 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3435
3436 double yminset = 0;
3437 double ymaxset = 0;
3438
3439 double rmin = 0;
3440 double rmax = 0;
3441
3442 if ( xinfo.rangeset() ) {
3443 rmin = plots.realmin( plots.lo(), plots.hi() );
3444 rmax = plots.realmax( plots.lo(), plots.hi() );
3447 // if ( yinfo.normset() ) {
3448 // Norm( htest, 1, rmin, rmax );
3449 // if ( href ) Norm( href, 1, rmin, rmax );
3450 // }
3451 }
3452 else {
3453 rmin = plots.realmin();
3454 rmax = plots.realmax();
3455 }
3456
3457 if ( yinfo.autoset() ) {
3458
3459 int csize = chains.size() + taglabels.size() + ( atlasstyle ? 1 : 0 );
3460
3461 if ( yinfo.log() && rmin>0 && rmax>0 ) {
3462
3464 double delta = std::log10(rmax)-std::log10(rmin);
3465
3467 // ymaxset = rmax*std::pow(10,delta*0.15*csize);
3468
3469 yminset = rmin*std::pow(10,-delta*0.1);
3470
3471 double newdelta = std::log10(rmax) - std::log10(yminset) + 0.05*delta;
3472
3473 if ( csize<10 ) ymaxset = rmin*std::pow(10,newdelta/(1-0.07*csize));
3474 else ymaxset = rmin*std::pow(10,newdelta*2);
3475
3476 if ( yminset!=yminset ) {
3477 std::cerr << " range error " << delta << " " << yminset << " " << ymaxset << "\t(" << rmin << " " << rmax << ")" << std::endl;
3481 continue;
3482 }
3483
3484 }
3485 else {
3486
3489
3490 if ( ypos>0.5 ) {
3491 double delta = rmax-rmin;
3492
3493 yminset = rmin-0.1*delta;
3494
3495 if ( rmin>=0 && yminset<=0 ) yminset = 0;
3496
3497 double newdelta = rmax - yminset + 0.05*delta;
3498
3499 if ( csize<10 ) ymaxset = yminset + newdelta/(1-0.09*csize);
3500 else ymaxset = yminset + newdelta*2;
3501 }
3502 else {
3503 double delta = rmax-rmin;
3504
3505 ymaxset = rmax+0.1*delta;
3506
3507 double newdelta = ymaxset - rmin - 0.05*delta;
3508
3509 if ( csize<10 ) yminset = ymaxset - newdelta/(1-0.09*csize);
3510 else yminset = ymaxset - newdelta*2;
3511
3512 if ( rmin>=0 && yminset<=0 ) yminset = 0;
3513
3514 }
3515
3516 }
3517
3518 }
3519 else {
3520 if ( yinfo.rangeset() ) {
3521 yminset = yinfo.lo();
3522 ymaxset = yinfo.hi();
3523 }
3524 }
3525
3526 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3527
3528 // more useful debugging ...
3529 // std::cout << "yauto: " << yinfo.autoset() << "\tyrange " << yinfo.rangeset() << std::endl;
3530
3531 // std::cout << "yminset " << yminset << "\tymaxset " << ymaxset << std::endl;
3532
3533 if ( yinfo.autoset() && yinfo.rangeset() ) {
3534
3535 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3536
3537 if ( yminset>yinfo.lo() ) yminset = yinfo.lo();
3538 if ( ymaxset<yinfo.hi() ) ymaxset = yinfo.hi();
3539 }
3540
3541
3542 if ( make_efficiencies && contains(histo.name(),"_eff") ) {
3543
3544 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3545
3546 if ( effset ) {
3547 ymaxset = effmax;
3548 yminset = effmin;
3549 }
3550 }
3551
3552 if ( ymaxset!=0 || yminset!=0 ) {
3553
3554 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3555
3556 plots.Max( ymaxset );
3557 plots.Min( yminset );
3558 }
3559
3560 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3561
3562 if ( yminset!=0 || ymaxset!=0 ) {
3563 if ( yminset>0 ) plots.SetLogy(yinfo.log());
3564 else plots.SetLogy(false);
3565 }
3566 else plots.SetLogy(yinfo.log());
3567
3568 // plots.SetLogy(false);
3569
3570 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3571
3572 // plots.limits();
3573
3575
3576 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3577
3578 plots.Draw( legend );
3579
3580 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3581
3582 if ( atlasstyle ) ATLASLabel( xpos, ypositions[0]+deltay, atlaslabel, labelcolour, ncolsp, nrowsp );
3583
3584 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3585
3586 for ( unsigned it=0 ; it<taglabels.size() ; it++ ) {
3587 DrawLabel( xpos, ypositions[it], taglabels[it], labelcolour, 0.04 );
3588 }
3589
3590 for ( unsigned it=0 ; it<taglabels2.size() ; it++ ) {
3591 DrawLabel( xpos+0.35, ypositions2[it], taglabels2[it], labelcolour, 0.04 );
3592 }
3593
3594 }
3595
3596 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3597
3598 std::cout << "means: " << means << std::endl;
3599
3600 // if ( means ) for ( unsigned j=0 ; j<MeanLF.size() ; j++ ) DrawLabel( 0.5, (0.65-(j+chains.size()-1)*0.035), MeanLF[j], colours[j%6] ); // DrawLabel( 0.75, 0.85-j*0.035, Chi2[j], colours[j%6] );
3601 if ( means ) {
3602 if ( runnumber!="" ) DrawLabel( 0.2, 0.89, "run "+runnumber );
3603 for ( unsigned j=0 ; j<MeanLF.size() ; j++ ) DrawLabel( 0.2, (0.85-(j+chains.size()-1)*0.035), MeanLF[j], colours[j%6] );
3604 }
3605
3606
3607 // double ytop = 0.67;
3608 double ytop = 0.5;
3609
3610 if ( ( !nostats || !nomeans ) && !noplots ) {
3611 if ( dochi2 ) for ( unsigned j=0 ; j<Chi2.size() ; j++ ) DrawLabel( 0.75, 0.85-j*0.035, Chi2[j], colours[j%6] );
3612 if ( ( (contains(histo.name(),"_res") ||
3613 contains(histo.name(),"1d") ||
3614 histo.name()=="pT" ||
3615 contains(histo.name(),"residual_") ||
3616 contains(histo.name(),"vs_pt") ) && !contains(histo.name(),"sigma") ) || drawmeans ) {
3617
3618 if ( contains(histo.name(),"_res") || contains(histo.name(),"residual_") || contains(histo.name(),"1d") || drawresiduals ) {
3619 for ( unsigned j=0 ; j<chains.size() ; j++ ) {
3620 if ( !noreftmp ) {
3621 if ( j<MeanRef.size() ) {
3622 if ( !nomeans ) DrawLabel( xpos_original, (ytop-j*0.035), MeanRef[j], colours[j%6] );
3623 DrawLabel( xpos_original, (ytop-0.035*chains.size()-j*0.035)-0.01, RMSRef[j], colours[j%6] );
3624 }
3625 }
3626 if ( j<Mean.size() ) {
3627 if ( !nomeans ) DrawLabel( 0.62, (ytop-j*0.035), Mean[j], colours[j%6] );
3628 DrawLabel( 0.62, (ytop-0.035*chains.size()-j*0.035)-0.01, RMS[j], colours[j%6] );
3629 }
3630 }
3631 }
3632 }
3633 }
3634
3635 if ( xinfo.log() ) gPad->SetLogx(true);
3636 else gPad->SetLogx(false);
3637
3638 if ( yinfo.log() ) gPad->SetLogy(true);
3639 else gPad->SetLogy(false);
3640
3641 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3642
3643 if ( !noplots ) {
3644
3645 if ( make_ref_efficiencies ) {
3646
3647 plots_eff.SetXaxisTitle( plots.GetXaxisTitle() );
3648 plots_eff.SetYaxisTitle( plots.GetYaxisTitle() );
3649
3650 plots_eff.Draw( legend_eff );
3651 }
3652
3653 if ( !noreflabel.empty() ) DrawLabel(0.1, 0.06, noreflabel, kRed, 0.03 );
3654
3655 } // no plots
3656
3657 }
3658
3659
3665
3666 if ( !noplots ) {
3667
3668 if ( !quiet ) {
3669
3670 tc->cd();
3671
3672 std::string useplotname;
3673
3674 if ( panel.size()>1 ) {
3675 useplotname = panel.name();
3676 replace( useplotname, '/', '_' );
3677 }
3678 else {
3679 useplotname = plotname;
3680 }
3681
3682 useplotname.erase( std::remove( useplotname.begin(), useplotname.end(), '+' ), useplotname.end() );
3683
3684 // std::string printbase = dir+"HLT_"+ppanelname+tag;
3685 std::string printbase = dir + useplotname + tag;
3686
3687 tc->Update();
3688
3689 if ( !nopdf ) print_pad( printbase+".pdf" );
3690 if ( !nopng ) print_pad( printbase+".png" );
3691 if ( Cfile ) print_pad( printbase+".C" );
3692
3693 std::cout << std::endl;
3694 }
3695
3696 }
3697
3698 if ( tc ) delete tc;
3699
3700 }
3701
3702
3703 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3704
3706
3707
3709 bool files_duplicated = ( fref_==ftest_ );
3710
3711 if ( deleteref && !files_duplicated ) {
3712
3713 if ( fref_ ) {
3714
3716
3717 std::cout << "main() cleaning up reference file" << std::endl;
3718
3719 TFile* newout = new TFile(".newout.root","recreate");
3720 newout->cd();
3721
3723 copyReleaseInfo( fref, newout );
3724
3725 TDirectory* base = gDirectory;
3726
3727 for ( unsigned i=0 ; i<savedhistos.size() ; i++ ) {
3728
3730 // std::cout << i << " " << savedhistos[i] << std::endl;
3731
3732 std::vector<std::string> dirs = AxisInfo::split( savedhistos[i], "/" );
3733
3734 for ( unsigned j=0 ; j<dirs.size()-1 ; j++ ) {
3735 std::cout << "\t" << dirs[j] << std::endl;
3736 TDirectory* renedir = gDirectory->GetDirectory( dirs[j].c_str() );
3737 if ( renedir==0 ) gDirectory->mkdir( dirs[j].c_str() );
3738 gDirectory->cd( dirs[j].c_str() );
3739 }
3740
3741
3742
3743 // TH1* href = (TH1*)fref->Get( savedhistos[i].c_str() );
3744 TH1* href = Get( *fref, savedhistos[i].c_str(), "", chainmap );
3745 if ( !noreftmp && href ) {
3746 std::cout << i << " " << savedhistos[i] << " 0x" << href << std::endl;
3747 href->Write( dirs.back().c_str() );
3748 }
3749
3750
3751
3752 base->cd();
3753 }
3754
3755 newout->Close();
3756
3757 }
3758 }
3759
3760
3761 if ( fulldbg ) std::cout << __LINE__ << std::endl;
3762
3764
3765 if ( fref_ && !files_duplicated ) fref_->Close();
3766 if ( ftest_ ) ftest_->Close();
3767
3769
3770 if ( deleteref && !noref ) {
3771 std::cout << "ref " << frefname << "\ttest " << ftestname << std::endl;
3772 if ( frefname != ftestname && !files_duplicated ) {
3773 std::string cmd = std::string("mv ") + frefname + " " + frefname + ".bak";
3774 std::system( cmd.c_str() );
3775
3776 cmd = std::string("mv .newout.root ") + std::string(frefname);
3777 std::system( cmd.c_str() );
3778 }
3779 else {
3780 std::cerr << "reference file and test file are the same - not replacing" << std::endl;
3781 }
3782 }
3783
3784 // std::cout << "deleting " << __LINE__ << std::endl;
3785
3786 if ( fref_ && !files_duplicated ) delete fref_;
3787 if ( ftest_ ) delete ftest_;
3788
3789 return 0;
3790}
int DrawLabel(float xstart, float ystart, string label)
TStyle * AtlasStyle()
static Double_t ss
static Double_t tc
static Double_t rc
void ATLASLabel(Double_t x, Double_t y, char *text=NULL, Color_t color=1)
const double width
ATLAS Style, based on a style file from BaBar.
#define y
#define x
Header file for AthHistogramAlgorithm.
class to store information about axes, limits, whether it is log or linear scale etc
Definition computils.h:154
bool autoset() const
Definition computils.h:256
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
double hi() const
Definition computils.h:273
bool log() const
Definition computils.h:254
static std::vector< std::string > split(const std::string &s, const std::string &t=":")
Definition computils.h:285
double offset() const
Definition computils.h:269
bool normset() const
Definition computils.h:258
double lo() const
Definition computils.h:272
details of the histogram axes etc
Definition computils.h:1568
slightly more convenient legend class
Definition computils.h:344
int ncols() const
Definition computils.h:1665
size_t size() const
Definition computils.h:1656
const std::string & name() const
Definition computils.h:1654
int nrows() const
Definition computils.h:1664
set of generic plots
Definition computils.h:1210
void SetXaxisTitle(const std::string &s)
Definition computils.h:1516
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
void Draw(Legend &leg, bool means=false)
Definition computils.h:1452
void SetYaxisTitle(const std::string &s)
Definition computils.h:1520
static void setwatermark(bool b)
Definition computils.h:1533
Get tag-value pairs from a file.
Definition ReadCards.h:50
int Finalise(double a=-999, double b=-999, TF1 *(*func)(TH1D *s, double a, double b)=Resplot::FitGaussian)
Definition Resplot.cxx:389
static bool setscalerms95(bool b)
Definition Resplot.h:556
int Refit(TF1 *(*func)(TH1D *s, double a, double b))
Definition Resplot.h:442
static TF1 * FitNull(TH1D *s, double a=-999, double b=-999)
Definition Resplot.cxx:1267
static TF1 * FitNull95(TH1D *s, double a=0, double b=0)
Definition Resplot.cxx:1657
static bool setoldrms95(bool b)
Definition Resplot.h:555
bool finalised() const
Definition Resplot.h:369
TH1D * Sigma()
Definition Resplot.h:351
TH1D * Mean()
Definition Resplot.h:347
std::vector< std::string > m_labels
bands(const std::vector< double > &limits, const std::vector< std::string > &labels)
bands(const bands &b)=default
bands & operator=(const bands &b)=default
void range(const std::string &chain, TH1F *h)
std::vector< double > m_limits
void range(size_t i, TH1F *h)
static void setplotref(bool b)
Definition computils.h:1137
void ascale(TH1F *h, double s_)
void autoy(TH2 *h)
get the auto y range of a 2d histogram
TH1F * rebin_log(TH1F *h, bool low=false)
void normaliseBinWidth(TH1 *h)
bool EPS
bool fulldbg
void zero(TH2 *h)
zero the contents of a 2d histogram
bool LINES
Definition computils.cxx:41
void normy(TH2 *h)
zero the contents of a 2d histogram
TH1F * trans(TH1F *h, bool t=false)
void print_pad(const std::string &s)
int markers[6]
Definition computils.cxx:49
void arsaway(std::string &s, const std::string &pattern, const std::string &rep)
void testfit(TH1 *htest, const std::string &s)
bool isTEfficiency(T *h)
const std::string reset
double total_eff(TH1 *hn, TH1 *hd)
std::string fullreplace(std::string s, const std::string &s2, const std::string &s3)
void ifdbg(const std::string &)
TCanvas * fitcanvas
void autox(TH2 *h, bool t=false)
get the auto x range of a 2d histogram
TH1F * d0rebin(TH1F *h)
bool LINEF
Definition computils.cxx:40
std::map< std::string, std::string > chainmap_t
global typedef here is ok, since this is a standalone executable, including a main().
double chi2(TH1 *h0, TH1 *h1)
TH1F * makeplot(TObject *hreft)
TH1F * Rebin(TH1F *h, double f)
TCanvas * fitcanvas_rec
std::string eround(double x, int decfigs=4)
void Scale(TH1 *h, double d=1)
void SetZeros(TH2D *h)
int colours[6]
Definition computils.cxx:48
T * Get(TFile &f, const std::string &n, const std::string &dir="", const chainmap_t *chainmap=0, std::vector< std::string > *saved=0)
get a histogram given a path, and an optional initial directory if histogram is not found,...
void copyReleaseInfo(TFile *finput, TFile *foutdir)
copy the release info TTree
void contents(std::vector< std::string > &keys, TDirectory *td, const std::string &directory, const std::string &pattern, const std::string &path)
void Norm(TH1 *h, double scale, double xmin, double xmax)
double Entries(TH1 *h)
std::string findrun(TFile *f)
bool exists(const std::string &filename)
does a file exist
bool JLflag
Definition computils.cxx:44
bool fcontains(const std::string &s, const std::string &p)
contains a string at the beginning of the string
tPlotter< TH1F > Plotter
Definition computils.h:1179
static std::string release
Definition computils.h:54
std::string diff_panel[10][6]
std::string res_panel[4][6]
std::string eff_panel[4][6]
StatusCode usage()
std::vector< std::string > savedhistos
Definition hcg.cxx:55
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:312
bool contains(const std::string &s, const std::string &regx)
does a string contain the substring
Definition hcg.cxx:116
std::string find(const std::string &s)
return a remapped string
Definition hcg.cxx:140
std::string base
Definition hcg.cxx:83
std::map< std::string, int > dirs
list of directories to be explicitly included, together with corresponding depths of subdirectories
Definition hcg.cxx:104
std::string chop(std::string &s1, const std::string &s2)
Definition hcg.cxx:163
int main()
Definition hello.cxx:18
static std::vector< uint32_t > runnumber
Definition iLumiCalc.h:37
std::string label(const std::string &format, int i)
Definition label.h:19
bool binwidth
Definition listroot.cxx:58
DataModel_detail::iterator< DVL > remove(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end, const T &value)
Specialization of remove for DataVector/List.
TFile * file
std::string dirname(std::string name)
Definition utils.cxx:200
std::string basename(std::string name)
Definition utils.cxx:207