Geant4.10
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Public Member Functions | Static Public Member Functions | Static Public Attributes
HadrontherapyMatrix Class Reference

#include <HadrontherapyMatrix.hh>

Public Member Functions

 ~HadrontherapyMatrix ()
 
void PrintNuclides ()
 
void ClearHitTrack ()
 
G4int * GetHitTrack (G4int i, G4int j, G4int k)
 
void Initialize ()
 
void Clear ()
 
G4bool Fill (G4int, G4ParticleDefinition *particleDef, G4int i, G4int j, G4int k, G4double energyDeposit, G4bool fluence=false)
 
void Fill (G4int i, G4int j, G4int k, G4double energyDeposit)
 
void TotalEnergyDeposit ()
 
void StoreMatrix (G4String file, void *data, size_t psize)
 
void StoreFluenceData ()
 
void StoreDoseData ()
 
void StoreDoseFluenceAscii (G4String filename="")
 
G4int Index (G4int i, G4int j, G4int k)
 
G4double * GetMatrix ()
 
G4int GetNvoxel ()
 
G4int GetNumberOfVoxelAlongX ()
 
G4int GetNumberOfVoxelAlongY ()
 
G4int GetNumberOfVoxelAlongZ ()
 

Static Public Member Functions

static HadrontherapyMatrix * GetInstance ()
 
static HadrontherapyMatrix * GetInstance (G4int nX, G4int nY, G4int nZ, G4double mass)
 

Static Public Attributes

static G4bool secondary = false
 

Detailed Description

Definition at line 61 of file HadrontherapyMatrix.hh.

Constructor & Destructor Documentation

HadrontherapyMatrix::~HadrontherapyMatrix ( )

Definition at line 95 of file HadrontherapyMatrix.cc.

References Clear().

96 {
97  delete[] matrix;
98  delete[] hitTrack;
99  // free fluences/dose data memory
100  Clear();
101 }

Member Function Documentation

void HadrontherapyMatrix::Clear ( )

Definition at line 104 of file HadrontherapyMatrix.cc.

Referenced by Initialize(), and ~HadrontherapyMatrix().

105 {
106  for (size_t i=0; i<ionStore.size(); i++)
107  {
108  delete[] ionStore[i].dose;
109  delete[] ionStore[i].fluence;
110  }
111  ionStore.clear();
112 }
void HadrontherapyMatrix::ClearHitTrack ( )

Definition at line 138 of file HadrontherapyMatrix.cc.

139 {
140  for(G4int i=0; i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; i++) hitTrack[i] = 0;
141 }
int G4int
Definition: G4Types.hh:78
G4bool HadrontherapyMatrix::Fill ( G4int  trackID,
G4ParticleDefinition *  particleDef,
G4int  i,
G4int  j,
G4int  k,
G4double  energyDeposit,
G4bool  fluence = false 
)

Definition at line 154 of file HadrontherapyMatrix.cc.

References ion::dose, ion::fluence, Index(), and secondary.

159 {
160  if ( (energyDeposit <=0. && !fluence) || !secondary) return false;
161  // Get Particle Data Group particle ID
162  G4int PDGencoding = particleDef -> GetPDGEncoding();
163  PDGencoding -= PDGencoding%10;
164 
165  // Search for already allocated data...
166  for (size_t l=0; l < ionStore.size(); l++)
167  {
168  if (ionStore[l].PDGencoding == PDGencoding )
169  { // Is it a primary or a secondary particle?
170  if ( (trackID ==1 && ionStore[l].isPrimary) || (trackID !=1 && !ionStore[l].isPrimary))
171  {
172  if (energyDeposit > 0.) ionStore[l].dose[Index(i, j, k)] += energyDeposit;
173 
174  // Fill a matrix per each ion with the fluence
175  if (fluence) ionStore[l].fluence[Index(i, j, k)]++;
176  return true;
177  }
178  }
179  }
180 
181  G4int Z = particleDef-> GetAtomicNumber();
182  G4int A = particleDef-> GetAtomicMass();
183 
184  G4String fullName = particleDef -> GetParticleName();
185  G4String name = fullName.substr (0, fullName.find("[") ); // cut excitation energy
186  // Let's put a new particle in our store...
187  ion newIon =
188  {
189  (trackID == 1) ? true:false,
190  PDGencoding,
191  name,
192  name.length(),
193  Z,
194  A,
195  new G4double[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ],
196  new unsigned int[numberOfVoxelAlongX * numberOfVoxelAlongY * numberOfVoxelAlongZ]
197  };
198  // Initialize data
199  if (newIon.dose && newIon.fluence)
200  {
201  for(G4int q=0; q<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; q++)
202  {
203  newIon.dose[q] = 0.;
204  newIon.fluence[q] = 0;
205  }
206  if (energyDeposit > 0.) newIon.dose[Index(i, j, k)] += energyDeposit;
207  if (fluence) newIon.fluence[Index(i, j, k)]++;
208 
209  ionStore.push_back(newIon);
210 
211  // TODO Put some verbosity check
212  /*
213  G4cout << "Memory space to store the DOSE/FLUENCE into " <<
214  numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ <<
215  " voxels has been allocated for the nuclide " << newIon.name <<
216  " (Z = " << Z << ", A = " << A << ")" << G4endl ;
217  */
218  return true;
219  }
220  else // XXX Out of memory! XXX
221  {
222  return false;
223  }
224 
225 }
G4double * dose
G4int Index(G4int i, G4int j, G4int k)
const XML_Char * name
int G4int
Definition: G4Types.hh:78
unsigned int * fluence
double G4double
Definition: G4Types.hh:76
void HadrontherapyMatrix::Fill ( G4int  i,
G4int  j,
G4int  k,
G4double  energyDeposit 
)

