CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
List of all members | Public Types | Public Member Functions | Protected Member Functions | Protected Attributes
CompHist Class Referenceabstract

#include <CompHist.h>

Inheritance diagram for CompHist:
FitHist TopInspect ManipHist TopInspectFit CalibClosureTest TopInspectRatio TopInspectSum

Public Types

enum  HistFilter { kBeginsWith, kEndsWith, kContains }
 
enum  RootOutput { kFirstOnly, kLastOnly, kAll }
 

Public Member Functions

 CompHist ()
 
 CompHist (bool verbose)
 
void draw (TCanvas &, TLegend &, int &, int &)
 
void drawEps ()
 
void drawPs ()
 
bool histFilter (TString &, std::vector< std::string > &)
 
bool histFilter (TString &, std::vector< std::string > &, CompHist::HistFilter)
 
void loadHistograms (std::vector< std::string > &, std::vector< TObjArray > &)
 
void loadHistograms ()
 
virtual void readConfig (std::string)=0
 
void setVerbose (bool val)
 
bool verbose ()
 
std::string writeAs ()
 
void writeOutput (CompHist::RootOutput)
 
void writeOutput ()
 
virtual ~CompHist ()
 

Protected Member Functions

void configBlockHist (ConfigFile &)
 
void configBlockIO (ConfigFile &)
 
double findMaximum (int)
 
bool isOutputRequested ()
 
std::string legend (int)
 
void readHistogramList ()
 
void readLabels (std::string, std::vector< std::string > &)
 
void setAxesStyle (TH1 &, const char *, const char *)
 
void setCanvasStyle (TCanvas &)
 
void setCanvGrid (TCanvas &, int)
 
void setCanvLog (TCanvas &, int)
 
void setFillColor (TH1F &, int)
 
void setFillStyle (TH1F &, int)
 
void setHistLabels (TH1F &, int)
 
void setHistMax (TH1F &, int)
 
void setHistMin (TH1F &, int)
 
void setHistScale (TH1F &, int)
 
void setHistStyles (TH1F &, int, int)
 
void setLegendStyle (TLegend &)
 
void setLineColor (TH1F &, int)
 
void setLineStyle (TH1F &, int)
 
void setLineWidth (TH1F &, int)
 
void setMarkerColor (TH1F &, int)
 
void setMarkerSize (TH1F &, int)
 
void setMarkerStyle (TH1F &, int)
 

Protected Attributes

std::vector< short int > commonStyle_
 
std::vector< short int > commonWidth_
 
std::vector< std::string > dirNameList_
 
std::vector< short int > errors_
 
std::vector< TFile * > fileList_
 
std::vector< std::string > fileNameList_
 
std::string filterOpt_
 
std::vector< short int > gridX_
 
std::vector< short int > gridY_
 
std::vector< short int > histColor_
 
std::string histFile_
 
std::vector< std::string > histFilterList_
 
std::vector< std::string > histList_
 
std::vector< short int > histStyle_
 
std::vector< std::string > legendEntries_
 
double legXLeft_
 
double legXRight_
 
double legYLower_
 
double legYUpper_
 
std::vector< short int > logX_
 
std::vector< short int > logY_
 
std::vector< double > markerSize_
 
std::vector< short int > markerStyle_
 
std::vector< double > max_
 
std::vector< double > min_
 
std::string output_
 
std::vector< std::string > outputLabelList_
 
std::vector< std::string > plotFilterList_
 
std::string rootOutDir_
 
std::vector< TObjArray > sampleList_
 
std::vector< double > scale_
 
bool verbose_
 
std::string writeAs_
 
std::string writeTo_
 
std::vector< std::string > xAxes_
 
std::vector< std::string > yAxes_
 

Detailed Description

Definition at line 35 of file CompHist.h.

Member Enumeration Documentation

Enumerator
kBeginsWith 
kEndsWith 
kContains 

Definition at line 40 of file CompHist.h.

Enumerator
kFirstOnly 
kLastOnly 
kAll 

Definition at line 39 of file CompHist.h.

Constructor & Destructor Documentation

CompHist::CompHist ( )
inline

Definition at line 44 of file CompHist.h.

44 :verbose_(false){};
bool verbose_
Definition: CompHist.h:136
CompHist::CompHist ( bool  verbose)
inline

Definition at line 45 of file CompHist.h.

45 :verbose_(verbose){};
bool verbose_
Definition: CompHist.h:136
virtual CompHist::~CompHist ( )
inlinevirtual

Definition at line 47 of file CompHist.h.

47 {};

Member Function Documentation

void CompHist::configBlockHist ( ConfigFile cfg)
protected

Definition at line 72 of file CompHist.cc.

References benchmark_cfg::cerr, cmsRelvalreport::exit, ConfigFile::read(), and readVector().

