-
Notifications
You must be signed in to change notification settings - Fork 1
/
subtraction_internal_ver0.cc
467 lines (400 loc) · 15 KB
/
subtraction_internal_ver0.cc
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
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
#include <fstream>
#include <sstream>
#include <algorithm>
#include <TROOT.h>
#include <TSystem.h>
#include <TFile.h>
#include <TTree.h>
#include <TApplication.h>
#include <TStyle.h>
#include <TCanvas.h>
#include <TH1D.h>
#define NOBJECT_MAX 16384
double ue_predictor_pf[3][15][5][2][82];
double ue_interpolation_pf0[15][344];
double ue_interpolation_pf1[15][344];
double ue_interpolation_pf2[15][82];
size_t pf_id_reduce(const Int_t pf_id)
{
// Particle::pdgId_ PFCandidate::particleId_
// PFCandidate::ParticleType Particle
// 0 0 X unknown, or dummy
// +211, -211 1 h charged hadron
// +11, -11 2 e electron
// +13, -13 3 mu muon
// 22 4 gamma photon
// 130 5 h0 neutral hadron
// 130 6 h_HF hadronic energy in an HF tower
// 22 7 egamma_HF electromagnetic energy in an HF tower
if (pf_id == 4) {
return 1;
}
else if (pf_id >= 5 && pf_id <= 7) {
return 2;
}
return 0;
}
void subtraction_internal_ver0(const char *filename = "root://eoscms//eos/cms/store/group/phys_heavyions/dgulhan/PbPbForest_MatchEqR_Calo_HIHighPt_HIRun2011-14Mar2014-v4_merged_nodublicate/PbPbForest_MatchEqR_Calo_HIHighPt_HIRun2011-14Mar2014-v4.root")
{
static const size_t nfourier = 5;
int data = 0;
int calorimetric = 0;
const char *root_tree_name = calorimetric ?
"rechitanalyzer/tower" : "pfcandAnalyzer/pfTree";
TFile *f = TFile::Open(filename);
TTree *root_tree = dynamic_cast<TTree *>(gDirectory->Get(root_tree_name));
Int_t nPFpart;
Int_t pfId[NOBJECT_MAX];
Float_t pfPt[NOBJECT_MAX];
Float_t pfEta[NOBJECT_MAX];
Float_t pfPhi[NOBJECT_MAX];
Float_t pfArea[NOBJECT_MAX];
if (calorimetric) {
root_tree->SetBranchAddress("n", &nPFpart);
root_tree->SetBranchAddress("et", pfPt);
root_tree->SetBranchAddress("eta", pfEta);
root_tree->SetBranchAddress("phi", pfPhi);
root_tree->SetBranchAddress("vsArea", pfArea);
}
else {
root_tree->SetBranchAddress("nPFpart", &nPFpart);
root_tree->SetBranchAddress("pfId", pfId);
root_tree->SetBranchAddress("pfPt", pfPt);
root_tree->SetBranchAddress("pfEta", pfEta);
root_tree->SetBranchAddress("pfPhi", pfPhi);
root_tree->SetBranchAddress("pfArea", pfArea);
}
TTree *hiTree = dynamic_cast<TTree *>(gDirectory->Get("hiEvtAnalyzer/HiTree"));
Int_t run;
Int_t lumi;
Float_t vx;
Float_t vy;
Float_t vz;
Int_t hiBin;
Float_t hiHF;
Float_t hiHFplus;
Float_t hiHFminus;
Float_t hiZDC;
Float_t hiZDCplus;
Float_t hiZDCminus;
Float_t hiHFhit;
Float_t hiHFhitPlus;
Float_t hiHFhitMinus;
Float_t hiET;
Float_t hiEE;
Float_t hiEB;
Float_t hiEEplus;
Float_t hiEEminus;
Int_t hiNpix;
Int_t hiNpixelTracks;
Int_t hiNtracks;
Int_t hiNtracksPtCut;
Int_t hiNtracksEtaCut;
Int_t hiNtracksEtaPtCut;
Int_t hiNevtPlane;
Float_t hiEvtPlanes[38];
// Set branch addresses.
hiTree->SetBranchAddress("run",&run);
hiTree->SetBranchAddress("lumi",&lumi);
hiTree->SetBranchAddress("vx",&vx);
hiTree->SetBranchAddress("vy",&vy);
hiTree->SetBranchAddress("vz",&vz);
hiTree->SetBranchAddress("hiBin",&hiBin);
hiTree->SetBranchAddress("hiHF",&hiHF);
hiTree->SetBranchAddress("hiHFplus",&hiHFplus);
hiTree->SetBranchAddress("hiHFminus",&hiHFminus);
hiTree->SetBranchAddress("hiZDC",&hiZDC);
hiTree->SetBranchAddress("hiZDCplus",&hiZDCplus);
hiTree->SetBranchAddress("hiZDCminus",&hiZDCminus);
hiTree->SetBranchAddress("hiHFhit",&hiHFhit);
hiTree->SetBranchAddress("hiHFhitPlus",&hiHFhitPlus);
hiTree->SetBranchAddress("hiHFhitMinus",&hiHFhitMinus);
hiTree->SetBranchAddress("hiET",&hiET);
hiTree->SetBranchAddress("hiEE",&hiEE);
hiTree->SetBranchAddress("hiEB",&hiEB);
hiTree->SetBranchAddress("hiEEplus",&hiEEplus);
hiTree->SetBranchAddress("hiEEminus",&hiEEminus);
hiTree->SetBranchAddress("hiNpix",&hiNpix);
hiTree->SetBranchAddress("hiNpixelTracks",&hiNpixelTracks);
hiTree->SetBranchAddress("hiNtracks",&hiNtracks);
hiTree->SetBranchAddress("hiNtracksPtCut",&hiNtracksPtCut);
hiTree->SetBranchAddress("hiNtracksEtaCut",&hiNtracksEtaCut);
hiTree->SetBranchAddress("hiNtracksEtaPtCut",&hiNtracksEtaPtCut);
hiTree->SetBranchAddress("hiNevtPlane",&hiNevtPlane);
hiTree->SetBranchAddress("hiEvtPlanes",hiEvtPlanes);
const char *tree_name = "akVs3PFJetAnalyzer/t";
TTree *t = dynamic_cast<TTree *>(gDirectory->Get(tree_name));
Int_t evt;
// Float_t b;
Int_t nref;
Float_t rawpt[NOBJECT_MAX];
Float_t jtpt[NOBJECT_MAX];
Float_t jteta[NOBJECT_MAX];
Float_t jty[NOBJECT_MAX];
Float_t jtphi[NOBJECT_MAX];
Float_t jtpu[NOBJECT_MAX];
// Set branch addresses.
t->SetBranchAddress("evt", &evt);
// t->SetBranchAddress("b", &b);
t->SetBranchAddress("nref", &nref);
t->SetBranchAddress("rawpt", rawpt);
t->SetBranchAddress("jtpt", jtpt);
t->SetBranchAddress("jteta", jteta);
t->SetBranchAddress("jty", jty);
t->SetBranchAddress("jtphi", jtphi);
t->SetBranchAddress("jtpu", jtpu);
std::ifstream in_stream(data ? (calorimetric ? "ue_calibrations_calo_data.txt" : "ue_calibrations_pf_data.txt") : (calorimetric ? "ue_calibrations_calo_mc.txt" : "ue_calibrations_pf_mc.txt"));
std::string line;
size_t index = 0;
static const size_t nline_predictor = 3 * 15 * (1 + (5 - 1) * 2) * 82;
while (std::getline(in_stream, line)) {
if (line.empty() || line[0] == '#') {
continue;
}
std::istringstream line_stream(line);
double val;
int bin0, bin1, bin2, bin3, bin4;
if (index < nline_predictor) {
line_stream >> bin0 >> bin1 >> bin2 >> bin3 >> bin4 >> val;
ue_predictor_pf[bin0][bin1][bin2][bin3][bin4] = val;
}
else if (index < nline_predictor + sizeof(ue_interpolation_pf0) / sizeof(double)) {
line_stream >> bin0 >> bin1 >> val;
ue_interpolation_pf0[bin0][bin1] = val;
}
else if (index < nline_predictor + sizeof(ue_interpolation_pf0) / sizeof(double) + sizeof(ue_interpolation_pf1) / sizeof(double)) {
line_stream >> bin0 >> bin1 >> val;
ue_interpolation_pf1[bin0][bin1] = val;
}
else if (index < nline_predictor + sizeof(ue_interpolation_pf0) / sizeof(double) + sizeof(ue_interpolation_pf1) / sizeof(double) + sizeof(ue_interpolation_pf2) / sizeof(double)) {
line_stream >> bin0 >> bin1 >> val;
ue_interpolation_pf2[bin0][bin1] = val;
}
index++;
}
static const size_t nreduced_id = 3;
static const size_t nedge_pseudorapidity = 15 + 1;
static const double edge_pseudorapidity[nedge_pseudorapidity] = {
-5.191, -2.650, -2.043, -1.740, -1.479, -1.131, -0.783, -0.522,
0.522, 0.783, 1.131, 1.479, 1.740, 2.043, 2.650, 5.191
};
const std::vector<double> edge_pseudorapidity_v(edge_pseudorapidity, edge_pseudorapidity + nedge_pseudorapidity);
static const size_t ncms_hcal_edge_pseudorapidity = 82 + 1;
static const double cms_hcal_edge_pseudorapidity[
ncms_hcal_edge_pseudorapidity] = {
-5.191, -4.889, -4.716, -4.538, -4.363, -4.191, -4.013,
-3.839, -3.664, -3.489, -3.314, -3.139, -2.964, -2.853,
-2.650, -2.500, -2.322, -2.172, -2.043, -1.930, -1.830,
-1.740, -1.653, -1.566, -1.479, -1.392, -1.305, -1.218,
-1.131, -1.044, -0.957, -0.879, -0.783, -0.696, -0.609,
-0.522, -0.435, -0.348, -0.261, -0.174, -0.087,
0.000,
0.087, 0.174, 0.261, 0.348, 0.435, 0.522, 0.609,
0.696, 0.783, 0.879, 0.957, 1.044, 1.131, 1.218,
1.305, 1.392, 1.479, 1.566, 1.653, 1.740, 1.830,
1.930, 2.043, 2.172, 2.322, 2.500, 2.650, 2.853,
2.964, 3.139, 3.314, 3.489, 3.664, 3.839, 4.013,
4.191, 4.363, 4.538, 4.716, 4.889, 5.191
};
const std::vector<double> cms_hcal_edge_pseudorapidity_v(cms_hcal_edge_pseudorapidity, cms_hcal_edge_pseudorapidity + ncms_hcal_edge_pseudorapidity);
static const size_t ncms_ecal_edge_pseudorapidity = 344 + 1;
double cms_ecal_edge_pseudorapidity[
ncms_ecal_edge_pseudorapidity];
for (size_t i = 0; i < ncms_ecal_edge_pseudorapidity; i++) {
cms_ecal_edge_pseudorapidity[i] =
i * (2 * 2.9928 /
(ncms_ecal_edge_pseudorapidity - 1)) -
2.9928;
};
const std::vector<double> cms_ecal_edge_pseudorapidity_v(cms_ecal_edge_pseudorapidity, cms_ecal_edge_pseudorapidity + ncms_ecal_edge_pseudorapidity);
size_t nentries = root_tree->GetEntries();
nentries = 10;
for (size_t i = 0; i < nentries; i++) {
root_tree->GetEntry(i);
hiTree->GetEntry(i);
t->GetEntry(i);
// Event collective Fourier components, per particle flow ID
// group. Note that since by heavy ion convention, dN/dphi =
// v0/(2 pi) + v0 v1/pi cos(phi - Psi_RP) + v0 v2/pi cos(2(phi
// - Psi_RP)) + ..., and orthonormal relation for the Fourier
// basis f0 = v0, f1 = v0 v1, ..., if f is the Fourier and v0
// the phi-averaged 1/(2 pi) dpT/dy
double perp_fourier[nedge_pseudorapidity - 1][nreduced_id][nfourier][2];
for (size_t k = 1; k < nedge_pseudorapidity; k++) {
for (size_t l = 0; l < nreduced_id; l++) {
for (size_t m = 0; m < nfourier; m++) {
for (size_t re_or_im = 0; re_or_im < 2;
re_or_im++) {
perp_fourier[k - 1][l][m][re_or_im] = 0;
}
}
}
}
memset(perp_fourier, 0,
(nedge_pseudorapidity - 1) * nreduced_id * nfourier * 2 *
sizeof(double));
for (Int_t j = 0; j < nPFpart; j++) {
size_t reduced_id = pf_id_reduce(pfId[j]);
for (size_t k = 1; k < nedge_pseudorapidity; k++) {
if (pfEta[j] >= edge_pseudorapidity[k - 1] &&
pfEta[j] < edge_pseudorapidity[k]) {
for (size_t l = 0; l < nfourier; l++) {
perp_fourier[k - 1][reduced_id][l][0] +=
pfPt[j] * cos(l * pfPhi[j]);
perp_fourier[k - 1][reduced_id][l][1] +=
pfPt[j] * sin(l * pfPhi[j]);
}
}
}
}
// Event selection
static const size_t nfeature = 2 * nfourier - 1;
double feature[nfeature];
// Scale factor to get 95% of the coefficient below 1.0
std::vector<double> scale(nfourier, 1.0 / 200.0);
if (nfourier >= 1) {
scale[0] = 1.0 / 5400.0;
}
if (nfourier >= 2) {
scale[1] = 1.0 / 130.0;
}
if (nfourier >= 3) {
scale[2] = 1.0 / 220.0;
}
feature[0] = 0;
for (size_t l = 0; l < nreduced_id; l++) {
feature[0] += scale[0] *
(perp_fourier[0 ][l][0][0] +
perp_fourier[nedge_pseudorapidity - 2][l][0][0]);
}
fprintf(stderr, "%s:%d: %f %f\n", __FILE__, __LINE__, feature[0], feature[0] / scale[0]);
for (size_t k = 1; k < nfourier; k++) {
feature[2 * k - 1] = 0;
for (size_t l = 0; l < nreduced_id; l++) {
feature[2 * k - 1] += scale[k] *
(perp_fourier[0 ][l][k][0] +
perp_fourier[nedge_pseudorapidity - 2][l][k][0]);
}
fprintf(stderr, "%s:%d: %f %f %f\n", __FILE__, __LINE__, perp_fourier[0 ][2][k][0], perp_fourier[nedge_pseudorapidity - 2][2][k][0], feature[2 * k - 1]);
feature[2 * k] = 0;
for (size_t l = 0; l < nreduced_id; l++) {
feature[2 * k] += scale[k] *
(perp_fourier[0 ][l][k][1] +
perp_fourier[nedge_pseudorapidity - 2][l][k][1]);
}
fprintf(stderr, "%s:%d: %f %f %f\n", __FILE__, __LINE__, perp_fourier[0 ][2][k][1], perp_fourier[nedge_pseudorapidity - 2][2][k][1], feature[2 * k]);
}
#if 0
const double event_plane = atan2(feature[4], feature[3]);
const double v2 =
sqrt(feature[3] * feature[3] +
feature[4] * feature[4]) / feature[0];
#endif
fprintf(stderr, "%s:%d: %f %f\n", __FILE__, __LINE__, hiBin * 0.5, sqrt(feature[3] * feature[3] +
feature[4] * feature[4]));
std::vector<double> particle_perp_subtracted;
std::vector<double> particle_perp_subtracted_unequalized;
for (Int_t k = 0; k < nPFpart; k++) {
int predictor_index = -1;
int interpolation_index = -1;
double density = 0;
if (pfEta[k] >= edge_pseudorapidity[0] &&
pfEta[k] < edge_pseudorapidity[nedge_pseudorapidity - 1]) {
std::vector<double>::const_iterator p = std::lower_bound(edge_pseudorapidity_v.begin(), edge_pseudorapidity_v.end(), pfEta[k]);
predictor_index = (p - edge_pseudorapidity_v.begin()) - 1;
}
for (size_t j = 0; j < nreduced_id; j++) {
if (j == 2) {
// HCAL
if (pfEta[k] >=
cms_hcal_edge_pseudorapidity[0] &&
pfEta[k] <
cms_hcal_edge_pseudorapidity[ncms_hcal_edge_pseudorapidity - 1]) {
std::vector<double>::const_iterator p = std::lower_bound(cms_hcal_edge_pseudorapidity_v.begin(), cms_hcal_edge_pseudorapidity_v.end(), pfEta[k]);
interpolation_index = (p - cms_hcal_edge_pseudorapidity_v.begin()) - 1;
}
}
else {
// Tracks or ECAL clusters
if (pfEta[k] >=
cms_ecal_edge_pseudorapidity[0] &&
pfEta[k] <
cms_ecal_edge_pseudorapidity[ncms_ecal_edge_pseudorapidity - 1]) {
std::vector<double>::const_iterator p = std::lower_bound(cms_ecal_edge_pseudorapidity_v.begin(), cms_ecal_edge_pseudorapidity_v.end(), pfEta[k]);
interpolation_index = (p - cms_ecal_edge_pseudorapidity_v.begin()) - 1;
}
}
if (predictor_index >= 0 && interpolation_index >= 0) {
// Calculate the aggregated prediction and
// interpolation for the pseudorapidity segment
const double azimuth = pfPhi[k];
const double (*p)[2][82] =
ue_predictor_pf[j][predictor_index];
double pred = 0;
for (size_t l = 0; l < nfourier; l++) {
for (size_t m = 0; m < 2; m++) {
float u = p[l][m][0];
for (size_t n = 0; n < 2 * nfourier - 1; n++) {
u += (((((((((p[l][m][9 * n + 9]) *
feature[n] +
p[l][m][9 * n + 8]) *
feature[n] +
p[l][m][9 * n + 7]) *
feature[n] +
p[l][m][9 * n + 6]) *
feature[n] +
p[l][m][9 * n + 5]) *
feature[n] +
p[l][m][9 * n + 4]) *
feature[n] +
p[l][m][9 * n + 3]) *
feature[n] +
p[l][m][9 * n + 2]) *
feature[n] +
p[l][m][9 * n + 1]) *
feature[n];
}
#if 0
// This looks at a specific flow component and see how the polynomial is evaluated
if (j == 0 && predictor_index == 3 && l == 0 && m == 0) {
//fprintf(stderr, "%s:%d: %f %f\n", __FILE__, __LINE__, perp_fourier[0][2][2][0], perp_fourier[nedge_pseudorapidity - 2][2][2][1]);
fprintf(stderr, "%s:%d: << %f %f %f %f %f %f %f\n", __FILE__, __LINE__, feature[0], feature[1], feature[2], feature[3], feature[4], u, perp_fourier[predictor_index][j][l][m]);
}
#endif
pred += u * (l == 0 ? 1.0 : 2.0) *
(m == 0 ? cos(l * azimuth) :
sin(l * azimuth));
}
}
double interp;
if (j == 0) {
interp =
ue_interpolation_pf0[predictor_index][
interpolation_index];
}
else if (j == 1) {
interp =
ue_interpolation_pf1[predictor_index][
interpolation_index];
}
else if (j == 2) {
interp =
ue_interpolation_pf2[predictor_index][
interpolation_index];
}
// Interpolate down to the finely binned
// pseudorapidity
density += pred /
(2.0 * M_PI *
(edge_pseudorapidity[predictor_index + 1] -
edge_pseudorapidity[predictor_index])) *
interp;
}
}
// Prints the subtracted density * area
fprintf(stderr, "%s:%d: %.8e %.8e %.8e %.8e %.8e\n", __FILE__, __LINE__, hiBin * 0.5, pfEta[k], pfPhi[k], pfPt[k], density * pfArea[k]);
}
}
f->Close();
gSystem->Exit(0);
}