├── examples ├── na22 │ ├── na22.geo │ ├── NaISort.inp │ ├── coincSort.inp │ ├── README │ ├── Makefile │ ├── center_vis.mac │ ├── off_center_vis.mac │ ├── center.mac │ ├── off_center.mac │ ├── plotMca.py │ ├── diffMca.py │ ├── NaISort.py │ └── coincSort.py ├── simple │ ├── README │ ├── NaISort.inp │ ├── e1000.mac │ ├── Makefile │ ├── plotMca.py │ └── NaISort.py └── cs137 │ ├── NaISort.inp │ ├── README │ ├── cs137_simple.mac │ ├── Makefile │ ├── cs137.mac │ ├── plotMca.py │ ├── diffMca.py │ └── NaISort.py ├── include ├── GEM.pdf ├── SourceData.hh ├── RunAction.hh ├── TrackingAction.hh ├── EventAction_Messenger.hh ├── TrackerGammaSD_Messenger.hh ├── Source_Capsule_Messenger.hh ├── Experimental_Hall_Messenger.hh ├── TrackerGammaSD.hh ├── Lead_Brick_Messenger.hh ├── Target_Messenger.hh ├── NaI_Detector_Messenger.hh ├── PrimaryGeneratorAction_Messenger.hh ├── EventAction.hh ├── Experimental_Hall.hh ├── Materials.hh ├── PrimaryGeneratorAction.hh ├── VisManager.hh ├── EventInformation.hh ├── Source_Capsule.hh ├── Lead_Brick.hh ├── Target.hh ├── DetectorConstruction.hh ├── PhysicsList.hh.old ├── TrackerGammaHit.hh ├── StepMaxMessenger.hh ├── PhysicsListMessenger.hh ├── NaI_Detector.hh ├── EmStandardPhysics_option4_mod.hh ├── StepMax.hh └── PhysicsList.hh ├── src ├── .PrimaryGeneratorAction.cc.swp ├── EventAction_Messenger.cc ├── EventInformation.cc ├── TrackerGammaSD_Messenger.cc ├── TrackingAction.cc ├── Source_Capsule_Messenger.cc ├── DetectorConstruction.cc ├── Experimental_Hall_Messenger.cc ├── Source_Capsule.cc ├── TrackerGammaHit.cc ├── PrimaryGeneratorAction_Messenger.cc ├── Lead_Brick_Messenger.cc ├── Experimental_Hall.cc ├── StepMaxMessenger.cc ├── Target.cc ├── Lead_Brick.cc ├── VisManager.cc ├── TrackerGammaSD.cc ├── RunAction.cc ├── Materials.cc ├── NaI_Detector_Messenger.cc ├── PhysicsListMessenger.cc ├── PrimaryGeneratorAction.cc ├── Target_Messenger.cc ├── StepMax.cc ├── EventAction.cc ├── NaI_Detector.cc └── PhysicsList.cc ├── .gitignore ├── GNUmakefile ├── vis ├── vis.mac └── trajectories.mac ├── UCNaI.cc └── README.md /examples/na22/na22.geo: -------------------------------------------------------------------------------- 1 | 0 0 0 -90 0 0 2 | 0 0 200 -90 0 0 3 | -------------------------------------------------------------------------------- /include/GEM.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rileyle/UCNaI/HEAD/include/GEM.pdf -------------------------------------------------------------------------------- /examples/simple/README: -------------------------------------------------------------------------------- 1 | e1000.mac uses the "Simple" gamma-ray source to emit 1000 keV gamma rays. -------------------------------------------------------------------------------- /src/.PrimaryGeneratorAction.cc.swp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rileyle/UCNaI/HEAD/src/.PrimaryGeneratorAction.cc.swp -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | DEVNOTES 2 | *~ 3 | *.out 4 | *.log 5 | *.mca 6 | *.root 7 | *.rad 8 | *.spe 9 | *.wrl 10 | tmp* 11 | *.dat 12 | -------------------------------------------------------------------------------- /examples/na22/NaISort.inp: -------------------------------------------------------------------------------- 1 | 2 # Number of detectors 2 | 0.84 # Resolution parameter 3 | 0 # Energy calibration parameter A (keV) 4 | 1.0 # Energy calibration parameter B (keV/bin) 5 | 2048 # Maximum energy (keV) 6 | 2048 # Number of bins 7 | -------------------------------------------------------------------------------- /examples/cs137/NaISort.inp: -------------------------------------------------------------------------------- 1 | 1 # Number of detectors 2 | 0.84 # Resolution parameter 3 | 0 # Energy calibration parameter A (keV) 4 | 1.0 # Energy calibration parameter B (keV/bin) 5 | 2048 # Maximum energy (keV) 6 | 2048 # Number of bins 7 | -------------------------------------------------------------------------------- /examples/cs137/README: -------------------------------------------------------------------------------- 1 | cs137.mac simulates the beta decay of 137Cs producing the 137Ba 2 | daughter which emits a 663 keV gamma ray. Auger electrons and the 3 | associated X-rays can also be produced. 4 | 5 | cs137_simple.mac simulates a "Simple" source emitting 663 keV gamma 6 | rays. 7 | -------------------------------------------------------------------------------- /examples/simple/NaISort.inp: -------------------------------------------------------------------------------- 1 | 1 # Number of detectors 2 | 0.84 # Resolution parameter 3 | 0 # Energy calibration parameter A (keV) 4 | 1.0 # Energy calibration parameter B (keV/bin) 5 | 2048 # Maximum energy (keV) 6 | 2048 # Number of bins 7 | -------------------------------------------------------------------------------- /include/SourceData.hh: -------------------------------------------------------------------------------- 1 | #ifndef SourceData_h 2 | #define SourceData_h 1 3 | class SourceData 4 | { 5 | public: 6 | SourceData() {} 7 | SourceData(G4double def_e, G4double def_b) : e(def_e), b(def_b) {} 8 | virtual ~SourceData() {} 9 | 10 | G4double e,b; 11 | 12 | }; 13 | #endif 14 | -------------------------------------------------------------------------------- /examples/na22/coincSort.inp: -------------------------------------------------------------------------------- 1 | 0.84 # Detector resolution parameter 2 | 0 # Energy calibration parameter A (keV) 3 | 1.0 # Energy calibration parameter B (keV/bin) 4 | 2000 # Maximum energy (keV) 5 | 200 # Number of bins 6 | 1220 # Gate lower limit (keV) 7 | 1320 # Gate upper limit (keV) -------------------------------------------------------------------------------- /examples/simple/e1000.mac: -------------------------------------------------------------------------------- 1 | # Geometry ===================================================================== 2 | /Source/Simple 1000 keV 3 | /Source/Capsule/Construct 4 | /NaI/setZ 20 cm 5 | 6 | # Initialize run manager ======================================================= 7 | /run/initialize 8 | 9 | /Output/Filename e1000.out 10 | /run/beamOn 1000000 11 | -------------------------------------------------------------------------------- /examples/cs137/cs137_simple.mac: -------------------------------------------------------------------------------- 1 | # Geometry ===================================================================== 2 | /Source/Simple 662 keV 3 | /Source/Capsule/Construct 4 | /NaI/setZ 10 cm 5 | 6 | # Initialize run manager ======================================================= 7 | /run/initialize 8 | 9 | /Output/Filename cs137_simple.out 10 | /run/beamOn 1000000 11 | -------------------------------------------------------------------------------- /GNUmakefile: -------------------------------------------------------------------------------- 1 | # $Id: GNUmakefile,v 1.1 1999/01/07 16:05:40 gunter Exp $ 2 | # -------------------------------------------------------------- 3 | # GNUmakefile for examples module. Gabriele Cosmo, 06/04/98. 4 | # -------------------------------------------------------------- 5 | 6 | name := UCNaI 7 | 8 | G4TARGET := $(name) 9 | G4EXLIB := true 10 | 11 | ifndef G4INSTALL 12 | G4INSTALL = ../../.. 13 | endif 14 | 15 | .PHONY: all 16 | all: lib bin 17 | 18 | include $(G4INSTALL)/config/binmake.gmk 19 | -------------------------------------------------------------------------------- /vis/vis.mac: -------------------------------------------------------------------------------- 1 | /Source/Capsule/Construct 2 | /NaI/setZ 10 cm 3 | 4 | # Initialize run manager ======================================================= 5 | /run/initialize 6 | 7 | #/vis/open RayTracer # Makes a jpeg image 8 | #/vis/open OGLIX 9 | #/vis/open VRML1FILE # To view, use $ SceneViewer file.wrl 10 | /vis/open VRML2FILE # To view, use $ view3dscene file.wrl 11 | 12 | /vis/scene/create 13 | /vis/drawVolume 14 | /vis/viewer/set/viewpointThetaPhi 20 150 deg 15 | /vis/viewer/flush 16 | -------------------------------------------------------------------------------- /examples/simple/Makefile: -------------------------------------------------------------------------------- 1 | all: e1000.mca 2 | echo "Geant4 simulations done." 3 | 4 | # Pattern rules for running Geant4 simulations. 5 | %.out : %.mac 6 | if test -e $*.out; \ 7 | then echo "Removing existing file $*.out"; rm $*.out; \ 8 | fi 9 | UCNaI $*.mac 2>&1 | tee $*.log 10 | 11 | # Pattern rule for sorting the simulation output into Root histograms 12 | # and Radware ascii spectra 13 | %.mca : %.out 14 | python3 NaISort.py $*.out 2>&1 | tee -a $*.log 15 | 16 | clean: 17 | rm *.log *.out *.mca *.wrl 18 | -------------------------------------------------------------------------------- /examples/cs137/Makefile: -------------------------------------------------------------------------------- 1 | all: cs137.mca cs137_simple.mca 2 | echo "Geant4 simulations done." 3 | 4 | # Pattern rules for running Geant4 simulations. 5 | %.out : %.mac 6 | if test -e $*.out; \ 7 | then echo "Removing existing file $*.out"; rm $*.out; \ 8 | fi 9 | UCNaI $*.mac 2>&1 | tee $*.log 10 | 11 | # Pattern rule for sorting the simulation output into Root histograms 12 | # and Radware ascii spectra 13 | %.mca : %.out 14 | python3 NaISort.py $*.out 2>&1 | tee -a $*.log 15 | 16 | clean: 17 | rm *.log *.out *.mca *.wrl 18 | -------------------------------------------------------------------------------- /examples/na22/README: -------------------------------------------------------------------------------- 1 | center.mac simulates the beta decay of 22Na with the source centered 2 | between two 2x2 NaI detectors. (Coincidences between the two 511 keV 3 | gamma rays from the annihilation of the positron produces in the beta 4 | decay are observed.) 5 | 6 | off_center.mac simulates the beta decay of 22Na with the source 7 | placement offset from the line of sight between two 2x2 NaI 8 | detectors. (No 511-511 keV coincidences are observed.) 9 | 10 | center_vis.mac and off_center_vis.mac produce graphical visualizations 11 | of the two arrangements (.wrl files). -------------------------------------------------------------------------------- /examples/cs137/cs137.mac: -------------------------------------------------------------------------------- 1 | # Geometry ===================================================================== 2 | /Source/Capsule/Construct 3 | /NaI/setZ 10 cm 4 | 5 | # Processes ==================================================================== 6 | 7 | # Produce Auger electrons and X-rays 8 | /process/em/auger true 9 | 10 | # Initialize run manager ======================================================= 11 | /run/initialize 12 | 13 | # Initialize the source ======================================================== 14 | /gun/particle ion 15 | /gun/ion 55 137 16 | 17 | /Output/Filename cs137.out 18 | /run/beamOn 1000000 19 | -------------------------------------------------------------------------------- /include/RunAction.hh: -------------------------------------------------------------------------------- 1 | #ifndef RunAction_h 2 | #define RunAction_h 1 3 | 4 | #include "G4UserRunAction.hh" 5 | #include "DetectorConstruction.hh" 6 | #include "G4Run.hh" 7 | #include "globals.hh" 8 | #include "G4UnitsTable.hh" 9 | #include "EventAction.hh" 10 | 11 | class RunAction : public G4UserRunAction 12 | { 13 | public: 14 | RunAction(DetectorConstruction*,EventAction*); 15 | ~RunAction(); 16 | 17 | public: 18 | void BeginOfRunAction(const G4Run*); 19 | void EndOfRunAction(const G4Run*); 20 | 21 | private: 22 | DetectorConstruction* myDetector; 23 | EventAction* evaction; 24 | 25 | }; 26 | 27 | 28 | 29 | 30 | #endif 31 | 32 | 33 | -------------------------------------------------------------------------------- /include/TrackingAction.hh: -------------------------------------------------------------------------------- 1 | #ifndef TrackingAction_h 2 | #define TrackingAction_h 1 3 | 4 | #include "G4UserTrackingAction.hh" 5 | #include "G4TrackingManager.hh" 6 | #include "EventInformation.hh" 7 | #include "G4Track.hh" 8 | #include "G4ios.hh" 9 | 10 | #include "EventAction.hh" 11 | 12 | class TrackingAction : public G4UserTrackingAction { 13 | 14 | public: 15 | 16 | TrackingAction(EventAction*); 17 | ~TrackingAction() {}; 18 | 19 | void PreUserTrackingAction(const G4Track*); 20 | void PostUserTrackingAction(const G4Track*){;}; 21 | 22 | private: 23 | 24 | EventAction* eventAction; 25 | EventInformation* eventInfo; 26 | }; 27 | 28 | #endif //TRACKINGACTION_H 29 | -------------------------------------------------------------------------------- /examples/na22/Makefile: -------------------------------------------------------------------------------- 1 | all: center.out center.mca center_coinc.mca \ 2 | off_center.out off_center.mca off_center_coinc.mca 3 | echo "Geant4 simulations done." 4 | 5 | # Pattern rules for running Geant4 simulations. 6 | %.out : %.mac 7 | if test -e $*.out; \ 8 | then echo "Removing existing file $*.out"; rm $*.out; \ 9 | fi 10 | UCNaI $*.mac 2>&1 | tee $*.log 11 | 12 | # Pattern rule for sorting the simulation output into Root histograms 13 | # and Radware ascii spectra 14 | %.mca : %.out 15 | python3 NaISort.py $*.out 2>&1 | tee -a $*.log 16 | 17 | %_coinc.mca : %.out 18 | python3 coincSort.py $*.out 2>&1 | tee -a $*.log 19 | 20 | clean: 21 | rm *.log *.out *.mca *.wrl 22 | -------------------------------------------------------------------------------- /examples/na22/center_vis.mac: -------------------------------------------------------------------------------- 1 | # Geometry ===================================================================== 2 | /Source/setZ 10 cm 3 | /Source/setX 0 cm 4 | /Source/Capsule/rotateX 90 deg 5 | /Source/Capsule/Construct 6 | 7 | /NaI/GeometryFile na22.geo 8 | 9 | # Initialize run manager ======================================================= 10 | /run/initialize 11 | 12 | #/vis/open RayTracer # Makes a jpeg image 13 | #/vis/open OGLIX 14 | #/vis/open VRML1FILE # To view, use $ SceneViewer file.wrl 15 | /vis/open VRML2FILE # To view, use $ view3dscene file.wrl 16 | 17 | /vis/scene/create 18 | /vis/drawVolume 19 | /vis/viewer/set/viewpointThetaPhi 20 150 deg 20 | /vis/viewer/flush 21 | -------------------------------------------------------------------------------- /examples/na22/off_center_vis.mac: -------------------------------------------------------------------------------- 1 | # Geometry ===================================================================== 2 | /Source/setZ 10 cm 3 | /Source/setX 10 cm 4 | /Source/Capsule/rotateX 90 deg 5 | /Source/Capsule/Construct 6 | 7 | /NaI/GeometryFile na22.geo 8 | 9 | # Initialize run manager ======================================================= 10 | /run/initialize 11 | 12 | #/vis/open RayTracer # Makes a jpeg image 13 | #/vis/open OGLIX 14 | #/vis/open VRML1FILE # To view, use $ SceneViewer file.wrl 15 | /vis/open VRML2FILE # To view, use $ view3dscene file.wrl 16 | 17 | /vis/scene/create 18 | /vis/drawVolume 19 | /vis/viewer/set/viewpointThetaPhi 20 150 deg 20 | /vis/viewer/flush 21 | -------------------------------------------------------------------------------- /examples/na22/center.mac: -------------------------------------------------------------------------------- 1 | # Geometry ===================================================================== 2 | /Source/setZ 10 cm 3 | /Source/setX 0 cm 4 | /Source/Capsule/rotateX 90 deg 5 | /Source/Capsule/Construct 6 | 7 | /NaI/GeometryFile na22.geo 8 | 9 | # Processes ==================================================================== 10 | 11 | # Produce Auger electrons and X-rays 12 | /process/em/auger true 13 | 14 | # Initialize run manager ======================================================= 15 | /run/initialize 16 | 17 | # Initialize the source ======================================================== 18 | /gun/particle ion 19 | /gun/ion 11 22 20 | 21 | /Output/Filename center.out 22 | /run/beamOn 1000000 23 | -------------------------------------------------------------------------------- /examples/na22/off_center.mac: -------------------------------------------------------------------------------- 1 | # Geometry ===================================================================== 2 | /Source/setZ 10 cm 3 | /Source/setX 10 cm 4 | /Source/Capsule/rotateX 90 deg 5 | /Source/Capsule/Construct 6 | 7 | /NaI/GeometryFile na22.geo 8 | 9 | # Processes ==================================================================== 10 | 11 | # Produce Auger electrons and X-rays 12 | /process/em/auger true 13 | 14 | # Initialize run manager ======================================================= 15 | /run/initialize 16 | 17 | # Initialize the source ======================================================== 18 | /gun/particle ion 19 | /gun/ion 11 22 20 | 21 | /Output/Filename off_center.out 22 | /run/beamOn 1000000 23 | -------------------------------------------------------------------------------- /src/EventAction_Messenger.cc: -------------------------------------------------------------------------------- 1 | #include "EventAction_Messenger.hh" 2 | 3 | 4 | EventAction_Messenger::EventAction_Messenger(EventAction* EA):theEventAction(EA) 5 | { 6 | 7 | OutputDir = new G4UIdirectory("/Output/"); 8 | OutputDir->SetGuidance("Event by event output control."); 9 | 10 | OutFileCmd = new G4UIcmdWithAString("/Output/Filename",this); 11 | OutFileCmd->SetGuidance("Output file name."); 12 | 13 | } 14 | 15 | 16 | 17 | EventAction_Messenger::~EventAction_Messenger() 18 | 19 | { 20 | 21 | delete OutputDir; 22 | delete OutFileCmd; 23 | 24 | } 25 | 26 | 27 | 28 | void EventAction_Messenger::SetNewValue(G4UIcommand* command,G4String newValue) 29 | { 30 | 31 | if( command == OutFileCmd ) 32 | {theEventAction->SetOutFile(newValue);} 33 | 34 | } 35 | 36 | -------------------------------------------------------------------------------- /src/EventInformation.cc: -------------------------------------------------------------------------------- 1 | #include "EventInformation.hh" 2 | 3 | EventInformation::EventInformation() { 4 | fNEmittedGammas = 0; 5 | fFullEnergy = -1; 6 | } 7 | 8 | void EventInformation::AddEmittedGamma(G4double e, 9 | G4ThreeVector *pos, 10 | G4ThreeVector *dir, 11 | G4int parentID){ 12 | 13 | //G4cout << " fNEmittedGammas = " << fNEmittedGammas << G4endl; 14 | 15 | fEmittedGammaEnergies[fNEmittedGammas] = e/keV; 16 | fEmittedGammaPosX[fNEmittedGammas] = pos->getX()/mm; 17 | fEmittedGammaPosY[fNEmittedGammas] = pos->getY()/mm; 18 | fEmittedGammaPosZ[fNEmittedGammas] = pos->getZ()/mm; 19 | fEmittedGammaPhi[fNEmittedGammas] = dir->getPhi()/rad; 20 | fEmittedGammaTheta[fNEmittedGammas] = dir->getTheta()/rad; 21 | fNEmittedGammas++; 22 | 23 | } 24 | -------------------------------------------------------------------------------- /include/EventAction_Messenger.hh: -------------------------------------------------------------------------------- 1 | #ifndef EventAction_Messenger_h 2 | #define EventAction_Messenger_h 1 3 | 4 | #include "EventAction.hh" 5 | #include "globals.hh" 6 | #include "G4UImessenger.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "G4UIcmdWithADouble.hh" 11 | #include "G4UIcmdWithoutParameter.hh" 12 | #include "G4UIcmdWithAnInteger.hh" 13 | 14 | 15 | class EventAction_Messenger: public G4UImessenger 16 | { 17 | 18 | public: 19 | EventAction_Messenger(EventAction*); 20 | ~EventAction_Messenger(); 21 | 22 | void SetNewValue(G4UIcommand*, G4String); 23 | 24 | private: 25 | EventAction* theEventAction; 26 | G4UIdirectory* OutputDir; 27 | G4UIcmdWithAString* OutFileCmd; 28 | 29 | }; 30 | 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /include/TrackerGammaSD_Messenger.hh: -------------------------------------------------------------------------------- 1 | #ifndef TrackerGammaSD_Messenger_h 2 | #define TrackerGammaSD_Messenger_h 1 3 | 4 | #include "TrackerGammaSD.hh" 5 | #include "globals.hh" 6 | #include "G4UImessenger.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "G4UIcmdWithADouble.hh" 11 | #include "G4UIcmdWithoutParameter.hh" 12 | #include "G4UIcmdWithAnInteger.hh" 13 | 14 | 15 | class TrackerGammaSD_Messenger: public G4UImessenger 16 | { 17 | 18 | public: 19 | TrackerGammaSD_Messenger(TrackerGammaSD*); 20 | ~TrackerGammaSD_Messenger(); 21 | 22 | void SetNewValue(G4UIcommand*, G4String); 23 | 24 | private: 25 | TrackerGammaSD* tracker; 26 | G4UIdirectory* PrtGDir; 27 | G4UIcmdWithoutParameter* PrtGSCmd; 28 | G4UIcmdWithoutParameter* PrtGUCmd; 29 | 30 | }; 31 | 32 | 33 | #endif 34 | 35 | -------------------------------------------------------------------------------- /include/Source_Capsule_Messenger.hh: -------------------------------------------------------------------------------- 1 | #ifndef Source_Capsule_Messenger_h 2 | #define Source_Capsule_Messenger_h 1 3 | 4 | #include "Source_Capsule.hh" 5 | #include "globals.hh" 6 | #include "G4UImessenger.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "G4UIcmdWithADouble.hh" 11 | #include "G4UIcmdWithoutParameter.hh" 12 | 13 | class Source_Capsule_Messenger: public G4UImessenger 14 | { 15 | public: 16 | Source_Capsule_Messenger(Source_Capsule*); 17 | ~Source_Capsule_Messenger(); 18 | 19 | void SetNewValue(G4UIcommand*, G4String); 20 | 21 | private: 22 | Source_Capsule* capsule; 23 | 24 | G4UIdirectory* Source_CapsuleDir; 25 | 26 | G4UIcmdWithADoubleAndUnit* rXCmd; 27 | G4UIcmdWithADoubleAndUnit* rYCmd; 28 | G4UIcmdWithADoubleAndUnit* rZCmd; 29 | }; 30 | 31 | 32 | #endif 33 | 34 | -------------------------------------------------------------------------------- /vis/trajectories.mac: -------------------------------------------------------------------------------- 1 | /Source/Simple 1000 keV 2 | /Source/Capsule/Construct 3 | /NaI/setZ 10 cm 4 | 5 | # Initialize run manager ======================================================= 6 | /run/initialize 7 | 8 | #/vis/open RayTracer # Makes a jpeg image 9 | #/vis/open OGLIX 10 | #/vis/open VRML1FILE # To view, use $ SceneViewer file.wrl 11 | /vis/open VRML2FILE # To view, use $ mayavi2 file.wrl 12 | 13 | # Disable auto refresh and quieten vis messages while scene and 14 | # trajectories are established 15 | /vis/viewer/set/autoRefresh false 16 | /vis/verbose errors 17 | 18 | # setup viewer 19 | /vis/drawVolume 20 | #/vis/viewer/set/style surface 21 | #/vis/viewer/set/hiddenEdge 22 | #/vis/scene/add/axes 23 | #/vis/scene/add/hits 24 | /vis/scene/add/trajectories 25 | /vis/scene/endOfEventAction accumulate 26 | 27 | # Re-establish auto refreshing and verbosity 28 | /vis/viewer/set/autoRefresh true 29 | /vis/verbose warnings 30 | 31 | /run/beamOn 100 32 | -------------------------------------------------------------------------------- /include/Experimental_Hall_Messenger.hh: -------------------------------------------------------------------------------- 1 | #ifndef Experimental_Hall_Messenger_h 2 | #define Experimental_Hall_Messenger_h 1 3 | 4 | #include "Experimental_Hall.hh" 5 | #include "globals.hh" 6 | #include "G4UImessenger.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "G4UIcmdWithoutParameter.hh" 11 | 12 | 13 | 14 | class Experimental_Hall_Messenger: public G4UImessenger 15 | { 16 | public: 17 | Experimental_Hall_Messenger(Experimental_Hall*); 18 | ~Experimental_Hall_Messenger(); 19 | 20 | void SetNewValue(G4UIcommand*, G4String); 21 | 22 | private: 23 | Experimental_Hall* ExpHall; 24 | 25 | G4UIdirectory* ExpHallDir; 26 | G4UIcmdWithAString* MatCmd; 27 | G4UIcmdWithADoubleAndUnit* XCmd; 28 | G4UIcmdWithADoubleAndUnit* YCmd; 29 | G4UIcmdWithADoubleAndUnit* ZCmd; 30 | G4UIcmdWithoutParameter* RepCmd; 31 | 32 | 33 | }; 34 | 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /include/TrackerGammaSD.hh: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TrackerGammaSD_h 3 | #define TrackerGammaSD_h 1 4 | 5 | #include "G4VSensitiveDetector.hh" 6 | #include "TrackerGammaHit.hh" 7 | #include "G4SystemOfUnits.hh" 8 | #include 9 | #include 10 | #include 11 | using namespace std; 12 | 13 | class G4Step; 14 | class G4HCofThisEvent; 15 | 16 | 17 | class TrackerGammaSD : public G4VSensitiveDetector 18 | { 19 | public: 20 | TrackerGammaSD(G4String); 21 | ~TrackerGammaSD(); 22 | 23 | void SetPrint(){ 24 | G4cout<<"----> Gamma track data set to print at the end of event"< Gamma track data set not to print at the end of event"<SetGuidance("Event by event print control for."); 10 | 11 | PrtGSCmd = new G4UIcmdWithoutParameter("/GammaPrint/Track_Set",this); 12 | PrtGSCmd->SetGuidance("Sets printing of track gamma results."); 13 | 14 | PrtGUCmd = new G4UIcmdWithoutParameter("/GammaPrint/Track_UnSet",this); 15 | PrtGUCmd->SetGuidance("Un sets printing of track gamma results."); 16 | 17 | } 18 | 19 | 20 | 21 | TrackerGammaSD_Messenger::~TrackerGammaSD_Messenger() 22 | 23 | { 24 | 25 | delete PrtGDir; 26 | delete PrtGSCmd; 27 | delete PrtGUCmd; 28 | 29 | } 30 | 31 | 32 | 33 | void TrackerGammaSD_Messenger::SetNewValue(G4UIcommand* command,G4String) 34 | { 35 | 36 | if( command == PrtGSCmd ) 37 | {tracker ->SetPrint();} 38 | 39 | if( command == PrtGUCmd ) 40 | {tracker ->UnSetPrint();} 41 | 42 | } 43 | 44 | -------------------------------------------------------------------------------- /include/Lead_Brick_Messenger.hh: -------------------------------------------------------------------------------- 1 | #ifndef Lead_Brick_Messenger_h 2 | #define Lead_Brick_Messenger_h 1 3 | 4 | #include "Lead_Brick.hh" 5 | #include "globals.hh" 6 | #include "G4UImessenger.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "G4UIcmdWithADouble.hh" 11 | #include "G4UIcmdWithoutParameter.hh" 12 | 13 | class Lead_Brick_Messenger: public G4UImessenger 14 | { 15 | public: 16 | Lead_Brick_Messenger(Lead_Brick*); 17 | ~Lead_Brick_Messenger(); 18 | 19 | void SetNewValue(G4UIcommand*, G4String); 20 | 21 | private: 22 | Lead_Brick* Brick; 23 | 24 | G4UIdirectory* BrickDir; 25 | 26 | G4UIcmdWithADoubleAndUnit* XCmd; 27 | G4UIcmdWithADoubleAndUnit* YCmd; 28 | G4UIcmdWithADoubleAndUnit* ZCmd; 29 | G4UIcmdWithADoubleAndUnit* rXCmd; 30 | G4UIcmdWithADoubleAndUnit* rYCmd; 31 | G4UIcmdWithADoubleAndUnit* rZCmd; 32 | G4UIcmdWithoutParameter* cCmd; 33 | G4UIcmdWithAString* GCmd; 34 | }; 35 | 36 | 37 | #endif 38 | 39 | -------------------------------------------------------------------------------- /include/Target_Messenger.hh: -------------------------------------------------------------------------------- 1 | #ifndef Target_Messenger_h 2 | #define Target_Messenger_h 1 3 | 4 | #include "Target.hh" 5 | #include "globals.hh" 6 | #include "G4UImessenger.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "G4UIcmdWithADouble.hh" 11 | #include "G4UIcmdWithoutParameter.hh" 12 | 13 | class Target_Messenger: public G4UImessenger 14 | { 15 | public: 16 | Target_Messenger(Target*); 17 | ~Target_Messenger(); 18 | 19 | void SetNewValue(G4UIcommand*, G4String); 20 | 21 | private: 22 | Target* target; 23 | 24 | G4UIdirectory* TargetDir; 25 | 26 | G4UIcmdWithADoubleAndUnit* XCmd; 27 | G4UIcmdWithADoubleAndUnit* YCmd; 28 | G4UIcmdWithADoubleAndUnit* ZCmd; 29 | G4UIcmdWithADoubleAndUnit* rXCmd; 30 | G4UIcmdWithADoubleAndUnit* rYCmd; 31 | G4UIcmdWithADoubleAndUnit* rZCmd; 32 | G4UIcmdWithADoubleAndUnit* RCmd; 33 | G4UIcmdWithADoubleAndUnit* LCmd; 34 | G4UIcmdWithoutParameter* cCmd; 35 | G4UIcmdWithAString* GCmd; 36 | }; 37 | 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /include/NaI_Detector_Messenger.hh: -------------------------------------------------------------------------------- 1 | #ifndef NaI_Detector_Messenger_h 2 | #define NaI_Detector_Messenger_h 1 3 | 4 | #include "NaI_Detector.hh" 5 | #include "globals.hh" 6 | #include "G4UImessenger.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "G4UIcmdWithADouble.hh" 11 | #include "G4UIcmdWithoutParameter.hh" 12 | 13 | class NaI_Detector_Messenger: public G4UImessenger 14 | { 15 | public: 16 | NaI_Detector_Messenger(NaI_Detector*); 17 | ~NaI_Detector_Messenger(); 18 | 19 | void SetNewValue(G4UIcommand*, G4String); 20 | 21 | private: 22 | NaI_Detector* NaIDet; 23 | 24 | G4UIdirectory* NaIDir; 25 | 26 | G4UIcmdWithADoubleAndUnit* XCmd; 27 | G4UIcmdWithADoubleAndUnit* YCmd; 28 | G4UIcmdWithADoubleAndUnit* ZCmd; 29 | G4UIcmdWithADoubleAndUnit* RCmd; 30 | G4UIcmdWithADoubleAndUnit* LCmd; 31 | G4UIcmdWithADoubleAndUnit* rXCmd; 32 | G4UIcmdWithADoubleAndUnit* rYCmd; 33 | G4UIcmdWithADoubleAndUnit* rZCmd; 34 | G4UIcmdWithAString* GCmd; 35 | }; 36 | 37 | 38 | #endif 39 | 40 | -------------------------------------------------------------------------------- /include/PrimaryGeneratorAction_Messenger.hh: -------------------------------------------------------------------------------- 1 | #ifndef PrimaryGeneratorAction_Messenger_h 2 | #define PrimaryGeneratorAction_Messenger_h 1 3 | 4 | #include "PrimaryGeneratorAction.hh" 5 | #include "globals.hh" 6 | #include "G4UImessenger.hh" 7 | #include "G4UIdirectory.hh" 8 | #include "G4UIcmdWithAString.hh" 9 | #include "G4UIcmdWithADoubleAndUnit.hh" 10 | #include "G4UIcmdWithADouble.hh" 11 | #include "G4UIcmdWithoutParameter.hh" 12 | #include "G4UIcmdWithAnInteger.hh" 13 | 14 | 15 | class PrimaryGeneratorAction_Messenger: public G4UImessenger 16 | { 17 | public: 18 | PrimaryGeneratorAction_Messenger(PrimaryGeneratorAction*); 19 | ~PrimaryGeneratorAction_Messenger(); 20 | 21 | void SetNewValue(G4UIcommand*, G4String); 22 | 23 | private: 24 | PrimaryGeneratorAction* PGA; 25 | G4UIdirectory* SrcDir; 26 | G4UIcmdWithADoubleAndUnit* SrcECmd; 27 | G4UIcmdWithADoubleAndUnit* SrcMCmd; 28 | G4UIcmdWithADoubleAndUnit* SrcXCmd; 29 | G4UIcmdWithADoubleAndUnit* SrcYCmd; 30 | G4UIcmdWithADoubleAndUnit* SrcZCmd; 31 | G4UIcmdWithoutParameter* SrcCCmd; 32 | 33 | }; 34 | 35 | 36 | #endif 37 | 38 | -------------------------------------------------------------------------------- /include/EventAction.hh: -------------------------------------------------------------------------------- 1 | #ifndef EventAction_h 2 | #define EventAction_h 1 3 | 4 | #include "G4UserEventAction.hh" 5 | #include "G4EventManager.hh" 6 | #include "TrackerGammaSD.hh" 7 | #include "G4Event.hh" 8 | #include "EventInformation.hh" 9 | #include "G4TrajectoryContainer.hh" 10 | #include "G4Trajectory.hh" 11 | #include "G4ios.hh" 12 | #include "globals.hh" 13 | #include "G4UnitsTable.hh" 14 | #include 15 | #include 16 | 17 | class EventAction : public G4UserEventAction 18 | { 19 | public: 20 | EventAction(); 21 | ~EventAction(); 22 | 23 | void BeginOfEventAction(const G4Event*); 24 | void EndOfEventAction(const G4Event*); 25 | void SetOutFile(G4String); 26 | void closeEvfile(); 27 | void openEvfile(); 28 | const G4Event* GetEvent() { return evt; } 29 | 30 | void SetNTotalevents(G4int n){NTotalEvents = n;} 31 | G4int GetNTotalevents(){return NTotalEvents;} 32 | void SetEveryNEvents(G4int n){everyNevents = n;} 33 | G4int GetEveryNEvents(){return everyNevents;} 34 | 35 | private: 36 | G4int gammaCollectionID; 37 | G4String outFileName; 38 | std::ofstream evfile; 39 | G4int NTotalEvents; 40 | G4int everyNevents; 41 | G4int timerCount; 42 | G4double eventsPerSecond; 43 | const G4Event* evt; 44 | }; 45 | 46 | #endif //EVENTACTION_H 47 | -------------------------------------------------------------------------------- /include/Experimental_Hall.hh: -------------------------------------------------------------------------------- 1 | #ifndef Experimental_Hall_H 2 | #define Experimental_Hall_H 1 3 | 4 | 5 | #include "G4Material.hh" 6 | #include "Materials.hh" 7 | #include "G4Box.hh" 8 | #include "G4LogicalVolume.hh" 9 | #include "G4VPhysicalVolume.hh" 10 | #include "G4ThreeVector.hh" 11 | #include "G4PVPlacement.hh" 12 | #include "G4VisAttributes.hh" 13 | #include "G4Colour.hh" 14 | #include "G4RotationMatrix.hh" 15 | #include "G4Transform3D.hh" 16 | #include "G4UnitsTable.hh" 17 | #include "G4UnitsTable.hh" 18 | #include "G4SystemOfUnits.hh" 19 | 20 | class Experimental_Hall 21 | { 22 | public: 23 | 24 | Experimental_Hall(Materials*); 25 | ~Experimental_Hall(); 26 | 27 | G4VPhysicalVolume *Construct(); 28 | G4LogicalVolume* GetLogVolume(){return ExperimentalHall_log;}; 29 | void setX(G4double); 30 | void setY(G4double); 31 | void setZ(G4double); 32 | void setMaterial(G4String); 33 | void Report(); 34 | 35 | private: 36 | // dimensions 37 | G4double expHall_x; 38 | G4double expHall_y; 39 | G4double expHall_z; 40 | 41 | //materials 42 | Materials* materials; 43 | G4Material* ExperimentalHallMaterial; 44 | 45 | //the box 46 | G4Box* ExperimentalHall; 47 | 48 | //logical volume 49 | G4LogicalVolume* ExperimentalHall_log; 50 | 51 | //physical volume 52 | G4VPhysicalVolume* ExperimentalHall_phys; 53 | 54 | 55 | }; 56 | 57 | #endif 58 | 59 | -------------------------------------------------------------------------------- /include/Materials.hh: -------------------------------------------------------------------------------- 1 | #ifndef Materials_H 2 | #define Materials_H 1 3 | 4 | #include "G4Material.hh" 5 | #include "G4NistManager.hh" 6 | #include "G4SystemOfUnits.hh" 7 | 8 | class Materials 9 | { 10 | public: 11 | 12 | Materials(); 13 | ~Materials(); 14 | 15 | G4Material* FindMaterial(G4String ); 16 | 17 | private: 18 | // Elements 19 | 20 | G4Element* elementH; 21 | G4Element* elementC; 22 | G4Element* elementN; 23 | G4Element* elementO; 24 | G4Element* elementMg; 25 | G4Element* elementAl; 26 | G4Element* elementSi; 27 | G4Element* elementTi; 28 | G4Element* elementV; 29 | G4Element* elementFe; 30 | G4Element* elementCo; 31 | G4Element* elementCu; 32 | G4Element* elementMo; 33 | G4Element* elementPt; 34 | G4Element* elementAu; 35 | G4Element* elementPb; 36 | 37 | G4NistManager* NISTman; 38 | 39 | // Materials 40 | G4Material* vacuum; 41 | G4Material* HpGe; 42 | G4Material* pmtMat; 43 | G4Material* G10; 44 | G4Material* polyethylene; 45 | G4Material* polypropylene; 46 | G4Material* ssteel; 47 | G4Material* CsI; 48 | G4Material* NaI; 49 | G4Material* MgO; 50 | G4Material* Al; 51 | G4Material* Cu; 52 | G4Material* Nb; 53 | G4Material* C; 54 | G4Material* Au; 55 | G4Material* Pb; 56 | G4Material* Ir; 57 | G4Material* Si; 58 | G4Material* Be; 59 | G4Material* Bi; 60 | G4Material* LH; 61 | }; 62 | 63 | #endif 64 | 65 | -------------------------------------------------------------------------------- /include/PrimaryGeneratorAction.hh: -------------------------------------------------------------------------------- 1 | #ifndef PrimaryGeneratorAction_h 2 | #define PrimaryGeneratorAction_h 1 3 | 4 | #include "G4VUserPrimaryGeneratorAction.hh" 5 | #include "G4ThreeVector.hh" 6 | #include "G4Event.hh" 7 | #include "G4ParticleGun.hh" 8 | #include "G4ParticleTable.hh" 9 | #include "G4ParticleDefinition.hh" 10 | #include "DetectorConstruction.hh" 11 | #include "Randomize.hh" 12 | #include "G4RandomDirection.hh" 13 | #include 14 | #include "SourceData.hh" 15 | 16 | using namespace std; 17 | 18 | class PrimaryGeneratorAction : public G4VUserPrimaryGeneratorAction 19 | { 20 | public: 21 | PrimaryGeneratorAction(DetectorConstruction*); 22 | ~PrimaryGeneratorAction(); 23 | 24 | public: 25 | void GeneratePrimaries(G4Event* anEvent); 26 | void SetSourceX(G4double); 27 | void SetSourceY(G4double); 28 | void SetSourceZ(G4double); 29 | void SourceReport(); 30 | void SetSourceEnergy(G4double); 31 | void SetMuonEnergy(G4double); 32 | DetectorConstruction* getDetectorConstruction(){return myDetector;}; 33 | 34 | private: 35 | 36 | G4int n_particle; 37 | G4ParticleGun* particleGun; 38 | G4ParticleTable* particleTable; 39 | 40 | DetectorConstruction* myDetector; 41 | 42 | // source stuff 43 | G4String sourceType; 44 | G4ThreeVector sourcePosition; 45 | G4double simpleSourceEnergy; 46 | G4double muonSourceEnergy; 47 | }; 48 | 49 | 50 | #endif 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /include/VisManager.hh: -------------------------------------------------------------------------------- 1 | 2 | 3 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 4 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 5 | 6 | // Example Visualization Manager implementing virtual function 7 | // RegisterGraphicsSystems. Exploits C-pre-processor variables 8 | // G4VIS_USE_DAWN, etc., which are set by the GNUmakefiles if 9 | // environment variables of the same name are set. 10 | 11 | // So all you have to do is set environment variables and compile and 12 | // instantiate this in your main(). 13 | 14 | // Alternatively, you can implement an empty function here and just 15 | // register the systems you want in your main(), e.g.: 16 | // G4VisManager* myVisManager = new MyVisManager; 17 | // myVisManager -> RegisterGraphicsSystem (new MyGraphicsSystem); 18 | 19 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 20 | 21 | #ifndef VisManager_h 22 | #define VisManager_h 1 23 | 24 | #ifdef G4VIS_USE 25 | 26 | #include "G4VisManager.hh" 27 | 28 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 29 | 30 | class VisManager: public G4VisManager { 31 | 32 | public: 33 | 34 | VisManager (); 35 | 36 | private: 37 | 38 | void RegisterGraphicsSystems (); 39 | 40 | }; 41 | 42 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 43 | 44 | #endif 45 | 46 | #endif 47 | -------------------------------------------------------------------------------- /src/TrackingAction.cc: -------------------------------------------------------------------------------- 1 | #include "TrackingAction.hh" 2 | 3 | TrackingAction::TrackingAction(EventAction* evt){ 4 | eventAction = evt; 5 | } 6 | 7 | void TrackingAction::PreUserTrackingAction(const G4Track* aTrack) 8 | { 9 | 10 | eventInfo 11 | = (EventInformation*)eventAction->GetEvent()->GetUserInformation(); 12 | 13 | // Emitted gamma 14 | if( ( aTrack->GetParticleDefinition()->GetParticleName() == "gamma" || 15 | aTrack->GetParticleDefinition()->GetParticleName() == "neutron" || 16 | aTrack->GetParticleDefinition()->GetParticleName() == "mu+" || 17 | aTrack->GetParticleDefinition()->GetParticleName() == "mu-" ) 18 | && 19 | ( aTrack->GetParentID() == 0 || 20 | aTrack->GetCreatorProcess()->GetProcessName() == "RadioactiveDecay" || 21 | aTrack->GetCreatorProcess()->GetProcessName() == "Radioactivation") ){ 22 | 23 | // G4cout << "> Event ID = " << eventAction->GetEvent()->GetEventID() << G4endl; 24 | 25 | G4ThreeVector pos = aTrack->GetPosition(); 26 | G4ThreeVector dir = aTrack->GetMomentumDirection(); 27 | 28 | // G4cout << std::fixed << std::setprecision(4) 29 | // << std::setw(12) << std::right 30 | // << " pos = " << pos 31 | // << " dir = " << dir 32 | // << " energy = " << aTrack->GetKineticEnergy() 33 | // << " parent = " << aTrack->GetParentID() 34 | // << G4endl; 35 | 36 | eventInfo->AddEmittedGamma(aTrack->GetKineticEnergy(), 37 | &pos, &dir, 38 | aTrack->GetParentID()); 39 | 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /include/EventInformation.hh: -------------------------------------------------------------------------------- 1 | #ifndef EventInformation_h 2 | #define EventInformation_h 1 3 | 4 | #include "G4VUserEventInformation.hh" 5 | #include "G4ThreeVector.hh" 6 | #include "G4SystemOfUnits.hh" 7 | 8 | #define MAX_SIM_GAMMAS 10 /* max. simulated gammas per event */ 9 | 10 | class EventInformation : public G4VUserEventInformation 11 | { 12 | public: 13 | 14 | EventInformation(); 15 | ~EventInformation(){}; 16 | 17 | inline virtual void Print()const{;} 18 | 19 | void AddEmittedGamma(G4double, G4ThreeVector*, G4ThreeVector*, G4int); 20 | void SetFullEnergy(G4int f){ fFullEnergy = f; } 21 | 22 | G4double GetEmittedGammaEnergy(G4int i){ return fEmittedGammaEnergies[i]; } 23 | G4double GetEmittedGammaPosX(G4int i){ return fEmittedGammaPosX[i]; } 24 | G4double GetEmittedGammaPosY(G4int i){ return fEmittedGammaPosY[i]; } 25 | G4double GetEmittedGammaPosZ(G4int i){ return fEmittedGammaPosZ[i]; } 26 | G4double GetEmittedGammaPhi(G4int i){ return fEmittedGammaPhi[i]; } 27 | G4double GetEmittedGammaTheta(G4int i){ return fEmittedGammaTheta[i]; } 28 | G4int GetNEmittedGammas(){return fNEmittedGammas;} 29 | G4int GetFullEnergy(){ return fFullEnergy; } 30 | 31 | private: 32 | 33 | G4double fEmittedGammaEnergies[MAX_SIM_GAMMAS]; 34 | G4double fEmittedGammaPosX[MAX_SIM_GAMMAS]; 35 | G4double fEmittedGammaPosY[MAX_SIM_GAMMAS]; 36 | G4double fEmittedGammaPosZ[MAX_SIM_GAMMAS]; 37 | G4double fEmittedGammaPhi[MAX_SIM_GAMMAS]; 38 | G4double fEmittedGammaTheta[MAX_SIM_GAMMAS]; 39 | G4int fNEmittedGammas; 40 | G4int fFullEnergy; 41 | }; 42 | 43 | #endif 44 | -------------------------------------------------------------------------------- /include/Source_Capsule.hh: -------------------------------------------------------------------------------- 1 | #ifndef Source_Capsule_H 2 | #define Source_Capsule_H 1 3 | 4 | #include "G4Material.hh" 5 | #include "Materials.hh" 6 | #include "G4Tubs.hh" 7 | #include "G4LogicalVolume.hh" 8 | #include "G4VPhysicalVolume.hh" 9 | #include "G4ThreeVector.hh" 10 | #include "G4PVPlacement.hh" 11 | 12 | #include "G4VisAttributes.hh" 13 | #include "G4Colour.hh" 14 | 15 | #include "G4RotationMatrix.hh" 16 | #include "G4Transform3D.hh" 17 | #include "Randomize.hh" 18 | #include "globals.hh" 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | class Source_Capsule 25 | { 26 | public: 27 | 28 | G4LogicalVolume *expHall_log; 29 | Materials* materials; 30 | 31 | Source_Capsule(G4LogicalVolume*, Materials*); 32 | ~Source_Capsule(); 33 | 34 | G4VPhysicalVolume *Construct(); 35 | void setX(G4double); 36 | void setY(G4double); 37 | void setZ(G4double); 38 | 39 | void rotateX(G4double); 40 | void rotateY(G4double); 41 | void rotateZ(G4double); 42 | 43 | G4double getDepth(){return Depth;}; 44 | G4double getRadius(){return Radius;}; 45 | void PlaceCapsule(); 46 | 47 | private: 48 | 49 | // Logical volume 50 | 51 | G4LogicalVolume* capsule_log; 52 | 53 | // Physical volume 54 | 55 | G4VPhysicalVolume* capsule_phys; 56 | 57 | // Materials 58 | G4Material* polyethylene; 59 | 60 | // dimensions 61 | G4double Depth; 62 | G4double Radius; 63 | G4double innerRadius; 64 | G4double startAngle; 65 | G4double spanningAngle; 66 | 67 | // position 68 | G4RotationMatrix Rot; 69 | G4ThreeVector Pos; 70 | 71 | G4Tubs* capsule; 72 | 73 | }; 74 | 75 | #endif 76 | 77 | -------------------------------------------------------------------------------- /src/Source_Capsule_Messenger.cc: -------------------------------------------------------------------------------- 1 | #include "Source_Capsule_Messenger.hh" 2 | 3 | Source_Capsule_Messenger::Source_Capsule_Messenger(Source_Capsule* sc) 4 | :capsule(sc) 5 | { 6 | 7 | Source_CapsuleDir = new G4UIdirectory("/Source/Capsule/"); 8 | Source_CapsuleDir->SetGuidance("Source_Capsule control."); 9 | 10 | rXCmd = new G4UIcmdWithADoubleAndUnit("/Source/Capsule/rotateX",this); 11 | rXCmd->SetGuidance("Rotate the capsule about the x axis"); 12 | rXCmd->SetParameterName("choice",false); 13 | rXCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 14 | 15 | rYCmd = new G4UIcmdWithADoubleAndUnit("/Source/Capsule/rotateY",this); 16 | rYCmd->SetGuidance("Rotate the capsule about the y axis"); 17 | rYCmd->SetParameterName("choice",false); 18 | rYCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 19 | 20 | rZCmd = new G4UIcmdWithADoubleAndUnit("/Source/Capsule/rotateZ",this); 21 | rZCmd->SetGuidance("Rotate the capsule about the z axis"); 22 | rZCmd->SetParameterName("choice",false); 23 | rZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 24 | 25 | } 26 | 27 | Source_Capsule_Messenger::~Source_Capsule_Messenger() 28 | { 29 | delete Source_CapsuleDir; 30 | delete rXCmd; 31 | delete rYCmd; 32 | delete rZCmd; 33 | } 34 | 35 | 36 | void Source_Capsule_Messenger::SetNewValue(G4UIcommand* command,G4String newValue) 37 | { 38 | if( command == rXCmd ) 39 | {capsule->rotateX(rXCmd->GetNewDoubleValue(newValue));} 40 | if( command == rYCmd ) 41 | {capsule->rotateY(rYCmd->GetNewDoubleValue(newValue));} 42 | if( command == rZCmd ) 43 | {capsule->rotateZ(rZCmd->GetNewDoubleValue(newValue));} 44 | } 45 | 46 | -------------------------------------------------------------------------------- /include/Lead_Brick.hh: -------------------------------------------------------------------------------- 1 | #ifndef Lead_Brick_H 2 | #define Lead_Brick_H 1 3 | 4 | #include "G4Material.hh" 5 | #include "Materials.hh" 6 | #include "G4Box.hh" 7 | #include "G4LogicalVolume.hh" 8 | #include "G4VPhysicalVolume.hh" 9 | #include "G4ThreeVector.hh" 10 | #include "G4PVPlacement.hh" 11 | 12 | #include "G4VisAttributes.hh" 13 | #include "G4Colour.hh" 14 | 15 | #include "G4RotationMatrix.hh" 16 | #include "G4Transform3D.hh" 17 | #include "Randomize.hh" 18 | #include "globals.hh" 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | class Lead_Brick 25 | { 26 | public: 27 | 28 | G4LogicalVolume *expHall_log; 29 | Materials* materials; 30 | 31 | Lead_Brick(G4LogicalVolume*, Materials*); 32 | ~Lead_Brick(); 33 | 34 | void Construct(); 35 | 36 | void setX(G4double); 37 | void setY(G4double); 38 | void setZ(G4double); 39 | 40 | void rotateX(G4double); 41 | void rotateY(G4double); 42 | void rotateZ(G4double); 43 | void setGeoFile(G4String fname){geoFileName = fname;} 44 | 45 | G4double getLength(){return Length;}; 46 | G4double getWidth(){return Width;}; 47 | G4double getDepth(){return Depth;}; 48 | 49 | void PlaceBrick(); 50 | 51 | private: 52 | 53 | // Logical volume 54 | 55 | G4LogicalVolume* brick_log; 56 | 57 | // Physical volume 58 | 59 | // G4VPhysicalVolume* brick_phys; 60 | 61 | // Materials 62 | G4Material* Pb; 63 | 64 | // dimensions 65 | G4double Length; 66 | G4double Width; 67 | G4double Depth; 68 | 69 | // position 70 | G4RotationMatrix Rot; 71 | G4ThreeVector Pos; 72 | 73 | G4Box* brick; 74 | 75 | G4String geoFileName; 76 | std::ifstream geoFile; 77 | }; 78 | 79 | #endif 80 | 81 | -------------------------------------------------------------------------------- /include/Target.hh: -------------------------------------------------------------------------------- 1 | #ifndef Target_H 2 | #define Target_H 1 3 | 4 | #include "G4Material.hh" 5 | #include "Materials.hh" 6 | #include "G4Tubs.hh" 7 | #include "G4LogicalVolume.hh" 8 | #include "G4VPhysicalVolume.hh" 9 | #include "G4ThreeVector.hh" 10 | #include "G4PVPlacement.hh" 11 | 12 | #include "G4VisAttributes.hh" 13 | #include "G4Colour.hh" 14 | 15 | #include "G4RotationMatrix.hh" 16 | #include "G4Transform3D.hh" 17 | #include "Randomize.hh" 18 | #include "globals.hh" 19 | #include 20 | #include 21 | 22 | using namespace std; 23 | 24 | class Target 25 | { 26 | public: 27 | 28 | G4LogicalVolume *expHall_log; 29 | Materials* materials; 30 | 31 | Target(G4LogicalVolume*, Materials*); 32 | ~Target(); 33 | 34 | void Construct(); 35 | 36 | void setX(G4double); 37 | void setY(G4double); 38 | void setZ(G4double); 39 | 40 | void rotateX(G4double); 41 | void rotateY(G4double); 42 | void rotateZ(G4double); 43 | void setGeoFile(G4String fname){geoFileName = fname;} 44 | 45 | void setR(G4double r){Radius = r;} 46 | void setL(G4double l){Length = l;} 47 | 48 | G4double getLength(){return Length;}; 49 | G4double getRadius(){return Radius;}; 50 | 51 | void PlaceTarget(); 52 | 53 | private: 54 | 55 | // Logical volume 56 | 57 | G4LogicalVolume* target_log; 58 | 59 | // Physical volume 60 | 61 | // G4VPhysicalVolume* target_phys; 62 | 63 | // Materials 64 | G4Material* Al; 65 | 66 | // dimensions 67 | G4double Length; 68 | G4double Radius; 69 | 70 | // position 71 | G4RotationMatrix Rot; 72 | G4ThreeVector Pos; 73 | 74 | G4Tubs* target; 75 | 76 | G4String geoFileName; 77 | std::ifstream geoFile; 78 | }; 79 | 80 | #endif 81 | 82 | -------------------------------------------------------------------------------- /include/DetectorConstruction.hh: -------------------------------------------------------------------------------- 1 | #ifndef DetectorConstruction_H 2 | #define DetectorConstruction_H 1 3 | 4 | #include "G4VUserDetectorConstruction.hh" 5 | #include "Materials.hh" 6 | #include "Experimental_Hall.hh" 7 | #include "Experimental_Hall_Messenger.hh" 8 | #include "NaI_Detector.hh" 9 | #include "NaI_Detector_Messenger.hh" 10 | #include "Lead_Brick.hh" 11 | #include "Lead_Brick_Messenger.hh" 12 | #include "Target.hh" 13 | #include "Target_Messenger.hh" 14 | #include "Source_Capsule.hh" 15 | #include "Source_Capsule_Messenger.hh" 16 | #include "G4LogicalVolume.hh" 17 | #include "G4VPhysicalVolume.hh" 18 | #include "TrackerGammaSD.hh" 19 | #include "TrackerGammaSD_Messenger.hh" 20 | #include "G4SDManager.hh" 21 | #include "G4Tubs.hh" 22 | 23 | class DetectorConstruction : public G4VUserDetectorConstruction 24 | { 25 | public: 26 | 27 | DetectorConstruction(); 28 | ~DetectorConstruction(); 29 | 30 | G4VPhysicalVolume* Construct(); 31 | Source_Capsule* getSourceCapsule(){return capsule;}; 32 | G4LogicalVolume* HallLog(){return ExpHall_log;}; 33 | 34 | private: 35 | 36 | NaI_Detector* the_NaI_Detector; 37 | 38 | Source_Capsule* capsule; 39 | Lead_Brick* brick; 40 | Target* target; 41 | 42 | // Logical volumes 43 | G4LogicalVolume* ExpHall_log; 44 | 45 | // Physical volumes 46 | G4VPhysicalVolume* ExpHall_phys; 47 | 48 | Experimental_Hall_Messenger* ExperimentalHallMessenger; 49 | TrackerGammaSD* TrackerGamma; 50 | TrackerGammaSD_Messenger* TrackerGammaSDMessenger; 51 | NaI_Detector_Messenger* the_NaI_Detector_Messenger; 52 | Source_Capsule_Messenger* capsule_Messenger; 53 | Lead_Brick_Messenger* brick_Messenger; 54 | Target_Messenger* target_Messenger; 55 | 56 | Materials* materials; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /src/DetectorConstruction.cc: -------------------------------------------------------------------------------- 1 | #include "DetectorConstruction.hh" 2 | 3 | DetectorConstruction::DetectorConstruction() 4 | { 5 | // Materials* materials=new Materials(); 6 | materials=new Materials(); 7 | 8 | // Experimental Hall 9 | 10 | Experimental_Hall* ExperimentalHall = new Experimental_Hall(materials); 11 | ExpHall_phys=ExperimentalHall->Construct(); 12 | ExpHall_log=ExperimentalHall->GetLogVolume(); 13 | // ExperimentalHall->Report(); 14 | ExperimentalHallMessenger = new Experimental_Hall_Messenger(ExperimentalHall); 15 | 16 | // NaI Detector 17 | 18 | the_NaI_Detector = new NaI_Detector(ExpHall_log, materials); 19 | the_NaI_Detector_Messenger = new NaI_Detector_Messenger(the_NaI_Detector); 20 | 21 | // Source Capsule 22 | 23 | capsule = new Source_Capsule(ExpHall_log, materials); 24 | capsule_Messenger = new Source_Capsule_Messenger(capsule); 25 | 26 | brick = new Lead_Brick(ExpHall_log, materials); 27 | 28 | brick_Messenger = new Lead_Brick_Messenger(brick); 29 | 30 | target = new Target(ExpHall_log, materials); 31 | 32 | target_Messenger = new Target_Messenger(target); 33 | } 34 | 35 | DetectorConstruction::~DetectorConstruction() 36 | { 37 | delete ExperimentalHallMessenger; 38 | delete TrackerGammaSDMessenger; 39 | 40 | } 41 | 42 | G4VPhysicalVolume* DetectorConstruction::Construct() 43 | { 44 | 45 | the_NaI_Detector->Construct(); 46 | 47 | //------------------------------------------------ 48 | // Sensitive detectors 49 | //------------------------------------------------ 50 | 51 | G4SDManager* SDman = G4SDManager::GetSDMpointer(); 52 | 53 | //------------------------------------------------ 54 | // Detectors sensitive for gamma-ray tracking 55 | //------------------------------------------------- 56 | 57 | TrackerGamma = new TrackerGammaSD("GammaTracker" ); 58 | TrackerGammaSDMessenger = new TrackerGammaSD_Messenger(TrackerGamma); 59 | SDman->AddNewDetector( TrackerGamma ); 60 | the_NaI_Detector->MakeSensitive(TrackerGamma); 61 | 62 | return ExpHall_phys; 63 | } 64 | -------------------------------------------------------------------------------- /src/Experimental_Hall_Messenger.cc: -------------------------------------------------------------------------------- 1 | #include "Experimental_Hall_Messenger.hh" 2 | 3 | 4 | Experimental_Hall_Messenger::Experimental_Hall_Messenger(Experimental_Hall* EH) 5 | :ExpHall(EH) 6 | { 7 | 8 | ExpHallDir = new G4UIdirectory("/ExpHall/"); 9 | ExpHallDir->SetGuidance("Exp. Hall control."); 10 | 11 | MatCmd = new G4UIcmdWithAString("/ExpHall/Material",this); 12 | MatCmd->SetGuidance("Select material for the exp. hall."); 13 | MatCmd->SetParameterName("choice",false); 14 | MatCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 15 | 16 | XCmd = new G4UIcmdWithADoubleAndUnit("/ExpHall/X_length",this); 17 | XCmd->SetGuidance("Select the X length for the exp. hall"); 18 | XCmd->SetParameterName("choice",false); 19 | XCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 20 | 21 | YCmd = new G4UIcmdWithADoubleAndUnit("/ExpHall/Y_length",this); 22 | YCmd->SetGuidance("Select the Y length for the exp. hall"); 23 | YCmd->SetParameterName("choice",false); 24 | YCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 25 | 26 | ZCmd = new G4UIcmdWithADoubleAndUnit("/ExpHall/Z_length",this); 27 | ZCmd->SetGuidance("Select the Z length for the exp. hall"); 28 | ZCmd->SetParameterName("choice",false); 29 | ZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 30 | 31 | 32 | 33 | RepCmd = new G4UIcmdWithoutParameter("/ExpHall/Report",this); 34 | RepCmd->SetGuidance("Report exp. hall parameters"); 35 | 36 | } 37 | 38 | 39 | 40 | Experimental_Hall_Messenger::~Experimental_Hall_Messenger() 41 | { 42 | delete XCmd; 43 | delete YCmd; 44 | delete ZCmd; 45 | delete MatCmd; 46 | delete ExpHallDir; 47 | delete RepCmd; 48 | } 49 | 50 | 51 | void Experimental_Hall_Messenger::SetNewValue(G4UIcommand* command,G4String newValue) 52 | { 53 | if( command == MatCmd ) 54 | { ExpHall->setMaterial(newValue);} 55 | if( command == XCmd ) 56 | { ExpHall->setX(XCmd->GetNewDoubleValue(newValue));} 57 | if( command == YCmd ) 58 | { ExpHall->setY(YCmd->GetNewDoubleValue(newValue));} 59 | if( command == ZCmd ) 60 | { ExpHall->setZ(ZCmd->GetNewDoubleValue(newValue));} 61 | if( command == RepCmd ) 62 | { ExpHall->Report();} 63 | 64 | } 65 | 66 | -------------------------------------------------------------------------------- /src/Source_Capsule.cc: -------------------------------------------------------------------------------- 1 | #include "Source_Capsule.hh" 2 | 3 | Source_Capsule::Source_Capsule(G4LogicalVolume* experimentalHall_log, 4 | Materials* mat) 5 | { 6 | materials=mat; 7 | expHall_log=experimentalHall_log; 8 | 9 | polyethylene = materials->FindMaterial("G4_POLYETHYLENE"); 10 | 11 | Depth=2.54*.1875*cm; 12 | Radius=2.54*.5*cm; 13 | innerRadius=2.54*.125*cm; 14 | startAngle = 45.*deg; 15 | spanningAngle = 360.*deg; 16 | 17 | Pos.setX(0); 18 | Pos.setY(0); 19 | Pos.setZ(0); 20 | 21 | Rot = G4RotationMatrix::IDENTITY; 22 | 23 | } 24 | 25 | Source_Capsule::~Source_Capsule() 26 | { 27 | } 28 | 29 | G4VPhysicalVolume* Source_Capsule::Construct() 30 | { 31 | 32 | capsule = new G4Tubs("Capsule",innerRadius,Radius,Depth/2.0,startAngle,spanningAngle); 33 | 34 | capsule_log = new G4LogicalVolume(capsule,polyethylene,"capsule_log",0,0,0); 35 | 36 | PlaceCapsule(); 37 | 38 | G4Colour dGrey (0.8, 0.8, 0.8, 1.0); 39 | G4VisAttributes* Vis = new G4VisAttributes(dGrey); 40 | Vis->SetVisibility(true); 41 | Vis->SetForceSolid(true); 42 | 43 | capsule_log->SetVisAttributes(Vis); 44 | 45 | return capsule_phys; 46 | } 47 | //--------------------------------------------------------------------- 48 | void Source_Capsule::PlaceCapsule() 49 | { 50 | 51 | capsule_phys = new G4PVPlacement(G4Transform3D(Rot,Pos), 52 | capsule_log, "Capsule", 53 | expHall_log, false, 0); 54 | 55 | } 56 | //--------------------------------------------------------------------- 57 | void Source_Capsule::setX(G4double x) 58 | { 59 | Pos.setX(x); 60 | } 61 | //--------------------------------------------------------------------- 62 | void Source_Capsule::setY(G4double y) 63 | { 64 | Pos.setY(y); 65 | } 66 | //--------------------------------------------------------------------- 67 | void Source_Capsule::setZ(G4double z) 68 | { 69 | Pos.setZ(z); 70 | } 71 | //--------------------------------------------------------------------- 72 | void Source_Capsule::rotateX(G4double ax) 73 | { 74 | Rot.rotateX(ax); 75 | } 76 | //--------------------------------------------------------------------- 77 | void Source_Capsule::rotateY(G4double ay) 78 | { 79 | Rot.rotateY(ay); 80 | } 81 | //--------------------------------------------------------------------- 82 | void Source_Capsule::rotateZ(G4double az) 83 | { 84 | Rot.rotateZ(az); 85 | } 86 | //--------------------------------------------------------------------- 87 | -------------------------------------------------------------------------------- /include/PhysicsList.hh.old: -------------------------------------------------------------------------------- 1 | #ifndef PhysicsList_h 2 | #define PhysicsList_h 1 3 | 4 | #include "G4VUserPhysicsList.hh" 5 | #include "G4ParticleTypes.hh" 6 | #include "G4ProcessManager.hh" 7 | 8 | //gamma 9 | #include "G4ComptonScattering.hh" 10 | #include "G4GammaConversion.hh" 11 | #include "G4PhotoElectricEffect.hh" 12 | #include "G4RayleighScattering.hh" 13 | 14 | //e-/e+ 15 | #include "G4eBremsstrahlung.hh" 16 | #include "G4eIonisation.hh" 17 | #include "G4eMultipleScattering.hh" 18 | #include "G4eplusAnnihilation.hh" 19 | 20 | // Low Energy EM Processes (deprecated) 21 | //#include "G4LowEnergyRayleigh.hh" 22 | //#include "G4LowEnergyPhotoElectric.hh" 23 | //#include "G4LowEnergyCompton.hh" 24 | //#include "G4LowEnergyGammaConversion.hh" 25 | //#include "G4LowEnergyIonisation.hh" 26 | //#include "G4LowEnergyBremsstrahlung.hh" 27 | 28 | // Penelope Low Energy EM Processes (deprecated) 29 | //#include "G4PenelopeIonisation.hh" 30 | //#include "G4PenelopeBremsstrahlung.hh" 31 | //#include "G4PenelopeAnnihilation.hh" 32 | //#include "G4PenelopeCompton.hh" 33 | //#include "G4PenelopePhotoElectric.hh" 34 | //#include "G4PenelopeGammaConversion.hh" 35 | //#include "G4PenelopeRayleigh.hh" 36 | 37 | // Livermore Low Energy EM Models 38 | //#include "G4LivermorePhotoElectricModel.hh" 39 | //#include "G4LivermoreComptonModel.hh" 40 | //#include "G4LivermoreGammaConversionModel.hh" 41 | //#include "G4LivermoreRayleighModel.hh" 42 | //#include "G4LivermoreIonisationModel.hh" 43 | //#include "G4LivermoreBremsstrahlungModel.hh" 44 | 45 | // Penelope Low Energy EM Models 46 | #include "G4PenelopeIonisationModel.hh" 47 | #include "G4PenelopeBremsstrahlungModel.hh" 48 | #include "G4PenelopeAnnihilationModel.hh" 49 | #include "G4PenelopeComptonModel.hh" 50 | #include "G4PenelopePhotoElectricModel.hh" 51 | #include "G4PenelopeGammaConversionModel.hh" 52 | #include "G4PenelopeRayleighModel.hh" 53 | 54 | // ions 55 | #include "G4ionIonisation.hh" 56 | #include "G4hMultipleScattering.hh" 57 | #include "G4IonTable.hh" 58 | #include "G4IonConstructor.hh" 59 | #include "G4StepLimiter.hh" 60 | 61 | class PhysicsList: public G4VUserPhysicsList 62 | { 63 | public: 64 | PhysicsList(); 65 | ~PhysicsList(); 66 | 67 | protected: 68 | // Construct particle and physics process 69 | void ConstructParticle(); 70 | void ConstructProcess(); 71 | void ConstructEM(); 72 | void SetCuts(); 73 | 74 | private: 75 | G4double cutForGamma; //LR 76 | G4double cutForElectron; //LR 77 | G4double cutForPositron; //LR 78 | 79 | }; 80 | 81 | #endif 82 | -------------------------------------------------------------------------------- /src/TrackerGammaHit.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "TrackerGammaHit.hh" 3 | #include "G4UnitsTable.hh" 4 | #include "G4VVisManager.hh" 5 | #include "G4Circle.hh" 6 | #include "G4Colour.hh" 7 | #include "G4VisAttributes.hh" 8 | 9 | G4Allocator TrackerGammaHitAllocator; 10 | 11 | 12 | TrackerGammaHit::TrackerGammaHit() {} 13 | 14 | 15 | 16 | TrackerGammaHit::~TrackerGammaHit() {} 17 | 18 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 19 | 20 | TrackerGammaHit::TrackerGammaHit(const TrackerGammaHit& right) 21 | : G4VHit() 22 | { 23 | trackID = right.trackID; 24 | particleID = right.particleID; 25 | detID = right.detID; 26 | edep = right.edep; 27 | etotal = right.etotal; 28 | pos = right.pos; 29 | } 30 | 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 | 33 | const TrackerGammaHit& TrackerGammaHit::operator=(const TrackerGammaHit& right) 34 | { 35 | trackID = right.trackID; 36 | particleID = right.particleID; 37 | detID = right.detID; 38 | edep = right.edep; 39 | etotal = right.etotal; 40 | pos = right.pos; 41 | return *this; 42 | } 43 | 44 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 | 46 | G4int TrackerGammaHit::operator==(const TrackerGammaHit& right) const 47 | { 48 | return (this==&right) ? 1 : 0; 49 | } 50 | 51 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 | 53 | void TrackerGammaHit::Draw() 54 | { 55 | G4VVisManager* pVVisManager = G4VVisManager::GetConcreteInstance(); 56 | if(pVVisManager) 57 | { 58 | G4Circle circle(pos); 59 | circle.SetScreenSize(4); 60 | circle.SetFillStyle(G4Circle::filled); 61 | G4Colour colour(1.,1.,0.); 62 | G4VisAttributes attribs(colour); 63 | circle.SetVisAttributes(attribs); 64 | pVVisManager->Draw(circle); 65 | } 66 | } 67 | 68 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 69 | 70 | void TrackerGammaHit::Print() 71 | { 72 | 73 | G4cout << std::setw(5) << std::right << trackID 74 | << std::setw(10) << particleID 75 | << std::setw(5) << detID 76 | << std::fixed << std::setprecision(2) << std::setw(10) << std::right 77 | << edep/keV 78 | << std::setw(10) << std::right 79 | << pos.getX()/mm 80 | << std::setw(10) << std::right 81 | << pos.getY()/mm 82 | << std::setw(10) << std::right 83 | << pos.getZ()/mm 84 | << G4endl; 85 | 86 | } 87 | 88 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 89 | 90 | -------------------------------------------------------------------------------- /include/TrackerGammaHit.hh: -------------------------------------------------------------------------------- 1 | 2 | #ifndef TrackerGammaHit_h 3 | #define TrackerGammaHit_h 1 4 | 5 | #include "G4VHit.hh" 6 | #include "G4THitsCollection.hh" 7 | #include "G4Allocator.hh" 8 | #include "G4ThreeVector.hh" 9 | #include "G4SystemOfUnits.hh" 10 | #include 11 | 12 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 13 | 14 | class TrackerGammaHit : public G4VHit 15 | { 16 | public: 17 | 18 | TrackerGammaHit(); 19 | ~TrackerGammaHit(); 20 | TrackerGammaHit(const TrackerGammaHit&); 21 | const TrackerGammaHit& operator=(const TrackerGammaHit&); 22 | G4int operator==(const TrackerGammaHit&) const; 23 | 24 | inline void* operator new(size_t); 25 | inline void operator delete(void*); 26 | 27 | void Draw(); 28 | void Print(); 29 | 30 | public: 31 | 32 | void SetTrackID (G4int track) { trackID = track; }; 33 | void SetParticleID (G4String particle){ particleID = particle; }; 34 | void SetDetID(G4int id) { detID = id; }; 35 | void SetEdep (G4double de) { edep = de; }; 36 | void SetTotalEnergy(G4double te) { etotal = te; }; 37 | void SetPos (G4ThreeVector xyz) { pos = xyz; }; 38 | 39 | G4int GetTrackID() { return trackID; }; 40 | G4String GetParticleID() { return particleID; }; 41 | G4int GetDetID() { return detID; }; 42 | G4double GetEdep() { return edep; }; 43 | G4double GetTotalEnergy(){ return etotal; }; 44 | G4ThreeVector GetPos() { return pos; }; 45 | 46 | private: 47 | 48 | G4int trackID; 49 | G4String particleID; 50 | G4int detID; 51 | G4double edep; 52 | G4double etotal; 53 | G4ThreeVector pos; 54 | }; 55 | 56 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 | 58 | typedef G4THitsCollection TrackerGammaHitsCollection; 59 | 60 | extern G4Allocator TrackerGammaHitAllocator; 61 | 62 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 63 | 64 | inline void* TrackerGammaHit::operator new(size_t) 65 | { 66 | void *aHit; 67 | aHit = (void *) TrackerGammaHitAllocator.MallocSingle(); 68 | return aHit; 69 | } 70 | 71 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 72 | 73 | inline void TrackerGammaHit::operator delete(void *aHit) 74 | { 75 | TrackerGammaHitAllocator.FreeSingle((TrackerGammaHit*) aHit); 76 | } 77 | 78 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 79 | 80 | #endif 81 | -------------------------------------------------------------------------------- /include/StepMaxMessenger.hh: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | /// \file polarisation/Pol01/include/StepMaxMessenger.hh 27 | /// \brief Definition of the StepMaxMessenger class 28 | // 29 | // 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 | 33 | #ifndef StepMaxMessenger_h 34 | #define StepMaxMessenger_h 1 35 | 36 | #include "G4UImessenger.hh" 37 | #include "globals.hh" 38 | 39 | class StepMax; 40 | class G4UIcmdWithADoubleAndUnit; 41 | 42 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 43 | 44 | class StepMaxMessenger: public G4UImessenger 45 | { 46 | public: 47 | StepMaxMessenger(StepMax*); 48 | ~StepMaxMessenger(); 49 | 50 | virtual void SetNewValue(G4UIcommand*, G4String); 51 | 52 | private: 53 | StepMax* fStepMax; 54 | G4UIcmdWithADoubleAndUnit* fStepMaxCmd; 55 | }; 56 | 57 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /examples/cs137/plotMca.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | import sys 4 | 5 | #====================================================================== 6 | # Read a spectrum from an ADMCA .mca file 7 | # 8 | # To load the spectrum in the file "myspectrum.mca" (stored in the 9 | # same directory as the notebook): 10 | # 11 | # realTime, liveTime, bins, counts = readMca("myspectrum.mca", 10) 12 | # 13 | # realTime: duration of the measurement 14 | # liveTime: live time of the acquisition system 15 | # bins: list of bin positions 16 | # counts list of count values 17 | # 18 | #====================================================================== 19 | def readMca(filename, binning = 1): 20 | infile = open(filename, 'r') 21 | 22 | # Skip to line 8 and store the live time. 23 | for i in range(8): 24 | line = infile.readline() 25 | words = line.split() 26 | liveTime = float(words[2]) 27 | 28 | # Store the real time. 29 | line = infile.readline() 30 | words = line.split() 31 | realTime = float(words[2]) 32 | 33 | # Skip the rest of the header. 34 | for i in range(7): 35 | line = infile.readline() 36 | 37 | # Empty lists for the spectrum 38 | bins = [] 39 | counts = [] 40 | 41 | bin = 1 42 | while 1: 43 | line = infile.readline(); 44 | if "END" in line: # Stop when you read the <> tag 45 | break 46 | words = line.split() 47 | bins.append(bin) 48 | bin += 1 49 | counts.append(float(words[0])) 50 | bins = np.array(bins) 51 | counts = np.array(counts) 52 | 53 | # Rebin the spectrum. 54 | if binning > 1: 55 | newbins = [] 56 | newcounts = [] 57 | j = 0 58 | bin = 0 59 | count = 0 60 | for i in range(len(bins)): 61 | j += 1 62 | count += counts[i] 63 | bin += bins[i] 64 | if j == binning: 65 | newbins.append(bin/binning) 66 | newcounts.append(count) 67 | j = 0 68 | bin = 0 69 | count = 0 70 | bins = np.array(newbins) 71 | counts = np.array(newcounts) 72 | 73 | return realTime, liveTime, bins, counts 74 | 75 | if(len(sys.argv) == 3): 76 | binning = int(sys.argv[2]) 77 | elif(len(sys.argv) == 2): 78 | binning = 1 79 | else: 80 | print('Usage: python plotPCA.py ') 81 | exit 82 | 83 | realTime, liveTime, bins, counts = readMca(sys.argv[1], binning) 84 | 85 | plt.step(bins, counts, where='mid', color='blue') 86 | #plt.yscale('log') 87 | plt.xlabel('E (keV)') 88 | plt.ylabel('Counts/bin') 89 | plt.title(sys.argv[1]) 90 | 91 | plt.show() 92 | -------------------------------------------------------------------------------- /examples/na22/plotMca.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | import sys 4 | 5 | #====================================================================== 6 | # Read a spectrum from an ADMCA .mca file 7 | # 8 | # To load the spectrum in the file "myspectrum.mca" (stored in the 9 | # same directory as the notebook): 10 | # 11 | # realTime, liveTime, bins, counts = readMca("myspectrum.mca", 10) 12 | # 13 | # realTime: duration of the measurement 14 | # liveTime: live time of the acquisition system 15 | # bins: list of bin positions 16 | # counts list of count values 17 | # 18 | #====================================================================== 19 | def readMca(filename, binning = 1): 20 | infile = open(filename, 'r') 21 | 22 | # Skip to line 8 and store the live time. 23 | for i in range(8): 24 | line = infile.readline() 25 | words = line.split() 26 | liveTime = float(words[2]) 27 | 28 | # Store the real time. 29 | line = infile.readline() 30 | words = line.split() 31 | realTime = float(words[2]) 32 | 33 | # Skip the rest of the header. 34 | for i in range(7): 35 | line = infile.readline() 36 | 37 | # Empty lists for the spectrum 38 | bins = [] 39 | counts = [] 40 | 41 | bin = 1 42 | while 1: 43 | line = infile.readline(); 44 | if "END" in line: # Stop when you read the <> tag 45 | break 46 | words = line.split() 47 | bins.append(bin) 48 | bin += 1 49 | counts.append(float(words[0])) 50 | bins = np.array(bins) 51 | counts = np.array(counts) 52 | 53 | # Rebin the spectrum. 54 | if binning > 1: 55 | newbins = [] 56 | newcounts = [] 57 | j = 0 58 | bin = 0 59 | count = 0 60 | for i in range(len(bins)): 61 | j += 1 62 | count += counts[i] 63 | bin += bins[i] 64 | if j == binning: 65 | newbins.append(bin/binning) 66 | newcounts.append(count) 67 | j = 0 68 | bin = 0 69 | count = 0 70 | bins = np.array(newbins) 71 | counts = np.array(newcounts) 72 | 73 | return realTime, liveTime, bins, counts 74 | 75 | if(len(sys.argv) == 3): 76 | binning = int(sys.argv[2]) 77 | elif(len(sys.argv) == 2): 78 | binning = 1 79 | else: 80 | print('Usage: python plotPCA.py ') 81 | exit 82 | 83 | realTime, liveTime, bins, counts = readMca(sys.argv[1], binning) 84 | 85 | plt.step(bins, counts, where='mid', color='blue') 86 | #plt.yscale('log') 87 | plt.xlabel('E (keV)') 88 | plt.ylabel('Counts/bin') 89 | plt.title(sys.argv[1]) 90 | 91 | plt.show() 92 | -------------------------------------------------------------------------------- /examples/simple/plotMca.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | import sys 4 | 5 | #====================================================================== 6 | # Read a spectrum from an ADMCA .mca file 7 | # 8 | # To load the spectrum in the file "myspectrum.mca" (stored in the 9 | # same directory as the notebook): 10 | # 11 | # realTime, liveTime, bins, counts = readMca("myspectrum.mca", 10) 12 | # 13 | # realTime: duration of the measurement 14 | # liveTime: live time of the acquisition system 15 | # bins: list of bin positions 16 | # counts list of count values 17 | # 18 | #====================================================================== 19 | def readMca(filename, binning = 1): 20 | infile = open(filename, 'r') 21 | 22 | # Skip to line 8 and store the live time. 23 | for i in range(8): 24 | line = infile.readline() 25 | words = line.split() 26 | liveTime = float(words[2]) 27 | 28 | # Store the real time. 29 | line = infile.readline() 30 | words = line.split() 31 | realTime = float(words[2]) 32 | 33 | # Skip the rest of the header. 34 | for i in range(7): 35 | line = infile.readline() 36 | 37 | # Empty lists for the spectrum 38 | bins = [] 39 | counts = [] 40 | 41 | bin = 1 42 | while 1: 43 | line = infile.readline(); 44 | if "END" in line: # Stop when you read the <> tag 45 | break 46 | words = line.split() 47 | bins.append(bin) 48 | bin += 1 49 | counts.append(float(words[0])) 50 | bins = np.array(bins) 51 | counts = np.array(counts) 52 | 53 | # Rebin the spectrum. 54 | if binning > 1: 55 | newbins = [] 56 | newcounts = [] 57 | j = 0 58 | bin = 0 59 | count = 0 60 | for i in range(len(bins)): 61 | j += 1 62 | count += counts[i] 63 | bin += bins[i] 64 | if j == binning: 65 | newbins.append(bin/binning) 66 | newcounts.append(count) 67 | j = 0 68 | bin = 0 69 | count = 0 70 | bins = np.array(newbins) 71 | counts = np.array(newcounts) 72 | 73 | return realTime, liveTime, bins, counts 74 | 75 | if(len(sys.argv) == 3): 76 | binning = int(sys.argv[2]) 77 | elif(len(sys.argv) == 2): 78 | binning = 1 79 | else: 80 | print('Usage: python plotPCA.py ') 81 | exit 82 | 83 | realTime, liveTime, bins, counts = readMca(sys.argv[1], binning) 84 | 85 | plt.step(bins, counts, where='mid', color='blue') 86 | #plt.yscale('log') 87 | plt.xlabel('E (keV)') 88 | plt.ylabel('Counts/bin') 89 | plt.title(sys.argv[1]) 90 | 91 | plt.show() 92 | -------------------------------------------------------------------------------- /src/PrimaryGeneratorAction_Messenger.cc: -------------------------------------------------------------------------------- 1 | #include "PrimaryGeneratorAction_Messenger.hh" 2 | 3 | 4 | PrimaryGeneratorAction_Messenger::PrimaryGeneratorAction_Messenger(PrimaryGeneratorAction* pga):PGA(pga) 5 | { 6 | SrcDir = new G4UIdirectory("/Source/"); 7 | SrcDir->SetGuidance("Select source parameters for simulation."); 8 | 9 | SrcECmd = new G4UIcmdWithADoubleAndUnit("/Source/Simple",this); 10 | SrcECmd->SetGuidance("Use a simple monoenergetic gamma-ray energy with the specified energy."); 11 | SrcECmd->SetParameterName("Source Energy",false); 12 | SrcECmd->AvailableForStates(G4State_PreInit,G4State_Idle); 13 | 14 | SrcMCmd = new G4UIcmdWithADoubleAndUnit("/Source/Muon",this); 15 | SrcMCmd->SetGuidance("Set the energy of a monoenergetic muon source."); 16 | SrcMCmd->SetParameterName("Muon Source Energy",false); 17 | SrcMCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 18 | 19 | SrcXCmd = new G4UIcmdWithADoubleAndUnit("/Source/setX",this); 20 | SrcXCmd->SetGuidance("Set X position for the source"); 21 | SrcXCmd->SetParameterName("Source X position",false); 22 | SrcXCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 23 | 24 | SrcYCmd = new G4UIcmdWithADoubleAndUnit("/Source/setY",this); 25 | SrcYCmd->SetGuidance("Set Y position for the source"); 26 | SrcYCmd->SetParameterName("Source Y position",false); 27 | SrcYCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 28 | 29 | SrcZCmd = new G4UIcmdWithADoubleAndUnit("/Source/setZ",this); 30 | SrcZCmd->SetGuidance("Set Z position for the source"); 31 | SrcZCmd->SetParameterName("Source Z position",false); 32 | SrcZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 33 | 34 | SrcCCmd = new G4UIcmdWithoutParameter("/Source/Capsule/Construct",this); 35 | SrcCCmd->SetGuidance("Construct source capsule"); 36 | 37 | } 38 | 39 | PrimaryGeneratorAction_Messenger::~PrimaryGeneratorAction_Messenger() 40 | { 41 | delete SrcDir; 42 | delete SrcECmd; 43 | delete SrcMCmd; 44 | delete SrcXCmd; 45 | delete SrcYCmd; 46 | delete SrcZCmd; 47 | delete SrcCCmd; 48 | } 49 | 50 | void PrimaryGeneratorAction_Messenger::SetNewValue(G4UIcommand* command,G4String newValue) 51 | { 52 | 53 | if( command == SrcECmd ) 54 | {PGA ->SetSourceEnergy(SrcECmd->GetNewDoubleValue(newValue));} 55 | 56 | if( command == SrcMCmd ) 57 | {PGA ->SetMuonEnergy(SrcMCmd->GetNewDoubleValue(newValue));} 58 | 59 | if( command == SrcXCmd ) 60 | {PGA ->SetSourceX(SrcXCmd->GetNewDoubleValue(newValue));} 61 | 62 | if( command == SrcYCmd ) 63 | {PGA ->SetSourceY(SrcYCmd->GetNewDoubleValue(newValue));} 64 | 65 | if( command == SrcZCmd ) 66 | {PGA ->SetSourceZ(SrcZCmd->GetNewDoubleValue(newValue));} 67 | 68 | if( command == SrcCCmd ) 69 | {PGA ->getDetectorConstruction()->getSourceCapsule()->Construct();} 70 | 71 | } 72 | 73 | -------------------------------------------------------------------------------- /examples/cs137/diffMca.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | import sys 4 | 5 | #====================================================================== 6 | # Read a spectrum from an ADMCA .mca file 7 | # 8 | # To load the spectrum in the file "myspectrum.mca" (stored in the 9 | # same directory as the notebook): 10 | # 11 | # realTime, liveTime, bins, counts = readMca("myspectrum.mca", 10) 12 | # 13 | # realTime: duration of the measurement 14 | # liveTime: live time of the acquisition system 15 | # bins: list of bin positions 16 | # counts list of count values 17 | # 18 | #====================================================================== 19 | def readMca(filename, binning = 1): 20 | infile = open(filename, 'r') 21 | 22 | # Skip to line 8 and store the live time. 23 | for i in range(8): 24 | line = infile.readline() 25 | words = line.split() 26 | liveTime = float(words[2]) 27 | 28 | # Store the real time. 29 | line = infile.readline() 30 | words = line.split() 31 | realTime = float(words[2]) 32 | 33 | # Skip the rest of the header. 34 | for i in range(7): 35 | line = infile.readline() 36 | 37 | # Empty lists for the spectrum 38 | bins = [] 39 | counts = [] 40 | 41 | bin = 1 42 | while 1: 43 | line = infile.readline(); 44 | if "END" in line: # Stop when you read the <> tag 45 | break 46 | words = line.split() 47 | bins.append(bin) 48 | bin += 1 49 | counts.append(float(words[0])) 50 | bins = np.array(bins) 51 | counts = np.array(counts) 52 | 53 | # Rebin the spectrum. 54 | if binning > 1: 55 | newbins = [] 56 | newcounts = [] 57 | j = 0 58 | bin = 0 59 | count = 0 60 | for i in range(len(bins)): 61 | j += 1 62 | count += counts[i] 63 | bin += bins[i] 64 | if j == binning: 65 | newbins.append(bin/binning) 66 | newcounts.append(count) 67 | j = 0 68 | bin = 0 69 | count = 0 70 | bins = np.array(newbins) 71 | counts = np.array(newcounts) 72 | 73 | return realTime, liveTime, bins, counts 74 | 75 | if(len(sys.argv) == 4): 76 | binning = int(sys.argv[3]) 77 | elif(len(sys.argv) == 3): 78 | binning = 1 79 | else: 80 | print('Usage: python plotPCA.py ') 81 | exit 82 | 83 | _, _, bins1, counts1 = readMca(sys.argv[1], binning) 84 | _, _, bins2, counts2 = readMca(sys.argv[2], binning) 85 | 86 | plt.step(bins1, counts1, where='mid', color='black', label=sys.argv[1]) 87 | plt.step(bins2, counts2, where='mid', color='blue', label=sys.argv[2]) 88 | #plt.yscale('log') 89 | plt.xlabel('E (keV)') 90 | plt.ylabel('Counts/bin') 91 | plt.title(sys.argv[1]) 92 | plt.legend() 93 | 94 | plt.show() 95 | -------------------------------------------------------------------------------- /examples/na22/diffMca.py: -------------------------------------------------------------------------------- 1 | import matplotlib.pyplot as plt 2 | import numpy as np 3 | import sys 4 | 5 | #====================================================================== 6 | # Read a spectrum from an ADMCA .mca file 7 | # 8 | # To load the spectrum in the file "myspectrum.mca" (stored in the 9 | # same directory as the notebook): 10 | # 11 | # realTime, liveTime, bins, counts = readMca("myspectrum.mca", 10) 12 | # 13 | # realTime: duration of the measurement 14 | # liveTime: live time of the acquisition system 15 | # bins: list of bin positions 16 | # counts list of count values 17 | # 18 | #====================================================================== 19 | def readMca(filename, binning = 1): 20 | infile = open(filename, 'r') 21 | 22 | # Skip to line 8 and store the live time. 23 | for i in range(8): 24 | line = infile.readline() 25 | words = line.split() 26 | liveTime = float(words[2]) 27 | 28 | # Store the real time. 29 | line = infile.readline() 30 | words = line.split() 31 | realTime = float(words[2]) 32 | 33 | # Skip the rest of the header. 34 | for i in range(7): 35 | line = infile.readline() 36 | 37 | # Empty lists for the spectrum 38 | bins = [] 39 | counts = [] 40 | 41 | bin = 1 42 | while 1: 43 | line = infile.readline(); 44 | if "END" in line: # Stop when you read the <> tag 45 | break 46 | words = line.split() 47 | bins.append(bin) 48 | bin += 1 49 | counts.append(float(words[0])) 50 | bins = np.array(bins) 51 | counts = np.array(counts) 52 | 53 | # Rebin the spectrum. 54 | if binning > 1: 55 | newbins = [] 56 | newcounts = [] 57 | j = 0 58 | bin = 0 59 | count = 0 60 | for i in range(len(bins)): 61 | j += 1 62 | count += counts[i] 63 | bin += bins[i] 64 | if j == binning: 65 | newbins.append(bin/binning) 66 | newcounts.append(count) 67 | j = 0 68 | bin = 0 69 | count = 0 70 | bins = np.array(newbins) 71 | counts = np.array(newcounts) 72 | 73 | return realTime, liveTime, bins, counts 74 | 75 | if(len(sys.argv) == 4): 76 | binning = int(sys.argv[3]) 77 | elif(len(sys.argv) == 3): 78 | binning = 1 79 | else: 80 | print('Usage: python plotPCA.py ') 81 | exit 82 | 83 | _, _, bins1, counts1 = readMca(sys.argv[1], binning) 84 | _, _, bins2, counts2 = readMca(sys.argv[2], binning) 85 | 86 | plt.step(bins1, counts1, where='mid', color='black', label=sys.argv[1]) 87 | plt.step(bins2, counts2, where='mid', color='blue', label=sys.argv[2]) 88 | #plt.yscale('log') 89 | plt.xlabel('E (keV)') 90 | plt.ylabel('Counts/bin') 91 | plt.title(sys.argv[1]) 92 | plt.legend() 93 | 94 | plt.show() 95 | -------------------------------------------------------------------------------- /include/PhysicsListMessenger.hh: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | /// \file electromagnetic/TestEm7/include/PhysicsListMessenger.hh 27 | /// \brief Definition of the PhysicsListMessenger class 28 | // 29 | // 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 | 33 | #ifndef PhysicsListMessenger_h 34 | #define PhysicsListMessenger_h 1 35 | 36 | #include "globals.hh" 37 | #include "G4UImessenger.hh" 38 | 39 | class PhysicsList; 40 | class G4UIdirectory; 41 | class G4UIcmdWithAString; 42 | class G4UIcmdWithABool; 43 | 44 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 45 | 46 | class PhysicsListMessenger: public G4UImessenger 47 | { 48 | public: 49 | 50 | PhysicsListMessenger(PhysicsList* ); 51 | ~PhysicsListMessenger(); 52 | 53 | virtual void SetNewValue(G4UIcommand*, G4String); 54 | 55 | private: 56 | 57 | PhysicsList* fPhysicsList; 58 | 59 | G4UIdirectory* fPhysDir; 60 | G4UIcmdWithAString* fListCmd; 61 | G4UIcmdWithABool* PolCmd; 62 | 63 | }; 64 | 65 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 66 | 67 | #endif 68 | 69 | -------------------------------------------------------------------------------- /include/NaI_Detector.hh: -------------------------------------------------------------------------------- 1 | #ifndef NaI_Detector_H 2 | #define NaI_Detector_H 1 3 | 4 | #include "G4Material.hh" 5 | #include "Materials.hh" 6 | #include "G4Tubs.hh" 7 | #include "G4AssemblyVolume.hh" 8 | #include "G4LogicalVolume.hh" 9 | #include "G4VPhysicalVolume.hh" 10 | #include "G4ThreeVector.hh" 11 | #include "G4PVPlacement.hh" 12 | #include "G4PVReplica.hh" 13 | #include "G4PVDivision.hh" 14 | 15 | #include "TrackerGammaSD.hh" 16 | 17 | #include "G4VisAttributes.hh" 18 | #include "G4Colour.hh" 19 | #include "G4SubtractionSolid.hh" 20 | 21 | #include "G4RotationMatrix.hh" 22 | #include "G4Transform3D.hh" 23 | #include "Randomize.hh" 24 | #include "globals.hh" 25 | #include 26 | #include 27 | 28 | using namespace std; 29 | 30 | class NaI_Detector 31 | { 32 | public: 33 | 34 | G4LogicalVolume *expHall_log; 35 | Materials* materials; 36 | 37 | NaI_Detector(G4LogicalVolume*, Materials*); 38 | ~NaI_Detector(); 39 | 40 | void Construct(); 41 | 42 | void setX(G4double x){assemblyPos.setX(x);} 43 | void setY(G4double y){assemblyPos.setY(y);} 44 | void setZ(G4double z){assemblyPos.setZ(z);} 45 | void setR(G4double r){Radius = r;} 46 | void setL(G4double l){Length = l;} 47 | void rotateX(G4double ax){assemblyRot.rotateX(ax);} 48 | void rotateY(G4double ay){assemblyRot.rotateY(ay);} 49 | void rotateZ(G4double az){assemblyRot.rotateZ(az);} 50 | void setGeoFile(G4String fname){geoFileName = fname;} 51 | 52 | void PlaceDetector(); 53 | void MakeSensitive(TrackerGammaSD*); 54 | 55 | private: 56 | 57 | // Logical volumes 58 | 59 | G4LogicalVolume* detector_log; 60 | G4LogicalVolume* can_log; 61 | G4LogicalVolume* cap_log; 62 | G4LogicalVolume* pmt_log; 63 | 64 | // Physical volumes 65 | 66 | G4VPhysicalVolume* detector_phys; 67 | G4VPhysicalVolume* can_phys; 68 | G4VPhysicalVolume* cap_phys; 69 | G4VPhysicalVolume* pmt_phys; 70 | 71 | // Materials 72 | G4Material* NaI; 73 | G4Material* Al; 74 | G4Material* pmtMat; 75 | 76 | // dimensions 77 | G4double Length; 78 | G4double Radius; 79 | G4double CanThickness; 80 | G4double CanInnerRadius; 81 | G4double CanOuterRadius; 82 | G4double CanLength; 83 | G4double pmtRadius; 84 | G4double pmtLength; 85 | 86 | G4double startAngle; 87 | G4double spanningAngle; 88 | 89 | // position 90 | G4RotationMatrix DetRot; 91 | G4RotationMatrix assemblyRot; 92 | G4ThreeVector detShift; 93 | G4ThreeVector DetPos; 94 | G4ThreeVector pmtShift; 95 | G4ThreeVector pmtPos; 96 | G4ThreeVector canShift; 97 | G4ThreeVector capShift; 98 | G4ThreeVector canPos; 99 | G4ThreeVector capPos; 100 | G4ThreeVector assemblyPos; 101 | G4double thetad; 102 | G4double phid; 103 | 104 | G4Tubs* can; 105 | G4Tubs* cap; 106 | G4Tubs* pmt; 107 | G4Tubs* detector; 108 | G4AssemblyVolume * assembly; 109 | 110 | G4String geoFileName; 111 | std::ifstream geoFile; 112 | }; 113 | 114 | #endif 115 | 116 | -------------------------------------------------------------------------------- /src/Lead_Brick_Messenger.cc: -------------------------------------------------------------------------------- 1 | #include "Lead_Brick_Messenger.hh" 2 | 3 | Lead_Brick_Messenger::Lead_Brick_Messenger(Lead_Brick* LB) 4 | :Brick(LB) 5 | { 6 | 7 | BrickDir = new G4UIdirectory("/Brick/"); 8 | BrickDir->SetGuidance("Brick control."); 9 | 10 | XCmd = new G4UIcmdWithADoubleAndUnit("/Brick/setX",this); 11 | XCmd->SetGuidance("Set the x position of the brick center"); 12 | XCmd->SetParameterName("choice",false); 13 | XCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 14 | 15 | YCmd = new G4UIcmdWithADoubleAndUnit("/Brick/setY",this); 16 | YCmd->SetGuidance("Set the y position of the brick center"); 17 | YCmd->SetParameterName("choice",false); 18 | YCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 19 | 20 | ZCmd = new G4UIcmdWithADoubleAndUnit("/Brick/setZ",this); 21 | ZCmd->SetGuidance("Set the z position of the brick center"); 22 | ZCmd->SetParameterName("choice",false); 23 | ZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 24 | 25 | rXCmd = new G4UIcmdWithADoubleAndUnit("/Brick/rotateX",this); 26 | rXCmd->SetGuidance("Rotate the brick about the x axis"); 27 | rXCmd->SetParameterName("choice",false); 28 | rXCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 29 | 30 | rYCmd = new G4UIcmdWithADoubleAndUnit("/Brick/rotateY",this); 31 | rYCmd->SetGuidance("Rotate the brick about the y axis"); 32 | rYCmd->SetParameterName("choice",false); 33 | rYCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 34 | 35 | rZCmd = new G4UIcmdWithADoubleAndUnit("/Brick/rotateZ",this); 36 | rZCmd->SetGuidance("Rotate the brick about the z axis"); 37 | rZCmd->SetParameterName("choice",false); 38 | rZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 39 | 40 | cCmd = new G4UIcmdWithoutParameter("/Brick/Construct",this); 41 | cCmd->SetGuidance("Construct the brick"); 42 | cCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 43 | 44 | GCmd = new G4UIcmdWithAString("/Brick/GeometryFile",this); 45 | GCmd->SetGuidance("Set the brick geometry file name."); 46 | GCmd->SetParameterName("choice",false); 47 | GCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 48 | 49 | } 50 | 51 | Lead_Brick_Messenger::~Lead_Brick_Messenger() 52 | { 53 | delete BrickDir; 54 | delete XCmd; 55 | delete YCmd; 56 | delete ZCmd; 57 | delete rXCmd; 58 | delete rYCmd; 59 | delete rZCmd; 60 | delete cCmd; 61 | delete GCmd; 62 | } 63 | 64 | 65 | void Lead_Brick_Messenger::SetNewValue(G4UIcommand* command,G4String newValue) 66 | { 67 | if( command == XCmd ) 68 | {Brick->setX(XCmd->GetNewDoubleValue(newValue));} 69 | if( command == YCmd ) 70 | {Brick->setY(YCmd->GetNewDoubleValue(newValue));} 71 | if( command == ZCmd ) 72 | {Brick->setZ(ZCmd->GetNewDoubleValue(newValue));} 73 | if( command == rXCmd ) 74 | {Brick->rotateX(rXCmd->GetNewDoubleValue(newValue));} 75 | if( command == rYCmd ) 76 | {Brick->rotateY(rYCmd->GetNewDoubleValue(newValue));} 77 | if( command == rZCmd ) 78 | {Brick->rotateZ(rZCmd->GetNewDoubleValue(newValue));} 79 | if( command == cCmd ) 80 | {Brick->Construct();} 81 | if( command == GCmd ) 82 | {Brick->setGeoFile(newValue);} 83 | } 84 | 85 | -------------------------------------------------------------------------------- /src/Experimental_Hall.cc: -------------------------------------------------------------------------------- 1 | #include "Experimental_Hall.hh" 2 | 3 | Experimental_Hall::Experimental_Hall(Materials* mat) 4 | { 5 | materials=mat; 6 | expHall_x = 400.*cm; 7 | expHall_y = 400.*cm; 8 | expHall_z = 400.*cm; 9 | 10 | ExperimentalHallMaterial = materials->FindMaterial("G4_Galactic"); 11 | 12 | 13 | } 14 | 15 | Experimental_Hall::~Experimental_Hall() 16 | {;} 17 | //----------------------------------------------------------------------------- 18 | G4VPhysicalVolume* Experimental_Hall::Construct() 19 | { 20 | 21 | ExperimentalHall 22 | = new G4Box("expHall_box",expHall_x,expHall_y,expHall_z); 23 | 24 | ExperimentalHall_log = new G4LogicalVolume(ExperimentalHall, 25 | ExperimentalHallMaterial,"expHall_log",0,0,0); 26 | 27 | ExperimentalHall_phys = new G4PVPlacement(0,G4ThreeVector(), 28 | ExperimentalHall_log,"expHall",0,false,0); 29 | 30 | ExperimentalHall_log-> SetVisAttributes (G4VisAttributes::Invisible); 31 | 32 | return ExperimentalHall_phys; 33 | } 34 | //----------------------------------------------------------------------------- 35 | void Experimental_Hall::setX(G4double X) 36 | { 37 | expHall_x=X/2.; 38 | ExperimentalHall->SetXHalfLength(expHall_x); 39 | G4cout<<"----> Exp. Hall X length is set to "<GetXHalfLength(),"Length")<SetYHalfLength(expHall_y); 46 | G4cout<<"----> Exp. Hall Y length is set to "<GetYHalfLength(),"Length")<SetZHalfLength(expHall_z); 53 | G4cout<<"----> Exp. Hall Z length is set to "<GetZHalfLength(),"Length")< Exp. Hall material set to "<GetMaterial()->GetName()<< G4endl; 60 | G4cout<<"----> Exp. Hall X length is set to "<GetXHalfLength(),"Length")< Exp. Hall Y length is set to "<GetYHalfLength(),"Length")< Exp. Hall Z length is set to "<GetZHalfLength(),"Length")<FindMaterial(materialName); 71 | ExperimentalHall_log->SetMaterial(ExperimentalHallMaterial); 72 | G4cout<<"----> Exp. Hall material set to "<GetMaterial()->GetName()<< G4endl; 73 | } 74 | -------------------------------------------------------------------------------- /include/EmStandardPhysics_option4_mod.hh: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | // 27 | // $Id$ 28 | // 29 | //--------------------------------------------------------------------------- 30 | // 31 | // ClassName: G4EmStandardPhysics_option4 32 | // 33 | // Author: V.Ivanchenko 28.09.2012 34 | // 35 | // Modified: 36 | // 37 | //---------------------------------------------------------------------------- 38 | // 39 | // This class provides construction of EM physics using the best models 40 | // of standard and low-energy packages and set of 41 | // the most adavced options allowing precise simulation at low 42 | // and intermediate energies 43 | // 44 | 45 | #ifndef EmStandardPhysics_option4_mod_h 46 | #define EmStandardPhysics_option4_mod_h 1 47 | 48 | #include "G4VPhysicsConstructor.hh" 49 | #include "globals.hh" 50 | 51 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 | 53 | class EmStandardPhysics_option4_mod : public G4VPhysicsConstructor 54 | { 55 | public: 56 | EmStandardPhysics_option4_mod(G4int ver = 1); 57 | 58 | // obsolete 59 | EmStandardPhysics_option4_mod(G4int ver, const G4String& name); 60 | 61 | virtual ~EmStandardPhysics_option4_mod(); 62 | 63 | virtual void ConstructParticle(); 64 | virtual void ConstructProcess(); 65 | 66 | private: 67 | G4int verbose; 68 | }; 69 | 70 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 71 | 72 | #endif 73 | 74 | 75 | 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /src/StepMaxMessenger.cc: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | /// \file polarisation/Pol01/src/StepMaxMessenger.cc 27 | /// \brief Implementation of the StepMaxMessenger class 28 | // 29 | // 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 | 33 | #include "StepMaxMessenger.hh" 34 | 35 | #include "StepMax.hh" 36 | #include "G4UIcmdWithADoubleAndUnit.hh" 37 | 38 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 39 | 40 | StepMaxMessenger::StepMaxMessenger(StepMax* stepMax) 41 | : G4UImessenger(), 42 | fStepMax(stepMax), fStepMaxCmd(0) 43 | { 44 | fStepMaxCmd = new G4UIcmdWithADoubleAndUnit("/testem/stepMax",this); 45 | fStepMaxCmd->SetGuidance("Set max allowed step length"); 46 | fStepMaxCmd->SetParameterName("mxStep",false); 47 | fStepMaxCmd->SetRange("mxStep>0."); 48 | fStepMaxCmd->SetUnitCategory("Length"); 49 | } 50 | 51 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 52 | 53 | StepMaxMessenger::~StepMaxMessenger() 54 | { 55 | delete fStepMaxCmd; 56 | } 57 | 58 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 59 | 60 | void StepMaxMessenger::SetNewValue(G4UIcommand* command, G4String newValue) 61 | { 62 | if (command == fStepMaxCmd) 63 | { fStepMax->SetMaxStep(fStepMaxCmd->GetNewDoubleValue(newValue));} 64 | } 65 | 66 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 67 | -------------------------------------------------------------------------------- /UCNaI.cc: -------------------------------------------------------------------------------- 1 | //PROGRAM MPP4 2 | #include "G4RunManager.hh" 3 | #include "G4UImanager.hh" 4 | 5 | #include "G4UIterminal.hh" 6 | #include "G4UItcsh.hh" 7 | 8 | #ifdef G4UI_USE_XM 9 | #include "G4UIXm.hh" 10 | #endif 11 | 12 | #include "DetectorConstruction.hh" 13 | #include "PhysicsList.hh" 14 | #include "PrimaryGeneratorAction.hh" 15 | #include "PrimaryGeneratorAction_Messenger.hh" 16 | #include "EventAction.hh" 17 | #include "EventAction_Messenger.hh" 18 | #include "TrackingAction.hh" 19 | #include "RunAction.hh" 20 | 21 | #ifdef G4VIS_USE 22 | #include "VisManager.hh" 23 | #endif 24 | 25 | #include "G4Timer.hh" 26 | G4Timer Timer; 27 | G4Timer Timerintern; 28 | 29 | int main(int argc,char** argv) 30 | { 31 | // Construct the default run manager 32 | G4RunManager* runManager = new G4RunManager; 33 | 34 | // set mandatory initialization classes 35 | DetectorConstruction* detector=new DetectorConstruction(); 36 | // PhysicsList *physicsList = new PhysicsList(detector); 37 | PhysicsList *physicsList = new PhysicsList(); 38 | runManager->SetUserInitialization(detector); 39 | runManager->SetUserInitialization(physicsList); 40 | 41 | // set mandatory user action class 42 | EventAction* eventAction = new EventAction(); 43 | new EventAction_Messenger(eventAction); 44 | runManager->SetUserAction(eventAction); 45 | PrimaryGeneratorAction* generatorAction= new PrimaryGeneratorAction(detector); 46 | new PrimaryGeneratorAction_Messenger(generatorAction); 47 | runManager->SetUserAction(generatorAction); 48 | RunAction* runAction = new RunAction(detector,eventAction); 49 | runManager->SetUserAction(runAction); 50 | 51 | TrackingAction* trackingAction = new TrackingAction(eventAction); 52 | runManager->SetUserAction(trackingAction); 53 | 54 | G4UIsession* session=0; 55 | 56 | #ifdef G4VIS_USE 57 | // visualization manager 58 | G4VisManager* visManager=0; 59 | #endif 60 | 61 | if (argc==1) // Define UI session for interactive mode. 62 | { 63 | 64 | #ifdef G4VIS_USE 65 | // visualization manager 66 | visManager = new VisManager; 67 | visManager->Initialize(); 68 | #endif 69 | 70 | // G4UIterminal is a (dumb) terminal. 71 | #ifdef G4UI_USE_TCSH 72 | session = new G4UIterminal(new G4UItcsh); 73 | #else 74 | session = new G4UIterminal(); 75 | #endif 76 | 77 | } 78 | 79 | // Initialize G4 kernel 80 | // runManager->Initialize(); 81 | // Actually, we don't, so that we can set parameters before 82 | // the detector is constructed. 83 | 84 | 85 | // get the pointer to the UI manager and set verbosities 86 | G4UImanager* UI = G4UImanager::GetUIpointer(); 87 | 88 | if (session) // Define UI session for interactive mode. 89 | { 90 | session->SessionStart(); 91 | delete session; 92 | } 93 | else // Batch mode 94 | { 95 | G4String command = "/control/execute "; 96 | G4String fileName = argv[1]; 97 | UI->ApplyCommand(command+fileName); 98 | } 99 | 100 | // job termination 101 | if(argc==1){ 102 | #ifdef G4VIS_USE 103 | delete visManager; 104 | #endif 105 | } 106 | 107 | delete runManager; 108 | 109 | return 0; 110 | } 111 | -------------------------------------------------------------------------------- /src/Target.cc: -------------------------------------------------------------------------------- 1 | #include "Target.hh" 2 | 3 | Target::Target(G4LogicalVolume* experimentalHall_log, 4 | Materials* mat) 5 | { 6 | materials=mat; 7 | expHall_log=experimentalHall_log; 8 | 9 | Al = materials->FindMaterial("Al"); 10 | 11 | Length=2.54*2*cm; 12 | Radius=2.54*0.25*cm; 13 | 14 | Pos.setX(0); 15 | Pos.setY(0); 16 | Pos.setZ(0); 17 | 18 | Rot = G4RotationMatrix::IDENTITY; 19 | Rot.rotateX(90.*deg); 20 | 21 | geoFileName = ""; 22 | } 23 | 24 | 25 | Target::~Target() 26 | { 27 | } 28 | 29 | void Target::Construct() 30 | { 31 | 32 | target = new G4Tubs("Target", 0, Radius, Length/2.0, 0, 360.*deg); 33 | 34 | target_log = new G4LogicalVolume(target, Al, "target_log", 0, 0, 0); 35 | 36 | PlaceTarget(); 37 | 38 | G4Colour dGrey (0.8, 0.8, 0.8, 1.0); 39 | G4VisAttributes* Vis = new G4VisAttributes(dGrey); 40 | Vis->SetVisibility(true); 41 | Vis->SetForceSolid(true); 42 | 43 | target_log->SetVisAttributes(Vis); 44 | 45 | return; 46 | } 47 | //--------------------------------------------------------------------- 48 | void Target::PlaceTarget() 49 | { 50 | 51 | // If there is a Target geometry file, use it for placement; 52 | // if not, use the current Pos and Rot to place a single Target. 53 | if(geoFileName != ""){ 54 | geoFile.open(geoFileName.c_str()); 55 | if (!geoFile.is_open()) 56 | G4cout<< "ERROR opening Target geometry file." << G4endl; 57 | else 58 | G4cout << "\nPositioning Targets using the geometry file: " << geoFileName << G4endl; 59 | 60 | char Label[50]; 61 | G4int targetID = 0; 62 | G4double x, y, z, ax, ay, az; 63 | while(geoFile >> x >> y >> z >> ax >> ay >> az){ 64 | sprintf(Label, "Target%d", targetID); 65 | Pos.setX(x); 66 | Pos.setY(y); 67 | Pos.setZ(z); 68 | Rot = G4RotationMatrix::IDENTITY; 69 | Rot.rotateX(ax*deg); 70 | Rot.rotateY(ay*deg); 71 | Rot.rotateZ(az*deg); 72 | 73 | new G4PVPlacement(G4Transform3D(Rot,Pos), 74 | target_log, G4String(Label), expHall_log, 75 | false, 0); 76 | targetID++; 77 | } 78 | } else { 79 | new G4PVPlacement(G4Transform3D(Rot,Pos), 80 | target_log, "Target", expHall_log, 81 | false, 0); 82 | } 83 | } 84 | //--------------------------------------------------------------------- 85 | void Target::setX(G4double x) 86 | { 87 | Pos.setX(x); 88 | } 89 | //--------------------------------------------------------------------- 90 | void Target::setY(G4double y) 91 | { 92 | Pos.setY(y); 93 | } 94 | //--------------------------------------------------------------------- 95 | void Target::setZ(G4double z) 96 | { 97 | Pos.setZ(z); 98 | } 99 | //--------------------------------------------------------------------- 100 | void Target::rotateX(G4double ax) 101 | { 102 | Rot.rotateX(ax); 103 | } 104 | //--------------------------------------------------------------------- 105 | void Target::rotateY(G4double ay) 106 | { 107 | Rot.rotateY(ay); 108 | } 109 | //--------------------------------------------------------------------- 110 | void Target::rotateZ(G4double az) 111 | { 112 | Rot.rotateZ(az); 113 | } 114 | //--------------------------------------------------------------------- 115 | -------------------------------------------------------------------------------- /src/Lead_Brick.cc: -------------------------------------------------------------------------------- 1 | #include "Lead_Brick.hh" 2 | 3 | Lead_Brick::Lead_Brick(G4LogicalVolume* experimentalHall_log, 4 | Materials* mat) 5 | { 6 | materials=mat; 7 | expHall_log=experimentalHall_log; 8 | 9 | Pb = materials->FindMaterial("Pb"); 10 | 11 | Length=2.54*6*cm; 12 | Width=2.54*4*cm; 13 | Depth=2.54*2*cm; 14 | 15 | Pos.setX(0); 16 | Pos.setY(0); 17 | Pos.setZ(0); 18 | 19 | Rot = G4RotationMatrix::IDENTITY; 20 | 21 | geoFileName = ""; 22 | } 23 | 24 | 25 | Lead_Brick::~Lead_Brick() 26 | { 27 | } 28 | 29 | void Lead_Brick::Construct() 30 | { 31 | 32 | brick = new G4Box("Brick", Width/2.0, Depth/2.0, Length/2.0); 33 | 34 | brick_log = new G4LogicalVolume(brick,Pb,"brick_log",0,0,0); 35 | 36 | PlaceBrick(); 37 | 38 | G4Colour dGrey (0.8, 0.8, 0.8, 1.0); 39 | G4VisAttributes* Vis = new G4VisAttributes(dGrey); 40 | Vis->SetVisibility(true); 41 | Vis->SetForceSolid(true); 42 | 43 | brick_log->SetVisAttributes(Vis); 44 | 45 | return; 46 | } 47 | //--------------------------------------------------------------------- 48 | void Lead_Brick::PlaceBrick() 49 | { 50 | // If there is a Target geometry file, use it for placement; 51 | // if not, use the current Pos and Rot to place a single Target. 52 | if(geoFileName != ""){ 53 | geoFile.open(geoFileName.c_str()); 54 | if (!geoFile.is_open()) 55 | G4cout<< "ERROR opening Brick geometry file." << G4endl; 56 | else 57 | G4cout << "\nPositioning Bricks using the geometry file: " << geoFileName << G4endl; 58 | 59 | char Label[50]; 60 | G4int brickID = 0; 61 | G4double x, y, z, ax, ay, az; 62 | while(geoFile >> x >> y >> z >> ax >> ay >> az){ 63 | sprintf(Label, "Brick%d", brickID); 64 | Pos.setX(x); 65 | Pos.setY(y); 66 | Pos.setZ(z); 67 | Rot = G4RotationMatrix::IDENTITY; 68 | Rot.rotateX(ax*deg); 69 | Rot.rotateY(ay*deg); 70 | Rot.rotateZ(az*deg); 71 | 72 | new G4PVPlacement(G4Transform3D(Rot,Pos), 73 | brick_log, G4String(Label), expHall_log, 74 | false,0 ); 75 | 76 | brickID++; 77 | } 78 | } else { 79 | new G4PVPlacement(G4Transform3D(Rot,Pos), 80 | brick_log,"Brick",expHall_log,false,0); 81 | } 82 | } 83 | //--------------------------------------------------------------------- 84 | void Lead_Brick::setX(G4double x) 85 | { 86 | Pos.setX(x); 87 | } 88 | //--------------------------------------------------------------------- 89 | void Lead_Brick::setY(G4double y) 90 | { 91 | Pos.setY(y); 92 | } 93 | //--------------------------------------------------------------------- 94 | void Lead_Brick::setZ(G4double z) 95 | { 96 | Pos.setZ(z); 97 | } 98 | //--------------------------------------------------------------------- 99 | void Lead_Brick::rotateX(G4double ax) 100 | { 101 | Rot.rotateX(ax); 102 | } 103 | //--------------------------------------------------------------------- 104 | void Lead_Brick::rotateY(G4double ay) 105 | { 106 | Rot.rotateY(ay); 107 | } 108 | //--------------------------------------------------------------------- 109 | void Lead_Brick::rotateZ(G4double az) 110 | { 111 | Rot.rotateZ(az); 112 | } 113 | //--------------------------------------------------------------------- 114 | -------------------------------------------------------------------------------- /src/VisManager.cc: -------------------------------------------------------------------------------- 1 | 2 | #ifdef G4VIS_USE 3 | 4 | #include "VisManager.hh" 5 | 6 | // Supported drivers... 7 | 8 | // Not needing external packages or libraries... 9 | #include "G4ASCIITree.hh" 10 | #include "G4DAWNFILE.hh" 11 | //LR #include "G4GAGTree.hh" 12 | #include "G4HepRepFile.hh" 13 | #include "G4HepRep.hh" 14 | #include "G4RayTracer.hh" 15 | #include "G4VRML1File.hh" 16 | #include "G4VRML2File.hh" 17 | 18 | // Needing external packages or libraries... 19 | 20 | // #ifdef G4VIS_USE_DAWN 21 | // #include "G4FukuiRenderer.hh" 22 | // #endif 23 | 24 | #ifdef G4VIS_USE_OPENGLX 25 | #include "G4OpenGLImmediateX.hh" 26 | #include "G4OpenGLStoredX.hh" 27 | #endif 28 | 29 | #ifdef G4VIS_USE_OPENGLWIN32 30 | #include "G4OpenGLImmediateWin32.hh" 31 | #include "G4OpenGLStoredWin32.hh" 32 | #endif 33 | 34 | #ifdef G4VIS_USE_OPENGLXM 35 | #include "G4OpenGLImmediateXm.hh" 36 | #include "G4OpenGLStoredXm.hh" 37 | #endif 38 | 39 | #ifdef G4VIS_USE_OIX 40 | #include "G4OpenInventorX.hh" 41 | #endif 42 | 43 | #ifdef G4VIS_USE_OIWIN32 44 | #include "G4OpenInventorWin32.hh" 45 | #endif 46 | 47 | // #ifdef G4VIS_USE_VRML 48 | // #include "G4VRML1.hh" 49 | // #include "G4VRML2.hh" 50 | // #endif 51 | 52 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 | 54 | VisManager::VisManager () {} 55 | 56 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 57 | 58 | void VisManager::RegisterGraphicsSystems () { 59 | 60 | // Graphics Systems not needing external packages or libraries... 61 | RegisterGraphicsSystem (new G4ASCIITree); 62 | RegisterGraphicsSystem (new G4DAWNFILE); 63 | //LR RegisterGraphicsSystem (new G4GAGTree); 64 | RegisterGraphicsSystem (new G4HepRepFile); 65 | RegisterGraphicsSystem (new G4HepRep); 66 | RegisterGraphicsSystem (new G4RayTracer); 67 | RegisterGraphicsSystem (new G4VRML1File); 68 | RegisterGraphicsSystem (new G4VRML2File); 69 | 70 | // Graphics systems needing external packages or libraries... 71 | 72 | // #ifdef G4VIS_USE_DAWN 73 | // RegisterGraphicsSystem (new G4FukuiRenderer); 74 | // #endif 75 | 76 | #ifdef G4VIS_USE_OPENGLX 77 | RegisterGraphicsSystem (new G4OpenGLImmediateX); 78 | RegisterGraphicsSystem (new G4OpenGLStoredX); 79 | #endif 80 | 81 | #ifdef G4VIS_USE_OPENGLWIN32 82 | RegisterGraphicsSystem (new G4OpenGLImmediateWin32); 83 | RegisterGraphicsSystem (new G4OpenGLStoredWin32); 84 | #endif 85 | 86 | #ifdef G4VIS_USE_OPENGLXM 87 | RegisterGraphicsSystem (new G4OpenGLImmediateXm); 88 | RegisterGraphicsSystem (new G4OpenGLStoredXm); 89 | #endif 90 | 91 | #ifdef G4VIS_USE_OIX 92 | RegisterGraphicsSystem (new G4OpenInventorX); 93 | #endif 94 | 95 | #ifdef G4VIS_USE_OIWIN32 96 | RegisterGraphicsSystem (new G4OpenInventorWin32); 97 | #endif 98 | 99 | // #ifdef G4VIS_USE_VRML 100 | // RegisterGraphicsSystem (new G4VRML1); 101 | // RegisterGraphicsSystem (new G4VRML2); 102 | // #endif 103 | 104 | if (fVerbose > 0) { 105 | G4cout << 106 | "\nYou have successfully chosen to use the following graphics systems." 107 | << G4endl; 108 | PrintAvailableGraphicsSystems (GetVerbosity()); 109 | } 110 | } 111 | 112 | #endif 113 | 114 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 115 | -------------------------------------------------------------------------------- /include/StepMax.hh: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | /// \file polarisation/Pol01/include/StepMax.hh 27 | /// \brief Definition of the StepMax class 28 | // 29 | // 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 | 33 | #ifndef StepMax_h 34 | #define StepMax_h 1 35 | 36 | #include "globals.hh" 37 | #include "G4VDiscreteProcess.hh" 38 | 39 | class StepMaxMessenger; 40 | class G4ParticleDefinition; 41 | class G4Step; 42 | 43 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 44 | 45 | class StepMax : public G4VDiscreteProcess 46 | { 47 | public: 48 | 49 | StepMax(const G4String& processName ="stepMax"); 50 | ~StepMax(); 51 | 52 | virtual G4bool IsApplicable(const G4ParticleDefinition&); 53 | void SetMaxStep(G4double); 54 | G4double GetMaxStep() {return fMaxChargedStep;}; 55 | 56 | virtual G4double PostStepGetPhysicalInteractionLength( const G4Track& track, 57 | G4double previousStepSize, 58 | G4ForceCondition* condition); 59 | 60 | virtual G4VParticleChange* PostStepDoIt(const G4Track&, const G4Step&); 61 | 62 | virtual G4double GetMeanFreePath(const G4Track&, G4double, G4ForceCondition*) 63 | {return 0.;}; // it is not needed here ! 64 | 65 | private: 66 | 67 | G4double fMaxChargedStep; 68 | StepMaxMessenger* fMessenger; 69 | }; 70 | 71 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 72 | 73 | #endif 74 | 75 | -------------------------------------------------------------------------------- /src/TrackerGammaSD.cc: -------------------------------------------------------------------------------- 1 | 2 | #include "TrackerGammaSD.hh" 3 | #include "G4HCofThisEvent.hh" 4 | #include "G4Step.hh" 5 | #include "G4ThreeVector.hh" 6 | #include "G4SDManager.hh" 7 | #include "G4ios.hh" 8 | #include "G4UnitsTable.hh" 9 | #include "G4VTouchable.hh" 10 | #include 11 | #include 12 | 13 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 14 | 15 | TrackerGammaSD::TrackerGammaSD(G4String name) 16 | :G4VSensitiveDetector(name) 17 | { 18 | G4String HCname; 19 | collectionName.insert(HCname="gammaCollection"); 20 | print=false; //LR (formerly not initialized) 21 | 22 | } 23 | 24 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 25 | 26 | TrackerGammaSD::~TrackerGammaSD(){ } 27 | 28 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 29 | 30 | void TrackerGammaSD::Initialize(G4HCofThisEvent*) 31 | { 32 | 33 | 34 | gammaCollection = new TrackerGammaHitsCollection 35 | (SensitiveDetectorName,collectionName[0]); 36 | 37 | } 38 | 39 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 40 | 41 | G4bool TrackerGammaSD::ProcessHits(G4Step* aStep,G4TouchableHistory*) 42 | { 43 | 44 | G4double DE = aStep->GetTotalEnergyDeposit(); 45 | if(DE<0.001*eV) return false; 46 | 47 | G4double edep = aStep->GetTotalEnergyDeposit(); 48 | G4double etotal = aStep->GetPreStepPoint()->GetTotalEnergy(); 49 | G4String name 50 | = aStep->GetPostStepPoint()->GetTouchable()->GetVolume()->GetName(); 51 | G4int detID 52 | = aStep->GetPostStepPoint()->GetTouchable()->GetReplicaNumber(0)-1000; 53 | 54 | if(name.contains("detector")) 55 | { 56 | 57 | TrackerGammaHit* newHit = new TrackerGammaHit(); 58 | 59 | newHit->SetTrackID (aStep->GetTrack()->GetTrackID()); 60 | 61 | newHit->SetParticleID(aStep->GetTrack()->GetDefinition()->GetParticleName()); 62 | newHit->SetDetID (detID); // Coming real soon now. 63 | newHit->SetEdep (edep); 64 | newHit->SetTotalEnergy(etotal); 65 | newHit->SetPos (aStep->GetPostStepPoint()->GetPosition()); 66 | 67 | gammaCollection->insert( newHit ); 68 | newHit->Draw(); 69 | 70 | // newHit->Print(); 71 | 72 | return true; 73 | } 74 | else 75 | { 76 | //G4cout << "Energy deposit in the " << name << G4endl; 77 | //G4cout << "E="<entries(); 91 | 92 | if (NbHits>0&&print) 93 | { 94 | 95 | G4cout << "\n--------> " << NbHits << " hits for gamma tracking: " << G4endl; 96 | 97 | for (i=0;iPrint(); 98 | 99 | } 100 | 101 | 102 | static G4int HCID = -1; 103 | if(HCID<0) 104 | { HCID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); } 105 | HCE->AddHitsCollection( HCID, gammaCollection ); 106 | } 107 | 108 | 109 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 110 | 111 | -------------------------------------------------------------------------------- /include/PhysicsList.hh: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | /// \file electromagnetic/TestEm7/include/PhysicsList.hh 27 | /// \brief Definition of the PhysicsList class 28 | // 29 | // 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | // 32 | // 14.10.02 (V.Ivanchenko) provide modular list on base of old PhysicsList 33 | // 34 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 35 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 36 | 37 | #ifndef PhysicsList_h 38 | #define PhysicsList_h 1 39 | 40 | #include "G4VModularPhysicsList.hh" 41 | #include "globals.hh" 42 | 43 | class G4VPhysicsConstructor; 44 | class StepMax; 45 | class PhysicsListMessenger; 46 | 47 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 48 | 49 | class PhysicsList: public G4VModularPhysicsList 50 | { 51 | public: 52 | 53 | PhysicsList(); 54 | ~PhysicsList(); 55 | 56 | virtual void ConstructParticle(); 57 | 58 | void AddPhysicsList(const G4String& name); 59 | virtual void ConstructProcess(); 60 | 61 | void SetUsePolarizedPhysics(bool); 62 | 63 | void AddRadioactiveDecay(); 64 | 65 | void AddStepMax(); 66 | StepMax* GetStepMaxProcess() {return fStepMaxProcess;}; 67 | 68 | private: 69 | 70 | void AddIonGasModels(); 71 | 72 | G4bool fHelIsRegisted; 73 | G4bool fBicIsRegisted; 74 | G4bool fBiciIsRegisted; 75 | 76 | G4bool usePolar; 77 | 78 | G4String fEmName; 79 | G4VPhysicsConstructor* fEmPhysicsList; 80 | G4VPhysicsConstructor* fDecPhysicsList; 81 | std::vector fHadronPhys; 82 | StepMax* fStepMaxProcess; 83 | 84 | PhysicsListMessenger* fMessenger; 85 | }; 86 | 87 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 88 | 89 | #endif 90 | 91 | -------------------------------------------------------------------------------- /src/RunAction.cc: -------------------------------------------------------------------------------- 1 | #include "RunAction.hh" 2 | 3 | #include "G4Timer.hh" 4 | extern G4Timer Timer; 5 | 6 | RunAction::RunAction(DetectorConstruction* detector, EventAction* ev): myDetector(detector), evaction(ev) 7 | { 8 | 9 | } 10 | 11 | 12 | RunAction::~RunAction() 13 | { 14 | 15 | } 16 | 17 | void RunAction::BeginOfRunAction(const G4Run* run) 18 | { 19 | 20 | G4cout<<" Begining of run "<SetNTotalevents(run->GetNumberOfEventToBeProcessed()); 23 | if(run->GetNumberOfEventToBeProcessed() > 1000000) 24 | evaction->SetEveryNEvents(10000); 25 | else if(run->GetNumberOfEventToBeProcessed() > 1000) 26 | evaction->SetEveryNEvents(1000); 27 | else if(run->GetNumberOfEventToBeProcessed() > 100) 28 | evaction->SetEveryNEvents(100); 29 | else 30 | evaction->SetEveryNEvents(1); 31 | 32 | G4cout << " Simulating " << run->GetNumberOfEventToBeProcessed() 33 | << " events." << G4endl; 34 | 35 | evaction->openEvfile(); 36 | 37 | Timer.Start(); 38 | 39 | } 40 | 41 | 42 | 43 | void RunAction::EndOfRunAction(const G4Run*) 44 | { 45 | evaction->closeEvfile(); 46 | 47 | Timer.Stop(); 48 | 49 | G4cout << " " << G4endl; 50 | 51 | G4double time, hours, minutes, seconds; 52 | 53 | G4cout << "Real time: "; 54 | time = Timer.GetRealElapsed(); 55 | hours = floor(time/3600.0); 56 | if(hours>0){ 57 | G4cout << std::setprecision(0) << std::setw(2) 58 | << hours << ":"; 59 | G4cout << std::setfill('0'); 60 | } else { 61 | G4cout << std::setfill(' '); 62 | } 63 | minutes = floor(fmod(time,3600.0)/60.0); 64 | if(minutes>0){ 65 | G4cout << std::setprecision(0) << std::setw(2) << minutes << ":"; 66 | G4cout << std::setfill('0'); 67 | } else { 68 | G4cout << std::setfill(' '); 69 | } 70 | seconds = fmod(time,60.0); 71 | if(seconds>0) 72 | G4cout << std::setprecision(2) << std::setw(5) << seconds; 73 | G4cout << std::setfill(' '); 74 | 75 | G4cout << " System time: "; 76 | time = Timer.GetSystemElapsed(); 77 | hours = floor(time/3600.0); 78 | if(hours>0){ 79 | G4cout << std::setprecision(0) << std::setw(2) 80 | << hours << ":"; 81 | G4cout << std::setfill('0'); 82 | } else { 83 | G4cout << std::setfill(' '); 84 | } 85 | minutes = floor(fmod(time,3600.0)/60.0); 86 | if(minutes>0){ 87 | G4cout << std::setprecision(0) << std::setw(2) << minutes << ":"; 88 | G4cout << std::setfill('0'); 89 | } else { 90 | G4cout << std::setfill(' '); 91 | } 92 | seconds = fmod(time,60.0); 93 | if(seconds>0) 94 | G4cout << std::setprecision(2) << std::setw(5) << seconds; 95 | G4cout << std::setfill(' '); 96 | 97 | G4cout << " User time: "; 98 | time = Timer.GetUserElapsed(); 99 | hours = floor(time/3600.0); 100 | if(hours>0){ 101 | G4cout << std::setprecision(0) << std::setw(2) 102 | << hours << ":"; 103 | G4cout << std::setfill('0'); 104 | } else { 105 | G4cout << std::setfill(' '); 106 | } 107 | minutes = floor(fmod(time,3600.0)/60.0); 108 | if(minutes>0){ 109 | G4cout << std::setprecision(0) << std::setw(2) << minutes << ":"; 110 | G4cout << std::setfill('0'); 111 | } else { 112 | G4cout << std::setfill(' '); 113 | } 114 | seconds = fmod(time,60.0); 115 | if(seconds>0) 116 | G4cout << std::setprecision(2) << std::setw(5) << seconds; 117 | G4cout << std::setfill(' '); 118 | 119 | G4cout << " " 120 | << evaction->GetNTotalevents()/Timer.GetRealElapsed() 121 | << " events/s" << G4endl; 122 | } 123 | 124 | -------------------------------------------------------------------------------- /src/Materials.cc: -------------------------------------------------------------------------------- 1 | #include "Materials.hh" 2 | 3 | Materials:: Materials() 4 | { 5 | // Elements 6 | 7 | elementH = new G4Element("Hydrogen", "H", 1., 1.0079*g/mole); 8 | elementC = new G4Element("Carbon", "C", 6., 12.011*g/mole); 9 | elementN = new G4Element("Nitrogen", "N", 7., 14.007*g/mole); 10 | elementO = new G4Element("Oxygen", "O", 8., 15.9994*g/mole); 11 | elementMg = new G4Element("Magnesium", "Mg",12., 24.3050*g/mole); 12 | elementAl = new G4Element("Aluminium", "Al",13., 26.9815*g/mole); 13 | elementSi = new G4Element("Silicon", "Si",14., 28.0855*g/mole); 14 | elementTi = new G4Element("Titanium", "Ti",22., 47.90*g/mole); 15 | elementV = new G4Element("Vanadium", "V", 23., 50.9415*g/mole); 16 | elementFe = new G4Element("Iron", "Fe",26., 55.845*g/mole); 17 | elementCo = new G4Element("Cobalt", "Co",27., 58.9332*g/mole); 18 | elementCu = new G4Element("Copper", "Cu",29., 63.55*g/mole); 19 | elementMo = new G4Element("Molybdenum","Mo",42., 95.94*g/mole); 20 | elementPt = new G4Element("Platinum", "Pt",78., 195.08*g/mole); 21 | elementAu = new G4Element("Gold", "Au",79., 196.97*g/mole); 22 | elementPb = new G4Element("Lead", "Pb",82., 207.2*g/mole); 23 | 24 | // Materials 25 | 26 | // vacuum = new G4Material("vacuum", 1, 1.00794*g/mole, 27 | // 1.0E-25*g/cm3, kStateGas, 0.1*kelvin, 1.0E-19*pascal); 28 | 29 | HpGe = new G4Material("HpGe", 32., 72.61*g/mole, 5.323*g/cm3); 30 | // pmtMat = new G4Material("pmtMat", 13., 26.982*g/mole, 1.35*g/cm3); //LR (Air, copper, and aluminum?) 31 | pmtMat = new G4Material("pmtMat", 26., 26.982*g/mole, 1.35*g/cm3); //LR (Air, copper, and aluminum?) 32 | 33 | LH = new G4Material("LH", 2., 2.0159*g/mole, 70.99*mg/cm3); 34 | 35 | G10 = new G4Material("G10", 1.70*g/cm3, 4); 36 | G10->AddElement(elementSi, 1); 37 | G10->AddElement(elementO, 2); 38 | G10->AddElement(elementC, 3); 39 | G10->AddElement(elementH, 3); 40 | 41 | ssteel = new G4Material("ssteel", 7.7*g/cm3, 3); 42 | ssteel->AddElement(elementC, 0.04); 43 | ssteel->AddElement(elementFe, 0.88); 44 | ssteel->AddElement(elementCo, 0.08); 45 | 46 | // define materials from the G4 NIST database 47 | NISTman = G4NistManager::Instance(); 48 | 49 | CsI = NISTman->FindOrBuildMaterial("G4_CESIUM_IODIDE"); 50 | NaI = NISTman->FindOrBuildMaterial("G4_SODIUM_IODIDE"); 51 | MgO = NISTman->FindOrBuildMaterial("G4_MAGNESIUM_OXIDE"); 52 | vacuum = NISTman->FindOrBuildMaterial("G4_Galactic"); 53 | polyethylene = NISTman->FindOrBuildMaterial("G4_POLYETHYLENE"); 54 | polypropylene = NISTman->FindOrBuildMaterial("G4_POLYPROPYLENE"); 55 | 56 | Be = new G4Material("Be", 4., 9.012182*g/mole, 1.84*g/cm3); 57 | C = new G4Material("C", 6., 12.011*g/mole, 2.15*g/cm3); 58 | Al = new G4Material("Al", 13., 26.98153*g/mole, 2.70*g/cm3); 59 | Si = new G4Material("Si", 14., 28.0855*g/mole, 2.33*g/cm3); 60 | Cu = new G4Material("Cu", 29., 63.55*g/mole, 8.96*g/cm3); 61 | Nb = new G4Material("Nb", 41., 92.90638*g/mole, 8.57*g/cm3); 62 | Au = new G4Material("Au", 79., 196.9*g/mole, 19.32*g/cm3); 63 | Ir = new G4Material("Ir", 77., 192.217*g/mole, 22.65*g/cm3); 64 | Pb = new G4Material("Pb", 82., 207.2*g/mole, 11.34*g/cm3); 65 | 66 | } 67 | 68 | Materials::~ Materials() 69 | {;} 70 | //----------------------------------------------------------------------------- 71 | G4Material* Materials::FindMaterial(G4String materialName) 72 | { 73 | 74 | // search the material by its name 75 | G4Material* pttoMaterial = G4Material::GetMaterial(materialName); 76 | 77 | return pttoMaterial; 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/NaI_Detector_Messenger.cc: -------------------------------------------------------------------------------- 1 | #include "NaI_Detector_Messenger.hh" 2 | 3 | NaI_Detector_Messenger::NaI_Detector_Messenger(NaI_Detector* SD) 4 | :NaIDet(SD) 5 | { 6 | 7 | NaIDir = new G4UIdirectory("/NaI/"); 8 | NaIDir->SetGuidance("NaI control."); 9 | 10 | XCmd = new G4UIcmdWithADoubleAndUnit("/NaI/setX",this); 11 | XCmd->SetGuidance("Set the x position of the detector (crystal center)"); 12 | XCmd->SetParameterName("choice",false); 13 | XCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 14 | 15 | YCmd = new G4UIcmdWithADoubleAndUnit("/NaI/setY",this); 16 | YCmd->SetGuidance("Set the y position of the detector (crystal center)"); 17 | YCmd->SetParameterName("choice",false); 18 | YCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 19 | 20 | ZCmd = new G4UIcmdWithADoubleAndUnit("/NaI/setZ",this); 21 | ZCmd->SetGuidance("Set the z position of the detector (crystal center)"); 22 | ZCmd->SetParameterName("choice",false); 23 | ZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 24 | 25 | RCmd = new G4UIcmdWithADoubleAndUnit("/NaI/setR",this); 26 | RCmd->SetGuidance("Set the radius of the NaI crystal"); 27 | RCmd->SetParameterName("choice",false); 28 | RCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 29 | 30 | LCmd = new G4UIcmdWithADoubleAndUnit("/NaI/setL",this); 31 | LCmd->SetGuidance("Set the length of the NaI crystal"); 32 | LCmd->SetParameterName("choice",false); 33 | LCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 34 | 35 | rXCmd = new G4UIcmdWithADoubleAndUnit("/NaI/rotateX",this); 36 | rXCmd->SetGuidance("Rotate the detector about the x axis"); 37 | rXCmd->SetParameterName("choice",false); 38 | rXCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 39 | 40 | rYCmd = new G4UIcmdWithADoubleAndUnit("/NaI/rotateY",this); 41 | rYCmd->SetGuidance("Rotate the detector about the y axis"); 42 | rYCmd->SetParameterName("choice",false); 43 | rYCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 44 | 45 | rZCmd = new G4UIcmdWithADoubleAndUnit("/NaI/rotateZ",this); 46 | rZCmd->SetGuidance("Rotate the detector about the z axis"); 47 | rZCmd->SetParameterName("choice",false); 48 | rZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 49 | 50 | GCmd = new G4UIcmdWithAString("/NaI/GeometryFile",this); 51 | GCmd->SetGuidance("Set the geometry file name."); 52 | GCmd->SetParameterName("choice",false); 53 | GCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 54 | 55 | } 56 | 57 | 58 | 59 | NaI_Detector_Messenger::~NaI_Detector_Messenger() 60 | { 61 | delete NaIDir; 62 | delete XCmd; 63 | delete YCmd; 64 | delete ZCmd; 65 | delete RCmd; 66 | delete LCmd; 67 | delete rXCmd; 68 | delete rYCmd; 69 | delete rZCmd; 70 | delete GCmd; 71 | } 72 | 73 | 74 | void NaI_Detector_Messenger::SetNewValue(G4UIcommand* command,G4String newValue) 75 | { 76 | if( command == XCmd ) 77 | {NaIDet->setX(XCmd->GetNewDoubleValue(newValue));} 78 | if( command == YCmd ) 79 | {NaIDet->setY(YCmd->GetNewDoubleValue(newValue));} 80 | if( command == ZCmd ) 81 | {NaIDet->setZ(ZCmd->GetNewDoubleValue(newValue));} 82 | if( command == RCmd ) 83 | {NaIDet->setR(RCmd->GetNewDoubleValue(newValue));} 84 | if( command == LCmd ) 85 | {NaIDet->setL(LCmd->GetNewDoubleValue(newValue));} 86 | if( command == ZCmd ) 87 | {NaIDet->setZ(ZCmd->GetNewDoubleValue(newValue));} 88 | if( command == rXCmd ) 89 | {NaIDet->rotateX(rXCmd->GetNewDoubleValue(newValue));} 90 | if( command == rYCmd ) 91 | {NaIDet->rotateY(rYCmd->GetNewDoubleValue(newValue));} 92 | if( command == rZCmd ) 93 | {NaIDet->rotateZ(rZCmd->GetNewDoubleValue(newValue));} 94 | if( command == GCmd ) 95 | {NaIDet->setGeoFile(newValue);} 96 | } 97 | -------------------------------------------------------------------------------- /src/PhysicsListMessenger.cc: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | /// \file electromagnetic/TestEm7/src/PhysicsListMessenger.cc 27 | /// \brief Implementation of the PhysicsListMessenger class 28 | // 29 | // 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 | 33 | #include "PhysicsListMessenger.hh" 34 | 35 | #include "PhysicsList.hh" 36 | #include "G4UIdirectory.hh" 37 | #include "G4UIcmdWithADoubleAndUnit.hh" 38 | #include "G4UIcmdWithAString.hh" 39 | #include "G4UIcmdWithABool.hh" 40 | 41 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 42 | 43 | PhysicsListMessenger::PhysicsListMessenger(PhysicsList* phys) 44 | : G4UImessenger(),fPhysicsList(phys) 45 | { 46 | fPhysDir = new G4UIdirectory("/PhysicsList/"); 47 | fPhysDir->SetGuidance("physics list commands"); 48 | 49 | fListCmd = new G4UIcmdWithAString("/PhysicsList/addPhysics",this); 50 | fListCmd->SetGuidance("Add modula physics list."); 51 | fListCmd->SetParameterName("PList",false); 52 | fListCmd->AvailableForStates(G4State_PreInit); 53 | 54 | PolCmd = new G4UIcmdWithABool("/PhysicsList/SetGammaPolarization",this); 55 | PolCmd->SetGuidance("Enable/disable polarized gamma-ray physics"); 56 | PolCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 57 | 58 | } 59 | 60 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 61 | 62 | PhysicsListMessenger::~PhysicsListMessenger() 63 | { 64 | delete fListCmd; 65 | delete fPhysDir; 66 | delete PolCmd; 67 | } 68 | 69 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 70 | 71 | void PhysicsListMessenger::SetNewValue(G4UIcommand* command, 72 | G4String newValue) 73 | { 74 | if( command == fListCmd ) 75 | { fPhysicsList->AddPhysicsList(newValue);} 76 | if( command == PolCmd) 77 | { fPhysicsList->SetUsePolarizedPhysics(PolCmd->GetNewBoolValue(newValue));} 78 | } 79 | 80 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 81 | -------------------------------------------------------------------------------- /src/PrimaryGeneratorAction.cc: -------------------------------------------------------------------------------- 1 | #include "PrimaryGeneratorAction.hh" 2 | 3 | PrimaryGeneratorAction::PrimaryGeneratorAction(DetectorConstruction *detector): myDetector(detector) 4 | { 5 | sourcePosition.setX(0); 6 | sourcePosition.setY(2.54*.1875/2.*cm); // Half capsule depth 7 | sourcePosition.setZ(0); 8 | simpleSourceEnergy = 0; 9 | muonSourceEnergy = 0; 10 | sourceType = "decay"; 11 | n_particle = 1; 12 | particleGun = new G4ParticleGun(n_particle); 13 | } 14 | 15 | PrimaryGeneratorAction::~PrimaryGeneratorAction() 16 | { 17 | delete particleGun; 18 | } 19 | 20 | void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent) 21 | { 22 | 23 | particleTable = G4ParticleTable::GetParticleTable(); 24 | 25 | // G4cout<<" +++++ In Generate Primaries "<SetParticleDefinition(particleTable->FindParticle("gamma")); 30 | 31 | particleGun->SetParticleMomentumDirection(G4RandomDirection()); 32 | particleGun->SetParticlePosition(sourcePosition); 33 | particleGun->SetParticleEnergy(simpleSourceEnergy); 34 | } else if (sourceType == "muon") { 35 | if(G4UniformRand()<0.5) 36 | particleGun->SetParticleDefinition(particleTable->FindParticle("mu+")); 37 | else 38 | particleGun->SetParticleDefinition(particleTable->FindParticle("mu-")); 39 | particleGun->SetParticleMomentumDirection(G4RandomDirection()); 40 | particleGun->SetParticlePosition(sourcePosition); 41 | particleGun->SetParticleEnergy(muonSourceEnergy); 42 | } else { 43 | particleGun->SetParticleEnergy(0*eV); 44 | particleGun->SetParticlePosition(sourcePosition); 45 | particleGun->SetParticleMomentumDirection(G4ThreeVector(1.,0.,0.)); 46 | } 47 | // G4cout<<" +++++ Generating an event "<GeneratePrimaryVertex(anEvent); 49 | // G4cout<<" +++++ Out Generate Primaries "< Simple gamma-ray source, energy = "< Muon source, energy = "< Source position in X is set to "< Source position in Y is set to "< Source position in Z is set to "<getSourceCapsule()->setX(x); 79 | } 80 | //------------------------------------------------------------------------- 81 | void PrimaryGeneratorAction::SetSourceY(G4double y) 82 | { 83 | sourcePosition.setY(y); 84 | myDetector->getSourceCapsule()->setY(y); 85 | } 86 | //------------------------------------------------------------------------- 87 | void PrimaryGeneratorAction::SetSourceZ(G4double z) 88 | { 89 | sourcePosition.setZ(z); 90 | myDetector->getSourceCapsule()->setZ(z); 91 | } 92 | //------------------------------------------------------------------------- 93 | -------------------------------------------------------------------------------- /examples/cs137/NaISort.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | import sys 4 | 5 | # The detector resolution is simulated as the sum of two Gaussians 6 | sigmaPar = 0.75 # First energy resolution parameter 7 | 8 | # Linear energy calibration 9 | a = 0 # Energy calibration offset (keV) 10 | b = 1 # Energy calibration slope (keV/bin) 11 | 12 | # Histogram specifications 13 | eMax = 2048 14 | nBins = 2048 15 | 16 | def readInputFile(fileName = "NaISort.inp"): 17 | 18 | try: 19 | inFile = open(fileName, 'r') 20 | except IOError: 21 | return 22 | 23 | line = inFile.readline() 24 | words = line.split() 25 | nDet = int(words[0]) 26 | 27 | line = inFile.readline() 28 | words = line.split() 29 | sigmaPar = float(words[0]) 30 | 31 | line = inFile.readline() 32 | words = line.split() 33 | a = float(words[0]) 34 | 35 | line = inFile.readline() 36 | words = line.split() 37 | b = float(words[0]) 38 | 39 | line = inFile.readline() 40 | words = line.split() 41 | eMax = float(words[0]) 42 | 43 | line = inFile.readline() 44 | words = line.split() 45 | nBins = int(words[0]) 46 | 47 | inFile.close() 48 | 49 | return nDet, sigmaPar, a, b, eMax, nBins 50 | 51 | def Sort(fileName, nDet=1): 52 | 53 | try: 54 | inFile = open(fileName, 'r') 55 | except IOError: 56 | print('Error: unable to open file {0}'.format(fileName)) 57 | return 58 | 59 | # List of energies at bin centers. 60 | energies = [] 61 | width = float(eMax/nBins) 62 | for bin in range(nBins): 63 | energies.append((bin+0.5)*width) 64 | 65 | # Sort the output file. 66 | counts = np.zeros((nDet, nBins)) 67 | photopeakCounts = 0 68 | for line in inFile.readlines(): 69 | words = line.split() 70 | det = int(words[1])-1 71 | eSim = float(words[2]) 72 | 73 | if int(words[6]) == 1: 74 | photopeakCounts += 1 75 | 76 | # Fold in simulated resolution. 77 | sigma = sigmaPar*np.sqrt(eSim) 78 | eRes = eSim + np.random.normal(scale=sigma) 79 | 80 | # De-calibrate to match measured histogram 81 | eRes = (eRes - a)/b 82 | 83 | bin = int(eRes/eMax*nBins) 84 | if bin >= 0 and bin < nBins: 85 | counts[det][bin] += 1 86 | 87 | print('{0:d} photopeak counts'.format(photopeakCounts)) 88 | 89 | return energies, counts 90 | 91 | def writeMCA(counts, det=-1): 92 | fileName = sys.argv[1] 93 | 94 | if det >= 0: 95 | label = '_{0}'.format(det) 96 | else: 97 | label = '' 98 | outFileName = fileName.replace('.out', label+'.mca') 99 | 100 | try: 101 | outFile = open(outFileName, 'w') 102 | except IOError: 103 | print('Error: unable to open output file {0}'.format(fileName)) 104 | return 105 | 106 | header = ''' 107 | <> 108 | TAG - 109 | DESCRIPTION - UCNaI simulation 110 | GAIN - 0 111 | THRESHOLD - 0 112 | LIVE_MODE - 0 113 | PRESET_TIME - 0 114 | LIVE_TIME - 0 115 | REAL_TIME - 0 116 | START_TIME - 0 117 | SERIAL_NUMBER - 0 118 | <> 119 | ''' 120 | outFile.write(header) 121 | for count in counts: 122 | outFile.write(str(int(count))+'\n') 123 | 124 | outFile.write('<<>>') 125 | 126 | return 127 | 128 | nDet, sigmaPar, a, b, eMax, nBins = readInputFile() 129 | 130 | energies, counts = Sort(sys.argv[1], nDet) 131 | 132 | for i in range(nDet): 133 | if nDet > 1: 134 | det = i+1 135 | else: 136 | det = -1 137 | writeMCA(counts[i], det) 138 | 139 | #plt.step(energies, counts, where='mid') 140 | #plt.show() 141 | -------------------------------------------------------------------------------- /examples/na22/NaISort.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | import sys 4 | 5 | # The detector resolution is simulated as the sum of two Gaussians 6 | sigmaPar = 0.75 # First energy resolution parameter 7 | 8 | # Linear energy calibration 9 | a = 0 # Energy calibration offset (keV) 10 | b = 1 # Energy calibration slope (keV/bin) 11 | 12 | # Histogram specifications 13 | eMax = 2048 14 | nBins = 2048 15 | 16 | def readInputFile(fileName = "NaISort.inp"): 17 | 18 | try: 19 | inFile = open(fileName, 'r') 20 | except IOError: 21 | return 22 | 23 | line = inFile.readline() 24 | words = line.split() 25 | nDet = int(words[0]) 26 | 27 | line = inFile.readline() 28 | words = line.split() 29 | sigmaPar = float(words[0]) 30 | 31 | line = inFile.readline() 32 | words = line.split() 33 | a = float(words[0]) 34 | 35 | line = inFile.readline() 36 | words = line.split() 37 | b = float(words[0]) 38 | 39 | line = inFile.readline() 40 | words = line.split() 41 | eMax = float(words[0]) 42 | 43 | line = inFile.readline() 44 | words = line.split() 45 | nBins = int(words[0]) 46 | 47 | inFile.close() 48 | 49 | return nDet, sigmaPar, a, b, eMax, nBins 50 | 51 | def Sort(fileName, nDet=1): 52 | 53 | try: 54 | inFile = open(fileName, 'r') 55 | except IOError: 56 | print('Error: unable to open file {0}'.format(fileName)) 57 | return 58 | 59 | # List of energies at bin centers. 60 | energies = [] 61 | width = float(eMax/nBins) 62 | for bin in range(nBins): 63 | energies.append((bin+0.5)*width) 64 | 65 | # Sort the output file. 66 | counts = np.zeros((nDet, nBins)) 67 | photopeakCounts = 0 68 | for line in inFile.readlines(): 69 | words = line.split() 70 | det = int(words[1])-1 71 | eSim = float(words[2]) 72 | 73 | if int(words[6]) == 1: 74 | photopeakCounts += 1 75 | 76 | # Fold in simulated resolution. 77 | sigma = sigmaPar*np.sqrt(eSim) 78 | eRes = eSim + np.random.normal(scale=sigma) 79 | 80 | # De-calibrate to match measured histogram 81 | eRes = (eRes - a)/b 82 | 83 | bin = int(eRes/eMax*nBins) 84 | if bin >= 0 and bin < nBins: 85 | counts[det][bin] += 1 86 | 87 | print('{0:d} photopeak counts'.format(photopeakCounts)) 88 | 89 | return energies, counts 90 | 91 | def writeMCA(counts, det=-1): 92 | fileName = sys.argv[1] 93 | 94 | if det >= 0: 95 | label = '_{0}'.format(det) 96 | else: 97 | label = '' 98 | outFileName = fileName.replace('.out', label+'.mca') 99 | 100 | try: 101 | outFile = open(outFileName, 'w') 102 | except IOError: 103 | print('Error: unable to open output file {0}'.format(fileName)) 104 | return 105 | 106 | header = ''' 107 | <> 108 | TAG - 109 | DESCRIPTION - UCNaI simulation 110 | GAIN - 0 111 | THRESHOLD - 0 112 | LIVE_MODE - 0 113 | PRESET_TIME - 0 114 | LIVE_TIME - 0 115 | REAL_TIME - 0 116 | START_TIME - 0 117 | SERIAL_NUMBER - 0 118 | <> 119 | ''' 120 | outFile.write(header) 121 | for count in counts: 122 | outFile.write(str(int(count))+'\n') 123 | 124 | outFile.write('<<>>') 125 | 126 | return 127 | 128 | nDet, sigmaPar, a, b, eMax, nBins = readInputFile() 129 | 130 | energies, counts = Sort(sys.argv[1], nDet) 131 | 132 | for i in range(nDet): 133 | if nDet > 1: 134 | det = i+1 135 | else: 136 | det = -1 137 | writeMCA(counts[i], det) 138 | 139 | #plt.step(energies, counts, where='mid') 140 | #plt.show() 141 | -------------------------------------------------------------------------------- /examples/simple/NaISort.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | import sys 4 | 5 | # The detector resolution is simulated as the sum of two Gaussians 6 | sigmaPar = 0.75 # First energy resolution parameter 7 | 8 | # Linear energy calibration 9 | a = 0 # Energy calibration offset (keV) 10 | b = 1 # Energy calibration slope (keV/bin) 11 | 12 | # Histogram specifications 13 | eMax = 2048 14 | nBins = 2048 15 | 16 | def readInputFile(fileName = "NaISort.inp"): 17 | 18 | try: 19 | inFile = open(fileName, 'r') 20 | except IOError: 21 | return 22 | 23 | line = inFile.readline() 24 | words = line.split() 25 | nDet = int(words[0]) 26 | 27 | line = inFile.readline() 28 | words = line.split() 29 | sigmaPar = float(words[0]) 30 | 31 | line = inFile.readline() 32 | words = line.split() 33 | a = float(words[0]) 34 | 35 | line = inFile.readline() 36 | words = line.split() 37 | b = float(words[0]) 38 | 39 | line = inFile.readline() 40 | words = line.split() 41 | eMax = float(words[0]) 42 | 43 | line = inFile.readline() 44 | words = line.split() 45 | nBins = int(words[0]) 46 | 47 | inFile.close() 48 | 49 | return nDet, sigmaPar, a, b, eMax, nBins 50 | 51 | def Sort(fileName, nDet=1): 52 | 53 | try: 54 | inFile = open(fileName, 'r') 55 | except IOError: 56 | print('Error: unable to open file {0}'.format(fileName)) 57 | return 58 | 59 | # List of energies at bin centers. 60 | energies = [] 61 | width = float(eMax/nBins) 62 | for bin in range(nBins): 63 | energies.append((bin+0.5)*width) 64 | 65 | # Sort the output file. 66 | counts = np.zeros((nDet, nBins)) 67 | photopeakCounts = 0 68 | for line in inFile.readlines(): 69 | words = line.split() 70 | det = int(words[1])-1 71 | eSim = float(words[2]) 72 | 73 | if int(words[6]) == 1: 74 | photopeakCounts += 1 75 | 76 | # Fold in simulated resolution. 77 | sigma = sigmaPar*np.sqrt(eSim) 78 | eRes = eSim + np.random.normal(scale=sigma) 79 | 80 | # De-calibrate to match measured histogram 81 | eRes = (eRes - a)/b 82 | 83 | bin = int(eRes/eMax*nBins) 84 | if bin >= 0 and bin < nBins: 85 | counts[det][bin] += 1 86 | 87 | print('{0:d} photopeak counts'.format(photopeakCounts)) 88 | 89 | return energies, counts 90 | 91 | def writeMCA(counts, det=-1): 92 | fileName = sys.argv[1] 93 | 94 | if det >= 0: 95 | label = '_{0}'.format(det) 96 | else: 97 | label = '' 98 | outFileName = fileName.replace('.out', label+'.mca') 99 | 100 | try: 101 | outFile = open(outFileName, 'w') 102 | except IOError: 103 | print('Error: unable to open output file {0}'.format(fileName)) 104 | return 105 | 106 | header = ''' 107 | <> 108 | TAG - 109 | DESCRIPTION - UCNaI simulation 110 | GAIN - 0 111 | THRESHOLD - 0 112 | LIVE_MODE - 0 113 | PRESET_TIME - 0 114 | LIVE_TIME - 0 115 | REAL_TIME - 0 116 | START_TIME - 0 117 | SERIAL_NUMBER - 0 118 | <> 119 | ''' 120 | outFile.write(header) 121 | for count in counts: 122 | outFile.write(str(int(count))+'\n') 123 | 124 | outFile.write('<<>>') 125 | 126 | return 127 | 128 | nDet, sigmaPar, a, b, eMax, nBins = readInputFile() 129 | 130 | energies, counts = Sort(sys.argv[1], nDet) 131 | 132 | for i in range(nDet): 133 | if nDet > 1: 134 | det = i+1 135 | else: 136 | det = -1 137 | writeMCA(counts[i], det) 138 | 139 | #plt.step(energies, counts, where='mid') 140 | #plt.show() 141 | -------------------------------------------------------------------------------- /src/Target_Messenger.cc: -------------------------------------------------------------------------------- 1 | #include "Target_Messenger.hh" 2 | 3 | Target_Messenger::Target_Messenger(Target* tg) 4 | :target(tg) 5 | { 6 | 7 | TargetDir = new G4UIdirectory("/Target/"); 8 | TargetDir->SetGuidance("Target control."); 9 | 10 | XCmd = new G4UIcmdWithADoubleAndUnit("/Target/setX",this); 11 | XCmd->SetGuidance("Set the x position of the brick center"); 12 | XCmd->SetParameterName("choice",false); 13 | XCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 14 | 15 | YCmd = new G4UIcmdWithADoubleAndUnit("/Target/setY",this); 16 | YCmd->SetGuidance("Set the y position of the brick center"); 17 | YCmd->SetParameterName("choice",false); 18 | YCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 19 | 20 | ZCmd = new G4UIcmdWithADoubleAndUnit("/Target/setZ",this); 21 | ZCmd->SetGuidance("Set the z position of the brick center"); 22 | ZCmd->SetParameterName("choice",false); 23 | ZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 24 | 25 | rXCmd = new G4UIcmdWithADoubleAndUnit("/Target/rotateX",this); 26 | rXCmd->SetGuidance("Rotate the brick about the x axis"); 27 | rXCmd->SetParameterName("choice",false); 28 | rXCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 29 | 30 | rYCmd = new G4UIcmdWithADoubleAndUnit("/Target/rotateY",this); 31 | rYCmd->SetGuidance("Rotate the brick about the y axis"); 32 | rYCmd->SetParameterName("choice",false); 33 | rYCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 34 | 35 | rZCmd = new G4UIcmdWithADoubleAndUnit("/Target/rotateZ",this); 36 | rZCmd->SetGuidance("Rotate the brick about the z axis"); 37 | rZCmd->SetParameterName("choice",false); 38 | rZCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 39 | 40 | RCmd = new G4UIcmdWithADoubleAndUnit("/Target/setR",this); 41 | RCmd->SetGuidance("Set the radius of the target"); 42 | RCmd->SetParameterName("choice",false); 43 | RCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 44 | 45 | LCmd = new G4UIcmdWithADoubleAndUnit("/Target/setL",this); 46 | LCmd->SetGuidance("Set the length of the target"); 47 | LCmd->SetParameterName("choice",false); 48 | LCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 49 | 50 | cCmd = new G4UIcmdWithoutParameter("/Target/Construct",this); 51 | cCmd->SetGuidance("Construct the target"); 52 | cCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 53 | 54 | GCmd = new G4UIcmdWithAString("/Target/GeometryFile",this); 55 | GCmd->SetGuidance("Set the target geometry file name."); 56 | GCmd->SetParameterName("choice",false); 57 | GCmd->AvailableForStates(G4State_PreInit,G4State_Idle); 58 | 59 | } 60 | 61 | Target_Messenger::~Target_Messenger() 62 | { 63 | delete TargetDir; 64 | delete XCmd; 65 | delete YCmd; 66 | delete ZCmd; 67 | delete rXCmd; 68 | delete rYCmd; 69 | delete rZCmd; 70 | delete RCmd; 71 | delete LCmd; 72 | delete cCmd; 73 | delete GCmd; 74 | } 75 | 76 | 77 | void Target_Messenger::SetNewValue(G4UIcommand* command,G4String newValue) 78 | { 79 | if( command == XCmd ) 80 | {target->setX(XCmd->GetNewDoubleValue(newValue));} 81 | if( command == YCmd ) 82 | {target->setY(YCmd->GetNewDoubleValue(newValue));} 83 | if( command == ZCmd ) 84 | {target->setZ(ZCmd->GetNewDoubleValue(newValue));} 85 | if( command == rXCmd ) 86 | {target->rotateX(rXCmd->GetNewDoubleValue(newValue));} 87 | if( command == rYCmd ) 88 | {target->rotateY(rYCmd->GetNewDoubleValue(newValue));} 89 | if( command == rZCmd ) 90 | {target->rotateZ(rZCmd->GetNewDoubleValue(newValue));} 91 | if( command == RCmd ) 92 | {target->setR(RCmd->GetNewDoubleValue(newValue));} 93 | if( command == LCmd ) 94 | {target->setL(LCmd->GetNewDoubleValue(newValue));} 95 | if( command == cCmd ) 96 | {target->Construct();} 97 | if( command == GCmd ) 98 | {target->setGeoFile(newValue);} 99 | } 100 | 101 | -------------------------------------------------------------------------------- /src/StepMax.cc: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | /// \file polarisation/Pol01/src/StepMax.cc 27 | /// \brief Implementation of the StepMax class 28 | // 29 | // 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 | 33 | #include "StepMax.hh" 34 | #include "StepMaxMessenger.hh" 35 | 36 | #include "G4ParticleDefinition.hh" 37 | #include "G4Step.hh" 38 | 39 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 40 | 41 | StepMax::StepMax(const G4String& processName) 42 | : G4VDiscreteProcess(processName), 43 | fMaxChargedStep(DBL_MAX), fMessenger(0) 44 | { 45 | fMessenger = new StepMaxMessenger(this); 46 | } 47 | 48 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 49 | 50 | StepMax::~StepMax() { delete fMessenger; } 51 | 52 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 53 | 54 | G4bool StepMax::IsApplicable(const G4ParticleDefinition& particle) 55 | { 56 | return (particle.GetPDGCharge() != 0.); 57 | } 58 | 59 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 60 | 61 | void StepMax::SetMaxStep(G4double step) {fMaxChargedStep = step;} 62 | 63 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 64 | 65 | G4double StepMax::PostStepGetPhysicalInteractionLength(const G4Track& aTrack, 66 | G4double, 67 | G4ForceCondition* condition ) 68 | { 69 | // condition is set to "Not Forced" 70 | *condition = NotForced; 71 | 72 | G4double ProposedStep = DBL_MAX; 73 | 74 | if((fMaxChargedStep > 0.) && 75 | (aTrack.GetVolume() != 0) && 76 | (aTrack.GetVolume()->GetName() != "World")) 77 | ProposedStep = fMaxChargedStep; 78 | 79 | return ProposedStep; 80 | } 81 | 82 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 83 | 84 | G4VParticleChange* StepMax::PostStepDoIt(const G4Track& aTrack, const G4Step&) 85 | { 86 | // do nothing 87 | aParticleChange.Initialize(aTrack); 88 | return &aParticleChange; 89 | } 90 | 91 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 92 | -------------------------------------------------------------------------------- /examples/na22/coincSort.py: -------------------------------------------------------------------------------- 1 | import numpy as np 2 | from matplotlib import pyplot as plt 3 | import matplotlib as mpl 4 | import sys 5 | 6 | # The detector resolution is simulated as the sum of two Gaussians 7 | sigmaPar = 0.75 # First energy resolution parameter 8 | 9 | # Linear energy calibration 10 | a = 0 # Energy calibration offset (keV) 11 | b = 1 # Energy calibration slope (keV/bin) 12 | 13 | # Histogram specifications 14 | eMax = 2048 15 | nBins = 2048 16 | 17 | def readInputFile(fileName = "coincSort.inp"): 18 | 19 | try: 20 | inFile = open(fileName, 'r') 21 | except IOError: 22 | return 23 | 24 | line = inFile.readline() 25 | words = line.split() 26 | sigmaPar = float(words[0]) 27 | 28 | line = inFile.readline() 29 | words = line.split() 30 | a = float(words[0]) 31 | 32 | line = inFile.readline() 33 | words = line.split() 34 | b = float(words[0]) 35 | 36 | line = inFile.readline() 37 | words = line.split() 38 | eMax = float(words[0]) 39 | 40 | line = inFile.readline() 41 | words = line.split() 42 | nBins = int(words[0]) 43 | 44 | line = inFile.readline() 45 | words = line.split() 46 | lLim = int(words[0]) 47 | 48 | line = inFile.readline() 49 | words = line.split() 50 | uLim = int(words[0]) 51 | 52 | inFile.close() 53 | 54 | return sigmaPar, a, b, eMax, nBins, lLim, uLim 55 | 56 | def Sort(fileName): 57 | 58 | try: 59 | inFile = open(fileName, 'r') 60 | except IOError: 61 | print('Error: unable to open file {0}'.format(fileName)) 62 | return 63 | 64 | # Sort the output file. 65 | counts = np.zeros(nBins) 66 | eventNumLast = -1 67 | detIDLast = 0 68 | eResLast = 0 69 | e1s = [] 70 | e2s = [] 71 | for line in inFile.readlines(): 72 | words = line.split() 73 | 74 | eventNum = int(words[0]) 75 | detID = int(words[1]) 76 | eSim = float(words[2]) 77 | 78 | # Fold in simulated resolution. 79 | sigma = sigmaPar*np.sqrt(eSim) 80 | eRes = eSim + np.random.normal(scale=sigma) 81 | 82 | # De-calibrate to match measured histogram 83 | eRes = (eRes - a)/b 84 | 85 | # Check for a coincidence 86 | if eventNum == eventNumLast: 87 | # Get the energy deposited in each detector 88 | if detID == 1: 89 | e1 = eRes 90 | e2 = eResLast 91 | else: 92 | e1 = eResLast 93 | e2 = eRes 94 | e1s.append(e1) 95 | e2s.append(e2) 96 | 97 | eventNumLast = eventNum 98 | detIDLast = detID 99 | eResLast = eRes 100 | 101 | return e1s, e2s 102 | 103 | def writeMCA(counts, fname): 104 | 105 | outFileName = fname 106 | 107 | try: 108 | outFile = open(outFileName, 'w') 109 | except IOError: 110 | print('Error: unable to open output file {0}'.format(fileName)) 111 | return 112 | 113 | header = ''' 114 | <> 115 | TAG - 116 | DESCRIPTION - UCNaI simulation 117 | GAIN - 0 118 | THRESHOLD - 0 119 | LIVE_MODE - 0 120 | PRESET_TIME - 0 121 | LIVE_TIME - 0 122 | REAL_TIME - 0 123 | START_TIME - 0 124 | SERIAL_NUMBER - 0 125 | <> 126 | ''' 127 | outFile.write(header) 128 | for count in counts: 129 | outFile.write(str(int(count))+'\n') 130 | 131 | outFile.write('<<>>') 132 | 133 | return 134 | 135 | sigmaPar, a, b, eMax, nBins, lLim, uLim = readInputFile() 136 | 137 | e1s, e2s = Sort(sys.argv[1]) 138 | 139 | plt.figure(1) 140 | # matplotlib does a good job of filling histograms from lists. 141 | # The norm=mpl.colors.LogNorm() uses a log scale for the color map 142 | # which is helpful for seeing weak coincidences. 143 | matrix, xedges, yedges, _ = plt.hist2d(e1s, e2s, bins=[nBins, nBins], 144 | range=[[0, eMax],[0, eMax]], 145 | cmap='inferno', 146 | norm=mpl.colors.LogNorm()) 147 | ax = plt.gca() 148 | ax.set_aspect('equal') 149 | plt.colorbar(orientation='vertical') 150 | plt.xlabel('Detector 1 Energy (keV)') 151 | plt.ylabel('Detector 2 Energy (keV)') 152 | plt.title('{0} Coincidence Matrix'.format(sys.argv[1])) 153 | 154 | # Det 2 spectrum gated on det 1 155 | lBin = int(lLim/eMax*nBins) 156 | uBin = int(uLim/eMax*nBins) 157 | slice = matrix[lBin:uBin+1, 0:200] 158 | scounts = [] 159 | for bin in range(nBins): 160 | scounts.append(sum(slice[:,bin])) 161 | 162 | mcaFileName = sys.argv[1] 163 | mcaFileName = mcaFileName.replace('.out', '_coinc.mca') 164 | 165 | writeMCA(scounts, mcaFileName) 166 | 167 | plt.figure(2) 168 | # It's not straightforward to produce a matplotlib 1D histogram from a 169 | # 2D array, so we'll use the plt.step() to plot the gated spectrum. 170 | 171 | # yedges[0:-1] is the list of lower bin edges, so use where='post'. 172 | plt.step(yedges[0:-1], scounts, where='post') 173 | plt.title('{0}: Detector 2 {1:.0f}:{2:.0f} keV Gate'\ 174 | .format(sys.argv[1], lLim, uLim)) 175 | plt.xlabel('Energy (keV)') 176 | plt.ylabel('Counts/{0:.0f} keV'.format(yedges[1]-yedges[0])) 177 | 178 | print('{0}: {1:.0f}:{2:.0f} keV Gate total = {3} counts'\ 179 | .format(sys.argv[1], lLim, uLim, sum(scounts))) 180 | 181 | plt.show() 182 | -------------------------------------------------------------------------------- /src/EventAction.cc: -------------------------------------------------------------------------------- 1 | #include "EventAction.hh" 2 | #include "RunAction.hh" 3 | 4 | #include "G4Timer.hh" 5 | extern G4Timer Timerintern; 6 | 7 | EventAction::EventAction() 8 | { 9 | gammaCollectionID=-1; 10 | 11 | Timerintern.Start(); 12 | } 13 | 14 | 15 | EventAction::~EventAction() 16 | { 17 | ; 18 | } 19 | 20 | void EventAction::BeginOfEventAction(const G4Event* ev) 21 | { 22 | evt = ev; 23 | 24 | // Add a G4UserEventInformation object to store event info 25 | EventInformation* eventInfo = new EventInformation; 26 | G4EventManager::GetEventManager()->SetUserInformation(eventInfo); 27 | 28 | G4SDManager * SDman = G4SDManager::GetSDMpointer(); 29 | 30 | if(gammaCollectionID<0) 31 | { 32 | gammaCollectionID=SDman->GetCollectionID("gammaCollection"); 33 | } 34 | 35 | } 36 | 37 | 38 | void EventAction::EndOfEventAction(const G4Event* ev) 39 | { 40 | 41 | evt = ev; 42 | 43 | ios::fmtflags f( G4cout.flags() ); 44 | 45 | G4int event_id=evt->GetEventID(); 46 | 47 | if(event_id%everyNevents == 0 && event_id > 0) { 48 | Timerintern.Stop(); 49 | timerCount++; 50 | eventsPerSecond += 51 | ((double)everyNevents/Timerintern.GetRealElapsed() 52 | - eventsPerSecond)/timerCount; 53 | G4cout << std::fixed << std::setprecision(0) << std::setw(3) 54 | << std::setfill(' ') 55 | << (float)event_id/NTotalEvents*100 << " % " 56 | << eventsPerSecond << " events/s "; 57 | 58 | G4double hours, minutes, seconds; 59 | G4double time = (float)(NTotalEvents - event_id)/eventsPerSecond; 60 | hours = floor(time/3600.0); 61 | if(hours>0){ 62 | G4cout << std::setprecision(0) << std::setw(2) 63 | << hours << ":"; 64 | G4cout << std::setfill('0'); 65 | } else { 66 | G4cout << std::setfill(' '); 67 | } 68 | minutes = floor(fmod(time,3600.0)/60.0); 69 | if(minutes>0){ 70 | G4cout << std::setprecision(0) << std::setw(2) << minutes << ":"; 71 | G4cout << std::setfill('0'); 72 | } else { 73 | G4cout << std::setfill(' '); 74 | } 75 | seconds = fmod(time,60.0); 76 | if(seconds>0) 77 | G4cout << std::setprecision(0) << std::setw(2) << seconds; 78 | G4cout << std::setfill(' '); 79 | G4cout << " remaining " 80 | << "\r"<GetUserInformation(); 85 | 86 | // if(event_id%10000==0) { 87 | // G4cout<<" Number of processed events "<GetHCofThisEvent(); 92 | if(HCE) { 93 | 94 | TrackerGammaHitsCollection* gammaCollection = (TrackerGammaHitsCollection*)(HCE->GetHC(gammaCollectionID)); 95 | 96 | G4int Ngamma = gammaCollection->entries(); 97 | 98 | if(Ngamma>0) { 99 | 100 | G4double Edep[100] = {0}; 101 | G4double EdepMax[100] = {0}; 102 | G4int firstHit[100] = {0}; 103 | 104 | G4int detMax = 0; 105 | 106 | for(int i=0; iGetDetID()-1; 108 | G4double E = (*gammaCollection)[i]->GetEdep()/keV; 109 | 110 | if(E>EdepMax[det]) { 111 | EdepMax[det] = E; 112 | firstHit[det] = i; 113 | } 114 | 115 | Edep[det] += E; 116 | 117 | if(det > detMax) 118 | detMax = det; 119 | 120 | } 121 | 122 | // G4cout << "**** Track Total Energy = " << (*gammaCollection)[0]->GetTotalEnergy()/keV << G4endl; 123 | 124 | // G4cout << "**** Energy Deposited = " << Edep << G4endl; 125 | 126 | for(int det=0; det 0) { 129 | G4int photopeak = 0; 130 | 131 | if(abs(eventInfo->GetEmittedGammaEnergy(0) - Edep[det])<0.001){ 132 | photopeak = 1; 133 | eventInfo->SetFullEnergy(1); 134 | } else { 135 | eventInfo->SetFullEnergy(0); 136 | } 137 | 138 | evfile 139 | << std::setw(15) << std::right 140 | << event_id 141 | << std::setw(5) << std::right 142 | << (*gammaCollection)[firstHit[det]]->GetDetID() 143 | << std::fixed << std::setprecision(2) << std::setw(10) << std::right 144 | << Edep[det] 145 | << std::setw(10) << std::right 146 | << (*gammaCollection)[firstHit[det]]->GetPos().getX()/mm 147 | << std::setw(10) << std::right 148 | << (*gammaCollection)[firstHit[det]]->GetPos().getY()/mm 149 | << std::setw(10) << std::right 150 | << (*gammaCollection)[firstHit[det]]->GetPos().getZ()/mm 151 | << std::setw(10) << std::right 152 | << photopeak 153 | << G4endl; 154 | } 155 | 156 | } 157 | 158 | } 159 | 160 | } 161 | 162 | G4cout.flags( f ); 163 | 164 | } 165 | // -------------------------------------------------- 166 | void EventAction::openEvfile() 167 | { 168 | if (!evfile.is_open()) evfile.open(outFileName.c_str()); 169 | if (!evfile.is_open()) 170 | G4cout<< "ERROR opening evfile." << G4endl; 171 | else 172 | G4cout << "\nOpened output file: " << outFileName << G4endl; 173 | return; 174 | } 175 | //--------------------------------------------------- 176 | void EventAction::closeEvfile() 177 | { 178 | evfile.close(); 179 | return; 180 | } 181 | //---------------------------------------------------- 182 | void EventAction::SetOutFile(G4String name) 183 | { 184 | outFileName = name; 185 | closeEvfile(); 186 | openEvfile(); 187 | return; 188 | } 189 | -------------------------------------------------------------------------------- /src/NaI_Detector.cc: -------------------------------------------------------------------------------- 1 | #include "NaI_Detector.hh" 2 | 3 | NaI_Detector::NaI_Detector(G4LogicalVolume* experimentalHall_log, 4 | Materials* mat) 5 | { 6 | materials=mat; 7 | expHall_log=experimentalHall_log; 8 | 9 | NaI = materials->FindMaterial("G4_SODIUM_IODIDE"); 10 | Al = materials->FindMaterial("Al"); 11 | pmtMat = materials->FindMaterial("pmtMat"); 12 | 13 | Length=2*2.54*cm; 14 | Radius =1.0*2.54*cm; 15 | 16 | startAngle = 45.*deg; 17 | spanningAngle = 360.*deg; 18 | 19 | CanThickness = 0.0508*cm; 20 | CanOuterRadius = 2.54*2.1875/2.0*cm; // 21 | CanInnerRadius = CanOuterRadius - CanThickness; 22 | CanLength = Length + CanThickness; 23 | 24 | DetPos.setX(0); 25 | DetPos.setY(0); 26 | DetPos.setZ(0); 27 | 28 | canShift.setX(0); 29 | canShift.setY(0); 30 | canShift.setZ(1.5*CanThickness); 31 | canPos = DetPos + canShift; 32 | 33 | capShift.setX(0); 34 | capShift.setY(0); 35 | capShift.setZ(-CanLength/2.0 - CanThickness/2.0); 36 | 37 | capPos = canPos + capShift; 38 | 39 | detShift.setX(0); 40 | detShift.setY(0); 41 | detShift.setZ(2.0*CanThickness); 42 | DetPos = DetPos + detShift; 43 | 44 | pmtRadius = CanOuterRadius; 45 | pmtLength = 5.125*2.54*cm; // CHECK THIS 46 | 47 | pmtShift.setX(0); 48 | pmtShift.setY(0); 49 | pmtShift.setZ(3); 50 | pmtShift.setMag(Length/2.0 + pmtLength/2.0); 51 | pmtPos = DetPos + pmtShift; 52 | 53 | thetad = 90.*deg; 54 | phid = 90.*deg; 55 | 56 | DetRot=G4RotationMatrix::IDENTITY; 57 | DetRot.rotateX(180.*deg); 58 | DetRot.rotateY(90.*deg+thetad); 59 | DetRot.rotateZ(phid); 60 | 61 | assemblyRot = G4RotationMatrix::IDENTITY; 62 | assemblyRot.rotateX(-90.*deg); 63 | 64 | assemblyPos.setX(0); 65 | assemblyPos.setY(0); 66 | assemblyPos.setZ(20*cm); 67 | 68 | assembly = new G4AssemblyVolume(); 69 | 70 | geoFileName = ""; 71 | } 72 | 73 | NaI_Detector::~NaI_Detector() 74 | { 75 | } 76 | 77 | void NaI_Detector::Construct() 78 | { 79 | 80 | // Material surrounding the crystal 81 | can = new G4Tubs("Can",CanInnerRadius,CanOuterRadius,CanLength/2.0,startAngle,spanningAngle); 82 | 83 | can_log = new G4LogicalVolume(can,Al,"can_log",0,0,0); 84 | 85 | cap = new G4Tubs("Cap",0.,CanOuterRadius,CanThickness/2.0,startAngle,spanningAngle); 86 | 87 | cap_log = new G4LogicalVolume(cap,Al,"cap_log",0,0,0); 88 | 89 | pmt = new G4Tubs("pmt",0.,pmtRadius,pmtLength/2.0,startAngle,spanningAngle); 90 | 91 | pmt_log = new G4LogicalVolume(pmt,pmtMat,"pmt_log",0,0,0); 92 | 93 | // detector 94 | 95 | detector = new G4Tubs("detector",0,Radius,Length/2.0,startAngle,spanningAngle); 96 | 97 | detector_log = new G4LogicalVolume(detector,NaI,"detector_log",0,0,0); 98 | 99 | PlaceDetector(); 100 | 101 | //------------------------------Detector readout division 102 | 103 | //Visualization Attributes 104 | 105 | // NaI Crystal 106 | G4Colour dgreen (0.0,0.75, 0.0, 1.0); 107 | G4VisAttributes* Vis_1 = new G4VisAttributes(dgreen); 108 | Vis_1->SetVisibility(true); 109 | Vis_1->SetForceSolid(true); 110 | 111 | // Can 112 | G4Colour transGrey (0.5, 0.5, 0.5, 0.3); 113 | G4VisAttributes* Vis_2 = new G4VisAttributes(transGrey); 114 | Vis_2->SetVisibility(true); 115 | Vis_2->SetForceSolid(true); 116 | 117 | // Dead material 118 | G4Colour dGrey (0.8, 0.8, 0.8, 1.0); 119 | G4VisAttributes* Vis_3 = new G4VisAttributes(dGrey); 120 | Vis_3->SetVisibility(true); 121 | Vis_3->SetForceSolid(true); 122 | 123 | detector_log->SetVisAttributes(Vis_1); 124 | 125 | can_log->SetVisAttributes(Vis_2); 126 | 127 | cap_log->SetVisAttributes(Vis_2); 128 | 129 | pmt_log->SetVisAttributes(Vis_3); 130 | 131 | } 132 | //--------------------------------------------------------------------- 133 | void NaI_Detector::PlaceDetector() 134 | { 135 | 136 | // detector_phys = new G4PVPlacement(G4Transform3D(DetRot,DetPos), 137 | // detector_log,"detector",expHall_log,false,0); 138 | 139 | // can_phys = new G4PVPlacement(G4Transform3D(DetRot,canPos), 140 | // can_log,"Can",expHall_log,false,0,true); 141 | 142 | // cap_phys = new G4PVPlacement(G4Transform3D(DetRot,capPos), 143 | // cap_log,"Cap",expHall_log,false,0,true); 144 | 145 | // pmt_phys = new G4PVPlacement(G4Transform3D(DetRot,pmtPos), 146 | // pmt_log,"PMT",expHall_log,false,0,true); 147 | 148 | assembly->AddPlacedVolume(detector_log, DetPos, &DetRot); 149 | 150 | assembly->AddPlacedVolume(can_log, canPos, &DetRot); 151 | 152 | assembly->AddPlacedVolume(cap_log, capPos, &DetRot); 153 | 154 | assembly->AddPlacedVolume(pmt_log, pmtPos, &DetRot); 155 | 156 | // If there is a NaI geometry file, use it for placement, 157 | // if not, use the curret assemblyPos and assemblyRot to 158 | // place a single NaI. 159 | G4int detID = 1000; // Base for the replica number. 160 | if(geoFileName != ""){ 161 | geoFile.open(geoFileName.c_str()); 162 | if (!geoFile.is_open()) 163 | G4cout<< "ERROR opening NaI geometry file." << G4endl; 164 | else 165 | G4cout << "\nPositioning NaI detectors using the geometry file: " << geoFileName << G4endl; 166 | 167 | G4double x, y, z, ax, ay, az; 168 | while(geoFile >> x >> y >> z >> ax >> ay >> az){ 169 | assemblyPos.setX(x); 170 | assemblyPos.setY(y); 171 | assemblyPos.setZ(z); 172 | assemblyRot = G4RotationMatrix::IDENTITY; 173 | assemblyRot.rotateX(ax*deg); 174 | assemblyRot.rotateY(ay*deg); 175 | assemblyRot.rotateZ(az*deg); 176 | assembly->MakeImprint(expHall_log, assemblyPos, &assemblyRot, detID); 177 | detID++; 178 | } 179 | } else { 180 | assembly->MakeImprint(expHall_log, assemblyPos, &assemblyRot, detID); 181 | } 182 | } 183 | //--------------------------------------------------------------------- 184 | void NaI_Detector::MakeSensitive(TrackerGammaSD* TrackerGamma) 185 | { 186 | detector_log->SetSensitiveDetector(TrackerGamma); 187 | } 188 | //--------------------------------------------------------------------- 189 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # UCNaI 2 | 3 | ## Compile and install 4 | 5 | Install version [4.10.07.p01 of the Geant4 libraries](https://geant4.web.cern.ch/geant4/support/download.shtml). You will need the data files for low energy electromagnetic processes, photon evaporation, and radioactive decay. 6 | 7 | Set up your environment (consider adding this to your `.bashrc`): 8 | 9 | $ source /bin/geant4.sh 10 | $ source /share/Geant4-10.6.3/geant4make/geant4make.sh 11 | 12 | Compile: 13 | 14 | $ make 15 | 16 | ## Examples 17 | 18 | (Run the examples by typing `make` at the command line in the corresponding directory.) 19 | 20 | ### `./examples/cs137` 21 | 22 | This is a simple example collecting a spectrum with a single NaI detector from a 137Cs source. A sorting code `NaISort.py` is included which produces a histogram in the `.mca` format (requires python3 and the numpy module). A `Makefile` is included. 23 | 24 | ### `./examples/na22` 25 | 26 | This example simulates two NaI detectors collecting spectra from a 22Na source centered between them, and off center. The `coincSort.py` sorts a coincidence matrix and the spectrum of detector 2 gated on an energy range in spectrum 1. The gate range is set in the file `coincSort.inp` and is set to 0-2000 keV by default. (Gating in the range 1225 - 1325 keV shows coincidences with the 1274 keV transition in the 22Ne daughter and the 511 keV gamma rays from the e+ - e- annihilation.) 27 | 28 | ## Macro File Commands 29 | 30 | ### NaI Detector Placement 31 | 32 | /NaI/setX 33 | /NaI/setY 34 | /NaI/setZ 35 | 36 | > Set the position of the detector. 37 | 38 | /NaI/rotateX 39 | /NaI/rotateY 40 | /NaI/rotateZ 41 | 42 | > Orient the detector by rotating about X, Y, Z. 43 | 44 | /NaI/GeometryFile 45 | 46 | > Set the name of the optional geometry file. If this command is present, a NaI detector is placed for each line in the specified file. Each line has the format: 47 | 48 | 49 | 50 | > If a geometry file is specified, the positioning and rotation commands above are ignored. 51 | 52 | ### Source 53 | 54 | Realistic simulations of radioactive sources can be run as illustrated by `./examples/cs137/cs137.mac`. The Simple source is a computationally more efficient alternative. 55 | 56 | /Source/Simple 57 | 58 | > Use a simple monoenergetic gamma-ray source with the specified energy. 59 | 60 | /Source/setX 61 | /Source/setY 62 | /Source/setZ 63 | 64 | > Set the position of the source (and capsule if present). 65 | 66 | /Source/Capsule/rotateX 67 | /Source/Capsule/rotateY 68 | /Source/Capsule/rotateZ 69 | 70 | > Orient the source capsule by rotating about X, Y, Z. 71 | 72 | /Source/Capsule/Construct 73 | 74 | > Include the source capsule. Must be issued after the source positioning and capsule rotation commands. 75 | 76 | ### Lead Bricks 77 | 78 | Optionally, 2" x 4" x 6" lead bricks can be included in simulations. 79 | 80 | /Brick/setX 81 | /Brick/setY 82 | /Brick/setZ 83 | 84 | > Set the position of the brick. 85 | 86 | /Brick/rotateX 87 | /Brick/rotateY 88 | /Brick/rotateZ 89 | 90 | > Orient the brick by rotating about X, Y, Z. (The order of these commands matters.) 91 | 92 | /Brick/GeometryFile 93 | 94 | > Set the name of the optional geometry file. If this command is present, a brick is placed for each line in the specified file. Each line has the format: 95 | 96 | 97 | 98 | > If a geometry file is specified, the positioning and rotation commands above are ignored. 99 | 100 | /Brick/Construct 101 | 102 | > Include the brick. Must be issued after the positioning and rotation commands. 103 | 104 | ### Aluminum Targets 105 | 106 | Optionally, cylindrical aluminum targets can be included in simulations. 107 | 108 | /Target/setR 109 | 110 | > Set the radius of the target(s). 111 | 112 | /Target/setL 113 | 114 | > Set the length of the target(s). 115 | 116 | /Target/setX 117 | /Target/setY 118 | /Target/setZ 119 | 120 | > Set the position of the target. 121 | 122 | /Target/rotateX 123 | /Target/rotateY 124 | /Target/rotateZ 125 | 126 | > Orient the target by rotating about X, Y, Z. (The order of these commands matters.) 127 | 128 | /Target/GeometryFile 129 | 130 | > Set the name of the optional geometry file. If this command is present, a target is placed for each line in the specified file. Each line has the format: 131 | 132 | 133 | 134 | > If a geometry file is specified, the positioning and rotation commands above are ignored. 135 | 136 | /Target/Construct 137 | 138 | > Include the target(s). Must be issued after the positioning and rotation commands. 139 | 140 | ## Output 141 | 142 | Output is written to a text file. Each line represents a detected event and has the format: 143 | 144 | 145 | 146 | - `` : event number 147 | - `` : integer identifying the detector registering the event 148 | - `` : energy deposited in keV 149 | - ``, ``, `` : hit position in mm 150 | - `` : == 1 if the gamma ray deposited its total energy in the detector, == 0 otherwise 151 | 152 | ## Visualization 153 | 154 | Run the macro file `vis/vis.mac` an interactive session: 155 | 156 | $ UCNaI 157 | 158 | Idle> /control/execute vis/vis.mac 159 | Idle> exit 160 | 161 | This generates a VRML 2 file named `g4_XX.wrl` which can be viewed with a VRML viewer (like view3dscene, FreeWRL, or mayavi2). 162 | 163 | The macro file `./vis/trajectories.mac` illustrates how to add particle trajectories to visualizations. 164 | -------------------------------------------------------------------------------- /src/PhysicsList.cc: -------------------------------------------------------------------------------- 1 | // 2 | // ******************************************************************** 3 | // * License and Disclaimer * 4 | // * * 5 | // * The Geant4 software is copyright of the Copyright Holders of * 6 | // * the Geant4 Collaboration. It is provided under the terms and * 7 | // * conditions of the Geant4 Software License, included in the file * 8 | // * LICENSE and available at http://cern.ch/geant4/license . These * 9 | // * include a list of copyright holders. * 10 | // * * 11 | // * Neither the authors of this software system, nor their employing * 12 | // * institutes,nor the agencies providing financial support for this * 13 | // * work make any representation or warranty, express or implied, * 14 | // * regarding this software system or assume any liability for its * 15 | // * use. Please see the license in the file LICENSE and URL above * 16 | // * for the full disclaimer and the limitation of liability. * 17 | // * * 18 | // * This code implementation is the result of the scientific and * 19 | // * technical work of the GEANT4 collaboration. * 20 | // * By using, copying, modifying or distributing the software (or * 21 | // * any work based on the software) you agree to acknowledge its * 22 | // * use in resulting scientific publications, and indicate your * 23 | // * acceptance of all terms of the Geant4 Software license. * 24 | // ******************************************************************** 25 | // 26 | /// \file electromagnetic/TestEm7/src/PhysicsList.cc 27 | /// \brief Implementation of the PhysicsList class 28 | // 29 | // 30 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 31 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 32 | 33 | #include "PhysicsList.hh" 34 | #include "PhysicsListMessenger.hh" 35 | 36 | //#include "PhysListEmStandard.hh" 37 | //#include "PhysListEmStandardNR.hh" 38 | #include "G4EmStandardPhysics.hh" 39 | #include "G4EmStandardPhysics_option1.hh" 40 | #include "G4EmStandardPhysics_option2.hh" 41 | #include "G4EmStandardPhysics_option3.hh" 42 | #include "G4EmStandardPhysics_option4.hh" 43 | #include "G4EmStandardPhysicsWVI.hh" 44 | #include "G4EmStandardPhysicsGS.hh" 45 | #include "G4EmStandardPhysicsSS.hh" 46 | 47 | #include "G4EmLivermorePhysics.hh" 48 | #include "G4EmPenelopePhysics.hh" 49 | #include "G4EmLowEPPhysics.hh" 50 | 51 | #include "G4eMultipleScattering.hh" 52 | 53 | #include "G4PolarizedCompton.hh" 54 | #include "G4PolarizedGammaConversion.hh" 55 | #include "G4ePolarizedIonisation.hh" 56 | #include "G4ePolarizedBremsstrahlung.hh" 57 | #include "G4eplusPolarizedAnnihilation.hh" 58 | #include "G4PolarizedPhotoElectricEffect.hh" 59 | #include "G4DecayPhysics.hh" 60 | 61 | #include "G4HadronElasticPhysics.hh" 62 | #include "G4HadronDElasticPhysics.hh" 63 | #include "G4HadronHElasticPhysics.hh" 64 | #include "G4HadronInelasticQBBC.hh" 65 | #include "G4IonPhysics.hh" 66 | 67 | #include "G4LossTableManager.hh" 68 | #include "G4EmConfigurator.hh" 69 | #include "G4UnitsTable.hh" 70 | 71 | #include "G4ProcessManager.hh" 72 | #include "G4Decay.hh" 73 | 74 | #include "G4NuclideTable.hh" 75 | #include "G4UAtomicDeexcitation.hh" 76 | #include "G4NuclearLevelData.hh" 77 | #include "G4DeexPrecoParameters.hh" 78 | 79 | #include "StepMax.hh" 80 | 81 | #include "G4IonFluctuations.hh" 82 | #include "G4IonParametrisedLossModel.hh" 83 | #include "G4UniversalFluctuation.hh" 84 | 85 | #include "G4BraggIonGasModel.hh" 86 | #include "G4BetheBlochIonGasModel.hh" 87 | 88 | #include "G4PhysicalConstants.hh" 89 | #include "G4SystemOfUnits.hh" 90 | 91 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 92 | 93 | PhysicsList::PhysicsList() : G4VModularPhysicsList() 94 | , fStepMaxProcess(nullptr) 95 | { 96 | fHelIsRegisted = false; 97 | fBicIsRegisted = false; 98 | fBiciIsRegisted = false; 99 | 100 | // protected member of the base class 101 | verboseLevel = 1; 102 | 103 | fMessenger = new PhysicsListMessenger(this); 104 | 105 | // EM physics 106 | fEmName = G4String("emstandard_opt4"); 107 | fEmPhysicsList = new G4EmStandardPhysics(verboseLevel); 108 | 109 | // Deacy physics and all particles 110 | fDecPhysicsList = new G4DecayPhysics(verboseLevel); 111 | 112 | // mandatory for G4NuclideTable 113 | // 114 | G4NuclideTable::GetInstance()->SetThresholdOfHalfLife(0.1*picosecond); 115 | G4NuclideTable::GetInstance()->SetLevelTolerance(1.0*eV); 116 | 117 | //read new PhotonEvaporation data set 118 | // 119 | G4DeexPrecoParameters* deex = 120 | G4NuclearLevelData::GetInstance()->GetParameters(); 121 | deex->SetCorrelatedGamma(false); 122 | deex->SetStoreAllLevels(true); 123 | // deex->SetIsomerProduction(true); 124 | deex->SetMaxLifeTime(G4NuclideTable::GetInstance()->GetThresholdOfHalfLife() 125 | /std::log(2.)); 126 | 127 | G4LossTableManager::Instance(); 128 | // fix lower limit for cut 129 | G4ProductionCutsTable::GetProductionCutsTable()->SetEnergyRange(10*eV, 1*GeV); 130 | SetDefaultCutValue(1*mm); 131 | 132 | usePolar = false; 133 | } 134 | 135 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 136 | 137 | PhysicsList::~PhysicsList() 138 | { 139 | delete fMessenger; 140 | delete fEmPhysicsList; 141 | delete fDecPhysicsList; 142 | for(size_t i=0; iConstructParticle(); 150 | } 151 | 152 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 153 | 154 | void PhysicsList::ConstructProcess() 155 | { 156 | // transportation 157 | // 158 | AddTransportation(); 159 | 160 | // electromagnetic physics list 161 | // 162 | fEmPhysicsList->ConstructProcess(); 163 | 164 | if(usePolar){ 165 | // From examples/extended/polarisation/PhysListEmPolarized.cc 166 | auto particleIterator=GetParticleIterator(); 167 | particleIterator->reset(); 168 | while( (*particleIterator)() ){ 169 | G4ParticleDefinition* particle = particleIterator->value(); 170 | G4ProcessManager* pmanager = particle->GetProcessManager(); 171 | G4String particleName = particle->GetParticleName(); 172 | 173 | if (particleName == "gamma") { 174 | pmanager->AddDiscreteProcess(new G4PolarizedPhotoElectricEffect); 175 | pmanager->AddDiscreteProcess(new G4PolarizedCompton); 176 | pmanager->AddDiscreteProcess(new G4PolarizedGammaConversion); 177 | 178 | } else if (particleName == "e-") { 179 | pmanager->AddProcess(new G4eMultipleScattering, -1,1,1); 180 | pmanager->AddProcess(new G4ePolarizedIonisation, -1,2,2); 181 | pmanager->AddProcess(new G4ePolarizedBremsstrahlung, -1,3,3); 182 | 183 | } else if (particleName == "e+") { 184 | pmanager->AddProcess(new G4eMultipleScattering, -1, 1,1); 185 | pmanager->AddProcess(new G4ePolarizedIonisation, -1, 2,2); 186 | pmanager->AddProcess(new G4ePolarizedBremsstrahlung, -1, 3,3); 187 | pmanager->AddProcess(new G4eplusPolarizedAnnihilation, 0,-1,4); 188 | } 189 | } 190 | 191 | // G4ProcessManager *gpMan = G4Gamma::Gamma()->GetProcessManager(); 192 | // G4ProcessVector* pv = gpMan->GetProcessList(); 193 | // for(unsigned int i=0;ientries();i++){ 194 | // if((*pv)[i]->GetProcessName()=="phot"){ 195 | // gpMan->RemoveProcess((*pv)[i]); 196 | // gpMan->AddDiscreteProcess(new G4PolarizedPhotoElectricEffect); 197 | // } 198 | // if((*pv)[i]->GetProcessName()=="compt"){ 199 | // gpMan->RemoveProcess((*pv)[i]); 200 | // gpMan->AddDiscreteProcess(new G4PolarizedCompton()); 201 | // } 202 | // if((*pv)[i]->GetProcessName()=="conv"){ 203 | // gpMan->RemoveProcess((*pv)[i]); 204 | // gpMan->AddDiscreteProcess(new G4PolarizedGammaConversion); 205 | // } 206 | // } 207 | } 208 | 209 | // decay physics list 210 | // 211 | fDecPhysicsList->ConstructProcess(); 212 | 213 | // hadronic physics lists 214 | for(size_t i=0; iConstructProcess(); 216 | } 217 | 218 | AddRadioactiveDecay(); 219 | 220 | // step limitation (as a full process) 221 | 222 | AddStepMax(); 223 | } 224 | 225 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 226 | 227 | void PhysicsList::AddPhysicsList(const G4String& name) 228 | { 229 | if (verboseLevel>1) { 230 | G4cout << "PhysicsList::AddPhysicsList: <" << name << ">" << G4endl; 231 | } 232 | 233 | if (name == fEmName) return; 234 | 235 | // if (name == "local") { 236 | 237 | // fEmName = name; 238 | // delete fEmPhysicsList; 239 | // fEmPhysicsList = new PhysListEmStandard(name); 240 | 241 | // } else 242 | if (name == "emstandard_opt0") { 243 | 244 | fEmName = name; 245 | delete fEmPhysicsList; 246 | fEmPhysicsList = new G4EmStandardPhysics(verboseLevel); 247 | 248 | } else if (name == "emstandard_opt1") { 249 | 250 | fEmName = name; 251 | delete fEmPhysicsList; 252 | fEmPhysicsList = new G4EmStandardPhysics_option1(verboseLevel); 253 | 254 | } else if (name == "emstandard_opt2") { 255 | 256 | fEmName = name; 257 | delete fEmPhysicsList; 258 | fEmPhysicsList = new G4EmStandardPhysics_option2(verboseLevel); 259 | 260 | } else if (name == "emstandard_opt3") { 261 | 262 | fEmName = name; 263 | delete fEmPhysicsList; 264 | fEmPhysicsList = new G4EmStandardPhysics_option3(verboseLevel); 265 | 266 | } else if (name == "emstandard_opt4") { 267 | 268 | fEmName = name; 269 | delete fEmPhysicsList; 270 | fEmPhysicsList = new G4EmStandardPhysics_option4(verboseLevel); 271 | 272 | } else if (name == "ionGasModels") { 273 | 274 | AddPhysicsList("emstandard_opt0"); 275 | fEmName = name; 276 | AddIonGasModels(); 277 | 278 | // } else if (name == "standardNR") { 279 | 280 | // fEmName = name; 281 | // delete fEmPhysicsList; 282 | // fEmPhysicsList = new PhysListEmStandardNR(name); 283 | 284 | } else if (name == "emlivermore") { 285 | fEmName = name; 286 | delete fEmPhysicsList; 287 | fEmPhysicsList = new G4EmLivermorePhysics(verboseLevel); 288 | 289 | } else if (name == "empenelope") { 290 | fEmName = name; 291 | delete fEmPhysicsList; 292 | fEmPhysicsList = new G4EmPenelopePhysics(verboseLevel); 293 | 294 | } else if (name == "emlowenergy") { 295 | fEmName = name; 296 | delete fEmPhysicsList; 297 | fEmPhysicsList = new G4EmLowEPPhysics(verboseLevel); 298 | 299 | } else if (name == "emstandardSS") { 300 | 301 | fEmName = name; 302 | delete fEmPhysicsList; 303 | fEmPhysicsList = new G4EmStandardPhysicsSS(verboseLevel); 304 | 305 | } else if (name == "emstandardWVI") { 306 | 307 | fEmName = name; 308 | delete fEmPhysicsList; 309 | fEmPhysicsList = new G4EmStandardPhysicsWVI(verboseLevel); 310 | 311 | } else if (name == "emstandardGS") { 312 | 313 | fEmName = name; 314 | delete fEmPhysicsList; 315 | fEmPhysicsList = new G4EmStandardPhysicsGS(verboseLevel); 316 | 317 | } else if (name == "elastic" && !fHelIsRegisted) { 318 | fHadronPhys.push_back( new G4HadronElasticPhysics(verboseLevel)); 319 | fHelIsRegisted = true; 320 | 321 | } else if (name == "DElastic" && !fHelIsRegisted) { 322 | fHadronPhys.push_back( new G4HadronDElasticPhysics(verboseLevel)); 323 | fHelIsRegisted = true; 324 | 325 | } else if (name == "HElastic" && !fHelIsRegisted) { 326 | fHadronPhys.push_back( new G4HadronHElasticPhysics(verboseLevel)); 327 | fHelIsRegisted = true; 328 | 329 | } else if (name == "binary" && !fBicIsRegisted) { 330 | fHadronPhys.push_back(new G4HadronInelasticQBBC(verboseLevel)); 331 | fBicIsRegisted = true; 332 | 333 | } else if (name == "binary_ion" && !fBiciIsRegisted) { 334 | fHadronPhys.push_back(new G4IonPhysics(verboseLevel)); 335 | fBiciIsRegisted = true; 336 | 337 | } else { 338 | 339 | G4cout << "PhysicsList::AddPhysicsList: <" << name << ">" 340 | << " is not defined" 341 | << G4endl; 342 | } 343 | } 344 | 345 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 346 | 347 | void PhysicsList::AddStepMax() 348 | { 349 | // Step limitation seen as a process 350 | fStepMaxProcess = new StepMax(); 351 | 352 | auto particleIterator=GetParticleIterator(); 353 | particleIterator->reset(); 354 | while ((*particleIterator)()){ 355 | G4ParticleDefinition* particle = particleIterator->value(); 356 | G4ProcessManager* pmanager = particle->GetProcessManager(); 357 | 358 | if (fStepMaxProcess->IsApplicable(*particle) && pmanager) 359 | { 360 | pmanager ->AddDiscreteProcess(fStepMaxProcess); 361 | } 362 | } 363 | } 364 | 365 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 366 | 367 | #include "G4PhysicsListHelper.hh" 368 | //#include "G4RadioactiveDecay.hh" 369 | #include "G4Radioactivation.hh" 370 | #include "G4GenericIon.hh" 371 | 372 | void PhysicsList::AddRadioactiveDecay() 373 | { 374 | //G4RadioactiveDecay* radioactiveDecay = new G4RadioactiveDecay(); 375 | 376 | G4Radioactivation* radioactiveDecay = new G4Radioactivation(); 377 | 378 | G4bool ARMflag = true; 379 | radioactiveDecay->SetARM(ARMflag); //Atomic Rearangement 380 | 381 | // need to initialize atomic deexcitation 382 | // 383 | G4LossTableManager* man = G4LossTableManager::Instance(); 384 | G4VAtomDeexcitation* deex = man->AtomDeexcitation(); 385 | if (!deex) { 386 | ///G4EmParameters::Instance()->SetFluo(true); 387 | G4EmParameters::Instance()->SetAugerCascade(ARMflag); 388 | G4EmParameters::Instance()->SetDeexcitationIgnoreCut(ARMflag); 389 | deex = new G4UAtomicDeexcitation(); 390 | deex->InitialiseAtomicDeexcitation(); 391 | man->SetAtomDeexcitation(deex); 392 | } 393 | 394 | // register radioactiveDecay 395 | // 396 | G4PhysicsListHelper* ph = G4PhysicsListHelper::GetPhysicsListHelper(); 397 | ph->RegisterProcess(radioactiveDecay, G4GenericIon::GenericIon()); 398 | 399 | } 400 | 401 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 402 | 403 | void PhysicsList::AddIonGasModels() 404 | { 405 | G4EmConfigurator* em_config = 406 | G4LossTableManager::Instance()->EmConfigurator(); 407 | auto particleIterator=GetParticleIterator(); 408 | particleIterator->reset(); 409 | while ((*particleIterator)()) 410 | { 411 | G4ParticleDefinition* particle = particleIterator->value(); 412 | G4String partname = particle->GetParticleName(); 413 | if(partname == "alpha" || partname == "He3" || partname == "GenericIon") { 414 | G4BraggIonGasModel* mod1 = new G4BraggIonGasModel(); 415 | G4BetheBlochIonGasModel* mod2 = new G4BetheBlochIonGasModel(); 416 | G4double eth = 2.*MeV*particle->GetPDGMass()/proton_mass_c2; 417 | em_config->SetExtraEmModel(partname,"ionIoni",mod1,"",0.0,eth, 418 | new G4IonFluctuations()); 419 | em_config->SetExtraEmModel(partname,"ionIoni",mod2,"",eth,100*TeV, 420 | new G4UniversalFluctuation()); 421 | 422 | } 423 | } 424 | } 425 | 426 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 427 | 428 | void PhysicsList::SetUsePolarizedPhysics(bool use){ 429 | usePolar=use; 430 | } 431 | 432 | //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 433 | --------------------------------------------------------------------------------