-
Notifications
You must be signed in to change notification settings - Fork 4.4k
/
Copy pathHcalTopology.cc
1705 lines (1620 loc) · 62.5 KB
/
HcalTopology.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
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 "Geometry/CaloTopology/interface/HcalTopology.h"
#include <cmath>
#include <iostream>
#include <cassert>
#include <algorithm>
#include "FWCore/Utilities/interface/Exception.h"
#include "FWCore/MessageLogger/interface/MessageLogger.h"
#include "DataFormats/Math/interface/GeantUnits.h"
using namespace geant_units;
using namespace geant_units::operators;
static const int IPHI_MAX = 72;
//#define EDM_ML_DEBUG
HcalTopology::HcalTopology(const HcalDDDRecConstants* hcons, const bool mergePosition)
: hcons_(hcons),
mergePosition_(mergePosition),
excludeHB_(false),
excludeHE_(false),
excludeHO_(false),
excludeHF_(false),
firstHBRing_(1),
firstHERing_(999),
lastHERing_(0),
firstHFRing_(29),
lastHFRing_(41),
firstHORing_(1),
lastHORing_(15),
firstHEDoublePhiRing_(999),
firstHEQuadPhiRing_(999),
firstHFQuadPhiRing_(40),
firstHETripleDepthRing_(999),
singlePhiBins_(IPHI_MAX),
doublePhiBins_(36),
maxPhiHE_(IPHI_MAX) {
mode_ = (HcalTopologyMode::Mode)(hcons_->getTopoMode());
triggerMode_ = (HcalTopologyMode::TriggerMode)(hcons_->getTriggerMode());
maxDepthHB_ = hcons_->getMaxDepth(0);
maxDepthHE_ = hcons_->getMaxDepth(1);
maxDepthHF_ = hcons_->getMaxDepth(2);
etaBinsHB_ = hcons_->getEtaBins(0);
etaBinsHE_ = hcons_->getEtaBins(1);
nEtaHB_ = (hcons_->getEtaRange(0)).second - (hcons_->getEtaRange(0)).first + 1;
lastHBRing_ = firstHBRing_ + nEtaHB_ - 1;
if (hcons_->getNPhi(1) > maxPhiHE_)
maxPhiHE_ = hcons_->getNPhi(1);
for (auto& i : etaBinsHE_) {
if (firstHERing_ > i.ieta)
firstHERing_ = i.ieta;
if (lastHERing_ < i.ieta)
lastHERing_ = i.ieta;
int unit = static_cast<int>((i.dphi / 5.0_deg) + 0.01);
if (unit == 2 && firstHEDoublePhiRing_ > i.ieta)
firstHEDoublePhiRing_ = i.ieta;
if (unit == 4 && firstHEQuadPhiRing_ > i.ieta)
firstHEQuadPhiRing_ = i.ieta;
if (i.layer.size() > 2 && firstHETripleDepthRing_ > i.ieta)
firstHETripleDepthRing_ = i.ieta;
}
if (firstHERing_ > lastHERing_) {
firstHERing_ = lastHERing_ = firstHEDoublePhiRing_ = firstHEQuadPhiRing_ = firstHETripleDepthRing_ = nEtaHE_ = 0;
} else {
nEtaHE_ = (lastHERing_ - firstHERing_ + 1);
}
if (mode_ == HcalTopologyMode::LHC) {
topoVersion_ = 0; //DL
HBSize_ = kHBSizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/barrel * barrel/hcal
HESize_ = kHESizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/endcap * endcap/hcal
HOSize_ = kHOSizePreLS1; // ieta * iphi * 2
HFSize_ = kHFSizePreLS1; // ieta * iphi * depth * 2
CALIBSize_ = kCALIBSizePreLS1;
numberOfShapes_ = 87;
} else if (mode_ == HcalTopologyMode::SLHC) { // need to know more eventually
topoVersion_ = 10;
HBSize_ = nEtaHB_ * IPHI_MAX * maxDepthHB_ * 2;
HESize_ = nEtaHE_ * maxPhiHE_ * maxDepthHE_ * 2;
HOSize_ = (lastHORing_ - firstHORing_ + 1) * IPHI_MAX * 2; // ieta * iphi * 2
HFSize_ = (lastHFRing_ - firstHFRing_ + 1) * IPHI_MAX * maxDepthHF_ * 2; // ieta * iphi * depth * 2
CALIBSize_ = kOffCalibHFX_;
numberOfShapes_ = (maxPhiHE_ > 72) ? 1200 : 500;
}
maxEta_ = (lastHERing_ > lastHFRing_) ? lastHERing_ : lastHFRing_;
if (triggerMode_ == HcalTopologyMode::TriggerMode_2009) {
HTSize_ = kHTSizePreLS1;
} else {
HTSize_ = kHTSizePhase1;
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "Topo sizes " << HBSize_ << ":" << HESize_ << ":" << HOSize_ << ":" << HFSize_ << ":"
<< HTSize_ << ":" << CALIBSize_ << " for mode " << mode_ << ":" << triggerMode_;
#endif
//The transition between HE/HF in eta
etaTableHF = hcons_->getEtaTableHF();
etaTable = hcons_->getEtaTable();
dPhiTableHF = hcons_->getPhiTableHF();
dPhiTable = hcons_->getPhiTable();
phioff = hcons_->getPhiOffs();
std::pair<int, int> ietaHF = hcons_->getEtaRange(2);
etaHE2HF_ = firstHFRing_;
etaHF2HE_ = lastHERing_;
if (etaBinsHE_.size() > 1) {
double eta = etaBinsHE_[etaBinsHE_.size() - 1].etaMax;
for (unsigned int i = 1; i < etaTableHF.size(); ++i) {
if (eta < etaTableHF[i]) {
etaHE2HF_ = ietaHF.first + i - 1;
break;
}
}
eta = etaTableHF[0];
for (auto& i : etaBinsHE_) {
if (eta < i.etaMax) {
etaHF2HE_ = i.ieta;
break;
}
}
}
const double fiveDegInRad = 5.0_deg;
for (double k : dPhiTable) {
int units = (int)(k / fiveDegInRad + 0.5);
unitPhi.emplace_back(units);
}
for (double k : dPhiTableHF) {
int units = (int)(k / fiveDegInRad + 0.5);
unitPhiHF.emplace_back(units);
}
int nEta = hcons_->getNEta();
for (int ring = 1; ring <= nEta; ++ring) {
std::vector<int> segmentation = hcons_->getDepth(ring - 1, false);
setDepthSegmentation(ring, segmentation, false);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "Set segmentation for ring " << ring << " with " << segmentation.size()
<< " elements:";
for (unsigned int k = 0; k < segmentation.size(); ++k)
edm::LogVerbatim("HCalGeom") << "[" << k << "] " << segmentation[k];
#endif
segmentation = hcons_->getDepth(ring - 1, true);
setDepthSegmentation(ring, segmentation, true);
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "Set Plan-1 segmentation for ring " << ring << " with " << segmentation.size()
<< " elements:";
for (unsigned int k = 0; k < segmentation.size(); ++k)
edm::LogVerbatim("HCalGeom") << "[" << k << "] " << segmentation[k];
#endif
}
#ifdef EDM_ML_DEBUG
edm::LogVerbatim("HCalGeom") << "Constants in HcalTopology " << firstHBRing_ << ":" << lastHBRing_ << " "
<< firstHERing_ << ":" << lastHERing_ << ":" << firstHEDoublePhiRing_ << ":"
<< firstHEQuadPhiRing_ << ":" << firstHETripleDepthRing_ << " " << firstHFRing_ << ":"
<< lastHFRing_ << ":" << firstHFQuadPhiRing_ << " " << firstHORing_ << ":" << lastHORing_
<< " " << maxDepthHB_ << ":" << maxDepthHE_ << " " << nEtaHB_ << ":" << nEtaHE_ << " "
<< etaHE2HF_ << ":" << etaHF2HE_ << " " << maxPhiHE_;
#endif
}
HcalTopology::HcalTopology(HcalTopologyMode::Mode mode,
int maxDepthHB,
int maxDepthHE,
HcalTopologyMode::TriggerMode tmode)
: hcons_(nullptr),
mergePosition_(false),
excludeHB_(false),
excludeHE_(false),
excludeHO_(false),
excludeHF_(false),
mode_(mode),
triggerMode_(tmode),
firstHBRing_(1),
lastHBRing_(16),
firstHERing_(16),
lastHERing_(29),
firstHFRing_(29),
lastHFRing_(41),
firstHORing_(1),
lastHORing_(15),
firstHEDoublePhiRing_((mode == HcalTopologyMode::H2 || mode == HcalTopologyMode::H2HE) ? (22) : (21)),
firstHEQuadPhiRing_(999),
firstHFQuadPhiRing_(40),
firstHETripleDepthRing_((mode == HcalTopologyMode::H2 || mode == HcalTopologyMode::H2HE) ? (24) : (27)),
singlePhiBins_(IPHI_MAX),
doublePhiBins_(36),
maxDepthHB_(maxDepthHB),
maxDepthHE_(maxDepthHE),
maxDepthHF_(2),
etaHE2HF_(30),
etaHF2HE_(29),
maxPhiHE_(IPHI_MAX),
HBSize_(kHBSizePreLS1),
HESize_(kHESizePreLS1),
HOSize_(kHOSizePreLS1),
HFSize_(kHFSizePreLS1),
HTSize_(kHTSizePreLS1),
CALIBSize_(kCALIBSizePreLS1),
numberOfShapes_(
((mode == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::Run3) || (mode_ == HcalTopologyMode::Run4))
? 500
: 87) {
if (mode_ == HcalTopologyMode::LHC) {
topoVersion_ = 0; //DL
HBSize_ = kHBSizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/barrel * barrel/hcal
HESize_ = kHESizePreLS1; // qie-per-fiber * fiber/rm * rm/rbx * rbx/endcap * endcap/hcal
HOSize_ = kHOSizePreLS1; // ieta * iphi * 2
HFSize_ = kHFSizePreLS1; // phi * eta * depth * pm
} else if ((mode_ == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::Run3) ||
(mode_ == HcalTopologyMode::Run4)) { // need to know more eventually
HBSize_ = maxDepthHB * 16 * IPHI_MAX * 2;
HESize_ = maxDepthHE * (29 - 16 + 1) * maxPhiHE_ * 2;
HOSize_ = 15 * IPHI_MAX * 2; // ieta * iphi * 2
HFSize_ = IPHI_MAX * 13 * maxDepthHF_ * 2; // phi * eta * depth * pm
CALIBSize_ = kOffCalibHFX_;
topoVersion_ = 10;
}
nEtaHB_ = (lastHBRing_ - firstHBRing_ + 1);
nEtaHE_ = (lastHERing_ - firstHERing_ + 1);
if (triggerMode_ == HcalTopologyMode::TriggerMode_2009) {
HTSize_ = kHTSizePreLS1;
} else {
HTSize_ = kHTSizePhase1;
}
edm::LogWarning("HCalGeom") << "This is an incomplete constructor of HcalTopology - be warned that many "
<< "functionalities will not be there - revert from this - get from EventSetup";
}
bool HcalTopology::valid(const DetId& id) const {
assert(id.det() == DetId::Hcal);
return validHcal(id);
}
bool HcalTopology::validHcal(const HcalDetId& id) const {
// check the raw rules
return validRaw(id) && !isExcluded(id);
}
bool HcalTopology::validDetId(HcalSubdetector subdet, int ieta, int iphi, int depth) const {
return validHcal(HcalDetId(subdet, ieta, iphi, depth));
}
bool HcalTopology::validHT(const HcalTrigTowerDetId& id) const {
if (id.iphi() < 1 || id.iphi() > IPHI_MAX || id.ieta() == 0)
return false;
if (id.depth() != 0)
return false;
if (maxDepthHE_ == 0) {
if (id.ietaAbs() > lastHBRing_ && id.ietaAbs() < firstHFRing_)
return false;
}
// Version 2 TPs should be for HBHE when using 1TS filter scheme
if (id.version() == 0 or id.version() == 2) {
if (id.ietaAbs() > 28) {
if (triggerMode_ >= HcalTopologyMode::TriggerMode_2017)
return false;
if (triggerMode_ == HcalTopologyMode::TriggerMode_2018legacy)
return false;
if ((id.iphi() % 4) != 1)
return false;
if (id.ietaAbs() > 32)
return false;
}
} else if (id.version() == 1) {
if (triggerMode_ == HcalTopologyMode::TriggerMode_2009)
return false;
if (id.ietaAbs() < 30 || id.ietaAbs() > 41)
return false;
if (id.ietaAbs() > 29 && ((id.iphi() % 2) == 0))
return false;
if (id.ietaAbs() > 39 && ((id.iphi() % 4) != 3))
return false;
} else if (id.version() > 2) {
// only versions 0, 1, and 2 are supported
return false;
}
return true;
}
bool HcalTopology::validCalib(const HcalCalibDetId& tid) const {
bool ok(false);
if (tid.calibFlavor() == HcalCalibDetId::CalibrationBox) {
HcalSubdetector subdet = tid.hcalSubdet();
int ieta = tid.ieta();
int chan = tid.cboxChannel();
unsigned int iphi = static_cast<unsigned int>(tid.iphi());
if (subdet == HcalBarrel) {
if ((std::find(etaCalibHB_, etaCalibHB_ + nEtaCalibHB_, ieta) != (etaCalibHB_ + nEtaCalibHB_)) &&
(std::find(chanCalibHB_, chanCalibHB_ + nchanCalibHB_, chan) != (chanCalibHB_ + nchanCalibHB_)) &&
(iphi >= minPhi_) && (iphi <= maxPhi_))
ok = true;
} else if (subdet == HcalEndcap) {
if ((std::find(etaCalibHE_, etaCalibHE_ + nEtaCalibHE_, ieta) != (etaCalibHE_ + nEtaCalibHE_)) &&
(std::find(chanCalibHE1_, chanCalibHE1_ + nchanCalibHE1_, chan) != (chanCalibHE1_ + nchanCalibHE1_) ||
(chan == chanCalibHE2_)) &&
(iphi >= minPhi_) && (iphi <= maxPhi_))
ok = true;
} else if (subdet == HcalForward) {
if ((std::find(etaCalibHF_, etaCalibHF_ + nEtaCalibHF_, ieta) != (etaCalibHF_ + nEtaCalibHF_)) &&
(std::find(chanCalibHF1_, chanCalibHF1_ + nchanCalibHF1_, chan) != (chanCalibHF1_ + nchanCalibHF1_) ||
(chan == chanCalibHF2_)) &&
(iphi >= minPhi_) && (iphi <= maxPhi_))
ok = true;
} else if (subdet == HcalOuter) {
if ((std::find(etaCalibHO_, etaCalibHO_ + nEtaCalibHO_, ieta) != (etaCalibHO_ + nEtaCalibHO_)) &&
(std::find(chanCalibHO_, chanCalibHO_ + nchanCalibHO_, chan) != (chanCalibHO_ + nchanCalibHO_) ||
(chan == chanCalibHOs_)) &&
(iphi >= minPhi_) && (iphi <= maxPhi_))
ok = true;
}
} else if (tid.calibFlavor() == HcalCalibDetId::HOCrosstalk) {
int ieta = std::abs(tid.ieta());
unsigned int iphi = static_cast<unsigned int>(tid.iphi());
if ((std::find(etaCalibHOX_, etaCalibHOX_ + nEtaCalibHOX_, ieta) != (etaCalibHOX_ + nEtaCalibHOX_)) &&
(iphi >= minPhi_) && (iphi <= maxPhi_))
ok = true;
} else if (tid.calibFlavor() == HcalCalibDetId::HBX) {
int ieta = std::abs(tid.ieta());
unsigned int iphi = static_cast<unsigned int>(tid.iphi());
if ((ieta == etaCalibHBX_) && (iphi >= minPhi_) && (iphi <= maxPhi_))
ok = true;
} else if (tid.calibFlavor() == HcalCalibDetId::HEX) {
int ieta = std::abs(tid.ieta());
unsigned int iphi = static_cast<unsigned int>(tid.iphi());
if ((std::find(etaCalibHEX_, etaCalibHEX_ + nEtaCalibHEX_, ieta) != (etaCalibHEX_ + nEtaCalibHEX_)) &&
(iphi >= minPhi_) && (iphi <= maxPhi_))
ok = true;
} else if ((tid.calibFlavor() == HcalCalibDetId::uMNqie) || (tid.calibFlavor() == HcalCalibDetId::LASERMON) ||
(tid.calibFlavor() == HcalCalibDetId::CastorRadFacility)) {
ok = true;
}
return ok;
}
bool HcalTopology::validHcal(const HcalDetId& id, const unsigned int flag) const {
/* original logic show here because condensed form below is rather terse
// check the raw rules
bool ok = validHcal(id);
if (flag == 0) { // This is all what is needed
} else if (flag == 1) { // See if it is in the to be merged list and merged list
if (hcons_->isPlan1MergedId(id)) ok = true;
else if (hcons_->isPlan1ToBeMergedId(id)) ok = false;
} else if (!ok) {
ok = hcons_->isPlan1MergedId(id);
}
return ok;
*/
return (flag > 0 and hcons_->isPlan1MergedId(id)) or
((flag != 1 or !hcons_->isPlan1ToBeMergedId(id)) and validHcal(id));
}
bool HcalTopology::isExcluded(const HcalDetId& id) const {
bool exed = false;
// first, check the full detector exclusions... (fast)
switch (id.subdet()) {
case (HcalBarrel):
exed = excludeHB_;
break;
case (HcalEndcap):
exed = excludeHE_;
break;
case (HcalOuter):
exed = excludeHO_;
break;
case (HcalForward):
exed = excludeHF_;
break;
default:
exed = false;
}
// next, check the list (slower)
if (!exed && !exclusionList_.empty()) {
std::vector<HcalDetId>::const_iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
if (i != exclusionList_.end() && *i == id)
exed = true;
}
return exed;
}
void HcalTopology::exclude(const HcalDetId& id) {
std::vector<HcalDetId>::iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
if (i == exclusionList_.end() || *i != id) {
exclusionList_.insert(i, id);
}
}
void HcalTopology::excludeSubdetector(HcalSubdetector subdet) {
switch (subdet) {
case (HcalBarrel):
excludeHB_ = true;
break;
case (HcalEndcap):
excludeHE_ = true;
break;
case (HcalOuter):
excludeHO_ = true;
break;
case (HcalForward):
excludeHF_ = true;
break;
default:
break;
}
}
std::vector<DetId> HcalTopology::east(const DetId& id) const {
std::vector<DetId> vNeighborsDetId;
HcalDetId neighbors[2];
for (int i = 0; i < decIEta(HcalDetId(id), neighbors); i++) {
if (neighbors[i].oldFormat())
neighbors[i].changeForm();
vNeighborsDetId.emplace_back(DetId(neighbors[i].rawId()));
}
return vNeighborsDetId;
}
std::vector<DetId> HcalTopology::west(const DetId& id) const {
std::vector<DetId> vNeighborsDetId;
HcalDetId neighbors[2];
for (int i = 0; i < incIEta(HcalDetId(id), neighbors); i++) {
if (neighbors[i].oldFormat())
neighbors[i].changeForm();
vNeighborsDetId.emplace_back(DetId(neighbors[i].rawId()));
}
return vNeighborsDetId;
}
std::vector<DetId> HcalTopology::north(const DetId& id) const {
std::vector<DetId> vNeighborsDetId;
HcalDetId neighbor;
if (incIPhi(HcalDetId(id), neighbor)) {
if (neighbor.oldFormat())
neighbor.changeForm();
vNeighborsDetId.emplace_back(DetId(neighbor.rawId()));
}
return vNeighborsDetId;
}
std::vector<DetId> HcalTopology::south(const DetId& id) const {
std::vector<DetId> vNeighborsDetId;
HcalDetId neighbor;
if (decIPhi(HcalDetId(id), neighbor)) {
if (neighbor.oldFormat())
neighbor.changeForm();
vNeighborsDetId.emplace_back(DetId(neighbor.rawId()));
}
return vNeighborsDetId;
}
std::vector<DetId> HcalTopology::up(const DetId& id) const {
HcalDetId neighbor = id;
std::vector<DetId> vNeighborsDetId;
if (incrementDepth(neighbor)) {
if (neighbor.oldFormat())
neighbor.changeForm();
vNeighborsDetId.emplace_back(neighbor);
}
return vNeighborsDetId;
}
std::vector<DetId> HcalTopology::down(const DetId& id) const {
HcalDetId neighbor = id;
std::vector<DetId> vNeighborsDetId;
if (decrementDepth(neighbor)) {
if (neighbor.oldFormat())
neighbor.changeForm();
vNeighborsDetId.emplace_back(neighbor);
}
return vNeighborsDetId;
}
int HcalTopology::exclude(HcalSubdetector subdet, int ieta1, int ieta2, int iphi1, int iphi2, int depth1, int depth2) {
bool exed = false;
// first, check the full detector exclusions... (fast)
switch (subdet) {
case (HcalBarrel):
exed = excludeHB_;
break;
case (HcalEndcap):
exed = excludeHE_;
break;
case (HcalOuter):
exed = excludeHO_;
break;
case (HcalForward):
exed = excludeHF_;
break;
default:
exed = false;
}
if (exed)
return 0; // if the whole detector is excluded...
int ieta_l = std::min(ieta1, ieta2);
int ieta_h = std::max(ieta1, ieta2);
int iphi_l = std::min(iphi1, iphi2);
int iphi_h = std::max(iphi1, iphi2);
int depth_l = std::min(depth1, depth2);
int depth_h = std::max(depth1, depth2);
int n = 0;
for (int ieta = ieta_l; ieta <= ieta_h; ieta++)
for (int iphi = iphi_l; iphi <= iphi_h; iphi++)
for (int depth = depth_l; depth <= depth_h; depth++) {
HcalDetId id(subdet, ieta, iphi, depth);
if (validRaw(id)) { // use 'validRaw' to include check validity in "uncut" detector
exclude(id);
n++;
}
}
return n;
}
/** Basic rules used to derive this code:
HB has 72 towers in iphi. Ieta 1-14 have depth=1, Ieta 15-16 have depth=1 or 2.
HE ieta=16-20 have 72 towers in iphi
ieta=21-29 have 36 towers in iphi
ieta=16 is depth 3 only
ieta=17 is depth 1 only
ieta=18-26 & 29 have depth 1 and 2
ieta=27-28 has depth 1-3
HF ieta=29-39 have 36 in iphi
ieta=40-41 have 18 in iphi (71,3,7,11...)
all have two depths
HO has 15 towers in ieta and 72 in iphi and depth = 4 (one value)
At H2:
HE ieta 17 is two depths
HE ieta 22- have 36 towers in iphi (starts one higher)
HE ieta 24- has three depths
*/
bool HcalTopology::validDetIdPreLS1(const HcalDetId& id) const {
const HcalSubdetector sd(id.subdet());
const int ie(id.ietaAbs());
const int ip(id.iphi());
const int dp(id.depth());
return ((ip >= 1) && (ip <= IPHI_MAX) && (dp >= 1) && (ie >= 1) &&
(((sd == HcalBarrel) && (((ie <= 14) && (dp == 1)) || (((ie == 15) || (ie == 16)) && (dp <= 2)))) ||
((sd == HcalEndcap) &&
(((ie == firstHERing()) && (dp == 3)) || ((ie == 17) && (dp == 1)) ||
((ie >= 18) && (ie <= 20) && (dp <= 2)) || ((ie >= 21) && (ie <= 26) && (dp <= 2) && (ip % 2 == 1)) ||
((ie >= 27) && (ie <= 28) && (dp <= 3) && (ip % 2 == 1)) || ((ie == 29) && (dp <= 2) && (ip % 2 == 1)))) ||
((sd == HcalOuter) && (ie <= 15) && (dp == 4)) ||
((sd == HcalForward) && (dp <= 2) &&
(((ie >= firstHFRing()) && (ie < firstHFQuadPhiRing()) && (ip % 2 == 1)) ||
((ie >= firstHFQuadPhiRing()) && (ie <= lastHFRing()) && (ip % 4 == 3))))));
}
/** Is this a valid cell id? */
bool HcalTopology::validRaw(const HcalDetId& id) const {
bool ok = true;
int ieta = id.ieta();
int aieta = id.ietaAbs();
int depth = id.depth();
int iphi = id.iphi();
int zside = id.zside();
HcalSubdetector subdet = id.subdet();
int maxPhi = (subdet == HcalEndcap) ? maxPhiHE_ : IPHI_MAX;
if ((ieta == 0 || iphi <= 0 || iphi > maxPhi) || aieta > maxEta_)
ok = false; // outer limits
if (ok) {
if (subdet == HcalBarrel) {
if ((mode_ == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::H2HE) || (mode_ == HcalTopologyMode::Run3) ||
(mode_ == HcalTopologyMode::Run4)) {
if ((aieta > lastHBRing()) || (depth > hcons_->getMaxDepth(0, aieta, iphi, zside)) ||
(depth < hcons_->getMinDepth(0, aieta, iphi, zside)))
ok = false;
} else {
if (aieta > lastHBRing() || depth > 2 || (aieta <= 14 && depth > 1))
ok = false;
}
} else if (subdet == HcalEndcap) {
if ((mode_ == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::H2HE) || (mode_ == HcalTopologyMode::Run3) ||
(mode_ == HcalTopologyMode::Run4)) {
if ((depth > hcons_->getMaxDepth(1, aieta, iphi, zside)) ||
(depth < hcons_->getMinDepth(1, aieta, iphi, zside)) || (aieta < firstHERing()) || (aieta > lastHERing())) {
ok = false;
} else {
for (const auto& i : etaBinsHE_) {
if (aieta == i.ieta) {
if (aieta >= firstHEDoublePhiRing() && (iphi % 2) == 0)
ok = false;
if (aieta >= firstHEQuadPhiRing() && (iphi % 4) != 3)
ok = false;
if (aieta + 1 == hcons_->getNoff(1)) {
if (depth < 1)
ok = false;
} else {
if (depth < i.depthStart)
ok = false;
}
break;
}
}
}
} else {
if (depth > hcons_->getMaxDepth(1, aieta, iphi, zside) || aieta < firstHERing() || aieta > lastHERing() ||
(aieta == firstHERing() && depth != hcons_->getDepthEta16(2, iphi, zside)) ||
(aieta == 17 && depth != 1 && mode_ != HcalTopologyMode::H2) || // special case at H2
(((aieta >= 17 && aieta < firstHETripleDepthRing()) || aieta == lastHERing()) && depth > 2) ||
(aieta >= firstHEDoublePhiRing() && (iphi % 2) == 0))
ok = false;
}
} else if (subdet == HcalOuter) {
if (aieta > lastHORing() || iphi > IPHI_MAX || depth != 4)
ok = false;
} else if (subdet == HcalForward) {
if (aieta < firstHFRing() || aieta > lastHFRing() || ((iphi % 2) == 0) ||
(depth > hcons_->maxHFDepth(ieta, iphi)) || (aieta >= firstHFQuadPhiRing() && ((iphi + 1) % 4) != 0))
ok = false;
} else if (subdet == HcalTriggerTower) {
ok = validHT(HcalTrigTowerDetId(id.rawId()));
} else if (subdet == HcalOther) {
ok = validCalib(HcalCalibDetId(id.rawId()));
} else {
ok = false;
}
}
return ok;
}
bool HcalTopology::incIPhi(const HcalDetId& id, HcalDetId& neighbor) const {
bool ok = valid(id);
if (ok) {
switch (id.subdet()) {
case (HcalBarrel):
case (HcalOuter):
if (id.iphi() == IPHI_MAX)
neighbor = HcalDetId(id.subdet(), id.ieta(), 1, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 1, id.depth());
break;
case (HcalEndcap):
if (id.ietaAbs() >= firstHEQuadPhiRing()) {
if (id.iphi() == IPHI_MAX - 1)
neighbor = HcalDetId(id.subdet(), id.ieta(), 3, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 4, id.depth());
} else if (id.ietaAbs() >= firstHEDoublePhiRing()) {
if (id.iphi() == IPHI_MAX - 1)
neighbor = HcalDetId(id.subdet(), id.ieta(), 1, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 2, id.depth());
} else {
if (id.iphi() == maxPhiHE_)
neighbor = HcalDetId(id.subdet(), id.ieta(), 1, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 1, id.depth());
}
break;
case (HcalForward):
if (id.ietaAbs() >= firstHFQuadPhiRing()) {
if (id.iphi() == IPHI_MAX - 1)
neighbor = HcalDetId(id.subdet(), id.ieta(), 3, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 4, id.depth());
} else {
if (id.iphi() == IPHI_MAX - 1)
neighbor = HcalDetId(id.subdet(), id.ieta(), 1, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() + 2, id.depth());
}
if (!validRaw(neighbor))
ok = false;
break;
default:
ok = false;
}
}
return ok;
}
/** Get the neighbor (if present) of the given cell with lower iphi */
bool HcalTopology::decIPhi(const HcalDetId& id, HcalDetId& neighbor) const {
bool ok = valid(id);
if (ok) {
switch (id.subdet()) {
case (HcalBarrel):
case (HcalOuter):
if (id.iphi() == 1)
neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 1, id.depth());
break;
case (HcalEndcap):
if (id.ietaAbs() >= firstHEQuadPhiRing()) {
if (id.iphi() == 3)
neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX - 1, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 4, id.depth());
} else if (id.ietaAbs() >= firstHEDoublePhiRing()) {
if (id.iphi() == 1)
neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX - 1, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 2, id.depth());
} else {
if (id.iphi() == 1)
neighbor = HcalDetId(id.subdet(), id.ieta(), maxPhiHE_, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 1, id.depth());
}
break;
case (HcalForward):
if (id.ietaAbs() >= firstHFQuadPhiRing()) {
if (id.iphi() == 3)
neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX - 1, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 4, id.depth());
} else {
if (id.iphi() == 1)
neighbor = HcalDetId(id.subdet(), id.ieta(), IPHI_MAX - 1, id.depth());
else
neighbor = HcalDetId(id.subdet(), id.ieta(), id.iphi() - 2, id.depth());
}
if (!validRaw(neighbor))
ok = false;
break;
default:
ok = false;
}
}
return ok;
}
int HcalTopology::incIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
if (id.zside() == 1)
return incAIEta(id, neighbors);
else
return decAIEta(id, neighbors);
}
int HcalTopology::decIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
if (id.zside() == 1)
return decAIEta(id, neighbors);
else
return incAIEta(id, neighbors);
}
/** Increasing in |ieta|, there is always at most one neighbor */
int HcalTopology::incAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
int n = 1;
int aieta = id.ietaAbs();
if (aieta == firstHEDoublePhiRing() - 1 && (id.iphi() % 2) == 0)
neighbors[0] = HcalDetId(id.subdet(), (aieta + 1) * id.zside(), id.iphi() - 1, id.depth());
else if (aieta == firstHFQuadPhiRing() - 1 && ((id.iphi() + 1) % 4) != 0)
neighbors[0] =
HcalDetId(id.subdet(), (aieta + 1) * id.zside(), ((id.iphi() == 1) ? (71) : (id.iphi() - 2)), id.depth());
else if (aieta == firstHEQuadPhiRing() - 1 && ((id.iphi() + 1) % 4) != 0)
neighbors[0] =
HcalDetId(id.subdet(), (aieta + 1) * id.zside(), ((id.iphi() == 1) ? (71) : (id.iphi() - 2)), id.depth());
else if (aieta == lastHBRing() && id.subdet() == HcalBarrel)
neighbors[0] = HcalDetId(HcalEndcap, (aieta + 1) * id.zside(), id.iphi(), 1);
else if (aieta == lastHERing() && id.subdet() == HcalEndcap)
neighbors[0] = HcalDetId(HcalForward, etaHE2HF_ * id.zside(), id.iphi(), 1);
else
neighbors[0] = HcalDetId(id.subdet(), (aieta + 1) * id.zside(), id.iphi(), id.depth());
if (!valid(neighbors[0]))
n = 0;
return n;
}
/** Decreasing in |ieta|, there are two neighbors of 40 and 21*/
int HcalTopology::decAIEta(const HcalDetId& id, HcalDetId neighbors[2]) const {
int n = 1;
int aieta = id.ietaAbs();
if (aieta == firstHEDoublePhiRing()) {
n = 2;
neighbors[0] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi(), id.depth());
neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi() + 1, id.depth());
} else if (aieta == firstHFQuadPhiRing()) {
n = 2;
neighbors[0] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi(), id.depth());
if (id.iphi() == IPHI_MAX - 1)
neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), 1, id.depth());
else
neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi() + 2, id.depth());
} else if (aieta == firstHEQuadPhiRing()) {
n = 2;
neighbors[0] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi(), id.depth());
if (id.iphi() == IPHI_MAX - 1)
neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), 1, id.depth());
else
neighbors[1] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi() + 2, id.depth());
} else if (aieta == 1) {
neighbors[0] = HcalDetId(id.subdet(), -aieta * id.zside(), id.iphi(), id.depth());
} else if (aieta == firstHERing() && id.subdet() == HcalEndcap) {
neighbors[0] = HcalDetId(HcalBarrel, (aieta - 1) * id.zside(), id.iphi(), 1);
} else if (aieta == firstHFRing() && id.subdet() == HcalForward) {
neighbors[0] = HcalDetId(HcalEndcap, etaHF2HE_ * id.zside(), id.iphi(), 1);
} else
neighbors[0] = HcalDetId(id.subdet(), (aieta - 1) * id.zside(), id.iphi(), id.depth());
if (!valid(neighbors[0]) && n == 2) {
if (!valid(neighbors[1]))
n = 0;
else {
n = 1;
neighbors[0] = neighbors[1];
}
}
if (n == 2 && !valid(neighbors[1]))
n = 1;
if (n == 1 && !valid(neighbors[0]))
n = 0;
return n;
}
void HcalTopology::depthBinInformation(
HcalSubdetector subdet, int etaRing, int iphi, int zside, int& nDepthBins, int& startingBin) const {
if (subdet == HcalBarrel) {
if ((mode_ == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::H2HE) || (mode_ == HcalTopologyMode::Run3) ||
(mode_ == HcalTopologyMode::Run4)) {
startingBin = hcons_->getMinDepth(0, etaRing, iphi, zside);
if (etaRing == lastHBRing()) {
nDepthBins = hcons_->getDepthEta16(1, iphi, zside) - startingBin + 1;
} else {
nDepthBins = hcons_->getMaxDepth(0, etaRing, iphi, zside) - startingBin + 1;
}
} else {
if (etaRing <= 14) {
nDepthBins = 1;
startingBin = 1;
} else {
nDepthBins = 2;
startingBin = 1;
}
}
} else if (subdet == HcalEndcap) {
if ((mode_ == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::H2HE) || (mode_ == HcalTopologyMode::Run3) ||
(mode_ == HcalTopologyMode::Run4)) {
if (etaRing == firstHERing()) {
startingBin = hcons_->getDepthEta16(2, iphi, zside);
} else {
startingBin = hcons_->getMinDepth(1, etaRing, iphi, zside);
}
nDepthBins = hcons_->getMaxDepth(1, etaRing, iphi, zside) - startingBin + 1;
} else {
if (etaRing == firstHERing()) {
nDepthBins = 1;
startingBin = 3;
} else if (etaRing == 17) {
nDepthBins = 1;
startingBin = 1;
} else if (etaRing == lastHERing()) {
nDepthBins = 2;
startingBin = 1;
} else {
nDepthBins = (etaRing >= firstHETripleDepthRing()) ? 3 : 2;
startingBin = 1;
}
}
} else if (subdet == HcalForward) {
nDepthBins = maxDepthHF_;
startingBin = 1;
} else if (subdet == HcalOuter) {
nDepthBins = 1;
startingBin = 4;
} else {
edm::LogWarning("HCalGeom") << "Bad HCAL subdetector " << subdet;
}
}
bool HcalTopology::incrementDepth(HcalDetId& detId) const {
HcalSubdetector subdet = detId.subdet();
int ieta = detId.ieta();
int etaRing = detId.ietaAbs();
int depth = detId.depth();
int iphi = detId.iphi();
int zside = detId.zside();
int nDepthBins(0), startingBin(0);
depthBinInformation(subdet, etaRing, iphi, zside, nDepthBins, startingBin);
// see if the new depth bin exists
++depth;
if (depth >= (startingBin + nDepthBins)) {
// handle on a case-by-case basis
if (subdet == HcalBarrel && etaRing < lastHORing()) {
// HO
subdet = HcalOuter;
depth = 4;
} else if (subdet == HcalBarrel && etaRing == lastHBRing()) {
// overlap
subdet = HcalEndcap;
if ((mode_ == HcalTopologyMode::SLHC) || (mode_ == HcalTopologyMode::H2HE) || (mode_ == HcalTopologyMode::Run3) ||
(mode_ == HcalTopologyMode::Run4))
depth = hcons_->getDepthEta16(2, iphi, zside);
} else if ((subdet == HcalEndcap) && (etaRing == lastHERing() - 1) && (mode_ != HcalTopologyMode::SLHC) &&
(mode_ != HcalTopologyMode::Run3) && (mode_ != HcalTopologyMode::Run4)) {
// guard ring HF29 is behind HE 28
subdet = HcalForward;
(ieta > 0) ? ++ieta : --ieta;
depth = 1;
} else if ((subdet == HcalEndcap) && (etaRing == lastHERing()) && (mode_ != HcalTopologyMode::SLHC) &&
(mode_ != HcalTopologyMode::Run3) && (mode_ != HcalTopologyMode::Run4)) {
// split cells go to bigger granularity. Ring 29 -> 28
(ieta > 0) ? --ieta : ++ieta;
} else {
// no more chances
detId = HcalDetId();
return false;
}
}
detId = HcalDetId(subdet, ieta, iphi, depth);
return validRaw(detId);
}
bool HcalTopology::decrementDepth(HcalDetId& detId) const {
HcalSubdetector subdet = detId.subdet();
int ieta = detId.ieta();
int etaRing = detId.ietaAbs();
int depth = detId.depth();
int iphi = detId.iphi();
int zside = detId.zside();
int nDepthBins, startingBin;
depthBinInformation(subdet, etaRing, iphi, zside, nDepthBins, startingBin);
// see if the new depth bin exists
--depth;
if ((subdet == HcalOuter) || (subdet == HcalEndcap && etaRing == firstHERing())) {
subdet = HcalBarrel;
for (int i = 0; i < nEtaHB_; ++i) {
if (etaRing == etaBinsHB_[i].ieta) {
depth = etaBinsHB_[i].depthStart + etaBinsHB_[i].layer.size() - 1;
break;
}
}
} else if ((subdet == HcalEndcap) && (etaRing == lastHERing()) && (depth == hcons_->getDepthEta29(iphi, zside, 0)) &&
(mode_ != HcalTopologyMode::SLHC) && (mode_ != HcalTopologyMode::Run3) &&
(mode_ != HcalTopologyMode::Run4)) {
(ieta > 0) ? --ieta : ++ieta;
} else if (depth <= 0) {
if (subdet == HcalForward && etaRing == firstHFRing()) {
// overlap
subdet = HcalEndcap;
etaRing = etaHF2HE_;
ieta = (ieta > 0) ? etaRing : -etaRing;
for (const auto& i : etaBinsHE_) {
if (etaRing == i.ieta) {
depth = i.depthStart + i.layer.size() - 1;
break;
}
}
} else {
// no more chances
detId = HcalDetId();
return false;
}
}
detId = HcalDetId(subdet, ieta, detId.iphi(), depth);
return validRaw(detId);
}
int HcalTopology::nPhiBins(int etaRing) const {
int lastPhiBin = singlePhiBins_;
if (etaRing >= firstHFQuadPhiRing() || etaRing >= firstHEQuadPhiRing())
lastPhiBin = doublePhiBins_ / 2;
else if (etaRing >= firstHEDoublePhiRing())
lastPhiBin = doublePhiBins_;
if (hcons_ && etaRing >= hcons_->getEtaRange(1).first && etaRing <= hcons_->getEtaRange(1).second) {
return nPhiBins(HcalBarrel, etaRing);
}
return lastPhiBin;
}
int HcalTopology::nPhiBins(HcalSubdetector bc, int etaRing) const {
double phiTableVal;
if (bc == HcalForward) {
phiTableVal = dPhiTableHF[etaRing - firstHFRing_];
} else {
phiTableVal = dPhiTable[etaRing - firstHBRing_];
}
int lastPhiBin = 0;
if (phiTableVal != 0.0)
lastPhiBin = static_cast<int>((2._pi / phiTableVal) + 0.001);
return lastPhiBin;
}
int HcalTopology::maxDepth() const {
int maxd1 = std::max(maxDepthHB_, maxDepthHE_);
int maxd2 = std::max(maxDepthHF_, minMaxDepth_);
return std::max(maxd1, maxd2);
}
int HcalTopology::maxDepth(HcalSubdetector bc) const {
if (bc == HcalBarrel)