CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDDDSimConstants.cc
Go to the documentation of this file.
2 
5 
6 #include "CLHEP/Units/GlobalPhysicalConstants.h"
7 #include "CLHEP/Units/GlobalSystemOfUnits.h"
8 
9 //#define EDM_ML_DEBUG
10 
12 
13 #ifdef EDM_ML_DEBUG
14  edm::LogInfo("HCalGeom") << "HcalDDDSimConstants::HcalDDDSimConstants (const HcalParameter* hp) constructor\n";
15 #endif
16 
17  initialize();
18 #ifdef EDM_ML_DEBUG
19  std::vector<HcalCellType> cellTypes = HcalCellTypes();
20  std::cout << "HcalDDDSimConstants: " << cellTypes.size()
21  << " cells of type HCal (All)\n";
22 #endif
23 }
24 
25 
27 #ifdef EDM_ML_DEBUG
28  edm::LogInfo ("HCalGeom") << "HcalDDDSimConstants::destructed!!!\n";
29 #endif
30 }
31 
33  int depth, int etaR,
34  int iphi) const {
35 
36  double etaMn = hpar->etaMin[0];
37  double etaMx = hpar->etaMax[0];
38  if (idet==static_cast<int>(HcalEndcap)) {
39  etaMn = hpar->etaMin[1]; etaMx = hpar->etaMax[1];
40  } else if (idet==static_cast<int>(HcalForward)) {
41  etaMn = hpar->etaMin[2]; etaMx = hpar->etaMax[2];
42  }
43  double eta = 0, deta = 0, phi = 0, dphi = 0, rz = 0, drz = 0;
44  bool ok = false, flagrz = true;
45  if ((idet==static_cast<int>(HcalBarrel)||idet==static_cast<int>(HcalEndcap)||
46  idet==static_cast<int>(HcalOuter)||idet==static_cast<int>(HcalForward))
47  && etaR >=etaMn && etaR <= etaMx && depth > 0) ok = true;
48  if (idet == static_cast<int>(HcalEndcap) && depth>(int)(hpar->zHE.size()))ok=false;
49  else if (idet == static_cast<int>(HcalBarrel) && depth > 17) ok=false;
50  else if (idet == static_cast<int>(HcalOuter) && depth != 4) ok=false;
51  else if (idet == static_cast<int>(HcalForward) && depth > maxDepth[2]) ok=false;
52  if (ok) {
53  eta = getEta(idet, etaR, zside, depth);
54  deta = deltaEta(idet, etaR, depth);
55  double fibin, fioff;
56  if (idet == static_cast<int>(HcalBarrel)||
57  idet == static_cast<int>(HcalOuter)) {
58  fioff = hpar->phioff[0];
59  fibin = hpar->phibin[etaR-1];
60  } else if (idet == static_cast<int>(HcalEndcap)) {
61  fioff = hpar->phioff[1];
62  fibin = hpar->phibin[etaR-1];
63  } else {
64  fioff = hpar->phioff[2];
65  fibin = hpar->phitable[etaR-hpar->etaMin[2]];
66  if (unitPhi(fibin) > 2) fioff = hpar->phioff[4];
67  }
68  phi =-fioff + (iphi - 0.5)*fibin;
69  dphi = 0.5*fibin;
70  if (idet == static_cast<int>(HcalForward)) {
71  int ir = nR + hpar->etaMin[2] - etaR - 1;
72  if (ir > 0 && ir < nR) {
73  rz = 0.5*(hpar->rTable[ir]+hpar->rTable[ir-1]);
74  drz = 0.5*(hpar->rTable[ir]-hpar->rTable[ir-1]);
75  } else {
76  ok = false;
77 #ifdef EDM_ML_DEBUG
78  edm::LogInfo("HCalGeom") << "HcalDDDSimConstants: wrong eta " << etaR
79  << " (" << ir << "/" << nR << ") Detector "
80  << idet << std::endl;
81 #endif
82  }
83  } else if (etaR <= nEta) {
84  int laymin(depth), laymax(depth);
85  if (idet == static_cast<int>(HcalOuter)) {
86  laymin = (etaR > hpar->noff[2]) ? ((int)(hpar->zHE.size())) : ((int)(hpar->zHE.size()))-1;
87  laymax = ((int)(hpar->zHE.size()));
88  }
89  double d1=0, d2=0;
90  if (idet == static_cast<int>(HcalEndcap)) {
91  flagrz = false;
92  d1 = hpar->zHE[laymin-1] - hpar->dzHE[laymin-1];
93  d2 = hpar->zHE[laymax-1] + hpar->dzHE[laymax-1];
94  } else {
95  d1 = hpar->rHB[laymin-1] - hpar->drHB[laymin-1];
96  d2 = hpar->rHB[laymax-1] + hpar->drHB[laymax-1];
97  }
98  rz = 0.5*(d2+d1);
99  drz = 0.5*(d2-d1);
100  } else {
101  ok = false;
102  edm::LogWarning("HCalGeom") << "HcalDDDSimConstants: wrong depth "
103  << depth << " or etaR " << etaR
104  << " for detector " << idet;
105  }
106  } else {
107  ok = false;
108  edm::LogWarning("HCalGeom") << "HcalDDDSimConstants: wrong depth " << depth
109  << " det " << idet;
110  }
111  HcalCellType::HcalCell tmp(ok,eta,deta,phi,dphi,rz,drz,flagrz);
112 
113 #ifdef EDM_ML_DEBUG
114  std::cout << "HcalDDDSimConstants: det/side/depth/etaR/phi "
115  << idet << "/" << zside << "/" << depth << "/"
116  << etaR << "/" << iphi << " Cell Flag " << tmp.ok
117  << " " << tmp.eta << " " << tmp.deta << " phi "
118  << tmp.phi << " " << tmp.dphi << " r(z) " << tmp.rz
119  << " " << tmp.drz << " " << tmp.flagrz << std::endl;
120 #endif
121  return tmp;
122 }
123 
124 std::vector<std::pair<double,double> > HcalDDDSimConstants::getConstHBHE(const int type) const {
125 
126  std::vector<std::pair<double,double> > gcons;
127  if (type == 0) {
128  for (unsigned int i=0; i<hpar->rHB.size(); ++i) {
129  gcons.push_back(std::pair<double,double>(hpar->rHB[i],hpar->drHB[i]));
130  }
131  } else {
132  for (unsigned int i=0; i<hpar->zHE.size(); ++i) {
133  gcons.push_back(std::pair<double,double>(hpar->zHE[i],hpar->dzHE[i]));
134  }
135  }
136  return gcons;
137 }
138 
139 
140 std::pair<int,double> HcalDDDSimConstants::getDetEta(double eta, int depth) {
141 
142  int hsubdet(0), ieta(0);
143  double etaR(0);
144  double heta = fabs(eta);
145  for (int i = 0; i < nEta; i++)
146  if (heta > hpar->etaTable[i]) ieta = i + 1;
147  if (heta <= hpar->etaRange[1]) {
148  if ((ieta <= hpar->etaMin[1] && depth==depthEta16[1]) ||
149  (ieta > hpar->etaMax[0])) {
150  hsubdet = static_cast<int>(HcalEndcap);
151  } else {
152  hsubdet = static_cast<int>(HcalBarrel);
153  }
154  etaR = eta;
155  } else {
156  hsubdet = static_cast<int>(HcalForward);
157  double theta = 2.*atan(exp(-heta));
158  double hR = zVcal*tan(theta);
159  etaR = (eta >= 0. ? hR : -hR);
160  }
161  return std::pair<int,double>(hsubdet,etaR);
162 }
163 
164 int HcalDDDSimConstants::getEta(int det, int lay, double hetaR) {
165 
166  int ieta(0);
167  if (det == static_cast<int>(HcalForward)) { // Forward HCal
168  ieta = hpar->etaMax[2];
169  for (int i = nR-1; i > 0; i--)
170  if (hetaR < hpar->rTable[i]) ieta = hpar->etaMin[2] + nR - i - 1;
171  } else { // Barrel or Endcap
172  ieta = 1;
173  for (int i = 0; i < nEta-1; i++)
174  if (hetaR > hpar->etaTable[i]) ieta = i + 1;
175  if (det == static_cast<int>(HcalBarrel)) {
176  if (ieta > hpar->etaMax[0]) ieta = hpar->etaMax[0];
177  if (lay == 18) {
178  if (hetaR > etaHO[1] && ieta == hpar->noff[2]) ieta++;
179  }
180  } else if (det == static_cast<int>(HcalEndcap)) {
181  if (ieta <= hpar->etaMin[1]) ieta = hpar->etaMin[1];
182  }
183  }
184  return ieta;
185 }
186 
187 std::pair<int,int> HcalDDDSimConstants::getEtaDepth(int det, int etaR, int phi,
188  int depth, int lay) {
189 
190  //Modify the depth index
191  if (det == static_cast<int>(HcalForward)) { // Forward HCal
192  } else if (det == static_cast<int>(HcalOuter)) {
193  depth = 4;
194  } else {
195  if (lay >= 0) {
196  depth= layerGroup(etaR-1, lay-1);
197  if (etaR == hpar->noff[0] && lay > 1) {
198  int kphi = phi + int((hpar->phioff[3]+0.1)/hpar->phibin[etaR-1]);
199  kphi = (kphi-1)%4 + 1;
200  if (kphi == 2 || kphi == 3) depth = layerGroup(etaR-1, lay-2);
201  }
202  } else if (det == static_cast<int>(HcalBarrel)) {
203  if (depth>maxDepth[0]) depth = maxDepth[0];
204  }
205  if (etaR >= hpar->noff[1] && depth > depthEta29[0]) {
206  etaR -= depthEta29[1];
207  } else if (etaR == hpar->etaMin[1]) {
208  if (det == static_cast<int>(HcalBarrel)) {
209  if (depth > depthEta16[0]) depth = depthEta16[0];
210  } else {
211  if (depth < depthEta16[1]) depth = depthEta16[1];
212  }
213  }
214  }
215  if ((det == static_cast<int>(HcalEndcap)) && (etaR == 17) && (lay == 1))
216  etaR = 18;
217  return std::pair<int,int>(etaR,depth);
218 }
219 
220 double HcalDDDSimConstants::getEtaHO(double& etaR, double& x, double& y,
221  double& z) const {
222 
223  if (hpar->zHO.size() > 4) {
224  double eta = fabs(etaR);
225  double r = std::sqrt(x*x+y*y);
226  if (r > rminHO) {
227  double zz = fabs(z);
228  if (zz > hpar->zHO[3]) {
229  if (eta <= hpar->etaTable[10]) eta = hpar->etaTable[10]+0.001;
230  } else if (zz > hpar->zHO[1]) {
231  if (eta <= hpar->etaTable[4]) eta = hpar->etaTable[4]+0.001;
232  }
233  }
234  eta = (z >= 0. ? eta : -eta);
235 #ifdef EDM_ML_DEBUG
236  std::cout << "R " << r << " Z " << z << " eta " << etaR
237  << ":" << eta << std::endl;
238  if (eta != etaR) edm::LogInfo ("HCalGeom") << "**** Check *****";
239 #endif
240  return eta;
241  } else {
242  return etaR;
243  }
244 }
245 
246 double HcalDDDSimConstants::getLayer0Wt(int det, int , int ) const {
247 
248  return ((det == 2) ? hpar->Layer0Wt[1] : hpar->Layer0Wt[0]);
249 }
250 
251 unsigned int HcalDDDSimConstants::findLayer(int layer, const std::vector<HcalParameters::LayerItem>& layerGroup) const {
252 
253  unsigned int id = layerGroup.size();
254  for (unsigned int i = 0; i < layerGroup.size(); i++) {
255  if (layer == (int)(layerGroup[i].layer)) {
256  id = i;
257  break;
258  }
259  }
260  return id;
261 }
262 
263 std::pair<int,int> HcalDDDSimConstants::getModHalfHBHE(const int type) const {
264 
265  if (type == 0) {
266  return std::pair<int,int>(nmodHB,nzHB);
267  } else {
268  return std::pair<int,int>(nmodHE,nzHE);
269  }
270 }
271 
272 std::pair<double,double> HcalDDDSimConstants::getPhiCons(int det, int ieta) {
273 
274  double fioff(0), fibin(0);
275  if (det == static_cast<int>(HcalForward)) { // Forward HCal
276  fioff = hpar->phioff[2];
277  fibin = hpar->phitable[ieta-hpar->etaMin[2]];
278  if (unitPhi(fibin) > 2) { // HF double-phi
279  fioff = hpar->phioff[4];
280  }
281  } else { // Barrel or Endcap
282  if (det == static_cast<int>(HcalBarrel)) {
283  fioff = hpar->phioff[0];
284  } else {
285  fioff = hpar->phioff[1];
286  }
287  fibin = hpar->phibin[ieta-1];
288  }
289  return std::pair<double,double>(fioff,fibin);
290 }
291 
292 std::vector<HcalCellType> HcalDDDSimConstants::HcalCellTypes() const{
293 
294  std::vector<HcalCellType> cellTypes = HcalCellTypes(HcalBarrel);
295 #ifdef EDM_ML_DEBUG
296  edm::LogInfo ("HCalGeom") << "HcalDDDSimConstants: " << cellTypes.size()
297  << " cells of type HCal Barrel\n";
298  for (unsigned int i=0; i<cellTypes.size(); i++)
299  edm::LogInfo ("HCalGeom") << "Cell " << i << " " << cellTypes[i] << "\n";
300 #endif
301 
302  std::vector<HcalCellType> hoCells = HcalCellTypes(HcalOuter);
303 #ifdef EDM_ML_DEBUG
304  edm::LogInfo ("HCalGeom") << "HcalDDDSimConstants: " << hoCells.size()
305  << " cells of type HCal Outer\n";
306  for (unsigned int i=0; i<hoCells.size(); i++)
307  edm::LogInfo ("HCalGeom") << "Cell " << i << " " << hoCells[i] << "\n";
308 #endif
309  cellTypes.insert(cellTypes.end(), hoCells.begin(), hoCells.end());
310 
311  std::vector<HcalCellType> heCells = HcalCellTypes(HcalEndcap);
312 #ifdef EDM_ML_DEBUG
313  edm::LogInfo ("HCalGeom") << "HcalDDDSimConstants: " << heCells.size()
314  << " cells of type HCal Endcap\n";
315  for (unsigned int i=0; i<heCells.size(); i++)
316  edm::LogInfo ("HCalGeom") << "Cell " << i << " " << heCells[i] << "\n";
317 #endif
318  cellTypes.insert(cellTypes.end(), heCells.begin(), heCells.end());
319 
320  std::vector<HcalCellType> hfCells = HcalCellTypes(HcalForward);
321 #ifdef EDM_ML_DEBUG
322  edm::LogInfo ("HCalGeom") << "HcalDDDSimConstants: " << hfCells.size()
323  << " cells of type HCal Forward\n";
324  for (unsigned int i=0; i<hfCells.size(); i++)
325  edm::LogInfo ("HCalGeom") << "Cell " << i << " " << hfCells[i] << "\n";
326 #endif
327  cellTypes.insert(cellTypes.end(), hfCells.begin(), hfCells.end());
328 
329  return cellTypes;
330 }
331 
332 std::vector<HcalCellType> HcalDDDSimConstants::HcalCellTypes(HcalSubdetector subdet,
333  int ieta, int depthl) const {
334 
335  std::vector<HcalCellType> cellTypes;
336  if (subdet == HcalForward) {
337  if (dzVcal < 0) return cellTypes;
338  }
339 
340  int dmin, dmax, indx, nz, nmod;
341  double hsize = 0;
342  switch(subdet) {
343  case HcalEndcap:
344  dmin = 1; dmax = 19; indx = 1; nz = nzHE; nmod = nmodHE;
345  break;
346  case HcalForward:
347  dmin = 1; dmax = maxDepth[2]; indx = 2; nz = 2; nmod = 18;
348  break;
349  case HcalOuter:
350  dmin = 4; dmax = 4; indx = 0; nz = nzHB; nmod = nmodHB;
351  break;
352  default:
353  dmin = 1; dmax = 17; indx = 0; nz = nzHB; nmod = nmodHB;
354  break;
355  }
356  if (depthl > 0) dmin = dmax = depthl;
357  int ietamin = (ieta>0) ? ieta : hpar->etaMin[indx];
358  int ietamax = (ieta>0) ? ieta : hpar->etaMax[indx];
359  int phi = 1, zside = 1;
360 
361  // Get the Cells
362  int subdet0 = static_cast<int>(subdet);
363  for (int depth=dmin; depth<=dmax; depth++) {
364  int shift = getShift(subdet, depth);
365  double gain = getGain (subdet, depth);
366  if (subdet == HcalForward) {
367  if (depth%2 == 1) hsize = dzVcal;
368  else hsize = dzVcal-0.5*dlShort;
369  }
370  for (int eta=ietamin; eta<= ietamax; eta++) {
371  HcalCellType::HcalCell temp1 = cell(subdet0,zside,depth,eta,phi);
372  if (temp1.ok) {
373  int units = unitPhi (subdet0, eta);
374  HcalCellType temp2(subdet, eta, phi, depth, temp1,
375  shift, gain, nz, nmod, hsize, units);
376  if (subdet == HcalOuter) {
377  if (eta == hpar->noff[4]) {
378  std::vector<int> missPlus, missMinus;
379  int kk = 7;
380  for (int miss=0; miss<hpar->noff[5]; miss++) {
381  missPlus.push_back(hpar->noff[kk]);
382  kk++;
383  }
384  for (int miss=0; miss<hpar->noff[6]; miss++) {
385  missMinus.push_back(hpar->noff[kk]);
386  kk++;
387  }
388  temp2.setMissingPhi(missPlus, missMinus);
389  }
390  } else if (subdet == HcalForward) {
391  if (idHF2QIE.size() > 0 && depth > 2) {
392  int phiInc = 4/temp2.nPhiModule();
393  int iphi = 1;
394  if (temp2.unitPhi() == 4) iphi = 3;
395  std::vector<int> missPlus, missMinus;
396  for (int k=0; k<temp2.nPhiBins(); ++k) {
397  bool okp(true), okn(true);
398  for (unsigned int l=0; l<idHF2QIE.size(); ++l) {
399  if ((eta == idHF2QIE[l].ietaAbs()) &&
400  (iphi == idHF2QIE[l].iphi())) {
401  if (idHF2QIE[l].zside() == 1) okp = false;
402  else okn = false;
403  }
404  }
405  if (okp) missPlus.push_back(iphi);
406  if (okn) missMinus.push_back(iphi);
407  iphi += phiInc;
408  }
409  temp2.setMissingPhi(missPlus, missMinus);
410  }
411  }
412  cellTypes.push_back(temp2);
413  }
414  }
415  }
416  return cellTypes;
417 }
418 
419 int HcalDDDSimConstants::maxHFDepth(int eta, int iphi) const {
420  int mxdepth = maxDepth[2];
421  if (idHF2QIE.size() > 0) {
422  bool ok(false);
423  for (unsigned int k=0; k<idHF2QIE.size(); ++k) {
424  if ((eta == idHF2QIE[k].ieta()) && (iphi == idHF2QIE[k].iphi())) {
425  ok = true; break;
426  }
427  }
428  if (!ok) mxdepth = 2;
429  }
430  return mxdepth;
431 }
432 
434 
435  unsigned int num = 0;
436  std::vector<HcalCellType> cellTypes = HcalCellTypes(subdet);
437  for (unsigned int i=0; i<cellTypes.size(); i++) {
438  int ncur = (cellTypes[i].nHalves() > 1) ? 2*cellTypes[i].nPhiBins() :
439  cellTypes[i].nPhiBins();
440  num += (unsigned int)(ncur);
441  num -= (unsigned int)(cellTypes[i].nPhiMissingBins());
442  }
443 #ifdef EDM_ML_DEBUG
444  std::cout << "HcalDDDSimConstants:numberOfCells "
445  << cellTypes.size() << " " << num
446  << " for subdetector " << subdet << std::endl;
447 #endif
448  return num;
449 }
450 
452 
453  int iphi_skip = phi;
454  if (units==2) iphi_skip = (phi-1)*2+1;
455  else if (units==4) iphi_skip = (phi-1)*4-1;
456  if (iphi_skip < 0) iphi_skip += 72;
457  return iphi_skip;
458 }
459 
461 
462  std::cout << "Tile Information for HB from " << hpar->etaMin[0] << " to " << hpar->etaMax[0] << "\n\n";
463  for (int eta=hpar->etaMin[0]; eta<= hpar->etaMax[0]; eta++) {
464  int dmax = 1;
465  if (depths[0][eta-1] < 17) dmax = 2;
466  if (maxDepth[0] > 2) {
467  if (eta == hpar->etaMin[1]) dmax = depthEta16[0];
468  else dmax = maxDepth[0];
469  }
470  for (int depth=1; depth<=dmax; depth++)
472  }
473 
474  std::cout << "\nTile Information for HE from " << hpar->etaMin[1] << " to " << hpar->etaMax[1] << "\n\n";
475  for (int eta=hpar->etaMin[1]; eta<= hpar->etaMax[1]; eta++) {
476  int dmin=1, dmax=3;
477  if (eta == hpar->etaMin[1]) {
478  dmax = dmin = depthEta16[1];
479  } else if (depths[0][eta-1] > 18) {
480  dmax = 1;
481  } else if (depths[1][eta-1] > 18) {
482  dmax = 2;
483  }
484  for (int depth=dmin; depth<=dmax; depth++)
486  }
487 }
488 
489 int HcalDDDSimConstants::unitPhi(int det, int etaR) const {
490 
491  double dphi = (det == static_cast<int>(HcalForward)) ? hpar->phitable[etaR-hpar->etaMin[2]] : hpar->phibin[etaR-1];
492  return unitPhi(dphi);
493 }
494 
495 int HcalDDDSimConstants::unitPhi(double dphi) const {
496 
497  const double fiveDegInRad = 2*M_PI/72;
498  int units = int(dphi/fiveDegInRad+0.5);
499  if (units < 1) units = 1;
500  return units;
501 }
502 
504 
505  nEta = hpar->etaTable.size();
506  nR = hpar->rTable.size();
507  nPhiF = nR - 1;
508  isBH_ = false;
509 
510 #ifdef EDM_ML_DEBUG
511  for (int i=0; i<nEta-1; ++i) {
512  std::cout << "HcalDDDSimConstants:Read LayerGroup" << i << ":";
513  for (unsigned int k=0; k<layerGroupSize(i); k++)
514  std::cout << " [" << k << "] = " << layerGroup(i, k);
515  std::cout << std::endl;
516  }
517 #endif
518 
519  // Geometry parameters for HF
520  dlShort = hpar->gparHF[0];
521  zVcal = hpar->gparHF[4];
522  dzVcal = hpar->dzVcal;
523 #ifdef EDM_ML_DEBUG
524  std::cout << "HcalDDDSimConstants: dlShort " << dlShort << " zVcal " << zVcal
525  << " and dzVcal " << dzVcal << std::endl;
526 #endif
527 
528  //Transform some of the parameters
530  maxDepth[0] = maxDepth[1] = 0;
531  for (int i=0; i<nEta-1; ++i) {
532  unsigned int imx = layerGroupSize(i);
533  int laymax = (imx > 0) ? layerGroup(i, imx-1) : 0;
534  if (i < hpar->etaMax[0]) {
535  int laymax0 = (imx > 16) ? layerGroup(i, 16) : laymax;
536  if (i+1 == hpar->etaMax[0] && laymax0 > 2) laymax0 = 2;
537  if (maxDepth[0] < laymax0) maxDepth[0] = laymax0;
538  }
539  if (i >= hpar->etaMin[1]-1 && i < hpar->etaMax[1]) {
540  if (maxDepth[1] < laymax) maxDepth[1] = laymax;
541  }
542  }
543 #ifdef EDM_ML_DEBUG
544  for (int i=0; i<4; ++i)
545  std::cout << "Detector Type [" << i << "] iEta " << hpar->etaMin[i] << ":"
546  << hpar->etaMax[i] << " MaxDepth " << maxDepth[i] << std::endl;
547 #endif
548 
549  int maxdepth = (maxDepth[1]>maxDepth[0]) ? maxDepth[1] : maxDepth[0];
550  for (int i=0; i<maxdepth; ++i) {
551  for (int k=0; k<nEta-1; ++k) {
552  int layermx = ((k+1 < hpar->etaMin[1]) && i < maxDepth[0]) ? 17 : (int)layerGroupSize(k);
553  int ll = layermx;
554  for (int l=layermx-1; l >= 0; --l) {
555  if ((int)layerGroup(k, l) == i+1) {
556  ll = l+1; break;
557  }
558  }
559  depths[i].push_back(ll);
560  }
561 
562 #ifdef EDM_ML_DEBUG
563  std::cout << "Depth " << i << " with " << depths[i].size() << " etas:";
564  for (int k=0; k<nEta-1; ++k) std::cout << " " << depths[i][k];
565  std::cout << std::endl;
566 #endif
567  }
568 
569  nzHB = hpar->modHB[0];
570  nmodHB = hpar->modHB[1];
571  nzHE = hpar->modHE[0];
572  nmodHE = hpar->modHE[1];
573 #ifdef EDM_ML_DEBUG
574  std::cout << "HcalDDDSimConstants:: " << nzHB << ":" << nmodHB
575  << " barrel and " << nzHE << ":" << nmodHE
576  << " endcap half-sectors" << std::endl;
577 #endif
578 
579  if (hpar->rHB.size() > 17 && hpar->zHO.size() > 4) {
580  rminHO = hpar->rHO[0];
581  for (int k=0; k<4; ++k) etaHO[k] = hpar->rHO[k+1];
582  } else {
583  rminHO =-1.0;
584  etaHO[0] = hpar->etaTable[4];
585  etaHO[1] = hpar->etaTable[4];
586  etaHO[2] = hpar->etaTable[10];
587  etaHO[3] = hpar->etaTable[10];
588  }
589 #ifdef EDM_ML_DEBUG
590  std::cout << "HO Eta boundaries " << etaHO[0] << " " << etaHO[1]
591  << " " << etaHO[2] << " " << etaHO[3] << std::endl;
592  std::cout << "HO Parameters " << rminHO << " " << hpar->zHO.size();
593  for (int i=0; i<4; ++i) std::cout << " eta[" << i << "] = " << etaHO[i];
594  for (unsigned int i=0; i<hpar->zHO.size(); ++i)
595  std::cout << " zHO[" << i << "] = " << hpar->zHO[i];
596  std::cout << std::endl;
597 #endif
598 
599  int noffsize = 7 + hpar->noff[5] + hpar->noff[6];
600  int noffl(noffsize+5);
601  if ((int)(hpar->noff.size()) > (noffsize+3)) {
602  depthEta16[0] = hpar->noff[noffsize];
603  depthEta16[1] = hpar->noff[noffsize+1];
604  depthEta29[0] = hpar->noff[noffsize+2];
605  depthEta29[1] = hpar->noff[noffsize+3];
606  if ((int)(hpar->noff.size()) > (noffsize+4)) {
607  noffl += (2*hpar->noff[noffsize+4]);
608  if ((int)(hpar->noff.size()) > noffl) isBH_ = (hpar->noff[noffl] > 0);
609  }
610  } else {
611  depthEta16[0] = 2;
612  depthEta16[1] = 3;
613  depthEta29[0] = 2;
614  depthEta29[1] = 1;
615  }
616 #ifdef EDM_ML_DEBUG
617  std::cout << "isBH_ " << hpar->noff.size() << ":" << noffsize << ":"
618  << noffl << ":" << isBH_ << std::endl;
619  std::cout << "Depth index at ieta = 16 for HB (max) " << depthEta16[0]
620  << " HE (min) " << depthEta16[1] << "; max depth for itea = 29 : ("
621  << depthEta29[0] << ":" << depthEta29[1] << ")" << std::endl;
622 #endif
623 
624  if ((int)(hpar->noff.size()) > (noffsize+4)) {
625  int npair = hpar->noff[noffsize+4];
626  int kk = noffsize+4;
627  for (int k=0; k<npair; ++k) {
628  idHF2QIE.push_back(HcalDetId(HcalForward,hpar->noff[kk+1],hpar->noff[kk+2],1));
629  kk += 2;
630  }
631  }
632 #ifdef EDM_ML_DEBUG
633  std::cout << idHF2QIE.size() << " detector channels having 2 QIE cards:"
634  << std::endl;
635  for (unsigned int k=0; k<idHF2QIE.size(); ++k)
636  std::cout << " [" << k << "] " << idHF2QIE[k] << std::endl;
637 #endif
638 }
639 
640 double HcalDDDSimConstants::deltaEta(int det, int etaR, int depth) const {
641 
642  double tmp = 0;
643  if (det == static_cast<int>(HcalForward)) {
644  int ir = nR + hpar->etaMin[2] - etaR - 1;
645  if (ir > 0 && ir < nR) {
646  double z = zVcal;
647  if (depth%2 != 1) z += dlShort;
648  tmp = 0.5*(getEta(hpar->rTable[ir-1],z)-getEta(hpar->rTable[ir],z));
649  }
650  } else {
651  if (etaR > 0 && etaR < nEta) {
652  if (etaR == hpar->noff[1]-1 && depth > depthEta29[0]) {
653  tmp = 0.5*(hpar->etaTable[etaR+1]-hpar->etaTable[etaR-1]);
654  } else if (det == static_cast<int>(HcalOuter)) {
655  if (etaR == hpar->noff[2]) {
656  tmp = 0.5*(etaHO[0]-hpar->etaTable[etaR-1]);
657  } else if (etaR == hpar->noff[2]+1) {
658  tmp = 0.5*(hpar->etaTable[etaR]-etaHO[1]);
659  } else if (etaR == hpar->noff[3]) {
660  tmp = 0.5*(etaHO[2]-hpar->etaTable[etaR-1]);
661  } else if (etaR == hpar->noff[3]+1) {
662  tmp = 0.5*(hpar->etaTable[etaR]-etaHO[3]);
663  } else {
664  tmp = 0.5*(hpar->etaTable[etaR]-hpar->etaTable[etaR-1]);
665  }
666  } else {
667  tmp = 0.5*(hpar->etaTable[etaR]-hpar->etaTable[etaR-1]);
668  }
669  }
670  }
671 #ifdef EDM_ML_DEBUG
672  std::cout << "HcalDDDSimConstants::deltaEta " << etaR << " "
673  << depth << " ==> " << tmp << std::endl;
674 #endif
675  return tmp;
676 }
677 
678 double HcalDDDSimConstants::getEta(int det, int etaR, int zside,
679  int depth) const {
680 
681  double tmp = 0;
682  if (det == static_cast<int>(HcalForward)) {
683  int ir = nR + hpar->etaMin[2] - etaR - 1;
684  if (ir > 0 && ir < nR) {
685  double z = zVcal;
686  if (depth%2 != 1) z += dlShort;
687  tmp = 0.5*(getEta(hpar->rTable[ir-1],z)+getEta(hpar->rTable[ir],z));
688  }
689  } else {
690  if (etaR > 0 && etaR < nEta) {
691  if (etaR == hpar->noff[1]-1 && depth > depthEta29[0]) {
692  tmp = 0.5*(hpar->etaTable[etaR+1]+hpar->etaTable[etaR-1]);
693  } else if (det == static_cast<int>(HcalOuter)) {
694  if (etaR == hpar->noff[2]) {
695  tmp = 0.5*(etaHO[0]+hpar->etaTable[etaR-1]);
696  } else if (etaR == hpar->noff[2]+1) {
697  tmp = 0.5*(hpar->etaTable[etaR]+etaHO[1]);
698  } else if (etaR == hpar->noff[3]) {
699  tmp = 0.5*(etaHO[2]+hpar->etaTable[etaR-1]);
700  } else if (etaR == hpar->noff[3]+1) {
701  tmp = 0.5*(hpar->etaTable[etaR]+etaHO[3]);
702  } else {
703  tmp = 0.5*(hpar->etaTable[etaR]+hpar->etaTable[etaR-1]);
704  }
705  } else {
706  tmp = 0.5*(hpar->etaTable[etaR]+hpar->etaTable[etaR-1]);
707  }
708  }
709  }
710  if (zside == 0) tmp = -tmp;
711 #ifdef EDM_ML_DEBUG
712  std::cout << "HcalDDDSimConstants::getEta " << etaR << " "
713  << zside << " " << depth << " ==> " << tmp << "\n";
714 #endif
715  return tmp;
716 }
717 
718 double HcalDDDSimConstants::getEta(double r, double z) const {
719 
720  double tmp = 0;
721  if (z != 0) tmp = -log(tan(0.5*atan(r/z)));
722 #ifdef EDM_ML_DEBUG
723  std::cout << "HcalDDDSimConstants::getEta " << r << " " << z
724  << " ==> " << tmp << std::endl;
725 #endif
726  return tmp;
727 }
728 
730 
731  int shift;
732  switch(subdet) {
733  case HcalEndcap:
734  shift = hpar->HEShift[0];
735  break;
736  case HcalForward:
737  shift = hpar->HFShift[(depth-1)%2];
738  break;
739  case HcalOuter:
740  shift = hpar->HBShift[3];
741  break;
742  default:
743  shift = hpar->HBShift[0];
744  break;
745  }
746  return shift;
747 }
748 
750 
751  double gain;
752  switch(subdet) {
753  case HcalEndcap:
754  gain = hpar->HEGains[0];
755  break;
756  case HcalForward:
757  gain = hpar->HFGains[(depth-1)%2];
758  break;
759  case HcalOuter:
760  gain = hpar->HBGains[3];
761  break;
762  default:
763  gain = hpar->HBGains[0];
764  break;
765  }
766  return gain;
767 }
768 
770  std::cout << "HcalDDDSimConstants::printTileHB for eta " << eta << " and depth " << depth << "\n";
771 
772  double etaL = hpar->etaTable.at(eta-1);
773  double thetaL = 2.*atan(exp(-etaL));
774  double etaH = hpar->etaTable.at(eta);
775  double thetaH = 2.*atan(exp(-etaH));
776  int layL=0, layH=0;
777  if (depth == 1) {
778  layH = depths[0][eta-1];
779  } else {
780  layL = depths[0][eta-1];
781  layH = depths[1][eta-1];
782  }
783  std::cout << "\ntileHB:: eta|depth " << eta << "|" << depth << " theta " << thetaH/CLHEP::deg << ":" << thetaL/CLHEP::deg << " Layer " << layL << ":" << layH-1 << "\n";
784  for (int lay=layL; lay<layH; ++lay) {
785  std::vector<double> area(2,0);
786  int kk=0;
787  for (unsigned int k=0; k<hpar->layHB.size(); ++k) {
788  if (lay == hpar->layHB[k]) {
789  double zmin = hpar->rhoxHB[k]*std::cos(thetaL)/std::sin(thetaL);
790  double zmax = hpar->rhoxHB[k]*std::cos(thetaH)/std::sin(thetaH);
791  double dz = (std::min(zmax,hpar->dxHB[k]) - zmin);
792  if (dz > 0) {
793  area[kk] = dz*hpar->dyHB[k];
794  kk++;
795  }
796  }
797  }
798  if (area[0] > 0) std::cout << std::setw(2) << lay << " Area " << std::setw(8) << area[0] << " " << std::setw(8) << area[1] << "\n";
799  }
800 }
801 
803 
804  double etaL = hpar->etaTable[eta-1];
805  double thetaL = 2.*atan(exp(-etaL));
806  double etaH = hpar->etaTable[eta];
807  double thetaH = 2.*atan(exp(-etaH));
808  int layL=0, layH=0;
809  if (eta == 16) {
810  layH = depths[2][eta-1];
811  } else if (depth == 1) {
812  layH = depths[0][eta-1];
813  } else if (depth == 2) {
814  layL = depths[0][eta-1];
815  layH = depths[1][eta-1];
816  } else {
817  layL = depths[1][eta-1];
818  layH = depths[2][eta-1];
819  }
820  double phib = hpar->phibin[eta-1];
821  int nphi = 2;
822  if (phib > 6*CLHEP::deg) nphi = 1;
823  std::cout << "\ntileHE:: Eta/depth " << eta << "|" << depth << " theta " << thetaH/CLHEP::deg << ":" << thetaL/CLHEP::deg << " Layer " << layL << ":" << layH-1 << " phi " << nphi << "\n";
824  for (int lay=layL; lay<layH; ++lay) {
825  std::vector<double> area(4,0);
826  int kk=0;
827  for (unsigned int k=0; k<hpar->layHE.size(); ++k) {
828  if (lay == hpar->layHE[k]) {
829  double rmin = hpar->zxHE[k]*std::tan(thetaH);
830  double rmax = hpar->zxHE[k]*std::tan(thetaL);
831  if ((lay != 0 || eta == 18) &&
832  (lay != 1 || (eta == 18 && hpar->rhoxHE[k]-hpar->dyHE[k] > 1000) ||
833  (eta != 18 && hpar->rhoxHE[k]-hpar->dyHE[k] < 1000)) &&
834  rmin+30 < hpar->rhoxHE[k]+hpar->dyHE[k] &&
835  rmax > hpar->rhoxHE[k]-hpar->dyHE[k]) {
836  rmin = std::max(rmin,hpar->rhoxHE[k]-hpar->dyHE[k]);
837  rmax = std::min(rmax,hpar->rhoxHE[k]+hpar->dyHE[k]);
838  double dx1 = rmin*std::tan(phib);
839  double dx2 = rmax*std::tan(phib);
840  double ar1=0, ar2=0;
841  if (nphi == 1) {
842  ar1 = 0.5*(rmax-rmin)*(dx1+dx2-4.*hpar->dx1HE[k]);
843  } else {
844  ar1 = 0.5*(rmax-rmin)*(dx1+dx2-2.*hpar->dx1HE[k]);
845  ar2 = 0.5*(rmax-rmin)*((rmax+rmin)*tan(10.*CLHEP::deg)-4*hpar->dx1HE[k])-ar1;
846  }
847  area[kk] = ar1;
848  area[kk+2] = ar2;
849  kk++;
850  }
851  }
852  }
853  if (area[0] > 0 && area[1] > 0) {
854  int lay0 = lay-1;
855  if (eta == 18) lay0++;
856  if (nphi == 1) {
857  std::cout << std::setw(2) << lay0 << " Area " << std::setw(8) << area[0] << " " << std::setw(8) << area[1] << "\n";
858  } else {
859  std::cout << std::setw(2) << lay0 << " Area " << std::setw(8) << area[0] << " " << std::setw(8) << area[1] << ":" << std::setw(8) << area[2] << " " << std::setw(8) << area[3] << "\n";
860  }
861  }
862  }
863 }
864 
865 unsigned int HcalDDDSimConstants::layerGroupSize(unsigned int eta) const {
866  unsigned int k = 0;
867  for (auto const & it : hpar->layerGroupEtaSim) {
868  if (it.layer == eta + 1) {
869  return it.layerGroup.size();
870  }
871  if (it.layer > eta + 1) break;
872  k = it.layerGroup.size();
873  }
874  return k;
875 }
876 
877 unsigned int HcalDDDSimConstants::layerGroup(unsigned int eta,
878  unsigned int i) const {
879  unsigned int k = 0;
880  for (auto const & it : hpar->layerGroupEtaSim) {
881  if (it.layer == eta + 1) {
882  return it.layerGroup.at(i);
883  }
884  if (it.layer > eta + 1) break;
885  k = it.layerGroup.at(i);
886  }
887  return k;
888 }
std::pair< int, int > getEtaDepth(int det, int etaR, int phi, int depth, int lay)
type
Definition: HCALResponse.h:21
std::vector< double > zHO
int i
Definition: DBlmapReader.cc:9
std::vector< double > etaTable
void setMissingPhi(std::vector< int > &, std::vector< int > &)
Definition: HcalCellType.cc:81
int unitPhi(int det, int etaR) const
void printTileHB(int eta, int depth) const
std::vector< int > layHE
std::vector< int > maxDepth
std::vector< double > rHB
int getEta(int det, int lay, double hetaR)
double getLayer0Wt(int det, int phi, int zside) const
std::vector< double > rhoxHB
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
std::vector< double > HBGains
Geom::Theta< T > theta() const
std::vector< int > HEShift
int zside(DetId const &)
std::vector< std::pair< double, double > > getConstHBHE(const int type) const
HcalDDDSimConstants(const HcalParameters *hp)
unsigned int numberOfCells(HcalSubdetector) const
float float float z
std::vector< int > etaMax
std::vector< int > depths[nDepthMax]
std::vector< int > modHB
std::vector< double > rhoxHE
std::vector< double > zxHE
T x() const
Cartesian x coordinate.
std::vector< double > zHE
double getEtaHO(double &etaR, double &x, double &y, double &z) const
std::vector< LayerItem > layerGroupEtaSim
void printTileHE(int eta, int depth) const
std::vector< double > dyHE
std::vector< double > dx1HE
std::vector< double > rHO
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
T sqrt(T t)
Definition: SSEVec.h:18
std::vector< double > dzHE
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
int getShift(HcalSubdetector subdet, int depth) const
double getGain(HcalSubdetector subdet, int depth) const
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
HcalSubdetector
Definition: HcalAssistant.h:31
std::vector< HcalCellType > HcalCellTypes() const
std::vector< int > modHE
std::vector< HcalDetId > idHF2QIE
T min(T a, T b)
Definition: MathUtil.h:58
std::pair< int, int > getModHalfHBHE(const int type) const
std::vector< int > HFShift
unsigned int findLayer(int layer, const std::vector< HcalParameters::LayerItem > &layerGroup) const
#define M_PI
std::vector< double > HEGains
std::pair< int, double > getDetEta(double eta, int depth)
std::vector< double > dyHB
std::vector< double > phioff
std::pair< double, double > getPhiCons(int det, int ieta)
std::vector< double > gparHF
double deltaEta(int det, int eta, int depth) const
Geom::Phi< T > phi() const
std::vector< double > Layer0Wt
std::vector< double > dxHB
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
std::vector< double > rTable
std::vector< double > phitable
TString units(TString variable, Char_t axis)
int nPhiModule() const
Definition: HcalCellType.h:52
std::vector< double > phibin
HcalCellType::HcalCell cell(int det, int zside, int depth, int etaR, int iphi) const
int phiNumber(int phi, int unit) const
std::vector< double > drHB
std::vector< double > HFGains
static unsigned int const shift
std::vector< int > noff
tuple cout
Definition: gather_cfg.py:145
std::vector< int > HBShift
int nPhiBins() const
the number of these cells in a ring
Definition: HcalCellType.h:51
const HcalParameters * hpar
std::vector< int > maxDepth
int unitPhi() const
Definition: HcalCellType.h:59
std::vector< int > layHB
unsigned int layerGroup(unsigned int eta, unsigned int i) const
std::vector< int > etaMin
int maxHFDepth(int ieta, int iphi) const
unsigned int layerGroupSize(unsigned int eta) const