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[ 10.5.p1 ] [ 10.6 ] [ 10.6.p1 ] [ 10.6.p2 ] [ 10.6.p3 ] [ 10.7 ] [ 10.7.p1 ] [ 10.7.p2 ] [ 10.7.p3 ] [ 10.7.p4 ] [ 11.0 ] [ 11.0.p1 ] [ 11.0.p2 ] [ 11.0.p3, ] [ 11.0.p4 ] [ 11.1 ] [ 11.1.1 ] [ 11.1.2 ] [ 11.1.3 ] [ 11.2 ] [ 11.2.1 ] [ 11.2.2 ] [ 11.3.0 ]

  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 
 34 #include "G4AnalysisManagerState.hh"
 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 
 44 class G4PlotManager
 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);
 60     G4bool CloseFile();
 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 //_____________________________________________________________________________
 80 inline G4int  G4PlotManager::GetNofPlotsPerPage() const
 81 { return fPlotParameters.GetColumns()*fPlotParameters.GetRows(); }
 82 
 83 
 84 //_____________________________________________________________________________
 85 template <typename HT>
 86 inline G4bool G4PlotManager::PlotAndWrite(
 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
172