CMS 3D CMS Logo

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