diff --git a/core/data/CbmMCTrack.cxx b/core/data/CbmMCTrack.cxx index 33bdbea87ec9c9744740c3cec5facdd525206a46..7b78439a88e25d2a09f95067aa1ae000a571c057 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 7b7ce3f4f60a2e868fe71d66dc3657c9e7c32cda..70044af55f922fa2c654f13e1eaf91585a057740 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 {