Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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
39 //////////////////////////////////////////////////////////////////////////////////////////////
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 
52 /////////////////////////////////////////////////////////////////////////////
55 {
56  G4String HCname;
57  collectionName.insert(HCname="IORTDetectorHitsCollection");
58  HitsCollection = NULL;
59  sensitiveDetectorName = dname;
60 }
61 
62 /////////////////////////////////////////////////////////////////////////////
64 {
65 }
66 
67 /////////////////////////////////////////////////////////////////////////////
69 {
70  HitsCollection = new IORTDetectorHitsCollection(sensitiveDetectorName,
71  collectionName[0]);
72 }
73 
74 /////////////////////////////////////////////////////////////////////////////
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 
104 #ifdef G4ANALYSIS_USE_ROOT
106 #endif
107 
109 
110  if (matrix)
111  {
112 
113  // Increment Fluences & accumulate energy spectra
114  // Hit voxels are marked with track_id throught hitTrack matrix
115  G4int* hitTrack = matrix -> GetHitTrack(i,j,k); // hitTrack MUST BE cleared at every eventAction!
116  if ( *hitTrack != trackID )
117  {
118  *hitTrack = trackID;
119  /*
120  * Fill FLUENCE data for every single nuclide
121  * Exclude e-, neutrons, gamma, ...
122  */
123  if ( Z >= 1)
124  matrix -> Fill(trackID, particleDef, i, j, k, 0, true);
125 #ifdef G4ANALYSIS_USE_ROOT
126 /*
127  // Fragments kinetic energy (ntuple)
128  if (trackID !=1 && Z>=1)
129  {
130  // First step kinetic energy for every fragment
131  analysis -> FillKineticFragmentTuple(i, j, k, A, Z, kineticEnergy/MeV);
132  }
133  // Kinetic energy spectra for primary particles
134 
135  if ( trackID == 1 && i == 0)
136  {
137  // First step kinetic energy for primaries only
138  analysis -> FillKineticEnergyPrimaryNTuple(i, j, k, kineticEnergy/MeV);
139  }
140 */
141 #endif
142  }
143 
144  if(energyDeposit != 0)
145  {
146 /*
147  * This method will fill a dose matrix for every single nuclide.
148  * A method of the IORTMatrix class (StoreDoseFluenceAscii())
149  * is called automatically at the end of main (or via the macro command /analysis/writeDoseFile.
150  * It permits to store all dose/fluence data into a single plane ASCII file.
151 */
152  // if (A==1 && Z==1) // primary and sec. protons
153  if ( Z>=1 ) // exclude e-, neutrons, gamma, ...
154  matrix -> Fill(trackID, particleDef, i, j, k, energyDeposit);
155  /*
156  * Create a hit with the information of position is in the detector
157  */
158  IORTDetectorHit* detectorHit = new IORTDetectorHit();
159  detectorHit -> SetEdepAndPosition(i, j, k, energyDeposit);
160  HitsCollection -> insert(detectorHit);
161  }
162  }
163 
164 #ifdef G4ANALYSIS_USE_ROOT
165  if(energyDeposit != 0)
166  {
167  if(trackID != 1)
168  {
169  if (particleName == "proton")
170  analysis -> SecondaryProtonEnergyDeposit(i, energyDeposit/MeV);
171 
172  else if (particleName == "neutron")
173  analysis -> SecondaryNeutronEnergyDeposit(i, energyDeposit/MeV);
174 
175  else if (particleName == "alpha")
176  analysis -> SecondaryAlphaEnergyDeposit(i, energyDeposit/MeV);
177 
178  else if (particleName == "gamma")
179  analysis -> SecondaryGammaEnergyDeposit(i, energyDeposit/MeV);
180 
181  else if (particleName == "e-")
182  analysis -> SecondaryElectronEnergyDeposit(i, energyDeposit/MeV);
183 
184  else if (particleName == "triton")
185  analysis -> SecondaryTritonEnergyDeposit(i, energyDeposit/MeV);
186 
187  else if (particleName == "deuteron")
188  analysis -> SecondaryDeuteronEnergyDeposit(i, energyDeposit/MeV);
189 
190  else if (particleName == "pi+" || particleName == "pi-" || particleName == "pi0")
191  analysis -> SecondaryPionEnergyDeposit(i, energyDeposit/MeV);
192  }
193  }
194 #endif
195 
196  return true;
197 }
198 
199 /////////////////////////////////////////////////////////////////////////////
201 {
202  static G4int HCID = -1;
203  if(HCID < 0)
204  {
205  HCID = GetCollectionID(0);
206  }
207 
208  HCE -> AddHitsCollection(HCID,HitsCollection);
209 }
210 
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
void EndOfEvent(G4HCofThisEvent *HCE)
int G4int
Definition: G4Types.hh:78
virtual G4int GetCollectionID(G4int i)
bool G4bool
Definition: G4Types.hh:79
IORTDetectorSD(G4String name)
void Initialize(G4HCofThisEvent *)
Definition: G4Step.hh:76
static IORTAnalysisManager * GetInstance()
static IORTMatrix * GetInstance()
Definition: IORTMatrix.cc:61
G4CollectionNameVector collectionName
double G4double
Definition: G4Types.hh:76
G4THitsCollection< IORTDetectorHit > IORTDetectorHitsCollection