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.22 2009/11/12 10:32:59 pandola Exp $ |
---|
36 | // GEANT4 tag $Name: geant4-09-04-beta-01 $ |
---|
37 | // |
---|
38 | #ifdef G4ANALYSIS_USE |
---|
39 | |
---|
40 | #include <stdlib.h> |
---|
41 | #include <fstream> |
---|
42 | #include "BrachyAnalysisManager.hh" |
---|
43 | |
---|
44 | #include "G4ios.hh" |
---|
45 | |
---|
46 | |
---|
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 | |
---|
57 | |
---|
58 | BrachyAnalysisManager* BrachyAnalysisManager::instance = 0; |
---|
59 | |
---|
60 | BrachyAnalysisManager::BrachyAnalysisManager() : |
---|
61 | aFact(0), theTree(0), histFact(0), tupFact(0), h1(0), |
---|
62 | h2(0), h3(0), ntuple(0) |
---|
63 | |
---|
64 | { |
---|
65 | |
---|
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 |
---|
73 | G4String fileName = "brachytherapy.root"; |
---|
74 | theTree = treeFact -> create(fileName,"ROOT",false, true); |
---|
75 | |
---|
76 | delete treeFact; |
---|
77 | } |
---|
78 | |
---|
79 | BrachyAnalysisManager::~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 | |
---|
94 | BrachyAnalysisManager* BrachyAnalysisManager::getInstance() |
---|
95 | { |
---|
96 | if (instance == 0) instance = new BrachyAnalysisManager; |
---|
97 | return instance; |
---|
98 | } |
---|
99 | |
---|
100 | void 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 |
---|
122 | std::string columnNames = "double energy, x , y , z "; |
---|
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 | |
---|
131 | void BrachyAnalysisManager::FillNtupleWithEnergy(G4double xx, |
---|
132 | G4double yy, |
---|
133 | G4double zz, |
---|
134 | G4double en) |
---|
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 | |
---|
157 | void 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 | |
---|
165 | void BrachyAnalysisManager::PrimaryParticleEnergySpectrum(G4double primaryParticleEnergy) |
---|
166 | { |
---|
167 | // 1DHistogram: energy spectrum of primary particles |
---|
168 | h2 -> fill(primaryParticleEnergy); |
---|
169 | return; |
---|
170 | } |
---|
171 | |
---|
172 | void BrachyAnalysisManager::DoseDistribution(G4double x,G4double energy) |
---|
173 | { |
---|
174 | // 1DHistogram: energy spectrum of primary particles |
---|
175 | h3 -> fill(x, energy); |
---|
176 | } |
---|
177 | |
---|
178 | void BrachyAnalysisManager::finish() |
---|
179 | { |
---|
180 | |
---|
181 | // write all histograms to file ... |
---|
182 | theTree -> commit(); |
---|
183 | |
---|
184 | // close (will again commit) ... |
---|
185 | theTree -> close(); |
---|
186 | } |
---|
187 | #endif |
---|
188 | |
---|
189 | |
---|
190 | |
---|
191 | |
---|
192 | |
---|
193 | |
---|
194 | |
---|
195 | |
---|
196 | |
---|
197 | |
---|
198 | |
---|