49 fBaseToolsManager(
"H1"),
59 ExG4HbookH1Manager::~ExG4HbookH1Manager()
65 std::vector<h1_booking*>::iterator it;
66 for ( it = fH1BookingVector.begin(); it != fH1BookingVector.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]);
95 h1_booking* CreateH1Booking(
const G4String& title,
104 h1_booking* h1Booking = 0;
111 <<
" User binning scheme setting was ignored." <<
G4endl
112 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
116 h1Booking =
new h1_booking(nbins, fcn(xmin/unit), fcn(xmax/unit));
121 std::vector<G4double> edges;
122 ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, edges);
124 h1Booking =
new h1_booking(edges);
128 h1Booking->fTitle = title;
135 h1_booking* CreateH1Booking(
const G4String& title,
136 const std::vector<G4double>& edges,
144 std::vector<G4double> newEdges;
147 h1_booking* h1Booking =
new h1_booking(newEdges);
150 h1Booking->fTitle = title;
157 void UpdateH1Booking(h1_booking* h1Booking,
172 <<
" User binning scheme setting was ignored." <<
G4endl
173 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
177 h1Booking->fNbins = nbins;
178 h1Booking->fXmin = fcn(xmin/unit);
179 h1Booking->fXmax = fcn(xmax/unit);
183 ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, h1Booking->fEdges);
190 void UpdateH1Booking(h1_booking* h1Booking,
191 const std::vector<G4double>& edges,
205 void ConfigureHbookH1(tools::hbook::h1* h1,
220 <<
" User binning scheme setting was ignored." <<
G4endl
221 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
226 << h1 <<
", " << fcn(xmin/unit) <<
", " << fcn(xmax/unit) <<
G4endl;
227 h1->configure(nbins, fcn(xmin/unit), fcn(xmax/unit));
231 std::vector<G4double> edges;
232 ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, edges);
234 std::vector<float> fedges;
235 ConvertToFloat(edges, fedges);
236 h1->configure(fedges);
241 void ConfigureHbookH1(tools::hbook::h1* h1,
242 const std::vector<G4double>& edges,
249 std::vector<G4double> newEdges;
253 std::vector<float> newFEdges;
254 ConvertToFloat(newEdges, newFEdges);
256 h1->configure(newFEdges);
266 void ExG4HbookH1Manager::SetH1HbookIdOffset()
270 if ( fH1HbookIdOffset == -1 ) {
271 if ( fHnManager->GetFirstId() > 0 )
272 fH1HbookIdOffset = 0;
274 fH1HbookIdOffset = 1;
286 void ExG4HbookH1Manager::AddH1Information(
const G4String&
name,
291 auto hnInformation = fHnManager->AddHnInformation(name, 1);
292 hnInformation->
AddDimension(unitName, fcnName, binScheme);
296 G4int ExG4HbookH1Manager::CreateH1FromBooking(h1_booking* h1Booking,
303 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
304 G4String histoPath =
"//PAWC/LUN1/";
305 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
306 tools::hbook::CHCDIR(histoPath.
data(),
" ");
310 G4int index = fH1Vector.size();
311 G4int id = index + fHnManager->GetFirstId();
313 info = fHnManager->GetHnInformation(
id,
"CreateH1FromBooking");
315 G4int hbookIndex = fH1HbookIdOffset + index + fHnManager->GetFirstId();
318 if ( fState.GetVerboseL4() )
319 fState.GetVerboseL4()->Message(
"create from booking",
"h1", info->
GetName());
323 tools::hbook::h1* h1 = 0;
324 if ( ! h1Booking->fEdges.size() ) {
325 h1 =
new tools::hbook::h1(
326 hbookIndex, h1Booking->fTitle,
327 h1Booking->fNbins, h1Booking->fXmin, h1Booking->fXmax);
331 std::vector<float> newEdges;
332 ConvertToFloat(h1Booking->fEdges, newEdges);
334 h1 =
new tools::hbook::h1(hbookIndex, h1Booking->fTitle, newEdges);
337 fH1Vector.push_back(h1);
344 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
346 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
351 if ( fState.GetVerboseL3() ) {
353 description <<
" name : " << info->
GetName() <<
" hbook index : " << hbookIndex;
354 fState.GetVerboseL3()->Message(
"create from booking",
"h1", description);
362 G4int ExG4HbookH1Manager::RegisterH1Booking(
const G4String& name,
363 h1_booking* h1Booking)
366 G4int index = fH1BookingVector.size();
367 fH1BookingVector.push_back(h1Booking);
368 fH1NameIdMap[
name] = index + fHnManager->GetFirstId();
370 return index + fHnManager->GetFirstId();
374 void ExG4HbookH1Manager::BeginCreateH1(
const G4String& name)
377 if ( fState.GetVerboseL4() )
378 fState.GetVerboseL4()->Message(
"create",
"H1", name);
382 SetH1HbookIdOffset();
386 G4int ExG4HbookH1Manager::FinishCreateH1(
387 const G4String& name, h1_booking* h1Booking,
392 G4int id = RegisterH1Booking(name, h1Booking);
395 AddH1Information(name, unitName, fcnName, binScheme);
398 if ( fFileManager->IsFile() ) {
399 CreateH1FromBooking(h1Booking);
403 if ( fState.GetVerboseL2() ) {
404 G4int hbookIndex = fH1HbookIdOffset + id;
406 description <<
" name : " << name <<
" hbook index : " << hbookIndex;
407 fState.GetVerboseL2()->Message(
"create",
"H1", description);
415 G4bool ExG4HbookH1Manager::FinishSetH1(
423 UpdateH1Information(info, unitName, fcnName, binScheme);
426 fHnManager->SetActivation(
id,
true);
433 void ExG4HbookH1Manager::CreateH1sFromBooking()
439 if ( fH1Vector.size() || ( fH1BookingVector.size() == 0 ) )
return;
442 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
443 G4String histoPath =
"//PAWC/LUN1/";
444 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
445 tools::hbook::CHCDIR(histoPath.
data(),
" ");
449 std::vector<h1_booking*>::const_iterator it;
450 for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); ++it) {
451 CreateH1FromBooking(*it,
false);
455 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
457 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
462 void ExG4HbookH1Manager::Reset()
467 std::vector<tools::hbook::h1*>::iterator it;
468 for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
477 h1_booking* ExG4HbookH1Manager::GetH1Booking(
G4int id,
G4bool warn)
const
479 G4int index =
id - fHnManager->GetFirstId();
480 if ( index < 0 || index >=
G4int(fH1BookingVector.size()) ) {
483 description <<
" " <<
"histo " <<
id <<
" does not exist.";
490 return fH1BookingVector[index];
498 G4bool ExG4HbookH1Manager::WriteOnAscii(std::ofstream& output)
506 for (
G4int i=0; i<
G4int(fH1Vector.size()); ++i ) {
507 G4int id = i + fHnManager->GetFirstId();
509 = fHnManager->GetHnInformation(
id,
"WriteOnAscii");
512 tools::hbook::h1* h1 = fH1Vector[i];
515 if ( fState.GetVerboseL3() )
516 fState.GetVerboseL3()->Message(
"write on ascii",
"h1", info->
GetName());
519 output <<
"\n 1D histogram " <<
id <<
": " << h1->title()
520 <<
"\n \n \t X \t\t Y" <<
G4endl;
522 for (
G4int j=0; j<
G4int(h1->axis().bins()); ++j) {
523 output <<
" " << j <<
"\t"
524 << h1->axis().bin_center(j) <<
"\t"
525 << h1->bin_height(j) <<
G4endl;
533 tools::hbook::h1* ExG4HbookH1Manager::GetH1InFunction(
G4int id,
535 G4bool onlyIfActive)
const
537 G4int index =
id - fHnManager->GetFirstId();
538 if ( index < 0 || index >=
G4int(fH1Vector.size()) ) {
540 G4String inFunction =
"ExG4HbookH1Manager::";
541 inFunction += functionName;
543 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
550 if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(
id) ) ) {
554 return fH1Vector[index];
562 G4int ExG4HbookH1Manager::CreateH1(
573 h1_booking* h1Booking
574 = CreateH1Booking(title, nbins, xmin, xmax, unitName, fcnName, binScheme);
576 return FinishCreateH1(name, h1Booking, unitName, fcnName, binScheme);
580 G4int ExG4HbookH1Manager::CreateH1(
582 const std::vector<G4double>& edges,
589 h1_booking* h1Booking
590 = CreateH1Booking(title, edges, unitName, fcnName);
603 h1_booking* h1Booking = GetH1Booking(
id,
false);
606 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
614 if ( fState.GetVerboseL4() )
615 fState.GetVerboseL4()->Message(
"configure",
"H1", info->
GetName());
621 UpdateH1Booking(h1Booking,
622 nbins, xmin, xmax, unitName, fcnName, binScheme);
625 if ( fH1Vector.size() ) {
626 tools::hbook::h1* h1 = GetH1(
id);
627 ConfigureHbookH1(h1, nbins, xmin, xmax, unitName, fcnName, binScheme);
630 return FinishSetH1(
id, info, unitName, fcnName, binScheme);
635 const std::vector<G4double>& edges,
639 h1_booking* h1Booking = GetH1Booking(
id,
false);
642 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
650 if ( fState.GetVerboseL4() )
651 fState.GetVerboseL4()->Message(
"configure",
"H1", info->
GetName());
655 UpdateH1Booking(h1Booking, edges, unitName, fcnName);
658 if ( fH1Vector.size() ) {
659 tools::hbook::h1* h1 = GetH1(
id);
660 ConfigureHbookH1(h1, edges, unitName, fcnName);
670 tools::hbook::h1* h1 = GetH1InFunction(
id,
"ScaleH1",
false,
false);
671 if ( ! h1 )
return false;
673 return h1->scale(factor);
679 tools::hbook::h1* h1 = GetH1InFunction(
id,
"FillH1",
true,
false);
680 if ( ! h1 )
return false;
682 if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(
id) ) ) {
689 h1->fill(info->
fFcn(value/info->
fUnit), weight);
691 if ( fState.GetVerboseL4() ) {
693 description <<
" id " <<
id <<
" value " << value
694 <<
" fcn(value/unit) " << info->
fFcn(value/info->
fUnit)
695 <<
" weight " << weight;
696 fState.GetVerboseL4()->Message(
"fill",
"H1", description);
703 tools::hbook::h1* ExG4HbookH1Manager::GetH1(
G4int id,
G4bool warn,
704 G4bool onlyIfActive)
const
706 return GetH1InFunction(
id,
"GetH1", warn, onlyIfActive);
712 std::map<G4String, G4int>::const_iterator it = fH1NameIdMap.find(name);
713 if ( it == fH1NameIdMap.end() ) {
715 G4String inFunction =
"ExG4HbookH1Manager::GetH1Id";
717 description <<
" " <<
"histogram " << name <<
" does not exist.";
726 G4int ExG4HbookH1Manager::GetH1Nbins(
G4int id)
const
728 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1Nbins");
729 if ( ! h1 )
return 0;
731 return fBaseToolsManager.GetNbins(h1->axis());
739 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1Xmin");
740 if ( ! h1 )
return 0;
742 return fBaseToolsManager.GetMin(h1->axis());
748 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1Xmax");
749 if ( ! h1 )
return 0;
751 return fBaseToolsManager.GetMax(h1->axis());
757 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1XWidth",
true,
false);
758 if ( ! h1 )
return 0;
760 return fBaseToolsManager.GetWidth(h1->axis());
766 h1_booking* h1Booking = GetH1Booking(
id,
false);
769 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
775 h1Booking->fTitle = title;
782 h1_booking* h1Booking = GetH1Booking(
id,
false);
785 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
792 h1Booking->fXAxisTitle = title;
795 tools::hbook::h1* h1 = GetH1InFunction(
id,
"SetH1XAxisTitle",
false,
false);
796 if ( ! h1 )
return true;
804 h1_booking* h1Booking = GetH1Booking(
id,
false);
807 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
814 h1Booking->fYAxisTitle = title;
817 tools::hbook::h1* h1 = GetH1InFunction(
id,
"SetH1YAxisTitle",
false,
false);
818 if ( ! h1 )
return true;
826 h1_booking* h1Booking = GetH1Booking(
id,
false);
829 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
835 return h1Booking->fTitle;
842 h1_booking* h1Booking = GetH1Booking(
id,
false);
845 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
851 return h1Booking->fXAxisTitle;
857 h1_booking* h1Booking = GetH1Booking(
id,
false);
860 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
866 return h1Booking->fYAxisTitle;
870 G4bool ExG4HbookH1Manager::SetH1HbookIdOffset(
G4int offset)
872 if ( fH1Vector.size() ) {
875 <<
"Cannot set H1HbookIdOffset as some H1 histogramms already exist.";
876 G4Exception(
"G4HbookH1Manager::SetH1HbookIdOffset()",
881 if ( fHnManager->GetFirstId() + offset < 1 ) {
883 description <<
"The first histogram HBOOK id must be >= 1.";
884 G4Exception(
"G4HbookH1Manager::SetH1HbookIdOffset()",
889 fH1HbookIdOffset = 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)
G4GLOB_DLL std::ostream G4cout
G4double GetUnitValue(const G4String &unit)
Definition of the ExG4HbookH1Manager class.
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.