IAP GITLAB

Skip to content
Snippets Groups Projects
Commit c6a35928 authored by ralfulrich's avatar ralfulrich
Browse files

fixed the canInteract, knownby flags for sibyll, and added the xs-type code

parent 59304d3d
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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)
......@@ -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);
}
}
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