Rev 127 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
117 | f9daq | 1 | #include "workstation.h" |
2 | #include "daq.h" |
||
3 | #include "root_include.h" |
||
4 | #include "windowed_test.h" |
||
5 | |||
6 | #include <stdio.h> |
||
7 | #include <stdlib.h> |
||
8 | #include <time.h> |
||
9 | #include <unistd.h> |
||
10 | |||
11 | #include "daqscope.h" |
||
12 | |||
13 | //--------------------------------------------------------------- |
||
14 | // Subwindow layout class |
||
15 | |||
16 | class TGMdiSubwindow |
||
17 | { |
||
18 | RQ_OBJECT("TGMdiSubwindow") |
||
19 | |||
20 | protected: |
||
21 | TGMdiFrame *fMdiFrame; |
||
22 | |||
23 | public: |
||
24 | TGMdiSubwindow(TGMdiMainFrame *main, int w, int h); |
||
25 | |||
26 | TGMdiFrame *GetMdiFrame() const { return fMdiFrame; } |
||
27 | virtual Bool_t CloseWindow(); |
||
28 | }; |
||
29 | |||
30 | //--------------------------------------------------------------- |
||
31 | // Main window class |
||
32 | |||
33 | class TGAppMainFrame |
||
34 | { |
||
35 | RQ_OBJECT("TGAppMainFrame") |
||
36 | |||
37 | protected: |
||
38 | TGMainFrame *fMain; |
||
39 | TGMdiMainFrame *fMainFrame; |
||
40 | TGMdiMenuBar *fMenuBar; |
||
41 | TGLayoutHints *fMenuBarItemLayout; |
||
42 | TGPopupMenu *fMenuFile, *fMenuAnalysis, *fMenuWindow, *fMenuHelp; |
||
43 | TGPopupMenu *fMenuHisttype; |
||
44 | TGMdiSubwindow *settingsPane, *mainSubwindow, *histogramPane, *histogramPaneFile, *histogramPaneCtr; |
||
45 | |||
46 | void InitMenu(); |
||
47 | void MeasurementLayout(); |
||
48 | void CloseWindow(); |
||
49 | Bool_t About(); |
||
50 | public: |
||
51 | TGAppMainFrame(const TGWindow *p, int w, int h); |
||
52 | |||
53 | void HandleMenu(Int_t id); |
||
54 | |||
55 | void EnableVoltScan(); |
||
56 | void EnableSurfScan(); |
||
57 | void EnableZaxisScan(); |
||
58 | void VoltageLimit(); |
||
59 | void ChannelLimit(); |
||
60 | void CleanPlotToggle(); |
||
61 | void ConnectToScope(); |
||
62 | |||
63 | void SetVoltOut(); |
||
64 | void GetVoltOut(); |
||
65 | void ResetVoltOut(); |
||
66 | void SetPosition(); |
||
67 | void GetPosition(); |
||
68 | void HomePosition(); |
||
69 | void SaveFile(); |
||
70 | void StartAcq(); |
||
71 | |||
72 | void SelectDirectory(); |
||
73 | void ListMultiSelect(); |
||
74 | void ListSelectAll(); |
||
75 | void FileListNavigation(int pn); |
||
76 | |||
77 | void DisplayHistogram(char *histfile, int histtype); |
||
78 | void SetHistRange(); |
||
79 | void ChangeHisttype(int type); |
||
80 | void ChangeChannel(); |
||
81 | void HistogramExport(); |
||
82 | void MakeSurfPlot(TList *files); |
||
83 | void MakeBreakdownPlot(int nrp, double *volt, double *volterr, double *psep1, double *pseperr1, double *psep2, double *pseperr2, double *psep3, double *pseperr3, char *plotfile); |
||
84 | |||
85 | void FitSpectrum(TList *files, int q); |
||
86 | void EdgeDetection(TGraph *pdf, TGraph *cdf, char *outname, TCanvas *g1dCanvas, double pdfmax, int direction); |
||
87 | void IntegSpectrum(TList *files, int direction); |
||
88 | |||
89 | void RunMeas(void *ptr, int runCase, int zaxisscan); |
||
90 | }; |
||
91 | |||
92 | const char *histExt = ".root"; |
||
93 | const char *histExtAll = "*.root"; |
||
94 | daq *gDaq; |
||
95 | daqscope *gScopeDaq; |
||
96 | int debugSig = 0; |
||
97 | int retTemp; |
||
98 | int gStop=0; |
||
99 | unsigned int gBuf[BSIZE]; |
||
100 | int logchange = 0; |
||
101 | double tdctimeconversion = 45.0909; |
||
102 | double lenconversion = 0.3595; |
||
103 | int oscOn; |
||
104 | |||
105 | // ROOT file variable structure ----------- |
||
106 | struct EventHeader { |
||
107 | int nrch; |
||
108 | int timestamp; |
||
109 | double biasvolt; |
||
110 | int xpos; |
||
111 | int ypos; |
||
112 | int zpos; |
||
113 | double temperature; |
||
114 | char laserinfo[256]; |
||
115 | } evtheader; |
||
116 | |||
117 | struct EventData { |
||
118 | int adcdata[8]; |
||
119 | int tdcdata[8]; |
||
120 | } evtdata; |
||
121 | |||
122 | TFile *inroot; |
||
123 | TFile *outroot; |
||
124 | |||
125 | //--------------------------------------------------------------- |
||
126 | // Global variables |
||
127 | |||
128 | TGCheckButton *voltscanOn; |
||
129 | TGCheckButton *surfscanOn; |
||
130 | TGCheckButton *zscanOn; |
||
131 | TGTextEntry *oscIP; |
||
132 | TGTextButton *oscConnect; |
||
133 | TGCheckButton *histogramOn; |
||
134 | TGNumberEntry *vHardlimit; |
||
135 | TGNumberEntry *NCH; |
||
136 | TGTextEntry *laserInfo; |
||
137 | TGCheckButton *cleanOn; |
||
138 | |||
139 | TGTab *setTab; |
||
140 | TGComboBox *vOutCh; |
||
141 | TGNumberEntry *vOut; |
||
142 | TGCheckButton *vOutOnOff; |
||
143 | TGTextButton *vOutSet; |
||
144 | TGTextButton *vOutGet; |
||
145 | TGTextButton *vOutReset; |
||
146 | TGNumberEntry *vOutStart; |
||
147 | TGNumberEntry *vOutStop; |
||
148 | TGNumberEntry *vOutStep; |
||
149 | TGNumberEntry *xPos; |
||
150 | TGNumberEntry *yPos; |
||
151 | TGNumberEntry *zPos; |
||
152 | TGTextButton *positionSet; |
||
153 | TGTextButton *positionGet; |
||
154 | TGTextButton *positionHome; |
||
155 | TGNumberEntry *xPosMin; |
||
156 | TGNumberEntry *xPosMax; |
||
157 | TGNumberEntry *xPosStep; |
||
158 | TGNumberEntry *yPosMin; |
||
159 | TGNumberEntry *yPosMax; |
||
160 | TGNumberEntry *yPosStep; |
||
161 | TGNumberEntry *zPosMin; |
||
162 | TGNumberEntry *zPosMax; |
||
163 | TGNumberEntry *zPosStep; |
||
164 | TGNumberEntry *evtNum; |
||
165 | TGTextEntry *timeStamp; |
||
166 | TGTextEntry *fileName; |
||
167 | TGTextButton *saveFile; |
||
168 | TGTextButton *measStart; |
||
169 | TGLabel *busyLabel; |
||
170 | TGHProgressBar *curProgress; |
||
171 | |||
172 | TRootEmbeddedCanvas *histCanvas; |
||
173 | |||
174 | TGTextButton *selectDir; |
||
175 | TGListBox *fileList; |
||
176 | TGCheckButton *multiSelect; |
||
177 | TGCheckButton *multiSelectAll; |
||
178 | TGTextButton *prevFile; |
||
179 | TGTextButton *nextFile; |
||
180 | |||
181 | TGNumberEntry *adcMinRange; |
||
182 | TGNumberEntry *adcMaxRange; |
||
183 | TGNumberEntry *tdcMinwindow; |
||
184 | TGNumberEntry *tdcMaxwindow; |
||
185 | TGNumberEntry *yMinRange; |
||
186 | TGNumberEntry *yMaxRange; |
||
187 | TGNumberEntry *selectCh; |
||
188 | TGTextButton *changeADC; |
||
189 | TGTextButton *changeTDC; |
||
190 | TGTextButton *changeADCTDC; |
||
191 | TGTextButton *change2Dsurf; |
||
192 | TGCheckButton *logscale; |
||
193 | TGTextButton *exportHist; |
||
194 | TGNumberEntry *fitSigma; |
||
195 | TGNumberEntry *fitTresh; |
||
196 | TGNumberEntry *fitInter; |
||
197 | TGNumberEntry *accError; |
||
198 | TGCheckButton *exfitplots; |
||
199 | |||
200 | Bool_t firstrun = kTRUE; |
||
201 | Bool_t started; |
||
202 | Bool_t cleanPlots = kTRUE; |
||
203 | |||
204 | // Layout hints definitions |
||
205 | TGLayoutHints *f0 = new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2); |
||
206 | TGLayoutHints *f0centerx = new TGLayoutHints(kLHintsCenterX,2,2,2,2); |
||
207 | TGLayoutHints *f0centery = new TGLayoutHints(kLHintsLeft | kLHintsCenterY,2,2,2,2); |
||
208 | TGLayoutHints *f0center2d = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,2,2,2,2); |
||
209 | TGLayoutHints *f0right = new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2); |
||
210 | TGLayoutHints *f1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2); |
||
211 | TGLayoutHints *f2 = new TGLayoutHints(kLHintsExpandX,2,2,2,2); |
||
212 | TGLayoutHints *f3 = new TGLayoutHints(kLHintsCenterY,2,2,20,2); |
||
213 | TGLayoutHints *f3notop = new TGLayoutHints(kLHintsCenterY,4,4,2,30); |
||
214 | |||
215 | // Separate functions ----------------------------------------- |
||
216 | void GetTime(int intime, char *outtime) |
||
217 | { |
||
218 | time_t rawtime; |
||
219 | struct tm * timeinfo; |
||
220 | if(intime < 0) |
||
221 | time(&rawtime); |
||
222 | else |
||
223 | rawtime = (time_t)intime; |
||
224 | timeinfo = localtime(&rawtime); |
||
225 | sprintf(outtime, "%s", asctime(timeinfo)); |
||
226 | int len = strlen(outtime); |
||
227 | if(len) outtime[len-1] = 0; |
||
228 | } |
||
229 | |||
230 | int MyTimer() |
||
231 | { |
||
232 | char cmd[100]; |
||
233 | GetTime(-1, cmd); |
||
234 | if (timeStamp) timeStamp->SetText(cmd); |
||
235 | return 0; |
||
236 | } |
||
237 | |||
238 | int GetChannel() |
||
239 | { |
||
240 | int selectedOutput; |
||
241 | if(vOutCh->GetSelected() < 8) selectedOutput = (vOutCh->GetSelected())+1; |
||
242 | else if( (vOutCh->GetSelected() >= 8) && (vOutCh->GetSelected() < 16) ) selectedOutput = (vOutCh->GetSelected())+93; |
||
243 | else selectedOutput = 1; |
||
244 | |||
245 | return selectedOutput; |
||
246 | } |
||
247 | |||
248 | void remove_ext(char *inname, char *outname) |
||
249 | { |
||
250 | char ctemp[256]; |
||
251 | for(int i = 0; i < (int)strlen(inname); i++) |
||
252 | { |
||
253 | if( (inname[i] == '.') && (i > (int)(strlen(inname)-6)) ) |
||
254 | { |
||
255 | ctemp[i] = '\0'; |
||
256 | sprintf(outname, "%s", ctemp); |
||
257 | break; |
||
258 | } |
||
259 | else |
||
260 | ctemp[i] = inname[i]; |
||
261 | } |
||
262 | |||
263 | if(debugSig) |
||
264 | printf("Outfile (remove_ext): %s\n", outname); |
||
265 | } |
||
266 | |||
267 | void remove_from_last(char *inname, char search, char *outname) |
||
268 | { |
||
269 | char ctemp[256]; |
||
270 | int searchpos = -1; |
||
271 | for(int i = (int)strlen(inname); i >= 0; i--) |
||
272 | { |
||
273 | if(inname[i] == search) |
||
274 | { |
||
275 | searchpos = i; |
||
276 | break; |
||
277 | } |
||
278 | } |
||
279 | |||
280 | for(int i = 0; i < searchpos; i++) |
||
281 | ctemp[i] = inname[i]; |
||
282 | |||
283 | ctemp[searchpos] = '\0'; |
||
284 | sprintf(outname, "%s", ctemp); |
||
285 | |||
286 | if(debugSig) |
||
287 | printf("Outfile (remove_from_last): %s\n", outname); |
||
288 | } |
||
289 | |||
290 | // Peak detection function |
||
291 | int npeaks; |
||
292 | double FindPeaks(double *x, double *par) |
||
293 | { |
||
294 | double result = 0; |
||
295 | for(int i = 0; i < npeaks; i++) |
||
296 | { |
||
297 | double norm = par[3*i]; |
||
298 | double mean = par[3*i+1]; |
||
299 | double sigma = par[3*i+2]; |
||
300 | result += norm*TMath::Gaus(x[0], mean, sigma); |
||
301 | } |
||
302 | return result; |
||
303 | } |
||
304 | |||
305 | // Class related functions -------------------------------------- |
||
306 | |||
307 | // Apply the upper voltage limit from settings pane to main window |
||
308 | void TGAppMainFrame::VoltageLimit() |
||
309 | { |
||
310 | vOut->SetLimitValues(0, vHardlimit->GetNumber() ); |
||
311 | } |
||
312 | |||
313 | // Apply the upper channel limit from settings pane to histogram settings |
||
314 | void TGAppMainFrame::ChannelLimit() |
||
315 | { |
||
316 | selectCh->SetLimitValues(0, (NCH->GetNumber()-1) ); |
||
317 | } |
||
318 | |||
319 | // Enable or disable voltage scan controls |
||
320 | void TGAppMainFrame::EnableVoltScan() |
||
321 | { |
||
322 | if(voltscanOn->IsOn()) |
||
323 | { |
||
324 | vOutStart->SetState(kTRUE); |
||
325 | vOutStop->SetState(kTRUE); |
||
326 | vOutStep->SetState(kTRUE); |
||
327 | } |
||
328 | else |
||
329 | { |
||
330 | vOutStart->SetState(kFALSE); |
||
331 | vOutStop->SetState(kFALSE); |
||
332 | vOutStep->SetState(kFALSE); |
||
333 | } |
||
334 | } |
||
335 | |||
336 | // Enable or disable surface scan controls |
||
337 | void TGAppMainFrame::EnableSurfScan() |
||
338 | { |
||
339 | if(surfscanOn->IsOn()) |
||
340 | { |
||
341 | xPosMin->SetState(kTRUE); |
||
342 | xPosMax->SetState(kTRUE); |
||
343 | xPosStep->SetState(kTRUE); |
||
344 | yPosMin->SetState(kTRUE); |
||
345 | yPosMax->SetState(kTRUE); |
||
346 | yPosStep->SetState(kTRUE); |
||
347 | } |
||
348 | else |
||
349 | { |
||
350 | xPosMin->SetState(kFALSE); |
||
351 | xPosMax->SetState(kFALSE); |
||
352 | xPosStep->SetState(kFALSE); |
||
353 | yPosMin->SetState(kFALSE); |
||
354 | yPosMax->SetState(kFALSE); |
||
355 | yPosStep->SetState(kFALSE); |
||
356 | } |
||
357 | } |
||
358 | |||
359 | // Enable or disable Z axis scan controls |
||
360 | void TGAppMainFrame::EnableZaxisScan() |
||
361 | { |
||
362 | if(zscanOn->IsOn()) |
||
363 | { |
||
364 | zPosMin->SetState(kTRUE); |
||
365 | zPosMax->SetState(kTRUE); |
||
366 | zPosStep->SetState(kTRUE); |
||
367 | } |
||
368 | else |
||
369 | { |
||
370 | zPosMin->SetState(kFALSE); |
||
371 | zPosMax->SetState(kFALSE); |
||
372 | zPosStep->SetState(kFALSE); |
||
373 | } |
||
374 | } |
||
375 | |||
376 | // Toggle clean plots on/off |
||
377 | void TGAppMainFrame::CleanPlotToggle() |
||
378 | { |
||
379 | cleanPlots = cleanOn->IsDown(); |
||
380 | } |
||
381 | |||
382 | // Connect to oscilloscope |
||
383 | void TGAppMainFrame::ConnectToScope() |
||
384 | { |
||
385 | int scopeState = -1; |
||
386 | char *IPaddr = (char*)oscIP->GetText(); |
||
387 | int IPcorr = 0; |
||
388 | char buf[BSIZE]; |
||
389 | |||
390 | if(oscOn == 0) |
||
391 | { |
||
392 | // Check if the IP address has the required three . |
||
393 | for(int i = 0; i < (int)strlen(IPaddr); i++) |
||
394 | if(IPaddr[i] == '.') |
||
395 | IPcorr++; |
||
396 | |||
397 | if( (IPaddr != NULL) && (IPcorr == 3) ) |
||
398 | { |
||
399 | #if WORKSTAT == 'I' |
||
400 | printf("Connecting to oscilloscope.\n"); |
||
401 | retTemp = gScopeDaq->connect(IPaddr); |
||
402 | scopeState = 1; // For testing instead of making a real connection |
||
403 | #else |
||
404 | scopeState = 1; |
||
405 | #endif |
||
406 | } |
||
407 | else |
||
408 | { |
||
409 | scopeState = -1; |
||
410 | printf("Please enter a valid scope IP address.\n"); |
||
411 | } |
||
412 | } |
||
413 | else if(oscOn == 1) |
||
414 | { |
||
415 | #if WORKSTAT == 'I' |
||
416 | printf("Disconnecting from oscilloscope.\n"); |
||
417 | retTemp = gScopeDaq->disconnect(IPaddr); |
||
418 | scopeState = -1; // For testing instead of making a real disconnection |
||
419 | #else |
||
420 | scopeState = -1; |
||
421 | #endif |
||
422 | } |
||
423 | |||
424 | if(scopeState >= 0) |
||
425 | { |
||
426 | setTab->SetEnabled(1, kTRUE); |
||
427 | setTab->SetEnabled(2, kTRUE); |
||
428 | oscIP->SetEnabled(kFALSE); |
||
429 | oscConnect->SetText("Disconnect"); |
||
430 | oscConnect->SetTextJustify(36); |
||
431 | oscConnect->SetWrapLength(-1); |
||
432 | oscConnect->Resize(60,22); |
||
433 | oscOn = 1; |
||
434 | } |
||
435 | else |
||
436 | { |
||
437 | setTab->SetEnabled(1, kFALSE); |
||
438 | setTab->SetEnabled(2, kFALSE); |
||
439 | oscIP->SetEnabled(kTRUE); |
||
440 | oscConnect->SetText("Connect"); |
||
441 | oscConnect->SetTextJustify(36); |
||
442 | oscConnect->SetWrapLength(-1); |
||
443 | oscConnect->Resize(60,22); |
||
444 | oscOn = 0; |
||
445 | } |
||
446 | } |
||
447 | |||
448 | // Set the output voltage |
||
449 | void TGAppMainFrame::SetVoltOut() |
||
450 | { |
||
451 | char cmd[256]; |
||
452 | int outOn; |
||
453 | float outputVoltage; |
||
454 | |||
455 | outputVoltage = vOut->GetNumber(); |
||
456 | |||
457 | if(vOutOnOff->IsOn()) outOn = 1; |
||
458 | else outOn = 0; |
||
459 | |||
460 | fflush(stdout); |
||
461 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -o %d -v %f -s %d", rootdir, GetChannel(), outputVoltage, outOn); |
||
462 | #if WORKSTAT == 'I' |
||
463 | retTemp = system(cmd); |
||
464 | #else |
||
465 | printf("Cmd: %s\n",cmd); |
||
466 | #endif |
||
467 | fflush(stdout); |
||
468 | } |
||
469 | |||
470 | // Get the output voltage |
||
471 | void TGAppMainFrame::GetVoltOut() |
||
472 | { |
||
473 | char cmd[256]; |
||
474 | |||
475 | fflush(stdout); |
||
476 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -o %d -g > %s/curvolt.txt", rootdir, GetChannel(), rootdir); |
||
477 | #if WORKSTAT == 'I' |
||
478 | retTemp = system(cmd); |
||
479 | #else |
||
480 | printf("Cmd: %s\n",cmd); |
||
481 | #endif |
||
482 | fflush(stdout); |
||
483 | |||
484 | #if WORKSTAT == 'I' |
||
485 | FILE* fvolt; |
||
486 | double dtemp; |
||
487 | char ctemp[24]; |
||
488 | sprintf(cmd, "%s/curvolt.txt", rootdir); |
||
489 | fvolt = fopen(cmd, "r"); |
||
490 | |||
491 | if(fvolt != NULL) |
||
492 | { |
||
493 | sprintf(cmd, "WIENER-CRATE-MIB::outputVoltage.u%d = Opaque: Float: %s V\n", GetChannel()-1, "%lf" ); |
||
494 | retTemp = fscanf(fvolt, cmd, &dtemp); |
||
495 | vOut->SetNumber(dtemp); |
||
496 | sprintf(cmd, "WIENER-CRATE-MIB::outputSwitch.u%d = INTEGER: %s\n", GetChannel()-1, "%s" ); |
||
497 | retTemp = fscanf(fvolt, cmd, ctemp); |
||
498 | if( strcmp(ctemp, "On(1)") == 0 ) |
||
499 | vOutOnOff->SetState(kButtonDown); |
||
500 | else if( strcmp(ctemp, "Off(0)") == 0 ) |
||
501 | vOutOnOff->SetState(kButtonUp); |
||
502 | } |
||
503 | |||
504 | fclose(fvolt); |
||
505 | #endif |
||
506 | } |
||
507 | |||
508 | // Reset the output voltage |
||
509 | void TGAppMainFrame::ResetVoltOut() |
||
510 | { |
||
511 | char cmd[256]; |
||
512 | |||
513 | vOut->SetNumber(0.000); |
||
514 | vOutOnOff->SetState(kButtonUp); |
||
515 | |||
516 | fflush(stdout); |
||
517 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -r %d", rootdir, GetChannel()); |
||
518 | #if WORKSTAT == 'I' |
||
519 | retTemp = system(cmd); |
||
520 | #else |
||
521 | printf("Cmd: %s\n",cmd); |
||
522 | #endif |
||
523 | fflush(stdout); |
||
524 | } |
||
525 | |||
526 | // Get the current table position |
||
527 | void TGAppMainFrame::GetPosition() |
||
528 | { |
||
529 | char cmd[256]; |
||
530 | |||
531 | fflush(stdout); |
||
532 | |||
533 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -p > %s/curpos.txt", rootdir, rootdir); // X-axis |
||
534 | fflush(stdout); |
||
535 | #if WORKSTAT == 'I' |
||
536 | retTemp = system(cmd); |
||
537 | #else |
||
538 | printf("Cmd: %s\n",cmd); |
||
539 | #endif |
||
540 | |||
541 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -p >> %s/curpos.txt", rootdir, rootdir); // Y-axis |
||
542 | fflush(stdout); |
||
543 | #if WORKSTAT == 'I' |
||
544 | retTemp = system(cmd); |
||
545 | #else |
||
546 | printf("Cmd: %s\n",cmd); |
||
547 | #endif |
||
548 | |||
549 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -p >> %s/curpos.txt", rootdir, rootdir); // Z-axis |
||
550 | fflush(stdout); |
||
551 | #if WORKSTAT == 'I' |
||
552 | retTemp = system(cmd); |
||
553 | #else |
||
554 | printf("Cmd: %s\n",cmd); |
||
555 | #endif |
||
556 | |||
557 | #if WORKSTAT == 'I' |
||
558 | FILE* fpos; |
||
559 | int itemp; |
||
560 | sprintf(cmd, "%s/curpos.txt", rootdir); |
||
561 | fpos = fopen(cmd, "r"); |
||
562 | |||
563 | if(fpos != NULL) |
||
564 | { |
||
565 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
566 | xPos->SetNumber(itemp); |
||
567 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
568 | yPos->SetNumber(itemp); |
||
569 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
570 | zPos->SetNumber(itemp); |
||
571 | } |
||
572 | |||
573 | fclose(fpos); |
||
574 | #endif |
||
575 | } |
||
576 | |||
577 | // Set the current table position |
||
578 | void TGAppMainFrame::SetPosition() |
||
579 | { |
||
580 | char cmd[256]; |
||
581 | int positX, positY, positZ; |
||
582 | |||
583 | positX = xPos->GetNumber(); |
||
584 | positY = yPos->GetNumber(); |
||
585 | positZ = zPos->GetNumber(); |
||
586 | |||
587 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/MIKRO/mikro_ctrl -n 1 -c m", rootdir, positX, rootdir); |
||
588 | #if WORKSTAT == 'I' |
||
589 | retTemp = system(cmd); |
||
590 | #else |
||
591 | printf("Cmd: %s\n",cmd); |
||
592 | #endif |
||
593 | |||
594 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/MIKRO/mikro_ctrl -n 2 -c m", rootdir, positY, rootdir); |
||
595 | #if WORKSTAT == 'I' |
||
596 | retTemp = system(cmd); |
||
597 | #else |
||
598 | printf("Cmd: %s\n",cmd); |
||
599 | #endif |
||
600 | |||
601 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/MIKRO/mikro_ctrl -n 3 -c m", rootdir, positZ, rootdir); |
||
602 | #if WORKSTAT == 'I' |
||
603 | retTemp = system(cmd); |
||
604 | #else |
||
605 | printf("Cmd: %s\n",cmd); |
||
606 | #endif |
||
607 | } |
||
608 | |||
609 | // Set the current table position to a predetermined HOME position |
||
610 | void TGAppMainFrame::HomePosition() |
||
611 | { |
||
612 | char cmd[256]; |
||
613 | |||
614 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -h", rootdir); // X-axis |
||
615 | #if WORKSTAT == 'I' |
||
616 | retTemp = system(cmd); |
||
617 | #else |
||
618 | printf("Cmd: %s\n",cmd); |
||
619 | #endif |
||
620 | |||
621 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -h", rootdir); // Y-axis |
||
622 | #if WORKSTAT == 'I' |
||
623 | retTemp = system(cmd); |
||
624 | #else |
||
625 | printf("Cmd: %s\n",cmd); |
||
626 | #endif |
||
627 | |||
628 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -h", rootdir); // Z-axis |
||
629 | #if WORKSTAT == 'I' |
||
630 | retTemp = system(cmd); |
||
631 | #else |
||
632 | printf("Cmd: %s\n",cmd); |
||
633 | #endif |
||
634 | } |
||
635 | |||
636 | // Make breakdown voltage plot |
||
637 | void TGAppMainFrame::MakeBreakdownPlot(int nrp, double *volt, double *volterr, double *psep1, double *pseperr1, double *psep2, double *pseperr2, double *psep3, double *pseperr3, char *plotfile) |
||
638 | { |
||
639 | double fparam[2], fparamerr[2], meanval; |
||
640 | TLatex *latex; |
||
641 | char ctemp[256]; |
||
642 | int sortindex[nrp]; |
||
643 | |||
644 | TCanvas *canvas = new TCanvas("canv","canv",900,1200); |
||
645 | canvas->Divide(1,3); |
||
646 | |||
647 | TGraphErrors *gr1 = new TGraphErrors(nrp, volt, psep1, volterr, pseperr1); |
||
648 | TGraphErrors *gr2 = new TGraphErrors(nrp, volt, psep2, volterr, pseperr2); |
||
649 | TGraphErrors *gr3 = new TGraphErrors(nrp, volt, psep3, volterr, pseperr3); |
||
650 | |||
651 | if(!cleanPlots) |
||
652 | gr1->SetTitle("1st - 2nd peak separation"); |
||
653 | else |
||
654 | gr1->SetTitle(); |
||
655 | gr1->SetLineColor(kBlue); |
||
656 | gr1->SetMarkerColor(kBlue); |
||
657 | gr1->SetMarkerStyle(20); |
||
658 | gr1->SetMarkerSize(0.6); |
||
659 | |||
660 | |||
661 | if(!cleanPlots) |
||
662 | gr2->SetTitle("2nd - 3rd peak separation"); |
||
663 | else |
||
664 | gr2->SetTitle(); |
||
665 | gr2->SetLineColor(kMagenta); |
||
666 | gr2->SetMarkerColor(kMagenta); |
||
667 | gr2->SetMarkerStyle(21); |
||
668 | gr2->SetMarkerSize(0.4); |
||
669 | |||
670 | if(!cleanPlots) |
||
671 | gr3->SetTitle("3rd - 4th peak separation"); |
||
672 | else |
||
673 | gr3->SetTitle(); |
||
674 | gr3->SetLineColor(kGreen); |
||
675 | gr3->SetMarkerColor(kGreen); |
||
676 | gr3->SetMarkerStyle(22); |
||
677 | gr3->SetMarkerSize(0.6); |
||
678 | |||
679 | // Plotting the first breakdown voltage plot |
||
680 | canvas->cd(1); |
||
681 | gPad->SetGridx(1); |
||
682 | gPad->SetGridy(1); |
||
683 | |||
684 | gr1->Draw("AP"); |
||
685 | gr1->GetXaxis()->SetTitle("Bias voltage (V)"); |
||
686 | gr1->GetYaxis()->SetTitle("Peak separation"); |
||
687 | gr1->GetYaxis()->CenterTitle(); |
||
688 | gr1->Fit("pol1","Q"); |
||
689 | |||
690 | TF1 *fit1 = gr1->GetFunction("pol1"); |
||
691 | fparam[0] = fit1->GetParameter(0); |
||
692 | fparamerr[0] = fit1->GetParError(0); |
||
693 | fparam[1] = fit1->GetParameter(1); |
||
694 | fparamerr[1] = fit1->GetParError(1); |
||
695 | |||
696 | TMath::Sort(nrp, psep1, sortindex, kFALSE); |
||
697 | |||
698 | meanval = -fparam[0]/fparam[1]; |
||
699 | if(!cleanPlots) |
||
700 | { |
||
701 | sprintf(ctemp, "#splitline{#Delta_{p}(U) = (%.2lf #pm %.2lf)#timesU + (%.2lf #pm %.3lf)}{U_{0} = %.2lf #pm %.3lf}", fparam[0], fparamerr[0], fparam[1], fparamerr[1], meanval, meanval*(TMath::Abs(fparamerr[0]/fparam[0]) + TMath::Abs(fparamerr[1]/fparam[1])) ); |
||
702 | latex = new TLatex(); |
||
703 | latex->SetTextSize(0.039); |
||
704 | latex->DrawLatex(volt[0]-(volt[1]-volt[0]), 0.97*psep1[sortindex[nrp-1]], ctemp); |
||
705 | } |
||
706 | else |
||
707 | printf("#Delta_p(U) = (%.2lf #pm %.2lf)*U + (%.2lf #pm %.3lf)\nU_0 = %.2lf #pm %.3lf", fparam[0], fparamerr[0], fparam[1], fparamerr[1], meanval, meanval*(TMath::Abs(fparamerr[0]/fparam[0]) + TMath::Abs(fparamerr[1]/fparam[1])) ); |
||
708 | |||
709 | // Plotting the second breakdown voltage plot |
||
710 | canvas->cd(2); |
||
711 | gPad->SetGridx(1); |
||
712 | gPad->SetGridy(1); |
||
713 | |||
714 | gr2->Draw("AP"); |
||
715 | gr2->GetXaxis()->SetTitle("Bias voltage (V)"); |
||
716 | gr2->GetYaxis()->SetTitle("Peak separation"); |
||
717 | gr2->GetYaxis()->CenterTitle(); |
||
718 | gr2->Fit("pol1","Q"); |
||
719 | |||
720 | TF1 *fit2 = gr2->GetFunction("pol1"); |
||
721 | fparam[0] = fit2->GetParameter(0); |
||
722 | fparamerr[0] = fit2->GetParError(0); |
||
723 | fparam[1] = fit2->GetParameter(1); |
||
724 | fparamerr[1] = fit2->GetParError(1); |
||
725 | |||
726 | meanval = -fparam[0]/fparam[1]; |
||
727 | if(!cleanPlots) |
||
728 | { |
||
729 | sprintf(ctemp, "#splitline{#Delta_{p}(U) = (%.2lf #pm %.2lf)#timesU + (%.2lf #pm %.3lf)}{U_{0} = %.2lf #pm %.3lf}", fparam[0], fparamerr[0], fparam[1], fparamerr[1], meanval, meanval*(TMath::Abs(fparamerr[0]/fparam[0]) + TMath::Abs(fparamerr[1]/fparam[1])) ); |
||
730 | latex = new TLatex(); |
||
731 | latex->SetTextSize(0.039); |
||
732 | latex->DrawLatex(volt[0]-(volt[1]-volt[0]), 0.97*psep2[sortindex[nrp-1]], ctemp); |
||
733 | } |
||
734 | else |
||
735 | printf("#Delta_p(U) = (%.2lf #pm %.2lf)*U + (%.2lf #pm %.3lf)\nU_0 = %.2lf #pm %.3lf", fparam[0], fparamerr[0], fparam[1], fparamerr[1], meanval, meanval*(TMath::Abs(fparamerr[0]/fparam[0]) + TMath::Abs(fparamerr[1]/fparam[1])) ); |
||
736 | |||
737 | // Plotting the third breakdown voltage plot |
||
738 | canvas->cd(3); |
||
739 | gPad->SetGridx(1); |
||
740 | gPad->SetGridy(1); |
||
741 | |||
742 | gr3->Draw("AP"); |
||
743 | gr3->GetXaxis()->SetTitle("Bias voltage (V)"); |
||
744 | gr3->GetYaxis()->SetTitle("Peak separation"); |
||
745 | gr3->GetYaxis()->CenterTitle(); |
||
746 | gr3->Fit("pol1","Q"); |
||
747 | |||
748 | TF1 *fit3 = gr3->GetFunction("pol1"); |
||
749 | fparam[0] = fit3->GetParameter(0); |
||
750 | fparamerr[0] = fit3->GetParError(0); |
||
751 | fparam[1] = fit3->GetParameter(1); |
||
752 | fparamerr[1] = fit3->GetParError(1); |
||
753 | |||
754 | meanval = -fparam[0]/fparam[1]; |
||
755 | if(!cleanPlots) |
||
756 | { |
||
757 | sprintf(ctemp, "#splitline{#Delta_{p}(U) = (%.2lf #pm %.2lf)#timesU + (%.2lf #pm %.3lf)}{U_{0} = %.2lf #pm %.3lf}", fparam[0], fparamerr[0], fparam[1], fparamerr[1], meanval, meanval*(TMath::Abs(fparamerr[0]/fparam[0]) + TMath::Abs(fparamerr[1]/fparam[1])) ); |
||
758 | latex = new TLatex(); |
||
759 | latex->SetTextSize(0.039); |
||
760 | latex->DrawLatex(volt[0]-(volt[1]-volt[0]), 0.97*psep3[sortindex[nrp-1]], ctemp); |
||
761 | } |
||
762 | else |
||
763 | printf("#Delta_p(U) = (%.2lf #pm %.2lf)*U + (%.2lf #pm %.3lf)\nU_0 = %.2lf #pm %.3lf", fparam[0], fparamerr[0], fparam[1], fparamerr[1], meanval, meanval*(TMath::Abs(fparamerr[0]/fparam[0]) + TMath::Abs(fparamerr[1]/fparam[1])) ); |
||
764 | |||
765 | canvas->SaveAs(plotfile); |
||
766 | } |
||
767 | |||
768 | // Fit the ADC spectrum peaks and make a breakdown voltage plot |
||
769 | void TGAppMainFrame::FitSpectrum(TList *files, int q) |
||
770 | { |
||
771 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
772 | gCanvas->cd(); |
||
773 | TH1F *histtemp; |
||
774 | TSpectrum *spec; |
||
775 | TH1 *histback; |
||
776 | TH1F *h2; |
||
777 | float *xpeaks; |
||
778 | TF1 *fit; |
||
779 | TF1 *fittingfunc; |
||
780 | double *fparam; |
||
781 | double *fparamerr; |
||
782 | double meanparam[20], meanparamerr[20]; |
||
783 | int sortindex[20]; |
||
784 | char exportname[256]; |
||
785 | char paramname[256]; |
||
786 | char ctemp[256]; |
||
787 | |||
788 | FILE *fp; |
||
789 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
790 | sprintf(paramname, "%s_fitresult.txt", ctemp); |
||
791 | fp = fopen(paramname, "w"); |
||
792 | fclose(fp); |
||
793 | |||
794 | int peaklimit = 5; |
||
795 | int p = 0; |
||
796 | double dtemp; |
||
797 | double volt[files->GetSize()], volterr[files->GetSize()], sep[3][files->GetSize()], seperr[3][files->GetSize()]; |
||
798 | for(int m = 0; m < files->GetSize(); m++) |
||
799 | { |
||
800 | volt[m] = 0; volterr[m] = 0; |
||
801 | for(int i = 0; i < 3; i++) |
||
802 | { sep[i][m] = 0; seperr[i][m] = 0; } |
||
803 | } |
||
804 | |||
805 | for(int m = 0; m < files->GetSize(); m++) |
||
806 | { |
||
807 | for(int i = 0; i < 20; i++) { meanparam[20] = 0; meanparamerr[20] = 0; } |
||
808 | |||
809 | DisplayHistogram( (char*)(files->At(m)->GetTitle()), 0); |
||
810 | dtemp = evtheader.biasvolt; |
||
811 | gCanvas->Modified(); |
||
812 | gCanvas->Update(); |
||
813 | |||
814 | histtemp = (TH1F*)gCanvas->GetPrimitive(histname); |
||
815 | npeaks = 20; |
||
816 | double par[3000]; |
||
817 | spec = new TSpectrum(npeaks); |
||
818 | // Find spectrum background |
||
819 | histback = spec->Background(histtemp, (int)fitInter->GetNumber(), "same"); |
||
820 | // Clone histogram and subtract background from it |
||
821 | h2 = (TH1F*)histtemp->Clone("h2"); |
||
822 | h2->Add(histback, -1); |
||
823 | // Search for the peaks |
||
824 | int found = spec->Search(h2, fitSigma->GetNumber(), "goff", fitTresh->GetNumber() ); |
||
825 | printf("Found %d candidates to fit.\n",found); |
||
826 | npeaks = found; |
||
827 | |||
828 | xpeaks = spec->GetPositionX(); |
||
829 | for(int i = 0; i < found; i++) |
||
830 | { |
||
831 | float xp = xpeaks[i]; |
||
832 | int bin = h2->GetXaxis()->FindBin(xp); |
||
833 | float yp = h2->GetBinContent(bin); |
||
834 | par[3*i] = yp; |
||
835 | par[3*i+1] = xp; |
||
836 | // par[3*i+2] = 3; |
||
837 | par[3*i+2] = (double)fitSigma->GetNumber(); |
||
838 | // printf("Peak %d: %f\n", i+1, xp); |
||
839 | } |
||
840 | |||
841 | // Fit the histogram |
||
842 | fit = new TF1("fit", FindPeaks, 0, 400, 3*npeaks); |
||
843 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
||
844 | fit->SetParameters(par); |
||
845 | fit->SetNpx(300); |
||
846 | h2->Fit("fit","Q"); // for quiet mode, add Q |
||
847 | fittingfunc = h2->GetFunction("fit"); |
||
848 | fparam = fittingfunc->GetParameters(); |
||
849 | fparamerr = fittingfunc->GetParErrors(); |
||
850 | |||
851 | // Gather the parameters (mean peak value for now) |
||
852 | int j = 1; |
||
853 | int nrfit = 0; |
||
854 | while(1) |
||
855 | { |
||
856 | if( (fparam[j] < 1.E-30) || (fparamerr[j] < 1.E-10) ) |
||
857 | break; |
||
858 | else |
||
859 | { |
||
860 | if(fparam[j] > 0) |
||
861 | { |
||
862 | meanparam[nrfit] = fparam[j]; |
||
863 | meanparamerr[nrfit] = fparamerr[j]; |
||
864 | nrfit++; |
||
865 | } |
||
866 | } |
||
867 | |||
868 | j+=3; |
||
869 | } |
||
870 | |||
871 | // Write out parameters to a file |
||
872 | fp = fopen(paramname, "a"); |
||
873 | |||
874 | fprintf(fp, "%d\t", nrfit); |
||
875 | TMath::Sort(nrfit, meanparam, sortindex, kFALSE); |
||
876 | for(int i = 0; i < nrfit; i++) |
||
877 | { |
||
878 | if(debugSig) |
||
879 | printf("Peak %d: %lf\t%lf\n", i+1, meanparam[sortindex[i]], meanparamerr[sortindex[i]]); |
||
880 | fprintf(fp, "%le\t%le\t", meanparam[sortindex[i]], meanparamerr[sortindex[i]]); |
||
881 | } |
||
882 | printf("\n"); |
||
883 | fprintf(fp, "\n"); |
||
884 | |||
885 | fclose(fp); |
||
886 | |||
887 | h2->SetStats(0); |
||
888 | |||
889 | gCanvas->Modified(); |
||
890 | gCanvas->Update(); |
||
891 | |||
892 | // Save each fitting plot |
||
893 | if(exfitplots->IsDown()) |
||
894 | { |
||
895 | remove_ext((char*)files->At(m)->GetTitle(), ctemp); |
||
896 | sprintf(exportname, "%s_fit.pdf", ctemp); |
||
897 | gCanvas->SaveAs(exportname); |
||
898 | } |
||
899 | |||
900 | // Get points for mean peak values and create a breakdown voltage plot |
||
901 | if(nrfit >= peaklimit) |
||
902 | { |
||
903 | sep[0][p] = meanparam[sortindex[2]] - meanparam[sortindex[1]]; |
||
904 | sep[1][p] = meanparam[sortindex[3]] - meanparam[sortindex[2]]; |
||
905 | sep[2][p] = meanparam[sortindex[4]] - meanparam[sortindex[3]]; |
||
906 | |||
907 | seperr[0][p] = TMath::Abs(meanparamerr[sortindex[2]]) + TMath::Abs(meanparamerr[sortindex[1]]); |
||
908 | seperr[1][p] = TMath::Abs(meanparamerr[sortindex[3]]) + TMath::Abs(meanparamerr[sortindex[2]]); |
||
909 | seperr[2][p] = TMath::Abs(meanparamerr[sortindex[4]]) + TMath::Abs(meanparamerr[sortindex[3]]); |
||
910 | |||
911 | volt[p] = dtemp; |
||
912 | volterr[p] = 1.e-4; |
||
913 | |||
914 | if(debugSig) |
||
915 | printf("p=%d:\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\t%lf\n", p, volt[p], sep[0][p], seperr[0][p], sep[1][p], seperr[1][p], sep[2][p], seperr[2][p]); |
||
916 | |||
917 | // Accept only the points with a small enough error |
||
918 | if( (seperr[0][p]/sep[0][p] < accError->GetNumber()) && (seperr[1][p]/sep[1][p] < accError->GetNumber()) && (seperr[2][p]/sep[2][p] < accError->GetNumber()) ) |
||
919 | p++; |
||
920 | else |
||
921 | printf("Point (at %.2lfV) rejected due to errors: %lf, %lf, %lf\n", volt[p], seperr[0][p]/sep[0][p], seperr[1][p]/sep[1][p], seperr[2][p]/sep[2][p]); |
||
922 | } |
||
923 | |||
924 | if(q == 1) break; |
||
925 | } |
||
926 | |||
927 | // Plot & fit breakdown voltage plots |
||
928 | if(q > 1) |
||
929 | { |
||
930 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
931 | sprintf(paramname, "%s_breakdown.pdf", ctemp); |
||
932 | MakeBreakdownPlot(p, volt, volterr, sep[0], seperr[0], sep[1], seperr[1], sep[2], seperr[2], paramname); |
||
933 | } |
||
934 | } |
||
935 | |||
936 | // Plotting of PDF and CDF functions for the edge (with the added fit) |
||
937 | void TGAppMainFrame::EdgeDetection(TGraph *pdf, TGraph *cdf, char *outname, TCanvas *g1dCanvas, double pdfmax, int direction) |
||
938 | { |
||
939 | // double x, y; |
||
940 | |||
941 | pdf->Fit("gaus","Q"); |
||
942 | pdf->GetFunction("gaus")->SetNpx(400); |
||
943 | /* |
||
944 | for(int i = 0; i < nrpoints; i++) |
||
945 | { |
||
946 | pdf->GetPoint(i, x, y); |
||
947 | pdf->SetPoint(i, x, (y/pdfmax) ); |
||
948 | } |
||
949 | */ |
||
950 | gStyle->SetOptFit(1); |
||
951 | |||
952 | cdf->Draw("AL"); |
||
953 | gPad->Update(); |
||
954 | pdf->Draw("LP"); |
||
955 | |||
956 | g1dCanvas->Modified(); |
||
957 | g1dCanvas->Update(); |
||
958 | |||
959 | TPaveStats *stats = (TPaveStats*)pdf->FindObject("stats"); |
||
960 | if(!cleanPlots) |
||
961 | { |
||
962 | // stats->SetX1NDC(0.14); stats->SetX2NDC(0.28); |
||
963 | // stats->SetY1NDC(0.83); stats->SetY2NDC(0.96); |
||
964 | stats->SetX1NDC(0.86); stats->SetX2NDC(1.0); |
||
965 | stats->SetY1NDC(0.87); stats->SetY2NDC(1.0); |
||
966 | } |
||
967 | else |
||
968 | { |
||
969 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
970 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
971 | } |
||
972 | |||
973 | g1dCanvas->SetGridx(1); |
||
974 | g1dCanvas->SetGridy(1); |
||
975 | if(direction == 1) |
||
976 | cdf->GetXaxis()->SetTitle("X [#mum]"); |
||
977 | else if(direction == 2) |
||
978 | cdf->GetXaxis()->SetTitle("Y [#mum]"); |
||
979 | cdf->GetXaxis()->CenterTitle(kTRUE); |
||
980 | cdf->GetXaxis()->SetLabelSize(0.022); |
||
981 | cdf->GetYaxis()->SetTitle("Normalized ADC integral"); |
||
982 | // cdf->GetYaxis()->SetTitle("Normalized ADC integral (CDF)"); |
||
983 | // cdf->GetYaxis()->SetTitleColor(kBlue); |
||
984 | cdf->GetYaxis()->CenterTitle(kTRUE); |
||
985 | cdf->GetYaxis()->SetLabelSize(0.022); |
||
986 | cdf->GetYaxis()->SetRangeUser(0,1); |
||
987 | cdf->GetYaxis()->SetTitleSize(0.030); |
||
988 | // cdf->GetYaxis()->SetLabelColor(kBlue); |
||
989 | if(!cleanPlots) |
||
990 | cdf->SetTitle("SiPM edge detection"); |
||
991 | else |
||
992 | cdf->SetTitle(); |
||
993 | cdf->SetLineColor(kBlue); |
||
994 | pdf->SetLineWidth(2); |
||
995 | cdf->SetLineWidth(2); |
||
996 | |||
997 | /* TGaxis *axis = new TGaxis(gPad->GetUxmax(), 0, gPad->GetUxmax(), 1, 0, pdfmax, 510, "+L"); |
||
998 | axis->Draw(); |
||
999 | axis->SetTitle("Normalized ADC integral (PDF)"); |
||
1000 | axis->SetTitleSize(0.035); |
||
1001 | axis->CenterTitle(); |
||
1002 | axis->SetTitleColor(kBlack); |
||
1003 | axis->SetTitleFont(42); |
||
1004 | axis->SetLabelSize(0.022); |
||
1005 | axis->SetLabelColor(kBlack);*/ |
||
1006 | |||
1007 | g1dCanvas->Modified(); |
||
1008 | g1dCanvas->Update(); |
||
1009 | |||
1010 | g1dCanvas->SaveAs(outname); |
||
1011 | } |
||
1012 | |||
1013 | // Integrate the spectrum |
||
1014 | void TGAppMainFrame::IntegSpectrum(TList *files, int direction) |
||
1015 | { |
||
1016 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
1017 | char ctemp[256]; |
||
1018 | int j, k = 0, m = 0, n = 0; |
||
1019 | |||
1020 | TCanvas *gCanvas = new TCanvas("canv","canv",900,900); |
||
1021 | TCanvas *g1dCanvas = new TCanvas("canv1d","canv1d",1200,900); |
||
1022 | TTree *header_data, *meas_data; |
||
1023 | double *integralCount, *integralAcc; |
||
1024 | integralCount = new double[nrfiles]; |
||
1025 | integralAcc = new double[nrfiles]; |
||
1026 | // double xsurfmin, ysurfmin, zsurfmin; |
||
1027 | double *surfx, *surfy, *surfz; |
||
1028 | surfx = new double[nrfiles]; |
||
1029 | surfy = new double[nrfiles]; |
||
1030 | surfz = new double[nrfiles]; |
||
1031 | for(int i = 0; i < (int)nrfiles; i++) {integralCount[i] = 0; integralAcc[i] = 0; } |
||
1032 | |||
1033 | TGraph *gScan[2]; // graphs for PDF and CDF functions |
||
1034 | double pdfmax = -1; |
||
1035 | TGraph2D *gScan2D; |
||
1036 | gScan2D = new TGraph2D(); |
||
1037 | int nrentries; |
||
1038 | double minInteg, maxInteg; |
||
1039 | |||
1040 | char exportname[256]; |
||
1041 | |||
1042 | if(files->GetSize() > 0) |
||
1043 | { |
||
1044 | for(int i = 0; i < (int)files->GetSize(); i++) |
||
1045 | { |
||
1046 | n++; |
||
1047 | if(files->At(i)) |
||
1048 | { |
||
1049 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
||
1050 | inroot = new TFile(ctemp, "READ"); |
||
1051 | |||
1052 | inroot->GetObject("header_data", header_data); |
||
1053 | inroot->GetObject("meas_data", meas_data); |
||
1054 | |||
1055 | // Reading the header |
||
1056 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
||
1057 | header_data->GetEntry(0); |
||
1058 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
||
1059 | header_data->GetEntry(0); |
||
1060 | header_data->SetBranchAddress("zpos", &evtheader.zpos); |
||
1061 | header_data->GetEntry(0); |
||
1062 | |||
1063 | char rdc[256]; |
||
1064 | j = selectCh->GetNumber(); |
||
1065 | double rangetdc[2]; |
||
1066 | rangetdc[0] = tdcMinwindow->GetNumber(); |
||
1067 | rangetdc[1] = tdcMaxwindow->GetNumber(); |
||
1068 | |||
1069 | k = 0; |
||
1070 | m = 0; |
||
1071 | |||
1072 | // Reading the data |
||
1073 | for(int e = 0; e < meas_data->GetEntries(); e++) |
||
1074 | { |
||
1075 | sprintf(rdc, "ADC%d", j); |
||
1076 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
||
1077 | meas_data->GetEntry(e); |
||
1078 | |||
1079 | sprintf(rdc, "TDC%d", j); |
||
1080 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
||
1081 | meas_data->GetEntry(e); |
||
1082 | |||
1083 | // If our data point is inside the TDC window |
||
1084 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
||
1085 | { |
||
1086 | k++; |
||
1087 | m += evtdata.adcdata[j]; |
||
1088 | } |
||
1089 | } |
||
1090 | |||
1091 | /* if(n == 1) // these values can be used to set 0 value at first X, Y and Z positions |
||
1092 | { |
||
1093 | xsurfmin = evtheader.xpos; |
||
1094 | ysurfmin = evtheader.ypos; |
||
1095 | zsurfmin = evtheader.zpos; |
||
1096 | } |
||
1097 | surfx[i] = (double)(evtheader.xpos-xsurfmin)*lenconversion; |
||
1098 | surfy[i] = (double)(evtheader.ypos-ysurfmin)*lenconversion; |
||
1099 | surfz[i] = (double)(evtheader.zpos-zsurfmin)*lenconversion;*/ |
||
1100 | surfx[i] = (double)(evtheader.xpos*lenconversion); |
||
1101 | surfy[i] = (double)(evtheader.ypos*lenconversion); |
||
1102 | surfz[i] = (double)(evtheader.zpos*lenconversion); |
||
1103 | |||
1104 | /* surfx[i] = evtheader.xpos; |
||
1105 | surfy[i] = evtheader.ypos; |
||
1106 | surfz[i] = evtheader.zpos; |
||
1107 | */ |
||
1108 | integralCount[i] += ((double)m)/((double)k); |
||
1109 | |||
1110 | delete inroot; |
||
1111 | } |
||
1112 | } |
||
1113 | |||
1114 | nrentries = n; |
||
1115 | printf("%d files were selected.\n", nrentries); |
||
1116 | |||
1117 | double curzval = surfz[0]; |
||
1118 | j = 0; |
||
1119 | int acc = 0; |
||
1120 | int zb; |
||
1121 | for(int i = 0; i <= nrentries; i++) |
||
1122 | { |
||
1123 | if(acc == nrentries) |
||
1124 | { |
||
1125 | minInteg = TMath::MinElement(j, integralAcc); |
||
1126 | |||
1127 | for(int za = 0; za < j; za++) |
||
1128 | integralAcc[za] = integralAcc[za] - minInteg; |
||
1129 | |||
1130 | maxInteg = TMath::MaxElement(j, integralAcc); |
||
1131 | |||
1132 | for(int za = 0; za < j; za++) |
||
1133 | { |
||
1134 | zb = i-j+za; |
||
1135 | integralCount[zb] = integralAcc[za]/maxInteg; |
||
1136 | if(debugSig) |
||
1137 | printf("Integral check 2 (i=%d,j=%d,za=%d,z=%.2lf,zb=%d): %lf\t%lf\n", i, j, za, surfz[i-j], zb, integralCount[zb], integralAcc[za]/maxInteg); |
||
1138 | } |
||
1139 | |||
1140 | // Plotting of PDF and CDF functions for the edge (with the added fit) |
||
1141 | gScan[1] = new TGraph(); |
||
1142 | for(int za = 0; za < j; za++) |
||
1143 | { |
||
1144 | zb = i-j+za; |
||
1145 | if(direction == 1) |
||
1146 | gScan[1]->SetPoint(za, (double)surfx[zb], (double)integralAcc[za]/maxInteg); |
||
1147 | else if(direction == 2) |
||
1148 | gScan[1]->SetPoint(za, (double)surfy[zb], (double)integralAcc[za]/maxInteg); |
||
1149 | |||
1150 | if( ((integralAcc[za+1]-integralAcc[za])/maxInteg > pdfmax) && (za < j-1) ) |
||
1151 | pdfmax = (integralAcc[za+1]-integralAcc[za])/maxInteg; |
||
1152 | } |
||
1153 | |||
1154 | pdfmax = (TMath::Ceil(pdfmax*10))/10.; |
||
1155 | |||
1156 | gScan[0] = new TGraph(); |
||
1157 | for(int za = j-1; za >= 0; za--) |
||
1158 | { |
||
1159 | zb = (i-1)-(j-1)+za; |
||
1160 | if((integralAcc[za]-integralAcc[za-1])/(maxInteg) < 0) |
||
1161 | { |
||
1162 | if(direction == 1) |
||
1163 | gScan[0]->SetPoint(za, (double)surfx[zb], 0); |
||
1164 | else if(direction == 2) |
||
1165 | gScan[0]->SetPoint(za, (double)surfy[zb], 0); |
||
1166 | } |
||
1167 | else |
||
1168 | { |
||
1169 | if(direction == 1) |
||
1170 | gScan[0]->SetPoint(za, (double)surfx[zb], (integralAcc[za]-integralAcc[za-1])/(maxInteg)); |
||
1171 | else if(direction == 2) |
||
1172 | gScan[0]->SetPoint(za, (double)surfy[zb], (integralAcc[za]-integralAcc[za-1])/(maxInteg)); |
||
1173 | // gScan[0]->SetPoint(za, (double)surfx[zb], (integralAcc[za]-integralAcc[za-1])/(pdfmax*maxInteg)); |
||
1174 | } |
||
1175 | } |
||
1176 | |||
1177 | remove_from_last((char*)files->At(i-1)->GetTitle(), '_', ctemp); |
||
1178 | sprintf(exportname, "%s_edge.pdf", ctemp); |
||
1179 | EdgeDetection(gScan[0], gScan[1], exportname, g1dCanvas, pdfmax, direction); |
||
1180 | |||
1181 | // delete gScan[0]; |
||
1182 | // delete gScan[1]; |
||
1183 | |||
1184 | i--; |
||
1185 | pdfmax = 0; |
||
1186 | break; |
||
1187 | } |
||
1188 | else |
||
1189 | { |
||
1190 | if(surfz[i] == curzval) |
||
1191 | { |
||
1192 | integralAcc[j] = integralCount[i]; |
||
1193 | if(debugSig) |
||
1194 | printf("Integral check 1 (i=%d,j=%d,z=%.2lf): %lf\t%lf\n", i, j, surfz[i], integralCount[i], integralAcc[j]); |
||
1195 | j++; |
||
1196 | acc++; |
||
1197 | } |
||
1198 | else |
||
1199 | { |
||
1200 | minInteg = TMath::MinElement(j, integralAcc); |
||
1201 | |||
1202 | for(int za = 0; za < j; za++) |
||
1203 | integralAcc[za] = integralAcc[za] - minInteg; |
||
1204 | |||
1205 | maxInteg = TMath::MaxElement(j, integralAcc); |
||
1206 | |||
1207 | for(int za = 0; za < j; za++) |
||
1208 | { |
||
1209 | zb = i-j+za; |
||
1210 | integralCount[zb] = integralAcc[za]/maxInteg; |
||
1211 | if(debugSig) |
||
1212 | printf("Integral check 2 (i=%d,j=%d,za=%d,z=%.2lf,zb=%d): %lf\t%lf\n", i, j, za, surfz[i-j], zb, integralCount[zb], integralAcc[za]/maxInteg); |
||
1213 | } |
||
1214 | |||
1215 | curzval = surfz[i]; |
||
1216 | i--; |
||
1217 | |||
1218 | // Plotting of PDF and CDF functions for the edge (with the added fit) |
||
1219 | gScan[1] = new TGraph(); |
||
1220 | for(int za = 0; za < j; za++) |
||
1221 | { |
||
1222 | zb = i-(j-1)+za; |
||
1223 | if(direction == 1) |
||
1224 | gScan[1]->SetPoint(za, (double)surfx[zb], (double)integralAcc[za]/maxInteg); |
||
1225 | else if(direction == 2) |
||
1226 | gScan[1]->SetPoint(za, (double)surfy[zb], (double)integralAcc[za]/maxInteg); |
||
1227 | |||
1228 | if( ((integralAcc[za+1]-integralAcc[za])/maxInteg > pdfmax) && (za < j-1) ) |
||
1229 | pdfmax = (integralAcc[za+1]-integralAcc[za])/maxInteg; |
||
1230 | } |
||
1231 | |||
1232 | pdfmax = (TMath::Ceil(pdfmax*10))/10.; |
||
1233 | |||
1234 | gScan[0] = new TGraph(); |
||
1235 | for(int za = j-1; za >= 0; za--) |
||
1236 | { |
||
1237 | zb = i-(j-1)+za; |
||
1238 | if((integralAcc[za]-integralAcc[za-1])/(maxInteg) < 0) |
||
1239 | { |
||
1240 | if(direction == 1) |
||
1241 | gScan[0]->SetPoint(za, (double)surfx[zb], 0); |
||
1242 | else if(direction == 2) |
||
1243 | gScan[0]->SetPoint(za, (double)surfy[zb], 0); |
||
1244 | } |
||
1245 | else |
||
1246 | { |
||
1247 | if(direction == 1) |
||
1248 | gScan[0]->SetPoint(za, (double)surfx[zb], (integralAcc[za]-integralAcc[za-1])/(maxInteg)); |
||
1249 | else if(direction == 2) |
||
1250 | gScan[0]->SetPoint(za, (double)surfy[zb], (integralAcc[za]-integralAcc[za-1])/(maxInteg)); |
||
1251 | // gScan[0]->SetPoint(za, (double)surfx[zb], (integralAcc[za]-integralAcc[za-1])/(pdfmax*maxInteg)); |
||
1252 | } |
||
1253 | } |
||
1254 | |||
1255 | remove_from_last((char*)files->At(i)->GetTitle(), '_', ctemp); |
||
1256 | sprintf(exportname, "%s_edge.pdf", ctemp); |
||
1257 | EdgeDetection(gScan[0], gScan[1], exportname, g1dCanvas, pdfmax, direction); |
||
1258 | |||
1259 | delete gScan[0]; |
||
1260 | delete gScan[1]; |
||
1261 | |||
1262 | j = 0; |
||
1263 | pdfmax = 0; |
||
1264 | } |
||
1265 | } |
||
1266 | } |
||
1267 | |||
1268 | // delete g1dCanvas; |
||
1269 | |||
1270 | double range[4]; |
||
1271 | if(direction == 1) |
||
1272 | { |
||
1273 | range[0] = TMath::MinElement(nrentries, surfx); |
||
1274 | range[1] = TMath::MaxElement(nrentries, surfx); |
||
1275 | } |
||
1276 | else if(direction == 2) |
||
1277 | { |
||
1278 | range[0] = TMath::MinElement(nrentries, surfy); |
||
1279 | range[1] = TMath::MaxElement(nrentries, surfy); |
||
1280 | } |
||
1281 | else |
||
1282 | { |
||
1283 | range[0] = TMath::MinElement(nrentries, surfx); |
||
1284 | range[1] = TMath::MaxElement(nrentries, surfx); |
||
1285 | } |
||
1286 | range[2] = TMath::MinElement(nrentries, surfz); |
||
1287 | range[3] = TMath::MaxElement(nrentries, surfz); |
||
1288 | |||
1289 | // Plotting of 2D edge plot |
||
1290 | for(int i = 0; i < nrentries; i++) |
||
1291 | { |
||
1292 | if(direction == 1) |
||
1293 | { |
||
1294 | if(debugSig) |
||
1295 | printf("%.2lf\t%.2lf\t%lf\n", surfx[i], surfz[i], integralCount[i]); |
||
1296 | gScan2D->SetPoint(i, surfx[i], surfz[i], integralCount[i]); |
||
1297 | } |
||
1298 | else if(direction == 2) |
||
1299 | { |
||
1300 | if(debugSig) |
||
1301 | printf("%.2lf\t%.2lf\t%lf\n", surfy[i], surfz[i], integralCount[i]); |
||
1302 | gScan2D->SetPoint(i, surfy[i], surfz[i], integralCount[i]); |
||
1303 | } |
||
1304 | } |
||
1305 | |||
1306 | gCanvas->cd(); |
||
1307 | gStyle->SetPalette(1); |
||
1308 | gScan2D->Draw("COLZ"); |
||
1309 | |||
1310 | gCanvas->Modified(); |
||
1311 | gCanvas->Update(); |
||
1312 | |||
1313 | if(direction == 1) |
||
1314 | gScan2D->GetXaxis()->SetTitle("X [#mum]"); |
||
1315 | else if(direction == 2) |
||
1316 | gScan2D->GetXaxis()->SetTitle("Y [#mum]"); |
||
1317 | gScan2D->GetXaxis()->CenterTitle(kTRUE); |
||
1318 | gScan2D->GetXaxis()->SetLabelSize(0.022); |
||
1319 | gScan2D->GetXaxis()->SetRangeUser(range[0], range[1]); |
||
1320 | gScan2D->GetXaxis()->SetNoExponent(); |
||
1321 | gScan2D->GetYaxis()->SetTitle("Z [#mum]"); |
||
1322 | gScan2D->GetYaxis()->SetTitleOffset(1.3); |
||
1323 | gScan2D->GetYaxis()->CenterTitle(kTRUE); |
||
1324 | gScan2D->GetYaxis()->SetLabelSize(0.022); |
||
1325 | gScan2D->GetYaxis()->SetRangeUser(range[2], range[3]); |
||
1326 | TGaxis *yax = (TGaxis*)gScan2D->GetYaxis(); |
||
1327 | yax->SetMaxDigits(4); |
||
1328 | if(!cleanPlots) |
||
1329 | gScan2D->SetTitle("Laser focal point"); |
||
1330 | else |
||
1331 | gScan2D->SetTitle(); |
||
1332 | |||
1333 | gCanvas->Modified(); |
||
1334 | gCanvas->Update(); |
||
1335 | |||
1336 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
1337 | sprintf(exportname, "%s", ctemp); |
||
1338 | remove_from_last(exportname, '_', ctemp); |
||
1339 | if(direction == 1) |
||
1340 | sprintf(exportname, "%s_xdir_focalpoint.pdf", ctemp); |
||
1341 | else if(direction == 2) |
||
1342 | sprintf(exportname, "%s_ydir_focalpoint.pdf", ctemp); |
||
1343 | gCanvas->SaveAs(exportname); |
||
1344 | } |
||
1345 | } |
||
1346 | |||
1347 | void TGAppMainFrame::RunMeas(void *ptr, int runCase, int zaxisscan) |
||
1348 | { |
||
1349 | printf("Start of Run, run case %d\n", runCase); |
||
1350 | float progVal; |
||
1351 | |||
1352 | char ctemp[256]; |
||
1353 | char fname[256]; |
||
1354 | |||
1355 | remove_ext((char*)fileName->GetText(), ctemp); |
||
1356 | // printf("Save name: %s\nNo extension: %s\n", fileName->GetText(), ctemp); |
||
1357 | |||
1358 | // Open file for writing |
||
1359 | /* if(runCase == 0) |
||
1360 | { |
||
1361 | sprintf(fname, "rm %s_%s", ctemp, histExtAll); |
||
1362 | retTemp = system(fname); |
||
1363 | }*/ // deleting might not be necesary due to RECREATE in root file open |
||
1364 | |||
1365 | if( voltscanOn->IsOn() || surfscanOn->IsOn() ) |
||
1366 | { |
||
1367 | if(zaxisscan == 0) |
||
1368 | { |
||
1369 | if(runCase < 10) |
||
1370 | sprintf(fname, "%s_0000%d%s", ctemp, runCase, histExt); |
||
1371 | else if( (runCase >= 10) && (runCase < 100) ) |
||
1372 | sprintf(fname, "%s_000%d%s", ctemp, runCase, histExt); |
||
1373 | else if( (runCase >= 100) && (runCase < 1000) ) |
||
1374 | sprintf(fname, "%s_00%d%s", ctemp, runCase, histExt); |
||
1375 | else if( (runCase >= 1000) && (runCase < 10000) ) |
||
1376 | sprintf(fname, "%s_0%d%s", ctemp, runCase, histExt); |
||
1377 | else if( (runCase >= 10000) && (runCase < 100000) ) |
||
1378 | sprintf(fname, "%s_%d%s", ctemp, runCase, histExt); |
||
1379 | } |
||
1380 | else if(zaxisscan == 1) |
||
1381 | { |
||
1382 | if(runCase < 10) |
||
1383 | sprintf(fname, "%s_z%d_0000%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
1384 | else if( (runCase >= 10) && (runCase < 100) ) |
||
1385 | sprintf(fname, "%s_z%d_000%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
1386 | else if( (runCase >= 100) && (runCase < 1000) ) |
||
1387 | sprintf(fname, "%s_z%d_00%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
1388 | else if( (runCase >= 1000) && (runCase < 10000) ) |
||
1389 | sprintf(fname, "%s_z%d_0%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
1390 | else if( (runCase >= 10000) && (runCase < 100000) ) |
||
1391 | sprintf(fname, "%s_z%d_0%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
1392 | } |
||
1393 | } |
||
1394 | else if( !voltscanOn->IsOn() && !surfscanOn->IsOn() ) |
||
1395 | sprintf(fname, "%s%s", ctemp, histExt); |
||
1396 | // printf("Rootfile: %s\n", fname); |
||
1397 | |||
1398 | // Check if set voltage is below the hard limit |
||
1399 | if( vOut->GetNumber() > vHardlimit->GetNumber() ) |
||
1400 | { |
||
1401 | printf("Voltage hard limit triggered (%lf > %lf)!\n", vOut->GetNumber(), vHardlimit->GetNumber() ); |
||
1402 | vOut->SetNumber( vHardlimit->GetNumber() ); |
||
1403 | } |
||
1404 | |||
1405 | outroot = new TFile(fname, "RECREATE"); |
||
1406 | |||
1407 | TTree *header_data = new TTree("header_data", "Header information for the measurement."); |
||
1408 | TTree *meas_data = new TTree("meas_data", "Saved measurement data."); |
||
1409 | |||
1410 | // Branches for the header |
||
1411 | header_data->Branch("nrch", &evtheader.nrch, "nrch/I"); |
||
1412 | header_data->Branch("timestamp", &evtheader.timestamp, "timestamp/I"); |
||
1413 | header_data->Branch("biasvolt", &evtheader.biasvolt, "biasvolt/D"); |
||
1414 | header_data->Branch("xpos", &evtheader.xpos, "xpos/I"); |
||
1415 | header_data->Branch("ypos", &evtheader.ypos, "ypos/I"); |
||
1416 | header_data->Branch("zpos", &evtheader.zpos, "zpos/I"); |
||
1417 | header_data->Branch("temperature", &evtheader.temperature, "temperature/D"); |
||
1418 | header_data->Branch("laserinfo", &evtheader.laserinfo, "laserinfo/C"); |
||
1419 | |||
1420 | evtheader.nrch = (int)NCH->GetNumber()*2; |
||
1421 | evtheader.timestamp = (int)time(NULL); |
||
1422 | evtheader.biasvolt = (double)vOut->GetNumber(); |
||
1423 | evtheader.xpos = (int)xPos->GetNumber(); |
||
1424 | evtheader.ypos = (int)yPos->GetNumber(); |
||
1425 | evtheader.zpos = (int)zPos->GetNumber(); |
||
1426 | evtheader.temperature = 25.0; // Still to do!!! |
||
1427 | sprintf(evtheader.laserinfo, "%s", laserInfo->GetText()); |
||
1428 | |||
1429 | char histtime[256]; |
||
1430 | GetTime(evtheader.timestamp, histtime); |
||
1431 | |||
1432 | printf("Save file header information:\n"); |
||
1433 | printf("- Number of channels: %d\n", evtheader.nrch); |
||
1434 | printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime); |
||
1435 | printf("- Bias voltage: %lf\n", evtheader.biasvolt); |
||
1436 | printf("- Table position (X,Y,Z): %d, %d, %d\n", evtheader.xpos, evtheader.ypos, evtheader.zpos); |
||
1437 | printf("- Temperature: %lf\n", evtheader.temperature); |
||
1438 | printf("- Laser and filter settings: %s\n", evtheader.laserinfo); |
||
1439 | |||
1440 | header_data->Fill(); |
||
1441 | |||
1442 | // Branches for ADC and TDC data |
||
1443 | for(int i = 0; i < evtheader.nrch/2; i++) |
||
1444 | { |
||
1445 | sprintf(ctemp, "ADC%d", i); |
||
1446 | sprintf(fname, "ADC%d/I", i); |
||
1447 | meas_data->Branch(ctemp, &evtdata.adcdata[i], fname); |
||
1448 | |||
1449 | sprintf(ctemp, "TDC%d", i); |
||
1450 | sprintf(fname, "TDC%d/I", i); |
||
1451 | meas_data->Branch(ctemp, &evtdata.tdcdata[i], fname); |
||
1452 | } |
||
1453 | |||
1454 | int neve = (int) evtNum->GetNumber(); |
||
1455 | int allEvt, zProg; |
||
1456 | zProg = 1; |
||
1457 | |||
1458 | #if WORKSTAT == 'I' |
||
1459 | #else |
||
1460 | // ONLY FOR TESTING! |
||
1461 | TRandom *randNum = new TRandom(); |
||
1462 | randNum->SetSeed(0); |
||
1463 | // ONLY FOR TESTING! |
||
1464 | #endif |
||
1465 | |||
1466 | if (gDaq) |
||
1467 | { |
||
1468 | gDaq->fStop=0; |
||
1469 | // Start gathering |
||
1470 | gDaq->start(); |
||
1471 | |||
1472 | busyLabel->Enable(); |
||
1473 | |||
1474 | for (int n=0;n<neve && !gDaq->fStop ;/*n++*/) |
||
1475 | { |
||
1476 | int nb = gDaq->event(gBuf,BSIZE); |
||
1477 | |||
1478 | #if WORKSTAT == 'I' |
||
1479 | #else |
||
1480 | // ONLY FOR TESTING! |
||
1481 | for(int i=0; i < evtheader.nrch; i++) |
||
1482 | { |
||
1483 | if(i == 1) |
||
1484 | gBuf[i] = randNum->Gaus(1500,300); |
||
1485 | else if(i == 0) |
||
1486 | gBuf[i] = randNum->Poisson(2500); |
||
1487 | } |
||
1488 | // ONLY FOR TESTING! |
||
1489 | #endif |
||
1490 | if (nb<=0) n--; |
||
1491 | |||
1492 | int nc=0; |
||
1493 | |||
1494 | while ( (nb>0) && (n<neve) ) |
||
1495 | { |
||
1496 | for(int i = 0; i < evtheader.nrch; i++) |
||
1497 | { |
||
1498 | unsigned short adc = gBuf[i+nc]&0xFFFF; |
||
1499 | if(i % 2 == 0) // TDC |
||
1500 | evtdata.tdcdata[i/2] = (int)adc; |
||
1501 | else if(i % 2 == 1) // ADC |
||
1502 | evtdata.adcdata[i/2] = (int)adc; |
||
1503 | } |
||
1504 | meas_data->Fill(); |
||
1505 | |||
1506 | n++; |
||
1507 | nc += evtheader.nrch; |
||
1508 | nb -= evtheader.nrch; |
||
1509 | } |
||
1510 | |||
1511 | MyTimer(); |
||
1512 | allEvt = n; |
||
1513 | if (gSystem->ProcessEvents()) printf("Run Interrupted\n"); |
||
1514 | |||
1515 | if( (started) && (n == (neve*zProg)/10) ) |
||
1516 | { |
||
1517 | progVal = (float)zProg*10; |
||
1518 | curProgress->SetPosition(progVal); |
||
1519 | zProg++; |
||
1520 | } |
||
1521 | } |
||
1522 | |||
1523 | printf("Number of gathered events: %d\n", allEvt); |
||
1524 | measStart->SetText("Start acquisition"); |
||
1525 | started = kFALSE; |
||
1526 | |||
1527 | gDaq->stop(); |
||
1528 | } |
||
1529 | |||
1530 | busyLabel->Disable(); |
||
1531 | printf("End of Run neve=%d\n",neve); |
||
1532 | |||
1533 | header_data->Write(); |
||
1534 | meas_data->Write(); |
||
1535 | delete header_data; |
||
1536 | delete meas_data; |
||
1537 | |||
1538 | outroot->Close(); |
||
1539 | } |
||
1540 | |||
1541 | // Start the acquisition |
||
1542 | void TGAppMainFrame::StartAcq() |
||
1543 | { |
||
1544 | // Determine the type of measurement to perform |
||
1545 | int vscan = 0, pscan = 0, zscan = 0; |
||
1546 | if(voltscanOn->IsOn()) vscan = 1; |
||
1547 | if(surfscanOn->IsOn()) pscan = 1; |
||
1548 | if(zscanOn->IsOn()) zscan = 1; |
||
1549 | |||
1550 | char cmd[256]; |
||
1551 | int i, j, k; |
||
1552 | float progVal; |
||
1553 | FILE *pfin; |
||
1554 | |||
1555 | // Variables for voltage scan |
||
1556 | float currentVoltage, minVoltage, maxVoltage, stepVoltage; |
||
1557 | int repetition; |
||
1558 | |||
1559 | // Variables for surface scan |
||
1560 | int minXpos, maxXpos, stepXpos; |
||
1561 | int minYpos, maxYpos, stepYpos; |
||
1562 | int minZpos, maxZpos, stepZpos; |
||
1563 | int repetX, repetY, repetZ; |
||
1564 | |||
1565 | // Voltage scan |
||
1566 | if( (vscan == 1) && (pscan == 0) ) |
||
1567 | { |
||
1568 | if(started) |
||
1569 | { |
||
1570 | printf("Stopping current voltage scan...\n"); |
||
1571 | gROOT->SetInterrupt(); |
||
1572 | measStart->SetText("Start acquisition"); |
||
1573 | started = kFALSE; |
||
1574 | |||
1575 | pfin = fopen("finish_sig.txt","w"); |
||
1576 | fprintf(pfin, "%s: Voltage scan stopped.", timeStamp->GetText()); |
||
1577 | fclose(pfin); |
||
1578 | } |
||
1579 | else if(!started) |
||
1580 | { |
||
1581 | measStart->SetText("Stop acquisition"); |
||
1582 | started = kTRUE; |
||
1583 | |||
1584 | printf("Running a voltage scan...\n"); |
||
1585 | |||
1586 | minVoltage = vOutStart->GetNumber(); |
||
1587 | maxVoltage = vOutStop->GetNumber(); |
||
1588 | stepVoltage = vOutStep->GetNumber(); |
||
1589 | |||
1590 | if(stepVoltage == 0.) |
||
1591 | repetition = 1; |
||
1592 | else |
||
1593 | repetition = ((maxVoltage - minVoltage)/stepVoltage)+1; |
||
1594 | |||
1595 | for(i=0; i < repetition; i++) |
||
1596 | { |
||
1597 | progVal = (float)(100.00/repetition)*i; |
||
1598 | curProgress->SetPosition(progVal); |
||
1599 | |||
1600 | fflush(stdout); |
||
1601 | currentVoltage = minVoltage + stepVoltage*i; |
||
1602 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), currentVoltage); |
||
1603 | #if WORKSTAT == 'I' |
||
1604 | retTemp = system(cmd); |
||
1605 | #else |
||
1606 | printf("Cmd: %s\n",cmd); |
||
1607 | #endif |
||
1608 | fflush(stdout); |
||
1609 | |||
1610 | printf("Waiting for voltage change...\n"); |
||
1611 | sleep(5); |
||
1612 | vOut->SetNumber(currentVoltage); |
||
1613 | printf("Continuing...\n"); |
||
1614 | |||
1615 | // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<< |
||
1616 | RunMeas((void*)0, i, 0); |
||
1617 | fflush(stdout); |
||
1618 | } |
||
1619 | |||
1620 | // Set output back to off |
||
1621 | fflush(stdout); |
||
1622 | printf("Measurement finished, returning to starting voltage...\n"); |
||
1623 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), minVoltage); |
||
1624 | vOut->SetNumber(minVoltage); |
||
1625 | #if WORKSTAT == 'I' |
||
1626 | retTemp = system(cmd); |
||
1627 | #else |
||
1628 | printf("Cmd: %s\n",cmd); |
||
1629 | #endif |
||
1630 | fflush(stdout); |
||
1631 | |||
1632 | progVal = 100.00; |
||
1633 | curProgress->SetPosition(progVal); |
||
1634 | printf("\n"); |
||
1635 | |||
1636 | pfin = fopen("finish_sig.txt","w"); |
||
1637 | fprintf(pfin, "%s: Voltage scan finished.", timeStamp->GetText()); |
||
1638 | fclose(pfin); |
||
1639 | } |
||
1640 | } |
||
1641 | // Surface scan |
||
1642 | else if( (pscan == 1) && (vscan == 0) ) |
||
1643 | { |
||
1644 | minXpos = xPosMin->GetNumber(); |
||
1645 | maxXpos = xPosMax->GetNumber(); |
||
1646 | stepXpos = xPosStep->GetNumber(); |
||
1647 | minYpos = yPosMin->GetNumber(); |
||
1648 | maxYpos = yPosMax->GetNumber(); |
||
1649 | stepYpos = yPosStep->GetNumber(); |
||
1650 | minZpos = zPosMin->GetNumber(); |
||
1651 | maxZpos = zPosMax->GetNumber(); |
||
1652 | stepZpos = zPosStep->GetNumber(); |
||
1653 | |||
1654 | if(zscan == 1) |
||
1655 | { |
||
1656 | if(stepZpos == 0.) repetZ = 1; |
||
1657 | else repetZ = ((maxZpos - minZpos)/stepZpos)+1; |
||
1658 | } |
||
1659 | else |
||
1660 | { |
||
1661 | minZpos = zPos->GetNumber(); |
||
1662 | repetZ = 1; |
||
1663 | } |
||
1664 | |||
1665 | if(stepXpos == 0.) repetX = 1; |
||
1666 | else repetX = ((maxXpos - minXpos)/stepXpos)+1; |
||
1667 | if(stepYpos == 0.) repetY = 1; |
||
1668 | else repetY = ((maxYpos - minYpos)/stepYpos)+1; |
||
1669 | |||
1670 | for(k=0; k < repetZ; k++) |
||
1671 | { |
||
1672 | fflush(stdout); |
||
1673 | // Y-axis change |
||
1674 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/MIKRO/mikro_ctrl -n 3 -c m", rootdir, minZpos + stepZpos*k, rootdir); |
||
1675 | #if WORKSTAT == 'I' |
||
1676 | retTemp = system(cmd); |
||
1677 | #else |
||
1678 | printf("Cmd: %s\n",cmd); |
||
1679 | #endif |
||
1680 | fflush(stdout); |
||
1681 | |||
1682 | printf("Next Z position...\n"); |
||
1683 | zPos->SetNumber(minZpos + stepZpos*k); |
||
1684 | fflush(stdout); |
||
1685 | |||
1686 | for(j=0; j < repetY; j++) |
||
1687 | { |
||
1688 | fflush(stdout); |
||
1689 | // Y-axis change |
||
1690 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/MIKRO/mikro_ctrl -n 2 -c m", rootdir, minYpos + stepYpos*j, rootdir); |
||
1691 | #if WORKSTAT == 'I' |
||
1692 | retTemp = system(cmd); |
||
1693 | #else |
||
1694 | printf("Cmd: %s\n",cmd); |
||
1695 | #endif |
||
1696 | fflush(stdout); |
||
1697 | |||
1698 | sleep(4); |
||
1699 | printf("Next Y position...\n"); |
||
1700 | yPos->SetNumber(minYpos + stepYpos*j); |
||
1701 | fflush(stdout); |
||
1702 | |||
1703 | for(i=0; i < repetX; i++) |
||
1704 | { |
||
1705 | progVal = (float)(100.00/(repetX*repetY))*(j*repetX+i); |
||
1706 | curProgress->SetPosition(progVal); |
||
1707 | |||
1708 | // X-axis change |
||
1709 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/MIKRO/mikro_ctrl -n 1 -c m", rootdir, minXpos + stepXpos*i, rootdir); |
||
1710 | #if WORKSTAT == 'I' |
||
1711 | retTemp = system(cmd); |
||
1712 | #else |
||
1713 | printf("Cmd: %s\n",cmd); |
||
1714 | #endif |
||
1715 | fflush(stdout); |
||
1716 | |||
1717 | printf("Next X position...\n"); |
||
1718 | fflush(stdout); |
||
1719 | |||
1720 | printf("Waiting for position change...\n"); |
||
1721 | sleep(2); |
||
1722 | xPos->SetNumber(minXpos + stepXpos*i); |
||
1723 | printf("Continuing...\n"); |
||
1724 | |||
1725 | // for (k=0;k<(NTDCCH+NADCCH);k++) gHisto1D[k]->Reset(); |
||
1726 | // for (k=0;k<(NTDCCH+NADCCH)/2;k++) gHisto2D[k]->Reset(); |
||
1727 | |||
1728 | // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<< |
||
1729 | RunMeas((void*)0, (j*repetX + i), zscan ); |
||
1730 | |||
1731 | fflush(stdout); |
||
1732 | } |
||
1733 | |||
1734 | printf("\n"); |
||
1735 | } |
||
1736 | } |
||
1737 | |||
1738 | fflush(stdout); |
||
1739 | printf("Measurement finished, returning to starting position...\n"); |
||
1740 | // X-axis return |
||
1741 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/MIKRO/mikro_ctrl -n 1 -c m", rootdir, minXpos, rootdir); |
||
1742 | #if WORKSTAT == 'I' |
||
1743 | retTemp = system(cmd); |
||
1744 | #else |
||
1745 | printf("Cmd: %s\n",cmd); |
||
1746 | #endif |
||
1747 | fflush(stdout); |
||
1748 | |||
1749 | // Y-axis return |
||
1750 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/MIKRO/mikro_ctrl -n 2 -c m", rootdir, minYpos, rootdir); |
||
1751 | #if WORKSTAT == 'I' |
||
1752 | retTemp = system(cmd); |
||
1753 | #else |
||
1754 | printf("Cmd: %s\n",cmd); |
||
1755 | #endif |
||
1756 | |||
1757 | // Z-axis return |
||
1758 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/MIKRO/mikro_ctrl -n 3 -c m", rootdir, minZpos, rootdir); |
||
1759 | #if WORKSTAT == 'I' |
||
1760 | retTemp = system(cmd); |
||
1761 | #else |
||
1762 | printf("Cmd: %s\n",cmd); |
||
1763 | #endif |
||
1764 | xPos->SetNumber(minXpos); |
||
1765 | yPos->SetNumber(minYpos); |
||
1766 | zPos->SetNumber(minZpos); |
||
1767 | |||
1768 | progVal = 100.00; |
||
1769 | curProgress->SetPosition(progVal); |
||
1770 | printf("\n"); |
||
1771 | |||
1772 | pfin = fopen("finish_sig.txt","w"); |
||
1773 | fprintf(pfin, "%s: Surface scan finished.", timeStamp->GetText()); |
||
1774 | fclose(pfin); |
||
1775 | } |
||
1776 | // Normal single measurement |
||
1777 | else if( (vscan == 0) && (pscan == 0) ) |
||
1778 | { |
||
1779 | // Set the start button to stop and enable stopping of measurement |
||
1780 | if(started) |
||
1781 | { |
||
1782 | printf("Stopping current single scan...\n"); |
||
1783 | gROOT->SetInterrupt(); |
||
1784 | // gDaq->fStop=1; |
||
1785 | measStart->SetText("Start acquisition"); |
||
1786 | started = kFALSE; |
||
1787 | } |
||
1788 | else if(!started) |
||
1789 | { |
||
1790 | measStart->SetText("Stop acquisition"); |
||
1791 | started = kTRUE; |
||
1792 | |||
1793 | printf("Running a single scan...\n"); |
||
1794 | RunMeas((void*)0, 0, 0); |
||
1795 | printf("Measurement finished...\n"); |
||
1796 | printf("\n"); |
||
1797 | } |
||
1798 | } |
||
1799 | } |
||
1800 | |||
1801 | // File browser for opening histograms |
||
1802 | void TGAppMainFrame::SelectDirectory() |
||
1803 | { |
||
1804 | int i = fileList->GetNumberOfEntries(); |
||
1805 | |||
1806 | TGFileInfo file_info; |
||
1807 | const char *filetypes[] = {"Histograms",histExtAll,0,0}; |
||
1808 | file_info.fFileTypes = filetypes; |
||
1809 | file_info.fIniDir = StrDup("./results"); |
||
1810 | file_info.fMultipleSelection = kTRUE; |
||
1811 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info); |
||
1812 | |||
1813 | TList *files = file_info.fFileNamesList; |
||
1814 | if(files) |
||
1815 | { |
||
1816 | TSystemFile *file; |
||
1817 | TString fname; |
||
1818 | TIter next(files); |
||
1819 | while(file=(TSystemFile*)next()) |
||
1820 | { |
||
1821 | fname = file->GetName(); |
||
1822 | fileList->AddEntry(fname.Data(), i); |
||
1823 | i++; |
||
1824 | } |
||
1825 | } |
||
1826 | fileList->Layout(); |
||
1827 | } |
||
1828 | |||
1829 | // File browser for selecting the save file |
||
1830 | void TGAppMainFrame::SaveFile() |
||
1831 | { |
||
1832 | TGFileInfo file_info; |
||
1833 | const char *filetypes[] = {"Histograms",histExtAll,0,0}; |
||
1834 | file_info.fFileTypes = filetypes; |
||
1835 | file_info.fIniDir = StrDup("./results"); |
||
1836 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDSave, &file_info); |
||
1837 | |||
1838 | fileName->SetText(file_info.fFilename); |
||
1839 | } |
||
1840 | |||
1841 | // Toggle multiple selection in filelist |
||
1842 | void TGAppMainFrame::ListMultiSelect() |
||
1843 | { |
||
1844 | fileList->SetMultipleSelections((multiSelect->IsOn())); |
||
1845 | |||
1846 | if(multiSelectAll->IsDown()) |
||
1847 | multiSelectAll->SetState(kButtonUp); |
||
1848 | } |
||
1849 | |||
1850 | // Select all entries in filelist |
||
1851 | void TGAppMainFrame::ListSelectAll() |
||
1852 | { |
||
1853 | if(multiSelectAll->IsDown()) |
||
1854 | { |
||
1855 | multiSelect->SetState(kButtonDown); |
||
1856 | fileList->SetMultipleSelections((multiSelect->IsOn())); |
||
1857 | for(int i = 0; i < fileList->GetNumberOfEntries(); i++) |
||
1858 | fileList->Select(i,kTRUE); |
||
1859 | } |
||
1860 | else if(!multiSelectAll->IsDown()) |
||
1861 | { |
||
1862 | multiSelect->SetState(kButtonUp); |
||
1863 | fileList->SetMultipleSelections((multiSelect->IsOn())); |
||
1864 | for(int i = 0; i < fileList->GetNumberOfEntries(); i++) |
||
1865 | fileList->Select(i,kFALSE); |
||
1866 | } |
||
1867 | } |
||
1868 | |||
1869 | // Navigation buttons for the filelist (<<, >>) and double click |
||
1870 | void TGAppMainFrame::FileListNavigation(int pn) |
||
1871 | { |
||
1872 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
1873 | int curSel; |
||
1874 | TList *files; |
||
1875 | if( nrfiles > 0 ) |
||
1876 | { |
||
1877 | if(pn < -1) |
||
1878 | { |
||
1879 | if(multiSelect->IsOn()) |
||
1880 | { |
||
1881 | // turn off multiple selection and select first file on list |
||
1882 | fileList->SetMultipleSelections(kFALSE); |
||
1883 | multiSelect->SetState(kButtonUp); |
||
1884 | multiSelectAll->SetState(kButtonUp); |
||
1885 | |||
1886 | fileList->Select(0,kTRUE); |
||
1887 | } |
||
1888 | else |
||
1889 | { |
||
1890 | // if nothing is selected, curSel will be -1 |
||
1891 | curSel = fileList->GetSelected(); |
||
1892 | // go to next file on list |
||
1893 | if(pn == -3) |
||
1894 | { |
||
1895 | if( (curSel == (int)(nrfiles-1)) || (curSel == -1) ) |
||
1896 | fileList->Select(0); |
||
1897 | else |
||
1898 | fileList->Select(curSel+1); |
||
1899 | } |
||
1900 | // go to previous file on list |
||
1901 | else if(pn == -2) |
||
1902 | { |
||
1903 | if( (curSel == 0) || (curSel == -1) ) |
||
1904 | fileList->Select(nrfiles-1); |
||
1905 | else |
||
1906 | fileList->Select(curSel-1); |
||
1907 | } |
||
1908 | } |
||
1909 | } |
||
1910 | |||
1911 | // check the newly selected file/files and return its name/their names |
||
1912 | files = new TList(); |
||
1913 | fileList->GetSelectedEntries(files); |
||
1914 | if(files) |
||
1915 | { |
||
1916 | for(int i = 0; i < (int)nrfiles; i++) |
||
1917 | { |
||
1918 | if(files->At(i)) |
||
1919 | { |
||
1920 | if(debugSig) |
||
1921 | printf("Filename: %s\n", files->At(i)->GetTitle()); |
||
1922 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
1923 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
1924 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
1925 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1); |
||
1926 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
1927 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2); |
||
1928 | } |
||
1929 | } |
||
1930 | } |
||
1931 | |||
1932 | // Still need to include drawing of histograms we move to!!! |
||
1933 | } |
||
1934 | } |
||
1935 | |||
1936 | // Display the currently selected histogram in file list |
||
1937 | void TGAppMainFrame::DisplayHistogram(char* histfile, int histtype) |
||
1938 | { |
||
1939 | if(debugSig) |
||
1940 | printf("Selected file: %s\n", histfile); |
||
1941 | |||
1942 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
1943 | |||
1944 | inroot = new TFile(histfile, "READ"); |
||
1945 | |||
1946 | TTree *header_data, *meas_data; |
||
1947 | inroot->GetObject("header_data", header_data); |
||
1948 | inroot->GetObject("meas_data", meas_data); |
||
1949 | |||
1950 | // Reading the header |
||
1951 | header_data->SetBranchAddress("nrch", &evtheader.nrch); |
||
1952 | header_data->GetEntry(0); |
||
1953 | header_data->SetBranchAddress("timestamp", &evtheader.timestamp); |
||
1954 | header_data->GetEntry(0); |
||
1955 | header_data->SetBranchAddress("biasvolt", &evtheader.biasvolt); |
||
1956 | header_data->GetEntry(0); |
||
1957 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
||
1958 | header_data->GetEntry(0); |
||
1959 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
||
1960 | header_data->GetEntry(0); |
||
1961 | header_data->SetBranchAddress("zpos", &evtheader.zpos); |
||
1962 | header_data->GetEntry(0); |
||
1963 | header_data->SetBranchAddress("temperature", &evtheader.temperature); |
||
1964 | header_data->GetEntry(0); |
||
1965 | header_data->SetBranchAddress("laserinfo", &evtheader.laserinfo); |
||
1966 | header_data->GetEntry(0); |
||
1967 | |||
1968 | char histtime[256]; |
||
1969 | GetTime(evtheader.timestamp, histtime); |
||
1970 | |||
1971 | if(debugSig) |
||
1972 | { |
||
1973 | printf("Opened file header information:\n"); |
||
1974 | printf("- Number of channels: %d\n", evtheader.nrch); |
||
1975 | printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime); |
||
1976 | printf("- Bias voltage: %lf\n", evtheader.biasvolt); |
||
1977 | printf("- Table position (X,Y,Z): %d, %d, %d\n", evtheader.xpos, evtheader.ypos, evtheader.zpos); |
||
1978 | printf("- Temperature: %lf\n", evtheader.temperature); |
||
1979 | printf("- Laser and filter settings: %s\n", evtheader.laserinfo); |
||
1980 | } |
||
1981 | |||
1982 | int j; |
||
1983 | char rdc[256]; |
||
1984 | char rdcsel[256]; |
||
1985 | |||
1986 | j = selectCh->GetNumber(); |
||
1987 | |||
1988 | printf("Found %d data points.\n", (int)meas_data->GetEntries()); |
||
1989 | |||
1990 | gCanvas->cd(); |
||
1991 | double range[4]; |
||
1992 | range[0] = adcMinRange->GetNumber(); |
||
1993 | range[1] = adcMaxRange->GetNumber(); |
||
1994 | range[2] = tdcMinwindow->GetNumber(); |
||
1995 | range[3] = tdcMaxwindow->GetNumber(); |
||
1996 | |||
1997 | if(histtype == 0) |
||
1998 | { |
||
1999 | if( range[0] == range[1] ) |
||
2000 | sprintf(rdc, "ADC%d>>%s", j, histname); |
||
2001 | else |
||
2002 | sprintf(rdc, "ADC%d>>%s(%d,%lf,%lf)", j, histname, (int)(range[1]-range[0]), range[0]-0.5, range[1]-0.5); |
||
2003 | |||
2004 | sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion); |
||
2005 | meas_data->Draw(rdc, rdcsel); |
||
2006 | |||
2007 | sprintf(rdc, "ADC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);ADC;", j, evtheader.biasvolt, range[2], range[3]); |
||
2008 | TH1F *histtemp = (TH1F*)gCanvas->GetPrimitive(histname); |
||
2009 | if(!cleanPlots) |
||
2010 | histtemp->SetTitle(rdc); |
||
2011 | else |
||
2012 | histtemp->SetTitle(";ADC;"); |
||
2013 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
2014 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
2015 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
2016 | if(cleanPlots) |
||
2017 | { |
||
2018 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
2019 | yax->SetMaxDigits(4); |
||
2020 | } |
||
2021 | |||
2022 | gCanvas->Modified(); |
||
2023 | gCanvas->Update(); |
||
2024 | |||
2025 | if( yMinRange->GetNumber() != yMaxRange->GetNumber() ) |
||
2026 | { |
||
2027 | if( (logscale->IsDown()) && (yMinRange->GetNumber() <= 0) ) |
||
2028 | { |
||
2029 | histtemp->GetYaxis()->SetRangeUser(0.5, yMaxRange->GetNumber()); |
||
2030 | yMinRange->SetNumber(0.5); |
||
2031 | logchange = 1; |
||
2032 | } |
||
2033 | else |
||
2034 | { |
||
2035 | gCanvas->SetLogy(kFALSE); |
||
2036 | if(logchange == 1) |
||
2037 | { |
||
2038 | yMinRange->SetNumber(0.0); |
||
2039 | logchange = 0; |
||
2040 | } |
||
2041 | histtemp->GetYaxis()->SetRangeUser(yMinRange->GetNumber(), yMaxRange->GetNumber()); |
||
2042 | } |
||
2043 | } |
||
2044 | |||
2045 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
2046 | if(!cleanPlots) |
||
2047 | { |
||
2048 | stats->SetX1NDC(0.84); stats->SetX2NDC(0.97); |
||
2049 | stats->SetY1NDC(0.87); stats->SetY2NDC(0.97); |
||
2050 | } |
||
2051 | else |
||
2052 | { |
||
2053 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
2054 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
2055 | } |
||
2056 | } |
||
2057 | else if(histtype == 1) |
||
2058 | { |
||
2059 | if( range[0] == range[1] ) |
||
2060 | sprintf(rdc, "(TDC%d/%lf)>>%s", j, tdctimeconversion, histname); |
||
2061 | else |
||
2062 | sprintf(rdc, "(TDC%d/%lf)>>%s(%d,%lf,%lf)", j, tdctimeconversion, histname, (int)((range[3]-range[2])*tdctimeconversion), range[2], range[3]); |
||
2063 | sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion); |
||
2064 | meas_data->Draw(rdc, rdcsel); |
||
2065 | |||
2066 | sprintf(rdc, "TDC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);Time (TDC channel) [ns];", j, evtheader.biasvolt, range[2], range[3]); |
||
2067 | TH1F *histtemp = (TH1F*)gCanvas->GetPrimitive(histname); |
||
2068 | if(!cleanPlots) |
||
2069 | histtemp->SetTitle(rdc); |
||
2070 | else |
||
2071 | histtemp->SetTitle(";Time (TDC channel) [ns];"); |
||
2072 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
2073 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
2074 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
2075 | if(cleanPlots) |
||
2076 | { |
||
2077 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
2078 | yax->SetMaxDigits(4); |
||
2079 | } |
||
2080 | |||
2081 | gCanvas->Modified(); |
||
2082 | gCanvas->Update(); |
||
2083 | |||
2084 | if( yMinRange->GetNumber() != yMaxRange->GetNumber() ) |
||
2085 | { |
||
2086 | if( (logscale->IsDown()) && (yMinRange->GetNumber() <= 0) ) |
||
2087 | { |
||
2088 | histtemp->GetYaxis()->SetRangeUser(0.5, yMaxRange->GetNumber()); |
||
2089 | yMinRange->SetNumber(0.5); |
||
2090 | logchange = 1; |
||
2091 | } |
||
2092 | else |
||
2093 | { |
||
2094 | gCanvas->SetLogy(kFALSE); |
||
2095 | if(logchange == 1) |
||
2096 | { |
||
2097 | yMinRange->SetNumber(0.0); |
||
2098 | logchange = 0; |
||
2099 | } |
||
2100 | histtemp->GetYaxis()->SetRangeUser(yMinRange->GetNumber(), yMaxRange->GetNumber()); |
||
2101 | } |
||
2102 | } |
||
2103 | |||
2104 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
2105 | if(!cleanPlots) |
||
2106 | { |
||
2107 | stats->SetX1NDC(0.84); stats->SetX2NDC(0.97); |
||
2108 | stats->SetY1NDC(0.87); stats->SetY2NDC(0.97); |
||
2109 | } |
||
2110 | else |
||
2111 | { |
||
2112 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
2113 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
2114 | } |
||
2115 | } |
||
2116 | else if(histtype == 2) |
||
2117 | { |
||
2118 | if( ((range[0] == range[1]) && (range[2] == range[3])) || (range[2] == range[3]) || (range[0] == range[1]) ) |
||
2119 | sprintf(rdc, "(TDC%d/%lf):ADC%d>>%s", j, tdctimeconversion, j, histname); |
||
2120 | else |
||
2121 | 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]); |
||
2122 | meas_data->Draw(rdc,"","COLZ"); |
||
2123 | |||
2124 | sprintf(rdc, "ADC/TDC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);ADC;TDC", j, evtheader.biasvolt, range[2], range[3]); |
||
2125 | TH2F *histtemp = (TH2F*)gCanvas->GetPrimitive(histname); |
||
2126 | if(!cleanPlots) |
||
2127 | histtemp->SetTitle(rdc); |
||
2128 | else |
||
2129 | histtemp->SetTitle(";ADC;Time (TDC channel) [ns]"); |
||
2130 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
2131 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
2132 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
2133 | histtemp->GetYaxis()->CenterTitle(kTRUE); |
||
2134 | histtemp->GetYaxis()->SetTitleOffset(1.35); |
||
2135 | if(cleanPlots) |
||
2136 | { |
||
2137 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
2138 | yax->SetMaxDigits(4); |
||
2139 | } |
||
2140 | |||
2141 | gCanvas->Modified(); |
||
2142 | gCanvas->Update(); |
||
2143 | |||
2144 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
2145 | // stats->SetOptStat(0); |
||
2146 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
2147 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
2148 | |||
2149 | TPaletteAxis *gpalette = (TPaletteAxis*)histtemp->GetListOfFunctions()->FindObject("palette"); |
||
2150 | gpalette->SetLabelSize(0.022); |
||
2151 | } |
||
2152 | |||
2153 | if(histtype < 2) |
||
2154 | { |
||
2155 | if( logscale->IsDown() ) |
||
2156 | gCanvas->SetLogy(kTRUE); |
||
2157 | else if( !logscale->IsDown() ) |
||
2158 | gCanvas->SetLogy(kFALSE); |
||
2159 | } |
||
2160 | else |
||
2161 | gCanvas->SetLogy(kFALSE); |
||
2162 | |||
2163 | gCanvas->Modified(); |
||
2164 | gCanvas->Update(); |
||
2165 | |||
2166 | // If you close the opened file, the data can't be accessed by other functions |
||
2167 | } |
||
2168 | |||
2169 | // Create a 2D surface plot and plot it |
||
2170 | void TGAppMainFrame::MakeSurfPlot(TList *files) |
||
2171 | { |
||
2172 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2173 | int j, k = 0, m = 0, n = 0; |
||
2174 | char ctemp[256]; |
||
2175 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
2176 | TTree *header_data, *meas_data; |
||
2177 | double *integralCount; |
||
2178 | double *surfx, *surfy; |
||
2179 | double xsurfmin = 0, ysurfmin = 0; |
||
2180 | integralCount = new double[nrfiles]; |
||
2181 | for(int i = 0; i < (int)nrfiles; i++) integralCount[i] = 0; |
||
2182 | surfx = new double[nrfiles]; |
||
2183 | surfy = new double[nrfiles]; |
||
2184 | int nrentries; |
||
2185 | TGraph2D *gScan2D; |
||
2186 | gScan2D = new TGraph2D(); |
||
2187 | |||
2188 | /* int zProg = 0; |
||
2189 | float progVal; |
||
2190 | curProgress->SetPosition(zProg);*/ |
||
2191 | |||
2192 | char exportname[256]; |
||
2193 | |||
2194 | if(multiSelect->IsOn()) |
||
2195 | { |
||
2196 | printf("Creating a surface plot. Please wait...\n"); |
||
2197 | fileList->GetSelectedEntries(files); |
||
2198 | if(files) |
||
2199 | { |
||
2200 | busyLabel->Enable(); |
||
2201 | |||
2202 | for(int i = 0; i < (int)nrfiles; i++) |
||
2203 | { |
||
2204 | if(files->At(i)) |
||
2205 | { |
||
2206 | n++; |
||
2207 | // printf("Filename: %s\n", files->At(i)->GetTitle()); |
||
2208 | |||
2209 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
||
2210 | inroot = new TFile(ctemp, "READ"); |
||
2211 | |||
2212 | inroot->GetObject("header_data", header_data); |
||
2213 | inroot->GetObject("meas_data", meas_data); |
||
2214 | |||
2215 | // Reading the header |
||
2216 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
||
2217 | header_data->GetEntry(0); |
||
2218 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
||
2219 | header_data->GetEntry(0); |
||
2220 | |||
2221 | char rdc[256]; |
||
2222 | j = selectCh->GetNumber(); |
||
2223 | double rangetdc[2]; |
||
2224 | rangetdc[0] = tdcMinwindow->GetNumber(); |
||
2225 | rangetdc[1] = tdcMaxwindow->GetNumber(); |
||
2226 | |||
2227 | k = 0; |
||
2228 | m = 0; |
||
2229 | |||
2230 | // Reading the data |
||
2231 | for(int i = 0; i < meas_data->GetEntries(); i++) |
||
2232 | { |
||
2233 | sprintf(rdc, "ADC%d", j); |
||
2234 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
||
2235 | meas_data->GetEntry(i); |
||
2236 | |||
2237 | sprintf(rdc, "TDC%d", j); |
||
2238 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
||
2239 | meas_data->GetEntry(i); |
||
2240 | |||
2241 | // If our data point is inside the TDC window |
||
2242 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
||
2243 | { |
||
2244 | k++; |
||
2245 | m += evtdata.adcdata[j]; |
||
2246 | } |
||
2247 | } |
||
2248 | |||
2249 | integralCount[n-1] += ((double)m)/((double)k); |
||
2250 | if(n == 1) |
||
2251 | { |
||
2252 | xsurfmin = evtheader.xpos; |
||
2253 | ysurfmin = evtheader.ypos; |
||
2254 | } |
||
2255 | surfx[n-1] = (double)(evtheader.xpos-xsurfmin)*lenconversion; |
||
2256 | surfy[n-1] = (double)(evtheader.ypos-ysurfmin)*lenconversion; |
||
2257 | |||
2258 | /* if( n == (((files->GetSize())*zProg)/20)+1 ) // divide by 20 because files->GetSize() gives a double value of the files selected |
||
2259 | { |
||
2260 | progVal = (float)n; |
||
2261 | curProgress->SetPosition(progVal); |
||
2262 | zProg++; |
||
2263 | printf("Progress = %lf\n", progVal); |
||
2264 | }*/ |
||
2265 | |||
2266 | delete inroot; |
||
2267 | } |
||
2268 | } |
||
2269 | |||
2270 | busyLabel->Disable(); |
||
2271 | |||
2272 | nrentries = n; |
||
2273 | printf("%d files were selected.\n", nrentries); |
||
2274 | |||
2275 | for(int i = 0; i < nrentries; i++) |
||
2276 | { |
||
2277 | // printf("At position (%d,%d), the ADC integral is: %lf.\n", surfx[i], surfy[i], integralCount[i]); |
||
2278 | gScan2D->SetPoint(i, surfx[i], surfy[i], integralCount[i]); |
||
2279 | } |
||
2280 | gCanvas->cd(); |
||
2281 | gScan2D->Draw("COLZ"); |
||
2282 | |||
2283 | gCanvas->Modified(); |
||
2284 | gCanvas->Update(); |
||
2285 | |||
2286 | gScan2D->GetXaxis()->SetTitle("X [#mum]"); |
||
2287 | gScan2D->GetXaxis()->CenterTitle(kTRUE); |
||
2288 | gScan2D->GetXaxis()->SetLabelSize(0.022); |
||
2289 | gScan2D->GetXaxis()->SetRangeUser(surfx[0], surfx[nrentries-1]); |
||
2290 | // j = 500+(int)((surfx[nrentries-1]-surfx[0])/(surfx[1]-surfx[0])); |
||
2291 | // if(j > 510) j = 510; |
||
2292 | gScan2D->GetXaxis()->SetNdivisions(510, kTRUE); |
||
2293 | gScan2D->GetYaxis()->SetTitle("Y [#mum]"); |
||
2294 | gScan2D->GetYaxis()->SetTitleOffset(1.3); |
||
2295 | gScan2D->GetYaxis()->CenterTitle(kTRUE); |
||
2296 | gScan2D->GetYaxis()->SetLabelSize(0.022); |
||
2297 | gScan2D->GetYaxis()->SetRangeUser(surfy[0], surfy[nrentries-1]); |
||
2298 | // j = 500+(int)((surfy[nrentries-1]-surfy[0])/(surfy[(int)((surfx[nrentries-1]-surfx[0])/(surfx[1]-surfx[0])+1)]-surfy[0])); |
||
2299 | // if(j > 510) j = 510; |
||
2300 | gScan2D->GetYaxis()->SetNdivisions(510, kTRUE); |
||
2301 | |||
2302 | TGaxis *yax = (TGaxis*)gScan2D->GetYaxis(); |
||
2303 | yax->SetMaxDigits(4); |
||
2304 | |||
2305 | if(!cleanPlots) |
||
2306 | gScan2D->SetTitle("Surface scan"); |
||
2307 | else |
||
2308 | gScan2D->SetTitle(); |
||
2309 | |||
2310 | // TPaletteAxis *gpalette = (TPaletteAxis*)gScan2D->GetListOfFunctions()->FindObject("palette"); |
||
2311 | // gpalette->SetLabelSize(0.022); |
||
2312 | |||
2313 | gCanvas->Modified(); |
||
2314 | gCanvas->Update(); |
||
2315 | |||
2316 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
2317 | sprintf(exportname, "%s_surfscan.pdf", ctemp); |
||
2318 | gCanvas->SaveAs(exportname); |
||
2319 | } |
||
2320 | } |
||
2321 | else |
||
2322 | { |
||
2323 | printf("To make a 2D surface scan plot, select multiple root files.\n"); |
||
2324 | change2Dsurf->SetDown(kFALSE); |
||
2325 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_SURF); |
||
2326 | } |
||
2327 | |||
2328 | delete[] surfx; |
||
2329 | delete[] surfy; |
||
2330 | delete[] integralCount; |
||
2331 | } |
||
2332 | |||
2333 | // Change histogram when changing the channel |
||
2334 | void TGAppMainFrame::ChangeChannel() |
||
2335 | { |
||
2336 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2337 | TList *files; |
||
2338 | |||
2339 | if( nrfiles > 0 ) |
||
2340 | { |
||
2341 | // check the newly selected file/files and return its name/their names |
||
2342 | files = new TList(); |
||
2343 | fileList->GetSelectedEntries(files); |
||
2344 | if(files) |
||
2345 | { |
||
2346 | for(int i = 0; i < (int)nrfiles; i++) |
||
2347 | { |
||
2348 | if(files->At(i)) |
||
2349 | { |
||
2350 | if(debugSig) |
||
2351 | printf("Filename: %s\n", files->At(i)->GetTitle()); |
||
2352 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
2353 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
2354 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
2355 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1); |
||
2356 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
2357 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2); |
||
2358 | } |
||
2359 | } |
||
2360 | } |
||
2361 | } |
||
2362 | } |
||
2363 | |||
2364 | // Setting a predetermined X range |
||
2365 | void TGAppMainFrame::SetHistRange() |
||
2366 | { |
||
2367 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2368 | |||
2369 | if(nrfiles > 0) |
||
2370 | { |
||
2371 | TList *files; |
||
2372 | files = new TList(); |
||
2373 | fileList->GetSelectedEntries(files); |
||
2374 | if(files) |
||
2375 | { |
||
2376 | for(int i = 0; i < (int)nrfiles; i++) |
||
2377 | { |
||
2378 | if(files->At(i)) |
||
2379 | { |
||
2380 | if(debugSig) |
||
2381 | printf("Filename: %s\n", files->At(i)->GetTitle()); |
||
2382 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
2383 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
2384 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
2385 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1); |
||
2386 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
2387 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2); |
||
2388 | } |
||
2389 | } |
||
2390 | } |
||
2391 | } |
||
2392 | } |
||
2393 | |||
2394 | // Changing the histogram type to display |
||
2395 | void TGAppMainFrame::ChangeHisttype(int type) |
||
2396 | { |
||
2397 | TGTextButton *pressedB = new TGTextButton(); |
||
2398 | int menuID = 0; |
||
2399 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2400 | |||
2401 | // ADC histogram |
||
2402 | if(type == 0) |
||
2403 | { |
||
2404 | pressedB = changeADC; |
||
2405 | menuID = M_ANALYSIS_HISTTYPE_1DADC; |
||
2406 | |||
2407 | changeTDC->SetDown(kFALSE); |
||
2408 | changeADCTDC->SetDown(kFALSE); |
||
2409 | change2Dsurf->SetDown(kFALSE); |
||
2410 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC); |
||
2411 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D); |
||
2412 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_SURF); |
||
2413 | } |
||
2414 | // TDC histogram |
||
2415 | else if(type == 1) |
||
2416 | { |
||
2417 | pressedB = changeTDC; |
||
2418 | menuID = M_ANALYSIS_HISTTYPE_1DTDC; |
||
2419 | |||
2420 | changeADC->SetDown(kFALSE); |
||
2421 | changeADCTDC->SetDown(kFALSE); |
||
2422 | change2Dsurf->SetDown(kFALSE); |
||
2423 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
2424 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D); |
||
2425 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_SURF); |
||
2426 | } |
||
2427 | // ADC vs. TDC histogram |
||
2428 | else if(type == 2) |
||
2429 | { |
||
2430 | pressedB = changeADCTDC; |
||
2431 | menuID = M_ANALYSIS_HISTTYPE_2D; |
||
2432 | |||
2433 | changeADC->SetDown(kFALSE); |
||
2434 | changeTDC->SetDown(kFALSE); |
||
2435 | change2Dsurf->SetDown(kFALSE); |
||
2436 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
2437 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC); |
||
2438 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_SURF); |
||
2439 | } |
||
2440 | // Surface scan plot |
||
2441 | else if(type == 3) |
||
2442 | { |
||
2443 | pressedB = change2Dsurf; |
||
2444 | menuID = M_ANALYSIS_HISTTYPE_SURF; |
||
2445 | |||
2446 | changeADC->SetDown(kFALSE); |
||
2447 | changeTDC->SetDown(kFALSE); |
||
2448 | changeADCTDC->SetDown(kFALSE); |
||
2449 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
2450 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC); |
||
2451 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D); |
||
2452 | } |
||
2453 | |||
2454 | if( fMenuHisttype->IsEntryChecked(menuID) ) |
||
2455 | { |
||
2456 | pressedB->SetDown(kFALSE); |
||
2457 | fMenuHisttype->UnCheckEntry(menuID); |
||
2458 | } |
||
2459 | else if( !fMenuHisttype->IsEntryChecked(menuID) ) |
||
2460 | { |
||
2461 | pressedB->SetDown(kTRUE); |
||
2462 | fMenuHisttype->CheckEntry(menuID); |
||
2463 | } |
||
2464 | |||
2465 | if(nrfiles > 0) |
||
2466 | { |
||
2467 | // Still need to add the switch!!! |
||
2468 | TList *files; |
||
2469 | files = new TList(); |
||
2470 | fileList->GetSelectedEntries(files); |
||
2471 | |||
2472 | if(type < 3) |
||
2473 | DisplayHistogram( (char*)(files->At(0)->GetTitle()), type); |
||
2474 | else if(type == 3) |
||
2475 | MakeSurfPlot( files ); |
||
2476 | } |
||
2477 | } |
||
2478 | |||
2479 | // Changing the histogram type to display |
||
2480 | void TGAppMainFrame::HistogramExport() |
||
2481 | { |
||
2482 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2483 | TList *files; |
||
2484 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
2485 | |||
2486 | char exportname[256]; |
||
2487 | char ctemp[256]; |
||
2488 | |||
2489 | if(nrfiles > 0) |
||
2490 | { |
||
2491 | files = new TList(); |
||
2492 | fileList->GetSelectedEntries(files); |
||
2493 | if(files) |
||
2494 | { |
||
2495 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_SURF) ) // for the surface scan, the plot from all selected files is already created |
||
2496 | { |
||
2497 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
2498 | sprintf(exportname, "%s_surfscan.pdf", ctemp); |
||
2499 | gCanvas->SaveAs(exportname); |
||
2500 | } |
||
2501 | else |
||
2502 | { |
||
2503 | for(int i = 0; i < (int)nrfiles; i++) |
||
2504 | { |
||
2505 | if(files->At(i)) |
||
2506 | { |
||
2507 | remove_ext((char*)files->At(i)->GetTitle(), ctemp); |
||
2508 | |||
2509 | if(debugSig) |
||
2510 | printf("Filename: %s\n", files->At(i)->GetTitle()); |
||
2511 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
2512 | { |
||
2513 | sprintf(exportname, "%s_adc%d.pdf", ctemp, (int)selectCh->GetNumber()); |
||
2514 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
2515 | } |
||
2516 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
2517 | { |
||
2518 | sprintf(exportname, "%s_tdc%d.pdf", ctemp, (int)selectCh->GetNumber()); |
||
2519 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1); |
||
2520 | } |
||
2521 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
2522 | { |
||
2523 | sprintf(exportname, "%s_adctdc%d.pdf", ctemp, (int)selectCh->GetNumber()); |
||
2524 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2); |
||
2525 | } |
||
2526 | |||
2527 | gCanvas->SaveAs(exportname); |
||
2528 | } |
||
2529 | } |
||
2530 | } |
||
2531 | } |
||
2532 | } |
||
2533 | } |
||
2534 | |||
2535 | //--------------------------------------------------------------- |
||
2536 | // Main window constructor definition (& layout) |
||
2537 | |||
2538 | TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h) |
||
2539 | { |
||
2540 | gDaq = new daq(); |
||
2541 | gScopeDaq = new daqscope(); |
||
2542 | |||
2543 | // Define the main window and menubar |
||
2544 | fMain = new TGMainFrame(p, w, h, kVerticalFrame); // vertical frame split into menubar and main frame |
||
2545 | fMenuBar = new TGMdiMenuBar(fMain, 10, 10); // just prepare menubar, draw it with InitMenu() |
||
2546 | fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); |
||
2547 | |||
2548 | // Define the main frame where opened subwindows will appear |
||
2549 | fMainFrame = new TGMdiMainFrame(fMain, fMenuBar, 300, 300); |
||
2550 | fMain->AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); |
||
2551 | |||
2552 | // Initialize the menubar the initial measurement layout subwindows and display the main window |
||
2553 | InitMenu(); |
||
2554 | MeasurementLayout(); |
||
2555 | fMain->SetWindowName(WINDOW_NAME); |
||
2556 | fMain->MapSubwindows(); |
||
2557 | fMain->MapWindow(); |
||
2558 | fMain->Layout(); |
||
2559 | GetPosition(); |
||
2560 | GetVoltOut(); |
||
2561 | } |
||
2562 | |||
2563 | //--------------------------------------------------------------- |
||
2564 | // Event handler for menubar actions |
||
2565 | |||
2566 | void TGAppMainFrame::HandleMenu(Int_t id) |
||
2567 | { |
||
2568 | TList *files; |
||
2569 | |||
2570 | switch (id) { |
||
2571 | case M_FILE_NEW: |
||
2572 | // Clear any values and histogram |
||
2573 | break; |
||
2574 | |||
2575 | case M_FILE_EXIT: |
||
2576 | CloseWindow(); |
||
2577 | break; |
||
2578 | |||
2579 | case M_ANALYSIS_HISTTYPE_1DADC: |
||
2580 | // Toggles the ADC button |
||
2581 | ChangeHisttype(0); |
||
2582 | break; |
||
2583 | |||
2584 | case M_ANALYSIS_HISTTYPE_1DTDC: |
||
2585 | ChangeHisttype(1); |
||
2586 | break; |
||
2587 | |||
2588 | case M_ANALYSIS_HISTTYPE_2D: |
||
2589 | ChangeHisttype(2); |
||
2590 | break; |
||
2591 | |||
2592 | case M_ANALYSIS_HISTTYPE_SURF: |
||
2593 | ChangeHisttype(3); |
||
2594 | break; |
||
2595 | |||
2596 | case M_ANALYSIS_FIT: |
||
2597 | // Fit spectrum |
||
2598 | files = new TList(); |
||
2599 | fileList->GetSelectedEntries(files); |
||
2600 | |||
2601 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) && (files->GetSize() > 0) ) |
||
2602 | FitSpectrum(files, 1); |
||
2603 | break; |
||
2604 | |||
2605 | case M_ANALYSIS_FITSEL: |
||
2606 | // Fit all spectra |
||
2607 | files = new TList(); |
||
2608 | fileList->GetSelectedEntries(files); |
||
2609 | |||
2610 | if( (fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC)) && (files->GetSize() > 1) ) |
||
2611 | FitSpectrum(files, files->GetSize()); |
||
2612 | break; |
||
2613 | |||
2614 | case M_ANALYSIS_INTEGX: |
||
2615 | // Integrate the current spectra |
||
2616 | files = new TList(); |
||
2617 | fileList->GetSelectedEntries(files); |
||
2618 | |||
2619 | IntegSpectrum(files, 1); |
||
2620 | break; |
||
2621 | |||
2622 | case M_ANALYSIS_INTEGY: |
||
2623 | // Integrate the current spectra |
||
2624 | files = new TList(); |
||
2625 | fileList->GetSelectedEntries(files); |
||
2626 | |||
2627 | IntegSpectrum(files, 2); |
||
2628 | break; |
||
2629 | |||
2630 | case M_WINDOW_HOR: |
||
2631 | fMainFrame->TileHorizontal(); |
||
2632 | break; |
||
2633 | |||
2634 | case M_WINDOW_VERT: |
||
2635 | fMainFrame->TileVertical(); |
||
2636 | break; |
||
2637 | |||
2638 | case M_HELP_ABOUT: |
||
2639 | About(); |
||
2640 | break; |
||
2641 | |||
2642 | default: |
||
2643 | fMainFrame->SetCurrent(id); |
||
2644 | break; |
||
2645 | } |
||
2646 | } |
||
2647 | |||
2648 | //--------------------------------------------------------------- |
||
2649 | // Initialize the main window menu |
||
2650 | |||
2651 | void TGAppMainFrame::InitMenu() |
||
2652 | { |
||
2653 | fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); |
||
2654 | |||
2655 | // Popup menu in menubar for File controls |
||
2656 | fMenuFile = new TGPopupMenu(gClient->GetRoot()); // adds a new popup menu to the menubar |
||
2657 | fMenuFile->AddEntry(new TGHotString("&New Measurement"), M_FILE_NEW); |
||
2658 | fMenuFile->AddSeparator(); |
||
2659 | fMenuFile->AddEntry(new TGHotString("E&xit"), M_FILE_EXIT); |
||
2660 | |||
2661 | // Popup menu in menubar for Analysis controls |
||
2662 | fMenuHisttype = new TGPopupMenu(gClient->GetRoot()); // adds a cascade menu that will be incorporated into analysis controls |
||
2663 | fMenuHisttype->AddEntry(new TGHotString("1D &ADC histogram"), M_ANALYSIS_HISTTYPE_1DADC); |
||
2664 | fMenuHisttype->AddEntry(new TGHotString("1D &TDC histogram"), M_ANALYSIS_HISTTYPE_1DTDC); |
||
2665 | fMenuHisttype->AddEntry(new TGHotString("&2D ADC vs. TDC histogram"), M_ANALYSIS_HISTTYPE_2D); |
||
2666 | fMenuHisttype->AddEntry(new TGHotString("2D &surface scan plot"), M_ANALYSIS_HISTTYPE_SURF); |
||
2667 | |||
2668 | fMenuAnalysis = new TGPopupMenu(gClient->GetRoot()); // adds a new popup menu to the menubar |
||
2669 | fMenuAnalysis->AddPopup(new TGHotString("&Histogram type"), fMenuHisttype); |
||
2670 | |||
2671 | fMenuAnalysis->AddEntry(new TGHotString("&Fit spectrum"), M_ANALYSIS_FIT); |
||
2672 | fMenuAnalysis->AddEntry(new TGHotString("Fit &all selected"), M_ANALYSIS_FITSEL); |
||
2673 | fMenuAnalysis->AddEntry(new TGHotString("Integrate spectrum (&X direction)"), M_ANALYSIS_INTEGX); |
||
2674 | fMenuAnalysis->AddEntry(new TGHotString("Integrate spectrum (&Y direction)"), M_ANALYSIS_INTEGY); |
||
2675 | |||
2676 | // Popup menu in menubar for Window controls |
||
2677 | fMenuWindow = new TGPopupMenu(gClient->GetRoot()); // adds a new popup menu to the menubar |
||
2678 | fMenuWindow->AddEntry(new TGHotString("Tile &Horizontally"), M_WINDOW_HOR); |
||
2679 | fMenuWindow->AddEntry(new TGHotString("Tile &Vertically"), M_WINDOW_VERT); |
||
2680 | fMenuWindow->AddPopup(new TGHotString("&Windows"), fMainFrame->GetWinListMenu()); |
||
2681 | |||
2682 | // Popup menu in menubar for Help controls |
||
2683 | fMenuHelp = new TGPopupMenu(gClient->GetRoot()); |
||
2684 | fMenuHelp->AddEntry(new TGHotString("&About"), M_HELP_ABOUT); |
||
2685 | |||
2686 | // Connect all menu items with actions - handled by HandleMenu() |
||
2687 | fMenuFile->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
||
2688 | fMenuAnalysis->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
||
2689 | fMenuWindow->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
||
2690 | fMenuHelp->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
||
2691 | |||
2692 | // Draw the created popup menus on the menubar |
||
2693 | fMenuBar->AddPopup(new TGHotString("&File"), fMenuFile, fMenuBarItemLayout); |
||
2694 | fMenuBar->AddPopup(new TGHotString("&Analysis"),fMenuAnalysis,fMenuBarItemLayout); |
||
2695 | fMenuBar->AddPopup(new TGHotString("&Windows"),fMenuWindow,fMenuBarItemLayout); |
||
2696 | fMenuBar->AddPopup(new TGHotString("&Help"), fMenuHelp, fMenuBarItemLayout); |
||
2697 | } |
||
2698 | |||
2699 | //--------------------------------------------------------------- |
||
2700 | // Set the measurement subwindow layout |
||
2701 | |||
2702 | void TGAppMainFrame::MeasurementLayout() |
||
2703 | { |
||
2704 | TGMdiFrame *mdiFrame; |
||
2705 | |||
2706 | // Generic horizontal and vertical frames |
||
2707 | TGHorizontalFrame *fH1, *fH2, *fH3; |
||
2708 | TGVerticalFrame *fV1; |
||
2709 | TGGroupFrame *fG1; |
||
2710 | TGLabel *lab; |
||
2711 | TGCompositeFrame *fT1; |
||
2712 | |||
2713 | // Sizes of internal group and subwindow structures |
||
2714 | int subwin[2]; |
||
2715 | int subgroup[2]; |
||
2716 | |||
2717 | // Settings pane --------------------------------------------------------------------------- |
||
2718 | subwin[0] = (winWidth/6)-5; subwin[1] = 3*((winHeight/5)-5)-10; |
||
2719 | settingsPane = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
2720 | mdiFrame = settingsPane->GetMdiFrame(); |
||
2721 | |||
2722 | // Check button to toggle voltage scan |
||
2723 | voltscanOn = new TGCheckButton(mdiFrame, "Voltage scan ON/OFF"); |
||
2724 | voltscanOn->Resize(50,22); |
||
2725 | voltscanOn->SetState(kButtonUp); |
||
2726 | mdiFrame->AddFrame(voltscanOn, f0centerx); |
||
2727 | |||
2728 | // Check button to toggle surface scan |
||
2729 | surfscanOn = new TGCheckButton(mdiFrame, "Surface scan ON/OFF"); |
||
2730 | surfscanOn->Resize(50,22); |
||
2731 | surfscanOn->SetState(kButtonUp); |
||
2732 | mdiFrame->AddFrame(surfscanOn, f0centerx); |
||
2733 | |||
2734 | // Check button to toggle Z direction scan |
||
2735 | zscanOn = new TGCheckButton(mdiFrame, "Z-axis scan ON/OFF"); |
||
2736 | zscanOn->Resize(50,22); |
||
2737 | zscanOn->SetState(kButtonUp); |
||
2738 | mdiFrame->AddFrame(zscanOn, f0centerx); |
||
2739 | |||
2740 | // Check button to toggle (open) the histogram window |
||
2741 | // histogramOn = new TGCheckButton(mdiFrame, "Histogram display ON/OFF"); |
||
2742 | // histogramOn->Resize(50,22); |
||
2743 | // histogramOn->SetState(kButtonUp); |
||
2744 | // mdiFrame->AddFrame(histogramOn, f0centerx); |
||
2745 | |||
2746 | subgroup[0] = subwin[0]-10; |
||
2747 | // Hard limit for maximum voltage we can set |
||
2748 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
2749 | lab = new TGLabel(fH1, "Voltage limit:"); |
||
2750 | fH1->AddFrame(lab, f0center2d); |
||
2751 | vHardlimit = new TGNumberEntry(fH1, 70.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
2752 | vHardlimit->Resize(80,22); |
||
2753 | fH1->AddFrame(vHardlimit, f0center2d); |
||
2754 | mdiFrame->AddFrame(fH1, f2); |
||
2755 | |||
2756 | // Number of used channels |
||
2757 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
2758 | lab = new TGLabel(fH1, "Nr. of channels:"); |
||
2759 | fH1->AddFrame(lab, f0center2d); |
||
2760 | NCH = new TGNumberEntry(fH1, 1, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 8); |
||
2761 | NCH->Resize(40,22); |
||
2762 | fH1->AddFrame(NCH, f0center2d); |
||
2763 | mdiFrame->AddFrame(fH1, f2); |
||
2764 | |||
2765 | // Check button to toggle plots with additional information or clean plots |
||
2766 | cleanOn = new TGCheckButton(mdiFrame, "Clean plots ON/OFF"); |
||
2767 | cleanOn->Resize(50,22); |
||
2768 | cleanOn->SetState(kButtonDown); |
||
2769 | cleanPlots = 1; |
||
2770 | mdiFrame->AddFrame(cleanOn, f0centerx); |
||
2771 | |||
2772 | // Button and textbox to enter the oscilloscope IP address |
||
2773 | lab = new TGLabel(mdiFrame, "Scope IP:"); |
||
2774 | mdiFrame->AddFrame(lab, f0); |
||
2775 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
2776 | oscIP = new TGTextEntry(fH1, "178.172.43.157"); |
||
2777 | oscIP->Resize(110,22); |
||
2778 | fH1->AddFrame(oscIP, f0); |
||
2779 | oscConnect = new TGTextButton(fH1, "Connect"); |
||
2780 | oscConnect->SetTextJustify(36); |
||
2781 | oscConnect->SetWrapLength(-1); |
||
2782 | oscConnect->Resize(60,22); |
||
2783 | fH1->AddFrame(oscConnect, f0); |
||
2784 | oscOn = 0; |
||
2785 | mdiFrame->AddFrame(fH1, f2); |
||
2786 | |||
2787 | // Laser settings (freq., tune, ND filter) |
||
2788 | lab = new TGLabel(mdiFrame, "Laser settings:"); |
||
2789 | mdiFrame->AddFrame(lab, f0); |
||
2790 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
2791 | laserInfo = new TGTextEntry(fH1, "kHz, tune, ND"); |
||
2792 | fH1->AddFrame(laserInfo, f2); |
||
2793 | mdiFrame->AddFrame(fH1, f2); |
||
2794 | |||
2795 | mdiFrame->SetMdiHints(kMdiMinimize); |
||
2796 | mdiFrame->SetWindowName("Settings pane"); |
||
2797 | mdiFrame->MapSubwindows(); |
||
2798 | mdiFrame->Layout(); |
||
2799 | mdiFrame->Move(0,0); |
||
2800 | // Settings pane --------------------------------------------------------------------------- |
||
2801 | |||
2802 | // Main window ----------------------------------------------------------------------------- |
||
2803 | subwin[0] = 3*((winWidth/6)-5); subwin[1] = 3*((winHeight/5)-5)-10; |
||
2804 | mainSubwindow = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
2805 | mdiFrame = mainSubwindow->GetMdiFrame(); |
||
2806 | |||
2807 | // Voltage and position tab |
||
2808 | subgroup[0] = 2*subwin[0]/5-12; |
||
2809 | subgroup[1] = (subwin[1]+15)/2+5; |
||
2810 | setTab = new TGTab(mdiFrame, subgroup[0], subgroup[1]); |
||
2811 | |||
2812 | fT1 = setTab->AddTab("Voltage + Position"); |
||
2813 | |||
2814 | fH1 = new TGHorizontalFrame(fT1, subwin[0], subgroup[1], kFixedHeight); |
||
2815 | // Left pane (Bias voltage controls) |
||
2816 | fV1 = new TGVerticalFrame(fH1, subgroup[0], subgroup[1], kFixedWidth | kFixedHeight); |
||
2817 | fG1 = new TGGroupFrame(fV1, "Bias voltage controls"); |
||
2818 | |||
2819 | // Output voltage supply channel |
||
2820 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2821 | lab = new TGLabel(fH2, "Output channel:"); |
||
2822 | fH2->AddFrame(lab, f0center2d); |
||
2823 | vOutCh = new TGComboBox(fH2, 200); |
||
2824 | vOutCh->AddEntry("1", 0); |
||
2825 | vOutCh->AddEntry("2", 1); |
||
2826 | vOutCh->AddEntry("3", 2); |
||
2827 | vOutCh->AddEntry("4", 3); |
||
2828 | vOutCh->AddEntry("5", 4); |
||
2829 | vOutCh->AddEntry("6", 5); |
||
2830 | vOutCh->AddEntry("7", 6); |
||
2831 | vOutCh->AddEntry("8", 7); |
||
2832 | vOutCh->AddEntry("101", 8); |
||
2833 | vOutCh->AddEntry("102", 9); |
||
2834 | vOutCh->AddEntry("103", 10); |
||
2835 | vOutCh->AddEntry("104", 11); |
||
2836 | vOutCh->AddEntry("105", 12); |
||
2837 | vOutCh->AddEntry("106", 13); |
||
2838 | vOutCh->AddEntry("107", 14); |
||
2839 | vOutCh->AddEntry("108", 15); |
||
2840 | vOutCh->Resize(50,22); |
||
2841 | vOutCh->Select(0); |
||
2842 | fH2->AddFrame(vOutCh, f0center2d); |
||
2843 | fG1->AddFrame(fH2, f2); |
||
2844 | |||
2845 | // Output voltage setting |
||
2846 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2847 | lab = new TGLabel(fH2, "Output voltage:"); |
||
2848 | fH2->AddFrame(lab, f0center2d); |
||
2849 | vOut = new TGNumberEntry(fH2, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, 0, vHardlimit->GetNumber()); |
||
2850 | vOut->Resize(80,22); |
||
2851 | fH2->AddFrame(vOut, f0center2d); |
||
2852 | fG1->AddFrame(fH2, f2); |
||
2853 | |||
2854 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2855 | vOutOnOff = new TGCheckButton(fH2, "Output ON/OFF"); |
||
2856 | vOutOnOff->Resize(subgroup[0]-10,22); |
||
2857 | vOutOnOff->SetState(kButtonUp); |
||
2858 | fH2->AddFrame(vOutOnOff, f0centerx); |
||
2859 | fG1->AddFrame(fH2, f2); |
||
2860 | |||
2861 | // Set, get and reset voltage buttons |
||
2862 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2863 | fH3 = new TGHorizontalFrame(fH2, subgroup[0], 30); |
||
2864 | vOutSet = new TGTextButton(fH3, "Set"); |
||
2865 | vOutSet->SetTextJustify(36); |
||
2866 | vOutSet->SetWrapLength(-1); |
||
2867 | vOutSet->Resize(60,22); |
||
2868 | fH3->AddFrame(vOutSet, f0); |
||
2869 | vOutGet = new TGTextButton(fH3, "Get"); |
||
2870 | vOutGet->SetTextJustify(36); |
||
2871 | vOutGet->SetWrapLength(-1); |
||
2872 | vOutGet->Resize(60,22); |
||
2873 | fH3->AddFrame(vOutGet, f0); |
||
2874 | vOutReset = new TGTextButton(fH3, "Reset"); |
||
2875 | vOutReset->SetTextJustify(36); |
||
2876 | vOutReset->SetWrapLength(-1); |
||
2877 | vOutReset->Resize(60,22); |
||
2878 | fH3->AddFrame(vOutReset, f0); |
||
2879 | fH2->AddFrame(fH3, f0centerx); |
||
2880 | fG1->AddFrame(fH2, f2); |
||
2881 | |||
2882 | // Voltage scan controls |
||
2883 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2884 | lab = new TGLabel(fH2, "V (min):"); |
||
2885 | fH2->AddFrame(lab, f0center2d); |
||
2886 | vOutStart = new TGNumberEntry(fH2, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
2887 | vOutStart->Resize(80,22); |
||
2888 | fH2->AddFrame(vOutStart, f0center2d); |
||
2889 | fG1->AddFrame(fH2, f2); |
||
2890 | |||
2891 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2892 | lab = new TGLabel(fH2, "V (max):"); |
||
2893 | fH2->AddFrame(lab, f0center2d); |
||
2894 | vOutStop = new TGNumberEntry(fH2, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
2895 | vOutStop->Resize(80,22); |
||
2896 | fH2->AddFrame(vOutStop, f0center2d); |
||
2897 | fG1->AddFrame(fH2, f2); |
||
2898 | |||
2899 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2900 | lab = new TGLabel(fH2, "V (step):"); |
||
2901 | fH2->AddFrame(lab, f0center2d); |
||
2902 | vOutStep = new TGNumberEntry(fH2, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
2903 | vOutStep->Resize(80,22); |
||
2904 | fH2->AddFrame(vOutStep, f0center2d); |
||
2905 | fG1->AddFrame(fH2, f2); |
||
2906 | |||
2907 | fV1->AddFrame(fG1, f1); |
||
2908 | // Left pane (Bias voltage controls) |
||
2909 | fH1->AddFrame(fV1, f0); |
||
2910 | |||
2911 | // Right pane (Table position controls) |
||
2912 | subgroup[0] = 3*subwin[0]/5-12; |
||
2913 | fV1 = new TGVerticalFrame(fH1, subgroup[0], subgroup[1], kFixedWidth | kFixedHeight); |
||
2914 | fG1 = new TGGroupFrame(fV1, "Table position controls"); |
||
2915 | |||
2916 | // X, Y and Z positions |
||
2917 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2918 | lab = new TGLabel(fH2, "X:"); |
||
2919 | fH2->AddFrame(lab, f0center2d); |
||
2920 | xPos = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
2921 | xPos->Resize(80,22); |
||
2922 | fH2->AddFrame(xPos, f0center2d); |
||
2923 | |||
2924 | lab = new TGLabel(fH2, "Z (min):"); |
||
2925 | fH2->AddFrame(lab, f0center2d); |
||
2926 | zPosMin = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 375000); |
||
2927 | zPosMin->Resize(80,22); |
||
2928 | fH2->AddFrame(zPosMin, f0center2d); |
||
2929 | fG1->AddFrame(fH2, f2); |
||
2930 | |||
2931 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2932 | lab = new TGLabel(fH2, "Y:"); |
||
2933 | fH2->AddFrame(lab, f0center2d); |
||
2934 | yPos = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
2935 | yPos->Resize(80,22); |
||
2936 | fH2->AddFrame(yPos, f0center2d); |
||
2937 | |||
2938 | lab = new TGLabel(fH2, "Z (max):"); |
||
2939 | fH2->AddFrame(lab, f0center2d); |
||
2940 | zPosMax = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 375000); |
||
2941 | zPosMax->Resize(80,22); |
||
2942 | fH2->AddFrame(zPosMax, f0center2d); |
||
2943 | fG1->AddFrame(fH2, f2); |
||
2944 | |||
2945 | fH2 = new TGHorizontalFrame(fG1, subgroup[0] ,30); |
||
2946 | lab = new TGLabel(fH2, "Z:"); |
||
2947 | fH2->AddFrame(lab, f0center2d); |
||
2948 | zPos = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 375000); |
||
2949 | zPos->Resize(80,22); |
||
2950 | fH2->AddFrame(zPos, f0center2d); |
||
2951 | |||
2952 | lab = new TGLabel(fH2, "Z (step):"); |
||
2953 | fH2->AddFrame(lab, f0center2d); |
||
2954 | zPosStep = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
2955 | zPosStep->Resize(80,22); |
||
2956 | fH2->AddFrame(zPosStep, f0center2d); |
||
2957 | fG1->AddFrame(fH2, f2); |
||
2958 | |||
2959 | // Set, Get and Home the table position |
||
2960 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2961 | fH3 = new TGHorizontalFrame(fH2, subgroup[0], 30); |
||
2962 | positionSet = new TGTextButton(fH3, "Set"); |
||
2963 | positionSet->SetTextJustify(36); |
||
2964 | positionSet->SetWrapLength(-1); |
||
2965 | positionSet->Resize(60,22); |
||
2966 | fH3->AddFrame(positionSet, f0); |
||
2967 | positionGet = new TGTextButton(fH3, "Get"); |
||
2968 | positionGet->SetTextJustify(36); |
||
2969 | positionGet->SetWrapLength(-1); |
||
2970 | positionGet->Resize(60,22); |
||
2971 | fH3->AddFrame(positionGet, f0); |
||
2972 | positionHome = new TGTextButton(fH3, "Home"); |
||
2973 | positionHome->SetTextJustify(36); |
||
2974 | positionHome->SetWrapLength(-1); |
||
2975 | positionHome->Resize(60,22); |
||
2976 | fH3->AddFrame(positionHome, f0); |
||
2977 | fH2->AddFrame(fH3, f0centerx); |
||
2978 | fG1->AddFrame(fH2, f2); |
||
2979 | |||
2980 | // Position scan controls |
||
2981 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2982 | lab = new TGLabel(fH2, "X (min):"); |
||
2983 | fH2->AddFrame(lab, f0center2d); |
||
2984 | xPosMin = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
2985 | xPosMin->Resize(80,22); |
||
2986 | fH2->AddFrame(xPosMin, f0center2d); |
||
2987 | |||
2988 | lab = new TGLabel(fH2, "Y (min):"); |
||
2989 | fH2->AddFrame(lab, f0center2d); |
||
2990 | yPosMin = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
2991 | yPosMin->Resize(80,22); |
||
2992 | fH2->AddFrame(yPosMin, f0center2d); |
||
2993 | fG1->AddFrame(fH2, f2); |
||
2994 | |||
2995 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
2996 | lab = new TGLabel(fH2, "X (max):"); |
||
2997 | fH2->AddFrame(lab, f0center2d); |
||
2998 | xPosMax = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
2999 | xPosMax->Resize(80,22); |
||
3000 | fH2->AddFrame(xPosMax, f0center2d); |
||
3001 | |||
3002 | lab = new TGLabel(fH2, "Y (max):"); |
||
3003 | fH2->AddFrame(lab, f0center2d); |
||
3004 | yPosMax = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
3005 | yPosMax->Resize(80,22); |
||
3006 | fH2->AddFrame(yPosMax, f0center2d); |
||
3007 | fG1->AddFrame(fH2, f2); |
||
3008 | |||
3009 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3010 | lab = new TGLabel(fH2, "X (step):"); |
||
3011 | fH2->AddFrame(lab, f0center2d); |
||
3012 | xPosStep = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
3013 | xPosStep->Resize(80,22); |
||
3014 | fH2->AddFrame(xPosStep, f0center2d); |
||
3015 | |||
3016 | lab = new TGLabel(fH2, "Y (step):"); |
||
3017 | fH2->AddFrame(lab, f0center2d); |
||
3018 | yPosStep = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
3019 | yPosStep->Resize(80,22); |
||
3020 | fH2->AddFrame(yPosStep, f0center2d); |
||
3021 | fG1->AddFrame(fH2, f2); |
||
3022 | |||
3023 | fV1->AddFrame(fG1, f1); |
||
3024 | // Right pane (Table position controls) |
||
3025 | fH1->AddFrame(fV1, f0); |
||
3026 | fT1->AddFrame(fH1, f1); |
||
3027 | |||
3028 | // Waveform tab |
||
3029 | fT1 = setTab->AddTab("Waveform"); |
||
3030 | fH1 = new TGHorizontalFrame(fT1, subwin[0], subgroup[1], kFixedHeight); |
||
3031 | lab = new TGLabel(fH1, "Waveform controls"); |
||
3032 | fH1->AddFrame(lab, f0center2d); |
||
3033 | fT1->AddFrame(fH1, f0); |
||
3034 | |||
3035 | // Wave measurements tab |
||
3036 | fT1 = setTab->AddTab("Measurement"); |
||
3037 | fH1 = new TGHorizontalFrame(fT1, subwin[0], subgroup[1], kFixedHeight); |
||
3038 | lab = new TGLabel(fH1, "Waveform measurement controls"); |
||
3039 | fH1->AddFrame(lab, f0center2d); |
||
3040 | fT1->AddFrame(fH1, f0); |
||
3041 | |||
3042 | mdiFrame->AddFrame(setTab, f0); |
||
3043 | // Disable the two tabs regarding the Scope if not connected to one |
||
3044 | setTab->SetEnabled(1,kFALSE); |
||
3045 | setTab->SetEnabled(2,kFALSE); |
||
3046 | |||
3047 | // Bottom pane (File controls) |
||
3048 | subgroup[0] = subwin[0]-20; |
||
3049 | subgroup[1] = subwin[1]/3-30; //2*(3*((winWidth/6)-5))/5+10; |
||
3050 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], subgroup[1] /*1*(3*((winWidth/6)-5))/5+15*/ , kFixedWidth | kFixedHeight); |
||
3051 | fG1 = new TGGroupFrame(fH1, "Event/Data file controls"); |
||
3052 | |||
3053 | // Number of events |
||
3054 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3055 | lab = new TGLabel(fH2, "Number of events:"); |
||
3056 | fH2->AddFrame(lab, f0centery); |
||
3057 | evtNum = new TGNumberEntry(fH2, 10000, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
3058 | evtNum->Resize(80,22); |
||
3059 | fH2->AddFrame(evtNum, f0centery); |
||
3060 | fG1->AddFrame(fH2, f2); |
||
3061 | |||
3062 | // Time stamp display |
||
3063 | fH2 = new TGHorizontalFrame(fG1,600,200); |
||
3064 | lab = new TGLabel(fH2, "Time stamp:"); |
||
3065 | fH2->AddFrame(lab, f0centery); |
||
3066 | timeStamp = new TGTextEntry(fH2, ""); |
||
3067 | timeStamp->Resize(440,22); |
||
3068 | timeStamp->SetState(kFALSE); // time stamp is read-only |
||
3069 | fH2->AddFrame(timeStamp, f0centery); |
||
3070 | fG1->AddFrame(fH2, f2); |
||
3071 | |||
3072 | // Save to file |
||
3073 | fH2 = new TGHorizontalFrame(fG1,600,200); |
||
3074 | lab = new TGLabel(fH2, "Save to file:"); |
||
3075 | fH2->AddFrame(lab, f0centery); |
||
3076 | char *cTemp; |
||
3077 | cTemp = new char[256]; |
||
3078 | sprintf(cTemp, "./results/test%s", histExt); |
||
3079 | fileName = new TGTextEntry(fH2, cTemp); |
||
3080 | delete[] cTemp; |
||
3081 | fileName->Resize(400,22); |
||
3082 | fileName->SetState(kFALSE); |
||
3083 | fH2->AddFrame(fileName, f0centery); |
||
3084 | saveFile = new TGTextButton(fH2, "..."); |
||
3085 | saveFile->SetTextJustify(36); |
||
3086 | saveFile->SetWrapLength(-1); |
||
3087 | saveFile->Resize(80,22); |
||
3088 | fH2->AddFrame(saveFile, f0centery); |
||
3089 | // mdiFrame->AddFrame(fH2, f0); |
||
3090 | fG1->AddFrame(fH2, f2); |
||
3091 | fH1->AddFrame(fG1, f1); |
||
3092 | // Bottom pane (File controls) |
||
3093 | mdiFrame->AddFrame(fH1, f0); |
||
3094 | |||
3095 | subgroup[0] = subwin[0]-70; |
||
3096 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3097 | fH2 = new TGHorizontalFrame(fH1, 3*subgroup[0]/4, 30, kFixedWidth); |
||
3098 | measStart = new TGTextButton(fH2, "Start acquisition"); |
||
3099 | measStart->SetTextJustify(36); |
||
3100 | measStart->SetWrapLength(-1); |
||
3101 | measStart->Resize(80,22); |
||
3102 | fH2->AddFrame(measStart, f0center2d); |
||
3103 | |||
3104 | ULong_t fcolor; |
||
3105 | gClient->GetColorByName("red", fcolor); |
||
3106 | |||
3107 | busyLabel = new TGLabel(fH2, "Busy"); //, fTextGC->GetGC(), labelfont, kChildFrame); |
||
3108 | busyLabel->SetTextJustify(36); |
||
3109 | busyLabel->Resize(80,22); |
||
3110 | busyLabel->Disable(); |
||
3111 | busyLabel->SetTextColor(fcolor); |
||
3112 | fH2->AddFrame(busyLabel, f0center2d); |
||
3113 | |||
3114 | curProgress = new TGHProgressBar(fH2, TGProgressBar::kStandard, 150); |
||
3115 | curProgress->ShowPosition(); |
||
3116 | curProgress->SetRange(0,100); |
||
3117 | curProgress->SetBarColor("green"); |
||
3118 | fH2->AddFrame(curProgress, f0center2d); |
||
3119 | fH1->AddFrame(fH2, f0centerx); |
||
3120 | mdiFrame->AddFrame(fH1, f2); |
||
3121 | |||
3122 | mdiFrame->SetMdiHints(kMdiMinimize | kMdiMaximize); |
||
3123 | mdiFrame->SetWindowName("Main measurement window"); |
||
3124 | mdiFrame->MapSubwindows(); |
||
3125 | mdiFrame->Layout(); |
||
3126 | mdiFrame->Move((winWidth/6),0); |
||
3127 | // Main window ----------------------------------------------------------------------------- |
||
3128 | |||
3129 | // Histogram pane -------------------------------------------------------------------------- |
||
3130 | subwin[0] = 2*((winWidth/6)-5); subwin[1] = (int)(2.5*((winHeight/5)-5))-5; |
||
3131 | histogramPane = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
3132 | mdiFrame = histogramPane->GetMdiFrame(); |
||
3133 | |||
3134 | histCanvas = new TRootEmbeddedCanvas("histCanvas",mdiFrame,900,900); |
||
3135 | mdiFrame->AddFrame(histCanvas, f1); |
||
3136 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
3137 | gCanvas->SetGridx(); |
||
3138 | gCanvas->SetGridy(); |
||
3139 | |||
3140 | mdiFrame->SetMdiHints(kMdiMinimize | kMdiMaximize); |
||
3141 | mdiFrame->SetWindowName("Histogram"); |
||
3142 | mdiFrame->MapSubwindows(); |
||
3143 | mdiFrame->Layout(); |
||
3144 | mdiFrame->Move(4*((winWidth/6)-5)+10,0); |
||
3145 | // Histogram pane -------------------------------------------------------------------------- |
||
3146 | |||
3147 | // Histogram file selection pane ----------------------------------------------------------- |
||
3148 | subwin[0] = 4*((winWidth/6)-5); subwin[1] = 2*((winHeight/5)-5)+15; |
||
3149 | histogramPaneFile = new TGMdiSubwindow(fMainFrame, subwin[0]+5, subwin[1]); |
||
3150 | mdiFrame = histogramPaneFile->GetMdiFrame(); |
||
3151 | |||
3152 | // Open browser for file selection |
||
3153 | subgroup[0] = subwin[0]-10; |
||
3154 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3155 | lab = new TGLabel(fH1, "File selection:"); |
||
3156 | fH1->AddFrame(lab, f0centery); |
||
3157 | |||
3158 | selectDir = new TGTextButton(fH1, "..."); |
||
3159 | selectDir->SetTextJustify(36); |
||
3160 | selectDir->SetWrapLength(-1); |
||
3161 | selectDir->Resize(80,22); |
||
3162 | fH1->AddFrame(selectDir, f0centery); |
||
3163 | mdiFrame->AddFrame(fH1, f2); |
||
3164 | |||
3165 | // List view of the opened files |
||
3166 | fileList = new TGListBox(mdiFrame,1); |
||
3167 | fileList->GetVScrollbar(); |
||
3168 | fileList->Resize(300, (subwin[1]/2)-10 ); |
||
3169 | mdiFrame->AddFrame(fileList, f2); |
||
3170 | |||
3171 | // Multiple file selection toggle, previous/next controls and clear list |
||
3172 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3173 | multiSelect = new TGCheckButton(fH1, "Multiple file select"); |
||
3174 | multiSelect->Resize(50,22); |
||
3175 | multiSelect->SetState(kButtonUp); |
||
3176 | fH1->AddFrame(multiSelect, f0); |
||
3177 | |||
3178 | multiSelectAll = new TGCheckButton(fH1, "Select all listed files"); |
||
3179 | multiSelectAll->Resize(50,22); |
||
3180 | multiSelectAll->SetState(kButtonUp); |
||
3181 | fH1->AddFrame(multiSelectAll, f0); |
||
3182 | |||
3183 | TGTextButton *clearList = new TGTextButton(fH1, "Clear list"); |
||
3184 | clearList->SetTextJustify(36); |
||
3185 | clearList->SetWrapLength(-1); |
||
3186 | clearList->Resize(80,22); |
||
3187 | fH1->AddFrame(clearList, f0right); |
||
3188 | |||
3189 | nextFile = new TGTextButton(fH1, ">>"); |
||
3190 | nextFile->SetTextJustify(36); |
||
3191 | nextFile->SetWrapLength(-1); |
||
3192 | nextFile->Resize(80,22); |
||
3193 | fH1->AddFrame(nextFile, f0right); |
||
3194 | |||
3195 | prevFile = new TGTextButton(fH1, "<<"); |
||
3196 | prevFile->SetTextJustify(36); |
||
3197 | prevFile->SetWrapLength(-1); |
||
3198 | prevFile->Resize(80,22); |
||
3199 | fH1->AddFrame(prevFile, f0right); |
||
3200 | mdiFrame->AddFrame(fH1, f2); |
||
3201 | |||
3202 | mdiFrame->SetMdiHints(kMdiMinimize); |
||
3203 | mdiFrame->SetWindowName("Histogram file selection"); |
||
3204 | mdiFrame->MapSubwindows(); |
||
3205 | mdiFrame->Layout(); |
||
3206 | mdiFrame->Move(0,3*((winHeight/5)-5)-5); |
||
3207 | // Histogram file selection pane ----------------------------------------------------------- |
||
3208 | |||
3209 | // Histogram controls pane ----------------------------------------------------------------- |
||
3210 | subwin[0] = 2*((winWidth/6)-5); subwin[1] = (int)(2.5*((winHeight/5)-5))+10; |
||
3211 | histogramPaneCtr = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
3212 | mdiFrame = histogramPaneCtr->GetMdiFrame(); |
||
3213 | |||
3214 | // Control for histogram X range |
||
3215 | subgroup[0] = subwin[0]-10; |
||
3216 | fG1 = new TGGroupFrame(mdiFrame, "Histogram display"); |
||
3217 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3218 | lab = new TGLabel(fH1, "ADC range (min, max):"); |
||
3219 | fH1->AddFrame(lab, f0centery); |
||
3220 | adcMinRange = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber); |
||
3221 | adcMinRange->Resize(80,22); |
||
3222 | fH1->AddFrame(adcMinRange, f0centery); |
||
3223 | adcMaxRange = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber); |
||
3224 | adcMaxRange->Resize(80,22); |
||
3225 | fH1->AddFrame(adcMaxRange, f0centery); |
||
3226 | fG1->AddFrame(fH1, f2); |
||
3227 | |||
3228 | // TDC window for getting data |
||
3229 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3230 | lab = new TGLabel(fH1, "TDC range (min, max):"); |
||
3231 | fH1->AddFrame(lab, f0centery); |
||
3232 | tdcMinwindow = new TGNumberEntry(fH1, 0.0, 6, 999, TGNumberFormat::kNESRealTwo, TGNumberFormat::kNEAAnyNumber); |
||
3233 | tdcMinwindow->Resize(80,22); |
||
3234 | fH1->AddFrame(tdcMinwindow, f0centery); |
||
3235 | tdcMaxwindow = new TGNumberEntry(fH1, 221.8, 6, 999, TGNumberFormat::kNESRealTwo, TGNumberFormat::kNEAAnyNumber); |
||
3236 | tdcMaxwindow->Resize(80,22); |
||
3237 | fH1->AddFrame(tdcMaxwindow, f0centery); |
||
3238 | fG1->AddFrame(fH1, f2); |
||
3239 | |||
3240 | // Y axis range settings |
||
3241 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3242 | lab = new TGLabel(fH1, "Y range (min, max):"); |
||
3243 | fH1->AddFrame(lab, f0centery); |
||
3244 | yMinRange = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAAnyNumber); |
||
3245 | yMinRange->Resize(80,22); |
||
3246 | fH1->AddFrame(yMinRange, f0centery); |
||
3247 | yMaxRange = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAAnyNumber); |
||
3248 | yMaxRange->Resize(80,22); |
||
3249 | fH1->AddFrame(yMaxRange, f0centery); |
||
3250 | fG1->AddFrame(fH1, f2); |
||
3251 | |||
3252 | // Select the channel to display |
||
3253 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3254 | lab = new TGLabel(fH1, "Display channel:"); |
||
3255 | fH1->AddFrame(lab, f0centery); |
||
3256 | selectCh = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, (NCH->GetNumber())-1); |
||
3257 | selectCh->Resize(40,22); |
||
3258 | fH1->AddFrame(selectCh, f0centery); |
||
3259 | |||
3260 | changeADC = new TGTextButton(fH1, "ADC"); |
||
3261 | changeADC->AllowStayDown(kTRUE); |
||
3262 | changeADC->SetDown(kTRUE); |
||
3263 | fMenuHisttype->CheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
3264 | changeADC->SetTextJustify(36); |
||
3265 | changeADC->SetWrapLength(-1); |
||
3266 | changeADC->Resize(60,22); |
||
3267 | fH1->AddFrame(changeADC, f0centery); |
||
3268 | |||
3269 | changeTDC = new TGTextButton(fH1, "TDC"); |
||
3270 | changeTDC->AllowStayDown(kTRUE); |
||
3271 | changeTDC->SetTextJustify(36); |
||
3272 | changeTDC->SetWrapLength(-1); |
||
3273 | changeTDC->Resize(60,22); |
||
3274 | fH1->AddFrame(changeTDC, f0centery); |
||
3275 | |||
3276 | changeADCTDC = new TGTextButton(fH1, "ADC/TDC"); |
||
3277 | changeADCTDC->AllowStayDown(kTRUE); |
||
3278 | changeADCTDC->SetTextJustify(36); |
||
3279 | changeADCTDC->SetWrapLength(-1); |
||
3280 | changeADCTDC->Resize(60,22); |
||
3281 | fH1->AddFrame(changeADCTDC, f0centery); |
||
3282 | |||
3283 | change2Dsurf = new TGTextButton(fH1, "Surf 2D"); |
||
3284 | change2Dsurf->AllowStayDown(kTRUE); |
||
3285 | change2Dsurf->SetTextJustify(36); |
||
3286 | change2Dsurf->SetWrapLength(-1); |
||
3287 | change2Dsurf->Resize(60,22); |
||
3288 | fH1->AddFrame(change2Dsurf, f0); |
||
3289 | fG1->AddFrame(fH1, f2); |
||
3290 | |||
3291 | logscale = new TGCheckButton(fG1, "Logarithmic scale ON/OFF"); |
||
3292 | logscale->Resize(50,22); |
||
3293 | logscale->SetState(kButtonUp); |
||
3294 | fG1->AddFrame(logscale, f0centerx); |
||
3295 | |||
3296 | // Export the selected files |
||
3297 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 100); |
||
3298 | fH2 = new TGHorizontalFrame(fH1, subgroup[0], 100); |
||
3299 | lab = new TGLabel(fH2, "Export selected histograms:"); |
||
3300 | fH2->AddFrame(lab, f0centery); |
||
3301 | |||
3302 | exportHist = new TGTextButton(fH2, "Export"); |
||
3303 | exportHist->SetTextJustify(36); |
||
3304 | exportHist->SetWrapLength(-1); |
||
3305 | exportHist->Resize(80,22); |
||
3306 | fH2->AddFrame(exportHist, f0centery); |
||
3307 | fH1->AddFrame(fH2, f0centerx); |
||
3308 | fG1->AddFrame(fH1, f2); |
||
3309 | mdiFrame->AddFrame(fG1, f2); |
||
3310 | |||
3311 | // Fitting controls for ADC spectrum |
||
3312 | fG1 = new TGGroupFrame(mdiFrame, "Fit Settings"); |
||
3313 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3314 | lab = new TGLabel(fH1, "Peak sigma:"); |
||
3315 | fH1->AddFrame(lab, f0centery); |
||
3316 | fitSigma = new TGNumberEntry(fH1, 1.5, 3, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEANonNegative); |
||
3317 | fitSigma->Resize(60,22); |
||
3318 | fH1->AddFrame(fitSigma, f0centery); |
||
3319 | fG1->AddFrame(fH1, f2); |
||
3320 | |||
3321 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3322 | lab = new TGLabel(fH1, "Signal/Noise treshold:"); |
||
3323 | fH1->AddFrame(lab, f0centery); |
||
3324 | fitTresh = new TGNumberEntry(fH1, 5.0E-3, 3, 999, TGNumberFormat::kNESReal, TGNumberFormat::kNEANonNegative); |
||
3325 | fitTresh->Resize(60,22); |
||
3326 | fH1->AddFrame(fitTresh, f0centery); |
||
3327 | fG1->AddFrame(fH1, f2); |
||
3328 | |||
3329 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3330 | lab = new TGLabel(fH1, "Background interpolation:"); |
||
3331 | fH1->AddFrame(lab, f0centery); |
||
3332 | fitInter = new TGNumberEntry(fH1, 8, 3, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
3333 | fitInter->Resize(60,22); |
||
3334 | fH1->AddFrame(fitInter, f0centery); |
||
3335 | fG1->AddFrame(fH1, f2); |
||
3336 | |||
3337 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3338 | lab = new TGLabel(fH1, "Peak fit max. acceptable error:"); |
||
3339 | fH1->AddFrame(lab, f0centery); |
||
3340 | accError = new TGNumberEntry(fH1, 0.15, 3, 999, TGNumberFormat::kNESRealTwo, TGNumberFormat::kNEANonNegative); |
||
3341 | accError->Resize(60,22); |
||
3342 | fH1->AddFrame(accError, f0centery); |
||
3343 | fG1->AddFrame(fH1, f2); |
||
3344 | |||
3345 | exfitplots = new TGCheckButton(fG1, "Export fitting plots ON/OFF"); |
||
3346 | exfitplots->Resize(50,22); |
||
3347 | exfitplots->SetState(kButtonDown); |
||
3348 | fG1->AddFrame(exfitplots, f0centerx); |
||
3349 | mdiFrame->AddFrame(fG1, f2); |
||
3350 | |||
3351 | mdiFrame->SetMdiHints(kMdiMinimize); |
||
3352 | mdiFrame->SetWindowName("Histogram controls"); |
||
3353 | mdiFrame->MapSubwindows(); |
||
3354 | mdiFrame->Layout(); |
||
3355 | mdiFrame->Move(4*((winWidth/6)-5)+10,(int)(2.5*((winHeight/5)-5))); |
||
3356 | // Histogram controls pane ----------------------------------------------------------------- |
||
3357 | |||
3358 | // Action connections |
||
3359 | voltscanOn->Connect("Clicked()", "TGAppMainFrame", this, "EnableVoltScan()"); |
||
3360 | surfscanOn->Connect("Clicked()", "TGAppMainFrame", this, "EnableSurfScan()"); |
||
3361 | zscanOn->Connect("Clicked()", "TGAppMainFrame", this, "EnableZaxisScan()"); |
||
3362 | // histogramOn->Connect("Clicked()", "TGAppMainFrame", this, "HistogramToggle()"); |
||
3363 | vHardlimit->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "VoltageLimit()"); |
||
3364 | (vHardlimit->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "VoltageLimit()"); |
||
3365 | NCH->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "ChannelLimit()"); |
||
3366 | (NCH->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "ChannelLimit()"); |
||
3367 | cleanOn->Connect("Clicked()", "TGAppMainFrame", this, "CleanPlotToggle()"); |
||
3368 | oscConnect->Connect("Clicked()", "TGAppMainFrame", this, "ConnectToScope()"); |
||
3369 | vOutSet->Connect("Clicked()", "TGAppMainFrame", this, "SetVoltOut()"); |
||
3370 | vOutGet->Connect("Clicked()", "TGAppMainFrame", this, "GetVoltOut()"); |
||
3371 | vOutReset->Connect("Clicked()", "TGAppMainFrame", this, "ResetVoltOut()"); |
||
3372 | positionSet->Connect("Clicked()", "TGAppMainFrame", this, "SetPosition()"); |
||
3373 | positionGet->Connect("Clicked()", "TGAppMainFrame", this, "GetPosition()"); |
||
3374 | positionHome->Connect("Clicked()", "TGAppMainFrame", this, "HomePosition()"); |
||
3375 | saveFile->Connect("Clicked()", "TGAppMainFrame", this, "SaveFile()"); |
||
3376 | measStart->Connect("Clicked()", "TGAppMainFrame", this, "StartAcq()"); |
||
3377 | selectDir->Connect("Clicked()", "TGAppMainFrame", this, "SelectDirectory()"); |
||
3378 | multiSelect->Connect("Clicked()", "TGAppMainFrame", this, "ListMultiSelect()"); |
||
3379 | multiSelectAll->Connect("Clicked()", "TGAppMainFrame", this, "ListSelectAll()"); |
||
3380 | prevFile->Connect("Clicked()", "TGAppMainFrame", this, "FileListNavigation(=-2)"); |
||
3381 | nextFile->Connect("Clicked()", "TGAppMainFrame", this, "FileListNavigation(=-3)"); |
||
3382 | fileList->Connect("DoubleClicked(Int_t)", "TGAppMainFrame", this, "FileListNavigation(Int_t)"); |
||
3383 | clearList->Connect("Clicked()", "TGListBox", fileList, "RemoveAll()"); |
||
3384 | |||
3385 | adcMinRange->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
3386 | (adcMinRange->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
3387 | adcMaxRange->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
3388 | (adcMaxRange->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
3389 | yMinRange->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
3390 | (yMinRange->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
3391 | yMaxRange->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
3392 | (yMaxRange->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
3393 | tdcMinwindow->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
3394 | (tdcMinwindow->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
3395 | tdcMaxwindow->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
3396 | (tdcMaxwindow->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
3397 | changeADC->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=0)"); |
||
3398 | changeTDC->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=1)"); |
||
3399 | changeADCTDC->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=2)"); |
||
3400 | change2Dsurf->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=3)"); |
||
3401 | selectCh->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "ChangeChannel()"); |
||
3402 | (selectCh->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "ChangeChannel()"); |
||
3403 | logscale->Connect("Clicked()", "TGAppMainFrame", this, "SetHistRange()"); |
||
3404 | exportHist->Connect("Clicked()", "TGAppMainFrame", this, "HistogramExport()"); |
||
3405 | |||
3406 | started = kFALSE; |
||
3407 | EnableVoltScan(); |
||
3408 | EnableSurfScan(); |
||
3409 | EnableZaxisScan(); |
||
3410 | } |
||
3411 | |||
3412 | //--------------------------------------------------------------- |
||
3413 | // Closing the main application window and checking the about information |
||
3414 | |||
3415 | void TGAppMainFrame::CloseWindow() |
||
3416 | { |
||
3417 | gApplication->Terminate(0); |
||
3418 | } |
||
3419 | |||
3420 | Bool_t TGAppMainFrame::About() |
||
3421 | { |
||
3422 | int ret = 0; |
||
3423 | |||
3424 | new TGMsgBox(gClient->GetRoot(), fMain, |
||
3425 | fMain->GetWindowName(), "This is an application.", |
||
3426 | kMBIconQuestion, kMBClose, &ret); |
||
3427 | |||
3428 | if(debug == 1) |
||
3429 | if(ret == kMBClose) |
||
3430 | printf("Closing the About window (%d).\n", ret); |
||
3431 | |||
3432 | return kFALSE; |
||
3433 | } |
||
3434 | |||
3435 | //--------------------------------------------------------------- |
||
3436 | // Subwindow constructor definition (& layout) and close subwindow action |
||
3437 | |||
3438 | TGMdiSubwindow::TGMdiSubwindow(TGMdiMainFrame *main, int w, int h) |
||
3439 | { |
||
3440 | // Create a new subwindow |
||
3441 | fMdiFrame = new TGMdiFrame(main, w, h); |
||
3442 | fMdiFrame->Connect("CloseWindow()", "TGMdiSubwindow", this, "CloseWindow()"); // setting here to =0 -> will always ask before closing window |
||
3443 | fMdiFrame->DontCallClose(); // only let this window close if Yes is pressed when closing window |
||
3444 | |||
3445 | } |
||
3446 | |||
3447 | Bool_t TGMdiSubwindow::CloseWindow() |
||
3448 | { |
||
3449 | int ret = 0; |
||
3450 | |||
3451 | // if(noq == 0) |
||
3452 | // { |
||
3453 | new TGMsgBox(gClient->GetRoot(), fMdiFrame, |
||
3454 | fMdiFrame->GetWindowName(), "Really want to close the window?", |
||
3455 | kMBIconExclamation, kMBYes | kMBNo, &ret); |
||
3456 | if (ret == kMBYes) return fMdiFrame->CloseWindow(); |
||
3457 | |||
3458 | return kFALSE; |
||
3459 | // } |
||
3460 | // else |
||
3461 | // return fMdiFrame->CloseWindow(); |
||
3462 | } |
||
3463 | |||
3464 | //--------------------------------------------------------------- |
||
3465 | // Main function |
||
3466 | |||
3467 | void windowed_test() |
||
3468 | { |
||
3469 | new TGAppMainFrame(gClient->GetRoot(), winWidth, winHeight); |
||
3470 | } |
||
3471 | |||
3472 | //#ifdef STANDALONE |
||
3473 | int main(int argc, char **argv) |
||
3474 | { |
||
3475 | TApplication theApp("MdiTest", &argc, argv); |
||
3476 | |||
3477 | windowed_test(); |
||
3478 | |||
3479 | theApp.Run(); |
||
3480 | |||
3481 | return 0; |
||
3482 | } |
||
3483 | //#endif |