CMS 3D CMS Logo

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.emplace_back( id ) ;
40  }
41  else
42  {
43  if( id.subdetId() == HcalEndcap )
44  {
45  m_heIds.emplace_back( id ) ;
46  }
47  else
48  {
49  if( id.subdetId() == HcalOuter )
50  {
51  m_hoIds.emplace_back( id ) ;
52  }
53  else
54  {
55  if( id.subdetId() == HcalForward )
56  {
57  m_hfIds.emplace_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  constexpr double twopi = M_PI+M_PI;
88  constexpr double deg = M_PI/180.;
89 
90  // Now find the closest eta_bin, eta value of a bin i is average
91  // of eta[i] and eta[i-1]
92  double abseta = fabs(r.eta());
93  double phi = r.phi();
94  if (phi < 0) phi += twopi;
95  double radius = r.mag();
96  double z = fabs(r.z());
97 
98  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta "
99  << r.eta() << " phi " << phi/deg << " z " << r.z()
100  << " radius " << radius;
101  HcalDetId bestId;
102  if (abseta <= etaMax_) {
103  for (const auto & hcalCell : hcalCells_) {
104  if (abseta >=hcalCell.etaMin() && abseta <=hcalCell.etaMax()) {
105  HcalSubdetector bc = hcalCell.detType();
106  int etaring = hcalCell.etaBin();
107  int phibin = 0;
108  if (hcalCell.unitPhi() == 4) {
109  // rings 40 and 41 are offset wrt the other phi numbering
110  // 1 1 1 2
111  // ------------------------------
112  // 72 36 36 1
113  phibin = static_cast<int>((phi+hcalCell.phiOffset()+
114  0.5*hcalCell.phiBinWidth())/
115  hcalCell.phiBinWidth());
116  if (phibin == 0) phibin = hcalCell.nPhiBins();
117  phibin = phibin*4 - 1;
118  } else {
119  phibin = static_cast<int>((phi+hcalCell.phiOffset())/
120  hcalCell.phiBinWidth()) + 1;
121  // convert to the convention of numbering 1,3,5, in 36 phi bins
122  phibin = (phibin-1)*(hcalCell.unitPhi()) + 1;
123  }
124 
125  int dbin = 1;
126  int etabin = (r.z() > 0) ? etaring : -etaring;
127  if (bc == HcalForward) {
128  bestId = HcalDetId(bc, etabin, phibin, dbin);
129  break;
130  } else {
131  double rz = z;
132  if (hcalCell.depthType()) rz = radius;
133  if (rz < hcalCell.depthMax()) {
134  dbin = hcalCell.depthSegment();
135  bestId = HcalDetId(bc, etabin, phibin, dbin);
136  break;
137  }
138  }
139  }
140  }
141  }
142 
143  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
144 
145  return bestId;
146 }
147 
148 int
149 HcalDDDGeometry::insertCell(std::vector<HcalCellType> const & cells) {
150 
151  hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
152  int num = static_cast<int>(hcalCells_.size());
153  for (const auto & cell : cells) {
154  if (cell.etaMax() > etaMax_ ) etaMax_ = cell.etaMax();
155  }
156 
157  LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size()
158  << " cells inserted == Total " << num
159  << " EtaMax = " << etaMax_;
160  return num;
161 }
162 
163 void
165  const GlobalPoint& f2 ,
166  const GlobalPoint& f3 ,
167  const CCGFloat* parm ,
168  const DetId& detId )
169 {
170 
171  assert( detId.det()==DetId::Hcal );
172 
173  const unsigned int din(topo_.detId2denseId(detId));
174 
175  HcalDetId hId(detId);
176 
177  if( hId.subdet()==HcalBarrel ) {
178  m_hbCellVec[ din ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
179  } else {
180  if( hId.subdet()==HcalEndcap ) {
181  const unsigned int index ( din - m_hbCellVec.size() ) ;
182  m_heCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
183  } else {
184  if( hId.subdet()==HcalOuter ) {
185  const unsigned int index ( din
186  - m_hbCellVec.size()
187  - m_heCellVec.size() ) ;
188  m_hoCellVec[ index ] = IdealObliquePrism( f1, cornersMgr(), parm ) ;
189  } else { // assuming HcalForward here!
190  const unsigned int index ( din
191  - m_hbCellVec.size()
192  - m_heCellVec.size()
193  - m_hoCellVec.size() ) ;
194  m_hfCellVec[ index ] = IdealZPrism( f1, cornersMgr(), parm, hId.depth()==1 ? IdealZPrism::EM : IdealZPrism::HADR ) ;
195  }
196  }
197  }
198 }
199 
200 void
202  const GlobalPoint& f2 ,
203  const GlobalPoint& f3 ,
204  const CCGFloat* parm ,
205  const DetId& detId )
206 {
207  newCellImpl(f1,f2,f3,parm,detId);
208  addValidID( detId );
209 }
210 
211 void
213  const GlobalPoint& f2 ,
214  const GlobalPoint& f3 ,
215  const CCGFloat* parm ,
216  const DetId& detId )
217 {
218  newCellImpl(f1,f2,f3,parm,detId);
219  m_validIds.emplace_back(detId);
220 }
221 
223  // Modify the RawPtr class
224  const CaloCellGeometry* cell(nullptr);
225  if (m_hbCellVec.size() > din) {
226  cell = (&m_hbCellVec[din]);
227  } else if (m_hbCellVec.size()+m_heCellVec.size() > din) {
228  const unsigned int ind (din - m_hbCellVec.size() ) ;
229  cell = (&m_heCellVec[ind]);
230  } else if (m_hbCellVec.size()+m_heCellVec.size()+m_hoCellVec.size() > din) {
231  const unsigned int ind (din - m_hbCellVec.size() - m_heCellVec.size());
232  cell = (&m_hoCellVec[ind]);
233  } else if (m_hbCellVec.size()+m_heCellVec.size()+m_hoCellVec.size()+
234  m_hfCellVec.size() > din) {
235  const unsigned int ind (din - m_hbCellVec.size() - m_heCellVec.size() -
236  m_hoCellVec.size() ) ;
237  cell = (&m_hfCellVec[ind]);
238  }
239 
240  return (( nullptr == cell || nullptr == cell->param()) ? nullptr : cell ) ;
241 }
242 
243 void HcalDDDGeometry::increaseReserve(unsigned int extra) {
244  m_validIds.reserve(m_validIds.size()+extra);
245 }
246 
248  std::sort(m_validIds.begin(),m_validIds.end());
249 }
#define LogDebug(id)
static boost::mutex mutex
Definition: Proxy.cc:11
unsigned int detId2denseId(const DetId &id) const override
return a linear packed id
std::vector< DetId > m_hfIds
std::vector< DetId > m_heIds
std::atomic< bool > m_filledDetIds
Geom::Phi< T > phi() const
Definition: PV3DBase.h:69
const CaloCellGeometry * getGeometryRawPtr(uint32_t index) const override
CaloCellGeometry::CCGFloat CCGFloat
#define constexpr
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 getClosestCell(const GlobalPoint &r) const override
void newCellFast(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
const HcalTopology & topo_
const CCGFloat * param() const
T mag() const
Definition: PV3DBase.h:67
int insertCell(std::vector< HcalCellType > const &)
void increaseReserve(unsigned int extra)
std::vector< DetId > m_validIds
T z() const
Definition: PV3DBase.h:64
HcalSubdetector
Definition: HcalAssistant.h:31
HcalDDDGeometry(const HcalTopology &theTopo)
static std::mutex s_fillLock
void newCellImpl(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
std::vector< HcalCellType > hcalCells_
std::vector< DetId > m_hbIds
HBCellVec m_hbCellVec
#define M_PI
~HcalDDDGeometry() override
The HcalDDDGeometry will delete all its cell geometries at destruction time.
Definition: DetId.h:18
void fillDetIds() const
std::vector< DetId > m_emptyIds
void addValidID(const DetId &id)
HECellVec m_heCellVec
CaloCellGeometry::CornersMgr * cornersMgr()
Detector
Definition: DetId.h:26
HFCellVec m_hfCellVec
T eta() const
Definition: PV3DBase.h:76
HOCellVec m_hoCellVec
std::vector< DetId > m_hoIds
void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId) override
const std::vector< DetId > & getValidDetIds(DetId::Detector det=DetId::Detector(0), int subdet=0) const override
Get a list of valid detector ids (for the given subdetector)
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:39