Geant4  10.00.p01
G4SamplingPostStepAction.cc
Go to the documentation of this file.
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 //
27 // $Id: G4SamplingPostStepAction.cc 66241 2012-12-13 18:34:42Z gunter $
28 //
29 // ----------------------------------------------------------------------
30 // GEANT 4 class source file
31 //
32 // G4SamplingPostStepAction.cc
33 //
34 // ----------------------------------------------------------------------
35 
37 #include "G4Track.hh"
38 #include "G4ParticleChange.hh"
40 #include "G4Nsplit_Weight.hh"
41 #include "G4VTrackTerminator.hh"
42 #include <sstream>
43 
46  : fTrackTerminator(TrackTerminator)
47 {
48 }
49 
51 {
52 }
53 
55  G4ParticleChange *aParticleChange,
56  const G4Nsplit_Weight &nw)
57 {
58  // evaluate results from sampler
59  if (nw.fN>1)
60  {
61  // split track
62  Split(aTrack, nw, aParticleChange);
63  }
64  else if (nw.fN==1)
65  {
66  // don't split, but weight may be changed !
67  aParticleChange->ProposeWeight(nw.fW);
68  }
69  else if (nw.fN==0)
70  {
71  // kill track
73  }
74  else
75  {
76  // wrong answer
77  std::ostringstream os;
78  os << "Sampler returned nw = "
79  << nw
80  << "\n";
81  G4String msg = os.str();
82 
83  G4Exception("G4SamplingPostStepAction::DoIt()",
84  "InvalidCondition", FatalException, msg);
85  }
86 }
87 
89  const G4Nsplit_Weight &nw,
90  G4ParticleChange *aParticleChange)
91 {
92  aParticleChange->ProposeWeight(nw.fW);
93  aParticleChange->SetNumberOfSecondaries(nw.fN-1);
94 
95  for (G4int i=1;i<nw.fN;i++)
96  {
97  G4Track *ptrack = new G4Track(aTrack);
98 
99  // ptrack->SetCreatorProcess(aTrack.GetCreatorProcess());
100  ptrack->SetWeight(nw.fW);
101 
102  if (ptrack->GetMomentumDirection() != aTrack.GetMomentumDirection())
103  {
104  G4Exception("G4SamplingPostStepAction::Split()", "InvalidCondition",
105  FatalException, "Track with same momentum !");
106  }
107  aParticleChange->AddSecondary(ptrack);
108  }
109  return;
110 }
virtual void KillTrack() const =0
G4SamplingPostStepAction(const G4VTrackTerminator &TrackTerminator)
int G4int
Definition: G4Types.hh:78
void SetWeight(G4double aValue)
void ProposeWeight(G4double finalWeight)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const G4VTrackTerminator & fTrackTerminator
void DoIt(const G4Track &aTrack, G4ParticleChange *aParticleChange, const G4Nsplit_Weight &nw)
const G4ThreeVector & GetMomentumDirection() const
~G4SamplingPostStepAction()
void SetNumberOfSecondaries(G4int totSecondaries)
void AddSecondary(G4Track *aSecondary)
void Split(const G4Track &aTrack, const G4Nsplit_Weight &nw, G4ParticleChange *aParticleChange)