Geant4 Cross Reference |
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 nonvirtual public interface reader class for g4tools based analysis. 28 // It is defined as a composite of object manager base classes. 29 // Individual use of the component managers is disabled 30 // (except for file manager and Hn manager which are also used from 31 // other object managers). 32 // The functions which has to be implemented in concrete managers 33 // are declared as virtual protected. 34 35 // Author: Ivana Hrivnacova, 09/04/2014 (ivana@ipno.in2p3.fr) 36 37 #ifndef G4VAnalysisReader_h 38 #define G4VAnalysisReader_h 1 39 40 #include "G4AnalysisManagerState.hh" 41 #include "G4AnalysisUtilities.hh" 42 #include "globals.hh" 43 44 #include "G4VTBaseHnManager.hh" // make forward declaration if possible 45 46 #include <vector> 47 #include <memory> 48 #include <string_view> 49 50 class G4HnManager; 51 class G4VRNtupleManager; 52 class G4VRFileManager; 53 54 using G4Analysis::kDim1; 55 using G4Analysis::kDim2; 56 using G4Analysis::kDim3; 57 58 class G4VAnalysisReader 59 { 60 public: 61 virtual ~G4VAnalysisReader(); 62 63 // Methods for handling files 64 // G4bool OpenFile(const G4String& fileName = ""); 65 G4bool CloseFiles(G4bool reset = true); 66 67 // Methods for handling files and directories names 68 void SetFileName(const G4String& fileName); 69 G4String GetFileName() const; 70 71 // Methods to read histograms from a file 72 G4int ReadH1(const G4String& h1Name, const G4String& fileName = "", const G4String& dirName = ""); 73 G4int ReadH2(const G4String& h2Name, const G4String& fileName = "", const G4String& dirName = ""); 74 G4int ReadH3(const G4String& h3Name, const G4String& fileName = "", const G4String& dirName = ""); 75 G4int ReadP1(const G4String& h1Name, const G4String& fileName = "", const G4String& dirName = ""); 76 G4int ReadP2(const G4String& h2Name, const G4String& fileName = "", const G4String& dirName = ""); 77 78 // The ids of histograms and ntuples are generated automatically 79 // starting from 0; with following functions it is possible to 80 // change the first Id to start from other value 81 G4bool SetFirstHistoId(G4int firstId); 82 G4bool SetFirstH1Id(G4int firstId); 83 G4bool SetFirstH2Id(G4int firstId); 84 G4bool SetFirstH3Id(G4int firstId); 85 G4bool SetFirstProfileId(G4int firstId); 86 G4bool SetFirstP1Id(G4int firstId); 87 G4bool SetFirstP2Id(G4int firstId); 88 G4bool SetFirstNtupleId(G4int firstId); 89 90 // Methods to read ntuple from a file 91 G4int GetNtuple(const G4String& ntupleName, const G4String& fileName = "", const G4String& dirName = ""); 92 93 // Methods for ntuple with id = FirstNtupleId 94 G4bool SetNtupleIColumn(const G4String& columnName, G4int& value); 95 G4bool SetNtupleFColumn(const G4String& columnName, G4float& value); 96 G4bool SetNtupleDColumn(const G4String& columnName, G4double& value); 97 G4bool SetNtupleSColumn(const G4String& columnName, G4String& value); 98 // Bind the ntuple colums of vector type 99 G4bool SetNtupleIColumn(const G4String& columnName, 100 std::vector<int>& vector); 101 G4bool SetNtupleFColumn(const G4String& columnName, 102 std::vector<float>& vector); 103 G4bool SetNtupleDColumn(const G4String& columnName, 104 std::vector<double>& vector); 105 G4bool SetNtupleSColumn(const G4String& columnName, 106 std::vector<std::string>& vector); 107 // Methods for ntuple with id > FirstNtupleId 108 G4bool SetNtupleIColumn(G4int ntupleId, const G4String& columnName, 109 G4int& value); 110 G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName, 111 G4float& value); 112 G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName, 113 G4double& value); 114 G4bool SetNtupleSColumn(G4int ntupleId, const G4String& columnName, 115 G4String& value); 116 // Bind the ntuple colums of vector type 117 G4bool SetNtupleIColumn(G4int ntupleId, const G4String& columnName, 118 std::vector<int>& vector); 119 G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName, 120 std::vector<float>& vector); 121 G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName, 122 std::vector<double>& vector); 123 G4bool SetNtupleSColumn(G4int ntupleId, const G4String& columnName, 124 std::vector<std::string>& vector); 125 126 G4bool GetNtupleRow(); 127 G4bool GetNtupleRow(G4int ntupleId); 128 129 // ASCII option 130 131 // Return false if there is no object selected for ASCII output, 132 // return true otherwise 133 G4bool IsAscii() const; 134 135 // Access methods 136 G4int GetNofH1s(G4bool onlyIfExist = false) const; 137 G4int GetNofH2s(G4bool onlyIfExist = false) const; 138 G4int GetNofH3s(G4bool onlyIfExist = false) const; 139 G4int GetNofP1s(G4bool onlyIfExist = false) const; 140 G4int GetNofP2s(G4bool onlyIfExist = false) const; 141 G4int GetNofNtuples() const; 142 143 // Access methods via names 144 G4int GetH1Id(const G4String& name, G4bool warn = true) const; 145 G4int GetH2Id(const G4String& name, G4bool warn = true) const; 146 G4int GetH3Id(const G4String& name, G4bool warn = true) const; 147 G4int GetP1Id(const G4String& name, G4bool warn = true) const; 148 G4int GetP2Id(const G4String& name, G4bool warn = true) const; 149 150 // Access to histogram & profiles parameters 151 // 152 G4int GetH1Nbins(G4int id) const; 153 G4double GetH1Xmin(G4int id) const; 154 G4double GetH1Xmax(G4int id) const; 155 G4double GetH1Width(G4int id) const; 156 // 157 G4int GetH2Nxbins(G4int id) const; 158 G4double GetH2Xmin(G4int id) const; 159 G4double GetH2Xmax(G4int id) const; 160 G4double GetH2XWidth(G4int id) const; 161 G4int GetH2Nybins(G4int id) const; 162 G4double GetH2Ymin(G4int id) const; 163 G4double GetH2Ymax(G4int id) const; 164 G4double GetH2YWidth(G4int id) const; 165 // 166 G4int GetH3Nxbins(G4int id) const; 167 G4double GetH3Xmin(G4int id) const; 168 G4double GetH3Xmax(G4int id) const; 169 G4double GetH3XWidth(G4int id) const; 170 G4int GetH3Nybins(G4int id) const; 171 G4double GetH3Ymin(G4int id) const; 172 G4double GetH3Ymax(G4int id) const; 173 G4double GetH3YWidth(G4int id) const; 174 G4int GetH3Nzbins(G4int id) const; 175 G4double GetH3Zmin(G4int id) const; 176 G4double GetH3Zmax(G4int id) const; 177 G4double GetH3ZWidth(G4int id) const; 178 // 179 G4int GetP1Nbins(G4int id) const; 180 G4double GetP1Xmin(G4int id) const; 181 G4double GetP1Xmax(G4int id) const; 182 G4double GetP1XWidth(G4int id) const; 183 G4double GetP1Ymin(G4int id) const; 184 G4double GetP1Ymax(G4int id) const; 185 // 186 G4int GetP2Nxbins(G4int id) const; 187 G4double GetP2Xmin(G4int id) const; 188 G4double GetP2Xmax(G4int id) const; 189 G4double GetP2XWidth(G4int id) const; 190 G4int GetP2Nybins(G4int id) const; 191 G4double GetP2Ymin(G4int id) const; 192 G4double GetP2Ymax(G4int id) const; 193 G4double GetP2YWidth(G4int id) const; 194 G4double GetP2Zmin(G4int id) const; 195 G4double GetP2Zmax(G4int id) const; 196 197 // Access histogram & profiles attributes for plotting 198 // 199 G4String GetH1Title(G4int id) const; 200 G4String GetH1XAxisTitle(G4int id) const; 201 G4String GetH1YAxisTitle(G4int id) const; 202 // 203 G4String GetH2Title(G4int id) const; 204 G4String GetH2XAxisTitle(G4int id) const; 205 G4String GetH2YAxisTitle(G4int id) const; 206 G4String GetH2ZAxisTitle(G4int id) const; 207 // 208 G4String GetH3Title(G4int id) const; 209 G4String GetH3XAxisTitle(G4int id) const; 210 G4String GetH3YAxisTitle(G4int id) const; 211 G4String GetH3ZAxisTitle(G4int id) const; 212 // 213 G4String GetP1Title(G4int id) const; 214 G4String GetP1XAxisTitle(G4int id) const; 215 G4String GetP1YAxisTitle(G4int id) const; 216 G4String GetP1ZAxisTitle(G4int id) const; 217 // 218 G4String GetP2Title(G4int id) const; 219 G4String GetP2XAxisTitle(G4int id) const; 220 G4String GetP2YAxisTitle(G4int id) const; 221 G4String GetP2ZAxisTitle(G4int id) const; 222 223 // Verbosity 224 void SetVerboseLevel(G4int verboseLevel); 225 G4int GetVerboseLevel() const; 226 227 // The manager type (starts with an uppercase letter) 228 G4String GetType() const; 229 // The manager file type (starts with a lowercase letter) 230 G4String GetFileType() const; 231 232 protected: 233 explicit G4VAnalysisReader(const G4String& type); 234 235 // Virtual methods 236 virtual G4int ReadH1Impl(const G4String& h1Name, const G4String& fileName, 237 const G4String& dirName, G4bool isUserFileName) = 0; 238 virtual G4int ReadH2Impl(const G4String& h2Name, const G4String& fileName, 239 const G4String& dirName, G4bool isUserFileName) = 0; 240 virtual G4int ReadH3Impl(const G4String& h3Name, const G4String& fileName, 241 const G4String& dirName, G4bool isUserFileName) = 0; 242 virtual G4int ReadP1Impl(const G4String& p1Name, const G4String& fileName, 243 const G4String& dirName, G4bool isUserFileName) = 0; 244 virtual G4int ReadP2Impl(const G4String& p2Name, const G4String& fileName, 245 const G4String& dirName, G4bool isUserFileName) = 0; 246 virtual G4bool CloseFilesImpl(G4bool reset) = 0; 247 248 void Message(G4int level, 249 const G4String& action, 250 const G4String& objectType, 251 const G4String& objectName = "", 252 G4bool success = true) const; 253 254 // Methods 255 void SetH1Manager(G4VTBaseHnManager<kDim1>* h1Manager); 256 void SetH2Manager(G4VTBaseHnManager<kDim2>* h2Manager); 257 void SetH3Manager(G4VTBaseHnManager<kDim3>* h3Manager); 258 void SetP1Manager(G4VTBaseHnManager<kDim2>* p1Manager); 259 void SetP2Manager(G4VTBaseHnManager<kDim3>* p2Manager); 260 void SetNtupleManager(std::shared_ptr<G4VRNtupleManager> ntupleManager); 261 void SetFileManager(std::shared_ptr<G4VRFileManager> fileManager); 262 263 // Data members 264 G4AnalysisManagerState fState; 265 266 protected: 267 std::shared_ptr<G4VRFileManager> fVFileManager { nullptr }; 268 269 private: 270 // Static data members 271 static constexpr std::string_view fkClass { "G4VAnalysisReader" }; 272 273 // Data members 274 std::unique_ptr<G4VTBaseHnManager<kDim1>> fVH1Manager; 275 std::unique_ptr<G4VTBaseHnManager<kDim2>> fVH2Manager; 276 std::unique_ptr<G4VTBaseHnManager<kDim3>> fVH3Manager; 277 std::unique_ptr<G4VTBaseHnManager<kDim2>> fVP1Manager; 278 std::unique_ptr<G4VTBaseHnManager<kDim3>> fVP2Manager; 279 std::shared_ptr<G4VRNtupleManager> fVNtupleManager { nullptr }; 280 }; 281 282 // inline functions 283 284 #include "G4VAnalysisReader.icc" 285 286 #endif 287