CMS 3D CMS Logo

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