...
 
Commits (3)
.PHONY: all clean
# Add C++14 standard flag if no other C++ standard was selected
ifneq (,$(findstring CXXFLAGS,-std=))
CXXFLAGS += -std=c++14
endif
all: $(TARGET)
clean:
......
......@@ -22,7 +22,7 @@ ROOT_LIBS := $(shell $(ROOT_CONFIG) --libs)
ROOT_GLIBS := $(shell $(ROOT_CONFIG) --glibs)
CFLAGS = -O2 -g -Wall -fPIC $(DEPFLAGS)
CXXFLAGS = $(ROOT_CXXFLAGS) -Wall -g -O2 -fPIC $(DEPFLAGS)
CXXFLAGS = $(ROOT_CXXFLAGS) -Wall -g -O2 -fPIC $(DEPFLAGS) -I../util
LDFLAGS = -shared
LDLIBS = -lstdc++
DEPFLAGS = -MT $@ -MMD -MP -MF $*.Td
......
......@@ -31,6 +31,8 @@
#include <TAxis.h>
#include "Compat.hh"
namespace HDTV {
void Calibration::SetCal(const std::vector<double> &cal) {
......@@ -155,7 +157,7 @@ double Calibration::E2Ch(double e) const {
}
void Calibration::Apply(TAxis *axis, int nbins) {
auto centers = std::make_unique<double[]>(nbins);
auto centers = Util::make_unique<double[]>(nbins);
for (int i = 0; i < nbins; i++) {
centers[i] = Ch2E(i);
......
......@@ -23,8 +23,7 @@
#include "DisplayObj.hh"
#include <algorithm>
#include <Riostream.h>
#include <iostream>
#include "DisplayStack.hh"
#include "View1D.hh"
......
......@@ -24,7 +24,6 @@
#include <utility>
#include <Riostream.h>
#include <TH1.h>
#include <TROOT.h>
......
......@@ -22,7 +22,6 @@
#include "Marker.hh"
#include <Riostream.h>
#include <TColor.h>
#include <TROOT.h>
......
......@@ -22,7 +22,6 @@
#include "Painter.hh"
#include <Riostream.h>
#include <TGX11.h>
#include "DisplayFunc.hh"
......
......@@ -25,8 +25,8 @@
#include <cmath>
#include <limits>
#include <iostream>
#include <Riostream.h>
#include <TGScrollBar.h>
#include <TGStatusBar.h>
......
......@@ -32,6 +32,7 @@
#include <TH1.h>
#include <TVirtualFitter.h>
#include "Compat.hh"
#include "Util.hh"
namespace HDTV {
......@@ -125,9 +126,9 @@ TF1 *EEPeak::GetPeakFunc() {
double max = fPos.Value(fFunc) + DECOMP_FUNC_WIDTH * fSigma2.Value(fFunc);
int numParams = fFunc->GetNpar();
fPeakFunc = std::make_unique<TF1>(GetFuncUniqueName("eepeak", this).c_str(),
this, &EEPeak::Eval, min, max, numParams,
"EEPeak", "Eval");
fPeakFunc = Util::make_unique<TF1>(GetFuncUniqueName("eepeak", this).c_str(),
this, &EEPeak::Eval, min, max, numParams,
"EEPeak", "Eval");
for (int i = 0; i < numParams; i++) {
fPeakFunc->SetParameter(i, fFunc->GetParameter(i));
......@@ -276,14 +277,16 @@ double EEFitter::Eval(const double *x, const double *p) const {
double EEFitter::EvalBg(const double *x, const double *p) const {
// Private: evaluation function for background
// Evaluate background function, if it has been given
double sum = fBackground ? fBackground->Eval(*x) : 0.0;
const double sum = fBackground ? fBackground->Eval(*x) : 0.0;
// Evaluate internal background
return sum +
std::accumulate(
std::reverse_iterator<const double *>(p + fNumParams - 1),
std::reverse_iterator<const double *>(p + fNumParams - fIntBgDeg),
0.0, [x = *x](double bg, double param) { return bg * x + param; });
auto first = p + fNumParams;
auto last = first - fIntBgDeg - 1;
return sum + std::accumulate(std::reverse_iterator<const double *>(first),
std::reverse_iterator<const double *>(last),
0.0, [x = *x](double bg, double param) {
return std::fma(bg, x, param);
});
}
TF1 *EEFitter::GetBgFunc() {
......@@ -308,9 +311,9 @@ TF1 *EEFitter::GetBgFunc() {
max = fMax;
}
fBgFunc = std::make_unique<TF1>(GetFuncUniqueName("fitbg_ee", this).c_str(),
this, &EEFitter::EvalBg, min, max, fNumParams,
"EEFitter", "EvalBg");
fBgFunc = Util::make_unique<TF1>(GetFuncUniqueName("fitbg_ee", this).c_str(),
this, &EEFitter::EvalBg, min, max,
fNumParams, "EEFitter", "EvalBg");
for (int i = 0; i < fNumParams; i++) {
fBgFunc->SetParameter(i, fSumFunc->GetParameter(i));
......@@ -355,8 +358,8 @@ void EEFitter::_Fit(TH1 &hist) {
}
// Create fit function
fSumFunc = std::make_unique<TF1>("f", this, &EEFitter::Eval, fMin, fMax,
fNumParams, "EEFitter", "Eval");
fSumFunc = Util::make_unique<TF1>("f", this, &EEFitter::Eval, fMin, fMax,
fNumParams, "EEFitter", "Eval");
// Init fit parameters
// Note: this may set parameters several times, but that should not matter
......@@ -448,9 +451,9 @@ void EEFitter::_Restore(double ChiSquare) {
// Internal worker function to restore the fit
// Create fit function
fSumFunc = std::make_unique<TF1>(GetFuncUniqueName("f", this).c_str(), this,
&EEFitter::Eval, fMin, fMax, fNumParams,
"EEFitter", "Eval");
fSumFunc = Util::make_unique<TF1>(GetFuncUniqueName("f", this).c_str(), this,
&EEFitter::Eval, fMin, fMax, fNumParams,
"EEFitter", "Eval");
for (auto &peak : fPeaks) {
peak.SetSumFunc(fSumFunc.get());
......
......@@ -31,6 +31,7 @@
#include <TH1.h>
#include <TVirtualFitter.h>
#include "Compat.hh"
#include "Util.hh"
namespace HDTV {
......@@ -49,10 +50,10 @@ PolyBg::PolyBg(const PolyBg &src)
//! Copy constructor
if (src.fFunc != nullptr) {
fFunc = std::make_unique<TF1>(GetFuncUniqueName("b", this).c_str(), this,
&PolyBg::_Eval, src.fFunc->GetXmin(),
src.fFunc->GetXmax(), fBgDeg + 1, "PolyBg",
"_Eval");
fFunc = Util::make_unique<TF1>(GetFuncUniqueName("b", this).c_str(), this,
&PolyBg::_Eval, src.fFunc->GetXmin(),
src.fFunc->GetXmax(), fBgDeg + 1, "PolyBg",
"_Eval");
for (int i = 0; i <= fBgDeg; i++) {
fFunc->SetParameter(i, src.fFunc->GetParameter(i));
......@@ -74,10 +75,10 @@ PolyBg &PolyBg::operator=(const PolyBg &src) {
fChisquare = src.fChisquare;
fCovar = src.fCovar;
fFunc = std::make_unique<TF1>(GetFuncUniqueName("b", this).c_str(), this,
&PolyBg::_Eval, src.fFunc->GetXmin(),
src.fFunc->GetXmax(), fBgDeg + 1, "PolyBg",
"_Eval");
fFunc = Util::make_unique<TF1>(GetFuncUniqueName("b", this).c_str(), this,
&PolyBg::_Eval, src.fFunc->GetXmin(),
src.fFunc->GetXmax(), fBgDeg + 1, "PolyBg",
"_Eval");
for (int i = 0; i <= fBgDeg; i++) {
fFunc->SetParameter(i, src.fFunc->GetParameter(i));
......@@ -125,9 +126,9 @@ void PolyBg::Fit(TH1 &hist) {
}
// Copy parameters to new function
fFunc = std::make_unique<TF1>(GetFuncUniqueName("b", this).c_str(), this,
&PolyBg::_Eval, GetMin(), GetMax(), fBgDeg + 1,
"PolyBg", "_Eval");
fFunc = Util::make_unique<TF1>(GetFuncUniqueName("b", this).c_str(), this,
&PolyBg::_Eval, GetMin(), GetMax(), fBgDeg + 1,
"PolyBg", "_Eval");
for (int i = 0; i <= fBgDeg; i++) {
fFunc->SetParameter(i, fitFunc.GetParameter(i));
......@@ -148,9 +149,9 @@ bool PolyBg::Restore(const TArrayD &values, const TArrayD &errors,
}
// Copy parameters to new function
fFunc = std::make_unique<TF1>(GetFuncUniqueName("b", this).c_str(), this,
&PolyBg::_Eval, GetMin(), GetMax(), fBgDeg + 1,
"PolyBg", "_Eval");
fFunc = Util::make_unique<TF1>(GetFuncUniqueName("b", this).c_str(), this,
&PolyBg::_Eval, GetMin(), GetMax(), fBgDeg + 1,
"PolyBg", "_Eval");
for (int i = 0; i <= fBgDeg; i++) {
fFunc->SetParameter(i, values[i]);
......
......@@ -27,11 +27,11 @@
#include <algorithm>
#include <numeric>
#include <Riostream.h>
#include <TError.h>
#include <TF1.h>
#include <TH1.h>
#include "Compat.hh"
#include "Util.hh"
namespace HDTV {
......@@ -122,9 +122,10 @@ TF1 *TheuerkaufPeak::GetPeakFunc() {
double max = fPos.Value(fFunc) + DECOMP_FUNC_WIDTH * fSigma.Value(fFunc);
int numParams = fFunc->GetNpar();
fPeakFunc = std::make_unique<TF1>(GetFuncUniqueName("peak", this).c_str(),
this, &TheuerkaufPeak::EvalNoStep, min, max,
numParams, "TheuerkaufPeak", "EvalNoStep");
fPeakFunc =
Util::make_unique<TF1>(GetFuncUniqueName("peak", this).c_str(), this,
&TheuerkaufPeak::EvalNoStep, min, max, numParams,
"TheuerkaufPeak", "EvalNoStep");
for (int i = 0; i < numParams; i++) {
fPeakFunc->SetParameter(i, fFunc->GetParameter(i));
......@@ -284,9 +285,9 @@ TF1 *TheuerkaufFitter::GetBgFunc() {
max = fMax;
}
fBgFunc = std::make_unique<TF1>(GetFuncUniqueName("fitbg", this).c_str(),
this, &TheuerkaufFitter::EvalBg, min, max,
fNumParams, "TheuerkaufFitter", "EvalBg");
fBgFunc = Util::make_unique<TF1>(GetFuncUniqueName("fitbg", this).c_str(),
this, &TheuerkaufFitter::EvalBg, min, max,
fNumParams, "TheuerkaufFitter", "EvalBg");
for (int i = 0; i < fNumParams; i++) {
fBgFunc->SetParameter(i, fSumFunc->GetParameter(i));
......@@ -330,9 +331,9 @@ void TheuerkaufFitter::_Fit(TH1 &hist) {
}
// Create fit function
fSumFunc = std::make_unique<TF1>(GetFuncUniqueName("f", this).c_str(), this,
&TheuerkaufFitter::Eval, fMin, fMax,
fNumParams, "TheuerkaufFitter", "Eval");
fSumFunc = Util::make_unique<TF1>(GetFuncUniqueName("f", this).c_str(), this,
&TheuerkaufFitter::Eval, fMin, fMax,
fNumParams, "TheuerkaufFitter", "Eval");
PeakVector_t::const_iterator citer;
......@@ -599,9 +600,9 @@ bool TheuerkaufFitter::Restore(const TArrayD &bgPolValues,
//! Internal worker function to restore the fit
void TheuerkaufFitter::_Restore(double ChiSquare) {
// Create fit function
fSumFunc = std::make_unique<TF1>(GetFuncUniqueName("f", this).c_str(), this,
&TheuerkaufFitter::Eval, fMin, fMax,
fNumParams, "TheuerkaufFitter", "Eval");
fSumFunc = Util::make_unique<TF1>(GetFuncUniqueName("f", this).c_str(), this,
&TheuerkaufFitter::Eval, fMin, fMax,
fNumParams, "TheuerkaufFitter", "Eval");
for (auto &peak : fPeaks) {
peak.SetSumFunc(fSumFunc.get());
......
#ifndef HDTV_ROOTEXT_UTIL_COMPAT_HH
#define HDTV_ROOTEXT_UTIL_COMPAT_HH
#include <memory>
#include <type_traits>
namespace HDTV {
namespace Util {
#if __cplusplus >= 201402L
using std::make_unique;
#else
namespace detail {
template <typename T> struct MakeUniq {
using single_object = std::unique_ptr<T>;
};
template <typename T> struct MakeUniq<T[]> {
using array = std::unique_ptr<T[]>;
};
template <typename T, size_t N> struct MakeUniq<T[N]> {
struct invalid_type {};
};
} // namespace detail
// make_unique for single objects
template <typename T, typename... Args>
inline typename detail::MakeUniq<T>::single_object
make_unique(Args &&... args) {
return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
}
// make_unique for arrays of unknown bound
template <typename T, typename... Args>
inline typename detail::MakeUniq<T>::array
make_unique(size_t n) {
return std::unique_ptr<T>(new typename std::remove_extent<T>::type[n]);
}
// disable make_unique for arrays of known bounds
template <typename T, typename... Args>
inline typename detail::MakeUniq<T>::invalid_type
make_unique(Args &&... args) = delete;
#endif /* __cplusplus */
} // namespace Util
} // namespace HDTV
#endif /* HDTV_ROOTEXT_UTIL_COMPAT_HH */
......@@ -58,6 +58,7 @@ setup(
'display/*.hh', 'display/*.cc', 'display/Makefile',
'display/LinkDef.h', 'display/libdisplay.so',
'display/libdisplay_rdict.pcm', 'display/libdisplay.rootmap',
'util/Compat.hh'
],
},
data_files=[
......