diff --git a/Framework/Particles/CMakeLists.txt b/Framework/Particles/CMakeLists.txt index 99b458bbeb20ff3188190fec97e5087b593d36e5..99d8e5a96b526ea7903ff954a9c54d233d8deab9 100644 --- a/Framework/Particles/CMakeLists.txt +++ b/Framework/Particles/CMakeLists.txt @@ -1,6 +1,7 @@ add_custom_command ( OUTPUT ${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc + ${PROJECT_BINARY_DIR}/Framework/Particles/pythia_db.pkl COMMAND ${PROJECT_SOURCE_DIR}/Framework/Particles/pdxml_reader.py ${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleData.xml ${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleClassNames.xml diff --git a/Framework/Particles/ParticleClassNames.xml b/Framework/Particles/ParticleClassNames.xml index 2c909fb1ae904e9f22d3af0da1682ef842aee54b..1a8e249ea63186e80d59d433dd218ab3ea4c8039 100644 --- a/Framework/Particles/ParticleClassNames.xml +++ b/Framework/Particles/ParticleClassNames.xml @@ -3,7 +3,7 @@ <!-- For selected particles it is possible to specify the C++ class names for a specific unique PDG code --> - <particle pdgID="0" classname="unknown"/> <!-- VOID in Pythia8 --> + <particle pdgID="0" classname="Unknown"/> <!-- VOID in Pythia8 --> <particle pdgID="11" classname="Electron"/> <particle pdgID="-11" classname="Positron"/> diff --git a/Framework/Particles/ParticleProperties.h b/Framework/Particles/ParticleProperties.h index 9e3c557d6df2662e3bf3ae58f8121bf51f4ce164..e28648127830ab150556ec781ee057e4b6c39976 100644 --- a/Framework/Particles/ParticleProperties.h +++ b/Framework/Particles/ParticleProperties.h @@ -34,7 +34,7 @@ namespace corsika::particles { corsika::units::si::ElectricChargeType constexpr GetElectricCharge(Code const); corsika::units::si::MassType constexpr GetMass(Code const); PDGCodeType constexpr GetPDG(Code const); - std::string const GetName(Code const); + std::string const& GetName(Code const); #include <corsika/particles/GeneratedParticleProperties.inc> @@ -60,7 +60,7 @@ namespace corsika::particles { return GetElectricChargeNumber(p) * (corsika::units::si::constants::e / 3.); } - std::string const GetName(Code const p) { + std::string const& GetName(Code const p) { return names[static_cast<CodeIntType const>(p)]; } diff --git a/Framework/Particles/pdxml_reader.py b/Framework/Particles/pdxml_reader.py index 8f39bd7ef193ece82395bc7849f7cb89aa891503..96d50588baf20388a96ec79b416e9e8aa67066fd 100755 --- a/Framework/Particles/pdxml_reader.py +++ b/Framework/Particles/pdxml_reader.py @@ -3,7 +3,7 @@ import sys, math, itertools, re, csv, pprint import xml.etree.ElementTree as ET from collections import OrderedDict - +import pickle ############################################################## @@ -113,7 +113,7 @@ def c_identifier_camel(name): # move "Bar" to end of name ibar = name.find('Bar') if ibar > 0 and ibar < len(name)-3: - name = name[:ibar] + name[ibar+3:] + str('Bar') + name = name[:ibar] + name[ibar+3:] + 'Bar' # cleanup "_"s while True: @@ -158,9 +158,12 @@ def c_identifier_camel(name): def build_pythia_db(filename, classnames): particle_db = OrderedDict() + + counter = itertools.count(0) + for (pdg, name, mass, electric_charge, antiName) in parse(filename): - c_id = "unknown" + c_id = "Unknown" if pdg in classnames: c_id = classnames[pdg] else: @@ -171,7 +174,8 @@ def build_pythia_db(filename, classnames): "antiName" : antiName, "pdg" : pdg, "mass" : mass, # in GeV - "electric_charge" : electric_charge # in e/3 + "electric_charge" : electric_charge, # in e/3 + "ngc_code" : next(counter) } return particle_db @@ -261,7 +265,7 @@ def gen_classes(pythia_db): for cname in pythia_db: - antiP = 'unknown' + antiP = 'Unknown' for cname_anti in pythia_db: if (pythia_db[cname_anti]['name'] == pythia_db[cname]['antiName']): antiP = cname_anti @@ -282,7 +286,7 @@ def gen_classes(pythia_db): string += " static constexpr corsika::units::si::MassType GetMass() { return corsika::particles::GetMass(Type); }\n" string += " static constexpr corsika::units::si::ElectricChargeType GetCharge() { return corsika::particles::GetElectricCharge(Type); }\n" string += " static constexpr int16_t GetChargeNumber() { return corsika::particles::GetElectricChargeNumber(Type); }\n" - string += " static std::string const GetName() { return corsika::particles::GetName(Type); }\n" + string += " static std::string const& GetName() { return corsika::particles::GetName(Type); }\n" string += " static constexpr Code GetAntiParticle() { return AntiType; }\n" string += " static constexpr Code Type = Code::" + cname + ";\n" string += " static constexpr Code AntiType = Code::" + antiP + ";\n" @@ -312,6 +316,14 @@ def inc_end(): return string +################################################################### +# +# Serialize pythia_db into file +# + +def serialize_pythia_db(pythia_db, file): + pickle.dump(pythia_db, file) + ################################################################### # # Main function @@ -320,7 +332,7 @@ def inc_end(): if __name__ == "__main__": if len(sys.argv) != 3: - print("usage: {:s} <Pythia8.xml> <ClassNames.xml>".format(sys.argv[0])) + print("usage: {:s} <Pythia8.xml> <ClassNames.xml>".format(sys.argv[0]), file=sys.stderr) sys.exit(1) names = class_names(sys.argv[2]) @@ -328,12 +340,6 @@ if __name__ == "__main__": print("\n pdxml_reader.py: Automatically produce particle-properties from PYTHIA8 xml file\n") - counter = itertools.count(0) - - not_modeled = [] - for p in pythia_db: - pythia_db[p]['ngc_code'] = next(counter) - with open("GeneratedParticleProperties.inc", "w") as f: print(inc_start(), file=f) print(gen_internal_enum(pythia_db), file=f) @@ -341,7 +347,5 @@ if __name__ == "__main__": print(gen_classes(pythia_db), file=f) print(inc_end(), file=f) - #~ print(pdg_id_table, mass_table, name_table, enums, sep='\n\n') - - - + with open("pythia_db.pkl", "wb") as f: + serialize_pythia_db(pythia_db, f) diff --git a/Framework/StackInterface/ParticleBase.h b/Framework/StackInterface/ParticleBase.h index aa0bb3d11a9e11369ce1fa0ac4d83092262707f5..b907129295a006a88092c6b5d0caa346b9706de0 100644 --- a/Framework/StackInterface/ParticleBase.h +++ b/Framework/StackInterface/ParticleBase.h @@ -48,6 +48,6 @@ namespace corsika::stack { int GetIndex() const { return GetIterator().GetIndex(); } }; -}; // namespace corsika::stack +} // namespace corsika::stack #endif diff --git a/Stack/SuperStupidStack/SuperStupidStack.h b/Stack/SuperStupidStack/SuperStupidStack.h index a09fe930f5546f807e282376a1afd7ef776b6fc1..f5674e2cf885c809c17c631e0e3a832afc566047 100644 --- a/Stack/SuperStupidStack/SuperStupidStack.h +++ b/Stack/SuperStupidStack/SuperStupidStack.h @@ -80,7 +80,7 @@ namespace corsika::stack { protected: void IncrementSize() { fDataE.push_back(0_GeV); - fDataPID.push_back(Code::unknown); + fDataPID.push_back(Code::Unknown); } void DecrementSize() { if (fDataE.size() > 0) {