-
Notifications
You must be signed in to change notification settings - Fork 3
/
mainLightcurve.cxx
executable file
·195 lines (162 loc) · 4.76 KB
/
mainLightcurve.cxx
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
#include "mainLightcurve.h"
#include "gui.h"
#include "math.h"
#include "threads.h"
extern Gui *gui;
#define MAX_CHANNEL 1024
#define NUM_DETECTORS 7
extern pthread_mutex_t timebinmutex;
// the constructor method
mainLightcurve::mainLightcurve(int x,int y,int w,int h,const char *l)
: Fl_Gl_Window(x,y,w,h,l)
{
ymax = 1000;
ymin = 0;
xmax = 20;
xmin = 0;
current_timebin_detectors[0] = 0;
current_timebin_detectors[1] = 0;
current_timebin_detectors[2] = 0;
current_timebin_detectors[3] = 0;
current_timebin_detectors[4] = 0;
current_timebin_detectors[5] = 0;
current_timebin_detectors[6] = 0;
current_timebin = 0;
total_counts = 0;
for(int i = 0; i < MAX_CHANNEL; i++)
{
CountcurveFunction[i] = i;
binsize[i] = 1;
CountRatecurveFunction[i] = i;
for (int detector_num = 0; detector_num < NUM_DETECTORS; detector_num++) {
CountRatecurveDetectors[i][detector_num] = i;
}
}
}
// the drawing method: draws the histFunc into the window
void mainLightcurve::draw()
{
int k = 0;
float count_error = 0;
if (!valid()) {
make_current();
}
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
if (gui->mainLightcurve_ymaxslider->value() == 0){
// find the maximum
ymax = CountRatecurveFunction[0];
for (float x = 1; x < xmax; x+=binsize[k])
{
if (ymax < CountRatecurveFunction[k]) {
ymax = CountRatecurveFunction[k];
}
k++;
}
} else {
ymax = gui->mainLightcurve_ymaxslider->value();
}
//set camera
glViewport(0,0,w(),h());
gluOrtho2D(0, xmax, 0, ymax);
glMatrixMode(GL_MODELVIEW);
glDisable(GL_DEPTH_TEST);
glPushMatrix();
glLoadIdentity();
glClearColor(0.0,0.0,0.0,0.0);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
//draw the graph
glBegin(GL_LINES);
glColor3f(1.0, 0.0, 0.0);
k = 0;
for (float x = 0; x < xmax; x+=binsize[k])
{
CountRatecurveFunction[k] = CountcurveFunction[k]/binsize[k];
count_error = sqrt((float) CountcurveFunction[k]);
glVertex2f(x, CountRatecurveFunction[k]);
glVertex2f(x + binsize[k], CountRatecurveFunction[k]);
glVertex2f(x + binsize[k]/2.0, (CountcurveFunction[k] + count_error)/binsize[k]);
glVertex2f(x + binsize[k]/2.0, (CountcurveFunction[k] - count_error)/binsize[k]);
k++;
}
glEnd();
for (int detector_num = 0; detector_num < NUM_DETECTORS; detector_num++)
{
if (gui->mainHistogramWindow->get_detector_display(detector_num) == 1) {
k = 0;
glBegin(GL_LINES);
glColor3f(0.0, 1.0, 0.0);
k = 0;
for (float x = 0; x < xmax; x+=binsize[k])
{
CountRatecurveDetectors[k][detector_num] = CountcurveDetectors[k][detector_num]/binsize[k];
glVertex2f(x, CountRatecurveDetectors[k][detector_num]);
glVertex2f(x + binsize[k], CountRatecurveDetectors[k][detector_num]);
k++;
}
glEnd();
}
}
glPopMatrix();
glFinish();
// update the display of the current count rate
gui->ctsOutput->value(CountcurveFunction[0]/binsize[0]);
gui->totalctsOutput->value(total_counts);
}
void mainLightcurve::set_xmax(int newxmax){
xmax = newxmax;
}
void mainLightcurve::set_ymax(int newymax){
ymax = newymax;
}
void mainLightcurve::flush(int detector_number)
{
if( (detector_number < NUM_DETECTORS) && (detector_number >= 0) ){
for(int i = 0; i < MAX_CHANNEL; i++){
CountRatecurveDetectors[i][detector_number] = 0;}}
if (detector_number == 7) {
for (int detector_num = 0; detector_num < NUM_DETECTORS; detector_num++) {
for(int i = 0; i < MAX_CHANNEL; i++){
CountcurveFunction[i] = 0;
CountRatecurveDetectors[i][detector_num] = 0;
}
}
}
total_counts = 0;
redraw();
}
void mainLightcurve::add_count(int detector_number)
{
if( (detector_number < NUM_DETECTORS) && (detector_number >= 0) ){
pthread_mutex_trylock(&timebinmutex);
current_timebin_detectors[detector_number]++;
current_timebin++;
total_counts++;
pthread_mutex_unlock(&timebinmutex);
}
}
void mainLightcurve::reset(float current_binsize)
{
// save the info into the arrays
CountcurveFunction[0] = current_timebin;
binsize[0] = current_binsize;
for(int detector_num = 0; detector_num < NUM_DETECTORS; detector_num++)
{
CountcurveDetectors[0][detector_num] = current_timebin_detectors[detector_num];
}
// now shift everything back one
for(int j = MAX_CHANNEL-1; j > 0; j--){
CountcurveFunction[j] = CountcurveFunction[j-1];
binsize[j] = binsize[j-1];
}
for(int detector_num = 0; detector_num < NUM_DETECTORS; detector_num++)
{
for(int j = MAX_CHANNEL-1; j > 0; j--){ CountcurveDetectors[j][detector_num] = CountcurveDetectors[j-1][detector_num];}
}
pthread_mutex_lock(&timebinmutex);
// now reset all values to zero to start accumulating next time bin
for(int detector_num = 0; detector_num < NUM_DETECTORS; detector_num++)
{ current_timebin_detectors[detector_num] = 0; }
current_timebin = 0;
pthread_mutex_unlock(&timebinmutex);
}