Geant4-11
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<HT*>& htVector,
60 const std::vector<G4HnInformation*>& hnVector);
62
63 private:
64 // Methods
67
68 // Static data members
69 static constexpr std::string_view fkClass { "G4PlotManager" };
70
71 // Data members
74 std::unique_ptr<tools::viewplot> fViewer;
76};
77
78// inline functions
79
80//_____________________________________________________________________________
83
84
85//_____________________________________________________________________________
86template <typename HT>
87inline G4bool G4PlotManager::PlotAndWrite(const std::vector<HT*>& htVector,
88 const std::vector<G4HnInformation*>& hnVector)
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}
172
173#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 GetIsLogAxis(G4int axis) const
G4bool GetPlotting() const
G4bool GetActivation() const
G4String GetName() const
G4bool WritePage()
const G4AnalysisManagerState & fState
std::unique_ptr< tools::viewplot > fViewer
G4bool OpenFile(const G4String &fileName)
~G4PlotManager()=default
G4PlotParameters fPlotParameters
G4PlotManager()=delete
G4PlotManager & operator=(const G4PlotManager &rhs)=delete
G4bool CloseFile()
G4int GetNofPlotsPerPage() const
G4String fFileName
static constexpr std::string_view fkClass
G4PlotManager(const G4PlotManager &rhs)=delete
G4bool PlotAndWrite(const std::vector< HT * > &htVector, const std::vector< G4HnInformation * > &hnVector)
G4int GetColumns() const
G4String GetStyle() const
G4int GetRows() const
constexpr G4int kVL3
constexpr G4int kX
constexpr G4int kZ
constexpr G4int kY
const char * name(G4int ptype)