Definition at line 383 of file HadrontherapyMatrix.cc.

References Index().

385 {
386  if (matrix)
387  matrix[Index(i,j,k)] += energyDeposit;
388 
389  // Store the energy deposit in the matrix element corresponding
390  // to the phantom voxel
391 }
G4int Index(G4int i, G4int j, G4int k)
G4int * HadrontherapyMatrix::GetHitTrack ( G4int  i,
G4int  j,
G4int  k 
)

Definition at line 143 of file HadrontherapyMatrix.cc.

References Index().

144 {
145  return &(hitTrack[Index(i,j,k)]);
146 }
G4int Index(G4int i, G4int j, G4int k)
HadrontherapyMatrix * HadrontherapyMatrix::GetInstance ( )
static
HadrontherapyMatrix * HadrontherapyMatrix::GetInstance ( G4int  nX,
G4int  nY,
G4int  nZ,
G4double  mass 
)
static

Definition at line 60 of file HadrontherapyMatrix.cc.

References Initialize().

61 {
62  if (instance) delete instance;
63  instance = new HadrontherapyMatrix(voxelX, voxelY, voxelZ, mass);
64  instance -> Initialize();
65  return instance;
66 }
G4double* HadrontherapyMatrix::GetMatrix ( )
inline

Definition at line 120 of file HadrontherapyMatrix.hh.

120 {return matrix;}
G4int HadrontherapyMatrix::GetNumberOfVoxelAlongX ( )
inline

Definition at line 124 of file HadrontherapyMatrix.hh.

124 {return numberOfVoxelAlongX;}
G4int HadrontherapyMatrix::GetNumberOfVoxelAlongY ( )
inline

Definition at line 125 of file HadrontherapyMatrix.hh.

125 {return numberOfVoxelAlongY;}
G4int HadrontherapyMatrix::GetNumberOfVoxelAlongZ ( )
inline

Definition at line 126 of file HadrontherapyMatrix.hh.

126 {return numberOfVoxelAlongZ;}
G4int HadrontherapyMatrix::GetNvoxel ( )
inline

Definition at line 122 of file HadrontherapyMatrix.hh.

122 {return numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;}
G4int HadrontherapyMatrix::Index ( G4int  i,
G4int  j,
G4int  k 
)
inline

Definition at line 117 of file HadrontherapyMatrix.hh.

Referenced by Fill(), GetHitTrack(), StoreDoseFluenceAscii(), StoreMatrix(), and TotalEnergyDeposit().

117 { return (i * numberOfVoxelAlongY + j) * numberOfVoxelAlongZ + k; }
void HadrontherapyMatrix::Initialize ( )

Definition at line 116 of file HadrontherapyMatrix.cc.

References Clear().

Referenced by GetInstance().

117 {
118  // Clear ions store
119  Clear();
120  // Clear dose
121  for(int i=0;i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;i++)
122  {
123  matrix[i] = 0;
124  }
125 }
void HadrontherapyMatrix::PrintNuclides ( )

Definition at line 129 of file HadrontherapyMatrix.cc.

References G4cout, and G4endl.

