File indexing completed on 2026-04-29 07:38:52
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 "SteppingAction.hh"
0030
0031 #include "HistoManager.hh"
0032 #include "Run.hh"
0033
0034 #include "G4EmProcessSubType.hh"
0035 #include "G4ParticleTypes.hh"
0036 #include "G4RunManager.hh"
0037 #include "G4SteppingManager.hh"
0038 #include "G4SystemOfUnits.hh"
0039 #include "G4UnitsTable.hh"
0040 #include "G4VProcess.hh"
0041
0042
0043
0044 SteppingAction::SteppingAction() : G4UserSteppingAction() {}
0045
0046
0047
0048 void SteppingAction::UserSteppingAction(const G4Step* aStep)
0049 {
0050 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0051
0052 const G4VProcess* process = aStep->GetPostStepPoint()->GetProcessDefinedStep();
0053 if (process == nullptr) return;
0054
0055 G4int eventID = G4RunManager::GetRunManager()->GetCurrentEvent()->GetEventID();
0056 G4Track* trk = aStep->GetTrack();
0057
0058 thread_local G4int iCalled = 0;
0059 const G4int nprint = 10;
0060 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
0061
0062 if (fSynchrotronRadiation == process->GetProcessSubType()) {
0063 const G4StepPoint* PrePoint = aStep->GetPreStepPoint();
0064 const G4TrackVector* secondary = fpSteppingManager->GetSecondary();
0065 size_t lp = (*secondary).size();
0066 if (lp) {
0067 G4double Egamma = (*secondary)[lp - 1]->GetTotalEnergy();
0068 run->f_n_gam_sync++;
0069 run->f_e_gam_sync += Egamma;
0070 run->f_e_gam_sync2 += Egamma * Egamma;
0071 if (Egamma > run->f_e_gam_sync_max) run->f_e_gam_sync_max = Egamma;
0072 run->f_lam_gam_sync += aStep->GetStepLength();
0073 if (iCalled < nprint) {
0074 G4double Eelec = PrePoint->GetTotalEnergy();
0075 G4ThreeVector Pelec = PrePoint->GetMomentum();
0076 G4ThreeVector PGamma = (*secondary)[lp - 1]->GetMomentum();
0077 G4bool IsGamma = ((*secondary)[lp - 1]->GetDefinition() == G4Gamma::Gamma());
0078 const G4int wid = 8;
0079 if (analysisManager->GetVerboseLevel() > 1 && iCalled < nprint)
0080 G4cout << __FILE__ << " line " << __LINE__ << " " << __FUNCTION__
0081 << " processName=" << process->GetProcessName()
0082 << " Step Length=" << std::setw(wid)
0083 << G4BestUnit(aStep->GetStepLength(), "Length") << " Eelec=" << std::setw(wid)
0084 << G4BestUnit(Eelec, "Energy") << " Pelec=" << G4BestUnit(Pelec, "Energy")
0085 << " IsGamma=" << IsGamma << " Egamma=" << std::setw(8)
0086 << G4BestUnit(Egamma, "Energy") << " PGamma=" << std::setw(8)
0087 << G4BestUnit(PGamma, "Energy") << " #secondaries lp=" << lp << '\n';
0088 }
0089 analysisManager->FillH1(1, Egamma);
0090 analysisManager->FillH1(2, Egamma,
0091 Egamma / keV);
0092 analysisManager->FillH1(3, aStep->GetStepLength());
0093 }
0094 }
0095
0096 thread_local G4ThreeVector IncomingPhotonDirection;
0097 if (fGammaReflection == process->GetProcessSubType()) {
0098 const G4TrackVector* secondary = fpSteppingManager->GetSecondary();
0099 size_t lp = (*secondary).size();
0100 if (lp) {
0101 G4double Egamma = (*secondary)[lp - 1]->GetTotalEnergy();
0102 ++run->f_n_Xray_Refl;
0103 analysisManager->FillH1(1, Egamma, 1. / run->GetNumberOfEventToBeProcessed());
0104 if (analysisManager->GetVerboseLevel() > 1 && run->f_n_Xray_Refl < nprint)
0105 G4cout << __FILE__ << " line " << __LINE__ << " " << __FUNCTION__
0106 << " iCalled=" << std::setw(3) << iCalled << " eventID=" << std::setw(3) << eventID
0107 << " f_n_Xray_Refl=" << run->f_n_Xray_Refl
0108 << " ProcessName=" << process->GetProcessName()
0109 << " direction=" << trk->GetMomentumDirection() << " Egamma=" << Egamma / keV
0110 << " keV" << G4endl;
0111 IncomingPhotonDirection = trk->GetMomentumDirection();
0112 }
0113 }
0114
0115 const G4VProcess* creator = trk->GetCreatorProcess();
0116 G4int CreatorProcessSubType = 0;
0117 if (creator != nullptr) CreatorProcessSubType = creator->GetProcessSubType();
0118 if (CreatorProcessSubType == fGammaReflection) {
0119 if (IncomingPhotonDirection != G4ThreeVector(0, 0, 0)) {
0120 G4double cos_angle =
0121 IncomingPhotonDirection * trk->GetMomentumDirection();
0122 G4double IncidentAngle = std::acos(cos_angle) / 2.;
0123 analysisManager->FillH1(4, IncidentAngle, 1. / run->GetNumberOfEventToBeProcessed());
0124 if (analysisManager->GetVerboseLevel() > 1 && iCalled < nprint)
0125 G4cout << __FILE__ << " line " << __LINE__ << " " << __FUNCTION__
0126 << " iCalled=" << std::setw(3) << iCalled << " eventID=" << std::setw(3) << eventID
0127 << " CreatorProcname=" << creator->GetProcessName()
0128 << " ProcessName=" << process->GetProcessName()
0129 << " IncomingPhotonDirection=" << IncomingPhotonDirection
0130 << " outgoing PhotonDirection=" << trk->GetMomentumDirection()
0131 << " IncidentAngle=" << IncidentAngle
0132 << " NumberOfEventToBeProcessed=" << run->GetNumberOfEventToBeProcessed()
0133 << " RunID=" << run->GetRunID() << G4endl;
0134 }
0135 }
0136
0137 ++iCalled;
0138 }
0139
0140