Geant4  10.03.p03
 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),
29 // G.A.P. Cirrone(d), F.Romano(d)
30 //
31 // Contributor Authors: S.Guatelli(e)
32 // Past Authors: G.Arnetta(c), S.E.Mazzaglia(d)
33 //
34 // (a) Fondazione Istituto San Raffaele G.Giglio, Cefalù, Italy
35 // (b) IBFM-CNR , Segrate (Milano), Italy
36 // (c) LATO (Laboratorio di Tecnologie Oncologiche), Cefalù, Italy
37 // (d) Laboratori Nazionali del Sud of the INFN, Catania, Italy
38 // (e) University of Wallongong, Australia
39 //
40 // *Corresponding author, email to carlo.casarino@polooncologicocefalu.it
42 
43 #include "IORTAnalysisManager.hh"
44 #include "IORTMatrix.hh"
46 #include <time.h>
47 
48 IORTAnalysisManager* IORTAnalysisManager::instance = 0;
49 
50 IORTAnalysisManager::IORTAnalysisManager() :
51  analysisFileName("DoseDistribution"),
52  eventCounter(0)
53 {
54  fMess = new IORTAnalysisFileMessenger(this);
55 }
57 
59 {
60  if (fMess)
61  delete fMess;
62  delete G4AnalysisManager::Instance();
63 }
64 
66 
68 {
69  if (instance == 0) instance = new IORTAnalysisManager;
70  return instance;
71 }
72 
74 
76 {
77  analysisFileName = aFileName;
78 }
79 
81 
83 {
84  // Create analysis manager
85  G4AnalysisManager* man = G4AnalysisManager::Instance();
86  man->SetVerboseLevel(1);
87  man->SetFirstHistoId(1);
88  man->SetFirstNtupleId(1);
89 
90  man->OpenFile(analysisFileName);
91 
92  // Create the histograms with the energy deposit along the X axis
93  //ID=1 <different waterthicknesses are accoutned for in ROOT-analysis stage>
94  man->CreateH1("braggPeak","slice, energy", 400, 0., 80); //
95  //ID=2
96  man->CreateH1("h20","Secondary protons - slice, energy", 400, 0., 400.);
97  //ID=3
98  man->CreateH1("h30","Secondary neutrons - slice, energy", 400, 0., 400.);
99  //ID=4
100  man->CreateH1("h40","Secondary alpha - slice, energy", 400, 0., 400.);
101  //ID=5
102  man->CreateH1("h50","Secondary gamma - slice, energy", 400, 0., 400.);
103  //ID=6
104  man->CreateH1("h60","Secondary electron - slice, energy", 400, 0., 400.);
105  //ID=7
106  man->CreateH1("h70","Secondary triton - slice, energy", 400, 0., 400.);
107  //ID=8
108  man->CreateH1("h80","Secondary deuteron - slice, energy", 400, 0., 400.);
109  //ID=9
110  man->CreateH1("h90","Secondary pion - slice, energy", 400, 0., 400.);
111  //ID=10
112  man->CreateH1("h100","Energy distribution of secondary electrons", 70, 0., 70.);
113  //ID=11
114  man->CreateH1("h110","Energy distribution of secondary photons", 70, 0., 70.);
115  //ID=12
116  man->CreateH1("h120","Energy distribution of secondary deuterons", 70, 0., 70.);
117  //ID = 13
118  man->CreateH1("h130","Energy distribution of secondary tritons", 70, 0., 70.);
119  //ID = 14
120  man->CreateH1("h140","Energy distribution of secondary alpha particles", 70, 0., 70.);
121  //ID = 15
122  man->CreateH1("heliumEnergyAfterPhantom",
123  "Energy distribution of secondary helium fragments after the phantom",
124  70, 0., 500.);
125  //ID= 16
126  man->CreateH1("hydrogenEnergyAfterPhantom",
127  "Energy distribution of secondary helium fragments after the phantom",
128  70, 0., 500.);
129 
130  //Now the ntuples
131  //ID = 1
132  man->CreateNtuple("kinFragNtuple",
133  "Kinetic energy by voxel & fragment");
134  man->CreateNtupleIColumn("i");
135  man->CreateNtupleIColumn("j");
136  man->CreateNtupleIColumn("k");
137  man->CreateNtupleIColumn("A");
138  man->CreateNtupleDColumn("Z");
139  man->CreateNtupleDColumn("kineticEnergy");
140  man->FinishNtuple();
141 
142  //ID = 2
143  man->CreateNtuple("kineticEnergyPrimaryNtuple",
144  "Kinetic energy by voxel of primary");
145  man->CreateNtupleIColumn("i");
146  man->CreateNtupleIColumn("j");
147  man->CreateNtupleIColumn("k");
148  man->CreateNtupleDColumn("kineticEnergy");
149  man->FinishNtuple();
150 
151  //ID = 3
152  man->CreateNtuple("doseFragNtuple",
153  "Energy deposit by voxel & fragment");
154  man->CreateNtupleIColumn("i");
155  man->CreateNtupleIColumn("j");
156  man->CreateNtupleIColumn("k");
157  man->CreateNtupleIColumn("A");
158  man->CreateNtupleDColumn("Z");
159  man->CreateNtupleDColumn("energy");
160  man->FinishNtuple();
161 
162  // ID =4
163  man->CreateNtuple("fluenceFragNtuple",
164  "Fluence by voxel & fragment");
165  man->CreateNtupleIColumn("i");
166  man->CreateNtupleIColumn("j");
167  man->CreateNtupleIColumn("k");
168  man->CreateNtupleIColumn("A");
169  man->CreateNtupleDColumn("Z");
170  man->CreateNtupleDColumn("fluence");
171  man->FinishNtuple();
172 
173  // ID=5
174  man->CreateNtuple("letFragNtuple",
175  "Let by voxel & fragment");
176  man->CreateNtupleIColumn("i");
177  man->CreateNtupleIColumn("j");
178  man->CreateNtupleIColumn("k");
179  man->CreateNtupleIColumn("A");
180  man->CreateNtupleDColumn("Z");
181  man->CreateNtupleDColumn("letT");
182  man->CreateNtupleDColumn("letD");
183  man->FinishNtuple();
184 
185  //ID=6
186  man->CreateNtuple("theROOTNtuple",
187  "Energy deposit by slice");
188  man->CreateNtupleIColumn("i");
189  man->CreateNtupleIColumn("j");
190  man->CreateNtupleIColumn("k");
191  man->CreateNtupleDColumn("energy");
192  man->FinishNtuple();
193 
194  //ID=7
195  man->CreateNtuple("theROOTIonTuple",
196  "Generic ion information");
197  man->CreateNtupleIColumn("a");
198  man->CreateNtupleDColumn("z");
199  man->CreateNtupleIColumn("occupancy");
200  man->CreateNtupleDColumn("energy");
201  man->FinishNtuple();
202 
203  //ID=8
204  man->CreateNtuple("fragmentNtuple",
205  "Fragments");
206  man->CreateNtupleIColumn("A");
207  man->CreateNtupleDColumn("Z");
208  man->CreateNtupleDColumn("energy");
209  man->CreateNtupleDColumn("posX");
210  man->CreateNtupleDColumn("posY");
211  man->CreateNtupleDColumn("posZ");
212  man->FinishNtuple();
213 
214 }
215 
218  G4int j,
219  G4int k,
221 {
222  G4AnalysisManager* man = G4AnalysisManager::Instance();
223  man->FillNtupleIColumn(6,0,i);
224  man->FillNtupleIColumn(6,1,j);
225  man->FillNtupleIColumn(6,2,k);
226  man->FillNtupleDColumn(6,3,energy);
227  man->AddNtupleRow(6);
228 }
229 
232 {
233  //FIXME
234  G4AnalysisManager::Instance()->FillH1(1,slice,energy);
235  //histo1->SetBinContent(slice, energy); //This uses setbincontent instead of fill to get labels correct
236 }
237 
240 {
241  G4AnalysisManager::Instance()->FillH1(2,slice,energy);
242 }
243 
246 {
247  G4AnalysisManager::Instance()->FillH1(3,slice,energy);
248 }
249 
252 {
253  G4AnalysisManager::Instance()->FillH1(4,slice,energy);
254 }
255 
258 {
259  G4AnalysisManager::Instance()->FillH1(5,slice,energy);
260 }
261 
264 {
265  G4AnalysisManager::Instance()->FillH1(6,slice,energy);
266 }
267 
270 {
271  G4AnalysisManager::Instance()->FillH1(7,slice,energy);
272 }
273 
276 {
277  G4AnalysisManager::Instance()->FillH1(8,slice,energy);
278 }
279 
282 {
283  G4AnalysisManager::Instance()->FillH1(9,slice,energy);
284 }
285 
288 {
289  G4AnalysisManager::Instance()->FillH1(10,energy);
290 }
291 
294 {
295  G4AnalysisManager::Instance()->FillH1(11,energy);
296 }
297 
300 {
301  G4AnalysisManager::Instance()->FillH1(12,energy);
302 }
303 
306 {
307  G4AnalysisManager::Instance()->FillH1(13,energy);
308 }
309 
312 {
313  G4AnalysisManager::Instance()->FillH1(14,energy);
314 }
315 
317 void IORTAnalysisManager::heliumEnergy(G4double secondaryParticleKineticEnergy)
318 {
319  G4AnalysisManager::Instance()->FillH1(15,secondaryParticleKineticEnergy);
320 }
321 
323 void IORTAnalysisManager::hydrogenEnergy(G4double secondaryParticleKineticEnergy)
324 {
325  G4AnalysisManager::Instance()->FillH1(16,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
332 {
333  G4AnalysisManager* man = G4AnalysisManager::Instance();
334  man->FillNtupleIColumn(1,0,i);
335  man->FillNtupleIColumn(1,1,j);
336  man->FillNtupleIColumn(1,2,k);
337  man->FillNtupleIColumn(1,3,A);
338  man->FillNtupleDColumn(1,4,Z);
339  man->FillNtupleDColumn(1,5,kinEnergy);
340  man->AddNtupleRow(1);
341 }
342 
344 // FillKineticEnergyPrimaryNTuple creates a ntuple where the voxel indexs and the kinetic
345 // energies of ONLY primary particles interacting with the phantom, are stored
347 {
348  G4AnalysisManager* man = G4AnalysisManager::Instance();
349  man->FillNtupleIColumn(2,0,i);
350  man->FillNtupleIColumn(2,1,j);
351  man->FillNtupleIColumn(2,2,k);
352  man->FillNtupleDColumn(2,3,kinEnergy);
353  man->AddNtupleRow(2);
354 }
355 
357 // This function is called only if ROOT is activated.
358 // It is called by the IORTMatric.cc class file and it is used to create two ntuples containing
359 // the total energy deposited and the fluence values, in each voxel and per any particle (primary
360 // and secondary particles beam)
362  G4double energy, G4double fluence)
363 {
364  G4AnalysisManager* man = G4AnalysisManager::Instance();
365  man->FillNtupleIColumn(3,0,i);
366  man->FillNtupleIColumn(3,1,j);
367  man->FillNtupleIColumn(3,2,k);
368  man->FillNtupleIColumn(3,3,A);
369  man->FillNtupleDColumn(3,4,Z);
370  man->FillNtupleDColumn(3,5,energy);
371  man->AddNtupleRow(3);
372 
373 
374  // Fill the ntuple containing the voxel, mass and atomic number and the fluence
375  if (i==1 && Z==1) {
376  man->FillNtupleIColumn(4,0,i);
377  man->FillNtupleIColumn(4,1,j);
378  man->FillNtupleIColumn(4,2,k);
379  man->FillNtupleIColumn(4,3,A);
380  man->FillNtupleDColumn(4,4,Z);
381  man->FillNtupleDColumn(4,5,fluence);
382  man->AddNtupleRow(4);
383  }
384 }
385 
387  G4double letT, G4double letD)
388 {
389  G4AnalysisManager* man = G4AnalysisManager::Instance();
390  man->FillNtupleIColumn(5,0,i);
391  man->FillNtupleIColumn(5,1,j);
392  man->FillNtupleIColumn(5,2,k);
393  man->FillNtupleIColumn(5,3,A);
394  man->FillNtupleDColumn(5,4,Z);
395  man->FillNtupleDColumn(5,5,letT);
396  man->FillNtupleDColumn(5,6,letD);
397  man->AddNtupleRow(5);
398 }
399 
402  G4double posX, G4double posY, G4double posZ)
403 {
404  G4AnalysisManager* man = G4AnalysisManager::Instance();
405  man->FillNtupleIColumn(8,0,A);
406  man->FillNtupleDColumn(8,1,Z);
407  man->FillNtupleDColumn(8,2,energy);
408  man->FillNtupleDColumn(8,3,posX);
409  man->FillNtupleDColumn(8,4,posY);
410  man->FillNtupleDColumn(8,5,posZ);
411  man->AddNtupleRow(8);
412 }
413 
416  G4double z,
417  G4int electronOccupancy,
419 {
420  G4AnalysisManager* man = G4AnalysisManager::Instance();
421  man->FillNtupleIColumn(7,0,a);
422  man->FillNtupleDColumn(7,1,z);
423  man->FillNtupleIColumn(7,2,electronOccupancy);
424  man->FillNtupleDColumn(7,3,energy);
425  man->AddNtupleRow(7);
426 }
427 
430 {
431  eventCounter++;
432 }
434 void IORTAnalysisManager::setGeometryMetaData(G4double endDetectorPosition, G4double waterThickness,
435  G4double phantomCenter)
436 {
437  detectorDistance = endDetectorPosition;
438  phantomDepth = waterThickness;
439  phantomCenterDistance = phantomCenter;
440 }
441 
443 void IORTAnalysisManager::setBeamMetaData(G4double meanKineticEnergy,G4double sigmaEnergy)
444 {
445  beamEnergy = meanKineticEnergy;
446  energyError = sigmaEnergy;
447 }
449 // Flush data & close the file
451 {
452  // Save histograms
453  G4AnalysisManager* man = G4AnalysisManager::Instance();
454  man->Write();
455  man->CloseFile();
456  eventCounter = 0;
457 }
458 
void SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy)
Fill 1D histogram with the energy deposit of secondary deuterons.
void FillEnergyDeposit(G4int voxelXId, G4int voxelYId, G4int voxelZId, G4double energyDeposit)
G4int CreateNtupleIColumn(const G4String &name)
G4bool SetFirstHistoId(G4int firstId)
G4int CreateH1(const G4String &name, const G4String &title, G4int nbins, G4double xmin, G4double xmax, const G4String &unitName="none", const G4String &fcnName="none", const G4String &binSchemeName="linear")
std::vector< ExP01TrackerHit * > a
Definition: ExP01Classes.hh:33
void genericIonInformation(G4int, G4double, G4int, G4double)
void tritonEnergyDistribution(G4double secondaryParticleKineticEnergy)
Energy distribution of secondary tritons originated in the phantom.
void FillVoxelFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double energy, G4double fluence)
void SetVerboseLevel(G4int verboseLevel)
G4int CreateNtuple(const G4String &name, const G4String &title)
void FillKineticFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double kinEnergy)
void hydrogenEnergy(G4double secondaryParticleKineticEnergy)
Energy distribution of the hydrogen (proton, d, t) particles after the phantom.
int G4int
Definition: G4Types.hh:78
void SecondaryElectronEnergyDeposit(G4int slice, G4double energy)
Fill 1D histogram with the energy deposit of secondary electrons.
G4bool OpenFile(const G4String &fileName="")
void FillFragmentTuple(G4int A, G4double Z, G4double energy, G4double posX, G4double posY, G4double posZ)
Energy ntuple.
void SecondaryProtonEnergyDeposit(G4int slice, G4double energy)
Fill 1D histogram with the energy deposit of secondary protons.
void SecondaryPionEnergyDeposit(G4int slice, G4double energy)
Fill 1D histogram with the energy deposit of secondary pions.
G4bool FillNtupleIColumn(G4int id, G4int value)
double A(double temperature)
void FillKineticEnergyPrimaryNTuple(G4int i, G4int j, G4int k, G4double kinEnergy)
Energy by voxel, mass number A and atomic number Z.
void BraggPeak(G4int, G4double)
Fill 1D histogram with the Bragg peak in the phantom.
void FillLetFragmentTuple(G4int i, G4int j, G4int k, G4int A, G4double Z, G4double letT, G4double letD)
let ntuple
G4bool FillNtupleDColumn(G4int id, G4double value)
void SecondaryTritonEnergyDeposit(G4int slice, G4double energy)
Fill 1D histogram with the energy deposit of secondary tritons.
void SecondaryNeutronEnergyDeposit(G4int slice, G4double energy)
Fill 1D histogram with the energy deposit of secondary neutrons.
static IORTAnalysisManager * GetInstance()
void gammaEnergyDistribution(G4double secondaryParticleKineticEnergy)
Energy distribution of secondary gamma originated in the phantom.
void alphaEnergyDistribution(G4double secondaryParticleKineticEnergy)
Energy distribution of secondary alpha originated in the phantom.
G4bool SetFirstNtupleId(G4int firstId)
void SecondaryAlphaEnergyDeposit(G4int slice, G4double energy)
Fill 1D histogram with the energy deposit of secondary alpha particles.
void flush()
Close the .hbk file with the histograms and the ntuples.
G4double energy(const ThreeVector &p, const G4double m)
IORTAnalysisFileMessenger(IORTAnalysisManager *amgr)
tuple z
Definition: test.py:28
void startNewEvent()
Tell the analysis manager that a new event is starting.
void SetAnalysisFileName(G4String)
G4int CreateNtupleDColumn(const G4String &name)
void deuteronEnergyDistribution(G4double secondaryParticleKineticEnergy)
Energy distribution of secondary deuterons originated in the phantom.
void electronEnergyDistribution(G4double secondaryParticleKineticEnergy)
Energy distribution of secondary electrons originated in the phantom.
void setGeometryMetaData(G4double, G4double, G4double)
from the detector construction information about the geometry can be written as metadata ...
double G4double
Definition: G4Types.hh:76
void SecondaryGammaEnergyDeposit(G4int slice, G4double energy)
Fill 1D histogram with the energy deposit of secondary gamma.
void setBeamMetaData(G4double, G4double)
metadata about the beam can be written this way
void heliumEnergy(G4double secondaryParticleKineticEnergy)
Energy distribution of the helium (He3 and alpha) particles after the phantom.