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