-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #163 from acoussat/efficiency-actor
- Loading branch information
Showing
8 changed files
with
370 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
core/opengate_core/opengate_lib/digitizer/GateDigitizerEfficiencyActor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/* -------------------------------------------------- | ||
Copyright (C): OpenGATE Collaboration | ||
This software is distributed under the terms | ||
of the GNU Lesser General Public Licence (LGPL) | ||
See LICENSE.md for further details | ||
-------------------------------------------------- */ | ||
|
||
#include "GateDigitizerEfficiencyActor.h" | ||
#include "../GateHelpersDict.h" | ||
#include "GateDigiAdderInVolume.h" | ||
#include "GateDigiCollectionManager.h" | ||
#include <Randomize.hh> | ||
#include <iostream> | ||
|
||
GateDigitizerEfficiencyActor::GateDigitizerEfficiencyActor(py::dict &user_info) | ||
: GateVDigitizerWithOutputActor(user_info, true) { | ||
|
||
// actions | ||
fActions.insert("EndOfEventAction"); | ||
|
||
// efficiency method | ||
fEfficiency = DictGetDouble(user_info, "efficiency"); | ||
} | ||
|
||
GateDigitizerEfficiencyActor::~GateDigitizerEfficiencyActor() = default; | ||
|
||
void GateDigitizerEfficiencyActor::DigitInitialize( | ||
const std::vector<std::string> &attributes_not_in_filler) { | ||
GateVDigitizerWithOutputActor::DigitInitialize(attributes_not_in_filler); | ||
} | ||
|
||
void GateDigitizerEfficiencyActor::EndOfEventAction( | ||
const G4Event * /*unused*/) { | ||
// loop on all digi of this events | ||
auto &l = fThreadLocalData.Get(); | ||
auto &lr = fThreadLocalVDigitizerData.Get(); | ||
auto &iter = lr.fInputIter; | ||
iter.GoToBegin(); | ||
while (!iter.IsAtEnd()) { | ||
if (G4UniformRand() < fEfficiency) { | ||
auto &i = lr.fInputIter.fIndex; | ||
lr.fDigiAttributeFiller->Fill(i); | ||
} | ||
iter++; | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
core/opengate_core/opengate_lib/digitizer/GateDigitizerEfficiencyActor.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* -------------------------------------------------- | ||
Copyright (C): OpenGATE Collaboration | ||
This software is distributed under the terms | ||
of the GNU Lesser General Public Licence (LGPL) | ||
See LICENSE.md for further details | ||
-------------------------------------------------- */ | ||
|
||
#ifndef GateDigitizerEfficiencyActor_h | ||
#define GateDigitizerEfficiencyActor_h | ||
|
||
#include "../GateVActor.h" | ||
#include "GateDigiCollection.h" | ||
#include "GateDigiCollectionIterator.h" | ||
#include "GateHelpersDigitizer.h" | ||
#include "GateTDigiAttribute.h" | ||
#include "GateVDigitizerWithOutputActor.h" | ||
#include <G4Cache.hh> | ||
#include <pybind11/stl.h> | ||
|
||
namespace py = pybind11; | ||
|
||
/* | ||
* Digitizer module for simulating detector efficiency. | ||
*/ | ||
|
||
class GateDigitizerEfficiencyActor : public GateVDigitizerWithOutputActor { | ||
|
||
public: | ||
// constructor | ||
explicit GateDigitizerEfficiencyActor(py::dict &user_info); | ||
|
||
// destructor | ||
~GateDigitizerEfficiencyActor() override; | ||
|
||
// Called every time an Event ends (all threads) | ||
void EndOfEventAction(const G4Event *event) override; | ||
|
||
protected: | ||
void DigitInitialize( | ||
const std::vector<std::string> &attributes_not_in_filler) override; | ||
|
||
std::string fEfficiencyAttributeName; | ||
GateVDigiAttribute *fOutputEfficiencyAttribute{}; | ||
double fEfficiency; | ||
|
||
// During computation (thread local) | ||
struct threadLocalT { | ||
double *fAttDValue{}; | ||
}; | ||
G4Cache<threadLocalT> fThreadLocalData; | ||
}; | ||
|
||
#endif // GateDigitizerEfficiencyActor_h |
21 changes: 21 additions & 0 deletions
21
core/opengate_core/opengate_lib/digitizer/pyGateDigitizerEfficiencyActor.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
/* -------------------------------------------------- | ||
Copyright (C): OpenGATE Collaboration | ||
This software is distributed under the terms | ||
of the GNU Lesser General Public Licence (LGPL) | ||
See LICENSE.md for further details | ||
-------------------------------------------------- */ | ||
|
||
#include <pybind11/pybind11.h> | ||
#include <pybind11/stl.h> | ||
|
||
namespace py = pybind11; | ||
|
||
#include "GateDigitizerEfficiencyActor.h" | ||
|
||
void init_GateDigitizerEfficiencyActor(py::module &m) { | ||
|
||
py::class_<GateDigitizerEfficiencyActor, | ||
std::unique_ptr<GateDigitizerEfficiencyActor, py::nodelete>, | ||
GateVActor>(m, "GateDigitizerEfficiencyActor") | ||
.def(py::init<py::dict &>()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import opengate as gate | ||
import opengate_core as g4 | ||
|
||
|
||
class DigitizerEfficiencyActor(g4.GateDigitizerEfficiencyActor, gate.ActorBase): | ||
""" | ||
Digitizer module for simulating efficiency. | ||
""" | ||
|
||
type_name = "DigitizerEfficiencyActor" | ||
|
||
@staticmethod | ||
def set_default_user_info(user_info): | ||
gate.ActorBase.set_default_user_info(user_info) | ||
user_info.attributes = [] | ||
user_info.output = "efficiency.root" | ||
user_info.input_digi_collection = "Hits" | ||
user_info.skip_attributes = [] | ||
user_info.clear_every = 1e5 | ||
user_info.efficiency = 1.0 # keep everything | ||
|
||
def __init__(self, user_info): | ||
# check and adjust parameters | ||
self.set_param(user_info) | ||
# base classes | ||
gate.ActorBase.__init__(self, user_info) | ||
g4.GateDigitizerEfficiencyActor.__init__(self, user_info.__dict__) | ||
actions = {"StartSimulationAction", "EndSimulationAction"} | ||
self.AddActions(actions) | ||
|
||
def set_param(self, user_info): | ||
efficiency = user_info.efficiency | ||
if not (0.0 <= efficiency <= 1.0): | ||
gate.warning(f"Efficency set to {efficiency}, which is not in [0;1].") | ||
|
||
def __del__(self): | ||
pass | ||
|
||
def __str__(self): | ||
s = f"DigitizerEfficiencyActor {self.user_info.name}" | ||
return s | ||
|
||
def StartSimulationAction(self): | ||
g4.GateDigitizerEfficiencyActor.StartSimulationAction(self) | ||
|
||
def EndSimulationAction(self): | ||
g4.GateDigitizerEfficiencyActor.EndSimulationAction(self) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.