From b29b137cc65dd512d053e5a51cdb397947a5289c Mon Sep 17 00:00:00 2001
From: Lukas Chlad <chlad@ujf.cas.cz>
Date: Thu, 25 May 2023 14:29:55 +0000
Subject: [PATCH] Fix MCTrack charge to be always in units of electron charge

---
 core/data/CbmMCTrack.cxx   | 5 ++++-
 reco/L1/CbmCaMCModule.cxx  | 6 ++----
 reco/L1/CbmL1ReadEvent.cxx | 2 +-
 3 files changed, 7 insertions(+), 6 deletions(-)

diff --git a/core/data/CbmMCTrack.cxx b/core/data/CbmMCTrack.cxx
index 03974b9178..40066d4cca 100644
--- a/core/data/CbmMCTrack.cxx
+++ b/core/data/CbmMCTrack.cxx
@@ -154,7 +154,10 @@ double CbmMCTrack::GetCharge() const
     TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
 
     // Particle found in TDatabasePDG
-    if (particle) return particle->Charge();
+    if (particle) {
+      double electron_charge = abs(TDatabasePDG::Instance()->GetParticle(11)->Charge());
+      return particle->Charge() / electron_charge;
+    }
 
     // Ions may not be in the TDatabasePDG, but their charge number is encoded
     // in the PDG code like 10LZZZAAAI, where L is strangeness, Z is charge,
diff --git a/reco/L1/CbmCaMCModule.cxx b/reco/L1/CbmCaMCModule.cxx
index 9d55256837..2263509a63 100644
--- a/reco/L1/CbmCaMCModule.cxx
+++ b/reco/L1/CbmCaMCModule.cxx
@@ -730,10 +730,8 @@ void MCModule::ReadMCTracks()
       // in the data base, its mass is calculated as A times proton mass.
       aTrk.SetMass(pExtMCTrk->GetMass());
 
-      // The charge in CbmMCTrack is similarly to mass defined from ROOT PDG data base. The value of charge there is
-      // given in the units of 1/3e (absolute value of d-quark charge). In ::ca::tools::MCTrack we recalculate this
-      // value to the units of e.
-      aTrk.SetCharge(pExtMCTrk->GetCharge() / 3.);
+      // The charge in CbmMCTrack is given in the units of e
+      aTrk.SetCharge(pExtMCTrk->GetCharge());
 
       // Set index of mother track. We assume, that mother track was recorded into the internal array before
       int extMotherId = pExtMCTrk->GetMotherId();
diff --git a/reco/L1/CbmL1ReadEvent.cxx b/reco/L1/CbmL1ReadEvent.cxx
index 5655a3fdc3..f9c68efd9d 100644
--- a/reco/L1/CbmL1ReadEvent.cxx
+++ b/reco/L1/CbmL1ReadEvent.cxx
@@ -1272,7 +1272,7 @@ void CbmL1::Fill_vMCTracks()
       //}
       // TODO: Add light nuclei (d, t, He3, He4): they are common in tracking but not accounted in TDatabasePDG (S.Zharko)
 
-      q    = MCTrack->GetCharge() / 3.;
+      q    = MCTrack->GetCharge();
       mass = MCTrack->GetMass();
 
       Int_t iTrack = fvMCTracks.size();  //or iMCTrack?
-- 
GitLab