Geant4  10.02.p02
IORTDetectorSD.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 // This is the *BASIC* version of IORT, a Geant4-based application
27 //
28 // Main Authors: G.Russo(a,b), C.Casarino*(c), G.C. Candiano(c), G.A.P. Cirrone(d), F.Romano(d)
29 // Contributor Authors: S.Guatelli(e)
30 // Past Authors: G.Arnetta(c), S.E.Mazzaglia(d)
31 //
32 // (a) Fondazione Istituto San Raffaele G.Giglio, Cefalù, Italy
33 // (b) IBFM-CNR , Segrate (Milano), Italy
34 // (c) LATO (Laboratorio di Tecnologie Oncologiche), Cefalù, Italy
35 // (d) Laboratori Nazionali del Sud of the INFN, Catania, Italy
36 // (e) University of Wallongong, Australia
37 //
38 // *Corresponding author, email to carlo.casarino@polooncologicocefalu.it
40 
41 #include "IORTDetectorSD.hh"
42 #include "IORTAnalysisManager.hh"
43 #include "IORTDetectorHit.hh"
44 #include "G4Step.hh"
45 #include "G4VTouchable.hh"
46 #include "G4TouchableHistory.hh"
47 #include "G4SDManager.hh"
48 #include "IORTMatrix.hh"
49 #include "G4SystemOfUnits.hh"
50 
51 
55 {
56  G4String HCname;
57  collectionName.insert(HCname="IORTDetectorHitsCollection");
58  HitsCollection = NULL;
59  sensitiveDetectorName = dname;
60 }
61 
64 {
65 }
66 
69 {
71  collectionName[0]);
72 }
73 
76 {
77  //The code doesn't seem to get here if we use the IAEA geometry. FIXME
78  if(!ROhist)
79  return false;
80 
81  if (aStep -> GetPreStepPoint() -> GetPhysicalVolume() -> GetName() != "DetectorPhys")
82  return false;
83  // Get kinetic energy
84  G4Track * theTrack = aStep -> GetTrack();
85  //G4double kineticEnergy = theTrack -> GetKineticEnergy();
86 
87  G4ParticleDefinition *particleDef = theTrack -> GetDefinition();
88  //Get particle name
89  G4String particleName = particleDef -> GetParticleName();
90  // G4cout << particleDef -> GetParticleType() << '\n';
91  // Get unique track_id (in an event)
92  G4int trackID = theTrack -> GetTrackID();
93 
94  G4double energyDeposit = aStep -> GetTotalEnergyDeposit();
95 
96  G4int Z = particleDef-> GetAtomicNumber();
97  //G4int A = particleDef-> GetAtomicMass();
98 
99  // Read voxel indexes: i is the x index, k is the z index
100  G4int k = ROhist -> GetReplicaNumber(0);
101  G4int i = ROhist -> GetReplicaNumber(2);
102  G4int j = ROhist -> GetReplicaNumber(1);
103 
105 
107 
108  if (matrix)
109  {
110 
111  // Increment Fluences & accumulate energy spectra
112  // Hit voxels are marked with track_id throught hitTrack matrix
113  G4int* hitTrack = matrix -> GetHitTrack(i,j,k); // hitTrack MUST BE cleared at every eventAction!
114  if ( *hitTrack != trackID )
115  {
116  *hitTrack = trackID;
117  /*
118  * Fill FLUENCE data for every single nuclide
119  * Exclude e-, neutrons, gamma, ...
120  */
121  if ( Z >= 1)
122  matrix -> Fill(trackID, particleDef, i, j, k, 0, true);
123  /*
124  // Fragments kinetic energy (ntuple)
125  if (trackID !=1 && Z>=1)
126  {
127  // First step kinetic energy for every fragment
128  analysis -> FillKineticFragmentTuple(i, j, k, A, Z, kineticEnergy/MeV);
129  }
130  // Kinetic energy spectra for primary particles
131 
132  if ( trackID == 1 && i == 0)
133  {
134  // First step kinetic energy for primaries only
135  analysis -> FillKineticEnergyPrimaryNTuple(i, j, k, kineticEnergy/MeV);
136  }
137  */
138  }
139 
140  if(energyDeposit != 0)
141  {
142 /*
143  * This method will fill a dose matrix for every single nuclide.
144  * A method of the IORTMatrix class (StoreDoseFluenceAscii())
145  * is called automatically at the end of main (or via the macro command /analysis/writeDoseFile.
146  * It permits to store all dose/fluence data into a single plane ASCII file.
147 */
148  // if (A==1 && Z==1) // primary and sec. protons
149  if ( Z>=1 ) // exclude e-, neutrons, gamma, ...
150  matrix -> Fill(trackID, particleDef, i, j, k, energyDeposit);
151  /*
152  * Create a hit with the information of position is in the detector
153  */
154  IORTDetectorHit* detectorHit = new IORTDetectorHit();
155  detectorHit -> SetEdepAndPosition(i, j, k, energyDeposit);
156  HitsCollection -> insert(detectorHit);
157  }
158  }
159 
160  if(energyDeposit != 0)
161  {
162  if(trackID != 1)
163  {
164  if (particleName == "proton")
165  analysis -> SecondaryProtonEnergyDeposit(i, energyDeposit/MeV);
166 
167  else if (particleName == "neutron")
168  analysis -> SecondaryNeutronEnergyDeposit(i, energyDeposit/MeV);
169 
170  else if (particleName == "alpha")
171  analysis -> SecondaryAlphaEnergyDeposit(i, energyDeposit/MeV);
172 
173  else if (particleName == "gamma")
174  analysis -> SecondaryGammaEnergyDeposit(i, energyDeposit/MeV);
175 
176  else if (particleName == "e-")
177  analysis -> SecondaryElectronEnergyDeposit(i, energyDeposit/MeV);
178 
179  else if (particleName == "triton")
180  analysis -> SecondaryTritonEnergyDeposit(i, energyDeposit/MeV);
181 
182  else if (particleName == "deuteron")
183  analysis -> SecondaryDeuteronEnergyDeposit(i, energyDeposit/MeV);
184 
185  else if (particleName == "pi+" || particleName == "pi-" ||
186  particleName == "pi0")
187  analysis -> SecondaryPionEnergyDeposit(i, energyDeposit/MeV);
188  }
189  }
190 
191  return true;
192 }
193 
196 {
197  static G4int HCID = -1;
198  if(HCID < 0)
199  {
200  HCID = GetCollectionID(0);
201  }
202 
203  HCE -> AddHitsCollection(HCID,HitsCollection);
204 }
205 
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
static const double MeV
Definition: G4SIunits.hh:211
A class for connecting the simulation to an analysis package.
void EndOfEvent(G4HCofThisEvent *HCE)
int G4int
Definition: G4Types.hh:78
virtual G4int GetCollectionID(G4int i)
IORTDetectorHitsCollection * HitsCollection
G4String sensitiveDetectorName
bool G4bool
Definition: G4Types.hh:79
IORTDetectorSD(G4String name)
void Initialize(G4HCofThisEvent *)
Definition: G4Step.hh:76
static IORTAnalysisManager * GetInstance()
Get the pointer to the analysis manager.
static IORTMatrix * GetInstance()
Definition: IORTMatrix.cc:61
G4CollectionNameVector collectionName
double G4double
Definition: G4Types.hh:76
G4THitsCollection< IORTDetectorHit > IORTDetectorHitsCollection