Skip to content
Snippets Groups Projects
Commit 7274a748 authored by Danilo Piparo's avatar Danilo Piparo
Browse files

[DF] ROOT-9692 properly handle custom binning of 2d profiles

parent 0a0581fb
No related branches found
No related tags found
No related merge requests found
...@@ -272,6 +272,8 @@ TProfile2DModel::TProfile2DModel(const ::TProfile2D &h) ...@@ -272,6 +272,8 @@ TProfile2DModel::TProfile2DModel(const ::TProfile2D &h)
fXUp(h.GetXaxis()->GetXmax()), fNbinsY(h.GetNbinsY()), fYLow(h.GetYaxis()->GetXmin()), fXUp(h.GetXaxis()->GetXmax()), fNbinsY(h.GetNbinsY()), fYLow(h.GetYaxis()->GetXmin()),
fYUp(h.GetYaxis()->GetXmax()), fZLow(h.GetZmin()), fZUp(h.GetZmax()), fOption(h.GetErrorOption()) fYUp(h.GetYaxis()->GetXmax()), fZLow(h.GetZmin()), fZUp(h.GetZmax()), fOption(h.GetErrorOption())
{ {
SetAxisProperties(h.GetXaxis(), fXLow, fXUp, fBinXEdges);
SetAxisProperties(h.GetYaxis(), fYLow, fYUp, fBinYEdges);
} }
TProfile2DModel::TProfile2DModel(const char *name, const char *title, int nbinsx, double xlow, double xup, int nbinsy, TProfile2DModel::TProfile2DModel(const char *name, const char *title, int nbinsx, double xlow, double xup, int nbinsy,
double ylow, double yup, const char *option) double ylow, double yup, const char *option)
...@@ -311,9 +313,32 @@ TProfile2DModel::TProfile2DModel(const char *name, const char *title, int nbinsx ...@@ -311,9 +313,32 @@ TProfile2DModel::TProfile2DModel(const char *name, const char *title, int nbinsx
std::shared_ptr<::TProfile2D> TProfile2DModel::GetProfile() const std::shared_ptr<::TProfile2D> TProfile2DModel::GetProfile() const
{ {
auto prof = auto xEdgesEmpty = fBinXEdges.empty();
std::make_shared<::TProfile2D>(fName, fTitle, fNbinsX, fXLow, fXUp, fNbinsY, fYLow, fYUp, fZLow, fZUp, fOption); auto yEdgesEmpty = fBinYEdges.empty();
prof->SetDirectory(nullptr); // lifetime is managed by the shared_ptr, detach from ROOT's memory management std::shared_ptr<::TProfile2D> prof;
if (xEdgesEmpty && yEdgesEmpty) {
prof = std::make_shared<::TProfile2D>(fName, fTitle,
fNbinsX, fXLow, fXUp,
fNbinsY, fYLow, fYUp,
fZLow, fZUp, fOption);
} else if (!xEdgesEmpty && yEdgesEmpty) {
prof = std::make_shared<::TProfile2D>(fName, fTitle,
fNbinsX, fBinXEdges.data(),
fNbinsY, fYLow, fYUp,
fOption);
} else if (xEdgesEmpty && !yEdgesEmpty) {
prof = std::make_shared<::TProfile2D>(fName, fTitle,
fNbinsX, fXLow, fXUp,
fNbinsY, fBinYEdges.data(),
fOption);
} else {
prof = std::make_shared<::TProfile2D>(fName, fTitle,
fNbinsX, fBinXEdges.data(),
fNbinsY, fBinYEdges.data(),
fOption);
}
prof->SetDirectory(nullptr); // object's lifetime is managed by the shared_ptr, detach it from ROOT's memory management
return prof; return prof;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment