From ee69fbcc364c38aa03b0dcfa8df67b3147b68de6 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Thu, 13 Feb 2025 07:32:47 +0100
Subject: [PATCH] online-kfp: bugfix

---
 algo/kfp/KfpV0Finder.cxx              | 10 +++++-----
 algo/kfp/KfpV0Finder.h                |  3 +++
 algo/kfp/KfpV0FinderQa.cxx            | 15 +++++++++------
 algo/kfp/KfpV0FinderQa.h              |  4 +++-
 services/histserv/app/Application.cxx | 24 ++++++++++++------------
 5 files changed, 32 insertions(+), 24 deletions(-)

diff --git a/algo/kfp/KfpV0Finder.cxx b/algo/kfp/KfpV0Finder.cxx
index bc06d7800..c95965bc8 100644
--- a/algo/kfp/KfpV0Finder.cxx
+++ b/algo/kfp/KfpV0Finder.cxx
@@ -50,7 +50,7 @@ bool V0Finder::AssignMomentum(const PartitionedVector<tof::Hit>& tofHits,
   }
   double gamma{1. / sqrt(1. - beta * beta)};
   particleInfo.fBeta = beta;
-  particleInfo.fQp   = particleInfo.fQp / (gamma * beta * particleInfo.fMass);
+  particleInfo.fQp   = particleInfo.fCharge / (gamma * beta * particleInfo.fMass);
   return true;
 }
 
