Geant4-11
Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes
G4PlotManager Class Reference

#include <G4PlotManager.hh>

Public Member Functions

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

Private Member Functions

G4int GetNofPlotsPerPage () const
 
G4bool WritePage ()
 

Private Attributes

G4String fFileName
 
G4PlotParameters fPlotParameters
 
const G4AnalysisManagerStatefState
 
std::unique_ptr< tools::viewplot > fViewer
 

Static Private Attributes

static constexpr std::string_view fkClass { "G4PlotManager" }
 

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)
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 tools::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,
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,
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
const G4AnalysisManagerState & fState
std::unique_ptr< tools::viewplot > fViewer
G4PlotParameters fPlotParameters
G4int GetWidth() const
G4int GetColumns() const
G4int GetHeight() const
G4int GetRows() const
constexpr G4int kVL1

References fPlotParameters, fState, fViewer, G4cout, G4PlotParameters::GetColumns(), G4PlotParameters::GetHeight(), G4PlotParameters::GetRows(), G4PlotParameters::GetWidth(), G4Analysis::kVL1, and G4AnalysisManagerState::Message().

◆ ~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
G4String fFileName
static constexpr std::string_view fkClass
constexpr G4int kVL4
void Warn(const G4String &message, const std::string_view inClass, const std::string_view inFunction)

References fFileName, fkClass, fState, fViewer, G4Analysis::kVL1, G4Analysis::kVL4, G4AnalysisManagerState::Message(), and G4Analysis::Warn().

◆ GetNofPlotsPerPage()

G4int G4PlotManager::GetNofPlotsPerPage ( ) const
inlineprivate

◆ 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}

References fFileName, fkClass, fState, fViewer, G4Analysis::kVL1, G4Analysis::kVL4, G4AnalysisManagerState::Message(), and G4Analysis::Warn().

◆ operator=()

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

◆ PlotAndWrite()

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

Definition at line 87 of file G4PlotManager.hh.

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

References fPlotParameters, fState, fViewer, G4HnInformation::GetActivation(), G4PlotParameters::GetColumns(), G4AnalysisManagerState::GetIsActivation(), G4HnInformation::GetIsLogAxis(), G4HnInformation::GetName(), GetNofPlotsPerPage(), G4HnInformation::GetPlotting(), G4PlotParameters::GetRows(), G4PlotParameters::GetStyle(), G4Analysis::kVL3, G4Analysis::kX, G4Analysis::kY, G4Analysis::kZ, G4AnalysisManagerState::Message(), G4InuclParticleNames::name(), and WritePage().

◆ WritePage()

G4bool G4PlotManager::WritePage ( )
private

Definition at line 194 of file G4PlotManager.cc.

195{
196 fState.Message(kVL4, "write a page in", "plot file", fFileName);
197
198#if defined(TOOLS_USE_FREETYPE)
199 HD_style(fViewer->plots(), 5);
200 regions_style(fViewer->plots(), fPlotParameters.GetScale());
201#endif
202
203 G4bool result = fViewer->write_page();
204 if ( ! result ) {
205 Warn("Cannot write a page in the plot file " + fFileName,
206 fkClass, "WritePage");
207 }
208
209 // clear viewers plots
210 fViewer->plots().init_sg();
211 //it will recreate the sg::plotters and then reset the styles on new ones.
212
213 fState.Message(kVL3, "write a page in", "plot file", fFileName);
214
215 return result;
216}
G4float GetScale() const

References fFileName, fkClass, fPlotParameters, fState, fViewer, G4PlotParameters::GetScale(), G4Analysis::kVL3, G4Analysis::kVL4, G4AnalysisManagerState::Message(), and G4Analysis::Warn().

Referenced by PlotAndWrite().

Field Documentation

◆ fFileName

G4String G4PlotManager::fFileName
private

Definition at line 75 of file G4PlotManager.hh.

Referenced by CloseFile(), OpenFile(), and WritePage().

◆ fkClass

constexpr std::string_view G4PlotManager::fkClass { "G4PlotManager" }
staticconstexprprivate

Definition at line 69 of file G4PlotManager.hh.

Referenced by CloseFile(), OpenFile(), and WritePage().

◆ fPlotParameters

G4PlotParameters G4PlotManager::fPlotParameters
private

Definition at line 73 of file G4PlotManager.hh.

Referenced by G4PlotManager(), GetNofPlotsPerPage(), PlotAndWrite(), and WritePage().

◆ fState

const G4AnalysisManagerState& G4PlotManager::fState
private

Definition at line 72 of file G4PlotManager.hh.

Referenced by CloseFile(), G4PlotManager(), OpenFile(), PlotAndWrite(), and WritePage().

◆ fViewer

std::unique_ptr<tools::viewplot> G4PlotManager::fViewer
private

Definition at line 74 of file G4PlotManager.hh.

Referenced by CloseFile(), G4PlotManager(), OpenFile(), PlotAndWrite(), and WritePage().


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