From 26861e5eb68266bd25f8b04ea0b47d260ab401fa Mon Sep 17 00:00:00 2001
From: Florian Uhlig <f.uhlig@gsi.de>
Date: Thu, 3 Aug 2023 16:52:18 +0200
Subject: [PATCH] Fix mvd digi links

The mvd digitizer distributes the MC points into several new arrays which are
used for the different sensors. This distribution does not allow to use any
longer the index in the array to link the proper MC information.
To vercome the problem the index in the original array is added as a data
member to the MC point.

Correctly store information about contributing MC points in MvdPixelCharge.
---
 sim/detectors/mvd/CbmMvdDigitizer.cxx   |  9 +++++++++
 sim/detectors/mvd/CbmMvdPixelCharge.cxx | 12 +-----------
 2 files changed, 10 insertions(+), 11 deletions(-)

diff --git a/sim/detectors/mvd/CbmMvdDigitizer.cxx b/sim/detectors/mvd/CbmMvdDigitizer.cxx
index f7817b432d..97761f3346 100644
--- a/sim/detectors/mvd/CbmMvdDigitizer.cxx
+++ b/sim/detectors/mvd/CbmMvdDigitizer.cxx
@@ -403,6 +403,15 @@ void CbmMvdDigitizer::BuildEvent()
   // ----- First treat standard input file
   nOrig = fInputPoints->GetEntriesFast();
 
+  // Since the points are distributed to several sensor tasks which creates
+  // several new arrays, the array index can't be used to link the proper
+  // MC information in the tasks to be used inside the task to link the
+  // correct MC information
+  // Add the index in the original array to to the point itself
+  for (int iPoint = 0; iPoint < nOrig; iPoint++) {
+    point = static_cast<CbmMvdPoint*>(fInputPoints->At(iPoint));
+    point->SetPointId(iPoint);
+  }
 
   // ----- Then treat event pileup
   if (fNPileup > 0) {
diff --git a/sim/detectors/mvd/CbmMvdPixelCharge.cxx b/sim/detectors/mvd/CbmMvdPixelCharge.cxx
index c18a3c8ab0..611a8466c2 100644
--- a/sim/detectors/mvd/CbmMvdPixelCharge.cxx
+++ b/sim/detectors/mvd/CbmMvdPixelCharge.cxx
@@ -28,14 +28,6 @@ CbmMvdPixelCharge::CbmMvdPixelCharge(Float_t charge, Int_t channelNrX, Int_t cha
   , fTrackCharge(charge)
   , fPixelTime(time)
 {
-  fTrackId.push_back(trackId);
-  fPointId.push_back(pointId);
-  fPointWeight.push_back(charge);
-  fPointX.push_back(pointPosX);
-  fPointY.push_back(pointPosY);
-  fTime.push_back(time);
-  //  fLink.push_back(); // TODO: pass link
-  fDominatorIndex = fPointWeight.size();
 }
 
 // ------- DigestCharge ----------------------------------------------------#
@@ -61,9 +53,7 @@ void CbmMvdPixelCharge::DigestCharge(Float_t pointX, Float_t pointY, Double_t ti
     fPointX.push_back(pointX);
     fPointY.push_back(pointY);
     fTime.push_back(time);
-
-    //  fTime.push_back(time);
-    //  fLink.push_back(); // TODO: pass link
+    fContributors++;
 
     if (chargeContr > fMaxChargeContribution) {
       fDominatorIndex        = fPointWeight.size();
-- 
GitLab