From 862a44d6d395211bf5e471a3487496260cd8992e Mon Sep 17 00:00:00 2001
From: Volker Friese <v.friese@gsi.de>
Date: Tue, 15 Sep 2020 13:46:16 +0200
Subject: [PATCH] Catch case of ions and cherenkov photons not present in the
 standard TDatabasePDG in CbmMCTrack::GetMass() and GetCharge(). Refs #1806
 @1.5h

---
 core/data/CbmMCTrack.cxx | 54 +++++++++++++++++++++++++++++++++-------
 core/data/CbmMCTrack.h   | 17 +++++++++++++
 2 files changed, 62 insertions(+), 9 deletions(-)

diff --git a/core/data/CbmMCTrack.cxx b/core/data/CbmMCTrack.cxx
index 33bdbea87e..7b78439a88 100644
--- a/core/data/CbmMCTrack.cxx
+++ b/core/data/CbmMCTrack.cxx
@@ -112,31 +112,67 @@ CbmMCTrack::~CbmMCTrack() {}
 
 // -----   Public method GetMass   -----------------------------------------
 Double_t CbmMCTrack::GetMass() const {
+
   if (TDatabasePDG::Instance()) {
     TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
-    if (particle)
-      return particle->Mass();
-    else
+
+    // Particle found in TDatabasePDG
+    if (particle) return particle->Mass();
+
+    // Ions may not be in the TDatabasePDG, but their mass number is encoded
+    // in the PDG code like 10LZZZAAAI, where L is strangeness, Z is charge,
+    // A is number of nucleons, and I is isomer level.
+    else if (fPdgCode > 1000000000) {
+      Int_t a = (fPdgCode % 10000) / 10;
+      return Double_t(a) * CbmProtonMass();
+    }
+
+    // Cherenkov photons
+    else if (fPdgCode == 50000050)
       return 0.;
-  }
-  return 0.;
+
+    // Unknown particle type
+    else
+      LOG(fatal) << "CbmMCTrack: Unknown PDG code " << fPdgCode;
+  }  //? Instance of TDatabasePDG
+
+  LOG(fatal) << "CbmMCTrack: No TDatabasePDG";
+  return -1.;
 }
 // -------------------------------------------------------------------------
 
 
 // -----   Public method GetCharge   ---------------------------------------
 Double_t CbmMCTrack::GetCharge() const {
+
   if (TDatabasePDG::Instance()) {
     TParticlePDG* particle = TDatabasePDG::Instance()->GetParticle(fPdgCode);
-    if (particle)
-      return particle->Charge();
-    else
+
+    // Particle found in TDatabasePDG
+    if (particle) return particle->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,
+    // A is number of nucleons, and I is isomer level.
+    else if (fPdgCode > 1000000000) {
+      return Double_t((fPdgCode % 10000000) / 10000);
+    }
+
+    // Cherenkov photons
+    else if (fPdgCode == 50000050)
       return 0.;
-  }
+
+    // Unknown particle type
+    else
+      LOG(fatal) << "CbmMCTrack: Unknown PDG code " << fPdgCode;
+  }  //? Instance of TDatabasePDG
+
+  LOG(fatal) << "CbmMCTrack: No TDatabasePDG";
   return 0.;
 }
 // -------------------------------------------------------------------------
 
+
 // -----   Public method GetRapidity   -------------------------------------
 Double_t CbmMCTrack::GetRapidity() const {
   Double_t e = GetEnergy();
diff --git a/core/data/CbmMCTrack.h b/core/data/CbmMCTrack.h
index 7b7ce3f4f6..70044af55f 100644
--- a/core/data/CbmMCTrack.h
+++ b/core/data/CbmMCTrack.h
@@ -76,8 +76,25 @@ public:
   Double_t GetStartY() const { return fStartY; }
   Double_t GetStartZ() const { return fStartZ; }
   Double_t GetStartT() const { return fStartT; }
+
+  /** @brief Mass of the associated particle
+   ** @return Particle mass [GeV]
+   **
+   ** The mass is taken from TDatabasePDG if the particle exists there.
+   ** For ions, the mass is calculated from the PDG code. The method
+   ** throws an error for unknown PDG codes.
+   **/
   Double_t GetMass() const;
+
+  /** @brief Charge of the associated particle
+   ** @return Particle charge [e]
+   **
+   ** The charge is taken from TDatabasePDG if the particle exists there.
+   ** For ions, the charge is calculated from the PDG code. The method
+   ** throws an error for unknown PDG codes.
+   **/
   Double_t GetCharge() const;
+
   Double_t GetEnergy() const;
   Double_t GetPt() const { return TMath::Sqrt(fPx * fPx + fPy * fPy); }
   Double_t GetP() const {
-- 
GitLab