Geant4 11.4.0
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PlotManager Class Reference

#include <G4PlotManager.hh>

Public Member Functions

 G4PlotManager (const G4AnalysisManagerState &state)
 ~G4PlotManager ()=default
 G4PlotManager ()=delete
 G4PlotManager (const G4PlotManager &rhs)=delete
G4PlotManageroperator= (const G4PlotManager &rhs)=delete
G4bool OpenFile (const G4String &fileName)
template<typename HT>
G4bool PlotAndWrite (const std::vector< std::pair< HT *, G4HnInformation * > > &hnVector)
G4bool CloseFile ()

Detailed Description

Definition at line 44 of file G4PlotManager.hh.

Constructor & Destructor Documentation

◆ G4PlotManager() [1/3]

G4PlotManager::G4PlotManager ( const G4AnalysisManagerState & state)
explicit

Definition at line 149 of file G4PlotManager.cc.

150 : fState(state)
151{
152#if defined(TOOLS_USE_FREETYPE)
153 //////////////////////////////////////////////////////////////////////////////
154 /// plotting, high resolution with freetype fonts and by using styles : //////
155 //////////////////////////////////////////////////////////////////////////////
156 fState.Message(kVL1, "... using high resolution with Freetype fonts", "");
157 //Have vertical A4 :
158 // unsigned int ww = 2000; //to have better antialising on freetype fonts.
159 // float A4 = 29.7f/21.0f;
160 // unsigned int wh = (unsigned int)(float(ww)*A4*0.80);
161 static toolx::sg::text_freetype ttf;
162 ttf.add_embedded_font(tools::sg::font_lato_regular_ttf(),tools::font::lato_regular_ttf);
163 ttf.add_embedded_font(tools::sg::font_roboto_bold_ttf(),tools::font::roboto_bold_ttf);
164 fViewer = std::make_unique<tools::viewplot>(G4cout, ttf,
165 fPlotParameters.GetColumns(),
166 fPlotParameters.GetRows(),
167 fPlotParameters.GetWidth(),
168 fPlotParameters.GetHeight());
169 fViewer->plots().view_border = false;
170 load_embeded_styles(fViewer->styles());
171 fViewer->styles().add_colormap("default",tools::sg::style_default_colormap());
172 fViewer->styles().add_colormap("ROOT",tools::sg::style_ROOT_colormap());
173#else
174 // cretae a viewer with default parameters
175 fState.Message(kVL1, "... using low resolution with Hershey fonts", "");
176 fViewer = std::make_unique<tools::viewplot>(G4cout,
177 fPlotParameters.GetColumns(),
178 fPlotParameters.GetRows(),
179 fPlotParameters.GetWidth(),
180 fPlotParameters.GetHeight());
181 fViewer->plots().view_border = false;
182#endif
183}
G4GLOB_DLL std::ostream G4cout
constexpr G4int kVL1

Referenced by G4PlotManager(), and operator=().

◆ ~G4PlotManager()

G4PlotManager::~G4PlotManager ( )
default

◆ G4PlotManager() [2/3]

G4PlotManager::G4PlotManager ( )
delete

◆ G4PlotManager() [3/3]

G4PlotManager::G4PlotManager ( const G4PlotManager & rhs)
delete

Member Function Documentation

◆ CloseFile()

G4bool G4PlotManager::CloseFile ( )

Definition at line 237 of file G4PlotManager.cc.

238{
239 fState.Message(kVL4, "close", "plot file", fFileName);
240
241 G4bool result = fViewer->close_file();
242 if ( ! result ) {
243 Warn("Cannot close the plot file", fkClass, "CloseFile");
244 }
245
246 fState.Message(kVL1, "close", "plot file", fFileName);
247
248 return result;
249}
bool G4bool
Definition G4Types.hh:86
constexpr G4int kVL4
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

◆ OpenFile()

G4bool G4PlotManager::OpenFile ( const G4String & fileName)

Definition at line 219 of file G4PlotManager.cc.

