diff --git a/.clang-format b/.clang-format index 762ac959fa307f188f4cad00297a4ec9b7aeadd3..2f702594c31332c5501172a3ff58c25724639422 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,10 @@ --- Language: Cpp + +ColumnLimit: 0 # line width, 0: respect programmer's choice +TabWidth: 8 +UseTab: Never + AccessModifierOffset: -2 AlignAfterOpenBracket: Align AlignConsecutiveAssignments: false @@ -16,7 +21,6 @@ AllowShortLoopsOnASingleLine: true AlwaysBreakAfterDefinitionReturnType: None AlwaysBreakAfterReturnType: None AlwaysBreakBeforeMultilineStrings: true -AlwaysBreakTemplateDeclarations: true BinPackArguments: true BinPackParameters: true BraceWrapping: @@ -36,7 +40,7 @@ BreakBeforeBraces: Attach BreakBeforeTernaryOperators: true BreakConstructorInitializersBeforeComma: true # BreakInheritanceListBeforeComma: true -ColumnLimit: 90 + CommentPragmas: '^ IWYU pragma:' ConstructorInitializerAllOnOneLineOrOnePerLine: false ConstructorInitializerIndentWidth: 4 @@ -84,6 +88,8 @@ SpacesInCStyleCastParentheses: false SpacesInParentheses: false SpacesInSquareBrackets: false Standard: Auto -TabWidth: 8 -UseTab: Never + +# If true, always break after the template<...> of a template declaration. +AlwaysBreakTemplateDeclarations: true + ... diff --git a/Documentation/Examples/geometry_example.cc b/Documentation/Examples/geometry_example.cc index da23d81e02baae5381358ff13b12f93d071c5dfe..fa5902673cd48889460ecb70a6e5121d32669118 100644 --- a/Documentation/Examples/geometry_example.cc +++ b/Documentation/Examples/geometry_example.cc @@ -41,7 +41,7 @@ int main() { Vector<length_d> const diff = p2 - - p1; // the distance between the points, basically the translation vector given above + p1; // the distance between the points, basically the translation vector given above auto const norm = diff.squaredNorm(); // squared length with the right dimension // print the components of the vector as given in the different CS diff --git a/Documentation/Examples/vertical_EAS.cc b/Documentation/Examples/vertical_EAS.cc index e7944b8e63ef5b87ccb83101163c033f9e3c693e..f7b1868962883510b5c1730609384053bf5d40c6 100644 --- a/Documentation/Examples/vertical_EAS.cc +++ b/Documentation/Examples/vertical_EAS.cc @@ -14,6 +14,7 @@ #include <corsika/environment/ShowerAxis.h> #include <corsika/geometry/Plane.h> #include <corsika/geometry/Sphere.h> +#include <corsika/logging/Logging.h> #include <corsika/process/ProcessSequence.h> #include <corsika/process/StackProcess.h> #include <corsika/process/energy_loss/EnergyLoss.h> @@ -38,7 +39,6 @@ #include <corsika/utl/CorsikaFenv.h> #include <corsika/history/HistoryObservationPlane.hpp> -#include <corsika/history/HistorySecondaryView.hpp> #include <iomanip> #include <iostream> @@ -74,7 +74,9 @@ void registerRandomStreams(const int seed) { int main(int argc, char** argv) { - std::cout << "vertical_EAS" << std::endl; + logging::SetLevel(logging::level::debug); + + C8LOG_INFO("vertical_EAS"); if (argc < 4) { std::cerr << "usage: vertical_EAS <A> <Z> <energy/GeV> [seed]" << std::endl; @@ -135,7 +137,7 @@ int main(int argc, char** argv) { auto const observationHeight = 0_km + builder.getEarthRadius(); auto const injectionHeight = 112.75_km + builder.getEarthRadius(); auto const t = -observationHeight * cos(thetaRad) + - sqrt(-units::static_pow<2>(sin(thetaRad) * observationHeight) + + sqrt(-units::static_pow<2>(sin(thetaRad) * observationHeight) + units::static_pow<2>(injectionHeight)); Point const showerCore{rootCS, 0_m, 0_m, observationHeight}; Point const injectionPos = diff --git a/Framework/Logging/Logging.h b/Framework/Logging/Logging.h index b6190739979a34f7c93670e4fc2efe2dde074449..774bffab01117476f62c66792328d00a9a1a2ce5 100644 --- a/Framework/Logging/Logging.h +++ b/Framework/Logging/Logging.h @@ -168,7 +168,7 @@ namespace corsika::logging { inline auto ResetPattern(TLogger& logger) -> void { logger->set_pattern(default_pattern); } - + // define our macro-style loggers #define C8LOG_TRACE SPDLOG_TRACE #define C8LOG_DEBUG SPDLOG_DEBUG @@ -186,5 +186,3 @@ namespace corsika::logging { #define C8LOG_LOGGER_CRITICAL SPDLOG_LOGGER_CRITICAL } // namespace corsika::logging - - diff --git a/Framework/StackInterface/SecondaryView.h b/Framework/StackInterface/SecondaryView.h index bda66b88351a0283bb49e35df4ca49769d9d9ba6..b47d5a653e117402d08db90b977f18cd3f2b24c8 100644 --- a/Framework/StackInterface/SecondaryView.h +++ b/Framework/StackInterface/SecondaryView.h @@ -55,10 +55,17 @@ namespace corsika::stack { GetIndexFromIterator. */ - template <typename StackDataType, template <typename> typename ParticleInterface> - class SecondaryView : public Stack<StackDataType&, ParticleInterface> { + template <typename StackDataType, + template <typename> typename ParticleInterface, + //template <typename> typename MSecondaryProducer = DefaultSecondaryProducer> + template <class T1, template <class> class T2> class MSecondaryProducer> // T2==ParticleInterface - using ViewType = SecondaryView<StackDataType, ParticleInterface>; + class SecondaryView : public Stack<StackDataType&, ParticleInterface>, + public MSecondaryProducer<StackDataType, ParticleInterface> + + { //, public MSecondaryProducer<SecondaryView<StackDataType,ParticleInterface,MSecondaryProducer>> { + + using ViewType = SecondaryView<StackDataType, ParticleInterface, MSecondaryProducer>; private: /** @@ -75,20 +82,12 @@ namespace corsika::stack { using InnerStackTypeValue = Stack<StackDataType, ParticleInterface>; public: - using StackIteratorValue = - StackIteratorInterface<typename std::remove_reference<StackDataType>::type, - ParticleInterface, InnerStackTypeValue>; - using ConstStackIteratorValue = - ConstStackIteratorInterface<typename std::remove_reference<StackDataType>::type, - ParticleInterface, InnerStackTypeValue>; + using StackIteratorValue = StackIteratorInterface<typename std::remove_reference<StackDataType>::type, ParticleInterface, InnerStackTypeValue>; + using ConstStackIteratorValue = ConstStackIteratorInterface<typename std::remove_reference<StackDataType>::type, ParticleInterface, InnerStackTypeValue>; /// @} - using StackIterator = - StackIteratorInterface<typename std::remove_reference<StackDataType>::type, - ParticleInterface, ViewType>; - using ConstStackIterator = - ConstStackIteratorInterface<typename std::remove_reference<StackDataType>::type, - ParticleInterface, ViewType>; + using StackIterator = StackIteratorInterface<typename std::remove_reference<StackDataType>::type, ParticleInterface, ViewType>; + using ConstStackIterator = ConstStackIteratorInterface<typename std::remove_reference<StackDataType>::type, ParticleInterface, ViewType>; /** * this is the full type of the declared ParticleInterface: typedef typename @@ -96,14 +95,15 @@ namespace corsika::stack { using ParticleType = StackIterator; using ParticleInterfaceType = typename StackIterator::ParticleInterfaceType; - friend class StackIteratorInterface< - typename std::remove_reference<StackDataType>::type, ParticleInterface, ViewType>; + friend class StackIteratorInterface<typename std::remove_reference<StackDataType>::type, ParticleInterface, ViewType>; - friend class ConstStackIteratorInterface< - typename std::remove_reference<StackDataType>::type, ParticleInterface, ViewType>; + friend class ConstStackIteratorInterface<typename std::remove_reference<StackDataType>::type, ParticleInterface, ViewType>; friend class ParticleBase<StackIterator>; + template <template <typename> typename M1> + friend class MSecondaryProducer; + private: /** * This is not accessible, since we don't want to allow creating a @@ -125,7 +125,10 @@ namespace corsika::stack { SecondaryView(StackIteratorValue& vI) : Stack<StackDataType&, ParticleInterface>(vI.GetStackData()) , inner_stack_(vI.GetStack()) - , projectile_index_(vI.GetIndex()) {} + , projectile_index_(vI.GetIndex()) { + C8LOG_TRACE("SecondaryView::SecondaryView"); + MSecondaryProducer<StackDataType, ParticleInterface>::new_view(vI); + } /** * This returns the projectile/parent in the original Stack, where this @@ -133,9 +136,7 @@ namespace corsika::stack { * used to modify the Stack! */ - ConstStackIteratorValue parent() const { - return ConstStackIteratorValue(inner_stack_, projectile_index_); - } + ConstStackIteratorValue parent() const { return ConstStackIteratorValue(inner_stack_, projectile_index_); } /** * This return a projectile of this SecondaryView, which can be @@ -152,24 +153,24 @@ namespace corsika::stack { */ template <typename... Args> StackIterator AddSecondary(const Args... v) { - C8LOG_DEBUG("SecondaryView::AddSecondary(Args&&)"); - StackIterator proj = GetProjectile(); + C8LOG_TRACE("SecondaryView::AddSecondary(Args&&)"); + StackIterator proj = GetProjectile(); // make this const return AddSecondary(proj, v...); } protected: /** * Overwrite of Stack::StackIterator - * + * * increase stack size, create new particle at end of stack, * related to parent particle/projectile * * This should only get internally called from a * StackIterator::AddSecondary via ParticleBase - */ + */ template <typename... Args> StackIterator AddSecondary(StackIterator& proj, const Args... v) { - C8LOG_DEBUG("SecondaryView::AddSecondary(StackIterator&, Args&&)"); + C8LOG_TRACE("SecondaryView::AddSecondary(StackIterator&, Args&&)"); // make space on stack InnerStackTypeRef::GetStackData().IncrementSize(); inner_stack_.deleted_.push_back(false); @@ -180,11 +181,12 @@ namespace corsika::stack { indices_.push_back(index); // NOTE: "+1" is since "0" is special marker here for PROJECTILE, see // GetIndexFromIterator - return StackIterator(*this, idSec + 1, proj, v...); + auto sec = StackIterator(*this, idSec + 1, proj, v...); + MSecondaryProducer<StackDataType, ParticleInterface>::new_secondary(sec); + return sec; } - + public: - /** * overwrite Stack::GetSize to return actual number of secondaries */ @@ -293,15 +295,11 @@ namespace corsika::stack { * different */ bool isDeleted(const StackIterator& p) const { return isDeleted(p.GetIndex() - 1); } - bool isDeleted(const ConstStackIterator& p) const { - return isDeleted(p.GetIndex() - 1); - } + bool isDeleted(const ConstStackIterator& p) const { return isDeleted(p.GetIndex() - 1); } /** * delete this particle */ - bool isDeleted(const ParticleInterfaceType& p) const { - return isDeleted(p.GetIterator()); - } + bool isDeleted(const ParticleInterfaceType& p) const { return isDeleted(p.GetIterator()); } /** * Function to ultimatively remove the last entry from the stack, @@ -309,8 +307,7 @@ namespace corsika::stack { * the function will just return false and do nothing. */ bool purgeLastIfDeleted() { - if (!isDeleted(getSize() - 1)) - return false; // the last particle is not marked for deletion. Do nothing. + if (!isDeleted(getSize() - 1)) return false; // the last particle is not marked for deletion. Do nothing. inner_stack_.purge(GetIndexFromIterator(getSize())); InnerStackTypeRef::nDeleted_--; indices_.pop_back(); @@ -358,6 +355,40 @@ namespace corsika::stack { } }; + /** + * + */ + template <class T1, template <class> class T2> + class DefaultSecondaryProducer { + using View = SecondaryView<T1, T2, DefaultSecondaryProducer>; + + public: + /** + * Method is called after a new SecondaryView has been + * created. Extra logic can be introduced here. + * + * The input Particle is a reference object into the original + * parent stack! It is not a reference into the SecondaryView + * itself. + */ + template <typename Particle> + void new_view(Particle&) { + C8LOG_TRACE("DefaultSecondaryProducer::init"); + } + + /** + * Method is called after a new Secondary has been created on the + * SecondaryView. Extra logic can be introduced here. + * + * The input Particle is the new secondary that was produced and + * is of course a reference into the SecondaryView itself. + */ + template <typename Particle> + auto new_secondary(Particle&) { + C8LOG_TRACE("DefaultSecondaryProducer::produce(TView,Args&&)"); + } + }; + /* See Issue 161 @@ -367,9 +398,12 @@ namespace corsika::stack { generic and universal. */ #if not defined(__clang__) && defined(__GNUC__) || defined(__GNUG__) - template <typename S, template <typename> typename _PIType = S::template PIType> + template <typename S, + // template <typename> typename MSecondaryProducer = corsika::stack::DefaultSecondaryProducer, + template <class T1, template <class> class T2> class MSecondaryProducer = corsika::stack::DefaultSecondaryProducer, + template <typename> typename _PIType = S::template PIType> struct MakeView { - using type = corsika::stack::SecondaryView<typename S::StackImpl, _PIType>; + using type = corsika::stack::SecondaryView<typename S::StackImpl, _PIType, MSecondaryProducer>; }; #endif diff --git a/Framework/StackInterface/Stack.h b/Framework/StackInterface/Stack.h index ea59b2cff44fa27460b64b0f9adf1fa79426c376..94ee054c85dca11a7f119d1e20c4624c1acfd7be 100644 --- a/Framework/StackInterface/Stack.h +++ b/Framework/StackInterface/Stack.h @@ -55,7 +55,7 @@ namespace corsika::stack { using StackDataValueType = std::remove_reference_t<TStackData>; private: - TStackData data_; ///< this in general holds all the data and can be quite big + TStackData data_; ///< this in general holds all the data and can be quite big std::vector<bool> deleted_; ///< bit field to flag deleted entries protected: unsigned int nDeleted_ = 0; @@ -125,9 +125,15 @@ namespace corsika::stack { friend class StackIteratorInterface<StackDataValueType, TParticleInterface, Stack>; friend class ConstStackIteratorInterface<StackDataValueType, TParticleInterface, Stack>; - friend class SecondaryView<StackDataValueType, TParticleInterface>; + //friend class SecondaryView<StackDataValueType, TParticleInterface>; + template <typename T1, //=TStackData, + template <typename> typename M1, //=TParticleInterface, + // template<typename>typename M2> + template <class T2, template <class> class T3> class MSecondaryProducer> + friend class SecondaryView; //<TStackData,TParticleInterface,M>; // access for SecondaryView + friend class ParticleBase<StackIterator>; - + public: /** * @name Most generic proxy methods for TStackData data_ diff --git a/Framework/StackInterface/StackIteratorInterface.h b/Framework/StackInterface/StackIteratorInterface.h index 62596f93067468fba2108e8d4b8fbb5473c0aa33..33c4965e15956c1e9a9f4876b550cc5e67a1ab89 100644 --- a/Framework/StackInterface/StackIteratorInterface.h +++ b/Framework/StackInterface/StackIteratorInterface.h @@ -11,8 +11,10 @@ #include <corsika/stack/ParticleBase.h> namespace corsika::history { - template <typename T> - class HistorySecondaryView; // forward decl. for befriending + template <typename T, + template <typename> typename ParticleInterface> + //class HistorySecondaryView; // forward decl. for befriending + class HistorySecondaryProducer; } namespace corsika::stack { @@ -20,7 +22,10 @@ namespace corsika::stack { template <typename TStackData, template <typename> typename TParticleInterface> class Stack; // forward decl - template <typename TStackData, template <typename> typename TParticleInterface> + template <typename TStackData, + template <typename> typename TParticleInterface, + //template <typename> typename TProd> + template <class T1, template <class> class T2> class MSecondaryProducer> class SecondaryView; // forward decl template <typename TStackData, template <typename> typename TParticleInterface, @@ -65,7 +70,8 @@ namespace corsika::stack { corsika::processes::sibyll::SibStack class */ - template <typename TStackData, template <typename> typename TParticleInterface, + template <typename TStackData, + template <typename> typename TParticleInterface, typename StackType = Stack<TStackData, TParticleInterface>> class StackIteratorInterface : public TParticleInterface< @@ -78,15 +84,22 @@ namespace corsika::stack { // friends are needed for access to protected methods friend class Stack<TStackData, - TParticleInterface>; // for access to GetIndex for Stack + TParticleInterface>; // for access to GetIndex for Stack friend class Stack<TStackData&, TParticleInterface>; // for access to GetIndex // SecondaryView : public Stack friend class ParticleBase<StackIteratorInterface>; // for access to GetStackData - friend class SecondaryView<TStackData, - TParticleInterface>; // access for SecondaryView - template <typename T> - friend class corsika::history::HistorySecondaryView; + template <typename T1, //=TStackData, + template <typename> typename M1, //=TParticleInterface, + template <typename T, + template <typename> typename T3> typename M2> + // template <typename> typename M2> + friend class SecondaryView; //<TStackData,TParticleInterface,M>; // access for SecondaryView + + template <typename T, + template <typename> typename ParticleInterface> + //friend class corsika::history::HistorySecondaryView; + friend class corsika::history::HistorySecondaryProducer; friend class ConstStackIteratorInterface<TStackData, TParticleInterface, StackType>; @@ -245,15 +258,25 @@ namespace corsika::stack { // friends are needed for access to protected methods friend class Stack<TStackData, - TParticleInterface>; // for access to GetIndex for Stack - friend class Stack<TStackData&, TParticleInterface>; // for access to GetIndex - // SecondaryView : public Stack + TParticleInterface>; // for access to GetIndex for Stack + friend class Stack<TStackData&, TParticleInterface>; // for access to GetIndex + // SecondaryView : public Stack friend class ParticleBase<ConstStackIteratorInterface>; // for access to GetStackData - friend class SecondaryView<TStackData, - TParticleInterface>; // access for SecondaryView + //friend class SecondaryView<TStackData, + // TParticleInterface>; // access for SecondaryView + template <typename T1, //=TStackData, + template <typename> typename M1, //=TParticleInterface, + // template <typename> typename M2> + template <class T2, template <class> class T3> class MSecondaryProducer> + friend class SecondaryView; //<TStackData,TParticleInterface,M>; // access for SecondaryView friend class StackIteratorInterface<TStackData, TParticleInterface, StackType>; + template <typename T, + template <typename> typename ParticleInterface> + //friend class corsika::history::HistorySecondaryView; + friend class corsika::history::HistorySecondaryProducer; + protected: unsigned int index_ = 0; diff --git a/Framework/StackInterface/testSecondaryView.cc b/Framework/StackInterface/testSecondaryView.cc index e4c82d15bddf3eb0d9292559f9bb4ed7d5acb7be..ede66dc8657ac0bfa7e513e943efc040f09a6e05 100644 --- a/Framework/StackInterface/testSecondaryView.cc +++ b/Framework/StackInterface/testSecondaryView.cc @@ -44,6 +44,8 @@ using Particle = typename StackTest::ParticleType; TEST_CASE("SecondaryStack", "[stack]") { + logging::SetLevel(logging::level::debug); + // helper function for sum over stack data auto sum = [](const StackTest& stack) { double v = 0; diff --git a/Framework/Testing/TestMain.cc b/Framework/Testing/TestMain.cc index fa52fa804f307c546f628b7ccd5d14401b6f0adb..15312a6ad3f1f987fa438806773a51e0674983af 100644 --- a/Framework/Testing/TestMain.cc +++ b/Framework/Testing/TestMain.cc @@ -6,6 +6,6 @@ * the license. */ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one \ // cpp file #include <catch2/catch.hpp> diff --git a/Framework/Units/PhysicalUnits.h b/Framework/Units/PhysicalUnits.h index 9e9f26bde19df00c75d3f99593b471c5c705acb8..1f207abbc2f3c08bc7b39c49ca3a5db0719e6e5d 100644 --- a/Framework/Units/PhysicalUnits.h +++ b/Framework/Units/PhysicalUnits.h @@ -31,17 +31,17 @@ namespace phys::units { */ namespace corsika::units { - template <int N, typename T> - auto constexpr static_pow([[maybe_unused]] T x) { - if constexpr (N == 0) { - return 1; - } else if constexpr (N > 0) { - return x * static_pow<N - 1, T>(x); - } else { - return 1 / static_pow<-N, T>(x); - } + template <int N, typename T> + auto constexpr static_pow([[maybe_unused]] T x) { + if constexpr (N == 0) { + return 1; + } else if constexpr (N > 0) { + return x * static_pow<N - 1, T>(x); + } else { + return 1 / static_pow<-N, T>(x); } -} + } +} // namespace corsika::units namespace corsika::units::si { using namespace phys::units; diff --git a/Processes/CONEXSourceCut/CONEXSourceCut.cc b/Processes/CONEXSourceCut/CONEXSourceCut.cc index 8039d8ed867053756f631a950815aaf50d9c380f..b2de7cdbec63c06cbe469849129ac5dad646c60a 100644 --- a/Processes/CONEXSourceCut/CONEXSourceCut.cc +++ b/Processes/CONEXSourceCut/CONEXSourceCut.cc @@ -187,7 +187,8 @@ CONEXSourceCut::CONEXSourceCut(geometry::Point center, auto const transform = geometry::CoordinateSystem::GetTransformation( intermediateCS2, c8cs); // either this way or vice versa... TODO: test this! - std::cout << transform.matrix() << std::endl << std::endl; + std::cout << transform.matrix() << std::endl + << std::endl; std::cout << geometry::CoordinateSystem::GetTransformation(intermediateCS, c8cs).matrix() << std::endl diff --git a/Processes/CONEXSourceCut/CONEXSourceCut.h b/Processes/CONEXSourceCut/CONEXSourceCut.h index 121d8c16369a144bac054678f1c6b9af021b308a..115b8fc952349c9e21fb2f4d3a2652d7f9474ac4 100644 --- a/Processes/CONEXSourceCut/CONEXSourceCut.h +++ b/Processes/CONEXSourceCut/CONEXSourceCut.h @@ -53,8 +53,8 @@ namespace corsika::process { geometry::Point const center_; //!< center of CONEX Earth environment::ShowerAxis const& showerAxis_; - units::si::LengthType groundDist_; //!< length from injection point to shower core - geometry::Point const showerCore_; //!< shower core + units::si::LengthType groundDist_; //!< length from injection point to shower core + geometry::Point const showerCore_; //!< shower core geometry::CoordinateSystem const conexObservationCS_; //!< CONEX observation frame geometry::Vector<units::si::dimensionless_d> const x_sf_, y_sf_; //!< unit vectors of CONEX shower frame, z_sf is shower axis direction diff --git a/Processes/InteractionCounter/testInteractionCounter.cc b/Processes/InteractionCounter/testInteractionCounter.cc index 08b67182b1f881a48ce291bc37ca1c36359a08e5..6dfd2da9ac67fa475731c868bd62d97f0b36a6d5 100644 --- a/Processes/InteractionCounter/testInteractionCounter.cc +++ b/Processes/InteractionCounter/testInteractionCounter.cc @@ -61,7 +61,7 @@ auto setupStack(int vA, int vZ, HEPEnergyType vMomentum, TNodeType* vNodePtr, HEPEnergyType const E0 = sqrt(units::static_pow<2>(mN * vA) + pLab.squaredNorm()); - auto particle = + setup::Stack::StackIterator particle = stack->AddParticle(std::tuple<particles::Code, units::si::HEPEnergyType, corsika::stack::MomentumVector, geometry::Point, units::si::TimeType, unsigned short, unsigned short>{ @@ -70,7 +70,7 @@ auto setupStack(int vA, int vZ, HEPEnergyType vMomentum, TNodeType* vNodePtr, particle.SetNode(vNodePtr); return std::make_tuple( std::move(stack), - std::make_unique<decltype(corsika::stack::SecondaryView(particle))>(particle)); + std::make_unique<decltype(setup::StackView(particle))>(particle)); } template <typename TNodeType> @@ -92,7 +92,7 @@ auto setupStack(particles::Code vProjectileType, HEPEnergyType vMomentum, particle.SetNode(vNodePtr); return std::make_tuple( std::move(stack), - std::make_unique<decltype(corsika::stack::SecondaryView(particle))>(particle)); + std::make_unique<decltype(setup::StackView(particle))>(particle)); } struct DummyProcess { @@ -108,6 +108,9 @@ struct DummyProcess { }; TEST_CASE("InteractionCounter") { + + logging::SetLevel(logging::level::debug); + DummyProcess d; InteractionCounter countedProcess(d); diff --git a/Processes/ObservationPlane/testObservationPlane.cc b/Processes/ObservationPlane/testObservationPlane.cc index 7f3f183a6def750818aa1eb05be4bec81937d587..d35aba57e9ae0e5e08a262916b4adca1bf304947 100644 --- a/Processes/ObservationPlane/testObservationPlane.cc +++ b/Processes/ObservationPlane/testObservationPlane.cc @@ -6,7 +6,7 @@ * the license. */ -#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one +#define CATCH_CONFIG_MAIN // This tells Catch to provide a main() - only do this in one \ // cpp file #include <catch2/catch.hpp> diff --git a/Processes/ParticleCut/testParticleCut.cc b/Processes/ParticleCut/testParticleCut.cc index 05805cd92891d0144778bf54fa8e845081300e74..9ed381dfef2c5693c4df6a4c35685ce3f518d8c6 100644 --- a/Processes/ParticleCut/testParticleCut.cc +++ b/Processes/ParticleCut/testParticleCut.cc @@ -38,9 +38,9 @@ TEST_CASE("ParticleCut", "[processes]") { const HEPEnergyType Ebelow = 10_GeV; // list of arbitrary particles std::vector<particles::Code> particleList = { - particles::Code::PiPlus, particles::Code::PiMinus, particles::Code::KPlus, - particles::Code::KMinus, particles::Code::K0Long, particles::Code::K0Short, - particles::Code::Electron, particles::Code::MuPlus, particles::Code::NuE, + particles::Code::PiPlus, particles::Code::PiMinus, particles::Code::KPlus, + particles::Code::KMinus, particles::Code::K0Long, particles::Code::K0Short, + particles::Code::Electron, particles::Code::MuPlus, particles::Code::NuE, particles::Code::Neutron}; SECTION("cut on particle type: inv") { diff --git a/Processes/Pythia/Interaction.cc b/Processes/Pythia/Interaction.cc index fe641a62629a5bfc2b75f4ce9d0ada6c984322ce..0de68ef9fcdca20c7915ba02d5e2c623136bc4c2 100644 --- a/Processes/Pythia/Interaction.cc +++ b/Processes/Pythia/Interaction.cc @@ -51,14 +51,14 @@ namespace corsika::process::pythia { // define which particles are passed to corsika, i.e. which particles make it into // history even very shortlived particles like charm or pi0 are of interest here const std::vector<particles::Code> HadronsWeWantTrackedByCorsika = { - particles::Code::PiPlus, particles::Code::PiMinus, - particles::Code::Pi0, particles::Code::KMinus, - particles::Code::KPlus, particles::Code::K0Long, - particles::Code::K0Short, particles::Code::SigmaPlus, + particles::Code::PiPlus, particles::Code::PiMinus, + particles::Code::Pi0, particles::Code::KMinus, + particles::Code::KPlus, particles::Code::K0Long, + particles::Code::K0Short, particles::Code::SigmaPlus, particles::Code::SigmaMinus, particles::Code::Lambda0, - particles::Code::Xi0, particles::Code::XiMinus, + particles::Code::Xi0, particles::Code::XiMinus, particles::Code::OmegaMinus, particles::Code::DPlus, - particles::Code::DMinus, particles::Code::D0, + particles::Code::DMinus, particles::Code::D0, particles::Code::D0Bar}; Interaction::SetParticleListStable(HadronsWeWantTrackedByCorsika); diff --git a/Processes/Sibyll/NuclearInteraction.cc b/Processes/Sibyll/NuclearInteraction.cc index 1a814e0dd00f0684e228450541496e6c4dcdf85a..dc442cb938a9ceddc87468923376e4772f75c6eb 100644 --- a/Processes/Sibyll/NuclearInteraction.cc +++ b/Processes/Sibyll/NuclearInteraction.cc @@ -45,7 +45,7 @@ namespace corsika::process::sibyll { using namespace corsika::particles; const int k = targetComponentsIndex_.at(pCode); Code pNuclei[] = {Code::Helium, Code::Lithium7, Code::Oxygen, - Code::Neon, Code::Argon, Code::Iron}; + Code::Neon, Code::Argon, Code::Iron}; cout << "en/A "; for (auto& j : pNuclei) cout << std::setw(9) << j; cout << endl; diff --git a/Processes/UrQMD/UrQMD.cc b/Processes/UrQMD/UrQMD.cc index 0a795e1ee1c5809707edeb68505a671413b53303..6afc2d64215a3b5df4ecb8fc29feaa1b1b81113d 100644 --- a/Processes/UrQMD/UrQMD.cc +++ b/Processes/UrQMD/UrQMD.cc @@ -213,9 +213,9 @@ bool UrQMD::CanInteract(particles::Code code) const { // so we unfortunately have to forbid these interactions for the time being. static particles::Code const validProjectileCodes[] = { - particles::Code::Proton, particles::Code::AntiProton, particles::Code::Neutron, - particles::Code::AntiNeutron, particles::Code::PiPlus, particles::Code::PiMinus, - particles::Code::KPlus, particles::Code::KMinus, particles::Code::K0Short, + particles::Code::Proton, particles::Code::AntiProton, particles::Code::Neutron, + particles::Code::AntiNeutron, particles::Code::PiPlus, particles::Code::PiMinus, + particles::Code::KPlus, particles::Code::KMinus, particles::Code::K0Short, particles::Code::K0Long}; return std::find(std::cbegin(validProjectileCodes), std::cend(validProjectileCodes), diff --git a/Processes/UrQMD/UrQMD.h b/Processes/UrQMD/UrQMD.h index 937b6d702f63443fe0e221060e86739010ffcae8..016c958aac1935db65e1314728a372e10b111795 100644 --- a/Processes/UrQMD/UrQMD.h +++ b/Processes/UrQMD/UrQMD.h @@ -117,7 +117,7 @@ namespace corsika::process::UrQMD { int nevents; std::array<int, 2> spityp; // particle codes of: [0]: projectile, [1]: target int prspflg; // projectile special flag - int trspflg; // target special flag, set to 1 unless target is nucleus > H + int trspflg; // target special flag, set to 1 unless target is nucleus > H std::array<int, 2> spiso3; // particle codes of: [0]: projectile, [1]: target int outsteps, bflag, srtflag, efuncflag, nsrt, npb, firstev; } inputs_; diff --git a/Processes/UrQMD/testUrQMD.cc b/Processes/UrQMD/testUrQMD.cc index 5cb6be54ff7b6a0842a1729a2fa7fad2b8ae4a4f..e9d9de025e8ac285a6bf6329025b3ee4b5c2328e 100644 --- a/Processes/UrQMD/testUrQMD.cc +++ b/Processes/UrQMD/testUrQMD.cc @@ -138,9 +138,9 @@ TEST_CASE("UrQMD") { [[maybe_unused]] auto const& node_dummy = nodePtr; particles::Code validProjectileCodes[] = { - particles::Code::PiPlus, particles::Code::PiMinus, particles::Code::Proton, - particles::Code::Neutron, particles::Code::KPlus, particles::Code::KMinus, - particles::Code::K0, particles::Code::K0Bar, particles::Code::K0Long}; + particles::Code::PiPlus, particles::Code::PiMinus, particles::Code::Proton, + particles::Code::Neutron, particles::Code::KPlus, particles::Code::KMinus, + particles::Code::K0, particles::Code::K0Bar, particles::Code::K0Long}; for (auto code : validProjectileCodes) { auto [stack, view] = setupStack(code, 100_GeV, nodePtr, cs); diff --git a/Setup/SetupStack.h b/Setup/SetupStack.h index fce58ce07a686ea6d316d2f1b0f3d915619345c3..b838c04840d27d9feb6d27fc4a1fc2b34710ae9d 100644 --- a/Setup/SetupStack.h +++ b/Setup/SetupStack.h @@ -9,10 +9,10 @@ #pragma once #include <corsika/history/HistoryStackExtension.h> -#include <corsika/history/HistorySecondaryView.hpp> #include <corsika/stack/CombinedStack.h> #include <corsika/stack/node/GeometryNodeStackExtension.h> #include <corsika/stack/nuclear_extension/NuclearStackExtension.h> +#include <corsika/history/HistorySecondaryProducer.hpp> #include <corsika/setup/SetupEnvironment.h> @@ -58,12 +58,16 @@ namespace corsika::setup { // --------------------------------------- // this is the FINAL stack we use in C8: - + // the version without history // using Stack = detail::StackWithGeometry; + //template<typename T1, template<typename>typename M2> + //using StackViewProducer = corsika::stack::DefaultSecondaryProducer<T1,M2>; // the version with history using Stack = detail::StackWithHistory; + template <typename T1, template <typename> typename M2> + using StackViewProducer = corsika::history::HistorySecondaryProducer<T1, M2>; namespace detail { /* @@ -79,22 +83,18 @@ namespace corsika::setup { */ #if defined(__clang__) using TheStackView = corsika::stack::SecondaryView< - typename corsika::setup::Stack::StackImpl, - // CHECK with CLANG: corsika::setup::Stack::PIType>; - // corsika::setup::detail::StackWithGeometryInterface>; - corsika::setup::detail::StackWithHistoryInterface>; + typename corsika::setup::Stack::StackImpl, + // CHECK with CLANG: corsika::setup::Stack::PIType>; + // corsika::setup::detail::StackWithGeometryInterface>; + corsika::setup::detail::StackWithHistoryInterface>; #elif defined(__GNUC__) || defined(__GNUG__) - using TheStackView = corsika::stack::MakeView<corsika::setup::Stack>::type; + using TheStackView = corsika::stack::MakeView<corsika::setup::Stack, StackViewProducer>::type; #endif - } + } // namespace detail // --------------------------------------- // this is the FINAL stackitertor (particle type) we use in C8: - // the version without history - //using StackView = detail::StackView; - - // the one with history - using StackView = corsika::history::HistorySecondaryView<detail::TheStackView>; + using StackView = detail::TheStackView; } // namespace corsika::setup diff --git a/Stack/History/CMakeLists.txt b/Stack/History/CMakeLists.txt index de272dc23f91c533033f1abf4410be5466e16205..9adb558a24e3a6bab1f94cc29e144f3ce28db0d4 100644 --- a/Stack/History/CMakeLists.txt +++ b/Stack/History/CMakeLists.txt @@ -1,7 +1,7 @@ set ( HISTORY_HEADERS Event.hpp - HistorySecondaryView.hpp + HistorySecondaryProducer.hpp HistoryObservationPlane.hpp HistoryStackExtension.h SecondaryParticle.hpp @@ -23,7 +23,6 @@ CORSIKA_COPY_HEADERS_TO_NAMESPACE (CORSIKAhistory ${HISTORY_NAMESPACE} ${HISTORY target_link_libraries ( CORSIKAhistory -# INTERFACE CORSIKAparticles CORSIKAgeometry CORSIKAprocesssequence # for HistoryObservationPlane diff --git a/Stack/History/HistorySecondaryView.hpp b/Stack/History/HistorySecondaryView.hpp deleted file mode 100644 index e4a36cc1ce7a285e7a1881977de5333eb5c95367..0000000000000000000000000000000000000000 --- a/Stack/History/HistorySecondaryView.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * (c) Copyright 2018 CORSIKA Project, corsika-project@lists.kit.edu - * - * This software is distributed under the terms of the GNU General Public - * Licence version 3 (GPL Version 3). See file LICENSE for a full version of - * the license. - */ - -#pragma once - -#include <corsika/stack/SecondaryView.h> -#include <corsika/history/Event.hpp> - -#include <corsika/logging/Logging.h> - -#include <memory> -#include <type_traits> -#include <utility> - -namespace corsika::history { - - template <typename TView> - class HistorySecondaryView : public TView { - - EventPtr event_; - - public: - using StackIteratorValue = typename TView::StackIteratorValue; - using StackIterator = typename TView::StackIterator; - - public: - HistorySecondaryView(StackIteratorValue& p) - : TView{p} - , event_{std::make_shared<Event>()} { - event_->setProjectileIndex(p.GetIndex()); - event_->setParentEvent(p.GetEvent()); - } - - template <typename... Args> - StackIterator AddSecondary(Args&&... args) { - C8LOG_TRACE("HistorySecondaryView::AddSecondary(Args&&)"); - auto stack_sec = TView::AddSecondary(std::forward<Args...>(args...)); - - // store particles at production time in Event here - auto const sec_index = event_->addSecondary( - stack_sec.GetEnergy(), stack_sec.GetMomentum(), stack_sec.GetPID()); - stack_sec.SetParentEventIndex(sec_index); - stack_sec.SetEvent(event_); - - // RU: consider if we can call - // TView::AddSecondary twice instead: 1. for particle at production time - // , 2. dynamic particle ... not sure, but would be extremely flexible. - - return stack_sec; - } - - template <typename... Args> - StackIterator AddSecondary(StackIterator& proj, const Args... args) { - C8LOG_TRACE("HistorySecondaryView::AddSecondary(StackIterator&, Args&&)"); - return TView::AddSecondary(proj, std::forward<Args...>(args...)); - } - - }; - -} // namespace corsika::history diff --git a/Stack/History/HistoryStackExtension.h b/Stack/History/HistoryStackExtension.h index 798eb1004e6433c2dc884366df3e1f365cb8873e..bbb594b3771611633f677e3c8500baf610a90e1e 100644 --- a/Stack/History/HistoryStackExtension.h +++ b/Stack/History/HistoryStackExtension.h @@ -8,8 +8,8 @@ #pragma once -#include <corsika/stack/Stack.h> #include <corsika/logging/Logging.h> +#include <corsika/stack/Stack.h> #include <memory> #include <utility> @@ -27,7 +27,7 @@ namespace corsika::history { template <typename TEvent> class HistoryData { using EventPtr = - std::shared_ptr<TEvent>; //!< Pointer to the event where this particle was created + std::shared_ptr<TEvent>; //!< Pointer to the event where this particle was created using ParentEventIndex = int; //!< index to TEvent::secondaries_ using DataType = std::pair<EventPtr, ParentEventIndex>; @@ -84,12 +84,13 @@ namespace corsika::history { // create a new particle from scratch void SetParticleData() { C8LOG_TRACE("HistoyDatatInterface::SetParticleData()"); - GetStackData().SetParentEventIndex(GetIndex(), -1); } + GetStackData().SetParentEventIndex(GetIndex(), -1); + } // create a new particle as secondary of a parent void SetParticleData(HistoryDataInterface& /*parent*/) { - C8LOG_TRACE("HistoyDatatInterface::SetParticleData(parnt)"); - SetParticleData(); + C8LOG_TRACE("HistoyDatatInterface::SetParticleData(parnt)"); + SetParticleData(); } void SetEvent(const std::shared_ptr<TEvent>& v) { diff --git a/Stack/History/testHistoryStack.cc b/Stack/History/testHistoryStack.cc index fcb9934e40c6489e3df06c7880a7c2294b3021ce..80b1de4436178020bb6e32d0dd67eacc437417ac 100644 --- a/Stack/History/testHistoryStack.cc +++ b/Stack/History/testHistoryStack.cc @@ -52,6 +52,8 @@ using EvtPtr = std::shared_ptr<DummyEvent>; TEST_CASE("HistoryStackExtension", "[stack]") { + logging::SetLevel(logging::level::debug); + const dummy::NoData noData; TestStack s; diff --git a/Stack/History/testHistoryView.cc b/Stack/History/testHistoryView.cc index 5c14fdf1ea553519e29f7d98790c60935d9d2edb..d85693bc083becaa61cf4b33c6868682ced1ccac 100644 --- a/Stack/History/testHistoryView.cc +++ b/Stack/History/testHistoryView.cc @@ -8,7 +8,7 @@ #include <corsika/history/HistoryStackExtension.h> #include <corsika/history/Event.hpp> -#include <corsika/history/HistorySecondaryView.hpp> +#include <corsika/history/HistorySecondaryProducer.hpp> #include <corsika/stack/CombinedStack.h> #include <corsika/stack/dummy/DummyStack.h> @@ -49,16 +49,19 @@ using TestStack = corsika::stack::CombinedStack< actually needed. Keep an eye on this! */ #if defined(__clang__) -using TestStackView = corsika::stack::SecondaryView<typename TestStack::StackImpl, - StackWithHistoryInterface>; +using TheTestStackView = corsika::stack::SecondaryView<typename TestStack::StackImpl, + StackWithHistoryInterface, + history::HistorySecondaryProducer>; #elif defined(__GNUC__) || defined(__GNUG__) -using TestStackView = corsika::stack::MakeView<TestStack>::type; +//using TheTestStackView = corsika::stack::MakeView<TestStack, history::HistorySecondaryProducer>::type; +using TheTestStackView = corsika::stack::MakeView<TestStack, history::HistorySecondaryProducer>::type; #endif +using TestStackView = TheTestStackView; //history::HistorySecondaryView<TheTestStackView>; + TEST_CASE("HistoryStackExtension", "[stack]") { - logging::SetDefaultLevel(logging::level::debug); - logging::SetLevel(logging::level::trace); + logging::SetLevel(logging::level::debug); geometry::CoordinateSystem& dummyCS = geometry::RootCoordinateSystem::GetInstance().GetRootCoordinateSystem(); @@ -79,9 +82,9 @@ TEST_CASE("HistoryStackExtension", "[stack]") { CHECK(evt == nullptr); SECTION("interface test, view") { - + // add secondaries, 1st generation - history::HistorySecondaryView<TestStackView> hview0(p0); + TestStackView hview0(p0); auto const ev0 = p0.GetEvent(); CHECK(ev0 == nullptr); @@ -91,11 +94,11 @@ TEST_CASE("HistoryStackExtension", "[stack]") { // add 5 secondaries for (int i = 0; i < 5; ++i) { auto sec = hview0.AddSecondary( - std::tuple<particles::Code, units::si::HEPEnergyType, - corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ - particles::Code::Electron, 1.5_GeV, - corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), - Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); + std::tuple<particles::Code, units::si::HEPEnergyType, + corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ + particles::Code::Electron, 1.5_GeV, + corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), + Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); CHECK(sec.GetParentEventIndex() == i); CHECK(sec.GetEvent() != nullptr); @@ -105,55 +108,55 @@ TEST_CASE("HistoryStackExtension", "[stack]") { // read 1st genertion particle particle auto p1 = stack.GetNextParticle(); - history::HistorySecondaryView<TestStackView> hview1(p1); + TestStackView hview1(p1); - auto const ev1 = p1.GetEvent(); + auto const ev1 = p1.GetEvent(); - // add second generation of secondaries - // add 10 secondaries - for (int i = 0; i < 10; ++i) { - auto sec = hview1.AddSecondary( - std::tuple<particles::Code, units::si::HEPEnergyType, - corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ - particles::Code::Electron, 1.5_GeV, - corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), - Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); + // add second generation of secondaries + // add 10 secondaries + for (int i = 0; i < 10; ++i) { + auto sec = hview1.AddSecondary( + std::tuple<particles::Code, units::si::HEPEnergyType, + corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ + particles::Code::Electron, 1.5_GeV, + corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), + Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); - CHECK(sec.GetParentEventIndex() == i); - CHECK(sec.GetEvent()->parentEvent() == ev1); - CHECK(sec.GetEvent()->parentEvent()->parentEvent() == ev0); + CHECK(sec.GetParentEventIndex() == i); + CHECK(sec.GetEvent()->parentEvent() == ev1); + CHECK(sec.GetEvent()->parentEvent()->parentEvent() == ev0); - CHECK((stack.begin() + sec.GetEvent()->projectileIndex()).GetEvent() == - sec.GetEvent()->parentEvent()); - } + CHECK((stack.begin() + sec.GetEvent()->projectileIndex()).GetEvent() == + sec.GetEvent()->parentEvent()); + } - // read 2nd genertion particle particle - auto p2 = stack.GetNextParticle(); + // read 2nd genertion particle particle + auto p2 = stack.GetNextParticle(); - history::HistorySecondaryView<TestStackView> hview2(p2); + TestStackView hview2(p2); - auto const ev2 = p2.GetEvent(); + auto const ev2 = p2.GetEvent(); - // add third generation of secondaries - // add 15 secondaries - for (int i = 0; i < 15; ++i) { - C8LOG_TRACE("loop, view: " + std::to_string(i)); + // add third generation of secondaries + // add 15 secondaries + for (int i = 0; i < 15; ++i) { + C8LOG_TRACE("loop, view: " + std::to_string(i)); - auto sec = hview2.AddSecondary( - std::tuple<particles::Code, units::si::HEPEnergyType, - corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ - particles::Code::Electron, 1.5_GeV, - corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), - Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); - C8LOG_TRACE("loop, ---- " ); + auto sec = hview2.AddSecondary( + std::tuple<particles::Code, units::si::HEPEnergyType, + corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ + particles::Code::Electron, 1.5_GeV, + corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), + Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); + C8LOG_TRACE("loop, ---- "); - CHECK(sec.GetParentEventIndex() == i); - CHECK(sec.GetEvent()->parentEvent() == ev2); - CHECK(sec.GetEvent()->parentEvent()->parentEvent() == ev1); - CHECK(sec.GetEvent()->parentEvent()->parentEvent()->parentEvent() == ev0); - } + CHECK(sec.GetParentEventIndex() == i); + CHECK(sec.GetEvent()->parentEvent() == ev2); + CHECK(sec.GetEvent()->parentEvent()->parentEvent() == ev1); + CHECK(sec.GetEvent()->parentEvent()->parentEvent()->parentEvent() == ev0); + } - /* + /* Now, let's perform some history reading and checking based on p3 p3 should have 20 secondaries, and a projectile (with 15 @@ -188,36 +191,37 @@ TEST_CASE("HistoryStackExtension", "[stack]") { } SECTION("also test projectile access") { - - // add secondaries, 1st generation - history::HistorySecondaryView<TestStackView> hview0(p0); - auto proj0 = hview0.GetProjectile(); + + C8LOG_TRACE("projectile test"); + + // add secondaries, 1st generation + TestStackView hview0(p0); + auto proj0 = hview0.GetProjectile(); auto const ev0 = p0.GetEvent(); CHECK(ev0 == nullptr); C8LOG_TRACE("loop"); - + // add 5 secondaries for (int i = 0; i < 5; ++i) { C8LOG_TRACE("loop " + std::to_string(i)); auto sec = proj0.AddSecondary( - std::tuple<particles::Code, units::si::HEPEnergyType, - corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ - particles::Code::Electron, 1.5_GeV, - corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), - Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); - + std::tuple<particles::Code, units::si::HEPEnergyType, + corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ + particles::Code::Electron, 1.5_GeV, + corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), + Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); + CHECK(sec.GetParentEventIndex() == i); CHECK(sec.GetEvent() != nullptr); CHECK(sec.GetEvent()->parentEvent() == nullptr); } - CHECK(stack.getEntries()==6); - + CHECK(stack.getEntries() == 6); // read 1st genertion particle particle auto p1 = stack.GetNextParticle(); - history::HistorySecondaryView<TestStackView> hview1(p1); + TestStackView hview1(p1); auto proj1 = hview1.GetProjectile(); auto const ev1 = p1.GetEvent(); @@ -225,21 +229,20 @@ TEST_CASE("HistoryStackExtension", "[stack]") { // add 10 secondaries for (int i = 0; i < 10; ++i) { auto sec = proj1.AddSecondary( - std::tuple<particles::Code, units::si::HEPEnergyType, - corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ - particles::Code::Electron, 1.5_GeV, - corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), - Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); - + std::tuple<particles::Code, units::si::HEPEnergyType, + corsika::stack::MomentumVector, geometry::Point, units::si::TimeType>{ + particles::Code::Electron, 1.5_GeV, + corsika::stack::MomentumVector(dummyCS, {1_GeV, 1_GeV, 1_GeV}), + Point(dummyCS, {1 * meter, 1 * meter, 1 * meter}), 100_s}); + CHECK(sec.GetParentEventIndex() == i); CHECK(sec.GetEvent()->parentEvent() == ev1); - CHECK(sec.GetEvent()->parentEvent()->secondaries().size() == 10); + CHECK(sec.GetEvent()->secondaries().size() == i + 1); CHECK(sec.GetEvent()->parentEvent()->parentEvent() == ev0); - + CHECK((stack.begin() + sec.GetEvent()->projectileIndex()).GetEvent() == - sec.GetEvent()->parentEvent()); + sec.GetEvent()->parentEvent()); } - CHECK(stack.getEntries()==16); - + CHECK(stack.getEntries() == 16); } } diff --git a/Stack/NuclearStackExtension/NuclearStackExtension.h b/Stack/NuclearStackExtension/NuclearStackExtension.h index 0c0dbeff8fad1fcde39a60635ace06d57b163d50..79d4da2f9d5492e66f4e4472b91947f790536e1f 100644 --- a/Stack/NuclearStackExtension/NuclearStackExtension.h +++ b/Stack/NuclearStackExtension/NuclearStackExtension.h @@ -275,8 +275,8 @@ namespace corsika::stack { fNucleusRef[i2] = -1; // flag as non-nucleus fNuclearA.erase(fNuclearA.cbegin() + ref2); // remove data for i2 fNuclearZ.erase(fNuclearZ.cbegin() + ref2); // remove data for i2 - const int n = fNucleusRef.size(); // update fNucleusRef: indices above ref2 - // must be decremented by 1 + const int n = fNucleusRef.size(); // update fNucleusRef: indices above ref2 + // must be decremented by 1 for (int i = 0; i < n; ++i) { if (fNucleusRef[i] > ref2) { fNucleusRef[i] -= 1; } }