Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-03-25 23:59:22

0001 #include "Alignment/TrackerAlignment/interface/AlignableTrackerBuilder.h"
0002 
0003 // Original Author:  Max Stark
0004 //         Created:  Thu, 13 Jan 2016 10:22:57 CET
0005 
0006 // geometry
0007 #include "Geometry/CommonDetUnit/interface/GeomDet.h"
0008 #include "Geometry/CommonDetUnit/interface/GluedGeomDet.h"
0009 
0010 // alignment
0011 #include "Alignment/CommonAlignment/interface/AlignableObjectId.h"
0012 #include "Alignment/CommonAlignment/interface/AlignableDetUnit.h"
0013 #include "Alignment/CommonAlignment/interface/AlignableCompositeBuilder.h"
0014 #include "Alignment/TrackerAlignment/interface/AlignableSiStripDet.h"
0015 #include "Alignment/TrackerAlignment/interface/TrackerAlignableIndexer.h"
0016 
0017 #include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
0018 
0019 //=============================================================================
0020 //===   PUBLIC METHOD IMPLEMENTATION                                        ===
0021 //=============================================================================
0022 
0023 //_____________________________________________________________________________
0024 AlignableTrackerBuilder ::AlignableTrackerBuilder(const TrackerGeometry* trackerGeometry,
0025                                                   const TrackerTopology* trackerTopology)
0026     : trackerGeometry_(trackerGeometry),
0027       trackerTopology_(trackerTopology),
0028       alignableObjectId_(trackerGeometry, nullptr, nullptr, nullptr),
0029       alignableMap_(nullptr),
0030       trackerAlignmentLevelBuilder_(trackerTopology, trackerGeometry) {
0031   std::ostringstream ss;
0032 
0033   switch (alignableObjectId_.geometry()) {
0034     case AlignableObjectId::Geometry::RunI:
0035       ss << "RunI geometry";
0036       break;
0037     case AlignableObjectId::Geometry::PhaseI:
0038       ss << "PhaseI geometry";
0039       break;
0040     case AlignableObjectId::Geometry::PhaseII:
0041       ss << "PhaseII geometry";
0042       break;
0043     default:
0044       throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] unknown version of TrackerGeometry";
0045   }
0046 
0047   edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::AlignableTrackerBuilder"
0048                                         << "GeometryVersion: " << ss.str();
0049 }
0050 
0051 //_____________________________________________________________________________
0052 void AlignableTrackerBuilder ::buildAlignables(AlignableTracker* trackerAlignables, bool update) {
0053   alignableMap_ = &trackerAlignables->alignableMap_;
0054 
0055   // first, build Alignables on module-level (AlignableDetUnits)
0056   buildAlignableDetUnits(update);
0057 
0058   // now build the composite Alignables (Ladders, Layers etc.)
0059   buildAlignableComposites(update);
0060 
0061   if (update)
0062     return;  // everything else not needed for the update
0063 
0064   // create pixel-detector
0065   buildPixelDetector(trackerAlignables);
0066   // create strip-detector
0067   buildStripDetector(trackerAlignables);
0068 
0069   // tracker itself is of course also an Alignable
0070   alignableMap_->get("Tracker").push_back(trackerAlignables);
0071   // id is the id of first component (should be TPBBarrel)
0072   trackerAlignables->theId = trackerAlignables->components()[0]->id();
0073 }
0074 
0075 //=============================================================================
0076 //===   PRIVATE METHOD IMPLEMENTATION                                       ===
0077 //=============================================================================
0078 
0079 //_____________________________________________________________________________
0080 void AlignableTrackerBuilder ::buildAlignableDetUnits(bool update) {
0081   // PixelBarrel
0082   convertGeomDetsToAlignables(trackerGeometry_->detsPXB(), alignableObjectId_.idToString(align::TPBModule), update);
0083 
0084   // PixelEndcap
0085   convertGeomDetsToAlignables(trackerGeometry_->detsPXF(), alignableObjectId_.idToString(align::TPEModule), update);
0086 
0087   // TIB
0088   convertGeomDetsToAlignables(trackerGeometry_->detsTIB(), alignableObjectId_.idToString(align::TIBModule), update);
0089 
0090   // TID
0091   convertGeomDetsToAlignables(trackerGeometry_->detsTID(), alignableObjectId_.idToString(align::TIDModule), update);
0092 
0093   // TOB
0094   convertGeomDetsToAlignables(trackerGeometry_->detsTOB(), alignableObjectId_.idToString(align::TOBModule), update);
0095 
0096   // TEC
0097   convertGeomDetsToAlignables(trackerGeometry_->detsTEC(), alignableObjectId_.idToString(align::TECModule), update);
0098 }
0099 
0100 //_____________________________________________________________________________
0101 void AlignableTrackerBuilder ::convertGeomDetsToAlignables(const TrackingGeometry::DetContainer& geomDets,
0102                                                            const std::string& moduleName,
0103                                                            bool update) {
0104   numDetUnits = 0;
0105 
0106   auto& alignables = alignableMap_->get(moduleName);
0107   if (!update)
0108     alignables.reserve(geomDets.size());
0109 
0110   // units are added for each moduleName, which are at moduleName + "Unit"
0111   // in the pixel Module and ModuleUnit are equivalent
0112   auto& aliUnits = alignableMap_->get(moduleName + "Unit");
0113   if (!update)
0114     aliUnits.reserve(geomDets.size());  // minimal number space needed
0115 
0116   for (auto& geomDet : geomDets) {
0117     int subdetId = geomDet->geographicalId().subdetId();  //don't check det()==Tracker
0118 
0119     if (subdetId == PixelSubdetector::PixelBarrel || subdetId == PixelSubdetector::PixelEndcap) {
0120       buildPixelDetectorAlignable(geomDet, subdetId, alignables, aliUnits, update);
0121 
0122     } else if (subdetId == SiStripDetId::TIB || subdetId == SiStripDetId::TID || subdetId == SiStripDetId::TOB ||
0123                subdetId == SiStripDetId::TEC) {
0124       // for strip we create also <TIB/TID/TOB/TEC>ModuleUnit list
0125       // for 1D components of 2D layers
0126       buildStripDetectorAlignable(geomDet, subdetId, alignables, aliUnits, update);
0127 
0128     } else {
0129       throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] GeomDet of unknown subdetector";
0130     }
0131 
0132     trackerAlignmentLevelBuilder_.addDetUnitInfo(geomDet->geographicalId());
0133   }
0134 
0135   // JFI: For PXB and PXE we exclusively build AlignableDetUnit, hence
0136   // alignables.size() and numDetUnits are equal. But for modules in Strip
0137   // we also create AlignableSiStripDets, which consist of multiple
0138   // AlignableDetUnits, hence alignables.size() and numDetUnits are not equal.
0139 
0140   edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::convertGeomDetsToAlignables"
0141                                         << "converted GeomDets to Alignables for " << moduleName << "\n"
0142                                         << "   GeomDets:             " << geomDets.size() << "\n"
0143                                         << "   AlignableDetUnits:    " << numDetUnits;
0144 }
0145 
0146 //_____________________________________________________________________________
0147 void AlignableTrackerBuilder ::buildPixelDetectorAlignable(
0148     const GeomDet* geomDetUnit, int subdetId, Alignables& aliDets, Alignables& aliDetUnits, bool update) {
0149   // treat all pixel dets in same way with one AlignableDetUnit
0150   if (!geomDetUnit->isLeaf()) {
0151     throw cms::Exception("BadHierarchy") << "[AlignableTrackerBuilder] Pixel GeomDet (subdetector " << subdetId
0152                                          << ") is not a GeomDetUnit.";
0153   }
0154 
0155   if (update) {
0156     auto ali = std::find_if(aliDets.cbegin(), aliDets.cend(), [&geomDetUnit](const auto& i) {
0157       return i->id() == geomDetUnit->geographicalId().rawId();
0158     });
0159     if (ali != aliDets.end()) {
0160       // add dynamic cast here to get AlignableDetUnit!
0161       auto aliDetUnit = dynamic_cast<AlignableDetUnit*>(*ali);
0162       if (aliDetUnit) {
0163         aliDetUnit->update(geomDetUnit);
0164       } else {
0165         throw cms::Exception("LogicError") << "[AlignableTrackerBuilder::buildPixelDetectorAlignable] "
0166                                            << "cast to 'AlignableDetUnit*' failed while it should not\n";
0167       }
0168     } else {
0169       throw cms::Exception("GeometryMismatch")
0170           << "[AlignableTrackerBuilder::buildPixelDetectorAlignable] "
0171           << "GeomDet with DetId " << geomDetUnit->geographicalId().rawId() << " not found in current geometry.\n";
0172     }
0173   } else {
0174     aliDets.push_back(new AlignableDetUnit(geomDetUnit));
0175     aliDetUnits.push_back(aliDets.back());
0176   }
0177   numDetUnits += 1;
0178 }
0179 
0180 //_____________________________________________________________________________
0181 void AlignableTrackerBuilder ::buildStripDetectorAlignable(
0182     const GeomDet* geomDet, int subdetId, Alignables& aliDets, Alignables& aliDetUnits, bool update) {
0183   // In strip we have:
0184   // 1) 'Pure' 1D-modules like TOB layers 3-6 (not glued): AlignableDetUnit
0185   // 2) Composite 2D-modules like TOB layers 1&2 (not glued): AlignableDet
0186   // 3) The two 1D-components of case 2 (glued): AlignableDetUnit that is constructed
0187   //      inside AlignableDet-constructor of 'mother', only need to add to alignableLists
0188   const SiStripDetId detId(geomDet->geographicalId());
0189 
0190   // 2D- or 'pure' 1D-module
0191   if (!detId.glued()) {
0192     if (!geomDet->components().empty()) {
0193       // 2D-module, convert it to GluedGeomDet
0194       const GluedGeomDet* gluedGeomDet = dynamic_cast<const GluedGeomDet*>(geomDet);
0195       if (!gluedGeomDet) {
0196         throw cms::Exception("LogicError") << "[AlignableTrackerBuilder] dynamic_cast<const GluedGeomDet*> "
0197                                            << "failed.";
0198       }
0199 
0200       // components (AlignableDetUnits) constructed within
0201       if (update) {
0202         auto ali = std::find_if(aliDets.cbegin(), aliDets.cend(), [&gluedGeomDet](const auto& i) {
0203           return i->id() == gluedGeomDet->geographicalId().rawId();
0204         });
0205         if (ali != aliDets.end()) {
0206           auto aliSiStripDet = dynamic_cast<AlignableSiStripDet*>(*ali);
0207           if (aliSiStripDet) {
0208             aliSiStripDet->update(gluedGeomDet);
0209           } else {
0210             throw cms::Exception("LogicError") << "[AlignableTrackerBuilder::buildStripDetectorAlignable] "
0211                                                << "cast to 'AlignableSiStripDet*' failed while it should not\n";
0212           }
0213         } else {
0214           throw cms::Exception("GeometryMismatch")
0215               << "[AlignableTrackerBuilder::buildStripDetectorAlignable] "
0216               << "GeomDet with DetId " << gluedGeomDet->geographicalId().rawId() << " not found in current geometry.\n";
0217         }
0218       } else {
0219         aliDets.push_back(new AlignableSiStripDet(gluedGeomDet));
0220       }
0221       const auto& addAliDetUnits = aliDets.back()->components();
0222       const auto& nAddedUnits = addAliDetUnits.size();
0223 
0224       if (!update) {
0225         // reserve space for the additional units:
0226         aliDetUnits.reserve(aliDetUnits.size() + nAddedUnits - 1);
0227         aliDetUnits.insert(aliDetUnits.end(), addAliDetUnits.begin(), addAliDetUnits.end());
0228       }
0229       numDetUnits += nAddedUnits;
0230 
0231     } else {
0232       // no components: pure 1D-module
0233       buildPixelDetectorAlignable(geomDet, subdetId, aliDets, aliDetUnits, update);
0234     }
0235   }  // no else: glued components of AlignableDet constructed within
0236      // AlignableSiStripDet -> AlignableDet, see above
0237 }
0238 
0239 //_____________________________________________________________________________
0240 void AlignableTrackerBuilder ::buildAlignableComposites(bool update) {
0241   unsigned int numCompositeAlignables = 0;
0242 
0243   // tracker levels must be built before the indexer is created in order to pass
0244   // a valid namespace to the indexer; an exception would be thrown if one tries
0245   // to get the namespace w/o building the levels
0246   auto trackerLevels = trackerAlignmentLevelBuilder_.build();
0247   TrackerAlignableIndexer trackerIndexer{trackerAlignmentLevelBuilder_.trackerNameSpace()};
0248   AlignableCompositeBuilder compositeBuilder{trackerTopology_, trackerGeometry_, trackerIndexer};
0249 
0250   for (auto& trackerSubLevels : trackerLevels) {
0251     // first add all levels of the current subdetector to the builder
0252     for (auto& level : trackerSubLevels) {
0253       compositeBuilder.addAlignmentLevel(std::move(level));
0254     }
0255     // now build this tracker-level
0256     numCompositeAlignables += compositeBuilder.buildAll(*alignableMap_, update);
0257     // finally, reset the builder
0258     compositeBuilder.clearAlignmentLevels();
0259   }
0260 
0261   edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildAlignableComposites"
0262                                         << "AlignableComposites built for Tracker: " << numCompositeAlignables
0263                                         << " (note: without Pixel- and Strip-Alignable)";
0264 }
0265 
0266 //_____________________________________________________________________________
0267 void AlignableTrackerBuilder ::buildPixelDetector(AlignableTracker* trackerAlignables) {
0268   const std::string& pxbName = alignableObjectId_.idToString(align::TPBBarrel);
0269   const std::string& pxeName = alignableObjectId_.idToString(align::TPEEndcap);
0270   const std::string& pixelName = alignableObjectId_.idToString(align::Pixel);
0271 
0272   auto& pxbAlignables = alignableMap_->find(pxbName);
0273   auto& pxeAlignables = alignableMap_->find(pxeName);
0274   auto& pixelAlignables = alignableMap_->get(pixelName);
0275 
0276   pixelAlignables.push_back(new AlignableComposite(pxbAlignables[0]->id(), align::Pixel, align::RotationType()));
0277 
0278   pixelAlignables[0]->addComponent(pxbAlignables[0]);
0279   pixelAlignables[0]->addComponent(pxeAlignables[0]);
0280   pixelAlignables[0]->addComponent(pxeAlignables[1]);
0281 
0282   trackerAlignables->addComponent(pixelAlignables[0]);
0283 
0284   edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildPixelDetector"
0285                                         << "Built " << pixelName << "-detector Alignable, consisting of Alignables"
0286                                         << " of " << pxbName << " and " << pxeName;
0287 }
0288 
0289 //_____________________________________________________________________________
0290 void AlignableTrackerBuilder ::buildStripDetector(AlignableTracker* trackerAlignables) {
0291   const std::string& tibName = alignableObjectId_.idToString(align::TIBBarrel);
0292   const std::string& tidName = alignableObjectId_.idToString(align::TIDEndcap);
0293   const std::string& tobName = alignableObjectId_.idToString(align::TOBBarrel);
0294   const std::string& tecName = alignableObjectId_.idToString(align::TECEndcap);
0295   const std::string& stripName = alignableObjectId_.idToString(align::Strip);
0296 
0297   auto& tibAlignables = alignableMap_->find(tibName);
0298   auto& tidAlignables = alignableMap_->find(tidName);
0299   auto& tobAlignables = alignableMap_->find(tobName);
0300   auto& tecAlignables = alignableMap_->find(tecName);
0301   auto& stripAlignables = alignableMap_->get(stripName);
0302 
0303   stripAlignables.push_back(new AlignableComposite(tibAlignables[0]->id(), align::Strip, align::RotationType()));
0304 
0305   stripAlignables[0]->addComponent(tibAlignables[0]);
0306   stripAlignables[0]->addComponent(tidAlignables[0]);
0307   stripAlignables[0]->addComponent(tidAlignables[1]);
0308   stripAlignables[0]->addComponent(tobAlignables[0]);
0309   stripAlignables[0]->addComponent(tecAlignables[0]);
0310   stripAlignables[0]->addComponent(tecAlignables[1]);
0311 
0312   trackerAlignables->addComponent(stripAlignables[0]);
0313 
0314   edm::LogInfo("AlignableBuildProcess") << "@SUB=AlignableTrackerBuilder::buildStripDetector"
0315                                         << "Built " << stripName << "-detector Alignable, consisting of Alignables"
0316                                         << " of " << tibName << ", " << tidName << ", " << tobName << " and "
0317                                         << tecName;
0318 }