CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CastorTopology.cc
Go to the documentation of this file.
2 #include <cmath>
3 #include <iostream>
4 #include <algorithm>
5 
6 static const int MODULE_EM_MAX = 2;
7 static const int MODULE_HAD_MAX = 12;
8 
10  excludeEM_(false),
11  excludeHAD_(false),
12  excludeZP_(false),
13  excludeZN_(false),
14  firstEMModule_(1),
15  lastEMModule_(2),
16  firstHADModule_(3),
17  lastHADModule_(14)
18 {
19 }
20 
21 bool
23 {
24  return ( validRaw( id ) &&
25  !isExcluded( id ) ) ;
26 }
27 
29  bool exed=false;
30 
31  // check for section exclutions
32  switch (id.section()) {
33  case(HcalCastorDetId::EM) : exed = excludeEM_; break;
34  case(HcalCastorDetId::HAD) : exed = excludeHAD_; break;
35  default: exed = false;
36  }
37 
38  // check the entire list
39  if (!exed && !exclusionList_.empty()) {
40  std::vector<HcalCastorDetId>::const_iterator
41  i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
42  if (i!=exclusionList_.end() && *i==id) exed=true;
43  }
44  return exed;
45 }
46 
48  std::vector<HcalCastorDetId>::iterator
49  i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
50  if (i==exclusionList_.end() || *i!=id) {
51  exclusionList_.insert(i,id);
52  }
53 }
54 
56  switch(zside){
57  case( 1): excludeZP_ = true; break;
58  case(-1): excludeZN_ = true; break;
59  default: break;
60  }
61 }
62 
64  switch(zside){
65  case( 1): excludeZP_ = true; break;
66  case(-1): excludeZN_ = true; break;
67  default: break;
68  }
69  switch (section) {
70  case(HcalCastorDetId::EM) : excludeEM_ = true; break;
71  case(HcalCastorDetId::HAD) : excludeHAD_ = true; break;
72  default: break;
73  }
74 }
75 
76 int CastorTopology::exclude(int zside, HcalCastorDetId::Section section1, int isec1, int imod1,
77 HcalCastorDetId::Section section2, int isec2, int imod2) {
78  bool exed = false;
79  switch(zside){
80  case( 1): exed = excludeZP_; break;
81  case(-1): exed = excludeZN_; break;
82  default: exed = false;
83  }
84  if (exed) return 0;
85 
86 
87 /* NOTE not so sure about the exclusion */
88  if (section1 == HcalCastorDetId::EM && section2 == HcalCastorDetId::EM) {
89  exed = excludeEM_; }
90  else if (section1 == HcalCastorDetId::HAD && section2 == HcalCastorDetId::HAD) {
91  exed = excludeHAD_; }
92  else { exed = false; };
93 
94  if (exed) return 0;
95 
96  bool isPositive = false;
97  if(zside == 1)isPositive = true;
98 
99  int n = 0;
100  for (int isec = isec1; isec < isec2; isec++){
101  for (int imod = imod1; imod < imod2; imod++) {
102  HcalCastorDetId id(section1, isPositive, isec, imod);
103  if(validRaw(id))exclude(id);
104  n++;
105  }
106  }
107  return n;
108 }
109 
111 {
112  return HcalCastorDetId::validDetId( id.section(),
113  id.zside()>0,
114  id.sector(),
115  id.module() ) ;
116 }
117 
118 std::vector<DetId> CastorTopology::incSector(const DetId& id) const{
119  std::vector<DetId> vNeighborsDetId;
120  HcalCastorDetId castorId = HcalCastorDetId(id);
121  HcalCastorDetId castorDetId;
122  if(validRaw(castorId)) {
123  bool isPositive = false;
124  if(castorId.zside()==1)isPositive = true;
125  if(castorId.sector()==1) {
126  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()+1,
127 castorId.module());
128  vNeighborsDetId.push_back(castorDetId.rawId());
129  return vNeighborsDetId;
130  }
131  if(castorId.sector()== 16){
132  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()-1,
133 castorId.module());
134  vNeighborsDetId.push_back(castorDetId.rawId());
135  return vNeighborsDetId;
136  }
137  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()-1,
138 castorId.module());
139  vNeighborsDetId.push_back(castorDetId.rawId());
140  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()+1,
141 castorId.module());
142  vNeighborsDetId.push_back(castorDetId.rawId());
143  }
144  return vNeighborsDetId;
145 }
146 
147 std::vector<DetId> CastorTopology::incModule(const DetId& id) const{
148  std::vector<DetId> vNeighborsDetId;
149  HcalCastorDetId castorId = HcalCastorDetId(id);
150  HcalCastorDetId castorDetId;
151  if(validRaw(castorId) && castorId.section()== HcalCastorDetId::EM){
152  bool isPositive = false;
153  if(castorId.zside()==1)isPositive = true;
154  if(castorId.module()==1){
155  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
156  vNeighborsDetId.push_back(castorDetId.rawId());
157  return vNeighborsDetId;
158  }
159  if(castorId.module()== MODULE_EM_MAX){
160  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
161  vNeighborsDetId.push_back(castorDetId.rawId());
162  return vNeighborsDetId;
163  }
164  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
165  vNeighborsDetId.push_back(castorDetId.rawId());
166  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
167  vNeighborsDetId.push_back(castorDetId.rawId());
168  }
169  if(validRaw(castorId) && castorId.section()== HcalCastorDetId::HAD){
170  bool isPositive = false;
171  if(castorId.zside()==1)isPositive = true;
172  if(castorId.module()==1){
173  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
174  vNeighborsDetId.push_back(castorDetId.rawId());
175  return vNeighborsDetId;
176  }
177  if(castorId.module()== MODULE_HAD_MAX){
178  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
179  vNeighborsDetId.push_back(castorDetId.rawId());
180  return vNeighborsDetId;
181  }
182  }
183  return vNeighborsDetId;
184 }
185 
186 
187 std::vector<DetId> CastorTopology::east(const DetId& /*id*/) const
188 {
189  std::cout << "CastorTopology::east() not yet implemented" << std::endl;
190  std::vector<DetId> vNeighborsDetId;
191  return vNeighborsDetId;
192 }
193 
194 std::vector<DetId> CastorTopology::west(const DetId& /*id*/) const
195 {
196  std::cout << "CastorTopology::west() not yet implemented" << std::endl;
197  std::vector<DetId> vNeighborsDetId;
198  return vNeighborsDetId;
199 }
200 
201 std::vector<DetId> CastorTopology::north(const DetId& /*id*/) const
202 {
203  std::cout << "CastorTopology::north() not yet implemented" << std::endl;
204  std::vector<DetId> vNeighborsDetId;
205  return vNeighborsDetId;
206 }
207 std::vector<DetId> CastorTopology::south(const DetId& /*id*/) const
208 {
209  std::cout << "CastorTopology::south() not yet implemented" << std::endl;
210  std::vector<DetId> vNeighborsDetId;
211  return vNeighborsDetId;
212 }
213 std::vector<DetId> CastorTopology::up(const DetId& /*id*/) const
214 {
215  std::cout << "CastorTopology::up() not yet implemented" << std::endl;
216  std::vector<DetId> vNeighborsDetId;
217  return vNeighborsDetId;
218 }
219 std::vector<DetId> CastorTopology::down(const DetId& /*id*/) const
220 {
221  std::cout << "CastorTopology::down() not yet implemented" << std::endl;
222  std::vector<DetId> vNeighborsDetId;
223  return vNeighborsDetId;
224 }
225 
227  int ncells = 0;
228  switch (section) {
229  case(HcalCastorDetId::EM) : ncells = MODULE_EM_MAX*16; break;
230  case(HcalCastorDetId::HAD) : ncells = MODULE_HAD_MAX*16; break;
231  case(HcalCastorDetId::Unknown) : ncells =0; break;
232  }
233  return ncells;
234 }
235 
237  int firstCell = 0;
238  switch (section) {
239  case(HcalCastorDetId::EM) : firstCell = firstEMModule_ ; break;
240  case(HcalCastorDetId::HAD) : firstCell = firstHADModule_; break;
241  case(HcalCastorDetId::Unknown) : firstCell = 0; break;
242  }
243  return firstCell;
244 }
245 
247  int lastCell = 0;
248  switch (section) {
249  case(HcalCastorDetId::EM) : lastCell = lastEMModule_; break;
250  case(HcalCastorDetId::HAD) : lastCell = lastHADModule_; break;
251  case(HcalCastorDetId::Unknown) : lastCell = 0; break;
252  }
253  return lastCell;
254 }
255 
256 
257 
static bool validDetId(Section iSection, bool posEta, int iSector, int iMod)
int i
Definition: DBlmapReader.cc:9
int sector() const
get the sector (1-16)
virtual std::vector< DetId > incModule(const DetId &id) const
virtual std::vector< DetId > up(const DetId &id) const
static const int MODULE_EM_MAX
int module() const
get the module (1-2 for EM, 1-12 for HAD)
virtual std::vector< DetId > west(const DetId &id) const
virtual bool validRaw(const HcalCastorDetId &id) const
int zside(DetId const &)
Section section() const
get the section
virtual std::vector< DetId > south(const DetId &id) const
uint32_t rawId() const
get the raw id
Definition: DetId.h:43
static const int MODULE_HAD_MAX
virtual std::vector< DetId > north(const DetId &id) const
virtual unsigned int ncells() const
return a count of valid cells (for dense indexing use)
int zside() const
get the z-side of the cell (1/-1)
virtual std::vector< DetId > down(const DetId &id) const
virtual bool valid(const HcalCastorDetId &id) const
Definition: DetId.h:18
virtual std::vector< DetId > incSector(const DetId &id) const
virtual std::vector< DetId > east(const DetId &id) const
int firstCell(HcalCastorDetId::Section section) const
bool isExcluded(const HcalCastorDetId &id) const
int lastCell(HcalCastorDetId::Section section) const
tuple cout
Definition: gather_cfg.py:145
volatile std::atomic< bool > shutdown_flag false
void exclude(const HcalCastorDetId &id)
std::vector< HcalCastorDetId > exclusionList_