Geant4 11.1.1
Toolkit for the simulation of the passage of particles through matter
Loading...
Searching...
No Matches
G4PlotManager.hh
Go to the documentation of this file.
1//
2// ********************************************************************
3// * License and Disclaimer *
4// * *
5// * The Geant4 software is copyright of the Copyright Holders of *
6// * the Geant4 Collaboration. It is provided under the terms and *
7// * conditions of the Geant4 Software License, included in the file *
8// * LICENSE and available at http://cern.ch/geant4/license . These *
9// * include a list of copyright holders. *
10// * *
11// * Neither the authors of this software system, nor their employing *
12// * institutes,nor the agencies providing financial support for this *
13// * work make any representation or warranty, express or implied, *
14// * regarding this software system or assume any liability for its *
15// * use. Please see the license in the file LICENSE and URL above *
16// * for the full disclaimer and the limitation of liability. *
17// * *
18// * This code implementation is the result of the scientific and *
19// * technical work of the GEANT4 collaboration. *
20// * By using, copying, modifying or distributing the software (or *
21// * any work based on the software) you agree to acknowledge its *
22// * use in resulting scientific publications, and indicate your *
23// * acceptance of all terms of the Geant4 Software license. *
24// ********************************************************************
25//
26
27// The manager class for batch plotting.
28
29// Author: Ivana Hrivnacova, 02/06/2015 ([email protected])
30
31#ifndef G4PlotManager_h
32#define G4PlotManager_h 1
33
35#include "G4PlotParameters.hh"
36#include "G4HnInformation.hh"
37
38#include "tools/viewplot"
39
40#include <vector>
41#include <memory>
42#include <string_view>
43
45{
46 public:
47 explicit G4PlotManager(const G4AnalysisManagerState& state);
48 ~G4PlotManager() = default;
49
50 // deleted functions
51 G4PlotManager() = delete;
52 G4PlotManager(const G4PlotManager& rhs) = delete;
53 G4PlotManager& operator=(const G4PlotManager& rhs) = delete;
54
55 public:
56 // Methods
57 G4bool OpenFile(const G4String& fileName);
58 template <typename HT>
59 G4bool PlotAndWrite(const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector);
61
62 private:
63 // Methods
64 G4int GetNofPlotsPerPage() const;
65 G4bool WritePage();
66
67 // Static data members
68 static constexpr std::string_view fkClass { "G4PlotManager" };
69
70 // Data members
71 const G4AnalysisManagerState& fState;
72 G4PlotParameters fPlotParameters;
73 std::unique_ptr<tools::viewplot> fViewer;
74 G4String fFileName;
75};
76
77// inline functions
78
79//_____________________________________________________________________________
80inline G4int G4PlotManager::GetNofPlotsPerPage() const
81{ return fPlotParameters.GetColumns()*fPlotParameters.GetRows(); }
82
83
84//_____________________________________________________________________________
85template <typename HT>
87 const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector)
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}
168
169#endif
bool G4bool
Definition: G4Types.hh:86
int G4int
Definition: G4Types.hh:85
void Message(G4int level, const G4String &action, const G4String &objectType, const G4String &objectName="", G4bool success=true) const
G4bool OpenFile(const G4String &fileName)
~G4PlotManager()=default
G4PlotManager()=delete
G4PlotManager & operator=(const G4PlotManager &rhs)=delete
G4bool CloseFile()
G4PlotManager(const G4PlotManager &rhs)=delete
G4bool PlotAndWrite(const std::vector< std::pair< HT *, G4HnInformation * > > &hnVector)
G4int GetColumns() const
G4String GetStyle() const
G4int GetRows() const
constexpr G4int kVL3
constexpr G4int kX
constexpr G4int kZ
constexpr G4int kY