Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
HadrontherapyDetectorSD.cc
이 파일의 문서화 페이지로 가기
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 // Hadrontherapy advanced example for Geant4
27 // See more at: https://twiki.cern.ch/twiki/bin/view/Geant4/AdvancedExamplesHadrontherapy
28 
31 #include "G4Step.hh"
32 #include "G4VTouchable.hh"
33 #include "G4TouchableHistory.hh"
34 #include "G4SDManager.hh"
35 #include "HadrontherapyMatrix.hh"
36 #include "HadrontherapyLet.hh"
37 #include "G4Track.hh"
38 #include "G4SystemOfUnits.hh"
39 #include "HadrontherapyMatrix.hh"
40 
41 
42 #include "G4SteppingManager.hh"
43 #include "G4TrackVector.hh"
45 #include "G4ios.hh"
46 #include "G4SteppingManager.hh"
47 #include "G4Track.hh"
48 #include "G4Step.hh"
49 #include "G4StepPoint.hh"
50 #include "G4TrackStatus.hh"
51 #include "G4TrackVector.hh"
52 #include "G4ParticleDefinition.hh"
53 #include "G4ParticleTypes.hh"
54 #include "G4UserEventAction.hh"
56 #include "G4VSensitiveDetector.hh"
58 #include "G4SystemOfUnits.hh"
59 
60 
64 {
65  G4String HCname;
66  collectionName.insert(HCname="HadrontherapyDetectorHitsCollection");
67  HitsCollection = NULL;
69 
70 }
71 
74 {
75 }
76 
79 {
80 
82  collectionName[0]);
83 }
84 
87 {
88 
89 
90  if (aStep -> GetPreStepPoint() -> GetPhysicalVolume() -> GetName() != "RODetectorZDivisionPhys") return false;
91 
92 
93  // Get kinetic energy
94  G4Track * theTrack = aStep -> GetTrack();
95  G4double kineticEnergy = theTrack -> GetKineticEnergy();
96 
97  G4ParticleDefinition *particleDef = theTrack -> GetDefinition();
98  //Get particle name
99  G4String particleName = particleDef -> GetParticleName();
100 
101  G4int pdg = particleDef ->GetPDGEncoding();
102 
103  // Get unique track_id (in an event)
104  G4int trackID = theTrack -> GetTrackID();
105 
106  G4double energyDeposit = aStep -> GetTotalEnergyDeposit();
107 
108  G4double DX = aStep -> GetStepLength();
109  G4int Z = particleDef-> GetAtomicNumber();
110  G4int A = particleDef-> GetAtomicMass();
111  G4StepPoint* PreStep = aStep->GetPreStepPoint();
112 
113  // Read voxel indexes: i is the x index, k is the z index
114  const G4VTouchable* touchable = aStep->GetPreStepPoint()->GetTouchable();
115  G4int k = touchable->GetReplicaNumber(0);
116  G4int i = touchable->GetReplicaNumber(2);
117  G4int j = touchable->GetReplicaNumber(1);
118 
119  G4TouchableHandle touchPreStep = PreStep->GetTouchableHandle();
120  G4VPhysicalVolume* volumePre = touchPreStep->GetVolume();
121  G4String namePre = volumePre->GetName();
122  //G4double eKin = aStep -> GetPreStepPoint() -> GetKineticEnergy();
123 
124 
127 
128  G4int* hitTrack = matrix -> GetHitTrack(i,j,k);
129 
130 
131  // ******************** let ***************************
132  if (let)
133  {
134  if ( !(Z==0 && A==1) ) // All but not neutrons
135  {
136  if( energyDeposit>0. && DX >0. )
137  {
138  if (pdg !=22) // not gamma
139  {
140  let -> FillEnergySpectrum(trackID, particleDef,energyDeposit, DX, i, j, k);
141  }
142  else if (kineticEnergy > 50.*keV) // gamma cut
143  {
144  let -> FillEnergySpectrum(trackID, particleDef,energyDeposit, DX, i , j, k);
145  }
146 
147  }
148  }
149  }
150 
151 
152  if (matrix)
153  {
154 
155  // Increment Fluences & accumulate energy spectra
156  // Hit voxels are marked with track_id throught hitTrack matrix
157  //G4int* hitTrack = matrix -> GetHitTrack(i,j,k); // hitTrack MUST BE cleared at every eventAction!
158  if ( *hitTrack != trackID )
159  {
160  *hitTrack = trackID;
161  /*
162  * Fill FLUENCE data for every single nuclide
163  * Exclude e-, neutrons, gamma, ...
164  */
165  if ( Z >= 1) matrix -> Fill(trackID, particleDef, i, j, k, 0, true);
166 
167  }
168 
169  if(energyDeposit != 0)
170  {
171  /*
172  * This method will fill a dose matrix for every single nuclide.
173  * A method of the HadrontherapyMatrix class (StoreDoseFluenceAscii())
174  * is called automatically at the end of main (or via the macro command /analysis/writeDoseFile.
175  * It permits to store all dose/fluence data into a single plane ASCII file.
176  */
177  // if (A==1 && Z==1) // primary and sec. protons
178  if ( Z>=1 ) // exclude e-, neutrons, gamma, ...
179  matrix -> Fill(trackID, particleDef, i, j, k, energyDeposit);
180  /*
181  * Create a hit with the information of position is in the detector
182  */
184  detectorHit -> SetEdepAndPosition(i, j, k, energyDeposit);
185  HitsCollection -> insert(detectorHit);
186  }
187  }
188  return true;
189 }
190 
193 {
194 
195  static G4int HCID = -1;
196  if(HCID < 0)
197  {
198  HCID = GetCollectionID(0);
199  }
200 
201  HCE -> AddHitsCollection(HCID,HitsCollection);
202 }
203 
virtual G4int GetCollectionID(G4int i)
ntupleExperimental Fill(depthExp, EdepExp)
const XML_Char * name
Definition: expat.h:151
void EndOfEvent(G4HCofThisEvent *HCE)
const G4VTouchable * GetTouchable() const
HadrontherapyDetectorHitsCollection * HitsCollection
G4StepPoint * GetPreStepPoint() const
G4THitsCollection< HadrontherapyDetectorHit > HadrontherapyDetectorHitsCollection
static constexpr double keV
Definition: G4SIunits.hh:216
static HadrontherapyMatrix * GetInstance()
virtual G4VPhysicalVolume * GetVolume(G4int depth=0) const
Definition: G4VTouchable.cc:44
static HadrontherapyLet * GetInstance()
const G4TouchableHandle & GetTouchableHandle() const
Float_t Z
void Initialize(G4HCofThisEvent *)
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
double A(double temperature)
Definition: G4Step.hh:76
int G4int
Definition: G4Types.hh:78
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROhist)
G4CollectionNameVector collectionName
virtual G4int GetReplicaNumber(G4int depth=0) const
Definition: G4VTouchable.cc:58
const G4String & GetName() const