Geant4  10.01.p02
G4HnManager.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: G4HnManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
27 
28 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
29 
30 #include "G4HnManager.hh"
31 
32 //_____________________________________________________________________________
34  const G4AnalysisManagerState& state)
35  : G4BaseAnalysisManager(state),
36  fHnType(hnType),
37  fNofActiveObjects(0),
38  fNofAsciiObjects(0),
39  fHnVector()
40 {
41 }
42 
43 //_____________________________________________________________________________
45 {
46  std::vector<G4HnInformation*>::iterator it;
47  for (it = fHnVector.begin(); it != fHnVector.end(); it++ ) {
48  delete (*it);
49  }
50 }
51 
52 //
53 // public methods
54 //
55 
56 //_____________________________________________________________________________
58  const G4String& unitName,
59  const G4String& fcnName,
60  G4double unit, G4Fcn fcn,
61  G4BinScheme binScheme)
62 {
63  G4HnInformation* hnInformation = new G4HnInformation(name, 1);
64  hnInformation
66  G4HnDimensionInformation(unitName, fcnName, unit, fcn, binScheme));
67 
68  fHnVector.push_back(hnInformation);
70 }
71 
72 //_____________________________________________________________________________
74  const G4String& xunitName,
75  const G4String& yunitName,
76  const G4String& xfcnName,
77  const G4String& yfcnName,
78  G4double xunit, G4double yunit,
79  G4Fcn xfcn, G4Fcn yfcn,
80  G4BinScheme xbinScheme, G4BinScheme ybinScheme)
81 {
82  G4HnInformation* hnInformation = new G4HnInformation(name, 2);
83  hnInformation
85  G4HnDimensionInformation(xunitName, xfcnName, xunit, xfcn, xbinScheme));
86  hnInformation
88  G4HnDimensionInformation(yunitName, yfcnName, yunit, yfcn, ybinScheme));
89 
90  fHnVector.push_back(hnInformation);
92 }
93 
94 //_____________________________________________________________________________
96  const G4String& xunitName,
97  const G4String& yunitName,
98  const G4String& zunitName,
99  const G4String& xfcnName,
100  const G4String& yfcnName,
101  const G4String& zfcnName,
102  G4double xunit, G4double yunit, G4double zunit,
103  G4Fcn xfcn, G4Fcn yfcn, G4Fcn zfcn,
104  G4BinScheme xbinScheme, G4BinScheme ybinScheme,
105  G4BinScheme zbinScheme)
106 {
107  G4HnInformation* hnInformation = new G4HnInformation(name, 3);
108  hnInformation
110  G4HnDimensionInformation(xunitName, xfcnName, xunit, xfcn, xbinScheme));
111  hnInformation
113  G4HnDimensionInformation(yunitName, yfcnName, yunit, yfcn, ybinScheme));
114  hnInformation
116  G4HnDimensionInformation(zunitName, zfcnName, zunit, zfcn, zbinScheme));
117 
118  fHnVector.push_back(hnInformation);
120 }
121 
122 //_____________________________________________________________________________
124  G4String functionName, G4bool warn) const
125 {
126  G4int index = id - fFirstId;
127  if ( index < 0 || index >= G4int(fHnVector.size()) ) {
128  if ( warn ) {
129  G4String inFunction = "G4HnManager::";
130  if ( functionName.size() )
131  inFunction += functionName;
132  else
133  inFunction += "GetHnInformation";
134  G4ExceptionDescription description;
135  description << " " << fHnType << " histogram " << id
136  << " does not exist.";
137  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
138  }
139  return 0;
140  }
141  return fHnVector[index];
142 }
143 
144 //_____________________________________________________________________________
146  G4int dimension,
147  G4String functionName, G4bool warn) const
148 {
149  G4HnInformation* hnInformation = GetHnInformation(id, functionName, warn);
150  if ( ! hnInformation ) return 0;
151 
152  return hnInformation->GetHnDimensionInformation(dimension);
153 }
154 
155 //_____________________________________________________________________________
157 {
158  return ( fNofActiveObjects > 0 );
159 }
160 
161 //_____________________________________________________________________________
163 {
164  return ( fNofAsciiObjects > 0 );
165 }
166 
167 //_____________________________________________________________________________
169 {
170 // Set activation to a given object
171 
172  G4HnInformation* info = GetHnInformation(id, "SetActivation");
173 
174  if ( ! info ) return;
175 
176  // Do nothing if activation does not change
177  if ( info->GetActivation() == activation ) return;
178 
179  // Change activation and account it in fNofActiveObjects
180  info->SetActivation(activation);
181  if ( activation )
183  else
185 }
186 
187 //_____________________________________________________________________________
189 {
190 // Set activation to all objects of the given type
191 
192  std::vector<G4HnInformation*>::iterator it;
193  for ( it = fHnVector.begin(); it != fHnVector.end(); it++ ) {
194  G4HnInformation* info = *it;
195 
196  // Do nothing if activation does not change
197  if ( info->GetActivation() == activation ) continue;
198 
199  // Change activation and account it in fNofActiveObjects
200  info->SetActivation(activation);
201  if ( activation )
203  else
205  }
206 }
207 
208 //_____________________________________________________________________________
210 {
211  G4HnInformation* info = GetHnInformation(id, "SetAscii");
212 
213  if ( ! info ) return;
214 
215  // Do nothing if ascii does not change
216  if ( info->GetAscii() == ascii ) return;
217 
218  // Change ascii and account it in fNofAsciiObjects
219  info->SetAscii(ascii);
220  if ( ascii )
222  else
223  fNofAsciiObjects--;
224 }
225 
226 //_____________________________________________________________________________
228 {
229  G4HnInformation* info = GetHnInformation(id, "GetName");
230 
231  if ( ! info ) return "";
232 
233  return info->GetName();
234 }
235 
236 //_____________________________________________________________________________
238 {
241 
242  if ( ! info ) return 1.0;
243 
244  return info->fUnit;
245 }
246 
247 //_____________________________________________________________________________
249 {
252 
253  if ( ! info ) return 1.0;
254 
255  return info->fUnit;
256 }
257 
258 //_____________________________________________________________________________
260 {
263 
264  if ( ! info ) return 1.0;
265 
266  return info->fUnit;
267 }
268 
269 //_____________________________________________________________________________
271 {
272  G4HnInformation* info = GetHnInformation(id, "GetActivation");
273 
274  if ( ! info ) return true;
275 
276  return info->GetActivation();
277 }
278 
279 //_____________________________________________________________________________
281 {
282  G4HnInformation* info = GetHnInformation(id, "GetAscii");
283 
284  if ( ! info ) return false;
285 
286  return info->GetAscii();
287 }
G4bool IsAscii() const
Definition: G4HnManager.cc:162
G4bool GetAscii(G4int id) const
Definition: G4HnManager.cc:280
G4bool GetActivation() const
void SetActivation(G4bool activation)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
G4double GetZUnit(G4int id) const
Definition: G4HnManager.cc:259
G4String name
Definition: TRTMaterials.hh:40
void AddH1Information(const G4String &name, const G4String &unitName, const G4String &fcnName, G4double unit, G4Fcn fx, G4BinScheme binScheme)
Definition: G4HnManager.cc:57
G4double(* G4Fcn)(G4double)
Definition: G4Fcn.hh:36
void SetAscii(G4bool ascii)
void AddHnDimensionInformation(const G4HnDimensionInformation &hnDimensionInformation)
G4HnManager(const G4String &hnType, const G4AnalysisManagerState &state)
Definition: G4HnManager.cc:33
G4String fHnType
Definition: G4HnManager.hh:120
int G4int
Definition: G4Types.hh:78
G4HnInformation * GetHnInformation(G4int id, G4String functionName="", G4bool warn=true) const
Definition: G4HnManager.cc:123
G4bool GetActivation(G4int id) const
Definition: G4HnManager.cc:270
G4double GetXUnit(G4int id) const
Definition: G4HnManager.cc:237
bool G4bool
Definition: G4Types.hh:79
G4int fNofAsciiObjects
Definition: G4HnManager.hh:122
void SetAscii(G4int id, G4bool ascii)
Definition: G4HnManager.cc:209
G4String GetName(G4int id) const
Definition: G4HnManager.cc:227
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void AddH3Information(const G4String &name, const G4String &xunitName, const G4String &yunitName, const G4String &zunitName, const G4String &xfcnName, const G4String &yfcnName, const G4String &zfcnName, G4double xunit, G4double yunit, G4double zunit, G4Fcn fx, G4Fcn fy, G4Fcn fz, G4BinScheme xBinScheme, G4BinScheme yBinScheme, G4BinScheme zBinScheme)
Definition: G4HnManager.cc:95
G4HnDimensionInformation * GetHnDimensionInformation(G4int dimension)
G4bool GetAscii() const
G4String GetName() const
G4BinScheme
Definition: G4BinScheme.hh:40
std::vector< G4HnInformation * > fHnVector
Definition: G4HnManager.hh:125
void AddH2Information(const G4String &name, const G4String &xunitName, const G4String &yunitName, const G4String &xfcnName, const G4String &yfcnName, G4double xunit, G4double yunit, G4Fcn fx, G4Fcn fy, G4BinScheme xBinScheme, G4BinScheme yBinScheme)
Definition: G4HnManager.cc:73
double G4double
Definition: G4Types.hh:76
G4bool IsActive() const
Definition: G4HnManager.cc:156
virtual ~G4HnManager()
Definition: G4HnManager.cc:44
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:188
G4int fNofActiveObjects
Definition: G4HnManager.hh:121
G4double GetYUnit(G4int id) const
Definition: G4HnManager.cc:248
G4HnDimensionInformation * GetHnDimensionInformation(G4int id, G4int dimension, G4String functionName="", G4bool warn=true) const
Definition: G4HnManager.cc:145