ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/jbabb/ScriptsAndMacros/logPlotter.C
Revision: 1.1
Committed: Sat Sep 3 21:22:37 2011 UTC (13 years, 8 months ago) by jbabb
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 jbabb 1.1 //ROOT includes
2     #include "TFile.h"
3     #include "TH1F.h"
4     #include "TH2F.h"
5     #include "THStack.h"
6    
7    
8     //System includes
9     #include <TObject.h>
10     #include <TMinuit.h>
11     #include <TLorentzVector.h>
12     #include <TMath.h>
13     #include <TString.h>
14     #include <TStyle.h>
15     #include <TLegend.h>
16     #include <TCanvas.h>
17     #include <TPad.h>
18     #include <TGraphErrors.h>
19     #include <TSystem.h>
20     #include <vector>
21     #include <stdio.h>
22     #include <stdlib.h>
23     #include <iostream>
24     #include <string>
25    
26    
27    
28    
29     void logPlotter() {
30    
31     //input file
32     TString path = "/uscms_data/d2/jbabb/CMSSW_4_2_5/src/TopQuarkAnalysis/Skynet/test/Plots/ZprimeTree_fullyScaledAndTemplated-1564pb-1/";
33     TFile *file = new TFile(path+"nTuplePlots.root", "open");
34    
35    
36     //List the variables that we want plots of
37     int nVariables = 47;
38     int nBins;
39    
40     TString VariableList[] = {
41     "unfittedEvent_ttInvariantMass", "unfittedHadTopMass", "unfittedLepTopMass", "HtJets",
42     "HtJetsLepMET", "drMinMuJ_smuon", "drMaxMuJ_smuon", "dPhiMuMET_smuon", "aplanarity",
43     "centrality", "drJ1J2", "drJ1J3", "drJ2J3", "drMinJ1", "drMinJ2", "drMinJ3", "met",
44     "pt_jet1", "pt_jet2", "pt_jet3", "pt_smuon", "sphericity", "tt_dR", "tt_dPhi", "tt_dTheta",
45     "unfittedHadWMass", "unfittedHadWE", "unfittedHadWPt", "unfittedLepWMass", "unfittedLepWE",
46     "unfittedLepWPt", "unfittedHadTopE", "unfittedHadTopPt", "unfittedLepTopE", "unfittedLepTopPt",
47     "ptRel_muon", "relIso_muon", "pfIso_muon", "MMuJet1_smuon", "MJ1J2J3", "MJ1J2", "MJ1J3", "MJ2J3",
48     "topPtDiff", "topMassDiff", "nHardJets", "bJets"
49     };
50    
51    
52     TString TitleList[] = {
53     "M_{t#bar{t}} (GeV)", "M_{HadTop} (GeV)", "M_{LepTop} (GeV)", "H_{T} Jets (GeV)",
54     "H_{T} Jets+Leps (GeV)", "#Delta R_{Min}(#mu, Jet)", "#Delta R_{Max}(#mu, Jet)", "#Delta #phi (#mu, MET)", "Aplanarity",
55     "Centrality", "#Delta R(Jet1,Jet2)", "#Delta R(Jet1,Jet3)", "#Delta R(Jet2,Jet3)", "#Delta R_{Min} (Jet1, nearest Jet)",
56     "#Delta R_{Min} (Jet2, nearest Jet)", "#Delta R_{Min} (Jet3, nearest Jet)", "MET (GeV)",
57     "p_{T}^{Jet1} (GeV)", "p_{T}^{Jet2} (GeV)", "p_{T}^{Jet3} (GeV)", "p_{T}^{#mu} (GeV)", "Sphericity", "#Delta R t#bar{t}",
58     "#Delta #phi t#bar{t}", "#Delta #theta t#bar{t}",
59     "M_{HadW} (GeV)", "E_{HadW} (GeV)", "p_{T}^{HadW} (GeV)", "M_{LepW} (GeV)", "E_{LepW} (GeV)",
60     "p_{T}^{LepW} (GeV)", "E_{HadTop} (GeV)", "p_{T}^{HadTop} (GeV)", "E_{LepTop} (GeV)", "p_{T}^{LepTop} (GeV)",
61     "p_{T}^{Rel} (#mu, jet) (GeV)", "relIso", "pfIso", "M_{(#mu,Jet1)} (GeV)", "M_{(Jet1, Jet2, Jet3)} (GeV) ",
62     "M_{(Jet1, Jet2)} (GeV) ", "M_{(Jet1, Jet3)} (GeV) ", "M_{(Jet2, Jet3)} (GeV) ",
63     "ttPtDifference (GeV)", "topMassDifference (GeV)", "nJets", "bJets"
64     };
65    
66    
67     double VariableMax[] = { 2200., 750., 500., 2000., 2000., 3., 5., 3.2, 0.3,
68     1.0, 5., 5., 5., 5., 5., 5., 500., 750., 500., 300., 500., 1., 5., 3., 3.,
69     300., 1000., 500., 200., 1000., 500., 1000., 750., 1000., 750., 350., 1.,
70     2., 1000., 1500., 1000., 1000., 1000., 400., 400., 8., 5.
71     };
72    
73     double VariableMin[] = { 200., 100., 100., 100., 150., 0., 1.5, 0.0, 0.0,
74     0.0, 0., 0., 0., 0., 0., 0., 20., 40., 30., 20., 20., 0., 0., 0., 0.,
75     50., 0., 0., 70., 50., 0., 50., 0., 100., 0., 0., 0.,
76     0., 0., 0., 0., 0., 0., 0., 0., 3., 0.
77     };
78    
79    
80     TString PlotType = ".png";
81    
82     //Loop over all of the variables we want to plot
83     for ( int i = 0; i < nVariables; i++ ) {
84    
85     //ST_ TT_ WJ_ ZJets_ QCD_ Data_
86    
87    
88     if (i == (nVariables-1) || i == (nVariables - 2)) nBins = 5;
89     else if (i == 0) nBins = 20;
90     else nBins = 15;
91    
92    
93     //Stack for the MC
94     THStack *hStk = new THStack( VariableList[i], VariableList[i] );
95    
96    
97    
98     TCanvas* c9 = new TCanvas();
99     c9->cd();
100    
101    
102     //TH1F *QCDtemp = new TH1F();
103     //QCDtemp = (TH1F*) file->Get("QCD_"+VariableList[i]);
104     TH1F *QCDtemp = (TH1F*) file->Get("QCD_"+VariableList[i]);
105     TH1F *QCDPlot = new TH1F( "QCD_"+VariableList[i], "QCD_"+VariableList[i], nBins, VariableMin[i], VariableMax[i]);
106    
107     for (int j = 1; j <= nBins; j++){
108    
109     float qcd = QCDtemp->GetBinContent(j);
110     float qcdp = QCDtemp->GetBinCenter(j);
111     //QCDPlot->SetBinContent(j, qcd);
112     QCDPlot->Fill(qcdp, qcd);
113    
114     }//for j
115    
116     //c6->SetLogy();
117     QCDPlot->SetFillColor(kYellow);
118     QCDPlot->Draw();
119     hStk->Add( QCDPlot );
120    
121     delete c9;
122    
123    
124     TCanvas* c9 = new TCanvas();
125     c9->cd();
126    
127    
128     //TH1F *TTtemp = new (TH1F*);
129     //TTtemp = (TH1F*) file->Get("TT_"+VariableList[i]);
130     TH1F *TTtemp = (TH1F*) file->Get("TT_"+VariableList[i]);
131     TH1F *TTPlot = new TH1F( "TT_"+VariableList[i], "TT_"+VariableList[i], nBins, VariableMin[i], VariableMax[i]);
132    
133     for (int k = 1; k <= nBins; k++){
134    
135     float tt = TTtemp->GetBinContent(k);
136     float ttp = TTtemp->GetBinCenter(k);
137     TTPlot->Fill(ttp, tt);
138    
139     }//for j
140    
141     //c6->SetLogy();
142     TTPlot->SetFillColor(kRed+1);
143     TTPlot->Draw();
144     hStk->Add( TTPlot );
145    
146     delete c9;
147    
148    
149    
150    
151     TCanvas* c9 = new TCanvas();
152     c9->cd();
153    
154    
155     TH1F *STtemp = (TH1F*) file->Get("ST_"+VariableList[i]);
156    
157     TH1F *STPlot = new TH1F( "ST_"+VariableList[i], "ST_"+VariableList[i], nBins, VariableMin[i], VariableMax[i]);
158    
159     for (int l = 1; l <= nBins; l++){
160    
161     float st = STtemp->GetBinContent(l);
162     float stp = STtemp->GetBinCenter(l);
163     STPlot->Fill(stp, st);
164    
165     }//for j
166    
167     //c6->SetLogy();
168     STPlot->SetFillColor(kMagenta);
169     STPlot->Draw();
170     hStk->Add( STPlot );
171    
172     delete c9;
173    
174    
175    
176    
177     TCanvas* c9 = new TCanvas();
178     c9->cd();
179    
180    
181     TH1F *WJtemp = (TH1F*) file->Get("WJ_"+VariableList[i]);
182    
183     TH1F *WJPlot = new TH1F( "WJ_"+VariableList[i], "WJ_"+VariableList[i], nBins, VariableMin[i], VariableMax[i]);
184    
185     for (int m = 1; m <= nBins; m++){
186    
187     float wj = WJtemp->GetBinContent(m);
188     float wjp = WJtemp->GetBinCenter(m);
189     WJPlot->Fill(wjp, wj);
190    
191     }//for j
192    
193     //c6->SetLogy();
194     WJPlot->SetFillColor(kGreen);
195     WJPlot->Draw();
196     hStk->Add( WJPlot );
197    
198     delete c9;
199    
200    
201    
202     TCanvas* c9 = new TCanvas();
203     c9->cd();
204    
205    
206     TH1F *ZJtemp = (TH1F*) file->Get("ZJets_"+VariableList[i]);
207    
208     TH1F *ZJPlot = new TH1F( "ZJ_"+VariableList[i], "ZJ_"+VariableList[i], nBins, VariableMin[i], VariableMax[i]);
209    
210     for (int n = 1; n <= nBins; n++){
211    
212     float zj = ZJtemp->GetBinContent(n);
213     float zjp = ZJtemp->GetBinCenter(n);
214     ZJPlot->Fill(zjp, zj);
215    
216     }//for j
217    
218     //c6->SetLogy();
219     ZJPlot->SetFillColor(kAzure-2);
220     ZJPlot->Draw();
221     hStk->Add( ZJPlot );
222    
223     delete c9;
224     /*
225    
226     TH1F *VVtemp = (TH1F*) file->Get("VV_"+VariableList[i]);
227    
228     TH1F *VVPlot = new TH1F( "VV_"+VariableList[i], "VV_"+VariableList[i], nBins, VariableMin[i], VariableMax[i]);
229    
230     for (int j = 1; j == nBins; j++){
231    
232     float vv = VVtemp->GetBinContent(j);
233     VVPlot->SetBinContent(j, vv);
234    
235     }//for j
236    
237     //c6->SetLogy();
238     VVPlot->SetFillColor(kBlue);
239     VVPlot->Draw();
240     //hStk->Add( VVPlot );
241     */
242    
243    
244    
245     TCanvas* c9 = new TCanvas();
246     c9->cd();
247    
248     TH1F *DATAtemp = (TH1F*) file->Get("Data_"+VariableList[i]);
249     TH1F *DataPlot = new TH1F( "Data_"+VariableList[i], "Data_"+VariableList[i], nBins, VariableMin[i], VariableMax[i]);
250    
251     for (int o = 1; o <= nBins; o++){
252    
253     float data = DATAtemp->GetBinContent(o);
254     float datap = DATAtemp->GetBinCenter(o);
255     DataPlot->Fill(datap, data);
256    
257     }//for j
258    
259     //c6->SetLogy();
260     DataPlot->Draw("PE");
261    
262     delete c9;
263    
264    
265    
266    
267     TCanvas* c9 = new TCanvas();
268     c9->cd();
269    
270     c9->SetLogy(1);
271     c9->Update();
272    
273     double yscale = 10000.;
274     //double max1 = 1.;
275     //double max2 = 1.;
276    
277    
278     //max1 = hStk->GetMaximum();
279     //max2 = DataPlot->GetBinContent(DataPlot->GetMaximumBin());
280    
281    
282     //if (max1 > max2) yscale = max1*1.25;
283     // else yscale = max2*1.25;
284    
285    
286     //yscale = (DataPlot->GetBinContent(DataPlot->GetMaximumBin()))+10000.;
287    
288     c9->Update();
289    
290     DataPlot->Draw("PE");
291     c9->Update();
292     hStk->Draw("SAME");
293     c9->Update();
294     DataPlot->Draw("PE SAME");
295    
296     c9->Update();
297    
298     //DataPlot->GetYaxis()->SetRangeUser(0., yscale);
299     hStk->GetYaxis()->SetRangeUser(0., yscale);
300    
301     DataPlot->GetXaxis()->SetTitle(TitleList[i]);
302     hStk->GetXaxis()->SetTitle(TitleList[i]);
303    
304     if (i ==0 ) {
305    
306     DataPlot->GetYaxis()->SetTitle("Events / 100 GeV");
307     hStk->GetYaxis()->SetTitle("Events / 100 GeV");
308    
309     }
310    
311     c9->Update();
312    
313    
314     TLegend *leg = new TLegend(.8, .78, 0.97, 0.95);
315     leg->AddEntry(QCDPlot, "QCD", "f");
316     leg->AddEntry(STPlot, "Single Top", "f");
317     leg->AddEntry(ZJPlot, "Z+jets", "f");
318     leg->AddEntry(WJPlot, "W+jets", "f");
319     //leg->AddEntry(VVPlot, "Diboson", "f");
320     leg->AddEntry(TTPlot, "t #bar{t}", "f");
321     leg->AddEntry(DataPlot, "2011 Data", "p");
322     leg->Draw();
323    
324     //(x1,y1,x2,y2)
325     TPaveText *pt = new TPaveText(0.35,0.9,0.78,0.95,"brNDC");
326     //pt->SetFillColor(18);
327     pt->SetTextAlign(12);
328     //pt->AddText("CMS preliminary");
329     pt->AddText("CMS preliminary: 1564 pb^{-1} at #sqrt{s} = 7 TeV");
330     pt->Draw();
331    
332    
333     c9->Update();
334    
335    
336    
337     TString plotname = VariableList[i]+"_Log"+PlotType;
338     c9->Print( plotname );
339    
340    
341     delete c9;
342     delete hStk;
343    
344     delete TTPlot;
345     delete STPlot;
346     delete WJPlot;
347     delete ZJPlot;
348     delete QCDPlot;
349     //delete VVPlot;
350     delete DataPlot;
351    
352    
353     }//for i
354    
355     }//logPlotter