File indexing completed on 2025-02-23 09:22:32
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
0031 #include "Par01PionShowerModel.hh"
0032
0033 #include "Par01EnergySpot.hh"
0034
0035 #include "G4Colour.hh"
0036 #include "G4PhysicalConstants.hh"
0037 #include "G4PionMinus.hh"
0038 #include "G4PionPlus.hh"
0039 #include "G4SystemOfUnits.hh"
0040 #include "G4TouchableHistory.hh"
0041 #include "G4TransportationManager.hh"
0042 #include "G4VSensitiveDetector.hh"
0043 #include "Randomize.hh"
0044
0045
0046
0047 Par01PionShowerModel::Par01PionShowerModel(G4String modelName, G4Region* envelope)
0048 : G4VFastSimulationModel(modelName, envelope)
0049 {
0050 fFakeStep = new G4Step();
0051 fFakePreStepPoint = fFakeStep->GetPreStepPoint();
0052 fFakePostStepPoint = fFakeStep->GetPostStepPoint();
0053 fTouchableHandle = new G4TouchableHistory();
0054 fpNavigator = new G4Navigator();
0055 fNaviSetup = false;
0056 }
0057
0058
0059
0060 Par01PionShowerModel::Par01PionShowerModel(G4String modelName) : G4VFastSimulationModel(modelName)
0061 {
0062 fFakeStep = new G4Step();
0063 fFakePreStepPoint = fFakeStep->GetPreStepPoint();
0064 fFakePostStepPoint = fFakeStep->GetPostStepPoint();
0065 fTouchableHandle = new G4TouchableHistory();
0066 fpNavigator = new G4Navigator();
0067 fNaviSetup = false;
0068 }
0069
0070
0071
0072 Par01PionShowerModel::~Par01PionShowerModel()
0073 {
0074 delete fFakeStep;
0075 delete fpNavigator;
0076 }
0077
0078
0079
0080 G4bool Par01PionShowerModel::IsApplicable(const G4ParticleDefinition& particleType)
0081 {
0082 return &particleType == G4PionMinus::PionMinusDefinition()
0083 || &particleType == G4PionPlus::PionPlusDefinition();
0084 }
0085
0086
0087
0088 G4bool Par01PionShowerModel::ModelTrigger(const G4FastTrack&)
0089 {
0090
0091
0092 return true;
0093 }
0094
0095
0096
0097 void Par01PionShowerModel::DoIt(const G4FastTrack& fastTrack, G4FastStep& fastStep)
0098 {
0099
0100
0101
0102 fastStep.KillPrimaryTrack();
0103 fastStep.ProposePrimaryTrackPathLength(0.0);
0104 fastStep.ProposeTotalEnergyDeposited(fastTrack.GetPrimaryTrack()->GetKineticEnergy());
0105
0106
0107 Explode(fastTrack);
0108
0109
0110 BuildDetectorResponse();
0111 }
0112
0113
0114
0115 void Par01PionShowerModel::Explode(const G4FastTrack& fastTrack)
0116 {
0117
0118
0119
0120
0121
0122
0123 G4ThreeVector showerCenter;
0124 G4double distOut;
0125 distOut = fastTrack.GetEnvelopeSolid()->DistanceToOut(fastTrack.GetPrimaryTrackLocalPosition(),
0126 fastTrack.GetPrimaryTrackLocalDirection());
0127 showerCenter = fastTrack.GetPrimaryTrackLocalPosition()
0128 + (distOut / 2.) * fastTrack.GetPrimaryTrackLocalDirection();
0129
0130 showerCenter = fastTrack.GetInverseAffineTransformation()->TransformPoint(showerCenter);
0131
0132
0133 G4ThreeVector xShower, yShower, zShower;
0134 zShower = fastTrack.GetPrimaryTrack()->GetMomentumDirection();
0135 xShower = zShower.orthogonal();
0136 yShower = zShower.cross(xShower);
0137
0138
0139 G4double Energy = fastTrack.GetPrimaryTrack()->GetKineticEnergy();
0140 G4int nSpot = 50;
0141 G4double deposit = Energy / double(nSpot);
0142 Par01EnergySpot eSpot;
0143 eSpot.SetEnergy(deposit);
0144 G4ThreeVector ePoint;
0145
0146
0147 feSpotList.clear();
0148
0149 G4double z, r, phi;
0150 for (int i = 0; i < nSpot; i++) {
0151 z = G4RandGauss::shoot(0, 20 * cm);
0152 r = G4RandGauss::shoot(0, 10 * cm);
0153 phi = G4UniformRand() * twopi;
0154 ePoint = showerCenter + z * zShower + r * std::cos(phi) * xShower + r * std::sin(phi) * yShower;
0155 eSpot.SetPosition(ePoint);
0156 feSpotList.push_back(eSpot);
0157 }
0158 }
0159
0160
0161
0162 void Par01PionShowerModel::BuildDetectorResponse()
0163 {
0164
0165 for (size_t i = 0; i < feSpotList.size(); i++) {
0166
0167
0168
0169
0170
0171
0172
0173 AssignSpotAndCallHit(feSpotList[i]);
0174 }
0175 }
0176
0177
0178
0179 void Par01PionShowerModel::AssignSpotAndCallHit(const Par01EnergySpot& eSpot)
0180 {
0181
0182
0183
0184
0185 FillFakeStep(eSpot);
0186
0187
0188
0189
0190
0191 G4VPhysicalVolume* pCurrentVolume = fFakeStep->GetPreStepPoint()->GetPhysicalVolume();
0192 G4VSensitiveDetector* pSensitive;
0193
0194 if (pCurrentVolume != nullptr) {
0195 pSensitive = pCurrentVolume->GetLogicalVolume()->GetSensitiveDetector();
0196 if (pSensitive != nullptr) {
0197 pSensitive->Hit(fFakeStep);
0198 }
0199 }
0200 }
0201
0202
0203
0204 void Par01PionShowerModel::FillFakeStep(const Par01EnergySpot& eSpot)
0205 {
0206
0207
0208
0209 if (!fNaviSetup) {
0210 fpNavigator->SetWorldVolume(G4TransportationManager::GetTransportationManager()
0211 ->GetNavigatorForTracking()
0212 ->GetWorldVolume());
0213 fpNavigator->LocateGlobalPointAndUpdateTouchableHandle(
0214 eSpot.GetPosition(), G4ThreeVector(0., 0., 0.), fTouchableHandle, false);
0215 fNaviSetup = true;
0216 }
0217 else {
0218 fpNavigator->LocateGlobalPointAndUpdateTouchableHandle(
0219 eSpot.GetPosition(), G4ThreeVector(0., 0., 0.), fTouchableHandle);
0220 }
0221
0222
0223
0224
0225
0226 fFakePreStepPoint->SetTouchableHandle(fTouchableHandle);
0227
0228 fFakeStep->SetTotalEnergyDeposit(eSpot.GetEnergy());
0229 }