CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CompHist.h
Go to the documentation of this file.
1 #ifndef CompHist_h
2 #define CompHist_h
3 
4 #include <memory>
5 #include <string>
6 #include <vector>
7 #include <sstream>
8 #include <fstream>
9 #include <iostream>
10 
14 
15 
16 namespace HistStyle{
17  static const int Line = 0;
18  static const int Marker = 1;
19  static const int Filled = 2;
20 }
21 
22 template <class T>
23 void readVector(std::string s, std::vector<T>& vec)
24 {
25  std::stringstream stream( s );
26  T buffer;
27  while (!stream.eof()) {
28  stream >> buffer;
29  if(!stream.str().empty()){
30  vec.push_back( buffer );
31  }
32  }
33 }
34 
35 class CompHist{
36 
37  public:
38 
41 
42  public:
43 
45  CompHist(bool verbose):verbose_(verbose){};
46  //~CompHist(){ file_->Close(); };
47  virtual ~CompHist(){};
48  virtual void readConfig( std::string )=0;
49 
50  std::string writeAs(){return writeAs_;}
51  void setVerbose(bool val) {verbose_=val; return;}
52  bool verbose() {return verbose_;}
53  void loadHistograms(std::vector<std::string>&, std::vector<TObjArray>&);
54  void loadHistograms();
55  void drawPs();
56  void drawEps();
57  void draw(TCanvas&, TLegend&, int&, int&);
58  bool histFilter(TString&, std::vector<std::string>&);
59  bool histFilter(TString&, std::vector<std::string>&, CompHist::HistFilter);
62 
63  protected:
64 
65  // io helpers
68  void readLabels(std::string, std::vector<std::string>&);
69  bool isOutputRequested(){return rootOutDir_.size()>1;};
70  void readHistogramList();
71 
72  // save way to get members
73  std::string legend(int);
74 
75  // histogram manipulators
76  void setLegendStyle(TLegend&);
77  void setCanvasStyle(TCanvas&);
78  void setCanvLog(TCanvas&, int);
79  void setCanvGrid(TCanvas&, int);
80  void setAxesStyle(TH1&, const char*, const char*);
81  void setHistStyles(TH1F&, int, int);
82  void setHistLabels(TH1F&, int);
83  void setHistScale(TH1F&, int);
84  void setHistMax(TH1F&, int);
85  void setHistMin(TH1F&, int);
86  void setLineWidth (TH1F&, int);
87  void setLineStyle(TH1F&, int);
88  void setLineColor(TH1F&, int);
89  void setFillStyle(TH1F&, int);
90  void setFillColor(TH1F&, int);
91  void setMarkerStyle(TH1F&, int);
92  void setMarkerColor(TH1F&, int);
93  void setMarkerSize(TH1F&, int);
94  double findMaximum(int);
95 
96  protected:
97 
98  //---------------------------------------------
99  // Interface
100  //---------------------------------------------
101 
102  // define input/output
103  std::string filterOpt_; // filter option for different filtering types
104  std::string histFile_; // name of .hist file
105  std::vector<std::string> dirNameList_; // list of directory names in .root file(s)
106  std::vector<std::string> fileNameList_; // list of .root files
107  std::vector<std::string> plotFilterList_; // list of filter patterns for histograms to be ploted
108  std::vector<std::string> histFilterList_; // list of filter patterns for histograms to be loaded
109  std::string output_; // potential root output
110  std::string rootOutDir_; // root directory for potential root output
111  std::string writeTo_, writeAs_; // type (ps/eps) and directory of output
112  std::vector<std::string> outputLabelList_; // list of .root files
113 
114  // define histogram design
115  std::vector<short int> gridX_, gridY_; // grid in x/y to be set?
116  std::vector<short int> logX_, logY_; // log in x/y to be set?
117  std::vector<short int> histStyle_; // line, marker, filled?
118  std::vector<short int> histColor_; // line/fill color?
119  std::vector<short int> commonStyle_; // fill or line style
120  std::vector<short int> commonWidth_; // line width
121  std::vector<short int> markerStyle_; // marker style
122  std::vector<double> markerSize_; // marker size
123  std::vector<std::string> xAxes_, yAxes_; // x/y axes labels
124  std::vector<double> min_, max_; // min/max of histogram (to be set by hand)
125  std::vector<double> scale_; // scale if wanted
126  std::vector<short int> errors_; // show histogram with errors?
127 
128  // define legend design
129  double legXLeft_, legXRight_; // legend boundaries (common to all histograms)
130  double legYLower_, legYUpper_; // legend boundaries (common to all histograms)
131  std::vector<std::string> legendEntries_; // list of legend entries
132 
133  //---------------------------------------------
134  // Internals
135  //---------------------------------------------
136  bool verbose_;
137  std::vector<TFile*> fileList_;
138  std::vector<TObjArray> sampleList_;
139  std::vector<std::string> histList_;
140 };
141 #endif
std::vector< short int > commonStyle_
Definition: CompHist.h:119
std::vector< TObjArray > sampleList_
Definition: CompHist.h:138
void setFillColor(TH1F &, int)
Definition: CompHist.cc:689
std::vector< short int > commonWidth_
Definition: CompHist.h:120
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
void configBlockHist(ConfigFile &)
Definition: CompHist.cc:72
void setLegendStyle(TLegend &)
Definition: CompHist.cc:480
Definition: Line.h:10
void draw(TCanvas &, TLegend &, int &, int &)
Definition: CompHist.cc:294
static const int Marker
Definition: CompHist.h:18
std::vector< short int > errors_
Definition: CompHist.h:126
void setAxesStyle(TH1 &, const char *, const char *)
Definition: CompHist.cc:532
void configBlockIO(ConfigFile &)
Definition: CompHist.cc:40
void setHistLabels(TH1F &, int)
Definition: CompHist.cc:604
void setMarkerStyle(TH1F &, int)
Definition: CompHist.cc:698
void readHistogramList()
Definition: CompHist.cc:122
std::string writeTo_
Definition: CompHist.h:111
bool histFilter(TString &, std::vector< std::string > &)
Definition: CompHist.cc:244
std::vector< std::string > histFilterList_
Definition: CompHist.h:108
void readVector(std::string s, std::vector< T > &vec)
Definition: CompHist.h:23
virtual void readConfig(std::string)=0
void setCanvGrid(TCanvas &, int)
Definition: CompHist.cc:515
std::vector< short int > histColor_
Definition: CompHist.h:118
std::string legend(int)
Definition: CompHist.cc:457
void setLineColor(TH1F &, int)
Definition: CompHist.cc:671
void setHistMin(TH1F &, int)
Definition: CompHist.cc:642
std::vector< TFile * > fileList_
Definition: CompHist.h:137
RootOutput
Definition: CompHist.h:39
static const int Filled
Definition: CompHist.h:19
std::vector< std::string > legendEntries_
Definition: CompHist.h:131
void setHistMax(TH1F &, int)
Definition: CompHist.cc:631
std::vector< double > max_
Definition: CompHist.h:124
std::string output_
Definition: CompHist.h:109
std::vector< double > scale_
Definition: CompHist.h:125
void setLineWidth(TH1F &, int)
Definition: CompHist.cc:653
std::vector< short int > gridX_
Definition: CompHist.h:115
std::vector< std::string > outputLabelList_
Definition: CompHist.h:112
bool verbose()
Definition: CompHist.h:52
void readLabels(std::string, std::vector< std::string > &)
Definition: CompHist.cc:9
std::string filterOpt_
Definition: CompHist.h:103
std::vector< std::string > fileNameList_
Definition: CompHist.h:106
void setFillStyle(TH1F &, int)
Definition: CompHist.cc:680
void writeOutput()
Definition: CompHist.h:61
HistFilter
Definition: CompHist.h:40
void setHistStyles(TH1F &, int, int)
Definition: CompHist.cc:556
std::vector< short int > logX_
Definition: CompHist.h:116
void setCanvasStyle(TCanvas &)
Definition: CompHist.cc:488
bool verbose_
Definition: CompHist.h:136
std::vector< std::string > xAxes_
Definition: CompHist.h:123
std::vector< double > min_
Definition: CompHist.h:124
void setLineStyle(TH1F &, int)
Definition: CompHist.cc:662
void drawPs()
Definition: CompHist.cc:351
std::vector< short int > histStyle_
Definition: CompHist.h:117
CompHist()
Definition: CompHist.h:44
double legXRight_
Definition: CompHist.h:129
void setMarkerSize(TH1F &, int)
Definition: CompHist.cc:716
std::string writeAs()
Definition: CompHist.h:50
double legXLeft_
Definition: CompHist.h:129
double findMaximum(int)
Definition: CompHist.cc:468
std::vector< std::string > histList_
Definition: CompHist.h:139
void setHistScale(TH1F &, int)
Definition: CompHist.cc:623
std::vector< short int > markerStyle_
Definition: CompHist.h:121
double legYUpper_
Definition: CompHist.h:130
std::string writeAs_
Definition: CompHist.h:111
virtual ~CompHist()
Definition: CompHist.h:47
std::string rootOutDir_
Definition: CompHist.h:110
string s
Definition: asciidump.py:422
void loadHistograms()
Definition: CompHist.cc:216
std::vector< std::string > yAxes_
Definition: CompHist.h:123
std::vector< short int > gridY_
Definition: CompHist.h:115
void setCanvLog(TCanvas &, int)
Definition: CompHist.cc:498
double legYLower_
Definition: CompHist.h:130
CompHist(bool verbose)
Definition: CompHist.h:45
std::vector< short int > logY_
Definition: CompHist.h:116
void setMarkerColor(TH1F &, int)
Definition: CompHist.cc:707
void drawEps()
Definition: CompHist.cc:404
bool isOutputRequested()
Definition: CompHist.h:69
std::vector< double > markerSize_
Definition: CompHist.h:122
void setVerbose(bool val)
Definition: CompHist.h:51