CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
EcalEndcapGeometry.cc
Go to the documentation of this file.
6 #include <CLHEP/Geometry/Point3D.h>
7 #include <CLHEP/Geometry/Plane3D.h>
8 
12 typedef HepGeom::Plane3D<CCGFloat> Pl3D ;
13 
15  : _nnmods( 316 ),
16  _nncrys( 25 ),
17  zeP( 0. ),
18  zeN( 0. ),
19  m_wref( 0. ),
20  m_del( 0. ),
21  m_nref( 0 ),
22  m_borderMgr( 0 ),
23  m_borderPtrVec( 0 ),
24  m_avgZ( -1 ),
25  m_cellVec( k_NumberOfCellsForCorners )
26 {
27  m_xlo[0] = 999.;
28  m_xlo[1] = 999.;
29  m_xhi[0] = -999.;
30  m_xhi[1] = -999.;
31  m_ylo[0] = 999.;
32  m_ylo[1] = 999.;
33  m_yhi[0] = -999.;
34  m_yhi[1] = -999.;
35  m_xoff[0] = 0.;
36  m_xoff[1] = 0.;
37  m_yoff[0] = 0.;
38  m_yoff[0] = 0.;
39 }
40 
42 {
43  delete m_borderPtrVec ;
44  delete m_borderMgr ;
45 }
46 
47 unsigned int
49 {
50  const CaloGenericDetId gid ( id ) ;
51 
52  assert( gid.isEE() ) ;
53  unsigned int index ( EEDetId(id).ix()/51 + ( EEDetId(id).zside()<0 ? 0 : 2 ) ) ;
54 
55  return index ;
56 }
57 
58 DetId
60 {
61  return EEDetId( 20 + 50*( iLoc%2 ), 50, 2*( iLoc/2 ) - 1 ) ;
62 }
63 
64 unsigned int
66 {
67  return (unsigned int)DetId::Ecal - 1 ;
68 }
69 
70 void
72 {
73  zeP=0.;
74  zeN=0.;
75  unsigned nP=0;
76  unsigned nN=0;
77  m_nref = 0 ;
78 
79  for( uint32_t i ( 0 ) ; i != m_cellVec.size() ; ++i )
80  {
81  const CaloCellGeometry* cell ( cellGeomPtr(i) ) ;
82  if( 0 != cell )
83  {
84  const CCGFloat z ( cell->getPosition().z() ) ;
85  if(z>0.)
86  {
87  zeP+=z;
88  ++nP;
89  }
90  else
91  {
92  zeN+=z;
93  ++nN;
94  }
95  const EEDetId myId ( EEDetId::detIdFromDenseIndex(i) ) ;
96  const unsigned int ix ( myId.ix() ) ;
97  const unsigned int iy ( myId.iy() ) ;
98  if( ix > m_nref ) m_nref = ix ;
99  if( iy > m_nref ) m_nref = iy ;
100  }
101  }
102  if( 0 < nP ) zeP/=(CCGFloat)nP;
103  if( 0 < nN ) zeN/=(CCGFloat)nN;
104 
105  m_xlo[0] = 999 ;
106  m_xhi[0] = -999 ;
107  m_ylo[0] = 999 ;
108  m_yhi[0] = -999 ;
109  m_xlo[1] = 999 ;
110  m_xhi[1] = -999 ;
111  m_ylo[1] = 999 ;
112  m_yhi[1] = -999 ;
113  for( uint32_t i ( 0 ) ; i != m_cellVec.size() ; ++i )
114  {
115  const CaloCellGeometry* cell ( cellGeomPtr(i) ) ;
116  if( 0 != cell )
117  {
118  const GlobalPoint p ( cell->getPosition() ) ;
119  const CCGFloat z ( p.z() ) ;
120  const CCGFloat zz ( 0 > z ? zeN : zeP ) ;
121  const CCGFloat x ( p.x()*zz/z ) ;
122  const CCGFloat y ( p.y()*zz/z ) ;
123 
124  if( 0 > z && x < m_xlo[0] ) m_xlo[0] = x ;
125  if( 0 < z && x < m_xlo[1] ) m_xlo[1] = x ;
126  if( 0 > z && y < m_ylo[0] ) m_ylo[0] = y ;
127  if( 0 < z && y < m_ylo[1] ) m_ylo[1] = y ;
128 
129  if( 0 > z && x > m_xhi[0] ) m_xhi[0] = x ;
130  if( 0 < z && x > m_xhi[1] ) m_xhi[1] = x ;
131  if( 0 > z && y > m_yhi[0] ) m_yhi[0] = y ;
132  if( 0 < z && y > m_yhi[1] ) m_yhi[1] = y ;
133  }
134  }
135 
136  m_xoff[0] = ( m_xhi[0] + m_xlo[0] )/2. ;
137  m_xoff[1] = ( m_xhi[1] + m_xlo[1] )/2. ;
138  m_yoff[0] = ( m_yhi[0] + m_ylo[0] )/2. ;
139  m_yoff[1] = ( m_yhi[1] + m_ylo[1] )/2. ;
140 
141  m_del = ( m_xhi[0] - m_xlo[0] + m_xhi[1] - m_xlo[1] +
142  m_yhi[0] - m_ylo[0] + m_yhi[1] - m_ylo[1] ) ;
143 
144  if( 1 != m_nref ) m_wref = m_del/(4.*(m_nref-1)) ;
145 
146  m_xlo[0] -= m_wref/2 ;
147  m_xlo[1] -= m_wref/2 ;
148  m_xhi[0] += m_wref/2 ;
149  m_xhi[1] += m_wref/2 ;
150 
151  m_ylo[0] -= m_wref/2 ;
152  m_ylo[1] -= m_wref/2 ;
153  m_yhi[0] += m_wref/2 ;
154  m_yhi[1] += m_wref/2 ;
155 
156  m_del += m_wref ;
157 /*
158  std::cout<<"zeP="<<zeP<<", zeN="<<zeN<<", nP="<<nP<<", nN="<<nN<<std::endl ;
159 
160  std::cout<<"xlo[0]="<<m_xlo[0]<<", xlo[1]="<<m_xlo[1]<<", xhi[0]="<<m_xhi[0]<<", xhi[1]="<<m_xhi[1]
161  <<"\nylo[0]="<<m_ylo[0]<<", ylo[1]="<<m_ylo[1]<<", yhi[0]="<<m_yhi[0]<<", yhi[1]="<<m_yhi[1]<<std::endl ;
162 
163  std::cout<<"xoff[0]="<<m_xoff[0]<<", xoff[1]"<<m_xoff[1]<<", yoff[0]="<<m_yoff[0]<<", yoff[1]"<<m_yoff[1]<<std::endl ;
164 
165  std::cout<<"nref="<<m_nref<<", m_wref="<<m_wref<<std::endl ;
166 */
167 }
168 
169 
170 unsigned int
172  CCGFloat z ) const
173 {
174  const CCGFloat xlo ( 0 > z ? m_xlo[0] : m_xlo[1] ) ;
175  const int i ( 1 + int( ( x - xlo )/m_wref ) ) ;
176 
177  return ( 1 > i ? 1 :
178  ( m_nref < (unsigned int) i ? m_nref : (unsigned int) i ) ) ;
179 
180 }
181 
182 unsigned int
184  CCGFloat z ) const
185 {
186  const CCGFloat ylo ( 0 > z ? m_ylo[0] : m_ylo[1] ) ;
187  const int i ( 1 + int( ( y - ylo )/m_wref ) ) ;
188 
189  return ( 1 > i ? 1 :
190  ( m_nref < (unsigned int) i ? m_nref : (unsigned int) i ) ) ;
191 }
192 
193 EEDetId
195  float y,
196  float z ) const
197 {
198  const CCGFloat fac ( fabs( ( 0 > z ? zeN : zeP )/z ) ) ;
199  const unsigned int ix ( xindex( x*fac, z ) ) ;
200  const unsigned int iy ( yindex( y*fac, z ) ) ;
201  const unsigned int iz ( z>0 ? 1 : -1 ) ;
202 
203  if( EEDetId::validDetId( ix, iy, iz ) )
204  {
205  return EEDetId( ix, iy, iz ) ; // first try is on target
206  }
207  else // try nearby coordinates, spiraling out from center
208  {
209  for( unsigned int i ( 1 ) ; i != 6 ; ++i )
210  {
211  for( unsigned int k ( 0 ) ; k != 8 ; ++k )
212  {
213  const int jx ( 0 == k || 4 == k || 5 == k ? +i :
214  ( 1 == k || 5 < k ? -i : 0 ) ) ;
215  const int jy ( 2 == k || 4 == k || 6 == k ? +i :
216  ( 3 == k || 5 == k || 7 == k ? -i : 0 ) ) ;
217  if( EEDetId::validDetId( ix + jx, iy + jy, iz ) )
218  {
219  return EEDetId( ix + jx, iy + jy, iz ) ;
220  }
221  }
222  }
223  }
224  return EEDetId() ; // nowhere near any crystal
225 }
226 
227 
228 // Get closest cell, etc...
229 DetId
231 {
232  try
233  {
234  EEDetId mycellID ( gId( r.x(), r.y(), r.z() ) ) ; // educated guess
235 
236  if( EEDetId::validDetId( mycellID.ix(),
237  mycellID.iy(),
238  mycellID.zside() ) )
239  {
240  // now get points in convenient ordering
241 
242  Pt3D A;
243  Pt3D B;
244  Pt3D C;
245  Pt3D point(r.x(),r.y(),r.z());
246  // D.K. : equation of plane : AA*x+BB*y+CC*z+DD=0;
247  // finding equation for each edge
248 
249  // ================================================================
250  CCGFloat x,y,z;
251  unsigned offset=0;
252  int zsign=1;
253  //================================================================
254  std::vector<CCGFloat> SS;
255 
256  // compute the distance of the point with respect of the 4 crystal lateral planes
257 
258 
259  if( 0 != getGeometry(mycellID) )
260  {
261  const GlobalPoint& myPosition=getGeometry(mycellID)->getPosition();
262 
263  x=myPosition.x();
264  y=myPosition.y();
265  z=myPosition.z();
266 
267  offset=0;
268  // This will disappear when Andre has applied his fix
269  zsign=1;
270 
271  if(z>0)
272  {
273  if(x>0&&y>0)
274  offset=1;
275  else if(x<0&&y>0)
276  offset=2;
277  else if(x>0&&y<0)
278  offset=0;
279  else if (x<0&&y<0)
280  offset=3;
281  zsign=1;
282  }
283  else
284  {
285  if(x>0&&y>0)
286  offset=3;
287  else if(x<0&&y>0)
288  offset=2;
289  else if(x>0&&y<0)
290  offset=0;
291  else if(x<0&&y<0)
292  offset=1;
293  zsign=-1;
294  }
295  std::vector<GlobalPoint> corners;
296  corners.clear();
297  corners.resize(8);
298  for(unsigned ic=0;ic<4;++ic)
299  {
300  corners[ic]=getGeometry(mycellID)->getCorners()[(unsigned)((zsign*ic+offset)%4)];
301  corners[4+ic]=getGeometry(mycellID)->getCorners()[(unsigned)(4+(zsign*ic+offset)%4)];
302  }
303 
304  for (short i=0; i < 4 ; ++i)
305  {
306  A = Pt3D(corners[i%4].x(),corners[i%4].y(),corners[i%4].z());
307  B = Pt3D(corners[(i+1)%4].x(),corners[(i+1)%4].y(),corners[(i+1)%4].z());
308  C = Pt3D(corners[4+(i+1)%4].x(),corners[4+(i+1)%4].y(),corners[4+(i+1)%4].z());
309  Pl3D plane(A,B,C);
310  plane.normalize();
311  CCGFloat distance = plane.distance(point);
312  if (corners[0].z()<0.) distance=-distance;
313  SS.push_back(distance);
314  }
315 
316  // Only one move in necessary direction
317 
318  const bool yout ( 0 > SS[0]*SS[2] ) ;
319  const bool xout ( 0 > SS[1]*SS[3] ) ;
320 
321  if( yout || xout )
322  {
323  const int ydel ( !yout ? 0 : ( 0 < SS[0] ? -1 : 1 ) ) ;
324  const int xdel ( !xout ? 0 : ( 0 < SS[1] ? -1 : 1 ) ) ;
325  const unsigned int ix ( mycellID.ix() + xdel ) ;
326  const unsigned int iy ( mycellID.iy() + ydel ) ;
327  const unsigned int iz ( mycellID.zside() ) ;
328  if( EEDetId::validDetId( ix, iy, iz ) )
329  mycellID = EEDetId( ix, iy, iz ) ;
330  }
331 
332  return mycellID;
333  }
334  return DetId(0);
335  }
336  }
337  catch ( cms::Exception &e )
338  {
339  return DetId(0);
340  }
341  return DetId(0);
342 }
343 
346  double dR ) const
347 {
348  CaloSubdetectorGeometry::DetIdSet dis ; // return object
349  if( 0.000001 < dR )
350  {
351  if( dR > M_PI/2. ) // this code assumes small dR
352  {
353  dis = CaloSubdetectorGeometry::getCells( r, dR ) ; // base class version
354  }
355  else
356  {
357  const double dR2 ( dR*dR ) ;
358  const double reta ( r.eta() ) ;
359  const double rphi ( r.phi() ) ;
360  const double rx ( r.x() ) ;
361  const double ry ( r.y() ) ;
362  const double rz ( r.z() ) ;
363  const double fac ( fabs( zeP/rz ) ) ;
364  const double xx ( rx*fac ) ; // xyz at endcap z
365  const double yy ( ry*fac ) ;
366  const double zz ( rz*fac ) ;
367 
368  const double xang ( atan( xx/zz ) ) ;
369  const double lowX ( zz>0 ? zz*tan( xang - dR ) : zz*tan( xang + dR ) ) ;
370  const double highX ( zz>0 ? zz*tan( xang + dR ) : zz*tan( xang - dR ) ) ;
371  const double yang ( atan( yy/zz ) ) ;
372  const double lowY ( zz>0 ? zz*tan( yang - dR ) : zz*tan( yang + dR ) ) ;
373  const double highY ( zz>0 ? zz*tan( yang + dR ) : zz*tan( yang - dR ) ) ;
374 
375  const double refxlo ( 0 > rz ? m_xlo[0] : m_xlo[1] ) ;
376  const double refxhi ( 0 > rz ? m_xhi[0] : m_xhi[1] ) ;
377  const double refylo ( 0 > rz ? m_ylo[0] : m_ylo[1] ) ;
378  const double refyhi ( 0 > rz ? m_yhi[0] : m_yhi[1] ) ;
379 
380  if( lowX < refxhi && // proceed if any possible overlap with the endcap
381  lowY < refyhi &&
382  highX > refxlo &&
383  highY > refylo )
384  {
385  const int ix_ctr ( xindex( xx, rz ) ) ;
386  const int iy_ctr ( yindex( yy, rz ) ) ;
387  const int iz ( rz>0 ? 1 : -1 ) ;
388 
389  const int ix_hi ( ix_ctr + int( ( highX - xx )/m_wref ) + 2 ) ;
390  const int ix_lo ( ix_ctr - int( ( xx - lowX )/m_wref ) - 2 ) ;
391 
392  const int iy_hi ( iy_ctr + int( ( highY - yy )/m_wref ) + 2 ) ;
393  const int iy_lo ( iy_ctr - int( ( yy - lowY )/m_wref ) - 2 ) ;
394 
395  for( int kx ( ix_lo ) ; kx <= ix_hi ; ++kx )
396  {
397  if( kx > 0 &&
398  kx <= (int) m_nref )
399  {
400  for( int ky ( iy_lo ) ; ky <= iy_hi ; ++ky )
401  {
402  if( ky > 0 &&
403  ky <= (int) m_nref )
404  {
405  if( EEDetId::validDetId( kx, ky, iz ) ) // reject invalid ids
406  {
407  const EEDetId id ( kx, ky, iz ) ;
408  const CaloCellGeometry* cell ( getGeometry( id ) );
409  if( 0 != cell )
410  {
411  const GlobalPoint& p ( cell->getPosition() ) ;
412  const double eta ( p.eta() ) ;
413  const double phi ( p.phi() ) ;
414  if( reco::deltaR2( eta, phi, reta, rphi ) < dR2 ) dis.insert( id ) ;
415  }
416  }
417  }
418  }
419  }
420  }
421  }
422  }
423  }
424  return dis;
425 }
426 
429 {
430  OrderedListOfEBDetId* ptr ( 0 ) ;
431  if( 0 != id.rawId() &&
432  0 != getGeometry( id ) )
433  {
434  const float phi ( 370. +
435  getGeometry( id )->getPosition().phi().degrees() );
436  const int iPhi ( 1 + int(phi)%360 ) ;
437  const int iz ( id.zside() ) ;
438  if( 0 == m_borderMgr )
439  {
440  m_borderMgr = new EZMgrFL<EBDetId>( 720*9, 9 ) ;
441  }
442  if( 0 == m_borderPtrVec )
443  {
445  m_borderPtrVec->reserve( 720 ) ;
446  for( unsigned int i ( 0 ) ; i != 720 ; ++i )
447  {
448  const int kz ( 360>i ? -1 : 1 ) ;
449  const int iEta ( kz*85 ) ;
450  const int iEtam1 ( kz*84 ) ;
451  const int iEtam2 ( kz*83 ) ;
452  const int jPhi ( i%360 + 1 ) ;
454  olist[0]=EBDetId( iEta , jPhi ) ;
455  olist[1]=EBDetId( iEta , myPhi( jPhi+1 ) ) ;
456  olist[2]=EBDetId( iEta , myPhi( jPhi-1 ) ) ;
457  olist[3]=EBDetId( iEtam1, jPhi ) ;
458  olist[4]=EBDetId( iEtam1, myPhi( jPhi+1 ) ) ;
459  olist[5]=EBDetId( iEtam1, myPhi( jPhi-1 ) ) ;
460  olist[6]=EBDetId( iEta , myPhi( jPhi+2 ) ) ;
461  olist[7]=EBDetId( iEta , myPhi( jPhi-2 ) ) ;
462  olist[8]=EBDetId( iEtam2, jPhi ) ;
463  m_borderPtrVec->push_back( &olist ) ;
464  }
465  }
466  ptr = (*m_borderPtrVec)[ ( iPhi - 1 ) + ( 0>iz ? 0 : 360 ) ] ;
467  }
468  return ptr ;
469 }
470 
471 void
473  const CCGFloat* pv ,
474  unsigned int /*i*/,
475  Pt3D& ref )
476 {
477  TruncatedPyramid::localCorners( lc, pv, ref ) ;
478 }
479 
480 void
482  const GlobalPoint& f2 ,
483  const GlobalPoint& f3 ,
484  const CCGFloat* parm ,
485  const DetId& detId )
486 {
487  const unsigned int cellIndex ( EEDetId( detId ).denseIndex() ) ;
488  m_cellVec[ cellIndex ] =
489  TruncatedPyramid( cornersMgr(), f1, f2, f3, parm ) ;
490  m_validIds.push_back( detId ) ;
491 }
492 
493 
494 CCGFloat
496 {
497  if( 0 > m_avgZ )
498  {
499  CCGFloat sum ( 0 ) ;
500  for( unsigned int i ( 0 ) ; i != m_cellVec.size() ; ++i )
501  {
502  const CaloCellGeometry* cell ( cellGeomPtr(i) ) ;
503  if( 0 != cell )
504  {
505  sum += fabs( cell->getPosition().z() ) ;
506  }
507  }
508  m_avgZ = sum/m_cellVec.size() ;
509  }
510  return m_avgZ ;
511 }
512 
513 const CaloCellGeometry*
515 {
516  const CaloCellGeometry* cell ( &m_cellVec[ index ] ) ;
517  return ( m_cellVec.size() < index ||
518  0 == cell->param() ? 0 : cell ) ;
519 }
static EEDetId detIdFromDenseIndex(uint32_t din)
Definition: EEDetId.h:215
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
virtual DetId getClosestCell(const GlobalPoint &r) const
double degrees(double radiants)
def degrees
int i
Definition: DBlmapReader.cc:9
tuple nN
people filling error matrix uses the naive 1/sqrt(N) errors
int ix() const
Definition: EEDetId.h:71
static void localCorners(Pt3DVec &lc, const CCGFloat *pv, unsigned int i, Pt3D &ref)
double_binary B
Definition: DDStreamer.cc:234
CaloCellGeometry::Pt3D Pt3D
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
T y() const
Definition: PV3DBase.h:62
VecOrdListEBDetIdPtr * m_borderPtrVec
virtual void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
std::vector< Pt3D > Pt3DVec
T eta() const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
static unsigned int alignmentTransformIndexGlobal(const DetId &id)
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const
CaloCellGeometry::CCGFloat CCGFloat
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.cc:562
double double double z
CCGFloat avgAbsZFrontFaceCenter() const
virtual CaloSubdetectorGeometry::DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
virtual const CaloCellGeometry * getGeometry(const DetId &id) const
Get the cell geometry of a given detector id. Should return false if not found.
static unsigned int alignmentTransformIndexLocal(const DetId &id)
const CCGFloat * param() const
HepGeom::Plane3D< CCGFloat > Pl3D
unsigned int yindex(CCGFloat y, CCGFloat z) const
CaloCellGeometry::CCGFloat CCGFloat
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
CaloCellGeometry::Pt3DVec Pt3DVec
EZMgrFL< EBDetId > * m_borderMgr
std::vector< DetId > m_validIds
T z() const
Definition: PV3DBase.h:63
int zside() const
Definition: EEDetId.h:65
Tan< T >::type tan(const T &t)
Definition: Tan.h:22
std::vector< OrderedListOfEBDetId * > VecOrdListEBDetIdPtr
CaloCellGeometry::CCGFloat CCGFloat
int iy() const
Definition: EEDetId.h:77
const OrderedListOfEBDetId * getClosestBarrelCells(EEDetId id) const
virtual void initializeParms()
unsigned int offset(bool)
double deltaR2(double eta1, double phi1, double eta2, double phi2)
Definition: deltaR.h:13
int k[5][pyjets_maxn]
CaloCellGeometry::Pt3D Pt3D
unsigned int xindex(CCGFloat x, CCGFloat z) const
Definition: DetId.h:20
#define M_PI
Definition: BFit3D.cc:3
static int myPhi(int i)
CaloCellGeometry::CornersMgr * cornersMgr()
bool isEE() const
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Point3D< CCGFloat > Pt3D
A base class to handle the particular shape of Ecal Xtals. Taken from ORCA Calorimetry Code...
T eta() const
Definition: PV3DBase.h:75
EZArrayFL< EBDetId > OrderedListOfEBDetId
static DetId detIdFromLocalAlignmentIndex(unsigned int iLoc)
Definition: DDAxes.h:10
EEDetId gId(float x, float y, float z) const
T x() const
Definition: PV3DBase.h:61
*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
Definition: invegas.h:5
virtual const CornersVec & getCorners() const =0
Returns the corner points of this cell&#39;s volume.
Definition: DDAxes.h:10