35 #include "ExG4HbookAnalysisManager.hh"
43 ExG4HbookAnalysisManager* ExG4HbookAnalysisManager::fgInstance = 0;
44 const G4int ExG4HbookAnalysisManager::fgkDefaultH2HbookIdOffset = 100;
45 const G4int ExG4HbookAnalysisManager::fgkDefaultNtupleHbookId = 1;
46 const G4String ExG4HbookAnalysisManager::fgkDefaultNtupleDirectoryName =
"ntuple";
49 ExG4HbookAnalysisManager* ExG4HbookAnalysisManager::Instance()
51 if ( fgInstance == 0 ) {
52 fgInstance =
new ExG4HbookAnalysisManager();
59 ExG4HbookAnalysisManager::ExG4HbookAnalysisManager()
80 <<
"G4HbookAnalysisManager already exists."
81 <<
"Cannot create another instance.";
82 G4Exception(
"G4HbookAnalysisManager::G4HbookAnalysisManager()",
89 tools::hbook::CHLIMIT(
setpawc());
94 ExG4HbookAnalysisManager::~ExG4HbookAnalysisManager()
100 std::vector<h1_booking*>::iterator it;
101 for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); it++ ) {
104 std::vector<h2_booking*>::iterator it2;
105 for ( it2 = fH2BookingVector.begin(); it2 != fH2BookingVector.end(); it2++ ) {
109 delete fNtupleBooking;
120 void ExG4HbookAnalysisManager::SetH1HbookIdOffset()
124 if ( fH1HbookIdOffset == -1 ) {
125 if ( fFirstHistoId > 0 )
126 fH1HbookIdOffset = 0;
128 fH1HbookIdOffset = 1;
130 if ( fH1HbookIdOffset > 0 ) {
132 description <<
"H1 will be defined in HBOOK with ID = G4_firstHistoId + 1";
133 G4Exception(
"ExG4HbookAnalysisManager::SetH1HbookIdOffset()",
140 void ExG4HbookAnalysisManager::SetH2HbookIdOffset()
144 if ( fH2HbookIdOffset == -1 ) {
145 if ( fFirstHistoId > 0 )
146 fH2HbookIdOffset = 0;
148 fH2HbookIdOffset = 1;
150 if ( fH2HbookIdOffset > 0 ) {
152 description <<
"H2 will be defined in HBOOK with ID = G4_firstHistoId + 1";
153 G4Exception(
"ExG4HbookAnalysisManager::SetH1HbookIdOffset",
160 void ExG4HbookAnalysisManager::CreateH1FromBooking()
166 if ( fH1Vector.size() || ( fH1BookingVector.size() == 0 ) )
return;
169 if ( fHistoDirectoryName !=
"" ) {
170 G4String histoPath =
"//PAWC/LUN1/";
171 histoPath.
append(fHistoDirectoryName.data());
172 tools::hbook::CHCDIR(histoPath.
data(),
" ");
177 std::vector<h1_booking*>::const_iterator it;
178 for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); ++it) {
180 G4int id = index + fFirstHistoId;
183 G4int hbookIndex = fH1HbookIdOffset + index + fFirstHistoId;
188 fpVerboseL4->Message(
"create from booking",
"h1", info->
fName);
194 (*it)->fNbins, (*it)->fXmin, (*it)->fXmax);
195 fH1Vector.push_back(h1);
200 description <<
" name : " << info->
fName <<
" hbook index : " << hbookIndex;
201 fpVerboseL3->Message(
"create from booking",
"h1", description);
206 if ( fHistoDirectoryName !=
"" ) {
208 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
213 void ExG4HbookAnalysisManager::CreateH2FromBooking()
219 if ( fH2Vector.size() || ( fH2BookingVector.size() == 0 ) )
return;
222 if ( fHistoDirectoryName !=
"" ) {
223 G4String histoPath =
"//PAWC/LUN1/";
224 histoPath.
append(fHistoDirectoryName.data());
225 tools::hbook::CHCDIR(histoPath.
data(),
" ");
230 std::vector<h2_booking*>::const_iterator it;
231 for ( it = fH2BookingVector.begin(); it != fH2BookingVector.end(); ++it) {
233 G4int id = index + fFirstHistoId;
236 G4int hbookIndex = fH2HbookIdOffset + index + fFirstHistoId;
241 fpVerboseL3->Message(
"create from booking",
"h2", info->
fName);
247 (*it)->fNxbins, (*it)->fXmin, (*it)->fXmax,
248 (*it)->fNybins, (*it)->fYmin, (*it)->fYmax);
249 fH2Vector.push_back(h2);
254 description <<
" name : " << info->
fName <<
" hbook index : " << hbookIndex;
255 fpVerboseL3->Message(
"create from booking",
"h2", description);
260 if ( fHistoDirectoryName !=
"" ) {
262 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
267 void ExG4HbookAnalysisManager::CreateNtupleFromBooking()
271 if ( fNtuple || (! fNtupleBooking) )
return;
275 fpVerboseL4->Message(
"create from booking",
"ntuple", fNtupleBooking->m_name);
280 if ( fNtupleDirectoryName ==
"" )
281 fFile->mkcd(fgkDefaultNtupleDirectoryName.data());
283 fFile->mkcd(fNtupleDirectoryName.data());
284 fLockNtupleDirectoryName =
true;
287 if ( fNtupleHbookId == -1 ) fNtupleHbookId = fgkDefaultNtupleHbookId;
290 fNtuple =
new tools::hbook::wntuple(fNtupleHbookId, G4cout, *fNtupleBooking);
291 if ( fNtupleBooking->m_columns.size() ) {
293 const std::vector<tools::ntuple_booking::col_t>& columns
294 = fNtupleBooking->m_columns;
295 std::vector<tools::ntuple_booking::col_t>::const_iterator it;
297 for ( it = columns.begin(); it!=columns.end(); ++it) {
298 if ( (*it).second == tools::_cid(
int(0) ) ) {
299 G4cout <<
"adding int " << fNtuple->find_column<
int>((*it).first) <<
G4endl;
300 fNtupleIColumnMap[index++] = fNtuple->find_column<
int>((*it).first);
302 else if( (*it).second == tools::_cid(
float(0) ) ) {
303 fNtupleFColumnMap[index++] = fNtuple->find_column<
float>((*it).first);
305 else if((*it).second== tools::_cid(
double(0))) {
306 fNtupleDColumnMap[index++] = fNtuple->find_column<
double>((*it).first);
311 <<
"Unsupported column type " << (*it).first;
312 G4Exception(
"G4HbookAnalysisManager::CreateNtupleFromBooking()",
321 fpVerboseL3->Message(
"create from booking",
"ntuple", fNtupleBooking->m_name);
326 tools::hbook::wntuple::column<int>*
327 ExG4HbookAnalysisManager::GetNtupleIColumn(
G4int id)
const
329 std::map<G4int, tools::hbook::wntuple::column<int>* >::const_iterator it
330 = fNtupleIColumnMap.find(
id);
331 if ( it == fNtupleIColumnMap.end() ) {
333 description <<
" " <<
"column " <<
id <<
" does not exist.";
334 G4Exception(
"G4HbookAnalysisManager::GetNtupleIColumn()",
343 tools::hbook::wntuple::column<float>*
344 ExG4HbookAnalysisManager::GetNtupleFColumn(
G4int id)
const
346 std::map<G4int, tools::hbook::wntuple::column<float>* >::const_iterator it
347 = fNtupleFColumnMap.find(
id);
348 if ( it == fNtupleFColumnMap.end() ) {
350 description <<
" " <<
"column " <<
id <<
" does not exist.";
351 G4Exception(
"G4HbookAnalysisManager::GetNtupleFColumn()",
365 std::vector<tools::hbook::h1*>::iterator it;
366 for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
370 std::vector<tools::hbook::h2*>::iterator it2;
371 for (it2 = fH2Vector.begin(); it2 != fH2Vector.end(); it2++ ) {
392 if ( fcnName !=
"none" ) { title +=
" "; title += fcnName; title +=
"("; }
393 if ( unitName !=
"none" ) { title +=
" "; title += unitName; title +=
" ";}
394 if ( fcnName !=
"none" ) { title +=
")"; }
398 h1_booking* ExG4HbookAnalysisManager::GetH1Booking(
G4int id,
G4bool warn)
const
400 G4int index =
id - fFirstHistoId;
401 if ( index < 0 || index >=
G4int(fH1BookingVector.size()) ) {
404 description <<
" " <<
"histo " <<
id <<
" does not exist.";
405 G4Exception(
"G4HbookAnalysisManager::GetH1Booking()",
411 return fH1BookingVector[
index];
415 h2_booking* ExG4HbookAnalysisManager::GetH2Booking(
G4int id,
G4bool warn)
const
417 G4int index =
id - fFirstHistoId;
418 if ( index < 0 || index >=
G4int(fH2BookingVector.size()) ) {
421 description <<
" " <<
"histo " <<
id <<
" does not exist.";
422 G4Exception(
"G4HbookAnalysisManager::GetH2Booking()",
428 return fH2BookingVector[
index];
436 G4bool ExG4HbookAnalysisManager::WriteOnAscii(std::ofstream& output)
444 for (
G4int i=0; i<
G4int(fH1Vector.size()); ++i ) {
445 G4int id = i + fFirstHistoId;
448 if ( ! info->
fAscii )
continue;
453 fpVerboseL3->Message(
"write on ascii",
"h1", info->
fName);
456 output <<
"\n 1D histogram " <<
id <<
": " << h1->title()
457 <<
"\n \n \t X \t\t Y" <<
G4endl;
459 for (
G4int j=0; j<
G4int(h1->axis().bins()); ++j) {
460 output <<
" " << j <<
"\t"
461 << h1->axis().bin_center(j) <<
"\t"
462 << h1->bin_height(j) <<
G4endl;
472 G4bool onlyIfActive)
const
474 G4int index =
id - fFirstHistoId;
475 if ( index < 0 || index >=
G4int(fH1Vector.size()) ) {
477 G4String inFunction =
"ExG4HbookAnalysisManager::";
478 inFunction += functionName;
480 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
487 if ( fActivation && onlyIfActive && ( ! GetActivation(kH1,
id) ) ) {
491 return fH1Vector[
index];
497 G4bool onlyIfActive)
const
499 G4int index =
id - fFirstHistoId;
500 if ( index < 0 || index >=
G4int(fH2Vector.size()) ) {
502 G4String inFunction =
"ExG4HbookAnalysisManager::";
503 inFunction += functionName;
505 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
512 if ( fActivation && onlyIfActive && ( ! GetActivation(kH2,
id) ) ) {
516 return fH2Vector[
index];
520 tools::hbook::wntuple::column<double>*
521 ExG4HbookAnalysisManager::GetNtupleDColumn(
G4int id)
const
523 std::map<G4int, tools::hbook::wntuple::column<double>* >::const_iterator it
524 = fNtupleDColumnMap.find(
id);
525 if ( it == fNtupleDColumnMap.end() ) {
527 description <<
" " <<
"column " <<
id <<
" does not exist.";
528 G4Exception(
"G4HbookAnalysisManager::GetNtupleDColumn()",
541 G4bool ExG4HbookAnalysisManager::OpenFile(
const G4String& fileName)
544 fFileName = fileName;
548 if (
name.find(
".") == std::string::npos ) {
550 name.append(GetFileType());
555 fpVerboseL4->Message(
"open",
"analysis file",
name);
559 if ( fFile )
delete fFile;
561 tools::hbook::CHCDIR(
"//PAWC",
" ");
563 unsigned int unit = 1;
564 fFile =
new tools::hbook::wfile(std::cout,
name, unit);
565 if ( ! fFile->is_valid() ) {
567 description <<
" " <<
"Cannot open file " << fileName;
579 if ( fHistoDirectoryName !=
"" ) {
580 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
581 tools::hbook::CHMDIR(fHistoDirectoryName.data(),
" ");
582 tools::hbook::CHCDIR(
"//LUN1",
" ");
583 tools::hbook::CHMDIR(fHistoDirectoryName.data(),
" ");
590 if ( ( fH1Vector.size() == 0 ) && ( fH1BookingVector.size() ) )
591 CreateH1FromBooking();
594 if ( ( fH2Vector.size() == 0 ) && ( fH2BookingVector.size() ) )
595 CreateH2FromBooking();
598 if ( fNtupleBooking && ( ! fNtuple ) )
599 CreateNtupleFromBooking();
601 fLockFileName =
true;
602 fLockHistoDirectoryName =
true;
606 fpVerboseL1->Message(
"open",
"analysis file",
name);
613 G4bool ExG4HbookAnalysisManager::Write()
617 fpVerboseL4->Message(
"write",
"file", GetFullFileName());
625 G4bool result = fFile->write();
629 fpVerboseL1->Message(
"write",
"file", GetFullFileName(), result);
634 G4bool result2 = WriteAscii();
635 result = result && result2;
642 G4bool ExG4HbookAnalysisManager::CloseFile()
646 fpVerboseL4->Message(
"close",
"file", GetFullFileName());
653 G4bool result = fFile->close();
654 fLockFileName =
false;
658 fpVerboseL1->Message(
"close",
"file", GetFullFileName(), result);
671 fpVerboseL4->Message(
"create",
"H1", name);
675 G4int index = fH1BookingVector.size();
677 G4Fcn fcn = GetFunction(fcnName);
679 UpdateTitle(newTitle, unitName, fcnName);
680 h1_booking* h1Booking =
new h1_booking(nbins, fcn(xmin), fcn(xmax));
682 h1Booking->fTitle = newTitle;
683 fH1BookingVector.push_back(h1Booking);
684 AddH1Information(name, unitName, fcnName, unit, fcn);
687 SetH1HbookIdOffset();
690 G4int hbookIndex = fH1HbookIdOffset + index + fFirstHistoId;
695 G4String histoPath =
"//PAWC/LUN1/";
696 if ( fHistoDirectoryName !=
"" ) {
697 histoPath.
append(fHistoDirectoryName.data());
698 tools::hbook::CHCDIR(histoPath.
data(),
" ");
700 tools::hbook::CHCDIR(histoPath.
data(),
" ");
706 fH1Vector.push_back(h1);
708 if ( fHistoDirectoryName !=
"" ) {
710 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
714 fLockFirstHistoId =
true;
719 description <<
" name : " << name <<
" hbook index : " << hbookIndex;
720 fpVerboseL2->Message(
"create",
"H1", description);
724 fH1NameIdMap[
name] = index + fFirstHistoId;
725 return index + fFirstHistoId;
737 fpVerboseL4->Message(
"create",
"H2", name);
741 G4int index = fH2BookingVector.size();
744 G4Fcn xfcn = GetFunction(xfcnName);
745 G4Fcn yfcn = GetFunction(yfcnName);
747 UpdateTitle(newTitle, xunitName, xfcnName);
748 UpdateTitle(newTitle, yunitName, yfcnName);
750 h2_booking* h2Booking =
new h2_booking(nxbins, xfcn(xmin), xfcn(xmax),
751 nybins, yfcn(ymin), yfcn(ymax));
753 h2Booking->fTitle = newTitle;
754 fH2BookingVector.push_back(h2Booking);
755 AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
756 xunit, yunit, xfcn, yfcn);
759 SetH2HbookIdOffset();
762 G4int hbookIndex = fH2HbookIdOffset + index + fFirstHistoId;
767 G4String histoPath =
"//PAWC/LUN1/";
768 if ( fHistoDirectoryName !=
"" ) {
769 histoPath.
append(fHistoDirectoryName.data());
771 tools::hbook::CHCDIR(histoPath.
data(),
" ");
776 nxbins, xfcn(xmin), xfcn(xmax),
777 nybins, yfcn(ymin), yfcn(ymax));
779 fH2Vector.push_back(h2);
782 if ( fHistoDirectoryName !=
"" ) {
783 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
787 fLockFirstHistoId =
true;
792 description <<
" name : " << name <<
" hbook index : " << hbookIndex;
793 fpVerboseL2->Message(
"create",
"H2", description);
797 fH2NameIdMap[
name] = index + fFirstHistoId;
798 return index + fFirstHistoId;
807 h1_booking* h1Booking = GetH1Booking(
id,
false);
810 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
819 fpVerboseL4->Message(
"configure",
"H1", info->
fName);
824 G4Fcn fcn = GetFunction(fcnName);
825 h1Booking->fNbins = nbins;
826 h1Booking->fXmin = fcn(xmin);
827 h1Booking->fXmax = fcn(xmax);
836 SetActivation(kH1,
id,
true);
838 G4String newTitle(h1Booking->fTitle);
839 UpdateTitle(newTitle, unitName, fcnName);
840 h1Booking->fTitle = newTitle;
843 if ( fH1Vector.size() ) {
845 h1->configure(nbins, fcn(xmin), fcn(xmax));
859 h2_booking* h2Booking = GetH2Booking(
id,
false);
862 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
871 fpVerboseL4->Message(
"configure",
"H2", info->
fName);
877 G4Fcn xfcn = GetFunction(xfcnName);
878 G4Fcn yfcn = GetFunction(yfcnName);
880 h2Booking->fNxbins = nxbins;
881 h2Booking->fXmin = xfcn(xmin);
882 h2Booking->fXmax = xfcn(xmax);
883 h2Booking->fNybins = nybins;
884 h2Booking->fYmin = yfcn(ymin);
885 h2Booking->fYmax = yfcn(ymax);
895 SetActivation(kH2,
id,
true);
897 G4String newTitle(h2Booking->fTitle);
898 UpdateTitle(newTitle, xunitName, xfcnName);
899 UpdateTitle(newTitle, yunitName, yfcnName);
900 h2Booking->fTitle = newTitle;
903 if ( fH2Vector.size() ) {
905 h2->configure(nxbins, xfcn(xmin), xfcn(xmax),
906 nybins, yfcn(ymin), yfcn(ymax));
916 if ( ! h1 )
return false;
918 return h1->scale(factor);
925 if ( ! h2 )
return false;
927 return h2->scale(factor);
931 void ExG4HbookAnalysisManager::CreateNtuple(
const G4String& name,
936 fpVerboseL4->Message(
"create",
"ntuple", name);
939 if ( fNtupleBooking ) {
942 <<
"Ntuple already exists. "
943 <<
"(Only one ntuple is currently supported.)";
944 G4Exception(
"G4HbookAnalysisManager::CreateNtuple()",
952 if ( fNtupleDirectoryName ==
"" )
953 fFile->mkcd(fgkDefaultNtupleDirectoryName.data());
955 fFile->mkcd(fNtupleDirectoryName.data());
956 fLockNtupleDirectoryName =
true;
961 fpVerboseL4->Message(
"create",
"ntuple", name);
965 if ( fNtupleHbookId == -1 ) fNtupleHbookId = fgkDefaultNtupleHbookId;
968 fNtupleBooking =
new tools::ntuple_booking();
969 fNtupleBooking->m_name =
name;
970 fNtupleBooking->m_title =
title;
976 fNtuple =
new tools::hbook::wntuple(fNtupleHbookId, name);
983 description <<
" name : " << name <<
" hbook index : " << fNtupleHbookId;
984 fpVerboseL2->Message(
"create",
"ntuple", description);
990 G4int ExG4HbookAnalysisManager::CreateNtupleIColumn(
const G4String& name)
994 fpVerboseL4->Message(
"create",
"ntuple I column", name);
997 if ( ! fNtupleBooking ) {
1000 <<
"Ntuple has to be created first. ";
1001 G4Exception(
"G4HbookAnalysisManager::CreateNtupleIColumn()",
1007 G4int index = fNtupleBooking->m_columns.size();
1008 fNtupleBooking->add_column<
int>(
name);
1012 tools::hbook::wntuple::column<int>* column
1013 = fNtuple->create_column<
int>(
name);
1014 fNtupleIColumnMap[
index] = column;
1017 fLockFirstNtupleColumnId =
true;
1021 fpVerboseL2->Message(
"create",
"ntuple I column", name);
1024 return index + fFirstNtupleColumnId;
1028 G4int ExG4HbookAnalysisManager::CreateNtupleFColumn(
const G4String& name)
1032 fpVerboseL4->Message(
"create",
"ntuple F column", name);
1035 if ( ! fNtupleBooking ) {
1038 <<
"Ntuple has to be created first. ";
1039 G4Exception(
"G4HbookAnalysisManager::CreateNtupleFColumn()",
1045 G4int index = fNtupleBooking->m_columns.size();
1046 fNtupleBooking->add_column<
float>(
name);
1050 tools::hbook::wntuple::column<float>* column
1051 = fNtuple->create_column<
float>(
name);
1052 fNtupleFColumnMap[
index] = column;
1055 fLockFirstNtupleColumnId =
true;
1059 fpVerboseL2->Message(
"create",
"ntuple F column", name);
1062 return index + fFirstNtupleColumnId;
1067 G4int ExG4HbookAnalysisManager::CreateNtupleDColumn(
const G4String& name)
1071 fpVerboseL4->Message(
"create",
"ntuple D column", name);
1074 if ( ! fNtupleBooking ) {
1077 <<
"Ntuple has to be created first. ";
1078 G4Exception(
"G4HbookAnalysisManager::CreateNtupleDColumn()",
1084 G4int index = fNtupleBooking->m_columns.size();
1085 fNtupleBooking->add_column<
double>(
name);
1089 tools::hbook::wntuple::column<double>* column
1090 = fNtuple->create_column<
double>(
name);
1091 fNtupleDColumnMap[
index] = column;
1094 fLockFirstNtupleColumnId =
true;
1098 fpVerboseL2->Message(
"create",
"ntuple D column", name);
1101 return index + fFirstNtupleColumnId;
1105 void ExG4HbookAnalysisManager::FinishNtuple()
1107 if ( ! fNtuple )
return;
1111 fpVerboseL4->Message(
"finish",
"ntuple", fNtupleBooking->m_name);
1115 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
1120 fpVerboseL2->Message(
"finish",
"ntuple", fNtupleBooking->m_name);
1128 if ( ! h1 )
return false;
1130 if ( fActivation && ( ! GetActivation(kH1,
id) ) ) {
1138 if ( fpVerboseL4 ) {
1140 description <<
" id " <<
id <<
" value " <<
value;
1141 fpVerboseL4->Message(
"fill",
"H1", description);
1153 if ( ! h2 )
return false;
1155 if ( fActivation && ( ! GetActivation(kH2,
id) ) )
return false;
1161 if ( fpVerboseL4 ) {
1163 description <<
" id " <<
id
1164 <<
" xvalue " << xvalue <<
" yvalue " << yvalue;
1165 fpVerboseL4->Message(
"fill",
"H2", description);
1174 tools::hbook::wntuple::column<int>* column = GetNtupleIColumn(
id);
1177 description <<
" " <<
"column " <<
id <<
" does not exist.";
1178 G4Exception(
"G4HbookAnalysisManager::FillNtupleIColumn()",
1183 column->fill(value);
1185 if ( fpVerboseL4 ) {
1187 description <<
" id " <<
id <<
" value " <<
value;
1188 fpVerboseL4->Message(
"fill",
"ntuple I column", description);
1196 tools::hbook::wntuple::column<float>* column = GetNtupleFColumn(
id);
1199 description <<
" " <<
"column " <<
id <<
" does not exist.";
1200 G4Exception(
"G4HbookAnalysisManager::FillNtupleFColumn()",
1205 column->fill(value);
1207 if ( fpVerboseL4 ) {
1209 description <<
" id " <<
id <<
" value " <<
value;
1210 fpVerboseL4->Message(
"fill",
"ntuple F column", description);
1218 tools::hbook::wntuple::column<double>* column = GetNtupleDColumn(
id);
1221 description <<
" " <<
"column " <<
id <<
" does not exist.";
1222 G4Exception(
"G4HbookAnalysisManager::FillNtupleDColumn()",
1227 column->fill(value);
1229 if ( fpVerboseL4 ) {
1231 description <<
" id " <<
id <<
" value " <<
value;
1232 fpVerboseL4->Message(
"fill",
"ntuple D column", description);
1239 G4bool ExG4HbookAnalysisManager::AddNtupleRow()
1243 fpVerboseL4->Message(
"add",
"ntuple row",
"");
1249 description <<
" " <<
"ntuple does not exist. ";
1250 G4Exception(
"G4HbookAnalysisManager::AddNtupleRow()",
1259 fpVerboseL3->Message(
"add",
"ntuple row",
"");
1266 G4bool onlyIfActive)
const
1268 return GetH1InFunction(
id,
"GetH1", warn, onlyIfActive);
1273 G4bool onlyIfActive)
const
1275 return GetH2InFunction(
id,
"GetH2", warn, onlyIfActive);
1281 std::map<G4String, G4int>::const_iterator it = fH1NameIdMap.find(name);
1282 if ( it == fH1NameIdMap.end() ) {
1284 G4String inFunction =
"ExG4HbookAnalysisManager::GetH1Id";
1286 description <<
" " <<
"histogram " << name <<
" does not exist.";
1297 std::map<G4String, G4int>::const_iterator it = fH2NameIdMap.find(name);
1298 if ( it == fH2NameIdMap.end() ) {
1300 G4String inFunction =
"ExG4HbookAnalysisManager::GetH2Id";
1302 description <<
" " <<
"histogram " << name <<
" does not exist.";
1311 tools::hbook::wntuple* ExG4HbookAnalysisManager::GetNtuple()
const
1317 G4int ExG4HbookAnalysisManager::GetH1Nbins(
G4int id)
const
1320 if ( ! h1 )
return 0;
1322 return h1->axis().bins();
1326 G4double ExG4HbookAnalysisManager::GetH1Xmin(
G4int id)
const
1331 if ( ! h1 )
return 0;
1334 return info->
fXFcn(h1->axis().lower_edge()*info->
fXUnit);
1338 G4double ExG4HbookAnalysisManager::GetH1Xmax(
G4int id)
const
1341 if ( ! h1 )
return 0;
1344 return info->
fXFcn(h1->axis().upper_edge()*info->
fXUnit);
1348 G4double ExG4HbookAnalysisManager::GetH1Width(
G4int id)
const
1351 if ( ! h1 )
return 0;
1353 G4int nbins = h1->axis().bins();
1356 description <<
" nbins = 0 (for h1 id = " <<
id <<
").";
1357 G4Exception(
"ExG4HbookAnalysisManager::GetH1Width",
1363 return ( info->
fXFcn(h1->axis().upper_edge())
1364 - info->
fXFcn(h1->axis().lower_edge()))*info->
fXUnit/nbins;
1368 G4int ExG4HbookAnalysisManager::GetH2Nxbins(
G4int id)
const
1371 if ( ! h2 )
return 0;
1373 return h2->axis_x().bins();
1377 G4double ExG4HbookAnalysisManager::GetH2Xmin(
G4int id)
const
1382 if ( ! h2 )
return 0;
1385 return info->
fXFcn(h2->axis_x().lower_edge()*info->
fXUnit);
1389 G4double ExG4HbookAnalysisManager::GetH2Xmax(
G4int id)
const
1392 if ( ! h2 )
return 0;
1395 return info->
fXFcn(h2->axis_x().upper_edge()*info->
fXUnit);
1399 G4double ExG4HbookAnalysisManager::GetH2XWidth(
G4int id)
const
1402 if ( ! h2 )
return 0;
1404 G4int nbins = h2->axis_x().bins();
1407 description <<
" nbins = 0 (for h1 id = " <<
id <<
").";
1408 G4Exception(
"ExG4HbookAnalysisManager::GetH2Width",
1414 return ( info->
fXFcn(h2->axis_x().upper_edge())
1415 - info->
fXFcn(h2->axis_x().lower_edge()))*info->
fXUnit/nbins;
1419 G4int ExG4HbookAnalysisManager::GetH2Nybins(
G4int id)
const
1422 if ( ! h2 )
return 0;
1424 return h2->axis_y().bins();
1428 G4double ExG4HbookAnalysisManager::GetH2Ymin(
G4int id)
const
1433 if ( ! h2 )
return 0;
1436 return info->
fYFcn(h2->axis_y().lower_edge()*info->
fYUnit);
1440 G4double ExG4HbookAnalysisManager::GetH2Ymax(
G4int id)
const
1443 if ( ! h2 )
return 0;
1446 return info->
fYFcn(h2->axis_y().upper_edge()*info->
fYUnit);
1450 G4double ExG4HbookAnalysisManager::GetH2YWidth(
G4int id)
const
1453 if ( ! h2 )
return 0;
1455 G4int nbins = h2->axis_y().bins();
1458 description <<
" nbins = 0 (for h1 id = " <<
id <<
").";
1459 G4Exception(
"ExG4HbookAnalysisManager::GetH2Width",
1465 return ( info->
fYFcn(h2->axis_y().upper_edge())
1466 - info->
fYFcn(h2->axis_y().lower_edge()))*info->
fYUnit/nbins;
1472 h1_booking* h1Booking = GetH1Booking(
id,
false);
1473 if ( ! h1Booking ) {
1475 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
1476 G4Exception(
"G4HbookAnalysisManager::SetH1Title()",
1481 h1Booking->fTitle =
title;
1489 if ( ! h1 )
return false;
1491 h1->add_annotation(tools::hbook::key_axis_x_title(), title);
1499 if ( ! h1 )
return false;
1501 h1->add_annotation(tools::hbook::key_axis_y_title(), title);
1508 h2_booking* h2Booking = GetH2Booking(
id,
false);
1509 if ( ! h2Booking ) {
1511 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
1512 G4Exception(
"G4HbookAnalysisManager::SetH2Title()",
1517 h2Booking->fTitle =
title;
1525 if ( ! h2 )
return false;
1527 h2->add_annotation(tools::hbook::key_axis_x_title(), title);
1535 if ( ! h2 )
return false;
1537 h2->add_annotation(tools::hbook::key_axis_x_title(), title);
1545 if ( ! h2 )
return false;
1547 h2->add_annotation(tools::hbook::key_axis_z_title(), title);
1552 G4String ExG4HbookAnalysisManager::GetH1Title(
G4int id)
const
1554 h1_booking* h1Booking = GetH1Booking(
id,
false);
1555 if ( ! h1Booking ) {
1557 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
1558 G4Exception(
"G4HbookAnalysisManager::GetH1Title()",
1563 return h1Booking->fTitle;
1568 G4String ExG4HbookAnalysisManager::GetH1XAxisTitle(
G4int id)
const
1571 if ( ! h1 )
return "";
1574 G4bool result = h1->annotation(tools::hbook::key_axis_x_title(), title);
1577 description <<
" Failed to get x_axis title for h1 id = " <<
id <<
").";
1578 G4Exception(
"ExG4HbookAnalysisManager::GetH1XAxisTitle",
1587 G4String ExG4HbookAnalysisManager::GetH1YAxisTitle(
G4int id)
const
1590 if ( ! h1 )
return "";
1593 G4bool result = h1->annotation(tools::hbook::key_axis_y_title(), title);
1596 description <<
" Failed to get y_axis title for h1 id = " <<
id <<
").";
1597 G4Exception(
"ExG4HbookAnalysisManager::GetH1YAxisTitle",
1606 G4String ExG4HbookAnalysisManager::GetH2Title(
G4int id)
const
1608 h2_booking* h2Booking = GetH2Booking(
id,
false);
1609 if ( ! h2Booking ) {
1611 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
1612 G4Exception(
"G4HbookAnalysisManager::GetH2Title()",
1617 return h2Booking->fTitle;
1622 G4String ExG4HbookAnalysisManager::GetH2XAxisTitle(
G4int id)
const
1625 if ( ! h2 )
return "";
1628 G4bool result = h2->annotation(tools::hbook::key_axis_x_title(), title);
1631 description <<
" Failed to get x_axis title for h2 id = " <<
id <<
").";
1632 G4Exception(
"ExG4HbookAnalysisManager::GetH2XAxisTitle",
1641 G4String ExG4HbookAnalysisManager::GetH2YAxisTitle(
G4int id)
const
1644 if ( ! h2 )
return "";
1647 G4bool result = h2->annotation(tools::hbook::key_axis_y_title(), title);
1650 description <<
" Failed to get y_axis title for h2 id = " <<
id <<
").";
1651 G4Exception(
"ExG4HbookAnalysisManager::GetH2YAxisTitle",
1660 G4String ExG4HbookAnalysisManager::GetH2ZAxisTitle(
G4int id)
const
1663 if ( ! h2 )
return "";
1666 G4bool result = h2->annotation(tools::hbook::key_axis_z_title(), title);
1669 description <<
" Failed to get z_axis title for h2 id = " <<
id <<
").";
1670 G4Exception(
"ExG4HbookAnalysisManager::GetH2ZAxisTitle",
1679 G4bool ExG4HbookAnalysisManager::SetH1HbookIdOffset(
G4int offset)
1681 if ( fH1Vector.size() ) {
1684 <<
"Cannot set H1HbookIdOffset as some H1 histogramms already exist.";
1685 G4Exception(
"G4HbookAnalysisManager::SetH1HbookIdOffset()",
1690 if ( fFirstHistoId + offset < 1 ) {
1692 description <<
"The first histogram HBOOK id must be >= 1.";
1693 G4Exception(
"G4HbookAnalysisManager::SetH1HbookIdOffset()",
1698 fH1HbookIdOffset = offset;
1703 G4bool ExG4HbookAnalysisManager::SetH2HbookIdOffset(
G4int offset)
1705 if ( fH2Vector.size() ) {
1708 <<
"Cannot set H2HbookIdOffset as some H2 histogramms already exist.";
1709 G4Exception(
"G4HbookAnalysisManager::SetH2HbookIdOffset()",
1714 if ( fFirstHistoId + offset < 1 ) {
1716 description <<
"The first histogram HBOOK id must be >= 1.";
1717 G4Exception(
"G4HbookAnalysisManager::SetH1HbookIdOffset()",
1722 fH2HbookIdOffset = offset;
1727 G4bool ExG4HbookAnalysisManager::SetNtupleHbookId(
G4int ntupleId)
1732 <<
"Cannot set NtupleHbookId as an ntuple already exists.";
1733 G4Exception(
"G4HbookAnalysisManager::SetNtupleHbookId()",
1738 if ( ntupleId < 1 ) {
1740 description <<
"The ntuple HBOOK id must be >= 1.";
1741 G4Exception(
"G4HbookAnalysisManager::SetNtupleHbookId()",
1746 fNtupleHbookId = ntupleId;