-
Notifications
You must be signed in to change notification settings - Fork 0
/
YSH1.cpp
72 lines (65 loc) · 1.93 KB
/
YSH1.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
//
// YSH1.cpp
// A basic 1D function
//
// Created by Yves Schutz on 10/05/14.
// Copyright (c) 2014 Yves Schutz. All rights reserved.
#include "qcustomplot.h"
#include "YSH1.h"
//______________________________________________________________________________
YSH1::YSH1(QString name, int bins, qreal xmin, qreal xmax)
{
// ctor
mName = name;
mNumberOfBins = bins;
mXMax = xmax;
mXMin = xmin;
mXValues.resize(mNumberOfBins + 2);
mYValues.resize(mNumberOfBins + 2);
mDx = (mXMax - mXMin) / mNumberOfBins;
FillXValues();
}
//______________________________________________________________________________
YSH1::YSH1(const YSH1 &h1)
{
// copy ctor
((YSH1&)h1).Copy(*this);
}
//______________________________________________________________________________
void YSH1::Copy(QObject &obj) const
{
// copy this H1 to a new H1
((YSH1&) obj).mDx = mDx;
((YSH1&) obj).mName = mName;
((YSH1&) obj).mNumberOfBins = mNumberOfBins;
((YSH1&) obj).mXMax = mXMax;
((YSH1&) obj).mXMin = mXMin;
for (int index = 0; index < mNumberOfBins; index++) {
((YSH1&) obj).mXValues[index] = mXValues[index];
((YSH1&) obj).mYValues[index] = mYValues[index];
}
}
//______________________________________________________________________________
void YSH1::Fill(qreal x, qreal weight)
{
// fills the array with the x values
int index;
if ( x < mXMin || x > mXMax) // overflow
index = 0;
else {
index = ( x - mXMin) / mDx + 1;
}
mYValues[index] += weight;
}
//______________________________________________________________________________
qreal YSH1::GetYMax()
{
// search highest Y value
qreal ymax = 0.0;
for (int index = 0; index < mNumberOfBins -1; index++) {
if( mYValues[index] > ymax )
ymax = mYValues[index];
}
mYMax = ymax;
return ymax;
}