From a99796ddb1e590e18e60c68f2a8ffdf7184e22db Mon Sep 17 00:00:00 2001 From: delano campos Date: Fri, 13 Mar 2026 13:20:32 -0500 Subject: [PATCH 01/29] bitshift bug fix KMTF.cc --- L1Trigger/Phase2L1GMT/src/KMTF.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTF.cc b/L1Trigger/Phase2L1GMT/src/KMTF.cc index 918554895b131..1cb40bc1c72b4 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTF.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTF.cc @@ -77,7 +77,7 @@ std::pair, std::vector > KMTF::proce for (unsigned int i = 0; i < 32; ++i) { //print the stubs taking into account - bool patterns = pre_patterns && ((i < Nstubs4) || (i < Nstubs3) || (i << Nstubs2)); + bool patterns = pre_patterns && ((i < Nstubs4) || (i < Nstubs3) || (i < Nstubs2)); if (patterns) { edm::LogInfo("KMTF") << "KMTFPattern " << std::flush; From 584d7061c9ad538caf3b168746ad63e8fca0a6f2 Mon Sep 17 00:00:00 2001 From: delano campos Date: Fri, 13 Mar 2026 13:20:52 -0500 Subject: [PATCH 02/29] New typedef for 5 dimensional covariance matrix KMTFTrack now requires z, kSlope as arguments added z, kSlope members and accessors setCoordinates, setCovariance now require arguments z, kSlope --- .../L1TMuonPhase2/interface/KMTFTrack.h | 33 ++++++++++++++++--- 1 file changed, 28 insertions(+), 5 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h index 7e6197eea6d9e..1aa4ca819a282 100644 --- a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h +++ b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h @@ -10,13 +10,14 @@ namespace l1t { class KMTFTrack; typedef std::vector KMTFTrackCollection; typedef BXVector KMTFTrackBxCollection; + typedef math::Error<5>::type CovarianceMatrix5dim; class KMTFTrack : public reco::LeafCandidate { public: KMTFTrack() : reco::LeafCandidate(-1, reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), unconstrainedP4_(reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), - covariance_(std::vector(6, 0.0)), + covariance_(std::vector(15, 0.0)), curvVertex_(0), ptC_(0), phiVertex_(0), @@ -28,6 +29,8 @@ namespace l1t { curv_(0), phi_(0), phiB_(0), + z_(0), + kSlope_(0), coarseEta_(0), approxPromptChi2_(0), approxPromptErrChi2_(0), @@ -46,10 +49,10 @@ namespace l1t { ~KMTFTrack() override = default; - KMTFTrack(const l1t::MuonStubRef& seed, int phi, int phiB) + KMTFTrack(const l1t::MuonStubRef& seed, int phi, int phiB, int z, int kSlope) : reco::LeafCandidate(-1, reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), unconstrainedP4_(reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), - covariance_(std::vector(6, 0.0)), + covariance_(std::vector(15, 0.0)), curvVertex_(0), ptC_(0), phiVertex_(0), @@ -61,6 +64,8 @@ namespace l1t { curv_(0), phi_(phi), phiB_(phiB), + z_(z), + kSlope_(kSlope), coarseEta_(0), approxPromptChi2_(0), approxPromptErrChi2_(0), @@ -107,6 +112,10 @@ namespace l1t { int positionAngle() const { return phi_; } //Unconstrained bending angle at the Muon systen int bendingAngle() const { return phiB_; } + + //global z and slope of stub + int zPosition() const {return z_;} + int kSlope() const {return kSlope_;} //Coarse eta caluclated only using phi segments int coarseEta() const { return coarseEta_; } //Approximate Chi2 metrics @@ -188,11 +197,13 @@ namespace l1t { } //Set coordinates general - void setCoordinates(int step, int curv, int phi, int phiB) { + void setCoordinates(int step, int curv, int phi, int phiB, int z, int kSlope) { step_ = step; curv_ = curv; phiB_ = phiB; phi_ = phi; + z_ = z; + kSlope_ = kSlope; } void setCoordinatesAtVertex(int curv, int phi, int dxy) { @@ -306,13 +317,23 @@ namespace l1t { } //set covariance - void setCovariance(const CovarianceMatrix& c) { + void setCovariance(const CovarianceMatrix5dim& c) { covariance_[0] = c(0, 0); covariance_[1] = c(0, 1); covariance_[2] = c(1, 1); covariance_[3] = c(0, 2); covariance_[4] = c(1, 2); covariance_[5] = c(2, 2); + covariance_[6] = c(0, 3); + covariance_[7] = c(1, 3); + covariance_[8] = c(2, 3); + covariance_[9] = c(3, 3); + covariance_[10] = c(0, 4); + covariance_[11] = c(1, 4); + covariance_[12] = c(2, 4); + covariance_[13] = c(3, 4); + covariance_[14] = c(4, 4); + } //set fine eta @@ -347,6 +368,8 @@ namespace l1t { int curv_; int phi_; int phiB_; + int z_; + int kSlope_; //common coordinates int coarseEta_; From 76a32a885c2b0283586e738dd187697deb19cede Mon Sep 17 00:00:00 2001 From: delano campos Date: Fri, 13 Mar 2026 13:23:46 -0500 Subject: [PATCH 03/29] new class version for KMTFTrack.h update version 4. --- DataFormats/L1TMuonPhase2/src/classes_def.xml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/DataFormats/L1TMuonPhase2/src/classes_def.xml b/DataFormats/L1TMuonPhase2/src/classes_def.xml index 3af19882e9fc8..388e3e68621c7 100644 --- a/DataFormats/L1TMuonPhase2/src/classes_def.xml +++ b/DataFormats/L1TMuonPhase2/src/classes_def.xml @@ -25,7 +25,8 @@ - + + From e98e4a98f059a0d90d963bd88dda70e90daaaccb Mon Sep 17 00:00:00 2001 From: delano campos Date: Fri, 13 Mar 2026 14:01:22 -0500 Subject: [PATCH 04/29] initial development commits --- L1Trigger/Phase2L1GMT/interface/KMTFCore.h | 20 + .../L1TPhase2GMTBarrelStubProcessor.h | 5 +- .../plugins/Phase2L1TGMTStubProducer.cc | 20 +- .../Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 5 + L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py | 3 +- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 369 +++++++++++------- .../src/L1TPhase2GMTBarrelStubProcessor.cc | 101 +++-- 7 files changed, 346 insertions(+), 177 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h index 19291d1f53031..a86c526b5daf0 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h @@ -16,12 +16,23 @@ namespace Phase2L1GMT { class KMTFCore { public: typedef ROOT::Math::SVector Vector2; + typedef ROOT::Math::SVector Vector3; + typedef ROOT::Math::SVector Vector4; typedef ROOT::Math::SMatrix > CovarianceMatrix2; + typedef ROOT::Math::SMatrix > CovarianceMatrix3; + typedef ROOT::Math::SMatrix > CovarianceMatrix4; typedef ROOT::Math::SMatrix Matrix32; + typedef ROOT::Math::SMatrix Matrix53; typedef ROOT::Math::SMatrix Matrix23; + typedef ROOT::Math::SMatrix Matrix45; + typedef ROOT::Math::SMatrix Matrix54; typedef ROOT::Math::SMatrix Matrix13; + typedef ROOT::Math::SMatrix Matrix35; typedef ROOT::Math::SMatrix Matrix31; typedef ROOT::Math::SMatrix Matrix33; + typedef ROOT::Math::SMatrix Matrix55; + typedef ROOT::Math::SMatrix Matrix15; + typedef ROOT::Math::SMatrix Matrix51; KMTFCore(const edm::ParameterSet& settings); @@ -138,8 +149,13 @@ namespace Phase2L1GMT { /////////////////////////////////////////////////////// bool useOfflineAlgo_; + //used for z propagation + std::vector zdeltaR_; + //multiple scattering constants used in multiple scattering matrix to build RMS values std::vector mScatteringPhi_; std::vector mScatteringPhiB_; + std::vector mScatteringz_; + std::vector mScatteringkSlope_; //point resolution for phi double pointResolutionPhi_; //point resolution for phiB @@ -149,6 +165,10 @@ namespace Phase2L1GMT { //double pointResolutionPhiB_; //point resolution for vertex double pointResolutionVertex_; + // point resolution for z + std::vector pointResolutionz_; + // point resolution for kSlope + std::vector pointResolutionkSlope_; std::vector curvResolution1_; std::vector curvResolution2_; //Sorter diff --git a/L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h b/L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h index 81607c571c702..1e381de6f2d09 100644 --- a/L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h +++ b/L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h @@ -5,6 +5,8 @@ #include "DataFormats/L1DTTrackFinder/interface/L1Phase2MuDTPhContainer.h" #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThDigi.h" #include "DataFormats/L1DTTrackFinder/interface/L1MuDTChambThContainer.h" +#include "DataFormats/L1DTTrackFinder/interface/L1Phase2MuDTExtPhiThetaPair.h" +#include "DataFormats/L1DTTrackFinder/interface/L1Phase2MuDTExtPhiThetaPairContainer.h" #include "DataFormats/L1TMuonPhase2/interface/MuonStub.h" #include "FWCore/ParameterSet/interface/ParameterSet.h" #include "CondFormats/L1TObjects/interface/L1TMuonBarrelParams.h" @@ -17,9 +19,10 @@ class L1TPhase2GMTBarrelStubProcessor { ~L1TPhase2GMTBarrelStubProcessor(); - l1t::MuonStubCollection makeStubs(const L1Phase2MuDTPhContainer*, const L1MuDTChambThContainer*); + l1t::MuonStubCollection makeStubs(const L1Phase2MuDTExtPhiThetaPairContainer*); private: + l1t::MuonStub buildStubwithZandK(const L1Phase2MuDTExtPhiThetaPair&); l1t::MuonStub buildStub(const L1Phase2MuDTPhDigi&, const L1MuDTChambThDigi*); l1t::MuonStub buildStubNoEta(const L1Phase2MuDTPhDigi&); diff --git a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc index 26f995f14c839..c3dc3b4ca1f51 100644 --- a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc +++ b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc @@ -11,6 +11,8 @@ #include "L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTEndcapStubProcessor.h" #include "L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h" +#include "DataFormats/L1DTTrackFinder/interface/L1Phase2MuDTExtPhiThetaPairContainer.h" + #include "FWCore/Framework/interface/EventSetup.h" #include "FWCore/Framework/interface/ConsumesCollector.h" #include "FWCore/Framework/interface/ESProducts.h" @@ -32,8 +34,7 @@ class Phase2L1TGMTStubProducer : public edm::stream::EDProducer<> { void endStream() override; l1t::MuonStub convertToHybrid(const l1t::MuonStub& stub); edm::EDGetTokenT> srcCSC_; - edm::EDGetTokenT srcDT_; - edm::EDGetTokenT srcDTTheta_; + edm::EDGetTokenT srcDTPairs_; edm::EDGetTokenT srcRPC_; L1TPhase2GMTEndcapStubProcessor* procEndcap_; @@ -45,8 +46,7 @@ class Phase2L1TGMTStubProducer : public edm::stream::EDProducer<> { Phase2L1TGMTStubProducer::Phase2L1TGMTStubProducer(const edm::ParameterSet& iConfig) : srcCSC_( consumes>(iConfig.getParameter("srcCSC"))), - srcDT_(consumes(iConfig.getParameter("srcDT"))), - srcDTTheta_(consumes(iConfig.getParameter("srcDTTheta"))), + srcDTPairs_(consumes(iConfig.getParameter("srcDTPairs"))), srcRPC_(consumes(iConfig.getParameter("srcRPC"))), procEndcap_(new L1TPhase2GMTEndcapStubProcessor(iConfig.getParameter("Endcap"))), procBarrel_(new L1TPhase2GMTBarrelStubProcessor(iConfig.getParameter("Barrel"))), @@ -101,11 +101,8 @@ void Phase2L1TGMTStubProducer::produce(edm::Event& iEvent, const edm::EventSetup Handle rpcDigis; iEvent.getByToken(srcRPC_, rpcDigis); - Handle dtDigis; - iEvent.getByToken(srcDT_, dtDigis); - - Handle dtThetaDigis; - iEvent.getByToken(srcDTTheta_, dtThetaDigis); + Handle dtPairs; + iEvent.getByToken(srcDTPairs_, dtPairs); //Generate a unique stub ID l1t::MuonStubCollection stubs; @@ -115,7 +112,7 @@ void Phase2L1TGMTStubProducer::produce(edm::Event& iEvent, const edm::EventSetup for (auto& stub : stubsEndcap) { stubs.push_back(stub); } - l1t::MuonStubCollection stubsBarrel = procBarrel_->makeStubs(dtDigis.product(), dtThetaDigis.product()); + l1t::MuonStubCollection stubsBarrel = procBarrel_->makeStubs(dtPairs.product()); for (auto& stub : stubsBarrel) { //convert to Hybrid stubs.push_back(convertToHybrid(stub)); @@ -137,8 +134,7 @@ void Phase2L1TGMTStubProducer::fillDescriptions(edm::ConfigurationDescriptions& edm::ParameterSetDescription desc; desc.add("verbose", 0); desc.add("srcCSC", edm::InputTag("simCscTriggerPrimitiveDigis")); - desc.add("srcDT", edm::InputTag("dtTriggerPhase2PrimitiveDigis")); - desc.add("srcDTTheta", edm::InputTag("simDtTriggerPrimitiveDigis")); + desc.add("srcDTPairs", edm::InputTag("dtTriggerPhase2PrimitivePairDigis")); desc.add("srcRPC", edm::InputTag("simMuonRPCDigis")); { edm::ParameterSetDescription psd0; diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index b328e18adac84..f9836b23463a0 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -13,6 +13,7 @@ aPhi = cms.vdouble(5.6533349391874275, 0.03477876333443834, 0.032506522838098864, 0.024752809174909053), aPhiB = cms.vdouble(-2.02, -0.2994087741381382, -0.4033668521165302, -0.3592231728688621), + zdeltaR = cms.vdouble(445.0, 526.0-445.0, 635.0-526.0, 744.0-635.0), aPhiBNLO = cms.vdouble(9.04133e-05,0,0,0), bPhi = cms.vdouble(-1,.18245,.20898,.17286), @@ -58,11 +59,15 @@ ###Only for the offline algo -not in firmware -------------------- mScatteringPhi = cms.vdouble(0.1169021113298598, 0.00016777763395543814, 0.0004322078772344548, 0.00024985881710722107), mScatteringPhiB = cms.vdouble(.0522762, 0.01762000062188365, 0.03508319015441297, 0.03126825551530328), + mScatteringz = cms.vdouble(0.030625, 0.00010609, 0.00033489, 0.00033489), + mScatteringkSlope = cms.vdouble(0.030625, 0.00010609, 0.00033489, 0.00033489), pointResolutionPhi = cms.double(1.), pointResolutionPhiB = cms.double(12493.7429036), pointResolutionPhiBH = cms.vdouble(19925.62953113343, 15583.06791339368, 10258.11768352221, 15462.112839170433), pointResolutionPhiBL = cms.vdouble(161519.85395846734, 155051.58394241595, 149693.88179343447, 174896.46766622085), pointResolutionVertex = cms.double(1.), + pointResolutionz = cms.vdouble(214369, 9980.01, 9254.44, 9254.44), + pointResolutionkSlope = cms.vdouble(214369, 9980.01, 9254.44, 9254.44), curvResolution1 = cms.vdouble(1, 2.36097e+03, 8.73003e+02, 2.58138e5), curvResolution2 = cms.vdouble(1, 4.903692e+00, 4.87941e+01, 0)), Nprompt = cms.uint32(12), diff --git a/L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py index 1e4f32896bc7f..c8eabb59583e3 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py @@ -3,8 +3,7 @@ gmtStubs = cms.EDProducer("Phase2L1TGMTStubProducer", verbose = cms.int32(0), srcCSC = cms.InputTag("simCscTriggerPrimitiveDigis"), - srcDT = cms.InputTag("dtTriggerPhase2PrimitiveDigis"), - srcDTTheta = cms.InputTag("simDtTriggerPrimitiveDigis"), + srcDTPairs = cms.InputTag("dtTriggerPhase2PrimitivePairDigis"), srcRPC = cms.InputTag("simMuonRPCDigis"), Endcap =cms.PSet( verbose = cms.uint32(0), diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index fcbca8ba7284c..75a38d976fafe 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -47,13 +47,18 @@ KMTFCore::KMTFCore(const edm::ParameterSet& settings) combos1_(settings.getParameter >("combos1")), useOfflineAlgo_(settings.getParameter("useOfflineAlgo")), + zdeltaR_(settings.getParameter >("zdeltaR")), mScatteringPhi_(settings.getParameter >("mScatteringPhi")), mScatteringPhiB_(settings.getParameter >("mScatteringPhiB")), + mScatteringz_(settings.getParameter >("mScatteringz")), + mScatteringkSlope_(settings.getParameter >("mScatteringkSlope")), pointResolutionPhi_(settings.getParameter("pointResolutionPhi")), pointResolutionPhiB_(settings.getParameter("pointResolutionPhiB")), pointResolutionPhiBH_(settings.getParameter >("pointResolutionPhiBH")), pointResolutionPhiBL_(settings.getParameter >("pointResolutionPhiBL")), pointResolutionVertex_(settings.getParameter("pointResolutionVertex")), + pointResolutionz_(settings.getParameter >("pointResolutionz")), + pointResolutionkSlope_(settings.getParameter >("pointResolutionkSlope")), curvResolution1_(settings.getParameter >("curvResolution1")), curvResolution2_(settings.getParameter >("curvResolution2")) {} @@ -79,10 +84,10 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef throw cms::Exception("KMTFCore") << "Something really bad happend\n"; } - l1t::KMTFTrack nullTrack(seed, seed->coord1(), correctedPhiB(seed)); + l1t::KMTFTrack nullTrack(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), seed->eta2()); seedQual = seed->quality(); for (const auto& mask : combinatorics) { - l1t::KMTFTrack track(seed, seed->coord1(), correctedPhiB(seed)); + l1t::KMTFTrack track(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), seed->eta2()); int phiB = correctedPhiB(seed); int charge; if (phiB == 0) @@ -103,16 +108,16 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef initialK = pow(2, BITSCURV - 1) - 1; if (initialK <= -pow(2, BITSCURV - 1)) initialK = -pow(2, BITSCURV - 1) + 1; - track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), phiB); + track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), phiB, seed->eta1(), seed->eta2()); if (seed->quality() < 6) { - track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0); + track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), seed->eta2()); } if (verbose_) { edm::LogInfo("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK; } track.setHitPattern(hitPattern(track)); //set covariance - l1t::KMTFTrack::CovarianceMatrix covariance; + l1t::CovarianceMatrix5dim covariance; float DK = curvResolution1_[track.step() - 1] + curvResolution2_[track.step() - 1] * initialK * initialK; if (seed->quality() < 6) DK = pow(2, 22); @@ -134,6 +139,8 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef else covariance(2, 2) = float(pointResolutionPhiBH_[seed->depthRegion() - 1]); } + covariance(3,3) = float(pointResolutionz_[seed->depthRegion() - 1]); + covariance(4,4) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); track.setCovariance(covariance); // @@ -429,6 +436,8 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { int phi = track.positionAngle(); int phiB = track.bendingAngle(); unsigned int step = track.step(); + int z = track.zPosition(); + int kSlope = track.kSlope(); int charge = 1; if (K != 0) @@ -503,42 +512,76 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { //Rest of the stuff is for the offline version only //where we want to check what is happening in the covariance matrix + //z and kSlope propagation offline studies + //zdeltaR are in phyiscal units. convert for the propagation of z. + constexpr double ZRES_CONV = 65536. / 1500.; + constexpr double KRES_CONV = 65536. / 2. ; + constexpr double zdR_CONV = ZRES_CONV / KRES_CONV ; + double zdeltaR_dig = zdeltaR_[step - 1] * zdR_CONV ; + int kSlopeNew = kSlope; + int zNew = z + (int)(kSlope * zdeltaR_dig); + + //Create the transformation matrix - double a[9]; - a[0] = 1.; + double a[25]; + a[0] = 1.0; a[1] = 0.0; a[2] = 0.0; - a[3] = aPhi_[step - 1]; - // a[3] = 0.0; - a[4] = 1.0; - a[5] = -bPhi_[step - 1]; - //a[6]=0.0; - a[6] = aPhiB_[step - 1]; + a[3] = 0.0; + a[4] = 0.0; + a[5] = aPhi_[step - 1]; + a[6] = 1.0; + a[7] = -bPhi_[step - 1]; + a[8] = 0.0; + a[9] = 0.0; + a[10] = aPhiB_[step - 1]; if (step == 1) - a[6] = aPhiB_[step - 1] / 2.0; - - a[7] = 0.0; - a[8] = bPhiB_[step - 1]; - - ROOT::Math::SMatrix P(a, 9); + a[10] = aPhiB_[step - 1] / 2.0; + a[11] = 0.0; + a[12] = bPhiB_[step - 1]; + a[13] = 0.0; + a[14] = 0.0; + a[15] = 0.0; + a[16] = 0.0; + a[17] = 0.0; + a[18] = 1.0; + a[19] = zdeltaR_dig; + a[20] = 0.0; + a[21] = 0.0; + a[22] = 0.0; + a[23] = 0.0; + a[24] = 1.0; + + ROOT::Math::SMatrix P(a, 25); const std::vector& covLine = track.covariance(); - l1t::KMTFTrack::CovarianceMatrix cov(covLine.begin(), covLine.end()); + l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); cov = ROOT::Math::Similarity(P, cov); //Add the multiple scattering double phiRMS = mScatteringPhi_[step - 1] * K * K; double phiBRMS = mScatteringPhiB_[step - 1] * K * K; + double zRMS = mScatteringz_[step - 1] * K * K ; + double kSlopeRMS = mScatteringkSlope_[step - 1] * K * K; - std::vector b(6); + std::vector b(15); b[0] = 0; b[1] = 0; b[2] = phiRMS; b[3] = 0; b[4] = 0; b[5] = phiBRMS; - - reco::Candidate::CovarianceMatrix MS(b.begin(), b.end()); + b[6] = 0; + b[7] = 0; + b[8] = 0; + b[9] = zRMS; + b[10] = 0; + b[11] = 0; + b[12] = 0; + b[13] = 0; + b[14] = kSlopeRMS; + + l1t::CovarianceMatrix5dim MS(b.begin(), b.end()); cov = cov + MS; @@ -548,7 +591,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { } track.setCovariance(cov); - track.setCoordinates(step - 1, KNew, phiNew, phiBNew); + track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); } bool KMTFCore::update(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, int mask, int seedQual) { @@ -567,45 +610,71 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int trackK = track.curvature(); int trackPhi = track.positionAngle(); int trackPhiB = track.bendingAngle(); + int trackz = track.zPosition(); + int trackSlope = track.kSlope(); int phi = stub->coord1(); int phiB = correctedPhiB(stub); + int z = stub->eta1(); + int kSlope = stub->eta2(); - Vector2 residual; + Vector4 residual; residual[0] = ap_fixed(phi - trackPhi); residual[1] = phiB - trackPhiB; + residual[2] = z - trackz; + residual[3] = kSlope - trackSlope; - Matrix23 H; + Matrix45 H; H(0, 0) = 0.0; H(0, 1) = 1.0; H(0, 2) = 0.0; + H(0, 3) = 0.0; + H(0, 4) = 0.0; H(1, 0) = 0.0; H(1, 1) = 0.0; H(1, 2) = 1.0; + H(1, 3) = 0.0; + H(1, 4) = 0.0; + H(2, 0) = 0.0; + H(2, 1) = 0.0; + H(2, 2) = 0.0; + H(2, 3) = 1.0; + H(2, 4) = 0.0; + H(3, 0) = 0.0; + H(3, 1) = 0.0; + H(3, 2) = 0.0; + H(3, 3) = 0.0; + H(3, 4) = 1.0; const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] : pointResolutionPhiBH_[track.step() - 1]}; - const double r[]{pointResolutionPhi_, 0.0, 0.0, r11}; - const CovarianceMatrix2 R(r, 4); + const double r[]{ + pointResolutionPhi_, 0.0, 0.0, 0.0, + 0.0, r11, 0.0, 0.0, + 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, + 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix4 R(r, 16); const std::vector& covLine = track.covariance(); - const l1t::KMTFTrack::CovarianceMatrix cov(covLine.begin(), covLine.end()); - CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; + const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); + CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - const Matrix32 Gain = cov * ROOT::Math::Transpose(H) * S; + const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; - track.setKalmanGain( - track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), Gain(1, 0), Gain(1, 1), Gain(2, 0), Gain(2, 1)); + //track.setKalmanGain( + //track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), Gain(1, 0), Gain(1, 1), Gain(2, 0), Gain(2, 1)); - int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1))); + int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2) + Gain(0, 3) * residual(3))); if (fabs(KNew) > pow(2, BITSCURV - 1)) return false; int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); + int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); + int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); - track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew)); + track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); if (verbose_) { edm::LogInfo("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << int(residual[0]) << " " << phiB @@ -618,19 +687,14 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub << Gain(2, 1) << " * " << residual(1); } - track.setCoordinates(track.step(), KNew, phiNew, phiBNew); + track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); const auto covNew{cov - Gain * (H * cov)}; - l1t::KMTFTrack::CovarianceMatrix c; - - c(0, 0) = covNew(0, 0); - c(0, 1) = covNew(0, 1); - c(0, 2) = covNew(0, 2); - c(1, 0) = covNew(1, 0); - c(1, 1) = covNew(1, 1); - c(1, 2) = covNew(1, 2); - c(2, 0) = covNew(2, 0); - c(2, 1) = covNew(2, 1); - c(2, 2) = covNew(2, 2); + l1t::CovarianceMatrix5dim c; + + for (int i = 0; i < 5; i++) + for (int j = i; j < 5; j++) + c(i, j) = covNew(i, j); + if (verbose_) { edm::LogInfo("KMTFCore") << "Post Fit Covariance Matrix " << cov(0, 0) << " " << cov(1, 1) << " " << cov(2, 2); } @@ -646,51 +710,76 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int trackK = track.curvature(); int trackPhi = track.positionAngle(); int trackPhiB = track.bendingAngle(); + int trackz = track.zPosition(); + int trackSlope = track.kSlope(); int phi = stub->coord1(); + int z = stub->eta1(); + int kSlope = stub->eta2(); - double residual = ap_fixed(phi - trackPhi); + Vector3 residual; + residual[0] = ap_fixed(phi - trackPhi); + residual[1] = z - trackz; + residual[2] = kSlope - trackSlope; - if (verbose_) - edm::LogInfo("KMTFCore") << "residuals " << phi << " - " << trackPhi << " = " << int(residual); + if (verbose_) { + edm::LogInfo("KMTFCore") << "residual phi" << phi << " - " << trackPhi << " = " << int(residual(0)); + edm::LogInfo("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); + edm::LogInfo("KMTFCore") << "residual kSlope" << kSlope << " - " << trackSlope << " = " << int(residual(2)); + } - Matrix13 H; + Matrix35 H; H(0, 0) = 0.0; H(0, 1) = 1.0; H(0, 2) = 0.0; + H(0, 3) = 0.0; + H(0, 4) = 0.0; + H(1, 0) = 0.0; + H(1, 1) = 0.0; + H(1, 2) = 0.0; + H(1, 3) = 1.0; + H(1, 4) = 0.0; + H(2, 0) = 0.0; + H(2, 1) = 0.0; + H(2, 2) = 0.0; + H(2, 3) = 0.0; + H(2, 4) = 1.0; + + const double r[]{pointResolutionPhi_, 0.0, 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix3 R(r, 9); const std::vector& covLine = track.covariance(); - l1t::KMTFTrack::CovarianceMatrix cov(covLine.begin(), covLine.end()); + l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - double S = ROOT::Math::Similarity(H, cov)(0, 0) + pointResolutionPhi_; - if (S == 0.0) + CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; + if (!S.Invert()) return false; - Matrix31 Gain = cov * ROOT::Math::Transpose(H) / S; + Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; + + //track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, Gain(1, 0), 0.0, Gain(2, 0), 0.0); - track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, Gain(1, 0), 0.0, Gain(2, 0), 0.0); + int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); + int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); + int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); + int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); - int KNew = wrapAround(trackK + int(Gain(0, 0) * residual), pow(2, BITSCURV - 1)); - int phiNew = wrapAround(trackPhi + residual, pow(2, BITSPHI - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual), pow(2, BITSPHIB - 1)); - track.setCoordinates(track.step(), KNew, phiNew, phiBNew); - Matrix33 covNew = cov - Gain * (H * cov); - l1t::KMTFTrack::CovarianceMatrix c; + track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); + Matrix55 covNew = cov - Gain * (H * cov); + l1t::CovarianceMatrix5dim c; if (verbose_) { - edm::LogInfo("KMTFCore") << "phiUpdate: " << int(Gain(0, 0) * residual) << " " << int(Gain(2, 0) * residual); - edm::LogInfo("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual; - edm::LogInfo("KMTFCore") << " phiBNew = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual; + edm::LogInfo("KMTFCore") << "phiUpdate: " << int(Gain(0, 0) * residual(0)) << " " << int(Gain(2, 0) * residual(0)); + edm::LogInfo("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) << " * " << residual(1) << " + " << Gain(0, 2) << " * " << residual(2); + edm::LogInfo("KMTFCore") << " phiBNew = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1) << " + " << Gain(2, 2) << " * " << residual(2); + edm::LogInfo("KMTFCore") << " zNew = " << trackz << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1) << " + " << Gain(2, 2) << " * " << residual(2); + edm::LogInfo("KMTFCore") << " kSlopeNew = " << trackSlope << " + " << Gain(3, 0) << " * " << residual(0) << " + " << Gain(3, 1) << " * " << residual(1) << " + " << Gain(3, 2) << " * " << residual(2); } - c(0, 0) = covNew(0, 0); - c(0, 1) = covNew(0, 1); - c(0, 2) = covNew(0, 2); - c(1, 0) = covNew(1, 0); - c(1, 1) = covNew(1, 1); - c(1, 2) = covNew(1, 2); - c(2, 0) = covNew(2, 0); - c(2, 1) = covNew(2, 1); - c(2, 2) = covNew(2, 2); + for (int i = 0; i < 5; i++) + for (int j = i; j < 5; j++) + c(i, j) = covNew(i, j); + track.setCovariance(c); track.addStub(stub); track.setHitPattern(hitPattern(track)); @@ -794,7 +883,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in if ((phiBNew > (pow(2, BITSPHIB - 1) - 1)) || (phiBNew < (-pow(2, BITSPHIB - 1)))) return false; - track.setCoordinates(track.step(), KNew, phiNew, phiBNew); + track.setCoordinates(track.step(), KNew, phiNew, phiBNew, track.zPosition(), track.kSlope()); track.addStub(stub); track.setHitPattern(hitPattern(track)); if (verbose_) { @@ -813,71 +902,75 @@ void KMTFCore::vertexConstraint(l1t::KMTFTrack& track) { vertexConstraintLUT(track); } -void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track) { - double residual = -track.dxy(); - Matrix13 H; - H(0, 0) = 0; - H(0, 1) = 0; - H(0, 2) = 1; - const std::vector& covLine = track.covariance(); - l1t::KMTFTrack::CovarianceMatrix cov(covLine.begin(), covLine.end()); - - double S = (ROOT::Math::Similarity(H, cov))(0, 0) + pointResolutionVertex_; - S = 1.0 / S; - Matrix31 Gain = cov * (ROOT::Math::Transpose(H)) * S; - track.setKalmanGain(track.step(), fabs(track.curvature()), Gain(0, 0), Gain(1, 0), Gain(2, 0)); - - if (verbose_) { - edm::LogInfo("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); - edm::LogInfo("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; - } - - int KNew = wrapAround(int(track.curvature() + Gain(0, 0) * residual), pow(2, BITSCURV - 1)); - int phiNew = wrapAround(int(track.positionAngle() + Gain(1, 0) * residual), pow(2, BITSPHI)); - int dxyNew = wrapAround(int(track.dxy() + Gain(2, 0) * residual), pow(2, BITSPHIB)); - if (verbose_) - edm::LogInfo("KMTFCore") << "Post fit impact parameter=" << dxyNew; - track.setCoordinatesAtVertex(KNew, phiNew, -residual); - Matrix33 covNew = cov - Gain * (H * cov); - l1t::KMTFTrack::CovarianceMatrix c; - c(0, 0) = covNew(0, 0); - c(0, 1) = covNew(0, 1); - c(0, 2) = covNew(0, 2); - c(1, 0) = covNew(1, 0); - c(1, 1) = covNew(1, 1); - c(1, 2) = covNew(1, 2); - c(2, 0) = covNew(2, 0); - c(2, 1) = covNew(2, 1); - c(2, 2) = covNew(2, 2); - track.setCovariance(c); - // track.covariance = track.covariance - Gain*H*track.covariance; -} - -void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track) { - double residual = -track.dxy(); - uint absK = fabs(track.curvature()); - if (absK > pow(2, BITSCURV - 4) - 1) - absK = pow(2, BITSCURV - 4) - 1; - - std::pair GAIN = lutService_->vertexGain(track.hitPattern(), absK / 4); - track.setKalmanGain(track.step(), fabs(track.curvature()), GAIN.first, GAIN.second, -1); - - ap_fixed k_0 = - -(ap_ufixed(fabs(GAIN.first))) * ap_fixed(residual); - int KNew = ap_fixed(k_0 + ap_fixed(track.curvature())); - - if (verbose_) { - edm::LogInfo("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" - << ap_ufixed(fabs(GAIN.first)).to_float() << " * " - << ap_fixed(residual).to_int() << " = " << k_0.to_int(); - } +void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track){} +void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track){} + +//void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track) { +// double residual = -track.dxy(); +// Matrix13 H; +// H(0, 0) = 0; +// H(0, 1) = 0; +// H(0, 2) = 1; + +// const std::vector& covLine = track.covariance(); +// l1t::KMTFTrack::CovarianceMatrix cov(covLine.begin(), covLine.end()); + +// double S = (ROOT::Math::Similarity(H, cov))(0, 0) + pointResolutionVertex_; +// S = 1.0 / S; +// Matrix31 Gain = cov * (ROOT::Math::Transpose(H)) * S; +// track.setKalmanGain(track.step(), fabs(track.curvature()), Gain(0, 0), Gain(1, 0), Gain(2, 0)); + +// if (verbose_) { +// edm::LogInfo("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); +// edm::LogInfo("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; +// } + +// int KNew = wrapAround(int(track.curvature() + Gain(0, 0) * residual), pow(2, BITSCURV - 1)); +// int phiNew = wrapAround(int(track.positionAngle() + Gain(1, 0) * residual), pow(2, BITSPHI)); +// int dxyNew = wrapAround(int(track.dxy() + Gain(2, 0) * residual), pow(2, BITSPHIB)); +// if (verbose_) +// edm::LogInfo("KMTFCore") << "Post fit impact parameter=" << dxyNew; +// track.setCoordinatesAtVertex(KNew, phiNew, -residual); +// Matrix33 covNew = cov - Gain * (H * cov); +// l1t::KMTFTrack::CovarianceMatrix c; +// c(0, 0) = covNew(0, 0); +// c(0, 1) = covNew(0, 1); +// c(0, 2) = covNew(0, 2); +// c(1, 0) = covNew(1, 0); +// c(1, 1) = covNew(1, 1); +// c(1, 2) = covNew(1, 2); +// c(2, 0) = covNew(2, 0); +// c(2, 1) = covNew(2, 1); + // c(2, 2) = covNew(2, 2); +// track.setCovariance(c); +// // track.covariance = track.covariance - Gain*H*track.covariance; +//} + +//void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track) { +// double residual = -track.dxy(); +// uint absK = fabs(track.curvature()); +// if (absK > pow(2, BITSCURV - 4) - 1) +// absK = pow(2, BITSCURV - 4) - 1; + +// std::pair GAIN = lutService_->vertexGain(track.hitPattern(), absK / 4); +// track.setKalmanGain(track.step(), fabs(track.curvature()), GAIN.first, GAIN.second, -1); + +// ap_fixed k_0 = +// -(ap_ufixed(fabs(GAIN.first))) * ap_fixed(residual); +// int KNew = ap_fixed(k_0 + ap_fixed(track.curvature())); + +// if (verbose_) { +// edm::LogInfo("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" +// << ap_ufixed(fabs(GAIN.first)).to_float() << " * " +// << ap_fixed(residual).to_int() << " = " << k_0.to_int(); +// } //int p_0 = fp_product(GAIN.second, int(residual), 7); - int p_0 = GAIN.second * int(residual); - int phiNew = wrapAround(track.positionAngle() + p_0, pow(2, BITSPHI - 1)); - track.setCoordinatesAtVertex(KNew, phiNew, -residual); -} +// int p_0 = GAIN.second * int(residual); +// int phiNew = wrapAround(track.positionAngle() + p_0, pow(2, BITSPHI - 1)); +// track.setCoordinatesAtVertex(KNew, phiNew, -residual); +//} int KMTFCore::hitPattern(const l1t::KMTFTrack& track) { unsigned int mask = 0; diff --git a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc index 44c04b7875748..eb279ce3a2ef5 100644 --- a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc +++ b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc @@ -112,25 +112,85 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubNoEta(const L1Phase2MuDT return stub; } -l1t::MuonStubCollection L1TPhase2GMTBarrelStubProcessor::makeStubs(const L1Phase2MuDTPhContainer* phiContainer, - const L1MuDTChambThContainer* etaContainer) { +l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandK(const L1Phase2MuDTExtPhiThetaPair& pairs) { + + const auto& phiS = pairs.phiDigi(); + + static constexpr double ZCenterPhysPositive[] = {268.4783935546875, 533.9012145996094}; + static constexpr double ZCenterPhysNegative[] = {-267.72308349609375, -533.0657958984375}; + static constexpr double ZCenterPhysZero[] = {0.5035400390625}; + static constexpr int RadiusStationPhys[] = {445, 526, 634, 720}; + int wheel = phiS.whNum(); + int abswheel = fabs(phiS.whNum()); + int sector = phiS.scNum(); + int station = phiS.stNum(); + + ap_uint<18> normalization0 = sector * ap_uint<15>(21845); + ap_int<18> normalization1 = ap_int<18>(ap_int<17>(phiS.phi()) * ap_ufixed<8, 0>(0.3183)); + ap_int<18> kmtf_phi = ap_int<18>(normalization0 + normalization1); + int phi = int(kmtf_phi); + float globalPhi = phi * M_PI / (1 << 17); + + // double globalPhi = (sector * 30) + phiS.phi() * 30. / 65535.; + int tag = phiS.index(); + + int bx = phiS.bxNum() - 20; + int quality = phiS.quality(); + uint tfLayer = phiS.stNum() - 1; + + // instantiate stub with eta1=0, eta2=0, etaQuality=0 values which eventually get written over with stub.setEta below. + l1t::MuonStub stub(wheel, sector, station, tfLayer, phi, phiS.phiBend(), tag, bx, quality, 0, 0, 0, 1); + + //defining z, k, zPhys, kPhys for case where theta digi exists + //defining k_centerPhys, z_centerPhys, k_centerDigi, z_centerDigi for case where theta digi does not exist + constexpr float ZRES_CONV = 65536.0 / 1500.0 ; + constexpr float KRES_CONV = 65536.0 / 2.0 ; + int z = pairs.thetaDigi().z(); + int k = pairs.thetaDigi().k(); + double zPhys = z / ZRES_CONV; + double kPhys = k / KRES_CONV; + + //slight asymmetry in wheels w.r.t. the origin calls for different z_center values for case where no theta digi was matched + double z_centerPhys; + if (wheel > 0){ + z_centerPhys= ZCenterPhysPositive[abswheel - 1]; + } else if (wheel < 0) { + z_centerPhys= ZCenterPhysNegative[abswheel - 1]; + } else { + z_centerPhys= ZCenterPhysZero[0]; + } + + double R_centerPhys = RadiusStationPhys[station - 1]; + double k_centerPhys = z_centerPhys / R_centerPhys; + int k_centerDigi = (int)(KRES_CONV * k_centerPhys); + int z_centerDigi = (int)(ZRES_CONV * z_centerPhys); + + // check if theta digi exists with non-default constructor quality --> use z, k with etaQuality=3 from theta digi. + // if theta digi has no real data, use z_center and slope which points to origin with etaQuality=0.. + if (pairs.thetaDigi().quality() >= 0) { + stub.setEta(z, k, 3); + stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), zPhys, kPhys); + } else { + if (abswheel == 0) { + stub.setEta(0,0,0); + stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), z_centerPhys, k_centerPhys); + } else { + stub.setEta(z_centerDigi, k_centerDigi, 0); + stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), z_centerPhys, k_centerPhys); + } + } + return stub; +} + +l1t::MuonStubCollection L1TPhase2GMTBarrelStubProcessor::makeStubs(const L1Phase2MuDTExtPhiThetaPairContainer* pairContainer) { l1t::MuonStubCollection out; for (int bx = minBX_; bx <= maxBX_; bx++) { ostringstream os; if (verbose_ == 2) os << "PATTERN "; - for (int wheel = -2; wheel <= 2; wheel++) { - for (int sector = 0; sector < 12; sector++) { - for (int station = 1; station < 5; station++) { - bool hasEta = false; - const L1MuDTChambThDigi* tseta = etaContainer->chThetaSegm(wheel, station, sector, bx); - if (tseta != nullptr) { - hasEta = true; - } - - for (const auto& phiDigi : *phiContainer->getContainer()) { - if ((phiDigi.bxNum() - 20) != bx || phiDigi.whNum() != wheel || phiDigi.scNum() != sector || - phiDigi.stNum() != station) + for (const auto& pair : pairContainer->getContainer()){ + const auto& phiDigi = pair.phiDigi(); + if ((phiDigi.bxNum() - 20) != bx) continue; if (phiDigi.quality() < minPhiQuality_) continue; @@ -147,19 +207,11 @@ l1t::MuonStubCollection L1TPhase2GMTBarrelStubProcessor::makeStubs(const L1Phase sN = sN | (wr1 << 30); sN = sN | (wq << 51); sN = sN | (wr2 << 55); - os << std::setw(0) << std::dec << sector << " " << wheel << " " << station << " "; + os << std::setw(0) << std::dec << phiDigi.scNum() << " " << phiDigi.whNum() << " " << phiDigi.stNum() << " "; os << std::uppercase << std::setfill('0') << std::setw(16) << std::hex << uint64_t(sN) << " "; } - - if (hasEta) { - out.push_back(buildStub(phiDigi, tseta)); - } else { - out.push_back(buildStubNoEta(phiDigi)); + out.push_back(buildStubwithZandK(pair)); } - } - } - } - } if (verbose_ == 2) edm::LogInfo("BarrelStub") << os.str() << std::endl; } @@ -201,3 +253,4 @@ int L1TPhase2GMTBarrelStubProcessor::calculateEta(uint i, int wheel, uint sector return eta; } + From e514aeb25cfe8364dad53b4c4d102998de61fc9b Mon Sep 17 00:00:00 2001 From: delano campos Date: Fri, 13 Mar 2026 19:03:02 -0500 Subject: [PATCH 05/29] symmetrix matrix fix --- L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 2 +- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 12 ++++-------- .../src/L1TPhase2GMTBarrelStubProcessor.cc | 2 +- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index f9836b23463a0..5ffb84518f429 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -55,7 +55,7 @@ combos3=cms.vint32(5,6,7), combos2=cms.vint32(3), combos1=cms.vint32(), #for future possible usage - useOfflineAlgo = cms.bool(False), + useOfflineAlgo = cms.bool(True), ###Only for the offline algo -not in firmware -------------------- mScatteringPhi = cms.vdouble(0.1169021113298598, 0.00016777763395543814, 0.0004322078772344548, 0.00024985881710722107), mScatteringPhiB = cms.vdouble(.0522762, 0.01762000062188365, 0.03508319015441297, 0.03126825551530328), diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 75a38d976fafe..9f6b20d4df12b 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -648,12 +648,8 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] : pointResolutionPhiBH_[track.step() - 1]}; - const double r[]{ - pointResolutionPhi_, 0.0, 0.0, 0.0, - 0.0, r11, 0.0, 0.0, - 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, - 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix4 R(r, 16); + const double r[]{pointResolutionPhi_, 0.0, r11, 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix4 R(r, 10); const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); @@ -745,8 +741,8 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st H(2, 3) = 0.0; H(2, 4) = 1.0; - const double r[]{pointResolutionPhi_, 0.0, 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix3 R(r, 9); + const double r[]{pointResolutionPhi_, 0.0, pointResolutionz_[track.step() - 1], 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix3 R(r, 6); const std::vector& covLine = track.covariance(); l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); diff --git a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc index eb279ce3a2ef5..fadbe1f68b694 100644 --- a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc +++ b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc @@ -172,7 +172,7 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandK(const L1Phase2 stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), zPhys, kPhys); } else { if (abswheel == 0) { - stub.setEta(0,0,0); + stub.setEta(z_centerDigi,k_centerDigi,0); stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), z_centerPhys, k_centerPhys); } else { stub.setEta(z_centerDigi, k_centerDigi, 0); From e5b0f3c6ba269567ff14d3f4ee4a7960bcb6b91f Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 16 Mar 2026 14:47:28 -0500 Subject: [PATCH 06/29] matrix vector fix --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 9f6b20d4df12b..d4726cc244ca0 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -648,8 +648,11 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] : pointResolutionPhiBH_[track.step() - 1]}; - const double r[]{pointResolutionPhi_, 0.0, r11, 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix4 R(r, 10); + const double r[]{pointResolutionPhi_, 0.0, 0.0, 0.0, + 0.0, r11, 0.0, 0.0, + 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, + 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix4 R(r, 16); const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); @@ -658,6 +661,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub return false; const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; + //track.setKalmanGain( //track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), Gain(1, 0), Gain(1, 1), Gain(2, 0), Gain(2, 1)); @@ -741,8 +745,10 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st H(2, 3) = 0.0; H(2, 4) = 1.0; - const double r[]{pointResolutionPhi_, 0.0, pointResolutionz_[track.step() - 1], 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix3 R(r, 6); + const double r[]{pointResolutionPhi_, 0.0,0.0, + 0.0,pointResolutionz_[track.step() - 1], 0.0, + 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix3 R(r, 9); const std::vector& covLine = track.covariance(); l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); From afc1d61c21c1aa77006fa25d0c356ea9d03ccbb9 Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 16 Mar 2026 15:13:52 -0500 Subject: [PATCH 07/29] revert matrix vector argument to upper triangle only --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index d4726cc244ca0..9e44ece1cf7ec 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -648,11 +648,11 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] : pointResolutionPhiBH_[track.step() - 1]}; - const double r[]{pointResolutionPhi_, 0.0, 0.0, 0.0, - 0.0, r11, 0.0, 0.0, - 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, + const double r[]{pointResolutionPhi_, + 0.0, r11, + 0.0, 0.0, pointResolutionz_[track.step() - 1], 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix4 R(r, 16); + const CovarianceMatrix4 R(r, 10); const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); @@ -745,10 +745,10 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st H(2, 3) = 0.0; H(2, 4) = 1.0; - const double r[]{pointResolutionPhi_, 0.0,0.0, - 0.0,pointResolutionz_[track.step() - 1], 0.0, + const double r[]{pointResolutionPhi_, 0.0, + pointResolutionz_[track.step() - 1], 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix3 R(r, 9); + const CovarianceMatrix3 R(r, 6); const std::vector& covLine = track.covariance(); l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); From edee2c830fc4a8765deba29ed45092065c1b200c Mon Sep 17 00:00:00 2001 From: delano campos Date: Tue, 17 Mar 2026 14:49:14 -0500 Subject: [PATCH 08/29] verbose = 1 --- L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index 5ffb84518f429..9f33d491f8b1a 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -3,9 +3,9 @@ gmtKMTFMuons = cms.EDProducer('Phase2L1TGMTKMTFProducer', stubs = cms.InputTag('gmtStubs','kmtf'), - verbose = cms.int32(0), + verbose = cms.int32(1), algo = cms.PSet( - verbose = cms.bool(False), + verbose = cms.bool(True), lutFile = cms.string("L1Trigger/Phase2L1GMT/data/packedGainLUTs.root"), initialK = cms.vdouble(-0.4576229536749278, -0.6364802777566145, -1.0305030909883524, -1.7272067322624118), initialK2 = cms.vdouble(-6.442002637356136e-05, -9.582709649965545e-05, -0.0002741064246218815, -0.0014910074450869175), From d62af54133a08c9328ac1cc478a69edee7fdf3db Mon Sep 17 00:00:00 2001 From: delano campos Date: Tue, 17 Mar 2026 14:56:35 -0500 Subject: [PATCH 09/29] testing new z prop wheel-based logic --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 9e44ece1cf7ec..0982f9dd4836f 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -519,7 +519,17 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { constexpr double zdR_CONV = ZRES_CONV / KRES_CONV ; double zdeltaR_dig = zdeltaR_[step - 1] * zdR_CONV ; int kSlopeNew = kSlope; - int zNew = z + (int)(kSlope * zdeltaR_dig); + + //convention is plus sign with default kSlope and negative zdeltaR to propagate inward + int convergeTerm = abs((int)(kSlope * zdeltaR_dig)); + int wheel = track.wheel(); + int zNew; + if (wheel > 0) + zNew = z - convergeTerm; + else if (wheel < 0) + zNew = z + convergeTerm; + else + zNew = (z > 0) ? z - convergeTerm : z + convergeTerm; //Create the transformation matrix @@ -545,7 +555,12 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { a[16] = 0.0; a[17] = 0.0; a[18] = 1.0; - a[19] = zdeltaR_dig; + if (wheel > 0) + a[19] = -zdeltaR_dig; + else if (wheel < 0) + a[19] = zdeltaR_dig; + else + a[19] = (z > 0) ? -zdeltaR_dig : zdeltaR_dig; a[20] = 0.0; a[21] = 0.0; a[22] = 0.0; @@ -656,6 +671,8 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); + edm::LogInfo("KMTFCore") << "=== updateOffline step=" << track.step() << " ==="; + edm::LogInfo("KMTFCore") << "Pre-fit cov diag: " << cov(0,0) << " " << cov(1,1) << " " << cov(2,2) << " " << cov(3,3) << " " << cov(4,4); CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; @@ -688,7 +705,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub } track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); - const auto covNew{cov - Gain * (H * cov)}; + const Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; for (int i = 0; i < 5; i++) From 8ed52d9801de5adf01eeb000a5e4fd91f81b8225 Mon Sep 17 00:00:00 2001 From: delano campos Date: Tue, 17 Mar 2026 17:29:14 -0500 Subject: [PATCH 10/29] more verbose print statements --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 165 ++++++++++++++------------ 1 file changed, 92 insertions(+), 73 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 0982f9dd4836f..99b2e287dde29 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -113,7 +113,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), seed->eta2()); } if (verbose_) { - edm::LogInfo("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK; + edm::LogWarning("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK << " z=" << seed->eta1() << " kSlope=" << seed->eta2(); } track.setHitPattern(hitPattern(track)); //set covariance @@ -145,24 +145,24 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef // if (verbose_) { - edm::LogInfo("KMTFCore") << "New Kalman fit staring at step=" << track.step() << ", phi=" << track.positionAngle() + edm::LogWarning("KMTFCore") << "New Kalman fit staring at step=" << track.step() << ", phi=" << track.positionAngle() << ", phiB=" << track.bendingAngle() << ", with curvature=" << track.curvature(); - edm::LogInfo("KMTFCore") << "BITMASK:" << std::flush; + edm::LogWarning("KMTFCore") << "BITMASK:" << std::flush; for (unsigned int i = 0; i < 4; ++i) - edm::LogInfo("KMTFCore") << getBit(mask, i) << std::flush; - edm::LogInfo("KMTFCore") << std::endl; - edm::LogInfo("KMTFCore") << "------------------------------------------------------"; - edm::LogInfo("KMTFCore") << "------------------------------------------------------"; - edm::LogInfo("KMTFCore") << "------------------------------------------------------"; - edm::LogInfo("KMTFCore") << "stubs:"; + edm::LogWarning("KMTFCore") << getBit(mask, i) << std::flush; + edm::LogWarning("KMTFCore") << std::endl; + edm::LogWarning("KMTFCore") << "------------------------------------------------------"; + edm::LogWarning("KMTFCore") << "------------------------------------------------------"; + edm::LogWarning("KMTFCore") << "------------------------------------------------------"; + edm::LogWarning("KMTFCore") << "stubs:"; for (const auto& stub : stubs) - edm::LogInfo("KMTFCore") << "station=" << stub->depthRegion() << " phi=" << stub->coord1() + edm::LogWarning("KMTFCore") << "station=" << stub->depthRegion() << " phi=" << stub->coord1() << " phiB=" << correctedPhiB(stub) << " qual=" << stub->quality() << " tag=" << stub->id() << " sector=" << stub->phiRegion() << " wheel=" << stub->etaRegion() << " fineEta= " << stub->eta1() << " " << stub->eta2(); - edm::LogInfo("KMTFCore") << "------------------------------------------------------"; - edm::LogInfo("KMTFCore") << "------------------------------------------------------"; + edm::LogWarning("KMTFCore") << "------------------------------------------------------"; + edm::LogWarning("KMTFCore") << "------------------------------------------------------"; } bool passedU = false; @@ -175,32 +175,32 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef setRank(track, false); if (verbose_) - edm::LogInfo("KMTFCore") << "Calculated Chi2 for displaced track =" << track.approxDispChi2() + edm::LogWarning("KMTFCore") << "Calculated Chi2 for displaced track =" << track.approxDispChi2() << " Passed Cut=" << passedU; calculateEta(track); setFourVectors(track); //calculate coarse eta ////////////////////// if (verbose_) - edm::LogInfo("KMTFCore") << "Unconstrained PT in Muon System: pt=" << track.displacedP4().pt(); + edm::LogWarning("KMTFCore") << "Unconstrained PT in Muon System: pt=" << track.displacedP4().pt(); calculateEta(track); } propagate(track); if (verbose_) - edm::LogInfo("KMTFCore") << "propagated Coordinates step:" << track.step() << "phi=" << track.positionAngle() + edm::LogWarning("KMTFCore") << "propagated Coordinates step:" << track.step() << "phi=" << track.positionAngle() << "phiB=" << track.bendingAngle() << "K=" << track.curvature(); if (track.step() > 0) if (getBit(mask, track.step() - 1)) { std::pair bestStub = match(seed, stubs, track.step()); if (verbose_) - edm::LogInfo("KMTFCore") << "Found match =" << bestStub.first << " index=" << bestStub.second + edm::LogWarning("KMTFCore") << "Found match =" << bestStub.first << " index=" << bestStub.second << " number of all stubs=" << stubs.size(); if ((!bestStub.first) || (!update(track, stubs[bestStub.second], mask, seedQual))) break; if (verbose_) { - edm::LogInfo("KMTFCore") << "updated Coordinates step:" << track.step() << " phi=" << track.positionAngle() + edm::LogWarning("KMTFCore") << "updated Coordinates step:" << track.step() << " phi=" << track.positionAngle() << " phiB=" << track.bendingAngle() << " K=" << track.curvature(); } } @@ -208,7 +208,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (track.step() == 0) { track.setCoordinatesAtVertex(track.curvature(), track.positionAngle(), track.bendingAngle()); if (verbose_) - edm::LogInfo("KMTFCore") << " Coordinates before vertex constraint step:" << track.step() + edm::LogWarning("KMTFCore") << " Coordinates before vertex constraint step:" << track.step() << " phi=" << track.phiAtVertex() << " dxy=" << track.dxy() << " K=" << track.curvatureAtVertex(); @@ -220,23 +220,23 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef setRank(track, true); if (verbose_) - edm::LogInfo("KMTFCore") << "Calculated Chi2 for prompt track =" << track.approxPromptChi2() + edm::LogWarning("KMTFCore") << "Calculated Chi2 for prompt track =" << track.approxPromptChi2() << " Passed Cut=" << passedV; if (verbose_) { - edm::LogInfo("KMTFCore") << " Coordinates after vertex constraint step:" << track.step() + edm::LogWarning("KMTFCore") << " Coordinates after vertex constraint step:" << track.step() << " phi=" << track.phiAtVertex() << " dxy=" << track.dxy() << " K=" << track.curvatureAtVertex() << " maximum local chi2=" << track.approxPromptChi2(); - edm::LogInfo("KMTFCore") << "------------------------------------------------------"; - edm::LogInfo("KMTFCore") << "------------------------------------------------------"; + edm::LogWarning("KMTFCore") << "------------------------------------------------------"; + edm::LogWarning("KMTFCore") << "------------------------------------------------------"; } setFourVectors(track); //finally set the displaced or prompt ID track.setIDFlag(passedV, passedU); if (verbose_) - edm::LogInfo("KMTFCore") << "Floating point coordinates at vertex: pt=" << track.pt() + edm::LogWarning("KMTFCore") << "Floating point coordinates at vertex: pt=" << track.pt() << ", eta=" << track.eta() << " phi=" << track.phi(); pretracks.push_back(track); @@ -245,9 +245,9 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef } if (verbose_) { if (!pretracks.empty()) - edm::LogInfo("KMTFCore") << "-----Kalman Algo at station " << seed->depthRegion() << " (uncleaned)-----"; + edm::LogWarning("KMTFCore") << "-----Kalman Algo at station " << seed->depthRegion() << " (uncleaned)-----"; for (const auto& track : pretracks) - edm::LogInfo("KMTFCore") << "Kalman Track charge=" << track.charge() << " pt=" << track.pt() + edm::LogWarning("KMTFCore") << "Kalman Track charge=" << track.charge() << " pt=" << track.pt() << " hit pattern = " << track.hitPattern() << " eta=" << track.eta() << " phi=" << track.phi() << " curvature=" << track.curvatureAtVertex() << " curvature STA =" << track.curvatureAtMuon() @@ -258,13 +258,13 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef //Now for all the pretracks we need only one vertex constrained and one vertex unconstrained //so we clean twice if (verbose_) - edm::LogInfo("KMTFCore") << "Chain Reconstructed " << pretracks.size() + edm::LogWarning("KMTFCore") << "Chain Reconstructed " << pretracks.size() << " pretracks, now cleaning them separately"; std::vector cleanedPrompt = clean(pretracks, seed->depthRegion(), true); std::vector cleanedDisp = clean(pretracks, seed->depthRegion(), false); if (verbose_) - edm::LogInfo("KMTFCore") << "Cleaned Chain tracks prompt=" << cleanedPrompt.size() + edm::LogWarning("KMTFCore") << "Cleaned Chain tracks prompt=" << cleanedPrompt.size() << " displaced=" << cleanedDisp.size(); if (cleanedPrompt.empty() && cleanedDisp.empty()) @@ -291,7 +291,7 @@ std::vector KMTFCore::clean(const std::vector& t if ((track.id() & 0x1) == 0) continue; if (verbose_) - edm::LogInfo("KMTFCore") << "Chain Cleaning : Pre Track = pattern = " << track.rankPrompt() + edm::LogWarning("KMTFCore") << "Chain Cleaning : Pre Track = pattern = " << track.rankPrompt() << " rank=" << track.hitPattern(); infoRank[track.hitPattern()] = track.rankPrompt(); infoTrack[track.hitPattern()] = track; @@ -369,12 +369,12 @@ std::pair KMTFCore::match(const l1t::MuonStubRef& seed, const l1t::M const l1t::MuonStubRef& stub = stubs[N]; //Should not be stubs with tag=4 but there are, so skip those if (verbose_) - edm::LogInfo("KMTFCore") << "testing stub on depth=" << stub->depthRegion() << " for step=" << step; + edm::LogWarning("KMTFCore") << "testing stub on depth=" << stub->depthRegion() << " for step=" << step; if (stub->depthRegion() != step) continue; if (verbose_) - edm::LogInfo("KMTFCore") << "Passed"; + edm::LogWarning("KMTFCore") << "Passed"; uint distance = fabs(wrapAround((seed->coord1() - stub->coord1()) >> 3, 32768)); //if the wheels are not adjacent make this huge @@ -459,7 +459,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { ap_fixed KnewInt = ap_fixed(K) - eK * Kint; KNew = KnewInt; if (verbose_) - edm::LogInfo("KMTFCore") << "propagate to vertex Kint=" << Kint.to_int() << " ek=" << eK.to_float() + edm::LogWarning("KMTFCore") << "propagate to vertex Kint=" << Kint.to_int() << " ek=" << eK.to_float() << " Knew=" << KNew; } @@ -469,7 +469,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { ap_fixed(-bPhi_[step - 1]) * ap_fixed(phiB); if (verbose_) { - edm::LogInfo("KMTFCore") << "phi prop = " << K << " * " << ap_fixed(aPhi_[step - 1]).to_float() + edm::LogWarning("KMTFCore") << "phi prop = " << K << " * " << ap_fixed(aPhi_[step - 1]).to_float() << " = " << phi11.to_int() << ", " << phiB << " * " << ap_fixed(-bPhi_[step - 1]).to_float() << " = " << phi12.to_int(); } @@ -481,7 +481,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { ap_ufixed(bPhiB_[step - 1]) * ap_fixed(phiB); int phiBNew = ap_fixed(phiB11 + phiB12); if (verbose_) { - edm::LogInfo("KMTFCore") << "phiB prop = " << K << " * " << ap_fixed(aPhiB_[step - 1]).to_float() + edm::LogWarning("KMTFCore") << "phiB prop = " << K << " * " << ap_fixed(aPhiB_[step - 1]).to_float() << " = " << phiB11.to_int() << ", " << phiB << " * " << ap_ufixed(bPhiB_[step - 1]).to_float() << " = " << phiB12.to_int(); } @@ -503,7 +503,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { phiBNew = ap_fixed(diff); if (verbose_) { - edm::LogInfo("KMTFCore") << "Vertex phiB prop = " << DXY.to_int() << "(=" << aK.to_int() << " +" + edm::LogWarning("KMTFCore") << "Vertex phiB prop = " << DXY.to_int() << "(=" << aK.to_int() << " +" << (eK * Kint).to_int() << ") - " << ap_fixed(phiB).to_int() << " = " << phiBNew; } @@ -601,11 +601,19 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { cov = cov + MS; if (verbose_) { - edm::LogInfo("KMTFCore") << "Covariance term for phiB = " << cov(2, 2); - edm::LogInfo("KMTFCore") << "Multiple scattering term for phiB = " << MS(2, 2); + edm::LogWarning("KMTFCore") << "Covariance term for phiB = " << cov(2, 2); + edm::LogWarning("KMTFCore") << "Multiple scattering term for phiB = " << MS(2, 2); + edm::LogWarning("KMTFCore") << "Multiple scattering term for z = " << MS(3, 3); + edm::LogWarning("KMTFCore") << "Multiple scattering term for kSlope = " << MS(4, 4); } track.setCovariance(cov); + if (verbose_) { + edm::LogWarning("KMTFCore") << "z prop step " << step << "->" << (step-1) + << ": z=" << z << " -> " << zNew + << " (convergeTerm=" << convergeTerm << ", kSlope=" << kSlope + << ", zdeltaR_dig=" << zdeltaR_dig << ", wheel=" << track.wheel() << ")"; + } track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); } @@ -671,8 +679,8 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - edm::LogInfo("KMTFCore") << "=== updateOffline step=" << track.step() << " ==="; - edm::LogInfo("KMTFCore") << "Pre-fit cov diag: " << cov(0,0) << " " << cov(1,1) << " " << cov(2,2) << " " << cov(3,3) << " " << cov(4,4); + edm::LogWarning("KMTFCore") << "=== updateOffline step=" << track.step() << " ==="; + edm::LogWarning("KMTFCore") << "Pre-fit cov diag: " << cov(0,0) << " " << cov(1,1) << " " << cov(2,2) << " " << cov(3,3) << " " << cov(4,4); CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; @@ -694,14 +702,25 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); if (verbose_) { - edm::LogInfo("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << int(residual[0]) << " " << phiB + edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << int(residual[0]) << " " << phiB << " - " << trackPhiB << " = " << int(residual[1]); - edm::LogInfo("KMTFCore") << "Gains offline: " << Gain(0, 0) << " " << Gain(0, 1) << " " << Gain(2, 0) << " " + edm::LogWarning("KMTFCore") << "Gains offline: " << Gain(0, 0) << " " << Gain(0, 1) << " " << Gain(2, 0) << " " << Gain(2, 1); - edm::LogInfo("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) + edm::LogWarning("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) << " * " << residual(1); - edm::LogInfo("KMTFCore") << " phiB = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " + edm::LogWarning("KMTFCore") << " phiB = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1); + edm::LogWarning("KMTFCore") << " z = " << trackz << " + " << Gain(3,0) << "*" << residual(0) + << " + " << Gain(3,1) << "*" << residual(1) + << " + " << Gain(3,2) << "*" << residual(2) + << " + " << Gain(3,3) << "*" << residual(3) << " = " << zNew; + edm::LogWarning("KMTFCore") << " kSlope = " << trackSlope << " + " << Gain(4,0) << "*" << residual(0) + << " + " << Gain(4,1) << "*" << residual(1) + << " + " << Gain(4,2) << "*" << residual(2) + << " + " << Gain(4,3) << "*" << residual(3) << " = " << kSlopeNew; + edm::LogWarning("KMTFCore") << " stub z=" << z << " kSlope=" << kSlope + << " | residual z=" << residual(2) << " kSlope=" << residual(3); + } track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); @@ -713,7 +732,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub c(i, j) = covNew(i, j); if (verbose_) { - edm::LogInfo("KMTFCore") << "Post Fit Covariance Matrix " << cov(0, 0) << " " << cov(1, 1) << " " << cov(2, 2); + edm::LogWarning("KMTFCore") << "Post Fit Covariance Matrix " << cov(0, 0) << " " << cov(1, 1) << " " << cov(2, 2); } track.setCovariance(c); @@ -740,9 +759,9 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st residual[2] = kSlope - trackSlope; if (verbose_) { - edm::LogInfo("KMTFCore") << "residual phi" << phi << " - " << trackPhi << " = " << int(residual(0)); - edm::LogInfo("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); - edm::LogInfo("KMTFCore") << "residual kSlope" << kSlope << " - " << trackSlope << " = " << int(residual(2)); + edm::LogWarning("KMTFCore") << "residual phi" << phi << " - " << trackPhi << " = " << int(residual(0)); + edm::LogWarning("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); + edm::LogWarning("KMTFCore") << "residual kSlope" << kSlope << " - " << trackSlope << " = " << int(residual(2)); } Matrix35 H; @@ -788,11 +807,11 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st l1t::CovarianceMatrix5dim c; if (verbose_) { - edm::LogInfo("KMTFCore") << "phiUpdate: " << int(Gain(0, 0) * residual(0)) << " " << int(Gain(2, 0) * residual(0)); - edm::LogInfo("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) << " * " << residual(1) << " + " << Gain(0, 2) << " * " << residual(2); - edm::LogInfo("KMTFCore") << " phiBNew = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1) << " + " << Gain(2, 2) << " * " << residual(2); - edm::LogInfo("KMTFCore") << " zNew = " << trackz << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1) << " + " << Gain(2, 2) << " * " << residual(2); - edm::LogInfo("KMTFCore") << " kSlopeNew = " << trackSlope << " + " << Gain(3, 0) << " * " << residual(0) << " + " << Gain(3, 1) << " * " << residual(1) << " + " << Gain(3, 2) << " * " << residual(2); + edm::LogWarning("KMTFCore") << "phiUpdate: " << int(Gain(0, 0) * residual(0)) << " " << int(Gain(2, 0) * residual(0)); + edm::LogWarning("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) << " * " << residual(1) << " + " << Gain(0, 2) << " * " << residual(2); + edm::LogWarning("KMTFCore") << " phiBNew = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1) << " + " << Gain(2, 2) << " * " << residual(2); + edm::LogWarning("KMTFCore") << " zNew = " << trackz << " + " << Gain(3, 0) << " * " << residual(0) << " + " << Gain(3, 1) << " * " << residual(1) << " + " << Gain(3, 2) << " * " << residual(2); + edm::LogWarning("KMTFCore") << " kSlopeNew = " << trackSlope << " + " << Gain(4, 0) << " * " << residual(0) << " + " << Gain(4, 1) << " * " << residual(1) << " + " << Gain(4, 2) << " * " << residual(2); } for (int i = 0; i < 5; i++) @@ -819,7 +838,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in ap_fixed residualPhiB = phiB - trackPhiB; if (verbose_) - edm::LogInfo("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << residualPhi.to_int() << " " << phiB + edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << residualPhi.to_int() << " " << phiB << " - " << trackPhiB << " = " << residualPhiB.to_int(); uint absK = fabs(trackK); @@ -828,7 +847,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in std::vector GAIN; if (verbose_) { - edm::LogInfo("KMTFCore") << "Looking up LUTs for mask=" << mask << " with hit pattern=" << track.hitPattern(); + edm::LogWarning("KMTFCore") << "Looking up LUTs for mask=" << mask << " with hit pattern=" << track.hitPattern(); } //For the three stub stuff use only gains 0 and 4 if (!(mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) { @@ -840,14 +859,14 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in GAIN = lutService_->trackGain2(track.step(), track.hitPattern(), absK / 32, seedQual, stub->quality()); } if (verbose_) { - edm::LogInfo("KMTFCore") << "Gains (fp): " << GAIN[0] << " " << GAIN[1] << " " << GAIN[2] << " " << GAIN[3]; + edm::LogWarning("KMTFCore") << "Gains (fp): " << GAIN[0] << " " << GAIN[1] << " " << GAIN[2] << " " << GAIN[3]; if (!(mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) - edm::LogInfo("KMTFCore") << "Addr=" << absK / 16 + edm::LogWarning("KMTFCore") << "Addr=" << absK / 16 << " gain0=" << ap_ufixed(GAIN[0]).to_float() << " gain4=-" << ap_ufixed(GAIN[2]).to_float(); else - edm::LogInfo("KMTFCore") << "Addr=" << absK / 32 << " " << ap_ufixed(GAIN[0]).to_float() + edm::LogWarning("KMTFCore") << "Addr=" << absK / 32 << " " << ap_ufixed(GAIN[0]).to_float() << " -" << ap_ufixed(GAIN[1]).to_float() << " " << ap_ufixed(GAIN[2]).to_float() << " " << ap_ufixed(GAIN[3]).to_float(); @@ -860,7 +879,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in KNew = ap_fixed(ap_fixed(trackK) + ap_ufixed(GAIN[0]) * residualPhi); if (verbose_) { - edm::LogInfo("KMTFCore") << "K = " << KNew << " = " << ap_fixed(trackK).to_int() << " + " + edm::LogWarning("KMTFCore") << "K = " << KNew << " = " << ap_fixed(trackK).to_int() << " + " << ap_ufixed(GAIN[0]).to_float() << "*" << residualPhi.to_int(); } } else { @@ -869,13 +888,13 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in KNew = ap_fixed(ap_fixed(trackK) + k11 - k12); if (verbose_) { - edm::LogInfo("KMTFCore") << "K = " << KNew << " = " << ap_fixed(trackK).to_int() << " + " + edm::LogWarning("KMTFCore") << "K = " << KNew << " = " << ap_fixed(trackK).to_int() << " + " << k11.to_int() << " + " << k12.to_int(); } } if ((KNew > (pow(2, BITSCURV - 1) - 1)) || (KNew < -(pow(2, BITSCURV - 1)))) { if (verbose_) - edm::LogInfo("KMTFCore") << "K has saturated, track has extremely low energy"; + edm::LogWarning("KMTFCore") << "K has saturated, track has extremely low energy"; return false; } KNew = wrapAround(KNew, pow(2, BITSCURV - 1)); @@ -887,7 +906,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in ap_fixed pb_0 = ap_ufixed(GAIN[2]) * residualPhi; if (verbose_) { - edm::LogInfo("KMTFCore") << "phiupdate " << pb_0.to_float() << " " << pb_1.to_float() << " " + edm::LogWarning("KMTFCore") << "phiupdate " << pb_0.to_float() << " " << pb_1.to_float() << " " << pbdouble_0.to_float(); } @@ -906,9 +925,9 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in track.addStub(stub); track.setHitPattern(hitPattern(track)); if (verbose_) { - edm::LogInfo("KMTFCore") << "Stub station =" << stub->depthRegion(); + edm::LogWarning("KMTFCore") << "Stub station =" << stub->depthRegion(); - edm::LogInfo("KMTFCore") << "Updated Hit Pattern =" << track.hitPattern(); + edm::LogWarning("KMTFCore") << "Updated Hit Pattern =" << track.hitPattern(); } return true; @@ -941,15 +960,15 @@ void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track){} // track.setKalmanGain(track.step(), fabs(track.curvature()), Gain(0, 0), Gain(1, 0), Gain(2, 0)); // if (verbose_) { -// edm::LogInfo("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); -// edm::LogInfo("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; +// edm::LogWarning("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); +// edm::LogWarning("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; // } // int KNew = wrapAround(int(track.curvature() + Gain(0, 0) * residual), pow(2, BITSCURV - 1)); // int phiNew = wrapAround(int(track.positionAngle() + Gain(1, 0) * residual), pow(2, BITSPHI)); // int dxyNew = wrapAround(int(track.dxy() + Gain(2, 0) * residual), pow(2, BITSPHIB)); // if (verbose_) -// edm::LogInfo("KMTFCore") << "Post fit impact parameter=" << dxyNew; +// edm::LogWarning("KMTFCore") << "Post fit impact parameter=" << dxyNew; // track.setCoordinatesAtVertex(KNew, phiNew, -residual); // Matrix33 covNew = cov - Gain * (H * cov); // l1t::KMTFTrack::CovarianceMatrix c; @@ -980,7 +999,7 @@ void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track){} // int KNew = ap_fixed(k_0 + ap_fixed(track.curvature())); // if (verbose_) { -// edm::LogInfo("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" +// edm::LogWarning("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" // << ap_ufixed(fabs(GAIN.first)).to_float() << " * " // << ap_fixed(residual).to_int() << " = " << k_0.to_int(); // } @@ -1113,7 +1132,7 @@ bool KMTFCore::estimateChiSquare(l1t::KMTFTrack& track, bool vertex) { diffPhiB = 0; if (verbose_) - edm::LogInfo("KMTFCore") << "Error propagation coefficients A=" + edm::LogWarning("KMTFCore") << "Error propagation coefficients A=" << propErrA[stub->depthRegion() - innerStub->depthRegion() - 1] << " B=" << propErrB[stub->depthRegion() - innerStub->depthRegion() - 1] << " BK = " << uint(ap_fixed<8, 2>(propErrB[stub->depthRegion() - innerStub->depthRegion() - 1]) * @@ -1131,14 +1150,14 @@ bool KMTFCore::estimateChiSquare(l1t::KMTFTrack& track, bool vertex) { chi = chi + absDelta; chiErr = chiErr + err; if (verbose_) { - edm::LogInfo("KMTFCore") << "Chi Square stub for track with pattern=" << track.hitPattern() + edm::LogWarning("KMTFCore") << "Chi Square stub for track with pattern=" << track.hitPattern() << " inner stub depth=" << innerStub->depthRegion() << "-> AK=" << int(AK) << " stubDepth=" << stub->depthRegion() << " diff1=" << diffPhi << " diff2=" << diffPhiB << " delta=" << absDelta << " absK=" << uint(absK) << " err=" << err; } } if (verbose_) { - edm::LogInfo("KMTFCore") << "Chi Square =" << chi << " ChiSquare Error = " << chiErr; + edm::LogWarning("KMTFCore") << "Chi Square =" << chi << " ChiSquare Error = " << chiErr; } track.setApproxChi2(chi, chiErr, vertex); @@ -1173,7 +1192,7 @@ void KMTFCore::setRank(l1t::KMTFTrack& track, bool vertex) { rank = 0; if (verbose_) - edm::LogInfo("KMTFCore") << "Rank Calculated for vertex=" << vertex << " = " << rank; + edm::LogWarning("KMTFCore") << "Rank Calculated for vertex=" << vertex << " = " << rank; track.setRank(rank, vertex); } @@ -1198,7 +1217,7 @@ int KMTFCore::encode(bool ownwheel, int sector, int tag) { std::pair KMTFCore::getByCode(const std::vector& tracks, int mask) { for (uint i = 0; i < tracks.size(); ++i) { - edm::LogInfo("KMTFCore") << "Code=" << tracks[i].hitPattern() << ", track=" << mask; + edm::LogWarning("KMTFCore") << "Code=" << tracks[i].hitPattern() << ", track=" << mask; if (tracks[i].hitPattern() == mask) return std::make_pair(true, i); } @@ -1236,11 +1255,11 @@ void KMTFCore::calculateEta(l1t::KMTFTrack& track) { mask = mask | ((uint(fabs(track.stubs()[i]->etaRegion()) + 1) << (2 * (track.stubs()[i]->depthRegion() - 1)))); } if (verbose_) - edm::LogInfo("KMTFCore") << "Mask = " << mask; + edm::LogWarning("KMTFCore") << "Mask = " << mask; track.setCoarseEta(sign * lutService_->coarseEta(mask)); if (verbose_) - edm::LogInfo("KMTFCore") << "Coarse Eta mask=" << mask << " set = " << sign * lutService_->coarseEta(mask); + edm::LogWarning("KMTFCore") << "Coarse Eta mask=" << mask << " set = " << sign * lutService_->coarseEta(mask); track.setFineEta(0); } From e84f5c7150c5c5aeafd0b9f7574171fa6903a0b6 Mon Sep 17 00:00:00 2001 From: delano campos Date: Wed, 18 Mar 2026 18:58:10 -0500 Subject: [PATCH 11/29] printout changes --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 70 ++++++++++++++++++--------- 1 file changed, 48 insertions(+), 22 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 99b2e287dde29..6c14c184f2e1e 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -109,6 +109,12 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (initialK <= -pow(2, BITSCURV - 1)) initialK = -pow(2, BITSCURV - 1) + 1; track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), phiB, seed->eta1(), seed->eta2()); + edm::LogWarning("KMTFCore") << "------------------"; + edm::LogWarning("KMTFCore") << "[INIT] mask=" << mask << " step=" << track.step() + << " K=" << initialK << " phi=" << seed->coord1() << " phiB=" << phiB + << " z=" << seed->eta1() << " kSlope=" << seed->eta2() + << " seedQual=" << seed->quality() << " wheel=" << seed->etaRegion(); + if (seed->quality() < 6) { track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), seed->eta2()); } @@ -146,7 +152,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef // if (verbose_) { edm::LogWarning("KMTFCore") << "New Kalman fit staring at step=" << track.step() << ", phi=" << track.positionAngle() - << ", phiB=" << track.bendingAngle() << ", with curvature=" << track.curvature(); + << ", phiB=" << track.bendingAngle() << ", z=" << track.zPosition() << ",kSlope = " << track.kSlope() << ", with curvature=" << track.curvature() ; edm::LogWarning("KMTFCore") << "BITMASK:" << std::flush; for (unsigned int i = 0; i < 4; ++i) edm::LogWarning("KMTFCore") << getBit(mask, i) << std::flush; @@ -159,8 +165,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef edm::LogWarning("KMTFCore") << "station=" << stub->depthRegion() << " phi=" << stub->coord1() << " phiB=" << correctedPhiB(stub) << " qual=" << stub->quality() << " tag=" << stub->id() << " sector=" << stub->phiRegion() - << " wheel=" << stub->etaRegion() << " fineEta= " << stub->eta1() << " " - << stub->eta2(); + << " wheel=" << stub->etaRegion() << " z= " << stub->eta1() << " kSlope = " << stub->eta2(); edm::LogWarning("KMTFCore") << "------------------------------------------------------"; edm::LogWarning("KMTFCore") << "------------------------------------------------------"; } @@ -181,15 +186,16 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef setFourVectors(track); //calculate coarse eta ////////////////////// - if (verbose_) + if (verbose_){ edm::LogWarning("KMTFCore") << "Unconstrained PT in Muon System: pt=" << track.displacedP4().pt(); + } calculateEta(track); } propagate(track); if (verbose_) edm::LogWarning("KMTFCore") << "propagated Coordinates step:" << track.step() << "phi=" << track.positionAngle() - << "phiB=" << track.bendingAngle() << "K=" << track.curvature(); + << "phiB=" << track.bendingAngle() << "K=" << track.curvature() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); if (track.step() > 0) if (getBit(mask, track.step() - 1)) { std::pair bestStub = match(seed, stubs, track.step()); @@ -201,7 +207,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef break; if (verbose_) { edm::LogWarning("KMTFCore") << "updated Coordinates step:" << track.step() << " phi=" << track.positionAngle() - << " phiB=" << track.bendingAngle() << " K=" << track.curvature(); + << " phiB=" << track.bendingAngle() << " K=" << track.curvature() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); } } @@ -210,7 +216,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (verbose_) edm::LogWarning("KMTFCore") << " Coordinates before vertex constraint step:" << track.step() << " phi=" << track.phiAtVertex() << " dxy=" << track.dxy() - << " K=" << track.curvatureAtVertex(); + << " K=" << track.curvatureAtVertex() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); //apply vertex constraint for non single tracks if (track.stubs().size() > 1) @@ -238,6 +244,12 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (verbose_) edm::LogWarning("KMTFCore") << "Floating point coordinates at vertex: pt=" << track.pt() << ", eta=" << track.eta() << " phi=" << track.phi(); + edm::LogWarning("KMTFCore") << "[RESULT] mask=" << mask + << " K=" << track.curvatureAtVertex() << " phi=" << track.phiAtVertex() + << " dxy=" << track.dxy() << " z=" << track.zPosition() << " kSlope=" << track.kSlope() + << " pt=" << track.pt() << " eta=" << track.eta() + << " chi2_prompt=" << track.approxPromptChi2() << " chi2_disp=" << track.approxDispChi2() + << " nstubs=" << track.stubs().size() << " hitPattern=" << track.hitPattern(); pretracks.push_back(track); } @@ -438,6 +450,10 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { unsigned int step = track.step(); int z = track.zPosition(); int kSlope = track.kSlope(); + edm::LogWarning("KMTFCore") << "[PRE-PROP] step " << step << "->" << (step - 1) + << ": K=" << K << " phi=" << phi << " phiB=" << phiB + << " z=" << z << " kSlope=" << kSlope << " wheel=" << track.wheel(); + int charge = 1; if (K != 0) @@ -606,14 +622,12 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { edm::LogWarning("KMTFCore") << "Multiple scattering term for z = " << MS(3, 3); edm::LogWarning("KMTFCore") << "Multiple scattering term for kSlope = " << MS(4, 4); } + edm::LogWarning("KMTFCore") << "[POST-PROP] step " << (step - 1) + << ": KNew=" << KNew << " phiNew=" << phiNew << " phiBNew=" << phiBNew + << " zNew=" << zNew << " kSlopeNew=" << kSlopeNew + << " convergeTerm=" << convergeTerm << " zdeltaR_dig=" << zdeltaR_dig; track.setCovariance(cov); - if (verbose_) { - edm::LogWarning("KMTFCore") << "z prop step " << step << "->" << (step-1) - << ": z=" << z << " -> " << zNew - << " (convergeTerm=" << convergeTerm << ", kSlope=" << kSlope - << ", zdeltaR_dig=" << zdeltaR_dig << ", wheel=" << track.wheel() << ")"; - } track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); } @@ -646,6 +660,11 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub residual[1] = phiB - trackPhiB; residual[2] = z - trackz; residual[3] = kSlope - trackSlope; + + edm::LogWarning("KMTFCore") << "[STUB] step=" << track.step() + << " stub(phi=" << phi << " phiB=" << phiB << " z=" << z << " kSlope=" << kSlope << ")" + << " track(phi=" << trackPhi << " phiB=" << trackPhiB << " z=" << trackz << " kSlope=" << trackSlope << ")" + << " residual=(" << int(residual[0]) << " " << int(residual[1]) << " " << int(residual[2]) << " " << int(residual[3]) << ")"; Matrix45 H; H(0, 0) = 0.0; @@ -722,18 +741,19 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub << " | residual z=" << residual(2) << " kSlope=" << residual(3); } - + track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); const Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; - for (int i = 0; i < 5; i++) - for (int j = i; j < 5; j++) - c(i, j) = covNew(i, j); + for (int i = 0; i < 5; i++){ + for (int j = i; j < 5; j++){ + c(i, j) = covNew(i, j);}} - if (verbose_) { - edm::LogWarning("KMTFCore") << "Post Fit Covariance Matrix " << cov(0, 0) << " " << cov(1, 1) << " " << cov(2, 2); - } + edm::LogWarning("KMTFCore") << "[POST-UPDATE] step=" << track.step() + << ": KNew=" << KNew << " phiNew=" << phiNew << " phiBNew=" << phiBNew + << " zNew=" << zNew << " kSlopeNew=" << kSlopeNew + << " cov_diag=(" << covNew(0,0) << " " << covNew(1,1) << " " << covNew(2,2) << " " << covNew(3,3) << " " << covNew(4,4) << ")"; track.setCovariance(c); track.addStub(stub); @@ -757,7 +777,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st residual[0] = ap_fixed(phi - trackPhi); residual[1] = z - trackz; residual[2] = kSlope - trackSlope; - + if (verbose_) { edm::LogWarning("KMTFCore") << "residual phi" << phi << " - " << trackPhi << " = " << int(residual(0)); edm::LogWarning("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); @@ -806,6 +826,11 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; + edm::LogWarning("KMTFCore") << "[POST-UPDATE-1D] step=" << track.step() + << ": K=" << track.curvature() << " phi=" << track.positionAngle() << "trac phiB=" << track.bendingAngle() + << " Track z=" << track.zPosition() << "Track kSlope=" << track.kSlope() + << " cov_diag=(" << covNew(0,0) << " " << covNew(1,1) << " " << covNew(2,2) << " " << covNew(3,3) << " " << covNew(4,4) << ")"; + if (verbose_) { edm::LogWarning("KMTFCore") << "phiUpdate: " << int(Gain(0, 0) * residual(0)) << " " << int(Gain(2, 0) * residual(0)); edm::LogWarning("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) << " * " << residual(1) << " + " << Gain(0, 2) << " * " << residual(2); @@ -840,6 +865,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in if (verbose_) edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << residualPhi.to_int() << " " << phiB << " - " << trackPhiB << " = " << residualPhiB.to_int(); + uint absK = fabs(trackK); if (absK > pow(2, BITSCURV - 2) - 1) @@ -1217,7 +1243,7 @@ int KMTFCore::encode(bool ownwheel, int sector, int tag) { std::pair KMTFCore::getByCode(const std::vector& tracks, int mask) { for (uint i = 0; i < tracks.size(); ++i) { - edm::LogWarning("KMTFCore") << "Code=" << tracks[i].hitPattern() << ", track=" << mask; + //edm::LogWarning("KMTFCore") << "Code=" << tracks[i].hitPattern() << ", track=" << mask; if (tracks[i].hitPattern() == mask) return std::make_pair(true, i); } From 2c2922017b82f020f050a3c55d4284555b829f35 Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 6 Apr 2026 13:10:54 -0500 Subject: [PATCH 12/29] fix initial covariances --- .../L1TMuonPhase2/interface/KMTFTrack.h | 1 + .../Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 4 +- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 119 ++++++++++-------- 3 files changed, 70 insertions(+), 54 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h index 1aa4ca819a282..166b74225a68e 100644 --- a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h +++ b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h @@ -85,6 +85,7 @@ namespace l1t { residuals_.push_back(0); residuals_.push_back(0); residuals_.push_back(0); + residuals_.push_back(0); } reco::LeafCandidate::PolarLorentzVector displacedP4() const { return unconstrainedP4_; } diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index 9f33d491f8b1a..5ffb84518f429 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -3,9 +3,9 @@ gmtKMTFMuons = cms.EDProducer('Phase2L1TGMTKMTFProducer', stubs = cms.InputTag('gmtStubs','kmtf'), - verbose = cms.int32(1), + verbose = cms.int32(0), algo = cms.PSet( - verbose = cms.bool(True), + verbose = cms.bool(False), lutFile = cms.string("L1Trigger/Phase2L1GMT/data/packedGainLUTs.root"), initialK = cms.vdouble(-0.4576229536749278, -0.6364802777566145, -1.0305030909883524, -1.7272067322624118), initialK2 = cms.vdouble(-6.442002637356136e-05, -9.582709649965545e-05, -0.0002741064246218815, -0.0014910074450869175), diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 6c14c184f2e1e..68dc937d2e401 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -109,11 +109,20 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (initialK <= -pow(2, BITSCURV - 1)) initialK = -pow(2, BITSCURV - 1) + 1; track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), phiB, seed->eta1(), seed->eta2()); - edm::LogWarning("KMTFCore") << "------------------"; - edm::LogWarning("KMTFCore") << "[INIT] mask=" << mask << " step=" << track.step() - << " K=" << initialK << " phi=" << seed->coord1() << " phiB=" << phiB - << " z=" << seed->eta1() << " kSlope=" << seed->eta2() - << " seedQual=" << seed->quality() << " wheel=" << seed->etaRegion(); + double ZRES_CONV=65536.0/1500.; + double KRES_CONV=65536.0/2.; + std::cout + << "------------------" + << "[INIT] mask=" << mask + << ", step=" << track.step() + << ", K=" << initialK + << ", phi=" << seed->coord1() + << ", phiB=" << phiB + << ", z=" << seed->eta1()/ZRES_CONV + << ", kSlope=" << seed->eta2()/KRES_CONV + << ", seedQual=" << seed->quality() + << ", wheel=" << seed->etaRegion() + << '\n'; if (seed->quality() < 6) { track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), seed->eta2()); @@ -145,8 +154,13 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef else covariance(2, 2) = float(pointResolutionPhiBH_[seed->depthRegion() - 1]); } - covariance(3,3) = float(pointResolutionz_[seed->depthRegion() - 1]); - covariance(4,4) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); + if (seed->depthRegion() == 4) { + covariance(3,3) = pow(2, 22); + covariance(4,4) = pow(2, 22); + } else { + covariance(3,3) = float(pointResolutionz_[seed->depthRegion() - 1]); + covariance(4,4) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); + } track.setCovariance(covariance); // @@ -244,12 +258,14 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (verbose_) edm::LogWarning("KMTFCore") << "Floating point coordinates at vertex: pt=" << track.pt() << ", eta=" << track.eta() << " phi=" << track.phi(); - edm::LogWarning("KMTFCore") << "[RESULT] mask=" << mask - << " K=" << track.curvatureAtVertex() << " phi=" << track.phiAtVertex() - << " dxy=" << track.dxy() << " z=" << track.zPosition() << " kSlope=" << track.kSlope() - << " pt=" << track.pt() << " eta=" << track.eta() - << " chi2_prompt=" << track.approxPromptChi2() << " chi2_disp=" << track.approxDispChi2() - << " nstubs=" << track.stubs().size() << " hitPattern=" << track.hitPattern(); + double ZRES_CONV=65536.0/1500.; + double KRES_CONV=65536.0/2.; + std::cout << "[RESULT] mask=" << mask + << ", K=" << track.curvatureAtVertex() << ", phi=" << track.phiAtVertex() + << ", dxy=" << track.dxy() << ", z=" << track.zPosition()/ZRES_CONV << ", kSlope=" << track.kSlope()/KRES_CONV + << ", pt=" << track.pt() << ", eta=" << track.eta() + << ", chi2_prompt=" << track.approxPromptChi2() << ", chi2_disp=" << track.approxDispChi2() + << ", nstubs=" << track.stubs().size() << ", hitPattern=" << track.hitPattern() << '\n'; pretracks.push_back(track); } @@ -450,9 +466,11 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { unsigned int step = track.step(); int z = track.zPosition(); int kSlope = track.kSlope(); - edm::LogWarning("KMTFCore") << "[PRE-PROP] step " << step << "->" << (step - 1) - << ": K=" << K << " phi=" << phi << " phiB=" << phiB - << " z=" << z << " kSlope=" << kSlope << " wheel=" << track.wheel(); + double ZRES_CONV=65536.0/1500.; + double KRES_CONV=65536.0/2.; + std::cout << "[PRE-PROP] step " << step << "->" << (step - 1) + << ": K=" << K << ", phi=" << phi << ", phiB=" << phiB + << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ", wheel=" << track.wheel() << '\n'; int charge = 1; @@ -530,22 +548,13 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { //z and kSlope propagation offline studies //zdeltaR are in phyiscal units. convert for the propagation of z. - constexpr double ZRES_CONV = 65536. / 1500.; - constexpr double KRES_CONV = 65536. / 2. ; - constexpr double zdR_CONV = ZRES_CONV / KRES_CONV ; + double zdR_CONV = ZRES_CONV / KRES_CONV ; double zdeltaR_dig = zdeltaR_[step - 1] * zdR_CONV ; int kSlopeNew = kSlope; //convention is plus sign with default kSlope and negative zdeltaR to propagate inward - int convergeTerm = abs((int)(kSlope * zdeltaR_dig)); - int wheel = track.wheel(); int zNew; - if (wheel > 0) - zNew = z - convergeTerm; - else if (wheel < 0) - zNew = z + convergeTerm; - else - zNew = (z > 0) ? z - convergeTerm : z + convergeTerm; + zNew = z - (int)(kSlope * zdeltaR_dig); //Create the transformation matrix @@ -571,12 +580,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { a[16] = 0.0; a[17] = 0.0; a[18] = 1.0; - if (wheel > 0) - a[19] = -zdeltaR_dig; - else if (wheel < 0) - a[19] = zdeltaR_dig; - else - a[19] = (z > 0) ? -zdeltaR_dig : zdeltaR_dig; + a[19] = -zdeltaR_dig; a[20] = 0.0; a[21] = 0.0; a[22] = 0.0; @@ -622,10 +626,10 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { edm::LogWarning("KMTFCore") << "Multiple scattering term for z = " << MS(3, 3); edm::LogWarning("KMTFCore") << "Multiple scattering term for kSlope = " << MS(4, 4); } - edm::LogWarning("KMTFCore") << "[POST-PROP] step " << (step - 1) - << ": KNew=" << KNew << " phiNew=" << phiNew << " phiBNew=" << phiBNew - << " zNew=" << zNew << " kSlopeNew=" << kSlopeNew - << " convergeTerm=" << convergeTerm << " zdeltaR_dig=" << zdeltaR_dig; + std::cout << "[POST-PROP] step " << (step - 1) + << ": KNew=" << KNew << ", phiNew=" << phiNew << ", phiBNew=" << phiBNew + << ", zNew=" << zNew/ZRES_CONV << ", kSlopeNew=" << kSlopeNew/KRES_CONV + << ", zdeltaR_dig=" << zdeltaR_dig << '\n'; track.setCovariance(cov); track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); @@ -660,11 +664,12 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub residual[1] = phiB - trackPhiB; residual[2] = z - trackz; residual[3] = kSlope - trackSlope; - - edm::LogWarning("KMTFCore") << "[STUB] step=" << track.step() - << " stub(phi=" << phi << " phiB=" << phiB << " z=" << z << " kSlope=" << kSlope << ")" - << " track(phi=" << trackPhi << " phiB=" << trackPhiB << " z=" << trackz << " kSlope=" << trackSlope << ")" - << " residual=(" << int(residual[0]) << " " << int(residual[1]) << " " << int(residual[2]) << " " << int(residual[3]) << ")"; + double ZRES_CONV=65536.0/1500.; + double KRES_CONV=65536.0/2.; + std::cout << "[STUB] step=" << track.step() + << ", stub(phi=" << phi << ", phiB=" << phiB << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" + << " track(phi=" << trackPhi << ", phiB=" << trackPhiB << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" + << " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << ", " << int(residual[3]) << ")" << '\n'; Matrix45 H; H(0, 0) = 0.0; @@ -698,8 +703,6 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - edm::LogWarning("KMTFCore") << "=== updateOffline step=" << track.step() << " ==="; - edm::LogWarning("KMTFCore") << "Pre-fit cov diag: " << cov(0,0) << " " << cov(1,1) << " " << cov(2,2) << " " << cov(3,3) << " " << cov(4,4); CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; @@ -750,10 +753,10 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub for (int j = i; j < 5; j++){ c(i, j) = covNew(i, j);}} - edm::LogWarning("KMTFCore") << "[POST-UPDATE] step=" << track.step() + std::cout << "[POST-UPDATE] step=" << track.step() << ": KNew=" << KNew << " phiNew=" << phiNew << " phiBNew=" << phiBNew - << " zNew=" << zNew << " kSlopeNew=" << kSlopeNew - << " cov_diag=(" << covNew(0,0) << " " << covNew(1,1) << " " << covNew(2,2) << " " << covNew(3,3) << " " << covNew(4,4) << ")"; + << " zNew=" << zNew/ZRES_CONV << " kSlopeNew=" << kSlopeNew/KRES_CONV + << " cov_diag=(" << covNew(0,0) << " " << covNew(1,1) << " " << covNew(2,2) << " " << covNew(3,3) << " " << covNew(4,4) << ")" << '\n'; track.setCovariance(c); track.addStub(stub); @@ -777,6 +780,14 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st residual[0] = ap_fixed(phi - trackPhi); residual[1] = z - trackz; residual[2] = kSlope - trackSlope; + + double ZRES_CONV=65536.0/1500.; + double KRES_CONV=65536.0/2.; + std::cout << "[STUB-1D] step=" << track.step() + << ", stub(phi=" << phi << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" + << " track(phi=" << trackPhi << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" + << " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << '\n'; + if (verbose_) { edm::LogWarning("KMTFCore") << "residual phi" << phi << " - " << trackPhi << " = " << int(residual(0)); @@ -826,10 +837,10 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; - edm::LogWarning("KMTFCore") << "[POST-UPDATE-1D] step=" << track.step() - << ": K=" << track.curvature() << " phi=" << track.positionAngle() << "trac phiB=" << track.bendingAngle() - << " Track z=" << track.zPosition() << "Track kSlope=" << track.kSlope() - << " cov_diag=(" << covNew(0,0) << " " << covNew(1,1) << " " << covNew(2,2) << " " << covNew(3,3) << " " << covNew(4,4) << ")"; + std::cout << "[POST-UPDATE-1D] step=" << track.step() + << ": Track K=" << track.curvature() << ", Track phi=" << track.positionAngle() << ", Track phiB=" << track.bendingAngle() + << ", Track z=" << track.zPosition()/ZRES_CONV << ", Track kSlope=" << track.kSlope()/KRES_CONV + << " cov_diag=(" << covNew(0,0) << ", " << covNew(1,1) << ", " << covNew(2,2) << ", " << covNew(3,3) << ", " << covNew(4,4) << ")" << '\n'; if (verbose_) { edm::LogWarning("KMTFCore") << "phiUpdate: " << int(Gain(0, 0) * residual(0)) << " " << int(Gain(2, 0) * residual(0)); @@ -1051,7 +1062,11 @@ int KMTFCore::customBitmask(unsigned int bit1, unsigned int bit2, unsigned int b bool KMTFCore::getBit(int bitmask, int pos) { return (bitmask & (1 << pos)) >> pos; } void KMTFCore::setFourVectors(l1t::KMTFTrack& track) { - int etaINT = track.coarseEta(); + //int etaINT = track.coarseEta(); + //new track eta with linear fit calibrated to gen eta. abandoning the legacy approach of setting track eta from coarseEta + const double m = 0.03458; + const double b = 0.7446; + int etaINT = int(round(m * track.kSlope() + b)); double lsbEta = M_PI / pow(2, 12); int charge = 1; From 4b648c69e99c68dc835300285da3825812c429b5 Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 6 Apr 2026 18:56:23 -0500 Subject: [PATCH 13/29] kSlope point resolution --- L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index 5ffb84518f429..71166e7aad49d 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -67,7 +67,7 @@ pointResolutionPhiBL = cms.vdouble(161519.85395846734, 155051.58394241595, 149693.88179343447, 174896.46766622085), pointResolutionVertex = cms.double(1.), pointResolutionz = cms.vdouble(214369, 9980.01, 9254.44, 9254.44), - pointResolutionkSlope = cms.vdouble(214369, 9980.01, 9254.44, 9254.44), + pointResolutionkSlope = cms.vdouble(186624, 350464, 375769, 375769), curvResolution1 = cms.vdouble(1, 2.36097e+03, 8.73003e+02, 2.58138e5), curvResolution2 = cms.vdouble(1, 4.903692e+00, 4.87941e+01, 0)), Nprompt = cms.uint32(12), From 93259fa6f8226e388726debb39366c4a1d7a3258 Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 6 Apr 2026 18:57:08 -0500 Subject: [PATCH 14/29] previous propagation residuals --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 68dc937d2e401..8b8720ca8cd3b 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -718,8 +718,11 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); + //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); + //int zNew = trackz + int(Gain(3, 1) * residual(1)); int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); + //int kSlopeNew = trackSlope + int(Gain(4, 2) * residual(2)); track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); @@ -830,8 +833,10 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); - int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); - int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); + //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); + int zNew = trackz + int(Gain(3, 1) * residual(1)); + //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); + int kSlopeNew = trackSlope + int(Gain(4, 2) * residual(2)); track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); Matrix55 covNew = cov - Gain * (H * cov); From d9dbe79b1fa385985cbdabfddbb9de91bc08ed0a Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 6 Apr 2026 21:16:25 -0500 Subject: [PATCH 15/29] latest --- L1Trigger/Phase2L1GMT/interface/KMTFCore.h | 2 + L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 207 ++++++++++++--------- 2 files changed, 116 insertions(+), 93 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h index a86c526b5daf0..564774fcd00fd 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h @@ -33,6 +33,8 @@ namespace Phase2L1GMT { typedef ROOT::Math::SMatrix Matrix55; typedef ROOT::Math::SMatrix Matrix15; typedef ROOT::Math::SMatrix Matrix51; + typedef ROOT::Math::SMatrix Matrix52; + typedef ROOT::Math::SMatrix Matrix25; KMTFCore(const edm::ParameterSet& settings); diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 8b8720ca8cd3b..a1c69570e3021 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -111,18 +111,18 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), phiB, seed->eta1(), seed->eta2()); double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; - std::cout - << "------------------" - << "[INIT] mask=" << mask - << ", step=" << track.step() - << ", K=" << initialK - << ", phi=" << seed->coord1() - << ", phiB=" << phiB - << ", z=" << seed->eta1()/ZRES_CONV - << ", kSlope=" << seed->eta2()/KRES_CONV - << ", seedQual=" << seed->quality() - << ", wheel=" << seed->etaRegion() - << '\n'; + //std::cout + //<< "------------------" + //<< "[INIT] mask=" << mask + //<< ", step=" << track.step() + //<< ", K=" << initialK + //<< ", phi=" << seed->coord1() + //<< ", phiB=" << phiB + //<< ", z=" << seed->eta1()/ZRES_CONV + //<< ", kSlope=" << seed->eta2()/KRES_CONV + //<< ", seedQual=" << seed->quality() + //<< ", wheel=" << seed->etaRegion() + //<< '\n'; if (seed->quality() < 6) { track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), seed->eta2()); @@ -260,12 +260,12 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef << ", eta=" << track.eta() << " phi=" << track.phi(); double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; - std::cout << "[RESULT] mask=" << mask - << ", K=" << track.curvatureAtVertex() << ", phi=" << track.phiAtVertex() - << ", dxy=" << track.dxy() << ", z=" << track.zPosition()/ZRES_CONV << ", kSlope=" << track.kSlope()/KRES_CONV - << ", pt=" << track.pt() << ", eta=" << track.eta() - << ", chi2_prompt=" << track.approxPromptChi2() << ", chi2_disp=" << track.approxDispChi2() - << ", nstubs=" << track.stubs().size() << ", hitPattern=" << track.hitPattern() << '\n'; + //std::cout << "[RESULT] mask=" << mask + //<< ", K=" << track.curvatureAtVertex() << ", phi=" << track.phiAtVertex() + //<< ", dxy=" << track.dxy() << ", z=" << track.zPosition()/ZRES_CONV << ", kSlope=" << track.kSlope()/KRES_CONV + //<< ", pt=" << track.pt() << ", eta=" << track.eta() + //<< ", chi2_prompt=" << track.approxPromptChi2() << ", chi2_disp=" << track.approxDispChi2() + //<< ", nstubs=" << track.stubs().size() << ", hitPattern=" << track.hitPattern() << '\n'; pretracks.push_back(track); } @@ -468,9 +468,9 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { int kSlope = track.kSlope(); double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; - std::cout << "[PRE-PROP] step " << step << "->" << (step - 1) - << ": K=" << K << ", phi=" << phi << ", phiB=" << phiB - << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ", wheel=" << track.wheel() << '\n'; + //std::cout << "[PRE-PROP] step " << step << "->" << (step - 1) + //<< ": K=" << K << ", phi=" << phi << ", phiB=" << phiB + //<< ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ", wheel=" << track.wheel() << '\n'; int charge = 1; @@ -626,10 +626,10 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { edm::LogWarning("KMTFCore") << "Multiple scattering term for z = " << MS(3, 3); edm::LogWarning("KMTFCore") << "Multiple scattering term for kSlope = " << MS(4, 4); } - std::cout << "[POST-PROP] step " << (step - 1) - << ": KNew=" << KNew << ", phiNew=" << phiNew << ", phiBNew=" << phiBNew - << ", zNew=" << zNew/ZRES_CONV << ", kSlopeNew=" << kSlopeNew/KRES_CONV - << ", zdeltaR_dig=" << zdeltaR_dig << '\n'; + //std::cout << "[POST-PROP] step " << (step - 1) + //<< ": KNew=" << KNew << ", phiNew=" << phiNew << ", phiBNew=" << phiBNew + //<< ", zNew=" << zNew/ZRES_CONV << ", kSlopeNew=" << kSlopeNew/KRES_CONV + //<< ", zdeltaR_dig=" << zdeltaR_dig << '\n'; track.setCovariance(cov); track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); @@ -659,19 +659,21 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int z = stub->eta1(); int kSlope = stub->eta2(); - Vector4 residual; + //Vector4 residual; + Vector3 residual; residual[0] = ap_fixed(phi - trackPhi); residual[1] = phiB - trackPhiB; residual[2] = z - trackz; - residual[3] = kSlope - trackSlope; + //residual[3] = kSlope - trackSlope; double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; - std::cout << "[STUB] step=" << track.step() - << ", stub(phi=" << phi << ", phiB=" << phiB << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" - << " track(phi=" << trackPhi << ", phiB=" << trackPhiB << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" - << " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << ", " << int(residual[3]) << ")" << '\n'; + //std::cout << "[STUB] step=" << track.step() + //<< ", stub(phi=" << phi << ", phiB=" << phiB << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" + //<< " track(phi=" << trackPhi << ", phiB=" << trackPhiB << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" + //<< " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << ", " << int(residual[3]) << ")" << '\n'; - Matrix45 H; + //Matrix45 H; + Matrix35 H; H(0, 0) = 0.0; H(0, 1) = 1.0; H(0, 2) = 0.0; @@ -687,44 +689,53 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub H(2, 2) = 0.0; H(2, 3) = 1.0; H(2, 4) = 0.0; - H(3, 0) = 0.0; - H(3, 1) = 0.0; - H(3, 2) = 0.0; - H(3, 3) = 0.0; - H(3, 4) = 1.0; + //H(3, 0) = 0.0; + //H(3, 1) = 0.0; + //H(3, 2) = 0.0; + //H(3, 3) = 0.0; + //H(3, 4) = 1.0; const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] : pointResolutionPhiBH_[track.step() - 1]}; - const double r[]{pointResolutionPhi_, - 0.0, r11, - 0.0, 0.0, pointResolutionz_[track.step() - 1], - 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix4 R(r, 10); + //const double r[]{pointResolutionPhi_, + //0.0, r11, + //0.0, 0.0, pointResolutionz_[track.step() - 1], + //0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + //const CovarianceMatrix4 R(r, 10); + const double r[]{pointResolutionPhi_, + 0.0, r11, + 0.0, 0.0, pointResolutionz_[track.step() - 1]}; + const CovarianceMatrix3 R(r, 6); + const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; + //CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; + CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; + //const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; + const Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; - //track.setKalmanGain( - //track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), Gain(1, 0), Gain(1, 1), Gain(2, 0), Gain(2, 1)); + track.setKalmanGain( + track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); - int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2) + Gain(0, 3) * residual(3))); + //int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2) + Gain(0, 3) * residual(3))); + int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2))); if (fabs(KNew) > pow(2, BITSCURV - 1)) return false; int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); - //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); - int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); - //int zNew = trackz + int(Gain(3, 1) * residual(1)); - int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); - //int kSlopeNew = trackSlope + int(Gain(4, 2) * residual(2)); + //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); + //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); + int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); + //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); + int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); - track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); + //track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); + track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew)); if (verbose_) { edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << int(residual[0]) << " " << phiB @@ -738,13 +749,13 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub edm::LogWarning("KMTFCore") << " z = " << trackz << " + " << Gain(3,0) << "*" << residual(0) << " + " << Gain(3,1) << "*" << residual(1) << " + " << Gain(3,2) << "*" << residual(2) - << " + " << Gain(3,3) << "*" << residual(3) << " = " << zNew; + << zNew; edm::LogWarning("KMTFCore") << " kSlope = " << trackSlope << " + " << Gain(4,0) << "*" << residual(0) << " + " << Gain(4,1) << "*" << residual(1) << " + " << Gain(4,2) << "*" << residual(2) - << " + " << Gain(4,3) << "*" << residual(3) << " = " << kSlopeNew; + << " = " << kSlopeNew; edm::LogWarning("KMTFCore") << " stub z=" << z << " kSlope=" << kSlope - << " | residual z=" << residual(2) << " kSlope=" << residual(3); + << " | residual z=" << residual(2); } @@ -756,10 +767,10 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub for (int j = i; j < 5; j++){ c(i, j) = covNew(i, j);}} - std::cout << "[POST-UPDATE] step=" << track.step() - << ": KNew=" << KNew << " phiNew=" << phiNew << " phiBNew=" << phiBNew - << " zNew=" << zNew/ZRES_CONV << " kSlopeNew=" << kSlopeNew/KRES_CONV - << " cov_diag=(" << covNew(0,0) << " " << covNew(1,1) << " " << covNew(2,2) << " " << covNew(3,3) << " " << covNew(4,4) << ")" << '\n'; + //std::cout << "[POST-UPDATE] step=" << track.step() + //<< ": KNew=" << KNew << " phiNew=" << phiNew << " phiBNew=" << phiBNew + //<< " zNew=" << zNew/ZRES_CONV << " kSlopeNew=" << kSlopeNew/KRES_CONV + //<< " cov_diag=(" << covNew(0,0) << " " << covNew(1,1) << " " << covNew(2,2) << " " << covNew(3,3) << " " << covNew(4,4) << ")" << '\n'; track.setCovariance(c); track.addStub(stub); @@ -779,26 +790,27 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int z = stub->eta1(); int kSlope = stub->eta2(); - Vector3 residual; + //Vector3 residual; + Vector2 residual; residual[0] = ap_fixed(phi - trackPhi); residual[1] = z - trackz; - residual[2] = kSlope - trackSlope; + //residual[2] = kSlope - trackSlope; double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; - std::cout << "[STUB-1D] step=" << track.step() - << ", stub(phi=" << phi << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" - << " track(phi=" << trackPhi << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" - << " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << '\n'; + //std::cout << "[STUB-1D] step=" << track.step() + //<< ", stub(phi=" << phi << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" + //<< " track(phi=" << trackPhi << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" + //<< " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << '\n'; if (verbose_) { edm::LogWarning("KMTFCore") << "residual phi" << phi << " - " << trackPhi << " = " << int(residual(0)); edm::LogWarning("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); - edm::LogWarning("KMTFCore") << "residual kSlope" << kSlope << " - " << trackSlope << " = " << int(residual(2)); } - Matrix35 H; + //Matrix35 H; + Matrix25 H; H(0, 0) = 0.0; H(0, 1) = 1.0; H(0, 2) = 0.0; @@ -809,50 +821,59 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st H(1, 2) = 0.0; H(1, 3) = 1.0; H(1, 4) = 0.0; - H(2, 0) = 0.0; - H(2, 1) = 0.0; - H(2, 2) = 0.0; - H(2, 3) = 0.0; - H(2, 4) = 1.0; + //H(2, 0) = 0.0; + //H(2, 1) = 0.0; + //H(2, 2) = 0.0; + //H(2, 3) = 0.0; + //H(2, 4) = 1.0; + + //const double r[]{pointResolutionPhi_, 0.0, + //pointResolutionz_[track.step() - 1], + //0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; + //const CovarianceMatrix3 R(r, 6); + const double r[]{pointResolutionPhi_, + 0.0, pointResolutionz_[track.step() - 1]}; + const CovarianceMatrix2 R(r, 3); + - const double r[]{pointResolutionPhi_, 0.0, - pointResolutionz_[track.step() - 1], - 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix3 R(r, 6); const std::vector& covLine = track.covariance(); l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; + //CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; + CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; + //Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; + Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; - //track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, Gain(1, 0), 0.0, Gain(2, 0), 0.0); + track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, 1, 0, Gain(2, 0), 0.0); - int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); + //int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); + int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1)), pow(2, BITSCURV - 1)); int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); + //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); - int zNew = trackz + int(Gain(3, 1) * residual(1)); + int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); - int kSlopeNew = trackSlope + int(Gain(4, 2) * residual(2)); + int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; - std::cout << "[POST-UPDATE-1D] step=" << track.step() - << ": Track K=" << track.curvature() << ", Track phi=" << track.positionAngle() << ", Track phiB=" << track.bendingAngle() - << ", Track z=" << track.zPosition()/ZRES_CONV << ", Track kSlope=" << track.kSlope()/KRES_CONV - << " cov_diag=(" << covNew(0,0) << ", " << covNew(1,1) << ", " << covNew(2,2) << ", " << covNew(3,3) << ", " << covNew(4,4) << ")" << '\n'; + //std::cout << "[POST-UPDATE-1D] step=" << track.step() + //<< ": Track K=" << track.curvature() << ", Track phi=" << track.positionAngle() << ", Track phiB=" << track.bendingAngle() + //<< ", Track z=" << track.zPosition()/ZRES_CONV << ", Track kSlope=" << track.kSlope()/KRES_CONV + //<< " cov_diag=(" << covNew(0,0) << ", " << covNew(1,1) << ", " << covNew(2,2) << ", " << covNew(3,3) << ", " << covNew(4,4) << ")" << '\n'; if (verbose_) { edm::LogWarning("KMTFCore") << "phiUpdate: " << int(Gain(0, 0) * residual(0)) << " " << int(Gain(2, 0) * residual(0)); - edm::LogWarning("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) << " * " << residual(1) << " + " << Gain(0, 2) << " * " << residual(2); - edm::LogWarning("KMTFCore") << " phiBNew = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1) << " + " << Gain(2, 2) << " * " << residual(2); - edm::LogWarning("KMTFCore") << " zNew = " << trackz << " + " << Gain(3, 0) << " * " << residual(0) << " + " << Gain(3, 1) << " * " << residual(1) << " + " << Gain(3, 2) << " * " << residual(2); - edm::LogWarning("KMTFCore") << " kSlopeNew = " << trackSlope << " + " << Gain(4, 0) << " * " << residual(0) << " + " << Gain(4, 1) << " * " << residual(1) << " + " << Gain(4, 2) << " * " << residual(2); + edm::LogWarning("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) << " * " << residual(1); + edm::LogWarning("KMTFCore") << " phiBNew = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1); + edm::LogWarning("KMTFCore") << " zNew = " << trackz << " + " << Gain(3, 0) << " * " << residual(0) << " + " << Gain(3, 1) << " * " << residual(1); + edm::LogWarning("KMTFCore") << " kSlopeNew = " << trackSlope << " + " << Gain(4, 0) << " * " << residual(0) << " + " << Gain(4, 1) << " * " << residual(1); } for (int i = 0; i < 5; i++) From 63e041efb595883747d864d2750700a5c3dd3c0a Mon Sep 17 00:00:00 2001 From: delano campos Date: Thu, 9 Apr 2026 13:33:16 -0500 Subject: [PATCH 16/29] reverting back to using kSlope in measurement space for residual --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 161 ++++++++++++++------------ 1 file changed, 90 insertions(+), 71 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index a1c69570e3021..e7e81ad9e69c0 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -552,9 +552,8 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { double zdeltaR_dig = zdeltaR_[step - 1] * zdR_CONV ; int kSlopeNew = kSlope; - //convention is plus sign with default kSlope and negative zdeltaR to propagate inward int zNew; - zNew = z - (int)(kSlope * zdeltaR_dig); + zNew = z -(int)(kSlope * zdeltaR_dig); //Create the transformation matrix @@ -580,7 +579,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { a[16] = 0.0; a[17] = 0.0; a[18] = 1.0; - a[19] = -zdeltaR_dig; + a[19] = zdeltaR_dig; a[20] = 0.0; a[21] = 0.0; a[22] = 0.0; @@ -659,12 +658,12 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int z = stub->eta1(); int kSlope = stub->eta2(); - //Vector4 residual; - Vector3 residual; + Vector4 residual; + //Vector3 residual; residual[0] = ap_fixed(phi - trackPhi); residual[1] = phiB - trackPhiB; residual[2] = z - trackz; - //residual[3] = kSlope - trackSlope; + residual[3] = kSlope - trackSlope; double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; //std::cout << "[STUB] step=" << track.step() @@ -672,8 +671,8 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub //<< " track(phi=" << trackPhi << ", phiB=" << trackPhiB << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" //<< " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << ", " << int(residual[3]) << ")" << '\n'; - //Matrix45 H; - Matrix35 H; + Matrix45 H; + //Matrix35 H; H(0, 0) = 0.0; H(0, 1) = 1.0; H(0, 2) = 0.0; @@ -689,53 +688,64 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub H(2, 2) = 0.0; H(2, 3) = 1.0; H(2, 4) = 0.0; - //H(3, 0) = 0.0; - //H(3, 1) = 0.0; - //H(3, 2) = 0.0; - //H(3, 3) = 0.0; - //H(3, 4) = 1.0; + H(3, 0) = 0.0; + H(3, 1) = 0.0; + H(3, 2) = 0.0; + H(3, 3) = 0.0; + H(3, 4) = 1.0; const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] : pointResolutionPhiBH_[track.step() - 1]}; - //const double r[]{pointResolutionPhi_, - //0.0, r11, - //0.0, 0.0, pointResolutionz_[track.step() - 1], - //0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - //const CovarianceMatrix4 R(r, 10); - const double r[]{pointResolutionPhi_, - 0.0, r11, - 0.0, 0.0, pointResolutionz_[track.step() - 1]}; - const CovarianceMatrix3 R(r, 6); + const double r[]{pointResolutionPhi_, + 0.0, r11, + 0.0, 0.0, pointResolutionz_[track.step() - 1], + 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix4 R(r, 10); + //const double r[]{pointResolutionPhi_, + // 0.0, r11, + // 0.0, 0.0, pointResolutionz_[track.step() - 1]}; + //const CovarianceMatrix3 R(r, 6); const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - //CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; - CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; + CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; + //CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - //const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; - const Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; + const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; + //const Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; track.setKalmanGain( track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); - //int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2) + Gain(0, 3) * residual(3))); - int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2))); + int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2) + Gain(0, 3) * residual(3))); + //int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2))); if (fabs(KNew) > pow(2, BITSCURV - 1)) return false; int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); - //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); - int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); - //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); - int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); - - //track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); - track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew)); + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); + //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); + int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); + //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); + int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); + //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); + //std::cout << "[UPDATE-OFFLINE] step=" << track.step() + //<< " Gain(3,0)=" << Gain(3,0) << " Gain(3,1)=" << Gain(3,1) << " Gain(3,2)=" << Gain(3,2) + //<< " Gain(4,0)=" << Gain(4,0) << " Gain(4,1)=" << Gain(4,1) << " Gain(4,2)=" << Gain(4,2) << '\n'; + //std::cout << " zNew = " << trackz + //<< " + (" << Gain(3,0) << "*" << int(residual(0)) + //<< " + " << Gain(3,1) << "*" << int(residual(1)) + //<< " + " << Gain(3,2) << "*" << int(residual(2)) << ") = " << zNew << '\n'; + //std::cout << " kSlopeNew = " << trackSlope + //<< " + (" << Gain(4,0) << "*" << int(residual(0)) + //<< " + " << Gain(4,1) << "*" << int(residual(1)) + //<< " + " << Gain(4,2) << "*" << int(residual(2)) << ") = " << kSlopeNew << '\n'; + + track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); + //track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew)); if (verbose_) { edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << int(residual[0]) << " " << phiB @@ -790,11 +800,11 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int z = stub->eta1(); int kSlope = stub->eta2(); - //Vector3 residual; - Vector2 residual; + Vector3 residual; + //Vector2 residual; residual[0] = ap_fixed(phi - trackPhi); residual[1] = z - trackz; - //residual[2] = kSlope - trackSlope; + residual[2] = kSlope - trackSlope; double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; @@ -809,8 +819,8 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st edm::LogWarning("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); } - //Matrix35 H; - Matrix25 H; + Matrix35 H; + //Matrix25 H; H(0, 0) = 0.0; H(0, 1) = 1.0; H(0, 2) = 0.0; @@ -821,45 +831,54 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st H(1, 2) = 0.0; H(1, 3) = 1.0; H(1, 4) = 0.0; - //H(2, 0) = 0.0; - //H(2, 1) = 0.0; - //H(2, 2) = 0.0; - //H(2, 3) = 0.0; - //H(2, 4) = 1.0; - - //const double r[]{pointResolutionPhi_, 0.0, - //pointResolutionz_[track.step() - 1], - //0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; - //const CovarianceMatrix3 R(r, 6); - const double r[]{pointResolutionPhi_, - 0.0, pointResolutionz_[track.step() - 1]}; - const CovarianceMatrix2 R(r, 3); + H(2, 0) = 0.0; + H(2, 1) = 0.0; + H(2, 2) = 0.0; + H(2, 3) = 0.0; + H(2, 4) = 1.0; + + const double r[]{pointResolutionPhi_, 0.0, + pointResolutionz_[track.step() - 1], + 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix3 R(r, 6); + //const double r[]{pointResolutionPhi_, + // 0.0, pointResolutionz_[track.step() - 1]}; + //const CovarianceMatrix2 R(r, 3); const std::vector& covLine = track.covariance(); l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - //CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; - CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; + CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; + //CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - //Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; - Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; + Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; + //Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, 1, 0, Gain(2, 0), 0.0); - //int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); - int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1)), pow(2, BITSCURV - 1)); + int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); + //int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1)), pow(2, BITSCURV - 1)); int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); - //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); - int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); - //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); - int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); + //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); + int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); + //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); + int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); + //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); + //std::cout << "[UPDATE-OFFLINE-1D] step=" << track.step() + //<< " Gain(3,0)=" << Gain(3,0) << " Gain(3,1)=" << Gain(3,1) + //<< " Gain(4,0)=" << Gain(4,0) << " Gain(4,1)=" << Gain(4,1) << '\n'; + //std::cout << " zNew = " << trackz + // << " + (" << Gain(3,0) << "*" << int(residual(0)) + // << " + " << Gain(3,1) << "*" << int(residual(1)) << ") = " << zNew << '\n'; + //std::cout << " kSlopeNew = " << trackSlope + //<< " + (" << Gain(4,0) << "*" << int(residual(0)) + //<< " + " << Gain(4,1) << "*" << int(residual(1)) << ") = " << kSlopeNew << '\n'; Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; @@ -1088,11 +1107,11 @@ int KMTFCore::customBitmask(unsigned int bit1, unsigned int bit2, unsigned int b bool KMTFCore::getBit(int bitmask, int pos) { return (bitmask & (1 << pos)) >> pos; } void KMTFCore::setFourVectors(l1t::KMTFTrack& track) { - //int etaINT = track.coarseEta(); + int etaINT = track.coarseEta(); //new track eta with linear fit calibrated to gen eta. abandoning the legacy approach of setting track eta from coarseEta - const double m = 0.03458; - const double b = 0.7446; - int etaINT = int(round(m * track.kSlope() + b)); + //const double m = 0.03458; + //const double b = 0.7446; + //int etaINT = int(round(m * track.kSlope() + b)); double lsbEta = M_PI / pow(2, 12); int charge = 1; From 1c15a25cb405b8c65870ac6045b0b12f89f1ec12 Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 13 Apr 2026 13:34:42 -0500 Subject: [PATCH 17/29] tests --- .../L1TMuonPhase2/interface/KMTFTrack.h | 6 + DataFormats/L1TMuonPhase2/src/classes_def.xml | 1 + L1Trigger/Phase2L1GMT/interface/KMTFCore.h | 1 + .../Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 2 +- L1Trigger/Phase2L1GMT/src/KMTF.cc | 5 + L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 148 +++++++++++------- 6 files changed, 103 insertions(+), 60 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h index 166b74225a68e..197c63c41a7f6 100644 --- a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h +++ b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h @@ -37,6 +37,7 @@ namespace l1t { approxDispChi2_(0), approxDispErrChi2_(0), hitPattern_(0), + thetaDigiPattern_(0), step_(1), sector_(0), wheel_(0), @@ -72,6 +73,7 @@ namespace l1t { approxDispChi2_(0), approxDispErrChi2_(0), hitPattern_(0), + thetaDigiPattern_(0), step_(seed->depthRegion()), sector_(seed->phiRegion()), wheel_(seed->etaRegion()), @@ -126,6 +128,7 @@ namespace l1t { int approxDispErrChi2() const { return approxDispErrChi2_; } int hitPattern() const { return hitPattern_; } + int thetaDigiPattern() const { return thetaDigiPattern_; } //step; int step() const { return step_; } //sector; @@ -227,6 +230,7 @@ namespace l1t { void setCoarseEta(int eta) { coarseEta_ = eta; } void setHitPattern(int pattern) { hitPattern_ = pattern; } + void setThetaDigiPattern(int theta_pattern) { thetaDigiPattern_ = theta_pattern; } void setApproxChi2(int chi, int chiErr, bool prompt) { if (prompt) { @@ -382,6 +386,8 @@ namespace l1t { //phi bitmask int hitPattern_; + //bitmask pattern based on theta digi presence + int thetaDigiPattern_; //propagation step int step_; diff --git a/DataFormats/L1TMuonPhase2/src/classes_def.xml b/DataFormats/L1TMuonPhase2/src/classes_def.xml index 388e3e68621c7..77127b87326de 100644 --- a/DataFormats/L1TMuonPhase2/src/classes_def.xml +++ b/DataFormats/L1TMuonPhase2/src/classes_def.xml @@ -26,6 +26,7 @@ + diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h index 564774fcd00fd..1413891f66fff 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h @@ -57,6 +57,7 @@ namespace Phase2L1GMT { void vertexConstraintOffline(l1t::KMTFTrack& track); void vertexConstraintLUT(l1t::KMTFTrack& track); int hitPattern(const l1t::KMTFTrack& track); + int thetaDigiPattern(const l1t::KMTFTrack& track); int customBitmask(unsigned int bit1, unsigned int bit2, unsigned int bit3, unsigned int bit4); bool getBit(int bitmask, int pos); void setFourVectors(l1t::KMTFTrack& track); diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index 71166e7aad49d..ede30c1aea441 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -60,7 +60,7 @@ mScatteringPhi = cms.vdouble(0.1169021113298598, 0.00016777763395543814, 0.0004322078772344548, 0.00024985881710722107), mScatteringPhiB = cms.vdouble(.0522762, 0.01762000062188365, 0.03508319015441297, 0.03126825551530328), mScatteringz = cms.vdouble(0.030625, 0.00010609, 0.00033489, 0.00033489), - mScatteringkSlope = cms.vdouble(0.030625, 0.00010609, 0.00033489, 0.00033489), + mScatteringkSlope = cms.vdouble(0.083521, 0.032041, 0.047961, 0.047961), pointResolutionPhi = cms.double(1.), pointResolutionPhiB = cms.double(12493.7429036), pointResolutionPhiBH = cms.vdouble(19925.62953113343, 15583.06791339368, 10258.11768352221, 15462.112839170433), diff --git a/L1Trigger/Phase2L1GMT/src/KMTF.cc b/L1Trigger/Phase2L1GMT/src/KMTF.cc index 1cb40bc1c72b4..5a5c4613bc2b4 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTF.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTF.cc @@ -301,6 +301,8 @@ void KMTF::overlapCleanTrack(l1t::KMTFTrack& source, const l1t::KMTFTrack& other int id2 = vertex ? other.id() & 0x1 : other.id() & 0x2; bool keep = true; unsigned int pattern = 0; + unsigned int thetaPattern = 0; + if (id1 == 0) keep = false; else if (id1 != 0 && id2 != 0) { @@ -320,10 +322,13 @@ void KMTF::overlapCleanTrack(l1t::KMTFTrack& source, const l1t::KMTFTrack& other if (ok) { stubs.push_back(s1); pattern = pattern | (1 << (s1->depthRegion() - 1)); + if (s1->depthRegion() != 4 && s1->etaQuality() > 0) + thetaPattern |= (1 << (s1->depthRegion() - 1)); } } source.setStubs(stubs); source.setHitPattern(pattern); + source.setThetaDigiPattern(thetaPattern); } std::vector KMTF::cleanRegion(const std::vector& tracks2, diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index e7e81ad9e69c0..9c61f28005759 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -131,6 +131,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef edm::LogWarning("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK << " z=" << seed->eta1() << " kSlope=" << seed->eta2(); } track.setHitPattern(hitPattern(track)); + track.setThetaDigiPattern(thetaDigiPattern(track)); //set covariance l1t::CovarianceMatrix5dim covariance; float DK = curvResolution1_[track.step() - 1] + curvResolution2_[track.step() - 1] * initialK * initialK; @@ -553,7 +554,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { int kSlopeNew = kSlope; int zNew; - zNew = z -(int)(kSlope * zdeltaR_dig); + zNew = z - (int)(kSlope * zdeltaR_dig); //Create the transformation matrix @@ -658,12 +659,13 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int z = stub->eta1(); int kSlope = stub->eta2(); - Vector4 residual; + //Vector4 residual; //Vector3 residual; - residual[0] = ap_fixed(phi - trackPhi); - residual[1] = phiB - trackPhiB; - residual[2] = z - trackz; - residual[3] = kSlope - trackSlope; + Vector2 residual; + //residual[0] = ap_fixed(phi - trackPhi); + //residual[1] = phiB - trackPhiB; + residual[0] = z - trackz; + residual[1] = kSlope - trackSlope; double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; //std::cout << "[STUB] step=" << track.step() @@ -671,67 +673,77 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub //<< " track(phi=" << trackPhi << ", phiB=" << trackPhiB << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" //<< " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << ", " << int(residual[3]) << ")" << '\n'; - Matrix45 H; + //Matrix45 H; //Matrix35 H; + Matrix25 H; H(0, 0) = 0.0; - H(0, 1) = 1.0; + H(0, 1) = 0.0; H(0, 2) = 0.0; - H(0, 3) = 0.0; + H(0, 3) = 1.0; H(0, 4) = 0.0; H(1, 0) = 0.0; H(1, 1) = 0.0; - H(1, 2) = 1.0; + H(1, 2) = 0.0; H(1, 3) = 0.0; - H(1, 4) = 0.0; - H(2, 0) = 0.0; - H(2, 1) = 0.0; - H(2, 2) = 0.0; - H(2, 3) = 1.0; - H(2, 4) = 0.0; - H(3, 0) = 0.0; - H(3, 1) = 0.0; - H(3, 2) = 0.0; - H(3, 3) = 0.0; - H(3, 4) = 1.0; + H(1, 4) = 1.0; + //H(2, 0) = 0.0; + //H(2, 1) = 0.0; + //H(2, 2) = 0.0; + //H(2, 3) = 1.0; + //H(2, 4) = 0.0; + //H(3, 0) = 0.0; + //H(3, 1) = 0.0; + //H(3, 2) = 0.0; + //H(3, 3) = 0.0; + //H(3, 4) = 1.0; const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] : pointResolutionPhiBH_[track.step() - 1]}; - const double r[]{pointResolutionPhi_, - 0.0, r11, - 0.0, 0.0, pointResolutionz_[track.step() - 1], - 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix4 R(r, 10); + //const double r[]{pointResolutionPhi_, + // 0.0, r11, + // 0.0, 0.0, pointResolutionz_[track.step() - 1], + // 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + //const CovarianceMatrix4 R(r, 10); //const double r[]{pointResolutionPhi_, // 0.0, r11, // 0.0, 0.0, pointResolutionz_[track.step() - 1]}; //const CovarianceMatrix3 R(r, 6); + const double r[]{pointResolutionz_[track.step() - 1], + 0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix2 R(r, 3); const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; + //CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; //CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; + CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; + //const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; //const Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; + const Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; track.setKalmanGain( track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); - int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2) + Gain(0, 3) * residual(3))); + //int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2) + Gain(0, 3) * residual(3))); //int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2))); + int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1))); if (fabs(KNew) > pow(2, BITSCURV - 1)) return false; int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); + //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); - int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); + //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); - int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); + int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); + //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); + int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); //std::cout << "[UPDATE-OFFLINE] step=" << track.step() //<< " Gain(3,0)=" << Gain(3,0) << " Gain(3,1)=" << Gain(3,1) << " Gain(3,2)=" << Gain(3,2) //<< " Gain(4,0)=" << Gain(4,0) << " Gain(4,1)=" << Gain(4,1) << " Gain(4,2)=" << Gain(4,2) << '\n'; @@ -744,8 +756,9 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub //<< " + " << Gain(4,1) << "*" << int(residual(1)) //<< " + " << Gain(4,2) << "*" << int(residual(2)) << ") = " << kSlopeNew << '\n'; - track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); + //track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); //track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew)); + track.setResidual(stub->depthRegion() - 1, fabs(z - zNew) + fabs(kSlope - kSlopeNew)); if (verbose_) { edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << int(residual[0]) << " " << phiB @@ -785,6 +798,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub track.setCovariance(c); track.addStub(stub); track.setHitPattern(hitPattern(track)); + track.setThetaDigiPattern(thetaDigiPattern(track)); return true; } @@ -802,9 +816,9 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st Vector3 residual; //Vector2 residual; - residual[0] = ap_fixed(phi - trackPhi); - residual[1] = z - trackz; - residual[2] = kSlope - trackSlope; + //residual[0] = ap_fixed(phi - trackPhi); + residual[0] = z - trackz; + residual[1] = kSlope - trackSlope; double ZRES_CONV=65536.0/1500.; double KRES_CONV=65536.0/2.; @@ -819,43 +833,43 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st edm::LogWarning("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); } - Matrix35 H; - //Matrix25 H; + //Matrix35 H; + Matrix25 H; H(0, 0) = 0.0; - H(0, 1) = 1.0; + H(0, 1) = 0.0; H(0, 2) = 0.0; - H(0, 3) = 0.0; + H(0, 3) = 1.0; H(0, 4) = 0.0; H(1, 0) = 0.0; H(1, 1) = 0.0; H(1, 2) = 0.0; - H(1, 3) = 1.0; - H(1, 4) = 0.0; - H(2, 0) = 0.0; - H(2, 1) = 0.0; - H(2, 2) = 0.0; - H(2, 3) = 0.0; - H(2, 4) = 1.0; - - const double r[]{pointResolutionPhi_, 0.0, - pointResolutionz_[track.step() - 1], - 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix3 R(r, 6); - //const double r[]{pointResolutionPhi_, - // 0.0, pointResolutionz_[track.step() - 1]}; - //const CovarianceMatrix2 R(r, 3); + H(1, 3) = 0.0; + H(1, 4) = 1.0; + //H(2, 0) = 0.0; + //H(2, 1) = 0.0; + //H(2, 2) = 0.0; + //H(2, 3) = 0.0; + //H(2, 4) = 1.0; + + //const double r[]{pointResolutionPhi_, 0.0, + // pointResolutionz_[track.step() - 1], + // 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; + //const CovarianceMatrix3 R(r, 6); + const double r[]{pointResolutionz_[track.step() - 1], + 0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix2 R(r, 3); const std::vector& covLine = track.covariance(); l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; - //CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; + //CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; + CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; - //Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; + //Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; + Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, 1, 0, Gain(2, 0), 0.0); @@ -902,6 +916,8 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st track.setCovariance(c); track.addStub(stub); track.setHitPattern(hitPattern(track)); + track.setThetaDigiPattern(thetaDigiPattern(track)); + return true; } @@ -1006,6 +1022,8 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in track.setCoordinates(track.step(), KNew, phiNew, phiBNew, track.zPosition(), track.kSlope()); track.addStub(stub); track.setHitPattern(hitPattern(track)); + track.setThetaDigiPattern(thetaDigiPattern(track)); + if (verbose_) { edm::LogWarning("KMTFCore") << "Stub station =" << stub->depthRegion(); @@ -1100,6 +1118,18 @@ int KMTFCore::hitPattern(const l1t::KMTFTrack& track) { return mask; } +//returns mask pattern based on stubs with a theta digi or not. e.g. 0010 is a track with stub at station 2 with a theta digi stub +int KMTFCore::thetaDigiPattern(const l1t::KMTFTrack& track) { + unsigned int mask = 0; + for (const auto& stub : track.stubs()) { + if (stub->depthRegion() == 4) + continue; + if (stub->etaQuality() > 0) + mask |= (1 << (stub->depthRegion() - 1)); + } + return mask; +} + int KMTFCore::customBitmask(unsigned int bit1, unsigned int bit2, unsigned int bit3, unsigned int bit4) { return bit1 * 1 + bit2 * 2 + bit3 * 4 + bit4 * 8; } From 13ff9196e469bf0a68e60b55c44647a020be9174 Mon Sep 17 00:00:00 2001 From: delano campos Date: Wed, 15 Apr 2026 13:38:37 -0500 Subject: [PATCH 18/29] testing --- .../L1TMuonPhase2/interface/KMTFTrack.h | 34 ++++++++++++ DataFormats/L1TMuonPhase2/src/classes_def.xml | 5 +- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 52 +++++++++++-------- 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h index 197c63c41a7f6..07af2b60c033d 100644 --- a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h +++ b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h @@ -169,6 +169,16 @@ namespace l1t { return kalmanGain0_; } + const std::vector& convergenceGain(unsigned int step) const { + switch (step) { + case 3: return convergenceGain3_; + case 2: return convergenceGain2_; + case 1: return convergenceGain1_; + case 0: return convergenceGain0_; + } + return convergenceGain0_; + } + //get covariance const std::vector& covariance() const { return covariance_; } @@ -321,6 +331,25 @@ namespace l1t { } } + void setConvergenceGain(unsigned int step, unsigned int K, int priorThetaPattern, + float Gz0, float Gz1, float Gk0, float Gk1) { + std::vector* v = nullptr; + switch (step) { + case 3: v = &convergenceGain3_; break; + case 2: v = &convergenceGain2_; break; + case 1: v = &convergenceGain1_; break; + case 0: v = &convergenceGain0_; break; + default: + throw cms::Exception("WrongCondition") << "Critical ERROR on setting the convergence gain\n"; + } + v->push_back(static_cast(K)); + v->push_back(static_cast(priorThetaPattern)); + v->push_back(Gz0); + v->push_back(Gz1); + v->push_back(Gk0); + v->push_back(Gk1); + } + //set covariance void setCovariance(const CovarianceMatrix5dim& c) { covariance_[0] = c(0, 0); @@ -423,6 +452,11 @@ namespace l1t { std::vector kalmanGain3_; std::vector residuals_; + + std::vector convergenceGain0_; + std::vector convergenceGain1_; + std::vector convergenceGain2_; + std::vector convergenceGain3_; }; } // namespace l1t diff --git a/DataFormats/L1TMuonPhase2/src/classes_def.xml b/DataFormats/L1TMuonPhase2/src/classes_def.xml index 77127b87326de..cf322c4850f7c 100644 --- a/DataFormats/L1TMuonPhase2/src/classes_def.xml +++ b/DataFormats/L1TMuonPhase2/src/classes_def.xml @@ -25,8 +25,9 @@ - - + + + diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 9c61f28005759..1b8b9d1666846 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -580,7 +580,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { a[16] = 0.0; a[17] = 0.0; a[18] = 1.0; - a[19] = zdeltaR_dig; + a[19] = -zdeltaR_dig; a[20] = 0.0; a[21] = 0.0; a[22] = 0.0; @@ -659,6 +659,8 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int z = stub->eta1(); int kSlope = stub->eta2(); + int priorThetaPattern = track.thetaDigiPattern(); + //Vector4 residual; //Vector3 residual; Vector2 residual; @@ -697,8 +699,8 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub //H(3, 3) = 0.0; //H(3, 4) = 1.0; - const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] - : pointResolutionPhiBH_[track.step() - 1]}; + //const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] + // : pointResolutionPhiBH_[track.step() - 1]}; //const double r[]{pointResolutionPhi_, // 0.0, r11, // 0.0, 0.0, pointResolutionz_[track.step() - 1], @@ -734,10 +736,12 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub if (fabs(KNew) > pow(2, BITSCURV - 1)) return false; - int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); + //int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); + int phiNew = trackPhi; //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); + //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); + int phiBNew = trackPhiB; //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); @@ -799,6 +803,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); + track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); return true; } @@ -814,14 +819,16 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int z = stub->eta1(); int kSlope = stub->eta2(); - Vector3 residual; - //Vector2 residual; + int priorThetaPattern = track.thetaDigiPattern(); + + //Vector3 residual; + Vector2 residual; //residual[0] = ap_fixed(phi - trackPhi); residual[0] = z - trackz; residual[1] = kSlope - trackSlope; - double ZRES_CONV=65536.0/1500.; - double KRES_CONV=65536.0/2.; + //double ZRES_CONV=65536.0/1500.; + //double KRES_CONV=65536.0/2.; //std::cout << "[STUB-1D] step=" << track.step() //<< ", stub(phi=" << phi << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" //<< " track(phi=" << trackPhi << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" @@ -873,15 +880,17 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, 1, 0, Gain(2, 0), 0.0); - int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); - //int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1)), pow(2, BITSCURV - 1)); - int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); + //int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); + int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1)), pow(2, BITSCURV - 1)); + //int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); + int phiNew = trackPhi; + //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); - int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); - //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); - int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); - //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); + int phiBNew = trackPhiB; + //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); + int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); + //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); + int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); //std::cout << "[UPDATE-OFFLINE-1D] step=" << track.step() @@ -917,6 +926,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); + track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); return true; @@ -1137,11 +1147,11 @@ int KMTFCore::customBitmask(unsigned int bit1, unsigned int bit2, unsigned int b bool KMTFCore::getBit(int bitmask, int pos) { return (bitmask & (1 << pos)) >> pos; } void KMTFCore::setFourVectors(l1t::KMTFTrack& track) { - int etaINT = track.coarseEta(); + //int etaINT = track.coarseEta(); //new track eta with linear fit calibrated to gen eta. abandoning the legacy approach of setting track eta from coarseEta - //const double m = 0.03458; - //const double b = 0.7446; - //int etaINT = int(round(m * track.kSlope() + b)); + const double m = 0.03458; + const double b = 0.7446; + int etaINT = int(round(m * track.kSlope() + b)); double lsbEta = M_PI / pow(2, 12); int charge = 1; From 629bb347604696e17e303a252f83e7786e44139f Mon Sep 17 00:00:00 2001 From: delano campos Date: Thu, 16 Apr 2026 14:16:37 -0500 Subject: [PATCH 19/29] testing --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 1b8b9d1666846..cbb3bb4a06097 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -141,11 +141,25 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef covariance(0, 0) = DK * 4; covariance(0, 1) = 0; covariance(0, 2) = 0; + covariance(0, 3) = 0; + covariance(0, 4) = 0; covariance(1, 0) = 0; covariance(1, 1) = float(pointResolutionPhi_); covariance(1, 2) = 0; + covariance(1, 3) = 0; + covariance(1, 4) = 0; covariance(2, 0) = 0; covariance(2, 1) = 0; + covariance(2, 3) = 0; + covariance(2, 4) = 0; + covariance(3, 0) = 0; + covariance(3, 1) = 0; + covariance(3, 2) = 0; + covariance(3, 4) = 0; + covariance(4, 0) = 0; + covariance(4, 1) = 0; + covariance(4, 2) = 0; + covariance(4, 3) = 0; if (!(mask == 1 || mask == 2 || mask == 3 || mask == 4 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) covariance(2, 2) = float(pointResolutionPhiB_); @@ -211,7 +225,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (verbose_) edm::LogWarning("KMTFCore") << "propagated Coordinates step:" << track.step() << "phi=" << track.positionAngle() << "phiB=" << track.bendingAngle() << "K=" << track.curvature() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); - if (track.step() > 0) + if (track.step() > 0){ if (getBit(mask, track.step() - 1)) { std::pair bestStub = match(seed, stubs, track.step()); if (verbose_) @@ -225,6 +239,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef << " phiB=" << track.bendingAngle() << " K=" << track.curvature() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); } } + } if (track.step() == 0) { track.setCoordinatesAtVertex(track.curvature(), track.positionAngle(), track.bendingAngle()); @@ -714,7 +729,6 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub 0, pointResolutionkSlope_[track.step() - 1]}; const CovarianceMatrix2 R(r, 3); - const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); //CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; @@ -726,7 +740,6 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub //const Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; const Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; - track.setKalmanGain( track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); @@ -736,12 +749,11 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub if (fabs(KNew) > pow(2, BITSCURV - 1)) return false; - //int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - int phiNew = trackPhi; + int phiNew = wrapAround(trackPhi + int(Gain(1, 0) * residual(0) + Gain(1, 1) * residual(1)), pow(2, BITSPHI - 1)); //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); - //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); - int phiBNew = trackPhiB; + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); + //int phiBNew = trackPhiB; //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); From 21729300f29dd1a747473f7979a6ba5ea30f8e04 Mon Sep 17 00:00:00 2001 From: delano campos Date: Thu, 16 Apr 2026 15:24:15 -0500 Subject: [PATCH 20/29] updates --- .../L1TMuonPhase2/interface/KMTFTrack.h | 11 ++ L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 108 +++++++++++++++--- 2 files changed, 105 insertions(+), 14 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h index 07af2b60c033d..0d91f158a6be1 100644 --- a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h +++ b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h @@ -11,6 +11,7 @@ namespace l1t { typedef std::vector KMTFTrackCollection; typedef BXVector KMTFTrackBxCollection; typedef math::Error<5>::type CovarianceMatrix5dim; + typedef math::Error<2>::type CovarianceMatrix2dim; class KMTFTrack : public reco::LeafCandidate { public: @@ -18,6 +19,7 @@ namespace l1t { : reco::LeafCandidate(-1, reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), unconstrainedP4_(reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), covariance_(std::vector(15, 0.0)), + covarianceNB_(std::vector(3, 0.0)), curvVertex_(0), ptC_(0), phiVertex_(0), @@ -54,6 +56,7 @@ namespace l1t { : reco::LeafCandidate(-1, reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), unconstrainedP4_(reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), covariance_(std::vector(15, 0.0)), + covarianceNB_(std::vector(3, 0.0)), curvVertex_(0), ptC_(0), phiVertex_(0), @@ -181,6 +184,7 @@ namespace l1t { //get covariance const std::vector& covariance() const { return covariance_; } + const std::vector& covarianceNB() const { return covarianceNB_; } //get residual int residual(uint i) const { return residuals_[i]; } @@ -369,6 +373,12 @@ namespace l1t { covariance_[14] = c(4, 4); } + + void setCovarianceNB(const CovarianceMatrix2dim& c) { + covarianceNB_[0] = c(0,0); + covarianceNB_[1] = c(0,1); + covarianceNB_[2] = c(1,1); + } //set fine eta void setFineEta(int eta) { @@ -384,6 +394,7 @@ namespace l1t { //Covariance matrix for studies std::vector covariance_; + std::vector covarianceNB_; l1t::MuonStubRefVector stubs_; //vertex coordinates diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index cbb3bb4a06097..abf11e69bad71 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -177,6 +177,16 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef covariance(4,4) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); } track.setCovariance(covariance); + l1t::CovarianceMatrix2dim covNB; + if (seed->depthRegion() == 4) { + covNB(0,0) = pow(2, 22); + covNB(1,1) = pow(2, 22); + } else { + covNB(0,0) = float(pointResolutionz_[seed->depthRegion() - 1]); + covNB(1,1) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); + } + covNB(0,1) = 0; + track.setCovarianceNB(covNB); // if (verbose_) { @@ -646,6 +656,22 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { //<< ", zNew=" << zNew/ZRES_CONV << ", kSlopeNew=" << kSlopeNew/KRES_CONV //<< ", zdeltaR_dig=" << zdeltaR_dig << '\n'; + ROOT::Math::SMatrix Fnb; + Fnb(0,0) = 1.0; + Fnb(0,1) = -zdeltaR_dig; + Fnb(1,0) = 0.0; + Fnb(1,1) = 1.0; + + const std::vector& covNBLine = track.covarianceNB(); + l1t::CovarianceMatrix2dim covNB(covNBLine.begin(), covNBLine.end()); + covNB = ROOT::Math::Similarity(Fnb, covNB); + + l1t::CovarianceMatrix2dim MSnb; + MSnb(0,0) = mScatteringz_[step - 1] * K * K; + MSnb(1,1) = mScatteringkSlope_[step - 1] * K * K; + MSnb(0,1) = 0; + covNB = covNB + MSnb; + track.setCovarianceNB(covNB); track.setCovariance(cov); track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); } @@ -663,6 +689,37 @@ bool KMTFCore::update(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, int m } bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub) { + const double rNB[]{ pointResolutionz_[track.step() - 1], + 0, + pointResolutionkSlope_[track.step() - 1] }; + const CovarianceMatrix2 Rnb(rNB, 3); + + const std::vector& cNBline = track.covarianceNB(); + l1t::CovarianceMatrix2dim covNB(cNBline.begin(), cNBline.end()); + + CovarianceMatrix2 Snb = covNB + Rnb; // H = I, so HPH^T = P + if (Snb.Invert()) { + ROOT::Math::SMatrix GainNB = covNB * Snb; // P H^T S^-1, H^T = I + + // Overwrite the saved gains with the pure-NB versions (G30, G31, G40, G41). + track.setKalmanGain(track.step(), fabs(track.curvature()), + 0, 0, 1, 0, + GainNB(0,0), GainNB(0,1)); // slot G30, G31 + track.setConvergenceGain(track.step(), fabs(track.curvature()), + track.thetaDigiPattern(), + GainNB(0,0), GainNB(0,1), // Gz0, Gz1 + GainNB(1,0), GainNB(1,1)); // Gk0, Gk1 (<-- G40, G41) + + // shrink Pnb so the NEXT step sees the post-update covariance + ROOT::Math::SMatrix I22; + I22(0,0) = 1; I22(1,1) = 1; I22(0,1) = 0; I22(1,0) = 0; + ROOT::Math::SMatrix covNBnew = (I22 - GainNB) * covNB; + l1t::CovarianceMatrix2dim cNB; + cNB(0,0) = covNBnew(0,0); + cNB(0,1) = covNBnew(0,1); + cNB(1,1) = covNBnew(1,1); + track.setCovarianceNB(cNB); + } int trackK = track.curvature(); int trackPhi = track.positionAngle(); int trackPhiB = track.bendingAngle(); @@ -740,25 +797,16 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub //const Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; const Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; - track.setKalmanGain( - track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); + //track.setKalmanGain( + //track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); - //int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2) + Gain(0, 3) * residual(3))); - //int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2))); int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1))); if (fabs(KNew) > pow(2, BITSCURV - 1)) return false; int phiNew = wrapAround(trackPhi + int(Gain(1, 0) * residual(0) + Gain(1, 1) * residual(1)), pow(2, BITSPHI - 1)); - //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2) + Gain(2, 3) * residual(3)), pow(2, BITSPHIB - 1)); - //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); - //int phiBNew = trackPhiB; - //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); - //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); - //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); - //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); //std::cout << "[UPDATE-OFFLINE] step=" << track.step() //<< " Gain(3,0)=" << Gain(3,0) << " Gain(3,1)=" << Gain(3,1) << " Gain(3,2)=" << Gain(3,2) @@ -815,12 +863,44 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); + //track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); return true; } bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub) { + const double rNB[]{ pointResolutionz_[track.step() - 1], + 0, + pointResolutionkSlope_[track.step() - 1] }; + const CovarianceMatrix2 Rnb(rNB, 3); + + const std::vector& cNBline = track.covarianceNB(); + l1t::CovarianceMatrix2dim covNB(cNBline.begin(), cNBline.end()); + + CovarianceMatrix2 Snb = covNB + Rnb; // H = I, so HPH^T = P + if (Snb.Invert()) { + ROOT::Math::SMatrix GainNB = covNB * Snb; // P H^T S^-1, H^T = I + + // Overwrite the saved gains with the pure-NB versions (G30, G31, G40, G41). + track.setKalmanGain(track.step(), fabs(track.curvature()), + 0, 0, 1, 0, + GainNB(0,0), GainNB(0,1)); // slot G30, G31 + track.setConvergenceGain(track.step(), fabs(track.curvature()), + track.thetaDigiPattern(), + GainNB(0,0), GainNB(0,1), // Gz0, Gz1 + GainNB(1,0), GainNB(1,1)); // Gk0, Gk1 (<-- G40, G41) + + // shrink Pnb so the NEXT step sees the post-update covariance + ROOT::Math::SMatrix I22; + I22(0,0) = 1; I22(1,1) = 1; I22(0,1) = 0; I22(1,0) = 0; + ROOT::Math::SMatrix covNBnew = (I22 - GainNB) * covNB; + l1t::CovarianceMatrix2dim cNB; + cNB(0,0) = covNBnew(0,0); + cNB(0,1) = covNBnew(0,1); + cNB(1,1) = covNBnew(1,1); + track.setCovarianceNB(cNB); + } + int trackK = track.curvature(); int trackPhi = track.positionAngle(); int trackPhiB = track.bendingAngle(); @@ -890,7 +970,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st //Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; - track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, 1, 0, Gain(2, 0), 0.0); + //track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, 1, 0, Gain(2, 0), 0.0); //int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1)), pow(2, BITSCURV - 1)); @@ -938,7 +1018,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); + //track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); return true; From 3bc97b4a3c0eccf967c2ccd55d7a3beca44ba2eb Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 27 Apr 2026 13:09:29 -0500 Subject: [PATCH 21/29] add new members and accessors for new gain values --- L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h | 33 ++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h b/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h index 42027a4c38e43..796172dfa576a 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h @@ -11,9 +11,11 @@ namespace Phase2L1GMT { class KMTFLUTs { public: - KMTFLUTs(const std::string &filename) { + KMTFLUTs(const std::string &filename, const std::string &ThetaFilename) { edm::FileInPath path(filename); + edm::FileInPath pathTheta(ThetaFilename); lutFile_ = new TFile(path.fullPath().c_str()); + lutThetaFile_ = new TFile(pathTheta.fullPath().c_str()); lut_[3 * 64 + 8] = (TH1 *)lutFile_->Get("gain_8_3"); lut_[2 * 64 + 8] = (TH1 *)lutFile_->Get("gain_8_2"); lut_[2 * 64 + 12] = (TH1 *)lutFile_->Get("gain_12_2"); @@ -63,12 +65,25 @@ namespace Phase2L1GMT { lut2LL_[1 * 64 + 2] = (TH1 *)lutFile_->Get("gain2_2_1_LL"); coarseEta_ = (TH1 *)lutFile_->Get("coarseETALUT"); + lutTheta_[1 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain_0_1"); + lutTheta_[1 * 64 + 2] = (TH1 *)lutThetaFile_->Get("gain_2_1"); + lutTheta_[1 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain_4_1"); + lutTheta_[1 * 64 + 6] = (TH1 *)lutThetaFile_->Get("gain_6_1"); + lutTheta_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain_0_2"); + lutTheta_[2 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain_4_2"); + lutTheta_[3 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain_0_3"); + } ~KMTFLUTs() { lutFile_->Close(); - if (lutFile_ != nullptr) + lutThetaFile_->Close(); + if (lutFile_ != nullptr){ delete lutFile_; + } + if (lutThetaFile_ != nullptr){ + delete lutThetaFile_; + } } std::vector trackGain(uint step, uint bitmask, uint K) { @@ -110,12 +125,26 @@ namespace Phase2L1GMT { return uint((1 << 12) * coarseEta_->GetBinContent(coarseEta_->GetXaxis()->FindBin(mask)) / M_PI); } + std::vector trackGainTheta(uint step, uint bitmask, uint K) { + std::vector gain(4, 0.0); + const TH1 *h; + h = lutTheta_[64 * step + bitmask]; + gain[0] = h->GetBinContent(K + 1); + gain[1] = h->GetBinContent(512 + K + 1); + gain[2] = h->GetBinContent(2 * 512 + K + 1); + gain[3] = h->GetBinContent(3 * 512 + K + 1); + return gain; + } + + TFile *lutFile_; + TFile *lutThetaFile_; std::map lut_; std::map lut2HH_; std::map lut2LH_; std::map lut2HL_; std::map lut2LL_; + std::map lutTheta_; const TH1 *coarseEta_; }; From 66d9d593ffc8fff1fbe9f4a563238d7be392f6c0 Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 27 Apr 2026 13:12:05 -0500 Subject: [PATCH 22/29] fixed point arithmetic for zNew and kSlope. updateLUT function pulls new gain LUTs now for z, kSlope --- DataFormats/L1TMuonPhase2/src/classes_def.xml | 3 +- L1Trigger/Phase2L1GMT/interface/KMTFCore.h | 11 ++ .../Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 3 +- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 136 ++++-------------- 4 files changed, 41 insertions(+), 112 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/src/classes_def.xml b/DataFormats/L1TMuonPhase2/src/classes_def.xml index cf322c4850f7c..13409d7876a62 100644 --- a/DataFormats/L1TMuonPhase2/src/classes_def.xml +++ b/DataFormats/L1TMuonPhase2/src/classes_def.xml @@ -25,7 +25,8 @@ - + + diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h index 1413891f66fff..b149c201bb4bc 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h @@ -132,6 +132,8 @@ namespace Phase2L1GMT { static const int BITSCURV = 16; static const int BITSPHI = 18; static const int BITSPHIB = 17; // 12 bits *28 (+5 bits) + static const int BITSZ = 16; + static const int BITSKSLOPE = 16; static const int BITSPARAM = 14; static const int GAIN_0 = 9; static const int GAIN_0INT = 6; @@ -148,6 +150,15 @@ namespace Phase2L1GMT { static const int GAIN2_4INT = 4; static const int GAIN2_5 = 12; static const int GAIN2_5INT = 0; + + static const int GAINT_6 = 12; //new theta view gain bits. + static const int GAINT_6INT = 3; + static const int GAINT_7 = 12; + static const int GAINT_7INT = 3; + static const int GAINT_8 = 12; + static const int GAINT_8INT = 3; + static const int GAINT_9 = 12; + static const int GAINT_9INT = 3; //STUFF NOT USED IN THE FIRMWARE BUT ONLY FOR DEBUGGING /////////////////////////////////////////////////////// diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index ede30c1aea441..56e3234425b47 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -7,6 +7,7 @@ algo = cms.PSet( verbose = cms.bool(False), lutFile = cms.string("L1Trigger/Phase2L1GMT/data/packedGainLUTs.root"), + lutThetaFile = cms.string("L1Trigger/Phase2L1GMT/data/packedThetaGainLUTs.root"), initialK = cms.vdouble(-0.4576229536749278, -0.6364802777566145, -1.0305030909883524, -1.7272067322624118), initialK2 = cms.vdouble(-6.442002637356136e-05, -9.582709649965545e-05, -0.0002741064246218815, -0.0014910074450869175), eLoss = cms.vdouble(6.77765e-05,0,0,0), @@ -55,7 +56,7 @@ combos3=cms.vint32(5,6,7), combos2=cms.vint32(3), combos1=cms.vint32(), #for future possible usage - useOfflineAlgo = cms.bool(True), + useOfflineAlgo = cms.bool(False), ###Only for the offline algo -not in firmware -------------------- mScatteringPhi = cms.vdouble(0.1169021113298598, 0.00016777763395543814, 0.0004322078772344548, 0.00024985881710722107), mScatteringPhiB = cms.vdouble(.0522762, 0.01762000062188365, 0.03508319015441297, 0.03126825551530328), diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index abf11e69bad71..9ba1feba2c1d3 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -1,7 +1,7 @@ #include "L1Trigger/Phase2L1GMT/interface/KMTFCore.h" using namespace Phase2L1GMT; KMTFCore::KMTFCore(const edm::ParameterSet& settings) - : lutService_(new KMTFLUTs(settings.getParameter("lutFile"))), + : lutService_(new KMTFLUTs(settings.getParameter("lutFile"), settings.getParameter("lutThetaFile"))), verbose_(settings.getParameter("verbose")), initK_(settings.getParameter >("initialK")), initK2_(settings.getParameter >("initialK2")), @@ -177,18 +177,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef covariance(4,4) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); } track.setCovariance(covariance); - l1t::CovarianceMatrix2dim covNB; - if (seed->depthRegion() == 4) { - covNB(0,0) = pow(2, 22); - covNB(1,1) = pow(2, 22); - } else { - covNB(0,0) = float(pointResolutionz_[seed->depthRegion() - 1]); - covNB(1,1) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); - } - covNB(0,1) = 0; - track.setCovarianceNB(covNB); - // if (verbose_) { edm::LogWarning("KMTFCore") << "New Kalman fit staring at step=" << track.step() << ", phi=" << track.positionAngle() << ", phiB=" << track.bendingAngle() << ", z=" << track.zPosition() << ",kSlope = " << track.kSlope() << ", with curvature=" << track.curvature() ; @@ -656,22 +645,6 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { //<< ", zNew=" << zNew/ZRES_CONV << ", kSlopeNew=" << kSlopeNew/KRES_CONV //<< ", zdeltaR_dig=" << zdeltaR_dig << '\n'; - ROOT::Math::SMatrix Fnb; - Fnb(0,0) = 1.0; - Fnb(0,1) = -zdeltaR_dig; - Fnb(1,0) = 0.0; - Fnb(1,1) = 1.0; - - const std::vector& covNBLine = track.covarianceNB(); - l1t::CovarianceMatrix2dim covNB(covNBLine.begin(), covNBLine.end()); - covNB = ROOT::Math::Similarity(Fnb, covNB); - - l1t::CovarianceMatrix2dim MSnb; - MSnb(0,0) = mScatteringz_[step - 1] * K * K; - MSnb(1,1) = mScatteringkSlope_[step - 1] * K * K; - MSnb(0,1) = 0; - covNB = covNB + MSnb; - track.setCovarianceNB(covNB); track.setCovariance(cov); track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); } @@ -689,48 +662,15 @@ bool KMTFCore::update(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, int m } bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub) { - const double rNB[]{ pointResolutionz_[track.step() - 1], - 0, - pointResolutionkSlope_[track.step() - 1] }; - const CovarianceMatrix2 Rnb(rNB, 3); - - const std::vector& cNBline = track.covarianceNB(); - l1t::CovarianceMatrix2dim covNB(cNBline.begin(), cNBline.end()); - - CovarianceMatrix2 Snb = covNB + Rnb; // H = I, so HPH^T = P - if (Snb.Invert()) { - ROOT::Math::SMatrix GainNB = covNB * Snb; // P H^T S^-1, H^T = I - - // Overwrite the saved gains with the pure-NB versions (G30, G31, G40, G41). - track.setKalmanGain(track.step(), fabs(track.curvature()), - 0, 0, 1, 0, - GainNB(0,0), GainNB(0,1)); // slot G30, G31 - track.setConvergenceGain(track.step(), fabs(track.curvature()), - track.thetaDigiPattern(), - GainNB(0,0), GainNB(0,1), // Gz0, Gz1 - GainNB(1,0), GainNB(1,1)); // Gk0, Gk1 (<-- G40, G41) - - // shrink Pnb so the NEXT step sees the post-update covariance - ROOT::Math::SMatrix I22; - I22(0,0) = 1; I22(1,1) = 1; I22(0,1) = 0; I22(1,0) = 0; - ROOT::Math::SMatrix covNBnew = (I22 - GainNB) * covNB; - l1t::CovarianceMatrix2dim cNB; - cNB(0,0) = covNBnew(0,0); - cNB(0,1) = covNBnew(0,1); - cNB(1,1) = covNBnew(1,1); - track.setCovarianceNB(cNB); - } int trackK = track.curvature(); int trackPhi = track.positionAngle(); int trackPhiB = track.bendingAngle(); int trackz = track.zPosition(); int trackSlope = track.kSlope(); - int phi = stub->coord1(); int phiB = correctedPhiB(stub); int z = stub->eta1(); int kSlope = stub->eta2(); - int priorThetaPattern = track.thetaDigiPattern(); //Vector4 residual; @@ -820,8 +760,6 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub //<< " + " << Gain(4,1) << "*" << int(residual(1)) //<< " + " << Gain(4,2) << "*" << int(residual(2)) << ") = " << kSlopeNew << '\n'; - //track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); - //track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew)); track.setResidual(stub->depthRegion() - 1, fabs(z - zNew) + fabs(kSlope - kSlopeNew)); if (verbose_) { @@ -863,59 +801,23 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - //track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); + track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); return true; } bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub) { - const double rNB[]{ pointResolutionz_[track.step() - 1], - 0, - pointResolutionkSlope_[track.step() - 1] }; - const CovarianceMatrix2 Rnb(rNB, 3); - - const std::vector& cNBline = track.covarianceNB(); - l1t::CovarianceMatrix2dim covNB(cNBline.begin(), cNBline.end()); - - CovarianceMatrix2 Snb = covNB + Rnb; // H = I, so HPH^T = P - if (Snb.Invert()) { - ROOT::Math::SMatrix GainNB = covNB * Snb; // P H^T S^-1, H^T = I - - // Overwrite the saved gains with the pure-NB versions (G30, G31, G40, G41). - track.setKalmanGain(track.step(), fabs(track.curvature()), - 0, 0, 1, 0, - GainNB(0,0), GainNB(0,1)); // slot G30, G31 - track.setConvergenceGain(track.step(), fabs(track.curvature()), - track.thetaDigiPattern(), - GainNB(0,0), GainNB(0,1), // Gz0, Gz1 - GainNB(1,0), GainNB(1,1)); // Gk0, Gk1 (<-- G40, G41) - - // shrink Pnb so the NEXT step sees the post-update covariance - ROOT::Math::SMatrix I22; - I22(0,0) = 1; I22(1,1) = 1; I22(0,1) = 0; I22(1,0) = 0; - ROOT::Math::SMatrix covNBnew = (I22 - GainNB) * covNB; - l1t::CovarianceMatrix2dim cNB; - cNB(0,0) = covNBnew(0,0); - cNB(0,1) = covNBnew(0,1); - cNB(1,1) = covNBnew(1,1); - track.setCovarianceNB(cNB); - } - int trackK = track.curvature(); int trackPhi = track.positionAngle(); int trackPhiB = track.bendingAngle(); int trackz = track.zPosition(); int trackSlope = track.kSlope(); - int phi = stub->coord1(); int z = stub->eta1(); int kSlope = stub->eta2(); - int priorThetaPattern = track.thetaDigiPattern(); - //Vector3 residual; Vector2 residual; - //residual[0] = ap_fixed(phi - trackPhi); residual[0] = z - trackz; residual[1] = kSlope - trackSlope; @@ -932,7 +834,6 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st edm::LogWarning("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); } - //Matrix35 H; Matrix25 H; H(0, 0) = 0.0; H(0, 1) = 0.0; @@ -958,16 +859,12 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st 0.0, pointResolutionkSlope_[track.step() - 1]}; const CovarianceMatrix2 R(r, 3); - - const std::vector& covLine = track.covariance(); l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - //CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - //Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; //track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, 1, 0, Gain(2, 0), 0.0); @@ -1018,7 +915,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - //track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); + track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); return true; @@ -1028,17 +925,23 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in int trackK = track.curvature(); int trackPhi = track.positionAngle(); int trackPhiB = track.bendingAngle(); + int trackz = track.zPosition(); + int trackSlope = track.kSlope(); int phi = stub->coord1(); int phiB = correctedPhiB(stub); + int z = stub->eta1(); + int kSlope = stub->eta2(); - Vector2 residual; + Vector4 residual; ap_fixed residualPhi = phi - trackPhi; ap_fixed residualPhiB = phiB - trackPhiB; + ap_fixed residualz = z - trackz; + ap_fixed residualSlope = kSlope - trackSlope; if (verbose_) edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << residualPhi.to_int() << " " << phiB - << " - " << trackPhiB << " = " << residualPhiB.to_int(); + << " - " << trackPhiB << " = " << residualPhiB.to_int(); uint absK = fabs(trackK); @@ -1046,6 +949,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in absK = pow(2, BITSCURV - 2) - 1; std::vector GAIN; + std::vector GAIN_THETA; if (verbose_) { edm::LogWarning("KMTFCore") << "Looking up LUTs for mask=" << mask << " with hit pattern=" << track.hitPattern(); } @@ -1058,6 +962,9 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in } else { GAIN = lutService_->trackGain2(track.step(), track.hitPattern(), absK / 32, seedQual, stub->quality()); } + + GAIN_THETA = lutService_->trackGainTheta(track.step(), track.thetaDigiPattern(), absK / 32); + if (verbose_) { edm::LogWarning("KMTFCore") << "Gains (fp): " << GAIN[0] << " " << GAIN[1] << " " << GAIN[2] << " " << GAIN[3]; @@ -1121,7 +1028,17 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in if ((phiBNew > (pow(2, BITSPHIB - 1) - 1)) || (phiBNew < (-pow(2, BITSPHIB - 1)))) return false; - track.setCoordinates(track.step(), KNew, phiNew, phiBNew, track.zPosition(), track.kSlope()); + ap_fixed z0 = ap_ufixed(GAIN_THETA[0]) * residualz; + ap_fixed z1 = ap_ufixed(GAIN_THETA[1]) * residualSlope; + ap_fixed k0 = ap_ufixed(GAIN_THETA[2]) * residualz; + ap_fixed k1 = ap_ufixed(GAIN_THETA[3]) * residualSlope; + + int zNew; + int kSlopeNew; + zNew = ap_fixed(ap_fixed(trackz) + z0 - z1); + kSlopeNew = ap_fixed(ap_fixed(trackSlope) - k0 + k1); + + track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); @@ -1142,7 +1059,6 @@ void KMTFCore::vertexConstraint(l1t::KMTFTrack& track) { vertexConstraintLUT(track); } - void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track){} void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track){} From 0fd6927f017ab6c04308b3726e1ab24c44451e3d Mon Sep 17 00:00:00 2001 From: delano campos Date: Mon, 27 Apr 2026 20:57:57 -0500 Subject: [PATCH 23/29] packed gain theta view LUT root file small cleanup cleanup printouts fix wraparound bug --- L1Trigger/Phase2L1GMT/interface/KMTFCore.h | 4 + .../L1TPhase2GMTBarrelStubProcessor.h | 2 +- .../Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 4 +- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 476 ++++++++---------- .../src/L1TPhase2GMTBarrelStubProcessor.cc | 15 +- 5 files changed, 218 insertions(+), 283 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h index b149c201bb4bc..09f031cfd2457 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h @@ -2,6 +2,8 @@ Kalman Filter L1 Muon algorithm Tyler Lam (UCLA) Sep. 2021 +Delano Campos (UCLA) +Feb. 2026 */ #ifndef L1Trigger_Phase2L1GMT_KMTFCore_h #define L1Trigger_Phase2L1GMT_KMTFCore_h @@ -129,6 +131,8 @@ namespace Phase2L1GMT { //bits for fixed point precision static const int PHIBSCALE = 16; static const int PHIBSCALE_INT = 5; + static const int ZDELTAR_BITS = 15; + static const int ZDELTAR_BITSINT = 1; static const int BITSCURV = 16; static const int BITSPHI = 18; static const int BITSPHIB = 17; // 12 bits *28 (+5 bits) diff --git a/L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h b/L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h index 1e381de6f2d09..523ef4649e865 100644 --- a/L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h +++ b/L1Trigger/Phase2L1GMT/interface/L1TPhase2GMTBarrelStubProcessor.h @@ -22,7 +22,7 @@ class L1TPhase2GMTBarrelStubProcessor { l1t::MuonStubCollection makeStubs(const L1Phase2MuDTExtPhiThetaPairContainer*); private: - l1t::MuonStub buildStubwithZandK(const L1Phase2MuDTExtPhiThetaPair&); + l1t::MuonStub buildStubwithZandkSlope(const L1Phase2MuDTExtPhiThetaPair&); l1t::MuonStub buildStub(const L1Phase2MuDTPhDigi&, const L1MuDTChambThDigi*); l1t::MuonStub buildStubNoEta(const L1Phase2MuDTPhDigi&); diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index 56e3234425b47..31c8865e12fc8 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -14,7 +14,7 @@ aPhi = cms.vdouble(5.6533349391874275, 0.03477876333443834, 0.032506522838098864, 0.024752809174909053), aPhiB = cms.vdouble(-2.02, -0.2994087741381382, -0.4033668521165302, -0.3592231728688621), - zdeltaR = cms.vdouble(445.0, 526.0-445.0, 635.0-526.0, 744.0-635.0), + zdeltaR = cms.vdouble(445.0, 526.0-445.0, 635.0-526.0, 730.0-635.0), aPhiBNLO = cms.vdouble(9.04133e-05,0,0,0), bPhi = cms.vdouble(-1,.18245,.20898,.17286), @@ -56,7 +56,7 @@ combos3=cms.vint32(5,6,7), combos2=cms.vint32(3), combos1=cms.vint32(), #for future possible usage - useOfflineAlgo = cms.bool(False), + useOfflineAlgo = cms.bool(True), ###Only for the offline algo -not in firmware -------------------- mScatteringPhi = cms.vdouble(0.1169021113298598, 0.00016777763395543814, 0.0004322078772344548, 0.00024985881710722107), mScatteringPhiB = cms.vdouble(.0522762, 0.01762000062188365, 0.03508319015441297, 0.03126825551530328), diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 9ba1feba2c1d3..fb6795e86c948 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -108,21 +108,8 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef initialK = pow(2, BITSCURV - 1) - 1; if (initialK <= -pow(2, BITSCURV - 1)) initialK = -pow(2, BITSCURV - 1) + 1; + track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), phiB, seed->eta1(), seed->eta2()); - double ZRES_CONV=65536.0/1500.; - double KRES_CONV=65536.0/2.; - //std::cout - //<< "------------------" - //<< "[INIT] mask=" << mask - //<< ", step=" << track.step() - //<< ", K=" << initialK - //<< ", phi=" << seed->coord1() - //<< ", phiB=" << phiB - //<< ", z=" << seed->eta1()/ZRES_CONV - //<< ", kSlope=" << seed->eta2()/KRES_CONV - //<< ", seedQual=" << seed->quality() - //<< ", wheel=" << seed->etaRegion() - //<< '\n'; if (seed->quality() < 6) { track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), seed->eta2()); @@ -273,15 +260,6 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (verbose_) edm::LogWarning("KMTFCore") << "Floating point coordinates at vertex: pt=" << track.pt() << ", eta=" << track.eta() << " phi=" << track.phi(); - double ZRES_CONV=65536.0/1500.; - double KRES_CONV=65536.0/2.; - //std::cout << "[RESULT] mask=" << mask - //<< ", K=" << track.curvatureAtVertex() << ", phi=" << track.phiAtVertex() - //<< ", dxy=" << track.dxy() << ", z=" << track.zPosition()/ZRES_CONV << ", kSlope=" << track.kSlope()/KRES_CONV - //<< ", pt=" << track.pt() << ", eta=" << track.eta() - //<< ", chi2_prompt=" << track.approxPromptChi2() << ", chi2_disp=" << track.approxDispChi2() - //<< ", nstubs=" << track.stubs().size() << ", hitPattern=" << track.hitPattern() << '\n'; - pretracks.push_back(track); } } @@ -481,14 +459,8 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { unsigned int step = track.step(); int z = track.zPosition(); int kSlope = track.kSlope(); - double ZRES_CONV=65536.0/1500.; - double KRES_CONV=65536.0/2.; - //std::cout << "[PRE-PROP] step " << step << "->" << (step - 1) - //<< ": K=" << K << ", phi=" << phi << ", phiB=" << phiB - //<< ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ", wheel=" << track.wheel() << '\n'; - - int charge = 1; + if (K != 0) charge = K / fabs(K); @@ -535,6 +507,24 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { << ap_ufixed(bPhiB_[step - 1]).to_float() << " = " << phiB12.to_int(); } + //z and kSlope propagation + // dR conversion factor comes from ZRES_CONV and KRES_CONV: ZRES_CONV/KRES_CONV=(65536/1500)/(65536/2) to go from physical (cm) to digitized units + double zdR_CONV = 2.0 / 1500.0 ; + double zdeltaR_dig = zdeltaR_[step - 1] * zdR_CONV ; + int kSlopeNew = kSlope; + int zNew; + zNew = ap_fixed(ap_fixed(z) - ap_ufixed(zdeltaR_dig) * ap_fixed(kSlope)); + + if (zNew > (1 << (BITSZ - 1)) - 1) { + if (verbose_) + edm::LogWarning("KMTFCore") << "z saturated high during propagation, step=" << step; + zNew = (1 << (BITSZ - 1) - 1); + } else if (zNew < -(1 << (BITSZ - 1))) { + if (verbose_) + edm::LogWarning("KMTFCore") << "z saturated low during propagation, step=" << step; + zNew = -(1 << (BITSZ - 1)); + } + //Only for the propagation to vertex we use second order; if (step == 1) { ap_fixed<10, 4> aPhiB = aPhiB_[step - 1]; @@ -561,16 +551,6 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { //Rest of the stuff is for the offline version only //where we want to check what is happening in the covariance matrix - //z and kSlope propagation offline studies - //zdeltaR are in phyiscal units. convert for the propagation of z. - double zdR_CONV = ZRES_CONV / KRES_CONV ; - double zdeltaR_dig = zdeltaR_[step - 1] * zdR_CONV ; - int kSlopeNew = kSlope; - - int zNew; - zNew = z - (int)(kSlope * zdeltaR_dig); - - //Create the transformation matrix double a[25]; a[0] = 1.0; @@ -640,11 +620,6 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { edm::LogWarning("KMTFCore") << "Multiple scattering term for z = " << MS(3, 3); edm::LogWarning("KMTFCore") << "Multiple scattering term for kSlope = " << MS(4, 4); } - //std::cout << "[POST-PROP] step " << (step - 1) - //<< ": KNew=" << KNew << ", phiNew=" << phiNew << ", phiBNew=" << phiBNew - //<< ", zNew=" << zNew/ZRES_CONV << ", kSlopeNew=" << kSlopeNew/KRES_CONV - //<< ", zdeltaR_dig=" << zdeltaR_dig << '\n'; - track.setCovariance(cov); track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); } @@ -667,75 +642,56 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int trackPhiB = track.bendingAngle(); int trackz = track.zPosition(); int trackSlope = track.kSlope(); + int phi = stub->coord1(); int phiB = correctedPhiB(stub); int z = stub->eta1(); int kSlope = stub->eta2(); int priorThetaPattern = track.thetaDigiPattern(); - //Vector4 residual; - //Vector3 residual; - Vector2 residual; - //residual[0] = ap_fixed(phi - trackPhi); - //residual[1] = phiB - trackPhiB; - residual[0] = z - trackz; - residual[1] = kSlope - trackSlope; - double ZRES_CONV=65536.0/1500.; - double KRES_CONV=65536.0/2.; - //std::cout << "[STUB] step=" << track.step() - //<< ", stub(phi=" << phi << ", phiB=" << phiB << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" - //<< " track(phi=" << trackPhi << ", phiB=" << trackPhiB << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" - //<< " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << ", " << int(residual[3]) << ")" << '\n'; - - //Matrix45 H; - //Matrix35 H; - Matrix25 H; + Vector4 residual; + residual[0] = ap_fixed(phi - trackPhi); + residual[1] = phiB - trackPhiB; + residual[2] = ap_fixed(z - trackz); + residual[3] = ap_fixed(kSlope - trackSlope); + + Matrix45 H; H(0, 0) = 0.0; - H(0, 1) = 0.0; + H(0, 1) = 1.0; H(0, 2) = 0.0; - H(0, 3) = 1.0; + H(0, 3) = 0.0; H(0, 4) = 0.0; H(1, 0) = 0.0; H(1, 1) = 0.0; - H(1, 2) = 0.0; + H(1, 2) = 1.0; H(1, 3) = 0.0; - H(1, 4) = 1.0; - //H(2, 0) = 0.0; - //H(2, 1) = 0.0; - //H(2, 2) = 0.0; - //H(2, 3) = 1.0; - //H(2, 4) = 0.0; - //H(3, 0) = 0.0; - //H(3, 1) = 0.0; - //H(3, 2) = 0.0; - //H(3, 3) = 0.0; - //H(3, 4) = 1.0; - - //const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] - // : pointResolutionPhiBH_[track.step() - 1]}; - //const double r[]{pointResolutionPhi_, - // 0.0, r11, - // 0.0, 0.0, pointResolutionz_[track.step() - 1], - // 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; - //const CovarianceMatrix4 R(r, 10); - //const double r[]{pointResolutionPhi_, - // 0.0, r11, - // 0.0, 0.0, pointResolutionz_[track.step() - 1]}; - //const CovarianceMatrix3 R(r, 6); - const double r[]{pointResolutionz_[track.step() - 1], - 0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix2 R(r, 3); - + H(1, 4) = 0.0; + H(2, 0) = 0.0; + H(2, 1) = 0.0; + H(2, 2) = 0.0; + H(2, 3) = 1.0; + H(2, 4) = 0.0; + H(3, 0) = 0.0; + H(3, 1) = 0.0; + H(3, 2) = 0.0; + H(3, 3) = 0.0; + H(3, 4) = 1.0; + + const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] + : pointResolutionPhiBH_[track.step() - 1]}; + const double r[]{pointResolutionPhi_, + 0.0, r11, + 0.0, 0.0, pointResolutionz_[track.step() - 1], + 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + + const CovarianceMatrix4 R(r, 10); const std::vector& covLine = track.covariance(); const l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - //CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; - //CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; - CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; + + CovarianceMatrix4 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - //const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; - //const Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; - const Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; + const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; //track.setKalmanGain( //track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); @@ -743,47 +699,44 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1))); if (fabs(KNew) > pow(2, BITSCURV - 1)) return false; - - int phiNew = wrapAround(trackPhi + int(Gain(1, 0) * residual(0) + Gain(1, 1) * residual(1)), pow(2, BITSPHI - 1)); + int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); - int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); - int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); - //std::cout << "[UPDATE-OFFLINE] step=" << track.step() - //<< " Gain(3,0)=" << Gain(3,0) << " Gain(3,1)=" << Gain(3,1) << " Gain(3,2)=" << Gain(3,2) - //<< " Gain(4,0)=" << Gain(4,0) << " Gain(4,1)=" << Gain(4,1) << " Gain(4,2)=" << Gain(4,2) << '\n'; - //std::cout << " zNew = " << trackz - //<< " + (" << Gain(3,0) << "*" << int(residual(0)) - //<< " + " << Gain(3,1) << "*" << int(residual(1)) - //<< " + " << Gain(3,2) << "*" << int(residual(2)) << ") = " << zNew << '\n'; - //std::cout << " kSlopeNew = " << trackSlope - //<< " + (" << Gain(4,0) << "*" << int(residual(0)) - //<< " + " << Gain(4,1) << "*" << int(residual(1)) - //<< " + " << Gain(4,2) << "*" << int(residual(2)) << ") = " << kSlopeNew << '\n'; - - track.setResidual(stub->depthRegion() - 1, fabs(z - zNew) + fabs(kSlope - kSlopeNew)); + int zNew = trackz + int(Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); + int kSlopeNew = trackSlope + int(Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); - if (verbose_) { - edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << int(residual[0]) << " " << phiB - << " - " << trackPhiB << " = " << int(residual[1]); - edm::LogWarning("KMTFCore") << "Gains offline: " << Gain(0, 0) << " " << Gain(0, 1) << " " << Gain(2, 0) << " " - << Gain(2, 1); - edm::LogWarning("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) - << " * " << residual(1); - edm::LogWarning("KMTFCore") << " phiB = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " - << Gain(2, 1) << " * " << residual(1); - edm::LogWarning("KMTFCore") << " z = " << trackz << " + " << Gain(3,0) << "*" << residual(0) - << " + " << Gain(3,1) << "*" << residual(1) - << " + " << Gain(3,2) << "*" << residual(2) - << zNew; - edm::LogWarning("KMTFCore") << " kSlope = " << trackSlope << " + " << Gain(4,0) << "*" << residual(0) - << " + " << Gain(4,1) << "*" << residual(1) - << " + " << Gain(4,2) << "*" << residual(2) - << " = " << kSlopeNew; - edm::LogWarning("KMTFCore") << " stub z=" << z << " kSlope=" << kSlope - << " | residual z=" << residual(2); + if ((zNew > (pow(2, BITSZ - 1) - 1)) || (zNew < -(pow(2, BITSZ - 1)))) { + if (verbose_) + edm::LogWarning("KMTFCore") << "z saturated in updateOffline"; + return false; + } + if ((kSlopeNew > (pow(2, BITSKSLOPE - 1) - 1)) || (kSlopeNew < -(pow(2, BITSKSLOPE - 1)))) { + if (verbose_) + edm::LogWarning("KMTFCore") << "kSlope saturated in updateOffline"; + return false; + } + track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); + + if (verbose_) { + edm::LogWarning("KMTFCore") << "residual(0): " << phi << "-" << trackPhi << " = " << residual(0); + edm::LogWarning("KMTFCore") << "residual(1): " << phiB << "-" << trackPhiB << " = " << residual(1); + edm::LogWarning("KMTFCore") << "residual(2): " << z << "-" << trackz << " = " << residual(2); + edm::LogWarning("KMTFCore") << "residual(3): " << kSlope << "-" << trackSlope << " = " << residual(3); + edm::LogWarning("KMTFCore") << "Gain(0,0): " << Gain(0, 0); + edm::LogWarning("KMTFCore") << "Gain(0,1): " << Gain(0, 1); + edm::LogWarning("KMTFCore") << "Gain(2,0): " << Gain(2, 0); + edm::LogWarning("KMTFCore") << "Gain(2,1): " << Gain(2, 1); + edm::LogWarning("KMTFCore") << "Gain(3,2): " << Gain(3, 2); + edm::LogWarning("KMTFCore") << "Gain(3,3): " << Gain(3, 3); + edm::LogWarning("KMTFCore") << "Gain(4,2): " << Gain(4, 2); + edm::LogWarning("KMTFCore") << "Gain(4,3): " << Gain(4, 3); + edm::LogWarning("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0) << "+" << Gain(0, 1) << "*" << residual(1) << " = " << KNew ; + edm::LogWarning("KMTFCore") << " phiNew = " << trackPhi << "+" << residual(0) << " = " << phiNew; + edm::LogWarning("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0) << "+" << Gain(2, 1) << "*" << residual(1) << " = " << phiBNew; + edm::LogWarning("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 2) << "*" << residual(2) << "+" << Gain(3, 3) << "*" << residual(3) << " = " << zNew; + edm::LogWarning("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 2) << "*" << residual(2) << "+" << Gain(4, 3) << "*" << residual(3) << " = " << kSlopeNew; } - + track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); const Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; @@ -792,16 +745,11 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub for (int j = i; j < 5; j++){ c(i, j) = covNew(i, j);}} - //std::cout << "[POST-UPDATE] step=" << track.step() - //<< ": KNew=" << KNew << " phiNew=" << phiNew << " phiBNew=" << phiBNew - //<< " zNew=" << zNew/ZRES_CONV << " kSlopeNew=" << kSlopeNew/KRES_CONV - //<< " cov_diag=(" << covNew(0,0) << " " << covNew(1,1) << " " << covNew(2,2) << " " << covNew(3,3) << " " << covNew(4,4) << ")" << '\n'; - track.setCovariance(c); track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); + track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 2), Gain(3, 3), Gain(4, 2), Gain(4, 3)); return true; } @@ -817,94 +765,77 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int kSlope = stub->eta2(); int priorThetaPattern = track.thetaDigiPattern(); - Vector2 residual; - residual[0] = z - trackz; - residual[1] = kSlope - trackSlope; + Vector3 residual; + residual[0] = ap_fixed(phi - trackPhi); + residual[1] = ap_fixed(z - trackz); + residual[2] = ap_fixed(kSlope - trackSlope); - //double ZRES_CONV=65536.0/1500.; - //double KRES_CONV=65536.0/2.; - //std::cout << "[STUB-1D] step=" << track.step() - //<< ", stub(phi=" << phi << ", z=" << z/ZRES_CONV << ", kSlope=" << kSlope/KRES_CONV << ")" - //<< " track(phi=" << trackPhi << ", z=" << trackz/ZRES_CONV << ", kSlope=" << trackSlope/KRES_CONV << ")" - //<< " residual=(" << int(residual[0]) << ", " << int(residual[1]) << ", " << int(residual[2]) << '\n'; - - if (verbose_) { - edm::LogWarning("KMTFCore") << "residual phi" << phi << " - " << trackPhi << " = " << int(residual(0)); - edm::LogWarning("KMTFCore") << "residual z" << z << " - " << trackz << " = " << int(residual(1)); + edm::LogWarning("KMTFCore") << "residual phi: " << phi << " - " << trackPhi << " = " << int(residual(0)); + edm::LogWarning("KMTFCore") << "residual z: " << z << " - " << trackz << " = " << int(residual(1)); + edm::LogWarning("KMTFCore") << "residual kSlope: " << kSlope << " - " << trackSlope << " = " << int(residual(2)); } - Matrix25 H; + Matrix35 H; H(0, 0) = 0.0; - H(0, 1) = 0.0; + H(0, 1) = 1.0; H(0, 2) = 0.0; - H(0, 3) = 1.0; + H(0, 3) = 0.0; H(0, 4) = 0.0; H(1, 0) = 0.0; H(1, 1) = 0.0; H(1, 2) = 0.0; - H(1, 3) = 0.0; - H(1, 4) = 1.0; - //H(2, 0) = 0.0; - //H(2, 1) = 0.0; - //H(2, 2) = 0.0; - //H(2, 3) = 0.0; - //H(2, 4) = 1.0; - - //const double r[]{pointResolutionPhi_, 0.0, - // pointResolutionz_[track.step() - 1], - // 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; - //const CovarianceMatrix3 R(r, 6); - const double r[]{pointResolutionz_[track.step() - 1], - 0.0, pointResolutionkSlope_[track.step() - 1]}; - const CovarianceMatrix2 R(r, 3); + H(1, 3) = 1.0; + H(1, 4) = 0.0; + H(2, 0) = 0.0; + H(2, 1) = 0.0; + H(2, 2) = 0.0; + H(2, 3) = 0.0; + H(2, 4) = 1.0; + + const double r[]{pointResolutionPhi_, + 0.0, pointResolutionz_[track.step() - 1], + 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; + const CovarianceMatrix3 R(r, 6); const std::vector& covLine = track.covariance(); l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); - CovarianceMatrix2 S = ROOT::Math::Similarity(H, cov) + R; + CovarianceMatrix3 S = ROOT::Math::Similarity(H, cov) + R; if (!S.Invert()) return false; - Matrix52 Gain = cov * ROOT::Math::Transpose(H) * S; + Matrix53 Gain = cov * ROOT::Math::Transpose(H) * S; //track.setKalmanGain(track.step(), fabs(trackK), Gain(0, 0), 0.0, 1, 0, Gain(2, 0), 0.0); - //int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1) + Gain(0, 2) * residual(2)), pow(2, BITSCURV - 1)); - int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1)), pow(2, BITSCURV - 1)); - //int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); - int phiNew = trackPhi; - //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1) + Gain(2, 2) * residual(2)), pow(2, BITSPHIB - 1)); - //int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0) + Gain(2, 1) * residual(1)), pow(2, BITSPHIB - 1)); - int phiBNew = trackPhiB; - //int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); - int zNew = trackz + int(Gain(3, 0) * residual(0) + Gain(3, 1) * residual(1)); - //int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); - int kSlopeNew = trackSlope + int(Gain(4, 0) * residual(0) + Gain(4, 1) * residual(1)); + int KNew = wrapAround(trackK + int(Gain(0, 0) * residual(0)), pow(2, BITSCURV - 1)); + int phiNew = wrapAround(trackPhi + residual(0), pow(2, BITSPHI - 1)); + int phiBNew = wrapAround(trackPhiB + int(Gain(2, 0) * residual(0)), pow(2, BITSPHIB - 1)); + int zNew = trackz + int(Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); + int kSlopeNew = trackSlope + int(Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); + + if ((zNew > (pow(2, BITSZ - 1) - 1)) || (zNew < -(pow(2, BITSZ - 1)))) { + if (verbose_) + edm::LogWarning("KMTFCore") << "z saturated in updateOffline1D"; + return false; + } + if ((kSlopeNew > (pow(2, BITSKSLOPE - 1) - 1)) || (kSlopeNew < -(pow(2, BITSKSLOPE - 1)))) { + if (verbose_) + edm::LogWarning("KMTFCore") << "kSlope saturated in updateOffline1D"; + return false; + } track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); - //std::cout << "[UPDATE-OFFLINE-1D] step=" << track.step() - //<< " Gain(3,0)=" << Gain(3,0) << " Gain(3,1)=" << Gain(3,1) - //<< " Gain(4,0)=" << Gain(4,0) << " Gain(4,1)=" << Gain(4,1) << '\n'; - //std::cout << " zNew = " << trackz - // << " + (" << Gain(3,0) << "*" << int(residual(0)) - // << " + " << Gain(3,1) << "*" << int(residual(1)) << ") = " << zNew << '\n'; - //std::cout << " kSlopeNew = " << trackSlope - //<< " + (" << Gain(4,0) << "*" << int(residual(0)) - //<< " + " << Gain(4,1) << "*" << int(residual(1)) << ") = " << kSlopeNew << '\n'; + Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; - //std::cout << "[POST-UPDATE-1D] step=" << track.step() - //<< ": Track K=" << track.curvature() << ", Track phi=" << track.positionAngle() << ", Track phiB=" << track.bendingAngle() - //<< ", Track z=" << track.zPosition()/ZRES_CONV << ", Track kSlope=" << track.kSlope()/KRES_CONV - //<< " cov_diag=(" << covNew(0,0) << ", " << covNew(1,1) << ", " << covNew(2,2) << ", " << covNew(3,3) << ", " << covNew(4,4) << ")" << '\n'; - if (verbose_) { - edm::LogWarning("KMTFCore") << "phiUpdate: " << int(Gain(0, 0) * residual(0)) << " " << int(Gain(2, 0) * residual(0)); - edm::LogWarning("KMTFCore") << " K = " << trackK << " + " << Gain(0, 0) << " * " << residual(0) << " + " << Gain(0, 1) << " * " << residual(1); - edm::LogWarning("KMTFCore") << " phiBNew = " << trackPhiB << " + " << Gain(2, 0) << " * " << residual(0) << " + " << Gain(2, 1) << " * " << residual(1); - edm::LogWarning("KMTFCore") << " zNew = " << trackz << " + " << Gain(3, 0) << " * " << residual(0) << " + " << Gain(3, 1) << " * " << residual(1); - edm::LogWarning("KMTFCore") << " kSlopeNew = " << trackSlope << " + " << Gain(4, 0) << " * " << residual(0) << " + " << Gain(4, 1) << " * " << residual(1); + edm::LogWarning("KMTFCore") << " phiNew: " << trackPhi << "+" << residual(0); + edm::LogWarning("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0); + edm::LogWarning("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0); + edm::LogWarning("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 1) << "*" << residual(1) << "+" << Gain(3, 2) << "*" << residual(2); + edm::LogWarning("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 1) << "*" << residual(1) << "+" << Gain(4, 2) << "*" << residual(2); } for (int i = 0; i < 5; i++) @@ -915,8 +846,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 0), Gain(3, 1), Gain(4, 0), Gain(4, 1)); - + track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 1), Gain(3, 2), Gain(4, 1), Gain(4, 2)); return true; } @@ -979,7 +909,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in << ap_ufixed(GAIN[3]).to_float(); } - track.setKalmanGain(track.step(), fabs(trackK), GAIN[0], GAIN[1], 1, 0, GAIN[2], GAIN[3]); + //track.setKalmanGain(track.step(), fabs(trackK), GAIN[0], GAIN[1], 1, 0, GAIN[2], GAIN[3]); int KNew; if (!(mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) { @@ -1028,15 +958,21 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in if ((phiBNew > (pow(2, BITSPHIB - 1) - 1)) || (phiBNew < (-pow(2, BITSPHIB - 1)))) return false; - ap_fixed z0 = ap_ufixed(GAIN_THETA[0]) * residualz; - ap_fixed z1 = ap_ufixed(GAIN_THETA[1]) * residualSlope; - ap_fixed k0 = ap_ufixed(GAIN_THETA[2]) * residualz; - ap_fixed k1 = ap_ufixed(GAIN_THETA[3]) * residualSlope; - int zNew; int kSlopeNew; - zNew = ap_fixed(ap_fixed(trackz) + z0 - z1); - kSlopeNew = ap_fixed(ap_fixed(trackSlope) - k0 + k1); + zNew = ap_fixed(ap_fixed(trackz) + ap_ufixed(GAIN_THETA[0]) * residualz - ap_ufixed(GAIN_THETA[1]) * residualSlope); + kSlopeNew = ap_fixed(ap_fixed(trackSlope) - ap_ufixed(GAIN_THETA[2]) * residualz + ap_ufixed(GAIN_THETA[3]) * residualSlope); + + if ((zNew > (pow(2, BITSZ - 1) - 1)) || (zNew < -(pow(2, BITSZ - 1)))) { + if (verbose_) + edm::LogWarning("KMTFCore") << "z has saturated"; + return false; + } + if ((kSlopeNew > (pow(2, BITSKSLOPE - 1) - 1)) || (kSlopeNew < -(pow(2, BITSKSLOPE - 1)))) { + if (verbose_) + edm::LogWarning("KMTFCore") << "kSlope has saturated"; + return false; + } track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); track.addStub(stub); @@ -1064,68 +1000,68 @@ void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track){} //void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track) { // double residual = -track.dxy(); -// Matrix13 H; -// H(0, 0) = 0; -// H(0, 1) = 0; -// H(0, 2) = 1; - -// const std::vector& covLine = track.covariance(); -// l1t::KMTFTrack::CovarianceMatrix cov(covLine.begin(), covLine.end()); - -// double S = (ROOT::Math::Similarity(H, cov))(0, 0) + pointResolutionVertex_; -// S = 1.0 / S; -// Matrix31 Gain = cov * (ROOT::Math::Transpose(H)) * S; -// track.setKalmanGain(track.step(), fabs(track.curvature()), Gain(0, 0), Gain(1, 0), Gain(2, 0)); - -// if (verbose_) { -// edm::LogWarning("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); -// edm::LogWarning("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; -// } - -// int KNew = wrapAround(int(track.curvature() + Gain(0, 0) * residual), pow(2, BITSCURV - 1)); -// int phiNew = wrapAround(int(track.positionAngle() + Gain(1, 0) * residual), pow(2, BITSPHI)); -// int dxyNew = wrapAround(int(track.dxy() + Gain(2, 0) * residual), pow(2, BITSPHIB)); -// if (verbose_) -// edm::LogWarning("KMTFCore") << "Post fit impact parameter=" << dxyNew; -// track.setCoordinatesAtVertex(KNew, phiNew, -residual); -// Matrix33 covNew = cov - Gain * (H * cov); -// l1t::KMTFTrack::CovarianceMatrix c; -// c(0, 0) = covNew(0, 0); -// c(0, 1) = covNew(0, 1); -// c(0, 2) = covNew(0, 2); -// c(1, 0) = covNew(1, 0); -// c(1, 1) = covNew(1, 1); -// c(1, 2) = covNew(1, 2); -// c(2, 0) = covNew(2, 0); -// c(2, 1) = covNew(2, 1); - // c(2, 2) = covNew(2, 2); -// track.setCovariance(c); -// // track.covariance = track.covariance - Gain*H*track.covariance; + // Matrix13 H; + //H(0, 0) = 0; + //H(0, 1) = 0; + //H(0, 2) = 1; + + //const std::vector& covLine = track.covariance(); + //l1t::KMTFTrack::CovarianceMatrix cov(covLine.begin(), covLine.end()); + + //double S = (ROOT::Math::Similarity(H, cov))(0, 0) + pointResolutionVertex_; + //S = 1.0 / S; + //Matrix31 Gain = cov * (ROOT::Math::Transpose(H)) * S; + //track.setKalmanGain(track.step(), fabs(track.curvature()), Gain(0, 0), Gain(1, 0), Gain(2, 0)); + + //if (verbose_) { + // edm::LogWarning("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); + // edm::LogWarning("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; + //} + + //int KNew = wrapAround(int(track.curvature() + Gain(0, 0) * residual), pow(2, BITSCURV - 1)); + //int phiNew = wrapAround(int(track.positionAngle() + Gain(1, 0) * residual), pow(2, BITSPHI)); + //int dxyNew = wrapAround(int(track.dxy() + Gain(2, 0) * residual), pow(2, BITSPHIB)); + //if (verbose_) + //edm::LogWarning("KMTFCore") << "Post fit impact parameter=" << dxyNew; + //track.setCoordinatesAtVertex(KNew, phiNew, -residual); + //Matrix33 covNew = cov - Gain * (H * cov); + //l1t::KMTFTrack::CovarianceMatrix c; + //c(0, 0) = covNew(0, 0); + //c(0, 1) = covNew(0, 1); + //c(0, 2) = covNew(0, 2); + //c(1, 0) = covNew(1, 0); + //c(1, 1) = covNew(1, 1); + //c(1, 2) = covNew(1, 2); + //c(2, 0) = covNew(2, 0); + //c(2, 1) = covNew(2, 1); + //c(2, 2) = covNew(2, 2); + //track.setCovariance(c); + //track.covariance = track.covariance - Gain*H*track.covariance; //} //void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track) { -// double residual = -track.dxy(); -// uint absK = fabs(track.curvature()); -// if (absK > pow(2, BITSCURV - 4) - 1) -// absK = pow(2, BITSCURV - 4) - 1; + //double residual = -track.dxy(); + //uint absK = fabs(track.curvature()); + //if (absK > pow(2, BITSCURV - 4) - 1) + //absK = pow(2, BITSCURV - 4) - 1; -// std::pair GAIN = lutService_->vertexGain(track.hitPattern(), absK / 4); -// track.setKalmanGain(track.step(), fabs(track.curvature()), GAIN.first, GAIN.second, -1); + //std::pair GAIN = lutService_->vertexGain(track.hitPattern(), absK / 4); + //track.setKalmanGain(track.step(), fabs(track.curvature()), GAIN.first, GAIN.second, -1); -// ap_fixed k_0 = -// -(ap_ufixed(fabs(GAIN.first))) * ap_fixed(residual); -// int KNew = ap_fixed(k_0 + ap_fixed(track.curvature())); + //ap_fixed k_0 = + // -(ap_ufixed(fabs(GAIN.first))) * ap_fixed(residual); + //int KNew = ap_fixed(k_0 + ap_fixed(track.curvature())); -// if (verbose_) { -// edm::LogWarning("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" -// << ap_ufixed(fabs(GAIN.first)).to_float() << " * " -// << ap_fixed(residual).to_int() << " = " << k_0.to_int(); -// } + //if (verbose_) { + // edm::LogWarning("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" + // << ap_ufixed(fabs(GAIN.first)).to_float() << " * " + // << ap_fixed(residual).to_int() << " = " << k_0.to_int(); + //} //int p_0 = fp_product(GAIN.second, int(residual), 7); -// int p_0 = GAIN.second * int(residual); -// int phiNew = wrapAround(track.positionAngle() + p_0, pow(2, BITSPHI - 1)); -// track.setCoordinatesAtVertex(KNew, phiNew, -residual); + //int p_0 = GAIN.second * int(residual); + //int phiNew = wrapAround(track.positionAngle() + p_0, pow(2, BITSPHI - 1)); + //track.setCoordinatesAtVertex(KNew, phiNew, -residual); //} int KMTFCore::hitPattern(const l1t::KMTFTrack& track) { @@ -1157,8 +1093,8 @@ bool KMTFCore::getBit(int bitmask, int pos) { return (bitmask & (1 << pos)) >> p void KMTFCore::setFourVectors(l1t::KMTFTrack& track) { //int etaINT = track.coarseEta(); //new track eta with linear fit calibrated to gen eta. abandoning the legacy approach of setting track eta from coarseEta - const double m = 0.03458; - const double b = 0.7446; + const double m = 0.03602; + const double b = 0.66840; int etaINT = int(round(m * track.kSlope() + b)); double lsbEta = M_PI / pow(2, 12); diff --git a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc index fadbe1f68b694..3756498b94abd 100644 --- a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc +++ b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc @@ -112,14 +112,14 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubNoEta(const L1Phase2MuDT return stub; } -l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandK(const L1Phase2MuDTExtPhiThetaPair& pairs) { +l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandkSlope(const L1Phase2MuDTExtPhiThetaPair& pairs) { const auto& phiS = pairs.phiDigi(); static constexpr double ZCenterPhysPositive[] = {268.4783935546875, 533.9012145996094}; static constexpr double ZCenterPhysNegative[] = {-267.72308349609375, -533.0657958984375}; static constexpr double ZCenterPhysZero[] = {0.5035400390625}; - static constexpr int RadiusStationPhys[] = {445, 526, 634, 720}; + static constexpr int RadiusStationPhys[] = {445, 526, 635, 730}; int wheel = phiS.whNum(); int abswheel = fabs(phiS.whNum()); int sector = phiS.scNum(); @@ -171,13 +171,8 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandK(const L1Phase2 stub.setEta(z, k, 3); stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), zPhys, kPhys); } else { - if (abswheel == 0) { - stub.setEta(z_centerDigi,k_centerDigi,0); - stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), z_centerPhys, k_centerPhys); - } else { - stub.setEta(z_centerDigi, k_centerDigi, 0); - stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), z_centerPhys, k_centerPhys); - } + stub.setEta(z_centerDigi,k_centerDigi,0); + stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), z_centerPhys, k_centerPhys); } return stub; } @@ -210,7 +205,7 @@ l1t::MuonStubCollection L1TPhase2GMTBarrelStubProcessor::makeStubs(const L1Phase os << std::setw(0) << std::dec << phiDigi.scNum() << " " << phiDigi.whNum() << " " << phiDigi.stNum() << " "; os << std::uppercase << std::setfill('0') << std::setw(16) << std::hex << uint64_t(sN) << " "; } - out.push_back(buildStubwithZandK(pair)); + out.push_back(buildStubwithZandkSlope(pair)); } if (verbose_ == 2) edm::LogInfo("BarrelStub") << os.str() << std::endl; From 343e0071d41e6525d56ed5f498bfa7b6dc9262ee Mon Sep 17 00:00:00 2001 From: delano campos Date: Wed, 29 Apr 2026 14:20:19 -0500 Subject: [PATCH 24/29] 5D vertex constraint offline/LUT updates --- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 160 ++++++++++++++------------ 1 file changed, 88 insertions(+), 72 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index fb6795e86c948..351d609c60e79 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -516,9 +516,10 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { zNew = ap_fixed(ap_fixed(z) - ap_ufixed(zdeltaR_dig) * ap_fixed(kSlope)); if (zNew > (1 << (BITSZ - 1)) - 1) { - if (verbose_) + if (verbose_){ edm::LogWarning("KMTFCore") << "z saturated high during propagation, step=" << step; - zNew = (1 << (BITSZ - 1) - 1); + } + zNew = (1 << (BITSZ - 1)) - 1; } else if (zNew < -(1 << (BITSZ - 1))) { if (verbose_) edm::LogWarning("KMTFCore") << "z saturated low during propagation, step=" << step; @@ -704,7 +705,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int zNew = trackz + int(Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); int kSlopeNew = trackSlope + int(Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); - if ((zNew > (pow(2, BITSZ - 1) - 1)) || (zNew < -(pow(2, BITSZ - 1)))) { + if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { if (verbose_) edm::LogWarning("KMTFCore") << "z saturated in updateOffline"; return false; @@ -814,7 +815,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int zNew = trackz + int(Gain(3, 1) * residual(1) + Gain(3, 2) * residual(2)); int kSlopeNew = trackSlope + int(Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); - if ((zNew > (pow(2, BITSZ - 1) - 1)) || (zNew < -(pow(2, BITSZ - 1)))) { + if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { if (verbose_) edm::LogWarning("KMTFCore") << "z saturated in updateOffline1D"; return false; @@ -961,9 +962,9 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in int zNew; int kSlopeNew; zNew = ap_fixed(ap_fixed(trackz) + ap_ufixed(GAIN_THETA[0]) * residualz - ap_ufixed(GAIN_THETA[1]) * residualSlope); - kSlopeNew = ap_fixed(ap_fixed(trackSlope) - ap_ufixed(GAIN_THETA[2]) * residualz + ap_ufixed(GAIN_THETA[3]) * residualSlope); - if ((zNew > (pow(2, BITSZ - 1) - 1)) || (zNew < -(pow(2, BITSZ - 1)))) { + + if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { if (verbose_) edm::LogWarning("KMTFCore") << "z has saturated"; return false; @@ -995,74 +996,89 @@ void KMTFCore::vertexConstraint(l1t::KMTFTrack& track) { vertexConstraintLUT(track); } -void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track){} -void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track){} - -//void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track) { -// double residual = -track.dxy(); - // Matrix13 H; - //H(0, 0) = 0; - //H(0, 1) = 0; - //H(0, 2) = 1; - - //const std::vector& covLine = track.covariance(); - //l1t::KMTFTrack::CovarianceMatrix cov(covLine.begin(), covLine.end()); - - //double S = (ROOT::Math::Similarity(H, cov))(0, 0) + pointResolutionVertex_; - //S = 1.0 / S; - //Matrix31 Gain = cov * (ROOT::Math::Transpose(H)) * S; - //track.setKalmanGain(track.step(), fabs(track.curvature()), Gain(0, 0), Gain(1, 0), Gain(2, 0)); - - //if (verbose_) { - // edm::LogWarning("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); - // edm::LogWarning("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; - //} - - //int KNew = wrapAround(int(track.curvature() + Gain(0, 0) * residual), pow(2, BITSCURV - 1)); - //int phiNew = wrapAround(int(track.positionAngle() + Gain(1, 0) * residual), pow(2, BITSPHI)); - //int dxyNew = wrapAround(int(track.dxy() + Gain(2, 0) * residual), pow(2, BITSPHIB)); - //if (verbose_) - //edm::LogWarning("KMTFCore") << "Post fit impact parameter=" << dxyNew; - //track.setCoordinatesAtVertex(KNew, phiNew, -residual); - //Matrix33 covNew = cov - Gain * (H * cov); - //l1t::KMTFTrack::CovarianceMatrix c; - //c(0, 0) = covNew(0, 0); - //c(0, 1) = covNew(0, 1); - //c(0, 2) = covNew(0, 2); - //c(1, 0) = covNew(1, 0); - //c(1, 1) = covNew(1, 1); - //c(1, 2) = covNew(1, 2); - //c(2, 0) = covNew(2, 0); - //c(2, 1) = covNew(2, 1); - //c(2, 2) = covNew(2, 2); - //track.setCovariance(c); - //track.covariance = track.covariance - Gain*H*track.covariance; -//} - -//void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track) { - //double residual = -track.dxy(); - //uint absK = fabs(track.curvature()); - //if (absK > pow(2, BITSCURV - 4) - 1) - //absK = pow(2, BITSCURV - 4) - 1; - - //std::pair GAIN = lutService_->vertexGain(track.hitPattern(), absK / 4); - //track.setKalmanGain(track.step(), fabs(track.curvature()), GAIN.first, GAIN.second, -1); - - //ap_fixed k_0 = - // -(ap_ufixed(fabs(GAIN.first))) * ap_fixed(residual); - //int KNew = ap_fixed(k_0 + ap_fixed(track.curvature())); - - //if (verbose_) { - // edm::LogWarning("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" - // << ap_ufixed(fabs(GAIN.first)).to_float() << " * " - // << ap_fixed(residual).to_int() << " = " << k_0.to_int(); - //} + +void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track) { + double residual = -track.dxy(); + Matrix15 H; + H(0, 0) = 0; + H(0, 1) = 0; + H(0, 2) = 1; + H(0, 3) = 0; + H(0, 4) = 0; + + const std::vector& covLine = track.covariance(); + l1t::CovarianceMatrix5dim cov(covLine.begin(), covLine.end()); + + double S = (ROOT::Math::Similarity(H, cov))(0, 0) + pointResolutionVertex_; + S = 1.0 / S; + Matrix51 Gain = cov * (ROOT::Math::Transpose(H)) * S; + track.setKalmanGain(track.step(), fabs(track.curvature()), Gain(0, 0), Gain(1, 0), Gain(2, 0)); + + if (verbose_) { + edm::LogWarning("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); + edm::LogWarning("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; + } + + int KNew = wrapAround(int(track.curvature() + Gain(0, 0) * residual), pow(2, BITSCURV - 1)); + int phiNew = wrapAround(int(track.positionAngle() + Gain(1, 0) * residual), pow(2, BITSPHI)); + int dxyNew = wrapAround(int(track.dxy() + Gain(2, 0) * residual), pow(2, BITSPHIB)); + if (verbose_) + edm::LogWarning("KMTFCore") << "Post fit impact parameter=" << dxyNew; + track.setCoordinatesAtVertex(KNew, phiNew, -residual); + Matrix55 covNew = cov - Gain * (H * cov); + l1t::CovarianceMatrix5dim c; + c(0, 0) = covNew(0, 0); + c(0, 1) = covNew(0, 1); + c(0, 2) = covNew(0, 2); + c(0, 3) = covNew(0, 3); + c(0, 4) = covNew(0, 4); + c(1, 0) = covNew(1, 0); + c(1, 1) = covNew(1, 1); + c(1, 2) = covNew(1, 2); + c(1, 3) = covNew(1, 3); + c(1, 4) = covNew(1, 4); + c(2, 0) = covNew(2, 0); + c(2, 1) = covNew(2, 1); + c(2, 2) = covNew(2, 2); + c(2, 3) = covNew(2, 3); + c(2, 4) = covNew(2, 4); + c(3, 0) = covNew(3, 0); + c(3, 1) = covNew(3, 1); + c(3, 2) = covNew(3, 2); + c(3, 3) = covNew(3, 3); + c(3, 4) = covNew(3, 4); + c(4, 0) = covNew(4, 0); + c(4, 1) = covNew(4, 1); + c(4, 2) = covNew(4, 2); + c(4, 3) = covNew(4, 3); + c(4, 4) = covNew(4, 4); + track.setCovariance(c); +} + +void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track) { + double residual = -track.dxy(); + uint absK = fabs(track.curvature()); + if (absK > pow(2, BITSCURV - 4) - 1) + absK = pow(2, BITSCURV - 4) - 1; + + std::pair GAIN = lutService_->vertexGain(track.hitPattern(), absK / 4); + track.setKalmanGain(track.step(), fabs(track.curvature()), GAIN.first, GAIN.second, -1); + + ap_fixed k_0 = + -(ap_ufixed(fabs(GAIN.first))) * ap_fixed(residual); + int KNew = ap_fixed(k_0 + ap_fixed(track.curvature())); + + if (verbose_) { + edm::LogWarning("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" + << ap_ufixed(fabs(GAIN.first)).to_float() << " * " + << ap_fixed(residual).to_int() << " = " << k_0.to_int(); + } //int p_0 = fp_product(GAIN.second, int(residual), 7); - //int p_0 = GAIN.second * int(residual); - //int phiNew = wrapAround(track.positionAngle() + p_0, pow(2, BITSPHI - 1)); - //track.setCoordinatesAtVertex(KNew, phiNew, -residual); -//} + int p_0 = GAIN.second * int(residual); + int phiNew = wrapAround(track.positionAngle() + p_0, pow(2, BITSPHI - 1)); + track.setCoordinatesAtVertex(KNew, phiNew, -residual); +} int KMTFCore::hitPattern(const l1t::KMTFTrack& track) { unsigned int mask = 0; From a2fde59e285470f82823fc34c4568ae7c1c35559 Mon Sep 17 00:00:00 2001 From: delano campos Date: Wed, 29 Apr 2026 14:52:21 -0500 Subject: [PATCH 25/29] kSlopeNew fixed point arithmetic computation Barrel Stub Processor cleanup update ThetaGain function --- .../L1TMuonPhase2/interface/KMTFTrack.h | 85 +++++++++++++------ DataFormats/L1TMuonPhase2/src/classes_def.xml | 3 +- L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h | 63 +++++++++++--- .../Phase2L1GMT/python/gmtKMTFMuons_cfi.py | 2 +- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 65 +++++++++----- .../src/L1TPhase2GMTBarrelStubProcessor.cc | 35 ++++---- 6 files changed, 173 insertions(+), 80 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h index 0d91f158a6be1..f3be8b3465489 100644 --- a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h +++ b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h @@ -172,16 +172,27 @@ namespace l1t { return kalmanGain0_; } - const std::vector& convergenceGain(unsigned int step) const { + const std::vector& ThetaGain1D(unsigned int step) const { switch (step) { - case 3: return convergenceGain3_; - case 2: return convergenceGain2_; - case 1: return convergenceGain1_; - case 0: return convergenceGain0_; + case 3: return ThetaGain1D3_; + case 2: return ThetaGain1D2_; + case 1: return ThetaGain1D1_; + case 0: return ThetaGain1D0_; } - return convergenceGain0_; + return ThetaGain1D0_; } + const std::vector& ThetaGain(unsigned int step) const { + switch (step) { + case 3: return ThetaGain3_; + case 2: return ThetaGain2_; + case 1: return ThetaGain1_; + case 0: return ThetaGain0_; + } + return ThetaGain0_; + } + + //get covariance const std::vector& covariance() const { return covariance_; } const std::vector& covarianceNB() const { return covarianceNB_; } @@ -335,23 +346,44 @@ namespace l1t { } } - void setConvergenceGain(unsigned int step, unsigned int K, int priorThetaPattern, - float Gz0, float Gz1, float Gk0, float Gk1) { - std::vector* v = nullptr; + void setThetaGain1D(unsigned int step, unsigned int K, int priorThetaPattern, int seedStation, int priorPhiPattern, float G31, float G32, float G41, float G42) { + std::vector* v1 = nullptr; + switch (step) { + case 3: v1 = &ThetaGain1D3_; break; + case 2: v1 = &ThetaGain1D2_; break; + case 1: v1 = &ThetaGain1D1_; break; + case 0: v1 = &ThetaGain1D0_; break; + default: + throw cms::Exception("WrongCondition") << "1D: Critical ERROR on setting the Theta gain\n"; + } + v1->push_back(static_cast(K)); + v1->push_back(static_cast(priorThetaPattern)); + v1->push_back(static_cast(seedStation)); + v1->push_back(static_cast(priorPhiPattern)); + v1->push_back(G31); + v1->push_back(G32); + v1->push_back(G41); + v1->push_back(G42); + } + + void setThetaGain(unsigned int step, unsigned int K, int priorThetaPattern, int seedStation, int priorPhiPattern, float G32, float G33, float G42, float G43) { + std::vector* v2 = nullptr; switch (step) { - case 3: v = &convergenceGain3_; break; - case 2: v = &convergenceGain2_; break; - case 1: v = &convergenceGain1_; break; - case 0: v = &convergenceGain0_; break; + case 3: v2 = &ThetaGain3_; break; + case 2: v2 = &ThetaGain2_; break; + case 1: v2 = &ThetaGain1_; break; + case 0: v2 = &ThetaGain0_; break; default: - throw cms::Exception("WrongCondition") << "Critical ERROR on setting the convergence gain\n"; + throw cms::Exception("WrongCondition") << "Critical ERROR on setting the Theta gain\n"; } - v->push_back(static_cast(K)); - v->push_back(static_cast(priorThetaPattern)); - v->push_back(Gz0); - v->push_back(Gz1); - v->push_back(Gk0); - v->push_back(Gk1); + v2->push_back(static_cast(K)); + v2->push_back(static_cast(priorThetaPattern)); + v2->push_back(static_cast(seedStation)); + v2->push_back(static_cast(priorPhiPattern)); + v2->push_back(G32); + v2->push_back(G33); + v2->push_back(G42); + v2->push_back(G43); } //set covariance @@ -464,10 +496,15 @@ namespace l1t { std::vector residuals_; - std::vector convergenceGain0_; - std::vector convergenceGain1_; - std::vector convergenceGain2_; - std::vector convergenceGain3_; + std::vector ThetaGain1D0_; + std::vector ThetaGain1D1_; + std::vector ThetaGain1D2_; + std::vector ThetaGain1D3_; + + std::vector ThetaGain0_; + std::vector ThetaGain1_; + std::vector ThetaGain2_; + std::vector ThetaGain3_; }; } // namespace l1t diff --git a/DataFormats/L1TMuonPhase2/src/classes_def.xml b/DataFormats/L1TMuonPhase2/src/classes_def.xml index 13409d7876a62..bb196197ddf65 100644 --- a/DataFormats/L1TMuonPhase2/src/classes_def.xml +++ b/DataFormats/L1TMuonPhase2/src/classes_def.xml @@ -25,7 +25,8 @@ - + + diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h b/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h index 796172dfa576a..e6051a1c33410 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h @@ -65,14 +65,23 @@ namespace Phase2L1GMT { lut2LL_[1 * 64 + 2] = (TH1 *)lutFile_->Get("gain2_2_1_LL"); coarseEta_ = (TH1 *)lutFile_->Get("coarseETALUT"); - lutTheta_[1 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain_0_1"); - lutTheta_[1 * 64 + 2] = (TH1 *)lutThetaFile_->Get("gain_2_1"); - lutTheta_[1 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain_4_1"); - lutTheta_[1 * 64 + 6] = (TH1 *)lutThetaFile_->Get("gain_6_1"); - lutTheta_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain_0_2"); - lutTheta_[2 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain_4_2"); - lutTheta_[3 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain_0_3"); - + + lutTheta1D_[1 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_1"); + lutTheta1D_[1 * 64 + 2] = (TH1 *)lutThetaFile_->Get("gain1D_2_1"); + lutTheta1D_[1 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain1D_4_1"); + lutTheta1D_[1 * 64 + 6] = (TH1 *)lutThetaFile_->Get("gain1D_6_1"); + lutTheta1D_[2 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain1D_4_2"); + lutTheta1D_[3 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_3"); + lutTheta2D_[1 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_1"); + lutTheta2D_[1 * 64 + 2] = (TH1 *)lutThetaFile_->Get("gain2D_2_1"); + lutTheta2D_[1 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain2D_4_1"); + lutTheta2D_[1 * 64 + 6] = (TH1 *)lutThetaFile_->Get("gain2D_6_1"); + lutTheta2D_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_2"); + lutTheta2D_[2 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain2D_4_2"); + lutTheta2D_[3 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_3"); + lutTheta1D11_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi1100"); + lutTheta1D01_[2 * 64 + 0]= (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi0100"); + lutTheta1D10_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi1000"); } ~KMTFLUTs() { @@ -87,8 +96,8 @@ namespace Phase2L1GMT { } std::vector trackGain(uint step, uint bitmask, uint K) { - std::vector gain(4, 0.0); - const TH1 *h = lut_[64 * step + bitmask]; + std::vector gain(4, 0.0); + const TH1 *h = lut_[64 * step + bitmask]; gain[0] = h->GetBinContent(K + 1); gain[2] = h->GetBinContent(1024 + K + 1); return gain; @@ -125,10 +134,15 @@ namespace Phase2L1GMT { return uint((1 << 12) * coarseEta_->GetBinContent(coarseEta_->GetXaxis()->FindBin(mask)) / M_PI); } - std::vector trackGainTheta(uint step, uint bitmask, uint K) { + std::vector trackGainTheta(uint step, uint bitmask, uint K, bool is2D) { std::vector gain(4, 0.0); const TH1 *h; - h = lutTheta_[64 * step + bitmask]; + if (is2D){ + h = lutTheta2D_[64 * step + bitmask]; + } + else { + h = lutTheta1D_[64 * step + bitmask]; + } gain[0] = h->GetBinContent(K + 1); gain[1] = h->GetBinContent(512 + K + 1); gain[2] = h->GetBinContent(2 * 512 + K + 1); @@ -136,6 +150,24 @@ namespace Phase2L1GMT { return gain; } + std::vector trackGainTheta2(uint step, uint bitmask, uint phiBitmask, uint K) { + std::vector gain(4, 0.0); + const TH1 *h; + if (phiBitmask == 0b1100){ + h = lutTheta1D11_[64 * step + bitmask]; + } + else if (phiBitmask == 0b1000){ + h = lutTheta1D10_[64 * step + bitmask]; + } + else { + h = lutTheta1D01_[64 * step + bitmask]; + } + gain[0] = h->GetBinContent(K + 1); + gain[1] = h->GetBinContent(512 + K + 1); + gain[2] = h->GetBinContent(2 * 512 + K + 1); + gain[3] = h->GetBinContent(3 * 512 + K + 1); + return gain; + } TFile *lutFile_; TFile *lutThetaFile_; @@ -144,7 +176,12 @@ namespace Phase2L1GMT { std::map lut2LH_; std::map lut2HL_; std::map lut2LL_; - std::map lutTheta_; + + std::map lutTheta1D_; + std::map lutTheta2D_; + std::map lutTheta1D11_; + std::map lutTheta1D10_; + std::map lutTheta1D01_; const TH1 *coarseEta_; }; diff --git a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py index 31c8865e12fc8..5119381b7c8fa 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtKMTFMuons_cfi.py @@ -56,7 +56,7 @@ combos3=cms.vint32(5,6,7), combos2=cms.vint32(3), combos1=cms.vint32(), #for future possible usage - useOfflineAlgo = cms.bool(True), + useOfflineAlgo = cms.bool(False), ###Only for the offline algo -not in firmware -------------------- mScatteringPhi = cms.vdouble(0.1169021113298598, 0.00016777763395543814, 0.0004322078772344548, 0.00024985881710722107), mScatteringPhiB = cms.vdouble(.0522762, 0.01762000062188365, 0.03508319015441297, 0.03126825551530328), diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 351d609c60e79..ae9a2b0211ced 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -156,7 +156,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef else covariance(2, 2) = float(pointResolutionPhiBH_[seed->depthRegion() - 1]); } - if (seed->depthRegion() == 4) { + if (seed->etaQuality() <= 0) { covariance(3,3) = pow(2, 22); covariance(4,4) = pow(2, 22); } else { @@ -649,6 +649,8 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int z = stub->eta1(); int kSlope = stub->eta2(); int priorThetaPattern = track.thetaDigiPattern(); + int priorPhiPattern = track.hitPattern(); + int seedStation = track.stubs().empty() ? 0 : track.stubs()[0]->depthRegion(); Vector4 residual; residual[0] = ap_fixed(phi - trackPhi); @@ -719,23 +721,23 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); if (verbose_) { - edm::LogWarning("KMTFCore") << "residual(0): " << phi << "-" << trackPhi << " = " << residual(0); - edm::LogWarning("KMTFCore") << "residual(1): " << phiB << "-" << trackPhiB << " = " << residual(1); - edm::LogWarning("KMTFCore") << "residual(2): " << z << "-" << trackz << " = " << residual(2); - edm::LogWarning("KMTFCore") << "residual(3): " << kSlope << "-" << trackSlope << " = " << residual(3); - edm::LogWarning("KMTFCore") << "Gain(0,0): " << Gain(0, 0); - edm::LogWarning("KMTFCore") << "Gain(0,1): " << Gain(0, 1); - edm::LogWarning("KMTFCore") << "Gain(2,0): " << Gain(2, 0); - edm::LogWarning("KMTFCore") << "Gain(2,1): " << Gain(2, 1); - edm::LogWarning("KMTFCore") << "Gain(3,2): " << Gain(3, 2); - edm::LogWarning("KMTFCore") << "Gain(3,3): " << Gain(3, 3); - edm::LogWarning("KMTFCore") << "Gain(4,2): " << Gain(4, 2); - edm::LogWarning("KMTFCore") << "Gain(4,3): " << Gain(4, 3); - edm::LogWarning("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0) << "+" << Gain(0, 1) << "*" << residual(1) << " = " << KNew ; - edm::LogWarning("KMTFCore") << " phiNew = " << trackPhi << "+" << residual(0) << " = " << phiNew; - edm::LogWarning("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0) << "+" << Gain(2, 1) << "*" << residual(1) << " = " << phiBNew; - edm::LogWarning("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 2) << "*" << residual(2) << "+" << Gain(3, 3) << "*" << residual(3) << " = " << zNew; - edm::LogWarning("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 2) << "*" << residual(2) << "+" << Gain(4, 3) << "*" << residual(3) << " = " << kSlopeNew; + std::cout << "residual(0): " << phi << "-" << trackPhi << " = " << residual(0) << "\n"; + std::cout << "residual(1): " << phiB << "-" << trackPhiB << " = " << residual(1) << "\n"; + std::cout << "residual(2): " << z << "-" << trackz << " = " << residual(2) << "\n"; + std::cout << "residual(3): " << kSlope << "-" << trackSlope << " = " << residual(3) << "\n"; + std::cout << "Gain(0,0): " << Gain(0, 0) << "\n"; + std::cout << "Gain(0,1): " << Gain(0, 1) << "\n"; + std::cout << "Gain(2,0): " << Gain(2, 0) << "\n"; + std::cout << "Gain(2,1): " << Gain(2, 1) << "\n"; + std::cout << "Gain(3,2): " << Gain(3, 2) << "\n"; + std::cout << "Gain(3,3): " << Gain(3, 3) << "\n"; + std::cout << "Gain(4,2): " << Gain(4, 2) << "\n"; + std::cout << "Gain(4,3): " << Gain(4, 3) << "\n"; + std::cout << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0) << "+" << Gain(0, 1) << "*" << residual(1) << " = " << KNew << "\n"; + std::cout << " phiNew = " << trackPhi << "+" << residual(0) << " = " << phiNew << "\n"; + std::cout << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0) << "+" << Gain(2, 1) << "*" << residual(1) << " = " << phiBNew << "\n"; + std::cout << " zNew = " << trackz << "+" << Gain(3, 2) << "*" << residual(2) << "+" << Gain(3, 3) << "*" << residual(3) << " = " << zNew << "\n"; + std::cout << " kSlopeNew = " << trackSlope << "+" << Gain(4, 2) << "*" << residual(2) << "+" << Gain(4, 3) << "*" << residual(3) << " = " << kSlopeNew << "\n"; } track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); @@ -750,7 +752,19 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 2), Gain(3, 3), Gain(4, 2), Gain(4, 3)); + track.setThetaGain(track.step(), fabs(trackK), priorThetaPattern, seedStation, priorPhiPattern, Gain(3, 2), Gain(3, 3), Gain(4, 2), Gain(4, 3)); + + if (verbose_){ + std::cout << "step: " << track.step() << "\n"; + std::cout << "|K|: " << fabs(trackK) << "\n"; + std::cout << "priorThetaPattern: " << priorThetaPattern << "\n"; + std::cout << "priorPhiPattern: " << priorPhiPattern << "\n"; + std::cout << "seed Station: " << seedStation << "\n"; + std::cout << "Gain32: " << Gain(3, 2) << "\n"; + std::cout << "Gain33: " << Gain(3, 3) << "\n"; + std::cout << "Gain42: " << Gain(4, 2) << "\n"; + std::cout << "Gain43: " << Gain(4, 3) << "\n"; + } return true; } @@ -765,6 +779,8 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int z = stub->eta1(); int kSlope = stub->eta2(); int priorThetaPattern = track.thetaDigiPattern(); + int priorPhiPattern = track.hitPattern(); + int seedStation = track.stubs().empty() ? 0 : track.stubs()[0]->depthRegion(); Vector3 residual; residual[0] = ap_fixed(phi - trackPhi); @@ -847,7 +863,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - track.setConvergenceGain(track.step(), fabs(trackK), priorThetaPattern, Gain(3, 1), Gain(3, 2), Gain(4, 1), Gain(4, 2)); + track.setThetaGain1D(track.step(), fabs(trackK), priorThetaPattern, seedStation, priorPhiPattern, Gain(3, 1), Gain(3, 2), Gain(4, 1), Gain(4, 2)); return true; } @@ -894,7 +910,12 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in GAIN = lutService_->trackGain2(track.step(), track.hitPattern(), absK / 32, seedQual, stub->quality()); } - GAIN_THETA = lutService_->trackGainTheta(track.step(), track.thetaDigiPattern(), absK / 32); + const bool is2D = (mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12); + if (!(is2D) && (track.step() == 2) && (track.thetaDigiPattern() == 0)) { + GAIN_THETA = lutService_->trackGainTheta2(track.step(), track.thetaDigiPattern(), track.hitPattern(), absK / 32); + } else { + GAIN_THETA = lutService_->trackGainTheta(track.step(), track.thetaDigiPattern(), absK / 32, is2D); + } if (verbose_) { edm::LogWarning("KMTFCore") << "Gains (fp): " << GAIN[0] << " " << GAIN[1] << " " << GAIN[2] << " " << GAIN[3]; @@ -962,7 +983,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in int zNew; int kSlopeNew; zNew = ap_fixed(ap_fixed(trackz) + ap_ufixed(GAIN_THETA[0]) * residualz - ap_ufixed(GAIN_THETA[1]) * residualSlope); - + kSlopeNew = ap_fixed(ap_fixed(trackSlope) - ap_ufixed(GAIN_THETA[2]) * residualz + ap_ufixed(GAIN_THETA[3]) * residualSlope); if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { if (verbose_) diff --git a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc index 3756498b94abd..2c8b84676580d 100644 --- a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc +++ b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc @@ -115,11 +115,10 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubNoEta(const L1Phase2MuDT l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandkSlope(const L1Phase2MuDTExtPhiThetaPair& pairs) { const auto& phiS = pairs.phiDigi(); - - static constexpr double ZCenterPhysPositive[] = {268.4783935546875, 533.9012145996094}; - static constexpr double ZCenterPhysNegative[] = {-267.72308349609375, -533.0657958984375}; - static constexpr double ZCenterPhysZero[] = {0.5035400390625}; - static constexpr int RadiusStationPhys[] = {445, 526, 635, 730}; + static constexpr int ZCenterDigitizedPositive[] = {11730, 23327}; + static constexpr int ZCenterDigitizedNegative[] = {-11697, -23290}; + static constexpr int ZCenterDigitizedZero[] = {22}; + static constexpr float RadiusStationPhys[] = {445., 526., 635., 730.}; int wheel = phiS.whNum(); int abswheel = fabs(phiS.whNum()); int sector = phiS.scNum(); @@ -142,31 +141,29 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandkSlope(const L1P l1t::MuonStub stub(wheel, sector, station, tfLayer, phi, phiS.phiBend(), tag, bx, quality, 0, 0, 0, 1); //defining z, k, zPhys, kPhys for case where theta digi exists - //defining k_centerPhys, z_centerPhys, k_centerDigi, z_centerDigi for case where theta digi does not exist - constexpr float ZRES_CONV = 65536.0 / 1500.0 ; - constexpr float KRES_CONV = 65536.0 / 2.0 ; int z = pairs.thetaDigi().z(); int k = pairs.thetaDigi().k(); - double zPhys = z / ZRES_CONV; - double kPhys = k / KRES_CONV; + float zPhys = z * (1500. / (1 << 16)); + float kPhys = k * (2. / (1 << 16)); //slight asymmetry in wheels w.r.t. the origin calls for different z_center values for case where no theta digi was matched - double z_centerPhys; + //defining z_center adn k_center for when theta digi does NOT exist!! + int z_centerDigi; if (wheel > 0){ - z_centerPhys= ZCenterPhysPositive[abswheel - 1]; + z_centerDigi= ZCenterDigitizedPositive[abswheel - 1]; } else if (wheel < 0) { - z_centerPhys= ZCenterPhysNegative[abswheel - 1]; + z_centerDigi= ZCenterDigitizedNegative[abswheel - 1]; } else { - z_centerPhys= ZCenterPhysZero[0]; + z_centerDigi= ZCenterDigitizedZero[0]; } - - double R_centerPhys = RadiusStationPhys[station - 1]; - double k_centerPhys = z_centerPhys / R_centerPhys; - int k_centerDigi = (int)(KRES_CONV * k_centerPhys); - int z_centerDigi = (int)(ZRES_CONV * z_centerPhys); + float z_centerPhys = z_centerDigi * (1500. / (1 << 16)); + float R_centerPhys = RadiusStationPhys[station - 1]; + float k_centerPhys = z_centerPhys / R_centerPhys; + int k_centerDigi = k_centerPhys * ((1 << 16) / 2.); // check if theta digi exists with non-default constructor quality --> use z, k with etaQuality=3 from theta digi. // if theta digi has no real data, use z_center and slope which points to origin with etaQuality=0.. + // stub set to etaQuality==3 if theta digi exists, 0 if not. if (pairs.thetaDigi().quality() >= 0) { stub.setEta(z, k, 3); stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), zPhys, kPhys); From 432ccea940546ce4c3976843a07e77669f91f999 Mon Sep 17 00:00:00 2001 From: delano campos Date: Fri, 15 May 2026 18:24:14 -0500 Subject: [PATCH 26/29] Track functionality to hold z, kSlope at Muon station 1 and Vertex. Update in core where these are set. KMTFPattern saves granular eta instead of coarse. Also saved z, kSlope. fix prinouts for KMTFPatterns SetPtEtaPhiDispl now stores etaDisp z, kSlope saturation changes saturate KSlope properly and add edm::LogWarnings provide z0, new eta to SAMuon update LSB comment LogInfo add back srcDT, srcDTTheta --- .../L1TMuonPhase2/interface/KMTFTrack.h | 28 +- DataFormats/L1TMuonPhase2/src/classes_def.xml | 9 +- L1Trigger/Phase2L1GMT/interface/KMTFCore.h | 3 +- .../plugins/Phase2L1TGMTKMTFProducer.cc | 14 +- .../plugins/Phase2L1TGMTStubProducer.cc | 12 + L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py | 2 + L1Trigger/Phase2L1GMT/src/KMTF.cc | 135 ++++--- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 359 +++++++++++------- 8 files changed, 355 insertions(+), 207 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h index f3be8b3465489..0031a0f30cfef 100644 --- a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h +++ b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h @@ -24,10 +24,14 @@ namespace l1t { ptC_(0), phiVertex_(0), dxy_(0), + zVertex_(0), + kSlopeVertex_(0), curvMuon_(0), ptU_(0), phiMuon_(0), phiBMuon_(0), + zMuon_(0), + kSlopeMuon_(0), curv_(0), phi_(0), phiB_(0), @@ -61,10 +65,14 @@ namespace l1t { ptC_(0), phiVertex_(0), dxy_(0), + zVertex_(0), + kSlopeVertex_(0), curvMuon_(0), ptU_(0), phiMuon_(0), phiBMuon_(0), + zMuon_(0), + kSlopeMuon_(0), curv_(0), phi_(phi), phiB_(phiB), @@ -103,6 +111,10 @@ namespace l1t { int phiAtMuon() const { return phiMuon_; } //unconstrained phiB at station 1 int phiBAtMuon() const { return phiBMuon_; } + //unconstrained z at station 1 + int zAtMuon() const { return zMuon_; } + //unconstrained kSLope at station 1 + int kSlopeAtMuon() const { return kSlopeMuon_; } //constrained pt int ptPrompt() const { return ptC_; } @@ -110,6 +122,10 @@ namespace l1t { int curvatureAtVertex() const { return curvVertex_; } //constrained phi at the vertex int phiAtVertex() const { return phiVertex_; } + //constrained z at the vertex + int zAtVertex() const { return zVertex_; } + //constrained kSlope at the vertex + int kSlopeAtVertex() const { return kSlopeVertex_; } //Impact parameter as calculated from the muon track int dxy() const { return dxy_; } //Unconstrained curvature at the Muon systen @@ -235,16 +251,20 @@ namespace l1t { kSlope_ = kSlope; } - void setCoordinatesAtVertex(int curv, int phi, int dxy) { + void setCoordinatesAtVertex(int curv, int phi, int dxy, int z, int kSlope) { curvVertex_ = curv; phiVertex_ = phi; dxy_ = dxy; + zVertex_ = z; + kSlopeVertex_ = kSlope; } - void setCoordinatesAtMuon(int curv, int phi, int phiB) { + void setCoordinatesAtMuon(int curv, int phi, int phiB, int z, int kSlope) { curvMuon_ = curv; phiMuon_ = phi; phiBMuon_ = phiB; + zMuon_ = z; + kSlopeMuon_ = kSlope; } void setPt(int ptC, int ptU) { @@ -434,12 +454,16 @@ namespace l1t { int ptC_; int phiVertex_; int dxy_; + int zVertex_; + int kSlopeVertex_; //muon coordinates int curvMuon_; int ptU_; int phiMuon_; int phiBMuon_; + int zMuon_; + int kSlopeMuon_; //generic coordinates int curv_; diff --git a/DataFormats/L1TMuonPhase2/src/classes_def.xml b/DataFormats/L1TMuonPhase2/src/classes_def.xml index bb196197ddf65..d472ab4c4e6b7 100644 --- a/DataFormats/L1TMuonPhase2/src/classes_def.xml +++ b/DataFormats/L1TMuonPhase2/src/classes_def.xml @@ -25,12 +25,9 @@ - - - - - - + + + diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h index 09f031cfd2457..bb6942a5dbe1a 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h @@ -66,6 +66,7 @@ namespace Phase2L1GMT { bool estimateChiSquare(l1t::KMTFTrack& track, bool vertex); void setRank(l1t::KMTFTrack& track, bool vertex); int wrapAround(int value, int maximum); + int satKSlope(int k); int encode(bool ownwheel, int sector, int tag); std::pair getByCode(const std::vector& tracks, int mask); uint twosCompToBits(int q); @@ -131,7 +132,7 @@ namespace Phase2L1GMT { //bits for fixed point precision static const int PHIBSCALE = 16; static const int PHIBSCALE_INT = 5; - static const int ZDELTAR_BITS = 15; + static const int ZDELTAR_BITS = 14; static const int ZDELTAR_BITSINT = 1; static const int BITSCURV = 16; static const int BITSPHI = 18; diff --git a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTKMTFProducer.cc b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTKMTFProducer.cc index 04855cd154cb3..d24921204377e 100644 --- a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTKMTFProducer.cc +++ b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTKMTFProducer.cc @@ -95,12 +95,17 @@ void Phase2L1TGMTKMTFProducer::produce(edm::Event& iEvent, const edm::EventSetup std::vector kmtfTracks; for (const auto& track : kmtfOutput.first) { kmtfTracks.push_back(track); + //convert kmtf track.zPosition (LSB_kmtf=1500./2<<16) into z0 for SAMuon. + //LSBSAz0 = 1.6cm is too small given only 5 bits. the range fro z0 is +- 25.6cm from DataFormats/L1TMuonPhase2/interface/Constants.h + //eff. LSB = 1.6cm * 16 = 25.6 cm to widen the z0 range that can covered given only 5 bits. + //full conversion is z0_SA=z0_kmtf*(LSB_kmtf)*(1/LSB_SA)*(1/16) to convert between kmtf->SAMuon digitizations + ap_fixed z0 = track.zPosition() * ap_ufixed<18, 0>((1500.0 / (1 << 16)) / (LSBSAz0 * 16)); l1t::SAMuon p(track.p4(), (track.curvatureAtVertex() < 0), track.ptPrompt(), - track.coarseEta(), + round(track.eta() / (M_PI / (1 << 12))), track.phiAtMuon() / (1 << 5), - 0, + z0, 0, track.stubs().size() - 1); p.setTF(l1t::tftype::bmtf); @@ -123,12 +128,13 @@ void Phase2L1TGMTKMTFProducer::produce(edm::Event& iEvent, const edm::EventSetup for (const auto& track : kmtfOutput.second) { kmtfTracks.push_back(track); ap_int<7> dxy = track.dxy() * ap_ufixed<8, 1>(1.606); + ap_fixed z0 = track.zPosition() * ap_ufixed<18, 0>((1500.0 / (1 << 16)) / (LSBSAz0 * 16)); l1t::SAMuon p(track.displacedP4(), (track.curvatureAtMuon() < 0), track.ptDisplaced(), - track.coarseEta(), + round(track.eta() / (M_PI / (1 << 12))), track.phiAtMuon() / (1 << 5), - 0, + z0, dxy, track.approxDispChi2()); p.setTF(l1t::tftype::bmtf); diff --git a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc index c3dc3b4ca1f51..ab61b1bb77947 100644 --- a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc +++ b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc @@ -34,6 +34,8 @@ class Phase2L1TGMTStubProducer : public edm::stream::EDProducer<> { void endStream() override; l1t::MuonStub convertToHybrid(const l1t::MuonStub& stub); edm::EDGetTokenT> srcCSC_; + edm::EDGetTokenT srcDT_; + edm::EDGetTokenT srcDTTheta_; edm::EDGetTokenT srcDTPairs_; edm::EDGetTokenT srcRPC_; @@ -46,6 +48,8 @@ class Phase2L1TGMTStubProducer : public edm::stream::EDProducer<> { Phase2L1TGMTStubProducer::Phase2L1TGMTStubProducer(const edm::ParameterSet& iConfig) : srcCSC_( consumes>(iConfig.getParameter("srcCSC"))), + srcDT_(consumes(iConfig.getParameter("srcDT"))), + srcDTTheta_(consumes(iConfig.getParameter("srcDTTheta"))), srcDTPairs_(consumes(iConfig.getParameter("srcDTPairs"))), srcRPC_(consumes(iConfig.getParameter("srcRPC"))), procEndcap_(new L1TPhase2GMTEndcapStubProcessor(iConfig.getParameter("Endcap"))), @@ -101,6 +105,12 @@ void Phase2L1TGMTStubProducer::produce(edm::Event& iEvent, const edm::EventSetup Handle rpcDigis; iEvent.getByToken(srcRPC_, rpcDigis); + Handle dtDigis; + iEvent.getByToken(srcDT_, dtDigis); + + Handle dtThetaDigis; + iEvent.getByToken(srcDTTheta_, dtThetaDigis); + Handle dtPairs; iEvent.getByToken(srcDTPairs_, dtPairs); @@ -134,6 +144,8 @@ void Phase2L1TGMTStubProducer::fillDescriptions(edm::ConfigurationDescriptions& edm::ParameterSetDescription desc; desc.add("verbose", 0); desc.add("srcCSC", edm::InputTag("simCscTriggerPrimitiveDigis")); + desc.add("srcDT", edm::InputTag("dtTriggerPhase2PrimitiveDigis")); + desc.add("srcDTTheta", edm::InputTag("simDtTriggerPrimitiveDigis")); desc.add("srcDTPairs", edm::InputTag("dtTriggerPhase2PrimitivePairDigis")); desc.add("srcRPC", edm::InputTag("simMuonRPCDigis")); { diff --git a/L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py b/L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py index c8eabb59583e3..97053d7bcc162 100644 --- a/L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py +++ b/L1Trigger/Phase2L1GMT/python/gmtStubs_cfi.py @@ -3,6 +3,8 @@ gmtStubs = cms.EDProducer("Phase2L1TGMTStubProducer", verbose = cms.int32(0), srcCSC = cms.InputTag("simCscTriggerPrimitiveDigis"), + srcDT = cms.InputTag("dtTriggerPhase2PrimitiveDigis"), + srcDTTheta = cms.InputTag("simDtTriggerPrimitiveDigis"), srcDTPairs = cms.InputTag("dtTriggerPhase2PrimitivePairDigis"), srcRPC = cms.InputTag("simMuonRPCDigis"), Endcap =cms.PSet( diff --git a/L1Trigger/Phase2L1GMT/src/KMTF.cc b/L1Trigger/Phase2L1GMT/src/KMTF.cc index 5a5c4613bc2b4..72dec42cb9b2e 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTF.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTF.cc @@ -82,64 +82,71 @@ std::pair, std::vector > KMTF::proce if (patterns) { edm::LogInfo("KMTF") << "KMTFPattern " << std::flush; if (i < Nstubs4) - edm::LogInfo("KMTF") << stubs4[0]->coord1() << " " << stubs4[0]->coord2() << " " << stubs4[0]->quality() << " " - << " 1 " << stubs4[0]->kmtf_address() << " 0 " << std::flush; + edm::LogInfo("KMTF") << stubs4[0]->coord1() << " " << stubs4[0]->coord2() << " " << stubs4[0]->quality() << " " + << " 1 " << stubs4[0]->kmtf_address() << " 0 " << stubs4[0]->eta1() << " " + << stubs4[0]->eta2() << " " << (stubs4[0]->etaQuality() > 0 ? 1 : 0) << " " << std::flush; else - edm::LogInfo("KMTF") << "0 0 0 0 511 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; if (i < Nstubs3) { for (const auto& s : stubs3) { - edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " - << s->kmtf_address() << " 0 " << std::flush; + edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " + << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } //pad with zeros for (unsigned int j = stubs3.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } } else { for (unsigned int j = stubs3.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } for (const auto& s : stubs3) { - edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " - << s->kmtf_address() << " 0 " << std::flush; + edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " + << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } } if (i < Nstubs2) { for (const auto& s : stubs2) { - edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " - << s->kmtf_address() << " 0 " << std::flush; + edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " + << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } //pad with zeros for (unsigned int j = stubs2.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } } else { for (unsigned int j = stubs2.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } for (const auto& s : stubs2) { - edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() - << " 0 " << std::flush; + edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() + << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } } if (i < Nstubs1) { for (const auto& s : stubs1) { - edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() - << " 0 " << std::flush; + edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() + << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } //pad with zeros for (unsigned int j = stubs1.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } } else { for (unsigned int j = stubs1.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } for (const auto& s : stubs1) { - edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() - << " 0 " << std::flush; + edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() + << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } } } @@ -160,25 +167,27 @@ std::pair, std::vector > KMTF::proce pretracksD4.push_back(tracks.second); if (patterns) { if (tracks.first.id() & 0x1) - edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " - << tracks.first.coarseEta() << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.first.rankPrompt() << " " << std::flush; - + edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " + << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) + << " " << tracks.first.rankPrompt() << " " + << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " + << " " << std::flush; else - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; if (tracks.second.id() & 0x2) - edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " - << tracks.second.coarseEta() << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.second.rankDisp() << " " << std::flush; - + edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " + << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) + << " " << tracks.second.rankDisp() << " " + << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " + << " " << std::flush; else - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } } else if (patterns) { - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } if (i < Nstubs3) { @@ -194,25 +203,30 @@ std::pair, std::vector > KMTF::proce pretracksD3.push_back(tracks.second); if (patterns) { if (tracks.first.id() & 0x1) - edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " - << tracks.first.coarseEta() << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.first.rankPrompt() << " " << std::flush; + edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " + << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) + << " " << tracks.first.rankPrompt() << " " + << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " + << " " << std::flush; else - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; if (tracks.second.id() & 0x2) - edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " - << tracks.second.coarseEta() << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.second.rankDisp() << " " << std::flush; + edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " + << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) + << " " << tracks.second.rankDisp() << " " + << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " + << " " << std::flush; + else - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } } else if (patterns) { - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } if (i < Nstubs2) { l1t::MuonStubRefVector stubs_proc; @@ -225,24 +239,27 @@ std::pair, std::vector > KMTF::proce pretracksD2.push_back(tracks.second); if (patterns) { if (tracks.first.id() & 0x1) - edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " - << tracks.first.coarseEta() << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.first.rankPrompt() << " " << std::flush; + edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " + << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) + << " " << tracks.first.rankPrompt() << " " + << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " + << " " << std::flush; else - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0" << std::flush; if (tracks.second.id() & 0x2) - edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " - << tracks.second.coarseEta() << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.second.rankDisp(); + edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " + << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) + << " " << tracks.second.rankDisp() << " " + << tracks.second.zPosition() << " " << tracks.second.kSlope() << " "; else - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0" << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } } else if (patterns) { - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 " << std::flush; - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0"; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 "; } //Now the shift register emulation in C_++ if (stubs4.size() > 1) { diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index ae9a2b0211ced..2135e248609ed 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -84,10 +84,10 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef throw cms::Exception("KMTFCore") << "Something really bad happend\n"; } - l1t::KMTFTrack nullTrack(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), seed->eta2()); + l1t::KMTFTrack nullTrack(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), satKSlope(seed->eta2())); seedQual = seed->quality(); for (const auto& mask : combinatorics) { - l1t::KMTFTrack track(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), seed->eta2()); + l1t::KMTFTrack track(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), satKSlope(seed->eta2())); int phiB = correctedPhiB(seed); int charge; if (phiB == 0) @@ -109,13 +109,13 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef if (initialK <= -pow(2, BITSCURV - 1)) initialK = -pow(2, BITSCURV - 1) + 1; - track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), phiB, seed->eta1(), seed->eta2()); + track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), phiB, seed->eta1(), satKSlope(seed->eta2())); if (seed->quality() < 6) { - track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), seed->eta2()); + track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), satKSlope(seed->eta2())); } if (verbose_) { - edm::LogWarning("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK << " z=" << seed->eta1() << " kSlope=" << seed->eta2(); + edm::LogInfo("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK << " z=" << seed->eta1() << " kSlope=" << satKSlope(seed->eta2()); } track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); @@ -166,23 +166,23 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef track.setCovariance(covariance); if (verbose_) { - edm::LogWarning("KMTFCore") << "New Kalman fit staring at step=" << track.step() << ", phi=" << track.positionAngle() + edm::LogInfo("KMTFCore") << "New Kalman fit staring at step=" << track.step() << ", phi=" << track.positionAngle() << ", phiB=" << track.bendingAngle() << ", z=" << track.zPosition() << ",kSlope = " << track.kSlope() << ", with curvature=" << track.curvature() ; - edm::LogWarning("KMTFCore") << "BITMASK:" << std::flush; + edm::LogInfo("KMTFCore") << "BITMASK:" << std::flush; for (unsigned int i = 0; i < 4; ++i) - edm::LogWarning("KMTFCore") << getBit(mask, i) << std::flush; - edm::LogWarning("KMTFCore") << std::endl; - edm::LogWarning("KMTFCore") << "------------------------------------------------------"; - edm::LogWarning("KMTFCore") << "------------------------------------------------------"; - edm::LogWarning("KMTFCore") << "------------------------------------------------------"; - edm::LogWarning("KMTFCore") << "stubs:"; + edm::LogInfo("KMTFCore") << getBit(mask, i) << std::flush; + edm::LogInfo("KMTFCore") << std::endl; + edm::LogInfo("KMTFCore") << "------------------------------------------------------"; + edm::LogInfo("KMTFCore") << "------------------------------------------------------"; + edm::LogInfo("KMTFCore") << "------------------------------------------------------"; + edm::LogInfo("KMTFCore") << "stubs:"; for (const auto& stub : stubs) - edm::LogWarning("KMTFCore") << "station=" << stub->depthRegion() << " phi=" << stub->coord1() + edm::LogInfo("KMTFCore") << "station=" << stub->depthRegion() << " phi=" << stub->coord1() << " phiB=" << correctedPhiB(stub) << " qual=" << stub->quality() << " tag=" << stub->id() << " sector=" << stub->phiRegion() - << " wheel=" << stub->etaRegion() << " z= " << stub->eta1() << " kSlope = " << stub->eta2(); - edm::LogWarning("KMTFCore") << "------------------------------------------------------"; - edm::LogWarning("KMTFCore") << "------------------------------------------------------"; + << " wheel=" << stub->etaRegion() << " z= " << stub->eta1() << " kSlope = " << satKSlope(stub->eta2()); + edm::LogInfo("KMTFCore") << "------------------------------------------------------"; + edm::LogInfo("KMTFCore") << "------------------------------------------------------"; } bool passedU = false; @@ -190,47 +190,66 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef while (track.step() > 0) { // muon station 1 if (track.step() == 1) { - track.setCoordinatesAtMuon(track.curvature(), track.positionAngle(), track.bendingAngle()); + track.setCoordinatesAtMuon(track.curvature(), track.positionAngle(), track.bendingAngle(), track.zPosition(), track.kSlope()); passedU = estimateChiSquare(track, false); setRank(track, false); if (verbose_) - edm::LogWarning("KMTFCore") << "Calculated Chi2 for displaced track =" << track.approxDispChi2() + edm::LogInfo("KMTFCore") << "Calculated Chi2 for displaced track =" << track.approxDispChi2() << " Passed Cut=" << passedU; calculateEta(track); setFourVectors(track); //calculate coarse eta ////////////////////// if (verbose_){ - edm::LogWarning("KMTFCore") << "Unconstrained PT in Muon System: pt=" << track.displacedP4().pt(); + edm::LogInfo("KMTFCore") << "Unconstrained PT in Muon System: pt=" << track.displacedP4().pt(); } calculateEta(track); } propagate(track); if (verbose_) - edm::LogWarning("KMTFCore") << "propagated Coordinates step:" << track.step() << "phi=" << track.positionAngle() + edm::LogInfo("KMTFCore") << "propagated Coordinates step:" << track.step() << "phi=" << track.positionAngle() << "phiB=" << track.bendingAngle() << "K=" << track.curvature() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); if (track.step() > 0){ if (getBit(mask, track.step() - 1)) { std::pair bestStub = match(seed, stubs, track.step()); if (verbose_) - edm::LogWarning("KMTFCore") << "Found match =" << bestStub.first << " index=" << bestStub.second + edm::LogInfo("KMTFCore") << "Found match =" << bestStub.first << " index=" << bestStub.second << " number of all stubs=" << stubs.size(); - - if ((!bestStub.first) || (!update(track, stubs[bestStub.second], mask, seedQual))) + const bool updated = bestStub.first ? update(track, stubs[bestStub.second], mask, seedQual) : false; + if ((!bestStub.first) || (!updated)) { + if (verbose_) { + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] Breaking Kalman chain before final ID assignment" + << " seed(st=" << seed->depthRegion() << ",sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() + << ",bx=" << seed->bxNum() << ",id=" << seed->id() << ")" + << " step=" << track.step() << " mask=" << mask << " hitPattern=" << track.hitPattern() + << " matchFound=" << bestStub.first << " matchIndex=" << bestStub.second << " updateOK=" << updated + << " partialID=" << track.id() << " nStubs=" << track.stubs().size(); + if (seed->depthRegion() == 2) { + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG_STA2] break-on-no-update/no-match" + << " seed(st=2,sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() << ",bx=" << seed->bxNum() + << ",id=" << seed->id() << ")" + << " currentStep=" << track.step() << " mask=" << mask << " hitPattern=" << track.hitPattern() + << " thetaPattern=" << track.thetaDigiPattern() << " passU_sofar=" << passedU + << " passV_sofar=" << passedV << " id_sofar=" << track.id() << " phiMuon=" << track.phiAtMuon() + << " phiVertex=" << track.phiAtVertex() << " z=" << track.zPosition() + << " kSlope=" << track.kSlope(); + } + } break; + } if (verbose_) { - edm::LogWarning("KMTFCore") << "updated Coordinates step:" << track.step() << " phi=" << track.positionAngle() + edm::LogInfo("KMTFCore") << "updated Coordinates step:" << track.step() << " phi=" << track.positionAngle() << " phiB=" << track.bendingAngle() << " K=" << track.curvature() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); } } } if (track.step() == 0) { - track.setCoordinatesAtVertex(track.curvature(), track.positionAngle(), track.bendingAngle()); + track.setCoordinatesAtVertex(track.curvature(), track.positionAngle(), track.bendingAngle(), track.zPosition(), track.kSlope()); if (verbose_) - edm::LogWarning("KMTFCore") << " Coordinates before vertex constraint step:" << track.step() + edm::LogInfo("KMTFCore") << " Coordinates before vertex constraint step:" << track.step() << " phi=" << track.phiAtVertex() << " dxy=" << track.dxy() << " K=" << track.curvatureAtVertex() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); @@ -242,23 +261,46 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef setRank(track, true); if (verbose_) - edm::LogWarning("KMTFCore") << "Calculated Chi2 for prompt track =" << track.approxPromptChi2() + edm::LogInfo("KMTFCore") << "Calculated Chi2 for prompt track =" << track.approxPromptChi2() << " Passed Cut=" << passedV; if (verbose_) { - edm::LogWarning("KMTFCore") << " Coordinates after vertex constraint step:" << track.step() + edm::LogInfo("KMTFCore") << " Coordinates after vertex constraint step:" << track.step() << " phi=" << track.phiAtVertex() << " dxy=" << track.dxy() << " K=" << track.curvatureAtVertex() << " maximum local chi2=" << track.approxPromptChi2(); - edm::LogWarning("KMTFCore") << "------------------------------------------------------"; - edm::LogWarning("KMTFCore") << "------------------------------------------------------"; + edm::LogInfo("KMTFCore") << "------------------------------------------------------"; + edm::LogInfo("KMTFCore") << "------------------------------------------------------"; } setFourVectors(track); //finally set the displaced or prompt ID + const int oldId = track.id(); track.setIDFlag(passedV, passedU); + if (verbose_) { + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] setIDFlag transition" + << " seed(st=" << seed->depthRegion() << ",sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() + << ",bx=" << seed->bxNum() << ",id=" << seed->id() << ")" + << " mask=" << mask << " hitPattern=" << track.hitPattern() << " thetaPattern=" << track.thetaDigiPattern() + << " passPrompt=" << passedV << " passDisp=" << passedU << " promptChi2=" << track.approxPromptChi2() + << " dispChi2=" << track.approxDispChi2() << " rankPrompt=" << track.rankPrompt() + << " rankDisp=" << track.rankDisp() << " oldID=" << oldId << " newID=" << track.id() + << " phiMuon=" << track.phiAtMuon() << " phiVertex=" << track.phiAtVertex() + << " nStubs=" << track.stubs().size(); + if (seed->depthRegion() == 2) { + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG_STA2] final-id-decision" + << " seed(st=2,sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() << ",bx=" << seed->bxNum() + << ",id=" << seed->id() << ")" + << " mask=" << mask << " passPrompt=" << passedV << " passDisp=" << passedU << " oldID=" << oldId + << " newID=" << track.id() << " rankPrompt=" << track.rankPrompt() << " rankDisp=" << track.rankDisp() + << " promptChi2=" << track.approxPromptChi2() << " dispChi2=" << track.approxDispChi2() + << " phiMuon=" << track.phiAtMuon() << " phiVertex=" << track.phiAtVertex() + << " z=" << track.zPosition() << " kSlope=" << track.kSlope() + << " nStubs=" << track.stubs().size(); + } + } if (verbose_) - edm::LogWarning("KMTFCore") << "Floating point coordinates at vertex: pt=" << track.pt() + edm::LogInfo("KMTFCore") << "Floating point coordinates at vertex: pt=" << track.pt() << ", eta=" << track.eta() << " phi=" << track.phi(); pretracks.push_back(track); } @@ -266,9 +308,9 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef } if (verbose_) { if (!pretracks.empty()) - edm::LogWarning("KMTFCore") << "-----Kalman Algo at station " << seed->depthRegion() << " (uncleaned)-----"; + edm::LogInfo("KMTFCore") << "-----Kalman Algo at station " << seed->depthRegion() << " (uncleaned)-----"; for (const auto& track : pretracks) - edm::LogWarning("KMTFCore") << "Kalman Track charge=" << track.charge() << " pt=" << track.pt() + edm::LogInfo("KMTFCore") << "Kalman Track charge=" << track.charge() << " pt=" << track.pt() << " hit pattern = " << track.hitPattern() << " eta=" << track.eta() << " phi=" << track.phi() << " curvature=" << track.curvatureAtVertex() << " curvature STA =" << track.curvatureAtMuon() @@ -279,13 +321,13 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef //Now for all the pretracks we need only one vertex constrained and one vertex unconstrained //so we clean twice if (verbose_) - edm::LogWarning("KMTFCore") << "Chain Reconstructed " << pretracks.size() + edm::LogInfo("KMTFCore") << "Chain Reconstructed " << pretracks.size() << " pretracks, now cleaning them separately"; std::vector cleanedPrompt = clean(pretracks, seed->depthRegion(), true); std::vector cleanedDisp = clean(pretracks, seed->depthRegion(), false); if (verbose_) - edm::LogWarning("KMTFCore") << "Cleaned Chain tracks prompt=" << cleanedPrompt.size() + edm::LogInfo("KMTFCore") << "Cleaned Chain tracks prompt=" << cleanedPrompt.size() << " displaced=" << cleanedDisp.size(); if (cleanedPrompt.empty() && cleanedDisp.empty()) @@ -309,17 +351,31 @@ std::vector KMTFCore::clean(const std::vector& t for (const auto& track : tracks) { if (vertex) { - if ((track.id() & 0x1) == 0) + if ((track.id() & 0x1) == 0) { + if (verbose_) { + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] clean(prompt) dropping pretrack due to prompt ID bit=0" + << " seedStep=" << seed << " id=" << track.id() << " hitPattern=" << track.hitPattern() + << " rankPrompt=" << track.rankPrompt() << " rankDisp=" << track.rankDisp() + << " nStubs=" << track.stubs().size(); + } continue; + } if (verbose_) - edm::LogWarning("KMTFCore") << "Chain Cleaning : Pre Track = pattern = " << track.rankPrompt() + edm::LogInfo("KMTFCore") << "Chain Cleaning : Pre Track = pattern = " << track.rankPrompt() << " rank=" << track.hitPattern(); infoRank[track.hitPattern()] = track.rankPrompt(); infoTrack[track.hitPattern()] = track; } else { - if ((track.id() & 0x2) == 0) + if ((track.id() & 0x2) == 0) { + if (verbose_) { + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] clean(displaced) dropping pretrack due to displaced ID bit=0" + << " seedStep=" << seed << " id=" << track.id() << " hitPattern=" << track.hitPattern() + << " rankPrompt=" << track.rankPrompt() << " rankDisp=" << track.rankDisp() + << " nStubs=" << track.stubs().size(); + } continue; + } infoRank[track.hitPattern()] = track.rankDisp(); infoTrack[track.hitPattern()] = track; } @@ -359,9 +415,21 @@ std::vector KMTFCore::clean(const std::vector& t selected = 1; auto search = infoTrack.find(selected); - if (search != infoTrack.end()) + if (search != infoTrack.end()) { + if (verbose_) { + const auto& kept = search->second; + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] clean(" << (vertex ? "prompt" : "displaced") + << ") keeping selected pretrack" + << " seedStep=" << seed << " selectedPattern=" << selected << " id=" << kept.id() + << " rankPrompt=" << kept.rankPrompt() << " rankDisp=" << kept.rankDisp() + << " hitPattern=" << kept.hitPattern() << " thetaPattern=" << kept.thetaDigiPattern() + << " phiMuon=" << kept.phiAtMuon() << " phiVertex=" << kept.phiAtVertex() + << " curvMuon=" << kept.curvatureAtMuon() << " curvVertex=" << kept.curvatureAtVertex() + << " z=" << kept.zPosition() << " kSlope=" << kept.kSlope() + << " nStubs=" << kept.stubs().size(); + } out.push_back(search->second); - + } return out; } @@ -390,12 +458,12 @@ std::pair KMTFCore::match(const l1t::MuonStubRef& seed, const l1t::M const l1t::MuonStubRef& stub = stubs[N]; //Should not be stubs with tag=4 but there are, so skip those if (verbose_) - edm::LogWarning("KMTFCore") << "testing stub on depth=" << stub->depthRegion() << " for step=" << step; + edm::LogInfo("KMTFCore") << "testing stub on depth=" << stub->depthRegion() << " for step=" << step; if (stub->depthRegion() != step) continue; if (verbose_) - edm::LogWarning("KMTFCore") << "Passed"; + edm::LogInfo("KMTFCore") << "Passed"; uint distance = fabs(wrapAround((seed->coord1() - stub->coord1()) >> 3, 32768)); //if the wheels are not adjacent make this huge @@ -480,7 +548,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { ap_fixed KnewInt = ap_fixed(K) - eK * Kint; KNew = KnewInt; if (verbose_) - edm::LogWarning("KMTFCore") << "propagate to vertex Kint=" << Kint.to_int() << " ek=" << eK.to_float() + edm::LogInfo("KMTFCore") << "propagate to vertex Kint=" << Kint.to_int() << " ek=" << eK.to_float() << " Knew=" << KNew; } @@ -490,7 +558,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { ap_fixed(-bPhi_[step - 1]) * ap_fixed(phiB); if (verbose_) { - edm::LogWarning("KMTFCore") << "phi prop = " << K << " * " << ap_fixed(aPhi_[step - 1]).to_float() + edm::LogInfo("KMTFCore") << "phi prop = " << K << " * " << ap_fixed(aPhi_[step - 1]).to_float() << " = " << phi11.to_int() << ", " << phiB << " * " << ap_fixed(-bPhi_[step - 1]).to_float() << " = " << phi12.to_int(); } @@ -502,7 +570,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { ap_ufixed(bPhiB_[step - 1]) * ap_fixed(phiB); int phiBNew = ap_fixed(phiB11 + phiB12); if (verbose_) { - edm::LogWarning("KMTFCore") << "phiB prop = " << K << " * " << ap_fixed(aPhiB_[step - 1]).to_float() + edm::LogInfo("KMTFCore") << "phiB prop = " << K << " * " << ap_fixed(aPhiB_[step - 1]).to_float() << " = " << phiB11.to_int() << ", " << phiB << " * " << ap_ufixed(bPhiB_[step - 1]).to_float() << " = " << phiB12.to_int(); } @@ -514,15 +582,15 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { int kSlopeNew = kSlope; int zNew; zNew = ap_fixed(ap_fixed(z) - ap_ufixed(zdeltaR_dig) * ap_fixed(kSlope)); - if (zNew > (1 << (BITSZ - 1)) - 1) { if (verbose_){ - edm::LogWarning("KMTFCore") << "z saturated high during propagation, step=" << step; + edm::LogInfo("KMTFCore") << "z saturated high during propagation, step=" << step; } zNew = (1 << (BITSZ - 1)) - 1; } else if (zNew < -(1 << (BITSZ - 1))) { - if (verbose_) - edm::LogWarning("KMTFCore") << "z saturated low during propagation, step=" << step; + if (verbose_){ + edm::LogInfo("KMTFCore") << "z saturated low during propagation, step=" << step; + } zNew = -(1 << (BITSZ - 1)); } @@ -543,7 +611,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { phiBNew = ap_fixed(diff); if (verbose_) { - edm::LogWarning("KMTFCore") << "Vertex phiB prop = " << DXY.to_int() << "(=" << aK.to_int() << " +" + edm::LogInfo("KMTFCore") << "Vertex phiB prop = " << DXY.to_int() << "(=" << aK.to_int() << " +" << (eK * Kint).to_int() << ") - " << ap_fixed(phiB).to_int() << " = " << phiBNew; } @@ -616,10 +684,10 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { cov = cov + MS; if (verbose_) { - edm::LogWarning("KMTFCore") << "Covariance term for phiB = " << cov(2, 2); - edm::LogWarning("KMTFCore") << "Multiple scattering term for phiB = " << MS(2, 2); - edm::LogWarning("KMTFCore") << "Multiple scattering term for z = " << MS(3, 3); - edm::LogWarning("KMTFCore") << "Multiple scattering term for kSlope = " << MS(4, 4); + edm::LogInfo("KMTFCore") << "Covariance term for phiB = " << cov(2, 2); + edm::LogInfo("KMTFCore") << "Multiple scattering term for phiB = " << MS(2, 2); + edm::LogInfo("KMTFCore") << "Multiple scattering term for z = " << MS(3, 3); + edm::LogInfo("KMTFCore") << "Multiple scattering term for kSlope = " << MS(4, 4); } track.setCovariance(cov); track.setCoordinates(step - 1, KNew, phiNew, phiBNew, zNew, kSlopeNew); @@ -647,7 +715,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int phi = stub->coord1(); int phiB = correctedPhiB(stub); int z = stub->eta1(); - int kSlope = stub->eta2(); + int kSlope = satKSlope(stub->eta2()); int priorThetaPattern = track.thetaDigiPattern(); int priorPhiPattern = track.hitPattern(); int seedStation = track.stubs().empty() ? 0 : track.stubs()[0]->depthRegion(); @@ -707,37 +775,37 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int zNew = trackz + int(Gain(3, 2) * residual(2) + Gain(3, 3) * residual(3)); int kSlopeNew = trackSlope + int(Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); - if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { + if ((zNew > ((1 << (BITSZ - 1)) - 1)) || (zNew < (-(1 << (BITSZ - 1))))) { if (verbose_) - edm::LogWarning("KMTFCore") << "z saturated in updateOffline"; + edm::LogInfo("KMTFCore") << "z saturated in updateOffline"; return false; } - if ((kSlopeNew > (pow(2, BITSKSLOPE - 1) - 1)) || (kSlopeNew < -(pow(2, BITSKSLOPE - 1)))) { + if ((kSlopeNew > ((1 << (BITSKSLOPE - 1)) - 1)) || (kSlopeNew < (-(1 << (BITSKSLOPE - 1))))) { if (verbose_) - edm::LogWarning("KMTFCore") << "kSlope saturated in updateOffline"; + edm::LogInfo("KMTFCore") << "kSlope saturated in updateOffline"; return false; } track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); if (verbose_) { - std::cout << "residual(0): " << phi << "-" << trackPhi << " = " << residual(0) << "\n"; - std::cout << "residual(1): " << phiB << "-" << trackPhiB << " = " << residual(1) << "\n"; - std::cout << "residual(2): " << z << "-" << trackz << " = " << residual(2) << "\n"; - std::cout << "residual(3): " << kSlope << "-" << trackSlope << " = " << residual(3) << "\n"; - std::cout << "Gain(0,0): " << Gain(0, 0) << "\n"; - std::cout << "Gain(0,1): " << Gain(0, 1) << "\n"; - std::cout << "Gain(2,0): " << Gain(2, 0) << "\n"; - std::cout << "Gain(2,1): " << Gain(2, 1) << "\n"; - std::cout << "Gain(3,2): " << Gain(3, 2) << "\n"; - std::cout << "Gain(3,3): " << Gain(3, 3) << "\n"; - std::cout << "Gain(4,2): " << Gain(4, 2) << "\n"; - std::cout << "Gain(4,3): " << Gain(4, 3) << "\n"; - std::cout << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0) << "+" << Gain(0, 1) << "*" << residual(1) << " = " << KNew << "\n"; - std::cout << " phiNew = " << trackPhi << "+" << residual(0) << " = " << phiNew << "\n"; - std::cout << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0) << "+" << Gain(2, 1) << "*" << residual(1) << " = " << phiBNew << "\n"; - std::cout << " zNew = " << trackz << "+" << Gain(3, 2) << "*" << residual(2) << "+" << Gain(3, 3) << "*" << residual(3) << " = " << zNew << "\n"; - std::cout << " kSlopeNew = " << trackSlope << "+" << Gain(4, 2) << "*" << residual(2) << "+" << Gain(4, 3) << "*" << residual(3) << " = " << kSlopeNew << "\n"; + edm::LogInfo("KMTFCore") << "residual(0): " << phi << "-" << trackPhi << " = " << residual(0) << "\n"; + edm::LogInfo("KMTFCore") << "residual(1): " << phiB << "-" << trackPhiB << " = " << residual(1) << "\n"; + edm::LogInfo("KMTFCore") << "residual(2): " << z << "-" << trackz << " = " << residual(2) << "\n"; + edm::LogInfo("KMTFCore") << "residual(3): " << kSlope << "-" << trackSlope << " = " << residual(3) << "\n"; + edm::LogInfo("KMTFCore") << "Gain(0,0): " << Gain(0, 0) << "\n"; + edm::LogInfo("KMTFCore") << "Gain(0,1): " << Gain(0, 1) << "\n"; + edm::LogInfo("KMTFCore") << "Gain(2,0): " << Gain(2, 0) << "\n"; + edm::LogInfo("KMTFCore") << "Gain(2,1): " << Gain(2, 1) << "\n"; + edm::LogInfo("KMTFCore") << "Gain(3,2): " << Gain(3, 2) << "\n"; + edm::LogInfo("KMTFCore") << "Gain(3,3): " << Gain(3, 3) << "\n"; + edm::LogInfo("KMTFCore") << "Gain(4,2): " << Gain(4, 2) << "\n"; + edm::LogInfo("KMTFCore") << "Gain(4,3): " << Gain(4, 3) << "\n"; + edm::LogInfo("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0) << "+" << Gain(0, 1) << "*" << residual(1) << " = " << KNew << "\n"; + edm::LogInfo("KMTFCore") << " phiNew = " << trackPhi << "+" << residual(0) << " = " << phiNew << "\n"; + edm::LogInfo("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0) << "+" << Gain(2, 1) << "*" << residual(1) << " = " << phiBNew << "\n"; + edm::LogInfo("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 2) << "*" << residual(2) << "+" << Gain(3, 3) << "*" << residual(3) << " = " << zNew << "\n"; + edm::LogInfo("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 2) << "*" << residual(2) << "+" << Gain(4, 3) << "*" << residual(3) << " = " << kSlopeNew << "\n"; } track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); @@ -755,15 +823,15 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub track.setThetaGain(track.step(), fabs(trackK), priorThetaPattern, seedStation, priorPhiPattern, Gain(3, 2), Gain(3, 3), Gain(4, 2), Gain(4, 3)); if (verbose_){ - std::cout << "step: " << track.step() << "\n"; - std::cout << "|K|: " << fabs(trackK) << "\n"; - std::cout << "priorThetaPattern: " << priorThetaPattern << "\n"; - std::cout << "priorPhiPattern: " << priorPhiPattern << "\n"; - std::cout << "seed Station: " << seedStation << "\n"; - std::cout << "Gain32: " << Gain(3, 2) << "\n"; - std::cout << "Gain33: " << Gain(3, 3) << "\n"; - std::cout << "Gain42: " << Gain(4, 2) << "\n"; - std::cout << "Gain43: " << Gain(4, 3) << "\n"; + edm::LogInfo("KMTFCore") << "step: " << track.step() << "\n"; + edm::LogInfo("KMTFCore") << "|K|: " << fabs(trackK) << "\n"; + edm::LogInfo("KMTFCore") << "priorThetaPattern: " << priorThetaPattern << "\n"; + edm::LogInfo("KMTFCore") << "priorPhiPattern: " << priorPhiPattern << "\n"; + edm::LogInfo("KMTFCore") << "seed Station: " << seedStation << "\n"; + edm::LogInfo("KMTFCore") << "Gain32: " << Gain(3, 2) << "\n"; + edm::LogInfo("KMTFCore") << "Gain33: " << Gain(3, 3) << "\n"; + edm::LogInfo("KMTFCore") << "Gain42: " << Gain(4, 2) << "\n"; + edm::LogInfo("KMTFCore") << "Gain43: " << Gain(4, 3) << "\n"; } return true; @@ -777,7 +845,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int trackSlope = track.kSlope(); int phi = stub->coord1(); int z = stub->eta1(); - int kSlope = stub->eta2(); + int kSlope = satKSlope(stub->eta2()); int priorThetaPattern = track.thetaDigiPattern(); int priorPhiPattern = track.hitPattern(); int seedStation = track.stubs().empty() ? 0 : track.stubs()[0]->depthRegion(); @@ -788,9 +856,9 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st residual[2] = ap_fixed(kSlope - trackSlope); if (verbose_) { - edm::LogWarning("KMTFCore") << "residual phi: " << phi << " - " << trackPhi << " = " << int(residual(0)); - edm::LogWarning("KMTFCore") << "residual z: " << z << " - " << trackz << " = " << int(residual(1)); - edm::LogWarning("KMTFCore") << "residual kSlope: " << kSlope << " - " << trackSlope << " = " << int(residual(2)); + edm::LogInfo("KMTFCore") << "residual phi: " << phi << " - " << trackPhi << " = " << int(residual(0)); + edm::LogInfo("KMTFCore") << "residual z: " << z << " - " << trackz << " = " << int(residual(1)); + edm::LogInfo("KMTFCore") << "residual kSlope: " << kSlope << " - " << trackSlope << " = " << int(residual(2)); } Matrix35 H; @@ -833,12 +901,12 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { if (verbose_) - edm::LogWarning("KMTFCore") << "z saturated in updateOffline1D"; + edm::LogInfo("KMTFCore") << "z saturated in updateOffline1D"; return false; } if ((kSlopeNew > (pow(2, BITSKSLOPE - 1) - 1)) || (kSlopeNew < -(pow(2, BITSKSLOPE - 1)))) { if (verbose_) - edm::LogWarning("KMTFCore") << "kSlope saturated in updateOffline1D"; + edm::LogInfo("KMTFCore") << "kSlope saturated in updateOffline1D"; return false; } @@ -848,11 +916,11 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st l1t::CovarianceMatrix5dim c; if (verbose_) { - edm::LogWarning("KMTFCore") << " phiNew: " << trackPhi << "+" << residual(0); - edm::LogWarning("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0); - edm::LogWarning("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0); - edm::LogWarning("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 1) << "*" << residual(1) << "+" << Gain(3, 2) << "*" << residual(2); - edm::LogWarning("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 1) << "*" << residual(1) << "+" << Gain(4, 2) << "*" << residual(2); + edm::LogInfo("KMTFCore") << " phiNew: " << trackPhi << "+" << residual(0); + edm::LogInfo("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0); + edm::LogInfo("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0); + edm::LogInfo("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 1) << "*" << residual(1) << "+" << Gain(3, 2) << "*" << residual(2); + edm::LogInfo("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 1) << "*" << residual(1) << "+" << Gain(4, 2) << "*" << residual(2); } for (int i = 0; i < 5; i++) @@ -878,7 +946,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in int phi = stub->coord1(); int phiB = correctedPhiB(stub); int z = stub->eta1(); - int kSlope = stub->eta2(); + int kSlope = satKSlope(stub->eta2()); Vector4 residual; ap_fixed residualPhi = phi - trackPhi; @@ -887,7 +955,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in ap_fixed residualSlope = kSlope - trackSlope; if (verbose_) - edm::LogWarning("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << residualPhi.to_int() << " " << phiB + edm::LogInfo("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << residualPhi.to_int() << " " << phiB << " - " << trackPhiB << " = " << residualPhiB.to_int(); @@ -898,7 +966,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in std::vector GAIN; std::vector GAIN_THETA; if (verbose_) { - edm::LogWarning("KMTFCore") << "Looking up LUTs for mask=" << mask << " with hit pattern=" << track.hitPattern(); + edm::LogInfo("KMTFCore") << "Looking up LUTs for mask=" << mask << " with hit pattern=" << track.hitPattern(); } //For the three stub stuff use only gains 0 and 4 if (!(mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) { @@ -918,14 +986,14 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in } if (verbose_) { - edm::LogWarning("KMTFCore") << "Gains (fp): " << GAIN[0] << " " << GAIN[1] << " " << GAIN[2] << " " << GAIN[3]; + edm::LogInfo("KMTFCore") << "Gains (fp): " << GAIN[0] << " " << GAIN[1] << " " << GAIN[2] << " " << GAIN[3]; if (!(mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) - edm::LogWarning("KMTFCore") << "Addr=" << absK / 16 + edm::LogInfo("KMTFCore") << "Addr=" << absK / 16 << " gain0=" << ap_ufixed(GAIN[0]).to_float() << " gain4=-" << ap_ufixed(GAIN[2]).to_float(); else - edm::LogWarning("KMTFCore") << "Addr=" << absK / 32 << " " << ap_ufixed(GAIN[0]).to_float() + edm::LogInfo("KMTFCore") << "Addr=" << absK / 32 << " " << ap_ufixed(GAIN[0]).to_float() << " -" << ap_ufixed(GAIN[1]).to_float() << " " << ap_ufixed(GAIN[2]).to_float() << " " << ap_ufixed(GAIN[3]).to_float(); @@ -938,7 +1006,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in KNew = ap_fixed(ap_fixed(trackK) + ap_ufixed(GAIN[0]) * residualPhi); if (verbose_) { - edm::LogWarning("KMTFCore") << "K = " << KNew << " = " << ap_fixed(trackK).to_int() << " + " + edm::LogInfo("KMTFCore") << "K = " << KNew << " = " << ap_fixed(trackK).to_int() << " + " << ap_ufixed(GAIN[0]).to_float() << "*" << residualPhi.to_int(); } } else { @@ -947,13 +1015,13 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in KNew = ap_fixed(ap_fixed(trackK) + k11 - k12); if (verbose_) { - edm::LogWarning("KMTFCore") << "K = " << KNew << " = " << ap_fixed(trackK).to_int() << " + " + edm::LogInfo("KMTFCore") << "K = " << KNew << " = " << ap_fixed(trackK).to_int() << " + " << k11.to_int() << " + " << k12.to_int(); } } if ((KNew > (pow(2, BITSCURV - 1) - 1)) || (KNew < -(pow(2, BITSCURV - 1)))) { if (verbose_) - edm::LogWarning("KMTFCore") << "K has saturated, track has extremely low energy"; + edm::LogInfo("KMTFCore") << "K has saturated, track has extremely low energy"; return false; } KNew = wrapAround(KNew, pow(2, BITSCURV - 1)); @@ -965,7 +1033,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in ap_fixed pb_0 = ap_ufixed(GAIN[2]) * residualPhi; if (verbose_) { - edm::LogWarning("KMTFCore") << "phiupdate " << pb_0.to_float() << " " << pb_1.to_float() << " " + edm::LogInfo("KMTFCore") << "phiupdate " << pb_0.to_float() << " " << pb_1.to_float() << " " << pbdouble_0.to_float(); } @@ -987,12 +1055,12 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { if (verbose_) - edm::LogWarning("KMTFCore") << "z has saturated"; + edm::LogInfo("KMTFCore") << "z has saturated"; return false; } if ((kSlopeNew > (pow(2, BITSKSLOPE - 1) - 1)) || (kSlopeNew < -(pow(2, BITSKSLOPE - 1)))) { if (verbose_) - edm::LogWarning("KMTFCore") << "kSlope has saturated"; + edm::LogInfo("KMTFCore") << "kSlope has saturated"; return false; } @@ -1002,9 +1070,9 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in track.setThetaDigiPattern(thetaDigiPattern(track)); if (verbose_) { - edm::LogWarning("KMTFCore") << "Stub station =" << stub->depthRegion(); + edm::LogInfo("KMTFCore") << "Stub station =" << stub->depthRegion(); - edm::LogWarning("KMTFCore") << "Updated Hit Pattern =" << track.hitPattern(); + edm::LogInfo("KMTFCore") << "Updated Hit Pattern =" << track.hitPattern(); } return true; @@ -1036,16 +1104,16 @@ void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track) { track.setKalmanGain(track.step(), fabs(track.curvature()), Gain(0, 0), Gain(1, 0), Gain(2, 0)); if (verbose_) { - edm::LogWarning("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); - edm::LogWarning("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; + edm::LogInfo("KMTFCore") << "sigma3=" << cov(0, 3) << " sigma6=" << cov(3, 3); + edm::LogInfo("KMTFCore") << " K = " << track.curvature() << " + " << Gain(0, 0) << " * " << residual; } int KNew = wrapAround(int(track.curvature() + Gain(0, 0) * residual), pow(2, BITSCURV - 1)); int phiNew = wrapAround(int(track.positionAngle() + Gain(1, 0) * residual), pow(2, BITSPHI)); int dxyNew = wrapAround(int(track.dxy() + Gain(2, 0) * residual), pow(2, BITSPHIB)); if (verbose_) - edm::LogWarning("KMTFCore") << "Post fit impact parameter=" << dxyNew; - track.setCoordinatesAtVertex(KNew, phiNew, -residual); + edm::LogInfo("KMTFCore") << "Post fit impact parameter=" << dxyNew; + track.setCoordinatesAtVertex(KNew, phiNew, -residual, track.zPosition(), track.kSlope()); Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; c(0, 0) = covNew(0, 0); @@ -1090,7 +1158,7 @@ void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track) { int KNew = ap_fixed(k_0 + ap_fixed(track.curvature())); if (verbose_) { - edm::LogWarning("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" + edm::LogInfo("KMTFCore") << "VERTEX GAIN(" << absK / 4 << ")= -" << ap_ufixed(fabs(GAIN.first)).to_float() << " * " << ap_fixed(residual).to_int() << " = " << k_0.to_int(); } @@ -1098,7 +1166,7 @@ void KMTFCore::vertexConstraintLUT(l1t::KMTFTrack& track) { //int p_0 = fp_product(GAIN.second, int(residual), 7); int p_0 = GAIN.second * int(residual); int phiNew = wrapAround(track.positionAngle() + p_0, pow(2, BITSPHI - 1)); - track.setCoordinatesAtVertex(KNew, phiNew, -residual); + track.setCoordinatesAtVertex(KNew, phiNew, -residual, track.zPosition(), track.kSlope()); } int KMTFCore::hitPattern(const l1t::KMTFTrack& track) { @@ -1129,10 +1197,10 @@ bool KMTFCore::getBit(int bitmask, int pos) { return (bitmask & (1 << pos)) >> p void KMTFCore::setFourVectors(l1t::KMTFTrack& track) { //int etaINT = track.coarseEta(); - //new track eta with linear fit calibrated to gen eta. abandoning the legacy approach of setting track eta from coarseEta - const double m = 0.03602; - const double b = 0.66840; - int etaINT = int(round(m * track.kSlope() + b)); + ap_ufixed<18, 0> m = 0.03602; + ap_ufixed<18, 0> b = 0.66840; + int etaINT = int(round(double(m * track.kSlope() + b))); + int etaINTDisp = int(round(double(m * track.kSlopeAtMuon() + b))); double lsbEta = M_PI / pow(2, 12); int charge = 1; @@ -1146,21 +1214,22 @@ void KMTFCore::setFourVectors(l1t::KMTFTrack& track) { //Also set PT =0 and dxy=0 if (track.stubs().size() == 1) { ptC = 0; - track.setCoordinatesAtMuon(track.curvatureAtMuon(), track.stubs()[0]->coord1(), track.phiBAtMuon()); - track.setCoordinatesAtVertex(track.curvatureAtVertex(), track.phiAtVertex(), 0); + track.setCoordinatesAtMuon(track.curvatureAtMuon(), track.stubs()[0]->coord1(), track.phiBAtMuon(), track.zPosition(), track.kSlope()); + track.setCoordinatesAtVertex(track.curvatureAtVertex(), track.phiAtVertex(), 0, track.zPosition(), track.kSlope()); } track.setPt(ptC, ptU); //shift the dxy by 10 bits - track.setCoordinatesAtVertex(track.curvatureAtVertex(), track.phiAtVertex(), track.dxy() / 1024); + track.setCoordinatesAtVertex(track.curvatureAtVertex(), track.phiAtVertex(), track.dxy() / 1024, track.zPosition(), track.kSlope()); //vertex double pt = ptC * 0.03125; double phi = (track.phiAtMuon() / 32) * M_PI / pow(2, 12); double eta = etaINT * lsbEta; + double etaDisp = etaINTDisp * lsbEta; track.setPtEtaPhi(pt, eta, phi); track.setCharge(charge); pt = double(ptLUT(track.curvatureAtMuon())) * 0.03125; - track.setPtEtaPhiDisplaced(pt, eta, phi); + track.setPtEtaPhiDisplaced(pt, etaDisp, phi); } bool KMTFCore::estimateChiSquare(l1t::KMTFTrack& track, bool vertex) { @@ -1185,6 +1254,15 @@ bool KMTFCore::estimateChiSquare(l1t::KMTFTrack& track, bool vertex) { std::vector cut; const l1t::MuonStubRef& innerStub = track.stubs()[track.stubs().size() - 1]; + if (verbose_) { + edm::LogInfo("KMTFCore") << "[KMTF_CHI2DBG] begin " << (vertex ? "prompt" : "displaced") + << " chi2 fit: hitPattern=" << track.hitPattern() + << " thetaPattern=" << track.thetaDigiPattern() + << " nStubs=" << track.stubs().size() << " innerDepth=" << innerStub->depthRegion() + << " curvMuon=" << track.curvatureAtMuon() << " curvVtx=" << track.curvatureAtVertex() + << " phiMuon=" << track.phiAtMuon() << " phiVtx=" << track.phiAtVertex() + << " z=" << track.zPosition() << " kSlope=" << track.kSlope(); + } if (vertex) { K = track.curvatureAtVertex(); @@ -1239,7 +1317,7 @@ bool KMTFCore::estimateChiSquare(l1t::KMTFTrack& track, bool vertex) { diffPhiB = 0; if (verbose_) - edm::LogWarning("KMTFCore") << "Error propagation coefficients A=" + edm::LogInfo("KMTFCore") << "Error propagation coefficients A=" << propErrA[stub->depthRegion() - innerStub->depthRegion() - 1] << " B=" << propErrB[stub->depthRegion() - innerStub->depthRegion() - 1] << " BK = " << uint(ap_fixed<8, 2>(propErrB[stub->depthRegion() - innerStub->depthRegion() - 1]) * @@ -1257,14 +1335,19 @@ bool KMTFCore::estimateChiSquare(l1t::KMTFTrack& track, bool vertex) { chi = chi + absDelta; chiErr = chiErr + err; if (verbose_) { - edm::LogWarning("KMTFCore") << "Chi Square stub for track with pattern=" << track.hitPattern() - << " inner stub depth=" << innerStub->depthRegion() << "-> AK=" << int(AK) - << " stubDepth=" << stub->depthRegion() << " diff1=" << diffPhi << " diff2=" << diffPhiB - << " delta=" << absDelta << " absK=" << uint(absK) << " err=" << err; + edm::LogInfo("KMTFCore") << "[KMTF_CHI2DBG] per-stub " << (vertex ? "prompt" : "displaced") + << " innerDepth=" << innerStub->depthRegion() << " stubDepth=" << stub->depthRegion() + << " diffPhi=" << diffPhi << " diffPhiB=" << diffPhiB + << " propC=" << float(propC) << " Kshifted=" << int(Kshifted) << " AK=" << int(AK) + << " deltaSigned=" << delta << " deltaAbs=" << absDelta + << " posErrA=" << positionError + << " errBTerm=" << uint(ap_fixed<8, 2>(propErrB[stub->depthRegion() - innerStub->depthRegion() - 1]) * absK) + << " errTotal=" << err << " chiRunning=" << chi << " chiErrRunning=" << chiErr; } } if (verbose_) { - edm::LogWarning("KMTFCore") << "Chi Square =" << chi << " ChiSquare Error = " << chiErr; + edm::LogInfo("KMTFCore") << "[KMTF_CHI2DBG] final " << (vertex ? "prompt" : "displaced") + << " chi=" << chi << " chiErr=" << chiErr << " pass=" << (chi <= chiErr); } track.setApproxChi2(chi, chiErr, vertex); @@ -1299,7 +1382,7 @@ void KMTFCore::setRank(l1t::KMTFTrack& track, bool vertex) { rank = 0; if (verbose_) - edm::LogWarning("KMTFCore") << "Rank Calculated for vertex=" << vertex << " = " << rank; + edm::LogInfo("KMTFCore") << "Rank Calculated for vertex=" << vertex << " = " << rank; track.setRank(rank, vertex); } @@ -1311,6 +1394,12 @@ int KMTFCore::wrapAround(int value, int maximum) { return value; } +int KMTFCore::satKSlope(int k) { + const int kmax = (1 << (BITSKSLOPE - 1)) - 1; + const int kmin = -(1 << (BITSKSLOPE - 1)); + return k > kmax ? kmax : (k < kmin ? kmin : k); +} + int KMTFCore::encode(bool ownwheel, int sector, int tag) { int wheel = ownwheel ? 1 : 0; int phi = 0; @@ -1324,7 +1413,7 @@ int KMTFCore::encode(bool ownwheel, int sector, int tag) { std::pair KMTFCore::getByCode(const std::vector& tracks, int mask) { for (uint i = 0; i < tracks.size(); ++i) { - //edm::LogWarning("KMTFCore") << "Code=" << tracks[i].hitPattern() << ", track=" << mask; + //edm::LogInfo("KMTFCore") << "Code=" << tracks[i].hitPattern() << ", track=" << mask; if (tracks[i].hitPattern() == mask) return std::make_pair(true, i); } @@ -1362,11 +1451,11 @@ void KMTFCore::calculateEta(l1t::KMTFTrack& track) { mask = mask | ((uint(fabs(track.stubs()[i]->etaRegion()) + 1) << (2 * (track.stubs()[i]->depthRegion() - 1)))); } if (verbose_) - edm::LogWarning("KMTFCore") << "Mask = " << mask; + edm::LogInfo("KMTFCore") << "Mask = " << mask; track.setCoarseEta(sign * lutService_->coarseEta(mask)); if (verbose_) - edm::LogWarning("KMTFCore") << "Coarse Eta mask=" << mask << " set = " << sign * lutService_->coarseEta(mask); + edm::LogInfo("KMTFCore") << "Coarse Eta mask=" << mask << " set = " << sign * lutService_->coarseEta(mask); track.setFineEta(0); } From 6b86d68ab772564ba9795f324f2d46720613ce76 Mon Sep 17 00:00:00 2001 From: delano campos Date: Fri, 12 Jun 2026 18:02:41 -0500 Subject: [PATCH 27/29] some PR comment updates + minor emu/fw agreement changes --- DataFormats/L1TMuonPhase2/src/classes_def.xml | 3 +-- L1Trigger/Phase2L1GMT/src/KMTF.cc | 22 +++++++------------ L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 14 ++++++------ .../src/L1TPhase2GMTBarrelStubProcessor.cc | 15 ++++++++++--- 4 files changed, 28 insertions(+), 26 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/src/classes_def.xml b/DataFormats/L1TMuonPhase2/src/classes_def.xml index d472ab4c4e6b7..b11b593334ce8 100644 --- a/DataFormats/L1TMuonPhase2/src/classes_def.xml +++ b/DataFormats/L1TMuonPhase2/src/classes_def.xml @@ -25,8 +25,7 @@ - - + diff --git a/L1Trigger/Phase2L1GMT/src/KMTF.cc b/L1Trigger/Phase2L1GMT/src/KMTF.cc index 72dec42cb9b2e..1a7f8afc2d0ed 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTF.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTF.cc @@ -72,7 +72,6 @@ std::pair, std::vector > KMTF::proce } bool pre_patterns = (verbose_ > 1) && ((Nstubs4 + Nstubs3 + Nstubs2 + Nstubs1) > 2); - //OK now process the data almost as in hardware for (unsigned int i = 0; i < 32; ++i) { //print the stubs taking into account @@ -171,8 +170,7 @@ std::pair, std::vector > KMTF::proce << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.first.rankPrompt() << " " - << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " - << " " << std::flush; + << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; if (tracks.second.id() & 0x2) @@ -180,8 +178,7 @@ std::pair, std::vector > KMTF::proce << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.second.rankDisp() << " " - << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " - << " " << std::flush; + << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } @@ -207,8 +204,7 @@ std::pair, std::vector > KMTF::proce << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.first.rankPrompt() << " " - << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " - << " " << std::flush; + << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; @@ -217,8 +213,7 @@ std::pair, std::vector > KMTF::proce << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.second.rankDisp() << " " - << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " - << " " << std::flush; + << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " << std::flush; else @@ -243,23 +238,22 @@ std::pair, std::vector > KMTF::proce << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.first.rankPrompt() << " " - << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " - << " " << std::flush; + << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; else - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0" << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; if (tracks.second.id() & 0x2) edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.second.rankDisp() << " " - << tracks.second.zPosition() << " " << tracks.second.kSlope() << " "; + << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } } else if (patterns) { edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 "; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0"; } //Now the shift register emulation in C_++ if (stubs4.size() > 1) { diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 2135e248609ed..9af338fdae874 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -83,10 +83,10 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef default: throw cms::Exception("KMTFCore") << "Something really bad happend\n"; } - l1t::KMTFTrack nullTrack(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), satKSlope(seed->eta2())); seedQual = seed->quality(); for (const auto& mask : combinatorics) { + l1t::KMTFTrack track(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), satKSlope(seed->eta2())); int phiB = correctedPhiB(seed); int charge; @@ -115,7 +115,7 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), satKSlope(seed->eta2())); } if (verbose_) { - edm::LogInfo("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK << " z=" << seed->eta1() << " kSlope=" << satKSlope(seed->eta2()); + edm::LogInfo("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK << " z=" << seed->eta1() << " kSlope=" << satKSlope(seed->eta2()); } track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); @@ -956,8 +956,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in if (verbose_) edm::LogInfo("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << residualPhi.to_int() << " " << phiB - << " - " << trackPhiB << " = " << residualPhiB.to_int(); - + << " - " << trackPhiB << " = " << residualPhiB.to_int(); uint absK = fabs(trackK); if (absK > pow(2, BITSCURV - 2) - 1) @@ -999,8 +998,6 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in << ap_ufixed(GAIN[3]).to_float(); } - //track.setKalmanGain(track.step(), fabs(trackK), GAIN[0], GAIN[1], 1, 0, GAIN[2], GAIN[3]); - int KNew; if (!(mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12)) { KNew = ap_fixed(ap_fixed(trackK) + @@ -1197,6 +1194,10 @@ bool KMTFCore::getBit(int bitmask, int pos) { return (bitmask & (1 << pos)) >> p void KMTFCore::setFourVectors(l1t::KMTFTrack& track) { //int etaINT = track.coarseEta(); + //legacy version of KMTF used coarse Eta to set the eta in SAMuons based on wheel-based LUT + //new approach uses kSlope to build eta for SAMuons + //matched KMTF output to gen muons and performed linear fit of gen eta vs kSlope of KMTF output + //eta=m*kslope+b where m and b come from fit ap_ufixed<18, 0> m = 0.03602; ap_ufixed<18, 0> b = 0.66840; int etaINT = int(round(double(m * track.kSlope() + b))); @@ -1413,7 +1414,6 @@ int KMTFCore::encode(bool ownwheel, int sector, int tag) { std::pair KMTFCore::getByCode(const std::vector& tracks, int mask) { for (uint i = 0; i < tracks.size(); ++i) { - //edm::LogInfo("KMTFCore") << "Code=" << tracks[i].hitPattern() << ", track=" << mask; if (tracks[i].hitPattern() == mask) return std::make_pair(true, i); } diff --git a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc index 2c8b84676580d..62b94c10471e4 100644 --- a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc +++ b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc @@ -141,8 +141,8 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandkSlope(const L1P l1t::MuonStub stub(wheel, sector, station, tfLayer, phi, phiS.phiBend(), tag, bx, quality, 0, 0, 0, 1); //defining z, k, zPhys, kPhys for case where theta digi exists - int z = pairs.thetaDigi().z(); - int k = pairs.thetaDigi().k(); + ap_int<16> z = pairs.thetaDigi().z(); + ap_int<16> k = pairs.thetaDigi().k(); float zPhys = z * (1500. / (1 << 16)); float kPhys = k * (2. / (1 << 16)); @@ -160,7 +160,16 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandkSlope(const L1P float R_centerPhys = RadiusStationPhys[station - 1]; float k_centerPhys = z_centerPhys / R_centerPhys; int k_centerDigi = k_centerPhys * ((1 << 16) / 2.); - + //very important + //clamp to a signed 16-bit range. upstream z and kSlope were declared with keyword int from phi-theta digi matched pair dataformat + //. this triggers only in wheels 1/2 wher k can exceed +/-1.0 for case of no theta digi!!!!!!!!!!!!! + //point back as close to the origin as we can. fixed range of kSlope binds the value + if (k_centerDigi > (1 << 15)-1) { + k_centerDigi = (1 << 15)-1; + } + if (k_centerDigi < -(1 << 15)) { + k_centerDigi = -(1 << 15); + } // check if theta digi exists with non-default constructor quality --> use z, k with etaQuality=3 from theta digi. // if theta digi has no real data, use z_center and slope which points to origin with etaQuality=0.. // stub set to etaQuality==3 if theta digi exists, 0 if not. From b5215b1819d921a1ae08baad8a60b1973350e069 Mon Sep 17 00:00:00 2001 From: Zhenbin Wu Date: Mon, 29 Jun 2026 15:08:50 -0500 Subject: [PATCH 28/29] Code format --- .../L1TMuonPhase2/interface/KMTFTrack.h | 162 +++++---- DataFormats/L1TMuonPhase2/src/classes_def.xml | 2 +- L1Trigger/Phase2L1GMT/interface/Isolation.h | 2 +- L1Trigger/Phase2L1GMT/interface/KMTFCore.h | 20 +- L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h | 73 ++-- .../plugins/Phase2L1TGMTKMTFProducer.cc | 10 +- .../plugins/Phase2L1TGMTStubProducer.cc | 2 +- L1Trigger/Phase2L1GMT/src/KMTF.cc | 132 +++---- L1Trigger/Phase2L1GMT/src/KMTFCore.cc | 337 ++++++++++-------- .../src/L1TPhase2GMTBarrelStubProcessor.cc | 89 +++-- 10 files changed, 459 insertions(+), 370 deletions(-) diff --git a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h index 0031a0f30cfef..a414b3458e169 100644 --- a/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h +++ b/DataFormats/L1TMuonPhase2/interface/KMTFTrack.h @@ -19,7 +19,7 @@ namespace l1t { : reco::LeafCandidate(-1, reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), unconstrainedP4_(reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), covariance_(std::vector(15, 0.0)), - covarianceNB_(std::vector(3, 0.0)), + covarianceNB_(std::vector(3, 0.0)), curvVertex_(0), ptC_(0), phiVertex_(0), @@ -35,8 +35,8 @@ namespace l1t { curv_(0), phi_(0), phiB_(0), - z_(0), - kSlope_(0), + z_(0), + kSlope_(0), coarseEta_(0), approxPromptChi2_(0), approxPromptErrChi2_(0), @@ -60,7 +60,7 @@ namespace l1t { : reco::LeafCandidate(-1, reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), unconstrainedP4_(reco::LeafCandidate::PolarLorentzVector(0.1, 0.0, 0.0, 0.105)), covariance_(std::vector(15, 0.0)), - covarianceNB_(std::vector(3, 0.0)), + covarianceNB_(std::vector(3, 0.0)), curvVertex_(0), ptC_(0), phiVertex_(0), @@ -76,8 +76,8 @@ namespace l1t { curv_(0), phi_(phi), phiB_(phiB), - z_(z), - kSlope_(kSlope), + z_(z), + kSlope_(kSlope), coarseEta_(0), approxPromptChi2_(0), approxPromptErrChi2_(0), @@ -134,10 +134,10 @@ namespace l1t { int positionAngle() const { return phi_; } //Unconstrained bending angle at the Muon systen int bendingAngle() const { return phiB_; } - - //global z and slope of stub - int zPosition() const {return z_;} - int kSlope() const {return kSlope_;} + + //global z and slope of stub + int zPosition() const { return z_; } + int kSlope() const { return kSlope_; } //Coarse eta caluclated only using phi segments int coarseEta() const { return coarseEta_; } //Approximate Chi2 metrics @@ -188,30 +188,37 @@ namespace l1t { return kalmanGain0_; } - const std::vector& ThetaGain1D(unsigned int step) const { - switch (step) { - case 3: return ThetaGain1D3_; - case 2: return ThetaGain1D2_; - case 1: return ThetaGain1D1_; - case 0: return ThetaGain1D0_; - } - return ThetaGain1D0_; - } + const std::vector& ThetaGain1D(unsigned int step) const { + switch (step) { + case 3: + return ThetaGain1D3_; + case 2: + return ThetaGain1D2_; + case 1: + return ThetaGain1D1_; + case 0: + return ThetaGain1D0_; + } + return ThetaGain1D0_; + } const std::vector& ThetaGain(unsigned int step) const { - switch (step) { - case 3: return ThetaGain3_; - case 2: return ThetaGain2_; - case 1: return ThetaGain1_; - case 0: return ThetaGain0_; - } - return ThetaGain0_; + switch (step) { + case 3: + return ThetaGain3_; + case 2: + return ThetaGain2_; + case 1: + return ThetaGain1_; + case 0: + return ThetaGain0_; + } + return ThetaGain0_; } - //get covariance const std::vector& covariance() const { return covariance_; } - const std::vector& covarianceNB() const { return covarianceNB_; } + const std::vector& covarianceNB() const { return covarianceNB_; } //get residual int residual(uint i) const { return residuals_[i]; } @@ -247,15 +254,15 @@ namespace l1t { curv_ = curv; phiB_ = phiB; phi_ = phi; - z_ = z; - kSlope_ = kSlope; + z_ = z; + kSlope_ = kSlope; } void setCoordinatesAtVertex(int curv, int phi, int dxy, int z, int kSlope) { curvVertex_ = curv; phiVertex_ = phi; dxy_ = dxy; - zVertex_ = z; + zVertex_ = z; kSlopeVertex_ = kSlope; } @@ -263,7 +270,7 @@ namespace l1t { curvMuon_ = curv; phiMuon_ = phi; phiBMuon_ = phiB; - zMuon_ = z; + zMuon_ = z; kSlopeMuon_ = kSlope; } @@ -275,7 +282,7 @@ namespace l1t { void setCoarseEta(int eta) { coarseEta_ = eta; } void setHitPattern(int pattern) { hitPattern_ = pattern; } - void setThetaDigiPattern(int theta_pattern) { thetaDigiPattern_ = theta_pattern; } + void setThetaDigiPattern(int theta_pattern) { thetaDigiPattern_ = theta_pattern; } void setApproxChi2(int chi, int chiErr, bool prompt) { if (prompt) { @@ -366,13 +373,29 @@ namespace l1t { } } - void setThetaGain1D(unsigned int step, unsigned int K, int priorThetaPattern, int seedStation, int priorPhiPattern, float G31, float G32, float G41, float G42) { + void setThetaGain1D(unsigned int step, + unsigned int K, + int priorThetaPattern, + int seedStation, + int priorPhiPattern, + float G31, + float G32, + float G41, + float G42) { std::vector* v1 = nullptr; switch (step) { - case 3: v1 = &ThetaGain1D3_; break; - case 2: v1 = &ThetaGain1D2_; break; - case 1: v1 = &ThetaGain1D1_; break; - case 0: v1 = &ThetaGain1D0_; break; + case 3: + v1 = &ThetaGain1D3_; + break; + case 2: + v1 = &ThetaGain1D2_; + break; + case 1: + v1 = &ThetaGain1D1_; + break; + case 0: + v1 = &ThetaGain1D0_; + break; default: throw cms::Exception("WrongCondition") << "1D: Critical ERROR on setting the Theta gain\n"; } @@ -386,13 +409,29 @@ namespace l1t { v1->push_back(G42); } - void setThetaGain(unsigned int step, unsigned int K, int priorThetaPattern, int seedStation, int priorPhiPattern, float G32, float G33, float G42, float G43) { + void setThetaGain(unsigned int step, + unsigned int K, + int priorThetaPattern, + int seedStation, + int priorPhiPattern, + float G32, + float G33, + float G42, + float G43) { std::vector* v2 = nullptr; switch (step) { - case 3: v2 = &ThetaGain3_; break; - case 2: v2 = &ThetaGain2_; break; - case 1: v2 = &ThetaGain1_; break; - case 0: v2 = &ThetaGain0_; break; + case 3: + v2 = &ThetaGain3_; + break; + case 2: + v2 = &ThetaGain2_; + break; + case 1: + v2 = &ThetaGain1_; + break; + case 0: + v2 = &ThetaGain0_; + break; default: throw cms::Exception("WrongCondition") << "Critical ERROR on setting the Theta gain\n"; } @@ -423,14 +462,13 @@ namespace l1t { covariance_[12] = c(2, 4); covariance_[13] = c(3, 4); covariance_[14] = c(4, 4); - } - - void setCovarianceNB(const CovarianceMatrix2dim& c) { - covarianceNB_[0] = c(0,0); - covarianceNB_[1] = c(0,1); - covarianceNB_[2] = c(1,1); - } + + void setCovarianceNB(const CovarianceMatrix2dim& c) { + covarianceNB_[0] = c(0, 0); + covarianceNB_[1] = c(0, 1); + covarianceNB_[2] = c(1, 1); + } //set fine eta void setFineEta(int eta) { @@ -446,7 +484,7 @@ namespace l1t { //Covariance matrix for studies std::vector covariance_; - std::vector covarianceNB_; + std::vector covarianceNB_; l1t::MuonStubRefVector stubs_; //vertex coordinates @@ -469,8 +507,8 @@ namespace l1t { int curv_; int phi_; int phiB_; - int z_; - int kSlope_; + int z_; + int kSlope_; //common coordinates int coarseEta_; @@ -482,7 +520,7 @@ namespace l1t { //phi bitmask int hitPattern_; - //bitmask pattern based on theta digi presence + //bitmask pattern based on theta digi presence int thetaDigiPattern_; //propagation step @@ -520,15 +558,15 @@ namespace l1t { std::vector residuals_; - std::vector ThetaGain1D0_; - std::vector ThetaGain1D1_; - std::vector ThetaGain1D2_; - std::vector ThetaGain1D3_; + std::vector ThetaGain1D0_; + std::vector ThetaGain1D1_; + std::vector ThetaGain1D2_; + std::vector ThetaGain1D3_; - std::vector ThetaGain0_; - std::vector ThetaGain1_; - std::vector ThetaGain2_; - std::vector ThetaGain3_; + std::vector ThetaGain0_; + std::vector ThetaGain1_; + std::vector ThetaGain2_; + std::vector ThetaGain3_; }; } // namespace l1t diff --git a/DataFormats/L1TMuonPhase2/src/classes_def.xml b/DataFormats/L1TMuonPhase2/src/classes_def.xml index b11b593334ce8..eaca77aede328 100644 --- a/DataFormats/L1TMuonPhase2/src/classes_def.xml +++ b/DataFormats/L1TMuonPhase2/src/classes_def.xml @@ -27,7 +27,7 @@ - + diff --git a/L1Trigger/Phase2L1GMT/interface/Isolation.h b/L1Trigger/Phase2L1GMT/interface/Isolation.h index 447aff5fd1ea0..70a82a9ca29f9 100644 --- a/L1Trigger/Phase2L1GMT/interface/Isolation.h +++ b/L1Trigger/Phase2L1GMT/interface/Isolation.h @@ -85,7 +85,7 @@ namespace Phase2L1GMT { static std::atomic nevto = 0; auto evto = nevto++; for (unsigned int i = 0; i < trkMus.size(); ++i) { - auto mu = trkMus.at(i); + const auto &mu = trkMus.at(i); if (mu.hwPt() != 0) { double convertphi = mu.hwPhi() * LSBphi; if (convertphi > M_PI) { diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h index bb6942a5dbe1a..99cb6553f3522 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFCore.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFCore.h @@ -66,7 +66,7 @@ namespace Phase2L1GMT { bool estimateChiSquare(l1t::KMTFTrack& track, bool vertex); void setRank(l1t::KMTFTrack& track, bool vertex); int wrapAround(int value, int maximum); - int satKSlope(int k); + int satKSlope(int k); int encode(bool ownwheel, int sector, int tag); std::pair getByCode(const std::vector& tracks, int mask); uint twosCompToBits(int q); @@ -132,13 +132,13 @@ namespace Phase2L1GMT { //bits for fixed point precision static const int PHIBSCALE = 16; static const int PHIBSCALE_INT = 5; - static const int ZDELTAR_BITS = 14; - static const int ZDELTAR_BITSINT = 1; + static const int ZDELTAR_BITS = 14; + static const int ZDELTAR_BITSINT = 1; static const int BITSCURV = 16; static const int BITSPHI = 18; static const int BITSPHIB = 17; // 12 bits *28 (+5 bits) - static const int BITSZ = 16; - static const int BITSKSLOPE = 16; + static const int BITSZ = 16; + static const int BITSKSLOPE = 16; static const int BITSPARAM = 14; static const int GAIN_0 = 9; static const int GAIN_0INT = 6; @@ -156,7 +156,7 @@ namespace Phase2L1GMT { static const int GAIN2_5 = 12; static const int GAIN2_5INT = 0; - static const int GAINT_6 = 12; //new theta view gain bits. + static const int GAINT_6 = 12; //new theta view gain bits. static const int GAINT_6INT = 3; static const int GAINT_7 = 12; static const int GAINT_7INT = 3; @@ -168,9 +168,9 @@ namespace Phase2L1GMT { /////////////////////////////////////////////////////// bool useOfflineAlgo_; - //used for z propagation + //used for z propagation std::vector zdeltaR_; - //multiple scattering constants used in multiple scattering matrix to build RMS values + //multiple scattering constants used in multiple scattering matrix to build RMS values std::vector mScatteringPhi_; std::vector mScatteringPhiB_; std::vector mScatteringz_; @@ -184,9 +184,9 @@ namespace Phase2L1GMT { //double pointResolutionPhiB_; //point resolution for vertex double pointResolutionVertex_; - // point resolution for z + // point resolution for z std::vector pointResolutionz_; - // point resolution for kSlope + // point resolution for kSlope std::vector pointResolutionkSlope_; std::vector curvResolution1_; std::vector curvResolution2_; diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h b/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h index e6051a1c33410..5af07d993668c 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h @@ -65,39 +65,39 @@ namespace Phase2L1GMT { lut2LL_[1 * 64 + 2] = (TH1 *)lutFile_->Get("gain2_2_1_LL"); coarseEta_ = (TH1 *)lutFile_->Get("coarseETALUT"); - - lutTheta1D_[1 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_1"); - lutTheta1D_[1 * 64 + 2] = (TH1 *)lutThetaFile_->Get("gain1D_2_1"); - lutTheta1D_[1 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain1D_4_1"); - lutTheta1D_[1 * 64 + 6] = (TH1 *)lutThetaFile_->Get("gain1D_6_1"); - lutTheta1D_[2 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain1D_4_2"); - lutTheta1D_[3 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_3"); - lutTheta2D_[1 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_1"); - lutTheta2D_[1 * 64 + 2] = (TH1 *)lutThetaFile_->Get("gain2D_2_1"); - lutTheta2D_[1 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain2D_4_1"); - lutTheta2D_[1 * 64 + 6] = (TH1 *)lutThetaFile_->Get("gain2D_6_1"); - lutTheta2D_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_2"); - lutTheta2D_[2 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain2D_4_2"); - lutTheta2D_[3 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_3"); - lutTheta1D11_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi1100"); - lutTheta1D01_[2 * 64 + 0]= (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi0100"); - lutTheta1D10_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi1000"); + + lutTheta1D_[1 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_1"); + lutTheta1D_[1 * 64 + 2] = (TH1 *)lutThetaFile_->Get("gain1D_2_1"); + lutTheta1D_[1 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain1D_4_1"); + lutTheta1D_[1 * 64 + 6] = (TH1 *)lutThetaFile_->Get("gain1D_6_1"); + lutTheta1D_[2 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain1D_4_2"); + lutTheta1D_[3 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_3"); + lutTheta2D_[1 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_1"); + lutTheta2D_[1 * 64 + 2] = (TH1 *)lutThetaFile_->Get("gain2D_2_1"); + lutTheta2D_[1 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain2D_4_1"); + lutTheta2D_[1 * 64 + 6] = (TH1 *)lutThetaFile_->Get("gain2D_6_1"); + lutTheta2D_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_2"); + lutTheta2D_[2 * 64 + 4] = (TH1 *)lutThetaFile_->Get("gain2D_4_2"); + lutTheta2D_[3 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain2D_0_3"); + lutTheta1D11_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi1100"); + lutTheta1D01_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi0100"); + lutTheta1D10_[2 * 64 + 0] = (TH1 *)lutThetaFile_->Get("gain1D_0_2_phi1000"); } ~KMTFLUTs() { lutFile_->Close(); lutThetaFile_->Close(); - if (lutFile_ != nullptr){ + if (lutFile_ != nullptr) { delete lutFile_; - } - if (lutThetaFile_ != nullptr){ + } + if (lutThetaFile_ != nullptr) { delete lutThetaFile_; } } std::vector trackGain(uint step, uint bitmask, uint K) { - std::vector gain(4, 0.0); - const TH1 *h = lut_[64 * step + bitmask]; + std::vector gain(4, 0.0); + const TH1 *h = lut_[64 * step + bitmask]; gain[0] = h->GetBinContent(K + 1); gain[2] = h->GetBinContent(1024 + K + 1); return gain; @@ -134,15 +134,14 @@ namespace Phase2L1GMT { return uint((1 << 12) * coarseEta_->GetBinContent(coarseEta_->GetXaxis()->FindBin(mask)) / M_PI); } - std::vector trackGainTheta(uint step, uint bitmask, uint K, bool is2D) { + std::vector trackGainTheta(uint step, uint bitmask, uint K, bool is2D) { std::vector gain(4, 0.0); const TH1 *h; - if (is2D){ - h = lutTheta2D_[64 * step + bitmask]; - } - else { - h = lutTheta1D_[64 * step + bitmask]; - } + if (is2D) { + h = lutTheta2D_[64 * step + bitmask]; + } else { + h = lutTheta1D_[64 * step + bitmask]; + } gain[0] = h->GetBinContent(K + 1); gain[1] = h->GetBinContent(512 + K + 1); gain[2] = h->GetBinContent(2 * 512 + K + 1); @@ -153,15 +152,13 @@ namespace Phase2L1GMT { std::vector trackGainTheta2(uint step, uint bitmask, uint phiBitmask, uint K) { std::vector gain(4, 0.0); const TH1 *h; - if (phiBitmask == 0b1100){ - h = lutTheta1D11_[64 * step + bitmask]; - } - else if (phiBitmask == 0b1000){ - h = lutTheta1D10_[64 * step + bitmask]; - } - else { - h = lutTheta1D01_[64 * step + bitmask]; - } + if (phiBitmask == 0b1100) { + h = lutTheta1D11_[64 * step + bitmask]; + } else if (phiBitmask == 0b1000) { + h = lutTheta1D10_[64 * step + bitmask]; + } else { + h = lutTheta1D01_[64 * step + bitmask]; + } gain[0] = h->GetBinContent(K + 1); gain[1] = h->GetBinContent(512 + K + 1); gain[2] = h->GetBinContent(2 * 512 + K + 1); diff --git a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTKMTFProducer.cc b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTKMTFProducer.cc index d24921204377e..c8c3a6b0411fd 100644 --- a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTKMTFProducer.cc +++ b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTKMTFProducer.cc @@ -95,11 +95,12 @@ void Phase2L1TGMTKMTFProducer::produce(edm::Event& iEvent, const edm::EventSetup std::vector kmtfTracks; for (const auto& track : kmtfOutput.first) { kmtfTracks.push_back(track); - //convert kmtf track.zPosition (LSB_kmtf=1500./2<<16) into z0 for SAMuon. + //convert kmtf track.zPosition (LSB_kmtf=1500./2<<16) into z0 for SAMuon. //LSBSAz0 = 1.6cm is too small given only 5 bits. the range fro z0 is +- 25.6cm from DataFormats/L1TMuonPhase2/interface/Constants.h - //eff. LSB = 1.6cm * 16 = 25.6 cm to widen the z0 range that can covered given only 5 bits. + //eff. LSB = 1.6cm * 16 = 25.6 cm to widen the z0 range that can covered given only 5 bits. //full conversion is z0_SA=z0_kmtf*(LSB_kmtf)*(1/LSB_SA)*(1/16) to convert between kmtf->SAMuon digitizations - ap_fixed z0 = track.zPosition() * ap_ufixed<18, 0>((1500.0 / (1 << 16)) / (LSBSAz0 * 16)); + ap_fixed z0 = + track.zPosition() * ap_ufixed<18, 0>((1500.0 / (1 << 16)) / (LSBSAz0 * 16)); l1t::SAMuon p(track.p4(), (track.curvatureAtVertex() < 0), track.ptPrompt(), @@ -128,7 +129,8 @@ void Phase2L1TGMTKMTFProducer::produce(edm::Event& iEvent, const edm::EventSetup for (const auto& track : kmtfOutput.second) { kmtfTracks.push_back(track); ap_int<7> dxy = track.dxy() * ap_ufixed<8, 1>(1.606); - ap_fixed z0 = track.zPosition() * ap_ufixed<18, 0>((1500.0 / (1 << 16)) / (LSBSAz0 * 16)); + ap_fixed z0 = + track.zPosition() * ap_ufixed<18, 0>((1500.0 / (1 << 16)) / (LSBSAz0 * 16)); l1t::SAMuon p(track.displacedP4(), (track.curvatureAtMuon() < 0), track.ptDisplaced(), diff --git a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc index ab61b1bb77947..56789cc38370d 100644 --- a/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc +++ b/L1Trigger/Phase2L1GMT/plugins/Phase2L1TGMTStubProducer.cc @@ -48,7 +48,7 @@ class Phase2L1TGMTStubProducer : public edm::stream::EDProducer<> { Phase2L1TGMTStubProducer::Phase2L1TGMTStubProducer(const edm::ParameterSet& iConfig) : srcCSC_( consumes>(iConfig.getParameter("srcCSC"))), - srcDT_(consumes(iConfig.getParameter("srcDT"))), + srcDT_(consumes(iConfig.getParameter("srcDT"))), srcDTTheta_(consumes(iConfig.getParameter("srcDTTheta"))), srcDTPairs_(consumes(iConfig.getParameter("srcDTPairs"))), srcRPC_(consumes(iConfig.getParameter("srcRPC"))), diff --git a/L1Trigger/Phase2L1GMT/src/KMTF.cc b/L1Trigger/Phase2L1GMT/src/KMTF.cc index 1a7f8afc2d0ed..b96989ee9cecb 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTF.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTF.cc @@ -81,71 +81,71 @@ std::pair, std::vector > KMTF::proce if (patterns) { edm::LogInfo("KMTF") << "KMTFPattern " << std::flush; if (i < Nstubs4) - edm::LogInfo("KMTF") << stubs4[0]->coord1() << " " << stubs4[0]->coord2() << " " << stubs4[0]->quality() << " " - << " 1 " << stubs4[0]->kmtf_address() << " 0 " << stubs4[0]->eta1() << " " - << stubs4[0]->eta2() << " " << (stubs4[0]->etaQuality() > 0 ? 1 : 0) << " " << std::flush; + edm::LogInfo("KMTF") << stubs4[0]->coord1() << " " << stubs4[0]->coord2() << " " << stubs4[0]->quality() << " " + << " 1 " << stubs4[0]->kmtf_address() << " 0 " << stubs4[0]->eta1() << " " + << stubs4[0]->eta2() << " " << (stubs4[0]->etaQuality() > 0 ? 1 : 0) << " " << std::flush; else - edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; if (i < Nstubs3) { for (const auto& s : stubs3) { - edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " - << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " - << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; + edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " + << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } //pad with zeros for (unsigned int j = stubs3.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } } else { for (unsigned int j = stubs3.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } for (const auto& s : stubs3) { - edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " - << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " - << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; + edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " + << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } } if (i < Nstubs2) { for (const auto& s : stubs2) { - edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " - << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " - << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; + edm::LogInfo("KMTF") << "" << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " + << s->kmtf_address() << " 0 " << s->eta1() << " " << s->eta2() << " " + << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; } //pad with zeros for (unsigned int j = stubs2.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } } else { for (unsigned int j = stubs2.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } for (const auto& s : stubs2) { - edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() - << " 0 " << s->eta1() << " " << s->eta2() << " " - << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; + edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() + << " 0 " << s->eta1() << " " << s->eta2() << " " << (s->etaQuality() > 0 ? 1 : 0) << " " + << std::flush; } } if (i < Nstubs1) { for (const auto& s : stubs1) { - edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() - << " 0 " << s->eta1() << " " << s->eta2() << " " - << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; + edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() + << " 0 " << s->eta1() << " " << s->eta2() << " " << (s->etaQuality() > 0 ? 1 : 0) << " " + << std::flush; } //pad with zeros for (unsigned int j = stubs1.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } } else { for (unsigned int j = stubs1.size(); j < 32; ++j) { - edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 511 0 0 0 0 " << std::flush; } for (const auto& s : stubs1) { - edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() - << " 0 " << s->eta1() << " " << s->eta2() << " " - << (s->etaQuality() > 0 ? 1 : 0) << " " << std::flush; + edm::LogInfo("KMTF") << s->coord1() << " " << s->coord2() << " " << s->quality() << " 1 " << s->kmtf_address() + << " 0 " << s->eta1() << " " << s->eta2() << " " << (s->etaQuality() > 0 ? 1 : 0) << " " + << std::flush; } } } @@ -166,25 +166,26 @@ std::pair, std::vector > KMTF::proce pretracksD4.push_back(tracks.second); if (patterns) { if (tracks.first.id() & 0x1) - edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " - << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.first.rankPrompt() << " " - << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; + edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " + << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " + << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.first.rankPrompt() + << " " << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; if (tracks.second.id() & 0x2) - edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " - << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " - << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.second.rankDisp() << " " - << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " << std::flush; + edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " + << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " + << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.second.rankDisp() + << " " << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " + << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } } else if (patterns) { - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } if (i < Nstubs3) { @@ -200,28 +201,28 @@ std::pair, std::vector > KMTF::proce pretracksD3.push_back(tracks.second); if (patterns) { if (tracks.first.id() & 0x1) - edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " - << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.first.rankPrompt() << " " - << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; + edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " + << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " + << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.first.rankPrompt() + << " " << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; if (tracks.second.id() & 0x2) - edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " - << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " - << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.second.rankDisp() << " " - << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " << std::flush; - + edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " + << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " + << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.second.rankDisp() + << " " << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " + << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } } else if (patterns) { - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } if (i < Nstubs2) { l1t::MuonStubRefVector stubs_proc; @@ -234,26 +235,27 @@ std::pair, std::vector > KMTF::proce pretracksD2.push_back(tracks.second); if (patterns) { if (tracks.first.id() & 0x1) - edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " - << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " - << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.first.rankPrompt() << " " - << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; + edm::LogInfo("KMTF") << "1 " << (tracks.first.curvatureAtVertex() < 0 ? 1 : 0) << " " + << tracks.first.ptPrompt() << " " << tracks.first.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.first.eta() / (M_PI / (1 << 12)))) << " " + << int(tracks.first.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.first.rankPrompt() + << " " << tracks.first.zPosition() << " " << tracks.first.kSlope() << " " << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; if (tracks.second.id() & 0x2) - edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " - << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " - << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) - << " " << tracks.second.rankDisp() << " " - << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " << std::flush; + edm::LogInfo("KMTF") << "1 " << (tracks.second.curvatureAtMuon() < 0 ? 1 : 0) << " " + << tracks.second.ptDisplaced() << " " << tracks.second.phiAtMuon() / (1 << 5) << " " + << int(round(tracks.second.eta() / (M_PI / (1 << 12)))) << " " + << int(tracks.second.dxy() * ap_ufixed<8, 1>(1.606)) << " " << tracks.second.rankDisp() + << " " << tracks.second.zPosition() << " " << tracks.second.kSlope() << " " + << std::flush; else edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; } } else if (patterns) { - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; - edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0"; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0 " << std::flush; + edm::LogInfo("KMTF") << "0 0 0 0 0 0 0 0 0"; } //Now the shift register emulation in C_++ if (stubs4.size() > 1) { diff --git a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc index 9af338fdae874..0cb775261d990 100644 --- a/L1Trigger/Phase2L1GMT/src/KMTFCore.cc +++ b/L1Trigger/Phase2L1GMT/src/KMTFCore.cc @@ -1,7 +1,8 @@ #include "L1Trigger/Phase2L1GMT/interface/KMTFCore.h" using namespace Phase2L1GMT; KMTFCore::KMTFCore(const edm::ParameterSet& settings) - : lutService_(new KMTFLUTs(settings.getParameter("lutFile"), settings.getParameter("lutThetaFile"))), + : lutService_(new KMTFLUTs(settings.getParameter("lutFile"), + settings.getParameter("lutThetaFile"))), verbose_(settings.getParameter("verbose")), initK_(settings.getParameter >("initialK")), initK2_(settings.getParameter >("initialK2")), @@ -86,7 +87,6 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef l1t::KMTFTrack nullTrack(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), satKSlope(seed->eta2())); seedQual = seed->quality(); for (const auto& mask : combinatorics) { - l1t::KMTFTrack track(seed, seed->coord1(), correctedPhiB(seed), seed->eta1(), satKSlope(seed->eta2())); int phiB = correctedPhiB(seed); int charge; @@ -115,7 +115,8 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef track.setCoordinates(seed->depthRegion(), initialK, seed->coord1(), 0, seed->eta1(), satKSlope(seed->eta2())); } if (verbose_) { - edm::LogInfo("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK << " z=" << seed->eta1() << " kSlope=" << satKSlope(seed->eta2()); + edm::LogInfo("KMTFCore") << "Initial state: phiB=" << phiB << " addr=" << address << " K=" << initialK + << " z=" << seed->eta1() << " kSlope=" << satKSlope(seed->eta2()); } track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); @@ -156,18 +157,19 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef else covariance(2, 2) = float(pointResolutionPhiBH_[seed->depthRegion() - 1]); } - if (seed->etaQuality() <= 0) { - covariance(3,3) = pow(2, 22); - covariance(4,4) = pow(2, 22); - } else { - covariance(3,3) = float(pointResolutionz_[seed->depthRegion() - 1]); - covariance(4,4) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); - } + if (seed->etaQuality() <= 0) { + covariance(3, 3) = pow(2, 22); + covariance(4, 4) = pow(2, 22); + } else { + covariance(3, 3) = float(pointResolutionz_[seed->depthRegion() - 1]); + covariance(4, 4) = float(pointResolutionkSlope_[seed->depthRegion() - 1]); + } track.setCovariance(covariance); if (verbose_) { edm::LogInfo("KMTFCore") << "New Kalman fit staring at step=" << track.step() << ", phi=" << track.positionAngle() - << ", phiB=" << track.bendingAngle() << ", z=" << track.zPosition() << ",kSlope = " << track.kSlope() << ", with curvature=" << track.curvature() ; + << ", phiB=" << track.bendingAngle() << ", z=" << track.zPosition() + << ",kSlope = " << track.kSlope() << ", with curvature=" << track.curvature(); edm::LogInfo("KMTFCore") << "BITMASK:" << std::flush; for (unsigned int i = 0; i < 4; ++i) edm::LogInfo("KMTFCore") << getBit(mask, i) << std::flush; @@ -180,7 +182,8 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef edm::LogInfo("KMTFCore") << "station=" << stub->depthRegion() << " phi=" << stub->coord1() << " phiB=" << correctedPhiB(stub) << " qual=" << stub->quality() << " tag=" << stub->id() << " sector=" << stub->phiRegion() - << " wheel=" << stub->etaRegion() << " z= " << stub->eta1() << " kSlope = " << satKSlope(stub->eta2()); + << " wheel=" << stub->etaRegion() << " z= " << stub->eta1() + << " kSlope = " << satKSlope(stub->eta2()); edm::LogInfo("KMTFCore") << "------------------------------------------------------"; edm::LogInfo("KMTFCore") << "------------------------------------------------------"; } @@ -190,7 +193,8 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef while (track.step() > 0) { // muon station 1 if (track.step() == 1) { - track.setCoordinatesAtMuon(track.curvature(), track.positionAngle(), track.bendingAngle(), track.zPosition(), track.kSlope()); + track.setCoordinatesAtMuon( + track.curvature(), track.positionAngle(), track.bendingAngle(), track.zPosition(), track.kSlope()); passedU = estimateChiSquare(track, false); setRank(track, false); @@ -201,17 +205,18 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef setFourVectors(track); //calculate coarse eta ////////////////////// - if (verbose_){ + if (verbose_) { edm::LogInfo("KMTFCore") << "Unconstrained PT in Muon System: pt=" << track.displacedP4().pt(); - } + } calculateEta(track); } propagate(track); if (verbose_) edm::LogInfo("KMTFCore") << "propagated Coordinates step:" << track.step() << "phi=" << track.positionAngle() - << "phiB=" << track.bendingAngle() << "K=" << track.curvature() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); - if (track.step() > 0){ + << "phiB=" << track.bendingAngle() << "K=" << track.curvature() + << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); + if (track.step() > 0) { if (getBit(mask, track.step() - 1)) { std::pair bestStub = match(seed, stubs, track.step()); if (verbose_) @@ -220,38 +225,44 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef const bool updated = bestStub.first ? update(track, stubs[bestStub.second], mask, seedQual) : false; if ((!bestStub.first) || (!updated)) { if (verbose_) { - edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] Breaking Kalman chain before final ID assignment" - << " seed(st=" << seed->depthRegion() << ",sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() - << ",bx=" << seed->bxNum() << ",id=" << seed->id() << ")" - << " step=" << track.step() << " mask=" << mask << " hitPattern=" << track.hitPattern() - << " matchFound=" << bestStub.first << " matchIndex=" << bestStub.second << " updateOK=" << updated - << " partialID=" << track.id() << " nStubs=" << track.stubs().size(); + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] Breaking Kalman chain before final ID assignment" + << " seed(st=" << seed->depthRegion() << ",sec=" << seed->phiRegion() + << ",wh=" << seed->etaRegion() << ",bx=" << seed->bxNum() << ",id=" << seed->id() + << ")" + << " step=" << track.step() << " mask=" << mask + << " hitPattern=" << track.hitPattern() << " matchFound=" << bestStub.first + << " matchIndex=" << bestStub.second << " updateOK=" << updated + << " partialID=" << track.id() << " nStubs=" << track.stubs().size(); if (seed->depthRegion() == 2) { - edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG_STA2] break-on-no-update/no-match" - << " seed(st=2,sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() << ",bx=" << seed->bxNum() - << ",id=" << seed->id() << ")" - << " currentStep=" << track.step() << " mask=" << mask << " hitPattern=" << track.hitPattern() - << " thetaPattern=" << track.thetaDigiPattern() << " passU_sofar=" << passedU - << " passV_sofar=" << passedV << " id_sofar=" << track.id() << " phiMuon=" << track.phiAtMuon() - << " phiVertex=" << track.phiAtVertex() << " z=" << track.zPosition() - << " kSlope=" << track.kSlope(); + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG_STA2] break-on-no-update/no-match" + << " seed(st=2,sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() + << ",bx=" << seed->bxNum() << ",id=" << seed->id() << ")" + << " currentStep=" << track.step() << " mask=" << mask + << " hitPattern=" << track.hitPattern() + << " thetaPattern=" << track.thetaDigiPattern() << " passU_sofar=" << passedU + << " passV_sofar=" << passedV << " id_sofar=" << track.id() + << " phiMuon=" << track.phiAtMuon() << " phiVertex=" << track.phiAtVertex() + << " z=" << track.zPosition() << " kSlope=" << track.kSlope(); } } break; } if (verbose_) { edm::LogInfo("KMTFCore") << "updated Coordinates step:" << track.step() << " phi=" << track.positionAngle() - << " phiB=" << track.bendingAngle() << " K=" << track.curvature() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); + << " phiB=" << track.bendingAngle() << " K=" << track.curvature() + << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); } } - } + } if (track.step() == 0) { - track.setCoordinatesAtVertex(track.curvature(), track.positionAngle(), track.bendingAngle(), track.zPosition(), track.kSlope()); + track.setCoordinatesAtVertex( + track.curvature(), track.positionAngle(), track.bendingAngle(), track.zPosition(), track.kSlope()); if (verbose_) edm::LogInfo("KMTFCore") << " Coordinates before vertex constraint step:" << track.step() << " phi=" << track.phiAtVertex() << " dxy=" << track.dxy() - << " K=" << track.curvatureAtVertex() << ", z=" << track.zPosition() << ", kSlope=" << track.kSlope(); + << " K=" << track.curvatureAtVertex() << ", z=" << track.zPosition() + << ", kSlope=" << track.kSlope(); //apply vertex constraint for non single tracks if (track.stubs().size() > 1) @@ -277,25 +288,28 @@ std::pair KMTFCore::chain(const l1t::MuonStubRef const int oldId = track.id(); track.setIDFlag(passedV, passedU); if (verbose_) { - edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] setIDFlag transition" - << " seed(st=" << seed->depthRegion() << ",sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() - << ",bx=" << seed->bxNum() << ",id=" << seed->id() << ")" - << " mask=" << mask << " hitPattern=" << track.hitPattern() << " thetaPattern=" << track.thetaDigiPattern() - << " passPrompt=" << passedV << " passDisp=" << passedU << " promptChi2=" << track.approxPromptChi2() - << " dispChi2=" << track.approxDispChi2() << " rankPrompt=" << track.rankPrompt() - << " rankDisp=" << track.rankDisp() << " oldID=" << oldId << " newID=" << track.id() - << " phiMuon=" << track.phiAtMuon() << " phiVertex=" << track.phiAtVertex() - << " nStubs=" << track.stubs().size(); + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] setIDFlag transition" + << " seed(st=" << seed->depthRegion() << ",sec=" << seed->phiRegion() + << ",wh=" << seed->etaRegion() << ",bx=" << seed->bxNum() << ",id=" << seed->id() + << ")" + << " mask=" << mask << " hitPattern=" << track.hitPattern() + << " thetaPattern=" << track.thetaDigiPattern() << " passPrompt=" << passedV + << " passDisp=" << passedU << " promptChi2=" << track.approxPromptChi2() + << " dispChi2=" << track.approxDispChi2() << " rankPrompt=" << track.rankPrompt() + << " rankDisp=" << track.rankDisp() << " oldID=" << oldId << " newID=" << track.id() + << " phiMuon=" << track.phiAtMuon() << " phiVertex=" << track.phiAtVertex() + << " nStubs=" << track.stubs().size(); if (seed->depthRegion() == 2) { - edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG_STA2] final-id-decision" - << " seed(st=2,sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() << ",bx=" << seed->bxNum() - << ",id=" << seed->id() << ")" - << " mask=" << mask << " passPrompt=" << passedV << " passDisp=" << passedU << " oldID=" << oldId - << " newID=" << track.id() << " rankPrompt=" << track.rankPrompt() << " rankDisp=" << track.rankDisp() - << " promptChi2=" << track.approxPromptChi2() << " dispChi2=" << track.approxDispChi2() - << " phiMuon=" << track.phiAtMuon() << " phiVertex=" << track.phiAtVertex() - << " z=" << track.zPosition() << " kSlope=" << track.kSlope() - << " nStubs=" << track.stubs().size(); + edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG_STA2] final-id-decision" + << " seed(st=2,sec=" << seed->phiRegion() << ",wh=" << seed->etaRegion() + << ",bx=" << seed->bxNum() << ",id=" << seed->id() << ")" + << " mask=" << mask << " passPrompt=" << passedV << " passDisp=" << passedU + << " oldID=" << oldId << " newID=" << track.id() + << " rankPrompt=" << track.rankPrompt() << " rankDisp=" << track.rankDisp() + << " promptChi2=" << track.approxPromptChi2() + << " dispChi2=" << track.approxDispChi2() << " phiMuon=" << track.phiAtMuon() + << " phiVertex=" << track.phiAtVertex() << " z=" << track.zPosition() + << " kSlope=" << track.kSlope() << " nStubs=" << track.stubs().size(); } } @@ -354,9 +368,9 @@ std::vector KMTFCore::clean(const std::vector& t if ((track.id() & 0x1) == 0) { if (verbose_) { edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] clean(prompt) dropping pretrack due to prompt ID bit=0" - << " seedStep=" << seed << " id=" << track.id() << " hitPattern=" << track.hitPattern() - << " rankPrompt=" << track.rankPrompt() << " rankDisp=" << track.rankDisp() - << " nStubs=" << track.stubs().size(); + << " seedStep=" << seed << " id=" << track.id() + << " hitPattern=" << track.hitPattern() << " rankPrompt=" << track.rankPrompt() + << " rankDisp=" << track.rankDisp() << " nStubs=" << track.stubs().size(); } continue; } @@ -370,9 +384,9 @@ std::vector KMTFCore::clean(const std::vector& t if ((track.id() & 0x2) == 0) { if (verbose_) { edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] clean(displaced) dropping pretrack due to displaced ID bit=0" - << " seedStep=" << seed << " id=" << track.id() << " hitPattern=" << track.hitPattern() - << " rankPrompt=" << track.rankPrompt() << " rankDisp=" << track.rankDisp() - << " nStubs=" << track.stubs().size(); + << " seedStep=" << seed << " id=" << track.id() + << " hitPattern=" << track.hitPattern() << " rankPrompt=" << track.rankPrompt() + << " rankDisp=" << track.rankDisp() << " nStubs=" << track.stubs().size(); } continue; } @@ -419,14 +433,14 @@ std::vector KMTFCore::clean(const std::vector& t if (verbose_) { const auto& kept = search->second; edm::LogInfo("KMTFCore") << "[KMTF_VALIDDBG] clean(" << (vertex ? "prompt" : "displaced") - << ") keeping selected pretrack" - << " seedStep=" << seed << " selectedPattern=" << selected << " id=" << kept.id() - << " rankPrompt=" << kept.rankPrompt() << " rankDisp=" << kept.rankDisp() - << " hitPattern=" << kept.hitPattern() << " thetaPattern=" << kept.thetaDigiPattern() - << " phiMuon=" << kept.phiAtMuon() << " phiVertex=" << kept.phiAtVertex() - << " curvMuon=" << kept.curvatureAtMuon() << " curvVertex=" << kept.curvatureAtVertex() - << " z=" << kept.zPosition() << " kSlope=" << kept.kSlope() - << " nStubs=" << kept.stubs().size(); + << ") keeping selected pretrack" + << " seedStep=" << seed << " selectedPattern=" << selected << " id=" << kept.id() + << " rankPrompt=" << kept.rankPrompt() << " rankDisp=" << kept.rankDisp() + << " hitPattern=" << kept.hitPattern() << " thetaPattern=" << kept.thetaDigiPattern() + << " phiMuon=" << kept.phiAtMuon() << " phiVertex=" << kept.phiAtVertex() + << " curvMuon=" << kept.curvatureAtMuon() << " curvVertex=" << kept.curvatureAtVertex() + << " z=" << kept.zPosition() << " kSlope=" << kept.kSlope() + << " nStubs=" << kept.stubs().size(); } out.push_back(search->second); } @@ -577,21 +591,23 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { //z and kSlope propagation // dR conversion factor comes from ZRES_CONV and KRES_CONV: ZRES_CONV/KRES_CONV=(65536/1500)/(65536/2) to go from physical (cm) to digitized units - double zdR_CONV = 2.0 / 1500.0 ; - double zdeltaR_dig = zdeltaR_[step - 1] * zdR_CONV ; + double zdR_CONV = 2.0 / 1500.0; + double zdeltaR_dig = zdeltaR_[step - 1] * zdR_CONV; int kSlopeNew = kSlope; int zNew; - zNew = ap_fixed(ap_fixed(z) - ap_ufixed(zdeltaR_dig) * ap_fixed(kSlope)); + zNew = + ap_fixed(ap_fixed(z) - ap_ufixed(zdeltaR_dig) * + ap_fixed(kSlope)); if (zNew > (1 << (BITSZ - 1)) - 1) { - if (verbose_){ - edm::LogInfo("KMTFCore") << "z saturated high during propagation, step=" << step; - } - zNew = (1 << (BITSZ - 1)) - 1; + if (verbose_) { + edm::LogInfo("KMTFCore") << "z saturated high during propagation, step=" << step; + } + zNew = (1 << (BITSZ - 1)) - 1; } else if (zNew < -(1 << (BITSZ - 1))) { - if (verbose_){ - edm::LogInfo("KMTFCore") << "z saturated low during propagation, step=" << step; - } - zNew = -(1 << (BITSZ - 1)); + if (verbose_) { + edm::LogInfo("KMTFCore") << "z saturated low during propagation, step=" << step; + } + zNew = -(1 << (BITSZ - 1)); } //Only for the propagation to vertex we use second order; @@ -659,7 +675,7 @@ void KMTFCore::propagate(l1t::KMTFTrack& track) { //Add the multiple scattering double phiRMS = mScatteringPhi_[step - 1] * K * K; double phiBRMS = mScatteringPhiB_[step - 1] * K * K; - double zRMS = mScatteringz_[step - 1] * K * K ; + double zRMS = mScatteringz_[step - 1] * K * K; double kSlopeRMS = mScatteringkSlope_[step - 1] * K * K; std::vector b(15); @@ -750,10 +766,16 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub const auto r11{stub->quality() < 6 ? pointResolutionPhiBL_[track.step() - 1] : pointResolutionPhiBH_[track.step() - 1]}; - const double r[]{pointResolutionPhi_, - 0.0, r11, - 0.0, 0.0, pointResolutionz_[track.step() - 1], - 0.0, 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; + const double r[]{pointResolutionPhi_, + 0.0, + r11, + 0.0, + 0.0, + pointResolutionz_[track.step() - 1], + 0.0, + 0.0, + 0.0, + pointResolutionkSlope_[track.step() - 1]}; const CovarianceMatrix4 R(r, 10); const std::vector& covLine = track.covariance(); @@ -765,7 +787,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub const Matrix54 Gain = cov * ROOT::Math::Transpose(H) * S; //track.setKalmanGain( - //track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); + //track.step(), fabs(trackK), Gain(0, 0), Gain(0, 1), 1, 0, Gain(2, 0), Gain(2, 1)); int KNew = (trackK + int(Gain(0, 0) * residual(0) + Gain(0, 1) * residual(1))); if (fabs(KNew) > pow(2, BITSCURV - 1)) @@ -776,17 +798,18 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub int kSlopeNew = trackSlope + int(Gain(4, 2) * residual(2) + Gain(4, 3) * residual(3)); if ((zNew > ((1 << (BITSZ - 1)) - 1)) || (zNew < (-(1 << (BITSZ - 1))))) { - if (verbose_) - edm::LogInfo("KMTFCore") << "z saturated in updateOffline"; - return false; + if (verbose_) + edm::LogInfo("KMTFCore") << "z saturated in updateOffline"; + return false; } if ((kSlopeNew > ((1 << (BITSKSLOPE - 1)) - 1)) || (kSlopeNew < (-(1 << (BITSKSLOPE - 1))))) { - if (verbose_) - edm::LogInfo("KMTFCore") << "kSlope saturated in updateOffline"; - return false; + if (verbose_) + edm::LogInfo("KMTFCore") << "kSlope saturated in updateOffline"; + return false; } - track.setResidual(stub->depthRegion() - 1, fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); + track.setResidual(stub->depthRegion() - 1, + fabs(phi - phiNew) + fabs(phiB - phiBNew) + fabs(z - zNew) + fabs(kSlope - kSlopeNew)); if (verbose_) { edm::LogInfo("KMTFCore") << "residual(0): " << phi << "-" << trackPhi << " = " << residual(0) << "\n"; @@ -801,29 +824,43 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub edm::LogInfo("KMTFCore") << "Gain(3,3): " << Gain(3, 3) << "\n"; edm::LogInfo("KMTFCore") << "Gain(4,2): " << Gain(4, 2) << "\n"; edm::LogInfo("KMTFCore") << "Gain(4,3): " << Gain(4, 3) << "\n"; - edm::LogInfo("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0) << "+" << Gain(0, 1) << "*" << residual(1) << " = " << KNew << "\n"; + edm::LogInfo("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0) << "+" << Gain(0, 1) + << "*" << residual(1) << " = " << KNew << "\n"; edm::LogInfo("KMTFCore") << " phiNew = " << trackPhi << "+" << residual(0) << " = " << phiNew << "\n"; - edm::LogInfo("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0) << "+" << Gain(2, 1) << "*" << residual(1) << " = " << phiBNew << "\n"; - edm::LogInfo("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 2) << "*" << residual(2) << "+" << Gain(3, 3) << "*" << residual(3) << " = " << zNew << "\n"; - edm::LogInfo("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 2) << "*" << residual(2) << "+" << Gain(4, 3) << "*" << residual(3) << " = " << kSlopeNew << "\n"; + edm::LogInfo("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0) << "+" + << Gain(2, 1) << "*" << residual(1) << " = " << phiBNew << "\n"; + edm::LogInfo("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 2) << "*" << residual(2) << "+" << Gain(3, 3) + << "*" << residual(3) << " = " << zNew << "\n"; + edm::LogInfo("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 2) << "*" << residual(2) << "+" + << Gain(4, 3) << "*" << residual(3) << " = " << kSlopeNew << "\n"; } track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); const Matrix55 covNew = cov - Gain * (H * cov); l1t::CovarianceMatrix5dim c; - for (int i = 0; i < 5; i++){ - for (int j = i; j < 5; j++){ - c(i, j) = covNew(i, j);}} + for (int i = 0; i < 5; i++) { + for (int j = i; j < 5; j++) { + c(i, j) = covNew(i, j); + } + } track.setCovariance(c); track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - track.setThetaGain(track.step(), fabs(trackK), priorThetaPattern, seedStation, priorPhiPattern, Gain(3, 2), Gain(3, 3), Gain(4, 2), Gain(4, 3)); - - if (verbose_){ - edm::LogInfo("KMTFCore") << "step: " << track.step() << "\n"; + track.setThetaGain(track.step(), + fabs(trackK), + priorThetaPattern, + seedStation, + priorPhiPattern, + Gain(3, 2), + Gain(3, 3), + Gain(4, 2), + Gain(4, 3)); + + if (verbose_) { + edm::LogInfo("KMTFCore") << "step: " << track.step() << "\n"; edm::LogInfo("KMTFCore") << "|K|: " << fabs(trackK) << "\n"; edm::LogInfo("KMTFCore") << "priorThetaPattern: " << priorThetaPattern << "\n"; edm::LogInfo("KMTFCore") << "priorPhiPattern: " << priorPhiPattern << "\n"; @@ -832,7 +869,7 @@ bool KMTFCore::updateOffline(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub edm::LogInfo("KMTFCore") << "Gain33: " << Gain(3, 3) << "\n"; edm::LogInfo("KMTFCore") << "Gain42: " << Gain(4, 2) << "\n"; edm::LogInfo("KMTFCore") << "Gain43: " << Gain(4, 3) << "\n"; - } + } return true; } @@ -859,7 +896,7 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st edm::LogInfo("KMTFCore") << "residual phi: " << phi << " - " << trackPhi << " = " << int(residual(0)); edm::LogInfo("KMTFCore") << "residual z: " << z << " - " << trackz << " = " << int(residual(1)); edm::LogInfo("KMTFCore") << "residual kSlope: " << kSlope << " - " << trackSlope << " = " << int(residual(2)); - } + } Matrix35 H; H(0, 0) = 0.0; @@ -878,9 +915,8 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st H(2, 3) = 0.0; H(2, 4) = 1.0; - const double r[]{pointResolutionPhi_, - 0.0, pointResolutionz_[track.step() - 1], - 0.0,0.0, pointResolutionkSlope_[track.step() - 1]}; + const double r[]{ + pointResolutionPhi_, 0.0, pointResolutionz_[track.step() - 1], 0.0, 0.0, pointResolutionkSlope_[track.step() - 1]}; const CovarianceMatrix3 R(r, 6); const std::vector& covLine = track.covariance(); @@ -900,14 +936,14 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st int kSlopeNew = trackSlope + int(Gain(4, 1) * residual(1) + Gain(4, 2) * residual(2)); if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { - if (verbose_) - edm::LogInfo("KMTFCore") << "z saturated in updateOffline1D"; - return false; + if (verbose_) + edm::LogInfo("KMTFCore") << "z saturated in updateOffline1D"; + return false; } if ((kSlopeNew > (pow(2, BITSKSLOPE - 1) - 1)) || (kSlopeNew < -(pow(2, BITSKSLOPE - 1)))) { - if (verbose_) - edm::LogInfo("KMTFCore") << "kSlope saturated in updateOffline1D"; - return false; + if (verbose_) + edm::LogInfo("KMTFCore") << "kSlope saturated in updateOffline1D"; + return false; } track.setCoordinates(track.step(), KNew, phiNew, phiBNew, zNew, kSlopeNew); @@ -919,8 +955,10 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st edm::LogInfo("KMTFCore") << " phiNew: " << trackPhi << "+" << residual(0); edm::LogInfo("KMTFCore") << " KNew = " << trackK << "+" << Gain(0, 0) << "*" << residual(0); edm::LogInfo("KMTFCore") << " phiBNew = " << trackPhiB << "+" << Gain(2, 0) << "*" << residual(0); - edm::LogInfo("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 1) << "*" << residual(1) << "+" << Gain(3, 2) << "*" << residual(2); - edm::LogInfo("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 1) << "*" << residual(1) << "+" << Gain(4, 2) << "*" << residual(2); + edm::LogInfo("KMTFCore") << " zNew = " << trackz << "+" << Gain(3, 1) << "*" << residual(1) << "+" << Gain(3, 2) + << "*" << residual(2); + edm::LogInfo("KMTFCore") << " kSlopeNew = " << trackSlope << "+" << Gain(4, 1) << "*" << residual(1) << "+" + << Gain(4, 2) << "*" << residual(2); } for (int i = 0; i < 5; i++) @@ -931,7 +969,15 @@ bool KMTFCore::updateOffline1D(l1t::KMTFTrack& track, const l1t::MuonStubRef& st track.addStub(stub); track.setHitPattern(hitPattern(track)); track.setThetaDigiPattern(thetaDigiPattern(track)); - track.setThetaGain1D(track.step(), fabs(trackK), priorThetaPattern, seedStation, priorPhiPattern, Gain(3, 1), Gain(3, 2), Gain(4, 1), Gain(4, 2)); + track.setThetaGain1D(track.step(), + fabs(trackK), + priorThetaPattern, + seedStation, + priorPhiPattern, + Gain(3, 1), + Gain(3, 2), + Gain(4, 1), + Gain(4, 2)); return true; } @@ -956,7 +1002,7 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in if (verbose_) edm::LogInfo("KMTFCore") << "residual " << phi << " - " << trackPhi << " = " << residualPhi.to_int() << " " << phiB - << " - " << trackPhiB << " = " << residualPhiB.to_int(); + << " - " << trackPhiB << " = " << residualPhiB.to_int(); uint absK = fabs(trackK); if (absK > pow(2, BITSCURV - 2) - 1) @@ -979,10 +1025,10 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in const bool is2D = (mask == 3 || mask == 5 || mask == 9 || mask == 6 || mask == 10 || mask == 12); if (!(is2D) && (track.step() == 2) && (track.thetaDigiPattern() == 0)) { - GAIN_THETA = lutService_->trackGainTheta2(track.step(), track.thetaDigiPattern(), track.hitPattern(), absK / 32); + GAIN_THETA = lutService_->trackGainTheta2(track.step(), track.thetaDigiPattern(), track.hitPattern(), absK / 32); } else { - GAIN_THETA = lutService_->trackGainTheta(track.step(), track.thetaDigiPattern(), absK / 32, is2D); - } + GAIN_THETA = lutService_->trackGainTheta(track.step(), track.thetaDigiPattern(), absK / 32, is2D); + } if (verbose_) { edm::LogInfo("KMTFCore") << "Gains (fp): " << GAIN[0] << " " << GAIN[1] << " " << GAIN[2] << " " << GAIN[3]; @@ -1047,12 +1093,16 @@ bool KMTFCore::updateLUT(l1t::KMTFTrack& track, const l1t::MuonStubRef& stub, in int zNew; int kSlopeNew; - zNew = ap_fixed(ap_fixed(trackz) + ap_ufixed(GAIN_THETA[0]) * residualz - ap_ufixed(GAIN_THETA[1]) * residualSlope); - kSlopeNew = ap_fixed(ap_fixed(trackSlope) - ap_ufixed(GAIN_THETA[2]) * residualz + ap_ufixed(GAIN_THETA[3]) * residualSlope); + zNew = ap_fixed(ap_fixed(trackz) + + ap_ufixed(GAIN_THETA[0]) * residualz - + ap_ufixed(GAIN_THETA[1]) * residualSlope); + kSlopeNew = ap_fixed(ap_fixed(trackSlope) - + ap_ufixed(GAIN_THETA[2]) * residualz + + ap_ufixed(GAIN_THETA[3]) * residualSlope); if ((zNew > (1 << (BITSZ - 1)) - 1) || (zNew < -(pow(2, BITSZ - 1)))) { if (verbose_) - edm::LogInfo("KMTFCore") << "z has saturated"; + edm::LogInfo("KMTFCore") << "z has saturated"; return false; } if ((kSlopeNew > (pow(2, BITSKSLOPE - 1) - 1)) || (kSlopeNew < -(pow(2, BITSKSLOPE - 1)))) { @@ -1082,7 +1132,6 @@ void KMTFCore::vertexConstraint(l1t::KMTFTrack& track) { vertexConstraintLUT(track); } - void KMTFCore::vertexConstraintOffline(l1t::KMTFTrack& track) { double residual = -track.dxy(); Matrix15 H; @@ -1215,12 +1264,14 @@ void KMTFCore::setFourVectors(l1t::KMTFTrack& track) { //Also set PT =0 and dxy=0 if (track.stubs().size() == 1) { ptC = 0; - track.setCoordinatesAtMuon(track.curvatureAtMuon(), track.stubs()[0]->coord1(), track.phiBAtMuon(), track.zPosition(), track.kSlope()); + track.setCoordinatesAtMuon( + track.curvatureAtMuon(), track.stubs()[0]->coord1(), track.phiBAtMuon(), track.zPosition(), track.kSlope()); track.setCoordinatesAtVertex(track.curvatureAtVertex(), track.phiAtVertex(), 0, track.zPosition(), track.kSlope()); } track.setPt(ptC, ptU); //shift the dxy by 10 bits - track.setCoordinatesAtVertex(track.curvatureAtVertex(), track.phiAtVertex(), track.dxy() / 1024, track.zPosition(), track.kSlope()); + track.setCoordinatesAtVertex( + track.curvatureAtVertex(), track.phiAtVertex(), track.dxy() / 1024, track.zPosition(), track.kSlope()); //vertex double pt = ptC * 0.03125; @@ -1257,12 +1308,12 @@ bool KMTFCore::estimateChiSquare(l1t::KMTFTrack& track, bool vertex) { const l1t::MuonStubRef& innerStub = track.stubs()[track.stubs().size() - 1]; if (verbose_) { edm::LogInfo("KMTFCore") << "[KMTF_CHI2DBG] begin " << (vertex ? "prompt" : "displaced") - << " chi2 fit: hitPattern=" << track.hitPattern() - << " thetaPattern=" << track.thetaDigiPattern() - << " nStubs=" << track.stubs().size() << " innerDepth=" << innerStub->depthRegion() - << " curvMuon=" << track.curvatureAtMuon() << " curvVtx=" << track.curvatureAtVertex() - << " phiMuon=" << track.phiAtMuon() << " phiVtx=" << track.phiAtVertex() - << " z=" << track.zPosition() << " kSlope=" << track.kSlope(); + << " chi2 fit: hitPattern=" << track.hitPattern() + << " thetaPattern=" << track.thetaDigiPattern() << " nStubs=" << track.stubs().size() + << " innerDepth=" << innerStub->depthRegion() << " curvMuon=" << track.curvatureAtMuon() + << " curvVtx=" << track.curvatureAtVertex() << " phiMuon=" << track.phiAtMuon() + << " phiVtx=" << track.phiAtVertex() << " z=" << track.zPosition() + << " kSlope=" << track.kSlope(); } if (vertex) { @@ -1336,19 +1387,19 @@ bool KMTFCore::estimateChiSquare(l1t::KMTFTrack& track, bool vertex) { chi = chi + absDelta; chiErr = chiErr + err; if (verbose_) { - edm::LogInfo("KMTFCore") << "[KMTF_CHI2DBG] per-stub " << (vertex ? "prompt" : "displaced") - << " innerDepth=" << innerStub->depthRegion() << " stubDepth=" << stub->depthRegion() - << " diffPhi=" << diffPhi << " diffPhiB=" << diffPhiB - << " propC=" << float(propC) << " Kshifted=" << int(Kshifted) << " AK=" << int(AK) - << " deltaSigned=" << delta << " deltaAbs=" << absDelta - << " posErrA=" << positionError - << " errBTerm=" << uint(ap_fixed<8, 2>(propErrB[stub->depthRegion() - innerStub->depthRegion() - 1]) * absK) - << " errTotal=" << err << " chiRunning=" << chi << " chiErrRunning=" << chiErr; + edm::LogInfo("KMTFCore") << "[KMTF_CHI2DBG] per-stub " << (vertex ? "prompt" : "displaced") + << " innerDepth=" << innerStub->depthRegion() << " stubDepth=" << stub->depthRegion() + << " diffPhi=" << diffPhi << " diffPhiB=" << diffPhiB << " propC=" << float(propC) + << " Kshifted=" << int(Kshifted) << " AK=" << int(AK) << " deltaSigned=" << delta + << " deltaAbs=" << absDelta << " posErrA=" << positionError << " errBTerm=" + << uint(ap_fixed<8, 2>(propErrB[stub->depthRegion() - innerStub->depthRegion() - 1]) * + absK) + << " errTotal=" << err << " chiRunning=" << chi << " chiErrRunning=" << chiErr; } } if (verbose_) { - edm::LogInfo("KMTFCore") << "[KMTF_CHI2DBG] final " << (vertex ? "prompt" : "displaced") - << " chi=" << chi << " chiErr=" << chiErr << " pass=" << (chi <= chiErr); + edm::LogInfo("KMTFCore") << "[KMTF_CHI2DBG] final " << (vertex ? "prompt" : "displaced") << " chi=" << chi + << " chiErr=" << chiErr << " pass=" << (chi <= chiErr); } track.setApproxChi2(chi, chiErr, vertex); @@ -1397,7 +1448,7 @@ int KMTFCore::wrapAround(int value, int maximum) { int KMTFCore::satKSlope(int k) { const int kmax = (1 << (BITSKSLOPE - 1)) - 1; - const int kmin = -(1 << (BITSKSLOPE - 1)); + const int kmin = -(1 << (BITSKSLOPE - 1)); return k > kmax ? kmax : (k < kmin ? kmin : k); } diff --git a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc index 62b94c10471e4..6f938f52cf69f 100644 --- a/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc +++ b/L1Trigger/Phase2L1GMT/src/L1TPhase2GMTBarrelStubProcessor.cc @@ -113,12 +113,11 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubNoEta(const L1Phase2MuDT } l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandkSlope(const L1Phase2MuDTExtPhiThetaPair& pairs) { - const auto& phiS = pairs.phiDigi(); - static constexpr int ZCenterDigitizedPositive[] = {11730, 23327}; - static constexpr int ZCenterDigitizedNegative[] = {-11697, -23290}; - static constexpr int ZCenterDigitizedZero[] = {22}; - static constexpr float RadiusStationPhys[] = {445., 526., 635., 730.}; + static constexpr int ZCenterDigitizedPositive[] = {11730, 23327}; + static constexpr int ZCenterDigitizedNegative[] = {-11697, -23290}; + static constexpr int ZCenterDigitizedZero[] = {22}; + static constexpr float RadiusStationPhys[] = {445., 526., 635., 730.}; int wheel = phiS.whNum(); int abswheel = fabs(phiS.whNum()); int sector = phiS.scNum(); @@ -149,70 +148,71 @@ l1t::MuonStub L1TPhase2GMTBarrelStubProcessor::buildStubwithZandkSlope(const L1P //slight asymmetry in wheels w.r.t. the origin calls for different z_center values for case where no theta digi was matched //defining z_center adn k_center for when theta digi does NOT exist!! int z_centerDigi; - if (wheel > 0){ - z_centerDigi= ZCenterDigitizedPositive[abswheel - 1]; + if (wheel > 0) { + z_centerDigi = ZCenterDigitizedPositive[abswheel - 1]; } else if (wheel < 0) { - z_centerDigi= ZCenterDigitizedNegative[abswheel - 1]; + z_centerDigi = ZCenterDigitizedNegative[abswheel - 1]; } else { - z_centerDigi= ZCenterDigitizedZero[0]; + z_centerDigi = ZCenterDigitizedZero[0]; } float z_centerPhys = z_centerDigi * (1500. / (1 << 16)); float R_centerPhys = RadiusStationPhys[station - 1]; - float k_centerPhys = z_centerPhys / R_centerPhys; + float k_centerPhys = z_centerPhys / R_centerPhys; int k_centerDigi = k_centerPhys * ((1 << 16) / 2.); //very important //clamp to a signed 16-bit range. upstream z and kSlope were declared with keyword int from phi-theta digi matched pair dataformat //. this triggers only in wheels 1/2 wher k can exceed +/-1.0 for case of no theta digi!!!!!!!!!!!!! //point back as close to the origin as we can. fixed range of kSlope binds the value - if (k_centerDigi > (1 << 15)-1) { - k_centerDigi = (1 << 15)-1; - } + if (k_centerDigi > (1 << 15) - 1) { + k_centerDigi = (1 << 15) - 1; + } if (k_centerDigi < -(1 << 15)) { - k_centerDigi = -(1 << 15); - } + k_centerDigi = -(1 << 15); + } // check if theta digi exists with non-default constructor quality --> use z, k with etaQuality=3 from theta digi. // if theta digi has no real data, use z_center and slope which points to origin with etaQuality=0.. // stub set to etaQuality==3 if theta digi exists, 0 if not. if (pairs.thetaDigi().quality() >= 0) { - stub.setEta(z, k, 3); - stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), zPhys, kPhys); + stub.setEta(z, k, 3); + stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), zPhys, kPhys); } else { - stub.setEta(z_centerDigi,k_centerDigi,0); - stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), z_centerPhys, k_centerPhys); + stub.setEta(z_centerDigi, k_centerDigi, 0); + stub.setOfflineQuantities(globalPhi, float(phiS.phiBend() * 0.49e-3), z_centerPhys, k_centerPhys); } return stub; } -l1t::MuonStubCollection L1TPhase2GMTBarrelStubProcessor::makeStubs(const L1Phase2MuDTExtPhiThetaPairContainer* pairContainer) { +l1t::MuonStubCollection L1TPhase2GMTBarrelStubProcessor::makeStubs( + const L1Phase2MuDTExtPhiThetaPairContainer* pairContainer) { l1t::MuonStubCollection out; for (int bx = minBX_; bx <= maxBX_; bx++) { ostringstream os; if (verbose_ == 2) os << "PATTERN "; - for (const auto& pair : pairContainer->getContainer()){ - const auto& phiDigi = pair.phiDigi(); - if ((phiDigi.bxNum() - 20) != bx) - continue; - if (phiDigi.quality() < minPhiQuality_) - continue; - - if (verbose_ == 2) { - ap_uint<64> wphi = ap_uint<17>(phiDigi.phi()); - ap_uint<64> wphib = ap_uint<13>(phiDigi.phiBend()); - ap_uint<64> wr1 = ap_uint<21>(0); - ap_uint<64> wq = ap_uint<4>(phiDigi.quality()); - ap_uint<64> wr2 = ap_uint<9>(0); - ap_uint<64> sN = 0; - sN = sN | wphi; - sN = sN | (wphib << 17); - sN = sN | (wr1 << 30); - sN = sN | (wq << 51); - sN = sN | (wr2 << 55); - os << std::setw(0) << std::dec << phiDigi.scNum() << " " << phiDigi.whNum() << " " << phiDigi.stNum() << " "; - os << std::uppercase << std::setfill('0') << std::setw(16) << std::hex << uint64_t(sN) << " "; - } - out.push_back(buildStubwithZandkSlope(pair)); - } + for (const auto& pair : pairContainer->getContainer()) { + const auto& phiDigi = pair.phiDigi(); + if ((phiDigi.bxNum() - 20) != bx) + continue; + if (phiDigi.quality() < minPhiQuality_) + continue; + + if (verbose_ == 2) { + ap_uint<64> wphi = ap_uint<17>(phiDigi.phi()); + ap_uint<64> wphib = ap_uint<13>(phiDigi.phiBend()); + ap_uint<64> wr1 = ap_uint<21>(0); + ap_uint<64> wq = ap_uint<4>(phiDigi.quality()); + ap_uint<64> wr2 = ap_uint<9>(0); + ap_uint<64> sN = 0; + sN = sN | wphi; + sN = sN | (wphib << 17); + sN = sN | (wr1 << 30); + sN = sN | (wq << 51); + sN = sN | (wr2 << 55); + os << std::setw(0) << std::dec << phiDigi.scNum() << " " << phiDigi.whNum() << " " << phiDigi.stNum() << " "; + os << std::uppercase << std::setfill('0') << std::setw(16) << std::hex << uint64_t(sN) << " "; + } + out.push_back(buildStubwithZandkSlope(pair)); + } if (verbose_ == 2) edm::LogInfo("BarrelStub") << os.str() << std::endl; } @@ -254,4 +254,3 @@ int L1TPhase2GMTBarrelStubProcessor::calculateEta(uint i, int wheel, uint sector return eta; } - From cbd01b57f116da75a81b86a55dd6ed98ffd99dc2 Mon Sep 17 00:00:00 2001 From: Zhenbin Wu Date: Mon, 13 Jul 2026 17:07:48 -0500 Subject: [PATCH 29/29] With unique_ptr for TFile --- L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h | 28 +++++++++------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h b/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h index 5af07d993668c..03b8577d23282 100644 --- a/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h +++ b/L1Trigger/Phase2L1GMT/interface/KMTFLUTs.h @@ -14,8 +14,8 @@ namespace Phase2L1GMT { KMTFLUTs(const std::string &filename, const std::string &ThetaFilename) { edm::FileInPath path(filename); edm::FileInPath pathTheta(ThetaFilename); - lutFile_ = new TFile(path.fullPath().c_str()); - lutThetaFile_ = new TFile(pathTheta.fullPath().c_str()); + lutFile_ = std::unique_ptr{TFile::Open(path.fullPath().c_str())}; + lutThetaFile_ = std::unique_ptr(TFile::Open(pathTheta.fullPath().c_str())); lut_[3 * 64 + 8] = (TH1 *)lutFile_->Get("gain_8_3"); lut_[2 * 64 + 8] = (TH1 *)lutFile_->Get("gain_8_2"); lut_[2 * 64 + 12] = (TH1 *)lutFile_->Get("gain_12_2"); @@ -87,12 +87,6 @@ namespace Phase2L1GMT { ~KMTFLUTs() { lutFile_->Close(); lutThetaFile_->Close(); - if (lutFile_ != nullptr) { - delete lutFile_; - } - if (lutThetaFile_ != nullptr) { - delete lutThetaFile_; - } } std::vector trackGain(uint step, uint bitmask, uint K) { @@ -134,13 +128,13 @@ namespace Phase2L1GMT { return uint((1 << 12) * coarseEta_->GetBinContent(coarseEta_->GetXaxis()->FindBin(mask)) / M_PI); } - std::vector trackGainTheta(uint step, uint bitmask, uint K, bool is2D) { + std::vector trackGainTheta(uint step, uint bitmask, uint K, bool is2D) const { std::vector gain(4, 0.0); const TH1 *h; if (is2D) { - h = lutTheta2D_[64 * step + bitmask]; + h = lutTheta2D_.at(64 * step + bitmask); } else { - h = lutTheta1D_[64 * step + bitmask]; + h = lutTheta1D_.at(64 * step + bitmask); } gain[0] = h->GetBinContent(K + 1); gain[1] = h->GetBinContent(512 + K + 1); @@ -149,15 +143,15 @@ namespace Phase2L1GMT { return gain; } - std::vector trackGainTheta2(uint step, uint bitmask, uint phiBitmask, uint K) { + std::vector trackGainTheta2(uint step, uint bitmask, uint phiBitmask, uint K) const { std::vector gain(4, 0.0); const TH1 *h; if (phiBitmask == 0b1100) { - h = lutTheta1D11_[64 * step + bitmask]; + h = lutTheta1D11_.at(64 * step + bitmask); } else if (phiBitmask == 0b1000) { - h = lutTheta1D10_[64 * step + bitmask]; + h = lutTheta1D10_.at(64 * step + bitmask); } else { - h = lutTheta1D01_[64 * step + bitmask]; + h = lutTheta1D01_.at(64 * step + bitmask); } gain[0] = h->GetBinContent(K + 1); gain[1] = h->GetBinContent(512 + K + 1); @@ -166,8 +160,8 @@ namespace Phase2L1GMT { return gain; } - TFile *lutFile_; - TFile *lutThetaFile_; + std::unique_ptr lutFile_; + std::unique_ptr lutThetaFile_; std::map lut_; std::map lut2HH_; std::map lut2LH_;