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