Loading...
Searching...
No Matches
Dicom2PrimaryGeneratorAction.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/// \file Dicom2PrimaryGeneratorAction.cc
28/// \brief Implementation of the Dicom2PrimaryGeneratorAction class
29
32
33#include "G4LogicalVolumeStore.hh"
34#include "G4PhysicalVolumeStore.hh"
35#include "G4LogicalVolume.hh"
36#include "G4VPhysicalVolume.hh"
37#include "G4Box.hh"
38#include "G4RunManager.hh"
39#include "G4ParticleGun.hh"
40#include "G4ParticleTable.hh"
41#include "G4ParticleDefinition.hh"
42#include "G4SystemOfUnits.hh"
43#include "Randomize.hh"
44#include "G4RandomDirection.hh"
45#include "G4UnitsTable.hh"
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
48
51 fParticleGun(new G4ParticleGun(1)),
52 fEnvelopeBox(nullptr),
53 fEnvelopeVol(nullptr),
54 fPosCenter(G4ThreeVector(0.0)),
55 fPosDelta(G4ThreeVector(0.0)),
56 fGeomFactor(0.8)
57{
58 // default particle kinematic
59 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
60 G4String particleName;
61 G4ParticleDefinition* particle
62 = particleTable->FindParticle(particleName="e-");
63 fParticleGun->SetParticleDefinition(particle);
64 fParticleGun->SetParticleMomentumDirection(G4ThreeVector(0.,0.,1.));
65 fParticleGun->SetParticleEnergy(10.*MeV);
66}
67
68//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
69
74
75//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76
78{
79 //this function is called at the begining of ecah event
80 //
81
82 // In order to avoid dependence of PrimaryGeneratorAction
83 // on DetectorConstruction class we get phantomContainer volume
84 // from G4LogicalVolumeStore.
85 if (!fEnvelopeBox)
86 {
87 G4LogicalVolume* envLV
88 = G4LogicalVolumeStore::GetInstance()->GetVolume("phantomContainer");
89 if(envLV)
90 fEnvelopeBox = dynamic_cast<G4Box*>(envLV->GetSolid());
91 }
92
93 if(!fEnvelopeVol)
94 {
95 fEnvelopeVol = G4PhysicalVolumeStore::GetInstance()->GetVolume("phantomContainer");
96 }
97
98 // get the center of the phantom
99 if(fEnvelopeVol)
100 {
101 fPosCenter = fEnvelopeVol->GetObjectTranslation();
102 }
103 else
104 {
105 G4ExceptionDescription msg;
106 msg << "Envelope physical volume not found.\n";
107 msg << "The gun will be place at the center.";
108 G4Exception("Dicom2PrimaryGeneratorAction::GeneratePrimaries()",
109 "DICOM20002",JustWarning, msg);
110 }
111
112 // get the size of the phantom
113 if(fEnvelopeBox)
114 {
115 fPosDelta = G4ThreeVector(2.0 * fEnvelopeBox->GetXHalfLength(),
116 2.0 * fEnvelopeBox->GetYHalfLength(),
117 2.0 * fEnvelopeBox->GetZHalfLength());
118 }
119 else
120 {
121 G4ExceptionDescription msg;
122 msg << "Envelope volume of box shape not found.\n";
123 msg << "The gun will be place at the center.";
124 G4Exception("Dicom2PrimaryGeneratorAction::GeneratePrimaries()",
125 "DICOM20003",JustWarning, msg);
126 }
127
128 // start at center
129 G4ThreeVector pos = fPosCenter;
130 // get a random displacement
131 G4ThreeVector delta(fPosDelta.x() * (G4UniformRand()-0.5),
132 fPosDelta.y() * (G4UniformRand()-0.5),
133 fPosDelta.z() * (G4UniformRand()-0.5));
134 // scale by geom factor
135 delta *= fGeomFactor;
136
137 //G4cout << "Starting position: " << G4BestUnit(pos + delta, "Length")
138 // << ", pos = " << G4BestUnit(fPosCenter, "Length")
139 // << ", size = " << G4BestUnit(fPosDelta, "Length")
140 // << ", delta = " << G4BestUnit(delta, "Length")
141 // << G4endl;
142
143 fParticleGun->SetParticlePosition(pos + delta);
144 fParticleGun->SetParticleMomentumDirection(G4RandomDirection());
145 fParticleGun->GeneratePrimaryVertex(anEvent);
146}
147
148//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
149
Definition of the Dicom2PrimaryGeneratorAction class.
Definition of the DicomDetectorConstruction class.

Applications | User Support | Publications | Collaboration