Geant4  10.02.p01
SteppingAction.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 //
28 //
29 // $Id: SteppingAction.cc 94619 2015-11-26 13:57:32Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "SteppingAction.hh"
35 #include "Run.hh"
36 #include "HistoManager.hh"
37 
38 #include "G4ParticleTypes.hh"
39 #include "G4RunManager.hh"
40 #include "G4HadronicProcess.hh"
41 
42 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
43 
46 { }
47 
48 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
49 
51 { }
52 
53 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
54 
56 {
57  Run* run
59 
60  // count processes
61  //
62  const G4StepPoint* endPoint = aStep->GetPostStepPoint();
63  G4VProcess* process =
64  const_cast<G4VProcess*>(endPoint->GetProcessDefinedStep());
65  run->CountProcesses(process);
66 
67  // check that an real interaction occured (eg. not a transportation)
68  G4StepStatus stepStatus = endPoint->GetStepStatus();
69  G4bool transmit = (stepStatus==fGeomBoundary || stepStatus==fWorldBoundary);
70  if (transmit) return;
71 
72  //real processes : sum track length
73  //
74  G4double stepLength = aStep->GetStepLength();
75  run->SumTrack(stepLength);
76 
77  //energy-momentum balance initialisation
78  //
79  const G4StepPoint* prePoint = aStep->GetPreStepPoint();
80  G4double Q = - prePoint->GetKineticEnergy();
81  G4ThreeVector Pbalance = - prePoint->GetMomentum();
82 
83  //initialisation of the nuclear channel identification
84  //
85  G4ParticleDefinition* particle = aStep->GetTrack()->GetDefinition();
86  G4String partName = particle->GetParticleName();
87  G4String nuclearChannel = partName;
88  G4HadronicProcess* hproc = dynamic_cast<G4HadronicProcess*>(process);
89  const G4Isotope* target = NULL;
90  if (hproc) target = hproc->GetTargetIsotope();
91  G4String targetName = "XXXX";
92  if (target) targetName = target->GetName();
93  nuclearChannel += " + " + targetName + " --> ";
94  if (targetName == "XXXX") run->SetTargetXXX(true);
95 
96  //scattered primary particle (if any)
97  //
98  G4AnalysisManager* analysis = G4AnalysisManager::Instance();
99  G4int ih = 1;
100  if (aStep->GetTrack()->GetTrackStatus() == fAlive) {
101  G4double energy = endPoint->GetKineticEnergy();
102  analysis->FillH1(ih,energy);
103  //
104  G4ThreeVector momentum = endPoint->GetMomentum();
105  Q += energy;
106  Pbalance += momentum;
107  //
108  nuclearChannel += partName + " + ";
109  }
110 
111  //secondaries
112  //
113  const std::vector<const G4Track*>* secondary
114  = aStep->GetSecondaryInCurrentStep();
115  for (size_t lp=0; lp<(*secondary).size(); lp++) {
116  particle = (*secondary)[lp]->GetDefinition();
117  G4String name = particle->GetParticleName();
118  G4String type = particle->GetParticleType();
119  G4double energy = (*secondary)[lp]->GetKineticEnergy();
120  run->ParticleCount(name,energy);
121  //energy spectrum
122  ih = 0;
123  if (particle == G4Gamma::Gamma()) ih = 2;
124  else if (particle == G4Neutron::Neutron()) ih = 3;
125  else if (particle == G4Proton::Proton()) ih = 4;
126  else if (particle == G4Deuteron::Deuteron()) ih = 5;
127  else if (particle == G4Alpha::Alpha()) ih = 6;
128  else if (type == "nucleus") ih = 7;
129  else if (type == "meson") ih = 8;
130  else if (type == "baryon") ih = 9;
131  if (ih > 0) analysis->FillH1(ih,energy);
132  //atomic mass
133  if (type == "nucleus") {
134  G4int A = particle->GetAtomicMass();
135  analysis->FillH1(12, A);
136  }
137  //energy-momentum balance
138  G4ThreeVector momentum = (*secondary)[lp]->GetMomentum();
139  Q += energy;
140  Pbalance += momentum;
141  //particle flag
142  fParticleFlag[particle]++;
143  }
144 
145  //energy-momentum balance
146  G4double Pbal = Pbalance.mag();
147  run->Balance(Pbal);
148  ih = 10;
149  analysis->FillH1(ih,Q);
150  ih = 11;
151  analysis->FillH1(ih,Pbal);
152 
153  // nuclear channel
154  const G4int kMax = 16;
155  const G4String conver[] = {"0","","2 ","3 ","4 ","5 ","6 ","7 ","8 ","9 ",
156  "10 ","11 ","12 ","13 ","14 ","15 ","16 "};
157  std::map<G4ParticleDefinition*,G4int>::iterator ip;
158  for (ip = fParticleFlag.begin(); ip != fParticleFlag.end(); ip++) {
159  particle = ip->first;
160  G4String name = particle->GetParticleName();
161  G4int nb = ip->second;
162  if (nb > kMax) nb = kMax;
163  G4String Nb = conver[nb];
164  if (particle == G4Gamma::Gamma()) {
165  run->CountGamma(nb);
166  Nb = "N ";
167  }
168  if (ip != fParticleFlag.begin()) nuclearChannel += " + ";
169  nuclearChannel += Nb + name;
170  }
171 
173  run->CountNuclearChannel(nuclearChannel, Q);
174 
175  fParticleFlag.clear();
176 
177  // kill event after first interaction
178  //
180 }
181 
182 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
183 
184 
G4ParticleDefinition * GetDefinition() const
void CountProcesses(G4String procName)
Definition: Run.cc:72
const G4String & GetName() const
Definition: G4Isotope.hh:88
void CountGamma(G4int)
Definition: Run.cc:144
void SetTargetXXX(G4bool)
Definition: Run.cc:71
CLHEP::Hep3Vector G4ThreeVector
G4double GetStepLength() const
std::map< G4ParticleDefinition *, G4int > fParticleFlag
G4String name
Definition: TRTMaterials.hh:40
G4StepStatus GetStepStatus() const
AnalysisManager * analysis
G4TrackStatus GetTrackStatus() const
static double Q[]
G4ThreeVector GetMomentum() const
void Balance(G4double)
Definition: Run.cc:133
void UserSteppingAction(const G4Step *)
int G4int
Definition: G4Types.hh:78
const G4Isotope * GetTargetIsotope()
const G4String & GetParticleName() const
G4StepStatus
Definition: G4StepStatus.hh:49
G4StepPoint * GetPreStepPoint() const
void CountNuclearChannel(G4String, G4double)
Definition: Run.cc:99
double A(double temperature)
void SumTrack(G4double track)
Definition: Run.cc:81
bool G4bool
Definition: G4Types.hh:79
static G4Proton * Proton()
Definition: G4Proton.cc:93
const G4String & GetParticleType() const
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:66
Definition: G4Step.hh:76
static G4Neutron * Neutron()
Definition: G4Neutron.cc:104
const std::vector< const G4Track * > * GetSecondaryInCurrentStep() const
Definition: G4Step.cc:193
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
static G4Deuteron * Deuteron()
Definition: G4Deuteron.cc:94
G4int GetAtomicMass() const
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
const G4VProcess * GetProcessDefinedStep() const
G4double energy(const ThreeVector &p, const G4double m)
G4StepPoint * GetPostStepPoint() const
static G4Alpha * Alpha()
Definition: G4Alpha.cc:89
virtual void AbortEvent()
G4double GetKineticEnergy() const
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4Track * GetTrack() const
G4Run * GetNonConstCurrentRun() const
void ParticleCount(G4String, G4double)
Definition: Run.cc:114