Geant4  10.03.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HadrontherapyMatrix Class Reference

#include <HadrontherapyMatrix.hh>

Public Member Functions

 ~HadrontherapyMatrix ()
 
void PrintNuclides ()
 
void ClearHitTrack ()
 
G4intGetHitTrack (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)
 
G4doubleGetMatrix ()
 
G4int GetNvoxel ()
 
G4int GetNumberOfVoxelAlongX ()
 
G4int GetNumberOfVoxelAlongY ()
 
G4int GetNumberOfVoxelAlongZ ()
 

Static Public Member Functions

static HadrontherapyMatrixGetInstance ()
 
static HadrontherapyMatrixGetInstance (G4int nX, G4int nY, G4int nZ, G4double mass)
 

Static Public Attributes

static G4bool secondary = false
 

Detailed Description

Definition at line 55 of file HadrontherapyMatrix.hh.

Constructor & Destructor Documentation

HadrontherapyMatrix::~HadrontherapyMatrix ( )

Definition at line 89 of file HadrontherapyMatrix.cc.

90 {
91  delete[] matrix;
92  delete[] hitTrack;
93  // free fluences/dose data memory
94  Clear();
95 }

Here is the call graph for this function:

Member Function Documentation

void HadrontherapyMatrix::Clear ( )

Definition at line 98 of file HadrontherapyMatrix.cc.

99 {
100  for (size_t i=0; i<ionStore.size(); i++)
101  {
102  delete[] ionStore[i].dose;
103  delete[] ionStore[i].fluence;
104  }
105  ionStore.clear();
106 }

Here is the caller graph for this function:

void HadrontherapyMatrix::ClearHitTrack ( )

Definition at line 132 of file HadrontherapyMatrix.cc.

133 {
134  for(G4int i=0; i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ; i++) hitTrack[i] = 0;
135 }
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 148 of file HadrontherapyMatrix.cc.

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

Here is the call graph for this function:

void HadrontherapyMatrix::Fill ( G4int  i,
G4int  j,
G4int  k,
G4double  energyDeposit 
)

Definition at line 377 of file HadrontherapyMatrix.cc.

379 {
380  if (matrix)
381  matrix[Index(i,j,k)] += energyDeposit;
382 
383  // Store the energy deposit in the matrix element corresponding
384  // to the phantom voxel
385 }
G4int Index(G4int i, G4int j, G4int k)

Here is the call graph for this function:

G4int * HadrontherapyMatrix::GetHitTrack ( G4int  i,
G4int  j,
G4int  k 
)

Definition at line 137 of file HadrontherapyMatrix.cc.

138 {
139  return &(hitTrack[Index(i,j,k)]);
140 }
G4int Index(G4int i, G4int j, G4int k)

Here is the call graph for this function:

HadrontherapyMatrix * HadrontherapyMatrix::GetInstance ( )
static

Definition at line 48 of file HadrontherapyMatrix.cc.

49 {
50  return instance;
51 }
static MCTruthManager * instance

Here is the caller graph for this function:

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

Definition at line 54 of file HadrontherapyMatrix.cc.

55 {
56  if (instance) delete instance;
57  instance = new HadrontherapyMatrix(voxelX, voxelY, voxelZ, mass);
58  instance -> Initialize();
59  return instance;
60 }
static MCTruthManager * instance

Here is the call graph for this function:

G4double* HadrontherapyMatrix::GetMatrix ( )
inline

Definition at line 114 of file HadrontherapyMatrix.hh.

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

Definition at line 118 of file HadrontherapyMatrix.hh.

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

Definition at line 119 of file HadrontherapyMatrix.hh.

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

Definition at line 120 of file HadrontherapyMatrix.hh.

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

Definition at line 116 of file HadrontherapyMatrix.hh.

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

Definition at line 111 of file HadrontherapyMatrix.hh.

111 { return (i * numberOfVoxelAlongY + j) * numberOfVoxelAlongZ + k; }

Here is the caller graph for this function:

void HadrontherapyMatrix::Initialize ( )

Definition at line 110 of file HadrontherapyMatrix.cc.

111 {
112  // Clear ions store
113  Clear();
114  // Clear dose
115  for(int i=0;i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;i++)
116  {
117  matrix[i] = 0;
118  }
119 }

Here is the call graph for this function:

Here is the caller graph for this function:

void HadrontherapyMatrix::PrintNuclides ( )

Definition at line 123 of file HadrontherapyMatrix.cc.

124 {
125  for (size_t i=0; i<ionStore.size(); i++)
126  {
127  G4cout << ionStore[i].name << G4endl;
128  }
129 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void HadrontherapyMatrix::StoreDoseData ( )

Definition at line 267 of file HadrontherapyMatrix.cc.

268 {
269 
270  for (size_t i=0; i < ionStore.size(); i++){
271  StoreMatrix(ionStore[i].name + "_Dose.out", ionStore[i].dose, sizeof(G4double));
272  }
273 }
const XML_Char * name
Definition: expat.h:151
void StoreMatrix(G4String file, void *data, size_t psize)
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

void HadrontherapyMatrix::StoreDoseFluenceAscii ( G4String  filename = "")

Definition at line 278 of file HadrontherapyMatrix.cc.

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

Here is the call graph for this function:

void HadrontherapyMatrix::StoreFluenceData ( )

Definition at line 260 of file HadrontherapyMatrix.cc.

261 {
262  for (size_t i=0; i < ionStore.size(); i++){
263  StoreMatrix(ionStore[i].name + "_Fluence.out", ionStore[i].fluence, sizeof(unsigned int));
264  }
265 }
const XML_Char * name
Definition: expat.h:151
void StoreMatrix(G4String file, void *data, size_t psize)

Here is the call graph for this function:

void HadrontherapyMatrix::StoreMatrix ( G4String  file,
void data,
size_t  psize 
)

Definition at line 228 of file HadrontherapyMatrix.cc.

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

Here is the call graph for this function:

Here is the caller graph for this function:

void HadrontherapyMatrix::TotalEnergyDeposit ( )

Definition at line 386 of file HadrontherapyMatrix.cc.

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

Here is the call graph for this function:

Member Data Documentation

G4bool HadrontherapyMatrix::secondary = false
static

Definition at line 72 of file HadrontherapyMatrix.hh.


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