17 #include <sys/types.h>
49 #include "TPaveStats.h"
71 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
72 for (
int j=1 ; j<=
h->GetNbinsY() ; j++ ) {
73 int ibin =
h->GetBin(
i, j );
74 if (
h->GetBinContent(ibin)==0 )
h->SetBinContent(ibin, 0.1);
81 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
82 h->SetBinContent(
i,
h->GetBinContent(
i)*
d );
83 h->SetBinError(
i,
h->GetBinError(
i)*
d );
90 std::cout <<
"\nREBIN: " <<
h->GetName() <<
" :: " <<
f << std::endl;
93 TH1F*
n = (
TH1F*)
h->Clone(
"foeda");
n->SetDirectory(0);
101 for (
int i=0 ;
i<10 ;
i++ ) {
103 if ( std::fabs(
int(fb)-fb)<1
e-6 )
break;
106 std::vector<double> limits;
109 for (
int i=1 ;
i<=
h->GetNbinsX()+1 ;
i++ ) {
110 limits.push_back(
h->GetBinLowEdge(
i) );
117 TH1F*
n =
new TH1F(
"foeda",
h->GetTitle(), limits.size()-1, &limits[0] );
n->SetDirectory(0);
129 double limits[40] = {
130 0.5, 1.5, 2.5, 3.5, 4.5,
131 5.5, 6.5, 7.5, 8.5, 9.5,
132 10.5, 11.5, 12.5, 13.5, 14.5,
133 15.5, 16.5, 17.5, 18.5, 19.5,
134 20.5, 21.5, 22.5, 23.5, 24.5,
135 25.5, 26.5, 28.5, 30.5, 32.5,
136 35.5, 38.5, 42.5, 46.5, 50.5,
137 55.5, 60.5, 66.5, 72.5, 78.5
140 double lowlimits[24] = {
141 0.5, 1.5, 2.5, 3.5, 4.5,
142 5.5, 6.5, 7.5, 8.5, 9.5,
143 10.5, 11.5, 12.5, 14.5, 17.5,
144 20.5, 24.5, 29.5, 35.5, 42.5,
145 50.5, 60.5, 72.5, 86.5,
150 if ( low )
n =
new TH1F(
"foeda",
h->GetTitle(), 39, limits );
151 else n =
new TH1F(
"foeda",
h->GetTitle(), 23, lowlimits );
155 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
156 n->Fill(
h->GetBinCenter(
i),
h->GetBinContent(
i) );
160 for (
int i=1 ;
i<=
n->GetNbinsX() ;
i++ ) {
161 n->SetBinError(
i, std::sqrt(
n->GetBinContent(
i) ) );
180 template<
typename T=TH1F>
181 T*
Get( TFile&
f,
const std::string&
n,
const std::string&
dir=
"",
182 const chainmap_t* chainmap=0, std::vector<std::string>* saved=0 ) {
186 size_t pos =
n.find(
'+');
187 if (
pos!=std::string::npos )
name =
n.substr( 0,
pos );
191 if (
h ||
dir.empty() ||
name.find(
dir)!=std::string::npos ) {
192 std::cout <<
"Get() name 0 " <<
name <<
" :: " <<
h << std::endl;
197 std::cout <<
"Get() name 1 " <<
name <<
" :: " <<
h << std::endl;
201 if ( chainmap && chainmap->size()!=0 ) {
202 for ( chainmap_t::const_iterator itr=chainmap->begin() ; itr!=chainmap->end() ; ++itr ) {
204 std::cout <<
"\tmatch: " << itr->first <<
" -> " << itr->second << std::endl;
205 name.replace(
name.find(itr->first), itr->first.size(), itr->second );
213 if ( saved ) saved->push_back(
name );
215 if (
h )
h->SetDirectory(0);
231 bands(
const std::vector<double>& limits,
const std::vector<std::string>&
labels )
245 double minx =
h->GetBinLowEdge(1);
246 double maxx =
h->GetBinLowEdge(
h->GetNbinsX()+1);
248 if (
i>=
m_limits.size() ) { maxx+=1; minx=maxx; }
256 for (
int j=1 ; j<=
h->GetNbinsX() ; j++ ) {
258 std::cout <<
"range: " << j <<
"\tminx: " << minx <<
"\t" << maxx << std::endl;
259 if ( ! (
h->GetBinCenter(j)>=minx &&
h->GetBinCenter(j)<maxx ) ) {
260 h->SetBinContent(j,0);
277 std::vector<double> limits;
279 for (
int i=1 ;
i<
h->GetNbinsX() ;
i++ ) {
280 limits.push_back(
h->GetBinLowEdge(
i) );
283 std::vector<double> alimits;
284 std::vector<double> nlimits;
288 for ( [[maybe_unused]]
int i=0 ;
x<20 ;
i++ ) {
290 alimits.push_back(
x);
294 else if (
x<1.0 )
x+=0.2;
295 else if (
x<1.5 )
x+=0.3;
296 else if (
x<2.0 )
x+=0.4;
297 else if (
x<2.5 )
x+=0.5;
301 else if (
x<1.0 )
x+=0.2;
302 else if (
x<1.5 )
x+=0.2;
303 else if (
x<2.0 )
x+=0.2;
304 else if (
x<2.5 )
x+=0.2;
305 else if (
x<3.0 )
x+=0.3;
311 for (
size_t i=alimits.size() ;
i-- ; ) {
312 if ( alimits[
i]<=15 ) nlimits.push_back( -alimits[
i] );
315 for (
size_t i=1 ;
i<alimits.size() ;
i++ ) {
316 if ( alimits[
i]<=15 ) nlimits.push_back( alimits[
i] );
319 std::cout <<
"limits: " << limits.size() <<
" " << nlimits.size() << std::endl;
321 TH1F* hnew =
new TH1F(
"h",
h->GetTitle(), nlimits.size()-1, &nlimits[0] );
323 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
324 double d =
h->GetBinCenter(
i);
325 int j = hnew->FindBin(
d );
326 hnew->SetBinContent( j, hnew->GetBinContent(j)+
h->GetBinContent(
i) );
336 if ( err_msg !=
"" ) std::cerr << err_msg <<
"\n" << std::endl;
337 std::ostream&
s = std::cout;
338 s <<
"Usage: " <<
name <<
"\t [OPTIONS] test.root reference.root chain1 chain2 chain2 ...\n\n";
339 s <<
"\t" <<
" plots comparison histograms";
340 s <<
" - compiled on " << __DATE__ <<
" at " << __TIME__ <<
"\n\n";
342 s <<
" -c, --config value \t configure which histograms to plot from config file,\n\n";
343 s <<
" -t, --tag value \t appends tag 'value' to the end of output plot names, \n";
344 s <<
" -k, --key value \t prepends key 'value' to the front of output plots name, \n";
345 s <<
" -t, --tag value \t post pend tag 'value' to the end of output plots name, \n";
346 s <<
" -d, --dir value \t creates output files into directory, \"value\" \n\n";
347 s <<
" --ncols value \t creates panels with \"value\" columns\n\n";
349 s <<
" -e, --efficiencies \t make test efficiencies with respect to reference \n";
350 s <<
" -es, --effscale value \t scale efficiencies to value\n";
351 s <<
" -er, --effscaleref value \t scale reference efficiencies to value\n";
352 s <<
" -nb --nobayes \t do not calculate Basyesian efficiency uncertaintiesr\n\n";
354 s <<
" -r, --refit \t refit all test resplots\n";
355 s <<
" -rr, --refitref \t also refit all reference resplots\n";
356 s <<
" --oldrms \t use fast rms95 when refitting resplots\n\n";
358 s <<
" -as, --atlasstyle \t use ATLAS style\n";
359 s <<
" -l, --labels values\t use specified labels for key\n";
360 s <<
" --taglabels values\t use specified additional labels \n";
361 s <<
" -al, --atlaslable value \t set value for atlas label\n";
362 s <<
" -sx, --swapaxtitles exp pattern\t swap the expression \"exp \" in the axis titles with \"pattern\"\n";
363 s <<
" -ac, --addchains \t if possible, add chain names histogram labels \n\n";
365 s <<
" -m, --mapfile \t remap file for reference histograms \n\n";
367 s <<
" -rc, --refchains values ..\t allow different reference chains for comparison\n";
368 s <<
" -s, --swap pattern regex \t swap \"pattern\" in the chain names by \"regex\"\n";
369 s <<
" --swapr pattern regex \t swap \"pattern\" in the ref chain names by \"regex\"\n";
370 s <<
" --swapt pattern regex \t swap \"pattern\" in the test chain names by \"regex\"\n";
371 s <<
" -nr, --noref \t do not plot reference histograms\n";
372 s <<
" --normref \t normalise the reference counting histograms to test histograms\n";
373 s <<
" -us, --usechainref \t use the histograms from chain definied in the \"Chain\" histogram as reference\n\n";
375 s <<
" -ns, --nostats \t do not show stats for mean and rms\n";
376 s <<
" -nm, --nomeans \t do not show stats for the means\n";
377 s <<
" --chi2 \t show the chi2 with respect to the reference\n\n";
379 s <<
" -np, --noplots \t do not actually make any plot\n";
380 s <<
" -q, --quiet \t make the plots but do not print them out\n\n";
382 s <<
" --unscalepix \t do not scale the number of pixels by 0.5 (unscaled by default)\n";
383 s <<
" --scalepix \t do scale the number of pixels by 0.5 (unscaled by default)\n";
384 s <<
" --yrange min max \t use specified y axis range\n";
385 s <<
" -xo, --xoffset value \t relative x offset for the key\n";
386 s <<
" -yp, --ypos value \t relative yposition for the key\n";
387 s <<
" -xe, --xerror value \t size of the x error tick marks\n";
388 s <<
" -nw, --nowatermark \t do not plot the release watermark\n\n";
390 s <<
" -C, --Cfiles \t write C files also\n";
391 s <<
" --nopng \t do not print png files\n";
392 s <<
" --nopdf \t do not print pdf files\n";
393 s <<
" --deleteref \t delete unused reference histograms\n\n";
395 s <<
" --printconfig \t print the configuration being used in the form useable as an input file\n\n";
397 s <<
" -h, --help \t this help\n";
406 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
407 double w =
h->GetBinLowEdge(
i+1) -
h->GetBinLowEdge(
i);
408 h->SetBinContent(
i,
h->GetBinContent(
i)/
w );
409 h->SetBinError(
i,
h->GetBinError(
i)/
w );
414 for (
int i=1 ;
i<=
h->GetNbinsX() ;
i++ ) {
415 h->SetBinContent(
i,
h->GetBinContent(
i)*s_ );
416 h->SetBinError(
i,
h->GetBinError(
i)*s_ );
424 if (
s2==
"" ||
s2==
s3 )
return s;
425 std::string::size_type
pos;
426 while ( (
pos=
s.find(
s2)) != std::string::npos )
s.replace(
pos,
s2.size(),
s3);
431 std::cout <<
"Printing " <<
s << std::endl;
432 gPad->Print(
s.c_str() );
439 int Nx =
h->GetNbinsX();
440 int Ny =
h->GetNbinsY();
441 for (
int i=1 ;
i<=Nx ;
i++ ) {
442 for (
int j=1 ; j<=Ny ; j++ ) {
443 if (
h->GetBinContent(
i, j )==0 ) {
444 h->SetBinContent(
i, j, 1
e-10 );
445 h->SetBinError(
i, j, 1
e-10 );
454 int Nx =
h->GetNbinsX();
455 int Ny =
h->GetNbinsY();
456 for (
int i=1 ;
i<=Nx ;
i++ ) {
458 for (
int j=1 ; j<=Ny ; j++ )
n +=
h->GetBinContent(
i,j);
459 if (
n>0 )
for (
int j=1 ; j<=Ny ; j++ )
h->SetBinContent(
i, j,
h->GetBinContent(
i,j)/
n );
467 int Nx =
h->GetNbinsX();
468 int Ny =
h->GetNbinsY();
470 double xhi =
h->GetXaxis()->GetBinLowEdge(1);
471 double xlo =
h->GetXaxis()->GetBinLowEdge(
h->GetXaxis()->GetNbins() );
473 for (
int i=1 ;
i<=Nx ;
i++ ) {
474 double x =
h->GetXaxis()->GetBinLowEdge(
i);
475 for (
int j=1 ; j<=Ny ; j++ ) {
476 double n =
h->GetBinContent(
i,j);
479 if (
i>1 )
xlo =
h->GetXaxis()->GetBinLowEdge(
i-1);
483 if ( i<h->GetXaxis()->GetNbins() )
xhi =
h->GetXaxis()->GetBinLowEdge(
i+1);
490 h->GetXaxis()->SetRangeUser(
xlo,
xhi );
497 int Nx =
h->GetNbinsX();
498 int Ny =
h->GetNbinsY();
500 double yhi =
h->GetYaxis()->GetBinLowEdge(1);
501 double ylo =
h->GetYaxis()->GetBinLowEdge(
h->GetYaxis()->GetNbins() );
503 for (
int i=1 ;
i<=Ny ;
i++ ) {
504 double y =
h->GetYaxis()->GetBinLowEdge(
i);
505 for (
int j=1 ; j<=Nx ; j++ ) {
506 double n =
h->GetBinContent(j,
i);
509 if (
i>1 )
ylo =
h->GetYaxis()->GetBinLowEdge(
i-1);
513 if ( i<h->GetYaxis()->GetNbins() )
yhi =
h->GetYaxis()->GetBinLowEdge(
i+1);
520 h->GetYaxis()->SetRangeUser(
ylo,
yhi );
528 for (
int i=0 ;
i<
h0->GetNbinsX() ;
i++ ) {
530 double d0 =
h0->GetBinContent(
i+1);
531 double d1 =
h1->GetBinContent(
i+1);
533 double e0 =
h0->GetBinError(
i+1);
534 double e1 =
h1->GetBinError(
i+1);
548 std::cout <<
"\n---------------------------------\n";
549 std::cout <<
"\n comparitor is off ...\n";
551 if (
argc<4 )
return usage(
argv[0], -1,
"too few arguments");
555 std::string
tag =
"";
556 std::string
key =
"";
558 std::string
dir =
"";
560 std::string ftestname =
"";
561 std::string frefname =
"";
570 std::string defreflabel =
"";
574 std::vector<std::string> usrlabels;
575 bool uselabels =
false;
576 bool addinglabels =
false;
578 std::vector<std::string> taglabels;
579 bool addingtags =
false;
581 bool make_ref_efficiencies =
false;
582 bool refit_resplots =
false;
583 bool refitref_resplots =
false;
585 bool nostats =
false;
586 bool nomeans =
false;
588 bool atlasstyle =
false;
589 bool deleteref =
false;
590 bool nowatermark =
false;
591 bool noplots =
false;
597 bool normref =
false;
598 bool scalepix =
false;
600 bool addchains =
false;
601 bool usechainref =
false;
604 bool RANGEMAP =
false;
605 bool ALLRANGEMAP =
false;
609 std::string atlaslabel_tmp =
"Internal";
612 double scale_eff = -1;
613 double scale_eff_ref = -1;
615 std::string configfile =
"";
623 std::string
regex =
"";
625 std::string patternr =
"";
626 std::string regexr =
"";
628 std::string patternt =
"";
629 std::string regext =
"";
631 std::string basedir =
"";
633 std::string xpattern =
"";
634 std::string xregex =
"";
636 std::vector<std::string>
chains;
637 std::vector<std::string> refchains;
639 bool addingrefchains =
false;
641 std::string mapfile =
"";
643 std::vector<std::string> chainfiles;
651 if (
arg.find(
'-')!=0 && addinglabels ) {
655 usrlabels.push_back(
label );
658 else addinglabels =
false;
660 if (
arg.find(
'-')!=0 && addingrefchains ) {
661 refchains.push_back(
arg );
664 else addingrefchains =
false;
666 if (
arg.find(
'-')!=0 && addingtags ) {
668 std::cout <<
"\tadding tag label: " << taglabels.back() << std::endl;
671 else addingtags =
false;
673 if (
arg==
"-h" ||
arg==
"--help" ) {
676 else if (
arg==
"-c" ||
arg==
"--config" ) {
678 else return usage(
argv[0], -1,
"no config file provided");
680 else if (
arg==
"-t" ||
arg==
"--tag" ) {
682 else return usage(
argv[0], -1,
"no tag provided");
684 else if (
arg==
"-l" ||
arg==
"--labels" ) {
687 else if (
arg==
"-el" ) {
690 else if (
arg==
"-k" ||
arg==
"--key" ) {
692 else return usage(
argv[0], -1,
"no key provided");
694 else if (
arg==
"-m" ||
arg==
"--mapfile" ) {
696 else return usage(
argv[0], -1,
"no mapfile provided");
698 else if (
arg==
"-d" ||
arg==
"--dir" ) {
700 else return usage(
argv[0], -1,
"no directory provided");
702 else if (
arg==
"-b" ||
arg==
"--bdir" ) {
704 else return usage(
argv[0], -1,
"no directory provided");
706 else if (
arg==
"--taglabels" ) {
709 else if (
arg==
"--unscalepix" ) {
712 else if (
arg==
"--scalepix" ) {
715 else if (
arg==
"-ac" ||
arg==
"--addchains" ) {
718 else if (
arg==
"-yrange" ) {
721 else return usage(
argv[0], -1,
"no range specified");
723 else return usage(
argv[0], -1,
"no upper y limit specified");
725 else if (
arg==
"-e" ||
arg==
"--efficiencies" ) {
726 make_ref_efficiencies =
true;
728 else if (
arg==
"-r" ||
arg==
"--refit" ) {
729 refit_resplots =
true;
731 else if (
arg==
"-rr" ||
arg==
"--refitref" ) {
732 refitref_resplots =
true;
734 else if (
arg==
"--oldrms" ) {
737 else if (
arg==
"-nw" ||
arg==
"--nowatermark" ) {
741 else if (
arg==
"--chi2" ) {
744 else if (
arg==
"-ns" ||
arg==
"--nostats" ) {
747 else if (
arg==
"-nm" ||
arg==
"--nomeans" ) {
750 else if (
arg==
"-nt" ||
arg==
"--notitle" ) {
753 else if (
arg==
"-nr" ||
arg==
"--noref" ) {
757 else if (
arg==
"--normref" ) {
760 else if (
arg==
"-rc" ||
arg==
"--refchains" ) {
761 addingrefchains =
true;
763 else if (
arg==
"-uc" ||
arg==
"--usechainref" ) {
766 else if (
arg==
"-nb" ||
arg==
"--nobayes" ) {
769 else if (
arg==
"-es" ||
arg==
"--effscale" ) {
771 else return usage(
argv[0], -1,
"no efficiency scale provided");
773 else if (
arg==
"-er" ||
arg==
"--effscaleref" ) {
775 else return usage(
argv[0], -1,
"no efficiency scale for the reference histograms provided");
777 else if (
arg==
"--ncols" ) {
779 else return usage(
argv[0], -1,
"no number of columns provided");
781 else if (
arg==
"-np" ||
arg==
"--noplots" ) {
784 else if (
arg==
"-C" ||
arg==
"--Cfiles" ) {
787 else if (
arg==
"--deleteref" ) {
790 else if (
arg==
"--nopng" ) {
793 else if (
arg==
"--nopdf" ) {
796 else if (
arg==
"-as" ||
arg==
"--atlasstyle" ) {
799 else if (
arg==
"-q" ||
arg==
"--quiet" ) {
802 else if (
arg==
"-al" ||
arg==
"--atlaslabel" ) {
804 else return usage(
argv[0], -1,
"no label provided");
806 else if (
arg==
"-xo" ||
arg==
"--xoffset" ) {
808 else return usage(
argv[0], -1,
"no xoffset provided");
810 else if (
arg==
"-yp" ||
arg==
"--ypos" ) {
812 else return usage(
argv[0], -1,
"no y position provided");
814 else if (
arg==
"-xe" ||
arg==
"--xerror" ) {
816 else return usage(
argv[0], -1,
"no x error provided");
818 else if (
arg==
"-s" ||
arg==
"--swap" ) {
820 else return usage(
argv[0], -1,
"no patterns provided");
822 else return usage(
argv[0], -1,
"no target pattern provided");
824 else if (
arg==
"--swapt" ) {
826 else return usage(
argv[0], -1,
"no patterns provided");
828 else return usage(
argv[0], -1,
"no target pattern provided");
830 else if (
arg==
"--swapr" ) {
832 else return usage(
argv[0], -1,
"no patterns provided");
834 else return usage(
argv[0], -1,
"no target pattern provided");
836 else if (
arg==
"-sx" ||
arg==
"--swapaxtitles" ) {
838 else return usage(
argv[0], -1,
"no target pattern provided");
840 else return usage(
argv[0], -1,
"no patterns provided");
842 else if (
arg.find(
'-')==0 ) {
843 std::cerr <<
"unknown option: " <<
arg <<
"\n" << std::endl;
847 if ( ftestname==
"" ) ftestname =
arg;
848 else if ( frefname==
"" ) frefname =
arg;
850 std::string
file =
"";
852 if (
arg.find(
":file:")!=std::string::npos ) {
854 chainfiles.push_back(
file );
866 std::cout <<
"file: " <<
file <<
"\tchain: " <<
chain << std::endl;
872 if ( ftestname.empty() ) {
873 std::cerr <<
"main(): test file not specified " << std::endl;
877 if ( !
exists(ftestname) ) {
878 std::cerr <<
"main(): test file " << ftestname <<
" does not exist" << std::endl;
882 std::vector<TFile*> chainTFiles;
886 if ( chainfiles.size()==0 ) ftest_ = TFile::Open( ftestname.c_str() );
889 chainTFiles.resize(chainfiles.size());
890 for (
size_t i=0 ;
i<chainfiles.size() ;
i++ ) {
891 chainTFiles[
i] = TFile::Open( chainfiles[
i].c_str() );
892 if ( chainTFiles[
i] == 0 ) {
893 std::cerr <<
"\tfile: " << chainfiles[
i] <<
" could not be opened" << std::endl;
896 else std::cout <<
"\tchainfiles: " << chainfiles[
i] <<
" " << chainTFiles[
i] << std::endl;
901 if ( noref==
false ) {
902 if ( frefname.empty() ) {
903 std::cerr <<
"main(): ref file not specified " << std::endl;
913 if ( frefname==ftestname ) fref_ = ftest_;
914 else if (
exists(frefname) ) fref_ = TFile::Open( frefname.c_str() );
916 std::cerr <<
"main(): ref file " << frefname <<
" does not exist" << std::endl;
924 if ( chainfiles.size()==0 ) {
926 std::cerr <<
"could not open test file " << ftestname << std::endl;
930 if ( noref==
false && fref_==0 ) {
931 std::cerr <<
"could not open files " << std::endl;
937 defreflabel =
"failed to open reference file";
942 if ( scale_eff == -1 ) scale_eff = 100;
943 if ( scale_eff_ref == -1 ) scale_eff_ref = scale_eff;
946 bool noreftmp = noref;
948 if (
chains.size()==0 )
return usage(
argv[0], -1,
"no chains specified");
951 if ( basedir.size()>0 ) {
952 if ( basedir[basedir.size()-1]!=
'/' ) basedir +=
"/";
956 if ( refchains.size()>0 && refchains.size()!=
chains.size() )
return usage(
argv[0], -1,
"not enough chains specified");
958 if ( refchains.size()==0 ) refchains =
chains;
960 std::vector<std::string> chainref(
chains.size(),
"");
961 std::vector<std::string> chain_name(
chains.size(),
"");
963 std::vector<std::string> refchain(chainref.size(),
"");
967 std::cout <<
argv[0] <<
" options:" << std::endl;
968 std::cout <<
"\tATLAS style: " << ( atlasstyle ?
"true" :
"false" ) << std::endl;
969 std::cout <<
"\tBayesian uncertainties: " << ( bayes ?
"true" :
"false" ) << std::endl;
970 std::cout <<
"\trefit resplot uncertainties: " << ( refit_resplots ?
"true" :
"false" ) << std::endl;
971 std::cout <<
"\tsuppress mean and rms stats: " << ( nostats ?
"true" :
"false" ) << std::endl;
972 if ( !nostats ) std::cout <<
"\tsuppress meanstats: " << ( nomeans ?
"true" :
"false" ) << std::endl;
973 std::cout <<
"\tsuppress png output: " << ( nopng ?
"true" :
"false" ) << std::endl;
974 std::cout <<
"\tsuppress pdf output: " << ( nopdf ?
"true" :
"false" ) << std::endl;
975 std::cout <<
"\tsuppress reference output: " << ( noref ?
"true" :
"false" ) << std::endl;
976 std::cout <<
"\tuse chain references: " << ( usechainref ?
"true" :
"false" ) << std::endl;
977 std::cout <<
"\tpanel ncols: " << ncols << std::endl;
979 if ( usrlabels.size()>0 ) std::cout <<
"\tlabels: " << usrlabels.size() << std::endl;
980 if ( taglabels.size()>0 ) std::cout <<
"\textra text: " << taglabels << std::endl;
983 for (
size_t il=0 ;
il<usrlabels.size() ;
il++ ) {
984 std::cout <<
"usr label[" <<
il <<
"] : " << usrlabels[
il] << std::endl;
987 std::cout <<
"atlas style : " << atlasstyle << std::endl;
995 gROOT->SetStyle(
"Plain");
997 gStyle->SetLineScalePS(1);
1001 gStyle->SetErrorX(xerror);
1003 gStyle->SetPadLeftMargin(0.15);
1004 gStyle->SetPadBottomMargin(0.15);
1006 gStyle->SetPadRightMargin(0.02);
1007 gStyle->SetPadTopMargin(0.05);
1009 std::cout <<
"Chains: " << std::endl;
1012 if ( usrlabels.size()>0 ) std::cout <<
"labels: " << usrlabels << std::endl;
1014 if ( usrlabels.size()>0 && usrlabels.size()==
chains.size() ) uselabels =
true;
1018 TTree* dataTree = 0;
1019 TString* releaseData =
new TString(
"");
1020 std::vector<std::string> release_data;
1022 if ( !nowatermark && ftest_ ) {
1024 dataTree = (TTree*)ftest_->Get(
"dataTree");
1027 dataTree->SetBranchAddress(
"ReleaseMetaData", &releaseData);
1029 for (
unsigned int i=0;
i<dataTree->GetEntries() ;
i++ ) {
1030 dataTree->GetEntry(
i);
1031 release_data.push_back( releaseData->Data() );
1032 std::cout <<
"main() release data: " << release_data.back() <<
" : " << *releaseData << std::endl;
1037 if ( release_data.size()>0 ) {
1038 if ( release_data.size()>1 ) std::cerr <<
"main() more than one release - using only the first" << std::endl;
1042 std::string
nightly =
chop(release_data[0],
" " );
1045 for (
int ic=0 ;
ic<4 ;
ic++ )
chop(release_data[0],
" " );
1046 release +=
" (" + release_data[0]+
")";
1050 chop( release_data[0],
" " );
1051 release +=
" " +
chop(release_data[0],
" " ) +
")";
1062 std::cout <<
"trying to make directory" << std::endl;
1065 if (
mkdir(
dir.c_str(), 0777 ) ) std::cerr <<
"main() couldn't create directory " <<
dir << std::endl;
1066 else std::cout <<
"main() output will be sent to directory " <<
dir << std::endl;
1070 if ( ftest_==0 && chainTFiles.size()>0 ) fref_ = ftest_ = chainTFiles[0];
1072 TFile* ftest = ftest_;
1073 TFile* fref = fref_;
1075 std::string testrun =
findrun( ftest );
1077 std::string rawrefrun =
"";
1078 std::string refrun =
"";
1080 if ( fref_ ) refrun = rawrefrun =
findrun( fref );
1082 std::cout <<
"testrun: " << testrun <<
"\nrefrun: " << refrun << std::endl;
1084 if ( !testrun.empty() && refrun != testrun ) {
1092 if ( !refrun.empty() ) {
1094 std::string newtag =
"Reference: ";
1096 std::cout <<
"refrun: " << refrun << std::endl;
1099 while ( (
pos=refrun.find(
'_'))!=std::string::npos ) refrun.replace(
pos, 1,
" " );
1102 std::string rawrun = refrun.erase( refrun.find(
"run"), 4 );
1104 if (
contains(frefname, rawrun) ) {
1106 std::string
release = frefname;
1121 taglabels.push_back( newtag );
1123 std::cout <<
"tag labels: " << taglabels << std::endl;
1138 if ( !nowatermark ) {
1140 TH1D* htestev = (TH1D*)ftest->Get(
"event") ;
1141 TH1D* hrefev = (TH1D*)fref->Get(
"event") ;
1143 std::cout <<
"htestev " << htestev <<
" " << hrefev << std::endl;
1145 if ( htestev ) NeventTest = htestev->GetEntries();
1146 if ( hrefev ) NeventRef = hrefev->GetEntries();
1156 if ( NeventTest>1 ) std::cout <<
"Nevents Test: " << NeventTest << std::endl;
1157 if ( NeventRef>1 ) std::cout <<
"Nevents Ref: " << NeventRef << std::endl;
1161 if ( mapfile.empty() ) mapfile = configfile;
1163 if ( !mapfile.empty() ) {
1167 if (
m.isTagDefined(
"ChainMap" ) ) {
1168 std::vector<std::string>
chains =
m.GetStringVector(
"ChainMap" );
1172 for (
size_t i=0 ;
i<
chains.size() ;
i+=2 ) {
1173 chainmap->insert( chainmap_t::value_type(
chains[
i],
chains[
i+1] ) );
1176 std::cout <<
"\nusing chain map:" << std::endl;
1179 std::cout <<
"\t" << itr->first <<
"\t" << itr->second << std::endl;
1186 std::cout <<
"\ncreating chain and reference information ..." << std::endl;
1188 for (
size_t j=0; j<
chains.size(); j++) {
1196 std::cout <<
"chain: " <<
chains[j] <<
"\taddchains: " << addchains << std::endl;
1200 TFile* fftest = ftest;
1202 if ( chainfiles.size()>0 && chainfiles.size()>j ) fftest = chainTFiles[j];
1208 std::string
name = hchain->GetTitle();
1214 std::cout <<
"new chainref: " << chainref[j] << std::endl;
1216 std::string::size_type
pos = chainref[j].find(
":for");
1217 if (
pos!=std::string::npos ) chainref[j].replace(
pos, 4,
"_for" );
1220 chainref[j] = newchain;
1222 std::cout <<
"final chainref: " << chainref[j] << std::endl;
1226 std::cout <<
"chainref: " << chainref[j] << std::endl;
1230 std::cout <<
"name: " <<
name << std::endl;
1233 else chain_name[j] =
name;
1235 if ( chain_name[j] ==
" : " ) chain_name[j] =
"";
1237 std::cout <<
"chain_name: " << chain_name[j] << std::endl;
1242 std::cout <<
"chainref size: " << chainref.size() <<
" " << refchains.size() << std::endl;
1244 for (
size_t j=0 ; j<chainref.size() ; j++ ) {
1245 std::cout <<
"chainref: " << chainref[j] <<
" :: " << refchains[j] << std::endl;
1251 if ( !patternr.empty() ) {
1252 if ( chainref[j]!=
"" ) refchain[j] =
fullreplace( chainref[j], patternr, regexr );
1253 else refchain[j] =
fullreplace( refchains[j], patternr, regexr );
1256 std::cout <<
"refchain: " << refchain[j] << std::endl;
1259 std::cout <<
"done chains" << std::endl;
1263 std::vector<Panel> panels;
1270 std::vector<int> ccolours;
1271 std::vector<int> cstyles;
1273 std::vector<std::string> ctags;
1274 std::vector<std::string> ctaglabels;
1277 std::cout <<
"\n" <<
argv[0] <<
"\tconfigfile: " << configfile << std::endl;
1279 bool use_file_config =
false;
1281 if ( configfile!=
"" ) {
1283 if (
exists(configfile) ) {
1285 std::cout <<
argv[0] <<
":\treading configuration file " << configfile << std::endl;
1292 if ( rc.isTagDefined(
"histos" ) ) {
1294 std::cout <<
argv[0] <<
":\treading histogram configuration from file " << configfile << std::endl;
1296 use_file_config =
true;
1298 std::vector<std::string> raw_input = rc.GetStringVector(
"histos" );
1300 for (
size_t iraw=0 ; iraw<raw_input.size() ; iraw += 6) {
1304 panels.push_back(
p );
1309 std::cout <<
"searching for panels" << std::endl;
1313 if ( rc.isTagDefined(
"panels" ) ) {
1315 std::cout <<
argv[0] <<
":\treading histogram panel configuration from file " << configfile << std::endl;
1317 use_file_config =
true;
1319 std::vector<std::string> panel_config = rc.GetStringVector(
"panels" );
1321 std::vector<string> panel_columns;
1323 if ( rc.isTagDefined(
"panel_columns") ) {
1324 panel_columns = rc.GetStringVector(
"panel_columns" );
1325 if ( panel_columns.size()%2 )
return usage(
argv[0], -1,
"incorrect panel settings" );
1329 for (
size_t ipanel=panel_config.size() ; ipanel-- ; ) {
1331 std::vector<std::string> raw_input = rc.GetStringVector( panel_config[ipanel] );
1335 if ( panel_columns.size() ) {
1337 if ( itr!=panel_columns.end() ) tncols =
std::atoi( (++itr)->c_str() );
1340 Panel p( panel_config[ipanel], tncols );
1343 for (
size_t iraw=0 ; iraw<raw_input.size() ; iraw += 6 )
p.push_back(
HistDetails( &(raw_input[iraw]) ) );
1345 panels.push_back(
p );
1351 if ( rc.isTagDefined(
"Bands" ) && rc.isTagDefined(
"Labels" ) ) {
1352 bnd =
bands( rc.GetVector(
"Bands"), rc.GetStringVector(
"Labels" ) );
1356 if ( rc.isTagDefined(
"Colours") ) ccolours = rc.GetIntVector(
"Colours");
1357 if ( rc.isTagDefined(
"Styles") ) cstyles = rc.GetIntVector(
"Styles");
1358 if ( rc.isTagDefined(
"Tags") ) ctags = rc.GetStringVector(
"Tags");
1359 if ( rc.isTagDefined(
"TagLabels") ) ctaglabels = rc.GetStringVector(
"TagLabels");
1360 if ( rc.isTagDefined(
"TagLabels") ) usrlabels = rc.GetStringVector(
"TagLabels");
1362 if ( rc.isTagDefined(
"Styles") ) {
1363 for (
size_t is=0 ; is<cstyles.size() && is<6 ; is++ ) {
1372 std::cout <<
argv[0] <<
"\tuserlabels :" << usrlabels <<
":" << std::endl;
1376 if ( rc.isTagDefined(
"RANGEMAP") ) RANGEMAP =
true;
1377 if ( rc.isTagDefined(
"ALLRANGEMAP") ) ALLRANGEMAP =
true;
1379 std::cout <<
"Extra: " << rc.isTagDefined(
"Extra") << std::endl;
1381 if ( rc.isTagDefined(
"Extra") ) taglabels.push_back(
fullreplace( rc.GetString(
"Extra"),
"__",
" " ) );
1386 std::cerr <<
argv[0] <<
":\t config file not found: " << configfile << std::endl;
1392 if ( !use_file_config ) {
1394 std::cout <<
"using default panels" << std::endl;
1408 scale_eff_ref = 100;
1414 size_t nphist[3] = { 4, 4, 10 };
1416 std::string pnames[3] = {
"eff",
"res",
"diff" };
1418 for (
size_t ip=0 ;
ip<3 ;
ip++ ) {
1420 for (
size_t iraw=0 ; iraw<nphist[
ip] ; iraw++ )
p.push_back(
HistDetails( inpanels[
ip][iraw] ) );
1421 panels.push_back(
p );
1427 std::cout <<
"taglabels" << std::endl;
1429 for (
size_t it=0 ;
it<taglabels.size() ;
it++ ) std::cout << taglabels[
it] << std::endl;
1432 std::cout <<
"\npanels: " << panels.size() << std::endl;
1434 if ( panels.size()==0 )
return usage(
argv[0], -1,
"no panels to plot");
1436 for (
size_t ip=0 ;
ip<panels.size() ;
ip++ ) std::cout << panels[
ip] << std::endl;
1441 gStyle->SetPadRightMargin(0.05);
1442 gStyle->SetPadTopMargin(0.05);
1444 const Int_t Number = 3;
1445 Double_t
Red[Number] = { 0.00, 0.00, 1.00};
1446 Double_t
Green[Number] = { 0.00, 5.00, 1.00};
1447 Double_t Blue[Number] = { 0.00, 0.50, 0.00};
1448 Double_t Length[Number] = { 0.00, 0.50, 1.00 };
1450 TColor::CreateGradientColorTable(Number,Length,
Red,
Green,Blue,
nb);
1452 else gStyle->SetPalette(1);
1454 if (
fulldbg ) std::cout << __LINE__ << std::endl;
1456 double rightmargin = gStyle->GetPadRightMargin();
1457 gStyle->SetPadRightMargin(0.1);
1461 gStyle->SetPadRightMargin(rightmargin);
1465 for (
size_t ipanel=0 ; ipanel<panels.size() ; ipanel++ ) {
1467 Panel& panel = panels[ipanel];
1469 std::cout <<
"\n\n---------------------------------------------\n";
1471 std::cout << panel <<
"\n" << std::endl;
1473 int ncolsp = panel.
ncols();
1474 int nrowsp = panel.
nrows();
1478 std::cout <<
"\nncols: " << ncolsp <<
"\tnrows: " << nrowsp << std::endl;
1480 bool multipanel = ( panel.
size() > 1 );
1482 if ( panel.
size()==0 ) {
1483 std::cout <<
"panel empty: " << panel.
name() << std::endl;
1489 if ( panel.
size()>4 ) gStyle->SetLineScalePS(0.5);
1491 if ( multipanel ) extraw = 1.05;
1493 TCanvas* tc =
new TCanvas(
"tc",
"", extraw*ncolsp*800, nrowsp*600 );
1497 const std::string& atlaslabel = atlaslabel_tmp;
1502 gStyle->SetLineScalePS(1);
1518 tc->Divide( ncolsp, nrowsp, 0.0001, 0.0003 );
1524 std::string plotname =
"";
1526 for (
size_t i=0 ;
i<panel.
size() ;
i++ ) {
1530 bool drawmeans =
false;
1531 bool drawresiduals =
true;
1534 if (
contains(
histo.detail(),
"-residual") ) drawresiduals =
false;
1536 std::string xaxis =
histo.xtitle();
1537 std::string yaxis =
histo.ytitle();
1539 if ( !xregex.empty() ) {
1540 size_t pos = xaxis.find(xregex);
1541 if (
pos!=std::string::npos ) xaxis.replace(
pos, xregex.size(), xpattern );
1542 pos = yaxis.find(xregex);
1543 if (
pos!=std::string::npos ) yaxis.replace(
pos, xregex.size(), xpattern );
1553 bool d0rebin_flag =
false;
1566 int npanel = nrowsp*(
i/nrowsp) +
i%nrowsp + 1 ;
1568 std::cout <<
"panel: panel: " << panel.
name() <<
"\tsubpanel: " << npanel << std::endl;
1570 if ( multipanel ) tc->cd( npanel );
1578 if (
fulldbg ) std::cout << __LINE__ << std::endl;
1580 std::cout <<
"main() processing histo[" <<
i <<
"] " << (
i<10 ?
" " :
"" ) <<
histo.name() <<
"\t" <<
histo.xaxis() << std::endl;
1588 std::string noreflabel=defreflabel;
1602 if ( ypos>0.5 ) ypos = 0.85;
1606 if ( ypos_arg!=0 ) ypos = ypos_arg;
1608 double xpos_original = xpos;
1612 if ( xinfo.
offset() != 0 ) {
1614 std::cout <<
"HA ! xinfo.offset: " << xinfo.
offset() << std::endl;
1621 if ( yinfo.
offset() != 0 ) {
1623 std::cout <<
"HA ! yinfo.offset: " << yinfo.
offset() << std::endl;
1633 size_t Nrows =
chains.size();
1635 if ( ALLRANGEMAP || (RANGEMAP && xaxis.find(
"p_{T}")!=std::string::npos && ccolours.size() ) )
1636 Nrows = ( Nrows < ccolours.size() ? Nrows : ccolours.size() );
1638 int Nlines = Nrows + taglabels.size();
1640 std::vector<double> ypositions;
1642 double deltay = (Nrows*0.055-0.005)/Nrows;
1645 double yhi = ypos-0.01;
1647 if ( ypos>0.5 )
ylo -= Nlines*deltay;
1648 else yhi += Nlines*deltay;
1650 ypositions.reserve(Nlines);
1651 for (
int ilines=0 ; ilines<Nlines ; ilines++ ) {
1652 ypositions.push_back(
yhi - deltay*(ilines+0.5) );
1663 Legend legend_eff( xpos, xpos+0.1,
ylo,
ylo+Nrows*0.06-0.005 );
1666 std::vector<std::string>
Mean;
1667 std::vector<std::string>
RMS;
1672 std::vector<std::string> Chi2;
1673 std::vector<std::string> MeanRef;
1674 std::vector<std::string> RMSRef;
1684 bool power_set =
false;
1692 for (
unsigned int j=0; j<
chains.size(); j++) {
1694 TFile* fftest = ftest;
1695 TFile* ffref = fref;
1697 if ( chainfiles.size()>0 && chainfiles.size()>j ) ffref = fftest = chainTFiles[j];
1702 std::cout <<
"chain: " <<
chains[j] <<
"\taddchains: " << addchains << std::endl;
1703 std::cout <<
"chainref: " << chainref[j] << std::endl;
1715 TGraphAsymmErrors* tgtest = 0;
1717 std::cout <<
"refchain.size() " << refchain.size() << std::endl;
1719 std::cout <<
"refchain: " << refchain[j] << std::endl;
1723 gPad->SetRightMargin(0.03);
1727 gPad->SetRightMargin(0.13);
1733 h2test->GetYaxis()->SetTitleOffset(1.55);
1734 h2test->GetXaxis()->SetTitleOffset(1.5);
1735 h2test->GetXaxis()->SetTitle(xaxis.c_str());
1736 h2test->GetYaxis()->SetTitle(yaxis.c_str());
1742 std::cout << xinfo << std::endl;
1743 std::cout << yinfo << std::endl;
1746 h2test->GetYaxis()->SetRangeUser( yinfo.
lo(), yinfo.
hi() );
1752 h2test->GetXaxis()->SetRangeUser( xinfo.
lo(), xinfo.
hi() );
1760 h2test->DrawCopy(
"colz");
1762 if (
histo.detail().find(
"logz")!=std::string::npos ) gPad->SetLogz(
true);
1763 else gPad->SetLogz(
false);
1769 bool bsigma =
false;
1775 std::cout <<
"\trefitting: " <<
histo.name() << std::endl;
1780 std::string tmp_ =
histo.name();
1783 if ( bsigma )
base =
chop( tmp_,
"/sigma" );
1784 if ( bmean )
base =
chop( tmp_,
"/mean" );
1788 std::cout <<
"ffref " << ffref << std::endl;
1791 if ( ffref ) href2d_ = Get<TH2D>( *ffref,
chains[j]+
"/"+
base+
"/2d", testrun );
1793 if ( htest2d_==0 )
continue;
1794 if ( !noreftmp && href2d_==0 ) noreftmp =
true;
1799 Resplot rtest(
"tmp", htest2d_ );
1810 if ( bsigma ) {
htest = (
TH1F*)rtest.
Sigma()->Clone(
"rtest_sigma");
htest->SetDirectory(0); }
1811 if ( bmean ) {
htest = (
TH1F*)rtest.
Mean()->Clone(
"rtest_mean");
htest->SetDirectory(0); }
1814 std::cerr <<
"missing test histogram: " << (refchain[j]+
" / "+
histo.name()) <<
" " <<
htest <<
"(test)" << std::endl;
1825 if ( refitref_resplots ) {
1827 Resplot rref(
"tmp", href2d_ );
1838 if ( bsigma ) { hreft = (
TH1F*)rref.
Sigma()->Clone(
"rref_sigma"); hreft->SetDirectory(0); }
1839 if ( bmean ) { hreft = (
TH1F*)rref.
Mean()->Clone(
"rref_mean"); hreft->SetDirectory(0); }
1843 hreft =
Get( *ffref, refchain[j]+
"/"+
histo.name(), rawrefrun, chainmap );
1845 std::cerr <<
"ERROR: could not find " << (refchain[j]+
"/"+
histo.name()) << std::endl;
1850 if ( !noreftmp && hreft==0 ) {
1851 std::cerr <<
"missing ref histogram: " << (refchain[j]+
" / "+
histo.name()) <<
" " <<
htest <<
"(ref)" << std::endl;
1855 noreflabel=
"reference not found";
1863 href->SetDirectory(0);
1874 if (
fulldbg ) std::cout << __LINE__ << std::endl;
1878 std::string reghist =
histo.name();
1880 std::cout <<
"hist: " << (
chains[j]+
"/"+reghist) <<
"\tftest " << ftest << std::endl;
1884 std::cout <<
"hist: " <<
htest << std::endl;
1886 std::cout << xaxis << std::endl;
1889 std::cerr <<
"missing test histogram: " << (
chains[j]+
" / "+reghist) <<
" " <<
htest<< std::endl;
1895 std::cout <<
"hreft: " << hreft << std::endl;
1897 if ( ffref ) hreft =
Get( *ffref, refchain[j]+
"/"+reghist, rawrefrun, chainmap );
1898 else noreftmp =
true;
1900 std::cout <<
"hreft: " << hreft << std::endl;
1902 if ( std::string(
htest->ClassName()).find(
"TH2")!=std::string::npos ) {
1903 std::cout <<
"Class TH2: " <<
htest->GetName() << std::endl;
1907 if ( std::string(
htest->ClassName()).find(
"TH1")!=std::string::npos ) {
1908 std::cout <<
"Class TH1: " <<
htest->GetName() << std::endl;
1910 else if ( std::string(
htest->ClassName()).find(
"TProfile")!=std::string::npos ) {
1911 std::cout <<
"Class TProf: " <<
htest->GetName() << std::endl;
1916 if ( !noreftmp && hreft==0 ) {
1917 std::cerr <<
"missing ref histogram: " << (refchain[j]+
" / "+reghist)
1918 <<
" " << hreft << std::endl;
1921 noreflabel=
"reference not found";
1930 href->SetDirectory(0);
1937 std::cout <<
" \tget " << (
chains[j]+
"/"+reghist) <<
"\thtest " <<
htest << std::endl;
1938 std::cout <<
" \tget " << (refchain[j]+
"/"+reghist) <<
"\thref " <<
href << std::endl;
1940 if (
htest==0 )
continue;
1942 if ( !noreftmp &&
href==0 ) {
1947 if (
fulldbg ) std::cout << __LINE__ << std::endl;
1951 std::cout <<
"rebin: " <<
hname <<
"\t" <<
rebin << std::endl;
1954 for (
int ip=0 ;
ip<10 ;
ip++ ) std::cout << std::endl;
1960 std::cout <<
"Rebinning histogram: " <<
histo.name() << std::endl;
1961 if (
htest->GetNbinsX()>500 )
htest->Rebin(10);
1967 if (
histo.name().find(
"zed_eff")!=std::string::npos ) {
1968 if (
htest->GetNbinsX()>100 )
htest->Rebin(5);
1973 if (
fulldbg ) std::cout << __LINE__ << std::endl;
1975 if ( scalepix && std::string(
htest->GetName()).find(
"npix")!=std::string::npos )
Scale(
htest,0.5);
1976 if ( scalepix &&
href && std::string(
htest->GetName()).find(
"npix")!=std::string::npos )
Scale(
href,0.5);
1978 if (
fulldbg ) std::cout << __LINE__ << std::endl;
1981 htest->SetTitle(
"");
1985 if (
fulldbg ) std::cout << __LINE__ << std::endl;
1989 if (
fulldbg ) std::cout << __LINE__ << std::endl;
1991 if ( make_ref_efficiencies ) {
1999 std::string effhist =
histo.name();
2003 TH1F* hrefnumt =
Get( *ffref, refchain[j]+
"/"+effhist+
"_n", rawrefrun, chainmap, &
savedhistos );
2005 if ( !noreftmp && hrefnumt!=0 ) {
2006 hrefnum = (
TH1F*)hrefnumt->Clone();
2007 hrefnum->SetDirectory(0);
2019 std::string effhist =
histo.name();
2023 if (
rebin!=1 ) std::cout << effhist <<
"\trebin: " <<
rebin << std::endl;
2028 std::cout <<
"1: Bayesian error calculation " << htestnum <<
" " << htestden <<
"\tscale " << scale_eff << std::endl;
2030 if ( htestnum && htestden ) {
2032 if ( d0rebin_flag ) {
2033 htestnum =
d0rebin( htestnum );
2034 htestden =
d0rebin( htestden );
2036 else if (
rebin!=1 ) {
2041 std::cout <<
"test histogram name: : " << htestnum->GetName() <<
"\txaxis: " << xaxis <<
"\t" << std::endl;
2044 if ( std::string(htestnum->GetName()).find(
"ntrax_eff")!=std::string::npos ) {
2058 std::cout <<
"rebin " <<
histo.name() << std::endl;
2064 std::cout <<
"rebin " <<
histo.name() << std::endl;
2071 if ( RANGEMAP && (effhist.find(
"ET")!=std::string::npos ) ) {
2072 std::cout <<
"\trange: " << j <<
" " <<
htest << std::endl;
2079 tgtest =
e.Bayes(scale_eff);
2083 std::cout <<
"effhist: " << effhist << std::endl;
2089 std::cout <<
"recalculating reference efficiencies ..." << std::endl;
2093 std::cout <<
"doin ..." << std::endl;
2095 TH1F* hrefnum =
Get( *ffref, refchain[j]+
"/"+
histo.name()+
"_n", rawrefrun, chainmap );
2097 TH1F* hrefden =
Get( *ffref, refchain[j]+
"/"+
histo.name()+
"_d", rawrefrun, chainmap );
2099 std::cout <<
"2. Bayesian error calculation " << htestnum <<
" " << htestden <<
"\tscale " << scale_eff << std::endl;
2100 std::cout <<
"3. Bayesian error calculation " << hrefnum <<
" " << hrefden <<
"\tscale " << scale_eff_ref << std::endl;
2103 if ( hrefnum && hrefden ) {
2105 if ( d0rebin_flag ) {
2109 else if (
rebin!=1 ) {
2128 std::cout <<
" no test histogram : " << (
chains[j]+
"/"+
histo.name()) << std::endl;
2132 if ( !noreftmp &&
href==0 ) {
2133 std::cout <<
" no ref histogram : " << (
chains[j]+
"/"+
histo.name()) << std::endl;
2136 noreflabel=
"reference not found";
2143 htest->GetYaxis()->SetTitleOffset(1.55);
2144 htest->GetXaxis()->SetTitleOffset(1.5);
2145 htest->GetXaxis()->SetTitle(xaxis.c_str());
2146 htest->GetYaxis()->SetTitle(yaxis.c_str());
2149 href->GetYaxis()->SetTitleOffset(1.5);
2150 href->GetXaxis()->SetTitleOffset(1.5);
2151 href->GetXaxis()->SetTitle(xaxis.c_str());
2152 if (
contains(yaxis,
"Efficiency") && !
contains(yaxis,
"%") && scale_eff==100 )
href->GetYaxis()->SetTitle((yaxis+
" [%]").c_str());
2153 else href->GetYaxis()->SetTitle(yaxis.c_str());
2156 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2161 double xm =
htest->GetMean();
2164 double lxm = std::log10(xm);
2165 int newbins =
int(0.5+xm/
std::pow(10,
int(lxm)))*
pow(10,
int(lxm));
2166 int nrebin =
int( (newbins+5)/10 );
2169 std::cout <<
"rebin: " <<
htest->GetName() <<
"\tbins: " << nrebin << std::endl;
2170 htest->Rebin(nrebin);
2173 href->Rebin(nrebin);
2181 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2184 if ( plotname ==
"" ) {
2187 htest->SetTitle(
"");
2192 htest->SetTitle(
"");
2197 htest->SetTitle(
"");
2202 htest->SetTitle(
"");
2207 htest->SetTitle((
"FTK "+
histo.name()).c_str());
2212 plotname +=
histo.name();
2221 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2234 if ( collection.find(
"_InDet")!=std::string::npos ) collection.erase( 0, collection.find(
"_InDet")+1 );
2235 if ( actual_chain.find(
"_InDet")!=std::string::npos ) actual_chain.erase( actual_chain.find(
"_InDet") );
2238 std::cout <<
"raw: " <<
chains[j] << std::endl;
2240 std::cout <<
"track collection: " << collection << std::endl;
2241 std::cout <<
"actual chain: " << actual_chain << std::endl;
2246 actual_chain = std::regex_replace( actual_chain,
std::regex(
"_HLT_IDTrack.*" ),
"" );
2248 collection = std::regex_replace( collection,
std::regex(
".*HLT_IDTrack_"),
"IDTrack " );
2249 collection = std::regex_replace( collection,
std::regex(
"IDTrack "),
"" );
2250 collection = std::regex_replace( std::regex_replace( collection, rx,
"" ),
rx1,
"" );
2252 if ( actual_chain.find(
"HLT_IDTrack_")!=std::string::npos ) actual_chain.erase( actual_chain.find(
"HLT_IDTrack_"), 12 );
2253 if ( actual_chain.find(
"_IDTrack_")!=std::string::npos ) actual_chain.erase( actual_chain.find(
"_IDTrack_"), 9 );
2254 if ( actual_chain.find(
"IDTrack")!=std::string::npos ) actual_chain.erase( actual_chain.find(
"IDTrack"), 7 );
2255 if ( actual_chain.find(
"_idperf")!=std::string::npos ) actual_chain.erase( actual_chain.find(
"_idperf"), 7 );
2256 if ( actual_chain.find(
"_bperf")!=std::string::npos ) actual_chain.erase( actual_chain.find(
"_bperf"), 6 );
2257 if ( actual_chain.find(
"_boffperf")!=std::string::npos ) actual_chain.erase( actual_chain.find(
"_boffperf"), 9 );
2258 if ( actual_chain.find(
"_HLT_")!=std::string::npos ) actual_chain.replace( actual_chain.find(
"_HLT_"), 5,
" " );
2259 if ( actual_chain.find(
"HLT_")!=std::string::npos ) actual_chain.erase( actual_chain.find(
"HLT_"), 4 );
2261 if ( collection.find(
"_IDTrkNoCut")!=std::string::npos ) collection.erase( collection.find(
"_IDTrkNoCut"), 11 );
2262 if ( collection.find(
"xAODCnv")!=std::string::npos ) collection.erase( collection.find(
"xAODCnv"), 7 );
2263 if ( collection.find(
"HLT_IDTrack_")!=std::string::npos ) collection.erase( collection.find(
"HLT_IDTrack_"), 12 );
2264 if ( collection.find(
"HLT_IDTrack")!=std::string::npos ) collection.erase( collection.find(
"HLT_IDTrack"), 11 );
2265 if ( collection.find(
"Tracking")!=std::string::npos ) collection.replace( collection.find(
"Tracking"), 8,
"Trk" );
2266 if ( collection.find(
"InDetTrigTrk_")!=std::string::npos ) collection.erase( collection.find(
"InDetTrigTrk_"), 13 );
2267 if ( collection.find(
"HLT_xAODTracks_")!=std::string::npos ) collection.erase( collection.find(
"HLT_xAODTracks_"), 15 );
2268 if ( collection.find(
"_HLT_")!=std::string::npos ) collection.replace( collection.find(
"_HLT_"), 5,
" " );
2269 if ( collection.find(
"HLT_")!=std::string::npos ) collection.erase( collection.find(
"HLT_"), 4 );
2272 if ( actual_chain.size()>30 ) {
2273 size_t pos = actual_chain.find_last_of(
"_");
2274 while (
pos!=std::string::npos && actual_chain.size()>30 ) {
2275 actual_chain.erase(
pos, actual_chain.size()-
pos );
2276 actual_chain+=
"...";
2277 pos = actual_chain.find_last_of(
"_");
2281 std::string
c = actual_chain +
" : " + collection;
2283 std::cout <<
"track collection: " << collection <<
" <-" << std::endl;
2284 std::cout <<
"actual chain: " << actual_chain <<
" <-" << std::endl;
2290 std::cout <<
"use label: " <<
c <<
"\tchains size " <<
chains.size() <<
"\t" << usrlabels.size() << std::endl;
2292 std::cout <<
"chains.size() " <<
chains.size() <<
" " << j << std::endl;
2293 std::cout <<
"chains.size() " <<
chains.size() <<
" " << j << std::endl;
2295 std::cout <<
"chains[j] : " << j <<
" " <<
chains[j] << std::endl;
2297 std::cout <<
"userlabels.size() " << usrlabels.size() << std::endl;
2299 if ( usrlabels.size() < j+1 ) {
2300 if ( usrlabels.size()!=0 ) std::cerr <<
"userlabels not large enough - not using userlabels" << std::endl;
2302 else c = usrlabels[ j ];
2304 std::cout <<
"use label: c: " <<
c << std::endl;
2310 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2314 std::cout <<
"\n\n\n\nxaxis: " << xaxis << std::endl;
2318 if ( ALLRANGEMAP || xaxis.find(
"p_{T}")!=std::string::npos || xaxis.find(
"E_{T}")!=std::string::npos ) {
2320 if ( RANGEMAP && xaxis.find(
"p_{T}")!=std::string::npos ) {
2325 if ( RANGEMAP || ALLRANGEMAP ) {
2329 std::cout <<
"\n\n\nctags " << ctags.size() <<
"\n\n" << std::endl;
2331 for (
size_t ic=0 ;
ic<ctags.size() ;
ic++ ) {
2335 std::cout <<
"\n\nic: " <<
ic <<
" " << ctags[
ic] <<
" " << ccolours[
ic] <<
"\n\n" << std::endl;
2338 std::cout <<
"\ttag " << ctags[
ic] <<
" \tcolour: " << ccolours[
ic] <<
"\tstyle: " << cstyles[
ic] << std::endl;
2339 htest->SetLineColor( ccolours[
ic] );
2340 htest->SetMarkerColor( ccolours[
ic] );
2341 htest->SetMarkerStyle( cstyles[
ic] );
2344 tgtest->SetLineColor(
htest->GetMarkerColor());
2345 tgtest->SetMarkerStyle(
htest->GetMarkerStyle());
2346 tgtest->SetMarkerColor(
htest->GetMarkerColor());
2354 std::cout <<
"test: " <<
chains[j] <<
"chains colour: " <<
htest->GetMarkerColor() << std::endl;
2359 std::cout <<
"movin' on ..." << std::endl;
2361 std::cout <<
"chain: " <<
chains[j] <<
" \t marker colour: " <<
htest->GetMarkerColor() << std::endl;
2365 std::cout <<
"Plotter marker : " <<
htest->GetMarkerColor() <<
" " <<
htest->GetMarkerStyle() << std::endl;
2370 std::cout <<
"using label: " <<
c << std::endl;
2374 if ( ALLRANGEMAP || ( RANGEMAP && xaxis.find(
"p_{T}")!=std::string::npos ) )
plots.back().max_entries( ccolours.size() );
2376 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2378 if ( make_ref_efficiencies ) {
2380 if ( htestnum && hrefnum ) {
2385 double range =
h->GetMaximum()-
h->GetMinimum();
2387 if (
range<0.2*scale_eff ) {
2389 double max =
int( (
h->GetMaximum() + 20)*0.1 )*0.1*scale_eff;
2390 double min =
int( (
h->GetMinimum() - 10)*0.1 )*0.1*scale_eff;
2392 if (
max>1*scale_eff )
max = 1.02*scale_eff;
2410 double mean_95 =
htest->GetMean();
2411 double dmean_95 =
htest->GetMeanError();
2412 double rms_95 =
htest->GetRMS();
2413 double drms_95 =
htest->GetRMSError();
2415 Mean.push_back(
label(
" mean = %4.2lf #pm %4.2lf", mean_95, dmean_95) );
2416 RMS.push_back(
label(
" rms = %4.2lf #pm %4.2lf", rms_95, drms_95 ) );
2424 xpos = xpos_original;
2426 std::cout <<
"calculating resolutions : " <<
histo.name() <<
" " <<
htest->GetName() << std::endl;
2430 double mean_95 = d95->GetParameter(1);
2431 double dmean_95 = d95->GetParError(1);
2432 double rms_95 = d95->GetParameter(2);
2433 double drms_95 = d95->GetParError(2);
2435 std::cout <<
"\t\t" <<
histo.name()
2436 <<
"\tmean: " << mean_95 <<
" +- " << dmean_95
2437 <<
"\trms: " << rms_95 <<
" +- " << drms_95 << std::endl;
2442 for (
int ip=-2 ;
ip<9 ;
ip++ ) {
2443 if ( std::fabs(mean_95) >=
std::pow( 10.,
double(-
ip) ) ) {
2449 for (
int ip=-2 ;
ip<9 ;
ip++ ) {
2450 if ( std::fabs(rms_95) >=
std::pow( 10.,
double(-
ip) ) ) {
2459 std::cout <<
"\t\t" <<
histo.name()
2460 <<
"\tmean: " << mean_95 <<
" +- " << dmean_95 <<
" : pow " << mean_power
2461 <<
"\trms: " << rms_95 <<
" +- " << drms_95 <<
" : pow " << rms_power << std::endl;
2464 if ( mean_power == 0 ) {
2465 Mean.push_back(
label(
"mean_{95} = %4.2lf #pm %4.2lf", mean_95, dmean_95) );
2468 Mean.push_back(
label(
"mean_{95} = ( %4.2lf #pm %4.2lf ) #times 10^{%d}",
2469 mean_95*
std::pow(10.,
double(mean_power)), dmean_95*
std::pow(10,
double(mean_power)), -mean_power ) );
2473 if ( rms_power == 0 ) {
2474 RMS.push_back(
label(
"rms_{95} = %4.2lf #pm %4.2lf", rms_95, drms_95 ) );
2477 RMS.push_back(
label(
"rms_{95} = ( %4.2lf #pm %4.2lf ) #times 10^{%d}",
2478 rms_95*
std::pow(10.,
double(rms_power)), drms_95*
std::pow(10,
double(rms_power)), -rms_power ) );
2484 double mean_95ref = d95ref->GetParameter(1);
2485 double dmean_95ref = d95ref->GetParError(1);
2486 double rms_95ref = d95ref->GetParameter(2);
2487 double drms_95ref = d95ref->GetParError(2);
2489 std::cout <<
"\t\t" <<
histo.name()
2490 <<
"\tmean ref: " << mean_95ref <<
" +- " << dmean_95ref <<
" : pow " << mean_power
2491 <<
"\trms ref: " << rms_95ref <<
" +- " << drms_95ref <<
" : pow " << rms_power << std::endl;
2493 if ( mean_power == 0 ) {
2494 MeanRef.push_back(
label(
"mean_{95} ref = %4.2lf #pm %4.2lf", mean_95ref, dmean_95ref) );
2497 MeanRef.push_back(
label(
"mean_{95} ref = ( %4.2lf #pm %4.2lf ) #times 10^{%d}",
2498 mean_95ref*
std::pow(10,
double(mean_power)), dmean_95ref*
std::pow(10,
double(mean_power)), -mean_power ) );
2503 if ( rms_power == 0 ) {
2504 RMSRef.push_back(
label(
"rms_{95} ref = %4.2lf #pm %4.2lf", rms_95ref, drms_95ref ) );
2507 RMSRef.push_back(
label(
"rms_{95} ref = ( %4.2lf #pm %4.2lf ) #times 10^{%d}",
2508 rms_95ref*
std::pow(10,
double(rms_power)), drms_95ref*
std::pow(10,
double(rms_power)), -rms_power ) );
2531 if ( !noreftmp && normref &&
2540 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2547 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2550 plots.sortx( xinfo );
2552 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2565 rmin =
plots.realmin();
2566 rmax =
plots.realmax();
2571 int csize =
chains.size() + taglabels.size() + ( atlasstyle ? 1 : 0 );
2573 if ( yinfo.
log() && rmin>0 && rmax>0 ) {
2576 double delta = std::log10(rmax)-std::log10(rmin);
2581 yminset = rmin*
std::pow(10,-delta*0.1);
2583 double newdelta = std::log10(rmax) - std::log10(yminset) + 0.05*delta;
2585 if ( csize<10 ) ymaxset = rmin*
std::pow(10,newdelta/(1-0.07*csize));
2586 else ymaxset = rmin*
std::pow(10,newdelta*2);
2588 if ( yminset!=yminset ) {
2589 std::cerr <<
" range error " << delta <<
" " << yminset <<
" " << ymaxset <<
"\t(" << rmin <<
" " << rmax <<
")" << std::endl;
2603 double delta = rmax-rmin;
2605 yminset = rmin-0.1*delta;
2607 if ( rmin>=0 && yminset<=0 ) yminset = 0;
2609 double newdelta = rmax - yminset + 0.05*delta;
2611 if ( csize<10 ) ymaxset = yminset + newdelta/(1-0.09*csize);
2612 else ymaxset = yminset + newdelta*2;
2615 double delta = rmax-rmin;
2617 ymaxset = rmax+0.1*delta;
2619 double newdelta = ymaxset - rmin - 0.05*delta;
2621 if ( csize<10 ) yminset = ymaxset - newdelta/(1-0.09*csize);
2622 else yminset = ymaxset - newdelta*2;
2624 if ( rmin>=0 && yminset<=0 ) yminset = 0;
2633 yminset = yinfo.
lo();
2634 ymaxset = yinfo.
hi();
2638 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2647 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2649 if ( yminset>yinfo.
lo() ) yminset = yinfo.
lo();
2650 if ( ymaxset<yinfo.
hi() ) ymaxset = yinfo.
hi();
2656 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2664 if ( ymaxset!=0 || yminset!=0 ) {
2666 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2668 plots.Max( ymaxset );
2669 plots.Min( yminset );
2672 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2674 if ( yminset!=0 || ymaxset!=0 ) {
2675 if ( yminset>0 )
plots.SetLogy(yinfo.
log());
2676 else plots.SetLogy(
false);
2682 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2688 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2692 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2694 if ( atlasstyle )
ATLASLabel( xpos, ypositions[0]+deltay, atlaslabel, kBlack, ncolsp, nrowsp );
2696 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2698 for (
unsigned it=0 ;
it<taglabels.size() ;
it++ ) {
2699 DrawLabel( xpos, ypositions[
it], taglabels[
it], kBlack, 0.04 );
2703 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2706 if ( ( !nostats || !nomeans ) && !noplots ) {
2707 if ( dochi2 )
for (
unsigned j=0 ; j<Chi2.size() ; j++ )
DrawLabel( 0.75, 0.85-j*0.035, Chi2[j],
colours[j%6] );
2710 histo.name()==
"pT" ||
2715 for (
unsigned j=0 ; j<
chains.size() ; j++ ) {
2717 if ( j<MeanRef.size() ) {
2718 if ( !nomeans )
DrawLabel( xpos_original-0.02, (0.67-j*0.035), MeanRef[j],
colours[j%6] );
2722 if ( j<
Mean.size() ) {
2732 if ( xinfo.
log() ) gPad->SetLogx(
true);
2733 else gPad->SetLogx(
false);
2735 if ( yinfo.
log() ) gPad->SetLogy(
true);
2736 else gPad->SetLogy(
false);
2738 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2742 if ( make_ref_efficiencies ) {
2747 plots_eff.
Draw( legend_eff );
2750 if ( !noreflabel.empty() )
DrawLabel(0.1, 0.06, noreflabel, kRed, 0.03 );
2769 std::string useplotname;
2771 if ( panel.
size()>1 ) {
2772 useplotname = panel.
name();
2773 replace( useplotname,
'/',
'_' );
2776 useplotname = plotname;
2779 useplotname.erase(
std::remove( useplotname.begin(), useplotname.end(),
'+' ), useplotname.end() );
2782 std::string printbase =
dir + useplotname +
tag;
2786 if ( !nopdf )
print_pad( printbase+
".pdf" );
2787 if ( !nopng )
print_pad( printbase+
".png" );
2788 if ( Cfile )
print_pad( printbase+
".C" );
2790 std::cout << std::endl;
2795 if ( tc )
delete tc;
2800 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2806 bool files_duplicated = ( fref_==ftest_ );
2808 if ( deleteref && !files_duplicated ) {
2814 std::cout <<
"main() cleaning up reference file" << std::endl;
2816 TFile* newout =
new TFile(
".newout.root",
"recreate");
2831 for (
unsigned j=0 ; j<
dirs.size()-1 ; j++ ) {
2832 std::cout <<
"\t" <<
dirs[j] << std::endl;
2833 TDirectory* renedir =
gDirectory->GetDirectory(
dirs[j].c_str() );
2840 if ( !noreftmp &&
href ) {
2842 href->Write(
dirs.back().c_str() );
2855 if (
fulldbg ) std::cout << __LINE__ << std::endl;
2859 if ( fref_ && !files_duplicated ) fref_->Close();
2860 if ( ftest_ ) ftest_->Close();
2864 if ( deleteref && !noref ) {
2865 std::cout <<
"ref " << frefname <<
"\ttest " << ftestname << std::endl;
2866 if ( frefname != ftestname && !files_duplicated ) {
2867 std::string
cmd = std::string(
"mv ") + frefname +
" " + frefname +
".bak";
2868 std::system(
cmd.c_str() );
2870 cmd = std::string(
"mv .newout.root ") + std::string(frefname);
2871 std::system(
cmd.c_str() );
2874 std::cerr <<
"reference file and test file are the same - not replacing" << std::endl;
2880 if ( fref_ && !files_duplicated )
delete fref_;
2881 if ( ftest_ )
delete ftest_;