@@ -91,7 +91,7 @@ void V0Finder::CollectDca(const RecoResults& recoEvent)
   const auto& stsHitIndices = recoEvent.trackStsHitIndices;
   for (size_t iTrk = 0; iTrk < stsHitIndices.size(); ++iTrk) {
     const auto& stsHitIndicesInTrack = stsHitIndices[iTrk];
-    if (stsHitIndicesInTrack.size() < 2) {  // less then two sts hits
+    if (stsHitIndicesInTrack.size() < 2) {  // DCA cannot be estimated
       fEventMonitor.IncrementCounter(ECounter::TracksWoStsHits);
       continue;
     }
@@ -130,7 +130,7 @@ double V0Finder::EstimateBeta(const tof::Hit& hit, double t0) const
   double t = hit.Time() - t0 - fTzeroOffset;
   double x{hit.X() - fOrigin[0]};
   double y{hit.Y() - fOrigin[1]};
-  double z{hit.Y() - fOrigin[2]};
+  double z{hit.Z() - fOrigin[2]};
   double x2{x * x};
   double y2{y * y};
   double z2{z * z};
@@ -217,7 +217,6 @@ bool V0Finder::FindV0Candidates(const RecoResults& recoEvent, double t0)
   KFPTrackVector kfpTracksLst;
   kfpTracksFst.Resize(nSelectedTracks);
   kfpTracksLst.Resize(nSelectedTracks);
-  fpTopoReconstructor->Init(kfpTracksFst, kfpTracksLst);
   for (uint32_t iKfpTrk = 0; iKfpTrk < fvSelectedTrackIds.size(); ++iKfpTrk) {  // Over selected tracks
     uint32_t iCaTrk{fvSelectedTrackIds[iKfpTrk]};
     const auto& trkParam{fvTrackParam[iCaTrk]};
@@ -225,6 +224,7 @@ bool V0Finder::FindV0Candidates(const RecoResults& recoEvent, double t0)
     SetKfpTrackParameters(kfpTracksFst, iKfpTrk, iCaTrk, trkParam.first, particleInfo);
     SetKfpTrackParameters(kfpTracksLst, iKfpTrk, iCaTrk, trkParam.second, particleInfo);
   }
+  fpTopoReconstructor->Init(kfpTracksFst, kfpTracksLst);
   fpTopoReconstructor->AddPV(MakeKfpPrimaryVertex(fOrigin));
   fpTopoReconstructor->SortTracks();
   fEventMonitor.StopTimer(ETimer::InitKfp);
@@ -308,7 +308,7 @@ CbmEventTriggers V0Finder::Process(const RecoResults& recoEvent)
     if (FindV0Candidates(recoEvent, t0)) {
       fSelectedT0 = t0;
       res.Set(CbmEventTriggers::ETrigger::Lambda);
-      fEventMonitor.IncrementCounter(ECounter::EventsLambdaCand);
+      fEventMonitor.IncrementCounter(ECounter::KfpEventsLambdaCand);
       break;  // Lambda-candidates were found, there is no sense to scan further
     }
   }
diff --git a/algo/kfp/KfpV0Finder.h b/algo/kfp/KfpV0Finder.h
index 72d1d1c57..9605b581b 100644
--- a/algo/kfp/KfpV0Finder.h
+++ b/algo/kfp/KfpV0Finder.h
@@ -92,6 +92,9 @@ namespace cbm::algo::kfp
     /// \brief  Accessor to topology reconstructor
     const std::unique_ptr<KFParticleTopoReconstructor>& GetTopoReconstructor() const { return fpTopoReconstructor; }
 
+    /// \brief  Gets track parameters
+    const auto& GetTrackAssignedParams() const { return fvTrackParam; }
+
     /// \brief Initializes the instance (called in the beginning of the run)
     void Init();
 
diff --git a/algo/kfp/KfpV0FinderQa.cxx b/algo/kfp/KfpV0FinderQa.cxx
index 4239174a7..ffc903e2a 100644
--- a/algo/kfp/KfpV0FinderQa.cxx
+++ b/algo/kfp/KfpV0FinderQa.cxx
@@ -29,17 +29,18 @@ void V0FinderQa::Init()
   fvphMassAll    = MakeObj<H1D>("kfp_mass_all", "Mass of particles;m [GeV/c^{2}];Counts", 300, 0., 1.5);
   fvphDcaAll     = MakeObj<H1D>("kfp_dca_all", "DCA of tracks to origin;DCA [cm];Counts", kDcaB, kDcaL, kDcaU);
   fvphBetaAll    = MakeObj<H1D>("kfp_beta_all", "Speed of tracks;#beta;Counts", kBetaB, kBetaL, kBetaU);
-  fvphBetaPdg    = MakeObj<H1D>("kfp_beta_pdg", "Speed of tracks w/ PDG;#beta;Counts", kBetaB, kBetaL, kBetaU);
   fvphBetaPion   = MakeObj<H1D>("kfp_beta_pion", "Speed of #pi-candidates;#beta;Counts", kBetaB, kBetaL, kBetaU);
   fvphBetaProton = MakeObj<H1D>("kfp_beta_proton", "Speed of proton-candidates;#beta;Counts", kBetaB, kBetaL, kBetaU);
+  fvphMomAll     = MakeObj<H1D>("kfp_mom_all", "Momentum of tracks;p [GeV/c];Counts", kBetaB, kBetaL, kBetaU);
+  fvphMomPion    = MakeObj<H1D>("kfp_mom_pion", "Momentum of #pi-candidates;p [GeV/c];Counts", kBetaB, kBetaL, kBetaU);
+  fvphMomProton =
+    MakeObj<H1D>("kfp_mom_proton", "Momentum of proton-candidates;p [GeV/c];Counts", kBetaB, kBetaL, kBetaU);
 
   //* Canvas initialisation
-  auto canv = CanvasConfig("kfp_lambda", "Lambda-trigger summary QA", 4, 2);
+  auto canv = CanvasConfig("kfp_lambda", "Lambda-trigger summary QA", 3, 2);
   canv.AddPadConfig(PadConfig(fvphMassLambdaCand, "hist"));  // (0, 0)
-  canv.AddPadConfig(PadConfig(fvphMassAll, "hist"));         // (1, 0)
   canv.AddPadConfig(PadConfig(fvphDcaAll, "hist"));          // (0, 1)
   canv.AddPadConfig(PadConfig(fvphBetaAll, "hist"));
-  canv.AddPadConfig(PadConfig(fvphBetaPdg, "hist"));
   canv.AddPadConfig(PadConfig(fvphBetaPion, "hist"));
   canv.AddPadConfig(PadConfig(fvphBetaProton, "hist"));
   AddCanvasConfig(canv);
@@ -54,16 +55,18 @@ void V0FinderQa::Exec(const RecoResults& recoEvent, const V0Finder& v0Finder)
   if (v0Finder.GetT0s().size() == 1) {
     for (uint32_t iTrk = 0; iTrk < tracks.size(); ++iTrk) {
       const auto& particleInfo{v0Finder.GetParticleInfo()[iTrk]};
+      const auto& trkParFst{(v0Finder.GetTrackAssignedParams()[iTrk]).first};
       bool bPdgDefined = (particleInfo.fPdg != V0Finder::kUndefPdg);
       fvphDcaAll->Fill(bPdgDefined ? particleInfo.fDca : -999);
       fvphBetaAll->Fill(particleInfo.fBeta);
       if (bPdgDefined) {
-        fvphBetaPdg->Fill(particleInfo.fBeta);
         if (particleInfo.fPdg == -211) {
           fvphBetaPion->Fill(particleInfo.fBeta);
+          fvphMomPion->Fill(trkParFst.GetP());
         }
         else if (particleInfo.fPdg == 2212) {
           fvphBetaProton->Fill(particleInfo.fBeta);
+          fvphMomProton->Fill(trkParFst.GetP());
         }
       }
     }
@@ -75,9 +78,9 @@ void V0FinderQa::Exec(const RecoResults& recoEvent, const V0Finder& v0Finder)
       fvphDcaAll->Fill(bPdgDefined ? particleInfo.fDca : -999);
       fvphBetaAll->Fill(-999);
       if (bPdgDefined) {
-        fvphBetaPdg->Fill(-999);
         if (particleInfo.fPdg == -211) {
           fvphBetaPion->Fill(-999);
+          fvphMomPion->Fill(-999);
         }
         else if (particleInfo.fPdg == 2212) {
           fvphBetaProton->Fill(-999);
diff --git a/algo/kfp/KfpV0FinderQa.h b/algo/kfp/KfpV0FinderQa.h
index 39a1289ba..35b914e18 100644
--- a/algo/kfp/KfpV0FinderQa.h
+++ b/algo/kfp/KfpV0FinderQa.h
@@ -75,8 +75,10 @@ namespace cbm::algo::kfp
     qa::H1D* fvphMassAll{nullptr};         ///< Mass of all particles in the topology
     qa::H1D* fvphDcaAll{nullptr};          ///< DCA of particles to origin
     qa::H1D* fvphBetaAll{nullptr};         ///< Speed of all particles
-    qa::H1D* fvphBetaPdg{nullptr};         ///< Speed of particles with PID hypothesis
     qa::H1D* fvphBetaPion{nullptr};        ///< Speed of pion-candidates
     qa::H1D* fvphBetaProton{nullptr};      ///< Speed of proton-candidates
+    qa::H1D* fvphMomAll{nullptr};          ///< Speed of all particles
+    qa::H1D* fvphMomPion{nullptr};         ///< Speed of pion-candidates
+    qa::H1D* fvphMomProton{nullptr};       ///< Speed of proton-candidates
   };
 }  // namespace cbm::algo::kfp
diff --git a/services/histserv/app/Application.cxx b/services/histserv/app/Application.cxx
index d2215633e..a4978c303 100644
--- a/services/histserv/app/Application.cxx
+++ b/services/histserv/app/Application.cxx
@@ -800,21 +800,21 @@ bool Application::PrepareCanvas(uint32_t uCanvIdx)
       if ("nullptr" != sName) {
         TObject* pObj = fArrayHisto[FindHistogram(sName)];
 
-        if (auto* pHist = dynamic_cast<TProfile2D*>(pObj)) {
-          pHist->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
+        if (auto* pHistP2 = dynamic_cast<TProfile2D*>(pObj)) {
+          pHistP2->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
         }  // if( nullptr != dynamic_cast< TProfile *>( pObj ) )
-        else if (auto* pHist = dynamic_cast<TProfile*>(pObj)) {
-          pHist->SetLineColor(uObjIdx + 1);
-          pHist->SetMarkerColor(uObjIdx + 1);
-          pHist->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
+        else if (auto* pHistP1 = dynamic_cast<TProfile*>(pObj)) {
+          pHistP1->SetLineColor(uObjIdx + 1);
+          pHistP1->SetMarkerColor(uObjIdx + 1);
+          pHistP1->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
         }  // if( nullptr != dynamic_cast< TProfile *>( pObj ) )
-        else if (auto* pHist = dynamic_cast<TH2*>(pObj)) {
-          pHist->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
+        else if (auto* pHistH2 = dynamic_cast<TH2*>(pObj)) {
+          pHistH2->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
         }  // if( nullptr != dynamic_cast< TH2 *>( pObj ) )
-        else if (auto* pHist = dynamic_cast<TH1*>(pObj)) {
-          pHist->SetLineColor(uObjIdx + 1);
-          pHist->SetMarkerColor(uObjIdx + 1);
-          pHist->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
+        else if (auto* pHistH1 = dynamic_cast<TH1*>(pObj)) {
+          pHistH1->SetLineColor(uObjIdx + 1);
+          pHistH1->SetMarkerColor(uObjIdx + 1);
+          pHistH1->Draw(conf.GetOption(uPadIdx, uObjIdx).data());
         }  // if( nullptr != dynamic_cast< TH1 *>( pObj ) )
         else
           LOG(warning) << "  Unsupported object type for " << sName << " when preparing canvas " << conf.GetName();
-- 
GitLab