Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4AdjointForcedInteractionForGamma.cc
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // $Id: G4AdjointForcedInteractionForGamma.cc 87443 2014-12-04 12:26:31Z gunter $
27 //
29 #include "G4SystemOfUnits.hh"
30 #include "G4AdjointCSManager.hh"
31 #include "G4AdjointCSMatrix.hh"
32 #include "G4VEmAdjointModel.hh"
33 #include "G4MaterialCutsCouple.hh"
34 #include "G4ParticleChange.hh"
35 #include "G4AdjointGamma.hh"
36 
37 
40  G4VContinuousDiscreteProcess(process_name),theAdjointComptonModel(0),theAdjointBremModel(0)
43  lastAdjCS=0.;
44  trackid = nstep = 0;
45  is_free_flight_gamma = false;
48 
51 
58 
59 
60 
61 }
63 //
66 { if (fParticleChange) delete fParticleChange;
67 }
69 //
71 {;
72 }
74 //
76 {
77  theAdjointCSManager->BuildCrossSectionMatrices(); //do not worry it will be done just once
79 }
80 //Note on weight correction for forced interaction
81 //For the forced interaction applied here we do use a truncated exponential law for the probability of survival
82 //over a fixed total length. This is done by using a linear transformation of the non biased probability survival
83 //In mathematic this writes
84 //P'(x)=C1P(x)+C2
85 //With P(x)=exp(-sum(sigma_ixi)) x and L can cross different volumes with different cross section sigma.
86 //For forced interaction we get the following limit conditions
87 //P'(L)=0 P'(0)=1 (L can be used over different volumes)
88 //From simple solving of linear equation we get
89 //C1=1/(1-P(L)) et C2=-P(L)/(1-P(L))
90 //P'(x)=(P(x)-P(L))/(1-P(L))
91 //For the probability over a step x1 to x2
92 //P'(x1->x2)=P'(x2)/P'(x1)
93 //The effective cross section is defined -d(P'(x))/dx/P'(x)
94 //We get therefore
95 //sigma_eff=C1sigmaP(x)/(C1P(x)+C2)=sigmaP(x)/(P(x)+C2/C1)=sigmaP(x)/(P(x)-P(L))=sigma/(1-P(L)/P(x))
97 //
99 { fParticleChange->Initialize(track);
100  //For the free flight gamma no interaction occur but a gamma with same property is
101  //produces for further forced interaction
102  //It is done at the very beginning of the track such that the weight can be the same
104  G4ThreeVector theGammaMomentum = track.GetMomentum();
108  }
109  else { //Occurrence of forced interaction
110 
111  //Selection of the model to be called
112  G4VEmAdjointModel* theSelectedModel =0;
113  G4bool is_scat_proj_to_proj_case=false;
115  if (!theAdjointComptonModel) {
116  theSelectedModel = theAdjointBremModel;
117  is_scat_proj_to_proj_case=false;
118  //This is needed because the results of it will be used in the post step do it weight correction inside the model
120  track.GetMaterialCutsCouple(),track.GetKineticEnergy(), false);
121 
122  }
123  else if (!theAdjointBremModel) {
124  theSelectedModel = theAdjointComptonModel;
125  is_scat_proj_to_proj_case=true;
126  }
127  else { //Choose the model according to cross sections
128 
130  track.GetMaterialCutsCouple(),track.GetKineticEnergy(), false);
131  if (G4UniformRand()*lastAdjCS<bremAdjCS) {
132  theSelectedModel = theAdjointBremModel;
133  is_scat_proj_to_proj_case=false;
134  }
135  else {
136  theSelectedModel = theAdjointComptonModel;
137  is_scat_proj_to_proj_case=true;
138  }
139  }
140 
141  //Compute the weight correction factor
142  G4double one_over_effectiveAdjointCS= (1.-std::exp(acc_nb_adj_interaction_length-total_acc_nb_adj_interaction_length))/lastAdjCS;
143  G4double weight_correction_factor = lastAdjCS*one_over_effectiveAdjointCS;
144  //G4cout<<"Weight correction factor start "<<weight_correction_factor<<std::endl;
145  //Call the selected model without correction of the weight in the model
146  theSelectedModel->SetCorrectWeightForPostStepInModel(false);
147  theSelectedModel->SetAdditionalWeightCorrectionFactorForPostStepOutsideModel(weight_correction_factor);
148  theSelectedModel->SampleSecondaries(track,is_scat_proj_to_proj_case,fParticleChange);
149  theSelectedModel->SetCorrectWeightForPostStepInModel(true);
150 
152  }
153  return fParticleChange;
154 }
156 //
158 { fParticleChange->Initialize(track);
159  //Compute nb of interactions length over step length
162  G4double ekin = track.GetKineticEnergy();
163  G4double nb_fwd_interaction_length_over_step=0.;
164  G4double nb_adj_interaction_length_over_step=0.;
167  ekin,track.GetMaterialCutsCouple());
168  nb_fwd_interaction_length_over_step = stepLength*lastFwdCS;
169  nb_adj_interaction_length_over_step = stepLength*lastAdjCS;
170  G4double fwd_survival_probability=std::exp(-nb_fwd_interaction_length_over_step);
171  G4double mc_induced_survival_probability=1.;
172 
173  if (is_free_flight_gamma) { //for free_flight survival probability stays 1
174  //Accumulate the number of interaction lengths during free flight of gamma
175  total_acc_nb_fwd_interaction_length+=nb_fwd_interaction_length_over_step;
176  total_acc_nb_adj_interaction_length+=nb_adj_interaction_length_over_step;
178  }
179  else {
180  G4double previous_acc_nb_adj_interaction_length =acc_nb_adj_interaction_length;
181  acc_nb_fwd_interaction_length+=nb_fwd_interaction_length_over_step;
182  acc_nb_adj_interaction_length+=nb_adj_interaction_length_over_step;
183  theNumberOfInteractionLengthLeft-=nb_adj_interaction_length_over_step;
184 
185  //Following condition to remove very rare FPE issue
186  //if (total_acc_nb_adj_interaction_length <= 1.e-50 && theNumberOfInteractionLengthLeft<=1.e-50) { //condition added to avoid FPE issue
187  // VI 06.11.2017 - new condition
188  if (std::abs(total_acc_nb_adj_interaction_length - previous_acc_nb_adj_interaction_length) <= 1.e-15) {
189  mc_induced_survival_probability = 1.e50;
190  /*
191  G4cout << "FPE protection: " << total_acc_nb_adj_interaction_length << " "
192  << previous_acc_nb_adj_interaction_length << " "
193  << acc_nb_fwd_interaction_length << " "
194  << acc_nb_adj_interaction_length << " "
195  << theNumberOfInteractionLengthLeft
196  << G4endl;
197  */
198  }
199  else {
200  mc_induced_survival_probability= std::exp(-acc_nb_adj_interaction_length)-std::exp(-total_acc_nb_adj_interaction_length);
201  mc_induced_survival_probability=mc_induced_survival_probability/(std::exp(-previous_acc_nb_adj_interaction_length)-std::exp(-total_acc_nb_adj_interaction_length));
202  }
203  }
204  G4double weight_correction = fwd_survival_probability/mc_induced_survival_probability;
205 
206  //weight_correction = 1.;
207  //Caution!!!
208  // It is important to select the weight of the post_step_point
209  // as the current weight and not the weight of the track, as t
210  // the weight of the track is changed after having applied all
211  // the along_step_do_it.
212  G4double new_weight=weight_correction*track.GetStep()->GetPostStepPoint()->GetWeight();
213 /*
214  G4cout<<"New weight "<<new_weight<<std::endl;
215  G4cout<<"Weight correction "<<weight_correction<<std::endl;
216  */
217 
221 
222  return fParticleChange;
223 }
225 //
227  const G4Track& track,
228  G4double ,
230 { G4int step_id = track.GetCurrentStepNumber();
231  *condition = NotForced;
233  G4int track_id=track.GetTrackID();
235  if (is_free_flight_gamma) {
236  if (step_id == 1 || continue_gamma_as_new_free_flight) {
237  *condition=Forced;
238  //A gamma with same conditions will be generate at next post_step do it for the forced interaction
240  last_free_flight_trackid = track_id;
241  acc_track_length=0.;
245  return 1.e-90;
246  }
247  else {
248  //Computation of accumulated length for
249  return DBL_MAX;
250  }
251  }
252  else { //compute the interaction length for forced interaction
253  if (step_id ==1) {
254  G4double min_val= std::exp(-total_acc_nb_adj_interaction_length);
255  theNumberOfInteractionLengthLeft = -std::log( min_val+G4UniformRand()*(1.-min_val));
259  }
260  G4VPhysicalVolume* thePostPhysVolume = track.GetStep()->GetPreStepPoint()->GetPhysicalVolume();
261  G4double ekin =track.GetKineticEnergy();
262  G4double postCS=0.;
263  if (thePostPhysVolume){
265  ekin,thePostPhysVolume->GetLogicalVolume()->GetMaterialCutsCouple());
266  }
267  if (postCS>0.) return theNumberOfInteractionLengthLeft/postCS;
268  else return DBL_MAX;
269  }
270 }
272 //
274  G4double ,
275  G4double ,
276  G4double& )
277 {return DBL_MAX;
278 }
280 //Not used in this process but should be implemented as virtual method
282  G4double ,
284 { return 0.;
285 }
286 
287 
G4double GetKineticEnergy() const
G4LogicalVolume * GetLogicalVolume() const
G4StepPoint * GetPreStepPoint() const
virtual G4VParticleChange * AlongStepDoIt(const G4Track &track, const G4Step &step)
void PreparePhysicsTable(const G4ParticleDefinition &)
G4int GetTrackID() const
void SetSecondaryWeightByProcess(G4bool)
G4VPhysicalVolume * GetPhysicalVolume() const
G4int GetCurrentStepNumber() const
G4double condition(const G4ErrorSymMatrix &m)
G4ParticleDefinition * GetDefinition() const
void AddSecondary(G4Track *aSecondary)
static G4AdjointGamma * AdjointGamma()
G4double GetTotalAdjointCS(G4ParticleDefinition *aPartDef, G4double Ekin, const G4MaterialCutsCouple *aCouple)
G4ThreeVector GetMomentum() const
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
void SetCorrectWeightForPostStepInModel(G4bool aBool)
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
virtual void Initialize(const G4Track &)
const G4MaterialCutsCouple * GetMaterialCutsCouple() const
G4double GetStepLength() const
#define G4UniformRand()
Definition: Randomize.hh:53
const G4ThreeVector & GetPosition() const
Definition: G4Step.hh:76
G4StepPoint * GetPostStepPoint() const
const G4Step * GetStep() const
virtual G4double GetMeanFreePath(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
static G4AdjointCSManager * GetAdjointCSManager()
G4double theInitialNumberOfInteractionLength
Definition: G4VProcess.hh:300
G4double GetTotalForwardCS(G4ParticleDefinition *aPartDef, G4double Ekin, const G4MaterialCutsCouple *aCouple)
virtual G4VParticleChange * PostStepDoIt(const G4Track &, const G4Step &)
int G4int
Definition: G4Types.hh:78
void SetParentWeightByProcess(G4bool)
void ProposeParentWeight(G4double finalWeight)
void SetAdditionalWeightCorrectionFactorForPostStepOutsideModel(G4double factor)
G4ForceCondition
G4double GetWeight() const
virtual G4double PostStepGetPhysicalInteractionLength(const G4Track &track, G4double previousStepSize, G4ForceCondition *condition)
G4double theNumberOfInteractionLengthLeft
Definition: G4VProcess.hh:293
virtual G4double AdjointCrossSection(const G4MaterialCutsCouple *aCouple, G4double primEnergy, G4bool IsScatProjToProjCase)
void BuildPhysicsTable(const G4ParticleDefinition &)
#define DBL_MAX
Definition: templates.hh:83
virtual G4double GetContinuousStepLimit(const G4Track &aTrack, G4double previousStepSize, G4double currentMinimumStep, G4double &currentSafety)
virtual void SampleSecondaries(const G4Track &aTrack, G4bool IsScatProjToProjCase, G4ParticleChange *fParticleChange)=0