/scratch0/jsnuveri/BDSIM/BDSIMgit/bdsim/src/BDSGammaConversion_LPB.cc

00001 //GammaConversion Leading Particle Biasing Method, M.D. Salt, R.B. Appleby, 15/10/09
00002 
00003 #include "BDSGammaConversion_LPB.hh"
00004 #include "CLHEP/Random/Random.h"
00005 #include "BDSGlobalConstants.hh"
00006 
00007 G4VParticleChange* GammaConversion_LPB::PostStepDoIt(const G4Track& track, const G4Step& step)
00008 {
00009   //System to control degree of biasing used
00010   G4bool fActive = true;
00011   G4double fBiasFraction = BDSGlobalConstants::Instance()->GetLPBFraction();
00012   if(fBiasFraction < CLHEP::RandFlat::shoot()){
00013     fActive = false;
00014   }
00015 
00016   //Obtain initial parent weight
00017   G4double initialWeight = track.GetWeight();
00018 
00019   //Secondaries store
00020   std::vector<G4Track*> secondaries;
00021 
00022   //Declare particle change
00023   G4VParticleChange* particleChange = NULL;
00024 
00025   //Get secondaries
00026   particleChange = pRegProcess->PostStepDoIt(track, step);
00027   assert (0 != particleChange);
00028   G4int j(0);
00029   for(j=0; j<particleChange->GetNumberOfSecondaries(); j++)
00030   {
00031     secondaries.push_back(new G4Track(*(particleChange->GetSecondary(j))));
00032   }
00033   particleChange->Clear();
00034   particleChange->SetNumberOfSecondaries(secondaries.size());
00035 
00036   //Permit weight setting for leading particle biasing
00037   particleChange->SetSecondaryWeightByProcess(true);
00038 
00039   //Add the secondaries and perform leading particle biasing
00040   std::vector<G4Track*>::iterator iter = secondaries.begin();
00041   G4double survivalProbability(0.0); //relates to the first [0] secondary
00042   survivalProbability = secondaries[0]->GetKineticEnergy() / track.GetKineticEnergy();
00043   if(fActive)
00044     {
00045     if(survivalProbability > CLHEP::RandFlat::shoot())
00046     {
00047       //secondaries[0] survives
00048       secondaries[0]->SetWeight(initialWeight / survivalProbability);
00049       secondaries[1]->SetTrackStatus(fStopAndKill);
00050     }
00051     else
00052     {
00053       //secondaries[1] survives
00054       secondaries[0]->SetTrackStatus(fStopAndKill);
00055       secondaries[1]->SetWeight(initialWeight / (1.0 - survivalProbability));
00056     }
00057   }
00058   else
00059   {
00060     secondaries[0]->SetWeight(initialWeight);
00061     secondaries[1]->SetWeight(initialWeight);
00062   }
00063 
00064   while(iter != secondaries.end())
00065   {
00066     G4Track* myTrack = *iter;
00067     particleChange->AddSecondary(myTrack);
00068     iter++;
00069   }
00070   //Kill the incident photon
00071   particleChange->ProposeTrackStatus(fStopAndKill);
00072   return particleChange;
00073 }
00074 
00075 
00076 
00077 //Version 2 - no secondaries are killed, bu leading particles are split with reduced weight
00078 
00079 G4VParticleChange* GammaConversion_LPB_v2::PostStepDoIt(const G4Track& track, const G4Step& step)
00080 {
00081   G4int multiplicity = 2;
00082 
00083   //System to control degree of biasing used
00084   // G4bool fActive = true;
00085   // G4double fBiasFraction = BDSGlobalConstants::Instance()->GetLPBFraction();
00086   // if(fBiasFraction < CLHEP::RandFlat::shoot()){
00087   //   fActive = false;
00088   // }
00089 
00090   //Obtain initial parent weight
00091   G4double initialWeight = track.GetWeight();
00092 
00093   //Secondaries store
00094   std::vector<G4Track*> secondaries;
00095 
00096   //Declare particle change
00097   G4VParticleChange* particleChange = NULL;
00098 
00099   //Get secondaries
00100   particleChange = pRegProcess->PostStepDoIt(track, step);
00101   assert (0 != particleChange);
00102   G4int j(0);
00103   for(j=0; j<particleChange->GetNumberOfSecondaries(); j++){
00104     secondaries.push_back(new G4Track(*(particleChange->GetSecondary(j))));
00105   }
00106   
00107   //Permit weight setting for leading particle biasing
00108   particleChange->SetSecondaryWeightByProcess(true);
00109 
00110   //Add the secondaries and perform leading particle biasing
00111   std::vector<G4Track*>::iterator iter = secondaries.begin();
00112   G4double survivalProbability(0.0); //relates to the first [0] secondary
00113   survivalProbability = secondaries[0]->GetKineticEnergy() / track.GetKineticEnergy();
00114   if(0)
00115     //if(fActive)
00116   {
00117     if(survivalProbability > CLHEP::RandFlat::shoot())
00118     {
00119       //secondaries[0] is multiplied with reduced weight
00120       secondaries[0]->SetWeight(initialWeight / (G4double)multiplicity);
00121       for(int i=0; i<(multiplicity-1); i++){
00122         secondaries.push_back(new G4Track(*secondaries[0]));
00123       }
00124     }
00125     else
00126     {
00127       //secondaries[1] is multiplied with reduced weight
00128       secondaries[1]->SetWeight(initialWeight / (G4double)multiplicity);
00129       for(int i=0; i<(multiplicity-1); i++){
00130         secondaries.push_back(new G4Track(*secondaries[1]));
00131       }
00132     }
00133   }
00134   else
00135   {
00136     secondaries[0]->SetWeight(initialWeight);
00137     secondaries[1]->SetWeight(initialWeight);
00138   }
00139 
00140   particleChange->Clear();
00141   particleChange->SetNumberOfSecondaries(secondaries.size());
00142 
00143   while(iter != secondaries.end())
00144   {
00145     G4Track* myTrack = *iter;
00146     particleChange->AddSecondary(myTrack);
00147     iter++;
00148   }
00149   //Kill the incident photon
00150   particleChange->ProposeTrackStatus(fStopAndKill);
00151   return particleChange;
00152 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7