G4RootAnalysisManager.hh

Go to the documentation of this file.
00001 //
00002 // ********************************************************************
00003 // * License and Disclaimer                                           *
00004 // *                                                                  *
00005 // * The  Geant4 software  is  copyright of the Copyright Holders  of *
00006 // * the Geant4 Collaboration.  It is provided  under  the terms  and *
00007 // * conditions of the Geant4 Software License,  included in the file *
00008 // * LICENSE and available at  http://cern.ch/geant4/license .  These *
00009 // * include a list of copyright holders.                             *
00010 // *                                                                  *
00011 // * Neither the authors of this software system, nor their employing *
00012 // * institutes,nor the agencies providing financial support for this *
00013 // * work  make  any representation or  warranty, express or implied, *
00014 // * regarding  this  software system or assume any liability for its *
00015 // * use.  Please see the license in the file  LICENSE  and URL above *
00016 // * for the full disclaimer and the limitation of liability.         *
00017 // *                                                                  *
00018 // * This  code  implementation is the result of  the  scientific and *
00019 // * technical work of the GEANT4 collaboration.                      *
00020 // * By using,  copying,  modifying or  distributing the software (or *
00021 // * any work based  on the software)  you  agree  to acknowledge its *
00022 // * use  in  resulting  scientific  publications,  and indicate your *
00023 // * acceptance of all terms of the Geant4 Software license.          *
00024 // ********************************************************************
00025 //
00026 // $Id$
00027 
00028 // Author: Ivana Hrivnacova, 15/06/2011  (ivana@ipno.in2p3.fr)
00029 
00030 #ifndef G4RootAnalysisManager_h
00031 #define G4RootAnalysisManager_h 1
00032 
00033 #include "G4VAnalysisManager.hh"
00034 #include "globals.hh"
00035 
00036 #include "tools/wroot/file"
00037 #include "tools/wroot/to"
00038 #include "tools/ntuple_booking"
00039 #include "tools/wroot/ntuple"
00040 #include "tools/histo/h1d"
00041 #include "tools/histo/h2d"
00042 
00043 #include <vector>
00044 #include <map>
00045 
00046 class G4RootAnalysisManager : public G4VAnalysisManager
00047 {
00048   public:
00049     G4RootAnalysisManager();
00050     virtual ~G4RootAnalysisManager();
00051     
00052     // static methods
00053     static G4RootAnalysisManager* Instance();
00054 
00055     // Methods to manipulate files
00056     using G4VAnalysisManager::OpenFile;
00057     virtual G4bool OpenFile(const G4String& fileName);
00058     virtual G4bool Write();
00059     virtual G4bool CloseFile(); 
00060    
00061     // Methods to create histogrammes, ntuples
00062     virtual G4int CreateH1(const G4String& name, const G4String& title,
00063                            G4int nbins, G4double xmin, G4double xmax,
00064                            const G4String& unitName = "none",
00065                            const G4String& fcnName = "none");
00066     virtual G4int CreateH2(const G4String& name, const G4String& title,
00067                            G4int nxbins, G4double xmin, G4double xmax, 
00068                            G4int nybins, G4double ymin, G4double ymax,
00069                            const G4String& xunitName = "none", 
00070                            const G4String& yunitName = "none",
00071                            const G4String& xfcnName = "none", 
00072                            const G4String& yfcnName = "none");
00073                            
00074     virtual G4bool SetH1(G4int id,
00075                            G4int nbins, G4double xmin, G4double xmax,
00076                            const G4String& unitName = "none",
00077                            const G4String& fcnName = "none");
00078     virtual G4bool SetH2(G4int id,
00079                            G4int nxbins, G4double xmin, G4double xmax, 
00080                            G4int nybins, G4double ymin, G4double ymax,
00081                            const G4String& xunitName = "none", 
00082                            const G4String& yunitName = "none",
00083                            const G4String& xfcnName = "none", 
00084                            const G4String& yfcnName = "none");
00085 
00086     virtual G4bool ScaleH1(G4int id, G4double factor);
00087     virtual G4bool ScaleH2(G4int id, G4double factor);
00088                            
00089     virtual void  CreateNtuple(const G4String& name, const G4String& title);
00090     virtual G4int CreateNtupleIColumn(const G4String& name);
00091     virtual G4int CreateNtupleFColumn(const G4String& name);
00092     virtual G4int CreateNtupleDColumn(const G4String& name);   
00093     virtual void  FinishNtuple();   
00094   
00095     // Methods to fill histogrammes, ntuples
00096     virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
00097     virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
00098                           G4double weight = 1.0);
00099     virtual G4bool FillNtupleIColumn(G4int id, G4int value);
00100     virtual G4bool FillNtupleFColumn(G4int id, G4float value);
00101     virtual G4bool FillNtupleDColumn(G4int id, G4double value);
00102     virtual G4bool AddNtupleRow();
00103     
00104     // Access methods
00105     virtual tools::histo::h1d*  GetH1(G4int id, G4bool warn = true,
00106                                       G4bool onlyIfActive = true) const;
00107     virtual tools::histo::h2d*  GetH2(G4int id, G4bool warn = true,
00108                                       G4bool onlyIfActive = true) const;
00109     
00110     virtual tools::wroot::ntuple* GetNtuple() const;
00111 
00112     // Access methods via names
00113     virtual G4int  GetH1Id(const G4String& name, G4bool warn = true) const;
00114     virtual G4int  GetH2Id(const G4String& name, G4bool warn = true) const;
00115 
00116     // Access to H1 parameters
00117     virtual G4int    GetH1Nbins(G4int id) const;
00118     virtual G4double GetH1Xmin(G4int id) const;
00119     virtual G4double GetH1Xmax(G4int id) const;
00120     virtual G4double GetH1Width(G4int id) const;
00121 
00122     // Access to H2 parameters
00123     virtual G4int    GetH2Nxbins(G4int id) const;
00124     virtual G4double GetH2Xmin(G4int id) const;
00125     virtual G4double GetH2Xmax(G4int id) const;
00126     virtual G4double GetH2XWidth(G4int id) const;
00127     virtual G4int    GetH2Nybins(G4int id) const;
00128     virtual G4double GetH2Ymin(G4int id) const;
00129     virtual G4double GetH2Ymax(G4int id) const;
00130     virtual G4double GetH2YWidth(G4int id) const;
00131         
00132     // Setters for attributes for plotting
00133     virtual G4bool SetH1Title(G4int id, const G4String& title);
00134     virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
00135     virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
00136     virtual G4bool SetH2Title(G4int id, const G4String& title);
00137     virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
00138     virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
00139     virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
00140 
00141     // Access attributes for plotting
00142     virtual G4String GetH1Title(G4int id) const;
00143     virtual G4String GetH1XAxisTitle(G4int id) const;
00144     virtual G4String GetH1YAxisTitle(G4int id) const;
00145     virtual G4String GetH2Title(G4int id) const;
00146     virtual G4String GetH2XAxisTitle(G4int id) const;
00147     virtual G4String GetH2YAxisTitle(G4int id) const;
00148     virtual G4String GetH2ZAxisTitle(G4int id) const;
00149 
00150   protected:
00151     virtual G4bool WriteOnAscii(std::ofstream& output);
00152 
00153   private:
00154     // static data members
00155     //
00156     static G4RootAnalysisManager* fgInstance;
00157 
00158     // methods
00159     //
00160     G4bool CreateHistoDirectory();
00161     G4bool CreateNtupleDirectory();
00162     void CreateNtupleFromBooking();
00163     tools::wroot::ntuple::column<int>*    GetNtupleIColumn(G4int id) const;
00164     tools::wroot::ntuple::column<float>*  GetNtupleFColumn(G4int id) const;
00165     tools::wroot::ntuple::column<double>* GetNtupleDColumn(G4int id) const;
00166     virtual G4bool Reset();
00167     virtual tools::histo::h1d*  GetH1InFunction(G4int id, G4String function,
00168                                       G4bool warn = true,
00169                                       G4bool onlyIfActive = true) const;
00170     virtual tools::histo::h2d*  GetH2InFunction(G4int id, G4String function,
00171                                       G4bool warn = true,
00172                                       G4bool onlyIfActive = true) const;
00173     void UpdateTitle(G4String& title, 
00174                      const G4String& unitName, const G4String& fcnName) const;                                      
00175 
00176     // data members
00177     //
00178     tools::wroot::file*       fFile;
00179     tools::wroot::directory*  fHistoDirectory;
00180     tools::wroot::directory*  fNtupleDirectory;
00181 
00182     std::vector<tools::histo::h1d*>  fH1Vector;            
00183     std::vector<tools::histo::h2d*>  fH2Vector;            
00184     std::map<G4String, G4int>  fH1NameIdMap;            
00185     std::map<G4String, G4int>  fH2NameIdMap;            
00186     
00187     tools::wroot::ntuple*   fNtuple; 
00188     tools::ntuple_booking*  fNtupleBooking; 
00189     std::map<G4int, tools::wroot::ntuple::column<int>* >    fNtupleIColumnMap;           
00190     std::map<G4int, tools::wroot::ntuple::column<float>* >  fNtupleFColumnMap;           
00191     std::map<G4int, tools::wroot::ntuple::column<double>* > fNtupleDColumnMap;           
00192 };
00193 
00194 #endif
00195 

Generated on Mon May 27 17:49:44 2013 for Geant4 by  doxygen 1.4.7