220{
221 fState.Message(kVL4, "open", "plot file", fileName);
222
223 // Keep filename for logging
224 fFileName = fileName;
225
226 G4bool result = fViewer->open_file(fileName);
227 if ( ! result ) {
228 Warn("Cannot open plot file " + fileName, fkClass, "OpenFile");
229 }
230
231 fState.Message(kVL1, "open", "plot file", fileName);
232
233 return result;
234}

◆ operator=()

G4PlotManager & G4PlotManager::operator= ( const G4PlotManager & rhs)
delete

◆ PlotAndWrite()

template<typename HT>
G4bool G4PlotManager::PlotAndWrite ( const std::vector< std::pair< HT *, G4HnInformation * > > & hnVector)
inline

Definition at line 86 of file G4PlotManager.hh.

88{
89 if ( ! hnVector.size() ) return true;
90
91 fViewer->plots().init_sg();
92 //it will recreate the sg::plotters and then reset the styles on new ones.
93 fViewer->set_cols_rows(fPlotParameters.GetColumns(), fPlotParameters.GetRows());
94 fViewer->plots().set_current_plotter(0);
95
96 auto result = true;
97 auto isWriteNeeded = false;
98
99 for (const auto& [ht, info] : hnVector) {
100 G4bool plotting = info->GetPlotting();
101 G4bool activation = info->GetActivation();
102 G4String name = info->GetName();
103 // skip plotting if not selected for plotting or
104 // if activation is enabled and HT is inactivated
105 // or HT is delted
106 if ( ( ! plotting ) ||
107 ( fState.GetIsActivation() && ( ! activation ) ) ||
108 ( info->GetDeleted() ) ) continue;
109
110 // plot this object
111 fViewer->plot(*ht);
112 fViewer->set_current_plotter_style(fPlotParameters.GetStyle());
113
114 // set color (only blue for the time being)
115 tools::sg::plotter& plotter = fViewer->plots().current_plotter();
116 // set plot properties (use info object to get these)
117 plotter.bins_style(0).color = tools::colorf_blue();
118
119 // get axis titles from base_histo (base of all T)
120 G4String title;
121 if ( ht->annotation(tools::histo::key_axis_x_title(), title) ) {
122 plotter.x_axis().title = title;
123 }
124 if ( ht->annotation(tools::histo::key_axis_y_title(), title) ) {
125 plotter.y_axis().title = title;
126 }
127 if ( ht->annotation(tools::histo::key_axis_z_title(), title) ) {
128 plotter.z_axis().title = title;
129 }
130
131#ifndef TOOLS_USE_FREETYPE
132 plotter.set_encoding_none();
133#endif
134
135 // get log axis parameters from G4HnInformation
136 if ( info->GetIsLogAxis(G4Analysis::kX) ) {
137 plotter.x_axis().labels_style().encoding = "PAW";
138 plotter.x_axis_is_log = true;
139 }
140 if ( info->GetIsLogAxis(G4Analysis::kY) ) {
141 plotter.y_axis().labels_style().encoding = "PAW";
142 plotter.y_axis_is_log = true;
143 }
144 if ( info->GetIsLogAxis(G4Analysis::kZ) ) {
145 plotter.z_axis().labels_style().encoding = "PAW";
146 plotter.z_axis_is_log = true;
147 }
148 isWriteNeeded = true;
149
150 fState.Message(G4Analysis::kVL3, "plotting", "hd|pd", name);
151
152 // write a page if number of plots per page is achieved
153 if ( G4int(fViewer->plots().current_index()) == (GetNofPlotsPerPage() - 1) ) {
154 result &= WritePage();
155 isWriteNeeded = false;
156 }
157
158 // Prepare for the next plot
159 fViewer->plots().next();
160 }
161
162 // write a page if loop is finished and there are plots to be written
163 if ( isWriteNeeded ) {
164 result &= WritePage();
165 }
166
167 // add test of result
168 return result;
169}
int G4int
Definition G4Types.hh:85
constexpr G4int kVL3
constexpr G4int kX
constexpr G4int kZ
constexpr G4int kY
const char * name(G4int ptype)

The documentation for this class was generated from the following files: