Subversion Repositories f9daq

Rev

Rev 172 | Details | Compare with Previous | Last modification | View Log | RSS feed

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