Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 27 // Author: Ivana Hrivnacova, 02/06/2015 (ivan 28 29 #include "G4HnInformation.hh" 30 #include "G4PlotManager.hh" 31 #include "G4AnalysisUtilities.hh" 32 #include "G4ios.hh" 33 34 #if defined(TOOLS_USE_FREETYPE) 35 #include "toolx/sg/text_freetype" 36 #include "toolx/xml/xml_style" 37 #include "tools/xml/wrap_viewplot_fonts_google 38 //inlib/xml/viewplot.style file embeded in a 39 #include "tools/font/lato_regular_ttf" 40 #include "tools/font/roboto_bold_ttf" 41 42 namespace { 43 44 // from g4tools/test/viewplot.cpp 45 //____________________________________________ 46 void HD_style(tools::sg::plots& a_plots,float 47 std::vector<tools::sg::plotter*> plotters; 48 a_plots.plotters(plotters); 49 tools_vforcit(tools::sg::plotter*,plotters,i 50 tools::sg::plotter* _plotter = *it; 51 _plotter->bins_style(0).line_width = a_lin 52 _plotter->inner_frame_style().line_width = 53 _plotter->grid_style().line_width = a_line 54 _plotter->x_axis().line_style().width = a_ 55 _plotter->x_axis().ticks_style().width = a 56 _plotter->y_axis().line_style().width = a_ 57 _plotter->y_axis().ticks_style().width = a 58 _plotter->z_axis().line_style().width = a_ 59 _plotter->z_axis().ticks_style().width = a 60 61 // needed if font is hershey : 62 _plotter->title_style().line_width = a_lin 63 _plotter->infos_style().line_width = a_lin 64 _plotter->title_box_style().line_width = a 65 66 _plotter->x_axis().labels_style().line_wid 67 _plotter->x_axis().mag_style().line_width 68 _plotter->x_axis().title_style().line_widt 69 70 _plotter->y_axis().labels_style().line_wid 71 _plotter->y_axis().mag_style().line_width 72 _plotter->y_axis().title_style().line_widt 73 74 _plotter->z_axis().labels_style().line_wid 75 _plotter->z_axis().mag_style().line_width 76 _plotter->z_axis().title_style().line_widt 77 } 78 } 79 80 // from g4tools/test/viewplot.cpp 81 //____________________________________________ 82 void regions_style(tools::sg::plots& a_plots,f 83 // Rescale some plotter parameters (for exam 84 // We assume that these parameters had been 85 // Then this function must be applied after 86 // a plotting style may set these parameters 87 88 float ww_wc = a_plots.width; 89 float wh_wc = a_plots.height; 90 float rw_wc = ww_wc/a_plots.cols; 91 float rh_wc = wh_wc/a_plots.rows; 92 93 float cooking = 1.2f; //if increased the dat 94 95 float wfac = (rw_wc/ww_wc)*cooking; 96 float hfac = (rh_wc/wh_wc)*cooking; 97 98 float label_cooking = 1.6f; //if increased t 99 100 if((a_plots.cols.value()>=4)&&(a_plots.cols. 101 102 float title_cooking = 1.1f; //extra title co 103 104 a_plots.plotter_scale = a_plotter_scale; 105 106 std::vector<tools::sg::plotter*> plotters; 107 a_plots.plotters(plotters); 108 tools_vforcit(tools::sg::plotter*,plotters,i 109 tools::sg::plotter* _plotter = *it; 110 111 _plotter->left_margin = _plotter->left_mar 112 _plotter->right_margin = _plotter->right_m 113 _plotter->bottom_margin = _plotter->bottom 114 _plotter->top_margin = _plotter->top_margi 115 116 _plotter->x_axis().tick_length = _plotter- 117 _plotter->y_axis().tick_length = _plotter- 118 119 _plotter->title_to_axis = _plotter->title_ 120 _plotter->title_height = _plotter->title_h 121 122 _plotter->x_axis().label_height = _plotter 123 _plotter->y_axis().label_height = _plotter 124 125 } 126 } 127 128 // from g4tools/test/viewplot.cpp 129 //____________________________________________ 130 bool load_embeded_styles(tools::xml::styles& a 131 std::string ss; 132 unsigned int linen; 133 const char** lines = viewplot_fonts_google_s 134 for(unsigned int index=0;index<linen;index++ 135 std::string s = lines[index]; 136 tools::replace(s,"@@double_quote@@","\""); 137 tools::replace(s,"@@back_slash@@","\\"); 138 ss += s + "\n"; 139 } 140 return toolx::xml::load_style_string(a_style 141 } 142 143 } 144 #endif 145 146 using namespace G4Analysis; 147 148 // 149 // ctors, dtor 150 // 151 152 //____________________________________________ 153 G4PlotManager::G4PlotManager(const G4AnalysisM 154 : fState(state) 155 { 156 #if defined(TOOLS_USE_FREETYPE) 157 //////////////////////////////////////////// 158 /// plotting, high resolution with freetype 159 //////////////////////////////////////////// 160 fState.Message(kVL1, "... using high resolu 161 //Have vertical A4 : 162 // unsigned int ww = 2000; //to have better 163 // float A4 = 29.7f/21.0f; 164 // unsigned int wh = (unsigned int)(float(ww 165 static toolx::sg::text_freetype ttf; 166 ttf.add_embedded_font(tools::sg::font_lato_r 167 ttf.add_embedded_font(tools::sg::font_roboto 168 fViewer = std::make_unique<tools::viewplot>( 169 fPlotParam 170 fPlotParam 171 fPlotParam 172 fPlotParam 173 fViewer->plots().view_border = false; 174 load_embeded_styles(fViewer->styles()); 175 fViewer->styles().add_colormap("default",too 176 fViewer->styles().add_colormap("ROOT",tools: 177 #else 178 // cretae a viewer with default parameters 179 fState.Message(kVL1, "... using low resolut 180 fViewer = std::make_unique<tools::viewplot>( 181 fPlotParam 182 fPlotParam 183 fPlotParam 184 fPlotParam 185 fViewer->plots().view_border = false; 186 #endif 187 } 188 189 // 190 // private methods 191 // 192 193 //____________________________________________ 194 G4bool G4PlotManager::WritePage() 195 { 196 fState.Message(kVL4, "write a page in", "plo 197 198 #if defined(TOOLS_USE_FREETYPE) 199 HD_style(fViewer->plots(), 5); 200 regions_style(fViewer->plots(), fPlotParamet 201 #endif 202 203 G4bool result = fViewer->write_page(); 204 if ( ! result ) { 205 Warn("Cannot write a page in the plot file 206 fkClass, "WritePage"); 207 } 208 209 // clear viewers plots 210 fViewer->plots().init_sg(); 211 //it will recreate the sg::plotters and th 212 213 fState.Message(kVL3, "write a page in", "plo 214 215 return result; 216 } 217 218 // 219 // public methods 220 // 221 222 //____________________________________________ 223 G4bool G4PlotManager::OpenFile(const G4String& 224 { 225 fState.Message(kVL4, "open", "plot file", fi 226 227 // Keep filename for logging 228 fFileName = fileName; 229 230 G4bool result = fViewer->open_file(fileName) 231 if ( ! result ) { 232 Warn("Cannot open plot file " + fileName, 233 } 234 235 fState.Message(kVL1, "open", "plot file", fi 236 237 return result; 238 } 239 240 //____________________________________________ 241 G4bool G4PlotManager::CloseFile() 242 { 243 fState.Message(kVL4, "close", "plot file", f 244 245 G4bool result = fViewer->close_file(); 246 if ( ! result ) { 247 Warn("Cannot close the plot file", fkClass 248 } 249 250 fState.Message(kVL1, "close", "plot file", f 251 252 return result; 253 } 254