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