From a6dcf70dbf9f03b9dc35cc5065fc7aee0e1a8e0e Mon Sep 17 00:00:00 2001 From: YiHui Liu Date: Thu, 19 May 2022 11:47:35 +0800 Subject: [PATCH] add: user action, edep statistic; --- CMakeLists.txt | 1 - G4.code-workspace | 13 +++++- include/DetectorConstruction.h | 4 +- include/EventAction.h | 22 +++++++++ include/RunAction.h | 24 ++++++++++ macro/GCR_Al.mac | 15 ++++++ macro/GCR_Ar.mac | 15 ++++++ macro/GCR_B.mac | 15 ++++++ macro/GCR_Be.mac | 15 ++++++ macro/GCR_C.mac | 15 ++++++ macro/GCR_Ca.mac | 15 ++++++ macro/GCR_Cl.mac | 15 ++++++ macro/GCR_Co.mac | 15 ++++++ macro/GCR_Cr.mac | 15 ++++++ macro/GCR_F.mac | 15 ++++++ macro/GCR_Fe.mac | 15 ++++++ macro/GCR_H.mac | 15 ++++++ macro/GCR_He.mac | 15 ++++++ macro/GCR_K.mac | 15 ++++++ macro/GCR_Li.mac | 15 ++++++ macro/GCR_Mg.mac | 15 ++++++ macro/GCR_Mn.mac | 15 ++++++ macro/GCR_N.mac | 15 ++++++ macro/GCR_Na.mac | 15 ++++++ macro/GCR_Ne.mac | 15 ++++++ macro/GCR_Ni.mac | 15 ++++++ macro/GCR_O.mac | 15 ++++++ macro/GCR_P.mac | 15 ++++++ macro/GCR_S.mac | 15 ++++++ macro/GCR_Sc.mac | 15 ++++++ macro/GCR_Si.mac | 15 ++++++ macro/GCR_Ti.mac | 15 ++++++ macro/GCR_V.mac | 15 ++++++ electron.mac => macro/TE.mac | 8 ++-- macro/TP.mac | 15 ++++++ src/ActionInitialization.cpp | 12 ++++- src/DetectorConstruction.cpp | 61 ++++++++++++++++++++---- src/EventAction.cpp | 22 +++++++++ src/G4HumanPhantomSD.cpp | 7 +-- src/G4MIRDLiver.cpp | 2 +- src/G4MIRDThyroid.cpp | 2 +- src/PrimaryGeneratorAction.cpp | 2 +- src/RunAction.cpp | 85 ++++++++++++++++++++++++++++++++++ 43 files changed, 675 insertions(+), 25 deletions(-) create mode 100644 include/EventAction.h create mode 100644 include/RunAction.h create mode 100644 macro/GCR_Al.mac create mode 100644 macro/GCR_Ar.mac create mode 100644 macro/GCR_B.mac create mode 100644 macro/GCR_Be.mac create mode 100644 macro/GCR_C.mac create mode 100644 macro/GCR_Ca.mac create mode 100644 macro/GCR_Cl.mac create mode 100644 macro/GCR_Co.mac create mode 100644 macro/GCR_Cr.mac create mode 100644 macro/GCR_F.mac create mode 100644 macro/GCR_Fe.mac create mode 100644 macro/GCR_H.mac create mode 100644 macro/GCR_He.mac create mode 100644 macro/GCR_K.mac create mode 100644 macro/GCR_Li.mac create mode 100644 macro/GCR_Mg.mac create mode 100644 macro/GCR_Mn.mac create mode 100644 macro/GCR_N.mac create mode 100644 macro/GCR_Na.mac create mode 100644 macro/GCR_Ne.mac create mode 100644 macro/GCR_Ni.mac create mode 100644 macro/GCR_O.mac create mode 100644 macro/GCR_P.mac create mode 100644 macro/GCR_S.mac create mode 100644 macro/GCR_Sc.mac create mode 100644 macro/GCR_Si.mac create mode 100644 macro/GCR_Ti.mac create mode 100644 macro/GCR_V.mac rename electron.mac => macro/TE.mac (82%) create mode 100644 macro/TP.mac create mode 100644 src/EventAction.cpp create mode 100644 src/RunAction.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 9538295..4ce8e36 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,7 +20,6 @@ add_executable(DESCSS main.cpp ${sources} ${headers}) target_link_libraries(DESCSS ${Geant4_LIBRARIES}) set(DESCSS_SCRIPTS - electron.mac vis.mac assets/model.txt ) diff --git a/G4.code-workspace b/G4.code-workspace index 21e9d73..5a9ad94 100644 --- a/G4.code-workspace +++ b/G4.code-workspace @@ -120,7 +120,18 @@ "vmanip": "cpp", "element": "cpp", "tree": "cpp", - "vertices": "cpp" + "vertices": "cpp", + "c1d": "cpp", + "dps": "cpp", + "rotf": "cpp", + "vec2": "cpp", + "vec3": "cpp", + "vec4": "cpp", + "bsf": "cpp", + "senum": "cpp", + "value": "cpp", + "ntuple": "cpp", + "free_seg": "cpp" } } } \ No newline at end of file diff --git a/include/DetectorConstruction.h b/include/DetectorConstruction.h index 3aede27..cdd3ed4 100644 --- a/include/DetectorConstruction.h +++ b/include/DetectorConstruction.h @@ -23,6 +23,7 @@ public: void SetParticleType(G4String s) { particleType = s; }; void ConstructSDandField(); G4String GetParticleType() const { return particleType; }; + std::vector GetSensitiveList() const { return sensitiveList; }; private: void ConstructSectionSphere(G4LogicalVolume* fMotherLogical, G4double zBias); @@ -35,7 +36,8 @@ private: private: G4String sex = "Male"; G4String model = "MIRD"; - G4String particleType = "TE"; + G4String particleType = "GCR_H"; + std::vector sensitiveList; std::map sensitivities; G4HumanPhantomMaterial* material; G4HumanPhantomMessenger* messenger; diff --git a/include/EventAction.h b/include/EventAction.h new file mode 100644 index 0000000..a4659e0 --- /dev/null +++ b/include/EventAction.h @@ -0,0 +1,22 @@ +#ifndef DESCSS_EventAction_h +#define DESCSS_EventAction_h + +#include "G4UserEventAction.hh" +#include "globals.hh" + +class RunAction; + +class EventAction : public G4UserEventAction { +public: + EventAction(RunAction* runAction); + ~EventAction() override; + + void BeginOfEventAction(const G4Event*) override; + void EndOfEventAction(const G4Event*) override; + +private: + RunAction* fRunAction = nullptr; + std::map fEdep; +}; + +#endif \ No newline at end of file diff --git a/include/RunAction.h b/include/RunAction.h new file mode 100644 index 0000000..d6b34be --- /dev/null +++ b/include/RunAction.h @@ -0,0 +1,24 @@ +#ifndef DESCSS_RunAction_h +#define DESCSS_RunAction_h + +#include "G4Accumulable.hh" +#include "G4UserRunAction.hh" +#include "globals.hh" + +class G4Run; + +class RunAction : public G4UserRunAction { +public: + RunAction(); + ~RunAction() override; + + void BeginOfRunAction(const G4Run*) override; + void EndOfRunAction(const G4Run*) override; + + void AddEdep(std::map edep); + +private: + std::vector sensitiveList; +}; + +#endif \ No newline at end of file diff --git a/macro/GCR_Al.mac b/macro/GCR_Al.mac new file mode 100644 index 0000000..a15356c --- /dev/null +++ b/macro/GCR_Al.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Al + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Ar.mac b/macro/GCR_Ar.mac new file mode 100644 index 0000000..00871c9 --- /dev/null +++ b/macro/GCR_Ar.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Ar + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_B.mac b/macro/GCR_B.mac new file mode 100644 index 0000000..7dfc951 --- /dev/null +++ b/macro/GCR_B.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_B + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Be.mac b/macro/GCR_Be.mac new file mode 100644 index 0000000..df415b6 --- /dev/null +++ b/macro/GCR_Be.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Be + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_C.mac b/macro/GCR_C.mac new file mode 100644 index 0000000..fad8b72 --- /dev/null +++ b/macro/GCR_C.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_C + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Ca.mac b/macro/GCR_Ca.mac new file mode 100644 index 0000000..2b5c58a --- /dev/null +++ b/macro/GCR_Ca.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Ca + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Cl.mac b/macro/GCR_Cl.mac new file mode 100644 index 0000000..8147f5a --- /dev/null +++ b/macro/GCR_Cl.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Cl + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Co.mac b/macro/GCR_Co.mac new file mode 100644 index 0000000..0040318 --- /dev/null +++ b/macro/GCR_Co.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Co + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Cr.mac b/macro/GCR_Cr.mac new file mode 100644 index 0000000..931391f --- /dev/null +++ b/macro/GCR_Cr.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Cr + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_F.mac b/macro/GCR_F.mac new file mode 100644 index 0000000..01caf9c --- /dev/null +++ b/macro/GCR_F.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_F + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Fe.mac b/macro/GCR_Fe.mac new file mode 100644 index 0000000..5be5d91 --- /dev/null +++ b/macro/GCR_Fe.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Fe + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_H.mac b/macro/GCR_H.mac new file mode 100644 index 0000000..3c2a86b --- /dev/null +++ b/macro/GCR_H.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_H + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_He.mac b/macro/GCR_He.mac new file mode 100644 index 0000000..d00c909 --- /dev/null +++ b/macro/GCR_He.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_He + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_K.mac b/macro/GCR_K.mac new file mode 100644 index 0000000..1e1592b --- /dev/null +++ b/macro/GCR_K.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_K + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Li.mac b/macro/GCR_Li.mac new file mode 100644 index 0000000..aa2ae00 --- /dev/null +++ b/macro/GCR_Li.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Li + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Mg.mac b/macro/GCR_Mg.mac new file mode 100644 index 0000000..52c25c0 --- /dev/null +++ b/macro/GCR_Mg.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Mg + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Mn.mac b/macro/GCR_Mn.mac new file mode 100644 index 0000000..1acbd91 --- /dev/null +++ b/macro/GCR_Mn.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Mn + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_N.mac b/macro/GCR_N.mac new file mode 100644 index 0000000..5cb36e9 --- /dev/null +++ b/macro/GCR_N.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_N + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Na.mac b/macro/GCR_Na.mac new file mode 100644 index 0000000..6f0630b --- /dev/null +++ b/macro/GCR_Na.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Na + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Ne.mac b/macro/GCR_Ne.mac new file mode 100644 index 0000000..e441af8 --- /dev/null +++ b/macro/GCR_Ne.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Ne + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Ni.mac b/macro/GCR_Ni.mac new file mode 100644 index 0000000..846b746 --- /dev/null +++ b/macro/GCR_Ni.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Ni + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_O.mac b/macro/GCR_O.mac new file mode 100644 index 0000000..3bf82c7 --- /dev/null +++ b/macro/GCR_O.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_O + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_P.mac b/macro/GCR_P.mac new file mode 100644 index 0000000..24bf75f --- /dev/null +++ b/macro/GCR_P.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_P + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_S.mac b/macro/GCR_S.mac new file mode 100644 index 0000000..b497eaf --- /dev/null +++ b/macro/GCR_S.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_S + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Sc.mac b/macro/GCR_Sc.mac new file mode 100644 index 0000000..af8d154 --- /dev/null +++ b/macro/GCR_Sc.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Sc + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Si.mac b/macro/GCR_Si.mac new file mode 100644 index 0000000..e4aec78 --- /dev/null +++ b/macro/GCR_Si.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Si + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_Ti.mac b/macro/GCR_Ti.mac new file mode 100644 index 0000000..31c3220 --- /dev/null +++ b/macro/GCR_Ti.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_Ti + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/macro/GCR_V.mac b/macro/GCR_V.mac new file mode 100644 index 0000000..af32ec2 --- /dev/null +++ b/macro/GCR_V.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set GCR_V + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/electron.mac b/macro/TE.mac similarity index 82% rename from electron.mac rename to macro/TE.mac index f66ed5a..1c78b8a 100644 --- a/electron.mac +++ b/macro/TE.mac @@ -2,14 +2,14 @@ /run/numberOfThreads 12 # verbose -/control/verbose 2 +/control/verbose 1 /run/verbose 0 /event/verbose 0 /tracking/verbose 0 /vis/verbose errors +/type/set TE + # 初始化 /run/initialize - -/type/set TE -/run/beamOn 50 \ No newline at end of file +/run/beamOn 923242 \ No newline at end of file diff --git a/macro/TP.mac b/macro/TP.mac new file mode 100644 index 0000000..b1467d3 --- /dev/null +++ b/macro/TP.mac @@ -0,0 +1,15 @@ +# 多线程设置 +/run/numberOfThreads 12 + +# verbose +/control/verbose 1 +/run/verbose 0 +/event/verbose 0 +/tracking/verbose 0 +/vis/verbose errors + +/type/set TP + +# 初始化 +/run/initialize +/run/beamOn 100000 \ No newline at end of file diff --git a/src/ActionInitialization.cpp b/src/ActionInitialization.cpp index a9822a1..5c6d9f2 100644 --- a/src/ActionInitialization.cpp +++ b/src/ActionInitialization.cpp @@ -1,5 +1,7 @@ #include "ActionInitialization.h" +#include "EventAction.h" #include "PrimaryGeneratorAction.h" +#include "RunAction.h" #include #include "Randomize.hh" @@ -15,8 +17,16 @@ ActionInitialization::ActionInitialization() { ActionInitialization::~ActionInitialization() {} -void ActionInitialization::BuildForMaster() const {} +void ActionInitialization::BuildForMaster() const { + RunAction* runAction = new RunAction; + SetUserAction(runAction); +} void ActionInitialization::Build() const { SetUserAction(new PrimaryGeneratorAction); + + RunAction* runAction = new RunAction; + SetUserAction(runAction); + EventAction* eventAction = new EventAction(runAction); + SetUserAction(eventAction); } diff --git a/src/DetectorConstruction.cpp b/src/DetectorConstruction.cpp index 0f48dbf..25d0bef 100644 --- a/src/DetectorConstruction.cpp +++ b/src/DetectorConstruction.cpp @@ -23,6 +23,49 @@ DetectorConstruction::DetectorConstruction() { material = new G4HumanPhantomMaterial(); messenger = new G4HumanPhantomMessenger(this); + + sensitiveList.emplace_back("logicalHead"); + sensitiveList.emplace_back("logicalSkull"); + sensitiveList.emplace_back("logicalBrain"); + sensitiveList.emplace_back("logicalTrunk"); + sensitiveList.emplace_back("logicalLeftLeg"); + sensitiveList.emplace_back("logicalRightLeg"); + sensitiveList.emplace_back("logicalLeftArmBone"); + sensitiveList.emplace_back("logicalRightArmBone"); + sensitiveList.emplace_back("logicalLeftLegBone"); + sensitiveList.emplace_back("logicalRightLegBone"); + sensitiveList.emplace_back("logicalUpperSpine"); + sensitiveList.emplace_back("logicalLeftScapula"); + sensitiveList.emplace_back("logicalRightScapula"); + sensitiveList.emplace_back("logicalLeftAdrenal"); + sensitiveList.emplace_back("logicalRightAdrenal"); + sensitiveList.emplace_back("logicalThymus"); + sensitiveList.emplace_back("logicalLeftClavicle"); + sensitiveList.emplace_back("logicalRightClavicle"); + sensitiveList.emplace_back("logicalSmallIntestine"); + sensitiveList.emplace_back("logicalRibCage"); + sensitiveList.emplace_back("logicalMiddleLowerSpine"); + sensitiveList.emplace_back("logicalPelvis"); + sensitiveList.emplace_back("logicalStomach"); + sensitiveList.emplace_back("logicalUpperLargeIntestine"); + sensitiveList.emplace_back("logicalLowerLargeIntestine"); + sensitiveList.emplace_back("logicalSpleen"); + sensitiveList.emplace_back("logicalPancreas"); + sensitiveList.emplace_back("logicalLiver"); + sensitiveList.emplace_back("logicalLeftKidney"); + sensitiveList.emplace_back("logicalRightKidney"); + sensitiveList.emplace_back("logicalUrinaryBladder"); + sensitiveList.emplace_back("logicalLeftLung"); + sensitiveList.emplace_back("logicalRightLung"); + sensitiveList.emplace_back("logicalThyroid"); + sensitiveList.emplace_back("logicalLeftOvary"); + sensitiveList.emplace_back("logicalRightOvary"); + sensitiveList.emplace_back("logicalUterus"); + sensitiveList.emplace_back("logicalLeftBreast"); + sensitiveList.emplace_back("logicalRightBreast"); + sensitiveList.emplace_back("logicalMaleGenitalia"); + sensitiveList.emplace_back("logicalLeftTeste"); + sensitiveList.emplace_back("logicalRightTeste"); } DetectorConstruction::~DetectorConstruction() { @@ -289,7 +332,7 @@ void DetectorConstruction::ConstructHumanPhantom(G4VPhysicalVolume* fMotherPhysi builder->BuildRightKidney("green", true, sensitivities["RightKidney"]); builder->BuildUrinaryBladder("green", true, sensitivities["UrinaryBladder"]); - builder->BuildHeart("red", true, sensitivities["Hearth"]); // to do MIRD + // builder->BuildHeart("red", true, sensitivities["Hearth"]); // to do MIRD builder->BuildLeftLung("blue", true, sensitivities["LeftLung"]); builder->BuildRightLung("blue", true, sensitivities["RightLung"]); builder->BuildThyroid("orange", true, sensitivities["Thyroid"]); @@ -299,13 +342,8 @@ void DetectorConstruction::ConstructHumanPhantom(G4VPhysicalVolume* fMotherPhysi builder->BuildRightOvary("purple", true, sensitivities["RightOvary"]); builder->BuildUterus("purple", true, sensitivities["Uterus"]); - if (model == "MIRD") { - builder->BuildLeftBreast("purple", true, sensitivities["LeftBreast"]); - builder->BuildRightBreast("purple", true, sensitivities["RightBreast"]); - } else { - builder->BuildVoxelLeftBreast("purple", false, sensitivities["LeftBreast"]); - builder->BuildVoxelRightBreast("purple", false, sensitivities["RightBreast"]); - } + builder->BuildLeftBreast("purple", true, sensitivities["LeftBreast"]); + builder->BuildRightBreast("purple", true, sensitivities["RightBreast"]); } if (sex == "Male") { @@ -349,6 +387,8 @@ G4VPhysicalVolume* DetectorConstruction::Construct() { "Phantom", logicWorld, false, 0, true); ConstructHumanPhantom(physicsPhantom); + // for (auto i = sensitivities.begin(); i != sensitivities.end(); ++i) sensitiveList.emplace_back(i->first); + return physicsWorld; } @@ -399,14 +439,19 @@ void DetectorConstruction::ConstructSDandField() { SetSensitiveDetector("logicalSmallIntestine", SD); SetSensitiveDetector("logicalRibCage", SD); SetSensitiveDetector("logicalMiddleLowerSpine", SD); + SetSensitiveDetector("logicalPelvis", SD); SetSensitiveDetector("logicalStomach", SD); SetSensitiveDetector("logicalUpperLargeIntestine", SD); SetSensitiveDetector("logicalLowerLargeIntestine", SD); SetSensitiveDetector("logicalSpleen", SD); SetSensitiveDetector("logicalPancreas", SD); + SetSensitiveDetector("logicalLiver", SD); SetSensitiveDetector("logicalLeftKidney", SD); SetSensitiveDetector("logicalRightKidney", SD); SetSensitiveDetector("logicalUrinaryBladder", SD); + SetSensitiveDetector("logicalLeftLung", SD); + SetSensitiveDetector("logicalRightLung", SD); + SetSensitiveDetector("logicalThyroid", SD); if (sex == "Female") { SetSensitiveDetector("logicalLeftOvary", SD); diff --git a/src/EventAction.cpp b/src/EventAction.cpp new file mode 100644 index 0000000..18dfef0 --- /dev/null +++ b/src/EventAction.cpp @@ -0,0 +1,22 @@ +#include "EventAction.h" +#include "G4HumanPhantomHit.h" +#include "RunAction.h" + +#include "G4Event.hh" +#include "G4VHitsCollection.hh" + +EventAction::EventAction(RunAction* runAction) : fRunAction(runAction) {} + +EventAction::~EventAction() {} + +void EventAction::BeginOfEventAction(const G4Event*) { fEdep.clear(); } + +void EventAction::EndOfEventAction(const G4Event* event) { + G4HumanPhantomHitsCollection* hc = (G4HumanPhantomHitsCollection*)event->GetHCofThisEvent()->GetHC(0); + int numHits = hc->entries(); + for (int i = 0; i < numHits; i++) { + G4String name = (*hc)[0]->GetBodyPartID(); + fEdep[name] += (*hc)[i]->GetEdep(); + } + if (numHits > 0) fRunAction->AddEdep(fEdep); +} \ No newline at end of file diff --git a/src/G4HumanPhantomSD.cpp b/src/G4HumanPhantomSD.cpp index a331e6e..72b5fa9 100644 --- a/src/G4HumanPhantomSD.cpp +++ b/src/G4HumanPhantomSD.cpp @@ -36,9 +36,4 @@ G4bool G4HumanPhantomSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) { return true; } -void G4HumanPhantomSD::EndOfEvent(G4HCofThisEvent*) { - // G4int NbHits = collection->entries(); - // G4cout << "\n-------->Hits Collection: in this event, there are " << NbHits - // << " hits in the tracker chambers: " << G4endl; - // for (G4int i = 0; i < NbHits; i++) (*collection)[i]->Print(); -} +void G4HumanPhantomSD::EndOfEvent(G4HCofThisEvent*) {} diff --git a/src/G4MIRDLiver.cpp b/src/G4MIRDLiver.cpp index 63c6cec..e8992f9 100644 --- a/src/G4MIRDLiver.cpp +++ b/src/G4MIRDLiver.cpp @@ -58,7 +58,7 @@ G4VPhysicalVolume* G4MIRDLiver::Construct(const G4String& volumeName, G4VPhysica G4SubtractionSolid* liver = new G4SubtractionSolid("Liver", firstLiver, subtrLiver, rm_relative, G4ThreeVector(10.0 * cm, 0.0 * cm, 0.0 * cm)); - G4LogicalVolume* logicLiver = new G4LogicalVolume(liver, soft, "LiverVolume", 0, 0, 0); + G4LogicalVolume* logicLiver = new G4LogicalVolume(liver, soft, "logical" + volumeName, 0, 0, 0); // Define rotation and position here! G4RotationMatrix* rm = new G4RotationMatrix(); diff --git a/src/G4MIRDThyroid.cpp b/src/G4MIRDThyroid.cpp index b894faa..ae5180f 100644 --- a/src/G4MIRDThyroid.cpp +++ b/src/G4MIRDThyroid.cpp @@ -60,7 +60,7 @@ G4VPhysicalVolume* G4MIRDThyroid::Construct(const G4String& volumeName, G4VPhysi G4SubtractionSolid* thyroid = new G4SubtractionSolid( "SecondThyroid", SecondThyroid, SubtrThyroid, relative_matrix_2, G4ThreeVector(0.0 * cm, 0.0 * cm, -5.40 * cm)); - G4LogicalVolume* logicThyroid = new G4LogicalVolume(thyroid, soft, "ThyroidVolume", 0, 0, 0); + G4LogicalVolume* logicThyroid = new G4LogicalVolume(thyroid, soft, "logical" + volumeName, 0, 0, 0); G4RotationMatrix* rm = new G4RotationMatrix(); rm->rotateZ(180. * degree); diff --git a/src/PrimaryGeneratorAction.cpp b/src/PrimaryGeneratorAction.cpp index 431143f..176bc4e 100644 --- a/src/PrimaryGeneratorAction.cpp +++ b/src/PrimaryGeneratorAction.cpp @@ -15,6 +15,7 @@ G4double C1, C2, C3, C4, sum; PrimaryGeneratorAction::PrimaryGeneratorAction() { G4ParticleDefinition* ion = DefineParticle(); + fParticleGun = new G4ParticleGun(); fParticleGun->SetParticleCharge(this->Z * eplus); fParticleGun->SetParticleDefinition(ion); @@ -52,7 +53,6 @@ G4ParticleDefinition* PrimaryGeneratorAction::DefineParticle() { } G4ParticleDefinition* ion; - fParticleGun = new G4ParticleGun(); if (Z == -1) ion = G4ParticleTable::GetParticleTable()->FindParticle("e-"); else if (Z == 1) diff --git a/src/RunAction.cpp b/src/RunAction.cpp new file mode 100644 index 0000000..a9b1c0b --- /dev/null +++ b/src/RunAction.cpp @@ -0,0 +1,85 @@ +#include "DetectorConstruction.h" +#include "RunAction.h" + +#include "G4AccumulableManager.hh" +#include "G4Run.hh" +#include "G4RunManager.hh" +#include "G4SystemOfUnits.hh" + +RunAction::RunAction() { + G4RunManager::GetRunManager()->SetPrintProgress(10000); + + const DetectorConstruction* detConstruction = + static_cast(G4RunManager::GetRunManager()->GetUserDetectorConstruction()); + sensitiveList = detConstruction->GetSensitiveList(); + + G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); + for (int i = 0; i < sensitiveList.size(); i++) { + G4String name = sensitiveList[i]; + accumulableManager->CreateAccumulable(name + "Edep", 0); + accumulableManager->CreateAccumulable(name + "Edep2", 0); + } +} + +RunAction::~RunAction() {} + +void RunAction::BeginOfRunAction(const G4Run*) { + G4RunManager::GetRunManager()->SetRandomNumberStore(false); + + G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); + accumulableManager->Reset(); +} + +void RunAction::EndOfRunAction(const G4Run* run) { + G4int nofEvents = run->GetNumberOfEvent(); + if (nofEvents == 0) return; + + G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); + accumulableManager->Merge(); + + std::map edep; + std::map edep2; + std::map rms; + + for (int i = 0; i < sensitiveList.size(); i++) { + G4String name = sensitiveList[i]; + G4Accumulable* fEdep = accumulableManager->GetAccumulable(name + "Edep"); + G4Accumulable* fEdep2 = accumulableManager->GetAccumulable(name + "Edep2"); + edep[name] = fEdep->GetValue(); + edep2[name] = fEdep2->GetValue(); + rms[name] = edep2[name] - edep[name] * edep[name] / nofEvents; + if (rms[name] > 0.) + rms[name] = std::sqrt(rms[name]); + else + rms[name] = 0.; + } + + if (IsMaster()) { + const DetectorConstruction* detConstruction = + static_cast(G4RunManager::GetRunManager()->GetUserDetectorConstruction()); + std::ofstream edepFile("result/edep_" + detConstruction->GetParticleType() + ".txt"); + + for (int i = 0; i < sensitiveList.size(); i++) { + G4String name = sensitiveList[i]; + edepFile << "bodyPart: " << std::setw(30) << name << " | eDep: " << std::setw(15) + << edep[name] / MeV << " MeV | eDep2: " << std::setw(15) + << edep2[name] / MeV << " MeV | rms: " << std::setw(15) + << rms[name] / MeV << " MeV" << G4endl; + } + + G4cout << G4endl << "--------------------End of Global Run-----------------------" << G4endl; + } else + G4cout << G4endl << "--------------------End of Local Run------------------------" << G4endl; +} + +void RunAction::AddEdep(std::map edep) { + G4AccumulableManager* accumulableManager = G4AccumulableManager::Instance(); + for (int i = 0; i < sensitiveList.size(); i++) { + G4String name = sensitiveList[i]; + G4double value = edep[name] * MeV; + G4Accumulable* fEdep = accumulableManager->GetAccumulable(name + "Edep"); + G4Accumulable* fEdep2 = accumulableManager->GetAccumulable(name + "Edep2"); + *(fEdep) += value; + *(fEdep2) += value * value; + } +}