19#include "BDSOutputROOTEventHistograms.hh"
24#include "BDSBH4DBase.hh"
28#include "BDSBH4DTypeDefs.hh"
30#include "BDSException.hh"
35BDSOutputROOTEventHistograms::BDSOutputROOTEventHistograms()
37 TH1D::AddDirectory(kFALSE);
38 TH2D::AddDirectory(kFALSE);
39 TH3D::AddDirectory(kFALSE);
48BDSOutputROOTEventHistograms::BDSOutputROOTEventHistograms(std::vector<TH1D*>& histograms1DIn,
49 std::vector<TH2D*>& histograms2DIn,
50 std::vector<TH3D*>& histograms3DIn,
51 std::vector<BDSBH4DBase*>& histograms4DIn):
52 histograms1D(histograms1DIn),
53 histograms2D(histograms2DIn),
54 histograms3D(histograms3DIn),
55 histograms4D(histograms4DIn)
58BDSOutputROOTEventHistograms::~BDSOutputROOTEventHistograms()
66 histograms1D = rhs->histograms1D;
67 histograms2D = rhs->histograms2D;
68 histograms3D = rhs->histograms3D;
69 histograms4D = rhs->histograms4D;
78 for (
auto h : rhs->histograms1D)
79 {histograms1D.push_back(
static_cast<TH1D*
>(h->Clone()));}
80 for (
auto h : rhs->histograms2D)
81 {histograms2D.push_back(
static_cast<TH2D*
>(h->Clone()));}
82 for (
auto h : rhs->histograms3D)
83 {histograms3D.push_back(
static_cast<TH3D*
>(h->Clone()));}
85 for (
auto h : rhs->histograms4D)
86 {histograms4D.push_back(
static_cast<BDSBH4DBase*
>(h->Clone(
"")));}
92 int nbins,
double xmin,
double xmax)
94 histograms1D.push_back(
new TH1D(name.c_str(),title.c_str(), nbins, xmin, xmax));
95 return (
int)histograms1D.size() - 1;
100G4int BDSOutputROOTEventHistograms::Create1DHistogram(G4String name, G4String title,
101 G4int nbins, G4double xmin, G4double xmax)
103 histograms1D.push_back(
new TH1D(name,title, nbins, xmin, xmax));
104 return (G4int)histograms1D.size() - 1;
107G4int BDSOutputROOTEventHistograms::Create1DHistogram(G4String name,
109 std::vector<double>& edges)
111 histograms1D.push_back(
new TH1D(name, title, (Int_t)edges.size()-1, edges.data()));
112 return (G4int)histograms1D.size() - 1;
115G4int BDSOutputROOTEventHistograms::Create2DHistogram(G4String name, G4String title,
116 G4int nxbins, G4double xmin, G4double xmax,
117 G4int nybins, G4double ymin, G4double ymax)
119 histograms2D.push_back(
new TH2D(name,title, nxbins, xmin, xmax, nybins, ymin, ymax));
120 return (G4int)histograms2D.size() - 1;
123G4int BDSOutputROOTEventHistograms::Create2DHistogram(G4String name, G4String title,
124 std::vector<double>& xedges,
125 std::vector<double>& yedges)
127 histograms2D.push_back(
new TH2D(name.data(),title.data(),
128 (Int_t)xedges.size()-1, xedges.data(),
129 (Int_t)yedges.size()-1, yedges.data()));
130 return (G4int)histograms2D.size() - 1;
133G4int BDSOutputROOTEventHistograms::Create3DHistogram(G4String name, G4String title,
134 G4int nxbins, G4double xmin, G4double xmax,
135 G4int nybins, G4double ymin, G4double ymax,
136 G4int nzbins, G4double zmin, G4double zmax)
138 histograms3D.push_back(
new TH3D(name, title,
141 nzbins, zmin, zmax));
142 return (G4int)histograms3D.size() - 1;
145G4int BDSOutputROOTEventHistograms::Create3DHistogram(G4String name, G4String title,
146 std::vector<double>& xedges,
147 std::vector<double>& yedges,
148 std::vector<double>& zedges)
150 histograms3D.push_back(
new TH3D(name.data(),title.data(),
151 (Int_t)xedges.size()-1, xedges.data(),
152 (Int_t)yedges.size()-1, yedges.data(),
153 (Int_t)zedges.size()-1, zedges.data()));
154 return (G4int)histograms3D.size() - 1;
158G4int BDSOutputROOTEventHistograms::Create4DHistogram(
const G4String& name,
159 const G4String& title,
160 const G4String& eScale,
161 const std::vector<double>& eBinsEdges,
162 unsigned int nxbins, G4double xmin, G4double xmax,
163 unsigned int nybins, G4double ymin, G4double ymax,
164 unsigned int nzbins, G4double zmin, G4double zmax,
165 unsigned int nebins, G4double emin, G4double emax)
167 std::string nameC = (std::string)name;
168 std::string titleC = (std::string)title;
169 std::string eScaleC = (std::string)eScale;
171 if(eScale ==
"linear")
177 nebins, emin, emax));
179 else if(eScale ==
"log")
185 nebins, emin, emax));
187 else if(eScale ==
"user")
192 nzbins, zmin, zmax));
195 return (G4int)histograms4D.size() - 1;
198G4int BDSOutputROOTEventHistograms::Create4DHistogram(
const G4String&,
const G4String&,
const G4String&,
199 const std::vector<double>&,
200 unsigned int, G4double, G4double,
201 unsigned int, G4double, G4double,
202 unsigned int, G4double, G4double,
203 unsigned int, G4double, G4double)
205 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
209void BDSOutputROOTEventHistograms::Fill1DHistogram(G4int histoId,
213 histograms1D[histoId]->Fill(value,weight);
216void BDSOutputROOTEventHistograms::Fill2DHistogram(G4int histoId,
221 histograms2D[histoId]->Fill(xValue,yValue,weight);
224void BDSOutputROOTEventHistograms::Fill3DHistogram(G4int histoId,
230 histograms3D[histoId]->Fill(xValue,yValue,zValue,weight);
234void BDSOutputROOTEventHistograms::Fill4DHistogram(G4int histoId,
240 histograms4D[histoId]->Fill_BDSBH4D(xValue, yValue, zValue, eValue);
243void BDSOutputROOTEventHistograms::Fill4DHistogram(G4int,
249 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
257 histograms3D[histoId]->SetBinContent(globalBinID, value);
261void BDSOutputROOTEventHistograms::Set4DHistogramBinContent(G4int histoId,
268 histograms4D[histoId]->Set_BDSBH4D(x, y, z, e, value);
271void BDSOutputROOTEventHistograms::Set4DHistogramBinContent(G4int, G4int, G4int, G4int, G4int, G4double)
273 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
278 TH3D* otherHistogram)
280 histograms3D[histoId]->Add(otherHistogram);
283void BDSOutputROOTEventHistograms::AccumulateHistogram4D(G4int histoId,
286 *histograms4D[histoId] += *otherHistogram;
293 for (
auto h : histograms1D)
295 for (
auto h : histograms2D)
297 for (
auto h : histograms3D)
300 for (
auto h : histograms4D)
301 {h->Reset_BDSBH4D();}
Base class for the 4D histogram classes.
4D histogram classes with linear, logarithmic and user-defined energy binning.
General exception with possible name of object and message.
Holder for a set of histograms to be stored.
virtual void Flush()
Flush the contents.
void AccumulateHistogram3D(G4int histoId, TH3D *otherHistogram)
Add the values from one supplied 3D histogram to another. Uses TH3-Add().
int Create1DHistogramSTD(std::string name, std::string title, int nbins, double xmin, double xmax)
Interface function to create a 1D histogram using only standard types.
void Fill(const BDSOutputROOTEventHistograms *rhs)
Copy (using the TH->Clone) method from another instance.
void FillSimple(const BDSOutputROOTEventHistograms *rhs)
Copy (without using the TH->Clone) method from another instance. (Quicker).
void Set3DHistogramBinContent(G4int histoId, G4int globalBinID, G4double value)