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