ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
G4PlotManager.hh
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file G4PlotManager.hh
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 
44 {
45  public:
46  explicit G4PlotManager(const G4AnalysisManagerState& state);
48 
49  // deleted functions
50  G4PlotManager(const G4PlotManager& rhs) = delete;
51  G4PlotManager& operator=(const G4PlotManager& rhs) = delete;
52 
53  public:
54  // methods
55  G4bool OpenFile(const G4String& fileName);
56  template <typename T>
57  G4bool PlotAndWrite(const std::vector<T*>& htVector,
58  const std::vector<G4HnInformation*>& hnVector);
59  G4bool CloseFile();
60 
61  private:
62  // methods
63  G4int GetNofPlotsPerPage() const;
64  G4bool WritePage();
65 
66  // data members
69  std::unique_ptr<tools::viewplot> fViewer;
71 };
72 
73 // inline functions
74 
75 //_____________________________________________________________________________
78 
79 
80 //_____________________________________________________________________________
81 template <typename T>
82 inline G4bool G4PlotManager::PlotAndWrite(const std::vector<T*>& htVector,
83  const std::vector<G4HnInformation*>& hnVector)
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.
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 }
172 
173 #endif