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 (
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
......
......@@ -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"/>
......
......@@ -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)];
}
......
......@@ -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)
......@@ -48,6 +48,6 @@ namespace corsika::stack {
int GetIndex() const { return GetIterator().GetIndex(); }
};
}; // namespace corsika::stack
} // namespace corsika::stack
#endif
......@@ -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) {
......
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