23 #include <tspectrum.h>
26 const std::string& option,
31 tspectrum::Spectrum2D spec;
32 auto peaks = spec.find_peaks(arr, sigma, option, threshold);
35 std::vector<std::pair<double, double>> result;
37 for (
const auto& p : peaks) {
38 double row_value = p.first;
39 double col_value = p.second;
41 size_t xaxis_index =
static_cast<size_t>(col_value);
42 size_t yaxis_index = hist.
yAxis().
size() - 1 -
static_cast<size_t>(row_value);
47 double dx = col_value -
static_cast<size_t>(col_value);
48 double dy = -1.0 * (row_value -
static_cast<size_t>(row_value));
53 result.push_back(std::make_pair(x, y));
63 throw std::runtime_error(
"Error in HistoUtils::RelativeDifference: "
64 "different number of elements");
67 double sum_of_diff = 0.0;
68 for (
size_t i = 0; i < dat.
size(); ++i)
70 return sum_of_diff / dat.
size();
85 std::cerr <<
"Could not read reference data from file " << refFileName << std::endl;
88 std::unique_ptr<OutputData<double>> datDat(dat.
data());
Defines namespace DataUtils.
PyObvject forward declaration.
Defines class Histogram2D.
Defines class IntensityDataIOFactory.
Defines constants and "almost equal" in namespace Numeric.
Defines class SimulationResult.
Two dimensional histogram.
virtual Bin1D bin(size_t index) const =0
retrieve a 1d bin for the given index
virtual size_t size() const =0
retrieve the number of bins
Base class for 1D and 2D histograms holding values of double type.
const IAxis & yAxis() const
returns y-axis for 2D histograms
const IAxis & xAxis() const
returns x-axis
const OutputData< CumulativeValue > & getData() const
OutputData< double > * createOutputData(DataType dataType=DataType::INTEGRAL) const
creates new OutputData with histogram's shape and values corresponding to DataType
static OutputData< double > * readOutputData(const std::string &file_name)
Reads file and returns newly created OutputData object.
OutputData< double > * meanValues() const
Wrapper around OutputData<double> that also provides unit conversions.
std::unique_ptr< OutputData< double > > data(Axes::Units units=Axes::Units::DEFAULT) const
decltype(auto) createVector2D(const T &data)
Creates 2D vector from OutputData.
bool checkRelativeDifference(const OutputData< double > &dat, const OutputData< double > &ref, const double threshold)
Returns true is relative difference is below threshold; prints informative output.
double relativeDataDifference(const OutputData< double > &dat, const OutputData< double > &ref)
Returns relative difference between two data sets sum(dat[i] - ref[i])/ref[i]).
std::vector< std::pair< double, double > > FindPeaks(const Histogram2D &hist, double sigma=2, const std::string &option={}, double threshold=0.05)
Returns vector of peak center coordinates, for peaks in given histogram.
double getRelativeDifference(const IHistogram &dat, const IHistogram &ref)
bool agreesWithReference(const SimulationResult &dat, const std::string &refFileName, double tol)
Returns true if SimulatioResult agrees with data from reference file.
double RelativeDifference(const SimulationResult &dat, const SimulationResult &ref)
Returns sum of relative differences between each pair of elements: (a, b) -> 2*abs(a - b)/(a + b) ( a...
double GetRelativeDifference(double a, double b)
Returns the safe relative difference, which is 2(|a-b|)/(|a|+|b|) except in special cases.