Geant4  10.02.p02
TrackerSD.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 example is provided by the Geant4-DNA collaboration
27 // Any report or published results obtained using the Geant4-DNA software
28 // shall cite the following Geant4-DNA collaboration publication:
29 // Med. Phys. 37 (2010) 4692-4708
30 // The Geant4-DNA web site is available at http://geant4-dna.org
31 //
32 // $Id: TrackerSD.cc 87359 2014-12-01 16:04:27Z gcosmo $
33 //
36 
37 #include "TrackerSD.hh"
38 #include "G4SDManager.hh"
39 
40 #include "Randomize.hh"
41 #include "G4RandomDirection.hh"
42 #include "G4SystemOfUnits.hh"
43 #include "Analysis.hh"
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
46 
48  const G4String& hitsCollectionName)
49  : G4VSensitiveDetector(name),
50  fHitsCollection(NULL)
51 {
52  collectionName.insert(hitsCollectionName);
53 }
54 
55 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
56 
58 {}
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
63 {
64  // Create hits collection
65 
68 
69  // Add this collection in hce
70 
71  G4int hcID
73  hce->AddHitsCollection( hcID, fHitsCollection );
74 }
75 
76 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
77 
80 {
81  // energy deposit
82  G4double edep = aStep->GetTotalEnergyDeposit();
83 
84  if (edep==0.) return false;
85 
86  TrackerHit* newHit = new TrackerHit();
87 
88  newHit->SetTrackID (aStep->GetTrack()->GetTrackID());
89  newHit->SetEdep(edep);
90  newHit->SetPos (aStep->GetPostStepPoint()->GetPosition());
91 
92  fHitsCollection->insert( newHit );
93 
94  //newHit->Print();
95 
96  return true;
97 }
98 
99 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
100 
102 {
103  G4int nofHits = fHitsCollection->entries();
104 
105  if ( verboseLevel>1 )
106 
107  G4cout << G4endl
108  << "-------->Hits Collection: in this event they are "
109  << nofHits
110  << " hits in the target volume " << G4endl;
111 
112  // PROCESSING OF MICRODOSIMETRY Y & Z SPECTRA
113 
114  // main loop
115 
116  // *************************************
117  // Please select herebelow :
118  // 1 - the number of sampling per incident envent
119  // variable name = nbSampling
120  // (it is set to 100 by default)
121  //
122  //
123  // 2 - the radius of the target sphere
124  // variable name = radius
125  // (it is set to 50 nm by default)
126  //
127 
128  G4int nbSampling = 1000;
129  G4double radius = 1.50*um;
130 
131  // ************************************
132 
133  for ( G4int k=0; k<nbSampling; k++ )
134  {
135 
136  //***************
137  // FIRST SAMPLING: Y
138  //***************
139 
140  // select random hit
141  G4int randHit=0; // Runs from 0 to number of hits - 1
142  randHit = static_cast<G4int>( G4UniformRand()*nofHits );
143 
144  //G4cout << static_cast<G4int>(2.7)
145  //<< "======> random selection of hit number randHit ="
146  // << randHit << G4endl;
147 
148  // get random hit position
149  G4ThreeVector hitPos = (*fHitsCollection)[randHit]->GetPos();
150  //G4cout << "======> random hit position x/nm =" << hitPos.x()/nm << G4endl;
151  //G4cout << "======> random hit position y/nm =" << hitPos.y()/nm << G4endl;
152  //G4cout << "======> random hit position z/nm =" << hitPos.z()/nm << G4endl;
153 
154  // select random center of sphere within radius
155  G4double chord = 4.*radius/3;
156  //G4double density = 1 * g/cm3;
157  //G4double mass = (4./3)*CLHEP::pi*radius*radius*radius*density;
158 
159  G4ThreeVector randDir = G4RandomDirection();
160  G4double randRadius = G4UniformRand()*radius;
161  G4ThreeVector randCenterPos = randRadius*randDir + hitPos;
162 
163  // search for neighbouring hits in the sphere and cumulate deposited energy
164  // in epsilon
165  G4double epsilon = 0;
166  G4int nbEdep = 0;
167 
168  for ( G4int i=0; i<nofHits; i++ )
169  {
170  G4ThreeVector localPos = (*fHitsCollection)[i]->GetPos();;
171  if (
172  (localPos.x()-randCenterPos.x()) * (localPos.x()-randCenterPos.x()) +
173  (localPos.y()-randCenterPos.y()) * (localPos.y()-randCenterPos.y()) +
174  (localPos.z()-randCenterPos.z()) * (localPos.z()-randCenterPos.z())
175  <= radius*radius
176  )
177 
178  {
179  epsilon = epsilon + (*fHitsCollection)[i]->GetEdep() ;
180  nbEdep = nbEdep+1;
181  }
182 
183  }
184 
185 
186  //***************
187 
188  /*
189  // for testing only
190 
191  G4cout << "======> for hit number #" << randHit <<
192  ", we collect "
193  << nbEdep << " energy depositions in a sphere of radius "
194  << radius/nm << " nm and mass "
195  << mass/kg << " kg for a total of "
196  << epsilon/eV << " eV or "
197  << (epsilon/joule)/(mass/kg) << " Gy" << G4endl;
198  G4cout << "-" << G4endl;
199 
200  FILE* myFile;
201  myFile=fopen("yz.txt","a");
202  fprintf(myFile,"%e %e %e\n",radius/nm,(epsilon/eV)/(chord/nm),
203  (epsilon/joule)/(mass/kg));
204  fclose(myFile);
205  */
206 
207  // get analysis manager
208  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
209 
210  // fill ntuple
211  analysisManager->FillNtupleDColumn(0, radius/nm);
212  analysisManager->FillNtupleDColumn(1, (epsilon/eV)/(chord/nm));
213  analysisManager->AddNtupleRow();
214 
215  } // END MAIN LOOP ON SAMPLING
216 
217 }
218 
219 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
void SetTrackID(G4int track)
Definition: TrackerHit.hh:69
virtual G4bool ProcessHits(G4Step *step, G4TouchableHistory *history)
Definition: TrackerSD.cc:78
G4THitsCollection< TrackerHit > TrackerHitsCollection
Definition: TrackerHit.hh:87
Definition of the TrackerSD class.
virtual void EndOfEvent(G4HCofThisEvent *hitCollection)
Definition: TrackerSD.cc:101
G4int GetCollectionID(G4String colName)
Definition: G4SDManager.cc:135
CLHEP::Hep3Vector G4ThreeVector
Tracker hit class.
Definition: TrackerHit.hh:50
G4String name
Definition: TRTMaterials.hh:40
G4int entries() const
G4ThreeVector G4RandomDirection()
G4int insert(T *aHit)
int G4int
Definition: G4Types.hh:78
void SetPos(G4ThreeVector xyz)
Definition: TrackerHit.hh:71
virtual void Initialize(G4HCofThisEvent *hitCollection)
Definition: TrackerSD.cc:62
#define G4UniformRand()
Definition: Randomize.hh:97
G4GLOB_DLL std::ostream G4cout
const G4ThreeVector & GetPosition() const
bool G4bool
Definition: G4Types.hh:79
static const double nm
Definition: G4SIunits.hh:111
ExG4HbookAnalysisManager G4AnalysisManager
Definition: g4hbook_defs.hh:66
Definition: G4Step.hh:76
G4int GetTrackID() const
TrackerSD(const G4String &name, const G4String &hitsCollectionName)
Definition: TrackerSD.cc:47
G4double GetTotalEnergyDeposit() const
void AddHitsCollection(G4int HCID, G4VHitsCollection *aHC)
TrackerHitsCollection * fHitsCollection
Definition: TrackerSD.hh:65
static const double eV
Definition: G4SIunits.hh:212
G4StepPoint * GetPostStepPoint() const
static G4SDManager * GetSDMpointer()
Definition: G4SDManager.cc:40
void SetEdep(G4double de)
Definition: TrackerHit.hh:70
static const double um
Definition: G4SIunits.hh:112
#define G4endl
Definition: G4ios.hh:61
G4CollectionNameVector collectionName
double G4double
Definition: G4Types.hh:76
virtual ~TrackerSD()
Definition: TrackerSD.cc:57
G4Track * GetTrack() const
double epsilon(double density, double temperature)