CMS 3D CMS Logo

HGCalTBGeometryLoader.cc
Go to the documentation of this file.
9 
10 //#define EDM_ML_DEBUG
11 
13 typedef std::vector<float> ParmVec;
14 
15 HGCalTBGeometryLoader::HGCalTBGeometryLoader() : twoBysqrt3_(2.0 / std::sqrt(3.0)) {}
16 
18  // allocate geometry
20  unsigned int numberOfCells = topology.totalGeomModules(); // both sides
21  unsigned int numberExpected = topology.allGeomModules();
23  uint32_t numberOfShapes = HGCalTBGeometry::k_NumberOfShapes;
24 #ifdef EDM_ML_DEBUG
25  edm::LogVerbatim("HGCalGeom") << "Number of Cells " << numberOfCells << ":" << numberExpected << " for sub-detector "
26  << topology.subDetector() << " Shapes " << numberOfShapes << ":" << parametersPerShape_;
27 #endif
28  geom->allocateCorners(numberOfCells);
29  geom->allocatePar(numberOfShapes, parametersPerShape_);
30 
31  // loop over modules
33  unsigned int counter(0);
34 #ifdef EDM_ML_DEBUG
35  edm::LogVerbatim("HGCalGeom") << "HGCalTBGeometryLoader with # of "
36  << "transformation matrices " << topology.dddConstants().getTrFormN() << " and "
37  << topology.dddConstants().volumes() << ":" << topology.dddConstants().sectors()
38  << " volumes";
39 #endif
40  for (unsigned itr = 0; itr < topology.dddConstants().getTrFormN(); ++itr) {
41  HGCalTBParameters::hgtrform mytr = topology.dddConstants().getTrForm(itr);
42  int zside = mytr.zp;
43  int layer = mytr.lay;
44 #ifdef EDM_ML_DEBUG
45  unsigned int kount(0);
46  edm::LogVerbatim("HGCalGeom") << "HGCalTBGeometryLoader:: Z:Layer " << zside << ":" << layer << " z "
47  << mytr.h3v.z();
48 #endif
49  ForwardSubdetector subdet = topology.subDetector();
50  for (int wafer = 0; wafer < topology.dddConstants().sectors(); ++wafer) {
51  std::string code[2] = {"False", "True"};
52  if (topology.dddConstants().waferInLayer(wafer, layer, true)) {
53  int type = topology.dddConstants().waferTypeT(wafer);
54  if (type != 1)
55  type = 0;
56  DetId detId = static_cast<DetId>(HGCalDetId(subdet, zside, layer, type, wafer, 0));
57  const auto& w = topology.dddConstants().waferPosition(wafer, true);
58  double xx = (zside > 0) ? w.first : -w.first;
59  CLHEP::Hep3Vector h3v(xx, w.second, mytr.h3v.z());
60  const HepGeom::Transform3D ht3d(mytr.hr, h3v);
61 #ifdef EDM_ML_DEBUG
62  edm::LogVerbatim("HGCalGeom") << "HGCalTBGeometryLoader:: Wafer:Type " << wafer << ":" << type << " DetId "
63  << HGCalDetId(detId) << std::hex << " " << detId.rawId() << std::dec << " transf "
64  << ht3d.getTranslation() << " and " << ht3d.getRotation();
65 #endif
66  HGCalTBParameters::hgtrap vol = topology.dddConstants().getModule(wafer, true, true);
68  params[FlatHexagon::k_r] = topology.dddConstants().cellSizeHex(type);
70 
71  buildGeom(params, ht3d, detId, geom);
72  counter++;
73 #ifdef EDM_ML_DEBUG
74  ++kount;
75 #endif
76  }
77  }
78 #ifdef EDM_ML_DEBUG
79  edm::LogVerbatim("HGCalGeom") << kount << " modules found in Layer " << layer << " Z " << zside;
80 #endif
81  }
82 
83  geom->sortDetIds();
84 
85  if (counter != numberExpected) {
86  edm::LogError("HGCalGeom") << "Inconsistent # of cells: expected " << numberExpected << ":" << numberOfCells
87  << " , inited " << counter;
88  }
89 
90  return geom;
91 }
92 
94  const HepGeom::Transform3D& ht3d,
95  const DetId& detId,
97 #ifdef EDM_ML_DEBUG
98  for (int i = 0; i < parametersPerShape_; ++i)
99  edm::LogVerbatim("HGCalGeom") << "Parameter[" << i << "] : " << params[i];
100 #endif
101  std::vector<GlobalPoint> corners(FlatHexagon::ncorner_);
102 
103  FlatHexagon::createCorners(params, ht3d, corners);
104 
105  const CCGFloat* parmPtr(CaloCellGeometry::getParmPtr(params, geom->parMgr(), geom->parVecVec()));
106 
107  GlobalPoint front(
109  (corners[0].x() + corners[1].x() + corners[2].x() + corners[3].x() + corners[4].x() + corners[5].x()),
111  (corners[0].y() + corners[1].y() + corners[2].y() + corners[3].y() + corners[4].y() + corners[5].y()),
113  (corners[0].z() + corners[1].z() + corners[2].z() + corners[3].z() + corners[4].z() + corners[5].z()));
114 
115  GlobalPoint back(
117  (corners[6].x() + corners[7].x() + corners[8].x() + corners[9].x() + corners[10].x() + corners[11].x()),
119  (corners[6].y() + corners[7].y() + corners[8].y() + corners[9].y() + corners[10].y() + corners[11].y()),
121  (corners[6].z() + corners[7].z() + corners[8].z() + corners[9].z() + corners[10].z() + corners[11].z()));
122 
123  if (front.mag2() > back.mag2()) { // front should always point to the center, so swap front and back
124  std::swap(front, back);
125  std::swap_ranges(
126  corners.begin(), corners.begin() + FlatHexagon::ncornerBy2_, corners.begin() + FlatHexagon::ncornerBy2_);
127  }
128  geom->newCell(front, back, corners[0], parmPtr, detId);
129 }
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatHexagon.cc:134
Log< level::Info, true > LogVerbatim
static constexpr unsigned int k_NumberOfParametersPerHex
HGCalTBGeometry * build(const HGCalTBTopology &)
T w() const
int zside(DetId const &)
Log< level::Error, false > LogError
T mag2() const
Definition: PV3DBase.h:63
ForwardSubdetector
void swap(Association< C > &lhs, Association< C > &rhs)
Definition: Association.h:112
static constexpr unsigned int ncorner_
Definition: FlatHexagon.h:81
void buildGeom(const ParmVec &, const HepGeom::Transform3D &, const DetId &, HGCalTBGeometry *)
std::vector< float > ParmVec
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
std::vector< float > ParmVec
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
CaloCellGeometry::CCGFloat CCGFloat
Definition: DetId.h:17
static constexpr unsigned int ncornerBy2_
Definition: FlatHexagon.h:82
static constexpr uint32_t k_dZ
Definition: FlatHexagon.h:27
static std::atomic< unsigned int > counter
static constexpr unsigned int k_NumberOfShapes
static constexpr double oneBySix_
Definition: FlatHexagon.h:80
CaloCellGeometry::CCGFloat CCGFloat