G4SamplingPostStepAction.cc

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 //
00027 // $Id$
00028 //
00029 // ----------------------------------------------------------------------
00030 // GEANT 4 class source file
00031 //
00032 // G4SamplingPostStepAction.cc
00033 //
00034 // ----------------------------------------------------------------------
00035 
00036 #include "G4SamplingPostStepAction.hh"
00037 #include "G4Track.hh"
00038 #include "G4ParticleChange.hh"
00039 #include "G4VImportanceSplitExaminer.hh"
00040 #include "G4Nsplit_Weight.hh"
00041 #include "G4VTrackTerminator.hh"
00042 #include <sstream>
00043 
00044 G4SamplingPostStepAction::
00045 G4SamplingPostStepAction(const G4VTrackTerminator &TrackTerminator)
00046   : fTrackTerminator(TrackTerminator)
00047 {
00048 }
00049 
00050 G4SamplingPostStepAction::~G4SamplingPostStepAction()
00051 {
00052 }
00053 
00054 void G4SamplingPostStepAction::DoIt(const G4Track& aTrack, 
00055                                           G4ParticleChange *aParticleChange,
00056                                     const G4Nsplit_Weight &nw)
00057 {  
00058   // evaluate results from sampler
00059   if (nw.fN>1)
00060   {
00061     // split track 
00062     Split(aTrack, nw, aParticleChange);
00063   }
00064   else if (nw.fN==1)
00065   {
00066     // don't split, but weight may be changed ! 
00067     aParticleChange->ProposeWeight(nw.fW);
00068   }
00069   else if (nw.fN==0)
00070   {
00071     // kill track
00072     fTrackTerminator.KillTrack();
00073   }
00074   else
00075   {
00076     // wrong answer
00077     std::ostringstream os;
00078     os << "Sampler returned nw = "
00079        << nw
00080        << "\n";
00081     G4String msg = os.str();
00082     
00083     G4Exception("G4SamplingPostStepAction::DoIt()",
00084                 "InvalidCondition", FatalException, msg);
00085   }
00086 }
00087 
00088 void G4SamplingPostStepAction::Split(const G4Track &aTrack,
00089                                      const G4Nsplit_Weight &nw,
00090                                            G4ParticleChange *aParticleChange)
00091 {
00092   aParticleChange->ProposeWeight(nw.fW);
00093   aParticleChange->SetNumberOfSecondaries(nw.fN-1);
00094   
00095   for (G4int i=1;i<nw.fN;i++)
00096   {
00097     G4Track *ptrack = new G4Track(aTrack);
00098     
00099     //    ptrack->SetCreatorProcess(aTrack.GetCreatorProcess());
00100     ptrack->SetWeight(nw.fW);
00101     
00102     if (ptrack->GetMomentumDirection() != aTrack.GetMomentumDirection())
00103     {
00104       G4Exception("G4SamplingPostStepAction::Split()", "InvalidCondition",
00105                   FatalException, "Track with same momentum !");
00106     }
00107     aParticleChange->AddSecondary(ptrack);
00108   }
00109   return;
00110 }  

Generated on Mon May 27 17:49:47 2013 for Geant4 by  doxygen 1.4.7