CMS 3D CMS Logo

EBDetId.cc
Go to the documentation of this file.
3 
4 #include <algorithm>
5 const int EBDetId::kModuleBoundaries[4] = {25, 45, 65, 85};
6 
7 // pi / 180.
8 const float EBDetId::crystalUnitToEta = 0.017453292519943295;
9 
10 EBDetId::EBDetId(int index1, int index2, int mode) : DetId(Ecal, EcalBarrel) {
11  int crystal_ieta;
12  int crystal_iphi;
13  if (mode == ETAPHIMODE) {
14  crystal_ieta = index1;
15  crystal_iphi = index2;
16  } else if (mode == SMCRYSTALMODE) {
17  int SM = index1;
18  int crystal = index2;
19  int i = (int)floor((crystal - 1) / kCrystalsInPhi);
20  int j = ((crystal - 1) - (kCrystalsInPhi * i));
21  if (SM <= 18) {
22  crystal_ieta = i + 1;
23  crystal_iphi = ((SM - 1) * kCrystalsInPhi) + (kCrystalsInPhi - j);
24  } else {
25  crystal_ieta = -(i + 1);
26  crystal_iphi = ((SM - 19) * kCrystalsInPhi) + j + 1;
27  }
28  } else {
29  throw cms::Exception("InvalidDetId") << "EBDetId: Cannot create object. Unknown mode for (int, int) constructor.";
30  }
31 
32  if (!validDetId(crystal_ieta, crystal_iphi)) {
33  // std::cout << "crystal_eta " << crystal_ieta << "crystal_phi " << crystal_iphi << std::endl;
34  throw cms::Exception("InvalidDetId") << "EBDetId: Cannot create object. Indexes out of bounds \n"
35  << "eta = " << crystal_ieta << " phi = " << crystal_iphi;
36  }
37  id_ |= ((crystal_ieta > 0) ? (0x10000 | (crystal_ieta << 9)) : ((-crystal_ieta) << 9)) | (crystal_iphi & 0x1FF);
38 }
39 
40 //Following TB 2004 numbering scheme
41 int EBDetId::ic() const {
42  int ie = ietaAbs() - 1;
43  return (ie * kCrystalsInPhi) +
44  (positiveZ() ? (kCrystalsInPhi - ((iphi() - 1) % kCrystalsInPhi)) : ((iphi() - 1) % kCrystalsInPhi + 1));
45 }
46 
47 //Maintains SM crystals in bunch of 1700 indices
48 int EBDetId::numberBySM() const { return (ism() - 1) * kCrystalsPerSM + ic() - 1; }
49 
50 EBDetId EBDetId::offsetBy(int nrStepsEta, int nrStepsPhi) const {
51  int newEta = ieta() + nrStepsEta;
52  if (newEta * ieta() <= 0) {
53  if (ieta() < 0) {
54  newEta++;
55  } else if (ieta() > 0) {
56  newEta--;
57  }
58  }
59  int newPhi = iphi() + nrStepsPhi;
60  while (newPhi > 360)
61  newPhi -= 360;
62  while (newPhi <= 0)
63  newPhi += 360;
64 
65  if (validDetId(newEta, newPhi)) {
66  return EBDetId(newEta, newPhi);
67  } else {
68  return EBDetId(0);
69  }
70 }
71 
73  int newEta = ieta() * -1;
74  if (validDetId(newEta, iphi())) {
75  return EBDetId(newEta, iphi());
76  } else {
77  return EBDetId(0);
78  }
79 }
80 
81 DetId EBDetId::offsetBy(const DetId startId, int nrStepsEta, int nrStepsPhi) {
82  if (startId.det() == DetId::Ecal && startId.subdetId() == EcalBarrel) {
83  EBDetId ebStartId(startId);
84  return ebStartId.offsetBy(nrStepsEta, nrStepsPhi).rawId();
85  } else {
86  return DetId(0);
87  }
88 }
89 
91  if (startId.det() == DetId::Ecal && startId.subdetId() == EcalBarrel) {
92  EBDetId ebStartId(startId);
93  return ebStartId.switchZSide().rawId();
94  } else {
95  return DetId(0);
96  }
97 }
98 
99 //corrects for HB/EB differing iphi=1
100 int EBDetId::tower_iphi() const {
101  int iphi_simple = ((iphi() - 1) / 5) + 1;
102  iphi_simple -= 2;
103  return ((iphi_simple <= 0) ? (iphi_simple + 72) : (iphi_simple));
104 }
105 
107 
109  int ieta = id.ietaSM();
111 }
112 
114  int iphi = id.iphiSM();
115  return iphi == 1 || iphi == 20;
116 }
117 
118 int EBDetId::distanceEta(const EBDetId& a, const EBDetId& b) {
119  if (a.ieta() * b.ieta() > 0)
120  return abs(a.ieta() - b.ieta());
121  else
122  return abs(a.ieta() - b.ieta()) - 1;
123 }
124 
125 int EBDetId::distancePhi(const EBDetId& a, const EBDetId& b) {
126  int PI = 180;
127  int result = a.iphi() - b.iphi();
128 
129  while (result > PI)
130  result -= 2 * PI;
131  while (result <= -PI)
132  result += 2 * PI;
133  return abs(result);
134 }
135 
136 float EBDetId::approxEta(const DetId id) {
137  if (id.subdetId() == EcalBarrel) {
138  EBDetId ebId(id);
139  return ebId.approxEta();
140  } else {
141  return 0;
142  }
143 }
144 
145 #include <ostream>
146 std::ostream& operator<<(std::ostream& s, const EBDetId& id) {
147  return s << "(EB ieta " << id.ieta() << ", iphi " << id.iphi() << " ; ism " << id.ism() << " , ic " << id.ic() << ')';
148 }
EBDetId::kCrystalsInPhi
static const int kCrystalsInPhi
Definition: EBDetId.h:142
PI
Definition: PayloadInspector.h:19
EBDetId::crystalUnitToEta
static const float crystalUnitToEta
Definition: EBDetId.h:153
EBDetId::positiveZ
bool positiveZ() const
Definition: EBDetId.h:76
EBDetId::isNextToEtaBoundary
static bool isNextToEtaBoundary(EBDetId id)
Definition: EBDetId.cc:108
EBDetId::kCrystalsPerSM
static const int kCrystalsPerSM
Definition: EBDetId.h:144
EBDetId::ieta
int ieta() const
get the crystal ieta
Definition: EBDetId.h:49
mps_fire.i
i
Definition: mps_fire.py:355
EBDetId::isNextToBoundary
static bool isNextToBoundary(EBDetId id)
Definition: EBDetId.cc:106
EBDetId::EBDetId
EBDetId()
Definition: EBDetId.h:21
EBDetId::approxEta
float approxEta() const
Definition: EBDetId.h:102
PI
#define PI
Definition: QcdUeDQM.h:37
EBDetId::ic
int ic() const
get ECAL/crystal number inside SM
Definition: EBDetId.cc:41
EBDetId::kModuleBoundaries
static const int kModuleBoundaries[4]
Definition: EBDetId.h:141
EBDetId
Definition: EBDetId.h:17
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
EBDetId.h
ALCARECOPromptCalibProdSiPixelAli0T_cff.mode
mode
Definition: ALCARECOPromptCalibProdSiPixelAli0T_cff.py:96
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
EcalBarrel
Definition: EcalSubdetector.h:10
DetId
Definition: DetId.h:17
alignCSCRings.s
s
Definition: alignCSCRings.py:92
b
double b
Definition: hdecay.h:118
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EBDetId::ETAPHIMODE
static const int ETAPHIMODE
Definition: EBDetId.h:158
EBDetId::tower_iphi
int tower_iphi() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.cc:100
EBDetId::numberBySM
int numberBySM() const
Definition: EBDetId.cc:48
a
double a
Definition: hdecay.h:119
DetId::id_
uint32_t id_
Definition: DetId.h:69
EBDetId::distanceEta
static int distanceEta(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:118
createfilelist.int
int
Definition: createfilelist.py:10
EBDetId::offsetBy
EBDetId offsetBy(int nrStepsEta, int nrStepsPhi) const
Definition: EBDetId.cc:50
DetId::Ecal
Definition: DetId.h:27
EBDetId::validDetId
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
EBDetId::isNextToPhiBoundary
static bool isNextToPhiBoundary(EBDetId id)
Definition: EBDetId.cc:113
EBDetId::switchZSide
EBDetId switchZSide() const
Definition: EBDetId.cc:72
DetId::rawId
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
Exception
Definition: hltDiff.cc:246
EBDetId::ietaAbs
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
DetId::DetId
constexpr DetId()
Create an empty or null id (also for persistence)
Definition: DetId.h:38
Exception.h
EBDetId::ism
int ism() const
get the ECAL/SM id
Definition: EBDetId.h:59
EBDetId::iphi
int iphi() const
get the crystal iphi
Definition: EBDetId.h:51
mps_fire.result
result
Definition: mps_fire.py:303
funct::abs
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
EBDetId::distancePhi
static int distancePhi(const EBDetId &a, const EBDetId &b)
Definition: EBDetId.cc:125
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
operator<<
std::ostream & operator<<(std::ostream &s, const EBDetId &id)
Definition: EBDetId.cc:146
EBDetId::SMCRYSTALMODE
static const int SMCRYSTALMODE
Definition: EBDetId.h:159