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

#include <IORTMatrix.hh>

Public Member Functions

 ~IORTMatrix ()
 
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="")
 
void StoreDoseFluenceRoot ()
 
G4int Index (G4int i, G4int j, G4int k)
 
G4double * GetMatrix ()
 
G4int GetNvoxel ()
 
G4int GetNumberOfVoxelAlongX ()
 
G4int GetNumberOfVoxelAlongY ()
 
G4int GetNumberOfVoxelAlongZ ()
 

Static Public Member Functions

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

Static Public Attributes

static G4bool secondary = false
 

Detailed Description

Definition at line 66 of file IORTMatrix.hh.

Constructor & Destructor Documentation

IORTMatrix::~IORTMatrix ( )

Definition at line 102 of file IORTMatrix.cc.

103 {
104  delete[] matrix;
105  delete[] hitTrack;
106  // free fluences/dose data memory
107  Clear();
108 }
void Clear()
Definition: IORTMatrix.cc:111

Here is the call graph for this function:

Member Function Documentation

void IORTMatrix::Clear ( )

Definition at line 111 of file IORTMatrix.cc.

112 {
113  for (size_t i=0; i<ionStore.size(); i++)
114  {
115  delete[] ionStore[i].dose;
116  delete[] ionStore[i].fluence;
117  }
118  ionStore.clear();
119 }

Here is the caller graph for this function:

void IORTMatrix::ClearHitTrack ( )

Definition at line 145 of file IORTMatrix.cc.

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

Definition at line 161 of file IORTMatrix.cc.

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

Here is the call graph for this function:

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

Definition at line 386 of file IORTMatrix.cc.

388 {
389  if (matrix)
390  matrix[Index(i,j,k)] += energyDeposit;
391 
392  // Store the energy deposit in the matrix element corresponding
393  // to the phantom voxel
394 }
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120

Here is the call graph for this function:

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

Definition at line 150 of file IORTMatrix.cc.

151 {
152  return &(hitTrack[Index(i,j,k)]);
153 }
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120

Here is the call graph for this function:

IORTMatrix * IORTMatrix::GetInstance ( )
static

Definition at line 61 of file IORTMatrix.cc.

62 {
63  return instance;
64 }

Here is the caller graph for this function:

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

Definition at line 67 of file IORTMatrix.cc.

68 {
69  if (instance) delete instance;
70  instance = new IORTMatrix(voxelX, voxelY, voxelZ, mass);
71  instance -> Initialize();
72  return instance;
73 }
void Initialize()
Definition: IORTMatrix.cc:123

Here is the call graph for this function:

G4double* IORTMatrix::GetMatrix ( )
inline

Definition at line 123 of file IORTMatrix.hh.

123 {return matrix;}
G4int IORTMatrix::GetNumberOfVoxelAlongX ( )
inline

Definition at line 127 of file IORTMatrix.hh.

127 {return numberOfVoxelAlongX;}
G4int IORTMatrix::GetNumberOfVoxelAlongY ( )
inline

Definition at line 128 of file IORTMatrix.hh.

128 {return numberOfVoxelAlongY;}
G4int IORTMatrix::GetNumberOfVoxelAlongZ ( )
inline

Definition at line 129 of file IORTMatrix.hh.

129 {return numberOfVoxelAlongZ;}
G4int IORTMatrix::GetNvoxel ( )
inline

Definition at line 125 of file IORTMatrix.hh.

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

Definition at line 120 of file IORTMatrix.hh.

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

Here is the caller graph for this function:

void IORTMatrix::Initialize ( )

Definition at line 123 of file IORTMatrix.cc.

124 {
125  // Clear ions store
126  Clear();
127  // Clear dose
128  for(int i=0;i<numberOfVoxelAlongX*numberOfVoxelAlongY*numberOfVoxelAlongZ;i++)
129  {
130  matrix[i] = 0;
131  }
132 }
void Clear()
Definition: IORTMatrix.cc:111

