CMS 3D CMS Logo

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