Geant4  10.02.p03
IORTMatrix Class Reference

#include <IORTMatrix.hh>

Collaboration diagram for IORTMatrix:

Public Member Functions

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

Static Public Member Functions

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

Static Public Attributes

static G4bool secondary = false
 

Private Member Functions

 IORTMatrix (G4int numberOfVoxelAlongX, G4int numberOfVoxelAlongY, G4int numberOfVoxelAlongZ, G4double massOfVoxel)
 

Private Attributes

G4int numberOfVoxelAlongX
 
G4int numberOfVoxelAlongY
 
G4int numberOfVoxelAlongZ
 
G4double massOfVoxel
 
G4doublematrix
 
G4inthitTrack
 
G4String stdFile
 
G4String filename
 
std::ofstream ofs
 
std::vector< ionionStore
 
G4double doseUnit
 

Static Private Attributes

static IORTMatrixinstance = NULL
 

Detailed Description

Definition at line 66 of file IORTMatrix.hh.

Constructor & Destructor Documentation

◆ IORTMatrix()

IORTMatrix::IORTMatrix ( G4int  numberOfVoxelAlongX,
G4int  numberOfVoxelAlongY,
G4int  numberOfVoxelAlongZ,
G4double  massOfVoxel 
)
private

Definition at line 74 of file IORTMatrix.cc.

74  :
75  stdFile("Dose.out"),
76  doseUnit(MeV/g)
77 {
78  // Number of the voxels of the phantom
79  // For Y = Z = 1 the phantom is divided in slices (and not in voxels)
80  // orthogonal to the beam axis
81  numberOfVoxelAlongX = voxelX;
82  numberOfVoxelAlongY = voxelY;
83  numberOfVoxelAlongZ = voxelZ;
84  massOfVoxel = mass;
85  // Create the dose matrix
87  if (matrix)
88  {
89  G4cout << "IORTMatrix: Memory space to store physical dose into " <<
91  " voxels has been allocated " << G4endl;
92  }
93  else G4Exception("IORTMatrix::IORTMatrix()", "IORT0005", FatalException, "Error: can't allocate memory to store physical dose!");
94  // Hit voxel (TrackID) marker
95  // This array mark the status of voxel, if a hit occur, with the trackID of the particle
96  // Must be initialized
98  ClearHitTrack();
99 }
static const double MeV
Definition: G4SIunits.hh:211
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134
G4double massOfVoxel
Definition: IORTMatrix.hh:136
int G4int
Definition: G4Types.hh:78
G4double doseUnit
Definition: IORTMatrix.hh:146
G4String stdFile
Definition: IORTMatrix.hh:140
function g(Y1, Y2, PT2)
Definition: hijing1.383.f:5206
G4GLOB_DLL std::ostream G4cout
G4double * matrix
Definition: IORTMatrix.hh:138
G4int numberOfVoxelAlongX
Definition: IORTMatrix.hh:133
void ClearHitTrack()
Definition: IORTMatrix.cc:145
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4int * hitTrack
Definition: IORTMatrix.hh:139
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135
Here is the call graph for this function:
Here is the caller graph for this function:

◆ ~IORTMatrix()

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
G4double * matrix
Definition: IORTMatrix.hh:138
G4int * hitTrack
Definition: IORTMatrix.hh:139
Here is the call graph for this function:

Member Function Documentation

◆ Clear()

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 }
std::vector< ion > ionStore
Definition: IORTMatrix.hh:144
Here is the caller graph for this function:

◆ ClearHitTrack()

void IORTMatrix::ClearHitTrack ( )

Definition at line 145 of file IORTMatrix.cc.

146 {
148 }
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134
int G4int
Definition: G4Types.hh:78
G4int numberOfVoxelAlongX
Definition: IORTMatrix.hh:133
G4int * hitTrack
Definition: IORTMatrix.hh:139
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135
Here is the caller graph for this function:

