Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:58:56

0001 //
0002 // ********************************************************************
0003 // * License and Disclaimer                                           *
0004 // *                                                                  *
0005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
0006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
0007 // * conditions of the Geant4 Software License,  included in the file *
0008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
0009 // * include a list of copyright holders.                             *
0010 // *                                                                  *
0011 // * Neither the authors of this software system, nor their employing *
0012 // * institutes,nor the agencies providing financial support for this *
0013 // * work  make  any representation or  warranty, express or implied, *
0014 // * regarding  this  software system or assume any liability for its *
0015 // * use.  Please see the license in the file  LICENSE  and URL above *
0016 // * for the full disclaimer and the limitation of liability.         *
0017 // *                                                                  *
0018 // * This  code  implementation is the result of  the  scientific and *
0019 // * technical work of the GEANT4 collaboration.                      *
0020 // * By using,  copying,  modifying or  distributing the software (or *
0021 // * any work based  on the software)  you  agree  to acknowledge its *
0022 // * use  in  resulting  scientific  publications,  and indicate your *
0023 // * acceptance of all terms of the Geant4 Software license.          *
0024 // ********************************************************************
0025 //
0026 
0027 // The manager class for batch plotting.
0028 
0029 // Author: Ivana Hrivnacova, 02/06/2015  (ivana@ipno.in2p3.fr)
0030 
0031 #ifndef G4PlotManager_h
0032 #define G4PlotManager_h 1
0033 
0034 #include "G4AnalysisManagerState.hh"
0035 #include "G4PlotParameters.hh"
0036 #include "G4HnInformation.hh"
0037 
0038 #include "tools/viewplot"
0039 
0040 #include <vector>
0041 #include <memory>
0042 #include <string_view>
0043 
0044 class G4PlotManager
0045 {
0046   public:
0047     explicit G4PlotManager(const G4AnalysisManagerState& state);
0048     ~G4PlotManager() = default;
0049 
0050     // deleted functions
0051     G4PlotManager() = delete;
0052     G4PlotManager(const G4PlotManager& rhs) = delete;
0053     G4PlotManager& operator=(const G4PlotManager& rhs) = delete;
0054 
0055   public:
0056     // Methods
0057     G4bool OpenFile(const G4String& fileName);
0058     template <typename HT>
0059     G4bool PlotAndWrite(const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector);
0060     G4bool CloseFile();
0061 
0062   private:
0063     // Methods
0064     G4int  GetNofPlotsPerPage() const;
0065     G4bool WritePage();
0066 
0067     // Static data members
0068     static constexpr std::string_view fkClass { "G4PlotManager" };
0069 
0070     // Data members
0071     const G4AnalysisManagerState& fState;
0072     G4PlotParameters fPlotParameters;
0073     std::unique_ptr<tools::viewplot>  fViewer;
0074     G4String  fFileName;
0075 };
0076 
0077 // inline functions
0078 
0079 //_____________________________________________________________________________
0080 inline G4int  G4PlotManager::GetNofPlotsPerPage() const
0081 { return fPlotParameters.GetColumns()*fPlotParameters.GetRows(); }
0082 
0083 
0084 //_____________________________________________________________________________
0085 template <typename HT>
0086 inline G4bool G4PlotManager::PlotAndWrite(
0087   const std::vector<std::pair<HT*, G4HnInformation*>>& hnVector)
0088 {
0089   if ( ! hnVector.size() ) return true;
0090 
0091   fViewer->plots().init_sg();
0092     //it will recreate the sg::plotters and then reset the styles on new ones.
0093   fViewer->set_cols_rows(fPlotParameters.GetColumns(), fPlotParameters.GetRows());
0094   fViewer->plots().set_current_plotter(0);
0095 
0096   auto result = true;
0097   auto isWriteNeeded = false;
0098 
0099   for (const auto& [ht, info] : hnVector) {
0100     G4bool plotting = info->GetPlotting();
0101     G4bool activation = info->GetActivation();
0102     G4String name = info->GetName();
0103     // skip plotting if not selected for plotting or
0104     // if activation is enabled and HT is inactivated
0105     // or HT is delted
0106     if ( ( ! plotting ) ||
0107          ( fState.GetIsActivation() && ( ! activation ) ) ||
0108          ( info->GetDeleted() ) ) continue;
0109 
0110     // plot this object
0111     fViewer->plot(*ht);
0112     fViewer->set_current_plotter_style(fPlotParameters.GetStyle());
0113 
0114     // set color (only blue for the time being)
0115     tools::sg::plotter& plotter = fViewer->plots().current_plotter();
0116     // set plot properties (use info object to get these)
0117     plotter.bins_style(0).color = tools::colorf_blue();
0118 
0119     // get axis titles from base_histo (base of all T)
0120     G4String title;
0121     if ( ht->annotation(tools::histo::key_axis_x_title(), title) ) {
0122       plotter.x_axis().title = title;
0123     }
0124     if ( ht->annotation(tools::histo::key_axis_y_title(), title) ) {
0125       plotter.y_axis().title = title;
0126     }
0127     if ( ht->annotation(tools::histo::key_axis_z_title(), title) ) {
0128       plotter.z_axis().title = title;
0129     }
0130 
0131 #ifndef TOOLS_USE_FREETYPE
0132     plotter.set_encoding_none();
0133 #endif
0134 
0135     // get log axis parameters from G4HnInformation
0136     if ( info->GetIsLogAxis(G4Analysis::kX) ) {
0137       plotter.x_axis().labels_style().encoding = "PAW";
0138       plotter.x_axis_is_log = true;
0139     }
0140     if ( info->GetIsLogAxis(G4Analysis::kY) ) {
0141       plotter.y_axis().labels_style().encoding = "PAW";
0142       plotter.y_axis_is_log = true;
0143     }
0144     if ( info->GetIsLogAxis(G4Analysis::kZ) ) {
0145       plotter.z_axis().labels_style().encoding = "PAW";
0146       plotter.z_axis_is_log = true;
0147     }
0148     isWriteNeeded = true;
0149 
0150     fState.Message(G4Analysis::kVL3, "plotting", "hd|pd", name);
0151 
0152     // write a page if number of plots per page is achieved
0153     if ( G4int(fViewer->plots().current_index()) == (GetNofPlotsPerPage() - 1) ) {
0154       result &= WritePage();
0155       isWriteNeeded = false;
0156     }
0157 
0158     // Prepare for the next plot
0159     fViewer->plots().next();
0160   }
0161 
0162   // write a page if loop is finished and there are plots to be written
0163   if ( isWriteNeeded ) {
0164     result &= WritePage();
0165   }
0166 
0167   // add test of result
0168   return result;
0169 }
0170 
0171 #endif