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.
6 
7 #include <algorithm>
8 
9 //#define DebugLog
10 
12  lastReqDet_(DetId::Detector(0)),
13  lastReqSubdet_(0),
14  etaMax_(0),
15  firstHFQuadRing_(40) ,
16  m_hbCellVec ( HcalDetId::kHBSize ) ,
17  m_heCellVec ( HcalDetId::kHESize ) ,
18  m_hoCellVec ( HcalDetId::kHOSize ) ,
19  m_hfCellVec ( HcalDetId::kHFSize )
20 {
21  twopi = M_PI + M_PI;
22  deg = M_PI/180.;
23 }
24 
25 
27 {
28 }
29 
30 
31 std::vector<DetId> const & HcalDDDGeometry::getValidDetIds(DetId::Detector det,
32  int subdet) const {
33 
34  const std::vector<DetId>& baseIds(CaloSubdetectorGeometry::getValidDetIds());
35  if (det == DetId::Detector( 0 ) && subdet == 0) {
36  return baseIds ;
37  }
38 
39  if (lastReqDet_ != det || lastReqSubdet_ != subdet ) {
40  lastReqDet_ = det ;
41  lastReqSubdet_ = subdet ;
42  m_validIds.clear();
43  m_validIds.reserve( baseIds.size() ) ;
44  }
45 
46  if (m_validIds.empty() ) {
47  for (unsigned int i = 0 ; i != baseIds.size() ; ++i ) {
48  const DetId id ( baseIds[i] );
49  if (id.det() == det && id.subdetId() == subdet ) {
50  m_validIds.push_back( id ) ;
51  }
52  }
53  std::sort(m_validIds.begin(),m_validIds.end());
54  }
55 
56 #ifdef DebugLog
57  LogDebug("HCalGeom") << "HcalDDDGeometry::getValidDetIds: "
58  << m_validIds.size() << " valid IDs found for detector "
59  << det << " Sub-detector " << subdet;
60 #endif
61  return m_validIds;
62 }
63 
64 
66 
67  // Now find the closest eta_bin, eta value of a bin i is average
68  // of eta[i] and eta[i-1]
69  double abseta = fabs(r.eta());
70  double phi = r.phi();
71  if (phi < 0) phi += twopi;
72  double radius = r.mag();
73  double z = fabs(r.z());
74 #ifdef DebugLog
75  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta "
76  << r.eta() << " phi " << phi/deg << " z " << r.z()
77  << " radius " << radius;
78 #endif
79 
80  HcalDetId bestId;
81  if (abseta <= etaMax_) {
82  for (unsigned int i=0; i<hcalCells_.size(); i++) {
83  if (abseta >=hcalCells_[i].etaMin() && abseta <=hcalCells_[i].etaMax()) {
84  HcalSubdetector bc = hcalCells_[i].detType();
85  int etaring = hcalCells_[i].etaBin();
86  int phibin = 0;
87  if (hcalCells_[i].unitPhi() == 4) {
88  // rings 40 and 41 are offset wrt the other phi numbering
89  // 1 1 1 2
90  // ------------------------------
91  // 72 36 36 1
92  phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset()+
93  0.5*hcalCells_[i].phiBinWidth())/
94  hcalCells_[i].phiBinWidth());
95  if (phibin == 0) phibin = hcalCells_[i].nPhiBins();
96  phibin = phibin*4 - 1;
97  } else {
98  phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset())/
99  hcalCells_[i].phiBinWidth()) + 1;
100  // convert to the convention of numbering 1,3,5, in 36 phi bins
101  phibin = (phibin-1)*(hcalCells_[i].unitPhi()) + 1;
102  }
103 
104  int dbin = 1;
105  int etabin = (r.z() > 0) ? etaring : -etaring;
106  if (bc == HcalForward) {
107  bestId = HcalDetId(bc, etabin, phibin, dbin);
108  break;
109  } else {
110  double rz = z;
111  if (hcalCells_[i].depthType()) rz = radius;
112  if (rz < hcalCells_[i].depthMax()) {
113  dbin = hcalCells_[i].depthSegment();
114  bestId = HcalDetId(bc, etabin, phibin, dbin);
115  break;
116  }
117  }
118  }
119  }
120  }
121 #ifdef DebugLog
122  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
123 #endif
124  return bestId;
125 }
126 
127 
128 int HcalDDDGeometry::insertCell(std::vector<HcalCellType> const & cells){
129 
130  hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
131  int num = static_cast<int>(hcalCells_.size());
132  for (unsigned int i=0; i<cells.size(); i++) {
133  if (cells[i].etaMax() > etaMax_ ) etaMax_ = cells[i].etaMax();
134  }
135 #ifdef DebugLog
136  LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size()
137  << " cells inserted == Total " << num
138  << " EtaMax = " << etaMax_;
139 #endif
140  return num;
141 }
142 
143 void
145  const GlobalPoint& f2 ,
146  const GlobalPoint& f3 ,
147  const CCGFloat* parm ,
148  const DetId& detId )
149 {
150  const CaloGenericDetId cgid ( detId ) ;
151 
152  const unsigned int din ( cgid.denseIndex() ) ;
153 
154  assert( cgid.isHcal() ) ;
155 
156  if( cgid.isHB() )
157  {
158  m_hbCellVec[ din ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
159  }
160  else
161  {
162  if( cgid.isHE() )
163  {
164  const unsigned int index ( din - m_hbCellVec.size() ) ;
165  m_heCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
166  }
167  else
168  {
169  if( cgid.isHO() )
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  {
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
bool isHE() const
virtual const CaloCellGeometry * cellGeomPtr(uint32_t index) const
Geom::Phi< T > phi() const
Definition: PV3DBase.h:68
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.
double double double 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 CCGFloat * param() const
T mag() const
Definition: PV3DBase.h:66
int insertCell(std::vector< HcalCellType > const &)
T z() const
Definition: PV3DBase.h:63
HcalSubdetector
Definition: HcalAssistant.h:32
std::vector< HcalCellType > hcalCells_
HBCellVec m_hbCellVec
bool isHcal() const
uint32_t denseIndex() const
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:75
HOCellVec m_hoCellVec
bool isHO() const
bool isHB() const
virtual DetId getClosestCell(const GlobalPoint &r) const
Definition: DDAxes.h:10