-
Notifications
You must be signed in to change notification settings - Fork 0
/
draw.h
220 lines (161 loc) · 6.59 KB
/
draw.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
#include "TStyle.h"
#include "TROOT.h"
#include "TPad.h"
#include "TFile.h"
#include "TTree.h"
#include "TChain.h"
#include "TFileCollection.h"
#include "TString.h"
#include "TH1D.h"
#include "TH2D.h"
#include "TCanvas.h"
#include "TLegend.h"
#include "TF1.h"
#include "TProfile.h"
#include "tdrstyle.C"
#include <iostream>
#include <fstream>
using namespace std;
void load_trees(){
TString path = "root://cmsxrootd.fnal.gov//store/group/lpchbb/noreplica/stata/AnalysisTrees/addedHistos/";
std::vector<TString> files_TT;
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_0.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_1.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_10.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_11.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_12.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_13.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_14.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_15.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_16.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_17.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_18.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_19.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_2.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_20.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_21.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_3.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_4.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_5.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_6.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_7.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_8.root");
files_TT.push_back(path+"allHistos_TT_TuneCUETP8M1_13TeV-powheg-pythia8_9.root");
}
class sample {
public:
sample(TString);
~sample();
TString tree_name = "treeR";
TString name;
TString humanName;
TFile* file;
TTree* tree;
UInt_t color = kBlack;
TH1D lastHisto;
};
sample::sample(TString temp){
name = temp;
file = TFile::Open(name);
tree = (TTree*)file->Get("treeR");
}
sample::~sample(){
file->Close();
}
class sample2 {
public:
sample2(std::vector<TString>);
~sample2();
TString tree_name = "treeR";
TString name;
TString humanName;
std::vector<TString> files;
TChain* tree;
UInt_t color = kBlack;
TH1D lastHisto;
};
sample2::sample2(std::vector<TString> temp){
files = temp;
ofstream myfile;
myfile.open ("files.txt");
for(unsigned int i=0; i<files.size(); i++){
myfile << files.at(i).Data();
myfile << "\n";
}
myfile.close();
}
sample2::~sample2(){
}
void drawPlots(std::vector<sample*> sampleVector, const TString varname, const int nbins, const float low, const float high,
const TString xtitle, const TString ytitle, const TString cutstring = "1")
{
std::cout << "Start drawing" << std::endl;
gStyle->SetOptStat(0);
bool log_y = false;
//TStyle* theStyle = 0;
//initStyle(theStyle);
//gROOT->SetStyle("CMS");
setTDRStyle();
std::map<TString, TH1D> histos;
std::cout << "size " << sampleVector.size() << std::endl;
double plotMinimum_ = 0;
if(log_y) plotMinimum_ = 1e-7;
TCanvas thecanvas("c1", "c1", 640, 640);
thecanvas.cd();
float leg_x1=0.5, leg_y1=0.6, leg_x2=0.9, leg_y2=0.88;
TLegend leg(leg_x1, leg_y1, leg_x2, leg_y2);
leg.SetBorderSize(0);
leg.SetLineStyle(0);
leg.SetTextFont(42);
leg.SetFillStyle(0);
//Draw Histograms
double max = 0;
for(unsigned int isample=0; isample<sampleVector.size(); isample++) {
//Create histogram
TString hname = "h";
hname+=isample;
histos[sampleVector.at(isample)->name] = TH1D(hname, hname, nbins, low, high);
histos[sampleVector.at(isample)->name].Sumw2();
cout << sampleVector.at(isample)->name << endl;
cout << sampleVector.at(isample)->tree->GetName() << endl;
//Project
(sampleVector.at(isample)->tree)->Project(hname, varname, cutstring);
//Temp
for(int i=0; i<histos[sampleVector.at(isample)->name].GetNbinsX(); i++) cout << i << " " << histos[sampleVector.at(isample)->name].GetBinContent(i) << endl;
//Normalize
cout << "!! HISTOGRAM IS NORMALIZED !!" << endl;
histos[sampleVector.at(isample)->name].Scale(1.0/histos[sampleVector.at(isample)->name].Integral());
//Save to last Histo
sampleVector.at(isample)->lastHisto = *(TH1D*)histos[sampleVector.at(isample)->name].Clone("last_"+hname);
//sampleVector.at(isample)->lastHisto = histos[sampleVector.at(isample)->name].Clone("last_"+hname);
//sampleVector.at(isample)->lastHisto->SetDirectory(0);
//Get what you want from histogram
if( histos[sampleVector.at(isample)->name].GetMaximum() > max ) max = histos[sampleVector.at(isample)->name].GetMaximum();
}
//Second loop to draw (knowing max)
int ndrawn = 0;
for(unsigned int isample=0; isample<sampleVector.size(); isample++) {
//Style
if(isample==0) histos[sampleVector.at(isample)->name].SetTitle("");
histos[sampleVector.at(isample)->name].SetLineWidth(2);
histos[sampleVector.at(isample)->name].SetLineColor(sampleVector.at(isample)->color);
histos[sampleVector.at(isample)->name].SetMarkerColor(sampleVector.at(isample)->color);
histos[sampleVector.at(isample)->name].SetXTitle(xtitle);
histos[sampleVector.at(isample)->name].SetYTitle(ytitle);
if(high-low < 1.0) histos[sampleVector.at(isample)->name].SetNdivisions(506);
//Add to legend
leg.AddEntry(&histos[sampleVector.at(isample)->name], sampleVector.at(isample)->humanName, "L");
//Draw histogram
TString drawOptions = "HIST E";
if(ndrawn>0) drawOptions += " SAME";
if(ndrawn==0) histos[sampleVector.at(isample)->name].SetMaximum(1.1*max);
if(ndrawn==0) histos[sampleVector.at(isample)->name].SetMinimum(plotMinimum_);
histos[sampleVector.at(isample)->name].Draw(drawOptions);
ndrawn++;
}
leg.Draw();
if(log_y) thecanvas.SetLogy();
TString log_string = "";
if(log_y) log_string = "_log";
thecanvas.SaveAs("h_"+varname+log_string+".pdf");
}//end of drawPlots