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 90848 2015-06-10 13:44:30Z gcosmo $
30 //
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "SteppingAction.hh"
35 #include "DetectorConstruction.hh"
36 #include "RunAction.hh"
37 #include "TrackingAction.hh"
38 #include "HistoManager.hh"
39 #include "Run.hh"
40 #include "G4RunManager.hh"
41 
42 #include "G4SteppingManager.hh"
43 #include "G4Gamma.hh"
44 #include "G4UnitsTable.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
47 
49  :fDetector(det), fTrackAction(TrAct),
50  fWall(0), fCavity(0)
51 {
52  first = true;
53  fTrackSegm = 0.;
54  fDirectionIn = G4ThreeVector(0.,0.,0.);
55 }
56 
57 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
58 
60 { }
61 
62 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
63 
65 {
66  //get fDetector pointers
67  if (first) {
68  fWall = fDetector->GetWall();
70  first = false;
71  }
72 
73  //histograms
74  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
75 
76  //get volume
77  //
78  G4StepPoint* point1 = step->GetPreStepPoint();
79  G4VPhysicalVolume* volume = point1->GetTouchableHandle()->GetVolume();
80 
81  Run* run = static_cast<Run*>(
83  // count processes
84  //
85  G4StepPoint* point2 = step->GetPostStepPoint();
86  const G4VProcess* process = point2->GetProcessDefinedStep();
87  if (process) run->CountProcesses(process->GetProcessName());
88 
89  //energy deposit in cavity
90  //
91  if (volume == fCavity) {
92  G4double edep = step->GetTotalEnergyDeposit();
93  if (edep > 0.) fTrackAction->AddEdepCavity(edep);
94  }
95 
96  //keep only charged particles
97  //
98  if (step->GetTrack()->GetDefinition() == G4Gamma::Gamma()) return;
99 
100  //step size of charged particles
101  //
102  G4int id;
103  G4double steplen = step->GetStepLength();
104  if (volume == fWall) {run->StepInWall (steplen); id = 9;}
105  else {run->StepInCavity(steplen); id = 10;}
106  analysisManager->FillH1(id,steplen);
107 
108  //last step before hitting the cavity
109  //
110  if ((volume == fWall) && (point2->GetStepStatus() == fGeomBoundary)) {
112  }
113 
114  //keep only charged particles within cavity
115  //
116  if (volume == fWall) return;
117 
118  G4double ekin1 = point1->GetKineticEnergy();
119  G4double ekin2 = point2->GetKineticEnergy();
120 
121  //first step in cavity
122  //
123  if (point1->GetStepStatus() == fGeomBoundary) {
124  fTrackSegm = 0.;
125  G4ThreeVector vertex = step->GetTrack()->GetVertexPosition();
126  analysisManager->FillH1(4,vertex.z());
127  run->FlowInCavity(0,ekin1);
128  analysisManager->FillH1(5,ekin1);
129  if (steplen>0.) {
130  G4ThreeVector directionOut =
131  (point2->GetPosition() - point1->GetPosition()).unit();
133  ->SurfaceNormal(point1->GetPosition());
134  analysisManager->FillH1(6,std::acos(-fDirectionIn*normal));
135  analysisManager->FillH1(7,std::acos(-directionOut*normal));
136  }
137  }
138 
139  //within cavity
140  //
141  if (step->GetTrack()->GetCurrentStepNumber() == 1) fTrackSegm = 0.;
142  fTrackSegm += steplen;
143  if (ekin2 <= 0.) {
145  analysisManager->FillH1(8,fTrackSegm);
146  }
147 
148  //exit cavity
149  //
150  if (point2->GetStepStatus() == fGeomBoundary) {
151  run->FlowInCavity(1,ekin2);
153  analysisManager->FillH1(8,fTrackSegm);
154  }
155 }
156 
157 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
158 
159 
void AddTrakCavity(G4double dt)
Definition: Run.hh:74
G4ParticleDefinition * GetDefinition() const
G4VPhysicalVolume * GetWall()
void CountProcesses(G4String procName)
Definition: Run.cc:72
virtual G4VSolid * GetSolid(G4int depth=0) const
Definition: G4VTouchable.cc:51
CLHEP::Hep3Vector G4ThreeVector
void StepInCavity(G4double s)
Definition: Run.hh:78
G4double GetStepLength() const
G4ThreeVector fDirectionIn
G4StepStatus GetStepStatus() const
void UserSteppingAction(const G4Step *)
int G4int
Definition: G4Types.hh:78
G4VPhysicalVolume * fWall
static double normal(HepRandomEngine *eptr)
Definition: RandPoisson.cc:77
G4VPhysicalVolume * fCavity
G4StepPoint * GetPreStepPoint() const
TrackingAction * fTrackAction
const G4ThreeVector & GetMomentumDirection() const
G4int GetCurrentStepNumber() const
const G4ThreeVector & GetPosition() const
virtual G4ThreeVector SurfaceNormal(const G4ThreeVector &p) const =0
G4double fTrackSegm
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:66
Definition: G4Step.hh:76
DetectorConstruction * fDetector
static G4Gamma * Gamma()
Definition: G4Gamma.cc:86
const G4String & GetProcessName() const
Definition: G4VProcess.hh:408
const G4ThreeVector & GetVertexPosition() const
G4double GetTotalEnergyDeposit() const
G4VPhysicalVolume * GetCavity()
static G4RunManager * GetRunManager()
Definition: G4RunManager.cc:79
const G4VProcess * GetProcessDefinedStep() const
void StepInWall(G4double s)
Definition: Run.hh:76
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
void FlowInCavity(G4int k, G4double e)
Definition: Run.hh:69
G4StepPoint * GetPostStepPoint() const
Detector construction class to demonstrate various ways of placement.
void AddEdepCavity(G4double de)
G4double GetKineticEnergy() const
double G4double
Definition: G4Types.hh:76
Definition: Run.hh:46
G4Track * GetTrack() const
G4Run * GetNonConstCurrentRun() const
const G4TouchableHandle & GetTouchableHandle() const