Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
exGPSAnalysisManager.cc
Go to the documentation of this file.
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 //
28 //
29 #ifdef G4ANALYSIS_USE
30 #include <AIDA/AIDA.h>
31 #include "exGPSAnalysisManager.hh"
33 
34 #include "G4UnitsTable.hh"
35 #include "G4SystemOfUnits.hh"
36 
37 exGPSAnalysisManager* exGPSAnalysisManager::fInstance = 0;
38 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
39 
40 exGPSAnalysisManager::exGPSAnalysisManager():
41 fIleName("exgps.aida"),fIleType("xml"),fAnalysisFactory(0),
42 fTree(0),fPlotter(0),fMinpos(-10.),fMaxpos(10),fMineng(0.),fMaxeng(1000.),
43 fEnerHisto(0),fPosiXY(0),fPosiXZ(0),fPosiYZ(0),fAnglCTP(0),fAnglTP(0),fTuple(0)
44 {
45  // Define the messenger and the analysis system
46  fAnalysisMessenger = new exGPSAnalysisMessenger(this);
47 
48 }
49 
50 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
51 
52 exGPSAnalysisManager::~exGPSAnalysisManager() {
53  delete fAnalysisMessenger;
54 }
55 
56 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
57 
58 exGPSAnalysisManager* exGPSAnalysisManager::GetInstance ()
59 {
60  if (fInstance == 0) fInstance = new exGPSAnalysisManager();
61  return fInstance;
62 }
63 
64 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
65 
66 void exGPSAnalysisManager::Dispose()
67 {
68  if (fInstance != 0)
69  {
70  delete fInstance;
71  fInstance = 0;
72  }
73 }
74 
75 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
76 
80 {
81  if(fEnerHisto) {
82  fEnerHisto->fill(e/MeV,w);
83  fPosiXY->fill(x/cm,y/cm,w);
84  fPosiXZ->fill(x/cm,z/cm,w);
85  fPosiYZ->fill(y/cm,z/cm,w);
86  fAnglCTP->fill(p/deg,std::cos(t),w);
87  fAnglTP->fill(p/deg,t/deg,w);
88  }
89 
90  if (fPlotter) fPlotter->refresh();
91 
92  // Fill the fTuple
93 
94  if (fTuple) {
95  fTuple->fill(0,pname);
96  fTuple->fill(1,e/MeV);
97  fTuple->fill(2,x/cm);
98  fTuple->fill(3,y/cm);
99  fTuple->fill(4,z/cm);
100  fTuple->fill(5,t/deg);
101  fTuple->fill(6,p/deg);
102  fTuple->fill(7,w);
103  fTuple->addRow();
104  }
105 }
106 
107 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
108 /*
109  This member reset the histograms and it is called at the begin
110  of each run; here we put the initialization so that the histograms have
111  always the right dimensions depending from the detector geometry
112 */
113 void exGPSAnalysisManager::BeginOfRun()
114 {
115  fTree = 0;
116  fPlotter = 0;
117  fEnerHisto =0;
118  fPosiXY = fPosiXZ = fPosiYZ = fAnglCTP =fAnglTP = 0;
119  fTuple = 0;
120 
121  //Hooking an AIDA compliant analysis system.
122  fAnalysisFactory = AIDA_createAnalysisFactory();
123  if(!fAnalysisFactory) //Have to check that, it can fail.
124  {
125  G4cout << "exGPSAnalysisManager::BeginOfRun: can't get AIDA." << G4endl;
126  return;
127  }
128  AIDA::ITreeFactory* treeFactory = fAnalysisFactory->createTreeFactory();
129  if(treeFactory)
130  {
131  fTree = treeFactory->create(fIleName,fIleType,false,true,"compress=yes");
132  if(!fTree) //Have to check that, it can fail.
133  {
134  G4cout << "exGPSAnalysisManager::BeginOfRun:"
135  << " can't create the AIDA::ITree : " << fIleName << G4endl;
136  return;
137  }
138 
139  delete treeFactory; // Will not delete the ITree.
140  }
141 
142  AIDA::IHistogramFactory* hFactory =
143  fAnalysisFactory->createHistogramFactory(*fTree);
144  if (hFactory)
145  {
146  // Create the energy histogram
147  fEnerHisto = hFactory->createHistogram1D("Source Energy Spectrum",100,
148  fMineng,fMaxeng);
149 
150  // Create some 2d histos
151  fPosiXY = hFactory->createHistogram2D("Source X-Y distribution",100,
152  fMinpos/cm,fMaxpos/cm,100,fMinpos/cm,fMaxpos/cm);
153  fPosiXZ = hFactory->createHistogram2D("Source X-Z distribution",100,
154  fMinpos/cm,fMaxpos/cm,100,fMinpos/cm,fMaxpos/cm);
155  fPosiYZ = hFactory->createHistogram2D("Source Y-Z distribution",100,
156  fMinpos/cm,fMaxpos/cm,100,fMinpos/cm,fMaxpos/cm);
157  fAnglCTP = hFactory->createHistogram2D("Source phi-std::cos(theta) distribution",
158  360,0,360,100, -1, 1);
159  fAnglTP = hFactory->createHistogram2D("Source phi-theta distribution",
160  360,0,360,180,0,180);
161  delete hFactory;
162  }
163 
164  // Create a Tuple
165 
166  AIDA::ITupleFactory* tFactory = fAnalysisFactory->createTupleFactory(*fTree);
167  if (tFactory)
168  {
169  fTuple = tFactory->create("MyTuple","MyTuple",
170  "string Pname, double Energy, X, Y, Z, Theta, Phi, Weight","");
171  delete tFactory;
172  }
173 
174  AIDA::IPlotterFactory* pf = fAnalysisFactory->createPlotterFactory(0,0);
175  if(pf)
176  {
177  fPlotter = pf->create();
178  if (fPlotter)
179  {
180  fPlotter->createRegions(2,3);
181  if(fEnerHisto) fPlotter->region(0)->plot(*fEnerHisto);
182  if(fPosiXY) fPlotter->region(1)->plot(*fPosiXY);
183  if(fPosiXZ) fPlotter->region(2)->plot(*fPosiXZ);
184  if(fPosiYZ) fPlotter->region(3)->plot(*fPosiYZ);
185  if(fAnglCTP) fPlotter->region(4)->plot(*fAnglCTP);
186  if(fAnglTP) fPlotter->region(5)->plot(*fAnglTP);
187  fPlotter->show();
188  }
189  delete pf;
190  }
191 }
192 
193 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
194 
195 /*
196  This member is called at the end of each run
197 */
198 void exGPSAnalysisManager::EndOfRun()
199 {
200  if (fAnalysisFactory)
201  {
202  if (!fTree->commit()) G4cout << "Commit failed: no AIDA file produced!"
203  << G4endl;
204  delete fTree;
205  fTree = 0;
206 
207  delete fPlotter;
208  fPlotter = 0;
209 
210  delete fAnalysisFactory; //cleanup all AIDA related things.
211  fAnalysisFactory = 0;
212 
213  fEnerHisto = 0;
214  fPosiXY = fPosiXZ = fPosiYZ = fAnglCTP =fAnglTP = 0;
215  fTuple = 0;
216 
217  }
218 }
219 
220 
221 #endif // G4ANALYSIS_USE