ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/plotH4l.cc
Revision: 1.7
Committed: Tue Feb 5 09:30:02 2013 UTC (12 years, 3 months ago) by dkralph
Content type: text/plain
Branch: MAIN
CVS Tags: HEAD
Changes since 1.6: +11 -212 lines
Log Message:
*** empty log message ***

File Contents

# Content
1 #include <iostream>
2 #include <algorithm>
3 #include <iomanip>
4
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 "../../"
28 #endif
29
30 using namespace std;
31 using namespace RooFit;
32 using namespace mithep;
33
34 TCanvas *can;
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 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 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");
67 SimpleTable xstab(xspath.c_str());
68
69 vector<CSample*> samplev;
70 TString ntupledir(""),label(""),plotLabel(""),jsonFile("");
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;
76 for(unsigned ics=0; ics<samplev.size(); ics++) {
77 CSample *cs = samplev[ics];
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_ << " " << 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 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 }
103
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( " << setw(12) << total << " ) skipped " << nDuplSkipped << " duplicate events" << endl;
156 }
157 }
158 cout << "run range: " << setw(12) << minRun << setw(12) << maxRun << endl;
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",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(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,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,"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)
211 {
212 map<TString,map<TString,TH1D*>* > hists;
213 map<TString,TH1D*> *h_4e = new map<TString,TH1D*>; hists["4e"] = h_4e;
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,TH1D*> *h_vbf = new map<TString,TH1D*>; hists["vbf"] = h_vbf;
218
219 allocate_hists(hists,str);
220 return hists;
221 }