43 using namespace G4Analysis;
57 ExG4HbookH1Manager::~ExG4HbookH1Manager()
63 std::vector<h1_booking*>::iterator it;
64 for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); it++ ) {
76 void ConvertToFloat(
const std::vector<G4double>& doubleVector,
77 std::vector<float>& floatVector)
79 for (
G4int i=0; i<
G4int(doubleVector.size()); ++i)
80 floatVector.push_back((
float)doubleVector[i]);
95 information->
fXUnit = unit;
96 information->
fYUnit = unit;
97 information->
fXFcn = fcn;
98 information->
fYFcn = fcn;
112 h1_booking* h1Booking = 0;
119 <<
" User binning scheme setting was ignored." <<
G4endl
120 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
124 h1Booking =
new h1_booking(nbins, fcn(xmin), fcn(xmax));
130 std::vector<G4double> edges;
134 h1Booking =
new h1_booking(edges);
138 h1Booking->fTitle =
title;
145 h1_booking* CreateH1Booking(
const G4String& title,
146 const std::vector<G4double>& edges,
153 std::vector<G4double> newEdges;
157 h1_booking* h1Booking =
new h1_booking(newEdges);
161 h1Booking->fTitle =
title;
168 void UpdateH1Booking(h1_booking* h1Booking,
183 <<
" User binning scheme setting was ignored." <<
G4endl
184 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
188 h1Booking->fNbins = nbins;
189 h1Booking->fXmin = fcn(xmin);
190 h1Booking->fXmax = fcn(xmax);
194 ComputeEdges(nbins, xmin, xmax, fcn, binScheme, h1Booking->fEdges);
201 void UpdateH1Booking(h1_booking* h1Booking,
202 const std::vector<G4double>& edges,
228 <<
" User binning scheme setting was ignored." <<
G4endl
229 <<
" Linear binning will be applied with given (nbins, xmin, xmax) values";
233 h1->configure(nbins, fcn(xmin), fcn(xmax));
237 std::vector<G4double> edges;
240 std::vector<float> fedges;
241 ConvertToFloat(edges, fedges);
243 h1->configure(fedges);
249 const std::vector<G4double>& edges,
254 std::vector<G4double> newEdges;
258 std::vector<float> newFEdges;
259 ConvertToFloat(newEdges, newFEdges);
261 h1->configure(newFEdges);
271 void ExG4HbookH1Manager::SetH1HbookIdOffset()
275 if ( fH1HbookIdOffset == -1 ) {
277 fH1HbookIdOffset = 0;
279 fH1HbookIdOffset = 1;
281 if ( fH1HbookIdOffset > 0 ) {
283 description <<
"H1 will be defined in HBOOK with ID = G4_firstHistoId + 1";
284 G4Exception(
"ExG4HbookH1Manager::SetH1HbookIdOffset()",
291 void ExG4HbookH1Manager::AddH1Information(
const G4String&
name,
298 fHnManager->AddH1Information(name, unitName, fcnName, unit, fcn, binScheme);
302 G4int ExG4HbookH1Manager::CreateH1FromBooking(h1_booking* h1Booking,
309 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
310 G4String histoPath =
"//PAWC/LUN1/";
311 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
312 tools::hbook::CHCDIR(histoPath.
data(),
" ");
317 G4int id = index + fFirstId;
319 info = fHnManager->GetHnInformation(
id,
"CreateH1FromBooking");
321 G4int hbookIndex = fH1HbookIdOffset + index + fFirstId;
324 if ( fState.GetVerboseL4() )
325 fState.GetVerboseL4()->Message(
"create from booking",
"h1", info->
fName);
330 if ( ! h1Booking->fEdges.size() ) {
332 hbookIndex, h1Booking->fTitle,
333 h1Booking->fNbins, h1Booking->fXmin, h1Booking->fXmax);
337 std::vector<float> newEdges;
338 ConvertToFloat(h1Booking->fEdges, newEdges);
343 fH1Vector.push_back(h1);
346 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
348 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
353 if ( fState.GetVerboseL3() ) {
355 description <<
" name : " << info->
fName <<
" hbook index : " << hbookIndex;
356 fState.GetVerboseL3()->Message(
"create from booking",
"h1", description);
364 G4int ExG4HbookH1Manager::RegisterH1Booking(
const G4String& name,
365 h1_booking* h1Booking)
368 G4int index = fH1BookingVector.size();
369 fH1BookingVector.push_back(h1Booking);
370 fH1NameIdMap[
name] = index + fFirstId;
375 return index + fFirstId;
379 void ExG4HbookH1Manager::BeginCreateH1(
const G4String& name)
382 if ( fState.GetVerboseL4() )
383 fState.GetVerboseL4()->Message(
"create",
"H1", name);
387 SetH1HbookIdOffset();
391 G4int ExG4HbookH1Manager::FinishCreateH1(
392 const G4String& name, h1_booking* h1Booking,
397 G4int id = RegisterH1Booking(name, h1Booking);
400 AddH1Information(name, unitName, fcnName, binScheme);
403 if ( fFileManager->IsFile() ) {
404 CreateH1FromBooking(h1Booking);
408 if ( fState.GetVerboseL2() ) {
409 G4int hbookIndex = fH1HbookIdOffset + id;
411 description <<
" name : " << name <<
" hbook index : " << hbookIndex;
412 fState.GetVerboseL2()->Message(
"create",
"H1", description);
420 G4bool ExG4HbookH1Manager::BeginSetH1(
422 h1_booking* h1Booking,
425 h1Booking = GetH1Booking(
id,
false);
428 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
434 info = fHnManager->GetHnInformation(
id,
"SetH1");
436 if ( fState.GetVerboseL4() )
437 fState.GetVerboseL4()->Message(
"configure",
"H1", info->
fName);
444 G4bool ExG4HbookH1Manager::FinishSetH1(
452 UpdateH1Information(info, unitName, fcnName, binScheme);
455 fHnManager->SetActivation(
id,
true);
462 void ExG4HbookH1Manager::CreateH1sFromBooking()
468 if ( fH1Vector.size() || ( fH1BookingVector.size() == 0 ) )
return;
471 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
472 G4String histoPath =
"//PAWC/LUN1/";
473 histoPath.
append(fFileManager->GetHistoDirectoryName().data());
474 tools::hbook::CHCDIR(histoPath.
data(),
" ");
478 std::vector<h1_booking*>::const_iterator it;
479 for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); ++it) {
480 CreateH1FromBooking(*it,
false);
484 if ( fFileManager->GetHistoDirectoryName() !=
"" ) {
486 tools::hbook::CHCDIR(
"//PAWC/LUN1",
" ");
496 std::vector<tools::hbook::h1*>::iterator it;
497 for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
506 h1_booking* ExG4HbookH1Manager::GetH1Booking(
G4int id,
G4bool warn)
const
508 G4int index =
id - fFirstId;
509 if ( index < 0 || index >=
G4int(fH1BookingVector.size()) ) {
512 description <<
" " <<
"histo " <<
id <<
" does not exist.";
513 G4Exception(
"G4HbookAnalysisManager::GetH1Booking()",
519 return fH1BookingVector[
index];
527 G4bool ExG4HbookH1Manager::WriteOnAscii(std::ofstream& output)
535 for (
G4int i=0; i<
G4int(fH1Vector.size()); ++i ) {
536 G4int id = i + fFirstId;
538 = fHnManager->GetHnInformation(
id,
"WriteOnAscii");
540 if ( ! info->
fAscii )
continue;
544 if ( fState.GetVerboseL3() )
545 fState.GetVerboseL3()->Message(
"write on ascii",
"h1", info->
fName);
548 output <<
"\n 1D histogram " <<
id <<
": " << h1->title()
549 <<
"\n \n \t X \t\t Y" <<
G4endl;
551 for (
G4int j=0; j<
G4int(h1->axis().bins()); ++j) {
552 output <<
" " << j <<
"\t"
553 << h1->axis().bin_center(j) <<
"\t"
554 << h1->bin_height(j) <<
G4endl;
564 G4bool onlyIfActive)
const
566 G4int index =
id - fFirstId;
567 if ( index < 0 || index >=
G4int(fH1Vector.size()) ) {
569 G4String inFunction =
"ExG4HbookH1Manager::";
570 inFunction += functionName;
572 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
579 if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(
id) ) ) {
583 return fH1Vector[
index];
591 G4int ExG4HbookH1Manager::CreateH1(
602 h1_booking* h1Booking
603 = CreateH1Booking(title, nbins, xmin, xmax, unitName, fcnName, binScheme);
605 return FinishCreateH1(name, h1Booking, unitName, fcnName, binScheme);
609 G4int ExG4HbookH1Manager::CreateH1(
611 const std::vector<G4double>& edges,
618 h1_booking* h1Booking
619 = CreateH1Booking(title, edges, unitName, fcnName);
621 return FinishCreateH1(name, h1Booking, unitName, fcnName,
kUserBinScheme);
632 h1_booking* h1Booking = 0;
635 if ( ! BeginSetH1(
id, h1Booking, info) )
return false;
640 UpdateH1Booking(h1Booking,
641 nbins, xmin, xmax, unitName, fcnName, binScheme);
644 if ( fH1Vector.size() ) {
646 ConfigureHbookH1(h1, nbins, xmin, xmax, fcnName, binScheme);
649 return FinishSetH1(
id, info, unitName, fcnName, binScheme);
654 const std::vector<G4double>& edges,
658 h1_booking* h1Booking = 0;
661 if ( ! BeginSetH1(
id, h1Booking, info) )
return false;
664 UpdateH1Booking(h1Booking, edges, unitName, fcnName);
667 if ( fH1Vector.size() ) {
669 ConfigureHbookH1(h1, edges, fcnName);
680 if ( ! h1 )
return false;
682 return h1->scale(factor);
689 if ( ! h1 )
return false;
691 if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(
id) ) ) {
699 if ( fState.GetVerboseL4() ) {
701 description <<
" id " <<
id <<
" value " <<
value;
702 fState.GetVerboseL4()->Message(
"fill",
"H1", description);
710 G4bool onlyIfActive)
const
712 return GetH1InFunction(
id,
"GetH1", warn, onlyIfActive);
718 std::map<G4String, G4int>::const_iterator it = fH1NameIdMap.find(name);
719 if ( it == fH1NameIdMap.end() ) {
721 G4String inFunction =
"ExG4HbookH1Manager::GetH1Id";
723 description <<
" " <<
"histogram " << name <<
" does not exist.";
732 G4int ExG4HbookH1Manager::GetH1Nbins(
G4int id)
const
735 if ( ! h1 )
return 0;
737 return h1->axis().bins();
746 if ( ! h1 )
return 0;
749 return info->
fXFcn(h1->axis().lower_edge()*info->
fXUnit);
756 if ( ! h1 )
return 0;
759 return info->
fXFcn(h1->axis().upper_edge()*info->
fXUnit);
766 if ( ! h1 )
return 0;
768 G4int nbins = h1->axis().bins();
771 description <<
" nbins = 0 (for h1 id = " <<
id <<
").";
777 G4HnInformation* info = fHnManager->GetHnInformation(
id,
"GetH1XWidth");
778 return ( info->
fXFcn(h1->axis().upper_edge())
779 - info->
fXFcn(h1->axis().lower_edge()))*info->
fXUnit/nbins;
785 h1_booking* h1Booking = GetH1Booking(
id,
false);
788 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
789 G4Exception(
"G4HbookAnalysisManager::SetH1Title()",
794 h1Booking->fTitle =
title;
802 if ( ! h1 )
return false;
804 h1->add_annotation(tools::hbook::key_axis_x_title(), title);
812 if ( ! h1 )
return false;
814 h1->add_annotation(tools::hbook::key_axis_y_title(), title);
821 h1_booking* h1Booking = GetH1Booking(
id,
false);
824 description <<
" " <<
"histogram " <<
id <<
" does not exist.";
825 G4Exception(
"G4HbookAnalysisManager::GetH1Title()",
830 return h1Booking->fTitle;
838 if ( ! h1 )
return "";
841 G4bool result = h1->annotation(tools::hbook::key_axis_x_title(), title);
844 description <<
" Failed to get x_axis title for h1 id = " <<
id <<
").";
857 if ( ! h1 )
return "";
860 G4bool result = h1->annotation(tools::hbook::key_axis_y_title(), title);
863 description <<
" Failed to get y_axis title for h1 id = " <<
id <<
").";
873 G4bool ExG4HbookH1Manager::SetH1HbookIdOffset(
G4int offset)
875 if ( fH1Vector.size() ) {
878 <<
"Cannot set H1HbookIdOffset as some H1 histogramms already exist.";
879 G4Exception(
"G4HbookAnalysisManager::SetH1HbookIdOffset()",
884 if ( fFirstId + offset < 1 ) {
886 description <<
"The first histogram HBOOK id must be >= 1.";
887 G4Exception(
"G4HbookAnalysisManager::SetH1HbookIdOffset()",
892 fH1HbookIdOffset = offset;
std::ostringstream G4ExceptionDescription
G4double(* G4Fcn)(G4double)
G4double G4NeutronHPJENDLHEData::G4double result
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)
ntupleExperimental Reset()
const char * data() const
G4Fcn GetFunction(const G4String &fcnName)
subroutine title(NA, NB, NCA, NCB)
G4String & append(const G4String &)
G4BinScheme GetBinScheme(const G4String &binSchemeName)
const XML_Char XML_Encoding * info
const XML_Char int const XML_Char * value
void ComputeEdges(G4int nbins, G4double xmin, G4double xmax, G4Fcn fcn, G4BinScheme, std::vector< G4double > &edges)
Definition of the ExG4HbookFileManager class.