46 const G4int ExG4HbookP1Manager::fgkDefaultP1HbookIdOffset = 201;
52 fBaseToolsManager(
"P1"),
62 ExG4HbookP1Manager::~ExG4HbookP1Manager()
68 std::vector<p1_booking*>::iterator it;
69 for ( it = fP1BookingVector.begin(); it != fP1BookingVector.end(); it++ ) {
81 void ConvertToFloat(
const std::vector<G4double>& doubleVector,
82 std::vector<float>& floatVector)
84 for (
G4int i=0; i<
G4int(doubleVector.size()); ++i)
85 floatVector.push_back((
float)doubleVector[i]);
101 p1_booking* CreateP1Booking(
const G4String& title,
115 p1_booking* p1Booking = 0;
122 <<
" User binning scheme setting was ignored." <<
G4endl
123 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
127 p1Booking =
new p1_booking(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
128 yfcn(ymin/yunit), yfcn(ymax/yunit));
133 std::vector<G4double> edges;
134 ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, edges);
135 p1Booking =
new p1_booking(edges, yfcn(ymin/yunit), yfcn(ymax/yunit));
139 p1Booking->fTitle = title;
140 UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
146 p1_booking* CreateP1Booking(
const G4String& title,
147 const std::vector<G4double>& edges,
160 std::vector<G4double> newEdges;
163 p1_booking* p1Booking =
new p1_booking(newEdges, yfcn(ymin/yunit), yfcn(ymax/yunit));
166 p1Booking->fTitle = title;
167 UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
173 void UpdateP1Booking(p1_booking* p1Booking,
193 <<
" User binning scheme setting was ignored." <<
G4endl
194 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
198 p1Booking->fNbins = nbins;
199 p1Booking->fXmin = xfcn(xmin/xunit);
200 p1Booking->fXmax = xfcn(xmax/xunit);
201 p1Booking->fYmin = yfcn(ymin/yunit);
202 p1Booking->fYmax = yfcn(ymax/yunit);
206 ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, p1Booking->fEdges);
207 p1Booking->fYmin = yfcn(ymin/yunit);
208 p1Booking->fYmax = yfcn(ymax/yunit);
211 UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
215 void UpdateP1Booking(p1_booking* p1Booking,
216 const std::vector<G4double>& edges,
230 p1Booking->fYmin = yfcn(ymin/yunit);
231 p1Booking->fYmax = yfcn(ymax/yunit);
233 UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
237 void ConfigureHbookP1(tools::hbook::p1* p1,
257 <<
" User binning scheme setting was ignored." <<
G4endl
258 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
263 p1->configure(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
264 yfcn(ymin/yunit), yfcn(ymax/yunit));
268 std::vector<G4double> edges;
269 ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, edges);
271 std::vector<float> fedges;
272 ConvertToFloat(edges, fedges);
280 void ConfigureHbookP1(tools::hbook::p1* ,
281 const std::vector<G4double>& edges,
293 std::vector<G4double> newEdges;
297 std::vector<float> newFEdges;
298 ConvertToFloat(newEdges, newFEdges);
311 void ExG4HbookP1Manager::SetP1HbookIdOffset()
315 if ( fP1HbookIdOffset == -1 ) {
316 if ( fHnManager->GetFirstId() > 0 )
317 fP1HbookIdOffset = fgkDefaultP1HbookIdOffset - 1;
319 fP1HbookIdOffset = fgkDefaultP1HbookIdOffset;
329 void ExG4HbookP1Manager::AddP1Information(
const G4String&
name,
336 auto hnInformation = fHnManager->AddHnInformation(name, 2);
337 hnInformation->
AddDimension(xunitName, xfcnName, xbinScheme);
342 G4int ExG4HbookP1Manager::CreateP1FromBooking(p1_booking* p1Booking,
349 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
350 G4String histoPath =
"//PAWC/LUN1/";
351 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
352 tools::hbook::CHCDIR(histoPath.
data(),
" ");
356 G4int index = fP1Vector.size();
357 G4int id = index + fHnManager->GetFirstId();
359 info = fHnManager->GetHnInformation(
id,
"CreateP1FromBooking");
361 G4int hbookIndex = fP1HbookIdOffset + index + fHnManager->GetFirstId();
364 if ( fState.GetVerboseL4() )
365 fState.GetVerboseL4()->Message(
"create from booking",
"p1", info->
GetName());
369 tools::hbook::p1* p1 = 0;
370 if ( ! p1Booking->fEdges.size() ) {
371 p1 =
new tools::hbook::p1(
372 hbookIndex, p1Booking->fTitle,
373 p1Booking->fNbins, p1Booking->fXmin, p1Booking->fXmax,
374 p1Booking->fYmin, p1Booking->fYmax);
378 std::vector<float> newEdges;
379 ConvertToFloat(p1Booking->fEdges, newEdges);
386 fP1Vector.push_back(p1);
393 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
395 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
400 if ( fState.GetVerboseL3() ) {
402 description <<
" name : " << info->
GetName() <<
" hbook index : " << hbookIndex;
403 fState.GetVerboseL3()->Message(
"create from booking",
"p1", description);
411 G4int ExG4HbookP1Manager::RegisterP1Booking(
const G4String& name,
412 p1_booking* p1Booking)
415 G4int index = fP1BookingVector.size();
416 fP1BookingVector.push_back(p1Booking);
417 fP1NameIdMap[
name] = index + fHnManager->GetFirstId();
419 return index + fHnManager->GetFirstId();
423 void ExG4HbookP1Manager::BeginCreateP1(
const G4String& name)
426 if ( fState.GetVerboseL4() )
427 fState.GetVerboseL4()->Message(
"create",
"P1", name);
431 SetP1HbookIdOffset();
435 G4int ExG4HbookP1Manager::FinishCreateP1(
436 const G4String& name, p1_booking* p1Booking,
444 G4int id = RegisterP1Booking(name, p1Booking);
447 AddP1Information(name, xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
450 if ( fFileManager->IsFile() ) {
451 CreateP1FromBooking(p1Booking);
455 if ( fState.GetVerboseL2() ) {
456 G4int hbookIndex = fP1HbookIdOffset + id;
458 description <<
" name : " << name <<
" hbook index : " << hbookIndex;
459 fState.GetVerboseL2()->Message(
"create",
"P1", description);
467 G4bool ExG4HbookP1Manager::FinishSetP1(
477 UpdateP1Information(info, xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
480 fHnManager->SetActivation(
id,
true);
487 void ExG4HbookP1Manager::CreateP1sFromBooking()
493 if ( fP1Vector.size() || ( fP1BookingVector.size() == 0 ) )
return;
496 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
497 G4String histoPath =
"//PAWC/LUN1/";
498 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
499 tools::hbook::CHCDIR(histoPath.
data(),
" ");
503 std::vector<p1_booking*>::const_iterator it;
504 for ( it = fP1BookingVector.begin(); it != fP1BookingVector.end(); ++it) {
505 CreateP1FromBooking(*it,
false);
509 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
511 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
516 void ExG4HbookP1Manager::Reset()
531 p1_booking* ExG4HbookP1Manager::GetP1Booking(
G4int id,
G4bool warn)
const
533 G4int index =
id - fHnManager->GetFirstId();
534 if ( index < 0 || index >=
G4int(fP1BookingVector.size()) ) {
537 description <<
" " <<
"profile " <<
id <<
" does not exist.";
544 return fP1BookingVector[index];
587 tools::hbook::p1* ExG4HbookP1Manager::GetP1InFunction(
G4int id,
589 G4bool onlyIfActive)
const
591 G4int index =
id - fHnManager->GetFirstId();
592 if ( index < 0 || index >=
G4int(fP1Vector.size()) ) {
594 G4String inFunction =
"ExG4HbookP1Manager::";
595 inFunction += functionName;
597 description <<
" " <<
"profile " <<
id <<
" does not exist.";
604 if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(
id) ) ) {
608 return fP1Vector[index];
616 G4int ExG4HbookP1Manager::CreateP1(
631 p1_booking* p1Booking
632 = CreateP1Booking(title, nbins, xmin, xmax, ymin, ymax,
633 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
635 return FinishCreateP1(name, p1Booking,
636 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
640 G4int ExG4HbookP1Manager::CreateP1(
642 const std::vector<G4double>& edges,
652 p1_booking* p1Booking
653 = CreateP1Booking(title, edges, ymin, ymax,
654 xunitName, yunitName, xfcnName, yfcnName);
656 return FinishCreateP1(name, p1Booking,
669 p1_booking*p1Booking = GetP1Booking(
id,
false);
672 description <<
" " <<
"profile " <<
id <<
" does not exist.";
680 if ( fState.GetVerboseL4() )
681 fState.GetVerboseL4()->Message(
"configure",
"P1", info->
GetName());
687 UpdateP1Booking(p1Booking, nbins, xmin, xmax, ymin, ymax,
688 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
691 if ( fP1Vector.size() ) {
692 tools::hbook::p1* p1 = GetP1(
id);
693 ConfigureHbookP1(p1, nbins, xmin, xmax, ymin, ymax,
694 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
697 return FinishSetP1(
id, info,
698 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
703 const std::vector<G4double>& edges,
708 p1_booking*p1Booking = GetP1Booking(
id,
false);
711 description <<
" " <<
"profile " <<
id <<
" does not exist.";
719 if ( fState.GetVerboseL4() )
720 fState.GetVerboseL4()->Message(
"configure",
"P1", info->
GetName());
724 UpdateP1Booking(p1Booking, edges, ymin, ymax,
725 xunitName, yunitName, xfcnName, yfcnName);
728 if ( fP1Vector.size() ) {
729 tools::hbook::p1* p1 = GetP1(
id);
730 ConfigureHbookP1(p1, edges, ymin, ymax,
731 xunitName, yunitName, xfcnName, yfcnName);
735 FinishSetP1(
id, info,
742 tools::hbook::p1* p1 = GetP1InFunction(
id,
"ScaleP1",
false,
false);
743 if ( ! p1 )
return false;
745 return p1->scale(factor);
752 tools::hbook::p1* p1 = GetP1InFunction(
id,
"FillP1",
true,
false);
753 if ( ! p1 )
return false;
755 if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(
id) ) ) {
761 = fHnManager->GetHnDimensionInformation(
id,
kX,
"FillP1");
763 = fHnManager->GetHnDimensionInformation(
id,
kY,
"FillP1");
765 p1->fill(xInfo->
fFcn(xvalue/xInfo->
fUnit),
766 yInfo->
fFcn(yvalue/yInfo->
fUnit), weight);
768 if ( fState.GetVerboseL4() ) {
770 description <<
" id " <<
id
771 <<
" xvalue " << xvalue
772 <<
" xfcn(xvalue/xunit) " << xInfo->
fFcn(xvalue/xInfo->
fUnit)
773 <<
" yvalue " << yvalue
774 <<
" yfcn(yvalue/yunit) " << yInfo->
fFcn(yvalue/yInfo->
fUnit)
775 <<
" weight " << weight;
776 fState.GetVerboseL4()->Message(
"fill",
"P1", description);
783 tools::hbook::p1* ExG4HbookP1Manager::GetP1(
G4int id,
G4bool warn,
784 G4bool onlyIfActive)
const
786 return GetP1InFunction(
id,
"GetP1", warn, onlyIfActive);
792 std::map<G4String, G4int>::const_iterator it = fP1NameIdMap.find(name);
793 if ( it == fP1NameIdMap.end() ) {
795 G4String inFunction =
"ExG4HbookP1Manager::GetP1Id";
797 description <<
" " <<
"profile " << name <<
" does not exist.";
806 G4int ExG4HbookP1Manager::GetP1Nbins(
G4int id)
const
808 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Nbins");
809 if ( ! p1 )
return 0;
811 return fBaseToolsManager.GetNbins(p1->axis());
819 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Xmin");
820 if ( ! p1 )
return 0;
822 return fBaseToolsManager.GetMin(p1->axis());
828 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Xmax");
829 if ( ! p1 )
return 0;
831 return fBaseToolsManager.GetMax(p1->axis());
837 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1XWidth",
true,
false);
838 if ( ! p1 )
return 0;
840 G4int nbins = p1->axis().bins();
843 description <<
" nbins = 0 (for p1 id = " <<
id <<
").";
849 return fBaseToolsManager.GetWidth(p1->axis());
857 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Ymin",
true,
false);
858 if ( ! p1 )
return 0;
863 G4String inFunction =
"ExG4HbookP1Manager::GetP1Ymin";
865 description <<
"Get function not available.";
873 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Ymax",
true,
false);
874 if ( ! p1 )
return 0;
879 G4String inFunction =
"ExG4HbookP1Manager::GetP1Ymax";
881 description <<
"Get function not available.";
889 p1_booking* p1Booking = GetP1Booking(
id,
false);
892 description <<
" " <<
"profile " <<
id <<
" does not exist.";
898 p1Booking->fTitle = title;
905 p1_booking* p1Booking = GetP1Booking(
id,
false);
908 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
915 p1Booking->fXAxisTitle = title;
918 tools::hbook::p1* p1 = GetP1InFunction(
id,
"SetP1XAxisTitle",
false,
false);
919 if ( ! p1 )
return true;
927 p1_booking* p1Booking = GetP1Booking(
id,
false);
930 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
937 p1Booking->fYAxisTitle = title;
940 tools::hbook::p1* p1 = GetP1InFunction(
id,
"SetP1YAxisTitle",
false,
false);
941 if ( ! p1 )
return true;
949 p1_booking* p1Booking = GetP1Booking(
id,
false);
952 description <<
" " <<
"profile " <<
id <<
" does not exist.";
958 return p1Booking->fTitle;
965 p1_booking* p1Booking = GetP1Booking(
id,
false);
968 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
974 return p1Booking->fXAxisTitle;
980 p1_booking* p1Booking = GetP1Booking(
id,
false);
983 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
989 return p1Booking->fYAxisTitle;
993 G4bool ExG4HbookP1Manager::SetP1HbookIdOffset(
G4int offset)
995 if ( fP1Vector.size() ) {
998 <<
"Cannot set P1HbookIdOffset as some P1 profiles already exist.";
999 G4Exception(
"G4HbookP1Manager::SetP1HbookIdOffset()",
1004 if ( fHnManager->GetFirstId() + offset < 1 ) {
1006 description <<
"The first profile HBOOK id must be >= 1.";
1007 G4Exception(
"G4HbookP1Manager::SetP1HbookIdOffset()",
1012 fP1HbookIdOffset = offset;
G4double(*)(G4double) G4Fcn
std::ostringstream G4ExceptionDescription
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4double unit, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
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 ExG4HbookFileManager class.
Definition of the ExG4HbookP1Manager class.