48 fBaseToolsManager(
"H1"),
58 ExG4HbookH1Manager::~ExG4HbookH1Manager()
64 std::vector<h1_booking*>::iterator it;
65 for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); it++ ) {
77 void ConvertToFloat(
const std::vector<G4double>& doubleVector,
78 std::vector<float>& floatVector)
80 for (
G4int i=0; i<
G4int(doubleVector.size()); ++i)
81 floatVector.push_back((
float)doubleVector[i]);
96 information->
fUnit = unit;
97 information->
fFcn = fcn;
102 h1_booking* CreateH1Booking(
const G4String& title,
111 h1_booking* h1Booking = 0;
118 <<
" User binning scheme setting was ignored." <<
G4endl
119 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
123 h1Booking =
new h1_booking(nbins, fcn(xmin/unit), fcn(xmax/unit));
128 std::vector<G4double> edges;
129 ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, edges);
130 h1Booking =
new h1_booking(edges);
134 h1Booking->fTitle = title;
141 h1_booking* CreateH1Booking(
const G4String& title,
142 const std::vector<G4double>& edges,
150 std::vector<G4double> newEdges;
153 h1_booking* h1Booking =
new h1_booking(newEdges);
156 h1Booking->fTitle = title;
163 void UpdateH1Booking(h1_booking* h1Booking,
179 <<
" User binning scheme setting was ignored." <<
G4endl
180 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
184 h1Booking->fNbins = nbins;
185 h1Booking->fXmin = fcn(xmin/unit);
186 h1Booking->fXmax = fcn(xmax/unit);
190 ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, h1Booking->fEdges);
197 void UpdateH1Booking(h1_booking* h1Booking,
198 const std::vector<G4double>& edges,
212 void ConfigureHbookH1(tools::hbook::h1* h1,
227 <<
" User binning scheme setting was ignored." <<
G4endl
228 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
232 h1->configure(nbins, fcn(xmin/unit), fcn(xmax/unit));
236 std::vector<G4double> edges;
237 ComputeEdges(nbins, xmin, xmax, unit, fcn, binScheme, edges);
239 std::vector<float> fedges;
240 ConvertToFloat(edges, fedges);
242 h1->configure(fedges);
247 void ConfigureHbookH1(tools::hbook::h1* h1,
248 const std::vector<G4double>& edges,
255 std::vector<G4double> newEdges;
259 std::vector<float> newFEdges;
260 ConvertToFloat(newEdges, newFEdges);
262 h1->configure(newFEdges);
272 void ExG4HbookH1Manager::SetH1HbookIdOffset()
276 if ( fH1HbookIdOffset == -1 ) {
278 fH1HbookIdOffset = 0;
280 fH1HbookIdOffset = 1;
282 if ( fH1HbookIdOffset > 0 ) {
284 description <<
"H1 will be defined in HBOOK with ID = G4_firstHistoId + 1";
285 G4Exception(
"ExG4HbookH1Manager::SetH1HbookIdOffset()",
292 void ExG4HbookH1Manager::AddH1Information(
const G4String&
name,
299 fHnManager->AddH1Information(name, unitName, fcnName, unit, fcn, binScheme);
303 G4int ExG4HbookH1Manager::CreateH1FromBooking(h1_booking* h1Booking,
310 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
311 G4String histoPath =
"//PAWC/LUN1/";
312 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
313 tools::hbook::CHCDIR(histoPath.
data(),
" ");
317 G4int index = fH1Vector.size();
318 G4int id = index + fFirstId;
320 info = fHnManager->GetHnInformation(
id,
"CreateH1FromBooking");
322 G4int hbookIndex = fH1HbookIdOffset + index + fFirstId;
325 if ( fState.GetVerboseL4() )
326 fState.GetVerboseL4()->Message(
"create from booking",
"h1", info->
GetName());
330 tools::hbook::h1* h1 = 0;
331 if ( ! h1Booking->fEdges.size() ) {
332 h1 =
new tools::hbook::h1(
333 hbookIndex, h1Booking->fTitle,
334 h1Booking->fNbins, h1Booking->fXmin, h1Booking->fXmax);
338 std::vector<float> newEdges;
339 ConvertToFloat(h1Booking->fEdges, newEdges);
341 h1 =
new tools::hbook::h1(hbookIndex, h1Booking->fTitle, newEdges);
344 fH1Vector.push_back(h1);
347 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
349 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
354 if ( fState.GetVerboseL3() ) {
356 description <<
" name : " << info->
GetName() <<
" hbook index : " << hbookIndex;
357 fState.GetVerboseL3()->Message(
"create from booking",
"h1", description);
365 G4int ExG4HbookH1Manager::RegisterH1Booking(
const G4String& name,
366 h1_booking* h1Booking)
369 G4int index = fH1BookingVector.size();
370 fH1BookingVector.push_back(h1Booking);
371 fH1NameIdMap[
name] = index + fFirstId;
376 return index + fFirstId;
380 void ExG4HbookH1Manager::BeginCreateH1(
const G4String& name)
383 if ( fState.GetVerboseL4() )
384 fState.GetVerboseL4()->Message(
"create",
"H1", name);
388 SetH1HbookIdOffset();
392 G4int ExG4HbookH1Manager::FinishCreateH1(
393 const G4String& name, h1_booking* h1Booking,
398 G4int id = RegisterH1Booking(name, h1Booking);
401 AddH1Information(name, unitName, fcnName, binScheme);
404 if ( fFileManager->IsFile() ) {
405 CreateH1FromBooking(h1Booking);
409 if ( fState.GetVerboseL2() ) {
410 G4int hbookIndex = fH1HbookIdOffset + id;
412 description <<
" name : " << name <<
" hbook index : " << hbookIndex;
413 fState.GetVerboseL2()->Message(
"create",
"H1", description);
421 G4bool ExG4HbookH1Manager::BeginSetH1(
423 h1_booking* h1Booking,
426 h1Booking = GetH1Booking(
id,
false);
429 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
435 info = fHnManager->GetHnInformation(
id,
"SetH1");
437 if ( fState.GetVerboseL4() )
438 fState.GetVerboseL4()->Message(
"configure",
"H1", info->
GetName());
445 G4bool ExG4HbookH1Manager::FinishSetH1(
453 UpdateH1Information(info, unitName, fcnName, binScheme);
456 fHnManager->SetActivation(
id,
true);
463 void ExG4HbookH1Manager::CreateH1sFromBooking()
469 if ( fH1Vector.size() || ( fH1BookingVector.size() == 0 ) )
return;
472 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
473 G4String histoPath =
"//PAWC/LUN1/";
474 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
475 tools::hbook::CHCDIR(histoPath.
data(),
" ");
479 std::vector<h1_booking*>::const_iterator it;
480 for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); ++it) {
481 CreateH1FromBooking(*it,
false);
485 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
487 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
492 void ExG4HbookH1Manager::Reset()
497 std::vector<tools::hbook::h1*>::iterator it;
498 for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
507 h1_booking* ExG4HbookH1Manager::GetH1Booking(
G4int id,
G4bool warn)
const
509 G4int index =
id - fFirstId;
510 if ( index < 0 || index >=
G4int(fH1BookingVector.size()) ) {
513 description <<
" " <<
"histo " <<
id <<
" does not exist.";
514 G4Exception(
"G4HbookAnalysisManager::GetH1Booking()",
520 return fH1BookingVector[index];
528 G4bool ExG4HbookH1Manager::WriteOnAscii(std::ofstream& output)
536 for (
G4int i=0; i<
G4int(fH1Vector.size()); ++i ) {
537 G4int id = i + fFirstId;
539 = fHnManager->GetHnInformation(
id,
"WriteOnAscii");
542 tools::hbook::h1* h1 = fH1Vector[i];
545 if ( fState.GetVerboseL3() )
546 fState.GetVerboseL3()->Message(
"write on ascii",
"h1", info->
GetName());
549 output <<
"\n 1D histogram " <<
id <<
": " << h1->title()
550 <<
"\n \n \t X \t\t Y" <<
G4endl;
552 for (
G4int j=0; j<
G4int(h1->axis().bins()); ++j) {
553 output <<
" " << j <<
"\t"
554 << h1->axis().bin_center(j) <<
"\t"
555 << h1->bin_height(j) <<
G4endl;
563 tools::hbook::h1* ExG4HbookH1Manager::GetH1InFunction(
G4int id,
565 G4bool onlyIfActive)
const
567 G4int index =
id - fFirstId;
568 if ( index < 0 || index >=
G4int(fH1Vector.size()) ) {
570 G4String inFunction =
"ExG4HbookH1Manager::";
571 inFunction += functionName;
573 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
580 if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(
id) ) ) {
584 return fH1Vector[index];
592 G4int ExG4HbookH1Manager::CreateH1(
603 h1_booking* h1Booking
604 = CreateH1Booking(title, nbins, xmin, xmax, unitName, fcnName, binScheme);
606 return FinishCreateH1(name, h1Booking, unitName, fcnName, binScheme);
610 G4int ExG4HbookH1Manager::CreateH1(
612 const std::vector<G4double>& edges,
619 h1_booking* h1Booking
620 = CreateH1Booking(title, edges, unitName, fcnName);
622 return FinishCreateH1(name, h1Booking, unitName, fcnName,
kUserBinScheme);
633 h1_booking* h1Booking = 0;
636 if ( ! BeginSetH1(
id, h1Booking, info) )
return false;
641 UpdateH1Booking(h1Booking,
642 nbins, xmin, xmax, unitName, fcnName, binScheme);
645 if ( fH1Vector.size() ) {
646 tools::hbook::h1* h1 = GetH1(
id);
647 ConfigureHbookH1(h1, nbins, xmin, xmax, unitName, fcnName, binScheme);
650 return FinishSetH1(
id, info, unitName, fcnName, binScheme);
655 const std::vector<G4double>& edges,
659 h1_booking* h1Booking = 0;
662 if ( ! BeginSetH1(
id, h1Booking, info) )
return false;
665 UpdateH1Booking(h1Booking, edges, unitName, fcnName);
668 if ( fH1Vector.size() ) {
669 tools::hbook::h1* h1 = GetH1(
id);
670 ConfigureHbookH1(h1, edges, unitName, fcnName);
680 tools::hbook::h1* h1 = GetH1InFunction(
id,
"ScaleH1",
false,
false);
681 if ( ! h1 )
return false;
683 return h1->scale(factor);
689 tools::hbook::h1* h1 = GetH1InFunction(
id,
"FillH1",
true,
false);
690 if ( ! h1 )
return false;
692 if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(
id) ) ) {
699 h1->fill(info->
fFcn(value/info->
fUnit), weight);
701 if ( fState.GetVerboseL4() ) {
703 description <<
" id " <<
id <<
" value " << value
704 <<
" fcn(value/unit) " << info->
fFcn(value/info->
fUnit)
705 <<
" weight " << weight;
706 fState.GetVerboseL4()->Message(
"fill",
"H1", description);
713 tools::hbook::h1* ExG4HbookH1Manager::GetH1(
G4int id,
G4bool warn,
714 G4bool onlyIfActive)
const
716 return GetH1InFunction(
id,
"GetH1", warn, onlyIfActive);
722 std::map<G4String, G4int>::const_iterator it = fH1NameIdMap.find(name);
723 if ( it == fH1NameIdMap.end() ) {
725 G4String inFunction =
"ExG4HbookH1Manager::GetH1Id";
727 description <<
" " <<
"histogram " << name <<
" does not exist.";
736 G4int ExG4HbookH1Manager::GetH1Nbins(
G4int id)
const
738 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1Nbins");
739 if ( ! h1 )
return 0;
741 return fBaseToolsManager.GetNbins(h1->axis());
749 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1Xmin");
750 if ( ! h1 )
return 0;
752 return fBaseToolsManager.GetMin(h1->axis());
758 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1Xmax");
759 if ( ! h1 )
return 0;
761 return fBaseToolsManager.GetMax(h1->axis());
767 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1XWidth",
true,
false);
768 if ( ! h1 )
return 0;
770 return fBaseToolsManager.GetWidth(h1->axis());
776 h1_booking* h1Booking = GetH1Booking(
id,
false);
779 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
780 G4Exception(
"G4HbookAnalysisManager::SetH1Title()",
785 h1Booking->fTitle = title;
792 tools::hbook::h1* h1 = GetH1InFunction(
id,
"SetH1XAxisTitle");
793 if ( ! h1 )
return false;
801 tools::hbook::h1* h1 = GetH1InFunction(
id,
"SetH1YAxisTitle");
802 if ( ! h1 )
return false;
810 h1_booking* h1Booking = GetH1Booking(
id,
false);
813 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
814 G4Exception(
"G4HbookAnalysisManager::GetH1Title()",
819 return h1Booking->fTitle;
826 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1XAxisTitle");
827 if ( ! h1 )
return "";
835 tools::hbook::h1* h1 = GetH1InFunction(
id,
"GetH1YAxisTitle");
836 if ( ! h1 )
return "";
842 G4bool ExG4HbookH1Manager::SetH1HbookIdOffset(
G4int offset)
844 if ( fH1Vector.size() ) {
847 <<
"Cannot set H1HbookIdOffset as some H1 histogramms already exist.";
848 G4Exception(
"G4HbookAnalysisManager::SetH1HbookIdOffset()",
853 if ( fFirstId + offset < 1 ) {
855 description <<
"The first histogram HBOOK id must be >= 1.";
856 G4Exception(
"G4HbookAnalysisManager::SetH1HbookIdOffset()",
861 fH1HbookIdOffset = 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)
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.