55 saving_in_ROG_Voxels_every_events=voxSave;
69 sprintf(a,
"%d", seed);
72 fullOutFileData=ROGOutFile+
"_"+seedName+
".txt";
73 fullOutFileDataSingle=
"";
78 NumberOfVoxelsAlongX=NumVX;
79 NumberOfVoxelsAlongY=NumVY;
80 NumberOfVoxelsAlongZ=NumVZ;
81 halfXVoxelDimensionX=halfSize.
getX()/NumberOfVoxelsAlongX;
82 halfXVoxelDimensionY=halfSize.
getY()/NumberOfVoxelsAlongY;
83 halfXVoxelDimensionZ=halfSize.
getZ()/NumberOfVoxelsAlongZ;
85 voxelVolume=halfXVoxelDimensionX*halfXVoxelDimensionY*halfXVoxelDimensionZ*8.;
88 voxelsSum=
new Svoxel**[NumberOfVoxelsAlongX];
89 for (
int ix=0; ix< NumberOfVoxelsAlongX; ix++)
91 voxelsSum[ix]=
new Svoxel*[NumberOfVoxelsAlongY];
92 for (
int iy=0; iy< NumberOfVoxelsAlongY; iy++)
94 voxelsSum[ix][iy]=
new Svoxel[NumberOfVoxelsAlongZ];
95 for (
int iz=0; iz< NumberOfVoxelsAlongZ; iz++)
102 voxelsSum[ix][iy][iz].
expDose=0.;
103 voxelsSum[ix][iy][iz].
halfSize.
set(halfXVoxelDimensionX, halfXVoxelDimensionY, halfXVoxelDimensionZ);
104 voxelsSum[ix][iy][iz].
pos.
set(2.*(ix)*halfXVoxelDimensionX -halfSize.
getX()+halfXVoxelDimensionX + centre.
getX(),
105 2.*(iy)*halfXVoxelDimensionY -halfSize.
getY()+halfXVoxelDimensionY + centre.
getY(),
106 2.*(iz)*halfXVoxelDimensionZ -halfSize.
getZ()+halfXVoxelDimensionZ + centre.
getZ());
107 voxelsSum[ix][iy][iz].
nEvents=0;
114 voxelsSingle=
new Svoxel**[NumberOfVoxelsAlongX];
115 for (
int ix=0; ix< NumberOfVoxelsAlongX; ix++)
117 voxelsSingle[ix]=
new Svoxel*[NumberOfVoxelsAlongY];
118 for (
int iy=0; iy< NumberOfVoxelsAlongY; iy++)
120 voxelsSingle[ix][iy]=
new Svoxel[NumberOfVoxelsAlongZ];
121 for (
int iz=0; iz< NumberOfVoxelsAlongZ; iz++)
123 voxelsSingle[ix][iy][iz].
volumeId=-1;
128 voxelsSingle[ix][iy][iz].
expDose=0.;
129 voxelsSingle[ix][iy][iz].
halfSize.
set(halfXVoxelDimensionX, halfXVoxelDimensionY, halfXVoxelDimensionZ);
130 voxelsSingle[ix][iy][iz].
pos.
set(2.*(ix)*halfXVoxelDimensionX -halfSize.
getX()+halfXVoxelDimensionX + centre.
getX(),
131 2.*(iy)*halfXVoxelDimensionY -halfSize.
getY()+halfXVoxelDimensionY + centre.
getY(),
132 2.*(iz)*halfXVoxelDimensionZ -halfSize.
getZ()+halfXVoxelDimensionZ + centre.
getZ());
133 voxelsSingle[ix][iy][iz].
nEvents=0;
145 delete [] voxelsSingle;
150 for (
int ix=0; ix< NumberOfVoxelsAlongX; ix++)
152 for (
int iy=0; iy< NumberOfVoxelsAlongY; iy++)
154 for (
int iz=0; iz< NumberOfVoxelsAlongZ; iz++)
156 voxelsSingle[ix][iy][iz].
volumeId=-1;
161 voxelsSingle[ix][iy][iz].
expDose=0.;
162 voxelsSingle[ix][iy][iz].
halfSize.
set(halfXVoxelDimensionX, halfXVoxelDimensionY, halfXVoxelDimensionZ);
163 voxelsSingle[ix][iy][iz].
pos.
set(2.*(ix)*halfXVoxelDimensionX -halfSize.
getX()+halfXVoxelDimensionX + centre.
getX(),
164 2.*(iy)*halfXVoxelDimensionY -halfSize.
getY()+halfXVoxelDimensionY + centre.
getY(),
165 2.*(iz)*halfXVoxelDimensionZ -halfSize.
getZ()+halfXVoxelDimensionZ + centre.
getZ());
166 voxelsSingle[ix][iy][iz].
nEvents=0;
170 nSingleTotalEvents=0;
178 if (bSaveROG && energyDep>0.)
189 voxelMass=voxelVolume*density;
190 energyDep/=voxelMass*nRecycling;
192 voxelsSum[ix][iy][iz].
depEnergy+=energyDep;
193 voxelsSum[ix][iy][iz].
depEnergy2+=energyDep*energyDep;
194 voxelsSum[ix][iy][iz].
nEvents++;
197 voxelsSingle[ix][iy][iz].
depEnergy+=energyDep;
198 voxelsSingle[ix][iy][iz].
depEnergy2+=energyDep*energyDep;
199 voxelsSingle[ix][iy][iz].
nEvents++;
201 nSingleTotalEvents++;
202 if (nTotalEvents%saving_in_ROG_Voxels_every_events==0 && nTotalEvents>0)
212 for (
int i=0; i<(
int)volumeNameIdLink.size(); i++)
214 if (volumeNameIdLink[i].volumeName==name)
216 return volumeNameIdLink[i].volumeId;
224 std::cout<<
"n. of events collected in the whole ROG phantom for all geometries: "<< nTotalEvents<<
G4endl;
225 std::cout<<
"n. of events collected in the whole ROG phantom for the current geometry: "<< nSingleTotalEvents<<
G4endl;
227 {saveData(fullOutFileData, voxelsSum);}
228 if (nSingleTotalEvents>0)
229 {saveData(fullOutFileDataSingle, voxelsSingle);}
231 void CML2SDWithVoxels::saveData(
G4String Filename,
Svoxel ***voxels)
234 out.open(Filename, std::ios::out);
235 out <<
"Sensitive Detector-Voxels. Total number of events, [mm]->centreX centreY centreZ HalfSizeX HalfSizeY HalfSizeZ minX maxX, minY maxY, minZ maxZ, Dx, Dy, Dz, nX, nY, nZ: \n";
236 out <<nTotalEvents<<
'\t';
238 out <<halfSize.
getX()/
mm <<
'\t' << halfSize.
getY()/
mm <<
'\t'<< halfSize.
getZ()/
mm<<
'\t';
242 out <<halfXVoxelDimensionX/
mm<<
'\t'<<halfXVoxelDimensionY/
mm<<
'\t'<<halfXVoxelDimensionZ/
mm<<
'\t';
243 out <<NumberOfVoxelsAlongX <<
'\t'<<NumberOfVoxelsAlongY <<
'\t'<<NumberOfVoxelsAlongZ <<
'\n';
244 out <<
"Number of physical volumes: "<< volumeNameIdLink.size() <<
'\n';
245 for (
int i=0; i<(
int)volumeNameIdLink.size(); i++)
247 out << volumeNameIdLink[i].volumeName <<
'\t'<< volumeNameIdLink[i].volumeId <<
G4endl;
251 out <<
"Phys Volume x [mm], y [mm], z [mm], ix, iy, iz, Dose [Gy], Dose2 [Gy^2], nEvents" <<
G4endl;
253 for (
int ix=0; ix< NumberOfVoxelsAlongX; ix++)
255 for (
int iy=0; iy< NumberOfVoxelsAlongY; iy++)
257 for (
int iz=0; iz< NumberOfVoxelsAlongZ; iz++)
259 if (voxels[ix][iy][iz].nEvents>0)
261 out << voxels[ix][iy][iz].
volumeId <<
'\t';
262 out << voxels[ix][iy][iz].
pos.
getX()/
mm <<
'\t';
263 out << voxels[ix][iy][iz].
pos.
getY()/
mm <<
'\t';
264 out << voxels[ix][iy][iz].
pos.
getZ()/
mm <<
'\t';
280 unsigned int ind = fullOutFileData.find(
".txt");
281 G4String onlyName=fullOutFileData.substr( 0, ind);
284 static unsigned int indGeom=0;
286 sprintf(cT,
"%d",indGeom);
287 fullOutFileDataSingle=onlyName+
"Single_"+
G4String(cT)+
".txt";
292 fullOutFileDataSingle=onlyName+val+
".txt";
void set(double x, double y, double z)
static constexpr double mm
G4Material * GetMaterial() const
std::vector< ExP01TrackerHit * > a
const G4String & GetName() const
G4double GetDensity() const
CML2SDWithVoxels(G4String name, G4int saving_in_ROG_Voxels_every_events, G4int seed, G4String ROGOutFile, G4bool bSaveROG, G4ThreeVector centre, G4ThreeVector halfSize, G4int NumberOfVoxelsAlongX, G4int NumberOfVoxelsAlongY, G4int NumberOfVoxelsAlongZ)
G4StepPoint * GetPreStepPoint() const
G4VPhysicalVolume * GetPhysicalVolume() const
G4int GetReplicaNumber(G4int depth=0) const
G4double depEnergyNormError
typedef int(XMLCALL *XML_NotStandaloneHandler)(void *userData)
static constexpr double kg
void setFullOutFileDataSingle(G4String val)
G4double GetTotalEnergyDeposit() const
G4bool ProcessHits(G4Step *aStep, G4TouchableHistory *ROHist)
G4LogicalVolume * GetLogicalVolume() const
static constexpr double joule