CMS 3D CMS Logo

moduleDB.cc
Go to the documentation of this file.
3 
7 
8 template<>
11  const Alignments* alignPtr ( nullptr ) ;
12  const Alignments* globalPtr ( nullptr ) ;
13  if( m_applyAlignment ) {// get ptr if necessary
14  edm::ESHandle< Alignments > alignments ;
15  iRecord.getRecord< typename HcalGeometry::AlignmentRecord >().get( alignments ) ;
16 
17  assert( alignments.isValid() && // require valid alignments and expected size
18  ( alignments->m_align.size() == HcalGeometry::numberOfAlignments() ) ) ;
19  alignPtr = alignments.product() ;
20 
22  iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;
23 
24  assert( globals.isValid() ) ;
25  globalPtr = globals.product() ;
26  }
27 
28  TrVec tvec ;
29  DimVec dvec ;
30  IVec ivec ;
31  IVec dins ;
32 
35  iRecord.get( HcalGeometry::producerTag() + std::string("_master"), pG ) ;
36 
37  const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
38 
39  pGptr->getSummary( tvec, ivec, dvec, dins ) ;
40 
41  CaloGeometryDBReader::writeIndexed( tvec, dvec, ivec, dins, HcalGeometry::dbString() ) ;
42  } else {
44  iRecord.getRecord<typename HcalGeometry::PGeometryRecord >().get( pG ) ;
45 
46  tvec = pG->getTranslation() ;
47  dvec = pG->getDimension() ;
48  ivec = pG->getIndexes() ;
49  dins = pG->getDenseIndices();
50  }
51  //*********************************************************************************************
52 
53  edm::ESHandle<HcalTopology> hcalTopology;
54  iRecord.getRecord<HcalRecNumberingRecord>().get( hcalTopology );
55 
56  // We know that the numer of shapes chanes with changing depth
57  // so, this check is temporary disabled. We need to implement
58  // a way either to store or calculate the number of shapes or be able
59  // to deal with only max numer of shapes.
60  // assert( dvec.size() == hcalTopology->getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape ) ;
61  assert( dvec.size() <= hcalTopology->getNumberOfShapes() * HcalGeometry::k_NumberOfParametersPerShape ) ;
62  HcalGeometry* hcg = new HcalGeometry( *hcalTopology );
63 
64  PtrType ptr ( hcg );
65 
66  const unsigned int nTrParm( hcg->numberOfTransformParms());
67 
68  ptr->fillDefaultNamedParameters();
69  ptr->allocateCorners( hcalTopology->ncells()+hcalTopology->getHFSize());
70  ptr->allocatePar( dvec.size() ,
72 
73  for( unsigned int i ( 0 ) ; i < dins.size() ; ++i ) {
74  const unsigned int nPerShape ( HcalGeometry::k_NumberOfParametersPerShape );
75  DimVec dims;
76  dims.reserve( nPerShape );
77 
78  const unsigned int indx( ivec.size() == 1 ? 0 : i );
79 
80  DimVec::const_iterator dsrc( dvec.begin() + ivec[indx]*nPerShape );
81 
82  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j ) {
83  dims.emplace_back( *dsrc ) ;
84  ++dsrc ;
85  }
86 
87  const CCGFloat* myParm( CaloCellGeometry::getParmPtr( dims,
88  ptr->parMgr(),
89  ptr->parVecVec()));
90 
91  const DetId id( hcalTopology->denseId2detId( dins[i]));
92 
93  const unsigned int iGlob( nullptr == globalPtr ? 0 :
95 
96  assert( nullptr == globalPtr || iGlob < globalPtr->m_align.size());
97 
98  const AlignTransform* gt ( nullptr == globalPtr ? nullptr : &globalPtr->m_align[ iGlob ] );
99 
100  assert( nullptr == gt || iGlob == HcalGeometry::alignmentTransformIndexGlobal( DetId( gt->rawId())));
101 
102  const unsigned int iLoc( nullptr == alignPtr ? 0 :
104 
105  assert( nullptr == alignPtr || iLoc < alignPtr->m_align.size());
106 
107  const AlignTransform* at( nullptr == alignPtr ? nullptr :
108  &alignPtr->m_align[ iLoc ]);
109 
110  assert( nullptr == at || ( HcalGeometry::alignmentTransformIndexLocal( DetId( at->rawId())) == iLoc ));
111 
112  Pt3D lRef ;
113  Pt3DVec lc( 8, Pt3D( 0, 0, 0 ));
114  hcg->localCorners( lc, &dims.front(), dins[i], lRef );
115 
116  const Pt3D lBck( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] )); // ctr rear face in local
117  const Pt3D lCor( lc[0] );
118 
119  //----------------------------------- create transform from 6 numbers ---
120  const unsigned int jj( i * nTrParm ); // Note: Dence indices are not sorted and
121  // parameters stored according to order of a cell creation
122  Tr3D tr;
123  const ROOT::Math::Translation3D tl( tvec[jj], tvec[jj+1], tvec[jj+2] );
124  const ROOT::Math::EulerAngles ea( 6 == nTrParm ?
125  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
127  const ROOT::Math::Transform3D rt( ea, tl );
128  double xx, xy, xz, dx;
129  double yx, yy, yz, dy;
130  double zx, zy, zz, dz;
131  rt.GetComponents( xx, xy, xz, dx,
132  yx, yy, yz, dy,
133  zx, zy, zz, dz );
134  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
135  yx, yy, yz,
136  zx, zy, zz ),
137  CLHEP::Hep3Vector( dx, dy, dz));
138 
139  // now prepend alignment(s) for final transform
140  const Tr3D atr( nullptr == at ? tr :
141  ( nullptr == gt ? at->transform() * tr :
142  at->transform() * gt->transform() * tr ));
143  //--------------------------------- done making transform ---------------
144 
145  const Pt3D gRef( atr*lRef ) ;
146  const GlobalPoint fCtr( gRef.x(), gRef.y(), gRef.z() ) ;
147  const Pt3D gBck( atr*lBck ) ;
148  const GlobalPoint fBck( gBck.x(), gBck.y(), gBck.z() ) ;
149  const Pt3D gCor( atr*lCor ) ;
150  const GlobalPoint fCor( gCor.x(), gCor.y(), gCor.z() ) ;
151 
152  assert( hcalTopology->detId2denseId(id) == dins[i] );
153 
154  ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
155  }
156 
157  ptr->initializeParms(); // initializations; must happen after cells filled
158 
159  return ptr;
160 }
161 
162 template<>
165 
166  const Alignments* alignPtr ( nullptr ) ;
167  const Alignments* globalPtr ( nullptr ) ;
168  if( m_applyAlignment ) { // get ptr if necessary
169  edm::ESHandle< Alignments > alignments ;
170  iRecord.getRecord< typename CaloTowerGeometry::AlignmentRecord >().get( alignments ) ;
171 
172  assert( alignments.isValid() && // require valid alignments and expected sizet
173  ( alignments->m_align.size() == CaloTowerGeometry::numberOfAlignments() ) ) ;
174  alignPtr = alignments.product() ;
175 
177  iRecord.getRecord<GlobalPositionRcd>().get( globals ) ;
178 
179  assert( globals.isValid() ) ;
180  globalPtr = globals.product() ;
181  }
182 
183  TrVec tvec ;
184  DimVec dvec ;
185  IVec ivec ;
186  IVec dins ;
187 
190  iRecord.get( CaloTowerGeometry::producerTag() + std::string("_master"), pG ) ;
191 
192  const CaloSubdetectorGeometry* pGptr ( pG.product() ) ;
193 
194  pGptr->getSummary( tvec, ivec, dvec, dins ) ;
195 
197  } else {
199  iRecord.getRecord<typename CaloTowerGeometry::PGeometryRecord >().get( pG ) ;
200 
201  tvec = pG->getTranslation() ;
202  dvec = pG->getDimension() ;
203  ivec = pG->getIndexes() ;
204  dins = pG->getDenseIndices();
205  }
206 //*********************************************************************************************
207 
209  iRecord.getRecord<HcalRecNumberingRecord>().get( caloTopology );
210 
211 
212  CaloTowerGeometry* ctg=new CaloTowerGeometry( &*caloTopology );
213 
214  const unsigned int nTrParm ( tvec.size()/ctg->numberOfCellsForCorners() ) ;
215 
216  assert( dvec.size() == ctg->numberOfShapes() * CaloTowerGeometry::k_NumberOfParametersPerShape ) ;
217 
218 
219  PtrType ptr ( ctg ) ;
220 
221  ptr->fillDefaultNamedParameters() ;
222 
223  ptr->allocateCorners( ctg->numberOfCellsForCorners() ) ;
224 
225  ptr->allocatePar( dvec.size() ,
227 
228  for( unsigned int i ( 0 ) ; i < dins.size() ; ++i ) {
229  const unsigned int nPerShape ( ctg->numberOfParametersPerShape() ) ;
230  DimVec dims ;
231  dims.reserve( nPerShape ) ;
232 
233  const unsigned int indx ( ivec.size()==1 ? 0 : i ) ;
234 
235  DimVec::const_iterator dsrc ( dvec.begin() + ivec[indx]*nPerShape ) ;
236 
237  for( unsigned int j ( 0 ) ; j != nPerShape ; ++j ) {
238  dims.emplace_back( *dsrc ) ;
239  ++dsrc ;
240  }
241 
242  const CCGFloat* myParm ( CaloCellGeometry::getParmPtr( dims,
243  ptr->parMgr(),
244  ptr->parVecVec() ));
245 
246 
247  const DetId id ( caloTopology->detIdFromDenseIndex(dins[i]) ) ;
248 
249  const unsigned int iGlob ( nullptr == globalPtr ? 0 :
250  ctg->alignmentTransformIndexGlobal( id ) ) ;
251 
252  assert( nullptr == globalPtr || iGlob < globalPtr->m_align.size() ) ;
253 
254  const AlignTransform* gt ( nullptr == globalPtr ? nullptr : &globalPtr->m_align[ iGlob ] ) ;
255 
256  assert( nullptr == gt || iGlob == ctg->alignmentTransformIndexGlobal( DetId( gt->rawId() ) ) ) ;
257 
258  const unsigned int iLoc ( nullptr == alignPtr ? 0 :
259  ctg->alignmentTransformIndexLocal( id ) ) ;
260 
261  assert( nullptr == alignPtr || iLoc < alignPtr->m_align.size() ) ;
262 
263  const AlignTransform* at ( nullptr == alignPtr ? nullptr :
264  &alignPtr->m_align[ iLoc ] ) ;
265 
266  assert( nullptr == at || ( ctg->alignmentTransformIndexLocal( DetId( at->rawId() ) ) == iLoc ) ) ;
267 
268  const CaloGenericDetId gId ( id ) ;
269 
270  Pt3D lRef ;
271  Pt3DVec lc ( 8, Pt3D(0,0,0) ) ;
272  ctg->localCorners( lc, &dims.front(), dins[i], lRef ) ;
273 
274  const Pt3D lBck ( 0.25*(lc[4]+lc[5]+lc[6]+lc[7] ) ) ; // ctr rear face in local
275  const Pt3D lCor ( lc[0] ) ;
276 
277  //----------------------------------- create transform from 6 numbers ---
278  const unsigned int jj ( i*nTrParm ) ;
279  Tr3D tr ;
280  const ROOT::Math::Translation3D tl ( tvec[jj], tvec[jj+1], tvec[jj+2] ) ;
281  const ROOT::Math::EulerAngles ea (
282  6==nTrParm ?
283  ROOT::Math::EulerAngles( tvec[jj+3], tvec[jj+4], tvec[jj+5] ) :
285  const ROOT::Math::Transform3D rt ( ea, tl ) ;
286  double xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz;
287  rt.GetComponents(xx,xy,xz,dx,yx,yy,yz,dy,zx,zy,zz,dz) ;
288  tr = Tr3D( CLHEP::HepRep3x3( xx, xy, xz,
289  yx, yy, yz,
290  zx, zy, zz ),
291  CLHEP::Hep3Vector(dx,dy,dz) );
292 
293  // now prepend alignment(s) for final transform
294  const Tr3D atr ( nullptr == at ? tr :
295  ( nullptr == gt ? at->transform()*tr :
296  at->transform()*gt->transform()*tr ) ) ;
297  //--------------------------------- done making transform ---------------
298 
299  const Pt3D gRef ( atr*lRef ) ;
300  const GlobalPoint fCtr ( gRef.x(), gRef.y(), gRef.z() ) ;
301  const Pt3D gBck ( atr*lBck ) ;
302  const GlobalPoint fBck ( gBck.x(), gBck.y(), gBck.z() ) ;
303  const Pt3D gCor ( atr*lCor ) ;
304  const GlobalPoint fCor ( gCor.x(), gCor.y(), gCor.z() ) ;
305 
306  assert( caloTopology->denseIndex(id) == dins[i] );
307 
308  ptr->newCell( fCtr, fBck, fCor, myParm, id ) ;
309  }
310 
311  ptr->initializeParms() ; // initializations; must happen after cells filled
312 
313  return ptr ;
314 }
315 
317 
320 
322 
324 
327 
DetId denseId2detId(unsigned int) const override
return a linear packed id
unsigned int getHFSize() const
Definition: HcalTopology.h:141
CaloCellGeometry::Pt3D Pt3D
static unsigned int alignmentTransformIndexLocal(const DetId &id)
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:66
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
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
unsigned int numberOfParametersPerShape() const override
CaloTowerDetId detIdFromDenseIndex(uint32_t din) const
CaloGeometryDBEP< CaloTowerGeometry, CaloGeometryDBReader > CaloTowerGeometryFromDBEP
Definition: moduleDB.cc:326
unsigned int getNumberOfShapes() const
Definition: HcalTopology.h:164
void get(HolderT &iHolder) const
static std::string dbString()
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)
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:43
#define DEFINE_FWK_EVENTSETUP_MODULE(type)
Definition: ModuleFactory.h:60
CaloCellGeometry::Tr3D Tr3D
CaloCellGeometry::Tr3D Tr3D
unsigned int ncells() const override
return a count of valid cells (for dense indexing use)
CaloSubdetectorGeometry::DimVec DimVec
CaloGeometryDBEP< HcalGeometry, CaloGeometryDBReader > HcalGeometryFromDBEP
Definition: moduleDB.cc:319
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:78
std::vector< uint32_t > const & getDenseIndices() const
Definition: PCaloGeometry.h:23
static unsigned int numberOfAlignments()
static void writeIndexed(const TrVec &, const DimVec &, const IVec &, const std::vector< uint32_t > &, const std::string &)