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.push_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  std::vector<DetId> items;
73 
74  // build reverse map if needed
75  if(!m_reverseItems.load(std::memory_order_acquire)) {
76  std::unique_ptr<std::multimap<CaloTowerDetId,DetId>> ptr{new std::multimap<CaloTowerDetId,DetId>};
77  for (auto i=m_items.begin(); i!=m_items.end(); i++)
78  ptr->insert(std::pair<CaloTowerDetId,DetId>(i->tower,i->cell));
79  std::multimap<CaloTowerDetId,DetId>* expected = nullptr;
80  if(m_reverseItems.compare_exchange_strong(expected, ptr.get(), std::memory_order_acq_rel)) {
81  ptr.release();
82  }
83  }
84 
86  std::multimap<CaloTowerDetId,DetId>::const_iterator j;
87  auto range=(*m_reverseItems.load(std::memory_order_acquire)).equal_range(id);
88  for (j=range.first; j!=range.second; j++)
89  items.push_back(j->second);
90 
91  // dealing with topo dependency...
92  //use cttopo when dealing with calotower detids
93  int nd, sd;
94  int hcal_ieta = m_cttopo->convertCTtoHcal(id.ietaAbs());
95 
96  if (standardHB_) {
97  if (id.ietaAbs()<=m_cttopo->lastHBRing()) {
98  m_hcaltopo->depthBinInformation(HcalBarrel,hcal_ieta,id.iphi(),id.zside(),nd,sd);
99  for (int i=0; i<nd; i++) {
101  HcalDetId hid = m_hcaltopo->mergedDepthDetId(HcalDetId(HcalBarrel,hcal_ieta*id.zside(),id.iphi(),i+sd));
102  if (std::find(items.begin(),items.end(),hid) == items.end()) {
103  items.push_back(hid);
104 #ifdef EDM_ML_DEBUG
105  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
106 #endif
107  }
108  } else {
109  HcalDetId hid(HcalBarrel,hcal_ieta*id.zside(),id.iphi(),i+sd);
110  items.push_back(hid);
111 #ifdef EDM_ML_DEBUG
112  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
113 #endif
114  }
115  }
116  }
117  }
118  if (standardHO_) {
119  if (id.ietaAbs()<=m_cttopo->lastHORing()) {
120  m_hcaltopo->depthBinInformation(HcalOuter,hcal_ieta,id.iphi(),id.zside(),nd,sd);
121  for (int i=0; i<nd; i++) {
122  HcalDetId hid(HcalOuter,hcal_ieta*id.zside(),id.iphi(),i+sd);
123  items.push_back(hid);
124 #ifdef EDM_ML_DEBUG
125  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
126 #endif
127  }
128  }
129  }
130  if (standardHE_) {
131  if (id.ietaAbs()>=m_cttopo->firstHERing() && id.ietaAbs()<=m_cttopo->lastHERing()) {
132  m_hcaltopo->depthBinInformation(HcalEndcap,hcal_ieta,id.iphi(),id.zside(),nd,sd);
133  for (int i=0; i<nd; i++) {
135  HcalDetId hid = m_hcaltopo->mergedDepthDetId(HcalDetId(HcalEndcap,hcal_ieta*id.zside(),id.iphi(),i+sd));
136  if (std::find(items.begin(),items.end(),hid) == items.end()) {
137  items.push_back(hid);
138 #ifdef EDM_ML_DEBUG
139  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
140 #endif
141  }
142  } else {
143  HcalDetId hid(HcalEndcap,hcal_ieta*id.zside(),id.iphi(),i+sd);
144  items.push_back(hid);
145 #ifdef EDM_ML_DEBUG
146  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
147 #endif
148  }
149  }
150  }
151  }
152  if (standardHF_) {
153  if (id.ietaAbs()>=m_cttopo->firstHFRing() && id.ietaAbs()<=m_cttopo->lastHFRing()) {
154  m_hcaltopo->depthBinInformation(HcalForward,hcal_ieta,id.iphi(),id.zside(),nd,sd);
155  for (int i=0; i<nd; i++) {
156  HcalDetId hid(HcalForward,hcal_ieta*id.zside(),id.iphi(),i+sd);
157  items.push_back(hid);
158 #ifdef EDM_ML_DEBUG
159  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
160 #endif
161  }
162  // special handling for first HF tower
163  if (id.ietaAbs() == m_cttopo->firstHFRing()) {
164  int hcal_ieta2 = hcal_ieta-1;
165  m_hcaltopo->depthBinInformation(HcalForward,hcal_ieta2,id.iphi(),id.zside(),nd,sd);
166  for (int i=0; i<nd; i++) {
167  HcalDetId hid(HcalForward,hcal_ieta2*id.zside(),id.iphi(),i+sd);
168  items.push_back(hid);
169 #ifdef EDM_ML_DEBUG
170  std::cout << id << " Depth " << i << ":" << i+sd << " " << hid <<"\n";
171 #endif
172  }
173  }
174  }
175  }
176  if (standardEB_ && hcal_ieta<=EBDetId::MAX_IETA/5) {
177  HcalDetId hid(HcalBarrel,hcal_ieta*id.zside(),id.iphi(),1); // for the limits
178  int etaMin, etaMax;
179  if (hid.zside() == -1) {
180  etaMin = hid.crystal_ieta_high();
181  etaMax = hid.crystal_ieta_low();
182  } else {
183  etaMin = hid.crystal_ieta_low();
184  etaMax = hid.crystal_ieta_high();
185  }
186  for (int ie=etaMin; ie<=etaMax; ie++)
187  for (int ip=hid.crystal_iphi_low(); ip<=hid.crystal_iphi_high(); ip++)
188  items.push_back(EBDetId(ie,ip));
189  }
190  return items;
191 }
192 
194  standardHB_=use;
195 }
197  standardHE_=use;
198 }
200  standardHO_=use;
201 }
203  standardHF_=use;
204 }
206  standardEB_=use;
207 }
void useStandardHE(bool use=true)
add standard (hardcoded) HE items?
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:49
int convertHcaltoCT(int hcal_ieta, HcalSubdetector subdet) const
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.cc:93
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.cc:201
std::vector< T >::const_iterator const_iterator
void useStandardEB(bool use=true)
add standard (hardcoded) EB items?
const CaloTowerTopology * m_cttopo
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
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:163
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:77
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.cc:98
int iphi() const
get the cell iphi
Definition: HcalDetId.cc:103
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:79
bool null() const
is this a null id ?
Definition: DetId.h:45
static const int MAX_IETA
Definition: EBDetId.h:143
int lastHERing() const
if(dp >Float(M_PI)) dp-
std::atomic< std::multimap< CaloTowerDetId, DetId > * > m_reverseItems
int convertCTtoHcal(int ct_ieta) const
int lastHORing() const
int lastHBRing() const
int firstHFRing() const
bool withSpecialRBXHBHE() const
Definition: HcalTopology.h:162
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.cc:207
EcalSubdetector
void useStandardHF(bool use=true)
add standard (hardcoded) HF items?
edm::SortedCollection< MapItem > m_items