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 |
#include "PlotHeaders.h"
|
17 |
|
18 |
#ifndef CMSSW_BASE
|
19 |
#define CMSSW_BASE "../../"
|
20 |
#endif
|
21 |
|
22 |
using namespace std;
|
23 |
using namespace RooFit;
|
24 |
using namespace mithep;
|
25 |
|
26 |
TCanvas *can;
|
27 |
|
28 |
void makeHTML(FOFlags &ctrl, TString plotLabel);
|
29 |
map<TString,map<TString,TH1D*>* > init_hists(FOFlags &ctrl, TString str="");
|
30 |
|
31 |
//----------------------------------------------------------------------------------------
|
32 |
int main(int argc, char** argv)
|
33 |
{
|
34 |
double lumi = 5000;//10093;//5000+2600;
|
35 |
|
36 |
FOFlags ctrl;
|
37 |
parse_foargs( argc, argv, ctrl );
|
38 |
ctrl.dump();
|
39 |
|
40 |
can = new TCanvas("can","can");
|
41 |
|
42 |
TString cmsswpath(CMSSW_BASE + TString("/src"));
|
43 |
string xspath = (string(cmsswpath)+"/MitPhysics/data/xs.dat");
|
44 |
SimpleTable xstab(xspath.c_str());
|
45 |
|
46 |
vector<CSample*> samplev;
|
47 |
TString ntupledir(""),label(""),plotLabel(""),jsonFile("");
|
48 |
readConfigFile(ctrl.config, ntupledir, label, plotLabel, jsonFile, samplev, &ctrl, init_hists);
|
49 |
|
50 |
vector<pair<unsigned,unsigned> > runEvtv; // vector to veto duplicate events
|
51 |
UInt_t minRun=999999999,maxRun=0;
|
52 |
for(unsigned ics=0; ics<samplev.size(); ics++) {
|
53 |
CSample *cs = samplev[ics];
|
54 |
cout << cs->name << endl;
|
55 |
for(unsigned ifs=0; ifs<(cs->fsv).size(); ifs++) {
|
56 |
filestuff *fs = (cs->fsv)[ifs];
|
57 |
cout << "\t" << fs->fname_ << endl;
|
58 |
unsigned nDuplSkipped=0;
|
59 |
for(unsigned ientry=0; ientry<fs->getentries("zznt"); ientry++) {
|
60 |
fs->getentry(ientry,"info","zznt");
|
61 |
fs->getentry(ientry,"kinematics","zznt");
|
62 |
|
63 |
if(fs->isdata_) {
|
64 |
setMinMaxRun(fs->info->run, minRun, maxRun);
|
65 |
bool dupl = takeCareOfDuplicateEvents(fs->info->run, fs->info->evt, runEvtv, nDuplSkipped);
|
66 |
if(dupl) continue;
|
67 |
}
|
68 |
|
69 |
double wgt = fs->isdata_ ? 1 : lumi*xstab.Get(fs->dataset_)/fs->total_entries_;
|
70 |
|
71 |
(*(cs->hists)["all"])["run"]->Fill( fs->info->run , wgt);
|
72 |
(*(cs->hists)["all"])["mZ1"]->Fill( fs->kine->mZ1 , wgt);
|
73 |
(*(cs->hists)["all"])["m4l"]->Fill( fs->kine->m4l , wgt);
|
74 |
(*(cs->hists)["all"])["m4l_lo"]->Fill( fs->kine->m4l , wgt);
|
75 |
(*(cs->hists)["all"])["Z1pt"]->Fill( fs->kine->Z1pt , wgt);
|
76 |
(*(cs->hists)["all"])["ZZpt"]->Fill( fs->kine->ZZpt , wgt);
|
77 |
|
78 |
}
|
79 |
cout << "\t\tWARNING: skipped " << nDuplSkipped << " duplicate events" << endl;
|
80 |
}
|
81 |
}
|
82 |
cout << "run range: " << setw(12) << minRun << setw(12) << maxRun << endl;
|
83 |
gSystem->mkdir(ctrl.outdir+"/"+plotLabel,true);
|
84 |
TFile runHistFile(ctrl.outdir+"/"+plotLabel+"/runs.root","recreate");
|
85 |
assert(samplev.size() > 0);
|
86 |
map<TString,TH1D*>::iterator it_v;
|
87 |
for(it_v=(*(samplev[0]->hists)["all"]).begin(); it_v!=(*(samplev[0]->hists)["all"]).end(); it_v++) {
|
88 |
TString var((*it_v).first);
|
89 |
CPlot cplot(var,"",(*(samplev[0]->hists)["all"])[var]->GetXaxis()->GetTitle(),"events",ctrl.outdir+"/"+plotLabel+"/plots");
|
90 |
for(unsigned isam=0; isam<samplev.size(); isam++) {
|
91 |
CSample *cs = samplev[isam];
|
92 |
TH1D *hist = (*(cs->hists)["all"])[var];
|
93 |
if(cs->isdata) {
|
94 |
cplot.AddHist1D(hist,cs->legend+": "+integral_str(hist),"E",cs->color);
|
95 |
} else {
|
96 |
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);
|
98 |
}
|
99 |
if(cs->isdata && var=="run") {
|
100 |
assert(hist->GetBinContent(0)==0 && hist->GetBinContent(hist->GetXaxis()->GetNbins()+1)==0);
|
101 |
hist->Write();
|
102 |
}
|
103 |
}
|
104 |
cplot.Draw(can,true,"png");
|
105 |
}
|
106 |
runHistFile.Close();
|
107 |
|
108 |
makeHTML(ctrl,plotLabel);
|
109 |
}
|
110 |
//----------------------------------------------------------------------------------------
|
111 |
map<TString,map<TString,TH1D*>* > init_hists(FOFlags &ctrl, TString str)
|
112 |
{
|
113 |
map<TString,map<TString,TH1D*>* > hists;
|
114 |
map<TString,TH1D*> *h_4e = new map<TString,TH1D*>; hists["4e"] = h_4e;
|
115 |
map<TString,TH1D*> *h_4m = new map<TString,TH1D*>; hists["4m"] = h_4m;
|
116 |
map<TString,TH1D*> *h_2e2m = new map<TString,TH1D*>; hists["2e2m"] = h_2e2m;
|
117 |
map<TString,TH1D*> *h_all = new map<TString,TH1D*>; hists["all"] = h_all;
|
118 |
map<TString,map<TString,TH1D*>* >::iterator it_h;
|
119 |
for(it_h=hists.begin(); it_h!=hists.end(); it_h++) {
|
120 |
(*((*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 |
|
128 |
return hists;
|
129 |
}
|
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 |
}
|