Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IORTAnalysisManager.cc
Go to the documentation of this file.
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 // This is the *BASIC* version of IORT, a Geant4-based application
27 //
28 // Main Authors: G.Russo(a,b), C.Casarino*(c), G.C. Candiano(c), G.A.P. Cirrone(d), F.Romano(d)
29 // Contributor Authors: S.Guatelli(e)
30 // Past Authors: G.Arnetta(c), S.E.Mazzaglia(d)
31 //
32 // (a) Fondazione Istituto San Raffaele G.Giglio, Cefalù, Italy
33 // (b) IBFM-CNR , Segrate (Milano), Italy
34 // (c) LATO (Laboratorio di Tecnologie Oncologiche), Cefalù, Italy
35 // (d) Laboratori Nazionali del Sud of the INFN, Catania, Italy
36 // (e) University of Wallongong, Australia
37 //
38 // *Corresponding author, email to carlo.casarino@polooncologicocefalu.it
40 
41 #include "IORTAnalysisManager.hh"
42 #include "IORTMatrix.hh"
44 #include <time.h>
45 
47 
48 IORTAnalysisManager::IORTAnalysisManager()
49 #ifdef G4ANALYSIS_USE_ROOT
50 :
51 analysisFileName("DoseDistribution.root"),theTFile(0), histo1(0), histo2(0), histo3(0),
52 histo4(0), histo5(0), histo6(0), histo7(0), histo8(0), histo9(0), histo10(0), histo11(0), histo12(0), histo13(0), histo14(0), histo15(0), histo16(0),
53 kinFragNtuple(0),
54 kineticEnergyPrimaryNtuple(0),
55 doseFragNtuple(0),
56 fluenceFragNtuple(0),
57 letFragNtuple(0),
58 theROOTNtuple(0),
59 theROOTIonTuple(0),
60 fragmentNtuple(0),
61 metaData(0),
62 eventCounter(0)
63 #endif
64 {
65  fMess = new IORTAnalysisFileMessenger(this);
66 }
68 
70 {
71  delete fMess;
72 #ifdef G4ANALYSIS_USE_ROOT
73  Clear();
74 #endif
75 }
76 
78 {
79  if (instance == 0) instance = new IORTAnalysisManager;
80  return instance;
81 }
82 #ifdef G4ANALYSIS_USE_ROOT
84 {
85  if (theTFile)
86  {
87  delete metaData;
88  metaData = 0;
89 
90  delete fragmentNtuple;
91  fragmentNtuple = 0;
92 
93  delete theROOTIonTuple;
94  theROOTIonTuple = 0;
95 
96  delete theROOTNtuple;
97  theROOTNtuple = 0;
98 
99  delete histo16;
100  histo16 = 0;
101 
102  delete histo15;
103  histo15 = 0;
104 
105  delete histo14;
106  histo14 = 0;
107 
108  delete histo13;
109  histo13 = 0;
110 
111  delete histo12;
112  histo12 = 0;
113 
114  delete histo11;
115  histo11 = 0;
116 
117  delete histo10;
118  histo10 = 0;
119 
120  delete histo9;
121  histo9 = 0;
122 
123  delete histo8;
124  histo8 = 0;
125 
126  delete histo7;
127  histo7 = 0;
128 
129  delete histo6;
130  histo6 = 0;
131 
132  delete histo5;
133  histo5 = 0;
134 
135  delete histo4;
136  histo4 = 0;
137 
138  delete histo3;
139  histo3 = 0;
140 
141  delete histo2;
142  histo2 = 0;
143 
144  delete histo1;
145  histo1 = 0;
146  }
147 }
149 
150 void IORTAnalysisManager::SetAnalysisFileName(G4String aFileName)
151 {
152  this->analysisFileName = aFileName;
153 }
154 
156 G4bool IORTAnalysisManager::IsTheTFile()
157 {
158  return (theTFile) ? true:false;
159 }
160 void IORTAnalysisManager::book()
161 {
162  delete theTFile; // this is similar to theTFile->Close() => delete all associated variables created via new, moreover it delete itself.
163 
164  theTFile = new TFile(analysisFileName, "RECREATE");
165 
166  // Create the histograms with the energy deposit along the X axis
167  histo1 = createHistogram1D("braggPeak","slice, energy", 400, 0., 80); //<different waterthicknesses are accoutned for in ROOT-analysis stage
168  histo2 = createHistogram1D("h20","Secondary protons - slice, energy", 400, 0., 400.);
169  histo3 = createHistogram1D("h30","Secondary neutrons - slice, energy", 400, 0., 400.);
170  histo4 = createHistogram1D("h40","Secondary alpha - slice, energy", 400, 0., 400.);
171  histo5 = createHistogram1D("h50","Secondary gamma - slice, energy", 400, 0., 400.);
172  histo6 = createHistogram1D("h60","Secondary electron - slice, energy", 400, 0., 400.);
173  histo7 = createHistogram1D("h70","Secondary triton - slice, energy", 400, 0., 400.);
174  histo8 = createHistogram1D("h80","Secondary deuteron - slice, energy", 400, 0., 400.);
175  histo9 = createHistogram1D("h90","Secondary pion - slice, energy", 400, 0., 400.);
176  histo10 = createHistogram1D("h100","Energy distribution of secondary electrons", 70, 0., 70.);
177  histo11 = createHistogram1D("h110","Energy distribution of secondary photons", 70, 0., 70.);
178  histo12 = createHistogram1D("h120","Energy distribution of secondary deuterons", 70, 0., 70.);
179  histo13 = createHistogram1D("h130","Energy distribution of secondary tritons", 70, 0., 70.);
180  histo14 = createHistogram1D("h140","Energy distribution of secondary alpha particles", 70, 0., 70.);
181  histo15 = createHistogram1D("heliumEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",
182  70, 0., 500.);
183  histo16 = createHistogram1D("hydrogenEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",
184  70, 0., 500.);
185 
186  kinFragNtuple = new TNtuple("kinFragNtuple",
187  "Kinetic energy by voxel & fragment",
188  "i:j:k:A:Z:kineticEnergy");
189  kineticEnergyPrimaryNtuple= new TNtuple("kineticEnergyPrimaryNtuple",
190  "Kinetic energy by voxel of primary",
191  "i:j:k:kineticEnergy");
192  doseFragNtuple = new TNtuple("doseFragNtuple",
193  "Energy deposit by voxel & fragment",
194  "i:j:k:A:Z:energy");
195 
196  fluenceFragNtuple = new TNtuple("fluenceFragNtuple",
197  "Fluence by voxel & fragment",
198  "i:j:k:A:Z:fluence");
199 
200  letFragNtuple = new TNtuple("letFragNtuple",
201  "Let by voxel & fragment",
202  "i:j:k:A:Z:letT:letD");
203 
204  theROOTNtuple = new TNtuple("theROOTNtuple",
205  "Energy deposit by slice",
206  "i:j:k:energy");
207 
208  theROOTIonTuple = new TNtuple("theROOTIonTuple",
209  "Generic ion information",
210  "a:z:occupancy:energy");
211 
212  fragmentNtuple = new TNtuple("fragmentNtuple",
213  "Fragments",
214  "A:Z:energy:posX:posY:posZ");
215 
216  metaData = new TNtuple("metaData",
217  "Metadata",
218  "events:detectorDistance:waterThickness:beamEnergy:energyError:phantomCenterDistance");
219 }
220 
222 void IORTAnalysisManager::FillEnergyDeposit(G4int i,
223  G4int j,
224  G4int k,
226 {
227  if (theROOTNtuple)
228  {
229  theROOTNtuple->Fill(i, j, k, energy);
230  }
231 }
232 
234 void IORTAnalysisManager::BraggPeak(G4int slice, G4double energy)
235 {
236  histo1->SetBinContent(slice, energy); //This uses setbincontent instead of fill to get labels correct
237 }
238 
240 void IORTAnalysisManager::SecondaryProtonEnergyDeposit(G4int slice, G4double energy)
241 {
242  histo2->Fill(slice, energy);
243 }
244 
246 void IORTAnalysisManager::SecondaryNeutronEnergyDeposit(G4int slice, G4double energy)
247 {
248  histo3->Fill(slice, energy);
249 }
250 
252 void IORTAnalysisManager::SecondaryAlphaEnergyDeposit(G4int slice, G4double energy)
253 {
254  histo4->Fill(slice, energy);
255 }
256 
258 void IORTAnalysisManager::SecondaryGammaEnergyDeposit(G4int slice, G4double energy)
259 {
260  histo5->Fill(slice, energy);
261 }
262 
264 void IORTAnalysisManager::SecondaryElectronEnergyDeposit(G4int slice, G4double energy)
265 {
266  histo6->Fill(slice, energy);
267 }
268 
270 void IORTAnalysisManager::SecondaryTritonEnergyDeposit(G4int slice, G4double energy)
271 {
272  histo7->Fill(slice, energy);
273 }
274 
276 void IORTAnalysisManager::SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy)
277 {
278  histo8->Fill(slice, energy);
279 }
280 
282 void IORTAnalysisManager::SecondaryPionEnergyDeposit(G4int slice, G4double energy)
283 {
284  histo9->Fill(slice, energy);
285 }
286 
288 void IORTAnalysisManager::electronEnergyDistribution(G4double energy)
289 {
290  histo10->Fill(energy);
291 }
292 
294 void IORTAnalysisManager::gammaEnergyDistribution(G4double energy)
295 {
296  histo11->Fill(energy);
297 }
298 
300 void IORTAnalysisManager::deuteronEnergyDistribution(G4double energy)
301 {
302  histo12->Fill(energy);
303 }
304 
306 void IORTAnalysisManager::tritonEnergyDistribution(G4double energy)
307 {
308  histo13->Fill(energy);
309 }
310 
312 void IORTAnalysisManager::alphaEnergyDistribution(G4double energy)
313 {
314  histo14->Fill(energy);
315 }
317 void IORTAnalysisManager::heliumEnergy(G4double secondaryParticleKineticEnergy)
318 {
319  histo15->Fill(secondaryParticleKineticEnergy);
320 }
321 
323 void IORTAnalysisManager::hydrogenEnergy(G4double secondaryParticleKineticEnergy)
324 {
325  histo16->Fill(secondaryParticleKineticEnergy);
326 }
327 
329  // FillKineticFragmentTuple create an ntuple where the voxel indexs, the atomic number and mass and the kinetic
330  // energy of all the particles interacting with the phantom, are stored
331 void IORTAnalysisManager::FillKineticFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double kinEnergy)
332 {
333  kinFragNtuple -> Fill(i, j, k, A, Z, kinEnergy);
334 }
335 
337  // FillKineticEnergyPrimaryNTuple creates a ntuple where the voxel indexs and the kinetic
338  // energies of ONLY primary particles interacting with the phantom, are stored
339 void IORTAnalysisManager::FillKineticEnergyPrimaryNTuple(G4int i, G4int j, G4int k, G4double kinEnergy)
340 {
341  kineticEnergyPrimaryNtuple -> Fill(i, j, k, kinEnergy);
342 }
343 
345  // This function is called only if ROOT is activated.
346  // It is called by the IORTMatric.cc class file and it is used to create two ntuples containing
347  // the total energy deposited and the fluence values, in each voxel and per any particle (primary
348  // and secondary particles beam)
349 void IORTAnalysisManager::FillVoxelFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double energy, G4double fluence)
350 {
351  // Fill the ntuple containing the voxel, mass and atomic number and the energy deposited
352  doseFragNtuple -> Fill( i, j, k, A, Z, energy );
353 
354  // Fill the ntuple containing the voxel, mass and atomic number and the fluence
355  if (i==1 && Z==1) {
356  fluenceFragNtuple -> Fill( i, j, k, A, Z, fluence );
357 
358  }
359 }
360 
361 void IORTAnalysisManager::FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letT, G4double letD)
362 {
363  letFragNtuple -> Fill( i, j, k, A, Z, letT, letD);
364 
365 }
367 void IORTAnalysisManager::FillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ)
368 {
369  fragmentNtuple->Fill(A, Z, energy, posX, posY, posZ);
370 }
371 
373 void IORTAnalysisManager::genericIonInformation(G4int a,
374  G4double z,
375  G4int electronOccupancy,
376  G4double energy)
377 {
378  if (theROOTIonTuple) {
379  theROOTIonTuple->Fill(a, z, electronOccupancy, energy);
380  }
381 }
382 
384 void IORTAnalysisManager::startNewEvent()
385 {
386  eventCounter++;
387 }
389 void IORTAnalysisManager::setGeometryMetaData(G4double endDetectorPosition, G4double waterThickness, G4double phantomCenter)
390 {
391  this->detectorDistance = endDetectorPosition;
392  this->phantomDepth = waterThickness;
393  this->phantomCenterDistance = phantomCenter;
394 }
395 void IORTAnalysisManager::setBeamMetaData(G4double meanKineticEnergy,G4double sigmaEnergy)
396 {
397  this->beamEnergy = meanKineticEnergy;
398  this->energyError = sigmaEnergy;
399 }
401 // Flush data & close the file
402 void IORTAnalysisManager::flush()
403 {
404  if (theTFile)
405  {
406  theTFile -> Write();
407  theTFile -> Close();
408  }
409  theTFile = 0;
410  eventCounter = 0;
411 }
412 
413 #endif