G4VAnalysisManager.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 G4VAnalysisManager_h
00031 #define G4VAnalysisManager_h 1
00032 
00033 #include "G4AnalysisVerbose.hh"
00034 #include "G4HnInformation.hh"
00035 #include "globals.hh"
00036 
00037 #include <vector>
00038 #include <fstream>
00039 
00040 class G4AnalysisMessenger;
00041 
00042 class G4VAnalysisManager
00043 {
00044   public:
00045     // Supported object types
00046     enum ObjectType { kH1, kH2, kNtuple };
00047 
00048   public:
00049     G4VAnalysisManager(const G4String& type = "");
00050     virtual ~G4VAnalysisManager();
00051    
00052     // Methods to manipulate files
00053     virtual G4bool OpenFile();
00054     virtual G4bool OpenFile(const G4String& fileName) = 0;
00055     virtual G4bool Write() = 0; 
00056     virtual G4bool CloseFile() = 0; 
00057     
00058     // Methods for handling files and directories names
00059     virtual G4bool SetFileName(const G4String& fileName);
00060     virtual G4bool SetHistoDirectoryName(const G4String& dirName);
00061     virtual G4bool SetNtupleDirectoryName(const G4String& dirName);
00062     virtual G4String GetFileName() const;
00063     virtual G4String GetFullFileName() const;
00064     virtual G4String GetHistoDirectoryName() const;
00065     virtual G4String GetNtupleDirectoryName() const;
00066     
00067     // Methods for handling histogrammes
00068     virtual G4int CreateH1(const G4String& name, const G4String& title,
00069                            G4int nbins, G4double xmin, G4double xmax,
00070                            const G4String& unitName = "none",
00071                            const G4String& fcnName = "none") = 0;
00072     virtual G4int CreateH2(const G4String& name, const G4String& title,
00073                            G4int nxbins, G4double xmin, G4double xmax, 
00074                            G4int nybins, G4double ymin, G4double ymax,
00075                            const G4String& xunitName = "none", 
00076                            const G4String& yunitName = "none",
00077                            const G4String& xfcnName = "none", 
00078                            const G4String& yfcnName = "none") = 0;
00079                            
00080     virtual G4bool SetH1(G4int id,
00081                            G4int nbins, G4double xmin, G4double xmax,
00082                            const G4String& unitName = "none",
00083                            const G4String& fcnName = "none") = 0;
00084     virtual G4bool SetH2(G4int id,
00085                            G4int nxbins, G4double xmin, G4double xmax, 
00086                            G4int nybins, G4double ymin, G4double ymax,
00087                            const G4String& xunitName = "none", 
00088                            const G4String& yunitName = "none",
00089                            const G4String& xfcnName = "none", 
00090                            const G4String& yfcnName = "none") = 0;
00091 
00092     virtual G4bool ScaleH1(G4int id, G4double factor) = 0;
00093     virtual G4bool ScaleH2(G4int id, G4double factor) = 0;
00094                            
00095     // Methods for handling ntuples
00096     virtual void  CreateNtuple(const G4String& name, const G4String& title) = 0;
00097     virtual G4int CreateNtupleIColumn(const G4String& name) = 0;
00098     virtual G4int CreateNtupleFColumn(const G4String& name) = 0;
00099     virtual G4int CreateNtupleDColumn(const G4String& name) = 0;
00100     virtual void  FinishNtuple() = 0;   
00101     
00102     // The ids of histograms and ntuples are generated automatically
00103     // starting from 0; with following functions it is possible to
00104     // change the first Id to start from other value
00105     virtual G4bool SetFirstHistoId(G4int firstId);
00106     virtual G4bool SetFirstNtupleColumnId(G4int firstId);
00107   
00108     // Methods to fill histogrammes, ntuples
00109     virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0) = 0;
00110     virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
00111                           G4double weight = 1.0) = 0;
00112     virtual G4bool FillNtupleIColumn(G4int id, G4int value) = 0;
00113     virtual G4bool FillNtupleFColumn(G4int id, G4float value) = 0;
00114     virtual G4bool FillNtupleDColumn(G4int id, G4double value) = 0;
00115     virtual G4bool AddNtupleRow() = 0;
00116     
00117     // Activation option
00118     
00119     // When this option is enabled, only the histograms marked as activated
00120     // are returned, filled or saved on file.
00121     // No warning is issued when Get or Fill is called on inactive histogram.
00122     void   SetActivation(G4bool activation);
00123     G4bool GetActivation() const;
00124 
00125     // Return false if activation is enabled and there is no object activated,
00126     // return true otherwise
00127     G4bool IsActive() const;
00128 
00129     // ASCII option
00130 
00131     // Return false if there is no object selected for ASCII output,
00132     // return true otherwise
00133     G4bool IsAscii() const;
00134 
00135     // Access methods
00136     virtual G4int GetNofH1s() const;
00137     virtual G4int GetNofH2s() const;
00138     
00139     // Methods to manipulate additional information
00140 
00141     // Setters for additional information by fields
00142     // (other fields are set by SetH1, SetH2 methods)
00143     void  SetActivation(ObjectType type, G4bool activation);
00144     void  SetActivation(ObjectType type, G4int id, G4bool activation);
00145     void  SetAscii(ObjectType type, G4int id, G4bool ascii);
00146     
00147     // Access to H1 parameters
00148     virtual G4int    GetH1Nbins(G4int id) const = 0;
00149     virtual G4double GetH1Xmin(G4int id) const = 0;
00150     virtual G4double GetH1Xmax(G4int id) const = 0;
00151     virtual G4double GetH1Width(G4int id) const = 0;
00152     
00153     // Access to H2 parameters
00154     virtual G4int    GetH2Nxbins(G4int id) const = 0;
00155     virtual G4double GetH2Xmin(G4int id) const = 0;
00156     virtual G4double GetH2Xmax(G4int id) const = 0;
00157     virtual G4double GetH2XWidth(G4int id) const = 0;
00158     virtual G4int    GetH2Nybins(G4int id) const = 0;
00159     virtual G4double GetH2Ymin(G4int id) const = 0;
00160     virtual G4double GetH2Ymax(G4int id) const = 0;
00161     virtual G4double GetH2YWidth(G4int id) const = 0;
00162 
00163     // Access to H1 additional information
00164     G4String GetH1Name(G4int id) const;
00165     G4double GetH1Unit(G4int id) const;
00166     G4bool   GetH1Activation(G4int id) const;
00167     G4bool   GetH1Ascii(G4int id) const;
00168 
00169     // Access to H2 additional information
00170     G4String GetH2Name(G4int id) const;
00171     G4double GetH2XUnit(G4int id) const;
00172     G4double GetH2YUnit(G4int id) const;
00173     G4bool   GetH2Activation(G4int id) const;
00174     G4bool   GetH2Ascii(G4int id) const;
00175     
00176     // Setters for attributes for plotting
00177     virtual G4bool SetH1Title(G4int id, const G4String& title) = 0;
00178     virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title) = 0;
00179     virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title) = 0;
00180     virtual G4bool SetH2Title(G4int id, const G4String& title) = 0;
00181     virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title) = 0;
00182     virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title) = 0;
00183     virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title) = 0;
00184 
00185     // Access attributes for plotting
00186     virtual G4String GetH1Title(G4int id) const = 0;
00187     virtual G4String GetH1XAxisTitle(G4int id) const = 0;
00188     virtual G4String GetH1YAxisTitle(G4int id) const = 0;
00189     virtual G4String GetH2Title(G4int id) const = 0;
00190     virtual G4String GetH2XAxisTitle(G4int id) const = 0;
00191     virtual G4String GetH2YAxisTitle(G4int id) const = 0;
00192     virtual G4String GetH2ZAxisTitle(G4int id) const = 0;
00193 
00194     // Verbosity
00195     virtual G4int GetVerboseLevel() const;
00196     virtual void  SetVerboseLevel(G4int verboseLevel);
00197 
00198     // The manager type (starts with an uppercase letter)
00199     G4String GetType() const;                 
00200     // The manager file type (starts with a lowercase letter)
00201     G4String GetFileType() const;                 
00202     
00203   protected:
00204     // methods to manipulate additional information
00205     void   AddH1Information(const G4String& name, 
00206                             const G4String& unitName,
00207                             const G4String& fcnName,
00208                             G4double unit, 
00209                             G4Fcn fx);
00210     void   AddH2Information(const G4String& name,
00211                             const G4String& xunitName, 
00212                             const G4String& yunitName,
00213                             const G4String& xfcnName,
00214                             const G4String& yfcnName,
00215                             G4double xunit, G4double yunit, 
00216                             G4Fcn fx, G4Fcn fy); 
00217     
00218     // Methods to access additional information
00219     G4HnInformation* GetH1Information(G4int id) const;
00220     G4HnInformation* GetH2Information(G4int id) const;
00221     G4HnInformation* GetInformation(ObjectType type, G4int id) const;
00222     
00223     // Access to additional information by fields
00224     G4String GetName(ObjectType type, G4int id) const;
00225     G4double GetXUnit(ObjectType type, G4int id) const;
00226     G4double GetYUnit(ObjectType type, G4int id) const;
00227     G4bool   GetActivation(ObjectType type, G4int id) const;
00228     G4bool   GetAscii(ObjectType type, G4int id) const;
00229     
00230     G4bool  WriteAscii(); 
00231     virtual G4bool WriteOnAscii(std::ofstream& output) = 0;
00232     
00233     G4double GetUnitValue(const G4String& unit) const;
00234     G4Fcn    GetFunction(const G4String& fcnName) const;
00235     
00236     // data members
00237     G4int    fVerboseLevel;
00238     G4bool   fActivation;
00239     G4int    fFirstHistoId;
00240     G4int    fFirstNtupleColumnId;
00241     G4String fFileName;
00242     G4String fHistoDirectoryName;
00243     G4String fNtupleDirectoryName; 
00244     G4bool   fLockFirstHistoId;     
00245     G4bool   fLockFirstNtupleColumnId;     
00246     G4bool   fLockFileName;     
00247     G4bool   fLockHistoDirectoryName;     
00248     G4bool   fLockNtupleDirectoryName;
00249 
00250     // Additional histograms properties not included in tools
00251     G4AnalysisVerbose  fVerboseL1;
00252     G4AnalysisVerbose  fVerboseL2;
00253     G4AnalysisVerbose  fVerboseL3;
00254     G4AnalysisVerbose  fVerboseL4;
00255     G4AnalysisVerbose* fpVerboseL1;
00256     G4AnalysisVerbose* fpVerboseL2;
00257     G4AnalysisVerbose* fpVerboseL3;
00258     G4AnalysisVerbose* fpVerboseL4;
00259  
00260   private:
00261     G4AnalysisMessenger* fMessenger;    
00262     G4int   fNofActiveObjects;
00263     G4int   fNofAsciiObjects;
00264 
00265     // Additional histograms/ntuple properties not included in tools
00266     std::vector<G4HnInformation*> fH1Informations;
00267     std::vector<G4HnInformation*> fH2Informations;
00268 };
00269 
00270 // inline functions
00271 
00272 inline G4String G4VAnalysisManager::GetFileName() const {
00273   return fFileName;
00274 }  
00275 
00276 inline G4String G4VAnalysisManager::GetHistoDirectoryName() const {
00277   return fHistoDirectoryName;
00278 }  
00279 
00280 inline G4String G4VAnalysisManager::GetNtupleDirectoryName() const {
00281   return fNtupleDirectoryName;
00282 }  
00283 
00284 inline G4int G4VAnalysisManager::GetVerboseLevel() const {
00285   return fVerboseLevel;
00286 }  
00287 
00288 inline  G4String G4VAnalysisManager::GetType() const {
00289   return fVerboseL1.GetType();
00290 }                 
00291 
00292 inline  void  G4VAnalysisManager::SetActivation(G4bool activation) {
00293   fActivation = activation;
00294 }
00295 
00296 inline G4bool G4VAnalysisManager::GetActivation() const {
00297   return fActivation;
00298 }  
00299 
00300 inline  G4int  G4VAnalysisManager::GetNofH1s() const { 
00301   return fH1Informations.size();
00302 }
00303   
00304 inline  G4int  G4VAnalysisManager::GetNofH2s() const {
00305   return fH2Informations.size();
00306 }
00307 
00308 inline G4String G4VAnalysisManager::GetH1Name(G4int id) const {
00309   return GetName(kH1, id);
00310 }  
00311   
00312 inline G4double G4VAnalysisManager::GetH1Unit(G4int id) const {
00313   return GetXUnit(kH1, id);
00314 }
00315   
00316 inline G4bool G4VAnalysisManager::GetH1Activation(G4int id) const {
00317  return GetActivation(kH1, id);
00318 }
00319  
00320 inline G4bool G4VAnalysisManager::GetH1Ascii(G4int id) const {
00321   return GetAscii(kH1, id);
00322 }  
00323 
00324 inline G4String G4VAnalysisManager::GetH2Name(G4int id) const {
00325   return GetName(kH2, id);
00326 }  
00327 
00328 inline G4double G4VAnalysisManager::GetH2XUnit(G4int id) const {
00329   return GetXUnit(kH2, id);
00330 }
00331 
00332 inline G4double G4VAnalysisManager::GetH2YUnit(G4int id) const {
00333   return GetYUnit(kH2, id);
00334 }
00335 
00336 inline G4bool G4VAnalysisManager::GetH2Activation(G4int id) const {
00337  return GetActivation(kH2, id);
00338 }
00339 
00340 inline G4bool G4VAnalysisManager::GetH2Ascii(G4int id) const {
00341   return GetAscii(kH2, id);
00342 }  
00343   
00344 #endif
00345 

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