Skip to content

Commit

Permalink
option to discard photons if no edep in germanium
Browse files Browse the repository at this point in the history
  • Loading branch information
ManuelHu committed May 7, 2024
1 parent 16e75ad commit 0778f10
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 9 deletions.
6 changes: 6 additions & 0 deletions include/RMGGermaniumOutputScheme.hh
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ class RMGGermaniumOutputScheme : public RMGVOutputScheme {
inline void SetEdepCutHigh(double threshold) { fEdepCutHigh = threshold; }
inline void AddEdepCutDetector(int det_uid) { fEdepCutDetectors.insert(det_uid); }

[[nodiscard]] inline bool GetDiscardPhotonsIfNoGermaniumEdep() const {
return fDiscardPhotonsIfNoGermaniumEdep;
}

private:

RMGGermaniumDetectorHitsCollection* GetHitColl(const G4Event*);
Expand All @@ -49,6 +53,8 @@ class RMGGermaniumOutputScheme : public RMGVOutputScheme {
double fEdepCutLow = -1;
double fEdepCutHigh = -1;
std::set<int> fEdepCutDetectors;

bool fDiscardPhotonsIfNoGermaniumEdep = false;
};

#endif
Expand Down
6 changes: 4 additions & 2 deletions include/RMGRunAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,10 @@ class RMGRunAction : public G4UserRunAction {

[[nodiscard]] inline int GetCurrentRunPrintModulo() const { return fCurrentPrintModulo; }

inline auto& GetOutputDataFields(RMGHardware::DetectorType d_type) {
return fOutputDataFields.at(d_type);
inline std::shared_ptr<RMGVOutputScheme> GetOutputDataFields(RMGHardware::DetectorType d_type) {
auto it = fOutputDataFields.find(d_type);
if (it != fOutputDataFields.end()) return (*it).second;
return nullptr;
}
inline void ClearOutputDataFields() {
for (auto& el : fOutputDataFields) el.second->ClearBeforeEvent();
Expand Down
6 changes: 3 additions & 3 deletions include/RMGStackingAction.hh
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
#include "G4UserStackingAction.hh"

class G4Track;
class RMGEventAction;
class RMGRunAction;
class RMGStackingAction : public G4UserStackingAction {

public:

RMGStackingAction(RMGEventAction*);
RMGStackingAction(RMGRunAction*);
~RMGStackingAction() = default;

RMGStackingAction(RMGStackingAction const&) = delete;
Expand All @@ -38,7 +38,7 @@ class RMGStackingAction : public G4UserStackingAction {

private:

RMGEventAction* fEventAction = nullptr;
RMGRunAction* fRunAction = nullptr;
};

#endif
Expand Down
4 changes: 4 additions & 0 deletions src/RMGGermaniumOutputScheme.cc
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,10 @@ void RMGGermaniumOutputScheme::DefineCommands() {
.SetGuidance("Take this detector into account for the filtering by /EdepThreshold.")
.SetParameterName("det_uid", false)
.SetStates(G4State_Idle);

fMessenger->DeclareProperty("DiscardPhotonsIfNoGermaniumEdep", fDiscardPhotonsIfNoGermaniumEdep)
.SetGuidance("Disable the automatic overlap check after loading a GDML file")
.SetStates(G4State_Idle);
}

// vim: tabstop=2 shiftwidth=2 expandtab
32 changes: 29 additions & 3 deletions src/RMGStackingAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,41 @@

#include "RMGStackingAction.hh"

#include "G4EventManager.hh"
#include "G4OpticalPhoton.hh"
#include "G4Track.hh"

#include "RMGEventAction.hh"
#include "RMGGermaniumOutputScheme.hh"
#include "RMGHardware.hh"
#include "RMGManager.hh"
#include "RMGOpticalOutputScheme.hh"
#include "RMGRunAction.hh"

RMGStackingAction::RMGStackingAction(RMGEventAction* eventaction) : fEventAction(eventaction) {}
RMGStackingAction::RMGStackingAction(RMGRunAction* runaction) : fRunAction(runaction) {}

G4ClassificationOfNewTrack RMGStackingAction::ClassifyNewTrack(const G4Track* /*aTrack*/) {
G4ClassificationOfNewTrack RMGStackingAction::ClassifyNewTrack(const G4Track* aTrack) {
// defer tracking of optical photons.
if (aTrack->GetDefinition() == G4OpticalPhoton::OpticalPhotonDefinition()) return fWaiting;
return fUrgent;
}

void RMGStackingAction::NewStage() {}
void RMGStackingAction::NewStage() {
auto ge_output = fRunAction->GetOutputDataFields(RMGHardware::DetectorType::kGermanium);
if (ge_output == nullptr) return;

bool discard_photons =
(dynamic_cast<RMGGermaniumOutputScheme&>(*ge_output)).GetDiscardPhotonsIfNoGermaniumEdep();
if (!discard_photons) return;

auto run_man = RMGManager::Instance()->GetG4RunManager();
const auto event = run_man->GetCurrentEvent();
if (ge_output->ShouldDiscardEvent(event)) {
// discard all waiting events, as there was no energy deposition in Germanium.
auto stack_man = G4EventManager::GetEventManager()->GetStackManager();
stack_man->clear();
}
}

void RMGStackingAction::PrepareNewEvent() {}

Expand Down
2 changes: 1 addition & 1 deletion src/RMGUserAction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void RMGUserAction::Build() const {
this->SetUserAction(generator_primary);
this->SetUserAction(event_action);
this->SetUserAction(run_action);
this->SetUserAction(new RMGStackingAction(event_action));
this->SetUserAction(new RMGStackingAction(run_action));
this->SetUserAction(new RMGSteppingAction(event_action));
this->SetUserAction(new RMGTrackingAction(event_action));
}
Expand Down

0 comments on commit 0778f10

Please sign in to comment.