CMS 3D CMS Logo

GflashHadronWrapperProcess.cc
Go to the documentation of this file.
1 //
2 // S.Y. Jun, August 2007
3 //
5 
6 #include "G4ios.hh"
7 #include "G4GPILSelection.hh"
8 #include "G4ProcessManager.hh"
9 #include "G4ProcessVector.hh"
10 #include "G4Track.hh"
11 #include "G4VParticleChange.hh"
12 #include "G4VProcess.hh"
13 
14 using namespace CLHEP;
15 
17  : particleChange(nullptr), pmanager(nullptr), fProcessVector(nullptr), fProcess(nullptr) {
19 }
20 
22 
23 G4VParticleChange *GflashHadronWrapperProcess::PostStepDoIt(const G4Track &track, const G4Step &step) {
24  // process PostStepDoIt for the original process
25 
26  particleChange = pRegProcess->PostStepDoIt(track, step);
27 
28  // specific actions of the wrapper process
29 
30  // update step/track information after PostStep of the original process is
31  // done these steps will be repeated again without additional conflicts even
32  // if the parameterized physics process doesn't take over the original process
33 
34  particleChange->UpdateStepForPostStep(const_cast<G4Step *>(&step));
35 
36  // we may not want to update G4Track during this wrapper process if
37  // G4Track accessors are not used in the G4VFastSimulationModel model
38  // (const_cast<G4Step *> (&step))->UpdateTrack();
39 
40  // update safety after each invocation of PostStepDoIts
41  // G4double safety = std::max(endpointSafety - (endpointSafOrigin -
42  // fPostStepPoint->GetPosition()).mag(),0.);
43  // step.GetPostStepPoint()->SetSafety(safety);
44 
45  // the secondaries from the original process are also created at the wrapper
46  // process, but they must be deleted whether the parameterized physics is
47  // an 'ExclusivelyForced' process or not. Normally the secondaries will be
48  // created after this wrapper process in G4SteppingManager::InvokePSDIP
49 
50  // store the secondaries from ParticleChange to SecondaryList
51 
52  G4TrackVector *fSecondary = (const_cast<G4Step *>(&step))->GetfSecondary();
53  G4int nSecondarySave = fSecondary->size();
54 
55  G4int num2ndaries = particleChange->GetNumberOfSecondaries();
56  G4Track *tempSecondaryTrack;
57 
58  for (G4int DSecLoop = 0; DSecLoop < num2ndaries; DSecLoop++) {
59  tempSecondaryTrack = particleChange->GetSecondary(DSecLoop);
60 
61  // Set the process pointer which created this track
62  tempSecondaryTrack->SetCreatorProcess(pRegProcess);
63 
64  // add secondaries from this wrapper process to the existing list
65  fSecondary->push_back(tempSecondaryTrack);
66 
67  } // end of loop on secondary
68 
69  // Now we can still impose conditions on the secondaries from ModelTrigger,
70  // such as the number of secondaries produced by the original process as well
71  // as those by other continuous processes - for the hadronic inelastic
72  // interaction, it is always true that
73  // particleChange->GetNumberOfSecondaries() > 0
74 
75  // at this stage, updated step information after all processes involved
76  // should be available
77 
78  // Print(step);
79 
80  // call ModelTrigger for the second time - the primary loop of PostStepGPIL
81  // is inside G4SteppingManager::DefinePhysicalStepLength().
82 
83  pmanager = track.GetDefinition()->GetProcessManager();
84 
85  G4double testGPIL = DBL_MAX;
86  G4double fStepLength = 0.0;
87  G4ForceCondition fForceCondition = InActivated;
88 
89  fStepLength = step.GetStepLength();
90 
91  fProcessVector = pmanager->GetPostStepProcessVector(typeDoIt);
92 
93  // keep the current status of track, use fPostponeToNextEvent word for
94  // this particular PostStep GPIL and then restore G4TrackStatus if the
95  // paramterized physics doesn't meet trigger conditions in ModelTrigger
96 
97  const G4TrackStatus keepStatus = track.GetTrackStatus();
98 
99  (const_cast<G4Track *>(&track))->SetTrackStatus(fPostponeToNextEvent);
100  int fpv_entries = fProcessVector->entries();
101  for (G4int ipm = 0; ipm < fpv_entries; ipm++) {
102  fProcess = (*fProcessVector)(ipm);
103 
104  if (fProcess->GetProcessType() == fParameterisation) {
105  // test ModelTrigger via PostStepGPIL
106 
107  testGPIL = fProcess->PostStepGPIL(track, fStepLength, &fForceCondition);
108 
109  // if G4FastSimulationModel:: ModelTrigger is true, then the parameterized
110  // physics process takes over the current process
111 
112  if (fForceCondition == ExclusivelyForced) {
113  // clean up memory for changing the process - counter clean up for
114  // the secondaries created by new G4Track in
115  // G4HadronicProcess::FillTotalResult
116  G4int nsec = particleChange->GetNumberOfSecondaries();
117  for (G4int DSecLoop = 0; DSecLoop < nsec; DSecLoop++) {
118  G4Track *tempSecondaryTrack = particleChange->GetSecondary(DSecLoop);
119  delete tempSecondaryTrack;
120  }
121  particleChange->Clear();
122 
123  // updating G4Step between PostStepGPIL and PostStepDoIt for the
124  // parameterized process may not be necessary, but do it anyway
125 
126  (const_cast<G4Step *>(&step))->SetStepLength(testGPIL);
127  (const_cast<G4Track *>(&track))->SetStepLength(testGPIL);
128 
129  step.GetPostStepPoint()->SetStepStatus(fExclusivelyForcedProc);
130  ;
131  step.GetPostStepPoint()->SetProcessDefinedStep(fProcess);
132  step.GetPostStepPoint()->SetSafety(0.0);
133 
134  // invoke PostStepDoIt: equivalent steps for
135  // G4SteppingManager::InvokePSDIP
136  particleChange = fProcess->PostStepDoIt(track, step);
137 
138  // update PostStepPoint of Step according to ParticleChange
139  particleChange->UpdateStepForPostStep(const_cast<G4Step *>(&step));
140 
141  // update G4Track according to ParticleChange after each PostStepDoIt
142  (const_cast<G4Step *>(&step))->UpdateTrack();
143 
144  // update safety after each invocation of PostStepDoIts - acutally this
145  // is not necessary for the parameterized physics process, but do it
146  // anyway
147  step.GetPostStepPoint()->SetSafety(0.0);
148 
149  // additional nullification
150  (const_cast<G4Track *>(&track))->SetTrackStatus(particleChange->GetTrackStatus());
151  } else {
152  // restore TrackStatus if fForceCondition != ExclusivelyForced
153  (const_cast<G4Track *>(&track))->SetTrackStatus(keepStatus);
154  }
155  // assume that there is one and only one parameterized physics
156  break;
157  }
158  }
159 
160  // remove secondaries of this wrapper process that were added to the secondary
161  // list since they will be added in the normal stepping procedure after
162  // this->PostStepDoIt in G4SteppingManager::InvokePSDIP
163 
164  // move the iterator to the (nSecondarySave+1)th element in the secondary list
165  G4TrackVector::iterator itv = fSecondary->begin();
166  itv += nSecondarySave;
167 
168  // delete next num2ndaries tracks from the secondary list
169  fSecondary->erase(itv, itv + num2ndaries);
170 
171  // end of specific actions of this wrapper process
172 
173  return particleChange;
174 }
175 
177  G4cout << " GflashHadronWrapperProcess ProcessName, PreStepPosition, preStepPoint KE, PostStepPoint KE, DeltaEnergy "
178  "Nsec \n "
179  << step.GetPostStepPoint()->GetProcessDefinedStep()->GetProcessName() << " "
180  << step.GetPostStepPoint()->GetPosition() << " " << step.GetPreStepPoint()->GetKineticEnergy() / CLHEP::GeV
181  << " " << step.GetPostStepPoint()->GetKineticEnergy() / CLHEP::GeV << " " << step.GetDeltaEnergy() / CLHEP::GeV
182  << " " << particleChange->GetNumberOfSecondaries() << G4endl;
183 }
GflashHadronWrapperProcess(G4String processName)
G4VParticleChange * PostStepDoIt(const G4Track &track, const G4Step &step) override
step
Definition: StallMonitor.cc:83