IAP GITLAB

Skip to content
Snippets Groups Projects
Commit ec12dcaa authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan:
Browse files

upper case "Unknown" particle, pickle pythia_db

parent d90842e5
No related branches found
No related tags found
No related merge requests found
add_custom_command ( add_custom_command (
OUTPUT ${PROJECT_BINARY_DIR}/Framework/Particles/GeneratedParticleProperties.inc 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 COMMAND ${PROJECT_SOURCE_DIR}/Framework/Particles/pdxml_reader.py
${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleData.xml ${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleData.xml
${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleClassNames.xml ${PROJECT_SOURCE_DIR}/Framework/Particles/ParticleClassNames.xml
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<!-- For selected particles it is possible to specify the C++ class <!-- For selected particles it is possible to specify the C++ class
names for a specific unique PDG code --> 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="Electron"/>
<particle pdgID="-11" classname="Positron"/> <particle pdgID="-11" classname="Positron"/>
......
...@@ -34,7 +34,7 @@ namespace corsika::particles { ...@@ -34,7 +34,7 @@ namespace corsika::particles {
corsika::units::si::ElectricChargeType constexpr GetElectricCharge(Code const); corsika::units::si::ElectricChargeType constexpr GetElectricCharge(Code const);
corsika::units::si::MassType constexpr GetMass(Code const); corsika::units::si::MassType constexpr GetMass(Code const);
PDGCodeType constexpr GetPDG(Code const); PDGCodeType constexpr GetPDG(Code const);
std::string const GetName(Code const); std::string const& GetName(Code const);
#include <corsika/particles/GeneratedParticleProperties.inc> #include <corsika/particles/GeneratedParticleProperties.inc>
...@@ -60,7 +60,7 @@ namespace corsika::particles { ...@@ -60,7 +60,7 @@ namespace corsika::particles {
return GetElectricChargeNumber(p) * (corsika::units::si::constants::e / 3.); 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)]; return names[static_cast<CodeIntType const>(p)];
} }
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
import sys, math, itertools, re, csv, pprint import sys, math, itertools, re, csv, pprint
import xml.etree.ElementTree as ET import xml.etree.ElementTree as ET
from collections import OrderedDict from collections import OrderedDict
import pickle
############################################################## ##############################################################
...@@ -113,7 +113,7 @@ def c_identifier_camel(name): ...@@ -113,7 +113,7 @@ def c_identifier_camel(name):
# move "Bar" to end of name # move "Bar" to end of name
ibar = name.find('Bar') ibar = name.find('Bar')
if ibar > 0 and ibar < len(name)-3: 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 # cleanup "_"s
while True: while True:
...@@ -158,9 +158,12 @@ def c_identifier_camel(name): ...@@ -158,9 +158,12 @@ def c_identifier_camel(name):
def build_pythia_db(filename, classnames): def build_pythia_db(filename, classnames):
particle_db = OrderedDict() particle_db = OrderedDict()
counter = itertools.count(0)
for (pdg, name, mass, electric_charge, antiName) in parse(filename): for (pdg, name, mass, electric_charge, antiName) in parse(filename):
c_id = "unknown" c_id = "Unknown"
if pdg in classnames: if pdg in classnames:
c_id = classnames[pdg] c_id = classnames[pdg]
else: else:
...@@ -171,7 +174,8 @@ def build_pythia_db(filename, classnames): ...@@ -171,7 +174,8 @@ def build_pythia_db(filename, classnames):
"antiName" : antiName, "antiName" : antiName,
"pdg" : pdg, "pdg" : pdg,
"mass" : mass, # in GeV "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 return particle_db
...@@ -261,7 +265,7 @@ def gen_classes(pythia_db): ...@@ -261,7 +265,7 @@ def gen_classes(pythia_db):
for cname in pythia_db: for cname in pythia_db:
antiP = 'unknown' antiP = 'Unknown'
for cname_anti in pythia_db: for cname_anti in pythia_db:
if (pythia_db[cname_anti]['name'] == pythia_db[cname]['antiName']): if (pythia_db[cname_anti]['name'] == pythia_db[cname]['antiName']):
antiP = cname_anti antiP = cname_anti
...@@ -282,7 +286,7 @@ def gen_classes(pythia_db): ...@@ -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::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 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 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 GetAntiParticle() { return AntiType; }\n"
string += " static constexpr Code Type = Code::" + cname + ";\n" string += " static constexpr Code Type = Code::" + cname + ";\n"
string += " static constexpr Code AntiType = Code::" + antiP + ";\n" string += " static constexpr Code AntiType = Code::" + antiP + ";\n"
...@@ -312,6 +316,14 @@ def inc_end(): ...@@ -312,6 +316,14 @@ def inc_end():
return string return string
###################################################################
#
# Serialize pythia_db into file
#
def serialize_pythia_db(pythia_db, file):
pickle.dump(pythia_db, file)
################################################################### ###################################################################
# #
# Main function # Main function
...@@ -320,7 +332,7 @@ def inc_end(): ...@@ -320,7 +332,7 @@ def inc_end():
if __name__ == "__main__": if __name__ == "__main__":
if len(sys.argv) != 3: 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) sys.exit(1)
names = class_names(sys.argv[2]) names = class_names(sys.argv[2])
...@@ -328,12 +340,6 @@ if __name__ == "__main__": ...@@ -328,12 +340,6 @@ if __name__ == "__main__":
print("\n pdxml_reader.py: Automatically produce particle-properties from PYTHIA8 xml file\n") 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: with open("GeneratedParticleProperties.inc", "w") as f:
print(inc_start(), file=f) print(inc_start(), file=f)
print(gen_internal_enum(pythia_db), file=f) print(gen_internal_enum(pythia_db), file=f)
...@@ -341,7 +347,5 @@ if __name__ == "__main__": ...@@ -341,7 +347,5 @@ if __name__ == "__main__":
print(gen_classes(pythia_db), file=f) print(gen_classes(pythia_db), file=f)
print(inc_end(), 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)
...@@ -48,6 +48,6 @@ namespace corsika::stack { ...@@ -48,6 +48,6 @@ namespace corsika::stack {
int GetIndex() const { return GetIterator().GetIndex(); } int GetIndex() const { return GetIterator().GetIndex(); }
}; };
}; // namespace corsika::stack } // namespace corsika::stack
#endif #endif
...@@ -80,7 +80,7 @@ namespace corsika::stack { ...@@ -80,7 +80,7 @@ namespace corsika::stack {
protected: protected:
void IncrementSize() { void IncrementSize() {
fDataE.push_back(0_GeV); fDataE.push_back(0_GeV);
fDataPID.push_back(Code::unknown); fDataPID.push_back(Code::Unknown);
} }
void DecrementSize() { void DecrementSize() {
if (fDataE.size() > 0) { if (fDataE.size() > 0) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment