CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
MatrixHCALDetIds.cc
Go to the documentation of this file.
2 
4 
5 #include<algorithm>
6 #include<iostream>
7 
8 namespace spr{
9 
10  std::vector<DetId> matrixHCALIds(std::vector<DetId>& dets,
11  const HcalTopology* topology, int ieta,
12  int iphi, bool includeHO, bool debug) {
13 
14  if (debug) {
15  std::cout << "matrixHCALIds::Add " << ieta << " rows and " << iphi
16  << " columns of cells for " << dets.size() << " cells"
17  << std::endl;
18  for (unsigned int i1=0; i1<dets.size(); i1++) {
19  HcalDetId id = HcalDetId(dets[i1]());
20  std::cout << "matrixHCALIds::Cell " << i1 << " 0x" << std::hex
21  << id.rawId() << std::dec << " " << id << std::endl;
22  }
23  }
24 
25  std::vector<DetId> vdetN = spr::newHCALIdNS(dets, 0, topology, true, ieta,
26  iphi, debug);
27  std::vector<DetId> vdetS = spr::newHCALIdNS(dets, 0, topology, false, ieta,
28  iphi, debug);
29  for (unsigned int i1=0; i1<vdetS.size(); i1++) {
30  if (std::count(vdetN.begin(),vdetN.end(),vdetS[i1]) == 0)
31  vdetN.push_back(vdetS[i1]);
32  }
33 
34  vdetS = spr::matrixHCALIdsDepth(vdetN, topology, includeHO, debug);
35 
36  if (debug) {
37  std::cout << "matrixHCALIds::Total number of cells found is "
38  << vdetS.size() << std::endl;
39  for (unsigned int i1=0; i1<vdetS.size(); i1++) {
40  HcalDetId id = HcalDetId(vdetS[i1]());
41  std::cout << "matrixHCALIds::Cell " << i1 << " " << id << std::endl;
42  }
43  }
44  return vdetS;
45  }
46 
47  std::vector<DetId> matrixHCALIds(std::vector<DetId>& dets,
48  const HcalTopology* topology, int ietaE,
49  int ietaW,int iphiN,int iphiS,
50  bool includeHO, bool debug) {
51 
52  if (debug) {
53  std::cout << "matrixHCALIds::Add " <<ietaE << "|" <<ietaW << " rows and "
54  << iphiN << "|" << iphiS << " columns of cells for "
55  << dets.size() << " cells" << std::endl;
56  for (unsigned int i1=0; i1<dets.size(); i1++) {
57  HcalDetId id = HcalDetId(dets[i1]());
58  std::cout << "matrixHCALIds::Cell " << i1 << " 0x" << std::hex
59  << id.rawId() << std::dec << " " << id << std::endl;
60  }
61  }
62 
63  std::vector<DetId> vdetN = spr::newHCALIdNS(dets, 0, topology, true, ietaE,
64  ietaW, iphiN, iphiS, debug);
65  std::vector<DetId> vdetS = spr::newHCALIdNS(dets, 0, topology, false,ietaE,
66  ietaW, iphiN, iphiS, debug);
67  for (unsigned int i1=0; i1<vdetS.size(); i1++) {
68  if (std::count(vdetN.begin(),vdetN.end(),vdetS[i1]) == 0)
69  vdetN.push_back(vdetS[i1]);
70  }
71 
72  vdetS = spr::matrixHCALIdsDepth(vdetN, topology, includeHO, debug);
73 
74  if (debug) {
75  std::cout << "matrixHCALIds::Total number of cells found is "
76  << vdetS.size() << std::endl;
77  for (unsigned int i1=0; i1<vdetS.size(); i1++) {
78  HcalDetId id = HcalDetId(vdetS[i1]());
79  std::cout << "matrixHCALIds::Cell " << i1 << " " << id << std::endl;
80  }
81  }
82  return vdetS;
83  }
84 
85  std::vector<DetId> newHCALIdNS(std::vector<DetId>& dets, unsigned int last,
86  const HcalTopology* topology, bool shiftNorth,
87  int ieta, int iphi, bool debug) {
88 
89  if (debug) {
90  std::cout << "newHCALIdNS::Add " << iphi << " columns of cells along "
91  << shiftNorth << " for " << (dets.size()-last) << " cells"
92  << std::endl;
93  for (unsigned int i1=last; i1<dets.size(); i1++) {
94  HcalDetId id = HcalDetId(dets[i1]());
95  std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
96  }
97  }
98 
99  std::vector<DetId> vdets;
100  vdets.insert(vdets.end(), dets.begin(), dets.end());
101  std::vector<DetId> vdetE, vdetW;
102  if (last == 0) {
103  vdetE = spr::newHCALIdEW(dets, last, topology, true, ieta, debug);
104  vdetW = spr::newHCALIdEW(dets, last, topology, false, ieta, debug);
105  for (unsigned int i1=0; i1<vdetW.size(); i1++) {
106  if (std::count(vdets.begin(),vdets.end(),vdetW[i1]) == 0)
107  vdets.push_back(vdetW[i1]);
108  }
109  for (unsigned int i1=0; i1<vdetE.size(); i1++) {
110  if (std::count(vdets.begin(),vdets.end(),vdetE[i1]) == 0)
111  vdets.push_back(vdetE[i1]);
112  }
113  if (debug) {
114  std::cout <<"newHCALIdNS::With Added cells along E/W results a set of "
115  << (vdets.size()-dets.size()) << " new cells" << std::endl;
116  for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
117  HcalDetId id = HcalDetId(vdets[i1]());
118  std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
119  }
120  }
121  }
122  unsigned int last0 = vdets.size();
123  if (iphi > 0) {
124  std::vector<DetId> vdetnew;
125  for (unsigned int i1=last; i1<dets.size(); i1++) {
126  std::vector<DetId> vdet;
127  if (shiftNorth) vdet = topology->north(dets[i1]);
128  else vdet = topology->south(dets[i1]);
129  for (unsigned int i2=0; i2<vdet.size(); i2++) {
130  if (std::count(vdets.begin(),vdets.end(),vdet[i2]) == 0)
131  vdetnew.push_back(vdet[i2]);
132  }
133  }
134  iphi--;
135  vdetE = spr::newHCALIdEW(vdetnew, 0, topology, true, ieta, debug);
136  vdetW = spr::newHCALIdEW(vdetnew, 0, topology, false, ieta, debug);
137  for (unsigned int i2=0; i2<vdetW.size(); i2++) {
138  if (std::count(vdets.begin(),vdets.end(),vdetW[i2]) == 0 &&
139  std::count(vdetnew.begin(),vdetnew.end(),vdetW[i2]) == 0)
140  vdets.push_back(vdetW[i2]);
141  }
142  for (unsigned int i2=0; i2<vdetE.size(); i2++) {
143  if (std::count(vdets.begin(),vdets.end(),vdetE[i2]) == 0 &&
144  std::count(vdetnew.begin(),vdetnew.end(),vdetE[i2]) == 0)
145  vdets.push_back(vdetE[i2]);
146  }
147  last = vdets.size();
148  vdets.insert(vdets.end(), vdetnew.begin(), vdetnew.end());
149  if (debug) {
150  std::cout << "newHCALIdNS::Addition results a set of "
151  << (vdets.size()-last0) << " new cells" << std::endl;
152  for (unsigned int i1=last0; i1<vdets.size(); i1++) {
153  HcalDetId id = HcalDetId(vdets[i1]());
154  std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
155  }
156  }
157  last0 = last;
158  }
159 
160  if (iphi > 0) {
161  last = last0;
162  return spr::newHCALIdNS(vdets,last,topology,shiftNorth,ieta,iphi,debug);
163  } else {
164  if (debug) {
165  std::cout << "newHCALIdNS::Final list consists of " << vdets.size()
166  << " cells" << std::endl;
167  for (unsigned int i1=0; i1<vdets.size(); i1++) {
168  HcalDetId id = HcalDetId(vdets[i1]());
169  std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
170  }
171  }
172  return vdets;
173  }
174  }
175 
176  std::vector<DetId> newHCALIdNS(std::vector<DetId>& dets, unsigned int last,
177  const HcalTopology* topology, bool shiftNorth,
178  int ietaE, int ietaW, int iphiN, int iphiS,
179  bool debug) {
180 
181  if (debug) {
182  std::cout << "newHCALIdNS::Add " << iphiN << "|" << iphiS
183  << " columns of cells along " << shiftNorth << " for "
184  << (dets.size()-last) << " cells" << std::endl;
185  for (unsigned int i1=last; i1<dets.size(); i1++) {
186  HcalDetId id = HcalDetId(dets[i1]());
187  std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
188  }
189  }
190 
191  std::vector<DetId> vdets;
192  vdets.insert(vdets.end(), dets.begin(), dets.end());
193  std::vector<DetId> vdetE, vdetW;
194  if (last == 0) {
195  vdetE = spr::newHCALIdEW(dets,last, topology, true, ietaE,ietaW, debug);
196  vdetW = spr::newHCALIdEW(dets,last, topology, false, ietaE,ietaW, debug);
197  for (unsigned int i1=0; i1<vdetW.size(); i1++) {
198  if (std::count(vdets.begin(),vdets.end(),vdetW[i1]) == 0)
199  vdets.push_back(vdetW[i1]);
200  }
201  for (unsigned int i1=0; i1<vdetE.size(); i1++) {
202  if (std::count(vdets.begin(),vdets.end(),vdetE[i1]) == 0)
203  vdets.push_back(vdetE[i1]);
204  }
205  if (debug) {
206  std::cout <<"newHCALIdNS::With Added cells along E/W results a set of "
207  << (vdets.size()-dets.size()) << " new cells" << std::endl;
208  for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
209  HcalDetId id = HcalDetId(vdets[i1]());
210  std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
211  }
212  }
213  }
214  unsigned int last0 = vdets.size();
215  int iphi = iphiS;
216  if (shiftNorth) iphi = iphiN;
217  if (iphi > 0) {
218  std::vector<DetId> vdetnew;
219  for (unsigned int i1=last; i1<dets.size(); i1++) {
220  std::vector<DetId> vdet;
221  if (shiftNorth) vdet = topology->north(dets[i1]);
222  else vdet = topology->south(dets[i1]);
223  for (unsigned int i2=0; i2<vdet.size(); i2++) {
224  if (std::count(vdets.begin(),vdets.end(),vdet[i2]) == 0)
225  vdetnew.push_back(vdet[i2]);
226  }
227  }
228  iphi--;
229  vdetE = spr::newHCALIdEW(vdetnew,0, topology, true, ietaE,ietaW, debug);
230  vdetW = spr::newHCALIdEW(vdetnew,0, topology, false, ietaE,ietaW, debug);
231  for (unsigned int i2=0; i2<vdetW.size(); i2++) {
232  if (std::count(vdets.begin(),vdets.end(),vdetW[i2]) == 0 &&
233  std::count(vdetnew.begin(),vdetnew.end(),vdetW[i2]) == 0)
234  vdets.push_back(vdetW[i2]);
235  }
236  for (unsigned int i2=0; i2<vdetE.size(); i2++) {
237  if (std::count(vdets.begin(),vdets.end(),vdetE[i2]) == 0 &&
238  std::count(vdetnew.begin(),vdetnew.end(),vdetE[i2]) == 0)
239  vdets.push_back(vdetE[i2]);
240  }
241  last = vdets.size();
242  vdets.insert(vdets.end(), vdetnew.begin(), vdetnew.end());
243  if (debug) {
244  std::cout << "newHCALIdNS::Addition results a set of "
245  << (vdets.size()-last0) << " new cells" << std::endl;
246  for (unsigned int i1=last0; i1<vdets.size(); i1++) {
247  HcalDetId id = HcalDetId(vdets[i1]());
248  std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
249  }
250  }
251  last0 = last;
252  }
253  if (shiftNorth) iphiN = iphi;
254  else iphiS = iphi;
255 
256  if (iphi > 0) {
257  last = last0;
258  return spr::newHCALIdNS(vdets,last,topology,shiftNorth,ietaE,ietaW,
259  iphiN,iphiS,debug);
260  } else {
261  if (debug) {
262  std::cout << "newHCALIdNS::Final list consists of " << vdets.size()
263  << " cells" << std::endl;
264  for (unsigned int i1=0; i1<vdets.size(); i1++) {
265  HcalDetId id = HcalDetId(vdets[i1]());
266  std::cout << "newHCALIdNS::Cell " << i1 << " " << id << std::endl;
267  }
268  }
269  return vdets;
270  }
271  }
272 
273  std::vector<DetId> newHCALIdEW(std::vector<DetId>& dets, unsigned int last,
274  const HcalTopology* topology, bool shiftEast,
275  int ieta, bool debug) {
276 
277  if (debug) {
278  std::cout << "newHCALIdEW::Add " << ieta << " rows of cells along "
279  << shiftEast << " for " << (dets.size()-last) << " cells"
280  << std::endl;
281  for (unsigned int i1=last; i1<dets.size(); i1++) {
282  HcalDetId id = HcalDetId(dets[i1]());
283  std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
284  }
285  }
286 
287  std::vector<DetId> vdets;
288  vdets.insert(vdets.end(), dets.begin(), dets.end());
289  if (ieta > 0) {
290  for (unsigned int i1=last; i1<dets.size(); i1++) {
291  std::vector<DetId> vdet;
292  if (shiftEast) vdet = topology->east(dets[i1]);
293  else vdet = topology->west(dets[i1]);
294  for (unsigned int i2=0; i2<vdet.size(); i2++) {
295  if (std::count(vdets.begin(),vdets.end(),vdet[i2]) == 0)
296  vdets.push_back(vdet[i2]);
297  }
298  }
299  ieta--;
300  }
301 
302  if (debug) {
303  std::cout << "newHCALIdEW::Addition results a set of "
304  << (vdets.size()-dets.size()) << " new cells" << std::endl;
305  for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
306  HcalDetId id = HcalDetId(vdets[i1]());
307  std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
308  }
309  }
310 
311  if (ieta > 0) {
312  last = dets.size();
313  return spr::newHCALIdEW(vdets, last, topology, shiftEast, ieta, debug);
314  } else {
315  if (debug) {
316  std::cout << "newHCALIdEW::Final list (EW) consists of " <<vdets.size()
317  << " cells" << std::endl;
318  for (unsigned int i1=0; i1<vdets.size(); i1++) {
319  HcalDetId id = HcalDetId(vdets[i1]());
320  std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
321  }
322  }
323  return vdets;
324  }
325  }
326 
327  std::vector<DetId> newHCALIdEW(std::vector<DetId>& dets, unsigned int last,
328  const HcalTopology* topology, bool shiftEast,
329  int ietaE, int ietaW, bool debug) {
330 
331  if (debug) {
332  std::cout << "newHCALIdEW::Add " << ietaE << "|" << ietaW
333  << " rows of cells along " << shiftEast << " for "
334  << (dets.size()-last) << " cells" << std::endl;
335  for (unsigned int i1=last; i1<dets.size(); i1++) {
336  HcalDetId id = HcalDetId(dets[i1]());
337  std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
338  }
339  }
340 
341  int ieta = ietaW;
342  if (shiftEast) ieta = ietaE;
343  std::vector<DetId> vdets;
344  vdets.insert(vdets.end(), dets.begin(), dets.end());
345  if (ieta > 0) {
346  for (unsigned int i1=last; i1<dets.size(); i1++) {
347  std::vector<DetId> vdet;
348  if (shiftEast) vdet = topology->east(dets[i1]);
349  else vdet = topology->west(dets[i1]);
350  for (unsigned int i2=0; i2<vdet.size(); i2++) {
351  if (std::count(vdets.begin(),vdets.end(),vdet[i2]) == 0)
352  vdets.push_back(vdet[i2]);
353  }
354  }
355  ieta--;
356  }
357  if (shiftEast) ietaE = ieta;
358  else ietaW = ieta;
359 
360  if (debug) {
361  std::cout << "newHCALIdEW::Addition results a set of "
362  << (vdets.size()-dets.size()) << " new cells" << std::endl;
363  for (unsigned int i1=dets.size(); i1<vdets.size(); i1++) {
364  HcalDetId id = HcalDetId(vdets[i1]());
365  std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
366  }
367  }
368 
369  if (ieta > 0) {
370  last = dets.size();
371  return spr::newHCALIdEW(vdets,last,topology,shiftEast,ietaE,ietaW,debug);
372  } else {
373  if (debug) {
374  std::cout << "newHCALIdEW::Final list (EW) consists of " <<vdets.size()
375  << " cells" << std::endl;
376  for (unsigned int i1=0; i1<vdets.size(); i1++) {
377  HcalDetId id = HcalDetId(vdets[i1]());
378  std::cout << "newHCALIdEW::Cell " << i1 << " " << id << std::endl;
379  }
380  }
381  return vdets;
382  }
383  }
384 
385  std::vector<DetId> matrixHCALIdsDepth(std::vector<DetId>& dets,
386  const HcalTopology* topology,
387  bool includeHO, bool debug) {
388 
389  if (debug) {
390  std::cout << "matrixHCALIdsDepth::Add cells with higher depths with HO"
391  << "Flag set to " << includeHO << " to existing "
392  << dets.size() << " cells" << std::endl;
393  for (unsigned int i1=0; i1<dets.size(); i1++) {
394  HcalDetId id = HcalDetId(dets[i1]());
395  std::cout << "matrixHCALIdsDepth::Cell " << i1 << " " <<id <<std::endl;
396  }
397  }
398 
399  std::vector<DetId> vdets(dets);
400  for (unsigned int i1=0; i1<dets.size(); i1++) {
401  HcalDetId vdet = dets[i1];
402  for (int idepth = 0; idepth < 3; idepth++) {
403  std::vector<DetId> vUpDetId = topology->up(vdet);
404  if (vUpDetId.size() != 0) {
405  if (includeHO || vUpDetId[0].subdetId() != (int)(HcalOuter)) {
406  int n = std::count(vdets.begin(),vdets.end(),vUpDetId[0]);
407  if (n == 0) {
408  if (debug) std::cout << "matrixHCALIdsDepth:: Depth " << idepth << " " << vdet << " " << (HcalDetId)vUpDetId[0] << std::endl;
409  vdets.push_back(vUpDetId[0]);
410  }
411  }
412  vdet = vUpDetId[0];
413  }
414  }
415  }
416 
417  if (debug) {
418  std::cout << "matrixHCALIdsDepth::Final list contains " << vdets.size()
419  << " cells" << std::endl;
420  for (unsigned int i1=0; i1<vdets.size(); i1++) {
421  HcalDetId id = HcalDetId(vdets[i1]());
422  std::cout << "matrixHCALIdsDepth::Cell " << i1 << " " <<id <<std::endl;
423  }
424  }
425  return vdets;
426  }
427 
428 }
std::vector< DetId > newHCALIdNS(std::vector< DetId > &dets, unsigned int last, const HcalTopology *topology, bool shiftNorth, int ieta, int iphi, bool debug=false)
virtual std::vector< DetId > south(const DetId &id) const
virtual std::vector< DetId > west(const DetId &id) const
Definition: HcalTopology.cc:84
virtual std::vector< DetId > north(const DetId &id) const
Definition: HcalTopology.cc:92
virtual std::vector< DetId > up(const DetId &id) const
std::vector< DetId > matrixHCALIdsDepth(std::vector< DetId > &dets, const HcalTopology *topology, bool includeHO=false, bool debug=false)
std::vector< DetId > matrixHCALIds(std::vector< DetId > &dets, const HcalTopology *topology, int ieta, int iphi, bool includeHO=false, bool debug=false)
tuple cout
Definition: gather_cfg.py:41
virtual std::vector< DetId > east(const DetId &id) const
Definition: HcalTopology.cc:76
#define debug
Definition: MEtoEDMFormat.h:34
std::vector< DetId > newHCALIdEW(std::vector< DetId > &dets, unsigned int last, const HcalTopology *topology, bool shiftEast, int ieta, bool debug=false)