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.
4 
5 #include <algorithm>
6 #include <mutex>
7 
9 
11  : topo_(topo),
12  etaMax_(0),
13  m_hbCellVec ( topo.getHBSize() ) ,
14  m_heCellVec ( topo.getHESize() ) ,
15  m_hoCellVec ( topo.getHOSize() ) ,
16  m_hfCellVec ( topo.getHFSize() ) ,
17  m_filledDetIds(false)
18 {
19 }
20 
22 {
23 }
24 
25 void
27 {
28  std::lock_guard<std::mutex> guard(s_fillLock);
29  if (m_filledDetIds) {
30  //another thread already did the work
31  return;
32  }
33  const std::vector<DetId>& baseIds ( CaloSubdetectorGeometry::getValidDetIds() ) ;
34  for( unsigned int i ( 0 ) ; i != baseIds.size() ; ++i )
35  {
36  const DetId id ( baseIds[i] );
37  if( id.subdetId() == HcalBarrel )
38  {
39  m_hbIds.push_back( id ) ;
40  }
41  else
42  {
43  if( id.subdetId() == HcalEndcap )
44  {
45  m_heIds.push_back( id ) ;
46  }
47  else
48  {
49  if( id.subdetId() == HcalOuter )
50  {
51  m_hoIds.push_back( id ) ;
52  }
53  else
54  {
55  if( id.subdetId() == HcalForward )
56  {
57  m_hfIds.push_back( id ) ;
58  }
59  }
60  }
61  }
62  }
63  std::sort( m_hbIds.begin(), m_hbIds.end() ) ;
64  std::sort( m_heIds.begin(), m_heIds.end() ) ;
65  std::sort( m_hoIds.begin(), m_hoIds.end() ) ;
66  std::sort( m_hfIds.begin(), m_hfIds.end() ) ;
67 
68  m_emptyIds.resize( 0 ) ;
69  m_filledDetIds = true;
70 }
71 
72 std::vector<DetId> const &
74  int subdet) const
75 {
76  if( 0 != subdet &&
77  not m_filledDetIds ) fillDetIds() ;
78  return ( 0 == subdet ? CaloSubdetectorGeometry::getValidDetIds() :
79  ( HcalBarrel == subdet ? m_hbIds :
80  ( HcalEndcap == subdet ? m_heIds :
81  ( HcalOuter == subdet ? m_hoIds :
82  ( HcalForward == subdet ? m_hfIds : m_emptyIds ) ) ) ) ) ;
83 }
84 
85 DetId
87 {
88  constexpr double twopi = M_PI+M_PI;
89  constexpr double deg = M_PI/180.;
90 
91  // Now find the closest eta_bin, eta value of a bin i is average
92  // of eta[i] and eta[i-1]
93  double abseta = fabs(r.eta());
94  double phi = r.phi();
95  if (phi < 0) phi += twopi;
96  double radius = r.mag();
97  double z = fabs(r.z());
98 
99  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta "
100  << r.eta() << " phi " << phi/deg << " z " << r.z()
101  << " radius " << radius;
102  HcalDetId bestId;
103  if (abseta <= etaMax_) {
104  for (unsigned int i=0; i<hcalCells_.size(); i++) {
105  if (abseta >=hcalCells_[i].etaMin() && abseta <=hcalCells_[i].etaMax()) {
106  HcalSubdetector bc = hcalCells_[i].detType();
107  int etaring = hcalCells_[i].etaBin();
108  int phibin = 0;
109  if (hcalCells_[i].unitPhi() == 4) {
110  // rings 40 and 41 are offset wrt the other phi numbering
111  // 1 1 1 2
112  // ------------------------------
113  // 72 36 36 1
114  phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset()+
115  0.5*hcalCells_[i].phiBinWidth())/
116  hcalCells_[i].phiBinWidth());
117  if (phibin == 0) phibin = hcalCells_[i].nPhiBins();
118  phibin = phibin*4 - 1;
119  } else {
120  phibin = static_cast<int>(((phi/deg)+hcalCells_[i].phiOffset())/
121  hcalCells_[i].phiBinWidth()) + 1;
122  // convert to the convention of numbering 1,3,5, in 36 phi bins
123  phibin = (phibin-1)*(hcalCells_[i].unitPhi()) + 1;
124  }
125 
126  int dbin = 1;
127  int etabin = (r.z() > 0) ? etaring : -etaring;
128  if (bc == HcalForward) {
129  bestId = HcalDetId(bc, etabin, phibin, dbin);
130  break;
131  } else {
132  double rz = z;
133  if (hcalCells_[i].depthType()) rz = radius;
134  if (rz < hcalCells_[i].depthMax()) {
135  dbin = hcalCells_[i].depthSegment();
136  bestId = HcalDetId(bc, etabin, phibin, dbin);
137  break;
138  }
139  }
140  }
141  }
142  }
143 
144  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
145 
146  return bestId;
147 }
148 
149 int
150 HcalDDDGeometry::insertCell(std::vector<HcalCellType> const & cells){
151 
152  hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
153  int num = static_cast<int>(hcalCells_.size());
154  for (unsigned int i=0; i<cells.size(); i++) {
155  if (cells[i].etaMax() > etaMax_ ) etaMax_ = cells[i].etaMax();
156  }
157 
158  LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size()
159  << " cells inserted == Total " << num
160  << " EtaMax = " << etaMax_;
161  return num;
162 }
163 
164 void
166  const GlobalPoint& f2 ,
167  const GlobalPoint& f3 ,
168  const CCGFloat* parm ,
169  const DetId& detId )
170 {
171 
172  assert( detId.det()==DetId::Hcal );
173 
174  const unsigned int din(topo_.detId2denseId(detId));
175 
176  HcalDetId hId(detId);
177 
178  if( hId.subdet()==HcalBarrel )
179  {
180  m_hbCellVec[ din ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
181  }
182  else
183  {
184  if( hId.subdet()==HcalEndcap )
185  {
186  const unsigned int index ( din - m_hbCellVec.size() ) ;
187  m_heCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
188  }
189  else
190  {
191  if( hId.subdet()==HcalOuter )
192  {
193  const unsigned int index ( din
194  - m_hbCellVec.size()
195  - m_heCellVec.size() ) ;
196  m_hoCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
197  }
198  else
199  { // assuming HcalForward here!
200  const unsigned int index ( din
201  - m_hbCellVec.size()
202  - m_heCellVec.size()
203  - m_hoCellVec.size() ) ;
204  m_hfCellVec[ index ] = IdealZPrism( f1, cornersMgr(), parm ) ;
205  }
206  }
207  }
208  addValidID( detId ) ;
209 }
210 
211 const CaloCellGeometry*
213 {
214  const CaloCellGeometry* cell ( 0 ) ;
215  if( m_hbCellVec.size() > din )
216  {
217  cell = &m_hbCellVec[ din ] ;
218  }
219  else
220  {
221  if( m_hbCellVec.size() +
222  m_heCellVec.size() > din )
223  {
224  const unsigned int index ( din - m_hbCellVec.size() ) ;
225  cell = &m_heCellVec[ index ] ;
226  }
227  else
228  {
229  if( m_hbCellVec.size() +
230  m_heCellVec.size() +
231  m_hoCellVec.size() > din )
232  {
233  const unsigned int index ( din
234  - m_hbCellVec.size()
235  - m_heCellVec.size() ) ;
236  cell = &m_hoCellVec[ index ] ;
237  }
238  else
239  {
240  if( m_hbCellVec.size() +
241  m_heCellVec.size() +
242  m_hoCellVec.size() +
243  m_hfCellVec.size() > din )
244  {
245  const unsigned int index ( din
246  - m_hbCellVec.size()
247  - m_heCellVec.size()
248  - m_hoCellVec.size() ) ;
249  cell = &m_hfCellVec[ index ] ;
250  }
251  }
252  }
253  }
254  return ( 0 == cell || 0 == cell->param() ? 0 : cell ) ;
255 }
#define LogDebug(id)
CMS_THREAD_GUARD(m_filledDetIds) mutable std CMS_THREAD_GUARD(m_filledDetIds) mutable std CMS_THREAD_GUARD(m_filledDetIds) mutable std CMS_THREAD_GUARD(m_filledDetIds) mutable std CMS_THREAD_GUARD(m_filledDetIds) mutable std const HcalTopology & topo_
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
static boost::mutex mutex
Definition: LHEProxy.cc:11
std::atomic< bool > m_filledDetIds
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 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:31
HcalDDDGeometry(const HcalTopology &theTopo)
static std::mutex s_fillLock
std::vector< HcalCellType > hcalCells_
HBCellVec m_hbCellVec
#define M_PI
Definition: DetId.h:18
void fillDetIds() const
void addValidID(const DetId &id)
HECellVec m_heCellVec
CaloCellGeometry::CornersMgr * cornersMgr()
Detector
Definition: DetId.h:24
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)
T eta() const
Definition: PV3DBase.h:76
HOCellVec m_hoCellVec
virtual DetId getClosestCell(const GlobalPoint &r) const
volatile std::atomic< bool > shutdown_flag false
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
#define constexpr
Definition: DDAxes.h:10