IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 2a24b038 authored by ralfulrich's avatar ralfulrich Committed by Ralf Ulrich
Browse files

adapted InteractionCounter

parent 843c0309
No related branches found
No related tags found
1 merge request!387Hadronic model interface overhaul
...@@ -18,22 +18,20 @@ namespace corsika { ...@@ -18,22 +18,20 @@ namespace corsika {
template <class TCountedProcess> template <class TCountedProcess>
template <typename TSecondaryView> template <typename TSecondaryView>
inline void InteractionCounter<TCountedProcess>::doInteraction(TSecondaryView& view) { inline void InteractionCounter<TCountedProcess>::doInteraction(
auto const projectile = view.getProjectile(); TSecondaryView& view, Code const projectileId, Code const targetId,
auto const massNumber = projectile.getNode() FourMomentum const& projectileP4, FourMomentum const& targetP4) {
->getModelProperties() size_t const massNumber = is_nucleus(targetId) ? get_nucleus_A(targetId) : 1;
.getNuclearComposition()
.getAverageMassNumber();
auto const massTarget = massNumber * constants::nucleonMass; auto const massTarget = massNumber * constants::nucleonMass;
histogram_.fill(projectile.getPID(), projectile.getEnergy(), massTarget); histogram_.fill(projectileId, projectileP4.getTimeLikeComponent(), massTarget);
process_.doInteraction(view); process_.doInteraction(view, projectileId, targetId, projectileP4, targetP4);
} }
template <class TCountedProcess> template <class TCountedProcess>
template <typename TParticle> inline CrossSectionType InteractionCounter<TCountedProcess>::getCrossSection(
inline GrammageType InteractionCounter<TCountedProcess>::getInteractionLength( Code const projectileId, Code const targetId, FourMomentum const& projectileP4,
TParticle const& particle) const { FourMomentum const& targetP4) const {
return process_.getInteractionLength(particle); return process_.getCrossSection(projectileId, targetId, projectileP4, targetP4);
} }
template <class TCountedProcess> template <class TCountedProcess>
......
...@@ -43,7 +43,7 @@ namespace corsika::urqmd { ...@@ -43,7 +43,7 @@ namespace corsika::urqmd {
throw std::runtime_error("UrQMD projectile is not a compatible hadron."); throw std::runtime_error("UrQMD projectile is not a compatible hadron.");
} }
if (!is_nucleus(targetId)) { if (!is_nucleus(targetId)) {
throw std::runtime_error("UrQMD target is not a nucleus."); throw std::runtime_error("UrQMD target is not a nucleus .");
} }
} }
......
...@@ -10,24 +10,25 @@ ...@@ -10,24 +10,25 @@
#include <corsika/framework/process/InteractionHistogram.hpp> #include <corsika/framework/process/InteractionHistogram.hpp>
#include <corsika/framework/process/InteractionProcess.hpp> #include <corsika/framework/process/InteractionProcess.hpp>
#include <corsika/framework/geometry/FourVector.hpp>
namespace corsika { namespace corsika {
/*! /**
@ingroup Processes * @ingroup Processes
@{ * @{
*
* Wrapper around an InteractionProcess that fills histograms of the number * Wrapper around an InteractionProcess that fills histograms of the number
* of calls to `doInteraction()` binned in projectile energy (both in * of calls to `doInteraction()` binned in projectile energy (both in
* lab and center-of-mass frame) and species * lab and center-of-mass frame) and species.
* *
* Use by wrapping a normal InteractionProcess * Use by wrapping a normal InteractionProcess:
* @code{.cpp} * @code{.cpp}
* InteractionProcess collision1; * InteractionProcess collision1;
* InteractionClounter<collision1> counted_collision1; * InteractionClounter<collision1> counted_collision1;
* @endcode * @endcode
*
*/ */
template <class TCountedProcess> template <class TCountedProcess>
class InteractionCounter class InteractionCounter
: public InteractionProcess<InteractionCounter<TCountedProcess>> { : public InteractionProcess<InteractionCounter<TCountedProcess>> {
...@@ -35,17 +36,24 @@ namespace corsika { ...@@ -35,17 +36,24 @@ namespace corsika {
public: public:
InteractionCounter(TCountedProcess& process); InteractionCounter(TCountedProcess& process);
//! wrapper around internall process doInteraction /**
* Wrapper around internal process doInteraction.
*/
template <typename TSecondaryView> template <typename TSecondaryView>
void doInteraction(TSecondaryView& view); void doInteraction(TSecondaryView& view, Code const, Code const, FourMomentum const&,
FourMomentum const&);
///! returns internal process getInteractionLength /**
template <typename TParticle> * Wrapper around internal process getCrossSection.
GrammageType getInteractionLength(TParticle const& particle) const; */
CrossSectionType getCrossSection(Code const, Code const, FourMomentum const&,
FourMomentum const&) const;
/** returns the filles histograms /**
@return InteractionHistogram, which contains the histogram data * returns the filles histograms.
*/ *
* @return InteractionHistogram, which contains the histogram data
*/
InteractionHistogram const& getHistogram() const; InteractionHistogram const& getHistogram() const;
private: private:
......
...@@ -105,7 +105,6 @@ void modular() { ...@@ -105,7 +105,6 @@ void modular() {
int main() { int main() {
logging::set_level(logging::level::info); logging::set_level(logging::level::info);
corsika_logger->set_pattern("[%n:%^%-8l%$] custom pattern: %v");
std::cout << "staticsequence_example" << std::endl; std::cout << "staticsequence_example" << std::endl;
......
...@@ -7,17 +7,11 @@ ...@@ -7,17 +7,11 @@
*/ */
#include <corsika/framework/process/InteractionCounter.hpp> #include <corsika/framework/process/InteractionCounter.hpp>
#include <corsika/media/Environment.hpp>
#include <corsika/media/HomogeneousMedium.hpp>
#include <corsika/media/NuclearComposition.hpp>
#include <corsika/framework/geometry/Point.hpp> #include <corsika/framework/geometry/Point.hpp>
#include <corsika/framework/geometry/RootCoordinateSystem.hpp> #include <corsika/framework/geometry/RootCoordinateSystem.hpp>
#include <corsika/framework/geometry/Vector.hpp> #include <corsika/framework/geometry/Vector.hpp>
#include <corsika/framework/core/PhysicalUnits.hpp> #include <corsika/framework/core/PhysicalUnits.hpp>
#include <SetupTestStack.hpp>
#include <SetupTestEnvironment.hpp>
#include <catch2/catch.hpp> #include <catch2/catch.hpp>
#include <numeric> #include <numeric>
...@@ -32,37 +26,46 @@ using namespace corsika; ...@@ -32,37 +26,46 @@ using namespace corsika;
const std::string refDataDir = std::string(REFDATADIR); // from cmake const std::string refDataDir = std::string(REFDATADIR); // from cmake
struct DummyProcess { struct DummyProcess {
template <typename TParticle>
GrammageType getInteractionLength(TParticle const&) { CrossSectionType getCrossSection(Code const, Code const, FourMomentum const&,
return 100_g / 1_cm / 1_cm; FourMomentum const&) {
return 100_mb;
} }
template <typename TParticle> template <typename TParticle>
void doInteraction(TParticle&) {} void doInteraction(TParticle&, Code const, Code const, FourMomentum const&,
FourMomentum const&) {}
}; };
TEST_CASE("InteractionCounter", "[process]") { struct DummyOutput {
/* can do nothing */
};
TEST_CASE("InteractionCounter", "process") {
logging::set_level(logging::level::info); logging::set_level(logging::level::info);
DummyProcess d; DummyProcess d;
InteractionCounter countedProcess(d); InteractionCounter countedProcess(d);
SECTION("getInteractionLength") { auto const rootCS = get_root_CoordinateSystem();
CHECK(countedProcess.getInteractionLength(nullptr) == 100_g / 1_cm / 1_cm); DummyOutput output;
}
auto [env, csPtr, nodePtr] = setup::testing::setup_environment(Code::Oxygen); SECTION("cross section pass-through") {
[[maybe_unused]] auto& env_dummy = env; CHECK(countedProcess.getCrossSection(
Code::Oxygen, Code::Proton, {10_GeV, {rootCS, {0_eV, 0_eV, 0_eV}}},
{10_GeV, {rootCS, {0_eV, 0_eV, 0_eV}}}) == 100_mb);
}
SECTION("DoInteraction nucleus") { SECTION("doInteraction nucleus") {
unsigned short constexpr A = 14, Z = 7; unsigned short constexpr A = 14, Z = 7;
auto [stackPtr, secViewPtr] = setup::testing::setup_stack( Code const pid = get_nucleus_code(A, Z);
get_nucleus_code(A, Z), 105_TeV, (setup::Environment::BaseNodeType* const)nodePtr,
*csPtr);
CHECK(stackPtr->getEntries() == 1);
CHECK(secViewPtr->getEntries() == 0);
countedProcess.doInteraction(*secViewPtr); countedProcess.doInteraction(
output, pid, Code::Oxygen,
{sqrt(static_pow<2>(105_TeV) + static_pow<2>(get_mass(pid))),
{rootCS, {105_TeV, 0_GeV, 0_GeV}}},
{Oxygen::mass, {rootCS, {0_eV, 0_eV, 0_eV}}});
auto const& h = countedProcess.getHistogram().labHist(); auto const& h = countedProcess.getHistogram().labHist();
CHECK(h.at(h.axis(0).index(1'000'070'140), h.axis(1).index(1.05e14)) == 1); CHECK(h.at(h.axis(0).index(1'000'070'140), h.axis(1).index(1.05e14)) == 1);
...@@ -99,14 +102,14 @@ TEST_CASE("InteractionCounter", "[process]") { ...@@ -99,14 +102,14 @@ TEST_CASE("InteractionCounter", "[process]") {
} }
} }
SECTION("DoInteraction Lambda") { SECTION("doInteraction Lambda") {
auto constexpr code = Code::Lambda0; auto constexpr pid = Code::Lambda0;
auto [stackPtr, secViewPtr] = setup::testing::setup_stack(
code, 105_TeV, (setup::Environment::BaseNodeType* const)nodePtr, *csPtr);
CHECK(stackPtr->getEntries() == 1);
CHECK(secViewPtr->getEntries() == 0);
countedProcess.doInteraction(*secViewPtr); countedProcess.doInteraction(
output, pid, Code::Oxygen,
{sqrt(static_pow<2>(105_TeV) + static_pow<2>(get_mass(pid))),
{rootCS, {105_TeV, 0_GeV, 0_GeV}}},
{Oxygen::mass, {rootCS, {0_eV, 0_eV, 0_eV}}});
auto const& h = countedProcess.getHistogram().labHist(); auto const& h = countedProcess.getHistogram().labHist();
CHECK(h.at(h.axis(0).index(3122), h.axis(1).index(1.05e14)) == 1); CHECK(h.at(h.axis(0).index(3122), h.axis(1).index(1.05e14)) == 1);
......
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