Here is the call graph for this function:

Here is the caller graph for this function:

void IORTMatrix::PrintNuclides ( )

Definition at line 136 of file IORTMatrix.cc.

137 {
138  for (size_t i=0; i<ionStore.size(); i++)
139  {
140  G4cout << ionStore[i].name << G4endl;
141  }
142 }
G4GLOB_DLL std::ostream G4cout
#define G4endl
Definition: G4ios.hh:61
void IORTMatrix::StoreDoseData ( )

Definition at line 280 of file IORTMatrix.cc.

281 {
282 
283  for (size_t i=0; i < ionStore.size(); i++){
284  StoreMatrix(ionStore[i].name + "_Dose.out", ionStore[i].dose, sizeof(G4double));
285  }
286 }
const XML_Char * name
Definition: expat.h:151
void StoreMatrix(G4String file, void *data, size_t psize)
Definition: IORTMatrix.cc:241
double G4double
Definition: G4Types.hh:76

Here is the call graph for this function:

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

Definition at line 291 of file IORTMatrix.cc.

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

Here is the call graph for this function:

void IORTMatrix::StoreDoseFluenceRoot ( )

Definition at line 362 of file IORTMatrix.cc.

363 {
365  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
366  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
367  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
368  {
369  G4int n = Index(i, j, k);
370  for (size_t l=0; l < ionStore.size(); l++)
371 
372  {
373  // Do the same work for .root file: fill dose/fluence ntuple
374  analysis -> FillVoxelFragmentTuple( i, j, k,
375  ionStore[l].A,
376  ionStore[l].Z,
377  ionStore[l].dose[n]/massOfVoxel/doseUnit,
378  ionStore[l].fluence[n] );
379 
380 
381  }
382 
383  }
384 }
int G4int
Definition: G4Types.hh:78
double A(double temperature)
const G4int n
static IORTAnalysisManager * GetInstance()
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120

Here is the call graph for this function:

void IORTMatrix::StoreFluenceData ( )

Definition at line 273 of file IORTMatrix.cc.

274 {
275  for (size_t i=0; i < ionStore.size(); i++){
276  StoreMatrix(ionStore[i].name + "_Fluence.out", ionStore[i].fluence, sizeof(unsigned int));
277  }
278 }
const XML_Char * name
Definition: expat.h:151
void StoreMatrix(G4String file, void *data, size_t psize)
Definition: IORTMatrix.cc:241

Here is the call graph for this function:

void IORTMatrix::StoreMatrix ( G4String  file,
void *  data,
size_t  psize 
)

Definition at line 241 of file IORTMatrix.cc.

242 {
243  if (data)
244  {
245  ofs.open(file, std::ios::out);
246  if (ofs.is_open())
247  {
248  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
249  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
250  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
251  {
252  G4int n = Index(i, j, k);
253  // Check for data type: u_int, G4double, XXX
254  if (psize == sizeof(unsigned int))
255  {
256  unsigned int* pdata = (unsigned int*)data;
257  if (pdata[n]) ofs << i << '\t' << j << '\t' <<
258  k << '\t' << pdata[n] << G4endl;
259  }
260  else if (psize == sizeof(G4double))
261  {
262  G4double* pdata = (G4double*)data;
263  if (pdata[n]) ofs << i << '\t' << j << '\t' <<
264  k << '\t' << pdata[n] << G4endl;
265  }
266  }
267  ofs.close();
268  }
269  }
270 }
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
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120

Here is the call graph for this function:

Here is the caller graph for this function:

void IORTMatrix::TotalEnergyDeposit ( )

Definition at line 395 of file IORTMatrix.cc.

396 {
397  // Store the information of the matrix in a ntuple and in
398  // a 1D Histogram
399 }

Member Data Documentation

G4bool IORTMatrix::secondary = false
static

Definition at line 83 of file IORTMatrix.hh.


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