CMS 3D CMS Logo

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