CMS 3D CMS Logo

CaloGeometryDBEP.h
Go to the documentation of this file.
1 #ifndef GEOMETRY_CALOGEOMETRY_CALOGEOMETRYDBEP_H
2 #define GEOMETRY_CALOGEOMETRY_CALOGEOMETRYDBEP_H 1
3 
4 // system include files
5 #include <memory>
6 
7 // user include files
11 
19 
21 
23 
24 #include <Math/Transform3D.h>
25 #include <Math/EulerAngles.h>
26 
27 //Forward declaration
28 
29 //
30 // class declaration
31 //
32 
34  // For U::writeFlag() == true
35  template <typename T, bool>
36  struct GeometryTraits {
38 
40  return cc.template consumes<CaloSubdetectorGeometry>(
41  edm::ESInputTag{"", T::producerTag() + std::string("_master")});
42  }
43  };
44 
45  template <typename T>
46  struct GeometryTraits<T, false> {
48 
50  return cc.template consumesFrom<PCaloGeometry, typename T::PGeometryRecord>(edm::ESInputTag{});
51  }
52  };
53 
54  // For the case of non-existent AlignmentRecord
55  //
56  // SFINAE tricks to detect if T::AlignmentRecord exists. Note that
57  // the declarations of the following are sufficient.
58  template <typename T>
59  std::false_type has_AlignmentRecord(...);
60  template <typename T>
61  std::true_type has_AlignmentRecord(typename T::AlignmentRecord*);
62 
63  template <typename T>
65  static constexpr bool value = std::is_same<decltype(has_AlignmentRecord<T>(nullptr)), std::true_type>::value;
66  };
67 
68  // Then define tokens from alignment record
70  struct AlignmentTokens {
73  };
74  template <typename T>
75  struct AlignmentTokens<T, false> {};
76 
77  // Some partial specializations need additional tokens...
78  template <typename T>
81  };
82 } // namespace calogeometryDBEPimpl
83 
84 template <class T, class U>
86 public:
91 
92  using PtrType = std::unique_ptr<CaloSubdetectorGeometry>;
96 
97  CaloGeometryDBEP<T, U>(const edm::ParameterSet& ps) : applyAlignment_(ps.getParameter<bool>("applyAlignment")) {
98  auto cc = setWhatProduced(this,
100  edm::es::Label(T::producerTag())); //+std::string("TEST") ) ) ;
101 
103  if (applyAlignment_) {
105  cc.template consumesFrom<Alignments, typename T::AlignmentRecord>(edm::ESInputTag{});
106  alignmentTokens_.globals = cc.template consumesFrom<Alignments, GlobalPositionRcd>(edm::ESInputTag{});
107  }
108  }
110 
111  additionalTokens_.makeTokens(cc);
112  }
113 
114  ~CaloGeometryDBEP<T, U>() override {}
115 
116  PtrType produceAligned(const typename T::AlignedRecord& iRecord) {
117  const auto [alignPtr, globalPtr] = getAlignGlobal(iRecord);
118 
119  TrVec tvec;
120  DimVec dvec;
121  IVec ivec;
122  std::vector<uint32_t> dins;
123 
124  if constexpr (U::writeFlag()) {
125  const auto& pG = iRecord.get(geometryToken_);
126 
127  pG.getSummary(tvec, ivec, dvec, dins);
128 
129  U::write(tvec, dvec, ivec, T::dbString());
130  } else {
131  const auto& pG = iRecord.get(geometryToken_);
132 
133  tvec = pG.getTranslation();
134  dvec = pG.getDimension();
135  ivec = pG.getIndexes();
136  }
137  //*********************************************************************************************
138 
139  const unsigned int nTrParm(tvec.size() / T::k_NumberOfCellsForCorners);
140 
141  assert(dvec.size() == T::k_NumberOfShapes * T::k_NumberOfParametersPerShape);
142 
143  PtrType ptr = std::make_unique<T>();
144 
145  ptr->fillDefaultNamedParameters();
146 
147  ptr->allocateCorners(T::k_NumberOfCellsForCorners);
148 
149  ptr->allocatePar(dvec.size(), T::k_NumberOfParametersPerShape);
150 
151  for (unsigned int i(0); i != T::k_NumberOfCellsForCorners; ++i) {
152  const unsigned int nPerShape(T::k_NumberOfParametersPerShape);
153  DimVec dims;
154  dims.reserve(nPerShape);
155 
156  const unsigned int indx(ivec.size() == 1 ? 0 : i);
157 
158  DimVec::const_iterator dsrc(dvec.begin() + ivec[indx] * nPerShape);
159 
160  for (unsigned int j(0); j != nPerShape; ++j) {
161  dims.emplace_back(*dsrc);
162  ++dsrc;
163  }
164 
165  const CCGFloat* myParm(CaloCellGeometry::getParmPtr(dims, ptr->parMgr(), ptr->parVecVec()));
166 
167  const DetId id(T::DetIdType::detIdFromDenseIndex(i));
168 
169  const unsigned int iGlob(nullptr == globalPtr ? 0 : T::alignmentTransformIndexGlobal(id));
170 
171  assert(nullptr == globalPtr || iGlob < globalPtr->m_align.size());
172 
173  const AlignTransform* gt(nullptr == globalPtr ? nullptr : &globalPtr->m_align[iGlob]);
174 
175  assert(nullptr == gt || iGlob == T::alignmentTransformIndexGlobal(DetId(gt->rawId())));
176 
177  const unsigned int iLoc(nullptr == alignPtr ? 0 : T::alignmentTransformIndexLocal(id));
178 
179  assert(nullptr == alignPtr || iLoc < alignPtr->m_align.size());
180 
181  const AlignTransform* at(nullptr == alignPtr ? nullptr : &alignPtr->m_align[iLoc]);
182 
183  assert(nullptr == at || (T::alignmentTransformIndexLocal(DetId(at->rawId())) == iLoc));
184 
185  const CaloGenericDetId gId(id);
186 
187  Pt3D lRef;
188  Pt3DVec lc(8, Pt3D(0, 0, 0));
189  T::localCorners(lc, &dims.front(), i, lRef);
190 
191  const Pt3D lBck(0.25 * (lc[4] + lc[5] + lc[6] + lc[7])); // ctr rear face in local
192  const Pt3D lCor(lc[0]);
193 
194  //----------------------------------- create transform from 6 numbers ---
195  const unsigned int jj(i * nTrParm);
196  Tr3D tr;
197  const ROOT::Math::Translation3D tl(tvec[jj], tvec[jj + 1], tvec[jj + 2]);
198  const ROOT::Math::EulerAngles ea(6 == nTrParm ? ROOT::Math::EulerAngles(tvec[jj + 3], tvec[jj + 4], tvec[jj + 5])
200  const ROOT::Math::Transform3D rt(ea, tl);
201  double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
202  rt.GetComponents(xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz);
203  tr = Tr3D(CLHEP::HepRep3x3(xx, xy, xz, yx, yy, yz, zx, zy, zz), CLHEP::Hep3Vector(dx, dy, dz));
204 
205  // now prepend alignment(s) for final transform
206  const Tr3D atr(nullptr == at ? tr
207  : (nullptr == gt ? at->transform() * tr : at->transform() * gt->transform() * tr));
208  //--------------------------------- done making transform ---------------
209 
210  const Pt3D gRef(atr * lRef);
211  const GlobalPoint fCtr(gRef.x(), gRef.y(), gRef.z());
212  const Pt3D gBck(atr * lBck);
213  const GlobalPoint fBck(gBck.x(), gBck.y(), gBck.z());
214  const Pt3D gCor(atr * lCor);
215  const GlobalPoint fCor(gCor.x(), gCor.y(), gCor.z());
216 
217  ptr->newCell(fCtr, fBck, fCor, myParm, id);
218  }
219 
220  ptr->initializeParms(); // initializations; must happen after cells filled
221 
222  return ptr;
223  }
224 
225 private:
226  std::tuple<const Alignments*, const Alignments*> getAlignGlobal(const typename T::AlignedRecord& iRecord) const {
227  const Alignments* alignPtr(nullptr);
228  const Alignments* globalPtr(nullptr);
230  if (applyAlignment_) // get ptr if necessary
231  {
232  const auto& alignments = iRecord.get(alignmentTokens_.alignments);
233  // require expected size
234  assert(alignments.m_align.size() == T::numberOfAlignments());
235  alignPtr = &alignments;
236 
237  const auto& globals = iRecord.get(alignmentTokens_.globals);
238  globalPtr = &globals;
239  }
240  }
241  return std::make_tuple(alignPtr, globalPtr);
242  }
243 
248 };
249 
250 #endif
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:165
CaloCellGeometry::Pt3D Pt3D
static TokenType makeToken(edm::ESConsumesCollectorT< typename T::AlignedRecord > &cc)
std::vector< CCGFloat > DimVec
std::false_type has_AlignmentRecord(...)
edm::ESGetToken< Alignments, GlobalPositionRcd > globals
uint32_t cc[maxCellsPerHit]
Definition: gpuFishbone.h:49
std::unique_ptr< CaloSubdetectorGeometry > PtrType
calogeometryDBEPimpl::AlignmentTokens< T > alignmentTokens_
std::vector< unsigned int > IVec
CaloCellGeometry::Pt3DVec Pt3DVec
std::vector< CCGFloat > TrVec
HepGeom::Transform3D Tr3D
std::vector< Pt3D > Pt3DVec
assert(be >=bs)
std::tuple< const Alignments *, const Alignments * > getAlignGlobal(const typename T::AlignedRecord &iRecord) const
CaloSubdetectorGeometry::IVec IVec
PtrType produceAligned(const typename T::AlignedRecord &iRecord)
CaloSubdetectorGeometry::TrVec TrVec
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
Definition: value.py:1
calogeometryDBEPimpl::GeometryTraits< T, U::writeFlag()>::TokenType geometryToken_
Definition: DetId.h:17
AlgebraicVector EulerAngles
Definition: Definitions.h:34
void makeTokens(edm::ESConsumesCollectorT< typename T::AlignedRecord > &cc)
edm::ESGetToken< Alignments, typename T::AlignmentRecord > alignments
static TokenType makeToken(edm::ESConsumesCollectorT< typename T::AlignedRecord > &cc)
HepGeom::Point3D< CCGFloat > Pt3D
CaloCellGeometry::Tr3D Tr3D
CaloSubdetectorGeometry::DimVec DimVec
long double T
CaloCellGeometry::CCGFloat CCGFloat
calogeometryDBEPimpl::AdditionalTokens< T > additionalTokens_