source: trunk/examples/advanced/hadrontherapy/src/HadrontherapyAnalysisManager.cc @ 1029

Last change on this file since 1029 was 807, checked in by garnier, 16 years ago

update

File size: 8.5 KB
Line 
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// $Id: HadrontherapyAnalisysManager.cc;  May 2005
27// ----------------------------------------------------------------------------
28//                 GEANT 4 - Hadrontherapy example
29// ----------------------------------------------------------------------------
30// Code developed by:
31//
32// G.A.P. Cirrone(a)*, F. Di Rosa(a), S. Guatelli(b), G. Russo(a)
33//
34// (a) Laboratori Nazionali del Sud
35//     of the INFN, Catania, Italy
36// (b) INFN Section of Genova, Genova, Italy
37//
38// * cirrone@lns.infn.it
39// ----------------------------------------------------------------------------
40
41#ifdef  G4ANALYSIS_USE
42#include "HadrontherapyAnalysisManager.hh"
43
44HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::instance = 0;
45
46HadrontherapyAnalysisManager::HadrontherapyAnalysisManager() : 
47  aFact(0), theTree(0), histFact(0), tupFact(0), h1(0), h2(0), h3(0),
48  h4(0), h5(0), h6(0), h7(0), h8(0), h9(0), h10(0), h11(0), h12(0), h13(0), h14(0), ntuple(0),
49  ionTuple(0)
50{ 
51}
52
53HadrontherapyAnalysisManager::~HadrontherapyAnalysisManager() 
54{ 
55  delete ionTuple;
56  ionTuple = 0;
57 
58  delete ntuple;
59  ntuple = 0;
60
61  delete h14;
62  h14 = 0;
63
64  delete h13;
65  h13 = 0;
66
67  delete h12;
68  h12 = 0;
69
70  delete h11;
71  h11 = 0;
72
73  delete h10;
74  h10 = 0;
75
76  delete h9;
77  h9 = 0;
78
79  delete h8;
80  h8 = 0;
81
82  delete h7;
83  h7 = 0;
84
85  delete h6;
86  h6 = 0;
87
88  delete h5;
89  h5 = 0;
90
91  delete h4;
92  h4 = 0;
93
94  delete h3;
95  h3 = 0;
96
97  delete h2;
98  h2 = 0;
99
100  delete h1;
101  h1 = 0;
102 
103  delete tupFact;
104  tupFact = 0;
105
106  delete histFact;
107  histFact = 0;
108
109  delete theTree;
110  theTree = 0;
111
112  delete aFact;
113  aFact = 0;
114}
115
116HadrontherapyAnalysisManager* HadrontherapyAnalysisManager::getInstance()
117{
118  if (instance == 0) instance = new HadrontherapyAnalysisManager;
119  return instance;
120}
121
122void HadrontherapyAnalysisManager::book() 
123{
124  // Build up  the  analysis factory
125  aFact = AIDA_createAnalysisFactory();
126  AIDA::ITreeFactory* treeFact = aFact -> createTreeFactory();
127
128  // Create the .hbk file
129  G4String fileName = "hadrontherapy.hbk";
130  theTree = treeFact -> create(fileName,"hbook",false,true);
131  delete treeFact;
132
133  // Create the histogram and the ntuple factory
134  histFact = aFact -> createHistogramFactory(*theTree);
135  tupFact = aFact -> createTupleFactory(*theTree);
136
137  // Create the histograms with the enrgy deposit along the X axis
138  h1 = histFact -> createHistogram1D("10","slice, energy", 200, 0., 200. );
139
140  h2 = histFact -> createHistogram1D("20","Secondary protons - slice, energy", 200, 0., 200. );
141 
142  h3 = histFact -> createHistogram1D("30","Secondary neutrons - slice, energy", 200, 0., 200. );
143
144  h4 = histFact -> createHistogram1D("40","Secondary alpha - slice, energy", 200, 0., 200. );
145
146  h5 = histFact -> createHistogram1D("50","Secondary gamma - slice, energy", 200, 0., 200. );
147
148  h6 = histFact -> createHistogram1D("60","Secondary electron - slice, energy", 200, 0., 200. );
149
150  h7 = histFact -> createHistogram1D("70","Secondary triton - slice, energy", 200, 0., 200. );
151
152  h8 = histFact -> createHistogram1D("80","Secondary deuteron - slice, energy", 200, 0., 200. );
153
154  h9 = histFact -> createHistogram1D("90","Secondary pion - slice, energy", 200, 0., 200. );
155 
156  h10 = histFact -> createHistogram1D("100","Energy distribution of secondary electrons", 70, 0., 70. );
157 
158  h11 = histFact -> createHistogram1D("110","Energy distribution of secondary photons", 70, 0., 70. );
159
160  h12 = histFact -> createHistogram1D("120","Energy distribution of secondary deuterons", 70, 0., 70. );
161 
162  h13 = histFact -> createHistogram1D("130","Energy distribution of secondary tritons", 70, 0., 70. );
163
164  h14 = histFact -> createHistogram1D("140","Energy distribution of secondary alpha particles", 70, 0., 70. );
165
166  // Create the ntuple
167  G4String columnNames = "int i; int j; int k; double energy;";
168  G4String options = "";
169  if (tupFact) ntuple = tupFact -> create("1","1",columnNames, options);
170
171  // Create the ntuple
172  G4String columnNames2 = "int a; double z;  int occupancy; double energy;";
173  G4String options2 = "";
174  if (tupFact) ionTuple = tupFact -> create("2","2", columnNames2, options2);
175}
176
177void HadrontherapyAnalysisManager::FillEnergyDeposit(G4int i, 
178                                                     G4int j, 
179                                                     G4int k,
180                                                     G4double energy)
181{
182 if (ntuple)     {
183       G4int iSlice = ntuple -> findColumn("i");
184       G4int jSlice = ntuple -> findColumn("j");
185       G4int kSlice = ntuple -> findColumn("k");
186       G4int iEnergy = ntuple -> findColumn("energy");
187     
188       ntuple -> fill(iSlice,i);
189       ntuple -> fill(jSlice,j); 
190       ntuple -> fill(kSlice,k);
191       ntuple -> fill(iEnergy, energy);     }
192
193  ntuple -> addRow(); 
194}
195
196void HadrontherapyAnalysisManager::BraggPeak(G4int slice, G4double energy)
197{
198  h1 -> fill(slice,energy);
199}
200
201void HadrontherapyAnalysisManager::SecondaryProtonEnergyDeposit(G4int slice, G4double energy)
202{
203  h2 -> fill(slice,energy);
204}
205
206void HadrontherapyAnalysisManager::SecondaryNeutronEnergyDeposit(G4int slice, G4double energy)
207{
208  h3 -> fill(slice,energy);
209}
210
211void HadrontherapyAnalysisManager::SecondaryAlphaEnergyDeposit(G4int slice, G4double energy)
212{
213  h4 -> fill(slice,energy);
214}
215
216void HadrontherapyAnalysisManager::SecondaryGammaEnergyDeposit(G4int slice, G4double energy)
217{
218  h5 -> fill(slice,energy);
219}
220
221void HadrontherapyAnalysisManager::SecondaryElectronEnergyDeposit(G4int slice, G4double energy)
222{
223  h6 -> fill(slice,energy);
224}
225
226void HadrontherapyAnalysisManager::SecondaryTritonEnergyDeposit(G4int slice, G4double energy)
227{
228  h7 -> fill(slice,energy);
229}
230
231void HadrontherapyAnalysisManager::SecondaryDeuteronEnergyDeposit(G4int slice, G4double energy)
232{
233  h8 -> fill(slice,energy);
234}
235
236void HadrontherapyAnalysisManager::SecondaryPionEnergyDeposit(G4int slice, G4double energy)
237{
238  h9 -> fill(slice,energy);
239}
240
241void HadrontherapyAnalysisManager::electronEnergyDistribution(G4double energy)
242{
243  h10 -> fill(energy);
244}
245
246void HadrontherapyAnalysisManager::gammaEnergyDistribution(G4double energy)
247{
248  h11 -> fill(energy);
249}
250
251void HadrontherapyAnalysisManager::deuteronEnergyDistribution(G4double energy)
252{
253  h12 -> fill(energy);
254}
255
256void HadrontherapyAnalysisManager::tritonEnergyDistribution(G4double energy)
257{
258  h13 -> fill(energy);
259}
260
261void HadrontherapyAnalysisManager::alphaEnergyDistribution(G4double energy)
262{
263  h14 -> fill(energy);
264}
265
266void HadrontherapyAnalysisManager::genericIonInformation(G4int a, 
267                                                         G4double z, 
268                                                         G4int electronOccupancy,
269                                                         G4double energy) 
270{
271  if (ionTuple)    {
272       G4int aIndex = ionTuple -> findColumn("a");
273       G4int zIndex = ionTuple -> findColumn("z");
274       G4int electronIndex = ionTuple -> findColumn("occupancy"); 
275       G4int energyIndex = ionTuple -> findColumn("energy");
276     
277       ionTuple -> fill(aIndex,a);
278      ionTuple -> fill(zIndex,z); 
279      ionTuple -> fill(electronIndex, electronOccupancy); 
280       ionTuple -> fill(energyIndex, energy);
281     }
282   ionTuple -> addRow(); 
283}
284
285void HadrontherapyAnalysisManager::finish() 
286{ 
287  // Write all histograms to file
288  theTree -> commit();
289 
290  // Close (will again commit)
291  theTree ->close();
292}
293#endif
294
295
296
297
298
299
300
301
302
303
304
Note: See TracBrowser for help on using the repository browser.