CMS 3D CMS Logo

CaloTowerConstituentsMap.cc
Go to the documentation of this file.
7 
8 #include <memory>
9 
10 //#define EDM_ML_DEBUG
11 
13  delete m_reverseItems.load();
14  m_reverseItems = nullptr;
15 }
17  m_hcaltopo(hcaltopo),
18  m_cttopo(cttopo),
25 {
26 }
27 
29  CaloTowerDetId tid; // null to start with
30 
32  if (i!=m_items.end()) 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_ ) ||
39  (hid.subdet()==HcalEndcap && standardHE_ ) ||
40  (hid.subdet()==HcalOuter && standardHO_ ) ||
41  (hid.subdet()==HcalForward && standardHF_) ) {
42  tid = CaloTowerDetId(m_cttopo->convertHcaltoCT(hid.ietaAbs(),hid.subdet())*hid.zside(),hid.iphi());
43  }
44  } else if (id.det()==DetId::Ecal) {
45  EcalSubdetector esd=(EcalSubdetector)id.subdetId();
46  if (esd==EcalBarrel && standardEB_) {
47  EBDetId ebid(id);
48  tid=CaloTowerDetId(ebid.tower_ieta(),ebid.tower_iphi());
49  }
50  }
51  }
52 
53  return tid;
54 }
55 
56 void CaloTowerConstituentsMap::assign(const DetId& cell, const CaloTowerDetId& tower) {
57  if (m_items.find(cell)!=m_items.end()) {
58  throw cms::Exception("CaloTowers") << "Cell with id " << std::hex << cell.rawId() << std::dec << " is already mapped to a CaloTower " << m_items.find(cell)->tower << 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 // std::cout << std::hex << it.cell.rawId() << " " << it.tower.rawId() << std::dec << std::endl;
68 
69 }
70 
71 std::vector<DetId> CaloTowerConstituentsMap::constituentsOf(const CaloTowerDetId& id) const {
72 #ifdef EDM_ML_DEBUG
73  std::cout << "Get constituent of " << std::hex << id.rawId() << std::dec
74  << " ID " << id << " ieta " << id.ieta() << std::endl;
75 #endif
76  std::vector<DetId> items;
77  if (id.ieta() == 0) 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 = m_hcaltopo->mergedDepthDetId(HcalDetId(HcalBarrel,hcal_ieta*id.zside(),id.iphi(),i+sd));
107  if (std::find(items.begin(),items.end(),hid) == items.end()) {
108  items.emplace_back(hid);
109 #ifdef EDM_ML_DEBUG
110  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
111 #endif
112  }
113  } else {
114  HcalDetId hid(HcalBarrel,hcal_ieta*id.zside(),id.iphi(),i+sd);
115  items.emplace_back(hid);
116 #ifdef EDM_ML_DEBUG
117  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
118 #endif
119  }
120  }
121  }
122  }
123  if (standardHO_) {
124  if (id.ietaAbs()<=m_cttopo->lastHORing()) {
125  m_hcaltopo->depthBinInformation(HcalOuter,hcal_ieta,id.iphi(),id.zside(),nd,sd);
126  for (int i=0; i<nd; i++) {
127  HcalDetId hid(HcalOuter,hcal_ieta*id.zside(),id.iphi(),i+sd);
128  items.emplace_back(hid);
129 #ifdef EDM_ML_DEBUG
130  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
131 #endif
132  }
133  }
134  }
135  if (standardHE_) {
136  if (id.ietaAbs()>=m_cttopo->firstHERing() && id.ietaAbs()<=m_cttopo->lastHERing()) {
137  m_hcaltopo->depthBinInformation(HcalEndcap,hcal_ieta,id.iphi(),id.zside(),nd,sd);
138  for (int i=0; i<nd; i++) {
140  HcalDetId hid = m_hcaltopo->mergedDepthDetId(HcalDetId(HcalEndcap,hcal_ieta*id.zside(),id.iphi(),i+sd));
141  if (std::find(items.begin(),items.end(),hid) == items.end()) {
142  items.emplace_back(hid);
143 #ifdef EDM_ML_DEBUG
144  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
145 #endif
146  }
147  } else {
148  HcalDetId hid(HcalEndcap,hcal_ieta*id.zside(),id.iphi(),i+sd);
149  items.emplace_back(hid);
150 #ifdef EDM_ML_DEBUG
151  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
152 #endif
153  }
154  }
155  }
156  }
157  if (standardHF_) {
158  if (id.ietaAbs()>=m_cttopo->firstHFRing() && id.ietaAbs()<=m_cttopo->lastHFRing()) {
159  m_hcaltopo->depthBinInformation(HcalForward,hcal_ieta,id.iphi(),id.zside(),nd,sd);
160  for (int i=0; i<nd; i++) {
161  HcalDetId hid(HcalForward,hcal_ieta*id.zside(),id.iphi(),i+sd);
162  items.emplace_back(hid);
163 #ifdef EDM_ML_DEBUG
164  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
165 #endif
166  }
167  // special handling for first HF tower
168  if (id.ietaAbs() == m_cttopo->firstHFRing()) {
169  int hcal_ieta2 = hcal_ieta-1;
170  m_hcaltopo->depthBinInformation(HcalForward,hcal_ieta2,id.iphi(),id.zside(),nd,sd);
171  for (int i=0; i<nd; i++) {
172  HcalDetId hid(HcalForward,hcal_ieta2*id.zside(),id.iphi(),i+sd);
173  items.emplace_back(hid);
174 #ifdef EDM_ML_DEBUG
175  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
176 #endif
177  }
178  }
179  }
180  }
181  if (standardEB_ && hcal_ieta<=EBDetId::MAX_IETA/5) {
182  HcalDetId hid(HcalBarrel,hcal_ieta*id.zside(),id.iphi(),1); // for the limits
183  int etaMin, etaMax;
184  if (hid.zside() == -1) {
185  etaMin = hid.crystal_ieta_high();
186  etaMax = hid.crystal_ieta_low();
187  } else {
188  etaMin = hid.crystal_ieta_low();
189  etaMax = hid.crystal_ieta_high();
190  }
191  for (int ie=etaMin; ie<=etaMax; ie++)
192  for (int ip=hid.crystal_iphi_low(); ip<=hid.crystal_iphi_high(); ip++)
193  items.emplace_back(EBDetId(ie,ip));
194  }
195  return items;
196 }
197 
199  standardHB_=use;
200 }
202  standardHE_=use;
203 }
205  standardHO_=use;
206 }
208  standardHF_=use;
209 }
211  standardEB_=use;
212 }
void useStandardHE(bool use=true)
add standard (hardcoded) HE items?
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:142
int convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const
constexpr bool null() const
is this a null id ?
Definition: DetId.h:49
int tower_ieta() const
get the HCAL/trigger ieta of this crystal
Definition: EBDetId.h:55
int zside() const
get the z-side of the cell (1/-1)
Definition: HcalDetId.h:145
int tower_iphi() const
get the HCAL/trigger iphi of this crystal
Definition: EBDetId.cc:114
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:256
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:47
std::vector< T >::const_iterator const_iterator
void useStandardEB(bool use=true)
add standard (hardcoded) EB items?
const CaloTowerTopology * m_cttopo
int zside(DetId const &)
void sort()
done adding to the association
#define nullptr
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:20
bool getMergePositionFlag() const
Definition: HcalTopology.h:170
int firstHERing() const
void useStandardHB(bool use=true)
add standard (hardcoded) HB items?
std::vector< DetId > constituentsOf(const CaloTowerDetId &id) const
Get the constituent detids for this tower id ( not yet implemented )
HcalDetId mergedDepthDetId(const HcalDetId &id) const
Definition: HcalTopology.h:169
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
int lastHFRing() const
CaloTowerDetId towerOf(const DetId &id) const
Get the tower id for this det id (or null if not known)
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:252
void assign(const DetId &cell, const CaloTowerDetId &tower)
set the association between a DetId and a tower
int ietaAbs() const
get the absolute value of the cell ieta
Definition: HcalDetId.h:150
int iphi() const
get the cell iphi
Definition: HcalDetId.h:157
Definition: DetId.h:18
void useStandardHO(bool use=true)
add standard (hardcoded) HO items?
double sd
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:254
static const int MAX_IETA
Definition: EBDetId.h:143
int lastHERing() const
std::atomic< std::multimap< CaloTowerDetId, DetId > * > m_reverseItems
int convertCTtoHcal(int ct_ieta) const
int lastHORing() const
int lastHBRing() const
int firstHFRing() const
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:262
EcalSubdetector
void useStandardHF(bool use=true)
add standard (hardcoded) HF items?
edm::SortedCollection< MapItem > m_items