From fddb8d96941aff2b7f2b0a38de990404bd0567ae Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 6 May 2024 15:02:38 +0000 Subject: [PATCH] [pre-commit.ci] Automatic python and c++ formatting --- .../opengate_lib/GateChemistryActor.cpp | 2 +- .../GateChemistryLongTimeActor.cpp | 207 +++++++++--------- .../opengate_lib/GateChemistryLongTimeActor.h | 45 ++-- .../pyGateChemistryLongTimeActor.cpp | 4 +- opengate/actors/chemistryactors.py | 6 +- 5 files changed, 137 insertions(+), 127 deletions(-) diff --git a/core/opengate_core/opengate_lib/GateChemistryActor.cpp b/core/opengate_core/opengate_lib/GateChemistryActor.cpp index d6ddc438d..177e5a1d3 100644 --- a/core/opengate_core/opengate_lib/GateChemistryActor.cpp +++ b/core/opengate_core/opengate_lib/GateChemistryActor.cpp @@ -40,7 +40,7 @@ GateChemistryActor::GateChemistryActor(pybind11::dict &user_info) _timeStepModelStr = DictGetStr(user_info, "timestep_model"); _endTime = DictGetDouble(user_info, "end_time"); _reactions = getReactionInputs(user_info, "reactions"); - _moleculeCounterVerbose = DictGetInt(user_info, "molecule_counter_verbose"); + _moleculeCounterVerbose = DictGetInt(user_info, "molecule_counter_verbose"); setTimeBinsCount(DictGetInt(user_info, "time_bins_count")); } diff --git a/core/opengate_core/opengate_lib/GateChemistryLongTimeActor.cpp b/core/opengate_core/opengate_lib/GateChemistryLongTimeActor.cpp index 7f3c52ac5..3cadbe100 100644 --- a/core/opengate_core/opengate_lib/GateChemistryLongTimeActor.cpp +++ b/core/opengate_core/opengate_lib/GateChemistryLongTimeActor.cpp @@ -8,16 +8,16 @@ #include "GateChemistryLongTimeActor.h" #include +#include #include #include -#include -#include #include #include #include #include #include #include +#include #include #include #include @@ -26,85 +26,88 @@ #include #include #include -#include #include +#include #include #include +#include "GateHelpersDict.h" #include #include -#include "GateHelpersDict.h" #include "../g4_bindings/chemistryadaptator.h" #include "GateVActor.h" -GateChemistryLongTimeActor::ChemistryWorld::ChemistryWorld(GateChemistryLongTimeActor *actor): - _actor(actor) -{ -} +GateChemistryLongTimeActor::ChemistryWorld::ChemistryWorld( + GateChemistryLongTimeActor *actor) + : _actor(actor) {} void GateChemistryLongTimeActor::ChemistryWorld::ConstructChemistryBoundary() { - auto const &size = _actor->_boundarySize; - std::initializer_list boundingBox{ - // high, low - size[0], -size[0], // x - size[1], -size[1], // y - size[2], -size[2] // z - }; - fpChemistryBoundary = std::make_unique(boundingBox); + auto const &size = _actor->_boundarySize; + std::initializer_list boundingBox{ + // high, low + size[0], -size[0], // x + size[1], -size[1], // y + size[2], -size[2] // z + }; + fpChemistryBoundary = std::make_unique(boundingBox); } -void GateChemistryLongTimeActor::ChemistryWorld::ConstructChemistryComponents() { - constexpr auto water = 55.3; // from NIST material database - constexpr auto moleLiter = CLHEP::mole * CLHEP::liter; +void GateChemistryLongTimeActor::ChemistryWorld:: + ConstructChemistryComponents() { + constexpr auto water = 55.3; // from NIST material database + constexpr auto moleLiter = CLHEP::mole * CLHEP::liter; constexpr double pKw = 14; // at 25°C pK of water is 14 - auto const & pH = _actor->_pH; + auto const &pH = _actor->_pH; - auto* moleculeTable = G4MoleculeTable::Instance(); + auto *moleculeTable = G4MoleculeTable::Instance(); - auto* mH2O = moleculeTable->GetConfiguration("H2O"); + auto *mH2O = moleculeTable->GetConfiguration("H2O"); fpChemicalComponent[mH2O] = water / moleLiter; - auto* mH3Op = moleculeTable->GetConfiguration("H3Op(B)"); - fpChemicalComponent[mH3Op] = std::pow(10, - pH) / moleLiter; // pH = 7 + auto *mH3Op = moleculeTable->GetConfiguration("H3Op(B)"); + fpChemicalComponent[mH3Op] = std::pow(10, -pH) / moleLiter; // pH = 7 - auto* mOHm = moleculeTable->GetConfiguration("OHm(B)"); + auto *mOHm = moleculeTable->GetConfiguration("OHm(B)"); fpChemicalComponent[mOHm] = std::pow(10, -(pKw - pH)) / moleLiter; // pH = 7 - auto* mO2 = moleculeTable->GetConfiguration("O2"); + auto *mO2 = moleculeTable->GetConfiguration("O2"); fpChemicalComponent[mO2] = (0. / 100) * 0.0013 / moleLiter; - // apply scavanger configurations - for(auto const &scavengerConfig : _actor->_scavengerConfigs) { - auto* m = moleculeTable->GetConfiguration(scavengerConfig.species); - auto const &concentration = scavengerConfig.concentration; - auto const &unitWithPrefix = scavengerConfig.unit; - if(not unitWithPrefix.empty()) { - char unit = *unitWithPrefix.rbegin(); - if(unit == 'M') { - double factor = 1; - if(unitWithPrefix.size() > 1) { - auto prefix = unitWithPrefix.substr(0, unitWithPrefix.size()-1); - if(prefix == "u") factor = 1e-6; - else if(prefix == "m") factor = 1e-3; - else // TODO error - ; - } - - fpChemicalComponent[m] = factor * concentration / moleLiter; - } else if(unit == '%') { - constexpr auto o2 = 0.0013; - double concentrationInM = - fpChemicalComponent[m] = (concentration / 100) * o2 / moleLiter; - } - } - } + // apply scavanger configurations + for (auto const &scavengerConfig : _actor->_scavengerConfigs) { + auto *m = moleculeTable->GetConfiguration(scavengerConfig.species); + auto const &concentration = scavengerConfig.concentration; + auto const &unitWithPrefix = scavengerConfig.unit; + if (not unitWithPrefix.empty()) { + char unit = *unitWithPrefix.rbegin(); + if (unit == 'M') { + double factor = 1; + if (unitWithPrefix.size() > 1) { + auto prefix = unitWithPrefix.substr(0, unitWithPrefix.size() - 1); + if (prefix == "u") + factor = 1e-6; + else if (prefix == "m") + factor = 1e-3; + else // TODO error + ; + } + + fpChemicalComponent[m] = factor * concentration / moleLiter; + } else if (unit == '%') { + constexpr auto o2 = 0.0013; + double concentrationInM = fpChemicalComponent[m] = + (concentration / 100) * o2 / moleLiter; + } + } + } } /* *** */ -GateChemistryLongTimeActor::GateChemistryLongTimeActor(pybind11::dict &user_info) +GateChemistryLongTimeActor::GateChemistryLongTimeActor( + pybind11::dict &user_info) : GateVActor(user_info, true) { fActions.insert("NewStage"); fActions.insert("EndOfRunAction"); @@ -115,28 +118,29 @@ GateChemistryLongTimeActor::GateChemistryLongTimeActor(pybind11::dict &user_info _timeStepModelStr = DictGetStr(user_info, "timestep_model"); _endTime = DictGetDouble(user_info, "end_time"); _reactions = getReactionInputs(user_info, "reactions"); - _moleculeCounterVerbose = DictGetInt(user_info, "molecule_counter_verbose"); + _moleculeCounterVerbose = DictGetInt(user_info, "molecule_counter_verbose"); setTimeBinsCount(DictGetInt(user_info, "time_bins_count")); - _pH = DictGetDouble(user_info, "pH"); - _scavengerConfigs = getScavengerConfigs(user_info, "scavengers"); + _pH = DictGetDouble(user_info, "pH"); + _scavengerConfigs = getScavengerConfigs(user_info, "scavengers"); - _doseCutOff = DictGetDouble(user_info, "dose_cutoff"); + _doseCutOff = DictGetDouble(user_info, "dose_cutoff"); - _resetScavengerForEachBeam = DictGetBool(user_info, "reset_scavenger_for_each_beam"); + _resetScavengerForEachBeam = + DictGetBool(user_info, "reset_scavenger_for_each_beam"); - // TODO remove - _boundarySize = DictGetVecDouble(user_info, "boundary_size"); + // TODO remove + _boundarySize = DictGetVecDouble(user_info, "boundary_size"); } void GateChemistryLongTimeActor::Initialize(G4HCofThisEvent *hce) { GateVActor::Initialize(hce); - _chemistryWorld = std::make_unique(this); - _chemistryWorld->ConstructChemistryComponents(); + _chemistryWorld = std::make_unique(this); + _chemistryWorld->ConstructChemistryComponents(); - G4Scheduler::Instance()->ResetScavenger(_resetScavengerForEachBeam); + G4Scheduler::Instance()->ResetScavenger(_resetScavengerForEachBeam); G4MoleculeCounter::Instance()->SetVerbose(_moleculeCounterVerbose); G4MoleculeCounter::Instance()->Use(); @@ -249,33 +253,36 @@ void GateChemistryLongTimeActor::SteppingAction(G4Step *step) { edep *= step->GetPreStepPoint()->GetWeight(); _edepSum += edep; - auto *track = step->GetTrack(); - - if(track->GetParentID() == 0 && track->GetCurrentStepNumber() == 1) { - constexpr auto density = .001; - auto volume = _chemistryWorld->GetChemistryBoundary()->Volume(); - double dose = (_edepSum / CLHEP::eV) / (density * volume * 6.242e+18); - if(dose > _doseCutOff) { - auto *eventManager = G4EventManager::GetEventManager(); - auto *primary = eventManager->GetConstCurrentEvent()->GetPrimaryVertex()->GetPrimary(); - auto const &name = primary->GetParticleDefinition()->GetParticleName(); - auto energy = primary->GetKineticEnergy(); - G4cout << "[GateChemistryLongTimeActor] stop beam line '" << name << "' (" << energy << " MeV) at dose: " << dose << " Gy" << G4endl; - - track->SetTrackStatus(fStopAndKill); - auto const *secondaries = track->GetStep()->GetSecondaryInCurrentStep(); - for (auto const *secondary : *secondaries) { - if (secondary != nullptr) { - // FIXME - // from UHDR example - // must find how to get non-const access to secondaries - auto *secondaryMut = const_cast(secondary); - secondaryMut->SetTrackStatus(fStopAndKill); - } - } - eventManager->GetStackManager()->ClearUrgentStack(); - } - } + auto *track = step->GetTrack(); + + if (track->GetParentID() == 0 && track->GetCurrentStepNumber() == 1) { + constexpr auto density = .001; + auto volume = _chemistryWorld->GetChemistryBoundary()->Volume(); + double dose = (_edepSum / CLHEP::eV) / (density * volume * 6.242e+18); + if (dose > _doseCutOff) { + auto *eventManager = G4EventManager::GetEventManager(); + auto *primary = eventManager->GetConstCurrentEvent() + ->GetPrimaryVertex() + ->GetPrimary(); + auto const &name = primary->GetParticleDefinition()->GetParticleName(); + auto energy = primary->GetKineticEnergy(); + G4cout << "[GateChemistryLongTimeActor] stop beam line '" << name << "' (" + << energy << " MeV) at dose: " << dose << " Gy" << G4endl; + + track->SetTrackStatus(fStopAndKill); + auto const *secondaries = track->GetStep()->GetSecondaryInCurrentStep(); + for (auto const *secondary : *secondaries) { + if (secondary != nullptr) { + // FIXME + // from UHDR example + // must find how to get non-const access to secondaries + auto *secondaryMut = const_cast(secondary); + secondaryMut->SetTrackStatus(fStopAndKill); + } + } + eventManager->GetStackManager()->ClearUrgentStack(); + } + } } void GateChemistryLongTimeActor::NewStage() { @@ -335,24 +342,24 @@ pybind11::dict GateChemistryLongTimeActor::getData() const { GateChemistryLongTimeActor::ScavengerConfigs GateChemistryLongTimeActor::getScavengerConfigs(pybind11::dict &user_info, - std::string const &key) { - ScavengerConfigs scavengerConfigs; + std::string const &key) { + ScavengerConfigs scavengerConfigs; - auto configs = DictGetVecList(user_info, key); - for (auto const &config : configs) { - ScavengerConfig scavengerConfig; + auto configs = DictGetVecList(user_info, key); + for (auto const &config : configs) { + ScavengerConfig scavengerConfig; - scavengerConfig.species = config[0].cast(); - scavengerConfig.concentration = config[1].cast(); - scavengerConfig.unit = config[2].cast(); - } + scavengerConfig.species = config[0].cast(); + scavengerConfig.concentration = config[1].cast(); + scavengerConfig.unit = config[2].cast(); + } - return scavengerConfigs; + return scavengerConfigs; } GateChemistryLongTimeActor::ReactionInputs GateChemistryLongTimeActor::getReactionInputs(pybind11::dict &user_info, - std::string const &key) { + std::string const &key) { ReactionInputs reactionInputs; auto reactions = DictGetVecList(user_info, key); diff --git a/core/opengate_core/opengate_lib/GateChemistryLongTimeActor.h b/core/opengate_core/opengate_lib/GateChemistryLongTimeActor.h index 71d223a16..8f79f3a71 100644 --- a/core/opengate_core/opengate_lib/GateChemistryLongTimeActor.h +++ b/core/opengate_core/opengate_lib/GateChemistryLongTimeActor.h @@ -38,11 +38,11 @@ class GateChemistryLongTimeActor : public GateVActor { [[nodiscard]] pybind11::dict getData() const; public: - struct ScavengerConfig { - std::string species; - double concentration; - std::string unit; - }; + struct ScavengerConfig { + std::string species; + double concentration; + std::string unit; + }; using ScavengerConfigs = std::vector; @@ -67,21 +67,20 @@ class GateChemistryLongTimeActor : public GateVActor { using SpeciesMap = std::map; private: - class ChemistryWorld: public G4VChemistryWorld { - public: - ChemistryWorld(GateChemistryLongTimeActor *actor); - - void ConstructChemistryBoundary() override; - void ConstructChemistryComponents() override; + class ChemistryWorld : public G4VChemistryWorld { + public: + ChemistryWorld(GateChemistryLongTimeActor *actor); - private: - GateChemistryLongTimeActor *_actor; - }; + void ConstructChemistryBoundary() override; + void ConstructChemistryComponents() override; + private: + GateChemistryLongTimeActor *_actor; + }; protected: - static ScavengerConfigs getScavengerConfigs(pybind11::dict &user_info, - std::string const &key); + static ScavengerConfigs getScavengerConfigs(pybind11::dict &user_info, + std::string const &key); static ReactionInputs getReactionInputs(pybind11::dict &user_info, std::string const &key); @@ -99,17 +98,17 @@ class GateChemistryLongTimeActor : public GateVActor { double _endTime; std::vector _reactions; - std::unique_ptr _chemistryWorld; + std::unique_ptr _chemistryWorld; - double _pH = 7; - ScavengerConfigs _scavengerConfigs; + double _pH = 7; + ScavengerConfigs _scavengerConfigs; - double _doseCutOff = 0; + double _doseCutOff = 0; - bool _resetScavengerForEachBeam = false; + bool _resetScavengerForEachBeam = false; - // TODO remove - std::vector _boundarySize; + // TODO remove + std::vector _boundarySize; }; #endif diff --git a/core/opengate_core/opengate_lib/pyGateChemistryLongTimeActor.cpp b/core/opengate_core/opengate_lib/pyGateChemistryLongTimeActor.cpp index f6d7c02cc..2a37901ef 100644 --- a/core/opengate_core/opengate_lib/pyGateChemistryLongTimeActor.cpp +++ b/core/opengate_core/opengate_lib/pyGateChemistryLongTimeActor.cpp @@ -14,8 +14,8 @@ namespace py = pybind11; void init_GateChemistryLongTimeActor(py::module &m) { py::class_, GateVActor>( - m, "GateChemistryLongTimeActor") + std::unique_ptr, + GateVActor>(m, "GateChemistryLongTimeActor") .def(py::init()) .def("get_times", &GateChemistryLongTimeActor::getTimes) .def("get_data", &GateChemistryLongTimeActor::getData); diff --git a/opengate/actors/chemistryactors.py b/opengate/actors/chemistryactors.py index 42ae95cf0..e55d0af47 100644 --- a/opengate/actors/chemistryactors.py +++ b/opengate/actors/chemistryactors.py @@ -65,7 +65,11 @@ def set_default_user_info(user_info): user_info.reset_scavenger_for_each_beam = False # TODO remove - user_info.boundary_size = [0.8 * g4_units.um, 0.8 * g4_units.um, 0.8 * g4_units.um] + user_info.boundary_size = [ + 0.8 * g4_units.um, + 0.8 * g4_units.um, + 0.8 * g4_units.um, + ] def __init__(self, user_info): ActorBase.__init__(self, user_info)