G4XmlAnalysisManager.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 G4XmlAnalysisManager_h
00031 #define G4XmlAnalysisManager_h 1
00032 
00033 #include "G4VAnalysisManager.hh"
00034 #include "globals.hh"
00035 
00036 #include "tools/waxml/ntuple"
00037 #include "tools/ntuple_booking"
00038 #include "tools/histo/h1d"
00039 #include "tools/histo/h2d"
00040 
00041 #include <fstream>
00042 #include <vector>
00043 #include <map>
00044 
00045 class G4XmlAnalysisManager : public G4VAnalysisManager
00046 {
00047   public:
00048     G4XmlAnalysisManager();
00049     ~G4XmlAnalysisManager();
00050     
00051     // static methods
00052     static G4XmlAnalysisManager* Instance();
00053 
00054     // Methods to manipulate files
00055     using G4VAnalysisManager::OpenFile;
00056     virtual G4bool OpenFile(const G4String& fileName);
00057     virtual G4bool Write();
00058     virtual G4bool CloseFile(); 
00059 
00060     // Methods for handling histogrammes, ntuples
00061     virtual G4int CreateH1(const G4String& name, const G4String& title,
00062                            G4int nbins, G4double xmin, G4double xmax,
00063                            const G4String& unitName = "none",
00064                            const G4String& fcnName = "none");
00065     virtual G4int CreateH2(const G4String& name, const G4String& title,
00066                            G4int nxbins, G4double xmin, G4double xmax, 
00067                            G4int nybins, G4double ymin, G4double ymax,
00068                            const G4String& xunitName = "none", 
00069                            const G4String& yunitName = "none",
00070                            const G4String& xfcnName = "none", 
00071                            const G4String& yfcnName = "none");
00072                            
00073     virtual G4bool SetH1(G4int id,
00074                            G4int nbins, G4double xmin, G4double xmax,
00075                            const G4String& unitName = "none",
00076                            const G4String& fcnName = "none");
00077     virtual G4bool SetH2(G4int id,
00078                            G4int nxbins, G4double xmin, G4double xmax, 
00079                            G4int nybins, G4double ymin, G4double ymax,
00080                            const G4String& xunitName = "none", 
00081                            const G4String& yunitName = "none",
00082                            const G4String& xfcnName = "none", 
00083                            const G4String& yfcnName = "none");
00084 
00085     virtual G4bool ScaleH1(G4int id, G4double factor);
00086     virtual G4bool ScaleH2(G4int id, G4double factor);
00087                            
00088     virtual void  CreateNtuple(const G4String& name, const G4String& title);
00089     virtual G4int CreateNtupleIColumn(const G4String& name);
00090     virtual G4int CreateNtupleFColumn(const G4String& name);
00091     virtual G4int CreateNtupleDColumn(const G4String& name);   
00092     virtual void  FinishNtuple();   
00093     
00094     // Methods to fill histogrammes, ntuples
00095     virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
00096     virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
00097                           G4double weight = 1.0);
00098     virtual G4bool FillNtupleIColumn(G4int id, G4int value);
00099     virtual G4bool FillNtupleFColumn(G4int id, G4float value);
00100     virtual G4bool FillNtupleDColumn(G4int id, G4double value);
00101     virtual G4bool AddNtupleRow();
00102    
00103     // Access methods
00104     virtual tools::histo::h1d* GetH1(G4int id, G4bool warn = true,
00105                                      G4bool onlyIfActive = true) const;
00106     virtual tools::histo::h2d* GetH2(G4int id, G4bool warn = true,
00107                                      G4bool onlyIfActive = true) const;
00108     virtual tools::waxml::ntuple* GetNtuple() const;
00109 
00110     // Access methods via names
00111     virtual G4int  GetH1Id(const G4String& name, G4bool warn = true) const;
00112     virtual G4int  GetH2Id(const G4String& name, G4bool warn = true) const;
00113         
00114     // Access to H1 parameters
00115     virtual G4int    GetH1Nbins(G4int id) const;
00116     virtual G4double GetH1Xmin(G4int id) const;
00117     virtual G4double GetH1Xmax(G4int id) const;
00118     virtual G4double GetH1Width(G4int id) const;
00119 
00120     // Access to H2 parameters
00121     virtual G4int    GetH2Nxbins(G4int id) const;
00122     virtual G4double GetH2Xmin(G4int id) const;
00123     virtual G4double GetH2Xmax(G4int id) const;
00124     virtual G4double GetH2XWidth(G4int id) const;
00125     virtual G4int    GetH2Nybins(G4int id) const;
00126     virtual G4double GetH2Ymin(G4int id) const;
00127     virtual G4double GetH2Ymax(G4int id) const;
00128     virtual G4double GetH2YWidth(G4int id) const;
00129         
00130     // Setters for attributes for plotting
00131     virtual G4bool SetH1Title(G4int id, const G4String& title);
00132     virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
00133     virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
00134     virtual G4bool SetH2Title(G4int id, const G4String& title);
00135     virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
00136     virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
00137     virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
00138 
00139     // Access attributes for plotting
00140     virtual G4String GetH1Title(G4int id) const;
00141     virtual G4String GetH1XAxisTitle(G4int id) const;
00142     virtual G4String GetH1YAxisTitle(G4int id) const;
00143     virtual G4String GetH2Title(G4int id) const;
00144     virtual G4String GetH2XAxisTitle(G4int id) const;
00145     virtual G4String GetH2YAxisTitle(G4int id) const;
00146     virtual G4String GetH2ZAxisTitle(G4int id) const;
00147 
00148   protected:
00149     virtual G4bool WriteOnAscii(std::ofstream& output);
00150 
00151   private:
00152     // static data members
00153     //
00154     static G4XmlAnalysisManager* fgInstance;
00155 
00156     // methods
00157     //
00158     void CreateNtupleFromBooking();
00159     tools::waxml::ntuple::column<int>*    GetNtupleIColumn(G4int id) const;
00160     tools::waxml::ntuple::column<float>*  GetNtupleFColumn(G4int id) const;
00161     tools::waxml::ntuple::column<double>* GetNtupleDColumn(G4int id) const;
00162     virtual G4bool Reset();
00163     virtual tools::histo::h1d*  GetH1InFunction(G4int id, G4String function,
00164                                       G4bool warn = true,
00165                                       G4bool onlyIfActive = true) const;
00166     virtual tools::histo::h2d*  GetH2InFunction(G4int id, G4String function,
00167                                       G4bool warn = true,
00168                                       G4bool onlyIfActive = true) const;
00169  
00170     void UpdateTitle(G4String& title, 
00171                      const G4String& unitName, const G4String& fcnName) const;                                      
00172     
00173    // data members
00174     //
00175     //waxml*  fFile;
00176     std::ofstream* fFile;
00177 
00178     std::vector<tools::histo::h1d*>         fH1Vector;            
00179     std::vector<tools::histo::h2d*>         fH2Vector;            
00180     std::map<G4String, G4int>  fH1NameIdMap;            
00181     std::map<G4String, G4int>  fH2NameIdMap;            
00182     
00183     tools::waxml::ntuple*   fNtuple; 
00184     tools::ntuple_booking*  fNtupleBooking; 
00185     std::map<G4int, tools::waxml::ntuple::column<int>* >    fNtupleIColumnMap;           
00186     std::map<G4int, tools::waxml::ntuple::column<float>* >  fNtupleFColumnMap;           
00187     std::map<G4int, tools::waxml::ntuple::column<double>* > fNtupleDColumnMap;           
00188 };
00189 
00190 #endif
00191 

Generated on Mon May 27 17:50:26 2013 for Geant4 by  doxygen 1.4.7