130 {
131  for (size_t i=0; i<ionStore.size(); i++)
132  {
133  G4cout << ionStore[i].name << G4endl;
134  }
135 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void HadrontherapyMatrix::StoreDoseData ( )

Definition at line 273 of file HadrontherapyMatrix.cc.

References StoreMatrix().

274 {
275 
276  for (size_t i=0; i < ionStore.size(); i++){
277  StoreMatrix(ionStore[i].name + "_Dose.out", ionStore[i].dose, sizeof(G4double));
278  }
279 }
const XML_Char * name
void StoreMatrix(G4String file, void *data, size_t psize)
double G4double
Definition: G4Types.hh:76
void HadrontherapyMatrix::StoreDoseFluenceAscii ( G4String  filename = "")

Definition at line 284 of file HadrontherapyMatrix.cc.

References test::a, G4cout, G4endl, Index(), left, n, secondary, sort(), and width.

285 {
286 #define width 15L
287  filename = (file=="") ? stdFile:file;
288  // Sort like periodic table
289  std::sort(ionStore.begin(), ionStore.end());
290  G4cout << "Dose is being written to " << filename << G4endl;
291  ofs.open(filename, std::ios::out);
292  if (ofs.is_open())
293  {
294  // Write the voxels index and the list of particles/ions
295  ofs << std::setprecision(6) << std::left <<
296  "i\tj\tk\t";
297  // Total dose
298  ofs << std::setw(width) << "Dose(Gy)";
299  if (secondary)
300  {
301  for (size_t l=0; l < ionStore.size(); l++)
302  {
303  G4String a = (ionStore[l].isPrimary) ? "_1":""; // is it a primary?
304  ofs << std::setw(width) << ionStore[l].name + a <<
305  std::setw(width) << ionStore[l].name + a;
306  }
307  ofs << G4endl;
308 
309  /*
310  * PDGencondig
311  */
312  /*
313  ofs << std::setprecision(6) << std::left <<
314  "0\t0\t0\t";
315 
316  // Total dose
317  ofs << std::setw(width) << '0';
318  for (size_t l=0; l < ionStore.size(); l++)
319  {
320  ofs << std::setw(width) << ionStore[l].PDGencoding <<
321  std::setw(width) << ionStore[l].PDGencoding;
322  }
323  ofs << G4endl;
324  */
325  }
326  // Write data
327  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
328  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
329  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
330  {
331  G4int n = Index(i, j, k);
332  // Write only not identically null data lines
333  if (matrix[n])
334  {
335  ofs << G4endl;
336  ofs << i << '\t' << j << '\t' << k << '\t';
337  // Total dose
338  ofs << std::setw(width) << (matrix[n]/massOfVoxel)/doseUnit;
339  if (secondary)
340  {
341  for (size_t l=0; l < ionStore.size(); l++)
342  {
343  // Fill ASCII file rows
344  ofs << std::setw(width) << ionStore[l].dose[n]/massOfVoxel/doseUnit <<
345  std::setw(width) << ionStore[l].fluence[n];
346  }
347  }
348  }
349  }
350  ofs.close();
351  }
352 }
G4int Index(G4int i, G4int j, G4int k)
#define width
subroutine sort(A, N)
Definition: dpm25nuc7.f:4670
int G4int
Definition: G4Types.hh:78
G4GLOB_DLL std::ostream G4cout
const G4int n
#define G4endl
Definition: G4ios.hh:61
void HadrontherapyMatrix::StoreFluenceData ( )

Definition at line 266 of file HadrontherapyMatrix.cc.

References StoreMatrix().

267 {
268  for (size_t i=0; i < ionStore.size(); i++){
269  StoreMatrix(ionStore[i].name + "_Fluence.out", ionStore[i].fluence, sizeof(unsigned int));
270  }
271 }
const XML_Char * name
void StoreMatrix(G4String file, void *data, size_t psize)
void HadrontherapyMatrix::StoreMatrix ( G4String  file,
void *  data,
size_t  psize 
)

Definition at line 234 of file HadrontherapyMatrix.cc.

References G4endl, Index(), and n.

Referenced by StoreDoseData(), and StoreFluenceData().

235 {
236  if (data)
237  {
238  ofs.open(file, std::ios::out);
239  if (ofs.is_open())
240  {
241  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
242  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
243  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
244  {
245  G4int n = Index(i, j, k);
246  // Check for data type: u_int, G4double, XXX
247  if (psize == sizeof(unsigned int))
248  {
249  unsigned int* pdata = (unsigned int*)data;
250  if (pdata[n]) ofs << i << '\t' << j << '\t' <<
251  k << '\t' << pdata[n] << G4endl;
252  }
253  else if (psize == sizeof(G4double))
254  {
255  G4double* pdata = (G4double*)data;
256  if (pdata[n]) ofs << i << '\t' << j << '\t' <<
257  k << '\t' << pdata[n] << G4endl;
258  }
259  }
260  ofs.close();
261  }
262  }
263 }
G4int Index(G4int i, G4int j, G4int k)
int G4int
Definition: G4Types.hh:78
const G4int n
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
const XML_Char const XML_Char * data
void HadrontherapyMatrix::TotalEnergyDeposit ( )

Definition at line 392 of file HadrontherapyMatrix.cc.

References HadrontherapyAnalysisManager::GetInstance(), Index(), and n.

393 {
394  // Convert energy deposited to dose.
395  // Store the information of the matrix in a ntuple and in
396  // a 1D Histogram
397 #ifdef G4ANALYSIS_USE_ROOT
399 #endif
400 
401  if (matrix)
402  {
403  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
404  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
405  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
406  {
407 #ifdef G4ANALYSIS_USE_ROOT
408  G4int n = Index(i,j,k);
409  if (analysis -> IsTheTFile() )
410  {
411  analysis -> FillEnergyDeposit(i, j, k, matrix[n]/massOfVoxel/doseUnit);
412  analysis -> BraggPeak(i, matrix[n]/massOfVoxel/doseUnit);
413  }
414 #endif
415  }
416  }
417 }
static HadrontherapyAnalysisManager * GetInstance()
G4int Index(G4int i, G4int j, G4int k)
int G4int
Definition: G4Types.hh:78
const G4int n

Field Documentation

G4bool HadrontherapyMatrix::secondary = false
static

Definition at line 78 of file HadrontherapyMatrix.hh.

Referenced by Fill(), and StoreDoseFluenceAscii().


The documentation for this class was generated from the following files: