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.
12 
13 template<>
16 {
17  const Alignments* alignPtr ( 0 ) ;
18  const Alignments* globalPtr ( 0 ) ;
19  if( m_applyAlignment ) // get ptr if necessary
20  {
21  edm::ESHandle< Alignments > alignments ;
22  iRecord.getRecord< typename HcalGeometry::AlignmentRecord >().get( alignments ) ;
23 
24  assert( alignments.isValid() && // require valid alignments and expected size
25  ( alignments->m_align.size() == HcalGeometry::numberOfAlignments() ) ) ;
26  alignPtr = alignments.product() ;
27 
29  iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;
30 
31  assert( globals.isValid() ) ;
32  globalPtr = globals.product() ;
33  }
34 
35  TrVec tvec ;
36  DimVec dvec ;
37  IVec ivec ;
38  IVec dins ;
39 
41  {
43  iRecord.get( HcalGeometry::producerTag() + std::string("_master"), pG ) ;
44 
45  const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
46 
47  pGptr->getSummary( tvec, ivec, dvec, dins ) ;
48 
49  CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, HcalGeometry::dbString() ) ;
50  }
51  else
52  {
54  iRecord.getRecord<typename HcalGeometry::PGeometryRecord >().get( pG ) ;
55 
56  tvec = pG->getTranslation() ;
57  dvec = pG->getDimension() ;
58  ivec = pG->getIndexes() ;
59  dins = pG->getDenseIndices();
60  }
61  //*********************************************************************************************
62 
63  edm::ESHandle<HcalTopology> hcalTopology;
64  iRecord.getRecord<HcalRecNumberingRecord>().get( hcalTopology );
65 
66  // We know that the numer of shapes chanes with changing depth
67  // so, this check is temporary disabled. We need to implement
68  // a way either to store or calculate the number of shapes or be able
69  // to deal with only max numer of shapes.
70  assert( dvec.size() <= hcalTopology->getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape ) ;
71  HcalGeometry* hcg=new HcalGeometry( *hcalTopology );
72  PtrType ptr ( hcg );
73 
74  const unsigned int nTrParm ( tvec.size()/hcalTopology->ncells() ) ;
75 
76  ptr->fillDefaultNamedParameters() ;
77 
78  ptr->allocateCorners( hcalTopology->ncells() + hcalTopology->getHFSize() ) ;
79 
80  ptr->allocatePar( dvec.size() ,
82 
83  for( unsigned int i ( 0 ) ; i < dins.size(); ++i )
84  {
85  const unsigned int nPerShape ( HcalGeometry::k_NumberOfParametersPerShape ) ;
86  DimVec dims ;
87  dims.reserve( nPerShape ) ;
88 
89  const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
90 
91  DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
92 
93  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
94  {
95  dims.push_back( *dsrc ) ;
96  ++dsrc ;
97  }
98 
99  const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
100  ptr->parMgr(),
101  ptr->parVecVec() ) ) ;
102 
103 
104  const DetId id ( hcalTopology->denseId2detId(dins[i]) ) ;
105 
106  const unsigned int iGlob ( 0 == globalPtr ? 0 :
108 
109  assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;
110 
111  const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;
112 
113  assert( 0 == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
114 
115  const unsigned int iLoc ( 0 == alignPtr ? 0 :
117 
118  assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;
119 
120  const AlignTransform* at ( 0 == alignPtr ? 0 :
121  &alignPtr->m_align[ iLoc ] ) ;
122 
123  assert( 0 == at || ( HcalGeometry::alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
124 
125  Pt3D lRef ;
126  Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
127  hcg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
128 
129  const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
130  const Pt3D lCor ( lc[0] ) ;
131 
132  //----------------------------------- create transform from 6 numbers ---
133  const unsigned int jj ( dins[i]*nTrParm ) ;
134 
135  Tr3D tr ;
136  const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
137  const ROOT::Math::EulerAngles ea (
138  6==nTrParm ?
139  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
141  const ROOT::Math::Transform3D rt ( ea, tl ) ;
142  double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
143  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
144  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
145  yx, yy, yz,
146  zx, zy, zz ),
147  CLHEP::Hep3Vector(dx,dy,dz) );
148 
149  // now prepend alignment(s) for final transform
150  const Tr3D atr ( 0 == at ? tr :
151  ( 0 == gt ? at->transform()*tr :
152  at->transform()*gt->transform()*tr ) ) ;
153  //--------------------------------- done making transform ---------------
154 
155  const Pt3D gRef ( atr*lRef ) ;
156  const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
157  const Pt3D gBck ( atr*lBck ) ;
158  const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
159  const Pt3D gCor ( atr*lCor ) ;
160  const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
161 
162  assert( hcalTopology->detId2denseId(id) == dins[i] );
163  ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
164  }
165 
166  ptr->initializeParms() ; // initializations; must happen after cells filled
167 
168  return ptr ;
169 }
170 
171 template<>
174 
175  const Alignments* alignPtr ( 0 ) ;
176  const Alignments* globalPtr ( 0 ) ;
177  if( m_applyAlignment ) { // get ptr if necessary
178  edm::ESHandle< Alignments > alignments ;
179  iRecord.getRecord< typename CaloTowerGeometry::AlignmentRecord >().get( alignments ) ;
180 
181  assert( alignments.isValid() && // require valid alignments and expected sizet
182  ( alignments->m_align.size() == CaloTowerGeometry::numberOfAlignments() ) ) ;
183  alignPtr = alignments.product() ;
184 
186  iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;
187 
188  assert( globals.isValid() ) ;
189  globalPtr = globals.product() ;
190  }
191 
192  TrVec tvec ;
193  DimVec dvec ;
194  IVec ivec ;
195  IVec dins ;
196 
199  iRecord.get( CaloTowerGeometry::producerTag() + std::string("_master"), pG ) ;
200 
201  const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
202 
203  pGptr->getSummary( tvec, ivec, dvec, dins ) ;
204 
206  } else {
208  iRecord.getRecord<typename CaloTowerGeometry::PGeometryRecord >().get( pG ) ;
209 
210  tvec = pG->getTranslation() ;
211  dvec = pG->getDimension() ;
212  ivec = pG->getIndexes() ;
213  dins = pG->getDenseIndices();
214  }
215 //*********************************************************************************************
216 
218  iRecord.getRecord<HcalRecNumberingRecord>().get( caloTopology );
219 
220 
221  CaloTowerGeometry* ctg=new CaloTowerGeometry( &*caloTopology );
222 
223  const unsigned int nTrParm ( tvec.size()/ctg->numberOfCellsForCorners() ) ;
224 
226 
227 
228  PtrType ptr ( ctg ) ;
229 
230  ptr->fillDefaultNamedParameters() ;
231 
232  ptr->allocateCorners( ctg->numberOfCellsForCorners() ) ;
233 
234  ptr->allocatePar( dvec.size() ,
236 
237  for( unsigned int i ( 0 ) ; i < dins.size() ; ++i ) {
238  const unsigned int nPerShape ( ctg->numberOfParametersPerShape() ) ;
239  DimVec dims ;
240  dims.reserve( nPerShape ) ;
241 
242  const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
243 
244  DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
245 
246  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j ) {
247  dims.push_back( *dsrc ) ;
248  ++dsrc ;
249  }
250 
251  const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
252  ptr->parMgr(),
253  ptr->parVecVec() ));
254 
255 
256  const DetId id ( caloTopology->detIdFromDenseIndex(dins[i]) ) ;
257 
258  const unsigned int iGlob ( 0 == globalPtr ? 0 :
259  ctg->alignmentTransformIndexGlobal( id ) ) ;
260 
261  assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;
262 
263  const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;
264 
265  assert( 0 == gt || iGlob == ctg->alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
266 
267  const unsigned int iLoc ( 0 == alignPtr ? 0 :
268  ctg->alignmentTransformIndexLocal( id ) ) ;
269 
270  assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;
271 
272  const AlignTransform* at ( 0 == alignPtr ? 0 :
273  &alignPtr->m_align[ iLoc ] ) ;
274 
275  assert( 0 == at || ( ctg->alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
276 
277  const CaloGenericDetId gId ( id ) ;
278 
279  Pt3D lRef ;
280  Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
281  ctg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
282 
283  const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
284  const Pt3D lCor ( lc[0] ) ;
285 
286  //----------------------------------- create transform from 6 numbers ---
287  const unsigned int jj ( i*nTrParm ) ;
288  Tr3D tr ;
289  const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
290  const ROOT::Math::EulerAngles ea (
291  6==nTrParm ?
292  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
294  const ROOT::Math::Transform3D rt ( ea, tl ) ;
295  double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
296  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
297  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
298  yx, yy, yz,
299  zx, zy, zz ),
300  CLHEP::Hep3Vector(dx,dy,dz) );
301 
302  // now prepend alignment(s) for final transform
303  const Tr3D atr ( 0 == at ? tr :
304  ( 0 == gt ? at->transform()*tr :
305  at->transform()*gt->transform()*tr ) ) ;
306  //--------------------------------- done making transform ---------------
307 
308  const Pt3D gRef ( atr*lRef ) ;
309  const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
310  const Pt3D gBck ( atr*lBck ) ;
311  const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
312  const Pt3D gCor ( atr*lCor ) ;
313  const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
314 
315  assert( caloTopology->denseIndex(id) == dins[i] );
316 
317  ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
318  }
319 
320  ptr->initializeParms() ; // initializations; must happen after cells filled
321 
322  return ptr ;
323 }
324 
325 template<>
328 {
329  TrVec tvec; // transformation
330  DimVec dvec; // parameters
331  IVec ivec; // layers
332  IVec dins; // valid geom ids
333 
335 
336  name = "HGCalEESensitive";
337 
339  {
341  iRecord.getRecord<IdealGeometryRecord>().get( name, geom );
342 
343  geom->getSummary( tvec, ivec, dvec, dins ) ;
344 
345  CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, HGCalGeometry::dbString() ) ;
346  }
347  else
348  {
350  iRecord.getRecord<typename HGCalGeometry::PGeometryRecord >().get( pG ) ;
351 
352  tvec = pG->getTranslation() ;
353  dvec = pG->getDimension() ;
354  ivec = pG->getIndexes() ;
355  dins = pG->getDenseIndices();
356  }
357  //*********************************************************************************************
358 
360  iRecord.getRecord<IdealGeometryRecord>().get( name, topology );
361 
362  assert( dvec.size() <= topology->totalGeomModules() * HGCalGeometry::k_NumberOfParametersPerShape );
363  HGCalGeometry* hcg = new HGCalGeometry( *topology );
364  PtrType ptr ( hcg );
365 
366  ptr->allocateCorners( topology->ncells());
367  ptr->allocatePar( HGCalGeometry::k_NumberOfShapes,
369 
370  const unsigned int nTrParm( ptr->numberOfTransformParms());
371  const unsigned int nPerShape( HGCalGeometry::k_NumberOfParametersPerShape );
372 
373  for( auto it : dins )
374  {
375  DetId id = topology->encode( topology->geomDenseId2decId( it ));
376  // get layer
377  int layer = ivec[ it ];
378 
379  // get transformation
380  const unsigned int jj ( it * nTrParm );
381  Tr3D tr;
382  const ROOT::Math::Translation3D tl( tvec[jj], tvec[jj+1], tvec[jj+2]);
383  const ROOT::Math::EulerAngles ea( 6 == nTrParm ?
384  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
386  const ROOT::Math::Transform3D rt( ea, tl );
387  double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
388  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
389  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
390  yx, yy, yz,
391  zx, zy, zz ),
392  CLHEP::Hep3Vector( dx, dy, dz));
393 
394  // get parameters
395  DimVec dims;
396  dims.reserve( nPerShape );
397 
398  DimVec::const_iterator dsrc( dvec.begin() + layer * nPerShape );
399  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
400  {
401  dims.push_back( *dsrc ) ;
402  ++dsrc ;
403  }
404 
405  std::vector<GlobalPoint> corners( 8 );
406 
407  FlatTrd::createCorners( dims, tr, corners );
408 
409  const CCGFloat* myParm( CaloCellGeometry::getParmPtr( dims,
410  ptr->parMgr(),
411  ptr->parVecVec()));
412  GlobalPoint front ( 0.25*( corners[0].x() +
413  corners[1].x() +
414  corners[2].x() +
415  corners[3].x()),
416  0.25*( corners[0].y() +
417  corners[1].y() +
418  corners[2].y() +
419  corners[3].y()),
420  0.25*( corners[0].z() +
421  corners[1].z() +
422  corners[2].z() +
423  corners[3].z()));
424 
425  GlobalPoint back ( 0.25*( corners[4].x() +
426  corners[5].x() +
427  corners[6].x() +
428  corners[7].x()),
429  0.25*( corners[4].y() +
430  corners[5].y() +
431  corners[6].y() +
432  corners[7].y()),
433  0.25*( corners[4].z() +
434  corners[5].z() +
435  corners[6].z() +
436  corners[7].z()));
437 
438  if (front.mag2() > back.mag2()) { // front should always point to the center, so swap front and back
439  std::swap (front, back);
440  std::swap_ranges (corners.begin(), corners.begin()+4, corners.begin()+4);
441  }
442 
443  ptr->newCell( front, back, corners[0], myParm, id );
444  }
445 
446  ptr->initializeParms(); // initializations; must happen after cells filled
447 
448  return ptr;
449 }
450 
454 
459 
462 
464 
467 
469 
472 
474 
477 
479 
482 
484 
487 
489 
492 
494 
497 
CaloGeometryDBEP< EcalBarrelGeometry, CaloGeometryDBWriter > EcalBarrelGeometryToDBEP
Definition: calowriters.cc:461
int i
Definition: DBlmapReader.cc:9
CaloCellGeometry::Pt3D Pt3D
static unsigned int alignmentTransformIndexLocal(const DetId &id)
T mag2() const
Definition: PV3DBase.h:66
CaloGeometryDBEP< CastorGeometry, CaloGeometryDBWriter > CastorGeometryToDBEP
Definition: calowriters.cc:491
CaloTopology const * topology(0)
virtual unsigned int numberOfCellsForCorners() const
assert(m_qm.get())
static std::string producerTag()
Definition: HcalGeometry.h:54
CaloGeometryDBEP< ZdcGeometry, CaloGeometryDBWriter > ZdcGeometryToDBEP
Definition: calowriters.cc:486
CaloCellGeometry::Pt3DVec Pt3DVec
unsigned int alignmentTransformIndexLocal(const DetId &id)
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
boost::shared_ptr< CaloSubdetectorGeometry > PtrType
float float float z
virtual void getSummary(TrVec &trVector, IVec &iVector, DimVec &dimVector, IVec &dinsVector) const
static std::string producerTag()
CaloSubdetectorGeometry::IVec IVec
T x() const
Cartesian x coordinate.
CaloGeometryDBEP< HGCalGeometry, CaloGeometryDBWriter > HGCalGeometryToDBEP
Definition: calowriters.cc:496
CaloGeometryDBEP< HcalGeometry, CaloGeometryDBWriter > HcalGeometryToDBEP
Definition: calowriters.cc:476
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
virtual unsigned int numberOfParametersPerShape() const
static std::string dbString()
Definition: HGCalGeometry.h:45
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:466
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatTrd.cc:136
CaloCellGeometry::Tr3D Tr3D
virtual unsigned int numberOfShapes() const
CaloGeometryDBEP< EcalPreshowerGeometry, CaloGeometryDBWriter > EcalPreshowerGeometryToDBEP
Definition: calowriters.cc:471
CaloSubdetectorGeometry::DimVec DimVec
CaloGeometryDBEP< CaloTowerGeometry, CaloGeometryDBWriter > CaloTowerGeometryToDBEP
Definition: calowriters.cc:481
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()