ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitHzz4l/Selection/src/plotH4l.cc
Revision: 1.4
Committed: Thu Jul 19 11:12:35 2012 UTC (12 years, 10 months ago) by dkralph
Content type: text/plain
Branch: MAIN
Changes since 1.3: +2 -1 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
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 dkralph 1.2 #include "PlotHeaders.h"
17 dkralph 1.1
18     #ifndef CMSSW_BASE
19     #define CMSSW_BASE "../../"
20     #endif
21    
22     using namespace std;
23     using namespace RooFit;
24 dkralph 1.3 using namespace mithep;
25 dkralph 1.1
26     TCanvas *can;
27    
28 dkralph 1.2 void makeHTML(FOFlags &ctrl, TString plotLabel);
29 dkralph 1.1 map<TString,map<TString,TH1D*>* > init_hists(FOFlags &ctrl, TString str="");
30    
31     //----------------------------------------------------------------------------------------
32     int main(int argc, char** argv)
33     {
34 dkralph 1.2 double lumi = 5000;//10093;//5000+2600;
35 dkralph 1.1
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 dkralph 1.3 TString ntupledir(""),label(""),plotLabel(""),jsonFile("");
48 dkralph 1.4 int puTarget;
49     readConfigFile(ctrl.config, ntupledir, label, plotLabel, jsonFile, puTarget, samplev, &ctrl, init_hists);
50 dkralph 1.1
51     vector<pair<unsigned,unsigned> > runEvtv; // vector to veto duplicate events
52 dkralph 1.2 UInt_t minRun=999999999,maxRun=0;
53 dkralph 1.1 for(unsigned ics=0; ics<samplev.size(); ics++) {
54     CSample *cs = samplev[ics];
55 dkralph 1.2 cout << cs->name << endl;
56 dkralph 1.1 for(unsigned ifs=0; ifs<(cs->fsv).size(); ifs++) {
57     filestuff *fs = (cs->fsv)[ifs];
58 dkralph 1.2 cout << "\t" << fs->fname_ << endl;
59     unsigned nDuplSkipped=0;
60 dkralph 1.1 for(unsigned ientry=0; ientry<fs->getentries("zznt"); ientry++) {
61     fs->getentry(ientry,"info","zznt");
62     fs->getentry(ientry,"kinematics","zznt");
63 dkralph 1.2
64 dkralph 1.1 if(fs->isdata_) {
65 dkralph 1.2 setMinMaxRun(fs->info->run, minRun, maxRun);
66     bool dupl = takeCareOfDuplicateEvents(fs->info->run, fs->info->evt, runEvtv, nDuplSkipped);
67     if(dupl) continue;
68 dkralph 1.1 }
69 dkralph 1.2
70 dkralph 1.1 double wgt = fs->isdata_ ? 1 : lumi*xstab.Get(fs->dataset_)/fs->total_entries_;
71    
72     (*(cs->hists)["all"])["run"]->Fill( fs->info->run , wgt);
73     (*(cs->hists)["all"])["mZ1"]->Fill( fs->kine->mZ1 , wgt);
74     (*(cs->hists)["all"])["m4l"]->Fill( fs->kine->m4l , wgt);
75     (*(cs->hists)["all"])["m4l_lo"]->Fill( fs->kine->m4l , wgt);
76     (*(cs->hists)["all"])["Z1pt"]->Fill( fs->kine->Z1pt , wgt);
77     (*(cs->hists)["all"])["ZZpt"]->Fill( fs->kine->ZZpt , wgt);
78    
79     }
80 dkralph 1.2 cout << "\t\tWARNING: skipped " << nDuplSkipped << " duplicate events" << endl;
81 dkralph 1.1 }
82     }
83 dkralph 1.2 cout << "run range: " << setw(12) << minRun << setw(12) << maxRun << endl;
84     gSystem->mkdir(ctrl.outdir+"/"+plotLabel,true);
85     TFile runHistFile(ctrl.outdir+"/"+plotLabel+"/runs.root","recreate");
86 dkralph 1.1 assert(samplev.size() > 0);
87     map<TString,TH1D*>::iterator it_v;
88     for(it_v=(*(samplev[0]->hists)["all"]).begin(); it_v!=(*(samplev[0]->hists)["all"]).end(); it_v++) {
89     TString var((*it_v).first);
90 dkralph 1.2 CPlot cplot(var,"",(*(samplev[0]->hists)["all"])[var]->GetXaxis()->GetTitle(),"events",ctrl.outdir+"/"+plotLabel+"/plots");
91 dkralph 1.1 for(unsigned isam=0; isam<samplev.size(); isam++) {
92     CSample *cs = samplev[isam];
93     TH1D *hist = (*(cs->hists)["all"])[var];
94 dkralph 1.2 if(cs->isdata) {
95     cplot.AddHist1D(hist,cs->legend+": "+integral_str(hist),"E",cs->color);
96     } else {
97     cplot.AddToStack(hist,cs->legend+": "+integral_str(hist),kCyan-6);
98     // cplot.AddToStack((*(cs_zj->hists)["all"])[var],"ZJ: "+integral_str((*(cs_zj->hists)["all"])[var]),843);
99     }
100 dkralph 1.1 if(cs->isdata && var=="run") {
101     assert(hist->GetBinContent(0)==0 && hist->GetBinContent(hist->GetXaxis()->GetNbins()+1)==0);
102     hist->Write();
103     }
104     }
105     cplot.Draw(can,true,"png");
106     }
107     runHistFile.Close();
108    
109 dkralph 1.2 makeHTML(ctrl,plotLabel);
110 dkralph 1.1 }
111     //----------------------------------------------------------------------------------------
112     map<TString,map<TString,TH1D*>* > init_hists(FOFlags &ctrl, TString str)
113     {
114     map<TString,map<TString,TH1D*>* > hists;
115     map<TString,TH1D*> *h_4e = new map<TString,TH1D*>; hists["4e"] = h_4e;
116     map<TString,TH1D*> *h_4m = new map<TString,TH1D*>; hists["4m"] = h_4m;
117     map<TString,TH1D*> *h_2e2m = new map<TString,TH1D*>; hists["2e2m"] = h_2e2m;
118     map<TString,TH1D*> *h_all = new map<TString,TH1D*>; hists["all"] = h_all;
119     map<TString,map<TString,TH1D*>* >::iterator it_h;
120     for(it_h=hists.begin(); it_h!=hists.end(); it_h++) {
121     (*((*it_h).second))["run"] = new TH1D(TString("run") +"_"+(*it_h).first+str,";#bf{run};", 50,163330,196455); (*((*it_h).second))["run"]->Sumw2();
122     (*((*it_h).second))["mZ1"] = new TH1D(TString("mZ1") +"_"+(*it_h).first+str,";#bf{mZ1 [GeV]};", 20,75,105); (*((*it_h).second))["mZ1"]->Sumw2();
123     (*((*it_h).second))["m4l"] = new TH1D(TString("m4l") +"_"+(*it_h).first+str,";#bf{m4l [GeV]};", 40,50,500); (*((*it_h).second))["m4l"]->Sumw2();
124     (*((*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();
125     (*((*it_h).second))["Z1pt"] = new TH1D(TString("Z1pt") +"_"+(*it_h).first+str,";#bf{Z1pt [GeV]};", 20,0,200); (*((*it_h).second))["Z1pt"]->Sumw2();
126     (*((*it_h).second))["ZZpt"] = new TH1D(TString("ZZpt") +"_"+(*it_h).first+str,";#bf{ZZpt [GeV]};", 30,0,200); (*((*it_h).second))["ZZpt"]->Sumw2();
127     }
128    
129     return hists;
130     }
131     //--------------------------------------------------------------------------------------------------
132 dkralph 1.2 void makeHTML(FOFlags &ctrl, TString plotLabel)
133 dkralph 1.1 {
134     // TString title(ctrl.inputdir);
135     // title = title(title.Last('/')+1,title.Length());
136 dkralph 1.2 TString title("Full selection: "+plotLabel);
137     TString htmlfname(ctrl.outdir+"/"+plotLabel+"/plots.html");
138     ofstream htmlfile(htmlfname);
139 dkralph 1.1
140     htmlfile << "<!DOCTYPE html" << endl;
141     htmlfile << " PUBLIC \"-//W3C//DTD HTML 3.2//EN\">" << endl;
142     htmlfile << "<html>" << endl;
143    
144     htmlfile << "<head><title>"+title+"</title></head>" << endl;
145     htmlfile << "<body bgcolor=\"EEEEEE\">" << endl;
146     htmlfile << "<h3 style=\"text-align:left; color:DD6600;\">"+title+"</h3>" << endl;
147    
148     htmlfile << "<table border=\"0\" cellspacing=\"5\" width=\"100%\">" << endl;
149    
150     htmlfile << "<tr>" << endl;
151     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;
152     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;
153     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;
154     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;
155     // htmlfile << "<td width=\"25%\"><a></a></td>" << endl;
156     htmlfile << "</tr>" << endl;
157    
158     htmlfile << "<tr>" << endl;
159     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;
160     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;
161     htmlfile << "<td width=\"25%\"><a></a></td>" << endl;
162     htmlfile << "<td width=\"25%\"><a></a></td>" << endl;
163     htmlfile << "</tr>" << endl;
164    
165     htmlfile << "</table>" << endl;
166    
167     htmlfile << "<hr />" << endl;
168    
169     htmlfile << "<hr />" << endl;
170    
171     htmlfile << "</body>" << endl;
172     htmlfile << "</html>" << endl;
173     htmlfile.close();
174     }