73 {
74  //-----------------------------------------------
75  // read all configurables defined in CompHisto-
76  // grams from config file. Throw human readable
77  // exception when misspellings occure
78  //-----------------------------------------------
79  try{
80  //-----------------------------------------------
81  // canvas steering
82  //-----------------------------------------------
83  readVector( cfg.read<std::string>( "xLog" ), logX_ );
84  readVector( cfg.read<std::string>( "yLog" ), logY_ );
85  readVector( cfg.read<std::string>( "xGrid" ), gridX_);
86  readVector( cfg.read<std::string>( "yGrid" ), gridY_);
87 
88  //-----------------------------------------------
89  // histogram steering
90  //-----------------------------------------------
91  readVector( cfg.read<std::string>( "histErrors" ), errors_);
92  readVector( cfg.read<std::string>( "histScale" ), scale_ );
93  readVector( cfg.read<std::string>( "histMinimum"), min_ );
94  readVector( cfg.read<std::string>( "histMaximum"), max_ );
95  readVector( cfg.read<std::string>( "histType" ), histStyle_ );
96  readVector( cfg.read<std::string>( "histStyle" ), commonStyle_ );
97  readVector( cfg.read<std::string>( "histColor" ), histColor_ );
98  readVector( cfg.read<std::string>( "lineWidth" ), commonWidth_ );
99  readVector( cfg.read<std::string>( "markerStyle" ), markerStyle_ );
100  readVector( cfg.read<std::string>( "markerSize" ), markerSize_ );
101  readLabels( cfg.read<std::string>( "xAxes" ), xAxes_ );
102  readLabels( cfg.read<std::string>( "yAxes" ), yAxes_ );
103 
104  //-----------------------------------------------
105  // legend steering
106  //-----------------------------------------------
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" );
112  }
113  catch(...){
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;
117  std::exit(1);
118  }
119 }
std::vector< short int > commonStyle_
Definition: CompHist.h:119
std::vector< short int > commonWidth_
Definition: CompHist.h:120
T read(const std::string &key) const
Definition: ConfigFile.h:173
std::vector< short int > errors_
Definition: CompHist.h:126
void readVector(std::string s, std::vector< T > &vec)
Definition: CompHist.h:23
std::vector< short int > histColor_
Definition: CompHist.h:118
std::vector< std::string > legendEntries_
Definition: CompHist.h:131
std::vector< double > max_
Definition: CompHist.h:124
std::vector< double > scale_
Definition: CompHist.h:125
std::vector< short int > gridX_
Definition: CompHist.h:115
void readLabels(std::string, std::vector< std::string > &)
Definition: CompHist.cc:9
std::vector< short int > logX_
Definition: CompHist.h:116
std::vector< std::string > xAxes_
Definition: CompHist.h:123
std::vector< double > min_
Definition: CompHist.h:124
std::vector< short int > histStyle_
Definition: CompHist.h:117
double legXRight_
Definition: CompHist.h:129
double legXLeft_
Definition: CompHist.h:129
std::vector< short int > markerStyle_
Definition: CompHist.h:121
double legYUpper_
Definition: CompHist.h:130
std::vector< std::string > yAxes_
Definition: CompHist.h:123
std::vector< short int > gridY_
Definition: CompHist.h:115
double legYLower_
Definition: CompHist.h:130
std::vector< short int > logY_
Definition: CompHist.h:116
std::vector< double > markerSize_
Definition: CompHist.h:122
void CompHist::configBlockIO ( ConfigFile cfg)
protected

Definition at line 40 of file CompHist.cc.

References benchmark_cfg::cerr, cmsRelvalreport::exit, ConfigFile::read(), and readVector().

41 {
42  //-----------------------------------------------
43  // read all configurables defined in CompHisto-
44  // grams from config file. Throw human readable
45  // exception when misspellings occure
46  //-----------------------------------------------
47  try{
48  //-----------------------------------------------
49  // input/output files
50  //-----------------------------------------------
51  histFile_ = cfg.read<std::string>( "histInput" );
52  readVector ( cfg.read<std::string>( "rootInput" ), fileNameList_ );
53  readVector ( cfg.read<std::string>( "inputDirs" ), dirNameList_ );
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_ );
62  }
63  catch(...){
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;
67  std::exit(1);
68  }
69 }
std::vector< std::string > plotFilterList_
Definition: CompHist.h:107
std::vector< std::string > dirNameList_
Definition: CompHist.h:105
std::string histFile_
Definition: CompHist.h:104
T read(const std::string &key) const
Definition: ConfigFile.h:173
std::string writeTo_
Definition: CompHist.h:111
std::vector< std::string > histFilterList_
Definition: CompHist.h:108
void readVector(std::string s, std::vector< T > &vec)
Definition: CompHist.h:23
std::string output_
Definition: CompHist.h:109
std::vector< std::string > outputLabelList_
Definition: CompHist.h:112
std::string filterOpt_
Definition: CompHist.h:103
std::vector< std::string > fileNameList_
Definition: CompHist.h:106
std::string writeAs_
Definition: CompHist.h:111
std::string rootOutDir_
Definition: CompHist.h:110
void CompHist::draw ( TCanvas &  canv,
TLegend &  leg,
int &  idx,
int &  jdx 
)

Definition at line 294 of file CompHist.cc.

References HistStyle::Filled, estimatePileup::hist, MultipleCompare::legend, HistStyle::Line, and HistStyle::Marker.