◆ Fill() [1/2]

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,
204  };
205  // Initialize data
206  if (newIon.dose && newIon.fluence)
207  {
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 }
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134
G4double * dose
G4String name
Definition: TRTMaterials.hh:40
static G4bool secondary
Definition: IORTMatrix.hh:83
G4double massOfVoxel
Definition: IORTMatrix.hh:136
int G4int
Definition: G4Types.hh:78
double A(double temperature)
unsigned int * fluence
Float_t Z
G4int numberOfVoxelAlongX
Definition: IORTMatrix.hh:133
std::vector< ion > ionStore
Definition: IORTMatrix.hh:144
double G4double
Definition: G4Types.hh:76
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120
Here is the call graph for this function:

◆ Fill() [2/2]

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 }
G4double * matrix
Definition: IORTMatrix.hh:138
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120
Here is the call graph for this function:

◆ GetHitTrack()

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 * hitTrack
Definition: IORTMatrix.hh:139
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120
Here is the call graph for this function:

◆ GetInstance() [1/2]

IORTMatrix * IORTMatrix::GetInstance ( )
static

Definition at line 61 of file IORTMatrix.cc.

62 {
63  return instance;
64 }
static IORTMatrix * instance
Definition: IORTMatrix.hh:132
Here is the caller graph for this function:

◆ GetInstance() [2/2]

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 }
static IORTMatrix * instance
Definition: IORTMatrix.hh:132
IORTMatrix(G4int numberOfVoxelAlongX, G4int numberOfVoxelAlongY, G4int numberOfVoxelAlongZ, G4double massOfVoxel)
Definition: IORTMatrix.cc:74
void Initialize()
Definition: IORTMatrix.cc:123
Here is the call graph for this function:

◆ GetMatrix()

G4double* IORTMatrix::GetMatrix ( )
inline

Definition at line 123 of file IORTMatrix.hh.

123 {return matrix;}
G4double * matrix
Definition: IORTMatrix.hh:138

◆ GetNumberOfVoxelAlongX()

G4int IORTMatrix::GetNumberOfVoxelAlongX ( )
inline

Definition at line 127 of file IORTMatrix.hh.

127 {return numberOfVoxelAlongX;}
G4int numberOfVoxelAlongX
Definition: IORTMatrix.hh:133

◆ GetNumberOfVoxelAlongY()

G4int IORTMatrix::GetNumberOfVoxelAlongY ( )
inline

Definition at line 128 of file IORTMatrix.hh.

128 {return numberOfVoxelAlongY;}
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134

◆ GetNumberOfVoxelAlongZ()

G4int IORTMatrix::GetNumberOfVoxelAlongZ ( )
inline

Definition at line 129 of file IORTMatrix.hh.

129 {return numberOfVoxelAlongZ;}
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135

◆ GetNvoxel()

G4int IORTMatrix::GetNvoxel ( )
inline

Definition at line 125 of file IORTMatrix.hh.

◆ Index()

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; }
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135
Here is the caller graph for this function:

◆ Initialize()

void IORTMatrix::Initialize ( )

Definition at line 123 of file IORTMatrix.cc.

124 {
125  // Clear ions store
126  Clear();
127  // Clear dose
129  {
130  matrix[i] = 0;
131  }
132 }
void Clear()
Definition: IORTMatrix.cc:111
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134
G4double * matrix
Definition: IORTMatrix.hh:138
G4int numberOfVoxelAlongX
Definition: IORTMatrix.hh:133
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135
Here is the call graph for this function:
Here is the caller graph for this function:

◆ PrintNuclides()

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
std::vector< ion > ionStore
Definition: IORTMatrix.hh:144

◆ StoreDoseData()

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 }
Float_t dose
G4String name
Definition: TRTMaterials.hh:40
void StoreMatrix(G4String file, void *data, size_t psize)
Definition: IORTMatrix.cc:241
std::vector< ion > ionStore
Definition: IORTMatrix.hh:144
double G4double
Definition: G4Types.hh:76
Here is the call graph for this function:

