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

Last change on this file since 1285 was 1230, checked in by garnier, 16 years ago

update to geant4.9.3

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