CMS 3D CMS Logo

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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
10 
12 
20 
22 
24 
25 #include <Math/Transform3D.h>
26 #include <Math/EulerAngles.h>
27 
28 //Forward declaration
29 
30 //
31 // class declaration
32 //
33 
34 template <class T, class U>
36 {
37  public:
38 
43 
44  using PtrType = std::unique_ptr<CaloSubdetectorGeometry >;
48 
50  m_applyAlignment ( ps.getParameter<bool>("applyAlignment") ),
51  m_pSet( ps )
52 
53  {
54  setWhatProduced( this,
56  edm::es::Label( T::producerTag() ) ) ;//+std::string("TEST") ) ) ;
57  }
58 
59  ~CaloGeometryDBEP<T,U>() override {}
60 
61  PtrType produceAligned( const typename T::AlignedRecord& iRecord )
62  {
63  const Alignments* alignPtr ( nullptr ) ;
64  const Alignments* globalPtr ( nullptr ) ;
65  if( m_applyAlignment ) // get ptr if necessary
66  {
67  edm::ESHandle< Alignments > alignments ;
68  iRecord.template getRecord< typename T::AlignmentRecord >().get( alignments ) ;
69 
70  assert( alignments.isValid() && // require valid alignments and expected size
71  ( alignments->m_align.size() == T::numberOfAlignments() ) ) ;
72  alignPtr = alignments.product() ;
73 
75  iRecord.template getRecord<GlobalPositionRcd>().get( globals ) ;
76 
77  assert( globals.isValid() ) ;
78  globalPtr = globals.product() ;
79  }
80 
81  TrVec tvec ;
82  DimVec dvec ;
83  IVec ivec ;
84  std::vector<uint32_t> dins;
85 
86  if( U::writeFlag() )
87  {
89  iRecord.get( T::producerTag() + std::string("_master"), pG ) ;
90 
91  const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
92 
93  pGptr->getSummary( tvec, ivec, dvec, dins ) ;
94 
95  U::write( tvec, dvec, ivec, T::dbString() ) ;
96  }
97  else
98  {
100  iRecord.template getRecord<typename T::PGeometryRecord >().get( pG ) ;
101 
102  tvec = pG->getTranslation() ;
103  dvec = pG->getDimension() ;
104  ivec = pG->getIndexes() ;
105  }
106 //*********************************************************************************************
107 
108  const unsigned int nTrParm ( tvec.size()/T::k_NumberOfCellsForCorners ) ;
109 
110  assert( dvec.size() == T::k_NumberOfShapes * T::k_NumberOfParametersPerShape ) ;
111 
112  PtrType ptr = std::make_unique<T>();
113 
114  ptr->fillDefaultNamedParameters() ;
115 
116  ptr->allocateCorners( T::k_NumberOfCellsForCorners ) ;
117 
118  ptr->allocatePar( dvec.size() ,
119  T::k_NumberOfParametersPerShape ) ;
120 
121  for( unsigned int i ( 0 ) ; i != T::k_NumberOfCellsForCorners ; ++i )
122  {
123  const unsigned int nPerShape ( T::k_NumberOfParametersPerShape ) ;
124  DimVec dims ;
125  dims.reserve( nPerShape ) ;
126 
127  const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
128 
129  DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
130 
131  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
132  {
133  dims.emplace_back( *dsrc ) ;
134  ++dsrc ;
135  }
136 
137  const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
138  ptr->parMgr(),
139  ptr->parVecVec() ) ) ;
140 
141 
142  const DetId id ( T::DetIdType::detIdFromDenseIndex( i ) ) ;
143 
144  const unsigned int iGlob ( nullptr == globalPtr ? 0 :
145  T::alignmentTransformIndexGlobal( id ) ) ;
146 
147  assert( nullptr == globalPtr || iGlob < globalPtr->m_align.size() ) ;
148 
149  const AlignTransform* gt ( nullptr == globalPtr ? nullptr : &globalPtr->m_align[ iGlob ] ) ;
150 
151  assert( nullptr == gt || iGlob == T::alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
152 
153  const unsigned int iLoc ( nullptr == alignPtr ? 0 :
154  T::alignmentTransformIndexLocal( id ) ) ;
155 
156  assert( nullptr == alignPtr || iLoc < alignPtr->m_align.size() ) ;
157 
158  const AlignTransform* at ( nullptr == alignPtr ? nullptr :
159  &alignPtr->m_align[ iLoc ] ) ;
160 
161  assert( nullptr == at || ( T::alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
162 
163  const CaloGenericDetId gId ( id ) ;
164 
165  Pt3D lRef ;
166  Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
167  T::localCorners( lc, &dims.front(), i, lRef ) ;
168 
169  const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
170  const Pt3D lCor ( lc[0] ) ;
171 
172  //----------------------------------- create transform from 6 numbers ---
173  const unsigned int jj ( i*nTrParm ) ;
174  Tr3D tr ;
175  const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
176  const ROOT::Math::EulerAngles ea (
177  6==nTrParm ?
178  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
180  const ROOT::Math::Transform3D rt ( ea, tl ) ;
181  double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
182  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
183  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
184  yx, yy, yz,
185  zx, zy, zz ),
186  CLHEP::Hep3Vector(dx,dy,dz) );
187 
188  // now prepend alignment(s) for final transform
189  const Tr3D atr ( nullptr == at ? tr :
190  ( nullptr == gt ? at->transform()*tr :
191  at->transform()*gt->transform()*tr ) ) ;
192  //--------------------------------- done making transform ---------------
193 
194  const Pt3D gRef ( atr*lRef ) ;
195  const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
196  const Pt3D gBck ( atr*lBck ) ;
197  const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
198  const Pt3D gCor ( atr*lCor ) ;
199  const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
200 
201  ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
202  }
203 
204  ptr->initializeParms() ; // initializations; must happen after cells filled
205 
206  return ptr ;
207  }
208 
209 private:
210 
213 };
214 
215 #endif
auto setWhatProduced(T *iThis, const es::Label &iLabel={})
Definition: ESProducer.h:124
CaloCellGeometry::Pt3D Pt3D
std::vector< CCGFloat > DimVec
std::vector< unsigned int > IVec
CaloCellGeometry::Pt3DVec Pt3DVec
std::vector< CCGFloat > TrVec
HepGeom::Transform3D Tr3D
std::vector< Pt3D > Pt3DVec
std::vector< float > const & getTranslation() const
Definition: PCaloGeometry.h:20
const edm::ParameterSet m_pSet
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
std::vector< float > const & getDimension() const
Definition: PCaloGeometry.h:21
virtual void getSummary(TrVec &trVector, IVec &iVector, DimVec &dimVector, IVec &dinsVector) const
CaloSubdetectorGeometry::IVec IVec
std::unique_ptr< CaloSubdetectorGeometry > PtrType
PtrType produceAligned(const typename T::AlignedRecord &iRecord)
CaloSubdetectorGeometry::TrVec TrVec
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
Definition: DetId.h:18
AlgebraicVector EulerAngles
Definition: Definitions.h:36
HepGeom::Point3D< CCGFloat > Pt3D
CaloCellGeometry::Tr3D Tr3D
CaloSubdetectorGeometry::DimVec DimVec
def write(self, setup)
bool isValid() const
Definition: ESHandle.h:44
T const * product() const
Definition: ESHandle.h:86
CaloCellGeometry::CCGFloat CCGFloat
std::vector< uint32_t > const & getIndexes() const
Definition: PCaloGeometry.h:22