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