Import Geant4 10.0.0 source tree

This commit is contained in:
Gabriele Cosmo
2016-06-10 11:51:14 +02:00
parent e2d2f9810a
commit 286caacf06
12421 changed files with 730077 additions and 502383 deletions
+18
View File
@@ -0,0 +1,18 @@
#------------------------------------------------------------------------------
# CMakeLists.txt
# Module : G4analysis
# Package: Geant4.src.G4analysis.G4hntools
#
# CMakeLists.txt for building a single granular library.
#
# Created on : 15/07/2013
#
# $Id: CMakeLists.txt 72292 2013-07-15 12:01:43Z ihrivnac $
#
#------------------------------------------------------------------------------
if(GEANT4_BUILD_GRANULAR_LIBS)
include(Geant4MacroLibraryTargets)
GEANT4_GRANULAR_LIBRARY_TARGET(COMPONENT sources.cmake)
endif()
+19
View File
@@ -0,0 +1,19 @@
# $Id: GNUmakefile 66356 2012-12-18 09:02:32Z gcosmo $
# --------------------------------------------------------------------
# GNUmakefile for geometry/biasing library. Gabriele Cosmo, 25/03/02.
# --------------------------------------------------------------------
name := G4hntools
ifndef G4INSTALL
G4INSTALL = ../../..
endif
include $(G4INSTALL)/config/architecture.gmk
CPPFLAGS += -I$(G4BASE)/global/management/include \
-I$(G4BASE)/intercoms/include \
-I$(G4BASE)/analysis/g4tools/include \
-I$(G4BASE)/analysis/management/include
include $(G4INSTALL)/config/common.gmk
@@ -0,0 +1,105 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4H1DummyManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Manager class for H1 for managers which do not support this object
// type. It will just issue warnings.
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4H1DummyManager_h
#define G4H1DummyManager_h 1
#include "G4VH1Manager.hh"
#include "globals.hh"
class G4H1DummyManager : public G4VH1Manager
{
public:
G4H1DummyManager(const G4AnalysisManagerState& state);
virtual ~G4H1DummyManager();
protected:
// Virtual functions from base class
// Methods to create histograms
//
virtual G4int CreateH1(const G4String& name, const G4String& title,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName = "none",
const G4String& fcnName = "none",
const G4String& binScheme = "linear");
virtual G4int CreateH1(const G4String& name, const G4String& title,
const std::vector<G4double>& edges,
const G4String& unitName = "none",
const G4String& fcnName = "none");
virtual G4bool SetH1(G4int id,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName = "none",
const G4String& fcnName = "none",
const G4String& binSchemeName = "linear");
virtual G4bool SetH1(G4int id,
const std::vector<G4double>& edges,
const G4String& unitName = "none",
const G4String& fcnName = "none");
virtual G4bool ScaleH1(G4int id, G4double factor);
// Method to fill histograms
//
virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
// Access methods
//
virtual G4int GetNofH1s() const;
virtual G4int GetH1Id(const G4String& name, G4bool warn = true) const;
// Access to H1 parameters
virtual G4int GetH1Nbins(G4int id) const;
virtual G4double GetH1Xmin(G4int id) const;
virtual G4double GetH1Xmax(G4int id) const;
virtual G4double GetH1Width(G4int id) const;
// Attributes for plotting
//
// Setters
virtual G4bool SetH1Title(G4int id, const G4String& title);
virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
// Accessors
virtual G4String GetH1Title(G4int id) const;
virtual G4String GetH1XAxisTitle(G4int id) const;
virtual G4String GetH1YAxisTitle(G4int id) const;
// Write data on ASCII file
virtual G4bool WriteOnAscii(std::ofstream& output);
};
#endif
@@ -0,0 +1,160 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4H1ToolsManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Manager class for tools::histo::h1d.
// It implements functions specific to the H1 type
// (defined in g4tools).
//
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4H1ToolsManager_h
#define G4H1ToolsManager_h 1
#include "G4VH1Manager.hh"
#include "G4HnManager.hh"
#include "G4BinScheme.hh"
#include "globals.hh"
#include <vector>
#include <map>
namespace tools {
namespace histo {
class h1d;
}
}
class G4H1ToolsManager : public G4VH1Manager
{
public:
G4H1ToolsManager(const G4AnalysisManagerState& state);
virtual ~G4H1ToolsManager();
// Method for merge (MT)
void AddH1Vector(const std::vector<tools::histo::h1d*>& h1Vector);
// Reset data
G4bool Reset();
// Return true if the H1 vector is empty
G4bool IsEmpty() const;
// Access methods
//
tools::histo::h1d* GetH1(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
// Access to histogram vector (needed for Write())
const std::vector<tools::histo::h1d*>& GetH1Vector() const;
const std::vector<G4HnInformation*>& GetHnVector() const;
protected:
// Virtual functions from base class
//
// Methods to create histograms
//
virtual G4int CreateH1(const G4String& name, const G4String& title,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName = "none",
const G4String& fcnName = "none",
const G4String& binScheme = "linear");
virtual G4int CreateH1(const G4String& name, const G4String& title,
const std::vector<G4double>& edges,
const G4String& unitName = "none",
const G4String& fcnName = "none");
virtual G4bool SetH1(G4int id,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName = "none",
const G4String& fcnName = "none",
const G4String& binSchemeName = "linear");
virtual G4bool SetH1(G4int id,
const std::vector<G4double>& edges,
const G4String& unitName = "none",
const G4String& fcnName = "none");
virtual G4bool ScaleH1(G4int id, G4double factor);
// Method to fill histograms
//
virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
// Access methods
//
virtual G4int GetH1Id(const G4String& name, G4bool warn = true) const;
// Access to H1 parameters
virtual G4int GetH1Nbins(G4int id) const;
virtual G4double GetH1Xmin(G4int id) const;
virtual G4double GetH1Xmax(G4int id) const;
virtual G4double GetH1Width(G4int id) const;
// Attributes for plotting
//
// Setters
virtual G4bool SetH1Title(G4int id, const G4String& title);
virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
// Accessors
virtual G4String GetH1Title(G4int id) const;
virtual G4String GetH1XAxisTitle(G4int id) const;
virtual G4String GetH1YAxisTitle(G4int id) const;
// Write data on ASCII file
virtual G4bool WriteOnAscii(std::ofstream& output);
private:
// methods
//
virtual tools::histo::h1d* GetH1InFunction(G4int id,
G4String functionName,
G4bool warn = true,
G4bool onlyIfActive = true) const;
void AddH1Information(const G4String& name,
const G4String& unitName,
const G4String& fcnName,
G4BinScheme binScheme) const;
G4int RegisterToolsH1(tools::histo::h1d* h1d,
const G4String& name);
// data members
//
std::vector<tools::histo::h1d*> fH1Vector;
std::map<G4String, G4int> fH1NameIdMap;
};
// inline methods
inline const std::vector<tools::histo::h1d*>& G4H1ToolsManager::GetH1Vector() const
{ return fH1Vector; }
inline const std::vector<G4HnInformation*>& G4H1ToolsManager::GetHnVector() const
{ return fHnManager->GetHnVector(); }
#endif
@@ -0,0 +1,128 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4H2DummyManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Manager class for H2 for managers which do not support this object
// type. It will just issue warnings.
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4H2DummyManager_h
#define G4H2DummyManager_h 1
#include "G4VH2Manager.hh"
#include "globals.hh"
class G4H2DummyManager : public G4VH2Manager
{
public:
G4H2DummyManager(const G4AnalysisManagerState& state);
virtual ~G4H2DummyManager();
protected:
// Virtual functions from base class
//
// Methods to create histograms
//
virtual G4int CreateH2(const G4String& name, const G4String& title,
G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax,
const G4String& xunitName = "none",
const G4String& yunitName = "none",
const G4String& xfcnName = "none",
const G4String& yfcnName = "none",
const G4String& xbinScheme = "linear",
const G4String& ybinScheme = "linear");
virtual G4int CreateH2(const G4String& name, const G4String& title,
const std::vector<G4double>& xedges,
const std::vector<G4double>& yedges,
const G4String& xunitName = "none",
const G4String& yunitName = "none",
const G4String& xfcnName = "none",
const G4String& yfcnName = "none");
virtual G4bool SetH2(G4int id,
G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax,
const G4String& xunitName = "none",
const G4String& yunitName = "none",
const G4String& xfcnName = "none",
const G4String& yfcnName = "none",
const G4String& xbinScheme = "linear",
const G4String& ybinScheme = "linear");
virtual G4bool SetH2(G4int id,
const std::vector<G4double>& xedges,
const std::vector<G4double>& yedges,
const G4String& xunitName = "none",
const G4String& yunitName = "none",
const G4String& xfcnName = "none",
const G4String& yfcnName = "none");
virtual G4bool ScaleH2(G4int id, G4double factor);
// Method to fill histograms
//
virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
G4double weight = 1.0);
// Methods to manipulate histograms
//
// Access methods
virtual G4int GetNofH2s() const;
virtual G4int GetH2Id(const G4String& name, G4bool warn = true) const;
// Access to H2 parameters
virtual G4int GetH2Nxbins(G4int id) const;
virtual G4double GetH2Xmin(G4int id) const;
virtual G4double GetH2Xmax(G4int id) const;
virtual G4double GetH2XWidth(G4int id) const;
virtual G4int GetH2Nybins(G4int id) const;
virtual G4double GetH2Ymin(G4int id) const;
virtual G4double GetH2Ymax(G4int id) const;
virtual G4double GetH2YWidth(G4int id) const;
// Setters for attributes for plotting
virtual G4bool SetH2Title(G4int id, const G4String& title);
virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
// Access attributes for plotting
virtual G4String GetH2Title(G4int id) const;
virtual G4String GetH2XAxisTitle(G4int id) const;
virtual G4String GetH2YAxisTitle(G4int id) const;
virtual G4String GetH2ZAxisTitle(G4int id) const;
// Write data on ASCII file
virtual G4bool WriteOnAscii(std::ofstream& output);
};
#endif
@@ -0,0 +1,183 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4H2ToolsManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
// Manager class for tools::histo::h2d.
// It implements functions specific to the H2 type
// (defined in g4tools).
//
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#ifndef G4H2ToolsManager_h
#define G4H2ToolsManager_h 1
#include "G4VH2Manager.hh"
#include "G4HnManager.hh"
#include "globals.hh"
#include <vector>
#include <map>
namespace tools {
namespace histo {
class h2d;
}
}
class G4H2ToolsManager : public G4VH2Manager
{
public:
G4H2ToolsManager(const G4AnalysisManagerState& state);
virtual ~G4H2ToolsManager();
// Method for merge (MT)
void AddH2Vector(const std::vector<tools::histo::h2d*>& h2Vector);
// Reset data
G4bool Reset();
// Return true if the H2 vector is empty
G4bool IsEmpty() const;
// Access methods
//
tools::histo::h2d* GetH2(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
// Access to histogram vector (needed for Write())
const std::vector<tools::histo::h2d*>& GetH2Vector() const;
const std::vector<G4HnInformation*>& GetHnVector() const;
protected:
// Virtual functions from base class
//
// Methods to create histograms
//
virtual G4int CreateH2(const G4String& name, const G4String& title,
G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax,
const G4String& xunitName = "none",
const G4String& yunitName = "none",
const G4String& xfcnName = "none",
const G4String& yfcnName = "none",
const G4String& xbinScheme = "linear",
const G4String& ybinScheme = "linear");
virtual G4int CreateH2(const G4String& name, const G4String& title,
const std::vector<G4double>& xedges,
const std::vector<G4double>& yedges,
const G4String& xunitName = "none",
const G4String& yunitName = "none",
const G4String& xfcnName = "none",
const G4String& yfcnName = "none");
virtual G4bool SetH2(G4int id,
G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax,
const G4String& xunitName = "none",
const G4String& yunitName = "none",
const G4String& xfcnName = "none",
const G4String& yfcnName = "none",
const G4String& xbinScheme = "linear",
const G4String& ybinScheme = "linear");
virtual G4bool SetH2(G4int id,
const std::vector<G4double>& xedges,
const std::vector<G4double>& yedges,
const G4String& xunitName = "none",
const G4String& yunitName = "none",
const G4String& xfcnName = "none",
const G4String& yfcnName = "none");
virtual G4bool ScaleH2(G4int id, G4double factor);
// Method to fill histograms
//
virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
G4double weight = 1.0);
// Methods to manipulate histograms
//
// Access methods
virtual G4int GetH2Id(const G4String& name, G4bool warn = true) const;
// Access to H2 parameters
virtual G4int GetH2Nxbins(G4int id) const;
virtual G4double GetH2Xmin(G4int id) const;
virtual G4double GetH2Xmax(G4int id) const;
virtual G4double GetH2XWidth(G4int id) const;
virtual G4int GetH2Nybins(G4int id) const;
virtual G4double GetH2Ymin(G4int id) const;
virtual G4double GetH2Ymax(G4int id) const;
virtual G4double GetH2YWidth(G4int id) const;
// Setters for attributes for plotting
virtual G4bool SetH2Title(G4int id, const G4String& title);
virtual G4bool SetH2XAxisTitle(G4int id, const G4String& title);
virtual G4bool SetH2YAxisTitle(G4int id, const G4String& title);
virtual G4bool SetH2ZAxisTitle(G4int id, const G4String& title);
// Access attributes for plotting
virtual G4String GetH2Title(G4int id) const;
virtual G4String GetH2XAxisTitle(G4int id) const;
virtual G4String GetH2YAxisTitle(G4int id) const;
virtual G4String GetH2ZAxisTitle(G4int id) const;
// Write data on ASCII file
virtual G4bool WriteOnAscii(std::ofstream& output);
private:
virtual tools::histo::h2d* GetH2InFunction(G4int id, G4String function,
G4bool warn = true,
G4bool onlyIfActive = true) const;
void AddH2Information(const G4String& name,
const G4String& xunitName,
const G4String& yunitName,
const G4String& xfcnName,
const G4String& yfcnName,
G4BinScheme xbinScheme,
G4BinScheme ybinScheme) const;
G4int RegisterToolsH2(tools::histo::h2d* h2d,
const G4String& name);
// data members
//
std::vector<tools::histo::h2d*> fH2Vector;
std::map<G4String, G4int> fH2NameIdMap;
};
// inline methods
inline const std::vector<tools::histo::h2d*>& G4H2ToolsManager::GetH2Vector() const
{ return fH2Vector; }
inline const std::vector<G4HnInformation*>& G4H2ToolsManager::GetHnVector() const
{ return fHnManager->GetHnVector(); }
#endif
+53
View File
@@ -0,0 +1,53 @@
#------------------------------------------------------------------------------
# sources.cmake
# Module : G4hntools
# Package: Geant4.src.G4analysis.G4hntools
#
# Sources description for a library.
# Lists the sources and headers of the code explicitely.
# Lists include paths needed.
# Lists the internal granular and global dependencies of the library.
# Source specific properties should be added at the end.
#
# Generated on : 15/07/2013
#
# $Id: sources.cmake 72327 2013-07-16 06:52:43Z gcosmo $
#
#------------------------------------------------------------------------------
# List external includes needed.
include_directories(${CLHEP_INCLUDE_DIRS})
# List internal includes needed.
include_directories(${CMAKE_SOURCE_DIR}/source/global/management/include)
include_directories(${CMAKE_SOURCE_DIR}/source/intercoms/include)
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/g4tools/include)
include_directories(${CMAKE_SOURCE_DIR}/source/analysis/management/include)
#
# Define the Geant4 Module.
#
include(Geant4MacroDefineModule)
GEANT4_DEFINE_MODULE(NAME G4hntools
HEADERS
G4H1DummyManager.hh
G4H1ToolsManager.hh
G4H2DummyManager.hh
G4H2ToolsManager.hh
SOURCES
G4H1DummyManager.cc
G4H1ToolsManager.cc
G4H2DummyManager.cc
G4H2ToolsManager.cc
GRANULAR_DEPENDENCIES
G4globman
G4intercoms
G4analysismng
GLOBAL_DEPENDENCIES
G4global
G4intercoms
LINK_LIBRARIES
)
# List any source specific properties here
@@ -0,0 +1,206 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4H1DummyManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4H1DummyManager.hh"
//_____________________________________________________________________________
G4H1DummyManager::G4H1DummyManager(const G4AnalysisManagerState& state)
: G4VH1Manager(state)
{
}
//_____________________________________________________________________________
G4H1DummyManager::~G4H1DummyManager()
{
}
//
// protected methods
//
//_____________________________________________________________________________
G4int G4H1DummyManager::CreateH1(const G4String& /*name*/,
const G4String& /*title*/,
G4int /*nbins*/,
G4double /*xmin*/, G4double /*xmax*/,
const G4String& /*unitName*/,
const G4String& /*fcnName*/,
const G4String& /*binScheme*/)
{
ExceptionForHistograms("CreateH1");
return 0;
}
//_____________________________________________________________________________
G4int G4H1DummyManager::CreateH1(const G4String& /*name*/,
const G4String& /*title*/,
const std::vector<G4double>& /*edges*/,
const G4String& /*unitName*/,
const G4String& /*fcnName*/)
{
ExceptionForHistograms("CreateH1");
return 0;
}
//_____________________________________________________________________________
G4bool G4H1DummyManager::SetH1(G4int /*id*/,
G4int /*nbins*/,
G4double /*xmin*/, G4double /*xmax*/,
const G4String& /*unitName*/,
const G4String& /*fcnName*/,
const G4String& /*binScheme*/)
{
ExceptionForHistograms("SetH1");
return false;
}
//_____________________________________________________________________________
G4bool G4H1DummyManager::SetH1(G4int /*id*/,
const std::vector<G4double>& /*edges*/,
const G4String& /*unitName*/,
const G4String& /*fcnName*/)
{
ExceptionForHistograms("SetH1");
return false;
}
//_____________________________________________________________________________
G4bool G4H1DummyManager::ScaleH1(G4int /*id*/, G4double /*factor*/)
{
ExceptionForHistograms("ScaleH1");
return false;
}
//_____________________________________________________________________________
G4bool G4H1DummyManager::FillH1(G4int /*id*/,
G4double /*value*/, G4double /*weight*/)
{
G4ExceptionDescription description;
description << " "
<< "Histograms are not supported." ;
G4Exception("G4H1DummyManager::FillH1()",
"Analysis_W007", JustWarning, description);
return false;
}
//_____________________________________________________________________________
G4int G4H1DummyManager::GetNofH1s() const
{
ExceptionForHistograms("GetNofH1s");
return 0;
}
//_____________________________________________________________________________
G4int G4H1DummyManager::GetH1Id(const G4String& /*name*/, G4bool /*warn*/) const
{
ExceptionForHistograms("GetH1Id");
return 0;
}
//_____________________________________________________________________________
G4int G4H1DummyManager::GetH1Nbins(G4int /*id*/) const
{
ExceptionForHistograms("GetH1Nbins");
return 0;
}
//_____________________________________________________________________________
G4double G4H1DummyManager::GetH1Xmin(G4int /*id*/) const
{
ExceptionForHistograms("GetH1Xmin");
return 0;
}
//_____________________________________________________________________________
G4double G4H1DummyManager::GetH1Xmax(G4int /*id*/) const
{
ExceptionForHistograms("GetH1Xmax");
return 0;
}
//_____________________________________________________________________________
G4double G4H1DummyManager::GetH1Width(G4int /*id*/) const
{
ExceptionForHistograms("GetH1Xwidth");
return 0;
}
//_____________________________________________________________________________
G4bool G4H1DummyManager::SetH1Title(G4int /*id*/,
const G4String& /*title*/)
{
ExceptionForHistograms("SetH1Title");
return false;
}
//_____________________________________________________________________________
G4bool G4H1DummyManager::SetH1XAxisTitle(G4int /*id*/,
const G4String& /*title*/)
{
ExceptionForHistograms("SetH1XAxisTitle");
return false;
}
//_____________________________________________________________________________
G4bool G4H1DummyManager::SetH1YAxisTitle(G4int /*id*/,
const G4String& /*title*/)
{
ExceptionForHistograms("SetH1YAxisTitle");
return false;
}
//_____________________________________________________________________________
G4String G4H1DummyManager::GetH1XAxisTitle(G4int /*id*/) const
{
ExceptionForHistograms("GetH1XAxisTitle");
return "";
}
//_____________________________________________________________________________
G4String G4H1DummyManager::GetH1Title(G4int /*id*/) const
{
ExceptionForHistograms("GetH1Title");
return "";
}
//_____________________________________________________________________________
G4String G4H1DummyManager::GetH1YAxisTitle(G4int /*id*/) const
{
ExceptionForHistograms("GetH1YAxisTitle");
return "";
}
//_____________________________________________________________________________
G4bool G4H1DummyManager::WriteOnAscii(std::ofstream& /*output*/)
{
ExceptionForHistograms("GetH1YAxisTitle");
return false;
}
@@ -0,0 +1,623 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4H1ToolsManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4H1ToolsManager.hh"
#include "G4HnManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
#include "tools/histo/h1d"
#include <fstream>
using namespace G4Analysis;
//
// Constructors, destructor
//
//_____________________________________________________________________________
G4H1ToolsManager::G4H1ToolsManager(const G4AnalysisManagerState& state)
: G4VH1Manager(state),
fH1Vector(),
fH1NameIdMap()
{
}
//_____________________________________________________________________________
G4H1ToolsManager::~G4H1ToolsManager()
{
std::vector<tools::histo::h1d*>::iterator it;
for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
delete (*it);
}
}
//
// Utility functions
//
namespace {
//_____________________________________________________________________________
void UpdateH1Information(G4HnInformation* information,
const G4String& unitName,
const G4String& fcnName,
G4BinScheme binScheme)
{
G4double unit = GetUnitValue(unitName);
G4Fcn fcn = GetFunction(fcnName);
information->fXUnitName = unitName;
information->fYUnitName = unitName;
information->fXFcnName = fcnName;
information->fYFcnName = fcnName;
information->fXUnit = unit;
information->fYUnit = unit;
information->fXFcn = fcn;
information->fYFcn = fcn;
information->fXBinScheme = binScheme;
information->fYBinScheme = binScheme;
}
//_____________________________________________________________________________
void AddH1Annotation(tools::histo::h1d* h1d,
const G4String& unitName,
const G4String& fcnName)
{
G4String axisTitle;
UpdateTitle(axisTitle, unitName, fcnName);
h1d->add_annotation(tools::histo::key_axis_x_title(), axisTitle);
}
//_____________________________________________________________________________
tools::histo::h1d* CreateToolsH1(const G4String& title,
G4int nbins, G4double xmin, G4double xmax,
const G4String& fcnName,
const G4String& binSchemeName)
{
G4Fcn fcn = GetFunction(fcnName);
G4BinScheme binScheme = GetBinScheme(binSchemeName);
if ( binScheme != kLogBinScheme ) {
if ( binScheme == kUserBinScheme ) {
// This should never happen, but let's make sure about it
// by issuing a warning
G4ExceptionDescription description;
description
<< " User binning scheme setting was ignored." << G4endl
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
G4Exception("G4H1ToolsManager::CreateH1",
"Analysis_W013", JustWarning, description);
}
return new tools::histo::h1d(title, nbins, fcn(xmin), fcn(xmax));
}
else {
// Compute edges
std::vector<G4double> edges;
ComputeEdges(nbins, xmin, xmax, fcn, binScheme, edges);
return new tools::histo::h1d(title, edges);
}
}
//_____________________________________________________________________________
tools::histo::h1d* CreateToolsH1(const G4String& title,
const std::vector<G4double>& edges,
const G4String& fcnName)
{
G4Fcn fcn = GetFunction(fcnName);
// Apply function
std::vector<G4double> newEdges;
ComputeEdges(edges, fcn, newEdges);
return new tools::histo::h1d(title, newEdges);
}
//_____________________________________________________________________________
void ConfigureToolsH1(tools::histo::h1d* h1d,
G4int nbins, G4double xmin, G4double xmax,
const G4String& fcnName,
const G4String& binSchemeName)
{
G4Fcn fcn = GetFunction(fcnName);
G4BinScheme binScheme = GetBinScheme(binSchemeName);
if ( binScheme != kLogBinScheme ) {
if ( binScheme == kUserBinScheme ) {
// This should never happen, but let's make sure about it
// by issuing a warning
G4ExceptionDescription description;
description
<< " User binning scheme setting was ignored." << G4endl
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
G4Exception("G4H1ToolsManager::SetH1",
"Analysis_W013", JustWarning, description);
}
h1d->configure(nbins, fcn(xmin), fcn(xmax));
}
else {
// Compute bins
std::vector<G4double> edges;
ComputeEdges(nbins, xmin, xmax, fcn, binScheme, edges);
h1d->configure(edges);
}
}
//_____________________________________________________________________________
void ConfigureToolsH1(tools::histo::h1d* h1d,
const std::vector<G4double>& edges,
const G4String& fcnName)
{
// Apply function to edges
G4Fcn fcn = GetFunction(fcnName);
std::vector<G4double> newEdges;
ComputeEdges(edges, fcn, newEdges);
h1d->configure(newEdges);
}
}
//
// private methods
//
//_____________________________________________________________________________
tools::histo::h1d* G4H1ToolsManager::GetH1InFunction(G4int id,
G4String functionName, G4bool warn,
G4bool onlyIfActive) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fH1Vector.size()) ) {
if ( warn) {
G4String inFunction = "G4H1ToolsManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "histogram " << id << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return 0;
}
// Do not return histogram if inactive
if ( fState.GetIsActivation() && onlyIfActive && ( ! fHnManager->GetActivation(id) ) ) {
return 0;
}
return fH1Vector[index];
}
//_____________________________________________________________________________
void G4H1ToolsManager::AddH1Information(const G4String& name,
const G4String& unitName,
const G4String& fcnName,
G4BinScheme binScheme) const
{
G4double unit = GetUnitValue(unitName);
G4Fcn fcn = GetFunction(fcnName);
fHnManager->AddH1Information(name, unitName, fcnName, unit, fcn, binScheme);
}
//_____________________________________________________________________________
G4int G4H1ToolsManager::RegisterToolsH1(tools::histo::h1d* h1d,
const G4String& name)
{
G4int index = fH1Vector.size();
fH1Vector.push_back(h1d);
fLockFirstId = true;
fH1NameIdMap[name] = index + fFirstId;
return index + fFirstId;
}
//
// protected methods
//
//_____________________________________________________________________________
G4int G4H1ToolsManager::CreateH1(const G4String& name, const G4String& title,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName, const G4String& fcnName,
const G4String& binSchemeName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "H1", name);
#endif
tools::histo::h1d* h1d
= CreateToolsH1(title, nbins, xmin, xmax, fcnName, binSchemeName);
// Add annotation
AddH1Annotation(h1d, unitName, fcnName);
// Save H1 information
G4BinScheme binScheme = GetBinScheme(binSchemeName);
AddH1Information(name, unitName, fcnName, binScheme);
// Register histogram
G4int id = RegisterToolsH1(h1d, name);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("create", "H1", name);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4H1ToolsManager::CreateH1(const G4String& name, const G4String& title,
const std::vector<G4double>& edges,
const G4String& unitName, const G4String& fcnName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "H1", name);
#endif
tools::histo::h1d* h1d
= CreateToolsH1(title, edges, fcnName);
// Add annotation
AddH1Annotation(h1d, unitName, fcnName);
// Save H1 information
AddH1Information(name, unitName, fcnName, kUserBinScheme);
// Register histogram
G4int id = RegisterToolsH1(h1d, name);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("create", "H1", name);
#endif
return id;
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::SetH1(G4int id,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName, const G4String& fcnName,
const G4String& binSchemeName)
{
tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1", false, false);
if ( ! h1d ) return false;
G4HnInformation* info = fHnManager->GetHnInformation(id,"SetH1");
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("configure", "H1", info->fName);
#endif
// Configure tools h1
ConfigureToolsH1(h1d, nbins, xmin, xmax, fcnName, binSchemeName);
// Add annotation
AddH1Annotation(h1d, unitName, fcnName);
// Update information
G4BinScheme binScheme = GetBinScheme(binSchemeName);
UpdateH1Information(info, unitName, fcnName, binScheme);
// Set activation
fHnManager->SetActivation(id, true);
return true;
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::SetH1(G4int id,
const std::vector<G4double>& edges,
const G4String& unitName,
const G4String& fcnName)
{
tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1", false, false);
if ( ! h1d ) return false;
G4HnInformation* info = fHnManager->GetHnInformation(id,"SetH1");
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("configure", "H1", info->fName);
#endif
// Configure tools h1
ConfigureToolsH1(h1d, edges, fcnName);
// Add annotation
AddH1Annotation(h1d, unitName, fcnName);
// Update information
UpdateH1Information(info, unitName, fcnName, kUserBinScheme);
// Set activation
fHnManager->SetActivation(id, true);
return true;
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::ScaleH1(G4int id, G4double factor)
{
tools::histo::h1d* h1d = GetH1InFunction(id, "ScaleH1", false, false);
if ( ! h1d ) return false;
return h1d->scale(factor);
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::FillH1(G4int id, G4double value, G4double weight)
{
tools::histo::h1d* h1d = GetH1InFunction(id, "FillH1", true, false);
if ( ! h1d ) return false;
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
//G4cout << "Skipping FillH1 for " << id << G4endl;
return false;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "FillId");
h1d->fill(info->fXFcn(value/info->fXUnit), weight);
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " id " << id << " value " << value;
fState.GetVerboseL4()->Message("fill", "H1", description);
}
#endif
return true;
}
//_____________________________________________________________________________
G4int G4H1ToolsManager::GetH1Id(const G4String& name, G4bool warn) const
{
std::map<G4String, G4int>::const_iterator it = fH1NameIdMap.find(name);
if ( it == fH1NameIdMap.end() ) {
if ( warn) {
G4String inFunction = "G4H1ToolsManager::GetH1Id";
G4ExceptionDescription description;
description << " " << "histogram " << name << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return -1;
}
return it->second;
}
//_____________________________________________________________________________
G4int G4H1ToolsManager::GetH1Nbins(G4int id) const
{
tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1Nbins");
if ( ! h1d ) return 0;
return h1d->axis().bins();
}
//_____________________________________________________________________________
G4double G4H1ToolsManager::GetH1Xmin(G4int id) const
{
// Returns xmin value with applied unit and histogram function
tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1Xmin");
if ( ! h1d ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH1Xmin");
return info->fXFcn(h1d->axis().lower_edge()*info->fXUnit);
}
//_____________________________________________________________________________
G4double G4H1ToolsManager::GetH1Xmax(G4int id) const
{
tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1Xmax");
if ( ! h1d ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH1Xmax");
return info->fXFcn(h1d->axis().upper_edge()*info->fXUnit);
}
//_____________________________________________________________________________
G4double G4H1ToolsManager::GetH1Width(G4int id) const
{
tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1XWidth", true, false);
if ( ! h1d ) return 0;
G4int nbins = h1d->axis().bins();
if ( ! nbins ) {
G4ExceptionDescription description;
description << " nbins = 0 (for h1 id = " << id << ").";
G4Exception("G4H1ToolsManager::GetH1Width",
"Analysis_W014", JustWarning, description);
return 0;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH1XWidth");
return ( info->fXFcn(h1d->axis().upper_edge())
- info->fXFcn(h1d->axis().lower_edge()))*info->fXUnit/nbins;
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::SetH1Title(G4int id, const G4String& title)
{
tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1Title");
if ( ! h1d ) return false;
return h1d->set_title(title);
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::SetH1XAxisTitle(G4int id, const G4String& title)
{
tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1XAxisTitle");
if ( ! h1d ) return false;
h1d->add_annotation(tools::histo::key_axis_x_title(), title);
return true;
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::SetH1YAxisTitle(G4int id, const G4String& title)
{
tools::histo::h1d* h1d = GetH1InFunction(id, "SetH1YAxisTitle");
if ( ! h1d ) return false;
h1d->add_annotation(tools::histo::key_axis_y_title(), title);
return true;
}
//_____________________________________________________________________________
G4String G4H1ToolsManager::GetH1Title(G4int id) const
{
tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1Title");
if ( ! h1d ) return "";
return h1d->title();
}
//_____________________________________________________________________________
G4String G4H1ToolsManager::GetH1XAxisTitle(G4int id) const
{
tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1XAxisTitle");
if ( ! h1d ) return "";
G4String title;
G4bool result = h1d->annotation(tools::histo::key_axis_x_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get x_axis title for h1 id = " << id << ").";
G4Exception("G4H1ToolsManager::GetH1XAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4String G4H1ToolsManager::GetH1YAxisTitle(G4int id) const
{
tools::histo::h1d* h1d = GetH1InFunction(id, "GetH1YAxisTitle");
if ( ! h1d ) return "";
G4String title;
G4bool result = h1d->annotation(tools::histo::key_axis_y_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get y_axis title for h1 id = " << id << ").";
G4Exception("G4H1ToolsManager::GetH1YAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::WriteOnAscii(std::ofstream& output)
{
// Write selected objects on ASCII file
// According to the implementation by Michel Maire, originally in
// extended examples.
// h1 histograms
for ( G4int i=0; i<G4int(fH1Vector.size()); ++i ) {
G4int id = i + fFirstId;
G4HnInformation* info = fHnManager->GetHnInformation(id,"WriteOnAscii");
// skip writing if activation is enabled and H1 is inactivated
if ( ! info->fAscii ) continue;
tools::histo::h1d* h1 = fH1Vector[i];
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()->Message("write on ascii", "h1d", info->fName);
#endif
output << "\n 1D histogram " << id << ": " << h1->title()
<< "\n \n \t X \t\t Y" << G4endl;
for (G4int j=0; j< G4int(h1->axis().bins()); ++j) {
output << " " << j << "\t"
<< h1->axis().bin_center(j) << "\t"
<< h1->bin_height(j) << G4endl;
}
}
return true;
}
//
// public methods
//
//_____________________________________________________________________________
void G4H1ToolsManager::AddH1Vector(
const std::vector<tools::histo::h1d*>& h1Vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("merge", "all h1", "");
#endif
std::vector<tools::histo::h1d*>::const_iterator itw = h1Vector.begin();
std::vector<tools::histo::h1d*>::iterator it;
for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
(*it)->add(*(*itw++));
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("merge", "all h1", "");
#endif
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::Reset()
{
// Reset histograms and ntuple
G4bool finalResult = true;
std::vector<tools::histo::h1d*>::iterator it;
for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
G4bool result = (*it)->reset();
if ( ! result ) finalResult = false;
}
return finalResult;
}
//_____________________________________________________________________________
G4bool G4H1ToolsManager::IsEmpty() const
{
return ! fH1Vector.size();
}
//_____________________________________________________________________________
tools::histo::h1d* G4H1ToolsManager::GetH1(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return GetH1InFunction(id, "GetH1", warn, onlyIfActive);
}
@@ -0,0 +1,265 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4H2DummyManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4H2DummyManager.hh"
//_____________________________________________________________________________
G4H2DummyManager::G4H2DummyManager(const G4AnalysisManagerState& state)
: G4VH2Manager(state)
{
}
//_____________________________________________________________________________
G4H2DummyManager::~G4H2DummyManager()
{
}
//
// protected methods
//
//_____________________________________________________________________________
G4int G4H2DummyManager::CreateH2(const G4String& /*name*/,
const G4String& /*title*/,
G4int /*nxbins*/,
G4double /*xmin*/, G4double /*xmax*/,
G4int /*nybins*/,
G4double /*ymin*/, G4double /*ymax*/,
const G4String& /*xunitName*/,
const G4String& /*yunitName*/,
const G4String& /*xfcnName*/,
const G4String& /*yfcnName*/,
const G4String& /*xbinScheme*/,
const G4String& /*ybinScheme*/)
{
ExceptionForHistograms("CreateH2");
return 0;
}
//_____________________________________________________________________________
G4int G4H2DummyManager::CreateH2(const G4String& /*name*/,
const G4String& /*title*/,
const std::vector<G4double>& /*xedges*/,
const std::vector<G4double>& /*yedges*/,
const G4String& /*xunitName*/,
const G4String& /*yunitName*/,
const G4String& /*xfcnName*/,
const G4String& /*yfcnName*/)
{
ExceptionForHistograms("CreateH2");
return 0;
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::SetH2(G4int /*id*/,
G4int /*nxbins*/,
G4double /*xmin*/, G4double /*xmax*/,
G4int /*nybins*/,
G4double /*ymin*/, G4double /*ymax*/,
const G4String& /*xunitName*/,
const G4String& /*yunitName*/,
const G4String& /*xfcnName*/,
const G4String& /*yfcnName*/,
const G4String& /*xbinScheme*/,
const G4String& /*ybinScheme*/)
{
ExceptionForHistograms("SetH2");
return false;
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::SetH2(G4int /*id*/,
const std::vector<G4double>& /*xedges*/,
const std::vector<G4double>& /*yedges*/,
const G4String& /*xunitName*/,
const G4String& /*yunitName*/,
const G4String& /*xfcnName*/,
const G4String& /*yfcnName*/)
{
ExceptionForHistograms("SetH2");
return false;
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::ScaleH2(G4int /*id*/, G4double /*factor*/)
{
ExceptionForHistograms("ScaleH2");
return false;
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::FillH2(G4int /*id*/,
G4double /*xvalue*/, G4double /*yvalue*/,
G4double /*weight*/)
{
G4ExceptionDescription description;
description << " "
<< "Histograms are not supported." ;
G4Exception("G4H2DummyManager::FillH2()",
"Analysis_W007", JustWarning, description);
return false;
}
//_____________________________________________________________________________
G4int G4H2DummyManager::GetNofH2s() const
{
ExceptionForHistograms("GetNofH2s");
return 0;
}
//_____________________________________________________________________________
G4int G4H2DummyManager::GetH2Id(const G4String& /*name*/, G4bool /*warn*/) const
{
ExceptionForHistograms("GetH2Id");
return 0;
}
//_____________________________________________________________________________
G4int G4H2DummyManager::GetH2Nxbins(G4int /*id*/) const
{
ExceptionForHistograms("GetH2NXbins");
return 0;
}
//_____________________________________________________________________________
G4double G4H2DummyManager::GetH2Xmin(G4int /*id*/) const
{
ExceptionForHistograms("GetH2Xmin");
return 0;
}
//_____________________________________________________________________________
G4double G4H2DummyManager::GetH2Xmax(G4int /*id*/) const
{
ExceptionForHistograms("GetH2Xmin");
return 0;
}
//_____________________________________________________________________________
G4double G4H2DummyManager::GetH2XWidth(G4int /*id*/) const
{
ExceptionForHistograms("GetH2XWidth");
return 0;
}
//_____________________________________________________________________________
G4int G4H2DummyManager::GetH2Nybins(G4int /*id*/) const
{
ExceptionForHistograms("GetH2NYbins");
return 0;
}
//_____________________________________________________________________________
G4double G4H2DummyManager::GetH2Ymin(G4int /*id*/) const
{
ExceptionForHistograms("GetH2Ymin");
return 0;
}
//_____________________________________________________________________________
G4double G4H2DummyManager::GetH2Ymax(G4int /*id*/) const
{
ExceptionForHistograms("GetH2Ymax");
return 0;
}
//_____________________________________________________________________________
G4double G4H2DummyManager::GetH2YWidth(G4int /*id*/) const
{
ExceptionForHistograms("GetH2YWidth");
return 0;
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::SetH2Title(G4int /*id*/,
const G4String& /*title*/)
{
ExceptionForHistograms("SetH2Title");
return false;
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::SetH2XAxisTitle(G4int /*id*/,
const G4String& /*title*/)
{
ExceptionForHistograms("SetH2XAxisTitle");
return false;
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::SetH2YAxisTitle(G4int /*id*/,
const G4String& /*title*/)
{
ExceptionForHistograms("SetH2YAxisTitle");
return false;
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::SetH2ZAxisTitle(G4int /*id*/,
const G4String& /*title*/)
{
ExceptionForHistograms("SetH2ZAxisTitle");
return false;
}
//_____________________________________________________________________________
G4String G4H2DummyManager::GetH2Title(G4int /*id*/) const
{
ExceptionForHistograms("GetH2Title");
return "";
}
//_____________________________________________________________________________
G4String G4H2DummyManager::GetH2XAxisTitle(G4int /*id*/) const
{
ExceptionForHistograms("GetH2XAxisTitle");
return "";
}
//_____________________________________________________________________________
G4String G4H2DummyManager::GetH2YAxisTitle(G4int /*id*/) const
{
ExceptionForHistograms("GetH2YAxisTitle");
return "";
}
//_____________________________________________________________________________
G4String G4H2DummyManager::GetH2ZAxisTitle(G4int /*id*/) const
{
ExceptionForHistograms("GetH2ZAxisTitle");
return "";
}
//_____________________________________________________________________________
G4bool G4H2DummyManager::WriteOnAscii(std::ofstream& /*output*/)
{
ExceptionForHistograms("WriteOnAscii");
return false;
}
@@ -0,0 +1,754 @@
//
// ********************************************************************
// * License and Disclaimer *
// * *
// * The Geant4 software is copyright of the Copyright Holders of *
// * the Geant4 Collaboration. It is provided under the terms and *
// * conditions of the Geant4 Software License, included in the file *
// * LICENSE and available at http://cern.ch/geant4/license . These *
// * include a list of copyright holders. *
// * *
// * Neither the authors of this software system, nor their employing *
// * institutes,nor the agencies providing financial support for this *
// * work make any representation or warranty, express or implied, *
// * regarding this software system or assume any liability for its *
// * use. Please see the license in the file LICENSE and URL above *
// * for the full disclaimer and the limitation of liability. *
// * *
// * This code implementation is the result of the scientific and *
// * technical work of the GEANT4 collaboration. *
// * By using, copying, modifying or distributing the software (or *
// * any work based on the software) you agree to acknowledge its *
// * use in resulting scientific publications, and indicate your *
// * acceptance of all terms of the Geant4 Software license. *
// ********************************************************************
//
// $Id: G4H2ToolsManager.cc 70604 2013-06-03 11:27:06Z ihrivnac $
// Author: Ivana Hrivnacova, 18/06/2013 (ivana@ipno.in2p3.fr)
#include "G4H2ToolsManager.hh"
#include "G4HnManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
#include "tools/histo/h2d"
#include <fstream>
using namespace G4Analysis;
//_____________________________________________________________________________
G4H2ToolsManager::G4H2ToolsManager(const G4AnalysisManagerState& state)
: G4VH2Manager(state),
fH2Vector(),
fH2NameIdMap()
{
}
//_____________________________________________________________________________
G4H2ToolsManager::~G4H2ToolsManager()
{
std::vector<tools::histo::h2d*>::iterator it;
for (it = fH2Vector.begin(); it != fH2Vector.end(); it++ ) {
delete (*it);
}
}
//
// Utility functions
//
namespace {
//_____________________________________________________________________________
void UpdateH2Information(G4HnInformation* information,
const G4String& xunitName,
const G4String& yunitName,
const G4String& xfcnName,
const G4String& yfcnName,
G4BinScheme xbinScheme,
G4BinScheme ybinScheme)
{
G4double xunit = GetUnitValue(xunitName);
G4double yunit = GetUnitValue(yunitName);
G4Fcn xfcn = GetFunction(xfcnName);
G4Fcn yfcn = GetFunction(yfcnName);
information->fXUnitName = xunitName;
information->fYUnitName = yunitName;
information->fXFcnName = xfcnName;
information->fYFcnName = yfcnName;
information->fXUnit = xunit;
information->fYUnit = yunit;
information->fXFcn = xfcn;
information->fYFcn = yfcn;
information->fXBinScheme = xbinScheme;
information->fYBinScheme = ybinScheme;
}
//_____________________________________________________________________________
void AddH2Annotation(tools::histo::h2d* h2d,
const G4String& xunitName,
const G4String& yunitName,
const G4String& xfcnName,
const G4String& yfcnName)
{
G4String xaxisTitle;
G4String yaxisTitle;
UpdateTitle(xaxisTitle, xunitName, xfcnName);
UpdateTitle(yaxisTitle, yunitName, yfcnName);
h2d->add_annotation(tools::histo::key_axis_x_title(), xaxisTitle);
h2d->add_annotation(tools::histo::key_axis_y_title(), yaxisTitle);
}
//_____________________________________________________________________________
tools::histo::h2d* CreateToolsH2(
const G4String& title,
G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax,
const G4String& xfcnName,
const G4String& yfcnName,
const G4String& xbinSchemeName,
const G4String& ybinSchemeName)
{
G4Fcn xfcn = GetFunction(xfcnName);
G4Fcn yfcn = GetFunction(yfcnName);
G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme) {
if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme) {
// This should never happen, but let's make sure about it
// by issuing a warning
G4ExceptionDescription description;
description
<< " User binning scheme setting was ignored." << G4endl
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
G4Exception("G4H2ToolsManager::CreateH2",
"Analysis_W013", JustWarning, description);
}
return new tools::histo::h2d(title,
nxbins, xfcn(xmin), xfcn(xmax),
nybins, yfcn(ymin), yfcn(ymax));
// h2 objects are deleted in destructor and reset when
// closing a file.
}
else {
// Compute edges
std::vector<G4double> xedges;
ComputeEdges(nxbins, xmin, xmax, xfcn, xbinScheme, xedges);
std::vector<G4double> yedges;
ComputeEdges(nybins, ymin, ymax, yfcn, ybinScheme, yedges);
return new tools::histo::h2d(title, xedges, yedges);
}
}
//_____________________________________________________________________________
tools::histo::h2d* CreateToolsH2(
const G4String& title,
const std::vector<G4double>& xedges,
const std::vector<G4double>& yedges,
const G4String& xfcnName,
const G4String& yfcnName)
{
G4Fcn xfcn = GetFunction(xfcnName);
G4Fcn yfcn = GetFunction(yfcnName);
// Apply function
std::vector<G4double> xnewEdges;
ComputeEdges(xedges, xfcn, xnewEdges);
std::vector<G4double> ynewEdges;
ComputeEdges(yedges, yfcn, ynewEdges);
return new tools::histo::h2d(title, xnewEdges, ynewEdges);
// h2 objects are deleted in destructor and reset when
// closing a file.
}
//_____________________________________________________________________________
void ConfigureToolsH2(tools::histo::h2d* h2d,
G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax,
const G4String& xfcnName,
const G4String& yfcnName,
const G4String& xbinSchemeName,
const G4String& ybinSchemeName)
{
G4Fcn xfcn = GetFunction(xfcnName);
G4Fcn yfcn = GetFunction(yfcnName);
G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
if ( xbinScheme != kLogBinScheme && ybinScheme != kLogBinScheme) {
if ( xbinScheme == kUserBinScheme || ybinScheme == kUserBinScheme) {
// This should never happen, but let's make sure about it
// by issuing a warning
G4ExceptionDescription description;
description
<< " User binning scheme setting was ignored." << G4endl
<< " Linear binning will be applied with given (nbins, xmin, xmax) values";
G4Exception("G4H2ToolsManager::CreateH2",
"Analysis_W013", JustWarning, description);
}
h2d->configure(nxbins, xfcn(xmin), xfcn(xmax),
nybins, yfcn(ymin), yfcn(ymax));
}
else {
// Compute bins
std::vector<G4double> xedges;
ComputeEdges(nxbins, xmin, xmax, xfcn, xbinScheme, xedges);
std::vector<G4double> yedges;
ComputeEdges(nybins, ymin, ymax, yfcn, ybinScheme, yedges);
h2d->configure(xedges, yedges);
}
}
//_____________________________________________________________________________
void ConfigureToolsH2(tools::histo::h2d* h2d,
const std::vector<G4double>& xedges,
const std::vector<G4double>& yedges,
const G4String& xfcnName,
const G4String& yfcnName)
{
G4Fcn xfcn = GetFunction(xfcnName);
std::vector<G4double> xnewEdges;
ComputeEdges(xedges, xfcn, xnewEdges);
G4Fcn yfcn = GetFunction(yfcnName);
std::vector<G4double> ynewEdges;
ComputeEdges(yedges, yfcn, ynewEdges);
h2d->configure(xnewEdges, ynewEdges);
}
}
//
// private methods
//
//_____________________________________________________________________________
tools::histo::h2d* G4H2ToolsManager::GetH2InFunction(G4int id,
G4String functionName, G4bool warn,
G4bool onlyIfActive) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fH2Vector.size()) ) {
if ( warn) {
G4String inFunction = "G4H2ToolsManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "histogram " << id << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return 0;
}
// Do not return histogram if inactive
if ( fState.GetIsActivation() && onlyIfActive &&
( ! fHnManager->GetActivation(id) ) ) {
return 0;
}
return fH2Vector[index];
}
//_____________________________________________________________________________
void G4H2ToolsManager::AddH2Information(const G4String& name,
const G4String& xunitName,
const G4String& yunitName,
const G4String& xfcnName,
const G4String& yfcnName,
G4BinScheme xbinScheme,
G4BinScheme ybinScheme) const
{
G4double xunit = GetUnitValue(xunitName);
G4double yunit = GetUnitValue(yunitName);
G4Fcn xfcn = GetFunction(xfcnName);
G4Fcn yfcn = GetFunction(yfcnName);
fHnManager
->AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
xunit, yunit, xfcn, yfcn,
xbinScheme, ybinScheme);
}
//_____________________________________________________________________________
G4int G4H2ToolsManager::RegisterToolsH2(tools::histo::h2d* h2d,
const G4String& name)
{
G4int index = fH2Vector.size();
fH2Vector.push_back(h2d);
fLockFirstId = true;
fH2NameIdMap[name] = index + fFirstId;
return index + fFirstId;
}
//
// protected methods
//
//_____________________________________________________________________________
G4int G4H2ToolsManager::CreateH2(const G4String& name, const G4String& title,
G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax,
const G4String& xunitName, const G4String& yunitName,
const G4String& xfcnName, const G4String& yfcnName,
const G4String& xbinSchemeName,
const G4String& ybinSchemeName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "H2", name);
#endif
tools::histo::h2d* h2d
= CreateToolsH2(title, nxbins, xmin, xmax, nybins, ymin, ymax,
xfcnName, yfcnName, xbinSchemeName, ybinSchemeName);
// Add annotation
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
// Save H2 information
G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
AddH2Information(
name, xunitName, yunitName, xfcnName, yfcnName, xbinScheme, ybinScheme);
// Register histogram
G4int id = RegisterToolsH2(h2d, name);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("create", "H2", name);
#endif
return id;
}
//_____________________________________________________________________________
G4int G4H2ToolsManager::CreateH2(const G4String& name, const G4String& title,
const std::vector<G4double>& xedges,
const std::vector<G4double>& yedges,
const G4String& xunitName, const G4String& yunitName,
const G4String& xfcnName, const G4String& yfcnName)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "H2", name);
#endif
tools::histo::h2d* h2d
= CreateToolsH2(title, xedges, yedges, xfcnName, yfcnName);
// Add annotation
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
// Save H2 information
AddH2Information(
name, xunitName, yunitName, xfcnName, yfcnName, kUserBinScheme, kUserBinScheme);
// Register histogram
G4int id = RegisterToolsH2(h2d, name);
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()->Message("create", "H2", name);
#endif
return id;
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::SetH2(G4int id,
G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax,
const G4String& xunitName, const G4String& yunitName,
const G4String& xfcnName, const G4String& yfcnName,
const G4String& xbinSchemeName,
const G4String& ybinSchemeName)
{
tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2", false, false);
if ( ! h2d ) return false;
G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH2");
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("configure", "H2", info->fName);
#endif
// Configure tools h2
ConfigureToolsH2(
h2d, nxbins, xmin, xmax, nybins, ymin, ymax, xfcnName, yfcnName,
xbinSchemeName, xbinSchemeName);
// Add annotation
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
// Update information
G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
UpdateH2Information(
info, xunitName, yunitName, xfcnName, yfcnName, xbinScheme, ybinScheme);
// Set activation
fHnManager->SetActivation(id, true);
return true;
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::SetH2(G4int id,
const std::vector<G4double>& xedges,
const std::vector<G4double>& yedges,
const G4String& xunitName, const G4String& yunitName,
const G4String& xfcnName, const G4String& yfcnName)
{
tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2", false, false);
if ( ! h2d ) return false;
G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH2");
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("configure", "H2", info->fName);
#endif
// Configure tools h2
ConfigureToolsH2(h2d, xedges, yedges, xfcnName, yfcnName);
// Add annotation
AddH2Annotation(h2d, xunitName, yunitName, xfcnName, yfcnName);
// Update information
UpdateH2Information(
info, xunitName, yunitName, xfcnName, yfcnName, kUserBinScheme, kUserBinScheme);
// Set activation
fHnManager->SetActivation(id, true);
return true;
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::ScaleH2(G4int id, G4double factor)
{
tools::histo::h2d* h2d = GetH2InFunction(id, "ScaleH2", false, false);
if ( ! h2d ) return false;
return h2d->scale(factor);
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::FillH2(G4int id,
G4double xvalue, G4double yvalue,
G4double weight)
{
tools::histo::h2d* h2d = GetH2InFunction(id, "FillH2", true, false);
if ( ! h2d ) return false;
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
return false;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "FillH2");
h2d->fill(info->fXFcn(xvalue/info->fXUnit),
info->fYFcn(yvalue/info->fYUnit), weight);
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " id " << id
<< " xvalue " << xvalue << " yvalue " << yvalue;
fState.GetVerboseL4()->Message("fill", "H2", description);
}
#endif
return true;
}
//_____________________________________________________________________________
G4int G4H2ToolsManager::GetH2Id(const G4String& name, G4bool warn) const
{
std::map<G4String, G4int>::const_iterator it = fH2NameIdMap.find(name);
if ( it == fH2NameIdMap.end() ) {
if ( warn) {
G4String inFunction = "G4H2ToolsManager::GetH2Id";
G4ExceptionDescription description;
description << " " << "histogram " << name << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return -1;
}
return it->second;
}
//_____________________________________________________________________________
G4int G4H2ToolsManager::GetH2Nxbins(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2NXbins");
if ( ! h2d ) return 0;
return h2d->axis_x().bins();
}
//_____________________________________________________________________________
G4double G4H2ToolsManager::GetH2Xmin(G4int id) const
{
// Returns xmin value with applied unit and histogram function
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Xmin");
if ( ! h2d ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Xmin");
return info->fXFcn(h2d->axis_x().lower_edge()*info->fXUnit);
}
//_____________________________________________________________________________
G4double G4H2ToolsManager::GetH2Xmax(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Xmax");
if ( ! h2d ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Xmax");
return info->fXFcn(h2d->axis_x().upper_edge()*info->fXUnit);
}
//_____________________________________________________________________________
G4double G4H2ToolsManager::GetH2XWidth(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2XWidth", true, false);
if ( ! h2d ) return 0;
G4int nbins = h2d->axis_x().bins();
if ( ! nbins ) {
G4ExceptionDescription description;
description << " nbins = 0 (for h2 id = " << id << ").";
G4Exception("G4H2ToolsManager::GetH2Width",
"Analysis_W014", JustWarning, description);
return 0;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2XWidth");
return ( info->fXFcn(h2d->axis_x().upper_edge())
- info->fXFcn(h2d->axis_x().lower_edge()))*info->fXUnit/nbins;
}
//_____________________________________________________________________________
G4int G4H2ToolsManager::GetH2Nybins(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2NYbins");
if ( ! h2d ) return 0;
return h2d->axis_y().bins();
}
//_____________________________________________________________________________
G4double G4H2ToolsManager::GetH2Ymin(G4int id) const
{
// Returns xmin value with applied unit and histogram function
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Ymin");
if ( ! h2d ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Ymin");
return info->fYFcn(h2d->axis_y().lower_edge()*info->fYUnit);
}
//_____________________________________________________________________________
G4double G4H2ToolsManager::GetH2Ymax(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Ymax");
if ( ! h2d ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Ymax");
return info->fYFcn(h2d->axis_y().upper_edge()*info->fYUnit);
}
//_____________________________________________________________________________
G4double G4H2ToolsManager::GetH2YWidth(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2YWidth", true, false);
if ( ! h2d ) return 0;
G4int nbins = h2d->axis_y().bins();
if ( ! nbins ) {
G4ExceptionDescription description;
description << " nbins = 0 (for h2 id = " << id << ").";
G4Exception("G4H2ToolsManager::GetH2Width",
"Analysis_W014", JustWarning, description);
return 0;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2YWidth");
return ( info->fYFcn(h2d->axis_y().upper_edge())
- info->fYFcn(h2d->axis_y().lower_edge()))*info->fYUnit/nbins;
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::SetH2Title(G4int id, const G4String& title)
{
tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2Title");
if ( ! h2d ) return false;
return h2d->set_title(title);
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::SetH2XAxisTitle(G4int id, const G4String& title)
{
tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2XAxisTitle");
if ( ! h2d ) return false;
h2d->add_annotation(tools::histo::key_axis_x_title(), title);
return true;
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::SetH2YAxisTitle(G4int id, const G4String& title)
{
tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2YAxisTitle");
if ( ! h2d ) return false;
h2d->add_annotation(tools::histo::key_axis_x_title(), title);
return true;
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::SetH2ZAxisTitle(G4int id, const G4String& title)
{
tools::histo::h2d* h2d = GetH2InFunction(id, "SetH2ZAxisTitle");
if ( ! h2d ) return false;
h2d->add_annotation(tools::histo::key_axis_z_title(), title);
return true;
}
//_____________________________________________________________________________
G4String G4H2ToolsManager::GetH2Title(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2Title");
if ( ! h2d ) return "";
return h2d->title();
}
//_____________________________________________________________________________
G4String G4H2ToolsManager::GetH2XAxisTitle(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2XAxisTitle");
if ( ! h2d ) return "";
G4String title;
G4bool result = h2d->annotation(tools::histo::key_axis_x_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get x_axis title for h2 id = " << id << ").";
G4Exception("G4H2ToolsManager::GetH2XAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4String G4H2ToolsManager::GetH2YAxisTitle(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2YAxisTitle");
if ( ! h2d ) return "";
G4String title;
G4bool result = h2d->annotation(tools::histo::key_axis_y_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get y_axis title for h2 id = " << id << ").";
G4Exception("G4H2ToolsManager::GetH2YAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4String G4H2ToolsManager::GetH2ZAxisTitle(G4int id) const
{
tools::histo::h2d* h2d = GetH2InFunction(id, "GetH2ZAxisTitle");
if ( ! h2d ) return "";
G4String title;
G4bool result = h2d->annotation(tools::histo::key_axis_z_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get z_axis title for h2 id = " << id << ").";
G4Exception("G4H2ToolsManager::GetH2ZAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::WriteOnAscii(std::ofstream& /*output*/)
{
// Write selected objects on ASCII file
// According to the implementation by Michel Maire, originally in
// extended examples.
// Not yet available for H2
return false;
}
//
// public methods
//
//_____________________________________________________________________________
void G4H2ToolsManager::AddH2Vector(
const std::vector<tools::histo::h2d*>& h2Vector)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("merge", "all h2", "");
#endif
std::vector<tools::histo::h2d*>::const_iterator itw = h2Vector.begin();
std::vector<tools::histo::h2d*>::iterator it;
for (it = fH2Vector.begin(); it != fH2Vector.end(); it++ ) {
(*it)->add(*(*itw++));
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("merge", "all h2", "");
#endif
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::Reset()
{
// Reset histograms and ntuple
G4bool finalResult = true;
std::vector<tools::histo::h2d*>::iterator it;
for (it = fH2Vector.begin(); it != fH2Vector.end(); it++ ) {
G4bool result = (*it)->reset();
if ( ! result ) finalResult = false;
}
return finalResult;
}
//_____________________________________________________________________________
G4bool G4H2ToolsManager::IsEmpty() const
{
return ! fH2Vector.size();
}
//_____________________________________________________________________________
tools::histo::h2d* G4H2ToolsManager::GetH2(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return GetH2InFunction(id, "GetH2", warn, onlyIfActive);
}