diff --git a/Processes/Sibyll/ParticleConversion.h b/Processes/Sibyll/ParticleConversion.h index e0ef48ecfca2c2c6f07678783a3354f38c195f9d..9d7227ce97b324ba33977ce351c476cb1a2fe0c9 100644 --- a/Processes/Sibyll/ParticleConversion.h +++ b/Processes/Sibyll/ParticleConversion.h @@ -45,6 +45,10 @@ namespace corsika::process::sibyll { int ConvertToSibyllRaw(corsika::particles::Code pCode){ return (int)static_cast<corsika::process::sibyll::SibyllCodeIntType>( corsika::process::sibyll::ConvertToSibyll( pCode ) ); } + + int GetSibyllXSCode(corsika::particles::Code pCode) { + return corsika2sibyllXStype[static_cast<corsika::particles::CodeIntType>(pCode)]; + } } // namespace corsika::process::sibyll diff --git a/Processes/Sibyll/code_generator.py b/Processes/Sibyll/code_generator.py index a2929fdaa1fca5e544f153a197af02fbdc4e1649..77c1f5dd8216ad48ebf5c4aa476ef57695bb7fea 100755 --- a/Processes/Sibyll/code_generator.py +++ b/Processes/Sibyll/code_generator.py @@ -32,7 +32,7 @@ def read_sibyll_codes(filename, pythia_db): try: pythia_db[identifier]["sibyll_code"] = int(sib_code) pythia_db[identifier]["sibyll_canInteract"] = int(canInteractFlag) - pythia_db[identifier]["xsType"] = int(xsType) + pythia_db[identifier]["sibyll_xsType"] = int(xsType) except KeyError as e: raise Exception("Identifier '{:s}' not found in pythia_db".format(identifier)) @@ -52,7 +52,7 @@ 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)) + string = "std::array<SibyllCodeIntType, {:d}> constexpr corsika2sibyll = {{\n".format(len(pythia_db)) 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)") @@ -61,13 +61,27 @@ def generate_corsika2sibyll(pythia_db): +# generates the look-up table to convert corsika codes to sibyll codes +def generate_corsika2sibyll_xsType(pythia_db): + string = "std::array<int, {:d}> constexpr corsika2sibyllXStype = {{\n".format(len(pythia_db)) + for identifier, pData in pythia_db.items(): + sibCodeXS = pData.get("sibyll_xsType", -1) + string += " {:d}, // {:s}\n".format(sibCodeXS, identifier if sibCodeXS else identifier + " (not implemented in SIBYLL)") + string += "};\n" + return string + + # generates the look-up table to convert sibyll codes to corsika codes def generate_sibyll2corsika(pythia_db) : + string = "" + minID = 0 for identifier, pData in pythia_db.items() : if 'sibyll_code' in pData: minID = min(minID, pData['sibyll_code']) - + + string += "SibyllCodeIntType constexpr minSibyll = {:d};\n\n".format(minID) + pDict = {} for identifier, pData in pythia_db.items() : if 'sibyll_code' in pData: @@ -75,7 +89,7 @@ def generate_sibyll2corsika(pythia_db) : pDict[sib_code] = identifier nPart = max(pDict.keys()) - min(pDict.keys()) + 1 - string = "std::array<corsika::particles::Code, {:d}> sibyll2corsika = {{\n".format(nPart) + string += "std::array<corsika::particles::Code, {:d}> sibyll2corsika = {{\n".format(nPart) for iPart in range(nPart) : if iPart in pDict: @@ -85,7 +99,6 @@ def generate_sibyll2corsika(pythia_db) : string += " corsika::particles::Code::{:s}, \n".format(identifier) string += "};\n" - string += "SibyllCodeIntType constexpr minSibyll = {:d};\n".format(minID) return string @@ -116,12 +129,15 @@ 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) + #string = "std::array<bool, {:d}> constexpr corsika2sibyll = {{\n".format(num_particles) numeric = 0 for identifier, pData in reversed(pythia_db.items()): + can = 0 if 'sibyll_canInteract' in pData: - can = int(pData["sibyll_canInteract"]) & 0x1 - numeric = (numeric << 1) | can + if pData['sibyll_canInteract'] > 0: + can = 0x1 + numeric = (numeric << 1) | can while numeric != 0: low = numeric & 0xFFFFFFFF @@ -143,6 +159,8 @@ if __name__ == "__main__": pythia_db = load_pythiadb(sys.argv[1]) read_sibyll_codes(sys.argv[2], pythia_db) + print (str(pythia_db)) + with open("Generated.inc", "w") as f: print("// this file is automatically generated\n// edit at your own risk!\n", file=f) print(generate_sibyll_enum(pythia_db), file=f) @@ -150,3 +168,4 @@ if __name__ == "__main__": print(generate_known_particle(pythia_db), file=f) print(generate_sibyll2corsika(pythia_db), file=f) print(generate_interacting_particle(pythia_db), file=f) + print(generate_corsika2sibyll_xsType(pythia_db), file=f) diff --git a/Processes/Sibyll/testSibyll.cc b/Processes/Sibyll/testSibyll.cc index c811327706efced8ef430a37ebb1fb333ddd4337..20cbedf03d20b3f1c210c3c2e69a473c6c05c39e 100644 --- a/Processes/Sibyll/testSibyll.cc +++ b/Processes/Sibyll/testSibyll.cc @@ -17,6 +17,8 @@ // cpp file #include <catch2/catch.hpp> +#include <iostream> +using namespace std; using namespace corsika; TEST_CASE("Sibyll", "[processes]") { @@ -30,23 +32,29 @@ TEST_CASE("Sibyll", "[processes]") { REQUIRE(process::sibyll::ConvertToSibyll(corsika::particles::Electron::GetCode()) == process::sibyll::SibyllCode::Electron); REQUIRE(process::sibyll::ConvertToSibyllRaw(corsika::particles::Proton::GetCode()) == - 13 ); + 13); } - SECTION("handledBySibyll") { + SECTION("KnownBySibyll") { REQUIRE(process::sibyll::KnownBySibyll(corsika::particles::Electron::GetCode())); REQUIRE_FALSE( process::sibyll::KnownBySibyll(corsika::particles::XiPrimeC0::GetCode())); } - SECTION("cross-section type") { + SECTION("canInteractInSibyll") { REQUIRE(process::sibyll::CanInteract(corsika::particles::Proton::GetCode())); - REQUIRE(process::sibyll::CanInteract(corsika::particles::XiCPlus::GetCode())); + REQUIRE(process::sibyll::CanInteract(corsika::particles::Code::XiCPlus)); - REQUIRE_FALSE( - process::sibyll::CanInteract(corsika::particles::Electron::GetCode())); - REQUIRE_FALSE( - process::sibyll::CanInteract(corsika::particles::SigmaC0::GetCode())); + REQUIRE_FALSE(process::sibyll::CanInteract(corsika::particles::Electron::GetCode())); + REQUIRE_FALSE(process::sibyll::CanInteract(corsika::particles::SigmaC0::GetCode())); + } + + SECTION("cross-section type") { + + REQUIRE(process::sibyll::GetSibyllXSCode(corsika::particles::Code::Electron) == 0); + REQUIRE(process::sibyll::GetSibyllXSCode(corsika::particles::Code::K0Long) == 3); + REQUIRE(process::sibyll::GetSibyllXSCode(corsika::particles::Code::SigmaPlus) == 1); + REQUIRE(process::sibyll::GetSibyllXSCode(corsika::particles::Code::PiMinus) == 2); } }