Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:28:13

0001 #ifndef RecoTracker_MkFit_plugins_convertHits_h
0002 #define RecoTracker_MkFit_plugins_convertHits_h
0003 
0004 #include "DataFormats/Provenance/interface/ProductID.h"
0005 
0006 #include "FWCore/Utilities/interface/Likely.h"
0007 
0008 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
0009 #include "DataFormats/TrackerCommon/interface/TrackerDetSide.h"
0010 
0011 #include "TrackingTools/TransientTrackingRecHit/interface/TransientTrackingRecHitBuilder.h"
0012 
0013 #include "RecoTracker/MkFit/interface/MkFitGeometry.h"
0014 
0015 // ROOT
0016 #include "Math/SVector.h"
0017 #include "Math/SMatrix.h"
0018 
0019 // mkFit includes
0020 #include "RecoTracker/MkFitCore/interface/Hit.h"
0021 #include "RecoTracker/MkFitCore/interface/HitStructures.h"
0022 
0023 namespace mkfit {
0024   template <typename Traits, typename HitCollection>
0025   edm::ProductID convertHits(const Traits& traits,
0026                              const HitCollection& hits,
0027                              mkfit::HitVec& mkFitHits,
0028                              std::vector<TrackingRecHit const*>& clusterIndexToHit,
0029                              std::vector<float>& clusterChargeVec,
0030                              const TrackerTopology& ttopo,
0031                              const TransientTrackingRecHitBuilder& ttrhBuilder,
0032                              const MkFitGeometry& mkFitGeom) {
0033     if (hits.empty())
0034       return edm::ProductID{};
0035 
0036     edm::ProductID clusterID;
0037     {
0038       const auto& lastClusterRef = hits.data().back().firstClusterRef();
0039       clusterID = lastClusterRef.id();
0040       if (lastClusterRef.index() >= mkFitHits.size()) {
0041         auto const size = lastClusterRef.index();
0042         mkFitHits.resize(size);
0043         clusterIndexToHit.resize(size, nullptr);
0044         if constexpr (Traits::applyCCC()) {
0045           clusterChargeVec.resize(size, -1.f);
0046         }
0047       }
0048     }
0049 
0050     for (const auto& detset : hits) {
0051       const DetId detid = detset.detId();
0052       const auto ilay = mkFitGeom.mkFitLayerNumber(detid);
0053 
0054       for (const auto& hit : detset) {
0055         const auto charge = traits.clusterCharge(hit, detid);
0056         if (!traits.passCCC(charge))
0057           continue;
0058 
0059         const auto& gpos = hit.globalPosition();
0060         SVector3 pos(gpos.x(), gpos.y(), gpos.z());
0061         const auto& gerr = hit.globalPositionError();
0062         SMatrixSym33 err;
0063         err.At(0, 0) = gerr.cxx();
0064         err.At(1, 1) = gerr.cyy();
0065         err.At(2, 2) = gerr.czz();
0066         err.At(0, 1) = gerr.cyx();
0067         err.At(0, 2) = gerr.czx();
0068         err.At(1, 2) = gerr.czy();
0069 
0070         auto clusterRef = hit.firstClusterRef();
0071         if UNLIKELY (clusterRef.id() != clusterID) {
0072           throw cms::Exception("LogicError")
0073               << "Input hit collection has Refs to many cluster collections. Last hit had Ref to product " << clusterID
0074               << ", but encountered Ref to product " << clusterRef.id() << " on detid " << detid.rawId();
0075         }
0076         const auto clusterIndex = clusterRef.index();
0077         LogTrace("MkFitHitConverter") << "Adding hit detid " << detid.rawId() << " subdet " << detid.subdetId()
0078                                       << " layer " << ttopo.layer(detid) << " isStereo " << ttopo.isStereo(detid)
0079                                       << " zplus "
0080                                       << " index " << clusterIndex << " ilay " << ilay;
0081 
0082         if UNLIKELY (clusterIndex >= mkFitHits.size()) {
0083           mkFitHits.resize(clusterIndex + 1);
0084           clusterIndexToHit.resize(clusterIndex + 1, nullptr);
0085           if constexpr (Traits::applyCCC()) {
0086             clusterChargeVec.resize(clusterIndex + 1, -1.f);
0087           }
0088         }
0089         mkFitHits[clusterIndex] = mkfit::Hit(pos, err);
0090         clusterIndexToHit[clusterIndex] = &hit;
0091         if constexpr (Traits::applyCCC()) {
0092           clusterChargeVec[clusterIndex] = charge;
0093         }
0094 
0095         const auto uniqueIdInLayer = mkFitGeom.uniqueIdInLayer(ilay, detid.rawId());
0096         traits.setDetails(mkFitHits[clusterIndex], *(hit.cluster()), uniqueIdInLayer, charge);
0097       }
0098     }
0099     return clusterID;
0100   }
0101 }  // namespace mkfit
0102 
0103 #endif