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 10.5 ] [ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

Diff markup

Differences between /examples/extended/medical/dna/microyz/src/TrackerSD.cc (Version 11.3.0) and /examples/extended/medical/dna/microyz/src/TrackerSD.cc (Version 9.4.p4)


  1 //                                                  1 
  2 // *******************************************    
  3 // * License and Disclaimer                       
  4 // *                                              
  5 // * The  Geant4 software  is  copyright of th    
  6 // * the Geant4 Collaboration.  It is provided    
  7 // * conditions of the Geant4 Software License    
  8 // * LICENSE and available at  http://cern.ch/    
  9 // * include a list of copyright holders.         
 10 // *                                              
 11 // * Neither the authors of this software syst    
 12 // * institutes,nor the agencies providing fin    
 13 // * work  make  any representation or  warran    
 14 // * regarding  this  software system or assum    
 15 // * use.  Please see the license in the file     
 16 // * for the full disclaimer and the limitatio    
 17 // *                                              
 18 // * This  code  implementation is the result     
 19 // * technical work of the GEANT4 collaboratio    
 20 // * By using,  copying,  modifying or  distri    
 21 // * any work based  on the software)  you  ag    
 22 // * use  in  resulting  scientific  publicati    
 23 // * acceptance of all terms of the Geant4 Sof    
 24 // *******************************************    
 25 //                                                
 26 // This example is provided by the Geant4-DNA     
 27 // Any report or published results obtained us    
 28 // shall cite the following Geant4-DNA collabo    
 29 // Med. Phys. 45 (2018) e722-e739                 
 30 // Phys. Med. 31 (2015) 861-874                   
 31 // Med. Phys. 37 (2010) 4692-4708                 
 32 // Int. J. Model. Simul. Sci. Comput. 1 (2010)    
 33 // The Geant4-DNA web site is available at htt    
 34 //                                                
 35 /// \file TrackerSD.cc                            
 36 /// \brief Implementation of the TrackerSD cla    
 37                                                   
 38 #include "TrackerSD.hh"                           
 39                                                   
 40 #include "G4AnalysisManager.hh"                   
 41 #include "G4SDManager.hh"                         
 42 #include "G4SystemOfUnits.hh"                     
 43 #include "Randomize.hh"                           
 44                                                   
 45 //....oooOO0OOooo........oooOO0OOooo........oo    
 46                                                   
 47 TrackerSD::TrackerSD(const G4String& name, con    
 48   : G4VSensitiveDetector(name), fHitsCollectio    
 49 {                                                 
 50   collectionName.insert(hitsCollectionName);      
 51 }                                                 
 52                                                   
 53 //....oooOO0OOooo........oooOO0OOooo........oo    
 54                                                   
 55 TrackerSD::~TrackerSD() = default;                
 56                                                   
 57 //....oooOO0OOooo........oooOO0OOooo........oo    
 58                                                   
 59 void TrackerSD::Initialize(G4HCofThisEvent* hc    
 60 {                                                 
 61   // Create hits collection                       
 62   fHitsCollection = new TrackerHitsCollection(    
 63                                                   
 64   // Add this collection in hce                   
 65   G4int hcID = G4SDManager::GetSDMpointer()->G    
 66                                                   
 67   hce->AddHitsCollection(hcID, fHitsCollection    
 68 }                                                 
 69                                                   
 70 //....oooOO0OOooo........oooOO0OOooo........oo    
 71                                                   
 72 G4bool TrackerSD::ProcessHits(G4Step* aStep, G    
 73 {                                                 
 74   // Energy deposit                               
 75   G4double edep = aStep->GetTotalEnergyDeposit    
 76                                                   
 77   if (edep == 0.) return false;                   
 78                                                   
 79   auto newHit = new TrackerHit();                 
 80                                                   
 81   newHit->SetTrackID(aStep->GetTrack()->GetTra    
 82   newHit->SetEdep(edep);                          
 83   newHit->SetPos(aStep->GetPostStepPoint()->Ge    
 84                                                   
 85   if (aStep->GetTrack()->GetTrackID() == 1 &&     
 86     newHit->SetIncidentEnergy(aStep->GetTrack(    
 87   }                                               
 88   fHitsCollection->insert(newHit);                
 89   // newHit->Print();                             
 90                                                   
 91   return true;                                    
 92 }                                                 
 93                                                   
 94 void TrackerSD::SetRadius(const G4double& valu    
 95 {                                                 
 96   fRadius = value;                                
 97 }                                                 
 98                                                   
 99 //....oooOO0OOooo........oooOO0OOooo........oo    
100                                                   
101 void TrackerSD::EndOfEvent(G4HCofThisEvent*)      
102 {                                                 
103   G4int nofHits = fHitsCollection->entries();     
104                                                   
105   G4double Einc = 0;                              
106                                                   
107   /*                                              
108   G4cout << G4endl                                
109   << "-------->Hits Collection: in this event     
110   << nofHits                                      
111   << " hits in the target volume " << G4endl;     
112   */                                              
113                                                   
114   // PROCESSING OF MICRODOSIMETRY Y & Z SPECTR    
115                                                   
116   // *************************************        
117   // Please select herebelow :                    
118   // the radius of the target sphere:             
119   // variable name = radius                       
120   // it is set to 5 nm by default)                
121                                                   
122   G4double radius = fRadius;                      
123                                                   
124   //                                              
125                                                   
126   //***************                               
127   // y and z                                      
128   //***************                               
129                                                   
130   // Select random hit                            
131   G4int randHit = 0;  // Runs from 0 to number    
132   randHit = static_cast<G4int>(G4UniformRand()    
133                                                   
134   /*                                              
135   G4cout                                          
136   << "======> random selection of hit number r    
137   << randHit << G4endl;                           
138   */                                              
139                                                   
140   // Get selected random hit position             
141   G4ThreeVector hitPos = (*fHitsCollection)[ra    
142   // G4cout << "======> random hit position x/    
143   // G4cout << "======> random hit position y/    
144   // G4cout << "======> random hit position z/    
145                                                   
146   // Set random position of center of sphere w    
147   G4double chord = 4. * radius / 3;               
148   G4double density = 1 * g / cm3;                 
149   G4double mass = (4. / 3) * CLHEP::pi * radiu    
150                                                   
151   // Random placement of sphere: method 1         
152   /*                                              
153   G4ThreeVector randDir = G4RandomDirection();    
154   G4double randRadius = G4UniformRand()*radius    
155   G4ThreeVector randCenterPos = randRadius*ran    
156   */                                              
157                                                   
158   // Random placement of sphere: method 2         
159                                                   
160   G4double xRand = 1.01 * radius;                 
161   G4double yRand = 1.01 * radius;                 
162   G4double zRand = 1.01 * radius;                 
163   G4double randRad = 1.01 * radius;               
164   do {                                            
165     xRand = (2 * G4UniformRand() - 1) * radius    
166     yRand = (2 * G4UniformRand() - 1) * radius    
167     zRand = (2 * G4UniformRand() - 1) * radius    
168     randRad = std::sqrt(xRand * xRand + yRand     
169   } while (randRad > radius);                     
170                                                   
171   G4ThreeVector randCenterPos(xRand + hitPos.x    
172                                                   
173   // Search for neighbouring hits in the spher    
174   //  in epsilon                                  
175   G4double epsilon = 0;                           
176   G4int nbEdep = 0;                               
177                                                   
178   for (G4int i = 0; i < nofHits; i++) {           
179     if ((*fHitsCollection)[i]->GetIncidentEner    
180       Einc = (*fHitsCollection)[i]->GetInciden    
181                                                   
182     G4ThreeVector localPos = (*fHitsCollection    
183                                                   
184     // G4cout << i << " " << (*fHitsCollection    
185     // G4cout << i << " " << (*fHitsCollection    
186                                                   
187     if ((localPos.x() - randCenterPos.x()) * (    
188           + (localPos.y() - randCenterPos.y())    
189           + (localPos.z() - randCenterPos.z())    
190         <= radius * radius)                       
191                                                   
192     {                                             
193       epsilon = epsilon + (*fHitsCollection)[i    
194       nbEdep = nbEdep + 1;                        
195     }                                             
196   }                                               
197                                                   
198   // For testing only                             
199   /*                                              
200   G4cout << "======> for hit number #" << rand    
201   ", we collect "                                 
202   << nbEdep << " energy depositions in a spher    
203   << radius/nm << " nm and mass "                 
204   << mass/kg << " kg for a total of "             
205   << epsilon/eV << " eV or "                      
206   << (epsilon/joule)/(mass/kg) << " Gy" << G4e    
207   G4cout << "-" << G4endl;                        
208   */                                              
209                                                   
210   /*                                              
211   FILE* myFile;                                   
212   myFile=fopen("yz.txt","a");                     
213   fprintf(myFile,"%e %e %e\n",radius/nm,(epsil    
214    (epsilon/joule)/(mass/kg));                    
215   fclose(myFile);                                 
216   */                                              
217                                                   
218   // Get analysis manager                         
219   G4AnalysisManager* analysisManager = G4Analy    
220                                                   
221   // Fill ntuple including weighting              
222   analysisManager->FillNtupleDColumn(0, radius    
223   analysisManager->FillNtupleDColumn(2, nofHit    
224   analysisManager->FillNtupleDColumn(3, nbEdep    
225   analysisManager->FillNtupleDColumn(4, (epsil    
226   analysisManager->FillNtupleDColumn(5, (epsil    
227   analysisManager->FillNtupleDColumn(6, Einc /    
228   analysisManager->AddNtupleRow();                
229 }                                                 
230                                                   
231 //....oooOO0OOooo........oooOO0OOooo........oo    
232