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  lastReqSubdet_(0), etaMax_(0),
12  firstHFQuadRing_(40) {
13  twopi = M_PI + M_PI;
14  deg = M_PI/180.;
15 }
16 
17 
19 
20 
21 std::vector<DetId> const & HcalDDDGeometry::getValidDetIds(DetId::Detector det,
22  int subdet) const {
23 
24  const std::vector<DetId>& baseIds(CaloSubdetectorGeometry::getValidDetIds());
25  if (det == DetId::Detector( 0 ) && subdet == 0) {
26  return baseIds ;
27  }
28 
29  if (lastReqDet_ != det || lastReqSubdet_ != subdet ) {
30  lastReqDet_ = det ;
31  lastReqSubdet_ = subdet ;
32  m_validIds.clear();
33  m_validIds.reserve( baseIds.size() ) ;
34  }
35 
36  if (m_validIds.empty() ) {
37  for (unsigned int i = 0 ; i != baseIds.size() ; ++i ) {
38  const DetId id ( baseIds[i] );
39  if (id.det() == det && id.subdetId() == subdet ) {
40  m_validIds.push_back( id ) ;
41  }
42  }
43  std::sort(m_validIds.begin(),m_validIds.end());
44  }
45 
46 #ifdef DebugLog
47  LogDebug("HCalGeom") << "HcalDDDGeometry::getValidDetIds: "
48  << m_validIds.size() << " valid IDs found for detector "
49  << det << " Sub-detector " << subdet;
50 #endif
51  return m_validIds;
52 }
53 
54 
56 
57  // Now find the closest eta_bin, eta value of a bin i is average
58  // of eta[i] and eta[i-1]
59  double abseta = fabs(r.eta());
60  double phi = r.phi();
61  if (phi < 0) phi += twopi;
62  double radius = r.mag();
63  double z = fabs(r.z());
64 #ifdef DebugLog
65  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta "
66  << r.eta() << " phi " << phi/deg << " z " << r.z()
67  << " radius " << radius;
68 #endif
69 
70  HcalDetId bestId;
71  if (abseta <= etaMax_) {
72  for (unsigned int i=0; i<hcalCells_.size(); i++) {
73  if (abseta >=hcalCells_[i].etaMin() && abseta <=hcalCells_[i].etaMax()) {
74  HcalSubdetector bc = hcalCells_[i].detType();
75  int etaring = hcalCells_[i].etaBin();
76  int phibin = 0;
77  if (hcalCells_[i].unitPhi() == 4) {
78  // rings 40 and 41 are offset wrt the other phi numbering
79  // 1 1 1 2
80  // ------------------------------
81  // 72 36 36 1
82  phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset()+
83  0.5*hcalCells_[i].phiBinWidth())/
84  hcalCells_[i].phiBinWidth());
85  if (phibin == 0) phibin = hcalCells_[i].nPhiBins();
86  phibin = phibin*4 - 1;
87  } else {
88  phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset())/
89  hcalCells_[i].phiBinWidth()) + 1;
90  // convert to the convention of numbering 1,3,5, in 36 phi bins
91  phibin = (phibin-1)*(hcalCells_[i].unitPhi()) + 1;
92  }
93 
94  int dbin = 1;
95  int etabin = (r.z() > 0) ? etaring : -etaring;
96  if (bc == HcalForward) {
97  bestId = HcalDetId(bc, etabin, phibin, dbin);
98  break;
99  } else {
100  double rz = z;
101  if (hcalCells_[i].depthType()) rz = radius;
102  if (rz < hcalCells_[i].depthMax()) {
103  dbin = hcalCells_[i].depthSegment();
104  bestId = HcalDetId(bc, etabin, phibin, dbin);
105  break;
106  }
107  }
108  }
109  }
110  }
111 #ifdef DebugLog
112  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
113 #endif
114  return bestId;
115 }
116 
117 
118 int HcalDDDGeometry::insertCell(std::vector<HcalCellType> const & cells){
119 
120  hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
121  int num = static_cast<int>(hcalCells_.size());
122  for (unsigned int i=0; i<cells.size(); i++) {
123  if (cells[i].etaMax() > etaMax_ ) etaMax_ = cells[i].etaMax();
124  }
125 #ifdef DebugLog
126  LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size()
127  << " cells inserted == Total " << num
128  << " EtaMax = " << etaMax_;
129 #endif
130  return num;
131 }
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
Geom::Phi< T > phi() const
Definition: PV3DBase.h:63
virtual ~HcalDDDGeometry()
The HcalDDDGeometry will delete all its cell geometries at destruction time.
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)
T mag() const
Definition: PV3DBase.h:61
Definition: DDAxes.h:10
int insertCell(std::vector< HcalCellType > const &)
T z() const
Definition: PV3DBase.h:58
HcalSubdetector
Definition: HcalAssistant.h:32
std::vector< HcalCellType > hcalCells_
Definition: DetId.h:20
#define M_PI
Definition: BFit3D.cc:3
Detector
Definition: DetId.h:26
std::vector< DetId > m_validIds
long long int num
Definition: procUtils.cc:71
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:70
virtual DetId getClosestCell(const GlobalPoint &r) const
Definition: DDAxes.h:10