CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CaloTowerConstituentsMap.cc
Go to the documentation of this file.
6 
7 #include <memory>
8 
10  delete m_reverseItems;
11  m_reverseItems = nullptr;
12 }
14  m_topology(topology),
15  standardHB_(false),
16  standardHE_(false),
17  standardHF_(false),
18  standardHO_(false),
19  standardEB_(false),
20  m_reverseItems(nullptr)
21 {
22 }
23 
25  CaloTowerDetId tid; // null to start with
26 
28  if (i!=m_items.end()) tid=i->tower;
29 
30  if (tid.null()) {
31  if (id.det()==DetId::Hcal) {
32  HcalDetId hid(id);
33  if ( (hid.subdet()==HcalBarrel && standardHB_ ) ||
34  (hid.subdet()==HcalEndcap && standardHE_ ) ||
35  (hid.subdet()==HcalOuter && standardHO_ ) ||
36  (hid.subdet()==HcalForward && standardHF_) ) {
37  if ((hid.subdet()==HcalForward) && hid.ietaAbs()==29) // special handling for tower 29
38  tid=CaloTowerDetId(30*hid.zside(),hid.iphi());
39  else
40  tid=CaloTowerDetId(hid.ieta(),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 
54 void CaloTowerConstituentsMap::assign(const DetId& cell, const CaloTowerDetId& tower) {
55  if (m_items.find(cell)!=m_items.end()) {
56  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;
57  }
58  m_items.push_back(MapItem(cell,tower));
59 }
60 
62  m_items.sort();
63 }
64 
65 std::vector<DetId> CaloTowerConstituentsMap::constituentsOf(const CaloTowerDetId& id) const {
66  std::vector<DetId> items;
67 
68  // build reverse map if needed
69  if(!m_reverseItems.load(std::memory_order_acquire)) {
70  std::unique_ptr<std::multimap<CaloTowerDetId,DetId>> ptr{new std::multimap<CaloTowerDetId,DetId>};
71  for (auto i=m_items.begin(); i!=m_items.end(); i++)
72  ptr->insert(std::pair<CaloTowerDetId,DetId>(i->tower,i->cell));
73  std::multimap<CaloTowerDetId,DetId>* expected = nullptr;
74  if(m_reverseItems.compare_exchange_strong(expected, ptr.get(), std::memory_order_acq_rel)) {
75  ptr.release();
76  }
77  }
78 
80  std::multimap<CaloTowerDetId,DetId>::const_iterator j;
81  auto range=(*m_reverseItems.load(std::memory_order_acquire)).equal_range(id);
82  for (j=range.first; j!=range.second; j++)
83  items.push_back(j->second);
84 
85  // dealing with topo dependency...
86  int nd, sd;
87 
88  if (standardHB_) {
89  if (id.ietaAbs()<=m_topology->lastHBRing()) {
90  m_topology->depthBinInformation(HcalBarrel,id.ietaAbs(),nd,sd);
91  for (int i=0; i<nd; i++)
92  items.push_back(HcalDetId(HcalBarrel,id.ieta(),id.iphi(),i+sd));
93  }
94  }
95  if (standardHO_) {
96  if (id.ietaAbs()<=m_topology->lastHORing()) {
97  m_topology->depthBinInformation(HcalOuter,id.ietaAbs(),nd,sd);
98  for (int i=0; i<nd; i++)
99  items.push_back(HcalDetId(HcalOuter,id.ieta(),id.iphi(),i+sd));
100  }
101  }
102  if (standardHE_) {
103  if (id.ietaAbs()>=m_topology->firstHERing() && id.ietaAbs()<=m_topology->lastHERing()) {
104  m_topology->depthBinInformation(HcalEndcap,id.ietaAbs(),nd,sd);
105  for (int i=0; i<nd; i++)
106  items.push_back(HcalDetId(HcalEndcap,id.ieta(),id.iphi(),i+sd));
107  }
108  }
109  if (standardHF_) {
110  if (id.ietaAbs()>m_topology->firstHFRing() && id.ietaAbs()<=m_topology->lastHFRing()) {
111  int ieta=id.ieta();
112  m_topology->depthBinInformation(HcalForward,id.ietaAbs(),nd,sd);
113  for (int i=0; i<nd; i++)
114  items.push_back(HcalDetId(HcalForward,ieta,id.iphi(),i+sd));
115  if (id.ietaAbs() == 30) {
116  ieta = 29*id.zside();
118  for (int i=0; i<nd; i++)
119  items.push_back(HcalDetId(HcalForward,ieta,id.iphi(),i+sd));
120  }
121  }
122  }
123  if (standardEB_ && id.ietaAbs()<=EBDetId::MAX_IETA/5) {
124  HcalDetId hid(HcalBarrel,id.ieta(),id.iphi(),1); // for the limits
125  int etaMin, etaMax;
126  if (hid.zside() == -1) {
127  etaMin = hid.crystal_ieta_high();
128  etaMax = hid.crystal_ieta_low();
129  } else {
130  etaMin = hid.crystal_ieta_low();
131  etaMax = hid.crystal_ieta_high();
132  }
133  for (int ie=etaMin; ie<=etaMax; ie++)
134  for (int ip=hid.crystal_iphi_low(); ip<=hid.crystal_iphi_high(); ip++)
135  items.push_back(EBDetId(ie,ip));
136  }
137  return items;
138 }
139 
141  standardHB_=use;
142 }
144  standardHE_=use;
145 }
147  standardHO_=use;
148 }
150  standardHF_=use;
151 }
153  standardEB_=use;
154 }
int firstHFRing() const
Definition: HcalTopology.h:81
int i
Definition: DBlmapReader.cc:9
void useStandardHE(bool use=true)
add standard (hardcoded) HE items?
HcalSubdetector subdet() const
get the subdetector
Definition: HcalDetId.h:30
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:32
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:46
#define nullptr
std::vector< T >::const_iterator const_iterator
void useStandardEB(bool use=true)
add standard (hardcoded) EB items?
int lastHBRing() const
Definition: HcalTopology.h:78
void sort()
done adding to the association
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 )
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:42
int ieta() const
get the cell ieta
Definition: HcalDetId.h:36
int lastHFRing() const
Definition: HcalTopology.h:82
int j
Definition: DBlmapReader.cc:9
void depthBinInformation(HcalSubdetector subdet, int etaRing, int &nDepthBins, int &startingBin) const
finds the number of depth bins and which is the number to start with
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:34
int iphi() const
get the cell iphi
Definition: HcalDetId.h:38
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:44
bool null() const
is this a null id ?
Definition: DetId.h:45
static const int MAX_IETA
Definition: EBDetId.h:143
int firstHERing() const
Definition: HcalTopology.h:79
if(dp >Float(M_PI)) dp-
std::atomic< std::multimap< CaloTowerDetId, DetId > * > m_reverseItems
volatile std::atomic< bool > shutdown_flag false
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:52
EcalSubdetector
int lastHORing() const
Definition: HcalTopology.h:84
void useStandardHF(bool use=true)
add standard (hardcoded) HF items?
int lastHERing() const
Definition: HcalTopology.h:80
edm::SortedCollection< MapItem > m_items