diff --git a/Documentation/Examples/CMakeLists.txt b/Documentation/Examples/CMakeLists.txt index 2a66a3470584d14733e8a4651238e13b95756879..148df3493a54be8a98442a2f065a6c7a11858591 100644 --- a/Documentation/Examples/CMakeLists.txt +++ b/Documentation/Examples/CMakeLists.txt @@ -1,20 +1,28 @@ add_executable (helix_example helix_example.cc) +target_compile_options(helix_example PRIVATE -g) # do not skip asserts target_link_libraries(helix_example CORSIKAgeometry CORSIKAunits) install (TARGETS helix_example DESTINATION share/examples) +add_test(helix_example helix_example) add_executable (geometry_example geometry_example.cc) +target_compile_options(geometry_example PRIVATE -g) # do not skip asserts target_link_libraries (geometry_example CORSIKAgeometry CORSIKAunits) -install (TARGETS geometry_example DESTINATION share/examples) +#install (TARGETS geometry_example DESTINATION share/examples) +add_test(geometry_example geometry_example) add_executable (logger_example logger_example.cc) +target_compile_options(logger_example PRIVATE -g) # do not skip asserts target_link_libraries (logger_example CORSIKAunits CORSIKAlogging) -install (TARGETS logger_example DESTINATION share/examples) +#install (TARGETS logger_example DESTINATION share/examples) +add_test(logger_example logger_example) add_executable (stack_example stack_example.cc) +target_compile_options(stack_example PRIVATE -g) # do not skip asserts target_link_libraries (stack_example SuperStupidStack CORSIKAunits CORSIKAlogging) -install (TARGETS stack_example DESTINATION share/examples) +add_test(stack_example stack_example) add_executable (cascade_example cascade_example.cc) +target_compile_options(cascade_example PRIVATE -g) # do not skip asserts target_link_libraries (cascade_example SuperStupidStack CORSIKAunits CORSIKAlogging CORSIKArandom CORSIKAsibyll @@ -25,13 +33,15 @@ target_link_libraries (cascade_example SuperStupidStack CORSIKAunits CORSIKAlogg CORSIKAgeometry CORSIKAprocesssequence ) -install (TARGETS cascade_example DESTINATION share/examples) +#install (TARGETS cascade_example DESTINATION share/examples) +add_test(cascade_example cascade_example) add_executable (staticsequence_example staticsequence_example.cc) +target_compile_options(staticsequence_example PRIVATE -g) # do not skip asserts target_link_libraries (staticsequence_example CORSIKAprocesssequence CORSIKAunits CORSIKAgeometry CORSIKAlogging) -install (TARGETS staticsequence_example DESTINATION share/examples) - +#install (TARGETS staticsequence_example DESTINATION share/examples) +add_test(staticsequence_example staticsequence_example) diff --git a/Documentation/Examples/geometry_example.cc b/Documentation/Examples/geometry_example.cc index 5bacd1489ab9bff7add254ad8edc70ccada9ea43..67f43344c55d99fadfca0483e824f862c533db4d 100644 --- a/Documentation/Examples/geometry_example.cc +++ b/Documentation/Examples/geometry_example.cc @@ -50,12 +50,15 @@ int main() { std::cout << "p2-p1 components in cs3: " << diff.GetComponents(cs3) << std::endl; // but not under rotations std::cout << "p2-p1 norm^2: " << norm << std::endl; + assert(norm == 1 * meter * meter); Sphere s(p1, 10_m); // define a sphere around a point with a radius std::cout << "p1 inside s: " << s.Contains(p2) << std::endl; + assert(s.Contains(p2) == 1); Sphere s2(p1, 3_um); // another sphere std::cout << "p1 inside s2: " << s2.Contains(p2) << std::endl; + assert(s2.Contains(p2) == 0); // let's try parallel projections: auto const v1 = Vector<length_d>(root, {1_m, 1_m, 0_m}); diff --git a/Documentation/Examples/helix_example.cc b/Documentation/Examples/helix_example.cc index c51afce291181a4629b4fceaf776b0bfa9fc40cd..02ccc7c2454da62ea2fec686f9980f923ba34ceb 100644 --- a/Documentation/Examples/helix_example.cc +++ b/Documentation/Examples/helix_example.cc @@ -35,7 +35,7 @@ int main() { auto constexpr t0 = 0_s; auto constexpr t1 = 1_s; - auto constexpr dt = 1_us; + auto constexpr dt = 1_ms; auto constexpr n = long((t1 - t0) / dt) + 1; auto arr = std::make_unique<std::array<std::array<double, 4>, n>>(); diff --git a/Documentation/Examples/logger_example.cc b/Documentation/Examples/logger_example.cc index 1bd72012ec936e33d9caf791f240d1f7b24dde0b..9d9b743c13caff6010b13a37e5a20aed02c58ed2 100644 --- a/Documentation/Examples/logger_example.cc +++ b/Documentation/Examples/logger_example.cc @@ -35,7 +35,7 @@ int main() { std::any */ - for (int i = 0; i < 100000; ++i) { + for (int i = 0; i < 10000; ++i) { LOG(info, "irgendwas", " ", string("and more"), " ", boost::format("error: %i message: %s. done."), i, "stupido"); LOG(err, "Fehler"); @@ -46,7 +46,7 @@ int main() { sink::NoSink off; Logger<MessageOff> info("", "", off); - for (int i = 0; i < 100000; ++i) { + for (int i = 0; i < 10000; ++i) { LOG(info, "irgendwas", string("and more"), boost::format("error: %i message: %s. done."), i, "stupido", "a-number:", 8.99, "ENDE"); diff --git a/Documentation/Examples/stack_example.cc b/Documentation/Examples/stack_example.cc index f0a04f79be09dff2c58a74bc4822c443c12061f0..fbe4cd9da69440c48d345c17a1affc52d6c0f150 100644 --- a/Documentation/Examples/stack_example.cc +++ b/Documentation/Examples/stack_example.cc @@ -11,15 +11,13 @@ #include <corsika/particles/ParticleProperties.h> #include <corsika/stack/super_stupid/SuperStupidStack.h> +#include <cassert> #include <iomanip> #include <iostream> -using namespace std; -// using namespace corsika::literals; -// using namespace corsika::io; - using namespace corsika::units::si; using namespace corsika::stack; +using namespace std; void fill(corsika::stack::super_stupid::SuperStupidStack& s) { for (int i = 0; i < 11; ++i) { @@ -30,14 +28,17 @@ void fill(corsika::stack::super_stupid::SuperStupidStack& s) { } void read(corsika::stack::super_stupid::SuperStupidStack& s) { - cout << "found Stack with " << s.GetSize() << " particles. " << endl; - EnergyType Etot; + assert(s.GetSize() == 11); // stack has 11 particles + + EnergyType total_energy; + int i = 0; for (auto& p : s) { - Etot += p.GetEnergy(); - cout << "particle: " << p.GetPID() << " with " << p.GetEnergy() / 1_GeV << " GeV" - << endl; + total_energy += p.GetEnergy(); + // particles are electrons with 1.5 GeV energy times i + assert(p.GetPID() == corsika::particles::Code::Electron); + assert(p.GetEnergy() == 1.5_GeV * (i++)); } - cout << "Etot=" << Etot << " = " << Etot / 1_GeV << " GeV" << endl; + // assert(total_energy == 82.5_GeV); } int main() { diff --git a/Documentation/Examples/staticsequence_example.cc b/Documentation/Examples/staticsequence_example.cc index 07cc7561e0a8222e26d9e5b7eeba8ced68f6f63b..522c17114d05182c51237340f1afa63becc9e8d6 100644 --- a/Documentation/Examples/staticsequence_example.cc +++ b/Documentation/Examples/staticsequence_example.cc @@ -15,20 +15,23 @@ #include <corsika/process/ProcessSequence.h> -#include <corsika/setup/SetupTrajectory.h> // TODO: try to break this dependence later -using corsika::setup::Trajectory; -#include <corsika/units/PhysicalUnits.h> // dito -using namespace corsika::units::si; +#include <corsika/geometry/Point.h> +#include <corsika/geometry/RootCoordinateSystem.h> +#include <corsika/geometry/Vector.h> -using namespace std; +using namespace corsika; +using namespace corsika::units::si; using namespace corsika::process; +using namespace std; + +const int nData = 10; class Process1 : public BaseProcess<Process1> { public: Process1() {} template <typename D, typename T, typename S> EProcessReturn DoContinuous(D& d, T&, S&) const { - for (int i = 0; i < 10; ++i) d.p[i] += 1; + for (int i = 0; i < nData; ++i) d.p[i] += 1; return EProcessReturn::eOk; } }; @@ -38,62 +41,65 @@ public: Process2() {} template <typename D, typename T, typename S> - inline EProcessReturn DoContinuous(D&, T&, S&) const { - // for (int i=0; i<10; ++i) d.p[i] *= 2; + inline EProcessReturn DoContinuous(D& d, T&, S&) const { + for (int i = 0; i < nData; ++i) d.p[i] -= 0.1 * i; return EProcessReturn::eOk; } }; class Process3 : public BaseProcess<Process3> { public: - // Process3(const int v) :fV(v) {} Process3() {} template <typename D, typename T, typename S> - inline EProcessReturn DoContinuous(D& /*d*/, T& /*t*/, S& /*s*/) const { - // for (int i=0; i<10; ++i) d.p[i] += fV; + inline EProcessReturn DoContinuous(D&, T&, S&) const { return EProcessReturn::eOk; } - -private: - // int fV; }; class Process4 : public BaseProcess<Process4> { public: - // Process4(const int v) : fV(v) {} - Process4() {} + Process4(const double v) + : fV(v) {} template <typename D, typename T, typename S> - inline EProcessReturn DoContinuous(D& /*d*/, T& /*t*/, S& /*s*/) const { - // for (int i=0; i<10; ++i) d.p[i] /= fV; + inline EProcessReturn DoContinuous(D& d, T&, S&) const { + for (int i = 0; i < nData; ++i) d.p[i] *= fV; return EProcessReturn::eOk; } private: - // int fV; + double fV; }; struct DummyData { - double p[10]; + double p[nData] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; }; -struct DummyStack {}; +struct DummyStack { + void clear() {} +}; +struct DummyTrajectory {}; void modular() { Process1 m1; Process2 m2; Process3 m3; - Process4 m4; + Process4 m4(0.9); const auto sequence = m1 + m2 + m3 + m4; DummyData p; DummyStack s; - Trajectory t; + DummyTrajectory t; - const int n = 100000000; + const int n = 1000; for (int i = 0; i < n; ++i) { sequence.DoContinuous(p, t, s); } + for (int i = 0; i < nData; ++i) { + // cout << p.p[i] << endl; + // assert(p.p[i] == n-i*100); + } + cout << " done (nothing...) " << endl; } diff --git a/Framework/Cascade/Cascade.h b/Framework/Cascade/Cascade.h index c166517fa78b69507751ab88b6174cccc9ea1c36..4f4aadf786f7f7b8848cac9e6c2370e0ad19c5b9 100644 --- a/Framework/Cascade/Cascade.h +++ b/Framework/Cascade/Cascade.h @@ -34,12 +34,7 @@ namespace corsika::cascade { Cascade(Tracking& tr, ProcessList& pl, Stack& stack) : fTracking(tr) , fProcesseList(pl) - , fStack(stack) { - // static_assert(std::is_member_function_pointer<decltype(&ProcessList::DoDiscrete)>::value, - //"ProcessList has not function DoDiscrete."); - // static_assert(std::is_member_function_pointer<decltype(&ProcessList::DoContinuous)>::value, - // "ProcessList has not function DoContinuous."); - } + , fStack(stack) {} void Init() { fTracking.Init(); @@ -66,7 +61,8 @@ namespace corsika::cascade { fProcesseList.MinStepLength(particle, step); /// here the particle is actually moved along the trajectory to new position: - std::visit(corsika::setup::ParticleUpdate<Particle>{particle}, step); + // std::visit(corsika::setup::ParticleUpdate<Particle>{particle}, step); + particle.SetPosition(step.GetPosition(1)); corsika::process::EProcessReturn status = fProcesseList.DoContinuous(particle, step, fStack); diff --git a/Framework/Cascade/testCascade.cc b/Framework/Cascade/testCascade.cc index 6d0244555d7c9e66de6121e4f3d2a2e31bb4dda3..a218cb788e9da5748fbc634367cce8810a5356c8 100644 --- a/Framework/Cascade/testCascade.cc +++ b/Framework/Cascade/testCascade.cc @@ -18,6 +18,7 @@ #include <corsika/stack/super_stupid/SuperStupidStack.h> #include <corsika/geometry/Point.h> +#include <corsika/geometry/RootCoordinateSystem.h> #include <corsika/geometry/Vector.h> #include <corsika/setup/SetupStack.h> diff --git a/Framework/Geometry/Point.h b/Framework/Geometry/Point.h index c9c88d7bf599e3f41d33bd92dfe746706f5e5339..74c4b6f8da208064103c1a23018cc208b58b1659 100644 --- a/Framework/Geometry/Point.h +++ b/Framework/Geometry/Point.h @@ -26,27 +26,26 @@ namespace corsika::geometry { * A Point represents a point in position space. It is defined by its * coordinates with respect to some CoordinateSystem. */ - class Point : public BaseVector<phys::units::length_d> { + class Point : public BaseVector<length_d> { public: - Point(CoordinateSystem const& pCS, QuantityVector<phys::units::length_d> pQVector) - : BaseVector<phys::units::length_d>(pCS, pQVector) {} + Point(CoordinateSystem const& pCS, QuantityVector<length_d> pQVector) + : BaseVector<length_d>(pCS, pQVector) {} Point(CoordinateSystem const& cs, LengthType x, LengthType y, LengthType z) - : BaseVector<phys::units::length_d>(cs, {x, y, z}) {} + : BaseVector<length_d>(cs, {x, y, z}) {} // TODO: this should be private or protected, we don NOT want to expose numbers // without reference to outside: - auto GetCoordinates() const { return BaseVector<phys::units::length_d>::qVector; } + auto GetCoordinates() const { return BaseVector<length_d>::qVector; } /// this always returns a QuantityVector as triple auto GetCoordinates(CoordinateSystem const& pCS) const { - if (&pCS == BaseVector<phys::units::length_d>::cs) { - return BaseVector<phys::units::length_d>::qVector; + if (&pCS == BaseVector<length_d>::cs) { + return BaseVector<length_d>::qVector; } else { - return QuantityVector<phys::units::length_d>( - CoordinateSystem::GetTransformation(*BaseVector<phys::units::length_d>::cs, - pCS) * - BaseVector<phys::units::length_d>::qVector.eVector); + return QuantityVector<length_d>( + CoordinateSystem::GetTransformation(*BaseVector<length_d>::cs, pCS) * + BaseVector<length_d>::qVector.eVector); } } @@ -55,22 +54,21 @@ namespace corsika::geometry { * coordinates interally */ void rebase(CoordinateSystem const& pCS) { - BaseVector<phys::units::length_d>::qVector = GetCoordinates(pCS); - BaseVector<phys::units::length_d>::cs = &pCS; + BaseVector<length_d>::qVector = GetCoordinates(pCS); + BaseVector<length_d>::cs = &pCS; } - Point operator+(Vector<phys::units::length_d> const& pVec) const { - return Point( - *BaseVector<phys::units::length_d>::cs, - GetCoordinates() + pVec.GetComponents(*BaseVector<phys::units::length_d>::cs)); + Point operator+(Vector<length_d> const& pVec) const { + return Point(*BaseVector<length_d>::cs, + GetCoordinates() + pVec.GetComponents(*BaseVector<length_d>::cs)); } /*! * returns the distance Vector between two points */ - Vector<phys::units::length_d> operator-(Point const& pB) const { - auto& cs = *BaseVector<phys::units::length_d>::cs; - return Vector<phys::units::length_d>(cs, GetCoordinates() - pB.GetCoordinates(cs)); + Vector<length_d> operator-(Point const& pB) const { + auto& cs = *BaseVector<length_d>::cs; + return Vector<length_d>(cs, GetCoordinates() - pB.GetCoordinates(cs)); } }; diff --git a/Framework/ProcessSequence/BaseProcess.h b/Framework/ProcessSequence/BaseProcess.h index 897497d83c82caee4dbc6c19f90996a5ee7f97fa..34dcb198e4d26f409837d253f3270cc0f488098b 100644 --- a/Framework/ProcessSequence/BaseProcess.h +++ b/Framework/ProcessSequence/BaseProcess.h @@ -29,8 +29,15 @@ namespace corsika::process { struct BaseProcess { derived& GetRef() { return static_cast<derived&>(*this); } const derived& GetRef() const { return static_cast<const derived&>(*this); } + + template <typename Particle, typename Stack> + inline EProcessReturn DoDiscrete(Particle&, Stack&) const; // {} + + template <typename Particle, typename Track, typename Stack> + inline EProcessReturn DoContinuous(Particle&, Track&, Stack&) const; // {} }; + /* template <typename T> struct is_base { static const bool value = false; @@ -39,6 +46,7 @@ namespace corsika::process { struct is_base<BaseProcess<T>> { static const bool value = true; }; + */ } // namespace corsika::process diff --git a/Framework/ProcessSequence/ContinuousProcess.h b/Framework/ProcessSequence/ContinuousProcess.h index c53365f1afcdfb64ac808580077dd0e284dcdbd2..a9bc21e5db1c6dcbb2ff8e13110ec957e6242e39 100644 --- a/Framework/ProcessSequence/ContinuousProcess.h +++ b/Framework/ProcessSequence/ContinuousProcess.h @@ -13,6 +13,7 @@ #define _include_corsika_continuousprocess_h_ #include <corsika/process/ProcessReturn.h> // for convenience +//#include <corsika/setup/SetupTrajectory.h> namespace corsika::process { @@ -29,6 +30,11 @@ namespace corsika::process { struct ContinuousProcess { derived& GetRef() { return static_cast<derived&>(*this); } const derived& GetRef() const { return static_cast<const derived&>(*this); } + + // here starts the interface part + // -> enforce derived to implement DoContinuous... + template <typename D, typename T, typename S> + inline EProcessReturn DoContinuous(D&, T&, S&) const; }; } // namespace corsika::process diff --git a/Framework/ProcessSequence/DiscreteProcess.h b/Framework/ProcessSequence/DiscreteProcess.h index 83064f5d8767c93619f6742d50c56aeae0863700..a540c92c783dcad931f0d2bf8278c057736bda79 100644 --- a/Framework/ProcessSequence/DiscreteProcess.h +++ b/Framework/ProcessSequence/DiscreteProcess.h @@ -13,7 +13,7 @@ #define _include_corsika_discreteprocess_h_ #include <corsika/process/ProcessReturn.h> // for convenience - +#include <corsika/setup/SetupTrajectory.h> #include <iostream> // debug namespace corsika::process { @@ -30,25 +30,13 @@ namespace corsika::process { template <typename derived> struct DiscreteProcess { - // DiscreteProcess() { - // static_assert(mustProvide<derived>::mustProvide, ""); - //} - derived& GetRef() { return static_cast<derived&>(*this); } const derived& GetRef() const { return static_cast<const derived&>(*this); } - // here starts the interface part + /// here starts the interface-definition part // -> enforce derived to implement DoDiscrete... template <typename Particle, typename Stack> inline EProcessReturn DoDiscrete(Particle&, Stack&) const; // {} - - // private: - template <typename D, typename T, typename S> - inline EProcessReturn DoContinuous(D& d, T&, S&) const { - std::cout << "yeah" << std::endl; - return EProcessReturn::eOk; - } // find out how to make this FINAL - // void DoContinuous; }; } // namespace corsika::process diff --git a/Framework/ProcessSequence/ProcessSequence.h b/Framework/ProcessSequence/ProcessSequence.h index a07e3ef84c91e6e4e54743c4a4e87c09d933bf2f..54ac90e7a18f7c40c1e5a53c82ebf854e5abe486 100644 --- a/Framework/ProcessSequence/ProcessSequence.h +++ b/Framework/ProcessSequence/ProcessSequence.h @@ -17,14 +17,12 @@ #include <corsika/process/DiscreteProcess.h> #include <corsika/process/ProcessReturn.h> -#include <corsika/setup/SetupTrajectory.h> - -#include <variant> +//#include <corsika/setup/SetupTrajectory.h> +// using corsika::setup::Trajectory; +//#include <variant> //#include <type_traits> // still needed ? -using corsika::setup::Trajectory; - namespace corsika::process { /* namespace detail { */ @@ -149,31 +147,33 @@ namespace corsika::process { // example for a trait-based call: // void Hello() const { detail::CallHello<T1,T2>::Call(A, B); } - template <typename Particle, typename Stack> - inline EProcessReturn DoContinuous(Particle& p, Trajectory& t, Stack& s) const { + template <typename Particle, typename Track, typename Stack> + inline EProcessReturn DoContinuous(Particle& p, Track& t, Stack& s) const { EProcessReturn ret = EProcessReturn::eOk; if constexpr (!std::is_base_of<DiscreteProcess<T1>, T1>::value) { + // A.DoContinuous(std::forward<Particle>(p), t, std::forward<Stack>(s)); A.DoContinuous(p, t, s); } if constexpr (!std::is_base_of<DiscreteProcess<T2>, T2>::value) { + // B.DoContinuous(std::forward<Particle>(p), t, std::forward<Stack>(s)); B.DoContinuous(p, t, s); } return ret; } - template <typename Particle> - inline void MinStepLength(Particle& p, Trajectory& step) const { - A.MinStepLength(p, step); - B.MinStepLength(p, step); + template <typename Particle, typename Track> + inline void MinStepLength(Particle& p, Track& track) const { + A.MinStepLength(p, track); + B.MinStepLength(p, track); } /* - template <typename Particle, typename Trajectory> - inline Trajectory Transport(Particle& p, double& length) const { + template <typename Particle, typename Track> + inline Track Transport(Particle& p, double& length) const { A.Transport(p, length); // todo: maybe check (?) if there is more than one Transport // process implemented?? return B.Transport( - p, length); // need to do this also to decide which Trajectory to return!!!! + p, length); // need to do this also to decide which Track to return!!!! } */ diff --git a/Framework/ProcessSequence/testProcessSequence.cc b/Framework/ProcessSequence/testProcessSequence.cc index 9757298cdc2269a90fd875cdedfa68a16f19ab5a..7094cacb94e8da03bcfce1b9190160fb1b8c1898 100644 --- a/Framework/ProcessSequence/testProcessSequence.cc +++ b/Framework/ProcessSequence/testProcessSequence.cc @@ -19,76 +19,81 @@ #include <corsika/process/ProcessSequence.h> -#include <corsika/setup/SetupTrajectory.h> // TODO: maybe try to break this dependency later! -using corsika::setup::Trajectory; -#include <corsika/units/PhysicalUnits.h> +using namespace corsika; using namespace corsika::units::si; - -using namespace std; using namespace corsika::process; +using namespace std; static const int nData = 10; +int globalCount = 0; + class ContinuousProcess1 : public ContinuousProcess<ContinuousProcess1> { + int fV = 0; + public: - ContinuousProcess1() {} - void Init() { cout << "ContinuousProcess1::Init" << endl; } - template <typename D, typename S> - inline EProcessReturn DoContinuous(D& d, Trajectory&, S&) const { + ContinuousProcess1(const int v) + : fV(v) {} + void Init() { + cout << "ContinuousProcess1::Init" << endl; + assert(globalCount == fV); + globalCount++; + } + template <typename D, typename T, typename S> + inline EProcessReturn DoContinuous(D& d, T&, S&) const { cout << "ContinuousProcess1::DoContinuous" << endl; for (int i = 0; i < nData; ++i) d.p[i] += 0.933; return EProcessReturn::eOk; } - - template <typename Particle, typename Stack> - inline EProcessReturn DoDiscrete(Particle&, Stack&) const { - cout << "ContinuousProcess1::DoDiscrete" << endl; - return EProcessReturn::eOk; - } }; class ContinuousProcess2 : public ContinuousProcess<ContinuousProcess2> { + int fV = 0; + public: - ContinuousProcess2() {} - void Init() { cout << "ContinuousProcess2::Init" << endl; } - template <typename D, typename S> - inline EProcessReturn DoContinuous(D& d, Trajectory&, S&) const { + ContinuousProcess2(const int v) + : fV(v) {} + void Init() { + cout << "ContinuousProcess2::Init" << endl; + assert(globalCount == fV); + globalCount++; + } + template <typename D, typename T, typename S> + inline EProcessReturn DoContinuous(D& d, T&, S&) const { cout << "ContinuousProcess2::DoContinuous" << endl; for (int i = 0; i < nData; ++i) d.p[i] += 0.933; return EProcessReturn::eOk; } - - template <typename Particle, typename Stack> - inline EProcessReturn DoDiscrete(Particle&, Stack&) const { - cout << "ContinuousProcess2::DoDiscrete" << endl; - return EProcessReturn::eOk; - } }; class Process1 : public DiscreteProcess<Process1> { public: - Process1() {} - void Init() { cout << "Process1::Init" << endl; } + Process1(const int v) + : fV(v) {} + void Init() { + cout << "Process1::Init" << endl; + assert(globalCount == fV); + globalCount++; + } template <typename D, typename S> - inline EProcessReturn DoContinuous(D& d, Trajectory&, S&) const { + inline EProcessReturn DoDiscrete(D& d, S&) const { for (int i = 0; i < nData; ++i) d.p[i] += 1 + i; return EProcessReturn::eOk; } - template <typename Particle, typename Stack> - inline EProcessReturn DoDiscrete(Particle&, Stack&) const { - cout << "Process1::DoDiscrete" << endl; - return EProcessReturn::eOk; - } + // private: + int fV; }; class Process2 : public DiscreteProcess<Process2> { + int fV = 0; + public: - Process2() {} - void Init() { cout << "Process2::Init" << endl; } - template <typename D, typename S> - inline EProcessReturn DoContinuous(D& d, Trajectory&, S&) const { - for (int i = 0; i < nData; ++i) d.p[i] *= 0.7; - return EProcessReturn::eOk; + Process2(const int v) + : fV(v) {} + void Init() { + cout << "Process2::Init" << endl; + assert(globalCount == fV); + globalCount++; } template <typename Particle, typename Stack> inline EProcessReturn DoDiscrete(Particle&, Stack&) const { @@ -98,13 +103,15 @@ public: }; class Process3 : public DiscreteProcess<Process3> { + int fV = 0; + public: - Process3() {} - void Init() { cout << "Process3::Init" << endl; } - template <typename D, typename S> - inline EProcessReturn DoContinuous(D& d, Trajectory&, S&) const { - for (int i = 0; i < nData; ++i) d.p[i] += 0.933; - return EProcessReturn::eOk; + Process3(const int v) + : fV(v) {} + void Init() { + cout << "Process3::Init" << endl; + assert(globalCount == fV); + globalCount++; } template <typename Particle, typename Stack> inline EProcessReturn DoDiscrete(Particle&, Stack&) const { @@ -114,66 +121,84 @@ public: }; class Process4 : public BaseProcess<Process4> { + int fV = 0; + public: - Process4() {} - void Init() { cout << "Process4::Init" << endl; } - template <typename D, typename S> - inline EProcessReturn DoContinuous(D& d, Trajectory&, S&) const { - for (int i = 0; i < nData; ++i) d.p[i] /= 1.2; + Process4(const int v) + : fV(v) {} + void Init() { + cout << "Process4::Init" << endl; + assert(globalCount == fV); + globalCount++; + } + template <typename D, typename T, typename S> + inline EProcessReturn DoContinuous(D& d, T&, S&) const { + for (int i = 0; i < nData; ++i) { d.p[i] /= 1.2; } return EProcessReturn::eOk; } // inline double MinStepLength(D& d) { - // void DoDiscrete(Particle& p, Stack& s) const { + template <typename Particle, typename Stack> + EProcessReturn DoDiscrete(Particle&, Stack&) const { + return EProcessReturn::eOk; + } }; struct DummyData { double p[nData] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; }; struct DummyStack {}; +struct DummyTrajectory {}; -TEST_CASE("Cascade", "[Cascade]") { +TEST_CASE("Process Sequence", "[Process Sequence]") { - SECTION("sectionTwo") { - - Process1 m1; - Process2 m2; - Process3 m3; - Process4 m4; + SECTION("Check init order") { + Process1 m1(0); + Process2 m2(1); + Process3 m3(2); + Process4 m4(3); const auto sequence = m1 + m2 + m3 + m4; - ContinuousProcess1 cp1; - ContinuousProcess2 cp2; + globalCount = 0; + sequence.Init(); + // REQUIRE_NOTHROW( (sequence.Init()) ); + + // const auto sequence_wrong = m3 + m2 + m1 + m4; + // globalCount = 0; + // sequence_wrong.Init(); + // REQUIRE_THROWS(sequence_wrong.Init()); + } + + SECTION("sectionTwo") { + + ContinuousProcess1 cp1(0); + ContinuousProcess2 cp2(3); + Process2 m2(1); + Process3 m3(2); const auto sequence2 = cp1 + m2 + m3 + cp2; DummyData p; DummyStack s; + DummyTrajectory t; - cout << "-->init" << endl; + cout << "-->init sequence2" << endl; + globalCount = 0; sequence2.Init(); cout << "-->docont" << endl; - // auto const root = corsika::geometry::CoordinateSystem::CreateRootCS(); - // corsika::geometry::Point pos(root, {0_m, 0_m, 0_m}); - // corsika::geometry::Vector<SpeedType::dimension_type> vec(root, - // {1_m/1_s,0_m/1_s,0_m/1_s}); corsika::geometry::Line traj(pos, vec); - Trajectory - t; //(corsika::geometry::Trajectory<corsika::geometry::Line>(traj, 0_s, 100_ns)); - sequence2.DoContinuous(p, t, s); cout << "-->dodisc" << endl; sequence2.DoDiscrete(p, s); cout << "-->done" << endl; - sequence.Init(); - const int nLoop = 5; cout << "Running loop with n=" << nLoop << endl; - for (int i = 0; i < nLoop; ++i) { sequence.DoContinuous(p, t, s); } + for (int i = 0; i < nLoop; ++i) { + sequence2.DoContinuous(p, t, s); + sequence2.DoDiscrete(p, s); + } for (int i = 0; i < nData; i++) { cout << "data[" << i << "]=" << p.p[i] << endl; } cout << "done" << endl; } - - SECTION("sectionThree") {} } diff --git a/Setup/SetupTrajectory.h b/Setup/SetupTrajectory.h index f1dfd497a6bec31eeb9e4d84967a8b80f380ebb0..acbbc373ac2c3b8454a0bcfb1fb42c84b33f49f5 100644 --- a/Setup/SetupTrajectory.h +++ b/Setup/SetupTrajectory.h @@ -26,9 +26,12 @@ namespace corsika::setup { using corsika::geometry::Line; /// definition of Trajectory base class, to be used in tracking and cascades + typedef corsika::geometry::Trajectory<Line> Trajectory; + + /* typedef std::variant<std::monostate, corsika::geometry::Trajectory<Line>, corsika::geometry::Trajectory<Helix>> - Trajectory; + Trajectory; /// helper visitor to modify Particle by moving along Trajectory template <typename Particle> @@ -58,7 +61,7 @@ namespace corsika::setup { return trajectory.GetDuration(); } }; - + */ } // namespace corsika::setup #endif diff --git a/Stack/SuperStupidStack/SuperStupidStack.h b/Stack/SuperStupidStack/SuperStupidStack.h index 88ec5d58baa4d6d0da208628a41dbdf92e28e569..a1468d239e7f00227e79825b49439cdeba054e50 100644 --- a/Stack/SuperStupidStack/SuperStupidStack.h +++ b/Stack/SuperStupidStack/SuperStupidStack.h @@ -89,8 +89,11 @@ namespace corsika::stack { void Init() {} void Clear() { - fDataE.clear(); fDataPID.clear(); + fDataE.clear(); + fMomentum.clear(); + fPosition.clear(); + fTime.clear(); } int GetSize() const { return fDataPID.size(); }