45 const G4int ExG4HbookH2Manager::fgkDefaultH2HbookIdOffset = 100;
50 fBaseToolsManager(
"H2"),
60 ExG4HbookH2Manager::~ExG4HbookH2Manager()
66 std::vector<h2_booking*>::iterator it2;
67 for ( it2 = fH2BookingVector.begin(); it2 != fH2BookingVector.end(); it2++ ) {
77 void ExG4HbookH2Manager::SetH2HbookIdOffset()
81 if ( fH2HbookIdOffset == -1 ) {
87 if ( fH2HbookIdOffset > 0 ) {
89 description <<
"H2 will be defined in HBOOK with ID = G4_firstHistoId + 1";
90 G4Exception(
"ExG4HbookH2Manager::SetH1HbookIdOffset",
97 void ExG4HbookH2Manager::CreateH2sFromBooking()
103 if ( fH2Vector.size() || ( fH2BookingVector.size() == 0 ) )
return;
106 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
107 G4String histoPath =
"//PAWC/LUN1/";
108 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
109 tools::hbook::CHCDIR(histoPath.
data(),
" ");
114 std::vector<h2_booking*>::const_iterator it;
115 for ( it = fH2BookingVector.begin(); it != fH2BookingVector.end(); ++it) {
117 G4int id = index + fFirstId;
118 G4HnInformation* info = fHnManager->GetHnInformation(
id,
"CreateH2FromBooking");
120 G4int hbookIndex = fH2HbookIdOffset + index + fFirstId;
124 if ( fState.GetVerboseL3() )
125 fState.GetVerboseL3()->Message(
"create from booking",
"h2", info->
GetName());
130 =
new tools::hbook::h2(hbookIndex, (*it)->fTitle,
131 (*it)->fNxbins, (*it)->fXmin, (*it)->fXmax,
132 (*it)->fNybins, (*it)->fYmin, (*it)->fYmax);
133 fH2Vector.push_back(h2);
136 if ( fState.GetVerboseL3() ) {
138 description <<
" name : " << info->
GetName() <<
" hbook index : " << hbookIndex;
139 fState.GetVerboseL3()->Message(
"create from booking",
"h2", description);
144 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
146 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
151 void ExG4HbookH2Manager::Reset()
156 std::vector<tools::hbook::h2*>::iterator it2;
157 for (it2 = fH2Vector.begin(); it2 != fH2Vector.end(); it2++ ) {
166 h2_booking* ExG4HbookH2Manager::GetH2Booking(
G4int id,
G4bool warn)
const
168 G4int index =
id - fFirstId;
169 if ( index < 0 || index >=
G4int(fH2BookingVector.size()) ) {
172 description <<
" " <<
"histo " <<
id <<
" does not exist.";
173 G4Exception(
"G4HbookAnalysisManager::GetH2Booking()",
179 return fH2BookingVector[index];
187 G4bool ExG4HbookH2Manager::WriteOnAscii(std::ofstream& )
198 tools::hbook::h2* ExG4HbookH2Manager::GetH2InFunction(
G4int id,
200 G4bool onlyIfActive)
const
202 G4int index =
id - fFirstId;
203 if ( index < 0 || index >=
G4int(fH2Vector.size()) ) {
205 G4String inFunction =
"ExG4HbookH2Manager::";
206 inFunction += functionName;
208 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
215 if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(
id) ) ) {
219 return fH2Vector[index];
237 if ( xbinSchemeName !=
"linear" || ybinSchemeName !=
"linear" ) {
241 <<
"Logarithimc binning is not supported for H2.";
247 if ( fState.GetVerboseL4() )
248 fState.GetVerboseL4()->Message(
"create",
"H2", name);
252 G4int index = fH2BookingVector.size();
263 h2_booking* h2Booking =
new h2_booking(nxbins, xfcn(xmin), xfcn(xmax),
264 nybins, yfcn(ymin), yfcn(ymax));
266 h2Booking->fTitle = newTitle;
267 fH2BookingVector.push_back(h2Booking);
269 ->AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
270 xunit, yunit, xfcn, yfcn, xbinScheme, ybinScheme);
273 SetH2HbookIdOffset();
276 G4int hbookIndex = fH2HbookIdOffset + index + fFirstId;
279 if ( fFileManager->IsFile() ) {
281 G4String histoPath =
"//PAWC/LUN1/";
282 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
283 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
285 tools::hbook::CHCDIR(histoPath.
data(),
" ");
289 =
new tools::hbook::h2(hbookIndex, title,
290 nxbins, xfcn(xmin), xfcn(xmax),
291 nybins, yfcn(ymin), yfcn(ymax));
293 fH2Vector.push_back(h2);
296 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
297 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
304 if ( fState.GetVerboseL2() ) {
306 description <<
" name : " << name <<
" hbook index : " << hbookIndex;
307 fState.GetVerboseL2()->Message(
"create",
"H2", description);
311 fH2NameIdMap[
name] = index + fFirstId;
312 return index + fFirstId;
317 const std::vector<G4double>& ,
318 const std::vector<G4double>& ,
326 <<
"User defined binning is not supported for H2.";
341 if ( xbinScheme !=
"linear" || ybinScheme !=
"linear" ) {
345 <<
"Logarithimc binning is not supported for H2.";
350 h2_booking* h2Booking = GetH2Booking(
id,
false);
353 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
361 if ( fState.GetVerboseL4() )
362 fState.GetVerboseL4()->Message(
"configure",
"H2", hnInfo->
GetName());
371 h2Booking->fNxbins = nxbins;
372 h2Booking->fXmin = xfcn(xmin/xunit);
373 h2Booking->fXmax = xfcn(xmax/xunit);
374 h2Booking->fNybins = nybins;
375 h2Booking->fYmin = yfcn(ymin/yunit);
376 h2Booking->fYmax = yfcn(ymax/yunit);
383 xInfo->
fUnit = xunit;
390 yInfo->
fUnit = yunit;
392 fHnManager->SetActivation(
id,
true);
394 G4String newTitle(h2Booking->fTitle);
397 h2Booking->fTitle = newTitle;
400 if ( fH2Vector.size() ) {
401 tools::hbook::h2* h2 = GetH2(
id);
402 h2->configure(nxbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
403 nybins, yfcn(ymin/yunit), yfcn(ymax/yunit));
411 const std::vector<G4double>& ,
412 const std::vector<G4double>& ,
420 <<
"User defined binning is not supported for H2.";
430 tools::hbook::h2* h2 = GetH2InFunction(
id,
"ScaleH2",
false,
false);
431 if ( ! h2 )
return false;
433 return h2->scale(factor);
441 tools::hbook::h2* h2 = GetH2InFunction(
id,
"FillH2",
true,
false);
442 if ( ! h2 )
return false;
444 if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(
id) ) )
return false;
450 h2->fill(xInfo->
fFcn(xvalue/xInfo->
fUnit),
451 yInfo->
fFcn(yvalue/yInfo->
fUnit), weight);
453 if ( fState.GetVerboseL4() ) {
455 description <<
" id " <<
id
456 <<
" xvalue " << xvalue
457 <<
" xfcn(xvalue/xunit) " << xInfo->
fFcn(xvalue/xInfo->
fUnit)
458 <<
" yvalue " << yvalue
459 <<
" yfcn(yvalue/yunit) " << yInfo->
fFcn(yvalue/yInfo->
fUnit)
460 <<
" weight " << weight;
461 fState.GetVerboseL4()->Message(
"fill",
"H2", description);
468 tools::hbook::h2* ExG4HbookH2Manager::GetH2(
G4int id,
G4bool warn,
469 G4bool onlyIfActive)
const
471 return GetH2InFunction(
id,
"GetH2", warn, onlyIfActive);
477 std::map<G4String, G4int>::const_iterator it = fH2NameIdMap.find(name);
478 if ( it == fH2NameIdMap.end() ) {
480 G4String inFunction =
"ExG4HbookH2Manager::GetH2Id";
482 description <<
" " <<
"histogram " << name <<
" does not exist.";
491 G4int ExG4HbookH2Manager::GetH2Nxbins(
G4int id)
const
493 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2NXbins");
494 if ( ! h2 )
return 0;
496 return fBaseToolsManager.GetNbins(h2->axis_x());
504 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2Xmin");
505 if ( ! h2 )
return 0;
507 return fBaseToolsManager.GetMin(h2->axis_x());
513 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2Xmax");
514 if ( ! h2 )
return 0;
516 return fBaseToolsManager.GetMin(h2->axis_x());
522 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2XWidth",
true,
false);
523 if ( ! h2 )
return 0;
525 return fBaseToolsManager.GetWidth(h2->axis_x());
529 G4int ExG4HbookH2Manager::GetH2Nybins(
G4int id)
const
531 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2NYbins");
532 if ( ! h2 )
return 0;
534 return fBaseToolsManager.GetNbins(h2->axis_y());
542 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2Ymin");
543 if ( ! h2 )
return 0;
545 return fBaseToolsManager.GetMin(h2->axis_y());
551 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2Ymax");
552 if ( ! h2 )
return 0;
554 return fBaseToolsManager.GetMax(h2->axis_y());
560 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2YWidth",
true,
false);
561 if ( ! h2 )
return 0;
563 return fBaseToolsManager.GetWidth(h2->axis_y());
569 h2_booking* h2Booking = GetH2Booking(
id,
false);
572 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
573 G4Exception(
"G4HbookAnalysisManager::SetH2Title()",
578 h2Booking->fTitle = title;
585 tools::hbook::h2* h2 = GetH2InFunction(
id,
"SetH2XAxisTitle");
586 if ( ! h2 )
return false;
594 tools::hbook::h2* h2 = GetH2InFunction(
id,
"SetH2YAxisTitle");
595 if ( ! h2 )
return false;
603 tools::hbook::h2* h2 = GetH2InFunction(
id,
"SetH2ZAxisTitle");
604 if ( ! h2 )
return false;
612 h2_booking* h2Booking = GetH2Booking(
id,
false);
615 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
616 G4Exception(
"G4HbookAnalysisManager::GetH2Title()",
621 return h2Booking->fTitle;
628 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2XAxisTitle");
629 if ( ! h2 )
return "";
637 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2YAxisTitle");
638 if ( ! h2 )
return "";
646 tools::hbook::h2* h2 = GetH2InFunction(
id,
"GetH2ZAxisTitle");
647 if ( ! h2 )
return "";
653 G4bool ExG4HbookH2Manager::SetH2HbookIdOffset(
G4int offset)
655 if ( fH2Vector.size() ) {
658 <<
"Cannot set H2HbookIdOffset as some H2 histogramms already exist.";
659 G4Exception(
"G4HbookAnalysisManager::SetH2HbookIdOffset()",
664 if ( fFirstId + offset < 1 ) {
666 description <<
"The first histogram HBOOK id must be >= 1.";
667 G4Exception(
"G4HbookAnalysisManager::SetH1HbookIdOffset()",
672 fH2HbookIdOffset = offset;
std::ostringstream G4ExceptionDescription
G4double(* G4Fcn)(G4double)
void UpdateTitle(G4String &title, const G4String &unitName, const G4String &fcnName)
G4double GetUnitValue(const G4String &unit)
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
const char * data() const
static const G4double factor
G4Fcn GetFunction(const G4String &fcnName)
G4String & append(const G4String &)
G4BinScheme GetBinScheme(const G4String &binSchemeName)
Definition of the ExG4HbookH2Manager class.
Definition of the ExG4HbookFileManager class.