diff --git a/reco/KF/CbmKFParticleFinder.cxx b/reco/KF/CbmKFParticleFinder.cxx
index 0d53795e85217bb6f220d63c0b994c8f574f3ab6..6b9992843d6c7f1dfd8efbb6c0a7ed77ffd41fdc 100644
--- a/reco/KF/CbmKFParticleFinder.cxx
+++ b/reco/KF/CbmKFParticleFinder.cxx
@@ -158,9 +158,17 @@ void CbmKFParticleFinder::Exec(Option_t* /*opt*/)
 
     //calculate number of d-He4 candidates
     int nCandidatesDHe4 = 0;
-    if (fPID)
-      for (int iTr = 0; iTr < nTracksEvent; iTr++)
-        if (TMath::Abs(fPID->GetPID()[iTr]) == 1000010029) nCandidatesDHe4++;
+    if (fPID) {
+      if ((int) fPID->GetPID().size() == nTracksEvent) {
+        for (int iTr = 0; iTr < nTracksEvent; iTr++) {
+          if (TMath::Abs(fPID->GetPID()[iTr]) == 1000010029) nCandidatesDHe4++;
+        }
+      }
+      else {
+        Error("CbmKFParticleFinder::Event", "PID task has a wrong number of tracks: %l of %l", fPID->GetPID().size(),
+              nTracksEvent);
+      }
+    }
 
     vector<CbmStsTrack> vRTracks(nTracksEvent + nCandidatesDHe4);
     vector<int> pdg(nTracksEvent + nCandidatesDHe4, -1);