ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/UserCode/MitPhysics/Utils/src/ElectronEnergyRegression.cc
Revision: 1.2
Committed: Fri Dec 14 14:17:30 2012 UTC (12 years, 4 months ago) by sixie
Content type: text/plain
Branch: MAIN
CVS Tags: Mit_029c, Mit_029b, Mit_029a, HEAD
Changes since 1.1: +358 -310 lines
Log Message:
update for new versions of regression with track variables

File Contents

# Content
1 #include "MitPhysics/Utils/interface/ElectronEnergyRegression.h"
2 #include <cmath>
3 #include <cassert>
4 #include <iostream>
5
6 ClassImp(mithep::ElectronEnergyRegression)
7
8 using namespace mithep;
9
10
11 ElectronEnergyRegression::ElectronEnergyRegression() :
12 fIsInitialized(kFALSE),
13 fVersionType(kNoTrkVar),
14 forestCorrection_eb(0),
15 forestCorrection_ee(0),
16 forestUncertainty_eb(0),
17 forestUncertainty_ee(0) {
18 }
19
20 ElectronEnergyRegression::~ElectronEnergyRegression() {}
21 // Destructor does nothing
22
23
24 void ElectronEnergyRegression::initialize(std::string weightsFile,
25 ElectronEnergyRegression::ElectronEnergyRegressionType type) {
26
27 // Loading forest object according to different versions
28 TFile file(weightsFile.c_str());
29
30 if (type == kNoTrkVar || type == kWithTrkVarV1 || type == kWithTrkVarV2) {
31 forestCorrection_eb = (GBRForest*) file.Get("EBCorrection");
32 forestCorrection_ee = (GBRForest*) file.Get("EECorrection");
33 forestUncertainty_eb = (GBRForest*) file.Get("EBUncertainty");
34 forestUncertainty_ee = (GBRForest*) file.Get("EEUncertainty");
35
36 // Just checking
37 assert(forestCorrection_eb);
38 assert(forestCorrection_ee);
39 assert(forestUncertainty_eb);
40 assert(forestUncertainty_ee);
41 }
42
43 // Updating type and marking as initialized
44 fVersionType = type;
45 fIsInitialized = kTRUE;
46 }
47
48
49 double ElectronEnergyRegression::regressionValueNoTrkVar(
50 double SCRawEnergy,
51 double scEta,
52 double scPhi,
53 double R9,
54 double etawidth,
55 double phiwidth,
56 double NClusters,
57 double HoE,
58 double rho,
59 double vertices,
60 double EtaSeed,
61 double PhiSeed,
62 double ESeed,
63 double E3x3Seed,
64 double E5x5Seed,
65 double see,
66 double spp,
67 double sep,
68 double EMaxSeed,
69 double E2ndSeed,
70 double ETopSeed,
71 double EBottomSeed,
72 double ELeftSeed,
73 double ERightSeed,
74 double E2x5MaxSeed,
75 double E2x5TopSeed,
76 double E2x5BottomSeed,
77 double E2x5LeftSeed,
78 double E2x5RightSeed,
79 double IEtaSeed,
80 double IPhiSeed,
81 double EtaCrySeed,
82 double PhiCrySeed,
83 double PreShowerOverRaw,
84 bool printDebug)
85 {
86 // Checking if instance has been initialized
87 if (fIsInitialized == kFALSE) {
88 printf("ElectronEnergyRegression instance not initialized !!!");
89 return 0;
90 }
91
92 // Checking if type is correct
93 if (!(fVersionType == kNoTrkVar)) {
94 std::cout << "Error: Regression VersionType " << fVersionType << " is not supported to use function regressionValueNoTrkVar.\n";
95 return 0;
96 }
97
98 // Now applying regression according to version and (endcap/barrel)
99 float *vals = (fabs(scEta) <= 1.479) ? new float[38] : new float[31];
100 if (fabs(scEta) <= 1.479) { // Barrel
101 vals[0] = SCRawEnergy;
102 vals[1] = scEta;
103 vals[2] = scPhi;
104 vals[3] = R9;
105 vals[4] = E5x5Seed/SCRawEnergy;
106 vals[5] = etawidth;
107 vals[6] = phiwidth;
108 vals[7] = NClusters;
109 vals[8] = HoE;
110 vals[9] = rho;
111 vals[10] = vertices;
112 vals[11] = EtaSeed - scEta;
113 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
114 vals[13] = ESeed/SCRawEnergy;
115 vals[14] = E3x3Seed/ESeed;
116 vals[15] = E5x5Seed/ESeed;
117 vals[16] = see;
118 vals[17] = spp;
119 vals[18] = sep;
120 vals[19] = EMaxSeed/ESeed;
121 vals[20] = E2ndSeed/ESeed;
122 vals[21] = ETopSeed/ESeed;
123 vals[22] = EBottomSeed/ESeed;
124 vals[23] = ELeftSeed/ESeed;
125 vals[24] = ERightSeed/ESeed;
126 vals[25] = E2x5MaxSeed/ESeed;
127 vals[26] = E2x5TopSeed/ESeed;
128 vals[27] = E2x5BottomSeed/ESeed;
129 vals[28] = E2x5LeftSeed/ESeed;
130 vals[29] = E2x5RightSeed/ESeed;
131 vals[30] = IEtaSeed;
132 vals[31] = IPhiSeed;
133 vals[32] = ((int) IEtaSeed)%5;
134 vals[33] = ((int) IPhiSeed)%2;
135 vals[34] = (abs(IEtaSeed)<=25)*(((int)IEtaSeed)%25) + (abs(IEtaSeed)>25)*(((int) (IEtaSeed-25*abs(IEtaSeed)/IEtaSeed))%20);
136 vals[35] = ((int) IPhiSeed)%20;
137 vals[36] = EtaCrySeed;
138 vals[37] = PhiCrySeed;
139 }
140 else { // Endcap
141 vals[0] = SCRawEnergy;
142 vals[1] = scEta;
143 vals[2] = scPhi;
144 vals[3] = R9;
145 vals[4] = E5x5Seed/SCRawEnergy;
146 vals[5] = etawidth;
147 vals[6] = phiwidth;
148 vals[7] = NClusters;
149 vals[8] = HoE;
150 vals[9] = rho;
151 vals[10] = vertices;
152 vals[11] = EtaSeed - scEta;
153 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
154 vals[13] = ESeed/SCRawEnergy;
155 vals[14] = E3x3Seed/ESeed;
156 vals[15] = E5x5Seed/ESeed;
157 vals[16] = see;
158 vals[17] = spp;
159 vals[18] = sep;
160 vals[19] = EMaxSeed/ESeed;
161 vals[20] = E2ndSeed/ESeed;
162 vals[21] = ETopSeed/ESeed;
163 vals[22] = EBottomSeed/ESeed;
164 vals[23] = ELeftSeed/ESeed;
165 vals[24] = ERightSeed/ESeed;
166 vals[25] = E2x5MaxSeed/ESeed;
167 vals[26] = E2x5TopSeed/ESeed;
168 vals[27] = E2x5BottomSeed/ESeed;
169 vals[28] = E2x5LeftSeed/ESeed;
170 vals[29] = E2x5RightSeed/ESeed;
171 vals[30] = PreShowerOverRaw;
172 }
173
174 // Now evaluating the regression
175 double regressionResult = 0;
176 Int_t BinIndex = -1;
177
178 if (fVersionType == kNoTrkVar) {
179 if (fabs(scEta) <= 1.479) {
180 regressionResult = SCRawEnergy * forestCorrection_eb->GetResponse(vals);
181 BinIndex = 0;
182 }
183 else {
184 regressionResult = (SCRawEnergy*(1+PreShowerOverRaw)) * forestCorrection_ee->GetResponse(vals);
185 BinIndex = 1;
186 }
187 }
188
189 //print debug
190 if (printDebug) {
191 if ( fabs(scEta) <= 1.479) {
192 std::cout << "Barrel :";
193 for (uint v=0; v < 38; ++v) std::cout << vals[v] << ", ";
194 std::cout << "\n";
195 }
196 else {
197 std::cout << "Endcap :";
198 for (uint v=0; v < 32; ++v) std::cout << vals[v] << ", ";
199 std::cout << "\n";
200 }
201 std::cout << "BinIndex : " << BinIndex << "\n";
202 std::cout << "SCRawEnergy = " << SCRawEnergy << " : PreShowerOverRaw = " << PreShowerOverRaw << std::endl;
203 std::cout << "regression energy = " << regressionResult << std::endl;
204 }
205
206
207 // Cleaning up and returning
208 delete[] vals;
209 return regressionResult;
210 }
211
212 double ElectronEnergyRegression::regressionUncertaintyNoTrkVar(
213 double SCRawEnergy,
214 double scEta,
215 double scPhi,
216 double R9,
217 double etawidth,
218 double phiwidth,
219 double NClusters,
220 double HoE,
221 double rho,
222 double vertices,
223 double EtaSeed,
224 double PhiSeed,
225 double ESeed,
226 double E3x3Seed,
227 double E5x5Seed,
228 double see,
229 double spp,
230 double sep,
231 double EMaxSeed,
232 double E2ndSeed,
233 double ETopSeed,
234 double EBottomSeed,
235 double ELeftSeed,
236 double ERightSeed,
237 double E2x5MaxSeed,
238 double E2x5TopSeed,
239 double E2x5BottomSeed,
240 double E2x5LeftSeed,
241 double E2x5RightSeed,
242 double IEtaSeed,
243 double IPhiSeed,
244 double EtaCrySeed,
245 double PhiCrySeed,
246 double PreShowerOverRaw,
247 bool printDebug)
248 {
249 // Checking if instance has been initialized
250 if (fIsInitialized == kFALSE) {
251 printf("ElectronEnergyRegression instance not initialized !!!");
252 return 0;
253 }
254
255 // Checking if type is correct
256 if (!(fVersionType == kNoTrkVar)) {
257 std::cout << "Error: Regression VersionType " << fVersionType << " is not supported to use function regressionValueNoTrkVar.\n";
258 return 0;
259 }
260
261 // Now applying regression according to version and (endcap/barrel)
262 float *vals = (fabs(scEta) <= 1.479) ? new float[38] : new float[31];
263 if (fabs(scEta) <= 1.479) { // Barrel
264 vals[0] = SCRawEnergy;
265 vals[1] = scEta;
266 vals[2] = scPhi;
267 vals[3] = R9;
268 vals[4] = E5x5Seed/SCRawEnergy;
269 vals[5] = etawidth;
270 vals[6] = phiwidth;
271 vals[7] = NClusters;
272 vals[8] = HoE;
273 vals[9] = rho;
274 vals[10] = vertices;
275 vals[11] = EtaSeed - scEta;
276 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
277 vals[13] = ESeed/SCRawEnergy;
278 vals[14] = E3x3Seed/ESeed;
279 vals[15] = E5x5Seed/ESeed;
280 vals[16] = see;
281 vals[17] = spp;
282 vals[18] = sep;
283 vals[19] = EMaxSeed/ESeed;
284 vals[20] = E2ndSeed/ESeed;
285 vals[21] = ETopSeed/ESeed;
286 vals[22] = EBottomSeed/ESeed;
287 vals[23] = ELeftSeed/ESeed;
288 vals[24] = ERightSeed/ESeed;
289 vals[25] = E2x5MaxSeed/ESeed;
290 vals[26] = E2x5TopSeed/ESeed;
291 vals[27] = E2x5BottomSeed/ESeed;
292 vals[28] = E2x5LeftSeed/ESeed;
293 vals[29] = E2x5RightSeed/ESeed;
294 vals[30] = IEtaSeed;
295 vals[31] = IPhiSeed;
296 vals[32] = ((int) IEtaSeed)%5;
297 vals[33] = ((int) IPhiSeed)%2;
298 vals[34] = (abs(IEtaSeed)<=25)*(((int)IEtaSeed)%25) + (abs(IEtaSeed)>25)*(((int) (IEtaSeed-25*abs(IEtaSeed)/IEtaSeed))%20);
299 vals[35] = ((int) IPhiSeed)%20;
300 vals[36] = EtaCrySeed;
301 vals[37] = PhiCrySeed;
302 }
303 else { // Endcap
304 vals[0] = SCRawEnergy;
305 vals[1] = scEta;
306 vals[2] = scPhi;
307 vals[3] = R9;
308 vals[4] = E5x5Seed/SCRawEnergy;
309 vals[5] = etawidth;
310 vals[6] = phiwidth;
311 vals[7] = NClusters;
312 vals[8] = HoE;
313 vals[9] = rho;
314 vals[10] = vertices;
315 vals[11] = EtaSeed - scEta;
316 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
317 vals[13] = ESeed/SCRawEnergy;
318 vals[14] = E3x3Seed/ESeed;
319 vals[15] = E5x5Seed/ESeed;
320 vals[16] = see;
321 vals[17] = spp;
322 vals[18] = sep;
323 vals[19] = EMaxSeed/ESeed;
324 vals[20] = E2ndSeed/ESeed;
325 vals[21] = ETopSeed/ESeed;
326 vals[22] = EBottomSeed/ESeed;
327 vals[23] = ELeftSeed/ESeed;
328 vals[24] = ERightSeed/ESeed;
329 vals[25] = E2x5MaxSeed/ESeed;
330 vals[26] = E2x5TopSeed/ESeed;
331 vals[27] = E2x5BottomSeed/ESeed;
332 vals[28] = E2x5LeftSeed/ESeed;
333 vals[29] = E2x5RightSeed/ESeed;
334 vals[30] = PreShowerOverRaw;
335 }
336
337 // Now evaluating the regression
338 double regressionResult = 0;
339 Int_t BinIndex = -1;
340
341 if (fVersionType == kNoTrkVar) {
342 if (fabs(scEta) <= 1.479) {
343 regressionResult = SCRawEnergy * forestUncertainty_eb->GetResponse(vals);
344 BinIndex = 0;
345 }
346 else {
347 regressionResult = (SCRawEnergy*(1+PreShowerOverRaw)) * forestUncertainty_ee->GetResponse(vals);
348 BinIndex = 1;
349 }
350 }
351
352 //print debug
353 if (printDebug) {
354 if (fabs(scEta) <= 1.479) {
355 std::cout << "Barrel :";
356 for (uint v=0; v < 38; ++v) std::cout << vals[v] << ", ";
357 std::cout << "\n";
358 }
359 else {
360 std::cout << "Endcap :";
361 for (uint v=0; v < 32; ++v) std::cout << vals[v] << ", ";
362 std::cout << "\n";
363 }
364 std::cout << "BinIndex : " << BinIndex << "\n";
365 std::cout << "SCRawEnergy = " << SCRawEnergy << " : PreShowerOverRaw = " << PreShowerOverRaw << std::endl;
366 std::cout << "regression energy uncertainty = " << regressionResult << std::endl;
367 }
368
369
370 // Cleaning up and returning
371 delete[] vals;
372 return regressionResult;
373 }
374
375 double ElectronEnergyRegression::regressionValueWithTrkVarV1( std::vector<double> &inputvars,
376 bool printDebug)
377 {
378 // Checking if instance has been initialized
379 if (fIsInitialized == kFALSE) {
380 printf("ElectronEnergyRegression instance not initialized !!!");
381 return 0;
382 }
383
384 // Checking if fVersionType is correct
385 assert(fVersionType == kWithTrkVarV1);
386
387 //Check that inputvars vector has the right number of inputs
388 assert(inputvars.size() == 42);
389
390 //assign variables from inputvars array to named variables
391 double SCRawEnergy = inputvars[0];
392 double scEta = inputvars[1];
393 double scPhi = inputvars[2];
394 double R9 = inputvars[3];
395 double etawidth = inputvars[4];
396 double phiwidth = inputvars[5];
397 double NClusters = inputvars[6];
398 double HoE = inputvars[7];
399 double rho = inputvars[8];
400 double vertices = inputvars[9];
401 double EtaSeed = inputvars[10];
402 double PhiSeed = inputvars[11];
403 double ESeed = inputvars[12];
404 double E3x3Seed = inputvars[13];
405 double E5x5Seed = inputvars[14];
406 double see = inputvars[15];
407 double spp = inputvars[16];
408 double sep = inputvars[17];
409 double EMaxSeed = inputvars[18];
410 double E2ndSeed = inputvars[19];
411 double ETopSeed = inputvars[20];
412 double EBottomSeed = inputvars[21];
413 double ELeftSeed = inputvars[22];
414 double ERightSeed = inputvars[23];
415 double E2x5MaxSeed = inputvars[24];
416 double E2x5TopSeed = inputvars[25];
417 double E2x5BottomSeed = inputvars[26];
418 double E2x5LeftSeed = inputvars[27];
419 double E2x5RightSeed = inputvars[28];
420 double IEtaSeed = inputvars[29];
421 double IPhiSeed = inputvars[30];
422 double EtaCrySeed = inputvars[31];
423 double PhiCrySeed = inputvars[32];
424 double PreShowerOverRaw = inputvars[33];
425 int IsEcalDriven = inputvars[34];
426 double GsfTrackPIn = inputvars[35];
427 double fbrem = inputvars[36];
428 double Charge = inputvars[37];
429 double EoP = inputvars[38];
430 double TrackMomentumError = inputvars[39];
431 double EcalEnergyError = inputvars[40];
432 int Classification = inputvars[41];
433
434 float *vals = (fabs(scEta) <= 1.479) ? new float[46] : new float[39];
435 if (fabs(scEta) <= 1.479) { // Barrel
436 vals[0] = SCRawEnergy;
437 vals[1] = scEta;
438 vals[2] = scPhi;
439 vals[3] = R9;
440 vals[4] = E5x5Seed/SCRawEnergy;
441 vals[5] = etawidth;
442 vals[6] = phiwidth;
443 vals[7] = NClusters;
444 vals[8] = HoE;
445 vals[9] = rho;
446 vals[10] = vertices;
447 vals[11] = EtaSeed - scEta;
448 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
449 vals[13] = ESeed/SCRawEnergy;
450 vals[14] = E3x3Seed/ESeed;
451 vals[15] = E5x5Seed/ESeed;
452 vals[16] = see;
453 vals[17] = spp;
454 vals[18] = sep;
455 vals[19] = EMaxSeed/ESeed;
456 vals[20] = E2ndSeed/ESeed;
457 vals[21] = ETopSeed/ESeed;
458 vals[22] = EBottomSeed/ESeed;
459 vals[23] = ELeftSeed/ESeed;
460 vals[24] = ERightSeed/ESeed;
461 vals[25] = E2x5MaxSeed/ESeed;
462 vals[26] = E2x5TopSeed/ESeed;
463 vals[27] = E2x5BottomSeed/ESeed;
464 vals[28] = E2x5LeftSeed/ESeed;
465 vals[29] = E2x5RightSeed/ESeed;
466 vals[30] = IsEcalDriven;
467 vals[31] = GsfTrackPIn;
468 vals[32] = fbrem;
469 vals[33] = Charge;
470 vals[34] = EoP;
471 vals[35] = TrackMomentumError/GsfTrackPIn;
472 vals[36] = EcalEnergyError/SCRawEnergy;
473 vals[37] = Classification;
474 vals[38] = IEtaSeed;
475 vals[39] = IPhiSeed;
476 vals[40] = ((int) IEtaSeed)%5;
477 vals[41] = ((int) IPhiSeed)%2;
478 vals[42] = (abs(IEtaSeed)<=25)*(((int)IEtaSeed)%25) + (abs(IEtaSeed)>25)*(((int) (IEtaSeed-25*abs(IEtaSeed)/IEtaSeed))%20);
479 vals[43] = ((int) IPhiSeed)%20;
480 vals[44] = EtaCrySeed;
481 vals[45] = PhiCrySeed;
482 }
483
484 else { // Endcap
485 vals[0] = SCRawEnergy;
486 vals[1] = scEta;
487 vals[2] = scPhi;
488 vals[3] = R9;
489 vals[4] = E5x5Seed/SCRawEnergy;
490 vals[5] = etawidth;
491 vals[6] = phiwidth;
492 vals[7] = NClusters;
493 vals[8] = HoE;
494 vals[9] = rho;
495 vals[10] = vertices;
496 vals[11] = EtaSeed - scEta;
497 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
498 vals[13] = ESeed/SCRawEnergy;
499 vals[14] = E3x3Seed/ESeed;
500 vals[15] = E5x5Seed/ESeed;
501 vals[16] = see;
502 vals[17] = spp;
503 vals[18] = sep;
504 vals[19] = EMaxSeed/ESeed;
505 vals[20] = E2ndSeed/ESeed;
506 vals[21] = ETopSeed/ESeed;
507 vals[22] = EBottomSeed/ESeed;
508 vals[23] = ELeftSeed/ESeed;
509 vals[24] = ERightSeed/ESeed;
510 vals[25] = E2x5MaxSeed/ESeed;
511 vals[26] = E2x5TopSeed/ESeed;
512 vals[27] = E2x5BottomSeed/ESeed;
513 vals[28] = E2x5LeftSeed/ESeed;
514 vals[29] = E2x5RightSeed/ESeed;
515 vals[30] = IsEcalDriven;
516 vals[31] = GsfTrackPIn;
517 vals[32] = fbrem;
518 vals[33] = Charge;
519 vals[34] = EoP;
520 vals[35] = TrackMomentumError/GsfTrackPIn;
521 vals[36] = EcalEnergyError/SCRawEnergy;
522 vals[37] = Classification;
523 vals[38] = PreShowerOverRaw;
524 }
525
526 // Now evaluating the regression
527 double regressionResult = 0;
528
529 if (fVersionType == kWithTrkVarV1) {
530 if (fabs(scEta) <= 1.479) regressionResult = SCRawEnergy * forestCorrection_eb->GetResponse(vals);
531 else regressionResult = (SCRawEnergy*(1+PreShowerOverRaw)) * forestCorrection_ee->GetResponse(vals);
532 }
533
534
535 //print debug
536 if (printDebug) {
537 if (fabs(scEta) <= 1.479) {
538 std::cout << "Barrel :";
539 for (uint v=0; v < 46; ++v) std::cout << vals[v] << ", ";
540 std::cout << "\n";
541 }
542 else {
543 std::cout << "Endcap :";
544 for (uint v=0; v < 39; ++v) std::cout << vals[v] << ", ";
545 std::cout << "\n";
546 }
547 std::cout << "SCRawEnergy = " << SCRawEnergy << " : PreShowerOverRaw = " << PreShowerOverRaw << std::endl;
548 std::cout << "regression energy = " << regressionResult << std::endl;
549 }
550
551 // Cleaning up and returning
552 delete[] vals;
553 return regressionResult;
554 }
555
556
557
558
559
560 double ElectronEnergyRegression::regressionUncertaintyWithTrkVarV1( std::vector<double> &inputvars,
561 bool printDebug)
562 {
563 // Checking if instance has been initialized
564 if (fIsInitialized == kFALSE) {
565 printf("ElectronEnergyRegression instance not initialized !!!");
566 return 0;
567 }
568
569 // Checking if fVersionType is correct
570 assert(fVersionType == kWithTrkVarV1);
571
572 // Checking if fVersionType is correct
573 assert(inputvars.size() == 42);
574
575 double SCRawEnergy = inputvars[0];
576 double scEta = inputvars[1];
577 double scPhi = inputvars[2];
578 double R9 = inputvars[3];
579 double etawidth = inputvars[4];
580 double phiwidth = inputvars[5];
581 double NClusters = inputvars[6];
582 double HoE = inputvars[7];
583 double rho = inputvars[8];
584 double vertices = inputvars[9];
585 double EtaSeed = inputvars[10];
586 double PhiSeed = inputvars[11];
587 double ESeed = inputvars[12];
588 double E3x3Seed = inputvars[13];
589 double E5x5Seed = inputvars[14];
590 double see = inputvars[15];
591 double spp = inputvars[16];
592 double sep = inputvars[17];
593 double EMaxSeed = inputvars[18];
594 double E2ndSeed = inputvars[19];
595 double ETopSeed = inputvars[20];
596 double EBottomSeed = inputvars[21];
597 double ELeftSeed = inputvars[22];
598 double ERightSeed = inputvars[23];
599 double E2x5MaxSeed = inputvars[24];
600 double E2x5TopSeed = inputvars[25];
601 double E2x5BottomSeed = inputvars[26];
602 double E2x5LeftSeed = inputvars[27];
603 double E2x5RightSeed = inputvars[28];
604 double IEtaSeed = inputvars[29];
605 double IPhiSeed = inputvars[30];
606 double EtaCrySeed = inputvars[31];
607 double PhiCrySeed = inputvars[32];
608 double PreShowerOverRaw = inputvars[33];
609 int IsEcalDriven = inputvars[34];
610 double GsfTrackPIn = inputvars[35];
611 double fbrem = inputvars[36];
612 double Charge = inputvars[37];
613 double EoP = inputvars[38];
614 double TrackMomentumError = inputvars[39];
615 double EcalEnergyError = inputvars[40];
616 int Classification = inputvars[41];
617
618
619 float *vals = (fabs(scEta) <= 1.479) ? new float[46] : new float[39];
620 if (fabs(scEta) <= 1.479) { // Barrel
621 vals[0] = SCRawEnergy;
622 vals[1] = scEta;
623 vals[2] = scPhi;
624 vals[3] = R9;
625 vals[4] = E5x5Seed/SCRawEnergy;
626 vals[5] = etawidth;
627 vals[6] = phiwidth;
628 vals[7] = NClusters;
629 vals[8] = HoE;
630 vals[9] = rho;
631 vals[10] = vertices;
632 vals[11] = EtaSeed - scEta;
633 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
634 vals[13] = ESeed/SCRawEnergy;
635 vals[14] = E3x3Seed/ESeed;
636 vals[15] = E5x5Seed/ESeed;
637 vals[16] = see;
638 vals[17] = spp;
639 vals[18] = sep;
640 vals[19] = EMaxSeed/ESeed;
641 vals[20] = E2ndSeed/ESeed;
642 vals[21] = ETopSeed/ESeed;
643 vals[22] = EBottomSeed/ESeed;
644 vals[23] = ELeftSeed/ESeed;
645 vals[24] = ERightSeed/ESeed;
646 vals[25] = E2x5MaxSeed/ESeed;
647 vals[26] = E2x5TopSeed/ESeed;
648 vals[27] = E2x5BottomSeed/ESeed;
649 vals[28] = E2x5LeftSeed/ESeed;
650 vals[29] = E2x5RightSeed/ESeed;
651 vals[30] = IsEcalDriven;
652 vals[31] = GsfTrackPIn;
653 vals[32] = fbrem;
654 vals[33] = Charge;
655 vals[34] = EoP;
656 vals[35] = TrackMomentumError/GsfTrackPIn;
657 vals[36] = EcalEnergyError/SCRawEnergy;
658 vals[37] = Classification;
659 vals[38] = IEtaSeed;
660 vals[39] = IPhiSeed;
661 vals[40] = ((int) IEtaSeed)%5;
662 vals[41] = ((int) IPhiSeed)%2;
663 vals[42] = (abs(IEtaSeed)<=25)*(((int)IEtaSeed)%25) + (abs(IEtaSeed)>25)*(((int) (IEtaSeed-25*abs(IEtaSeed)/IEtaSeed))%20);
664 vals[43] = ((int) IPhiSeed)%20;
665 vals[44] = EtaCrySeed;
666 vals[45] = PhiCrySeed;
667 }
668
669 else { // Endcap
670 vals[0] = SCRawEnergy;
671 vals[1] = scEta;
672 vals[2] = scPhi;
673 vals[3] = R9;
674 vals[4] = E5x5Seed/SCRawEnergy;
675 vals[5] = etawidth;
676 vals[6] = phiwidth;
677 vals[7] = NClusters;
678 vals[8] = HoE;
679 vals[9] = rho;
680 vals[10] = vertices;
681 vals[11] = EtaSeed - scEta;
682 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
683 vals[13] = ESeed/SCRawEnergy;
684 vals[14] = E3x3Seed/ESeed;
685 vals[15] = E5x5Seed/ESeed;
686 vals[16] = see;
687 vals[17] = spp;
688 vals[18] = sep;
689 vals[19] = EMaxSeed/ESeed;
690 vals[20] = E2ndSeed/ESeed;
691 vals[21] = ETopSeed/ESeed;
692 vals[22] = EBottomSeed/ESeed;
693 vals[23] = ELeftSeed/ESeed;
694 vals[24] = ERightSeed/ESeed;
695 vals[25] = E2x5MaxSeed/ESeed;
696 vals[26] = E2x5TopSeed/ESeed;
697 vals[27] = E2x5BottomSeed/ESeed;
698 vals[28] = E2x5LeftSeed/ESeed;
699 vals[29] = E2x5RightSeed/ESeed;
700 vals[30] = IsEcalDriven;
701 vals[31] = GsfTrackPIn;
702 vals[32] = fbrem;
703 vals[33] = Charge;
704 vals[34] = EoP;
705 vals[35] = TrackMomentumError/GsfTrackPIn;
706 vals[36] = EcalEnergyError/SCRawEnergy;
707 vals[37] = Classification;
708 vals[38] = PreShowerOverRaw;
709 }
710
711 // Now evaluating the regression
712 double regressionResult = 0;
713
714 if (fVersionType == kWithTrkVarV1) {
715 if (fabs(scEta) <= 1.479) regressionResult = SCRawEnergy * forestUncertainty_eb->GetResponse(vals);
716 else regressionResult = (SCRawEnergy*(1+PreShowerOverRaw)) * forestUncertainty_ee->GetResponse(vals);
717 }
718
719 //print debug
720 if (printDebug) {
721 if (fabs(scEta) <= 1.479) {
722 std::cout << "Barrel :";
723 for (uint v=0; v < 46; ++v) std::cout << vals[v] << ", ";
724 std::cout << "\n";
725 }
726 else {
727 std::cout << "Endcap :";
728 for (uint v=0; v < 39; ++v) std::cout << vals[v] << ", ";
729 std::cout << "\n";
730 }
731 std::cout << " SCRawEnergy = " << SCRawEnergy << " : PreShowerOverRaw = " << PreShowerOverRaw << std::endl;
732 std::cout << "regression energy uncertainty = " << regressionResult << std::endl;
733 }
734
735
736 // Cleaning up and returning
737 delete[] vals;
738 return regressionResult;
739 }
740
741
742
743
744
745
746 double ElectronEnergyRegression::regressionValueWithTrkVarV2( std::vector<double> &inputvars,
747 bool printDebug)
748 {
749 // Checking if instance has been initialized
750 if (fIsInitialized == kFALSE) {
751 printf("ElectronEnergyRegression instance not initialized !!!");
752 return 0;
753 }
754
755 // Checking if fVersionType is correct
756 assert(fVersionType == kWithTrkVarV2);
757
758 // Checking if fVersionType is correct
759 assert(inputvars.size() == 49);
760
761 double SCRawEnergy = inputvars[0];
762 double scEta = inputvars[1];
763 double scPhi = inputvars[2];
764 double R9 = inputvars[3];
765 double etawidth = inputvars[4];
766 double phiwidth = inputvars[5];
767 double NClusters = inputvars[6];
768 double HoE = inputvars[7];
769 double rho = inputvars[8];
770 double vertices = inputvars[9];
771 double EtaSeed = inputvars[10];
772 double PhiSeed = inputvars[11];
773 double ESeed = inputvars[12];
774 double E3x3Seed = inputvars[13];
775 double E5x5Seed = inputvars[14];
776 double see = inputvars[15];
777 double spp = inputvars[16];
778 double sep = inputvars[17];
779 double EMaxSeed = inputvars[18];
780 double E2ndSeed = inputvars[19];
781 double ETopSeed = inputvars[20];
782 double EBottomSeed = inputvars[21];
783 double ELeftSeed = inputvars[22];
784 double ERightSeed = inputvars[23];
785 double E2x5MaxSeed = inputvars[24];
786 double E2x5TopSeed = inputvars[25];
787 double E2x5BottomSeed = inputvars[26];
788 double E2x5LeftSeed = inputvars[27];
789 double E2x5RightSeed = inputvars[28];
790 double IEtaSeed = inputvars[29];
791 double IPhiSeed = inputvars[30];
792 double EtaCrySeed = inputvars[31];
793 double PhiCrySeed = inputvars[32];
794 double PreShowerOverRaw = inputvars[33];
795 int IsEcalDriven = inputvars[34];
796 double GsfTrackPIn = inputvars[35];
797 double fbrem = inputvars[36];
798 double Charge = inputvars[37];
799 double EoP = inputvars[38];
800 double TrackMomentumError = inputvars[39];
801 double EcalEnergyError = inputvars[40];
802 int Classification = inputvars[41];
803 double detaIn = inputvars[42];
804 double dphiIn = inputvars[43];
805 double detaCalo = inputvars[44];
806 double dphiCalo = inputvars[45];
807 double GsfTrackChiSqr = inputvars[46];
808 double KFTrackNLayers = inputvars[47];
809 double ElectronEnergyOverPout = inputvars[48];
810
811 float *vals = (fabs(scEta) <= 1.479) ? new float[53] : new float[46];
812 if (fabs(scEta) <= 1.479) { // Barrel
813 vals[0] = SCRawEnergy;
814 vals[1] = scEta;
815 vals[2] = scPhi;
816 vals[3] = R9;
817 vals[4] = E5x5Seed/SCRawEnergy;
818 vals[5] = etawidth;
819 vals[6] = phiwidth;
820 vals[7] = NClusters;
821 vals[8] = HoE;
822 vals[9] = rho;
823 vals[10] = vertices;
824 vals[11] = EtaSeed - scEta;
825 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
826 vals[13] = ESeed/SCRawEnergy;
827 vals[14] = E3x3Seed/ESeed;
828 vals[15] = E5x5Seed/ESeed;
829 vals[16] = see;
830 vals[17] = spp;
831 vals[18] = sep;
832 vals[19] = EMaxSeed/ESeed;
833 vals[20] = E2ndSeed/ESeed;
834 vals[21] = ETopSeed/ESeed;
835 vals[22] = EBottomSeed/ESeed;
836 vals[23] = ELeftSeed/ESeed;
837 vals[24] = ERightSeed/ESeed;
838 vals[25] = E2x5MaxSeed/ESeed;
839 vals[26] = E2x5TopSeed/ESeed;
840 vals[27] = E2x5BottomSeed/ESeed;
841 vals[28] = E2x5LeftSeed/ESeed;
842 vals[29] = E2x5RightSeed/ESeed;
843 vals[30] = IsEcalDriven;
844 vals[31] = GsfTrackPIn;
845 vals[32] = fbrem;
846 vals[33] = Charge;
847 vals[34] = EoP;
848 vals[35] = TrackMomentumError/GsfTrackPIn;
849 vals[36] = EcalEnergyError/SCRawEnergy;
850 vals[37] = Classification;
851 vals[38] = detaIn;
852 vals[39] = dphiIn;
853 vals[40] = detaCalo;
854 vals[41] = dphiCalo;
855 vals[42] = GsfTrackChiSqr;
856 vals[43] = KFTrackNLayers;
857 vals[44] = ElectronEnergyOverPout;
858 vals[45] = IEtaSeed;
859 vals[46] = IPhiSeed;
860 vals[47] = ((int) IEtaSeed)%5;
861 vals[48] = ((int) IPhiSeed)%2;
862 vals[49] = (abs(IEtaSeed)<=25)*(((int)IEtaSeed)%25) + (abs(IEtaSeed)>25)*(((int) (IEtaSeed-25*abs(IEtaSeed)/IEtaSeed))%20);
863 vals[50] = ((int) IPhiSeed)%20;
864 vals[51] = EtaCrySeed;
865 vals[52] = PhiCrySeed;
866 }
867
868 else { // Endcap
869 vals[0] = SCRawEnergy;
870 vals[1] = scEta;
871 vals[2] = scPhi;
872 vals[3] = R9;
873 vals[4] = E5x5Seed/SCRawEnergy;
874 vals[5] = etawidth;
875 vals[6] = phiwidth;
876 vals[7] = NClusters;
877 vals[8] = HoE;
878 vals[9] = rho;
879 vals[10] = vertices;
880 vals[11] = EtaSeed - scEta;
881 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
882 vals[13] = ESeed/SCRawEnergy;
883 vals[14] = E3x3Seed/ESeed;
884 vals[15] = E5x5Seed/ESeed;
885 vals[16] = see;
886 vals[17] = spp;
887 vals[18] = sep;
888 vals[19] = EMaxSeed/ESeed;
889 vals[20] = E2ndSeed/ESeed;
890 vals[21] = ETopSeed/ESeed;
891 vals[22] = EBottomSeed/ESeed;
892 vals[23] = ELeftSeed/ESeed;
893 vals[24] = ERightSeed/ESeed;
894 vals[25] = E2x5MaxSeed/ESeed;
895 vals[26] = E2x5TopSeed/ESeed;
896 vals[27] = E2x5BottomSeed/ESeed;
897 vals[28] = E2x5LeftSeed/ESeed;
898 vals[29] = E2x5RightSeed/ESeed;
899 vals[30] = IsEcalDriven;
900 vals[31] = GsfTrackPIn;
901 vals[32] = fbrem;
902 vals[33] = Charge;
903 vals[34] = EoP;
904 vals[35] = TrackMomentumError/GsfTrackPIn;
905 vals[36] = EcalEnergyError/SCRawEnergy;
906 vals[37] = Classification;
907 vals[38] = detaIn;
908 vals[39] = dphiIn;
909 vals[40] = detaCalo;
910 vals[41] = dphiCalo;
911 vals[42] = GsfTrackChiSqr;
912 vals[43] = KFTrackNLayers;
913 vals[44] = ElectronEnergyOverPout;
914 vals[45] = PreShowerOverRaw;
915 }
916
917 // Now evaluating the regression
918 double regressionResult = 0;
919
920 if (fVersionType == kWithTrkVarV2) {
921 if (fabs(scEta) <= 1.479) regressionResult = SCRawEnergy * forestCorrection_eb->GetResponse(vals);
922 else regressionResult = (SCRawEnergy*(1+PreShowerOverRaw)) * forestCorrection_ee->GetResponse(vals);
923 }
924
925
926 //print debug
927 if (printDebug) {
928 if (fabs(scEta) <= 1.479) {
929 std::cout << "Barrel :";
930 for (uint v=0; v < 53; ++v) std::cout << vals[v] << ", ";
931 std::cout << "\n";
932 }
933 else {
934 std::cout << "Endcap :";
935 for (uint v=0; v < 46; ++v) std::cout << vals[v] << ", ";
936 std::cout << "\n";
937 }
938 std::cout << "SCRawEnergy = " << SCRawEnergy << " : PreShowerOverRaw = " << PreShowerOverRaw << std::endl;
939 std::cout << "regression energy = " << regressionResult << std::endl;
940 }
941
942 // Cleaning up and returning
943 delete[] vals;
944 return regressionResult;
945 }
946
947
948
949
950
951
952 double ElectronEnergyRegression::regressionUncertaintyWithTrkVarV2( std::vector<double> &inputvars,
953 bool printDebug)
954 {
955 // Checking if instance has been initialized
956 if (fIsInitialized == kFALSE) {
957 printf("ElectronEnergyRegression instance not initialized !!!");
958 return 0;
959 }
960
961 // Checking if fVersionType is correct
962 assert(fVersionType == kWithTrkVarV2);
963
964 // Checking if fVersionType is correct
965 assert(inputvars.size() == 49);
966
967 double SCRawEnergy = inputvars[0];
968 double scEta = inputvars[1];
969 double scPhi = inputvars[2];
970 double R9 = inputvars[3];
971 double etawidth = inputvars[4];
972 double phiwidth = inputvars[5];
973 double NClusters = inputvars[6];
974 double HoE = inputvars[7];
975 double rho = inputvars[8];
976 double vertices = inputvars[9];
977 double EtaSeed = inputvars[10];
978 double PhiSeed = inputvars[11];
979 double ESeed = inputvars[12];
980 double E3x3Seed = inputvars[13];
981 double E5x5Seed = inputvars[14];
982 double see = inputvars[15];
983 double spp = inputvars[16];
984 double sep = inputvars[17];
985 double EMaxSeed = inputvars[18];
986 double E2ndSeed = inputvars[19];
987 double ETopSeed = inputvars[20];
988 double EBottomSeed = inputvars[21];
989 double ELeftSeed = inputvars[22];
990 double ERightSeed = inputvars[23];
991 double E2x5MaxSeed = inputvars[24];
992 double E2x5TopSeed = inputvars[25];
993 double E2x5BottomSeed = inputvars[26];
994 double E2x5LeftSeed = inputvars[27];
995 double E2x5RightSeed = inputvars[28];
996 double IEtaSeed = inputvars[29];
997 double IPhiSeed = inputvars[30];
998 double EtaCrySeed = inputvars[31];
999 double PhiCrySeed = inputvars[32];
1000 double PreShowerOverRaw = inputvars[33];
1001 int IsEcalDriven = inputvars[34];
1002 double GsfTrackPIn = inputvars[35];
1003 double fbrem = inputvars[36];
1004 double Charge = inputvars[37];
1005 double EoP = inputvars[38];
1006 double TrackMomentumError = inputvars[39];
1007 double EcalEnergyError = inputvars[40];
1008 int Classification = inputvars[41];
1009 double detaIn = inputvars[42];
1010 double dphiIn = inputvars[43];
1011 double detaCalo = inputvars[44];
1012 double dphiCalo = inputvars[45];
1013 double GsfTrackChiSqr = inputvars[46];
1014 double KFTrackNLayers = inputvars[47];
1015 double ElectronEnergyOverPout = inputvars[48];
1016
1017 float *vals = (fabs(scEta) <= 1.479) ? new float[53] : new float[46];
1018 if (fabs(scEta) <= 1.479) { // Barrel
1019 vals[0] = SCRawEnergy;
1020 vals[1] = scEta;
1021 vals[2] = scPhi;
1022 vals[3] = R9;
1023 vals[4] = E5x5Seed/SCRawEnergy;
1024 vals[5] = etawidth;
1025 vals[6] = phiwidth;
1026 vals[7] = NClusters;
1027 vals[8] = HoE;
1028 vals[9] = rho;
1029 vals[10] = vertices;
1030 vals[11] = EtaSeed - scEta;
1031 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
1032 vals[13] = ESeed/SCRawEnergy;
1033 vals[14] = E3x3Seed/ESeed;
1034 vals[15] = E5x5Seed/ESeed;
1035 vals[16] = see;
1036 vals[17] = spp;
1037 vals[18] = sep;
1038 vals[19] = EMaxSeed/ESeed;
1039 vals[20] = E2ndSeed/ESeed;
1040 vals[21] = ETopSeed/ESeed;
1041 vals[22] = EBottomSeed/ESeed;
1042 vals[23] = ELeftSeed/ESeed;
1043 vals[24] = ERightSeed/ESeed;
1044 vals[25] = E2x5MaxSeed/ESeed;
1045 vals[26] = E2x5TopSeed/ESeed;
1046 vals[27] = E2x5BottomSeed/ESeed;
1047 vals[28] = E2x5LeftSeed/ESeed;
1048 vals[29] = E2x5RightSeed/ESeed;
1049 vals[30] = IsEcalDriven;
1050 vals[31] = GsfTrackPIn;
1051 vals[32] = fbrem;
1052 vals[33] = Charge;
1053 vals[34] = EoP;
1054 vals[35] = TrackMomentumError/GsfTrackPIn;
1055 vals[36] = EcalEnergyError/SCRawEnergy;
1056 vals[37] = Classification;
1057 vals[38] = detaIn;
1058 vals[39] = dphiIn;
1059 vals[40] = detaCalo;
1060 vals[41] = dphiCalo;
1061 vals[42] = GsfTrackChiSqr;
1062 vals[43] = KFTrackNLayers;
1063 vals[44] = ElectronEnergyOverPout;
1064 vals[45] = IEtaSeed;
1065 vals[46] = IPhiSeed;
1066 vals[47] = ((int) IEtaSeed)%5;
1067 vals[48] = ((int) IPhiSeed)%2;
1068 vals[49] = (abs(IEtaSeed)<=25)*(((int)IEtaSeed)%25) + (abs(IEtaSeed)>25)*(((int) (IEtaSeed-25*abs(IEtaSeed)/IEtaSeed))%20);
1069 vals[50] = ((int) IPhiSeed)%20;
1070 vals[51] = EtaCrySeed;
1071 vals[52] = PhiCrySeed;
1072 }
1073
1074 else { // Endcap
1075 vals[0] = SCRawEnergy;
1076 vals[1] = scEta;
1077 vals[2] = scPhi;
1078 vals[3] = R9;
1079 vals[4] = E5x5Seed/SCRawEnergy;
1080 vals[5] = etawidth;
1081 vals[6] = phiwidth;
1082 vals[7] = NClusters;
1083 vals[8] = HoE;
1084 vals[9] = rho;
1085 vals[10] = vertices;
1086 vals[11] = EtaSeed - scEta;
1087 vals[12] = atan2(sin(PhiSeed-scPhi),cos(PhiSeed-scPhi));
1088 vals[13] = ESeed/SCRawEnergy;
1089 vals[14] = E3x3Seed/ESeed;
1090 vals[15] = E5x5Seed/ESeed;
1091 vals[16] = see;
1092 vals[17] = spp;
1093 vals[18] = sep;
1094 vals[19] = EMaxSeed/ESeed;
1095 vals[20] = E2ndSeed/ESeed;
1096 vals[21] = ETopSeed/ESeed;
1097 vals[22] = EBottomSeed/ESeed;
1098 vals[23] = ELeftSeed/ESeed;
1099 vals[24] = ERightSeed/ESeed;
1100 vals[25] = E2x5MaxSeed/ESeed;
1101 vals[26] = E2x5TopSeed/ESeed;
1102 vals[27] = E2x5BottomSeed/ESeed;
1103 vals[28] = E2x5LeftSeed/ESeed;
1104 vals[29] = E2x5RightSeed/ESeed;
1105 vals[30] = IsEcalDriven;
1106 vals[31] = GsfTrackPIn;
1107 vals[32] = fbrem;
1108 vals[33] = Charge;
1109 vals[34] = EoP;
1110 vals[35] = TrackMomentumError/GsfTrackPIn;
1111 vals[36] = EcalEnergyError/SCRawEnergy;
1112 vals[37] = Classification;
1113 vals[38] = detaIn;
1114 vals[39] = dphiIn;
1115 vals[40] = detaCalo;
1116 vals[41] = dphiCalo;
1117 vals[42] = GsfTrackChiSqr;
1118 vals[43] = KFTrackNLayers;
1119 vals[44] = ElectronEnergyOverPout;
1120 vals[45] = PreShowerOverRaw;
1121 }
1122
1123 // Now evaluating the regression
1124 double regressionResult = 0;
1125
1126 if (fVersionType == kWithTrkVarV2) {
1127 if (fabs(scEta) <= 1.479) regressionResult = SCRawEnergy * forestUncertainty_eb->GetResponse(vals);
1128 else regressionResult = (SCRawEnergy*(1+PreShowerOverRaw)) * forestUncertainty_ee->GetResponse(vals);
1129 }
1130
1131 //print debug
1132 if (printDebug) {
1133 if (fabs(scEta) <= 1.479) {
1134 std::cout << "Barrel :";
1135 for (uint v=0; v < 53; ++v) std::cout << vals[v] << ", ";
1136 std::cout << "\n";
1137 }
1138 else {
1139 std::cout << "Endcap :";
1140 for (uint v=0; v < 46; ++v) std::cout << vals[v] << ", ";
1141 std::cout << "\n";
1142 }
1143 std::cout << "SCRawEnergy = " << SCRawEnergy << " : PreShowerOverRaw = " << PreShowerOverRaw << std::endl;
1144 std::cout << "regression energy uncertainty = " << regressionResult << std::endl;
1145 }
1146
1147
1148 // Cleaning up and returning
1149 delete[] vals;
1150 return regressionResult;
1151 }
1152