CMS 3D CMS Logo

AlignableTrackerBuilder.cc
Go to the documentation of this file.
2 
3 // Original Author: Max Stark
4 // Created: Thu, 13 Jan 2016 10:22:57 CET
5 
6 // geometry
10 
11 // alignment
18 
20 
21 //=============================================================================
22 //=== PUBLIC METHOD IMPLEMENTATION ===
23 //=============================================================================
24 
25 //_____________________________________________________________________________
27  const TrackerTopology* trackerTopology)
28  : trackerGeometry_(trackerGeometry),
29  trackerTopology_(trackerTopology),
30  alignableObjectId_(trackerGeometry, nullptr, nullptr, nullptr),
31  alignableMap_(nullptr),
32  trackerAlignmentLevelBuilder_(trackerTopology, trackerGeometry) {
33  std::ostringstream ss;
34 
35  switch (alignableObjectId_.geometry()) {
37  ss << "RunI geometry";
38  break;
40  ss << "PhaseI geometry";
41  break;
43  ss << "PhaseII geometry";
44  break;
45  default:
46  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] unknown version of TrackerGeometry";
47  }
48 
49  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::AlignableTrackerBuilder"
50  << "GeometryVersion: " << ss.str();
51 }
52 
53 //_____________________________________________________________________________
55  alignableMap_ = &trackerAlignables->alignableMap_;
56 
57  // first, build Alignables on module-level (AlignableDetUnits)
59 
60  // now build the composite Alignables (Ladders, Layers etc.)
62 
63  if (update)
64  return; // everything else not needed for the update
65 
66  // create pixel-detector
67  buildPixelDetector(trackerAlignables);
68 
69  // for the Outer Tracker, decide which geometry we are addressing
71  // create strip-detector
72  buildStripDetector(trackerAlignables);
73  } else {
74  // create Phase2 Outer Tracker-detector
75  buildOuterTrackerDetector(trackerAlignables);
76  }
77 
78  // tracker itself is of course also an Alignable
79  alignableMap_->get("Tracker").push_back(trackerAlignables);
80  // id is the id of first component (should be TPBBarrel)
81  trackerAlignables->theId = trackerAlignables->components()[0]->id();
82 }
83 
84 //=============================================================================
85 //=== PRIVATE METHOD IMPLEMENTATION ===
86 //=============================================================================
87 
88 //_____________________________________________________________________________
90  // PixelBarrel
92 
93  // PixelEndcap
95 
96  // TIB
98 
99  // TID
101 
102  // TOB
104 
105  // TEC
107 }
108 
109 //_____________________________________________________________________________
111  const std::string& moduleName,
112  bool update) {
113  numDetUnits = 0;
114 
115  auto& alignables = alignableMap_->get(moduleName);
116  if (!update)
117  alignables.reserve(geomDets.size());
118 
119  // units are added for each moduleName, which are at moduleName + "Unit"
120  // in the pixel Module and ModuleUnit are equivalent
121  auto& aliUnits = alignableMap_->get(moduleName + "Unit");
122  if (!update)
123  aliUnits.reserve(geomDets.size()); // minimal number space needed
124 
125  for (auto& geomDet : geomDets) {
126  int subdetId = geomDet->geographicalId().subdetId(); //don't check det()==Tracker
127 
128  if (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) {
129  buildPixelDetectorAlignable(geomDet, subdetId, alignables, aliUnits, update);
130 
131  } else if (subdetId == SiStripDetId::TIB || subdetId == SiStripDetId::TID || subdetId == SiStripDetId::TOB ||
132  subdetId == SiStripDetId::TEC) {
133  // for strip we create also <TIB/TID/TOB/TEC>ModuleUnit list
134  // for 1D components of 2D layers
135 
137  buildStripDetectorAlignable(geomDet, subdetId, alignables, aliUnits, update);
138  } else {
139  buildOuterTrackerDetectorAlignable(geomDet, subdetId, alignables, aliUnits, update);
140  }
141 
142  } else {
143  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] GeomDet of unknown subdetector";
144  }
145 
146  trackerAlignmentLevelBuilder_.addDetUnitInfo(geomDet->geographicalId());
147  }
148 
149  // JFI: For PXB and PXE we exclusively build AlignableDetUnit, hence
150  // alignables.size() and numDetUnits are equal. But for modules in Strip
151  // we also create AlignableSiStripDets, which consist of multiple
152  // AlignableDetUnits, hence alignables.size() and numDetUnits are not equal.
153 
154  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::convertGeomDetsToAlignables"
155  << "converted GeomDets to Alignables for " << moduleName << "\n"
156  << " GeomDets: " << geomDets.size() << "\n"
157  << " AlignableDetUnits: " << numDetUnits;
158 }
159 
160 //_____________________________________________________________________________
162  const GeomDet* geomDetUnit, int subdetId, Alignables& aliDets, Alignables& aliDetUnits, bool update) {
163  // treat all pixel dets in same way with one AlignableDetUnit
164  if (!geomDetUnit->isLeaf()) {
165  throw cms::Exception("BadHierarchy") << "[AlignableTrackerBuilder] Pixel GeomDet (subdetector " << subdetId
166  << ") is not a GeomDetUnit.";
167  }
168 
169  if (update) {
170  auto ali = std::find_if(aliDets.cbegin(), aliDets.cend(), [&geomDetUnit](const auto& i) {
171  return i->id() == geomDetUnit->geographicalId().rawId();
172  });
173  if (ali != aliDets.end()) {
174  // add dynamic cast here to get AlignableDetUnit!
175  auto aliDetUnit = dynamic_cast<AlignableDetUnit*>(*ali);
176  if (aliDetUnit) {
177  aliDetUnit->update(geomDetUnit);
178  } else {
179  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder::buildPixelDetectorAlignable] "
180  << "cast to 'AlignableDetUnit*' failed while it should not\n";
181  }
182  } else {
183  throw cms::Exception("GeometryMismatch")
184  << "[AlignableTrackerBuilder::buildPixelDetectorAlignable] "
185  << "GeomDet with DetId " << geomDetUnit->geographicalId().rawId() << " not found in current geometry.\n";
186  }
187  } else {
188  aliDets.push_back(new AlignableDetUnit(geomDetUnit));
189  aliDetUnits.push_back(aliDets.back());
190  }
191  numDetUnits += 1;
192 }
193 
194 //_____________________________________________________________________________
196  const GeomDet* geomDet, int subdetId, Alignables& aliDets, Alignables& aliDetUnits, bool update) {
197  // In strip we have:
198  // 1) 'Pure' 1D-modules like TOB layers 3-6 (not glued): AlignableDetUnit
199  // 2) Composite 2D-modules like TOB layers 1&2 (not glued): AlignableDet
200  // 3) The two 1D-components of case 2 (glued): AlignableDetUnit that is constructed
201  // inside AlignableDet-constructor of 'mother', only need to add to alignableLists
202  const SiStripDetId detId(geomDet->geographicalId());
203 
204  // 2D- or 'pure' 1D-module
205  if (!detId.glued()) {
206  if (!geomDet->components().empty()) {
207  // 2D-module, convert it to GluedGeomDet
208  const GluedGeomDet* gluedGeomDet = dynamic_cast<const GluedGeomDet*>(geomDet);
209  if (!gluedGeomDet) {
210  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] dynamic_cast<const GluedGeomDet*> "
211  << "failed.";
212  }
213 
214  // components (AlignableDetUnits) constructed within
215  if (update) {
216  auto ali = std::find_if(aliDets.cbegin(), aliDets.cend(), [&gluedGeomDet](const auto& i) {
217  return i->id() == gluedGeomDet->geographicalId().rawId();
218  });
219  if (ali != aliDets.end()) {
220  auto aliSiStripDet = dynamic_cast<AlignableSiStripDet*>(*ali);
221  if (aliSiStripDet) {
222  aliSiStripDet->update(gluedGeomDet);
223  } else {
224  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder::buildStripDetectorAlignable] "
225  << "cast to 'AlignableSiStripDet*' failed while it should not\n";
226  }
227  } else {
228  throw cms::Exception("GeometryMismatch")
229  << "[AlignableTrackerBuilder::buildStripDetectorAlignable] "
230  << "GeomDet with DetId " << gluedGeomDet->geographicalId().rawId() << " not found in current geometry.\n";
231  }
232  } else {
233  aliDets.push_back(new AlignableSiStripDet(gluedGeomDet));
234  }
235  const auto& addAliDetUnits = aliDets.back()->components();
236  const auto& nAddedUnits = addAliDetUnits.size();
237 
238  if (!update) {
239  // reserve space for the additional units:
240  aliDetUnits.reserve(aliDetUnits.size() + nAddedUnits - 1);
241  aliDetUnits.insert(aliDetUnits.end(), addAliDetUnits.begin(), addAliDetUnits.end());
242  }
243  numDetUnits += nAddedUnits;
244 
245  } else {
246  // no components: pure 1D-module
247  buildPixelDetectorAlignable(geomDet, subdetId, aliDets, aliDetUnits, update);
248  }
249  } // no else: glued components of AlignableDet constructed within
250  // AlignableSiStripDet -> AlignableDet, see above
251 }
252 
253 //_____________________________________________________________________________
255  const GeomDet* geomDet, int subdetId, Alignables& aliDets, Alignables& aliDetUnits, bool update) {
256  // hopefully all the geomdets are composite (either PS or SS modules in Ph-2 Outer Tracker)
257  if (!geomDet->components().empty()) {
258  // 2D-module, convert it to StackGeomDet
259  const StackGeomDet* stackGeomDet = dynamic_cast<const StackGeomDet*>(geomDet);
260  if (!stackGeomDet) {
261  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] dynamic_cast<const StackGeomDet*> "
262  << "failed.";
263  }
264 
265  // components (AlignableDetUnits) constructed within
266  if (update) {
267  auto ali = std::find_if(aliDets.cbegin(), aliDets.cend(), [&stackGeomDet](const auto& i) {
268  return i->id() == stackGeomDet->geographicalId().rawId();
269  });
270  if (ali != aliDets.end()) {
271  auto aliStackDet = dynamic_cast<AlignableStackDet*>(*ali);
272  if (aliStackDet) {
273  aliStackDet->update(geomDet);
274  } else {
275  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder::buildOuterTrackerDetectorAlignable] "
276  << "cast to 'AlignableStackDet*' failed while it should not\n";
277  }
278  } else {
279  throw cms::Exception("GeometryMismatch")
280  << "[AlignableTrackerBuilder::buildStripDetectorAlignable] "
281  << "GeomDet with DetId " << stackGeomDet->geographicalId().rawId() << " not found in current geometry.\n";
282  }
283  } else {
284  aliDets.push_back(new AlignableStackDet(stackGeomDet));
285  }
286  const auto& addAliDetUnits = aliDets.back()->components();
287  const auto& nAddedUnits = addAliDetUnits.size();
288 
289  if (!update) {
290  // reserve space for the additional units:
291  aliDetUnits.reserve(aliDetUnits.size() + nAddedUnits - 1);
292  aliDetUnits.insert(aliDetUnits.end(), addAliDetUnits.begin(), addAliDetUnits.end());
293  }
294  numDetUnits += nAddedUnits;
295  } // no else: stacked components of AlignableDet constructed within
296  // AlignableStackDet -> AlignableDet, see above
297 }
298 
299 //_____________________________________________________________________________
301  unsigned int numCompositeAlignables = 0;
302 
303  // tracker levels must be built before the indexer is created in order to pass
304  // a valid namespace to the indexer; an exception would be thrown if one tries
305  // to get the namespace w/o building the levels
306  auto trackerLevels = trackerAlignmentLevelBuilder_.build();
308  AlignableCompositeBuilder compositeBuilder{trackerTopology_, trackerGeometry_, trackerIndexer};
309 
310  for (auto& trackerSubLevels : trackerLevels) {
311  // first add all levels of the current subdetector to the builder
312  for (auto& level : trackerSubLevels) {
313  compositeBuilder.addAlignmentLevel(std::move(level));
314  }
315  // now build this tracker-level
316  numCompositeAlignables += compositeBuilder.buildAll(*alignableMap_, update);
317  // finally, reset the builder
318  compositeBuilder.clearAlignmentLevels();
319  }
320 
321  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildAlignableComposites"
322  << "AlignableComposites built for Tracker: " << numCompositeAlignables
323  << " (note: without Pixel- and Strip-Alignable)";
324 }
325 
326 //_____________________________________________________________________________
331 
332  auto& pxbAlignables = alignableMap_->find(pxbName);
333  auto& pxeAlignables = alignableMap_->find(pxeName);
334  auto& pixelAlignables = alignableMap_->get(pixelName);
335 
336  pixelAlignables.push_back(new AlignableComposite(pxbAlignables[0]->id(), align::Pixel, align::RotationType()));
337 
338  pixelAlignables[0]->addComponent(pxbAlignables[0]);
339  pixelAlignables[0]->addComponent(pxeAlignables[0]);
340  pixelAlignables[0]->addComponent(pxeAlignables[1]);
341 
342  trackerAlignables->addComponent(pixelAlignables[0]);
343 
344  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildPixelDetector"
345  << "Built " << pixelName << "-detector Alignable, consisting of Alignables"
346  << " of " << pxbName << " and " << pxeName;
347 }
348 
349 //_____________________________________________________________________________
356 
357  auto& tibAlignables = alignableMap_->find(tibName);
358  auto& tidAlignables = alignableMap_->find(tidName);
359  auto& tobAlignables = alignableMap_->find(tobName);
360  auto& tecAlignables = alignableMap_->find(tecName);
361  auto& stripAlignables = alignableMap_->get(stripName);
362 
363  stripAlignables.push_back(new AlignableComposite(tibAlignables[0]->id(), align::Strip, align::RotationType()));
364 
365  stripAlignables[0]->addComponent(tibAlignables[0]);
366  stripAlignables[0]->addComponent(tidAlignables[0]);
367  stripAlignables[0]->addComponent(tidAlignables[1]);
368  stripAlignables[0]->addComponent(tobAlignables[0]);
369  stripAlignables[0]->addComponent(tecAlignables[0]);
370  stripAlignables[0]->addComponent(tecAlignables[1]);
371 
372  trackerAlignables->addComponent(stripAlignables[0]);
373 
374  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildStripDetector"
375  << "Built " << stripName << "-detector Alignable, consisting of Alignables"
376  << " of " << tibName << ", " << tidName << ", " << tobName << " and "
377  << tecName;
378 }
379 
380 //_____________________________________________________________________________
385 
386  auto& tidAlignables = alignableMap_->find(tidName);
387  auto& tobAlignables = alignableMap_->find(tobName);
388  auto& stripAlignables = alignableMap_->get(stripName);
389 
390  stripAlignables.push_back(new AlignableComposite(tobAlignables[0]->id(), align::Strip, align::RotationType()));
391  stripAlignables[0]->addComponent(tobAlignables[0]);
392  stripAlignables[0]->addComponent(tidAlignables[0]);
393  stripAlignables[0]->addComponent(tidAlignables[1]);
394 
395  trackerAlignables->addComponent(stripAlignables[0]);
396 
397  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildStripDetector"
398  << "Built " << stripName << "-detector Alignable, consisting of Alignables"
399  << " of " << tidName << " and " << tobName;
400 }
virtual std::vector< const GeomDet * > components() const
Returns direct components, if any.
Definition: GeomDet.h:73
const DetContainer & detsTIB() const
align::Alignables & get(const std::string &name="")
Definition: AlignableMap.cc:7
virtual bool isLeaf() const
is a Unit
Definition: GeomDet.h:70
void buildPixelDetectorAlignable(const GeomDet *, int subdetId, Alignables &aliDets, Alignables &aliDetUnits, bool update=false)
Converts GeomDetUnits of PXB and PXE to AlignableDetUnits.
void buildPixelDetector(AlignableTracker *)
Builds the PixelDetector by hand.
const DetContainer & detsPXB() const
static constexpr auto TID
Definition: SiStripDetId.h:38
AlignableMap alignableMap_
const DetContainer & detsPXF() const
const Alignables & components() const override
Return vector of direct components.
const TrackerTopology * trackerTopology_
std::vector< align::AlignmentLevels > build()
void update(const GeomDetUnit *geomDetUnit)
std::vector< const GeomDet * > DetContainer
align::Alignables & find(const std::string &name="")
Definition: AlignableMap.cc:10
void buildOuterTrackerDetectorAlignable(const GeomDet *, int subdetId, Alignables &aliDets, Alignables &aliDetUnits, bool update=false)
const DetContainer & detsTOB() const
void buildOuterTrackerDetector(AlignableTracker *)
Builds the Phase-2 Outer Tracker Detector by hand.
const AlignableObjectId alignableObjectId_
TrackerAlignmentLevelBuilder trackerAlignmentLevelBuilder_
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
static constexpr auto TOB
Definition: SiStripDetId.h:39
const align::TrackerNameSpace & trackerNameSpace() const
void buildAlignableDetUnits(bool update=false)
Builds Alignables on module-level for each part of the tracker.
void buildStripDetector(AlignableTracker *)
Builds the StripDetector by hand.
Log< level::Info, false > LogInfo
Detector identifier class for the strip tracker.
Definition: SiStripDetId.h:18
AlignableTrackerBuilder(const TrackerGeometry *, const TrackerTopology *)
const char * idToString(align::StructureType type) const
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
static constexpr auto TIB
Definition: SiStripDetId.h:37
#define update(a, b)
Geometry geometry() const
retrieve the geometry information
void update(const GeomDet *geomDet, bool updateComponents=true)
Definition: AlignableDet.cc:50
const DetContainer & detsTEC() const
void buildStripDetectorAlignable(const GeomDet *, int subdetId, Alignables &aliDets, Alignables &aliDetUnits, bool update=false)
void buildAlignables(AlignableTracker *, bool update=false)
align::ID theId
Definition: Alignable.h:235
void convertGeomDetsToAlignables(const TrackingGeometry::DetContainer &, const std::string &moduleName, bool update=false)
const TrackerGeometry * trackerGeometry_
def move(src, dest)
Definition: eostools.py:511
void buildAlignableComposites(bool update=false)
void addComponent(Alignable *component) final
static constexpr auto TEC
Definition: SiStripDetId.h:40
const DetContainer & detsTID() const