CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CaloTowerTopology.cc
Go to the documentation of this file.
3 #include <cassert>
4 #include <algorithm>
5 
6 //#define DebugLog
7 
8 CaloTowerTopology::CaloTowerTopology(const HcalTopology* topology) : hcaltopo(topology) {
9  //get number of towers in each hcal subdet from hcaltopo
10  int nEtaHB, nEtaHO, nEtaHF;
11  nEtaHB = hcaltopo->lastHBRing() - hcaltopo->firstHBRing() + 1;
13  nEtaHO = hcaltopo->lastHORing() - hcaltopo->firstHORing() + 1;
14  nEtaHF = hcaltopo->lastHFRing() - hcaltopo->firstHFRing() + 1;
15 #ifdef DebugLog
16  std::cout << "CaloTowerTopology:(1) " << nEtaHB << ":" << nEtaHE_ << ":" << nEtaHO << ":" << nEtaHF << ":"
17  << hcaltopo->isBH() << std::endl;
18 #endif
19  if (hcaltopo->isBH())
20  nEtaHE_ = 0;
21 
22  //setup continuous ieta
23  firstHBRing_ = 1;
24  lastHBRing_ = firstHBRing_ + nEtaHB - 1;
25  firstHERing_ = lastHBRing_; //crossover
26  lastHERing_ = firstHERing_ + std::max(nEtaHE_ - 1, 0); //max = protection for case with no HE
27  //no crossover for CaloTowers; HF crossover cells go in the subsequent non-crossover HF tower
29  lastHFRing_ = firstHFRing_ + (nEtaHF - 1) - 1; //nEtaHF - 1 to account for no crossover
30  firstHORing_ = 1;
31  lastHORing_ = firstHORing_ + nEtaHO - 1;
32 #ifdef DebugLog
33  std::cout << "CaloTowerTopology: (2) " << firstHBRing_ << ":" << lastHBRing_ << ":" << firstHERing_ << ":"
34  << lastHERing_ << ":" << firstHFRing_ << ":" << lastHFRing_ << ":" << firstHORing_ << ":" << lastHORing_
35  << std::endl;
36 #endif
37 
38  //translate phi segmentation boundaries into continuous ieta
39  if (hcaltopo->firstHEDoublePhiRing() == 999 || nEtaHE_ == 0)
41  else
45 
46  //number of etas per phi segmentation type
47  int nEtaSinglePhi_, nEtaDoublePhi_, nEtaQuadPhi_;
48  nEtaSinglePhi_ = firstHEDoublePhiRing_ - firstHBRing_;
49  nEtaDoublePhi_ = firstHFQuadPhiRing_ - firstHEDoublePhiRing_;
50  nEtaQuadPhi_ = lastHFRing_ - firstHFQuadPhiRing_ + 1; //include lastHFRing
51 
52  //total number of towers per phi segmentation type
53  nSinglePhi_ = nEtaSinglePhi_ * 72;
54  nDoublePhi_ = nEtaDoublePhi_ * 36;
55  nQuadPhi_ = nEtaQuadPhi_ * 18;
56 
57 #ifdef DebugLog
58  std::cout << "CaloTowerTopology: (3) " << nEtaSinglePhi_ << ":" << nEtaDoublePhi_ << ":" << nEtaQuadPhi_ << ":"
59  << nSinglePhi_ << ":" << nDoublePhi_ << ":" << nQuadPhi_ << std::endl;
60 #endif
61 
62  //calculate maximum dense index size
64 }
65 
66 //convert CaloTowerTopology ieta to HcalTopology ieta
67 int CaloTowerTopology::convertCTtoHcal(int ct_ieta) const {
68  if (ct_ieta <= lastHBRing_)
69  return ct_ieta - firstHBRing_ + hcaltopo->firstHBRing();
70  else if (ct_ieta <= lastHERing_)
71  return ct_ieta - firstHERing_ + hcaltopo->firstHERing();
72  else if (ct_ieta <= lastHFRing_)
73  return ct_ieta - firstHFRing_ + hcaltopo->firstHFRing() + 1; //account for no HF crossover
74  else
75  return 0; //if ct_ieta outside range
76 }
77 
78 //convert HcalTopology ieta to CaloTowerTopology ieta
79 int CaloTowerTopology::convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const {
80  if (subdet == HcalBarrel && hcal_ieta >= hcaltopo->firstHBRing() && hcal_ieta <= hcaltopo->lastHBRing()) {
81  return hcal_ieta - hcaltopo->firstHBRing() + firstHBRing_;
82  } else if (subdet == HcalEndcap && hcal_ieta >= hcaltopo->firstHERing() && hcal_ieta <= hcaltopo->lastHERing()) {
83  return ((nEtaHE_ == 0) ? 0 : (hcal_ieta - hcaltopo->firstHERing() + firstHERing_));
84  } else if (subdet == HcalForward && hcal_ieta >= hcaltopo->firstHFRing() && hcal_ieta <= hcaltopo->lastHFRing()) {
85  if (hcal_ieta == hcaltopo->firstHFRing())
86  hcal_ieta++; //account for no HF crossover
87  return hcal_ieta - hcaltopo->firstHFRing() + firstHFRing_ - 1;
88  } else if (subdet == HcalOuter && hcal_ieta >= hcaltopo->firstHORing() && hcal_ieta <= hcaltopo->lastHORing()) {
89  return hcal_ieta - hcaltopo->firstHORing() + firstHORing_;
90  } else
91  return 0; //if hcal_ieta outside range, or unknown subdet
92 }
93 
94 bool CaloTowerTopology::valid(const DetId& id) const {
95  assert(id.det() == DetId::Calo && id.subdetId() == CaloTowerDetId::SubdetId);
96  return validDetId(id);
97 }
98 
100  int ia = id.ietaAbs();
101  int ip = id.iphi();
102 
103  return ((ia >= firstHBRing_) && (ia <= lastHFRing_) //eta range
104  && (ip >= 1) && (ip <= 72) //phi range
105  && ((ia < firstHEDoublePhiRing_) //72 phi segments
106  || (ia < firstHFQuadPhiRing_ && (ip - 1) % 2 == 0) //36 phi segments, numbered 1,3,...,33,35
107  || (ia >= firstHFQuadPhiRing_ && (ip - 3) % 4 == 0)) //18 phi segments, numbered 71,3,7,11,...
108  );
109 }
110 
111 //decreasing ieta
112 std::vector<DetId> CaloTowerTopology::east(const DetId& id) const {
113  std::vector<DetId> dd;
114  CaloTowerDetId tid(id);
115  int ieta = tid.ieta();
116  int iphi = tid.iphi();
117 
118  if (ieta == 1) { //no ieta=0
119  ieta = -1;
120  } else if (ieta == firstHEDoublePhiRing_) {
121  //currently double phi, going to single phi (positive eta) -> extra neighbor
122  ieta--;
123  dd.emplace_back(CaloTowerDetId(ieta, iphi + 1));
124  } else if (ieta - 1 == -firstHEDoublePhiRing_) {
125  //currently single phi, going to double phi (negative eta) -> change numbering
126  if ((iphi % 2) == 0)
127  iphi--;
128  ieta--;
129  } else if (ieta == firstHFQuadPhiRing_) { //currently quad phi, going to double phi (positive eta) -> extra neighbor
130  ieta--;
131  dd.emplace_back(CaloTowerDetId(ieta, ((iphi + 1) % 72) + 1));
132  } else if (ieta - 1 == -firstHFQuadPhiRing_) {
133  //currently double phi, going to quad phi (negative eta) -> change numbering
134  if (((iphi - 1) % 4) == 0) {
135  if (iphi == 1)
136  iphi = 71;
137  else
138  iphi -= 2;
139  }
140  ieta--;
141  } else { //general case
142  ieta--;
143  }
144 
145  if (ieta >= -lastHFRing_)
146  dd.emplace_back(CaloTowerDetId(ieta, iphi));
147  return dd;
148 }
149 
150 //increasing ieta
151 std::vector<DetId> CaloTowerTopology::west(const DetId& id) const {
152  std::vector<DetId> dd;
153  CaloTowerDetId tid(id);
154 
155  int ieta = tid.ieta();
156  int iphi = tid.iphi();
157 
158  if (ieta == -1) { //no ieta=0
159  ieta = 1;
160  } else if (ieta == -firstHEDoublePhiRing_) {
161  //currently double phi, going to single phi (negative eta) -> extra neighbor
162  ieta++;
163  dd.emplace_back(CaloTowerDetId(ieta, iphi + 1));
164  } else if (ieta + 1 == firstHEDoublePhiRing_) {
165  //currently single phi, going to double phi (positive eta) -> change numbering
166  if ((iphi % 2) == 0)
167  iphi--;
168  ieta++;
169  } else if (ieta == -firstHFQuadPhiRing_) { //currently quad phi, going to double phi (negative eta) -> extra neighbor
170  ieta++;
171  dd.emplace_back(CaloTowerDetId(ieta, ((iphi + 1) % 72) + 1));
172  } else if (ieta + 1 == firstHFQuadPhiRing_) {
173  //currently double phi, going to quad phi (positive eta) -> change numbering
174  if (((iphi - 1) % 4) == 0) {
175  if (iphi == 1)
176  iphi = 71;
177  else
178  iphi -= 2;
179  }
180  ieta++;
181  } else {
182  ieta++;
183  }
184 
185  if (ieta <= lastHFRing_)
186  dd.emplace_back(CaloTowerDetId(ieta, iphi));
187 
188  return dd;
189 }
190 
191 //increasing iphi
192 std::vector<DetId> CaloTowerTopology::north(const DetId& id) const {
193  CaloTowerDetId tid(id);
194  int iphi_n = tid.iphi() + 1;
195  if (iphi_n > 72)
196  iphi_n = 1;
197  if (tid.ietaAbs() >= firstHFQuadPhiRing_) { //18 phi segments, numbered 71,3,7,11,...
198  iphi_n += 3;
199  if (iphi_n > 72)
200  iphi_n -= 72;
201  } else if (tid.ietaAbs() >= firstHEDoublePhiRing_ && (iphi_n % 2) == 0) { //36 phi segments, numbered 1,3,...,33,35
202  iphi_n++;
203  if (iphi_n > 72)
204  iphi_n -= 72;
205  }
206 
207  std::vector<DetId> dd;
208  dd.emplace_back(CaloTowerDetId(tid.ieta(), iphi_n));
209  return dd;
210 }
211 
212 //decreasing iphi
213 std::vector<DetId> CaloTowerTopology::south(const DetId& id) const {
214  CaloTowerDetId tid(id);
215  int iphi_s = tid.iphi() - 1;
216  if (iphi_s == 0)
217  iphi_s = 72;
218  if (tid.ietaAbs() >= firstHFQuadPhiRing_) { //18 phi segments, numbered 71,3,7,11,...
219  iphi_s -= 3;
220  if (iphi_s <= 0)
221  iphi_s += 72;
222  } else if (tid.ietaAbs() >= firstHEDoublePhiRing_ && (iphi_s % 2) == 0) { //36 phi segments, numbered 1,3,...,33,35
223  iphi_s--;
224  }
225 
226  std::vector<DetId> dd;
227  dd.emplace_back(CaloTowerDetId(tid.ieta(), iphi_s));
228  return dd;
229 }
230 
231 std::vector<DetId> CaloTowerTopology::up(const DetId& /*id*/) const { return std::vector<DetId>(); }
232 
233 std::vector<DetId> CaloTowerTopology::down(const DetId& /*id*/) const { return std::vector<DetId>(); }
234 
235 uint32_t CaloTowerTopology::denseIndex(const DetId& id) const {
236  CaloTowerDetId tid(id);
237  const int ie(tid.ietaAbs());
238  const int ip(tid.iphi() - 1);
239 
240  return ((0 > tid.zside() ? 0 : kSizeForDenseIndexing / 2) +
241  ((firstHEDoublePhiRing_ > ie
242  ? (ie - 1) * 72 + ip
243  : (firstHFQuadPhiRing_ > ie ? nSinglePhi_ + (ie - firstHEDoublePhiRing_) * 36 + ip / 2
244  : nSinglePhi_ + nDoublePhi_ + (ie - firstHFQuadPhiRing_) * 18 + ip / 4))));
245 }
246 
248  const int iz(din < kSizeForDenseIndexing / 2 ? -1 : 1);
249  din %= kSizeForDenseIndexing / 2;
250  const int ie(nSinglePhi_ + nDoublePhi_ - 1 < (int)(din)
251  ? firstHFQuadPhiRing_ + (din - nSinglePhi_ - nDoublePhi_) / 18
252  : (nSinglePhi_ - 1 < (int)din ? firstHEDoublePhiRing_ + (din - nSinglePhi_) / 36 : din / 72 + 1));
253 
254  const int ip(nSinglePhi_ + nDoublePhi_ - 1 < (int)(din)
255  ? ((din - nSinglePhi_ - nDoublePhi_) % 18) * 4 + 3
256  : (nSinglePhi_ - 1 < (int)(din) ? ((din - nSinglePhi_) % 36) * 2 + 1 : din % 72 + 1));
257 
258  return (validDenseIndex(din) ? CaloTowerDetId(iz * ie, ip) : CaloTowerDetId());
259 }
int firstHFRing() const
Definition: HcalTopology.h:96
int convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const
int ietaAbs() const
get the absolute value of the tower ieta
std::vector< DetId > down(const DetId &id) const override
int firstHBRing() const
Definition: HcalTopology.h:91
int lastHBRing() const
Definition: HcalTopology.h:92
uint32_t kSizeForDenseIndexing
bool valid(const DetId &id) const override
is this detid present in the Topology?
assert(be >=bs)
CaloTowerTopology(const HcalTopology *topology)
standard constructor
CaloTowerDetId detIdFromDenseIndex(uint32_t din) const
std::vector< DetId > south(const DetId &id) const override
std::vector< DetId > up(const DetId &id) const override
static const int SubdetId
int lastHFRing() const
Definition: HcalTopology.h:97
int iphi() const
get the tower iphi
HcalSubdetector
Definition: HcalAssistant.h:31
int firstHORing() const
Definition: HcalTopology.h:98
int firstHEDoublePhiRing() const
Definition: HcalTopology.h:101
const HcalTopology * hcaltopo
uint32_t denseIndex(const DetId &id) const
Definition: DetId.h:17
std::vector< DetId > north(const DetId &id) const override
std::vector< DetId > east(const DetId &id) const override
bool isBH() const
Definition: HcalTopology.h:162
int firstHERing() const
Definition: HcalTopology.h:93
int zside() const
get the z-side of the tower (1/-1)
int firstHFQuadPhiRing() const
Definition: HcalTopology.h:103
int convertCTtoHcal(int ct_ieta) const
tuple cout
Definition: gather_cfg.py:144
int firstHEQuadPhiRing() const
Definition: HcalTopology.h:102
int ieta() const
get the tower ieta
int lastHORing() const
Definition: HcalTopology.h:99
bool validDenseIndex(uint32_t din) const
virtual bool validDetId(const CaloTowerDetId &id) const
int lastHERing() const
Definition: HcalTopology.h:94
std::vector< DetId > west(const DetId &id) const override