1616#ifndef O2_O2DATABASEPDG_H
1717#define O2_O2DATABASEPDG_H
1818
19+ #include < atomic>
1920#include < cmath>
2021#include < string>
2122#include " TDatabasePDG.h"
@@ -39,7 +40,8 @@ class O2DatabasePDG
3940 static bool initialized = false ; // initialize this --> adds particles to TDatabasePDG;
4041 auto db = TDatabasePDG::Instance ();
4142 if (!initialized) {
42- addALICEParticles (db);
43+ // uses the monopole mass of the simulation if a reader has already set it
44+ addALICEParticles (db, getMonopoleMass ());
4345 initialized = true ;
4446 }
4547 return db;
@@ -68,6 +70,26 @@ class O2DatabasePDG
6870 return true ;
6971 }
7072
73+ // Sets the mass (GeV) of the monopole species for consumers of simulated data, which do not
74+ // have access to G4Params.monopoleMass. It is taken from the MCEventHeader of the
75+ // simulation (key o2::sim::MonopoleMassHeaderKey) by MCKinematicsReader.
76+ // It only affects Mass() (hence MCTrack::GetMass() / GetEnergy() / GetRapidity()) and
77+ // Instance() if called before the first Instance(): particles already registered in a
78+ // TDatabasePDG keep their mass, since ROOT offers no way to change it afterwards.
79+ // Not used (and not needed) in the simulation itself, where TDatabasePDG is registered
80+ // with G4Params.monopoleMass.
81+ static void setMonopoleMass (double massGeV) { monopoleMassOverride ().store (massGeV); }
82+
83+ // mass set by setMonopoleMass(), or the default if it was never set
84+ static double getMonopoleMass ()
85+ {
86+ const double mass = monopoleMassOverride ().load ();
87+ return mass > 0 . ? mass : o2::sim::MonopoleMassDefaultGeV;
88+ }
89+
90+ // true if a monopole mass was set by setMonopoleMass()
91+ static bool hasMonopoleMassOverride () { return monopoleMassOverride ().load () > 0 .; }
92+
7193 // get particle's (if any) mass
7294 static Double_t MassImpl (TParticlePDG* particle, bool & success)
7395 {
@@ -82,6 +104,11 @@ class O2DatabasePDG
82104 // determine particle to get mass for based on PDG
83105 static Double_t Mass (int pdg, bool & success, TDatabasePDG* db = O2DatabasePDG::Instance())
84106 {
107+ if (hasMonopoleMassOverride () && o2::sim::isMonopole (pdg)) {
108+ // the table may have been filled with the default mass before the simulation mass was known
109+ success = true ;
110+ return getMonopoleMass ();
111+ }
85112 if (pdg < IONBASELOW || pdg > IONBASEHIGH ) {
86113 // not an ion, return immediately
87114 return MassImpl (db->GetParticle (pdg), success);
@@ -99,6 +126,13 @@ class O2DatabasePDG
99126 O2DatabasePDG () = delete ;
100127
101128 private:
129+ // negative: not set (the TDatabasePDG content is used)
130+ static std::atomic<double >& monopoleMassOverride ()
131+ {
132+ static std::atomic<double > mass{-1 .};
133+ return mass;
134+ }
135+
102136 static constexpr int IONBASELOW {1000000000 };
103137 static constexpr int IONBASEHIGH {1099999999 };
104138};
@@ -161,7 +195,7 @@ inline void O2DatabasePDG::addALICEParticles(TDatabasePDG* db, double monopoleMa
161195 db->AddParticle (" A_0+ " , " " , 0.9960 , kFALSE , 0.0 , +3 , " meson" , 9000211 );
162196 db->AddParticle (" A_0- " , " " , 0.9960 , kFALSE , 0.0 , -3 , " meson" , -9000211 );
163197
164- // db->AddParticle("F0P0 ", " ", 0.9960, kFALSE, 0.0, 0, "meson", 9010221);
198+ // db->AddParticle("F0P0 ", " ", 0.9960, kFALSE, 0.0, 0, "meson", 9010221);
165199
166200 db->AddParticle (" KDL_2+ " , " " , 1.773 , kFALSE , 0.0 , +3 , " meson" , 10325 );
167201 db->AddParticle (" KDL_2- " , " " , 1.773 , kFALSE , 0.0 , -3 , " meson" , -10325 );
@@ -261,7 +295,7 @@ inline void O2DatabasePDG::addALICEParticles(TDatabasePDG* db, double monopoleMa
261295 db->AddParticle (" FeedbackPhoton" , " FeedbackPhoton" , 0 , kFALSE ,
262296 0 , 0 , " Special" , kspe + 51 );
263297
264- // Hyper nuclei and exotica
298+ // Hyper nuclei and exotica
265299 ionCode = 1010010030 ;
266300 if (!db->GetParticle (ionCode)) {
267301 db->AddParticle (" HyperTriton" , " HyperTriton" , 2.991134 , kFALSE ,
@@ -274,25 +308,25 @@ inline void O2DatabasePDG::addALICEParticles(TDatabasePDG* db, double monopoleMa
274308 2.5e-15 , 3 , " Ion" , ionCode);
275309 }
276310
277- // hyper hydrogen 4 ground state
311+ // hyper hydrogen 4 ground state
278312 ionCode = 1010010040 ;
279313 if (!db->GetParticle (ionCode)) {
280314 db->AddParticle (" Hyperhydrog4" , " Hyperhydrog4" , 3.922434 , kFALSE ,
281315 2.5e-15 , 3 , " Ion" , ionCode);
282316 }
283- // anti hyper hydrogen 4 ground state
317+ // anti hyper hydrogen 4 ground state
284318 ionCode = -1010010040 ;
285319 if (!db->GetParticle (ionCode)) {
286320 db->AddParticle (" AntiHyperhydrog4" , " AntiHyperhydrog4" , 3.922434 , kFALSE ,
287321 2.5e-15 , 3 , " Ion" , ionCode);
288322 }
289- // hyper helium 4 ground state
323+ // hyper helium 4 ground state
290324 ionCode = 1010020040 ;
291325 if (!db->GetParticle (ionCode)) {
292326 db->AddParticle (" Hyperhelium4" , " Hyperhelium4" , 3.921728 , kFALSE ,
293327 2.5e-15 , 6 , " Ion" , ionCode);
294328 }
295- // anti hyper helium 4 ground state
329+ // anti hyper helium 4 ground state
296330 ionCode = -1010020040 ;
297331 if (!db->GetParticle (ionCode)) {
298332 db->AddParticle (" AntiHyperhelium4" , " AntiHyperhelium4" , 3.921728 , kFALSE ,
@@ -642,9 +676,9 @@ inline void O2DatabasePDG::addALICEParticles(TDatabasePDG* db, double monopoleMa
642676 0.040 , -3 , " Resonance" , -ionCode);
643677 }
644678
645- // Additional Hidden Strangeness Pentaquarks
679+ // Additional Hidden Strangeness Pentaquarks
646680
647- // Ps +/-
681+ // Ps +/-
648682 ionCode = 9322132 ;
649683 if (!db->GetParticle (ionCode)) {
650684 db->AddParticle (" Ps_Plus_1870" , " Ps_Plus_1870" , 1.870 , kFALSE ,
@@ -682,7 +716,7 @@ inline void O2DatabasePDG::addALICEParticles(TDatabasePDG* db, double monopoleMa
682716 0.10 , -3 , " Resonance" , -ionCode);
683717 }
684718
685- // Ps0
719+ // Ps0
686720 ionCode = 9322131 ;
687721 if (!db->GetParticle (ionCode)) {
688722 db->AddParticle (" Ps_0_1870" , " Ps_0_1870" , 1.870 , kFALSE ,
@@ -786,14 +820,14 @@ inline void O2DatabasePDG::addALICEParticles(TDatabasePDG* db, double monopoleMa
786820
787821 // d*(2380) - dibaryon resonance
788822
789- ionCode = 900010020 ; // Arbitrary choice - as deuteron but with leading 9 instead of 10
823+ ionCode = 900010020 ; // Arbitrary choice - as deuteron but with leading 9 instead of 10
790824 if (!db->GetParticle (ionCode)) {
791825 db->AddParticle (" d*_2380" , " d*_2380" , 2.38 , kFALSE ,
792826 0.070 , 3 , " Resonance" , ionCode);
793827 }
794828 db->AddAntiParticle (" d*_2380_bar" , -ionCode);
795829
796- // Sexaquark (uuddss): compact, neutral and stable hypothetical bound state (arxiv.org/abs/1708.08951)
830+ // Sexaquark (uuddss): compact, neutral and stable hypothetical bound state (arxiv.org/abs/1708.08951)
797831 ionCode = 900000020 ;
798832 if (!db->GetParticle (ionCode)) {
799833 db->AddParticle (" Sexaquark" , " Sexaquark" , 2.0 , kTRUE , 0.0 , 0 , " Special" , ionCode);
@@ -826,4 +860,4 @@ inline void O2DatabasePDG::addParticlesFromExternalFile(TDatabasePDG* db)
826860
827861} // namespace o2
828862
829- #endif // O2_O2DATABASEPDG_H
863+ #endif // O2_O2DATABASEPDG_H
0 commit comments