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, G4String title,
108 std::vector<double>& edges)
111 Double_t* edgesD =
new Double_t[edges.size()];
112 for (
int i=0;i<(int)edges.size();++i)
113 {edgesD[i] = edges[i];}
115 histograms1D.push_back(
new TH1D(name,title,(Int_t)edges.size()-1,edgesD));
118 return (G4int)histograms1D.size() - 1;
121G4int BDSOutputROOTEventHistograms::Create2DHistogram(G4String name, G4String title,
122 G4int nxbins, G4double xmin, G4double xmax,
123 G4int nybins, G4double ymin, G4double ymax)
125 histograms2D.push_back(
new TH2D(name,title, nxbins, xmin, xmax, nybins, ymin, ymax));
126 return (G4int)histograms2D.size() - 1;
129G4int BDSOutputROOTEventHistograms::Create2DHistogram(G4String name, G4String title,
130 std::vector<double>& xedges,
131 std::vector<double>& yedges)
133 Double_t* xedgesD =
new Double_t[xedges.size()];
134 for (
int i=0;i<(int)xedges.size();++i)
135 {xedgesD[i] = xedges[i];}
137 Double_t* yedgesD =
new Double_t[yedges.size()];
138 for (
int i=0;i<(int)yedges.size();++i)
139 {yedgesD[i] = yedges[i];}
141 histograms2D.push_back(
new TH2D(name.data(),title.data(), (Int_t)xedges.size()-1, xedgesD, (Int_t)yedges.size()-1, yedgesD));
145 return (G4int)histograms2D.size() - 1;
148G4int BDSOutputROOTEventHistograms::Create3DHistogram(G4String name, G4String title,
149 G4int nxbins, G4double xmin, G4double xmax,
150 G4int nybins, G4double ymin, G4double ymax,
151 G4int nzbins, G4double zmin, G4double zmax)
153 histograms3D.push_back(
new TH3D(name, title,
156 nzbins, zmin, zmax));
157 return (G4int)histograms3D.size() - 1;
160G4int BDSOutputROOTEventHistograms::Create3DHistogram(G4String name, G4String title,
161 std::vector<double>& xedges,
162 std::vector<double>& yedges,
163 std::vector<double>& zedges)
165 Double_t* xedgesD =
new Double_t[xedges.size()];
166 for (
int i=0;i<(int)xedges.size();++i)
167 {xedgesD[i] = xedges[i];}
169 Double_t* yedgesD =
new Double_t[yedges.size()];
170 for (
int i=0;i<(int)yedges.size();++i)
171 {yedgesD[i] = yedges[i];}
173 Double_t* zedgesD =
new Double_t[zedges.size()];
174 for (
int i=0;i<(int)zedges.size();++i)
175 {zedgesD[i] = zedges[i];}
177 histograms3D.push_back(
new TH3D(name.data(),title.data(),
178 (Int_t)xedges.size()-1, xedgesD,
179 (Int_t)yedges.size()-1, yedgesD,
180 (Int_t)zedges.size()-1, zedgesD));
181 return (G4int)histograms3D.size() - 1;
185G4int BDSOutputROOTEventHistograms::Create4DHistogram(
const G4String& name,
186 const G4String& title,
187 const G4String& eScale,
188 const std::vector<double>& eBinsEdges,
189 unsigned int nxbins, G4double xmin, G4double xmax,
190 unsigned int nybins, G4double ymin, G4double ymax,
191 unsigned int nzbins, G4double zmin, G4double zmax,
192 unsigned int nebins, G4double emin, G4double emax)
194 std::string nameC = (std::string)name;
195 std::string titleC = (std::string)title;
196 std::string eScaleC = (std::string)eScale;
198 if(eScale ==
"linear")
204 nebins, emin, emax));
206 else if(eScale ==
"log")
212 nebins, emin, emax));
214 else if(eScale ==
"user")
219 nzbins, zmin, zmax));
222 return (G4int)histograms4D.size() - 1;
225G4int BDSOutputROOTEventHistograms::Create4DHistogram(
const G4String&,
const G4String&,
const G4String&,
226 const std::vector<double>&,
227 unsigned int, G4double, G4double,
228 unsigned int, G4double, G4double,
229 unsigned int, G4double, G4double,
230 unsigned int, G4double, G4double)
232 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
236void BDSOutputROOTEventHistograms::Fill1DHistogram(G4int histoId,
240 histograms1D[histoId]->Fill(value,weight);
243void BDSOutputROOTEventHistograms::Fill2DHistogram(G4int histoId,
248 histograms2D[histoId]->Fill(xValue,yValue,weight);
251void BDSOutputROOTEventHistograms::Fill3DHistogram(G4int histoId,
257 histograms3D[histoId]->Fill(xValue,yValue,zValue,weight);
261void BDSOutputROOTEventHistograms::Fill4DHistogram(G4int histoId,
267 histograms4D[histoId]->Fill_BDSBH4D(xValue, yValue, zValue, eValue);
270void BDSOutputROOTEventHistograms::Fill4DHistogram(G4int,
276 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
284 histograms3D[histoId]->SetBinContent(globalBinID, value);
288void BDSOutputROOTEventHistograms::Set4DHistogramBinContent(G4int histoId,
295 histograms4D[histoId]->Set_BDSBH4D(x, y, z, e, value);
298void BDSOutputROOTEventHistograms::Set4DHistogramBinContent(G4int, G4int, G4int, G4int, G4int, G4double)
300 throw BDSException(__METHOD_NAME__,
"BDSIM compiled without BOOST support -> no 4D histograms.");
305 TH3D* otherHistogram)
307 histograms3D[histoId]->Add(otherHistogram);
310void BDSOutputROOTEventHistograms::AccumulateHistogram4D(G4int histoId,
313 *histograms4D[histoId] += *otherHistogram;
320 for (
auto h : histograms1D)
322 for (
auto h : histograms2D)
324 for (
auto h : histograms3D)
327 for (
auto h : histograms4D)
328 {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)