Geant4 Cross Reference |
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 // -------------------------------------------------------------------------------- 27 // MONTE CARLO SIMULATION OF REALISTIC GEOMETRY FROM MICROSCOPES IMAGES 28 // 29 // Authors and contributors: 30 // P. Barberet, S. Incerti, N. H. Tran, L. Morelli 31 // 32 // University of Bordeaux, CNRS, LP2i, UMR5797, Gradignan, France 33 // 34 // If you use this code, please cite the following publication: 35 // P. Barberet et al., 36 // "Monte-Carlo dosimetry on a realistic cell monolayer 37 // geometry exposed to alpha particles." 38 // Ph. Barberet et al 2012 Phys. Med. Biol. 57 2189 39 // doi: 110.1088/0031-9155/57/8/2189 40 // -------------------------------------------------------------------------------- 41 42 #include "RunAction.hh" 43 44 #include "G4UnitsTable.hh" 45 46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 47 48 RunAction::RunAction() 49 :G4UserRunAction() 50 { 51 auto man = G4AnalysisManager::Instance(); 52 man->SetDefaultFileType("root"); 53 man->SetNtupleMerging(true); 54 man->SetFirstNtupleId(1); 55 56 // Create 1st ntuple (id = 1) 57 man->CreateNtuple("ntuple1", "RED"); 58 man->CreateNtupleDColumn("x"); 59 man->CreateNtupleDColumn("y"); 60 man->CreateNtupleDColumn("z"); 61 man->CreateNtupleDColumn("energy"); 62 man->CreateNtupleDColumn("dose"); 63 man->CreateNtupleIColumn("voxelID"); 64 man->FinishNtuple(); 65 66 // Create 2nd ntuple (id = 2) 67 man->CreateNtuple("ntuple2", "GREEN"); 68 man->CreateNtupleDColumn("x"); 69 man->CreateNtupleDColumn("y"); 70 man->CreateNtupleDColumn("z"); 71 man->CreateNtupleDColumn("energy"); 72 man->CreateNtupleDColumn("dose"); 73 man->CreateNtupleIColumn("voxelID"); 74 man->FinishNtuple(); 75 76 // Create 3rd ntuple (id = 3) 77 man->CreateNtuple("ntuple3", "BLUE"); 78 man->CreateNtupleDColumn("x"); 79 man->CreateNtupleDColumn("y"); 80 man->CreateNtupleDColumn("z"); 81 man->CreateNtupleDColumn("energy"); 82 man->CreateNtupleDColumn("dose"); 83 man->CreateNtupleIColumn("voxelID"); 84 man->FinishNtuple(); 85 } 86 87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 88 89 RunAction::~RunAction() 90 { 91 delete[] fVoxelEnergy; 92 } 93 94 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 95 96 void RunAction::BeginOfRunAction(const G4Run *) 97 { 98 // Analysis manager 99 auto man = G4AnalysisManager::Instance(); 100 man->OpenFile("phantom"); 101 102 // Access phantom singleton 103 fMyPhantomParam = CellParameterisation::Instance(); 104 105 fNbVoxels = fMyPhantomParam->GetPhantomTotalPixels(); 106 107 // Allocates the array receiving the energy per voxel 108 fVoxelEnergy = new G4double[fNbVoxels]; 109 110 // Initialisation of the energy array 111 for (G4int i = 0; i < fNbVoxels; i++) fVoxelEnergy[i] = 0; 112 } 113 114 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo.... 115 116 void RunAction::EndOfRunAction(const G4Run * /*aRun*/) 117 { 118 auto man = G4AnalysisManager::Instance(); 119 120 G4double X, Y, Z; 121 122 // Total mass of voxel 123 G4double redMassTot=0.; 124 G4double greenMassTot=0.; 125 G4double blueMassTot=0.; 126 127 redMassTot = fMyPhantomParam->GetRedMass(); 128 greenMassTot = fMyPhantomParam->GetGreenMass(); 129 blueMassTot = fMyPhantomParam->GetBlueMass(); 130 131 // (Optional) Numbers of voxel 132 //G4double redVox=0; 133 //G4double greenVox=0; 134 //G4double blueVox=0; 135 //redVox = fMyPhantomParam->GetRedTotalPixels(); 136 //greenVox = fMyPhantomParam->GetGreenTotalPixels(); 137 //blueVox = fMyPhantomParam->GetBlueTotalPixels(); 138 139 // (Optional) Single voxel mass 140 //G4double redMass=0.; 141 //G4double greenMass=0.; 142 //G4double blueMass=0.; 143 //redMass = redMassTot/redVox; 144 //greenMass = greenMassTot/greenVox; 145 //blueMass = blueMassTot/blueVox; 146 147 // Save x, y, z and energy for every voxel having absorbed an energy above 0. 148 // Energy is in keV 149 // Dose is in Gy 150 151 for (G4int i = 0; i < fMyPhantomParam->GetPhantomTotalPixels(); i++) 152 { 153 if (fVoxelEnergy[i] > 0.) 154 { 155 X = (fMyPhantomParam->GetVoxelThreeVectorOriginal(i).x()) / um; 156 Y = (fMyPhantomParam->GetVoxelThreeVectorOriginal(i).y()) / um; 157 Z = (fMyPhantomParam->GetVoxelThreeVectorOriginal(i).z()) / um; 158 159 if (fMyPhantomParam->GetMaterial(i) == 1) 160 { 161 man->FillNtupleDColumn(1,0,X); 162 man->FillNtupleDColumn(1,1,Y); 163 man->FillNtupleDColumn(1,2,Z); 164 man->FillNtupleDColumn(1,3,fVoxelEnergy[i]/keV); 165 man->FillNtupleDColumn(1,4,((fVoxelEnergy[i]/joule)/(redMassTot/kg))); 166 man->FillNtupleIColumn(1,5,i); 167 man->AddNtupleRow(1); 168 } 169 170 else if (fMyPhantomParam->GetMaterial(i) == 2) 171 { 172 man->FillNtupleDColumn(2,0,X); 173 man->FillNtupleDColumn(2,1,Y); 174 man->FillNtupleDColumn(2,2,Z); 175 man->FillNtupleDColumn(2,3,fVoxelEnergy[i]/keV); 176 man->FillNtupleDColumn(2,4,((fVoxelEnergy[i]/joule)/(greenMassTot/kg))); 177 man->FillNtupleIColumn(2,5,i); 178 man->AddNtupleRow(2); 179 } 180 181 else if (fMyPhantomParam->GetMaterial(i) == 3) 182 { 183 man->FillNtupleDColumn(3,0,X); 184 man->FillNtupleDColumn(3,1,Y); 185 man->FillNtupleDColumn(3,2,Z); 186 man->FillNtupleDColumn(3,3,fVoxelEnergy[i]/keV); 187 man->FillNtupleDColumn(3,4,((fVoxelEnergy[i]/joule)/(blueMassTot/kg))); 188 man->FillNtupleIColumn(3,5,i); 189 man->AddNtupleRow(3); 190 } 191 } 192 } 193 194 // Save histograms 195 man->Write(); 196 man->CloseFile(); 197 198 // Complete clean-up 199 man->Clear(); 200 } 201