source: trunk/examples/advanced/brachytherapy/src/BrachyAnalysisManager.cc@ 1143

Last change on this file since 1143 was 807, checked in by garnier, 17 years ago

update

File size: 6.4 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// Code developed by:
27// S.Guatelli
28//
29// *******************************
30// * *
31// * BrachyAnalysisManager.cc *
32// * *
33// *******************************
34//
35// $Id: BrachyAnalysisManager.cc,v 1.19 2007/05/14 09:57:55 pia Exp $
36// GEANT4 tag $Name: $
37//
38#include <stdlib.h>
39#include <fstream>
40#include "BrachyAnalysisManager.hh"
41
42#include "G4ios.hh"
43
44#ifdef G4ANALYSIS_USE
45#include "AIDA/IHistogram1D.h"
46#include "AIDA/IHistogram2D.h"
47#include "AIDA/IManagedObject.h"
48#include "AIDA/IAnalysisFactory.h"
49#include "AIDA/IHistogramFactory.h"
50#include "AIDA/ITupleFactory.h"
51#include "AIDA/ITreeFactory.h"
52#include "AIDA/ITree.h"
53#include "AIDA/ITuple.h"
54#endif
55
56BrachyAnalysisManager* BrachyAnalysisManager::instance = 0;
57
58BrachyAnalysisManager::BrachyAnalysisManager()
59{
60
61#ifdef G4ANALYSIS_USE
62 aFact = 0;
63 theTree(0);
64 histFact = 0;
65 tupFact = 0;
66 h1 = 0;
67 h2 = 0;
68 ntuple = 0;
69
70 // Instantiate the factories
71 // The factories manage the analysis objects
72 aFact = AIDA_createAnalysisFactory();
73
74 AIDA::ITreeFactory *treeFact = aFact -> createTreeFactory();
75
76 // Definition of the output file
77 G4String fileName = "brachytherapy.hbk";
78 theTree = treeFact -> create(fileName,"hbook",false, true);
79
80 delete treeFact;
81#endif
82}
83
84BrachyAnalysisManager::~BrachyAnalysisManager()
85{
86
87#ifdef G4ANALYSIS_USE
88 delete tupFact;
89 tupFact = 0;
90
91 delete histFact;
92 histFact = 0;
93
94 delete theTree;
95 histFact = 0;
96
97 delete aFact;
98 aFact = 0;
99#endif
100}
101
102BrachyAnalysisManager* BrachyAnalysisManager::getInstance()
103{
104 if (instance == 0) instance = new BrachyAnalysisManager;
105 return instance;
106}
107
108void BrachyAnalysisManager::book()
109{
110#ifdef G4ANALYSIS_USE
111 // Instantiate the histogram and ntuple factories
112 histFact = aFact -> createHistogramFactory( *theTree );
113 tupFact = aFact -> createTupleFactory ( *theTree );
114
115 // Creating a 2D histogram
116 // Energy deposit in the plane containing the source
117 h1 = histFact -> createHistogram2D("10","Energy, pos", //histoID,histo name
118 300 ,-150.,150., //bins'number,xmin,xmax
119 300,-150.,150.); //bins'number,ymin,ymax
120 //creating a 1D histograms
121 // Histogram containing the initial energy (MeV) of the photons delivered by the radioactive core
122 h2 = histFact -> createHistogram1D("20","Initial Energy", //histoID, histo name
123 1000,0.,1.); //bins' number, xmin, xmax
124
125 // Histogram containing the energy deposit in the plane containing the source, along the axis
126 // perpendicular to the source main axis
127 h3 = histFact -> createHistogram1D("30","Energy deposit Distribution",
128 300,-150.,150.); //bins' number, xmin, xmax
129
130 //defining the ntuple columns' name
131 std::string columnNames = "float energy; float x; float y; float z";
132 std::string options = "";
133
134 //creating a ntuple
135 if (tupFact) ntuple = tupFact -> create("1","1",columnNames, options);
136 // check for non-zero ...
137 if (ntuple) G4cout<<"The Ntuple is non-zero"<<G4endl;
138#endif
139}
140
141void BrachyAnalysisManager::FillNtupleWithEnergy(G4double xx,
142 G4double yy,
143 G4double zz,
144 G4float en)
145{
146#ifdef G4ANALYSIS_USE
147 if (ntuple == 0)
148 {
149 G4cout << "AAAAAAAGH..... The Ntuple is 0" << G4endl;
150 return;
151 }
152
153 // Fill the ntuple
154
155 G4int indexX = ntuple -> findColumn( "x" );
156 G4int indexY = ntuple -> findColumn( "y" );
157 G4int indexZ = ntuple -> findColumn( "z" );
158 G4int indexEnergy = ntuple -> findColumn( "energy" );
159
160 ntuple -> fill(indexEnergy, en);// method: fill ( int column, double value )
161 ntuple -> fill(indexX, xx);
162 ntuple -> fill(indexY, yy);
163 ntuple -> fill(indexZ, zz);
164
165 ntuple->addRow();
166#endif
167}
168
169void BrachyAnalysisManager::FillHistogramWithEnergy(G4double x,
170 G4double z,
171 G4double energyDeposit)
172{
173#ifdef G4ANALYSIS_USE
174 // 2DHistogram: energy deposit in a voxel which center is fixed in position (x,z)
175 h1 -> fill(x,z,energyDeposit);
176#endif
177}
178
179void BrachyAnalysisManager::PrimaryParticleEnergySpectrum(G4double primaryParticleEnergy)
180{
181#ifdef G4ANALYSIS_USE
182 // 1DHistogram: energy spectrum of primary particles
183 h2 -> fill(primaryParticleEnergy);
184#endif
185 return;
186}
187
188void BrachyAnalysisManager::DoseDistribution(G4double x,G4double energy)
189{
190#ifdef G4ANALYSIS_USE
191 // 1DHistogram: energy spectrum of primary particles
192 h3 -> fill(x, energy);
193#endif
194}
195
196void BrachyAnalysisManager::finish()
197{
198#ifdef G4ANALYSIS_USE
199 // write all histograms to file ...
200 theTree -> commit();
201
202 // close (will again commit) ...
203 theTree -> close();
204#endif
205}
206
207
208
209
210
211
212
213
214
215
216
217
Note: See TracBrowser for help on using the repository browser.