CMS 3D CMS Logo

MatrixECALDetIds.cc
Go to the documentation of this file.
4 
8 
9 #include <algorithm>
10 #include <iostream>
11 
12 //#define EDM_ML_DEBUG
13 
14 namespace spr {
15 
16  void matrixECALIds(const DetId& det,
17  int ieta,
18  int iphi,
19  const CaloGeometry* geo,
20  const CaloTopology* caloTopology,
21  std::vector<DetId>& vdets,
22  bool debug,
23  bool ignoreTransition) {
24  const CaloSubdetectorTopology* barrelTopo = (caloTopology->getSubdetectorTopology(DetId::Ecal, EcalBarrel));
25  const CaloSubdetectorTopology* endcapTopo = (caloTopology->getSubdetectorTopology(DetId::Ecal, EcalEndcap));
26  const EcalBarrelGeometry* barrelGeom =
27  (dynamic_cast<const EcalBarrelGeometry*>(geo->getSubdetectorGeometry(DetId::Ecal, EcalBarrel)));
28  const EcalEndcapGeometry* endcapGeom =
29  (dynamic_cast<const EcalEndcapGeometry*>(geo->getSubdetectorGeometry(DetId::Ecal, EcalEndcap)));
30 
31 #ifdef EDM_ML_DEBUG
32  if (debug) {
33  std::cout << "matrixECALIds::Add " << ieta << " rows and " << iphi << " columns of cells for 1 cell" << std::endl;
34  spr::debugEcalDets(0, det, true);
35  }
36 #endif
37  std::vector<DetId> dets(1, det);
38  std::vector<CaloDirection> dirs(1, NORTH);
39  vdets = spr::newECALIdNS(
40  dets, 0, ieta, iphi, dirs, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
41  dirs[0] = SOUTH;
42  std::vector<DetId> vdetS = spr::newECALIdNS(
43  dets, 0, ieta, iphi, dirs, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
44  for (unsigned int i1 = 0; i1 < vdetS.size(); i1++) {
45  if (std::count(vdets.begin(), vdets.end(), vdetS[i1]) == 0)
46  vdets.push_back(vdetS[i1]);
47  }
48  unsigned int ndet = (2 * ieta + 1) * (2 * iphi + 1);
49  if (vdets.size() != ndet) {
50  std::vector<DetId> vdetExtra;
51  spr::extraIds(det, vdets, ieta, ieta, iphi, iphi, barrelGeom, endcapGeom, vdetExtra, debug);
52  if (!vdetExtra.empty())
53  vdets.insert(vdets.end(), vdetExtra.begin(), vdetExtra.end());
54  }
55 
56 #ifdef EDM_ML_DEBUG
57  if (debug) {
58  std::cout << "matrixECALIds::Total number of cells found is " << vdets.size() << std::endl;
59  spr::debugEcalDets(0, vdets);
60  }
61 #endif
62  }
63 
64  std::vector<DetId> matrixECALIds(const DetId& det,
65  int ieta,
66  int iphi,
67  const CaloGeometry* geo,
68  const CaloTopology* caloTopology,
69  bool debug,
70  bool ignoreTransition) {
71  std::vector<DetId> vdets;
72  spr::matrixECALIds(det, ieta, iphi, geo, caloTopology, vdets, debug, ignoreTransition);
73  return vdets;
74  }
75 
76  std::vector<DetId> matrixECALIds(const DetId& det,
77  double dR,
78  const GlobalVector& trackMom,
79  const CaloGeometry* geo,
80  const CaloTopology* caloTopology,
81  bool debug,
82  bool ignoreTransition) {
84  if (det.subdetId() == EcalEndcap) {
85  EEDetId EEid = EEDetId(det);
86  core = geo->getPosition(EEid);
87  } else {
88  EBDetId EBid = EBDetId(det);
89  core = geo->getPosition(EBid);
90  }
91  int ietaphi = (int)(dR / 2.0) + 1;
92  std::vector<DetId> vdets, vdetx;
93  spr::matrixECALIds(det, ietaphi, ietaphi, geo, caloTopology, vdets, debug, ignoreTransition);
94  for (unsigned int i = 0; i < vdets.size(); ++i) {
95  GlobalPoint rpoint;
96  if (vdets[i].subdetId() == EcalEndcap) {
97  EEDetId EEid = EEDetId(vdets[i]);
98  rpoint = geo->getPosition(EEid);
99  } else {
100  EBDetId EBid = EBDetId(vdets[i]);
101  rpoint = geo->getPosition(EBid);
102  }
103  if (spr::getDistInPlaneTrackDir(core, trackMom, rpoint) < dR) {
104  vdetx.push_back(vdets[i]);
105  }
106  }
107 
108 #ifdef EDM_ML_DEBUG
109  if (debug) {
110  std::cout << "matrixECALIds::Final List of cells for dR " << dR << " is with " << vdetx.size()
111  << " from original list of " << vdets.size() << std::endl;
112  spr::debugEcalDets(0, vdetx);
113  }
114 #endif
115  return vdetx;
116  }
117 
118  void matrixECALIds(const DetId& det,
119  int ietaE,
120  int ietaW,
121  int iphiN,
122  int iphiS,
123  const CaloGeometry* geo,
124  const CaloTopology* caloTopology,
125  std::vector<DetId>& vdets,
126  bool debug,
127  bool ignoreTransition) {
128  const CaloSubdetectorTopology* barrelTopo = (caloTopology->getSubdetectorTopology(DetId::Ecal, EcalBarrel));
129  const CaloSubdetectorTopology* endcapTopo = (caloTopology->getSubdetectorTopology(DetId::Ecal, EcalEndcap));
130  const EcalBarrelGeometry* barrelGeom =
131  (dynamic_cast<const EcalBarrelGeometry*>(geo->getSubdetectorGeometry(DetId::Ecal, EcalBarrel)));
132  const EcalEndcapGeometry* endcapGeom =
133  (dynamic_cast<const EcalEndcapGeometry*>(geo->getSubdetectorGeometry(DetId::Ecal, EcalEndcap)));
134 
135 #ifdef EDM_ML_DEBUG
136  if (debug) {
137  std::cout << "matrixECALIds::Add " << ietaE << "|" << ietaW << " rows and " << iphiN << "|" << iphiS
138  << " columns of cells for 1 cell" << std::endl;
139  debugEcalDets(0, det, true);
140  }
141 #endif
142  std::vector<DetId> dets(1, det);
143  std::vector<CaloDirection> dirs(1, NORTH);
144  std::vector<int> jetaE(1, ietaE), jetaW(1, ietaW);
145  std::vector<int> jphiN(1, iphiN), jphiS(1, iphiS);
146  vdets = spr::newECALIdNS(dets,
147  0,
148  jetaE,
149  jetaW,
150  jphiN,
151  jphiS,
152  dirs,
153  barrelTopo,
154  endcapTopo,
155  barrelGeom,
156  endcapGeom,
157  debug,
158  ignoreTransition);
159  dirs[0] = SOUTH;
160  std::vector<DetId> vdetS = spr::newECALIdNS(dets,
161  0,
162  jetaE,
163  jetaW,
164  jphiN,
165  jphiS,
166  dirs,
167  barrelTopo,
168  endcapTopo,
169  barrelGeom,
170  endcapGeom,
171  debug,
172  ignoreTransition);
173  for (unsigned int i1 = 0; i1 < vdetS.size(); i1++) {
174  if (std::count(vdets.begin(), vdets.end(), vdetS[i1]) == 0)
175  vdets.push_back(vdetS[i1]);
176  }
177 
178  unsigned int ndet = (ietaE + ietaW + 1) * (iphiN + iphiS + 1);
179  if (vdets.size() != ndet) {
180  std::vector<DetId> vdetExtra;
181  spr::extraIds(det, vdets, ietaE, ietaW, iphiN, iphiS, barrelGeom, endcapGeom, vdetExtra, debug);
182  if (!vdetExtra.empty())
183  vdets.insert(vdets.end(), vdetExtra.begin(), vdetExtra.end());
184  }
185 
186 #ifdef EDM_ML_DEBUG
187  if (debug) {
188  std::cout << "matrixECALIds::Total number of cells found is " << vdets.size() << std::endl;
189  spr::debugEcalDets(0, vdets);
190  }
191 #endif
192  }
193 
194  std::vector<DetId> matrixECALIds(const DetId& det,
195  int ietaE,
196  int ietaW,
197  int iphiN,
198  int iphiS,
199  const CaloGeometry* geo,
200  const CaloTopology* caloTopology,
201  bool debug,
202  bool ignoreTransition) {
203  std::vector<DetId> vdets;
204  spr::matrixECALIds(det, ietaE, ietaW, iphiN, iphiS, geo, caloTopology, vdets, debug, ignoreTransition);
205  return vdets;
206  }
207 
208  std::vector<DetId> newECALIdNS(std::vector<DetId>& dets,
209  unsigned int last,
210  int ieta,
211  int iphi,
212  std::vector<CaloDirection>& dir,
213  const CaloSubdetectorTopology* barrelTopo,
214  const CaloSubdetectorTopology* endcapTopo,
215  const EcalBarrelGeometry* barrelGeom,
216  const EcalEndcapGeometry* endcapGeom,
217  bool debug,
218  bool ignoreTransition) {
219 #ifdef EDM_ML_DEBUG
220  if (debug) {
221  std::cout << "newECALIdNS::Add " << iphi << " columns of cells for " << (dets.size() - last) << " cells (last "
222  << last << ")" << std::endl;
223  spr::debugEcalDets(last, dets, dir);
224  }
225 #endif
226  std::vector<DetId> vdets;
227  std::vector<CaloDirection> dirs;
228  vdets.insert(vdets.end(), dets.begin(), dets.end());
229  dirs.insert(dirs.end(), dir.begin(), dir.end());
230 
231  std::vector<DetId> vdetE, vdetW;
232  if (last == 0) {
233  unsigned int ndet = vdets.size();
234  std::vector<CaloDirection> dirE(ndet, EAST), dirW(ndet, WEST);
235  vdetE = spr::newECALIdEW(
236  dets, last, ieta, dirE, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
237  vdetW = spr::newECALIdEW(
238  dets, last, ieta, dirW, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
239  for (unsigned int i1 = 0; i1 < vdetW.size(); i1++) {
240  if (std::count(vdets.begin(), vdets.end(), vdetW[i1]) == 0) {
241  vdets.push_back(vdetW[i1]);
242  dirs.push_back(dir[0]);
243  }
244  }
245  for (unsigned int i1 = 0; i1 < vdetE.size(); i1++) {
246  if (std::count(vdets.begin(), vdets.end(), vdetE[i1]) == 0) {
247  vdets.push_back(vdetE[i1]);
248  dirs.push_back(dir[0]);
249  }
250  }
251 #ifdef EDM_ML_DEBUG
252  if (debug) {
253  std::cout << "newECALIdNS::With Added cells along E/W results a set of " << (vdets.size() - dets.size())
254  << " new cells" << std::endl;
255  spr::debugEcalDets(dets.size(), vdets, dirs);
256  }
257 #endif
258  }
259 
260  unsigned int last0 = vdets.size();
261  std::vector<DetId> vdetnew;
262  std::vector<CaloDirection> dirnew;
263  if (iphi > 0) {
264  std::vector<DetId> vdetn(1);
265  std::vector<CaloDirection> dirn(1);
266  std::vector<CaloDirection> dirnE(1, EAST), dirnW(1, WEST);
267  int flag = 0;
268  for (unsigned int i1 = last; i1 < dets.size(); i1++) {
269  std::vector<DetId> cells;
271  dets[i1], dir[i1], barrelTopo, endcapTopo, barrelGeom, endcapGeom, cells, flag, debug, ignoreTransition);
272  if (flag != 0) {
273  if (std::count(vdets.begin(), vdets.end(), cells[0]) == 0) {
274  vdetn[0] = cells[0];
275  vdetnew.push_back(vdetn[0]);
276  dirn[0] = dir[i1];
277  if (flag < 0) {
278  if (dirn[0] == NORTH)
279  dirn[0] = SOUTH;
280  else
281  dirn[0] = NORTH;
282  }
283  dirnew.push_back(dirn[0]);
284  vdetE = spr::newECALIdEW(
285  vdetn, 0, ieta, dirnE, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
286  vdetW = spr::newECALIdEW(
287  vdetn, 0, ieta, dirnW, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
288  for (unsigned int i2 = 0; i2 < vdetW.size(); i2++) {
289  if (std::count(vdets.begin(), vdets.end(), vdetW[i2]) == 0 &&
290  std::count(vdetnew.begin(), vdetnew.end(), vdetW[i2]) == 0) {
291  vdets.push_back(vdetW[i2]);
292  dirs.push_back(dirn[0]);
293  }
294  }
295  for (unsigned int i2 = 0; i2 < vdetE.size(); i2++) {
296  if (std::count(vdets.begin(), vdets.end(), vdetE[i2]) == 0 &&
297  std::count(vdetnew.begin(), vdetnew.end(), vdetE[i2]) == 0) {
298  vdets.push_back(vdetE[i2]);
299  dirs.push_back(dirn[0]);
300  }
301  }
302  }
303  }
304  }
305  iphi--;
306  last = vdets.size();
307  for (unsigned int i2 = 0; i2 < vdetnew.size(); i2++) {
308  if (std::count(vdets.begin(), vdets.end(), vdetnew[i2]) == 0) {
309  vdets.push_back(vdetnew[i2]);
310  dirs.push_back(dirnew[i2]);
311  }
312  }
313 #ifdef EDM_ML_DEBUG
314  if (debug) {
315  std::cout << "newECALIdNS::Addition results a set of " << (vdets.size() - last0) << " new cells (last "
316  << last0 << ", iphi " << iphi << ")" << std::endl;
317  spr::debugEcalDets(last0, vdets, dirs);
318  }
319 #endif
320  last0 = last;
321  }
322 
323  if (iphi > 0) {
324  last = last0;
325  return spr::newECALIdNS(
326  vdets, last, ieta, iphi, dirs, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
327  } else {
328 #ifdef EDM_ML_DEBUG
329  if (debug) {
330  std::cout << "newECALIdNS::Final list consists of " << vdets.size() << " cells" << std::endl;
331  spr::debugEcalDets(0, vdets);
332  }
333 #endif
334  return vdets;
335  }
336  }
337 
338  std::vector<DetId> newECALIdNS(std::vector<DetId>& dets,
339  unsigned int last,
340  std::vector<int>& ietaE,
341  std::vector<int>& ietaW,
342  std::vector<int>& iphiN,
343  std::vector<int>& iphiS,
344  std::vector<CaloDirection>& dir,
345  const CaloSubdetectorTopology* barrelTopo,
346  const CaloSubdetectorTopology* endcapTopo,
347  const EcalBarrelGeometry* barrelGeom,
348  const EcalEndcapGeometry* endcapGeom,
349  bool debug,
350  bool ignoreTransition) {
351 #ifdef EDM_ML_DEBUG
352  if (debug) {
353  std::cout << "newECALIdNS::Add columns of cells for " << (dets.size() - last) << " cells (last) " << last
354  << std::endl;
355  for (unsigned int i1 = last; i1 < dets.size(); i1++) {
356  spr::debugEcalDets(i1, dets[i1], false);
357  std::cout << " along " << dir[i1] << " # " << iphiN[i1] << "|" << iphiS[i1] << std::endl;
358  }
359  }
360 #endif
361  std::vector<DetId> vdets;
362  std::vector<CaloDirection> dirs;
363  std::vector<int> jetaE, jetaW, jphiN, jphiS;
364  vdets.insert(vdets.end(), dets.begin(), dets.end());
365  dirs.insert(dirs.end(), dir.begin(), dir.end());
366  jetaE.insert(jetaE.end(), ietaE.begin(), ietaE.end());
367  jetaW.insert(jetaW.end(), ietaW.begin(), ietaW.end());
368  jphiN.insert(jphiN.end(), iphiN.begin(), iphiN.end());
369  jphiS.insert(jphiS.end(), iphiS.begin(), iphiS.end());
370  std::vector<DetId> vdetE, vdetW;
371  if (last == 0) {
372  unsigned int ndet = vdets.size();
373  std::vector<CaloDirection> dirE(ndet, EAST), dirW(ndet, WEST);
374  vdetE = spr::newECALIdEW(
375  dets, last, ietaE, ietaW, dirE, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
376  vdetW = spr::newECALIdEW(
377  dets, last, ietaE, ietaW, dirW, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
378  for (unsigned int i1 = 0; i1 < vdetW.size(); i1++) {
379  if (std::count(vdets.begin(), vdets.end(), vdetW[i1]) == 0) {
380  vdets.push_back(vdetW[i1]);
381  dirs.push_back(dir[0]);
382  jetaE.push_back(0);
383  jetaW.push_back(0);
384  jphiN.push_back(iphiN[0]);
385  jphiS.push_back(iphiS[0]);
386  }
387  }
388  for (unsigned int i1 = 0; i1 < vdetE.size(); i1++) {
389  if (std::count(vdets.begin(), vdets.end(), vdetE[i1]) == 0) {
390  vdets.push_back(vdetE[i1]);
391  dirs.push_back(dir[0]);
392  jetaE.push_back(0);
393  jetaW.push_back(0);
394  jphiN.push_back(iphiN[0]);
395  jphiS.push_back(iphiS[0]);
396  }
397  }
398 #ifdef EDM_ML_DEBUG
399  if (debug) {
400  std::cout << "newECALIdNS::With Added cells along E/W results a set of " << (vdets.size() - dets.size())
401  << " new cells" << std::endl;
402  spr::debugEcalDets(dets.size(), vdets, dirs);
403  }
404 #endif
405  }
406 
407  unsigned int last0 = vdets.size();
408  std::vector<DetId> vdetnew;
409  std::vector<CaloDirection> dirnew;
410  std::vector<int> kphiN, kphiS, ketaE, ketaW;
411  int kphi = 0;
412  for (unsigned int i1 = last; i1 < dets.size(); i1++) {
413  int iphi = iphiS[i1];
414  if (dir[i1] == NORTH)
415  iphi = iphiN[i1];
416  if (iphi > 0) {
417  std::vector<DetId> vdetn(1);
418  std::vector<CaloDirection> dirn(1);
419  std::vector<CaloDirection> dirnE(1, EAST), dirnW(1, WEST);
420  int flag = 0;
421  std::vector<DetId> cells;
423  dets[i1], dir[i1], barrelTopo, endcapTopo, barrelGeom, endcapGeom, cells, flag, debug, ignoreTransition);
424  iphi--;
425  if (iphi > kphi)
426  kphi = iphi;
427  if (dir[i1] == NORTH)
428  jphiN[i1] = iphi;
429  else
430  jphiS[i1] = iphi;
431  if (flag != 0) {
432  if (std::count(vdets.begin(), vdets.end(), cells[0]) == 0) {
433  int kfiN = iphiN[i1];
434  int kfiS = iphiS[i1];
435  vdetn[0] = cells[0];
436  vdetnew.push_back(vdetn[0]);
437  dirn[0] = dir[i1];
438  if (dir[i1] == NORTH)
439  kfiN = iphi;
440  else
441  kfiS = iphi;
442  if (flag < 0) {
443  int ktmp = kfiS;
444  kfiS = kfiN;
445  kfiN = ktmp;
446  if (dirn[0] == NORTH)
447  dirn[0] = SOUTH;
448  else
449  dirn[0] = NORTH;
450  }
451  dirnew.push_back(dirn[0]);
452  kphiN.push_back(kfiN);
453  ketaE.push_back(ietaE[i1]);
454  kphiS.push_back(kfiS);
455  ketaW.push_back(ietaW[i1]);
456  std::vector<int> ietE(1, ietaE[i1]), ietW(1, ietaW[i1]);
457  vdetE = spr::newECALIdEW(
458  vdetn, 0, ietE, ietW, dirnE, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
459  vdetW = spr::newECALIdEW(
460  vdetn, 0, ietE, ietW, dirnW, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
461  for (unsigned int i2 = 0; i2 < vdetW.size(); i2++) {
462  if (std::count(vdets.begin(), vdets.end(), vdetW[i2]) == 0 &&
463  std::count(vdetnew.begin(), vdetnew.end(), vdetW[i2]) == 0) {
464  vdets.push_back(vdetW[i2]);
465  dirs.push_back(dirn[0]);
466  jetaE.push_back(0);
467  jphiN.push_back(kfiN);
468  jetaW.push_back(0);
469  jphiS.push_back(kfiS);
470  }
471  }
472  for (unsigned int i2 = 0; i2 < vdetE.size(); i2++) {
473  if (std::count(vdets.begin(), vdets.end(), vdetE[i2]) == 0 &&
474  std::count(vdetnew.begin(), vdetnew.end(), vdetE[i2]) == 0) {
475  vdets.push_back(vdetE[i2]);
476  dirs.push_back(dirn[0]);
477  jetaE.push_back(0);
478  jphiN.push_back(kfiN);
479  jetaW.push_back(0);
480  jphiS.push_back(kfiS);
481  }
482  }
483  }
484  }
485  }
486  }
487  last = vdets.size();
488  for (unsigned int i2 = 0; i2 < vdetnew.size(); i2++) {
489  if (std::count(vdets.begin(), vdets.end(), vdetnew[i2]) == 0) {
490  vdets.push_back(vdetnew[i2]);
491  dirs.push_back(dirnew[i2]);
492  jetaE.push_back(ketaE[i2]);
493  jetaW.push_back(ketaW[i2]);
494  jphiN.push_back(kphiN[i2]);
495  jphiS.push_back(kphiS[i2]);
496  }
497  }
498 #ifdef EDM_ML_DEBUG
499  if (debug) {
500  std::cout << "newECALIdNS::Addition results a set of " << (vdets.size() - last0) << " new cells (last " << last0
501  << ", iphi " << kphi << ")" << std::endl;
502  for (unsigned int i1 = last0; i1 < vdets.size(); i1++) {
503  spr::debugEcalDets(i1, vdets[i1], false);
504  std::cout << " along " << dirs[i1] << " iphi " << jphiN[i1] << "|" << jphiS[i1] << " ieta " << jetaE[i1] << "|"
505  << jetaW[i1] << std::endl;
506  }
507  }
508 #endif
509  last0 = last;
510 
511  if (kphi > 0) {
512  last = last0;
513  return spr::newECALIdNS(vdets,
514  last,
515  jetaE,
516  jetaW,
517  jphiN,
518  jphiS,
519  dirs,
520  barrelTopo,
521  endcapTopo,
522  barrelGeom,
523  endcapGeom,
524  debug,
525  ignoreTransition);
526  } else {
527 #ifdef EDM_ML_DEBUG
528  if (debug) {
529  std::cout << "newECALIdNS::Final list consists of " << vdets.size() << " cells" << std::endl;
530  spr::debugEcalDets(0, vdets);
531  }
532 #endif
533  return vdets;
534  }
535  }
536 
537  std::vector<DetId> newECALIdEW(std::vector<DetId>& dets,
538  unsigned int last,
539  int ieta,
540  std::vector<CaloDirection>& dir,
541  const CaloSubdetectorTopology* barrelTopo,
542  const CaloSubdetectorTopology* endcapTopo,
543  const EcalBarrelGeometry* barrelGeom,
544  const EcalEndcapGeometry* endcapGeom,
545  bool debug,
546  bool ignoreTransition) {
547 #ifdef EDM_ML_DEBUG
548  if (debug) {
549  std::cout << "newECALIdEW::Add " << ieta << " rows of cells for " << last << ":" << dets.size() << ":"
550  << (dets.size() - last) << " cells" << std::endl;
551  spr::debugEcalDets(last, dets, dir);
552  }
553 #endif
554  std::vector<DetId> vdets;
555  vdets.clear();
556  std::vector<CaloDirection> dirs;
557  dirs.clear();
558  vdets.insert(vdets.end(), dets.begin(), dets.end());
559  dirs.insert(dirs.end(), dir.begin(), dir.end());
560 
561  if (ieta > 0) {
562  for (unsigned int i1 = last; i1 < dets.size(); i1++) {
563  int flag = 0;
564  std::vector<DetId> cells;
566  dets[i1], dir[i1], barrelTopo, endcapTopo, barrelGeom, endcapGeom, cells, flag, debug, ignoreTransition);
567  if (flag != 0) {
568  if (std::count(vdets.begin(), vdets.end(), cells[0]) == 0) {
569  CaloDirection dirn = dir[i1];
570  if (flag < 0) {
571  if (dirn == EAST)
572  dirn = WEST;
573  else
574  dirn = EAST;
575  }
576  vdets.push_back(cells[0]);
577  dirs.push_back(dirn);
578  }
579  }
580  }
581  ieta--;
582  }
583 
584 #ifdef EDM_ML_DEBUG
585  if (debug) {
586  std::cout << "newECALIdEW::Addition results a set of " << (vdets.size() - dets.size()) << " new cells"
587  << std::endl;
588  spr::debugEcalDets(dets.size(), vdets, dirs);
589  }
590 #endif
591  if (ieta > 0) {
592  last = dets.size();
593  return spr::newECALIdEW(
594  vdets, last, ieta, dirs, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
595  } else {
596 #ifdef EDM_ML_DEBUG
597  if (debug) {
598  std::cout << "newECALIdEW::Final list (EW) consists of " << vdets.size() << " cells" << std::endl;
599  spr::debugEcalDets(0, vdets);
600  }
601 #endif
602  return vdets;
603  }
604  }
605 
606  std::vector<DetId> newECALIdEW(std::vector<DetId>& dets,
607  unsigned int last,
608  std::vector<int>& ietaE,
609  std::vector<int>& ietaW,
610  std::vector<CaloDirection>& dir,
611  const CaloSubdetectorTopology* barrelTopo,
612  const CaloSubdetectorTopology* endcapTopo,
613  const EcalBarrelGeometry* barrelGeom,
614  const EcalEndcapGeometry* endcapGeom,
615  bool debug,
616  bool ignoreTransition) {
617 #ifdef EDM_ML_DEBUG
618  if (debug) {
619  std::cout << "newECALIdEW::Add " << ietaE[0] << "|" << ietaW[0] << " rows of cells for " << (dets.size() - last)
620  << " cells (last " << last << ")" << std::endl;
621  spr::debugEcalDets(last, dets, dir);
622  }
623 #endif
624  std::vector<DetId> vdets;
625  vdets.insert(vdets.end(), dets.begin(), dets.end());
626  std::vector<CaloDirection> dirs;
627  dirs.insert(dirs.end(), dir.begin(), dir.end());
628  std::vector<int> jetaE, jetaW;
629  jetaE.insert(jetaE.end(), ietaE.begin(), ietaE.end());
630  jetaW.insert(jetaW.end(), ietaW.begin(), ietaW.end());
631  int keta = 0;
632  for (unsigned int i1 = last; i1 < dets.size(); i1++) {
633  int ieta = ietaW[i1];
634  if (dir[i1] == EAST)
635  ieta = ietaE[i1];
636  if (ieta > 0) {
637  int flag = 0;
638  std::vector<DetId> cells;
640  dets[i1], dir[i1], barrelTopo, endcapTopo, barrelGeom, endcapGeom, cells, flag, debug, ignoreTransition);
641  ieta--;
642  if (ieta > keta)
643  keta = ieta;
644  if (dir[i1] == EAST)
645  jetaE[i1] = ieta;
646  else
647  jetaW[i1] = ieta;
648  if (flag != 0) {
649  if (std::count(vdets.begin(), vdets.end(), cells[0]) == 0) {
650  vdets.push_back(cells[0]);
651  CaloDirection dirn = dir[i1];
652  int ketaE = ietaE[i1];
653  int ketaW = ietaW[i1];
654  if (dirn == EAST)
655  ketaE = ieta;
656  else
657  ketaW = ieta;
658  if (flag < 0) {
659  int ktmp = ketaW;
660  ketaW = ketaE;
661  ketaE = ktmp;
662  if (dirn == EAST)
663  dirn = WEST;
664  else
665  dirn = EAST;
666  }
667  dirs.push_back(dirn);
668  jetaE.push_back(ketaE);
669  jetaW.push_back(ketaW);
670  }
671  }
672  }
673  }
674 
675 #ifdef EDM_ML_DEBUG
676  if (debug) {
677  std::cout << "newECALIdEW::Addition results a set of " << (vdets.size() - dets.size()) << " new cells (last "
678  << dets.size() << ", ieta " << keta << ")" << std::endl;
679  spr::debugEcalDets(dets.size(), vdets);
680  }
681 #endif
682  if (keta > 0) {
683  last = dets.size();
684  return spr::newECALIdEW(
685  vdets, last, jetaE, jetaW, dirs, barrelTopo, endcapTopo, barrelGeom, endcapGeom, debug, ignoreTransition);
686  } else {
687 #ifdef EDM_ML_DEBUG
688  if (debug) {
689  std::cout << "newECALIdEW::Final list (EW) consists of " << vdets.size() << " cells" << std::endl;
690  spr::debugEcalDets(0, vdets);
691  }
692 #endif
693  return vdets;
694  }
695  }
696 
697  void simpleMove(DetId& det,
698  const CaloDirection& dir,
699  const CaloSubdetectorTopology* barrelTopo,
700  const CaloSubdetectorTopology* endcapTopo,
701  const EcalBarrelGeometry* barrelGeom,
702  const EcalEndcapGeometry* endcapGeom,
703  std::vector<DetId>& cells,
704  int& ok,
705  bool
706 #ifdef EDM_ML_DEBUG
707  debug
708 #endif
709  ,
710  bool ignoreTransition) {
711 
712  DetId cell;
713  ok = 0;
714  if (det.subdetId() == EcalBarrel) {
715  EBDetId detId = det;
716  std::vector<DetId> neighbours = barrelTopo->getNeighbours(detId, dir);
717  if (!neighbours.empty() && !neighbours[0].null()) {
718  cells.push_back(neighbours[0]);
719  cell = neighbours[0];
720  ok = 1;
721  } else {
722  const int ietaAbs(detId.ietaAbs()); // abs value of ieta
723  if (EBDetId::MAX_IETA == ietaAbs && (!ignoreTransition) && endcapGeom) {
724  // get ee nbrs for for end of barrel crystals
726  // take closest neighbour on the other side, that is in the endcap
727  cell = *(ol.begin());
728  neighbours = endcapTopo->getNeighbours(cell, dir);
729  if (!neighbours.empty() && !neighbours[0].null())
730  ok = 1;
731  else
732  ok = -1;
733  for (EcalBarrelGeometry::OrderedListOfEEDetId::const_iterator iptr = ol.begin(); iptr != ol.end(); ++iptr)
734  cells.push_back(*iptr);
735  }
736  }
737  } else if (det.subdetId() == EcalEndcap && endcapGeom) {
738  EEDetId detId = det;
739  std::vector<DetId> neighbours = endcapTopo->getNeighbours(detId, dir);
740  if (!neighbours.empty() && !neighbours[0].null()) {
741  cells.push_back(neighbours[0]);
742  cell = neighbours[0];
743  ok = 1;
744  } else {
745  // are we on the outer ring ?
746  const int iphi(detId.iPhiOuterRing());
747  // int isc = detId.isc();
748  if (iphi != 0 && (!ignoreTransition)) {
749  // get eb nbrs for for end of endcap crystals
751  // take closest neighbour on the other side, that is in the barrel.
752  cell = *(ol.begin());
753  neighbours = barrelTopo->getNeighbours(cell, dir);
754  if (!neighbours.empty() && !neighbours[0].null())
755  ok = 1;
756  else
757  ok = -1;
758  for (EcalEndcapGeometry::OrderedListOfEBDetId::const_iterator iptr = ol.begin(); iptr != ol.end(); ++iptr)
759  cells.push_back(*iptr);
760  }
761  }
762  }
763 #ifdef EDM_ML_DEBUG
764  if (debug) {
765  std::cout << "simpleMove:: Move DetId 0x" << std::hex << det() << std::dec << " along " << dir << " to get 0x"
766  << std::hex << cell() << std::dec << " with flag " << ok << " # " << cells.size();
767  for (unsigned int i1 = 0; i1 < cells.size(); ++i1)
768  std::cout << " " << std::hex << cells[0]() << std::dec;
769  std::cout << std::endl;
770  }
771 #endif
772  }
773 
774  void extraIds(const DetId& det,
775  std::vector<DetId>& dets,
776  int ietaE,
777  int ietaW,
778  int iphiN,
779  int iphiS,
780  const EcalBarrelGeometry* barrelGeom,
781  const EcalEndcapGeometry* endcapGeom,
782  std::vector<DetId>& cells,
783  bool
784 #ifdef EDM_ML_DEBUG
785  debug
786 #endif
787  ) {
788 
789  if (det.subdetId() == EcalBarrel) {
790  EBDetId id = det;
791 #ifdef EDM_ML_DEBUG
792  if (debug)
793  std::cout << "extraIds::Cell " << id << " rows " << ietaW << "|" << ietaE << " columns " << iphiS << "|"
794  << iphiN << std::endl;
795 #endif
796  int etaC = id.ietaAbs();
797  int phiC = id.iphi();
798  int zsid = id.zside();
799  for (int eta = -ietaW; eta <= ietaE; ++eta) {
800  for (int phi = -iphiS; phi <= iphiN; ++phi) {
801  int iphi = phiC + phi;
802  if (iphi < 0)
803  iphi += 360;
804  else if (iphi > 360)
805  iphi -= 360;
806  int ieta = zsid * (etaC + eta);
807  if (EBDetId::validDetId(ieta, iphi)) {
808  id = EBDetId(ieta, iphi);
809  if (barrelGeom->present(id)) {
810  if (std::count(dets.begin(), dets.end(), (DetId)id) == 0) {
811  cells.push_back((DetId)id);
812  }
813  }
814  }
815  }
816  }
817  } else if (det.subdetId() == EcalEndcap && endcapGeom) {
818  EEDetId id = det;
819 #ifdef EDM_ML_DEBUG
820  if (debug)
821  std::cout << "extraIds::Cell " << id << " rows " << ietaW << "|" << ietaE << " columns " << iphiS << "|"
822  << iphiN << std::endl;
823 #endif
824  int ixC = id.ix();
825  int iyC = id.iy();
826  int zsid = id.zside();
827  for (int kx = -ietaW; kx <= ietaE; ++kx) {
828  for (int ky = -iphiS; ky <= iphiN; ++ky) {
829  int ix = ixC + kx;
830  int iy = iyC + ky;
831  if (EEDetId::validDetId(ix, iy, zsid)) {
832  id = EEDetId(ix, iy, zsid);
833  if (endcapGeom->present(id)) {
834  if (std::count(dets.begin(), dets.end(), (DetId)id) == 0) {
835  cells.push_back((DetId)id);
836  }
837  }
838  }
839  }
840  }
841  }
842 
843 #ifdef EDM_ML_DEBUG
844  if (debug) {
845  std::cout << "extraIds:: finds " << cells.size() << " new cells" << std::endl;
847  }
848 #endif
849  }
850 } // namespace spr
Vector3DBase
Definition: Vector3DBase.h:8
CaloDirection
CaloDirection
Codes the local directions in the cell lattice.
Definition: CaloDirection.h:9
testProducerWithPsetDescEmpty_cfi.i2
i2
Definition: testProducerWithPsetDescEmpty_cfi.py:46
mps_fire.i
i
Definition: mps_fire.py:355
spr
Definition: CaloConstants.h:6
EcalBarrelGeometry::getClosestEndcapCells
const OrderedListOfEEDetId * getClosestEndcapCells(EBDetId id) const
Definition: EcalBarrelGeometry.cc:338
EcalEndcapGeometry
Definition: EcalEndcapGeometry.h:20
CaloGeometry::getPosition
GlobalPoint getPosition(const DetId &id) const
Get the position of a given detector id.
Definition: CaloGeometry.cc:50
heppy_check.dirs
dirs
Definition: heppy_check.py:26
EBDetId
Definition: EBDetId.h:17
gather_cfg.cout
cout
Definition: gather_cfg.py:144
EBDetId.h
EEDetId.h
testProducerWithPsetDescEmpty_cfi.i1
i1
Definition: testProducerWithPsetDescEmpty_cfi.py:45
DebugInfo.h
CaloGeometry::getSubdetectorGeometry
const CaloSubdetectorGeometry * getSubdetectorGeometry(const DetId &id) const
access the subdetector geometry for the given subdetector directly
Definition: CaloGeometry.cc:34
spr::debugEcalDets
void debugEcalDets(unsigned int, const DetId &, bool)
Definition: DebugInfo.cc:11
EZArrayFL
Definition: EZArrayFL.h:20
spr::matrixECALIds
void matrixECALIds(const DetId &det, int ieta, int iphi, const CaloGeometry *geo, const CaloTopology *caloTopology, std::vector< DetId > &vdets, bool debug=false, bool igNoreTransition=true)
Definition: MatrixECALDetIds.cc:16
EcalEndcapGeometry::present
bool present(const DetId &id) const override
is this detid present in the geometry?
Definition: EcalEndcapGeometry.cc:450
convertSQLiteXML.ok
bool ok
Definition: convertSQLiteXML.py:98
spr::getDistInPlaneTrackDir
double getDistInPlaneTrackDir(const GlobalPoint &caloPoint, const GlobalVector &caloVector, const GlobalPoint &rechitPoint, bool debug=false)
Definition: FindDistCone.cc:12
CaloTopology
Definition: CaloTopology.h:19
EcalBarrel
Definition: EcalSubdetector.h:10
LEDCalibrationChannels.iphi
iphi
Definition: LEDCalibrationChannels.py:64
DetId
Definition: DetId.h:17
CaloGeometry
Definition: CaloGeometry.h:21
dqmdumpme.last
last
Definition: dqmdumpme.py:56
debug
#define debug
Definition: HDRShower.cc:19
EAST
Definition: CaloDirection.h:14
NORTH
Definition: CaloDirection.h:18
PVValHelper::eta
Definition: PVValidationHelpers.h:69
MatrixECALDetIds.h
EDM_ML_DEBUG
#define EDM_ML_DEBUG
Definition: HcalHBHEMuonSimAnalyzer.cc:41
EZArrayFL::const_iterator
MgrType::const_iterator const_iterator
Definition: EZArrayFL.h:24
Point3DBase< float, GlobalTag >
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
EEDetId
Definition: EEDetId.h:14
spr::extraIds
void extraIds(const DetId &det, std::vector< DetId > &dets, int ietaE, int ietaW, int iphiN, int iphiS, const EcalBarrelGeometry *barrelGeom, const EcalEndcapGeometry *endcapGeom, std::vector< DetId > &cells, bool debug=false)
Definition: MatrixECALDetIds.cc:774
EcalSubdetector.h
EcalEndcap
Definition: EcalSubdetector.h:10
CaloSubdetectorTopology::getNeighbours
virtual std::vector< DetId > getNeighbours(const DetId &id, const CaloDirection &dir) const
Definition: CaloSubdetectorTopology.h:77
LEDCalibrationChannels.ieta
ieta
Definition: LEDCalibrationChannels.py:63
spr::newECALIdEW
std::vector< DetId > newECALIdEW(std::vector< DetId > &dets, unsigned int last, int ieta, std::vector< CaloDirection > &dir, const CaloSubdetectorTopology *barrelTopo, const CaloSubdetectorTopology *endcapTopo, const EcalBarrelGeometry *barrelGeom, const EcalEndcapGeometry *endcapGeom, bool debug=false, bool igNoreTransition=true)
Definition: MatrixECALDetIds.cc:537
core
Definition: __init__.py:1
EcalBarrelGeometry
Definition: EcalBarrelGeometry.h:19
KineDebug3::count
void count()
Definition: KinematicConstrainedVertexUpdatorT.h:21
CaloTopology::getSubdetectorTopology
const CaloSubdetectorTopology * getSubdetectorTopology(const DetId &id) const
access the subdetector Topology for the given subdetector directly
Definition: CaloTopology.cc:17
createfilelist.int
int
Definition: createfilelist.py:10
EcalBarrelGeometry::present
bool present(const DetId &id) const override
is this detid present in the geometry?
Definition: EcalBarrelGeometry.cc:441
CaloSubdetectorTopology
Definition: CaloSubdetectorTopology.h:17
DetId::Ecal
Definition: DetId.h:27
EBDetId::validDetId
static bool validDetId(int i, int j)
check if a valid index combination
Definition: EBDetId.h:118
EcalEndcapGeometry::getClosestBarrelCells
const OrderedListOfEBDetId * getClosestBarrelCells(EEDetId id) const
Definition: EcalEndcapGeometry.cc:372
WEST
Definition: CaloDirection.h:15
spr::simpleMove
void simpleMove(DetId &det, const CaloDirection &dir, const CaloSubdetectorTopology *barrelTopo, const CaloSubdetectorTopology *endcapTopo, const EcalBarrelGeometry *barrelGeom, const EcalEndcapGeometry *endcapGeom, std::vector< DetId > &cells, int &flag, bool debug=false, bool igNoreTransition=true)
Definition: MatrixECALDetIds.cc:697
postprocess-scan-build.cells
cells
Definition: postprocess-scan-build.py:13
FindDistCone.h
EBDetId::ietaAbs
int ietaAbs() const
get the absolute value of the crystal ieta
Definition: EBDetId.h:47
EEDetId::validDetId
static bool validDetId(int crystal_ix, int crystal_iy, int iz)
Definition: EEDetId.h:248
EEDetId::iPhiOuterRing
int iPhiOuterRing() const
Definition: EEDetId.cc:295
SOUTH
Definition: CaloDirection.h:11
HGC3DClusterGenMatchSelector_cfi.dR
dR
Definition: HGC3DClusterGenMatchSelector_cfi.py:7
spr::newECALIdNS
std::vector< DetId > newECALIdNS(std::vector< DetId > &dets, unsigned int last, int ieta, int iphi, std::vector< CaloDirection > &dir, const CaloSubdetectorTopology *barrelTopo, const CaloSubdetectorTopology *endcapTopo, const EcalBarrelGeometry *barrelGeom, const EcalEndcapGeometry *endcapGeom, bool debug=false, bool igNoreTransition=true)
Definition: MatrixECALDetIds.cc:208
TauDecayModes.dec
dec
Definition: TauDecayModes.py:143
EBDetId::MAX_IETA
static const int MAX_IETA
Definition: EBDetId.h:136
RemoveAddSevLevel.flag
flag
Definition: RemoveAddSevLevel.py:116
DeadROC_duringRun.dir
dir
Definition: DeadROC_duringRun.py:23