295 {
296  //-----------------------------------------------
297  // loop all samples via the list sampleList_, which
298  // containas the histograms of each sample as
299  // TObjects in TObjectArrays
300  //-----------------------------------------------
301  TH1F hfirst; //draw first histogram on top of others
302  //after all histograms have been drawn
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]); //recieve histogram
306  setCanvLog( canv, jdx );
307  setCanvGrid( canv, jdx );
308  setHistStyles( hcmp, jdx, kdx );
309  // for the first histogram just draw
310  // for the following ones draw same
311  if(kdx==0){
312  hfirst = hcmp; // buffer first histogram to redraw it after all
313  if(errors_[kdx])
314  hcmp.Draw("e");
315  else
316  hcmp.Draw( );
317  }
318  else{
319  if(errors_[kdx])
320  hcmp.Draw("samee");
321  else
322  hcmp.Draw("same" );
323  }
324  // add legend entry in appropriate format
325  switch( histStyle_[kdx]){
326  case HistStyle::Line:
327  leg.AddEntry( &hcmp, legend(kdx).c_str(), "L" );
328  break;
329 
330  case HistStyle::Marker:
331  leg.AddEntry( &hcmp, legend(kdx).c_str(), "PL" );
332  break;
333 
334  case HistStyle::Filled:
335  leg.AddEntry( &hcmp, legend(kdx).c_str(), "FL" );
336  break;
337  }
338  }
339  if(errors_[0]){
340  hfirst.Draw("esame");
341  }
342  else{
343  hfirst.Draw( "same");
344  }
345  leg.Draw( "same" );
346  canv.RedrawAxis( );
347  canv.Update( );
348 }
std::vector< TObjArray > sampleList_
Definition: CompHist.h:138
static const int Line
Definition: CompHist.h:17
static const int Marker
Definition: CompHist.h:18
std::vector< short int > errors_
Definition: CompHist.h:126
void setCanvGrid(TCanvas &, int)
Definition: CompHist.cc:515
std::string legend(int)
Definition: CompHist.cc:457
static const int Filled
Definition: CompHist.h:19
void setHistStyles(TH1F &, int, int)
Definition: CompHist.cc:556
std::vector< short int > histStyle_
Definition: CompHist.h:117
void setCanvLog(TCanvas &, int)
Definition: CompHist.cc:498
void CompHist::drawEps ( )

Definition at line 404 of file CompHist.cc.

References gather_cfg::cout, cond::draw(), and convertSQLitetoXML_cfg::output.

Referenced by main().

405 {
406  //-----------------------------------------------
407  // define canvas
408  //-----------------------------------------------
409  TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
410  setCanvasStyle( *canv );
411 
412  //-----------------------------------------------
413  // loop histograms via the list of histogram
414  // names stored in histList_, open a new page
415  // for each histogram & plot each sample in
416  // the same canvas
417  //-----------------------------------------------
418  for(int idx=0, jdx=0; idx<(int)histList_.size(); ++idx){
419  //-----------------------------------------------
420  // prepare compare string for plot filtering
421  //-----------------------------------------------
422  TString cmp( histList_[idx] );
423  if( !histFilter(cmp, plotFilterList_) ){
424  if(verbose_){
425  cout << " event is filtered out according to"
426  << " settings in cfg file; filterOpt: "
427  << filterOpt_
428  << " hist: " << cmp << std::endl;
429  }
430  continue;
431  }
432  //-----------------------------------------------
433  // open output files
434  //-----------------------------------------------
435  TString output( writeTo_.c_str() );
436  output += "/";
437  output += histList_[ idx ];
438  output += ".";
439  output += writeAs_;
440 
441  TPostScript psFile( output, 113);
442  psFile.NewPage();
443  //-----------------------------------------------
444  // on each page the legend needs to be redeclared
445  //-----------------------------------------------
446  TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
447  setLegendStyle( *leg );
448  draw(*canv, *leg, idx, jdx);
449  psFile.Close();
450  ++jdx; delete leg;
451  }
452  canv->Close();
453  delete canv;
454 }
std::vector< std::string > plotFilterList_
Definition: CompHist.h:107
void setLegendStyle(TLegend &)
Definition: CompHist.cc:480
void draw(TCanvas &, TLegend &, int &, int &)
Definition: CompHist.cc:294
std::string writeTo_
Definition: CompHist.h:111
bool histFilter(TString &, std::vector< std::string > &)
Definition: CompHist.cc:244
std::string filterOpt_
Definition: CompHist.h:103
void setCanvasStyle(TCanvas &)
Definition: CompHist.cc:488
bool verbose_
Definition: CompHist.h:136
double legXRight_
Definition: CompHist.h:129
double legXLeft_
Definition: CompHist.h:129
std::vector< std::string > histList_
Definition: CompHist.h:139
double legYUpper_
Definition: CompHist.h:130
std::string writeAs_
Definition: CompHist.h:111
tuple cout
Definition: gather_cfg.py:41
double legYLower_
Definition: CompHist.h:130
void CompHist::drawPs ( )

Definition at line 351 of file CompHist.cc.

References gather_cfg::cout, cond::draw(), and convertSQLitetoXML_cfg::output.

Referenced by main().

352 {
353  //-----------------------------------------------
354  // define canvas
355  //-----------------------------------------------
356  TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
357  setCanvasStyle( *canv );
358 
359  //-----------------------------------------------
360  // open output file
361  //-----------------------------------------------
362  TString output( writeTo_.c_str() );
363  output += "/";
364  output += "inspect";
365  output += ".";
366  output += writeAs_;
367  TPostScript psFile( output, 111); //112 for portrait
368 
369  //-----------------------------------------------
370  // loop histograms via the list of histogram
371  // names stored in histList_, open a new page
372  // for each histogram & plot each sample in
373  // the same canvas
374  //-----------------------------------------------
375  for(int idx=0, jdx=0; idx<(int)histList_.size(); ++idx){
376  // prepare compare string for plot filtering
377  TString cmp( histList_[idx] );
378  if( !histFilter(cmp, plotFilterList_) ){
379  if(verbose_){
380  cout << " event is filtered out according to"
381  << " settings in cfg file; filterOpt: "
382  << filterOpt_
383  << " hist: " << cmp << std::endl;
384  }
385  continue;
386  }
387  psFile.NewPage();
388  //-----------------------------------------------
389  // on each page the legend needs to be redeclared
390  //-----------------------------------------------
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){
395  psFile.Close();
396  }
397  ++jdx; delete leg;
398  }
399  canv->Close();
400  delete canv;
401 }
std::vector< std::string > plotFilterList_
Definition: CompHist.h:107
void setLegendStyle(TLegend &)
Definition: CompHist.cc:480
void draw(TCanvas &, TLegend &, int &, int &)
Definition: CompHist.cc:294
std::string writeTo_
Definition: CompHist.h:111
bool histFilter(TString &, std::vector< std::string > &)
Definition: CompHist.cc:244
std::string filterOpt_
Definition: CompHist.h:103
void setCanvasStyle(TCanvas &)
Definition: CompHist.cc:488
bool verbose_
Definition: CompHist.h:136
double legXRight_
Definition: CompHist.h:129
double legXLeft_
Definition: CompHist.h:129
std::vector< std::string > histList_
Definition: CompHist.h:139
double legYUpper_
Definition: CompHist.h:130
std::string writeAs_
Definition: CompHist.h:111
tuple cout
Definition: gather_cfg.py:41
double legYLower_
Definition: CompHist.h:130
double CompHist::findMaximum ( int  idx)
protected

