1 |
dkralph |
1.1 |
#include <iostream>
|
2 |
|
|
#include <algorithm>
|
3 |
|
|
#include <iomanip>
|
4 |
|
|
|
5 |
|
|
#include "TCanvas.h"
|
6 |
|
|
#include "TChain.h"
|
7 |
|
|
#include "TString.h"
|
8 |
|
|
#include "TStyle.h"
|
9 |
|
|
#include "TH1D.h"
|
10 |
|
|
|
11 |
|
|
#include "Various.h"
|
12 |
|
|
|
13 |
|
|
#include "CPlot.h"
|
14 |
|
|
#include "FOArgs.h"
|
15 |
|
|
#include "SampleWeight.h"
|
16 |
|
|
|
17 |
|
|
#ifndef CMSSW_BASE
|
18 |
|
|
#define CMSSW_BASE "../../"
|
19 |
|
|
#endif
|
20 |
|
|
|
21 |
|
|
using namespace std;
|
22 |
|
|
using namespace RooFit;
|
23 |
|
|
|
24 |
|
|
TCanvas *can;
|
25 |
|
|
|
26 |
|
|
void makeHTML(FOFlags &ctrl);
|
27 |
|
|
map<TString,map<TString,TH1D*>* > init_hists(FOFlags &ctrl, TString str="");
|
28 |
|
|
|
29 |
|
|
//----------------------------------------------------------------------------------------
|
30 |
|
|
int main(int argc, char** argv)
|
31 |
|
|
{
|
32 |
|
|
double lumi = 5000;//5000+2600;
|
33 |
|
|
UInt_t minRun=999999999,maxRun=0;
|
34 |
|
|
|
35 |
|
|
FOFlags ctrl;
|
36 |
|
|
parse_foargs( argc, argv, ctrl );
|
37 |
|
|
ctrl.dump();
|
38 |
|
|
|
39 |
|
|
can = new TCanvas("can","can");
|
40 |
|
|
|
41 |
|
|
TString cmsswpath(CMSSW_BASE + TString("/src"));
|
42 |
|
|
string xspath = (string(cmsswpath)+"/MitPhysics/data/xs.dat");
|
43 |
|
|
SimpleTable xstab(xspath.c_str());
|
44 |
|
|
|
45 |
|
|
vector<CSample*> samplev;
|
46 |
|
|
|
47 |
|
|
ifstream instream;
|
48 |
|
|
instream.open(ctrl.config); assert(instream.is_open());
|
49 |
|
|
TString ntupledir;
|
50 |
|
|
string line;
|
51 |
|
|
while(getline(instream,line)) {
|
52 |
|
|
if(line[0]=='#') continue;
|
53 |
|
|
|
54 |
|
|
stringstream ss(line);
|
55 |
|
|
if(line[0]=='^') {
|
56 |
|
|
TString dummy;
|
57 |
|
|
if(TString(line).Contains("^ntupdir")) ss >> dummy >> ntupledir;
|
58 |
|
|
// if(TString(line).Contains("^skim")) ss >> dummy >> ntupledir;
|
59 |
|
|
continue;
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
if(line[0]=='$') {
|
63 |
|
|
samplev.push_back(new CSample());
|
64 |
|
|
stringstream ss(line);
|
65 |
|
|
string chr;
|
66 |
|
|
TString sname;
|
67 |
|
|
Int_t color;
|
68 |
|
|
ss >> chr >> sname >> color;
|
69 |
|
|
string legend = line.substr(line.find('@')+1);
|
70 |
|
|
cout << sname << endl;
|
71 |
|
|
samplev.back()->name = sname;
|
72 |
|
|
samplev.back()->legend = legend;
|
73 |
|
|
samplev.back()->color = color;
|
74 |
|
|
samplev.back()->hists = init_hists(ctrl,sname);
|
75 |
|
|
continue;
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
TString dset,book,skimmed;
|
79 |
|
|
bool isdata;
|
80 |
|
|
double xsec;
|
81 |
|
|
ss >> dset >> isdata >> xsec >> book >> skimmed;
|
82 |
|
|
assert(ctrl.muSele==ctrl.eleSele);
|
83 |
|
|
assert(skimmed=="skimmed" || skimmed=="unskimmed");
|
84 |
|
|
TString fname = ntupledir+"/"+ctrl.muSele+"/"+dset+(skimmed=="unskimmed" ? "/"+skimmed : "")+"/merged.root";
|
85 |
|
|
cout << "\tadding: " << fname << endl;
|
86 |
|
|
samplev.back()->isdata = isdata;
|
87 |
|
|
(samplev.back()->fsv).push_back(new filestuff(dset,fname,dset,isdata));
|
88 |
|
|
}
|
89 |
|
|
instream.close();
|
90 |
|
|
|
91 |
|
|
vector<pair<unsigned,unsigned> > runEvtv; // vector to veto duplicate events
|
92 |
|
|
for(unsigned ics=0; ics<samplev.size(); ics++) {
|
93 |
|
|
CSample *cs = samplev[ics];
|
94 |
|
|
|
95 |
|
|
for(unsigned ifs=0; ifs<(cs->fsv).size(); ifs++) {
|
96 |
|
|
|
97 |
|
|
filestuff *fs = (cs->fsv)[ifs];
|
98 |
|
|
for(unsigned ientry=0; ientry<fs->getentries("zznt"); ientry++) {
|
99 |
|
|
fs->getentry(ientry,"info","zznt");
|
100 |
|
|
fs->getentry(ientry,"kinematics","zznt");
|
101 |
|
|
if(fs->isdata_) {
|
102 |
|
|
if(fs->info->run < minRun) minRun = fs->info->run;
|
103 |
|
|
if(fs->info->run > maxRun) maxRun = fs->info->run;
|
104 |
|
|
}
|
105 |
|
|
bool dupl=false;
|
106 |
|
|
for(unsigned ievt=0; ievt<runEvtv.size(); ievt++) {
|
107 |
|
|
if( (runEvtv[ievt].first == fs->info->run) && (runEvtv[ievt].second == fs->info->evt) ) {
|
108 |
|
|
cout << "found duplicate event!" << setw(12) << fs->info->run << setw(12) << fs->info->evt << endl;
|
109 |
|
|
dupl = true;
|
110 |
|
|
}
|
111 |
|
|
}
|
112 |
|
|
if(dupl) continue;
|
113 |
|
|
runEvtv.push_back(pair<unsigned,unsigned> (fs->info->run,fs->info->evt));
|
114 |
|
|
|
115 |
|
|
double wgt = fs->isdata_ ? 1 : lumi*xstab.Get(fs->dataset_)/fs->total_entries_;
|
116 |
|
|
|
117 |
|
|
(*(cs->hists)["all"])["run"]->Fill( fs->info->run , wgt);
|
118 |
|
|
(*(cs->hists)["all"])["mZ1"]->Fill( fs->kine->mZ1 , wgt);
|
119 |
|
|
(*(cs->hists)["all"])["m4l"]->Fill( fs->kine->m4l , wgt);
|
120 |
|
|
(*(cs->hists)["all"])["m4l_lo"]->Fill( fs->kine->m4l , wgt);
|
121 |
|
|
(*(cs->hists)["all"])["Z1pt"]->Fill( fs->kine->Z1pt , wgt);
|
122 |
|
|
(*(cs->hists)["all"])["ZZpt"]->Fill( fs->kine->ZZpt , wgt);
|
123 |
|
|
|
124 |
|
|
}
|
125 |
|
|
}
|
126 |
|
|
}
|
127 |
|
|
cout << setw(12) << minRun << setw(12) << maxRun << endl;
|
128 |
|
|
TFile runHistFile(ctrl.outdir+"/runs.root","recreate");
|
129 |
|
|
assert(samplev.size() > 0);
|
130 |
|
|
map<TString,TH1D*>::iterator it_v;
|
131 |
|
|
for(it_v=(*(samplev[0]->hists)["all"]).begin(); it_v!=(*(samplev[0]->hists)["all"]).end(); it_v++) {
|
132 |
|
|
TString var((*it_v).first);
|
133 |
|
|
CPlot cplot(var,"",(*(samplev[0]->hists)["all"])[var]->GetXaxis()->GetTitle(),"events",ctrl.outdir+"/plots");
|
134 |
|
|
for(unsigned isam=0; isam<samplev.size(); isam++) {
|
135 |
|
|
CSample *cs = samplev[isam];
|
136 |
|
|
TH1D *hist = (*(cs->hists)["all"])[var];
|
137 |
|
|
cplot.AddHist1D(hist,cs->legend+": "+integral_str(hist),"E",cs->color);
|
138 |
|
|
// cplot.AddToStack((*(cs_zz->hists)["all"])[var],"ZZ: "+integral_str((*(cs_zz->hists)["all"])[var]),kCyan-6);
|
139 |
|
|
// cplot.AddToStack((*(cs_zj->hists)["all"])[var],"ZJ: "+integral_str((*(cs_zj->hists)["all"])[var]),843);
|
140 |
|
|
if(cs->isdata && var=="run") {
|
141 |
|
|
assert(hist->GetBinContent(0)==0 && hist->GetBinContent(hist->GetXaxis()->GetNbins()+1)==0);
|
142 |
|
|
hist->Write();
|
143 |
|
|
}
|
144 |
|
|
}
|
145 |
|
|
cplot.Draw(can,true,"png");
|
146 |
|
|
}
|
147 |
|
|
runHistFile.Close();
|
148 |
|
|
|
149 |
|
|
makeHTML(ctrl);
|
150 |
|
|
}
|
151 |
|
|
//----------------------------------------------------------------------------------------
|
152 |
|
|
map<TString,map<TString,TH1D*>* > init_hists(FOFlags &ctrl, TString str)
|
153 |
|
|
{
|
154 |
|
|
map<TString,map<TString,TH1D*>* > hists;
|
155 |
|
|
map<TString,TH1D*> *h_4e = new map<TString,TH1D*>; hists["4e"] = h_4e;
|
156 |
|
|
map<TString,TH1D*> *h_4m = new map<TString,TH1D*>; hists["4m"] = h_4m;
|
157 |
|
|
map<TString,TH1D*> *h_2e2m = new map<TString,TH1D*>; hists["2e2m"] = h_2e2m;
|
158 |
|
|
map<TString,TH1D*> *h_all = new map<TString,TH1D*>; hists["all"] = h_all;
|
159 |
|
|
map<TString,map<TString,TH1D*>* >::iterator it_h;
|
160 |
|
|
for(it_h=hists.begin(); it_h!=hists.end(); it_h++) {
|
161 |
|
|
(*((*it_h).second))["run"] = new TH1D(TString("run") +"_"+(*it_h).first+str,";#bf{run};", 50,163330,196455); (*((*it_h).second))["run"]->Sumw2();
|
162 |
|
|
(*((*it_h).second))["mZ1"] = new TH1D(TString("mZ1") +"_"+(*it_h).first+str,";#bf{mZ1 [GeV]};", 20,75,105); (*((*it_h).second))["mZ1"]->Sumw2();
|
163 |
|
|
(*((*it_h).second))["m4l"] = new TH1D(TString("m4l") +"_"+(*it_h).first+str,";#bf{m4l [GeV]};", 40,50,500); (*((*it_h).second))["m4l"]->Sumw2();
|
164 |
|
|
(*((*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();
|
165 |
|
|
(*((*it_h).second))["Z1pt"] = new TH1D(TString("Z1pt") +"_"+(*it_h).first+str,";#bf{Z1pt [GeV]};", 20,0,200); (*((*it_h).second))["Z1pt"]->Sumw2();
|
166 |
|
|
(*((*it_h).second))["ZZpt"] = new TH1D(TString("ZZpt") +"_"+(*it_h).first+str,";#bf{ZZpt [GeV]};", 30,0,200); (*((*it_h).second))["ZZpt"]->Sumw2();
|
167 |
|
|
}
|
168 |
|
|
|
169 |
|
|
return hists;
|
170 |
|
|
}
|
171 |
|
|
//--------------------------------------------------------------------------------------------------
|
172 |
|
|
void makeHTML(FOFlags &ctrl)
|
173 |
|
|
{
|
174 |
|
|
// TString title(ctrl.inputdir);
|
175 |
|
|
// title = title(title.Last('/')+1,title.Length());
|
176 |
|
|
TString title("Full selection: "+ctrl.muSele);
|
177 |
|
|
ofstream htmlfile;
|
178 |
|
|
char htmlfname[100];
|
179 |
|
|
assert(ctrl.muSele==ctrl.eleSele);
|
180 |
|
|
sprintf(htmlfname,"%s/plots.html",ctrl.outdir.Data());
|
181 |
|
|
htmlfile.open(htmlfname);
|
182 |
|
|
|
183 |
|
|
htmlfile << "<!DOCTYPE html" << endl;
|
184 |
|
|
htmlfile << " PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" << endl;
|
185 |
|
|
htmlfile << "<html>" << endl;
|
186 |
|
|
|
187 |
|
|
htmlfile << "<head><title>"+title+"</title></head>" << endl;
|
188 |
|
|
htmlfile << "<body bgcolor=\"EEEEEE\">" << endl;
|
189 |
|
|
htmlfile << "<h3 style=\"text-align:left; color:DD6600;\">"+title+"</h3>" << endl;
|
190 |
|
|
|
191 |
|
|
htmlfile << "<table border=\"0\" cellspacing=\"5\" width=\"100%\">" << endl;
|
192 |
|
|
|
193 |
|
|
htmlfile << "<tr>" << endl;
|
194 |
|
|
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;
|
195 |
|
|
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;
|
196 |
|
|
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;
|
197 |
|
|
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;
|
198 |
|
|
// htmlfile << "<td width=\"25%\"><a></a></td>" << endl;
|
199 |
|
|
htmlfile << "</tr>" << endl;
|
200 |
|
|
|
201 |
|
|
htmlfile << "<tr>" << endl;
|
202 |
|
|
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;
|
203 |
|
|
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;
|
204 |
|
|
htmlfile << "<td width=\"25%\"><a></a></td>" << endl;
|
205 |
|
|
htmlfile << "<td width=\"25%\"><a></a></td>" << endl;
|
206 |
|
|
htmlfile << "</tr>" << endl;
|
207 |
|
|
|
208 |
|
|
htmlfile << "</table>" << endl;
|
209 |
|
|
|
210 |
|
|
htmlfile << "<hr />" << endl;
|
211 |
|
|
|
212 |
|
|
htmlfile << "<hr />" << endl;
|
213 |
|
|
|
214 |
|
|
htmlfile << "</body>" << endl;
|
215 |
|
|
htmlfile << "</html>" << endl;
|
216 |
|
|
htmlfile.close();
|
217 |
|
|
}
|