CMS 3D CMS Logo

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 ( nullptr ) ,
15  m_cmgr ( nullptr ) ,
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 ( nullptr != 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( nullptr != 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( nullptr != 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.emplace_back(getGeometry(id));
126  return cells;
127 }
128 
129 void
131 {
132  assert( nullptr == m_cmgr ) ;
135 
136  m_validIds.reserve( n ) ;
137 }
138 
139 void
141  unsigned int m )
142 {
143  assert( nullptr == 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(const auto & pv : parVecVec())
158  {
159  for(float iv : pv)
160  {
161  dVec.emplace_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( nullptr != ptr ) ;
170  ptr->getTransform( tr, ( Pt3DVec* ) nullptr ) ;
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.emplace_back( tt.x() ) ;
180  tVec.emplace_back( tt.y() ) ;
181  tVec.emplace_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.emplace_back( ea.Phi() ) ;
191  tVec.emplace_back( ea.Theta() ) ;
192  tVec.emplace_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.emplace_back( ishape ) ;
216  }
217 }
218 
219 CCGFloat
221 {
222  const CaloGenericDetId cgId ( detId ) ;
223 
224  if(!m_deltaPhi.load(std::memory_order_acquire))
225  {
226  const uint32_t kSize ( sizeForDenseIndex(detId));
227  auto ptr = new std::vector<CCGFloat>(kSize);
228  for( uint32_t i ( 0 ) ; i != kSize ; ++i )
229  {
230  const CaloCellGeometry* cellPtr ( cellGeomPtr( i ) ) ;
231  if( nullptr != 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  (*ptr)[i] = dPhi1>dPhi2 ? dPhi1 : dPhi2 ;
263  }
264  }
265  std::vector<CCGFloat>* expect = nullptr;
266  bool exchanged = m_deltaPhi.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
267  if (!exchanged) delete ptr;
268  }
269  return (*m_deltaPhi.load(std::memory_order_acquire))[ indexFor(detId) ] ;
270 }
271 
272 CCGFloat
274 {
275 
276  if(!m_deltaEta.load(std::memory_order_acquire))
277  {
278  const uint32_t kSize ( sizeForDenseIndex(detId));
279  auto ptr = new std::vector<CCGFloat> ( kSize ) ;
280  for( uint32_t i ( 0 ) ; i != kSize ; ++i )
281  {
282  const CaloCellGeometry* cellPtr ( cellGeomPtr( i ) ) ;
283  if( nullptr != cellPtr )
284  {
285  const CaloCellGeometry& cell ( *cellPtr ) ;
286  const CCGFloat dEta1 ( fabs(
287  GlobalPoint( ( cell.getCorners()[0].x() +
288  cell.getCorners()[1].x() )/2. ,
289  ( cell.getCorners()[0].y() +
290  cell.getCorners()[1].y() )/2. ,
291  ( cell.getCorners()[0].z() +
292  cell.getCorners()[1].z() )/2. ).eta() -
293  GlobalPoint( ( cell.getCorners()[2].x() +
294  cell.getCorners()[3].x() )/2. ,
295  ( cell.getCorners()[2].y() +
296  cell.getCorners()[3].y() )/2. ,
297  ( cell.getCorners()[2].z() +
298  cell.getCorners()[3].z() )/2. ).eta() ) ) ;
299  const CCGFloat dEta2 ( fabs(
300  GlobalPoint( ( cell.getCorners()[0].x() +
301  cell.getCorners()[3].x() )/2. ,
302  ( cell.getCorners()[0].y() +
303  cell.getCorners()[3].y() )/2. ,
304  ( cell.getCorners()[0].z() +
305  cell.getCorners()[3].z() )/2. ).eta() -
306  GlobalPoint( ( cell.getCorners()[2].x() +
307  cell.getCorners()[1].x() )/2. ,
308  ( cell.getCorners()[2].y() +
309  cell.getCorners()[1].y() )/2. ,
310  ( cell.getCorners()[2].z() +
311  cell.getCorners()[1].z() )/2. ).eta() ) ) ;
312  (*ptr)[i] = dEta1>dEta2 ? dEta1 : dEta2 ;
313  }
314  }
315  std::vector<CCGFloat>* expect = nullptr;
316  bool exchanged = m_deltaEta.compare_exchange_strong(expect, ptr, std::memory_order_acq_rel);
317  if (!exchanged) delete ptr;
318  }
319  return (*m_deltaEta.load(std::memory_order_acquire))[ indexFor(detId)];
320 }
321 
322 
323 unsigned int CaloSubdetectorGeometry::indexFor(const DetId& id) const { return CaloGenericDetId(id).denseIndex(); }
324 
CaloCellGeometry::CornersMgr * m_cmgr
std::vector< CCGFloat > DimVec
virtual unsigned int numberOfParametersPerShape() const
virtual const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
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
CaloCellGeometry::Tr3D Tr3D
CaloCellGeometry::Pt3DVec Pt3DVec
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
def pv(vc)
Definition: MetAnalyzer.py:6
CaloSubdetectorGeometry::CCGFloat CCGFloat
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const =0
uint32_t denseIndex() const
#define M_PI
int k[5][pyjets_maxn]
virtual DetId getClosestCell(const GlobalPoint &r) const
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::Pt3D 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
virtual ~CaloSubdetectorGeometry()
The base class DOES assume that it owns the CaloCellGeometry objects.
#define begin
Definition: vmac.h:30
void allocateCorners(CaloCellGeometry::CornersVec::size_type n)
std::atomic< std::vector< CCGFloat > * > m_deltaEta
virtual unsigned int numberOfTransformParms() const
virtual unsigned int sizeForDenseIndex(const DetId &id) const