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.
7 
8 #include <memory>
9 
11  delete m_reverseItems.load();
12  m_reverseItems = nullptr;
13 }
15  m_hcaltopo(hcaltopo),
16  m_cttopo(cttopo),
17  standardHB_(false),
18  standardHE_(false),
19  standardHF_(false),
20  standardHO_(false),
21  standardEB_(false),
22  m_reverseItems(nullptr)
23 {
24 }
25 
27  CaloTowerDetId tid; // null to start with
28 
30  if (i!=m_items.end()) tid=i->tower;
31 
32  //use hcaltopo when dealing with hcal detids
33  if (tid.null()) {
34  if (id.det()==DetId::Hcal) {
35  HcalDetId hid(id);
36  if ( (hid.subdet()==HcalBarrel && standardHB_ ) ||
37  (hid.subdet()==HcalEndcap && standardHE_ ) ||
38  (hid.subdet()==HcalOuter && standardHO_ ) ||
39  (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 
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  //use cttopo when dealing with calotower detids
91  int nd, sd;
92  int hcal_ieta = m_cttopo->convertCTtoHcal(id.ietaAbs());
93 
94  if (standardHB_) {
95  if (id.ietaAbs()<=m_cttopo->lastHBRing()) {
96  m_hcaltopo->depthBinInformation(HcalBarrel,hcal_ieta,nd,sd);
97  for (int i=0; i<nd; i++)
98  items.push_back(HcalDetId(HcalBarrel,hcal_ieta*id.zside(),id.iphi(),i+sd));
99  }
100  }
101  if (standardHO_) {
102  if (id.ietaAbs()<=m_cttopo->lastHORing()) {
103  m_hcaltopo->depthBinInformation(HcalOuter,hcal_ieta,nd,sd);
104  for (int i=0; i<nd; i++)
105  items.push_back(HcalDetId(HcalOuter,hcal_ieta*id.zside(),id.iphi(),i+sd));
106  }
107  }
108  if (standardHE_) {
109  if (id.ietaAbs()>=m_cttopo->firstHERing() && id.ietaAbs()<=m_cttopo->lastHERing()) {
110  m_hcaltopo->depthBinInformation(HcalEndcap,hcal_ieta,nd,sd);
111  for (int i=0; i<nd; i++)
112  items.push_back(HcalDetId(HcalEndcap,hcal_ieta*id.zside(),id.iphi(),i+sd));
113  }
114  }
115  if (standardHF_) {
116  if (id.ietaAbs()>=m_cttopo->firstHFRing() && id.ietaAbs()<=m_cttopo->lastHFRing()) {
117  m_hcaltopo->depthBinInformation(HcalForward,hcal_ieta,nd,sd);
118  for (int i=0; i<nd; i++)
119  items.push_back(HcalDetId(HcalForward,hcal_ieta*id.zside(),id.iphi(),i+sd));
120  // special handling for first HF tower
121  if (id.ietaAbs() == m_cttopo->firstHFRing()) {
122  int hcal_ieta2 = hcal_ieta-1;
123  m_hcaltopo->depthBinInformation(HcalForward,hcal_ieta2,nd,sd);
124  for (int i=0; i<nd; i++)
125  items.push_back(HcalDetId(HcalForward,hcal_ieta2*id.zside(),id.iphi(),i+sd));
126  }
127  }
128  }
129  if (standardEB_ && hcal_ieta<=EBDetId::MAX_IETA/5) {
130  HcalDetId hid(HcalBarrel,hcal_ieta*id.zside(),id.iphi(),1); // for the limits
131  int etaMin, etaMax;
132  if (hid.zside() == -1) {
133  etaMin = hid.crystal_ieta_high();
134  etaMax = hid.crystal_ieta_low();
135  } else {
136  etaMin = hid.crystal_ieta_low();
137  etaMax = hid.crystal_ieta_high();
138  }
139  for (int ie=etaMin; ie<=etaMax; ie++)
140  for (int ip=hid.crystal_iphi_low(); ip<=hid.crystal_iphi_high(); ip++)
141  items.push_back(EBDetId(ie,ip));
142  }
143  return items;
144 }
145 
147  standardHB_=use;
148 }
150  standardHE_=use;
151 }
153  standardHO_=use;
154 }
156  standardHF_=use;
157 }
159  standardEB_=use;
160 }
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
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.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?
const CaloTowerTopology * m_cttopo
int zside(DetId const &)
void sort()
done adding to the association
#define nullptr
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 )
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
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:59
int j
Definition: DBlmapReader.cc:9
if(c.getParameter< edm::InputTag >("puppiValueMap").label().size()!=0)
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 lastHERing() const
std::atomic< std::multimap< CaloTowerDetId, DetId > * > m_reverseItems
int convertCTtoHcal(int ct_ieta) const
int lastHORing() const
int lastHBRing() const
volatile std::atomic< bool > shutdown_flag false
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.cc:53
EcalSubdetector
void useStandardHF(bool use=true)
add standard (hardcoded) HF items?
edm::SortedCollection< MapItem > m_items