ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/Anghel/macros/makePlotsCombined.cc
Revision: 1.1
Committed: Fri Jan 29 23:12:58 2010 UTC (15 years, 3 months ago) by anghel
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Log Message:
Revision 29Jan2010

File Contents

# User Rev Content
1 anghel 1.1 #include "../../Style.cc"
2     #include "TFile.h"
3     #include "TH1F.h"
4     #include "THStack.h"
5     #include "TMath.h"
6     #include "TLatex.h"
7     #include "TLegend.h"
8     #include "TCanvas.h"
9     #include <iostream>
10     #include <string>
11    
12     using namespace std;
13    
14     void makePlotsCombined() {
15     Style();
16     TLatex *latex = new TLatex();
17     latex->SetNDC();
18    
19     TFile *file;
20     file = TFile::Open("histosFilenoTagging_1.root");
21     //file = TFile::Open("histosFileMediumOP_1.root");
22     //file = TFile::Open("histosFileTightOP_1.root");
23     file->cd();
24    
25     string dataType[20] = {"TTjets","Wjets_Wbb","Wjets_Wcc","Wjets_Wjets","Zjets_Wbb","Zjets_Wcc","Zjets_Wjets","VqqW_Wbb","VqqW_Wb","VqqW_Wcc","VqqW_Wc","VqqZ_Wbb","VqqZ_Wb","VqqZ_Wcc","VqqZ_Wc","Wc_Wc","inclusiveMu","Tops","Topt","ToptW"};
26    
27     int N = 10; //# of combined samples
28     Int_t color[10] = {kRed,kAzure,kTeal,kGreen+1,kMagenta,kBlue+3,kYellow,kOrange+4,kMagenta+3,kRed-7};
29     string combDataType[10] = {"TTjets","inclusiveMu","singleTop","Wjets_bb","Wjets_cc","Wjets_light","Wc","Zjets_bb","Zjets_cc","Zjets_light"};
30    
31     //define histograms and related parameters
32     string histoType[12] = {"jetMultiplicity_4binInclusive","tagjetMultiplicity","tagBjetMultiplicity","jetPt","tagjetPt","tagBjetPt","jetFlavor","tagjetFlavor","metEt","pdgID","bpartonsDR","cpartonsDR"};
33     string histoLabelX[12] = {"# of jets","# of tags","# of B tags","p_{T}^{good_Jet}","p_{T}^{tagged_Jet}","p_{T}^{tagged_Bjet}","jet_Flavor","taggedjet_Flavor","E_{T}^{#nu}","partonID","DR","DR"};
34     Int_t xbins[12] = {4,4,4,500,500,500,25,25,500,20,40,40};
35     Double_t xlow[12] = {0.,0.,0.,0.,0.,0.,0.,0.,0.,-10.,-20.,-20.};
36     Double_t xhigh[12] = {4.,4.,4.,300.,300.,300.,25.,25.,300.,10.,20.,20.};
37    
38     //int k=2;
39     //file[k]->cd();
40    
41     //TH1F *f;
42     //gDirectory->GetObject(histoType[0].c_str(),f);
43     //cout << "name = " << f->GetName() << endl;
44    
45     TH1F *combHist[120];
46     TH1F *flavorHist[20];
47    
48     TH1F *hist[240];
49     THStack *hs[3];
50     hs[0] = new THStack("hs","");
51     hs[1] = new THStack("hstag","");
52     hs[2] = new THStack("hstagB","");
53    
54     for (int i=0; i < 12; i++) { //loop over histo types
55     for (int icomb=0; icomb != N; icomb++) { //loop over combined histos types for defining them
56     string combHistName = combDataType[icomb]+"_"+histoType[i];
57     if ((i==6)||(i==7)) combHist[i*N+icomb] = new TH1F(combHistName.c_str(),"",2000,0.,2000.);
58     if ((i==3)||(i==4)||(i==5)||(i==8)) combHist[i*N+icomb] = new TH1F(combHistName.c_str(),"",500,0.,500.);
59     else if ((i!=3)&&(i!=4)&&(i!=5)&&(i!=8)&&(i!=6)&&(i!=7)) combHist[i*N+icomb] = new TH1F(combHistName.c_str(), "", xbins[i],xlow[i],xhigh[i]);
60     }
61     for (int j=0; j < 20; j++) { //read histos from the root file
62     string histName;
63     if ((dataType[j]=="TTjets")||(dataType[j]=="inclusiveMu")||(dataType[j]=="Tops")||(dataType[j]=="Topt")||(dataType[j]=="ToptW")) histName = "h_" + histoType[i]+"_"+dataType[j]+"_noFilter";
64     else histName = "h_" + histoType[i]+"_"+dataType[j];
65     cout << histName << endl;
66     hist[i*20+j] = (TH1F*) file->Get(histName.c_str());
67    
68     //gDirectory->GetObject(histName.c_str(),hist[i*N+j]);
69     cout << "hist[" << i*20+j << "] = " << hist[i*20+j]->GetName() << endl;
70     //hist[i*N+j]->Sumw2();
71    
72     if (dataType[j]=="TTjets") combHist[i*N] -> Add(combHist[i*N],hist[i*20+j],1.0,1.0);
73     if (dataType[j]=="inclusiveMu") combHist[i*N+1] -> Add(combHist[i*N+1],hist[i*20+j],1.0,1.0);
74     if ((dataType[j]=="Tops")||(dataType[j]=="Topt")||(dataType[j]=="ToptW")) combHist[i*N+2] -> Add(combHist[i*N+2],hist[i*20+j],1.0,1.0);
75     if ((dataType[j]=="Wjets_Wbb")||(dataType[j]=="VqqW_Wbb")||(dataType[j]=="VqqW_Wb")) combHist[i*N+3] -> Add(combHist[i*N+3],hist[i*20+j],1.0,1.0);
76     if ((dataType[j]=="Wjets_Wcc")||(dataType[j]=="VqqW_Wcc")||(dataType[j]=="VqqW_Wc")) combHist[i*N+4] -> Add(combHist[i*N+4],hist[i*20+j],1.0,1.0);
77     if (dataType[j]=="Wjets_Wjets") combHist[i*N+5] -> Add(combHist[i*N+5],hist[i*20+j],1.0,1.0);
78     if (dataType[j]=="Wc_Wc") combHist[i*N+6] -> Add(combHist[i*N+6],hist[i*20+j],1.0,1.0);
79     if ((dataType[j]=="Zjets_Wbb")||(dataType[j]=="VqqZ_Wbb")||(dataType[j]=="VqqZ_Wb")) combHist[i*N+7] -> Add(combHist[i*N+7],hist[i*20+j],1.0,1.0);
80     if ((dataType[j]=="Zjets_Wcc")||(dataType[j]=="VqqZ_Wbb")||(dataType[j]=="VqqZ_Wb")) combHist[i*N+8] -> Add(combHist[i*N+8],hist[i*20+j],1.0,1.0);
81     if (dataType[j]=="Zjets_Wjets") combHist[i*N+9] -> Add(combHist[i*N+9],hist[i*20+j],1.0,1.0);
82     } //end loop for reading the histos from the root file
83    
84     for (int icomb=0; icomb != N; icomb++) { //loop over combined histos types
85     combHist[i*N+icomb]->SetLineColor(color[icomb]);
86     if (i < 3) {
87     combHist[i*N+icomb]->SetFillStyle(1000);
88     combHist[i*N+icomb]->SetFillColor(color[icomb]);
89     }
90     else {
91     combHist[i*N+icomb]->SetMarkerStyle(20);
92     combHist[i*N+icomb]->SetMarkerColor(color[icomb]);
93     combHist[i*N+icomb]->SetMarkerSize(1.4);
94     }
95     combHist[i*N+icomb]->SetStats(0);
96     if ((i==3)||(i==4)||(i==5)||(i==8)) combHist[i*N+icomb]->Rebin(8); //rebin for Pt of the jets
97    
98     combHist[i*N+icomb]->GetXaxis()->SetRangeUser(xlow[i], xhigh[i]);
99     //if ((i==6)||(i==7)) combHist[i*N+icomb]->GetYaxis()->SetRangeUser(1.0e-10,90000);
100     //if ((i==3)||(i==4)||(i==5)||(i==8)) combHist[i*N+icomb]->GetYaxis()->SetRangeUser(1.0e-10,60000);
101     combHist[i*N+icomb]->GetXaxis()->SetTitle((histoLabelX[i]).c_str());
102     combHist[i*N+icomb]->GetYaxis()->SetTitle("Entries");
103     combHist[i*N+icomb]->SetTitle("");
104     }
105    
106     if(i < 3) {
107     TCanvas *canvas3 = new TCanvas(histoType[i].c_str(), "");
108     for (int icomb=0; icomb < N; icomb++) hs[i]->Add(combHist[i*N+icomb]);
109     hs[i]->Draw();
110     TLegend *legend3 = new TLegend(0.7, 0.3, 0.9, 0.85);
111     for (int icomb=0; icomb < N; icomb++) legend3->AddEntry(combHist[i*N+icomb],combDataType[icomb].c_str());
112     legend3->Draw();
113     legend3->SetFillColor(kWhite);
114     latex->DrawLatex(0.22,0.91,histoType[i].c_str());
115     string nameCanvas3 = histoType[i]+".eps";
116     canvas3->SaveAs(nameCanvas3.c_str());
117     }
118    
119     if ((i > 8)) {
120     TCanvas *canvas1 = new TCanvas(histoType[i].c_str(), "");
121     combHist[i*N+5]->Draw("hist e0");
122     for (int icomb=0; icomb != N; icomb++) {
123     if (icomb==5) continue;
124     combHist[i*N+icomb]->Draw("same hist e0");
125     }
126     TLegend *legend1 = new TLegend(0.7, 0.3, 0.9, 0.85);
127     for (int icomb=0; icomb < N; icomb++) legend1->AddEntry(combHist[i*N+icomb],combDataType[icomb].c_str());
128     legend1->Draw();
129     legend1->SetFillColor(kWhite);
130     latex->DrawLatex(0.22,0.91,histoType[i].c_str());
131     //canvas1->SetLogy();
132     string nameCanvas1 = histoType[i]+".eps";
133     canvas1->SaveAs(nameCanvas1.c_str());
134     }
135    
136     if ((i==3)||(i==4)||(i==5)||(i==8)) {
137     TCanvas *canvas2 = new TCanvas(histoType[i].c_str(), "");
138     combHist[i*N+5]->Draw("P e0");
139     for (int icomb=0; icomb != N; icomb++) {
140     if (icomb==5) continue;
141     combHist[i*N+icomb]->Draw("same P e0");
142     }
143     TLegend *legend2 = new TLegend(0.7, 0.3, 0.9, 0.85);
144     for (int icomb=0; icomb < N; icomb++) legend2->AddEntry(combHist[i*N+icomb],combDataType[icomb].c_str());
145     legend2->Draw();
146     legend2->SetFillColor(kWhite);
147     latex->DrawLatex(0.22,0.91,histoType[i].c_str());
148     //canvas2->SetLogy();
149     string nameCanvas2 = histoType[i]+".eps";
150     canvas2->SaveAs(nameCanvas2.c_str());
151     }
152    
153     if ((i==6)||(i==7)) {
154     for (int k=0; k!=N; k++) {
155     string flavorHistName = combHist[i*N+k]->GetName();
156     flavorHist[(i-6)*N+k] = new TH1F((flavorHistName+"_newbinning").c_str(),"",26,-0.5,25.5);
157     for (int ibin=1; ibin!=26; ibin++) {
158     double value = combHist[i*N+k]->GetBinContent(ibin);
159     flavorHist[(i-6)*N+k]->SetBinContent(ibin,value);
160     }
161     flavorHist[(i-6)*N+k]->SetLineColor(color[k]);
162     flavorHist[(i-6)*N+k]->SetMarkerStyle(20);
163     flavorHist[(i-6)*N+k]->SetMarkerColor(color[k]);
164     flavorHist[(i-6)*N+k]->SetMarkerSize(1.4);
165     flavorHist[(i-6)*N+k]->SetStats(0);
166     flavorHist[(i-6)*N+k]->GetXaxis()->SetTitle((histoLabelX[i]).c_str());
167     flavorHist[(i-6)*N+k]->GetYaxis()->SetTitle("Entries");
168     flavorHist[(i-6)*N+k]->SetTitle("");
169     }
170     TCanvas *canvas4 = new TCanvas(histoType[i].c_str(), "");
171     flavorHist[(i-6)*N+5]->Draw("hist e0");
172     for (int icomb=0; icomb != N; icomb++) {
173     if (icomb==5) continue;
174     flavorHist[(i-6)*N+icomb]->Draw("same hist e0");
175     }
176     TLegend *legend4 = new TLegend(0.7, 0.3, 0.9, 0.85);
177     for (int icomb=0; icomb < N; icomb++) legend4->AddEntry(flavorHist[(i-6)*N+icomb],combDataType[icomb].c_str());
178     legend4->Draw();
179     legend4->SetFillColor(kWhite);
180     latex->DrawLatex(0.22,0.91,histoType[i].c_str());
181     //canvas4->SetLogy();
182     string nameCanvas4 = histoType[i]+".eps";
183     canvas4->SaveAs(nameCanvas4.c_str());
184     }
185    
186     }
187     }
188    
189    
190    
191    
192