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