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