CMS 3D CMS Logo

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 
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* hcalGeometry = new HcalGeometry( *hcalTopology );
72  PtrType ptr( hcalGeometry );
73 
74  const unsigned int nTrParm( hcalGeometry->numberOfTransformParms());
75 
76  ptr->fillDefaultNamedParameters();
77  ptr->allocateCorners( hcalTopology->ncells() + hcalTopology->getHFSize());
78  ptr->allocatePar( hcalGeometry->numberOfShapes(),
80 
81  for( unsigned int i ( 0 ) ; i < dins.size(); ++i )
82  {
83  const unsigned int nPerShape( HcalGeometry::k_NumberOfParametersPerShape );
84  DimVec dims;
85  dims.reserve( nPerShape );
86 
87  const unsigned int indx( ivec.size() == 1 ? 0 : i );
88 
89  DimVec::const_iterator dsrc( dvec.begin() + ivec[indx] * nPerShape );
90 
91  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
92  {
93  dims.push_back( *dsrc );
94  ++dsrc ;
95  }
96 
97  const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
98  ptr->parMgr(),
99  ptr->parVecVec()));
100 
101  const DetId id( hcalTopology->denseId2detId( dins[i]));
102 
103  const unsigned int iGlob( 0 == globalPtr ? 0 :
105 
106  assert( 0 == globalPtr || iGlob < globalPtr->m_align.size());
107 
108  const AlignTransform* gt( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ]);
109 
110  assert( 0 == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal( DetId( gt->rawId())));
111 
112  const unsigned int iLoc( 0 == alignPtr ? 0 :
114 
115  assert( 0 == alignPtr || iLoc < alignPtr->m_align.size());
116 
117  const AlignTransform* at( 0 == alignPtr ? 0 :
118  &alignPtr->m_align[ iLoc ]);
119 
120  assert( 0 == at || ( HcalGeometry::alignmentTransformIndexLocal( DetId( at->rawId())) == iLoc ));
121 
122  Pt3D lRef;
123  Pt3DVec lc( 8, Pt3D( 0, 0, 0 ));
124  hcalGeometry->localCorners( lc, &dims.front(), dins[i], lRef );
125 
126  const Pt3D lBck( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] )); // ctr rear face in local
127  const Pt3D lCor( lc[0] ) ;
128 
129  //----------------------------------- create transform from 6 numbers ---
130  const unsigned int jj( i * nTrParm );
131 
132  Tr3D tr;
133  const ROOT::Math::Translation3D tl( tvec[jj], tvec[jj+1], tvec[jj+2] );
134  const ROOT::Math::EulerAngles ea( 6 == nTrParm ?
135  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
137  const ROOT::Math::Transform3D rt( ea, tl );
138  double xx, xy, xz, dx;
139  double yx, yy, yz, dy;
140  double zx, zy, zz, dz;
141  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
142  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
143  yx, yy, yz,
144  zx, zy, zz ),
145  CLHEP::Hep3Vector( dx, dy, dz ));
146 
147  // now prepend alignment(s) for final transform
148  const Tr3D atr( 0 == at ? tr :
149  ( 0 == gt ? at->transform() * tr :
150  at->transform() * gt->transform() * tr ));
151  //--------------------------------- done making transform ---------------
152 
153  const Pt3D gRef( atr*lRef );
154  const GlobalPoint fCtr( gRef.x(), gRef.y(), gRef.z());
155  const Pt3D gBck( atr*lBck );
156  const GlobalPoint fBck( gBck.x(), gBck.y(), gBck.z());
157  const Pt3D gCor( atr*lCor );
158  const GlobalPoint fCor( gCor.x(), gCor.y(), gCor.z());
159 
160  assert( hcalTopology->detId2denseId(id) == dins[i] );
161  ptr->newCell( fCtr, fBck, fCor, myParm, id );
162  }
163 
164  ptr->initializeParms(); // initializations; must happen after cells filled
165 
166  return ptr;
167 }
168 
169 template<>
172 
173  const Alignments* alignPtr ( 0 ) ;
174  const Alignments* globalPtr ( 0 ) ;
175  if( m_applyAlignment ) { // get ptr if necessary
176  edm::ESHandle< Alignments > alignments ;
177  iRecord.getRecord< typename CaloTowerGeometry::AlignmentRecord >().get( alignments ) ;
178 
179  assert( alignments.isValid() && // require valid alignments and expected sizet
180  ( alignments->m_align.size() == CaloTowerGeometry::numberOfAlignments() ) ) ;
181  alignPtr = alignments.product() ;
182 
184  iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;
185 
186  assert( globals.isValid() ) ;
187  globalPtr = globals.product() ;
188  }
189 
190  TrVec tvec ;
191  DimVec dvec ;
192  IVec ivec ;
193  IVec dins ;
194 
197  iRecord.get( CaloTowerGeometry::producerTag() + std::string("_master"), pG ) ;
198 
199  const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
200 
201  pGptr->getSummary( tvec, ivec, dvec, dins ) ;
202 
204  } else {
206  iRecord.getRecord<typename CaloTowerGeometry::PGeometryRecord >().get( pG ) ;
207 
208  tvec = pG->getTranslation() ;
209  dvec = pG->getDimension() ;
210  ivec = pG->getIndexes() ;
211  dins = pG->getDenseIndices();
212  }
213 //*********************************************************************************************
214 
216  iRecord.getRecord<HcalRecNumberingRecord>().get( caloTopology );
217 
218 
219  CaloTowerGeometry* ctg=new CaloTowerGeometry( &*caloTopology );
220 
221  const unsigned int nTrParm ( tvec.size()/ctg->numberOfCellsForCorners() ) ;
222 
223  assert( dvec.size() == ctg->numberOfShapes() * CaloTowerGeometry::k_NumberOfParametersPerShape ) ;
224 
225 
226  PtrType ptr ( ctg ) ;
227 
228  ptr->fillDefaultNamedParameters() ;
229 
230  ptr->allocateCorners( ctg->numberOfCellsForCorners() ) ;
231 
232  ptr->allocatePar( dvec.size() ,
234 
235  for( unsigned int i ( 0 ) ; i < dins.size() ; ++i ) {
236  const unsigned int nPerShape ( ctg->numberOfParametersPerShape() ) ;
237  DimVec dims ;
238  dims.reserve( nPerShape ) ;
239 
240  const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
241 
242  DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
243 
244  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j ) {
245  dims.push_back( *dsrc ) ;
246  ++dsrc ;
247  }
248 
249  const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
250  ptr->parMgr(),
251  ptr->parVecVec() ));
252 
253 
254  const DetId id ( caloTopology->detIdFromDenseIndex(dins[i]) ) ;
255 
256  const unsigned int iGlob ( 0 == globalPtr ? 0 :
257  ctg->alignmentTransformIndexGlobal( id ) ) ;
258 
259  assert( 0 == globalPtr || iGlob < globalPtr->m_align.size() ) ;
260 
261  const AlignTransform* gt ( 0 == globalPtr ? 0 : &globalPtr->m_align[ iGlob ] ) ;
262 
263  assert( 0 == gt || iGlob == ctg->alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
264 
265  const unsigned int iLoc ( 0 == alignPtr ? 0 :
266  ctg->alignmentTransformIndexLocal( id ) ) ;
267 
268  assert( 0 == alignPtr || iLoc < alignPtr->m_align.size() ) ;
269 
270  const AlignTransform* at ( 0 == alignPtr ? 0 :
271  &alignPtr->m_align[ iLoc ] ) ;
272 
273  assert( 0 == at || ( ctg->alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
274 
275  const CaloGenericDetId gId ( id ) ;
276 
277  Pt3D lRef ;
278  Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
279  ctg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
280 
281  const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
282  const Pt3D lCor ( lc[0] ) ;
283 
284  //----------------------------------- create transform from 6 numbers ---
285  const unsigned int jj ( i*nTrParm ) ;
286  Tr3D tr ;
287  const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
288  const ROOT::Math::EulerAngles ea (
289  6==nTrParm ?
290  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
292  const ROOT::Math::Transform3D rt ( ea, tl ) ;
293  double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
294  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
295  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
296  yx, yy, yz,
297  zx, zy, zz ),
298  CLHEP::Hep3Vector(dx,dy,dz) );
299 
300  // now prepend alignment(s) for final transform
301  const Tr3D atr ( 0 == at ? tr :
302  ( 0 == gt ? at->transform()*tr :
303  at->transform()*gt->transform()*tr ) ) ;
304  //--------------------------------- done making transform ---------------
305 
306  const Pt3D gRef ( atr*lRef ) ;
307  const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
308  const Pt3D gBck ( atr*lBck ) ;
309  const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
310  const Pt3D gCor ( atr*lCor ) ;
311  const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
312 
313  assert( caloTopology->denseIndex(id) == dins[i] );
314 
315  ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
316  }
317 
318  ptr->initializeParms() ; // initializations; must happen after cells filled
319 
320  return ptr ;
321 }
322 
323 template<>
326 {
327  TrVec tvec; // transformation
328  DimVec dvec; // parameters
329  IVec ivec; // layers
330  IVec dins; // valid geom ids
331 
333 
334  name = "HGCalEESensitive";
335 
337  {
339  iRecord.getRecord<IdealGeometryRecord>().get( name, geom );
340 
341  geom->getSummary( tvec, ivec, dvec, dins ) ;
342 
343  CaloGeometryDBWriter::writeIndexed( tvec, dvec, ivec, dins, HGCalGeometry::dbString() ) ;
344  }
345  else
346  {
348  iRecord.getRecord<typename HGCalGeometry::PGeometryRecord >().get( pG ) ;
349 
350  tvec = pG->getTranslation() ;
351  dvec = pG->getDimension() ;
352  ivec = pG->getIndexes() ;
353  dins = pG->getDenseIndices();
354  }
355  //*********************************************************************************************
356 
358  iRecord.getRecord<IdealGeometryRecord>().get( name, topology );
359 
360  assert( dvec.size() <= topology->totalGeomModules() * HGCalGeometry::k_NumberOfParametersPerShape );
361  HGCalGeometry* hcg = new HGCalGeometry( *topology );
362  PtrType ptr ( hcg );
363 
364  ptr->allocateCorners( topology->ncells());
365  ptr->allocatePar( HGCalGeometry::k_NumberOfShapes,
367 
368  const unsigned int nTrParm( ptr->numberOfTransformParms());
369  const unsigned int nPerShape( HGCalGeometry::k_NumberOfParametersPerShape );
370 
371  for( auto it : dins )
372  {
373  DetId id = topology->encode( topology->geomDenseId2decId( it ));
374  // get layer
375  int layer = ivec[ it ];
376 
377  // get transformation
378  const unsigned int jj ( it * nTrParm );
379  Tr3D tr;
380  const ROOT::Math::Translation3D tl( tvec[jj], tvec[jj+1], tvec[jj+2]);
381  const ROOT::Math::EulerAngles ea( 6 == nTrParm ?
382  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
384  const ROOT::Math::Transform3D rt( ea, tl );
385  double xx, xy, xz, dx, yx, yy, yz, dy, zx, zy, zz, dz;
386  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
387  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
388  yx, yy, yz,
389  zx, zy, zz ),
390  CLHEP::Hep3Vector( dx, dy, dz));
391 
392  // get parameters
393  DimVec dims;
394  dims.reserve( nPerShape );
395 
396  DimVec::const_iterator dsrc( dvec.begin() + layer * nPerShape );
397  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j )
398  {
399  dims.push_back( *dsrc ) ;
400  ++dsrc ;
401  }
402 
403  std::vector<GlobalPoint> corners( 8 );
404 
405  FlatTrd::createCorners( dims, tr, corners );
406 
407  const CCGFloat* myParm( CaloCellGeometry::getParmPtr( dims,
408  ptr->parMgr(),
409  ptr->parVecVec()));
410  GlobalPoint front ( 0.25*( corners[0].x() +
411  corners[1].x() +
412  corners[2].x() +
413  corners[3].x()),
414  0.25*( corners[0].y() +
415  corners[1].y() +
416  corners[2].y() +
417  corners[3].y()),
418  0.25*( corners[0].z() +
419  corners[1].z() +
420  corners[2].z() +
421  corners[3].z()));
422 
423  GlobalPoint back ( 0.25*( corners[4].x() +
424  corners[5].x() +
425  corners[6].x() +
426  corners[7].x()),
427  0.25*( corners[4].y() +
428  corners[5].y() +
429  corners[6].y() +
430  corners[7].y()),
431  0.25*( corners[4].z() +
432  corners[5].z() +
433  corners[6].z() +
434  corners[7].z()));
435 
436  if (front.mag2() > back.mag2()) { // front should always point to the center, so swap front and back
437  std::swap (front, back);
438  std::swap_ranges (corners.begin(), corners.begin()+4, corners.begin()+4);
439  }
440 
441  ptr->newCell( front, back, corners[0], myParm, id );
442  }
443 
444  ptr->initializeParms(); // initializations; must happen after cells filled
445 
446  return ptr;
447 }
448 
452 
457 
460 
462 
465 
467 
470 
472 
475 
477 
480 
482 
485 
487 
490 
492 
495 
DetId denseId2detId(unsigned int) const override
return a linear packed id
CaloGeometryDBEP< EcalBarrelGeometry, CaloGeometryDBWriter > EcalBarrelGeometryToDBEP
Definition: calowriters.cc:459
unsigned int getHFSize() const
Definition: HcalTopology.h:135
CaloCellGeometry::Pt3D Pt3D
static unsigned int alignmentTransformIndexLocal(const DetId &id)
T mag2() const
Definition: PV3DBase.h:66
CaloGeometryDBEP< CastorGeometry, CaloGeometryDBWriter > CastorGeometryToDBEP
Definition: calowriters.cc:489
static void writeIndexed(const TrVec &tvec, const DimVec &dvec, const IVec &ivec, const IVec &dins, const std::string &tag)
CaloTopology const * topology(0)
unsigned int detId2denseId(const DetId &id) const override
return a linear packed id
virtual unsigned int numberOfCellsForCorners() const
static std::string producerTag()
Definition: HcalGeometry.h:63
CaloGeometryDBEP< ZdcGeometry, CaloGeometryDBWriter > ZdcGeometryToDBEP
Definition: calowriters.cc:484
unsigned int numberOfShapes() const override
CaloCellGeometry::Pt3DVec Pt3DVec
unsigned int alignmentTransformIndexLocal(const DetId &id)
std::vector< float > const & getTranslation() const
Definition: PCaloGeometry.h:20
std::shared_ptr< CaloSubdetectorGeometry > PtrType
std::vector< AlignTransform > m_align
Definition: Alignments.h:19
float float float z
std::vector< float > const & getDimension() const
Definition: PCaloGeometry.h:21
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.
unsigned int numberOfParametersPerShape() const override
CaloGeometryDBEP< HGCalGeometry, CaloGeometryDBWriter > HGCalGeometryToDBEP
Definition: calowriters.cc:494
unsigned int totalGeomModules() const
CaloTowerDetId detIdFromDenseIndex(uint32_t din) const
CaloGeometryDBEP< HcalGeometry, CaloGeometryDBWriter > HcalGeometryToDBEP
Definition: calowriters.cc:474
unsigned int getNumberOfShapes() const
Definition: HcalTopology.h:158
void swap(edm::DataFrameContainer &lhs, edm::DataFrameContainer &rhs)
DetId encode(const DecodedDetId &id_) const
static std::string dbString()
Definition: HGCalGeometry.h:45
void get(HolderT &iHolder) const
static std::string dbString()
virtual unsigned int ncells() const
return a count of valid cells (for dense indexing use)
static unsigned int alignmentTransformIndexGlobal(const DetId &id)
PtrType produceAligned(const typename T::AlignedRecord &iRecord)
CaloSubdetectorGeometry::TrVec TrVec
static const CCGFloat * getParmPtr(const std::vector< CCGFloat > &vd, ParMgr *mgr, ParVecVec &pvv)
DecodedDetId geomDenseId2decId(const uint32_t &hi) const
unsigned int alignmentTransformIndexGlobal(const DetId &id)
CaloCellGeometry::Pt3D Pt3D
uint32_t denseIndex(const DetId &id) const
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:41
void getSummary(CaloSubdetectorGeometry::TrVec &trVector, CaloSubdetectorGeometry::IVec &iVector, CaloSubdetectorGeometry::DimVec &dimVector, CaloSubdetectorGeometry::IVec &dinsVector) const override
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
CaloCellGeometry::Tr3D Tr3D
CaloGeometryDBEP< EcalEndcapGeometry, CaloGeometryDBWriter > EcalEndcapGeometryToDBEP
Definition: calowriters.cc:464
static void createCorners(const std::vector< CCGFloat > &pv, const Tr3D &tr, std::vector< GlobalPoint > &co)
Definition: FlatTrd.cc:140
CaloCellGeometry::Tr3D Tr3D
CaloGeometryDBEP< EcalPreshowerGeometry, CaloGeometryDBWriter > EcalPreshowerGeometryToDBEP
Definition: calowriters.cc:469
unsigned int ncells() const override
return a count of valid cells (for dense indexing use)
CaloSubdetectorGeometry::DimVec DimVec
CaloGeometryDBEP< CaloTowerGeometry, CaloGeometryDBWriter > CaloTowerGeometryToDBEP
Definition: calowriters.cc:479
bool isValid() const
Definition: ESHandle.h:47
T const * product() const
Definition: ESHandle.h:86
CaloCellGeometry::CCGFloat CCGFloat
std::vector< uint32_t > const & getIndexes() const
Definition: PCaloGeometry.h:22
static unsigned int numberOfAlignments()
Definition: HcalGeometry.h:75
std::vector< uint32_t > const & getDenseIndices() const
Definition: PCaloGeometry.h:23
static unsigned int numberOfAlignments()