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
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="")
 
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.

References Clear().

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

Member Function Documentation

void IORTMatrix::Clear ( )

Definition at line 111 of file IORTMatrix.cc.

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

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 }
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.

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

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 }
G4double * dose
static G4bool secondary
Definition: IORTMatrix.hh:83
const XML_Char * name
int G4int
Definition: G4Types.hh:78
unsigned int * fluence
double G4double
Definition: G4Types.hh:76
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:122
void IORTMatrix::Fill ( G4int  i,
G4int  j,
G4int  k,
G4double  energyDeposit 
)

Definition at line 390 of file IORTMatrix.cc.

References Index().

392 {
393  if (matrix)
394  matrix[Index(i,j,k)] += energyDeposit;
395 
396  // Store the energy deposit in the matrix element corresponding
397  // to the phantom voxel
398 }
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:122
G4int * IORTMatrix::GetHitTrack ( G4int  i,
G4int  j,
G4int  k 
)

Definition at line 150 of file IORTMatrix.cc.

References Index().

151 {
152  return &(hitTrack[Index(i,j,k)]);
153 }
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:122
IORTMatrix * IORTMatrix::GetInstance ( )
static
IORTMatrix * IORTMatrix::GetInstance ( G4int  nX,
G4int  nY,
G4int  nZ,
G4double  mass 
)
static

Definition at line 67 of file IORTMatrix.cc.

References Initialize().

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
G4double* IORTMatrix::GetMatrix ( )
inline

Definition at line 125 of file IORTMatrix.hh.

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

Definition at line 129 of file IORTMatrix.hh.

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

Definition at line 130 of file IORTMatrix.hh.

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

Definition at line 131 of file IORTMatrix.hh.

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

Definition at line 127 of file IORTMatrix.hh.

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

Definition at line 122 of file IORTMatrix.hh.

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

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

Definition at line 123 of file IORTMatrix.cc.

References Clear().

Referenced by GetInstance().

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
void IORTMatrix::PrintNuclides ( )

Definition at line 136 of file IORTMatrix.cc.

References G4cout, and G4endl.

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.

References StoreMatrix().

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 }
void StoreMatrix(G4String file, void *data, size_t psize)
Definition: IORTMatrix.cc:241
const XML_Char * name
double G4double
Definition: G4Types.hh:76
void IORTMatrix::StoreDoseFluenceAscii ( G4String  filename = "")

Definition at line 291 of file IORTMatrix.cc.

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

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 }
static G4bool secondary
Definition: IORTMatrix.hh:83
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
#define width
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:122
void IORTMatrix::StoreFluenceData ( )

Definition at line 273 of file IORTMatrix.cc.

References StoreMatrix().

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 }
void StoreMatrix(G4String file, void *data, size_t psize)
Definition: IORTMatrix.cc:241
const XML_Char * name
void IORTMatrix::StoreMatrix ( G4String  file,
void *  data,
size_t  psize 
)

Definition at line 241 of file IORTMatrix.cc.

References G4endl, Index(), and n.

Referenced by StoreDoseData(), and StoreFluenceData().

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 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:122
const XML_Char const XML_Char * data
void IORTMatrix::TotalEnergyDeposit ( )

Definition at line 399 of file IORTMatrix.cc.

400 {
401  // Store the information of the matrix in a ntuple and in
402  // a 1D Histogram
403 
404 /*
405 /////////////////////////////////// imported from eliot_geant4.9.3p01_version /////////////////////////////
406  G4int k;
407  G4int j;
408  G4int i;
409 
410  if (matrix)
411  { // AGGIUNTO
412  std::ofstream ofs; // AGGIUNTO
413 
414 ofs.open("PDD9.9Mev_coll60_0gradi_s500_Sp1_6gradi_step0.01_setcuts0.01.out"); // AGGIUNTO
415 
416  for(G4int l = 0; l < numberOfVoxelAlongZ; l++) // was "numberVoxelZ" and so in the other directions
417  {
418  k = l;
419 
420  for(G4int m = 0; m < numberOfVoxelAlongY; m++)
421  {
422  j = m * numberOfVoxelAlongZ + k;
423 
424  for(G4int n = 0; n < numberOfVoxelAlongX; n++)
425  {
426  i = n* numberOfVoxelAlongZ * numberOfVoxelAlongY + j;
427  if(matrix[i] != 0)
428  {
429  ofs<< n <<'\t'<< m <<'\t'<< // AGGIUNTO
430  k<<'\t'<<matrix[i]<<G4endl; // AGGIUNTO
431 
432 
433  }
434  }
435  }
436  }
437  ofs.close(); // AGGIUNTO
438  }
439 /////////////////////////////////// imported from eliot_geant4.9.3p01_version /////////////////////////////
440 */
441 
442  // Convert energy deposited to dose.
443  // Store the information of the matrix in a ntuple and in
444  // a 1D Histogram
445 /*
446  IORTAnalysisManager* analysis = IORTAnalysisManager::GetInstance();
447  if (matrix)
448  {
449  for(G4int i = 0; i < numberOfVoxelAlongX; i++)
450  for(G4int j = 0; j < numberOfVoxelAlongY; j++)
451  for(G4int k = 0; k < numberOfVoxelAlongZ; k++)
452  {
453  G4int n = Index(i,j,k);
454 
455 #ifdef G4ANALYSIS_USE_ROOT
456  if (analysis -> IsTheTFile() )
457  {
458  analysis -> FillEnergyDeposit(i, j, k, matrix[n]/massOfVoxel/doseUnit);
459  analysis -> BraggPeak(i, matrix[n]/massOfVoxel/doseUnit);
460  }
461 #endif
462 
463  }
464  }
465 */
466 }

Field Documentation

G4bool IORTMatrix::secondary = false
static

Definition at line 83 of file IORTMatrix.hh.

Referenced by Fill(), and StoreDoseFluenceAscii().


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