Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HadrontherapyDetectorSD.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 Hadrontherapy, a Geant4-based application
27 // See more at: http://g4advancedexamples.lngs.infn.it/Examples/hadrontherapy
28 //
29 // Visit the Hadrontherapy web site (http://www.lns.infn.it/link/Hadrontherapy) to request
30 // the *COMPLETE* version of this program, together with its documentation;
31 // Hadrontherapy (both basic and full version) are supported by the Italian INFN
32 // Institute in the framework of the MC-INFN Group
33 //
34 
36 
40 #include "G4Step.hh"
41 #include "G4VTouchable.hh"
42 #include "G4TouchableHistory.hh"
43 #include "G4SDManager.hh"
44 #include "HadrontherapyMatrix.hh"
45 
49 {
50  G4String HCname;
51  collectionName.insert(HCname="HadrontherapyDetectorHitsCollection");
52  HitsCollection = NULL;
53  sensitiveDetectorName = name;
54 
55 }
56 
59 {
60 }
61 
64 {
65  HitsCollection = new HadrontherapyDetectorHitsCollection(sensitiveDetectorName,
66  collectionName[0]);
67 }
68 
71 {
72  //The code doesn't seem to get here if we use the IAEA geometry. FIXME
73  if(!ROhist)
74  return false;
75 
76  if (aStep -> GetPreStepPoint() -> GetPhysicalVolume() -> GetName() != "DetectorPhys")
77  return false;
78  // Get kinetic energy
79  G4Track * theTrack = aStep -> GetTrack();
80  //G4double kineticEnergy = theTrack -> GetKineticEnergy();
81 
82  G4ParticleDefinition *particleDef = theTrack -> GetDefinition();
83  //Get particle name
84  G4String particleName = particleDef -> GetParticleName();
85  // G4cout << particleDef -> GetParticleType() << '\n';
86  // Get unique track_id (in an event)
87  G4int trackID = theTrack -> GetTrackID();
88 
89  G4double energyDeposit = aStep -> GetTotalEnergyDeposit();
90 
91  G4int Z = particleDef-> GetAtomicNumber();
92  //G4int A = particleDef-> GetAtomicMass();
93 
94  // Read voxel indexes: i is the x index, k is the z index
95  G4int k = ROhist -> GetReplicaNumber(0);
96  G4int i = ROhist -> GetReplicaNumber(2);
97  G4int j = ROhist -> GetReplicaNumber(1);
98 
99 #ifdef G4ANALYSIS_USE_ROOT
101 #endif
102 
104 
105  if (matrix)
106  {
107 
108  // Increment Fluences & accumulate energy spectra
109  // Hit voxels are marked with track_id throught hitTrack matrix
110  G4int* hitTrack = matrix -> GetHitTrack(i,j,k); // hitTrack MUST BE cleared at every eventAction!
111  if ( *hitTrack != trackID )
112  {
113  *hitTrack = trackID;
114  /*
115  * Fill FLUENCE data for every single nuclide
116  * Exclude e-, neutrons, gamma, ...
117  */
118  if ( Z >= 1)
119  matrix -> Fill(trackID, particleDef, i, j, k, 0, true);
120 #ifdef G4ANALYSIS_USE_ROOT
121 /*
122  // Fragments kinetic energy (ntuple)
123  if (trackID !=1 && Z>=1)
124  {
125  // First step kinetic energy for every fragment
126  analysis -> FillKineticFragmentTuple(i, j, k, A, Z, kineticEnergy/MeV);
127  }
128  // Kinetic energy spectra for primary particles
129 
130  if ( trackID == 1 && i == 0)
131  {
132  // First step kinetic energy for primaries only
133  analysis -> FillKineticEnergyPrimaryNTuple(i, j, k, kineticEnergy/MeV);
134  }
135 */
136 #endif
137  }
138 
139  if(energyDeposit != 0)
140  {
141 /*
142  * This method will fill a dose matrix for every single nuclide.
143  * A method of the HadrontherapyMatrix class (StoreDoseFluenceAscii())
144  * is called automatically at the end of main (or via the macro command /analysis/writeDoseFile.
145  * It permits to store all dose/fluence data into a single plane ASCII file.
146 */
147  // if (A==1 && Z==1) // primary and sec. protons
148  if ( Z>=1 ) // exclude e-, neutrons, gamma, ...
149  matrix -> Fill(trackID, particleDef, i, j, k, energyDeposit);
150  /*
151  * Create a hit with the information of position is in the detector
152  */
154  detectorHit -> SetEdepAndPosition(i, j, k, energyDeposit);
155  HitsCollection -> insert(detectorHit);
156  }
157  }
158 
159 #ifdef G4ANALYSIS_USE_ROOT
160  if(energyDeposit != 0)
161  {
162  if(trackID != 1)
163  {
164  if (particleName == "proton")
165  analysis -> SecondaryProtonEnergyDeposit(i, energyDeposit/CLHEP::MeV);
166 
167  else if (particleName == "neutron")
168  analysis -> SecondaryNeutronEnergyDeposit(i, energyDeposit/CLHEP::MeV);
169 
170  else if (particleName == "alpha")
171  analysis -> SecondaryAlphaEnergyDeposit(i, energyDeposit/CLHEP::MeV);
172 
173  else if (particleName == "gamma")
174  analysis -> SecondaryGammaEnergyDeposit(i, energyDeposit/CLHEP::MeV);
175 
176  else if (particleName == "e-")
177  analysis -> SecondaryElectronEnergyDeposit(i, energyDeposit/CLHEP::MeV);
178 
179  else if (particleName == "triton")
180  analysis -> SecondaryTritonEnergyDeposit(i, energyDeposit/CLHEP::MeV);
181 
182  else if (particleName == "deuteron")
183  analysis -> SecondaryDeuteronEnergyDeposit(i, energyDeposit/CLHEP::MeV);
184 
185  else if (particleName == "pi+" || particleName == "pi-" || particleName == "pi0")
186  analysis -> SecondaryPionEnergyDeposit(i, energyDeposit/CLHEP::MeV);
187  }
188  }
189 #endif
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