source: trunk/examples/advanced/hadrontherapy/src/HadrontherapyPhantomSD.cc @ 1317

Last change on this file since 1317 was 807, checked in by garnier, 16 years ago

update

File size: 5.4 KB
Line 
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// $Id: HadrontherapyPhantomSD.cc; May 2005
27// ----------------------------------------------------------------------------
28//                 GEANT 4 - Hadrontherapy example
29// ----------------------------------------------------------------------------
30// Code developed by:
31//
32// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
33//
34// (a) Laboratori Nazionali del Sud
35//     of the National Institute for Nuclear Physics, Catania, Italy
36// (b) National Institute for Nuclear Physics Section of Genova, genova, Italy
37//
38// * cirrone@lns.infn.it
39// ----------------------------------------------------------------------------
40
41#include "HadrontherapyPhantomSD.hh"
42#include "HadrontherapyAnalysisManager.hh"
43#include "HadrontherapyPhantomHit.hh"
44#include "G4Step.hh"
45#include "G4VTouchable.hh"
46#include "G4TouchableHistory.hh"
47#include "G4SDManager.hh"
48
49HadrontherapyPhantomSD::HadrontherapyPhantomSD(G4String name):G4VSensitiveDetector(name)
50{ 
51  G4String HCname;
52  collectionName.insert(HCname="HadrontherapyPhantomHitsCollection");
53 
54  HitsCollection = NULL; 
55  G4String sensitiveDetectorName = name;
56}
57
58HadrontherapyPhantomSD::~HadrontherapyPhantomSD()
59{ 
60}
61
62void HadrontherapyPhantomSD::Initialize(G4HCofThisEvent*)
63{ 
64  HitsCollection = new HadrontherapyPhantomHitsCollection(sensitiveDetectorName,
65                                                          collectionName[0]);
66}
67
68
69G4bool HadrontherapyPhantomSD::ProcessHits(G4Step* aStep, G4TouchableHistory* ROhist)
70{
71  if(!ROhist)
72    return false;
73 
74  if(aStep -> GetPreStepPoint() -> GetPhysicalVolume() -> GetName() != "PhantomPhys")
75    return false;
76
77  G4double energyDeposit = aStep -> GetTotalEnergyDeposit();
78 
79  if(energyDeposit == 0.) return false;
80
81  // Read voxel indexes: i is the x index, k is the z index
82
83  G4int k  = ROhist -> GetReplicaNumber(0);
84  G4int i  = ROhist -> GetReplicaNumber(2);
85  G4int j  = ROhist -> GetReplicaNumber(1);
86 
87  G4String particleName = aStep -> GetTrack() -> GetDynamicParticle() -> 
88                           GetDefinition() -> GetParticleName();
89
90  if(energyDeposit != 0)                       
91    { 
92      // Create a hit with the information of position in the phantom and energy deposit     
93      HadrontherapyPhantomHit* phantomHit = new HadrontherapyPhantomHit();       
94      phantomHit -> SetEdepAndPosition(i, j, k, energyDeposit); 
95      HitsCollection -> insert(phantomHit);
96    }
97
98  // Energy deposit of secondary particles along X (integrated on Y and Z)
99#ifdef G4ANALYSIS_USE   
100
101 HadrontherapyAnalysisManager* analysis = 
102                        HadrontherapyAnalysisManager::getInstance();
103
104 if(energyDeposit != 0)                       
105    { 
106   
107 if(aStep -> GetTrack() -> GetTrackID()!= 1)
108   {
109     if (particleName == "proton")
110           analysis -> SecondaryProtonEnergyDeposit(i, energyDeposit/MeV);
111 
112     if (particleName == "neutron")
113     analysis -> SecondaryNeutronEnergyDeposit(i, energyDeposit/MeV);
114
115     if (particleName == "alpha")
116       analysis -> SecondaryAlphaEnergyDeposit(i, energyDeposit/MeV);
117
118     if (particleName == "gamma")
119       analysis -> SecondaryGammaEnergyDeposit(i, energyDeposit/MeV);
120       
121     if (particleName == "e-")
122       analysis -> SecondaryElectronEnergyDeposit(i, energyDeposit/MeV);
123       
124     if (particleName == "triton")
125       analysis -> SecondaryTritonEnergyDeposit(i, energyDeposit/MeV);
126 
127     if (particleName == "deuteron")
128       analysis -> SecondaryDeuteronEnergyDeposit(i, energyDeposit/MeV);
129       
130    if (particleName == "pi+" || particleName == "pi-" ||  particleName == "pi0")
131       analysis -> SecondaryPionEnergyDeposit(i, energyDeposit/MeV);   
132   }
133    }
134#endif
135
136  return true;
137}
138
139void HadrontherapyPhantomSD::EndOfEvent(G4HCofThisEvent* HCE)
140{
141  static G4int HCID = -1;
142  if(HCID < 0)
143    { 
144      HCID = GetCollectionID(0); 
145    }
146  HCE -> AddHitsCollection(HCID,HitsCollection);
147}
148
Note: See TracBrowser for help on using the repository browser.