00001 
00002 
00003 #include "BDSeBremsstrahlung_LPB.hh"
00004 #include "CLHEP/Random/Random.h"
00005 #include "BDSGlobalConstants.hh"
00006 
00007 G4VParticleChange* eBremsstrahlung_LPB::PostStepDoIt(const G4Track& track, const G4Step& step)
00008 {
00009   
00010   G4bool fActive = true;
00011   G4double fBiasFraction = BDSGlobalConstants::Instance()->GetLPBFraction(); 
00012   if(fBiasFraction < CLHEP::RandFlat::shoot()) {
00013     fActive = false;
00014   }
00015   
00016   
00017   G4double initialWeight = track.GetWeight();
00018   
00019   
00020   std::vector<G4Track*> secondaries;
00021   
00022   
00023   G4VParticleChange* particleChange = NULL;
00024 
00025   
00026   particleChange = pRegProcess->PostStepDoIt(track, step);
00027   assert (0 != particleChange);
00028   G4int j(0);
00029 
00030   for(j=0; j<particleChange->GetNumberOfSecondaries(); j++)
00031   {
00032     secondaries.push_back(new G4Track(*(particleChange->GetSecondary(j))));
00033   }
00034   particleChange->Clear();
00035   particleChange->SetNumberOfSecondaries(secondaries.size());
00036   
00037   
00038   particleChange->SetParentWeightByProcess(true);
00039   particleChange->SetSecondaryWeightByProcess(true);
00040   
00041   
00042   std::vector<G4Track*>::iterator iter = secondaries.begin();
00043   G4double survivalProbability(0.0);
00044   while(iter != secondaries.end())
00045   {
00046     G4Track* myTrack = *iter;
00047     if(fActive)
00048     {
00049       survivalProbability = myTrack->GetKineticEnergy() / track.GetKineticEnergy();
00050       if(survivalProbability > CLHEP::RandFlat::shoot())
00051       {
00052         
00053         myTrack->SetWeight(initialWeight / survivalProbability);
00054         particleChange->ProposeTrackStatus(fStopAndKill);
00055       }
00056       else
00057       {
00058         
00059         myTrack->SetTrackStatus(fStopAndKill);
00060         particleChange->ProposeParentWeight(initialWeight / (1.0 - survivalProbability));
00061       }
00062     }
00063     else
00064     {
00065       particleChange->ProposeParentWeight(initialWeight);
00066       myTrack->SetWeight(initialWeight);
00067     }
00068     particleChange->AddSecondary(myTrack);
00069     iter++;
00070   }
00071   return particleChange;
00072 }
00073 
00074 
00075 
00076 G4VParticleChange* eBremsstrahlung_LPB_v2::PostStepDoIt(const G4Track& track, const G4Step& step)
00077 {
00078   G4int multiplicity = 2;
00079 
00080   
00081   G4bool fActive = true;
00082   G4double fBiasFraction = BDSGlobalConstants::Instance()->GetLPBFraction(); 
00083   if(fBiasFraction < CLHEP::RandFlat::shoot()) {
00084     fActive = false;
00085   }
00086   
00087   
00088   G4double initialWeight = track.GetWeight();
00089   
00090   
00091   std::vector<G4Track*> secondaries;
00092   
00093   
00094   G4VParticleChange* particleChange = NULL;
00095 
00096   
00097   particleChange = pRegProcess->PostStepDoIt(track, step);
00098   assert (0 != particleChange);
00099   G4int j(0);
00100 
00101   for(j=0; j<particleChange->GetNumberOfSecondaries(); j++)
00102   {
00103     secondaries.push_back(new G4Track(*(particleChange->GetSecondary(j))));
00104   }
00105   particleChange->Clear();
00106   particleChange->SetNumberOfSecondaries(secondaries.size());
00107   
00108   
00109   particleChange->SetParentWeightByProcess(true);
00110   particleChange->SetSecondaryWeightByProcess(true);
00111   
00112   
00113   G4double survivalProbability(0.0);
00114 
00115   std::vector<G4Track*>::iterator iter = secondaries.begin();
00116   G4Track* myTrack = *iter;
00117   while(iter != secondaries.end()){
00118     if(fActive)
00119     {
00120       survivalProbability = myTrack->GetKineticEnergy() / track.GetKineticEnergy();
00121       if(survivalProbability > CLHEP::RandFlat::shoot())
00122         {
00123         
00124         myTrack->SetWeight(initialWeight / (G4double)multiplicity);
00125         for(int i=0; i<(multiplicity-1); i++){
00126           secondaries.push_back(new G4Track(*myTrack));
00127         }
00128       }
00129     }
00130     else
00131     {
00132       particleChange->ProposeParentWeight(initialWeight);
00133       secondaries[0]->SetWeight(initialWeight);
00134     }
00135     iter++;
00136   }
00137  
00138   particleChange->SetNumberOfSecondaries(secondaries.size());
00139 
00140     iter = secondaries.begin();
00141     while(iter != secondaries.end())
00142       {
00143         G4Track* myTrack = *iter;
00144         particleChange->AddSecondary(myTrack);
00145         iter++;
00146       }
00147   
00148      return particleChange;
00149 }