test
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_deltaPhi (nullptr) ,
17  m_deltaEta (nullptr)
18 {}
19 
20 
22 {
23  delete m_cmgr ;
24  delete m_parMgr ;
25  if (m_deltaPhi) delete m_deltaPhi.load() ;
26  if (m_deltaEta) delete m_deltaEta.load() ;
27 }
28 
29 void
31 {
32  auto pos = std::lower_bound(m_validIds.begin(), m_validIds.end(), id);
33  m_validIds.insert(pos, id);
34 }
35 
36 const std::vector<DetId>&
38  int /*subdet*/ ) const
39 {
40  return m_validIds ;
41 }
42 
43 const CaloCellGeometry*
45 {
46  return cellGeomPtr( CaloGenericDetId( id ).denseIndex() ) ;
47 }
48 
49 bool
51 {
52  return ( 0 != getGeometry( id ) ) ;
53 }
54 
55 DetId
57 {
58  const CCGFloat eta ( r.eta() ) ;
59  const CCGFloat phi ( r.phi() ) ;
60  uint32_t index ( ~0 ) ;
61  CCGFloat closest ( 1e9 ) ;
62 
63  for( uint32_t i ( 0 ); i != m_validIds.size() ; ++i )
64  {
65  const CaloCellGeometry* cell ( getGeometry( m_validIds[ i ] ) ) ;
66  if( 0 != cell )
67  {
68  const GlobalPoint& p ( cell->getPosition() ) ;
69  const CCGFloat eta0 ( p.eta() ) ;
70  const CCGFloat phi0 ( p.phi() ) ;
71  const CCGFloat dR2 ( reco::deltaR2( eta0, phi0, eta, phi ) ) ;
72  if( dR2 < closest )
73  {
74  closest = dR2 ;
75  index = i ;
76  }
77  }
78  }
79  return ( closest > 0.9e9 ||
80  (uint32_t)(~0) == index ? DetId(0) :
81  m_validIds[index] ) ;
82 }
83 
86  double dR ) const
87 {
88  const double dR2 ( dR*dR ) ;
89  const double eta ( r.eta() ) ;
90  const double phi ( r.phi() ) ;
91 
92  DetIdSet dss;
93 
94  if( 0.000001 < dR )
95  {
96  for( uint32_t i ( 0 ); i != m_validIds.size() ; ++i )
97  {
98  const CaloCellGeometry* cell ( getGeometry( m_validIds[i] ) ) ;
99  if( 0 != cell )
100  {
101  const GlobalPoint& p ( cell->getPosition() ) ;
102  const CCGFloat eta0 ( p.eta() ) ;
103  if( fabs( eta - eta0 ) < dR )
104  {
105  const CCGFloat phi0 ( p.phi() ) ;
106  CCGFloat delp ( fabs( phi - phi0 ) ) ;
107  if( delp > M_PI ) delp = 2*M_PI - delp ;
108  if( delp < dR )
109  {
110  const CCGFloat dist2 ( reco::deltaR2( eta0, phi0, eta, phi ) ) ;
111  if( dist2 < dR2 ) dss.insert( m_validIds[i] ) ;
112  }
113  }
114  }
115  }
116  }
117  return dss;
118 }
119 
122  // stupid implementation not to be really used...
123  DetIdSet ids = getCells(r, dR);
124  CellSet cells; cells.reserve(ids.size());
125  for ( auto id : ids) cells.push_back(getGeometry(id));
126  return cells;
127 }
128 
129 void
131 {
132  assert( 0 == m_cmgr ) ;
135 
136  m_validIds.reserve( n ) ;
137 }
138 
139 void
141  unsigned int m )
142 {
143  assert( 0 == m_parMgr ) ;
144  m_parMgr = new ParMgr( n*m, m ) ;
145 }
146 
147 void
151  CaloSubdetectorGeometry::IVec& /*dins*/) const
152 {
153  tVec.reserve( m_validIds.size()*numberOfTransformParms() ) ;
154  iVec.reserve( numberOfShapes()==1 ? 1 : m_validIds.size() ) ;
155  dVec.reserve( numberOfShapes()*numberOfParametersPerShape() ) ;
156 
157  for( ParVecVec::const_iterator ivv ( parVecVec().begin() ) ; ivv != parVecVec().end() ; ++ivv )
158  {
159  const ParVec& pv ( *ivv ) ;
160  for( ParVec::const_iterator iv ( pv.begin() ) ; iv != pv.end() ; ++iv )
161  {
162  dVec.push_back( *iv ) ;
163  }
164  }
165 
166  for( uint32_t i ( 0 ) ; i != m_validIds.size() ; ++i )
167  {
168  Tr3D tr ;
169  const CaloCellGeometry* ptr ( cellGeomPtr( i ) ) ;
170  assert( 0 != ptr ) ;
171  ptr->getTransform( tr, ( Pt3DVec* ) 0 ) ;
172 
173  if( Tr3D() == tr ) // for preshower there is no rotation
174  {
175  const GlobalPoint& gp ( ptr->getPosition() ) ;
176  tr = HepGeom::Translate3D( gp.x(), gp.y(), gp.z() ) ;
177  }
178 
179  const CLHEP::Hep3Vector tt ( tr.getTranslation() ) ;
180  tVec.push_back( tt.x() ) ;
181  tVec.push_back( tt.y() ) ;
182  tVec.push_back( tt.z() ) ;
183  if( 6 == numberOfTransformParms() )
184  {
185  const CLHEP::HepRotation rr ( tr.getRotation() ) ;
186  const ROOT::Math::Transform3D rtr ( rr.xx(), rr.xy(), rr.xz(), tt.x(),
187  rr.yx(), rr.yy(), rr.yz(), tt.y(),
188  rr.zx(), rr.zy(), rr.zz(), tt.z() ) ;
190  rtr.GetRotation( ea ) ;
191  tVec.push_back( ea.Phi() ) ;
192  tVec.push_back( ea.Theta() ) ;
193  tVec.push_back( ea.Psi() ) ;
194  }
195 
196  const CCGFloat* par ( ptr->param() ) ;
197 
198  unsigned int ishape ( 9999 ) ;
199  for( unsigned int ivv ( 0 ) ; ivv != parVecVec().size() ; ++ivv )
200  {
201  bool ok ( true ) ;
202  const CCGFloat* pv ( &(*parVecVec()[ivv].begin() ) ) ;
203  for( unsigned int k ( 0 ) ; k != numberOfParametersPerShape() ; ++k )
204  {
205  ok = ok && ( fabs( par[k] - pv[k] ) < 1.e-6 ) ;
206  }
207  if( ok )
208  {
209  ishape = ivv ;
210  break ;
211  }
212  }
213  assert( 9999 != ishape ) ;
214 
215  const unsigned int nn (( numberOfShapes()==1) ? (unsigned int)1 : m_validIds.size() ) ;
216  if( iVec.size() < nn ) iVec.push_back( ishape ) ;
217  }
218 }
219 
220 CCGFloat
222 {
223  const CaloGenericDetId cgId ( detId ) ;
224 
225  if(!m_deltaPhi.load(std::memory_order_acquire))
226  {
227  const uint32_t kSize ( sizeForDenseIndex(detId));
228  auto ptr = new std::vector<CCGFloat>(kSize);
229  for( uint32_t i ( 0 ) ; i != kSize ; ++i )
230  {
231  const CaloCellGeometry* cellPtr ( cellGeomPtr( i ) ) ;
232  if( 0 != cellPtr )
233  {
234  const CaloCellGeometry& cell ( *cellPtr ) ;
235  CCGFloat dPhi1 ( fabs(
236  GlobalPoint( ( cell.getCorners()[0].x() +
237  cell.getCorners()[1].x() )/2. ,
238  ( cell.getCorners()[0].y() +
239  cell.getCorners()[1].y() )/2. ,
240  ( cell.getCorners()[0].z() +
241  cell.getCorners()[1].z() )/2. ).phi() -
242  GlobalPoint( ( cell.getCorners()[2].x() +
243  cell.getCorners()[3].x() )/2. ,
244  ( cell.getCorners()[2].y() +
245  cell.getCorners()[3].y() )/2. ,
246  ( cell.getCorners()[2].z() +
247  cell.getCorners()[3].z() )/2. ).phi() ) ) ;
248  CCGFloat dPhi2 ( fabs(
249  GlobalPoint( ( cell.getCorners()[0].x() +
250  cell.getCorners()[3].x() )/2. ,
251  ( cell.getCorners()[0].y() +
252  cell.getCorners()[3].y() )/2. ,
253  ( cell.getCorners()[0].z() +
254  cell.getCorners()[3].z() )/2. ).phi() -
255  GlobalPoint( ( cell.getCorners()[2].x() +
256  cell.getCorners()[1].x() )/2. ,
257  ( cell.getCorners()[2].y() +
258  cell.getCorners()[1].y() )/2. ,
259  ( cell.getCorners()[2].z() +
260  cell.getCorners()[1].z() )/2. ).phi() ) ) ;
261  if( M_PI < dPhi1 ) dPhi1 = fabs( dPhi1 - 2.*M_PI ) ;
262  if( M_PI < dPhi2 ) dPhi2 = fabs( dPhi2 - 2.*M_PI ) ;
263  (*ptr)[i] = dPhi1>dPhi2 ? dPhi1 : dPhi2 ;
264  }
265  }
266  std::vector<CCGFloat>* expect = nullptr;
267  bool exchanged = m_deltaPhi.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
268  if (!exchanged) delete ptr;
269  }
270  return (*m_deltaPhi.load(std::memory_order_acquire))[ indexFor(detId) ] ;
271 }
272 
273 CCGFloat
275 {
276 
277  if(!m_deltaEta.load(std::memory_order_acquire))
278  {
279  const uint32_t kSize ( sizeForDenseIndex(detId));
280  auto ptr = new std::vector<CCGFloat> ( kSize ) ;
281  for( uint32_t i ( 0 ) ; i != kSize ; ++i )
282  {
283  const CaloCellGeometry* cellPtr ( cellGeomPtr( i ) ) ;
284  if( 0 != cellPtr )
285  {
286  const CaloCellGeometry& cell ( *cellPtr ) ;
287  const CCGFloat dEta1 ( fabs(
288  GlobalPoint( ( cell.getCorners()[0].x() +
289  cell.getCorners()[1].x() )/2. ,
290  ( cell.getCorners()[0].y() +
291  cell.getCorners()[1].y() )/2. ,
292  ( cell.getCorners()[0].z() +
293  cell.getCorners()[1].z() )/2. ).eta() -
294  GlobalPoint( ( cell.getCorners()[2].x() +
295  cell.getCorners()[3].x() )/2. ,
296  ( cell.getCorners()[2].y() +
297  cell.getCorners()[3].y() )/2. ,
298  ( cell.getCorners()[2].z() +
299  cell.getCorners()[3].z() )/2. ).eta() ) ) ;
300  const CCGFloat dEta2 ( fabs(
301  GlobalPoint( ( cell.getCorners()[0].x() +
302  cell.getCorners()[3].x() )/2. ,
303  ( cell.getCorners()[0].y() +
304  cell.getCorners()[3].y() )/2. ,
305  ( cell.getCorners()[0].z() +
306  cell.getCorners()[3].z() )/2. ).eta() -
307  GlobalPoint( ( cell.getCorners()[2].x() +
308  cell.getCorners()[1].x() )/2. ,
309  ( cell.getCorners()[2].y() +
310  cell.getCorners()[1].y() )/2. ,
311  ( cell.getCorners()[2].z() +
312  cell.getCorners()[1].z() )/2. ).eta() ) ) ;
313  (*ptr)[i] = dEta1>dEta2 ? dEta1 : dEta2 ;
314  }
315  }
316  std::vector<CCGFloat>* expect = nullptr;
317  bool exchanged = m_deltaEta.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
318  if (!exchanged) delete ptr;
319  }
320  return (*m_deltaEta.load(std::memory_order_acquire))[ indexFor(detId)];
321 }
322 
323 
324 unsigned int CaloSubdetectorGeometry::indexFor(const DetId& id) const { return CaloGenericDetId(id).denseIndex(); }
325 
int i
Definition: DBlmapReader.cc:9
CaloCellGeometry::CornersMgr * m_cmgr
std::vector< CCGFloat > DimVec
virtual unsigned int numberOfParametersPerShape() const
assert(m_qm.get())
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< 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
#define nullptr
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.
static constexpr unsigned int k_cornerSize
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
std::atomic< std::vector< CCGFloat > * > m_deltaPhi
CaloCellGeometry::CCGFloat CCGFloat
uint32_t denseIndex() const
#define M_PI
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const =0
virtual DetId getClosestCell(const GlobalPoint &r) const
CaloCellGeometry::Pt3D Pt3D
Definition: DetId.h:18
AlgebraicVector EulerAngles
Definition: Definitions.h:36
void addValidID(const DetId &id)
Detector
Definition: DetId.h:24
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Point3D< CCGFloat > Pt3D
CaloCellGeometry::ParMgr ParMgr
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
Definition: deltaR.h:36
CornersVec const & getCorners() const
Returns the corner points of this cell&#39;s volume.
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:30
const_iterator end() const
Definition: EZArrayFL.h:64
void allocateCorners(CaloCellGeometry::CornersVec::size_type n)
std::atomic< std::vector< CCGFloat > * > m_deltaEta
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