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 
20 
22  std::lock_guard<std::mutex> guard(s_fillLock);
23  if (m_filledDetIds) {
24  //another thread already did the work
25  return;
26  }
27  const std::vector<DetId>& baseIds(CaloSubdetectorGeometry::getValidDetIds());
28  for (unsigned int i(0); i != baseIds.size(); ++i) {
29  const DetId id(baseIds[i]);
30  if (id.subdetId() == HcalBarrel) {
31  m_hbIds.emplace_back(id);
32  } else {
33  if (id.subdetId() == HcalEndcap) {
34  m_heIds.emplace_back(id);
35  } else {
36  if (id.subdetId() == HcalOuter) {
37  m_hoIds.emplace_back(id);
38  } else {
39  if (id.subdetId() == HcalForward) {
40  m_hfIds.emplace_back(id);
41  }
42  }
43  }
44  }
45  }
46  std::sort(m_hbIds.begin(), m_hbIds.end());
47  std::sort(m_heIds.begin(), m_heIds.end());
48  std::sort(m_hoIds.begin(), m_hoIds.end());
49  std::sort(m_hfIds.begin(), m_hfIds.end());
50 
51  m_emptyIds.resize(0);
52  m_filledDetIds = true;
53 }
54 
55 std::vector<DetId> const& HcalDDDGeometry::getValidDetIds(DetId::Detector det, int subdet) const {
56  if (0 != subdet && not m_filledDetIds)
57  fillDetIds();
58  return (0 == subdet
60  : (HcalBarrel == subdet
61  ? m_hbIds
62  : (HcalEndcap == subdet
63  ? m_heIds
64  : (HcalOuter == subdet ? m_hoIds : (HcalForward == subdet ? m_hfIds : m_emptyIds)))));
65 }
66 
68  constexpr double twopi = M_PI + M_PI;
69  constexpr double deg = M_PI / 180.;
70 
71  // Now find the closest eta_bin, eta value of a bin i is average
72  // of eta[i] and eta[i-1]
73  double abseta = fabs(r.eta());
74  double phi = r.phi();
75  if (phi < 0)
76  phi += twopi;
77  double radius = r.mag();
78  double z = fabs(r.z());
79 
80  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell for eta " << r.eta() << " phi " << phi / deg << " z "
81  << r.z() << " radius " << radius;
82  HcalDetId bestId;
83  if (abseta <= etaMax_) {
84  for (const auto& hcalCell : hcalCells_) {
85  if (abseta >= hcalCell.etaMin() && abseta <= hcalCell.etaMax()) {
86  HcalSubdetector bc = hcalCell.detType();
87  int etaring = hcalCell.etaBin();
88  int phibin = 0;
89  if (hcalCell.unitPhi() == 4) {
90  // rings 40 and 41 are offset wrt the other phi numbering
91  // 1 1 1 2
92  // ------------------------------
93  // 72 36 36 1
94  phibin =
95  static_cast<int>((phi + hcalCell.phiOffset() + 0.5 * hcalCell.phiBinWidth()) / hcalCell.phiBinWidth());
96  if (phibin == 0)
97  phibin = hcalCell.nPhiBins();
98  phibin = phibin * 4 - 1;
99  } else {
100  phibin = static_cast<int>((phi + hcalCell.phiOffset()) / hcalCell.phiBinWidth()) + 1;
101  // convert to the convention of numbering 1,3,5, in 36 phi bins
102  phibin = (phibin - 1) * (hcalCell.unitPhi()) + 1;
103  }
104 
105  int dbin = 1;
106  int etabin = (r.z() > 0) ? etaring : -etaring;
107  if (bc == HcalForward) {
108  bestId = HcalDetId(bc, etabin, phibin, dbin);
109  break;
110  } else {
111  double rz = z;
112  if (hcalCell.depthType())
113  rz = radius;
114  if (rz < hcalCell.depthMax()) {
115  dbin = hcalCell.depthSegment();
116  bestId = HcalDetId(bc, etabin, phibin, dbin);
117  break;
118  }
119  }
120  }
121  }
122  }
123 
124  LogDebug("HCalGeom") << "HcalDDDGeometry::getClosestCell " << bestId;
125 
126  return bestId;
127 }
128 
129 int HcalDDDGeometry::insertCell(std::vector<HcalCellType> const& cells) {
130  hcalCells_.insert(hcalCells_.end(), cells.begin(), cells.end());
131  int num = static_cast<int>(hcalCells_.size());
132  for (const auto& cell : cells) {
133  if (cell.etaMax() > etaMax_)
134  etaMax_ = cell.etaMax();
135  }
136 
137  LogDebug("HCalGeom") << "HcalDDDGeometry::insertCell " << cells.size() << " cells inserted == Total " << num
138  << " EtaMax = " << etaMax_;
139  return num;
140 }
141 
143  const GlobalPoint& f1, const GlobalPoint& f2, const GlobalPoint& f3, const CCGFloat* parm, const DetId& detId) {
144  assert(detId.det() == DetId::Hcal);
145 
146  const unsigned int din(topo_.detId2denseId(detId));
147 
148  HcalDetId hId(detId);
149 
150  if (hId.subdet() == HcalBarrel) {
152  } else {
153  if (hId.subdet() == HcalEndcap) {
154  const unsigned int index(din - m_hbCellVec.size());
156  } else {
157  if (hId.subdet() == HcalOuter) {
158  const unsigned int index(din - m_hbCellVec.size() - m_heCellVec.size());
160  } else { // assuming HcalForward here!
161  const unsigned int index(din - m_hbCellVec.size() - m_heCellVec.size() - m_hoCellVec.size());
162  m_hfCellVec[index] =
163  IdealZPrism(f1, cornersMgr(), parm, hId.depth() == 1 ? IdealZPrism::EM : IdealZPrism::HADR);
164  }
165  }
166  }
167 }
168 
170  const GlobalPoint& f1, const GlobalPoint& f2, const GlobalPoint& f3, const CCGFloat* parm, const DetId& detId) {
171  newCellImpl(f1, f2, f3, parm, detId);
172  addValidID(detId);
173 }
174 
176  const GlobalPoint& f1, const GlobalPoint& f2, const GlobalPoint& f3, const CCGFloat* parm, const DetId& detId) {
177  newCellImpl(f1, f2, f3, parm, detId);
178  m_validIds.emplace_back(detId);
179 }
180 
182  // Modify the RawPtr class
183  const CaloCellGeometry* cell(nullptr);
184  if (m_hbCellVec.size() > din) {
185  cell = (&m_hbCellVec[din]);
186  } else if (m_hbCellVec.size() + m_heCellVec.size() > din) {
187  const unsigned int ind(din - m_hbCellVec.size());
188  cell = (&m_heCellVec[ind]);
189  } else if (m_hbCellVec.size() + m_heCellVec.size() + m_hoCellVec.size() > din) {
190  const unsigned int ind(din - m_hbCellVec.size() - m_heCellVec.size());
191  cell = (&m_hoCellVec[ind]);
192  } else if (m_hbCellVec.size() + m_heCellVec.size() + m_hoCellVec.size() + m_hfCellVec.size() > din) {
193  const unsigned int ind(din - m_hbCellVec.size() - m_heCellVec.size() - m_hoCellVec.size());
194  cell = (&m_hfCellVec[ind]);
195  }
196 
197  return ((nullptr == cell || nullptr == cell->param()) ? nullptr : cell);
198 }
199 
200 void HcalDDDGeometry::increaseReserve(unsigned int extra) { m_validIds.reserve(m_validIds.size() + extra); }
201 
mps_fire.i
i
Definition: mps_fire.py:428
HcalDDDGeometry::hcalCells_
std::vector< HcalCellType > hcalCells_
Definition: HcalDDDGeometry.h:59
HcalDDDGeometry::etaMax_
double etaMax_
Definition: HcalDDDGeometry.h:67
MessageLogger.h
funct::false
false
Definition: Factorize.h:29
IdealZPrism::HADR
Definition: IdealZPrism.h:28
HcalDDDGeometry.h
DetId::det
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
HcalTopology
Definition: HcalTopology.h:26
DetId::Hcal
Definition: DetId.h:28
cells
const caConstants::TupleMultiplicity const CAHitNtupletGeneratorKernelsGPU::HitToTuple cms::cuda::AtomicPairCounter const GPUCACell *__restrict__ cells
Definition: CAHitNtupletGeneratorKernelsImpl.h:43
cms::cuda::assert
assert(be >=bs)
HcalDDDGeometry::getGeometryRawPtr
const CaloCellGeometry * getGeometryRawPtr(uint32_t index) const override
Definition: HcalDDDGeometry.cc:181
HcalDDDGeometry::m_heIds
std::vector< DetId > m_heIds
Definition: HcalDDDGeometry.h:61
HcalBarrel
Definition: HcalAssistant.h:33
HcalDDDGeometry::increaseReserve
void increaseReserve(unsigned int extra)
Definition: HcalDDDGeometry.cc:200
HcalDDDGeometry::getClosestCell
DetId getClosestCell(const GlobalPoint &r) const override
Definition: HcalDDDGeometry.cc:67
HcalDDDGeometry::newCellFast
void newCellFast(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
Definition: HcalDDDGeometry.cc:175
DetId
Definition: DetId.h:17
CaloSubdetectorGeometry::CCGFloat
CaloCellGeometry::CCGFloat CCGFloat
Definition: CaloSubdetectorGeometry.h:25
IdealObliquePrism
Definition: IdealObliquePrism.h:28
HcalDDDGeometry::m_hbIds
std::vector< DetId > m_hbIds
Definition: HcalDDDGeometry.h:60
CaloSubdetectorGeometry::m_validIds
std::vector< DetId > m_validIds
Definition: CaloSubdetectorGeometry.h:115
DDAxes::z
HcalDDDGeometry::m_hfIds
std::vector< DetId > m_hfIds
Definition: HcalDDDGeometry.h:63
HcalOuter
Definition: HcalAssistant.h:35
Point3DBase< float, GlobalTag >
HcalTopology::detId2denseId
unsigned int detId2denseId(const DetId &id) const override
return a linear packed id
Definition: HcalTopology.cc:1519
CaloSubdetectorGeometry::getValidDetIds
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)
Definition: CaloSubdetectorGeometry.cc:32
IdealZPrism
Definition: IdealZPrism.h:26
HcalDDDGeometry::insertCell
int insertCell(std::vector< HcalCellType > const &)
Definition: HcalDDDGeometry.cc:129
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
cropTnPTrees.din
din
Definition: cropTnPTrees.py:30
CaloCellGeometry
Definition: CaloCellGeometry.h:50
DeadROC_duringRun.f2
f2
Definition: DeadROC_duringRun.py:220
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
CaloCellGeometry::param
const CCGFloat * param() const
Definition: CaloCellGeometry.h:99
HcalDDDGeometry::HcalDDDGeometry
HcalDDDGeometry(const HcalTopology &theTopo)
Definition: HcalDDDGeometry.cc:10
HcalDetId
Definition: HcalDetId.h:12
mutex
static std::mutex mutex
Definition: Proxy.cc:8
CaloSubdetectorGeometry::addValidID
void addValidID(const DetId &id)
Definition: CaloSubdetectorGeometry.cc:27
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
HcalDDDGeometry::m_hfCellVec
HFCellVec m_hfCellVec
Definition: HcalDDDGeometry.h:72
DetId::Detector
Detector
Definition: DetId.h:24
HcalDDDGeometry::m_filledDetIds
std::atomic< bool > m_filledDetIds
Definition: HcalDDDGeometry.h:73
IdealZPrism::EM
Definition: IdealZPrism.h:28
EgammaValidation_cff.num
num
Definition: EgammaValidation_cff.py:33
HcalDDDGeometry::~HcalDDDGeometry
~HcalDDDGeometry() override
The HcalDDDGeometry will delete all its cell geometries at destruction time.
Definition: HcalDDDGeometry.cc:19
alignCSCRings.r
r
Definition: alignCSCRings.py:93
HcalSubdetector
HcalSubdetector
Definition: HcalAssistant.h:31
HcalForward
Definition: HcalAssistant.h:36
DDAxes::phi
CaloCellGeometry.h
HcalDDDGeometry::m_hoIds
std::vector< DetId > m_hoIds
Definition: HcalDDDGeometry.h:62
CaloSubdetectorGeometry::cornersMgr
CaloCellGeometry::CornersMgr * cornersMgr()
Definition: CaloSubdetectorGeometry.h:82
HcalEndcap
Definition: HcalAssistant.h:34
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
s_fillLock
static std::mutex s_fillLock
Definition: HcalDDDGeometry.cc:8
HcalDDDGeometry::fillDetIds
void fillDetIds() const
Definition: HcalDDDGeometry.cc:21
CosmicsPD_Skims.radius
radius
Definition: CosmicsPD_Skims.py:135
HcalDDDGeometry::m_emptyIds
std::vector< DetId > m_emptyIds
Definition: HcalDDDGeometry.h:64
HcalDDDGeometry::getValidDetIds
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)
Definition: HcalDDDGeometry.cc:55
HcalDDDGeometry::newCellImpl
void newCellImpl(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId)
Definition: HcalDDDGeometry.cc:142
AlignmentPI::index
index
Definition: AlignmentPayloadInspectorHelper.h:46
HcalDDDGeometry::newCell
void newCell(const GlobalPoint &f1, const GlobalPoint &f2, const GlobalPoint &f3, const CCGFloat *parm, const DetId &detId) override
Definition: HcalDDDGeometry.cc:169
HcalDDDGeometry::m_hoCellVec
HOCellVec m_hoCellVec
Definition: HcalDDDGeometry.h:71
HcalDDDGeometry::topo_
const HcalTopology & topo_
Definition: HcalDDDGeometry.h:66
DeadROC_duringRun.f1
f1
Definition: DeadROC_duringRun.py:219
HcalDDDGeometry::m_hbCellVec
HBCellVec m_hbCellVec
Definition: HcalDDDGeometry.h:69
HcalDDDGeometry::m_heCellVec
HECellVec m_heCellVec
Definition: HcalDDDGeometry.h:70
HcalDDDGeometry::sortValidIds
void sortValidIds()
Definition: HcalDDDGeometry.cc:202