CMS 3D CMS Logo

GeometryInterface.cc
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // Package: SiPixelPhase1Common
4 // Class: GeometryInterface
5 //
6 // Geometry depedence goes here.
7 //
8 // Original Author: Marcel Schneider
9 
11 
12 // general plotting helpers
14 
15 // Tracker Geometry/Topology stuff
20 
21 // Pixel names
24 
25 // C++ stuff
26 #include <cassert>
27 #include <cstdint>
28 #include <iostream>
29 #include <iomanip>
30 #include <memory>
31 
33 
36  edm::Transition transition)
37  : iConfig(conf), cablingMapLabel_{conf.getParameter<std::string>("CablingMapLabel")} {
38  if (transition == edm::Transition::BeginRun) {
39  trackerGeometryToken_ = iC.esConsumes<TrackerGeometry, TrackerDigiGeometryRecord, edm::Transition::BeginRun>();
40  trackerTopologyToken_ = iC.esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::BeginRun>();
41  siPixelFedCablingMapToken_ =
43  if (!cablingMapLabel_.empty()) {
44  labeledSiPixelFedCablingMapToken_ =
46  edm::ESInputTag("", cablingMapLabel_));
47  }
48  } else {
49  trackerGeometryToken_ =
51  trackerTopologyToken_ = iC.esConsumes<TrackerTopology, TrackerTopologyRcd, edm::Transition::EndLuminosityBlock>();
52  siPixelFedCablingMapToken_ =
54  if (!cablingMapLabel_.empty()) {
55  labeledSiPixelFedCablingMapToken_ =
57  edm::ESInputTag("", cablingMapLabel_));
58  }
59  }
60 }
61 
63  const TrackerGeometry& trackerGeometry = iSetup.getData(trackerGeometryToken_);
64  const TrackerTopology& trackerTopology = iSetup.getData(trackerTopologyToken_);
65  const SiPixelFedCablingMap& siPixelFedCablingMap = iSetup.getData(siPixelFedCablingMapToken_);
66 
67  const SiPixelFedCablingMap* labeledSiPixelFedCablingMap = &siPixelFedCablingMap;
68  if (!cablingMapLabel_.empty()) {
69  labeledSiPixelFedCablingMap = &iSetup.getData(labeledSiPixelFedCablingMapToken_);
70  }
71 
72  //loadFromAlignment(iSetup, iConfig);
73  loadFromTopology(trackerGeometry, trackerTopology, iConfig);
76  loadFEDCabling(labeledSiPixelFedCablingMap);
77  loadFromSiPixelCoordinates(trackerGeometry, trackerTopology, siPixelFedCablingMap, iConfig);
78  edm::LogInfo log("GeometryInterface");
79  log << "Known colum names:\n";
80  for (const auto& e : ids)
81  log << "+++ column: " << e.first << " ok " << bool(extractors[e.second]) << " min " << min_value[e.second]
82  << " max " << max_value[e.second] << "\n";
83  is_loaded = true;
84 }
85 
87  const TrackerTopology& trackerTopology,
88  const edm::ParameterSet& iConfig) {
89  std::vector<ID> geomquantities;
90 
91  struct TTField {
92  const TrackerTopology* tt;
94  Value operator()(InterestingQuantities const& iq) {
95  if (tt->hasField(iq.sourceModule, field))
96  return tt->getField(iq.sourceModule, field);
97  else
98  return UNDEFINED;
99  };
100  };
101 
102  const TrackerTopology* tt = &trackerTopology;
103 
104  std::vector<std::pair<std::string, TTField>> namedPartitions{
105  {"PXEndcap", {tt, TrackerTopology::PFSide}},
106 
107  {"PXLayer", {tt, TrackerTopology::PBLayer}},
108  {"PXLadder", {tt, TrackerTopology::PBLadder}},
109  {"PXBModule", {tt, TrackerTopology::PBModule}},
110 
111  {"PXBlade", {tt, TrackerTopology::PFBlade}},
112  {"PXDisk", {tt, TrackerTopology::PFDisk}},
113  {"PXPanel", {tt, TrackerTopology::PFPanel}},
114  {"PXFModule", {tt, TrackerTopology::PFModule}},
115  };
116 
117  for (auto& e : namedPartitions) {
118  geomquantities.push_back(intern(e.first));
119  addExtractor(intern(e.first), e.second, UNDEFINED, UNDEFINED);
120  }
121 
122  auto pxbarrel = [](InterestingQuantities const& iq) {
123  return iq.sourceModule.subdetId() == PixelSubdetector::PixelBarrel ? 0 : UNDEFINED;
124  };
125  auto pxforward = [](InterestingQuantities const& iq) {
126  return iq.sourceModule.subdetId() == PixelSubdetector::PixelEndcap ? 0 : UNDEFINED;
127  };
128  auto pxall = [](InterestingQuantities const& iq) { return 0; };
129  addExtractor(intern("PXBarrel"), pxbarrel, 0, 0);
130  addExtractor(intern("PXForward"), pxforward, 0, 0);
131  addExtractor(intern("PXAll"), pxall, 0, 0);
132 
133  // Redefine the disk numbering to use the sign
134  auto pxendcap = extractors[intern("PXEndcap")];
135  auto diskid = intern("PXDisk");
136  auto pxdisk = extractors[diskid];
137  extractors[diskid] = [pxdisk, pxendcap](InterestingQuantities const& iq) {
138  auto disk = pxdisk(iq);
139  if (disk == UNDEFINED)
140  return UNDEFINED;
141  auto endcap = pxendcap(iq);
142  return endcap == 1 ? -disk : disk;
143  };
144 
145  // DetId and module names
146  auto detid = [](InterestingQuantities const& iq) {
147  uint32_t id = iq.sourceModule.rawId();
148  return Value(id);
149  };
150  addExtractor(intern("DetId"), detid, 0, 0 // No sane value possible here.
151  );
152  // these are just aliases with special handling in formatting
153  // the names are created with PixelBarrelName et. al. later
154  addExtractor(intern("PXModuleName"), detid, 0, 0);
155 
156  int phase = iConfig.getParameter<int>("upgradePhase");
157  bool isUpgrade = phase == 1;
158 
159  // Now traverse the detector and collect whatever we need.
160  auto detids = trackerGeometry.detIds();
161  for (DetId id : detids) {
162  if (id.subdetId() != PixelSubdetector::PixelBarrel && id.subdetId() != PixelSubdetector::PixelEndcap)
163  continue;
164  auto iq = InterestingQuantities{nullptr, id, 0, 0};
165 
166  // prepare pretty names
167  std::string name = "";
168  if (id.subdetId() == PixelSubdetector::PixelBarrel) { // Barrel
170  name = mod.name();
171  } else { // assume Endcap
173  name = mod.name();
174  }
175  format_value[std::make_pair(intern("PXModuleName"), Value(id.rawId()))] = name;
176 
177  // we record each module 4 times, one for each corner, so we also get ROCs
178  // in booking (at least for the ranges)
179  const PixelGeomDetUnit* detUnit = dynamic_cast<const PixelGeomDetUnit*>(trackerGeometry.idToDetUnit(id));
180  assert(detUnit);
181  const PixelTopology* topo = &detUnit->specificTopology();
182  iq.row = 0;
183  iq.col = 0;
184  all_modules.push_back(iq);
185  iq.row = topo->nrows() - 1;
186  iq.col = 0;
187  all_modules.push_back(iq);
188  iq.row = 0;
189  iq.col = topo->ncolumns() - 1;
190  all_modules.push_back(iq);
191  iq.row = topo->nrows() - 1;
192  iq.col = topo->ncolumns() - 1;
193  all_modules.push_back(iq);
194  }
195 }
196 
198  const TrackerTopology& trackerTopology,
199  const SiPixelFedCablingMap& siPixelFedCablingMap,
200  const edm::ParameterSet& iConfig) {
201  // TODO: SiPixelCoordinates has a large overlap with theis GeometryInterface
202  // in general.
203  // Rough convention is to use own code for things that are easy and fast to
204  // determine, and use SiPixelCoordinates for complicated things.
205  // SiPixelCoordinates uses lookup maps for everything, so it is faster than
206  // most other code, but still slow on DQM scales.
207  int phase = iConfig.getParameter<int>("upgradePhase");
208 
209  // this shared pointer is kept alive by the references in the lambdas that follow.
210  // That is a bit less obvious than keeping it as a member but more correct.
211  auto coord = std::make_shared<SiPixelCoordinates>(phase);
212 
213  // note that we should reeinit for each event. But this probably won't explode
214  // thanks to the massive memoization in SiPixelCoordinates which is completely
215  // initialized while booking.
216  coord->init(&trackerTopology, &trackerGeometry, &siPixelFedCablingMap);
217 
218  // SiPixelCoordinates uses a different convention for UNDEFINED:
219  auto from_coord = [](double in) { return (in == -9999.0) ? UNDEFINED : Value(in); };
220 
221  // Rings are a concept that cannot be derived from bitmasks.
222  addExtractor(intern("PXRing"), [coord, from_coord](InterestingQuantities const& iq) {
223  return from_coord(coord->ring(iq.sourceModule));
224  });
225 
226  // Quadrant names.
227  auto pxbarrel = extractors[intern("PXBarrel")];
228  addExtractor(
229  intern("HalfCylinder"),
230  [coord, pxbarrel](InterestingQuantities const& iq) {
231  if (pxbarrel(iq) != UNDEFINED)
232  return UNDEFINED;
233  int quadrant = coord->quadrant(iq.sourceModule);
234  switch (quadrant) {
235  case 1:
236  return Value(12); // mO
237  case 2:
238  return Value(11); // mI
239  case 3:
240  return Value(22); // pO
241  case 4:
242  return Value(21); // pI
243  default:
244  return UNDEFINED;
245  }
246  },
247  0,
248  0 // N/A
249  );
250  addExtractor(
251  intern("Shell"),
252  [coord, pxbarrel](InterestingQuantities const& iq) {
253  if (pxbarrel(iq) == UNDEFINED)
254  return UNDEFINED;
255  int quadrant = coord->quadrant(iq.sourceModule);
256  switch (quadrant) {
257  case 1:
258  return Value(12); // mO
259  case 2:
260  return Value(11); // mI
261  case 3:
262  return Value(22); // pO
263  case 4:
264  return Value(21); // pI
265  default:
266  return UNDEFINED;
267  }
268  },
269  0,
270  0 // N/A
271  );
272 
273  // Online Numbering.
274  addExtractor(intern("SignedLadder"), [coord, from_coord](InterestingQuantities const& iq) {
275  return from_coord(coord->signed_ladder(iq.sourceModule()));
276  });
277  addExtractor(intern("SignedModule"), [coord, from_coord](InterestingQuantities const& iq) {
278  return from_coord(coord->signed_module(iq.sourceModule()));
279  });
280  addExtractor(intern("SignedBlade"), [coord, from_coord](InterestingQuantities const& iq) {
281  return from_coord(coord->signed_blade(iq.sourceModule()));
282  });
283 
284  // Flipped and Outer ladders
285  addExtractor(intern("OuterLadder"), [coord, from_coord](InterestingQuantities const& iq) {
286  return from_coord(coord->outer(iq.sourceModule()));
287  });
288  addExtractor(intern("FlippedLadder"), [coord, from_coord](InterestingQuantities const& iq) {
289  return from_coord(coord->flipped(iq.sourceModule()));
290  });
291 
292  // Pixel Map axis.
293  // TODO: automatic range and binning for phase0 are incorrect.
294  // Should be set manually here.
295  addExtractor(
296  intern("SignedModuleCoord"), // BPIX x
297  [coord, from_coord](InterestingQuantities const& iq) {
298  return from_coord(coord->signed_module_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
299  },
300  UNDEFINED,
301  UNDEFINED,
302  1.0 / 8.0);
303  addExtractor(
304  intern("SignedLadderCoord"), // BPIX y
305  [coord, from_coord](InterestingQuantities const& iq) {
306  return from_coord(coord->signed_ladder_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
307  },
308  UNDEFINED,
309  UNDEFINED,
310  1.0 / 2.0);
311  addExtractor(
312  intern("SignedDiskCoord"), // FPIX x (per-ring)
313  [coord, from_coord](InterestingQuantities const& iq) {
314  return from_coord(coord->signed_disk_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
315  },
316  UNDEFINED,
317  UNDEFINED,
318  1.0 / 8.0);
319  addExtractor(
320  intern("SignedDiskRingCoord"), // FPIX x (FPIX-as-one-plot)
321  [coord, from_coord](InterestingQuantities const& iq) {
322  return from_coord(coord->signed_disk_ring_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
323  },
324  UNDEFINED,
325  UNDEFINED,
326  1.0 / 16.0);
327  addExtractor(
328  intern("SignedBladePanelCoord"), // FPIX y
329  [coord, from_coord, phase](InterestingQuantities const& iq) {
330  if (phase == 0) {
331  return from_coord(coord->signed_blade_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
332  } else if (phase == 1) {
333  return from_coord(
334  coord->signed_blade_panel_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
335  } else {
336  return UNDEFINED; // TODO: phase2
337  }
338  },
339  UNDEFINED,
340  UNDEFINED,
341  phase == 1 ? 0.25 : 0.2);
342  addExtractor(
343  intern("SignedShiftedBladePanelCoord"), // FPIX-as-one y
344  [coord, from_coord, phase](InterestingQuantities const& iq) {
345  if (phase == 0) {
346  return from_coord(coord->signed_blade_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
347  } else if (phase == 1) {
348  return from_coord(
349  coord->signed_shifted_blade_panel_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
350  } else {
351  return UNDEFINED; // TODO: phase2
352  }
353  },
354  UNDEFINED,
355  UNDEFINED,
356  phase == 1 ? 0.25 : 0.1 // half-roc for phase0
357  );
358  addExtractor(
359  intern("SignedBladePanel"), // per-module FPIX y
360  [coord, from_coord](InterestingQuantities const& iq) {
361  return from_coord(coord->signed_blade_panel_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
362  },
363  UNDEFINED,
364  UNDEFINED,
365  1.0 / 2.0);
366 
367  addExtractor(
368  intern("SignedBladePanel"),
369  [coord, from_coord](InterestingQuantities const& iq) {
370  return from_coord(coord->signed_blade_panel_coord(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
371  },
372  UNDEFINED,
373  UNDEFINED,
374  1.0 / 2.0);
375 
376  // more readout-related things.
377  addExtractor(intern("ROC"), [coord, from_coord](InterestingQuantities const& iq) {
378  return from_coord(coord->roc(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
379  });
380  addExtractor(intern("Sector"), [coord, from_coord](InterestingQuantities const& iq) {
381  return from_coord(coord->sector(iq.sourceModule()));
382  });
383  addExtractor(intern("Channel"), [coord, from_coord](InterestingQuantities const& iq) {
384  return from_coord(coord->channel(iq.sourceModule(), std::make_pair(int(iq.row), int(iq.col))));
385  });
386 }
387 
389  // extractors for quantities that are roughly time-based. We cannot book plots based on these; they have to
390  // be grouped away in step1.
391  addExtractor(
392  intern("Lumisection"),
393  [](InterestingQuantities const& iq) {
394  if (!iq.sourceEvent)
395  return UNDEFINED;
396  return Value(iq.sourceEvent->luminosityBlock());
397  },
398  1,
399  iConfig.getParameter<int>("max_lumisection"));
400 
401  int onlineblock = iConfig.getParameter<int>("onlineblock");
402  int n_onlineblocks = iConfig.getParameter<int>("n_onlineblocks");
403  addExtractor(
404  intern("OnlineBlock"),
405  [onlineblock](InterestingQuantities const& iq) {
406  if (!iq.sourceEvent)
407  return UNDEFINED;
409  },
410  // note: this range is not visible anywhere (if the RenderPlugin does its job),
411  // but the strange range allows the RenderPlugin to know the block size.
412  onlineblock,
414 
415  int lumiblock = iConfig.getParameter<int>("lumiblock");
416  addExtractor(
417  intern("LumiBlock"),
418  [lumiblock](InterestingQuantities const& iq) {
419  if (!iq.sourceEvent)
420  return UNDEFINED;
421  // The '-1' is for making 1-10 the same block rather than 0-9
422  // The '+0.5' makes the block span an integer range rather n.5-m.5
423  return Value(((iq.sourceEvent->luminosityBlock() - 1) / lumiblock) + 0.5);
424  },
425  -0.5,
426  iConfig.getParameter<int>("max_lumisection") / lumiblock);
427 
428  addExtractor(
429  intern("BX"),
430  [](InterestingQuantities const& iq) {
431  if (!iq.sourceEvent)
432  return UNDEFINED;
433  return Value(iq.sourceEvent->bunchCrossing());
434  },
435  1,
436  iConfig.getParameter<int>("max_bunchcrossing"));
437 }
438 
440  // stuff that is within modules. Might require some phase0/phase1/strip switching later
441  addExtractor(
442  intern("row"),
443  [](InterestingQuantities const& iq) { return Value(iq.row); },
444  0,
445  iConfig.getParameter<int>("module_rows") - 1);
446  addExtractor(
447  intern("col"),
448  [](InterestingQuantities const& iq) { return Value(iq.col); },
449  0,
450  iConfig.getParameter<int>("module_cols") - 1);
451 }
452 
453 void GeometryInterface::loadFEDCabling(const SiPixelFedCablingMap* labeledSiPixelFedCablingMap) {
454  std::shared_ptr<SiPixelFrameReverter> siPixelFrameReverter =
455  // I think passing the bare pointer here is safe, but who knows...
456  std::make_shared<SiPixelFrameReverter>(labeledSiPixelFedCablingMap);
457 
458  addExtractor(intern("FED"), [siPixelFrameReverter](InterestingQuantities const& iq) {
459  if (iq.sourceModule == 0xFFFFFFFF)
460  return Value(iq.col); // hijacked for the raw data plugin
461  return Value(siPixelFrameReverter->findFedId(iq.sourceModule.rawId()));
462  });
463 
464  // TODO: ranges should be set manually below, since booking probably cannot
465  // infer them correctly (no ROC-level granularity)
466  // PERF: this is slow. Prefer SiPixelCordinates versions here.
467  addExtractor(intern("LinkInFed"), [siPixelFrameReverter](InterestingQuantities const& iq) {
468  if (iq.sourceModule == 0xFFFFFFFF)
469  return Value(iq.row); // hijacked for the raw data plugin
470  sipixelobjects::GlobalPixel gp = {iq.row, iq.col};
471  return Value(siPixelFrameReverter->findLinkInFed(iq.sourceModule.rawId(), gp));
472  });
473  // not sure if this is useful anywhere.
474  addExtractor(intern("RocInLink"), [siPixelFrameReverter](InterestingQuantities const& iq) {
476  return Value(siPixelFrameReverter->findRocInLink(iq.sourceModule.rawId(), gp));
477  });
478  // This might be equivalent to our ROC numbering.
479  addExtractor(intern("RocInDet"), [siPixelFrameReverter](InterestingQuantities const& iq) {
481  return Value(siPixelFrameReverter->findRocInDet(iq.sourceModule.rawId(), gp));
482  });
483 }
484 
486  auto it = format_value.find(std::make_pair(col, val));
487  if (it != format_value.end())
488  return it->second;
489 
490  // non-number output names (_pO etc.) are hardwired here.
492  std::string value = "_" + std::to_string(int(val));
493  if (val == 0)
494  value = ""; // hide Barrel_0 etc.
495  if (name == "PXDisk" && val > 0) // +/- sign for disk num
496  value = "_+" + std::to_string(int(val));
497  // pretty (legacy?) names for Shells and HalfCylinders
498  std::map<int, std::string> shellname{{11, "_mI"}, {12, "_mO"}, {21, "_pI"}, {22, "_pO"}};
499  if (name == "HalfCylinder" || name == "Shell")
500  value = shellname[int(val)];
501  if (val == UNDEFINED)
502  value = "_UNDEFINED";
503  return format_value[std::make_pair(col, val)] = name + value;
504 }
std::map< ID, Value > max_value
std::string cablingMapLabel_
std::map< std::pair< Column, Value >, std::string > format_value
T getParameter(std::string const &) const
Definition: ParameterSet.h:303
GeometryInterface(const edm::ParameterSet &, edm::ConsumesCollector &&, edm::Transition transition=edm::Transition::BeginRun)
T const & getData(const ESGetToken< T, R > &iToken) const noexcept(false)
Definition: EventSetup.h:119
std::map< std::string, ID > ids
const TrackerGeomDet * idToDetUnit(DetId) const override
Return the pointer to the GeomDetUnit corresponding to a given DetId.
virtual int ncolumns() const =0
const DetIdContainer & detIds() const override
Returm a vector of all GeomDet DetIds (including those of GeomDetUnits)
std::string pretty(Column col)
void addExtractor(ID id, std::function< Value(InterestingQuantities const &iq)> func, Value min=UNDEFINED, Value max=UNDEFINED, Value binwidth=1)
int quadrant(const DetId &detid, const TrackerTopology *tTopo_, bool phase_)
std::string formatValue(Column, Value)
virtual int nrows() const =0
assert(be >=bs)
edm::LuminosityBlockNumber_t luminosityBlock() const
Definition: EventBase.h:65
static std::string to_string(const XMLCh *ch)
global coordinates (row and column in DetUnit, as in PixelDigi)
Definition: GlobalPixel.h:6
void loadFromTopology(const TrackerGeometry &, const TrackerTopology &, const edm::ParameterSet &)
edm::ESGetToken< TrackerTopology, TrackerTopologyRcd > trackerTopologyToken_
Definition: TTTypes.h:54
void loadModuleLevel(const edm::ParameterSet &iConfig)
void load(edm::EventSetup const &iSetup)
void loadFromSiPixelCoordinates(const TrackerGeometry &, const TrackerTopology &, const SiPixelFedCablingMap &, const edm::ParameterSet &)
const edm::ParameterSet iConfig
std::vector< InterestingQuantities > all_modules
Transition
Definition: Transition.h:12
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > labeledSiPixelFedCablingMapToken_
Definition: value.py:1
static const Value UNDEFINED
void loadFEDCabling(const SiPixelFedCablingMap *)
Definition: DetId.h:17
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
int bunchCrossing() const
Definition: EventBase.h:68
edm::ESGetToken< TrackerGeometry, TrackerDigiGeometryRecord > trackerGeometryToken_
edm::ESGetToken< SiPixelFedCablingMap, SiPixelFedCablingMapRcd > siPixelFedCablingMapToken_
virtual const PixelTopology & specificTopology() const
Returns a reference to the pixel proxy topology.
col
Definition: cuy.py:1009
std::vector< std::function< Value(InterestingQuantities const &iq)> > extractors
void loadTimebased(const edm::ParameterSet &iConfig)
std::map< ID, Value > min_value
ID intern(std::string const &id)
T mod(const T &a, const T &b)
Definition: ecalDccMap.h:4