Warning, file /geant4/examples/extended/hadronic/ParticleFluence/Layer/src/SteppingAction.cc was not indexed
or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).
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 "Run.hh"
0032
0033 #include "G4IonTable.hh"
0034 #include "G4LossTableManager.hh"
0035 #include "G4ParticleDefinition.hh"
0036 #include "G4ParticleTypes.hh"
0037 #include "G4Step.hh"
0038 #include "G4StepPoint.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4TouchableHistory.hh"
0041 #include "G4Track.hh"
0042 #include "G4VPhysicalVolume.hh"
0043 #include "G4VSolid.hh"
0044 #include "G4VTouchable.hh"
0045
0046 const std::array<G4String, SteppingAction::fkNumberScoringVolumes>
0047 SteppingAction::fkArrayScoringVolumeNames = {"downstream", "side", "upstream"};
0048
0049 const std::array<G4String, SteppingAction::fkNumberKinematicRegions>
0050 SteppingAction::fkArrayKinematicRegionNames = {"", "below 20 MeV", "above 20 MeV"};
0051
0052 const std::array<G4String, SteppingAction::fkNumberParticleTypes>
0053 SteppingAction::fkArrayParticleTypeNames = {"all", "electron", "gamma", "muon",
0054 "neutrino", "pion", "neutron", "proton",
0055 "ion", "otherMeson", "otherBaryon"};
0056
0057
0058
0059 G4int SteppingAction::GetIndex(const G4int iScoringVolume, const G4int iKinematicRegion,
0060 const G4int iParticleType)
0061 {
0062 G4int index = -1;
0063 if (iScoringVolume >= 0 && iScoringVolume < fkNumberScoringVolumes && iKinematicRegion >= 0
0064 && iKinematicRegion < fkNumberKinematicRegions && iParticleType >= 0
0065 && iParticleType < fkNumberParticleTypes)
0066 {
0067 index = iScoringVolume * fkNumberKinematicRegions * fkNumberParticleTypes
0068 + iKinematicRegion * fkNumberParticleTypes + iParticleType;
0069 }
0070 if (index < 0 || index >= fkNumberCombinations) {
0071 G4cerr << "SteppingAction::GetIndex : WRONG index=" << index << " set it to 0 !" << G4endl;
0072 index = 0;
0073 }
0074 return index;
0075 }
0076
0077
0078
0079 SteppingAction::SteppingAction() : G4UserSteppingAction()
0080 {
0081 Initialize();
0082 }
0083
0084
0085
0086 void SteppingAction::Initialize()
0087 {
0088
0089 fPrimaryParticleId = 0;
0090 fPrimaryParticleEnergy = 0.0;
0091 fPrimaryParticleDirection = G4ThreeVector(0.0, 0.0, 1.0);
0092 fTargetMaterialName = "";
0093 fIsFirstStepOfTheEvent = true;
0094 fIsFirstStepInTarget = true;
0095 fIsFirstStepInScoringUpDown = true;
0096 fIsFirstStepInScoringSide = true;
0097 fCubicVolumeScoringUpDown = 1.0;
0098 fCubicVolumeScoringSide = 1.0;
0099 for (G4int i = 0; i < fkNumberCombinations; ++i) {
0100 fArraySumStepLengths[i] = 0.0;
0101 }
0102
0103
0104
0105
0106
0107
0108
0109
0110
0111
0112
0113
0114
0115
0116
0117
0118
0119
0120 }
0121
0122
0123
0124 void SteppingAction::UserSteppingAction(const G4Step* theStep)
0125 {
0126
0127 if (fIsFirstStepOfTheEvent) {
0128 if (theStep->GetTrack()->GetParentID() == 0) {
0129 fPrimaryParticleId = theStep->GetTrack()->GetDefinition()->GetPDGEncoding();
0130 fPrimaryParticleEnergy = theStep->GetPreStepPoint()->GetKineticEnergy();
0131 fPrimaryParticleDirection = theStep->GetPreStepPoint()->GetMomentumDirection();
0132 if (fRunPtr) {
0133 fRunPtr->SetPrimaryParticleId(fPrimaryParticleId);
0134 fRunPtr->SetPrimaryParticleEnergy(fPrimaryParticleEnergy);
0135 fRunPtr->SetPrimaryParticleDirection(fPrimaryParticleDirection);
0136 }
0137 fIsFirstStepOfTheEvent = false;
0138 }
0139 }
0140
0141 if (fIsFirstStepInTarget
0142 && theStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() == "physiLayer")
0143 {
0144 fTargetMaterialName = theStep->GetPreStepPoint()->GetMaterial()->GetName();
0145 if (fRunPtr) fRunPtr->SetTargetMaterialName(fTargetMaterialName);
0146 fIsFirstStepInTarget = false;
0147 }
0148
0149 G4int iScoringVolume = -1;
0150 if (theStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() == "physiScoringDownstream") {
0151 iScoringVolume = 0;
0152 if (fIsFirstStepInScoringUpDown) {
0153 fCubicVolumeScoringUpDown =
0154 theStep->GetTrack()->GetVolume()->GetLogicalVolume()->GetSolid()->GetCubicVolume();
0155 if (fRunPtr) fRunPtr->SetCubicVolumeScoringUpDown(fCubicVolumeScoringUpDown);
0156 fIsFirstStepInScoringUpDown = false;
0157 }
0158 }
0159 else if (theStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() == "physiScoringSide") {
0160 iScoringVolume = 1;
0161 if (fIsFirstStepInScoringSide) {
0162 fCubicVolumeScoringSide =
0163 theStep->GetTrack()->GetVolume()->GetLogicalVolume()->GetSolid()->GetCubicVolume();
0164 if (fRunPtr) fRunPtr->SetCubicVolumeScoringSide(fCubicVolumeScoringSide);
0165 fIsFirstStepInScoringSide = false;
0166 }
0167 }
0168 else if (theStep->GetPreStepPoint()->GetPhysicalVolume()->GetName() == "physiScoringUpstream") {
0169 iScoringVolume = 2;
0170 if (fIsFirstStepInScoringUpDown) {
0171 fCubicVolumeScoringUpDown =
0172 theStep->GetTrack()->GetVolume()->GetLogicalVolume()->GetSolid()->GetCubicVolume();
0173 if (fRunPtr) fRunPtr->SetCubicVolumeScoringUpDown(fCubicVolumeScoringUpDown);
0174 fIsFirstStepInScoringUpDown = false;
0175 }
0176 }
0177 if (iScoringVolume >= 0) {
0178
0179
0180
0181 if (iScoringVolume == 2
0182 && fPrimaryParticleDirection.dot(theStep->GetPreStepPoint()->GetMomentumDirection()) > 0.0)
0183 {
0184 return;
0185 }
0186 G4double stepLength = theStep->GetTrack()->GetStepLength() * theStep->GetTrack()->GetWeight();
0187 G4int absPdg = theStep->GetTrack()->GetDefinition() == nullptr
0188 ? 0
0189 : std::abs(theStep->GetTrack()->GetDefinition()->GetPDGEncoding());
0190
0191
0192
0193
0194
0195
0196
0197
0198
0199
0200
0201
0202
0203
0204
0205 G4int iKinematicRegion = theStep->GetPreStepPoint()->GetKineticEnergy() < 20.0 ? 1 : 2;
0206 G4int iParticleType = -1;
0207 if (absPdg == 11)
0208 iParticleType = 1;
0209 else if (absPdg == 22)
0210 iParticleType = 2;
0211 else if (absPdg == 13)
0212 iParticleType = 3;
0213 else if (absPdg == 12 || absPdg == 14 || absPdg == 16)
0214 iParticleType = 4;
0215
0216 else if (absPdg == 111 || absPdg == 211)
0217 iParticleType = 5;
0218 else if (absPdg == 2112)
0219 iParticleType = 6;
0220 else if (absPdg == 2212)
0221 iParticleType = 7;
0222 else if (G4IonTable::IsIon(theStep->GetTrack()->GetDefinition()) ||
0223 G4IonTable::IsAntiIon(theStep->GetTrack()->GetDefinition()))
0224 iParticleType = 8;
0225 else if (absPdg < 1000)
0226 iParticleType = 9;
0227
0228 else if (absPdg > 1000)
0229 iParticleType = 10;
0230
0231
0232 G4int index = GetIndex(iScoringVolume, iKinematicRegion, iParticleType);
0233 fArraySumStepLengths[index] += stepLength;
0234
0235 index = GetIndex(iScoringVolume, iKinematicRegion, 0);
0236 fArraySumStepLengths[index] += stepLength;
0237
0238 index = GetIndex(iScoringVolume, 0, iParticleType);
0239 fArraySumStepLengths[index] += stepLength;
0240
0241 index = GetIndex(iScoringVolume, 0, 0);
0242 fArraySumStepLengths[index] += stepLength;
0243 if (fRunPtr) fRunPtr->SetSteppingArray(fArraySumStepLengths);
0244 }
0245 }
0246
0247