Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
PurgMagAnalysisManager.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 //
26 // Code developed by:
27 // S.Larsson
28 //
29 // ************************************
30 // * *
31 // * PurgMagAnalysisManager.cc *
32 // * *
33 // ************************************
34 //
35 // $Id$
36 //
37 #ifdef G4ANALYSIS_USE
38 #include <stdlib.h>
39 #include <fstream>
41 
42 #include "G4ios.hh"
43 
44 #include "AIDA/IHistogram1D.h"
45 #include "AIDA/IHistogram2D.h"
46 
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 
55 PurgMagAnalysisManager* PurgMagAnalysisManager::instance = 0;
56 
57 
58 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
59 
60 PurgMagAnalysisManager::PurgMagAnalysisManager() :
61  aFact(0), theTree(0), tupFact(0)
62 
63 
64 {
65  // Build the factories
66  aFact = AIDA_createAnalysisFactory();
67 
68  AIDA::ITreeFactory *treeFact = aFact->createTreeFactory();
69 
70 
71  // Parameters for the TreeFactory
72 
73  std::string fileName="purgmag.hbk";
74  theTree = treeFact->create(fileName,"hbook",false, true);
75 
76  delete treeFact;
77 
78  tupFact = aFact->createTupleFactory ( *theTree );
79 }
80 
81 
82 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
83 
84 PurgMagAnalysisManager::~PurgMagAnalysisManager()
85 {
86  delete tupFact;
87  tupFact=0;
88 
89  delete histFact;
90  histFact=0;
91 
92  delete theTree;
93  histFact=0;
94 
95  delete aFact;
96  aFact = 0;
97 }
98 
99 
100 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
101 
102 PurgMagAnalysisManager* PurgMagAnalysisManager::getInstance()
103 {
104  if (instance == 0) instance = new PurgMagAnalysisManager;
105  return instance;
106 }
107 
108 
109 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
110 
111 void PurgMagAnalysisManager::book()
112 {
113 
114  // N-tuple
115  std::string options = "";
116 
117  // Electrons
118  std::string columnNames1 = "double ex; double ey; double ez; double ee; double epx; double epy; double epz";
119  if (tupFact) ntuple1 = tupFact->create("1","1",columnNames1, options);
120  // check for non-zero ...
121  if (ntuple1) G4cout<<"N-tuple 1 is non-zero"<<G4endl;
122 
123  // Photons (gamma)
124  std::string columnNames2 = "double gx; double gy; double gz; double ge; double gpx; double gpy; double gpz";
125  if (tupFact) ntuple2 = tupFact->create("2","2",columnNames2, options);
126  // check for non-zero ...
127  if (ntuple2) G4cout<<"N-tuple 2 is non-zero"<<G4endl;
128 
129  // Positrons
130  std::string columnNames3 = "double px; double py; double pz; double pe; double ppx; double ppy; double ppz";
131  if (tupFact) ntuple3 = tupFact->create("3","3",columnNames3, options);
132  // check for non-zero ...
133  if (ntuple3) G4cout<<"N-tuple 3 is non-zero"<<G4endl;
134 
135  }
136 
137 
138 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
139 // This function fills a N-tuple with position, energy and momentum of
140 // electrons entering the measurement volume.
141 void PurgMagAnalysisManager::fill_Tuple_Electrons(G4double ex, G4double ey, G4double ez, // Position
142  G4double ee, // Energy
143  G4double epx, G4double epy, G4double epz) // Momentum
144 {
145 
146  if (ntuple1 == 0) {
147  G4cout << "N-tuple 1 is zero " << "\n";
148  return;
149  }
150 
151  int iex = ntuple1->findColumn( "ex" );
152  int iey = ntuple1->findColumn( "ey" );
153  int iez = ntuple1->findColumn( "ez" );
154  int iee = ntuple1->findColumn( "ee" );
155  int iepx = ntuple1->findColumn( "epx" );
156  int iepy = ntuple1->findColumn( "epy" );
157  int iepz = ntuple1->findColumn( "epz" );
158  ntuple1->fill(iex, ex); // fill ( int column, double value )
159  ntuple1->fill(iey, ey);
160  ntuple1->fill(iez, ez);
161  ntuple1->fill(iee, ee);
162  ntuple1->fill(iepx, epx);
163  ntuple1->fill(iepy, epy);
164  ntuple1->fill(iepz, epz);
165 
166  ntuple1->addRow();
167 
168 }
169 
170 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
171 // This function fills a N-tuple with position, energy and momentum of
172 // photons entering the measurement volume.
173 void PurgMagAnalysisManager::fill_Tuple_Gamma(G4double gx, G4double gy, G4double gz, // Position
174  G4double ge, // Energy
175  G4double gpx, G4double gpy, G4double gpz) // Momentum
176 {
177 
178  if (ntuple2 == 0) {
179  G4cout << "N-tuple 2 is zero" << "\n";
180  return;
181  }
182 
183  int igx = ntuple2->findColumn( "gx" );
184  int igy = ntuple2->findColumn( "gy" );
185  int igz = ntuple2->findColumn( "gz" );
186  int ige = ntuple2->findColumn( "ge" );
187  int igpx = ntuple2->findColumn( "gpx" );
188  int igpy = ntuple2->findColumn( "gpy" );
189  int igpz = ntuple2->findColumn( "gpz" );
190  ntuple2->fill(igx, gx); // fill ( int column, double value )
191  ntuple2->fill(igy, gy);
192  ntuple2->fill(igz, gz);
193  ntuple2->fill(ige, ge);
194  ntuple2->fill(igpx, gpx);
195  ntuple2->fill(igpy, gpy);
196  ntuple2->fill(igpz, gpz);
197 
198  ntuple2->addRow();
199 
200 }
201 
202 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
203 // This function fills a N-tuple with position, energy and momentum of
204 // positrons entering the measurement volume.
205 void PurgMagAnalysisManager::fill_Tuple_Positrons(G4double px, G4double py, G4double pz, // Position
206  G4double pe, // Energy
207  G4double ppx, G4double ppy, G4double ppz) // Momentum
208 {
209 
210  if (ntuple3 == 0) {
211  G4cout << "N-tuple 3 is zero" << "\n";
212  return;
213  }
214 
215  int ipx = ntuple3->findColumn( "px" );
216  int ipy = ntuple3->findColumn( "py" );
217  int ipz = ntuple3->findColumn( "pz" );
218  int ipe = ntuple3->findColumn( "pe" );
219  int ippx = ntuple3->findColumn( "ppx" );
220  int ippy = ntuple3->findColumn( "ppy" );
221  int ippz = ntuple3->findColumn( "ppz" );
222  ntuple3->fill(ipx, px); // fill ( int column, double value )
223  ntuple3->fill(ipy, py);
224  ntuple3->fill(ipz, pz);
225  ntuple3->fill(ipe, pe);
226  ntuple3->fill(ippx, ppx);
227  ntuple3->fill(ippy, ppy);
228  ntuple3->fill(ippz, ppz);
229 
230  ntuple3->addRow();
231 
232 }
233 
234 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
235 void PurgMagAnalysisManager::finish()
236 {
237  // Writes all histograms to file
238  theTree->commit();
239 
240  // Close (will again commit)
241  theTree->close();
242 }
243 #endif
244