IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 17cee635 authored by Maximilian Reininghaus's avatar Maximilian Reininghaus :vulcan:
Browse files

"transparent" observation plane

parent 5620d8b0
No related branches found
No related tags found
No related merge requests found
...@@ -16,7 +16,7 @@ set ( ...@@ -16,7 +16,7 @@ set (
add_library (ProcessObservationPlane STATIC ${MODEL_SOURCES}) add_library (ProcessObservationPlane STATIC ${MODEL_SOURCES})
CORSIKA_COPY_HEADERS_TO_NAMESPACE (ProcessObservationPlane ${MODEL_NAMESPACE} ${MODEL_HEADERS}) CORSIKA_COPY_HEADERS_TO_NAMESPACE (ProcessObservationPlane ${MODEL_NAMESPACE} ${MODEL_HEADERS})
# target dependencies on other libraries (also the header onlys) #target dependencies on other libraries(also the header onlys)
target_link_libraries ( target_link_libraries (
ProcessObservationPlane ProcessObservationPlane
CORSIKAgeometry CORSIKAgeometry
...@@ -32,8 +32,8 @@ target_include_directories ( ...@@ -32,8 +32,8 @@ target_include_directories (
install (FILES ${MODEL_HEADERS} DESTINATION include/${MODEL_NAMESPACE}) install (FILES ${MODEL_HEADERS} DESTINATION include/${MODEL_NAMESPACE})
# -------------------- #-- -- -- -- -- -- -- -- -- --
# code unit testing #code unit testing
CORSIKA_ADD_TEST(testObservationPlane) CORSIKA_ADD_TEST(testObservationPlane)
target_link_libraries ( target_link_libraries (
testObservationPlane testObservationPlane
...@@ -41,4 +41,3 @@ target_link_libraries ( ...@@ -41,4 +41,3 @@ target_link_libraries (
CORSIKAstackinterface CORSIKAstackinterface
CORSIKAthirdparty # for catch2 CORSIKAthirdparty # for catch2
) )
...@@ -15,36 +15,48 @@ ...@@ -15,36 +15,48 @@
using namespace corsika::process::observation_plane; using namespace corsika::process::observation_plane;
using namespace corsika::units::si; using namespace corsika::units::si;
ObservationPlane::ObservationPlane(geometry::Plane const& vObsPlane, ObservationPlane::ObservationPlane(geometry::Plane const& obsPlane,
std::string const& vFilename) std::string const& filename, bool deleteOnHit)
: fObsPlane(vObsPlane) : plane_(obsPlane)
, fOutputStream(vFilename) { , outputStream_(filename)
fOutputStream << "#PDG code, energy / eV, distance to center / m" << std::endl; , deleteOnHit_(deleteOnHit) {
outputStream_ << "#PDG code, energy / eV, distance to center / m" << std::endl;
} }
corsika::process::EProcessReturn ObservationPlane::DoContinuous( corsika::process::EProcessReturn ObservationPlane::DoContinuous(
setup::Stack::ParticleType const& vParticle, setup::Trajectory const& vTrajectory) { setup::Stack::ParticleType const& particle, setup::Trajectory const& trajectory) {
TimeType const timeOfIntersection =
(plane_.GetCenter() - trajectory.GetR0()).dot(plane_.GetNormal()) /
trajectory.GetV0().dot(plane_.GetNormal());
if (fObsPlane.IsAbove(vTrajectory.GetPosition(1.0001))) { if (timeOfIntersection < TimeType::zero()) { return process::EProcessReturn::eOk; }
if (plane_.IsAbove(trajectory.GetR0()) == plane_.IsAbove(trajectory.GetPosition(1))) {
return process::EProcessReturn::eOk; return process::EProcessReturn::eOk;
} }
fOutputStream << static_cast<int>(particles::GetPDG(vParticle.GetPID())) << ' ' outputStream_ << static_cast<int>(particles::GetPDG(particle.GetPID())) << ' '
<< vParticle.GetEnergy() * (1 / 1_eV) << ' ' << particle.GetEnergy() * (1 / 1_eV) << ' '
<< (vTrajectory.GetPosition(1) - fObsPlane.GetCenter()).norm() / 1_m << (trajectory.GetPosition(1) - plane_.GetCenter()).norm() / 1_m
<< std::endl; << std::endl;
return process::EProcessReturn::eParticleAbsorbed; if (deleteOnHit_) {
return process::EProcessReturn::eParticleAbsorbed;
} else {
return process::EProcessReturn::eOk;
}
} }
LengthType ObservationPlane::MaxStepLength(setup::Stack::ParticleType const&, LengthType ObservationPlane::MaxStepLength(setup::Stack::ParticleType const&,
setup::Trajectory const& vTrajectory) { setup::Trajectory const& trajectory) {
if (!fObsPlane.IsAbove(vTrajectory.GetR0())) { TimeType const timeOfIntersection =
(plane_.GetCenter() - trajectory.GetR0()).dot(plane_.GetNormal()) /
trajectory.GetV0().dot(plane_.GetNormal());
if (timeOfIntersection < TimeType::zero()) {
return std::numeric_limits<double>::infinity() * 1_m; return std::numeric_limits<double>::infinity() * 1_m;
} }
auto const pointOfIntersection = vTrajectory.GetPosition( auto const pointOfIntersection = trajectory.GetPosition(timeOfIntersection);
(fObsPlane.GetCenter() - vTrajectory.GetR0()).dot(fObsPlane.GetNormal()) / return (trajectory.GetR0() - pointOfIntersection).norm() * 1.0001;
vTrajectory.GetV0().dot(fObsPlane.GetNormal()));
return (vTrajectory.GetR0() - pointOfIntersection).norm();
} }
...@@ -29,7 +29,7 @@ namespace corsika::process::observation_plane { ...@@ -29,7 +29,7 @@ namespace corsika::process::observation_plane {
class ObservationPlane : public corsika::process::ContinuousProcess<ObservationPlane> { class ObservationPlane : public corsika::process::ContinuousProcess<ObservationPlane> {
public: public:
ObservationPlane(geometry::Plane const& vObsPlane, std::string const& vFilename); ObservationPlane(geometry::Plane const&, std::string const&, bool = true);
void Init() {} void Init() {}
corsika::process::EProcessReturn DoContinuous( corsika::process::EProcessReturn DoContinuous(
...@@ -41,8 +41,9 @@ namespace corsika::process::observation_plane { ...@@ -41,8 +41,9 @@ namespace corsika::process::observation_plane {
corsika::setup::Trajectory const& vTrajectory); corsika::setup::Trajectory const& vTrajectory);
private: private:
geometry::Plane const fObsPlane; geometry::Plane const plane_;
std::ofstream fOutputStream; std::ofstream outputStream_;
bool const deleteOnHit_;
}; };
} // namespace corsika::process::observation_plane } // namespace corsika::process::observation_plane
......
...@@ -41,7 +41,7 @@ TEST_CASE("ContinuousProcess interface", "[proccesses][observation_plane]") { ...@@ -41,7 +41,7 @@ TEST_CASE("ContinuousProcess interface", "[proccesses][observation_plane]") {
Vector<units::si::SpeedType::dimension_type> vec(rootCS, 0_m / second, 0_m / second, Vector<units::si::SpeedType::dimension_type> vec(rootCS, 0_m / second, 0_m / second,
-units::constants::c); -units::constants::c);
Line line(start, vec); Line line(start, vec);
Trajectory<Line> track(line, 10_m / units::constants::c); Trajectory<Line> track(line, 12_m / units::constants::c);
// setup particle stack, and add primary particle // setup particle stack, and add primary particle
setup::Stack stack; setup::Stack stack;
...@@ -64,14 +64,14 @@ TEST_CASE("ContinuousProcess interface", "[proccesses][observation_plane]") { ...@@ -64,14 +64,14 @@ TEST_CASE("ContinuousProcess interface", "[proccesses][observation_plane]") {
Plane const obsPlane(Point(rootCS, {0_m, 0_m, 0_m}), Plane const obsPlane(Point(rootCS, {0_m, 0_m, 0_m}),
Vector<dimensionless_d>(rootCS, {0., 0., 1.})); Vector<dimensionless_d>(rootCS, {0., 0., 1.}));
ObservationPlane obs(obsPlane, "particles.dat"); ObservationPlane obs(obsPlane, "particles.dat", true);
obs.Init(); obs.Init();
[[maybe_unused]] const LengthType length = obs.MaxStepLength(particle, track); const LengthType length = obs.MaxStepLength(particle, track);
[[maybe_unused]] const process::EProcessReturn ret = const process::EProcessReturn ret = obs.DoContinuous(particle, track);
obs.DoContinuous(particle, track);
SECTION("steplength") { REQUIRE(length == 10_m); } REQUIRE(length / 10_m == Approx(1).margin(1e-4));
REQUIRE(ret == process::EProcessReturn::eParticleAbsorbed);
/* /*
SECTION("horizontal plane") { SECTION("horizontal plane") {
...@@ -81,16 +81,18 @@ TEST_CASE("ContinuousProcess interface", "[proccesses][observation_plane]") { ...@@ -81,16 +81,18 @@ TEST_CASE("ContinuousProcess interface", "[proccesses][observation_plane]") {
*/ */
} }
SECTION("inclined plane") { SECTION("inclined plane") {}
SECTION("transparent plane") {
Plane const obsPlane(Point(rootCS, {0_m, 0_m, 0_m}), Plane const obsPlane(Point(rootCS, {0_m, 0_m, 0_m}),
Vector<dimensionless_d>(rootCS, {1., 1., 0.5})); Vector<dimensionless_d>(rootCS, {0., 0., 1.}));
ObservationPlane obs(obsPlane, "particles.dat"); ObservationPlane obs(obsPlane, "particles.dat", false);
obs.Init(); obs.Init();
[[maybe_unused]] const LengthType length = obs.MaxStepLength(particle, track); const LengthType length = obs.MaxStepLength(particle, track);
[[maybe_unused]] const process::EProcessReturn ret = const process::EProcessReturn ret = obs.DoContinuous(particle, track);
obs.DoContinuous(particle, track);
SECTION("steplength") { REQUIRE(length == 12_m); } REQUIRE(length / 10_m == Approx(1).margin(1e-4));
REQUIRE(ret == process::EProcessReturn::eOk);
} }
} }
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