56 if (instance)
delete instance;
68 numberOfVoxelAlongX = voxelX;
69 numberOfVoxelAlongY = voxelY;
70 numberOfVoxelAlongZ = voxelZ;
73 matrix =
new G4double[numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ];
76 G4cout <<
"HadrontherapyMatrix: Memory space to store physical dose into " <<
77 numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ <<
78 " voxels has been allocated " <<
G4endl;
80 else G4Exception(
"HadrontherapyMatrix::HadrontherapyMatrix()",
"Hadrontherapy0005",
FatalException,
"Can't allocate memory to store physical dose!");
84 hitTrack =
new G4int[numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ];
100 for (
size_t i=0; i<ionStore.size(); i++)
102 delete[] ionStore[i].dose;
103 delete[] ionStore[i].fluence;
115 for(
int i=0;i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;i++)
125 for (
size_t i=0; i<ionStore.size(); i++)
134 for(
G4int i=0; i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; i++) hitTrack[i] = 0;
139 return &(hitTrack[
Index(i,j,k)]);
154 if ( (energyDeposit <=0. && !fluence) || !
secondary)
return false;
156 G4int PDGencoding = particleDef -> GetPDGEncoding();
157 PDGencoding -= PDGencoding%10;
160 for (
size_t l=0; l < ionStore.size(); l++)
162 if (ionStore[l].PDGencoding == PDGencoding )
164 if ( (trackID ==1 && ionStore[l].isPrimary) || (trackID !=1 && !ionStore[l].isPrimary))
166 if (energyDeposit > 0.) ionStore[l].dose[
Index(i, j, k)] += energyDeposit;
169 if (fluence) ionStore[l].fluence[
Index(i, j, k)]++;
175 G4int Z = particleDef-> GetAtomicNumber();
176 G4int A = particleDef-> GetAtomicMass();
178 G4String fullName = particleDef -> GetParticleName();
179 G4String name = fullName.substr (0, fullName.find(
"[") );
183 (trackID == 1) ?
true:
false,
189 new G4double[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ],
190 new unsigned int[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ]
195 for(
G4int q=0; q<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; q++)
200 if (energyDeposit > 0.) newIon.
dose[
Index(i, j, k)] += energyDeposit;
203 ionStore.push_back(newIon);
232 ofs.open(file, std::ios::out);
235 for(
G4int i = 0; i < numberOfVoxelAlongX; i++)
236 for(
G4int j = 0; j < numberOfVoxelAlongY; j++)
237 for(
G4int k = 0; k < numberOfVoxelAlongZ; k++)
241 if (psize ==
sizeof(
unsigned int))
243 unsigned int* pdata = (
unsigned int*)data;
244 if (pdata[n]) ofs << i <<
'\t' << j <<
'\t' <<
245 k <<
'\t' << pdata[
n] <<
G4endl;
250 if (pdata[n]) ofs << i <<
'\t' << j <<
'\t' <<
251 k <<
'\t' << pdata[
n] <<
G4endl;
262 for (
size_t i=0; i < ionStore.size(); i++){
263 StoreMatrix(ionStore[i].
name +
"_Fluence.out", ionStore[i].fluence,
sizeof(
unsigned int));
270 for (
size_t i=0; i < ionStore.size(); i++){
281 filename = (file==
"") ? stdFile:file;
283 std::sort(ionStore.begin(), ionStore.end());
284 G4cout <<
"Dose is being written to " << filename <<
G4endl;
285 ofs.open(filename, std::ios::out);
289 ofs << std::setprecision(6) <<
std::left <<
292 ofs << std::setw(
width) <<
"Dose(Gy)";
295 for (
size_t l=0; l < ionStore.size(); l++)
297 G4String a = (ionStore[l].isPrimary) ?
"_1":
"";
298 ofs << std::setw(
width) << ionStore[l].name + a <<
299 std::setw(
width) << ionStore[l].name +
a;
321 for(
G4int i = 0; i < numberOfVoxelAlongX; i++)
322 for(
G4int j = 0; j < numberOfVoxelAlongY; j++)
323 for(
G4int k = 0; k < numberOfVoxelAlongZ; k++)
330 ofs << i <<
'\t' << j <<
'\t' << k <<
'\t';
332 ofs << std::setw(
width) << (matrix[
n]/massOfVoxel)/doseUnit;
335 for (
size_t l=0; l < ionStore.size(); l++)
338 ofs << std::setw(
width) << ionStore[l].dose[
n]/massOfVoxel/doseUnit <<
339 std::setw(
width) << ionStore[l].fluence[
n];
349 #ifdef G4ANALYSIS_USE_ROOT
350 void HadrontherapyMatrix::StoreDoseFluenceRoot()
353 if (analysis -> IsTheTFile())
355 for(
G4int i = 0; i < numberOfVoxelAlongX; i++)
356 for(
G4int j = 0; j < numberOfVoxelAlongY; j++)
357 for(
G4int k = 0; k < numberOfVoxelAlongZ; k++)
360 for (
size_t l=0; l < ionStore.size(); l++)
364 analysis -> FillVoxelFragmentTuple( i, j, k,
367 ionStore[l].dose[n]/massOfVoxel/doseUnit,
368 ionStore[l].fluence[n] );
381 matrix[
Index(i,j,k)] += energyDeposit;
391 #ifdef G4ANALYSIS_USE_ROOT
397 for(
G4int i = 0; i < numberOfVoxelAlongX; i++)
398 for(
G4int j = 0; j < numberOfVoxelAlongY; j++)
399 for(
G4int k = 0; k < numberOfVoxelAlongZ; k++)
401 #ifdef G4ANALYSIS_USE_ROOT
403 if (analysis -> IsTheTFile() )
405 analysis -> FillEnergyDeposit(i, j, k, matrix[n]/massOfVoxel/doseUnit);
406 analysis -> BraggPeak(i, matrix[n]/massOfVoxel/doseUnit);
static HadrontherapyAnalysisManager * GetInstance()
std::vector< ExP01TrackerHit * > a
G4int Index(G4int i, G4int j, G4int k)
void StoreDoseFluenceAscii(G4String filename="")
const XML_Char const XML_Char * data
static HadrontherapyMatrix * GetInstance()
void StoreMatrix(G4String file, void *data, size_t psize)
G4GLOB_DLL std::ostream G4cout
double A(double temperature)
static constexpr double gray
G4int * GetHitTrack(G4int i, G4int j, G4int k)
G4bool Fill(G4int, G4ParticleDefinition *particleDef, G4int i, G4int j, G4int k, G4double energyDeposit, G4bool fluence=false)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
void TotalEnergyDeposit()