CMS 3D CMS Logo

HGCalGeometryLoader.cc
Go to the documentation of this file.
12 
13 //#define EDM_ML_DEBUG
14 
16 typedef std::vector<float> ParmVec;
17 
18 HGCalGeometryLoader::HGCalGeometryLoader () : twoBysqrt3_(2.0/std::sqrt(3.0)) {
19 }
20 
22 
24 
25  // allocate geometry
26  HGCalGeometry* geom = new HGCalGeometry (topology);
27  unsigned int numberOfCells = topology.totalGeomModules(); // both sides
28  unsigned int numberExpected= topology.allGeomModules();
33  uint32_t numberOfShapes = ((mode == HGCalGeometryMode::Trapezoid) ?
36 #ifdef EDM_ML_DEBUG
37  edm::LogVerbatim("HGCalGeom") << "Number of Cells " << numberOfCells << ":"
38  << numberExpected << " for sub-detector "
39  << topology.subDetector() << " Shapes "
40  << numberOfShapes << ":" << parametersPerShape_
41  << " mode " << mode;
42 #endif
43  geom->allocateCorners( numberOfCells ) ;
44  geom->allocatePar(numberOfShapes, parametersPerShape_);
45 
46  // loop over modules
47  ParmVec params(parametersPerShape_,0);
48  unsigned int counter(0);
49 #ifdef EDM_ML_DEBUG
50  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader with # of "
51  << "transformation matrices "
52  << topology.dddConstants().getTrFormN()
53  << " and " << topology.dddConstants().volumes()
54  << ":" << topology.dddConstants().sectors()
55  << " volumes";
56 #endif
57  for (unsigned itr=0; itr<topology.dddConstants().getTrFormN(); ++itr) {
58  HGCalParameters::hgtrform mytr = topology.dddConstants().getTrForm(itr);
59  int zside = mytr.zp;
60  int layer = mytr.lay;
61 #ifdef EDM_ML_DEBUG
62  unsigned int kount(0);
63  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader:: Z:Layer " << zside
64  << ":" << layer << " z " << mytr.h3v.z();
65 #endif
66  if ((mode == HGCalGeometryMode::Hexagon) ||
68  ForwardSubdetector subdet = topology.subDetector();
69  for (int wafer=0; wafer<topology.dddConstants().sectors(); ++wafer) {
70  std::string code[2] = {"False", "True"};
71  if (topology.dddConstants().waferInLayer(wafer,layer,true)) {
72  int type = topology.dddConstants().waferTypeT(wafer);
73  if (type != 1) type = 0;
74  DetId detId = (DetId)(HGCalDetId(subdet,zside,layer,type,wafer,0));
75  const auto & w = topology.dddConstants().waferPosition(wafer,true);
76  double xx = (zside > 0) ? w.first : -w.first;
77  CLHEP::Hep3Vector h3v(xx,w.second,mytr.h3v.z());
78  const HepGeom::Transform3D ht3d (mytr.hr, h3v);
79 #ifdef EDM_ML_DEBUG
80  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader:: Wafer:Type "
81  << wafer << ":" << type << " DetId "
82  << HGCalDetId(detId) << std::hex
83  << " " << detId.rawId() << std::dec
84  << " transf " << ht3d.getTranslation()
85  << " and " << ht3d.getRotation();
86 #endif
87  HGCalParameters::hgtrap vol = topology.dddConstants().getModule(wafer,true,true);
88  params[0] = vol.dz;
89  params[1] = topology.dddConstants().cellSizeHex(type);
90  params[2] = twoBysqrt3_*params[1];
91 
92  buildGeom(params, ht3d, detId, geom, 0);
93  counter++;
94 #ifdef EDM_ML_DEBUG
95  ++kount;
96 #endif
97  }
98  }
99  } else if (mode == HGCalGeometryMode::Trapezoid) {
100  int indx = topology.dddConstants().layerIndex(layer,true);
101  int ieta = topology.dddConstants().getParameter()->iEtaMinBH_[indx];
102  int nphi = topology.dddConstants().getParameter()->nPhiBinBH_[indx];
103  int type = topology.dddConstants().getTypeTrap(layer);
104  for (int md=topology.dddConstants().getParameter()->firstModule_[indx];
105  md<=topology.dddConstants().getParameter()->lastModule_[indx];++md){
106  for (int iphi=1; iphi<=nphi; ++iphi) {
107  DetId detId = (DetId)(HGCScintillatorDetId(type,layer,zside*ieta,iphi));
108  const auto & w = topology.dddConstants().locateCellTrap(layer,ieta,iphi,true);
109  double xx = (zside > 0) ? w.first : -w.first;
110  CLHEP::Hep3Vector h3v(xx,w.second,mytr.h3v.z());
111  const HepGeom::Transform3D ht3d (mytr.hr, h3v);
112 #ifdef EDM_ML_DEBUG
113  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader::eta:phi:type "
114  << ieta*zside << ":" << iphi << ":"
115  << type << " DetId "
116  << HGCScintillatorDetId(detId) << " "
117  << std::hex << detId.rawId()
118  << std::dec << " transf "
119  << ht3d.getTranslation() << " and "
120  << ht3d.getRotation();
121 #endif
122  HGCalParameters::hgtrap vol = topology.dddConstants().getModule(md,false,true);
123  params[0] = vol.dz;
124  params[1] = params[2] = 0;
125  params[3] = params[7] = vol.h;
126  params[4] = params[8] = vol.bl;
127  params[5] = params[9] = vol.tl;
128  params[6] = params[10]= 0;
129  params[11]= topology.dddConstants().cellSizeHex(type);
130 
131  buildGeom(params, ht3d, detId, geom, 1);
132  counter++;
133 #ifdef EDM_ML_DEBUG
134  ++kount;
135 #endif
136  }
137  ++ieta;
138  }
139  } else {
140  DetId::Detector det = topology.detector();
141  for (int wafer=0; wafer<topology.dddConstants().sectors(); ++wafer) {
142  if (topology.dddConstants().waferInLayer(wafer,layer,true)) {
143  int copy = topology.dddConstants().getParameter()->waferCopy_[wafer];
144  int u = HGCalWaferIndex::waferU(copy);
145  int v = HGCalWaferIndex::waferV(copy);
146  int type = topology.dddConstants().getTypeHex(layer,u,v);
147  DetId detId = (DetId)(HGCSiliconDetId(det,zside,type,layer,u,v,0,0));
148  const auto & w = topology.dddConstants().waferPosition(u,v,true);
149  double xx = (zside > 0) ? w.first : -w.first;
150  CLHEP::Hep3Vector h3v(xx,w.second,mytr.h3v.z());
151  const HepGeom::Transform3D ht3d (mytr.hr, h3v);
152 #ifdef EDM_ML_DEBUG
153  edm::LogVerbatim("HGCalGeom") << "HGCalGeometryLoader:: Wafer:Type "
154  << wafer << ":" << type << " DetId "
155  << HGCSiliconDetId(detId) << std::hex
156  << " " << detId.rawId() << std::dec
157  << " transf " << ht3d.getTranslation()
158  << " and " << ht3d.getRotation();
159 #endif
160  HGCalParameters::hgtrap vol = topology.dddConstants().getModule(type,false,true);
161  params[0] = vol.dz;
162  params[1] = topology.dddConstants().cellSizeHex(type);
163  params[2] = twoBysqrt3_*params[1];
164 
165  buildGeom(params, ht3d, detId, geom, 0);
166  counter++;
167 #ifdef EDM_ML_DEBUG
168  ++kount;
169 #endif
170  }
171  }
172  }
173 #ifdef EDM_ML_DEBUG
174  edm::LogVerbatim("HGCalGeom") << kount << " modules found in Layer "
175  << layer << " Z " << zside;
176 #endif
177  }
178 
179  geom->sortDetIds();
180 
181  if (counter != numberExpected) {
182  edm::LogError("HGCalGeom") << "Inconsistent # of cells: expected "
183  << numberExpected << ":" << numberOfCells
184  << " , inited " << counter;
185  assert( counter == numberExpected ) ;
186  }
187 
188  return geom;
189 }
190 
192  const HepGeom::Transform3D& ht3d,
193  const DetId& detId, HGCalGeometry* geom,
194  int mode) {
195 
196 #ifdef EDM_ML_DEBUG
197  for (int i=0; i<parametersPerShape_; ++i)
198  edm::LogVerbatim("HGCalGeom") << "Parameter[" << i << "] : " << params[i];
199 #endif
200  if (mode == 1) {
201  std::vector<GlobalPoint> corners (FlatTrd::ncorner_);
202 
203  FlatTrd::createCorners( params, ht3d, corners ) ;
204 
205  const CCGFloat* parmPtr (CaloCellGeometry::getParmPtr(params,
206  geom->parMgr(),
207  geom->parVecVec()));
208 
209  GlobalPoint front ( 0.25 * ( corners[0].x() +
210  corners[1].x() +
211  corners[2].x() +
212  corners[3].x() ),
213  0.25 * ( corners[0].y() +
214  corners[1].y() +
215  corners[2].y() +
216  corners[3].y() ),
217  0.25 * ( corners[0].z() +
218  corners[1].z() +
219  corners[2].z() +
220  corners[3].z() ) ) ;
221 
222  GlobalPoint back ( 0.25 * ( corners[4].x() +
223  corners[5].x() +
224  corners[6].x() +
225  corners[7].x() ),
226  0.25 * ( corners[4].y() +
227  corners[5].y() +
228  corners[6].y() +
229  corners[7].y() ),
230  0.25 * ( corners[4].z() +
231  corners[5].z() +
232  corners[6].z() +
233  corners[7].z() ) ) ;
234 
235  if (front.mag2() > back.mag2()) { // front should always point to the center, so swap front and back
236  std::swap (front, back);
237  std::swap_ranges (corners.begin(),corners.begin()+FlatTrd::ncornerBy2_,
238  corners.begin()+FlatTrd::ncornerBy2_);
239  }
240  geom->newCell(front, back, corners[0], parmPtr, detId) ;
241  } else {
242  std::vector<GlobalPoint> corners (FlatHexagon::ncorner_);
243 
244  FlatHexagon::createCorners( params, ht3d, corners ) ;
245 
246  const CCGFloat* parmPtr (CaloCellGeometry::getParmPtr(params,
247  geom->parMgr(),
248  geom->parVecVec()));
249 
250  GlobalPoint front ( FlatHexagon::oneBySix_*( corners[0].x() +
251  corners[1].x() +
252  corners[2].x() +
253  corners[3].x() +
254  corners[4].x() +
255  corners[5].x() ),
256  FlatHexagon::oneBySix_*( corners[0].y() +
257  corners[1].y() +
258  corners[2].y() +
259  corners[3].y() +
260  corners[4].y() +
261  corners[5].y() ),
262  FlatHexagon::oneBySix_*( corners[0].z() +
263  corners[1].z() +
264  corners[2].z() +
265  corners[3].z() +
266  corners[4].z() +
267  corners[5].z() ) ) ;
268 
269  GlobalPoint back ( FlatHexagon::oneBySix_*( corners[6].x() +
270  corners[7].x() +
271  corners[8].x() +
272  corners[9].x() +
273  corners[10].x()+
274  corners[11].x() ),
275  FlatHexagon::oneBySix_*( corners[6].y() +
276  corners[7].y() +
277  corners[8].y() +
278  corners[9].y() +
279  corners[10].y()+
280  corners[11].y() ),
281  FlatHexagon::oneBySix_*( corners[6].z() +
282  corners[7].z() +
283  corners[8].z() +
284  corners[9].z() +
285  corners[10].z()+
286  corners[11].z() ) ) ;
287 
288  if (front.mag2() > back.mag2()) { // front should always point to the center, so swap front and back
289  std::swap (front, back);
290  std::swap_ranges (corners.begin(),corners.begin()+FlatHexagon::ncornerBy2_,
291  corners.begin()+FlatHexagon::ncornerBy2_);
292  }
293  geom->newCell(front, back, corners[0], parmPtr, detId) ;
294  }
295 }
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatHexagon.cc:152
HGCalGeometryMode::GeometryMode geomMode() const
Geometry mode.
Definition: HGCalTopology.h:86
type
Definition: HCALResponse.h:21
std::vector< int > iEtaMinBH_
T mag2() const
Definition: PV3DBase.h:66
int getTypeTrap(int layer) const
static constexpr unsigned int ncornerBy2_
Definition: FlatTrd.h:77
unsigned int allGeomModules() const
const double w
Definition: UKUtility.cc:23
def copy(args, dbName)
CaloTopology const * topology(0)
double cellSizeHex(int type) const
HGCalParameters::hgtrform getTrForm(unsigned int k) const
static int32_t waferV(const int32_t index)
const HGCalParameters * getParameter() const
HGCalGeometry * build(const HGCalTopology &)
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
int getTypeHex(int layer, int waferU, int waferV) const
void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId) override
int zside(DetId const &)
ForwardSubdetector
void allocatePar(ParVec::size_type n, unsigned int m)
CaloCellGeometry::CCGFloat CCGFloat
int layerIndex(int lay, bool reco) const
std::vector< int > nPhiBinBH_
static constexpr unsigned int ncorner_
Definition: FlatHexagon.h:78
unsigned int totalGeomModules() const
Definition: HGCalTopology.h:98
static constexpr unsigned int ncorner_
Definition: FlatTrd.h:76
std::vector< int > firstModule_
static unsigned int k_NumberOfShapes
Definition: HGCalGeometry.h:46
unsigned int getTrFormN() const
static unsigned int k_NumberOfParametersPerHex
Definition: HGCalGeometry.h:44
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
T sqrt(T t)
Definition: SSEVec.h:18
std::pair< float, float > locateCellTrap(int lay, int ieta, int iphi, bool reco) const
static unsigned int k_NumberOfShapesTrd
Definition: HGCalGeometry.h:47
static int32_t waferU(const int32_t index)
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
int sectors() const
static unsigned int k_NumberOfParametersPerTrd
Definition: HGCalGeometry.h:43
Definition: DetId.h:18
static constexpr unsigned int ncornerBy2_
Definition: FlatHexagon.h:79
std::vector< int > lastModule_
const HGCalDDDConstants & dddConstants() const
Detector
Definition: DetId.h:26
ForwardSubdetector subDetector() const
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatTrd.cc:152
static std::atomic< unsigned int > counter
std::vector< int > waferCopy_
std::pair< double, double > waferPosition(int wafer, bool reco) const
void allocateCorners(CaloCellGeometry::CornersVec::size_type n)
std::vector< float > ParmVec
std::vector< float > ParmVec
CaloCellGeometry::CCGFloat CCGFloat
DetId::Detector detector() const
HGCalParameters::hgtrap getModule(unsigned int k, bool hexType, bool reco) const
CLHEP::HepRotation hr
void buildGeom(const ParmVec &, const HepGeom::Transform3D &, const DetId &, HGCalGeometry *, int mode)
int waferTypeT(int wafer) const
static constexpr double oneBySix_
Definition: FlatHexagon.h:77
bool waferInLayer(int wafer, int lay, bool reco) const
unsigned int volumes() const