Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MicrobeamHistoManager.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 "MicrobeamHistoManager.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 << " MicrobeamHistoManager::MicrobeamHistoManager() :"
47  << " problem creating the AIDA analysis factory."
48  << G4endl;
49  }
50 #endif
51 
52  fileName[0] = "microbeam";
53  fileType = "root";
54  fileOption = "";
55  ntupl0=0;
56  ntupl1=0;
57  ntupl2=0;
58  ntupl3=0;
59  ntupl4=0;
60 
61 }
62 
63 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
64 
66 {
67 #ifdef G4ANALYSIS_USE
68  delete af;
69 #endif
70 }
71 
72 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
73 
75 {
76 #ifdef G4ANALYSIS_USE
77  if(!af) return;
78 
79  // Creating a tree mapped to an hbook file.
80  fileName[1] = fileName[0] + "." + fileType;
81  G4bool readOnly = false;
82  G4bool createNew = true;
83  AIDA::ITreeFactory* tf = af->createTreeFactory();
84  tree = tf->create(fileName[1], fileType, readOnly, createNew, fileOption);
85  delete tf;
86  if(!tree) {
87  G4cout << "MicrobeamHistoManager::book() :"
88  << " problem creating the AIDA tree with "
89  << " storeName = " << fileName[1]
90  << " storeType = " << fileType
91  << " readOnly = " << readOnly
92  << " createNew = " << createNew
93  << " options = " << fileOption
94  << G4endl;
95  return;
96  }
97 
98  // Creating a histogram & ntuplr factory
99  AIDA::IHistogramFactory* hf = af->createHistogramFactory(*tree);
100  AIDA::ITupleFactory* ntf = af->createTupleFactory(*tree);
101 
102  ntupl0 = ntf->create( "ntuple0", "Stopping power", "double e, sp");
103  ntupl1 = ntf->create( "ntuple1", "Beam position", "double x, y");
104  ntupl2 = ntf->create( "ntuple2", "Range", "double x, y, z");
105  ntupl3 = ntf->create( "ntuple3", "Doses", "double doseN, doseC");
106  ntupl4 = ntf->create( "ntuple4", "3D", "double x, y, z, doseV");
107  factoryOn = true;
108 
109  delete hf;
110  delete ntf;
111 
112  if (factoryOn)
113  G4cout << "\n----> Histogram Tree is opened in " << fileName[1] << G4endl;
114 #endif
115 }
116 
117 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
118 
120 {
121 #ifdef G4ANALYSIS_USE
122  if (factoryOn) {
123 
124  tree->commit(); // Writing the histograms to the file
125  tree->close(); // and closing the tree (and the file)
126  G4cout << "\n----> Histogram Tree is saved in " << fileName[1] << G4endl;
127 
128  delete tree;
129  tree = 0;
130  factoryOn = false;
131  }
132 #endif
133 }
134 
135 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
136 
138 {
139  if (nt >= MaxNtupl) {
140  G4cout << "---> warning from MicrobeamHistoManager::FillNtuple() : Ntuple " << nt
141  << " does not exist " << column << value << G4endl;
142  return;
143  }
144 #ifdef G4ANALYSIS_USE
145  if(nt==0) ntupl0->fill(column, value);
146  if(nt==1) ntupl1->fill(column, value);
147  if(nt==2) ntupl2->fill(column, value);
148  if(nt==3) ntupl3->fill(column, value);
149  if(nt==4) ntupl4->fill(column, value);
150 #endif
151 }
152 
153 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
154 
156 {
157  if (nt >= MaxNtupl) {
158  G4cout << "---> warning from MicrobeamHistoManager::AddRowNtuple() : Ntuple " << nt
159  << " do not exist" << G4endl;
160  return;
161  }
162 #ifdef G4ANALYSIS_USE
163  if(nt==0) ntupl0->addRow();
164  if(nt==1) ntupl1->addRow();
165  if(nt==2) ntupl2->addRow();
166  if(nt==3) ntupl3->addRow();
167  if(nt==4) ntupl4->addRow();
168 #endif
169 }
170 
171 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......