ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4HnManager.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4HnManager.cc
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 
27 // Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
28 
29 #include "G4HnManager.hh"
30 #include "G4AnalysisUtilities.hh"
31 
32 using namespace G4Analysis;
33 
34 //_____________________________________________________________________________
36  const G4AnalysisManagerState& state)
37  : G4BaseAnalysisManager(state),
38  fHnType(hnType),
39  fNofActiveObjects(0),
40  fNofAsciiObjects(0),
41  fNofPlottingObjects(0),
42  fHnVector()
43 {
44 }
45 
46 //_____________________________________________________________________________
48 {
49  for ( auto hnInformation : fHnVector ) {
50  delete hnInformation;
51  }
52 }
53 
54 //
55 // public methods
56 //
57 
58 //_____________________________________________________________________________
60 {
61  auto hnInformation = new G4HnInformation(name, nofDimensions);
62  fHnVector.push_back(hnInformation);
64 
65  return hnInformation;
66 }
67 
68 //_____________________________________________________________________________
70  G4String functionName, G4bool warn) const
71 {
72  G4int index = id - fFirstId;
73  if ( index < 0 || index >= G4int(fHnVector.size()) ) {
74  if ( warn ) {
75  G4String inFunction = "G4HnManager::";
76  if ( functionName.size() )
77  inFunction += functionName;
78  else
79  inFunction += "GetHnInformation";
80  G4ExceptionDescription description;
81  description << " " << fHnType << " histogram " << id
82  << " does not exist.";
83  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
84  }
85  return nullptr;
86  }
87  return fHnVector[index];
88 }
89 
90 //_____________________________________________________________________________
92  G4int dimension,
93  G4String functionName, G4bool warn) const
94 {
95  auto hnInformation = GetHnInformation(id, functionName, warn);
96  if ( ! hnInformation ) return nullptr;
97 
98  return hnInformation->GetHnDimensionInformation(dimension);
99 }
100 
101 //_____________________________________________________________________________
103 {
104  return ( fNofActiveObjects > 0 );
105 }
106 
107 //_____________________________________________________________________________
109 {
110  return ( fNofAsciiObjects > 0 );
111 }
112 
113 //_____________________________________________________________________________
115 {
116  return ( fNofPlottingObjects > 0 );
117 }
118 
119 //_____________________________________________________________________________
121 {
122 // Set activation to a given object
123 
124  auto info = GetHnInformation(id, "SetActivation");
125 
126  if ( ! info ) return;
127 
128  // Do nothing if activation does not change
129  if ( info->GetActivation() == activation ) return;
130 
131  // Change activation and account it in fNofActiveObjects
132  info->SetActivation(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  for ( auto info : fHnVector ) {
149 
150  // Do nothing if activation does not change
151  if ( info->GetActivation() == activation ) continue;
152 
153  // Change activation and account it in fNofActiveObjects
154  info->SetActivation(activation);
155  if ( activation )
157  else
159  }
160 }
161 
162 //_____________________________________________________________________________
164 {
165  auto info = GetHnInformation(id, "SetAscii");
166 
167  if ( ! info ) return;
168 
169  // Do nothing if ascii does not change
170  if ( info->GetAscii() == ascii ) return;
171 
172  // Change ascii and account it in fNofAsciiObjects
173  info->SetAscii(ascii);
174  if ( ascii )
176  else
177  fNofAsciiObjects--;
178 }
179 
180 //_____________________________________________________________________________
182 {
183  auto info = GetHnInformation(id, "SetPlotting");
184 
185  if ( ! info ) return;
186 
187  // Do nothing if ascii does not change
188  if ( info->GetPlotting() == plotting ) return;
189 
190  // Change Plotting and account it in fNofPlottingObjects
191  info->SetPlotting(plotting);
192  if ( plotting )
194  else
196 }
197 
198 //_____________________________________________________________________________
200 {
201 // Set plotting to all objects of the given type
202 
203  for ( auto info : fHnVector ) {
204 
205  // Do nothing if plotting does not change
206  if ( info->GetPlotting() == plotting ) continue;
207 
208  // Change plotting and account it in fNofActiveObjects
209  info->SetPlotting(plotting);
210  if ( plotting )
212  else
214  }
215 }
216 
217 //_____________________________________________________________________________
219 {
220  auto info = GetHnInformation(id, "SetXAxisIsLog");
221 
222  if ( ! info ) return false;
223 
224  info->SetIsLogAxis(kX, isLog);
225  return true;
226 }
227 
228 //_____________________________________________________________________________
230 {
231  auto info = GetHnInformation(id, "SetYAxisIsLog");
232 
233  if ( ! info ) return false;
234 
235  info->SetIsLogAxis(kY, isLog);
236  return true;
237 }
238 
239 //_____________________________________________________________________________
241 {
242  auto info = GetHnInformation(id, "SetZAxisIsLog");
243 
244  if ( ! info ) return false;
245 
246  info->SetIsLogAxis(kZ, isLog);
247  return true;
248 }
249 
250 //_____________________________________________________________________________
252 {
253  auto info = GetHnInformation(id, "GetName");
254 
255  if ( ! info ) return "";
256 
257  return info->GetName();
258 }
259 
260 //_____________________________________________________________________________
262 {
263  auto info = GetHnDimensionInformation(id, kX, "GetXUnit");
264 
265  if ( ! info ) return 1.0;
266 
267  return info->fUnit;
268 }
269 
270 //_____________________________________________________________________________
272 {
273  auto info = GetHnDimensionInformation(id, kY, "GetYUnit");
274 
275  if ( ! info ) return 1.0;
276 
277  return info->fUnit;
278 }
279 
280 //_____________________________________________________________________________
282 {
283  auto info = GetHnDimensionInformation(id, kZ, "GetZUnit");
284 
285  if ( ! info ) return 1.0;
286 
287  return info->fUnit;
288 }
289 
290 //_____________________________________________________________________________
292 {
293  auto info = GetHnInformation(id, "GetXAxisIsLog");
294 
295  if ( ! info ) return false;
296 
297  return info->GetIsLogAxis(kX);
298 }
299 
300 //_____________________________________________________________________________
302 {
303  auto info = GetHnInformation(id, "GetYAxisIsLog");
304 
305  if ( ! info ) return 1.0;
306 
307  return info->GetIsLogAxis(kY);
308 }
309 
310 //_____________________________________________________________________________
312 {
313  auto info = GetHnInformation(id, "GetZAxisIsLog");
314 
315  if ( ! info ) return 1.0;
316 
317  return info->GetIsLogAxis(kZ);
318 }
319 
320 //_____________________________________________________________________________
322 {
323  auto info = GetHnInformation(id, "GetActivation");
324 
325  if ( ! info ) return true;
326 
327  return info->GetActivation();
328 }
329 
330 //_____________________________________________________________________________
332 {
333  auto info = GetHnInformation(id, "GetAscii");
334 
335  if ( ! info ) return false;
336 
337  return info->GetAscii();
338 }
339 
340 //_____________________________________________________________________________
342 {
343  auto info = GetHnInformation(id, "GetPlotting");
344 
345  if ( ! info ) return false;
346 
347  return info->GetPlotting();
348 }