17 std::stringstream stream( s );
18 std::string buffer,
label;
19 while (!stream.eof()) {
21 if(buffer.find(
"\"", 0)==0){
32 if(buffer.find(
"\"", buffer.size()-2)==buffer.size()-2 &&
33 buffer.find(
";", buffer.size()-2)==buffer.size()-1){
34 vec.push_back( label.substr(1, label.size()-3) );
51 histFile_ = cfg.
read<std::string>(
"histInput" );
52 readVector ( cfg.
read<std::string>(
"rootInput" ), fileNameList_ );
54 filterOpt_ = cfg.
read<std::string>(
"filterOption" );
55 readVector ( cfg.
read<std::string>(
"histFilter" ), histFilterList_ );
56 readVector ( cfg.
read<std::string>(
"plotFilter" ), plotFilterList_ );
57 writeTo_ = cfg.
read<std::string>(
"writePlotsTo" );
58 writeAs_ = cfg.
read<std::string>(
"writePlotsAs" );
59 rootOutDir_= cfg.
read<std::string>(
"outputDir" );
60 output_ = cfg.
read<std::string>(
"rootOutput" );
61 readVector ( cfg.
read<std::string>(
"outputLabels" ), outputLabelList_ );
64 std::cerr <<
"ERROR during reading of config file" << std::endl;
65 std::cerr <<
" misspelled variables in cfg ?" << std::endl;
66 std::cerr <<
" [--called in configBlockIO--]" << std::endl;
99 readVector( cfg.
read<std::string>(
"markerStyle" ), markerStyle_ );
101 readLabels( cfg.
read<std::string>(
"xAxes" ), xAxes_ );
102 readLabels( cfg.
read<std::string>(
"yAxes" ), yAxes_ );
107 readLabels( cfg.
read<std::string>(
"legEntries"), legendEntries_);
108 legXLeft_ = cfg.
read<
double>(
"legXLeft" );
109 legXRight_= cfg.
read<
double>(
"legXRight" );
110 legYLower_= cfg.
read<
double>(
"legYLower" );
111 legYUpper_= cfg.
read<
double>(
"legYUpper" );
114 std::cerr <<
"ERROR during reading of config file" << std::endl;
115 std::cerr <<
" misspelled variables in cfg ?" << std::endl;
116 std::cerr <<
" [--called in configBlockHist--]" << std::endl;
130 ifstream
histFile( histFile_.c_str() );
136 if( buffer.size()>0 ){
138 if( histFilter(cmp, histFilterList_) )
139 histList_.push_back(buffer);
142 std::cout <<
" histogram is filtered out according"
143 <<
" to settings in cfg file; filterOpt: "
144 << filterOpt_ << std::endl;
149 std::cerr <<
"ERROR caught in slope for histogram" << std::endl;
150 std::cerr <<
" names. Misspelled file name ?" << std::endl;
151 std::cerr << histFile_.c_str() << std::endl;
162 if( fileList_.empty() ){
163 std::vector<std::string>::const_iterator
name;
164 for(name = fileNameList_.begin(); name!=fileNameList_.end(); ++
name){
165 fileList_.push_back(
new TFile( name->c_str() ) );
169 std::vector<TFile*>::const_iterator
file = fileList_.begin();
170 for(
int jdx=0 ; file!=fileList_.end(); ++
file, ++jdx){
171 std::vector<std::string>::const_iterator rootDir;
172 for(rootDir = dirNameList_.begin(); rootDir!=dirNameList_.end(); ++rootDir){
175 for(
int idx=0; idx<(int)histList.size(); ++idx ){
178 directory+=histList[idx];
181 std::cout <<
"load from: " << (*file)->GetName() <<
" "
182 <<
"directory: " << directory << std::endl;
184 dummy = (TH1F*)(*file)->Get( directory );
187 <<
" Didn't find indicated hist"
188 <<
" [" << directory <<
"]"
190 <<
" [" << (*file)->GetName() <<
"]"
196 TString outname( fileNameList_[jdx] );
197 outname.Remove(outname.Last(
'.'), outname.Length());
201 outname +=dummy->GetName();
202 dummy->SetName( outname );
207 std::cout <<
"added to list as: " << dummy->GetName() << std::endl;
210 sampleList.push_back( hist );
228 if( !histFile_.empty() )
231 if( histFilterList_.size()>0 ){
232 if( !filterOpt_.compare(
"contains") )
233 cout <<
"WARNING: missing hist file in cfg file; will use list of histogram" << std::endl
234 <<
" names given in histFilter instead, requires filterOption " << std::endl
235 <<
" 'optains'; will move filterOption to 'optain' to go on..." << std::endl;
236 filterOpt_=
"contains";
237 histList_ =histFilterList_;
240 loadHistograms(histList_, sampleList_);
247 if(!filterOpt_.empty()){
249 if(!filterOpt_.compare(
"begins")){
250 contained = histFilter(cmp, ref, kBeginsWith);
252 else if(!filterOpt_.compare(
"ends")){
253 contained = histFilter(cmp, ref, kEndsWith);
255 else if(!filterOpt_.compare(
"contains")){
256 contained = histFilter(cmp, ref, kContains);
259 std::cerr <<
"ERROR during histogram filtering " << std::endl;
260 std::cerr <<
" filter option is not properly" << std::endl;
261 std::cerr <<
" specified : " << filterOpt_ << std::endl;
273 for(
unsigned int idx=0; idx<ref.size(); ++idx){
274 TString buffer(ref[idx]);
275 if( !option==kContains ) buffer+=
"_";
276 if( option==kBeginsWith && cmp.BeginsWith(buffer) ){
280 if( option==kEndsWith && cmp.EndsWith(buffer) ){
284 if( option==kContains && cmp.Contains(buffer) ){
303 std::vector<TObjArray>::const_iterator
hist = sampleList_.begin();
304 for(
int kdx=0; hist!=sampleList_.end(); ++
hist, ++kdx){
305 TH1F& hcmp = *((TH1F*)(*hist)[idx]);
306 setCanvLog( canv, jdx );
307 setCanvGrid( canv, jdx );
308 setHistStyles( hcmp, jdx, kdx );
325 switch( histStyle_[kdx]){
327 leg.AddEntry( &hcmp, legend(kdx).c_str(),
"L" );
331 leg.AddEntry( &hcmp, legend(kdx).c_str(),
"PL" );
335 leg.AddEntry( &hcmp, legend(kdx).c_str(),
"FL" );
340 hfirst.Draw(
"esame");
343 hfirst.Draw(
"same");
356 TCanvas *canv =
new TCanvas(
"canv",
"histograms", 600, 600);
357 setCanvasStyle( *canv );
362 TString
output( writeTo_.c_str() );
367 TPostScript psFile( output, 111);
375 for(
int idx=0, jdx=0; idx<(int)histList_.size(); ++idx){
377 TString cmp( histList_[idx] );
378 if( !histFilter(cmp, plotFilterList_) ){
380 cout <<
" event is filtered out according to"
381 <<
" settings in cfg file; filterOpt: "
383 <<
" hist: " << cmp << std::endl;
391 TLegend* leg =
new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
392 setLegendStyle( *leg );
393 draw(*canv, *leg, idx, jdx);
394 if(idx == (
int)histList_.size()-1){
409 TCanvas *canv =
new TCanvas(
"canv",
"histograms", 600, 600);
410 setCanvasStyle( *canv );
418 for(
int idx=0, jdx=0; idx<(int)histList_.size(); ++idx){
422 TString cmp( histList_[idx] );
423 if( !histFilter(cmp, plotFilterList_) ){
425 cout <<
" event is filtered out according to"
426 <<
" settings in cfg file; filterOpt: "
428 <<
" hist: " << cmp << std::endl;
435 TString
output( writeTo_.c_str() );
437 output += histList_[ idx ];
441 TPostScript psFile( output, 113);
446 TLegend* leg =
new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
447 setLegendStyle( *leg );
448 draw(*canv, *leg, idx, jdx);
460 sprintf(buffer,
"undefined sample %i", idx);
461 if( legendEntries_.size()>=sampleList_.size() ){
462 return legendEntries_[idx];
471 for(std::vector<TObjArray>::const_iterator
hist = sampleList_.begin();
473 TH1F& hcmp = *((TH1F*)(*
hist)[idx]);
474 if( max<0 || hcmp.GetMaximum()>
max ) max=hcmp.GetMaximum();
482 leg.SetFillStyle ( 0 );
483 leg.SetFillColor ( 0 );
484 leg.SetBorderSize( 0 );
490 canv.SetFillStyle ( 4000 );
491 canv.SetLeftMargin ( 0.20 );
492 canv.SetRightMargin ( 0.05 );
493 canv.SetBottomMargin( 0.15 );
494 canv.SetTopMargin ( 0.05 );
500 if( idx<((
int)logX_.size()-1) && idx<((
int)logY_.size()-1) ){
501 canv.SetLogx ( logX_[idx] );
502 canv.SetLogy ( logY_[idx] );
504 else if( idx<((
int)logY_.size()-1) ){
506 canv.SetLogy ( logY_[idx] );
517 if( idx<((
int)gridX_.size()-1) && idx<((
int)gridY_.size()-1) ){
518 canv.SetGridx ( gridX_[idx] );
519 canv.SetGridy ( gridY_[idx] );
521 else if( idx<((
int)gridY_.size()-1) ){
523 canv.SetGridy ( gridY_[idx] );
536 hist.GetXaxis()->SetTitle( titleX );
537 hist.GetXaxis()->SetTitleSize ( 0.06 );
538 hist.GetXaxis()->SetTitleColor ( 1 );
539 hist.GetXaxis()->SetTitleOffset( 1.0 );
540 hist.GetXaxis()->SetTitleFont ( 62 );
541 hist.GetXaxis()->SetLabelSize ( 0.05 );
542 hist.GetXaxis()->SetLabelFont ( 62 );
543 hist.GetXaxis()->CenterTitle ( );
544 hist.GetXaxis()->SetNdivisions ( 505 );
546 hist.GetYaxis()->SetTitle( titleY );
547 hist.GetYaxis()->SetTitleSize ( 0.07 );
548 hist.GetYaxis()->SetTitleColor ( 1 );
549 hist.GetYaxis()->SetTitleOffset( 1.3 );
550 hist.GetYaxis()->SetTitleFont ( 62 );
551 hist.GetYaxis()->SetLabelSize ( 0.05 );
552 hist.GetYaxis()->SetLabelFont ( 62 );
564 if( jdx<((
int)histStyle_.size()) ){
566 histType=histStyle_[jdx];
569 throw "Histogram Type cannot be specified ";
574 setHistLabels( hist, idx );
575 setHistScale ( hist, idx );
576 setHistMax ( hist, idx );
577 setHistMin ( hist, idx );
581 setLineWidth( hist, jdx );
582 setLineColor( hist, jdx );
583 setLineStyle( hist, jdx );
587 setLineWidth ( hist, jdx );
588 setLineColor ( hist, jdx );
589 setMarkerColor( hist, jdx );
590 setMarkerStyle( hist, jdx );
591 setMarkerSize ( hist, jdx );
595 setLineWidth( hist, jdx );
596 setLineColor( hist, jdx );
597 setFillColor( hist, jdx );
598 setFillStyle( hist, jdx );
606 if( idx<((
int)xAxes_.size()) && idx<((
int)yAxes_.size()) ){
607 setAxesStyle( hist, xAxes_[idx].c_str(), yAxes_[idx].c_str() );
609 else if( idx<((
int)xAxes_.size()) ){
610 setAxesStyle( hist, xAxes_[idx].c_str(),
"events" );
613 if( strcmp(hist.GetTitle(),
"") == 0 ){
614 setAxesStyle( hist, hist.GetXaxis()->GetTitle(),
"events" );
617 setAxesStyle( hist, hist.GetTitle(),
"events" );
625 if( idx<((
int)scale_.size()) ){
626 if( scale_[idx]>0 ) hist.Scale(scale_[idx]/hist.Integral());
633 if( ((
int)max_.size()>0) && (idx<(
int)max_.size()) ){
634 hist.SetMaximum(max_[idx]);
637 hist.SetMaximum(1.5*findMaximum(idx));
644 if( ((
int)min_.size()>0) && (idx<(
int)min_.size()) ){
645 hist.SetMinimum(min_[idx]);
655 hist.SetLineWidth( 5 );
656 if( jdx<((
int)commonWidth_.size()) ){
657 hist.SetLineWidth(commonWidth_[jdx]);
664 hist.SetLineStyle( 1 );
665 if( jdx<((
int)commonStyle_.size()) ){
666 hist.SetLineStyle(commonStyle_[jdx]);
673 hist.SetLineColor( 1 );
674 if( jdx<((
int)histColor_.size()) ){
675 hist.SetLineColor(histColor_[jdx]);
682 hist.SetFillStyle( 3005 );
683 if( jdx<((
int)commonStyle_.size()) ){
684 hist.SetFillStyle(commonStyle_[jdx]);
691 hist.SetFillColor( 1 );
692 if( jdx<((
int)histColor_.size()) ){
693 hist.SetFillColor(histColor_[jdx]);
700 hist.SetMarkerStyle( 23 );
701 if( jdx<((
int)markerStyle_.size()) ){
702 hist.SetMarkerStyle(markerStyle_[jdx]);
709 hist.SetMarkerColor( 1 );
710 if( jdx<((
int)histColor_.size()) ){
711 hist.SetMarkerColor(histColor_[jdx]);
718 hist.SetMarkerSize( 2.3 );
719 if( jdx<((
int)markerSize_.size()) ){
720 hist.SetMarkerSize(markerSize_[jdx]);
731 if( isOutputRequested() ){
735 TString
name( output_ );
736 name.Remove(name.Last(
'.'), name.Length());
744 TFile
file( output_.c_str(),
"update" );
745 if( !
file.GetDirectory(rootOutDir_.c_str()) )
747 file.mkdir( rootOutDir_.c_str(), rootOutDir_.c_str() );
750 (
file.GetDirectory(rootOutDir_.c_str()))->Delete(
"*;*");
751 file.cd(rootOutDir_.c_str());
757 std::vector<TObjArray>::const_iterator
hist = sampleList_.begin();
758 for( ;hist!=sampleList_.end(); ++
hist){
759 for(
unsigned int idx=0; idx<histList_.size(); ++idx){
760 histFile << ((TH1F*)(*hist)[idx])->GetName() <<
"\n";
761 ((TH1F*)(*hist)[idx])->Write();
766 for(
unsigned int idx=0; idx<histList_.size(); ++idx){
768 histFile << (TH1F*)((sampleList_.back())[idx])->GetName() <<
"\n";
771 ((TH1F*)((*sampleList_.begin())[idx]))->Write();
774 ((TH1F*)((sampleList_.back())[idx]))->Write();
778 <<
" Wrong option indicated for writeOutput" <<
" [" << option
779 <<
"]" <<
" while only " << kFirstOnly <<
" up to " << kAll
780 <<
" are available" << std::endl;
void setFillColor(TH1F &, int)
void configBlockHist(ConfigFile &)
void setLegendStyle(TLegend &)
T read(const std::string &key) const
void draw(TCanvas &, TLegend &, int &, int &)
void setAxesStyle(TH1 &, const char *, const char *)
void configBlockIO(ConfigFile &)
void setHistLabels(TH1F &, int)
void setMarkerStyle(TH1F &, int)
bool histFilter(TString &, std::vector< std::string > &)
void readVector(std::string s, std::vector< T > &vec)
void setCanvGrid(TCanvas &, int)
void setLineColor(TH1F &, int)
void setHistMin(TH1F &, int)
void setHistMax(TH1F &, int)
const T & max(const T &a, const T &b)
void setLineWidth(TH1F &, int)
void readLabels(std::string, std::vector< std::string > &)
void setFillStyle(TH1F &, int)
void setHistStyles(TH1F &, int, int)
void setCanvasStyle(TCanvas &)
void setLineStyle(TH1F &, int)
void setMarkerSize(TH1F &, int)
void setHistScale(TH1F &, int)
void setCanvLog(TCanvas &, int)
void setMarkerColor(TH1F &, int)