Geant4 11.2.2
Toolkit for the simulation of the passage of particles through matter
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 (ivana@ipno.in2p3.fr)
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 // 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}
170
171#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
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