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
@@ -1,4 +1,4 @@
# $Id: GNUmakefile,v 1.4 2010-11-08 10:38:44 maire Exp $
# $Id: GNUmakefile 68059 2013-03-13 14:49:02Z gcosmo $
# --------------------------------------------------------------
# GNUmakefile for examples module. Gabriele Cosmo, 06/04/98.
# --------------------------------------------------------------
+21
View File
@@ -16,6 +16,27 @@ track of all tags.
* Reverse chronological order (last date on top), please *
----------------------------------------------------------
07/11/2013 I. Hrivnacova (excommon-analysis-V09-06-04)
- Implemented functions for user defined/logarithmic binning for H1
and H2; in case of H2 an exception is (not available in HBOOK)
11/07/2013 I. Hrivnacova (excommon-analysis-V09-06-03)
- Refactoring ExG4Hnook manager class following changes
in analysis (analysis-V09-06-11)
20/06/2013 I. Hrivnacova (excommon-analysis-V09-06-02)
- Fixed a typo in ExG4HbookAnalysisManager.hh which caused compilation
error
03/06/2013 I. Hrivnacova (excommon-analysis-V09-06-01)
- Implemented ExG4HbookAnalysisManager::Create() required with
update for MT migration; returns an exception in case of MT mode
(as Hbook is not supported with MT)
29/03/2013 I. Hrivnacova (excommon-analysis-V09-06-00)
- Updated to analysis-V09-06-05
- Extended the manager class for handling more than one ntuple
19/11/2012 I. Hrivnacova (excommon-analysis-V09-05-04)
- Updated to analysis-V09-05-15
- Adding functions for accessing h1, h2 by name
@@ -58,36 +58,10 @@ namespace G4Hbook {
typedef ExG4HbookAnalysisManager G4AnalysisManager;
}
struct h1_booking {
h1_booking(G4int nbins, G4double xmin, G4double xmax)
: fTitle(""),
fNbins(nbins),
fXmin(xmin),
fXmax(xmax) {}
G4String fTitle;
G4int fNbins;
G4double fXmin;
G4double fXmax;
};
struct h2_booking {
h2_booking(G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax)
: fTitle(""),
fNxbins(nxbins),
fXmin(xmin),
fXmax(xmax),
fNybins(nybins),
fYmin(ymin),
fYmax(ymax) {}
G4String fTitle;
G4int fNxbins;
G4double fXmin;
G4double fXmax;
G4int fNybins;
G4double fYmin;
G4double fYmax;
};
class ExG4HbookFileManager;
class ExG4HbookH1Manager;
class ExG4HbookH2Manager;
class ExG4HbookNtupleManager;
/// HBook Analysis manager
///
@@ -102,102 +76,9 @@ class ExG4HbookAnalysisManager : public G4VAnalysisManager
virtual ~ExG4HbookAnalysisManager();
// static methods
static ExG4HbookAnalysisManager* Create(G4bool isMaster = true);
static ExG4HbookAnalysisManager* Instance();
// Methods to manipulate files
using G4VAnalysisManager::OpenFile;
virtual G4bool OpenFile(const G4String& fileName);
virtual G4bool Write();
virtual G4bool CloseFile();
// Methods to create histogrammes, ntuples
virtual G4int CreateH1(const G4String& name, const G4String& title,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName = "none",
const G4String& fcnName = "none");
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");
virtual G4bool SetH1(G4int id,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName = "none",
const G4String& fcnName = "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");
virtual G4bool ScaleH1(G4int id, G4double factor);
virtual G4bool ScaleH2(G4int id, G4double factor);
virtual void CreateNtuple(const G4String& name, const G4String& title);
virtual G4int CreateNtupleIColumn(const G4String& name);
virtual G4int CreateNtupleFColumn(const G4String& name);
virtual G4int CreateNtupleDColumn(const G4String& name);
virtual void FinishNtuple();
// Methods to fill histogrammes, ntuples
virtual G4bool FillH1(G4int id, G4double value, G4double weight = 1.0);
virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
G4double weight = 1.0);
virtual G4bool FillNtupleIColumn(G4int id, G4int value);
virtual G4bool FillNtupleFColumn(G4int id, G4float value);
virtual G4bool FillNtupleDColumn(G4int id, G4double value);
virtual G4bool AddNtupleRow();
// Access methods
virtual tools::hbook::h1* GetH1(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
virtual tools::hbook::h2* GetH2(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
virtual tools::hbook::wntuple* GetNtuple() const;
// Access methods via names
virtual G4int GetH1Id(const G4String& name, G4bool warn = true) const;
virtual G4int GetH2Id(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;
// 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 SetH1Title(G4int id, const G4String& title);
virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
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 GetH1Title(G4int id) const;
virtual G4String GetH1XAxisTitle(G4int id) const;
virtual G4String GetH1YAxisTitle(G4int id) const;
virtual G4String GetH2Title(G4int id) const;
virtual G4String GetH2XAxisTitle(G4int id) const;
virtual G4String GetH2YAxisTitle(G4int id) const;
virtual G4String GetH2ZAxisTitle(G4int id) const;
// HBOOK does not allow IDs the same IDs for H1 and H2,
// and also IDs starting from 0; thats why there is defined an offset
// with respect to the G4AnalysisManager generic Ids.
@@ -206,89 +87,51 @@ class ExG4HbookAnalysisManager : public G4VAnalysisManager
// Set the offset of HBOOK ID for H1
// ( default value = firstHistoID if firstHistoID > 0; otherwise = 1)
G4bool SetH1HbookIdOffset(G4int offset);
//
// Set the offset of HBOOK ID for H2
// ( default value = firstHistoID + 100 if firstHistoID > 0; otherwise = 101 )
G4bool SetH2HbookIdOffset(G4int offset);
//
// Set the HBOOK ID for the ntuple
// (default value = 1 )
G4bool SetNtupleHbookId(G4int ntupleId);
G4int GetH1HbookIdOffset() const;
G4int GetH2HbookIdOffset() const;
G4int GetNtupleHbookId() const;
protected:
virtual G4bool WriteOnAscii(std::ofstream& output);
// Set the offset of HBOOK ID for H2
// ( default value = firstHistoID + 100 if firstHistoID > 0;
// otherwise = 101 )
G4bool SetH2HbookIdOffset(G4int offset);
G4int GetH2HbookIdOffset() const;
// Set the offset of NTUPLE ID for ntuples
// ( default value = firstNtupleID if firstNtupleID > 0; otherwise = 1)
G4bool SetNtupleHbookIdOffset(G4int offset);
G4int GetNtupleHbookIdOffset() const;
// Access methods
//
tools::hbook::h1* GetH1(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
tools::hbook::h2* GetH2(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
tools::hbook::wntuple* GetNtuple() const;
tools::hbook::wntuple* GetNtuple(G4int ntupleId) const;
protected:
// virtual methods from base class
virtual G4bool OpenFileImpl(const G4String& fileName);
virtual G4bool WriteImpl();
virtual G4bool CloseFileImpl();
private:
// static data members
//
static ExG4HbookAnalysisManager* fgInstance;
static const G4int fgkDefaultH2HbookIdOffset;
static const G4int fgkDefaultNtupleHbookId;
static const G4String fgkDefaultNtupleDirectoryName;
// methods
//
void SetH1HbookIdOffset();
void SetH2HbookIdOffset();
void CreateH1FromBooking();
void CreateH2FromBooking();
void CreateNtupleFromBooking();
tools::hbook::wntuple::column<int>* GetNtupleIColumn(G4int id) const;
tools::hbook::wntuple::column<float>* GetNtupleFColumn(G4int id) const;
tools::hbook::wntuple::column<double>* GetNtupleDColumn(G4int id) const;
void Reset();
virtual h1_booking* GetH1Booking(G4int id, G4bool warn = true) const;
virtual h2_booking* GetH2Booking(G4int id, G4bool warn = true) const;
virtual tools::hbook::h1* GetH1InFunction(G4int id, G4String function,
G4bool warn = true,
G4bool onlyIfActive = true) const;
virtual tools::hbook::h2* GetH2InFunction(G4int id, G4String function,
G4bool warn = true,
G4bool onlyIfActive = true) const;
void UpdateTitle(G4String& title,
const G4String& unitName, const G4String& fcnName) const;
// data members
//
G4int fH1HbookIdOffset;
G4int fH2HbookIdOffset;
G4int fNtupleHbookId;
tools::hbook::wfile* fFile;
std::vector<tools::hbook::h1*> fH1Vector;
std::vector<tools::hbook::h2*> fH2Vector;
std::vector<h1_booking*> fH1BookingVector;
std::vector<h2_booking*> fH2BookingVector;
std::map<G4String, G4int> fH1NameIdMap;
std::map<G4String, G4int> fH2NameIdMap;
tools::hbook::wntuple* fNtuple;
tools::ntuple_booking* fNtupleBooking;
std::map<G4int, tools::hbook::wntuple::column<int>* > fNtupleIColumnMap;
std::map<G4int, tools::hbook::wntuple::column<float>* > fNtupleFColumnMap;
std::map<G4int, tools::hbook::wntuple::column<double>* > fNtupleDColumnMap;
ExG4HbookH1Manager* fH1Manager;
ExG4HbookH2Manager* fH2Manager;
ExG4HbookNtupleManager* fNtupleManager;
ExG4HbookFileManager* fFileManager;
};
// inline functions
inline G4int ExG4HbookAnalysisManager::GetH1HbookIdOffset() const {
return fH1HbookIdOffset;
}
inline G4int ExG4HbookAnalysisManager::GetH2HbookIdOffset() const {
return fH2HbookIdOffset;
}
inline G4int ExG4HbookAnalysisManager::GetNtupleHbookId() const {
return fNtupleHbookId;
}
#include "ExG4HbookAnalysisManager.icc"
#endif
@@ -0,0 +1,102 @@
//
// ********************************************************************
// * 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: ExG4HbookAnalysisManager.hh 70604 2013-06-03 11:27:06Z ihrivnac $
#include "ExG4HbookH1Manager.hh"
#include "ExG4HbookH2Manager.hh"
#include "ExG4HbookNtupleManager.hh"
//_____________________________________________________________________________
inline
G4bool ExG4HbookAnalysisManager::SetH1HbookIdOffset(G4int offset)
{
return fH1Manager->SetH1HbookIdOffset(offset);
}
//_____________________________________________________________________________
inline
G4int ExG4HbookAnalysisManager::GetH1HbookIdOffset() const
{
return fH1Manager->GetH1HbookIdOffset();
}
//_____________________________________________________________________________
inline
G4bool ExG4HbookAnalysisManager::SetH2HbookIdOffset(G4int offset)
{
return fH2Manager->SetH2HbookIdOffset(offset);
}
//_____________________________________________________________________________
inline
G4int ExG4HbookAnalysisManager::GetH2HbookIdOffset() const
{
return fH2Manager->GetH2HbookIdOffset();
}
//_____________________________________________________________________________
inline
G4bool ExG4HbookAnalysisManager::SetNtupleHbookIdOffset(G4int offset)
{
return fNtupleManager->SetNtupleHbookIdOffset(offset);
}
//_____________________________________________________________________________
inline
G4int ExG4HbookAnalysisManager::GetNtupleHbookIdOffset() const
{
return fNtupleManager->GetNtupleHbookIdOffset();
}
//_____________________________________________________________________________
inline
tools::hbook::h1* ExG4HbookAnalysisManager::GetH1(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return fH1Manager->GetH1(id, warn, onlyIfActive);
}
//_____________________________________________________________________________
inline
tools::hbook::h2* ExG4HbookAnalysisManager::GetH2(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return fH2Manager->GetH2(id, warn, onlyIfActive);
}
//_____________________________________________________________________________
inline
tools::hbook::wntuple* ExG4HbookAnalysisManager::GetNtuple() const
{
return fNtupleManager->GetNtuple();
}
//_____________________________________________________________________________
inline
tools::hbook::wntuple* ExG4HbookAnalysisManager::GetNtuple(G4int ntupleId) const
{
return fNtupleManager->GetNtuple(ntupleId);
}
@@ -0,0 +1,81 @@
//
// ********************************************************************
// * 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$
//
/// \file common/analysis/include/ExG4HbookFileManager.hh
/// \brief Definition of the ExG4HbookFileManager class
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#ifndef ExG4HbookFileManager_h
#define ExG4HbookFileManager_h 1
#include "G4VFileManager.hh"
#include "globals.hh"
#include <tools/hbook/wfile>
/// The manager for HBook file operations.
///
/// The class implements the G4VFileManager manager for HBook.
/// It is provided separately from geant4/source/analysis in order
/// to avoid a need of linking Geant4 kernel libraries with cerblib.
class ExG4HbookFileManager : public G4VFileManager
{
public:
ExG4HbookFileManager(const G4AnalysisManagerState& state);
virtual ~ExG4HbookFileManager();
// Methods to manipulate files
using G4VFileManager::OpenFile;
virtual G4bool OpenFile(const G4String& fileName);
virtual G4bool WriteFile();
virtual G4bool CloseFile();
// Specific methods for files per objects
void CreateNtupleDirectory();
// Get method
G4bool IsFile() const;
private:
static const G4String fgkDefaultNtupleDirectoryName;
// data members
tools::hbook::wfile* fFile;
};
// inline functions
inline G4bool ExG4HbookFileManager::IsFile() const
{ return fFile; }
#endif
#endif
@@ -0,0 +1,215 @@
//
// ********************************************************************
// * 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$
//
/// \file common/analysis/include/ExG4HbookH1Manager.hh
/// \brief Definition of the ExG4HbookH1Manager class
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#ifndef ExG4HbookH1Manager_h
#define ExG4HbookH1Manager_h 1
#include "G4VH1Manager.hh"
#include "G4HnInformation.hh"
#include "globals.hh"
#include <tools/hbook/h1>
#include <vector>
#include <map>
class ExG4HbookFileManager;
struct h1_booking {
h1_booking(G4int nbins, G4double xmin, G4double xmax)
: fTitle(""),
fNbins(nbins),
fXmin(xmin),
fXmax(xmax),
fEdges() {}
h1_booking(const std::vector<G4double>& edges)
: fTitle(""),
fNbins(0),
fXmin(0),
fXmax(0),
fEdges() {
for (G4int i=0; i<=G4int(edges.size()); ++i) fEdges.push_back(edges[i]);
}
G4String fTitle;
G4int fNbins;
G4double fXmin;
G4double fXmax;
std::vector<G4double> fEdges;
};
/// Manager class for HBook H1 histograms
///
/// The class implements the G4VH1Manager manager for HBook.
/// It is provided separately from geant4/source/analysis in order
/// to avoid a need of linking Geant4 kernel libraries with cerblib.
class ExG4HbookH1Manager : public G4VH1Manager
{
friend class ExG4HbookAnalysisManager;
protected:
ExG4HbookH1Manager(const G4AnalysisManagerState& state);
virtual ~ExG4HbookH1Manager();
// Functions specific to the output type
//
// HBOOK does not allow IDs the same IDs for H1 and H2,
// and also IDs starting from 0; thats why there is defined an offset
// with respect to the G4AnalysisManager generic Ids.
// The default values of these offsets can be changed by the user.
//
// Set the offset of HBOOK ID for H1
// ( default value = firstHistoID if firstHistoID > 0; otherwise = 1)
G4bool SetH1HbookIdOffset(G4int offset);
G4int GetH1HbookIdOffset() const;
// Set methods
void SetFileManager(ExG4HbookFileManager* fileManager);
// Access methods
//
tools::hbook::h1* GetH1(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
// Virtual functions from base class
//
// Methods to create histogrammes, ntuples
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& binSchemeName = "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);
// Methods to fill histogrammes, ntuples
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;
// Setters for attributes for plotting
virtual G4bool SetH1Title(G4int id, const G4String& title);
virtual G4bool SetH1XAxisTitle(G4int id, const G4String& title);
virtual G4bool SetH1YAxisTitle(G4int id, const G4String& title);
// Access attributes for plotting
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
//
void SetH1HbookIdOffset();
void AddH1Information(const G4String& name,
const G4String& unitName,
const G4String& fcnName,
G4BinScheme binScheme) const;
G4int CreateH1FromBooking(h1_booking* h1Booking,
G4bool chDir = true);
G4int RegisterH1Booking(const G4String& name,
h1_booking* h1Booking);
void BeginCreateH1(const G4String& name);
G4int FinishCreateH1(const G4String& name, h1_booking* h1Booking,
const G4String& unitName, const G4String& fcnName,
G4BinScheme binScheme);
G4bool BeginSetH1(G4int id,
h1_booking* h1Booking,
G4HnInformation* info);
G4bool FinishSetH1(G4int id,
G4HnInformation* info,
const G4String& unitName, const G4String& fcnName,
G4BinScheme binScheme);
void CreateH1sFromBooking();
void Reset();
virtual h1_booking* GetH1Booking(G4int id, G4bool warn = true) const;
virtual tools::hbook::h1* GetH1InFunction(G4int id, G4String function,
G4bool warn = true,
G4bool onlyIfActive = true) const;
// data members
//
ExG4HbookFileManager* fFileManager;
G4int fH1HbookIdOffset;
std::vector<tools::hbook::h1*> fH1Vector;
std::vector<h1_booking*> fH1BookingVector;
std::map<G4String, G4int> fH1NameIdMap;
};
// inline functions
inline void ExG4HbookH1Manager::SetFileManager(ExG4HbookFileManager* fileManager)
{ fFileManager = fileManager; }
inline G4int ExG4HbookH1Manager::GetH1HbookIdOffset() const {
return fH1HbookIdOffset;
}
#endif
#endif
@@ -0,0 +1,209 @@
//
// ********************************************************************
// * 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$
//
/// \file common/analysis/include/ExG4HbookH2Manager.hh
/// \brief Definition of the ExG4HbookH2Manager class
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#ifndef ExG4HbookH2Manager_h
#define ExG4HbookH2Manager_h 1
#include "G4VH2Manager.hh"
#include "globals.hh"
#include <tools/hbook/h2>
#include <vector>
#include <map>
class ExG4HbookFileManager;
struct h2_booking {
h2_booking(G4int nxbins, G4double xmin, G4double xmax,
G4int nybins, G4double ymin, G4double ymax)
: fTitle(""),
fNxbins(nxbins),
fXmin(xmin),
fXmax(xmax),
fNybins(nybins),
fYmin(ymin),
fYmax(ymax) {}
G4String fTitle;
G4int fNxbins;
G4double fXmin;
G4double fXmax;
G4int fNybins;
G4double fYmin;
G4double fYmax;
};
/// Manager class for HBook H2 histograms
///
/// The class implements the G4VH2Manager manager for HBook.
/// It is provided separately from geant4/source/analysis in order
/// to avoid a need of linking Geant4 kernel libraries with cerblib.
class ExG4HbookH2Manager : public G4VH2Manager
{
friend class ExG4HbookAnalysisManager;
protected:
ExG4HbookH2Manager(const G4AnalysisManagerState& state);
virtual ~ExG4HbookH2Manager();
// Functions specific to the output type
//
// Set the offset of HBOOK ID for H2
// ( default value = firstHistoID + 100 if firstHistoID > 0;
// otherwise = 101 )
G4bool SetH2HbookIdOffset(G4int offset);
G4int GetH2HbookIdOffset() const;
// Set methods
void SetFileManager(ExG4HbookFileManager* fileManager);
// Access methods
tools::hbook::h2* GetH2(G4int id, G4bool warn = true,
G4bool onlyIfActive = true) const;
protected:
// Virtual functions from base class
//
// Methods to create histogrammes, ntuples
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);
// Methods to fill histogrammes, ntuples
virtual G4bool FillH2(G4int id, G4double xvalue, G4double yvalue,
G4double weight = 1.0);
// Access methods via names
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:
// static data members
//
static const G4int fgkDefaultH2HbookIdOffset;
// methods
//
void SetH2HbookIdOffset();
void CreateH2sFromBooking();
void Reset();
virtual h2_booking* GetH2Booking(G4int id, G4bool warn = true) const;
virtual tools::hbook::h2* GetH2InFunction(G4int id, G4String function,
G4bool warn = true,
G4bool onlyIfActive = true) const;
// data members
//
ExG4HbookFileManager* fFileManager;
G4int fH2HbookIdOffset;
std::vector<tools::hbook::h2*> fH2Vector;
std::vector<h2_booking*> fH2BookingVector;
std::map<G4String, G4int> fH2NameIdMap;
};
// inline functions
inline void ExG4HbookH2Manager::SetFileManager(ExG4HbookFileManager* fileManager)
{ fFileManager = fileManager; }
inline G4int ExG4HbookH2Manager::GetH2HbookIdOffset() const {
return fH2HbookIdOffset;
}
#endif
#endif
@@ -0,0 +1,63 @@
//
// ********************************************************************
// * 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: G4HnInformation.hh 66310 2012-12-17 11:56:35Z ihrivnac $
// Author: Ivana Hrivnacova, 04/07/2012 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#ifndef ExG4HbookNtupleDescription_h
#define ExG4HbookNtupleDescription_h 1
#include "tools/hbook/wntuple"
#include "tools/ntuple_booking"
#include <map>
// Structure containing the information related to one Hbook ntuple
struct ExG4HbookNtupleDescription
{
ExG4HbookNtupleDescription()
: fNtuple(0),
fNtupleBooking(0),
fNtupleIColumnMap(),
fNtupleFColumnMap(),
fNtupleDColumnMap() {}
~ExG4HbookNtupleDescription()
{ delete fNtupleBooking; }
tools::hbook::wntuple* fNtuple;
tools::ntuple_booking* fNtupleBooking;
std::map<G4int, tools::hbook::wntuple::column<int>* > fNtupleIColumnMap;
std::map<G4int, tools::hbook::wntuple::column<float>* > fNtupleFColumnMap;
std::map<G4int, tools::hbook::wntuple::column<double>* > fNtupleDColumnMap;
};
#endif
#endif
@@ -0,0 +1,152 @@
//
// ********************************************************************
// * 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$
//
/// \file common/analysis/include/ExG4HbookNtupleManager.hh
/// \brief Definition of the ExG4HbookNtupleManager class
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#ifndef ExG4HbookNtupleManager_h
#define ExG4HbookNtupleManager_h 1
#include "G4VNtupleManager.hh"
#include "ExG4HbookNtupleDescription.hh"
#include "globals.hh"
#include <tools/hbook/wntuple>
#include <vector>
#include <map>
class ExG4HbookFileManager;
/// Manager class for HBook ntuples
///
/// The class implements the G4VAnalysisManager manager for HBook.
/// It is provided separately from geant4/source/analysis in order
/// to avoid a need of linking Geant4 kernel libraries with cerblib.
class ExG4HbookNtupleManager : public G4VNtupleManager
{
friend class ExG4HbookAnalysisManager;
protected:
ExG4HbookNtupleManager(const G4AnalysisManagerState& state);
virtual ~ExG4HbookNtupleManager();
// Functions specific to the output type
//
// Set the offset of NTUPLE ID for ntuples
// ( default value = firstNtupleID if firstNtupleID > 0; otherwise = 1)
G4bool SetNtupleHbookIdOffset(G4int offset);
G4int GetNtupleHbookIdOffset() const;
// Set methods
void SetFileManager(ExG4HbookFileManager* fileManager);
// Access methods
tools::hbook::wntuple* GetNtuple() const;
tools::hbook::wntuple* GetNtuple(G4int ntupleId) const;
// Virtual functions from base class
//
// Methods to create ntuples
virtual G4int CreateNtuple(const G4String& name, const G4String& title);
// Create columns in the last created ntuple
virtual G4int CreateNtupleIColumn(const G4String& name);
virtual G4int CreateNtupleFColumn(const G4String& name);
virtual G4int CreateNtupleDColumn(const G4String& name);
virtual void FinishNtuple();
// Create columns in the ntuple with given id
virtual G4int CreateNtupleIColumn(G4int ntupleId, const G4String& name);
virtual G4int CreateNtupleFColumn(G4int ntupleId, const G4String& name);
virtual G4int CreateNtupleDColumn(G4int ntupleId, const G4String& name);
virtual void FinishNtuple(G4int ntupleId);
// Methods to fill ntuples
// Methods for ntuple with id = FirstNtupleId
virtual G4bool FillNtupleIColumn(G4int columnId, G4int value);
virtual G4bool FillNtupleFColumn(G4int columnId, G4float value);
virtual G4bool FillNtupleDColumn(G4int columnId, G4double value);
virtual G4bool AddNtupleRow();
// Methods for ntuple with id > FirstNtupleId (when more ntuples exist)
virtual G4bool FillNtupleIColumn(
G4int ntupleId, G4int columnId, G4int value);
virtual G4bool FillNtupleFColumn(
G4int ntupleId, G4int columnId, G4float value);
virtual G4bool FillNtupleDColumn(
G4int ntupleId, G4int columnId, G4double value);
virtual G4bool AddNtupleRow(G4int ntupleId);
// Access methods
virtual G4int GetNofNtuples() const;
private:
// methods
//
void SetNtupleHbookIdOffset();
void CreateNtuplesFromBooking();
tools::hbook::wntuple::column<int>*
GetNtupleIColumn(G4int ntupleId, G4int columnId) const;
tools::hbook::wntuple::column<float>*
GetNtupleFColumn(G4int ntupleId, G4int columnId) const;
tools::hbook::wntuple::column<double>*
GetNtupleDColumn(G4int ntupleId, G4int columnId) const;
void Reset();
ExG4HbookNtupleDescription* GetNtupleInFunction(G4int id,
G4String function,
G4bool warn = true,
G4bool onlyIfActive = true) const;
// data members
//
ExG4HbookFileManager* fFileManager;
G4int fNtupleHbookIdOffset;
std::vector<ExG4HbookNtupleDescription*> fNtupleVector;
};
// inline functions
inline void ExG4HbookNtupleManager::SetFileManager(ExG4HbookFileManager* fileManager)
{ fFileManager = fileManager; }
inline G4int ExG4HbookNtupleManager::GetNtupleHbookIdOffset() const {
return fNtupleHbookIdOffset;
}
inline G4int ExG4HbookNtupleManager::GetNofNtuples() const
{ return fNtupleVector.size(); }
#endif
#endif
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,163 @@
//
// ********************************************************************
// * 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$
//
/// \file common/analysis/src/ExG4HbookFileManager.cc
/// \brief Implementation of the ExG4HbookFileManager class
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#include "ExG4HbookFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include <iostream>
const G4String ExG4HbookFileManager::fgkDefaultNtupleDirectoryName = "ntuple";
//_____________________________________________________________________________
ExG4HbookFileManager::ExG4HbookFileManager(const G4AnalysisManagerState& state)
: G4VFileManager(state),
fFile(0)
{
}
//_____________________________________________________________________________
ExG4HbookFileManager::~ExG4HbookFileManager()
{
delete fFile;
}
//
// public methods
//
//_____________________________________________________________________________
G4bool ExG4HbookFileManager::OpenFile(const G4String& fileName)
{
// Keep file name
fFileName = fileName;
G4String name = GetFullFileName();
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("open", "analysis file", name);
#endif
// delete a previous file if it exists
if ( fFile ) delete fFile;
tools::hbook::CHCDIR("//PAWC"," ");
unsigned int unit = 1;
fFile = new tools::hbook::wfile(std::cout, name, unit);
if ( ! fFile->is_valid() ) {
G4ExceptionDescription description;
description << " " << "Cannot open file " << fileName;
G4Exception("G4HbookAnalysisManager::OpenFile()",
"Analysis_W001", JustWarning, description);
return false;
}
// At this point, in HBOOK, we should have :
// - created a //LUN1 directory attached to the file
// - created a //PAWC/LUN1 in memory
// - be in the directory //PAWC/LUN1.
// create an "histo" HBOOK directory both in memory and in the file :
if ( fHistoDirectoryName != "" ) {
tools::hbook::CHCDIR("//PAWC/LUN1"," ");
tools::hbook::CHMDIR(fHistoDirectoryName.data()," ");
tools::hbook::CHCDIR("//LUN1"," ");
tools::hbook::CHMDIR(fHistoDirectoryName.data()," ");
}
// the five upper lines could have been done with :
//fFile->cd_home();
//fFile->mkcd("histo");
fLockFileName = true;
fLockHistoDirectoryName = true;
fLockNtupleDirectoryName = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("open", "analysis file", name);
#endif
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookFileManager::WriteFile()
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("write", "file", GetFullFileName());
#endif
// Return to //PAWC/LUN1 :
//tools::hbook::CHCDIR("//PAWC/LUN1"," ");
G4bool result = fFile->write();
#ifdef G4VERBOSE
if ( fState.GetVerboseL1() )
fState.GetVerboseL1()->Message("write", "file", GetFullFileName(), result);
#endif
return result;
}
//_____________________________________________________________________________
G4bool ExG4HbookFileManager::CloseFile()
{
// close file
G4bool result = fFile->close();
fLockFileName = false;
return result;
}
//_____________________________________________________________________________
void ExG4HbookFileManager::CreateNtupleDirectory()
{
// Create an "ntuple" directory both in memory and in the file
static G4bool isDone = false;
// Do not create directory more than once
if (isDone) return;
fFile->cd_home(); //go under //PAWC/LUN1
if ( fNtupleDirectoryName == "" )
fFile->mkcd(fgkDefaultNtupleDirectoryName.data());
else
fFile->mkcd(fNtupleDirectoryName.data());
fLockNtupleDirectoryName = true;
isDone = false;
}
#endif
@@ -0,0 +1,896 @@
//
// ********************************************************************
// * 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$
//
/// \file common/analysis/src/ExG4HbookH1Manager.cc
/// \brief Implementation of the ExG4HbookH1Manager class
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#include "ExG4HbookH1Manager.hh"
#include "ExG4HbookFileManager.hh"
#include "G4HnManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
#include <fstream>
using namespace G4Analysis;
//_____________________________________________________________________________
ExG4HbookH1Manager::ExG4HbookH1Manager(const G4AnalysisManagerState& state)
: G4VH1Manager(state),
fFileManager(0),
fH1HbookIdOffset(-1),
fH1Vector(),
fH1BookingVector(),
fH1NameIdMap()
{
}
//_____________________________________________________________________________
ExG4HbookH1Manager::~ExG4HbookH1Manager()
{
// Delete h1
Reset();
// Delete h1 booking
std::vector<h1_booking*>::iterator it;
for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); it++ ) {
delete *it;
}
}
//
// utility functions
//
namespace {
//_____________________________________________________________________________
void ConvertToFloat(const std::vector<G4double>& doubleVector,
std::vector<float>& floatVector)
{
for (G4int i=0; i<G4int(doubleVector.size()); ++i)
floatVector.push_back((float)doubleVector[i]);
}
//_____________________________________________________________________________
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;
}
//_____________________________________________________________________________
h1_booking* CreateH1Booking(const G4String& title,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName,
const G4String& fcnName,
G4BinScheme binScheme)
{
G4Fcn fcn = GetFunction(fcnName);
h1_booking* h1Booking = 0;
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("ExG4HbookH1Manager::CreateH1",
"Analysis_W013", JustWarning, description);
}
h1Booking = new h1_booking(nbins, fcn(xmin), fcn(xmax));
// h1_booking object is deleted in destructor
}
else {
// Compute edges
G4cout << " 1x1" << G4endl;
std::vector<G4double> edges;
G4cout << " 1x2" << G4endl;
ComputeEdges(nbins, xmin, xmax, fcn, binScheme, edges);
G4cout << " 1x2" << G4endl;
h1Booking = new h1_booking(edges);
// h1_booking object is deleted in destructor
}
h1Booking->fTitle = title;
UpdateTitle(h1Booking->fTitle, unitName, fcnName);
return h1Booking;
}
//_____________________________________________________________________________
h1_booking* CreateH1Booking(const G4String& title,
const std::vector<G4double>& edges,
const G4String& unitName,
const G4String& fcnName)
{
G4Fcn fcn = GetFunction(fcnName);
// Apply function
std::vector<G4double> newEdges;
ComputeEdges(edges, fcn, newEdges);
G4cout << " 11" << G4endl;
h1_booking* h1Booking = new h1_booking(newEdges);
G4cout << " 12" << G4endl;
// h1_booking object is deleted in destructor
h1Booking->fTitle = title;
UpdateTitle(h1Booking->fTitle, unitName, fcnName);
return h1Booking;
}
//_____________________________________________________________________________
void UpdateH1Booking(h1_booking* h1Booking,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName,
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("ExG4HbookH1Manager::SetH1",
"Analysis_W013", JustWarning, description);
}
h1Booking->fNbins = nbins;
h1Booking->fXmin = fcn(xmin);
h1Booking->fXmax = fcn(xmax);
}
else {
// Compute edges
ComputeEdges(nbins, xmin, xmax, fcn, binScheme, h1Booking->fEdges);
}
UpdateTitle(h1Booking->fTitle, unitName, fcnName);
}
//_____________________________________________________________________________
void UpdateH1Booking(h1_booking* h1Booking,
const std::vector<G4double>& edges,
const G4String& unitName,
const G4String& fcnName)
{
G4Fcn fcn = GetFunction(fcnName);
// Apply function
ComputeEdges(edges, fcn, h1Booking->fEdges);
UpdateTitle(h1Booking->fTitle, unitName, fcnName);
}
//_____________________________________________________________________________
void ConfigureHbookH1(tools::hbook::h1* h1,
G4int nbins, G4double xmin, G4double xmax,
const G4String& fcnName,
G4BinScheme binScheme)
{
G4Fcn fcn = GetFunction(fcnName);
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("ExG4HbookH1Manager::SetH1",
"Analysis_W013", JustWarning, description);
}
h1->configure(nbins, fcn(xmin), fcn(xmax));
}
else {
// Compute bins
std::vector<G4double> edges;
ComputeEdges(nbins, xmin, xmax, fcn, binScheme, edges);
// Convert to float
std::vector<float> fedges;
ConvertToFloat(edges, fedges);
h1->configure(fedges);
}
}
//_____________________________________________________________________________
void ConfigureHbookH1(tools::hbook::h1* h1,
const std::vector<G4double>& edges,
const G4String& fcnName)
{
// Apply function to edges
G4Fcn fcn = GetFunction(fcnName);
std::vector<G4double> newEdges;
ComputeEdges(edges, fcn, newEdges);
// Convert to float
std::vector<float> newFEdges;
ConvertToFloat(newEdges, newFEdges);
h1->configure(newFEdges);
}
}
//
// private methods
//
//_____________________________________________________________________________
void ExG4HbookH1Manager::SetH1HbookIdOffset()
{
// Set fH1HbookIdOffset if needed
if ( fH1HbookIdOffset == -1 ) {
if ( fFirstId > 0 )
fH1HbookIdOffset = 0;
else
fH1HbookIdOffset = 1;
if ( fH1HbookIdOffset > 0 ) {
G4ExceptionDescription description;
description << "H1 will be defined in HBOOK with ID = G4_firstHistoId + 1";
G4Exception("ExG4HbookH1Manager::SetH1HbookIdOffset()",
"Analysis_W011", JustWarning, description);
}
}
}
//_____________________________________________________________________________
void ExG4HbookH1Manager::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 ExG4HbookH1Manager::CreateH1FromBooking(h1_booking* h1Booking,
G4bool chDir)
{
// Create h1 from h1_booking.
if ( chDir ) {
// Go to histograms directory if defined
if ( fFileManager->GetHistoDirectoryName() != "" ) {
G4String histoPath = "//PAWC/LUN1/";
histoPath.append(fFileManager->GetHistoDirectoryName().data());
tools::hbook::CHCDIR(histoPath.data()," ");
}
}
G4int index = fH1Vector.size();
G4int id = index + fFirstId;
G4HnInformation*
info = fHnManager->GetHnInformation(id, "CreateH1FromBooking");
// Hbook index
G4int hbookIndex = fH1HbookIdOffset + index + fFirstId;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create from booking", "h1", info->fName);
#endif
// Create h1
tools::hbook::h1* h1 = 0;
if ( ! h1Booking->fEdges.size() ) {
h1 = new tools::hbook::h1(
hbookIndex, h1Booking->fTitle,
h1Booking->fNbins, h1Booking->fXmin, h1Booking->fXmax);
}
else {
// Convert to float
std::vector<float> newEdges;
ConvertToFloat(h1Booking->fEdges, newEdges);
h1 = new tools::hbook::h1(hbookIndex, h1Booking->fTitle, newEdges);
}
fH1Vector.push_back(h1);
if ( chDir ) {
if ( fFileManager->GetHistoDirectoryName() != "" ) {
// Return to //PAWC/LUN1 :
tools::hbook::CHCDIR("//PAWC/LUN1"," ");
}
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() ) {
G4ExceptionDescription description;
description << " name : " << info->fName << " hbook index : " << hbookIndex;
fState.GetVerboseL3()->Message("create from booking", "h1", description);
}
#endif
return id;
}
//_____________________________________________________________________________
G4int ExG4HbookH1Manager::RegisterH1Booking(const G4String& name,
h1_booking* h1Booking)
{
// Register h1
G4int index = fH1BookingVector.size();
fH1BookingVector.push_back(h1Booking);
fH1NameIdMap[name] = index + fFirstId;
// Lock id
fLockFirstId = true;
return index + fFirstId;
}
//_____________________________________________________________________________
void ExG4HbookH1Manager::BeginCreateH1(const G4String& name)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "H1", name);
#endif
// Set fH1HbookIdOffset if needed
SetH1HbookIdOffset();
}
//_____________________________________________________________________________
G4int ExG4HbookH1Manager::FinishCreateH1(
const G4String& name, h1_booking* h1Booking,
const G4String& unitName, const G4String& fcnName,
G4BinScheme binScheme)
{
// Register h1 booking
G4int id = RegisterH1Booking(name, h1Booking);
// Save H1 information
AddH1Information(name, unitName, fcnName, binScheme);
// Create h1 if the file is open
if ( fFileManager->IsFile() ) {
CreateH1FromBooking(h1Booking);
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4int hbookIndex = fH1HbookIdOffset + id;
G4ExceptionDescription description;
description << " name : " << name << " hbook index : " << hbookIndex;
fState.GetVerboseL2()->Message("create", "H1", description);
}
#endif
return id;
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::BeginSetH1(
G4int id,
h1_booking* h1Booking,
G4HnInformation* info)
{
h1Booking = GetH1Booking(id, false);
if ( ! h1Booking ) {
G4ExceptionDescription description;
description << " " << "histogram " << id << " does not exist.";
G4Exception("G4HbookAnalysisManager::SetH1()",
"Analysis_W007", JustWarning, description);
return false;
}
info = fHnManager->GetHnInformation(id,"SetH1");
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("configure", "H1", info->fName);
#endif
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::FinishSetH1(
G4int id,
G4HnInformation* info,
const G4String& unitName,
const G4String& fcnName,
G4BinScheme binScheme)
{
// Update information
UpdateH1Information(info, unitName, fcnName, binScheme);
// Set activation
fHnManager->SetActivation(id, true);
return true;
}
//_____________________________________________________________________________
void ExG4HbookH1Manager::CreateH1sFromBooking()
{
// Create all h1 from h1_booking.
// Do nothing if any h1 histogram already exists
// or no h1 histograms are booked
if ( fH1Vector.size() || ( fH1BookingVector.size() == 0 ) ) return;
// Go to histograms directory if defined
if ( fFileManager->GetHistoDirectoryName() != "" ) {
G4String histoPath = "//PAWC/LUN1/";
histoPath.append(fFileManager->GetHistoDirectoryName().data());
tools::hbook::CHCDIR(histoPath.data()," ");
}
// Create histograms
std::vector<h1_booking*>::const_iterator it;
for ( it = fH1BookingVector.begin(); it != fH1BookingVector.end(); ++it) {
CreateH1FromBooking(*it, false);
}
// Return backi from histograms directory if defined
if ( fFileManager->GetHistoDirectoryName() != "" ) {
// Return to //PAWC/LUN1 :
tools::hbook::CHCDIR("//PAWC/LUN1"," ");
}
}
//_____________________________________________________________________________
void ExG4HbookH1Manager::Reset()
{
// Reset histograms and ntuple
// Delete histograms
std::vector<tools::hbook::h1*>::iterator it;
for (it = fH1Vector.begin(); it != fH1Vector.end(); it++ ) {
delete *it;
}
// Clear vectors
fH1Vector.clear();
}
//_____________________________________________________________________________
h1_booking* ExG4HbookH1Manager::GetH1Booking(G4int id, G4bool warn) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fH1BookingVector.size()) ) {
if ( warn) {
G4ExceptionDescription description;
description << " " << "histo " << id << " does not exist.";
G4Exception("G4HbookAnalysisManager::GetH1Booking()",
"Analysis_W007", JustWarning, description);
}
return 0;
}
return fH1BookingVector[index];
}
//
// protected methods
//
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::WriteOnAscii(std::ofstream& output)
{
// Write selected objects on ASCII file
// (Only H1 implemented by now)
// 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::hbook::h1* h1 = fH1Vector[i];
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()->Message("write on ascii", "h1", 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;
}
//_____________________________________________________________________________
tools::hbook::h1* ExG4HbookH1Manager::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 = "ExG4HbookH1Manager::";
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];
}
//
// public methods
//
//_____________________________________________________________________________
G4int ExG4HbookH1Manager::CreateH1(
const G4String& name, const G4String& title,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName, const G4String& fcnName,
const G4String& binSchemeName)
{
BeginCreateH1(name);
G4BinScheme binScheme = GetBinScheme(binSchemeName);
// Create h1 booking
h1_booking* h1Booking
= CreateH1Booking(title, nbins, xmin, xmax, unitName, fcnName, binScheme);
return FinishCreateH1(name, h1Booking, unitName, fcnName, binScheme);
}
//_____________________________________________________________________________
G4int ExG4HbookH1Manager::CreateH1(
const G4String& name, const G4String& title,
const std::vector<G4double>& edges,
const G4String& unitName,
const G4String& fcnName)
{
BeginCreateH1(name);
// Create h1 booking
h1_booking* h1Booking
= CreateH1Booking(title, edges, unitName, fcnName);
return FinishCreateH1(name, h1Booking, unitName, fcnName, kUserBinScheme);
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::SetH1(G4int id,
G4int nbins, G4double xmin, G4double xmax,
const G4String& unitName,
const G4String& fcnName,
const G4String& binSchemeName)
{
h1_booking* h1Booking = 0;
G4HnInformation* info = 0;
if ( ! BeginSetH1(id, h1Booking, info) ) return false;
G4BinScheme binScheme = GetBinScheme(binSchemeName);
// Update H1 booking
UpdateH1Booking(h1Booking,
nbins, xmin, xmax, unitName, fcnName, binScheme);
// Re-configure histogram if it was already defined
if ( fH1Vector.size() ) {
tools::hbook::h1* h1 = GetH1(id);
ConfigureHbookH1(h1, nbins, xmin, xmax, fcnName, binScheme);
}
return FinishSetH1(id, info, unitName, fcnName, binScheme);
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::SetH1(G4int id,
const std::vector<G4double>& edges,
const G4String& unitName,
const G4String& fcnName)
{
h1_booking* h1Booking = 0;
G4HnInformation* info = 0;
if ( ! BeginSetH1(id, h1Booking, info) ) return false;
// Update H1 booking
UpdateH1Booking(h1Booking, edges, unitName, fcnName);
// Re-configure histogram if it was already defined
if ( fH1Vector.size() ) {
tools::hbook::h1* h1 = GetH1(id);
ConfigureHbookH1(h1, edges, fcnName);
}
return
FinishSetH1(id, info, unitName, fcnName, kUserBinScheme);
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::ScaleH1(G4int id, G4double factor)
{
tools::hbook::h1* h1 = GetH1InFunction(id, "ScaleH1", false, false);
if ( ! h1 ) return false;
return h1->scale(factor);
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::FillH1(G4int id, G4double value, G4double weight)
{
tools::hbook::h1* h1 = GetH1InFunction(id, "FillH1", true, false);
if ( ! h1 ) return false;
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) {
//G4cout << "Skipping FillH1 for " << id << G4endl;
return false;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "FillH1");
h1->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;
}
//_____________________________________________________________________________
tools::hbook::h1* ExG4HbookH1Manager::GetH1(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return GetH1InFunction(id, "GetH1", warn, onlyIfActive);
}
//_____________________________________________________________________________
G4int ExG4HbookH1Manager::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 = "ExG4HbookH1Manager::GetH1Id";
G4ExceptionDescription description;
description << " " << "histogram " << name << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return -1;
}
return it->second;
}
//_____________________________________________________________________________
G4int ExG4HbookH1Manager::GetH1Nbins(G4int id) const
{
tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1Nbins");
if ( ! h1 ) return 0;
return h1->axis().bins();
}
//_____________________________________________________________________________
G4double ExG4HbookH1Manager::GetH1Xmin(G4int id) const
{
// Returns xmin value with applied unit and histogram function
tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1Xmin");
if ( ! h1 ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH1Xmin");
return info->fXFcn(h1->axis().lower_edge()*info->fXUnit);
}
//_____________________________________________________________________________
G4double ExG4HbookH1Manager::GetH1Xmax(G4int id) const
{
tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1Xmax");
if ( ! h1 ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH1Xmax");
return info->fXFcn(h1->axis().upper_edge()*info->fXUnit);
}
//_____________________________________________________________________________
G4double ExG4HbookH1Manager::GetH1Width(G4int id) const
{
tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1XWidth", true, false);
if ( ! h1 ) return 0;
G4int nbins = h1->axis().bins();
if ( ! nbins ) {
G4ExceptionDescription description;
description << " nbins = 0 (for h1 id = " << id << ").";
G4Exception("ExG4HbookH1Manager::GetH1Width",
"Analysis_W014", JustWarning, description);
return 0;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH1XWidth");
return ( info->fXFcn(h1->axis().upper_edge())
- info->fXFcn(h1->axis().lower_edge()))*info->fXUnit/nbins;
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::SetH1Title(G4int id, const G4String& title)
{
h1_booking* h1Booking = GetH1Booking(id, false);
if ( ! h1Booking ) {
G4ExceptionDescription description;
description << " " << "histogram " << id << " does not exist.";
G4Exception("G4HbookAnalysisManager::SetH1Title()",
"Analysis_W007", JustWarning, description);
return false;
}
h1Booking->fTitle = title;
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::SetH1XAxisTitle(G4int id, const G4String& title)
{
tools::hbook::h1* h1 = GetH1InFunction(id, "SetH1XAxisTitle");
if ( ! h1 ) return false;
h1->add_annotation(tools::hbook::key_axis_x_title(), title);
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::SetH1YAxisTitle(G4int id, const G4String& title)
{
tools::hbook::h1* h1 = GetH1InFunction(id, "SetH1YAxisTitle");
if ( ! h1 ) return false;
h1->add_annotation(tools::hbook::key_axis_y_title(), title);
return true;
}
//_____________________________________________________________________________
G4String ExG4HbookH1Manager::GetH1Title(G4int id) const
{
h1_booking* h1Booking = GetH1Booking(id, false);
if ( ! h1Booking ) {
G4ExceptionDescription description;
description << " " << "histogram " << id << " does not exist.";
G4Exception("G4HbookAnalysisManager::GetH1Title()",
"Analysis_W007", JustWarning, description);
return "";
}
return h1Booking->fTitle;
}
//_____________________________________________________________________________
G4String ExG4HbookH1Manager::GetH1XAxisTitle(G4int id) const
{
tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1XAxisTitle");
if ( ! h1 ) return "";
G4String title;
G4bool result = h1->annotation(tools::hbook::key_axis_x_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get x_axis title for h1 id = " << id << ").";
G4Exception("ExG4HbookH1Manager::GetH1XAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4String ExG4HbookH1Manager::GetH1YAxisTitle(G4int id) const
{
tools::hbook::h1* h1 = GetH1InFunction(id, "GetH1YAxisTitle");
if ( ! h1 ) return "";
G4String title;
G4bool result = h1->annotation(tools::hbook::key_axis_y_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get y_axis title for h1 id = " << id << ").";
G4Exception("ExG4HbookH1Manager::GetH1YAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4bool ExG4HbookH1Manager::SetH1HbookIdOffset(G4int offset)
{
if ( fH1Vector.size() ) {
G4ExceptionDescription description;
description
<< "Cannot set H1HbookIdOffset as some H1 histogramms already exist.";
G4Exception("G4HbookAnalysisManager::SetH1HbookIdOffset()",
"Analysis_W009", JustWarning, description);
return false;
}
if ( fFirstId + offset < 1 ) {
G4ExceptionDescription description;
description << "The first histogram HBOOK id must be >= 1.";
G4Exception("G4HbookAnalysisManager::SetH1HbookIdOffset()",
"Analysis_W009", JustWarning, description);
return false;
}
fH1HbookIdOffset = offset;
return true;
}
#endif
@@ -0,0 +1,721 @@
//
// ********************************************************************
// * 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$
//
/// \file common/analysis/src/ExG4HbookH2Manager.cc
/// \brief Implementation of the ExG4HbookH2Manager class
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#include "ExG4HbookH2Manager.hh"
#include "ExG4HbookFileManager.hh"
#include "G4HnManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4AnalysisUtilities.hh"
#include <iostream>
using namespace G4Analysis;
const G4int ExG4HbookH2Manager::fgkDefaultH2HbookIdOffset = 100;
//_____________________________________________________________________________
ExG4HbookH2Manager::ExG4HbookH2Manager(const G4AnalysisManagerState& state)
: G4VH2Manager(state),
fFileManager(0),
fH2HbookIdOffset(-1),
fH2Vector(),
fH2BookingVector(),
fH2NameIdMap()
{
}
//_____________________________________________________________________________
ExG4HbookH2Manager::~ExG4HbookH2Manager()
{
// Delete h2
Reset();
// Delete h2 booking
std::vector<h2_booking*>::iterator it2;
for ( it2 = fH2BookingVector.begin(); it2 != fH2BookingVector.end(); it2++ ) {
delete *it2;
}
}
//
// private methods
//
//_____________________________________________________________________________
void ExG4HbookH2Manager::SetH2HbookIdOffset()
{
// Set fH2HbookIdOffset if needed
if ( fH2HbookIdOffset == -1 ) {
if ( fFirstId > 0 )
fH2HbookIdOffset = 0;
else
fH2HbookIdOffset = 1;
if ( fH2HbookIdOffset > 0 ) {
G4ExceptionDescription description;
description << "H2 will be defined in HBOOK with ID = G4_firstHistoId + 1";
G4Exception("ExG4HbookH2Manager::SetH1HbookIdOffset",
"Analysis_W011", JustWarning, description);
}
}
}
//_____________________________________________________________________________
void ExG4HbookH2Manager::CreateH2sFromBooking()
{
// Create h2 from h2_booking.
// Do nothing if any h2 histogram already exists
// or no h2 histograms are booked
if ( fH2Vector.size() || ( fH2BookingVector.size() == 0 ) ) return;
// Go to histograms directory
if ( fFileManager->GetHistoDirectoryName() != "" ) {
G4String histoPath = "//PAWC/LUN1/";
histoPath.append(fFileManager->GetHistoDirectoryName().data());
tools::hbook::CHCDIR(histoPath.data()," ");
}
// Create histograms
G4int index = 0;
std::vector<h2_booking*>::const_iterator it;
for ( it = fH2BookingVector.begin(); it != fH2BookingVector.end(); ++it) {
// Get information
G4int id = index + fFirstId;
G4HnInformation* info = fHnManager->GetHnInformation(id, "CreateH2FromBooking");
// Hbook index
G4int hbookIndex = fH2HbookIdOffset + index + fFirstId;
++index;
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()->Message("create from booking", "h2", info->fName);
#endif
// Create h2
tools::hbook::h2* h2
= new tools::hbook::h2(hbookIndex, (*it)->fTitle,
(*it)->fNxbins, (*it)->fXmin, (*it)->fXmax,
(*it)->fNybins, (*it)->fYmin, (*it)->fYmax);
fH2Vector.push_back(h2);
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() ) {
G4ExceptionDescription description;
description << " name : " << info->fName << " hbook index : " << hbookIndex;
fState.GetVerboseL3()->Message("create from booking", "h2", description);
}
#endif
}
if ( fFileManager->GetHistoDirectoryName() != "" ) {
// Return to //PAWC/LUN1 :
tools::hbook::CHCDIR("//PAWC/LUN1"," ");
}
}
//_____________________________________________________________________________
void ExG4HbookH2Manager::Reset()
{
// Reset histograms and ntuple
// Delete histograms
std::vector<tools::hbook::h2*>::iterator it2;
for (it2 = fH2Vector.begin(); it2 != fH2Vector.end(); it2++ ) {
delete *it2;
}
// Clear vectors
fH2Vector.clear();
}
//_____________________________________________________________________________
h2_booking* ExG4HbookH2Manager::GetH2Booking(G4int id, G4bool warn) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fH2BookingVector.size()) ) {
if ( warn) {
G4ExceptionDescription description;
description << " " << "histo " << id << " does not exist.";
G4Exception("G4HbookAnalysisManager::GetH2Booking()",
"Analysis_W007", JustWarning, description);
}
return 0;
}
return fH2BookingVector[index];
}
//
// protected methods
//
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::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;
}
//_____________________________________________________________________________
tools::hbook::h2* ExG4HbookH2Manager::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 = "ExG4HbookH2Manager::";
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];
}
//
// public methods
//
//_____________________________________________________________________________
G4int ExG4HbookH2Manager::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)
{
// HBook does not support user defined binning for H2
if ( xbinSchemeName != "linear" || ybinSchemeName != "linear" ) {
G4ExceptionDescription description;
description
<< " "
<< "Logarithimc binning is not supported for H2.";
G4Exception("ExG4HbookH2Manager::CreateH2",
"Analysis_F015", FatalException, description);
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "H2", name);
#endif
// Create h2 booking & information
G4int index = fH2BookingVector.size();
G4double xunit = GetUnitValue(xunitName);
G4double yunit = GetUnitValue(yunitName);
G4Fcn xfcn = GetFunction(xfcnName);
G4Fcn yfcn = GetFunction(yfcnName);
G4BinScheme xbinScheme = GetBinScheme(xbinSchemeName);
G4BinScheme ybinScheme = GetBinScheme(ybinSchemeName);
G4String newTitle(title);
UpdateTitle(newTitle, xunitName, xfcnName);
UpdateTitle(newTitle, yunitName, yfcnName);
h2_booking* h2Booking = new h2_booking(nxbins, xfcn(xmin), xfcn(xmax),
nybins, yfcn(ymin), yfcn(ymax));
// h2_booking object is deleted in destructor
h2Booking->fTitle = newTitle;
fH2BookingVector.push_back(h2Booking);
fHnManager
->AddH2Information(name, xunitName, yunitName, xfcnName, yfcnName,
xunit, yunit, xfcn, yfcn, xbinScheme, ybinScheme);
// Set fH1HbookIdOffset if needed
SetH2HbookIdOffset();
// Hbook index
G4int hbookIndex = fH2HbookIdOffset + index + fFirstId;
// Create h2 if the file is open
if ( fFileManager->IsFile() ) {
// Go to histograms directory
G4String histoPath = "//PAWC/LUN1/";
if ( fFileManager->GetHistoDirectoryName() != "" ) {
histoPath.append(fFileManager->GetHistoDirectoryName().data());
}
tools::hbook::CHCDIR(histoPath.data()," ");
// Create histogram
tools::hbook::h2* h2
= new tools::hbook::h2(hbookIndex, title,
nxbins, xfcn(xmin), xfcn(xmax),
nybins, yfcn(ymin), yfcn(ymax));
// h2 objects are deleted when closing a file.
fH2Vector.push_back(h2);
// Return to //PAWC/LUN1
if ( fFileManager->GetHistoDirectoryName() != "" ) {
tools::hbook::CHCDIR("//PAWC/LUN1"," ");
}
}
fLockFirstId = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << " name : " << name << " hbook index : " << hbookIndex;
fState.GetVerboseL2()->Message("create", "H2", description);
}
#endif
fH2NameIdMap[name] = index + fFirstId;
return index + fFirstId;
}
//_____________________________________________________________________________
G4int ExG4HbookH2Manager::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*/)
{
// HBook does not support user defined binning for H2
G4ExceptionDescription description;
description
<< " "
<< "User defined binning is not supported for H2.";
G4Exception("ExG4HbookH2Manager::CreateH2",
"Analysis_F015", FatalException, description);
return 0;
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::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)
{
// HBook does not support user defined binning for H2
if ( xbinScheme != "linear" || ybinScheme != "linear" ) {
G4ExceptionDescription description;
description
<< " "
<< "Logarithimc binning is not supported for H2.";
G4Exception("ExG4HbookH2Manager::CreateH2",
"Analysis_F015", FatalException, description);
}
h2_booking* h2Booking = GetH2Booking(id, false);
if ( ! h2Booking ) {
G4ExceptionDescription description;
description << " " << "histogram " << id << " does not exist.";
G4Exception("G4HbookAnalysisManager::SetH2()",
"Analysis_W007", JustWarning, description);
return false;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "SetH2");
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("configure", "H2", info->fName);
#endif
// Keep new parameters in booking & information
G4double xunit = GetUnitValue(xunitName);
G4double yunit = GetUnitValue(yunitName);
G4Fcn xfcn = GetFunction(xfcnName);
G4Fcn yfcn = GetFunction(yfcnName);
h2Booking->fNxbins = nxbins;
h2Booking->fXmin = xfcn(xmin);
h2Booking->fXmax = xfcn(xmax);
h2Booking->fNybins = nybins;
h2Booking->fYmin = yfcn(ymin);
h2Booking->fYmax = yfcn(ymax);
info->fXUnitName = xunitName;
info->fYUnitName = yunitName;
info->fXFcnName = xfcnName;
info->fYFcnName = yfcnName;
info->fXUnit = xunit;
info->fYUnit = yunit;
info->fXFcn = xfcn;
info->fYFcn = yfcn;
fHnManager->SetActivation(id, true);
G4String newTitle(h2Booking->fTitle);
UpdateTitle(newTitle, xunitName, xfcnName);
UpdateTitle(newTitle, yunitName, yfcnName);
h2Booking->fTitle = newTitle;
// Re-configure histogram if it was already defined
if ( fH2Vector.size() ) {
tools::hbook::h2* h2 = GetH2(id);
h2->configure(nxbins, xfcn(xmin), xfcn(xmax),
nybins, yfcn(ymin), yfcn(ymax));
}
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::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*/)
{
// HBook does not support user defined binning for H2
G4ExceptionDescription description;
description
<< " "
<< "User defined binning is not supported for H2.";
G4Exception("ExG4HbookH2Manager::CreateH2",
"Analysis_F015", FatalException, description);
return false;
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::ScaleH2(G4int id, G4double factor)
{
tools::hbook::h2* h2 = GetH2InFunction(id, "ScaleH2", false, false);
if ( ! h2 ) return false;
return h2->scale(factor);
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::FillH2(G4int id,
G4double xvalue, G4double yvalue,
G4double weight)
{
tools::hbook::h2* h2 = GetH2InFunction(id, "FillH2", true, false);
if ( ! h2 ) return false;
if ( fState.GetIsActivation() && ( ! fHnManager->GetActivation(id) ) ) return false;
G4HnInformation* info = fHnManager->GetHnInformation(id, "FillH2");
h2->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;
}
//_____________________________________________________________________________
tools::hbook::h2* ExG4HbookH2Manager::GetH2(G4int id, G4bool warn,
G4bool onlyIfActive) const
{
return GetH2InFunction(id, "GetH2", warn, onlyIfActive);
}
//_____________________________________________________________________________
G4int ExG4HbookH2Manager::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 = "ExG4HbookH2Manager::GetH2Id";
G4ExceptionDescription description;
description << " " << "histogram " << name << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return -1;
}
return it->second;
}
//_____________________________________________________________________________
G4int ExG4HbookH2Manager::GetH2Nxbins(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2NXbins");
if ( ! h2 ) return 0;
return h2->axis_x().bins();
}
//_____________________________________________________________________________
G4double ExG4HbookH2Manager::GetH2Xmin(G4int id) const
{
// Returns xmin value with applied unit and histogram function
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2Xmin");
if ( ! h2 ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Xmin");
return info->fXFcn(h2->axis_x().lower_edge()*info->fXUnit);
}
//_____________________________________________________________________________
G4double ExG4HbookH2Manager::GetH2Xmax(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2Xmax");
if ( ! h2 ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Xmax");
return info->fXFcn(h2->axis_x().upper_edge()*info->fXUnit);
}
//_____________________________________________________________________________
G4double ExG4HbookH2Manager::GetH2XWidth(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2XWidth", true, false);
if ( ! h2 ) return 0;
G4int nbins = h2->axis_x().bins();
if ( ! nbins ) {
G4ExceptionDescription description;
description << " nbins = 0 (for h1 id = " << id << ").";
G4Exception("ExG4HbookH2Manager::GetH2Width",
"Analysis_W014", JustWarning, description);
return 0;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2XWidth");
return ( info->fXFcn(h2->axis_x().upper_edge())
- info->fXFcn(h2->axis_x().lower_edge()))*info->fXUnit/nbins;
}
//_____________________________________________________________________________
G4int ExG4HbookH2Manager::GetH2Nybins(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2NYbins");
if ( ! h2 ) return 0;
return h2->axis_y().bins();
}
//_____________________________________________________________________________
G4double ExG4HbookH2Manager::GetH2Ymin(G4int id) const
{
// Returns xmin value with applied unit and histogram function
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2Ymin");
if ( ! h2 ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Ymin");
return info->fYFcn(h2->axis_y().lower_edge()*info->fYUnit);
}
//_____________________________________________________________________________
G4double ExG4HbookH2Manager::GetH2Ymax(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2Ymax");
if ( ! h2 ) return 0;
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2Ymax");
return info->fYFcn(h2->axis_y().upper_edge()*info->fYUnit);
}
//_____________________________________________________________________________
G4double ExG4HbookH2Manager::GetH2YWidth(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2YWidth", true, false);
if ( ! h2 ) return 0;
G4int nbins = h2->axis_y().bins();
if ( ! nbins ) {
G4ExceptionDescription description;
description << " nbins = 0 (for h1 id = " << id << ").";
G4Exception("ExG4HbookH2Manager::GetH2Width",
"Analysis_W014", JustWarning, description);
return 0;
}
G4HnInformation* info = fHnManager->GetHnInformation(id, "GetH2YWidth");
return ( info->fYFcn(h2->axis_y().upper_edge())
- info->fYFcn(h2->axis_y().lower_edge()))*info->fYUnit/nbins;
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::SetH2Title(G4int id, const G4String& title)
{
h2_booking* h2Booking = GetH2Booking(id, false);
if ( ! h2Booking ) {
G4ExceptionDescription description;
description << " " << "histogram " << id << " does not exist.";
G4Exception("G4HbookAnalysisManager::SetH2Title()",
"Analysis_W007", JustWarning, description);
return false;
}
h2Booking->fTitle = title;
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::SetH2XAxisTitle(G4int id, const G4String& title)
{
tools::hbook::h2* h2 = GetH2InFunction(id, "SetH2XAxisTitle");
if ( ! h2 ) return false;
h2->add_annotation(tools::hbook::key_axis_x_title(), title);
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::SetH2YAxisTitle(G4int id, const G4String& title)
{
tools::hbook::h2* h2 = GetH2InFunction(id, "SetH2YAxisTitle");
if ( ! h2 ) return false;
h2->add_annotation(tools::hbook::key_axis_x_title(), title);
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::SetH2ZAxisTitle(G4int id, const G4String& title)
{
tools::hbook::h2* h2 = GetH2InFunction(id, "SetH2ZAxisTitle");
if ( ! h2 ) return false;
h2->add_annotation(tools::hbook::key_axis_z_title(), title);
return true;
}
//_____________________________________________________________________________
G4String ExG4HbookH2Manager::GetH2Title(G4int id) const
{
h2_booking* h2Booking = GetH2Booking(id, false);
if ( ! h2Booking ) {
G4ExceptionDescription description;
description << " " << "histogram " << id << " does not exist.";
G4Exception("G4HbookAnalysisManager::GetH2Title()",
"Analysis_W007", JustWarning, description);
return "";
}
return h2Booking->fTitle;
}
//_____________________________________________________________________________
G4String ExG4HbookH2Manager::GetH2XAxisTitle(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2XAxisTitle");
if ( ! h2 ) return "";
G4String title;
G4bool result = h2->annotation(tools::hbook::key_axis_x_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get x_axis title for h2 id = " << id << ").";
G4Exception("ExG4HbookH2Manager::GetH2XAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4String ExG4HbookH2Manager::GetH2YAxisTitle(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2YAxisTitle");
if ( ! h2 ) return "";
G4String title;
G4bool result = h2->annotation(tools::hbook::key_axis_y_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get y_axis title for h2 id = " << id << ").";
G4Exception("ExG4HbookH2Manager::GetH2YAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4String ExG4HbookH2Manager::GetH2ZAxisTitle(G4int id) const
{
tools::hbook::h2* h2 = GetH2InFunction(id, "GetH2ZAxisTitle");
if ( ! h2 ) return "";
G4String title;
G4bool result = h2->annotation(tools::hbook::key_axis_z_title(), title);
if ( ! result ) {
G4ExceptionDescription description;
description << " Failed to get z_axis title for h2 id = " << id << ").";
G4Exception("ExG4HbookH2Manager::GetH2ZAxisTitle",
"Analysis_W014", JustWarning, description);
return "";
}
return title;
}
//_____________________________________________________________________________
G4bool ExG4HbookH2Manager::SetH2HbookIdOffset(G4int offset)
{
if ( fH2Vector.size() ) {
G4ExceptionDescription description;
description
<< "Cannot set H2HbookIdOffset as some H2 histogramms already exist.";
G4Exception("G4HbookAnalysisManager::SetH2HbookIdOffset()",
"Analysis_W009", JustWarning, description);
return false;
}
if ( fFirstId + offset < 1 ) {
G4ExceptionDescription description;
description << "The first histogram HBOOK id must be >= 1.";
G4Exception("G4HbookAnalysisManager::SetH1HbookIdOffset()",
"Analysis_W009", JustWarning, description);
return false;
}
fH2HbookIdOffset = offset;
return true;
}
#endif
@@ -0,0 +1,698 @@
//
// ********************************************************************
// * 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$
//
/// \file common/analysis/src/ExG4HbookNtupleManager.cc
/// \brief Implementation of the ExG4HbookNtupleManager class
// Author: Ivana Hrivnacova, 15/06/2011 (ivana@ipno.in2p3.fr)
#ifdef G4_USE_HBOOK
#include "ExG4HbookNtupleManager.hh"
#include "ExG4HbookFileManager.hh"
#include "G4AnalysisManagerState.hh"
#include "G4UnitsTable.hh"
#include <iostream>
//_____________________________________________________________________________
ExG4HbookNtupleManager::ExG4HbookNtupleManager(const G4AnalysisManagerState& state)
: G4VNtupleManager(state),
fNtupleHbookIdOffset(-1),
fNtupleVector()
{
}
//_____________________________________________________________________________
ExG4HbookNtupleManager::~ExG4HbookNtupleManager()
{
// Reset();
std::vector<ExG4HbookNtupleDescription*>::iterator it;
for (it = fNtupleVector.begin(); it != fNtupleVector.end(); it++ ) {
delete *it;
}
}
//
// private methods
//
//_____________________________________________________________________________
void ExG4HbookNtupleManager::SetNtupleHbookIdOffset()
{
// Set fH1HbookIdOffset if needed
if ( fNtupleHbookIdOffset == -1 ) {
if ( fFirstId > 0 )
fNtupleHbookIdOffset = 0;
else
fNtupleHbookIdOffset = 1;
if ( fNtupleHbookIdOffset > 0 ) {
G4ExceptionDescription description;
description << "Ntuple will be defined in HBOOK with ID = G4_firstNtupleId + 1";
G4Exception("ExG4HbookNtupleManager::SetNtupleHbookIdOffset()",
"Analysis_W011", JustWarning, description);
}
}
}
//_____________________________________________________________________________
void ExG4HbookNtupleManager::CreateNtuplesFromBooking()
{
// Create ntuple from ntuple_booking.
if ( ! fNtupleVector.size() ) return;
// Set fNtupleHbookIdOffset if needed
SetNtupleHbookIdOffset();
G4int index = 0;
std::vector<ExG4HbookNtupleDescription*>::iterator itn;
for (itn = fNtupleVector.begin(); itn != fNtupleVector.end(); itn++ ) {
tools::ntuple_booking* ntupleBooking = (*itn)->fNtupleBooking;
if ( ! ntupleBooking ) continue;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("create from booking", "ntuple", ntupleBooking->m_name);
#endif
// Create an "ntuple" directory both in memory and in the file
fFileManager->CreateNtupleDirectory();
G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
++index;
// We should be under //PAWC/LUN1/ntuple
(*itn)->fNtuple
= new tools::hbook::wntuple(hbookIndex, G4cout, *ntupleBooking);
if ( ntupleBooking->m_columns.size() ) {
// store ntuple columns in local maps
const std::vector<tools::ntuple_booking::col_t>& columns
= ntupleBooking->m_columns;
std::vector<tools::ntuple_booking::col_t>::const_iterator it;
G4int counter = 0;
for ( it = columns.begin(); it!=columns.end(); ++it) {
if ( (*it).second == tools::_cid(int(0) ) ) {
(*itn)->fNtupleIColumnMap[counter++]
= (*itn)->fNtuple->find_column<int>((*it).first);
}
else if( (*it).second == tools::_cid(float(0) ) ) {
(*itn)->fNtupleFColumnMap[counter++]
= (*itn)->fNtuple->find_column<float>((*it).first);
}
else if((*it).second== tools::_cid(double(0))) {
(*itn)->fNtupleDColumnMap[counter++]
= (*itn)->fNtuple->find_column<double>((*it).first);
}
else {
G4ExceptionDescription description;
description << " "
<< "Unsupported column type " << (*it).first;
G4Exception("G4HbookAnalysisManager::CreateNtupleFromBooking()",
"Analysis_W004", JustWarning, description);
}
}
}
FinishNtuple();
#ifdef G4VERBOSE
if ( fState.GetVerboseL3() )
fState.GetVerboseL3()
->Message("create from booking", "ntuple", ntupleBooking->m_name);
#endif
}
}
//_____________________________________________________________________________
tools::hbook::wntuple::column<int>*
ExG4HbookNtupleManager::GetNtupleIColumn(G4int ntupleId, G4int columnId) const
{
ExG4HbookNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleIColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::hbook::wntuple::column<int>* >& ntupleIColumnMap
= ntupleDecription->fNtupleIColumnMap;
std::map<G4int, tools::hbook::wntuple::column<int>* >::const_iterator it
= ntupleIColumnMap.find(columnId);
if ( it == ntupleIColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4HbookAnalysisManager::GetNtupleIColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
tools::hbook::wntuple::column<float>*
ExG4HbookNtupleManager::GetNtupleFColumn(G4int ntupleId, G4int columnId) const
{
ExG4HbookNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleFColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::hbook::wntuple::column<float>* >& ntupleFColumnMap
= ntupleDecription->fNtupleFColumnMap;
std::map<G4int, tools::hbook::wntuple::column<float>* >::const_iterator it
= ntupleFColumnMap.find(columnId);
if ( it == ntupleFColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4HbookAnalysisManager::GetNtupleFColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
tools::hbook::wntuple::column<double>*
ExG4HbookNtupleManager::GetNtupleDColumn(G4int ntupleId, G4int columnId) const
{
ExG4HbookNtupleDescription* ntupleDecription
= GetNtupleInFunction(ntupleId, "GetNtupleDColumn");
if ( ! ntupleDecription ) return 0;
std::map<G4int, tools::hbook::wntuple::column<double>* >& ntupleDColumnMap
= ntupleDecription->fNtupleDColumnMap;
std::map<G4int, tools::hbook::wntuple::column<double>* >::const_iterator it
= ntupleDColumnMap.find(columnId);
if ( it == ntupleDColumnMap.end() ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4HbookAnalysisManager::GetNtupleDColumn()",
"Analysis_W009", JustWarning, description);
return 0;
}
return it->second;
}
//_____________________________________________________________________________
void ExG4HbookNtupleManager::Reset()
{
// Reset ntuple
std::vector<ExG4HbookNtupleDescription*>::iterator it3;
for (it3 = fNtupleVector.begin(); it3 != fNtupleVector.end(); it3++ ) {
delete (*it3)->fNtuple;
(*it3)->fNtuple = 0;
}
}
//
// protected methods
//
//_____________________________________________________________________________
ExG4HbookNtupleDescription* ExG4HbookNtupleManager::GetNtupleInFunction(
G4int id,
G4String functionName, G4bool warn,
G4bool /*onlyIfActive*/) const
{
G4int index = id - fFirstId;
if ( index < 0 || index >= G4int(fNtupleVector.size()) ) {
if ( warn) {
G4String inFunction = "G4HbookAnalysisManager::";
inFunction += functionName;
G4ExceptionDescription description;
description << " " << "ntuple " << id << " does not exist.";
G4Exception(inFunction, "Analysis_W007", JustWarning, description);
}
return 0;
}
return fNtupleVector[index];
}
//
// public methods
//
//_____________________________________________________________________________
G4int ExG4HbookNtupleManager::CreateNtuple(const G4String& name,
const G4String& title)
{
// Create an "ntuple" directory both in memory and in the file
if ( fFileManager->IsFile() )
fFileManager->CreateNtupleDirectory();
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()->Message("create", "ntuple", name);
#endif
// Create ntuple description
G4int index = fNtupleVector.size();
ExG4HbookNtupleDescription* ntupleDescription
= new ExG4HbookNtupleDescription();
fNtupleVector.push_back(ntupleDescription);
// Create ntuple booking
ntupleDescription->fNtupleBooking = new tools::ntuple_booking();
ntupleDescription->fNtupleBooking->m_name = name;
ntupleDescription->fNtupleBooking->m_title = title;
// ntuple booking object is deleted in destructor
// Set fNtupleHbookIdOffset if needed
SetNtupleHbookIdOffset();
// Create ntuple if the file is open
// We should be under //PAWC/LUN1/ntuple
if ( fFileManager->IsFile() ) {
G4int hbookIndex = fNtupleHbookIdOffset + index + fFirstId;
ntupleDescription->fNtuple
= new tools::hbook::wntuple(hbookIndex, name);
// ntuple object is deleted when closing a file
}
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << index + fFirstId;
fState.GetVerboseL2()->Message("create", "ntuple", description);
}
#endif
return index + fFirstId;
}
//_____________________________________________________________________________
G4int ExG4HbookNtupleManager::CreateNtupleIColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleIColumn(ntupleId, name);
}
//_____________________________________________________________________________
G4int ExG4HbookNtupleManager::CreateNtupleFColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleFColumn(ntupleId, name);
}
//_____________________________________________________________________________
G4int ExG4HbookNtupleManager::CreateNtupleDColumn(const G4String& name)
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
return CreateNtupleDColumn(ntupleId, name);
}
//_____________________________________________________________________________
void ExG4HbookNtupleManager::FinishNtuple()
{
G4int ntupleId = fNtupleVector.size() + fFirstId - 1;
FinishNtuple(ntupleId);
}
//_____________________________________________________________________________
G4int ExG4HbookNtupleManager::CreateNtupleIColumn(G4int ntupleId,
const G4String& name)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("create", "ntuple I column", description);
}
#endif
ExG4HbookNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleIColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4HbookAnalysisManager::CreateNtupleIColumn()",
"Analysis_W005", JustWarning, description);
return -1;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
ntupleBooking->add_column<int>(name);
// Create column if ntuple already exists
if ( ntupleDescription->fNtuple ) {
tools::hbook::wntuple::column<int>* column
= ntupleDescription->fNtuple->create_column<int>(name);
ntupleDescription->fNtupleIColumnMap[index] = column;
}
fLockFirstNtupleColumnId = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("create", "ntuple I column", description);
}
#endif
return index + fFirstNtupleColumnId;
}
//_____________________________________________________________________________
G4int ExG4HbookNtupleManager::CreateNtupleFColumn(G4int ntupleId,
const G4String& name)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("create", "ntuple F column", description);
}
#endif
ExG4HbookNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleFColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4HbookAnalysisManager::CreateNtupleFColumn()",
"Analysis_W005", JustWarning, description);
return -1;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
ntupleBooking->add_column<float>(name);
// Create column if ntuple already exists
if ( ntupleDescription->fNtuple ) {
tools::hbook::wntuple::column<float>* column
= ntupleDescription->fNtuple->create_column<float>(name);
ntupleDescription->fNtupleFColumnMap[index] = column;
}
fLockFirstNtupleColumnId = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("create", "ntuple F column", description);
}
#endif
return index + fFirstNtupleColumnId;
}
//_____________________________________________________________________________
G4int ExG4HbookNtupleManager::CreateNtupleDColumn(G4int ntupleId,
const G4String& name)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("create", "ntuple D column", description);
}
#endif
ExG4HbookNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
tools::ntuple_booking* ntupleBooking
= ntupleDescription->fNtupleBooking;
if ( ! ntupleBooking ) {
G4ExceptionDescription description;
description << " "
<< "Ntuple " << ntupleId << " has to be created first. ";
G4Exception("G4HbookAnalysisManager::CreateNtupleDColumn()",
"Analysis_W005", JustWarning, description);
return -1;
}
// Save column info in booking
G4int index = ntupleBooking->m_columns.size();
ntupleBooking->add_column<double>(name);
// Create column if ntuple already exists
if ( ntupleDescription->fNtuple ) {
tools::hbook::wntuple::column<double>* column
= ntupleDescription->fNtuple->create_column<double>(name);
ntupleDescription->fNtupleDColumnMap[index] = column;
}
fLockFirstNtupleColumnId = true;
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() ) {
G4ExceptionDescription description;
description << name << " ntupleId " << ntupleId;
fState.GetVerboseL2()->Message("create", "ntuple D column", description);
}
#endif
return index + fFirstNtupleColumnId;
}
//_____________________________________________________________________________
void ExG4HbookNtupleManager::FinishNtuple(G4int ntupleId)
{
ExG4HbookNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "CreateNtupleDColumn");
tools::hbook::wntuple* ntuple = ntupleDescription->fNtuple;
if ( ! ntuple ) return;
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() )
fState.GetVerboseL4()
->Message("finish", "ntuple", ntupleDescription->fNtupleBooking->m_name);
#endif
// Return to //PAWC/LUN1 :
tools::hbook::CHCDIR("//PAWC/LUN1"," ");
//fNtuple->add_row_beg();
#ifdef G4VERBOSE
if ( fState.GetVerboseL2() )
fState.GetVerboseL2()
->Message("finish", "ntuple", ntupleDescription->fNtupleBooking->m_name);
#endif
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::FillNtupleIColumn(G4int columnId, G4int value)
{
return FillNtupleIColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::FillNtupleFColumn(G4int columnId, G4float value)
{
return FillNtupleFColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::FillNtupleDColumn(G4int columnId, G4double value)
{
return FillNtupleDColumn(fFirstId, columnId, value);
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::AddNtupleRow()
{
return AddNtupleRow(fFirstId);
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::FillNtupleIColumn(
G4int ntupleId, G4int columnId,
G4int value)
{
tools::hbook::wntuple::column<int>* column
= GetNtupleIColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4HbookAnalysisManager::FillNtupleIColumn()",
"Analysis_W009", JustWarning, description);
return false;
}
column->fill(value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId
<< " columnId " << columnId << " value " << value;
fState.GetVerboseL4()->Message("fill", "ntuple I column", description);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::FillNtupleFColumn(
G4int ntupleId, G4int columnId,
G4float value)
{
tools::hbook::wntuple::column<float>* column
= GetNtupleFColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4HbookAnalysisManager::FillNtupleFColumn()",
"Analysis_W009", JustWarning, description);
return false;
}
column->fill(value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId
<< " columnId " << columnId << " value " << value;
fState.GetVerboseL4()->Message("fill", "ntuple F column", description);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::FillNtupleDColumn(
G4int ntupleId, G4int columnId,
G4double value)
{
tools::hbook::wntuple::column<double>* column
= GetNtupleDColumn(ntupleId, columnId);
if ( ! column ) {
G4ExceptionDescription description;
description << " " << "ntupleId " << ntupleId
<< "column " << columnId << " does not exist.";
G4Exception("G4HbookAnalysisManager::FillNtupleDColumn()",
"Analysis_W009", JustWarning, description);
return false;
}
column->fill(value);
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId
<< " columnId " << columnId << " value " << value;
fState.GetVerboseL4()->Message("fill", "ntuple D column", description);
}
#endif
return true;
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::AddNtupleRow(G4int ntupleId)
{
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("add", "ntuple row", description);
}
#endif
ExG4HbookNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "AddNtupleRow");
if ( ! ntupleDescription || ! ntupleDescription->fNtuple ) {
G4ExceptionDescription description;
description << " " << " ntupleId " << ntupleId
<< " does not exist. ";
G4Exception("G4HbookAnalysisManager::AddNtupleRow()",
"Analysis_W008", JustWarning, description);
return false;
}
ntupleDescription->fNtuple->add_row();
#ifdef G4VERBOSE
if ( fState.GetVerboseL4() ) {
G4ExceptionDescription description;
description << " ntupleId " << ntupleId;
fState.GetVerboseL4()->Message("add", "ntuple row", description, true);
}
#endif
return true;
}
//_____________________________________________________________________________
tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple() const
{
return GetNtuple(fFirstId);
}
//_____________________________________________________________________________
tools::hbook::wntuple* ExG4HbookNtupleManager::GetNtuple(G4int ntupleId) const
{
ExG4HbookNtupleDescription* ntupleDescription
= GetNtupleInFunction(ntupleId, "GetNtuple");
return ntupleDescription->fNtuple;
}
//_____________________________________________________________________________
G4bool ExG4HbookNtupleManager::SetNtupleHbookIdOffset(G4int offset)
{
if ( fNtupleVector.size() ) {
G4ExceptionDescription description;
description
<< "Cannot set NtupleHbookIdOffset as some ntuples already exist.";
G4Exception("G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
"Analysis_W009", JustWarning, description);
return false;
}
if ( fFirstId + offset < 1 ) {
G4ExceptionDescription description;
description << "The first ntuple HBOOK id must be >= 1.";
G4Exception("G4HbookAnalysisManager::SetNtupleHbookIdOffset()",
"Analysis_W009", JustWarning, description);
return false;
}
fNtupleHbookIdOffset = offset;
return true;
}
#endif