ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
TrackerSD.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file TrackerSD.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 // 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 publications:
29 // Phys. Med. 31 (2015) 861-874
30 // Med. Phys. 37 (2010) 4692-4708
31 // The Geant4-DNA web site is available at http://geant4-dna.org
32 //
35 
36 #include "Analysis.hh"
37 #include "TrackerSD.hh"
38 #include "Randomize.hh"
39 #include "G4SDManager.hh"
40 
41 #include "G4RandomDirection.hh"
42 #include "G4SystemOfUnits.hh"
43 
44 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
45 
47  const G4String& hitsCollectionName)
49 fHitsCollection(NULL)
50 {
51  collectionName.insert(hitsCollectionName);
52 }
53 
54 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
55 
57 {}
58 
59 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
60 
62 {
63  // Create hits collection
66 
67  // Add this collection in hce
68 
69  G4int hcID
71 
72  hce->AddHitsCollection( hcID, fHitsCollection );
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
76 
79 {
80  // energy deposit
82 
83  if (edep==0.) return false;
84 
85  TrackerHit* newHit = new TrackerHit();
86 
87  newHit->SetTrackID (aStep->GetTrack()->GetTrackID());
88  newHit->SetEdep(edep);
89  newHit->SetPos (aStep->GetPostStepPoint()->GetPosition());
90 
91  if (aStep->GetTrack()->GetTrackID()==1&&aStep->GetTrack()->GetParentID()==0)
93 
94  fHitsCollection->insert( newHit );
95 
96  //newHit->Print();
97 
98  return true;
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
102 
104 {
105  G4int nofHits = fHitsCollection->entries();
106 
107  G4double Einc=0;
108 
109  /*
110  G4cout << G4endl
111  << "-------->Hits Collection: in this event they are "
112  << nofHits
113  << " hits in the target volume " << G4endl;
114  */
115 
116  // PROCESSING OF MICRODOSIMETRY Y & Z SPECTRA
117 
118  // *************************************
119  // Please select herebelow :
120  // the radius of the target sphere:
121  // variable name = radius
122  // it is set to 5 nm by default)
123  //
124 
125  G4double radius = 5*nm;
126 
127  //
128 
129  //***************
130  // y and z
131  //***************
132 
133  // select random hit
134  G4int randHit=0; // Runs from 0 to number of hits - 1
135  randHit = static_cast<G4int>( G4UniformRand()*nofHits );
136 
137  /*
138  G4cout
139  << "======> random selection of hit number randHit ="
140  << randHit << G4endl;
141  */
142 
143  // get selected random hit position
144  G4ThreeVector hitPos = (*fHitsCollection)[randHit]->GetPos();
145 //G4cout << "======> random hit position x/nm =" << hitPos.x()/nm << G4endl;
146 //G4cout << "======> random hit position y/nm =" << hitPos.y()/nm << G4endl;
147 //G4cout << "======> random hit position z/nm =" << hitPos.z()/nm << G4endl;
148 
149  // set random position of center of sphere within radius
150  G4double chord = 4.*radius/3;
151  G4double density = 1 * g/cm3;
152  G4double mass = (4./3)*CLHEP::pi*radius*radius*radius*density;
153 
154  // random placement of sphere: method 1
155  /*
156  G4ThreeVector randDir = G4RandomDirection();
157  G4double randRadius = G4UniformRand()*radius;
158  G4ThreeVector randCenterPos = randRadius*randDir + hitPos;
159  */
160 
161  // random placement of sphere: method 2
162 
163  G4double xRand = 1.01*radius;
164  G4double yRand = 1.01*radius;
165  G4double zRand = 1.01*radius;
166  G4double randRad = 1.01*radius;
167  do
168  {
169  xRand = (2*G4UniformRand()-1)*radius;
170  yRand = (2*G4UniformRand()-1)*radius;
171  zRand = (2*G4UniformRand()-1)*radius;
172  randRad = std::sqrt( xRand*xRand+yRand*yRand+zRand*zRand );
173  }
174  while (randRad>radius);
175 
177  randCenterPos(xRand+hitPos.x(),yRand+hitPos.y(),zRand+hitPos.z());
178 
179  // search for neighbouring hits in the sphere and cumulate deposited energy
180  // in epsilon
181  G4double epsilon = 0;
182  G4int nbEdep = 0;
183 
184  for ( G4int i=0; i<nofHits; i++ )
185  {
186 
187  if ((*fHitsCollection)[i]->GetIncidentEnergy()>0)
188  Einc = (*fHitsCollection)[i]->GetIncidentEnergy();
189 
190  G4ThreeVector localPos = (*fHitsCollection)[i]->GetPos();
191 
192  // G4cout << i << " " << (*fHitsCollection)[i] << G4endl;
193  // G4cout << i << " " << (*fHitsCollection)[i]->GetEdep()/eV << G4endl;
194 
195  if (
196  (localPos.x()-randCenterPos.x()) * (localPos.x()-randCenterPos.x()) +
197  (localPos.y()-randCenterPos.y()) * (localPos.y()-randCenterPos.y()) +
198  (localPos.z()-randCenterPos.z()) * (localPos.z()-randCenterPos.z())
199  <= radius*radius
200  )
201 
202  {
203  epsilon = epsilon + (*fHitsCollection)[i]->GetEdep() ;
204  nbEdep = nbEdep+1;
205  }
206 
207  }
208 
209  // for testing only
210  /*
211  G4cout << "======> for hit number #" << randHit <<
212  ", we collect "
213  << nbEdep << " energy depositions in a sphere of radius "
214  << radius/nm << " nm and mass "
215  << mass/kg << " kg for a total of "
216  << epsilon/eV << " eV or "
217  << (epsilon/joule)/(mass/kg) << " Gy" << G4endl;
218  G4cout << "-" << G4endl;
219  */
220 
221  /*
222  FILE* myFile;
223  myFile=fopen("yz.txt","a");
224  fprintf(myFile,"%e %e %e\n",radius/nm,(epsilon/eV)/(chord/nm),
225  (epsilon/joule)/(mass/kg));
226  fclose(myFile);
227  */
228 
229  // get analysis manager
230  G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
231 
232  // fill ntuple including weighting
233  analysisManager->FillNtupleDColumn(0, radius/nm);
234  analysisManager->FillNtupleDColumn(2, nofHits);
235  analysisManager->FillNtupleDColumn(3, nbEdep);
236  analysisManager->FillNtupleDColumn(4, (epsilon/eV)/(chord/nm));
237  analysisManager->FillNtupleDColumn(5, (epsilon/mass)/gray);
238  analysisManager->FillNtupleDColumn(6, Einc/eV);
239  analysisManager->AddNtupleRow();
240 
241 }
242 
243 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......