-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplotClass.cc
More file actions
375 lines (303 loc) · 10.4 KB
/
plotClass.cc
File metadata and controls
375 lines (303 loc) · 10.4 KB
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
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
#include "plotClass.hh"
#include <fstream>
#include <iostream>
#include <sstream>
#include "TROOT.h"
#include "TStyle.h"
#include "TMath.h"
#include "TRandom3.h"
#include "TString.h"
#include "TCanvas.h"
#include "TPad.h"
#include "TF1.h"
#include "util.hh"
ClassImp(plotClass)
using namespace std;
// ----------------------------------------------------------------------
plotClass::plotClass(string dir, string files, string cuts, string setup) {
gStyle->SetHatchesSpacing(2);
fDirectory = dir;
fSetup = setup;
fMode = UNSET;
fSuffix = "";
delete gRandom;
gRandom = (TRandom*) new TRandom3;
legg = 0;
c0 = c1 = c2 = c3 = c4 = c5 =0;
tl = new TLatex();
box = new TBox();
pa = new TArrow();
pl = new TLine();
legge = 0;
c0 = (TCanvas*)gROOT->FindObject("c0");
if (!c0) c0 = new TCanvas("c0","--c0--",0,0,1200,700);
fHistFile = 0; // this must be opened in a derived class!
}
// ----------------------------------------------------------------------
plotClass::~plotClass() {
cout << "plotClass destructor" << endl;
for (map<string, dataset*>::iterator imap = fDS.begin(); imap != fDS.end(); ++imap) {
if (fDS[imap->first]->fF) {
cout << " => closing " << imap->first;
cout << ": " << fDS[imap->first]->fF->GetName() << endl;
imap->second->fF->Close();
}
}
}
// ----------------------------------------------------------------------
// see http://root.cern.ch/phpBB3/viewtopic.php?f=3&t=15054
void plotClass::closeHistFile() {
fHistFile->Write();
}
// ----------------------------------------------------------------------
void plotClass::makeAll(int bitmask) {
cout << "wrong class function" << endl;
}
// ----------------------------------------------------------------------
void plotClass::setup(string ds) {
fSample = ds;
string dir = "";
fTreeDir = dir;
}
// ----------------------------------------------------------------------
void plotClass::changeSetup(string dir, string name, string setup) {
fHistFileName = Form("%s/%s.%s.root", dir.c_str(), name.c_str(), fSetup.c_str());
fNumbersFileName = fDirectory + Form("/%s.%s.txt", name.c_str(), fSetup.c_str());
fTexFileName = fNumbersFileName;
replaceAll(fTexFileName, ".txt", ".tex");
cout << "plotClass::changeSetup: " << endl
<< " name = " << name << endl
<< " setup = " << setup << endl
<< " fSetup = " << fSetup << endl
<< " fSuffix = " << fSuffix << endl
<< " fHistFileName = " << fHistFileName << endl
<< " fNumbersFileName = " << fNumbersFileName << endl
<< " fTexFileName = " << fTexFileName << endl
<< endl;
}
// ----------------------------------------------------------------------
void plotClass::init() {
cout << "***************************************************************" << endl;
fTEX.close();
cout << Form("/bin/rm -f %s", fTexFileName.c_str()) << endl;
system(Form("/bin/rm -f %s", fTexFileName.c_str()));
cout << Form("open for TeX output: %s", fTexFileName.c_str()) << endl;
fTEX.open(fTexFileName.c_str(), ios::app);
}
// ----------------------------------------------------------------------
void plotClass::setupTree(TTree *t, string mode) {
cout << "wrong class function" << endl;
// t->SetBranchAddress("run", &fb.run);
// t->SetBranchAddress("evt", &fb.evt);
}
// ----------------------------------------------------------------------
void plotClass::loopOverTree(TTree *t, int ifunc, int nevts, int nstart) {
cout << "wrong class function" << endl;
}
// ----------------------------------------------------------------------
void plotClass::loopFunction1() {
cout << "wrong class function" << endl;
}
// ----------------------------------------------------------------------
void plotClass::candAnalysis() {
}
// ----------------------------------------------------------------------
TTree* plotClass::getTree(string ds, string dir, string tree) {
if (!fDS[ds]) {
cout << "xx> plotClass::getTree: dataset ->" << ds << "<- not found" << endl;
return 0;
}
TTree *t(0);
if (!dir.compare("")) {
t = (TTree*)fDS[ds]->fF->Get(tree.c_str());
} else {
t = (TTree*)fDS[ds]->fF->Get(Form("%s/%s", dir.c_str(), tree.c_str()));
}
cout << "plotClass::getTree(" << ds << ", " << dir << ", " << tree << "): " << t << endl;
return t;
}
// ----------------------------------------------------------------------
TFile* plotClass::loadFile(string file) {
TFile *f = TFile::Open(file.c_str());
return f;
}
// ----------------------------------------------------------------------
void plotClass::loadFiles(string afiles) {
string files = fDirectory + string("/") + afiles;
cout << "==> plotClass::loadFiles loading files listed in " << files << endl;
char buffer[1000];
ifstream is(files.c_str());
while (is.getline(buffer, 1000, '\n')) {
if (buffer[0] == '#') {continue;}
if (buffer[0] == '/') {continue;}
string sbuffer = string(buffer);
replaceAll(sbuffer, " ", "");
replaceAll(sbuffer, "\t", "");
if (sbuffer.size() < 1) continue;
string::size_type m1 = sbuffer.find("lumi=");
string::size_type m2 = sbuffer.find("eff=");
string::size_type m3 = sbuffer.find("file=");
string stype("nada");
bool useBf(false);
if (m1 > sbuffer.size()) {
m1 = sbuffer.find("bf=");
useBf = true;
}
double eff(0.), effE(0.);
if (m2 > sbuffer.size()) {
m2 = sbuffer.find("file=");
} else {
string seff = sbuffer.substr(m2+4, m3-m2-4);
float val, err;
int expo;
sscanf(seff.c_str(), "(%f,%f)e%d", &val, &err, &expo);
eff = val*TMath::Power(10., expo);
effE = err*TMath::Power(10., expo);
}
stype = sbuffer.substr(5, m1-5);
string slumi("nada"), sbf("nada");
if (useBf) {
sbf = sbuffer.substr(m1+3, m2-m1-3);
} else {
slumi = sbuffer.substr(m1+5, m3-m1-5);
}
string sfile = sbuffer.substr(m3+5);
string sname("nada"), sdecay("nada"), ldecay("");
double bf(0.), bfE(0.);
if (useBf) {
//cout << "sbf = " << sbf << endl;
float val, err;
int expo;
sscanf(sbf.c_str(), "(%f,%f)e%d", &val, &err, &expo);
bf = val*TMath::Power(10., expo);
bfE = err*TMath::Power(10., expo);
} else {
bf = 0.;
bfE = 0.;
}
// if (useBf) cout << " -> BF = " << bf << " +/- " << bfE << endl;
TFile *pF(0);
dataset *ds(0);
if (string::npos != stype.find("data")) {
cout << "reading sfile ->" << sfile << "<-" << " stype ->" << stype << "<-" << endl;
// -- DATA
pF = loadFile(sfile);
ds = new dataset();
ds->fSize = 1.2;
ds->fWidth = 2;
if (string::npos != stype.find("pixel,")) {
sname = "pixelData";
ds->fColor = kBlack;
ds->fSymbol = 20;
ds->fF = pF;
ds->fBf = bf;
ds->fBfE = bfE;
ds->fFilterEff = eff;
ds->fFilterEffE = effE;
ds->fMass = 1.;
ds->fFillStyle = 3365;
ds->fLumi = atof(slumi.c_str());
cout << "adding ds " << sname << endl;
}
}
}
}
// ----------------------------------------------------------------------
void plotClass::replaceAll(string &sInput, const string &oldString, const string &newString) {
string::size_type foundpos = sInput.find(oldString);
while (foundpos != string::npos) {
sInput.replace(sInput.begin() + foundpos, sInput.begin() + foundpos + oldString.length(), newString);
foundpos = sInput.find(oldString);
}
}
// ----------------------------------------------------------------------
void plotClass::newLegend(double x1, double y1, double x2, double y2, string title) {
// if (legg) delete legg;
legg = new TLegend(x1, y1, x2, y2, title.c_str());
legg->SetFillStyle(0);
legg->SetBorderSize(0);
legg->SetTextSize(0.04);
legg->SetFillColor(0);
legg->SetTextFont(42);
}
// ----------------------------------------------------------------------
void plotClass::makeCanvas(int i) {
if (i & 16) {
c5 = new TCanvas("c5", "c5", 210, 0, 800, 900);
c5->ToggleEventStatus();
}
if (i & 8) {
c4 = new TCanvas("c4", "c4", 210, 0, 800, 600);
c4->ToggleEventStatus();
}
if (i & 4) {
c3 = new TCanvas("c3", "c3", 200, 20, 800, 800);
c3->ToggleEventStatus();
}
if (i & 1) {
// c1 = new TCanvas("c1", "c1", 20, 60, 1200, 400);
c1 = new TCanvas("c1", "c1", 20, 60, 1000, 400);
c1->ToggleEventStatus();
}
if (i & 2) {
c2 = new TCanvas("c2", "c2", 300, 200, 400, 800);
c2->ToggleEventStatus();
}
}
// ----------------------------------------------------------------------
void plotClass::readCuts(string filename) {
cout << "==> plotClass: Reading " << filename << " for cut settings" << endl;
vector<string> cutLines;
readFile(filename, cutLines);
cout << "==> finished reading cut setting " << endl;
}
// ----------------------------------------------------------------------
void plotClass::readFile(string filename, vector<string> &lines) {
cout << " readFile " << filename << endl;
char buffer[200];
ifstream is(filename.c_str());
if (!is) {
cout << "file ->" << filename << "<- not found, exit(1)" << endl;
exit(1);
}
char input[1000];
while (is.getline(buffer, 200, '\n')) {
if (buffer[0] != '+') {
lines.push_back(string(buffer));
} else {
sscanf(buffer, "+input %s", input);
readFile(input, lines);
}
}
}
// ----------------------------------------------------------------------
void plotClass::printCuts(ostream &OUT) {
OUT << "----------------------------------------------------------------------" << endl;
OUT << endl;
OUT << "metaMin ";
OUT << endl;
}
// ----------------------------------------------------------------------
void plotClass::setItalic() {
tl->SetTextFont(52);
}
// ----------------------------------------------------------------------
void plotClass::setRoman() {
tl->SetTextFont(42);
}
// ----------------------------------------------------------------------
void plotClass::savePad(string name, TCanvas *c) {
if (0 == c) {
gPad->SaveAs(Form("%s/%s", fDirectory.c_str(), name.c_str()));
} else {
c->SaveAs(Form("%s/%s", fDirectory.c_str(), name.c_str()));
}
}
// ----------------------------------------------------------------------
void plotClass::cd(std::string dataset, std::string dir) {
if (0 == fDS.count(dataset)) {
cout << "unknown dataset: " << dataset << endl;
} else {
fDS[dataset]->cd(dir.c_str());
}
}