Commit 0fbc3ebd authored by Simon Spannagel's avatar Simon Spannagel
Browse files

Merge branch 'geant4SteppingAction' into 'master'

Added step hook for Geant4, allowing for aborting events.

See merge request allpix-squared/allpix-squared!1053
parents ff302691 12a8af61
Loading
Loading
Loading
Loading
+4 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@
#include "core/config/Configuration.hpp"

#include "SetTrackInfoUserHookG4.hpp"
#include "StepInfoUserHookG4.hpp"

namespace allpix {
    /**
@@ -36,6 +37,9 @@ namespace allpix {

            // tracker hook
            SetUserAction(new SetTrackInfoUserHookG4());

            // step hook
            SetUserAction(new StepInfoUserHookG4());
        };

        /**
+1 −0
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ ALLPIX_MODULE_SOURCES(
    TrackInfoG4.cpp
    TrackInfoManager.cpp
    SetTrackInfoUserHookG4.cpp
    StepInfoUserHookG4.cpp
    SDAndFieldConstruction.cpp)

# Allpix Geant4 interface is required for this module
+26 −0
Original line number Diff line number Diff line
/**
 * @file
 * @brief Implements a user hook for Geant4 stepping action to catch problematic events and abort them
 *
 * @copyright Copyright (c) 2023-2024 CERN and the Allpix Squared authors.
 * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
 * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
 * Intergovernmental Organization or submit itself to any jurisdiction.
 * SPDX-License-Identifier: MIT
 */

#include "StepInfoUserHookG4.hpp"
#include "DepositionGeant4Module.hpp"

#include "tools/geant4/RunManager.hpp"

using namespace allpix;

void StepInfoUserHookG4::UserSteppingAction(const G4Step* aStep) {
    if(aStep->GetStepLength() < 0) {
        LOG(WARNING) << "Negative step length found; aborting event.";

        // Load the G4 run manager (which is owned by the geometry builder), and call AbortRun() to abort the current event
        G4RunManager::GetRunManager()->AbortRun();
    }
}
+42 −0
Original line number Diff line number Diff line
/**
 * @file
 * @brief Defines a user hook for Geant4 stepping action to catch problematic events and abort them
 *
 * @copyright Copyright (c) 2023-2024 CERN and the Allpix Squared authors.
 * This software is distributed under the terms of the MIT License, copied verbatim in the file "LICENSE.md".
 * In applying this license, CERN does not waive the privileges and immunities granted to it by virtue of its status as an
 * Intergovernmental Organization or submit itself to any jurisdiction.
 * SPDX-License-Identifier: MIT
 */

#ifndef StepInfoUserHookG4_H
#define StepInfoUserHookG4_H 1

#include "G4Step.hh"
#include "G4UserSteppingAction.hh"

namespace allpix {
    /**
     * @brief Allows access to the info of each Geant4 step
     */
    class StepInfoUserHookG4 : public G4UserSteppingAction {
    public:
        /**
         * @brief Default constructor
         */
        explicit StepInfoUserHookG4() = default;

        /**
         * @brief Default destructor
         */
        ~StepInfoUserHookG4() override = default;

        /**
         * @brief Called for every step in Geant4
         * @param aStep The pointer to the G4Step for which this routine is called
         */
        void UserSteppingAction(const G4Step* aStep) override;
    };

} // namespace allpix
#endif /* StepInfoUserHookG4_H */