Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2023-10-25 10:02:29

0001 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
0002 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0003 #include "DataFormats/TrackerCommon/interface/TrackerDetSide.h"
0004 #include "Geometry/TrackerGeometryBuilder/interface/TrackerGeometry.h"
0005 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
0006 #include "RecoTracker/MkFit/interface/MkFitGeometry.h"
0007 
0008 #include "RecoTracker/MkFitCMS/interface/LayerNumberConverter.h"
0009 #include "RecoTracker/MkFitCore/interface/TrackerInfo.h"
0010 
0011 namespace {
0012   bool isPlusSide(const TrackerTopology& ttopo, DetId detid) {
0013     return ttopo.side(detid) == static_cast<unsigned>(TrackerDetSide::PosEndcap);
0014   }
0015 }  // namespace
0016 
0017 MkFitGeometry::MkFitGeometry(const TrackerGeometry& geom,
0018                              const GeometricSearchTracker& tracker,
0019                              const TrackerTopology& ttopo,
0020                              std::unique_ptr<mkfit::TrackerInfo> trackerInfo,
0021                              const mkfit::LayerNumberConverter& layNConv)
0022     : ttopo_(&ttopo),
0023       lnc_{std::make_unique<mkfit::LayerNumberConverter>(layNConv)},
0024       trackerInfo_(std::move(trackerInfo)) {
0025   if (lnc_->getEra() != mkfit::TkLayout::phase1 && lnc_->getEra() != mkfit::TkLayout::phase2)
0026     throw cms::Exception("Assert") << "This code works only with phase1 and phase2 tracker, you have something else";
0027 
0028   // Create DetLayer structure
0029   dets_.resize(lnc_->nLayers(), nullptr);
0030   auto setDet = [this](const int subdet, const int layer, const int isStereo, const DetId& detId, const DetLayer* lay) {
0031     const int index = lnc_->convertLayerNumber(subdet, layer, false, isStereo, isPlusSide(*ttopo_, detId));
0032     if (index < 0 or static_cast<unsigned>(index) >= dets_.size()) {
0033       throw cms::Exception("LogicError") << "Invalid mkFit layer index " << index << " for DetId " << detId.rawId()
0034                                          << " subdet " << subdet << " layer " << layer << " isStereo " << isStereo;
0035     }
0036     dets_[index] = lay;
0037   };
0038   constexpr int monoLayer = 0;
0039   constexpr int stereoLayer = 1;
0040   for (const DetLayer* lay : tracker.allLayers()) {
0041     const auto& comp = lay->basicComponents();
0042     if (UNLIKELY(comp.empty())) {
0043       throw cms::Exception("LogicError") << "Got a tracker layer (subdet " << lay->subDetector()
0044                                          << ") with empty basicComponents.";
0045     }
0046     // First component is enough for layer and side information
0047     const auto& detId = comp.front()->geographicalId();
0048     const auto subdet = detId.subdetId();
0049     const auto layer = ttopo.layer(detId);
0050 
0051     setDet(subdet, layer, monoLayer, detId, lay);
0052     if (lnc_->doesHaveStereo(subdet, layer))
0053       setDet(subdet, layer, stereoLayer, detId, lay);
0054   }
0055 }
0056 
0057 // Explicit out-of-line because of the mkfit::LayerNumberConverter is
0058 // only forward declared in the header
0059 MkFitGeometry::~MkFitGeometry() {}
0060 
0061 int MkFitGeometry::mkFitLayerNumber(DetId detId) const {
0062   return lnc_->convertLayerNumber(
0063       detId.subdetId(), ttopo_->layer(detId), false, ttopo_->isStereo(detId), isPlusSide(*ttopo_, detId));
0064 }