CMS 3D CMS Logo

HGCalGeometryLoader.cc
Go to the documentation of this file.
13 
14 //#define EDM_ML_DEBUG
15 
17 typedef std::vector<float> ParmVec;
18 
19 HGCalGeometryLoader::HGCalGeometryLoader() : twoBysqrt3_(2.0 / std::sqrt(3.0)) {}
20 
22  // allocate geometry
24  unsigned int numberOfCells = topology.totalGeomModules(); // both sides
25  unsigned int numberExpected = topology.allGeomModules();
28  uint32_t numberOfShapes =
32 #ifdef EDM_ML_DEBUG
33  edm::LogVerbatim("HGCalGeom") << "Number of Cells " << numberOfCells << ":" << numberExpected << " for sub-detector "
34  << topology.subDetector() << " Shapes " << numberOfShapes << ":" << parametersPerShape_
35  << " mode " << mode;
36 #endif
37  geom->allocateCorners(numberOfCells);
38  geom->allocatePar(numberOfShapes, parametersPerShape_);
39 
40  // loop over modules
42  unsigned int counter(0);
43 #ifdef EDM_ML_DEBUG
44  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader with # of "
45  << "transformation matrices " << topology.dddConstants().getTrFormN() << " and "
46  << topology.dddConstants().volumes() << ":" << topology.dddConstants().sectors()
47  << " volumes";
48 #endif
49  for (unsigned itr = 0; itr < topology.dddConstants().getTrFormN(); ++itr) {
50  HGCalParameters::hgtrform mytr = topology.dddConstants().getTrForm(itr);
51  int zside = mytr.zp;
52  int layer = mytr.lay;
53 #ifdef EDM_ML_DEBUG
54  unsigned int kount(0);
55  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader:: Z:Layer " << zside << ":" << layer << " z " << mytr.h3v.z();
56 #endif
57  if (topology.waferHexagon6()) {
58  ForwardSubdetector subdet = topology.subDetector();
59  for (int wafer = 0; wafer < topology.dddConstants().sectors(); ++wafer) {
60  std::string code[2] = {"False", "True"};
61  if (topology.dddConstants().waferInLayer(wafer, layer, true)) {
62  int type = topology.dddConstants().waferTypeT(wafer);
63  if (type != 1)
64  type = 0;
65  DetId detId = static_cast<DetId>(HGCalDetId(subdet, zside, layer, type, wafer, 0));
66  const auto& w = topology.dddConstants().waferPosition(wafer, true);
67  double xx = (zside > 0) ? w.first : -w.first;
68  CLHEP::Hep3Vector h3v(xx, w.second, mytr.h3v.z());
69  const HepGeom::Transform3D ht3d(mytr.hr, h3v);
70 #ifdef EDM_ML_DEBUG
71  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader:: Wafer:Type " << wafer << ":" << type << " DetId "
72  << HGCalDetId(detId) << std::hex << " " << detId.rawId() << std::dec
73  << " transf " << ht3d.getTranslation() << " and " << ht3d.getRotation();
74 #endif
75  HGCalParameters::hgtrap vol = topology.dddConstants().getModule(wafer, true, true);
77  params[FlatHexagon::k_r] = topology.dddConstants().cellSizeHex(type);
79 
80  buildGeom(params, ht3d, detId, geom, 0);
81  counter++;
82 #ifdef EDM_ML_DEBUG
83  ++kount;
84 #endif
85  }
86  }
87  } else if (topology.tileTrapezoid()) {
88  int indx = topology.dddConstants().layerIndex(layer, true);
89  int ring = topology.dddConstants().getParameter()->iradMinBH_[indx];
90  int nphi = topology.dddConstants().getParameter()->scintCells(layer);
91  int type = topology.dddConstants().getParameter()->scintType(layer);
92  for (int md = topology.dddConstants().getParameter()->firstModule_[indx];
93  md <= topology.dddConstants().getParameter()->lastModule_[indx];
94  ++md) {
95  for (int iphi = 1; iphi <= nphi; ++iphi) {
97  std::pair<int, int> typm = topology.dddConstants().tileType(layer, ring, 0);
98  if (typm.first >= 0) {
99  id.setType(typm.first);
100  id.setSiPM(typm.second);
101  }
102  bool ok = test ? topology.dddConstants().tileExist(zside, layer, ring, iphi) : true;
103 #ifdef EDM_ML_DEBUG
104  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader::layer:rad:phi:type:sipm " << layer << ":"
105  << ring * zside << ":" << iphi << ":" << type << ":" << typm.first << ":"
106  << typm.second << " Test " << test << ":" << ok << " ID " << id;
107 #endif
108  if (ok) {
109  DetId detId = static_cast<DetId>(id);
110  const auto& w = topology.dddConstants().locateCellTrap(zside, layer, ring, iphi, true, false);
111  double xx = (zside > 0) ? w.first : -w.first;
112  CLHEP::Hep3Vector h3v(xx, w.second, mytr.h3v.z());
113  const HepGeom::Transform3D ht3d(mytr.hr, h3v);
114 #ifdef EDM_ML_DEBUG
115  edm::LogVerbatim("HGCalGeom")
116  << "HGCalGeometryLoader::rad:phi:type " << ring * zside << ":" << iphi << ":" << type << " DetId "
117  << HGCScintillatorDetId(detId) << " " << std::hex << detId.rawId() << std::dec << " transf "
118  << ht3d.getTranslation() << " R " << ht3d.getTranslation().perp() << " and " << ht3d.getRotation();
119 #endif
120  HGCalParameters::hgtrap vol = topology.dddConstants().getModule(md, false, true);
121  params[FlatTrd::k_dZ] = vol.dz;
127  params[FlatTrd::k_Cell] = topology.dddConstants().cellSizeHex(type);
128 
129  buildGeom(params, ht3d, detId, geom, 1);
130  counter++;
131 #ifdef EDM_ML_DEBUG
132  ++kount;
133 #endif
134  }
135  }
136  ++ring;
137  }
138  } else {
139  DetId::Detector det = topology.detector();
140  for (int wafer = 0; wafer < topology.dddConstants().sectors(); ++wafer) {
141  if (topology.dddConstants().waferInLayer(wafer, layer, true)) {
142  int copy = topology.dddConstants().getParameter()->waferCopy_[wafer];
143  int u = HGCalWaferIndex::waferU(copy);
145  int type = topology.dddConstants().getTypeHex(layer, u, v);
146  DetId detId =
147  (topology.isHFNose() ? static_cast<DetId>(HFNoseDetId(zside, type, layer, u, v, 0, 0))
148  : static_cast<DetId>(HGCSiliconDetId(det, zside, type, layer, u, v, 0, 0)));
149  const auto& w = topology.dddConstants().waferPosition(layer, u, v, true, true);
150  double xx = (zside > 0) ? w.first : -w.first;
151  CLHEP::Hep3Vector h3v(xx, w.second, mytr.h3v.z());
152  const HepGeom::Transform3D ht3d(mytr.hr, h3v);
153 #ifdef EDM_ML_DEBUG
154  if (topology.isHFNose())
155  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader::Wafer:Type " << wafer << ":" << type << " DetId "
156  << HFNoseDetId(detId) << std::hex << " " << detId.rawId() << std::dec
157  << " trans " << ht3d.getTranslation() << " and " << ht3d.getRotation();
158  else
159  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader::Wafer:Type " << wafer << ":" << type << " DetId "
160  << HGCSiliconDetId(detId) << std::hex << " " << detId.rawId() << std::dec
161  << " trans " << ht3d.getTranslation() << " and " << ht3d.getRotation();
162 #endif
163  HGCalParameters::hgtrap vol = topology.dddConstants().getModule(type, false, true);
164  params[FlatHexagon::k_dZ] = vol.dz;
165  params[FlatHexagon::k_r] = topology.dddConstants().cellSizeHex(type);
167 
168  buildGeom(params, ht3d, detId, geom, 0);
169  counter++;
170 #ifdef EDM_ML_DEBUG
171  ++kount;
172 #endif
173  }
174  }
175  }
176 #ifdef EDM_ML_DEBUG
177  edm::LogVerbatim("HGCalGeom") << kount << " modules found in Layer " << layer << " Z " << zside;
178 #endif
179  }
180 
181  geom->sortDetIds();
182 
183  if (counter != numberExpected) {
184  if (topology.tileTrapezoid()) {
185  edm::LogVerbatim("HGCalGeom") << "Inconsistent # of cells: expected " << numberExpected << ":" << numberOfCells
186  << " , inited " << counter;
187  } else {
188  edm::LogError("HGCalGeom") << "Inconsistent # of cells: expected " << numberExpected << ":" << numberOfCells
189  << " , inited " << counter;
190  assert(counter == numberExpected);
191  }
192  }
193 
194  return geom;
195 }
196 
198  const ParmVec& params, const HepGeom::Transform3D& ht3d, const DetId& detId, HGCalGeometry* geom, int mode) {
199 #ifdef EDM_ML_DEBUG
200  for (int i = 0; i < parametersPerShape_; ++i)
201  edm::LogVerbatim("HGCalGeom") << "Parameter[" << i << "] : " << params[i];
202 #endif
203  if (mode == 1) {
204  std::vector<GlobalPoint> corners(FlatTrd::ncorner_);
205 
206  FlatTrd::createCorners(params, ht3d, corners);
207 
208  const CCGFloat* parmPtr(CaloCellGeometry::getParmPtr(params, geom->parMgr(), geom->parVecVec()));
209 
210  GlobalPoint front(0.25 * (corners[0].x() + corners[1].x() + corners[2].x() + corners[3].x()),
211  0.25 * (corners[0].y() + corners[1].y() + corners[2].y() + corners[3].y()),
212  0.25 * (corners[0].z() + corners[1].z() + corners[2].z() + corners[3].z()));
213 
214  GlobalPoint back(0.25 * (corners[4].x() + corners[5].x() + corners[6].x() + corners[7].x()),
215  0.25 * (corners[4].y() + corners[5].y() + corners[6].y() + corners[7].y()),
216  0.25 * (corners[4].z() + corners[5].z() + corners[6].z() + corners[7].z()));
217 
218  if (front.mag2() > back.mag2()) { // front should always point to the center, so swap front and back
219  std::swap(front, back);
220  std::swap_ranges(corners.begin(), corners.begin() + FlatTrd::ncornerBy2_, corners.begin() + FlatTrd::ncornerBy2_);
221  }
222  geom->newCell(front, back, corners[0], parmPtr, detId);
223  } else {
224  std::vector<GlobalPoint> corners(FlatHexagon::ncorner_);
225 
226  FlatHexagon::createCorners(params, ht3d, corners);
227 
228  const CCGFloat* parmPtr(CaloCellGeometry::getParmPtr(params, geom->parMgr(), geom->parVecVec()));
229 
230  GlobalPoint front(
232  (corners[0].x() + corners[1].x() + corners[2].x() + corners[3].x() + corners[4].x() + corners[5].x()),
234  (corners[0].y() + corners[1].y() + corners[2].y() + corners[3].y() + corners[4].y() + corners[5].y()),
236  (corners[0].z() + corners[1].z() + corners[2].z() + corners[3].z() + corners[4].z() + corners[5].z()));
237 
238  GlobalPoint back(
240  (corners[6].x() + corners[7].x() + corners[8].x() + corners[9].x() + corners[10].x() + corners[11].x()),
242  (corners[6].y() + corners[7].y() + corners[8].y() + corners[9].y() + corners[10].y() + corners[11].y()),
244  (corners[6].z() + corners[7].z() + corners[8].z() + corners[9].z() + corners[10].z() + corners[11].z()));
245 
246  if (front.mag2() > back.mag2()) { // front should always point to the center, so swap front and back
247  std::swap(front, back);
248  std::swap_ranges(
249  corners.begin(), corners.begin() + FlatHexagon::ncornerBy2_, corners.begin() + FlatHexagon::ncornerBy2_);
250  }
251  geom->newCell(front, back, corners[0], parmPtr, detId);
252  }
253 }
static constexpr unsigned int k_NumberOfShapes
Definition: HGCalGeometry.h:46
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatHexagon.cc:134
Log< level::Info, true > LogVerbatim
const int nphi
static constexpr unsigned int ncornerBy2_
Definition: FlatTrd.h:98
T w() const
int32_t waferU(const int32_t index)
HGCalGeometry * build(const HGCalTopology &)
static constexpr uint32_t k_Theta
Definition: FlatTrd.h:27
int zside(DetId const &)
static constexpr uint32_t k_Cell
Definition: FlatTrd.h:45
static constexpr uint32_t k_dY1
Definition: FlatTrd.h:31
Log< level::Error, false > LogError
T mag2() const
Definition: PV3DBase.h:63
ForwardSubdetector
assert(be >=bs)
CaloCellGeometry::CCGFloat CCGFloat
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
static constexpr unsigned int ncorner_
Definition: FlatHexagon.h:81
static constexpr unsigned int ncorner_
Definition: FlatTrd.h:97
static constexpr uint32_t k_R
Definition: FlatHexagon.h:29
static constexpr uint32_t k_r
Definition: FlatHexagon.h:28
T sqrt(T t)
Definition: SSEVec.h:23
static constexpr uint32_t k_dX1
Definition: FlatTrd.h:32
static constexpr unsigned int k_NumberOfParametersPerTrd
Definition: HGCalGeometry.h:43
static constexpr uint32_t k_dY2
Definition: FlatTrd.h:38
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
static constexpr uint32_t k_dX4
Definition: FlatTrd.h:41
static constexpr unsigned int k_NumberOfParametersPerHex
Definition: HGCalGeometry.h:44
Definition: DetId.h:17
static constexpr unsigned int ncornerBy2_
Definition: FlatHexagon.h:82
static constexpr uint32_t k_dZ
Definition: FlatHexagon.h:27
static constexpr uint32_t k_Phi
Definition: FlatTrd.h:29
Detector
Definition: DetId.h:24
static constexpr unsigned int k_NumberOfShapesTrd
Definition: HGCalGeometry.h:47
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatTrd.cc:133
static std::atomic< unsigned int > counter
int32_t waferV(const int32_t index)
static constexpr uint32_t k_dZ
Definition: FlatTrd.h:26
std::vector< float > ParmVec
static constexpr uint32_t k_Alp1
Definition: FlatTrd.h:36
std::vector< float > ParmVec
CaloCellGeometry::CCGFloat CCGFloat
static constexpr uint32_t k_dX3
Definition: FlatTrd.h:39
CLHEP::HepRotation hr
void buildGeom(const ParmVec &, const HepGeom::Transform3D &, const DetId &, HGCalGeometry *, int mode)
static constexpr uint32_t k_dX2
Definition: FlatTrd.h:34
static constexpr double oneBySix_
Definition: FlatHexagon.h:80
static constexpr uint32_t k_Alp2
Definition: FlatTrd.h:43