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