Geant4 11.1.1
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 153 of file G4PlotManager.cc.

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

◆ ~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 241 of file G4PlotManager.cc.

242{
243 fState.Message(kVL4, "close", "plot file", fFileName);
244
245 G4bool result = fViewer->close_file();
246 if ( ! result ) {
247 Warn("Cannot close the plot file", fkClass, "CloseFile");
248 }
249
250 fState.Message(kVL1, "close", "plot file", fFileName);
251
252 return result;
253}
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 223 of file G4PlotManager.cc.

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

◆ 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 if ( ( ! plotting ) ||
106 ( fState.GetIsActivation() && ( ! activation ) ) ) continue;
107
108 // plot this object
109 fViewer->plot(*ht);
110 fViewer->set_current_plotter_style(fPlotParameters.GetStyle());
111
112 // set color (only blue for the time being)
113 tools::sg::plotter& plotter = fViewer->plots().current_plotter();
114 // set plot properties (use info object to get these)
115 plotter.bins_style(0).color = tools::colorf_blue();
116
117 // get axis titles from base_histo (base of all T)
118 G4String title;
119 if ( ht->annotation(tools::histo::key_axis_x_title(), title) ) {
120 plotter.x_axis().title = title;
121 }
122 if ( ht->annotation(tools::histo::key_axis_y_title(), title) ) {
123 plotter.y_axis().title = title;
124 }
125 if ( ht->annotation(tools::histo::key_axis_z_title(), title) ) {
126 plotter.z_axis().title = title;
127 }
128
129#ifndef TOOLS_USE_FREETYPE
130 plotter.set_encoding_none();
131#endif
132
133 // get log axis parameters from G4HnInformation
134 if ( info->GetIsLogAxis(G4Analysis::kX) ) {
135 plotter.x_axis().labels_style().encoding = "PAW";
136 plotter.x_axis_is_log = true;
137 }
138 if ( info->GetIsLogAxis(G4Analysis::kY) ) {
139 plotter.y_axis().labels_style().encoding = "PAW";
140 plotter.y_axis_is_log = true;
141 }
142 if ( info->GetIsLogAxis(G4Analysis::kZ) ) {
143 plotter.z_axis().labels_style().encoding = "PAW";
144 plotter.z_axis_is_log = true;
145 }
146 isWriteNeeded = true;
147
148 fState.Message(G4Analysis::kVL3, "plotting", "hd|pd", name);
149
150 // write a page if number of plots per page is achieved
151 if ( G4int(fViewer->plots().current_index()) == (GetNofPlotsPerPage() - 1) ) {
152 result &= WritePage();
153 isWriteNeeded = false;
154 }
155
156 // Prepare for the next plot
157 fViewer->plots().next();
158 }
159
160 // write a page if loop is finished and there are plots to be written
161 if ( isWriteNeeded ) {
162 result &= WritePage();
163 }
164
165 // add test of result
166 return result;
167}
int G4int
Definition: G4Types.hh:85
G4String GetStyle() const
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: