CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HcalDDDGeometry.cc
Go to the documentation of this file.
5 
6 #include <algorithm>
7 
8 //#define DebugLog
9 
11  lastReqDet_(DetId::Detector(0)),
12  lastReqSubdet_(0),
13  etaMax_(0),
14  firstHFQuadRing_(40) ,
15  m_hbCellVec ( topo.getHBSize() ) ,
16  m_heCellVec ( topo.getHESize() ) ,
17  m_hoCellVec ( topo.getHOSize() ) ,
18  m_hfCellVec ( topo.getHFSize() )
19 {
20  twopi = M_PI + M_PI;
21  deg = M_PI/180.;
22 }
23 
24 
26 {
27 }
28 
29 
30 std::vector<DetId> const & HcalDDDGeometry::getValidDetIds(DetId::Detector det,
31  int subdet) const {
32 
33  const std::vector<DetId>& baseIds(CaloSubdetectorGeometry::getValidDetIds());
34  if (det == DetId::Detector( 0 ) && subdet == 0) {
35  return baseIds ;
36  }
37 
38  if (lastReqDet_ != det || lastReqSubdet_ != subdet ) {
39  lastReqDet_ = det ;
40  lastReqSubdet_ = subdet ;
41  m_validIds.clear();
42  m_validIds.reserve( baseIds.size() ) ;
43  }
44 
45  if (m_validIds.empty() ) {
46  for (unsigned int i = 0 ; i != baseIds.size() ; ++i ) {
47  const DetId id ( baseIds[i] );
48  if (id.det() == det && id.subdetId() == subdet ) {
49  m_validIds.push_back( id ) ;
50  }
51  }
52  std::sort(m_validIds.begin(),m_validIds.end());
53  }
54 
55 #ifdef DebugLog
56  LogDebug("HCalGeom") << "HcalDDDGeometry::getValidDetIds: "
57  << m_validIds.size() << " valid IDs found for detector "
58  << det << " Sub-detector " << subdet;
59 #endif
60  return m_validIds;
61 }
62 
63 
65 
66  // Now find the closest eta_bin, eta value of a bin i is average
67  // of eta[i] and eta[i-1]
68  double abseta = fabs(r.eta());
69  double phi = r.phi();
70  if (phi < 0) phi += twopi;
71  double radius = r.mag();
72  double z = fabs(r.z());
73 #ifdef DebugLog
74  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta "
75  << r.eta() << " phi " << phi/deg << " z " << r.z()
76  << " radius " << radius;
77 #endif
78 
79  HcalDetId bestId;
80  if (abseta <= etaMax_) {
81  for (unsigned int i=0; i<hcalCells_.size(); i++) {
82  if (abseta >=hcalCells_[i].etaMin() && abseta <=hcalCells_[i].etaMax()) {
83  HcalSubdetector bc = hcalCells_[i].detType();
84  int etaring = hcalCells_[i].etaBin();
85  int phibin = 0;
86  if (hcalCells_[i].unitPhi() == 4) {
87  // rings 40 and 41 are offset wrt the other phi numbering
88  // 1 1 1 2
89  // ------------------------------
90  // 72 36 36 1
91  phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset()+
92  0.5*hcalCells_[i].phiBinWidth())/
93  hcalCells_[i].phiBinWidth());
94  if (phibin == 0) phibin = hcalCells_[i].nPhiBins();
95  phibin = phibin*4 - 1;
96  } else {
97  phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset())/
98  hcalCells_[i].phiBinWidth()) + 1;
99  // convert to the convention of numbering 1,3,5, in 36 phi bins
100  phibin = (phibin-1)*(hcalCells_[i].unitPhi()) + 1;
101  }
102 
103  int dbin = 1;
104  int etabin = (r.z() > 0) ? etaring : -etaring;
105  if (bc == HcalForward) {
106  bestId = HcalDetId(bc, etabin, phibin, dbin);
107  break;
108  } else {
109  double rz = z;
110  if (hcalCells_[i].depthType()) rz = radius;
111  if (rz < hcalCells_[i].depthMax()) {
112  dbin = hcalCells_[i].depthSegment();
113  bestId = HcalDetId(bc, etabin, phibin, dbin);
114  break;
115  }
116  }
117  }
118  }
119  }
120 #ifdef DebugLog
121  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
122 #endif
123  return bestId;
124 }
125 
126 
127 int HcalDDDGeometry::insertCell(std::vector<HcalCellType> const & cells){
128 
129  hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
130  int num = static_cast<int>(hcalCells_.size());
131  for (unsigned int i=0; i<cells.size(); i++) {
132  if (cells[i].etaMax() > etaMax_ ) etaMax_ = cells[i].etaMax();
133  }
134 #ifdef DebugLog
135  LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size()
136  << " cells inserted == Total " << num
137  << " EtaMax = " << etaMax_;
138 #endif
139  return num;
140 }
141 
142 void
144  const GlobalPoint& f2 ,
145  const GlobalPoint& f3 ,
146  const CCGFloat* parm ,
147  const DetId& detId )
148 {
149 
150  assert( detId.det()==DetId::Hcal );
151 
152  const unsigned int din(topo_.detId2denseId(detId));
153 
154  HcalDetId hId(detId);
155 
156  if( hId.subdet()==HcalBarrel )
157  {
158  m_hbCellVec[ din ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
159  }
160  else
161  {
162  if( hId.subdet()==HcalEndcap )
163  {
164  const unsigned int index ( din - m_hbCellVec.size() ) ;
165  m_heCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
166  }
167  else
168  {
169  if( hId.subdet()==HcalOuter )
170  {
171  const unsigned int index ( din
172  - m_hbCellVec.size()
173  - m_heCellVec.size() ) ;
174  m_hoCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
175  }
176  else
177  { // assuming HcalForward here!
178  const unsigned int index ( din
179  - m_hbCellVec.size()
180  - m_heCellVec.size()
181  - m_hoCellVec.size() ) ;
182  m_hfCellVec[ index ] = IdealZPrism( f1, cornersMgr(), parm ) ;
183  }
184  }
185  }
186  m_validIds.push_back( detId ) ;
187 }
188 
189 const CaloCellGeometry*
191 {
192  const CaloCellGeometry* cell ( 0 ) ;
193  if( m_hbCellVec.size() > din )
194  {
195  cell = &m_hbCellVec[ din ] ;
196  }
197  else
198  {
199  if( m_hbCellVec.size() +
200  m_heCellVec.size() > din )
201  {
202  const unsigned int index ( din - m_hbCellVec.size() ) ;
203  cell = &m_heCellVec[ index ] ;
204  }
205  else
206  {
207  if( m_hbCellVec.size() +
208  m_heCellVec.size() +
209  m_hoCellVec.size() > din )
210  {
211  const unsigned int index ( din
212  - m_hbCellVec.size()
213  - m_heCellVec.size() ) ;
214  cell = &m_hoCellVec[ index ] ;
215  }
216  else
217  {
218  if( m_hbCellVec.size() +
219  m_heCellVec.size() +
220  m_hoCellVec.size() +
221  m_hfCellVec.size() > din )
222  {
223  const unsigned int index ( din
224  - m_hbCellVec.size()
225  - m_heCellVec.size()
226  - m_hoCellVec.size() ) ;
227  cell = &m_hfCellVec[ index ] ;
228  }
229  }
230  }
231  }
232  return ( 0 == cell || 0 == cell->param() ? 0 : cell ) ;
233 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
virtual unsigned int detId2denseId(const DetId &id) const
return a linear packed id
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
virtual void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
CaloCellGeometry::CCGFloat CCGFloat
virtual ~HcalDDDGeometry()
The HcalDDDGeometry will delete all its cell geometries at destruction time.
float float float z
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)
const HcalTopology & topo_
const CCGFloat * param() const
T mag() const
Definition: PV3DBase.h:67
int insertCell(std::vector< HcalCellType > const &)
T z() const
Definition: PV3DBase.h:64
HcalSubdetector
Definition: HcalAssistant.h:32
HcalDDDGeometry(const HcalTopology &theTopo)
std::vector< HcalCellType > hcalCells_
HBCellVec m_hbCellVec
Definition: DetId.h:20
#define M_PI
Definition: BFit3D.cc:3
HECellVec m_heCellVec
CaloCellGeometry::CornersMgr * cornersMgr()
Detector
Definition: DetId.h:26
std::vector< DetId > m_validIds
long long int num
Definition: procUtils.cc:71
HFCellVec m_hfCellVec
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)
DetId::Detector lastReqDet_
T eta() const
Definition: PV3DBase.h:76
HOCellVec m_hoCellVec
virtual DetId getClosestCell(const GlobalPoint &r) const
Detector det() const
get the detector field from this detid
Definition: DetId.h:37
Definition: DDAxes.h:10