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