8 #include <CLHEP/Geometry/Point3D.h>
9 #include <CLHEP/Geometry/Plane3D.h>
10 #include <CLHEP/Geometry/Vector3D.h>
18 typedef HepGeom::Plane3D<CCGFloat>
Pl3D ;
20 EcalBarrelGeometry::EcalBarrelGeometry() :
28 m_cellVec ( k_NumberOfCellsForCorners )
30 const int neba[] = {25,45,65,85} ;
31 _EtaBaskets = std::vector<int>( neba, neba+4 ) ;
35 EcalBarrelGeometry::~EcalBarrelGeometry()
39 auto ptr = m_borderPtrVec.load(std::memory_order_acquire);
40 for(
auto&
v: (*ptr)) {
44 delete m_borderPtrVec.load() ;
46 delete m_borderMgr.load() ;
51 EcalBarrelGeometry::alignmentTransformIndexLocal(
const DetId&
id )
55 assert( gid.isEB() ) ;
63 EcalBarrelGeometry::detIdFromLocalAlignmentIndex(
unsigned int iLoc )
69 EcalBarrelGeometry::alignmentTransformIndexGlobal(
const DetId& )
75 EcalBarrelGeometry::getClosestCell(
const GlobalPoint&
r)
const
92 int guessed_eta = (int)( fabs(pointeta) / 0.0174)+1;
93 int guessed_eta_begin = guessed_eta-1;
94 int guessed_eta_end = guessed_eta+1;
95 if (guessed_eta_begin < 1) guessed_eta_begin = 1;
96 if (guessed_eta_end > 85) guessed_eta_end = 85;
98 for(
int bin=guessed_eta_begin;
bin<= guessed_eta_end;
bin++)
107 if(fabs(pointeta-eta)<deta)
109 deta=fabs(pointeta-eta);
134 int phibin =
static_cast<int>(pointphi / (twopi/_nnxtalPhi)) + 1;
145 if (!present(myCell))
165 while (leverx==1 || levery == 1)
174 for (
short i=0;
i < 4 ; ++
i)
176 A =
Pt3D(corners[
i%4].
x(),corners[
i%4].
y(),corners[
i%4].
z());
177 B =
Pt3D(corners[(
i+1)%4].
x(),corners[(
i+1)%4].
y(),corners[(
i+1)%4].
z());
178 C =
Pt3D(corners[4+(
i+1)%4].
x(),corners[4+(
i+1)%4].
y(),corners[4+(
i+1)%4].
z());
182 if(plane.d()>0.) distance=-distance;
183 if (corners[0].
z()<0.) distance=-distance;
191 if ( ( SS[0]>0.&&SS[2]>0. )||( SS[0]<0.&&SS[2]<0. ) )
194 if ( history[0]>0. && history[2]>0. && SS[0]<0 && SS[2]<0 &&
195 (fabs(SS[0])+fabs(SS[2]))> (fabs(history[0])+fabs(history[2]))) levery = 0 ;
196 if ( history[0]<0. && history[2]<0. && SS[0]>0 && SS[2]>0 &&
197 (fabs(SS[0])+fabs(SS[2]))> (fabs(history[0])+fabs(history[2]))) levery = 0 ;
206 nextPoint=
EBDetId(myCell.ieta(),myCell.iphi()-1);
207 if (present(nextPoint))
218 nextPoint=
EBDetId(myCell.ieta(),myCell.iphi()+1);
219 if (present(nextPoint))
227 if ( ( ( SS[1]>0.&&SS[3]>0. )||( SS[1]<0.&&SS[3]<0. )) && start==1 )
231 if ( history[1]>0. && history[3]>0. && SS[1]<0 && SS[3]<0 &&
232 (fabs(SS[1])+fabs(SS[3]))> (fabs(history[1])+fabs(history[3])) )
238 if ( history[1]<0. && history[3]<0. && SS[1]>0 && SS[3]>0 &&
239 (fabs(SS[1])+fabs(SS[3]))> (fabs(history[1])+fabs(history[3])) )
249 if (myCell.ieta()==-1)
250 nextPoint=
EBDetId (1,myCell.iphi());
253 int nieta= myCell.
ieta()+1;
254 if(nieta==86) nieta=85;
255 nextPoint=
EBDetId(nieta,myCell.iphi());
257 if (present(nextPoint))
265 if (myCell.ieta()==1)
266 nextPoint=
EBDetId(-1,myCell.iphi());
269 int nieta=myCell.
ieta()-1;
270 if(nieta==-86) nieta=-85;
271 nextPoint=
EBDetId(nieta,myCell.iphi());
273 if (present(nextPoint))
292 return DetId(myCell);
302 EcalBarrelGeometry::getCells(
const GlobalPoint& r,
319 const float dR2 ( dR*dR ) ;
320 const float reta ( r.
eta() ) ;
321 const float rz ( r.
z() ) ;
322 const float rphi ( r.
phi() ) ;
323 const float lowEta ( reta - dR ) ;
324 const float highEta ( reta + dR ) ;
326 if( highEta > -1.5 &&
329 const int ieta_center (
int( reta*
scale + ((rz<0)?(-1):(1))) ) ;
330 const float phi ( rphi<0 ? rphi +
float(2*M_PI) : rphi ) ;
331 const int iphi_center (
int(
phi*
scale + 11.
f ) ) ;
333 const float fr ( dR*
scale ) ;
334 const float frp ( 1.08
f*fr + 1.
f ) ;
335 const float frm ( 0.92
f*fr - 1.
f ) ;
336 const int idr ( (
int)frp ) ;
337 const int idr2p ( (
int)(frp*frp) ) ;
338 const int idr2m ( frm > 0 ?
int(frm*frm) : 0 ) ;
340 for(
int de ( -idr ) ; de <= idr ; ++de )
342 int ieta ( de + ieta_center ) ;
347 const int de2 ( de*de ) ;
348 for(
int dp ( -idr ) ;
dp <= idr ; ++
dp )
350 const int irange2 (
dp*
dp + de2 ) ;
352 if( irange2 <= idr2p )
354 const int iphi ( ( iphi_center +
dp + maxphi - 1 )%maxphi + 1 ) ;
358 const EBDetId id ( ieta, iphi ) ;
360 bool ok ( irange2 < idr2m ) ;
369 if(
ok ) dis.insert(
id ) ;
381 const EcalBarrelGeometry::OrderedListOfEEDetId*
382 EcalBarrelGeometry::getClosestEndcapCells(
EBDetId id )
const
384 OrderedListOfEEDetId* ptr (
nullptr ) ;
385 auto ptrVec = m_borderPtrVec.load(std::memory_order_acquire);
387 if( 0 !=
id.rawId() ) {
388 const int iPhi (
id.iphi() ) ;
389 const int iz (
id.ieta()>0 ? 1 : -1 ) ;
391 const int iq ( eeid.iquadrant() ) ;
392 const int xout ( 1==iq || 4==iq ? 1 : -1 ) ;
393 const int yout ( 1==iq || 2==iq ? 1 : -1 ) ;
394 if (!m_borderMgr.load(std::memory_order_acquire)) {
397 bool exchanged = m_borderMgr.compare_exchange_strong(expect, ptrMgr, std::memory_order_acq_rel);
398 if(!exchanged)
delete ptrMgr;
400 VecOrdListEEDetIdPtr* expect =
nullptr;
401 auto ptrVec =
new VecOrdListEEDetIdPtr();
402 ptrVec->reserve(720);
403 for(
unsigned int i ( 0 ) ;
i != 720 ; ++
i )
405 const int kz ( 360>
i ? -1 : 1 ) ;
408 const int jx ( eeid.ix() ) ;
409 const int jy ( eeid.iy() ) ;
411 OrderedListOfEEDetId& olist ( *
new OrderedListOfEEDetId( m_borderMgr.load(std::memory_order_acquire) ) );
414 for(
unsigned int k ( 1 ) ;
k <= 25 ; ++
k )
416 const int kx ( 1==
k || 2==
k || 3==
k || 12==
k || 13==
k ? 0 :
417 ( 4==
k || 6==
k || 8==
k || 15==
k || 20==
k ? 1 :
418 ( 5==
k || 7==
k || 9==
k || 16==
k || 19==
k ? -1 :
419 ( 10==
k || 14==
k || 21==
k || 22==
k || 25==
k ? 2 : -2 )))) ;
420 const int ky ( 1==
k || 4==
k || 5==
k || 10==
k || 11==
k ? 0 :
421 ( 2==
k || 6==
k || 7==
k || 14==
k || 17==
k ? 1 :
422 ( 3==
k || 8==
k || 9==
k || 18==
k || 21==
k ? -1 :
423 ( 12==
k || 15==
k || 16==
k || 22==
k || 23==
k ? 2 : -2 )))) ;
426 jy + ky*yout , kz ) )
428 olist[il++]=
EEDetId( jx + kx*xout, jy + ky*yout, kz ) ;
431 ptrVec->push_back( &olist ) ;
433 bool exchanged = m_borderPtrVec.compare_exchange_strong(expect, ptrVec, std::memory_order_acq_rel);
434 if(!exchanged)
delete ptrVec;
435 ptrVec = m_borderPtrVec.load(std::memory_order_acquire);
436 ptr = (*ptrVec)[iPhi - 1 + ( 0>iz ? 0 : 360 )];
443 EcalBarrelGeometry::localCorners(
Pt3DVec& lc ,
449 const bool odd ( 1 == i%2 ) ;
451 if( ( ( negz && !odd ) ||
454 TruncatedPyramid::localCornersReflection( lc, pv, ref ) ;
458 TruncatedPyramid::localCornersSwap( lc, pv, ref ) ;
469 const unsigned int cellIndex (
EBDetId( detId ).denseIndex() ) ;
470 m_cellVec[ cellIndex ] =
472 addValidID( detId ) ;
476 EcalBarrelGeometry::avgRadiusXYFrontFaceCenter()
const
478 if(!m_check.load(std::memory_order_acquire))
481 for( uint32_t i ( 0 ) ; i != m_cellVec.size() ; ++
i )
490 m_radius = sum/m_cellVec.size() ;
491 m_check.store(
true, std::memory_order_release);
497 EcalBarrelGeometry::cellGeomPtr( uint32_t
index )
const
500 return ( m_cellVec.size() < index ||
501 0 == cell->param() ? 0 : cell ) ;
std::set< DetId > DetIdSet
static const int MIN_IPHI
tuple start
Check for commandline option errors.
Geom::Phi< T > phi() const
std::vector< Pt3D > Pt3DVec
CaloGeometry const * getGeometry()
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.
Abs< T >::type abs(const T &t)
CaloCellGeometry::CCGFloat CCGFloat
int ieta() const
get the crystal ieta
static const int ETAPHIMODE
CaloCellGeometry::Pt3D Pt3D
static const int MAX_IPHI
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
static const int MAX_IETA
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...
static std::atomic< unsigned int > counter
static EEDetId idOuterRing(int iPhi, int zEnd)
static const int SMCRYSTALMODE
int ism(int ieta, int iphi)
*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