CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CalibClosureTest.cc
Go to the documentation of this file.
1 #include <memory>
2 #include <string>
3 #include <fstream>
4 #include <iostream>
5 
11 
12 using namespace std;
13 
14 class CalibClosureTest : public ManipHist {
15  public:
18  virtual void readConfig( std::string );
19  void configBlockSpecific(ConfigFile&);
20 
21  //extra members
22  void drawEff();
23  void drawCorrel();
24  TString output(const char*, std::string&, const char*);
25  TString output(const char*, std::string&, std::string&, const char*);
26 
27  private:
28 
29  // extra memebers
30  std::vector<std::string> corrHistNameList_;
31  std::vector<std::string> corrAxesLabelList_;
32  std::vector<std::string> cmpObjLabelList_;
33  std::vector<std::string> effHistNameList_;
34  std::vector<std::string> effAxesLabelList_;
35 };
36 
37 
39 {
40  ConfigFile cfg( name, "=", "$" );
41  configBlockIO ( cfg );
42  configBlockHist( cfg );
43  configBlockFit ( cfg );
44  configBlockSpecific( cfg );
45 }
46 
47 void
49 {
50  //-----------------------------------------------
51  // read all configurables defined in CompHisto-
52  // grams from config file. Throw human readable
53  // exception when misspellings occure
54  //-----------------------------------------------
55  try{
56  //-----------------------------------------------
57  // input/output files
58  //-----------------------------------------------
59  readVector ( cfg.read<std::string>( "corrHistNames" ), corrHistNameList_ );
60  readLabels ( cfg.read<std::string>( "corrAxesLabels"), corrAxesLabelList_);
61  readVector ( cfg.read<std::string>( "effHistNames" ), effHistNameList_ );
62  readLabels ( cfg.read<std::string>( "effAxesLabels" ), effAxesLabelList_ );
63  readVector ( cfg.read<std::string>( "cmpObjectLabels"), cmpObjLabelList_ );
64  }
65  catch(...){
66  std::cerr << "ERROR during reading of config file" << std::endl;
67  std::cerr << " misspelled variables in cfg ?" << std::endl;
68  std::cerr << " [--called in configBlockSpecific--]" << std::endl;
69  std::exit(1);
70  }
71 }
72 
73 TString
74 CalibClosureTest::output(const char* pre, std::string& name, std::string& label, const char* post)
75 {
76  TString buffer( output(pre, name, post) );
77  buffer.Remove(buffer.Last('.'), buffer.Length());
78  buffer+="_";
79  buffer+=label;
80  buffer+=".";
81  buffer+=post;
82  return buffer;
83 }
84 
85 TString
86 CalibClosureTest::output(const char* pre, std::string& name, const char* post)
87 {
88  // prepare name of the output file
89  TString buffer( name );
90  if( ((TString)buffer(buffer.Last('_')+1, buffer.Length())).IsDigit() )
91  buffer.Remove(buffer.Last('_'), buffer.Length()); // chop off everything before the
92  buffer.Remove(0, buffer.Last ('_')+1); // second to last and last '_'
93  TString output( writeTo_.c_str() );
94  output+=pre;
95  output+=buffer;
96  output+= ".";
97  output+=post;
98  return output;
99 }
100 
102 {
103  std::vector<TObjArray> effSampleList;
104  loadHistograms(effHistNameList_, effSampleList);
105 
106  TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
107  setCanvasStyle( *canv );
108  canv->SetGridx( 1 );
109  canv->SetGridy( 1 );
110 
111  //---------------------------------------------
112  // loop histograms via the list of histogram
113  // names stored in effHistNameList_, open a
114  // new page for each histogram; histograms are
115  // expected in order ref(0)/sample(1),...
116  //---------------------------------------------
117  for(unsigned int jdx=0; jdx<effHistNameList_.size()/2; ++jdx){
118  TPostScript psFile(output("/inspectMatch_", effHistNameList_[2*jdx], "eps"), 113);
119  psFile.NewPage();
120 
121  TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
122  setLegendStyle( *leg );
123  //-----------------------------------------------
124  // loop each sample, draw all sample for a given
125  // histogram name in one plot
126  //-----------------------------------------------
127  std::vector<TObjArray>::const_iterator hist = effSampleList.begin();
128  for(unsigned int idx=0; hist!=effSampleList.end(); ++hist, ++idx){
129  TH1F& href = *((TH1F*)(*hist)[2*jdx]); //recieve histograms
130  TH1F& hcmp = *((TH1F*)(*hist)[2*jdx+1]);
131  setHistStyles( hcmp, jdx, idx );
132 
133  if(idx==0){
134  // prepare axes labels
135  char xstring[100], ystring[100];
136  if( idx<effAxesLabelList_.size() )
137  sprintf(xstring, effAxesLabelList_[jdx].c_str(), cmpObjLabelList_[1].c_str());
138  sprintf(ystring, "match^{%s}/match^{%s}", cmpObjLabelList_[0].c_str(), cmpObjLabelList_[1].c_str());
139  hcmp.GetXaxis()->SetTitle( xstring );
140  hcmp.GetYaxis()->SetTitle( ystring );
141  hcmp.SetMinimum(0.85*hcmp.GetMinimum());
142  hcmp.SetMaximum(1.25*hcmp.GetMaximum());
143  divideHistograms(hcmp, href, 1);
144  hcmp.Draw();
145  }
146  else{
147  divideHistograms(hcmp, href, 1);
148  hcmp.Draw("same");
149  }
150  leg->AddEntry( &hcmp, legend( idx ).c_str(), "PL" );
151  }
152  leg->Draw( "same" );
153  canv->RedrawAxis( );
154  canv->Update( );
155  psFile.Close();
156  delete leg;
157  }
158  canv->Close();
159  delete canv;
160 }
161 
163 {
164  std::vector<TObjArray> corrSampleList;
165  loadHistograms(corrHistNameList_, corrSampleList);
166 
167  TCanvas *canv = new TCanvas("canv", "histograms", 600, 600);
168  setCanvasStyle( *canv );
169  canv->SetGridx( 1 );
170  canv->SetGridy( 1 );
171 
172  //---------------------------------------------
173  // loop histograms via the list of histogram
174  // names stored in corrHistNameList_, open a
175  // new file for each histogram and each sample
176  //---------------------------------------------
177  for(unsigned int jdx=0; jdx<corrHistNameList_.size(); ++jdx){
178  //---------------------------------------------
179  // loop all available samples, open a new file
180  // for each sample
181  //---------------------------------------------
182  std::vector<TObjArray>::const_iterator hist = corrSampleList.begin();
183  for(unsigned int idx=0; hist!=corrSampleList.end(); ++hist, ++idx){
184  TLegend* leg = new TLegend(legXLeft_,legYLower_,legXRight_,legYUpper_);
185  setLegendStyle( *leg );
186 
187  TPostScript psFile(output("/inspectCorrel_", corrHistNameList_[jdx], outputLabelList_[idx], "eps"), 113);
188  psFile.NewPage();
189 
190  TH2F& hcmp = *((TH2F*)(*hist)[jdx]);
191  hcmp.SetLineColor ( histColor_[idx] );
192  hcmp.SetFillColor ( histColor_[idx] );
193  hcmp.SetMarkerColor( histColor_[idx] );
194  char xstring[100], ystring[100];
195  if( jdx<corrAxesLabelList_.size() ){
196  sprintf(xstring, corrAxesLabelList_[jdx].c_str(), cmpObjLabelList_[0].c_str() );
197  sprintf(ystring, corrAxesLabelList_[jdx].c_str(), cmpObjLabelList_[1].c_str() );
198  }
199  setAxesStyle( hcmp, xstring, ystring );
200  leg->AddEntry( &hcmp, legend( idx ).c_str(), "FL" );
201  hcmp.Draw("box");
202  leg->Draw( "same" );
203  canv->RedrawAxis( );
204  canv->Update( );
205  psFile.Close();
206  delete leg;
207  }
208  }
209  canv->Close();
210  delete canv;
211 }
212 
213 int main(int argc, char* argv[])
214 {
215  setNiceStyle();
216  gStyle->SetOptStat( 0 );
217  gStyle->SetOptFit ( 0 );
218 
219  gStyle->SetStatColor(0);
220  gStyle->SetStatBorderSize(0);
221  gStyle->SetStatX(0.93);
222  gStyle->SetStatY(0.93);
223  gStyle->SetStatW(0.18);
224  gStyle->SetStatH(0.18);
225 
226  if( argc<2 ){
227  std::cerr << "ERROR:"
228  << " Missing argument" << std::endl;
229  return 1;
230  }
231 
232  CalibClosureTest plots;
233  //plots.setVerbose(true);
234  plots.readConfig( argv[1] );
235  plots.loadHistograms();
236  if( !strcmp(plots.writeAs().c_str(), "ps") ){
237  plots.fitAndDrawPs();
238  plots.fillTargetHistograms();
239  plots.drawPs();
240  } else if( !strcmp(plots.writeAs().c_str(), "eps") ){
241  plots.fitAndDrawEps();
242  plots.fillTargetHistograms();
243  plots.drawEps();
244  } else{
245  std::cerr << "ERROR:"
246  << " Unknown file format requested: "
247  << plots.writeAs() << std::endl;
248  return -1;
249  }
250  plots.drawEff();
251  plots.drawCorrel();
252 
253  std::cout << "works " << "thanx and GoodBye " << std::endl;
254  return 0;
255 }
void configBlockSpecific(ConfigFile &)
void fitAndDrawPs()
Definition: FitHist.cc:314
const std::string & label
Definition: MVAComputer.cc:186
T read(const std::string &key) const
Definition: ConfigFile.h:173
std::vector< std::string > effHistNameList_
void fitAndDrawEps()
Definition: FitHist.cc:414
def main
— Main —############################
void readVector(std::string s, std::vector< T > &vec)
Definition: CompHist.h:23
std::vector< std::string > effAxesLabelList_
TString output(const char *, std::string &, const char *)
virtual void readConfig(std::string)
std::vector< std::string > corrHistNameList_
void fillTargetHistograms()
Definition: FitHist.cc:512
void drawPs()
Definition: CompHist.cc:351
void loadHistograms(std::vector< std::string > &, std::vector< TObjArray > &)
Definition: CompHist.cc:159
std::string writeAs()
Definition: CompHist.h:50
std::vector< std::string > corrAxesLabelList_
tuple cout
Definition: gather_cfg.py:41
boost::shared_ptr< edm::ProcessDesc > readConfig(const std::string &config)
std::vector< std::string > cmpObjLabelList_
void drawEps()
Definition: CompHist.cc:404
void setNiceStyle()
Definition: NiceStyle.cc:3