Commit 2162602b authored by Håkan Wennlöf's avatar Håkan Wennlöf Committed by Simon Spannagel
Browse files

Added step hook for Geant4, allowing for aborting events.

Very useful for the ones with negative step length, that take literally forever.
parent ff302691
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 to assign custom track information via TrackInfoG4 objects
 *
 * @copyright Copyright (c) 2018-2020 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.
 */

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

#include "tools/geant4/RunManager.hpp"

using namespace allpix;

void StepInfoUserHookG4::UserSteppingAction(const G4Step* aStep) {
    LOG(DEBUG) << "Step length: " << aStep->GetStepLength();
    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 AbortEvent()
        G4RunManager::GetRunManager()->AbortEvent();
    }
}
+42 −0
Original line number Diff line number Diff line
/**
 * @file
 * @brief Defines a user hook for Geant4 to assign custom track information via TrackInfoG4 objects. This includes custom
 * (unique) track ids.
 *
 * @copyright Copyright (c) 2018-2020 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.
 */

#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 */