CMS 3D CMS Logo

HcalDDDRecConstants.cc
Go to the documentation of this file.
2 
6 #include "CLHEP/Units/GlobalPhysicalConstants.h"
7 #include "CLHEP/Units/GlobalSystemOfUnits.h"
8 #include <algorithm>
9 #include <cmath>
10 
11 //#define EDM_ML_DEBUG
12 using namespace geant_units::operators;
13 
14 enum { kHOSizePreLS1 = 2160, kHFSizePreLS1 = 1728 };
15 
17  : hpar(hp), hcons(hc) {
18 #ifdef EDM_ML_DEBUG
19  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants::HcalDDDRecConstants (const HcalParameters* hp) constructor";
20 #endif
21  initialize();
22 }
23 
25 #ifdef EDM_ML_DEBUG
26  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants::destructed!!!";
27 #endif
28 }
29 
30 std::vector<int> HcalDDDRecConstants::getDepth(const unsigned int& eta, const bool& extra) const {
31  if (!extra) {
32  std::vector<HcalParameters::LayerItem>::const_iterator last = hpar->layerGroupEtaRec.begin();
33  for (std::vector<HcalParameters::LayerItem>::const_iterator it = hpar->layerGroupEtaRec.begin();
34  it != hpar->layerGroupEtaRec.end();
35  ++it) {
36  if (it->layer == eta + 1)
37  return it->layerGroup;
38  if (it->layer > eta + 1)
39  return last->layerGroup;
40  last = it;
41  }
42  return last->layerGroup;
43  } else {
44  std::map<int, int> layers;
46  std::vector<int> depths;
47  for (unsigned int lay = 0; lay < layers.size(); ++lay)
48  depths.emplace_back(layers[lay + 1]);
49  return depths;
50  }
51 }
52 
53 std::vector<int> HcalDDDRecConstants::getDepth(const int& det,
54  const int& phi,
55  const int& zside,
56  const unsigned int& eta) const {
57  std::map<int, int> layers;
58  hcons.ldMap()->getLayerDepth(det, eta + 1, phi, zside, layers);
59  if (layers.empty()) {
60  return getDepth(eta, false);
61  } else {
62  std::vector<int> depths;
63  for (unsigned int lay = 0; lay < layers.size(); ++lay)
64  depths.emplace_back(layers[lay + 1]);
65  return depths;
66  }
67 }
68 
69 std::vector<HcalDDDRecConstants::HcalEtaBin> HcalDDDRecConstants::getEtaBins(const int& itype) const {
70  std::vector<HcalDDDRecConstants::HcalEtaBin> bins;
71  unsigned int type = (itype == 0) ? 0 : 1;
72  HcalSubdetector subdet = HcalSubdetector(type + 1);
73  std::vector<int> phiSp;
74  HcalSubdetector subdetSp = HcalSubdetector(hcons.ldMap()->validDet(phiSp));
75  std::map<int, int> layers;
76  for (int iz = 0; iz < 2; ++iz) {
77  int zside = 2 * iz - 1;
78  for (int ieta = iEtaMin[type]; ieta <= iEtaMax[type]; ++ieta) {
79  std::vector<std::pair<int, double>> phis = getPhis(subdet, ieta);
80  std::vector<std::pair<int, double>> phiUse;
82  if (subdet == subdetSp) {
83  for (auto& phi : phis) {
84  if (std::find(phiSp.begin(), phiSp.end(), (zside * phi.first)) == phiSp.end()) {
85  phiUse.emplace_back(phi);
86  }
87  }
88  } else {
89  phiUse.insert(phiUse.end(), phis.begin(), phis.end());
90  }
91  if (!phiUse.empty())
92  getOneEtaBin(subdet, ieta, zside, phiUse, layers, false, bins);
93  }
94  }
95  if (subdetSp == subdet) {
96  for (int ieta = iEtaMin[type]; ieta <= iEtaMax[type]; ++ieta) {
97  std::vector<std::pair<int, double>> phis = getPhis(subdet, ieta);
98  for (int iz = 0; iz < 2; ++iz) {
99  int zside = 2 * iz - 1;
100  std::vector<std::pair<int, double>> phiUse;
101  for (int i : phiSp) {
102  for (auto& phi : phis) {
103  if (i == zside * phi.first) {
104  phiUse.emplace_back(phi);
105  break;
106  }
107  }
108  }
109  if (!phiUse.empty()) {
110  hcons.ldMap()->getLayerDepth(subdet, ieta, phiUse[0].first, zside, layers);
111  getOneEtaBin(subdet, ieta, zside, phiUse, layers, true, bins);
112  }
113  }
114  }
115  }
116 #ifdef EDM_ML_DEBUG
117  edm::LogVerbatim("HCalGeom") << "Prepares " << bins.size() << " eta bins for type " << type;
118  for (unsigned int i = 0; i < bins.size(); ++i) {
119  edm::LogVerbatim("HCalGeom") << "Bin[" << i << "]: Eta = (" << bins[i].ieta << ":" << bins[i].etaMin << ":"
120  << bins[i].etaMax << "), Zside = " << bins[i].zside << ", phis = ("
121  << bins[i].phis.size() << ":" << bins[i].dphi << ") and " << bins[i].layer.size()
122  << " depths (start) " << bins[i].depthStart;
123  for (unsigned int k = 0; k < bins[i].layer.size(); ++k)
124  edm::LogVerbatim("HCalGeom") << " [" << k << "] " << bins[i].layer[k].first << ":" << bins[i].layer[k].second;
125  edm::LogVerbatim("HCalGeom") << "Phi sets";
126  for (unsigned int k = 0; k < bins[i].phis.size(); ++k)
127  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << bins[i].phis[k].first << ":" << bins[i].phis[k].second;
128  }
129 #endif
130  return bins;
131 }
132 
133 std::pair<double, double> HcalDDDRecConstants::getEtaPhi(const int& subdet, const int& ieta, const int& iphi) const {
134  int ietaAbs = (ieta > 0) ? ieta : -ieta;
135  double eta(0), phi(0);
136  if ((subdet == static_cast<int>(HcalBarrel)) || (subdet == static_cast<int>(HcalEndcap)) ||
137  (subdet == static_cast<int>(HcalOuter))) { // Use Eta Table
138  int unit = hcons.unitPhi(phibin[ietaAbs - 1]);
139  int kphi = (unit == 2) ? ((iphi - 1) / 2 + 1) : iphi;
140  double foff = (ietaAbs <= iEtaMax[0]) ? hpar->phioff[0] : hpar->phioff[1];
141  eta = 0.5 * (etaTable[ietaAbs - 1] + etaTable[ietaAbs]);
142  phi = foff + (kphi - 0.5) * phibin[ietaAbs - 1];
143  } else {
144  ietaAbs -= iEtaMin[2];
145  int unit = hcons.unitPhi(hpar->phitable[ietaAbs - 1]);
146  int kphi = (unit == 4) ? ((iphi - 3) / 4 + 1) : ((iphi - 1) / 2 + 1);
147  double foff = (unit > 2) ? hpar->phioff[4] : hpar->phioff[2];
148  eta = 0.5 * (hpar->etaTableHF[ietaAbs - 1] + hpar->etaTableHF[ietaAbs]);
149  phi = foff + (kphi - 0.5) * hpar->phitable[ietaAbs - 1];
150  }
151  if (ieta < 0)
152  eta = -eta;
153  if (phi > M_PI)
154  phi -= (2 * M_PI);
155 #ifdef EDM_ML_DEBUG
156  edm::LogVerbatim("HCalGeom") << "getEtaPhi: subdet|ieta|iphi " << subdet << "|" << ieta << "|" << iphi << " eta|phi "
157  << eta << "|" << phi;
158 #endif
159  return std::pair<double, double>(eta, phi);
160 }
161 
162 HcalDDDRecConstants::HcalID HcalDDDRecConstants::getHCID(int subdet, int keta, int iphi, int lay, int idepth) const {
163  uint32_t ieta = (keta > 0) ? keta : -keta;
164  int zside = (keta > 0) ? 1 : -1;
165  if ((ieta > hpar->etaMaxHBHE()) &&
166  ((subdet == static_cast<int>(HcalOuter)) || (subdet == static_cast<int>(HcalBarrel)) ||
167  (subdet == static_cast<int>(HcalEndcap))))
168  throw cms::Exception("HcalDDDRecConstants")
169  << "getHCID: receives an eta value " << ieta << " outside the limit (1:" << hpar->etaMaxHBHE() << ")";
170  int eta(ieta), phi(iphi), depth(idepth);
171  if ((subdet == static_cast<int>(HcalOuter)) ||
172  ((subdet == static_cast<int>(HcalBarrel)) && (lay > maxLayerHB_ + 1))) {
173  subdet = static_cast<int>(HcalOuter);
174  depth = 4;
175  } else if (subdet == static_cast<int>(HcalBarrel) || subdet == static_cast<int>(HcalEndcap)) {
176  eta = ietaMap[ieta - 1];
177  int unit = phiUnitS[ieta - 1];
178  int phi0 = (iphi - 1) / (hpar->phigroup[eta - 1]);
179  if (unit == 2) {
180  phi0 = (iphi + 1) / 2;
181  phi0 = (phi0 - 1) / (hpar->phigroup[eta - 1]);
182  } else if (unit == 4) {
183  phi0 = (iphi + 1) / 4;
184  phi0 = (phi0 - 1) / (hpar->phigroup[eta - 1]);
185  }
186  ++phi0;
187  unit = hcons.unitPhi(phibin[eta - 1]);
188  phi = hcons.phiNumber(phi0, unit);
189  depth = hcons.findDepth(subdet, eta, phi, zside, lay - 1);
190  if (depth <= 0)
191  depth = layerGroup(eta - 1, lay - 1);
192  if (eta == iEtaMin[1]) {
193  if (subdet == static_cast<int>(HcalBarrel)) {
194  if (depth > hcons.getDepthEta16(subdet, phi, zside))
195  depth = hcons.getDepthEta16(subdet, phi, zside);
196  } else {
197  if (depth < hcons.getDepthEta16(subdet, phi, zside))
198  depth = hcons.getDepthEta16(subdet, phi, zside);
199  }
200  } else if (eta == hpar->noff[0] && lay > 1) {
201  int kphi = phi + int((hpar->phioff[3] + 0.1) / phibin[eta - 1]);
202  kphi = (kphi - 1) % 4 + 1;
203  if (kphi == 2 || kphi == 3)
204  depth = layerGroup(eta - 1, lay - 2);
205  } else if (eta == hpar->noff[1] && depth > hcons.getDepthEta29(phi, zside, 0)) {
206  eta -= hcons.getDepthEta29(phi, zside, 1);
207  }
208  }
209 #ifdef EDM_ML_DEBUG
210  edm::LogVerbatim("HCalGeom") << "getHCID: input " << subdet << ":" << ieta << ":" << iphi << ":" << idepth << ":"
211  << lay << " output " << eta << ":" << phi << ":" << depth;
212 #endif
213  return HcalDDDRecConstants::HcalID(subdet, eta, phi, depth);
214 }
215 
216 std::vector<HcalDDDRecConstants::HFCellParameters> HcalDDDRecConstants::getHFCellParameters() const {
217  std::vector<HcalDDDRecConstants::HFCellParameters> cells;
218  unsigned int nEta = hcons.getPhiTableHF().size();
219  if (maxDepth[2] > 0) {
220  for (unsigned int k = 0; k < nEta; ++k) {
221  int ieta = iEtaMin[2] + k;
222  int dphi = (int)(0.001 + hcons.getPhiTableHF()[k] / (5._deg));
223  int iphi = (dphi == 4) ? 3 : 1;
224  int nphi = 72 / dphi;
225  double rMin = hcons.getRTableHF()[nEta - k - 1] / CLHEP::cm;
226  double rMax = hcons.getRTableHF()[nEta - k] / CLHEP::cm;
228  cells.emplace_back(cell1);
230  cells.emplace_back(cell2);
231  }
232  }
233  if (maxDepth[2] > 2) {
234  if (!hcons.getIdHF2QIE().empty()) {
235  for (unsigned int k = 0; k < hcons.getIdHF2QIE().size(); ++k) {
236  int ieta = hcons.getIdHF2QIE()[k].ieta();
237  int ind = std::abs(ieta) - iEtaMin[2];
238  int dphi = (int)(0.001 + hcons.getPhiTableHF()[ind] / (5._deg));
239  int iphi = hcons.getIdHF2QIE()[k].iphi();
240  double rMin = hcons.getRTableHF()[nEta - ind - 1] / CLHEP::cm;
241  double rMax = hcons.getRTableHF()[nEta - ind] / CLHEP::cm;
243  cells.emplace_back(cell1);
244  }
245  } else {
246  for (unsigned int k = 0; k < nEta; ++k) {
247  int ieta = iEtaMin[2] + k;
248  int dphi = (int)(0.001 + hcons.getPhiTableHF()[k] / (5._deg));
249  int iphi = (dphi == 4) ? 3 : 1;
250  int nphi = 72 / dphi;
251  double rMin = hcons.getRTableHF()[nEta - k - 1] / CLHEP::cm;
252  double rMax = hcons.getRTableHF()[nEta - k] / CLHEP::cm;
254  cells.emplace_back(cell1);
256  cells.emplace_back(cell2);
257  }
258  }
259  }
260 #ifdef EDM_ML_DEBUG
261  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants returns " << cells.size() << " HF cell parameters";
262  for (unsigned int k = 0; k < cells.size(); ++k)
263  edm::LogVerbatim("HCalGeom") << "Cell[" << k << "] : (" << cells[k].ieta << ", " << cells[k].depth << ", "
264  << cells[k].firstPhi << ", " << cells[k].stepPhi << ", " << cells[k].nPhi << ", "
265  << cells[k].rMin << ", " << cells[k].rMax << ")";
266 #endif
267  return cells;
268 }
269 
270 void HcalDDDRecConstants::getLayerDepth(const int& ieta, std::map<int, int>& layers) const {
271  layers.clear();
272  for (unsigned int l = 0; l < layerGroupSize(ieta - 1); ++l) {
273  int lay = l + 1;
274  layers[lay] = layerGroup(ieta - 1, l);
275  }
276 #ifdef EDM_ML_DEBUG
277  edm::LogVerbatim("HCalGeom") << "getLayerDepth::Input " << ieta << " Output " << layers.size() << " entries";
278  for (std::map<int, int>::iterator itr = layers.begin(); itr != layers.end(); ++itr)
279  edm::LogVerbatim("HCalGeom") << " [" << itr->first << "] " << itr->second;
280 #endif
281 }
282 
283 int HcalDDDRecConstants::getLayerBack(const int& idet, const int& ieta, const int& iphi, const int& depth) const {
284  int subdet = (idet == 1) ? 1 : 2;
285  int zside = (ieta > 0) ? 1 : -1;
286  int eta = zside * ieta;
287  int layBack = hcons.ldMap()->getLayerBack(subdet, eta, iphi, zside, depth);
288  int laymax = hcons.getLastLayer(subdet, ieta);
289  if (layBack < 0 && eta <= hpar->etaMax[1]) {
290  for (unsigned int k = 0; k < layerGroupSize(eta - 1); ++k) {
291  if (depth + 1 == (int)layerGroup(eta - 1, k)) {
292  layBack = k - 1;
293  break;
294  }
295  }
296  }
297  if (layBack < 0 || layBack > laymax)
298  layBack = laymax;
299 #ifdef EDM_ML_DEBUG
300  edm::LogVerbatim("HCalGeom") << "getLayerBack::Input " << idet << ":" << ieta << ":" << iphi << ":" << depth
301  << " Output " << layBack;
302 #endif
303  return layBack;
304 }
305 
306 int HcalDDDRecConstants::getLayerFront(const int& idet, const int& ieta, const int& iphi, const int& depth) const {
307  int subdet = (idet == 1) ? 1 : 2;
308  int zside = (ieta > 0) ? 1 : -1;
309  int eta = zside * ieta;
310  int layFront = hcons.ldMap()->getLayerFront(subdet, eta, iphi, zside, depth);
311  int laymin = hcons.getFrontLayer(subdet, ieta);
312  if ((layFront < 0) || ((subdet == static_cast<int>(HcalEndcap)) && (eta == 16))) {
313  if ((subdet == static_cast<int>(HcalEndcap)) && (eta == 16)) {
314  layFront = laymin;
315  } else if (eta <= hpar->etaMax[1]) {
316  for (unsigned int k = 0; k < layerGroupSize(eta - 1); ++k) {
317  if (depth == (int)layerGroup(eta - 1, k)) {
318  if ((int)(k) >= laymin) {
319  layFront = k;
320  break;
321  }
322  }
323  }
324  }
325  } else {
326  if (layFront < laymin)
327  layFront = laymin;
328  }
329 #ifdef EDM_ML_DEBUG
330  edm::LogVerbatim("HCalGeom") << "getLayerFront::Input " << idet << ":" << ieta << ":" << iphi << ":" << depth
331  << " Output " << layFront;
332 #endif
333  return layFront;
334 }
335 
336 int HcalDDDRecConstants::getMaxDepth(const int& itype, const int& ieta, const int& iphi, const int& zside) const {
337  unsigned int type = (itype == 0) ? 0 : 1;
338  int lmax = hcons.getMaxDepth(type + 1, ieta, iphi, zside, true);
339  if (lmax < 0) {
340  unsigned int lymax = (type == 0) ? maxLayerHB_ + 1 : maxLayer_ + 1;
341  lmax = 0;
342  if (layerGroupSize(ieta - 1) > 0) {
343  if (layerGroupSize(ieta - 1) < lymax)
344  lymax = layerGroupSize(ieta - 1);
345  lmax = (int)(layerGroup(ieta - 1, lymax - 1));
346  if (type == 0 && ieta == iEtaMax[type])
347  lmax = hcons.getDepthEta16M(1);
348  if (type == 1 && ieta >= hpar->noff[1])
349  lmax = hcons.getDepthEta29M(0, false);
350  }
351  }
352 #ifdef EDM_ML_DEBUG
353  edm::LogVerbatim("HCalGeom") << "getMaxDepth::Input " << itype << ":" << ieta << ":" << iphi << ":" << zside
354  << " Output " << lmax;
355 #endif
356  return lmax;
357 }
358 
359 int HcalDDDRecConstants::getMinDepth(const int& itype, const int& ieta, const int& iphi, const int& zside) const {
360  int lmin = hcons.getMinDepth(itype + 1, ieta, iphi, zside, true);
361  if (lmin < 0) {
362  if (itype == 2) { // HFn
363  lmin = 1;
364  } else if (itype == 3) { //HO
365  lmin = maxDepth[3];
366  } else {
367  unsigned int type = (itype == 0) ? 0 : 1;
368  if (layerGroupSize(ieta - 1) > 0) {
369  if (type == 1 && ieta == iEtaMin[type])
370  lmin = hcons.getDepthEta16M(2);
371  else
372  lmin = (int)(layerGroup(ieta - 1, 0));
373  }
374  }
375  }
376  return lmin;
377 }
378 
379 std::vector<std::pair<int, double>> HcalDDDRecConstants::getPhis(const int& subdet, const int& ieta) const {
380  std::vector<std::pair<int, double>> phis;
381  int ietaAbs = (ieta > 0) ? ieta : -ieta;
382  int keta = (subdet != HcalForward) ? etaSimValu[ietaAbs - 1].first : ietaAbs;
383  std::pair<double, double> ficons = hcons.getPhiCons(subdet, keta);
384  double fioff = ficons.first;
385  double dphi = (subdet != HcalForward) ? phibin[ietaAbs - 1] : ficons.second;
386  int nphi = int((2._pi + 0.1 * dphi) / dphi);
387  int units = hcons.unitPhi(subdet, keta);
388  for (int ifi = 0; ifi < nphi; ++ifi) {
389  double phi = -fioff + (ifi + 0.5) * dphi;
390  int iphi = hcons.phiNumber(ifi + 1, units);
391  phis.emplace_back(std::pair<int, double>(iphi, phi));
392  }
393 #ifdef EDM_ML_DEBUG
394  edm::LogVerbatim("HCalGeom") << "getEtaPhi: subdet|ieta|iphi " << subdet << "|" << ieta << " with " << phis.size()
395  << " phi bins";
396  for (unsigned int k = 0; k < phis.size(); ++k)
397  edm::LogVerbatim("HCalGeom") << "[" << k << "] iphi " << phis[k].first << " phi "
398  << convertRadToDeg(phis[k].second);
399 #endif
400  return phis;
401 }
402 
403 int HcalDDDRecConstants::getPhiZOne(std::vector<std::pair<int, int>>& phiz) const {
404  phiz.clear();
405  int subdet = hcons.ldMap()->getSubdet();
406  if (subdet > 0) {
407  std::vector<int> phis = hcons.ldMap()->getPhis();
408  for (int k : phis) {
409  int zside = (k > 0) ? 1 : -1;
410  int phi = (k > 0) ? k : -k;
411  phiz.emplace_back(std::pair<int, int>(phi, zside));
412  }
413  }
414 #ifdef EDM_ML_DEBUG
415  edm::LogVerbatim("HCalGeom") << "Special RBX for detector " << subdet << " with " << phiz.size() << " phi/z bins";
416  for (unsigned int k = 0; k < phiz.size(); ++k)
417  edm::LogVerbatim("HCalGeom") << " [" << k << "] " << phiz[k].first << ":" << phiz[k].second;
418 #endif
419  return subdet;
420 }
421 
422 double HcalDDDRecConstants::getRZ(const int& subdet, const int& ieta, const int& depth) const {
423  return getRZ(subdet, ieta, 1, depth);
424 }
425 
426 double HcalDDDRecConstants::getRZ(const int& subdet, const int& ieta, const int& iphi, const int& depth) const {
427  int layf = getLayerFront(subdet, ieta, iphi, depth);
428  double rz =
429  (layf < 0) ? 0.0 : ((subdet == static_cast<int>(HcalBarrel)) ? (gconsHB[layf].first) : (gconsHE[layf].first));
430 #ifdef EDM_ML_DEBUG
431  edm::LogVerbatim("HCalGeom") << "getRZ: subdet|ieta|ipho|depth " << subdet << "|" << ieta << "|" << iphi << "|"
432  << depth << " lay|rz " << layf << "|" << rz;
433 #endif
434  return rz;
435 }
436 
437 double HcalDDDRecConstants::getRZ(const int& subdet, const int& layer) const {
438  double rz(0);
439  if (layer > 0 && layer <= (int)(layerGroupSize(0)))
440  rz = ((subdet == static_cast<int>(HcalBarrel)) ? (gconsHB[layer - 1].first) : (gconsHE[layer - 1].first));
441 #ifdef EDM_ML_DEBUG
442  edm::LogVerbatim("HCalGeom") << "getRZ: subdet|layer " << subdet << "|" << layer << " rz " << rz;
443 #endif
444  return rz;
445 }
446 
447 std::pair<double, double> HcalDDDRecConstants::getRZ(const HcalDetId& id) const {
448  int subdet = id.subdetId();
449  int ieta = id.ieta();
450  int iphi = id.iphi();
451  int depth = id.depth();
452  int zside = (subdet == static_cast<int>(HcalBarrel)) ? 1 : id.zside();
453  int layf = getLayerFront(subdet, ieta, iphi, depth);
454  double rzf = (layf < 0)
455  ? 0.0
456  : ((subdet == static_cast<int>(HcalBarrel)) ? zside * (gconsHB[layf].first - gconsHB[layf].second)
457  : zside * (gconsHE[layf].first - gconsHE[layf].second));
458  int layb = getLayerBack(subdet, ieta, iphi, depth);
459  double rzb = (layb < 0)
460  ? 0.0
461  : ((subdet == static_cast<int>(HcalBarrel)) ? zside * (gconsHB[layb].first + gconsHB[layb].second)
462  : zside * (gconsHE[layb].first + gconsHE[layb].second));
463 #ifdef EDM_ML_DEBUG
464  edm::LogVerbatim("HCalGeom") << "getRZ: subdet|ieta|ipho|depth " << subdet << "|" << ieta << "|" << iphi << "|"
465  << depth << " lay|rz (front) " << layf << "|" << rzf << " lay|rz (back) " << layb << "|"
466  << rzb;
467 #endif
468  return std::pair<double, double>(rzf, rzb);
469 }
470 
471 std::vector<HcalDDDRecConstants::HcalActiveLength> HcalDDDRecConstants::getThickActive(const int& type) const {
472  std::vector<HcalDDDRecConstants::HcalActiveLength> actives;
473  std::vector<HcalDDDRecConstants::HcalEtaBin> bins = getEtaBins(type);
474 #ifdef EDM_ML_DEBUG
475  unsigned int kount(0);
476 #endif
477  for (auto& bin : bins) {
478  int ieta = bin.ieta;
479  int zside = bin.zside;
480  int stype = (bin.phis.size() > 4) ? 0 : 1;
481  int layf = getLayerFront(type + 1, zside * ieta, bin.phis[0].first, bin.depthStart) + 1;
482  int layl = hcons.getLastLayer(type + 1, zside * ieta) + 1;
483  double eta = 0.5 * (bin.etaMin + bin.etaMax);
484  double theta = 2 * atan(exp(-eta));
485  double scale = 1.0 / ((type == 0) ? sin(theta) : cos(theta));
486  int depth = bin.depthStart;
487 #ifdef EDM_ML_DEBUG
488  edm::LogVerbatim("HCalGeom") << "Eta " << ieta << " zside " << zside << " depth " << depth << " Layers " << layf
489  << ":" << layl << ":" << bin.layer.size();
490  for (auto ll : bin.layer)
491  edm::LogVerbatim("HCalGeom") << "Layer " << ll.first << ":" << ll.second;
492  for (auto phi : bin.phis)
493  edm::LogVerbatim("HCalGeom") << "Phi " << phi.first << ":" << convertRadToDeg(phi.second);
494 #endif
495  for (unsigned int i = 0; i < bin.layer.size(); ++i) {
496  double thick(0);
497  int lmin = (type == 1 && ieta == iEtaMin[1]) ? layf : std::max(bin.layer[i].first, layf);
498  int lmax = std::min(bin.layer[i].second, layl);
499  for (int j = lmin; j <= lmax; ++j) {
500  double t = ((type == 0) ? gconsHB[j - 1].second : gconsHE[j - 1].second);
501  if ((type == 1) && (ieta <= 18))
502  t = gconsHE[j].second;
503  if (t > 0)
504  thick += t;
505  }
506 #ifdef EDM_ML_DEBUG
507  edm::LogVerbatim("HCalGeom") << "Type " << type << " L " << lmin << ":" << lmax << " T " << thick;
508 #endif
509  thick *= (2. * scale);
510  HcalDDDRecConstants::HcalActiveLength active(ieta, depth, zside, stype, zside * eta, thick);
511  for (auto phi : bin.phis)
512  active.iphis.emplace_back(phi.first);
513  actives.emplace_back(active);
514  ++depth;
515 #ifdef EDM_ML_DEBUG
516  kount++;
517  edm::LogVerbatim("HCalGeom") << "getThickActive: [" << kount << "] eta:" << active.ieta << ":" << active.eta
518  << " zside " << active.zside << " depth " << active.depth << " type " << active.stype
519  << " thick " << active.thick;
520 #endif
521  }
522  }
523  return actives;
524 }
525 
526 std::vector<HcalCellType> HcalDDDRecConstants::HcalCellTypes(HcalSubdetector subdet) const {
527  if (subdet == HcalBarrel || subdet == HcalEndcap) {
528  std::vector<HcalCellType> cells;
529  int isub = (subdet == HcalBarrel) ? 0 : 1;
530  std::vector<HcalDDDRecConstants::HcalEtaBin> etabins = getEtaBins(isub);
531  std::vector<int> missPhi;
532  for (const auto& etabin : etabins) {
533  std::vector<HcalCellType> temp;
534  std::vector<int> count;
535  std::vector<double> dmin, dmax;
536  for (unsigned int il = 0; il < etabin.layer.size(); ++il) {
537  HcalCellType cell(subdet, etabin.ieta, etabin.zside, 0, HcalCellType::HcalCell());
538  temp.emplace_back(cell);
539  count.emplace_back(0);
540  dmin.emplace_back(0);
541  dmax.emplace_back(0);
542  }
543  int ieta = etabin.ieta;
544  for (int keta = etaSimValu[ieta - 1].first; keta <= etaSimValu[ieta - 1].second; ++keta) {
545  std::vector<HcalCellType> cellsm = hcons.HcalCellTypes(subdet, keta, -1);
546  for (unsigned int il = 0; il < etabin.layer.size(); ++il) {
547  for (auto& ic : cellsm) {
548  if (ic.depthSegment() >= etabin.layer[il].first && ic.depthSegment() <= etabin.layer[il].second &&
549  ic.etaBin() == temp[il].etaBin() && ic.zside() == temp[il].zside()) {
550  if (count[il] == 0) {
551  temp[il] = ic;
552  dmin[il] = ic.depthMin();
553  dmax[il] = ic.depthMax();
554  }
555  ++count[il];
556  if (ic.depthMin() < dmin[il])
557  dmin[il] = ic.depthMin();
558  if (ic.depthMax() > dmax[il])
559  dmax[il] = ic.depthMax();
560  }
561  }
562  }
563  }
564  for (unsigned int il = 0; il < etabin.layer.size(); ++il) {
565  int depth = etabin.depthStart + (int)(il);
566  temp[il].setEta(ieta, etabin.etaMin, etabin.etaMax);
567  temp[il].setDepth(depth, dmin[il], dmax[il]);
568  double foff = (etabin.ieta <= iEtaMax[0]) ? hpar->phioff[0] : hpar->phioff[1];
569  int unit = hcons.unitPhi(etabin.dphi);
570  temp[il].setPhi(etabin.phis, missPhi, foff, etabin.dphi, unit);
571  cells.emplace_back(temp[il]);
572  }
573  }
574 #ifdef EDM_ML_DEBUG
575  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants: found " << cells.size() << " cells for sub-detector type "
576  << isub;
577  for (unsigned int ic = 0; ic < cells.size(); ++ic)
578  edm::LogVerbatim("HCalGeom") << "Cell[" << ic << "] " << cells[ic];
579 #endif
580  return cells;
581  } else {
582  return hcons.HcalCellTypes(subdet, -1, -1);
583  }
584 }
585 
587  int eta = std::abs(ieta);
588  int zside = (ieta > 0) ? 1 : -1;
589  int etamin = iEtaMax[1] - hcons.getDepthEta29(iphi, zside, 1);
590  if ((eta >= etamin) && (eta <= iEtaMax[1])) {
591  int depthMax = getMaxDepth(1, etamin, iphi, zside);
592  int depthMin = hcons.getDepthEta29(iphi, zside, 0) + 1;
593  if (depth >= depthMin && depth <= depthMax)
594  return true;
595  }
596  return false;
597 }
598 
599 std::vector<int> HcalDDDRecConstants::mergedDepthList29(int ieta, int iphi) const {
600  std::vector<int> depths;
601  int eta = std::abs(ieta);
602  int zside = (ieta > 0) ? 1 : -1;
603  int etamin = iEtaMax[1] - hcons.getDepthEta29(iphi, zside, 1);
604  if ((eta >= etamin) && (eta <= iEtaMax[1])) {
605  int depthMax = getMaxDepth(1, etamin, iphi, zside);
606  int depthMin = hcons.getDepthEta29(iphi, zside, 0) + 1;
607  depths.reserve(depthMax - depthMin + 1);
608  for (int depth = depthMin; depth <= depthMax; ++depth)
609  depths.emplace_back(depth);
610  }
611  return depths;
612 }
613 
615  if (subdet == HcalBarrel || subdet == HcalEndcap) {
616  unsigned int num = 0;
617  std::vector<HcalCellType> cellTypes = HcalCellTypes(subdet);
618  for (auto& cellType : cellTypes) {
619  num += (unsigned int)(cellType.nPhiBins());
620  }
621 #ifdef EDM_ML_DEBUG
622  edm::LogInfo("HCalGeom") << "HcalDDDRecConstants:numberOfCells " << cellTypes.size() << " " << num
623  << " for subdetector " << subdet;
624 #endif
625  return num;
626  } else {
627  return hcons.numberOfCells(subdet);
628  }
629 }
630 
631 unsigned int HcalDDDRecConstants::nCells(HcalSubdetector subdet) const {
632  if (subdet == HcalBarrel || subdet == HcalEndcap) {
633  int isub = (subdet == HcalBarrel) ? 0 : 1;
634  std::vector<HcalDDDRecConstants::HcalEtaBin> etabins = getEtaBins(isub);
635  unsigned int ncell(0);
636  for (auto& etabin : etabins) {
637  ncell += ((etabin.phis.size()) * (etabin.layer.size()));
638  }
639  return ncell;
640  } else if (subdet == HcalOuter) {
641  return kHOSizePreLS1;
642  } else if (subdet == HcalForward) {
643  return (unsigned int)(hcons.numberOfCells(subdet));
644  } else {
645  return 0;
646  }
647 }
648 
649 unsigned int HcalDDDRecConstants::nCells() const {
651 }
652 
654  std::map<HcalDetId, HcalDetId>::const_iterator itr = detIdSp_.find(id);
655  if (itr == detIdSp_.end())
656  return id;
657  else
658  return itr->second;
659 }
660 
662  HcalDetId hid(id);
663  std::map<HcalDetId, std::vector<HcalDetId>>::const_iterator itr = detIdSpR_.find(id);
664  if (itr != detIdSpR_.end())
665  hid = HcalDetId(id.subdet(), id.ieta(), id.iphi(), (itr->second)[0].depth());
666  return hid;
667 }
668 
670  HcalDetId hid(id);
671  std::map<HcalDetId, std::vector<HcalDetId>>::const_iterator itr = detIdSpR_.find(id);
672  if (itr != detIdSpR_.end())
673  hid = HcalDetId(id.subdet(), id.ieta(), id.iphi(), (itr->second).back().depth());
674  return hid;
675 }
676 
677 void HcalDDDRecConstants::unmergeDepthDetId(const HcalDetId& id, std::vector<HcalDetId>& ids) const {
678  ids.clear();
679  std::map<HcalDetId, std::vector<HcalDetId>>::const_iterator itr = detIdSpR_.find(id);
680  if (itr == detIdSpR_.end()) {
681  ids.emplace_back(id);
682  } else {
683  for (auto k : itr->second) {
684  HcalDetId hid(id.subdet(), id.ieta(), id.iphi(), k.depth());
685  ids.emplace_back(hid);
686  }
687  }
688 }
689 
690 void HcalDDDRecConstants::specialRBXHBHE(const std::vector<HcalDetId>& idsOld, std::vector<HcalDetId>& idsNew) const {
691  for (auto k : idsOld) {
692  std::map<HcalDetId, HcalDetId>::const_iterator itr = detIdSp_.find(k);
693  if (itr == detIdSp_.end())
694  idsNew.emplace_back(k);
695  else
696  idsNew.emplace_back(itr->second);
697  }
698 }
699 
700 bool HcalDDDRecConstants::specialRBXHBHE(bool tobemerged, std::vector<HcalDetId>& ids) const {
701  if (tobemerged) {
702  std::map<HcalDetId, HcalDetId>::const_iterator itr;
703  for (itr = detIdSp_.begin(); itr != detIdSp_.end(); ++itr)
704  ids.emplace_back(itr->first);
705  } else {
706  std::map<HcalDetId, std::vector<HcalDetId>>::const_iterator itr;
707  for (itr = detIdSpR_.begin(); itr != detIdSpR_.end(); ++itr)
708  ids.emplace_back(itr->first);
709  }
710  return (!ids.empty());
711 }
712 
714  int ieta,
715  int zside,
716  std::vector<std::pair<int, double>>& phis,
717  std::map<int, int>& layers,
718  bool planOne,
719  std::vector<HcalDDDRecConstants::HcalEtaBin>& bins) const {
720  unsigned int lymax = (subdet == HcalBarrel) ? maxLayerHB_ + 1 : maxLayer_ + 1;
721  int type = (subdet == HcalBarrel) ? 0 : 1;
722  double dphi = phibin[ieta - 1];
725  etabin.phis.insert(etabin.phis.end(), phis.begin(), phis.end());
726  int n = (ieta == iEtaMax[type]) ? 0 : 1;
729  etabin0.depthStart = hcons.getDepthEta29(phis[0].first, zside, 0) + 1;
730  int dstart = -1;
731  int lmin(0), lmax(0);
732 
733  std::map<int, int>::iterator itr = layers.begin();
734  if (!layers.empty()) {
735  int dep = itr->second;
736  if (subdet == HcalEndcap && ieta == iEtaMin[type])
737  dep = hcons.getDepthEta16(subdet, phis[0].first, zside);
738  unsigned lymx0 = (layers.size() > lymax) ? lymax : layers.size();
739 #ifdef EDM_ML_DEBUG
740  edm::LogVerbatim("HCalGeom") << "Eta " << ieta << ":" << hpar->noff[1] << " zside " << zside << " lymax " << lymx0
741  << ":" << lymax << " Depth " << dep << ":" << itr->second;
742  unsigned int l(0);
743  for (itr = layers.begin(); itr != layers.end(); ++itr, ++l)
744  edm::LogVerbatim("HCalGeom") << "Layer [" << l << "] " << itr->first << ":" << itr->second;
745  edm::LogVerbatim("HCalGeom") << "With " << phis.size() << " phis";
746  for (unsigned int l = 0; l < phis.size(); ++l)
747  edm::LogVerbatim("HCalGeom") << "[" << l << "] " << phis[l].first << ":" << convertRadToDeg(phis[l].second);
748 #endif
749  for (itr = layers.begin(); itr != layers.end(); ++itr) {
750  if (itr->first <= (int)(lymx0)) {
751  if (itr->second == dep) {
752  if (lmin == 0)
753  lmin = itr->first;
754  lmax = itr->first;
755  } else if (itr->second > dep) {
756  if (dstart < 0)
757  dstart = dep;
758  int lmax0 = (lmax >= lmin) ? lmax : lmin;
759  if (subdet == HcalEndcap && ieta + 1 == hpar->noff[1] && dep > hcons.getDepthEta29(phis[0].first, zside, 0)) {
760  etabin0.layer.emplace_back(std::pair<int, int>(lmin, lmax0));
761  } else {
762  etabin.layer.emplace_back(std::pair<int, int>(lmin, lmax0));
763  }
764  lmin = itr->first;
765  lmax = lmin - 1;
766  dep = itr->second;
767  }
768  if (subdet == HcalBarrel && ieta == iEtaMax[type] && dep > hcons.getDepthEta16M(1))
769  break;
770  if (subdet == HcalEndcap && ieta == hpar->noff[1] && dep > hcons.getDepthEta29M(0, planOne)) {
771  lmax = lymx0;
772  break;
773  }
774  if (itr->first == (int)(lymx0))
775  lmax = lymx0;
776  }
777  }
778  if (lmax >= lmin) {
779  if (ieta + 1 == hpar->noff[1]) {
780  etabin0.layer.emplace_back(std::pair<int, int>(lmin, lmax));
781  etabin0.phis.insert(etabin0.phis.end(), phis.begin(), phis.end());
782  bins.emplace_back(etabin0);
783 #ifdef EDM_ML_DEBUG
784  edm::LogVerbatim("HCalGeom") << "etabin0: dStatrt " << etabin0.depthStart << " layers " << etabin0.layer.size()
785  << ":" << lmin << ":" << lmax << " phis " << phis.size();
786  for (unsigned int k = 0; k < etabin0.layer.size(); ++k)
787  edm::LogVerbatim("HCalGeom") << " [" << k << "] " << etabin0.layer[k].first << ":" << etabin0.layer[k].second;
788 #endif
789  } else if (ieta == hpar->noff[1]) {
790  } else {
791  etabin.layer.emplace_back(std::pair<int, int>(lmin, lmax));
792  if (dstart < 0)
793  dstart = dep;
794  }
795  }
796  }
797  etabin.depthStart = dstart;
798  bins.emplace_back(etabin);
799 #ifdef EDM_ML_DEBUG
800  edm::LogVerbatim("HCalGeom") << "etabin: dStatrt " << etabin.depthStart << " layers " << etabin.layer.size() << ":"
801  << lmin << ":" << lmax << " phis " << etabin.phis.size();
802  for (unsigned int k = 0; k < etabin.layer.size(); ++k)
803  edm::LogVerbatim("HCalGeom") << "[" << k << "] " << etabin.layer[k].first << ":" << etabin.layer[k].second;
804 #endif
805 }
806 
808  //Eta grouping
809  int nEta = (int)(hpar->etagroup.size());
810  if (nEta != (int)(hpar->phigroup.size())) {
811  edm::LogError("HCalGeom") << "HcalDDDRecConstants: sizes of the vectors "
812  << " etaGroup (" << nEta << ") and phiGroup (" << hpar->phigroup.size()
813  << ") do not match";
814  throw cms::Exception("DDException") << "HcalDDDRecConstants: inconsistent array sizes" << nEta << ":"
815  << hpar->phigroup.size();
816  }
817 
818  // First eta table
819  iEtaMin = hpar->etaMin;
820  iEtaMax = hpar->etaMax;
821  etaTable.clear();
822  ietaMap.clear();
823  etaSimValu.clear();
824  int ieta(0), ietaHB(0), ietaHE(0), ietaHEM(0);
825  etaTable.emplace_back(hpar->etaTable[ieta]);
826  for (int i = 0; i < nEta; ++i) {
827  int ef = ieta + 1;
828  ieta += (hpar->etagroup[i]);
829  if (ieta >= (int)(hpar->etaTable.size())) {
830  edm::LogError("HCalGeom") << "HcalDDDRecConstants: Going beyond the array boundary " << hpar->etaTable.size()
831  << " at index " << i << " of etaTable from SimConstant";
832  throw cms::Exception("DDException")
833  << "HcalDDDRecConstants: Going beyond the array boundary " << hpar->etaTable.size() << " at index " << i
834  << " of etaTable from SimConstant";
835  } else {
836  etaTable.emplace_back(hpar->etaTable[ieta]);
837  etaSimValu.emplace_back(std::pair<int, int>(ef, ieta));
838  }
839  for (int k = 0; k < (hpar->etagroup[i]); ++k)
840  ietaMap.emplace_back(i + 1);
841  if (ieta <= hpar->etaMax[0])
842  ietaHB = i + 1;
843  if (ieta <= hpar->etaMin[1])
844  ietaHE = i + 1;
845  if (ieta <= hpar->etaMax[1])
846  ietaHEM = i + 1;
847  }
848  iEtaMin[1] = ietaHE;
849  iEtaMax[0] = ietaHB;
850  iEtaMax[1] = ietaHEM;
851 
852  // Then Phi bins
853  nPhiBins.clear();
854  for (unsigned int k = 0; k < 4; ++k)
855  nPhiBins.emplace_back(0);
856  ieta = 0;
857  phibin.clear();
858  phiUnitS.clear();
859  for (int i = 0; i < nEta; ++i) {
860  double dphi = (hpar->phigroup[i]) * (hpar->phibin[ieta]);
861  phibin.emplace_back(dphi);
862  int nphi = (int)((2._pi + 0.001) / dphi);
863  if (ieta <= iEtaMax[0]) {
864  if (nphi > nPhiBins[0])
865  nPhiBins[3] = nPhiBins[0] = nphi;
866  }
867  if (ieta >= iEtaMin[1]) {
868  if (nphi > nPhiBins[1])
869  nPhiBins[1] = nphi;
870  }
871  ieta += (hpar->etagroup[i]);
872  }
873  for (unsigned int i = 1; i < hpar->etaTable.size(); ++i) {
874  int unit = hcons.unitPhi(hpar->phibin[i - 1]);
875  phiUnitS.emplace_back(unit);
876  }
877  for (double i : hpar->phitable) {
878  int nphi = (int)((2._pi + 0.001) / i);
879  if (nphi > nPhiBins[2])
880  nPhiBins[2] = nphi;
881  }
882 #ifdef EDM_ML_DEBUG
883  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants: Modified eta/deltaphi table for " << nEta << " bins";
884  for (int i = 0; i < nEta; ++i)
885  edm::LogVerbatim("HCalGeom") << "Eta[" << i << "] = " << etaTable[i] << ":" << etaTable[i + 1] << ":"
886  << etaSimValu[i].first << ":" << etaSimValu[i].second << " PhiBin[" << i
887  << "] = " << convertRadToDeg(phibin[i]);
888  for (unsigned int i = 0; i < phiUnitS.size(); ++i)
889  edm::LogVerbatim("HCalGeom") << " PhiUnitS[" << i << "] = " << phiUnitS[i];
890  for (unsigned int i = 0; i < nPhiBins.size(); ++i)
891  edm::LogVerbatim("HCalGeom") << " nPhiBins[" << i << "] = " << nPhiBins[i];
892  for (unsigned int i = 0; i < hpar->etaTableHF.size(); ++i)
893  edm::LogVerbatim("HCalGeom") << " EtaTableHF[" << i << "] = " << hpar->etaTableHF[i];
894  for (unsigned int i = 0; i < hpar->phitable.size(); ++i)
895  edm::LogVerbatim("HCalGeom") << " PhiBinHF[" << i << "] = " << hpar->phitable[i];
896 #endif
897 
898  //Now the depths
900  maxDepth[0] = maxDepth[1] = 0;
901  for (int i = 0; i < nEta; ++i) {
902  unsigned int imx = layerGroupSize(i);
903  int laymax = (imx > 0) ? layerGroup(i, imx - 1) : 0;
904  if (i < iEtaMax[0]) {
905  int laymax0 = (imx > 16) ? layerGroup(i, 16) : laymax;
906  if (i + 1 == iEtaMax[0])
907  laymax0 = hcons.getDepthEta16M(1);
908 #ifdef EDM_ML_DEBUG
909  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:HB " << i << " " << imx << " " << laymax << " " << laymax0;
910 #endif
911  if (maxDepth[0] < laymax0)
912  maxDepth[0] = laymax0;
913  }
914  if (i >= iEtaMin[1] - 1 && i < iEtaMax[1]) {
915 #ifdef EDM_ML_DEBUG
916  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:HE " << i << " " << imx << " " << laymax;
917 #endif
918  if (maxDepth[1] < laymax)
919  maxDepth[1] = laymax;
920  }
921  }
922 #ifdef EDM_ML_DEBUG
923  for (int i = 0; i < 4; ++i)
924  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:Detector Type[" << i << "] iEta " << iEtaMin[i] << ":"
925  << iEtaMax[i] << " MaxDepth " << maxDepth[i];
926 #endif
927 
928  //Now the geometry constants
929  nModule[0] = hpar->modHB[0];
930  nHalves[0] = hpar->modHB[1];
931  for (unsigned int i = 0; i < hpar->rHB.size(); ++i) {
932  gconsHB.emplace_back(std::pair<double, double>(hpar->rHB[i] / CLHEP::cm, hpar->drHB[i] / CLHEP::cm));
933  }
934 #ifdef EDM_ML_DEBUG
935  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:HB with " << nModule[0] << " modules and " << nHalves[0]
936  << " halves and " << gconsHB.size() << " layers";
937  for (unsigned int i = 0; i < gconsHB.size(); ++i)
938  edm::LogVerbatim("HCalGeom") << "rHB[" << i << "] = " << gconsHB[i].first << " +- " << gconsHB[i].second;
939 #endif
940  nModule[1] = hpar->modHE[0];
941  nHalves[1] = hpar->modHE[1];
942  for (unsigned int i = 0; i < hpar->zHE.size(); ++i) {
943  gconsHE.emplace_back(std::pair<double, double>(hpar->zHE[i] / CLHEP::cm, hpar->dzHE[i] / CLHEP::cm));
944  }
945 #ifdef EDM_ML_DEBUG
946  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:HE with " << nModule[1] << " modules and " << nHalves[1]
947  << " halves and " << gconsHE.size() << " layers";
948  for (unsigned int i = 0; i < gconsHE.size(); ++i)
949  edm::LogVerbatim("HCalGeom") << "zHE[" << i << "] = " << gconsHE[i].first << " +- " << gconsHE[i].second;
950 #endif
951 
952  //Special RBX
954  if (depthMaxSp_.first == 0) {
955  depthMaxSp_ = depthMaxDf_ = std::pair<int, int>(2, maxDepth[1]);
956  } else if (depthMaxSp_.first == 1) {
957  depthMaxDf_ = std::pair<int, int>(1, maxDepth[0]);
958  if (depthMaxSp_.second > maxDepth[0])
959  maxDepth[0] = depthMaxSp_.second;
960  } else {
961  depthMaxDf_ = std::pair<int, int>(2, maxDepth[1]);
962  if (depthMaxSp_.second > maxDepth[1])
963  maxDepth[1] = depthMaxSp_.second;
964  }
965 #ifdef EDM_ML_DEBUG
966  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:Detector type and maximum depth for all RBX "
967  << depthMaxDf_.first << ":" << depthMaxDf_.second << " and for special RBX "
968  << depthMaxSp_.first << ":" << depthMaxSp_.second;
969 #endif
970 
971  //Map of special DetId's
972  std::vector<int> phis;
974  detIdSp_.clear();
975  detIdSpR_.clear();
976  if ((subdet == HcalBarrel) || (subdet == HcalEndcap)) {
977  int phi = (phis[0] > 0) ? phis[0] : -phis[0];
978  int zside = (phis[0] > 0) ? 1 : -1;
979  int lymax = (subdet == HcalBarrel) ? maxLayerHB_ + 1 : maxLayer_ + 1;
980  std::pair<int, int> etas = hcons.ldMap()->validEta();
981  for (int eta = etas.first; eta <= etas.second; ++eta) {
982  std::map<int, std::pair<int, int>> oldDep;
983  int depth(0);
984  int lmin = layerGroup(eta - 1, 0);
985  for (int lay = 0; lay < lymax; ++lay) {
986  int depc = layerGroup(eta - 1, lay);
987  if (depth != depc) {
988  if (depth != 0)
989  oldDep[depth] = std::pair<int, int>(lmin, lay - 1);
990  depth = depc;
991  lmin = lay;
992  }
993  }
994  if (depth != 0)
995  oldDep[depth] = std::pair<int, int>(lmin, lymax - 1);
996 #ifdef EDM_ML_DEBUG
997  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:Eta|Phi|Zside " << eta << ":" << phi << ":" << zside
998  << " with " << oldDep.size() << " old Depths";
999  unsigned int kk(0);
1000  for (std::map<int, std::pair<int, int>>::const_iterator itr = oldDep.begin(); itr != oldDep.end(); ++itr, ++kk)
1001  edm::LogVerbatim("HCalGeom") << "[" << kk << "] " << itr->first << " --> " << itr->second.first << ":"
1002  << itr->second.second;
1003 #endif
1004  std::pair<int, int> depths = hcons.ldMap()->getDepths(eta);
1005  for (int ndepth = depths.first; ndepth <= depths.second; ++ndepth) {
1006  bool flag = ((subdet == HcalBarrel && eta == iEtaMax[0] && ndepth > hcons.getDepthEta16(subdet, phi, zside)) ||
1007  (subdet == HcalEndcap && eta == iEtaMin[1] && ndepth < hcons.getDepthEta16(subdet, phi, zside)));
1008  if (!flag) {
1009  std::vector<int> count(oldDep.size(), 0);
1010  int layFront = hcons.ldMap()->getLayerFront(subdet, eta, phi, zside, ndepth);
1011  int layBack = hcons.ldMap()->getLayerBack(subdet, eta, phi, zside, ndepth);
1012  for (int lay = layFront; lay <= layBack; ++lay) {
1013  unsigned int l(0);
1014  for (std::map<int, std::pair<int, int>>::iterator itr = oldDep.begin(); itr != oldDep.end(); ++itr, ++l) {
1015  if (lay >= (itr->second).first && lay <= (itr->second).second) {
1016  ++count[l];
1017  break;
1018  }
1019  }
1020  }
1021  int odepth(0), maxlay(0);
1022  unsigned int l(0);
1023  for (std::map<int, std::pair<int, int>>::iterator itr = oldDep.begin(); itr != oldDep.end(); ++itr, ++l) {
1024  if (count[l] > maxlay) {
1025  odepth = itr->first;
1026  maxlay = count[l];
1027  }
1028  }
1029 #ifdef EDM_ML_DEBUG
1030  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:New Depth " << ndepth << " old Depth " << odepth
1031  << " max " << maxlay;
1032 #endif
1033  for (int k : phis) {
1034  zside = (k > 0) ? 1 : -1;
1035  phi = (k > 0) ? k : -k;
1036  if (subdet == HcalEndcap && eta == hpar->noff[1] && ndepth > hcons.getDepthEta29M(0, true))
1037  break;
1038  HcalDetId newId(subdet, zside * eta, phi, ndepth);
1039  HcalDetId oldId(subdet, zside * eta, phi, odepth);
1040  detIdSp_[newId] = oldId;
1041  std::vector<HcalDetId> ids;
1042  std::map<HcalDetId, std::vector<HcalDetId>>::iterator itr = detIdSpR_.find(oldId);
1043  if (itr != detIdSpR_.end())
1044  ids = itr->second;
1045  ids.emplace_back(newId);
1046  detIdSpR_[oldId] = ids;
1047  }
1048  }
1049  }
1050  }
1051 #ifdef EDM_ML_DEBUG
1052  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:Map for merging new channels to old channel"
1053  << " IDs with " << detIdSp_.size() << " entries";
1054  int l(0);
1055  for (auto itr : detIdSp_) {
1056  edm::LogVerbatim("HCalGeom") << "[" << l << "] Special " << itr.first << " Standard " << itr.second;
1057  ++l;
1058  }
1059  edm::LogVerbatim("HCalGeom") << "HcalDDDRecConstants:Reverse Map for mapping old to new IDs with "
1060  << detIdSpR_.size() << " entries";
1061  l = 0;
1062  for (auto itr : detIdSpR_) {
1063  edm::LogVerbatim("HCalGeom") << "[" << l << "] Standard " << itr.first << " Special";
1064  for (auto itr1 : itr.second)
1065  edm::LogVerbatim("HCalGeom") << "ID " << (itr1);
1066  ++l;
1067  }
1068 #endif
1069  }
1070 }
1071 
1072 unsigned int HcalDDDRecConstants::layerGroupSize(int eta) const {
1073  unsigned int k = 0;
1074  for (auto const& it : hpar->layerGroupEtaRec) {
1075  if (it.layer == (unsigned int)(eta + 1)) {
1076  return it.layerGroup.size();
1077  }
1078  if (it.layer > (unsigned int)(eta + 1))
1079  break;
1080  k = it.layerGroup.size();
1081  }
1082  return k;
1083 }
1084 
1085 unsigned int HcalDDDRecConstants::layerGroup(int eta, int i) const {
1086  unsigned int k = 0;
1087  for (auto const& it : hpar->layerGroupEtaRec) {
1088  if (it.layer == (unsigned int)(eta + 1)) {
1089  return it.layerGroup.at(i);
1090  }
1091  if (it.layer > (unsigned int)(eta + 1))
1092  break;
1093  k = it.layerGroup.at(i);
1094  }
1095  return k;
1096 }
int getMinDepth(const int &itype, const int &ieta, const int &iphi, const int &zside) const
Log< level::Info, true > LogVerbatim
const int nphi
std::map< HcalDetId, HcalDetId > detIdSp_
double getRZ(const int &subdet, const int &ieta, const int &depth) const
std::vector< double > etaTable
std::vector< int > iEtaMin
std::vector< int > etagroup
int getFrontLayer(const int &det, const int &eta) const
std::pair< int, int > depthMaxSp_
HcalDetId mergedDepthDetId(const HcalDetId &id) const
std::vector< double > rHB
void getOneEtaBin(HcalSubdetector subdet, int ieta, int zside, std::vector< std::pair< int, double >> &phis, std::map< int, int > &layers, bool planOne, std::vector< HcalDDDRecConstants::HcalEtaBin > &bins) const
int getDepthEta29M(const int &i, const bool &planOne) const
std::vector< std::pair< int, double > > getPhis(const int &subdet, const int &ieta) const
constexpr NumType convertRadToDeg(NumType radians)
Definition: angle_units.h:21
bool mergedDepthList29(int ieta, int iphi, int depth) const
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
int getLayerFront(const int subdet, const int ieta, const int iphi, const int zside, const int depth) const
int getDepthEta29(const int &phi, const int &zside, const int &i) const
static const int maxLayer_
HcalID getHCID(int subdet, int ieta, int iphi, int lay, int idepth) const
HcalDetId idBack(const HcalDetId &id) const
uint32_t etaMaxHBHE() const
std::vector< int > maxDepth
int zside(DetId const &)
std::pair< double, double > getPhiCons(const int &det, const int &ieta) const
Log< level::Error, false > LogError
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
unsigned int nCells() const
std::vector< HcalEtaBin > getEtaBins(const int &itype) const
std::vector< double > etaTableHF
int getDepthEta16M(const int &det) const
unsigned int numberOfCells(const HcalSubdetector &) const
std::vector< int > etaMax
constexpr std::array< uint8_t, layerIndexSize > layer
std::vector< int > phiUnitS
std::vector< int > modHB
int phiNumber(const int &phi, const int &unit) const
std::vector< HFCellParameters > getHFCellParameters() const
U second(std::pair< T, U > const &p)
std::vector< std::pair< double, double > > gconsHE
const HcalParameters * hpar
std::pair< double, double > getEtaPhi(const int &subdet, const int &ieta, const int &iphi) const
void specialRBXHBHE(const std::vector< HcalDetId > &, std::vector< HcalDetId > &) const
const std::vector< double > & getRTableHF() const
std::pair< int, int > getMaxDepthDet(const int &i) const
std::pair< int, int > depthMaxDf_
std::vector< double > zHE
std::vector< double > phibin
std::pair< int, int > getDepths(const int eta) const
std::vector< double > dzHE
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< int > iEtaMax
HcalSubdetector
Definition: HcalAssistant.h:31
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
std::vector< HcalCellType > HcalCellTypes() const
std::vector< int > ietaMap
std::vector< int > nPhiBins
const std::vector< double > & getPhiTableHF() const
const std::vector< int > & getPhis() const
const HcalLayerDepthMap * ldMap() const
std::vector< int > modHE
std::vector< std::pair< int, int > > layer
std::vector< std::pair< int, int > > etaSimValu
int getMaxDepth(const int &type) const
int findDepth(const int &det, const int &eta, const int &phi, const int &zside, const int &lay) const
unsigned int layerGroupSize(int eta) const
Basic3DVector unit() const
int unitPhi(const int &det, const int &etaR) const
std::vector< HcalCellType > HcalCellTypes(HcalSubdetector) const
std::vector< std::pair< double, double > > gconsHB
int getLayerBack(const int subdet, const int ieta, const int iphi, const int zside, const int depth) const
#define M_PI
Log< level::Info, false > LogInfo
caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple const cms::cuda::AtomicPairCounter GPUCACell const *__restrict__ cells
std::vector< double > phioff
int getPhiZOne(std::vector< std::pair< int, int >> &phiz) const
std::vector< double > etaTable
const std::vector< HcalDetId > & getIdHF2QIE() const
HcalDDDRecConstants(const HcalParameters *hp, const HcalDDDSimConstants &hc)
unsigned int numberOfCells(HcalSubdetector) const
void getLayerDepth(const int &ieta, std::map< int, int > &layers) const
int getMinDepth(const int &det, const int &eta, const int &phi, const int &zside, const bool &partialOnly) const
std::vector< double > phitable
HcalDetId idFront(const HcalDetId &id) const
TString units(TString variable, Char_t axis)
std::vector< double > phibin
std::vector< LayerItem > layerGroupEtaRec
int getLayerFront(const int &det, const int &eta, const int &phi, const int &depth) const
std::vector< double > drHB
const HcalDDDSimConstants & hcons
std::vector< HcalActiveLength > getThickActive(const int &type) const
unsigned int layerGroup(int eta, int i) const
std::vector< int > noff
std::vector< std::pair< int, double > > phis
const int ndepth
void unmergeDepthDetId(const HcalDetId &id, std::vector< HcalDetId > &ids) const
void getLayerDepth(const int subdet, const int ieta, const int iphi, const int zside, std::map< int, int > &layers) const
std::vector< int > maxDepth
std::vector< int > phigroup
std::pair< int, int > validEta() const
std::vector< int > getDepth(const int &det, const int &phi, const int &zside, const unsigned int &eta) const
int getMaxDepth(const int &type) const
int getLastLayer(const int &det, const int &eta) const
Geom::Theta< T > theta() const
static const int maxLayerHB_
int validDet(std::vector< int > &phis) const
int getDepthEta16(const int &det, const int &phi, const int &zside) const
int getLayerBack(const int &det, const int &eta, const int &phi, const int &depth) const
std::map< HcalDetId, std::vector< HcalDetId > > detIdSpR_
std::vector< int > etaMin