/
CalibCorr.C
692 lines (652 loc) · 23.1 KB
/
CalibCorr.C
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
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
#include <algorithm>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#include <iostream>
#include <fstream>
#include <sstream>
#include <TROOT.h>
#include <TChain.h>
void unpackDetId(unsigned int detId, int& subdet, int& zside, int& ieta,
int& iphi, int& depth) {
// The maskings are defined in DataFormats/DetId/interface/DetId.h
// and in DataFormats/HcalDetId/interface/HcalDetId.h
// The macro does not invoke the classes there and use them
subdet = ((detId >> 25) & (0x7));
if ((detId&0x1000000) == 0) {
ieta = ((detId >> 7) & 0x3F);
zside = (detId&0x2000)?(1):(-1);
depth = ((detId >> 14) & 0x1F);
iphi = (detId & 0x3F);
} else {
ieta = ((detId >> 10) & 0x1FF);
zside = (detId&0x80000)?(1):(-1);
depth = ((detId >> 20) & 0xF);
iphi = (detId & 0x3FF);
}
}
unsigned int truncateId(unsigned int detId, int truncateFlag, bool debug=false){
//Truncate depth information of DetId's
unsigned int id(detId);
if (debug) {
std::cout << "Truncate 1 " << std::hex << detId << " " << id
<< std::dec << " Flag " << truncateFlag << std::endl;
}
int subdet, depth, zside, ieta, iphi;
unpackDetId(detId, subdet, zside, ieta, iphi, depth);
if (truncateFlag == 1) {
//Ignore depth index of ieta values of 15 and 16 of HB
if ((subdet == 1) && (ieta > 14)) depth = 1;
} else if (truncateFlag == 2) {
//Ignore depth index of all ieta values
depth = 1;
} else if (truncateFlag == 3) {
//Ignore depth index for depth > 1 in HE
if ((subdet == 2) && (depth > 1)) depth = 2;
else depth = 1;
} else if (truncateFlag == 4) {
//Ignore depth index for depth > 1 in HB
if ((subdet == 1) && (depth > 1)) depth = 2;
else depth = 1;
} else if (truncateFlag == 5) {
//Ignore depth index for depth > 1 in HB and HE
if (depth > 1) depth = 2;
}
id = (subdet<<25) | (0x1000000) | ((depth&0xF)<<20) | ((zside>0)?(0x80000|(ieta<<10)):(ieta<<10));
if (debug) {
std::cout << "Truncate 2: " << subdet << " " << zside*ieta << " "
<< depth << " " << std::hex << id << " input " << detId
<< std::dec << std::endl;
}
return id;
}
double puFactor(int type, int ieta, double pmom, double eHcal, double ediff,
bool debug=false) {
double fac(1.0);
if (debug) std::cout << "Input Type " << type << " ieta " << ieta
<< " pmon " << pmom << " E " << eHcal << ":" << ediff;
if (type <=2) {
double frac = (type == 1) ? 0.02 : 0.03;
if (pmom > 0 && ediff > frac*pmom) {
double a1(0), a2(0);
if (type == 1) {
a1 = -0.35; a2 = -0.65;
if (std::abs(ieta) == 25) {
a2 = -0.30;
} else if (std::abs(ieta) > 25) {
a1 = -0.45; a2 = -0.10;
}
} else {
a1 = -0.39; a2 = -0.59;
if (std::abs(ieta) >= 25) {
a1 = -0.283; a2 = -0.272;
} else if (std::abs(ieta) > 22) {
a1 = -0.238; a2 = -0.241;
}
}
fac = (1.0+a1*(eHcal/pmom)*(ediff/pmom)*(1+a2*(ediff/pmom)));
if (debug) std::cout << " coeff " << a1 << ":" << a2 << " Fac " << fac;
}
} else {
int jeta = std::abs(ieta);
double d2p = (ediff/pmom);
const double DELTA_CUT = 0.03;
const int PU_IETA_3 = 25;
if (type == 3) { // 16pu
const double CONST_COR_COEF[4] = { 0.971, 1.008, 0.985, 1.086 };
const double LINEAR_COR_COEF[4] = { 0, -0.359, -0.251, -0.535 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.048, 0.143 };
const int PU_IETA_1 = 9;
const int PU_IETA_2 = 16;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
if (debug) std::cout << " d2p " << d2p << ":" << DELTA_CUT << " coeff "
<< icor << ":" << CONST_COR_COEF[icor] << ":"
<< LINEAR_COR_COEF[icor] << ":"
<< SQUARE_COR_COEF[icor] << " Fac " << fac;
} else if (type == 4) { // 17pu
const double CONST_COR_COEF[4] = { 0.974, 1.023, 0.989, 1.077 };
const double LINEAR_COR_COEF[4] = { 0, -0.524, -0.268, -0.584 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.053, 0.170 };
const int PU_IETA_1 = 9;
const int PU_IETA_2 = 18;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
if (debug) std::cout << " d2p " << d2p << ":" << DELTA_CUT << " coeff "
<< icor << ":" << CONST_COR_COEF[icor] << ":"
<< LINEAR_COR_COEF[icor] << ":"
<< SQUARE_COR_COEF[icor] << " Fac " << fac;
} else { // 18pu
const double CONST_COR_COEF[4] = { 0.973, 0.998, 0.992, 0.965 };
const double LINEAR_COR_COEF[4] = { 0, -0.318, -0.261, -0.406 };
const double SQUARE_COR_COEF[4] = { 0, 0, 0.047, 0.089 };
const int PU_IETA_1 = 7;
const int PU_IETA_2 = 16;
unsigned icor = (unsigned(jeta >= PU_IETA_1) +
unsigned(jeta >= PU_IETA_2) +
unsigned(jeta >= PU_IETA_3));
if (d2p > DELTA_CUT) fac = (CONST_COR_COEF[icor] +
LINEAR_COR_COEF[icor]*d2p +
SQUARE_COR_COEF[icor]*d2p*d2p);
if (debug) std::cout << " d2p " << d2p << ":" << DELTA_CUT << " coeff "
<< icor << ":" << CONST_COR_COEF[icor] << ":"
<< LINEAR_COR_COEF[icor] << ":"
<< SQUARE_COR_COEF[icor] << " Fac " << fac;
}
}
if (fac < 0 || fac > 1) fac = 0;
if (debug) std::cout << " Final factor " << fac << std::endl;
return fac;
}
double puFactorRho(int type, int ieta, double rho, double eHcal) {
// type = 1: 2017 Data; 2: 2017 MC; 3: 2018 MC; 4: 2018AB; 5: 2018BC
// 6: 2016 MC;
double par[36] = {0.0205395,-43.0914,2.67115,0.239674,-0.0228009,0.000476963,
0.137566,-32.8386,3.25886,0.0863636,-0.0165639,0.000413894,
0.206168,-145.828,10.3191,0.531418,-0.0578416,0.00118905,
0.175356,-175.543,14.3414,0.294718,-0.049836,0.00106228,
0.134314,-175.809,13.5307,0.395943,-0.0539062,0.00111573,
0.145342,-98.1904,8.14001,0.205526,-0.0327818,0.000726059};
double energy(eHcal);
if (type >= 1 && type <= 6) {
int eta = std::abs(ieta);
int it = 6*(type-1);
double ea = (eta < 20) ? par[it] : ((((par[it+5]*eta+par[it+4])*eta+par[it+3])*eta+par[it+2])*eta+par[it+1]);
energy -= (rho*ea);
}
return energy;
}
double puweight(double vtx) { ///////for QCD PU sample
double a(1.0);
if (vtx < 11) a = 0.120593 ;
else if (vtx < 21) a = 0.58804;
else if (vtx < 31) a = 1.16306;
else if (vtx < 41) a = 1.45892;
else if (vtx < 51) a = 1.35528;
else if (vtx < 61) a = 1.72032;
else if (vtx < 71) a = 3.34812;
else if (vtx < 81) a = 9.70097;
else if (vtx < 91) a = 9.24839;
else if (vtx < 101) a = 23.0816;
return a;
}
bool fillChain(TChain *chain, const char* inputFileList) {
std::string fname(inputFileList);
if (fname.substr(fname.size()-5,5) == ".root") {
chain->Add(fname.c_str());
} else {
ifstream infile(inputFileList);
if (!infile.is_open()) {
std::cout << "** ERROR: Can't open '" << inputFileList << "' for input"
<< std::endl;
return false;
}
while (1) {
infile >> fname;
if (!infile.good()) break;
chain->Add(fname.c_str());
}
infile.close();
}
std::cout << "No. of Entries in this tree : " << chain->GetEntries()
<< std::endl;
return true;
}
std::vector<std::string> splitString (const std::string& fLine) {
std::vector <std::string> result;
int start = 0;
bool empty = true;
for (unsigned i = 0; i <= fLine.size (); i++) {
if (fLine [i] == ' ' || i == fLine.size ()) {
if (!empty) {
std::string item (fLine, start, i-start);
result.push_back (item);
empty = true;
}
start = i+1;
} else {
if (empty) empty = false;
}
}
return result;
}
class CalibCorrFactor {
public :
CalibCorrFactor(const char* infile, int useScale, double scale, bool etamax,
bool debug);
~CalibCorrFactor() {}
bool doCorr() const {return (corrE_ || (useScale_ != 0));}
double getCorr(unsigned int id);
private:
bool readCorrFactor(const char* fName);
double getFactor(const int& ieta);
const int useScale_;
const double scale_;
const bool etaMax_, debug_;
bool corrE_;
int etamp_, etamn_;
double cfacmp_, cfacmn_;
std::map<std::pair<int,int>,double> cfactors_;
};
class CalibCorr {
public :
CalibCorr(const char* infile, int flag, bool debug);
~CalibCorr() {}
float getCorr(int run, unsigned int id);
private:
void readCorrRun(const char* infile);
void readCorrDepth(const char* infile);
void readCorrResp(const char* infile);
unsigned int getDetIdHE(int ieta, int iphi, int depth);
unsigned int getDetId(int subdet, int ieta, int iphi, int depth);
unsigned int correctDetId(const unsigned int& detId);
static const unsigned int nmax_=10;
int flag_;
bool debug_;
std::map<unsigned int,float> corrFac_[nmax_], corrFacDepth_, corrFacResp_;
std::vector<int> runlow_;
};
class CalibSelectRBX {
public:
CalibSelectRBX(int rbx, bool debug=false);
~CalibSelectRBX() {}
bool isItRBX(const unsigned int);
bool isItRBX(const std::vector<unsigned int> *);
bool isItRBX(const int, const int);
private:
bool debug_;
int subdet_, zside_;
std::vector<int> phis_;
};
CalibCorrFactor::CalibCorrFactor(const char* infile, int useScale, double scale,
bool etamax, bool debug) :
useScale_(useScale), scale_(scale), etaMax_(etamax), debug_(debug),
etamp_(0), etamn_(0), cfacmp_(1), cfacmn_(1) {
if (std::string(infile) != "") {
corrE_ = readCorrFactor(infile);
std::cout << "Reads " << cfactors_.size() << " correction factors from "
<< infile << " with flag " << corrE_ << std::endl
<< "Flag for scale " << useScale_ << " with scale " << scale_
<< " and flag for etaMax " << etaMax_ << std::endl;
} else {
corrE_ = false;
std::cout << "No correction factors provided; Flag for scale "
<< useScale_ << " with scale " << scale_
<< " and flag for etaMax " << etaMax_ << std::endl;
}
}
double CalibCorrFactor::getCorr(unsigned int id) {
double cfac(1.0);
if (corrE_) {
int subdet,zside,ieta,iphi,depth;
unpackDetId(id,subdet,zside,ieta,iphi,depth);
std::map<std::pair<int,int>,double>::const_iterator
itr = cfactors_.find(std::pair<int,int>(zside*ieta,depth));
if (itr != cfactors_.end()) {
cfac = itr->second;
} else if (etaMax_) {
if (zside > 0 && ieta > etamp_) cfac = cfacmp_;
if (zside < 0 && ieta > -etamn_) cfac = cfacmn_;
}
} else if (useScale_ != 0) {
int subdet,zside,ieta,iphi,depth;
unpackDetId(id,subdet,zside,ieta,iphi,depth);
cfac = getFactor(ieta);
}
return cfac;
}
bool CalibCorrFactor::readCorrFactor(const char* fname) {
bool ok(false);
if (std::string(fname) != "") {
std::ifstream fInput(fname);
if (!fInput.good()) {
std::cout << "Cannot open file " << fname << std::endl;
} else {
char buffer [1024];
unsigned int all(0), good(0);
while (fInput.getline(buffer, 1024)) {
++all;
if (buffer [0] == '#') continue; //ignore comment
std::vector <std::string> items = splitString (std::string (buffer));
if (items.size () != 5) {
std::cout << "Ignore line: " << buffer << std::endl;
} else {
++good;
int ieta = std::atoi (items[1].c_str());
int depth = std::atoi (items[2].c_str());
float corrf = std::atof (items[3].c_str());
double scale = getFactor(std::abs(ieta));
cfactors_[std::pair<int,int>(ieta,depth)] = scale*corrf;
if (ieta > etamp_ && depth == 1) {
etamp_ = ieta; cfacmp_ = scale*corrf;
}
if (ieta < etamn_ && depth == 1) {
etamn_ = ieta; cfacmn_ = scale*corrf;
}
}
}
fInput.close();
std::cout << "Reads total of " << all << " and " << good
<< " good records" << " Max eta (z>0) " << etamp_ << ":"
<< cfacmp_ << " eta (z<0) " << etamn_ << ":" << cfacmn_
<< std::endl;
if (good > 0) ok = true;
}
}
return ok;
}
double CalibCorrFactor::getFactor(const int& ieta) {
double scale(1.0);
if (ieta < 16) {
if ((useScale_ == 1) || (useScale_ == 3)) scale = scale_;
} else {
if ((useScale_ == 2) || (useScale_ == 3)) scale = scale_;
}
return scale;
}
CalibCorr::CalibCorr(const char* infile, int flag, bool debug) :
flag_(flag), debug_(debug) {
std::cout << "CalibCorr is created with flag " << flag << ":" << flag_
<< " for i/p file " << infile << std::endl;
if (flag == 1) readCorrDepth(infile);
else if (flag == 2) readCorrResp(infile);
else readCorrRun(infile);
}
float CalibCorr::getCorr(int run, unsigned int id) {
float cfac(1.0);
unsigned idx = correctDetId(id);
if (flag_ == 1) {
std::map<unsigned int,float>::iterator itr = corrFacDepth_.find(idx);
if (itr != corrFacDepth_.end()) cfac = itr->second;
} else if (flag_ == 2) {
std::map<unsigned int,float>::iterator itr = corrFacResp_.find(idx);
if (itr != corrFacResp_.end()) cfac = itr->second;
} else {
int ip(-1);
for (unsigned int k=0; k<runlow_.size(); ++k) {
unsigned int i = runlow_.size()-k-1;
if (run >= runlow_[i]) {
ip = (int)(i); break;
}
}
if (debug_) {
std::cout << "Run " << run << " Perdiod " << ip << std::endl;
}
if (ip >= 0) {
std::map<unsigned int,float>::iterator itr = corrFac_[ip].find(idx);
if (itr != corrFac_[ip].end()) cfac = itr->second;
}
}
if (debug_) {
int subdet, zside, ieta, iphi, depth;
unpackDetId(idx, subdet, zside, ieta, iphi, depth);
std::cout << "ID " << std::hex << id << std::dec << " (Sub " << subdet
<< " eta " << zside*ieta << " phi " << iphi << " depth " << depth
<< ") Factor " << cfac << std::endl;
}
return cfac;
}
void CalibCorr::readCorrRun(const char* infile) {
std::cout << "Enters readCorrRun for " << infile << std::endl;
std::ifstream fInput(infile);
unsigned int ncorr(0);
if (!fInput.good()) {
std::cout << "Cannot open file " << infile << std::endl;
} else {
char buffer [1024];
unsigned int all(0), good(0);
while (fInput.getline(buffer, 1024)) {
++all;
std::string bufferString(buffer);
if (bufferString.substr(0,5) == "#IOVs") {
std::vector<std::string> items = splitString(bufferString.substr(6));
ncorr = items.size() - 1;
for (unsigned int n=0; n<ncorr; ++n) {
int run = std::atoi (items[n].c_str());
runlow_.push_back(run);
}
std::cout << ncorr << ":" << runlow_.size() << " Run ranges"
<< std::endl;
for (unsigned int n=0; n<runlow_.size(); ++n)
std::cout << " [" << n << "] " << runlow_[n];
std::cout << std::endl;
} else if (buffer [0] == '#') {
continue; //ignore other comments
} else {
std::vector<std::string> items = splitString(bufferString);
if (items.size () != ncorr+3) {
std::cout << "Ignore line: " << buffer << std::endl;
} else {
++good;
int ieta = std::atoi (items[0].c_str());
int iphi = std::atoi (items[1].c_str());
int depth = std::atoi (items[2].c_str());
unsigned int id = getDetIdHE(ieta,iphi,depth);
for (unsigned int n=0; n<ncorr; ++n) {
float corrf = std::atof (items[n+3].c_str());
if (n<nmax_) corrFac_[n][id] = corrf;
}
if (debug_) {
std::cout << "ID " << std::hex << id << std::dec << ":" << id
<< " (eta " << ieta << " phi " << iphi << " depth "
<< depth << ")";
for (unsigned int n=0; n<ncorr; ++n)
std::cout << " " << corrFac_[n][id];
std::cout << std::endl;
}
}
}
}
fInput.close();
std::cout << "Reads total of " << all << " and " << good
<< " good records of run dependent corrections from "
<< infile << std::endl;
}
}
void CalibCorr::readCorrDepth(const char* infile) {
std::cout << "Enters readCorrDepth for " << infile << std::endl;
std::ifstream fInput(infile);
if (!fInput.good()) {
std::cout << "Cannot open file " << infile << std::endl;
} else {
char buffer [1024];
unsigned int all(0), good(0);
while (fInput.getline(buffer, 1024)) {
++all;
std::string bufferString(buffer);
if (bufferString.substr(0,5) == "depth") {
continue; //ignore other comments
} else {
std::vector<std::string> items = splitString(bufferString);
if (items.size () != 3) {
std::cout << "Ignore line: " << buffer << " Size " << items.size();
for (unsigned int k=0; k<items.size(); ++k)
std::cout << " [" << k << "] : " << items[k];
std::cout << std::endl;
} else {
++good;
int ieta = std::atoi (items[1].c_str());
int depth = std::atoi (items[0].c_str());
float corrf = std::atof (items[2].c_str());
int nphi = (std::abs(ieta) > 20) ? 36 : 72;
for (int i=1; i<=nphi; ++i) {
int iphi = (nphi > 36) ? i : (2*i-1);
unsigned int id = getDetIdHE(ieta,iphi,depth);
corrFacDepth_[id] = corrf;
if (debug_) {
std::cout << "ID " << std::hex << id << std::dec << ":" << id
<< " (eta " << ieta << " phi " << iphi << " depth "
<< depth << ") " << corrFacDepth_[id] << std::endl;
}
}
}
}
}
fInput.close();
std::cout << "Reads total of " << all << " and " << good
<< " good records of depth dependent factors from " << infile
<< std::endl;
}
}
void CalibCorr::readCorrResp(const char* infile) {
std::cout << "Enters readCorrResp for " << infile << std::endl;
std::ifstream fInput(infile);
if (!fInput.good()) {
std::cout << "Cannot open file " << infile << std::endl;
} else {
char buffer [1024];
unsigned int all(0), good(0), other(0);
while (fInput.getline(buffer, 1024)) {
++all;
std::string bufferString(buffer);
if (bufferString.substr(0,1) == "#") {
continue; //ignore other comments
} else {
std::vector<std::string> items = splitString(bufferString);
if (items.size () < 5) {
std::cout << "Ignore line: " << buffer << " Size " << items.size();
for (unsigned int k=0; k<items.size(); ++k)
std::cout << " [" << k << "] : " << items[k];
std::cout << std::endl;
} else if (items[3] == "HB" || items[3] == "HE") {
++good;
int ieta = std::atoi (items[0].c_str());
int iphi = std::atoi (items[1].c_str());
int depth = std::atoi (items[2].c_str());
int subdet= (items[3] == "HE") ? 2 : 1;
float corrf = std::atof (items[4].c_str());
unsigned int id = getDetId(subdet,ieta,iphi,depth);
corrFacResp_[id] = corrf;
if (debug_) {
std::cout << "ID " << std::hex << id << std::dec << ":" << id
<< " (subdet " << items[3] << ":" << subdet << " eta "
<< ieta << " phi " << iphi << " depth " << depth
<< ") " << corrFacResp_[id] << std::endl;
}
} else {
++other;
}
}
}
fInput.close();
std::cout << "Reads total of " << all << " and " << good << " good and "
<< other << " detector records of depth dependent factors from "
<< infile << std::endl;
}
}
unsigned int CalibCorr::getDetIdHE(int ieta, int iphi, int depth) {
return getDetId(2,ieta,iphi,depth);
}
unsigned int CalibCorr::getDetId(int subdet, int ieta, int iphi, int depth) {
// All numbers used here are described as masks/offsets in
// DataFormats/HcalDetId/interface/HcalDetId.h
unsigned int id_ = ((4<<28)|((subdet&0x7)<<25));
id_ |= ((0x1000000) | ((depth&0xF)<<20) |
((ieta>0)?(0x80000|(ieta<<10)):((-ieta)<<10)) |
(iphi&0x3FF));
return id_;
}
unsigned int CalibCorr::correctDetId(const unsigned int & detId) {
int subdet, ieta, zside, depth, iphi;
unpackDetId(detId, subdet, zside, ieta, iphi, depth);
if (subdet == 0) {
if (ieta > 16) subdet = 2;
else if (ieta == 16 && depth > 2) subdet = 2;
else subdet = 1;
}
unsigned int id = getDetId(subdet,ieta*zside,iphi,depth);
if ((id != detId) && debug_) {
std::cout << "Correct Id " << std::hex << detId << " to " << id << std::dec
<< "(Sub " << subdet << " eta " << ieta*zside << " phi " << iphi
<< " depth " << depth << ")" << std::endl;
}
return id;
}
CalibSelectRBX::CalibSelectRBX(int rbx, bool debug) : debug_(debug) {
zside_ = (rbx > 0) ? 1 : -1;
subdet_ = (std::abs(rbx)/100)%10;
if (subdet_ != 1) subdet_ = 2;
int iphis = std::abs(rbx)%100;
if (iphis > 0 && iphis <= 18) {
for (int i=0; i<4; ++i) {
int iphi = (iphis-2)*4+3+i;
if (iphi < 1) iphi += 72;
phis_.push_back(iphi);
}
}
std::cout << "Select RBX " << rbx << " ==> Subdet " << subdet_ << " zside "
<< zside_ << " with " << phis_.size() << " iphi values:";
for (unsigned int i=0; i<phis_.size(); ++i) std::cout << " " << phis_[i];
std::cout << std::endl;
}
bool CalibSelectRBX::isItRBX(const unsigned int detId) {
bool ok(true);
if (phis_.size() == 4) {
int subdet, ieta, zside, depth, iphi;
unpackDetId(detId, subdet, zside, ieta, iphi, depth);
ok = ((subdet == subdet_) && (zside == zside_) &&
(std::find(phis_.begin(),phis_.end(),iphi) != phis_.end()));
if (debug_) {
std::cout << "isItRBX:subdet|zside|iphi " << subdet << ":" << zside
<< ":" << iphi << " OK " << ok << std::endl;
}
}
return ok;
}
bool CalibSelectRBX::isItRBX(const std::vector<unsigned int> * detId) {
bool ok(true);
if (phis_.size() == 4) {
ok = true;
for (unsigned int i=0; i < detId->size(); ++i) {
int subdet, ieta, zside, depth, iphi;
unpackDetId((*detId)[i], subdet, zside, ieta, iphi, depth);
ok = ((subdet == subdet_) && (zside == zside_) &&
(std::find(phis_.begin(),phis_.end(),iphi) != phis_.end()));
if (debug_) {
std::cout << "isItRBX: subdet|zside|iphi " << subdet << ":" << zside
<< ":" << iphi << std::endl;
}
if (ok) break;
}
}
if (debug_) std::cout << "isItRBX: size " << detId->size() << " OK " << ok
<< std::endl;
return ok;
}
bool CalibSelectRBX::isItRBX(const int ieta, const int iphi) {
bool ok(true);
if (phis_.size() == 4) {
int zside = (ieta > 0) ? 1 : -1;
int subd1 = (std::abs(ieta) <= 16) ? 1 : 2;
int subd2 = (std::abs(ieta) >= 16) ? 2 : 1;
ok = (((subd1 == subdet_) || (subd2 == subdet_)) &&
(zside == zside_) &&
(std::find(phis_.begin(),phis_.end(),iphi) != phis_.end()));
}
if (debug_) {
std::cout << "isItRBX: ieta " << ieta << " iphi " << iphi << " OK " << ok
<< std::endl;
}
return ok;
}
void CalibCorrTest(const char* infile, int flag) {
CalibCorr* c1 = new CalibCorr(infile, flag, true);
for (int ieta = 1; ieta < 29; ++ieta) {
int subdet = (ieta > 16) ? 2 : 1;
int depth = (ieta > 16) ? 2 : 1;
unsigned int id1 = ((4<<28)|((subdet&0x7)<<25));
id1 |= ((0x1000000) | ((depth&0xF)<<20) | (ieta<<10) | 1);
c1->getCorr(0, id1);
id1 |= (0x80000);
c1->getCorr(0, id1);
}
}