CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 
18 
19 //=============================================================================
20 //=== PUBLIC METHOD IMPLEMENTATION ===
21 //=============================================================================
22 
23 //_____________________________________________________________________________
25  const TrackerTopology* trackerTopology)
26  : trackerGeometry_(trackerGeometry),
27  trackerTopology_(trackerTopology),
28  alignableObjectId_(trackerGeometry, nullptr, nullptr, nullptr),
29  alignableMap_(nullptr),
30  trackerAlignmentLevelBuilder_(trackerTopology, trackerGeometry) {
31  std::ostringstream ss;
32 
33  switch (alignableObjectId_.geometry()) {
35  ss << "RunI geometry";
36  break;
38  ss << "PhaseI geometry";
39  break;
41  ss << "PhaseII geometry";
42  break;
43  default:
44  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] unknown version of TrackerGeometry";
45  }
46 
47  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::AlignableTrackerBuilder"
48  << "GeometryVersion: " << ss.str();
49 }
50 
51 //_____________________________________________________________________________
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.)
60 
61  if (update)
62  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 //=== PRIVATE METHOD IMPLEMENTATION ===
77 //=============================================================================
78 
79 //_____________________________________________________________________________
81  // PixelBarrel
83 
84  // PixelEndcap
86 
87  // TIB
89 
90  // TID
92 
93  // TOB
95 
96  // TEC
98 }
99 
100 //_____________________________________________________________________________
102  const std::string& moduleName,
103  bool update) {
104  numDetUnits = 0;
105 
106  auto& alignables = alignableMap_->get(moduleName);
107  if (!update)
108  alignables.reserve(geomDets.size());
109 
110  // units are added for each moduleName, which are at moduleName + "Unit"
111  // in the pixel Module and ModuleUnit are equivalent
112  auto& aliUnits = alignableMap_->get(moduleName + "Unit");
113  if (!update)
114  aliUnits.reserve(geomDets.size()); // minimal number space needed
115 
116  for (auto& geomDet : geomDets) {
117  int subdetId = geomDet->geographicalId().subdetId(); //don't check det()==Tracker
118 
119  if (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) {
120  buildPixelDetectorAlignable(geomDet, subdetId, alignables, aliUnits, update);
121 
122  } else if (subdetId == SiStripDetId::TIB || subdetId == SiStripDetId::TID || subdetId == SiStripDetId::TOB ||
123  subdetId == SiStripDetId::TEC) {
124  // for strip we create also <TIB/TID/TOB/TEC>ModuleUnit list
125  // for 1D components of 2D layers
126  buildStripDetectorAlignable(geomDet, subdetId, alignables, aliUnits, update);
127 
128  } else {
129  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] GeomDet of unknown subdetector";
130  }
131 
132  trackerAlignmentLevelBuilder_.addDetUnitInfo(geomDet->geographicalId());
133  }
134 
135  // JFI: For PXB and PXE we exclusively build AlignableDetUnit, hence
136  // alignables.size() and numDetUnits are equal. But for modules in Strip
137  // we also create AlignableSiStripDets, which consist of multiple
138  // AlignableDetUnits, hence alignables.size() and numDetUnits are not equal.
139 
140  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::convertGeomDetsToAlignables"
141  << "converted GeomDets to Alignables for " << moduleName << "\n"
142  << " GeomDets: " << geomDets.size() << "\n"
143  << " AlignableDetUnits: " << numDetUnits;
144 }
145 
146 //_____________________________________________________________________________
148  const GeomDet* geomDetUnit, int subdetId, Alignables& aliDets, Alignables& aliDetUnits, bool update) {
149  // treat all pixel dets in same way with one AlignableDetUnit
150  if (!geomDetUnit->isLeaf()) {
151  throw cms::Exception("BadHierarchy") << "[AlignableTrackerBuilder] Pixel GeomDet (subdetector " << subdetId
152  << ") is not a GeomDetUnit.";
153  }
154 
155  if (update) {
156  auto ali = std::find_if(aliDets.cbegin(), aliDets.cend(), [&geomDetUnit](const auto& i) {
157  return i->id() == geomDetUnit->geographicalId().rawId();
158  });
159  if (ali != aliDets.end()) {
160  // add dynamic cast here to get AlignableDetUnit!
161  auto aliDetUnit = dynamic_cast<AlignableDetUnit*>(*ali);
162  if (aliDetUnit) {
163  aliDetUnit->update(geomDetUnit);
164  } else {
165  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder::buildPixelDetectorAlignable] "
166  << "cast to 'AlignableDetUnit*' failed while it should not\n";
167  }
168  } else {
169  throw cms::Exception("GeometryMismatch")
170  << "[AlignableTrackerBuilder::buildPixelDetectorAlignable] "
171  << "GeomDet with DetId " << geomDetUnit->geographicalId().rawId() << " not found in current geometry.\n";
172  }
173  } else {
174  aliDets.push_back(new AlignableDetUnit(geomDetUnit));
175  aliDetUnits.push_back(aliDets.back());
176  }
177  numDetUnits += 1;
178 }
179 
180 //_____________________________________________________________________________
182  const GeomDet* geomDet, int subdetId, Alignables& aliDets, Alignables& aliDetUnits, bool update) {
183  // In strip we have:
184  // 1) 'Pure' 1D-modules like TOB layers 3-6 (not glued): AlignableDetUnit
185  // 2) Composite 2D-modules like TOB layers 1&2 (not glued): AlignableDet
186  // 3) The two 1D-components of case 2 (glued): AlignableDetUnit that is constructed
187  // inside AlignableDet-constructor of 'mother', only need to add to alignableLists
188  const SiStripDetId detId(geomDet->geographicalId());
189 
190  // 2D- or 'pure' 1D-module
191  if (!detId.glued()) {
192  if (!geomDet->components().empty()) {
193  // 2D-module, convert it to GluedGeomDet
194  const GluedGeomDet* gluedGeomDet = dynamic_cast<const GluedGeomDet*>(geomDet);
195  if (!gluedGeomDet) {
196  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] dynamic_cast<const GluedGeomDet*> "
197  << "failed.";
198  }
199 
200  // components (AlignableDetUnits) constructed within
201  if (update) {
202  auto ali = std::find_if(aliDets.cbegin(), aliDets.cend(), [&gluedGeomDet](const auto& i) {
203  return i->id() == gluedGeomDet->geographicalId().rawId();
204  });
205  if (ali != aliDets.end()) {
206  auto aliSiStripDet = dynamic_cast<AlignableSiStripDet*>(*ali);
207  if (aliSiStripDet) {
208  aliSiStripDet->update(gluedGeomDet);
209  } else {
210  throw cms::Exception("LogicError") << "[AlignableTrackerBuilder::buildStripDetectorAlignable] "
211  << "cast to 'AlignableSiStripDet*' failed while it should not\n";
212  }
213  } else {
214  throw cms::Exception("GeometryMismatch")
215  << "[AlignableTrackerBuilder::buildStripDetectorAlignable] "
216  << "GeomDet with DetId " << gluedGeomDet->geographicalId().rawId() << " not found in current geometry.\n";
217  }
218  } else {
219  aliDets.push_back(new AlignableSiStripDet(gluedGeomDet));
220  }
221  const auto& addAliDetUnits = aliDets.back()->components();
222  const auto& nAddedUnits = addAliDetUnits.size();
223 
224  if (!update) {
225  // reserve space for the additional units:
226  aliDetUnits.reserve(aliDetUnits.size() + nAddedUnits - 1);
227  aliDetUnits.insert(aliDetUnits.end(), addAliDetUnits.begin(), addAliDetUnits.end());
228  }
229  numDetUnits += nAddedUnits;
230 
231  } else {
232  // no components: pure 1D-module
233  buildPixelDetectorAlignable(geomDet, subdetId, aliDets, aliDetUnits, update);
234  }
235  } // no else: glued components of AlignableDet constructed within
236  // AlignableSiStripDet -> AlignableDet, see above
237 }
238 
239 //_____________________________________________________________________________
241  unsigned int numCompositeAlignables = 0;
242 
243  // tracker levels must be built before the indexer is created in order to pass
244  // a valid namespace to the indexer; an exception would be thrown if one tries
245  // to get the namespace w/o building the levels
246  auto trackerLevels = trackerAlignmentLevelBuilder_.build();
248  AlignableCompositeBuilder compositeBuilder{trackerTopology_, trackerGeometry_, trackerIndexer};
249 
250  for (auto& trackerSubLevels : trackerLevels) {
251  // first add all levels of the current subdetector to the builder
252  for (auto& level : trackerSubLevels) {
253  compositeBuilder.addAlignmentLevel(std::move(level));
254  }
255  // now build this tracker-level
256  numCompositeAlignables += compositeBuilder.buildAll(*alignableMap_, update);
257  // finally, reset the builder
258  compositeBuilder.clearAlignmentLevels();
259  }
260 
261  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildAlignableComposites"
262  << "AlignableComposites built for Tracker: " << numCompositeAlignables
263  << " (note: without Pixel- and Strip-Alignable)";
264 }
265 
266 //_____________________________________________________________________________
271 
272  auto& pxbAlignables = alignableMap_->find(pxbName);
273  auto& pxeAlignables = alignableMap_->find(pxeName);
274  auto& pixelAlignables = alignableMap_->get(pixelName);
275 
276  pixelAlignables.push_back(new AlignableComposite(pxbAlignables[0]->id(), align::Pixel, align::RotationType()));
277 
278  pixelAlignables[0]->addComponent(pxbAlignables[0]);
279  pixelAlignables[0]->addComponent(pxeAlignables[0]);
280  pixelAlignables[0]->addComponent(pxeAlignables[1]);
281 
282  trackerAlignables->addComponent(pixelAlignables[0]);
283 
284  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildPixelDetector"
285  << "Built " << pixelName << "-detector Alignable, consisting of Alignables"
286  << " of " << pxbName << " and " << pxeName;
287 }
288 
289 //_____________________________________________________________________________
296 
297  auto& tibAlignables = alignableMap_->find(tibName);
298  auto& tidAlignables = alignableMap_->find(tidName);
299  auto& tobAlignables = alignableMap_->find(tobName);
300  auto& tecAlignables = alignableMap_->find(tecName);
301  auto& stripAlignables = alignableMap_->get(stripName);
302 
303  stripAlignables.push_back(new AlignableComposite(tibAlignables[0]->id(), align::Strip, align::RotationType()));
304 
305  stripAlignables[0]->addComponent(tibAlignables[0]);
306  stripAlignables[0]->addComponent(tidAlignables[0]);
307  stripAlignables[0]->addComponent(tidAlignables[1]);
308  stripAlignables[0]->addComponent(tobAlignables[0]);
309  stripAlignables[0]->addComponent(tecAlignables[0]);
310  stripAlignables[0]->addComponent(tecAlignables[1]);
311 
312  trackerAlignables->addComponent(stripAlignables[0]);
313 
314  edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildStripDetector"
315  << "Built " << stripName << "-detector Alignable, consisting of Alignables"
316  << " of " << tibName << ", " << tidName << ", " << tobName << " and "
317  << tecName;
318 }
align::Alignables & get(const std::string &name="")
Definition: AlignableMap.cc:7
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.
static constexpr auto TID
Definition: SiStripDetId.h:38
AlignableMap alignableMap_
constexpr uint32_t rawId() const
get the raw id
Definition: DetId.h:57
const Alignables & components() const override
Return vector of direct components.
virtual std::vector< const GeomDet * > components() const
Returns direct components, if any.
Definition: GeomDet.h:73
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
const align::TrackerNameSpace & trackerNameSpace() const
const DetContainer & detsTEC() const
def move
Definition: eostools.py:511
const DetContainer & detsPXB() const
DetId geographicalId() const
The label of this GeomDet.
Definition: GeomDet.h:64
virtual bool isLeaf() const
is a Unit
Definition: GeomDet.h:70
Geometry geometry() const
retrieve the geometry information
const AlignableObjectId alignableObjectId_
TrackerAlignmentLevelBuilder trackerAlignmentLevelBuilder_
static constexpr auto TOB
Definition: SiStripDetId.h:39
void buildAlignableDetUnits(bool update=false)
Builds Alignables on module-level for each part of the tracker.
const DetContainer & detsTIB() const
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
static constexpr auto TIB
Definition: SiStripDetId.h:37
#define update(a, b)
const DetContainer & detsPXF() const
const DetContainer & detsTOB() const
void update(const GeomDet *geomDet, bool updateComponents=true)
Definition: AlignableDet.cc:50
void buildStripDetectorAlignable(const GeomDet *, int subdetId, Alignables &aliDets, Alignables &aliDetUnits, bool update=false)
tuple level
Definition: testEve_cfg.py:47
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_
void buildAlignableComposites(bool update=false)
void addComponent(Alignable *component) final
static constexpr auto TEC
Definition: SiStripDetId.h:40
const DetContainer & detsTID() const