Definition at line 468 of file CompHist.cc.

References estimatePileup::hist, and max().

469 {
470  double max=-1.;
471  for(std::vector<TObjArray>::const_iterator hist = sampleList_.begin();
472  hist!=sampleList_.end(); ++hist){
473  TH1F& hcmp = *((TH1F*)(*hist)[idx]); //recieve histogram
474  if( max<0 || hcmp.GetMaximum()>max ) max=hcmp.GetMaximum();
475  }
476  return max;
477 }
std::vector< TObjArray > sampleList_
Definition: CompHist.h:138
const T & max(const T &a, const T &b)
bool CompHist::histFilter ( TString &  cmp,
std::vector< std::string > &  ref 
)

Definition at line 244 of file CompHist.cc.

References benchmark_cfg::cerr.

245 {
246  bool contained=true;
247  if(!filterOpt_.empty()){
248  contained=false;
249  if(!filterOpt_.compare("begins")){
250  contained = histFilter(cmp, ref, kBeginsWith);
251  }
252  else if(!filterOpt_.compare("ends")){
253  contained = histFilter(cmp, ref, kEndsWith);
254  }
255  else if(!filterOpt_.compare("contains")){
256  contained = histFilter(cmp, ref, kContains);
257  }
258  else{
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;
262  }
263  }
264  return contained;
265 }
bool histFilter(TString &, std::vector< std::string > &)
Definition: CompHist.cc:244
std::string filterOpt_
Definition: CompHist.h:103
bool CompHist::histFilter ( TString &  cmp,
std::vector< std::string > &  ref,
CompHist::HistFilter  option 
)

Definition at line 268 of file CompHist.cc.

269 {
270  bool contained=true;
271  if(ref.size()>0){
272  contained=false;
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) ){
277  contained=true;
278  break;
279  }
280  if( option==kEndsWith && cmp.EndsWith(buffer) ){
281  contained=true;
282  break;
283  }
284  if( option==kContains && cmp.Contains(buffer) ){
285  contained=true;
286  break;
287  }
288  }
289  }
290  return contained;
291 }
bool CompHist::isOutputRequested ( )
inlineprotected

Definition at line 69 of file CompHist.h.

References rootOutDir_.

69 {return rootOutDir_.size()>1;};
std::string rootOutDir_
Definition: CompHist.h:110
std::string CompHist::legend ( int  idx)
protected

Definition at line 457 of file CompHist.cc.

458 {
459  char buffer[100];
460  sprintf(buffer, "undefined sample %i", idx);
461  if( legendEntries_.size()>=sampleList_.size() ){
462  return legendEntries_[idx];
463  }
464  return buffer;
465 }
std::vector< TObjArray > sampleList_
Definition: CompHist.h:138
std::vector< std::string > legendEntries_
Definition: CompHist.h:131
void CompHist::loadHistograms ( std::vector< std::string > &  histList,
std::vector< TObjArray > &  sampleList 
)

Definition at line 159 of file CompHist.cc.

References benchmark_cfg::cerr, gather_cfg::cout, createBeamHaloJobs::directory, mergeVDriftHistosByStation::file, estimatePileup::hist, and mergeVDriftHistosByStation::name.

Referenced by main().

160 {
161  //fill vector of root files if not already done
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() ) );
166  }
167  }
168  //fill vector of histogram arrays
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){
173  TH1F *dummy;
174  TObjArray hist;
175  for( int idx=0; idx<(int)histList.size(); ++idx ){
176  TString directory( *rootDir );
177  directory+="/";
178  directory+=histList[idx];
179 
180  if(verbose_){
181  std::cout << "load from: " << (*file)->GetName() << " "
182  << "directory: " << directory << std::endl;
183  }
184  dummy = (TH1F*)(*file)->Get( directory );
185  if( !dummy ){
186  std::cerr << "WARNING:"
187  << " Didn't find indicated hist"
188  << " [" << directory << "]"
189  << " in file"
190  << " [" << (*file)->GetName() << "]"
191  << std::endl;
192  return;
193  }
194 
195  // prepare unambiguous histogram name
196  TString outname( fileNameList_[jdx] );
197  outname.Remove(outname.Last('.'), outname.Length());
198  outname += ":";
199  outname += *rootDir;
200  outname +="/";
201  outname +=dummy->GetName();
202  dummy->SetName( outname );
203 
204  // add histogram to list
205  hist.Add( dummy );
206  if(verbose_){
207  std::cout << "added to list as: " << dummy->GetName() << std::endl;
208  }
209  } // end of histogram name list
210  sampleList.push_back( hist );
211  } // end of root directory list
212  } // end of root file list
213 }
std::vector< std::string > dirNameList_
Definition: CompHist.h:105
std::vector< TFile * > fileList_
Definition: CompHist.h:137
std::vector< std::string > fileNameList_
Definition: CompHist.h:106
bool verbose_
Definition: CompHist.h:136
tuple cout
Definition: gather_cfg.py:41
void CompHist::loadHistograms ( )

