CMS 3D CMS Logo

ZdcTopology.cc
Go to the documentation of this file.
4 #include <cmath>
5 #include <iostream>
6 #include <algorithm>
7 
9  : hcons_(hcons),
10  excludeEM_(false),
11  excludeHAD_(false),
12  excludeLUM_(false),
13  excludeRPD_(false),
14  excludeZP_(false),
15  excludeZN_(false),
16  firstEMModule_(1),
17  lastEMModule_(HcalZDCDetId::kDepEM),
18  firstHADModule_(1),
19  lastHADModule_(HcalZDCDetId::kDepHAD),
20  firstLUMModule_(1),
21  lastLUMModule_(HcalZDCDetId::kDepLUM),
22  firstRPDModule_(1),
23  lastRPDModule_(HcalZDCDetId::kDepRPD) {
26  edm::LogVerbatim("ForwardGeom") << "ZdcTopology : Mode " << mode_ << ":" << HcalTopologyMode::Mode::Run3
27  << " ExcludeRPD " << excludeRPD_;
28 }
29 
30 bool ZdcTopology::valid(const HcalZDCDetId& id) const {
31  // check the raw rules
32  bool ok = validRaw(id);
33  ok = ok && !isExcluded(id);
34  return ok;
35 }
36 
37 bool ZdcTopology::isExcluded(const HcalZDCDetId& id) const {
38  bool exed = false;
39 
40  // check for section exclutions
41  switch (id.section()) {
42  case (HcalZDCDetId::EM):
43  exed = excludeEM_;
44  break;
45  case (HcalZDCDetId::HAD):
46  exed = excludeHAD_;
47  break;
48  case (HcalZDCDetId::LUM):
49  exed = excludeLUM_;
50  break;
51  case (HcalZDCDetId::RPD):
52  exed = excludeRPD_;
53  break;
54  default:
55  exed = true;
56  }
57 
58  // check the entire list
59  if (!exed && !exclusionList_.empty()) {
60  std::vector<HcalZDCDetId>::const_iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
61  if (i != exclusionList_.end() && *i == id)
62  exed = true;
63  }
64  return exed;
65 }
66 
68  std::vector<HcalZDCDetId>::iterator i = std::lower_bound(exclusionList_.begin(), exclusionList_.end(), id);
69  if (i == exclusionList_.end() || *i != id) {
70  exclusionList_.insert(i, id);
71  }
72 }
73 
75  switch (zside) {
76  case (1):
77  excludeZP_ = true;
78  break;
79  case (-1):
80  excludeZN_ = true;
81  break;
82  default:
83  break;
84  }
85 }
86 
88  switch (zside) {
89  case (1):
90  excludeZP_ = true;
91  break;
92  case (-1):
93  excludeZN_ = true;
94  break;
95  default:
96  break;
97  }
98  switch (section) {
99  case (HcalZDCDetId::EM):
100  excludeEM_ = true;
101  break;
102  case (HcalZDCDetId::HAD):
103  excludeHAD_ = true;
104  break;
105  case (HcalZDCDetId::LUM):
106  excludeLUM_ = true;
107  break;
108  case (HcalZDCDetId::RPD):
109  excludeRPD_ = true;
110  break;
111  default:
112  break;
113  }
114 }
115 
117  bool exed = false;
118  switch (zside) {
119  case (1):
120  exed = excludeZP_;
121  break;
122  case (-1):
123  exed = excludeZN_;
124  break;
125  default:
126  exed = false;
127  }
128  if (exed)
129  return 0;
130 
131  switch (section) {
132  case (HcalZDCDetId::EM):
133  exed = excludeEM_;
134  break;
135  case (HcalZDCDetId::HAD):
136  exed = excludeHAD_;
137  break;
138  case (HcalZDCDetId::LUM):
139  exed = excludeLUM_;
140  break;
141  case (HcalZDCDetId::RPD):
142  exed = excludeRPD_;
143  break;
144  default:
145  exed = false;
146  }
147  if (exed)
148  return 0;
149 
150  bool isPositive = false;
151  if (zside == 1)
152  isPositive = true;
153 
154  int n = 0;
155  for (int ich = ich1; ich < ich2; ich++) {
156  HcalZDCDetId id(section, isPositive, ich);
157  if (validRaw(id))
158  exclude(id);
159  n++;
160  }
161  return n;
162 }
163 
164 bool ZdcTopology::validRaw(const HcalZDCDetId& id) const {
165  bool ok = true;
166  if (abs(id.zside()) != 1)
167  ok = false;
168  else if (id.channel() <= 0)
169  ok = false;
170  else if (!(id.section() == HcalZDCDetId::EM || id.section() == HcalZDCDetId::HAD ||
172  ok = false;
173  else if (id.section() == HcalZDCDetId::EM && id.channel() > HcalZDCDetId::kDepEM)
174  ok = false;
175  else if (id.section() == HcalZDCDetId::HAD && id.channel() > HcalZDCDetId::kDepHAD)
176  ok = false;
177  else if (id.section() == HcalZDCDetId::LUM && id.channel() > HcalZDCDetId::kDepLUM)
178  ok = false;
179  else if (id.section() == HcalZDCDetId::RPD && id.channel() > HcalZDCDetId::kDepRPD)
180  ok = false;
181  else if (id.section() == HcalZDCDetId::Unknown)
182  ok = false;
183  return ok;
184 }
185 
186 std::vector<DetId> ZdcTopology::transverse(const DetId& id) const {
187  std::vector<DetId> vNeighborsDetId;
188  HcalZDCDetId zdcId = HcalZDCDetId(id);
189  HcalZDCDetId zdcDetId;
190  if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::EM) {
191  bool isPositive = false;
192  if (zdcId.zside() == 1)
193  isPositive = true;
194  if (zdcId.channel() == 1) {
195  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
196  vNeighborsDetId.emplace_back(zdcDetId.rawId());
197  return vNeighborsDetId;
198  }
199  if (zdcId.channel() == HcalZDCDetId::kDepEM) {
200  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
201  vNeighborsDetId.emplace_back(zdcDetId.rawId());
202  return vNeighborsDetId;
203  }
204  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
205  vNeighborsDetId.emplace_back(zdcDetId.rawId());
206  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
207  vNeighborsDetId.emplace_back(zdcDetId.rawId());
208  }
209  return vNeighborsDetId;
210 }
211 
212 std::vector<DetId> ZdcTopology::longitudinal(const DetId& id) const {
213  std::vector<DetId> vNeighborsDetId;
214  HcalZDCDetId zdcId = HcalZDCDetId(id);
215  HcalZDCDetId zdcDetId;
216  if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::HAD) {
217  bool isPositive = false;
218  if (zdcId.zside() == 1)
219  isPositive = true;
220  if (zdcId.channel() == 1) {
221  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
222  vNeighborsDetId.emplace_back(zdcDetId.rawId());
223  return vNeighborsDetId;
224  }
225  if (zdcId.channel() == HcalZDCDetId::kDepHAD) {
226  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
227  vNeighborsDetId.emplace_back(zdcDetId.rawId());
228  return vNeighborsDetId;
229  }
230  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
231  vNeighborsDetId.emplace_back(zdcDetId.rawId());
232  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
233  vNeighborsDetId.emplace_back(zdcDetId.rawId());
234  }
235  if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::LUM) {
236  bool isPositive = false;
237  if (zdcId.zside() == 1)
238  isPositive = true;
239  if (zdcId.channel() == 1) {
240  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
241  vNeighborsDetId.emplace_back(zdcDetId.rawId());
242  return vNeighborsDetId;
243  }
244  if (zdcId.channel() == HcalZDCDetId::kDepLUM) {
245  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
246  vNeighborsDetId.emplace_back(zdcDetId.rawId());
247  return vNeighborsDetId;
248  }
249  }
250  if (validRaw(zdcId) && zdcId.section() == HcalZDCDetId::RPD) {
251  bool isPositive = false;
252  if (zdcId.zside() == 1)
253  isPositive = true;
254  if (zdcId.channel() == 1) {
255  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() + 1);
256  vNeighborsDetId.emplace_back(zdcDetId.rawId());
257  return vNeighborsDetId;
258  }
259  if (zdcId.channel() == HcalZDCDetId::kDepRPD) {
260  zdcDetId = HcalZDCDetId(zdcId.section(), isPositive, zdcId.channel() - 1);
261  vNeighborsDetId.emplace_back(zdcDetId.rawId());
262  return vNeighborsDetId;
263  }
264  }
265  return vNeighborsDetId;
266 }
267 
268 std::vector<DetId> ZdcTopology::east(const DetId& /*id*/) const {
269  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::east() not yet implemented";
270  std::vector<DetId> vNeighborsDetId;
271  return vNeighborsDetId;
272 }
273 
274 std::vector<DetId> ZdcTopology::west(const DetId& /*id*/) const {
275  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::west() not yet implemented";
276  std::vector<DetId> vNeighborsDetId;
277  return vNeighborsDetId;
278 }
279 
280 std::vector<DetId> ZdcTopology::north(const DetId& /*id*/) const {
281  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::north() not yet implemented";
282  std::vector<DetId> vNeighborsDetId;
283  return vNeighborsDetId;
284 }
285 std::vector<DetId> ZdcTopology::south(const DetId& /*id*/) const {
286  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::south() not yet implemented";
287  std::vector<DetId> vNeighborsDetId;
288  return vNeighborsDetId;
289 }
290 std::vector<DetId> ZdcTopology::up(const DetId& /*id*/) const {
291  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::up() not yet implemented";
292  std::vector<DetId> vNeighborsDetId;
293  return vNeighborsDetId;
294 }
295 std::vector<DetId> ZdcTopology::down(const DetId& /*id*/) const {
296  edm::LogVerbatim("ForwardGeom") << "ZdcTopology::down() not yet implemented";
297  std::vector<DetId> vNeighborsDetId;
298  return vNeighborsDetId;
299 }
300 
302  int ncells = 0;
303  switch (section) {
304  case (HcalZDCDetId::EM):
306  break;
307  case (HcalZDCDetId::HAD):
309  break;
310  case (HcalZDCDetId::LUM):
312  break;
313  case (HcalZDCDetId::RPD):
315  break;
316  case (HcalZDCDetId::Unknown):
317  ncells = 0;
318  break;
319  }
320  return ncells;
321 }
322 
324  int firstCell = 0;
325  switch (section) {
326  case (HcalZDCDetId::EM):
328  break;
329  case (HcalZDCDetId::HAD):
331  break;
332  case (HcalZDCDetId::LUM):
334  break;
335  case (HcalZDCDetId::RPD):
337  break;
338  case (HcalZDCDetId::Unknown):
339  firstCell = 0;
340  break;
341  }
342  return firstCell;
343 }
344 
346  int lastCell = 0;
347  switch (section) {
348  case (HcalZDCDetId::EM):
350  break;
351  case (HcalZDCDetId::HAD):
353  break;
354  case (HcalZDCDetId::LUM):
356  break;
357  case (HcalZDCDetId::RPD):
359  break;
360  case (HcalZDCDetId::Unknown):
361  lastCell = 0;
362  break;
363  }
364  return lastCell;
365 }
366 
370 }
371 
372 DetId ZdcTopology::denseId2detId(uint32_t di) const {
373  if (validDenseIndex(di)) {
374  bool lz(false);
375  uint32_t dp(0);
377  if (di >= 2 * HcalZDCDetId::kDepRun1) {
379  se = HcalZDCDetId::RPD;
380  dp = 1 + ((di - 2 * HcalZDCDetId::kDepRun1) % HcalZDCDetId::kDepRPD);
381  } else {
382  lz = (di >= HcalZDCDetId::kDepRun1);
383  uint32_t in = (di % HcalZDCDetId::kDepRun1);
384  se = (in < HcalZDCDetId::kDepEM
387  dp = (se == HcalZDCDetId::EM ? in + 1
388  : (se == HcalZDCDetId::HAD ? in - HcalZDCDetId::kDepEM + 1
390  }
391  return static_cast<DetId>(HcalZDCDetId(se, lz, dp));
392  }
393  return DetId();
394 }
395 
396 uint32_t ZdcTopology::detId2DenseIndex(const DetId& id) const {
397  HcalZDCDetId detId(id);
398  const int32_t se(detId.section());
399  uint32_t di = (detId.channel() - 1 +
400  (se == HcalZDCDetId::RPD
401  ? 2 * HcalZDCDetId::kDepRun1 + (detId.zside() < 0 ? 0 : HcalZDCDetId::kDepRPD)
402  : ((detId.zside() < 0 ? 0 : HcalZDCDetId::kDepRun1) +
403  (se == HcalZDCDetId::HAD
406  return di;
407 }
int firstEMModule_
Definition: ZdcTopology.h:83
Log< level::Info, true > LogVerbatim
std::vector< DetId > down(const DetId &id) const override
Definition: ZdcTopology.cc:295
bool excludeEM_
Definition: ZdcTopology.h:81
void exclude(const HcalZDCDetId &id)
Definition: ZdcTopology.cc:67
int lastLUMModule_
Definition: ZdcTopology.h:83
uint32_t kSizeForDenseIndexing() const
Definition: ZdcTopology.cc:367
static constexpr int32_t kDepTot
Definition: HcalZDCDetId.h:42
bool excludeRPD_
Definition: ZdcTopology.h:81
bool excludeHAD_
Definition: ZdcTopology.h:81
int zside(DetId const &)
ZdcTopology(const HcalDDDRecConstants *hcons)
Definition: ZdcTopology.cc:8
static constexpr int32_t kSizeForDenseIndexingRun1
Definition: HcalZDCDetId.h:201
std::vector< DetId > up(const DetId &id) const override
Definition: ZdcTopology.cc:290
const HcalDDDRecConstants * hcons_
Definition: ZdcTopology.h:76
HcalTopologyMode::Mode mode_
Definition: ZdcTopology.h:77
std::vector< DetId > north(const DetId &id) const override
Definition: ZdcTopology.cc:280
int firstRPDModule_
Definition: ZdcTopology.h:83
static constexpr int32_t kDepHAD
Definition: HcalZDCDetId.h:38
bool excludeZN_
Definition: ZdcTopology.h:81
static constexpr int32_t kDepEM
Definition: HcalZDCDetId.h:37
uint32_t detId2DenseIndex(const DetId &id) const
Definition: ZdcTopology.cc:396
std::vector< DetId > south(const DetId &id) const override
Definition: ZdcTopology.cc:285
int firstHADModule_
Definition: ZdcTopology.h:83
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
DetId denseId2detId(uint32_t di) const override
Definition: ZdcTopology.cc:372
virtual std::vector< DetId > transverse(const DetId &id) const
Definition: ZdcTopology.cc:186
std::vector< HcalZDCDetId > exclusionList_
Definition: ZdcTopology.h:79
bool excludeLUM_
Definition: ZdcTopology.h:81
int lastRPDModule_
Definition: ZdcTopology.h:83
virtual bool valid(const HcalZDCDetId &id) const
Definition: ZdcTopology.cc:30
int firstCell(HcalZDCDetId::Section section) const
Definition: ZdcTopology.cc:323
std::vector< DetId > east(const DetId &id) const override
Definition: ZdcTopology.cc:268
Definition: DetId.h:17
std::vector< DetId > west(const DetId &id) const override
Definition: ZdcTopology.cc:274
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
virtual unsigned int ncells() const
return a count of valid cells (for dense indexing use)
int lastCell(HcalZDCDetId::Section section) const
Definition: ZdcTopology.cc:345
static constexpr int32_t kDepLUM
Definition: HcalZDCDetId.h:39
constexpr Section section() const
get the section
Definition: HcalZDCDetId.h:92
bool validRaw(const HcalZDCDetId &id) const
Definition: ZdcTopology.cc:164
static constexpr int32_t kDepRun1
Definition: HcalZDCDetId.h:41
bool validDenseIndex(uint32_t din) const
Definition: ZdcTopology.h:57
bool excludeZP_
Definition: ZdcTopology.h:81
static constexpr int32_t kDepRPD
Definition: HcalZDCDetId.h:40
int lastEMModule_
Definition: ZdcTopology.h:83
bool isExcluded(const HcalZDCDetId &id) const
Definition: ZdcTopology.cc:37
constexpr int32_t channel() const
get the channel
Definition: HcalZDCDetId.h:112
int firstLUMModule_
Definition: ZdcTopology.h:83
constexpr int32_t zside() const
get the z-side of the cell (1/-1)
Definition: HcalZDCDetId.h:90
static constexpr int32_t kSizeForDenseIndexingRun3
Definition: HcalZDCDetId.h:202
virtual std::vector< DetId > longitudinal(const DetId &id) const
Definition: ZdcTopology.cc:212
int lastHADModule_
Definition: ZdcTopology.h:83