File indexing completed on 2025-01-18 09:58:56
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031 #ifndef G4PlotManager_h
0032 #define G4PlotManager_h 1
0033
0034 #include "G4AnalysisManagerState.hh"
0035 #include "G4PlotParameters.hh"
0036 #include "G4HnInformation.hh"
0037
0038 #include "tools/viewplot"
0039
0040 #include <vector>
0041 #include <memory>
0042 #include <string_view>
0043
0044 class G4PlotManager
0045 {
0046 public:
0047 explicit G4PlotManager(const G4AnalysisManagerState& state);
0048 ~G4PlotManager() = default;
0049
0050
0051 G4PlotManager() = delete;
0052 G4PlotManager(const G4PlotManager& rhs) = delete;
0053 G4PlotManager& operator=(const G4PlotManager& rhs) = delete;
0054
0055 public:
0056
0057 G4bool OpenFile(const G4String& fileName);
0058 template <typename HT>
0059 G4bool PlotAndWrite(const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector);
0060 G4bool CloseFile();
0061
0062 private:
0063
0064 G4int GetNofPlotsPerPage() const;
0065 G4bool WritePage();
0066
0067
0068 static constexpr std::string_view fkClass { "G4PlotManager" };
0069
0070
0071 const G4AnalysisManagerState& fState;
0072 G4PlotParameters fPlotParameters;
0073 std::unique_ptr<tools::viewplot> fViewer;
0074 G4String fFileName;
0075 };
0076
0077
0078
0079
0080 inline G4int G4PlotManager::GetNofPlotsPerPage() const
0081 { return fPlotParameters.GetColumns()*fPlotParameters.GetRows(); }
0082
0083
0084
0085 template <typename HT>
0086 inline G4bool G4PlotManager::PlotAndWrite(
0087 const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector)
0088 {
0089 if ( ! hnVector.size() ) return true;
0090
0091 fViewer->plots().init_sg();
0092
0093 fViewer->set_cols_rows(fPlotParameters.GetColumns(), fPlotParameters.GetRows());
0094 fViewer->plots().set_current_plotter(0);
0095
0096 auto result = true;
0097 auto isWriteNeeded = false;
0098
0099 for (const auto& [ht, info] : hnVector) {
0100 G4bool plotting = info->GetPlotting();
0101 G4bool activation = info->GetActivation();
0102 G4String name = info->GetName();
0103
0104
0105
0106 if ( ( ! plotting ) ||
0107 ( fState.GetIsActivation() && ( ! activation ) ) ||
0108 ( info->GetDeleted() ) ) continue;
0109
0110
0111 fViewer->plot(*ht);
0112 fViewer->set_current_plotter_style(fPlotParameters.GetStyle());
0113
0114
0115 tools::sg::plotter& plotter = fViewer->plots().current_plotter();
0116
0117 plotter.bins_style(0).color = tools::colorf_blue();
0118
0119
0120 G4String title;
0121 if ( ht->annotation(tools::histo::key_axis_x_title(), title) ) {
0122 plotter.x_axis().title = title;
0123 }
0124 if ( ht->annotation(tools::histo::key_axis_y_title(), title) ) {
0125 plotter.y_axis().title = title;
0126 }
0127 if ( ht->annotation(tools::histo::key_axis_z_title(), title) ) {
0128 plotter.z_axis().title = title;
0129 }
0130
0131 #ifndef TOOLS_USE_FREETYPE
0132 plotter.set_encoding_none();
0133 #endif
0134
0135
0136 if ( info->GetIsLogAxis(G4Analysis::kX) ) {
0137 plotter.x_axis().labels_style().encoding = "PAW";
0138 plotter.x_axis_is_log = true;
0139 }
0140 if ( info->GetIsLogAxis(G4Analysis::kY) ) {
0141 plotter.y_axis().labels_style().encoding = "PAW";
0142 plotter.y_axis_is_log = true;
0143 }
0144 if ( info->GetIsLogAxis(G4Analysis::kZ) ) {
0145 plotter.z_axis().labels_style().encoding = "PAW";
0146 plotter.z_axis_is_log = true;
0147 }
0148 isWriteNeeded = true;
0149
0150 fState.Message(G4Analysis::kVL3, "plotting", "hd|pd", name);
0151
0152
0153 if ( G4int(fViewer->plots().current_index()) == (GetNofPlotsPerPage() - 1) ) {
0154 result &= WritePage();
0155 isWriteNeeded = false;
0156 }
0157
0158
0159 fViewer->plots().next();
0160 }
0161
0162
0163 if ( isWriteNeeded ) {
0164 result &= WritePage();
0165 }
0166
0167
0168 return result;
0169 }
0170
0171 #endif