CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
calowriters.cc
Go to the documentation of this file.
11 
12 template<>
15 {
16  const Alignments* alignPtr ( 0 ) ;
17  const Alignments* globalPtr ( 0 ) ;
18  if( m_applyAlignment ) // get ptr if necessary
19  {
20  edm::ESHandle< Alignments > alignments ;
21  iRecord.getRecord< typename HcalGeometry::AlignmentRecord >().get( alignments ) ;
22 
23  assert( alignments.isValid() && // require valid alignments and expected size
24  ( alignments->m_align.size() == HcalGeometry::numberOfAlignments() ) ) ;
25  alignPtr = alignments.product() ;
26 
28  iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;
29 
30  assert( globals.isValid() ) ;
31  globalPtr = globals.product() ;
32  }
33 
34  TrVec tvec ;
35  DimVec dvec ;
36  IVec ivec ;
37  IVec dins ;
38 
40  {
42  iRecord.get( HcalGeometry::producerTag() + std::string("_master"), pG ) ;
43 
44  const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
45 
46  pGptr->getSummary( tvec, ivec, dvec, dins ) ;
47 
48  CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, HcalGeometry::dbString() ) ;
49  }
50  else
51  {
53  iRecord.getRecord<typename HcalGeometry::PGeometryRecord >().get( pG ) ;
54 
55  tvec = pG->getTranslation() ;
56  dvec = pG->getDimension() ;
57  ivec = pG->getIndexes() ;
58  dins = pG->getDenseIndices();
59  }
60  //*********************************************************************************************
61 
62  edm::ESHandle<HcalTopology> hcalTopology;
63  iRecord.getRecord<HcalRecNumberingRecord>().get( hcalTopology );
64 
65  // We know that the numer of shapes chanes with changing depth
66  // so, this check is temporary disabled. We need to implement
67  // a way either to store or calculate the number of shapes or be able
68  // to deal with only max numer of shapes.
69  assert( dvec.size() <= hcalTopology->getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape ) ;
70  HcalGeometry* hcg=new HcalGeometry( *hcalTopology );
71  PtrType ptr ( hcg );
72 
73  const unsigned int nTrParm ( tvec.size()/hcalTopology->ncells() ) ;
74 
75  ptr->fillDefaultNamedParameters() ;
76 
77  ptr->allocateCorners( hcalTopology->ncells() ) ;
78 
79  ptr->allocatePar( dvec.size() ,
81 
82  for( unsigned int i ( 0 ) ; i < dins.size(); ++i )
83  {
84  const unsigned int nPerShape ( HcalGeometry::k_NumberOfParametersPerShape ) ;
85  DimVec dims ;
86  dims.reserve( nPerShape ) ;
87 
88  const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
89 
90  DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
91 
92  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
93  {
94  dims.push_back( *dsrc ) ;
95  ++dsrc ;
96  }
97 
98  const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
99  ptr->parMgr(),
100  ptr->parVecVec() ) ) ;
101 
102 
103  const DetId id ( hcalTopology->denseId2detId(dins[i]) ) ;
104 
105  const unsigned int iGlob ( 0 == globalPtr ? 0 :
107 
108  assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;
109 
110  const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;
111 
112  assert( 0 == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
113 
114  const unsigned int iLoc ( 0 == alignPtr ? 0 :
116 
117  assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;
118 
119  const AlignTransform* at ( 0 == alignPtr ? 0 :
120  &alignPtr->m_align[ iLoc ] ) ;
121 
122  assert( 0 == at || ( HcalGeometry::alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
123 
124  Pt3D lRef ;
125  Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
126  hcg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
127 
128  const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
129  const Pt3D lCor ( lc[0] ) ;
130 
131  //----------------------------------- create transform from 6 numbers ---
132  const unsigned int jj ( dins[i]*nTrParm ) ;
133 
134  Tr3D tr ;
135  const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
136  const ROOT::Math::EulerAngles ea (
137  6==nTrParm ?
138  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
140  const ROOT::Math::Transform3D rt ( ea, tl ) ;
141  double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
142  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
143  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
144  yx, yy, yz,
145  zx, zy, zz ),
146  CLHEP::Hep3Vector(dx,dy,dz) );
147 
148  // now prepend alignment(s) for final transform
149  const Tr3D atr ( 0 == at ? tr :
150  ( 0 == gt ? at->transform()*tr :
151  at->transform()*gt->transform()*tr ) ) ;
152  //--------------------------------- done making transform ---------------
153 
154  const Pt3D gRef ( atr*lRef ) ;
155  const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
156  const Pt3D gBck ( atr*lBck ) ;
157  const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
158  const Pt3D gCor ( atr*lCor ) ;
159  const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
160 
161  assert( hcalTopology->detId2denseId(id) == dins[i] );
162  ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
163  }
164 
165  ptr->initializeParms() ; // initializations; must happen after cells filled
166 
167  return ptr ;
168 }
169 
170 template<>
173 
174  const Alignments* alignPtr ( 0 ) ;
175  const Alignments* globalPtr ( 0 ) ;
176  if( m_applyAlignment ) { // get ptr if necessary
177  edm::ESHandle< Alignments > alignments ;
178  iRecord.getRecord< typename CaloTowerGeometry::AlignmentRecord >().get( alignments ) ;
179 
180  assert( alignments.isValid() && // require valid alignments and expected sizet
181  ( alignments->m_align.size() == CaloTowerGeometry::numberOfAlignments() ) ) ;
182  alignPtr = alignments.product() ;
183 
185  iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;
186 
187  assert( globals.isValid() ) ;
188  globalPtr = globals.product() ;
189  }
190 
191  TrVec tvec ;
192  DimVec dvec ;
193  IVec ivec ;
194  IVec dins ;
195 
198  iRecord.get( CaloTowerGeometry::producerTag() + std::string("_master"), pG ) ;
199 
200  const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
201 
202  pGptr->getSummary( tvec, ivec, dvec, dins ) ;
203 
205  } else {
207  iRecord.getRecord<typename CaloTowerGeometry::PGeometryRecord >().get( pG ) ;
208 
209  tvec = pG->getTranslation() ;
210  dvec = pG->getDimension() ;
211  ivec = pG->getIndexes() ;
212  dins = pG->getDenseIndices();
213  }
214 //*********************************************************************************************
215 
217  iRecord.getRecord<HcalRecNumberingRecord>().get( caloTopology );
218 
219 
220  CaloTowerGeometry* ctg=new CaloTowerGeometry( &*caloTopology );
221 
222  const unsigned int nTrParm ( tvec.size()/ctg->numberOfCellsForCorners() ) ;
223 
225 
226 
227  PtrType ptr ( ctg ) ;
228 
229  ptr->fillDefaultNamedParameters() ;
230 
231  ptr->allocateCorners( ctg->numberOfCellsForCorners() ) ;
232 
233  ptr->allocatePar( dvec.size() ,
235 
236  for( unsigned int i ( 0 ) ; i < dins.size() ; ++i ) {
237  const unsigned int nPerShape ( ctg->numberOfParametersPerShape() ) ;
238  DimVec dims ;
239  dims.reserve( nPerShape ) ;
240 
241  const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
242 
243  DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
244 
245  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j ) {
246  dims.push_back( *dsrc ) ;
247  ++dsrc ;
248  }
249 
250  const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
251  ptr->parMgr(),
252  ptr->parVecVec() ));
253 
254 
255  const DetId id ( caloTopology->detIdFromDenseIndex(dins[i]) ) ;
256 
257  const unsigned int iGlob ( 0 == globalPtr ? 0 :
258  ctg->alignmentTransformIndexGlobal( id ) ) ;
259 
260  assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;
261 
262  const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;
263 
264  assert( 0 == gt || iGlob == ctg->alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
265 
266  const unsigned int iLoc ( 0 == alignPtr ? 0 :
267  ctg->alignmentTransformIndexLocal( id ) ) ;
268 
269  assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;
270 
271  const AlignTransform* at ( 0 == alignPtr ? 0 :
272  &alignPtr->m_align[ iLoc ] ) ;
273 
274  assert( 0 == at || ( ctg->alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
275 
276  const CaloGenericDetId gId ( id ) ;
277 
278  Pt3D lRef ;
279  Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
280  ctg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
281 
282  const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
283  const Pt3D lCor ( lc[0] ) ;
284 
285  //----------------------------------- create transform from 6 numbers ---
286  const unsigned int jj ( i*nTrParm ) ;
287  Tr3D tr ;
288  const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
289  const ROOT::Math::EulerAngles ea (
290  6==nTrParm ?
291  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
293  const ROOT::Math::Transform3D rt ( ea, tl ) ;
294  double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
295  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
296  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
297  yx, yy, yz,
298  zx, zy, zz ),
299  CLHEP::Hep3Vector(dx,dy,dz) );
300 
301  // now prepend alignment(s) for final transform
302  const Tr3D atr ( 0 == at ? tr :
303  ( 0 == gt ? at->transform()*tr :
304  at->transform()*gt->transform()*tr ) ) ;
305  //--------------------------------- done making transform ---------------
306 
307  const Pt3D gRef ( atr*lRef ) ;
308  const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
309  const Pt3D gBck ( atr*lBck ) ;
310  const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
311  const Pt3D gCor ( atr*lCor ) ;
312  const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
313 
314  assert( caloTopology->denseIndex(id) == dins[i] );
315 
316  ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
317  }
318 
319  ptr->initializeParms() ; // initializations; must happen after cells filled
320 
321  return ptr ;
322 }
323 
327 
332 
335 
337 
340 
342 
345 
347 
350 
352 
355 
357 
360 
362 
365 
CaloGeometryDBEP< EcalBarrelGeometry, CaloGeometryDBWriter > EcalBarrelGeometryToDBEP
Definition: calowriters.cc:334
int i
Definition: DBlmapReader.cc:9
CaloCellGeometry::Pt3D Pt3D
static unsigned int alignmentTransformIndexLocal(const DetId &id)
CaloGeometryDBEP< CastorGeometry, CaloGeometryDBWriter > CastorGeometryToDBEP
Definition: calowriters.cc:364
virtual unsigned int numberOfCellsForCorners() const
assert(m_qm.get())
static std::string producerTag()
Definition: HcalGeometry.h:54
CaloGeometryDBEP< ZdcGeometry, CaloGeometryDBWriter > ZdcGeometryToDBEP
Definition: calowriters.cc:359
CaloCellGeometry::Pt3DVec Pt3DVec
unsigned int alignmentTransformIndexLocal(const DetId &id)
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
boost::shared_ptr< CaloSubdetectorGeometry > PtrType
virtual void getSummary(TrVec &trVector, IVec &iVector, DimVec &dimVector, IVec &dinsVector) const
static std::string producerTag()
CaloSubdetectorGeometry::IVec IVec
CaloGeometryDBEP< HcalGeometry, CaloGeometryDBWriter > HcalGeometryToDBEP
Definition: calowriters.cc:349
virtual unsigned int numberOfParametersPerShape() const
void get(HolderT &iHolder) const
static std::string dbString()
static unsigned int alignmentTransformIndexGlobal(const DetId &id)
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)
unsigned int alignmentTransformIndexGlobal(const DetId &id)
CaloCellGeometry::Pt3D Pt3D
static void localCorners(Pt3DVec &lc, const CCGFloat *pv, unsigned int i, Pt3D &ref)
Definition: DetId.h:18
AlgebraicVector EulerAngles
Definition: Definitions.h:36
static std::string dbString()
Definition: HcalGeometry.h:35
T const * product() const
Definition: ESHandle.h:86
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
CaloCellGeometry::Tr3D Tr3D
CaloGeometryDBEP< EcalEndcapGeometry, CaloGeometryDBWriter > EcalEndcapGeometryToDBEP
Definition: calowriters.cc:339
CaloCellGeometry::Tr3D Tr3D
virtual unsigned int numberOfShapes() const
CaloGeometryDBEP< EcalPreshowerGeometry, CaloGeometryDBWriter > EcalPreshowerGeometryToDBEP
Definition: calowriters.cc:344
CaloSubdetectorGeometry::DimVec DimVec
CaloGeometryDBEP< CaloTowerGeometry, CaloGeometryDBWriter > CaloTowerGeometryToDBEP
Definition: calowriters.cc:354
bool isValid() const
Definition: ESHandle.h:47
CaloCellGeometry::CCGFloat CCGFloat
static void writeIndexed(const TrVec &tvec, const DimVec &dvec, const IVec &ivec, const IVec &dins, std::string tag)
static unsigned int numberOfAlignments()
Definition: HcalGeometry.h:66
static unsigned int numberOfAlignments()