ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/SchieferD/jetcalib/plotvars_x.cpp
Revision: 1.1
Committed: Wed Aug 15 17:20:06 2007 UTC (17 years, 8 months ago) by schiefer
Branch: MAIN
Log Message:
first import

File Contents

# Content
1 ////////////////////////////////////////////////////////////////////////////////
2 //
3 // plotvars_x
4 // ----------
5 //
6 // 06/14/2007 Philipp Schieferdecker <philipp.schieferdecker@cern.ch>
7 ////////////////////////////////////////////////////////////////////////////////
8
9
10 #include "utils/cmdline.h"
11
12 #include <TROOT.h>
13 #include <TStyle.h>
14 #include <TRint.h>
15 #include <TFile.h>
16 #include <TTree.h>
17 #include <TChain.h>
18 #include <TH1F.h>
19 #include <TCanvas.h>
20 #include <TLegend.h>
21
22 #include <iostream>
23 #include <iomanip>
24 #include <string>
25 #include <vector>
26
27
28 using namespace std;
29
30
31 ////////////////////////////////////////////////////////////////////////////////
32 // main
33 ////////////////////////////////////////////////////////////////////////////////
34
35 //______________________________________________________________________________
36 int main(int argc,char**argv)
37 {
38 cmdline cl;
39 cl.parse(argc,argv);
40
41 vector<string> input = cl.get_vector<string>("input");
42 vector<string> variables = cl.get_vector<string>("variables");
43 string selection = cl.get_value<string> ("selection", "njt>0");
44 string treename = cl.get_value<string> ("treename", "t");
45 bool overlay = cl.get_value<bool> ("overlay", true);
46
47 if (!cl.check()) return 0;
48 cl.print();
49
50
51 // concider event weights via selection
52 selection = "weight*(" + selection + ")";
53
54 // jetalgs
55 vector<string> jetalgs;
56 for (vector<string>::const_iterator it=input.begin();it!=input.end();++it) {
57 string jetalg = *it;
58 string::size_type pos;
59 while ((pos=jetalg.find('/'))!=string::npos) jetalg = jetalg.substr(pos+1);
60 jetalg = jetalg.substr(0,jetalg.find(".root"));
61 jetalgs.push_back(jetalg);
62 }
63
64 // samples
65 vector<TTree*> samples;
66 for (unsigned int i=0;i<input.size();++i) {
67 TFile* f = new TFile(input[i].c_str(),"READ");
68 TTree* t = (TTree*)f->Get(treename.c_str());
69 samples.push_back(t);
70 cout<<jetalgs[i]<<" sample has "<<t->GetEntries()<<" total events."<<endl;
71 }
72
73
74 // histograms
75 TH1::SetDefaultSumw2();
76 vector<TH1F**> histograms;
77 for (unsigned int i=0;i<variables.size();i++)
78 histograms.push_back(new TH1F*[jetalgs.size()]);
79 for (unsigned int ivar=0;ivar<variables.size();++ivar) {
80 string variable = variables[ivar];
81 for (unsigned int isample=0;isample<samples.size();++isample) {
82 string jetalg = jetalgs[isample];
83 TTree* sample = samples[isample];
84 sample->Draw(variable.c_str(),selection.c_str(),"goff");
85 TH1F* h = (TH1F*)gROOT->FindObject("htemp");
86 if (ivar==0) cout<<jetalg<<": "<<h->GetEntries()<<" events selected."<<endl;
87 string hname = "h"+variable+"_"+jetalg;
88 string::size_type pos;
89 while ((pos=hname.find('['))<string::npos) hname.erase(pos,1);
90 while ((pos=hname.find(']'))<string::npos) hname.erase(pos,1);
91 h->SetNameTitle(hname.c_str(),hname.c_str());
92 histograms[ivar][isample]=h;
93 cout<<hname<<" finished."<<endl;
94 }
95 }
96
97
98 // make plots
99 argc=1;
100 TRint* app = new TRint(argv[0],&argc,argv);
101 if (overlay) gStyle->SetOptStat(0);
102 for (unsigned int ihist=0;ihist<histograms.size();++ihist) {
103 string variable = variables[ihist];
104 TLegend* leg(0);
105
106 if (overlay) {
107 string cname = "c"+variable;
108 TCanvas* c = new TCanvas(cname.c_str(),cname.c_str());
109 if (variable.find("photone")<string::npos||
110 variable.find("photonpt")<string::npos||
111 variable.find("njt")<string::npos||
112 variable.find("jte")<string::npos||
113 variable.find("jtpt")<string::npos||
114 variable.find("met")<string::npos) c->SetLogy();
115 leg = new TLegend(0.6,0.85-jetalgs.size()*0.05,0.9,0.85);
116 leg->SetFillColor(10);
117 }
118
119 Color_t color = kBlack;
120
121 for (unsigned int ialg=0;ialg<jetalgs.size();++ialg) {
122 string jetalg = jetalgs[ialg];
123 TH1F* h = histograms[ihist][ialg];
124 if (!overlay) {
125 string cname = "c"+variable+"_"+jetalg;
126 TCanvas* c = new TCanvas(cname.c_str(),cname.c_str());
127 if (variable.find("photone")<string::npos||
128 variable.find("photonpt")<string::npos||
129 variable.find("njt")<string::npos||
130 variable.find("jte")<string::npos||
131 variable.find("jtpt")<string::npos||
132 variable.find("met")<string::npos) c->SetLogy();
133 }
134 else {
135 h->SetTitle(variable.c_str());
136 h->SetLineColor(color++);
137 }
138
139 (ialg==0||!overlay) ? h->Draw("EHIST") : h->Draw("EHISTSAME");
140
141 if (leg!=0) {
142 stringstream ss;
143 ss<<jetalg<<" ("
144 <<h->GetEntries()<<"/"
145 <<setiosflags(ios::scientific)<<setprecision(2)
146 <<h->GetMean()<<"/"
147 <<h->GetRMS()
148 <<resetiosflags(ios::scientific)<<setprecision(6)
149 <<")";
150 leg->AddEntry(h,ss.str().c_str(),"l");
151 if (ialg==jetalgs.size()-1) leg->Draw();
152 }
153 }
154
155 }
156
157 app->Run();
158
159 return 0;
160 }