Only in geant4/examples/advanced/human_phantom: .git Only in geant4/examples/advanced/human_phantom: .gitignore Only in geant4/examples/advanced/human_phantom: .vscode diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/CMakeLists.txt geant4/examples/advanced/human_phantom/CMakeLists.txt --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/CMakeLists.txt 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/CMakeLists.txt 2024-08-17 09:47:11 @@ -26,7 +26,10 @@ add_definitions(-DG4LIB_USE_GDML) else() endif() - +set(CMAKE_BUILD_TYPE Debug) +set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} -g -Wall -O0") +add_compile_options(-fsanitize=address) +add_link_options(-fsanitize=address) #---------------------------------------------------------------------------- # Locate sources and headers for this project # Only in geant4/examples/advanced/human_phantom: build Only in Downloads/geant4-v11.2.2/examples/advanced/human_phantom: human_phantom.out diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/include/G4HumanPhantomMessenger.hh geant4/examples/advanced/human_phantom/include/G4HumanPhantomMessenger.hh --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/include/G4HumanPhantomMessenger.hh 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/include/G4HumanPhantomMessenger.hh 2024-08-10 08:43:28 @@ -61,6 +61,7 @@ G4UIcmdWithAString* fSexCmd; G4UIcmdWithAString* fBodypartCmd; G4UIcmdWithoutParameter* fEndCmd; + G4UIcmdWithoutParameter* fLungCmd; G4String fBodypart; G4bool fBps; diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/include/G4HumanPhantomPrimaryGeneratorAction.hh geant4/examples/advanced/human_phantom/include/G4HumanPhantomPrimaryGeneratorAction.hh --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/include/G4HumanPhantomPrimaryGeneratorAction.hh 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/include/G4HumanPhantomPrimaryGeneratorAction.hh 2024-08-31 09:17:59 @@ -30,7 +30,10 @@ #define G4HumanPhantomPrimaryGeneratorAction_h 1 #include "G4VUserPrimaryGeneratorAction.hh" +#include "G4HumanPhantomMessenger.hh" #include "globals.hh" +#include "myparams.hh" +#include "G4Box.hh" #include class G4GeneralParticleSource; @@ -41,12 +44,16 @@ public: G4HumanPhantomPrimaryGeneratorAction(); ~G4HumanPhantomPrimaryGeneratorAction(); + G4Event *event; public: void GeneratePrimaries(G4Event* anEvent); - - private: G4GeneralParticleSource* particleGun; + private: + std::unique_ptr right_construct(); + std::unique_ptr left_construct(); + G4ThreeVector GenerateRandomPointInLung(G4Box *lungVolume); + void SetRandomPositionInLung(); }; #endif diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/include/G4MIRDLeftLung.hh geant4/examples/advanced/human_phantom/include/G4MIRDLeftLung.hh --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/include/G4MIRDLeftLung.hh 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/include/G4MIRDLeftLung.hh 2024-08-31 09:20:29 @@ -32,6 +32,7 @@ #include "G4VPhysicalVolume.hh" #include "G4VOrgan.hh" +#include "G4Box.hh" class G4VPhysicalVolume; class G4LogicalVolume; @@ -44,6 +45,7 @@ ~G4MIRDLeftLung() override = default; G4VPhysicalVolume* Construct(const G4String&, G4VPhysicalVolume*, const G4String&,G4bool, G4bool) override; + G4VPhysicalVolume *Lung; }; #endif Only in geant4/examples/advanced/human_phantom/include: G4MyMessenger.hh Only in geant4/examples/advanced/human_phantom/include: myparams.hh Only in geant4/examples/advanced/human_phantom: maybe.cc diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/phantom.cc geant4/examples/advanced/human_phantom/phantom.cc --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/phantom.cc 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/phantom.cc 2024-08-10 12:11:30 @@ -51,7 +51,6 @@ runManager->SetUserInitialization(userPhantom); runManager->SetUserInitialization(new G4HumanPhantomPhysicsList); - G4VisManager* visManager = new G4VisExecutive; visManager->Initialize(); diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4HumanPhantomActionInitialization.cc geant4/examples/advanced/human_phantom/src/G4HumanPhantomActionInitialization.cc --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4HumanPhantomActionInitialization.cc 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/src/G4HumanPhantomActionInitialization.cc 2024-08-31 09:35:42 @@ -47,10 +47,11 @@ // Instantiate the analysis manager auto* analysis = new G4HumanPhantomAnalysisManager(); -SetUserAction(new G4HumanPhantomPrimaryGeneratorAction); - SetUserAction(new G4HumanPhantomRunAction(analysis)); SetUserAction(new G4HumanPhantomEventAction()); + +SetUserAction(new G4HumanPhantomPrimaryGeneratorAction()); + } diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4HumanPhantomConstruction.cc geant4/examples/advanced/human_phantom/src/G4HumanPhantomConstruction.cc --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4HumanPhantomConstruction.cc 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/src/G4HumanPhantomConstruction.cc 2024-08-10 08:05:35 @@ -147,8 +147,8 @@ builder->BuildUrinaryBladder("green", true, fSensitivities["UrinaryBladder"]); //builder->BuildHeart("red", true,fSensitivities["Hearth"]);// to do MIRD - // builder->BuildLeftLung("blue", true, fSensitivities["LeftLung"]); - //builder->BuildRightLung("blue", true, fSensitivities["RightLung"]); + builder->BuildLeftLung("blue", true, fSensitivities["LeftLung"]); + builder->BuildRightLung("blue", true, fSensitivities["RightLung"]); // builder->BuildThyroid("orange", true, fSensitivities["Thyroid"]); if(fSex=="Female"){ diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4HumanPhantomMessenger.cc geant4/examples/advanced/human_phantom/src/G4HumanPhantomMessenger.cc --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4HumanPhantomMessenger.cc 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/src/G4HumanPhantomMessenger.cc 2024-08-31 09:17:51 @@ -34,9 +34,11 @@ #include "G4UIcmdWithoutParameter.hh" #include "globals.hh" - +#include "myparams.hh" #include "G4RunManager.hh" +int is_set = 1; + G4HumanPhantomMessenger::G4HumanPhantomMessenger(G4HumanPhantomConstruction* myUsrPhtm) :fUserPhantom(myUsrPhtm),fBps(false) { @@ -68,6 +70,10 @@ fEndCmd = new G4UIcmdWithoutParameter("/phantom/buildNewPhantom",this); fEndCmd->SetGuidance("Build your Phantom."); fEndCmd->AvailableForStates(G4State_PreInit,G4State_Idle); + + fLungCmd = new G4UIcmdWithoutParameter("/phantom/SetLung",this); + fEndCmd->SetGuidance("Set gps position as randomized."); + fEndCmd->AvailableForStates(G4State_PreInit,G4State_Idle); } G4HumanPhantomMessenger::~G4HumanPhantomMessenger() @@ -99,6 +105,11 @@ G4cout << " ****************>>>> NEW PHANTOM CONSTRUCTION <<<<***************** " << G4endl; + } + if( command == fLungCmd) + { + G4cout << "Lung Set" << G4endl; + is_set = 0; } } diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4HumanPhantomPrimaryGeneratorAction.cc geant4/examples/advanced/human_phantom/src/G4HumanPhantomPrimaryGeneratorAction.cc --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4HumanPhantomPrimaryGeneratorAction.cc 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/src/G4HumanPhantomPrimaryGeneratorAction.cc 2024-08-31 09:13:28 @@ -27,28 +27,73 @@ // Authors (since 2007): S. Guatelli, University of Wollongong, Australia // #include "G4HumanPhantomPrimaryGeneratorAction.hh" +#include "G4HumanPhantomMessenger.hh" #include "globals.hh" #include "G4SystemOfUnits.hh" #include "G4Event.hh" #include "G4GeneralParticleSource.hh" #include "G4ParticleTable.hh" #include "G4ParticleDefinition.hh" - +#include "G4Box.hh" #include "G4RunManager.hh" #include "G4ios.hh" +#include "G4MyMessenger.hh" G4HumanPhantomPrimaryGeneratorAction::G4HumanPhantomPrimaryGeneratorAction() { particleGun = new G4GeneralParticleSource(); + } G4HumanPhantomPrimaryGeneratorAction::~G4HumanPhantomPrimaryGeneratorAction() { delete particleGun; } +void G4HumanPhantomPrimaryGeneratorAction::SetRandomPositionInLung() { + // Example implementation for generating a random point + auto leftlung = left_construct(); + auto rightlung = right_construct(); + G4ThreeVector randomPositionLeftLung = GenerateRandomPointInLung(leftlung.get()); + G4ThreeVector randomPositionRightLung = GenerateRandomPointInLung(rightlung.get()); + G4ThreeVector randomPosition; + if (G4UniformRand() < 0.5) { + randomPosition = randomPositionLeftLung; + } else { + randomPosition = randomPositionRightLung; + } + particleGun->SetParticlePosition(randomPosition); +} void G4HumanPhantomPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) { - particleGun -> GeneratePrimaryVertex(anEvent); + if(is_set == 0) + SetRandomPositionInLung(); + + particleGun->GeneratePrimaryVertex(anEvent); } +G4ThreeVector G4HumanPhantomPrimaryGeneratorAction::GenerateRandomPointInLung(G4Box *lungVolume) +{ + G4double x, y, z; + x = (2 * G4UniformRand() - 1) * lungVolume->GetXHalfLength(); + y = (2 * G4UniformRand() - 1) * lungVolume->GetYHalfLength(); + z = (2 * G4UniformRand() - 1) * lungVolume->GetZHalfLength(); + + return G4ThreeVector(x, y, z); +} + +std::unique_ptr G4HumanPhantomPrimaryGeneratorAction::left_construct(){ + G4double dx = 5.5 * cm; + G4double dy = 8.5 * cm; + G4double dz = 24. * cm; + + return std::make_unique("LeftLungBox", dx, dy, dz); +} + +std::unique_ptr G4HumanPhantomPrimaryGeneratorAction::right_construct(){ + G4double dx = 5.5 * cm; + G4double dy = 8.5 * cm; + G4double dz = 24. * cm; + + return std::make_unique("RightLungBox", dx, dy, dz); +} \ No newline at end of file diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4MIRDLeftLung.cc geant4/examples/advanced/human_phantom/src/G4MIRDLeftLung.cc --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4MIRDLeftLung.cc 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/src/G4MIRDLeftLung.cc 2024-08-17 08:19:04 @@ -69,7 +69,6 @@ by= 7.5*cm; cz= 24.*cm; - auto* subtrLung = new G4Ellipsoid("subtrLung",ax, by, cz); // y<0 @@ -110,7 +109,6 @@ mother, false, 0, true); - // Visualization Attributes //G4VisAttributes* LeftLungVisAtt = new G4VisAttributes(G4Colour(0.25,0.41,0.88)); diff --color --unified --recursive --no-dereference Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4MIRDRightLung.cc geant4/examples/advanced/human_phantom/src/G4MIRDRightLung.cc --- Downloads/geant4-v11.2.2/examples/advanced/human_phantom/src/G4MIRDRightLung.cc 2024-06-21 22:44:24 +++ geant4/examples/advanced/human_phantom/src/G4MIRDRightLung.cc 2024-08-31 09:23:07 @@ -97,7 +97,7 @@ mother, false, 0, true); - + // Visualization Attributes // G4VisAttributes* RightLungVisAtt = new G4VisAttributes(G4Colour(0.25,0.41,0.88)); auto* colourPointer = new G4HumanPhantomColour(); Only in geant4/examples/advanced/human_phantom/src: G4MyMessenger.cc