File indexing completed on 2025-10-13 08:26:58
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
0030 #include "SteppingAction.hh"
0031 #include "DetectorConstruction.hh"
0032
0033 #include "G4Step.hh"
0034 #include "G4Event.hh"
0035 #include "G4RunManager.hh"
0036 #include "G4LogicalVolume.hh"
0037
0038 #include "G4AnalysisManager.hh"
0039
0040
0041
0042 SteppingAction::SteppingAction()
0043 {}
0044
0045
0046
0047 void SteppingAction::UserSteppingAction(const G4Step* step)
0048 {
0049
0050 G4String volumeName = step->GetPreStepPoint()->GetTouchableHandle()
0051 ->GetVolume()->GetName();
0052
0053
0054 if (step->GetPreStepPoint()-> GetStepStatus()==G4StepStatus::fGeomBoundary&&
0055 (volumeName=="Crystal"||volumeName=="Detector"))
0056 {
0057
0058
0059 G4double x0 = step->GetPreStepPoint()->GetPosition().getX()/CLHEP::mm;
0060 G4double y0 = step->GetPreStepPoint()->GetPosition().getY()/CLHEP::mm;
0061
0062
0063 G4ThreeVector momentumDirection =
0064 step->GetPreStepPoint()->GetMomentumDirection();
0065 G4double angle_x =
0066 std::atan(momentumDirection.getX()/momentumDirection.getZ());
0067 G4double angle_y =
0068 std::atan(momentumDirection.getY()/momentumDirection.getZ());
0069 if (momentumDirection.getZ() < 0)
0070 {
0071 if (momentumDirection.getX() > 0)
0072 {
0073 angle_x += CLHEP::pi;
0074 }
0075 else
0076 {
0077 angle_x -= CLHEP::pi;
0078 }
0079 if (momentumDirection.getY() > 0)
0080 {
0081 angle_y += CLHEP::pi;
0082 }
0083 else
0084 {
0085 angle_y -= CLHEP::pi;
0086 }
0087 }
0088
0089
0090 G4double ekin = step->GetPreStepPoint()->GetKineticEnergy()/CLHEP::MeV;
0091
0092
0093 G4String particleName =
0094 step->GetTrack()->GetDefinition()->GetParticleName();
0095 G4int particleID = step->GetTrack()->GetTrackID();
0096 G4int parentID = step->GetTrack()->GetParentID();
0097
0098
0099 G4int eventID =
0100 G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
0101
0102
0103 G4int iTuple = 0;
0104 if(volumeName=="Crystal")
0105 {
0106 iTuple = 0;
0107 }
0108 else if(volumeName=="Detector")
0109 {
0110 if(particleName=="gamma")
0111 {
0112 iTuple = 2;
0113 }
0114 else
0115 {
0116 iTuple = 1;
0117 }
0118 }
0119
0120
0121 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0122 analysisManager->FillNtupleIColumn(iTuple,0,eventID);
0123 analysisManager->FillNtupleSColumn(iTuple,1,volumeName);
0124 analysisManager->FillNtupleDColumn(iTuple,2,x0);
0125 analysisManager->FillNtupleDColumn(iTuple,3,y0);
0126 analysisManager->FillNtupleDColumn(iTuple,4,angle_x);
0127 analysisManager->FillNtupleDColumn(iTuple,5,angle_y);
0128 analysisManager->FillNtupleDColumn(iTuple,6,ekin);
0129 analysisManager->FillNtupleSColumn(iTuple,7,particleName);
0130 analysisManager->FillNtupleIColumn(iTuple,8,particleID);
0131 analysisManager->FillNtupleIColumn(iTuple,9,parentID);
0132 analysisManager->AddNtupleRow(iTuple);
0133 }
0134 }
0135
0136
0137
0138