Definition at line 216 of file CompHist.cc.

References gather_cfg::cout.

217 {
218  //-----------------------------------------------
219  // fill histograms listed in histList_ into a
220  // TObjectArray for each sample given in the
221  // list fileNameList_ and its directories; Each
222  // TObjectArray is then pushed into the vector
223  // sampleList_ which keeps all TObjectArrays of
224  // histograms for each sample
225  //-----------------------------------------------
226 
227  //fill histogram list
228  if( !histFile_.empty() )
230  else{
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";
238  }
239  }
241 }
std::vector< TObjArray > sampleList_
Definition: CompHist.h:138
std::string histFile_
Definition: CompHist.h:104
void readHistogramList()
Definition: CompHist.cc:122
std::vector< std::string > histFilterList_
Definition: CompHist.h:108
std::string filterOpt_
Definition: CompHist.h:103
std::vector< std::string > histList_
Definition: CompHist.h:139
tuple cout
Definition: gather_cfg.py:41
void loadHistograms()
Definition: CompHist.cc:216
virtual void CompHist::readConfig ( std::string  )
pure virtual
void CompHist::readHistogramList ( )
protected

Definition at line 122 of file CompHist.cc.

References benchmark_cfg::cerr, prof2calltree::count, gather_cfg::cout, and estimatePileup::histFile.

123 {
124  //-----------------------------------------------
125  // fill the list histList_ with all requested
126  // histogram names; the names are recieved from
127  // a .hist file; jump out if the reading takes
128  // too long
129  //-----------------------------------------------
130  ifstream histFile( histFile_.c_str() );
131 
132  int count=0;
133  while( !histFile.eof() ){
134  std::string buffer;
135  histFile >> buffer;
136  if( buffer.size()>0 ){
137  TString cmp(buffer);
138  if( histFilter(cmp, histFilterList_) )
139  histList_.push_back(buffer);
140  else{
141  if(verbose_){
142  std::cout << " histogram is filtered out according"
143  << " to settings in cfg file; filterOpt: "
144  << filterOpt_ << std::endl;
145  }
146  }
147  }
148  if( count>999 ){
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;
152  break;
153  }
154  ++count;
155  }
156 }
std::string histFile_
Definition: CompHist.h:104
bool histFilter(TString &, std::vector< std::string > &)
Definition: CompHist.cc:244
std::vector< std::string > histFilterList_
Definition: CompHist.h:108
std::string filterOpt_
Definition: CompHist.h:103
bool verbose_
Definition: CompHist.h:136
std::vector< std::string > histList_
Definition: CompHist.h:139
tuple cout
Definition: gather_cfg.py:41
void CompHist::readLabels ( std::string  s,
std::vector< std::string > &  vec 
)
protected

Definition at line 9 of file CompHist.cc.

References label.

10 {
11  //-----------------------------------------------
12  // fill vector of std::string's from a single
13  // std::string s; the process starts as soon as
14  // leading " are found and starts a new substr
15  // as soon as a "; is encountered
16  //-----------------------------------------------
17  std::stringstream stream( s );
18  std::string buffer, label;
19  while (!stream.eof()) {
20  stream >> buffer;
21  if(buffer.find("\"", 0)==0){
22  //start new label if leading " are found
23  label=buffer;
24  }
25  else{
26  //concatenate buffer to label else
27  label+=" ";
28  label+=buffer;
29  }
30 
31  //push_back label if it starts with " and ends with ";
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) );
35  }
36  }
37 }
const std::string & label
Definition: MVAComputer.cc:186
string s
Definition: asciidump.py:422
void CompHist::setAxesStyle ( TH1 &  hist,
const char *  titleX,
const char *  titleY 
)
protected

Definition at line 532 of file CompHist.cc.

533 {
534  hist.SetTitle( "" );
535 
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 );
545 
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 );
553 }
void CompHist::setCanvasStyle ( TCanvas &  canv)
protected

Definition at line 488 of file CompHist.cc.

489 {
490  canv.SetFillStyle ( 4000 );
491  canv.SetLeftMargin ( 0.20 );
492  canv.SetRightMargin ( 0.05 );
493  canv.SetBottomMargin( 0.15 );
494  canv.SetTopMargin ( 0.05 );
495 }
void CompHist::setCanvGrid ( TCanvas &  canv,
int  idx 
)
protected

Definition at line 515 of file CompHist.cc.

516 {
517  if( idx<((int)gridX_.size()-1) && idx<((int)gridY_.size()-1) ){
518  canv.SetGridx ( gridX_[idx] );
519  canv.SetGridy ( gridY_[idx] );
520  }
521  else if( idx<((int)gridY_.size()-1) ){
522  canv.SetGridx ( 0 );
523  canv.SetGridy ( gridY_[idx] );
524  }
525  else{
526  canv.SetGridx ( 0 );
527  canv.SetGridy ( 0 );
528  }
529 }
std::vector< short int > gridX_
Definition: CompHist.h:115
std::vector< short int > gridY_
Definition: CompHist.h:115
void CompHist::setCanvLog ( TCanvas &  canv,
int  idx 
)
protected

