49 fBaseToolsManager(
"P1"),
59 ExG4HbookP1Manager::~ExG4HbookP1Manager()
65 std::vector<p1_booking*>::iterator it;
66 for ( it = fP1BookingVector.begin(); it != fP1BookingVector.end(); it++ ) {
78 void ConvertToFloat(
const std::vector<G4double>& doubleVector,
79 std::vector<float>& floatVector)
81 for (
G4int i=0; i<
G4int(doubleVector.size()); ++i)
82 floatVector.push_back((
float)doubleVector[i]);
102 xInformation->
fUnit = xunit;
103 xInformation->
fFcn = xfcn;
110 yInformation->
fUnit = yunit;
111 yInformation->
fFcn = yfcn;
116 p1_booking* CreateP1Booking(
const G4String& title,
130 p1_booking* p1Booking = 0;
137 <<
" User binning scheme setting was ignored." <<
G4endl
138 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
142 p1Booking =
new p1_booking(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
143 yfcn(ymin/yunit), yfcn(ymax/yunit));
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));
154 p1Booking->fTitle = title;
155 UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
161 p1_booking* CreateP1Booking(
const G4String& title,
162 const std::vector<G4double>& edges,
175 std::vector<G4double> newEdges;
178 p1_booking* p1Booking =
new p1_booking(newEdges, yfcn(ymin/yunit), yfcn(ymax/yunit));
181 p1Booking->fTitle = title;
182 UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
188 void UpdateP1Booking(p1_booking* p1Booking,
209 <<
" User binning scheme setting was ignored." <<
G4endl
210 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
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);
222 ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, p1Booking->fEdges);
223 p1Booking->fYmin = yfcn(ymin/yunit);
224 p1Booking->fYmax = yfcn(ymax/yunit);
227 UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
231 void UpdateP1Booking(p1_booking* p1Booking,
232 const std::vector<G4double>& edges,
246 p1Booking->fYmin = yfcn(ymin/yunit);
247 p1Booking->fYmax = yfcn(ymax/yunit);
249 UpdateTitle(p1Booking->fTitle, xunitName, xfcnName);
253 void ConfigureHbookP1(tools::hbook::p1* p1,
273 <<
" User binning scheme setting was ignored." <<
G4endl
274 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
279 p1->configure(nbins, xfcn(xmin/xunit), xfcn(xmax/xunit),
280 yfcn(ymin/yunit), yfcn(ymax/yunit));
284 std::vector<G4double> edges;
285 ComputeEdges(nbins, xmin, xmax, xunit, xfcn, xbinScheme, edges);
287 std::vector<float> fedges;
288 ConvertToFloat(edges, fedges);
296 void ConfigureHbookP1(tools::hbook::p1* ,
297 const std::vector<G4double>& edges,
309 std::vector<G4double> newEdges;
313 std::vector<float> newFEdges;
314 ConvertToFloat(newEdges, newFEdges);
327 void ExG4HbookP1Manager::SetP1HbookIdOffset()
331 if ( fP1HbookIdOffset == -1 ) {
333 fP1HbookIdOffset = 0;
335 fP1HbookIdOffset = 1;
337 if ( fP1HbookIdOffset > 0 ) {
339 description <<
"P1 will be defined in HBOOK with ID = G4_firstProfileId + 1";
340 G4Exception(
"ExG4HbookP1Manager::SetP1HbookIdOffset()",
347 void ExG4HbookP1Manager::AddP1Information(
const G4String&
name,
359 ->AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
360 xunit, yunit, xfcn, yfcn,
361 xbinScheme, xbinScheme);
365 G4int ExG4HbookP1Manager::CreateP1FromBooking(p1_booking* p1Booking,
372 if ( fFileManager->GetProfileDirectoryName() !=
"" ) {
373 G4String profilePath =
"//PAWC/LUN1/";
374 profilePath.
append(fFileManager->GetProfileDirectoryName().data());
375 tools::hbook::CHCDIR(profilePath.
data(),
" ");
379 G4int index = fP1Vector.size();
380 G4int id = index + fFirstId;
382 info = fHnManager->GetHnInformation(
id,
"CreateP1FromBooking");
384 G4int hbookIndex = fP1HbookIdOffset + index + fFirstId;
387 if ( fState.GetVerboseL4() )
388 fState.GetVerboseL4()->Message(
"create from booking",
"p1", info->
GetName());
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);
401 std::vector<float> newEdges;
402 ConvertToFloat(p1Booking->fEdges, newEdges);
409 fP1Vector.push_back(p1);
412 if ( fFileManager->GetProfileDirectoryName() !=
"" ) {
414 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
419 if ( fState.GetVerboseL3() ) {
421 description <<
" name : " << info->
GetName() <<
" hbook index : " << hbookIndex;
422 fState.GetVerboseL3()->Message(
"create from booking",
"p1", description);
430 G4int ExG4HbookP1Manager::RegisterP1Booking(
const G4String& name,
431 p1_booking* p1Booking)
434 G4int index = fP1BookingVector.size();
435 fP1BookingVector.push_back(p1Booking);
436 fP1NameIdMap[
name] = index + fFirstId;
441 return index + fFirstId;
445 void ExG4HbookP1Manager::BeginCreateP1(
const G4String& name)
448 if ( fState.GetVerboseL4() )
449 fState.GetVerboseL4()->Message(
"create",
"P1", name);
453 SetP1HbookIdOffset();
457 G4int ExG4HbookP1Manager::FinishCreateP1(
458 const G4String& name, p1_booking* p1Booking,
466 G4int id = RegisterP1Booking(name, p1Booking);
469 AddP1Information(name, xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
472 if ( fFileManager->IsFile() ) {
473 CreateP1FromBooking(p1Booking);
477 if ( fState.GetVerboseL2() ) {
478 G4int hbookIndex = fP1HbookIdOffset + id;
480 description <<
" name : " << name <<
" hbook index : " << hbookIndex;
481 fState.GetVerboseL2()->Message(
"create",
"P1", description);
489 G4bool ExG4HbookP1Manager::BeginSetP1(
491 p1_booking* p1Booking,
494 p1Booking = GetP1Booking(
id,
false);
497 description <<
" " <<
"profile " <<
id <<
" does not exist.";
503 info = fHnManager->GetHnInformation(
id,
"SetP1");
505 if ( fState.GetVerboseL4() )
506 fState.GetVerboseL4()->Message(
"configure",
"P1", info->
GetName());
513 G4bool ExG4HbookP1Manager::FinishSetP1(
523 UpdateP1Information(info, xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
526 fHnManager->SetActivation(
id,
true);
533 void ExG4HbookP1Manager::CreateP1sFromBooking()
539 if ( fP1Vector.size() || ( fP1BookingVector.size() == 0 ) )
return;
542 if ( fFileManager->GetProfileDirectoryName() !=
"" ) {
543 G4String profilePath =
"//PAWC/LUN1/";
544 profilePath.
append(fFileManager->GetProfileDirectoryName().data());
545 tools::hbook::CHCDIR(profilePath.
data(),
" ");
549 std::vector<p1_booking*>::const_iterator it;
550 for ( it = fP1BookingVector.begin(); it != fP1BookingVector.end(); ++it) {
551 CreateP1FromBooking(*it,
false);
555 if ( fFileManager->GetProfileDirectoryName() !=
"" ) {
557 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
562 void ExG4HbookP1Manager::Reset()
567 std::vector<tools::hbook::p1*>::iterator it;
568 for (it = fP1Vector.begin(); it != fP1Vector.end(); it++ ) {
577 p1_booking* ExG4HbookP1Manager::GetP1Booking(
G4int id,
G4bool warn)
const
579 G4int index =
id - fFirstId;
580 if ( index < 0 || index >=
G4int(fP1BookingVector.size()) ) {
583 description <<
" " <<
"profile " <<
id <<
" does not exist.";
584 G4Exception(
"G4HbookAnalysisManager::GetP1Booking()",
590 return fP1BookingVector[index];
633 tools::hbook::p1* ExG4HbookP1Manager::GetP1InFunction(
G4int id,
635 G4bool onlyIfActive)
const
637 G4int index =
id - fFirstId;
638 if ( index < 0 || index >=
G4int(fP1Vector.size()) ) {
640 G4String inFunction =
"ExG4HbookP1Manager::";
641 inFunction += functionName;
643 description <<
" " <<
"profile " <<
id <<
" does not exist.";
650 if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(
id) ) ) {
654 return fP1Vector[index];
662 G4int ExG4HbookP1Manager::CreateP1(
677 p1_booking* p1Booking
678 = CreateP1Booking(title, nbins, xmin, xmax, ymin, ymax,
679 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
681 return FinishCreateP1(name, p1Booking,
682 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
686 G4int ExG4HbookP1Manager::CreateP1(
688 const std::vector<G4double>& edges,
698 p1_booking* p1Booking
699 = CreateP1Booking(title, edges, ymin, ymax,
700 xunitName, yunitName, xfcnName, yfcnName);
702 return FinishCreateP1(name, p1Booking,
715 p1_booking* p1Booking = 0;
718 if ( ! BeginSetP1(
id, p1Booking, info) )
return false;
723 UpdateP1Booking(p1Booking, nbins, xmin, xmax, ymin, ymax,
724 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
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);
733 return FinishSetP1(
id, info,
734 xunitName, yunitName, xfcnName, yfcnName, xbinScheme);
739 const std::vector<G4double>& edges,
744 p1_booking* p1Booking = 0;
747 if ( ! BeginSetP1(
id, p1Booking, info) )
return false;
750 UpdateP1Booking(p1Booking, edges, ymin, ymax,
751 xunitName, yunitName, xfcnName, yfcnName);
754 if ( fP1Vector.size() ) {
755 tools::hbook::p1* p1 = GetP1(
id);
756 ConfigureHbookP1(p1, edges, ymin, ymax,
757 xunitName, yunitName, xfcnName, yfcnName);
761 FinishSetP1(
id, info,
768 tools::hbook::p1* p1 = GetP1InFunction(
id,
"ScaleP1",
false,
false);
769 if ( ! p1 )
return false;
771 return p1->scale(factor);
778 tools::hbook::p1* p1 = GetP1InFunction(
id,
"FillP1",
true,
false);
779 if ( ! p1 )
return false;
781 if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(
id) ) ) {
791 p1->fill(xInfo->
fFcn(xvalue/xInfo->
fUnit),
792 yInfo->
fFcn(yvalue/yInfo->
fUnit), weight);
794 if ( fState.GetVerboseL4() ) {
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);
809 tools::hbook::p1* ExG4HbookP1Manager::GetP1(
G4int id,
G4bool warn,
810 G4bool onlyIfActive)
const
812 return GetP1InFunction(
id,
"GetP1", warn, onlyIfActive);
818 std::map<G4String, G4int>::const_iterator it = fP1NameIdMap.find(name);
819 if ( it == fP1NameIdMap.end() ) {
821 G4String inFunction =
"ExG4HbookP1Manager::GetP1Id";
823 description <<
" " <<
"profile " << name <<
" does not exist.";
832 G4int ExG4HbookP1Manager::GetP1Nbins(
G4int id)
const
834 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Nbins");
835 if ( ! p1 )
return 0;
837 return fBaseToolsManager.GetNbins(p1->axis());
845 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Xmin");
846 if ( ! p1 )
return 0;
848 return fBaseToolsManager.GetMin(p1->axis());
854 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Xmax");
855 if ( ! p1 )
return 0;
857 return fBaseToolsManager.GetMax(p1->axis());
863 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1XWidth",
true,
false);
864 if ( ! p1 )
return 0;
866 G4int nbins = p1->axis().bins();
869 description <<
" nbins = 0 (for p1 id = " <<
id <<
").";
875 return fBaseToolsManager.GetWidth(p1->axis());
883 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Ymin",
true,
false);
884 if ( ! p1 )
return 0;
889 G4String inFunction =
"ExG4HbookP1Manager::GetP1Ymin";
891 description <<
"Get function not available.";
899 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1Ymax",
true,
false);
900 if ( ! p1 )
return 0;
905 G4String inFunction =
"ExG4HbookP1Manager::GetP1Ymax";
907 description <<
"Get function not available.";
915 p1_booking* p1Booking = GetP1Booking(
id,
false);
918 description <<
" " <<
"profile " <<
id <<
" does not exist.";
919 G4Exception(
"G4HbookAnalysisManager::SetP1Title()",
924 p1Booking->fTitle = title;
931 tools::hbook::p1* p1 = GetP1InFunction(
id,
"SetP1XAxisTitle");
932 if ( ! p1 )
return false;
934 p1->add_annotation(tools::hbook::key_axis_x_title(), title);
941 tools::hbook::p1* p1 = GetP1InFunction(
id,
"SetP1YAxisTitle");
942 if ( ! p1 )
return false;
944 p1->add_annotation(tools::hbook::key_axis_y_title(), title);
951 p1_booking* p1Booking = GetP1Booking(
id,
false);
954 description <<
" " <<
"profile " <<
id <<
" does not exist.";
955 G4Exception(
"G4HbookAnalysisManager::GetP1Title()",
960 return p1Booking->fTitle;
967 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1XAxisTitle");
968 if ( ! p1 )
return "";
971 G4bool result = p1->annotation(tools::hbook::key_axis_x_title(), title);
974 description <<
" Failed to get x_axis title for p1 id = " <<
id <<
").";
986 tools::hbook::p1* p1 = GetP1InFunction(
id,
"GetP1YAxisTitle");
987 if ( ! p1 )
return "";
990 G4bool result = p1->annotation(tools::hbook::key_axis_y_title(), title);
993 description <<
" Failed to get y_axis title for p1 id = " <<
id <<
").";
1003 G4bool ExG4HbookP1Manager::SetP1HbookIdOffset(
G4int offset)
1005 if ( fP1Vector.size() ) {
1008 <<
"Cannot set P1HbookIdOffset as some P1 profiles already exist.";
1009 G4Exception(
"G4HbookAnalysisManager::SetP1HbookIdOffset()",
1014 if ( fFirstId + offset < 1 ) {
1016 description <<
"The first profile HBOOK id must be >= 1.";
1017 G4Exception(
"G4HbookAnalysisManager::SetP1HbookIdOffset()",
1022 fP1HbookIdOffset = offset;
std::ostringstream G4ExceptionDescription
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4double unit, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
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 ExG4HbookFileManager class.
Definition of the ExG4HbookP1Manager class.