6 #include <CLHEP/Geometry/Point3D.h>
7 #include <CLHEP/Geometry/Plane3D.h>
12 typedef HepGeom::Plane3D<CCGFloat>
Pl3D ;
14 EcalEndcapGeometry::EcalEndcapGeometry(
void )
26 m_cellVec( k_NumberOfCellsForCorners )
42 EcalEndcapGeometry::~EcalEndcapGeometry()
46 auto ptr = m_borderPtrVec.load(std::memory_order_acquire);
47 for(
auto&
v: (*ptr)) {
51 delete m_borderPtrVec ;
57 EcalEndcapGeometry::alignmentTransformIndexLocal(
const DetId&
id )
61 assert( gid.isEE() ) ;
68 EcalEndcapGeometry::detIdFromLocalAlignmentIndex(
unsigned int iLoc )
70 return EEDetId( 20 + 50*( iLoc%2 ), 50, 2*( iLoc/2 ) - 1 ) ;
74 EcalEndcapGeometry::alignmentTransformIndexGlobal(
const DetId& )
80 EcalEndcapGeometry::initializeParms()
88 for( uint32_t
i ( 0 ) ;
i != m_cellVec.size() ; ++
i )
93 const CCGFloat z ( cell->getPosition().z() ) ;
105 const unsigned int ix ( myId.ix() ) ;
106 const unsigned int iy ( myId.iy() ) ;
107 if( ix > m_nref ) m_nref = ix ;
108 if( iy > m_nref ) m_nref = iy ;
122 for( uint32_t
i ( 0 ) ;
i != m_cellVec.size() ; ++
i )
129 const CCGFloat zz ( 0 >
z ? zeN : zeP ) ;
133 if( 0 >
z &&
x < m_xlo[0] ) m_xlo[0] =
x ;
134 if( 0 <
z &&
x < m_xlo[1] ) m_xlo[1] =
x ;
135 if( 0 >
z &&
y < m_ylo[0] ) m_ylo[0] =
y ;
136 if( 0 <
z &&
y < m_ylo[1] ) m_ylo[1] =
y ;
138 if( 0 >
z &&
x > m_xhi[0] ) m_xhi[0] =
x ;
139 if( 0 <
z &&
x > m_xhi[1] ) m_xhi[1] =
x ;
140 if( 0 >
z &&
y > m_yhi[0] ) m_yhi[0] =
y ;
141 if( 0 <
z &&
y > m_yhi[1] ) m_yhi[1] =
y ;
145 m_xoff[0] = ( m_xhi[0] + m_xlo[0] )/2. ;
146 m_xoff[1] = ( m_xhi[1] + m_xlo[1] )/2. ;
147 m_yoff[0] = ( m_yhi[0] + m_ylo[0] )/2. ;
148 m_yoff[1] = ( m_yhi[1] + m_ylo[1] )/2. ;
150 m_del = ( m_xhi[0] - m_xlo[0] + m_xhi[1] - m_xlo[1] +
151 m_yhi[0] - m_ylo[0] + m_yhi[1] - m_ylo[1] ) ;
153 if( 1 != m_nref ) m_wref = m_del/(4.*(m_nref-1)) ;
155 m_xlo[0] -= m_wref/2 ;
156 m_xlo[1] -= m_wref/2 ;
157 m_xhi[0] += m_wref/2 ;
158 m_xhi[1] += m_wref/2 ;
160 m_ylo[0] -= m_wref/2 ;
161 m_ylo[1] -= m_wref/2 ;
162 m_yhi[0] += m_wref/2 ;
163 m_yhi[1] += m_wref/2 ;
183 const CCGFloat xlo ( 0 > z ? m_xlo[0] : m_xlo[1] ) ;
184 const int i ( 1 +
int( ( x - xlo )/m_wref ) ) ;
187 ( m_nref < (
unsigned int)
i ? m_nref : (
unsigned int)
i ) ) ;
195 const CCGFloat ylo ( 0 > z ? m_ylo[0] : m_ylo[1] ) ;
196 const int i ( 1 +
int( ( y - ylo )/m_wref ) ) ;
199 ( m_nref < (
unsigned int)
i ? m_nref : (
unsigned int)
i ) ) ;
203 EcalEndcapGeometry::gId(
float x,
207 const CCGFloat fac ( fabs( ( 0 > z ? zeN : zeP )/z ) ) ;
208 const unsigned int ix ( xindex( x*fac, z ) ) ;
209 const unsigned int iy ( yindex( y*fac, z ) ) ;
210 const unsigned int iz ( z>0 ? 1 : -1 ) ;
218 for(
unsigned int i ( 1 ) ;
i != 6 ; ++
i )
220 for(
unsigned int k ( 0 ) ;
k != 8 ; ++
k )
222 const int jx ( 0 ==
k || 4 ==
k || 5 ==
k ? +
i :
223 ( 1 ==
k || 5 <
k ? -
i : 0 ) ) ;
224 const int jy ( 2 ==
k || 4 ==
k || 6 ==
k ? +
i :
225 ( 3 ==
k || 5 ==
k || 7 ==
k ? -
i : 0 ) ) ;
228 return EEDetId( ix + jx, iy + jy, iz ) ;
239 EcalEndcapGeometry::getClosestCell(
const GlobalPoint&
r )
const
243 EEDetId mycellID ( gId( r.
x(), r.
y(), r.
z() ) ) ;
267 if( 0 != getGeometry(mycellID) )
269 const GlobalPoint& myPosition=getGeometry(mycellID)->getPosition();
304 for(
unsigned ic=0;ic<4;++ic)
306 corners[ic]=getGeometry(mycellID)->getCorners()[(unsigned)((zsign*ic+offset)%4)];
307 corners[4+ic]=getGeometry(mycellID)->getCorners()[(unsigned)(4+(zsign*ic+offset)%4)];
311 for (
short i=0;
i < 4 ; ++
i)
313 A =
Pt3D(corners[
i%4].
x(),corners[
i%4].
y(),corners[
i%4].
z());
314 B =
Pt3D(corners[(
i+1)%4].
x(),corners[(
i+1)%4].
y(),corners[(
i+1)%4].
z());
315 C =
Pt3D(corners[4+(
i+1)%4].
x(),corners[4+(
i+1)%4].
y(),corners[4+(
i+1)%4].
z());
319 if (corners[0].
z()<0.) distance=-distance;
325 const bool yout ( 0 > SS[0]*SS[2] ) ;
326 const bool xout ( 0 > SS[1]*SS[3] ) ;
330 const int ydel ( !yout ? 0 : ( 0 < SS[0] ? -1 : 1 ) ) ;
331 const int xdel ( !xout ? 0 : ( 0 < SS[1] ? -1 : 1 ) ) ;
332 const unsigned int ix ( mycellID.ix() + xdel ) ;
333 const unsigned int iy ( mycellID.iy() + ydel ) ;
334 const unsigned int iz ( mycellID.zside() ) ;
336 mycellID =
EEDetId( ix, iy, iz ) ;
352 EcalEndcapGeometry::getCells(
const GlobalPoint& r,
364 const float dR2 ( dR*dR ) ;
365 const float reta ( r.
eta() ) ;
366 const float rphi ( r.
phi() ) ;
367 const float rx ( r.
x() ) ;
368 const float ry ( r.
y() ) ;
369 const float rz ( r.
z() ) ;
370 const float fac (
std::abs( zeP/rz ) ) ;
371 const float xx (
rx*fac ) ;
372 const float yy (
ry*fac ) ;
373 const float zz ( rz*fac ) ;
375 const float xang ( std::atan( xx/zz ) ) ;
376 const float lowX ( zz>0 ? zz*
std::tan( xang - dR ) : zz*
std::tan( xang + dR ) ) ;
377 const float highX ( zz>0 ? zz*
std::tan( xang + dR ) : zz*
std::tan( xang - dR ) ) ;
378 const float yang ( std::atan( yy/zz ) ) ;
379 const float lowY ( zz>0 ? zz*
std::tan( yang - dR ) : zz*
std::tan( yang + dR ) ) ;
380 const float highY ( zz>0 ? zz*
std::tan( yang + dR ) : zz*
std::tan( yang - dR ) ) ;
382 const float refxlo ( 0 > rz ? m_xlo[0] : m_xlo[1] ) ;
383 const float refxhi ( 0 > rz ? m_xhi[0] : m_xhi[1] ) ;
384 const float refylo ( 0 > rz ? m_ylo[0] : m_ylo[1] ) ;
385 const float refyhi ( 0 > rz ? m_yhi[0] : m_yhi[1] ) ;
392 const int ix_ctr ( xindex( xx, rz ) ) ;
393 const int iy_ctr ( yindex( yy, rz ) ) ;
394 const int iz ( rz>0 ? 1 : -1 ) ;
396 const int ix_hi ( ix_ctr +
int( ( highX - xx )/m_wref ) + 2 ) ;
397 const int ix_lo ( ix_ctr -
int( ( xx - lowX )/m_wref ) - 2 ) ;
399 const int iy_hi ( iy_ctr +
int( ( highY - yy )/m_wref ) + 2 ) ;
400 const int iy_lo ( iy_ctr -
int( ( yy - lowY )/m_wref ) - 2 ) ;
402 for(
int kx ( ix_lo ) ; kx <= ix_hi ; ++kx )
407 for(
int ky ( iy_lo ) ; ky <= iy_hi ; ++ky )
414 const EEDetId id ( kx, ky, iz ) ;
430 const EcalEndcapGeometry::OrderedListOfEBDetId*
431 EcalEndcapGeometry::getClosestBarrelCells(
EEDetId id )
const
433 OrderedListOfEBDetId* ptr (
nullptr ) ;
434 auto ptrVec = m_borderPtrVec.load(std::memory_order_acquire);
436 if(0 !=
id.rawId() && 0 != getGeometry(
id)) {
437 const float phi(370.+getGeometry(
id)->getPosition().
phi().
degrees());
438 const int iPhi(1+
int(
phi)%360) ;
439 const int iz(
id.zside()) ;
440 if (!m_borderMgr.load(std::memory_order_acquire)) {
443 bool exchanged = m_borderMgr.compare_exchange_strong(expect, ptrMgr, std::memory_order_acq_rel);
444 if(!exchanged)
delete ptrMgr;
446 VecOrdListEBDetIdPtr* expect =
nullptr;
447 auto ptrVec =
new VecOrdListEBDetIdPtr();
448 ptrVec->reserve(720);
449 for(
unsigned int i ( 0 ) ;
i != 720 ; ++
i )
451 const int kz ( 360>
i ? -1 : 1 ) ;
452 const int iEta ( kz*85 ) ;
453 const int iEtam1 ( kz*84 ) ;
454 const int iEtam2 ( kz*83 ) ;
455 const int jPhi (
i%360 + 1 ) ;
456 OrderedListOfEBDetId& olist ( *
new OrderedListOfEBDetId( m_borderMgr.load(std::memory_order_acquire) ) );
457 olist[0]=
EBDetId( iEta , jPhi ) ;
458 olist[1]=
EBDetId( iEta , myPhi( jPhi+1 ) ) ;
459 olist[2]=
EBDetId( iEta , myPhi( jPhi-1 ) ) ;
460 olist[3]=
EBDetId( iEtam1, jPhi ) ;
461 olist[4]=
EBDetId( iEtam1, myPhi( jPhi+1 ) ) ;
462 olist[5]=
EBDetId( iEtam1, myPhi( jPhi-1 ) ) ;
463 olist[6]=
EBDetId( iEta , myPhi( jPhi+2 ) ) ;
464 olist[7]=
EBDetId( iEta , myPhi( jPhi-2 ) ) ;
465 olist[8]=
EBDetId( iEtam2, jPhi ) ;
466 ptrVec->push_back( &olist ) ;
468 bool exchanged = m_borderPtrVec.compare_exchange_strong(expect, ptrVec, std::memory_order_acq_rel);
469 if(!exchanged)
delete ptrVec;
470 ptrVec = m_borderPtrVec.load(std::memory_order_acquire);
471 ptr = (*ptrVec)[ ( iPhi - 1 ) + ( 0>iz ? 0 : 360 ) ] ;
478 EcalEndcapGeometry::localCorners(
Pt3DVec& lc ,
483 TruncatedPyramid::localCorners( lc, pv, ref ) ;
493 const unsigned int cellIndex (
EEDetId( detId ).denseIndex() ) ;
494 m_cellVec[ cellIndex ] =
496 addValidID( detId ) ;
501 EcalEndcapGeometry::avgAbsZFrontFaceCenter()
const
503 if(!m_check.load(std::memory_order_acquire))
506 for(
unsigned int i ( 0 ) ;
i != m_cellVec.size() ; ++
i )
511 sum += fabs( cell->getPosition().z() ) ;
514 m_avgZ = sum/m_cellVec.size();
515 m_check.store(
true, std::memory_order_release);
521 EcalEndcapGeometry::cellGeomPtr( uint32_t
index )
const
524 return ( m_cellVec.size() < index ||
525 0 == cell->param() ? 0 : cell ) ;
static EEDetId detIdFromDenseIndex(uint32_t din)
double degrees(double radiants)
def degrees
std::set< DetId > DetIdSet
Geom::Phi< T > phi() const
std::vector< Pt3D > Pt3DVec
HepGeom::Plane3D< CCGFloat > Pl3D
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
Tan< T >::type tan(const T &t)
Abs< T >::type abs(const T &t)
CaloCellGeometry::CCGFloat CCGFloat
unsigned int offset(bool)
CaloCellGeometry::Pt3D Pt3D
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Point3D< CCGFloat > Pt3D
T1 deltaR2(T1 eta1, T2 phi1, T3 eta2, T4 phi2)
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point