File indexing completed on 2025-02-23 09:20:23
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #include "TrackingAction.hh"
0030 #include "G4Track.hh"
0031 #include "G4VSolid.hh"
0032 #include "G4Region.hh"
0033 #include "G4Electron.hh"
0034 #include "G4Gamma.hh"
0035 #include "DetectorConstruction.hh"
0036
0037 using namespace std;
0038
0039 TrackingAction::TrackingAction(DetectorConstruction* detector)
0040 {
0041 fDetector = detector;
0042 fTargetRegion = 0;
0043 }
0044
0045 TrackingAction::~TrackingAction()
0046 {
0047 fDetector = 0;
0048 fTargetRegion = 0;
0049 }
0050
0051 void TrackingAction::PreUserTrackingAction(const G4Track* track)
0052 {
0053 const G4ParticleDefinition* particleDefinition = track->GetParticleDefinition();
0054
0055 if(particleDefinition == G4Electron::Definition() || particleDefinition == G4Gamma::Definition())
0056 {
0057 if(fTargetRegion == 0)
0058 {
0059 fTargetRegion = fDetector->GetTargetRegion();
0060 }
0061
0062 const G4ThreeVector& position = track->GetPosition();
0063
0064 int N = fTargetRegion->GetNumberOfRootVolumes();
0065 std::vector<G4LogicalVolume*>::iterator it_logicalVolumeInRegion =
0066 fTargetRegion->GetRootLogicalVolumeIterator();
0067
0068 bool inside_target = false;
0069
0070 for(int i = 0; i < N ; i++, it_logicalVolumeInRegion++)
0071 {
0072 EInside test_status = (*it_logicalVolumeInRegion)->GetSolid()->Inside(position) ;
0073 if(test_status == kInside)
0074 {
0075 inside_target = true;
0076 break;
0077 }
0078
0079
0080
0081
0082
0083 }
0084
0085 if(inside_target == true)
0086 {
0087 fNParticleInTarget[particleDefinition]++;
0088 }
0089 else
0090 {
0091 fNParticleInWorld[particleDefinition]++;
0092 }
0093 }
0094 }
0095