CMS 3D CMS Logo

CaloTowerConstituentsMap.cc
Go to the documentation of this file.
8 
9 #include <memory>
10 
11 //#define EDM_ML_DEBUG
12 
14  delete m_reverseItems.load();
15  m_reverseItems = nullptr;
16 }
18  : m_hcaltopo(hcaltopo),
19  m_cttopo(cttopo),
20  standardHB_(false),
21  standardHE_(false),
22  standardHF_(false),
23  standardHO_(false),
24  standardEB_(false),
25  m_reverseItems(nullptr) {}
26 
28  CaloTowerDetId tid; // null to start with
29 
31  if (i != m_items.end())
32  tid = i->tower;
33 
34  //use hcaltopo when dealing with hcal detids
35  if (tid.null()) {
36  if (id.det() == DetId::Hcal) {
37  HcalDetId hid(id);
38  if ((hid.subdet() == HcalBarrel && standardHB_) || (hid.subdet() == HcalEndcap && standardHE_) ||
39  (hid.subdet() == HcalOuter && standardHO_) || (hid.subdet() == HcalForward && standardHF_)) {
40  tid = CaloTowerDetId(m_cttopo->convertHcaltoCT(hid.ietaAbs(), hid.subdet()) * hid.zside(), hid.iphi());
41  }
42  } else if (id.det() == DetId::Ecal) {
43  EcalSubdetector esd = (EcalSubdetector)id.subdetId();
44  if (esd == EcalBarrel && standardEB_) {
45  EBDetId ebid(id);
46  tid = CaloTowerDetId(ebid.tower_ieta(), ebid.tower_iphi());
47  }
48  }
49  }
50 
51  return tid;
52 }
53 
55  if (m_items.find(cell) != m_items.end()) {
56  throw cms::Exception("CaloTowers") << "Cell with id " << std::hex << cell.rawId() << std::dec
57  << " is already mapped to a CaloTower " << m_items.find(cell)->tower
58  << std::endl;
59  }
60  m_items.emplace_back(MapItem(cell, tower));
61 }
62 
64  m_items.sort();
65 
66  // for (auto const & it : m_items)
67  // edm::LogVerbatim("CaloTower") << std::hex << it.cell.rawId() << " " << it.tower.rawId() << std::dec;
68 }
69 
70 std::vector<DetId> CaloTowerConstituentsMap::constituentsOf(const CaloTowerDetId& id) const {
71 #ifdef EDM_ML_DEBUG
72  edm::LogVerbatim("CaloTower") << "Get constituent of " << std::hex << id.rawId() << std::dec << " ID " << id
73  << " ieta " << id.ieta();
74 #endif
75  std::vector<DetId> items;
76  if (id.ieta() == 0)
77  return items;
78 
79  // build reverse map if needed
80  if (!m_reverseItems.load(std::memory_order_acquire)) {
81  std::unique_ptr<std::multimap<CaloTowerDetId, DetId>> ptr{new std::multimap<CaloTowerDetId, DetId>};
82  for (auto m_item : m_items)
83  ptr->insert(std::pair<CaloTowerDetId, DetId>(m_item.tower, m_item.cell));
84  std::multimap<CaloTowerDetId, DetId>* expected = nullptr;
85  if (m_reverseItems.compare_exchange_strong(expected, ptr.get(), std::memory_order_acq_rel)) {
86  ptr.release();
87  }
88  }
89 
91  std::multimap<CaloTowerDetId, DetId>::const_iterator j;
92  auto range = (*m_reverseItems.load(std::memory_order_acquire)).equal_range(id);
93  for (j = range.first; j != range.second; j++)
94  items.emplace_back(j->second);
95 
96  // dealing with topo dependency...
97  //use cttopo when dealing with calotower detids
98  int nd, sd;
99  int hcal_ieta = m_cttopo->convertCTtoHcal(id.ietaAbs());
100 
101  if (standardHB_) {
102  if (id.ietaAbs() <= m_cttopo->lastHBRing()) {
103  m_hcaltopo->depthBinInformation(HcalBarrel, hcal_ieta, id.iphi(), id.zside(), nd, sd);
104  for (int i = 0; i < nd; i++) {
106  HcalDetId hid =
107  m_hcaltopo->mergedDepthDetId(HcalDetId(HcalBarrel, hcal_ieta * id.zside(), id.iphi(), i + sd));
108  if (std::find(items.begin(), items.end(), hid) == items.end()) {
109  items.emplace_back(hid);
110 #ifdef EDM_ML_DEBUG
111  edm::LogVerbatim("CaloTower") << id << " Depth " << i << ":" << i + sd << " " << hid;
112 #endif
113  }
114  } else {
115  HcalDetId hid(HcalBarrel, hcal_ieta * id.zside(), id.iphi(), i + sd);
116  items.emplace_back(hid);
117 #ifdef EDM_ML_DEBUG
118  edm::LogVerbatim("CaloTower") << id << " Depth " << i << ":" << i + sd << " " << hid;
119 #endif
120  }
121  }
122  }
123  }
124  if (standardHO_) {
125  if (id.ietaAbs() <= m_cttopo->lastHORing()) {
126  m_hcaltopo->depthBinInformation(HcalOuter, hcal_ieta, id.iphi(), id.zside(), nd, sd);
127  for (int i = 0; i < nd; i++) {
128  HcalDetId hid(HcalOuter, hcal_ieta * id.zside(), id.iphi(), i + sd);
129  items.emplace_back(hid);
130 #ifdef EDM_ML_DEBUG
131  edm::LogVerbatim("CaloTower") << id << " Depth " << i << ":" << i + sd << " " << hid;
132 #endif
133  }
134  }
135  }
136  if (standardHE_) {
137  if (id.ietaAbs() >= m_cttopo->firstHERing() && id.ietaAbs() <= m_cttopo->lastHERing()) {
138  m_hcaltopo->depthBinInformation(HcalEndcap, hcal_ieta, id.iphi(), id.zside(), nd, sd);
139  for (int i = 0; i < nd; i++) {
141  HcalDetId hid =
142  m_hcaltopo->mergedDepthDetId(HcalDetId(HcalEndcap, hcal_ieta * id.zside(), id.iphi(), i + sd));
143  if (std::find(items.begin(), items.end(), hid) == items.end()) {
144  items.emplace_back(hid);
145 #ifdef EDM_ML_DEBUG
146  edm::LogVerbatim("CaloTower") << id << " Depth " << i << ":" << i + sd << " " << hid;
147 #endif
148  }
149  } else {
150  HcalDetId hid(HcalEndcap, hcal_ieta * id.zside(), id.iphi(), i + sd);
151  items.emplace_back(hid);
152 #ifdef EDM_ML_DEBUG
153  edm::LogVerbatim("CaloTower") << id << " Depth " << i << ":" << i + sd << " " << hid;
154 #endif
155  }
156  }
157  }
158  }
159  if (standardHF_) {
160  if (id.ietaAbs() >= m_cttopo->firstHFRing() && id.ietaAbs() <= m_cttopo->lastHFRing()) {
161  m_hcaltopo->depthBinInformation(HcalForward, hcal_ieta, id.iphi(), id.zside(), nd, sd);
162  for (int i = 0; i < nd; i++) {
163  HcalDetId hid(HcalForward, hcal_ieta * id.zside(), id.iphi(), i + sd);
164  items.emplace_back(hid);
165 #ifdef EDM_ML_DEBUG
166  edm::LogVerbatim("CaloTower") << id << " Depth " << i << ":" << i + sd << " " << hid;
167 #endif
168  }
169  // special handling for first HF tower
170  if (id.ietaAbs() == m_cttopo->firstHFRing()) {
171  int hcal_ieta2 = hcal_ieta - 1;
172  m_hcaltopo->depthBinInformation(HcalForward, hcal_ieta2, id.iphi(), id.zside(), nd, sd);
173  for (int i = 0; i < nd; i++) {
174  HcalDetId hid(HcalForward, hcal_ieta2 * id.zside(), id.iphi(), i + sd);
175  items.emplace_back(hid);
176 #ifdef EDM_ML_DEBUG
177  edm::LogVerbatim("CaloTower") << id << " Depth " << i << ":" << i + sd << " " << hid;
178 #endif
179  }
180  }
181  }
182  }
183  if (standardEB_ && hcal_ieta <= EBDetId::MAX_IETA / 5) {
184  HcalDetId hid(HcalBarrel, hcal_ieta * id.zside(), id.iphi(), 1); // for the limits
185  int etaMin, etaMax;
186  if (hid.zside() == -1) {
187  etaMin = hid.crystal_ieta_high();
188  etaMax = hid.crystal_ieta_low();
189  } else {
190  etaMin = hid.crystal_ieta_low();
191  etaMax = hid.crystal_ieta_high();
192  }
193  for (int ie = etaMin; ie <= etaMax; ie++)
194  for (int ip = hid.crystal_iphi_low(); ip <= hid.crystal_iphi_high(); ip++)
195  items.emplace_back(EBDetId(ie, ip));
196  }
197  return items;
198 }
199 
Log< level::Info, true > LogVerbatim
bool getMergePositionFlag() const
Definition: HcalTopology.h:167
void useStandardHE(bool use=true)
add standard (hardcoded) HE items?
constexpr int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:141
constexpr int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:148
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
std::vector< T >::const_iterator const_iterator
void useStandardEB(bool use=true)
add standard (hardcoded) EB items?
const CaloTowerTopology * m_cttopo
constexpr int crystal_iphi_high() const
get the largest crystal_iphi of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.h:267
int zside(DetId const &)
void sort()
done adding to the association
int lastHFRing() const
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
void useStandardHB(bool use=true)
add standard (hardcoded) HB items?
int lastHERing() const
int lastHORing() const
int tower_ieta() const
get the HCAL/trigger ieta of this crystal
Definition: EBDetId.h:53
ALPAKA_FN_ACC ALPAKA_FN_INLINE uint32_t ietaAbs(uint32_t id)
constexpr bool null() const
is this a null id ?
Definition: DetId.h:59
constexpr HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:138
int firstHERing() const
int convertCTtoHcal(int ct_ieta) const
int convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const
void assign(const DetId &cell, const CaloTowerDetId &tower)
set the association between a DetId and a tower
int tower_iphi() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.cc:100
constexpr int crystal_ieta_high() const
get the largest crystal_ieta of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.h:259
constexpr int crystal_ieta_low() const
get the smallest crystal_ieta of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.h:257
Definition: DetId.h:17
void useStandardHO(bool use=true)
add standard (hardcoded) HO items?
void depthBinInformation(HcalSubdetector subdet, int etaRing, int iphi, int zside, int &nDepthBins, int &startingBin) const
finds the number of depth bins and which is the number to start with
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static const int MAX_IETA
Definition: EBDetId.h:136
HcalDetId mergedDepthDetId(const HcalDetId &id) const
Definition: HcalTopology.h:166
int firstHFRing() const
EcalSubdetector
if(threadIdxLocalY==0 &&threadIdxLocalX==0)
constexpr int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
std::vector< DetId > constituentsOf(const CaloTowerDetId &id) const
Get the constituent detids for this tower id ( not yet implemented )
void useStandardHF(bool use=true)
add standard (hardcoded) HF items?
constexpr int crystal_iphi_low() const
get the smallest crystal_iphi of the crystal in front of this tower (HB and HE tower 17 only) ...
Definition: HcalDetId.h:261
std::atomic< std::multimap< CaloTowerDetId, DetId > * > m_reverseItems
int lastHBRing() const
edm::SortedCollection< MapItem > m_items