18#include "BDSOutputROOTEventHistograms.hh"
23#include "BDSBH4DBase.hh"
27#include "BDSBH4DTypeDefs.hh"
29#include "BDSException.hh"
34BDSOutputROOTEventHistograms::BDSOutputROOTEventHistograms()
36 TH1D::AddDirectory(kFALSE);
37 TH2D::AddDirectory(kFALSE);
38 TH3D::AddDirectory(kFALSE);
47BDSOutputROOTEventHistograms::BDSOutputROOTEventHistograms(std::vector<TH1D*>& histograms1DIn,
48 std::vector<TH2D*>& histograms2DIn,
49 std::vector<TH3D*>& histograms3DIn,
50 std::vector<BDSBH4DBase*>& histograms4DIn):
51 histograms1D(histograms1DIn),
52 histograms2D(histograms2DIn),
53 histograms3D(histograms3DIn),
54 histograms4D(histograms4DIn)
57BDSOutputROOTEventHistograms::~BDSOutputROOTEventHistograms()
65 histograms1D = rhs->histograms1D;
66 histograms2D = rhs->histograms2D;
67 histograms3D = rhs->histograms3D;
68 histograms4D = rhs->histograms4D;
77 for (
auto h : rhs->histograms1D)
78 {histograms1D.push_back(
static_cast<TH1D*
>(h->Clone()));}
79 for (
auto h : rhs->histograms2D)
80 {histograms2D.push_back(
static_cast<TH2D*
>(h->Clone()));}
81 for (
auto h : rhs->histograms3D)
82 {histograms3D.push_back(
static_cast<TH3D*
>(h->Clone()));}
84 for (
auto h : rhs->histograms4D)
85 {histograms4D.push_back(
static_cast<BDSBH4DBase*
>(h->Clone(
"")));}
91 int nbins,
double xmin,
double xmax)
93 histograms1D.push_back(
new TH1D(name.c_str(),title.c_str(), nbins, xmin, xmax));
94 return (
int)histograms1D.size() - 1;
99G4int BDSOutputROOTEventHistograms::Create1DHistogram(G4String name, G4String title,
100 G4int nbins, G4double xmin, G4double xmax)
102 histograms1D.push_back(
new TH1D(name,title, nbins, xmin, xmax));
103 return (G4int)histograms1D.size() - 1;
106G4int BDSOutputROOTEventHistograms::Create1DHistogram(G4String name,
108 std::vector<double>& edges)
110 histograms1D.push_back(
new TH1D(name, title, (Int_t)edges.size()-1, edges.data()));
111 return (G4int)histograms1D.size() - 1;
114G4int BDSOutputROOTEventHistograms::Create2DHistogram(G4String name, G4String title,
115 G4int nxbins, G4double xmin, G4double xmax,
116 G4int nybins, G4double ymin, G4double ymax)
118 histograms2D.push_back(
new TH2D(name,title, nxbins, xmin, xmax, nybins, ymin, ymax));
119 return (G4int)histograms2D.size() - 1;
122G4int BDSOutputROOTEventHistograms::Create2DHistogram(G4String name, G4String title,
123 std::vector<double>& xedges,
124 std::vector<double>& yedges)
126 histograms2D.push_back(
new TH2D(name.data(),title.data(),
127 (Int_t)xedges.size()-1, xedges.data(),
128 (Int_t)yedges.size()-1, yedges.data()));
129 return (G4int)histograms2D.size() - 1;
132G4int BDSOutputROOTEventHistograms::Create3DHistogram(G4String name, G4String title,
133 G4int nxbins, G4double xmin, G4double xmax,
134 G4int nybins, G4double ymin, G4double ymax,
135 G4int nzbins, G4double zmin, G4double zmax)
137 histograms3D.push_back(
new TH3D(name, title,
140 nzbins, zmin, zmax));
141 return (G4int)histograms3D.size() - 1;
144G4int BDSOutputROOTEventHistograms::Create3DHistogram(G4String name, G4String title,
145 std::vector<double>& xedges,
146 std::vector<double>& yedges,
147 std::vector<double>& zedges)
149 histograms3D.push_back(
new TH3D(name.data(),title.data(),
150 (Int_t)xedges.size()-1, xedges.data(),
151 (Int_t)yedges.size()-1, yedges.data(),
152 (Int_t)zedges.size()-1, zedges.data()));
153 return (G4int)histograms3D.size() - 1;
157G4int BDSOutputROOTEventHistograms::Create4DHistogram(
const G4String& name,
158 const G4String& title,
159 const G4String& eScale,
160 const std::vector<double>& eBinsEdges,
161 unsigned int nxbins, G4double xmin, G4double xmax,
162 unsigned int nybins, G4double ymin, G4double ymax,
163 unsigned int nzbins, G4double zmin, G4double zmax,
164 unsigned int nebins, G4double emin, G4double emax)
166 std::string nameC = (std::string)name;
167 std::string titleC = (std::string)title;
168 std::string eScaleC = (std::string)eScale;
170 if(eScale ==
"linear")
176 nebins, emin, emax));
178 else if(eScale ==
"log")
184 nebins, emin, emax));
186 else if(eScale ==
"user")
191 nzbins, zmin, zmax));
194 return (G4int)histograms4D.size() - 1;
197G4int BDSOutputROOTEventHistograms::Create4DHistogram(
const G4String&,
const G4String&,
const G4String&,
198 const std::vector<double>&,
199 unsigned int, G4double, G4double,
200 unsigned int, G4double, G4double,
201 unsigned int, G4double, G4double,
202 unsigned int, G4double, G4double)
204 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
208void BDSOutputROOTEventHistograms::Fill1DHistogram(G4int histoId,
212 histograms1D[histoId]->Fill(value,weight);
215void BDSOutputROOTEventHistograms::Fill2DHistogram(G4int histoId,
220 histograms2D[histoId]->Fill(xValue,yValue,weight);
223void BDSOutputROOTEventHistograms::Fill3DHistogram(G4int histoId,
229 histograms3D[histoId]->Fill(xValue,yValue,zValue,weight);
233void BDSOutputROOTEventHistograms::Fill4DHistogram(G4int histoId,
239 histograms4D[histoId]->Fill_BDSBH4D(xValue, yValue, zValue, eValue);
242void BDSOutputROOTEventHistograms::Fill4DHistogram(G4int,
248 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
256 histograms3D[histoId]->SetBinContent(globalBinID, value);
260void BDSOutputROOTEventHistograms::Set4DHistogramBinContent(G4int histoId,
267 histograms4D[histoId]->Set_BDSBH4D(x, y, z, e, value);
270void BDSOutputROOTEventHistograms::Set4DHistogramBinContent(G4int, G4int, G4int, G4int, G4int, G4double)
272 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
277 TH3D* otherHistogram)
279 histograms3D[histoId]->Add(otherHistogram);
282void BDSOutputROOTEventHistograms::AccumulateHistogram4D(G4int histoId,
285 *histograms4D[histoId] += *otherHistogram;
292 for (
auto h : histograms1D)
294 for (
auto h : histograms2D)
296 for (
auto h : histograms3D)
299 for (
auto h : histograms4D)
300 {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)