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.load();
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 // for (auto const & it : m_items)
65 // std::cout << std::hex << it.cell.rawId() << " " << it.tower.rawId() << std::dec << std::endl;
66 
67 }
68 
69 std::vector<DetId> CaloTowerConstituentsMap::constituentsOf(const CaloTowerDetId& id) const {
70  std::vector<DetId> items;
71 
72  // build reverse map if needed
73  if(!m_reverseItems.load(std::memory_order_acquire)) {
74  std::unique_ptr<std::multimap<CaloTowerDetId,DetId>> ptr{new std::multimap<CaloTowerDetId,DetId>};
75  for (auto i=m_items.begin(); i!=m_items.end(); i++)
76  ptr->insert(std::pair<CaloTowerDetId,DetId>(i->tower,i->cell));
77  std::multimap<CaloTowerDetId,DetId>* expected = nullptr;
78  if(m_reverseItems.compare_exchange_strong(expected, ptr.get(), std::memory_order_acq_rel)) {
79  ptr.release();
80  }
81  }
82 
84  std::multimap<CaloTowerDetId,DetId>::const_iterator j;
85  auto range=(*m_reverseItems.load(std::memory_order_acquire)).equal_range(id);
86  for (j=range.first; j!=range.second; j++)
87  items.push_back(j->second);
88 
89  // dealing with topo dependency...
90  int nd, sd;
91 
92  if (standardHB_) {
93  if (id.ietaAbs()<=m_topology->lastHBRing()) {
94  m_topology->depthBinInformation(HcalBarrel,id.ietaAbs(),nd,sd);
95  for (int i=0; i<nd; i++)
96  items.push_back(HcalDetId(HcalBarrel,id.ieta(),id.iphi(),i+sd));
97  }
98  }
99  if (standardHO_) {
100  if (id.ietaAbs()<=m_topology->lastHORing()) {
101  m_topology->depthBinInformation(HcalOuter,id.ietaAbs(),nd,sd);
102  for (int i=0; i<nd; i++)
103  items.push_back(HcalDetId(HcalOuter,id.ieta(),id.iphi(),i+sd));
104  }
105  }
106  if (standardHE_) {
107  if (id.ietaAbs()>=m_topology->firstHERing() && id.ietaAbs()<=m_topology->lastHERing()) {
108  m_topology->depthBinInformation(HcalEndcap,id.ietaAbs(),nd,sd);
109  for (int i=0; i<nd; i++)
110  items.push_back(HcalDetId(HcalEndcap,id.ieta(),id.iphi(),i+sd));
111  }
112  }
113  if (standardHF_) {
114  if (id.ietaAbs()>m_topology->firstHFRing() && id.ietaAbs()<=m_topology->lastHFRing()) {
115  int ieta=id.ieta();
116  m_topology->depthBinInformation(HcalForward,id.ietaAbs(),nd,sd);
117  for (int i=0; i<nd; i++)
118  items.push_back(HcalDetId(HcalForward,ieta,id.iphi(),i+sd));
119  if (id.ietaAbs() == 30) {
120  ieta = 29*id.zside();
122  for (int i=0; i<nd; i++)
123  items.push_back(HcalDetId(HcalForward,ieta,id.iphi(),i+sd));
124  }
125  }
126  }
127  if (standardEB_ && id.ietaAbs()<=EBDetId::MAX_IETA/5) {
128  HcalDetId hid(HcalBarrel,id.ieta(),id.iphi(),1); // for the limits
129  int etaMin, etaMax;
130  if (hid.zside() == -1) {
131  etaMin = hid.crystal_ieta_high();
132  etaMax = hid.crystal_ieta_low();
133  } else {
134  etaMin = hid.crystal_ieta_low();
135  etaMax = hid.crystal_ieta_high();
136  }
137  for (int ie=etaMin; ie<=etaMax; ie++)
138  for (int ip=hid.crystal_iphi_low(); ip<=hid.crystal_iphi_high(); ip++)
139  items.push_back(EBDetId(ie,ip));
140  }
141  return items;
142 }
143 
145  standardHB_=use;
146 }
148  standardHE_=use;
149 }
151  standardHO_=use;
152 }
154  standardHF_=use;
155 }
157  standardEB_=use;
158 }
int firstHFRing() const
Definition: HcalTopology.h:83
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:45
CaloTopology const * topology(0)
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:47
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:47
std::vector< T >::const_iterator const_iterator
void useStandardEB(bool use=true)
add standard (hardcoded) EB items?
int lastHBRing() const
Definition: HcalTopology.h:80
void sort()
done adding to the association
#define nullptr
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:59
int ieta() const
get the cell ieta
Definition: HcalDetId.h:51
int lastHFRing() const
Definition: HcalTopology.h:84
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:49
int iphi() const
get the cell iphi
Definition: HcalDetId.h:53
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:61
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:81
std::atomic< std::multimap< CaloTowerDetId, DetId > * > m_reverseItems
volatile std::atomic< bool > shutdown_flag false
if(conf.exists("allCellsPositionCalc"))
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:53
EcalSubdetector
int lastHORing() const
Definition: HcalTopology.h:86
void useStandardHF(bool use=true)
add standard (hardcoded) HF items?
int lastHERing() const
Definition: HcalTopology.h:82
edm::SortedCollection< MapItem > m_items