CMS 3D CMS Logo

HcalFlexiHardcodeGeometryLoader.cc
Go to the documentation of this file.
9 
10 #include <vector>
11 #include <algorithm>
12 
14 
15 //#define EDM_ML_DEBUG
16 
17 // ==============> Loader Itself <==========================
18 
20 
21  MAX_HCAL_PHI = 72;
22  DEGREE2RAD = M_PI / 180.;
23 }
24 
26  HcalGeometry* hcalGeometry = new HcalGeometry (fTopology);
27  if( nullptr == hcalGeometry->cornersMgr() ) hcalGeometry->allocateCorners ( fTopology.ncells()+fTopology.getHFSize() );
28  if( nullptr == hcalGeometry->parMgr() ) hcalGeometry->allocatePar (hcalGeometry->numberOfShapes(),
30  isBH_ = hcons.isBH();
31 #ifdef EDM_ML_DEBUG
32  std::cout << "FlexiGeometryLoader initialize with ncells "
33  << fTopology.ncells() << " and shapes "
34  << hcalGeometry->numberOfShapes() << ":"
36  << " with BH Flag " << isBH_ << std::endl;
37 #endif
38  if (fTopology.mode() == HcalTopologyMode::H2) { // TB geometry
39  fillHBHO (hcalGeometry, makeHBCells(hcons), true);
40  fillHBHO (hcalGeometry, makeHOCells(), false);
41  fillHE (hcalGeometry, makeHECells_H2());
42  } else { // regular geometry
43  fillHBHO (hcalGeometry, makeHBCells(hcons), true);
44  fillHBHO (hcalGeometry, makeHOCells(), false);
45  fillHF (hcalGeometry, makeHFCells(hcons));
46  fillHE (hcalGeometry, makeHECells(hcons));
47  }
48  //fast insertion of valid ids requires sort at end
49  hcalGeometry->sortValidIds();
50  return hcalGeometry;
51 }
52 
53 
54 // ----------> HB <-----------
55 std::vector<HcalFlexiHardcodeGeometryLoader::HBHOCellParameters> HcalFlexiHardcodeGeometryLoader::makeHBCells (const HcalDDDRecConstants& hcons) {
56 
57  std::vector<HcalFlexiHardcodeGeometryLoader::HBHOCellParameters> result;
58  std::vector<std::pair<double,double> > gconsHB = hcons.getConstHBHE(0);
59  std::vector<HcalDDDRecConstants::HcalEtaBin> etabins = hcons.getEtaBins(0);
60 
61 #ifdef EDM_ML_DEBUG
62  std::cout << "FlexiGeometryLoader called for " << etabins.size()
63  << " Eta Bins" << std::endl;
64  for (unsigned int k=0; k<gconsHB.size(); ++k) {
65  std::cout << "gconsHB[" << k << "] = " << gconsHB[k].first << " +- "
66  << gconsHB[k].second << std::endl;
67  }
68 #endif
69  for (auto & etabin : etabins) {
70  int iring = (etabin.zside >= 0) ? etabin.ieta : -etabin.ieta;
71  int depth = etabin.depthStart;
72  double dphi = (etabin.phis.size() > 1) ?
73  (etabin.phis[1].second-etabin.phis[0].second) :
74  ((2.0*M_PI)/MAX_HCAL_PHI);
75  for (unsigned int k=0; k<etabin.layer.size(); ++k) {
76  int layf = etabin.layer[k].first-1;
77  int layl = etabin.layer[k].second-1;
78  double rmin = gconsHB[layf].first-gconsHB[layf].second;
79  double rmax = gconsHB[layl].first+gconsHB[layl].second;
80  for (unsigned int j=0; j<etabin.phis.size(); ++j) {
81 #ifdef EDM_ML_DEBUG
82  std::cout << "HBRing " << iring << " eta " << etabin.etaMin << ":"
83  << etabin.etaMax << " depth " << depth << " R " << rmin
84  << ":" << rmax << " Phi " << etabin.phis[j].first << ":"
85  << etabin.phis[j].second << ":" << dphi << " layer[" << k
86  << "]: " << etabin.layer[k].first-1 << ":"
87  << etabin.layer[k].second << std::endl;
88 #endif
89  result.emplace_back (HcalFlexiHardcodeGeometryLoader::HBHOCellParameters(iring, depth, etabin.phis[j].first, etabin.phis[j].second, dphi, rmin, rmax, etabin.etaMin, etabin.etaMax));
90  }
91  depth++;
92  }
93  }
94  return result;
95 }
96 
97 
98 // ----------> HO <-----------
99 std::vector<HcalFlexiHardcodeGeometryLoader::HBHOCellParameters> HcalFlexiHardcodeGeometryLoader::makeHOCells () {
100  const double HORMIN0 = 390.0;
101  const double HORMIN1 = 412.6;
102  const double HORMAX = 413.6;
103  const int nCells = 15;
104  const int nPhi = 72;
105  const double etamin[nCells] = {0.000,0.087,0.174, 0.261, 0.3395,0.435,0.522,
106  0.609,0.696,0.783, 0.873, 0.957, 1.044,1.131,
107  1.218};
108  const double etamax[nCells] = {0.087,0.174,0.261, 0.3075,0.435, 0.522,0.609,
109  0.696,0.783,0.8494,0.957, 1.044, 1.131,1.218,
110  1.305};
111  std::vector<HcalFlexiHardcodeGeometryLoader::HBHOCellParameters> result;
112  result.reserve (nCells*nPhi);
113  double dphi = ((2.0*M_PI)/nPhi);
114  for (int i = 0; i < nCells; ++i) {
115  double rmin = ((i < 4) ? HORMIN0 : HORMIN1);
116  for (int iside = -1; iside <= 1; iside += 2) {
117  for (int j=0; j < nPhi; ++j) {
118  double phi = (j+0.5)*dphi;
119  // eta, depth, phi, phi0, deltaPhi, rMin, rMax, etaMin, etaMax
120  result.emplace_back (HcalFlexiHardcodeGeometryLoader::HBHOCellParameters(iside*(i+1), 4, j+1, phi, dphi, rmin, HORMAX, etamin[i], etamax[i]));
121  }
122  }
123  }
124  return result;
125 }
126 
127 
128 //
129 // Convert constants to appropriate cells
130 //
131 void HcalFlexiHardcodeGeometryLoader::fillHBHO (HcalGeometry* fGeometry, const std::vector<HcalFlexiHardcodeGeometryLoader::HBHOCellParameters>& fCells, bool fHB) {
132 
133  fGeometry->increaseReserve(fCells.size());
134  for (const auto & param : fCells) {
135  HcalDetId hid (fHB ? HcalBarrel : HcalOuter, param.ieta, param.iphi, param.depth);
136  float phiCenter = param.phi; // middle of the cell
137  float etaCenter = 0.5*(param.etaMin + param.etaMax);
138  float x = param.rMin* cos (phiCenter);
139  float y = param.rMin* sin (phiCenter);
140  float z = (param.ieta < 0) ? -(param.rMin*sinh(etaCenter)) : (param.rMin*sinh(etaCenter));
141  // make cell geometry
142  GlobalPoint refPoint (x,y,z); // center of the cell's face
143  std::vector<CCGFloat> cellParams;
144  cellParams.reserve (5);
145  cellParams.emplace_back (0.5 * (param.etaMax - param.etaMin)); // deta_half
146  cellParams.emplace_back (0.5 * param.dphi); // dphi_half
147  cellParams.emplace_back (0.5 * (param.rMax - param.rMin) * cosh (etaCenter)); // dr_half
148  cellParams.emplace_back ( fabs( refPoint.eta() ) ) ;
149  cellParams.emplace_back ( fabs( refPoint.z() ) ) ;
150 #ifdef EDM_ML_DEBUG
151  std::cout << "HcalFlexiHardcodeGeometryLoader::fillHBHO-> " << hid
152  << " " << hid.rawId() << " " << std::hex << hid.rawId()
153  << std::dec << " " << hid << " " << refPoint << '/'
154  << cellParams [0] << '/' << cellParams [1] << '/'
155  << cellParams [2] << std::endl;
156 #endif
157  fGeometry->newCellFast(refPoint, refPoint, refPoint,
158  CaloCellGeometry::getParmPtr(cellParams,
159  fGeometry->parMgr(),
160  fGeometry->parVecVec()),
161  hid ) ;
162  }
163 }
164 
165 
166 // ----------> HE <-----------
167 std::vector<HcalFlexiHardcodeGeometryLoader::HECellParameters> HcalFlexiHardcodeGeometryLoader::makeHECells (const HcalDDDRecConstants& hcons) {
168 
169  std::vector<HcalFlexiHardcodeGeometryLoader::HECellParameters> result;
170  std::vector<std::pair<double,double> > gconsHE = hcons.getConstHBHE(1);
171 #ifdef EDM_ML_DEBUG
172  std::cout << "HcalFlexiHardcodeGeometryLoader:HE with " << gconsHE.size()
173  << " cells" << std::endl;
174 #endif
175  if (!gconsHE.empty()) {
176  std::vector<HcalDDDRecConstants::HcalEtaBin> etabins = hcons.getEtaBins(1);
177 
178 #ifdef EDM_ML_DEBUG
179  std::cout << "FlexiGeometryLoader called for HE with " << etabins.size()
180  << " Eta Bins and " << gconsHE.size() << " depths"
181  << std::endl;
182  for (unsigned int i=0; i<gconsHE.size(); ++i)
183  std::cout << " Depth[" << i << "] = " << gconsHE[i].first << " +- "
184  << gconsHE[i].second;
185  std::cout << std::endl;
186 #endif
187  for (auto & etabin : etabins) {
188  int iring = (etabin.zside >= 0) ? etabin.ieta : -etabin.ieta;
189  int depth = etabin.depthStart;
190  double dphi = (etabin.phis.size() > 1) ?
191  (etabin.phis[1].second-etabin.phis[0].second) :
192  ((2.0*M_PI)/MAX_HCAL_PHI);
193 #ifdef EDM_ML_DEBUG
194  std::cout << "FlexiGeometryLoader::Ring " << iring << " nphi "
195  << etabin.phis.size() << " dstart " << depth << " dphi "
196  << dphi << " layers "<< etabin.layer.size() << std::endl;
197  for (unsigned int j=0; j<etabin.phis.size(); ++j)
198  std::cout << " [" << j << "] " << etabin.phis[j].first << ":"
199  << etabin.phis[j].second;
200  std::cout << std::endl;
201 #endif
202  for (unsigned int k=0; k<etabin.layer.size(); ++k) {
203  int layf = etabin.layer[k].first-1;
204  int layl = etabin.layer[k].second-1;
205  double zmin = gconsHE[layf].first-gconsHE[layf].second;
206  double zmax = gconsHE[layl].first+gconsHE[layl].second;
207  if (zmin < 1.0) {
208  for (int k2=layf; k2<=layl; ++k2) {
209  if (gconsHE[k2].first > 10) {
210  zmin = gconsHE[k2].first-gconsHE[k2].second;
211  break;
212  }
213  }
214  }
215  if (zmin >= zmax) zmax = zmin+10.;
216  for (unsigned int j=0; j<etabin.phis.size(); ++j) {
217 #ifdef EDM_ML_DEBUG
218  std::cout << "HERing " << iring << " eta " << etabin.etaMin << ":"
219  << etabin.etaMax << " depth " << depth << " Z " << zmin
220  << ":" << zmax << " Phi :" << etabin.phis[j].first
221  << ":" << etabin.phis[j].second << ":" << dphi
222  << " layer[" << k << "]: " << etabin.layer[k].first-1
223  << ":" << etabin.layer[k].second-1 << std::endl;
224 #endif
225  result.emplace_back(HcalFlexiHardcodeGeometryLoader::HECellParameters(iring, depth, etabin.phis[j].first, etabin.phis[j].second, dphi, zmin, zmax, etabin.etaMin, etabin.etaMax));
226  }
227  depth++;
228  }
229  }
230  }
231  return result;
232 }
233 
234 
235 // ----------> HE @ H2 <-----------
236 std::vector <HcalFlexiHardcodeGeometryLoader::HECellParameters> HcalFlexiHardcodeGeometryLoader::makeHECells_H2 () {
237 
238  const double HEZMIN_H2 = 400.715;
239  const double HEZMID_H2 = 436.285;
240  const double HEZMAX_H2 = 541.885;
241  const int nEtas = 10;
242  const int nDepth[nEtas] = {1,2,2,2,2,2,2,2,3,3};
243  const int dStart[nEtas] = {3,1,1,1,1,1,1,1,1,1};
244  const int nPhis[nEtas] = {8,8,8,8,8,8,4,4,4,4};
245  const double etas[nEtas+1] = {1.305,1.373,1.444,1.521,1.603,1.693,1.790,
246  1.880,1.980,2.090,2.210};
247  const double zval[4*nEtas] = {409.885,462.685,0.,0.,
248  HEZMIN_H2,427.485,506.685,0.0,
249  HEZMIN_H2,HEZMID_H2,524.285,0.,
250  HEZMIN_H2,HEZMID_H2,HEZMAX_H2,0.,
251  HEZMIN_H2,HEZMID_H2,HEZMAX_H2,0.,
252  HEZMIN_H2,HEZMID_H2,HEZMAX_H2,0.,
253  HEZMIN_H2,HEZMID_H2,HEZMAX_H2,0.,
254  HEZMIN_H2,HEZMID_H2,HEZMAX_H2,0.,
255  HEZMIN_H2,418.685,HEZMID_H2,HEZMAX_H2,
256  HEZMIN_H2,418.685,HEZMID_H2,HEZMAX_H2};
257  std::vector<HcalFlexiHardcodeGeometryLoader::HECellParameters> result;
258 
259  for (int i = 0; i < nEtas; ++i) {
260  int ieta = 16+i;
261  for (int k=0; k<nDepth[i]; ++k) {
262  int depth = dStart[i]+k;
263  for (int j=0; j < nPhis[i]; ++j) {
264  int iphi = (nPhis[i] == 8) ? (j+1) : (2*j+1);
265  double dphi = (40.0*DEGREE2RAD)/nPhis[i];
266  double phi0 = (j+0.5)*dphi;
267  // ieta, depth, iphi, phi0, deltaPhi, zMin, zMax, etaMin, etaMax
268  result.emplace_back (HcalFlexiHardcodeGeometryLoader::HECellParameters(ieta, depth, iphi, phi0, dphi, zval[4*i+k+1], zval[4*i+k+2], etas[i], etas[i+1]));
269  }
270  }
271  }
272  return result;
273 }
274 
275 // ----------> HF <-----------
276 std::vector <HcalFlexiHardcodeGeometryLoader::HFCellParameters> HcalFlexiHardcodeGeometryLoader::makeHFCells (const HcalDDDRecConstants& hcons) {
277 
278  const float HFZMIN1 = 1115.;
279  const float HFZMIN2 = 1137.;
280  const float HFZMAX = 1280.1;
281  std::vector<HcalDDDRecConstants::HFCellParameters> cells = hcons.getHFCellParameters();
282  unsigned int nCells = cells.size();
283  std::vector <HcalFlexiHardcodeGeometryLoader::HFCellParameters> result;
284  result.reserve (nCells);
285  for (unsigned int i = 0; i < nCells; ++i) {
286  HcalFlexiHardcodeGeometryLoader::HFCellParameters cell1(cells[i].ieta,cells[i].depth,cells[i].firstPhi,cells[i].stepPhi,cells[i].nPhi,5*cells[i].stepPhi,HFZMIN1,HFZMAX,cells[i].rMin,cells[i].rMax);
287  result.emplace_back (cell1);
288  HcalFlexiHardcodeGeometryLoader::HFCellParameters cell2(cells[i].ieta,1+cells[i].depth,cells[i].firstPhi,cells[i].stepPhi,cells[i].nPhi,5*cells[i].stepPhi,HFZMIN2,HFZMAX,cells[i].rMin,cells[i].rMax);
289  result.emplace_back (cell2);
290  }
291  return result;
292 }
293 
294 void HcalFlexiHardcodeGeometryLoader::fillHE (HcalGeometry* fGeometry, const std::vector <HcalFlexiHardcodeGeometryLoader::HECellParameters>& fCells) {
295 
296  fGeometry->increaseReserve(fCells.size());
297  for (const auto & param : fCells) {
298  HcalDetId hid (HcalEndcap, param.ieta, param.iphi, param.depth);
299  float phiCenter = param.phi; // middle of the cell
300  float etaCenter = 0.5 * (param.etaMin + param.etaMax);
301  int iside = (param.ieta >= 0) ? 1 : -1;
302  float z = (isBH_) ? (iside*0.5*(param.zMin+param.zMax)) : (iside*param.zMin);
303  float perp = std::abs(z) / sinh (etaCenter);
304  float x = perp * cos (phiCenter);
305  float y = perp * sin (phiCenter);
306  // make cell geometry
307  GlobalPoint refPoint (x,y,z); // center of the cell's face
308  std::vector<CCGFloat> cellParams;
309  cellParams.reserve (5);
310  cellParams.emplace_back (0.5 * (param.etaMax - param.etaMin)); //deta_half
311  cellParams.emplace_back (0.5 * param.dphi); // dphi_half
312  cellParams.emplace_back (-0.5 * (param.zMax - param.zMin) / tanh (etaCenter)); // dz_half, "-" means edges in Z
313  cellParams.emplace_back ( fabs( refPoint.eta() ) ) ;
314  cellParams.emplace_back ( fabs( refPoint.z() ) ) ;
315 #ifdef EDM_ML_DEBUG
316  std::cout << "HcalFlexiHardcodeGeometryLoader::fillHE-> " << hid << " "
317  << hid.rawId() << " " << std::hex << hid.rawId() << std::dec
318  << " " << hid << refPoint << '/' << cellParams [0] << '/'
319  << cellParams [1] << '/' << cellParams [2] << std::endl;
320 #endif
321  fGeometry->newCellFast(refPoint, refPoint, refPoint,
322  CaloCellGeometry::getParmPtr(cellParams,
323  fGeometry->parMgr(),
324  fGeometry->parVecVec()),
325  hid ) ;
326  }
327 }
328 
329 void HcalFlexiHardcodeGeometryLoader::fillHF (HcalGeometry* fGeometry, const std::vector <HcalFlexiHardcodeGeometryLoader::HFCellParameters>& fCells) {
330 
331  fGeometry->increaseReserve(fCells.size());
332  for (const auto & param : fCells) {
333  for (int kPhi = 0; kPhi < param.nPhi; ++kPhi) {
334  int iPhi = param.phiFirst + kPhi*param.phiStep;
335  HcalDetId hid (HcalForward, param.eta, iPhi, param.depth);
336  // middle of the cell
337  float phiCenter = ((iPhi-1)*360./MAX_HCAL_PHI + 0.5*param.dphi) * DEGREE2RAD;
338  GlobalPoint inner (param.rMin, 0, param.zMin);
339  GlobalPoint outer (param.rMax, 0, param.zMin);
340  float iEta = inner.eta();
341  float oEta = outer.eta();
342  float etaCenter = 0.5 * ( iEta + oEta );
343 
344  float perp = param.zMin / sinh (etaCenter);
345  float x = perp * cos (phiCenter);
346  float y = perp * sin (phiCenter);
347  float z = (param.eta > 0) ? param.zMin : -param.zMin;
348  // make cell geometry
349  GlobalPoint refPoint (x,y,z); // center of the cell's face
350  std::vector<CCGFloat> cellParams;
351  cellParams.reserve (5);
352  cellParams.emplace_back (0.5 * ( iEta - oEta )); // deta_half
353  cellParams.emplace_back (0.5 * param.dphi * DEGREE2RAD); // dphi_half
354  cellParams.emplace_back (0.5 * (param.zMax - param.zMin)); // dz_half
355  cellParams.emplace_back ( fabs( refPoint.eta()));
356  cellParams.emplace_back ( fabs( refPoint.z() ) ) ;
357 #ifdef EDM_ML_DEBUG
358  std::cout << "HcalFlexiHardcodeGeometryLoader::fillHF-> " << hid << " "
359  << hid.rawId() << " " << std::hex << hid.rawId() << std::dec
360  << " " << hid << " " << refPoint << '/' << cellParams [0]
361  << '/' << cellParams [1] << '/' << cellParams [2] << std::endl;
362 #endif
363  fGeometry->newCellFast(refPoint, refPoint, refPoint,
364  CaloCellGeometry::getParmPtr(cellParams,
365  fGeometry->parMgr(),
366  fGeometry->parVecVec()),
367  hid ) ;
368  }
369  }
370 }
CaloCellGeometry::CCGFloat CCGFloat
unsigned int getHFSize() const
Definition: HcalTopology.h:135
std::vector< std::pair< double, double > > getConstHBHE(const int &type) const
std::vector< HFCellParameters > makeHFCells(const HcalDDDRecConstants &hcons)
Sin< T >::type sin(const T &t)
Definition: Sin.h:22
unsigned int numberOfShapes() const override
Definition: HcalGeometry.h:43
std::vector< HECellParameters > makeHECells_H2()
HcalFlexiHardcodeGeometryLoader(const edm::ParameterSet &)
void allocatePar(ParVec::size_type n, unsigned int m)
std::vector< HBHOCellParameters > makeHBCells(const HcalDDDRecConstants &hcons)
HcalTopologyMode::Mode mode() const
Definition: HcalTopology.h:31
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
U second(std::pair< T, U > const &p)
void newCellFast(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
std::vector< HcalEtaBin > getEtaBins(const int &itype) const
std::vector< HBHOCellParameters > makeHOCells()
void sortValidIds()
T z() const
Definition: PV3DBase.h:64
Cos< T >::type cos(const T &t)
Definition: Cos.h:22
std::vector< HFCellParameters > getHFCellParameters() const
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
void fillHE(HcalGeometry *fGeometry, const std::vector< HECellParameters > &fCells)
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
std::vector< HECellParameters > makeHECells(const HcalDDDRecConstants &hcons)
#define M_PI
int k[5][pyjets_maxn]
CaloCellGeometry::CornersMgr * cornersMgr()
void increaseReserve(unsigned int extra)
T eta() const
Definition: PV3DBase.h:76
T perp() const
Magnitude of transverse component.
void fillHBHO(HcalGeometry *fGeometry, const std::vector< HBHOCellParameters > &fCells, bool fHB)
CaloSubdetectorGeometry * load(const HcalTopology &fTopology, const HcalDDDRecConstants &hcons)
unsigned int ncells() const override
return a count of valid cells (for dense indexing use)
void allocateCorners(CaloCellGeometry::CornersVec::size_type n)
void fillHF(HcalGeometry *fGeometry, const std::vector< HFCellParameters > &fCells)