source: trunk/examples/extended/eventgenerator/exgps/src/exGPSAnalysisManager.cc@ 1036

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

update

File size: 6.8 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#ifdef G4ANALYSIS_USE
27
28#include <AIDA/AIDA.h>
29
30#include "exGPSAnalysisManager.hh"
31#include "exGPSAnalysisMessenger.hh"
32
33#include "G4UnitsTable.hh"
34
35exGPSAnalysisManager* exGPSAnalysisManager::instance = 0;
36//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
37
38exGPSAnalysisManager::exGPSAnalysisManager():
39fileName("exgps.aida"),fileType("xml"),analysisFactory(0), hFactory(0), tFactory(0),
40minpos(-10.),maxpos(10),mineng(0.),maxeng(1000.)
41{
42 // Define the messenger and the analysis system
43 analysisMessenger = new exGPSAnalysisMessenger(this);
44
45}
46
47//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
48
49exGPSAnalysisManager::~exGPSAnalysisManager() {
50
51 delete analysisMessenger;
52}
53
54//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
55
56
57IHistogramFactory* exGPSAnalysisManager::getHistogramFactory()
58{
59 return hFactory;
60}
61
62//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
63
64
65ITupleFactory* exGPSAnalysisManager::getTupleFactory()
66{
67 return tFactory;
68}
69
70//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
71
72IPlotter* exGPSAnalysisManager::createPlotter()
73{
74#ifdef JAIDA_HOME
75 if (analysisFactory)
76 {
77 IPlotterFactory* pf = analysisFactory->createPlotterFactory(0,0);
78 if (pf) return pf->create("Plotter");
79 }
80#endif
81 return 0;
82}
83
84
85////////////////////////////////////////////////////////////////////////////////
86//
87exGPSAnalysisManager* exGPSAnalysisManager::getInstance ()
88{
89 if (instance == 0) instance = new exGPSAnalysisManager();
90 return instance;
91}
92
93//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
94
95void exGPSAnalysisManager::dispose()
96{
97 if (instance != 0)
98 {
99 delete instance;
100 instance = 0;
101 }
102}
103
104//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
105
106void exGPSAnalysisManager::Fill(G4String pname, G4double e,
107 G4double x, G4double y, G4double z,
108 G4double t, G4double p, G4double w)
109{
110 enerHisto->fill(e/MeV,w);
111 posiXY->fill(x/cm,y/cm,w);
112 posiXZ->fill(x/cm,z/cm,w);
113 posiYZ->fill(y/cm,z/cm,w);
114 anglCTP->fill(p/deg,std::cos(t),w);
115 anglTP->fill(p/deg,t/deg,w);
116
117 if (plotter) plotter->refresh();
118
119 // Fill the tuple
120
121 if (tuple) {
122 tuple->fill(0,pname);
123 tuple->fill(1,e/MeV);
124 tuple->fill(2,x/cm);
125 tuple->fill(3,y/cm);
126 tuple->fill(4,z/cm);
127 tuple->fill(5,t/deg);
128 tuple->fill(6,p/deg);
129 tuple->fill(7,w);
130
131 tuple->addRow();
132 }
133}
134
135//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
136/*
137 This member reset the histograms and it is called at the begin
138 of each run; here we put the inizialization so that the histograms have
139 always the right dimensions depending from the detector geometry
140*/
141void exGPSAnalysisManager::BeginOfRun()
142{
143
144 // Hooking an AIDA compliant analysis system.
145 analysisFactory = AIDA_createAnalysisFactory();
146 if(analysisFactory){
147 ITreeFactory* treeFactory = analysisFactory->createTreeFactory();
148 tree = treeFactory->create(fileName,fileType,false,true,"compress=yes");
149 hFactory = analysisFactory->createHistogramFactory(*tree);
150 tFactory = analysisFactory->createTupleFactory(*tree);
151 delete treeFactory; // Will not delete the ITree.
152 }
153 //
154 enerHisto =0;
155 posiXY = posiXZ = posiYZ = anglCTP =anglTP = 0;
156 plotter = 0;
157 tuple = 0;
158 //
159 if (hFactory)
160 {
161 // Create the energy histogram
162 enerHisto = hFactory->createHistogram1D("Source Energy Spectrum",100,mineng,maxeng);
163
164 // Create some 2d histos
165 posiXY = hFactory->createHistogram2D("Source X-Y distribution",100,minpos/cm,maxpos/cm
166 ,100,minpos/cm,maxpos/cm);
167 posiXZ = hFactory->createHistogram2D("Source X-Z distribution",100,minpos/cm,maxpos/cm
168 ,100,minpos/cm,maxpos/cm);
169 posiYZ = hFactory->createHistogram2D("Source Y-Z distribution",100,minpos/cm,maxpos/cm
170 ,100,minpos/cm,maxpos/cm);
171 anglCTP = hFactory->createHistogram2D("Source phi-std::cos(theta) distribution",360,0,360
172 , 100, -1, 1);
173 anglTP = hFactory->createHistogram2D("Source phi-theta distribution",360,0,360
174 ,180,0,180);
175#ifdef JAIDA_HOME
176 plotter = createPlotter();
177
178 if (plotter)
179 {
180 plotter->createRegions(2,3);
181 plotter->region(0)->plot(*enerHisto);
182 plotter->region(1)->plot(*posiXY);
183 plotter->region(2)->plot(*posiXZ);
184 plotter->region(3)->plot(*posiYZ);
185 plotter->region(4)->plot(*anglCTP);
186 plotter->region(5)->plot(*anglTP);
187 plotter->show();
188 }
189#endif
190 }
191
192 // Create a Tuple
193
194 if (tFactory)
195 {
196 tuple = tFactory->create("MyTuple","MyTuple","std::string Pname, std::double Energy, X, Y, Z, Theta, Phi, Weight","");
197 }
198
199}
200
201//....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
202
203/*
204 This member is called at the end of each run
205*/
206void exGPSAnalysisManager::EndOfRun()
207{
208 if (analysisFactory)
209 {
210 if (!tree->commit()) G4cout << "Commit failed: no AIDA file produced!" << G4endl;
211 delete tree;
212 delete tFactory;
213 delete hFactory;
214 // G4cout << "Warning: Geant4 will NOT continue unless you close the JAS-AIDA window." << G4endl;
215 delete analysisFactory;
216 }
217 // dispose();
218}
219
220
221#endif // G4ANALYSIS_USE
222
223
224
225
226
227
228
229
230
231
Note: See TracBrowser for help on using the repository browser.