CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalGeometry.cc
Go to the documentation of this file.
5 #include <algorithm>
6 
10 
12  theTopology ( new HcalTopology ),
13  m_ownsTopology ( true )
14 {
15  init() ;
16 }
17 
19  theTopology ( topology ) ,
20  m_ownsTopology ( false )
21 {
22  init() ;
23 }
24 
25 
27 {
28  if( m_ownsTopology ) delete theTopology ;
29 }
30 
31 
32 void
34 {
39 }
40 
41 void
43 {
44  const std::vector<DetId>& baseIds ( CaloSubdetectorGeometry::getValidDetIds() ) ;
45  for( unsigned int i ( 0 ) ; i != baseIds.size() ; ++i )
46  {
47  const DetId id ( baseIds[i] );
48  if( id.subdetId() == HcalBarrel )
49  {
50  m_hbIds.push_back( id ) ;
51  }
52  else
53  {
54  if( id.subdetId() == HcalEndcap )
55  {
56  m_heIds.push_back( id ) ;
57  }
58  else
59  {
60  if( id.subdetId() == HcalOuter )
61  {
62  m_hoIds.push_back( id ) ;
63  }
64  else
65  {
66  if( id.subdetId() == HcalForward )
67  {
68  m_hfIds.push_back( id ) ;
69  }
70  }
71  }
72  }
73  }
74  std::sort( m_hbIds.begin(), m_hbIds.end() ) ;
75  std::sort( m_heIds.begin(), m_heIds.end() ) ;
76  std::sort( m_hoIds.begin(), m_hoIds.end() ) ;
77  std::sort( m_hfIds.begin(), m_hfIds.end() ) ;
78  m_emptyIds.resize( 0 ) ;
79 }
80 
81 const std::vector<DetId>&
83  int subdet ) const
84 {
85  if( 0 != subdet &&
86  0 == m_hbIds.size() ) fillDetIds() ;
87  return ( 0 == subdet ? CaloSubdetectorGeometry::getValidDetIds() :
88  ( HcalBarrel == subdet ? m_hbIds :
89  ( HcalEndcap == subdet ? m_heIds :
90  ( HcalOuter == subdet ? m_hoIds :
91  ( HcalForward == subdet ? m_hfIds : m_emptyIds ) ) ) ) ) ;
92 }
93 
95 
96  // Now find the closest eta_bin, eta value of a bin i is average
97  // of eta[i] and eta[i-1]
98  double abseta = fabs(r.eta());
99 
100  // figure out subdetector, giving preference to HE in HE/HF overlap region
102  if (abseta <= theHBHEEtaBounds[theTopology->lastHBRing()] ) {
103  bc = HcalBarrel;
104  } else if (abseta <= theHBHEEtaBounds[theTopology->lastHERing()] ) {
105  bc = HcalEndcap;
106  } else {
107  bc = HcalForward;
108  }
109 
110  if (bc == HcalForward) {
111  static const double z_short=1137.0;
112  int etaring = etaRing(bc, abseta); // This is safer
113  /*
114  static const double z_long=1115.0;
115  // determine front-face eta
116  double radius=sqrt(pow(r.x(),2)+pow(r.y(),2));
117  double trueAeta=asinh(z_long/radius);
118  // find eta bin
119  int etaring = etaRing(bc, trueAeta);
120  */
121  if (etaring>theTopology->lastHFRing()) etaring=theTopology->lastHFRing();
122 
123  int phibin = phiBin(r.phi(), etaring);
124 
125  // add a sign to the etaring
126  int etabin = (r.z() > 0) ? etaring : -etaring;
127  // Next line is premature depth 1 and 2 can coexist for large z-extent
128 
129 // HcalDetId bestId(bc,etabin,phibin,((fabs(r.z())>=z_short)?(2):(1)));
130 // above line is no good with finite precision
131  HcalDetId bestId(bc,etabin,phibin,((fabs(r.z()) - z_short >-0.1)?(2):(1)));
132  return bestId;
133  } else {
134 
135  // find eta bin
136  int etaring = etaRing(bc, abseta);
137 
138  int phibin = phiBin(r.phi(), etaring);
139 
140  // add a sign to the etaring
141  int etabin = (r.z() > 0) ? etaring : -etaring;
142 
143  //Now do depth if required
144  int dbin = 1;
145  double pointrz=0, drz=99999.;
146  HcalDetId currentId(bc, etabin, phibin, dbin);
147  if (bc == HcalBarrel) pointrz = r.mag();
148  else pointrz = std::abs(r.z());
149  HcalDetId bestId;
150  for ( ; currentId != HcalDetId(); theTopology->incrementDepth(currentId)) {
151  const CaloCellGeometry * cell = getGeometry(currentId);
152  assert(cell != 0);
153  double rz;
154  if (bc == HcalEndcap) rz = std::abs(cell->getPosition().z());
155  else rz = cell->getPosition().mag();
156  if (std::abs(pointrz-rz)<drz) {
157  bestId = currentId;
158  drz = std::abs(pointrz-rz);
159  }
160  }
161 
162  return bestId;
163  }
164 }
165 
166 
167 int HcalGeometry::etaRing(HcalSubdetector bc, double abseta) const
168 {
169  int etaring;
170  if( bc == HcalForward ) {
171  for(etaring = theTopology->firstHFRing();
172  etaring <= theTopology->lastHFRing(); ++etaring)
173  {
174  if(theHFEtaBounds[etaring-theTopology->firstHFRing()+1] > abseta) break;
175  }
176  }
177  else
178  {
179  for(etaring = 1;
180  etaring <= theTopology->lastHERing(); ++etaring)
181  {
182  if(theHBHEEtaBounds[etaring] >= abseta) break;
183  }
184  }
185 
186  return etaring;
187 }
188 
189 
190 int HcalGeometry::phiBin(double phi, int etaring) const
191 {
192  static const double twopi = M_PI+M_PI;
193  //put phi in correct range (0->2pi)
194  if(phi<0.0) phi += twopi;
195  if(phi>twopi) phi -= twopi;
196  int nphibins = theTopology->nPhiBins(etaring);
197  int phibin= static_cast<int>(phi/twopi*nphibins)+1;
198  int iphi;
199 
200  // rings 40 and 41 are offset wrt the other phi numbering
201  // 1 1 1 2
202  // ------------------------------
203  // 72 36 36 1
204  if(etaring >= theTopology->firstHFQuadPhiRing())
205  {
206  phi+=(twopi/36); //shift by half tower.
207  phibin=static_cast<int>(phi/twopi*nphibins);
208  if (phibin==0) phibin=18;
209  iphi=phibin*4-1; // 71,3,5,
210  } else {
211  // convert to the convention of numbering 1,3,5, in 36 phi bins
212  iphi=(phibin-1)*(72/nphibins) + 1;
213  }
214 
215  return iphi;
216 }
217 
220  double dR ) const
221 {
222  CaloSubdetectorGeometry::DetIdSet dis; // this is the return object
223 
224  if( 0.000001 < dR )
225  {
226  if( dR > M_PI/2. ) // this version needs "small" dR
227  {
228  dis = CaloSubdetectorGeometry::getCells( r, dR ) ; // base class version
229  }
230  else
231  {
232  const double dR2 ( dR*dR ) ;
233  const double reta ( r.eta() ) ;
234  const double rphi ( r.phi() ) ;
235  const double lowEta ( reta - dR ) ;
236  const double highEta ( reta + dR ) ;
237  const double lowPhi ( rphi - dR ) ;
238  const double highPhi ( rphi + dR ) ;
239 
240  const double hfEtaHi ( theHFEtaBounds[ theTopology->lastHFRing() -
241  theTopology->firstHFRing() + 1 ] ) ;
242 
243  if( highEta > -hfEtaHi &&
244  lowEta < hfEtaHi ) // in hcal
245  {
247 
248  for( unsigned int is ( 0 ) ; is != 4 ; ++is )
249  {
250  const int sign ( reta>0 ? 1 : -1 ) ;
251  const int ieta_center ( sign*etaRing( hs[is], fabs( reta ) ) ) ;
252  const int ieta_lo ( ( 0 < lowEta*sign ? sign : -sign )*etaRing( hs[is], fabs( lowEta ) ) ) ;
253  const int ieta_hi ( ( 0 < highEta*sign ? sign : -sign )*etaRing( hs[is], fabs( highEta ) ) ) ;
254  const int iphi_lo ( phiBin( lowPhi , ieta_center ) ) ;
255  const int iphi_hi ( phiBin( highPhi, ieta_center ) ) ;
256  const int jphi_lo ( iphi_lo>iphi_hi ? iphi_lo - 72 : iphi_lo ) ;
257  const int jphi_hi ( iphi_hi ) ;
258 
259  const int idep_lo ( 1 == is ? 4 : 1 ) ;
260  const int idep_hi ( 1 == is ? 4 :
261  ( 2 == is ? 3 : 2 ) ) ;
262  for( int ieta ( ieta_lo ) ; ieta <= ieta_hi ; ++ieta ) // over eta limits
263  {
264  if( ieta != 0 )
265  {
266  for( int jphi ( jphi_lo ) ; jphi <= jphi_hi ; ++jphi ) // over phi limits
267  {
268  const int iphi ( 1 > jphi ? jphi+72 : jphi ) ;
269 
270  for( int idep ( idep_lo ) ; idep <= idep_hi ; ++idep )
271  {
272  if( HcalDetId::validDetId( hs[is], ieta, iphi, idep ) )
273  {
274  const HcalDetId did ( hs[is], ieta, iphi, idep ) ;
275  const CaloCellGeometry* cell ( getGeometry( did ) );
276  if( 0 != cell )
277  {
278  const GlobalPoint& p ( cell->getPosition() ) ;
279  const double eta ( p.eta() ) ;
280  const double phi ( p.phi() ) ;
281  if( reco::deltaR2( eta, phi, reta, rphi ) < dR2 ) dis.insert( did ) ;
282  }
283  }
284  }
285  }
286  }
287  }
288  }
289  }
290  }
291  }
292  return dis;
293 }
294 
295 
296 unsigned int
298 {
299  const CaloGenericDetId gid ( id ) ;
300 
301  assert( gid.isHcal() ) ;
302 
303 
304  const HcalDetId hid ( id ) ;
305 
306  const int jz ( ( hid.zside() + 1 )/2 ) ;
307 
308  const int zoff ( jz*numberOfAlignments()/2 ) ;
309 
310  const int detoff ( zoff +
311  ( gid.isHB() ? 0 :
312  ( gid.isHE() ? numberOfBarrelAlignments()/2 :
313  ( gid.isHF() ? ( numberOfBarrelAlignments() +
317  numberOfForwardAlignments() )/2 ) ) ) ) ;
318 
319  const int iphi ( hid.iphi() ) ;
320 
321  unsigned int index ( numberOfAlignments() ) ;
322  if( gid.isHO() )
323  {
324  const int ieta ( hid.ieta() ) ;
325  const int ring ( ieta < -10 ? 0 :
326  ( ieta < -4 ? 1 :
327  ( ieta < 5 ? 2 :
328  ( ieta < 11 ? 3 : 4 ) ) ) ) ;
329 
330  index = detoff + 12*ring + ( iphi - 1 )%6 ;
331  }
332  else
333  {
334  index = detoff + ( iphi - 1 )%4 ;
335  }
336 
337  assert( index < numberOfAlignments() ) ;
338  return index ;
339 }
340 
341 unsigned int
343 {
344  return (unsigned int)DetId::Hcal - 1 ;
345 }
346 
347 void
349  const CCGFloat* pv ,
350  unsigned int i ,
351  Pt3D& ref )
352 {
353  const HcalDetId hid ( HcalDetId::detIdFromDenseIndex( i ) ) ;
354  const CaloGenericDetId cgid ( hid ) ;
355  if( cgid.isHF() )
356  {
357  IdealZPrism::localCorners( lc, pv, ref ) ;
358  }
359  else
360  {
361  IdealObliquePrism::localCorners( lc, pv, ref ) ;
362  }
363 }
364 
365 void
367  const GlobalPoint& f2 ,
368  const GlobalPoint& f3 ,
369  const CCGFloat* parm ,
370  const DetId& detId )
371 {
372  const CaloGenericDetId cgid ( detId ) ;
373 
374  const unsigned int din ( cgid.denseIndex() ) ;
375 
376  assert( cgid.isHcal() ) ;
377 
378  if( cgid.isHB() )
379  {
380  m_hbCellVec[ din ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
381  }
382  else
383  {
384  if( cgid.isHE() )
385  {
386  const unsigned int index ( din - m_hbCellVec.size() ) ;
387  m_heCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
388  }
389  else
390  {
391  if( cgid.isHO() )
392  {
393  const unsigned int index ( din
394  - m_hbCellVec.size()
395  - m_heCellVec.size() ) ;
396  m_hoCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
397  }
398  else
399  {
400  const unsigned int index ( din
401  - m_hbCellVec.size()
402  - m_heCellVec.size()
403  - m_hoCellVec.size() ) ;
404  m_hfCellVec[ index ] = IdealZPrism( f1, cornersMgr(), parm ) ;
405  }
406  }
407  }
408  m_validIds.push_back( detId ) ;
409 }
410 
411 const CaloCellGeometry*
413 {
414  const CaloCellGeometry* cell ( 0 ) ;
415  if( m_hbCellVec.size() > din )
416  {
417  cell = &m_hbCellVec[ din ] ;
418  }
419  else
420  {
421  if( m_hbCellVec.size() +
422  m_heCellVec.size() > din )
423  {
424  const unsigned int index ( din - m_hbCellVec.size() ) ;
425  cell = &m_heCellVec[ index ] ;
426  }
427  else
428  {
429  if( m_hbCellVec.size() +
430  m_heCellVec.size() +
431  m_hoCellVec.size() > din )
432  {
433  const unsigned int index ( din
434  - m_hbCellVec.size()
435  - m_heCellVec.size() ) ;
436  cell = &m_hoCellVec[ index ] ;
437  }
438  else
439  {
440  if( m_hbCellVec.size() +
441  m_heCellVec.size() +
442  m_hoCellVec.size() +
443  m_hfCellVec.size() > din )
444  {
445  const unsigned int index ( din
446  - m_hbCellVec.size()
447  - m_heCellVec.size()
448  - m_hoCellVec.size() ) ;
449  cell = &m_hfCellVec[ index ] ;
450  }
451  }
452  }
453  }
454  return ( 0 == cell || 0 == cell->param() ? 0 : cell ) ;
455 }
static unsigned int numberOfBarrelAlignments()
Definition: HcalGeometry.h:61
int firstHFRing() const
Definition: HcalTopology.h:65
std::vector< DetId > m_heIds
Definition: HcalGeometry.h:107
virtual void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
int i
Definition: DBlmapReader.cc:9
virtual DetId getClosestCell(const GlobalPoint &r) const
Definition: HcalGeometry.cc:94
static unsigned int alignmentTransformIndexLocal(const DetId &id)
bool isHE() const
std::vector< DetId > m_emptyIds
Definition: HcalGeometry.h:110
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
int nPhiBins(int etaRing) const
how many phi segments in this ring
#define abs(x)
Definition: mlp_lapack.h:159
int lastHBRing() const
Definition: HcalTopology.h:62
std::vector< IdealObliquePrism > HECellVec
Definition: HcalGeometry.h:17
std::vector< Pt3D > Pt3DVec
T eta() const
const GlobalPoint & getPosition() const
Returns the position of reference for this cell.
CaloCellGeometry::CCGFloat CCGFloat
const HcalTopology * theTopology
Definition: HcalGeometry.h:104
static bool validDetId(HcalSubdetector subdet, int tower_ieta, int tower_iphi, int depth)
Definition: HcalDetId.cc:70
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)
Definition: HcalGeometry.cc:82
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 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.
const CCGFloat * param() const
std::vector< DetId > m_hbIds
Definition: HcalGeometry.h:106
CaloCellGeometry::Pt3DVec Pt3DVec
Definition: HcalGeometry.h:23
std::vector< DetId > m_hoIds
Definition: HcalGeometry.h:108
virtual DetIdSet getCells(const GlobalPoint &r, double dR) const
Get a list of all cells within a dR of the given cell.
T mag() const
Definition: PV3DBase.h:66
HBCellVec m_hbCellVec
Definition: HcalGeometry.h:113
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const
HOCellVec m_hoCellVec
Definition: HcalGeometry.h:115
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
HFCellVec m_hfCellVec
Definition: HcalGeometry.h:116
static HcalDetId detIdFromDenseIndex(uint32_t di)
Definition: HcalDetId.cc:155
std::vector< DetId > m_validIds
std::vector< IdealObliquePrism > HOCellVec
Definition: HcalGeometry.h:18
T z() const
Definition: PV3DBase.h:63
int lastHFRing() const
Definition: HcalTopology.h:66
static unsigned int alignmentTransformIndexGlobal(const DetId &id)
bool m_ownsTopology
Definition: HcalGeometry.h:111
HcalSubdetector
Definition: HcalAssistant.h:32
CaloCellGeometry::CCGFloat CCGFloat
std::vector< DetId > m_hfIds
Definition: HcalGeometry.h:109
bool isHcal() const
int etaRing(HcalSubdetector bc, double abseta) const
helper methods for getClosestCell
double deltaR2(double eta1, double phi1, double eta2, double phi2)
Definition: deltaR.h:13
static void localCorners(Pt3DVec &lc, const CCGFloat *pv, unsigned int i, Pt3D &ref)
uint32_t denseIndex() const
CaloCellGeometry::Pt3D Pt3D
std::vector< IdealZPrism > HFCellVec
Definition: HcalGeometry.h:19
Definition: DetId.h:20
bool incrementDepth(HcalDetId &id) const
static unsigned int numberOfEndcapAlignments()
Definition: HcalGeometry.h:63
#define M_PI
Definition: BFit3D.cc:3
static const double theHFEtaBounds[]
bool isHF() const
virtual ~HcalGeometry()
The HcalGeometry will delete all its cell geometries at destruction time.
Definition: HcalGeometry.cc:26
CaloCellGeometry::CornersMgr * cornersMgr()
Detector
Definition: DetId.h:26
static void localCorners(Pt3DVec &vec, const CCGFloat *pv, Pt3D &ref)
Definition: IdealZPrism.cc:103
CaloCellGeometry::Pt3DVec Pt3DVec
HepGeom::Point3D< CCGFloat > Pt3D
std::vector< IdealObliquePrism > HBCellVec
Definition: HcalGeometry.h:16
int firstHFQuadPhiRing() const
Definition: HcalTopology.h:71
HECellVec m_heCellVec
Definition: HcalGeometry.h:114
T eta() const
Definition: PV3DBase.h:75
void fillDetIds() const
Definition: HcalGeometry.cc:42
static unsigned int numberOfForwardAlignments()
Definition: HcalGeometry.h:67
bool isHO() const
bool isHB() const
CaloCellGeometry::Pt3D Pt3D
Definition: HcalGeometry.h:22
static const double theHBHEEtaBounds[]
int phiBin(double phi, int etaring) const
static unsigned int numberOfAlignments()
Definition: HcalGeometry.h:69
int lastHERing() const
Definition: HcalTopology.h:64
Definition: DDAxes.h:10