Definition at line 498 of file CompHist.cc.

499 {
500  if( idx<((int)logX_.size()-1) && idx<((int)logY_.size()-1) ){
501  canv.SetLogx ( logX_[idx] );
502  canv.SetLogy ( logY_[idx] );
503  }
504  else if( idx<((int)logY_.size()-1) ){
505  canv.SetLogx ( 0 );
506  canv.SetLogy ( logY_[idx] );
507  }
508  else{
509  canv.SetLogx ( 0 );
510  canv.SetLogy ( 0 );
511  }
512 }
std::vector< short int > logX_
Definition: CompHist.h:116
std::vector< short int > logY_
Definition: CompHist.h:116
void CompHist::setFillColor ( TH1F &  hist,
int  jdx 
)
protected

Definition at line 689 of file CompHist.cc.

690 {
691  hist.SetFillColor( 1 );
692  if( jdx<((int)histColor_.size()) ){
693  hist.SetFillColor(histColor_[jdx]);
694  }
695 }
std::vector< short int > histColor_
Definition: CompHist.h:118
void CompHist::setFillStyle ( TH1F &  hist,
int  jdx 
)
protected

Definition at line 680 of file CompHist.cc.

681 {
682  hist.SetFillStyle( 3005 );
683  if( jdx<((int)commonStyle_.size()) ){
684  hist.SetFillStyle(commonStyle_[jdx]);
685  }
686 }
std::vector< short int > commonStyle_
Definition: CompHist.h:119
void CompHist::setHistLabels ( TH1F &  hist,
int  idx 
)
protected

Definition at line 604 of file CompHist.cc.

605 {
606  if( idx<((int)xAxes_.size()) && idx<((int)yAxes_.size()) ){
607  setAxesStyle( hist, xAxes_[idx].c_str(), yAxes_[idx].c_str() );
608  }
609  else if( idx<((int)xAxes_.size()) ){
610  setAxesStyle( hist, xAxes_[idx].c_str(), "events" );
611  }
612  else{
613  if( strcmp(hist.GetTitle(),"") == 0 ){
614  setAxesStyle( hist, hist.GetXaxis()->GetTitle(), "events" );
615  }
616  else{
617  setAxesStyle( hist, hist.GetTitle(), "events" );
618  }
619  }
620 }
void setAxesStyle(TH1 &, const char *, const char *)
Definition: CompHist.cc:532
std::vector< std::string > xAxes_
Definition: CompHist.h:123
std::vector< std::string > yAxes_
Definition: CompHist.h:123
void CompHist::setHistMax ( TH1F &  hist,
int  idx 
)
protected

Definition at line 631 of file CompHist.cc.

632 {
633  if( ((int)max_.size()>0) && (idx<(int)max_.size()) ){
634  hist.SetMaximum(max_[idx]);
635  }
636  else{
637  hist.SetMaximum(1.5*findMaximum(idx));
638  }
639 }
std::vector< double > max_
Definition: CompHist.h:124
double findMaximum(int)
Definition: CompHist.cc:468
void CompHist::setHistMin ( TH1F &  hist,
int  idx 
)
protected

Definition at line 642 of file CompHist.cc.

643 {
644  if( ((int)min_.size()>0) && (idx<(int)min_.size()) ){
645  hist.SetMinimum(min_[idx]);
646  }
647  else{
648  hist.SetMinimum(0.);
649  }
650 }
std::vector< double > min_
Definition: CompHist.h:124
void CompHist::setHistScale ( TH1F &  hist,
int  idx 
)
protected

Definition at line 623 of file CompHist.cc.

624 {
625  if( idx<((int)scale_.size()) ){
626  if( scale_[idx]>0 ) hist.Scale(scale_[idx]/hist.Integral());
627  }
628 }
std::vector< double > scale_
Definition: CompHist.h:125
void CompHist::setHistStyles ( TH1F &  hist,
int  idx,
int  jdx 
)
protected

Definition at line 556 of file CompHist.cc.

References HistStyle::Filled, HistStyle::Line, and HistStyle::Marker.

557 {
558  //-----------------------------------------------
559  // check hist style; throw exception if style
560  // is not competible with specifications; set
561  // default line[0] if vector is too short
562  //-----------------------------------------------
563  int histType=0;
564  if( jdx<((int)histStyle_.size()) ){
566  histType=histStyle_[jdx];
567  }
568  else{
569  throw "Histogram Type cannot be specified ";
570  }
571  }
572 
573  //define histogram styles
574  setHistLabels( hist, idx );
575  setHistScale ( hist, idx );
576  setHistMax ( hist, idx );
577  setHistMin ( hist, idx );
578 
579  switch( histType ){
580  case HistStyle::Line:
581  setLineWidth( hist, jdx );
582  setLineColor( hist, jdx );
583  setLineStyle( hist, jdx );
584  break;
585 
586  case HistStyle::Marker:
587  setLineWidth ( hist, jdx );
588  setLineColor ( hist, jdx );
589  setMarkerColor( hist, jdx );
590  setMarkerStyle( hist, jdx );
591  setMarkerSize ( hist, jdx );
592  break;
593 
594  case HistStyle::Filled:
595  setLineWidth( hist, jdx );
596  setLineColor( hist, jdx );
597  setFillColor( hist, jdx );
598  setFillStyle( hist, jdx );
599  break;
600  }
601 }
static const int Line
Definition: CompHist.h:17
void setFillColor(TH1F &, int)
Definition: CompHist.cc:689
static const int Marker
Definition: CompHist.h:18
void setHistLabels(TH1F &, int)
Definition: CompHist.cc:604
void setMarkerStyle(TH1F &, int)
Definition: CompHist.cc:698
void setLineColor(TH1F &, int)
Definition: CompHist.cc:671
void setHistMin(TH1F &, int)
Definition: CompHist.cc:642
static const int Filled
Definition: CompHist.h:19
void setHistMax(TH1F &, int)
Definition: CompHist.cc:631
void setLineWidth(TH1F &, int)
Definition: CompHist.cc:653
void setFillStyle(TH1F &, int)
Definition: CompHist.cc:680
void setLineStyle(TH1F &, int)
Definition: CompHist.cc:662
std::vector< short int > histStyle_
Definition: CompHist.h:117
void setMarkerSize(TH1F &, int)
Definition: CompHist.cc:716
void setHistScale(TH1F &, int)
Definition: CompHist.cc:623
void setMarkerColor(TH1F &, int)
Definition: CompHist.cc:707
void CompHist::setLegendStyle ( TLegend &  leg)
protected

