Geant4_10
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 #ifdef G4ANALYSIS_USE_ROOT
66  fMess = new IORTAnalysisFileMessenger(this);
67 #else
68  fMess = new IORTAnalysisFileMessenger();
69 #endif
70 }
72 
74 {
75  delete fMess;
76 #ifdef G4ANALYSIS_USE_ROOT
77  Clear();
78 #endif
79 }
80 
82 {
83  if (instance == 0) instance = new IORTAnalysisManager;
84  return instance;
85 }
86 #ifdef G4ANALYSIS_USE_ROOT
88 {
89  if (theTFile)
90  {
91  delete metaData;
92  metaData = 0;
93 
94  delete fragmentNtuple;
95  fragmentNtuple = 0;
96 
97  delete theROOTIonTuple;
98  theROOTIonTuple = 0;
99 
100  delete theROOTNtuple;
101  theROOTNtuple = 0;
102 
103  delete histo16;
104  histo16 = 0;
105 
106  delete histo15;
107  histo15 = 0;
108 
109  delete histo14;
110  histo14 = 0;
111 
112  delete histo13;
113  histo13 = 0;
114 
115  delete histo12;
116  histo12 = 0;
117 
118  delete histo11;
119  histo11 = 0;
120 
121  delete histo10;
122  histo10 = 0;
123 
124  delete histo9;
125  histo9 = 0;
126 
127  delete histo8;
128  histo8 = 0;
129 
130  delete histo7;
131  histo7 = 0;
132 
133  delete histo6;
134  histo6 = 0;
135 
136  delete histo5;
137  histo5 = 0;
138 
139  delete histo4;
140  histo4 = 0;
141 
142  delete histo3;
143  histo3 = 0;
144 
145  delete histo2;
146  histo2 = 0;
147 
148  delete histo1;
149  histo1 = 0;
150  }
151 }
153 
154 void IORTAnalysisManager::SetAnalysisFileName(G4String aFileName)
155 {
156  this->analysisFileName = aFileName;
157 }
158 
160 G4bool IORTAnalysisManager::IsTheTFile()
161 {
162  return (theTFile) ? true:false;
163 }
164 void IORTAnalysisManager::book()
165 {
166  delete theTFile; // this is similar to theTFile->Close() => delete all associated variables created via new, moreover it delete itself.
167 
168  theTFile = new TFile(analysisFileName, "RECREATE");
169 
170  // Create the histograms with the energy deposit along the X axis
171  histo1 = createHistogram1D("braggPeak","slice, energy", 400, 0., 80); //<different waterthicknesses are accoutned for in ROOT-analysis stage
172  histo2 = createHistogram1D("h20","Secondary protons - slice, energy", 400, 0., 400.);
173  histo3 = createHistogram1D("h30","Secondary neutrons - slice, energy", 400, 0., 400.);
174  histo4 = createHistogram1D("h40","Secondary alpha - slice, energy", 400, 0., 400.);
175  histo5 = createHistogram1D("h50","Secondary gamma - slice, energy", 400, 0., 400.);
176  histo6 = createHistogram1D("h60","Secondary electron - slice, energy", 400, 0., 400.);
177  histo7 = createHistogram1D("h70","Secondary triton - slice, energy", 400, 0., 400.);
178  histo8 = createHistogram1D("h80","Secondary deuteron - slice, energy", 400, 0., 400.);
179  histo9 = createHistogram1D("h90","Secondary pion - slice, energy", 400, 0., 400.);
180  histo10 = createHistogram1D("h100","Energy distribution of secondary electrons", 70, 0., 70.);
181  histo11 = createHistogram1D("h110","Energy distribution of secondary photons", 70, 0., 70.);
182  histo12 = createHistogram1D("h120","Energy distribution of secondary deuterons", 70, 0., 70.);
183  histo13 = createHistogram1D("h130","Energy distribution of secondary tritons", 70, 0., 70.);
184  histo14 = createHistogram1D("h140","Energy distribution of secondary alpha particles", 70, 0., 70.);
185  histo15 = createHistogram1D("heliumEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",
186  70, 0., 500.);
187  histo16 = createHistogram1D("hydrogenEnergyAfterPhantom","Energy distribution of secondary helium fragments after the phantom",
188  70, 0., 500.);
189 
190  kinFragNtuple = new TNtuple("kinFragNtuple",
191  "Kinetic energy by voxel & fragment",
192  "i:j:k:A:Z:kineticEnergy");
193  kineticEnergyPrimaryNtuple= new TNtuple("kineticEnergyPrimaryNtuple",
194  "Kinetic energy by voxel of primary",
195  "i:j:k:kineticEnergy");
196  doseFragNtuple = new TNtuple("doseFragNtuple",
197  "Energy deposit by voxel & fragment",
198  "i:j:k:A:Z:energy");
199 
200  fluenceFragNtuple = new TNtuple("fluenceFragNtuple",
201  "Fluence by voxel & fragment",
202  "i:j:k:A:Z:fluence");
203 
204  letFragNtuple = new TNtuple("letFragNtuple",
205  "Let by voxel & fragment",
206  "i:j:k:A:Z:letT:letD");
207 
208  theROOTNtuple = new TNtuple("theROOTNtuple",
209  "Energy deposit by slice",
210  "i:j:k:energy");
211 
212  theROOTIonTuple = new TNtuple("theROOTIonTuple",
213  "Generic ion information",
214  "a:z:occupancy:energy");
215 
216  fragmentNtuple = new TNtuple("fragmentNtuple",
217  "Fragments",
218  "A:Z:energy:posX:posY:posZ");
219 
220  metaData = new TNtuple("metaData",
221  "Metadata",
222  "events:detectorDistance:waterThickness:beamEnergy:energyError:phantomCenterDistance");
223 }
224 
226 void IORTAnalysisManager::FillEnergyDeposit(G4int i,
227  G4int j,
228  G4int k,
230 {
231  if (theROOTNtuple)
232  {
233  theROOTNtuple->Fill(i, j, k, energy);
234  }
235 }
236 
238 void IORTAnalysisManager::BraggPeak(G4int slice, G4double energy)
239 {
240  histo1->SetBinContent(slice, energy); //This uses setbincontent instead of fill to get labels correct
241 }
242 
244 void IORTAnalysisManager::SecondaryProtonEnergyDeposit(G4int slice, G4double energy)
245 {
246  histo2->Fill(slice, energy);
247 }
248 
250 void IORTAnalysisManager::SecondaryNeutronEnergyDeposit(G4int slice, G4double energy)
251 {
252  histo3->Fill(slice, energy);
253 }
254 
256 void IORTAnalysisManager::SecondaryAlphaEnergyDeposit(G4int slice, G4double energy)
257 {
258  histo4->Fill(slice, energy);
259 }
260 
262 void IORTAnalysisManager::SecondaryGammaEnergyDeposit(G4int slice, G4double energy)
263 {
264  histo5->Fill(slice, energy);
265 }
266 
268 void IORTAnalysisManager::SecondaryElectronEnergyDeposit(G4int slice, G4double energy)
269 {
270  histo6->Fill(slice, energy);
271 }
272 
274 void IORTAnalysisManager::SecondaryTritonEnergyDeposit(G4int slice, G4double energy)
275 {
276  histo7->Fill(slice, energy);
277 }
278 
280 void IORTAnalysisManager::SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy)
281 {
282  histo8->Fill(slice, energy);
283 }
284 
286 void IORTAnalysisManager::SecondaryPionEnergyDeposit(G4int slice, G4double energy)
287 {
288  histo9->Fill(slice, energy);
289 }
290 
292 void IORTAnalysisManager::electronEnergyDistribution(G4double energy)
293 {
294  histo10->Fill(energy);
295 }
296 
298 void IORTAnalysisManager::gammaEnergyDistribution(G4double energy)
299 {
300  histo11->Fill(energy);
301 }
302 
304 void IORTAnalysisManager::deuteronEnergyDistribution(G4double energy)
305 {
306  histo12->Fill(energy);
307 }
308 
310 void IORTAnalysisManager::tritonEnergyDistribution(G4double energy)
311 {
312  histo13->Fill(energy);
313 }
314 
316 void IORTAnalysisManager::alphaEnergyDistribution(G4double energy)
317 {
318  histo14->Fill(energy);
319 }
321 void IORTAnalysisManager::heliumEnergy(G4double secondaryParticleKineticEnergy)
322 {
323  histo15->Fill(secondaryParticleKineticEnergy);
324 }
325 
327 void IORTAnalysisManager::hydrogenEnergy(G4double secondaryParticleKineticEnergy)
328 {
329  histo16->Fill(secondaryParticleKineticEnergy);
330 }
331 
333  // FillKineticFragmentTuple create an ntuple where the voxel indexs, the atomic number and mass and the kinetic
334  // energy of all the particles interacting with the phantom, are stored
335 void IORTAnalysisManager::FillKineticFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double kinEnergy)
336 {
337  kinFragNtuple -> Fill(i, j, k, A, Z, kinEnergy);
338 }
339 
341  // FillKineticEnergyPrimaryNTuple creates a ntuple where the voxel indexs and the kinetic
342  // energies of ONLY primary particles interacting with the phantom, are stored
343 void IORTAnalysisManager::FillKineticEnergyPrimaryNTuple(G4int i, G4int j, G4int k, G4double kinEnergy)
344 {
345  kineticEnergyPrimaryNtuple -> Fill(i, j, k, kinEnergy);
346 }
347 
349  // This function is called only if ROOT is activated.
350  // It is called by the IORTMatric.cc class file and it is used to create two ntuples containing
351  // the total energy deposited and the fluence values, in each voxel and per any particle (primary
352  // and secondary particles beam)
353 void IORTAnalysisManager::FillVoxelFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double energy, G4double fluence)
354 {
355  // Fill the ntuple containing the voxel, mass and atomic number and the energy deposited
356  doseFragNtuple -> Fill( i, j, k, A, Z, energy );
357 
358  // Fill the ntuple containing the voxel, mass and atomic number and the fluence
359  if (i==1 && Z==1) {
360  fluenceFragNtuple -> Fill( i, j, k, A, Z, fluence );
361 
362  }
363 }
364 
365 void IORTAnalysisManager::FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letT, G4double letD)
366 {
367  letFragNtuple -> Fill( i, j, k, A, Z, letT, letD);
368 
369 }
371 void IORTAnalysisManager::FillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ)
372 {
373  fragmentNtuple->Fill(A, Z, energy, posX, posY, posZ);
374 }
375 
377 void IORTAnalysisManager::genericIonInformation(G4int a,
378  G4double z,
379  G4int electronOccupancy,
380  G4double energy)
381 {
382  if (theROOTIonTuple) {
383  theROOTIonTuple->Fill(a, z, electronOccupancy, energy);
384  }
385 }
386 
388 void IORTAnalysisManager::startNewEvent()
389 {
390  eventCounter++;
391 }
393 void IORTAnalysisManager::setGeometryMetaData(G4double endDetectorPosition, G4double waterThickness, G4double phantomCenter)
394 {
395  this->detectorDistance = endDetectorPosition;
396  this->phantomDepth = waterThickness;
397  this->phantomCenterDistance = phantomCenter;
398 }
399 void IORTAnalysisManager::setBeamMetaData(G4double meanKineticEnergy,G4double sigmaEnergy)
400 {
401  this->beamEnergy = meanKineticEnergy;
402  this->energyError = sigmaEnergy;
403 }
405 // Flush data & close the file
406 void IORTAnalysisManager::flush()
407 {
408  if (theTFile)
409  {
410  theTFile -> Write();
411  theTFile -> Close();
412  }
413  theTFile = 0;
414  eventCounter = 0;
415 }
416 
417 #endif
tuple a
Definition: test.py:11
ntupleExperimental Fill(depthExp, EdepExp)
void Clear(Node *)
int G4int
Definition: G4Types.hh:78
c1 Close()
double energy
Definition: plottest35.C:25
Float_t Z
Definition: plot.C:39
bool G4bool
Definition: G4Types.hh:79
static IORTAnalysisManager * GetInstance()
tuple z
Definition: test.py:28
double G4double
Definition: G4Types.hh:76
IORTAnalysisFileMessenger * fMess
static IORTAnalysisManager * instance