|
|
|||
File indexing completed on 2026-09-13 08:29:48
0001 // 0002 // ******************************************************************** 0003 // * License and Disclaimer * 0004 // * * 0005 // * The Geant4 software is copyright of the Copyright Holders of * 0006 // * the Geant4 Collaboration. It is provided under the terms and * 0007 // * conditions of the Geant4 Software License, included in the file * 0008 // * LICENSE and available at http://cern.ch/geant4/license . These * 0009 // * include a list of copyright holders. * 0010 // * * 0011 // * Neither the authors of this software system, nor their employing * 0012 // * institutes,nor the agencies providing financial support for this * 0013 // * work make any representation or warranty, express or implied, * 0014 // * regarding this software system or assume any liability for its * 0015 // * use. Please see the license in the file LICENSE and URL above * 0016 // * for the full disclaimer and the limitation of liability. * 0017 // * * 0018 // * This code implementation is the result of the scientific and * 0019 // * technical work of the GEANT4 collaboration. * 0020 // * By using, copying, modifying or distributing the software (or * 0021 // * any work based on the software) you agree to acknowledge its * 0022 // * use in resulting scientific publications, and indicate your * 0023 // * acceptance of all terms of the Geant4 Software license. * 0024 // ******************************************************************** 0025 // 0026 /// \file TrackerSD.cc 0027 /// \brief Implementation of the TrackerSD class 0028 0029 // This example is provided by the Geant4-DNA collaboration 0030 // Any report or published results obtained using the Geant4-DNA software 0031 // shall cite the following Geant4-DNA collaboration publications: 0032 // Med. Phys. 45 (2018) e722-e739 0033 // Phys. Med. 31 (2015) 861-874 0034 // Med. Phys. 37 (2010) 4692-4708 0035 // Int. J. Model. Simul. Sci. Comput. 1 (2010) 157–178 0036 // The Geant4-DNA web site is available at http://geant4-dna.org 0037 // 0038 0039 #include "TrackerSD.hh" 0040 0041 #include "G4AnalysisManager.hh" 0042 #include "G4SDManager.hh" 0043 #include "G4SystemOfUnits.hh" 0044 #include "Randomize.hh" 0045 0046 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0047 0048 TrackerSD::TrackerSD(const G4String& name, const G4String& hitsCollectionName) 0049 : G4VSensitiveDetector(name), fHitsCollection(nullptr) 0050 { 0051 collectionName.insert(hitsCollectionName); 0052 } 0053 0054 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0055 0056 TrackerSD::~TrackerSD() = default; 0057 0058 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0059 0060 void TrackerSD::Initialize(G4HCofThisEvent* hce) 0061 { 0062 // Create hits collection 0063 fHitsCollection = new TrackerHitsCollection(SensitiveDetectorName, collectionName[0]); 0064 0065 // Add this collection in hce 0066 G4int hcID = G4SDManager::GetSDMpointer()->GetCollectionID(collectionName[0]); 0067 0068 hce->AddHitsCollection(hcID, fHitsCollection); 0069 } 0070 0071 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0072 0073 G4bool TrackerSD::ProcessHits(G4Step* aStep, G4TouchableHistory*) 0074 { 0075 // Energy deposit 0076 G4double edep = aStep->GetTotalEnergyDeposit(); 0077 0078 if (edep == 0.) return false; 0079 0080 auto newHit = new TrackerHit(); 0081 0082 newHit->SetTrackID(aStep->GetTrack()->GetTrackID()); 0083 newHit->SetEdep(edep); 0084 newHit->SetPos(aStep->GetPostStepPoint()->GetPosition()); 0085 0086 if (aStep->GetTrack()->GetTrackID() == 1 && aStep->GetTrack()->GetParentID() == 0) { 0087 newHit->SetIncidentEnergy(aStep->GetTrack()->GetVertexKineticEnergy()); 0088 } 0089 fHitsCollection->insert(newHit); 0090 // newHit->Print(); 0091 0092 return true; 0093 } 0094 0095 void TrackerSD::SetRadius(const G4double& value) 0096 { 0097 fRadius = value; 0098 } 0099 0100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... 0101 0102 void TrackerSD::EndOfEvent(G4HCofThisEvent*) 0103 { 0104 G4int nofHits = fHitsCollection->entries(); 0105 0106 G4double Einc = 0; 0107 0108 /* 0109 G4cout << G4endl 0110 << "-------->Hits Collection: in this event they are " 0111 << nofHits 0112 << " hits in the target volume " << G4endl; 0113 */ 0114 0115 // PROCESSING OF MICRODOSIMETRY Y & Z SPECTRA 0116 0117 // ************************************* 0118 // Please select herebelow : 0119 // the radius of the target sphere: 0120 // variable name = radius 0121 // it is set to 5 nm by default) 0122 0123 G4double radius = fRadius; 0124 0125 // 0126 0127 //*************** 0128 // y and z 0129 //*************** 0130 0131 // Select random hit 0132 G4int randHit = 0; // Runs from 0 to number of hits - 1 0133 randHit = static_cast<G4int>(G4UniformRand() * nofHits); 0134 0135 /* 0136 G4cout 0137 << "======> random selection of hit number randHit =" 0138 << randHit << G4endl; 0139 */ 0140 0141 // Get selected random hit position 0142 G4ThreeVector hitPos = (*fHitsCollection)[randHit]->GetPos(); 0143 // G4cout << "======> random hit position x/nm =" << hitPos.x()/nm << G4endl; 0144 // G4cout << "======> random hit position y/nm =" << hitPos.y()/nm << G4endl; 0145 // G4cout << "======> random hit position z/nm =" << hitPos.z()/nm << G4endl; 0146 0147 // Set random position of center of sphere within radius 0148 G4double chord = 4. * radius / 3; 0149 G4double density = 1 * g / cm3; 0150 G4double mass = (4. / 3) * CLHEP::pi * radius * radius * radius * density; 0151 0152 // Random placement of sphere: method 1 0153 /* 0154 G4ThreeVector randDir = G4RandomDirection(); 0155 G4double randRadius = G4UniformRand()*radius; 0156 G4ThreeVector randCenterPos = randRadius*randDir + hitPos; 0157 */ 0158 0159 // Random placement of sphere: method 2 0160 0161 G4double xRand = 1.01 * radius; 0162 G4double yRand = 1.01 * radius; 0163 G4double zRand = 1.01 * radius; 0164 G4double randRad = 1.01 * radius; 0165 do { 0166 xRand = (2 * G4UniformRand() - 1) * radius; 0167 yRand = (2 * G4UniformRand() - 1) * radius; 0168 zRand = (2 * G4UniformRand() - 1) * radius; 0169 randRad = std::sqrt(xRand * xRand + yRand * yRand + zRand * zRand); 0170 } while (randRad > radius); 0171 0172 G4ThreeVector randCenterPos(xRand + hitPos.x(), yRand + hitPos.y(), zRand + hitPos.z()); 0173 0174 // Search for neighbouring hits in the sphere and cumulate deposited energy 0175 // in epsilon 0176 G4double epsilon = 0; 0177 G4int nbEdep = 0; 0178 0179 for (G4int i = 0; i < nofHits; i++) { 0180 if ((*fHitsCollection)[i]->GetIncidentEnergy() > 0) 0181 Einc = (*fHitsCollection)[i]->GetIncidentEnergy(); 0182 0183 G4ThreeVector localPos = (*fHitsCollection)[i]->GetPos(); 0184 0185 // G4cout << i << " " << (*fHitsCollection)[i] << G4endl; 0186 // G4cout << i << " " << (*fHitsCollection)[i]->GetEdep()/eV << G4endl; 0187 0188 if ((localPos.x() - randCenterPos.x()) * (localPos.x() - randCenterPos.x()) 0189 + (localPos.y() - randCenterPos.y()) * (localPos.y() - randCenterPos.y()) 0190 + (localPos.z() - randCenterPos.z()) * (localPos.z() - randCenterPos.z()) 0191 <= radius * radius) 0192 0193 { 0194 epsilon = epsilon + (*fHitsCollection)[i]->GetEdep(); 0195 nbEdep = nbEdep + 1; 0196 } 0197 } 0198 0199 // For testing only 0200 /* 0201 G4cout << "======> for hit number #" << randHit << 0202 ", we collect " 0203 << nbEdep << " energy depositions in a sphere of radius " 0204 << radius/nm << " nm and mass " 0205 << mass/kg << " kg for a total of " 0206 << epsilon/eV << " eV or " 0207 << (epsilon/joule)/(mass/kg) << " Gy" << G4endl; 0208 G4cout << "-" << G4endl; 0209 */ 0210 0211 /* 0212 FILE* myFile; 0213 myFile=fopen("yz.txt","a"); 0214 fprintf(myFile,"%e %e %e\n",radius/nm,(epsilon/eV)/(chord/nm), 0215 (epsilon/joule)/(mass/kg)); 0216 fclose(myFile); 0217 */ 0218 0219 // Get analysis manager 0220 G4AnalysisManager* analysisManager = G4AnalysisManager::Instance(); 0221 0222 // Fill ntuple including weighting 0223 analysisManager->FillNtupleDColumn(0, radius / nm); 0224 analysisManager->FillNtupleDColumn(2, nofHits); 0225 analysisManager->FillNtupleDColumn(3, nbEdep); 0226 analysisManager->FillNtupleDColumn(4, (epsilon / eV) / (chord / nm)); 0227 analysisManager->FillNtupleDColumn(5, (epsilon / mass) / gray); 0228 analysisManager->FillNtupleDColumn(6, Einc / eV); 0229 analysisManager->AddNtupleRow(); 0230 } 0231 0232 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|