Definition at line 480 of file CompHist.cc.

481 {
482  leg.SetFillStyle ( 0 );
483  leg.SetFillColor ( 0 );
484  leg.SetBorderSize( 0 );
485 }
void CompHist::setLineColor ( TH1F &  hist,
int  jdx 
)
protected

Definition at line 671 of file CompHist.cc.

672 {
673  hist.SetLineColor( 1 );
674  if( jdx<((int)histColor_.size()) ){
675  hist.SetLineColor(histColor_[jdx]);
676  }
677 }
std::vector< short int > histColor_
Definition: CompHist.h:118
void CompHist::setLineStyle ( TH1F &  hist,
int  jdx 
)
protected

Definition at line 662 of file CompHist.cc.

663 {
664  hist.SetLineStyle( 1 );
665  if( jdx<((int)commonStyle_.size()) ){
666  hist.SetLineStyle(commonStyle_[jdx]);
667  }
668 }
std::vector< short int > commonStyle_
Definition: CompHist.h:119
void CompHist::setLineWidth ( TH1F &  hist,
int  jdx 
)
protected

Definition at line 653 of file CompHist.cc.

654 {
655  hist.SetLineWidth( 5 );
656  if( jdx<((int)commonWidth_.size()) ){
657  hist.SetLineWidth(commonWidth_[jdx]);
658  }
659 }
std::vector< short int > commonWidth_
Definition: CompHist.h:120
void CompHist::setMarkerColor ( TH1F &  hist,
int  jdx 
)
protected

Definition at line 707 of file CompHist.cc.

708 {
709  hist.SetMarkerColor( 1 );
710  if( jdx<((int)histColor_.size()) ){
711  hist.SetMarkerColor(histColor_[jdx]);
712  }
713 }
std::vector< short int > histColor_
Definition: CompHist.h:118
void CompHist::setMarkerSize ( TH1F &  hist,
int  jdx 
)
protected

Definition at line 716 of file CompHist.cc.

717 {
718  hist.SetMarkerSize( 2.3 );
719  if( jdx<((int)markerSize_.size()) ){
720  hist.SetMarkerSize(markerSize_[jdx]);
721  }
722 }
std::vector< double > markerSize_
Definition: CompHist.h:122
void CompHist::setMarkerStyle ( TH1F &  hist,
int  jdx 
)
protected

Definition at line 698 of file CompHist.cc.

699 {
700  hist.SetMarkerStyle( 23 );
701  if( jdx<((int)markerStyle_.size()) ){
702  hist.SetMarkerStyle(markerStyle_[jdx]);
703  }
704 }
std::vector< short int > markerStyle_
Definition: CompHist.h:121
void CompHist::setVerbose ( bool  val)
inline

Definition at line 51 of file CompHist.h.

References verbose_.

51 {verbose_=val; return;}
bool verbose_
Definition: CompHist.h:136
bool CompHist::verbose ( )
inline

Definition at line 52 of file CompHist.h.

References verbose_.

52 {return verbose_;}
bool verbose_
Definition: CompHist.h:136
std::string CompHist::writeAs ( )
inline

Definition at line 50 of file CompHist.h.

References writeAs_.

Referenced by main().

50 {return writeAs_;}
std::string writeAs_
Definition: CompHist.h:111
void CompHist::writeOutput ( CompHist::RootOutput  option)

Definition at line 725 of file CompHist.cc.

References benchmark_cfg::cerr, mergeVDriftHistosByStation::file, estimatePileup::hist, estimatePileup::histFile, mergeVDriftHistosByStation::name, and dbtoconf::out.

