File indexing completed on 2025-01-18 03:42:17
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
0016 #include "Math/SVector.h"
0017 #include "Math/SMatrix.h"
0018
0019
0020 #include "RecoTracker/MkFitCore/interface/Hit.h"
0021 #include "RecoTracker/MkFitCore/interface/HitStructures.h"
0022
0023 namespace mkfit {
0024 template <typename Traits, typename HitCollection, typename ClusterCollection>
0025 edm::ProductID convertHits(const Traits& traits,
0026 const HitCollection& hits,
0027 const ClusterCollection& clusters,
0028 mkfit::HitVec& mkFitHits,
0029 std::vector<TrackingRecHit const*>& clusterIndexToHit,
0030 std::vector<int>& layerIndexToHit,
0031 std::vector<float>& clusterChargeVec,
0032 const TrackerTopology& ttopo,
0033 const TransientTrackingRecHitBuilder& ttrhBuilder,
0034 const MkFitGeometry& mkFitGeom,
0035 std::size_t maxSizeGuess = 0) {
0036 if (hits.empty())
0037 return edm::ProductID{};
0038
0039 const auto& lastClusterRef = hits.data().back().firstClusterRef();
0040 edm::ProductID clusterID = lastClusterRef.id();
0041 auto const size = std::max(static_cast<std::size_t>(lastClusterRef.index() + 1), maxSizeGuess);
0042 if (mkFitHits.size() < size) {
0043 mkFitHits.resize(size);
0044 clusterIndexToHit.resize(size, nullptr);
0045 layerIndexToHit.resize(size, -1);
0046 if constexpr (Traits::applyCCC()) {
0047 clusterChargeVec.resize(size, -1.f);
0048 }
0049 }
0050
0051 for (const auto& detset : hits) {
0052 if (detset.empty())
0053 continue;
0054 const DetId detid = detset.detId();
0055 const auto ilay = mkFitGeom.mkFitLayerNumber(detid);
0056 const auto uniqueIdInLayer = mkFitGeom.uniqueIdInLayer(ilay, detid.rawId());
0057 const auto chargeScale = traits.chargeScale(detid);
0058 const auto& surf = detset.begin()->det()->surface();
0059
0060 for (const auto& hit : detset) {
0061 auto clusterRef = hit.firstClusterRef();
0062 if UNLIKELY (clusterRef.id() != clusterID) {
0063 throw cms::Exception("LogicError")
0064 << "Input hit collection has Refs to many cluster collections. Last hit had Ref to product " << clusterID
0065 << ", but encountered Ref to product " << clusterRef.id() << " on detid " << detid.rawId();
0066 }
0067 const auto clusterIndex = clusterRef.index();
0068
0069 const auto& clu = traits.cluster(clusters, clusterIndex);
0070 const auto charge = traits.clusterCharge(clu, chargeScale);
0071 if (!traits.passCCC(charge))
0072 continue;
0073
0074 const auto& gpos = surf.toGlobal(hit.localPosition());
0075 SVector3 pos(gpos.x(), gpos.y(), gpos.z());
0076 const auto& gerr = ErrorFrameTransformer::transform(hit.localPositionError(), surf);
0077 SMatrixSym33 err{{float(gerr.cxx()),
0078 float(gerr.cyx()),
0079 float(gerr.cyy()),
0080 float(gerr.czx()),
0081 float(gerr.czy()),
0082 float(gerr.czz())}};
0083
0084 LogTrace("MkFitHitConverter") << "Adding hit detid " << detid.rawId() << " subdet " << detid.subdetId()
0085 << " layer " << ttopo.layer(detid) << " isStereo " << ttopo.isStereo(detid)
0086 << " zplus "
0087 << " index " << clusterIndex << " ilay " << ilay;
0088
0089 if UNLIKELY (clusterIndex >= mkFitHits.size()) {
0090 mkFitHits.resize(clusterIndex + 1);
0091 clusterIndexToHit.resize(clusterIndex + 1, nullptr);
0092 layerIndexToHit.resize(clusterIndex + 1, -1);
0093 if constexpr (Traits::applyCCC()) {
0094 clusterChargeVec.resize(clusterIndex + 1, -1.f);
0095 }
0096 }
0097 mkFitHits[clusterIndex] = mkfit::Hit(pos, err);
0098 clusterIndexToHit[clusterIndex] = &hit;
0099 layerIndexToHit[clusterIndex] = ilay;
0100 if constexpr (Traits::applyCCC()) {
0101 clusterChargeVec[clusterIndex] = charge;
0102 }
0103
0104 traits.setDetails(mkFitHits[clusterIndex], clu, uniqueIdInLayer, charge);
0105 }
0106 }
0107 return clusterID;
0108 }
0109 }
0110
0111 #endif