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