CMS 3D CMS Logo

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