File indexing completed on 2026-09-19 08:37:49
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 "G4HadronicProcess.hh"
0035 #include "G4ParticleTypes.hh"
0036 #include "G4RunManager.hh"
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046 void SteppingAction::UserSteppingAction(const G4Step* aStep)
0047 {
0048
0049 G4int trackID = aStep->GetTrack()->GetTrackID();
0050 G4int stepNb = aStep->GetTrack()->GetCurrentStepNumber();
0051 if (trackID * stepNb != 1) return;
0052
0053
0054 Run* run = static_cast<Run*>(G4RunManager::GetRunManager()->GetNonConstCurrentRun());
0055
0056
0057
0058 const G4StepPoint* endPoint = aStep->GetPostStepPoint();
0059 G4VProcess* process = const_cast<G4VProcess*>(endPoint->GetProcessDefinedStep());
0060 run->CountProcesses(process);
0061
0062
0063 G4StepStatus stepStatus = endPoint->GetStepStatus();
0064 G4bool transmit = (stepStatus == fGeomBoundary || stepStatus == fWorldBoundary);
0065 if (transmit) return;
0066
0067
0068
0069 G4double stepLength = aStep->GetStepLength();
0070 run->SumTrack(stepLength);
0071
0072
0073
0074 const G4StepPoint* prePoint = aStep->GetPreStepPoint();
0075 G4double Q = -prePoint->GetKineticEnergy();
0076 G4ThreeVector Pbalance = -prePoint->GetMomentum();
0077
0078
0079
0080 G4ParticleDefinition* particle = aStep->GetTrack()->GetDefinition();
0081 G4String partName = particle->GetParticleName();
0082 G4String nuclearChannel = partName;
0083 G4HadronicProcess* hproc = dynamic_cast<G4HadronicProcess*>(process);
0084 const G4Isotope* target = NULL;
0085 if (hproc) target = hproc->GetTargetIsotope();
0086 G4String targetName = "XXXX";
0087 if (target) targetName = target->GetName();
0088 nuclearChannel += " + " + targetName + " --> ";
0089 if (targetName == "XXXX") run->SetTargetXXX(true);
0090
0091
0092
0093 G4AnalysisManager* analysis = G4AnalysisManager::Instance();
0094 G4int ih = 1;
0095 if (aStep->GetTrack()->GetTrackStatus() == fAlive) {
0096 G4double energy = endPoint->GetKineticEnergy();
0097 analysis->FillH1(ih, energy);
0098
0099 G4ThreeVector momentum = endPoint->GetMomentum();
0100 Q += energy;
0101 Pbalance += momentum;
0102
0103 nuclearChannel += partName + " + ";
0104 }
0105
0106
0107
0108 const std::vector<const G4Track*>* secondary = aStep->GetSecondaryInCurrentStep();
0109 for (size_t lp = 0; lp < (*secondary).size(); lp++) {
0110 particle = (*secondary)[lp]->GetDefinition();
0111 G4String name = particle->GetParticleName();
0112 G4String type = particle->GetParticleType();
0113 G4double energy = (*secondary)[lp]->GetKineticEnergy();
0114 run->ParticleCount(name, energy);
0115
0116 ih = 0;
0117 if (particle == G4Gamma::Gamma())
0118 ih = 2;
0119 else if (particle == G4Electron::Electron())
0120 ih = 3;
0121 else if (particle == G4Neutron::Neutron())
0122 ih = 4;
0123 else if (particle == G4Proton::Proton())
0124 ih = 5;
0125 else if (particle == G4Deuteron::Deuteron())
0126 ih = 6;
0127 else if (particle == G4Alpha::Alpha())
0128 ih = 7;
0129 else if (type == "nucleus")
0130 ih = 8;
0131 else if (type == "meson")
0132 ih = 9;
0133 else if (type == "baryon")
0134 ih = 10;
0135 if (ih > 0) analysis->FillH1(ih, energy);
0136
0137 if (type == "nucleus") {
0138 G4int A = particle->GetAtomicMass();
0139 analysis->FillH1(13, A);
0140 }
0141
0142 G4ThreeVector momentum = (*secondary)[lp]->GetMomentum();
0143 Q += energy;
0144 Pbalance += momentum;
0145
0146 if (particle == G4Electron::Electron()) particle = G4Gamma::Gamma();
0147
0148 fParticleFlag[particle]++;
0149 }
0150
0151
0152 G4double Pbal = Pbalance.mag();
0153 run->Balance(Pbal);
0154 ih = 11;
0155 analysis->FillH1(ih, Q);
0156 ih = 12;
0157 analysis->FillH1(ih, Pbal);
0158
0159
0160 const G4int kMax = 16;
0161 const G4String conver[] = {"0", "", "2 ", "3 ", "4 ", "5 ", "6 ", "7 ", "8 ",
0162 "9 ", "10 ", "11 ", "12 ", "13 ", "14 ", "15 ", "16 "};
0163 std::map<G4ParticleDefinition*, G4int>::iterator ip;
0164 for (ip = fParticleFlag.begin(); ip != fParticleFlag.end(); ip++) {
0165 particle = ip->first;
0166 G4String name = particle->GetParticleName();
0167 G4int nb = ip->second;
0168 if (nb > kMax) nb = kMax;
0169 G4String Nb = conver[nb];
0170 if (particle == G4Gamma::Gamma()) {
0171 run->CountGamma(nb);
0172 Nb = "N ";
0173 name = "gamma or e-";
0174 }
0175 if (ip != fParticleFlag.begin()) nuclearChannel += " + ";
0176 nuclearChannel += Nb + name;
0177 }
0178
0179
0180 run->CountNuclearChannel(nuclearChannel, Q);
0181
0182 fParticleFlag.clear();
0183
0184
0185
0186 G4RunManager::GetRunManager()->AbortEvent();
0187 }
0188
0189