source: trunk/examples/advanced/purging_magnet/src/PurgMagAnalysisManager.cc @ 1321

Last change on this file since 1321 was 1230, checked in by garnier, 14 years ago

update to geant4.9.3

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