Rev 167 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
146 | f9daq | 1 | #include "../include/sipmscan.h" |
2 | #include "../include/workstation.h" |
||
3 | |||
4 | #include <stdio.h> |
||
5 | #include <stdlib.h> |
||
6 | |||
7 | int retTemp; |
||
8 | |||
9 | // Additional functions ------------------------------------- |
||
10 | |||
11 | // Display the currently selected histogram in the file list |
||
12 | void TGAppMainFrame::DisplayHistogram(char *histfile, int histtype, int opt) |
||
13 | { |
||
14 | char histtime[256]; |
||
15 | char ctemp[512]; |
||
16 | |||
17 | if(DBGSIG) |
||
18 | printf("DisplayHistogram(): Selected file: %s\n", histfile); |
||
19 | |||
20 | TCanvas *gCanvas = analysisCanvas->GetCanvas(); |
||
21 | |||
22 | inroot = TFile::Open(histfile, "READ"); |
||
23 | |||
24 | TTree *header_data, *meas_data; |
||
25 | inroot->GetObject("header_data", header_data); |
||
26 | inroot->GetObject("meas_data", meas_data); |
||
27 | |||
28 | // Reading the header |
||
29 | header_data->SetBranchAddress("nrch", &evtheader.nrch); |
||
30 | header_data->GetEntry(0); |
||
31 | header_data->SetBranchAddress("timestamp", &evtheader.timestamp); |
||
32 | header_data->GetEntry(0); |
||
33 | header_data->SetBranchAddress("biasvolt", &evtheader.biasvolt); |
||
34 | header_data->GetEntry(0); |
||
35 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
||
36 | header_data->GetEntry(0); |
||
37 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
||
38 | header_data->GetEntry(0); |
||
39 | header_data->SetBranchAddress("zpos", &evtheader.zpos); |
||
40 | header_data->GetEntry(0); |
||
41 | header_data->SetBranchAddress("temperature", &evtheader.temperature); |
||
42 | header_data->GetEntry(0); |
||
43 | if( header_data->FindBranch("angle") ) |
||
44 | { |
||
45 | header_data->SetBranchAddress("angle", &evtheader.angle); |
||
46 | header_data->GetEntry(0); |
||
47 | } |
||
48 | header_data->SetBranchAddress("laserinfo", &evtheader.laserinfo); |
||
49 | header_data->GetEntry(0); |
||
50 | |||
51 | // Change timestamp to local time |
||
52 | GetTime(evtheader.timestamp, histtime); |
||
53 | |||
54 | // Displaying header information debug |
||
55 | if(DBGSIG) |
||
56 | { |
||
57 | printf("DisplayHistogram(): Opened file header information:\n"); |
||
58 | printf("- Number of channels (ADC and TDC are considered as separate channels): %d\n", evtheader.nrch); |
||
59 | printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime); |
||
60 | printf("- Bias voltage: %lf\n", evtheader.biasvolt); |
||
61 | printf("- Table position (X,Y,Z): %d, %d, %d\n", evtheader.xpos, evtheader.ypos, evtheader.zpos); |
||
62 | if(evtheader.temperature) |
||
63 | printf("- Temperature: %lf\n", evtheader.temperature); |
||
64 | if( header_data->FindBranch("angle") ) |
||
65 | printf("- Incidence angle: %lf\n", evtheader.angle); |
||
66 | else |
||
67 | printf("- Incidence angle: No angle information!\n"); |
||
68 | printf("- Laser and filter settings: %s\n", evtheader.laserinfo); |
||
69 | } |
||
70 | |||
71 | // Displaying header information on the GUI |
||
72 | dispTime->widgetTE->SetText(histtime); |
||
73 | dispBias->widgetNE[0]->SetNumber(evtheader.biasvolt); |
||
74 | sprintf(ctemp, "%d, %d, %d", evtheader.xpos, evtheader.ypos, evtheader.zpos); |
||
75 | dispPos->widgetTE->SetText(ctemp); |
||
76 | if(evtheader.temperature) |
||
77 | dispTemp->widgetNE[0]->SetNumber(evtheader.temperature); |
||
78 | else |
||
79 | dispTemp->widgetNE[0]->SetNumber(0.0); |
||
80 | if( header_data->FindBranch("angle") ) |
||
81 | dispAngle->widgetNE[0]->SetNumber(evtheader.angle); |
||
82 | else |
||
83 | dispAngle->widgetNE[0]->SetNumber(0.0); |
||
84 | dispLaser->widgetTE->SetText(evtheader.laserinfo); |
||
85 | |||
86 | selectCh->widgetNE[0]->SetLimitValues(0, (evtheader.nrch/2)-1); |
||
87 | |||
88 | // Redraw the histograms |
||
89 | int j; |
||
90 | char rdc[256]; |
||
91 | char rdcsel[256]; |
||
92 | |||
93 | j = selectCh->widgetNE[0]->GetNumber(); |
||
94 | |||
95 | printf("Found %d data points.\n", (int)meas_data->GetEntries()); |
||
96 | |||
97 | gCanvas->cd(); |
||
98 | double range[4]; |
||
99 | range[0] = adcRange->widgetNE[0]->GetNumber(); |
||
100 | range[1] = adcRange->widgetNE[1]->GetNumber(); |
||
101 | range[2] = tdcRange->widgetNE[0]->GetNumber(); |
||
102 | range[3] = tdcRange->widgetNE[1]->GetNumber(); |
||
103 | |||
104 | // ADC histogram |
||
105 | if(histtype == 0) |
||
106 | { |
||
107 | if( range[0] == range[1] ) |
||
108 | sprintf(rdc, "ADC%d>>%s", j, histname); |
||
109 | else |
||
110 | sprintf(rdc, "ADC%d>>%s(%d,%lf,%lf)", j, histname, (int)(range[1]-range[0]), range[0]-0.5, range[1]-0.5); |
||
111 | |||
112 | sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion); |
||
113 | meas_data->Draw(rdc, rdcsel); |
||
114 | |||
115 | sprintf(rdc, "ADC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);ADC;", j, evtheader.biasvolt, range[2], range[3]); |
||
116 | TH1F *histtemp = (TH1F*)gCanvas->GetPrimitive(histname); |
||
117 | if(!cleanPlots) |
||
118 | histtemp->SetTitle(rdc); |
||
119 | else |
||
120 | histtemp->SetTitle(";ADC;"); |
||
121 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
122 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
123 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
124 | if(cleanPlots) |
||
125 | { |
||
126 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
127 | yax->SetMaxDigits(4); |
||
128 | } |
||
129 | |||
130 | gCanvas->Modified(); |
||
131 | gCanvas->Update(); |
||
132 | |||
133 | if( yRange->widgetNE[0]->GetNumber() != yRange->widgetNE[1]->GetNumber() ) |
||
134 | { |
||
135 | if( (histOpt->widgetChBox[0]->IsDown()) && (yRange->widgetNE[0]->GetNumber() <= 0) ) |
||
136 | { |
||
137 | histtemp->GetYaxis()->SetRangeUser(0.5, yRange->widgetNE[1]->GetNumber()); |
||
138 | yRange->widgetNE[0]->SetNumber(0.5); |
||
139 | logChange = 1; |
||
140 | } |
||
141 | else |
||
142 | { |
||
143 | gCanvas->SetLogy(kFALSE); |
||
144 | if(logChange == 1) |
||
145 | { |
||
146 | yRange->widgetNE[0]->SetNumber(0.0); |
||
147 | logChange = 0; |
||
148 | } |
||
149 | histtemp->GetYaxis()->SetRangeUser(yRange->widgetNE[0]->GetNumber(), yRange->widgetNE[1]->GetNumber()); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
154 | if(!cleanPlots) |
||
155 | { |
||
156 | stats->SetX1NDC(0.84); stats->SetX2NDC(0.97); |
||
157 | stats->SetY1NDC(0.87); stats->SetY2NDC(0.97); |
||
158 | } |
||
159 | else |
||
160 | { |
||
161 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
162 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
163 | } |
||
164 | } |
||
165 | // TDC histogram |
||
166 | else if(histtype == 1) |
||
167 | { |
||
168 | if( range[0] == range[1] ) |
||
169 | sprintf(rdc, "(TDC%d/%lf)>>%s", j, tdctimeconversion, histname); |
||
170 | else |
||
171 | sprintf(rdc, "(TDC%d/%lf)>>%s(%d,%lf,%lf)", j, tdctimeconversion, histname, (int)((range[3]-range[2])*tdctimeconversion), range[2], range[3]); |
||
172 | |||
173 | sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion); |
||
174 | meas_data->Draw(rdc, rdcsel); |
||
175 | |||
176 | sprintf(rdc, "TDC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);Time (TDC channel) [ns];", j, evtheader.biasvolt, range[2], range[3]); |
||
177 | TH1F *histtemp = (TH1F*)gCanvas->GetPrimitive(histname); |
||
178 | if(!cleanPlots) |
||
179 | histtemp->SetTitle(rdc); |
||
180 | else |
||
181 | histtemp->SetTitle(";Time (TDC channel) [ns];"); |
||
182 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
183 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
184 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
185 | if(cleanPlots) |
||
186 | { |
||
187 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
188 | yax->SetMaxDigits(4); |
||
189 | } |
||
190 | |||
191 | gCanvas->Modified(); |
||
192 | gCanvas->Update(); |
||
193 | |||
194 | if( yRange->widgetNE[0]->GetNumber() != yRange->widgetNE[1]->GetNumber() ) |
||
195 | { |
||
196 | if( (histOpt->widgetChBox[0]->IsDown()) && (yRange->widgetNE[0]->GetNumber() <= 0) ) |
||
197 | { |
||
198 | histtemp->GetYaxis()->SetRangeUser(0.5, yRange->widgetNE[1]->GetNumber()); |
||
199 | yRange->widgetNE[0]->SetNumber(0.5); |
||
200 | logChange = 1; |
||
201 | } |
||
202 | else |
||
203 | { |
||
204 | gCanvas->SetLogy(kFALSE); |
||
205 | if(logChange == 1) |
||
206 | { |
||
207 | yRange->widgetNE[0]->SetNumber(0.0); |
||
208 | logChange = 0; |
||
209 | } |
||
210 | histtemp->GetYaxis()->SetRangeUser(yRange->widgetNE[0]->GetNumber(), yRange->widgetNE[1]->GetNumber()); |
||
211 | } |
||
212 | } |
||
213 | |||
214 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
215 | if(!cleanPlots) |
||
216 | { |
||
217 | stats->SetX1NDC(0.84); stats->SetX2NDC(0.97); |
||
218 | stats->SetY1NDC(0.87); stats->SetY2NDC(0.97); |
||
219 | } |
||
220 | else |
||
221 | { |
||
222 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
223 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
224 | } |
||
225 | } |
||
226 | // ADC vs. TDC histogram |
||
227 | else if(histtype == 2) |
||
228 | { |
||
229 | if( ((range[0] == range[1]) && (range[2] == range[3])) || (range[2] == range[3]) || (range[0] == range[1]) ) |
||
230 | sprintf(rdc, "(TDC%d/%lf):ADC%d>>%s", j, tdctimeconversion, j, histname); |
||
231 | else |
||
232 | sprintf(rdc, "(TDC%d/%lf):ADC%d>>%s(%d,%lf,%lf,%d,%lf,%lf)", j, tdctimeconversion, j, histname, (int)(range[1]-range[0])/2, range[0]-0.5, range[1]-0.5, (int)((range[3]-range[2])*tdctimeconversion)/2, range[2], range[3]); |
||
233 | meas_data->Draw(rdc,"","COLZ"); |
||
234 | |||
235 | sprintf(rdc, "ADC/TDC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);ADC;TDC", j, evtheader.biasvolt, range[2], range[3]); |
||
236 | TH2F *histtemp = (TH2F*)gCanvas->GetPrimitive(histname); |
||
237 | if(!cleanPlots) |
||
238 | histtemp->SetTitle(rdc); |
||
239 | else |
||
240 | histtemp->SetTitle(";ADC;Time (TDC channel) [ns]"); |
||
241 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
242 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
243 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
244 | histtemp->GetYaxis()->CenterTitle(kTRUE); |
||
245 | histtemp->GetYaxis()->SetTitleOffset(1.35); |
||
246 | if(cleanPlots) |
||
247 | { |
||
248 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
249 | yax->SetMaxDigits(4); |
||
250 | } |
||
251 | |||
252 | gCanvas->Modified(); |
||
253 | gCanvas->Update(); |
||
254 | |||
255 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
256 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
257 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
258 | |||
259 | TPaletteAxis *gpalette = (TPaletteAxis*)histtemp->GetListOfFunctions()->FindObject("palette"); |
||
260 | gpalette->SetLabelSize(0.022); |
||
261 | } |
||
262 | |||
263 | if(histtype < 2) |
||
264 | { |
||
265 | if( histOpt->widgetChBox[0]->IsDown() ) |
||
266 | gCanvas->SetLogy(kTRUE); |
||
267 | else if( !histOpt->widgetChBox[0]->IsDown() ) |
||
268 | gCanvas->SetLogy(kFALSE); |
||
269 | } |
||
270 | else |
||
271 | gCanvas->SetLogy(kFALSE); |
||
272 | |||
273 | gCanvas->Modified(); |
||
274 | gCanvas->Update(); |
||
275 | |||
276 | delete header_data; |
||
277 | delete meas_data; |
||
278 | |||
279 | // Delete the opened file when we just display it in the analysis canvas (otherwise wait for histogram save) |
||
280 | if(opt != 1) |
||
281 | delete inroot; |
||
282 | |||
283 | // If you close the opened file (delete inroot), the data can not be accessed by other functions (any time we wish to use the data directly from histogram, we need to call the DisplayHistogram function -> using different opt to determine what we need to do) |
||
284 | } |
||
285 | |||
286 | // Start a measurement (acquisition from CAMAC) |
||
287 | void TGAppMainFrame::RunMeas(void *ptr, int runCase, int &scanon) |
||
288 | { |
||
289 | int vscan = 0, pscan = 0, zscan = 0, ascan = 0; |
||
290 | if(scansOn->widgetChBox[0]->IsDown()) vscan = 1; |
||
291 | if(scansOn->widgetChBox[1]->IsDown()) pscan = 1; |
||
292 | if(scansOn->widgetChBox[2]->IsDown()) zscan = 1; |
||
293 | if(scansOn->widgetChBox[3]->IsDown()) ascan = 1; |
||
294 | |||
295 | printf("Start of Run, run case %d\n", runCase); |
||
296 | |||
297 | float progVal; |
||
298 | |||
299 | char ctemp[256]; |
||
300 | char ctemp2[256]; |
||
301 | char fname[256]; |
||
302 | int itemp = 0; |
||
303 | TH1F *liveHist; |
||
304 | |||
305 | float minVoltage, maxVoltage, stepVoltage, diffVoltage; |
||
306 | float minXpos, maxXpos, stepXpos, diffXpos; |
||
307 | float minYpos, maxYpos, stepYpos, diffYpos; |
||
308 | float minZpos, maxZpos, stepZpos, diffZpos; |
||
309 | float minAlpha, maxAlpha, stepAlpha, diffAlpha; |
||
310 | |||
311 | minVoltage = vOutStart->widgetNE[0]->GetNumber(); |
||
312 | maxVoltage = vOutStop->widgetNE[0]->GetNumber(); |
||
313 | diffVoltage = abs(maxVoltage - minVoltage); |
||
314 | stepVoltage = abs(vOutStep->widgetNE[0]->GetNumber()); |
||
315 | minXpos = xPosMin->widgetNE[0]->GetNumber(); |
||
316 | maxXpos = xPosMax->widgetNE[0]->GetNumber(); |
||
317 | diffXpos = abs(maxXpos - minXpos); |
||
318 | stepXpos = abs(xPosStep->widgetNE[0]->GetNumber()); |
||
319 | minYpos = yPosMin->widgetNE[0]->GetNumber(); |
||
320 | maxYpos = yPosMax->widgetNE[0]->GetNumber(); |
||
321 | diffYpos = abs(maxYpos - minYpos); |
||
322 | stepYpos = abs(yPosStep->widgetNE[0]->GetNumber()); |
||
323 | minZpos = zPosMin->widgetNE[0]->GetNumber(); |
||
324 | maxZpos = zPosMax->widgetNE[0]->GetNumber(); |
||
325 | diffZpos = abs(maxZpos - minZpos); |
||
326 | stepZpos = abs(zPosStep->widgetNE[0]->GetNumber()); |
||
327 | minAlpha = rotPosMin->widgetNE[0]->GetNumber(); |
||
328 | maxAlpha = rotPosMax->widgetNE[0]->GetNumber(); |
||
329 | diffAlpha = abs(maxAlpha - minAlpha); |
||
330 | stepAlpha = abs(rotPosStep->widgetNE[0]->GetNumber()); |
||
331 | |||
332 | remove_ext((char*)fileName->widgetTE->GetText(), ctemp); |
||
333 | |||
334 | // TODO - angle scan + voltage scan |
||
335 | // Voltage or surface scan |
||
336 | if( vscan || pscan || ascan ) |
||
337 | { |
||
338 | // No Z scan, No angle scan |
||
339 | if(!zscan && !ascan) |
||
340 | { |
||
341 | // When we have a voltage scan |
||
342 | if( vscan && (stepVoltage > 0.) ) |
||
343 | SeqNumber(runCase, (int)diffVoltage/stepVoltage, ctemp2); |
||
344 | // With only a surface scan |
||
345 | else if(pscan) |
||
346 | { |
||
347 | if( stepXpos == 0 ) |
||
348 | itemp = 1; |
||
349 | else |
||
350 | itemp = (int)diffXpos/stepXpos; |
||
351 | |||
352 | if( stepYpos == 0 ) |
||
353 | itemp *= 1; |
||
354 | else |
||
355 | itemp *= (int)diffYpos/stepYpos; |
||
356 | SeqNumber(runCase, itemp, ctemp2); |
||
357 | } |
||
358 | sprintf(fname, "%s_%s%s", ctemp, ctemp2, histext); |
||
359 | } |
||
360 | // With Z scan, No angle scan |
||
361 | else if(zscan && !ascan) |
||
362 | { |
||
363 | SeqNumber((int)zPos->widgetNE[0]->GetNumber(), maxZpos, ctemp2); |
||
364 | |||
365 | // Voltage scan is on |
||
366 | if( vscan && (stepVoltage > 0.) ) |
||
367 | { |
||
368 | sprintf(fname, "%s_z%s_", ctemp, ctemp2); |
||
369 | SeqNumber(runCase, (int)diffVoltage/stepVoltage+1, ctemp2); |
||
370 | strcat(fname, ctemp2); |
||
371 | strcat(fname, histext); |
||
372 | } |
||
373 | // Surface scan is on |
||
374 | else if(pscan) |
||
375 | { |
||
376 | sprintf(fname, "%s_z%s_", ctemp, ctemp2); |
||
377 | |||
378 | if( stepXpos == 0 ) |
||
379 | itemp = 1; |
||
380 | else |
||
381 | itemp = (int)diffXpos/stepXpos+1; |
||
382 | |||
383 | if( stepYpos == 0 ) |
||
384 | itemp *= 1; |
||
385 | else |
||
386 | itemp *= (int)diffYpos/stepYpos+1; |
||
387 | SeqNumber(runCase, itemp, ctemp2); |
||
388 | strcat(fname, ctemp2); |
||
389 | strcat(fname, histext); |
||
390 | } |
||
391 | // Just Z scan |
||
392 | else |
||
393 | sprintf(fname, "%s_z%s%s", ctemp, ctemp2, histext); |
||
394 | } |
||
395 | // No Z scan, With angle scan |
||
396 | else if(!zscan && ascan) |
||
397 | { |
||
398 | SeqNumber(runCase, (int)diffAlpha/stepAlpha, ctemp2); |
||
399 | |||
400 | // Voltage scan is on |
||
401 | if( vscan && (stepVoltage > 0.) ) |
||
402 | { |
||
403 | sprintf(fname, "%s_phi%s_", ctemp, ctemp2); |
||
404 | SeqNumber(runCase, (int)diffVoltage/stepVoltage+1, ctemp2); |
||
405 | strcat(fname, ctemp2); |
||
406 | strcat(fname, histext); |
||
407 | } |
||
408 | // Just angle scan |
||
409 | else |
||
410 | sprintf(fname, "%s_phi%s%s", ctemp, ctemp2, histext); |
||
411 | } |
||
412 | } |
||
413 | // All the rest |
||
414 | else if(!vscan && !pscan) |
||
415 | sprintf(fname, "%s%s", ctemp, histext); |
||
416 | |||
417 | // Check if set voltage is below the hard limit |
||
418 | if( vOut->widgetNE[0]->GetNumber() > vHardlimit->widgetNE[0]->GetNumber() ) |
||
419 | { |
||
420 | printf("Voltage hard limit triggered (%lf > %lf)!\n", vOut->widgetNE[0]->GetNumber(), vHardlimit->widgetNE[0]->GetNumber() ); |
||
421 | vOut->widgetNE[0]->SetNumber( vHardlimit->widgetNE[0]->GetNumber() ); |
||
422 | } |
||
423 | |||
424 | printf("Output file is (runCase = %d): %s\n", runCase, fname); |
||
425 | |||
426 | // Writing to output file |
||
427 | outroot = TFile::Open(fname, "RECREATE"); |
||
428 | |||
429 | TTree *header_data = new TTree("header_data", "Header information for the measurement."); |
||
430 | TTree *meas_data = new TTree("meas_data", "Saved ADC and TDC measurement data."); |
||
431 | TTree *scope_data = new TTree("scope_data", "Saved scope measurement data."); |
||
432 | |||
433 | // Branches for the header |
||
434 | header_data->Branch("nrch", &evtheader.nrch, "nrch/I"); |
||
435 | header_data->Branch("timestamp", &evtheader.timestamp, "timestamp/I"); |
||
436 | header_data->Branch("biasvolt", &evtheader.biasvolt, "biasvolt/D"); |
||
437 | header_data->Branch("xpos", &evtheader.xpos, "xpos/I"); |
||
438 | header_data->Branch("ypos", &evtheader.ypos, "ypos/I"); |
||
439 | header_data->Branch("zpos", &evtheader.zpos, "zpos/I"); |
||
440 | header_data->Branch("temperature", &evtheader.temperature, "temperature/D"); |
||
441 | header_data->Branch("angle", &evtheader.angle, "angle/D"); |
||
442 | header_data->Branch("laserinfo", &evtheader.laserinfo, "laserinfo/C"); |
||
443 | |||
444 | evtheader.nrch = (int)NCH->widgetNE[0]->GetNumber()*2; |
||
445 | evtheader.timestamp = (int)time(NULL); |
||
446 | evtheader.biasvolt = (double)vOut->widgetNE[0]->GetNumber(); |
||
447 | if(posUnits->widgetCB->GetSelected() == 0) |
||
448 | { |
||
449 | evtheader.xpos = (int)xPos->widgetNE[0]->GetNumber(); |
||
450 | evtheader.ypos = (int)yPos->widgetNE[0]->GetNumber(); |
||
451 | evtheader.zpos = (int)zPos->widgetNE[0]->GetNumber(); |
||
452 | } |
||
453 | else if(posUnits->widgetCB->GetSelected() == 1) |
||
454 | { |
||
455 | evtheader.xpos = (int)xPos->widgetNE[0]->GetNumber()/lenconversion; |
||
456 | evtheader.ypos = (int)yPos->widgetNE[0]->GetNumber()/lenconversion; |
||
457 | evtheader.zpos = (int)zPos->widgetNE[0]->GetNumber()/lenconversion; |
||
458 | } |
||
459 | evtheader.temperature = (double)chtemp->widgetNE[0]->GetNumber(); |
||
460 | if(rotUnits->widgetCB->GetSelected() == 0) |
||
461 | evtheader.angle = (double)rotPos->widgetNE[0]->GetNumber()*rotconversion; |
||
462 | else if(rotUnits->widgetCB->GetSelected() == 1) |
||
463 | evtheader.angle = (double)rotPos->widgetNE[0]->GetNumber(); |
||
464 | sprintf(evtheader.laserinfo, "%s", laserInfo->widgetTE->GetText()); |
||
465 | |||
466 | char histtime[256]; |
||
467 | GetTime(evtheader.timestamp, histtime); |
||
468 | |||
469 | printf("Save file header information:\n"); |
||
470 | printf("- Number of channels: %d\n", evtheader.nrch); |
||
471 | printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime); |
||
472 | printf("- Bias voltage: %lf\n", evtheader.biasvolt); |
||
473 | printf("- Table position (X,Y,Z): %d, %d, %d\n", evtheader.xpos, evtheader.ypos, evtheader.zpos); |
||
474 | printf("- Temperature: %lf\n", evtheader.temperature); |
||
475 | printf("- Incidence angle: %lf\n", evtheader.angle); |
||
476 | printf("- Laser and filter settings: %s\n", evtheader.laserinfo); |
||
477 | |||
478 | header_data->Fill(); |
||
479 | |||
480 | // Branches for ADC and TDC data |
||
481 | for(int i = 0; i < evtheader.nrch/2; i++) |
||
482 | { |
||
483 | sprintf(ctemp, "ADC%d", i); |
||
484 | sprintf(fname, "ADC%d/I", i); |
||
485 | meas_data->Branch(ctemp, &evtdata.adcdata[i], fname); |
||
486 | |||
487 | sprintf(ctemp, "TDC%d", i); |
||
488 | sprintf(fname, "TDC%d/I", i); |
||
489 | meas_data->Branch(ctemp, &evtdata.tdcdata[i], fname); |
||
490 | } |
||
491 | |||
492 | //TODO |
||
493 | // Initialize the scope before measurement |
||
494 | /* if( sCamaclink->IsDown() ) |
||
495 | InitializeScope();*/ |
||
496 | |||
497 | // Branch for scope measurement data |
||
498 | /* if(gScopeDaq->scopeUseType == 2) // only if we select waveform measurement |
||
499 | { |
||
500 | if(gScopeDaq->scopeMeasSel == 0) |
||
501 | scope_data->Branch("amp", &evtmeas.measdata, "amp/D"); |
||
502 | else if(gScopeDaq->scopeMeasSel == 1) |
||
503 | scope_data->Branch("area", &evtmeas.measdata, "area/D"); |
||
504 | else if(gScopeDaq->scopeMeasSel == 2) |
||
505 | scope_data->Branch("delay", &evtmeas.measdata, "delay/D"); |
||
506 | else if(gScopeDaq->scopeMeasSel == 3) |
||
507 | scope_data->Branch("fall", &evtmeas.measdata, "fall/D"); |
||
508 | else if(gScopeDaq->scopeMeasSel == 4) |
||
509 | scope_data->Branch("freq", &evtmeas.measdata, "freq/D"); |
||
510 | else if(gScopeDaq->scopeMeasSel == 5) |
||
511 | scope_data->Branch("max", &evtmeas.measdata, "max/D"); |
||
512 | else if(gScopeDaq->scopeMeasSel == 6) |
||
513 | scope_data->Branch("mean", &evtmeas.measdata, "mean/D"); |
||
514 | else if(gScopeDaq->scopeMeasSel == 7) |
||
515 | scope_data->Branch("min", &evtmeas.measdata, "min/D"); |
||
516 | else if(gScopeDaq->scopeMeasSel == 8) |
||
517 | scope_data->Branch("pk2p", &evtmeas.measdata, "pk2p/D"); |
||
518 | else if(gScopeDaq->scopeMeasSel == 9) |
||
519 | scope_data->Branch("pwidth", &evtmeas.measdata, "pwidth/D"); |
||
520 | else if(gScopeDaq->scopeMeasSel == 10) |
||
521 | scope_data->Branch("rise", &evtmeas.measdata, "rise/D"); |
||
522 | }*/ |
||
523 | |||
524 | int neve = (int) evtNum->widgetNE[0]->GetNumber(); |
||
525 | int allEvt, zProg; |
||
526 | zProg = 1; |
||
527 | |||
528 | #if WORKSTAT == 'I' |
||
529 | #else |
||
530 | // ONLY FOR TESTING! |
||
531 | TRandom *randNum = new TRandom(); |
||
532 | randNum->SetSeed(0); |
||
533 | // ONLY FOR TESTING! |
||
534 | #endif |
||
535 | |||
536 | // Initialize the CAMAC |
||
537 | if (gDaq) |
||
538 | { |
||
539 | if(scanon == 0) |
||
540 | { |
||
541 | gDaq->init(evtheader.nrch); |
||
542 | scanon = 1; |
||
543 | } |
||
544 | gDaq->fStop=0; |
||
545 | |||
546 | // Set the stopwatch |
||
547 | clock_t clkt1; |
||
548 | |||
549 | // Prepare histogram for live histogram update |
||
550 | int liven; |
||
551 | TCanvas *gCanvas; |
||
552 | if(liveUpdate && (!vscan && !pscan && !zscan && !ascan)) |
||
553 | { |
||
554 | gCanvas = measCanvas->GetCanvas(); |
||
555 | gCanvas->SetGrid(); |
||
556 | gCanvas->cd(); |
||
557 | liveHist = new TH1F(histname,"",(int)TMath::Sqrt(neve),0,0); |
||
558 | liven = 1; |
||
559 | } |
||
560 | |||
561 | // Start gathering |
||
562 | gDaq->start(); |
||
563 | |||
564 | for (int n=0;n<neve && !gDaq->fStop ;/*n++*/) |
||
565 | { |
||
566 | int nb = gDaq->event(gBuf,BSIZE); |
||
567 | |||
568 | #if WORKSTAT == 'I' |
||
569 | #else |
||
570 | // ONLY FOR TESTING! |
||
571 | for(int i=0; i < evtheader.nrch; i++) |
||
572 | { |
||
573 | if(i == 1) |
||
574 | gBuf[i] = randNum->Gaus(1500,300); |
||
575 | else if(i == 0) |
||
576 | gBuf[i] = randNum->Poisson(2500); |
||
577 | } |
||
578 | // ONLY FOR TESTING! |
||
579 | #endif |
||
580 | if (nb<=0) n--; |
||
581 | |||
582 | int nc=0; |
||
583 | |||
584 | while ( (nb>0) && (n<neve) ) |
||
585 | { |
||
586 | for(int i = 0; i < evtheader.nrch; i++) |
||
587 | { |
||
588 | unsigned short adc = gBuf[i+nc]&0xFFFF; |
||
589 | if(i % 2 == 0) // TDC |
||
590 | evtdata.tdcdata[i/2] = (int)adc; |
||
591 | else if(i % 2 == 1) // ADC |
||
592 | evtdata.adcdata[i/2] = (int)adc; |
||
593 | |||
594 | // Start plotting the scope waveform |
||
595 | /* if( (gScopeDaq->scopeUseType == 1) && (sCamaclink->IsDown()) ) |
||
596 | StartScopeAcq();*/ // TODO |
||
597 | } |
||
598 | meas_data->Fill(); |
||
599 | n++; |
||
600 | sleep(1); |
||
601 | |||
602 | // Start making a scope measurement |
||
603 | /* if( (gScopeDaq->scopeUseType == 2) && (sCamaclink->IsDown()) ) |
||
604 | { |
||
605 | StartScopeAcq(); |
||
606 | evtmeas.measdata = gScopeDaq->measubuf; |
||
607 | } |
||
608 | scope_data->Fill();*/ // TODO |
||
609 | |||
610 | // Start filling the histogram (only in normal single scan) |
||
611 | if(liveUpdate && (!vscan && !pscan && !zscan && !ascan)) |
||
612 | { |
||
613 | liveHist->Fill(evtdata.adcdata[0]); |
||
614 | if( n == (neve*liven)/10 ) |
||
615 | { |
||
616 | gCanvas->cd(); |
||
617 | liveHist->Draw(""); |
||
618 | gCanvas->Modified(); |
||
619 | gCanvas->Update(); |
||
620 | liven++; |
||
621 | } |
||
622 | } |
||
623 | |||
624 | nc += evtheader.nrch; |
||
625 | nb -= evtheader.nrch; |
||
626 | } |
||
627 | |||
628 | MyTimer(); |
||
629 | allEvt = n; |
||
630 | if (gSystem->ProcessEvents()) printf("Run Interrupted\n"); |
||
631 | |||
632 | if( acqStarted && (n == (neve*zProg)/10) && (!vscan && !pscan && !zscan && !ascan) ) |
||
633 | { |
||
634 | // Progress the progress bar |
||
635 | progVal = (float)zProg*10; |
||
636 | measProgress->widgetPB->SetPosition(progVal); |
||
637 | |||
638 | // Calculate the remaining time |
||
639 | TimeEstimate(clkt0, timet0, progVal, ctemp, 0); |
||
640 | printf("End time: %s\n", ctemp); |
||
641 | measProgress->widgetTE->SetText(ctemp); |
||
642 | |||
643 | gVirtualX->Update(1); |
||
644 | zProg++; |
||
645 | } |
||
646 | } |
||
647 | |||
648 | printf("Number of gathered events: %d\n", allEvt); |
||
649 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
650 | acqStarted = false; |
||
651 | |||
652 | gDaq->stop(); |
||
653 | } |
||
654 | |||
655 | printf("End of Run neve=%d\n",neve); |
||
656 | |||
657 | header_data->Write(); |
||
658 | meas_data->Write(); |
||
659 | // scope_data->Write(); // TODO |
||
660 | delete header_data; |
||
661 | delete meas_data; |
||
662 | delete scope_data; |
||
663 | |||
664 | // Remove the histogram |
||
665 | if(liveUpdate && (!vscan && !pscan && !zscan && !ascan)) |
||
666 | delete liveHist; |
||
667 | |||
668 | |||
669 | outroot->Close(); |
||
670 | } |
||
671 | |||
672 | int TGAppMainFrame::MyTimer() |
||
673 | { |
||
674 | char cmd[100]; |
||
675 | GetTime(-1, cmd); |
||
676 | if (timeStamp) timeStamp->widgetTE->SetText(cmd); |
||
677 | return 0; |
||
678 | } |
||
679 | |||
680 | // Additional functions ------------------------------------- |
||
681 | |||
682 | // Settings pane connections -------------------------------- |
||
683 | |||
684 | // Enable or disable scans |
||
685 | void TGAppMainFrame::EnableScan(int type) |
||
686 | { |
||
687 | // Voltage scan |
||
688 | if(type == 0) |
||
689 | { |
||
690 | if(scansOn->widgetChBox[type]->IsOn()) |
||
691 | { |
||
692 | vOutStart->widgetNE[0]->SetState(kTRUE); |
||
693 | vOutStop->widgetNE[0]->SetState(kTRUE); |
||
694 | vOutStep->widgetNE[0]->SetState(kTRUE); |
||
695 | } |
||
696 | else |
||
697 | { |
||
698 | vOutStart->widgetNE[0]->SetState(kFALSE); |
||
699 | vOutStop->widgetNE[0]->SetState(kFALSE); |
||
700 | vOutStep->widgetNE[0]->SetState(kFALSE); |
||
701 | } |
||
702 | } |
||
703 | // Surface (X, Y axis) scan |
||
704 | else if(type == 1) |
||
705 | { |
||
706 | if(scansOn->widgetChBox[type]->IsOn()) |
||
707 | { |
||
708 | xPosMin->widgetNE[0]->SetState(kTRUE); |
||
709 | xPosMax->widgetNE[0]->SetState(kTRUE); |
||
710 | xPosStep->widgetNE[0]->SetState(kTRUE); |
||
711 | yPosMin->widgetNE[0]->SetState(kTRUE); |
||
712 | yPosMax->widgetNE[0]->SetState(kTRUE); |
||
713 | yPosStep->widgetNE[0]->SetState(kTRUE); |
||
714 | } |
||
715 | else |
||
716 | { |
||
717 | xPosMin->widgetNE[0]->SetState(kFALSE); |
||
718 | xPosMax->widgetNE[0]->SetState(kFALSE); |
||
719 | xPosStep->widgetNE[0]->SetState(kFALSE); |
||
720 | yPosMin->widgetNE[0]->SetState(kFALSE); |
||
721 | yPosMax->widgetNE[0]->SetState(kFALSE); |
||
722 | yPosStep->widgetNE[0]->SetState(kFALSE); |
||
723 | } |
||
724 | } |
||
725 | // Z axis scan |
||
726 | else if(type == 2) |
||
727 | { |
||
728 | if(scansOn->widgetChBox[type]->IsOn()) |
||
729 | { |
||
730 | zPosMin->widgetNE[0]->SetState(kTRUE); |
||
731 | zPosMax->widgetNE[0]->SetState(kTRUE); |
||
732 | zPosStep->widgetNE[0]->SetState(kTRUE); |
||
733 | } |
||
734 | else |
||
735 | { |
||
736 | zPosMin->widgetNE[0]->SetState(kFALSE); |
||
737 | zPosMax->widgetNE[0]->SetState(kFALSE); |
||
738 | zPosStep->widgetNE[0]->SetState(kFALSE); |
||
739 | } |
||
740 | } |
||
741 | // Incidence angle scan |
||
742 | else if(type == 3) |
||
743 | { |
||
744 | if(scansOn->widgetChBox[type]->IsOn()) |
||
745 | { |
||
746 | rotPosMin->widgetNE[0]->SetState(kTRUE); |
||
747 | rotPosMax->widgetNE[0]->SetState(kTRUE); |
||
748 | rotPosStep->widgetNE[0]->SetState(kTRUE); |
||
749 | } |
||
750 | else |
||
751 | { |
||
752 | rotPosMin->widgetNE[0]->SetState(kFALSE); |
||
753 | rotPosMax->widgetNE[0]->SetState(kFALSE); |
||
754 | rotPosStep->widgetNE[0]->SetState(kFALSE); |
||
755 | } |
||
756 | } |
||
757 | } |
||
758 | |||
759 | // Apply the upper voltage limit from settings pane to main window |
||
760 | void TGAppMainFrame::VoltageLimit() |
||
761 | { |
||
762 | vOut->widgetNE[0]->SetLimitValues(0, vHardlimit->widgetNE[0]->GetNumber() ); |
||
763 | } |
||
764 | |||
765 | // Select the table position units to be used (1 = 0.3595 micron) |
||
766 | void TGAppMainFrame::ChangeUnits(int type) |
||
767 | { |
||
768 | int pos[12], poslim[3], chng = 0; |
||
769 | double micro[12], microlim[3]; |
||
770 | |||
771 | TGNumberEntry *posEntries[12]; |
||
772 | posEntries[0] = (TGNumberEntry*)xPos->widgetNE[0]; |
||
773 | posEntries[1] = (TGNumberEntry*)yPos->widgetNE[0]; |
||
774 | posEntries[2] = (TGNumberEntry*)zPos->widgetNE[0]; |
||
775 | posEntries[3] = (TGNumberEntry*)xPosMin->widgetNE[0]; |
||
776 | posEntries[4] = (TGNumberEntry*)xPosMax->widgetNE[0]; |
||
777 | posEntries[5] = (TGNumberEntry*)xPosStep->widgetNE[0]; |
||
778 | posEntries[6] = (TGNumberEntry*)yPosMin->widgetNE[0]; |
||
779 | posEntries[7] = (TGNumberEntry*)yPosMax->widgetNE[0]; |
||
780 | posEntries[8] = (TGNumberEntry*)yPosStep->widgetNE[0]; |
||
781 | posEntries[9] = (TGNumberEntry*)zPosMin->widgetNE[0]; |
||
782 | posEntries[10] = (TGNumberEntry*)zPosMax->widgetNE[0]; |
||
783 | posEntries[11] = (TGNumberEntry*)zPosStep->widgetNE[0]; |
||
784 | |||
785 | // Table position values |
||
786 | if(type == 0) |
||
787 | { |
||
788 | // Check if we had microns before |
||
789 | if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo) |
||
790 | chng = 1; |
||
791 | |||
792 | // Change to table position values |
||
793 | if(chng == 1) |
||
794 | { |
||
795 | for(int i = 0; i < 12; i++) |
||
796 | { |
||
797 | if(posEntries[i]->GetNumber() == 0.0) |
||
798 | pos[i] = 0; |
||
799 | else |
||
800 | pos[i] = (int)posEntries[i]->GetNumber()/lenconversion; |
||
801 | } |
||
802 | |||
803 | poslim[0] = -100; |
||
804 | poslim[1] = 215000; |
||
805 | poslim[2] = 375000; |
||
806 | |||
807 | for(int i = 0; i < 12; i++) |
||
808 | { |
||
809 | posEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger); |
||
810 | if( (i > 8) || (i == 2) ) // limits for Z axis (longer table) |
||
811 | posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[2]); |
||
812 | else |
||
813 | posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[1]); |
||
814 | |||
815 | posEntries[i]->SetNumber(pos[i]); |
||
816 | } |
||
817 | } |
||
818 | } |
||
819 | // Microns |
||
820 | else if(type == 1) |
||
821 | { |
||
822 | // Check if we had table position values before |
||
823 | if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger) |
||
824 | chng = 1; |
||
825 | |||
826 | // Change to microns |
||
827 | if(chng == 1) |
||
828 | { |
||
829 | for(int i = 0; i < 12; i++) |
||
830 | { |
||
831 | if(posEntries[i]->GetNumber() == 0.0) |
||
832 | micro[i] = 0.; |
||
833 | else |
||
834 | micro[i] = (double)posEntries[i]->GetNumber()*lenconversion; |
||
835 | } |
||
836 | |||
837 | microlim[0] = (double)-100*lenconversion; |
||
838 | microlim[1] = (double)215000*lenconversion; |
||
839 | microlim[2] = (double)375000*lenconversion; |
||
840 | |||
841 | for(int i = 0; i < 12; i++) |
||
842 | { |
||
843 | posEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo); |
||
844 | if( (i > 8) || (i == 2) ) // limits for Z axis (longer table) |
||
845 | posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[2]); |
||
846 | else |
||
847 | posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[1]); |
||
848 | |||
849 | posEntries[i]->SetNumber(micro[i]); |
||
850 | } |
||
851 | } |
||
852 | } |
||
853 | } |
||
854 | |||
855 | // Select the rotation units to be used (1 = 6.3281/3600 degrees) |
||
856 | void TGAppMainFrame::ChangeUnitsRot(int type) |
||
857 | { |
||
858 | int rot[4], rotlim[2], chng = 0; |
||
859 | double deg[4], deglim[2]; |
||
860 | |||
861 | TGNumberEntry *rotEntries[4]; |
||
862 | rotEntries[0] = (TGNumberEntry*)rotPos->widgetNE[0]; |
||
863 | rotEntries[1] = (TGNumberEntry*)rotPosMin->widgetNE[0]; |
||
864 | rotEntries[2] = (TGNumberEntry*)rotPosMax->widgetNE[0]; |
||
865 | rotEntries[3] = (TGNumberEntry*)rotPosStep->widgetNE[0]; |
||
866 | |||
867 | // Rotation values |
||
868 | if(type == 0) |
||
869 | { |
||
870 | // Check if we had degrees before |
||
871 | if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo) |
||
872 | chng = 1; |
||
873 | |||
874 | // Change to rotation values |
||
875 | if(chng == 1) |
||
876 | { |
||
877 | for(int i = 0; i < 4; i++) |
||
878 | { |
||
879 | if(rotEntries[i]->GetNumber() == 0.0) |
||
880 | rot[i] = 0; |
||
881 | else |
||
882 | rot[i] = (int)rotEntries[i]->GetNumber()/rotconversion; |
||
883 | } |
||
884 | |||
885 | rotlim[0] = (int)-180/rotconversion; |
||
886 | rotlim[1] = (int)180/rotconversion; |
||
887 | |||
888 | for(int i = 0; i < 4; i++) |
||
889 | { |
||
890 | rotEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger); |
||
891 | rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, rotlim[0], rotlim[1]); |
||
892 | |||
893 | rotEntries[i]->SetNumber(rot[i]); |
||
894 | } |
||
895 | } |
||
896 | } |
||
897 | // Degree |
||
898 | else if(type == 1) |
||
899 | { |
||
900 | // Check if we had table position values before |
||
901 | if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger) |
||
902 | chng = 1; |
||
903 | |||
904 | // Change to degrees |
||
905 | if(chng == 1) |
||
906 | { |
||
907 | for(int i = 0; i < 4; i++) |
||
908 | { |
||
909 | if(rotEntries[i]->GetNumber() == 0) |
||
910 | deg[i] = 0.; |
||
911 | else |
||
912 | deg[i] = (double)rotEntries[i]->GetNumber()*rotconversion; |
||
913 | } |
||
914 | |||
915 | deglim[0] = -180.; |
||
916 | deglim[1] = 180.; |
||
917 | |||
918 | for(int i = 0; i < 4; i++) |
||
919 | { |
||
920 | rotEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo); |
||
921 | rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, deglim[0], deglim[1]); |
||
922 | |||
923 | rotEntries[i]->SetNumber(deg[i]); |
||
924 | } |
||
925 | } |
||
926 | } |
||
927 | } |
||
928 | |||
929 | // Enable display canvas to have a live update of histogram |
||
930 | void TGAppMainFrame::EnableLiveUpdate() |
||
931 | { |
||
932 | liveUpdate = liveDisp->widgetChBox[0]->IsDown(); |
||
933 | } |
||
934 | |||
935 | // Settings pane connections -------------------------------- |
||
936 | |||
937 | // Main measurement window connections ---------------------- |
||
938 | |||
939 | // Get the currently selected channel |
||
940 | int TGAppMainFrame::GetChannel() |
||
941 | { |
||
942 | int selectedOutput; |
||
943 | if(vOutCh->widgetCB->GetSelected() < 8) selectedOutput = (vOutCh->widgetCB->GetSelected())+1; |
||
944 | else if( (vOutCh->widgetCB->GetSelected() >= 8) && (vOutCh->widgetCB->GetSelected() < 16) ) selectedOutput = (vOutCh->widgetCB->GetSelected())+93; |
||
945 | else selectedOutput = 1; |
||
946 | |||
947 | return selectedOutput; |
||
948 | } |
||
949 | |||
950 | // Set, get or reset the output voltage |
||
951 | void TGAppMainFrame::VoltOut(int opt) |
||
952 | { |
||
953 | char cmd[256]; |
||
954 | |||
955 | // Set the selected voltage |
||
956 | if(opt == 0) |
||
957 | { |
||
958 | int outOn; |
||
959 | float outputVoltage; |
||
960 | |||
961 | outputVoltage = vOut->widgetNE[0]->GetNumber(); |
||
962 | |||
963 | if(vOutOpt->widgetChBox[1]->IsOn()) outOn = 1; |
||
964 | else outOn = 0; |
||
965 | |||
966 | fflush(stdout); |
||
967 | sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s %d", rootdir, GetChannel(), outputVoltage, outOn); |
||
968 | #if WORKSTAT == 'I' |
||
969 | retTemp = system(cmd); |
||
970 | #else |
||
971 | printf("Cmd: %s\n",cmd); |
||
972 | #endif |
||
973 | fflush(stdout); |
||
974 | } |
||
975 | // Get current voltage |
||
976 | else if(opt == 1) |
||
977 | { |
||
978 | fflush(stdout); |
||
979 | sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -g > %s/settings/curvolt.txt", rootdir, GetChannel(), rootdir); |
||
980 | #if WORKSTAT == 'I' |
||
981 | retTemp = system(cmd); |
||
982 | #else |
||
983 | printf("Cmd: %s\n",cmd); |
||
984 | #endif |
||
985 | fflush(stdout); |
||
986 | |||
987 | #if WORKSTAT == 'I' |
||
988 | FILE* fvolt; |
||
989 | double dtemp; |
||
990 | char ctemp[24]; |
||
991 | sprintf(cmd, "%s/settings/curvolt.txt", rootdir); |
||
992 | fvolt = fopen(cmd, "r"); |
||
993 | |||
994 | if(fvolt != NULL) |
||
995 | { |
||
996 | sprintf(cmd, "WIENER-CRATE-MIB::outputVoltage.u%d = Opaque: Float: %s V\n", GetChannel()-1, "%lf" ); |
||
997 | retTemp = fscanf(fvolt, cmd, &dtemp); |
||
998 | vOut->widgetNE[0]->SetNumber(dtemp); |
||
999 | sprintf(cmd, "WIENER-CRATE-MIB::outputSwitch.u%d = INTEGER: %s\n", GetChannel()-1, "%s" ); |
||
1000 | retTemp = fscanf(fvolt, cmd, ctemp); |
||
1001 | if( strcmp(ctemp, "On(1)") == 0 ) |
||
1002 | vOutOpt->widgetChBox[1]->SetState(kButtonDown); |
||
1003 | else if( strcmp(ctemp, "Off(0)") == 0 ) |
||
1004 | vOutOpt->widgetChBox[1]->SetState(kButtonUp); |
||
1005 | } |
||
1006 | |||
1007 | fclose(fvolt); |
||
1008 | #endif |
||
1009 | } |
||
1010 | // Reset output voltage (if stuck in interlock) |
||
1011 | else if(opt == 2) |
||
1012 | { |
||
1013 | vOut->widgetNE[0]->SetNumber(0.000); |
||
1014 | vOutOpt->widgetChBox[1]->SetState(kButtonUp); |
||
1015 | |||
1016 | fflush(stdout); |
||
1017 | sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -r %d", rootdir, GetChannel()); |
||
1018 | #if WORKSTAT == 'I' |
||
1019 | retTemp = system(cmd); |
||
1020 | #else |
||
1021 | printf("Cmd: %s\n",cmd); |
||
1022 | #endif |
||
1023 | fflush(stdout); |
||
1024 | } |
||
1025 | } |
||
1026 | |||
1027 | // Set output voltage polarity to negative |
||
1028 | void TGAppMainFrame::NegativePolarity() |
||
1029 | { |
||
1030 | double newHardlimit; |
||
1031 | int polar = 0; // 0 = positive, 1 = negative |
||
1032 | |||
1033 | if(vOutOpt->widgetChBox[0]->IsOn()) |
||
1034 | polar = 1; |
||
1035 | else |
||
1036 | polar = 0; |
||
1037 | |||
1038 | // Set hard limit to the negative version of what it was before |
||
1039 | if( (vHardlimit->widgetNE[0]->GetNumber() > 0.) && (polar == 1) ) |
||
1040 | newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber()); |
||
1041 | else if( (vHardlimit->widgetNE[0]->GetNumber() < 0.) && (polar == 0) ) |
||
1042 | newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber()); |
||
1043 | else if(vHardlimit->widgetNE[0]->GetNumber() == 0.) |
||
1044 | newHardlimit = 0.; |
||
1045 | else |
||
1046 | newHardlimit = vHardlimit->widgetNE[0]->GetNumber(); |
||
1047 | |||
1048 | // Apropriately set the limit to the output voltage number entry |
||
1049 | vHardlimit->widgetNE[0]->SetNumber(newHardlimit); |
||
1050 | |||
1051 | if(polar == 1) |
||
1052 | vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, newHardlimit, 0.); |
||
1053 | else if(polar == 0) |
||
1054 | vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, 0., newHardlimit); |
||
1055 | } |
||
1056 | |||
1057 | // Set, get, home or reset the table position |
||
1058 | void TGAppMainFrame::PositionSet(int opt) |
||
1059 | { |
||
1060 | char cmd[1024]; |
||
1061 | |||
1062 | // Set the selected table position |
||
1063 | if(opt == 0) |
||
1064 | { |
||
1065 | int positX, positY, positZ; |
||
1066 | |||
1067 | if(posUnits->widgetCB->GetSelected() == 0) |
||
1068 | { |
||
1069 | positX = xPos->widgetNE[0]->GetNumber(); |
||
1070 | positY = yPos->widgetNE[0]->GetNumber(); |
||
1071 | positZ = zPos->widgetNE[0]->GetNumber(); |
||
1072 | } |
||
1073 | else if(posUnits->widgetCB->GetSelected() == 1) |
||
1074 | { |
||
1075 | positX = (int)xPos->widgetNE[0]->GetNumber()/lenconversion; |
||
1076 | positY = (int)yPos->widgetNE[0]->GetNumber()/lenconversion; |
||
1077 | positZ = (int)zPos->widgetNE[0]->GetNumber()/lenconversion; |
||
1078 | } |
||
1079 | |||
1080 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, positX, rootdir); |
||
1081 | #if WORKSTAT == 'I' |
||
1082 | retTemp = system(cmd); |
||
1083 | #else |
||
1084 | printf("Cmd: %s\n",cmd); |
||
1085 | #endif |
||
1086 | |||
1087 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, positY, rootdir); |
||
1088 | #if WORKSTAT == 'I' |
||
1089 | retTemp = system(cmd); |
||
1090 | #else |
||
1091 | printf("Cmd: %s\n",cmd); |
||
1092 | #endif |
||
1093 | |||
1094 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, positZ, rootdir); |
||
1095 | #if WORKSTAT == 'I' |
||
1096 | retTemp = system(cmd); |
||
1097 | #else |
||
1098 | printf("Cmd: %s\n",cmd); |
||
1099 | #endif |
||
1100 | } |
||
1101 | // Get current table position |
||
1102 | else if(opt == 1) |
||
1103 | { |
||
1104 | fflush(stdout); |
||
1105 | |||
1106 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -p > %s/settings/curpos.txt", rootdir, rootdir); // X-axis |
||
1107 | fflush(stdout); |
||
1108 | #if WORKSTAT == 'I' |
||
1109 | retTemp = system(cmd); |
||
1110 | #else |
||
1111 | printf("Cmd: %s\n",cmd); |
||
1112 | #endif |
||
1113 | |||
1114 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Y-axis |
||
1115 | fflush(stdout); |
||
1116 | #if WORKSTAT == 'I' |
||
1117 | retTemp = system(cmd); |
||
1118 | #else |
||
1119 | printf("Cmd: %s\n",cmd); |
||
1120 | #endif |
||
1121 | |||
1122 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Z-axis |
||
1123 | fflush(stdout); |
||
1124 | #if WORKSTAT == 'I' |
||
1125 | retTemp = system(cmd); |
||
1126 | #else |
||
1127 | printf("Cmd: %s\n",cmd); |
||
1128 | #endif |
||
1129 | |||
1130 | #if WORKSTAT == 'I' |
||
1131 | FILE* fpos; |
||
1132 | int itemp; |
||
1133 | sprintf(cmd, "%s/settings/curpos.txt", rootdir); |
||
1134 | fpos = fopen(cmd, "r"); |
||
1135 | |||
1136 | if(fpos != NULL) |
||
1137 | { |
||
1138 | if(posUnits->widgetCB->GetSelected() == 0) |
||
1139 | { |
||
1140 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1141 | xPos->widgetNE[0]->SetNumber(itemp); |
||
1142 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1143 | yPos->widgetNE[0]->SetNumber(itemp); |
||
1144 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1145 | zPos->widgetNE[0]->SetNumber(itemp); |
||
1146 | } |
||
1147 | else if(posUnits->widgetCB->GetSelected() == 1) |
||
1148 | { |
||
1149 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1150 | xPos->widgetNE[0]->SetNumber((double)itemp*lenconversion); |
||
1151 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1152 | yPos->widgetNE[0]->SetNumber((double)itemp*lenconversion); |
||
1153 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1154 | zPos->widgetNE[0]->SetNumber((double)itemp*lenconversion); |
||
1155 | } |
||
1156 | } |
||
1157 | |||
1158 | fclose(fpos); |
||
1159 | #endif |
||
1160 | } |
||
1161 | // Home the table position |
||
1162 | else if(opt == 2) |
||
1163 | { |
||
1164 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -h", rootdir); // X-axis |
||
1165 | #if WORKSTAT == 'I' |
||
1166 | retTemp = system(cmd); |
||
1167 | #else |
||
1168 | printf("Cmd: %s\n",cmd); |
||
1169 | #endif |
||
1170 | |||
1171 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -h", rootdir); // Y-axis |
||
1172 | #if WORKSTAT == 'I' |
||
1173 | retTemp = system(cmd); |
||
1174 | #else |
||
1175 | printf("Cmd: %s\n",cmd); |
||
1176 | #endif |
||
1177 | |||
1178 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -h", rootdir); // Z-axis |
||
1179 | #if WORKSTAT == 'I' |
||
1180 | retTemp = system(cmd); |
||
1181 | #else |
||
1182 | printf("Cmd: %s\n",cmd); |
||
1183 | #endif |
||
1184 | PositionSet(1); |
||
1185 | } |
||
1186 | // Reset the table position |
||
1187 | else if(opt == 3) |
||
1188 | { |
||
1189 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -r && sudo %s/src/MIKRO/mikro_ctrl -n 1 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 1 -h", rootdir, rootdir, rootdir); // X-axis |
||
1190 | #if WORKSTAT == 'I' |
||
1191 | printf("Positioning table reset, initialization and homing in progress. Please wait...\n"); |
||
1192 | retTemp = system(cmd); |
||
1193 | #else |
||
1194 | printf("Cmd: %s\n",cmd); |
||
1195 | #endif |
||
1196 | |||
1197 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -r && sudo %s/src/MIKRO/mikro_ctrl -n 2 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 2 -h", rootdir, rootdir, rootdir); // Y-axis |
||
1198 | #if WORKSTAT == 'I' |
||
1199 | retTemp = system(cmd); |
||
1200 | #else |
||
1201 | printf("Cmd: %s\n",cmd); |
||
1202 | #endif |
||
1203 | |||
1204 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -r && sudo %s/src/MIKRO/mikro_ctrl -n 3 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 3 -h", rootdir, rootdir, rootdir); // Z-axis |
||
1205 | #if WORKSTAT == 'I' |
||
1206 | retTemp = system(cmd); |
||
1207 | printf("Positioning table reset, initialization and homing complete.\n"); |
||
1208 | #else |
||
1209 | printf("Cmd: %s\n",cmd); |
||
1210 | #endif |
||
1211 | PositionSet(1); |
||
1212 | } |
||
1213 | } |
||
1214 | |||
1215 | // Set, get, home or reset the rotation platform |
||
1216 | void TGAppMainFrame::RotationSet(int opt) |
||
1217 | { |
||
1218 | char cmd[1024]; |
||
1219 | |||
1220 | // Set the selected rotation |
||
1221 | if(opt == 0) |
||
1222 | { |
||
1223 | int positAlpha; |
||
1224 | |||
1225 | if(rotUnits->widgetCB->GetSelected() == 0) |
||
1226 | positAlpha = rotPos->widgetNE[0]->GetNumber(); |
||
1227 | else if(rotUnits->widgetCB->GetSelected() == 1) |
||
1228 | positAlpha = rotPos->widgetNE[0]->GetNumber()/rotconversion; |
||
1229 | |||
1230 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, positAlpha, rootdir); |
||
1231 | #if WORKSTAT == 'I' |
||
1232 | retTemp = system(cmd); |
||
1233 | #else |
||
1234 | printf("Cmd: %s\n",cmd); |
||
1235 | #endif |
||
1236 | } |
||
1237 | // Get current rotation |
||
1238 | else if(opt == 1) |
||
1239 | { |
||
1240 | fflush(stdout); |
||
1241 | |||
1242 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -p > %s/settings/currot.txt", rootdir, rootdir); |
||
1243 | fflush(stdout); |
||
1244 | #if WORKSTAT == 'I' |
||
1245 | retTemp = system(cmd); |
||
1246 | #else |
||
1247 | printf("Cmd: %s\n",cmd); |
||
1248 | #endif |
||
1249 | |||
1250 | #if WORKSTAT == 'I' |
||
1251 | FILE* frot; |
||
1252 | int itemp; |
||
1253 | sprintf(cmd, "%s/settings/currot.txt", rootdir); |
||
1254 | frot = fopen(cmd, "r"); |
||
1255 | |||
1256 | if(frot != NULL) |
||
1257 | { |
||
1258 | retTemp = fscanf(frot, "%d\n", &itemp); |
||
1259 | if(rotUnits->widgetCB->GetSelected() == 0) |
||
1260 | rotPos->widgetNE[0]->SetNumber(itemp); |
||
1261 | else if(rotUnits->widgetCB->GetSelected() == 1) |
||
1262 | rotPos->widgetNE[0]->SetNumber((double)itemp*rotconversion); |
||
1263 | } |
||
1264 | |||
1265 | fclose(frot); |
||
1266 | #endif |
||
1267 | } |
||
1268 | // Home the rotation |
||
1269 | else if(opt == 2) |
||
1270 | { |
||
1271 | // TODO: For now only set back to 0, not home! |
||
1272 | // sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -h", rootdir); |
||
1273 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v 0 -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, rootdir); |
||
1274 | #if WORKSTAT == 'I' |
||
1275 | retTemp = system(cmd); |
||
1276 | #else |
||
1277 | printf("Cmd: %s\n",cmd); |
||
1278 | #endif |
||
1279 | RotationSet(1); |
||
1280 | } |
||
1281 | // Reset the rotation |
||
1282 | else if(opt == 3) |
||
1283 | { |
||
1284 | // TODO: For now only set back to 0, not home! |
||
1285 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -r && sudo %s/src/MIKRO/mikro_ctrl -n 4 -i 2 && sudo %s/src/MIKRO/mikro_ctrl -n 4 -h", rootdir, rootdir, rootdir); |
||
1286 | #if WORKSTAT == 'I' |
||
1287 | printf("Rotation platform reset, initalization and homing in progress. Please wait...\n"); |
||
1288 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v 0 -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, rootdir); |
||
1289 | retTemp = system(cmd); |
||
1290 | sleep(15); // wait for the motor to change position from wherever to 0 |
||
1291 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -r && sudo %s/src/MIKRO/mikro_ctrl -n 4 -i 2", rootdir, rootdir); |
||
1292 | retTemp = system(cmd); |
||
1293 | printf("Rotation platform reset, initalization and homing complete.\n"); |
||
1294 | #else |
||
1295 | printf("Cmd: %s\n",cmd); |
||
1296 | #endif |
||
1297 | RotationSet(1); |
||
1298 | } |
||
1299 | } |
||
1300 | |||
1301 | // File browser for selecting the save file |
||
1302 | void TGAppMainFrame::SaveFile() |
||
1303 | { |
||
1304 | TGFileInfo file_info; |
||
1305 | const char *filetypes[] = {"Histograms",histextall,0,0}; |
||
1306 | char *cTemp; |
||
1307 | file_info.fFileTypes = filetypes; |
||
1308 | cTemp = new char[1024]; |
||
1309 | sprintf(cTemp, "%s/results", rootdir); |
||
1310 | file_info.fIniDir = StrDup(cTemp); |
||
1311 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDSave, &file_info); |
||
1312 | delete[] cTemp; |
||
1313 | |||
1314 | if(file_info.fFilename != NULL) |
||
1315 | fileName->widgetTE->SetText(file_info.fFilename); |
||
1316 | } |
||
1317 | |||
1318 | // Start the acquisition |
||
1319 | void TGAppMainFrame::StartAcq() |
||
1320 | { |
||
1321 | // Variable that will initialize camac only once (for scans) |
||
1322 | int scanon = 0; |
||
1323 | |||
1324 | // Determine the type of measurement to perform |
||
1325 | int vscan = 0, pscan = 0, zscan = 0, ascan = 0; |
||
1326 | if(scansOn->widgetChBox[0]->IsDown()) vscan = 1; |
||
1327 | if(scansOn->widgetChBox[1]->IsDown()) pscan = 1; |
||
1328 | if(scansOn->widgetChBox[2]->IsDown()) zscan = 1; |
||
1329 | if(scansOn->widgetChBox[3]->IsDown()) ascan = 1; |
||
1330 | |||
1331 | char cmd[256]; |
||
1332 | int i, j, k; |
||
1333 | float progVal; |
||
1334 | FILE *pfin; |
||
1335 | |||
1336 | // Variables for voltage scan |
||
1337 | float currentVoltage, minVoltage, maxVoltage, stepVoltage; |
||
1338 | int repetition; |
||
1339 | |||
1340 | // Variables for surface scan and Z axis scan |
||
1341 | float minXpos, maxXpos, stepXpos; |
||
1342 | float minYpos, maxYpos, stepYpos; |
||
1343 | float minZpos, maxZpos, stepZpos; |
||
1344 | int repetX, repetY, repetZ; |
||
1345 | |||
1346 | // Variables for angle scan |
||
1347 | float currentAlpha, minAlpha, maxAlpha, stepAlpha; |
||
1348 | int repetAlpha; |
||
1349 | |||
1350 | // Only voltage scan |
||
1351 | if( (vscan == 1) && (pscan == 0) && (ascan == 0) ) |
||
1352 | { // TODO - include possibility to make voltage and angle scan at same time |
||
1353 | // If already started, stop the acquisition |
||
1354 | if(acqStarted) |
||
1355 | { |
||
1356 | printf("Stopping current voltage scan...\n"); |
||
1357 | gROOT->SetInterrupt(); |
||
1358 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1359 | acqStarted = false; |
||
1360 | |||
1361 | // Write information to the finish_sig.txt value |
||
1362 | sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir); |
||
1363 | pfin = fopen(cmd,"w"); |
||
1364 | fprintf(pfin, "%s: Voltage scan stopped.", timeStamp->widgetTE->GetText()); |
||
1365 | fclose(pfin); |
||
1366 | } |
||
1367 | // If stopped, start the acquisition |
||
1368 | else if(!acqStarted) |
||
1369 | { |
||
1370 | printf("Running a voltage scan...\n"); |
||
1371 | |||
1372 | // Check the steps |
||
1373 | minVoltage = vOutStart->widgetNE[0]->GetNumber(); |
||
1374 | maxVoltage = vOutStop->widgetNE[0]->GetNumber(); |
||
1375 | stepVoltage = vOutStep->widgetNE[0]->GetNumber(); |
||
1376 | |||
1377 | if(stepVoltage == 0.) |
||
1378 | repetition = 1; |
||
1379 | else |
||
1380 | { |
||
1381 | // Example: min = 40, max = 70, step = 5 (in increasing steps) |
||
1382 | if( (maxVoltage > minVoltage) && (stepVoltage > 0) ) |
||
1383 | repetition = ((maxVoltage - minVoltage)/stepVoltage)+1; |
||
1384 | // Example: min = 70, max = 40, step = -5 (in decreasing steps) |
||
1385 | else if( (maxVoltage < minVoltage) && (stepVoltage < 0) ) |
||
1386 | repetition = ((minVoltage - maxVoltage)/stepVoltage)-1; |
||
1387 | // Example: min = 70, max = 70 (no scan) |
||
1388 | else if( maxVoltage == minVoltage ) |
||
1389 | repetition = 1; |
||
1390 | // If step is not correctly set, stop the acqusition |
||
1391 | else |
||
1392 | { |
||
1393 | // TODO |
||
1394 | printf("Stopping current voltage scan...\n"); |
||
1395 | gROOT->SetInterrupt(); |
||
1396 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1397 | acqStarted = false; |
||
1398 | repetition = 0; |
||
1399 | } |
||
1400 | } |
||
1401 | |||
1402 | if(DBGSIG) printf("StartAcq(): Voltage repetition (%lf,%lf,%lf) = %d\n", minVoltage, maxVoltage, stepVoltage, repetition); |
||
1403 | |||
1404 | i = 0; |
||
1405 | |||
1406 | // TODO - Setting button text and acqStarted do not work! |
||
1407 | measProgress->widgetTB[0]->SetText("Stop acquisition"); |
||
1408 | acqStarted = true; |
||
1409 | progVal = 0.00; |
||
1410 | measProgress->widgetPB->SetPosition(progVal); |
||
1411 | gVirtualX->Update(1); |
||
1412 | |||
1413 | clkt0 = clock(); |
||
1414 | timet0 = time(NULL); |
||
1415 | |||
1416 | while(1) |
||
1417 | { |
||
1418 | if( (repetition > 0) && (i == repetition) ) break; |
||
1419 | else if( (repetition < 0) && (i == -repetition) ) break; |
||
1420 | else if( repetition == 0 ) break; |
||
1421 | |||
1422 | progVal = (float)(100.00/abs(repetition))*i; |
||
1423 | measProgress->widgetPB->SetPosition(progVal); |
||
1424 | |||
1425 | TimeEstimate(clkt0, timet0, progVal, cmd, singlewait*abs(repetition)); |
||
1426 | measProgress->widgetTE->SetText(cmd); |
||
1427 | |||
1428 | gVirtualX->Update(1); |
||
1429 | |||
1430 | fflush(stdout); |
||
1431 | currentVoltage = minVoltage + stepVoltage*i; |
||
1432 | sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), currentVoltage); |
||
1433 | #if WORKSTAT == 'I' |
||
1434 | retTemp = system(cmd); |
||
1435 | #else |
||
1436 | printf("Cmd: %s\n",cmd); |
||
1437 | #endif |
||
1438 | fflush(stdout); |
||
1439 | |||
1440 | printf("Waiting for voltage change...\n"); |
||
1441 | sleep(singlewait); |
||
1442 | vOut->widgetNE[0]->SetNumber(currentVoltage); |
||
1443 | gVirtualX->Update(1); |
||
1444 | printf("Continuing...\n"); |
||
1445 | |||
1446 | // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<< |
||
1447 | RunMeas((void*)0, i, scanon); // TODO |
||
1448 | fflush(stdout); |
||
1449 | |||
1450 | i++; |
||
1451 | } |
||
1452 | |||
1453 | // Set output back to off |
||
1454 | fflush(stdout); |
||
1455 | printf("Measurement finished, returning to starting voltage...\n"); |
||
1456 | sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), minVoltage); |
||
1457 | vOut->widgetNE[0]->SetNumber(minVoltage); |
||
1458 | #if WORKSTAT == 'I' |
||
1459 | retTemp = system(cmd); |
||
1460 | #else |
||
1461 | printf("Cmd: %s\n",cmd); |
||
1462 | #endif |
||
1463 | fflush(stdout); |
||
1464 | |||
1465 | progVal = 100.00; |
||
1466 | measProgress->widgetPB->SetPosition(progVal); |
||
1467 | printf("\n"); |
||
1468 | |||
1469 | sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir); |
||
1470 | pfin = fopen(cmd,"w"); |
||
1471 | fprintf(pfin, "%s: Voltage scan finished.", timeStamp->widgetTE->GetText()); |
||
1472 | fclose(pfin); |
||
1473 | |||
1474 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1475 | acqStarted = false; |
||
1476 | } |
||
1477 | } |
||
1478 | // Surface scan |
||
1479 | else if( (pscan == 1) && (vscan == 0) && (ascan == 0) ) |
||
1480 | { |
||
1481 | // If already started, stop the acquisition |
||
1482 | if(acqStarted) |
||
1483 | { |
||
1484 | printf("Stopping current surface scan...\n"); |
||
1485 | gROOT->SetInterrupt(); |
||
1486 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1487 | acqStarted = false; |
||
1488 | |||
1489 | // Write information to the finish_sig.txt value |
||
1490 | sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir); |
||
1491 | pfin = fopen(cmd,"w"); |
||
1492 | fprintf(pfin, "%s: Surface scan stopped.", timeStamp->widgetTE->GetText()); |
||
1493 | fclose(pfin); |
||
1494 | } |
||
1495 | // If stopped, start the acquisition |
||
1496 | else if(!acqStarted) |
||
1497 | { |
||
1498 | printf("Running a surface scan...\n"); |
||
1499 | |||
1500 | minXpos = xPosMin->widgetNE[0]->GetNumber(); |
||
1501 | maxXpos = xPosMax->widgetNE[0]->GetNumber(); |
||
1502 | stepXpos = xPosStep->widgetNE[0]->GetNumber(); |
||
1503 | minYpos = yPosMin->widgetNE[0]->GetNumber(); |
||
1504 | maxYpos = yPosMax->widgetNE[0]->GetNumber(); |
||
1505 | stepYpos = yPosStep->widgetNE[0]->GetNumber(); |
||
1506 | minZpos = zPosMin->widgetNE[0]->GetNumber(); |
||
1507 | maxZpos = zPosMax->widgetNE[0]->GetNumber(); |
||
1508 | stepZpos = zPosStep->widgetNE[0]->GetNumber(); |
||
1509 | |||
1510 | // Setting repetition for Z axis scan |
||
1511 | if(zscan == 1) |
||
1512 | { |
||
1513 | if(stepZpos == 0.) |
||
1514 | repetZ = 1; |
||
1515 | else |
||
1516 | { |
||
1517 | // Example: min = 40, max = 70, step = 5 (in increasing steps) |
||
1518 | if( (maxZpos > minZpos) && (stepZpos > 0) ) |
||
1519 | repetZ = ((maxZpos - minZpos)/stepZpos)+1; |
||
1520 | // Example: min = 70, max = 40, step = -5 (in decreasing steps) |
||
1521 | else if( (maxZpos < minZpos) && (stepZpos < 0) ) |
||
1522 | repetZ = ((minZpos - maxZpos)/stepZpos)-1; |
||
1523 | // Example: min = 70, max = 70 (no scan) |
||
1524 | else if( maxZpos == minZpos ) |
||
1525 | repetZ = 1; |
||
1526 | // If step is not correctly set, stop the acqusition |
||
1527 | else |
||
1528 | { |
||
1529 | // TODO |
||
1530 | printf("Stopping current surface scan (Z step error)...\n"); |
||
1531 | gROOT->SetInterrupt(); |
||
1532 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1533 | acqStarted = false; |
||
1534 | repetZ = 0; |
||
1535 | } |
||
1536 | } |
||
1537 | } |
||
1538 | else |
||
1539 | { |
||
1540 | minZpos = zPos->widgetNE[0]->GetNumber(); |
||
1541 | repetZ = 1; |
||
1542 | } |
||
1543 | |||
1544 | // Setting repetition for X axis |
||
1545 | if(stepXpos == 0.) |
||
1546 | repetX = 1; |
||
1547 | else |
||
1548 | { |
||
1549 | // Example: min = 40, max = 70, step = 5 (in increasing steps) |
||
1550 | if( (maxXpos > minXpos) && (stepXpos > 0) ) |
||
1551 | repetX = ((maxXpos - minXpos)/stepXpos)+1; |
||
1552 | // Example: min = 70, max = 40, step = -5 (in decreasing steps) |
||
1553 | else if( (maxXpos < minXpos) && (stepXpos < 0) ) |
||
1554 | repetX = ((minXpos - maxXpos)/stepXpos)-1; |
||
1555 | // Example: min = 70, max = 70 (no scan) |
||
1556 | else if( maxXpos == minXpos ) |
||
1557 | repetX = 1; |
||
1558 | // If step is not correctly set, stop the acqusition |
||
1559 | else |
||
1560 | { |
||
1561 | // TODO |
||
1562 | printf("Stopping current surface scan (X step error)...\n"); |
||
1563 | gROOT->SetInterrupt(); |
||
1564 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1565 | acqStarted = false; |
||
1566 | repetX = 0; |
||
1567 | } |
||
1568 | } |
||
1569 | // Setting repetition for Y axis |
||
1570 | if(stepYpos == 0.) |
||
1571 | repetY = 1; |
||
1572 | else |
||
1573 | { |
||
1574 | // Example: min = 40, max = 70, step = 5 (in increasing steps) |
||
1575 | if( (maxYpos > minYpos) && (stepYpos > 0) ) |
||
1576 | repetY = ((maxYpos - minYpos)/stepYpos)+1; |
||
1577 | // Example: min = 70, max = 40, step = -5 (in decreasing steps) |
||
1578 | else if( (maxYpos < minYpos) && (stepYpos < 0) ) |
||
1579 | repetY = ((minYpos - maxYpos)/stepYpos)-1; |
||
1580 | // Example: min = 70, max = 70 (no scan) |
||
1581 | else if( maxYpos == minYpos ) |
||
1582 | repetY = 1; |
||
1583 | // If step is not correctly set, stop the acqusition |
||
1584 | else |
||
1585 | { |
||
1586 | // TODO |
||
1587 | printf("Stopping current surface scan (Y step error)...\n"); |
||
1588 | gROOT->SetInterrupt(); |
||
1589 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1590 | acqStarted = false; |
||
1591 | repetY = 0; |
||
1592 | } |
||
1593 | } |
||
1594 | |||
1595 | if(DBGSIG) printf("StartAcq(): X axis repetition (%lf,%lf,%lf) = %d\n", minXpos, maxXpos, stepXpos, repetX); |
||
1596 | if(DBGSIG) printf("StartAcq(): Y axis repetition (%lf,%lf,%lf) = %d\n", minYpos, maxYpos, stepYpos, repetY); |
||
1597 | if(DBGSIG) printf("StartAcq(): Z axis repetition (%lf,%lf,%lf) = %d\n", minZpos, maxZpos, stepZpos, repetZ); |
||
1598 | |||
1599 | i = 0; j = 0; k = 0; |
||
1600 | |||
1601 | // TODO - Setting button text and acqStarted do not work! |
||
1602 | measProgress->widgetTB[0]->SetText("Stop acquisition"); |
||
1603 | acqStarted = true; |
||
1604 | progVal = 0.00; |
||
1605 | measProgress->widgetPB->SetPosition(progVal); |
||
1606 | gVirtualX->Update(1); |
||
1607 | |||
1608 | clkt0 = clock(); |
||
1609 | timet0 = time(NULL); |
||
1610 | |||
1611 | // Scan over Z axis |
||
1612 | while(1) |
||
1613 | { |
||
1614 | if( (repetZ > 0) && (k == repetZ) ) break; |
||
1615 | else if( (repetZ < 0) && (k == -repetZ) ) break; |
||
1616 | else if( repetZ == 0 ) break; |
||
1617 | |||
1618 | fflush(stdout); |
||
1619 | // Z-axis change |
||
1620 | if( posUnits->widgetCB->GetSelected() == 0) |
||
1621 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)(minZpos + stepZpos*k), rootdir); |
||
1622 | else if( posUnits->widgetCB->GetSelected() == 1) |
||
1623 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)((minZpos + stepZpos*k)/lenconversion), rootdir); |
||
1624 | #if WORKSTAT == 'I' |
||
1625 | retTemp = system(cmd); |
||
1626 | #else |
||
1627 | printf("Cmd: %s\n",cmd); |
||
1628 | #endif |
||
1629 | fflush(stdout); |
||
1630 | |||
1631 | printf("Next Z position...\n"); |
||
1632 | sleep(2*doublewait); |
||
1633 | zPos->widgetNE[0]->SetNumber(minZpos + stepZpos*k); |
||
1634 | fflush(stdout); |
||
1635 | |||
1636 | // Scan over Y axis |
||
1637 | while(1) |
||
1638 | { |
||
1639 | if( (repetY > 0) && (j == repetY) ) break; |
||
1640 | else if( (repetY < 0) && (j == -repetY) ) break; |
||
1641 | else if( repetY == 0 ) break; |
||
1642 | |||
1643 | fflush(stdout); |
||
1644 | // Y-axis change |
||
1645 | if( posUnits->widgetCB->GetSelected() == 0) |
||
1646 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)(minYpos + stepYpos*j), rootdir); |
||
1647 | else if( posUnits->widgetCB->GetSelected() == 1) |
||
1648 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)((minYpos + stepYpos*j)/lenconversion), rootdir); |
||
1649 | #if WORKSTAT == 'I' |
||
1650 | retTemp = system(cmd); |
||
1651 | #else |
||
1652 | printf("Cmd: %s\n",cmd); |
||
1653 | #endif |
||
1654 | fflush(stdout); |
||
1655 | |||
1656 | printf("Next Y position...\n"); |
||
1657 | sleep(2*doublewait); |
||
1658 | yPos->widgetNE[0]->SetNumber(minYpos + stepYpos*j); |
||
1659 | fflush(stdout); |
||
1660 | |||
1661 | // Scan over X axis |
||
1662 | while(1) |
||
1663 | { |
||
1664 | if( (repetX > 0) && (i == repetX) ) break; |
||
1665 | else if( (repetX < 0) && (i == -repetX) ) break; |
||
1666 | else if( repetX == 0 ) break; |
||
1667 | |||
1668 | progVal = (float)(100.00/(abs(repetX)*abs(repetY)*abs(repetZ)))*(k*abs(repetX)*abs(repetY) + j*abs(repetX) + i); |
||
1669 | measProgress->widgetPB->SetPosition(progVal); |
||
1670 | |||
1671 | TimeEstimate(clkt0, timet0, progVal, cmd, doublewait*((abs(repetX)+2)*abs(repetY)+2)*abs(repetZ)); |
||
1672 | measProgress->widgetTE->SetText(cmd); |
||
1673 | |||
1674 | gVirtualX->Update(1); |
||
1675 | |||
1676 | // X-axis change |
||
1677 | if( posUnits->widgetCB->GetSelected() == 0) |
||
1678 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)(minXpos + stepXpos*i), rootdir); |
||
1679 | else if( posUnits->widgetCB->GetSelected() == 1) |
||
1680 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)((minXpos + stepXpos*i)/lenconversion), rootdir); |
||
1681 | #if WORKSTAT == 'I' |
||
1682 | retTemp = system(cmd); |
||
1683 | #else |
||
1684 | printf("Cmd: %s\n",cmd); |
||
1685 | #endif |
||
1686 | fflush(stdout); |
||
1687 | |||
1688 | printf("Next X position...\n"); |
||
1689 | fflush(stdout); |
||
1690 | |||
1691 | printf("Waiting for position change...\n"); |
||
1692 | sleep(doublewait); |
||
1693 | xPos->widgetNE[0]->SetNumber(minXpos + stepXpos*i); |
||
1694 | printf("Continuing...\n"); |
||
1695 | |||
1696 | // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<< |
||
1697 | RunMeas((void*)0, (j*repetX + i), scanon); |
||
1698 | |||
1699 | fflush(stdout); |
||
1700 | |||
1701 | i++; |
||
1702 | } |
||
1703 | |||
1704 | i = 0; |
||
1705 | printf("\n"); |
||
1706 | |||
1707 | j++; |
||
1708 | } |
||
1709 | |||
1710 | j = 0; |
||
1711 | |||
1712 | k++; |
||
1713 | } |
||
1714 | printf("Time = %d\n", (int)time(NULL)); |
||
1715 | |||
1716 | fflush(stdout); |
||
1717 | printf("Measurement finished, returning to starting position...\n"); |
||
1718 | // X-axis return |
||
1719 | if( posUnits->widgetCB->GetSelected() == 0) |
||
1720 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)minXpos, rootdir); |
||
1721 | else if( posUnits->widgetCB->GetSelected() == 1) |
||
1722 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)(minXpos/lenconversion), rootdir); |
||
1723 | #if WORKSTAT == 'I' |
||
1724 | retTemp = system(cmd); |
||
1725 | #else |
||
1726 | printf("Cmd: %s\n",cmd); |
||
1727 | #endif |
||
1728 | fflush(stdout); |
||
1729 | |||
1730 | // Y-axis return |
||
1731 | if( posUnits->widgetCB->GetSelected() == 0) |
||
1732 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)minYpos, rootdir); |
||
1733 | else if( posUnits->widgetCB->GetSelected() == 1) |
||
1734 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)(minYpos/lenconversion), rootdir); |
||
1735 | #if WORKSTAT == 'I' |
||
1736 | retTemp = system(cmd); |
||
1737 | #else |
||
1738 | printf("Cmd: %s\n",cmd); |
||
1739 | #endif |
||
1740 | |||
1741 | // Z-axis return |
||
1742 | if( posUnits->widgetCB->GetSelected() == 0) |
||
1743 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)minZpos, rootdir); |
||
1744 | else if( posUnits->widgetCB->GetSelected() == 1) |
||
1745 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)(minZpos/lenconversion), rootdir); |
||
1746 | #if WORKSTAT == 'I' |
||
1747 | retTemp = system(cmd); |
||
1748 | #else |
||
1749 | printf("Cmd: %s\n",cmd); |
||
1750 | #endif |
||
1751 | xPos->widgetNE[0]->SetNumber(minXpos); |
||
1752 | yPos->widgetNE[0]->SetNumber(minYpos); |
||
1753 | zPos->widgetNE[0]->SetNumber(minZpos); |
||
1754 | |||
1755 | progVal = 100.00; |
||
1756 | measProgress->widgetPB->SetPosition(progVal); |
||
1757 | printf("\n"); |
||
1758 | |||
1759 | // Write information to the finish_sig.txt value |
||
1760 | sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir); |
||
1761 | pfin = fopen(cmd,"w"); |
||
1762 | fprintf(pfin, "%s: Surface scan finished.", timeStamp->widgetTE->GetText()); |
||
1763 | fclose(pfin); |
||
1764 | |||
1765 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1766 | acqStarted = false; |
||
1767 | } |
||
1768 | } |
||
1769 | // Only angle scan |
||
1770 | if( (ascan == 1) && (pscan == 0) && (vscan == 0) ) |
||
1771 | { |
||
1772 | // If already started, stop the acquisition |
||
1773 | if(acqStarted) |
||
1774 | { |
||
1775 | printf("Stopping current angle scan...\n"); |
||
1776 | gROOT->SetInterrupt(); |
||
1777 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1778 | acqStarted = false; |
||
1779 | |||
1780 | // Write information to the finish_sig.txt value |
||
1781 | sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir); |
||
1782 | pfin = fopen(cmd,"w"); |
||
1783 | fprintf(pfin, "%s: Angle scan stopped.", timeStamp->widgetTE->GetText()); |
||
1784 | fclose(pfin); |
||
1785 | } |
||
1786 | // If stopped, start the acquisition |
||
1787 | else if(!acqStarted) |
||
1788 | { |
||
1789 | printf("Running an incidence angle scan...\n"); |
||
1790 | |||
1791 | // Check the steps |
||
1792 | minAlpha = rotPosMin->widgetNE[0]->GetNumber(); |
||
1793 | maxAlpha = rotPosMax->widgetNE[0]->GetNumber(); |
||
1794 | stepAlpha = rotPosStep->widgetNE[0]->GetNumber(); |
||
1795 | |||
1796 | if(stepAlpha == 0.) |
||
1797 | repetAlpha = 1; |
||
1798 | else |
||
1799 | { |
||
1800 | // Example: min = 40, max = 70, step = 5 (in increasing steps) |
||
1801 | if( (maxAlpha > minAlpha) && (stepAlpha > 0) ) |
||
1802 | repetAlpha = ((maxAlpha - minAlpha)/stepAlpha)+1; |
||
1803 | // Example: min = 70, max = 40, step = -5 (in decreasing steps) |
||
1804 | else if( (maxAlpha < minAlpha) && (stepAlpha < 0) ) |
||
1805 | repetAlpha = ((minAlpha - maxAlpha)/stepAlpha)-1; |
||
1806 | // Example: min = 70, max = 70 (no scan) |
||
1807 | else if( maxAlpha == minAlpha ) |
||
1808 | repetAlpha = 1; |
||
1809 | // If step is not correctly set, stop the acqusition |
||
1810 | else |
||
1811 | { |
||
1812 | // TODO |
||
1813 | printf("Stopping current incidence angle scan...\n"); |
||
1814 | gROOT->SetInterrupt(); |
||
1815 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1816 | acqStarted = false; |
||
1817 | repetAlpha = 0; |
||
1818 | } |
||
1819 | } |
||
1820 | |||
1821 | if(DBGSIG) printf("StartAcq(): Angle repetition (%lf,%lf,%lf) = %d\n", minAlpha, maxAlpha, stepAlpha, repetAlpha); |
||
1822 | |||
1823 | int angleWait = TMath::Ceil(abs(rotPos->widgetNE[0]->GetNumber()-minAlpha)*15/(rotPos->widgetNE[0]->GetNumMax())); |
||
1824 | if(rotUnits->widgetCB->GetSelected() == 1) |
||
1825 | { |
||
1826 | minAlpha = minAlpha/rotconversion; |
||
1827 | maxAlpha = maxAlpha/rotconversion; |
||
1828 | stepAlpha = stepAlpha/rotconversion; |
||
1829 | } |
||
1830 | |||
1831 | i = 0; |
||
1832 | |||
1833 | // TODO - Setting button text and acqStarted do not work! |
||
1834 | measProgress->widgetTB[0]->SetText("Stop acquisition"); |
||
1835 | acqStarted = true; |
||
1836 | progVal = 0.00; |
||
1837 | measProgress->widgetPB->SetPosition(progVal); |
||
1838 | gVirtualX->Update(1); |
||
1839 | |||
1840 | clkt0 = clock(); |
||
1841 | timet0 = time(NULL); |
||
1842 | |||
1843 | // Setting angle to initial position |
||
1844 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)minAlpha, rootdir); |
||
1845 | if(rotUnits->widgetCB->GetSelected() == 0) |
||
1846 | rotPos->widgetNE[0]->SetNumber(minAlpha); |
||
1847 | else if(rotUnits->widgetCB->GetSelected() == 1) |
||
1848 | rotPos->widgetNE[0]->SetNumber(minAlpha*rotconversion); |
||
1849 | #if WORKSTAT == 'I' |
||
1850 | retTemp = system(cmd); |
||
1851 | #else |
||
1852 | printf("Cmd: %s\n",cmd); |
||
1853 | #endif |
||
1854 | fflush(stdout); |
||
1855 | |||
1856 | printf("Waiting for %ds for rotation platform to move into starting position...\n", angleWait); |
||
1857 | sleep(angleWait); |
||
1858 | |||
1859 | while(1) |
||
1860 | { |
||
1861 | if( (repetAlpha > 0) && (i == repetAlpha) ) break; |
||
1862 | else if( (repetAlpha < 0) && (i == -repetAlpha) ) break; |
||
1863 | else if( repetAlpha == 0 ) break; |
||
1864 | |||
1865 | progVal = (float)(100.00/abs(repetAlpha))*i; |
||
1866 | measProgress->widgetPB->SetPosition(progVal); |
||
1867 | |||
1868 | TimeEstimate(clkt0, timet0, progVal, cmd, singlewait*abs(repetAlpha)); |
||
1869 | measProgress->widgetTE->SetText(cmd); |
||
1870 | |||
1871 | gVirtualX->Update(1); |
||
1872 | |||
1873 | fflush(stdout); |
||
1874 | currentAlpha = minAlpha + stepAlpha*i; |
||
1875 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)currentAlpha, rootdir); |
||
1876 | #if WORKSTAT == 'I' |
||
1877 | retTemp = system(cmd); |
||
1878 | #else |
||
1879 | printf("Cmd: %s\n",cmd); |
||
1880 | #endif |
||
1881 | fflush(stdout); |
||
1882 | |||
1883 | printf("Waiting for angle change...\n"); |
||
1884 | sleep(singlewait); |
||
1885 | if(rotUnits->widgetCB->GetSelected() == 0) |
||
1886 | rotPos->widgetNE[0]->SetNumber(currentAlpha); |
||
1887 | else if(rotUnits->widgetCB->GetSelected() == 1) |
||
1888 | rotPos->widgetNE[0]->SetNumber(currentAlpha*rotconversion); |
||
1889 | gVirtualX->Update(1); |
||
1890 | printf("Continuing...\n"); |
||
1891 | |||
1892 | // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<< |
||
1893 | RunMeas((void*)0, i, scanon); // TODO |
||
1894 | fflush(stdout); |
||
1895 | |||
1896 | i++; |
||
1897 | } |
||
1898 | |||
1899 | // Set angle back to original position |
||
1900 | fflush(stdout); |
||
1901 | printf("Measurement finished, returning to starting incidence angle...\n"); |
||
1902 | sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)minAlpha, rootdir); |
||
1903 | if(rotUnits->widgetCB->GetSelected() == 0) |
||
1904 | rotPos->widgetNE[0]->SetNumber(minAlpha); |
||
1905 | else if(rotUnits->widgetCB->GetSelected() == 1) |
||
1906 | rotPos->widgetNE[0]->SetNumber(minAlpha*rotconversion); |
||
1907 | #if WORKSTAT == 'I' |
||
1908 | retTemp = system(cmd); |
||
1909 | #else |
||
1910 | printf("Cmd: %s\n",cmd); |
||
1911 | #endif |
||
1912 | fflush(stdout); |
||
1913 | |||
1914 | progVal = 100.00; |
||
1915 | measProgress->widgetPB->SetPosition(progVal); |
||
1916 | printf("\n"); |
||
1917 | |||
1918 | sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir); |
||
1919 | pfin = fopen(cmd,"w"); |
||
1920 | fprintf(pfin, "%s: Incidence angle scan finished.", timeStamp->widgetTE->GetText()); |
||
1921 | fclose(pfin); |
||
1922 | |||
1923 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1924 | acqStarted = false; |
||
1925 | } |
||
1926 | } |
||
1927 | // Normal single measurement |
||
1928 | else if( (vscan == 0) && (pscan == 0) && (ascan == 0) ) |
||
1929 | { |
||
1930 | // Set the start button to stop and enable stopping of measurement |
||
1931 | if(acqStarted) |
||
1932 | { |
||
1933 | printf("Stopping current single scan...\n"); |
||
1934 | gROOT->SetInterrupt(); |
||
1935 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1936 | acqStarted = false; |
||
1937 | } |
||
1938 | else if(!acqStarted) |
||
1939 | { |
||
1940 | measProgress->widgetTB[0]->SetText("Stop acquisition"); |
||
1941 | acqStarted = true; |
||
1942 | |||
1943 | printf("Running a single scan...\n"); |
||
1944 | clkt0 = clock(); |
||
1945 | timet0 = time(NULL); |
||
1946 | RunMeas((void*)0, 0, scanon); |
||
1947 | printf("Measurement finished...\n"); |
||
1948 | printf("\n"); |
||
1949 | |||
1950 | measProgress->widgetTB[0]->SetText("Start acquisition"); |
||
1951 | acqStarted = false; |
||
1952 | } |
||
1953 | } |
||
1954 | } |
||
1955 | |||
1956 | // Main measurement window connections ---------------------- |
||
1957 | |||
1958 | // Histogram file selection pane connections ---------------- |
||
1959 | |||
1960 | // File browser for opening histograms |
||
1961 | void TGAppMainFrame::SelectDirectory() |
||
1962 | { |
||
1963 | int i = fileList->GetNumberOfEntries(); |
||
1964 | char *cTemp; |
||
1965 | |||
1966 | TGFileInfo file_info; |
||
1967 | const char *filetypes[] = {"Histograms",histextall,0,0}; |
||
1968 | file_info.fFileTypes = filetypes; |
||
1969 | cTemp = new char[1024]; |
||
1970 | sprintf(cTemp, "%s/results", rootdir); |
||
1971 | file_info.fIniDir = StrDup(cTemp); |
||
1972 | file_info.fMultipleSelection = kTRUE; |
||
1973 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info); |
||
1974 | delete[] cTemp; |
||
1975 | |||
1976 | TList *files = file_info.fFileNamesList; |
||
1977 | if(files) |
||
1978 | { |
||
1979 | TSystemFile *file; |
||
1980 | TString fname; |
||
1981 | TIter next(files); |
||
1982 | while(file=(TSystemFile*)next()) |
||
1983 | { |
||
1984 | fname = file->GetName(); |
||
1985 | fileList->AddEntry(fname.Data(), i); |
||
1986 | i++; |
||
1987 | } |
||
1988 | } |
||
1989 | fileList->Layout(); |
||
1990 | } |
||
1991 | |||
1992 | // Toggle multiple selection in filelist or delete all entries |
||
1993 | void TGAppMainFrame::ListMultiSelect(int opt) |
||
1994 | { |
||
1995 | // Enable multiselect |
||
1996 | if(opt == 0) |
||
1997 | { |
||
1998 | fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn())); |
||
1999 | |||
2000 | if(multiSelect->widgetChBox[1]->IsDown()) |
||
2001 | multiSelect->widgetChBox[1]->SetState(kButtonUp); |
||
2002 | } |
||
2003 | else if(opt == 1) |
||
2004 | { |
||
2005 | if(multiSelect->widgetChBox[1]->IsDown()) |
||
2006 | { |
||
2007 | multiSelect->widgetChBox[0]->SetState(kButtonDown); |
||
2008 | fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn())); |
||
2009 | for(int i = 0; i < fileList->GetNumberOfEntries(); i++) |
||
2010 | fileList->Select(i,kTRUE); |
||
2011 | } |
||
2012 | else if(!multiSelect->widgetChBox[1]->IsDown()) |
||
2013 | { |
||
2014 | multiSelect->widgetChBox[0]->SetState(kButtonUp); |
||
2015 | fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn())); |
||
2016 | for(int i = 0; i < fileList->GetNumberOfEntries(); i++) |
||
2017 | fileList->Select(i,kFALSE); |
||
2018 | } |
||
2019 | } |
||
2020 | } |
||
2021 | |||
2022 | // Navigation buttons for the filelist (<<, >>) and double click |
||
2023 | void TGAppMainFrame::FileListNavigation(int opt) |
||
2024 | { |
||
2025 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2026 | int curSel; |
||
2027 | TList *files; |
||
2028 | if( nrfiles > 0 ) |
||
2029 | { |
||
2030 | if(opt < -1) |
||
2031 | { |
||
2032 | // turn off multiple selection and select first file on list |
||
2033 | if(multiSelect->widgetChBox[0]->IsOn()) |
||
2034 | { |
||
2035 | fileList->SetMultipleSelections(kFALSE); |
||
2036 | multiSelect->widgetChBox[0]->SetState(kButtonUp); |
||
2037 | multiSelect->widgetChBox[1]->SetState(kButtonUp); |
||
2038 | |||
2039 | fileList->Select(0,kTRUE); |
||
2040 | } |
||
2041 | else |
||
2042 | { |
||
2043 | // if nothing is selected, curSel will be -1 |
||
2044 | curSel = fileList->GetSelected(); |
||
2045 | // go to next file on list |
||
2046 | if(opt == -3) |
||
2047 | { |
||
2048 | if( (curSel == (int)(nrfiles-1)) || (curSel == -1) ) |
||
2049 | fileList->Select(0); |
||
2050 | else |
||
2051 | fileList->Select(curSel+1); |
||
2052 | } |
||
2053 | // go to previous file on list |
||
2054 | else if(opt == -2) |
||
2055 | { |
||
2056 | if( (curSel == 0) || (curSel == -1) ) |
||
2057 | fileList->Select(nrfiles-1); |
||
2058 | else |
||
2059 | fileList->Select(curSel-1); |
||
2060 | } |
||
2061 | } |
||
2062 | } |
||
2063 | } |
||
2064 | |||
2065 | UpdateHistogram(0); |
||
2066 | } |
||
2067 | |||
2068 | // Open the header edit window when pressing on editHeader button |
||
2069 | void TGAppMainFrame::HeaderEdit() |
||
2070 | { |
||
2071 | bool createTab = true; |
||
2072 | int tabid = -1; |
||
2073 | |||
2074 | for(int i = 0; i < fTab->GetNumberOfTabs(); i++) |
||
2075 | { |
||
2076 | if(strcmp("File header editor", fTab->GetTabTab(i)->GetString() ) == 0) |
||
2077 | { |
||
2078 | createTab = false; |
||
2079 | tabid = i; |
||
2080 | } |
||
2081 | |||
2082 | if(DBGSIG > 1) printf("HeaderEdit(): Name of tab = %s\n", fTab->GetTabTab(i)->GetString() ); |
||
2083 | } |
||
2084 | |||
2085 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2086 | if(nrfiles > 0) |
||
2087 | HeaderEditTab(fTab, createTab, &tabid); |
||
2088 | } |
||
2089 | |||
2090 | // Clear the histogram file selection list and dark run analysis selection |
||
2091 | void TGAppMainFrame::ClearHistogramList() |
||
2092 | { |
||
2093 | fileList->RemoveAll(); |
||
2094 | darkRun->widgetTE->Clear(); |
||
2095 | } |
||
2096 | |||
2097 | // Histogram file selection pane connections ---------------- |
||
2098 | |||
2099 | // Histogram controls pane connections ---------------------- |
||
2100 | |||
2101 | // Readjust the histogram range after changing ADC, TDC, Y range or logarithmic scale (opt: 0 = normal redraw, 1 = export, 2 = redraw when changing which channel to display) |
||
2102 | void TGAppMainFrame::UpdateHistogram(int opt) |
||
2103 | { |
||
2104 | if(DBGSIG > 1) |
||
2105 | { |
||
2106 | printf("UpdateHistogram(): Clearing the TList\n"); |
||
2107 | gDirectory->GetList()->Delete(); |
||
2108 | gObjectTable->Print(); |
||
2109 | } |
||
2110 | |||
2111 | // Do not do normal histogram update if we have multiple files selected |
||
2112 | if( (opt == 0) && (multiSelect->widgetChBox[0]->IsDown()) ) |
||
2113 | { |
||
2114 | printf("UpdateHistogram(): To preview changes done to a histogram, please deselect the \"Multiple files select\" option."); |
||
2115 | return; |
||
2116 | } |
||
2117 | |||
2118 | // Do not update histogram if we are on the same channel |
||
2119 | if( ((opt == 2) && (selChannel != (int)selectCh->widgetNE[0]->GetNumber())) || (opt < 2) ) |
||
2120 | { |
||
2121 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2122 | TCanvas *gCanvas; |
||
2123 | char exportname[512]; |
||
2124 | char cTemp[512]; |
||
2125 | |||
2126 | if(opt == 1) |
||
2127 | gCanvas = analysisCanvas->GetCanvas(); |
||
2128 | |||
2129 | if(nrfiles > 0) |
||
2130 | { |
||
2131 | TList *files; |
||
2132 | files = new TList(); |
||
2133 | fileList->GetSelectedEntries(files); |
||
2134 | |||
2135 | if(files) |
||
2136 | { |
||
2137 | for(int i = 0; i < (int)nrfiles; i++) |
||
2138 | { |
||
2139 | if(files->At(i)) |
||
2140 | { |
||
2141 | if(DBGSIG) |
||
2142 | printf("UpdateHistogram(): Filename: %s\n", files->At(i)->GetTitle()); |
||
2143 | if(opt == 1) |
||
2144 | remove_ext((char*)files->At(i)->GetTitle(), cTemp); |
||
2145 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
2146 | { |
||
2147 | sprintf(exportname, "%s_adc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber()); |
||
2148 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, opt); |
||
2149 | } |
||
2150 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
2151 | { |
||
2152 | sprintf(exportname, "%s_tdc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber()); |
||
2153 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1, opt); |
||
2154 | } |
||
2155 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
2156 | { |
||
2157 | sprintf(exportname, "%s_adctdc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber()); |
||
2158 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2, opt); |
||
2159 | } |
||
2160 | |||
2161 | if(opt == 1) |
||
2162 | { |
||
2163 | gCanvas->SaveAs(exportname); |
||
2164 | delete inroot; |
||
2165 | } |
||
2166 | } |
||
2167 | } |
||
2168 | } |
||
2169 | } |
||
2170 | selChannel = selectCh->widgetNE[0]->GetNumber(); |
||
2171 | } |
||
2172 | |||
2173 | if(DBGSIG > 1) |
||
2174 | { |
||
2175 | printf("UpdateHistogram(): After drawing histograms (connections)\n"); |
||
2176 | gObjectTable->Print(); |
||
2177 | } |
||
2178 | } |
||
2179 | |||
2180 | // Options for histogram (logarithmic scale, clean plots) |
||
2181 | void TGAppMainFrame::HistogramOptions(int opt) |
||
2182 | { |
||
2183 | // Logarithmic scale |
||
2184 | if(opt == 0) |
||
2185 | UpdateHistogram(0); |
||
2186 | // Clean plots |
||
2187 | else if(opt == 1) |
||
2188 | { |
||
2189 | cleanPlots = histOpt->widgetChBox[1]->IsDown(); |
||
2190 | UpdateHistogram(0); |
||
2191 | } |
||
2192 | } |
||
2193 | |||
2194 | // Changing the histogram type to display |
||
2195 | void TGAppMainFrame::ChangeHisttype(int type) |
||
2196 | { |
||
2197 | TGTextButton *pressedB = new TGTextButton(); |
||
2198 | int menuID = 0; |
||
2199 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2200 | |||
2201 | // ADC histogram |
||
2202 | if(type == 0) |
||
2203 | { |
||
2204 | pressedB = plotType->widgetTB[0]; |
||
2205 | menuID = M_ANALYSIS_HISTTYPE_1DADC; |
||
2206 | |||
2207 | plotType->widgetTB[1]->SetDown(kFALSE); |
||
2208 | plotType->widgetTB[2]->SetDown(kFALSE); |
||
2209 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC); |
||
2210 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D); |
||
2211 | } |
||
2212 | // TDC histogram |
||
2213 | else if(type == 1) |
||
2214 | { |
||
2215 | pressedB = plotType->widgetTB[1]; |
||
2216 | menuID = M_ANALYSIS_HISTTYPE_1DTDC; |
||
2217 | |||
2218 | plotType->widgetTB[0]->SetDown(kFALSE); |
||
2219 | plotType->widgetTB[2]->SetDown(kFALSE); |
||
2220 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
2221 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D); |
||
2222 | } |
||
2223 | // ADC vs. TDC histogram |
||
2224 | else if(type == 2) |
||
2225 | { |
||
2226 | pressedB = plotType->widgetTB[2]; |
||
2227 | menuID = M_ANALYSIS_HISTTYPE_2D; |
||
2228 | |||
2229 | plotType->widgetTB[0]->SetDown(kFALSE); |
||
2230 | plotType->widgetTB[1]->SetDown(kFALSE); |
||
2231 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
2232 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC); |
||
2233 | } |
||
2234 | |||
2235 | if( fMenuHisttype->IsEntryChecked(menuID) ) |
||
2236 | { |
||
2237 | pressedB->SetDown(kFALSE); |
||
2238 | fMenuHisttype->UnCheckEntry(menuID); |
||
2239 | } |
||
2240 | else if( !fMenuHisttype->IsEntryChecked(menuID) ) |
||
2241 | { |
||
2242 | pressedB->SetDown(kTRUE); |
||
2243 | fMenuHisttype->CheckEntry(menuID); |
||
2244 | } |
||
2245 | |||
2246 | UpdateHistogram(0); |
||
2247 | } |
||
2248 | |||
2249 | // Histogram controls pane connections ---------------------- |