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  }
109  geometryToken_ = calogeometryDBEPimpl::GeometryTraits<T, U::writeFlag()>::makeToken(cc);
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 
245  typename calogeometryDBEPimpl::GeometryTraits<T, U::writeFlag()>::TokenType geometryToken_;
248 };
249 
250 #endif
CaloCellGeometry::Tr3D
HepGeom::Transform3D Tr3D
Definition: CaloCellGeometry.h:53
CaloCellGeometry::Pt3DVec
std::vector< Pt3D > Pt3DVec
Definition: CaloCellGeometry.h:55
CaloGeometryDBEP::Tr3D
CaloCellGeometry::Tr3D Tr3D
Definition: CaloGeometryDBEP.h:90
calogeometryDBEPimpl::HasAlignmentRecord
Definition: CaloGeometryDBEP.h:64
calogeometryDBEPimpl::AlignmentTokens
Definition: CaloGeometryDBEP.h:70
CaloGenericDetId.h
calogeometryDBEPimpl::AdditionalTokens::makeTokens
void makeTokens(edm::ESConsumesCollectorT< typename T::AlignedRecord > &cc)
Definition: CaloGeometryDBEP.h:80
GlobalPositionRcd.h
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
edm::ESInputTag
Definition: ESInputTag.h:87
geometryCSVtoXML.zz
zz
Definition: geometryCSVtoXML.py:19
CaloCellGeometry::CCGFloat
float CCGFloat
Definition: CaloCellGeometry.h:52
geometryCSVtoXML.yz
yz
Definition: geometryCSVtoXML.py:19
funct::false
false
Definition: Factorize.h:29
CaloGenericDetId
Definition: CaloGenericDetId.h:12
calogeometryDBEPimpl::has_AlignmentRecord
std::false_type has_AlignmentRecord(...)
CaloSubdetectorGeometry::DimVec
std::vector< CCGFloat > DimVec
Definition: CaloSubdetectorGeometry.h:35
calogeometryDBEPimpl::AlignmentTokens::globals
edm::ESGetToken< Alignments, GlobalPositionRcd > globals
Definition: CaloGeometryDBEP.h:72
hcal_runs.rt
rt
Definition: hcal_runs.py:76
edm::ESProducer::setWhatProduced
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:163
CaloGeometryDBEP::TrVec
CaloSubdetectorGeometry::TrVec TrVec
Definition: CaloGeometryDBEP.h:93
CaloGeometryDBEP::CCGFloat
CaloCellGeometry::CCGFloat CCGFloat
Definition: CaloGeometryDBEP.h:87
calogeometryDBEPimpl::GeometryTraits::makeToken
static TokenType makeToken(edm::ESConsumesCollectorT< typename T::AlignedRecord > &cc)
Definition: CaloGeometryDBEP.h:39
ESProducer.h
Alignments.h
CaloSubdetectorGeometry::TrVec
std::vector< CCGFloat > TrVec
Definition: CaloSubdetectorGeometry.h:33
CaloGeometryDBEP::additionalTokens_
calogeometryDBEPimpl::AdditionalTokens< T > additionalTokens_
Definition: CaloGeometryDBEP.h:246
cms::cuda::assert
assert(be >=bs)
CaloSubdetectorGeometry::IVec
std::vector< unsigned int > IVec
Definition: CaloSubdetectorGeometry.h:34
ESGetToken.h
DDCompactView.h
edm::ESConsumesCollectorT
Definition: ESConsumesCollector.h:125
DetId
Definition: DetId.h:17
submitPVValidationJobs.gt
list gt
Definition: submitPVValidationJobs.py:663
PCaloGeometry.h
TruncatedPyramid.h
calogeometryDBEPimpl::GeometryTraits< T, false >::makeToken
static TokenType makeToken(edm::ESConsumesCollectorT< typename T::AlignedRecord > &cc)
Definition: CaloGeometryDBEP.h:49
edm::es::Label
Definition: es_Label.h:56
calogeometryDBEPimpl
Definition: CaloGeometryDBEP.h:33
Point3DBase< float, GlobalTag >
CaloCellGeometry::Pt3D
HepGeom::Point3D< CCGFloat > Pt3D
Definition: CaloCellGeometry.h:54
geometryCSVtoXML.xy
xy
Definition: geometryCSVtoXML.py:19
AlignTransform
Definition: AlignTransform.h:15
CaloGeometryDBEP::PtrType
std::unique_ptr< CaloSubdetectorGeometry > PtrType
Definition: CaloGeometryDBEP.h:92
CaloSubdetectorGeometry.h
edm::ParameterSet
Definition: ParameterSet.h:47
PreshowerStrip.h
geometryCSVtoXML.yy
yy
Definition: geometryCSVtoXML.py:19
CaloGeometryDBEP::alignmentTokens_
calogeometryDBEPimpl::AlignmentTokens< T > alignmentTokens_
Definition: CaloGeometryDBEP.h:244
CaloGeometryDBEP::DimVec
CaloSubdetectorGeometry::DimVec DimVec
Definition: CaloGeometryDBEP.h:94
geometryCSVtoXML.xz
xz
Definition: geometryCSVtoXML.py:19
calogeometryDBEPimpl::AlignmentTokens::alignments
edm::ESGetToken< Alignments, typename T::AlignmentRecord > alignments
Definition: CaloGeometryDBEP.h:71
value
Definition: value.py:1
CaloGeometryDBEP::IVec
CaloSubdetectorGeometry::IVec IVec
Definition: CaloGeometryDBEP.h:95
IdealGeometryRecord.h
PVValHelper::dy
Definition: PVValidationHelpers.h:50
CaloGeometryDBEP
Definition: CaloGeometryDBEP.h:85
cc
align::EulerAngles
AlgebraicVector EulerAngles
Definition: Definitions.h:34
CaloGeometryDBEP::Pt3D
CaloCellGeometry::Pt3D Pt3D
Definition: CaloGeometryDBEP.h:88
AlCaHLTBitMon_QueryRunRegistry.string
string string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::ESGetToken
Definition: EventSetup.h:48
writeEcalDQMStatus.write
write
Definition: writeEcalDQMStatus.py:48
calogeometryDBEPimpl::GeometryTraits
Definition: CaloGeometryDBEP.h:36
calogeometryDBEPimpl::AdditionalTokens
Definition: CaloGeometryDBEP.h:79
ModuleFactory.h
CaloGeometryDBEP::applyAlignment_
bool applyAlignment_
Definition: CaloGeometryDBEP.h:247
PVValHelper::dz
Definition: PVValidationHelpers.h:51
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
T
long double T
Definition: Basic3DVectorLD.h:48
relativeConstraints.value
value
Definition: relativeConstraints.py:53
CaloGeometryDBEP::produceAligned
PtrType produceAligned(const typename T::AlignedRecord &iRecord)
Definition: CaloGeometryDBEP.h:116
findQualityFiles.jj
string jj
Definition: findQualityFiles.py:188
CaloCellGeometry::getParmPtr
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
Definition: CaloCellGeometry.cc:117
edm::ESProducer
Definition: ESProducer.h:104
CaloGeometryDBEP::Pt3DVec
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: CaloGeometryDBEP.h:89
dqmiolumiharvest.j
j
Definition: dqmiolumiharvest.py:66
Alignments
Definition: Alignments.h:10
CaloGeometryDBEP::geometryToken_
calogeometryDBEPimpl::GeometryTraits< T, U::writeFlag()>::TokenType geometryToken_
Definition: CaloGeometryDBEP.h:245
PVValHelper::dx
Definition: PVValidationHelpers.h:49
geometryCSVtoXML.xx
xx
Definition: geometryCSVtoXML.py:19
CaloGeometryDBEP::getAlignGlobal
std::tuple< const Alignments *, const Alignments * > getAlignGlobal(const typename T::AlignedRecord &iRecord) const
Definition: CaloGeometryDBEP.h:226