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 the for side exclusions
32  switch(id.zside()){
33  case( 1): exed = excludeZP_; break;
34  case(-1): exed = excludeZN_; break;
35  default: exed = false;
36  }
37 
38  // check for section exclutions
39  switch (id.section()) {
40  case(HcalCastorDetId::EM) : exed = excludeEM_; break;
41  case(HcalCastorDetId::HAD) : exed = excludeHAD_; break;
42  default: exed = false;
43  }
44 
45  // check the entire list
46  if (!exed && !exclusionList_.empty()) {
47  std::vector<HcalCastorDetId>::const_iterator
48  i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
49  if (i!=exclusionList_.end() && *i==id) exed=true;
50  }
51  return exed;
52 }
53 
55  std::vector<HcalCastorDetId>::iterator
56  i=std::lower_bound(exclusionList_.begin(),exclusionList_.end(),id);
57  if (i==exclusionList_.end() || *i!=id) {
58  exclusionList_.insert(i,id);
59  }
60 }
61 
62 void CastorTopology::exclude(int zside) {
63  switch(zside){
64  case( 1): excludeZP_ = true; break;
65  case(-1): excludeZN_ = true; break;
66  default: break;
67  }
68 }
69 
71  switch(zside){
72  case( 1): excludeZP_ = true; break;
73  case(-1): excludeZN_ = true; break;
74  default: break;
75  }
76  switch (section) {
77  case(HcalCastorDetId::EM) : excludeEM_ = true; break;
78  case(HcalCastorDetId::HAD) : excludeHAD_ = true; break;
79  default: break;
80  }
81 }
82 
83 int CastorTopology::exclude(int zside, HcalCastorDetId::Section section1, int isec1, int imod1,
84 HcalCastorDetId::Section section2, int isec2, int imod2) {
85  bool exed = false;
86  switch(zside){
87  case( 1): exed = excludeZP_; break;
88  case(-1): exed = excludeZN_; break;
89  default: exed = false;
90  }
91  if (exed) return 0;
92 
93 
94 /* NOTE not so sure about the exclusion */
95  if (section1 == HcalCastorDetId::EM && section2 == HcalCastorDetId::EM) {
96  exed = excludeEM_; }
97  else if (section1 == HcalCastorDetId::HAD && section2 == HcalCastorDetId::HAD) {
98  exed = excludeHAD_; }
99  else { exed = false; };
100 
101  if (exed) return 0;
102 
103  bool isPositive = false;
104  if(zside == 1)isPositive = true;
105 
106  int n = 0;
107  for (int isec = isec1; isec < isec2; isec++){
108  for (int imod = imod1; imod < imod2; imod++) {
109  HcalCastorDetId id(section1, isPositive, isec, imod);
110  if(validRaw(id))exclude(id);
111  n++;
112  }
113  }
114  return n;
115 }
116 
118 {
119  return HcalCastorDetId::validDetId( id.section(),
120  id.zside()>0,
121  id.sector(),
122  id.module() ) ;
123 }
124 
125 std::vector<DetId> CastorTopology::incSector(const DetId& id) const{
126  std::vector<DetId> vNeighborsDetId;
127  HcalCastorDetId castorId = HcalCastorDetId(id);
128  HcalCastorDetId castorDetId;
129  if(validRaw(castorId)) {
130  bool isPositive = false;
131  if(castorId.zside()==1)isPositive = true;
132  if(castorId.sector()==1) {
133  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()+1,
134 castorId.module());
135  vNeighborsDetId.push_back(castorDetId.rawId());
136  return vNeighborsDetId;
137  }
138  if(castorId.sector()== 16){
139  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()-1,
140 castorId.module());
141  vNeighborsDetId.push_back(castorDetId.rawId());
142  return vNeighborsDetId;
143  }
144  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()-1,
145 castorId.module());
146  vNeighborsDetId.push_back(castorDetId.rawId());
147  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector()+1,
148 castorId.module());
149  vNeighborsDetId.push_back(castorDetId.rawId());
150  }
151  return vNeighborsDetId;
152 }
153 
154 std::vector<DetId> CastorTopology::incModule(const DetId& id) const{
155  std::vector<DetId> vNeighborsDetId;
156  HcalCastorDetId castorId = HcalCastorDetId(id);
157  HcalCastorDetId castorDetId;
158  if(validRaw(castorId) && castorId.section()== HcalCastorDetId::EM){
159  bool isPositive = false;
160  if(castorId.zside()==1)isPositive = true;
161  if(castorId.module()==1){
162  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
163  vNeighborsDetId.push_back(castorDetId.rawId());
164  return vNeighborsDetId;
165  }
166  if(castorId.module()== MODULE_EM_MAX){
167  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
168  vNeighborsDetId.push_back(castorDetId.rawId());
169  return vNeighborsDetId;
170  }
171  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
172  vNeighborsDetId.push_back(castorDetId.rawId());
173  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
174  vNeighborsDetId.push_back(castorDetId.rawId());
175  }
176  if(validRaw(castorId) && castorId.section()== HcalCastorDetId::HAD){
177  bool isPositive = false;
178  if(castorId.zside()==1)isPositive = true;
179  if(castorId.module()==1){
180  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()+1);
181  vNeighborsDetId.push_back(castorDetId.rawId());
182  return vNeighborsDetId;
183  }
184  if(castorId.module()== MODULE_HAD_MAX){
185  castorDetId = HcalCastorDetId(castorId.section(), isPositive, castorId.sector(), castorId.module()-1);
186  vNeighborsDetId.push_back(castorDetId.rawId());
187  return vNeighborsDetId;
188  }
189  }
190  return vNeighborsDetId;
191 }
192 
193 
194 std::vector<DetId> CastorTopology::east(const DetId& /*id*/) const
195 {
196  std::cout << "CastorTopology::east() not yet implemented" << std::endl;
197  std::vector<DetId> vNeighborsDetId;
198  return vNeighborsDetId;
199 }
200 
201 std::vector<DetId> CastorTopology::west(const DetId& /*id*/) const
202 {
203  std::cout << "CastorTopology::west() not yet implemented" << std::endl;
204  std::vector<DetId> vNeighborsDetId;
205  return vNeighborsDetId;
206 }
207 
208 std::vector<DetId> CastorTopology::north(const DetId& /*id*/) const
209 {
210  std::cout << "CastorTopology::north() not yet implemented" << std::endl;
211  std::vector<DetId> vNeighborsDetId;
212  return vNeighborsDetId;
213 }
214 std::vector<DetId> CastorTopology::south(const DetId& /*id*/) const
215 {
216  std::cout << "CastorTopology::south() not yet implemented" << std::endl;
217  std::vector<DetId> vNeighborsDetId;
218  return vNeighborsDetId;
219 }
220 std::vector<DetId> CastorTopology::up(const DetId& /*id*/) const
221 {
222  std::cout << "CastorTopology::up() not yet implemented" << std::endl;
223  std::vector<DetId> vNeighborsDetId;
224  return vNeighborsDetId;
225 }
226 std::vector<DetId> CastorTopology::down(const DetId& /*id*/) const
227 {
228  std::cout << "CastorTopology::down() not yet implemented" << std::endl;
229  std::vector<DetId> vNeighborsDetId;
230  return vNeighborsDetId;
231 }
232 
234  int ncells = 0;
235  switch (section) {
236  case(HcalCastorDetId::EM) : ncells = MODULE_EM_MAX*16; break;
237  case(HcalCastorDetId::HAD) : ncells = MODULE_HAD_MAX*16; break;
238  case(HcalCastorDetId::Unknown) : ncells =0; break;
239  }
240  return ncells;
241 }
242 
244  int firstCell = 0;
245  switch (section) {
246  case(HcalCastorDetId::EM) : firstCell = firstEMModule_ ; break;
247  case(HcalCastorDetId::HAD) : firstCell = firstHADModule_; break;
248  case(HcalCastorDetId::Unknown) : firstCell = 0; break;
249  }
250  return firstCell;
251 }
252 
254  int lastCell = 0;
255  switch (section) {
256  case(HcalCastorDetId::EM) : lastCell = lastEMModule_; break;
257  case(HcalCastorDetId::HAD) : lastCell = lastHADModule_; break;
258  case(HcalCastorDetId::Unknown) : lastCell = 0; break;
259  }
260  return lastCell;
261 }
262 
263 
264 
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
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:45
static const int MODULE_HAD_MAX
virtual std::vector< DetId > north(const DetId &id) const
int ncells(HcalCastorDetId::Section section) const
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:20
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:121
void exclude(const HcalCastorDetId &id)
std::vector< HcalCastorDetId > exclusionList_