726 {
727  //---------------------------------------------
728  // write filled target histogram to output file
729  // if specified
730  //---------------------------------------------
731  if( isOutputRequested() ){
732  //-----------------------------------------------
733  // open hist file for book keeping of hist names
734  //-----------------------------------------------
735  TString name( output_ );
736  name.Remove(name.Last('.'), name.Length());
737  name+=".hist"; //replace .root by .hist
738  ofstream histFile(name, std::ios::out);
739 
740  //-----------------------------------------------
741  // open root output file and create directory
742  // if necessary
743  //-----------------------------------------------
744  TFile file( output_.c_str(), "update" );
745  if( !file.GetDirectory(rootOutDir_.c_str()) )
746  // create new directory if it does not yet exist
747  file.mkdir( rootOutDir_.c_str(), rootOutDir_.c_str() );
748  else
749  // clean-up directory if it was existing already
750  (file.GetDirectory(rootOutDir_.c_str()))->Delete("*;*");
751  file.cd(rootOutDir_.c_str());
752 
753  //-----------------------------------------------
754  // loop and write out histograms
755  //-----------------------------------------------
756  if( option==kAll ){
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();
762  }
763  }
764  }
765  else{
766  for(unsigned int idx=0; idx<histList_.size(); ++idx){
767  // write first/last histograms in the sample list only
768  histFile << (TH1F*)((sampleList_.back())[idx])->GetName() << "\n";
769  switch( option ){
770  case kFirstOnly:
771  ((TH1F*)((*sampleList_.begin())[idx]))->Write();
772  break;
773  case kLastOnly:
774  ((TH1F*)((sampleList_.back())[idx]))->Write();
775  break;
776  default:
777  std::cerr << "WARNING:"
778  << " Wrong option indicated for writeOutput" << " [" << option
779  << "]" << " while only " << kFirstOnly << " up to " << kAll
780  << " are available" << std::endl;
781  break;
782  }
783  }
784  }
785  file.Close();
786  }
787 }
std::vector< TObjArray > sampleList_
Definition: CompHist.h:138
std::string output_
Definition: CompHist.h:109
tuple out
Definition: dbtoconf.py:99
std::vector< std::string > histList_
Definition: CompHist.h:139
std::string rootOutDir_
Definition: CompHist.h:110
bool isOutputRequested()
Definition: CompHist.h:69
void CompHist::writeOutput ( )
inline

Definition at line 61 of file CompHist.h.

References kAll, and writeOutput().

Referenced by TopInspectRatio::writeOutput(), TopInspectSum::writeOutput(), and writeOutput().

61 {writeOutput(kAll);};
void writeOutput()
Definition: CompHist.h:61

Member Data Documentation

std::vector<short int> CompHist::commonStyle_
protected

Definition at line 119 of file CompHist.h.

std::vector<short int> CompHist::commonWidth_
protected

Definition at line 120 of file CompHist.h.

std::vector<std::string> CompHist::dirNameList_
protected

Definition at line 105 of file CompHist.h.

std::vector<short int> CompHist::errors_
protected

Definition at line 126 of file CompHist.h.

std::vector<TFile*> CompHist::fileList_
protected

Definition at line 137 of file CompHist.h.

std::vector<std::string> CompHist::fileNameList_
protected

Definition at line 106 of file CompHist.h.

std::string CompHist::filterOpt_
protected

Definition at line 103 of file CompHist.h.

std::vector<short int> CompHist::gridX_
protected

Definition at line 115 of file CompHist.h.

std::vector<short int> CompHist::gridY_
protected

Definition at line 115 of file CompHist.h.

std::vector<short int> CompHist::histColor_
protected

Definition at line 118 of file CompHist.h.

std::string CompHist::histFile_
protected

Definition at line 104 of file CompHist.h.

std::vector<std::string> CompHist::histFilterList_
protected

Definition at line 108 of file CompHist.h.

std::vector<std::string> CompHist::histList_
protected

Definition at line 139 of file CompHist.h.

std::vector<short int> CompHist::histStyle_
protected

Definition at line 117 of file CompHist.h.

std::vector<std::string> CompHist::legendEntries_
protected

Definition at line 131 of file CompHist.h.

double CompHist::legXLeft_
protected

Definition at line 129 of file CompHist.h.

double CompHist::legXRight_
protected

Definition at line 129 of file CompHist.h.

double CompHist::legYLower_
protected

Definition at line 130 of file CompHist.h.

double CompHist::legYUpper_
protected

Definition at line 130 of file CompHist.h.

std::vector<short int> CompHist::logX_
protected

Definition at line 116 of file CompHist.h.

std::vector<short int> CompHist::logY_
protected

Definition at line 116 of file CompHist.h.

std::vector<double> CompHist::markerSize_
protected

Definition at line 122 of file CompHist.h.

std::vector<short int> CompHist::markerStyle_
protected

Definition at line 121 of file CompHist.h.

std::vector<double> CompHist::max_
protected

Definition at line 124 of file CompHist.h.

std::vector<double> CompHist::min_
protected

Definition at line 124 of file CompHist.h.

std::string CompHist::output_
protected

Definition at line 109 of file CompHist.h.

std::vector<std::string> CompHist::outputLabelList_
protected

Definition at line 112 of file CompHist.h.

std::vector<std::string> CompHist::plotFilterList_
protected

Definition at line 107 of file CompHist.h.

std::string CompHist::rootOutDir_
protected

Definition at line 110 of file CompHist.h.

Referenced by isOutputRequested().

std::vector<TObjArray> CompHist::sampleList_
protected

Definition at line 138 of file CompHist.h.

std::vector<double> CompHist::scale_
protected

Definition at line 125 of file CompHist.h.

bool CompHist::verbose_
protected

Definition at line 136 of file CompHist.h.

Referenced by setVerbose(), and verbose().

std::string CompHist::writeAs_
protected

Definition at line 111 of file CompHist.h.

Referenced by writeAs().

std::string CompHist::writeTo_
protected

Definition at line 111 of file CompHist.h.

std::vector<std::string> CompHist::xAxes_
protected

Definition at line 123 of file CompHist.h.

std::vector<std::string> CompHist::yAxes_
protected

Definition at line 123 of file CompHist.h.