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