1717@date 2023-09-21
1818"""
1919
20+ import os
2021from ctypes import c_bool
2122from enum import Enum
2223
2324import ROOT # pylint: disable=import-error
2425
26+ name_script = os .path .basename (__file__ )
2527
2628# Enum of PDG_t particles
2729class PdgROOT (Enum ):
@@ -110,31 +112,44 @@ class Pdg(Enum):
110112 kXiCCPlusPlus = 4422
111113 kXiCPlus = 4232
112114 kXiCZero = 4132
115+ kDeuteron = 1000010020
116+ kTriton = 1000010030
117+ kHelium3 = 1000020030
118+ kAlpha = 1000020040
119+ kHyperTriton = 1010010030
120+ kHyperHydrogen4 = 1010010040
121+ kHyperHelium4 = 1010020040
122+
123+
124+ dbPdg = ROOT .o2 .O2DatabasePDG
113125
114126
115127def mass (code ):
116- """Returns particle mass from o2::O2DatabasePDG except for special cases."""
117- # Special cases (present in TDatabasePDG but with wrong values)
128+ """Returns particle mass from o2::O2DatabasePDG."""
118129 # Missing particles should be added in O2DatabasePDG.h.
119- if abs (code ) == Pdg .kXiCCPlusPlus .value :
120- return 3.62155 # PDG 2022: https://pdg.lbl.gov/2022/listings/rpp2022-list-xicc-plus-plus.pdf
121- if abs (code ) == Pdg .kOmegaC0 .value :
122- return 2.69520 # PDG 2022: https://pdg.lbl.gov/2022/listings/rpp2022-list-omegac-zero.pdf
123- # Default case
124130 success = c_bool (True )
125- return ROOT . o2 . O2DatabasePDG .Mass (code , success )
131+ return dbPdg .Mass (code , success )
126132
127133
128134def declare_mass (pdg , type = "double" ) -> str :
129135 """Returns a C++ declaration of a particle mass constant."""
130136 return f"constexpr { type } Mass{ pdg .name [1 :]} = { mass (pdg .value )} ;\n "
131137
132138
139+ # Comment at the beginning of the output
140+ str_block_begin = f"""// BEGINNING OF THE GENERATED BLOCK.
141+ // DO NOT EDIT THIS BLOCK DIRECTLY!
142+ // It has been generated by the { name_script } script.
143+ // For modifications, edit the script and generate this block again.
144+ """
145+ # Comment at the end of the output
146+ str_block_end = """// END OF THE GENERATED BLOCK
147+ """
133148# Start of enum declarations of additional particles
134149str_enum_head = """/// \\ brief Declarations of named PDG codes of particles missing in ROOT PDG_t
135150/// \\ note Follow kCamelCase naming convention
136151/// \\ link https://root.cern/doc/master/TPDGCode_8h.html
137- enum Code {
152+ enum Pdg {
138153"""
139154# End of enum declarations of additional particles
140155str_enum_foot = "};\n "
@@ -160,5 +175,5 @@ def declare_mass(pdg, type="double") -> str:
160175 str_mass_root += declare_mass (d )
161176
162177# Header body
163- str_header = "\n " .join ([ str_enum , str_mass_o2 , str_mass_root ] )
178+ str_header = "\n " .join (( str_block_begin , str_enum , str_mass_o2 , str_mass_root , str_block_end ) )
164179print (str_header )
0 commit comments