1 |
////////////////////////////////////////////////////////////////////////////////
|
2 |
//
|
3 |
// plotvars_x
|
4 |
// ----------
|
5 |
//
|
6 |
// 06/14/2007 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
|
7 |
////////////////////////////////////////////////////////////////////////////////
|
8 |
|
9 |
|
10 |
#include "utils/cmdline.h"
|
11 |
|
12 |
#include <TROOT.h>
|
13 |
#include <TStyle.h>
|
14 |
#include <TRint.h>
|
15 |
#include <TFile.h>
|
16 |
#include <TTree.h>
|
17 |
#include <TEventList.h>
|
18 |
#include <TH1F.h>
|
19 |
#include <TCanvas.h>
|
20 |
#include <TLegend.h>
|
21 |
|
22 |
#include <iostream>
|
23 |
#include <iomanip>
|
24 |
#include <string>
|
25 |
#include <vector>
|
26 |
|
27 |
|
28 |
using namespace std;
|
29 |
|
30 |
|
31 |
////////////////////////////////////////////////////////////////////////////////
|
32 |
// main
|
33 |
////////////////////////////////////////////////////////////////////////////////
|
34 |
|
35 |
//______________________________________________________________________________
|
36 |
int main(int argc,char**argv)
|
37 |
{
|
38 |
cmdline cl;
|
39 |
cl.parse(argc,argv);
|
40 |
|
41 |
vector<string> input = cl.get_vector<string>("input");
|
42 |
string variable = cl.get_value<string> ("variable");
|
43 |
string selection = cl.get_value<string> ("selection","njt>0");
|
44 |
string treename = cl.get_value<string> ("treename", "t");
|
45 |
bool logy = cl.get_value<bool> ("logy", true);
|
46 |
bool overlay = cl.get_value<bool> ("overlay", true);
|
47 |
|
48 |
if (!cl.check()) return 0;
|
49 |
cl.print();
|
50 |
|
51 |
|
52 |
// concider event weights via selection
|
53 |
selection = "weight*(" + selection + ")";
|
54 |
|
55 |
// jetalgs
|
56 |
vector<string> jetalgs;
|
57 |
for (vector<string>::const_iterator it=input.begin();it!=input.end();++it) {
|
58 |
string jetalg = *it;
|
59 |
string::size_type pos;
|
60 |
while ((pos=jetalg.find('/'))!=string::npos) jetalg = jetalg.substr(pos+1);
|
61 |
jetalg = jetalg.substr(0,jetalg.find(".root"));
|
62 |
jetalgs.push_back(jetalg);
|
63 |
}
|
64 |
|
65 |
argc=1;
|
66 |
TRint* app = new TRint(argv[0],&argc,argv);
|
67 |
|
68 |
// samples
|
69 |
vector<TTree*> samples;
|
70 |
for (unsigned int i=0;i<input.size();++i) {
|
71 |
TFile* f = new TFile(input[i].c_str(),"READ");
|
72 |
TTree* t = (TTree*)f->Get(treename.c_str());
|
73 |
|
74 |
samples.push_back(t);
|
75 |
cout<<jetalgs[i]<<" sample has "<<t->GetEntries()<<" total events."<<endl;
|
76 |
}
|
77 |
|
78 |
|
79 |
// histograms
|
80 |
vector<TH1F*> histograms;
|
81 |
|
82 |
for (unsigned int isample=0;isample<samples.size();++isample) {
|
83 |
string jetalg = jetalgs[isample];
|
84 |
TTree* sample = samples[isample];
|
85 |
|
86 |
TEventList* el = new TEventList("elist","elist");
|
87 |
sample->Draw(">>elist",selection.c_str());
|
88 |
int nevts = el->GetN();
|
89 |
|
90 |
char njt;
|
91 |
float weight;
|
92 |
float jtet[100];
|
93 |
float jteta[100];
|
94 |
float jtphi[100];
|
95 |
float jtgendr[100];
|
96 |
float jtgenet[100];
|
97 |
|
98 |
float* values(0);
|
99 |
if (variable=="jtet") values = jtet;
|
100 |
if (variable=="jteta") values = jteta;
|
101 |
if (variable=="jtphi") values = jtphi;
|
102 |
if (variable=="jtgendr") values = jtgendr;
|
103 |
if (variable=="jtgenet") values = jtgenet;
|
104 |
|
105 |
sample->SetBranchAddress("njt", &njt);
|
106 |
sample->SetBranchAddress("weight",&weight);
|
107 |
sample->SetBranchAddress("jtet", jtet);
|
108 |
sample->SetBranchAddress("jteta", jteta);
|
109 |
sample->SetBranchAddress("jtphi", jtphi);
|
110 |
sample->SetBranchAddress("jtgendr",jtgendr);
|
111 |
sample->SetBranchAddress("jtgenet",jtgenet);
|
112 |
|
113 |
|
114 |
gROOT->cd();
|
115 |
float value;
|
116 |
string treename = "t" + variable;
|
117 |
TTree* tree = new TTree(treename.c_str(),treename.c_str());
|
118 |
tree->Branch("value", &value, "value/F");
|
119 |
tree->Branch("weight",&weight,"value/F");
|
120 |
|
121 |
for (int ievt=0;ievt<nevts;ievt++) {
|
122 |
|
123 |
sample->GetEntry(el->GetEntry(ievt));
|
124 |
|
125 |
for (int ijt=0;ijt<njt;ijt++) {
|
126 |
|
127 |
// Section Cuts
|
128 |
if (jtgendr[ijt]<0.0||jtgendr[ijt]>0.3) continue;
|
129 |
|
130 |
// fill 'value' tree for selected events
|
131 |
value = values[ijt];
|
132 |
tree->Fill();
|
133 |
}
|
134 |
}
|
135 |
|
136 |
TH1F::SetDefaultSumw2();
|
137 |
tree->Draw("value","weight*(1)","goff");
|
138 |
TH1F* h = (TH1F*)gROOT->FindObject("htemp");
|
139 |
cout<<jetalg<<": "<<h->GetEntries()<<" jets selected."<<endl;
|
140 |
string hname = "h"+variable+"_"+jetalg;
|
141 |
string::size_type pos;
|
142 |
while ((pos=hname.find('['))<string::npos) hname.erase(pos,1);
|
143 |
while ((pos=hname.find(']'))<string::npos) hname.erase(pos,1);
|
144 |
h->SetNameTitle(hname.c_str(),hname.c_str());
|
145 |
h->SetXTitle(variable.c_str());
|
146 |
histograms.push_back(h);
|
147 |
cout<<hname<<" finished."<<endl;
|
148 |
|
149 |
delete tree;
|
150 |
delete el;
|
151 |
}
|
152 |
|
153 |
|
154 |
// make plots
|
155 |
if (overlay) gStyle->SetOptStat(0);
|
156 |
|
157 |
TLegend* leg(0);
|
158 |
|
159 |
if (overlay) {
|
160 |
string cname = "c"+variable;
|
161 |
TCanvas* c = new TCanvas(cname.c_str(),cname.c_str());
|
162 |
c->SetLogy(logy);
|
163 |
leg = new TLegend(0.6,0.85-jetalgs.size()*0.06,0.85,0.85);
|
164 |
leg->SetFillColor(10);
|
165 |
}
|
166 |
|
167 |
Color_t color = kBlack;
|
168 |
|
169 |
for (unsigned int ialg=0;ialg<jetalgs.size();++ialg) {
|
170 |
string jetalg = jetalgs[ialg];
|
171 |
TH1F* h = histograms[ialg];
|
172 |
h->SetLineWidth(2);
|
173 |
if (!overlay) {
|
174 |
string cname = "c"+variable+"_"+jetalg;
|
175 |
TCanvas* c = new TCanvas(cname.c_str(),cname.c_str());
|
176 |
c->SetLogy(logy);
|
177 |
}
|
178 |
else {
|
179 |
h->SetTitle(variable.c_str());
|
180 |
h->SetLineColor(color);
|
181 |
}
|
182 |
|
183 |
(ialg==0||!overlay) ? h->Draw("EHIST") : h->Draw("EHISTSAME");
|
184 |
|
185 |
if (leg!=0) {
|
186 |
leg->AddEntry(h,jetalg.c_str(),"l");
|
187 |
if (ialg==jetalgs.size()-1) leg->Draw();
|
188 |
}
|
189 |
|
190 |
color++;
|
191 |
while (color==10||color==kWhite||color==kYellow) color++;
|
192 |
}
|
193 |
|
194 |
app->Run();
|
195 |
|
196 |
return 0;
|
197 |
}
|