mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-13 05:17:13 +02:00
changed cxx to cpp
This commit is contained in:
148
slsDetectorGui/slsDetectorPlotting/src/SlsQt2DHist.cpp
Normal file
148
slsDetectorGui/slsDetectorPlotting/src/SlsQt2DHist.cpp
Normal file
@ -0,0 +1,148 @@
|
||||
|
||||
/**
|
||||
* @author Ian Johnson
|
||||
* @version 1.0
|
||||
*/
|
||||
|
||||
#include "SlsQt2DHist.h"
|
||||
#include "ansi.h"
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
|
||||
using std::cout;
|
||||
using std::endl;
|
||||
|
||||
SlsQt2DHist::SlsQt2DHist(int nbinsx, double xmin, double xmax, int nbinsy,
|
||||
double ymin, double ymax, double *d, double zmin,
|
||||
double zmax)
|
||||
: QwtRasterData() {
|
||||
x_min = 0;
|
||||
x_max = 0;
|
||||
y_min = 0;
|
||||
y_max = 0;
|
||||
interp = 0;
|
||||
nx_array = ny_array = 0;
|
||||
data = 0;
|
||||
SetData(nbinsx, xmin, xmax, nbinsy, ymin, ymax, d, zmin, zmax);
|
||||
}
|
||||
|
||||
SlsQt2DHist::~SlsQt2DHist() { delete[] data; }
|
||||
|
||||
int SlsQt2DHist::GetBinIndex(int bx, int by) {
|
||||
int b = bx * ny + by;
|
||||
if (b < 0 || b >= nb) {
|
||||
cout << "GetBinIndex:: Incorrect indicies bx and by returning overflow "
|
||||
"bin;"
|
||||
<< endl;
|
||||
return nb;
|
||||
}
|
||||
return b;
|
||||
}
|
||||
|
||||
int SlsQt2DHist::FindBinIndex(double x, double y) {
|
||||
return GetBinIndex(int((x - x_min) / x_width), int((y - y_min) / y_width));
|
||||
}
|
||||
|
||||
double SlsQt2DHist::GetBinValue(int bx, int by) {
|
||||
return data[GetBinIndex(bx, by)];
|
||||
}
|
||||
|
||||
void SlsQt2DHist::SetBinValue(int bx, int by, double v) {
|
||||
z_mean_has_been_calculated = 0;
|
||||
data[GetBinIndex(bx, by)] = v;
|
||||
}
|
||||
|
||||
void SlsQt2DHist::SetData(int nbinsx, double xmin, double xmax, int nbinsy,
|
||||
double ymin, double ymax, double *d, double zmin,
|
||||
double zmax) {
|
||||
z_mean_has_been_calculated = 0;
|
||||
if (xmax < xmin || ymax < ymin)
|
||||
cout << "Warning input range invalid." << endl;
|
||||
|
||||
x_width = (xmax - xmin) / nbinsx;
|
||||
y_width = (ymax - ymin) / nbinsy;
|
||||
|
||||
if (x_min != xmin || x_max != xmax || y_min != ymin || y_max != ymax) {
|
||||
x_min = xmin;
|
||||
x_max = xmax;
|
||||
y_min = ymin;
|
||||
y_max = ymax;
|
||||
setInterval(Qt::XAxis, QwtInterval(xmin, xmax));
|
||||
setInterval(Qt::YAxis, QwtInterval(ymin, ymax));
|
||||
}
|
||||
|
||||
if (nbinsx * nbinsy < 1) {
|
||||
cout << "Exitting: SlsQt2DHist::SetData() number of bins must be "
|
||||
"greater than zero."
|
||||
<< endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (nbinsx * nbinsy > nx_array * ny_array) {
|
||||
delete[] data;
|
||||
data = new double[nbinsx * nbinsy + 1]; // one for under/overflow bin
|
||||
nx_array = nbinsx;
|
||||
ny_array = nbinsy;
|
||||
}
|
||||
nx = nbinsx;
|
||||
ny = nbinsy;
|
||||
nb = nx * ny;
|
||||
data[nb] = 0; // set over flow to zero
|
||||
if (d) {
|
||||
memcpy(data, d, nb * sizeof(double));
|
||||
SetMinMax(zmin, zmax);
|
||||
}
|
||||
}
|
||||
|
||||
void SlsQt2DHist::SetMinMax(double zmin, double zmax) {
|
||||
/* if(zmin<zmax){ edited out to test*/
|
||||
if (zmax != -1) {
|
||||
z_min = zmin;
|
||||
z_max = zmax;
|
||||
} else {
|
||||
z_mean_has_been_calculated = 1;
|
||||
z_min = data[0];
|
||||
z_mean = 0;
|
||||
z_max = data[0];
|
||||
for (int i = 0; i < nb; i++) {
|
||||
if (data[i] < z_min)
|
||||
z_min = data[i];
|
||||
if (data[i] > z_max)
|
||||
z_max = data[i];
|
||||
z_mean += data[i];
|
||||
}
|
||||
z_mean /= nb;
|
||||
if (z_min > 0)
|
||||
z_min /= 1.02;
|
||||
else
|
||||
z_min *= 1.02;
|
||||
if (z_max > 0)
|
||||
z_max *= 1.02;
|
||||
else
|
||||
z_max /= 1.02;
|
||||
}
|
||||
setInterval(Qt::ZAxis, QwtInterval(z_min, z_max));
|
||||
}
|
||||
|
||||
double SlsQt2DHist::GetMean() {
|
||||
if (!z_mean_has_been_calculated) {
|
||||
z_mean_has_been_calculated = 1;
|
||||
z_mean = 0;
|
||||
for (int i = 0; i < nb; i++)
|
||||
z_mean += data[i];
|
||||
z_mean /= nb;
|
||||
}
|
||||
|
||||
return z_mean;
|
||||
}
|
||||
|
||||
double SlsQt2DHist::SetMinimumToFirstGreaterThanZero() {
|
||||
z_min = fabs(z_max) + 1;
|
||||
for (int i = 0; i < nb; i++) {
|
||||
if (data[i] > 0 && data[i] < z_min)
|
||||
z_min = data[i];
|
||||
}
|
||||
setInterval(Qt::ZAxis, QwtInterval(z_min, z_max));
|
||||
|
||||
return z_min;
|
||||
}
|
Reference in New Issue
Block a user