Geant4 10.7.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 ()
 
 G4PlotManager (const G4PlotManager &rhs)=delete
 
G4PlotManageroperator= (const G4PlotManager &rhs)=delete
 
G4bool OpenFile (const G4String &fileName)
 
template<typename T >
G4bool PlotAndWrite (const std::vector< T * > &htVector, const std::vector< G4HnInformation * > &hnVector)
 
G4bool CloseFile ()
 

Detailed Description

Definition at line 43 of file G4PlotManager.hh.

Constructor & Destructor Documentation

◆ G4PlotManager() [1/2]

G4PlotManager::G4PlotManager ( const G4AnalysisManagerState state)
explicit

Definition at line 152 of file G4PlotManager.cc.

153 : fState(state),
154 fPlotParameters(),
155 fViewer(nullptr),
156 fFileName()
157{
158#if defined(TOOLS_USE_FREETYPE)
159 //////////////////////////////////////////////////////////////////////////////
160 /// plotting, high resolution with freetype fonts and by using styles : //////
161 //////////////////////////////////////////////////////////////////////////////
162#ifdef G4VERBOSE
163 if ( fState.GetVerboseL1() )
164 G4cout << "... using high resolution with Freetype fonts" << G4endl;
165#endif
166 //Have vertical A4 :
167 // unsigned int ww = 2000; //to have better antialising on freetype fonts.
168 // float A4 = 29.7f/21.0f;
169 // unsigned int wh = (unsigned int)(float(ww)*A4*0.80);
170 static tools::sg::text_freetype ttf;
171 fViewer.reset(new tools::viewplot(G4cout, ttf,
172 fPlotParameters.GetColumns(),
173 fPlotParameters.GetRows(),
174 fPlotParameters.GetWidth(),
175 fPlotParameters.GetHeight()));
176 fViewer->plots().view_border = false;
177 load_embeded_styles(fViewer->styles());
178 fViewer->styles().add_colormap("default",tools::sg::style_default_colormap());
179 fViewer->styles().add_colormap("ROOT",tools::sg::style_ROOT_colormap());
180#else
181 // cretae a viewer with default parameters
182#ifdef G4VERBOSE
183 if ( fState.GetVerboseL1() )
184 G4cout << "... using low resolution with Hershey fonts" << G4endl;
185#endif
186 fViewer.reset(new tools::viewplot(G4cout,
187 fPlotParameters.GetColumns(),
188 fPlotParameters.GetRows(),
189 fPlotParameters.GetWidth(),
190 fPlotParameters.GetHeight()));
191 fViewer->plots().view_border = false;
192#endif
193}
#define G4endl
Definition: G4ios.hh:57
G4GLOB_DLL std::ostream G4cout
const G4AnalysisVerbose * GetVerboseL1() const
G4int GetWidth() const
G4int GetColumns() const
G4int GetHeight() const
G4int GetRows() const

◆ ~G4PlotManager()

G4PlotManager::~G4PlotManager ( )

Definition at line 196 of file G4PlotManager.cc.

197{}

◆ G4PlotManager() [2/2]

G4PlotManager::G4PlotManager ( const G4PlotManager rhs)
delete

Member Function Documentation

◆ CloseFile()

G4bool G4PlotManager::CloseFile ( )

Definition at line 268 of file G4PlotManager.cc.

269{
270#ifdef G4VERBOSE
271 if ( fState.GetVerboseL4() )
272 fState.GetVerboseL4()->Message("close", "plot file", fFileName);
273#endif
274
275 G4bool result = fViewer->close_file();
276 if ( ! result ) {
277 G4ExceptionDescription description;
278 description << " " << "Cannot close the plot file.";
279 G4Exception("G4PlotManager::CloseFile()",
280 "Analysis_W021", JustWarning, description);
281 }
282
283#ifdef G4VERBOSE
284 if ( fState.GetVerboseL1() )
285 fState.GetVerboseL1()->Message("close", "plot file", fFileName);
286#endif
287
288 return result;
289}
@ JustWarning
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.cc:35
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:40
bool G4bool
Definition: G4Types.hh:86
const G4AnalysisVerbose * GetVerboseL4() const
void Message(const G4String &action, const G4String &object, const G4String &objectName, G4bool success=true) const

◆ OpenFile()

G4bool G4PlotManager::OpenFile ( const G4String fileName)

Definition at line 241 of file G4PlotManager.cc.

242{
243#ifdef G4VERBOSE
244 if ( fState.GetVerboseL4() )
245 fState.GetVerboseL4()->Message("open", "plot file", fileName);
246#endif
247
248 // Keep filename for logging
249 fFileName = fileName;
250
251 G4bool result = fViewer->open_file(fileName);
252 if ( ! result ) {
253 G4ExceptionDescription description;
254 description << " " << "Cannot open plot file " << fileName;
255 G4Exception("G4PlotManager::OpenFile()",
256 "Analysis_W001", JustWarning, description);
257 }
258
259#ifdef G4VERBOSE
260 if ( fState.GetVerboseL1() )
261 fState.GetVerboseL1()->Message("open", "plot file", fileName);
262#endif
263
264 return result;
265}

◆ operator=()

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

◆ PlotAndWrite()

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

Definition at line 82 of file G4PlotManager.hh.

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

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