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 
121  // stupid implementation not to be really used...
122  DetIdSet ids = getCells(r, dR);
123  CellSet cells; cells.reserve(ids.size());
124  for ( auto id : ids) cells.push_back(getGeometry(id));
125  return cells;
126 }
127 
128 void
130 {
131  assert( 0 == m_cmgr ) ;
134 
135  m_validIds.reserve( n ) ;
136 }
137 
138 void
140  unsigned int m )
141 {
142  assert( 0 == m_parMgr ) ;
143  m_parMgr = new ParMgr( n*m, m ) ;
144 }
145 
146 void
150  CaloSubdetectorGeometry::IVec& /*dins*/) const
151 {
152  tVec.reserve( m_validIds.size()*numberOfTransformParms() ) ;
153  iVec.reserve( numberOfShapes()==1 ? 1 : m_validIds.size() ) ;
154  dVec.reserve( numberOfShapes()*numberOfParametersPerShape() ) ;
155 
156  for( ParVecVec::const_iterator ivv ( parVecVec().begin() ) ; ivv != parVecVec().end() ; ++ivv )
157  {
158  const ParVec& pv ( *ivv ) ;
159  for( ParVec::const_iterator iv ( pv.begin() ) ; iv != pv.end() ; ++iv )
160  {
161  dVec.push_back( *iv ) ;
162  }
163  }
164 
165  for( uint32_t i ( 0 ) ; i != m_validIds.size() ; ++i )
166  {
167  Tr3D tr ;
168  const CaloCellGeometry* ptr ( cellGeomPtr( i ) ) ;
169  assert( 0 != ptr ) ;
170  ptr->getTransform( tr, ( Pt3DVec* ) 0 ) ;
171 
172  if( Tr3D() == tr ) // for preshower there is no rotation
173  {
174  const GlobalPoint& gp ( ptr->getPosition() ) ;
175  tr = HepGeom::Translate3D( gp.x(), gp.y(), gp.z() ) ;
176  }
177 
178  const CLHEP::Hep3Vector tt ( tr.getTranslation() ) ;
179  tVec.push_back( tt.x() ) ;
180  tVec.push_back( tt.y() ) ;
181  tVec.push_back( tt.z() ) ;
182  if( 6 == numberOfTransformParms() )
183  {
184  const CLHEP::HepRotation rr ( tr.getRotation() ) ;
185  const ROOT::Math::Transform3D rtr ( rr.xx(), rr.xy(), rr.xz(), tt.x(),
186  rr.yx(), rr.yy(), rr.yz(), tt.y(),
187  rr.zx(), rr.zy(), rr.zz(), tt.z() ) ;
189  rtr.GetRotation( ea ) ;
190  tVec.push_back( ea.Phi() ) ;
191  tVec.push_back( ea.Theta() ) ;
192  tVec.push_back( ea.Psi() ) ;
193  }
194 
195  const CCGFloat* par ( ptr->param() ) ;
196 
197  unsigned int ishape ( 9999 ) ;
198  for( unsigned int ivv ( 0 ) ; ivv != parVecVec().size() ; ++ivv )
199  {
200  bool ok ( true ) ;
201  const CCGFloat* pv ( &(*parVecVec()[ivv].begin() ) ) ;
202  for( unsigned int k ( 0 ) ; k != numberOfParametersPerShape() ; ++k )
203  {
204  ok = ok && ( fabs( par[k] - pv[k] ) < 1.e-6 ) ;
205  }
206  if( ok )
207  {
208  ishape = ivv ;
209  break ;
210  }
211  }
212  assert( 9999 != ishape ) ;
213 
214  const unsigned int nn (( numberOfShapes()==1) ? (unsigned int)1 : m_validIds.size() ) ;
215  if( iVec.size() < nn ) iVec.push_back( ishape ) ;
216  }
217 }
218 
219 CCGFloat
221 {
222  const CaloGenericDetId cgId ( detId ) ;
223 
224  if( 0 == m_deltaPhi )
225  {
226  const uint32_t kSize ( sizeForDenseIndex(detId));
227  m_deltaPhi = new std::vector<CCGFloat> ( kSize ) ;
228  for( uint32_t i ( 0 ) ; i != kSize ; ++i )
229  {
230  const CaloCellGeometry* cellPtr ( cellGeomPtr( i ) ) ;
231  if( 0 != cellPtr )
232  {
233  const CaloCellGeometry& cell ( *cellPtr ) ;
234  CCGFloat dPhi1 ( fabs(
235  GlobalPoint( ( cell.getCorners()[0].x() +
236  cell.getCorners()[1].x() )/2. ,
237  ( cell.getCorners()[0].y() +
238  cell.getCorners()[1].y() )/2. ,
239  ( cell.getCorners()[0].z() +
240  cell.getCorners()[1].z() )/2. ).phi() -
241  GlobalPoint( ( cell.getCorners()[2].x() +
242  cell.getCorners()[3].x() )/2. ,
243  ( cell.getCorners()[2].y() +
244  cell.getCorners()[3].y() )/2. ,
245  ( cell.getCorners()[2].z() +
246  cell.getCorners()[3].z() )/2. ).phi() ) ) ;
247  CCGFloat dPhi2 ( fabs(
248  GlobalPoint( ( cell.getCorners()[0].x() +
249  cell.getCorners()[3].x() )/2. ,
250  ( cell.getCorners()[0].y() +
251  cell.getCorners()[3].y() )/2. ,
252  ( cell.getCorners()[0].z() +
253  cell.getCorners()[3].z() )/2. ).phi() -
254  GlobalPoint( ( cell.getCorners()[2].x() +
255  cell.getCorners()[1].x() )/2. ,
256  ( cell.getCorners()[2].y() +
257  cell.getCorners()[1].y() )/2. ,
258  ( cell.getCorners()[2].z() +
259  cell.getCorners()[1].z() )/2. ).phi() ) ) ;
260  if( M_PI < dPhi1 ) dPhi1 = fabs( dPhi1 - 2.*M_PI ) ;
261  if( M_PI < dPhi2 ) dPhi2 = fabs( dPhi2 - 2.*M_PI ) ;
262  (*m_deltaPhi)[i] = dPhi1>dPhi2 ? dPhi1 : dPhi2 ;
263  }
264  }
265  }
266  return (*m_deltaPhi)[ indexFor(detId) ] ;
267 }
268 
269 CCGFloat
271 {
272 
273  if( 0 == m_deltaEta )
274  {
275  const uint32_t kSize ( sizeForDenseIndex(detId));
276  m_deltaEta = new std::vector<CCGFloat> ( kSize ) ;
277  for( uint32_t i ( 0 ) ; i != kSize ; ++i )
278  {
279  const CaloCellGeometry* cellPtr ( cellGeomPtr( i ) ) ;
280  if( 0 != cellPtr )
281  {
282  const CaloCellGeometry& cell ( *cellPtr ) ;
283  const CCGFloat dEta1 ( fabs(
284  GlobalPoint( ( cell.getCorners()[0].x() +
285  cell.getCorners()[1].x() )/2. ,
286  ( cell.getCorners()[0].y() +
287  cell.getCorners()[1].y() )/2. ,
288  ( cell.getCorners()[0].z() +
289  cell.getCorners()[1].z() )/2. ).eta() -
290  GlobalPoint( ( cell.getCorners()[2].x() +
291  cell.getCorners()[3].x() )/2. ,
292  ( cell.getCorners()[2].y() +
293  cell.getCorners()[3].y() )/2. ,
294  ( cell.getCorners()[2].z() +
295  cell.getCorners()[3].z() )/2. ).eta() ) ) ;
296  const CCGFloat dEta2 ( fabs(
297  GlobalPoint( ( cell.getCorners()[0].x() +
298  cell.getCorners()[3].x() )/2. ,
299  ( cell.getCorners()[0].y() +
300  cell.getCorners()[3].y() )/2. ,
301  ( cell.getCorners()[0].z() +
302  cell.getCorners()[3].z() )/2. ).eta() -
303  GlobalPoint( ( cell.getCorners()[2].x() +
304  cell.getCorners()[1].x() )/2. ,
305  ( cell.getCorners()[2].y() +
306  cell.getCorners()[1].y() )/2. ,
307  ( cell.getCorners()[2].z() +
308  cell.getCorners()[1].z() )/2. ).eta() ) ) ;
309  (*m_deltaEta)[i] = dEta1>dEta2 ? dEta1 : dEta2 ;
310  }
311  }
312  }
313  return (*m_deltaEta)[ indexFor(detId)];
314 }
315 
316 
317 unsigned int CaloSubdetectorGeometry::indexFor(const DetId& id) const { return CaloGenericDetId(id).denseIndex(); }
318 
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:69
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< CaloCellGeometry const * > CellSet
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
CCGFloat deltaEta(const DetId &detId) const
CaloCellGeometry::CCGFloat CCGFloat
EZMgrFL< GlobalPoint > CornersMgr
void allocatePar(ParVec::size_type n, unsigned int m)
virtual CellSet getCellSet(const GlobalPoint &r, double dR) const
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.
virtual void getSummary(TrVec &trVector, IVec &iVector, DimVec &dimVector, IVec &dinsVector) 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.
const CCGFloat * param() const
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
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
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
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:58
CaloCellGeometry::Tr3D Tr3D
T eta() const
Definition: PV3DBase.h:76
virtual unsigned int indexFor(const DetId &id) const
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
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
virtual unsigned int sizeForDenseIndex(const DetId &id) const
virtual const CornersVec & getCorners() const =0
Returns the corner points of this cell&#39;s volume.
Definition: DDAxes.h:10