Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
HistoManager.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 // $Id$
27 //
28 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
29 
30 #include "HistoManager.hh"
31 #include "G4UnitsTable.hh"
32 
33 #ifdef G4ANALYSIS_USE
34 #include "AIDA/AIDA.h"
35 #endif
36 
37 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
38 
40 :af(0),tree(0),factoryOn(false)
41 {
42 #ifdef G4ANALYSIS_USE
43  // Creating the analysis factory
44  af = AIDA_createAnalysisFactory();
45  if(!af) {
46  G4cout << " HistoManager::HistoManager() :"
47  << " problem creating the AIDA analysis factory."
48  << G4endl;
49  }
50 #endif
51 
52  fileName[0] = "nanobeam";
53  fileType = "root";
54  fileOption = "";
55  ntupl0=0;
56  ntupl1=0;
57 
58 }
59 
60 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
61 
63 {
64 #ifdef G4ANALYSIS_USE
65  delete af;
66 #endif
67 }
68 
69 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
70 
71 void HistoManager::book()
72 {
73 #ifdef G4ANALYSIS_USE
74  if(!af) return;
75 
76  // Creating a tree mapped to an hbook file.
77  fileName[1] = fileName[0] + "." + fileType;
78  G4bool readOnly = false;
79  G4bool createNew = true;
80  AIDA::ITreeFactory* tf = af->createTreeFactory();
81  tree = tf->create(fileName[1], fileType, readOnly, createNew, fileOption);
82  delete tf;
83  if(!tree) {
84  G4cout << "HistoManager::book() :"
85  << " problem creating the AIDA tree with "
86  << " storeName = " << fileName[1]
87  << " storeType = " << fileType
88  << " readOnly = " << readOnly
89  << " createNew = " << createNew
90  << " options = " << fileOption
91  << G4endl;
92  return;
93  }
94 
95  // Creating a histogram & ntuplr factory
96  AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree);
97  AIDA::ITupleFactory* ntf = af->createTupleFactory(*tree);
98 
99  ntupl0 = ntf->create( "ntuple0", "Beam profile", "double xIn, yIn, zIn");
100  ntupl1 = ntf->create( "ntuple1", "Grid", "double xIn, yIn, e");
101  ntupl2 = ntf->create( "ntuple2", "Coef", "double xIn, yIn, thetaIn, phiIn");
102  factoryOn = true;
103 
104  delete hf;
105  delete ntf;
106 
107  if (factoryOn)
108  G4cout << "\n----> Histogram Tree is opened in " << fileName[1] << G4endl;
109 #endif
110 }
111 
112 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
113 
114 void HistoManager::save()
115 {
116 #ifdef G4ANALYSIS_USE
117  if (factoryOn) {
118 
119  tree->commit(); // Writing the histograms to the file
120  tree->close(); // and closing the tree (and the file)
121  G4cout << "\n----> Histogram Tree is saved in " << fileName[1] << G4endl;
122 
123  delete tree;
124  tree = 0;
125  factoryOn = false;
126  }
127 #endif
128 }
129 
130 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
131 
133 {
134  if (nt >= MaxNtupl) {
135  G4cout << "---> warning from HistoManager::FillNtuple() : Ntuple " << nt
136  << " does not exist " << column << value << G4endl;
137  return;
138  }
139 #ifdef G4ANALYSIS_USE
140  if(nt==0) ntupl0->fill(column, value);
141  if(nt==1) ntupl1->fill(column, value);
142  if(nt==2) ntupl2->fill(column, value);
143 #endif
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
147 
149 {
150  if (nt >= MaxNtupl) {
151  G4cout << "---> warning from HistoManager::AddRowNtuple() : Ntuple " << nt
152  << " do not exist" << G4endl;
153  return;
154  }
155 #ifdef G4ANALYSIS_USE
156  if(nt==0) ntupl0->addRow();
157  if(nt==1) ntupl1->addRow();
158  if(nt==2) ntupl2->addRow();
159 #endif
160 }
161 
162 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......