CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloSubdetectorGeometry.cc
Go to the documentation of this file.
3 
4 #include <Math/Transform3D.h>
5 #include <Math/EulerAngles.h>
6 
10 
12 
14  m_parMgr ( 0 ) ,
15  m_cmgr ( 0 ) ,
16  m_sortedIds (false) ,
17  m_deltaPhi ( 0 ) ,
18  m_deltaEta ( 0 )
19 {}
20 
21 
23 {
24  delete m_cmgr ;
25  delete m_parMgr ;
26  delete m_deltaPhi ;
27  delete m_deltaEta ;
28 }
29 
30 const std::vector<DetId>&
32  int /*subdet*/ ) const
33 {
34  if( !m_sortedIds )
35  {
36  m_sortedIds = true ;
37  std::sort( m_validIds.begin(), m_validIds.end() ) ;
38  }
39  return m_validIds ;
40 }
41 
42 const CaloCellGeometry*
44 {
45  return cellGeomPtr( CaloGenericDetId( id ).denseIndex() ) ;
46 }
47 
48 bool
50 {
51  return ( 0 != getGeometry( id ) ) ;
52 }
53 
54 DetId
56 {
57  const CCGFloat eta ( r.eta() ) ;
58  const CCGFloat phi ( r.phi() ) ;
59  uint32_t index ( ~0 ) ;
60  CCGFloat closest ( 1e9 ) ;
61 
62  for( uint32_t i ( 0 ); i != m_validIds.size() ; ++i )
63  {
64  const CaloCellGeometry* cell ( getGeometry( m_validIds[ i ] ) ) ;
65  if( 0 != cell )
66  {
67  const GlobalPoint& p ( cell->getPosition() ) ;
68  const CCGFloat eta0 ( p.eta() ) ;
69  const CCGFloat phi0 ( p.phi() ) ;
70  const CCGFloat dR2 ( reco::deltaR2( eta0, phi0, eta, phi ) ) ;
71  if( dR2 < closest )
72  {
73  closest = dR2 ;
74  index = i ;
75  }
76  }
77  }
78  return ( closest > 0.9e9 ||
79  (uint32_t)(~0) == index ? DetId(0) :
80  m_validIds[index] ) ;
81 }
82 
85  double dR ) const
86 {
87  const double dR2 ( dR*dR ) ;
88  const double eta ( r.eta() ) ;
89  const double phi ( r.phi() ) ;
90 
91  DetIdSet dss;
92 
93  if( 0.000001 < dR )
94  {
95  for( uint32_t i ( 0 ); i != m_validIds.size() ; ++i )
96  {
97  const CaloCellGeometry* cell ( getGeometry( m_validIds[i] ) ) ;
98  if( 0 != cell )
99  {
100  const GlobalPoint& p ( cell->getPosition() ) ;
101  const CCGFloat eta0 ( p.eta() ) ;
102  if( fabs( eta - eta0 ) < dR )
103  {
104  const CCGFloat phi0 ( p.phi() ) ;
105  CCGFloat delp ( fabs( phi - phi0 ) ) ;
106  if( delp > M_PI ) delp = 2*M_PI - delp ;
107  if( delp < dR )
108  {
109  const CCGFloat dist2 ( reco::deltaR2( eta0, phi0, eta, phi ) ) ;
110  if( dist2 < dR2 ) dss.insert( m_validIds[i] ) ;
111  }
112  }
113  }
114  }
115  }
116  return dss;
117 }
118 
119 void
121 {
122  assert( 0 == m_cmgr ) ;
125 
126  m_validIds.reserve( n ) ;
127 }
128 
129 void
131  unsigned int m )
132 {
133  assert( 0 == m_parMgr ) ;
134  m_parMgr = new ParMgr( n*m, m ) ;
135 }
136 
137 void
140  CaloSubdetectorGeometry::DimVec& dVec ) const
141 {
142  tVec.reserve( m_validIds.size()*numberOfTransformParms() ) ;
143  iVec.reserve( numberOfShapes()==1 ? 1 : m_validIds.size() ) ;
144  dVec.reserve( numberOfShapes()*numberOfParametersPerShape() ) ;
145 
146  for( ParVecVec::const_iterator ivv ( parVecVec().begin() ) ; ivv != parVecVec().end() ; ++ivv )
147  {
148  const ParVec& pv ( *ivv ) ;
149  for( ParVec::const_iterator iv ( pv.begin() ) ; iv != pv.end() ; ++iv )
150  {
151  dVec.push_back( *iv ) ;
152  }
153  }
154 
155  for( uint32_t i ( 0 ) ; i != m_validIds.size() ; ++i )
156  {
157  Tr3D tr ;
158  const CaloCellGeometry* ptr ( cellGeomPtr( i ) ) ;
159  assert( 0 != ptr ) ;
160  ptr->getTransform( tr, ( Pt3DVec* ) 0 ) ;
161 
162  if( Tr3D() == tr ) // for preshower there is no rotation
163  {
164  const GlobalPoint& gp ( ptr->getPosition() ) ;
165  tr = HepGeom::Translate3D( gp.x(), gp.y(), gp.z() ) ;
166  }
167 
168  const CLHEP::Hep3Vector tt ( tr.getTranslation() ) ;
169  tVec.push_back( tt.x() ) ;
170  tVec.push_back( tt.y() ) ;
171  tVec.push_back( tt.z() ) ;
172  if( 6 == numberOfTransformParms() )
173  {
174  const CLHEP::HepRotation rr ( tr.getRotation() ) ;
175  const ROOT::Math::Transform3D rtr ( rr.xx(), rr.xy(), rr.xz(), tt.x(),
176  rr.yx(), rr.yy(), rr.yz(), tt.y(),
177  rr.zx(), rr.zy(), rr.zz(), tt.z() ) ;
179  rtr.GetRotation( ea ) ;
180  tVec.push_back( ea.Phi() ) ;
181  tVec.push_back( ea.Theta() ) ;
182  tVec.push_back( ea.Psi() ) ;
183  }
184 
185  const CCGFloat* par ( ptr->param() ) ;
186 
187  unsigned int ishape ( 9999 ) ;
188  for( unsigned int ivv ( 0 ) ; ivv != parVecVec().size() ; ++ivv )
189  {
190  bool ok ( true ) ;
191  const CCGFloat* pv ( &(*parVecVec()[ivv].begin() ) ) ;
192  for( unsigned int k ( 0 ) ; k != numberOfParametersPerShape() ; ++k )
193  {
194  ok = ok && ( fabs( par[k] - pv[k] ) < 1.e-6 ) ;
195  }
196  if( ok )
197  {
198  ishape = ivv ;
199  break ;
200  }
201  }
202  assert( 9999 != ishape ) ;
203 
204  const unsigned int nn (( numberOfShapes()==1) ? (unsigned int)1 : m_validIds.size() ) ;
205  if( iVec.size() < nn ) iVec.push_back( ishape ) ;
206  }
207 }
208 
209 CCGFloat
211 {
212  const CaloGenericDetId cgId ( detId ) ;
213 
214  if( 0 == m_deltaPhi )
215  {
216  const uint32_t kSize ( cgId.sizeForDenseIndexing() ) ;
217  m_deltaPhi = new std::vector<CCGFloat> ( kSize ) ;
218  for( uint32_t i ( 0 ) ; i != kSize ; ++i )
219  {
220  const CaloCellGeometry* cellPtr ( cellGeomPtr( i ) ) ;
221  if( 0 != cellPtr )
222  {
223  const CaloCellGeometry& cell ( *cellPtr ) ;
224  CCGFloat dPhi1 ( fabs(
225  GlobalPoint( ( cell.getCorners()[0].x() +
226  cell.getCorners()[1].x() )/2. ,
227  ( cell.getCorners()[0].y() +
228  cell.getCorners()[1].y() )/2. ,
229  ( cell.getCorners()[0].z() +
230  cell.getCorners()[1].z() )/2. ).phi() -
231  GlobalPoint( ( cell.getCorners()[2].x() +
232  cell.getCorners()[3].x() )/2. ,
233  ( cell.getCorners()[2].y() +
234  cell.getCorners()[3].y() )/2. ,
235  ( cell.getCorners()[2].z() +
236  cell.getCorners()[3].z() )/2. ).phi() ) ) ;
237  CCGFloat dPhi2 ( fabs(
238  GlobalPoint( ( cell.getCorners()[0].x() +
239  cell.getCorners()[3].x() )/2. ,
240  ( cell.getCorners()[0].y() +
241  cell.getCorners()[3].y() )/2. ,
242  ( cell.getCorners()[0].z() +
243  cell.getCorners()[3].z() )/2. ).phi() -
244  GlobalPoint( ( cell.getCorners()[2].x() +
245  cell.getCorners()[1].x() )/2. ,
246  ( cell.getCorners()[2].y() +
247  cell.getCorners()[1].y() )/2. ,
248  ( cell.getCorners()[2].z() +
249  cell.getCorners()[1].z() )/2. ).phi() ) ) ;
250  if( M_PI < dPhi1 ) dPhi1 = fabs( dPhi1 - 2.*M_PI ) ;
251  if( M_PI < dPhi2 ) dPhi2 = fabs( dPhi2 - 2.*M_PI ) ;
252  (*m_deltaPhi)[i] = dPhi1>dPhi2 ? dPhi1 : dPhi2 ;
253  }
254  }
255  }
256  return (*m_deltaPhi)[ cgId.denseIndex() ] ;
257 }
258 
259 CCGFloat
261 {
262  const CaloGenericDetId cgId ( detId ) ;
263 
264  if( 0 == m_deltaEta )
265  {
266  const uint32_t kSize ( cgId.sizeForDenseIndexing() ) ;
267  m_deltaEta = new std::vector<CCGFloat> ( kSize ) ;
268  for( uint32_t i ( 0 ) ; i != kSize ; ++i )
269  {
270  const CaloCellGeometry* cellPtr ( cellGeomPtr( i ) ) ;
271  if( 0 != cellPtr )
272  {
273  const CaloCellGeometry& cell ( *cellPtr ) ;
274  const CCGFloat dEta1 ( fabs(
275  GlobalPoint( ( cell.getCorners()[0].x() +
276  cell.getCorners()[1].x() )/2. ,
277  ( cell.getCorners()[0].y() +
278  cell.getCorners()[1].y() )/2. ,
279  ( cell.getCorners()[0].z() +
280  cell.getCorners()[1].z() )/2. ).eta() -
281  GlobalPoint( ( cell.getCorners()[2].x() +
282  cell.getCorners()[3].x() )/2. ,
283  ( cell.getCorners()[2].y() +
284  cell.getCorners()[3].y() )/2. ,
285  ( cell.getCorners()[2].z() +
286  cell.getCorners()[3].z() )/2. ).eta() ) ) ;
287  const CCGFloat dEta2 ( fabs(
288  GlobalPoint( ( cell.getCorners()[0].x() +
289  cell.getCorners()[3].x() )/2. ,
290  ( cell.getCorners()[0].y() +
291  cell.getCorners()[3].y() )/2. ,
292  ( cell.getCorners()[0].z() +
293  cell.getCorners()[3].z() )/2. ).eta() -
294  GlobalPoint( ( cell.getCorners()[2].x() +
295  cell.getCorners()[1].x() )/2. ,
296  ( cell.getCorners()[2].y() +
297  cell.getCorners()[1].y() )/2. ,
298  ( cell.getCorners()[2].z() +
299  cell.getCorners()[1].z() )/2. ).eta() ) ) ;
300  (*m_deltaEta)[i] = dEta1>dEta2 ? dEta1 : dEta2 ;
301  }
302  }
303  }
304  return (*m_deltaEta)[ cgId.denseIndex() ] ;
305 }
int i
Definition: DBlmapReader.cc:9
CaloCellGeometry::CornersMgr * m_cmgr
std::vector< CCGFloat > DimVec
virtual unsigned int numberOfParametersPerShape() const
CCGFloat deltaPhi(const DetId &detId) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
MgrType::size_type size_type
Definition: EZArrayFL.h:30
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
std::vector< CCGFloat > * m_deltaEta
std::vector< unsigned int > IVec
std::vector< CCGFloat > TrVec
const_iterator begin() const
Definition: EZArrayFL.h:63
HepGeom::Transform3D Tr3D
uint32_t sizeForDenseIndexing() const
std::vector< Pt3D > Pt3DVec
T eta() const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
CCGFloat deltaEta(const DetId &detId) const
CaloCellGeometry::CCGFloat CCGFloat
EZMgrFL< GlobalPoint > CornersMgr
void allocatePar(ParVec::size_type n, unsigned int m)
virtual const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const
Get a list of valid detector ids (for the given subdetector)
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
const CCGFloat * param() const
virtual bool present(const DetId &id) const
is this detid present in the geometry?
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
virtual unsigned int numberOfShapes() const
virtual void getTransform(Tr3D &tr, Pt3DVec *lptr) const
--------— only needed by specific utility; overloaded when needed -—
std::vector< DetId > m_validIds
CaloCellGeometry::CCGFloat CCGFloat
double deltaR2(double eta1, double phi1, double eta2, double phi2)
Definition: deltaR.h:13
uint32_t denseIndex() const
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const =0
int k[5][pyjets_maxn]
virtual DetId getClosestCell(const GlobalPoint &r) const
CaloCellGeometry::Pt3D Pt3D
Definition: DetId.h:20
void getSummary(TrVec &trVector, IVec &iVector, DimVec &dimVector) const
AlgebraicVector EulerAngles
Definition: Definitions.h:36
#define M_PI
Definition: BFit3D.cc:3
Detector
Definition: DetId.h:26
std::vector< CCGFloat > * m_deltaPhi
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Point3D< CCGFloat > Pt3D
CaloCellGeometry::ParMgr ParMgr
CaloCellGeometry::Tr3D Tr3D
T eta() const
Definition: PV3DBase.h:75
MgrType::const_iterator const_iterator
Definition: EZArrayFL.h:27
virtual ~CaloSubdetectorGeometry()
The base class DOES assume that it owns the CaloCellGeometry objects.
#define begin
Definition: vmac.h:31
const_iterator end() const
Definition: EZArrayFL.h:64
void allocateCorners(CaloCellGeometry::CornersVec::size_type n)
virtual unsigned int numberOfTransformParms() const
virtual const CornersVec & getCorners() const =0
Returns the corner points of this cell&#39;s volume.
Definition: DDAxes.h:10