CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PlotCombiner.cc
Go to the documentation of this file.
1 /*
2  Macro to make the plots .......................................
3 
4  Instructions:
5  a. set up an input file that looks like the following:
6  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7  # zee or wenu
8  wenu
9  # file name, type (sig, qcd, bce, gje, ewk), weight
10  histos_wenu.root sig 1.46
11  histos_q20_30.root qcd 0
12  histos_q30_80.root qcd 100.
13  histos_q80_170.root qcd 0
14  histos_b20_30.root bce 0
15  histos_b30_80.root bce 0
16  histos_b80_170.root bce 0
17  histos_zee.root ewk 0
18  histos_wtaunu.root ewk 0
19  histos_ztautau.root ewk 0
20  histos_gj15.root gje 0
21  histos_gj20.root gje 0
22  histos_gj25.root gje 10.12
23  histos_gj30.root gje 0
24  histos_gj35.root gje 0
25  histos_wmunu.root ewk 0
26  histos_ttbar.root ewk 0
27  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
28  lines that start with # are considered to be comments
29  line 2 has wenu or zee. From line 4 the list of the histo files are listed
30  (first word) then a type that could be sig,qcd,bce, gj or ewk in order to
31  discriminate among different sources of bkgs and finally the weight that we
32  want to weight the histogram entries. This particular example is for Wenu. For
33  Zee one has to put type sig in the zee file and ewk in the Wenu file. The order
34  of the files is arbitrary. Files with weight 0 will be ignored.
35  After you have set up this code you run a root macro to combine the plots.
36  You can do (not recommended - it actually crushes - to be debugged)
37  root -b PlotCombiner.cc
38  or to compile it within root (recommended)
39  root -b
40  root [1] .L PlotCombiner.cc++
41  root [2] PlotCombiner()
42 
43  and you finally get the plots.
44 
45  TO DO:
46  functionalities to plot more kind of plots, e.g. efficiencies
47 
48 
49  Further Questions/Contact:
50 
51  nikolaos.rompotis @ cern.ch
52 
53 
54 
55  Nikolaos Rompotis - 29 June 09
56  18 Sept 09: 1st updgrade: input files in a text file
57  Imperial College London
58 
59 
60 */
61 
62 
63 #include <iostream>
64 #include <fstream>
65 #include <vector>
66 #include <string>
67 #include "TString.h"
68 #include "TROOT.h"
69 #include "TStyle.h"
70 #include "TH1F.h"
71 #include "TFile.h"
72 #include "TCanvas.h"
73 #include "TLegend.h"
74 
75 void plotMaker(TString histoName, TString typeOfplot,
76  vector<TString> file, vector<TString> type,
77  vector<double> weight,
78  TString xtitle, Int_t NBins, Double_t min, Double_t max);
79 
80 
82 {
83  // read the file
84  ifstream input("inputFiles");
85  int i = 0;
86  TString typeOfplot = "";
87  vector<TString> types;
88  vector<TString> files;
89  vector<double> weights;
90 
91  if (input.is_open()) {
92  std::string myline;
93  while (! input.eof()) {
94  getline(input, myline);
95  TString line(myline);
96  TString c('#');
97  TString empty(' ');
98  if (line[0] != c) {
99  ++i;
100  if (i==1) typeOfplot=line;
101  else {
102  // read until you find 3 words
103  TString fname("");
104  TString ftype("");
105  TString fw("");
106  int lineSize = (int) line.Length();
107  int j=0;
108  while (j<lineSize) {
109  if(line[j] != empty) fname += line[j];
110  else break;
111  ++j;
112  }
113  while (j<lineSize) {
114  if(line[j] != empty) ftype += line[j];
115  else if(ftype.Length()==3) break;
116  ++j;
117  }
118  while (j<lineSize) {
119  if(line[j] != empty) fw += line[j];
120  else{ if(fw.Length()>0) break;}
121  ++j;
122  }
123  if (fname.Length() == 0) break;
124  files.push_back(fname);
125  types.push_back(ftype);
126  double w = fw.Atof();
127  weights.push_back(w);
128  std::cout << fname << ", " << ftype << ", "<< w << std::endl;
129  }
130  }
131  }
132  input.close();
133  }
134  else {
135  std::cout << "File with name inputFile was not found" << std::endl;
136  return;
137  }
138 
139  // now you can launch the jobs
140  if (typeOfplot == "wenu") {
141  cout << "wenu plot maker" << endl;
142  // ====================
143  // =====> WHICH HISTOS TO PLOT
144  // ====================
145  plotMaker("h_met", typeOfplot, files, types, weights, "MET (GeV)", 100,0,100);
146  }
147  else {
148  cout << "zee plot maker" << endl;
149  // ====================
150  // =====> WHICH HISTOS TO PLOT
151  // ====================
152  plotMaker("h_mee", typeOfplot, files, types, weights, "M_{ee} (GeV)", 150,0,150);
153  }
154 
155 
156 }
157 
158 
159 
160 void plotMaker(TString histoName, TString wzsignal,
161  vector<TString> file, vector<TString> type,
162  vector<double> weight,
163  TString xtitle, Int_t NBins, Double_t min, Double_t max)
164 {
165  gROOT->Reset();
166  gROOT->ProcessLine(".L tdrstyle.C");
167  gROOT->ProcessLine("setTDRStyle()");
168 
169  // Wenu Signal .......................................................
170  TH1F h_wenu("h_wenu", "h_wenu", NBins, min, max);
171  int fmax = (int) file.size();
172  for (int i=0; i<fmax; ++i) {
173  if (type[i] == "sig" && weight[i]>0) {
174  TFile f(file[i]);
175  TH1F *h = (TH1F*) f.Get(histoName);
176  h_wenu.Add(h, weight[i]);
177  }
178  }
179  // Bkgs ..............................................................
180  //
181  // QCD light flavor
182  TH1F h_qcd("h_qcd", "h_qcd", NBins, min, max);
183  for (int i=0; i<fmax; ++i) {
184  if (type[i] == "qcd" && weight[i]>0) {
185  TFile f(file[i]);
186  TH1F *h = (TH1F*) f.Get(histoName);
187  h_qcd.Add(h, weight[i]);
188  }
189  }
190  // QCD heavy flavor
191  TH1F h_bce("h_bce", "h_bce", NBins, min, max);
192  for (int i=0; i<fmax; ++i) {
193  if (type[i] == "bce" && weight[i]>0) {
194  TFile f(file[i]);
195  TH1F *h = (TH1F*) f.Get(histoName);
196  h_bce.Add(h, weight[i]);
197  }
198  }
199  // QCD Gjets
200  TH1F h_gj("h_gj", "h_gj", NBins, min, max);
201  for (int i=0; i<fmax; ++i) {
202  if (type[i] == "gje" && weight[i]>0) {
203  TFile f(file[i]);
204  TH1F *h = (TH1F*) f.Get(histoName);
205  h_gj.Add(h, weight[i]);
206  }
207  }
208  // Other EWK bkgs
209  TH1F h_ewk("h_ewk", "h_ewk", NBins, min, max);
210  for (int i=0; i<fmax; ++i) {
211  if (type[i] == "ewk" && weight[i]>0) {
212  TFile f(file[i]);
213  TH1F *h = (TH1F*) f.Get(histoName);
214  h_ewk.Add(h, weight[i]);
215  }
216  }
217  //
218  // ok now decide how to plot them:
219  // first the EWK bkgs
220  h_ewk.SetFillColor(3);
221  //
222  // then the gjets
223  h_gj.Add(&h_ewk);
224  h_gj.SetFillColor(1);
225  // thent the QCD dijets
226  h_bce.Add(&h_qcd);
227  h_bce.Add(&h_gj);
228  h_bce.SetFillColor(2);
229  // and the signal at last
230  TH1F h_tot("h_tot", "h_tot", NBins, min, max);
231  h_tot.Add(&h_bce);
232  h_tot.Add(&h_wenu);
233  h_wenu.SetLineColor(4); h_wenu.SetLineWidth(2);
234  //
235  TCanvas c;
236  h_tot.GetXaxis()->SetTitle(xtitle);
237  h_tot.Draw("PE");
238  h_bce.Draw("same");
239  h_gj.Draw("same");
240  h_ewk.Draw("same");
241  h_wenu.Draw("same");
242 
243  // the Legend
244  TLegend leg(0.6,0.65,0.95,0.92);
245  if (wzsignal == "wenu")
246  leg.AddEntry(&h_wenu, "W#rightarrow e#nu","l");
247  else
248  leg.AddEntry(&h_wenu, "Z#rightarrow ee","l");
249  leg.AddEntry(&h_tot, "Signal + Bkg","p");
250  leg.AddEntry(&h_bce, "dijets","f");
251  leg.AddEntry(&h_gj, "#gamma + jets","f");
252  leg.AddEntry(&h_ewk, "EWK+t#bar t", "f");
253  leg.Draw("same");
254 
255  c.Print("test.png");
256 
257 
258 
259 }
260 
261 
262 
type
Definition: HCALResponse.h:21
int i
Definition: DBlmapReader.cc:9
void plotMaker(TString histoName, TString typeOfplot, vector< TString > file, vector< TString > type, vector< double > weight, TString xtitle)
void PlotCombiner()
const double w
Definition: UKUtility.cc:23
static std::string const input
Definition: EdmProvDump.cc:43
int j
Definition: DBlmapReader.cc:9
double f[11][100]
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
T min(T a, T b)
Definition: MathUtil.h:58
string fname
main script
tuple cout
Definition: gather_cfg.py:121