62     if (instance) 
delete instance;
 
   74     numberOfVoxelAlongX = voxelX;
 
   75     numberOfVoxelAlongY = voxelY;
 
   76     numberOfVoxelAlongZ = voxelZ; 
 
   79     matrix = 
new G4double[numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ];
 
   82         G4cout << 
"HadrontherapyMatrix: Memory space to store physical dose into " <<  
 
   83         numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ <<
 
   84         " voxels has been allocated " << 
G4endl;
 
   86     else G4Exception(
"HadrontherapyMatrix::HadrontherapyMatrix()", 
"Hadrontherapy0005", 
FatalException, 
"Can't allocate memory to store physical dose!");
 
   90     hitTrack = 
new G4int[numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ];
 
  106     for (
size_t i=0; i<ionStore.size(); i++)
 
  108     delete[] ionStore[i].dose; 
 
  109     delete[] ionStore[i].fluence; 
 
  121     for(
int i=0;i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;i++)
 
  131     for (
size_t i=0; i<ionStore.size(); i++)
 
  140     for(
G4int i=0; i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; i++) hitTrack[i] = 0;
 
  145     return &(hitTrack[
Index(i,j,k)]);
 
  160     if ( (energyDeposit <=0. && !fluence) || !
secondary) 
return false;
 
  162     G4int PDGencoding = particleDef -> GetPDGEncoding();
 
  163     PDGencoding -= PDGencoding%10;
 
  166     for (
size_t l=0; l < ionStore.size(); l++)
 
  168         if (ionStore[l].PDGencoding == PDGencoding ) 
 
  170           if ( (trackID ==1 && ionStore[l].isPrimary) || (trackID !=1 && !ionStore[l].isPrimary))
 
  172                 if (energyDeposit > 0.) ionStore[l].dose[
Index(i, j, k)] += energyDeposit;
 
  175                 if (fluence) ionStore[l].fluence[
Index(i, j, k)]++;
 
  181     G4int Z = particleDef-> GetAtomicNumber();
 
  182     G4int A = particleDef-> GetAtomicMass();
 
  184     G4String fullName = particleDef -> GetParticleName();
 
  185     G4String name = fullName.substr (0, fullName.find(
"[") ); 
 
  189         (trackID == 1) ? 
true:
false,
 
  195         new G4double[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ],
 
  196         new unsigned int[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ]
 
  201         for(
G4int q=0; q<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; q++)
 
  206         if (energyDeposit > 0.) newIon.
dose[
Index(i, j, k)] += energyDeposit;
 
  209         ionStore.push_back(newIon);
 
  238         ofs.open(file, std::ios::out);
 
  241             for(
G4int i = 0; i < numberOfVoxelAlongX; i++) 
 
  242                 for(
G4int j = 0; j < numberOfVoxelAlongY; j++) 
 
  243                     for(
G4int k = 0; k < numberOfVoxelAlongZ; k++) 
 
  247                         if (psize == 
sizeof(
unsigned int))
 
  249                             unsigned int* pdata = (
unsigned int*)data;
 
  250                             if (pdata[n]) ofs << i << 
'\t' << j << 
'\t' <<
 
  251                                 k << 
'\t' << pdata[
n] << 
G4endl;
 
  256                             if (pdata[n]) ofs << i << 
'\t' << j << 
'\t' <<
 
  257                                 k << 
'\t' << pdata[
n] << 
G4endl;
 
  268     for (
size_t i=0; i < ionStore.size(); i++){
 
  269         StoreMatrix(ionStore[i].
name + 
"_Fluence.out", ionStore[i].fluence, 
sizeof(
unsigned int));
 
  276     for (
size_t i=0; i < ionStore.size(); i++){
 
  287     filename = (file==
"") ? stdFile:file;
 
  289     std::sort(ionStore.begin(), ionStore.end());
 
  290     G4cout << 
"Dose is being written to " << filename << 
G4endl;
 
  291     ofs.open(filename, std::ios::out);
 
  295     ofs << std::setprecision(6) << 
std::left <<
 
  298     ofs << std::setw(
width) << 
"Dose(Gy)";
 
  301         for (
size_t l=0; l < ionStore.size(); l++)
 
  303         G4String a = (ionStore[l].isPrimary) ? 
"_1":
""; 
 
  304         ofs << std::setw(
width) << ionStore[l].name + a <<
 
  305             std::setw(
width) << ionStore[l].name  + 
a;
 
  327     for(
G4int i = 0; i < numberOfVoxelAlongX; i++) 
 
  328         for(
G4int j = 0; j < numberOfVoxelAlongY; j++) 
 
  329         for(
G4int k = 0; k < numberOfVoxelAlongZ; k++) 
 
  336             ofs << i << 
'\t' << j << 
'\t' << k << 
'\t';
 
  338             ofs << std::setw(
width) << (matrix[
n]/massOfVoxel)/doseUnit; 
 
  341                 for (
size_t l=0; l < ionStore.size(); l++)
 
  344                 ofs << std::setw(
width) << ionStore[l].dose[
n]/massOfVoxel/doseUnit <<
 
  345                     std::setw(
width) << ionStore[l].fluence[
n]; 
 
  355 #ifdef G4ANALYSIS_USE_ROOT 
  356 void HadrontherapyMatrix::StoreDoseFluenceRoot()
 
  359     if (analysis -> IsTheTFile())
 
  361     for(
G4int i = 0; i < numberOfVoxelAlongX; i++) 
 
  362         for(
G4int j = 0; j < numberOfVoxelAlongY; j++) 
 
  363         for(
G4int k = 0; k < numberOfVoxelAlongZ; k++) 
 
  366             for (
size_t l=0; l < ionStore.size(); l++)
 
  370             analysis -> FillVoxelFragmentTuple( i, j, k, 
 
  373                 ionStore[l].
dose[n]/massOfVoxel/doseUnit, 
 
  374                 ionStore[l].fluence[n] );
 
  387         matrix[
Index(i,j,k)] += energyDeposit;
 
  397 #ifdef G4ANALYSIS_USE_ROOT 
  403     for(
G4int i = 0; i < numberOfVoxelAlongX; i++) 
 
  404         for(
G4int j = 0; j < numberOfVoxelAlongY; j++) 
 
  405         for(
G4int k = 0; k < numberOfVoxelAlongZ; k++)
 
  407 #ifdef G4ANALYSIS_USE_ROOT 
  409             if (analysis -> IsTheTFile() )
 
  411             analysis -> FillEnergyDeposit(i, j, k, matrix[n]/massOfVoxel/doseUnit);
 
  412             analysis -> BraggPeak(i, matrix[n]/massOfVoxel/doseUnit);