Geant4  10.00.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  fHnVector.push_back(
64  new G4HnInformation(name, unitName, unitName, fcnName, fcnName,
65  unit, unit, fcn, fcn, binScheme, binScheme));
67 }
68 
69 //_____________________________________________________________________________
71  const G4String& xunitName,
72  const G4String& yunitName,
73  const G4String& xfcnName,
74  const G4String& yfcnName,
75  G4double xunit, G4double yunit,
76  G4Fcn xfcn, G4Fcn yfcn,
77  G4BinScheme xBinScheme, G4BinScheme yBinScheme)
78 {
79  fHnVector.push_back(
80  new G4HnInformation(name, xunitName, yunitName, xfcnName, yfcnName,
81  xunit, yunit, xfcn, yfcn, xBinScheme, yBinScheme));
83 }
84 
85 //_____________________________________________________________________________
87  G4String functionName, G4bool warn) const
88 {
89  G4int index = id - fFirstId;
90  if ( index < 0 || index >= G4int(fHnVector.size()) ) {
91  if ( warn ) {
92  G4String inFunction = "G4HnManager::";
93  if ( functionName.size() )
94  inFunction += functionName;
95  else
96  inFunction += "GetHnInformation";
97  G4ExceptionDescription description;
98  description << " " << fHnType << " histogram " << id
99  << " does not exist.";
100  G4Exception(inFunction, "Analysis_W007", JustWarning, description);
101  }
102  return 0;
103  }
104  return fHnVector[index];
105 }
106 
107 //_____________________________________________________________________________
109 {
110  return ( fNofActiveObjects > 0 );
111 }
112 
113 //_____________________________________________________________________________
115 {
116  return ( fNofAsciiObjects > 0 );
117 }
118 
119 //_____________________________________________________________________________
121 {
122 // Set activation to a given object
123 
124  G4HnInformation* info = GetHnInformation(id, "SetActivation");
125 
126  if ( ! info ) return;
127 
128  // Do nothing if activation does not change
129  if ( info->fActivation == activation ) return;
130 
131  // Change activation and account it in fNofActiveObjects
132  info->fActivation = activation;
133  if ( activation )
135  else
137 }
138 
139 //_____________________________________________________________________________
141 {
142 // Set activation to all objects of the given type
143 
144  std::vector<G4HnInformation*>::iterator it;
145  for ( it = fHnVector.begin(); it != fHnVector.end(); it++ ) {
146  G4HnInformation* info = *it;
147 
148  // Do nothing if activation does not change
149  if ( info->fActivation == activation ) continue;
150 
151  // Change activation and account it in fNofActiveObjects
152  info->fActivation = activation;
153  if ( activation )
155  else
157  }
158 }
159 
160 //_____________________________________________________________________________
162 {
163  G4HnInformation* info = GetHnInformation(id, "SetAscii");
164 
165  if ( ! info ) return;
166 
167  // Do nothing if ascii does not change
168  if ( info->fAscii == ascii ) return;
169 
170  // Change ascii and account it in fNofAsciiObjects
171  info->fAscii = ascii;
172  if ( ascii )
174  else
175  fNofAsciiObjects--;
176 }
177 
178 //_____________________________________________________________________________
180 {
181  G4HnInformation* info = GetHnInformation(id, "GetName");
182 
183  if ( ! info ) return "";
184 
185  return info->fName;
186 }
187 
188 //_____________________________________________________________________________
190 {
191  G4HnInformation* info = GetHnInformation(id, "GetXUnit");
192 
193  if ( ! info ) return 1.0;
194 
195  return info->fXUnit;
196 }
197 
198 //_____________________________________________________________________________
200 {
201  G4HnInformation* info = GetHnInformation(id, "GetYUnit");
202 
203  if ( ! info ) return 1.0;
204 
205  return info->fYUnit;
206 }
207 
208 //_____________________________________________________________________________
210 {
211  G4HnInformation* info = GetHnInformation(id, "GetActivation");
212 
213  if ( ! info ) return true;
214 
215  return info->fActivation;
216 }
217 
218 //_____________________________________________________________________________
220 {
221  G4HnInformation* info = GetHnInformation(id, "GetAscii");
222 
223  if ( ! info ) return false;
224 
225  return info->fAscii;
226 }
G4bool IsAscii() const
Definition: G4HnManager.cc:114
G4bool GetAscii(G4int id) const
Definition: G4HnManager.cc:219
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
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
G4HnManager(const G4String &hnType, const G4AnalysisManagerState &state)
Definition: G4HnManager.cc:33
G4String fHnType
Definition: G4HnManager.hh:103
int G4int
Definition: G4Types.hh:78
G4HnInformation * GetHnInformation(G4int id, G4String functionName="", G4bool warn=true) const
Definition: G4HnManager.cc:86
G4bool GetActivation(G4int id) const
Definition: G4HnManager.cc:209
G4double GetXUnit(G4int id) const
Definition: G4HnManager.cc:189
bool G4bool
Definition: G4Types.hh:79
G4int fNofAsciiObjects
Definition: G4HnManager.hh:105
void SetAscii(G4int id, G4bool ascii)
Definition: G4HnManager.cc:161
G4String GetName(G4int id) const
Definition: G4HnManager.cc:179
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
G4BinScheme
Definition: G4BinScheme.hh:40
std::vector< G4HnInformation * > fHnVector
Definition: G4HnManager.hh:108
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:70
double G4double
Definition: G4Types.hh:76
G4bool IsActive() const
Definition: G4HnManager.cc:108
virtual ~G4HnManager()
Definition: G4HnManager.cc:44
void SetActivation(G4bool activation)
Definition: G4HnManager.cc:140
G4int fNofActiveObjects
Definition: G4HnManager.hh:104
G4double GetYUnit(G4int id) const
Definition: G4HnManager.cc:199