Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
ExG4HbookAnalysisManager.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 //
28 //
29 // $Id$
30 //
33 
34 // Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
35 
36 #ifdef G4_USE_HBOOK
37 
38 #include "ExG4HbookAnalysisManager.hh"
39 #include "G4UnitsTable.hh"
40 
41 #include <iostream>
42 
43 extern "C" int setpawc();
44 extern "C" int setntuc();
45 
46 ExG4HbookAnalysisManager* ExG4HbookAnalysisManager::fgInstance = 0;
47 const G4int ExG4HbookAnalysisManager::fgkDefaultH2HbookIdOffset = 100;
48 const G4int ExG4HbookAnalysisManager::fgkDefaultNtupleHbookId = 1;
49 const G4String ExG4HbookAnalysisManager::fgkDefaultNtupleDirectoryName = "ntuple";
50 
51 //_____________________________________________________________________________
52 ExG4HbookAnalysisManager* ExG4HbookAnalysisManager::Instance()
53 {
54  if ( fgInstance == 0 ) {
55  fgInstance = new ExG4HbookAnalysisManager();
56  }
57 
58  return fgInstance;
59 }
60 
61 //_____________________________________________________________________________
62 ExG4HbookAnalysisManager::ExG4HbookAnalysisManager()
63  : G4VAnalysisManager("Hbook"),
64  fH1HbookIdOffset(-1),
65  fH2HbookIdOffset(-1),
66  fNtupleHbookId(-1),
67  fFile(0),
68  fH1Vector(),
69  fH1MapByName(),
70  fH2Vector(),
71  fH2MapByName(),
72  fNtupleName(),
73  fNtupleTitle(),
74  fNtuple(0),
75  fNtupleIColumnMap(),
76  fNtupleFColumnMap(),
77  fNtupleDColumnMap()
78 {
79  if ( fgInstance ) {
80  G4ExceptionDescription description;
81  description << " "
82  << "G4HbookAnalysisManager already exists."
83  << "Cannot create another instance.";
84  G4Exception("G4HbookAnalysisManager::G4HbookAnalysisManager()",
85  "Analysis_F001", FatalException, description);
86  }
87 
88  fgInstance = this;
89 
90  // Initialize HBOOK :
91  tools::hbook::CHLIMIT(setpawc());
92  setntuc(); //for ntuple.
93 }
94 
95 //_____________________________________________________________________________
96 ExG4HbookAnalysisManager::~ExG4HbookAnalysisManager()
97 {
98  std::vector<tools::hbook::h1*>::iterator it;
99  for ( it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
100  delete *it;
101  }
102  std::vector<tools::hbook::h2*>::iterator it2;
103  for ( it2 = fH2Vector.begin(); it2 != fH2Vector.end(); it2++ ) {
104  delete *it2;
105  }
106  delete fNtuple;
107  delete fFile;
108 
109  fgInstance = 0;
110 }
111 
112 //
113 // private methods
114 //
115 
116 //_____________________________________________________________________________
117 tools::hbook::wntuple::column<int>*
118 ExG4HbookAnalysisManager::GetNtupleIColumn(G4int id) const
119 {
120  std::map<G4int, tools::hbook::wntuple::column<int>* >::const_iterator it
121  = fNtupleIColumnMap.find(id);
122  if ( it == fNtupleIColumnMap.end() ) {
123  G4ExceptionDescription description;
124  description << " " << "column " << id << " does not exist.";
125  G4Exception("G4HbookAnalysisManager::GetNtupleIColumn()",
126  "Analysis_W009", JustWarning, description);
127  return 0;
128  }
129 
130  return it->second;
131 }
132 
133 //_____________________________________________________________________________
134 tools::hbook::wntuple::column<float>*
135 ExG4HbookAnalysisManager::GetNtupleFColumn(G4int id) const
136 {
137  std::map<G4int, tools::hbook::wntuple::column<float>* >::const_iterator it
138  = fNtupleFColumnMap.find(id);
139  if ( it == fNtupleFColumnMap.end() ) {
140  G4ExceptionDescription description;
141  description << " " << "column " << id << " does not exist.";
142  G4Exception("G4HbookAnalysisManager::GetNtupleFColumn()",
143  "Analysis_W009", JustWarning, description);
144  return 0;
145  }
146 
147  return it->second;
148 }
149 
150 
151 //_____________________________________________________________________________
152 tools::hbook::wntuple::column<double>*
153 ExG4HbookAnalysisManager::GetNtupleDColumn(G4int id) const
154 {
155  std::map<G4int, tools::hbook::wntuple::column<double>* >::const_iterator it
156  = fNtupleDColumnMap.find(id);
157  if ( it == fNtupleDColumnMap.end() ) {
158  G4ExceptionDescription description;
159  description << " " << "column " << id << " does not exist.";
160  G4Exception("G4HbookAnalysisManager::GetNtupleDColumn()",
161  "Analysis_W009", JustWarning, description);
162  return 0;
163  }
164 
165  return it->second;
166 }
167 
168 //
169 // public methods
170 //
171 
172 //_____________________________________________________________________________
173 G4bool ExG4HbookAnalysisManager::OpenFile(const G4String& fileName)
174 {
175  G4String name(fileName);
176  if ( name.find(".") == std::string::npos ) {
177  name.append(".");
178  name.append(GetFileType());
179  }
180 
181 #ifdef G4VERBOSE
182  if ( fpVerboseL3 )
183  fpVerboseL3->Message("open", "analysis file", name);
184 #endif
185 
186  tools::hbook::CHCDIR("//PAWC"," ");
187 
188  unsigned int unit = 1;
189  fFile = new tools::hbook::wfile(std::cout, name, unit);
190  if ( ! fFile->is_valid() ) {
191  G4ExceptionDescription description;
192  description << " " << "Cannot open file " << fileName;
193  G4Exception("G4HbookAnalysisManager::OpenFile()",
194  "Analysis_W001", JustWarning, description);
195  return false;
196  }
197 
198  // At this point, in HBOOK, we should have :
199  // - created a //LUN1 directory attached to the file
200  // - created a //PAWC/LUN1 in memory
201  // - be in the directory //PAWC/LUN1.
202 
203  // create an "histo" HBOOK directory both in memory and in the file :
204  if ( fHistoDirectoryName != "" ) {
205  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
206  tools::hbook::CHMDIR(fHistoDirectoryName.data()," ");
207  tools::hbook::CHCDIR("//LUN1"," ");
208  tools::hbook::CHMDIR(fHistoDirectoryName.data()," ");
209  }
210 
211  fLockHistoDirectoryName = true;
212 
213  // the five upper lines could have been done with :
214  //fFile->cd_home();
215  //fFile->mkcd("histo");
216 
217 #ifdef G4VERBOSE
218  if ( fpVerboseL1 )
219  fpVerboseL1->Message("open", "analysis file", name);
220 #endif
221 
222  return true;
223 }
224 
225 //_____________________________________________________________________________
226 G4bool ExG4HbookAnalysisManager::Write()
227 {
228 #ifdef G4VERBOSE
229  if ( fpVerboseL3 )
230  fpVerboseL3->Message("write", "file", "");
231 #endif
232 
233  // ntuple
234  //if ( fNtuple ) fNtuple->add_row_end();
235 
236  G4bool result = fFile->write();
237 
238 #ifdef G4VERBOSE
239  if ( fpVerboseL1 )
240  fpVerboseL1->Message("write", "file", "", result);
241 #endif
242 
243  return result;
244 }
245 
246 //_____________________________________________________________________________
247 G4bool ExG4HbookAnalysisManager::CloseFile()
248 {
249 #ifdef G4VERBOSE
250  if ( fpVerboseL3 )
251  fpVerboseL3->Message("close", "file", "");
252 #endif
253 
254  //WARNING : have to delete the ntuple before closing the file.
255  delete fNtuple;
256  fNtuple = 0;
257 
258  G4bool result = fFile->close();
259 
260 #ifdef G4VERBOSE
261  if ( fpVerboseL1 )
262  fpVerboseL1->Message("close", "file", "", result);
263 #endif
264 
265  return result;
266 }
267 
268 //_____________________________________________________________________________
269 G4int ExG4HbookAnalysisManager::CreateH1(const G4String& name, const G4String& title,
270  G4int nbins, G4double xmin, G4double xmax)
271 {
272 #ifdef G4VERBOSE
273  if ( fpVerboseL3 )
274  fpVerboseL3->Message("create", "H1", name);
275 #endif
276 
277  // Go to histograms directory
278  if ( fHistoDirectoryName != "" ) {
279  G4String histoPath = "//PAWC/LUN1/";
280  histoPath.append(fHistoDirectoryName.data());
281  tools::hbook::CHCDIR(histoPath.data()," ");
282  }
283 
284  // Set fH1HbookIdOffset if needed
285  if ( fH1Vector.size() == 0 ) {
286  if ( fH1HbookIdOffset == -1 ) {
287  if ( fFirstHistoId > 0 )
288  fH1HbookIdOffset = 0;
289  else
290  fH1HbookIdOffset = 1;
291 
292  if ( fH1HbookIdOffset > 0 ) {
293  G4ExceptionDescription description;
294  description << "H1 will be defined in HBOOK with ID = G4_firstHistoId + 1";
295  G4Exception("ExG4HbookAnalysisManager::CreateH1()",
296  "Analysis_W011", JustWarning, description);
297  }
298  }
299  }
300 
301  // Create histogram
302  G4int index = fH1Vector.size();
303  G4int hbookIndex = fH1HbookIdOffset + fH1Vector.size() + fFirstHistoId;
304  tools::hbook::h1* h1 = new tools::hbook::h1(hbookIndex, title, nbins, xmin, xmax);
305  fH1Vector.push_back(h1);
306  fH1MapByName[name] = h1;
307 
308  if ( fHistoDirectoryName != "" ) {
309  // Return to //PAWC/LUN1 :
310  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
311  }
312 
313  fLockFirstHistoId = true;
314 
315 #ifdef G4VERBOSE
316  if ( fpVerboseL1 ) {
317  G4ExceptionDescription description;
318  description << " name : " << name << " hbook index : " << hbookIndex;
319  fpVerboseL1->Message("create", "H1", description);
320  }
321 #endif
322 
323  return index + fFirstHistoId;
324 }
325 
326 //_____________________________________________________________________________
327 G4int ExG4HbookAnalysisManager::CreateH2(const G4String& name, const G4String& title,
328  G4int nxbins, G4double xmin, G4double xmax,
329  G4int nybins, G4double ymin, G4double ymax)
330 {
331 #ifdef G4VERBOSE
332  if ( fpVerboseL3 )
333  fpVerboseL3->Message("create", "H2", name);
334 #endif
335 
336  // Go to histograms directory
337  if ( fHistoDirectoryName != "" ) {
338  G4String histoPath = "//PAWC/LUN1/";
339  histoPath.append(fHistoDirectoryName.data());
340  tools::hbook::CHCDIR(histoPath.data()," ");
341  }
342 
343  // Set fH2HbookIdOffset if needed
344  if ( fH2Vector.size() == 0 ) {
345  if ( fH2HbookIdOffset == -1 ) {
346  if ( fFirstHistoId > 0 )
347  fH2HbookIdOffset = fgkDefaultH2HbookIdOffset;
348  else
349  fH2HbookIdOffset = fgkDefaultH2HbookIdOffset + 1;
350 
351  if ( fH2HbookIdOffset != fgkDefaultH2HbookIdOffset ) {
352  G4ExceptionDescription description;
353  description
354  << "H2 will be defined in HBOOK with ID = "
355  << fgkDefaultH2HbookIdOffset << " + G4_firstHistoId + 1";
356  G4Exception("ExG4HbookAnalysisManager::CreateH2()",
357  "Analysis_W011", JustWarning, description);
358  }
359  }
360  }
361 
362  G4int index = fH2Vector.size();
363  G4int hbookIndex = fH2HbookIdOffset + fH2Vector.size() + fFirstHistoId;
365  = new tools::hbook::h2(hbookIndex, title, nxbins, xmin, xmax, nybins, ymin, ymax);
366  fH2Vector.push_back(h2);
367  fH2MapByName[name] = h2;
368 
369  // Return to //PAWC/LUN1 :
370  if ( fHistoDirectoryName != "" ) {
371  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
372  }
373 
374  fLockFirstHistoId = true;
375 
376 #ifdef G4VERBOSE
377  if ( fpVerboseL1 ) {
378  G4ExceptionDescription description;
379  description << " name : " << name << " hbook index : " << hbookIndex;
380  fpVerboseL1->Message("create", "H2", description);
381  }
382 #endif
383 
384  return index + fFirstHistoId;
385 }
386 
387 //_____________________________________________________________________________
388 void ExG4HbookAnalysisManager::CreateNtuple(const G4String& name,
389  const G4String& title)
390 {
391 #ifdef G4VERBOSE
392  if ( fpVerboseL3 )
393  fpVerboseL3->Message("create", "ntuple", name);
394 #endif
395 
396  if ( fNtuple ) {
397  G4ExceptionDescription description;
398  description << " "
399  << "Ntuple already exists. "
400  << "(Only one ntuple is currently supported.)";
401  G4Exception("G4HbookAnalysisManager::CreateNtuple()",
402  "Analysis_W006", JustWarning, description);
403  return;
404  }
405 
406  // Create an "ntuple" directory both in memory and in the file
407  fFile->cd_home(); //go under //PAWC/LUN1
408  if ( fNtupleDirectoryName == "" )
409  fFile->mkcd(fgkDefaultNtupleDirectoryName.data());
410  else
411  fFile->mkcd(fNtupleDirectoryName.data());
412 
413  // Define ntuple ID in HBOOK
414  if ( fNtupleHbookId == -1 ) fNtupleHbookId = fgkDefaultNtupleHbookId;
415 
416  // We should be under //PAWC/LUN1/ntuple
417  fNtuple = new tools::hbook::wntuple(fNtupleHbookId, name);
418  fNtupleName = name;
419  fNtupleTitle = title;
420 
421 #ifdef G4VERBOSE
422  if ( fpVerboseL1 ) {
423  G4ExceptionDescription description;
424  description << " name : " << name << " hbook index : " << fNtupleHbookId;
425  fpVerboseL1->Message("create", "ntuple", description);
426  }
427 #endif
428 }
429 
430 //_____________________________________________________________________________
431 G4int ExG4HbookAnalysisManager::CreateNtupleIColumn(const G4String& name)
432 {
433 #ifdef G4VERBOSE
434  if ( fpVerboseL3 )
435  fpVerboseL3->Message("create", "ntuple I column", name);
436 #endif
437 
438  G4int index = fNtuple->columns().size();
439  tools::hbook::wntuple::column<int>* column = fNtuple->create_column<int>(name);
440  fNtupleIColumnMap[index] = column;
441  fLockFirstNtupleColumnId = true;
442 
443 #ifdef G4VERBOSE
444  if ( fpVerboseL1 )
445  fpVerboseL1->Message("create", "ntuple I column", name);
446 #endif
447 
448  return index + fFirstNtupleColumnId;
449 }
450 
451 //_____________________________________________________________________________
452 G4int ExG4HbookAnalysisManager::CreateNtupleFColumn(const G4String& name)
453 {
454 #ifdef G4VERBOSE
455  if ( fpVerboseL3 )
456  fpVerboseL3->Message("create", "ntuple F column", name);
457 #endif
458 
459  G4int index = fNtuple->columns().size();
460  tools::hbook::wntuple::column<float>* column = fNtuple->create_column<float>(name);
461  fNtupleFColumnMap[index] = column;
462  fLockFirstNtupleColumnId = true;
463 
464 #ifdef G4VERBOSE
465  if ( fpVerboseL1 )
466  fpVerboseL1->Message("create", "ntuple F column", name);
467 #endif
468 
469  return index + fFirstNtupleColumnId;
470 }
471 
472 
473 //_____________________________________________________________________________
474 G4int ExG4HbookAnalysisManager::CreateNtupleDColumn(const G4String& name)
475 {
476 #ifdef G4VERBOSE
477  if ( fpVerboseL3 )
478  fpVerboseL3->Message("create", "ntuple D column", name);
479 #endif
480 
481  G4int index = fNtuple->columns().size();
482  tools::hbook::wntuple::column<double>* column = fNtuple->create_column<double>(name);
483  fNtupleDColumnMap[index] = column;
484  fLockFirstNtupleColumnId = true;
485 
486 #ifdef G4VERBOSE
487  if ( fpVerboseL1 )
488  fpVerboseL1->Message("create", "ntuple D column", name);
489 #endif
490 
491  return index + fFirstNtupleColumnId;
492 }
493 
494 //_____________________________________________________________________________
495 void ExG4HbookAnalysisManager::FinishNtuple()
496 {
497 #ifdef G4VERBOSE
498  if ( fpVerboseL3 )
499  fpVerboseL3->Message("finish", "ntuple", fNtupleName);
500 #endif
501 
502  // Return to //PAWC/LUN1 :
503  tools::hbook::CHCDIR("//PAWC/LUN1"," ");
504 
505  //fNtuple->add_row_beg();
506 #ifdef G4VERBOSE
507  if ( fpVerboseL1 )
508  fpVerboseL1->Message("finish", "ntuple", fNtupleName);
509 #endif
510 }
511 
512 //_____________________________________________________________________________
513 G4bool ExG4HbookAnalysisManager::FillH1(G4int id, G4double value, G4double weight)
514 {
515 #ifdef G4VERBOSE
516  if ( fpVerboseL3 ) {
517  G4ExceptionDescription description;
518  description << " id " << id << " value " << value;
519  fpVerboseL3->Message("fill", "H1", description);
520  }
521 #endif
522 
523  tools::hbook::h1* h1 = GetH1(id);
524  if ( ! h1 ) {
525  G4ExceptionDescription description;
526  description << " " << "histogram " << id << " does not exist.";
527  G4Exception("G4HbookAnalysisManager::FillH1()",
528  "Analysis_W007", JustWarning, description);
529  return false;
530  }
531 
532  h1->fill(value, weight);
533 #ifdef G4VERBOSE
534  if ( fpVerboseL2 ) {
535  G4ExceptionDescription description;
536  description << " id " << id << " value " << value;
537  fpVerboseL2->Message("fill", "H1", description);
538  }
539 #endif
540  return true;
541 }
542 
543 //_____________________________________________________________________________
544 G4bool ExG4HbookAnalysisManager::FillH2(G4int id,
545  G4double xvalue, G4double yvalue,
546  G4double weight)
547 {
548 #ifdef G4VERBOSE
549  if ( fpVerboseL3 ) {
550  G4ExceptionDescription description;
551  description << " id " << id
552  << " xvalue " << xvalue << " yvalue " << yvalue;
553  fpVerboseL3->Message("fill", "H2", description);
554  }
555 #endif
556 
557  tools::hbook::h2* h2 = GetH2(id);
558  if ( ! h2 ) {
559  G4ExceptionDescription description;
560  description << " " << "histogram " << id << " does not exist.";
561  G4Exception("G4HbookAnalysisManager::FillH2()",
562  "Analysis_W007", JustWarning, description);
563  return false;
564  }
565 
566  h2->fill(xvalue, yvalue, weight);
567 #ifdef G4VERBOSE
568  if ( fpVerboseL2 ) {
569  G4ExceptionDescription description;
570  description << " id " << id
571  << " xvalue " << xvalue << " yvalue " << yvalue;
572  fpVerboseL2->Message("fill", "H2", description);
573  }
574 #endif
575  return true;
576 }
577 
578 //_____________________________________________________________________________
579 G4bool ExG4HbookAnalysisManager::FillNtupleIColumn(G4int id, G4int value)
580 {
581 #ifdef G4VERBOSE
582  if ( fpVerboseL3 ) {
583  G4ExceptionDescription description;
584  description << " id " << id << " value " << value;
585  fpVerboseL3->Message("fill", "ntuple I column", description);
586  }
587 #endif
588 
589  tools::hbook::wntuple::column<int>* column = GetNtupleIColumn(id);
590  if ( ! column ) {
591  G4ExceptionDescription description;
592  description << " " << "column " << id << " does not exist.";
593  G4Exception("G4HbookAnalysisManager::FillNtupleIColumn()",
594  "Analysis_W009", JustWarning, description);
595  return false;
596  }
597 
598  column->fill(value);
599  #ifdef G4VERBOSE
600  if ( fpVerboseL2 ) {
601  G4ExceptionDescription description;
602  description << " id " << id << " value " << value;
603  fpVerboseL2->Message("fill", "ntuple I column", description);
604  }
605 #endif
606  return true;
607 }
608 //_____________________________________________________________________________
609 G4bool ExG4HbookAnalysisManager::FillNtupleFColumn(G4int id, G4float value)
610 {
611 #ifdef G4VERBOSE
612  if ( fpVerboseL3 ) {
613  G4ExceptionDescription description;
614  description << " id " << id << " value " << value;
615  fpVerboseL3->Message("fill", "ntuple F column", description);
616  }
617 #endif
618 
619  tools::hbook::wntuple::column<float>* column = GetNtupleFColumn(id);
620  if ( ! column ) {
621  G4ExceptionDescription description;
622  description << " " << "column " << id << " does not exist.";
623  G4Exception("G4HbookAnalysisManager::FillNtupleFColumn()",
624  "Analysis_W009", JustWarning, description);
625  return false;
626  }
627 
628  column->fill(value);
629 #ifdef G4VERBOSE
630  if ( fpVerboseL2 ) {
631  G4ExceptionDescription description;
632  description << " id " << id << " value " << value;
633  fpVerboseL2->Message("fill", "ntuple F column", description);
634  }
635 #endif
636  return true;
637 }
638 //_____________________________________________________________________________
639 G4bool ExG4HbookAnalysisManager::FillNtupleDColumn(G4int id, G4double value)
640 {
641 #ifdef G4VERBOSE
642  if ( fpVerboseL3 ) {
643  G4ExceptionDescription description;
644  description << " id " << id << " value " << value;
645  fpVerboseL3->Message("fill", "ntuple D column", description);
646  }
647 #endif
648 
649  tools::hbook::wntuple::column<double>* column = GetNtupleDColumn(id);
650  if ( ! column ) {
651  G4ExceptionDescription description;
652  description << " " << "column " << id << " does not exist.";
653  G4Exception("G4HbookAnalysisManager::FillNtupleDColumn()",
654  "Analysis_W009", JustWarning, description);
655  return false;
656  }
657 
658  column->fill(value);
659 #ifdef G4VERBOSE
660  if ( fpVerboseL2 ) {
661  G4ExceptionDescription description;
662  description << " id " << id << " value " << value;
663  fpVerboseL2->Message("fill", "ntuple D column", description);
664  }
665 #endif
666  return true;
667 }
668 
669 //_____________________________________________________________________________
670 G4bool ExG4HbookAnalysisManager::AddNtupleRow()
671 {
672 #ifdef G4VERBOSE
673  if ( fpVerboseL3 )
674  fpVerboseL3->Message("add", "ntuple row", "");
675 #endif
676 
677  //G4cout << "Hbook: Going to add Ntuple row ..." << G4endl;
678  if ( ! fNtuple ) {
679  G4ExceptionDescription description;
680  description << " " << "ntuple does not exist. ";
681  G4Exception("G4HbookAnalysisManager::AddNtupleRow()",
682  "Analysis_W008", JustWarning, description);
683  return false;
684  }
685 
686  //fNtuple->add_row_fast();
687  fNtuple->add_row();
688 #ifdef G4VERBOSE
689  if ( fpVerboseL2 )
690  fpVerboseL2->Message("add", "ntuple row", "");
691 #endif
692  return true;
693 }
694 
695 //_____________________________________________________________________________
696 tools::hbook::h1* ExG4HbookAnalysisManager::GetH1(G4int id, G4bool warn) const
697 {
698  G4int index = id - fFirstHistoId;
699  if ( index < 0 || index >= G4int(fH1Vector.size()) ) {
700  if ( warn) {
701  G4ExceptionDescription description;
702  description << " " << "histo " << id << " does not exist.";
703  G4Exception("G4HbookAnalysisManager::GetH1()",
704  "Analysis_W007", JustWarning, description);
705  }
706  return 0;
707  }
708  return fH1Vector[index];
709 }
710 
711 //_____________________________________________________________________________
712 tools::hbook::h2* ExG4HbookAnalysisManager::GetH2(G4int id, G4bool warn) const
713 {
714  G4int index = id - fFirstHistoId;
715  if ( index < 0 || index >= G4int(fH2Vector.size()) ) {
716  if ( warn) {
717  G4ExceptionDescription description;
718  description << " " << "histo " << id << " does not exist.";
719  G4Exception("G4HbookAnalysisManager::GetH2()",
720  "Analysis_W007", JustWarning, description);
721  }
722  return 0;
723  }
724  return fH2Vector[index];
725 }
726 
727 //_____________________________________________________________________________
728 tools::hbook::wntuple* ExG4HbookAnalysisManager::GetNtuple() const
729 {
730  return fNtuple;
731 }
732 
733 //_____________________________________________________________________________
734 G4bool ExG4HbookAnalysisManager::SetH1HbookIdOffset(G4int offset)
735 {
736  if ( fH1Vector.size() ) {
737  G4ExceptionDescription description;
738  description
739  << "Cannot set H1HbookIdOffset as some H1 histogramms already exist.";
740  G4Exception("G4HbookAnalysisManager::SetH1HbookIdOffset()",
741  "Analysis_W009", JustWarning, description);
742  return false;
743  }
744 
745  if ( fFirstHistoId + offset < 1 ) {
746  G4ExceptionDescription description;
747  description << "The first histogram HBOOK id must be >= 1.";
748  G4Exception("G4HbookAnalysisManager::SetH1HbookIdOffset()",
749  "Analysis_W009", JustWarning, description);
750  return false;
751  }
752 
753  fH1HbookIdOffset = offset;
754  return true;
755 }
756 
757 //_____________________________________________________________________________
758 G4bool ExG4HbookAnalysisManager::SetH2HbookIdOffset(G4int offset)
759 {
760  if ( fH2Vector.size() ) {
761  G4ExceptionDescription description;
762  description
763  << "Cannot set H2HbookIdOffset as some H2 histogramms already exist.";
764  G4Exception("G4HbookAnalysisManager::SetH2HbookIdOffset()",
765  "Analysis_W009", JustWarning, description);
766  return false;
767  }
768 
769  if ( fFirstHistoId + offset < 1 ) {
770  G4ExceptionDescription description;
771  description << "The first histogram HBOOK id must be >= 1.";
772  G4Exception("G4HbookAnalysisManager::SetH1HbookIdOffset()",
773  "Analysis_W009", JustWarning, description);
774  return false;
775  }
776 
777  fH2HbookIdOffset = offset;
778  return true;
779 }
780 
781 //_____________________________________________________________________________
782 G4bool ExG4HbookAnalysisManager::SetNtupleHbookId(G4int ntupleId)
783 {
784  if ( fNtuple ) {
785  G4ExceptionDescription description;
786  description
787  << "Cannot set NtupleHbookId as an ntuple already exists.";
788  G4Exception("G4HbookAnalysisManager::SetNtupleHbookId()",
789  "Analysis_W010", JustWarning, description);
790  return false;
791  }
792 
793  if ( ntupleId < 1 ) {
794  G4ExceptionDescription description;
795  description << "The ntuple HBOOK id must be >= 1.";
796  G4Exception("G4HbookAnalysisManager::SetNtupleHbookId()",
797  "Analysis_W010", JustWarning, description);
798  return false;
799  }
800 
801  fNtupleHbookId = ntupleId;
802  return true;
803 }
804 
805 #endif