Rev 127 | Details | Compare with Previous | 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 <unistd.h> |
||
9 | |||
10 | #include "daqscope.h" |
||
11 | |||
12 | //--------------------------------------------------------------- |
||
13 | // Subwindow layout class |
||
14 | |||
15 | class TGMdiSubwindow |
||
16 | { |
||
17 | RQ_OBJECT("TGMdiSubwindow") |
||
18 | |||
19 | protected: |
||
20 | TGMdiFrame *fMdiFrame; |
||
21 | |||
22 | public: |
||
23 | TGMdiSubwindow(TGMdiMainFrame *main, int w, int h); |
||
24 | |||
25 | TGMdiFrame *GetMdiFrame() const { return fMdiFrame; } |
||
26 | virtual Bool_t CloseWindow(); |
||
27 | }; |
||
28 | |||
29 | //--------------------------------------------------------------- |
||
30 | // Main window class |
||
31 | |||
32 | class TGAppMainFrame |
||
33 | { |
||
34 | RQ_OBJECT("TGAppMainFrame") |
||
35 | |||
36 | protected: |
||
37 | TGMainFrame *fMain; |
||
38 | TGMdiMainFrame *fMainFrame; |
||
39 | TGMdiMenuBar *fMenuBar; |
||
40 | TGLayoutHints *fMenuBarItemLayout; |
||
128 | f9daq | 41 | TGPopupMenu *fMenuFile, *fMenuAnalysis, *fMenuTools, *fMenuWindow, *fMenuHelp; |
117 | f9daq | 42 | TGPopupMenu *fMenuHisttype; |
43 | TGMdiSubwindow *settingsPane, *mainSubwindow, *histogramPane, *histogramPaneFile, *histogramPaneCtr; |
||
44 | |||
45 | void InitMenu(); |
||
46 | void MeasurementLayout(); |
||
128 | f9daq | 47 | void OpenWindow(int winid); |
117 | f9daq | 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(); |
||
127 | f9daq | 69 | |
70 | void InitializeScope(); |
||
71 | void StartScopeAcq(); |
||
72 | void CustomScopeCommand(); |
||
73 | void SelectedMeasType(int mtype); |
||
74 | |||
117 | f9daq | 75 | void SaveFile(); |
76 | void StartAcq(); |
||
77 | |||
78 | void SelectDirectory(); |
||
79 | void ListMultiSelect(); |
||
80 | void ListSelectAll(); |
||
81 | void FileListNavigation(int pn); |
||
82 | |||
83 | void DisplayHistogram(char *histfile, int histtype); |
||
84 | void SetHistRange(); |
||
85 | void ChangeHisttype(int type); |
||
86 | void ChangeChannel(); |
||
87 | void HistogramExport(); |
||
88 | void MakeSurfPlot(TList *files); |
||
89 | void MakeBreakdownPlot(int nrp, double *volt, double *volterr, double *psep1, double *pseperr1, double *psep2, double *pseperr2, double *psep3, double *pseperr3, char *plotfile); |
||
90 | |||
91 | void FitSpectrum(TList *files, int q); |
||
92 | void EdgeDetection(TGraph *pdf, TGraph *cdf, char *outname, TCanvas *g1dCanvas, double pdfmax, int direction); |
||
93 | void IntegSpectrum(TList *files, int direction); |
||
128 | f9daq | 94 | void PhotonMu(TList *files); |
117 | f9daq | 95 | |
128 | f9daq | 96 | void UpdateTempPlot(); |
97 | void TempEndToggle(); |
||
98 | void ExportTempPlot(); |
||
99 | void GetTempFile(int set); |
||
100 | |||
117 | f9daq | 101 | void RunMeas(void *ptr, int runCase, int zaxisscan); |
102 | }; |
||
103 | |||
104 | const char *histExt = ".root"; |
||
105 | const char *histExtAll = "*.root"; |
||
106 | daq *gDaq; |
||
107 | daqscope *gScopeDaq; |
||
128 | f9daq | 108 | //int debugSig = 0; |
117 | f9daq | 109 | int retTemp; |
110 | int gStop=0; |
||
111 | unsigned int gBuf[BSIZE]; |
||
112 | int logchange = 0; |
||
113 | double tdctimeconversion = 45.0909; |
||
114 | double lenconversion = 0.3595; |
||
115 | int oscOn; |
||
127 | f9daq | 116 | const char *allMeasNames[11] = {"Amplitude","Area","Delay","Fall","Frequency","Maximum","Mean","Minimum","Peak-to-peak","Peak width","Rise"}; |
117 | f9daq | 117 | |
118 | // ROOT file variable structure ----------- |
||
119 | struct EventHeader { |
||
120 | int nrch; |
||
121 | int timestamp; |
||
122 | double biasvolt; |
||
123 | int xpos; |
||
124 | int ypos; |
||
125 | int zpos; |
||
126 | double temperature; |
||
128 | f9daq | 127 | double angle; |
117 | f9daq | 128 | char laserinfo[256]; |
129 | } evtheader; |
||
130 | |||
131 | struct EventData { |
||
132 | int adcdata[8]; |
||
133 | int tdcdata[8]; |
||
134 | } evtdata; |
||
135 | |||
127 | f9daq | 136 | struct EventMeas { |
137 | double measdata; |
||
138 | } evtmeas; |
||
139 | |||
117 | f9daq | 140 | TFile *inroot; |
141 | TFile *outroot; |
||
142 | |||
127 | f9daq | 143 | // Test graphs for scope measurements |
144 | TCanvas *wCanvas; |
||
145 | TGraph *testgraph; |
||
146 | |||
117 | f9daq | 147 | //--------------------------------------------------------------- |
148 | // Global variables |
||
149 | |||
150 | TGCheckButton *voltscanOn; |
||
151 | TGCheckButton *surfscanOn; |
||
152 | TGCheckButton *zscanOn; |
||
153 | TGTextEntry *oscIP; |
||
154 | TGTextButton *oscConnect; |
||
155 | TGCheckButton *histogramOn; |
||
156 | TGNumberEntry *vHardlimit; |
||
157 | TGNumberEntry *NCH; |
||
158 | TGTextEntry *laserInfo; |
||
127 | f9daq | 159 | TGNumberEntry *chtemp; |
128 | f9daq | 160 | TGNumberEntry *incangle; |
117 | f9daq | 161 | TGCheckButton *cleanOn; |
162 | |||
163 | TGTab *setTab; |
||
164 | TGComboBox *vOutCh; |
||
165 | TGNumberEntry *vOut; |
||
166 | TGCheckButton *vOutOnOff; |
||
167 | TGTextButton *vOutSet; |
||
168 | TGTextButton *vOutGet; |
||
169 | TGTextButton *vOutReset; |
||
170 | TGNumberEntry *vOutStart; |
||
171 | TGNumberEntry *vOutStop; |
||
172 | TGNumberEntry *vOutStep; |
||
173 | TGNumberEntry *xPos; |
||
174 | TGNumberEntry *yPos; |
||
175 | TGNumberEntry *zPos; |
||
176 | TGTextButton *positionSet; |
||
177 | TGTextButton *positionGet; |
||
178 | TGTextButton *positionHome; |
||
179 | TGNumberEntry *xPosMin; |
||
180 | TGNumberEntry *xPosMax; |
||
181 | TGNumberEntry *xPosStep; |
||
182 | TGNumberEntry *yPosMin; |
||
183 | TGNumberEntry *yPosMax; |
||
184 | TGNumberEntry *yPosStep; |
||
185 | TGNumberEntry *zPosMin; |
||
186 | TGNumberEntry *zPosMax; |
||
187 | TGNumberEntry *zPosStep; |
||
188 | TGNumberEntry *evtNum; |
||
189 | TGTextEntry *timeStamp; |
||
190 | TGTextEntry *fileName; |
||
191 | TGTextButton *saveFile; |
||
192 | TGTextButton *measStart; |
||
193 | TGLabel *busyLabel; |
||
194 | TGHProgressBar *curProgress; |
||
195 | |||
196 | TRootEmbeddedCanvas *histCanvas; |
||
197 | |||
198 | TGTextButton *selectDir; |
||
199 | TGListBox *fileList; |
||
200 | TGCheckButton *multiSelect; |
||
201 | TGCheckButton *multiSelectAll; |
||
202 | TGTextButton *prevFile; |
||
203 | TGTextButton *nextFile; |
||
204 | |||
128 | f9daq | 205 | TGTextEntry *disptime; |
206 | TGNumberEntry *dispbias; |
||
207 | TGTextEntry *disppos; |
||
208 | TGNumberEntry *disptemp; |
||
209 | TGNumberEntry *dispangle; |
||
210 | TGTextEntry *displaser; |
||
211 | |||
117 | f9daq | 212 | TGNumberEntry *adcMinRange; |
213 | TGNumberEntry *adcMaxRange; |
||
214 | TGNumberEntry *tdcMinwindow; |
||
215 | TGNumberEntry *tdcMaxwindow; |
||
216 | TGNumberEntry *yMinRange; |
||
217 | TGNumberEntry *yMaxRange; |
||
218 | TGNumberEntry *selectCh; |
||
219 | TGTextButton *changeADC; |
||
220 | TGTextButton *changeTDC; |
||
221 | TGTextButton *changeADCTDC; |
||
222 | TGTextButton *change2Dsurf; |
||
223 | TGCheckButton *logscale; |
||
224 | TGTextButton *exportHist; |
||
225 | TGNumberEntry *fitSigma; |
||
226 | TGNumberEntry *fitTresh; |
||
227 | TGNumberEntry *fitInter; |
||
228 | TGNumberEntry *accError; |
||
229 | TGCheckButton *exfitplots; |
||
230 | |||
127 | f9daq | 231 | //TGButtonGroup *sChangroup; |
232 | TGCheckButton *sCH[8]; |
||
233 | TGComboBox *sMeasType; |
||
234 | TGCheckButton *sCamaclink; |
||
235 | TGTextEntry *scopeCommand; |
||
236 | TGTextEntry *scopeReturn; |
||
237 | TGTextButton *sendScopeCustom; |
||
238 | TGComboBox *sMeasgroup; |
||
239 | TGTextButton *scopeInit; |
||
240 | |||
128 | f9daq | 241 | TRootEmbeddedCanvas *displayCanvas; |
242 | TGComboBox *tempCh; |
||
243 | TGComboBox *tempDay[2]; |
||
244 | TGComboBox *tempMonth[2]; |
||
245 | TGComboBox *tempYear[2]; |
||
246 | TGComboBox *tempHour[2]; |
||
247 | TGComboBox *tempMinute[2]; |
||
248 | TGComboBox *tempSecond[2]; |
||
249 | TGTextButton *tempFile[2]; |
||
250 | TGCheckButton *tempEndOn; |
||
251 | TGTextButton *updateTemp; |
||
252 | TGTextButton *exportTemp; |
||
253 | //TGTextButton *closeTemp; |
||
254 | |||
117 | f9daq | 255 | Bool_t firstrun = kTRUE; |
256 | Bool_t started; |
||
257 | Bool_t cleanPlots = kTRUE; |
||
258 | |||
259 | // Layout hints definitions |
||
260 | TGLayoutHints *f0 = new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,2,2); |
||
261 | TGLayoutHints *f0centerx = new TGLayoutHints(kLHintsCenterX,2,2,2,2); |
||
262 | TGLayoutHints *f0centery = new TGLayoutHints(kLHintsLeft | kLHintsCenterY,2,2,2,2); |
||
263 | TGLayoutHints *f0center2d = new TGLayoutHints(kLHintsCenterX | kLHintsCenterY,2,2,2,2); |
||
264 | TGLayoutHints *f0right = new TGLayoutHints(kLHintsRight | kLHintsTop,2,2,2,2); |
||
265 | TGLayoutHints *f1 = new TGLayoutHints(kLHintsExpandX | kLHintsExpandY,2,2,2,2); |
||
266 | TGLayoutHints *f2 = new TGLayoutHints(kLHintsExpandX,2,2,2,2); |
||
267 | TGLayoutHints *f3 = new TGLayoutHints(kLHintsCenterY,2,2,20,2); |
||
268 | TGLayoutHints *f3notop = new TGLayoutHints(kLHintsCenterY,4,4,2,30); |
||
269 | |||
270 | // Separate functions ----------------------------------------- |
||
271 | void GetTime(int intime, char *outtime) |
||
272 | { |
||
273 | time_t rawtime; |
||
274 | struct tm * timeinfo; |
||
275 | if(intime < 0) |
||
276 | time(&rawtime); |
||
277 | else |
||
278 | rawtime = (time_t)intime; |
||
279 | timeinfo = localtime(&rawtime); |
||
280 | sprintf(outtime, "%s", asctime(timeinfo)); |
||
281 | int len = strlen(outtime); |
||
282 | if(len) outtime[len-1] = 0; |
||
283 | } |
||
284 | |||
285 | int MyTimer() |
||
286 | { |
||
287 | char cmd[100]; |
||
288 | GetTime(-1, cmd); |
||
289 | if (timeStamp) timeStamp->SetText(cmd); |
||
290 | return 0; |
||
291 | } |
||
292 | |||
293 | int GetChannel() |
||
294 | { |
||
295 | int selectedOutput; |
||
296 | if(vOutCh->GetSelected() < 8) selectedOutput = (vOutCh->GetSelected())+1; |
||
297 | else if( (vOutCh->GetSelected() >= 8) && (vOutCh->GetSelected() < 16) ) selectedOutput = (vOutCh->GetSelected())+93; |
||
298 | else selectedOutput = 1; |
||
299 | |||
300 | return selectedOutput; |
||
301 | } |
||
302 | |||
303 | void remove_ext(char *inname, char *outname) |
||
304 | { |
||
305 | char ctemp[256]; |
||
306 | for(int i = 0; i < (int)strlen(inname); i++) |
||
307 | { |
||
308 | if( (inname[i] == '.') && (i > (int)(strlen(inname)-6)) ) |
||
309 | { |
||
310 | ctemp[i] = '\0'; |
||
311 | sprintf(outname, "%s", ctemp); |
||
312 | break; |
||
313 | } |
||
314 | else |
||
315 | ctemp[i] = inname[i]; |
||
316 | } |
||
317 | |||
128 | f9daq | 318 | if(debug) |
117 | f9daq | 319 | printf("Outfile (remove_ext): %s\n", outname); |
320 | } |
||
321 | |||
322 | void remove_from_last(char *inname, char search, char *outname) |
||
323 | { |
||
324 | char ctemp[256]; |
||
325 | int searchpos = -1; |
||
326 | for(int i = (int)strlen(inname); i >= 0; i--) |
||
327 | { |
||
328 | if(inname[i] == search) |
||
329 | { |
||
330 | searchpos = i; |
||
331 | break; |
||
332 | } |
||
333 | } |
||
334 | |||
335 | for(int i = 0; i < searchpos; i++) |
||
336 | ctemp[i] = inname[i]; |
||
337 | |||
338 | ctemp[searchpos] = '\0'; |
||
339 | sprintf(outname, "%s", ctemp); |
||
340 | |||
128 | f9daq | 341 | if(debug) |
117 | f9daq | 342 | printf("Outfile (remove_from_last): %s\n", outname); |
343 | } |
||
344 | |||
127 | f9daq | 345 | void SeqNumber(int innum, int maxnum, char *outstr) |
346 | { |
||
347 | int zeronum = 5; |
||
348 | |||
349 | // Check how many zeroes we need to add to get sequential numbers |
||
350 | if( (maxnum > 0) && (maxnum < 1000) ) |
||
351 | zeronum = 2; |
||
352 | else if( (maxnum >= 1000) && (maxnum < 10000) ) |
||
353 | zeronum = 3; |
||
354 | else if( (maxnum >= 10000) && (maxnum < 100000) ) |
||
355 | zeronum = 4; |
||
356 | else if( (maxnum >= 100000) && (maxnum < 1000000) ) |
||
357 | zeronum = 5; |
||
358 | |||
359 | // Make the sequence number depending on the number of zeroes |
||
360 | if(zeronum == 2) |
||
361 | { |
||
362 | if(innum < 10) |
||
363 | sprintf(outstr, "00%d", innum); |
||
364 | else if( (innum >= 10) && (innum < 100) ) |
||
365 | sprintf(outstr, "0%d", innum); |
||
366 | else if( (innum >= 100) && (innum < 1000) ) |
||
367 | sprintf(outstr, "%d", innum); |
||
368 | } |
||
369 | else if(zeronum == 3) |
||
370 | { |
||
371 | if(innum < 10) |
||
372 | sprintf(outstr, "000%d", innum); |
||
373 | else if( (innum >= 10) && (innum < 100) ) |
||
374 | sprintf(outstr, "00%d", innum); |
||
375 | else if( (innum >= 100) && (innum < 1000) ) |
||
376 | sprintf(outstr, "0%d", innum); |
||
377 | else if( (innum >= 1000) && (innum < 10000) ) |
||
378 | sprintf(outstr, "%d", innum); |
||
379 | } |
||
380 | else if(zeronum == 4) |
||
381 | { |
||
382 | if(innum < 10) |
||
383 | sprintf(outstr, "0000%d", innum); |
||
384 | else if( (innum >= 10) && (innum < 100) ) |
||
385 | sprintf(outstr, "000%d", innum); |
||
386 | else if( (innum >= 100) && (innum < 1000) ) |
||
387 | sprintf(outstr, "00%d", innum); |
||
388 | else if( (innum >= 1000) && (innum < 10000) ) |
||
389 | sprintf(outstr, "0%d", innum); |
||
390 | else if( (innum >= 10000) && (innum < 100000) ) |
||
391 | sprintf(outstr, "%d", innum); |
||
392 | } |
||
393 | else if(zeronum == 5) |
||
394 | { |
||
395 | if(innum < 10) |
||
396 | sprintf(outstr, "00000%d", innum); |
||
397 | else if( (innum >= 10) && (innum < 100) ) |
||
398 | sprintf(outstr, "0000%d", innum); |
||
399 | else if( (innum >= 100) && (innum < 1000) ) |
||
400 | sprintf(outstr, "000%d", innum); |
||
401 | else if( (innum >= 1000) && (innum < 10000) ) |
||
402 | sprintf(outstr, "00%d", innum); |
||
403 | else if( (innum >= 10000) && (innum < 100000) ) |
||
404 | sprintf(outstr, "0%d", innum); |
||
405 | else if( (innum >= 100000) && (innum < 1000000) ) |
||
406 | sprintf(outstr, "%d", innum); |
||
407 | } |
||
408 | } |
||
409 | |||
117 | f9daq | 410 | // Peak detection function |
411 | int npeaks; |
||
412 | double FindPeaks(double *x, double *par) |
||
413 | { |
||
414 | double result = 0; |
||
415 | for(int i = 0; i < npeaks; i++) |
||
416 | { |
||
417 | double norm = par[3*i]; |
||
418 | double mean = par[3*i+1]; |
||
419 | double sigma = par[3*i+2]; |
||
420 | result += norm*TMath::Gaus(x[0], mean, sigma); |
||
421 | } |
||
422 | return result; |
||
423 | } |
||
424 | |||
128 | f9daq | 425 | // Temperature sensor functions ----------------------------- |
426 | const char* dbname = "mysql://f9lab08.ijs.si/f9phdet"; |
||
427 | const char* tblname = "fprtd122"; |
||
428 | const char* username = "f9daq"; |
||
429 | const char* userpass = "f9lab"; |
||
430 | |||
431 | // Get the temperature from MYSQL database |
||
432 | double GetTemperature(int ch, const char *s) |
||
433 | { |
||
434 | int bin=5+7*4-ch*4; |
||
435 | char hex[16]; |
||
436 | strncpy(hex, (const char *) &s[bin], 4); |
||
437 | hex[4]=0; |
||
438 | int ix; |
||
439 | sscanf (hex,"%x",&ix); |
||
440 | //printf("0x%s\t",hex); |
||
441 | return (ix/65535.)*1050.-200.; |
||
442 | } |
||
443 | |||
444 | // Transform local time to timestamp |
||
445 | int GetTimeStamp(int *intime) |
||
446 | { |
||
447 | time_t rawtime; |
||
448 | struct tm * timeinfo; |
||
449 | time(&rawtime); |
||
450 | timeinfo = localtime(&rawtime); |
||
451 | |||
452 | printf("%d.%d.%d, %d:%d:%d\n", intime[0], intime[1], intime[2], intime[3], intime[4], intime[5]); |
||
453 | |||
454 | timeinfo->tm_mday = intime[0]; |
||
455 | timeinfo->tm_mon = intime[1] - 1; |
||
456 | timeinfo->tm_year = intime[2] - 1900; |
||
457 | timeinfo->tm_hour = intime[3]; |
||
458 | timeinfo->tm_min = intime[4]; |
||
459 | timeinfo->tm_sec = intime[5]; |
||
460 | |||
461 | return (int)mktime(timeinfo); |
||
462 | } |
||
463 | |||
464 | // Get data from MYSQL database |
||
465 | void fieldpoint(int *timerange, int selch) |
||
466 | { |
||
467 | char humantime[256]; |
||
468 | |||
469 | // Display selected timestamps |
||
470 | GetTime(timerange[0], humantime); |
||
471 | printf("Minimum time set to: %s (%d)\n", humantime, timerange[0]); |
||
472 | if(timerange[1] != -1) |
||
473 | { |
||
474 | GetTime(timerange[1], humantime); |
||
475 | printf("Maximum time set to: %s (%d)\n", humantime, timerange[1]); |
||
476 | } |
||
477 | printf("Selected fieldpoint channel: %d\n", selch); |
||
478 | printf("\n"); |
||
479 | |||
480 | // Database settings |
||
481 | TSQLServer *db = TSQLServer::Connect(dbname, username, userpass); |
||
482 | printf("Server info: %s\n", db->ServerInfo()); |
||
483 | TSQLRow *row; |
||
484 | TSQLResult *res; |
||
485 | |||
486 | // list databases available on server |
||
487 | printf("\nList all databases on server %s\n", db->GetHost()); |
||
488 | res = db->GetDataBases(); |
||
489 | while ((row = res->Next())) { |
||
490 | printf("%s\n", row->GetField(0)); |
||
491 | delete row; |
||
492 | } |
||
493 | delete res; |
||
494 | |||
495 | // list tables in database "test" (the permission tables) |
||
496 | printf("\nList all tables in database \"f9phdet\" on server %s\n", db->GetHost()); |
||
497 | res = db->GetTables("f9phdet"); |
||
498 | while ((row = res->Next())) { |
||
499 | printf("%s\n", row->GetField(0)); |
||
500 | delete row; |
||
501 | } |
||
502 | delete res; |
||
503 | |||
504 | // list columns in table "runcatalog" in database "mysql" |
||
505 | printf("\nList all columns in table \"f9phdet\" in database \"f9rtd122\" on server %s\n", db->GetHost()); |
||
506 | res = db->GetColumns("f9phdet", "fprtd122"); |
||
507 | while ((row = res->Next())) { |
||
508 | printf("%s\n", row->GetField(0)); |
||
509 | delete row; |
||
510 | } |
||
511 | delete res; |
||
512 | |||
513 | // query database and print results |
||
514 | char sql[1000] = "SELECT status,data,timestamp FROM fprtd122 WHERE status='A272727272727272748' AND substring(data,1,4)='A00C' "; |
||
515 | if(timerange[1] == -1) |
||
516 | sprintf(sql,"%s AND timestamp>='%d'", sql, timerange[0]); |
||
517 | else |
||
518 | sprintf(sql,"%s AND timestamp>='%d' AND timestamp<='%d'", sql, timerange[0], timerange[1]); |
||
519 | printf("%s\n",sql); |
||
520 | |||
521 | res = db->Query(sql); |
||
522 | |||
523 | int nrows = res->GetRowCount(); |
||
524 | printf("\nGot %d rows in result\n", nrows); |
||
525 | |||
526 | // Printing and plotting |
||
527 | char timeval[256]; |
||
528 | TGraph *gr; |
||
529 | gr = new TGraph(nrows); |
||
530 | gr->SetLineColor(kRed); |
||
531 | gr->SetLineWidth(1); |
||
532 | gr->SetMarkerColor(kRed); |
||
533 | gr->SetMarkerStyle(20); |
||
534 | gr->SetTitle("Temperature sensor;Time;Temperature (deg.)"); |
||
535 | |||
536 | FILE *fp; |
||
537 | fp = fopen("./fieldpoint/dataout_fieldpoint.txt", "w"); |
||
538 | |||
539 | if(debug) |
||
540 | printf("Time\tTemperature\n"); |
||
541 | for (int i = 0; i < nrows; i++) { |
||
542 | row = res->Next(); |
||
543 | |||
544 | GetTime((int)atof(row->GetField(2)), timeval); |
||
545 | double x = atof(row->GetField(2)); |
||
546 | double y = GetTemperature(selch,row->GetField(1)); |
||
547 | gr->SetPoint(i,x,y); |
||
548 | |||
549 | fprintf(fp, "%s\t%f\n",timeval,y); |
||
550 | |||
551 | if(debug) |
||
552 | printf("%s\t%f\n",timeval,y); |
||
553 | |||
554 | delete row; |
||
555 | } |
||
556 | |||
557 | fclose(fp); |
||
558 | |||
559 | delete res; |
||
560 | delete db; |
||
561 | |||
562 | TCanvas *gCanvas = displayCanvas->GetCanvas(); |
||
563 | gCanvas->SetGrid(); |
||
564 | gr->GetXaxis()->SetTimeDisplay(1); |
||
565 | gr->GetXaxis()->SetTimeFormat("%d.%m.%H:%M"); |
||
566 | gr->GetXaxis()->SetLabelSize(0.027); |
||
567 | gr->GetXaxis()->SetTitleSize(0.038); |
||
568 | gr->GetYaxis()->SetLabelSize(0.027); |
||
569 | gr->GetYaxis()->SetTitleSize(0.038); |
||
570 | gr->GetXaxis()->SetNdivisions(515,kTRUE); |
||
571 | gr->Draw("AL"); |
||
572 | |||
573 | gCanvas->Modified(); |
||
574 | gCanvas->Update(); |
||
575 | } |
||
576 | |||
577 | // Update the temperature plot |
||
578 | void TGAppMainFrame::UpdateTempPlot() |
||
579 | { |
||
580 | int stime[6]; |
||
581 | int etime[6]; |
||
582 | |||
583 | int timestamp[2]; |
||
584 | |||
585 | time_t rtime; |
||
586 | int curyear; |
||
587 | time(&rtime); |
||
588 | curyear = (int)(localtime(&rtime))->tm_year+1900; |
||
589 | |||
590 | int leapy = 0; |
||
591 | |||
592 | // Getting the start time |
||
593 | stime[0] = (int)(tempDay[0]->GetSelected())+1; |
||
594 | stime[2] = curyear - (int)(tempYear[0]->GetSelected()); |
||
595 | printf("%d, %d, %d\n", stime[2], curyear, (int)(tempYear[0]->GetSelected())); |
||
596 | stime[3] = (int)(tempHour[0]->GetSelected()); |
||
597 | stime[4] = (int)(tempMinute[0]->GetSelected()); |
||
598 | stime[5] = (int)(tempSecond[0]->GetSelected()); |
||
599 | |||
600 | switch( tempMonth[0]->GetSelected() ) |
||
601 | { |
||
602 | case 0: |
||
603 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
604 | break; |
||
605 | case 1: |
||
606 | if( stime[2]%4 == 0) |
||
607 | leapy = 1; |
||
608 | |||
609 | if( (leapy == 1) && (stime[0] > 29) ) |
||
610 | { |
||
611 | stime[0] = 29; |
||
612 | tempDay[0]->Select(28); |
||
613 | } |
||
614 | else if( (leapy == 0) && (stime[0] > 28) ) |
||
615 | { |
||
616 | stime[0] = 28; |
||
617 | tempDay[0]->Select(27); |
||
618 | } |
||
619 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
620 | break; |
||
621 | case 2: |
||
622 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
623 | break; |
||
624 | case 3: |
||
625 | if(stime[0] > 30) |
||
626 | { |
||
627 | stime[0] = 30; |
||
628 | tempDay[0]->Select(29); |
||
629 | } |
||
630 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
631 | break; |
||
632 | case 4: |
||
633 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
634 | break; |
||
635 | case 5: |
||
636 | if(stime[0] > 30) |
||
637 | { |
||
638 | stime[0] = 30; |
||
639 | tempDay[0]->Select(29); |
||
640 | } |
||
641 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
642 | break; |
||
643 | case 6: |
||
644 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
645 | break; |
||
646 | case 7: |
||
647 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
648 | break; |
||
649 | case 8: |
||
650 | if(stime[0] > 30) |
||
651 | { |
||
652 | stime[0] = 30; |
||
653 | tempDay[0]->Select(29); |
||
654 | } |
||
655 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
656 | break; |
||
657 | case 9: |
||
658 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
659 | break; |
||
660 | case 10: |
||
661 | if(stime[0] > 30) |
||
662 | { |
||
663 | stime[0] = 30; |
||
664 | tempDay[0]->Select(29); |
||
665 | } |
||
666 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
667 | break; |
||
668 | case 11: |
||
669 | stime[1] = (int)(tempMonth[0]->GetSelected())+1; |
||
670 | break; |
||
671 | default: |
||
672 | break; |
||
673 | } |
||
674 | |||
675 | timestamp[0] = GetTimeStamp(stime); |
||
676 | printf("Start time: %d\n", timestamp[0]); |
||
677 | |||
678 | // Getting the end time |
||
679 | etime[0] = (int)(tempDay[1]->GetSelected())+1; |
||
680 | etime[2] = curyear - (int)(tempYear[1]->GetSelected()); |
||
681 | etime[3] = (int)(tempHour[1]->GetSelected()); |
||
682 | etime[4] = (int)(tempMinute[1]->GetSelected()); |
||
683 | etime[5] = (int)(tempSecond[1]->GetSelected()); |
||
684 | |||
685 | switch( tempMonth[1]->GetSelected() ) |
||
686 | { |
||
687 | case 0: |
||
688 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
689 | break; |
||
690 | case 1: |
||
691 | if( etime[2]%4 == 0) |
||
692 | leapy = 1; |
||
693 | |||
694 | if( (leapy == 1) && (etime[0] > 29) ) |
||
695 | { |
||
696 | etime[0] = 29; |
||
697 | tempDay[1]->Select(28); |
||
698 | } |
||
699 | else if( (leapy == 0) && (etime[0] > 28) ) |
||
700 | { |
||
701 | etime[0] = 28; |
||
702 | tempDay[1]->Select(27); |
||
703 | } |
||
704 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
705 | break; |
||
706 | case 2: |
||
707 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
708 | break; |
||
709 | case 3: |
||
710 | if(etime[0] > 30) |
||
711 | { |
||
712 | etime[0] = 30; |
||
713 | tempDay[1]->Select(29); |
||
714 | } |
||
715 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
716 | break; |
||
717 | case 4: |
||
718 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
719 | break; |
||
720 | case 5: |
||
721 | if(etime[0] > 30) |
||
722 | { |
||
723 | etime[0] = 30; |
||
724 | tempDay[1]->Select(29); |
||
725 | } |
||
726 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
727 | break; |
||
728 | case 6: |
||
729 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
730 | break; |
||
731 | case 7: |
||
732 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
733 | break; |
||
734 | case 8: |
||
735 | if(etime[0] > 30) |
||
736 | { |
||
737 | etime[0] = 30; |
||
738 | tempDay[1]->Select(29); |
||
739 | } |
||
740 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
741 | break; |
||
742 | case 9: |
||
743 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
744 | break; |
||
745 | case 10: |
||
746 | if(etime[0] > 30) |
||
747 | { |
||
748 | etime[0] = 30; |
||
749 | tempDay[1]->Select(29); |
||
750 | } |
||
751 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
752 | break; |
||
753 | case 11: |
||
754 | etime[1] = (int)(tempMonth[1]->GetSelected())+1; |
||
755 | break; |
||
756 | default: |
||
757 | break; |
||
758 | } |
||
759 | |||
760 | if( tempEndOn->IsDown() ) |
||
761 | timestamp[1] = -1; |
||
762 | else |
||
763 | timestamp[1] = GetTimeStamp(etime); |
||
764 | printf("End time: %d\n", timestamp[1]); |
||
765 | |||
766 | fieldpoint(timestamp, tempCh->GetSelected()); |
||
767 | } |
||
768 | |||
769 | // Export the temperature plot to pdf |
||
770 | void TGAppMainFrame::ExportTempPlot() |
||
771 | { |
||
772 | TCanvas *gCanvas = displayCanvas->GetCanvas(); |
||
773 | gCanvas->Modified(); |
||
774 | gCanvas->Update(); |
||
775 | gCanvas->SaveAs("./fieldpoint/plotout_fieldpoint.pdf"); |
||
776 | } |
||
777 | |||
778 | // Get time information from a saved file |
||
779 | void TGAppMainFrame::GetTempFile(int set) |
||
780 | { |
||
781 | TGFileInfo file_info; |
||
782 | const char *filetypes[] = {"Histograms",histExtAll,0,0}; |
||
783 | file_info.fFileTypes = filetypes; |
||
784 | file_info.fIniDir = StrDup("./results"); |
||
785 | file_info.fMultipleSelection = kFALSE; |
||
786 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info); |
||
787 | int i = 0; |
||
788 | |||
789 | TTree *header_data; |
||
790 | time_t rtime, ctime; |
||
791 | struct tm * timeinfo; |
||
792 | |||
793 | int curyear; |
||
794 | time(&ctime); |
||
795 | curyear = (int)(localtime(&ctime))->tm_year+1900; |
||
796 | |||
797 | TList *files = file_info.fFileNamesList; |
||
798 | TString fname; |
||
799 | // If multiple files were selected, only use the first one |
||
800 | if(files) |
||
801 | { |
||
802 | printf("Using only the first selected file.\n"); |
||
803 | |||
804 | TSystemFile *file; |
||
805 | TIter next(files); |
||
806 | while(i == 0) |
||
807 | { |
||
808 | file=(TSystemFile*)next(); |
||
809 | fname = file->GetName(); |
||
810 | i++; |
||
811 | } |
||
812 | } |
||
813 | // If only one file was selected, use it |
||
814 | else |
||
815 | fname = file_info.fFilename; |
||
816 | |||
817 | if((int)fname.Length() > 0) |
||
818 | { |
||
819 | inroot = new TFile(fname, "READ"); |
||
820 | |||
821 | inroot->GetObject("header_data", header_data); |
||
822 | |||
823 | // Reading the timestamp information |
||
824 | header_data->SetBranchAddress("timestamp", &evtheader.timestamp); |
||
825 | header_data->GetEntry(0); |
||
826 | |||
827 | rtime = (time_t)evtheader.timestamp; |
||
828 | timeinfo = localtime(&rtime); |
||
829 | // printf("Time: %d.%d.%d, %d:%d:%d\n", timeinfo->tm_mday, timeinfo->tm_mon+1, timeinfo->tm_year+1900, timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); |
||
830 | |||
831 | tempDay[set]->Select(timeinfo->tm_mday - 1); |
||
832 | tempMonth[set]->Select(timeinfo->tm_mon); |
||
833 | tempYear[set]->Select(curyear - (timeinfo->tm_year+1900)); |
||
834 | tempHour[set]->Select(timeinfo->tm_hour); |
||
835 | tempMinute[set]->Select(timeinfo->tm_min); |
||
836 | tempSecond[set]->Select(timeinfo->tm_sec); |
||
837 | } |
||
838 | else |
||
839 | printf("No file selected.\n"); |
||
840 | |||
841 | delete inroot; |
||
842 | } |
||
843 | |||
844 | // Toggle the endtime settings for temperature sensor |
||
845 | void TGAppMainFrame::TempEndToggle() |
||
846 | { |
||
847 | if( tempEndOn->IsDown() ) |
||
848 | { |
||
849 | tempDay[1]->SetEnabled(kFALSE); |
||
850 | tempMonth[1]->SetEnabled(kFALSE); |
||
851 | tempYear[1]->SetEnabled(kFALSE); |
||
852 | tempHour[1]->SetEnabled(kFALSE); |
||
853 | tempMinute[1]->SetEnabled(kFALSE); |
||
854 | tempSecond[1]->SetEnabled(kFALSE); |
||
855 | tempFile[1]->SetEnabled(kFALSE); |
||
856 | } |
||
857 | else |
||
858 | { |
||
859 | tempDay[1]->SetEnabled(kTRUE); |
||
860 | tempMonth[1]->SetEnabled(kTRUE); |
||
861 | tempYear[1]->SetEnabled(kTRUE); |
||
862 | tempHour[1]->SetEnabled(kTRUE); |
||
863 | tempMinute[1]->SetEnabled(kTRUE); |
||
864 | tempSecond[1]->SetEnabled(kTRUE); |
||
865 | tempFile[1]->SetEnabled(kTRUE); |
||
866 | } |
||
867 | } |
||
868 | |||
869 | // -------------------------------------------------------------- |
||
870 | |||
117 | f9daq | 871 | // Class related functions -------------------------------------- |
872 | |||
873 | // Apply the upper voltage limit from settings pane to main window |
||
874 | void TGAppMainFrame::VoltageLimit() |
||
875 | { |
||
876 | vOut->SetLimitValues(0, vHardlimit->GetNumber() ); |
||
877 | } |
||
878 | |||
879 | // Apply the upper channel limit from settings pane to histogram settings |
||
880 | void TGAppMainFrame::ChannelLimit() |
||
881 | { |
||
882 | selectCh->SetLimitValues(0, (NCH->GetNumber()-1) ); |
||
883 | } |
||
884 | |||
885 | // Enable or disable voltage scan controls |
||
886 | void TGAppMainFrame::EnableVoltScan() |
||
887 | { |
||
888 | if(voltscanOn->IsOn()) |
||
889 | { |
||
890 | vOutStart->SetState(kTRUE); |
||
891 | vOutStop->SetState(kTRUE); |
||
892 | vOutStep->SetState(kTRUE); |
||
893 | } |
||
894 | else |
||
895 | { |
||
896 | vOutStart->SetState(kFALSE); |
||
897 | vOutStop->SetState(kFALSE); |
||
898 | vOutStep->SetState(kFALSE); |
||
899 | } |
||
900 | } |
||
901 | |||
902 | // Enable or disable surface scan controls |
||
903 | void TGAppMainFrame::EnableSurfScan() |
||
904 | { |
||
905 | if(surfscanOn->IsOn()) |
||
906 | { |
||
907 | xPosMin->SetState(kTRUE); |
||
908 | xPosMax->SetState(kTRUE); |
||
909 | xPosStep->SetState(kTRUE); |
||
910 | yPosMin->SetState(kTRUE); |
||
911 | yPosMax->SetState(kTRUE); |
||
912 | yPosStep->SetState(kTRUE); |
||
913 | } |
||
914 | else |
||
915 | { |
||
916 | xPosMin->SetState(kFALSE); |
||
917 | xPosMax->SetState(kFALSE); |
||
918 | xPosStep->SetState(kFALSE); |
||
919 | yPosMin->SetState(kFALSE); |
||
920 | yPosMax->SetState(kFALSE); |
||
921 | yPosStep->SetState(kFALSE); |
||
922 | } |
||
923 | } |
||
924 | |||
925 | // Enable or disable Z axis scan controls |
||
926 | void TGAppMainFrame::EnableZaxisScan() |
||
927 | { |
||
928 | if(zscanOn->IsOn()) |
||
929 | { |
||
930 | zPosMin->SetState(kTRUE); |
||
931 | zPosMax->SetState(kTRUE); |
||
932 | zPosStep->SetState(kTRUE); |
||
933 | } |
||
934 | else |
||
935 | { |
||
936 | zPosMin->SetState(kFALSE); |
||
937 | zPosMax->SetState(kFALSE); |
||
938 | zPosStep->SetState(kFALSE); |
||
939 | } |
||
940 | } |
||
941 | |||
942 | // Toggle clean plots on/off |
||
943 | void TGAppMainFrame::CleanPlotToggle() |
||
944 | { |
||
945 | cleanPlots = cleanOn->IsDown(); |
||
946 | } |
||
947 | |||
948 | // Connect to oscilloscope |
||
949 | void TGAppMainFrame::ConnectToScope() |
||
950 | { |
||
951 | int scopeState = -1; |
||
952 | char *IPaddr = (char*)oscIP->GetText(); |
||
953 | int IPcorr = 0; |
||
954 | |||
955 | if(oscOn == 0) |
||
956 | { |
||
957 | // Check if the IP address has the required three . |
||
958 | for(int i = 0; i < (int)strlen(IPaddr); i++) |
||
959 | if(IPaddr[i] == '.') |
||
960 | IPcorr++; |
||
961 | |||
962 | if( (IPaddr != NULL) && (IPcorr == 3) ) |
||
963 | { |
||
127 | f9daq | 964 | #if WORKSTAT == 'I' || WORKSTAT == 'S' |
117 | f9daq | 965 | printf("Connecting to oscilloscope.\n"); |
966 | retTemp = gScopeDaq->connect(IPaddr); |
||
967 | scopeState = 1; // For testing instead of making a real connection |
||
968 | #else |
||
969 | scopeState = 1; |
||
127 | f9daq | 970 | retTemp = 0; |
117 | f9daq | 971 | #endif |
972 | } |
||
973 | else |
||
974 | { |
||
975 | scopeState = -1; |
||
976 | printf("Please enter a valid scope IP address.\n"); |
||
977 | } |
||
978 | } |
||
127 | f9daq | 979 | else if(oscOn > 0) |
117 | f9daq | 980 | { |
127 | f9daq | 981 | #if WORKSTAT == 'I' || WORKSTAT == 'S' |
117 | f9daq | 982 | printf("Disconnecting from oscilloscope.\n"); |
983 | retTemp = gScopeDaq->disconnect(IPaddr); |
||
984 | scopeState = -1; // For testing instead of making a real disconnection |
||
985 | #else |
||
986 | scopeState = -1; |
||
127 | f9daq | 987 | retTemp = 0; |
117 | f9daq | 988 | #endif |
989 | } |
||
990 | |||
127 | f9daq | 991 | if(retTemp == 0) |
117 | f9daq | 992 | { |
127 | f9daq | 993 | if(scopeState >= 0) |
994 | { |
||
995 | oscIP->SetEnabled(kFALSE); |
||
996 | oscConnect->SetText("Disconnect"); |
||
997 | oscConnect->SetTextJustify(36); |
||
998 | oscConnect->SetWrapLength(-1); |
||
999 | oscConnect->Resize(60,22); |
||
1000 | |||
1001 | for(int i = 0; i < 8; i++) |
||
1002 | { |
||
1003 | sCH[i]->SetState(kButtonUp); |
||
1004 | sCH[i]->SetEnabled(kFALSE); |
||
1005 | } |
||
1006 | sMeasType->SetEnabled(kTRUE); |
||
1007 | sCamaclink->SetState(kButtonUp); |
||
1008 | sCamaclink->SetEnabled(kFALSE); |
||
1009 | scopeCommand->SetEnabled(kTRUE); |
||
1010 | sendScopeCustom->SetEnabled(kTRUE); |
||
1011 | sMeasgroup->SetEnabled(kFALSE); |
||
1012 | scopeInit->SetEnabled(kFALSE); |
||
1013 | |||
1014 | oscOn = 1; |
||
1015 | } |
||
1016 | else |
||
1017 | { |
||
1018 | oscIP->SetEnabled(kTRUE); |
||
1019 | oscConnect->SetText("Connect"); |
||
1020 | oscConnect->SetTextJustify(36); |
||
1021 | oscConnect->SetWrapLength(-1); |
||
1022 | oscConnect->Resize(60,22); |
||
1023 | |||
1024 | for(int i = 0; i < 8; i++) |
||
1025 | { |
||
1026 | sCH[i]->SetState(kButtonUp); |
||
1027 | sCH[i]->SetEnabled(kFALSE); |
||
1028 | } |
||
1029 | sMeasType->Select(0); |
||
1030 | sMeasType->SetEnabled(kFALSE); |
||
1031 | sCamaclink->SetState(kButtonUp); |
||
1032 | sCamaclink->SetEnabled(kFALSE); |
||
1033 | scopeCommand->SetEnabled(kFALSE); |
||
1034 | sendScopeCustom->SetEnabled(kFALSE); |
||
1035 | sMeasgroup->SetEnabled(kFALSE); |
||
1036 | scopeInit->SetEnabled(kFALSE); |
||
1037 | |||
1038 | oscOn = 0; |
||
1039 | } |
||
117 | f9daq | 1040 | } |
1041 | else |
||
127 | f9daq | 1042 | printf("Error! Connecting/disconnecting failed.\n"); |
117 | f9daq | 1043 | } |
1044 | |||
1045 | // Set the output voltage |
||
1046 | void TGAppMainFrame::SetVoltOut() |
||
1047 | { |
||
1048 | char cmd[256]; |
||
1049 | int outOn; |
||
1050 | float outputVoltage; |
||
1051 | |||
1052 | outputVoltage = vOut->GetNumber(); |
||
1053 | |||
1054 | if(vOutOnOff->IsOn()) outOn = 1; |
||
1055 | else outOn = 0; |
||
1056 | |||
1057 | fflush(stdout); |
||
1058 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -o %d -v %f -s %d", rootdir, GetChannel(), outputVoltage, outOn); |
||
1059 | #if WORKSTAT == 'I' |
||
1060 | retTemp = system(cmd); |
||
1061 | #else |
||
1062 | printf("Cmd: %s\n",cmd); |
||
1063 | #endif |
||
1064 | fflush(stdout); |
||
1065 | } |
||
1066 | |||
1067 | // Get the output voltage |
||
1068 | void TGAppMainFrame::GetVoltOut() |
||
1069 | { |
||
1070 | char cmd[256]; |
||
1071 | |||
1072 | fflush(stdout); |
||
1073 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -o %d -g > %s/curvolt.txt", rootdir, GetChannel(), rootdir); |
||
1074 | #if WORKSTAT == 'I' |
||
1075 | retTemp = system(cmd); |
||
1076 | #else |
||
1077 | printf("Cmd: %s\n",cmd); |
||
1078 | #endif |
||
1079 | fflush(stdout); |
||
1080 | |||
1081 | #if WORKSTAT == 'I' |
||
1082 | FILE* fvolt; |
||
1083 | double dtemp; |
||
1084 | char ctemp[24]; |
||
1085 | sprintf(cmd, "%s/curvolt.txt", rootdir); |
||
1086 | fvolt = fopen(cmd, "r"); |
||
1087 | |||
1088 | if(fvolt != NULL) |
||
1089 | { |
||
1090 | sprintf(cmd, "WIENER-CRATE-MIB::outputVoltage.u%d = Opaque: Float: %s V\n", GetChannel()-1, "%lf" ); |
||
1091 | retTemp = fscanf(fvolt, cmd, &dtemp); |
||
1092 | vOut->SetNumber(dtemp); |
||
1093 | sprintf(cmd, "WIENER-CRATE-MIB::outputSwitch.u%d = INTEGER: %s\n", GetChannel()-1, "%s" ); |
||
1094 | retTemp = fscanf(fvolt, cmd, ctemp); |
||
1095 | if( strcmp(ctemp, "On(1)") == 0 ) |
||
1096 | vOutOnOff->SetState(kButtonDown); |
||
1097 | else if( strcmp(ctemp, "Off(0)") == 0 ) |
||
1098 | vOutOnOff->SetState(kButtonUp); |
||
1099 | } |
||
1100 | |||
1101 | fclose(fvolt); |
||
1102 | #endif |
||
1103 | } |
||
1104 | |||
1105 | // Reset the output voltage |
||
1106 | void TGAppMainFrame::ResetVoltOut() |
||
1107 | { |
||
1108 | char cmd[256]; |
||
1109 | |||
1110 | vOut->SetNumber(0.000); |
||
1111 | vOutOnOff->SetState(kButtonUp); |
||
1112 | |||
1113 | fflush(stdout); |
||
1114 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -r %d", rootdir, GetChannel()); |
||
1115 | #if WORKSTAT == 'I' |
||
1116 | retTemp = system(cmd); |
||
1117 | #else |
||
1118 | printf("Cmd: %s\n",cmd); |
||
1119 | #endif |
||
1120 | fflush(stdout); |
||
1121 | } |
||
1122 | |||
1123 | // Get the current table position |
||
1124 | void TGAppMainFrame::GetPosition() |
||
1125 | { |
||
1126 | char cmd[256]; |
||
1127 | |||
1128 | fflush(stdout); |
||
1129 | |||
1130 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -p > %s/curpos.txt", rootdir, rootdir); // X-axis |
||
1131 | fflush(stdout); |
||
1132 | #if WORKSTAT == 'I' |
||
1133 | retTemp = system(cmd); |
||
1134 | #else |
||
1135 | printf("Cmd: %s\n",cmd); |
||
1136 | #endif |
||
1137 | |||
1138 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -p >> %s/curpos.txt", rootdir, rootdir); // Y-axis |
||
1139 | fflush(stdout); |
||
1140 | #if WORKSTAT == 'I' |
||
1141 | retTemp = system(cmd); |
||
1142 | #else |
||
1143 | printf("Cmd: %s\n",cmd); |
||
1144 | #endif |
||
1145 | |||
1146 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -p >> %s/curpos.txt", rootdir, rootdir); // Z-axis |
||
1147 | fflush(stdout); |
||
1148 | #if WORKSTAT == 'I' |
||
1149 | retTemp = system(cmd); |
||
1150 | #else |
||
1151 | printf("Cmd: %s\n",cmd); |
||
1152 | #endif |
||
1153 | |||
1154 | #if WORKSTAT == 'I' |
||
1155 | FILE* fpos; |
||
1156 | int itemp; |
||
1157 | sprintf(cmd, "%s/curpos.txt", rootdir); |
||
1158 | fpos = fopen(cmd, "r"); |
||
1159 | |||
1160 | if(fpos != NULL) |
||
1161 | { |
||
1162 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1163 | xPos->SetNumber(itemp); |
||
1164 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1165 | yPos->SetNumber(itemp); |
||
1166 | retTemp = fscanf(fpos, "%d\n", &itemp); |
||
1167 | zPos->SetNumber(itemp); |
||
1168 | } |
||
1169 | |||
1170 | fclose(fpos); |
||
1171 | #endif |
||
1172 | } |
||
1173 | |||
1174 | // Set the current table position |
||
1175 | void TGAppMainFrame::SetPosition() |
||
1176 | { |
||
1177 | char cmd[256]; |
||
1178 | int positX, positY, positZ; |
||
1179 | |||
1180 | positX = xPos->GetNumber(); |
||
1181 | positY = yPos->GetNumber(); |
||
1182 | positZ = zPos->GetNumber(); |
||
1183 | |||
1184 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/MIKRO/mikro_ctrl -n 1 -c m", rootdir, positX, rootdir); |
||
1185 | #if WORKSTAT == 'I' |
||
1186 | retTemp = system(cmd); |
||
1187 | #else |
||
1188 | printf("Cmd: %s\n",cmd); |
||
1189 | #endif |
||
1190 | |||
1191 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/MIKRO/mikro_ctrl -n 2 -c m", rootdir, positY, rootdir); |
||
1192 | #if WORKSTAT == 'I' |
||
1193 | retTemp = system(cmd); |
||
1194 | #else |
||
1195 | printf("Cmd: %s\n",cmd); |
||
1196 | #endif |
||
1197 | |||
1198 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/MIKRO/mikro_ctrl -n 3 -c m", rootdir, positZ, rootdir); |
||
1199 | #if WORKSTAT == 'I' |
||
1200 | retTemp = system(cmd); |
||
1201 | #else |
||
1202 | printf("Cmd: %s\n",cmd); |
||
1203 | #endif |
||
1204 | } |
||
1205 | |||
1206 | // Set the current table position to a predetermined HOME position |
||
1207 | void TGAppMainFrame::HomePosition() |
||
1208 | { |
||
1209 | char cmd[256]; |
||
1210 | |||
1211 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -h", rootdir); // X-axis |
||
1212 | #if WORKSTAT == 'I' |
||
1213 | retTemp = system(cmd); |
||
1214 | #else |
||
1215 | printf("Cmd: %s\n",cmd); |
||
1216 | #endif |
||
1217 | |||
1218 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -h", rootdir); // Y-axis |
||
1219 | #if WORKSTAT == 'I' |
||
1220 | retTemp = system(cmd); |
||
1221 | #else |
||
1222 | printf("Cmd: %s\n",cmd); |
||
1223 | #endif |
||
1224 | |||
1225 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -h", rootdir); // Z-axis |
||
1226 | #if WORKSTAT == 'I' |
||
1227 | retTemp = system(cmd); |
||
1228 | #else |
||
1229 | printf("Cmd: %s\n",cmd); |
||
1230 | #endif |
||
1231 | } |
||
1232 | |||
127 | f9daq | 1233 | // Initialize the currently connected scope for measurements |
1234 | void TGAppMainFrame::InitializeScope() |
||
1235 | { |
||
1236 | int iTemp; |
||
1237 | int chTemp[8]; |
||
1238 | for(int i = 0; i < 8; i++) chTemp[i] = -1; |
||
1239 | gScopeDaq->scopeUseType = sMeasType->GetSelected(); |
||
1240 | |||
1241 | // Check what channels are selected |
||
1242 | iTemp = 0; |
||
1243 | for(int i = 0; i < 8; i++) |
||
1244 | { |
||
1245 | if(sCH[i]->IsDown()) |
||
1246 | { |
||
1247 | chTemp[iTemp] = i; |
||
1248 | iTemp++; |
||
1249 | } |
||
1250 | } |
||
1251 | if(iTemp == 0) |
||
1252 | { |
||
1253 | // If no channel is selected, we select the first one |
||
1254 | chTemp[0] = 0; |
||
1255 | iTemp++; |
||
1256 | sCH[0]->SetState(kButtonDown); |
||
1257 | } |
||
1258 | // If measurement is used, only use the first selected channel |
||
1259 | if(gScopeDaq->scopeUseType == 2) |
||
1260 | { |
||
1261 | for(int i = 1; i < iTemp; i++) |
||
1262 | sCH[chTemp[i]]->SetState(kButtonUp); |
||
1263 | iTemp = 1; |
||
1264 | } |
||
1265 | |||
1266 | gScopeDaq->scopeChanNr = iTemp; |
||
1267 | for(int i = 0; i < 8; i++) gScopeDaq->scopeChans[i] = chTemp[i]; |
||
1268 | |||
1269 | // Check which measurement is selected |
||
1270 | gScopeDaq->scopeMeasSel = sMeasgroup->GetSelected(); |
||
1271 | |||
1272 | gScopeDaq->init(); |
||
1273 | } |
||
1274 | |||
1275 | // Run a scope measurement |
||
1276 | void TGAppMainFrame::StartScopeAcq() |
||
1277 | { |
||
1278 | // Lock the scope front panel |
||
1279 | gScopeDaq->lockunlock(true); |
||
1280 | |||
1281 | retTemp = gScopeDaq->event(); |
||
1282 | |||
1283 | if(gScopeDaq->scopeUseType == 1) |
||
1284 | { |
||
1285 | char len[16]; |
||
1286 | int sval; |
||
1287 | short *spoints; |
||
1288 | |||
1289 | if(retTemp == 0) |
||
1290 | { |
||
1291 | // Read the number of y bytes at beginning of CURVE binary data |
||
1292 | memcpy(len, &gScopeDaq->eventbuf[1],1); |
||
1293 | len[1] = 0; |
||
1294 | sval = atoi(len); |
||
1295 | // printf("Number of y bytes = %d\n", sval); |
||
1296 | |||
1297 | // Read the data |
||
1298 | spoints = (short *)(&gScopeDaq->eventbuf[2+sval]); |
||
1299 | |||
1300 | // Read the number of data points |
||
1301 | memcpy(len, &gScopeDaq->eventbuf[2],sval); |
||
1302 | len[sval] = 0; |
||
1303 | sval = atoi(len); |
||
1304 | // printf("Number of data points = %d\n", sval/2); |
||
1305 | |||
1306 | double *grafx, *grafy; |
||
1307 | grafx = new double[sval/2]; |
||
1308 | grafy = new double[sval/2]; |
||
1309 | // Parse data and graph it |
||
1310 | for(int i = 0; i < sval/2; i++) |
||
1311 | { |
||
1312 | grafx[i] = i*gScopeDaq->tektime*10./(sval/2.); |
||
1313 | grafy[i] = ((double)spoints[i]*5.*gScopeDaq->tekvolt/32767.) - (gScopeDaq->choffset*gScopeDaq->tekvolt); |
||
1314 | } |
||
1315 | |||
1316 | wCanvas->cd(); |
||
1317 | testgraph = new TGraph(sval/2, grafx, grafy); |
||
1318 | testgraph->GetXaxis()->SetTitle("Time [s]"); |
||
1319 | testgraph->GetXaxis()->SetRangeUser(grafx[0], grafx[(sval/2)-1]); |
||
1320 | testgraph->GetYaxis()->SetTitle("Voltage [V]"); |
||
1321 | testgraph->Draw("AL"); |
||
1322 | wCanvas->Modified(); |
||
1323 | wCanvas->Update(); |
||
1324 | |||
1325 | delete[] grafx; |
||
1326 | delete[] grafy; |
||
1327 | } |
||
1328 | } |
||
1329 | else if(gScopeDaq->scopeUseType == 2) |
||
1330 | { |
||
1331 | if(retTemp == 0) |
||
1332 | { |
||
1333 | if(gScopeDaq->measubuf < 1.e-4) |
||
1334 | printf("Measurement: %le\n", gScopeDaq->measubuf); |
||
1335 | else |
||
1336 | printf("Measurement: %lf\n", gScopeDaq->measubuf); |
||
1337 | } |
||
1338 | } |
||
1339 | |||
1340 | // Unlock the scope front panel |
||
1341 | gScopeDaq->lockunlock(false); |
||
1342 | } |
||
1343 | |||
1344 | // Send a custom command to the scope |
||
1345 | void TGAppMainFrame::CustomScopeCommand() |
||
1346 | { |
||
1347 | char *cmd = (char*)scopeCommand->GetText(); |
||
1348 | char ret[100000]; |
||
1349 | if( strchr(cmd, '?') == NULL) |
||
1350 | { |
||
1351 | printf("Sending command: %s\n", cmd); |
||
1352 | #if WORKSTAT == 'I' || WORKSTAT == 'S' |
||
1353 | gScopeDaq->customCommand(cmd, false, ret); |
||
1354 | #endif |
||
1355 | } |
||
1356 | else |
||
1357 | { |
||
1358 | printf("Sending query: %s\n", cmd); |
||
1359 | #if WORKSTAT == 'I' || WORKSTAT == 'S' |
||
1360 | gScopeDaq->customCommand(cmd, true, ret); |
||
1361 | #endif |
||
1362 | } |
||
1363 | |||
1364 | #if WORKSTAT == 'I' || WORKSTAT == 'S' |
||
1365 | scopeReturn->SetText(ret); |
||
1366 | #endif |
||
128 | f9daq | 1367 | |
1368 | #if WORKSTAT == 'O' |
||
1369 | sprintf(ret, "Program running in offline mode. Use I or S when configuring..."); |
||
1370 | scopeReturn->SetText(ret); |
||
1371 | #endif |
||
127 | f9daq | 1372 | } |
1373 | |||
1374 | // When we select the measurement type, change other scope settings accordingly |
||
1375 | void TGAppMainFrame::SelectedMeasType(int mtype) |
||
1376 | { |
||
1377 | // No waveform analysis |
||
1378 | if(mtype == 0) |
||
1379 | { |
||
1380 | for(int i = 0; i < 8; i++) |
||
1381 | { |
||
1382 | sCH[i]->SetState(kButtonUp); |
||
1383 | sCH[i]->SetEnabled(kFALSE); |
||
1384 | } |
||
1385 | sMeasType->SetEnabled(kTRUE); |
||
1386 | sCamaclink->SetState(kButtonUp); |
||
1387 | sCamaclink->SetEnabled(kFALSE); |
||
1388 | scopeCommand->SetEnabled(kTRUE); |
||
1389 | sendScopeCustom->SetEnabled(kTRUE); |
||
1390 | sMeasgroup->SetEnabled(kFALSE); |
||
1391 | scopeInit->SetEnabled(kFALSE); |
||
1392 | |||
1393 | oscOn = 1; |
||
1394 | } |
||
1395 | // Complete waveform acquisition |
||
1396 | else if(mtype == 1) |
||
1397 | { |
||
1398 | for(int i = 0; i < 8; i++) |
||
1399 | sCH[i]->SetEnabled(kTRUE); |
||
1400 | sMeasType->SetEnabled(kTRUE); |
||
1401 | sCamaclink->SetState(kButtonDown); |
||
1402 | sCamaclink->SetEnabled(kTRUE); |
||
1403 | scopeCommand->SetEnabled(kTRUE); |
||
1404 | sendScopeCustom->SetEnabled(kTRUE); |
||
1405 | sMeasgroup->SetEnabled(kFALSE); |
||
1406 | scopeInit->SetEnabled(kTRUE); |
||
1407 | |||
1408 | oscOn = 2; |
||
1409 | } |
||
1410 | // Waveform measurements |
||
1411 | else if(mtype == 2) |
||
1412 | { |
||
1413 | for(int i = 0; i < 8; i++) |
||
1414 | sCH[i]->SetEnabled(kTRUE); |
||
1415 | sMeasType->SetEnabled(kTRUE); |
||
1416 | sCamaclink->SetState(kButtonUp); |
||
1417 | sCamaclink->SetEnabled(kTRUE); |
||
1418 | scopeCommand->SetEnabled(kTRUE); |
||
1419 | sendScopeCustom->SetEnabled(kTRUE); |
||
1420 | sMeasgroup->SetEnabled(kTRUE); |
||
1421 | scopeInit->SetEnabled(kTRUE); |
||
1422 | |||
1423 | oscOn = 3; |
||
1424 | } |
||
1425 | } |
||
1426 | |||
117 | f9daq | 1427 | // Make breakdown voltage plot |
1428 | void TGAppMainFrame::MakeBreakdownPlot(int nrp, double *volt, double *volterr, double *psep1, double *pseperr1, double *psep2, double *pseperr2, double *psep3, double *pseperr3, char *plotfile) |
||
1429 | { |
||
1430 | double fparam[2], fparamerr[2], meanval; |
||
1431 | TLatex *latex; |
||
1432 | char ctemp[256]; |
||
1433 | int sortindex[nrp]; |
||
1434 | |||
1435 | TCanvas *canvas = new TCanvas("canv","canv",900,1200); |
||
1436 | canvas->Divide(1,3); |
||
1437 | |||
1438 | TGraphErrors *gr1 = new TGraphErrors(nrp, volt, psep1, volterr, pseperr1); |
||
1439 | TGraphErrors *gr2 = new TGraphErrors(nrp, volt, psep2, volterr, pseperr2); |
||
1440 | TGraphErrors *gr3 = new TGraphErrors(nrp, volt, psep3, volterr, pseperr3); |
||
1441 | |||
1442 | if(!cleanPlots) |
||
1443 | gr1->SetTitle("1st - 2nd peak separation"); |
||
1444 | else |
||
1445 | gr1->SetTitle(); |
||
1446 | gr1->SetLineColor(kBlue); |
||
1447 | gr1->SetMarkerColor(kBlue); |
||
1448 | gr1->SetMarkerStyle(20); |
||
1449 | gr1->SetMarkerSize(0.6); |
||
1450 | |||
1451 | |||
1452 | if(!cleanPlots) |
||
1453 | gr2->SetTitle("2nd - 3rd peak separation"); |
||
1454 | else |
||
1455 | gr2->SetTitle(); |
||
1456 | gr2->SetLineColor(kMagenta); |
||
1457 | gr2->SetMarkerColor(kMagenta); |
||
1458 | gr2->SetMarkerStyle(21); |
||
1459 | gr2->SetMarkerSize(0.4); |
||
1460 | |||
1461 | if(!cleanPlots) |
||
1462 | gr3->SetTitle("3rd - 4th peak separation"); |
||
1463 | else |
||
1464 | gr3->SetTitle(); |
||
1465 | gr3->SetLineColor(kGreen); |
||
1466 | gr3->SetMarkerColor(kGreen); |
||
1467 | gr3->SetMarkerStyle(22); |
||
1468 | gr3->SetMarkerSize(0.6); |
||
1469 | |||
1470 | // Plotting the first breakdown voltage plot |
||
1471 | canvas->cd(1); |
||
1472 | gPad->SetGridx(1); |
||
1473 | gPad->SetGridy(1); |
||
1474 | |||
1475 | gr1->Draw("AP"); |
||
1476 | gr1->GetXaxis()->SetTitle("Bias voltage (V)"); |
||
1477 | gr1->GetYaxis()->SetTitle("Peak separation"); |
||
1478 | gr1->GetYaxis()->CenterTitle(); |
||
1479 | gr1->Fit("pol1","Q"); |
||
1480 | |||
1481 | TF1 *fit1 = gr1->GetFunction("pol1"); |
||
1482 | fparam[0] = fit1->GetParameter(0); |
||
1483 | fparamerr[0] = fit1->GetParError(0); |
||
1484 | fparam[1] = fit1->GetParameter(1); |
||
1485 | fparamerr[1] = fit1->GetParError(1); |
||
1486 | |||
1487 | TMath::Sort(nrp, psep1, sortindex, kFALSE); |
||
1488 | |||
1489 | meanval = -fparam[0]/fparam[1]; |
||
1490 | if(!cleanPlots) |
||
1491 | { |
||
1492 | 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])) ); |
||
1493 | latex = new TLatex(); |
||
1494 | latex->SetTextSize(0.039); |
||
1495 | latex->DrawLatex(volt[0]-(volt[1]-volt[0]), 0.97*psep1[sortindex[nrp-1]], ctemp); |
||
1496 | } |
||
1497 | else |
||
1498 | 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])) ); |
||
1499 | |||
1500 | // Plotting the second breakdown voltage plot |
||
1501 | canvas->cd(2); |
||
1502 | gPad->SetGridx(1); |
||
1503 | gPad->SetGridy(1); |
||
1504 | |||
1505 | gr2->Draw("AP"); |
||
1506 | gr2->GetXaxis()->SetTitle("Bias voltage (V)"); |
||
1507 | gr2->GetYaxis()->SetTitle("Peak separation"); |
||
1508 | gr2->GetYaxis()->CenterTitle(); |
||
1509 | gr2->Fit("pol1","Q"); |
||
1510 | |||
1511 | TF1 *fit2 = gr2->GetFunction("pol1"); |
||
1512 | fparam[0] = fit2->GetParameter(0); |
||
1513 | fparamerr[0] = fit2->GetParError(0); |
||
1514 | fparam[1] = fit2->GetParameter(1); |
||
1515 | fparamerr[1] = fit2->GetParError(1); |
||
1516 | |||
1517 | meanval = -fparam[0]/fparam[1]; |
||
1518 | if(!cleanPlots) |
||
1519 | { |
||
1520 | 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])) ); |
||
1521 | latex = new TLatex(); |
||
1522 | latex->SetTextSize(0.039); |
||
1523 | latex->DrawLatex(volt[0]-(volt[1]-volt[0]), 0.97*psep2[sortindex[nrp-1]], ctemp); |
||
1524 | } |
||
1525 | else |
||
1526 | 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])) ); |
||
1527 | |||
1528 | // Plotting the third breakdown voltage plot |
||
1529 | canvas->cd(3); |
||
1530 | gPad->SetGridx(1); |
||
1531 | gPad->SetGridy(1); |
||
1532 | |||
1533 | gr3->Draw("AP"); |
||
1534 | gr3->GetXaxis()->SetTitle("Bias voltage (V)"); |
||
1535 | gr3->GetYaxis()->SetTitle("Peak separation"); |
||
1536 | gr3->GetYaxis()->CenterTitle(); |
||
1537 | gr3->Fit("pol1","Q"); |
||
1538 | |||
1539 | TF1 *fit3 = gr3->GetFunction("pol1"); |
||
1540 | fparam[0] = fit3->GetParameter(0); |
||
1541 | fparamerr[0] = fit3->GetParError(0); |
||
1542 | fparam[1] = fit3->GetParameter(1); |
||
1543 | fparamerr[1] = fit3->GetParError(1); |
||
1544 | |||
1545 | meanval = -fparam[0]/fparam[1]; |
||
1546 | if(!cleanPlots) |
||
1547 | { |
||
1548 | 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])) ); |
||
1549 | latex = new TLatex(); |
||
1550 | latex->SetTextSize(0.039); |
||
1551 | latex->DrawLatex(volt[0]-(volt[1]-volt[0]), 0.97*psep3[sortindex[nrp-1]], ctemp); |
||
1552 | } |
||
1553 | else |
||
1554 | 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])) ); |
||
1555 | |||
1556 | canvas->SaveAs(plotfile); |
||
1557 | } |
||
1558 | |||
1559 | // Fit the ADC spectrum peaks and make a breakdown voltage plot |
||
1560 | void TGAppMainFrame::FitSpectrum(TList *files, int q) |
||
1561 | { |
||
1562 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
1563 | gCanvas->cd(); |
||
1564 | TH1F *histtemp; |
||
1565 | TSpectrum *spec; |
||
1566 | TH1 *histback; |
||
1567 | TH1F *h2; |
||
1568 | float *xpeaks; |
||
1569 | TF1 *fit; |
||
1570 | TF1 *fittingfunc; |
||
1571 | double *fparam; |
||
1572 | double *fparamerr; |
||
1573 | double meanparam[20], meanparamerr[20]; |
||
1574 | int sortindex[20]; |
||
1575 | char exportname[256]; |
||
1576 | char paramname[256]; |
||
1577 | char ctemp[256]; |
||
1578 | |||
1579 | FILE *fp; |
||
1580 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
1581 | sprintf(paramname, "%s_fitresult.txt", ctemp); |
||
1582 | fp = fopen(paramname, "w"); |
||
1583 | fclose(fp); |
||
1584 | |||
1585 | int peaklimit = 5; |
||
1586 | int p = 0; |
||
1587 | double dtemp; |
||
1588 | double volt[files->GetSize()], volterr[files->GetSize()], sep[3][files->GetSize()], seperr[3][files->GetSize()]; |
||
1589 | for(int m = 0; m < files->GetSize(); m++) |
||
1590 | { |
||
1591 | volt[m] = 0; volterr[m] = 0; |
||
1592 | for(int i = 0; i < 3; i++) |
||
1593 | { sep[i][m] = 0; seperr[i][m] = 0; } |
||
1594 | } |
||
1595 | |||
1596 | for(int m = 0; m < files->GetSize(); m++) |
||
1597 | { |
||
1598 | for(int i = 0; i < 20; i++) { meanparam[20] = 0; meanparamerr[20] = 0; } |
||
1599 | |||
1600 | DisplayHistogram( (char*)(files->At(m)->GetTitle()), 0); |
||
1601 | dtemp = evtheader.biasvolt; |
||
1602 | gCanvas->Modified(); |
||
1603 | gCanvas->Update(); |
||
1604 | |||
1605 | histtemp = (TH1F*)gCanvas->GetPrimitive(histname); |
||
1606 | npeaks = 20; |
||
1607 | double par[3000]; |
||
1608 | spec = new TSpectrum(npeaks); |
||
1609 | // Find spectrum background |
||
1610 | histback = spec->Background(histtemp, (int)fitInter->GetNumber(), "same"); |
||
1611 | // Clone histogram and subtract background from it |
||
1612 | h2 = (TH1F*)histtemp->Clone("h2"); |
||
1613 | h2->Add(histback, -1); |
||
1614 | // Search for the peaks |
||
1615 | int found = spec->Search(h2, fitSigma->GetNumber(), "goff", fitTresh->GetNumber() ); |
||
1616 | printf("Found %d candidates to fit.\n",found); |
||
1617 | npeaks = found; |
||
1618 | |||
1619 | xpeaks = spec->GetPositionX(); |
||
1620 | for(int i = 0; i < found; i++) |
||
1621 | { |
||
1622 | float xp = xpeaks[i]; |
||
1623 | int bin = h2->GetXaxis()->FindBin(xp); |
||
1624 | float yp = h2->GetBinContent(bin); |
||
1625 | par[3*i] = yp; |
||
1626 | par[3*i+1] = xp; |
||
1627 | // par[3*i+2] = 3; |
||
1628 | par[3*i+2] = (double)fitSigma->GetNumber(); |
||
1629 | // printf("Peak %d: %f\n", i+1, xp); |
||
1630 | } |
||
1631 | |||
1632 | // Fit the histogram |
||
1633 | fit = new TF1("fit", FindPeaks, 0, 400, 3*npeaks); |
||
1634 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
||
1635 | fit->SetParameters(par); |
||
1636 | fit->SetNpx(300); |
||
1637 | h2->Fit("fit","Q"); // for quiet mode, add Q |
||
1638 | fittingfunc = h2->GetFunction("fit"); |
||
1639 | fparam = fittingfunc->GetParameters(); |
||
1640 | fparamerr = fittingfunc->GetParErrors(); |
||
1641 | |||
1642 | // Gather the parameters (mean peak value for now) |
||
1643 | int j = 1; |
||
1644 | int nrfit = 0; |
||
1645 | while(1) |
||
1646 | { |
||
1647 | if( (fparam[j] < 1.E-30) || (fparamerr[j] < 1.E-10) ) |
||
1648 | break; |
||
1649 | else |
||
1650 | { |
||
1651 | if(fparam[j] > 0) |
||
1652 | { |
||
1653 | meanparam[nrfit] = fparam[j]; |
||
1654 | meanparamerr[nrfit] = fparamerr[j]; |
||
1655 | nrfit++; |
||
1656 | } |
||
1657 | } |
||
1658 | |||
1659 | j+=3; |
||
1660 | } |
||
1661 | |||
1662 | // Write out parameters to a file |
||
1663 | fp = fopen(paramname, "a"); |
||
1664 | |||
1665 | TMath::Sort(nrfit, meanparam, sortindex, kFALSE); |
||
128 | f9daq | 1666 | |
1667 | // Only save the ones that do not have a too large error on peak separation for the first three peaks |
||
1668 | if( ((TMath::Abs(meanparamerr[sortindex[2]]) + TMath::Abs(meanparamerr[sortindex[1]]))/(meanparam[sortindex[2]] - meanparam[sortindex[1]]) < accError->GetNumber()) && ((TMath::Abs(meanparamerr[sortindex[3]]) + TMath::Abs(meanparamerr[sortindex[2]]))/(meanparam[sortindex[3]] - meanparam[sortindex[2]]) < accError->GetNumber()) && ((TMath::Abs(meanparamerr[sortindex[4]]) + TMath::Abs(meanparamerr[sortindex[3]]))/(meanparam[sortindex[4]] - meanparam[sortindex[3]]) < accError->GetNumber()) ) |
||
1669 | // if( (seperr[0][0]/sep[0][0] < accError->GetNumber()) && (seperr[1][0]/sep[1][0] < accError->GetNumber()) && (seperr[2][0]/sep[2][0] < accError->GetNumber()) ) |
||
117 | f9daq | 1670 | { |
128 | f9daq | 1671 | fprintf(fp, "%le\t%d\t", dtemp, nrfit); |
1672 | |||
1673 | for(int i = 0; i < nrfit; i++) |
||
1674 | { |
||
1675 | if(debug) |
||
1676 | printf("Peak %d (%lfV): %lf\t%lf\n", i+1, dtemp, meanparam[sortindex[i]], meanparamerr[sortindex[i]]); |
||
1677 | fprintf(fp, "%le\t%le\t", meanparam[sortindex[i]], meanparamerr[sortindex[i]]); |
||
1678 | } |
||
1679 | printf("\n"); |
||
1680 | fprintf(fp, "\n"); |
||
117 | f9daq | 1681 | } |
1682 | |||
1683 | fclose(fp); |
||
1684 | |||
1685 | h2->SetStats(0); |
||
1686 | |||
1687 | gCanvas->Modified(); |
||
1688 | gCanvas->Update(); |
||
1689 | |||
1690 | // Save each fitting plot |
||
1691 | if(exfitplots->IsDown()) |
||
1692 | { |
||
1693 | remove_ext((char*)files->At(m)->GetTitle(), ctemp); |
||
1694 | sprintf(exportname, "%s_fit.pdf", ctemp); |
||
1695 | gCanvas->SaveAs(exportname); |
||
1696 | } |
||
1697 | |||
1698 | // Get points for mean peak values and create a breakdown voltage plot |
||
1699 | if(nrfit >= peaklimit) |
||
1700 | { |
||
1701 | sep[0][p] = meanparam[sortindex[2]] - meanparam[sortindex[1]]; |
||
1702 | sep[1][p] = meanparam[sortindex[3]] - meanparam[sortindex[2]]; |
||
1703 | sep[2][p] = meanparam[sortindex[4]] - meanparam[sortindex[3]]; |
||
1704 | |||
1705 | seperr[0][p] = TMath::Abs(meanparamerr[sortindex[2]]) + TMath::Abs(meanparamerr[sortindex[1]]); |
||
1706 | seperr[1][p] = TMath::Abs(meanparamerr[sortindex[3]]) + TMath::Abs(meanparamerr[sortindex[2]]); |
||
1707 | seperr[2][p] = TMath::Abs(meanparamerr[sortindex[4]]) + TMath::Abs(meanparamerr[sortindex[3]]); |
||
1708 | |||
1709 | volt[p] = dtemp; |
||
1710 | volterr[p] = 1.e-4; |
||
1711 | |||
128 | f9daq | 1712 | if(debug) |
117 | f9daq | 1713 | 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]); |
1714 | |||
1715 | // Accept only the points with a small enough error |
||
1716 | 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()) ) |
||
1717 | p++; |
||
1718 | else |
||
1719 | 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]); |
||
1720 | } |
||
1721 | |||
1722 | if(q == 1) break; |
||
1723 | } |
||
1724 | |||
1725 | // Plot & fit breakdown voltage plots |
||
1726 | if(q > 1) |
||
1727 | { |
||
1728 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
1729 | sprintf(paramname, "%s_breakdown.pdf", ctemp); |
||
1730 | MakeBreakdownPlot(p, volt, volterr, sep[0], seperr[0], sep[1], seperr[1], sep[2], seperr[2], paramname); |
||
1731 | } |
||
1732 | } |
||
1733 | |||
1734 | // Plotting of PDF and CDF functions for the edge (with the added fit) |
||
1735 | void TGAppMainFrame::EdgeDetection(TGraph *pdf, TGraph *cdf, char *outname, TCanvas *g1dCanvas, double pdfmax, int direction) |
||
1736 | { |
||
1737 | // double x, y; |
||
1738 | |||
1739 | pdf->Fit("gaus","Q"); |
||
1740 | pdf->GetFunction("gaus")->SetNpx(400); |
||
1741 | /* |
||
1742 | for(int i = 0; i < nrpoints; i++) |
||
1743 | { |
||
1744 | pdf->GetPoint(i, x, y); |
||
1745 | pdf->SetPoint(i, x, (y/pdfmax) ); |
||
1746 | } |
||
1747 | */ |
||
1748 | gStyle->SetOptFit(1); |
||
1749 | |||
1750 | cdf->Draw("AL"); |
||
1751 | gPad->Update(); |
||
1752 | pdf->Draw("LP"); |
||
1753 | |||
1754 | g1dCanvas->Modified(); |
||
1755 | g1dCanvas->Update(); |
||
1756 | |||
1757 | TPaveStats *stats = (TPaveStats*)pdf->FindObject("stats"); |
||
1758 | if(!cleanPlots) |
||
1759 | { |
||
1760 | // stats->SetX1NDC(0.14); stats->SetX2NDC(0.28); |
||
1761 | // stats->SetY1NDC(0.83); stats->SetY2NDC(0.96); |
||
1762 | stats->SetX1NDC(0.86); stats->SetX2NDC(1.0); |
||
1763 | stats->SetY1NDC(0.87); stats->SetY2NDC(1.0); |
||
1764 | } |
||
1765 | else |
||
1766 | { |
||
1767 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
1768 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
1769 | } |
||
1770 | |||
1771 | g1dCanvas->SetGridx(1); |
||
1772 | g1dCanvas->SetGridy(1); |
||
1773 | if(direction == 1) |
||
1774 | cdf->GetXaxis()->SetTitle("X [#mum]"); |
||
1775 | else if(direction == 2) |
||
1776 | cdf->GetXaxis()->SetTitle("Y [#mum]"); |
||
1777 | cdf->GetXaxis()->CenterTitle(kTRUE); |
||
1778 | cdf->GetXaxis()->SetLabelSize(0.022); |
||
1779 | cdf->GetYaxis()->SetTitle("Normalized ADC integral"); |
||
1780 | // cdf->GetYaxis()->SetTitle("Normalized ADC integral (CDF)"); |
||
1781 | // cdf->GetYaxis()->SetTitleColor(kBlue); |
||
1782 | cdf->GetYaxis()->CenterTitle(kTRUE); |
||
1783 | cdf->GetYaxis()->SetLabelSize(0.022); |
||
1784 | cdf->GetYaxis()->SetRangeUser(0,1); |
||
1785 | cdf->GetYaxis()->SetTitleSize(0.030); |
||
1786 | // cdf->GetYaxis()->SetLabelColor(kBlue); |
||
1787 | if(!cleanPlots) |
||
1788 | cdf->SetTitle("SiPM edge detection"); |
||
1789 | else |
||
1790 | cdf->SetTitle(); |
||
1791 | cdf->SetLineColor(kBlue); |
||
1792 | pdf->SetLineWidth(2); |
||
1793 | cdf->SetLineWidth(2); |
||
1794 | |||
1795 | /* TGaxis *axis = new TGaxis(gPad->GetUxmax(), 0, gPad->GetUxmax(), 1, 0, pdfmax, 510, "+L"); |
||
1796 | axis->Draw(); |
||
1797 | axis->SetTitle("Normalized ADC integral (PDF)"); |
||
1798 | axis->SetTitleSize(0.035); |
||
1799 | axis->CenterTitle(); |
||
1800 | axis->SetTitleColor(kBlack); |
||
1801 | axis->SetTitleFont(42); |
||
1802 | axis->SetLabelSize(0.022); |
||
1803 | axis->SetLabelColor(kBlack);*/ |
||
1804 | |||
1805 | g1dCanvas->Modified(); |
||
1806 | g1dCanvas->Update(); |
||
1807 | |||
1808 | g1dCanvas->SaveAs(outname); |
||
1809 | } |
||
1810 | |||
1811 | // Integrate the spectrum |
||
1812 | void TGAppMainFrame::IntegSpectrum(TList *files, int direction) |
||
1813 | { |
||
1814 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
1815 | char ctemp[256]; |
||
1816 | int j, k = 0, m = 0, n = 0; |
||
1817 | |||
1818 | TCanvas *gCanvas = new TCanvas("canv","canv",900,900); |
||
1819 | TCanvas *g1dCanvas = new TCanvas("canv1d","canv1d",1200,900); |
||
1820 | TTree *header_data, *meas_data; |
||
1821 | double *integralCount, *integralAcc; |
||
1822 | integralCount = new double[nrfiles]; |
||
1823 | integralAcc = new double[nrfiles]; |
||
1824 | // double xsurfmin, ysurfmin, zsurfmin; |
||
1825 | double *surfx, *surfy, *surfz; |
||
1826 | surfx = new double[nrfiles]; |
||
1827 | surfy = new double[nrfiles]; |
||
1828 | surfz = new double[nrfiles]; |
||
1829 | for(int i = 0; i < (int)nrfiles; i++) {integralCount[i] = 0; integralAcc[i] = 0; } |
||
1830 | |||
1831 | TGraph *gScan[2]; // graphs for PDF and CDF functions |
||
1832 | double pdfmax = -1; |
||
1833 | TGraph2D *gScan2D; |
||
1834 | gScan2D = new TGraph2D(); |
||
1835 | int nrentries; |
||
1836 | double minInteg, maxInteg; |
||
1837 | |||
1838 | char exportname[256]; |
||
1839 | |||
1840 | if(files->GetSize() > 0) |
||
1841 | { |
||
1842 | for(int i = 0; i < (int)files->GetSize(); i++) |
||
1843 | { |
||
1844 | n++; |
||
1845 | if(files->At(i)) |
||
1846 | { |
||
1847 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
||
1848 | inroot = new TFile(ctemp, "READ"); |
||
1849 | |||
1850 | inroot->GetObject("header_data", header_data); |
||
1851 | inroot->GetObject("meas_data", meas_data); |
||
1852 | |||
1853 | // Reading the header |
||
1854 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
||
1855 | header_data->GetEntry(0); |
||
1856 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
||
1857 | header_data->GetEntry(0); |
||
1858 | header_data->SetBranchAddress("zpos", &evtheader.zpos); |
||
1859 | header_data->GetEntry(0); |
||
1860 | |||
1861 | char rdc[256]; |
||
1862 | j = selectCh->GetNumber(); |
||
1863 | double rangetdc[2]; |
||
1864 | rangetdc[0] = tdcMinwindow->GetNumber(); |
||
1865 | rangetdc[1] = tdcMaxwindow->GetNumber(); |
||
1866 | |||
1867 | k = 0; |
||
1868 | m = 0; |
||
1869 | |||
1870 | // Reading the data |
||
1871 | for(int e = 0; e < meas_data->GetEntries(); e++) |
||
1872 | { |
||
1873 | sprintf(rdc, "ADC%d", j); |
||
1874 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
||
1875 | meas_data->GetEntry(e); |
||
1876 | |||
1877 | sprintf(rdc, "TDC%d", j); |
||
1878 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
||
1879 | meas_data->GetEntry(e); |
||
1880 | |||
1881 | // If our data point is inside the TDC window |
||
1882 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
||
1883 | { |
||
1884 | k++; |
||
1885 | m += evtdata.adcdata[j]; |
||
1886 | } |
||
1887 | } |
||
1888 | |||
1889 | /* if(n == 1) // these values can be used to set 0 value at first X, Y and Z positions |
||
1890 | { |
||
1891 | xsurfmin = evtheader.xpos; |
||
1892 | ysurfmin = evtheader.ypos; |
||
1893 | zsurfmin = evtheader.zpos; |
||
1894 | } |
||
1895 | surfx[i] = (double)(evtheader.xpos-xsurfmin)*lenconversion; |
||
1896 | surfy[i] = (double)(evtheader.ypos-ysurfmin)*lenconversion; |
||
1897 | surfz[i] = (double)(evtheader.zpos-zsurfmin)*lenconversion;*/ |
||
1898 | surfx[i] = (double)(evtheader.xpos*lenconversion); |
||
1899 | surfy[i] = (double)(evtheader.ypos*lenconversion); |
||
1900 | surfz[i] = (double)(evtheader.zpos*lenconversion); |
||
1901 | |||
1902 | /* surfx[i] = evtheader.xpos; |
||
1903 | surfy[i] = evtheader.ypos; |
||
1904 | surfz[i] = evtheader.zpos; |
||
1905 | */ |
||
1906 | integralCount[i] += ((double)m)/((double)k); |
||
1907 | |||
1908 | delete inroot; |
||
1909 | } |
||
1910 | } |
||
1911 | |||
1912 | nrentries = n; |
||
1913 | printf("%d files were selected.\n", nrentries); |
||
1914 | |||
1915 | double curzval = surfz[0]; |
||
1916 | j = 0; |
||
1917 | int acc = 0; |
||
1918 | int zb; |
||
1919 | for(int i = 0; i <= nrentries; i++) |
||
1920 | { |
||
1921 | if(acc == nrentries) |
||
1922 | { |
||
1923 | minInteg = TMath::MinElement(j, integralAcc); |
||
1924 | |||
1925 | for(int za = 0; za < j; za++) |
||
1926 | integralAcc[za] = integralAcc[za] - minInteg; |
||
1927 | |||
1928 | maxInteg = TMath::MaxElement(j, integralAcc); |
||
1929 | |||
1930 | for(int za = 0; za < j; za++) |
||
1931 | { |
||
1932 | zb = i-j+za; |
||
1933 | integralCount[zb] = integralAcc[za]/maxInteg; |
||
128 | f9daq | 1934 | if(debug) |
117 | f9daq | 1935 | 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); |
1936 | } |
||
1937 | |||
1938 | // Plotting of PDF and CDF functions for the edge (with the added fit) |
||
1939 | gScan[1] = new TGraph(); |
||
1940 | for(int za = 0; za < j; za++) |
||
1941 | { |
||
1942 | zb = i-j+za; |
||
1943 | if(direction == 1) |
||
1944 | gScan[1]->SetPoint(za, (double)surfx[zb], (double)integralAcc[za]/maxInteg); |
||
1945 | else if(direction == 2) |
||
1946 | gScan[1]->SetPoint(za, (double)surfy[zb], (double)integralAcc[za]/maxInteg); |
||
1947 | |||
1948 | if( ((integralAcc[za+1]-integralAcc[za])/maxInteg > pdfmax) && (za < j-1) ) |
||
1949 | pdfmax = (integralAcc[za+1]-integralAcc[za])/maxInteg; |
||
1950 | } |
||
1951 | |||
1952 | pdfmax = (TMath::Ceil(pdfmax*10))/10.; |
||
1953 | |||
1954 | gScan[0] = new TGraph(); |
||
1955 | for(int za = j-1; za >= 0; za--) |
||
1956 | { |
||
1957 | zb = (i-1)-(j-1)+za; |
||
1958 | if((integralAcc[za]-integralAcc[za-1])/(maxInteg) < 0) |
||
1959 | { |
||
1960 | if(direction == 1) |
||
1961 | gScan[0]->SetPoint(za, (double)surfx[zb], 0); |
||
1962 | else if(direction == 2) |
||
1963 | gScan[0]->SetPoint(za, (double)surfy[zb], 0); |
||
1964 | } |
||
1965 | else |
||
1966 | { |
||
1967 | if(direction == 1) |
||
1968 | gScan[0]->SetPoint(za, (double)surfx[zb], (integralAcc[za]-integralAcc[za-1])/(maxInteg)); |
||
1969 | else if(direction == 2) |
||
1970 | gScan[0]->SetPoint(za, (double)surfy[zb], (integralAcc[za]-integralAcc[za-1])/(maxInteg)); |
||
1971 | // gScan[0]->SetPoint(za, (double)surfx[zb], (integralAcc[za]-integralAcc[za-1])/(pdfmax*maxInteg)); |
||
1972 | } |
||
1973 | } |
||
1974 | |||
1975 | remove_from_last((char*)files->At(i-1)->GetTitle(), '_', ctemp); |
||
1976 | sprintf(exportname, "%s_edge.pdf", ctemp); |
||
1977 | EdgeDetection(gScan[0], gScan[1], exportname, g1dCanvas, pdfmax, direction); |
||
1978 | |||
1979 | // delete gScan[0]; |
||
1980 | // delete gScan[1]; |
||
1981 | |||
1982 | i--; |
||
1983 | pdfmax = 0; |
||
1984 | break; |
||
1985 | } |
||
1986 | else |
||
1987 | { |
||
1988 | if(surfz[i] == curzval) |
||
1989 | { |
||
1990 | integralAcc[j] = integralCount[i]; |
||
128 | f9daq | 1991 | if(debug) |
117 | f9daq | 1992 | printf("Integral check 1 (i=%d,j=%d,z=%.2lf): %lf\t%lf\n", i, j, surfz[i], integralCount[i], integralAcc[j]); |
1993 | j++; |
||
1994 | acc++; |
||
1995 | } |
||
1996 | else |
||
1997 | { |
||
1998 | minInteg = TMath::MinElement(j, integralAcc); |
||
1999 | |||
2000 | for(int za = 0; za < j; za++) |
||
2001 | integralAcc[za] = integralAcc[za] - minInteg; |
||
2002 | |||
2003 | maxInteg = TMath::MaxElement(j, integralAcc); |
||
2004 | |||
2005 | for(int za = 0; za < j; za++) |
||
2006 | { |
||
2007 | zb = i-j+za; |
||
2008 | integralCount[zb] = integralAcc[za]/maxInteg; |
||
128 | f9daq | 2009 | if(debug) |
117 | f9daq | 2010 | 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); |
2011 | } |
||
2012 | |||
2013 | curzval = surfz[i]; |
||
2014 | i--; |
||
2015 | |||
2016 | // Plotting of PDF and CDF functions for the edge (with the added fit) |
||
2017 | gScan[1] = new TGraph(); |
||
2018 | for(int za = 0; za < j; za++) |
||
2019 | { |
||
2020 | zb = i-(j-1)+za; |
||
2021 | if(direction == 1) |
||
2022 | gScan[1]->SetPoint(za, (double)surfx[zb], (double)integralAcc[za]/maxInteg); |
||
2023 | else if(direction == 2) |
||
2024 | gScan[1]->SetPoint(za, (double)surfy[zb], (double)integralAcc[za]/maxInteg); |
||
2025 | |||
2026 | if( ((integralAcc[za+1]-integralAcc[za])/maxInteg > pdfmax) && (za < j-1) ) |
||
2027 | pdfmax = (integralAcc[za+1]-integralAcc[za])/maxInteg; |
||
2028 | } |
||
2029 | |||
2030 | pdfmax = (TMath::Ceil(pdfmax*10))/10.; |
||
2031 | |||
2032 | gScan[0] = new TGraph(); |
||
2033 | for(int za = j-1; za >= 0; za--) |
||
2034 | { |
||
2035 | zb = i-(j-1)+za; |
||
2036 | if((integralAcc[za]-integralAcc[za-1])/(maxInteg) < 0) |
||
2037 | { |
||
2038 | if(direction == 1) |
||
2039 | gScan[0]->SetPoint(za, (double)surfx[zb], 0); |
||
2040 | else if(direction == 2) |
||
2041 | gScan[0]->SetPoint(za, (double)surfy[zb], 0); |
||
2042 | } |
||
2043 | else |
||
2044 | { |
||
2045 | if(direction == 1) |
||
2046 | gScan[0]->SetPoint(za, (double)surfx[zb], (integralAcc[za]-integralAcc[za-1])/(maxInteg)); |
||
2047 | else if(direction == 2) |
||
2048 | gScan[0]->SetPoint(za, (double)surfy[zb], (integralAcc[za]-integralAcc[za-1])/(maxInteg)); |
||
2049 | // gScan[0]->SetPoint(za, (double)surfx[zb], (integralAcc[za]-integralAcc[za-1])/(pdfmax*maxInteg)); |
||
2050 | } |
||
2051 | } |
||
2052 | |||
2053 | remove_from_last((char*)files->At(i)->GetTitle(), '_', ctemp); |
||
2054 | sprintf(exportname, "%s_edge.pdf", ctemp); |
||
2055 | EdgeDetection(gScan[0], gScan[1], exportname, g1dCanvas, pdfmax, direction); |
||
2056 | |||
2057 | delete gScan[0]; |
||
2058 | delete gScan[1]; |
||
2059 | |||
2060 | j = 0; |
||
2061 | pdfmax = 0; |
||
2062 | } |
||
2063 | } |
||
2064 | } |
||
2065 | |||
2066 | // delete g1dCanvas; |
||
2067 | |||
2068 | double range[4]; |
||
2069 | if(direction == 1) |
||
2070 | { |
||
2071 | range[0] = TMath::MinElement(nrentries, surfx); |
||
2072 | range[1] = TMath::MaxElement(nrentries, surfx); |
||
2073 | } |
||
2074 | else if(direction == 2) |
||
2075 | { |
||
2076 | range[0] = TMath::MinElement(nrentries, surfy); |
||
2077 | range[1] = TMath::MaxElement(nrentries, surfy); |
||
2078 | } |
||
2079 | else |
||
2080 | { |
||
2081 | range[0] = TMath::MinElement(nrentries, surfx); |
||
2082 | range[1] = TMath::MaxElement(nrentries, surfx); |
||
2083 | } |
||
2084 | range[2] = TMath::MinElement(nrentries, surfz); |
||
2085 | range[3] = TMath::MaxElement(nrentries, surfz); |
||
2086 | |||
2087 | // Plotting of 2D edge plot |
||
2088 | for(int i = 0; i < nrentries; i++) |
||
2089 | { |
||
2090 | if(direction == 1) |
||
2091 | { |
||
128 | f9daq | 2092 | if(debug) |
117 | f9daq | 2093 | printf("%.2lf\t%.2lf\t%lf\n", surfx[i], surfz[i], integralCount[i]); |
2094 | gScan2D->SetPoint(i, surfx[i], surfz[i], integralCount[i]); |
||
2095 | } |
||
2096 | else if(direction == 2) |
||
2097 | { |
||
128 | f9daq | 2098 | if(debug) |
117 | f9daq | 2099 | printf("%.2lf\t%.2lf\t%lf\n", surfy[i], surfz[i], integralCount[i]); |
2100 | gScan2D->SetPoint(i, surfy[i], surfz[i], integralCount[i]); |
||
2101 | } |
||
2102 | } |
||
2103 | |||
2104 | gCanvas->cd(); |
||
2105 | gStyle->SetPalette(1); |
||
2106 | gScan2D->Draw("COLZ"); |
||
2107 | |||
2108 | gCanvas->Modified(); |
||
2109 | gCanvas->Update(); |
||
2110 | |||
2111 | if(direction == 1) |
||
2112 | gScan2D->GetXaxis()->SetTitle("X [#mum]"); |
||
2113 | else if(direction == 2) |
||
2114 | gScan2D->GetXaxis()->SetTitle("Y [#mum]"); |
||
2115 | gScan2D->GetXaxis()->CenterTitle(kTRUE); |
||
2116 | gScan2D->GetXaxis()->SetLabelSize(0.022); |
||
2117 | gScan2D->GetXaxis()->SetRangeUser(range[0], range[1]); |
||
2118 | gScan2D->GetXaxis()->SetNoExponent(); |
||
2119 | gScan2D->GetYaxis()->SetTitle("Z [#mum]"); |
||
2120 | gScan2D->GetYaxis()->SetTitleOffset(1.3); |
||
2121 | gScan2D->GetYaxis()->CenterTitle(kTRUE); |
||
2122 | gScan2D->GetYaxis()->SetLabelSize(0.022); |
||
2123 | gScan2D->GetYaxis()->SetRangeUser(range[2], range[3]); |
||
2124 | TGaxis *yax = (TGaxis*)gScan2D->GetYaxis(); |
||
2125 | yax->SetMaxDigits(4); |
||
2126 | if(!cleanPlots) |
||
2127 | gScan2D->SetTitle("Laser focal point"); |
||
2128 | else |
||
2129 | gScan2D->SetTitle(); |
||
2130 | |||
2131 | gCanvas->Modified(); |
||
2132 | gCanvas->Update(); |
||
2133 | |||
2134 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
2135 | sprintf(exportname, "%s", ctemp); |
||
2136 | remove_from_last(exportname, '_', ctemp); |
||
2137 | if(direction == 1) |
||
2138 | sprintf(exportname, "%s_xdir_focalpoint.pdf", ctemp); |
||
2139 | else if(direction == 2) |
||
2140 | sprintf(exportname, "%s_ydir_focalpoint.pdf", ctemp); |
||
2141 | gCanvas->SaveAs(exportname); |
||
2142 | } |
||
2143 | } |
||
2144 | |||
128 | f9daq | 2145 | // Integrate the spectrum |
2146 | void TGAppMainFrame::PhotonMu(TList *files) |
||
2147 | { |
||
2148 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2149 | char ctemp[256]; |
||
2150 | int j, k = 0, m = 0, n = 0, k2 = 0, m2 = 0; |
||
2151 | |||
2152 | // TCanvas *gCanvas = new TCanvas("canv","canv",900,900); |
||
2153 | TTree *header_data, *meas_data; |
||
2154 | double *integralCount, *integralPedestal; |
||
2155 | integralCount = new double[nrfiles]; |
||
2156 | integralPedestal = new double[nrfiles]; |
||
2157 | // double xsurfmin, ysurfmin, zsurfmin; |
||
2158 | double *angle; |
||
2159 | double *muval; |
||
2160 | angle = new double[nrfiles]; |
||
2161 | muval = new double[nrfiles]; |
||
2162 | for(int i = 0; i < (int)nrfiles; i++) {integralCount[i] = 0; integralPedestal[i] = 0; } |
||
2163 | |||
2164 | // TGraph *gScan[2]; // graph for angle dependence |
||
2165 | int nrentries; |
||
2166 | // double minInteg, maxInteg; |
||
2167 | |||
2168 | // char exportname[256]; |
||
2169 | |||
2170 | TSpectrum *spec; |
||
2171 | TH1F *histtemp; |
||
2172 | TH1 *histback; |
||
2173 | TH1F *h2; |
||
2174 | float *xpeaks; |
||
2175 | TF1 *fit; |
||
2176 | TF1 *fittingfunc; |
||
2177 | double *fparam; |
||
2178 | double meanparam; |
||
2179 | int adcpedestal[2]; |
||
2180 | double paramsigma = 0; |
||
2181 | |||
2182 | if(files->GetSize() > 0) |
||
2183 | { |
||
2184 | for(int i = 0; i < (int)files->GetSize(); i++) |
||
2185 | { |
||
2186 | n++; |
||
2187 | if(files->At(i)) |
||
2188 | { |
||
2189 | // Find the pedestal peak and the first minimum after pedestal ---------------- |
||
2190 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
2191 | histCanvas->GetCanvas()->Modified(); |
||
2192 | histCanvas->GetCanvas()->Update(); |
||
2193 | |||
2194 | histtemp = (TH1F*)histCanvas->GetCanvas()->GetPrimitive(histname); |
||
2195 | npeaks = 1; |
||
2196 | double par[300]; |
||
2197 | spec = new TSpectrum(npeaks); |
||
2198 | // Find spectrum background |
||
2199 | histback = spec->Background(histtemp, (int)fitInter->GetNumber(), "same"); |
||
2200 | // Clone histogram and subtract background from it |
||
2201 | h2 = (TH1F*)histtemp->Clone("h2"); |
||
2202 | h2->Add(histback, -1); |
||
2203 | // Search for the peaks |
||
2204 | int found = spec->Search(h2, fitSigma->GetNumber(), "goff", fitTresh->GetNumber() ); |
||
2205 | printf("Found %d candidates to fit.\n",found); |
||
2206 | npeaks = found; |
||
2207 | |||
2208 | xpeaks = spec->GetPositionX(); |
||
2209 | for(j = 0; j < found; j++) |
||
2210 | { |
||
2211 | float xp = xpeaks[j]; |
||
2212 | int bin = h2->GetXaxis()->FindBin(xp); |
||
2213 | float yp = h2->GetBinContent(bin); |
||
2214 | par[3*j] = yp; |
||
2215 | par[3*j+1] = xp; |
||
2216 | par[3*j+2] = (double)fitSigma->GetNumber(); |
||
2217 | } |
||
2218 | |||
2219 | // Fit the histogram |
||
2220 | fit = new TF1("fit", FindPeaks, 0, 400, 3*npeaks); |
||
2221 | TVirtualFitter::Fitter(histtemp, 3*npeaks); |
||
2222 | fit->SetParameters(par); |
||
2223 | fit->SetNpx(300); |
||
2224 | h2->Fit("fit","Q"); // for quiet mode, add Q |
||
2225 | fittingfunc = h2->GetFunction("fit"); |
||
2226 | fparam = fittingfunc->GetParameters(); |
||
2227 | |||
2228 | // Gather the parameters (mean peak value for now) |
||
2229 | j = 1; |
||
2230 | |||
2231 | meanparam = fparam[j]; |
||
2232 | paramsigma = fparam[j+1]; |
||
2233 | |||
2234 | /* while(1) |
||
2235 | { |
||
2236 | if( (fparam[j] < 1.E-30) || (fparamerr[j] < 1.E-10) ) |
||
2237 | break; |
||
2238 | else |
||
2239 | { |
||
2240 | if(fparam[j] > 0) |
||
2241 | { |
||
2242 | meanparam = fparam[j]; |
||
2243 | meanparamerr = fparamerr[j]; |
||
2244 | paramsigma = fparam[j+1]; |
||
2245 | nrfit++; |
||
2246 | } |
||
2247 | } |
||
2248 | |||
2249 | j+=3; |
||
2250 | } |
||
2251 | */ |
||
2252 | histCanvas->GetCanvas()->Modified(); |
||
2253 | histCanvas->GetCanvas()->Update(); |
||
2254 | |||
2255 | j = 0; |
||
2256 | adcpedestal[0] = 0; |
||
2257 | adcpedestal[1] = -1; |
||
2258 | while(1) |
||
2259 | { |
||
2260 | int bin = histtemp->GetXaxis()->FindBin((int)(j+meanparam+paramsigma)); |
||
2261 | |||
2262 | int yp = histtemp->GetBinContent(bin); |
||
2263 | if(adcpedestal[1] == -1) |
||
2264 | { |
||
2265 | adcpedestal[0] = j+meanparam+paramsigma; |
||
2266 | adcpedestal[1] = yp; |
||
2267 | } |
||
2268 | else |
||
2269 | { |
||
2270 | if(adcpedestal[1] >= yp) |
||
2271 | { |
||
2272 | adcpedestal[0] = j+meanparam+paramsigma; |
||
2273 | adcpedestal[1] = yp; |
||
2274 | } |
||
2275 | else |
||
2276 | break; |
||
2277 | } |
||
2278 | |||
2279 | j++; |
||
2280 | if(j > 50) break; |
||
2281 | } |
||
2282 | |||
2283 | cout << "Pedestal ends with ADC value: " << adcpedestal[0] << endl; |
||
2284 | |||
2285 | // ---------------------------------------------------------------------------- |
||
2286 | |||
2287 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
||
2288 | inroot = new TFile(ctemp, "READ"); |
||
2289 | |||
2290 | inroot->GetObject("header_data", header_data); |
||
2291 | inroot->GetObject("meas_data", meas_data); |
||
2292 | |||
2293 | // Reading the header |
||
2294 | // header_data->SetBranchAddress("angle", &evtheader.angle); |
||
2295 | // header_data->GetEntry(0); |
||
2296 | |||
2297 | char rdc[256]; |
||
2298 | j = selectCh->GetNumber(); |
||
2299 | double rangetdc[2]; |
||
2300 | rangetdc[0] = tdcMinwindow->GetNumber(); |
||
2301 | rangetdc[1] = tdcMaxwindow->GetNumber(); |
||
2302 | |||
2303 | k = 0; |
||
2304 | k2 = 0; |
||
2305 | m = 0; |
||
2306 | m2 = 0; |
||
2307 | |||
2308 | // Reading the data |
||
2309 | for(int e = 0; e < meas_data->GetEntries(); e++) |
||
2310 | { |
||
2311 | sprintf(rdc, "ADC%d", j); |
||
2312 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
||
2313 | meas_data->GetEntry(e); |
||
2314 | |||
2315 | sprintf(rdc, "TDC%d", j); |
||
2316 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
||
2317 | meas_data->GetEntry(e); |
||
2318 | |||
2319 | // If our data point is inside the TDC window |
||
2320 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
||
2321 | { |
||
2322 | // Gather only the integral of the pedestal |
||
2323 | if((double)evtdata.adcdata[j] < (double)adcpedestal[0]+0.5 ) |
||
2324 | { |
||
2325 | k2++; |
||
2326 | m2 += evtdata.adcdata[j]; |
||
2327 | } |
||
2328 | |||
2329 | // Gather the complete integral |
||
2330 | k++; |
||
2331 | m += evtdata.adcdata[j]; |
||
2332 | } |
||
2333 | } |
||
2334 | |||
2335 | // angle[i] = (double)(evtheader.angle); |
||
2336 | angle[i] = (double)(i*15.*TMath::ACos(-1.)/180.); // angle in radians |
||
2337 | cout << "Angle = " << angle[i] << endl; |
||
2338 | |||
2339 | // integralCount[i] += ((double)m)/((double)k); |
||
2340 | integralCount[i] += (double)m; |
||
2341 | cout << "Integral (" << k << " evts) = " << integralCount[i] << endl; |
||
2342 | |||
2343 | integralPedestal[i] += (double)m2; |
||
2344 | cout << "Integral (" << k2 << " evts) = " << integralPedestal[i] << endl; |
||
2345 | |||
2346 | muval[i] = -TMath::Log((double)k2/(double)k); |
||
2347 | cout << "Mu = " << muval[i] << endl; |
||
2348 | |||
2349 | delete inroot; |
||
2350 | } |
||
2351 | } |
||
2352 | |||
2353 | nrentries = n; |
||
2354 | printf("%d files were selected.\n", nrentries); |
||
2355 | |||
2356 | cout << "angle\tmu\trelative PDE\n" << endl; |
||
2357 | for(int i = 0; i < (int)files->GetSize(); i++) |
||
2358 | { |
||
2359 | // Relative PDE calculation |
||
2360 | cout << angle[i] << "\t" << muval[i] << "\t" << muval[i]/(muval[0]*TMath::Cos(angle[i])) << endl; |
||
2361 | } |
||
2362 | } |
||
2363 | } |
||
2364 | |||
117 | f9daq | 2365 | void TGAppMainFrame::RunMeas(void *ptr, int runCase, int zaxisscan) |
2366 | { |
||
2367 | printf("Start of Run, run case %d\n", runCase); |
||
2368 | float progVal; |
||
2369 | |||
2370 | char ctemp[256]; |
||
127 | f9daq | 2371 | char ctemp2[256]; |
117 | f9daq | 2372 | char fname[256]; |
127 | f9daq | 2373 | int itemp = 0; |
117 | f9daq | 2374 | |
2375 | remove_ext((char*)fileName->GetText(), ctemp); |
||
2376 | // printf("Save name: %s\nNo extension: %s\n", fileName->GetText(), ctemp); |
||
2377 | |||
2378 | // Open file for writing |
||
2379 | /* if(runCase == 0) |
||
2380 | { |
||
2381 | sprintf(fname, "rm %s_%s", ctemp, histExtAll); |
||
2382 | retTemp = system(fname); |
||
2383 | }*/ // deleting might not be necesary due to RECREATE in root file open |
||
2384 | |||
2385 | if( voltscanOn->IsOn() || surfscanOn->IsOn() ) |
||
2386 | { |
||
2387 | if(zaxisscan == 0) |
||
2388 | { |
||
127 | f9daq | 2389 | if( (voltscanOn->IsOn()) && (vOutStep->GetNumber() > 0.) ) |
2390 | SeqNumber(runCase, (int)((vOutStop->GetNumber())-(vOutStart->GetNumber()))/(vOutStep->GetNumber()), ctemp2); |
||
2391 | else if( surfscanOn->IsOn() ) |
||
2392 | { |
||
2393 | if( xPosStep->GetNumber() == 0 ) |
||
2394 | itemp = 1; |
||
2395 | else |
||
2396 | itemp = (int)((xPosMax->GetNumber())-(xPosMin->GetNumber()))/(xPosStep->GetNumber()); |
||
2397 | |||
2398 | if( yPosStep->GetNumber() == 0 ) |
||
2399 | itemp *= 1; |
||
2400 | else |
||
2401 | itemp *= (int)((yPosMax->GetNumber())-(yPosMin->GetNumber()))/(yPosStep->GetNumber()); |
||
2402 | SeqNumber(runCase, itemp, ctemp2); |
||
2403 | } |
||
2404 | sprintf(fname, "%s_%s%s", ctemp, ctemp2, histExt); |
||
117 | f9daq | 2405 | } |
2406 | else if(zaxisscan == 1) |
||
2407 | { |
||
127 | f9daq | 2408 | SeqNumber((int)zPos->GetNumber(), (int)zPosMax->GetNumber(), ctemp2); |
2409 | |||
2410 | if( (voltscanOn->IsOn()) && (vOutStep->GetNumber() > 0.) ) |
||
2411 | { |
||
2412 | sprintf(fname, "%s_z%s_", ctemp, ctemp2); |
||
2413 | SeqNumber(runCase, (int)((vOutStop->GetNumber())-(vOutStart->GetNumber()))/(vOutStep->GetNumber())+1, ctemp2); |
||
2414 | strcat(fname, ctemp2); |
||
2415 | strcat(fname, histExt); |
||
2416 | } |
||
2417 | else if( surfscanOn->IsOn() ) |
||
2418 | { |
||
2419 | sprintf(fname, "%s_z%s_", ctemp, ctemp2); |
||
2420 | |||
2421 | if( xPosStep->GetNumber() == 0 ) |
||
2422 | itemp = 1; |
||
2423 | else |
||
2424 | itemp = (int)((xPosMax->GetNumber())-(xPosMin->GetNumber()))/(xPosStep->GetNumber())+1; |
||
2425 | |||
2426 | if( yPosStep->GetNumber() == 0 ) |
||
2427 | itemp *= 1; |
||
2428 | else |
||
2429 | itemp *= (int)((yPosMax->GetNumber())-(yPosMin->GetNumber()))/(yPosStep->GetNumber())+1; |
||
2430 | SeqNumber(runCase, itemp, ctemp2); |
||
2431 | strcat(fname, ctemp2); |
||
2432 | strcat(fname, histExt); |
||
2433 | } |
||
2434 | else |
||
2435 | sprintf(fname, "%s_z%s%s", ctemp, ctemp2, histExt); |
||
2436 | |||
2437 | /* if(runCase < 10) |
||
117 | f9daq | 2438 | sprintf(fname, "%s_z%d_0000%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
2439 | else if( (runCase >= 10) && (runCase < 100) ) |
||
2440 | sprintf(fname, "%s_z%d_000%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
2441 | else if( (runCase >= 100) && (runCase < 1000) ) |
||
2442 | sprintf(fname, "%s_z%d_00%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
2443 | else if( (runCase >= 1000) && (runCase < 10000) ) |
||
2444 | sprintf(fname, "%s_z%d_0%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
2445 | else if( (runCase >= 10000) && (runCase < 100000) ) |
||
2446 | sprintf(fname, "%s_z%d_0%d%s", ctemp, (int)zPos->GetNumber(), runCase, histExt); |
||
127 | f9daq | 2447 | */ } |
117 | f9daq | 2448 | } |
2449 | else if( !voltscanOn->IsOn() && !surfscanOn->IsOn() ) |
||
2450 | sprintf(fname, "%s%s", ctemp, histExt); |
||
2451 | // printf("Rootfile: %s\n", fname); |
||
2452 | |||
2453 | // Check if set voltage is below the hard limit |
||
2454 | if( vOut->GetNumber() > vHardlimit->GetNumber() ) |
||
2455 | { |
||
2456 | printf("Voltage hard limit triggered (%lf > %lf)!\n", vOut->GetNumber(), vHardlimit->GetNumber() ); |
||
2457 | vOut->SetNumber( vHardlimit->GetNumber() ); |
||
2458 | } |
||
2459 | |||
2460 | outroot = new TFile(fname, "RECREATE"); |
||
2461 | |||
2462 | TTree *header_data = new TTree("header_data", "Header information for the measurement."); |
||
127 | f9daq | 2463 | TTree *meas_data = new TTree("meas_data", "Saved ADC and TDC measurement data."); |
2464 | TTree *scope_data = new TTree("scope_data", "Saved scope measurement data."); |
||
117 | f9daq | 2465 | |
2466 | // Branches for the header |
||
2467 | header_data->Branch("nrch", &evtheader.nrch, "nrch/I"); |
||
2468 | header_data->Branch("timestamp", &evtheader.timestamp, "timestamp/I"); |
||
2469 | header_data->Branch("biasvolt", &evtheader.biasvolt, "biasvolt/D"); |
||
2470 | header_data->Branch("xpos", &evtheader.xpos, "xpos/I"); |
||
2471 | header_data->Branch("ypos", &evtheader.ypos, "ypos/I"); |
||
2472 | header_data->Branch("zpos", &evtheader.zpos, "zpos/I"); |
||
2473 | header_data->Branch("temperature", &evtheader.temperature, "temperature/D"); |
||
2474 | header_data->Branch("laserinfo", &evtheader.laserinfo, "laserinfo/C"); |
||
2475 | |||
2476 | evtheader.nrch = (int)NCH->GetNumber()*2; |
||
2477 | evtheader.timestamp = (int)time(NULL); |
||
2478 | evtheader.biasvolt = (double)vOut->GetNumber(); |
||
2479 | evtheader.xpos = (int)xPos->GetNumber(); |
||
2480 | evtheader.ypos = (int)yPos->GetNumber(); |
||
2481 | evtheader.zpos = (int)zPos->GetNumber(); |
||
127 | f9daq | 2482 | evtheader.temperature = (double)chtemp->GetNumber(); |
128 | f9daq | 2483 | evtheader.angle = (double)incangle->GetNumber(); |
117 | f9daq | 2484 | sprintf(evtheader.laserinfo, "%s", laserInfo->GetText()); |
2485 | |||
2486 | char histtime[256]; |
||
2487 | GetTime(evtheader.timestamp, histtime); |
||
2488 | |||
2489 | printf("Save file header information:\n"); |
||
2490 | printf("- Number of channels: %d\n", evtheader.nrch); |
||
2491 | printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime); |
||
2492 | printf("- Bias voltage: %lf\n", evtheader.biasvolt); |
||
2493 | printf("- Table position (X,Y,Z): %d, %d, %d\n", evtheader.xpos, evtheader.ypos, evtheader.zpos); |
||
2494 | printf("- Temperature: %lf\n", evtheader.temperature); |
||
2495 | printf("- Laser and filter settings: %s\n", evtheader.laserinfo); |
||
2496 | |||
2497 | header_data->Fill(); |
||
2498 | |||
2499 | // Branches for ADC and TDC data |
||
2500 | for(int i = 0; i < evtheader.nrch/2; i++) |
||
2501 | { |
||
2502 | sprintf(ctemp, "ADC%d", i); |
||
2503 | sprintf(fname, "ADC%d/I", i); |
||
2504 | meas_data->Branch(ctemp, &evtdata.adcdata[i], fname); |
||
2505 | |||
2506 | sprintf(ctemp, "TDC%d", i); |
||
2507 | sprintf(fname, "TDC%d/I", i); |
||
2508 | meas_data->Branch(ctemp, &evtdata.tdcdata[i], fname); |
||
2509 | } |
||
2510 | |||
127 | f9daq | 2511 | // Initialize the scope before measurement |
2512 | if( sCamaclink->IsDown() ) |
||
2513 | InitializeScope(); |
||
2514 | |||
2515 | // Branch for scope measurement data |
||
2516 | if(gScopeDaq->scopeUseType == 2) // only if we select waveform measurement |
||
2517 | { |
||
2518 | if(gScopeDaq->scopeMeasSel == 0) |
||
2519 | scope_data->Branch("amp", &evtmeas.measdata, "amp/D"); |
||
2520 | else if(gScopeDaq->scopeMeasSel == 1) |
||
2521 | scope_data->Branch("area", &evtmeas.measdata, "area/D"); |
||
2522 | else if(gScopeDaq->scopeMeasSel == 2) |
||
2523 | scope_data->Branch("delay", &evtmeas.measdata, "delay/D"); |
||
2524 | else if(gScopeDaq->scopeMeasSel == 3) |
||
2525 | scope_data->Branch("fall", &evtmeas.measdata, "fall/D"); |
||
2526 | else if(gScopeDaq->scopeMeasSel == 4) |
||
2527 | scope_data->Branch("freq", &evtmeas.measdata, "freq/D"); |
||
2528 | else if(gScopeDaq->scopeMeasSel == 5) |
||
2529 | scope_data->Branch("max", &evtmeas.measdata, "max/D"); |
||
2530 | else if(gScopeDaq->scopeMeasSel == 6) |
||
2531 | scope_data->Branch("mean", &evtmeas.measdata, "mean/D"); |
||
2532 | else if(gScopeDaq->scopeMeasSel == 7) |
||
2533 | scope_data->Branch("min", &evtmeas.measdata, "min/D"); |
||
2534 | else if(gScopeDaq->scopeMeasSel == 8) |
||
2535 | scope_data->Branch("pk2p", &evtmeas.measdata, "pk2p/D"); |
||
2536 | else if(gScopeDaq->scopeMeasSel == 9) |
||
2537 | scope_data->Branch("pwidth", &evtmeas.measdata, "pwidth/D"); |
||
2538 | else if(gScopeDaq->scopeMeasSel == 10) |
||
2539 | scope_data->Branch("rise", &evtmeas.measdata, "rise/D"); |
||
2540 | } |
||
2541 | |||
117 | f9daq | 2542 | int neve = (int) evtNum->GetNumber(); |
2543 | int allEvt, zProg; |
||
2544 | zProg = 1; |
||
2545 | |||
2546 | #if WORKSTAT == 'I' |
||
2547 | #else |
||
2548 | // ONLY FOR TESTING! |
||
2549 | TRandom *randNum = new TRandom(); |
||
2550 | randNum->SetSeed(0); |
||
2551 | // ONLY FOR TESTING! |
||
2552 | #endif |
||
2553 | |||
2554 | if (gDaq) |
||
2555 | { |
||
2556 | gDaq->fStop=0; |
||
2557 | // Start gathering |
||
2558 | gDaq->start(); |
||
2559 | |||
2560 | busyLabel->Enable(); |
||
2561 | |||
2562 | for (int n=0;n<neve && !gDaq->fStop ;/*n++*/) |
||
2563 | { |
||
2564 | int nb = gDaq->event(gBuf,BSIZE); |
||
2565 | |||
2566 | #if WORKSTAT == 'I' |
||
2567 | #else |
||
2568 | // ONLY FOR TESTING! |
||
2569 | for(int i=0; i < evtheader.nrch; i++) |
||
2570 | { |
||
2571 | if(i == 1) |
||
2572 | gBuf[i] = randNum->Gaus(1500,300); |
||
2573 | else if(i == 0) |
||
2574 | gBuf[i] = randNum->Poisson(2500); |
||
2575 | } |
||
2576 | // ONLY FOR TESTING! |
||
2577 | #endif |
||
2578 | if (nb<=0) n--; |
||
2579 | |||
2580 | int nc=0; |
||
2581 | |||
2582 | while ( (nb>0) && (n<neve) ) |
||
2583 | { |
||
2584 | for(int i = 0; i < evtheader.nrch; i++) |
||
2585 | { |
||
2586 | unsigned short adc = gBuf[i+nc]&0xFFFF; |
||
2587 | if(i % 2 == 0) // TDC |
||
2588 | evtdata.tdcdata[i/2] = (int)adc; |
||
2589 | else if(i % 2 == 1) // ADC |
||
2590 | evtdata.adcdata[i/2] = (int)adc; |
||
127 | f9daq | 2591 | |
2592 | // Start plotting the scope waveform |
||
2593 | if( (gScopeDaq->scopeUseType == 1) && (sCamaclink->IsDown()) ) |
||
2594 | StartScopeAcq(); |
||
117 | f9daq | 2595 | } |
2596 | meas_data->Fill(); |
||
127 | f9daq | 2597 | |
2598 | // Start making a scope measurement |
||
2599 | if( (gScopeDaq->scopeUseType == 2) && (sCamaclink->IsDown()) ) |
||
2600 | { |
||
2601 | StartScopeAcq(); |
||
2602 | evtmeas.measdata = gScopeDaq->measubuf; |
||
2603 | } |
||
2604 | scope_data->Fill(); |
||
117 | f9daq | 2605 | |
2606 | n++; |
||
2607 | nc += evtheader.nrch; |
||
2608 | nb -= evtheader.nrch; |
||
2609 | } |
||
2610 | |||
2611 | MyTimer(); |
||
2612 | allEvt = n; |
||
2613 | if (gSystem->ProcessEvents()) printf("Run Interrupted\n"); |
||
2614 | |||
2615 | if( (started) && (n == (neve*zProg)/10) ) |
||
2616 | { |
||
2617 | progVal = (float)zProg*10; |
||
2618 | curProgress->SetPosition(progVal); |
||
2619 | zProg++; |
||
2620 | } |
||
2621 | } |
||
2622 | |||
2623 | printf("Number of gathered events: %d\n", allEvt); |
||
2624 | measStart->SetText("Start acquisition"); |
||
2625 | started = kFALSE; |
||
2626 | |||
2627 | gDaq->stop(); |
||
2628 | } |
||
2629 | |||
2630 | busyLabel->Disable(); |
||
2631 | printf("End of Run neve=%d\n",neve); |
||
2632 | |||
2633 | header_data->Write(); |
||
2634 | meas_data->Write(); |
||
127 | f9daq | 2635 | scope_data->Write(); |
117 | f9daq | 2636 | delete header_data; |
2637 | delete meas_data; |
||
127 | f9daq | 2638 | delete scope_data; |
117 | f9daq | 2639 | |
2640 | outroot->Close(); |
||
2641 | } |
||
2642 | |||
2643 | // Start the acquisition |
||
2644 | void TGAppMainFrame::StartAcq() |
||
2645 | { |
||
2646 | // Determine the type of measurement to perform |
||
2647 | int vscan = 0, pscan = 0, zscan = 0; |
||
2648 | if(voltscanOn->IsOn()) vscan = 1; |
||
2649 | if(surfscanOn->IsOn()) pscan = 1; |
||
2650 | if(zscanOn->IsOn()) zscan = 1; |
||
2651 | |||
2652 | char cmd[256]; |
||
2653 | int i, j, k; |
||
2654 | float progVal; |
||
2655 | FILE *pfin; |
||
2656 | |||
2657 | // Variables for voltage scan |
||
2658 | float currentVoltage, minVoltage, maxVoltage, stepVoltage; |
||
2659 | int repetition; |
||
2660 | |||
2661 | // Variables for surface scan |
||
2662 | int minXpos, maxXpos, stepXpos; |
||
2663 | int minYpos, maxYpos, stepYpos; |
||
2664 | int minZpos, maxZpos, stepZpos; |
||
2665 | int repetX, repetY, repetZ; |
||
2666 | |||
2667 | // Voltage scan |
||
2668 | if( (vscan == 1) && (pscan == 0) ) |
||
2669 | { |
||
2670 | if(started) |
||
2671 | { |
||
2672 | printf("Stopping current voltage scan...\n"); |
||
2673 | gROOT->SetInterrupt(); |
||
2674 | measStart->SetText("Start acquisition"); |
||
2675 | started = kFALSE; |
||
2676 | |||
2677 | pfin = fopen("finish_sig.txt","w"); |
||
2678 | fprintf(pfin, "%s: Voltage scan stopped.", timeStamp->GetText()); |
||
2679 | fclose(pfin); |
||
2680 | } |
||
2681 | else if(!started) |
||
2682 | { |
||
2683 | measStart->SetText("Stop acquisition"); |
||
2684 | started = kTRUE; |
||
2685 | |||
2686 | printf("Running a voltage scan...\n"); |
||
2687 | |||
2688 | minVoltage = vOutStart->GetNumber(); |
||
2689 | maxVoltage = vOutStop->GetNumber(); |
||
2690 | stepVoltage = vOutStep->GetNumber(); |
||
2691 | |||
2692 | if(stepVoltage == 0.) |
||
2693 | repetition = 1; |
||
2694 | else |
||
2695 | repetition = ((maxVoltage - minVoltage)/stepVoltage)+1; |
||
2696 | |||
2697 | for(i=0; i < repetition; i++) |
||
2698 | { |
||
2699 | progVal = (float)(100.00/repetition)*i; |
||
2700 | curProgress->SetPosition(progVal); |
||
2701 | |||
2702 | fflush(stdout); |
||
2703 | currentVoltage = minVoltage + stepVoltage*i; |
||
2704 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), currentVoltage); |
||
2705 | #if WORKSTAT == 'I' |
||
2706 | retTemp = system(cmd); |
||
2707 | #else |
||
2708 | printf("Cmd: %s\n",cmd); |
||
2709 | #endif |
||
2710 | fflush(stdout); |
||
2711 | |||
2712 | printf("Waiting for voltage change...\n"); |
||
127 | f9daq | 2713 | sleep(3); |
117 | f9daq | 2714 | vOut->SetNumber(currentVoltage); |
2715 | printf("Continuing...\n"); |
||
2716 | |||
2717 | // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<< |
||
2718 | RunMeas((void*)0, i, 0); |
||
2719 | fflush(stdout); |
||
2720 | } |
||
2721 | |||
2722 | // Set output back to off |
||
2723 | fflush(stdout); |
||
2724 | printf("Measurement finished, returning to starting voltage...\n"); |
||
2725 | sprintf(cmd, "%s/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), minVoltage); |
||
2726 | vOut->SetNumber(minVoltage); |
||
2727 | #if WORKSTAT == 'I' |
||
2728 | retTemp = system(cmd); |
||
2729 | #else |
||
2730 | printf("Cmd: %s\n",cmd); |
||
2731 | #endif |
||
2732 | fflush(stdout); |
||
2733 | |||
2734 | progVal = 100.00; |
||
2735 | curProgress->SetPosition(progVal); |
||
2736 | printf("\n"); |
||
2737 | |||
2738 | pfin = fopen("finish_sig.txt","w"); |
||
2739 | fprintf(pfin, "%s: Voltage scan finished.", timeStamp->GetText()); |
||
2740 | fclose(pfin); |
||
2741 | } |
||
2742 | } |
||
2743 | // Surface scan |
||
2744 | else if( (pscan == 1) && (vscan == 0) ) |
||
2745 | { |
||
2746 | minXpos = xPosMin->GetNumber(); |
||
2747 | maxXpos = xPosMax->GetNumber(); |
||
2748 | stepXpos = xPosStep->GetNumber(); |
||
2749 | minYpos = yPosMin->GetNumber(); |
||
2750 | maxYpos = yPosMax->GetNumber(); |
||
2751 | stepYpos = yPosStep->GetNumber(); |
||
2752 | minZpos = zPosMin->GetNumber(); |
||
2753 | maxZpos = zPosMax->GetNumber(); |
||
2754 | stepZpos = zPosStep->GetNumber(); |
||
2755 | |||
2756 | if(zscan == 1) |
||
2757 | { |
||
2758 | if(stepZpos == 0.) repetZ = 1; |
||
2759 | else repetZ = ((maxZpos - minZpos)/stepZpos)+1; |
||
2760 | } |
||
2761 | else |
||
2762 | { |
||
2763 | minZpos = zPos->GetNumber(); |
||
2764 | repetZ = 1; |
||
2765 | } |
||
2766 | |||
2767 | if(stepXpos == 0.) repetX = 1; |
||
2768 | else repetX = ((maxXpos - minXpos)/stepXpos)+1; |
||
2769 | if(stepYpos == 0.) repetY = 1; |
||
2770 | else repetY = ((maxYpos - minYpos)/stepYpos)+1; |
||
2771 | |||
2772 | for(k=0; k < repetZ; k++) |
||
2773 | { |
||
2774 | fflush(stdout); |
||
2775 | // Y-axis change |
||
2776 | 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); |
||
2777 | #if WORKSTAT == 'I' |
||
2778 | retTemp = system(cmd); |
||
2779 | #else |
||
2780 | printf("Cmd: %s\n",cmd); |
||
2781 | #endif |
||
2782 | fflush(stdout); |
||
2783 | |||
2784 | printf("Next Z position...\n"); |
||
2785 | zPos->SetNumber(minZpos + stepZpos*k); |
||
2786 | fflush(stdout); |
||
2787 | |||
2788 | for(j=0; j < repetY; j++) |
||
2789 | { |
||
2790 | fflush(stdout); |
||
2791 | // Y-axis change |
||
2792 | 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); |
||
2793 | #if WORKSTAT == 'I' |
||
2794 | retTemp = system(cmd); |
||
2795 | #else |
||
2796 | printf("Cmd: %s\n",cmd); |
||
2797 | #endif |
||
2798 | fflush(stdout); |
||
2799 | |||
2800 | sleep(4); |
||
2801 | printf("Next Y position...\n"); |
||
2802 | yPos->SetNumber(minYpos + stepYpos*j); |
||
2803 | fflush(stdout); |
||
2804 | |||
2805 | for(i=0; i < repetX; i++) |
||
2806 | { |
||
2807 | progVal = (float)(100.00/(repetX*repetY))*(j*repetX+i); |
||
2808 | curProgress->SetPosition(progVal); |
||
2809 | |||
2810 | // X-axis change |
||
2811 | 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); |
||
2812 | #if WORKSTAT == 'I' |
||
2813 | retTemp = system(cmd); |
||
2814 | #else |
||
2815 | printf("Cmd: %s\n",cmd); |
||
2816 | #endif |
||
2817 | fflush(stdout); |
||
2818 | |||
2819 | printf("Next X position...\n"); |
||
2820 | fflush(stdout); |
||
2821 | |||
2822 | printf("Waiting for position change...\n"); |
||
2823 | sleep(2); |
||
2824 | xPos->SetNumber(minXpos + stepXpos*i); |
||
2825 | printf("Continuing...\n"); |
||
2826 | |||
2827 | // for (k=0;k<(NTDCCH+NADCCH);k++) gHisto1D[k]->Reset(); |
||
2828 | // for (k=0;k<(NTDCCH+NADCCH)/2;k++) gHisto2D[k]->Reset(); |
||
2829 | |||
2830 | // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<< |
||
2831 | RunMeas((void*)0, (j*repetX + i), zscan ); |
||
2832 | |||
2833 | fflush(stdout); |
||
2834 | } |
||
2835 | |||
2836 | printf("\n"); |
||
2837 | } |
||
2838 | } |
||
2839 | |||
2840 | fflush(stdout); |
||
2841 | printf("Measurement finished, returning to starting position...\n"); |
||
2842 | // X-axis return |
||
2843 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/MIKRO/mikro_ctrl -n 1 -c m", rootdir, minXpos, rootdir); |
||
2844 | #if WORKSTAT == 'I' |
||
2845 | retTemp = system(cmd); |
||
2846 | #else |
||
2847 | printf("Cmd: %s\n",cmd); |
||
2848 | #endif |
||
2849 | fflush(stdout); |
||
2850 | |||
2851 | // Y-axis return |
||
2852 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/MIKRO/mikro_ctrl -n 2 -c m", rootdir, minYpos, rootdir); |
||
2853 | #if WORKSTAT == 'I' |
||
2854 | retTemp = system(cmd); |
||
2855 | #else |
||
2856 | printf("Cmd: %s\n",cmd); |
||
2857 | #endif |
||
2858 | |||
2859 | // Z-axis return |
||
2860 | sprintf(cmd, "sudo %s/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/MIKRO/mikro_ctrl -n 3 -c m", rootdir, minZpos, rootdir); |
||
2861 | #if WORKSTAT == 'I' |
||
2862 | retTemp = system(cmd); |
||
2863 | #else |
||
2864 | printf("Cmd: %s\n",cmd); |
||
2865 | #endif |
||
2866 | xPos->SetNumber(minXpos); |
||
2867 | yPos->SetNumber(minYpos); |
||
2868 | zPos->SetNumber(minZpos); |
||
2869 | |||
2870 | progVal = 100.00; |
||
2871 | curProgress->SetPosition(progVal); |
||
2872 | printf("\n"); |
||
2873 | |||
2874 | pfin = fopen("finish_sig.txt","w"); |
||
2875 | fprintf(pfin, "%s: Surface scan finished.", timeStamp->GetText()); |
||
2876 | fclose(pfin); |
||
2877 | } |
||
2878 | // Normal single measurement |
||
2879 | else if( (vscan == 0) && (pscan == 0) ) |
||
2880 | { |
||
2881 | // Set the start button to stop and enable stopping of measurement |
||
2882 | if(started) |
||
2883 | { |
||
2884 | printf("Stopping current single scan...\n"); |
||
2885 | gROOT->SetInterrupt(); |
||
2886 | // gDaq->fStop=1; |
||
2887 | measStart->SetText("Start acquisition"); |
||
2888 | started = kFALSE; |
||
2889 | } |
||
2890 | else if(!started) |
||
2891 | { |
||
2892 | measStart->SetText("Stop acquisition"); |
||
2893 | started = kTRUE; |
||
2894 | |||
2895 | printf("Running a single scan...\n"); |
||
2896 | RunMeas((void*)0, 0, 0); |
||
2897 | printf("Measurement finished...\n"); |
||
2898 | printf("\n"); |
||
2899 | } |
||
2900 | } |
||
2901 | } |
||
2902 | |||
2903 | // File browser for opening histograms |
||
2904 | void TGAppMainFrame::SelectDirectory() |
||
2905 | { |
||
2906 | int i = fileList->GetNumberOfEntries(); |
||
2907 | |||
2908 | TGFileInfo file_info; |
||
2909 | const char *filetypes[] = {"Histograms",histExtAll,0,0}; |
||
2910 | file_info.fFileTypes = filetypes; |
||
2911 | file_info.fIniDir = StrDup("./results"); |
||
2912 | file_info.fMultipleSelection = kTRUE; |
||
2913 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info); |
||
2914 | |||
2915 | TList *files = file_info.fFileNamesList; |
||
2916 | if(files) |
||
2917 | { |
||
2918 | TSystemFile *file; |
||
2919 | TString fname; |
||
2920 | TIter next(files); |
||
2921 | while(file=(TSystemFile*)next()) |
||
2922 | { |
||
2923 | fname = file->GetName(); |
||
2924 | fileList->AddEntry(fname.Data(), i); |
||
2925 | i++; |
||
2926 | } |
||
2927 | } |
||
2928 | fileList->Layout(); |
||
2929 | } |
||
2930 | |||
2931 | // File browser for selecting the save file |
||
2932 | void TGAppMainFrame::SaveFile() |
||
2933 | { |
||
2934 | TGFileInfo file_info; |
||
2935 | const char *filetypes[] = {"Histograms",histExtAll,0,0}; |
||
2936 | file_info.fFileTypes = filetypes; |
||
2937 | file_info.fIniDir = StrDup("./results"); |
||
2938 | new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDSave, &file_info); |
||
2939 | |||
2940 | fileName->SetText(file_info.fFilename); |
||
2941 | } |
||
2942 | |||
2943 | // Toggle multiple selection in filelist |
||
2944 | void TGAppMainFrame::ListMultiSelect() |
||
2945 | { |
||
2946 | fileList->SetMultipleSelections((multiSelect->IsOn())); |
||
2947 | |||
2948 | if(multiSelectAll->IsDown()) |
||
2949 | multiSelectAll->SetState(kButtonUp); |
||
2950 | } |
||
2951 | |||
2952 | // Select all entries in filelist |
||
2953 | void TGAppMainFrame::ListSelectAll() |
||
2954 | { |
||
2955 | if(multiSelectAll->IsDown()) |
||
2956 | { |
||
2957 | multiSelect->SetState(kButtonDown); |
||
2958 | fileList->SetMultipleSelections((multiSelect->IsOn())); |
||
2959 | for(int i = 0; i < fileList->GetNumberOfEntries(); i++) |
||
2960 | fileList->Select(i,kTRUE); |
||
2961 | } |
||
2962 | else if(!multiSelectAll->IsDown()) |
||
2963 | { |
||
2964 | multiSelect->SetState(kButtonUp); |
||
2965 | fileList->SetMultipleSelections((multiSelect->IsOn())); |
||
2966 | for(int i = 0; i < fileList->GetNumberOfEntries(); i++) |
||
2967 | fileList->Select(i,kFALSE); |
||
2968 | } |
||
2969 | } |
||
2970 | |||
2971 | // Navigation buttons for the filelist (<<, >>) and double click |
||
2972 | void TGAppMainFrame::FileListNavigation(int pn) |
||
2973 | { |
||
2974 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
2975 | int curSel; |
||
2976 | TList *files; |
||
2977 | if( nrfiles > 0 ) |
||
2978 | { |
||
2979 | if(pn < -1) |
||
2980 | { |
||
2981 | if(multiSelect->IsOn()) |
||
2982 | { |
||
2983 | // turn off multiple selection and select first file on list |
||
2984 | fileList->SetMultipleSelections(kFALSE); |
||
2985 | multiSelect->SetState(kButtonUp); |
||
2986 | multiSelectAll->SetState(kButtonUp); |
||
2987 | |||
2988 | fileList->Select(0,kTRUE); |
||
2989 | } |
||
2990 | else |
||
2991 | { |
||
2992 | // if nothing is selected, curSel will be -1 |
||
2993 | curSel = fileList->GetSelected(); |
||
2994 | // go to next file on list |
||
2995 | if(pn == -3) |
||
2996 | { |
||
2997 | if( (curSel == (int)(nrfiles-1)) || (curSel == -1) ) |
||
2998 | fileList->Select(0); |
||
2999 | else |
||
3000 | fileList->Select(curSel+1); |
||
3001 | } |
||
3002 | // go to previous file on list |
||
3003 | else if(pn == -2) |
||
3004 | { |
||
3005 | if( (curSel == 0) || (curSel == -1) ) |
||
3006 | fileList->Select(nrfiles-1); |
||
3007 | else |
||
3008 | fileList->Select(curSel-1); |
||
3009 | } |
||
3010 | } |
||
3011 | } |
||
3012 | |||
3013 | // check the newly selected file/files and return its name/their names |
||
3014 | files = new TList(); |
||
3015 | fileList->GetSelectedEntries(files); |
||
3016 | if(files) |
||
3017 | { |
||
3018 | for(int i = 0; i < (int)nrfiles; i++) |
||
3019 | { |
||
3020 | if(files->At(i)) |
||
3021 | { |
||
128 | f9daq | 3022 | if(debug) |
117 | f9daq | 3023 | printf("Filename: %s\n", files->At(i)->GetTitle()); |
3024 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
3025 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
3026 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
3027 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1); |
||
3028 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
3029 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2); |
||
3030 | } |
||
3031 | } |
||
3032 | } |
||
3033 | |||
3034 | // Still need to include drawing of histograms we move to!!! |
||
3035 | } |
||
3036 | } |
||
3037 | |||
3038 | // Display the currently selected histogram in file list |
||
3039 | void TGAppMainFrame::DisplayHistogram(char* histfile, int histtype) |
||
3040 | { |
||
128 | f9daq | 3041 | if(debug) |
117 | f9daq | 3042 | printf("Selected file: %s\n", histfile); |
3043 | |||
3044 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
3045 | |||
3046 | inroot = new TFile(histfile, "READ"); |
||
3047 | |||
3048 | TTree *header_data, *meas_data; |
||
3049 | inroot->GetObject("header_data", header_data); |
||
3050 | inroot->GetObject("meas_data", meas_data); |
||
3051 | |||
3052 | // Reading the header |
||
3053 | header_data->SetBranchAddress("nrch", &evtheader.nrch); |
||
3054 | header_data->GetEntry(0); |
||
3055 | header_data->SetBranchAddress("timestamp", &evtheader.timestamp); |
||
3056 | header_data->GetEntry(0); |
||
3057 | header_data->SetBranchAddress("biasvolt", &evtheader.biasvolt); |
||
3058 | header_data->GetEntry(0); |
||
3059 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
||
3060 | header_data->GetEntry(0); |
||
3061 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
||
3062 | header_data->GetEntry(0); |
||
3063 | header_data->SetBranchAddress("zpos", &evtheader.zpos); |
||
3064 | header_data->GetEntry(0); |
||
3065 | header_data->SetBranchAddress("temperature", &evtheader.temperature); |
||
3066 | header_data->GetEntry(0); |
||
128 | f9daq | 3067 | header_data->SetBranchAddress("angle", &evtheader.angle); |
3068 | header_data->GetEntry(0); |
||
117 | f9daq | 3069 | header_data->SetBranchAddress("laserinfo", &evtheader.laserinfo); |
3070 | header_data->GetEntry(0); |
||
3071 | |||
3072 | char histtime[256]; |
||
3073 | GetTime(evtheader.timestamp, histtime); |
||
3074 | |||
128 | f9daq | 3075 | // Displaying header information (debug and on the GUI) |
3076 | if(debug) |
||
117 | f9daq | 3077 | { |
3078 | printf("Opened file header information:\n"); |
||
3079 | printf("- Number of channels: %d\n", evtheader.nrch); |
||
3080 | printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime); |
||
3081 | printf("- Bias voltage: %lf\n", evtheader.biasvolt); |
||
3082 | printf("- Table position (X,Y,Z): %d, %d, %d\n", evtheader.xpos, evtheader.ypos, evtheader.zpos); |
||
128 | f9daq | 3083 | if(evtheader.temperature) |
3084 | printf("- Temperature: %lf\n", evtheader.temperature); |
||
3085 | if(evtheader.angle) |
||
3086 | printf("- Incidence angle: %lf\n", evtheader.angle); |
||
117 | f9daq | 3087 | printf("- Laser and filter settings: %s\n", evtheader.laserinfo); |
3088 | } |
||
3089 | |||
128 | f9daq | 3090 | char ctemp[512]; |
3091 | disptime->SetText(histtime); |
||
3092 | dispbias->SetNumber(evtheader.biasvolt); |
||
3093 | sprintf(ctemp, "%d, %d, %d", evtheader.xpos, evtheader.ypos, evtheader.zpos); |
||
3094 | disppos->SetText(ctemp); |
||
3095 | if(evtheader.temperature) |
||
3096 | disptemp->SetNumber(evtheader.temperature); |
||
3097 | else |
||
3098 | disptemp->SetNumber(0.0); |
||
3099 | if(evtheader.angle) |
||
3100 | dispangle->SetNumber(evtheader.angle); |
||
3101 | else |
||
3102 | dispangle->SetNumber(0.0); |
||
3103 | displaser->SetText(evtheader.laserinfo); |
||
3104 | |||
117 | f9daq | 3105 | int j; |
3106 | char rdc[256]; |
||
3107 | char rdcsel[256]; |
||
3108 | |||
3109 | j = selectCh->GetNumber(); |
||
3110 | |||
3111 | printf("Found %d data points.\n", (int)meas_data->GetEntries()); |
||
3112 | |||
3113 | gCanvas->cd(); |
||
3114 | double range[4]; |
||
3115 | range[0] = adcMinRange->GetNumber(); |
||
3116 | range[1] = adcMaxRange->GetNumber(); |
||
3117 | range[2] = tdcMinwindow->GetNumber(); |
||
3118 | range[3] = tdcMaxwindow->GetNumber(); |
||
3119 | |||
3120 | if(histtype == 0) |
||
3121 | { |
||
3122 | if( range[0] == range[1] ) |
||
3123 | sprintf(rdc, "ADC%d>>%s", j, histname); |
||
3124 | else |
||
3125 | sprintf(rdc, "ADC%d>>%s(%d,%lf,%lf)", j, histname, (int)(range[1]-range[0]), range[0]-0.5, range[1]-0.5); |
||
3126 | |||
3127 | sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion); |
||
3128 | meas_data->Draw(rdc, rdcsel); |
||
3129 | |||
3130 | sprintf(rdc, "ADC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);ADC;", j, evtheader.biasvolt, range[2], range[3]); |
||
3131 | TH1F *histtemp = (TH1F*)gCanvas->GetPrimitive(histname); |
||
3132 | if(!cleanPlots) |
||
3133 | histtemp->SetTitle(rdc); |
||
3134 | else |
||
3135 | histtemp->SetTitle(";ADC;"); |
||
3136 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
3137 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
3138 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
3139 | if(cleanPlots) |
||
3140 | { |
||
3141 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
3142 | yax->SetMaxDigits(4); |
||
3143 | } |
||
3144 | |||
3145 | gCanvas->Modified(); |
||
3146 | gCanvas->Update(); |
||
3147 | |||
3148 | if( yMinRange->GetNumber() != yMaxRange->GetNumber() ) |
||
3149 | { |
||
3150 | if( (logscale->IsDown()) && (yMinRange->GetNumber() <= 0) ) |
||
3151 | { |
||
3152 | histtemp->GetYaxis()->SetRangeUser(0.5, yMaxRange->GetNumber()); |
||
3153 | yMinRange->SetNumber(0.5); |
||
3154 | logchange = 1; |
||
3155 | } |
||
3156 | else |
||
3157 | { |
||
3158 | gCanvas->SetLogy(kFALSE); |
||
3159 | if(logchange == 1) |
||
3160 | { |
||
3161 | yMinRange->SetNumber(0.0); |
||
3162 | logchange = 0; |
||
3163 | } |
||
3164 | histtemp->GetYaxis()->SetRangeUser(yMinRange->GetNumber(), yMaxRange->GetNumber()); |
||
3165 | } |
||
3166 | } |
||
3167 | |||
3168 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
3169 | if(!cleanPlots) |
||
3170 | { |
||
3171 | stats->SetX1NDC(0.84); stats->SetX2NDC(0.97); |
||
3172 | stats->SetY1NDC(0.87); stats->SetY2NDC(0.97); |
||
3173 | } |
||
3174 | else |
||
3175 | { |
||
3176 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
3177 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
3178 | } |
||
3179 | } |
||
3180 | else if(histtype == 1) |
||
3181 | { |
||
3182 | if( range[0] == range[1] ) |
||
3183 | sprintf(rdc, "(TDC%d/%lf)>>%s", j, tdctimeconversion, histname); |
||
3184 | else |
||
3185 | sprintf(rdc, "(TDC%d/%lf)>>%s(%d,%lf,%lf)", j, tdctimeconversion, histname, (int)((range[3]-range[2])*tdctimeconversion), range[2], range[3]); |
||
3186 | sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion); |
||
3187 | meas_data->Draw(rdc, rdcsel); |
||
3188 | |||
3189 | sprintf(rdc, "TDC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);Time (TDC channel) [ns];", j, evtheader.biasvolt, range[2], range[3]); |
||
3190 | TH1F *histtemp = (TH1F*)gCanvas->GetPrimitive(histname); |
||
3191 | if(!cleanPlots) |
||
3192 | histtemp->SetTitle(rdc); |
||
3193 | else |
||
3194 | histtemp->SetTitle(";Time (TDC channel) [ns];"); |
||
3195 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
3196 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
3197 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
3198 | if(cleanPlots) |
||
3199 | { |
||
3200 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
3201 | yax->SetMaxDigits(4); |
||
3202 | } |
||
3203 | |||
3204 | gCanvas->Modified(); |
||
3205 | gCanvas->Update(); |
||
3206 | |||
3207 | if( yMinRange->GetNumber() != yMaxRange->GetNumber() ) |
||
3208 | { |
||
3209 | if( (logscale->IsDown()) && (yMinRange->GetNumber() <= 0) ) |
||
3210 | { |
||
3211 | histtemp->GetYaxis()->SetRangeUser(0.5, yMaxRange->GetNumber()); |
||
3212 | yMinRange->SetNumber(0.5); |
||
3213 | logchange = 1; |
||
3214 | } |
||
3215 | else |
||
3216 | { |
||
3217 | gCanvas->SetLogy(kFALSE); |
||
3218 | if(logchange == 1) |
||
3219 | { |
||
3220 | yMinRange->SetNumber(0.0); |
||
3221 | logchange = 0; |
||
3222 | } |
||
3223 | histtemp->GetYaxis()->SetRangeUser(yMinRange->GetNumber(), yMaxRange->GetNumber()); |
||
3224 | } |
||
3225 | } |
||
3226 | |||
3227 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
3228 | if(!cleanPlots) |
||
3229 | { |
||
3230 | stats->SetX1NDC(0.84); stats->SetX2NDC(0.97); |
||
3231 | stats->SetY1NDC(0.87); stats->SetY2NDC(0.97); |
||
3232 | } |
||
3233 | else |
||
3234 | { |
||
3235 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
3236 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
3237 | } |
||
3238 | } |
||
3239 | else if(histtype == 2) |
||
3240 | { |
||
3241 | if( ((range[0] == range[1]) && (range[2] == range[3])) || (range[2] == range[3]) || (range[0] == range[1]) ) |
||
3242 | sprintf(rdc, "(TDC%d/%lf):ADC%d>>%s", j, tdctimeconversion, j, histname); |
||
3243 | else |
||
3244 | 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]); |
||
3245 | meas_data->Draw(rdc,"","COLZ"); |
||
3246 | |||
3247 | sprintf(rdc, "ADC/TDC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);ADC;TDC", j, evtheader.biasvolt, range[2], range[3]); |
||
3248 | TH2F *histtemp = (TH2F*)gCanvas->GetPrimitive(histname); |
||
3249 | if(!cleanPlots) |
||
3250 | histtemp->SetTitle(rdc); |
||
3251 | else |
||
3252 | histtemp->SetTitle(";ADC;Time (TDC channel) [ns]"); |
||
3253 | histtemp->GetXaxis()->SetLabelSize(0.025); |
||
3254 | histtemp->GetXaxis()->CenterTitle(kTRUE); |
||
3255 | histtemp->GetYaxis()->SetLabelSize(0.025); |
||
3256 | histtemp->GetYaxis()->CenterTitle(kTRUE); |
||
3257 | histtemp->GetYaxis()->SetTitleOffset(1.35); |
||
3258 | if(cleanPlots) |
||
3259 | { |
||
3260 | TGaxis *yax = (TGaxis*)histtemp->GetYaxis(); |
||
3261 | yax->SetMaxDigits(4); |
||
3262 | } |
||
3263 | |||
3264 | gCanvas->Modified(); |
||
3265 | gCanvas->Update(); |
||
3266 | |||
3267 | TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats"); |
||
3268 | // stats->SetOptStat(0); |
||
3269 | stats->SetX1NDC(1.1); stats->SetX2NDC(1.3); |
||
3270 | stats->SetY1NDC(1.1); stats->SetY2NDC(1.3); |
||
3271 | |||
3272 | TPaletteAxis *gpalette = (TPaletteAxis*)histtemp->GetListOfFunctions()->FindObject("palette"); |
||
3273 | gpalette->SetLabelSize(0.022); |
||
3274 | } |
||
3275 | |||
3276 | if(histtype < 2) |
||
3277 | { |
||
3278 | if( logscale->IsDown() ) |
||
3279 | gCanvas->SetLogy(kTRUE); |
||
3280 | else if( !logscale->IsDown() ) |
||
3281 | gCanvas->SetLogy(kFALSE); |
||
3282 | } |
||
3283 | else |
||
3284 | gCanvas->SetLogy(kFALSE); |
||
3285 | |||
3286 | gCanvas->Modified(); |
||
3287 | gCanvas->Update(); |
||
3288 | |||
3289 | // If you close the opened file, the data can't be accessed by other functions |
||
3290 | } |
||
3291 | |||
3292 | // Create a 2D surface plot and plot it |
||
3293 | void TGAppMainFrame::MakeSurfPlot(TList *files) |
||
3294 | { |
||
3295 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
3296 | int j, k = 0, m = 0, n = 0; |
||
3297 | char ctemp[256]; |
||
3298 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
3299 | TTree *header_data, *meas_data; |
||
3300 | double *integralCount; |
||
3301 | double *surfx, *surfy; |
||
3302 | double xsurfmin = 0, ysurfmin = 0; |
||
3303 | integralCount = new double[nrfiles]; |
||
3304 | for(int i = 0; i < (int)nrfiles; i++) integralCount[i] = 0; |
||
3305 | surfx = new double[nrfiles]; |
||
3306 | surfy = new double[nrfiles]; |
||
3307 | int nrentries; |
||
3308 | TGraph2D *gScan2D; |
||
3309 | gScan2D = new TGraph2D(); |
||
3310 | |||
3311 | /* int zProg = 0; |
||
3312 | float progVal; |
||
3313 | curProgress->SetPosition(zProg);*/ |
||
3314 | |||
3315 | char exportname[256]; |
||
3316 | |||
3317 | if(multiSelect->IsOn()) |
||
3318 | { |
||
3319 | printf("Creating a surface plot. Please wait...\n"); |
||
3320 | fileList->GetSelectedEntries(files); |
||
3321 | if(files) |
||
3322 | { |
||
3323 | busyLabel->Enable(); |
||
3324 | |||
3325 | for(int i = 0; i < (int)nrfiles; i++) |
||
3326 | { |
||
3327 | if(files->At(i)) |
||
3328 | { |
||
3329 | n++; |
||
3330 | // printf("Filename: %s\n", files->At(i)->GetTitle()); |
||
3331 | |||
3332 | sprintf(ctemp, "%s", files->At(i)->GetTitle()); |
||
3333 | inroot = new TFile(ctemp, "READ"); |
||
3334 | |||
3335 | inroot->GetObject("header_data", header_data); |
||
3336 | inroot->GetObject("meas_data", meas_data); |
||
3337 | |||
3338 | // Reading the header |
||
3339 | header_data->SetBranchAddress("xpos", &evtheader.xpos); |
||
3340 | header_data->GetEntry(0); |
||
3341 | header_data->SetBranchAddress("ypos", &evtheader.ypos); |
||
3342 | header_data->GetEntry(0); |
||
3343 | |||
3344 | char rdc[256]; |
||
3345 | j = selectCh->GetNumber(); |
||
3346 | double rangetdc[2]; |
||
3347 | rangetdc[0] = tdcMinwindow->GetNumber(); |
||
3348 | rangetdc[1] = tdcMaxwindow->GetNumber(); |
||
3349 | |||
3350 | k = 0; |
||
3351 | m = 0; |
||
3352 | |||
3353 | // Reading the data |
||
3354 | for(int i = 0; i < meas_data->GetEntries(); i++) |
||
3355 | { |
||
3356 | sprintf(rdc, "ADC%d", j); |
||
3357 | meas_data->SetBranchAddress(rdc, &evtdata.adcdata[j]); |
||
3358 | meas_data->GetEntry(i); |
||
3359 | |||
3360 | sprintf(rdc, "TDC%d", j); |
||
3361 | meas_data->SetBranchAddress(rdc, &evtdata.tdcdata[j]); |
||
3362 | meas_data->GetEntry(i); |
||
3363 | |||
3364 | // If our data point is inside the TDC window |
||
3365 | if( ((double)evtdata.tdcdata[j]/tdctimeconversion >= rangetdc[0]) && ((double)evtdata.tdcdata[j]/tdctimeconversion <= rangetdc[1]) ) |
||
3366 | { |
||
3367 | k++; |
||
3368 | m += evtdata.adcdata[j]; |
||
3369 | } |
||
3370 | } |
||
3371 | |||
3372 | integralCount[n-1] += ((double)m)/((double)k); |
||
3373 | if(n == 1) |
||
3374 | { |
||
3375 | xsurfmin = evtheader.xpos; |
||
3376 | ysurfmin = evtheader.ypos; |
||
3377 | } |
||
3378 | surfx[n-1] = (double)(evtheader.xpos-xsurfmin)*lenconversion; |
||
3379 | surfy[n-1] = (double)(evtheader.ypos-ysurfmin)*lenconversion; |
||
3380 | |||
3381 | /* if( n == (((files->GetSize())*zProg)/20)+1 ) // divide by 20 because files->GetSize() gives a double value of the files selected |
||
3382 | { |
||
3383 | progVal = (float)n; |
||
3384 | curProgress->SetPosition(progVal); |
||
3385 | zProg++; |
||
3386 | printf("Progress = %lf\n", progVal); |
||
3387 | }*/ |
||
3388 | |||
3389 | delete inroot; |
||
3390 | } |
||
3391 | } |
||
3392 | |||
3393 | busyLabel->Disable(); |
||
3394 | |||
3395 | nrentries = n; |
||
3396 | printf("%d files were selected.\n", nrentries); |
||
3397 | |||
3398 | for(int i = 0; i < nrentries; i++) |
||
3399 | { |
||
3400 | // printf("At position (%d,%d), the ADC integral is: %lf.\n", surfx[i], surfy[i], integralCount[i]); |
||
3401 | gScan2D->SetPoint(i, surfx[i], surfy[i], integralCount[i]); |
||
3402 | } |
||
3403 | gCanvas->cd(); |
||
3404 | gScan2D->Draw("COLZ"); |
||
3405 | |||
3406 | gCanvas->Modified(); |
||
3407 | gCanvas->Update(); |
||
3408 | |||
3409 | gScan2D->GetXaxis()->SetTitle("X [#mum]"); |
||
3410 | gScan2D->GetXaxis()->CenterTitle(kTRUE); |
||
3411 | gScan2D->GetXaxis()->SetLabelSize(0.022); |
||
3412 | gScan2D->GetXaxis()->SetRangeUser(surfx[0], surfx[nrentries-1]); |
||
3413 | // j = 500+(int)((surfx[nrentries-1]-surfx[0])/(surfx[1]-surfx[0])); |
||
3414 | // if(j > 510) j = 510; |
||
3415 | gScan2D->GetXaxis()->SetNdivisions(510, kTRUE); |
||
3416 | gScan2D->GetYaxis()->SetTitle("Y [#mum]"); |
||
3417 | gScan2D->GetYaxis()->SetTitleOffset(1.3); |
||
3418 | gScan2D->GetYaxis()->CenterTitle(kTRUE); |
||
3419 | gScan2D->GetYaxis()->SetLabelSize(0.022); |
||
3420 | gScan2D->GetYaxis()->SetRangeUser(surfy[0], surfy[nrentries-1]); |
||
3421 | // j = 500+(int)((surfy[nrentries-1]-surfy[0])/(surfy[(int)((surfx[nrentries-1]-surfx[0])/(surfx[1]-surfx[0])+1)]-surfy[0])); |
||
3422 | // if(j > 510) j = 510; |
||
3423 | gScan2D->GetYaxis()->SetNdivisions(510, kTRUE); |
||
3424 | |||
3425 | TGaxis *yax = (TGaxis*)gScan2D->GetYaxis(); |
||
3426 | yax->SetMaxDigits(4); |
||
3427 | |||
3428 | if(!cleanPlots) |
||
3429 | gScan2D->SetTitle("Surface scan"); |
||
3430 | else |
||
3431 | gScan2D->SetTitle(); |
||
3432 | |||
3433 | // TPaletteAxis *gpalette = (TPaletteAxis*)gScan2D->GetListOfFunctions()->FindObject("palette"); |
||
3434 | // gpalette->SetLabelSize(0.022); |
||
3435 | |||
3436 | gCanvas->Modified(); |
||
3437 | gCanvas->Update(); |
||
3438 | |||
3439 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
3440 | sprintf(exportname, "%s_surfscan.pdf", ctemp); |
||
3441 | gCanvas->SaveAs(exportname); |
||
3442 | } |
||
3443 | } |
||
3444 | else |
||
3445 | { |
||
3446 | printf("To make a 2D surface scan plot, select multiple root files.\n"); |
||
3447 | change2Dsurf->SetDown(kFALSE); |
||
3448 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_SURF); |
||
3449 | } |
||
3450 | |||
3451 | delete[] surfx; |
||
3452 | delete[] surfy; |
||
3453 | delete[] integralCount; |
||
3454 | } |
||
3455 | |||
3456 | // Change histogram when changing the channel |
||
3457 | void TGAppMainFrame::ChangeChannel() |
||
3458 | { |
||
3459 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
3460 | TList *files; |
||
3461 | |||
3462 | if( nrfiles > 0 ) |
||
3463 | { |
||
3464 | // check the newly selected file/files and return its name/their names |
||
3465 | files = new TList(); |
||
3466 | fileList->GetSelectedEntries(files); |
||
3467 | if(files) |
||
3468 | { |
||
3469 | for(int i = 0; i < (int)nrfiles; i++) |
||
3470 | { |
||
3471 | if(files->At(i)) |
||
3472 | { |
||
128 | f9daq | 3473 | if(debug) |
117 | f9daq | 3474 | printf("Filename: %s\n", files->At(i)->GetTitle()); |
3475 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
3476 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
3477 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
3478 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1); |
||
3479 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
3480 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2); |
||
3481 | } |
||
3482 | } |
||
3483 | } |
||
3484 | } |
||
3485 | } |
||
3486 | |||
3487 | // Setting a predetermined X range |
||
3488 | void TGAppMainFrame::SetHistRange() |
||
3489 | { |
||
3490 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
3491 | |||
3492 | if(nrfiles > 0) |
||
3493 | { |
||
3494 | TList *files; |
||
3495 | files = new TList(); |
||
3496 | fileList->GetSelectedEntries(files); |
||
3497 | if(files) |
||
3498 | { |
||
3499 | for(int i = 0; i < (int)nrfiles; i++) |
||
3500 | { |
||
3501 | if(files->At(i)) |
||
3502 | { |
||
128 | f9daq | 3503 | if(debug) |
117 | f9daq | 3504 | printf("Filename: %s\n", files->At(i)->GetTitle()); |
3505 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
3506 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
3507 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
3508 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1); |
||
3509 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
3510 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2); |
||
3511 | } |
||
3512 | } |
||
3513 | } |
||
3514 | } |
||
3515 | } |
||
3516 | |||
3517 | // Changing the histogram type to display |
||
3518 | void TGAppMainFrame::ChangeHisttype(int type) |
||
3519 | { |
||
3520 | TGTextButton *pressedB = new TGTextButton(); |
||
3521 | int menuID = 0; |
||
3522 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
3523 | |||
3524 | // ADC histogram |
||
3525 | if(type == 0) |
||
3526 | { |
||
3527 | pressedB = changeADC; |
||
3528 | menuID = M_ANALYSIS_HISTTYPE_1DADC; |
||
3529 | |||
3530 | changeTDC->SetDown(kFALSE); |
||
3531 | changeADCTDC->SetDown(kFALSE); |
||
3532 | change2Dsurf->SetDown(kFALSE); |
||
3533 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC); |
||
3534 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D); |
||
3535 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_SURF); |
||
3536 | } |
||
3537 | // TDC histogram |
||
3538 | else if(type == 1) |
||
3539 | { |
||
3540 | pressedB = changeTDC; |
||
3541 | menuID = M_ANALYSIS_HISTTYPE_1DTDC; |
||
3542 | |||
3543 | changeADC->SetDown(kFALSE); |
||
3544 | changeADCTDC->SetDown(kFALSE); |
||
3545 | change2Dsurf->SetDown(kFALSE); |
||
3546 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
3547 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D); |
||
3548 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_SURF); |
||
3549 | } |
||
3550 | // ADC vs. TDC histogram |
||
3551 | else if(type == 2) |
||
3552 | { |
||
3553 | pressedB = changeADCTDC; |
||
3554 | menuID = M_ANALYSIS_HISTTYPE_2D; |
||
3555 | |||
3556 | changeADC->SetDown(kFALSE); |
||
3557 | changeTDC->SetDown(kFALSE); |
||
3558 | change2Dsurf->SetDown(kFALSE); |
||
3559 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
3560 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC); |
||
3561 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_SURF); |
||
3562 | } |
||
3563 | // Surface scan plot |
||
3564 | else if(type == 3) |
||
3565 | { |
||
3566 | pressedB = change2Dsurf; |
||
3567 | menuID = M_ANALYSIS_HISTTYPE_SURF; |
||
3568 | |||
3569 | changeADC->SetDown(kFALSE); |
||
3570 | changeTDC->SetDown(kFALSE); |
||
3571 | changeADCTDC->SetDown(kFALSE); |
||
3572 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
3573 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC); |
||
3574 | fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D); |
||
3575 | } |
||
3576 | |||
3577 | if( fMenuHisttype->IsEntryChecked(menuID) ) |
||
3578 | { |
||
3579 | pressedB->SetDown(kFALSE); |
||
3580 | fMenuHisttype->UnCheckEntry(menuID); |
||
3581 | } |
||
3582 | else if( !fMenuHisttype->IsEntryChecked(menuID) ) |
||
3583 | { |
||
3584 | pressedB->SetDown(kTRUE); |
||
3585 | fMenuHisttype->CheckEntry(menuID); |
||
3586 | } |
||
3587 | |||
3588 | if(nrfiles > 0) |
||
3589 | { |
||
3590 | // Still need to add the switch!!! |
||
3591 | TList *files; |
||
3592 | files = new TList(); |
||
3593 | fileList->GetSelectedEntries(files); |
||
3594 | |||
3595 | if(type < 3) |
||
3596 | DisplayHistogram( (char*)(files->At(0)->GetTitle()), type); |
||
3597 | else if(type == 3) |
||
3598 | MakeSurfPlot( files ); |
||
3599 | } |
||
3600 | } |
||
3601 | |||
3602 | // Changing the histogram type to display |
||
3603 | void TGAppMainFrame::HistogramExport() |
||
3604 | { |
||
3605 | unsigned int nrfiles = fileList->GetNumberOfEntries(); |
||
3606 | TList *files; |
||
3607 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
3608 | |||
3609 | char exportname[256]; |
||
3610 | char ctemp[256]; |
||
3611 | |||
3612 | if(nrfiles > 0) |
||
3613 | { |
||
3614 | files = new TList(); |
||
3615 | fileList->GetSelectedEntries(files); |
||
3616 | if(files) |
||
3617 | { |
||
3618 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_SURF) ) // for the surface scan, the plot from all selected files is already created |
||
3619 | { |
||
3620 | remove_from_last((char*)files->At(0)->GetTitle(), '_', ctemp); |
||
3621 | sprintf(exportname, "%s_surfscan.pdf", ctemp); |
||
3622 | gCanvas->SaveAs(exportname); |
||
3623 | } |
||
3624 | else |
||
3625 | { |
||
3626 | for(int i = 0; i < (int)nrfiles; i++) |
||
3627 | { |
||
3628 | if(files->At(i)) |
||
3629 | { |
||
3630 | remove_ext((char*)files->At(i)->GetTitle(), ctemp); |
||
3631 | |||
128 | f9daq | 3632 | if(debug) |
117 | f9daq | 3633 | printf("Filename: %s\n", files->At(i)->GetTitle()); |
3634 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) ) |
||
3635 | { |
||
3636 | sprintf(exportname, "%s_adc%d.pdf", ctemp, (int)selectCh->GetNumber()); |
||
3637 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0); |
||
3638 | } |
||
3639 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) ) |
||
3640 | { |
||
3641 | sprintf(exportname, "%s_tdc%d.pdf", ctemp, (int)selectCh->GetNumber()); |
||
3642 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1); |
||
3643 | } |
||
3644 | else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) ) |
||
3645 | { |
||
3646 | sprintf(exportname, "%s_adctdc%d.pdf", ctemp, (int)selectCh->GetNumber()); |
||
3647 | DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2); |
||
3648 | } |
||
3649 | |||
3650 | gCanvas->SaveAs(exportname); |
||
3651 | } |
||
3652 | } |
||
3653 | } |
||
3654 | } |
||
3655 | } |
||
3656 | } |
||
3657 | |||
3658 | //--------------------------------------------------------------- |
||
3659 | // Main window constructor definition (& layout) |
||
3660 | |||
3661 | TGAppMainFrame::TGAppMainFrame(const TGWindow *p, int w, int h) |
||
3662 | { |
||
3663 | gDaq = new daq(); |
||
3664 | gScopeDaq = new daqscope(); |
||
3665 | |||
3666 | // Define the main window and menubar |
||
3667 | fMain = new TGMainFrame(p, w, h, kVerticalFrame); // vertical frame split into menubar and main frame |
||
3668 | fMenuBar = new TGMdiMenuBar(fMain, 10, 10); // just prepare menubar, draw it with InitMenu() |
||
3669 | fMain->AddFrame(fMenuBar, new TGLayoutHints(kLHintsTop | kLHintsExpandX)); |
||
3670 | |||
3671 | // Define the main frame where opened subwindows will appear |
||
3672 | fMainFrame = new TGMdiMainFrame(fMain, fMenuBar, 300, 300); |
||
3673 | fMain->AddFrame(fMainFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY)); |
||
3674 | |||
3675 | // Initialize the menubar the initial measurement layout subwindows and display the main window |
||
3676 | InitMenu(); |
||
3677 | MeasurementLayout(); |
||
3678 | fMain->SetWindowName(WINDOW_NAME); |
||
3679 | fMain->MapSubwindows(); |
||
3680 | fMain->MapWindow(); |
||
3681 | fMain->Layout(); |
||
3682 | GetPosition(); |
||
3683 | GetVoltOut(); |
||
3684 | } |
||
3685 | |||
3686 | //--------------------------------------------------------------- |
||
3687 | // Event handler for menubar actions |
||
3688 | |||
3689 | void TGAppMainFrame::HandleMenu(Int_t id) |
||
3690 | { |
||
3691 | TList *files; |
||
3692 | |||
3693 | switch (id) { |
||
3694 | case M_FILE_NEW: |
||
3695 | // Clear any values and histogram |
||
3696 | break; |
||
3697 | |||
3698 | case M_FILE_EXIT: |
||
3699 | CloseWindow(); |
||
3700 | break; |
||
3701 | |||
3702 | case M_ANALYSIS_HISTTYPE_1DADC: |
||
3703 | // Toggles the ADC button |
||
3704 | ChangeHisttype(0); |
||
3705 | break; |
||
3706 | |||
3707 | case M_ANALYSIS_HISTTYPE_1DTDC: |
||
3708 | ChangeHisttype(1); |
||
3709 | break; |
||
3710 | |||
3711 | case M_ANALYSIS_HISTTYPE_2D: |
||
3712 | ChangeHisttype(2); |
||
3713 | break; |
||
3714 | |||
3715 | case M_ANALYSIS_HISTTYPE_SURF: |
||
3716 | ChangeHisttype(3); |
||
3717 | break; |
||
3718 | |||
3719 | case M_ANALYSIS_FIT: |
||
3720 | // Fit spectrum |
||
3721 | files = new TList(); |
||
3722 | fileList->GetSelectedEntries(files); |
||
3723 | |||
3724 | if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) && (files->GetSize() > 0) ) |
||
3725 | FitSpectrum(files, 1); |
||
3726 | break; |
||
3727 | |||
3728 | case M_ANALYSIS_FITSEL: |
||
3729 | // Fit all spectra |
||
3730 | files = new TList(); |
||
3731 | fileList->GetSelectedEntries(files); |
||
3732 | |||
3733 | if( (fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC)) && (files->GetSize() > 1) ) |
||
3734 | FitSpectrum(files, files->GetSize()); |
||
3735 | break; |
||
3736 | |||
3737 | case M_ANALYSIS_INTEGX: |
||
3738 | // Integrate the current spectra |
||
3739 | files = new TList(); |
||
3740 | fileList->GetSelectedEntries(files); |
||
3741 | |||
3742 | IntegSpectrum(files, 1); |
||
3743 | break; |
||
3744 | |||
3745 | case M_ANALYSIS_INTEGY: |
||
3746 | // Integrate the current spectra |
||
3747 | files = new TList(); |
||
3748 | fileList->GetSelectedEntries(files); |
||
3749 | |||
3750 | IntegSpectrum(files, 2); |
||
3751 | break; |
||
3752 | |||
128 | f9daq | 3753 | case M_ANALYSIS_PHOTMU: |
3754 | // Integrate the current spectra and calculate mean of detected photons: mu = -log(Nped/Ntot) |
||
3755 | files = new TList(); |
||
3756 | fileList->GetSelectedEntries(files); |
||
3757 | |||
3758 | PhotonMu(files); |
||
3759 | break; |
||
3760 | |||
3761 | case M_TOOLS_FIELDPOINT: |
||
3762 | OpenWindow(1); |
||
3763 | break; |
||
3764 | |||
117 | f9daq | 3765 | case M_WINDOW_HOR: |
3766 | fMainFrame->TileHorizontal(); |
||
3767 | break; |
||
3768 | |||
3769 | case M_WINDOW_VERT: |
||
3770 | fMainFrame->TileVertical(); |
||
3771 | break; |
||
3772 | |||
3773 | case M_HELP_ABOUT: |
||
3774 | About(); |
||
3775 | break; |
||
3776 | |||
3777 | default: |
||
3778 | fMainFrame->SetCurrent(id); |
||
3779 | break; |
||
3780 | } |
||
3781 | } |
||
3782 | |||
3783 | //--------------------------------------------------------------- |
||
3784 | // Initialize the main window menu |
||
3785 | |||
3786 | void TGAppMainFrame::InitMenu() |
||
3787 | { |
||
3788 | fMenuBarItemLayout = new TGLayoutHints(kLHintsTop | kLHintsLeft, 0, 4, 0, 0); |
||
3789 | |||
3790 | // Popup menu in menubar for File controls |
||
3791 | fMenuFile = new TGPopupMenu(gClient->GetRoot()); // adds a new popup menu to the menubar |
||
3792 | fMenuFile->AddEntry(new TGHotString("&New Measurement"), M_FILE_NEW); |
||
3793 | fMenuFile->AddSeparator(); |
||
3794 | fMenuFile->AddEntry(new TGHotString("E&xit"), M_FILE_EXIT); |
||
3795 | |||
3796 | // Popup menu in menubar for Analysis controls |
||
3797 | fMenuHisttype = new TGPopupMenu(gClient->GetRoot()); // adds a cascade menu that will be incorporated into analysis controls |
||
3798 | fMenuHisttype->AddEntry(new TGHotString("1D &ADC histogram"), M_ANALYSIS_HISTTYPE_1DADC); |
||
3799 | fMenuHisttype->AddEntry(new TGHotString("1D &TDC histogram"), M_ANALYSIS_HISTTYPE_1DTDC); |
||
3800 | fMenuHisttype->AddEntry(new TGHotString("&2D ADC vs. TDC histogram"), M_ANALYSIS_HISTTYPE_2D); |
||
3801 | fMenuHisttype->AddEntry(new TGHotString("2D &surface scan plot"), M_ANALYSIS_HISTTYPE_SURF); |
||
3802 | |||
3803 | fMenuAnalysis = new TGPopupMenu(gClient->GetRoot()); // adds a new popup menu to the menubar |
||
3804 | fMenuAnalysis->AddPopup(new TGHotString("&Histogram type"), fMenuHisttype); |
||
3805 | |||
3806 | fMenuAnalysis->AddEntry(new TGHotString("&Fit spectrum"), M_ANALYSIS_FIT); |
||
3807 | fMenuAnalysis->AddEntry(new TGHotString("Fit &all selected"), M_ANALYSIS_FITSEL); |
||
3808 | fMenuAnalysis->AddEntry(new TGHotString("Integrate spectrum (&X direction)"), M_ANALYSIS_INTEGX); |
||
3809 | fMenuAnalysis->AddEntry(new TGHotString("Integrate spectrum (&Y direction)"), M_ANALYSIS_INTEGY); |
||
128 | f9daq | 3810 | fMenuAnalysis->AddEntry(new TGHotString("Relative &PDE"), M_ANALYSIS_PHOTMU); |
117 | f9daq | 3811 | |
128 | f9daq | 3812 | // Popup menu in menubar for External tools |
3813 | fMenuTools = new TGPopupMenu(gClient->GetRoot()); // adds a new popup menu to the menubar |
||
3814 | fMenuTools->AddEntry(new TGHotString("&Fieldpoint temperature sensor"), M_TOOLS_FIELDPOINT); |
||
3815 | |||
117 | f9daq | 3816 | // Popup menu in menubar for Window controls |
3817 | fMenuWindow = new TGPopupMenu(gClient->GetRoot()); // adds a new popup menu to the menubar |
||
3818 | fMenuWindow->AddEntry(new TGHotString("Tile &Horizontally"), M_WINDOW_HOR); |
||
3819 | fMenuWindow->AddEntry(new TGHotString("Tile &Vertically"), M_WINDOW_VERT); |
||
3820 | fMenuWindow->AddPopup(new TGHotString("&Windows"), fMainFrame->GetWinListMenu()); |
||
3821 | |||
3822 | // Popup menu in menubar for Help controls |
||
3823 | fMenuHelp = new TGPopupMenu(gClient->GetRoot()); |
||
3824 | fMenuHelp->AddEntry(new TGHotString("&About"), M_HELP_ABOUT); |
||
3825 | |||
3826 | // Connect all menu items with actions - handled by HandleMenu() |
||
3827 | fMenuFile->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
||
3828 | fMenuAnalysis->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
||
128 | f9daq | 3829 | fMenuTools->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
117 | f9daq | 3830 | fMenuWindow->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
3831 | fMenuHelp->Connect("Activated(Int_t)", "TGAppMainFrame", this, "HandleMenu(Int_t)"); |
||
3832 | |||
3833 | // Draw the created popup menus on the menubar |
||
3834 | fMenuBar->AddPopup(new TGHotString("&File"), fMenuFile, fMenuBarItemLayout); |
||
3835 | fMenuBar->AddPopup(new TGHotString("&Analysis"),fMenuAnalysis,fMenuBarItemLayout); |
||
128 | f9daq | 3836 | fMenuBar->AddPopup(new TGHotString("&Tools"),fMenuTools,fMenuBarItemLayout); |
117 | f9daq | 3837 | fMenuBar->AddPopup(new TGHotString("&Windows"),fMenuWindow,fMenuBarItemLayout); |
3838 | fMenuBar->AddPopup(new TGHotString("&Help"), fMenuHelp, fMenuBarItemLayout); |
||
3839 | } |
||
3840 | |||
3841 | //--------------------------------------------------------------- |
||
3842 | // Set the measurement subwindow layout |
||
3843 | |||
3844 | void TGAppMainFrame::MeasurementLayout() |
||
3845 | { |
||
3846 | TGMdiFrame *mdiFrame; |
||
3847 | |||
3848 | // Generic horizontal and vertical frames |
||
3849 | TGHorizontalFrame *fH1, *fH2, *fH3; |
||
3850 | TGVerticalFrame *fV1; |
||
3851 | TGGroupFrame *fG1; |
||
3852 | TGLabel *lab; |
||
3853 | TGCompositeFrame *fT1; |
||
3854 | |||
3855 | // Sizes of internal group and subwindow structures |
||
3856 | int subwin[2]; |
||
3857 | int subgroup[2]; |
||
3858 | |||
3859 | // Settings pane --------------------------------------------------------------------------- |
||
3860 | subwin[0] = (winWidth/6)-5; subwin[1] = 3*((winHeight/5)-5)-10; |
||
3861 | settingsPane = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
3862 | mdiFrame = settingsPane->GetMdiFrame(); |
||
3863 | |||
3864 | // Check button to toggle voltage scan |
||
3865 | voltscanOn = new TGCheckButton(mdiFrame, "Voltage scan ON/OFF"); |
||
3866 | voltscanOn->Resize(50,22); |
||
3867 | voltscanOn->SetState(kButtonUp); |
||
3868 | mdiFrame->AddFrame(voltscanOn, f0centerx); |
||
3869 | |||
3870 | // Check button to toggle surface scan |
||
3871 | surfscanOn = new TGCheckButton(mdiFrame, "Surface scan ON/OFF"); |
||
3872 | surfscanOn->Resize(50,22); |
||
3873 | surfscanOn->SetState(kButtonUp); |
||
3874 | mdiFrame->AddFrame(surfscanOn, f0centerx); |
||
3875 | |||
3876 | // Check button to toggle Z direction scan |
||
3877 | zscanOn = new TGCheckButton(mdiFrame, "Z-axis scan ON/OFF"); |
||
3878 | zscanOn->Resize(50,22); |
||
3879 | zscanOn->SetState(kButtonUp); |
||
3880 | mdiFrame->AddFrame(zscanOn, f0centerx); |
||
3881 | |||
3882 | // Check button to toggle (open) the histogram window |
||
3883 | // histogramOn = new TGCheckButton(mdiFrame, "Histogram display ON/OFF"); |
||
3884 | // histogramOn->Resize(50,22); |
||
3885 | // histogramOn->SetState(kButtonUp); |
||
3886 | // mdiFrame->AddFrame(histogramOn, f0centerx); |
||
3887 | |||
3888 | subgroup[0] = subwin[0]-10; |
||
3889 | // Hard limit for maximum voltage we can set |
||
3890 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3891 | lab = new TGLabel(fH1, "Voltage limit:"); |
||
3892 | fH1->AddFrame(lab, f0center2d); |
||
3893 | vHardlimit = new TGNumberEntry(fH1, 70.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
3894 | vHardlimit->Resize(80,22); |
||
3895 | fH1->AddFrame(vHardlimit, f0center2d); |
||
3896 | mdiFrame->AddFrame(fH1, f2); |
||
3897 | |||
3898 | // Number of used channels |
||
3899 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3900 | lab = new TGLabel(fH1, "Nr. of channels:"); |
||
3901 | fH1->AddFrame(lab, f0center2d); |
||
3902 | NCH = new TGNumberEntry(fH1, 1, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 1, 8); |
||
3903 | NCH->Resize(40,22); |
||
3904 | fH1->AddFrame(NCH, f0center2d); |
||
3905 | mdiFrame->AddFrame(fH1, f2); |
||
3906 | |||
3907 | // Check button to toggle plots with additional information or clean plots |
||
3908 | cleanOn = new TGCheckButton(mdiFrame, "Clean plots ON/OFF"); |
||
3909 | cleanOn->Resize(50,22); |
||
3910 | cleanOn->SetState(kButtonDown); |
||
3911 | cleanPlots = 1; |
||
3912 | mdiFrame->AddFrame(cleanOn, f0centerx); |
||
3913 | |||
3914 | // Button and textbox to enter the oscilloscope IP address |
||
3915 | lab = new TGLabel(mdiFrame, "Scope IP:"); |
||
3916 | mdiFrame->AddFrame(lab, f0); |
||
3917 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3918 | oscIP = new TGTextEntry(fH1, "178.172.43.157"); |
||
3919 | oscIP->Resize(110,22); |
||
3920 | fH1->AddFrame(oscIP, f0); |
||
3921 | oscConnect = new TGTextButton(fH1, "Connect"); |
||
3922 | oscConnect->SetTextJustify(36); |
||
3923 | oscConnect->SetWrapLength(-1); |
||
3924 | oscConnect->Resize(60,22); |
||
3925 | fH1->AddFrame(oscConnect, f0); |
||
3926 | oscOn = 0; |
||
3927 | mdiFrame->AddFrame(fH1, f2); |
||
3928 | |||
3929 | // Laser settings (freq., tune, ND filter) |
||
3930 | lab = new TGLabel(mdiFrame, "Laser settings:"); |
||
3931 | mdiFrame->AddFrame(lab, f0); |
||
3932 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3933 | laserInfo = new TGTextEntry(fH1, "kHz, tune, ND"); |
||
3934 | fH1->AddFrame(laserInfo, f2); |
||
3935 | mdiFrame->AddFrame(fH1, f2); |
||
3936 | |||
127 | f9daq | 3937 | // Chamber temperature (will only be manually set until we can get it directly from the chamber) |
3938 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3939 | lab = new TGLabel(fH1, "Chamber temp.:"); |
||
3940 | fH1->AddFrame(lab, f0center2d); |
||
3941 | chtemp = new TGNumberEntry(fH1, 25.0, 6, 999, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -70., 150.); |
||
3942 | chtemp->Resize(60,22); |
||
3943 | fH1->AddFrame(chtemp, f0center2d); |
||
3944 | mdiFrame->AddFrame(fH1, f2); |
||
128 | f9daq | 3945 | |
3946 | // Incidence angle (will only be manually set until we can make it motorized) |
||
3947 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
3948 | lab = new TGLabel(fH1, "Incid. angle:"); |
||
3949 | fH1->AddFrame(lab, f0center2d); |
||
3950 | incangle = new TGNumberEntry(fH1, 0.0, 6, 999, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -180., 180.); |
||
3951 | incangle->Resize(60,22); |
||
3952 | fH1->AddFrame(incangle, f0center2d); |
||
3953 | mdiFrame->AddFrame(fH1, f2); |
||
127 | f9daq | 3954 | |
117 | f9daq | 3955 | mdiFrame->SetMdiHints(kMdiMinimize); |
3956 | mdiFrame->SetWindowName("Settings pane"); |
||
3957 | mdiFrame->MapSubwindows(); |
||
3958 | mdiFrame->Layout(); |
||
3959 | mdiFrame->Move(0,0); |
||
3960 | // Settings pane --------------------------------------------------------------------------- |
||
3961 | |||
3962 | // Main window ----------------------------------------------------------------------------- |
||
3963 | subwin[0] = 3*((winWidth/6)-5); subwin[1] = 3*((winHeight/5)-5)-10; |
||
3964 | mainSubwindow = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
3965 | mdiFrame = mainSubwindow->GetMdiFrame(); |
||
3966 | |||
3967 | // Voltage and position tab |
||
3968 | subgroup[0] = 2*subwin[0]/5-12; |
||
3969 | subgroup[1] = (subwin[1]+15)/2+5; |
||
3970 | setTab = new TGTab(mdiFrame, subgroup[0], subgroup[1]); |
||
3971 | |||
3972 | fT1 = setTab->AddTab("Voltage + Position"); |
||
3973 | |||
3974 | fH1 = new TGHorizontalFrame(fT1, subwin[0], subgroup[1], kFixedHeight); |
||
3975 | // Left pane (Bias voltage controls) |
||
3976 | fV1 = new TGVerticalFrame(fH1, subgroup[0], subgroup[1], kFixedWidth | kFixedHeight); |
||
3977 | fG1 = new TGGroupFrame(fV1, "Bias voltage controls"); |
||
3978 | |||
3979 | // Output voltage supply channel |
||
3980 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
3981 | lab = new TGLabel(fH2, "Output channel:"); |
||
3982 | fH2->AddFrame(lab, f0center2d); |
||
3983 | vOutCh = new TGComboBox(fH2, 200); |
||
3984 | vOutCh->AddEntry("1", 0); |
||
3985 | vOutCh->AddEntry("2", 1); |
||
3986 | vOutCh->AddEntry("3", 2); |
||
3987 | vOutCh->AddEntry("4", 3); |
||
3988 | vOutCh->AddEntry("5", 4); |
||
3989 | vOutCh->AddEntry("6", 5); |
||
3990 | vOutCh->AddEntry("7", 6); |
||
3991 | vOutCh->AddEntry("8", 7); |
||
3992 | vOutCh->AddEntry("101", 8); |
||
3993 | vOutCh->AddEntry("102", 9); |
||
3994 | vOutCh->AddEntry("103", 10); |
||
3995 | vOutCh->AddEntry("104", 11); |
||
3996 | vOutCh->AddEntry("105", 12); |
||
3997 | vOutCh->AddEntry("106", 13); |
||
3998 | vOutCh->AddEntry("107", 14); |
||
3999 | vOutCh->AddEntry("108", 15); |
||
4000 | vOutCh->Resize(50,22); |
||
4001 | vOutCh->Select(0); |
||
4002 | fH2->AddFrame(vOutCh, f0center2d); |
||
4003 | fG1->AddFrame(fH2, f2); |
||
4004 | |||
4005 | // Output voltage setting |
||
4006 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4007 | lab = new TGLabel(fH2, "Output voltage:"); |
||
4008 | fH2->AddFrame(lab, f0center2d); |
||
4009 | vOut = new TGNumberEntry(fH2, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, 0, vHardlimit->GetNumber()); |
||
4010 | vOut->Resize(80,22); |
||
4011 | fH2->AddFrame(vOut, f0center2d); |
||
4012 | fG1->AddFrame(fH2, f2); |
||
4013 | |||
4014 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4015 | vOutOnOff = new TGCheckButton(fH2, "Output ON/OFF"); |
||
4016 | vOutOnOff->Resize(subgroup[0]-10,22); |
||
4017 | vOutOnOff->SetState(kButtonUp); |
||
4018 | fH2->AddFrame(vOutOnOff, f0centerx); |
||
4019 | fG1->AddFrame(fH2, f2); |
||
4020 | |||
4021 | // Set, get and reset voltage buttons |
||
4022 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4023 | fH3 = new TGHorizontalFrame(fH2, subgroup[0], 30); |
||
4024 | vOutSet = new TGTextButton(fH3, "Set"); |
||
4025 | vOutSet->SetTextJustify(36); |
||
4026 | vOutSet->SetWrapLength(-1); |
||
4027 | vOutSet->Resize(60,22); |
||
4028 | fH3->AddFrame(vOutSet, f0); |
||
4029 | vOutGet = new TGTextButton(fH3, "Get"); |
||
4030 | vOutGet->SetTextJustify(36); |
||
4031 | vOutGet->SetWrapLength(-1); |
||
4032 | vOutGet->Resize(60,22); |
||
4033 | fH3->AddFrame(vOutGet, f0); |
||
4034 | vOutReset = new TGTextButton(fH3, "Reset"); |
||
4035 | vOutReset->SetTextJustify(36); |
||
4036 | vOutReset->SetWrapLength(-1); |
||
4037 | vOutReset->Resize(60,22); |
||
4038 | fH3->AddFrame(vOutReset, f0); |
||
4039 | fH2->AddFrame(fH3, f0centerx); |
||
4040 | fG1->AddFrame(fH2, f2); |
||
4041 | |||
4042 | // Voltage scan controls |
||
4043 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4044 | lab = new TGLabel(fH2, "V (min):"); |
||
4045 | fH2->AddFrame(lab, f0center2d); |
||
4046 | vOutStart = new TGNumberEntry(fH2, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
4047 | vOutStart->Resize(80,22); |
||
4048 | fH2->AddFrame(vOutStart, f0center2d); |
||
4049 | fG1->AddFrame(fH2, f2); |
||
4050 | |||
4051 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4052 | lab = new TGLabel(fH2, "V (max):"); |
||
4053 | fH2->AddFrame(lab, f0center2d); |
||
4054 | vOutStop = new TGNumberEntry(fH2, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
4055 | vOutStop->Resize(80,22); |
||
4056 | fH2->AddFrame(vOutStop, f0center2d); |
||
4057 | fG1->AddFrame(fH2, f2); |
||
4058 | |||
4059 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4060 | lab = new TGLabel(fH2, "V (step):"); |
||
4061 | fH2->AddFrame(lab, f0center2d); |
||
4062 | vOutStep = new TGNumberEntry(fH2, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
4063 | vOutStep->Resize(80,22); |
||
4064 | fH2->AddFrame(vOutStep, f0center2d); |
||
4065 | fG1->AddFrame(fH2, f2); |
||
4066 | |||
4067 | fV1->AddFrame(fG1, f1); |
||
4068 | // Left pane (Bias voltage controls) |
||
4069 | fH1->AddFrame(fV1, f0); |
||
4070 | |||
4071 | // Right pane (Table position controls) |
||
4072 | subgroup[0] = 3*subwin[0]/5-12; |
||
4073 | fV1 = new TGVerticalFrame(fH1, subgroup[0], subgroup[1], kFixedWidth | kFixedHeight); |
||
4074 | fG1 = new TGGroupFrame(fV1, "Table position controls"); |
||
4075 | |||
4076 | // X, Y and Z positions |
||
4077 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4078 | lab = new TGLabel(fH2, "X:"); |
||
4079 | fH2->AddFrame(lab, f0center2d); |
||
4080 | xPos = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
4081 | xPos->Resize(80,22); |
||
4082 | fH2->AddFrame(xPos, f0center2d); |
||
4083 | |||
4084 | lab = new TGLabel(fH2, "Z (min):"); |
||
4085 | fH2->AddFrame(lab, f0center2d); |
||
4086 | zPosMin = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 375000); |
||
4087 | zPosMin->Resize(80,22); |
||
4088 | fH2->AddFrame(zPosMin, f0center2d); |
||
4089 | fG1->AddFrame(fH2, f2); |
||
4090 | |||
4091 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4092 | lab = new TGLabel(fH2, "Y:"); |
||
4093 | fH2->AddFrame(lab, f0center2d); |
||
4094 | yPos = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
4095 | yPos->Resize(80,22); |
||
4096 | fH2->AddFrame(yPos, f0center2d); |
||
4097 | |||
4098 | lab = new TGLabel(fH2, "Z (max):"); |
||
4099 | fH2->AddFrame(lab, f0center2d); |
||
4100 | zPosMax = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 375000); |
||
4101 | zPosMax->Resize(80,22); |
||
4102 | fH2->AddFrame(zPosMax, f0center2d); |
||
4103 | fG1->AddFrame(fH2, f2); |
||
4104 | |||
4105 | fH2 = new TGHorizontalFrame(fG1, subgroup[0] ,30); |
||
4106 | lab = new TGLabel(fH2, "Z:"); |
||
4107 | fH2->AddFrame(lab, f0center2d); |
||
4108 | zPos = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 375000); |
||
4109 | zPos->Resize(80,22); |
||
4110 | fH2->AddFrame(zPos, f0center2d); |
||
4111 | |||
4112 | lab = new TGLabel(fH2, "Z (step):"); |
||
4113 | fH2->AddFrame(lab, f0center2d); |
||
4114 | zPosStep = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
4115 | zPosStep->Resize(80,22); |
||
4116 | fH2->AddFrame(zPosStep, f0center2d); |
||
4117 | fG1->AddFrame(fH2, f2); |
||
4118 | |||
4119 | // Set, Get and Home the table position |
||
4120 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4121 | fH3 = new TGHorizontalFrame(fH2, subgroup[0], 30); |
||
4122 | positionSet = new TGTextButton(fH3, "Set"); |
||
4123 | positionSet->SetTextJustify(36); |
||
4124 | positionSet->SetWrapLength(-1); |
||
4125 | positionSet->Resize(60,22); |
||
4126 | fH3->AddFrame(positionSet, f0); |
||
4127 | positionGet = new TGTextButton(fH3, "Get"); |
||
4128 | positionGet->SetTextJustify(36); |
||
4129 | positionGet->SetWrapLength(-1); |
||
4130 | positionGet->Resize(60,22); |
||
4131 | fH3->AddFrame(positionGet, f0); |
||
4132 | positionHome = new TGTextButton(fH3, "Home"); |
||
4133 | positionHome->SetTextJustify(36); |
||
4134 | positionHome->SetWrapLength(-1); |
||
4135 | positionHome->Resize(60,22); |
||
4136 | fH3->AddFrame(positionHome, f0); |
||
4137 | fH2->AddFrame(fH3, f0centerx); |
||
4138 | fG1->AddFrame(fH2, f2); |
||
4139 | |||
4140 | // Position scan controls |
||
4141 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4142 | lab = new TGLabel(fH2, "X (min):"); |
||
4143 | fH2->AddFrame(lab, f0center2d); |
||
4144 | xPosMin = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
4145 | xPosMin->Resize(80,22); |
||
4146 | fH2->AddFrame(xPosMin, f0center2d); |
||
4147 | |||
4148 | lab = new TGLabel(fH2, "Y (min):"); |
||
4149 | fH2->AddFrame(lab, f0center2d); |
||
4150 | yPosMin = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
4151 | yPosMin->Resize(80,22); |
||
4152 | fH2->AddFrame(yPosMin, f0center2d); |
||
4153 | fG1->AddFrame(fH2, f2); |
||
4154 | |||
4155 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4156 | lab = new TGLabel(fH2, "X (max):"); |
||
4157 | fH2->AddFrame(lab, f0center2d); |
||
4158 | xPosMax = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
4159 | xPosMax->Resize(80,22); |
||
4160 | fH2->AddFrame(xPosMax, f0center2d); |
||
4161 | |||
4162 | lab = new TGLabel(fH2, "Y (max):"); |
||
4163 | fH2->AddFrame(lab, f0center2d); |
||
4164 | yPosMax = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber, TGNumberFormat::kNELLimitMinMax, -100, 215000); |
||
4165 | yPosMax->Resize(80,22); |
||
4166 | fH2->AddFrame(yPosMax, f0center2d); |
||
4167 | fG1->AddFrame(fH2, f2); |
||
4168 | |||
4169 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4170 | lab = new TGLabel(fH2, "X (step):"); |
||
4171 | fH2->AddFrame(lab, f0center2d); |
||
4172 | xPosStep = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
4173 | xPosStep->Resize(80,22); |
||
4174 | fH2->AddFrame(xPosStep, f0center2d); |
||
4175 | |||
4176 | lab = new TGLabel(fH2, "Y (step):"); |
||
4177 | fH2->AddFrame(lab, f0center2d); |
||
4178 | yPosStep = new TGNumberEntry(fH2, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
4179 | yPosStep->Resize(80,22); |
||
4180 | fH2->AddFrame(yPosStep, f0center2d); |
||
4181 | fG1->AddFrame(fH2, f2); |
||
4182 | |||
4183 | fV1->AddFrame(fG1, f1); |
||
4184 | // Right pane (Table position controls) |
||
4185 | fH1->AddFrame(fV1, f0); |
||
4186 | fT1->AddFrame(fH1, f1); |
||
4187 | |||
4188 | // Waveform tab |
||
127 | f9daq | 4189 | fT1 = setTab->AddTab("Waveform analysis"); |
117 | f9daq | 4190 | fH1 = new TGHorizontalFrame(fT1, subwin[0], subgroup[1], kFixedHeight); |
127 | f9daq | 4191 | subgroup[0] = 1*subwin[0]/2-12; |
4192 | fV1 = new TGVerticalFrame(fH1, subgroup[0], subgroup[1]/3, kFixedWidth); |
||
117 | f9daq | 4193 | |
127 | f9daq | 4194 | fG1 = new TGGroupFrame(fV1, "Acquisition channel"); |
117 | f9daq | 4195 | |
127 | f9daq | 4196 | // Selection of channels |
4197 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 100); |
||
4198 | sCH[0] = new TGCheckButton(fH2, "CH1"); |
||
4199 | sCH[0]->Resize(50,22); |
||
4200 | sCH[0]->SetState(kButtonUp); |
||
4201 | fH2->AddFrame(sCH[0], f0centerx); |
||
4202 | sCH[1] = new TGCheckButton(fH2, "CH2"); |
||
4203 | sCH[1]->Resize(50,22); |
||
4204 | sCH[1]->SetState(kButtonUp); |
||
4205 | fH2->AddFrame(sCH[1], f0centerx); |
||
4206 | sCH[2] = new TGCheckButton(fH2, "CH3"); |
||
4207 | sCH[2]->Resize(50,22); |
||
4208 | sCH[2]->SetState(kButtonUp); |
||
4209 | fH2->AddFrame(sCH[2], f0centerx); |
||
4210 | sCH[3] = new TGCheckButton(fH2, "CH4"); |
||
4211 | sCH[3]->Resize(50,22); |
||
4212 | sCH[3]->SetState(kButtonUp); |
||
4213 | fH2->AddFrame(sCH[3], f0centerx); |
||
4214 | fG1->AddFrame(fH2, f0centerx); |
||
4215 | |||
4216 | // Selection of MATH channels |
||
4217 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 100); |
||
4218 | sCH[4] = new TGCheckButton(fH2, "MATH1"); |
||
4219 | sCH[4]->Resize(50,22); |
||
4220 | sCH[4]->SetState(kButtonUp); |
||
4221 | fH2->AddFrame(sCH[4], f0centerx); |
||
4222 | sCH[5] = new TGCheckButton(fH2, "MATH2"); |
||
4223 | sCH[5]->Resize(50,22); |
||
4224 | sCH[5]->SetState(kButtonUp); |
||
4225 | fH2->AddFrame(sCH[5], f0centerx); |
||
4226 | sCH[6] = new TGCheckButton(fH2, "MATH3"); |
||
4227 | sCH[6]->Resize(50,22); |
||
4228 | sCH[6]->SetState(kButtonUp); |
||
4229 | fH2->AddFrame(sCH[6], f0centerx); |
||
4230 | sCH[7] = new TGCheckButton(fH2, "MATH4"); |
||
4231 | sCH[7]->Resize(50,22); |
||
4232 | sCH[7]->SetState(kButtonUp); |
||
4233 | fH2->AddFrame(sCH[7], f0centerx); |
||
4234 | fG1->AddFrame(fH2, f0centerx); |
||
4235 | |||
4236 | fV1->AddFrame(fG1, f2); |
||
4237 | |||
4238 | // Selection of measurement type |
||
4239 | fH2 = new TGHorizontalFrame(fV1, subgroup[0], 30); |
||
4240 | lab = new TGLabel(fH2, "Scope use type:"); |
||
4241 | fH2->AddFrame(lab, f0center2d); |
||
4242 | sMeasType = new TGComboBox(fH2, 200); |
||
4243 | sMeasType->AddEntry("No waveform analysis", 0); |
||
4244 | sMeasType->AddEntry("Waveform acquisition", 1); |
||
4245 | sMeasType->AddEntry("Measurement", 2); |
||
4246 | sMeasType->Resize(150,22); |
||
4247 | sMeasType->Select(0); |
||
4248 | fH2->AddFrame(sMeasType, f0center2d); |
||
4249 | fV1->AddFrame(fH2, f2); |
||
4250 | |||
4251 | // Link waveform analysis to CAMAC acquisition |
||
4252 | sCamaclink = new TGCheckButton(fV1, "Link waveform to CAMAC acquisition"); |
||
4253 | sCamaclink->Resize(200,22); |
||
4254 | sCamaclink->SetState(kButtonUp); |
||
4255 | fV1->AddFrame(sCamaclink, f0centerx); |
||
4256 | |||
4257 | // Custom command interface for the scope |
||
4258 | lab = new TGLabel(fV1, "Custom scope command:"); |
||
4259 | fV1->AddFrame(lab, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,10,2) ); |
||
4260 | fH2 = new TGHorizontalFrame(fV1, subgroup[0], 30); |
||
4261 | scopeCommand = new TGTextEntry(fH2, ""); |
||
4262 | scopeCommand->Resize(subgroup[0]-45,22); |
||
4263 | fH2->AddFrame(scopeCommand, f2); |
||
4264 | sendScopeCustom = new TGTextButton(fH2, "Send"); |
||
4265 | sendScopeCustom->SetTextJustify(36); |
||
4266 | sendScopeCustom->SetWrapLength(-1); |
||
4267 | sendScopeCustom->Resize(80,22); |
||
4268 | fH2->AddFrame(sendScopeCustom, f0centery); |
||
4269 | fV1->AddFrame(fH2, f0); |
||
4270 | |||
4271 | // Return value for custom scope command |
||
4272 | lab = new TGLabel(fV1, "Return:"); |
||
4273 | fV1->AddFrame(lab, new TGLayoutHints(kLHintsLeft | kLHintsTop,2,2,10,2) ); |
||
4274 | scopeReturn = new TGTextEntry(fV1, ""); |
||
4275 | scopeReturn->Resize(subgroup[0],22); |
||
4276 | fV1->AddFrame(scopeReturn, f2); |
||
4277 | |||
4278 | fH1->AddFrame(fV1, f0); |
||
4279 | |||
4280 | // Wave measurement type |
||
4281 | fV1 = new TGVerticalFrame(fH1, subgroup[0], subgroup[1]/3, kFixedWidth); |
||
4282 | fH2 = new TGHorizontalFrame(fV1, subgroup[0], 30); |
||
4283 | lab = new TGLabel(fH2, "Meas. type:"); |
||
4284 | fH2->AddFrame(lab, f0center2d); |
||
4285 | sMeasgroup = new TGComboBox(fH2, 200); |
||
4286 | for(int i = 0; i < 11; i++) |
||
4287 | sMeasgroup->AddEntry(allMeasNames[i], i); |
||
4288 | sMeasgroup->Resize(150,22); |
||
4289 | sMeasgroup->Select(4); |
||
4290 | fH2->AddFrame(sMeasgroup, f0center2d); |
||
4291 | fV1->AddFrame(fH2, f2); |
||
4292 | |||
4293 | // Initialize current acquisition settings |
||
4294 | scopeInit = new TGTextButton(fV1, "Initialize scope"); |
||
4295 | scopeInit->SetTextJustify(36); |
||
4296 | scopeInit->SetWrapLength(-1); |
||
4297 | scopeInit->Resize(80,22); |
||
4298 | fV1->AddFrame(scopeInit, f0centerx); |
||
4299 | |||
4300 | fH1->AddFrame(fV1, f0); |
||
4301 | fT1->AddFrame(fH1, f1); |
||
4302 | |||
117 | f9daq | 4303 | mdiFrame->AddFrame(setTab, f0); |
4304 | |||
4305 | // Bottom pane (File controls) |
||
4306 | subgroup[0] = subwin[0]-20; |
||
4307 | subgroup[1] = subwin[1]/3-30; //2*(3*((winWidth/6)-5))/5+10; |
||
4308 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], subgroup[1] /*1*(3*((winWidth/6)-5))/5+15*/ , kFixedWidth | kFixedHeight); |
||
4309 | fG1 = new TGGroupFrame(fH1, "Event/Data file controls"); |
||
4310 | |||
4311 | // Number of events |
||
4312 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4313 | lab = new TGLabel(fH2, "Number of events:"); |
||
4314 | fH2->AddFrame(lab, f0centery); |
||
4315 | evtNum = new TGNumberEntry(fH2, 10000, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
||
4316 | evtNum->Resize(80,22); |
||
4317 | fH2->AddFrame(evtNum, f0centery); |
||
4318 | fG1->AddFrame(fH2, f2); |
||
4319 | |||
4320 | // Time stamp display |
||
4321 | fH2 = new TGHorizontalFrame(fG1,600,200); |
||
4322 | lab = new TGLabel(fH2, "Time stamp:"); |
||
4323 | fH2->AddFrame(lab, f0centery); |
||
4324 | timeStamp = new TGTextEntry(fH2, ""); |
||
4325 | timeStamp->Resize(440,22); |
||
4326 | timeStamp->SetState(kFALSE); // time stamp is read-only |
||
4327 | fH2->AddFrame(timeStamp, f0centery); |
||
4328 | fG1->AddFrame(fH2, f2); |
||
4329 | |||
4330 | // Save to file |
||
4331 | fH2 = new TGHorizontalFrame(fG1,600,200); |
||
4332 | lab = new TGLabel(fH2, "Save to file:"); |
||
4333 | fH2->AddFrame(lab, f0centery); |
||
4334 | char *cTemp; |
||
4335 | cTemp = new char[256]; |
||
4336 | sprintf(cTemp, "./results/test%s", histExt); |
||
4337 | fileName = new TGTextEntry(fH2, cTemp); |
||
4338 | delete[] cTemp; |
||
4339 | fileName->Resize(400,22); |
||
4340 | fileName->SetState(kFALSE); |
||
4341 | fH2->AddFrame(fileName, f0centery); |
||
4342 | saveFile = new TGTextButton(fH2, "..."); |
||
4343 | saveFile->SetTextJustify(36); |
||
4344 | saveFile->SetWrapLength(-1); |
||
4345 | saveFile->Resize(80,22); |
||
4346 | fH2->AddFrame(saveFile, f0centery); |
||
4347 | // mdiFrame->AddFrame(fH2, f0); |
||
4348 | fG1->AddFrame(fH2, f2); |
||
4349 | fH1->AddFrame(fG1, f1); |
||
4350 | // Bottom pane (File controls) |
||
4351 | mdiFrame->AddFrame(fH1, f0); |
||
4352 | |||
4353 | subgroup[0] = subwin[0]-70; |
||
4354 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
4355 | fH2 = new TGHorizontalFrame(fH1, 3*subgroup[0]/4, 30, kFixedWidth); |
||
4356 | measStart = new TGTextButton(fH2, "Start acquisition"); |
||
4357 | measStart->SetTextJustify(36); |
||
4358 | measStart->SetWrapLength(-1); |
||
4359 | measStart->Resize(80,22); |
||
4360 | fH2->AddFrame(measStart, f0center2d); |
||
4361 | |||
4362 | ULong_t fcolor; |
||
4363 | gClient->GetColorByName("red", fcolor); |
||
4364 | |||
4365 | busyLabel = new TGLabel(fH2, "Busy"); //, fTextGC->GetGC(), labelfont, kChildFrame); |
||
4366 | busyLabel->SetTextJustify(36); |
||
4367 | busyLabel->Resize(80,22); |
||
4368 | busyLabel->Disable(); |
||
4369 | busyLabel->SetTextColor(fcolor); |
||
4370 | fH2->AddFrame(busyLabel, f0center2d); |
||
4371 | |||
4372 | curProgress = new TGHProgressBar(fH2, TGProgressBar::kStandard, 150); |
||
4373 | curProgress->ShowPosition(); |
||
4374 | curProgress->SetRange(0,100); |
||
4375 | curProgress->SetBarColor("green"); |
||
4376 | fH2->AddFrame(curProgress, f0center2d); |
||
4377 | fH1->AddFrame(fH2, f0centerx); |
||
4378 | mdiFrame->AddFrame(fH1, f2); |
||
4379 | |||
4380 | mdiFrame->SetMdiHints(kMdiMinimize | kMdiMaximize); |
||
4381 | mdiFrame->SetWindowName("Main measurement window"); |
||
4382 | mdiFrame->MapSubwindows(); |
||
4383 | mdiFrame->Layout(); |
||
4384 | mdiFrame->Move((winWidth/6),0); |
||
4385 | // Main window ----------------------------------------------------------------------------- |
||
4386 | |||
4387 | // Histogram pane -------------------------------------------------------------------------- |
||
4388 | subwin[0] = 2*((winWidth/6)-5); subwin[1] = (int)(2.5*((winHeight/5)-5))-5; |
||
4389 | histogramPane = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
4390 | mdiFrame = histogramPane->GetMdiFrame(); |
||
4391 | |||
4392 | histCanvas = new TRootEmbeddedCanvas("histCanvas",mdiFrame,900,900); |
||
4393 | mdiFrame->AddFrame(histCanvas, f1); |
||
4394 | TCanvas *gCanvas = histCanvas->GetCanvas(); |
||
4395 | gCanvas->SetGridx(); |
||
4396 | gCanvas->SetGridy(); |
||
4397 | |||
4398 | mdiFrame->SetMdiHints(kMdiMinimize | kMdiMaximize); |
||
4399 | mdiFrame->SetWindowName("Histogram"); |
||
4400 | mdiFrame->MapSubwindows(); |
||
4401 | mdiFrame->Layout(); |
||
4402 | mdiFrame->Move(4*((winWidth/6)-5)+10,0); |
||
4403 | // Histogram pane -------------------------------------------------------------------------- |
||
4404 | |||
4405 | // Histogram file selection pane ----------------------------------------------------------- |
||
4406 | subwin[0] = 4*((winWidth/6)-5); subwin[1] = 2*((winHeight/5)-5)+15; |
||
4407 | histogramPaneFile = new TGMdiSubwindow(fMainFrame, subwin[0]+5, subwin[1]); |
||
4408 | mdiFrame = histogramPaneFile->GetMdiFrame(); |
||
4409 | |||
4410 | // Open browser for file selection |
||
4411 | subgroup[0] = subwin[0]-10; |
||
4412 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
4413 | lab = new TGLabel(fH1, "File selection:"); |
||
4414 | fH1->AddFrame(lab, f0centery); |
||
4415 | |||
4416 | selectDir = new TGTextButton(fH1, "..."); |
||
4417 | selectDir->SetTextJustify(36); |
||
4418 | selectDir->SetWrapLength(-1); |
||
4419 | selectDir->Resize(80,22); |
||
4420 | fH1->AddFrame(selectDir, f0centery); |
||
4421 | mdiFrame->AddFrame(fH1, f2); |
||
4422 | |||
4423 | // List view of the opened files |
||
4424 | fileList = new TGListBox(mdiFrame,1); |
||
4425 | fileList->GetVScrollbar(); |
||
128 | f9daq | 4426 | fileList->Resize(300, (3*subwin[1]/7)-10 ); |
117 | f9daq | 4427 | mdiFrame->AddFrame(fileList, f2); |
4428 | |||
4429 | // Multiple file selection toggle, previous/next controls and clear list |
||
4430 | fH1 = new TGHorizontalFrame(mdiFrame, subgroup[0], 30); |
||
4431 | multiSelect = new TGCheckButton(fH1, "Multiple file select"); |
||
4432 | multiSelect->Resize(50,22); |
||
4433 | multiSelect->SetState(kButtonUp); |
||
4434 | fH1->AddFrame(multiSelect, f0); |
||
4435 | |||
4436 | multiSelectAll = new TGCheckButton(fH1, "Select all listed files"); |
||
4437 | multiSelectAll->Resize(50,22); |
||
4438 | multiSelectAll->SetState(kButtonUp); |
||
4439 | fH1->AddFrame(multiSelectAll, f0); |
||
4440 | |||
4441 | TGTextButton *clearList = new TGTextButton(fH1, "Clear list"); |
||
4442 | clearList->SetTextJustify(36); |
||
4443 | clearList->SetWrapLength(-1); |
||
4444 | clearList->Resize(80,22); |
||
4445 | fH1->AddFrame(clearList, f0right); |
||
4446 | |||
4447 | nextFile = new TGTextButton(fH1, ">>"); |
||
4448 | nextFile->SetTextJustify(36); |
||
4449 | nextFile->SetWrapLength(-1); |
||
4450 | nextFile->Resize(80,22); |
||
4451 | fH1->AddFrame(nextFile, f0right); |
||
4452 | |||
4453 | prevFile = new TGTextButton(fH1, "<<"); |
||
4454 | prevFile->SetTextJustify(36); |
||
4455 | prevFile->SetWrapLength(-1); |
||
4456 | prevFile->Resize(80,22); |
||
4457 | fH1->AddFrame(prevFile, f0right); |
||
4458 | mdiFrame->AddFrame(fH1, f2); |
||
4459 | |||
128 | f9daq | 4460 | // Header information of opened file |
4461 | fG1 = new TGGroupFrame(mdiFrame, "Opened file header information"); |
||
4462 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4463 | lab = new TGLabel(fH1, "Time:"); |
||
4464 | fH1->AddFrame(lab, f0centery); |
||
4465 | disptime = new TGTextEntry(fH1, ""); |
||
4466 | disptime->Resize(440,22); |
||
4467 | disptime->SetState(kFALSE); |
||
4468 | fH1->AddFrame(disptime, f0centery); |
||
4469 | fG1->AddFrame(fH1, f2); |
||
4470 | |||
4471 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4472 | lab = new TGLabel(fH1, "Bias voltage:"); |
||
4473 | fH1->AddFrame(lab, f0centery); |
||
4474 | dispbias = new TGNumberEntry(fH1, 0.00, 4, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEAAnyNumber); |
||
4475 | dispbias->Resize(80,22); |
||
4476 | dispbias->SetState(kFALSE); |
||
4477 | fH1->AddFrame(dispbias, f0centery); |
||
4478 | |||
4479 | lab = new TGLabel(fH1, "Position:"); |
||
4480 | fH1->AddFrame(lab, f0centery); |
||
4481 | disppos = new TGTextEntry(fH1, ""); |
||
4482 | disppos->Resize(200,22); |
||
4483 | disppos->SetState(kFALSE); |
||
4484 | fH1->AddFrame(disppos, f0centery); |
||
4485 | |||
4486 | lab = new TGLabel(fH1, "Temperature:"); |
||
4487 | fH1->AddFrame(lab, f0centery); |
||
4488 | disptemp = new TGNumberEntry(fH1, 0.0, 6, 999, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAAnyNumber); |
||
4489 | disptemp->Resize(80,22); |
||
4490 | disptemp->SetState(kFALSE); |
||
4491 | fH1->AddFrame(disptemp, f0centery); |
||
4492 | |||
4493 | lab = new TGLabel(fH1, "Angle:"); |
||
4494 | fH1->AddFrame(lab, f0centery); |
||
4495 | dispangle = new TGNumberEntry(fH1, 0.0, 6, 999, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAAnyNumber); |
||
4496 | dispangle->Resize(80,22); |
||
4497 | dispangle->SetState(kFALSE); |
||
4498 | fH1->AddFrame(dispangle, f0centery); |
||
4499 | fG1->AddFrame(fH1, f2); |
||
4500 | |||
4501 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4502 | lab = new TGLabel(fH1, "Laser settings:"); |
||
4503 | fH1->AddFrame(lab, f0centery); |
||
4504 | displaser = new TGTextEntry(fH1, ""); |
||
4505 | displaser->Resize(440,22); |
||
4506 | displaser->SetState(kFALSE); |
||
4507 | fH1->AddFrame(displaser, f0centery); |
||
4508 | fG1->AddFrame(fH1, f2); |
||
4509 | mdiFrame->AddFrame(fG1, f2); |
||
4510 | |||
117 | f9daq | 4511 | mdiFrame->SetMdiHints(kMdiMinimize); |
4512 | mdiFrame->SetWindowName("Histogram file selection"); |
||
4513 | mdiFrame->MapSubwindows(); |
||
4514 | mdiFrame->Layout(); |
||
4515 | mdiFrame->Move(0,3*((winHeight/5)-5)-5); |
||
4516 | // Histogram file selection pane ----------------------------------------------------------- |
||
4517 | |||
4518 | // Histogram controls pane ----------------------------------------------------------------- |
||
4519 | subwin[0] = 2*((winWidth/6)-5); subwin[1] = (int)(2.5*((winHeight/5)-5))+10; |
||
4520 | histogramPaneCtr = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
4521 | mdiFrame = histogramPaneCtr->GetMdiFrame(); |
||
4522 | |||
4523 | // Control for histogram X range |
||
4524 | subgroup[0] = subwin[0]-10; |
||
4525 | fG1 = new TGGroupFrame(mdiFrame, "Histogram display"); |
||
4526 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4527 | lab = new TGLabel(fH1, "ADC range (min, max):"); |
||
4528 | fH1->AddFrame(lab, f0centery); |
||
4529 | adcMinRange = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber); |
||
4530 | adcMinRange->Resize(80,22); |
||
4531 | fH1->AddFrame(adcMinRange, f0centery); |
||
4532 | adcMaxRange = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEAAnyNumber); |
||
4533 | adcMaxRange->Resize(80,22); |
||
4534 | fH1->AddFrame(adcMaxRange, f0centery); |
||
4535 | fG1->AddFrame(fH1, f2); |
||
4536 | |||
4537 | // TDC window for getting data |
||
4538 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4539 | lab = new TGLabel(fH1, "TDC range (min, max):"); |
||
4540 | fH1->AddFrame(lab, f0centery); |
||
4541 | tdcMinwindow = new TGNumberEntry(fH1, 0.0, 6, 999, TGNumberFormat::kNESRealTwo, TGNumberFormat::kNEAAnyNumber); |
||
4542 | tdcMinwindow->Resize(80,22); |
||
4543 | fH1->AddFrame(tdcMinwindow, f0centery); |
||
4544 | tdcMaxwindow = new TGNumberEntry(fH1, 221.8, 6, 999, TGNumberFormat::kNESRealTwo, TGNumberFormat::kNEAAnyNumber); |
||
4545 | tdcMaxwindow->Resize(80,22); |
||
4546 | fH1->AddFrame(tdcMaxwindow, f0centery); |
||
4547 | fG1->AddFrame(fH1, f2); |
||
4548 | |||
4549 | // Y axis range settings |
||
4550 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4551 | lab = new TGLabel(fH1, "Y range (min, max):"); |
||
4552 | fH1->AddFrame(lab, f0centery); |
||
4553 | yMinRange = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAAnyNumber); |
||
4554 | yMinRange->Resize(80,22); |
||
4555 | fH1->AddFrame(yMinRange, f0centery); |
||
4556 | yMaxRange = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESRealOne, TGNumberFormat::kNEAAnyNumber); |
||
4557 | yMaxRange->Resize(80,22); |
||
4558 | fH1->AddFrame(yMaxRange, f0centery); |
||
4559 | fG1->AddFrame(fH1, f2); |
||
4560 | |||
4561 | // Select the channel to display |
||
4562 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4563 | lab = new TGLabel(fH1, "Display channel:"); |
||
4564 | fH1->AddFrame(lab, f0centery); |
||
4565 | selectCh = new TGNumberEntry(fH1, 0, 6, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative, TGNumberFormat::kNELLimitMinMax, 0, (NCH->GetNumber())-1); |
||
4566 | selectCh->Resize(40,22); |
||
4567 | fH1->AddFrame(selectCh, f0centery); |
||
4568 | |||
4569 | changeADC = new TGTextButton(fH1, "ADC"); |
||
4570 | changeADC->AllowStayDown(kTRUE); |
||
4571 | changeADC->SetDown(kTRUE); |
||
4572 | fMenuHisttype->CheckEntry(M_ANALYSIS_HISTTYPE_1DADC); |
||
4573 | changeADC->SetTextJustify(36); |
||
4574 | changeADC->SetWrapLength(-1); |
||
4575 | changeADC->Resize(60,22); |
||
4576 | fH1->AddFrame(changeADC, f0centery); |
||
4577 | |||
4578 | changeTDC = new TGTextButton(fH1, "TDC"); |
||
4579 | changeTDC->AllowStayDown(kTRUE); |
||
4580 | changeTDC->SetTextJustify(36); |
||
4581 | changeTDC->SetWrapLength(-1); |
||
4582 | changeTDC->Resize(60,22); |
||
4583 | fH1->AddFrame(changeTDC, f0centery); |
||
4584 | |||
4585 | changeADCTDC = new TGTextButton(fH1, "ADC/TDC"); |
||
4586 | changeADCTDC->AllowStayDown(kTRUE); |
||
4587 | changeADCTDC->SetTextJustify(36); |
||
4588 | changeADCTDC->SetWrapLength(-1); |
||
4589 | changeADCTDC->Resize(60,22); |
||
4590 | fH1->AddFrame(changeADCTDC, f0centery); |
||
4591 | |||
4592 | change2Dsurf = new TGTextButton(fH1, "Surf 2D"); |
||
4593 | change2Dsurf->AllowStayDown(kTRUE); |
||
4594 | change2Dsurf->SetTextJustify(36); |
||
4595 | change2Dsurf->SetWrapLength(-1); |
||
4596 | change2Dsurf->Resize(60,22); |
||
4597 | fH1->AddFrame(change2Dsurf, f0); |
||
4598 | fG1->AddFrame(fH1, f2); |
||
4599 | |||
4600 | logscale = new TGCheckButton(fG1, "Logarithmic scale ON/OFF"); |
||
4601 | logscale->Resize(50,22); |
||
4602 | logscale->SetState(kButtonUp); |
||
4603 | fG1->AddFrame(logscale, f0centerx); |
||
4604 | |||
4605 | // Export the selected files |
||
4606 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 100); |
||
4607 | fH2 = new TGHorizontalFrame(fH1, subgroup[0], 100); |
||
4608 | lab = new TGLabel(fH2, "Export selected histograms:"); |
||
4609 | fH2->AddFrame(lab, f0centery); |
||
4610 | |||
4611 | exportHist = new TGTextButton(fH2, "Export"); |
||
4612 | exportHist->SetTextJustify(36); |
||
4613 | exportHist->SetWrapLength(-1); |
||
4614 | exportHist->Resize(80,22); |
||
4615 | fH2->AddFrame(exportHist, f0centery); |
||
4616 | fH1->AddFrame(fH2, f0centerx); |
||
4617 | fG1->AddFrame(fH1, f2); |
||
4618 | mdiFrame->AddFrame(fG1, f2); |
||
4619 | |||
4620 | // Fitting controls for ADC spectrum |
||
4621 | fG1 = new TGGroupFrame(mdiFrame, "Fit Settings"); |
||
4622 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4623 | lab = new TGLabel(fH1, "Peak sigma:"); |
||
4624 | fH1->AddFrame(lab, f0centery); |
||
128 | f9daq | 4625 | fitSigma = new TGNumberEntry(fH1, 1.2, 3, 999, TGNumberFormat::kNESRealThree, TGNumberFormat::kNEANonNegative); |
117 | f9daq | 4626 | fitSigma->Resize(60,22); |
4627 | fH1->AddFrame(fitSigma, f0centery); |
||
4628 | fG1->AddFrame(fH1, f2); |
||
4629 | |||
4630 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4631 | lab = new TGLabel(fH1, "Signal/Noise treshold:"); |
||
4632 | fH1->AddFrame(lab, f0centery); |
||
4633 | fitTresh = new TGNumberEntry(fH1, 5.0E-3, 3, 999, TGNumberFormat::kNESReal, TGNumberFormat::kNEANonNegative); |
||
4634 | fitTresh->Resize(60,22); |
||
4635 | fH1->AddFrame(fitTresh, f0centery); |
||
4636 | fG1->AddFrame(fH1, f2); |
||
4637 | |||
4638 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4639 | lab = new TGLabel(fH1, "Background interpolation:"); |
||
4640 | fH1->AddFrame(lab, f0centery); |
||
128 | f9daq | 4641 | fitInter = new TGNumberEntry(fH1, 7, 3, 999, TGNumberFormat::kNESInteger, TGNumberFormat::kNEANonNegative); |
117 | f9daq | 4642 | fitInter->Resize(60,22); |
4643 | fH1->AddFrame(fitInter, f0centery); |
||
4644 | fG1->AddFrame(fH1, f2); |
||
4645 | |||
4646 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4647 | lab = new TGLabel(fH1, "Peak fit max. acceptable error:"); |
||
4648 | fH1->AddFrame(lab, f0centery); |
||
4649 | accError = new TGNumberEntry(fH1, 0.15, 3, 999, TGNumberFormat::kNESRealTwo, TGNumberFormat::kNEANonNegative); |
||
4650 | accError->Resize(60,22); |
||
4651 | fH1->AddFrame(accError, f0centery); |
||
4652 | fG1->AddFrame(fH1, f2); |
||
4653 | |||
4654 | exfitplots = new TGCheckButton(fG1, "Export fitting plots ON/OFF"); |
||
4655 | exfitplots->Resize(50,22); |
||
128 | f9daq | 4656 | exfitplots->SetState(kButtonUp); |
117 | f9daq | 4657 | fG1->AddFrame(exfitplots, f0centerx); |
4658 | mdiFrame->AddFrame(fG1, f2); |
||
4659 | |||
4660 | mdiFrame->SetMdiHints(kMdiMinimize); |
||
4661 | mdiFrame->SetWindowName("Histogram controls"); |
||
4662 | mdiFrame->MapSubwindows(); |
||
4663 | mdiFrame->Layout(); |
||
4664 | mdiFrame->Move(4*((winWidth/6)-5)+10,(int)(2.5*((winHeight/5)-5))); |
||
4665 | // Histogram controls pane ----------------------------------------------------------------- |
||
4666 | |||
4667 | // Action connections |
||
4668 | voltscanOn->Connect("Clicked()", "TGAppMainFrame", this, "EnableVoltScan()"); |
||
4669 | surfscanOn->Connect("Clicked()", "TGAppMainFrame", this, "EnableSurfScan()"); |
||
4670 | zscanOn->Connect("Clicked()", "TGAppMainFrame", this, "EnableZaxisScan()"); |
||
4671 | // histogramOn->Connect("Clicked()", "TGAppMainFrame", this, "HistogramToggle()"); |
||
4672 | vHardlimit->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "VoltageLimit()"); |
||
4673 | (vHardlimit->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "VoltageLimit()"); |
||
4674 | NCH->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "ChannelLimit()"); |
||
4675 | (NCH->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "ChannelLimit()"); |
||
4676 | cleanOn->Connect("Clicked()", "TGAppMainFrame", this, "CleanPlotToggle()"); |
||
4677 | oscConnect->Connect("Clicked()", "TGAppMainFrame", this, "ConnectToScope()"); |
||
4678 | vOutSet->Connect("Clicked()", "TGAppMainFrame", this, "SetVoltOut()"); |
||
4679 | vOutGet->Connect("Clicked()", "TGAppMainFrame", this, "GetVoltOut()"); |
||
4680 | vOutReset->Connect("Clicked()", "TGAppMainFrame", this, "ResetVoltOut()"); |
||
4681 | positionSet->Connect("Clicked()", "TGAppMainFrame", this, "SetPosition()"); |
||
4682 | positionGet->Connect("Clicked()", "TGAppMainFrame", this, "GetPosition()"); |
||
4683 | positionHome->Connect("Clicked()", "TGAppMainFrame", this, "HomePosition()"); |
||
4684 | saveFile->Connect("Clicked()", "TGAppMainFrame", this, "SaveFile()"); |
||
4685 | measStart->Connect("Clicked()", "TGAppMainFrame", this, "StartAcq()"); |
||
4686 | selectDir->Connect("Clicked()", "TGAppMainFrame", this, "SelectDirectory()"); |
||
4687 | multiSelect->Connect("Clicked()", "TGAppMainFrame", this, "ListMultiSelect()"); |
||
4688 | multiSelectAll->Connect("Clicked()", "TGAppMainFrame", this, "ListSelectAll()"); |
||
4689 | prevFile->Connect("Clicked()", "TGAppMainFrame", this, "FileListNavigation(=-2)"); |
||
4690 | nextFile->Connect("Clicked()", "TGAppMainFrame", this, "FileListNavigation(=-3)"); |
||
4691 | fileList->Connect("DoubleClicked(Int_t)", "TGAppMainFrame", this, "FileListNavigation(Int_t)"); |
||
4692 | clearList->Connect("Clicked()", "TGListBox", fileList, "RemoveAll()"); |
||
4693 | |||
4694 | adcMinRange->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
4695 | (adcMinRange->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
4696 | adcMaxRange->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
4697 | (adcMaxRange->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
4698 | yMinRange->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
4699 | (yMinRange->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
4700 | yMaxRange->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
4701 | (yMaxRange->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
4702 | tdcMinwindow->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
4703 | (tdcMinwindow->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
4704 | tdcMaxwindow->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "SetHistRange()"); |
||
4705 | (tdcMaxwindow->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "SetHistRange()"); |
||
4706 | changeADC->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=0)"); |
||
4707 | changeTDC->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=1)"); |
||
4708 | changeADCTDC->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=2)"); |
||
4709 | change2Dsurf->Connect("Clicked()", "TGAppMainFrame", this, "ChangeHisttype(=3)"); |
||
4710 | selectCh->Connect("ValueSet(Long_t)", "TGAppMainFrame", this, "ChangeChannel()"); |
||
4711 | (selectCh->GetNumberEntry())->Connect("ReturnPressed()", "TGAppMainFrame", this, "ChangeChannel()"); |
||
4712 | logscale->Connect("Clicked()", "TGAppMainFrame", this, "SetHistRange()"); |
||
4713 | exportHist->Connect("Clicked()", "TGAppMainFrame", this, "HistogramExport()"); |
||
4714 | |||
127 | f9daq | 4715 | scopeInit->Connect("Clicked()", "TGAppMainFrame", this, "InitializeScope()"); |
4716 | sendScopeCustom->Connect("Clicked()", "TGAppMainFrame", this, "CustomScopeCommand()"); |
||
4717 | sMeasType->Connect("Selected(Int_t)", "TGAppMainFrame", this, "SelectedMeasType(Int_t)"); |
||
4718 | |||
117 | f9daq | 4719 | started = kFALSE; |
127 | f9daq | 4720 | |
4721 | for(int i = 0; i < 8; i++) sCH[i]->SetEnabled(kFALSE); |
||
4722 | sMeasType->SetEnabled(kFALSE); |
||
4723 | sCamaclink->SetEnabled(kFALSE); |
||
4724 | scopeCommand->SetEnabled(kFALSE); |
||
4725 | sendScopeCustom->SetEnabled(kFALSE); |
||
4726 | sMeasgroup->SetEnabled(kFALSE); |
||
4727 | scopeInit->SetEnabled(kFALSE); |
||
4728 | |||
117 | f9daq | 4729 | EnableVoltScan(); |
4730 | EnableSurfScan(); |
||
4731 | EnableZaxisScan(); |
||
127 | f9daq | 4732 | |
4733 | // Testing canvas for scope waveforms |
||
4734 | wCanvas = new TCanvas("wCanvas", "Waveform canvas", 600, 300); |
||
117 | f9daq | 4735 | } |
4736 | |||
4737 | //--------------------------------------------------------------- |
||
128 | f9daq | 4738 | // Opening a new subwindow |
4739 | |||
4740 | void TGAppMainFrame::OpenWindow(int winid) |
||
4741 | { |
||
4742 | /* WinID: |
||
4743 | * - 1 = fieldpoint temperature sensor |
||
4744 | */ |
||
4745 | |||
4746 | TGMdiFrame *mdiFrame; |
||
4747 | |||
4748 | // Generic horizontal and vertical frames |
||
4749 | TGHorizontalFrame *fH1, *fH2; |
||
4750 | TGGroupFrame *fG1; |
||
4751 | TGLabel *lab; |
||
4752 | |||
4753 | int subwin[2]; |
||
4754 | int subgroup[2]; |
||
4755 | |||
4756 | char ctemp[256]; |
||
4757 | |||
4758 | // Fieldpoint pane ------------------------------------------------------------------------- |
||
4759 | if(winid == 1) |
||
4760 | { |
||
4761 | time_t rtime; |
||
4762 | int yearrange[2]; |
||
4763 | |||
4764 | subwin[0] = 3*((winWidth/4)-5); subwin[1] = (int)(2*((winHeight/3)-5))+10; |
||
4765 | histogramPaneCtr = new TGMdiSubwindow(fMainFrame, subwin[0], subwin[1]); |
||
4766 | mdiFrame = histogramPaneCtr->GetMdiFrame(); |
||
4767 | |||
4768 | subgroup[0] = subwin[0]-10; |
||
4769 | subgroup[1] = 7*subwin[1]/12; |
||
4770 | |||
4771 | // Display canvas for temperature sensor |
||
4772 | displayCanvas = new TRootEmbeddedCanvas("displayCanvas",mdiFrame,subgroup[0],subgroup[1]); |
||
4773 | mdiFrame->AddFrame(displayCanvas, f0centerx); |
||
4774 | TCanvas *gCanvas = displayCanvas->GetCanvas(); |
||
4775 | gCanvas->SetGridx(); |
||
4776 | gCanvas->SetGridy(); |
||
4777 | |||
4778 | fG1 = new TGGroupFrame(mdiFrame, "Temperature sensor settings"); |
||
4779 | // Channel selector |
||
4780 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4781 | lab = new TGLabel(fH1, "Fieldpoint channel:"); |
||
4782 | fH1->AddFrame(lab, f0centery); |
||
4783 | tempCh = new TGComboBox(fH1, 200); |
||
4784 | tempCh->AddEntry("0", 0); |
||
4785 | tempCh->AddEntry("1", 1); |
||
4786 | tempCh->AddEntry("2", 2); |
||
4787 | tempCh->AddEntry("3", 3); |
||
4788 | tempCh->AddEntry("4", 4); |
||
4789 | tempCh->AddEntry("5", 5); |
||
4790 | tempCh->AddEntry("6", 6); |
||
4791 | tempCh->AddEntry("7", 7); |
||
4792 | tempCh->Resize(50,22); |
||
4793 | tempCh->Select(1); |
||
4794 | fH1->AddFrame(tempCh, f0centery); |
||
4795 | fG1->AddFrame(fH1, f2); |
||
4796 | |||
4797 | // Start and stop time ------------------------ |
||
4798 | time(&rtime); |
||
4799 | |||
4800 | lab = new TGLabel(fG1, "Start time:"); |
||
4801 | fG1->AddFrame(lab, f0); |
||
4802 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4803 | // Start day |
||
4804 | lab = new TGLabel(fH1, "\tDay: "); |
||
4805 | fH1->AddFrame(lab, f0centery); |
||
4806 | tempDay[0] = new TGComboBox(fH1, 200); |
||
4807 | for(int i = 0; i < 31; i++) |
||
4808 | { |
||
4809 | sprintf(ctemp, "%d", i+1); |
||
4810 | tempDay[0]->AddEntry(ctemp, i); |
||
4811 | } |
||
4812 | tempDay[0]->Resize(50,22); |
||
4813 | tempDay[0]->Select((int)(localtime(&rtime))->tm_mday-1); |
||
4814 | fH1->AddFrame(tempDay[0], f0centery); |
||
4815 | |||
4816 | // Start month |
||
4817 | lab = new TGLabel(fH1, " Month: "); |
||
4818 | fH1->AddFrame(lab, f0centery); |
||
4819 | tempMonth[0] = new TGComboBox(fH1, 200); |
||
4820 | tempMonth[0]->AddEntry("January", 0); |
||
4821 | tempMonth[0]->AddEntry("February", 1); |
||
4822 | tempMonth[0]->AddEntry("March", 2); |
||
4823 | tempMonth[0]->AddEntry("April", 3); |
||
4824 | tempMonth[0]->AddEntry("May", 4); |
||
4825 | tempMonth[0]->AddEntry("June", 5); |
||
4826 | tempMonth[0]->AddEntry("July", 6); |
||
4827 | tempMonth[0]->AddEntry("August", 7); |
||
4828 | tempMonth[0]->AddEntry("September", 8); |
||
4829 | tempMonth[0]->AddEntry("October", 9); |
||
4830 | tempMonth[0]->AddEntry("November", 10); |
||
4831 | tempMonth[0]->AddEntry("December", 11); |
||
4832 | tempMonth[0]->Resize(80,22); |
||
4833 | tempMonth[0]->Select((int)(localtime(&rtime))->tm_mon); |
||
4834 | fH1->AddFrame(tempMonth[0], f0centery); |
||
4835 | |||
4836 | // Start year |
||
4837 | yearrange[0] = 2010; |
||
4838 | yearrange[1] = (int)(localtime(&rtime))->tm_year+1900; |
||
4839 | |||
4840 | lab = new TGLabel(fH1, " Year: "); |
||
4841 | fH1->AddFrame(lab, f0centery); |
||
4842 | tempYear[0] = new TGComboBox(fH1, 200); |
||
4843 | for(int i = 0; i < (yearrange[1]-yearrange[0])+1; i++) |
||
4844 | { |
||
4845 | sprintf(ctemp, "%d", yearrange[1]-i); |
||
4846 | tempYear[0]->AddEntry(ctemp, i); |
||
4847 | } |
||
4848 | tempYear[0]->Resize(60,22); |
||
4849 | tempYear[0]->Select(0); |
||
4850 | fH1->AddFrame(tempYear[0], f0centery); |
||
4851 | |||
4852 | // Start hour |
||
4853 | lab = new TGLabel(fH1, " Hour: "); |
||
4854 | fH1->AddFrame(lab, f0centery); |
||
4855 | tempHour[0] = new TGComboBox(fH1, 200); |
||
4856 | for(int i = 0; i < 24; i++) |
||
4857 | { |
||
4858 | if(i < 10) |
||
4859 | sprintf(ctemp, "0%d", i); |
||
4860 | else |
||
4861 | sprintf(ctemp, "%d", i); |
||
4862 | tempHour[0]->AddEntry(ctemp, i); |
||
4863 | } |
||
4864 | tempHour[0]->Resize(50,22); |
||
4865 | tempHour[0]->Select(7); |
||
4866 | fH1->AddFrame(tempHour[0], f0centery); |
||
4867 | |||
4868 | // Start minute |
||
4869 | lab = new TGLabel(fH1, " Minute: "); |
||
4870 | fH1->AddFrame(lab, f0centery); |
||
4871 | tempMinute[0] = new TGComboBox(fH1, 200); |
||
4872 | for(int i = 0; i < 60; i++) |
||
4873 | { |
||
4874 | if(i < 10) |
||
4875 | sprintf(ctemp, "0%d", i); |
||
4876 | else |
||
4877 | sprintf(ctemp, "%d", i); |
||
4878 | tempMinute[0]->AddEntry(ctemp, i); |
||
4879 | } |
||
4880 | tempMinute[0]->Resize(50,22); |
||
4881 | tempMinute[0]->Select(0); |
||
4882 | fH1->AddFrame(tempMinute[0], f0centery); |
||
4883 | |||
4884 | // Start second |
||
4885 | lab = new TGLabel(fH1, " Second: "); |
||
4886 | fH1->AddFrame(lab, f0centery); |
||
4887 | tempSecond[0] = new TGComboBox(fH1, 200); |
||
4888 | for(int i = 0; i < 60; i++) |
||
4889 | { |
||
4890 | if(i < 10) |
||
4891 | sprintf(ctemp, "0%d", i); |
||
4892 | else |
||
4893 | sprintf(ctemp, "%d", i); |
||
4894 | tempSecond[0]->AddEntry(ctemp, i); |
||
4895 | } |
||
4896 | tempSecond[0]->Resize(50,22); |
||
4897 | tempSecond[0]->Select(0); |
||
4898 | fH1->AddFrame(tempSecond[0], f0centery); |
||
4899 | |||
4900 | // Get start time from file |
||
4901 | lab = new TGLabel(fH1, " "); |
||
4902 | fH1->AddFrame(lab, f0centery); |
||
4903 | tempFile[0] = new TGTextButton(fH1, "Get from file..."); |
||
4904 | tempFile[0]->SetTextJustify(36); |
||
4905 | tempFile[0]->SetWrapLength(-1); |
||
4906 | tempFile[0]->Resize(100,22); |
||
4907 | fH1->AddFrame(tempFile[0], f0centery); |
||
4908 | |||
4909 | fG1->AddFrame(fH1, f2); |
||
4910 | |||
4911 | // Use the end time or not |
||
4912 | tempEndOn = new TGCheckButton(fG1, "Draw to last time point (ON/OFF)"); |
||
4913 | tempEndOn->Resize(100,22); |
||
4914 | tempEndOn->SetState(kButtonUp); |
||
4915 | fG1->AddFrame(tempEndOn, f0); |
||
4916 | |||
4917 | lab = new TGLabel(fG1, "End time:"); |
||
4918 | fG1->AddFrame(lab, f0); |
||
4919 | fH1 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
4920 | // End day |
||
4921 | lab = new TGLabel(fH1, "\tDay: "); |
||
4922 | fH1->AddFrame(lab, f0centery); |
||
4923 | tempDay[1] = new TGComboBox(fH1, 200); |
||
4924 | for(int i = 0; i < 31; i++) |
||
4925 | { |
||
4926 | sprintf(ctemp, "%d", i+1); |
||
4927 | tempDay[1]->AddEntry(ctemp, i); |
||
4928 | } |
||
4929 | tempDay[1]->Resize(50,22); |
||
4930 | tempDay[1]->Select((int)(localtime(&rtime))->tm_mday-1); |
||
4931 | fH1->AddFrame(tempDay[1], f0centery); |
||
4932 | |||
4933 | // End month |
||
4934 | lab = new TGLabel(fH1, " Month: "); |
||
4935 | fH1->AddFrame(lab, f0centery); |
||
4936 | tempMonth[1] = new TGComboBox(fH1, 200); |
||
4937 | tempMonth[1]->AddEntry("January", 0); |
||
4938 | tempMonth[1]->AddEntry("February", 1); |
||
4939 | tempMonth[1]->AddEntry("March", 2); |
||
4940 | tempMonth[1]->AddEntry("April", 3); |
||
4941 | tempMonth[1]->AddEntry("May", 4); |
||
4942 | tempMonth[1]->AddEntry("June", 5); |
||
4943 | tempMonth[1]->AddEntry("July", 6); |
||
4944 | tempMonth[1]->AddEntry("August", 7); |
||
4945 | tempMonth[1]->AddEntry("September", 8); |
||
4946 | tempMonth[1]->AddEntry("October", 9); |
||
4947 | tempMonth[1]->AddEntry("November", 10); |
||
4948 | tempMonth[1]->AddEntry("December", 11); |
||
4949 | tempMonth[1]->Resize(80,22); |
||
4950 | tempMonth[1]->Select((int)(localtime(&rtime))->tm_mon); |
||
4951 | fH1->AddFrame(tempMonth[1], f0centery); |
||
4952 | |||
4953 | // End year |
||
4954 | time(&rtime); |
||
4955 | yearrange[0] = 2010; |
||
4956 | yearrange[1] = (int)(localtime(&rtime))->tm_year+1900; |
||
4957 | |||
4958 | lab = new TGLabel(fH1, " Year: "); |
||
4959 | fH1->AddFrame(lab, f0centery); |
||
4960 | tempYear[1] = new TGComboBox(fH1, 200); |
||
4961 | for(int i = 0; i < (yearrange[1]-yearrange[0])+1; i++) |
||
4962 | { |
||
4963 | sprintf(ctemp, "%d", yearrange[1]-i); |
||
4964 | tempYear[1]->AddEntry(ctemp, i); |
||
4965 | } |
||
4966 | tempYear[1]->Resize(60,22); |
||
4967 | tempYear[1]->Select(0); |
||
4968 | fH1->AddFrame(tempYear[1], f0centery); |
||
4969 | |||
4970 | // End hour |
||
4971 | lab = new TGLabel(fH1, " Hour: "); |
||
4972 | fH1->AddFrame(lab, f0centery); |
||
4973 | tempHour[1] = new TGComboBox(fH1, 200); |
||
4974 | for(int i = 0; i < 24; i++) |
||
4975 | { |
||
4976 | if(i < 10) |
||
4977 | sprintf(ctemp, "0%d", i); |
||
4978 | else |
||
4979 | sprintf(ctemp, "%d", i); |
||
4980 | tempHour[1]->AddEntry(ctemp, i); |
||
4981 | } |
||
4982 | tempHour[1]->Resize(50,22); |
||
4983 | tempHour[1]->Select(18); |
||
4984 | fH1->AddFrame(tempHour[1], f0centery); |
||
4985 | |||
4986 | // End minute |
||
4987 | lab = new TGLabel(fH1, " Minute: "); |
||
4988 | fH1->AddFrame(lab, f0centery); |
||
4989 | tempMinute[1] = new TGComboBox(fH1, 200); |
||
4990 | for(int i = 0; i < 60; i++) |
||
4991 | { |
||
4992 | if(i < 10) |
||
4993 | sprintf(ctemp, "0%d", i); |
||
4994 | else |
||
4995 | sprintf(ctemp, "%d", i); |
||
4996 | tempMinute[1]->AddEntry(ctemp, i); |
||
4997 | } |
||
4998 | tempMinute[1]->Resize(50,22); |
||
4999 | tempMinute[1]->Select(0); |
||
5000 | fH1->AddFrame(tempMinute[1], f0centery); |
||
5001 | |||
5002 | // End second |
||
5003 | lab = new TGLabel(fH1, " Second: "); |
||
5004 | fH1->AddFrame(lab, f0centery); |
||
5005 | tempSecond[1] = new TGComboBox(fH1, 200); |
||
5006 | for(int i = 0; i < 60; i++) |
||
5007 | { |
||
5008 | if(i < 10) |
||
5009 | sprintf(ctemp, "0%d", i); |
||
5010 | else |
||
5011 | sprintf(ctemp, "%d", i); |
||
5012 | tempSecond[1]->AddEntry(ctemp, i); |
||
5013 | } |
||
5014 | tempSecond[1]->Resize(50,22); |
||
5015 | tempSecond[1]->Select(0); |
||
5016 | fH1->AddFrame(tempSecond[1], f0centery); |
||
5017 | |||
5018 | // Get start time from file |
||
5019 | lab = new TGLabel(fH1, " "); |
||
5020 | fH1->AddFrame(lab, f0centery); |
||
5021 | tempFile[1] = new TGTextButton(fH1, "Get from file..."); |
||
5022 | tempFile[1]->SetTextJustify(36); |
||
5023 | tempFile[1]->SetWrapLength(-1); |
||
5024 | tempFile[1]->Resize(100,22); |
||
5025 | fH1->AddFrame(tempFile[1], f0centery); |
||
5026 | |||
5027 | fG1->AddFrame(fH1, f2); |
||
5028 | // Start and stop time ------------------------ |
||
5029 | |||
5030 | // Control buttons |
||
5031 | fH2 = new TGHorizontalFrame(fG1, subgroup[0], 30); |
||
5032 | fH1 = new TGHorizontalFrame(fH2, subgroup[0], 30); |
||
5033 | updateTemp = new TGTextButton(fH1, "Update"); |
||
5034 | updateTemp->SetTextJustify(36); |
||
5035 | updateTemp->SetWrapLength(-1); |
||
5036 | updateTemp->Resize(80,22); |
||
5037 | fH1->AddFrame(updateTemp, f0); |
||
5038 | |||
5039 | exportTemp = new TGTextButton(fH1, "Export"); |
||
5040 | exportTemp->SetTextJustify(36); |
||
5041 | exportTemp->SetWrapLength(-1); |
||
5042 | exportTemp->Resize(80,22); |
||
5043 | fH1->AddFrame(exportTemp, f0); |
||
5044 | |||
5045 | /* closeTemp = new TGTextButton(fH1, "Close"); |
||
5046 | closeTemp->SetTextJustify(36); |
||
5047 | closeTemp->SetWrapLength(-1); |
||
5048 | closeTemp->Resize(80,22); |
||
5049 | fH1->AddFrame(closeTemp, f0);*/ |
||
5050 | fH2->AddFrame(fH1, f0centerx); |
||
5051 | |||
5052 | fG1->AddFrame(fH2, f2); |
||
5053 | |||
5054 | mdiFrame->AddFrame(fG1, f1); |
||
5055 | |||
5056 | mdiFrame->SetMdiHints(kMdiMinimize | kMdiMaximize | kMdiClose); |
||
5057 | mdiFrame->SetWindowName("Fieldpoint FP RTD 122 temperature sensor"); |
||
5058 | mdiFrame->MapSubwindows(); |
||
5059 | mdiFrame->Layout(); |
||
5060 | mdiFrame->Move(1*((winWidth/12)-5)+10,(int)(1*((winHeight/12)-5))); |
||
5061 | |||
5062 | // Action connections |
||
5063 | updateTemp->Connect("Clicked()", "TGAppMainFrame", this, "UpdateTempPlot()"); |
||
5064 | tempEndOn->Connect("Clicked()", "TGAppMainFrame", this, "TempEndToggle()"); |
||
5065 | exportTemp->Connect("Clicked()", "TGAppMainFrame", this, "ExportTempPlot()"); |
||
5066 | tempFile[0]->Connect("Clicked()", "TGAppMainFrame", this, "GetTempFile(=0)"); |
||
5067 | tempFile[1]->Connect("Clicked()", "TGAppMainFrame", this, "GetTempFile(=1)"); |
||
5068 | // closeTemp->Connect("Clicked()", "TGAppMainFrame", this, "UpdateTempPlot()"); |
||
5069 | } |
||
5070 | // Fieldpoint pane ------------------------------------------------------------------------- |
||
5071 | } |
||
5072 | |||
5073 | //--------------------------------------------------------------- |
||
117 | f9daq | 5074 | // Closing the main application window and checking the about information |
5075 | |||
5076 | void TGAppMainFrame::CloseWindow() |
||
5077 | { |
||
5078 | gApplication->Terminate(0); |
||
5079 | } |
||
5080 | |||
5081 | Bool_t TGAppMainFrame::About() |
||
5082 | { |
||
5083 | int ret = 0; |
||
5084 | |||
5085 | new TGMsgBox(gClient->GetRoot(), fMain, |
||
5086 | fMain->GetWindowName(), "This is an application.", |
||
5087 | kMBIconQuestion, kMBClose, &ret); |
||
5088 | |||
5089 | if(debug == 1) |
||
5090 | if(ret == kMBClose) |
||
5091 | printf("Closing the About window (%d).\n", ret); |
||
5092 | |||
5093 | return kFALSE; |
||
5094 | } |
||
5095 | |||
5096 | //--------------------------------------------------------------- |
||
5097 | // Subwindow constructor definition (& layout) and close subwindow action |
||
5098 | |||
5099 | TGMdiSubwindow::TGMdiSubwindow(TGMdiMainFrame *main, int w, int h) |
||
5100 | { |
||
5101 | // Create a new subwindow |
||
5102 | fMdiFrame = new TGMdiFrame(main, w, h); |
||
5103 | fMdiFrame->Connect("CloseWindow()", "TGMdiSubwindow", this, "CloseWindow()"); // setting here to =0 -> will always ask before closing window |
||
5104 | fMdiFrame->DontCallClose(); // only let this window close if Yes is pressed when closing window |
||
5105 | |||
5106 | } |
||
5107 | |||
5108 | Bool_t TGMdiSubwindow::CloseWindow() |
||
5109 | { |
||
5110 | int ret = 0; |
||
5111 | |||
5112 | // if(noq == 0) |
||
5113 | // { |
||
5114 | new TGMsgBox(gClient->GetRoot(), fMdiFrame, |
||
5115 | fMdiFrame->GetWindowName(), "Really want to close the window?", |
||
5116 | kMBIconExclamation, kMBYes | kMBNo, &ret); |
||
5117 | if (ret == kMBYes) return fMdiFrame->CloseWindow(); |
||
5118 | |||
5119 | return kFALSE; |
||
5120 | // } |
||
5121 | // else |
||
5122 | // return fMdiFrame->CloseWindow(); |
||
5123 | } |
||
5124 | |||
5125 | //--------------------------------------------------------------- |
||
5126 | // Main function |
||
5127 | |||
5128 | void windowed_test() |
||
5129 | { |
||
5130 | new TGAppMainFrame(gClient->GetRoot(), winWidth, winHeight); |
||
5131 | } |
||
5132 | |||
5133 | //#ifdef STANDALONE |
||
5134 | int main(int argc, char **argv) |
||
5135 | { |
||
5136 | TApplication theApp("MdiTest", &argc, argv); |
||
5137 | |||
5138 | windowed_test(); |
||
5139 | |||
5140 | theApp.Run(); |
||
5141 | |||
5142 | return 0; |
||
5143 | } |
||
5144 | //#endif |