-
Notifications
You must be signed in to change notification settings - Fork 1
/
variables.h
1884 lines (1703 loc) · 53.6 KB
/
variables.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
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
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "TROOT.h"
#include "TChain.h"
#include "Minuit2/MnUserParameters.h"
#include <string>
#include <vector>
#include <utility>
#include <fstream>
typedef struct
{
double min;
double max;
double s; // scale
double serr; // error of scale
} EnergyScale;
// define vectors to store data
// store all events
int nEventsAll, nSignalsAll;
std::vector<Int_t> allRunNum;
std::vector<ULong64_t> allEvtNum;
std::vector<double> allE1, allEReg1, allEta1, allPhi1;
std::vector<double> allE2, allEReg2, allEta2, allPhi2;
std::vector<int> allnHits1, allnHits2;
std::vector< std::vector<double> > allHitE1, allHitE2;
std::vector< std::vector<int> > allHitIX1, allHitIY1, allHitIZ1;
std::vector< std::vector<int> > allHitIX2, allHitIY2, allHitIZ2;
std::vector<int> allSeedIX1, allSeedIY1, allSeedIZ1;
std::vector<int> allSeedIX2, allSeedIY2, allSeedIZ2;
std::vector<double> allRawEEcal1, allRawEEcal2;
// store selected events
int nEvents, nSignals;
std::vector<double*> E1, EReg1, Eta1, Phi1;
std::vector<double*> E2, EReg2, Eta2, Phi2;
std::vector<int*> nHits1, nHits2;
std::vector< std::vector<double>* > HitE1, HitE2;
std::vector< std::vector<int>* > HitIX1, HitIY1, HitIZ1;
std::vector< std::vector<int>* > HitIX2, HitIY2, HitIZ2;
std::vector<bool> UseEle1, UseEle2;
std::vector<int> ScaleBin1, ScaleBin2;
std::vector<int*> SeedIX1, SeedIY1, SeedIZ1;
std::vector<int*> SeedIX2, SeedIY2, SeedIZ2;
std::vector<double*> RawEEcal1, RawEEcal2;
// variables for ROOT Tree
Int_t runNum;
ULong64_t evtNum;
Int_t lumBlk;
UInt_t runTime;
Int_t nVtx;
Int_t tnPar;
Int_t rStat[2];
Double_t rR9[2];
Double_t rPx[2];
Double_t rPy[2];
Double_t rPz[2];
Double_t rPt[2];
Double_t rE[2];
Double_t rEta[2];
Double_t rPhi[2];
Double_t rVtx[2];
Double_t rVty[2];
Double_t rVtz[2];
Double_t rERaw[2];
Double_t rNBCl[2];
Double_t rEtaWidth[2];
Double_t rPhiWidth[2];
Float_t rCaloE[2];
Float_t rEcalE[2];
Float_t rPresE[2];
Int_t rEB[2];
Float_t rSeedE[2];
Int_t rSeedIX[2];
Int_t rSeedIY[2];
Int_t rSeedIZ[2];
Int_t rNHits[2];
Float_t rHitE[2][200];
Int_t rHitIX[2][200];
Int_t rHitIY[2][200];
Int_t rHitIZ[2][200];
Int_t rZStat;
// newly added variables
Int_t rHLTFire;
Int_t rNPV;
Int_t rEleID[2];
Float_t rERegV8Elec[2];
Float_t rERegV8Phot[2];
Float_t rESigmaRegV8Elec[2];
Float_t rESigmaRegV8Phot[2];
Float_t rERegV7Elec[2];
Float_t rERegV7Phot[2];
Float_t rESigmaRegV7Elec[2];
Float_t rESigmaRegV7Phot[2];
Float_t rERegV6Elec[2];
Float_t rERegV6Phot[2];
Float_t rESigmaRegV6Elec[2];
Float_t rESigmaRegV6Phot[2];
Float_t rERegV5Elec[2];
Float_t rERegV5Phot[2];
Float_t rESigmaRegV5Elec[2];
Float_t rESigmaRegV5Phot[2];
// set tree branches
void SetTreeBranch(TChain* tree)
{
// Set branch addresses.
tree->SetBranchAddress("runNum",&runNum);
tree->SetBranchAddress("evtNum",&evtNum);
tree->SetBranchAddress("lumBlk",&lumBlk);
tree->SetBranchAddress("runTime",&runTime);
tree->SetBranchAddress("nVtx",&nVtx);
tree->SetBranchAddress("tnPar",&tnPar);
tree->SetBranchAddress("rStat",rStat);
tree->SetBranchAddress("rR9",rR9);
tree->SetBranchAddress("rPx",rPx);
tree->SetBranchAddress("rPy",rPy);
tree->SetBranchAddress("rPz",rPz);
tree->SetBranchAddress("rPt",rPt);
tree->SetBranchAddress("rE",rE);
tree->SetBranchAddress("rEta",rEta);
tree->SetBranchAddress("rPhi",rPhi);
tree->SetBranchAddress("rVtx",rVtx);
tree->SetBranchAddress("rVty",rVty);
tree->SetBranchAddress("rVtz",rVtz);
tree->SetBranchAddress("rERaw",rERaw);
tree->SetBranchAddress("rNBCl",rNBCl);
tree->SetBranchAddress("rEtaWidth",rEtaWidth);
tree->SetBranchAddress("rPhiWidth",rPhiWidth);
tree->SetBranchAddress("rCaloE",rCaloE);
tree->SetBranchAddress("rEcalE",rEcalE);
tree->SetBranchAddress("rPresE",rPresE);
tree->SetBranchAddress("rEB",rEB);
tree->SetBranchAddress("rSeedE",rSeedE);
tree->SetBranchAddress("rSeedIX",rSeedIX);
tree->SetBranchAddress("rSeedIY",rSeedIY);
tree->SetBranchAddress("rSeedIZ",rSeedIZ);
tree->SetBranchAddress("rNHits",rNHits);
tree->SetBranchAddress("rHitE",rHitE);
tree->SetBranchAddress("rHitIX",rHitIX);
tree->SetBranchAddress("rHitIY",rHitIY);
tree->SetBranchAddress("rHitIZ",rHitIZ);
tree->SetBranchAddress("rZStat",&rZStat);
// newly added branch
tree->SetBranchAddress("rHLTFire",&rHLTFire);
tree->SetBranchAddress("rNPV",&rNPV);
tree->SetBranchAddress("rEleID",rEleID);
tree->SetBranchAddress("rERegV8Elec",rERegV8Elec);
tree->SetBranchAddress("rERegV8Phot",rERegV8Phot);
tree->SetBranchAddress("rESigmaRegV8Elec",rESigmaRegV8Elec);
tree->SetBranchAddress("rESigmaRegV8Phot",rESigmaRegV8Phot);
tree->SetBranchAddress("rERegV7Elec",rERegV7Elec);
tree->SetBranchAddress("rERegV7Phot",rERegV7Phot);
tree->SetBranchAddress("rESigmaRegV7Elec",rESigmaRegV7Elec);
tree->SetBranchAddress("rESigmaRegV7Phot",rESigmaRegV7Phot);
tree->SetBranchAddress("rERegV6Elec",rERegV6Elec);
tree->SetBranchAddress("rERegV6Phot",rERegV6Phot);
tree->SetBranchAddress("rESigmaRegV6Elec",rESigmaRegV6Elec);
tree->SetBranchAddress("rESigmaRegV6Phot",rESigmaRegV6Phot);
tree->SetBranchAddress("rERegV5Elec",rERegV5Elec);
tree->SetBranchAddress("rERegV5Phot",rERegV5Phot);
tree->SetBranchAddress("rESigmaRegV5Elec",rESigmaRegV5Elec);
tree->SetBranchAddress("rESigmaRegV5Phot",rESigmaRegV5Phot);
}
// store all events from the Tree to vectors
void FillAllEvents(TChain* tree, const int debug=0, const std::string regVersion="V8Elec", const bool fitscale=false)
{
nEventsAll = (int)tree->GetEntries();
nSignalsAll = 0.99999*nEventsAll; // guess a number
if (debug>1) std::cout << "fill all data vectors: Using Regression "<< regVersion << std::endl;
// fill data vectors
for (int i=0; i<nEventsAll; i++){
// get event from tree
tree->GetEntry(i);
allRunNum.push_back(runNum);
allEvtNum.push_back(evtNum);
// first electron
//allE1.push_back(rE[0]);
//allE1.push_back(rERaw[0]+rPresE[0]); // SC raw as in Regression
allE1.push_back(rERaw[0]); // SC raw as in Regression
if(regVersion=="V5Elec") allEReg1.push_back(rERegV5Elec[0]);
else if(regVersion=="V6Elec") allEReg1.push_back(rERegV6Elec[0]);
else if(regVersion=="V7Elec") allEReg1.push_back(rERegV7Elec[0]);
else allEReg1.push_back(rERegV8Elec[0]);
allEta1.push_back(rEta[0]);
allPhi1.push_back(rPhi[0]);
allRawEEcal1.push_back(rERaw[0]-rPresE[0]);
allSeedIX1.push_back(rSeedIX[0]);
allSeedIY1.push_back(rSeedIY[0]);
allSeedIZ1.push_back(rSeedIZ[0]);
// if fit scale, then we don't need the following information
if(!fitscale)
{
allnHits1.push_back(rNHits[0]);
std::vector<double> hitE1;
std::vector<int> hitIX1, hitIY1, hitIZ1;
for (int ii=0; ii<rNHits[0]; ii++){
hitE1.push_back(rHitE[0][ii]);
hitIX1.push_back(rHitIX[0][ii]);
hitIY1.push_back(rHitIY[0][ii]);
hitIZ1.push_back(rHitIZ[0][ii]);
}
allHitE1.push_back(hitE1);
allHitIX1.push_back(hitIX1);
allHitIY1.push_back(hitIY1);
allHitIZ1.push_back(hitIZ1);
}
// second electron
//allE2.push_back(rE[1]);
//allE2.push_back(rERaw[1]+rPresE[1]); // SC raw as in Regression
allE2.push_back(rERaw[1]); // SC raw as in Regression
if(regVersion=="V5Elec") allEReg2.push_back(rERegV5Elec[1]);
else if(regVersion=="V6Elec") allEReg2.push_back(rERegV6Elec[1]);
else if(regVersion=="V7Elec") allEReg2.push_back(rERegV7Elec[1]);
else allEReg2.push_back(rERegV8Elec[1]);
allEta2.push_back(rEta[1]);
allPhi2.push_back(rPhi[1]);
allRawEEcal2.push_back(rERaw[1]-rPresE[1]);
allSeedIX2.push_back(rSeedIX[1]);
allSeedIY2.push_back(rSeedIY[1]);
allSeedIZ2.push_back(rSeedIZ[1]);
// if fit scale, then we don't need the following information
if(!fitscale)
{
allnHits2.push_back(rNHits[1]);
std::vector<double> hitE2;
std::vector<int> hitIX2, hitIY2, hitIZ2;
for (int ii=0; ii<rNHits[1]; ii++){
hitE2.push_back(rHitE[1][ii]);
hitIX2.push_back(rHitIX[1][ii]);
hitIY2.push_back(rHitIY[1][ii]);
hitIZ2.push_back(rHitIZ[1][ii]);
}
allHitE2.push_back(hitE2);
allHitIX2.push_back(hitIX2);
allHitIY2.push_back(hitIY2);
allHitIZ2.push_back(hitIZ2);
}
}
}
// generate an empty calib table
void GenEmptyCalibTable(std::vector<std::vector<int> > cells, const char* filename = "EmptyCalibTable.dat", int start_idx=0)
{
// init txt file and print
std::ofstream myfile(filename);
if (myfile.is_open())
{
for (int i=0; i<(int)cells.size(); i++)
{
myfile << i << " "
<< cells.at(i).at(0) << " "
<< cells.at(i).at(1) << " "
<< cells.at(i).at(2) << " "
<< 1.0 << " "
<< 0.1 << " "
<< 0 << " "
<< 0 << " "
<< std::endl;
}
myfile.close();
}
}
// this one is store the selection in E1, Eta1, .. E2, Eta2, .. HitE1, ... vectors.
// select events with at least one hit falling in one particular cell
int SelectEventsInOneCell(int ix, int iy, int iz)
{
// clear previous vectors
nEvents = 0;
nSignals = 0;
E1.clear();
EReg1.clear();
Eta1.clear();
Phi1.clear();
E2.clear();
EReg2.clear();
Eta2.clear();
Phi2.clear();
nHits1.clear();
nHits2.clear();
HitE1.clear();
HitE2.clear();
HitIX1.clear();
HitIY1.clear();
HitIZ1.clear();
HitIX2.clear();
HitIY2.clear();
HitIZ2.clear();
// loop over all events and select events
for (int i=0; i<nEventsAll; i++)
{
bool take=false;
// loop over all hits of electron1
for (int ii=0; ii<(int)allHitE1.at(i).size(); ii++ )
{
if(take==true) break;
if((allHitIX1.at(i).at(ii)==ix) &&
(allHitIY1.at(i).at(ii)==iy) &&
(allHitIZ1.at(i).at(ii)==iz) )
{
// if there is even one hit match a cell in selection, take the event
take = true;
break;
}
}
// loop over all hits of electron2
for (int ii=0; ii<(int)allHitE2.at(i).size(); ii++ )
{
if(take==true) break;
if((allHitIX2.at(i).at(ii)==ix) &&
(allHitIY2.at(i).at(ii)==iy) &&
(allHitIZ2.at(i).at(ii)==iz) )
{
// if there is even one hit match a cell in selection, take the event
take = true;
break;
}
}
// if do not decide to take this event, continue
if (!take)
{
continue;
}
// if not continue above, it is a useful event to use
E1.push_back(&(allE1.at(i)));
EReg1.push_back(&(allEReg1.at(i)));
Eta1.push_back(&(allEta1.at(i)));
Phi1.push_back(&(allPhi1.at(i)));
E2.push_back(&(allE2.at(i)));
EReg2.push_back(&(allEReg2.at(i)));
Eta2.push_back(&(allEta2.at(i)));
Phi2.push_back(&(allPhi2.at(i)));
nHits1.push_back(&(allnHits1.at(i)));
HitE1.push_back(&(allHitE1.at(i)));
HitIX1.push_back(&(allHitIX1.at(i)));
HitIY1.push_back(&(allHitIY1.at(i)));
HitIZ1.push_back(&(allHitIZ1.at(i)));
nHits2.push_back(&(allnHits2.at(i)));
HitE2.push_back(&(allHitE2.at(i)));
HitIX2.push_back(&(allHitIX2.at(i)));
HitIY2.push_back(&(allHitIY2.at(i)));
HitIZ2.push_back(&(allHitIZ2.at(i)));
}
// nEvents
nEvents = (int)E1.size();
nSignals = nEvents; // assume no background (fix me)
//
return nEvents;
}
// this one is store the selection in E1, Eta1, .. E2, Eta2, .. HitE1, ... vectors.
// select events with one hit falling in one particular cell
// and the energy of this hit should be greater than a fraction
int SelectEventsInOneCellWithFraction(int ix, int iy, int iz, double fraction=0.5, int doEvenOdd=0)
{
// clear previous vectors
nEvents = 0;
nSignals = 0;
E1.clear();
EReg1.clear();
Eta1.clear();
Phi1.clear();
E2.clear();
EReg2.clear();
Eta2.clear();
Phi2.clear();
nHits1.clear();
nHits2.clear();
HitE1.clear();
HitE2.clear();
HitIX1.clear();
HitIY1.clear();
HitIZ1.clear();
HitIX2.clear();
HitIY2.clear();
HitIZ2.clear();
// loop over all events and select events
for (int i=0; i<nEventsAll; i++)
{
bool take=false;
// even odd event check
if (doEvenOdd==1 && i%2==0) continue;
else if (doEvenOdd==2 && i%2==1) continue;
// loop over all hits of electron1
for (int ii=0; ii<(int)allHitE1.at(i).size(); ii++ )
{
if(take==true) break;
// if there is even one hit match a cell in selection,
// also this hit energy is bigger than fraction*E(total),
// take this event
if((allHitIX1.at(i).at(ii)==ix) &&
(allHitIY1.at(i).at(ii)==iy) &&
(allHitIZ1.at(i).at(ii)==iz) &&
(allHitE1.at(i).at(ii)>fraction*allE1.at(i)) )
{
take = true;
break;
}
}
// loop over all hits of electron2
for (int ii=0; ii<(int)allHitE2.at(i).size(); ii++ )
{
if(take==true) break;
// if there is even one hit match a cell in selection,
// also this hit energy is bigger than fraction*E(total),
// take this event
if((allHitIX2.at(i).at(ii)==ix) &&
(allHitIY2.at(i).at(ii)==iy) &&
(allHitIZ2.at(i).at(ii)==iz) &&
(allHitE2.at(i).at(ii)>fraction*allE2.at(i)) )
{
take = true;
break;
}
}
// if do not decide to take this event, continue
if (!take)
{
continue;
}
// if not continue above, it is a useful event to use
E1.push_back(&(allE1.at(i)));
EReg1.push_back(&(allEReg1.at(i)));
Eta1.push_back(&(allEta1.at(i)));
Phi1.push_back(&(allPhi1.at(i)));
E2.push_back(&(allE2.at(i)));
EReg2.push_back(&(allEReg2.at(i)));
Eta2.push_back(&(allEta2.at(i)));
Phi2.push_back(&(allPhi2.at(i)));
nHits1.push_back(&(allnHits1.at(i)));
HitE1.push_back(&(allHitE1.at(i)));
HitIX1.push_back(&(allHitIX1.at(i)));
HitIY1.push_back(&(allHitIY1.at(i)));
HitIZ1.push_back(&(allHitIZ1.at(i)));
nHits2.push_back(&(allnHits2.at(i)));
HitE2.push_back(&(allHitE2.at(i)));
HitIX2.push_back(&(allHitIX2.at(i)));
HitIY2.push_back(&(allHitIY2.at(i)));
HitIZ2.push_back(&(allHitIZ2.at(i)));
}
// nEvents
nEvents = (int)E1.size();
nSignals = nEvents; // assume no background (fix me)
//
return nEvents;
}
// this one is store the selection in E1, Eta1, .. E2, Eta2, .. HitE1, ... vectors.
// select events with one hit falling in one particular cell
// and the energy of this hit should be greater than a fraction
// with selection of EBEB, EBEE, or EEEE combination
int SelectEventsInOneCellWithFractionEBorEECombine(int ix, int iy, int iz, double fraction=0.5, int doEvenOdd=0, std::string Combine="")
{
// clear previous vectors
nEvents = 0;
nSignals = 0;
E1.clear();
EReg1.clear();
Eta1.clear();
Phi1.clear();
E2.clear();
EReg2.clear();
Eta2.clear();
Phi2.clear();
nHits1.clear();
nHits2.clear();
HitE1.clear();
HitE2.clear();
HitIX1.clear();
HitIY1.clear();
HitIZ1.clear();
HitIX2.clear();
HitIY2.clear();
HitIZ2.clear();
// loop over all events and select events
for (int i=0; i<nEventsAll; i++)
{
bool take=false;
// even odd event check
if (doEvenOdd==1 && i%2==0) continue;
else if (doEvenOdd==2 && i%2==1) continue;
// EB or EE combinatioin check
if ( Combine=="EBEB" ) // both in EB
{
if ( !(fabs(allEta1[i])<1.48&&fabs(allEta2[i])<1.48) ) continue;
}
if ( Combine=="EBEE" ) // one in EB one in EE
{
if ( !( (fabs(allEta1[i])<1.48&&fabs(allEta2[i])>1.48)||(fabs(allEta2[i])<1.48&&fabs(allEta1[i])>1.48) ) ) continue;
}
if ( Combine=="EEEE" ) // both in EE
{
if ( !(fabs(allEta1[i])>1.48&&fabs(allEta2[i])>1.48) ) continue;
}
if ( Combine=="EE" ) // any one of the two in EE
{
if ( !(fabs(allEta1[i])>1.48||fabs(allEta2[i])>1.48) ) continue;
}
if ( Combine=="EB" ) // any one of the two in EB
{
if ( !(fabs(allEta1[i])<1.48||fabs(allEta2[i])<1.48) ) continue;
}
// loop over all hits of electron1
for (int ii=0; ii<(int)allHitE1.at(i).size(); ii++ )
{
if(take==true) break;
// if there is even one hit match a cell in selection,
// also this hit energy is bigger than fraction*E(total),
// take this event
if((allHitIX1.at(i).at(ii)==ix) &&
(allHitIY1.at(i).at(ii)==iy) &&
(allHitIZ1.at(i).at(ii)==iz) &&
(allHitE1.at(i).at(ii)>fraction*allE1.at(i)) )
{
take = true;
break;
}
}
// loop over all hits of electron2
for (int ii=0; ii<(int)allHitE2.at(i).size(); ii++ )
{
if(take==true) break;
// if there is even one hit match a cell in selection,
// also this hit energy is bigger than fraction*E(total),
// take this event
if((allHitIX2.at(i).at(ii)==ix) &&
(allHitIY2.at(i).at(ii)==iy) &&
(allHitIZ2.at(i).at(ii)==iz) &&
(allHitE2.at(i).at(ii)>fraction*allE2.at(i)) )
{
take = true;
break;
}
}
// if do not decide to take this event, continue
if (!take)
{
continue;
}
// if not continue above, it is a useful event to use
E1.push_back(&(allE1.at(i)));
EReg1.push_back(&(allEReg1.at(i)));
Eta1.push_back(&(allEta1.at(i)));
Phi1.push_back(&(allPhi1.at(i)));
E2.push_back(&(allE2.at(i)));
EReg2.push_back(&(allEReg2.at(i)));
Eta2.push_back(&(allEta2.at(i)));
Phi2.push_back(&(allPhi2.at(i)));
nHits1.push_back(&(allnHits1.at(i)));
HitE1.push_back(&(allHitE1.at(i)));
HitIX1.push_back(&(allHitIX1.at(i)));
HitIY1.push_back(&(allHitIY1.at(i)));
HitIZ1.push_back(&(allHitIZ1.at(i)));
nHits2.push_back(&(allnHits2.at(i)));
HitE2.push_back(&(allHitE2.at(i)));
HitIX2.push_back(&(allHitIX2.at(i)));
HitIY2.push_back(&(allHitIY2.at(i)));
HitIZ2.push_back(&(allHitIZ2.at(i)));
}
// nEvents
nEvents = (int)E1.size();
nSignals = nEvents; // assume no background (fix me)
//
return nEvents;
}
int SelectEventsInOneSeed(int ix, int iy, int iz, bool doEvenOdd=0, std::string Combine="")
{
// clear previous vectors
nEvents = 0;
nSignals = 0;
E1.clear();
EReg1.clear();
Eta1.clear();
Phi1.clear();
E2.clear();
EReg2.clear();
Eta2.clear();
Phi2.clear();
nHits1.clear();
nHits2.clear();
HitE1.clear();
HitE2.clear();
HitIX1.clear();
HitIY1.clear();
HitIZ1.clear();
HitIX2.clear();
HitIY2.clear();
HitIZ2.clear();
UseEle1.clear();
UseEle2.clear();
RawEEcal1.clear();
RawEEcal2.clear();
SeedIX1.clear();
SeedIX2.clear();
SeedIY1.clear();
SeedIY2.clear();
SeedIZ1.clear();
SeedIZ2.clear();
// loop over all events and select events
for (int i=0; i<nEventsAll; i++)
{
// even odd check
if (doEvenOdd==1 && allEvtNum[i]%2==0) continue;
else if (doEvenOdd==2 && allEvtNum[i]%2==1) continue;
// EB or EE combinatioin check
if ( Combine=="EBEB" ) // both in EB
{
if ( !(fabs(allEta1[i])<1.48&&fabs(allEta2[i])<1.48) ) continue;
}
if ( Combine=="EBEE" ) // one in EB one in EE
{
if ( !( (fabs(allEta1[i])<1.48&&fabs(allEta2[i])>1.48)||(fabs(allEta2[i])<1.48&&fabs(allEta1[i])>1.48) ) ) continue;
}
if ( Combine=="EEEE" ) // both in EE
{
if ( !(fabs(allEta1[i])>1.48&&fabs(allEta2[i])>1.48) ) continue;
}
if ( Combine=="EE" ) // any one of the two in EE
{
if ( !(fabs(allEta1[i])>1.48||fabs(allEta2[i])>1.48) ) continue;
}
if ( Combine=="EB" ) // any one of the two in EB
{
if ( !(fabs(allEta1[i])<1.48||fabs(allEta2[i])<1.48) ) continue;
}
// check if e1 or e2 is in the cell to be fitted
bool takeEle1(false), takeEle2(false);
// e1
if (allSeedIX1.at(i)==ix &&
allSeedIY1.at(i)==iy &&
allSeedIZ1.at(i)==iz )
{
takeEle1=true;
}
// e2
if (allSeedIX2.at(i)==ix &&
allSeedIY2.at(i)==iy &&
allSeedIZ2.at(i)==iz )
{
takeEle2=true;
}
// if do not decide to take this event, continue
if (!takeEle1&&!takeEle2)
{
continue;
}
// if not continue above, it is a useful event to use
E1.push_back(&(allE1.at(i)));
EReg1.push_back(&(allEReg1.at(i)));
Eta1.push_back(&(allEta1.at(i)));
Phi1.push_back(&(allPhi1.at(i)));
E2.push_back(&(allE2.at(i)));
EReg2.push_back(&(allEReg2.at(i)));
Eta2.push_back(&(allEta2.at(i)));
Phi2.push_back(&(allPhi2.at(i)));
RawEEcal1.push_back(&(allRawEEcal1.at(i)));
RawEEcal2.push_back(&(allRawEEcal2.at(i)));
UseEle1.push_back(takeEle1);
UseEle2.push_back(takeEle2);
}
// nEvents
nEvents = (int)E1.size();
nSignals = nEvents; // assume no background (fix me)
//
return nEvents;
}
//
// Store the selection in E1, Eta1, .. E2, Eta2, .. HitE1, ... vectors.
// select events according to the following rule:
// - center at ix,iy,iz among a group of 3x3 = 9 cells
// - if one event has one electron falls inside these 9cells and deposits >90%
// of its energy inside these 9 cells, take the event.
// - no need to have all the 9 cells be fired by the same electron in the same
// event, but >90% electron energy is required.
// - no need to be exactly 9 cells if the center cell is at (or near) an edge.
// - store those cells among these 9 cells that follow some requirements.
// - if not an electron/event among all the events deposits >10% of the electron
// energy into this center cell ix, iy, iz, skip this cell and also all the
// other 8 cells around it.
// - if not an electron/event among all the events deposits >2% of its energy
// inside the 8 cells around the center cell, skip this surrounding cell.
//
// Has selection of EBEB, EBEE, or EEEE combination
int SelectEventsInOneCellWith3x3Others(int ix, int iy, int iz,
std::vector<int>& ixx, std::vector<int>& iyy, std::vector<int>& izz,
std::string Combine="")
{
// clear previous vectors
nEvents = 0;
nSignals = 0;
E1.clear();
EReg1.clear();
Eta1.clear();
Phi1.clear();
E2.clear();
EReg2.clear();
Eta2.clear();
Phi2.clear();
nHits1.clear();
nHits2.clear();
HitE1.clear();
HitE2.clear();
HitIX1.clear();
HitIY1.clear();
HitIZ1.clear();
HitIX2.clear();
HitIY2.clear();
HitIZ2.clear();
// define default 3x3 celles taking ix,iy,iz as center
// positions
std::vector<int> iixx, iiyy, iizz;
// largest energy fraction in all events
std::vector<double> iimaxefrac;
// push_back the fitted cell as the first item in the vector
iixx.push_back(ix);
iiyy.push_back(iy);
iizz.push_back(iz);
iimaxefrac.push_back(0.0);
// push_back the rest 8 cells
for (int jx=ix-1; jx<=ix+1; jx++)
{
for (int jy=iy-1; jy<=iy+1; jy++)
{
// skip the fitting cell that has already been booked.
if (jx==ix&&jy==iy) continue;
iiyy.push_back(jy);
iizz.push_back(iz);
iimaxefrac.push_back(0.0);
if (iz==0&&jx==0&&ix==1)
{
iixx.push_back(jx-1);
}
else if (iz==0&&jx==0&&ix==-1)
{
iixx.push_back(jx+1);
}
else
{
iixx.push_back(jx);
}
}
}
// some debug
std::cout << " Debug:: print 3x3 cells " << std::endl;
for (int icell=0; icell<(int)iixx.size(); icell++)
{
std::cout << "(" << iixx.at(icell) << "," << iiyy.at(icell) << "," << iizz.at(icell) << ")" << std::endl;
}
// loop over all events and select events
for (int i=0; i<nEventsAll; i++)
{
// EB or EE combinatioin check
if ( Combine=="EBEB" ) // both in EB
{
if ( !(fabs(allEta1[i])<1.48&&fabs(allEta2[i])<1.48) ) continue;
}
if ( Combine=="EBEE" ) // one in EB one in EE
{
if ( !( (fabs(allEta1[i])<1.48&&fabs(allEta2[i])>1.48)||(fabs(allEta2[i])<1.48&&fabs(allEta1[i])>1.48) ) ) continue;
}
if ( Combine=="EEEE" ) // both in EE
{
if ( !(fabs(allEta1[i])>1.48&&fabs(allEta2[i])>1.48) ) continue;
}
if ( Combine=="EE" ) // any one of the two in EE
{
if ( !(fabs(allEta1[i])>1.48||fabs(allEta2[i])>1.48) ) continue;
}
if ( Combine=="EB" ) // any one of the two in EB
{
if ( !(fabs(allEta1[i])<1.48||fabs(allEta2[i])<1.48) ) continue;
}
// note, if not any of the string above, this event will always pass this check.
//
double E1_9cells(0);
// loop over all hits of electron1
for (int ii=0; ii<(int)allHitE1.at(i).size(); ii++ )
{
double hitfrac = allHitE1.at(i).at(ii)/allE1.at(i);
// loop over all 9 cells
for (int icell=0; icell<(int)iixx.size(); icell++)
{
// check matching
if( (allHitIX1.at(i).at(ii)==iixx.at(icell)) &&
(allHitIY1.at(i).at(ii)==iiyy.at(icell)) &&
(allHitIZ1.at(i).at(ii)==iizz.at(icell)) )
{
E1_9cells += allHitE1.at(i).at(ii);
if (hitfrac>iimaxefrac.at(icell))
{
iimaxefrac.at(icell) = hitfrac;
}
} // if ( (allHitIX1.at(i)...
} // for (int icell=0; ..
} // for (int ii=0; ..
//
double E2_9cells(0);
// loop over all hits of electron2
for (int ii=0; ii<(int)allHitE2.at(i).size(); ii++ )
{
double hitfrac = allHitE2.at(i).at(ii)/allE2.at(i);
// loop over all 9 cells
for (int icell=0; icell<(int)iixx.size(); icell++)
{
// check matching
if( (allHitIX2.at(i).at(ii)==iixx.at(icell)) &&
(allHitIY2.at(i).at(ii)==iiyy.at(icell)) &&
(allHitIZ2.at(i).at(ii)==iizz.at(icell)) )
{
E2_9cells += allHitE2.at(i).at(ii);
if (hitfrac>iimaxefrac.at(icell))
{
iimaxefrac.at(icell) = hitfrac;
}
} // if ( (allHitIX2.at(i)...
} // for (int icell=0; ..
} // for (int ii=0; ..
// if the 9cells energy in both the two electrons are
// less than 90% of the electrons' energy, I skip this
// event.
if ( E1_9cells/allE1.at(i)<0.6 &&
E2_9cells/allE2.at(i)<0.6 )
{
continue;
}
// if not continue above, it is a useful event to use
E1.push_back(&(allE1.at(i)));
EReg1.push_back(&(allEReg1.at(i)));
Eta1.push_back(&(allEta1.at(i)));
Phi1.push_back(&(allPhi1.at(i)));
E2.push_back(&(allE2.at(i)));
EReg2.push_back(&(allEReg2.at(i)));
Eta2.push_back(&(allEta2.at(i)));
Phi2.push_back(&(allPhi2.at(i)));
nHits1.push_back(&(allnHits1.at(i)));
HitE1.push_back(&(allHitE1.at(i)));
HitIX1.push_back(&(allHitIX1.at(i)));
HitIY1.push_back(&(allHitIY1.at(i)));
HitIZ1.push_back(&(allHitIZ1.at(i)));
nHits2.push_back(&(allnHits2.at(i)));
HitE2.push_back(&(allHitE2.at(i)));
HitIX2.push_back(&(allHitIX2.at(i)));
HitIY2.push_back(&(allHitIY2.at(i)));
HitIZ2.push_back(&(allHitIZ2.at(i)));
}
// nEvents
nEvents = (int)E1.size();
nSignals = nEvents; // assume no background (fix me)
// making selection of the 3x3 cells according to the following rules:
// - if not an electron/event among all the events deposits >10% of the electron
// energy into this center cell ix, iy, iz, skip this cell and also all the
// other 8 cells around it.
// - if not an electron/event among all the events deposits >2% of its energy
// inside the 8 cells around the center cell, skip this surrounding cell.
// clean up the output cell position vectors
ixx.clear();
iyy.clear();
izz.clear();
// check fitting cell at first
if ( iimaxefrac.at(0)<0.1 )
{
return 0; // take this as a flag to skip this cell
}
else
{
// same, the first entry is the fitting cell.
ixx.push_back(iixx.at(0));
iyy.push_back(iiyy.at(0));
izz.push_back(iizz.at(0));
}
// check the rest 8 cells;
for (int icell=1; icell<(int)iixx.size(); icell++)
{
// if the maximum cell energy fraction among all events are <2%, do not use this cell
if (iimaxefrac.at(icell)<0.02) continue;
// if not use this cell
ixx.push_back(iixx.at(icell));
iyy.push_back(iiyy.at(icell));
izz.push_back(iizz.at(icell));
}
//
return nEvents;
}
//
// select events in one Eta bin
int SelectEventsInOneEtaBin(double bin_min, double bin_max, std::string Combine="")
{
// clear previous vectors
nEvents = 0;
nSignals = 0;
E1.clear();
EReg1.clear();
Eta1.clear();
UseEle1.clear();
Phi1.clear();
E2.clear();
EReg2.clear();
Eta2.clear();
Phi2.clear();
UseEle2.clear();
// loop over all events and select events
for (int i=0; i<nEventsAll; i++)
{
// EB or EE combinatioin check
if ( Combine=="EBEB" ) // both in EB
{
if ( !(fabs(allEta1[i])<1.48&&fabs(allEta2[i])<1.48) ) continue;
}
if ( Combine=="EBEE" ) // one in EB one in EE
{
if ( !( (fabs(allEta1[i])<1.48&&fabs(allEta2[i])>1.48)||(fabs(allEta2[i])<1.48&&fabs(allEta1[i])>1.48) ) ) continue;
}
if ( Combine=="EEEE" ) // both in EE
{
if ( !(fabs(allEta1[i])>1.48&&fabs(allEta2[i])>1.48) ) continue;
}
if ( Combine=="EE" ) // any one of the two in EE
{
if ( !(fabs(allEta1[i])>1.48||fabs(allEta2[i])>1.48) ) continue;
}
if ( Combine=="EB" ) // any one of the two in EB
{
if ( !(fabs(allEta1[i])<1.48||fabs(allEta2[i])<1.48) ) continue;
}
// note, if not any of the string above, this event will always pass this check.
// check which electron in this eta-ring
bool takeEle1(false), takeEle2(false);
if (allEta1.at(i)>bin_min&&allEta1.at(i)<bin_max) takeEle1 = true;