CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
calowriters.cc
Go to the documentation of this file.
15 
16 template <>
19  const typename HcalGeometry::AlignedRecord& iRecord) {
20  const auto [alignPtr, globalPtr] = getAlignGlobal(iRecord);
21 
22  TrVec tvec;
23  DimVec dvec;
24  IVec ivec;
25  IVec dins;
26 
27  const auto& pG = iRecord.get(geometryToken_);
28 
29  pG.getSummary(tvec, ivec, dvec, dins);
30 
32  //*********************************************************************************************
33 
34  const auto& hcalTopology = iRecord.get(additionalTokens_.topology);
35 
36  // We know that the numer of shapes chanes with changing depth
37  // so, this check is temporary disabled. We need to implement
38  // a way either to store or calculate the number of shapes or be able
39  // to deal with only max numer of shapes.
40  assert(dvec.size() <= hcalTopology.getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape);
41  HcalGeometry* hcalGeometry = new HcalGeometry(hcalTopology);
42  PtrType ptr(hcalGeometry);
43 
44  const unsigned int nTrParm(hcalGeometry->numberOfTransformParms());
45 
46  ptr->fillDefaultNamedParameters();
47  ptr->allocateCorners(hcalTopology.ncells() + hcalTopology.getHFSize());
48  ptr->allocatePar(hcalGeometry->numberOfShapes(), HcalGeometry::k_NumberOfParametersPerShape);
49 
50  for (unsigned int i(0); i < dins.size(); ++i) {
51  const unsigned int nPerShape(HcalGeometry::k_NumberOfParametersPerShape);
52  DimVec dims;
53  dims.reserve(nPerShape);
54 
55  const unsigned int indx(ivec.size() == 1 ? 0 : i);
56 
57  DimVec::const_iterator dsrc(dvec.begin() + ivec[indx] * nPerShape);
58 
59  for (unsigned int j(0); j != nPerShape; ++j) {
60  dims.push_back(*dsrc);
61  ++dsrc;
62  }
63 
64  const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
65 
66  const DetId id(hcalTopology.denseId2detId(dins[i]));
67 
68  const unsigned int iGlob(nullptr == globalPtr ? 0 : HcalGeometry::alignmentTransformIndexGlobal(id));
69 
70  assert(nullptr == globalPtr || iGlob < globalPtr->m_align.size());
71 
72  const AlignTransform* gt(nullptr == globalPtr ? nullptr : &globalPtr->m_align[iGlob]);
73 
74  assert(nullptr == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal(DetId(gt->rawId())));
75 
76  const unsigned int iLoc(nullptr == alignPtr ? 0 : HcalGeometry::alignmentTransformIndexLocal(id));
77 
78  assert(nullptr == alignPtr || iLoc < alignPtr->m_align.size());
79 
80  const AlignTransform* at(nullptr == alignPtr ? nullptr : &alignPtr->m_align[iLoc]);
81 
82  assert(nullptr == at || (HcalGeometry::alignmentTransformIndexLocal(DetId(at->rawId())) == iLoc));
83 
84  Pt3D lRef;
85  Pt3DVec lc(8, Pt3D(0, 0, 0));
86  hcalGeometry->localCorners(lc, &dims.front(), dins[i], lRef);
87 
88  const Pt3D lBck(0.25 * (lc[4] + lc[5] + lc[6] + lc[7])); // ctr rear face in local
89  const Pt3D lCor(lc[0]);
90 
91  //----------------------------------- create transform from 6 numbers ---
92  const unsigned int jj(i * nTrParm);
93 
94  Tr3D tr;
95  const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
96  const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
98  const ROOT::Math::Transform3D rt(ea, tl);
99  double xx, xy, xz, dx;
100  double yx, yy, yz, dy;
101  double zx, zy, zz, dz;
102  rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
103  tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
104 
105  // now prepend alignment(s) for final transform
106  const Tr3D atr(nullptr == at ? tr
107  : (nullptr == gt ? at->transform() * tr : at->transform() * gt->transform() * tr));
108  //--------------------------------- done making transform ---------------
109 
110  const Pt3D gRef(atr * lRef);
111  const GlobalPoint fCtr(gRef.x(), gRef.y(), gRef.z());
112  const Pt3D gBck(atr * lBck);
113  const GlobalPoint fBck(gBck.x(), gBck.y(), gBck.z());
114  const Pt3D gCor(atr * lCor);
115  const GlobalPoint fCor(gCor.x(), gCor.y(), gCor.z());
116 
117  assert(hcalTopology.detId2denseId(id) == dins[i]);
118  ptr->newCell(fCtr, fBck, fCor, myParm, id);
119  }
120 
121  ptr->initializeParms(); // initializations; must happen after cells filled
122 
123  return ptr;
124 }
125 
126 template <>
129  const typename CaloTowerGeometry::AlignedRecord& iRecord) {
130  const auto [alignPtr, globalPtr] = getAlignGlobal(iRecord);
131 
132  TrVec tvec;
133  DimVec dvec;
134  IVec ivec;
135  IVec dins;
136 
137  const auto& pG = iRecord.get(geometryToken_);
138 
139  pG.getSummary(tvec, ivec, dvec, dins);
140 
142  //*********************************************************************************************
143 
144  const auto& caloTopology = iRecord.get(additionalTokens_.topology);
145 
146  CaloTowerGeometry* ctg = new CaloTowerGeometry(&caloTopology);
147 
148  const unsigned int nTrParm(tvec.size() / ctg->numberOfCellsForCorners());
149 
151 
152  PtrType ptr(ctg);
153 
154  ptr->fillDefaultNamedParameters();
155 
156  ptr->allocateCorners(ctg->numberOfCellsForCorners());
157 
158  ptr->allocatePar(dvec.size(), CaloTowerGeometry::k_NumberOfParametersPerShape);
159 
160  for (unsigned int i(0); i < dins.size(); ++i) {
161  const unsigned int nPerShape(ctg->numberOfParametersPerShape());
162  DimVec dims;
163  dims.reserve(nPerShape);
164 
165  const unsigned int indx(ivec.size() == 1 ? 0 : i);
166 
167  DimVec::const_iterator dsrc(dvec.begin() + ivec[indx] * nPerShape);
168 
169  for (unsigned int j(0); j != nPerShape; ++j) {
170  dims.push_back(*dsrc);
171  ++dsrc;
172  }
173 
174  const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
175 
176  const DetId id(caloTopology.detIdFromDenseIndex(dins[i]));
177 
178  const unsigned int iGlob(nullptr == globalPtr ? 0 : ctg->alignmentTransformIndexGlobal(id));
179 
180  assert(nullptr == globalPtr || iGlob < globalPtr->m_align.size());
181 
182  const AlignTransform* gt(nullptr == globalPtr ? nullptr : &globalPtr->m_align[iGlob]);
183 
184  assert(nullptr == gt || iGlob == ctg->alignmentTransformIndexGlobal(DetId(gt->rawId())));
185 
186  const unsigned int iLoc(nullptr == alignPtr ? 0 : ctg->alignmentTransformIndexLocal(id));
187 
188  assert(nullptr == alignPtr || iLoc < alignPtr->m_align.size());
189 
190  const AlignTransform* at(nullptr == alignPtr ? nullptr : &alignPtr->m_align[iLoc]);
191 
192  assert(nullptr == at || (ctg->alignmentTransformIndexLocal(DetId(at->rawId())) == iLoc));
193 
194  const CaloGenericDetId gId(id);
195 
196  Pt3D lRef;
197  Pt3DVec lc(8, Pt3D(0, 0, 0));
198  ctg->localCorners(lc, &dims.front(), dins[i], lRef);
199 
200  const Pt3D lBck(0.25 * (lc[4] + lc[5] + lc[6] + lc[7])); // ctr rear face in local
201  const Pt3D lCor(lc[0]);
202 
203  //----------------------------------- create transform from 6 numbers ---
204  const unsigned int jj(i * nTrParm);
205  Tr3D tr;
206  const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
207  const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
209  const ROOT::Math::Transform3D rt(ea, tl);
210  double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
211  rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
212  tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
213 
214  // now prepend alignment(s) for final transform
215  const Tr3D atr(nullptr == at ? tr
216  : (nullptr == gt ? at->transform() * tr : at->transform() * gt->transform() * tr));
217  //--------------------------------- done making transform ---------------
218 
219  const Pt3D gRef(atr * lRef);
220  const GlobalPoint fCtr(gRef.x(), gRef.y(), gRef.z());
221  const Pt3D gBck(atr * lBck);
222  const GlobalPoint fBck(gBck.x(), gBck.y(), gBck.z());
223  const Pt3D gCor(atr * lCor);
224  const GlobalPoint fCor(gCor.x(), gCor.y(), gCor.z());
225 
226  assert(caloTopology.denseIndex(id) == dins[i]);
227 
228  ptr->newCell(fCtr, fBck, fCor, myParm, id);
229  }
230 
231  ptr->initializeParms(); // initializations; must happen after cells filled
232 
233  return ptr;
234 }
235 
236 template <>
239  const typename HGCalGeometry::AlignedRecord& iRecord) {
240  TrVec tvec; // transformation
241  DimVec dvec; // parameters
242  IVec ivec; // layers
243  IVec dins; // valid geom ids
244 
245  const auto& geom = iRecord.get(geometryToken_);
246 
247  geom.getSummary(tvec, ivec, dvec, dins);
248 
250  //*********************************************************************************************
251 
252  const auto& topology = iRecord.get(additionalTokens_.topology);
253 
254  assert(dvec.size() <= topology.totalGeomModules() * HGCalGeometry::k_NumberOfParametersPerShape);
255  HGCalGeometry* hcg = new HGCalGeometry(topology);
256  PtrType ptr(hcg);
257 
258  ptr->allocateCorners(topology.ncells());
260 
261  const unsigned int nTrParm(ptr->numberOfTransformParms());
262  const unsigned int nPerShape(HGCalGeometry::k_NumberOfParametersPerShape);
263 
264  for (auto it : dins) {
265  DetId id = topology.encode(topology.geomDenseId2decId(it));
266  // get layer
267  int layer = ivec[it];
268 
269  // get transformation
270  const unsigned int jj(it * nTrParm);
271  Tr3D tr;
272  const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
273  const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
275  const ROOT::Math::Transform3D rt(ea, tl);
276  double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
277  rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
278  tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
279 
280  // get parameters
281  DimVec dims;
282  dims.reserve(nPerShape);
283 
284  DimVec::const_iterator dsrc(dvec.begin() + layer * nPerShape);
285  for (unsigned int j(0); j != nPerShape; ++j) {
286  dims.push_back(*dsrc);
287  ++dsrc;
288  }
289 
290  std::vector<GlobalPoint> corners(FlatHexagon::ncorner_);
291 
292  FlatHexagon::createCorners(dims, tr, corners);
293 
294  const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
295  GlobalPoint front(
297  (corners[0].x() + corners[1].x() + corners[2].x() + corners[3].x() + corners[4].x() + corners[5].x()),
299  (corners[0].y() + corners[1].y() + corners[2].y() + corners[3].y() + corners[4].y() + corners[5].y()),
301  (corners[0].z() + corners[1].z() + corners[2].z() + corners[3].z() + corners[4].z() + corners[5].z()));
302 
303  GlobalPoint back(
305  (corners[6].x() + corners[7].x() + corners[8].x() + corners[9].x() + corners[10].x() + corners[11].x()),
307  (corners[6].y() + corners[7].y() + corners[8].y() + corners[9].y() + corners[10].y() + corners[11].y()),
309  (corners[6].z() + corners[7].z() + corners[8].z() + corners[9].z() + corners[10].z() + corners[11].z()));
310 
311  if (front.mag2() > back.mag2()) { // front should always point to the center, so swap front and back
312  std::swap(front, back);
313  std::swap_ranges(
314  corners.begin(), corners.begin() + FlatHexagon::ncornerBy2_, corners.begin() + FlatHexagon::ncornerBy2_);
315  }
316 
317  ptr->newCell(front, back, corners[0], myParm, id);
318  }
319 
320  ptr->initializeParms(); // initializations; must happen after cells filled
321 
322  return ptr;
323 }
324 
328 
333 
335 
337 
339 
341 
343 
345 
347 
349 
351 
353 
355 
357 
359 
361 
363 
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
CaloCellGeometry::Pt3D Pt3D
CaloGeometryDBEP< HcalGeometry, CaloGeometryDBWriter > HcalGeometryToDBEP
Definition: calowriters.cc:346
static unsigned int alignmentTransformIndexLocal(const DetId &id)
T mag2() const
Definition: PV3DBase.h:63
static void writeIndexed(const TrVec &tvec, const DimVec &dvec, const IVec &ivec, const IVec &dins, const std::string &tag)
uint16_t *__restrict__ id
unsigned int numberOfShapes() const override
virtual unsigned int numberOfCellsForCorners() const
CaloGeometryDBEP< CastorGeometry, CaloGeometryDBWriter > CastorGeometryToDBEP
Definition: calowriters.cc:358
std::unique_ptr< CaloSubdetectorGeometry > PtrType
unsigned int numberOfParametersPerShape() const override
CaloCellGeometry::Pt3DVec Pt3DVec
unsigned int alignmentTransformIndexLocal(const DetId &id)
assert(be >=bs)
list rt
Definition: hcal_runs.py:76
float float float z
static constexpr unsigned int ncorner_
Definition: FlatHexagon.h:81
constexpr std::array< uint8_t, layerIndexSize > layer
CaloGeometryDBEP< EcalEndcapGeometry, CaloGeometryDBWriter > EcalEndcapGeometryToDBEP
Definition: calowriters.cc:338
CaloSubdetectorGeometry::IVec IVec
ProductT const & get(ESGetToken< ProductT, DepRecordT > const &iToken) const
static constexpr unsigned int k_NumberOfParametersPerShape
Definition: HGCalGeometry.h:45
CaloGeometryDBEP< CaloTowerGeometry, CaloGeometryDBWriter > CaloTowerGeometryToDBEP
Definition: calowriters.cc:350
CaloGeometryDBEP< ZdcGeometry, CaloGeometryDBWriter > ZdcGeometryToDBEP
Definition: calowriters.cc:354
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
static std::string dbString()
Definition: HGCalGeometry.h:49
static std::string dbString()
static unsigned int alignmentTransformIndexGlobal(const DetId &id)
uint16_t const *__restrict__ x
Definition: gpuClustering.h:39
PtrType produceAligned(const typename T::AlignedRecord &iRecord)
CaloSubdetectorGeometry::TrVec TrVec
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
CaloGeometryDBEP< EcalPreshowerGeometry, CaloGeometryDBWriter > EcalPreshowerGeometryToDBEP
Definition: calowriters.cc:342
unsigned int alignmentTransformIndexGlobal(const DetId &id)
CaloCellGeometry::Pt3D Pt3D
static void localCorners(Pt3DVec &lc, const CCGFloat *pv, unsigned int i, Pt3D &ref)
Basic2DVector< T > xy() const
Definition: DetId.h:17
static constexpr unsigned int ncornerBy2_
Definition: FlatHexagon.h:82
AlgebraicVector EulerAngles
Definition: Definitions.h:34
CaloGeometryDBEP< HGCalGeometry, CaloGeometryDBWriter > HGCalGeometryToDBEP
Definition: calowriters.cc:362
static std::string dbString()
Definition: HcalGeometry.h:40
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
CaloCellGeometry::Tr3D Tr3D
CaloCellGeometry::Tr3D Tr3D
CaloSubdetectorGeometry::DimVec DimVec
CaloGeometryDBEP< EcalBarrelGeometry, CaloGeometryDBWriter > EcalBarrelGeometryToDBEP
Definition: calowriters.cc:334
CaloCellGeometry::CCGFloat CCGFloat
static constexpr double oneBySix_
Definition: FlatHexagon.h:80