Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:59:19

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 nonvirtual public interface reader class for g4tools based analysis.
0028 // It is defined as a composite of object manager base classes.
0029 // Individual use of the component managers is disabled
0030 // (except for file manager and Hn manager which are also used from
0031 //  other object managers).
0032 // The functions which has to be implemented in concrete managers
0033 // are declared as virtual protected.
0034 
0035 // Author: Ivana Hrivnacova, 09/04/2014 (ivana@ipno.in2p3.fr)
0036 
0037 #ifndef G4VAnalysisReader_h
0038 #define G4VAnalysisReader_h 1
0039 
0040 #include "G4AnalysisManagerState.hh"
0041 #include "G4AnalysisUtilities.hh"
0042 #include "globals.hh"
0043 
0044 #include "G4VTBaseHnManager.hh"  // make forward declaration if possible
0045 
0046 #include <vector>
0047 #include <memory>
0048 #include <string_view>
0049 
0050 class G4HnManager;
0051 class G4VRNtupleManager;
0052 class G4VRFileManager;
0053 
0054 using G4Analysis::kDim1;
0055 using G4Analysis::kDim2;
0056 using G4Analysis::kDim3;
0057 
0058 class G4VAnalysisReader
0059 {
0060   public:
0061     virtual ~G4VAnalysisReader();
0062 
0063     // Methods for handling files
0064     // G4bool OpenFile(const G4String& fileName = "");
0065     G4bool CloseFiles(G4bool reset = true);
0066 
0067     // Methods for handling files and directories names
0068     void SetFileName(const G4String& fileName);
0069     G4String GetFileName() const;
0070 
0071     // Methods to read histograms from a file
0072     G4int ReadH1(const G4String& h1Name, const G4String& fileName = "", const G4String& dirName = "");
0073     G4int ReadH2(const G4String& h2Name, const G4String& fileName = "", const G4String& dirName = "");
0074     G4int ReadH3(const G4String& h3Name, const G4String& fileName = "", const G4String& dirName = "");
0075     G4int ReadP1(const G4String& h1Name, const G4String& fileName = "", const G4String& dirName = "");
0076     G4int ReadP2(const G4String& h2Name, const G4String& fileName = "", const G4String& dirName = "");
0077 
0078     // The ids of histograms and ntuples are generated automatically
0079     // starting from 0; with following functions it is possible to
0080     // change the first Id to start from other value
0081     G4bool SetFirstHistoId(G4int firstId);
0082     G4bool SetFirstH1Id(G4int firstId);
0083     G4bool SetFirstH2Id(G4int firstId);
0084     G4bool SetFirstH3Id(G4int firstId);
0085     G4bool SetFirstProfileId(G4int firstId);
0086     G4bool SetFirstP1Id(G4int firstId);
0087     G4bool SetFirstP2Id(G4int firstId);
0088     G4bool SetFirstNtupleId(G4int firstId);
0089 
0090     // Methods to read ntuple from a file
0091     G4int GetNtuple(const G4String& ntupleName, const G4String& fileName = "", const G4String& dirName = "");
0092 
0093     // Methods for ntuple with id = FirstNtupleId
0094     G4bool SetNtupleIColumn(const G4String& columnName, G4int& value);
0095     G4bool SetNtupleFColumn(const G4String& columnName, G4float& value);
0096     G4bool SetNtupleDColumn(const G4String& columnName, G4double& value);
0097     G4bool SetNtupleSColumn(const G4String& columnName, G4String& value);
0098     // Bind the ntuple colums of vector type
0099     G4bool SetNtupleIColumn(const G4String& columnName,
0100                             std::vector<int>& vector);
0101     G4bool SetNtupleFColumn(const G4String& columnName,
0102                             std::vector<float>& vector);
0103     G4bool SetNtupleDColumn(const G4String& columnName,
0104                             std::vector<double>& vector);
0105     G4bool SetNtupleSColumn(const G4String& columnName,
0106                             std::vector<std::string>& vector);
0107     // Methods for ntuple with id > FirstNtupleId
0108     G4bool SetNtupleIColumn(G4int ntupleId, const G4String& columnName,
0109                             G4int& value);
0110     G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName,
0111                             G4float& value);
0112     G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
0113                             G4double& value);
0114     G4bool SetNtupleSColumn(G4int ntupleId, const G4String& columnName,
0115                             G4String& value);
0116     // Bind the ntuple colums of vector type
0117     G4bool SetNtupleIColumn(G4int ntupleId, const G4String& columnName,
0118                             std::vector<int>& vector);
0119     G4bool SetNtupleFColumn(G4int ntupleId, const G4String& columnName,
0120                             std::vector<float>& vector);
0121     G4bool SetNtupleDColumn(G4int ntupleId, const G4String& columnName,
0122                             std::vector<double>& vector);
0123     G4bool SetNtupleSColumn(G4int ntupleId, const G4String& columnName,
0124                             std::vector<std::string>& vector);
0125 
0126     G4bool GetNtupleRow();
0127     G4bool GetNtupleRow(G4int ntupleId);
0128 
0129     // ASCII option
0130 
0131     // Return false if there is no object selected for ASCII output,
0132     // return true otherwise
0133     G4bool IsAscii() const;
0134 
0135     // Access methods
0136     G4int GetNofH1s(G4bool onlyIfExist = false) const;
0137     G4int GetNofH2s(G4bool onlyIfExist = false) const;
0138     G4int GetNofH3s(G4bool onlyIfExist = false) const;
0139     G4int GetNofP1s(G4bool onlyIfExist = false) const;
0140     G4int GetNofP2s(G4bool onlyIfExist = false) const;
0141     G4int GetNofNtuples() const;
0142 
0143     // Access methods via names
0144     G4int GetH1Id(const G4String& name, G4bool warn = true) const;
0145     G4int GetH2Id(const G4String& name, G4bool warn = true) const;
0146     G4int GetH3Id(const G4String& name, G4bool warn = true) const;
0147     G4int GetP1Id(const G4String& name, G4bool warn = true) const;
0148     G4int GetP2Id(const G4String& name, G4bool warn = true) const;
0149 
0150     // Access to histogram & profiles parameters
0151     //
0152     G4int    GetH1Nbins(G4int id) const;
0153     G4double GetH1Xmin(G4int id) const;
0154     G4double GetH1Xmax(G4int id) const;
0155     G4double GetH1Width(G4int id) const;
0156     //
0157     G4int    GetH2Nxbins(G4int id) const;
0158     G4double GetH2Xmin(G4int id) const;
0159     G4double GetH2Xmax(G4int id) const;
0160     G4double GetH2XWidth(G4int id) const;
0161     G4int    GetH2Nybins(G4int id) const;
0162     G4double GetH2Ymin(G4int id) const;
0163     G4double GetH2Ymax(G4int id) const;
0164     G4double GetH2YWidth(G4int id) const;
0165     //
0166     G4int    GetH3Nxbins(G4int id) const;
0167     G4double GetH3Xmin(G4int id) const;
0168     G4double GetH3Xmax(G4int id) const;
0169     G4double GetH3XWidth(G4int id) const;
0170     G4int    GetH3Nybins(G4int id) const;
0171     G4double GetH3Ymin(G4int id) const;
0172     G4double GetH3Ymax(G4int id) const;
0173     G4double GetH3YWidth(G4int id) const;
0174     G4int    GetH3Nzbins(G4int id) const;
0175     G4double GetH3Zmin(G4int id) const;
0176     G4double GetH3Zmax(G4int id) const;
0177     G4double GetH3ZWidth(G4int id) const;
0178     //
0179     G4int    GetP1Nbins(G4int id) const;
0180     G4double GetP1Xmin(G4int id) const;
0181     G4double GetP1Xmax(G4int id) const;
0182     G4double GetP1XWidth(G4int id) const;
0183     G4double GetP1Ymin(G4int id) const;
0184     G4double GetP1Ymax(G4int id) const;
0185     //
0186     G4int    GetP2Nxbins(G4int id) const;
0187     G4double GetP2Xmin(G4int id) const;
0188     G4double GetP2Xmax(G4int id) const;
0189     G4double GetP2XWidth(G4int id) const;
0190     G4int    GetP2Nybins(G4int id) const;
0191     G4double GetP2Ymin(G4int id) const;
0192     G4double GetP2Ymax(G4int id) const;
0193     G4double GetP2YWidth(G4int id) const;
0194     G4double GetP2Zmin(G4int id) const;
0195     G4double GetP2Zmax(G4int id) const;
0196 
0197     // Access histogram & profiles attributes for plotting
0198     //
0199     G4String GetH1Title(G4int id) const;
0200     G4String GetH1XAxisTitle(G4int id) const;
0201     G4String GetH1YAxisTitle(G4int id) const;
0202     //
0203     G4String GetH2Title(G4int id) const;
0204     G4String GetH2XAxisTitle(G4int id) const;
0205     G4String GetH2YAxisTitle(G4int id) const;
0206     G4String GetH2ZAxisTitle(G4int id) const;
0207     //
0208     G4String GetH3Title(G4int id) const;
0209     G4String GetH3XAxisTitle(G4int id) const;
0210     G4String GetH3YAxisTitle(G4int id) const;
0211     G4String GetH3ZAxisTitle(G4int id) const;
0212     //
0213     G4String GetP1Title(G4int id) const;
0214     G4String GetP1XAxisTitle(G4int id) const;
0215     G4String GetP1YAxisTitle(G4int id) const;
0216     G4String GetP1ZAxisTitle(G4int id) const;
0217     //
0218     G4String GetP2Title(G4int id) const;
0219     G4String GetP2XAxisTitle(G4int id) const;
0220     G4String GetP2YAxisTitle(G4int id) const;
0221     G4String GetP2ZAxisTitle(G4int id) const;
0222 
0223     // Verbosity
0224     void  SetVerboseLevel(G4int verboseLevel);
0225     G4int GetVerboseLevel() const;
0226 
0227     // The manager type (starts with an uppercase letter)
0228     G4String GetType() const;
0229     // The manager file type (starts with a lowercase letter)
0230     G4String GetFileType() const;
0231 
0232   protected:
0233     explicit G4VAnalysisReader(const G4String& type);
0234 
0235     // Virtual methods
0236     virtual G4int  ReadH1Impl(const G4String& h1Name, const G4String& fileName,
0237                               const G4String& dirName, G4bool isUserFileName) = 0;
0238     virtual G4int  ReadH2Impl(const G4String& h2Name, const G4String& fileName,
0239                               const G4String& dirName, G4bool isUserFileName) = 0;
0240     virtual G4int  ReadH3Impl(const G4String& h3Name, const G4String& fileName,
0241                               const G4String& dirName, G4bool isUserFileName) = 0;
0242     virtual G4int  ReadP1Impl(const G4String& p1Name, const G4String& fileName,
0243                               const G4String& dirName, G4bool isUserFileName) = 0;
0244     virtual G4int  ReadP2Impl(const G4String& p2Name, const G4String& fileName,
0245                               const G4String& dirName, G4bool isUserFileName) = 0;
0246     virtual G4bool CloseFilesImpl(G4bool reset) = 0;
0247 
0248     void Message(G4int level,
0249                  const G4String& action,
0250                  const G4String& objectType,
0251                  const G4String& objectName = "",
0252                  G4bool success = true) const;
0253 
0254     // Methods
0255     void SetH1Manager(G4VTBaseHnManager<kDim1>* h1Manager);
0256     void SetH2Manager(G4VTBaseHnManager<kDim2>* h2Manager);
0257     void SetH3Manager(G4VTBaseHnManager<kDim3>* h3Manager);
0258     void SetP1Manager(G4VTBaseHnManager<kDim2>* p1Manager);
0259     void SetP2Manager(G4VTBaseHnManager<kDim3>* p2Manager);
0260     void SetNtupleManager(std::shared_ptr<G4VRNtupleManager> ntupleManager);
0261     void SetFileManager(std::shared_ptr<G4VRFileManager> fileManager);
0262 
0263     // Data members
0264     G4AnalysisManagerState fState;
0265 
0266   protected:
0267     std::shared_ptr<G4VRFileManager>  fVFileManager { nullptr };
0268 
0269   private:
0270     // Static data members
0271     static constexpr std::string_view fkClass { "G4VAnalysisReader" };
0272 
0273     // Data members
0274     std::unique_ptr<G4VTBaseHnManager<kDim1>> fVH1Manager;
0275     std::unique_ptr<G4VTBaseHnManager<kDim2>> fVH2Manager;
0276     std::unique_ptr<G4VTBaseHnManager<kDim3>> fVH3Manager;
0277     std::unique_ptr<G4VTBaseHnManager<kDim2>> fVP1Manager;
0278     std::unique_ptr<G4VTBaseHnManager<kDim3>> fVP2Manager;
0279     std::shared_ptr<G4VRNtupleManager> fVNtupleManager { nullptr };
0280 };
0281 
0282 // inline functions
0283 
0284 #include "G4VAnalysisReader.icc"
0285 
0286 #endif