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