◆ StoreDoseFluenceAscii()

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 }
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134
static G4bool secondary
Definition: IORTMatrix.hh:83
G4double massOfVoxel
Definition: IORTMatrix.hh:136
TFile * file
int G4int
Definition: G4Types.hh:78
G4double doseUnit
Definition: IORTMatrix.hh:146
G4String stdFile
Definition: IORTMatrix.hh:140
Char_t n[5]
G4GLOB_DLL std::ostream G4cout
G4double * matrix
Definition: IORTMatrix.hh:138
G4int numberOfVoxelAlongX
Definition: IORTMatrix.hh:133
#define G4endl
Definition: G4ios.hh:61
std::vector< ion > ionStore
Definition: IORTMatrix.hh:144
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135
std::ofstream ofs
Definition: IORTMatrix.hh:141
#define width
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120
Here is the call graph for this function:

◆ StoreDoseFluenceRoot()

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,
378  ionStore[l].fluence[n] );
379 
380 
381  }
382 
383  }
384 }
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134
Float_t dose
G4double massOfVoxel
Definition: IORTMatrix.hh:136
int G4int
Definition: G4Types.hh:78
G4double doseUnit
Definition: IORTMatrix.hh:146
Char_t n[5]
double A(double temperature)
Float_t Z
G4int numberOfVoxelAlongX
Definition: IORTMatrix.hh:133
static IORTAnalysisManager * GetInstance()
std::vector< ion > ionStore
Definition: IORTMatrix.hh:144
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135
G4int Index(G4int i, G4int j, G4int k)
Definition: IORTMatrix.hh:120
Here is the call graph for this function:

◆ StoreFluenceData()

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 }
G4String name
Definition: TRTMaterials.hh:40
void StoreMatrix(G4String file, void *data, size_t psize)
Definition: IORTMatrix.cc:241
std::vector< ion > ionStore
Definition: IORTMatrix.hh:144
Here is the call graph for this function:

◆ StoreMatrix()

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 }
G4int numberOfVoxelAlongY
Definition: IORTMatrix.hh:134
int G4int
Definition: G4Types.hh:78
Char_t n[5]
G4int numberOfVoxelAlongX
Definition: IORTMatrix.hh:133
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
G4int numberOfVoxelAlongZ
Definition: IORTMatrix.hh:135
std::ofstream ofs
Definition: IORTMatrix.hh:141
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:

◆ TotalEnergyDeposit()

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

◆ doseUnit

G4double IORTMatrix::doseUnit
private

Definition at line 146 of file IORTMatrix.hh.

◆ filename

G4String IORTMatrix::filename
private

Definition at line 140 of file IORTMatrix.hh.

◆ hitTrack

G4int* IORTMatrix::hitTrack
private

Definition at line 139 of file IORTMatrix.hh.

◆ instance

IORTMatrix * IORTMatrix::instance = NULL
staticprivate

Definition at line 132 of file IORTMatrix.hh.

◆ ionStore

std::vector<ion> IORTMatrix::ionStore
private

Definition at line 144 of file IORTMatrix.hh.

◆ massOfVoxel

G4double IORTMatrix::massOfVoxel
private

Definition at line 136 of file IORTMatrix.hh.

◆ matrix

G4double* IORTMatrix::matrix
private

Definition at line 138 of file IORTMatrix.hh.

◆ numberOfVoxelAlongX

G4int IORTMatrix::numberOfVoxelAlongX
private

Definition at line 133 of file IORTMatrix.hh.

◆ numberOfVoxelAlongY

G4int IORTMatrix::numberOfVoxelAlongY
private

Definition at line 134 of file IORTMatrix.hh.

◆ numberOfVoxelAlongZ

G4int IORTMatrix::numberOfVoxelAlongZ
private

Definition at line 135 of file IORTMatrix.hh.

◆ ofs

std::ofstream IORTMatrix::ofs
private

Definition at line 141 of file IORTMatrix.hh.

◆ secondary

G4bool IORTMatrix::secondary = false
static

Definition at line 83 of file IORTMatrix.hh.

◆ stdFile

G4String IORTMatrix::stdFile
private

Definition at line 140 of file IORTMatrix.hh.


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