diff --git a/Processes/Sibyll/ParticleConversion.h b/Processes/Sibyll/ParticleConversion.h index 66d589887306d45707836f90b4223cdfd6768bd8..e0ef48ecfca2c2c6f07678783a3354f38c195f9d 100644 --- a/Processes/Sibyll/ParticleConversion.h +++ b/Processes/Sibyll/ParticleConversion.h @@ -20,8 +20,8 @@ namespace corsika::process::sibyll { - enum class Code : int8_t; - using SibyllCodeIntType = std::underlying_type<Code>::type; + enum class SibyllCode : int8_t; + using SibyllCodeIntType = std::underlying_type<SibyllCode>::type; #include <corsika/process/sibyll/Generated.inc> @@ -33,12 +33,12 @@ namespace corsika::process::sibyll { return canInteract[static_cast<corsika::particles::CodeIntType>(pCode)]; } - Code constexpr ConvertToSibyll(corsika::particles::Code pCode) { + SibyllCode constexpr ConvertToSibyll(corsika::particles::Code pCode) { //~ assert(handledBySibyll(pCode)); - return static_cast<Code>(corsika2sibyll[static_cast<corsika::particles::CodeIntType>(pCode)]); + return static_cast<SibyllCode>(corsika2sibyll[static_cast<corsika::particles::CodeIntType>(pCode)]); } - corsika::particles::Code constexpr ConvertFromSibyll(Code pCode) { + corsika::particles::Code constexpr ConvertFromSibyll(SibyllCode pCode) { return sibyll2corsika[static_cast<SibyllCodeIntType>(pCode) - minSibyll]; } diff --git a/Processes/Sibyll/code_generator.py b/Processes/Sibyll/code_generator.py index aff36785e8c2e629d30092c1e43300fff6b7728b..784b8e7d87b0f51697674a02f2561aa95ac1ed52 100755 --- a/Processes/Sibyll/code_generator.py +++ b/Processes/Sibyll/code_generator.py @@ -27,21 +27,23 @@ def read_sibyll_codes(filename, pythia_db): for line in f: line = line.strip() if line[0] == '#': - continue - identifier, sib_code = line.split() + continue + identifier, sib_code, canInteractFlag = line.split() try: pythia_db[identifier]["sibyll_code"] = int(sib_code) + pythia_db[identifier]["sibyll_canInteract"] = int(canInteractFlag) except KeyError as e: raise Exception("Identifier '{:s}' not found in pythia_db".format(identifier)) + # generates the enum to access sibyll particles by readable names def generate_sibyll_enum(pythia_db): - output = "enum class Code : int8_t {\n" - for identifier, d in pythia_db.items(): - if d.get('sibyll_code') != None: - output += " {:s} = {:d},\n".format(identifier, d['sibyll_code']) + output = "enum class SibyllCode : int8_t {\n" + for identifier, pData in pythia_db.items(): + if pData.get('sibyll_code') != None: + output += " {:s} = {:d},\n".format(identifier, pData['sibyll_code']) output += "};\n" return output @@ -50,8 +52,8 @@ def generate_sibyll_enum(pythia_db): # generates the look-up table to convert corsika codes to sibyll codes def generate_corsika2sibyll(pythia_db): string = "std::array<SibyllCodeIntType, {:d}> constexpr corsika2sibyll = {{".format(len(pythia_db)) - for identifier, d in pythia_db.items(): - sibCode = d.get("sibyll_code", 0) + for identifier, pData in pythia_db.items(): + sibCode = pData.get("sibyll_code", 0) string += " {:d}, // {:s}\n".format(sibCode, identifier if sibCode else identifier + " (not implemented in SIBYLL)") string += "};\n" return string @@ -88,14 +90,14 @@ def generate_sibyll2corsika(pythia_db) : # generates the bitset for the flag whether Sibyll knows the particle -def generate_handles_particle(pythia_db): +def generate_known_particle(pythia_db): num_particles = len(pythia_db) num_bytes = num_particles // 32 + 1 - string = "Bitset2::bitset2<{:d}> constexpr handleable{{ std::array<uint32_t, {:d}>{{{{\n".format(num_particles, num_bytes) + string = "Bitset2::bitset2<{:d}> constexpr isKnown{{ std::array<uint32_t, {:d}>{{{{\n".format(num_particles, num_bytes) numeric = 0 - for identifier, d in reversed(pythia_db.items()): - handledBySibyll = int("sibyll_code" in d) & 0x1 + for identifier, pData in reversed(pythia_db.items()): + handledBySibyll = int("sibyll_code" in pData) & 0x1 numeric = (numeric << 1) | handledBySibyll while numeric != 0: @@ -105,6 +107,28 @@ def generate_handles_particle(pythia_db): string += "}}};\n" return string + + + +# generates the bitset for the flag whether Sibyll can use particle as projectile +def generate_interacting_particle(pythia_db): + num_particles = len(pythia_db) + num_bytes = num_particles // 32 + 1 + string = "Bitset2::bitset2<{:d}> constexpr canInteract{{ std::array<uint32_t, {:d}>{{{{\n".format(num_particles, num_bytes) + + numeric = 0 + for identifier, pData in reversed(pythia_db.items()): + if 'sibyll_canInteract' in pData: + can = int(pData["sibyll_canInteract"]) & 0x1 + numeric = (numeric << 1) | can + + while numeric != 0: + low = numeric & 0xFFFFFFFF + numeric = numeric >> 32 + string += " 0x{:0x},\n".format(low) + + string += "}}};\n" + return string @@ -122,5 +146,5 @@ if __name__ == "__main__": print("// this file is automatically generated\n// edit at your own risk!\n", file=f) print(generate_sibyll_enum(pythia_db), file=f) print(generate_corsika2sibyll(pythia_db), file=f) - print(generate_handles_particle(pythia_db), file=f) + print(generate_known_particle(pythia_db), file=f) print(generate_sibyll2corsika(pythia_db), file=f)