Geant4  10.01.p02
ExG4HbookP1Manager.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 //
30 
31 // Author: Ivana Hrivnacova, 03/11/2014 (ivana@ipno.in2p3.fr)
32 
33 #ifdef G4_USE_HBOOK
34 
35 #include "ExG4HbookP1Manager.hh"
36 #include "ExG4HbookFileManager.hh"
37 #include "G4HnManager.hh"
39 #include "G4AnalysisUtilities.hh"
40 #include "G4BinScheme.hh"
41 
42 #include <fstream>
43 
44 using namespace G4Analysis;
45 
46 //_____________________________________________________________________________
47 ExG4HbookP1Manager::ExG4HbookP1Manager(const G4AnalysisManagerState& state)
48  : G4VP1Manager(state),
49  fBaseToolsManager("P1"),
50  fFileManager(0),
51  fP1HbookIdOffset(-1),
52  fP1Vector(),
53  fP1BookingVector(),
54  fP1NameIdMap()
55 {
56 }
57 
58 //_____________________________________________________________________________
59 ExG4HbookP1Manager::~ExG4HbookP1Manager()
60 {
61  // Delete p1
62  Reset();
63 
64  // Delete p1 booking
65  std::vector<p1_booking*>::iterator it;
66  for ( it = fP1BookingVector.begin(); it != fP1BookingVector.end(); it++ ) {
67  delete *it;
68  }
69 }
70 
71 //
72 // utility functions
73 //
74 
75 namespace {
76 
77 //_____________________________________________________________________________
78 void ConvertToFloat(const std::vector<G4double>& doubleVector,
79  std::vector<float>& floatVector)
80 {
81  for (G4int i=0; i<G4int(doubleVector.size()); ++i)
82  floatVector.push_back((float)doubleVector[i]);
83 }
84 
85 //_____________________________________________________________________________
86 void UpdateP1Information(G4HnInformation* hnInformation,
87  const G4String& xunitName,
88  const G4String& yunitName,
89  const G4String& xfcnName,
90  const G4String& yfcnName,
91  G4BinScheme xbinScheme)
92 {
93  G4double xunit = GetUnitValue(xunitName);
94  G4double yunit = GetUnitValue(yunitName);
95  G4Fcn xfcn = GetFunction(xfcnName);
96  G4Fcn yfcn = GetFunction(yfcnName);
97 
98  G4HnDimensionInformation* xInformation
100  xInformation->fUnitName = xunitName;
101  xInformation->fFcnName = xfcnName;
102  xInformation->fUnit = xunit;
103  xInformation->fFcn = xfcn;
104  xInformation->fBinScheme = xbinScheme;
105 
106  G4HnDimensionInformation* yInformation
108  yInformation->fUnitName = yunitName;
109  yInformation->fFcnName = yfcnName;
110  yInformation->fUnit = yunit;
111  yInformation->fFcn = yfcn;
112  yInformation->fBinScheme = kLinearBinScheme;
113 }
114 
115 //_____________________________________________________________________________
116 p1_booking* CreateP1Booking(const G4String& title,
117  G4int nbins, G4double xmin, G4double xmax,
118  G4double ymin, G4double ymax,
119  const G4String& xunitName,
120  const G4String& yunitName,
121  const G4String& xfcnName,
122  const G4String& yfcnName,
123  G4BinScheme xbinScheme)
124 {
125  G4double xunit = GetUnitValue(xunitName);
126  G4double yunit = GetUnitValue(yunitName);
127  G4Fcn xfcn = GetFunction(xfcnName);
128  G4Fcn yfcn = GetFunction(yfcnName);
129 
130  p1_booking* p1Booking = 0;
131  if ( xbinScheme != kLogBinScheme ) {
132  if ( xbinScheme == kUserBinScheme ) {
133  // This should never happen, but let's make sure about it
134  // by issuing a warning
135  G4ExceptionDescription description;
136  description
137  << " User binning scheme setting was ignored." << G4endl
138  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
139  G4Exception("ExG4HbookP1Manager::CreateP1",
140  "Analysis_W013", JustWarning, description);
141  }
142  p1Booking = new p1_booking(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
143  yfcn(ymin/yunit), yfcn(ymax/yunit));
144  // p1_booking object is deleted in destructor
145  }
146  else {
147  // Compute edges
148  std::vector<G4double> edges;
149  ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, edges);
150  p1Booking = new p1_booking(edges, yfcn(ymin/yunit), yfcn(ymax/yunit));
151  // p1_booking object is deleted in destructor
152  }
153 
154  p1Booking->fTitle = title;
155  UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
156 
157  return p1Booking;
158 }
159 
160 //_____________________________________________________________________________
161 p1_booking* CreateP1Booking(const G4String& title,
162  const std::vector<G4double>& edges,
163  G4double ymin, G4double ymax,
164  const G4String& xunitName,
165  const G4String& yunitName,
166  const G4String& xfcnName,
167  const G4String& yfcnName)
168 {
169  G4double xunit = GetUnitValue(xunitName);
170  G4double yunit = GetUnitValue(yunitName);
171  G4Fcn xfcn = GetFunction(xfcnName);
172  G4Fcn yfcn = GetFunction(yfcnName);
173 
174  // Apply function
175  std::vector<G4double> newEdges;
176  ComputeEdges(edges, xunit, xfcn, newEdges);
177 
178  p1_booking* p1Booking = new p1_booking(newEdges, yfcn(ymin/yunit), yfcn(ymax/yunit));
179  // p1_booking object is deleted in destructor
180 
181  p1Booking->fTitle = title;
182  UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
183 
184  return p1Booking;
185 }
186 
187 //_____________________________________________________________________________
188 void UpdateP1Booking(p1_booking* p1Booking,
189  G4int nbins, G4double xmin, G4double xmax,
190  G4double ymin, G4double ymax,
191  const G4String& xunitName,
192  const G4String& yunitName,
193  const G4String& xfcnName,
194  const G4String& yfcnName,
195  const G4String& xbinSchemeName)
196 {
197  G4double xunit = GetUnitValue(xunitName);
198  G4double yunit = GetUnitValue(yunitName);
199  G4Fcn xfcn = GetFunction(xfcnName);
200  G4Fcn yfcn = GetFunction(yfcnName);
201  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
202 
203  if ( xbinScheme != kLogBinScheme ) {
204  if ( xbinScheme == kUserBinScheme ) {
205  // This should never happen, but let's make sure about it
206  // by issuing a warning
207  G4ExceptionDescription description;
208  description
209  << " User binning scheme setting was ignored." << G4endl
210  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
211  G4Exception("ExG4HbookP1Manager::SetP1",
212  "Analysis_W013", JustWarning, description);
213  }
214  p1Booking->fNbins = nbins;
215  p1Booking->fXmin = xfcn(xmin/xunit);
216  p1Booking->fXmax = xfcn(xmax/xunit);
217  p1Booking->fYmin = yfcn(ymin/yunit);
218  p1Booking->fYmax = yfcn(ymax/yunit);
219  }
220  else {
221  // Compute edges
222  ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, p1Booking->fEdges);
223  p1Booking->fYmin = yfcn(ymin/yunit);
224  p1Booking->fYmax = yfcn(ymax/yunit);
225  }
226 
227  UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
228 }
229 
230 //_____________________________________________________________________________
231 void UpdateP1Booking(p1_booking* p1Booking,
232  const std::vector<G4double>& edges,
233  G4double ymin, G4double ymax,
234  const G4String& xunitName,
235  const G4String& yunitName,
236  const G4String& xfcnName,
237  const G4String& yfcnName)
238 {
239  G4double xunit = GetUnitValue(xunitName);
240  G4double yunit = GetUnitValue(yunitName);
241  G4Fcn xfcn = GetFunction(xfcnName);
242  G4Fcn yfcn = GetFunction(yfcnName);
243 
244  // Apply function
245  ComputeEdges(edges, xunit, xfcn, p1Booking->fEdges);
246  p1Booking->fYmin = yfcn(ymin/yunit);
247  p1Booking->fYmax = yfcn(ymax/yunit);
248 
249  UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
250 }
251 
252 //_____________________________________________________________________________
253 void ConfigureHbookP1(tools::hbook::p1* p1,
254  G4int nbins, G4double xmin, G4double xmax,
255  G4double ymin, G4double ymax,
256  const G4String& xunitName,
257  const G4String& yunitName,
258  const G4String& xfcnName,
259  const G4String& yfcnName,
260  G4BinScheme xbinScheme)
261 {
262  G4double xunit = GetUnitValue(xunitName);
263  G4double yunit = GetUnitValue(yunitName);
264  G4Fcn xfcn = GetFunction(xfcnName);
265  G4Fcn yfcn = GetFunction(yfcnName);
266 
267  if ( xbinScheme != kLogBinScheme ) {
268  if ( xbinScheme == kUserBinScheme ) {
269  // This should never happen, but let's make sure about it
270  // by issuing a warning
271  G4ExceptionDescription description;
272  description
273  << " User binning scheme setting was ignored." << G4endl
274  << " Linear binning will be applied with given (nbins, xmin, xmax) values";
275  G4Exception("ExG4HbookP1Manager::SetP1",
276  "Analysis_W013", JustWarning, description);
277  }
278  // not available !!
279  p1->configure(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
280  yfcn(ymin/yunit), yfcn(ymax/yunit));
281  }
282  else {
283  // Compute bins
284  std::vector<G4double> edges;
285  ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, edges);
286  // Convert to float
287  std::vector<float> fedges;
288  ConvertToFloat(edges, fedges);
289 
290  // not available !!
291  //p1->configure(edges, yfcn(ymin/yunit), yfcn(ymax/yunit));
292  }
293 }
294 
295 //_____________________________________________________________________________
296 void ConfigureHbookP1(tools::hbook::p1* /*p1*/,
297  const std::vector<G4double>& edges,
298  G4double /*ymin*/, G4double /*ymax*/,
299  const G4String& xunitName,
300  const G4String& /*yunitName*/,
301  const G4String& xfcnName,
302  const G4String& /*yfcnName*/)
303 {
304  // Apply function to edges
305  G4double xunit = GetUnitValue(xunitName);
306  //G4double yunit = GetUnitValue(yunitName);
307  G4Fcn xfcn = GetFunction(xfcnName);
308  //G4Fcn yfcn = GetFunction(yfcnName);
309  std::vector<G4double> newEdges;
310  ComputeEdges(edges, xunit, xfcn, newEdges);
311 
312  // Convert to float
313  std::vector<float> newFEdges;
314  ConvertToFloat(newEdges, newFEdges);
315 
316  // not available !!
317  //p1->configure(newFEdges);
318 }
319 
320 }
321 
322 //
323 // private methods
324 //
325 
326 //_____________________________________________________________________________
327 void ExG4HbookP1Manager::SetP1HbookIdOffset()
328 {
329 // Set fP1HbookIdOffset if needed
330 
331  if ( fP1HbookIdOffset == -1 ) {
332  if ( fFirstId > 0 )
333  fP1HbookIdOffset = 0;
334  else
335  fP1HbookIdOffset = 1;
336 
337  if ( fP1HbookIdOffset > 0 ) {
338  G4ExceptionDescription description;
339  description << "P1 will be defined in HBOOK with ID = G4_firstProfileId + 1";
340  G4Exception("ExG4HbookP1Manager::SetP1HbookIdOffset()",
341  "Analysis_W013", JustWarning, description);
342  }
343  }
344 }
345 
346 //_____________________________________________________________________________
347 void ExG4HbookP1Manager::AddP1Information(const G4String& name,
348  const G4String& xunitName,
349  const G4String& yunitName,
350  const G4String& xfcnName,
351  const G4String& yfcnName,
352  G4BinScheme xbinScheme) const
353 {
354  G4double xunit = GetUnitValue(xunitName);
355  G4double yunit = GetUnitValue(yunitName);
356  G4Fcn xfcn = GetFunction(xfcnName);
357  G4Fcn yfcn = GetFunction(yfcnName);
358  fHnManager
359  ->AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
360  xunit, yunit, xfcn, yfcn,
361  xbinScheme, xbinScheme);
362 }
363 
364 //_____________________________________________________________________________
365 G4int ExG4HbookP1Manager::CreateP1FromBooking(p1_booking* p1Booking,
366  G4bool chDir)
367 {
368 // Create p1 from p1_booking.
369 
370  if ( chDir ) {
371  // Go to profiles directory if defined
372  if ( fFileManager->GetProfileDirectoryName() != "" ) {
373  G4String profilePath = "//PAWC/LUN1/";
374  profilePath.append(fFileManager->GetProfileDirectoryName().data());
375  tools::hbook::CHCDIR(profilePath.data()," ");
376  }
377  }
378 
379  G4int index = fP1Vector.size();
380  G4int id = index + fFirstId;
382  info = fHnManager->GetHnInformation(id, "CreateP1FromBooking");
383  // Hbook index
384  G4int hbookIndex = fP1HbookIdOffset + index + fFirstId;
385 
386 #ifdef G4VERBOSE
387  if ( fState.GetVerboseL4() )
388  fState.GetVerboseL4()->Message("create from booking", "p1", info->GetName());
389 #endif
390 
391  // Create p1
392  tools::hbook::p1* p1 = 0;
393  if ( ! p1Booking->fEdges.size() ) {
394  p1 = new tools::hbook::p1(
395  hbookIndex, p1Booking->fTitle,
396  p1Booking->fNbins, p1Booking->fXmin, p1Booking->fXmax,
397  p1Booking->fYmin, p1Booking->fYmax);
398  }
399  else {
400  // Convert to float
401  std::vector<float> newEdges;
402  ConvertToFloat(p1Booking->fEdges, newEdges);
403 
404  // not supported
405  //p1 = new tools::hbook::p1(hbookIndex, p1Booking->fTitle, newEdges,
406  // p1Booking->fYmin, p1Booking->fYmax);
407  }
408 
409  fP1Vector.push_back(p1);
410 
411  if ( chDir ) {
412  if ( fFileManager->GetProfileDirectoryName() != "" ) {
413  // Return to //PAWC/LUN1 :
414  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
415  }
416  }
417 
418 #ifdef G4VERBOSE
419  if ( fState.GetVerboseL3() ) {
420  G4ExceptionDescription description;
421  description << " name : " << info->GetName() << " hbook index : " << hbookIndex;
422  fState.GetVerboseL3()->Message("create from booking", "p1", description);
423  }
424 #endif
425 
426  return id;
427 }
428 
429 //_____________________________________________________________________________
430 G4int ExG4HbookP1Manager::RegisterP1Booking(const G4String& name,
431  p1_booking* p1Booking)
432 {
433  // Register p1
434  G4int index = fP1BookingVector.size();
435  fP1BookingVector.push_back(p1Booking);
436  fP1NameIdMap[name] = index + fFirstId;
437 
438  // Lock id
439  fLockFirstId = true;
440 
441  return index + fFirstId;
442 }
443 
444 //_____________________________________________________________________________
445 void ExG4HbookP1Manager::BeginCreateP1(const G4String& name)
446 {
447 #ifdef G4VERBOSE
448  if ( fState.GetVerboseL4() )
449  fState.GetVerboseL4()->Message("create", "P1", name);
450 #endif
451 
452  // Set fP1HbookIdOffset if needed
453  SetP1HbookIdOffset();
454 }
455 
456 //_____________________________________________________________________________
457 G4int ExG4HbookP1Manager::FinishCreateP1(
458  const G4String& name, p1_booking* p1Booking,
459  const G4String& xunitName,
460  const G4String& yunitName,
461  const G4String& xfcnName,
462  const G4String& yfcnName,
463  G4BinScheme xbinScheme)
464 {
465  // Register p1 booking
466  G4int id = RegisterP1Booking(name, p1Booking);
467 
468  // Save P1 information
469  AddP1Information(name, xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
470 
471  // Create p1 if the file is open
472  if ( fFileManager->IsFile() ) {
473  CreateP1FromBooking(p1Booking);
474  }
475 
476 #ifdef G4VERBOSE
477  if ( fState.GetVerboseL2() ) {
478  G4int hbookIndex = fP1HbookIdOffset + id;
479  G4ExceptionDescription description;
480  description << " name : " << name << " hbook index : " << hbookIndex;
481  fState.GetVerboseL2()->Message("create", "P1", description);
482  }
483 #endif
484 
485  return id;
486 }
487 
488 //_____________________________________________________________________________
489 G4bool ExG4HbookP1Manager::BeginSetP1(
490  G4int id,
491  p1_booking* p1Booking,
492  G4HnInformation* info)
493 {
494  p1Booking = GetP1Booking(id, false);
495  if ( ! p1Booking ) {
496  G4ExceptionDescription description;
497  description << " " << "profile " << id << " does not exist.";
498  G4Exception("G4HbookAnalysisManager::SetP1()",
499  "Analysis_W011", JustWarning, description);
500  return false;
501  }
502 
503  info = fHnManager->GetHnInformation(id,"SetP1");
504 #ifdef G4VERBOSE
505  if ( fState.GetVerboseL4() )
506  fState.GetVerboseL4()->Message("configure", "P1", info->GetName());
507 #endif
508 
509  return true;
510 }
511 
512 //_____________________________________________________________________________
513 G4bool ExG4HbookP1Manager::FinishSetP1(
514  G4int id,
515  G4HnInformation* info,
516  const G4String& xunitName,
517  const G4String& yunitName,
518  const G4String& xfcnName,
519  const G4String& yfcnName,
520  G4BinScheme xbinScheme)
521 {
522  // Update information
523  UpdateP1Information(info, xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
524 
525  // Set activation
526  fHnManager->SetActivation(id, true);
527 
528  return true;
529 }
530 
531 
532 //_____________________________________________________________________________
533 void ExG4HbookP1Manager::CreateP1sFromBooking()
534 {
535 // Create all p1 from p1_booking.
536 
537  // Do nothing if any p1 profile already exists
538  // or no p1 profiles are booked
539  if ( fP1Vector.size() || ( fP1BookingVector.size() == 0 ) ) return;
540 
541  // Go to profiles directory if defined
542  if ( fFileManager->GetProfileDirectoryName() != "" ) {
543  G4String profilePath = "//PAWC/LUN1/";
544  profilePath.append(fFileManager->GetProfileDirectoryName().data());
545  tools::hbook::CHCDIR(profilePath.data()," ");
546  }
547 
548  // Create profiles
549  std::vector<p1_booking*>::const_iterator it;
550  for ( it = fP1BookingVector.begin(); it != fP1BookingVector.end(); ++it) {
551  CreateP1FromBooking(*it, false);
552  }
553 
554  // Return backi from profiles directory if defined
555  if ( fFileManager->GetProfileDirectoryName() != "" ) {
556  // Return to //PAWC/LUN1 :
557  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
558  }
559 }
560 
561 //_____________________________________________________________________________
562 void ExG4HbookP1Manager::Reset()
563 {
564 // Reset profiles and ntuple
565 
566  // Delete profiles
567  std::vector<tools::hbook::p1*>::iterator it;
568  for (it = fP1Vector.begin(); it != fP1Vector.end(); it++ ) {
569  delete *it;
570  }
571 
572  // Clear vectors
573  fP1Vector.clear();
574 }
575 
576 //_____________________________________________________________________________
577 p1_booking* ExG4HbookP1Manager::GetP1Booking(G4int id, G4bool warn) const
578 {
579  G4int index = id - fFirstId;
580  if ( index < 0 || index >= G4int(fP1BookingVector.size()) ) {
581  if ( warn) {
582  G4ExceptionDescription description;
583  description << " " << "profile " << id << " does not exist.";
584  G4Exception("G4HbookAnalysisManager::GetP1Booking()",
585  "Analysis_W011", JustWarning, description);
586  }
587  return 0;
588  }
589 
590  return fP1BookingVector[index];
591 }
592 
593 //
594 // protected methods
595 //
596 /*
597 //_____________________________________________________________________________
598 G4bool ExG4HbookP1Manager::WriteOnAscii(std::ofstream& output)
599 {
600 // Write selected objects on ASCII file
601 // (Only P1 implemented by now)
602 // According to the implementation by Michel Maire, originally in
603 // extended examples.
604 
605  // p1 profiles
606  for ( G4int i=0; i<G4int(fP1Vector.size()); ++i ) {
607  G4int id = i + fFirstId;
608  G4HnInformation* info
609  = fHnManager->GetHnInformation(id, "WriteOnAscii");
610  // skip writing if activation is enabled and P1 is inactivated
611  if ( ! info->fAscii ) continue;
612  tools::hbook::p1* p1 = fP1Vector[i];
613 
614 #ifdef G4VERBOSE
615  if ( fState.GetVerboseL3() )
616  fState.GetVerboseL3()->Message("write on ascii", "p1", info->GetName());
617 #endif
618 
619  output << "\n 1D profile " << id << ": " << p1->title()
620  << "\n \n \t X \t\t Y" << G4endl;
621 
622  for (G4int j=0; j< G4int(p1->axis().bins()); ++j) {
623  output << " " << j << "\t"
624  << p1->axis().bin_center(j) << "\t"
625  << p1->bin_height(j) << G4endl;
626  }
627  }
628 
629  return true;
630 }
631 */
632 //_____________________________________________________________________________
633 tools::hbook::p1* ExG4HbookP1Manager::GetP1InFunction(G4int id,
634  G4String functionName, G4bool warn,
635  G4bool onlyIfActive) const
636 {
637  G4int index = id - fFirstId;
638  if ( index < 0 || index >= G4int(fP1Vector.size()) ) {
639  if ( warn) {
640  G4String inFunction = "ExG4HbookP1Manager::";
641  inFunction += functionName;
642  G4ExceptionDescription description;
643  description << " " << "profile " << id << " does not exist.";
644  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
645  }
646  return 0;
647  }
648 
649  // Do not return profile if inactive
650  if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(id) ) ) {
651  return 0;
652  }
653 
654  return fP1Vector[index];
655 }
656 
657 //
658 // public methods
659 //
660 
661 //_____________________________________________________________________________
662 G4int ExG4HbookP1Manager::CreateP1(
663  const G4String& name, const G4String& title,
664  G4int nbins, G4double xmin, G4double xmax,
665  G4double ymin, G4double ymax,
666  const G4String& xunitName,
667  const G4String& yunitName,
668  const G4String& xfcnName,
669  const G4String& yfcnName,
670  const G4String& xbinSchemeName)
671 {
672  BeginCreateP1(name);
673 
674  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
675 
676  // Create p1 booking
677  p1_booking* p1Booking
678  = CreateP1Booking(title, nbins, xmin, xmax, ymin, ymax,
679  xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
680 
681  return FinishCreateP1(name, p1Booking,
682  xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
683 }
684 
685 //_____________________________________________________________________________
686 G4int ExG4HbookP1Manager::CreateP1(
687  const G4String& name, const G4String& title,
688  const std::vector<G4double>& edges,
689  G4double ymin, G4double ymax,
690  const G4String& xunitName,
691  const G4String& yunitName,
692  const G4String& xfcnName,
693  const G4String& yfcnName)
694 {
695  BeginCreateP1(name);
696 
697  // Create p1 booking
698  p1_booking* p1Booking
699  = CreateP1Booking(title, edges, ymin, ymax,
700  xunitName, yunitName, xfcnName, yfcnName);
701 
702  return FinishCreateP1(name, p1Booking,
703  xunitName, yunitName, xfcnName, yfcnName, kUserBinScheme);
704 }
705 
706 
707 //_____________________________________________________________________________
708 G4bool ExG4HbookP1Manager::SetP1(G4int id,
709  G4int nbins, G4double xmin, G4double xmax,
710  G4double ymin, G4double ymax,
711  const G4String& xunitName, const G4String& yunitName,
712  const G4String& xfcnName, const G4String& yfcnName,
713  const G4String& xbinSchemeName)
714 {
715  p1_booking* p1Booking = 0;
716  G4HnInformation* info = 0;
717 
718  if ( ! BeginSetP1(id, p1Booking, info) ) return false;
719 
720  G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
721 
722  // Update P1 booking
723  UpdateP1Booking(p1Booking, nbins, xmin, xmax, ymin, ymax,
724  xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
725 
726  // Re-configure profile if it was already defined
727  if ( fP1Vector.size() ) {
728  tools::hbook::p1* p1 = GetP1(id);
729  ConfigureHbookP1(p1, nbins, xmin, xmax, ymin, ymax,
730  xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
731  }
732 
733  return FinishSetP1(id, info,
734  xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
735 }
736 
737 //_____________________________________________________________________________
738 G4bool ExG4HbookP1Manager::SetP1(G4int id,
739  const std::vector<G4double>& edges,
740  G4double ymin, G4double ymax,
741  const G4String& xunitName, const G4String& yunitName,
742  const G4String& xfcnName, const G4String& yfcnName)
743 {
744  p1_booking* p1Booking = 0;
745  G4HnInformation* info = 0;
746 
747  if ( ! BeginSetP1(id, p1Booking, info) ) return false;
748 
749  // Update P1 booking
750  UpdateP1Booking(p1Booking, edges, ymin, ymax,
751  xunitName, yunitName, xfcnName, yfcnName);
752 
753  // Re-configure profile if it was already defined
754  if ( fP1Vector.size() ) {
755  tools::hbook::p1* p1 = GetP1(id);
756  ConfigureHbookP1(p1, edges, ymin, ymax,
757  xunitName, yunitName, xfcnName, yfcnName);
758  }
759 
760  return
761  FinishSetP1(id, info,
762  xunitName, yunitName, xfcnName, yfcnName, kUserBinScheme);
763 }
764 
765 //_____________________________________________________________________________
766 G4bool ExG4HbookP1Manager::ScaleP1(G4int id, G4double factor)
767 {
768  tools::hbook::p1* p1 = GetP1InFunction(id, "ScaleP1", false, false);
769  if ( ! p1 ) return false;
770 
771  return p1->scale(factor);
772 }
773 
774 //_____________________________________________________________________________
775 G4bool ExG4HbookP1Manager::FillP1(G4int id, G4double xvalue, G4double yvalue,
776  G4double weight)
777 {
778  tools::hbook::p1* p1 = GetP1InFunction(id, "FillP1", true, false);
779  if ( ! p1 ) return false;
780 
781  if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
782  //G4cout << "Skipping FillP1 for " << id << G4endl;
783  return false;
784  }
785 
787  = fHnManager->GetHnDimensionInformation(id, G4HnInformation::kX, "FillP1");
789  = fHnManager->GetHnDimensionInformation(id, G4HnInformation::kY, "FillP1");
790 
791  p1->fill(xInfo->fFcn(xvalue/xInfo->fUnit),
792  yInfo->fFcn(yvalue/yInfo->fUnit), weight);
793 #ifdef G4VERBOSE
794  if ( fState.GetVerboseL4() ) {
795  G4ExceptionDescription description;
796  description << " id " << id
797  << " xvalue " << xvalue
798  << " xfcn(xvalue/xunit) " << xInfo->fFcn(xvalue/xInfo->fUnit)
799  << " yvalue " << yvalue
800  << " yfcn(yvalue/yunit) " << yInfo->fFcn(yvalue/yInfo->fUnit)
801  << " weight " << weight;
802  fState.GetVerboseL4()->Message("fill", "P1", description);
803  }
804 #endif
805  return true;
806 }
807 
808 //_____________________________________________________________________________
809 tools::hbook::p1* ExG4HbookP1Manager::GetP1(G4int id, G4bool warn,
810  G4bool onlyIfActive) const
811 {
812  return GetP1InFunction(id, "GetP1", warn, onlyIfActive);
813 }
814 
815 //_____________________________________________________________________________
816 G4int ExG4HbookP1Manager::GetP1Id(const G4String& name, G4bool warn) const
817 {
818  std::map<G4String, G4int>::const_iterator it = fP1NameIdMap.find(name);
819  if ( it == fP1NameIdMap.end() ) {
820  if ( warn) {
821  G4String inFunction = "ExG4HbookP1Manager::GetP1Id";
822  G4ExceptionDescription description;
823  description << " " << "profile " << name << " does not exist.";
824  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
825  }
826  return -1;
827  }
828  return it->second;
829 }
830 
831 //_____________________________________________________________________________
832 G4int ExG4HbookP1Manager::GetP1Nbins(G4int id) const
833 {
834  tools::hbook::p1* p1 = GetP1InFunction(id, "GetP1Nbins");
835  if ( ! p1 ) return 0;
836 
837  return fBaseToolsManager.GetNbins(p1->axis());
838 }
839 
840 //_____________________________________________________________________________
841 G4double ExG4HbookP1Manager::GetP1Xmin(G4int id) const
842 {
843 // Returns xmin value with applied unit and profile function
844 
845  tools::hbook::p1* p1 = GetP1InFunction(id, "GetP1Xmin");
846  if ( ! p1 ) return 0;
847 
848  return fBaseToolsManager.GetMin(p1->axis());
849 }
850 
851 //_____________________________________________________________________________
852 G4double ExG4HbookP1Manager::GetP1Xmax(G4int id) const
853 {
854  tools::hbook::p1* p1 = GetP1InFunction(id, "GetP1Xmax");
855  if ( ! p1 ) return 0;
856 
857  return fBaseToolsManager.GetMax(p1->axis());
858 }
859 
860 //_____________________________________________________________________________
861 G4double ExG4HbookP1Manager::GetP1XWidth(G4int id) const
862 {
863  tools::hbook::p1* p1 = GetP1InFunction(id, "GetP1XWidth", true, false);
864  if ( ! p1 ) return 0;
865 
866  G4int nbins = p1->axis().bins();
867  if ( ! nbins ) {
868  G4ExceptionDescription description;
869  description << " nbins = 0 (for p1 id = " << id << ").";
870  G4Exception("ExG4HbookP1Manager::GetP1Width",
871  "Analysis_W014", JustWarning, description);
872  return 0;
873  }
874 
875  return fBaseToolsManager.GetWidth(p1->axis());
876 }
877 
878 //_____________________________________________________________________________
879 G4double ExG4HbookP1Manager::GetP1Ymin(G4int id) const
880 {
881 // Returns xmin value with applied unit and profile function
882 
883  tools::hbook::p1* p1 = GetP1InFunction(id, "GetP1Ymin", true, false);
884  if ( ! p1 ) return 0;
885 
886  // not available
887  //return p1->min_v();
888 
889  G4String inFunction = "ExG4HbookP1Manager::GetP1Ymin";
890  G4ExceptionDescription description;
891  description << "Get function not available.";
892  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
893  return 0;
894 }
895 
896 //_____________________________________________________________________________
897 G4double ExG4HbookP1Manager::GetP1Ymax(G4int id) const
898 {
899  tools::hbook::p1* p1 = GetP1InFunction(id, "GetP1Ymax", true, false);
900  if ( ! p1 ) return 0;
901 
902  // not available
903  //return p1->max_v();
904 
905  G4String inFunction = "ExG4HbookP1Manager::GetP1Ymax";
906  G4ExceptionDescription description;
907  description << "Get function not available.";
908  G4Exception(inFunction, "Analysis_W011", JustWarning, description);
909  return 0;
910 }
911 
912 //_____________________________________________________________________________
913 G4bool ExG4HbookP1Manager::SetP1Title(G4int id, const G4String& title)
914 {
915  p1_booking* p1Booking = GetP1Booking(id, false);
916  if ( ! p1Booking ) {
917  G4ExceptionDescription description;
918  description << " " << "profile " << id << " does not exist.";
919  G4Exception("G4HbookAnalysisManager::SetP1Title()",
920  "Analysis_W011", JustWarning, description);
921  return false;
922  }
923 
924  p1Booking->fTitle = title;
925  return true;
926 }
927 
928 //_____________________________________________________________________________
929 G4bool ExG4HbookP1Manager::SetP1XAxisTitle(G4int id, const G4String& title)
930 {
931  tools::hbook::p1* p1 = GetP1InFunction(id, "SetP1XAxisTitle");
932  if ( ! p1 ) return false;
933 
934  p1->add_annotation(tools::hbook::key_axis_x_title(), title);
935  return true;
936 }
937 
938 //_____________________________________________________________________________
939 G4bool ExG4HbookP1Manager::SetP1YAxisTitle(G4int id, const G4String& title)
940 {
941  tools::hbook::p1* p1 = GetP1InFunction(id, "SetP1YAxisTitle");
942  if ( ! p1 ) return false;
943 
944  p1->add_annotation(tools::hbook::key_axis_y_title(), title);
945  return true;
946 }
947 
948 //_____________________________________________________________________________
949 G4String ExG4HbookP1Manager::GetP1Title(G4int id) const
950 {
951  p1_booking* p1Booking = GetP1Booking(id, false);
952  if ( ! p1Booking ) {
953  G4ExceptionDescription description;
954  description << " " << "profile " << id << " does not exist.";
955  G4Exception("G4HbookAnalysisManager::GetP1Title()",
956  "Analysis_W011", JustWarning, description);
957  return "";
958  }
959 
960  return p1Booking->fTitle;
961 }
962 
963 
964 //_____________________________________________________________________________
965 G4String ExG4HbookP1Manager::GetP1XAxisTitle(G4int id) const
966 {
967  tools::hbook::p1* p1 = GetP1InFunction(id, "GetP1XAxisTitle");
968  if ( ! p1 ) return "";
969 
970  G4String title;
971  G4bool result = p1->annotation(tools::hbook::key_axis_x_title(), title);
972  if ( ! result ) {
973  G4ExceptionDescription description;
974  description << " Failed to get x_axis title for p1 id = " << id << ").";
975  G4Exception("ExG4HbookP1Manager::GetP1XAxisTitle",
976  "Analysis_W014", JustWarning, description);
977  return "";
978  }
979 
980  return title;
981 }
982 
983 //_____________________________________________________________________________
984 G4String ExG4HbookP1Manager::GetP1YAxisTitle(G4int id) const
985 {
986  tools::hbook::p1* p1 = GetP1InFunction(id, "GetP1YAxisTitle");
987  if ( ! p1 ) return "";
988 
989  G4String title;
990  G4bool result = p1->annotation(tools::hbook::key_axis_y_title(), title);
991  if ( ! result ) {
992  G4ExceptionDescription description;
993  description << " Failed to get y_axis title for p1 id = " << id << ").";
994  G4Exception("ExG4HbookP1Manager::GetP1YAxisTitle",
995  "Analysis_W014", JustWarning, description);
996  return "";
997  }
998 
999  return title;
1000 }
1001 
1002 //_____________________________________________________________________________
1003 G4bool ExG4HbookP1Manager::SetP1HbookIdOffset(G4int offset)
1004 {
1005  if ( fP1Vector.size() ) {
1006  G4ExceptionDescription description;
1007  description
1008  << "Cannot set P1HbookIdOffset as some P1 profiles already exist.";
1009  G4Exception("G4HbookAnalysisManager::SetP1HbookIdOffset()",
1010  "Analysis_W013", JustWarning, description);
1011  return false;
1012  }
1013 
1014  if ( fFirstId + offset < 1 ) {
1015  G4ExceptionDescription description;
1016  description << "The first profile HBOOK id must be >= 1.";
1017  G4Exception("G4HbookAnalysisManager::SetP1HbookIdOffset()",
1018  "Analysis_W013", JustWarning, description);
1019  return false;
1020  }
1021 
1022  fP1HbookIdOffset = offset;
1023  return true;
1024 }
1025 
1026 #endif
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4double unit, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
Definition: G4BinScheme.cc:56
G4String name
Definition: TRTMaterials.hh:40
G4double(* G4Fcn)(G4double)
Definition: G4Fcn.hh:36
int G4int
Definition: G4Types.hh:78
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
bool G4bool
Definition: G4Types.hh:79
const G4double p1
G4double GetUnitValue(const G4String &unit)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
const char * data() const
static const G4double factor
G4Fcn GetFunction(const G4String &fcnName)
Definition: G4Fcn.cc:36
G4String & append(const G4String &)
G4HnDimensionInformation * GetHnDimensionInformation(G4int dimension)
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition: G4BinScheme.cc:36
#define G4endl
Definition: G4ios.hh:61
G4String GetName() const
G4BinScheme
Definition: G4BinScheme.hh:40
double G4double
Definition: G4Types.hh:76
Definition of the ExG4HbookFileManager class.
Definition of the ExG4HbookP1Manager class.