5 |
|
#include "TCanvas.h" |
6 |
|
#include "TChain.h" |
7 |
|
#include "TString.h" |
8 |
+ |
#include "Various.h" |
9 |
|
#include "TStyle.h" |
10 |
+ |
#include "TRandom.h" |
11 |
|
#include "TH1D.h" |
12 |
|
|
13 |
|
#include "Various.h" |
14 |
+ |
#include "RunLumiRangeMap.h" |
15 |
|
|
16 |
|
#include "CPlot.h" |
17 |
|
#include "FOArgs.h" |
18 |
+ |
#include "varkeepter.h" |
19 |
|
#include "SampleWeight.h" |
20 |
+ |
#include "SelectionFuncs.h" |
21 |
|
#include "PlotHeaders.h" |
22 |
+ |
#include "HistHeaders.h" |
23 |
+ |
#include "MitStyleRemix.h" |
24 |
+ |
#include "BdtIface.h" |
25 |
|
|
26 |
|
#ifndef CMSSW_BASE |
27 |
|
#define CMSSW_BASE "../../" |
32 |
|
using namespace mithep; |
33 |
|
|
34 |
|
TCanvas *can; |
35 |
< |
|
36 |
< |
void makeHTML(FOFlags &ctrl, TString plotLabel); |
35 |
> |
MitHzz4lPublic::BdtIface *bdti; |
36 |
> |
//---------------------------------------------------------------------------------------- |
37 |
> |
TString entry_str(TH1D *hist, bool dummyStr=false) |
38 |
> |
{ |
39 |
> |
if(dummyStr) return ""; |
40 |
> |
stringstream ss; |
41 |
> |
ss << hist->GetEntries(); |
42 |
> |
TString str; |
43 |
> |
ss >> str; |
44 |
> |
return str; |
45 |
> |
} |
46 |
> |
//---------------------------------------------------------------------------------------- |
47 |
> |
// void makeHTML(FOFlags &ctrl, TString plotLabel); |
48 |
|
map<TString,map<TString,TH1D*>* > init_hists(FOFlags &ctrl, TString str=""); |
49 |
|
|
50 |
|
//---------------------------------------------------------------------------------------- |
51 |
|
int main(int argc, char** argv) |
52 |
|
{ |
53 |
< |
double lumi = 5000;//10093;//5000+2600; |
54 |
< |
|
53 |
> |
SetStyle(); |
54 |
> |
bool dummyStr(true); // don't add the yield numbers to legends |
55 |
|
FOFlags ctrl; |
56 |
|
parse_foargs( argc, argv, ctrl ); |
57 |
|
ctrl.dump(); |
58 |
|
|
59 |
< |
can = new TCanvas("can","can"); |
59 |
> |
varkeepter vk("Selection/data/passVars.txt","w","pass.root",0,"zznt"); |
60 |
> |
bool writeFlatTuple(ctrl.makeFakeTuples); |
61 |
> |
|
62 |
> |
can = new TCanvas("can","can",700,500); |
63 |
> |
bdti = new MitHzz4lPublic::BdtIface(); |
64 |
|
|
65 |
|
TString cmsswpath(CMSSW_BASE + TString("/src")); |
66 |
|
string xspath = (string(cmsswpath)+"/MitPhysics/data/xs.dat"); |
68 |
|
|
69 |
|
vector<CSample*> samplev; |
70 |
|
TString ntupledir(""),label(""),plotLabel(""),jsonFile(""); |
71 |
< |
readConfigFile(ctrl.config, ntupledir, label, plotLabel, jsonFile, samplev, &ctrl, init_hists); |
71 |
> |
int puTarget; |
72 |
> |
readConfigFile(ctrl.config, ntupledir, label, plotLabel, jsonFile, puTarget, samplev, &ctrl, init_hists); |
73 |
|
|
74 |
|
vector<pair<unsigned,unsigned> > runEvtv; // vector to veto duplicate events |
75 |
|
UInt_t minRun=999999999,maxRun=0; |
78 |
|
cout << cs->name << endl; |
79 |
|
for(unsigned ifs=0; ifs<(cs->fsv).size(); ifs++) { |
80 |
|
filestuff *fs = (cs->fsv)[ifs]; |
81 |
< |
cout << "\t" << fs->fname_ << endl; |
81 |
> |
cout << "\t" << fs->fname_ << " " << fs->getentries("zznt"); cout << flush; |
82 |
|
unsigned nDuplSkipped=0; |
83 |
+ |
double total=0; |
84 |
+ |
|
85 |
|
for(unsigned ientry=0; ientry<fs->getentries("zznt"); ientry++) { |
86 |
+ |
// if(ientry>1500) { cout << "SKIPPING AFTER 1500\n"; break;} |
87 |
|
fs->getentry(ientry,"info","zznt"); |
88 |
|
fs->getentry(ientry,"kinematics","zznt"); |
89 |
< |
|
90 |
< |
if(fs->isdata_) { |
89 |
> |
fs->getentry(ientry,"weights","zznt"); |
90 |
> |
fs->getentry(ientry,"angles","zznt"); |
91 |
> |
fs->getentry(ientry,"","zznt"); |
92 |
> |
if(fs->get_zz_chain()->GetBranchStatus("jetinfo")) |
93 |
> |
fs->getentry(ientry,"jetinfo","zznt"); |
94 |
> |
|
95 |
> |
if(fs->isdata_ && !(fs->dataset_.Contains("fakes"))) { |
96 |
> |
if(!fs->rlrm_.HasRunLumi(pair<unsigned,unsigned> (fs->info->run, fs->info->lumi))) { |
97 |
> |
continue; |
98 |
> |
} |
99 |
|
setMinMaxRun(fs->info->run, minRun, maxRun); |
100 |
|
bool dupl = takeCareOfDuplicateEvents(fs->info->run, fs->info->evt, runEvtv, nDuplSkipped); |
101 |
|
if(dupl) continue; |
102 |
|
} |
68 |
– |
|
69 |
– |
double wgt = fs->isdata_ ? 1 : lumi*xstab.Get(fs->dataset_)/fs->total_entries_; |
103 |
|
|
104 |
< |
(*(cs->hists)["all"])["run"]->Fill( fs->info->run , wgt); |
105 |
< |
(*(cs->hists)["all"])["mZ1"]->Fill( fs->kine->mZ1 , wgt); |
106 |
< |
(*(cs->hists)["all"])["m4l"]->Fill( fs->kine->m4l , wgt); |
107 |
< |
(*(cs->hists)["all"])["m4l_lo"]->Fill( fs->kine->m4l , wgt); |
108 |
< |
(*(cs->hists)["all"])["Z1pt"]->Fill( fs->kine->Z1pt , wgt); |
109 |
< |
(*(cs->hists)["all"])["ZZpt"]->Fill( fs->kine->ZZpt , wgt); |
110 |
< |
|
104 |
> |
// calculate weights here: |
105 |
> |
// double wgt = fs->isdata_ ? 1 : fs->lumi_*xstab.Get(fs->dataset_)/fs->total_entries_; |
106 |
> |
// cout << "setting wgt to: " << wgt << " = " << fs->lumi_ << "*" << xstab.Get(fs->dataset_) << "/" << fs->total_entries_ << endl; |
107 |
> |
|
108 |
> |
double wgt(1); |
109 |
> |
if(!fs->isdata_) { |
110 |
> |
if(fs->dataset_.Contains("fakes")) { |
111 |
> |
} else { |
112 |
> |
if(fs->weights->npuw < 0 || fs->weights->npuw > 2) cout << "wtf? " << fs->weights->npuw << endl; |
113 |
> |
wgt = fs->lumi_ * fs->weights->w;// * fs->weights->npuw * fs->weights->woff * fs->weights->won; |
114 |
> |
if(fs->dataset_.Contains("-dkr")) wgt = 1; |
115 |
> |
} |
116 |
> |
} |
117 |
> |
|
118 |
> |
if(fs->dataset_.Contains("fakes")) { |
119 |
> |
fs->getentry(ientry,"weights","zznt"); |
120 |
> |
wgt = 2*fs->weights->w; |
121 |
> |
} |
122 |
> |
|
123 |
> |
// if(fs->kine->m4l < 100) continue; |
124 |
> |
// impose blinded region |
125 |
> |
// if(fs->isdata_ && !fs->dataset_.Contains("fakes")) { |
126 |
> |
// if(fs->kine->m4l > 110 && fs->kine->m4l < 140) continue; |
127 |
> |
// if(fs->kine->m4l > 300) continue; |
128 |
> |
// } |
129 |
> |
|
130 |
> |
// run = fs->info->run; |
131 |
> |
// evt = fs->info->evt; |
132 |
> |
// m4lbrvar = fs->kine->m4l; |
133 |
> |
// channel = fs->kine->channel; |
134 |
> |
if(writeFlatTuple) { |
135 |
> |
vk.setval("run",fs->info->run); |
136 |
> |
vk.setval("evt",fs->info->evt); |
137 |
> |
vk.setval("channel",fs->kine->channel); |
138 |
> |
vk.setval("m4l",fs->kine->m4l); |
139 |
> |
vk.setval("mZ1",fs->kine->mZ1); |
140 |
> |
vk.setval("mZ2",fs->kine->mZ2); |
141 |
> |
vk.setval("l1pt",fs->kine->l1pt); |
142 |
> |
vk.setval("l2pt",fs->kine->l2pt); |
143 |
> |
vk.setval("l3pt",fs->kine->l3pt); |
144 |
> |
vk.setval("l4pt",fs->kine->l4pt); |
145 |
> |
vk.fill(); |
146 |
> |
} |
147 |
> |
total += wgt; |
148 |
> |
|
149 |
> |
if(fs->kine->m4l > 105 && fs->kine->m4l < 140) { |
150 |
> |
fillAllHists( ctrl, cs, getChannel(fs->kine->channel), "", fs, *(fs->kine), *(fs->angles), wgt, 0, 0, bdti); |
151 |
> |
fillAllJetHists( ctrl, cs, getChannel(fs->kine->channel), "", fs, *(fs->kine), /*fusion,*/ /*goodJets,*/ *(fs->ji), wgt); |
152 |
> |
} |
153 |
> |
|
154 |
|
} |
155 |
< |
cout << "\t\tWARNING: skipped " << nDuplSkipped << " duplicate events" << endl; |
155 |
> |
cout << "\t( " << setw(12) << total << " ) skipped " << nDuplSkipped << " duplicate events" << endl; |
156 |
|
} |
157 |
|
} |
158 |
|
cout << "run range: " << setw(12) << minRun << setw(12) << maxRun << endl; |
159 |
< |
gSystem->mkdir(ctrl.outdir+"/"+plotLabel,true); |
159 |
> |
TString type("all"); |
160 |
> |
TString fullOutDir(ctrl.outdir+"/"+plotLabel+"/"+type); |
161 |
> |
gSystem->mkdir(fullOutDir,true); |
162 |
|
TFile runHistFile(ctrl.outdir+"/"+plotLabel+"/runs.root","recreate"); |
163 |
|
assert(samplev.size() > 0); |
164 |
+ |
bool plotShapesOnly=ctrl.plotWholeSample; |
165 |
|
map<TString,TH1D*>::iterator it_v; |
166 |
|
for(it_v=(*(samplev[0]->hists)["all"]).begin(); it_v!=(*(samplev[0]->hists)["all"]).end(); it_v++) { |
167 |
|
TString var((*it_v).first); |
168 |
< |
CPlot cplot(var,"",(*(samplev[0]->hists)["all"])[var]->GetXaxis()->GetTitle(),"events",ctrl.outdir+"/"+plotLabel+"/plots"); |
168 |
> |
CPlot cplot(var,"",(*(samplev[0]->hists)["all"])[var]->GetXaxis()->GetTitle(),"events",TString(fullOutDir+"/plots")); |
169 |
> |
double ymax=0; |
170 |
|
for(unsigned isam=0; isam<samplev.size(); isam++) { |
171 |
|
CSample *cs = samplev[isam]; |
172 |
|
TH1D *hist = (*(cs->hists)["all"])[var]; |
173 |
< |
if(cs->isdata) { |
174 |
< |
cplot.AddHist1D(hist,cs->legend+": "+integral_str(hist),"E",cs->color); |
173 |
> |
if(plotShapesOnly) hist->Scale(1./hist->Integral()); |
174 |
> |
// if(!var.Contains("Zdot") && !var.Contains("_zoom") && !(var=="pt4l") && !(var=="Z1pt") && !(var=="Z2pt") && !(var=="mZ2"))) shiftOverflows(hist); |
175 |
> |
if(var.Contains("run") || var.Contains("npu") || var=="mZ1" || var=="mZ2" || var.Contains("pt_j")) shiftOverflows(hist); |
176 |
> |
ymax = max(ymax,hist->GetMaximum()); |
177 |
> |
if(plotShapesOnly || (cs->isdata && !(cs->name.Contains("fakes")))) { |
178 |
> |
TString tmpstr = plotShapesOnly ? entry_str(hist,dummyStr) : integral_str(hist,1,dummyStr); |
179 |
> |
cplot.AddHist1D(hist,cs->legend+": "+tmpstr,plotShapesOnly ? TString("hist") : TString("E"),cs->color); |
180 |
|
} else { |
181 |
< |
cplot.AddToStack(hist,cs->legend+": "+integral_str(hist),kCyan-6); |
97 |
< |
// cplot.AddToStack((*(cs_zj->hists)["all"])[var],"ZJ: "+integral_str((*(cs_zj->hists)["all"])[var]),843); |
181 |
> |
cplot.AddToStack(hist,cs->legend+": "+integral_str(hist,4,dummyStr),cs->color); |
182 |
|
} |
183 |
|
if(cs->isdata && var=="run") { |
184 |
|
assert(hist->GetBinContent(0)==0 && hist->GetBinContent(hist->GetXaxis()->GetNbins()+1)==0); |
185 |
|
hist->Write(); |
186 |
|
} |
187 |
|
} |
188 |
+ |
if(var=="mZ1" || var=="m4l_lo") cplot.TransLegend(-.4,0); |
189 |
+ |
if(var=="w" || var.Contains("_log")) |
190 |
+ |
cplot.SetLogy(); |
191 |
+ |
else { |
192 |
+ |
cplot.SetLogy(false); |
193 |
+ |
double factor(1.2); |
194 |
+ |
if(var=="m4l_lo") factor = 1.5; |
195 |
+ |
cplot.SetYRange(0,factor*ymax); |
196 |
+ |
} |
197 |
+ |
TString txt("#bf{CMS Preliminary L = 5 ( + 20 ) fb^{-1} at #sqrt{s} = 7 ( + 8 ) TeV}"); // #sqrt{s} = 7 TeV, L = 5 fb^{-1}; #sqrt{s} = 8 TeV, L = 12 fb^{-1}"); |
198 |
+ |
cplot.AddTextBox(txt,0.16,0.95,0.85,0.99,0); |
199 |
|
cplot.Draw(can,true,"png"); |
200 |
|
} |
201 |
|
runHistFile.Close(); |
202 |
|
|
203 |
< |
makeHTML(ctrl,plotLabel); |
203 |
> |
makeHTML(ctrl,"XXX",plotLabel,fullOutDir); |
204 |
> |
if(writeFlatTuple) { |
205 |
> |
vk.writeclose(); |
206 |
> |
} |
207 |
> |
assert(string("ROOT SUCKS") == string("FALSE")); |
208 |
|
} |
209 |
|
//---------------------------------------------------------------------------------------- |
210 |
|
map<TString,map<TString,TH1D*>* > init_hists(FOFlags &ctrl, TString str) |
214 |
|
map<TString,TH1D*> *h_4m = new map<TString,TH1D*>; hists["4m"] = h_4m; |
215 |
|
map<TString,TH1D*> *h_2e2m = new map<TString,TH1D*>; hists["2e2m"] = h_2e2m; |
216 |
|
map<TString,TH1D*> *h_all = new map<TString,TH1D*>; hists["all"] = h_all; |
217 |
< |
map<TString,map<TString,TH1D*>* >::iterator it_h; |
218 |
< |
for(it_h=hists.begin(); it_h!=hists.end(); it_h++) { |
219 |
< |
(*((*it_h).second))["run"] = new TH1D(TString("run") +"_"+(*it_h).first+str,";#bf{run};", 50,163330,196455); (*((*it_h).second))["run"]->Sumw2(); |
121 |
< |
(*((*it_h).second))["mZ1"] = new TH1D(TString("mZ1") +"_"+(*it_h).first+str,";#bf{mZ1 [GeV]};", 20,75,105); (*((*it_h).second))["mZ1"]->Sumw2(); |
122 |
< |
(*((*it_h).second))["m4l"] = new TH1D(TString("m4l") +"_"+(*it_h).first+str,";#bf{m4l [GeV]};", 40,50,500); (*((*it_h).second))["m4l"]->Sumw2(); |
123 |
< |
(*((*it_h).second))["m4l_lo"] = new TH1D(TString("m4l_lo") +"_"+(*it_h).first+str,";#bf{m4l [GeV]};", 40,100,170); (*((*it_h).second))["m4l_lo"]->Sumw2(); |
124 |
< |
(*((*it_h).second))["Z1pt"] = new TH1D(TString("Z1pt") +"_"+(*it_h).first+str,";#bf{Z1pt [GeV]};", 20,0,200); (*((*it_h).second))["Z1pt"]->Sumw2(); |
125 |
< |
(*((*it_h).second))["ZZpt"] = new TH1D(TString("ZZpt") +"_"+(*it_h).first+str,";#bf{ZZpt [GeV]};", 30,0,200); (*((*it_h).second))["ZZpt"]->Sumw2(); |
126 |
< |
} |
127 |
< |
|
217 |
> |
map<TString,TH1D*> *h_vbf = new map<TString,TH1D*>; hists["vbf"] = h_vbf; |
218 |
> |
|
219 |
> |
allocate_hists(hists,str); |
220 |
|
return hists; |
221 |
|
} |
130 |
– |
//-------------------------------------------------------------------------------------------------- |
131 |
– |
void makeHTML(FOFlags &ctrl, TString plotLabel) |
132 |
– |
{ |
133 |
– |
// TString title(ctrl.inputdir); |
134 |
– |
// title = title(title.Last('/')+1,title.Length()); |
135 |
– |
TString title("Full selection: "+plotLabel); |
136 |
– |
TString htmlfname(ctrl.outdir+"/"+plotLabel+"/plots.html"); |
137 |
– |
ofstream htmlfile(htmlfname); |
138 |
– |
|
139 |
– |
htmlfile << "<!DOCTYPE html" << endl; |
140 |
– |
htmlfile << " PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" << endl; |
141 |
– |
htmlfile << "<html>" << endl; |
142 |
– |
|
143 |
– |
htmlfile << "<head><title>"+title+"</title></head>" << endl; |
144 |
– |
htmlfile << "<body bgcolor=\"EEEEEE\">" << endl; |
145 |
– |
htmlfile << "<h3 style=\"text-align:left; color:DD6600;\">"+title+"</h3>" << endl; |
146 |
– |
|
147 |
– |
htmlfile << "<table border=\"0\" cellspacing=\"5\" width=\"100%\">" << endl; |
148 |
– |
|
149 |
– |
htmlfile << "<tr>" << endl; |
150 |
– |
htmlfile << "<td width=\"25%\"><a target=\"_blank\" href=\"plots/mZ1.png\"><img src=\"plots/mZ1.png\" alt=\"plots/mZ1.png\" width=\"100%\"></a></td>" << endl; |
151 |
– |
htmlfile << "<td width=\"25%\"><a target=\"_blank\" href=\"plots/Z1pt.png\"><img src=\"plots/Z1pt.png\" alt=\"plots/Z1pt.png\" width=\"100%\"></a></td>" << endl; |
152 |
– |
htmlfile << "<td width=\"25%\"><a target=\"_blank\" href=\"plots/ZZpt.png\"><img src=\"plots/ZZpt.png\" alt=\"plots/ZZpt.png\" width=\"100%\"></a></td>" << endl; |
153 |
– |
htmlfile << "<td width=\"25%\"><a target=\"_blank\" href=\"plots/m4l.png\"><img src=\"plots/m4l.png\" alt=\"plots/m4l.png\" width=\"100%\"></a></td>" << endl; |
154 |
– |
// htmlfile << "<td width=\"25%\"><a></a></td>" << endl; |
155 |
– |
htmlfile << "</tr>" << endl; |
156 |
– |
|
157 |
– |
htmlfile << "<tr>" << endl; |
158 |
– |
htmlfile << "<td width=\"25%\"><a target=\"_blank\" href=\"plots/m4l_lo.png\"><img src=\"plots/m4l_lo.png\" alt=\"plots/m4l_lo.png\" width=\"100%\"></a></td>" << endl; |
159 |
– |
htmlfile << "<td width=\"25%\"><a target=\"_blank\" href=\"plots/run.png\"><img src=\"plots/run.png\" alt=\"plots/run.png\" width=\"100%\"></a></td>" << endl; |
160 |
– |
htmlfile << "<td width=\"25%\"><a></a></td>" << endl; |
161 |
– |
htmlfile << "<td width=\"25%\"><a></a></td>" << endl; |
162 |
– |
htmlfile << "</tr>" << endl; |
163 |
– |
|
164 |
– |
htmlfile << "</table>" << endl; |
165 |
– |
|
166 |
– |
htmlfile << "<hr />" << endl; |
167 |
– |
|
168 |
– |
htmlfile << "<hr />" << endl; |
169 |
– |
|
170 |
– |
htmlfile << "</body>" << endl; |
171 |
– |
htmlfile << "</html>" << endl; |
172 |
– |
htmlfile.close(); |
173 |
– |
} |