CMS 3D CMS Logo

PixelInactiveAreaFinder.cc
Go to the documentation of this file.
2 
12 
14 
15 #include <fstream>
16 #include <queue>
17 #include <algorithm>
18 
19 std::ostream& operator<<(std::ostream& os, SeedingLayerSetsBuilder::SeedingLayerId layer) {
20  if (std::get<0>(layer) == GeomDetEnumerators::PixelBarrel) {
21  os << "BPix";
22  } else {
23  os << "FPix";
24  }
25  os << std::get<2>(layer);
26  if (std::get<1>(layer) == TrackerDetSide::PosEndcap) {
27  os << "_pos";
28  } else if (std::get<1>(layer) == TrackerDetSide::NegEndcap) {
29  os << "_neg";
30  }
31  return os;
32 }
33 
34 namespace {
35  using LayerPair = std::pair<SeedingLayerSetsBuilder::SeedingLayerId, SeedingLayerSetsBuilder::SeedingLayerId>;
36  using ActiveLayerSetToInactiveSetsMap = std::map<LayerPair, edm::VecArray<LayerPair, 5>>;
37  using Stream = std::stringstream;
38  using Span_t = std::pair<float, float>;
39 
40  ActiveLayerSetToInactiveSetsMap createActiveToInactiveMap() {
41  ActiveLayerSetToInactiveSetsMap map;
42 
43  auto bpix = [](int layer) {
45  };
46  auto fpix_pos = [](int disk) {
48  };
49  auto fpix_neg = [](int disk) {
51  };
52 
53  auto add_permutations = [&](std::array<SeedingLayerSetsBuilder::SeedingLayerId, 4> quads) {
54  do {
55  // skip permutations like BPix2+BPix1 or FPix1+BPix1
56  // operator> works automatically
57  if (quads[0] > quads[1] || quads[2] > quads[3])
58  continue;
59 
60  map[std::make_pair(quads[0], quads[1])].emplace_back(quads[2], quads[3]);
61  } while (std::next_permutation(quads.begin(), quads.end()));
62  };
63 
64  // 4 barrel
65  add_permutations({{bpix(1), bpix(2), bpix(3), bpix(4)}});
66 
67  // 3 barrel, 1 forward
68  add_permutations({{bpix(1), bpix(2), bpix(3), fpix_pos(1)}});
69  add_permutations({{bpix(1), bpix(2), bpix(3), fpix_neg(1)}});
70 
71  // 2 barrel, 2 forward
72  add_permutations({{bpix(1), bpix(2), fpix_pos(1), fpix_pos(2)}});
73  add_permutations({{bpix(1), bpix(2), fpix_neg(1), fpix_neg(2)}});
74 
75  // 1 barrel, 3 forward
76  add_permutations({{bpix(1), fpix_pos(1), fpix_pos(2), fpix_pos(3)}});
77  add_permutations({{bpix(1), fpix_neg(1), fpix_neg(2), fpix_neg(3)}});
78 
79 #ifdef EDM_ML_DEBUG
80  LogDebug("PixelInactiveAreaFinder") << "Active to inactive mapping";
81  for (const auto& elem : map) {
82  std::stringstream ss;
83  for (const auto& layerPair : elem.second) {
84  ss << layerPair.first << "+" << layerPair.second << ",";
85  }
86  LogTrace("PixelInactiveAreaFinder") << " " << elem.first.first << "+" << elem.first.second << " => " << ss.str();
87  }
88 #endif
89 
90  return map;
91  }
92 
93  void detGroupSpanInfo(const PixelInactiveAreaFinder::DetGroupSpan& cspan, Stream& ss) {
94  using std::fixed;
95  using std::left;
96  using std::noshowpos;
97  using std::right;
98  using std::setfill;
99  using std::setprecision;
100  using std::setw;
101  using std::showpos;
102  std::string deli = "; ";
103  ss << "subdetid:[" << cspan.subdetId << "]" << deli;
105  ss << "layer:[" << cspan.layer << "]" << deli;
106  } else {
107  ss << "disk:[" << cspan.disk << "]" << deli;
108  }
109  ss
110  //<< setfill(' ') << setw(36) << " "
111  << setprecision(16) << showpos << "phi:<" << right << setw(12) << cspan.phiSpan.first << "," << left << setw(12)
112  << cspan.phiSpan.second << ">" << deli << "z:<" << right << setw(7) << cspan.zSpan.first << "," << left
113  << setw(7) << cspan.zSpan.second << ">" << deli << noshowpos << "r:<" << right << setw(10) << cspan.rSpan.first
114  << "," << left << setw(10) << cspan.rSpan.second << ">" << deli;
115  }
116  void printOverlapSpans(const PixelInactiveAreaFinder::InactiveAreas& areasLayers) {
117  auto spansLayerSets = areasLayers.spansAndLayerSets(GlobalPoint(0, 0, 0), std::numeric_limits<float>::infinity());
118 
119  Stream ss;
120  for (auto const& spansLayers : spansLayerSets) {
121  ss << "Overlapping detGroups:\n";
122  for (auto const& cspan : spansLayers.first) {
123  detGroupSpanInfo(cspan, ss);
124  ss << std::endl;
125  }
126  }
127  edm::LogPrint("PixelInactiveAreaFinder") << ss.str();
128  }
129 
130  // Functions for finding bad detGroups
131  bool phiRangesOverlap(const Span_t& phiSpanA, const Span_t& phiSpanB) {
132  float x1, x2, y1, y2;
133  std::tie(x1, x2) = phiSpanA;
134  std::tie(y1, y2) = phiSpanB;
135  // assuming phi ranges are [x1,x2] and [y1,y2] and xi,yi in [-pi,pi]
136  if (x1 <= x2 && y1 <= y2) {
137  return x1 <= y2 && y1 <= x2;
138  } else if ((x1 > x2 && y1 <= y2) || (y1 > y2 && x1 <= x2)) {
139  return y1 <= x2 || x1 <= y2;
140  } else if (x1 > x2 && y1 > y2) {
141  return true;
142  } else {
143  return false;
144  }
145  }
146 
147  // Functions for finding ranges that detGroups cover
148  bool phiMoreClockwise(float phiA, float phiB) {
149  // return true if a is more clockwise than b
150  return reco::deltaPhi(phiA, phiB) <= 0.f;
151  }
152  bool phiMoreCounterclockwise(float phiA, float phiB) {
153  // return true if a is more counterclockwise than b
154  return reco::deltaPhi(phiA, phiB) >= 0.f;
155  }
156 
157  // Functions for findind overlapping functions
158  float zAxisIntersection(const float zrPointA[2], const float zrPointB[2]) {
159  return (zrPointB[0] - zrPointA[0]) / (zrPointB[1] - zrPointA[1]) * (-zrPointA[1]) + zrPointA[0];
160  }
161  bool getZAxisOverlapRangeBarrel(const PixelInactiveAreaFinder::DetGroupSpan& cspanA,
163  std::pair<float, float>& range) {
166  if (cspanA.rSpan.second < cspanB.rSpan.first) {
167  cspanLower = cspanA;
168  cspanUpper = cspanB;
169  } else if (cspanA.rSpan.first > cspanB.rSpan.second) {
170  cspanUpper = cspanA;
171  cspanLower = cspanB;
172  } else {
173  return false;
174  }
175  float lower = 0;
176  float upper = 0;
177  if (cspanUpper.zSpan.second < cspanLower.zSpan.first) {
178  // lower intersectionpoint, point = {z,r} in cylindrical coordinates
179  const float pointUpperDetGroupL[2] = {cspanUpper.zSpan.second, cspanUpper.rSpan.second};
180  const float pointLowerDetGroupL[2] = {cspanLower.zSpan.first, cspanLower.rSpan.first};
181  lower = zAxisIntersection(pointUpperDetGroupL, pointLowerDetGroupL);
182  // upper intersectionpoint
183  const float pointUpperDetGroupU[2] = {cspanUpper.zSpan.first, cspanUpper.rSpan.first};
184  const float pointLowerDetGroupU[2] = {cspanLower.zSpan.second, cspanLower.rSpan.second};
185  upper = zAxisIntersection(pointUpperDetGroupU, pointLowerDetGroupU);
186  } else if (cspanUpper.zSpan.first <= cspanLower.zSpan.second && cspanLower.zSpan.first <= cspanUpper.zSpan.second) {
187  // lower intersectionpoint, point = {z,r} in cylindrical coordinates
188  const float pointUpperDetGroupL[2] = {cspanUpper.zSpan.second, cspanUpper.rSpan.first};
189  const float pointLowerDetGroupL[2] = {cspanLower.zSpan.first, cspanLower.rSpan.second};
190  lower = zAxisIntersection(pointUpperDetGroupL, pointLowerDetGroupL);
191  // upper intersectionpoint
192  const float pointUpperDetGroupU[2] = {cspanUpper.zSpan.first, cspanUpper.rSpan.first};
193  const float pointLowerDetGroupU[2] = {cspanLower.zSpan.second, cspanLower.rSpan.second};
194  upper = zAxisIntersection(pointUpperDetGroupU, pointLowerDetGroupU);
195  } else if (cspanUpper.zSpan.first > cspanLower.zSpan.second) {
196  // lower intersectionpoint, point = {z,r} in cylindrical coordinates
197  const float pointUpperDetGroupL[2] = {cspanUpper.zSpan.second, cspanUpper.rSpan.first};
198  const float pointLowerDetGroupL[2] = {cspanLower.zSpan.first, cspanLower.rSpan.second};
199  lower = zAxisIntersection(pointUpperDetGroupL, pointLowerDetGroupL);
200  // upper intersectionpoint
201  const float pointUpperDetGroupU[2] = {cspanUpper.zSpan.first, cspanUpper.rSpan.second};
202  const float pointLowerDetGroupU[2] = {cspanLower.zSpan.second, cspanLower.rSpan.first};
203  upper = zAxisIntersection(pointUpperDetGroupU, pointLowerDetGroupU);
204  } else {
205  //something wrong
206  return false;
207  }
208  range = std::pair<float, float>(lower, upper);
209  return true;
210  }
211  bool getZAxisOverlapRangeEndcap(const PixelInactiveAreaFinder::DetGroupSpan& cspanA,
213  std::pair<float, float>& range) {
214  // While on left hand side of pixel detector
217  float lower = 0;
218  float upper = 0;
219  if (cspanA.zSpan.first < 0 && cspanB.zSpan.first < 0) {
220  if (cspanA.zSpan.second < cspanB.zSpan.first) {
221  cspanFurther = cspanA;
222  cspanNearer = cspanB;
223  } else if (cspanB.zSpan.second < cspanA.zSpan.first) {
224  cspanFurther = cspanB;
225  cspanNearer = cspanA;
226  } else {
227 #ifdef EDM_ML_DEBUG
228  LogTrace("PixelInactiveAreaFinder") << "No overlap, same disk propably. Spans:";
229  Stream ss;
230  detGroupSpanInfo(cspanA, ss);
231  ss << std::endl;
232  detGroupSpanInfo(cspanB, ss);
233  ss << std::endl;
234  LogTrace("PixelInactiveAreaFinder") << ss.str();
235  ss.str(std::string());
236  LogTrace("PixelInactiveAreaFinder") << "**";
237 #endif
238  return false;
239  }
240  if (cspanFurther.rSpan.second > cspanNearer.rSpan.first) {
241  const float pointA[2] = {cspanFurther.zSpan.second, cspanFurther.rSpan.second};
242  const float pointB[2] = {cspanNearer.zSpan.first, cspanNearer.rSpan.first};
243  lower = zAxisIntersection(pointA, pointB);
244  if (cspanFurther.rSpan.first > cspanNearer.rSpan.second) {
245  const float pointC[2] = {cspanFurther.zSpan.first, cspanFurther.rSpan.first};
246  const float pointD[2] = {cspanNearer.zSpan.second, cspanFurther.rSpan.second};
247  upper = zAxisIntersection(pointC, pointD);
248  } else {
250  }
251  } else {
252 #ifdef EDM_ML_DEBUG
253  LogTrace("PixelInactiveAreaFinder") << "No overlap, further detGroup is lower. Spans:";
254  Stream ss;
255  detGroupSpanInfo(cspanA, ss);
256  ss << std::endl;
257  detGroupSpanInfo(cspanB, ss);
258  ss << std::endl;
259  LogTrace("PixelInactiveAreaFinder") << ss.str();
260  ss.str(std::string());
261  LogTrace("PixelInactiveAreaFinder") << "**";
262 #endif
263  return false;
264  }
265  } else if (cspanA.zSpan.first > 0 && cspanB.zSpan.first > 0) {
266  if (cspanA.zSpan.first > cspanB.zSpan.second) {
267  cspanFurther = cspanA;
268  cspanNearer = cspanB;
269  } else if (cspanB.zSpan.first > cspanA.zSpan.second) {
270  cspanFurther = cspanB;
271  cspanNearer = cspanA;
272  } else {
273 #ifdef EDM_ML_DEBUG
274  LogTrace("PixelInactiveAreaFinder") << "No overlap, same disk propably. Spans:";
275  Stream ss;
276  detGroupSpanInfo(cspanA, ss);
277  ss << std::endl;
278  detGroupSpanInfo(cspanB, ss);
279  ss << std::endl;
280  LogTrace("PixelInactiveAreaFinder") << ss.str();
281  ss.str(std::string());
282  LogTrace("PixelInactiveAreaFinder") << "**";
283 #endif
284  return false;
285  }
286  if (cspanFurther.rSpan.second > cspanNearer.rSpan.first) {
287  const float pointA[2] = {cspanFurther.zSpan.first, cspanFurther.rSpan.second};
288  const float pointB[2] = {cspanNearer.zSpan.second, cspanNearer.rSpan.first};
289  upper = zAxisIntersection(pointA, pointB);
290  if (cspanFurther.rSpan.first > cspanNearer.rSpan.second) {
291  const float pointC[2] = {cspanFurther.zSpan.second, cspanFurther.rSpan.first};
292  const float pointD[2] = {cspanNearer.zSpan.first, cspanFurther.rSpan.second};
293  lower = zAxisIntersection(pointC, pointD);
294  } else {
296  }
297  } else {
298 #ifdef EDM_ML_DEBUG
299  LogTrace("PixelInactiveAreaFinder") << "No overlap, further detGroup lower. Spans:";
300  Stream ss;
301  detGroupSpanInfo(cspanA, ss);
302  ss << std::endl;
303  detGroupSpanInfo(cspanB, ss);
304  ss << std::endl;
305  LogTrace("PixelInactiveAreaFinder") << ss.str();
306  ss.str(std::string());
307  LogTrace("PixelInactiveAreaFinder") << "**";
308 #endif
309  return false;
310  }
311  } else {
312 #ifdef EDM_ML_DEBUG
313  LogTrace("PixelInactiveAreaFinder") << "No overlap, different sides of z axis. Spans:";
314  Stream ss;
315  detGroupSpanInfo(cspanA, ss);
316  ss << std::endl;
317  detGroupSpanInfo(cspanB, ss);
318  ss << std::endl;
319  LogTrace("PixelInactiveAreaFinder") << ss.str();
320  ss.str(std::string());
321  LogTrace("PixelInactiveAreaFinder") << "**";
322 #endif
323  return false;
324  }
325  range = std::pair<float, float>(lower, upper);
326  return true;
327  }
328 
329  bool getZAxisOverlapRangeBarrelEndcap(const PixelInactiveAreaFinder::DetGroupSpan& cspanBar,
331  std::pair<float, float>& range) {
332  float lower = 0;
333  float upper = 0;
334  if (cspanEnd.rSpan.second > cspanBar.rSpan.first) {
335  if (cspanEnd.zSpan.second < cspanBar.zSpan.first) {
336  // if we are on the left hand side of pixel detector
337  const float pointA[2] = {cspanEnd.zSpan.second, cspanEnd.rSpan.second};
338  const float pointB[2] = {cspanBar.zSpan.first, cspanBar.rSpan.first};
339  lower = zAxisIntersection(pointA, pointB);
340  if (cspanEnd.rSpan.first > cspanBar.rSpan.second) {
341  // if does not overlap, then there is also upper limit
342  const float pointC[2] = {cspanEnd.zSpan.first, cspanEnd.rSpan.first};
343  const float pointD[2] = {cspanBar.zSpan.second, cspanBar.rSpan.second};
344  upper = zAxisIntersection(pointC, pointD);
345  } else {
347  }
348  } else if (cspanEnd.zSpan.first > cspanBar.zSpan.second) {
349  // if we are on the right hand side of pixel detector
350  const float pointA[2] = {cspanEnd.zSpan.first, cspanEnd.rSpan.second};
351  const float pointB[2] = {cspanBar.zSpan.second, cspanBar.rSpan.first};
352  upper = zAxisIntersection(pointA, pointB);
353  if (cspanEnd.rSpan.first > cspanBar.rSpan.second) {
354  const float pointC[2] = {cspanEnd.zSpan.second, cspanEnd.rSpan.first};
355  const float pointD[2] = {cspanBar.zSpan.first, cspanBar.rSpan.second};
356  lower = zAxisIntersection(pointC, pointD);
357  } else {
359  }
360  } else {
361  return false;
362  }
363  } else {
364  return false;
365  }
366  range = std::pair<float, float>(lower, upper);
367  return true;
368  }
369 } // namespace
370 
372  std::pair<edm::VecArray<PixelInactiveAreaFinder::Area, 2>, std::vector<PixelInactiveAreaFinder::LayerSetIndex>>>
374  auto spansLayerSets = spansAndLayerSets(point, zwidth);
375 
376  // TODO: try to remove this conversion...
377  std::vector<std::pair<VecArray2<Area>, std::vector<LayerSetIndex>>> ret;
378  for (auto& item : spansLayerSets) {
379  auto& innerSpan = item.first[0];
380  auto& outerSpan = item.first[1];
381  VecArray2<Area> areas;
382  areas.emplace_back(innerSpan.rSpan.first,
383  innerSpan.rSpan.second,
384  innerSpan.phiSpan.first,
385  innerSpan.phiSpan.second,
386  innerSpan.zSpan.first,
387  innerSpan.zSpan.second);
388  areas.emplace_back(outerSpan.rSpan.first,
389  outerSpan.rSpan.second,
390  outerSpan.phiSpan.first,
391  outerSpan.phiSpan.second,
392  outerSpan.zSpan.first,
393  outerSpan.zSpan.second);
394  ret.emplace_back(areas, std::move(item.second));
395  }
396 
397  return ret;
398 }
399 
400 std::vector<std::pair<edm::VecArray<PixelInactiveAreaFinder::DetGroupSpan, 2>,
401  std::vector<PixelInactiveAreaFinder::LayerSetIndex>>>
403  // TODO: in the future use 2D-r for the origin for the phi overlap check
404  const float zmin = point.z() - zwidth;
405  const float zmax = point.z() + zwidth;
406 
407  std::vector<std::pair<VecArray2<DetGroupSpan>, std::vector<LayerSetIndex>>> ret;
408 
409  LogDebug("PixelInactiveAreaFinder") << "Origin at " << point.x() << "," << point.y() << "," << point.z()
410  << " z half width " << zwidth;
411 
412  for (LayerSetIndex i = 0, end = inactiveLayerPairIndices_->size(); i < end; ++i) {
413  const auto& layerIdxPair = (*inactiveLayerPairIndices_)[i];
414  const auto& innerSpans = inactiveSpans_[layerIdxPair.first];
415  const auto& outerSpans = inactiveSpans_[layerIdxPair.second];
416 
417  for (const auto& innerSpan : innerSpans) {
418  for (const auto& outerSpan : outerSpans) {
419  if (phiRangesOverlap(innerSpan.phiSpan, outerSpan.phiSpan)) {
420  std::pair<float, float> range(0, 0);
421 
422  bool zOverlap = false;
423  const auto innerDet = std::get<0>((*inactiveLayers_)[layerIdxPair.first]);
424  const auto outerDet = std::get<0>((*inactiveLayers_)[layerIdxPair.second]);
425  if (innerDet == GeomDetEnumerators::PixelBarrel) {
426  if (outerDet == GeomDetEnumerators::PixelBarrel)
427  zOverlap = getZAxisOverlapRangeBarrel(innerSpan, outerSpan, range);
428  else
429  zOverlap = getZAxisOverlapRangeBarrelEndcap(innerSpan, outerSpan, range);
430  } else {
431  if (outerDet == GeomDetEnumerators::PixelEndcap)
432  zOverlap = getZAxisOverlapRangeEndcap(innerSpan, outerSpan, range);
433  else
434  throw cms::Exception("LogicError") << "Forward->barrel transition is not supported";
435  }
436 
437  if (zOverlap && zmin <= range.second && range.first <= zmax) {
438 #ifdef EDM_ML_DEBUG
439  Stream ss;
440  for (auto ind : (*layerSetIndexInactiveToActive_)[i]) {
441  ss << ind << ",";
442  }
443  ss << "\n ";
444  detGroupSpanInfo(innerSpan, ss);
445  ss << "\n ";
446  detGroupSpanInfo(outerSpan, ss);
447  LogTrace("PixelInactiveAreaFinder") << " adding areas for active layer sets " << ss.str();
448 #endif
450  vec.emplace_back(innerSpan);
451  vec.emplace_back(outerSpan);
452  ret.emplace_back(std::move(vec), (*layerSetIndexInactiveToActive_)[i]);
453  }
454  }
455  }
456  }
457  }
458 
459  return ret;
460 }
461 
463  const edm::ParameterSet& iConfig,
464  const std::vector<SeedingLayerSetsBuilder::SeedingLayerId>& seedingLayers,
465  const SeedingLayerSetsLooper& seedingLayerSetsLooper,
467  : debug_(iConfig.getUntrackedParameter<bool>("debug")),
468  createPlottingFiles_(iConfig.getUntrackedParameter<bool>("createPlottingFiles")),
469  ignoreSingleFPixPanelModules_(iConfig.getParameter<bool>("ignoreSingleFPixPanelModules")),
471  edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag>>("inactivePixelDetectorLabels"),
472  [&](const auto& tag) { return iC.consumes<DetIdCollection>(tag); })),
473  badPixelFEDChannelsTokens_(
474  edm::vector_transform(iConfig.getParameter<std::vector<edm::InputTag>>("badPixelFEDChannelCollectionLabels"),
475  [&](const auto& tag) { return iC.consumes<PixelFEDChannelCollection>(tag); })) {
476 #ifdef EDM_ML_DEBUG
477  for (const auto& layer : seedingLayers) {
478  LogTrace("PixelInactiveAreaFinder") << "Input layer subdet " << std::get<0>(layer) << " side "
479  << static_cast<unsigned int>(std::get<1>(layer)) << " layer "
480  << std::get<2>(layer);
481  }
482 #endif
483 
484  auto findOrAdd = [&](SeedingLayerId layer) -> unsigned short {
485  auto found = std::find(inactiveLayers_.cbegin(), inactiveLayers_.cend(), layer);
486  if (found == inactiveLayers_.cend()) {
487  auto ret = inactiveLayers_.size();
488  inactiveLayers_.push_back(layer);
489  return ret;
490  }
491  return std::distance(inactiveLayers_.cbegin(), found);
492  };
493 
494  // mapping from active layer pairs to inactive layer pairs
495  const auto activeToInactiveMap = createActiveToInactiveMap();
496 
497  // convert input layer pairs (that are for active layers) to layer
498  // pairs to look for inactive areas
499  LayerSetIndex i = 0;
500  for (const auto& layerSet : seedingLayerSetsLooper.makeRange(seedingLayers)) {
501  assert(layerSet.size() == 2);
502  auto found = activeToInactiveMap.find(std::make_pair(layerSet[0], layerSet[1]));
503  if (found == activeToInactiveMap.end()) {
504  throw cms::Exception("Configuration")
505  << "Encountered layer pair " << layerSet[0] << "+" << layerSet[1]
506  << " not found from the internal 'active layer pairs' to 'inactive layer pairs' mapping; either fix the "
507  "input or the mapping (in PixelInactiveAreaFinder.cc)";
508  }
509 
510  LogTrace("PixelInactiveAreaFinder") << "Input layer set " << layerSet[0] << "+" << layerSet[1];
511  for (const auto& inactiveLayerSet : found->second) {
512  auto innerInd = findOrAdd(inactiveLayerSet.first);
513  auto outerInd = findOrAdd(inactiveLayerSet.second);
514 
515  auto found = std::find(
516  inactiveLayerSetIndices_.cbegin(), inactiveLayerSetIndices_.cend(), std::make_pair(innerInd, outerInd));
517  if (found == inactiveLayerSetIndices_.end()) {
518  inactiveLayerSetIndices_.emplace_back(innerInd, outerInd);
519  layerSetIndexInactiveToActive_.push_back(std::vector<LayerSetIndex>{i});
520  } else {
521  layerSetIndexInactiveToActive_.at(std::distance(inactiveLayerSetIndices_.cbegin(), found))
522  .push_back(i); // TODO: move to operator[] once finished
523  }
524 
525  LogTrace("PixelInactiveAreaFinder")
526  << " inactive layer set " << inactiveLayerSet.first << "+" << inactiveLayerSet.second;
527  }
528 
529  ++i;
530  }
531 
532 #ifdef EDM_ML_DEBUG
533  LogDebug("PixelInactiveAreaFinder") << "All inactive layer sets";
534  for (const auto& idxPair : inactiveLayerSetIndices_) {
535  LogTrace("PixelInactiveAreaFinder") << " " << inactiveLayers_[idxPair.first] << "+"
536  << inactiveLayers_[idxPair.second];
537  }
538 #endif
539 }
540 
542  desc.add<std::vector<edm::InputTag>>("inactivePixelDetectorLabels",
543  std::vector<edm::InputTag>{{edm::InputTag("siPixelDigis")}})
544  ->setComment("One or more DetIdCollections of modules to mask on the fly for a given event");
545  desc.add<std::vector<edm::InputTag>>("badPixelFEDChannelCollectionLabels",
546  std::vector<edm::InputTag>{{edm::InputTag("siPixelDigis")}})
547  ->setComment("One or more PixelFEDChannelCollections of modules+ROCs to mask on the fly for a given event");
548  desc.add<bool>("ignoreSingleFPixPanelModules", false);
549 
550  desc.addUntracked<bool>("debug", false);
551  desc.addUntracked<bool>("createPlottingFiles", false);
552 }
553 
555  const edm::EventSetup& iSetup) {
556  // Set data to handles
557  {
558  edm::ESHandle<TrackerGeometry> trackerGeometry;
559  iSetup.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
560  trackerGeometry_ = trackerGeometry.product();
561 
562  edm::ESHandle<TrackerTopology> trackerTopology;
563  iSetup.get<TrackerTopologyRcd>().get(trackerTopology);
564  trackerTopology_ = trackerTopology.product();
565  }
566 
567  // assign data to instance variables
568  updatePixelDets(iSetup);
569  getBadPixelDets(iEvent, iSetup);
570 
571  //write files for plotting
572  if (createPlottingFiles_) {
574  }
575 
576  // find detGroupSpans ie phi,r,z limits for detector detGroups that are not working
577  // returns pair where first is barrel spans and second endcap spans
579 
580  // map spans to a vector with consistent indexing with inactiveLayers_ and inactiveLayerSetIndices_
581  // TODO: try to move the inner logic towards this direction as well
582  std::vector<DetGroupSpanContainer> spans(inactiveLayers_.size());
583 
584  auto doWork = [&](const DetGroupSpanContainer& container) {
585  for (const auto& span : container) {
586  const auto subdet = span.subdetId == PixelSubdetector::PixelBarrel ? GeomDetEnumerators::PixelBarrel
588  const auto side = (subdet == GeomDetEnumerators::PixelBarrel
590  : (span.zSpan.first < 0 ? TrackerDetSide::NegEndcap : TrackerDetSide::PosEndcap));
591  const auto layer = subdet == GeomDetEnumerators::PixelBarrel ? span.layer : span.disk;
592  auto found = std::find(inactiveLayers_.begin(), inactiveLayers_.end(), SeedingLayerId(subdet, side, layer));
593  if (found != inactiveLayers_.end()) { // it is possible that this layer is ignored by the configuration
594  spans[std::distance(inactiveLayers_.begin(), found)].push_back(span);
595  }
596  }
597  };
598  doWork(cspans.first);
599  doWork(cspans.second);
600 
601  auto ret =
603 
604  if (debug_) {
605  printOverlapSpans(ret);
606  }
607 
608  return ret;
609 }
610 
611 // Functions for fetching date from handles
613  if (!geometryWatcher_.check(iSetup))
614  return;
615 
616  // deduce the number of ladders per layer and the number of modules per ladder
617  {
618  // sanity checks
620  throw cms::Exception("NotImplemented")
621  << "This module supports only a detector with 4 pixel barrel layers, the current geometry has "
623  }
625  throw cms::Exception("NotImplemented")
626  << "This module supports only a detector with 3 pixel forward disks, the current geometry has "
628  }
629 
630  std::array<std::array<unsigned short, 100>, 4> counts = {}; // assume at most 100 ladders per layer
631  for (const auto& det : trackerGeometry_->detsPXB()) {
632  const auto layer = trackerTopology_->layer(det->geographicalId());
633  const auto ladder = trackerTopology_->pxbLadder(det->geographicalId());
634  if (ladder >= 100) {
635  throw cms::Exception("LogicError")
636  << "Got a ladder with number " << ladder
637  << " while the expected maximum was 100; either something is wrong or the maximum has to be increased.";
638  }
639  counts[layer - 1][ladder - 1] += 1; // numbering of layer and ladder starts at 1
640  }
641 
642  // take number of modules per ladder from the first ladder of the first layer (such better exist)
643  // other ladders better have the same number
644  nModulesPerLadder = counts[0][0];
645  if (nModulesPerLadder == 0) {
646  throw cms::Exception("LogicError") << "Ladder 1 of layer 1 has 0 modules, something fishy is going on.";
647  }
648 
649  LogDebug("PixelInactiveAreaFinder") << "Number of modules per ladder " << nModulesPerLadder
650  << "; below are number of ladders per layer";
651 
652  // number of ladders
653  for (unsigned layer = 0; layer < 4; ++layer) {
655  std::count_if(counts[layer].begin(), counts[layer].end(), [](unsigned short val) { return val > 0; });
656  LogTrace("PixelInactiveAreaFinder")
657  << "BPix layer " << (layer + 1) << " has " << nBPixLadders[layer] << " ladders";
658 
659  auto fail = std::count_if(counts[layer].begin(), counts[layer].end(), [&](unsigned short val) {
660  return val != nModulesPerLadder && val > 0;
661  });
662  if (fail != 0) {
663  throw cms::Exception("LogicError")
664  << "Layer " << (layer + 1) << " had " << fail
665  << " ladders whose number of modules/ladder differed from the ladder 1 of layer 1 (" << nModulesPerLadder
666  << "). Something fishy is going on.";
667  }
668  }
669  }
670 
671  // don't bother with the rest if not needed
673  return;
674 
675  pixelDetsBarrel_.clear();
676  pixelDetsEndcap_.clear();
677 
678  for (auto const& geomDetPtr : trackerGeometry_->detsPXB()) {
679  if (geomDetPtr->geographicalId().subdetId() == PixelSubdetector::PixelBarrel) {
680  pixelDetsBarrel_.push_back(geomDetPtr->geographicalId().rawId());
681  }
682  }
683  for (auto const& geomDetPtr : trackerGeometry_->detsPXF()) {
684  if (geomDetPtr->geographicalId().subdetId() == PixelSubdetector::PixelEndcap) {
685  pixelDetsEndcap_.push_back(geomDetPtr->geographicalId().rawId());
686  }
687  }
690 }
692  auto addDetId = [&](const auto id) {
693  const auto detid = DetId(id);
694  const auto subdet = detid.subdetId();
695  if (subdet == PixelSubdetector::PixelBarrel) {
696  badPixelDetsBarrel_.push_back(detid.rawId());
697  } else if (subdet == PixelSubdetector::PixelEndcap) {
698  badPixelDetsEndcap_.push_back(detid.rawId());
699  }
700  };
701 
702  // SiPixelQuality
703  edm::ESHandle<SiPixelQuality> pixelQuality;
704  iSetup.get<SiPixelQualityRcd>().get(pixelQuality);
705 
706  for (auto const& disabledModule : pixelQuality->getBadComponentList()) {
707  addDetId(disabledModule.DetID);
708  }
709 
710  // dynamic bad modules
711  for (const auto& token : inactivePixelDetectorTokens_) {
713  iEvent.getByToken(token, detIds);
714  for (const auto& id : *detIds) {
715  addDetId(id);
716  }
717  }
718 
719  // dynamic bad ROCs ("Fed25")
720  // TODO: consider moving to finer-grained areas for inactive ROCs
721  for (const auto& token : badPixelFEDChannelsTokens_) {
722  edm::Handle<PixelFEDChannelCollection> pixelFEDChannelCollectionHandle;
723  iEvent.getByToken(token, pixelFEDChannelCollectionHandle);
724  for (const auto& disabledChannels : *pixelFEDChannelCollectionHandle) {
725  addDetId(disabledChannels.detId());
726  }
727  }
728 
729  // remove duplicates
733  badPixelDetsBarrel_.end());
735  badPixelDetsEndcap_.end());
736 }
737 // Printing functions
739  using std::fixed;
740  using std::left;
741  using std::noshowpos;
742  using std::right;
743  using std::setfill;
744  using std::setprecision;
745  using std::setw;
746  using std::showpos;
747  using std::tie;
748  std::string deli = "; ";
749  ss << "id:[" << det << "]" << deli;
750  ss << "subdetid:[" << DetId(det).subdetId() << "]" << deli;
751  if (DetId(det).subdetId() == PixelSubdetector::PixelBarrel) {
752  unsigned int layer = trackerTopology_->pxbLayer(DetId(det));
753  unsigned int ladder = trackerTopology_->pxbLadder(DetId(det));
754  unsigned int module = trackerTopology_->pxbModule(DetId(det));
755  ss << "layer:[" << layer << "]" << deli << "ladder:[" << right << setw(2) << ladder << "]" << deli << "module:["
756  << module << "]" << deli;
757  } else if (DetId(det).subdetId() == PixelSubdetector::PixelEndcap) {
758  unsigned int disk = trackerTopology_->pxfDisk(DetId(det));
759  unsigned int blade = trackerTopology_->pxfBlade(DetId(det));
760  unsigned int panel = trackerTopology_->pxfPanel(DetId(det));
761  ss << left << setw(6) << "disk:"
762  << "[" << right << disk << "]" << deli << left << setw(7) << "blade:"
763  << "[" << setw(2) << right << blade << "]" << deli << left << setw(7) << "panel:"
764  << "[" << right << panel << "]" << deli;
765  }
766  float phiA, phiB, zA, zB, rA, rB;
767  auto detSurface = trackerGeometry_->idToDet(DetId(det))->surface();
768  tie(phiA, phiB) = detSurface.phiSpan();
769  tie(zA, zB) = detSurface.zSpan();
770  tie(rA, rB) = detSurface.rSpan();
771  ss << setprecision(16) << fixed << showpos << setfill(' ') << "phi:[" << right << setw(12) << phiA << "," << left
772  << setw(12) << phiB << "]" << deli << "z:[" << right << setw(7) << zA << "," << left << setw(7) << zB << "]"
773  << deli << noshowpos << "r:[" << right << setw(10) << rA << "," << left << setw(10) << rB << "]" << deli;
774 }
776  edm::LogPrint("PixelInactiveAreaFinder") << "Barrel detectors:";
777  Stream ss;
778  for (auto const& det : pixelDetsBarrel_) {
779  detInfo(det, ss);
780  edm::LogPrint("PixelInactiveAreaFinder") << ss.str();
781  ss.str(std::string());
782  }
783  edm::LogPrint("PixelInactiveAreaFinder") << "Endcap detectors;";
784  for (auto const& det : pixelDetsEndcap_) {
785  detInfo(det, ss);
786  edm::LogPrint("PixelInactiveAreaFinder") << ss.str();
787  ss.str(std::string());
788  }
789 }
791  edm::LogPrint("PixelInactiveAreaFinder") << "Bad barrel detectors:";
792  Stream ss;
793  for (auto const& det : badPixelDetsBarrel_) {
794  detInfo(det, ss);
795  edm::LogPrint("PixelInactiveAreaFinder") << ss.str();
796  ss.str(std::string());
797  }
798  edm::LogPrint("PixelInactiveAreaFinder") << "Endcap detectors;";
799  for (auto const& det : badPixelDetsEndcap_) {
800  detInfo(det, ss);
801  edm::LogPrint("PixelInactiveAreaFinder") << ss.str();
802  ss.str(std::string());
803  }
804 }
806  DetGroupContainer badDetGroupsBar = badDetGroupsBarrel();
807  DetGroupContainer badDetGroupsEnd = badDetGroupsEndcap();
808  Stream ss;
809  for (auto const& detGroup : badDetGroupsBar) {
810  ss << std::setfill(' ') << std::left << std::setw(16) << "DetGroup:";
811  DetGroupSpan cspan;
812  getPhiSpanBarrel(detGroup, cspan);
813  getZSpan(detGroup, cspan);
814  getRSpan(detGroup, cspan);
815  detGroupSpanInfo(cspan, ss);
816  ss << std::endl;
817  for (auto const& det : detGroup) {
818  detInfo(det, ss);
819  ss << std::endl;
820  }
821  ss << std::endl;
822  }
823  for (auto const& detGroup : badDetGroupsEnd) {
824  ss << std::setfill(' ') << std::left << std::setw(16) << "DetGroup:";
825  DetGroupSpan cspan;
826  getPhiSpanEndcap(detGroup, cspan);
827  getZSpan(detGroup, cspan);
828  getRSpan(detGroup, cspan);
829  detGroupSpanInfo(cspan, ss);
830  ss << std::endl;
831  for (auto const& det : detGroup) {
832  detInfo(det, ss);
833  ss << std::endl;
834  }
835  ss << std::endl;
836  }
837  edm::LogPrint("PixelInactiveAreaFinder") << ss.str();
838 }
841  Stream ss;
842  for (auto const& cspan : cspans.first) {
843  detGroupSpanInfo(cspan, ss);
844  ss << std::endl;
845  }
846  for (auto const& cspan : cspans.second) {
847  detGroupSpanInfo(cspan, ss);
848  ss << std::endl;
849  }
850  edm::LogPrint("PixelInactiveAreaFinder") << ss.str();
851 }
853  // All detectors to file DETECTORS
854  Stream ss;
855  std::ofstream fsDet("DETECTORS.txt");
856  for (auto const& det : pixelDetsBarrel_) {
857  detInfo(det, ss);
858  ss << std::endl;
859  }
860  edm::LogPrint("PixelInactiveAreaFinder") << "Endcap detectors;";
861  for (auto const& det : pixelDetsEndcap_) {
862  detInfo(det, ss);
863  ss << std::endl;
864  }
865  fsDet << ss.rdbuf();
866  ss.str(std::string());
867  // Bad detectors
868  std::ofstream fsBadDet("BADDETECTORS.txt");
869  for (auto const& det : badPixelDetsBarrel_) {
870  detInfo(det, ss);
871  ss << std::endl;
872  }
873  for (auto const& det : badPixelDetsEndcap_) {
874  detInfo(det, ss);
875  ss << std::endl;
876  }
877  fsBadDet << ss.rdbuf();
878  ss.str(std::string());
879  // detgroupspans
880  std::ofstream fsSpans("DETGROUPSPANS.txt");
882  for (auto const& cspan : cspans.first) {
883  detGroupSpanInfo(cspan, ss);
884  ss << std::endl;
885  }
886  for (auto const& cspan : cspans.second) {
887  detGroupSpanInfo(cspan, ss);
888  ss << std::endl;
889  }
890  fsSpans << ss.rdbuf();
891  ss.str(std::string());
892 }
893 // Functions for finding bad detGroups
895  return std::find(badPixelDetsBarrel_.begin(), badPixelDetsBarrel_.end(), det) == badPixelDetsBarrel_.end() &&
897 }
899  using std::remove_if;
900 
901  DetGroup adj;
902  auto const tTopo = trackerTopology_;
903  auto const& detId = DetId(det);
904  unsigned int layer = tTopo->pxbLayer(detId);
905  unsigned int ladder = tTopo->pxbLadder(detId);
906  unsigned int module = tTopo->pxbModule(detId);
907  unsigned int nLads = nBPixLadders[layer];
908  //add detectors from next and previous ladder
909  adj.push_back(tTopo->pxbDetId(layer, ((ladder - 1) + 1) % nLads + 1, module)());
910  adj.push_back(tTopo->pxbDetId(layer, ((ladder - 1) - 1 + nLads) % nLads + 1, module)());
911  //add adjecent detectors from same ladder
912  if (module == 1) {
913  adj.push_back(tTopo->pxbDetId(layer, ladder, module + 1)());
914  } else if (module == nModulesPerLadder) {
915  adj.push_back(tTopo->pxbDetId(layer, ladder, module - 1)());
916  } else {
917  adj.push_back(tTopo->pxbDetId(layer, ladder, module + 1)());
918  adj.push_back(tTopo->pxbDetId(layer, ladder, module - 1)());
919  }
920  //remove working detectors from list
921  adj.erase(remove_if(adj.begin(), adj.end(), [&](auto c) { return this->detWorks(c); }), adj.end());
922  return adj;
923 }
925  // this might be faster if adjecent
926  using std::ignore;
927  using std::tie;
928  DetGroup adj;
929  Span_t phiSpan, phiSpanComp;
930  float z, zComp;
931  unsigned int disk, diskComp;
932  auto const& detSurf = trackerGeometry_->idToDet(DetId(det))->surface();
933  phiSpan = detSurf.phiSpan();
934  tie(z, ignore) = detSurf.zSpan();
935  disk = trackerTopology_->pxfDisk(DetId(det));
936  // add detectors from same disk whose phi ranges overlap to the adjecent list
937  for (auto const& detComp : badPixelDetsEndcap_) {
938  auto const& detIdComp = DetId(detComp);
939  auto const& detSurfComp = trackerGeometry_->idToDet(detIdComp)->surface();
940  diskComp = trackerTopology_->pxfDisk(detIdComp);
941  phiSpanComp = detSurfComp.phiSpan();
942  tie(zComp, ignore) = detSurfComp.zSpan();
943  if (det != detComp && disk == diskComp && z * zComp > 0 && phiRangesOverlap(phiSpan, phiSpanComp)) {
944  adj.push_back(detComp);
945  }
946  }
947  return adj;
948 }
950  DetectorSet& foundDets) {
952  std::queue<det_t> workQueue;
953  det_t workDet;
954  DetGroup badAdjDets;
955  foundDets.insert(initDet);
956  workQueue.push(initDet);
957  reachableDetGroup.push_back(initDet);
958  while (!workQueue.empty()) {
959  workDet = workQueue.front();
960  workQueue.pop();
961  if (DetId(workDet).subdetId() == PixelSubdetector::PixelBarrel) {
962  badAdjDets = this->badAdjecentDetsBarrel(workDet);
963  } else if (DetId(workDet).subdetId() == PixelSubdetector::PixelEndcap) {
964  badAdjDets = this->badAdjecentDetsEndcap(workDet);
965  } else {
966  badAdjDets = {};
967  }
968  for (auto const& badDet : badAdjDets) {
969  if (foundDets.find(badDet) == foundDets.end()) {
970  reachableDetGroup.push_back(badDet);
971  foundDets.insert(badDet);
972  workQueue.push(badDet);
973  }
974  }
975  }
976  return reachableDetGroup;
977 }
979  DetGroupContainer detGroups;
980  DetectorSet foundDets;
981  for (auto const& badDet : badPixelDetsBarrel_) {
982  if (foundDets.find(badDet) == foundDets.end()) {
983  detGroups.push_back(this->reachableDetGroup(badDet, foundDets));
984  }
985  }
986  return detGroups;
987 }
989  DetGroupContainer detGroups;
990  DetectorSet foundDets;
991  for (auto const& badDet : badPixelDetsEndcap_) {
992  if (foundDets.find(badDet) == foundDets.end()) {
993  auto adjacentDets = this->reachableDetGroup(badDet, foundDets);
994  if (ignoreSingleFPixPanelModules_ && adjacentDets.size() == 1) {
995  // size==1 means that only a single panel of a blade was inactive
996  // because of the large overlap with the other panel (i.e.
997  // redundancy in the detectory) ignoring these may help to decrease fakes
998  continue;
999  }
1000  detGroups.push_back(adjacentDets);
1001  }
1002  }
1003  return detGroups;
1004 }
1005 // Functions for finding DetGroupSpans
1007  // find phiSpan using ordered vector of unique ladders in detGroup
1008  if (detGroup.empty()) {
1009  cspan = DetGroupSpan();
1010  return;
1011  } else {
1012  cspan.layer = trackerTopology_->pxbLayer(DetId(detGroup[0]));
1013  cspan.disk = 0;
1014  }
1015  using uint = unsigned int;
1016  using LadderSet = std::set<uint>;
1017  using LadVec = std::vector<uint>;
1018  LadderSet lads;
1019  for (auto const& det : detGroup) {
1020  lads.insert(trackerTopology_->pxbLadder(DetId(det)));
1021  }
1022  LadVec ladv(lads.begin(), lads.end());
1023  uint nLadders = nBPixLadders[cspan.layer];
1024  // find start ladder of detGroup
1025  uint i = 0;
1026  uint currentLadder = ladv[0];
1027  uint previousLadder = ladv[(ladv.size() + i - 1) % ladv.size()];
1028  // loop until discontinuity is found from vector
1029  while ((nLadders + currentLadder - 1) % nLadders == previousLadder) {
1030  ++i;
1031  currentLadder = ladv[i % ladv.size()];
1032  previousLadder = ladv[(ladv.size() + i - 1) % ladv.size()];
1033  if (i == ladv.size()) {
1035  cspan.phiSpan.second = -std::numeric_limits<float>::epsilon();
1036  return;
1037  }
1038  }
1039  uint startLadder = currentLadder;
1040  uint endLadder = previousLadder;
1041  auto detStart = trackerTopology_->pxbDetId(cspan.layer, startLadder, 1);
1042  auto detEnd = trackerTopology_->pxbDetId(cspan.layer, endLadder, 1);
1043  cspan.phiSpan.first = trackerGeometry_->idToDet(detStart)->surface().phiSpan().first;
1044  cspan.phiSpan.second = trackerGeometry_->idToDet(detEnd)->surface().phiSpan().second;
1045 }
1047  // this is quite naive/bruteforce method
1048  // 1) it starts by taking one detector from detGroup and starts to compare it to others
1049  // 2) when it finds overlapping detector in clockwise direction it starts comparing
1050  // found detector to others
1051  // 3) search stops until no overlapping detectors in clockwise detector or all detectors
1052  // have been work detector
1053  Stream ss;
1054  bool found = false;
1055  auto const tGeom = trackerGeometry_;
1056  DetGroup::const_iterator startDetIter = detGroup.begin();
1057  Span_t phiSpan, phiSpanComp;
1058  unsigned int counter = 0;
1059  while (!found) {
1060  phiSpan = tGeom->idToDet(DetId(*startDetIter))->surface().phiSpan();
1061  for (DetGroup::const_iterator compDetIter = detGroup.begin(); compDetIter != detGroup.end(); ++compDetIter) {
1062  phiSpanComp = tGeom->idToDet(DetId(*compDetIter))->surface().phiSpan();
1063  if (phiRangesOverlap(phiSpan, phiSpanComp) && phiMoreClockwise(phiSpanComp.first, phiSpan.first) &&
1064  startDetIter != compDetIter) {
1065  ++counter;
1066  if (counter > detGroup.size()) {
1068  cspan.phiSpan.second = -std::numeric_limits<float>::epsilon();
1069  return;
1070  }
1071  startDetIter = compDetIter;
1072  break;
1073  } else if (compDetIter == detGroup.end() - 1) {
1074  found = true;
1075  }
1076  }
1077  }
1078  cspan.phiSpan.first = phiSpan.first;
1079  // second with same method}
1080  found = false;
1081  DetGroup::const_iterator endDetIter = detGroup.begin();
1082  counter = 0;
1083  while (!found) {
1084  phiSpan = tGeom->idToDet(DetId(*endDetIter))->surface().phiSpan();
1085  for (DetGroup::const_iterator compDetIter = detGroup.begin(); compDetIter != detGroup.end(); ++compDetIter) {
1086  phiSpanComp = tGeom->idToDet(DetId(*compDetIter))->surface().phiSpan();
1087  if (phiRangesOverlap(phiSpan, phiSpanComp) && phiMoreCounterclockwise(phiSpanComp.second, phiSpan.second) &&
1088  endDetIter != compDetIter) {
1089  ++counter;
1090  if (counter > detGroup.size()) {
1092  cspan.phiSpan.second = -std::numeric_limits<float>::epsilon();
1093  return;
1094  }
1095  endDetIter = compDetIter;
1096  break;
1097  } else if (compDetIter == detGroup.end() - 1) {
1098  found = true;
1099  }
1100  }
1101  }
1102  cspan.phiSpan.second = phiSpan.second;
1103 }
1105  auto cmpFun = [this](det_t detA, det_t detB) {
1106  return trackerGeometry_->idToDet(DetId(detA))->surface().zSpan().first <
1107  trackerGeometry_->idToDet(DetId(detB))->surface().zSpan().first;
1108  };
1109 
1110  auto minmaxIters = std::minmax_element(detGroup.begin(), detGroup.end(), cmpFun);
1111  cspan.zSpan.first = trackerGeometry_->idToDet(DetId(*(minmaxIters.first)))->surface().zSpan().first;
1112  cspan.zSpan.second = trackerGeometry_->idToDet(DetId(*(minmaxIters.second)))->surface().zSpan().second;
1113 }
1115  auto cmpFun = [this](det_t detA, det_t detB) {
1116  return trackerGeometry_->idToDet(DetId(detA))->surface().rSpan().first <
1117  trackerGeometry_->idToDet(DetId(detB))->surface().rSpan().first;
1118  };
1119 
1120  auto minmaxIters = std::minmax_element(detGroup.begin(), detGroup.end(), cmpFun);
1121  cspan.rSpan.first = trackerGeometry_->idToDet(DetId(*(minmaxIters.first)))->surface().rSpan().first;
1122  cspan.rSpan.second = trackerGeometry_->idToDet(DetId(*(minmaxIters.second)))->surface().rSpan().second;
1123 }
1125  auto firstDetIt = detGroup.begin();
1126  if (firstDetIt != detGroup.end()) {
1127  cspan.subdetId = DetId(*firstDetIt).subdetId();
1128  if (cspan.subdetId == 1) {
1129  cspan.layer = trackerTopology_->pxbLayer(DetId(*firstDetIt));
1130  cspan.disk = 0;
1131  getPhiSpanBarrel(detGroup, cspan);
1132  } else if (cspan.subdetId == 2) {
1133  cspan.disk = trackerTopology_->pxfDisk(DetId(*firstDetIt));
1134  cspan.layer = 0;
1135  getPhiSpanEndcap(detGroup, cspan);
1136  }
1137  getZSpan(detGroup, cspan);
1138  getRSpan(detGroup, cspan);
1139  }
1140 }
1142  DetGroupSpanContainer cspansBarrel;
1143  DetGroupSpanContainer cspansEndcap;
1144  DetGroupContainer badDetGroupsBar = badDetGroupsBarrel();
1145  DetGroupContainer badDetGroupsEnd = badDetGroupsEndcap();
1146  for (auto const& detGroup : badDetGroupsBar) {
1147  DetGroupSpan cspan;
1148  getSpan(detGroup, cspan);
1149  cspansBarrel.push_back(cspan);
1150  }
1151  for (auto const& detGroup : badDetGroupsEnd) {
1152  DetGroupSpan cspan;
1153  getSpan(detGroup, cspan);
1154  cspansEndcap.push_back(cspan);
1155  }
1156  return DetGroupSpanContainerPair(cspansBarrel, cspansEndcap);
1157 }
SeedingLayerSetsLooper.h
runTheMatrix.ret
ret
prodAgent to be discontinued
Definition: runTheMatrix.py:542
TrackerGeometry::idToDet
const TrackerGeomDet * idToDet(DetId) const override
Definition: TrackerGeometry.cc:193
edm::ESWatcher::check
bool check(const edm::EventSetup &iSetup)
Definition: ESWatcher.h:52
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
PixelInactiveAreaFinder::detGroupSpans
DetGroupSpanContainerPair detGroupSpans()
Definition: PixelInactiveAreaFinder.cc:1141
PixelInactiveAreaFinder::badAdjecentDetsEndcap
DetGroup badAdjecentDetsEndcap(const det_t &det)
Definition: PixelInactiveAreaFinder.cc:924
counter
Definition: counter.py:1
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
alignBH_cfg.fixed
fixed
Definition: alignBH_cfg.py:54
electrons_cff.bool
bool
Definition: electrons_cff.py:366
mps_fire.i
i
Definition: mps_fire.py:428
HLT_FULL_cff.seedingLayers
seedingLayers
Definition: HLT_FULL_cff.py:9855
PixelSubdetector::PixelEndcap
Definition: PixelSubdetector.h:11
TrackerGeometry.h
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
SiPixelQualityRcd
Definition: SiPixelQualityRcd.h:13
PixelInactiveAreaFinder.h
ESHandle.h
PixelInactiveAreaFinder::badDetGroupsEndcap
DetGroupContainer badDetGroupsEndcap()
Definition: PixelInactiveAreaFinder.cc:988
reco::deltaPhi
constexpr double deltaPhi(double phi1, double phi2)
Definition: deltaPhi.h:26
deltaPhi.h
FrontierCondition_GT_autoExpress_cfi.auto
auto
Definition: FrontierCondition_GT_autoExpress_cfi.py:16
PixelInactiveAreaFinder::detWorks
bool detWorks(det_t det)
Definition: PixelInactiveAreaFinder.cc:894
edm
HLT enums.
Definition: AlignableModifier.h:19
testProducerWithPsetDescEmpty_cfi.x2
x2
Definition: testProducerWithPsetDescEmpty_cfi.py:28
TrackerTopology::pxbLadder
unsigned int pxbLadder(const DetId &id) const
Definition: TrackerTopology.h:155
edm::LogPrint
Log< level::Warning, true > LogPrint
Definition: MessageLogger.h:130
HLT_FULL_cff.InputTag
InputTag
Definition: HLT_FULL_cff.py:89281
edm::ParameterSetDescription
Definition: ParameterSetDescription.h:52
PixelInactiveAreaFinder::DetGroupSpan::phiSpan
std::pair< float, float > phiSpan
Definition: PixelInactiveAreaFinder.h:29
cms::cuda::assert
assert(be >=bs)
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
infinity
const double infinity
Definition: CSCChamberFitter.cc:10
spr::find
void find(edm::Handle< EcalRecHitCollection > &hits, DetId thisDet, std::vector< EcalRecHitCollection::const_iterator > &hit, bool debug=false)
Definition: FindCaloHit.cc:19
watchdog.const
const
Definition: watchdog.py:83
PixelInactiveAreaFinder::DetectorSet
std::set< uint32_t > DetectorSet
Definition: PixelInactiveAreaFinder.h:103
newFWLiteAna.found
found
Definition: newFWLiteAna.py:118
edm::Handle
Definition: AssociativeIterator.h:50
parallelization.uint
uint
Definition: parallelization.py:124
SiStripMonitorCluster_cfi.zmin
zmin
Definition: SiStripMonitorCluster_cfi.py:200
PixelInactiveAreaFinder::DetGroupSpan::layer
unsigned int layer
Definition: PixelInactiveAreaFinder.h:32
PixelInactiveAreaFinder::createPlottingFiles
void createPlottingFiles()
Definition: PixelInactiveAreaFinder.cc:852
geometryDiff.epsilon
int epsilon
Definition: geometryDiff.py:26
Surface::phiSpan
std::pair< float, float > const & phiSpan() const
Definition: Surface.h:90
PixelInactiveAreaFinder::trackerGeometry_
const TrackerGeometry * trackerGeometry_
Definition: PixelInactiveAreaFinder.h:109
TrackerGeometry::numberOfLayers
unsigned int numberOfLayers(int subdet) const
Definition: TrackerGeometry.cc:211
TrackerTopology::pxbLayer
unsigned int pxbLayer(const DetId &id) const
Definition: TrackerTopology.h:144
TrackerTopology::pxfPanel
unsigned int pxfPanel(const DetId &id) const
Definition: TrackerTopology.h:450
PixelInactiveAreaFinder::DetGroupSpan::rSpan
std::pair< float, float > rSpan
Definition: PixelInactiveAreaFinder.h:31
TrackerGeometry::detsPXB
const DetContainer & detsPXB() const
Definition: TrackerGeometry.cc:171
contentValuesCheck.ss
ss
Definition: contentValuesCheck.py:33
DetId
Definition: DetId.h:17
GeomDetEnumerators::PixelBarrel
Definition: GeomDetEnumerators.h:11
GeomDet::surface
const Plane & surface() const
The nominal surface of the GeomDet.
Definition: GeomDet.h:37
PixelInactiveAreaFinder::badPixelDetsEndcap_
DetContainer badPixelDetsEndcap_
Definition: PixelInactiveAreaFinder.h:115
TrackerTopology.h
testProducerWithPsetDescEmpty_cfi.x1
x1
Definition: testProducerWithPsetDescEmpty_cfi.py:33
PixelInactiveAreaFinder::badPixelFEDChannelsTokens_
std::vector< edm::EDGetTokenT< PixelFEDChannelCollection > > badPixelFEDChannelsTokens_
Definition: PixelInactiveAreaFinder.h:89
testProducerWithPsetDescEmpty_cfi.y1
y1
Definition: testProducerWithPsetDescEmpty_cfi.py:29
TrackerDetSide::Barrel
TrackerTopologyRcd.h
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
PixelInactiveAreaFinder::det_t
uint32_t det_t
Definition: PixelInactiveAreaFinder.h:99
PixelInactiveAreaFinder::Stream
std::stringstream Stream
Definition: PixelInactiveAreaFinder.h:104
SiStripMonitorCluster_cfi.zmax
zmax
Definition: SiStripMonitorCluster_cfi.py:201
PixelInactiveAreaFinder::badDetGroupsBarrel
DetGroupContainer badDetGroupsBarrel()
Definition: PixelInactiveAreaFinder.cc:978
PixelInactiveAreaFinder::inactiveAreas
InactiveAreas inactiveAreas(const edm::Event &iEvent, const edm::EventSetup &iSetup)
Definition: PixelInactiveAreaFinder.cc:554
PixelInactiveAreaFinder::ignoreSingleFPixPanelModules_
const bool ignoreSingleFPixPanelModules_
Definition: PixelInactiveAreaFinder.h:81
GlobalPosition_Frontier_DevDB_cff.tag
tag
Definition: GlobalPosition_Frontier_DevDB_cff.py:11
SiPixelQualityRcd.h
Surface::zSpan
std::pair< float, float > const & zSpan() const
Definition: Surface.h:91
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:15
PixelInactiveAreaFinder::trackerTopology_
const TrackerTopology * trackerTopology_
Definition: PixelInactiveAreaFinder.h:110
mps_fire.end
end
Definition: mps_fire.py:242
DDAxes::z
edm::ESHandle< TrackerGeometry >
TrackerGeometry::detsPXF
const DetContainer & detsPXF() const
Definition: TrackerGeometry.cc:173
TrackerDetSide::NegEndcap
PixelInactiveAreaFinder::updatePixelDets
void updatePixelDets(const edm::EventSetup &iSetup)
Definition: PixelInactiveAreaFinder.cc:612
PixelInactiveAreaFinder::printPixelDets
void printPixelDets()
Definition: PixelInactiveAreaFinder.cc:775
SeedingLayerSetsBuilder::SeedingLayerId
std::tuple< GeomDetEnumerators::SubDetector, TrackerDetSide, int > SeedingLayerId
Definition: SeedingLayerSetsBuilder.h:33
PixelInactiveAreaFinder::InactiveAreas::areasAndLayerSets
std::vector< std::pair< VecArray2< Area >, std::vector< LayerSetIndex > > > areasAndLayerSets(const GlobalPoint &point, float zwidth) const
Definition: PixelInactiveAreaFinder.cc:373
PixelInactiveAreaFinder::fillDescriptions
static void fillDescriptions(edm::ParameterSetDescription &desc)
Definition: PixelInactiveAreaFinder.cc:541
GlobalPoint
Global3DPoint GlobalPoint
Definition: GlobalPoint.h:10
Point3DBase< float, GlobalTag >
PixelInactiveAreaFinder::debug_
const bool debug_
Definition: PixelInactiveAreaFinder.h:79
PixelInactiveAreaFinder::DetGroupSpan::subdetId
int subdetId
Definition: PixelInactiveAreaFinder.h:28
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
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
AlCaHLTBitMon_QueryRunRegistry.string
string
Definition: AlCaHLTBitMon_QueryRunRegistry.py:256
edm::vector_transform
auto vector_transform(std::vector< InputType > const &input, Function predicate) -> std::vector< typename std::remove_cv< typename std::remove_reference< decltype(predicate(input.front()))>::type >::type >
Definition: transform.h:11
PixelInactiveAreaFinder::nModulesPerLadder
unsigned short nModulesPerLadder
Definition: PixelInactiveAreaFinder.h:97
testProducerWithPsetDescEmpty_cfi.y2
y2
Definition: testProducerWithPsetDescEmpty_cfi.py:30
PixelInactiveAreaFinder::printBadDetGroupSpans
void printBadDetGroupSpans()
Definition: PixelInactiveAreaFinder.cc:839
edm::VecArray
Definition: VecArray.h:28
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
edm::ParameterSet
Definition: ParameterSet.h:47
jetUpdater_cfi.sort
sort
Definition: jetUpdater_cfi.py:29
PixelInactiveAreaFinder::getSpan
void getSpan(const DetGroup &detGroup, DetGroupSpan &cspan)
Definition: PixelInactiveAreaFinder.cc:1124
PixelInactiveAreaFinder::getPhiSpanBarrel
void getPhiSpanBarrel(const DetGroup &detGroup, DetGroupSpan &cspan)
Definition: PixelInactiveAreaFinder.cc:1006
PixelInactiveAreaFinder::getRSpan
void getRSpan(const DetGroup &detGroup, DetGroupSpan &cspan)
Definition: PixelInactiveAreaFinder.cc:1114
PixelInactiveAreaFinder::pixelDetsBarrel_
DetContainer pixelDetsBarrel_
Definition: PixelInactiveAreaFinder.h:112
PixelInactiveAreaFinder::reachableDetGroup
DetGroup reachableDetGroup(const det_t &initDet, DetectorSet &foundDets)
Definition: PixelInactiveAreaFinder.cc:949
PixelInactiveAreaFinder::inactiveLayerSetIndices_
std::vector< std::pair< unsigned short, unsigned short > > inactiveLayerSetIndices_
Definition: PixelInactiveAreaFinder.h:84
createfilelist.int
int
Definition: createfilelist.py:10
iEvent
int iEvent
Definition: GenABIO.cc:224
TrackerTopology::pxfDisk
unsigned int pxfDisk(const DetId &id) const
Definition: TrackerTopology.h:446
trackerHitRTTI::vector
Definition: trackerHitRTTI.h:21
PixelInactiveAreaFinder::DetGroupSpan
Definition: PixelInactiveAreaFinder.h:27
SeedingLayerSetsLooper
Definition: SeedingLayerSetsLooper.h:10
counter
static std::atomic< unsigned int > counter
Definition: SharedResourceNames.cc:18
B2GTnPMonitor_cfi.item
item
Definition: B2GTnPMonitor_cfi.py:147
edm::EventSetup
Definition: EventSetup.h:58
edm::VecArray::emplace_back
void emplace_back(Args &&... args)
Definition: VecArray.h:90
PixelInactiveAreaFinder::DetGroupSpanContainerPair
std::pair< DetGroupSpanContainer, DetGroupSpanContainer > DetGroupSpanContainerPair
Definition: PixelInactiveAreaFinder.h:92
SequenceTypes.ignore
def ignore(seq)
Definition: SequenceTypes.py:630
get
#define get
edm::EDCollection< DetId >
PixelInactiveAreaFinder::InactiveAreas::spansAndLayerSets
std::vector< std::pair< VecArray2< DetGroupSpan >, std::vector< LayerSetIndex > > > spansAndLayerSets(const GlobalPoint &point, float zwidth) const
Definition: PixelInactiveAreaFinder.cc:402
PixelInactiveAreaFinder::getPhiSpanEndcap
void getPhiSpanEndcap(const DetGroup &detGroup, DetGroupSpan &cspan)
Definition: PixelInactiveAreaFinder.cc:1046
PixelInactiveAreaFinder::layerSetIndexInactiveToActive_
std::vector< std::vector< LayerSetIndex > > layerSetIndexInactiveToActive_
Definition: PixelInactiveAreaFinder.h:86
PixelInactiveAreaFinder::createPlottingFiles_
const bool createPlottingFiles_
Definition: PixelInactiveAreaFinder.h:80
PixelInactiveAreaFinder::InactiveAreas
Definition: PixelInactiveAreaFinder.h:38
TrackerDetSide::PosEndcap
SiPixelQuality::getBadComponentList
const std::vector< disabledModuleType > getBadComponentList() const
Definition: SiPixelQuality.h:100
PixelInactiveAreaFinder::LayerSetIndex
SeedingLayerSetsHits::LayerSetIndex LayerSetIndex
Definition: PixelInactiveAreaFinder.h:25
submitPVResolutionJobs.desc
string desc
Definition: submitPVResolutionJobs.py:251
heppy_batch.val
val
Definition: heppy_batch.py:351
eostools.move
def move(src, dest)
Definition: eostools.py:511
std
Definition: JetResolutionObject.h:76
PixelInactiveAreaFinder::detInfo
void detInfo(const det_t &det, Stream &ss)
Definition: PixelInactiveAreaFinder.cc:738
PixelInactiveAreaFinder::printBadDetGroups
void printBadDetGroups()
Definition: PixelInactiveAreaFinder.cc:805
tier0.unique
def unique(seq, keepstr=True)
Definition: tier0.py:24
PixelInactiveAreaFinder::DetGroupContainer
std::vector< DetGroup > DetGroupContainer
Definition: PixelInactiveAreaFinder.h:102
TrackerTopology::pxbModule
unsigned int pxbModule(const DetId &id) const
Definition: TrackerTopology.h:160
operator<<
std::ostream & operator<<(std::ostream &os, SeedingLayerSetsBuilder::SeedingLayerId layer)
Definition: PixelInactiveAreaFinder.cc:19
triggerObjects_cff.id
id
Definition: triggerObjects_cff.py:29
transform.h
Exception
Definition: hltDiff.cc:245
PixelInactiveAreaFinder::badAdjecentDetsBarrel
DetGroup badAdjecentDetsBarrel(const det_t &det)
Definition: PixelInactiveAreaFinder.cc:898
PixelInactiveAreaFinder::PixelInactiveAreaFinder
PixelInactiveAreaFinder(const edm::ParameterSet &iConfig, const std::vector< SeedingLayerId > &seedingLayers, const SeedingLayerSetsLooper &seedingLayerSetsLooper, edm::ConsumesCollector &&iC)
Definition: PixelInactiveAreaFinder.cc:462
PixelInactiveAreaFinder::badPixelDetsBarrel_
DetContainer badPixelDetsBarrel_
Definition: PixelInactiveAreaFinder.h:114
dqmiodumpmetadata.counts
counts
Definition: dqmiodumpmetadata.py:25
PVValHelper::ladder
Definition: PVValidationHelpers.h:73
PixelInactiveAreaFinder::inactiveLayers_
std::vector< SeedingLayerId > inactiveLayers_
Definition: PixelInactiveAreaFinder.h:83
pileupCalc.upper
upper
Definition: pileupCalc.py:214
PixelInactiveAreaFinder::getZSpan
void getZSpan(const DetGroup &detGroup, DetGroupSpan &cspan)
Definition: PixelInactiveAreaFinder.cc:1104
VecArray.h
PixelInactiveAreaFinder::geometryWatcher_
edm::ESWatcher< TrackerDigiGeometryRecord > geometryWatcher_
Definition: PixelInactiveAreaFinder.h:106
PixelInactiveAreaFinder::DetGroupSpan::zSpan
std::pair< float, float > zSpan
Definition: PixelInactiveAreaFinder.h:30
GeomDetEnumerators::PixelEndcap
Definition: GeomDetEnumerators.h:12
PixelInactiveAreaFinder::getBadPixelDets
void getBadPixelDets(const edm::Event &iEvent, const edm::EventSetup &iSetup)
Definition: PixelInactiveAreaFinder.cc:691
SiPixelQuality.h
DetGroup
Definition: DetGroup.h:41
TrackerTopology::pxfBlade
unsigned int pxfBlade(const DetId &id) const
Definition: TrackerTopology.h:447
PixelInactiveAreaFinder::DetGroup
std::vector< uint32_t > DetGroup
Definition: PixelInactiveAreaFinder.h:101
Surface::rSpan
std::pair< float, float > const & rSpan() const
Definition: Surface.h:92
genParticles_cff.map
map
Definition: genParticles_cff.py:11
LogTrace
#define LogTrace(id)
Definition: MessageLogger.h:234
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
TrackerTopology::pxbDetId
DetId pxbDetId(uint32_t layer, uint32_t ladder, uint32_t module) const
Definition: TrackerTopology.h:455
c
auto & c
Definition: CAHitNtupletGeneratorKernelsImpl.h:46
PixelInactiveAreaFinder::printBadPixelDets
void printBadPixelDets()
Definition: PixelInactiveAreaFinder.cc:790
point
*vegas h *****************************************************used in the default bin number in original ***version of VEGAS is ***a higher bin number might help to derive a more precise ***grade subtle point
Definition: invegas.h:5
edm::Event
Definition: Event.h:73
HLT_FULL_cff.distance
distance
Definition: HLT_FULL_cff.py:7733
PixelInactiveAreaFinder::SeedingLayerId
SeedingLayerSetsBuilder::SeedingLayerId SeedingLayerId
Definition: PixelInactiveAreaFinder.h:24
PixelInactiveAreaFinder::DetGroupSpanContainer
std::vector< DetGroupSpan > DetGroupSpanContainer
Definition: PixelInactiveAreaFinder.h:36
edm::ConsumesCollector
Definition: ConsumesCollector.h:45
PixelInactiveAreaFinder::pixelDetsEndcap_
DetContainer pixelDetsEndcap_
Definition: PixelInactiveAreaFinder.h:113
PixelInactiveAreaFinder::DetGroupSpan::disk
unsigned int disk
Definition: PixelInactiveAreaFinder.h:33
PixelInactiveAreaFinder::inactivePixelDetectorTokens_
std::vector< edm::EDGetTokenT< DetIdCollection > > inactivePixelDetectorTokens_
Definition: PixelInactiveAreaFinder.h:88
unpackBuffers-CaloStage2.token
token
Definition: unpackBuffers-CaloStage2.py:316
PixelInactiveAreaFinder::nBPixLadders
std::array< unsigned short, 4 > nBPixLadders
Definition: PixelInactiveAreaFinder.h:96