Subversion Repositories f9daq

Rev

Rev 172 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 172 Rev 173
1
#include "../include/sipmscan.h"
1
#include "../include/sipmscan.h"
2
#include "../include/workstation.h"
2
#include "../include/workstation.h"
3
 
3
 
4
#include <stdio.h>
4
#include <stdio.h>
5
#include <stdlib.h>
5
#include <stdlib.h>
6
 
6
 
7
int retTemp;
7
int retTemp;
8
 
8
 
9
// Additional functions -------------------------------------
9
// Additional functions -------------------------------------
10
 
10
 
11
// Display the currently selected histogram in the file list
11
// Display the currently selected histogram in the file list
12
void TGAppMainFrame::DisplayHistogram(char *histfile, int histtype, int opt)
12
void TGAppMainFrame::DisplayHistogram(char *histfile, int histtype, int opt)
13
{
13
{
14
   char histtime[256];
14
   char histtime[256];
15
   char ctemp[512];
15
   char ctemp[512];
16
 
16
 
17
   if(DBGSIG)
17
   if(DBGSIG)
18
      printf("DisplayHistogram(): Selected file: %s\n", histfile);
18
      printf("DisplayHistogram(): Selected file: %s\n", histfile);
19
 
19
 
20
   TCanvas *gCanvas = analysisCanvas->GetCanvas();
20
   TCanvas *gCanvas = analysisCanvas->GetCanvas();
21
 
21
 
22
   inroot = TFile::Open(histfile, "READ");
22
   inroot = TFile::Open(histfile, "READ");
23
 
23
 
24
   TTree *header_data, *meas_data;
24
   TTree *header_data, *meas_data;
25
   inroot->GetObject("header_data", header_data);
25
   inroot->GetObject("header_data", header_data);
26
   inroot->GetObject("meas_data", meas_data);
26
   inroot->GetObject("meas_data", meas_data);
27
 
27
 
28
   // Reading the header
28
   // Reading the header
29
   header_data->SetBranchAddress("nrch", &evtheader.nrch);
29
   header_data->SetBranchAddress("nrch", &evtheader.nrch);
30
   header_data->GetEntry(0);
30
   header_data->GetEntry(0);
31
   header_data->SetBranchAddress("timestamp", &evtheader.timestamp);
31
   header_data->SetBranchAddress("timestamp", &evtheader.timestamp);
32
   header_data->GetEntry(0);
32
   header_data->GetEntry(0);
33
   header_data->SetBranchAddress("biasvolt", &evtheader.biasvolt);
33
   header_data->SetBranchAddress("biasvolt", &evtheader.biasvolt);
34
   header_data->GetEntry(0);
34
   header_data->GetEntry(0);
35
   header_data->SetBranchAddress("xpos", &evtheader.xpos);
35
   header_data->SetBranchAddress("xpos", &evtheader.xpos);
36
   header_data->GetEntry(0);
36
   header_data->GetEntry(0);
37
   header_data->SetBranchAddress("ypos", &evtheader.ypos);
37
   header_data->SetBranchAddress("ypos", &evtheader.ypos);
38
   header_data->GetEntry(0);
38
   header_data->GetEntry(0);
39
   header_data->SetBranchAddress("zpos", &evtheader.zpos);
39
   header_data->SetBranchAddress("zpos", &evtheader.zpos);
40
   header_data->GetEntry(0);
40
   header_data->GetEntry(0);
41
   header_data->SetBranchAddress("temperature", &evtheader.temperature);
41
   header_data->SetBranchAddress("temperature", &evtheader.temperature);
42
   header_data->GetEntry(0);
42
   header_data->GetEntry(0);
43
   if( header_data->FindBranch("angle") )
43
   if( header_data->FindBranch("angle") )
44
   {
44
   {
45
      header_data->SetBranchAddress("angle", &evtheader.angle);
45
      header_data->SetBranchAddress("angle", &evtheader.angle);
46
      header_data->GetEntry(0);
46
      header_data->GetEntry(0);
47
   }
47
   }
48
   header_data->SetBranchAddress("laserinfo", &evtheader.laserinfo);
48
   header_data->SetBranchAddress("laserinfo", &evtheader.laserinfo);
49
   header_data->GetEntry(0);
49
   header_data->GetEntry(0);
50
 
50
 
51
   // Change timestamp to local time
51
   // Change timestamp to local time
52
   GetTime(evtheader.timestamp, histtime);
52
   GetTime(evtheader.timestamp, histtime);
53
 
53
 
54
   // Displaying header information debug
54
   // Displaying header information debug
55
   if(DBGSIG)
55
   if(DBGSIG)
56
   {
56
   {
57
      printf("DisplayHistogram(): Opened file header information:\n");
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);
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);
59
      printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime);
60
      printf("- Bias voltage: %lf\n", evtheader.biasvolt);
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);
61
      printf("- Table position (X,Y,Z): %d, %d, %d\n", evtheader.xpos, evtheader.ypos, evtheader.zpos);
62
      if(evtheader.temperature)
62
      if(evtheader.temperature)
63
         printf("- Temperature: %lf\n", evtheader.temperature);
63
         printf("- Temperature: %lf\n", evtheader.temperature);
64
      if( header_data->FindBranch("angle") )
64
      if( header_data->FindBranch("angle") )
65
         printf("- Incidence angle: %lf\n", evtheader.angle);
65
         printf("- Incidence angle: %lf\n", evtheader.angle);
66
      else
66
      else
67
         printf("- Incidence angle: No angle information!\n");
67
         printf("- Incidence angle: No angle information!\n");
68
      printf("- Laser and filter settings: %s\n", evtheader.laserinfo);
68
      printf("- Laser and filter settings: %s\n", evtheader.laserinfo);
69
   }
69
   }
70
 
70
 
71
   // Displaying header information on the GUI
71
   // Displaying header information on the GUI
72
   dispTime->widgetTE->SetText(histtime);
72
   dispTime->widgetTE->SetText(histtime);
73
   dispBias->widgetNE[0]->SetNumber(evtheader.biasvolt);
73
   dispBias->widgetNE[0]->SetNumber(evtheader.biasvolt);
74
   sprintf(ctemp, "%d, %d, %d", evtheader.xpos, evtheader.ypos, evtheader.zpos);
74
   sprintf(ctemp, "%d, %d, %d", evtheader.xpos, evtheader.ypos, evtheader.zpos);
75
   dispPos->widgetTE->SetText(ctemp);
75
   dispPos->widgetTE->SetText(ctemp);
76
   if(evtheader.temperature)
76
   if(evtheader.temperature)
77
      dispTemp->widgetNE[0]->SetNumber(evtheader.temperature);
77
      dispTemp->widgetNE[0]->SetNumber(evtheader.temperature);
78
   else
78
   else
79
      dispTemp->widgetNE[0]->SetNumber(0.0);
79
      dispTemp->widgetNE[0]->SetNumber(0.0);
80
   if( header_data->FindBranch("angle") )
80
   if( header_data->FindBranch("angle") )
81
      dispAngle->widgetNE[0]->SetNumber(evtheader.angle);
81
      dispAngle->widgetNE[0]->SetNumber(evtheader.angle);
82
   else
82
   else
83
      dispAngle->widgetNE[0]->SetNumber(0.0);
83
      dispAngle->widgetNE[0]->SetNumber(0.0);
84
   dispLaser->widgetTE->SetText(evtheader.laserinfo);
84
   dispLaser->widgetTE->SetText(evtheader.laserinfo);
85
 
85
 
86
   selectCh->widgetNE[0]->SetLimitValues(0, (evtheader.nrch/2)-1);
86
   selectCh->widgetNE[0]->SetLimitValues(0, (evtheader.nrch/2)-1);
87
 
87
 
88
   // Redraw the histograms
88
   // Redraw the histograms
89
   int j;
89
   int j;
90
   char rdc[256];
90
   char rdc[256];
91
   char rdcsel[256];
91
   char rdcsel[256];
92
 
92
 
93
   j = selectCh->widgetNE[0]->GetNumber();
93
   j = selectCh->widgetNE[0]->GetNumber();
94
 
94
 
95
   printf("Found %d data points.\n", (int)meas_data->GetEntries());
95
   printf("Found %d data points.\n", (int)meas_data->GetEntries());
96
 
96
 
97
   gCanvas->cd();
97
   gCanvas->cd();
98
   double range[4];
98
   double range[4];
99
   range[0] = adcRange->widgetNE[0]->GetNumber();
99
   range[0] = adcRange->widgetNE[0]->GetNumber();
100
   range[1] = adcRange->widgetNE[1]->GetNumber();
100
   range[1] = adcRange->widgetNE[1]->GetNumber();
101
   range[2] = tdcRange->widgetNE[0]->GetNumber();
101
   range[2] = tdcRange->widgetNE[0]->GetNumber();
102
   range[3] = tdcRange->widgetNE[1]->GetNumber();
102
   range[3] = tdcRange->widgetNE[1]->GetNumber();
103
 
103
 
104
   // ADC histogram
104
   // ADC histogram
105
   if(histtype == 0)
105
   if(histtype == 0)
106
   {
106
   {
107
      if( range[0] == range[1] )
107
      if( range[0] == range[1] )
108
         sprintf(rdc, "ADC%d>>%s", j, histname);
108
         sprintf(rdc, "ADC%d>>%s", j, histname);
109
      else
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);
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
 
111
 
112
      sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion);
112
      sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion);
113
      meas_data->Draw(rdc, rdcsel);
113
      meas_data->Draw(rdc, rdcsel);
114
 
114
 
115
      sprintf(rdc, "ADC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);ADC;", j, evtheader.biasvolt, range[2], range[3]);
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);
116
      TH1F *histtemp = (TH1F*)gCanvas->GetPrimitive(histname);
117
      if(!cleanPlots)
117
      if(!cleanPlots)
118
         histtemp->SetTitle(rdc);
118
         histtemp->SetTitle(rdc);
119
      else
119
      else
120
         histtemp->SetTitle(";ADC;");
120
         histtemp->SetTitle(";ADC;");
121
      histtemp->GetXaxis()->SetLabelSize(0.025);
121
      histtemp->GetXaxis()->SetLabelSize(0.025);
122
      histtemp->GetXaxis()->CenterTitle(kTRUE);
122
      histtemp->GetXaxis()->CenterTitle(kTRUE);
123
      histtemp->GetYaxis()->SetLabelSize(0.025);
123
      histtemp->GetYaxis()->SetLabelSize(0.025);
124
      if(cleanPlots)
124
      if(cleanPlots)
125
      {
125
      {
126
         TGaxis *yax = (TGaxis*)histtemp->GetYaxis();
126
         TGaxis *yax = (TGaxis*)histtemp->GetYaxis();
127
         yax->SetMaxDigits(4);
127
         yax->SetMaxDigits(4);
128
      }
128
      }
129
 
129
 
130
      gCanvas->Modified();
130
      gCanvas->Modified();
131
      gCanvas->Update();
131
      gCanvas->Update();
132
 
132
 
133
      if( yRange->widgetNE[0]->GetNumber() != yRange->widgetNE[1]->GetNumber() )
133
      if( yRange->widgetNE[0]->GetNumber() != yRange->widgetNE[1]->GetNumber() )
134
      {
134
      {
135
         if( (histOpt->widgetChBox[0]->IsDown()) && (yRange->widgetNE[0]->GetNumber() <= 0) )
135
         if( (histOpt->widgetChBox[0]->IsDown()) && (yRange->widgetNE[0]->GetNumber() <= 0) )
136
         {
136
         {
137
            histtemp->GetYaxis()->SetRangeUser(0.5, yRange->widgetNE[1]->GetNumber());
137
            histtemp->GetYaxis()->SetRangeUser(0.5, yRange->widgetNE[1]->GetNumber());
138
            yRange->widgetNE[0]->SetNumber(0.5);
138
            yRange->widgetNE[0]->SetNumber(0.5);
139
            logChange = 1;
139
            logChange = 1;
140
         }
140
         }
141
         else
141
         else
142
         {
142
         {
143
            gCanvas->SetLogy(kFALSE);
143
            gCanvas->SetLogy(kFALSE);
144
            if(logChange == 1)
144
            if(logChange == 1)
145
            {
145
            {
146
               yRange->widgetNE[0]->SetNumber(0.0);
146
               yRange->widgetNE[0]->SetNumber(0.0);
147
               logChange = 0;
147
               logChange = 0;
148
            }
148
            }
149
            histtemp->GetYaxis()->SetRangeUser(yRange->widgetNE[0]->GetNumber(), yRange->widgetNE[1]->GetNumber());
149
            histtemp->GetYaxis()->SetRangeUser(yRange->widgetNE[0]->GetNumber(), yRange->widgetNE[1]->GetNumber());
150
         }
150
         }
151
      }
151
      }
152
 
152
 
153
      TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats");
153
      TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats");
154
      if(!cleanPlots)
154
      if(!cleanPlots)
155
      {
155
      {
156
         stats->SetX1NDC(0.84); stats->SetX2NDC(0.97);
156
         stats->SetX1NDC(0.84); stats->SetX2NDC(0.97);
157
         stats->SetY1NDC(0.87); stats->SetY2NDC(0.97);
157
         stats->SetY1NDC(0.87); stats->SetY2NDC(0.97);
158
      }
158
      }
159
      else
159
      else
160
      {
160
      {
161
         stats->SetX1NDC(1.1); stats->SetX2NDC(1.3);
161
         stats->SetX1NDC(1.1); stats->SetX2NDC(1.3);
162
         stats->SetY1NDC(1.1); stats->SetY2NDC(1.3);
162
         stats->SetY1NDC(1.1); stats->SetY2NDC(1.3);
163
      }
163
      }
164
   }
164
   }
165
   // TDC histogram
165
   // TDC histogram
166
   else if(histtype == 1)
166
   else if(histtype == 1)
167
   {
167
   {
168
      if( range[0] == range[1] )
168
      if( range[0] == range[1] )
169
         sprintf(rdc, "(TDC%d/%lf)>>%s", j, tdctimeconversion, histname);
169
         sprintf(rdc, "(TDC%d/%lf)>>%s", j, tdctimeconversion, histname);
170
      else
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]);
171
         sprintf(rdc, "(TDC%d/%lf)>>%s(%d,%lf,%lf)", j, tdctimeconversion, histname, (int)((range[3]-range[2])*tdctimeconversion), range[2], range[3]);
172
 
172
 
173
      sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion);
173
      sprintf(rdcsel, "(TDC%d>%lf)&&(TDC%d<%lf)", j, range[2]*tdctimeconversion, j, range[3]*tdctimeconversion);
174
      meas_data->Draw(rdc, rdcsel);
174
      meas_data->Draw(rdc, rdcsel);
175
 
175
 
176
      sprintf(rdc, "TDC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);Time (TDC channel) [ns];", j, evtheader.biasvolt, range[2], range[3]);
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);
177
      TH1F *histtemp = (TH1F*)gCanvas->GetPrimitive(histname);
178
      if(!cleanPlots)
178
      if(!cleanPlots)
179
         histtemp->SetTitle(rdc);
179
         histtemp->SetTitle(rdc);
180
      else
180
      else
181
         histtemp->SetTitle(";Time (TDC channel) [ns];");
181
         histtemp->SetTitle(";Time (TDC channel) [ns];");
182
      histtemp->GetXaxis()->SetLabelSize(0.025);
182
      histtemp->GetXaxis()->SetLabelSize(0.025);
183
      histtemp->GetXaxis()->CenterTitle(kTRUE);
183
      histtemp->GetXaxis()->CenterTitle(kTRUE);
184
      histtemp->GetYaxis()->SetLabelSize(0.025);
184
      histtemp->GetYaxis()->SetLabelSize(0.025);
185
      if(cleanPlots)
185
      if(cleanPlots)
186
      {
186
      {
187
         TGaxis *yax = (TGaxis*)histtemp->GetYaxis();
187
         TGaxis *yax = (TGaxis*)histtemp->GetYaxis();
188
         yax->SetMaxDigits(4);
188
         yax->SetMaxDigits(4);
189
      }
189
      }
190
 
190
 
191
      gCanvas->Modified();
191
      gCanvas->Modified();
192
      gCanvas->Update();
192
      gCanvas->Update();
193
 
193
 
194
      if( yRange->widgetNE[0]->GetNumber() != yRange->widgetNE[1]->GetNumber() )
194
      if( yRange->widgetNE[0]->GetNumber() != yRange->widgetNE[1]->GetNumber() )
195
      {
195
      {
196
         if( (histOpt->widgetChBox[0]->IsDown()) && (yRange->widgetNE[0]->GetNumber() <= 0) )
196
         if( (histOpt->widgetChBox[0]->IsDown()) && (yRange->widgetNE[0]->GetNumber() <= 0) )
197
         {
197
         {
198
            histtemp->GetYaxis()->SetRangeUser(0.5, yRange->widgetNE[1]->GetNumber());
198
            histtemp->GetYaxis()->SetRangeUser(0.5, yRange->widgetNE[1]->GetNumber());
199
            yRange->widgetNE[0]->SetNumber(0.5);
199
            yRange->widgetNE[0]->SetNumber(0.5);
200
            logChange = 1;
200
            logChange = 1;
201
         }
201
         }
202
         else
202
         else
203
         {
203
         {
204
            gCanvas->SetLogy(kFALSE);
204
            gCanvas->SetLogy(kFALSE);
205
            if(logChange == 1)
205
            if(logChange == 1)
206
            {
206
            {
207
               yRange->widgetNE[0]->SetNumber(0.0);
207
               yRange->widgetNE[0]->SetNumber(0.0);
208
               logChange = 0;
208
               logChange = 0;
209
            }
209
            }
210
            histtemp->GetYaxis()->SetRangeUser(yRange->widgetNE[0]->GetNumber(), yRange->widgetNE[1]->GetNumber());
210
            histtemp->GetYaxis()->SetRangeUser(yRange->widgetNE[0]->GetNumber(), yRange->widgetNE[1]->GetNumber());
211
         }
211
         }
212
      }
212
      }
213
 
213
 
214
      TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats");
214
      TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats");
215
      if(!cleanPlots)
215
      if(!cleanPlots)
216
      {
216
      {
217
         stats->SetX1NDC(0.84); stats->SetX2NDC(0.97);
217
         stats->SetX1NDC(0.84); stats->SetX2NDC(0.97);
218
         stats->SetY1NDC(0.87); stats->SetY2NDC(0.97);
218
         stats->SetY1NDC(0.87); stats->SetY2NDC(0.97);
219
      }
219
      }
220
      else
220
      else
221
      {
221
      {
222
         stats->SetX1NDC(1.1); stats->SetX2NDC(1.3);
222
         stats->SetX1NDC(1.1); stats->SetX2NDC(1.3);
223
         stats->SetY1NDC(1.1); stats->SetY2NDC(1.3);
223
         stats->SetY1NDC(1.1); stats->SetY2NDC(1.3);
224
      }
224
      }
225
   }
225
   }
226
   // ADC vs. TDC histogram
226
   // ADC vs. TDC histogram
227
   else if(histtype == 2)
227
   else if(histtype == 2)
228
   {
228
   {
229
      if( ((range[0] == range[1]) && (range[2] == range[3])) || (range[2] == range[3]) || (range[0] == range[1]) )
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);
230
         sprintf(rdc, "(TDC%d/%lf):ADC%d>>%s", j, tdctimeconversion, j, histname);
231
      else
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]);
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");
233
      meas_data->Draw(rdc,"","COLZ");
234
 
234
 
235
      sprintf(rdc, "ADC/TDC%d, Vbias=%.3lf, TDC=(%.2lf,%.2lf);ADC;TDC", j, evtheader.biasvolt, range[2], range[3]);
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);
236
      TH2F *histtemp = (TH2F*)gCanvas->GetPrimitive(histname);
237
      if(!cleanPlots)
237
      if(!cleanPlots)
238
         histtemp->SetTitle(rdc);
238
         histtemp->SetTitle(rdc);
239
      else
239
      else
240
         histtemp->SetTitle(";ADC;Time (TDC channel) [ns]");
240
         histtemp->SetTitle(";ADC;Time (TDC channel) [ns]");
241
      histtemp->GetXaxis()->SetLabelSize(0.025);
241
      histtemp->GetXaxis()->SetLabelSize(0.025);
242
      histtemp->GetXaxis()->CenterTitle(kTRUE);
242
      histtemp->GetXaxis()->CenterTitle(kTRUE);
243
      histtemp->GetYaxis()->SetLabelSize(0.025);
243
      histtemp->GetYaxis()->SetLabelSize(0.025);
244
      histtemp->GetYaxis()->CenterTitle(kTRUE);
244
      histtemp->GetYaxis()->CenterTitle(kTRUE);
245
      histtemp->GetYaxis()->SetTitleOffset(1.35);
245
      histtemp->GetYaxis()->SetTitleOffset(1.35);
246
      if(cleanPlots)
246
      if(cleanPlots)
247
      {
247
      {
248
         TGaxis *yax = (TGaxis*)histtemp->GetYaxis();
248
         TGaxis *yax = (TGaxis*)histtemp->GetYaxis();
249
         yax->SetMaxDigits(4);
249
         yax->SetMaxDigits(4);
250
      }
250
      }
251
 
251
 
252
      gCanvas->Modified();
252
      gCanvas->Modified();
253
      gCanvas->Update();
253
      gCanvas->Update();
254
 
254
 
255
      TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats");
255
      TPaveStats *stats = (TPaveStats*)histtemp->FindObject("stats");
256
      stats->SetX1NDC(1.1); stats->SetX2NDC(1.3);
256
      stats->SetX1NDC(1.1); stats->SetX2NDC(1.3);
257
      stats->SetY1NDC(1.1); stats->SetY2NDC(1.3);
257
      stats->SetY1NDC(1.1); stats->SetY2NDC(1.3);
258
 
258
 
259
      TPaletteAxis *gpalette = (TPaletteAxis*)histtemp->GetListOfFunctions()->FindObject("palette");
259
      TPaletteAxis *gpalette = (TPaletteAxis*)histtemp->GetListOfFunctions()->FindObject("palette");
260
      gpalette->SetLabelSize(0.022);
260
      gpalette->SetLabelSize(0.022);
261
   }
261
   }
262
 
262
 
263
   if(histtype < 2)
263
   if(histtype < 2)
264
   {
264
   {
265
      if( histOpt->widgetChBox[0]->IsDown() )
265
      if( histOpt->widgetChBox[0]->IsDown() )
266
         gCanvas->SetLogy(kTRUE);
266
         gCanvas->SetLogy(kTRUE);
267
      else if( !histOpt->widgetChBox[0]->IsDown() )
267
      else if( !histOpt->widgetChBox[0]->IsDown() )
268
         gCanvas->SetLogy(kFALSE);
268
         gCanvas->SetLogy(kFALSE);
269
   }
269
   }
270
   else
270
   else
271
      gCanvas->SetLogy(kFALSE);
271
      gCanvas->SetLogy(kFALSE);
272
 
272
 
273
   gCanvas->Modified();
273
   gCanvas->Modified();
274
   gCanvas->Update();
274
   gCanvas->Update();
275
 
275
 
276
   delete header_data;
276
   delete header_data;
277
   delete meas_data;
277
   delete meas_data;
278
 
278
 
279
   // Delete the opened file when we just display it in the analysis canvas (otherwise wait for histogram save)
279
   // Delete the opened file when we just display it in the analysis canvas (otherwise wait for histogram save)
280
   if(opt != 1)
280
   if(opt != 1)
281
      delete inroot;
281
      delete inroot;
282
 
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)
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
}
284
}
285
 
285
 
286
// Start a measurement (acquisition from CAMAC)
286
// Start a measurement (acquisition from CAMAC)
287
void TGAppMainFrame::RunMeas(void *ptr, int runCase, int &scanon)
287
void TGAppMainFrame::RunMeas(void *ptr, int runCase, int &scanon)
288
{
288
{
289
   int vscan = 0, pscan = 0, zscan = 0, ascan = 0;
289
   int vscan = 0, pscan = 0, zscan = 0, ascan = 0;
290
   if(scansOn->widgetChBox[0]->IsDown()) vscan = 1;
290
   if(scansOn->widgetChBox[0]->IsDown()) vscan = 1;
291
   if(scansOn->widgetChBox[1]->IsDown()) pscan = 1;
291
   if(scansOn->widgetChBox[1]->IsDown()) pscan = 1;
292
   if(scansOn->widgetChBox[2]->IsDown()) zscan = 1;
292
   if(scansOn->widgetChBox[2]->IsDown()) zscan = 1;
293
   if(scansOn->widgetChBox[3]->IsDown()) ascan = 1;
293
   if(scansOn->widgetChBox[3]->IsDown()) ascan = 1;
294
 
294
 
295
   printf("Start of Run, run case %d\n", runCase);
295
   printf("Start of Run, run case %d\n", runCase);
296
 
296
 
297
   float progVal;
297
   float progVal;
298
 
298
 
299
   char ctemp[256];
299
   char ctemp[256];
300
   char ctemp2[256];
300
   char ctemp2[256];
301
   char fname[256];
301
   char fname[256];
302
   int itemp = 0;
302
   int itemp = 0;
303
   TH1F *liveHist;
303
   TH1F *liveHist;
304
 
304
 
305
   float minVoltage, maxVoltage, stepVoltage, diffVoltage;
305
   float minVoltage, maxVoltage, stepVoltage, diffVoltage;
306
   float minXpos, maxXpos, stepXpos, diffXpos;
306
   float minXpos, maxXpos, stepXpos, diffXpos;
307
   float minYpos, maxYpos, stepYpos, diffYpos;
307
   float minYpos, maxYpos, stepYpos, diffYpos;
308
   float minZpos, maxZpos, stepZpos, diffZpos;
308
   float minZpos, maxZpos, stepZpos, diffZpos;
309
   float minAlpha, maxAlpha, stepAlpha, diffAlpha;
309
   float minAlpha, maxAlpha, stepAlpha, diffAlpha;
310
 
310
 
311
   minVoltage = vOutStart->widgetNE[0]->GetNumber();
311
   minVoltage = vOutStart->widgetNE[0]->GetNumber();
312
   maxVoltage = vOutStop->widgetNE[0]->GetNumber();
312
   maxVoltage = vOutStop->widgetNE[0]->GetNumber();
313
   diffVoltage = abs(maxVoltage - minVoltage);
313
   diffVoltage = abs(maxVoltage - minVoltage);
314
   stepVoltage = abs(vOutStep->widgetNE[0]->GetNumber());
314
   stepVoltage = abs(vOutStep->widgetNE[0]->GetNumber());
315
   minXpos = xPosMin->widgetNE[0]->GetNumber();
315
   minXpos = xPosMin->widgetNE[0]->GetNumber();
316
   maxXpos = xPosMax->widgetNE[0]->GetNumber();
316
   maxXpos = xPosMax->widgetNE[0]->GetNumber();
317
   diffXpos = abs(maxXpos - minXpos);
317
   diffXpos = abs(maxXpos - minXpos);
318
   stepXpos = abs(xPosStep->widgetNE[0]->GetNumber());
318
   stepXpos = abs(xPosStep->widgetNE[0]->GetNumber());
319
   minYpos = yPosMin->widgetNE[0]->GetNumber();
319
   minYpos = yPosMin->widgetNE[0]->GetNumber();
320
   maxYpos = yPosMax->widgetNE[0]->GetNumber();
320
   maxYpos = yPosMax->widgetNE[0]->GetNumber();
321
   diffYpos = abs(maxYpos - minYpos);
321
   diffYpos = abs(maxYpos - minYpos);
322
   stepYpos = abs(yPosStep->widgetNE[0]->GetNumber());
322
   stepYpos = abs(yPosStep->widgetNE[0]->GetNumber());
323
   minZpos = zPosMin->widgetNE[0]->GetNumber();
323
   minZpos = zPosMin->widgetNE[0]->GetNumber();
324
   maxZpos = zPosMax->widgetNE[0]->GetNumber();
324
   maxZpos = zPosMax->widgetNE[0]->GetNumber();
325
   diffZpos = abs(maxZpos - minZpos);
325
   diffZpos = abs(maxZpos - minZpos);
326
   stepZpos = abs(zPosStep->widgetNE[0]->GetNumber());
326
   stepZpos = abs(zPosStep->widgetNE[0]->GetNumber());
327
   minAlpha = rotPosMin->widgetNE[0]->GetNumber();
327
   minAlpha = rotPosMin->widgetNE[0]->GetNumber();
328
   maxAlpha = rotPosMax->widgetNE[0]->GetNumber();
328
   maxAlpha = rotPosMax->widgetNE[0]->GetNumber();
329
   diffAlpha = abs(maxAlpha - minAlpha);
329
   diffAlpha = abs(maxAlpha - minAlpha);
330
   stepAlpha = abs(rotPosStep->widgetNE[0]->GetNumber());
330
   stepAlpha = abs(rotPosStep->widgetNE[0]->GetNumber());
331
 
331
 
332
   remove_ext((char*)fileName->widgetTE->GetText(), ctemp);
332
   remove_ext((char*)fileName->widgetTE->GetText(), ctemp);
333
 
333
 
334
   // TODO - angle scan + voltage scan
334
   // TODO - angle scan + voltage scan
335
   // Voltage or surface scan
335
   // Voltage or surface scan
336
   if( vscan || pscan || ascan )
336
   if( vscan || pscan || ascan )
337
   {
337
   {
338
      // No Z scan, No angle scan
338
      // No Z scan, No angle scan
339
      if(!zscan && !ascan)
339
      if(!zscan && !ascan)
340
      {
340
      {
341
         // When we have a voltage scan
341
         // When we have a voltage scan
342
         if( vscan && (stepVoltage > 0.) )
342
         if( vscan && (stepVoltage > 0.) )
343
            SeqNumber(runCase, (int)diffVoltage/stepVoltage, ctemp2);
343
            SeqNumber(runCase, (int)diffVoltage/stepVoltage, ctemp2);
344
         // With only a surface scan
344
         // With only a surface scan
345
         else if(pscan)
345
         else if(pscan)
346
         {
346
         {
347
            if( stepXpos == 0 )
347
            if( stepXpos == 0 )
348
               itemp = 1;
348
               itemp = 1;
349
            else
349
            else
350
               itemp = (int)diffXpos/stepXpos;
350
               itemp = (int)diffXpos/stepXpos;
351
 
351
 
352
            if( stepYpos == 0 )
352
            if( stepYpos == 0 )
353
               itemp *= 1;
353
               itemp *= 1;
354
            else
354
            else
355
               itemp *= (int)diffYpos/stepYpos;
355
               itemp *= (int)diffYpos/stepYpos;
356
            SeqNumber(runCase, itemp, ctemp2);
356
            SeqNumber(runCase, itemp, ctemp2);
357
         }
357
         }
358
         sprintf(fname, "%s_%s%s", ctemp, ctemp2, histext);
358
         sprintf(fname, "%s_%s%s", ctemp, ctemp2, histext);
359
      }
359
      }
360
      // With Z scan, No angle scan
360
      // With Z scan, No angle scan
361
      else if(zscan && !ascan)
361
      else if(zscan && !ascan)
362
      {
362
      {
363
         SeqNumber((int)zPos->widgetNE[0]->GetNumber(), maxZpos, ctemp2);
363
         SeqNumber((int)zPos->widgetNE[0]->GetNumber(), maxZpos, ctemp2);
364
 
364
 
365
         // Voltage scan is on
365
         // Voltage scan is on
366
         if( vscan && (stepVoltage > 0.) )
366
         if( vscan && (stepVoltage > 0.) )
367
         {
367
         {
368
            sprintf(fname, "%s_z%s_", ctemp, ctemp2);
368
            sprintf(fname, "%s_z%s_", ctemp, ctemp2);
369
            SeqNumber(runCase, (int)diffVoltage/stepVoltage+1, ctemp2);
369
            SeqNumber(runCase, (int)diffVoltage/stepVoltage+1, ctemp2);
370
            strcat(fname, ctemp2);
370
            strcat(fname, ctemp2);
371
            strcat(fname, histext);
371
            strcat(fname, histext);
372
         }
372
         }
373
         // Surface scan is on
373
         // Surface scan is on
374
         else if(pscan)
374
         else if(pscan)
375
         {
375
         {
376
            sprintf(fname, "%s_z%s_", ctemp, ctemp2);
376
            sprintf(fname, "%s_z%s_", ctemp, ctemp2);
377
 
377
 
378
            if( stepXpos == 0 )
378
            if( stepXpos == 0 )
379
               itemp = 1;
379
               itemp = 1;
380
            else
380
            else
381
               itemp = (int)diffXpos/stepXpos+1;
381
               itemp = (int)diffXpos/stepXpos+1;
382
 
382
 
383
            if( stepYpos == 0 )
383
            if( stepYpos == 0 )
384
               itemp *= 1;
384
               itemp *= 1;
385
            else
385
            else
386
               itemp *= (int)diffYpos/stepYpos+1;
386
               itemp *= (int)diffYpos/stepYpos+1;
387
            SeqNumber(runCase, itemp, ctemp2);
387
            SeqNumber(runCase, itemp, ctemp2);
388
            strcat(fname, ctemp2);
388
            strcat(fname, ctemp2);
389
            strcat(fname, histext);
389
            strcat(fname, histext);
390
         }
390
         }
391
         // Just Z scan
391
         // Just Z scan
392
         else
392
         else
393
            sprintf(fname, "%s_z%s%s", ctemp, ctemp2, histext);
393
            sprintf(fname, "%s_z%s%s", ctemp, ctemp2, histext);
394
      }
394
      }
395
      // No Z scan, With angle scan
395
      // No Z scan, With angle scan
396
      else if(!zscan && ascan)
396
      else if(!zscan && ascan)
397
      {
397
      {
398
         SeqNumber(runCase, (int)diffAlpha/stepAlpha, ctemp2);
398
         SeqNumber(runCase, (int)diffAlpha/stepAlpha, ctemp2);
399
 
399
 
400
         // Voltage scan is on
400
         // Voltage scan is on
401
         if( vscan && (stepVoltage > 0.) )
401
         if( vscan && (stepVoltage > 0.) )
402
         {
402
         {
403
            sprintf(fname, "%s_phi%s_", ctemp, ctemp2);
403
            sprintf(fname, "%s_phi%s_", ctemp, ctemp2);
404
            SeqNumber(runCase, (int)diffVoltage/stepVoltage+1, ctemp2);
404
            SeqNumber(runCase, (int)diffVoltage/stepVoltage+1, ctemp2);
405
            strcat(fname, ctemp2);
405
            strcat(fname, ctemp2);
406
            strcat(fname, histext);
406
            strcat(fname, histext);
407
         }
407
         }
408
         // Just angle scan
408
         // Just angle scan
409
         else
409
         else
410
            sprintf(fname, "%s_phi%s%s", ctemp, ctemp2, histext);
410
            sprintf(fname, "%s_phi%s%s", ctemp, ctemp2, histext);
411
      }
411
      }
412
   }
412
   }
413
   // All the rest
413
   // All the rest
414
   else if(!vscan && !pscan)
414
   else if(!vscan && !pscan)
415
      sprintf(fname, "%s%s", ctemp, histext);
415
      sprintf(fname, "%s%s", ctemp, histext);
416
 
416
 
417
   // Check if set voltage is below the hard limit
417
   // Check if set voltage is below the hard limit
418
   if( vOut->widgetNE[0]->GetNumber() > vHardlimit->widgetNE[0]->GetNumber() )
418
   if( vOut->widgetNE[0]->GetNumber() > vHardlimit->widgetNE[0]->GetNumber() )
419
   {
419
   {
420
      printf("Voltage hard limit triggered (%lf > %lf)!\n", vOut->widgetNE[0]->GetNumber(), vHardlimit->widgetNE[0]->GetNumber() );
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() );
421
      vOut->widgetNE[0]->SetNumber( vHardlimit->widgetNE[0]->GetNumber() );
422
   }
422
   }
423
 
423
 
424
   printf("Output file is (runCase = %d): %s\n", runCase, fname);
424
   printf("Output file is (runCase = %d): %s\n", runCase, fname);
425
 
425
 
426
   // Writing to output file
426
   // Writing to output file
427
   outroot = TFile::Open(fname, "RECREATE");
427
   outroot = TFile::Open(fname, "RECREATE");
428
 
428
 
429
   TTree *header_data = new TTree("header_data", "Header information for the measurement.");
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.");
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.");
431
   TTree *scope_data = new TTree("scope_data", "Saved scope measurement data.");
432
 
432
 
433
   // Branches for the header
433
   // Branches for the header
434
   header_data->Branch("nrch", &evtheader.nrch, "nrch/I");
434
   header_data->Branch("nrch", &evtheader.nrch, "nrch/I");
435
   header_data->Branch("timestamp", &evtheader.timestamp, "timestamp/I");
435
   header_data->Branch("timestamp", &evtheader.timestamp, "timestamp/I");
436
   header_data->Branch("biasvolt", &evtheader.biasvolt, "biasvolt/D");
436
   header_data->Branch("biasvolt", &evtheader.biasvolt, "biasvolt/D");
437
   header_data->Branch("xpos", &evtheader.xpos, "xpos/I");
437
   header_data->Branch("xpos", &evtheader.xpos, "xpos/I");
438
   header_data->Branch("ypos", &evtheader.ypos, "ypos/I");
438
   header_data->Branch("ypos", &evtheader.ypos, "ypos/I");
439
   header_data->Branch("zpos", &evtheader.zpos, "zpos/I");
439
   header_data->Branch("zpos", &evtheader.zpos, "zpos/I");
440
   header_data->Branch("temperature", &evtheader.temperature, "temperature/D");
440
   header_data->Branch("temperature", &evtheader.temperature, "temperature/D");
441
   header_data->Branch("angle", &evtheader.angle, "angle/D");
441
   header_data->Branch("angle", &evtheader.angle, "angle/D");
442
   header_data->Branch("laserinfo", &evtheader.laserinfo, "laserinfo/C");
442
   header_data->Branch("laserinfo", &evtheader.laserinfo, "laserinfo/C");
443
 
443
 
444
   evtheader.nrch = (int)NCH->widgetNE[0]->GetNumber()*2;
444
   evtheader.nrch = (int)NCH->widgetNE[0]->GetNumber()*2;
445
   evtheader.timestamp = (int)time(NULL);
445
   evtheader.timestamp = (int)time(NULL);
446
   evtheader.biasvolt = (double)vOut->widgetNE[0]->GetNumber();
446
   evtheader.biasvolt = (double)vOut->widgetNE[0]->GetNumber();
447
   if(posUnits->widgetCB->GetSelected() == 0)
447
   if(posUnits->widgetCB->GetSelected() == 0)
448
   {
448
   {
449
      evtheader.xpos = (int)xPos->widgetNE[0]->GetNumber();
449
      evtheader.xpos = (int)xPos->widgetNE[0]->GetNumber();
450
      evtheader.ypos = (int)yPos->widgetNE[0]->GetNumber();
450
      evtheader.ypos = (int)yPos->widgetNE[0]->GetNumber();
451
      evtheader.zpos = (int)zPos->widgetNE[0]->GetNumber();
451
      evtheader.zpos = (int)zPos->widgetNE[0]->GetNumber();
452
   }
452
   }
453
   else if(posUnits->widgetCB->GetSelected() == 1)
453
   else if(posUnits->widgetCB->GetSelected() == 1)
454
   {
454
   {
455
      evtheader.xpos = (int)xPos->widgetNE[0]->GetNumber()/lenconversion;
455
      evtheader.xpos = (int)xPos->widgetNE[0]->GetNumber()/lenconversion;
456
      evtheader.ypos = (int)yPos->widgetNE[0]->GetNumber()/lenconversion;
456
      evtheader.ypos = (int)yPos->widgetNE[0]->GetNumber()/lenconversion;
457
      evtheader.zpos = (int)zPos->widgetNE[0]->GetNumber()/lenconversion;
457
      evtheader.zpos = (int)zPos->widgetNE[0]->GetNumber()/lenconversion;
458
   }
458
   }
459
   evtheader.temperature = (double)chtemp->widgetNE[0]->GetNumber();
459
   evtheader.temperature = (double)chtemp->widgetNE[0]->GetNumber();
460
   if(rotUnits->widgetCB->GetSelected() == 0)
460
   if(rotUnits->widgetCB->GetSelected() == 0)
461
      evtheader.angle = (double)rotPos->widgetNE[0]->GetNumber()*rotconversion;
461
      evtheader.angle = (double)rotPos->widgetNE[0]->GetNumber()*rotconversion;
462
   else if(rotUnits->widgetCB->GetSelected() == 1)
462
   else if(rotUnits->widgetCB->GetSelected() == 1)
463
      evtheader.angle = (double)rotPos->widgetNE[0]->GetNumber();
463
      evtheader.angle = (double)rotPos->widgetNE[0]->GetNumber();
464
   sprintf(evtheader.laserinfo, "%s", laserInfo->widgetTE->GetText());
464
   sprintf(evtheader.laserinfo, "%s", laserInfo->widgetTE->GetText());
465
 
465
 
466
   char histtime[256];
466
   char histtime[256];
467
   GetTime(evtheader.timestamp, histtime);
467
   GetTime(evtheader.timestamp, histtime);
468
 
468
 
469
   printf("Save file header information:\n");
469
   printf("Save file header information:\n");
470
   printf("- Number of channels: %d\n", evtheader.nrch);
470
   printf("- Number of channels: %d\n", evtheader.nrch);
471
   printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime);
471
   printf("- Timestamp: %d (%s)\n", evtheader.timestamp, histtime);
472
   printf("- Bias voltage: %lf\n", evtheader.biasvolt);
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);
473
   printf("- Table position (X,Y,Z): %d, %d, %d\n", evtheader.xpos, evtheader.ypos, evtheader.zpos);
474
   printf("- Temperature: %lf\n", evtheader.temperature);
474
   printf("- Temperature: %lf\n", evtheader.temperature);
475
   printf("- Incidence angle: %lf\n", evtheader.angle);
475
   printf("- Incidence angle: %lf\n", evtheader.angle);
476
   printf("- Laser and filter settings: %s\n", evtheader.laserinfo);
476
   printf("- Laser and filter settings: %s\n", evtheader.laserinfo);
477
 
477
 
478
   header_data->Fill();
478
   header_data->Fill();
479
 
479
 
480
   // Branches for ADC and TDC data
480
   // Branches for ADC and TDC data
481
   for(int i = 0; i < evtheader.nrch/2; i++)
481
   for(int i = 0; i < evtheader.nrch/2; i++)
482
   {
482
   {
483
      sprintf(ctemp, "ADC%d", i);
483
      sprintf(ctemp, "ADC%d", i);
484
      sprintf(fname, "ADC%d/I", i);
484
      sprintf(fname, "ADC%d/I", i);
485
      meas_data->Branch(ctemp, &evtdata.adcdata[i], fname);
485
      meas_data->Branch(ctemp, &evtdata.adcdata[i], fname);
486
 
486
 
487
      sprintf(ctemp, "TDC%d", i);
487
      sprintf(ctemp, "TDC%d", i);
488
      sprintf(fname, "TDC%d/I", i);
488
      sprintf(fname, "TDC%d/I", i);
489
      meas_data->Branch(ctemp, &evtdata.tdcdata[i], fname);
489
      meas_data->Branch(ctemp, &evtdata.tdcdata[i], fname);
490
   }
490
   }
491
 
491
 
492
   //TODO
492
   //TODO
493
   // Initialize the scope before measurement
493
   // Initialize the scope before measurement
494
/*   if( sCamaclink->IsDown() )
494
/*   if( sCamaclink->IsDown() )
495
      InitializeScope();*/
495
      InitializeScope();*/
496
 
496
 
497
   // Branch for scope measurement data
497
   // Branch for scope measurement data
498
/*   if(gScopeDaq->scopeUseType == 2) // only if we select waveform measurement
498
/*   if(gScopeDaq->scopeUseType == 2) // only if we select waveform measurement
499
   {
499
   {
500
      if(gScopeDaq->scopeMeasSel == 0)
500
      if(gScopeDaq->scopeMeasSel == 0)
501
         scope_data->Branch("amp", &evtmeas.measdata, "amp/D");
501
         scope_data->Branch("amp", &evtmeas.measdata, "amp/D");
502
      else if(gScopeDaq->scopeMeasSel == 1)
502
      else if(gScopeDaq->scopeMeasSel == 1)
503
         scope_data->Branch("area", &evtmeas.measdata, "area/D");
503
         scope_data->Branch("area", &evtmeas.measdata, "area/D");
504
      else if(gScopeDaq->scopeMeasSel == 2)
504
      else if(gScopeDaq->scopeMeasSel == 2)
505
         scope_data->Branch("delay", &evtmeas.measdata, "delay/D");
505
         scope_data->Branch("delay", &evtmeas.measdata, "delay/D");
506
      else if(gScopeDaq->scopeMeasSel == 3)
506
      else if(gScopeDaq->scopeMeasSel == 3)
507
         scope_data->Branch("fall", &evtmeas.measdata, "fall/D");
507
         scope_data->Branch("fall", &evtmeas.measdata, "fall/D");
508
      else if(gScopeDaq->scopeMeasSel == 4)
508
      else if(gScopeDaq->scopeMeasSel == 4)
509
         scope_data->Branch("freq", &evtmeas.measdata, "freq/D");
509
         scope_data->Branch("freq", &evtmeas.measdata, "freq/D");
510
      else if(gScopeDaq->scopeMeasSel == 5)
510
      else if(gScopeDaq->scopeMeasSel == 5)
511
         scope_data->Branch("max", &evtmeas.measdata, "max/D");
511
         scope_data->Branch("max", &evtmeas.measdata, "max/D");
512
      else if(gScopeDaq->scopeMeasSel == 6)
512
      else if(gScopeDaq->scopeMeasSel == 6)
513
         scope_data->Branch("mean", &evtmeas.measdata, "mean/D");
513
         scope_data->Branch("mean", &evtmeas.measdata, "mean/D");
514
      else if(gScopeDaq->scopeMeasSel == 7)
514
      else if(gScopeDaq->scopeMeasSel == 7)
515
         scope_data->Branch("min", &evtmeas.measdata, "min/D");
515
         scope_data->Branch("min", &evtmeas.measdata, "min/D");
516
      else if(gScopeDaq->scopeMeasSel == 8)
516
      else if(gScopeDaq->scopeMeasSel == 8)
517
         scope_data->Branch("pk2p", &evtmeas.measdata, "pk2p/D");
517
         scope_data->Branch("pk2p", &evtmeas.measdata, "pk2p/D");
518
      else if(gScopeDaq->scopeMeasSel == 9)
518
      else if(gScopeDaq->scopeMeasSel == 9)
519
         scope_data->Branch("pwidth", &evtmeas.measdata, "pwidth/D");
519
         scope_data->Branch("pwidth", &evtmeas.measdata, "pwidth/D");
520
      else if(gScopeDaq->scopeMeasSel == 10)
520
      else if(gScopeDaq->scopeMeasSel == 10)
521
         scope_data->Branch("rise", &evtmeas.measdata, "rise/D");
521
         scope_data->Branch("rise", &evtmeas.measdata, "rise/D");
522
   }*/
522
   }*/
523
 
523
 
524
   int neve  = (int) evtNum->widgetNE[0]->GetNumber();
524
   int neve  = (int) evtNum->widgetNE[0]->GetNumber();
525
   int allEvt, zProg;
525
   int allEvt, zProg;
526
   zProg = 1;
526
   zProg = 1;
527
 
527
 
528
#if WORKSTAT == 'I'
528
#if WORKSTAT == 'I'
529
#else
529
#else
530
// ONLY FOR TESTING!
530
// ONLY FOR TESTING!
531
   TRandom *randNum = new TRandom();
531
   TRandom *randNum = new TRandom();
532
   randNum->SetSeed(0);
532
   randNum->SetSeed(0);
533
// ONLY FOR TESTING!
533
// ONLY FOR TESTING!
534
#endif
534
#endif
535
 
535
 
536
   // Initialize the CAMAC
536
   // Initialize the CAMAC
537
   if (gDaq)
537
   if (gDaq)
538
   {
538
   {
539
      if(scanon == 0)
539
      if(scanon == 0)
540
      {
540
      {
541
         gDaq->init(evtheader.nrch);
541
         gDaq->init(evtheader.nrch);
542
         scanon = 1;
542
         scanon = 1;
543
      }
543
      }
544
      gDaq->fStop=0;
544
      gDaq->fStop=0;
545
 
545
 
546
      // Set the stopwatch
546
      // Set the stopwatch
547
      clock_t clkt1;
547
      clock_t clkt1;
548
 
548
 
549
      // Prepare histogram for live histogram update
549
      // Prepare histogram for live histogram update
550
      int liven;
550
      int liven;
551
      TCanvas *gCanvas;
551
      TCanvas *gCanvas;
552
      if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
552
      if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
553
      {
553
      {
554
         gCanvas = measCanvas->GetCanvas();
554
         gCanvas = measCanvas->GetCanvas();
555
         gCanvas->SetGrid();
555
         gCanvas->SetGrid();
556
         gCanvas->cd();
556
         gCanvas->cd();
557
         liveHist = new TH1F(histname,"",(int)TMath::Sqrt(neve),0,0);
557
         liveHist = new TH1F(histname,"",(int)TMath::Sqrt(neve),0,0);
558
         liven = 1;
558
         liven = 1;
559
      }
559
      }
560
 
560
 
561
      // Start gathering
561
      // Start gathering
562
      gDaq->start();
562
      gDaq->start();
563
 
563
 
564
      for (int n=0;n<neve && !gDaq->fStop ;/*n++*/)
564
      for (int n=0;n<neve && !gDaq->fStop ;/*n++*/)
565
      {
565
      {
566
         int nb = gDaq->event(gBuf,BSIZE);
566
         int nb = gDaq->event(gBuf,BSIZE);
567
 
567
 
568
#if WORKSTAT == 'I'
568
#if WORKSTAT == 'I'
569
#else
569
#else
570
// ONLY FOR TESTING!
570
// ONLY FOR TESTING!
571
         for(int i=0; i < evtheader.nrch; i++)
571
         for(int i=0; i < evtheader.nrch; i++)
572
         {
572
         {
573
            if(i == 1)
573
            if(i == 1)
574
               gBuf[i] = randNum->Gaus(1500,300);
574
               gBuf[i] = randNum->Gaus(1500,300);
575
            else if(i == 0)
575
            else if(i == 0)
576
               gBuf[i] = randNum->Poisson(2500);
576
               gBuf[i] = randNum->Poisson(2500);
577
         }
577
         }
578
// ONLY FOR TESTING!
578
// ONLY FOR TESTING!
579
#endif
579
#endif
580
         if (nb<=0) n--;
580
         if (nb<=0) n--;
581
 
581
 
582
         int nc=0;
582
         int nc=0;
583
 
583
 
584
         while ( (nb>0) && (n<neve) )
584
         while ( (nb>0) && (n<neve) )
585
         {
585
         {
586
            for(int i = 0; i < evtheader.nrch; i++)
586
            for(int i = 0; i < evtheader.nrch; i++)
587
            {
587
            {
588
               unsigned short adc = gBuf[i+nc]&0xFFFF;
588
               unsigned short adc = gBuf[i+nc]&0xFFFF;
589
               if(i % 2 == 0)           // TDC
589
               if(i % 2 == 0)           // TDC
590
                  evtdata.tdcdata[i/2] = (int)adc;
590
                  evtdata.tdcdata[i/2] = (int)adc;
591
               else if(i % 2 == 1)      // ADC
591
               else if(i % 2 == 1)      // ADC
592
                  evtdata.adcdata[i/2] = (int)adc;
592
                  evtdata.adcdata[i/2] = (int)adc;
593
 
593
 
594
               // Start plotting the scope waveform
594
               // Start plotting the scope waveform
595
/*             if( (gScopeDaq->scopeUseType == 1) && (sCamaclink->IsDown()) )
595
/*             if( (gScopeDaq->scopeUseType == 1) && (sCamaclink->IsDown()) )
596
                  StartScopeAcq();*/ // TODO
596
                  StartScopeAcq();*/ // TODO
597
            }
597
            }
598
            meas_data->Fill();
598
            meas_data->Fill();
599
            n++;
599
            n++;
600
 
600
 
601
            // Start making a scope measurement
601
            // Start making a scope measurement
602
/*          if( (gScopeDaq->scopeUseType == 2) && (sCamaclink->IsDown()) )
602
/*          if( (gScopeDaq->scopeUseType == 2) && (sCamaclink->IsDown()) )
603
            {
603
            {
604
               StartScopeAcq();
604
               StartScopeAcq();
605
               evtmeas.measdata = gScopeDaq->measubuf;
605
               evtmeas.measdata = gScopeDaq->measubuf;
606
            }
606
            }
607
            scope_data->Fill();*/ // TODO
607
            scope_data->Fill();*/ // TODO
608
 
608
 
609
            // Start filling the histogram (only in normal single scan)
609
            // Start filling the histogram (only in normal single scan)
610
            if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
610
            if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
611
            {
611
            {
612
               liveHist->Fill(evtdata.adcdata[0]);
612
               liveHist->Fill(evtdata.adcdata[0]);
613
               if( n == (neve*liven)/10 )
613
               if( n == (neve*liven)/10 )
614
               {
614
               {
615
                  gCanvas->cd();
615
                  gCanvas->cd();
616
                  liveHist->Draw("");
616
                  liveHist->Draw("");
617
                  gCanvas->Modified();
617
                  gCanvas->Modified();
618
                  gCanvas->Update();
618
                  gCanvas->Update();
619
                  liven++;
619
                  liven++;
620
               }
620
               }
621
            }
621
            }
622
           
622
           
623
            nc += evtheader.nrch;
623
            nc += evtheader.nrch;
624
            nb -= evtheader.nrch;
624
            nb -= evtheader.nrch;
625
         }
625
         }
626
 
626
 
627
         MyTimer();
627
         MyTimer();
628
         allEvt = n;
628
         allEvt = n;
629
         if (gSystem->ProcessEvents()) printf("Run Interrupted\n");
629
         if (gSystem->ProcessEvents()) printf("Run Interrupted\n");
630
 
630
 
631
         if( acqStarted && (n == (neve*zProg)/10) && (!vscan && !pscan && !zscan && !ascan) )
631
         if( acqStarted && (n == (neve*zProg)/10) && (!vscan && !pscan && !zscan && !ascan) )
632
         {
632
         {
633
            // Progress the progress bar
633
            // Progress the progress bar
634
            progVal = (float)zProg*10;
634
            progVal = (float)zProg*10;
635
            measProgress->widgetPB->SetPosition(progVal);
635
            measProgress->widgetPB->SetPosition(progVal);
636
 
636
 
637
            // Calculate the remaining time
637
            // Calculate the remaining time
638
            TimeEstimate(clkt0, timet0, progVal, ctemp, 0);
638
            TimeEstimate(clkt0, timet0, progVal, ctemp, 0);
639
            printf("End time: %s\n", ctemp);
639
            printf("End time: %s\n", ctemp);
640
            measProgress->widgetTE->SetText(ctemp);
640
            measProgress->widgetTE->SetText(ctemp);
641
 
641
 
642
            gVirtualX->Update(1);
642
            gVirtualX->Update(1);
643
            zProg++;
643
            zProg++;
644
         }
644
         }
645
      }
645
      }
646
 
646
 
647
      printf("Number of gathered events: %d\n", allEvt);
647
      printf("Number of gathered events: %d\n", allEvt);
648
      measProgress->widgetTB[0]->SetText("Start acquisition");
648
      measProgress->widgetTB[0]->SetText("Start acquisition");
649
      acqStarted = false;
649
      acqStarted = false;
650
 
650
 
651
      gDaq->stop();
651
      gDaq->stop();
652
   }
652
   }
653
 
653
 
654
   printf("End of Run neve=%d\n",neve);
654
   printf("End of Run neve=%d\n",neve);
655
 
655
 
656
   header_data->Write();
656
   header_data->Write();
657
   meas_data->Write();
657
   meas_data->Write();
658
//   scope_data->Write(); // TODO
658
//   scope_data->Write(); // TODO
659
   delete header_data;
659
   delete header_data;
660
   delete meas_data;
660
   delete meas_data;
661
   delete scope_data;
661
   delete scope_data;
662
 
662
 
663
   // Remove the histogram
663
   // Remove the histogram
664
   if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
664
   if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
665
      delete liveHist;
665
      delete liveHist;
666
 
666
 
667
 
667
 
668
   outroot->Close();
668
   outroot->Close();
669
}
669
}
670
 
670
 
671
int TGAppMainFrame::MyTimer()
671
int TGAppMainFrame::MyTimer()
672
{
672
{
673
   char cmd[100];
673
   char cmd[100];
674
   GetTime(-1, cmd);
674
   GetTime(-1, cmd);
675
   if (timeStamp) timeStamp->widgetTE->SetText(cmd);
675
   if (timeStamp) timeStamp->widgetTE->SetText(cmd);
676
   return 0;
676
   return 0;
677
}
677
}
678
 
678
 
679
// Additional functions -------------------------------------
679
// Additional functions -------------------------------------
680
 
680
 
681
// Settings pane connections --------------------------------
681
// Settings pane connections --------------------------------
682
 
682
 
683
// Enable or disable scans
683
// Enable or disable scans
684
void TGAppMainFrame::EnableScan(int type)
684
void TGAppMainFrame::EnableScan(int type)
685
{
685
{
686
   // Voltage scan
686
   // Voltage scan
687
   if(type == 0)
687
   if(type == 0)
688
   {
688
   {
689
      if(scansOn->widgetChBox[type]->IsOn())
689
      if(scansOn->widgetChBox[type]->IsOn())
690
      {
690
      {
691
         vOutStart->widgetNE[0]->SetState(kTRUE);
691
         vOutStart->widgetNE[0]->SetState(kTRUE);
692
         vOutStop->widgetNE[0]->SetState(kTRUE);
692
         vOutStop->widgetNE[0]->SetState(kTRUE);
693
         vOutStep->widgetNE[0]->SetState(kTRUE);
693
         vOutStep->widgetNE[0]->SetState(kTRUE);
694
      }
694
      }
695
      else
695
      else
696
      {
696
      {
697
         vOutStart->widgetNE[0]->SetState(kFALSE);
697
         vOutStart->widgetNE[0]->SetState(kFALSE);
698
         vOutStop->widgetNE[0]->SetState(kFALSE);
698
         vOutStop->widgetNE[0]->SetState(kFALSE);
699
         vOutStep->widgetNE[0]->SetState(kFALSE);
699
         vOutStep->widgetNE[0]->SetState(kFALSE);
700
      }
700
      }
701
   }
701
   }
702
   // Surface (X, Y axis) scan
702
   // Surface (X, Y axis) scan
703
   else if(type == 1)
703
   else if(type == 1)
704
   {
704
   {
705
      if(scansOn->widgetChBox[type]->IsOn())
705
      if(scansOn->widgetChBox[type]->IsOn())
706
      {
706
      {
707
         xPosMin->widgetNE[0]->SetState(kTRUE);
707
         xPosMin->widgetNE[0]->SetState(kTRUE);
708
         xPosMax->widgetNE[0]->SetState(kTRUE);
708
         xPosMax->widgetNE[0]->SetState(kTRUE);
709
         xPosStep->widgetNE[0]->SetState(kTRUE);
709
         xPosStep->widgetNE[0]->SetState(kTRUE);
710
         yPosMin->widgetNE[0]->SetState(kTRUE);
710
         yPosMin->widgetNE[0]->SetState(kTRUE);
711
         yPosMax->widgetNE[0]->SetState(kTRUE);
711
         yPosMax->widgetNE[0]->SetState(kTRUE);
712
         yPosStep->widgetNE[0]->SetState(kTRUE);
712
         yPosStep->widgetNE[0]->SetState(kTRUE);
713
      }
713
      }
714
      else
714
      else
715
      {
715
      {
716
         xPosMin->widgetNE[0]->SetState(kFALSE);
716
         xPosMin->widgetNE[0]->SetState(kFALSE);
717
         xPosMax->widgetNE[0]->SetState(kFALSE);
717
         xPosMax->widgetNE[0]->SetState(kFALSE);
718
         xPosStep->widgetNE[0]->SetState(kFALSE);
718
         xPosStep->widgetNE[0]->SetState(kFALSE);
719
         yPosMin->widgetNE[0]->SetState(kFALSE);
719
         yPosMin->widgetNE[0]->SetState(kFALSE);
720
         yPosMax->widgetNE[0]->SetState(kFALSE);
720
         yPosMax->widgetNE[0]->SetState(kFALSE);
721
         yPosStep->widgetNE[0]->SetState(kFALSE);
721
         yPosStep->widgetNE[0]->SetState(kFALSE);
722
      }
722
      }
723
   }
723
   }
724
   // Z axis scan
724
   // Z axis scan
725
   else if(type == 2)
725
   else if(type == 2)
726
   {
726
   {
727
      if(scansOn->widgetChBox[type]->IsOn())
727
      if(scansOn->widgetChBox[type]->IsOn())
728
      {
728
      {
729
         zPosMin->widgetNE[0]->SetState(kTRUE);
729
         zPosMin->widgetNE[0]->SetState(kTRUE);
730
         zPosMax->widgetNE[0]->SetState(kTRUE);
730
         zPosMax->widgetNE[0]->SetState(kTRUE);
731
         zPosStep->widgetNE[0]->SetState(kTRUE);
731
         zPosStep->widgetNE[0]->SetState(kTRUE);
732
      }
732
      }
733
      else
733
      else
734
      {
734
      {
735
         zPosMin->widgetNE[0]->SetState(kFALSE);
735
         zPosMin->widgetNE[0]->SetState(kFALSE);
736
         zPosMax->widgetNE[0]->SetState(kFALSE);
736
         zPosMax->widgetNE[0]->SetState(kFALSE);
737
         zPosStep->widgetNE[0]->SetState(kFALSE);
737
         zPosStep->widgetNE[0]->SetState(kFALSE);
738
      }
738
      }
739
   }
739
   }
740
   // Incidence angle scan
740
   // Incidence angle scan
741
   else if(type == 3)
741
   else if(type == 3)
742
   {
742
   {
743
      if(scansOn->widgetChBox[type]->IsOn())
743
      if(scansOn->widgetChBox[type]->IsOn())
744
      {
744
      {
745
         rotPosMin->widgetNE[0]->SetState(kTRUE);
745
         rotPosMin->widgetNE[0]->SetState(kTRUE);
746
         rotPosMax->widgetNE[0]->SetState(kTRUE);
746
         rotPosMax->widgetNE[0]->SetState(kTRUE);
747
         rotPosStep->widgetNE[0]->SetState(kTRUE);
747
         rotPosStep->widgetNE[0]->SetState(kTRUE);
748
      }
748
      }
749
      else
749
      else
750
      {
750
      {
751
         rotPosMin->widgetNE[0]->SetState(kFALSE);
751
         rotPosMin->widgetNE[0]->SetState(kFALSE);
752
         rotPosMax->widgetNE[0]->SetState(kFALSE);
752
         rotPosMax->widgetNE[0]->SetState(kFALSE);
753
         rotPosStep->widgetNE[0]->SetState(kFALSE);
753
         rotPosStep->widgetNE[0]->SetState(kFALSE);
754
      }
754
      }
755
   }
755
   }
756
}
756
}
757
 
757
 
758
// Apply the upper voltage limit from settings pane to main window
758
// Apply the upper voltage limit from settings pane to main window
759
void TGAppMainFrame::VoltageLimit()
759
void TGAppMainFrame::VoltageLimit()
760
{
760
{
761
   vOut->widgetNE[0]->SetLimitValues(0, vHardlimit->widgetNE[0]->GetNumber() );
761
   vOut->widgetNE[0]->SetLimitValues(0, vHardlimit->widgetNE[0]->GetNumber() );
762
}
762
}
763
 
763
 
764
// Select the table position units to be used (1 = 0.3595 micron)
764
// Select the table position units to be used (1 = 0.3595 micron)
765
void TGAppMainFrame::ChangeUnits(int type)
765
void TGAppMainFrame::ChangeUnits(int type)
766
{
766
{
767
   int pos[12], poslim[3], chng = 0;
767
   int pos[12], poslim[3], chng = 0;
768
   double micro[12], microlim[3];
768
   double micro[12], microlim[3];
769
 
769
 
770
   TGNumberEntry *posEntries[12];
770
   TGNumberEntry *posEntries[12];
771
   posEntries[0] = (TGNumberEntry*)xPos->widgetNE[0];
771
   posEntries[0] = (TGNumberEntry*)xPos->widgetNE[0];
772
   posEntries[1] = (TGNumberEntry*)yPos->widgetNE[0];
772
   posEntries[1] = (TGNumberEntry*)yPos->widgetNE[0];
773
   posEntries[2] = (TGNumberEntry*)zPos->widgetNE[0];
773
   posEntries[2] = (TGNumberEntry*)zPos->widgetNE[0];
774
   posEntries[3] = (TGNumberEntry*)xPosMin->widgetNE[0];
774
   posEntries[3] = (TGNumberEntry*)xPosMin->widgetNE[0];
775
   posEntries[4] = (TGNumberEntry*)xPosMax->widgetNE[0];
775
   posEntries[4] = (TGNumberEntry*)xPosMax->widgetNE[0];
776
   posEntries[5] = (TGNumberEntry*)xPosStep->widgetNE[0];
776
   posEntries[5] = (TGNumberEntry*)xPosStep->widgetNE[0];
777
   posEntries[6] = (TGNumberEntry*)yPosMin->widgetNE[0];
777
   posEntries[6] = (TGNumberEntry*)yPosMin->widgetNE[0];
778
   posEntries[7] = (TGNumberEntry*)yPosMax->widgetNE[0];
778
   posEntries[7] = (TGNumberEntry*)yPosMax->widgetNE[0];
779
   posEntries[8] = (TGNumberEntry*)yPosStep->widgetNE[0];
779
   posEntries[8] = (TGNumberEntry*)yPosStep->widgetNE[0];
780
   posEntries[9] = (TGNumberEntry*)zPosMin->widgetNE[0];
780
   posEntries[9] = (TGNumberEntry*)zPosMin->widgetNE[0];
781
   posEntries[10] = (TGNumberEntry*)zPosMax->widgetNE[0];
781
   posEntries[10] = (TGNumberEntry*)zPosMax->widgetNE[0];
782
   posEntries[11] = (TGNumberEntry*)zPosStep->widgetNE[0];
782
   posEntries[11] = (TGNumberEntry*)zPosStep->widgetNE[0];
783
 
783
 
784
   // Table position values
784
   // Table position values
785
   if(type == 0)
785
   if(type == 0)
786
   {
786
   {
787
      // Check if we had microns before
787
      // Check if we had microns before
788
      if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo)
788
      if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo)
789
         chng = 1;
789
         chng = 1;
790
 
790
 
791
      // Change to table position values   
791
      // Change to table position values   
792
      if(chng == 1)
792
      if(chng == 1)
793
      {
793
      {
794
         for(int i = 0; i < 12; i++)
794
         for(int i = 0; i < 12; i++)
795
         {
795
         {
796
            if(posEntries[i]->GetNumber() == 0.0)
796
            if(posEntries[i]->GetNumber() == 0.0)
797
               pos[i] = 0;
797
               pos[i] = 0;
798
            else
798
            else
799
               pos[i] = (int)posEntries[i]->GetNumber()/lenconversion;
799
               pos[i] = (int)posEntries[i]->GetNumber()/lenconversion;
800
         }
800
         }
801
 
801
 
802
         poslim[0] = -100;
802
         poslim[0] = -100;
803
         poslim[1] = 215000;
803
         poslim[1] = 215000;
804
         poslim[2] = 375000;
804
         poslim[2] = 375000;
805
 
805
 
806
         for(int i = 0; i < 12; i++)
806
         for(int i = 0; i < 12; i++)
807
         {
807
         {
808
            posEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger);
808
            posEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger);
809
            if( (i > 8) || (i == 2) ) // limits for Z axis (longer table)
809
            if( (i > 8) || (i == 2) ) // limits for Z axis (longer table)
810
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[2]);
810
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[2]);
811
            else
811
            else
812
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[1]);
812
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[1]);
813
 
813
 
814
            posEntries[i]->SetNumber(pos[i]);
814
            posEntries[i]->SetNumber(pos[i]);
815
         }
815
         }
816
      }
816
      }
817
   }
817
   }
818
   // Microns
818
   // Microns
819
   else if(type == 1)
819
   else if(type == 1)
820
   {
820
   {
821
      // Check if we had table position values before
821
      // Check if we had table position values before
822
      if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger)
822
      if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger)
823
         chng = 1;
823
         chng = 1;
824
 
824
 
825
      // Change to microns   
825
      // Change to microns   
826
      if(chng == 1)
826
      if(chng == 1)
827
      {
827
      {
828
         for(int i = 0; i < 12; i++)
828
         for(int i = 0; i < 12; i++)
829
         {
829
         {
830
            if(posEntries[i]->GetNumber() == 0.0)
830
            if(posEntries[i]->GetNumber() == 0.0)
831
               micro[i] = 0.;
831
               micro[i] = 0.;
832
            else
832
            else
833
               micro[i] = (double)posEntries[i]->GetNumber()*lenconversion;
833
               micro[i] = (double)posEntries[i]->GetNumber()*lenconversion;
834
         }
834
         }
835
   
835
   
836
         microlim[0] = (double)-100*lenconversion;
836
         microlim[0] = (double)-100*lenconversion;
837
         microlim[1] = (double)215000*lenconversion;
837
         microlim[1] = (double)215000*lenconversion;
838
         microlim[2] = (double)375000*lenconversion;
838
         microlim[2] = (double)375000*lenconversion;
839
   
839
   
840
         for(int i = 0; i < 12; i++)
840
         for(int i = 0; i < 12; i++)
841
         {
841
         {
842
            posEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo);
842
            posEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo);
843
            if( (i > 8) || (i == 2) ) // limits for Z axis (longer table)
843
            if( (i > 8) || (i == 2) ) // limits for Z axis (longer table)
844
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[2]);
844
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[2]);
845
            else
845
            else
846
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[1]);
846
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[1]);
847
   
847
   
848
            posEntries[i]->SetNumber(micro[i]);
848
            posEntries[i]->SetNumber(micro[i]);
849
         }
849
         }
850
      }
850
      }
851
   }
851
   }
852
}
852
}
853
 
853
 
854
// Select the rotation units to be used (1 = 6.3281/3600 degrees)
854
// Select the rotation units to be used (1 = 6.3281/3600 degrees)
855
void TGAppMainFrame::ChangeUnitsRot(int type)
855
void TGAppMainFrame::ChangeUnitsRot(int type)
856
{
856
{
857
   int rot[4], rotlim[2], chng = 0;
857
   int rot[4], rotlim[2], chng = 0;
858
   double deg[4], deglim[2];
858
   double deg[4], deglim[2];
859
 
859
 
860
   TGNumberEntry *rotEntries[4];
860
   TGNumberEntry *rotEntries[4];
861
   rotEntries[0] = (TGNumberEntry*)rotPos->widgetNE[0];
861
   rotEntries[0] = (TGNumberEntry*)rotPos->widgetNE[0];
862
   rotEntries[1] = (TGNumberEntry*)rotPosMin->widgetNE[0];
862
   rotEntries[1] = (TGNumberEntry*)rotPosMin->widgetNE[0];
863
   rotEntries[2] = (TGNumberEntry*)rotPosMax->widgetNE[0];
863
   rotEntries[2] = (TGNumberEntry*)rotPosMax->widgetNE[0];
864
   rotEntries[3] = (TGNumberEntry*)rotPosStep->widgetNE[0];
864
   rotEntries[3] = (TGNumberEntry*)rotPosStep->widgetNE[0];
865
 
865
 
866
   // Rotation values
866
   // Rotation values
867
   if(type == 0)
867
   if(type == 0)
868
   {
868
   {
869
      // Check if we had degrees before
869
      // Check if we had degrees before
870
      if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo)
870
      if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo)
871
         chng = 1;
871
         chng = 1;
872
 
872
 
873
      // Change to rotation values   
873
      // Change to rotation values   
874
      if(chng == 1)
874
      if(chng == 1)
875
      {
875
      {
876
         for(int i = 0; i < 4; i++)
876
         for(int i = 0; i < 4; i++)
877
         {
877
         {
878
            if(rotEntries[i]->GetNumber() == 0.0)
878
            if(rotEntries[i]->GetNumber() == 0.0)
879
               rot[i] = 0;
879
               rot[i] = 0;
880
            else
880
            else
881
               rot[i] = (int)rotEntries[i]->GetNumber()/rotconversion;
881
               rot[i] = (int)rotEntries[i]->GetNumber()/rotconversion;
882
         }
882
         }
883
 
883
 
884
         rotlim[0] = (int)-180/rotconversion;
884
         rotlim[0] = (int)-180/rotconversion;
885
         rotlim[1] = (int)180/rotconversion;
885
         rotlim[1] = (int)180/rotconversion;
886
 
886
 
887
         for(int i = 0; i < 4; i++)
887
         for(int i = 0; i < 4; i++)
888
         {
888
         {
889
            rotEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger);
889
            rotEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger);
890
            rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, rotlim[0], rotlim[1]);
890
            rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, rotlim[0], rotlim[1]);
891
 
891
 
892
            rotEntries[i]->SetNumber(rot[i]);
892
            rotEntries[i]->SetNumber(rot[i]);
893
         }
893
         }
894
      }
894
      }
895
   }
895
   }
896
   // Degree
896
   // Degree
897
   else if(type == 1)
897
   else if(type == 1)
898
   {
898
   {
899
      // Check if we had table position values before
899
      // Check if we had table position values before
900
      if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger)
900
      if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger)
901
         chng = 1;
901
         chng = 1;
902
 
902
 
903
      // Change to degrees   
903
      // Change to degrees   
904
      if(chng == 1)
904
      if(chng == 1)
905
      {
905
      {
906
         for(int i = 0; i < 4; i++)
906
         for(int i = 0; i < 4; i++)
907
         {
907
         {
908
            if(rotEntries[i]->GetNumber() == 0)
908
            if(rotEntries[i]->GetNumber() == 0)
909
               deg[i] = 0.;
909
               deg[i] = 0.;
910
            else
910
            else
911
               deg[i] = (double)rotEntries[i]->GetNumber()*rotconversion;
911
               deg[i] = (double)rotEntries[i]->GetNumber()*rotconversion;
912
         }
912
         }
913
   
913
   
914
         deglim[0] = -180.;
914
         deglim[0] = -180.;
915
         deglim[1] = 180.;
915
         deglim[1] = 180.;
916
   
916
   
917
         for(int i = 0; i < 4; i++)
917
         for(int i = 0; i < 4; i++)
918
         {
918
         {
919
            rotEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo);
919
            rotEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo);
920
            rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, deglim[0], deglim[1]);
920
            rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, deglim[0], deglim[1]);
921
   
921
   
922
            rotEntries[i]->SetNumber(deg[i]);
922
            rotEntries[i]->SetNumber(deg[i]);
923
         }
923
         }
924
      }
924
      }
925
   }
925
   }
926
}
926
}
927
 
927
 
928
// Enable display canvas to have a live update of histogram
928
// Enable display canvas to have a live update of histogram
929
void TGAppMainFrame::EnableLiveUpdate()
929
void TGAppMainFrame::EnableLiveUpdate()
930
{
930
{
931
   liveUpdate = liveDisp->widgetChBox[0]->IsDown();
931
   liveUpdate = liveDisp->widgetChBox[0]->IsDown();
932
}
932
}
933
 
933
 
934
// Settings pane connections --------------------------------
934
// Settings pane connections --------------------------------
935
 
935
 
936
// Main measurement window connections ----------------------
936
// Main measurement window connections ----------------------
937
 
937
 
938
// Get the currently selected channel
938
// Get the currently selected channel
939
int TGAppMainFrame::GetChannel()
939
int TGAppMainFrame::GetChannel()
940
{
940
{
941
   int selectedOutput;
941
   int selectedOutput;
942
   if(vOutCh->widgetCB->GetSelected() < 8) selectedOutput = (vOutCh->widgetCB->GetSelected())+1;
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;
943
   else if( (vOutCh->widgetCB->GetSelected() >= 8) && (vOutCh->widgetCB->GetSelected() < 16) ) selectedOutput = (vOutCh->widgetCB->GetSelected())+93;
944
   else selectedOutput = 1;
944
   else selectedOutput = 1;
945
 
945
 
946
   return selectedOutput;
946
   return selectedOutput;
947
}
947
}
948
 
948
 
949
// Set, get or reset the output voltage
949
// Set, get or reset the output voltage
950
void TGAppMainFrame::VoltOut(int opt)
950
void TGAppMainFrame::VoltOut(int opt)
951
{
951
{
952
   char cmd[256];
952
   char cmd[256];
953
 
953
 
954
   // Set the selected voltage
954
   // Set the selected voltage
955
   if(opt == 0)
955
   if(opt == 0)
956
   {
956
   {
957
      int outOn;
957
      int outOn;
958
      float outputVoltage;
958
      float outputVoltage;
959
     
959
     
960
      outputVoltage = vOut->widgetNE[0]->GetNumber();
960
      outputVoltage = vOut->widgetNE[0]->GetNumber();
961
   
961
   
962
      if(vOutOpt->widgetChBox[1]->IsOn()) outOn = 1;
962
      if(vOutOpt->widgetChBox[1]->IsOn()) outOn = 1;
963
      else outOn = 0;
963
      else outOn = 0;
964
     
964
     
965
      fflush(stdout);
965
      fflush(stdout);
966
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s %d", rootdir, GetChannel(), outputVoltage, outOn);
966
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s %d", rootdir, GetChannel(), outputVoltage, outOn);
967
#if WORKSTAT == 'I'
967
#if WORKSTAT == 'I'
968
      retTemp = system(cmd);
968
      retTemp = system(cmd);
969
#else
969
#else
970
      printf("Cmd: %s\n",cmd);
970
      printf("Cmd: %s\n",cmd);
971
#endif
971
#endif
972
      fflush(stdout);
972
      fflush(stdout);
973
   }
973
   }
974
   // Get current voltage
974
   // Get current voltage
975
   else if(opt == 1)
975
   else if(opt == 1)
976
   {
976
   {
977
      fflush(stdout);
977
      fflush(stdout);
978
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -g > %s/settings/curvolt.txt", rootdir, GetChannel(), rootdir);
978
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -g > %s/settings/curvolt.txt", rootdir, GetChannel(), rootdir);
979
#if WORKSTAT == 'I'
979
#if WORKSTAT == 'I'
980
      retTemp = system(cmd);
980
      retTemp = system(cmd);
981
#else
981
#else
982
      printf("Cmd: %s\n",cmd);
982
      printf("Cmd: %s\n",cmd);
983
#endif
983
#endif
984
      fflush(stdout);
984
      fflush(stdout);
985
 
985
 
986
#if WORKSTAT == 'I'
986
#if WORKSTAT == 'I'
987
      FILE* fvolt;
987
      FILE* fvolt;
988
      double dtemp;
988
      double dtemp;
989
      char ctemp[24];
989
      char ctemp[24];
990
      sprintf(cmd, "%s/settings/curvolt.txt", rootdir);
990
      sprintf(cmd, "%s/settings/curvolt.txt", rootdir);
991
      fvolt = fopen(cmd, "r");
991
      fvolt = fopen(cmd, "r");
992
     
992
     
993
      if(fvolt != NULL)
993
      if(fvolt != NULL)
994
      {
994
      {
995
         sprintf(cmd, "WIENER-CRATE-MIB::outputVoltage.u%d = Opaque: Float: %s V\n", GetChannel()-1, "%lf" );
995
         sprintf(cmd, "WIENER-CRATE-MIB::outputVoltage.u%d = Opaque: Float: %s V\n", GetChannel()-1, "%lf" );
996
         retTemp = fscanf(fvolt, cmd, &dtemp);
996
         retTemp = fscanf(fvolt, cmd, &dtemp);
997
         vOut->widgetNE[0]->SetNumber(dtemp);
997
         vOut->widgetNE[0]->SetNumber(dtemp);
998
         sprintf(cmd, "WIENER-CRATE-MIB::outputSwitch.u%d = INTEGER: %s\n", GetChannel()-1, "%s" );
998
         sprintf(cmd, "WIENER-CRATE-MIB::outputSwitch.u%d = INTEGER: %s\n", GetChannel()-1, "%s" );
999
         retTemp = fscanf(fvolt, cmd, ctemp);
999
         retTemp = fscanf(fvolt, cmd, ctemp);
1000
         if( strcmp(ctemp, "On(1)") == 0 )
1000
         if( strcmp(ctemp, "On(1)") == 0 )
1001
            vOutOpt->widgetChBox[1]->SetState(kButtonDown);
1001
            vOutOpt->widgetChBox[1]->SetState(kButtonDown);
1002
         else if( strcmp(ctemp, "Off(0)") == 0 )
1002
         else if( strcmp(ctemp, "Off(0)") == 0 )
1003
            vOutOpt->widgetChBox[1]->SetState(kButtonUp);
1003
            vOutOpt->widgetChBox[1]->SetState(kButtonUp);
1004
      }
1004
      }
1005
   
1005
   
1006
      fclose(fvolt);
1006
      fclose(fvolt);
1007
#endif
1007
#endif
1008
   }
1008
   }
1009
   // Reset output voltage (if stuck in interlock)
1009
   // Reset output voltage (if stuck in interlock)
1010
   else if(opt == 2)
1010
   else if(opt == 2)
1011
   {
1011
   {
1012
      vOut->widgetNE[0]->SetNumber(0.000);
1012
      vOut->widgetNE[0]->SetNumber(0.000);
1013
      vOutOpt->widgetChBox[1]->SetState(kButtonUp);
1013
      vOutOpt->widgetChBox[1]->SetState(kButtonUp);
1014
 
1014
 
1015
      fflush(stdout);
1015
      fflush(stdout);
1016
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -r %d", rootdir, GetChannel());
1016
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -r %d", rootdir, GetChannel());
1017
#if WORKSTAT == 'I'
1017
#if WORKSTAT == 'I'
1018
      retTemp = system(cmd);
1018
      retTemp = system(cmd);
1019
#else
1019
#else
1020
      printf("Cmd: %s\n",cmd);
1020
      printf("Cmd: %s\n",cmd);
1021
#endif
1021
#endif
1022
      fflush(stdout);
1022
      fflush(stdout);
1023
   }
1023
   }
1024
}
1024
}
1025
 
1025
 
1026
// Set output voltage polarity to negative
1026
// Set output voltage polarity to negative
1027
void TGAppMainFrame::NegativePolarity()
1027
void TGAppMainFrame::NegativePolarity()
1028
{
1028
{
1029
   double newHardlimit;
1029
   double newHardlimit;
1030
   int polar = 0;  // 0 = positive, 1 = negative
1030
   int polar = 0;  // 0 = positive, 1 = negative
1031
 
1031
 
1032
   if(vOutOpt->widgetChBox[0]->IsOn())
1032
   if(vOutOpt->widgetChBox[0]->IsOn())
1033
      polar = 1;
1033
      polar = 1;
1034
   else
1034
   else
1035
      polar = 0;
1035
      polar = 0;
1036
 
1036
 
1037
   // Set hard limit to the negative version of what it was before
1037
   // Set hard limit to the negative version of what it was before
1038
   if( (vHardlimit->widgetNE[0]->GetNumber() > 0.) && (polar == 1) )
1038
   if( (vHardlimit->widgetNE[0]->GetNumber() > 0.) && (polar == 1) )
1039
      newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber());
1039
      newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber());
1040
   else if( (vHardlimit->widgetNE[0]->GetNumber() < 0.) && (polar == 0) )
1040
   else if( (vHardlimit->widgetNE[0]->GetNumber() < 0.) && (polar == 0) )
1041
      newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber());
1041
      newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber());
1042
   else if(vHardlimit->widgetNE[0]->GetNumber() == 0.)
1042
   else if(vHardlimit->widgetNE[0]->GetNumber() == 0.)
1043
      newHardlimit = 0.;
1043
      newHardlimit = 0.;
1044
   else
1044
   else
1045
      newHardlimit = vHardlimit->widgetNE[0]->GetNumber();
1045
      newHardlimit = vHardlimit->widgetNE[0]->GetNumber();
1046
 
1046
 
1047
   // Apropriately set the limit to the output voltage number entry
1047
   // Apropriately set the limit to the output voltage number entry
1048
   vHardlimit->widgetNE[0]->SetNumber(newHardlimit);
1048
   vHardlimit->widgetNE[0]->SetNumber(newHardlimit);
1049
 
1049
 
1050
   if(polar == 1)
1050
   if(polar == 1)
1051
      vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, newHardlimit, 0.);
1051
      vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, newHardlimit, 0.);
1052
   else if(polar == 0)
1052
   else if(polar == 0)
1053
      vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, 0., newHardlimit);
1053
      vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, 0., newHardlimit);
1054
}
1054
}
1055
 
1055
 
1056
// Set, get, home or reset the table position
1056
// Set, get, home or reset the table position
1057
void TGAppMainFrame::PositionSet(int opt)
1057
void TGAppMainFrame::PositionSet(int opt)
1058
{
1058
{
1059
   char cmd[1024];
1059
   char cmd[1024];
1060
 
1060
 
1061
   // Set the selected table position
1061
   // Set the selected table position
1062
   if(opt == 0)
1062
   if(opt == 0)
1063
   {
1063
   {
1064
      int positX, positY, positZ;
1064
      int positX, positY, positZ;
1065
 
1065
 
1066
      if(posUnits->widgetCB->GetSelected() == 0)
1066
      if(posUnits->widgetCB->GetSelected() == 0)
1067
      {
1067
      {
1068
         positX = xPos->widgetNE[0]->GetNumber();
1068
         positX = xPos->widgetNE[0]->GetNumber();
1069
         positY = yPos->widgetNE[0]->GetNumber();
1069
         positY = yPos->widgetNE[0]->GetNumber();
1070
         positZ = zPos->widgetNE[0]->GetNumber();
1070
         positZ = zPos->widgetNE[0]->GetNumber();
1071
      }
1071
      }
1072
      else if(posUnits->widgetCB->GetSelected() == 1)
1072
      else if(posUnits->widgetCB->GetSelected() == 1)
1073
      {
1073
      {
1074
         positX = (int)xPos->widgetNE[0]->GetNumber()/lenconversion;
1074
         positX = (int)xPos->widgetNE[0]->GetNumber()/lenconversion;
1075
         positY = (int)yPos->widgetNE[0]->GetNumber()/lenconversion;
1075
         positY = (int)yPos->widgetNE[0]->GetNumber()/lenconversion;
1076
         positZ = (int)zPos->widgetNE[0]->GetNumber()/lenconversion;
1076
         positZ = (int)zPos->widgetNE[0]->GetNumber()/lenconversion;
1077
      }
1077
      }
1078
 
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);
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'
1080
#if WORKSTAT == 'I'
1081
      retTemp = system(cmd);
1081
      retTemp = system(cmd);
1082
#else
1082
#else
1083
      printf("Cmd: %s\n",cmd);
1083
      printf("Cmd: %s\n",cmd);
1084
#endif
1084
#endif
1085
 
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);
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'
1087
#if WORKSTAT == 'I'
1088
      retTemp = system(cmd);
1088
      retTemp = system(cmd);
1089
#else
1089
#else
1090
      printf("Cmd: %s\n",cmd);
1090
      printf("Cmd: %s\n",cmd);
1091
#endif
1091
#endif
1092
 
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);
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'
1094
#if WORKSTAT == 'I'
1095
      retTemp = system(cmd);
1095
      retTemp = system(cmd);
1096
#else
1096
#else
1097
      printf("Cmd: %s\n",cmd);
1097
      printf("Cmd: %s\n",cmd);
1098
#endif
1098
#endif
1099
   }
1099
   }
1100
   // Get current table position
1100
   // Get current table position
1101
   else if(opt == 1)
1101
   else if(opt == 1)
1102
   {
1102
   {
1103
      fflush(stdout);
1103
      fflush(stdout);
1104
   
1104
   
1105
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -p > %s/settings/curpos.txt", rootdir, rootdir);  // X-axis
1105
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -p > %s/settings/curpos.txt", rootdir, rootdir);  // X-axis
1106
      fflush(stdout);
1106
      fflush(stdout);
1107
#if WORKSTAT == 'I'
1107
#if WORKSTAT == 'I'
1108
      retTemp = system(cmd);
1108
      retTemp = system(cmd);
1109
#else
1109
#else
1110
      printf("Cmd: %s\n",cmd);
1110
      printf("Cmd: %s\n",cmd);
1111
#endif
1111
#endif
1112
   
1112
   
1113
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Y-axis
1113
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Y-axis
1114
      fflush(stdout);
1114
      fflush(stdout);
1115
#if WORKSTAT == 'I'
1115
#if WORKSTAT == 'I'
1116
      retTemp = system(cmd);
1116
      retTemp = system(cmd);
1117
#else
1117
#else
1118
      printf("Cmd: %s\n",cmd);
1118
      printf("Cmd: %s\n",cmd);
1119
#endif
1119
#endif
1120
   
1120
   
1121
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Z-axis
1121
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Z-axis
1122
      fflush(stdout);
1122
      fflush(stdout);
1123
#if WORKSTAT == 'I'
1123
#if WORKSTAT == 'I'
1124
      retTemp = system(cmd);
1124
      retTemp = system(cmd);
1125
#else
1125
#else
1126
      printf("Cmd: %s\n",cmd);
1126
      printf("Cmd: %s\n",cmd);
1127
#endif
1127
#endif
1128
 
1128
 
1129
#if WORKSTAT == 'I'
1129
#if WORKSTAT == 'I'
1130
      FILE* fpos;
1130
      FILE* fpos;
1131
      int itemp;
1131
      int itemp;
1132
      sprintf(cmd, "%s/settings/curpos.txt", rootdir);
1132
      sprintf(cmd, "%s/settings/curpos.txt", rootdir);
1133
      fpos = fopen(cmd, "r");
1133
      fpos = fopen(cmd, "r");
1134
     
1134
     
1135
      if(fpos != NULL)
1135
      if(fpos != NULL)
1136
      {
1136
      {
1137
         if(posUnits->widgetCB->GetSelected() == 0)
1137
         if(posUnits->widgetCB->GetSelected() == 0)
1138
         {
1138
         {
1139
            retTemp = fscanf(fpos, "%d\n", &itemp);
1139
            retTemp = fscanf(fpos, "%d\n", &itemp);
1140
            xPos->widgetNE[0]->SetNumber(itemp);
1140
            xPos->widgetNE[0]->SetNumber(itemp);
1141
            retTemp = fscanf(fpos, "%d\n", &itemp);
1141
            retTemp = fscanf(fpos, "%d\n", &itemp);
1142
            yPos->widgetNE[0]->SetNumber(itemp);
1142
            yPos->widgetNE[0]->SetNumber(itemp);
1143
            retTemp = fscanf(fpos, "%d\n", &itemp);
1143
            retTemp = fscanf(fpos, "%d\n", &itemp);
1144
            zPos->widgetNE[0]->SetNumber(itemp);
1144
            zPos->widgetNE[0]->SetNumber(itemp);
1145
         }
1145
         }
1146
         else if(posUnits->widgetCB->GetSelected() == 1)
1146
         else if(posUnits->widgetCB->GetSelected() == 1)
1147
         {
1147
         {
1148
            retTemp = fscanf(fpos, "%d\n", &itemp);
1148
            retTemp = fscanf(fpos, "%d\n", &itemp);
1149
            xPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1149
            xPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1150
            retTemp = fscanf(fpos, "%d\n", &itemp);
1150
            retTemp = fscanf(fpos, "%d\n", &itemp);
1151
            yPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1151
            yPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1152
            retTemp = fscanf(fpos, "%d\n", &itemp);
1152
            retTemp = fscanf(fpos, "%d\n", &itemp);
1153
            zPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1153
            zPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1154
         }
1154
         }
1155
      }
1155
      }
1156
 
1156
 
1157
      fclose(fpos);
1157
      fclose(fpos);
1158
#endif
1158
#endif
1159
   }
1159
   }
1160
   // Home the table position
1160
   // Home the table position
1161
   else if(opt == 2)
1161
   else if(opt == 2)
1162
   {
1162
   {
1163
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -h", rootdir);    // X-axis
1163
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -h", rootdir);    // X-axis
1164
#if WORKSTAT == 'I'
1164
#if WORKSTAT == 'I'
1165
      retTemp = system(cmd);
1165
      retTemp = system(cmd);
1166
#else
1166
#else
1167
      printf("Cmd: %s\n",cmd);
1167
      printf("Cmd: %s\n",cmd);
1168
#endif
1168
#endif
1169
 
1169
 
1170
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -h", rootdir);    // Y-axis
1170
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -h", rootdir);    // Y-axis
1171
#if WORKSTAT == 'I'
1171
#if WORKSTAT == 'I'
1172
      retTemp = system(cmd);
1172
      retTemp = system(cmd);
1173
#else
1173
#else
1174
      printf("Cmd: %s\n",cmd);
1174
      printf("Cmd: %s\n",cmd);
1175
#endif
1175
#endif
1176
 
1176
 
1177
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -h", rootdir);    // Z-axis
1177
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -h", rootdir);    // Z-axis
1178
#if WORKSTAT == 'I'
1178
#if WORKSTAT == 'I'
1179
      retTemp = system(cmd);
1179
      retTemp = system(cmd);
1180
#else
1180
#else
1181
      printf("Cmd: %s\n",cmd);
1181
      printf("Cmd: %s\n",cmd);
1182
#endif
1182
#endif
1183
      PositionSet(1);
1183
      PositionSet(1);
1184
   }
1184
   }
1185
   // Reset the table position
1185
   // Reset the table position
1186
   else if(opt == 3)
1186
   else if(opt == 3)
1187
   {
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
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'
1189
#if WORKSTAT == 'I'
1190
      printf("Positioning table reset, initialization and homing in progress. Please wait...\n");
1190
      printf("Positioning table reset, initialization and homing in progress. Please wait...\n");
1191
      retTemp = system(cmd);
1191
      retTemp = system(cmd);
1192
#else
1192
#else
1193
      printf("Cmd: %s\n",cmd);
1193
      printf("Cmd: %s\n",cmd);
1194
#endif
1194
#endif
1195
 
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
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'
1197
#if WORKSTAT == 'I'
1198
      retTemp = system(cmd);
1198
      retTemp = system(cmd);
1199
#else
1199
#else
1200
      printf("Cmd: %s\n",cmd);
1200
      printf("Cmd: %s\n",cmd);
1201
#endif
1201
#endif
1202
 
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
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'
1204
#if WORKSTAT == 'I'
1205
      retTemp = system(cmd);
1205
      retTemp = system(cmd);
1206
      printf("Positioning table reset, initialization and homing complete.\n");
1206
      printf("Positioning table reset, initialization and homing complete.\n");
1207
#else
1207
#else
1208
      printf("Cmd: %s\n",cmd);
1208
      printf("Cmd: %s\n",cmd);
1209
#endif
1209
#endif
1210
      PositionSet(1);
1210
      PositionSet(1);
1211
   }
1211
   }
1212
   // Abort any motion
1212
   // Abort any motion
1213
   else if(opt == 4)
1213
   else if(opt == 4)
1214
   {
1214
   {
1215
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -c ab", rootdir); // X-axis
1215
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -c ab", rootdir); // X-axis
1216
#if WORKSTAT == 'I'
1216
#if WORKSTAT == 'I'
1217
      printf("Emergency stop of the current movement of all linear tables.\n");
1217
      printf("Emergency stop of the current movement of all linear tables.\n");
1218
      retTemp = system(cmd);
1218
      retTemp = system(cmd);
1219
#else
1219
#else
1220
      printf("Cmd: %s\n",cmd);
1220
      printf("Cmd: %s\n",cmd);
1221
#endif
1221
#endif
1222
 
1222
 
1223
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -c ab", rootdir); // Y-axis
1223
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -c ab", rootdir); // Y-axis
1224
#if WORKSTAT == 'I'
1224
#if WORKSTAT == 'I'
1225
      retTemp = system(cmd);
1225
      retTemp = system(cmd);
1226
#else
1226
#else
1227
      printf("Cmd: %s\n",cmd);
1227
      printf("Cmd: %s\n",cmd);
1228
#endif
1228
#endif
1229
 
1229
 
1230
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -c ab", rootdir); // Z-axis
1230
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -c ab", rootdir); // Z-axis
1231
#if WORKSTAT == 'I'
1231
#if WORKSTAT == 'I'
1232
      retTemp = system(cmd);
1232
      retTemp = system(cmd);
1233
#else
1233
#else
1234
      printf("Cmd: %s\n",cmd);
1234
      printf("Cmd: %s\n",cmd);
1235
#endif
1235
#endif
1236
      PositionSet(1);
1236
      PositionSet(1);
1237
   }
1237
   }
1238
}
1238
}
1239
 
1239
 
1240
// Set, get, home or reset the rotation platform
1240
// Set, get, home or reset the rotation platform
1241
void TGAppMainFrame::RotationSet(int opt)
1241
void TGAppMainFrame::RotationSet(int opt)
1242
{
1242
{
1243
   char cmd[1024];
1243
   char cmd[1024];
1244
 
1244
 
1245
   // Set the selected rotation
1245
   // Set the selected rotation
1246
   if(opt == 0)
1246
   if(opt == 0)
1247
   {
1247
   {
1248
      int positAlpha;
1248
      int positAlpha;
1249
 
1249
 
1250
      if(rotUnits->widgetCB->GetSelected() == 0)
1250
      if(rotUnits->widgetCB->GetSelected() == 0)
1251
         positAlpha = rotPos->widgetNE[0]->GetNumber();
1251
         positAlpha = rotPos->widgetNE[0]->GetNumber();
1252
      else if(rotUnits->widgetCB->GetSelected() == 1)
1252
      else if(rotUnits->widgetCB->GetSelected() == 1)
1253
         positAlpha = rotPos->widgetNE[0]->GetNumber()/rotconversion;
1253
         positAlpha = rotPos->widgetNE[0]->GetNumber()/rotconversion;
1254
 
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);
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'
1256
#if WORKSTAT == 'I'
1257
      retTemp = system(cmd);
1257
      retTemp = system(cmd);
1258
#else
1258
#else
1259
      printf("Cmd: %s\n",cmd);
1259
      printf("Cmd: %s\n",cmd);
1260
#endif
1260
#endif
1261
   }
1261
   }
1262
   // Get current rotation
1262
   // Get current rotation
1263
   else if(opt == 1)
1263
   else if(opt == 1)
1264
   {
1264
   {
1265
      fflush(stdout);
1265
      fflush(stdout);
1266
   
1266
   
1267
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -p > %s/settings/currot.txt", rootdir, rootdir);
1267
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -p > %s/settings/currot.txt", rootdir, rootdir);
1268
      fflush(stdout);
1268
      fflush(stdout);
1269
#if WORKSTAT == 'I'
1269
#if WORKSTAT == 'I'
1270
      retTemp = system(cmd);
1270
      retTemp = system(cmd);
1271
#else
1271
#else
1272
      printf("Cmd: %s\n",cmd);
1272
      printf("Cmd: %s\n",cmd);
1273
#endif
1273
#endif
1274
 
1274
 
1275
#if WORKSTAT == 'I'
1275
#if WORKSTAT == 'I'
1276
      FILE* frot;
1276
      FILE* frot;
1277
      int itemp;
1277
      int itemp;
1278
      sprintf(cmd, "%s/settings/currot.txt", rootdir);
1278
      sprintf(cmd, "%s/settings/currot.txt", rootdir);
1279
      frot = fopen(cmd, "r");
1279
      frot = fopen(cmd, "r");
1280
 
1280
 
1281
      if(frot != NULL)
1281
      if(frot != NULL)
1282
      {
1282
      {
1283
         retTemp = fscanf(frot, "%d\n", &itemp);
1283
         retTemp = fscanf(frot, "%d\n", &itemp);
1284
         if(rotUnits->widgetCB->GetSelected() == 0)
1284
         if(rotUnits->widgetCB->GetSelected() == 0)
1285
            rotPos->widgetNE[0]->SetNumber(itemp);
1285
            rotPos->widgetNE[0]->SetNumber(itemp);
1286
         else if(rotUnits->widgetCB->GetSelected() == 1)
1286
         else if(rotUnits->widgetCB->GetSelected() == 1)
1287
            rotPos->widgetNE[0]->SetNumber((double)itemp*rotconversion);
1287
            rotPos->widgetNE[0]->SetNumber((double)itemp*rotconversion);
1288
      }
1288
      }
1289
 
1289
 
1290
      fclose(frot);
1290
      fclose(frot);
1291
#endif
1291
#endif
1292
   }
1292
   }
1293
   // Home the rotation
1293
   // Home the rotation
1294
   else if(opt == 2)
1294
   else if(opt == 2)
1295
   {
1295
   {
1296
      // TODO: For now only set back to 0, not home!
1296
      // TODO: For now only set back to 0, not home!
1297
//      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -h", rootdir);
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);
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'
1299
#if WORKSTAT == 'I'
1300
      retTemp = system(cmd);
1300
      retTemp = system(cmd);
1301
#else
1301
#else
1302
      printf("Cmd: %s\n",cmd);
1302
      printf("Cmd: %s\n",cmd);
1303
#endif
1303
#endif
1304
      RotationSet(1);
1304
      RotationSet(1);
1305
   }
1305
   }
1306
   // Reset the rotation
1306
   // Reset the rotation
1307
   else if(opt == 3)
1307
   else if(opt == 3)
1308
   {
1308
   {
1309
      // TODO: For now only set back to 0, not home!
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);
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'
1311
#if WORKSTAT == 'I'
1312
      printf("Rotation platform reset, initalization and homing in progress. Please wait...\n");
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);
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);
1314
      retTemp = system(cmd);
1315
      sleep(15);        // wait for the motor to change position from wherever to 0
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);
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);
1317
      retTemp = system(cmd);
1318
      printf("Rotation platform reset, initalization and homing complete.\n");
1318
      printf("Rotation platform reset, initalization and homing complete.\n");
1319
#else
1319
#else
1320
      printf("Cmd: %s\n",cmd);
1320
      printf("Cmd: %s\n",cmd);
1321
#endif
1321
#endif
1322
      RotationSet(1);
1322
      RotationSet(1);
1323
   }
1323
   }
1324
   // Abort any motion
1324
   // Abort any motion
1325
   else if(opt == 4)
1325
   else if(opt == 4)
1326
   {
1326
   {
1327
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -c ab", rootdir);
1327
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -c ab", rootdir);
1328
#if WORKSTAT == 'I'
1328
#if WORKSTAT == 'I'
1329
      printf("Emergency stop of the current movement of the rotation platform.\n");
1329
      printf("Emergency stop of the current movement of the rotation platform.\n");
1330
      retTemp = system(cmd);
1330
      retTemp = system(cmd);
1331
#else
1331
#else
1332
      printf("Cmd: %s\n",cmd);
1332
      printf("Cmd: %s\n",cmd);
1333
#endif
1333
#endif
1334
      RotationSet(1);
1334
      RotationSet(1);
1335
   }
1335
   }
1336
}
1336
}
1337
 
1337
 
1338
// File browser for selecting the save file
1338
// File browser for selecting the save file
1339
void TGAppMainFrame::SaveFile()
1339
void TGAppMainFrame::SaveFile()
1340
{
1340
{
1341
//   char *cTemp;
1341
//   char *cTemp;
1342
 
1342
 
1343
   TGFileInfo file_info;
1343
   TGFileInfo file_info;
1344
   const char *filetypes[] = {"Histograms",histextall,0,0};
1344
   const char *filetypes[] = {"Histograms",histextall,0,0};
1345
   file_info.fFileTypes = filetypes;
1345
   file_info.fFileTypes = filetypes;
1346
//   cTemp = new char[1024];
1346
//   cTemp = new char[1024];
1347
//   sprintf(cTemp, "%s/results", rootdir);
1347
//   sprintf(cTemp, "%s/results", rootdir);
1348
//   file_info.fIniDir = StrDup(cTemp);
1348
//   file_info.fIniDir = StrDup(cTemp);
1349
   file_info.fIniDir = StrDup(currentMeasDir);
1349
   file_info.fIniDir = StrDup(currentMeasDir);
1350
   new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDSave, &file_info);
1350
   new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDSave, &file_info);
1351
//   delete[] cTemp;
1351
//   delete[] cTemp;
1352
 
1352
 
1353
   if(file_info.fFilename != NULL)
1353
   if(file_info.fFilename != NULL)
1354
   {
1354
   {
1355
      fileName->widgetTE->SetText(file_info.fFilename);
1355
      fileName->widgetTE->SetText(file_info.fFilename);
1356
      remove_from_last(file_info.fFilename, '/', currentMeasDir);
1356
      remove_from_last(file_info.fFilename, '/', currentMeasDir);
1357
   }
1357
   }
1358
}
1358
}
1359
 
1359
 
1360
// Start the acquisition
1360
// Start the acquisition
1361
void TGAppMainFrame::StartAcq()
1361
void TGAppMainFrame::StartAcq()
1362
{
1362
{
-
 
1363
   // Save measurement settings any time we run a new measurement
-
 
1364
   SaveMeasSettings();
-
 
1365
 
1363
   // Variable that will initialize camac only once (for scans)
1366
   // Variable that will initialize camac only once (for scans)
1364
   int scanon = 0;
1367
   int scanon = 0;
1365
 
1368
 
1366
   // Determine the type of measurement to perform
1369
   // Determine the type of measurement to perform
1367
   int vscan = 0, pscan = 0, zscan = 0, ascan = 0;
1370
   int vscan = 0, pscan = 0, zscan = 0, ascan = 0;
1368
   if(scansOn->widgetChBox[0]->IsDown()) vscan = 1;
1371
   if(scansOn->widgetChBox[0]->IsDown()) vscan = 1;
1369
   if(scansOn->widgetChBox[1]->IsDown()) pscan = 1;
1372
   if(scansOn->widgetChBox[1]->IsDown()) pscan = 1;
1370
   if(scansOn->widgetChBox[2]->IsDown()) zscan = 1;
1373
   if(scansOn->widgetChBox[2]->IsDown()) zscan = 1;
1371
   if(scansOn->widgetChBox[3]->IsDown()) ascan = 1;
1374
   if(scansOn->widgetChBox[3]->IsDown()) ascan = 1;
1372
 
1375
 
1373
   char cmd[256];
1376
   char cmd[256];
1374
   int i, j, k;
1377
   int i, j, k;
1375
   float progVal;
1378
   float progVal;
1376
   FILE *pfin;
1379
   FILE *pfin;
1377
 
1380
 
1378
   // Variables for voltage scan
1381
   // Variables for voltage scan
1379
   float currentVoltage, minVoltage, maxVoltage, stepVoltage;
1382
   float currentVoltage, minVoltage, maxVoltage, stepVoltage;
1380
   int repetition;
1383
   int repetition;
1381
 
1384
 
1382
   // Variables for surface scan and Z axis scan
1385
   // Variables for surface scan and Z axis scan
1383
   float minXpos, maxXpos, stepXpos;
1386
   float minXpos, maxXpos, stepXpos;
1384
   float minYpos, maxYpos, stepYpos;
1387
   float minYpos, maxYpos, stepYpos;
1385
   float minZpos, maxZpos, stepZpos;
1388
   float minZpos, maxZpos, stepZpos;
1386
   int repetX, repetY, repetZ;
1389
   int repetX, repetY, repetZ;
1387
 
1390
 
1388
   // Variables for angle scan
1391
   // Variables for angle scan
1389
   float currentAlpha, minAlpha, maxAlpha, stepAlpha;
1392
   float currentAlpha, minAlpha, maxAlpha, stepAlpha;
1390
   int repetAlpha;
1393
   int repetAlpha;
1391
 
1394
 
1392
   // Only voltage scan
1395
   // Only voltage scan
1393
   if( (vscan == 1) && (pscan == 0) && (ascan == 0) )
1396
   if( (vscan == 1) && (pscan == 0) && (ascan == 0) )
1394
   { // TODO - include possibility to make voltage and angle scan at same time
1397
   { // TODO - include possibility to make voltage and angle scan at same time
1395
      // If already started, stop the acquisition
1398
      // If already started, stop the acquisition
1396
      if(acqStarted)
1399
      if(acqStarted)
1397
      {
1400
      {
1398
         printf("Stopping current voltage scan...\n");
1401
         printf("Stopping current voltage scan...\n");
1399
         gROOT->SetInterrupt();
1402
         gROOT->SetInterrupt();
1400
         measProgress->widgetTB[0]->SetText("Start acquisition");
1403
         measProgress->widgetTB[0]->SetText("Start acquisition");
1401
         acqStarted = false;
1404
         acqStarted = false;
1402
 
1405
 
1403
         // Write information to the finish_sig.txt value
1406
         // Write information to the finish_sig.txt value
1404
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1407
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1405
         pfin = fopen(cmd,"w");
1408
         pfin = fopen(cmd,"w");
1406
         fprintf(pfin, "%s: Voltage scan stopped.", timeStamp->widgetTE->GetText());
1409
         fprintf(pfin, "%s: Voltage scan stopped.", timeStamp->widgetTE->GetText());
1407
         fclose(pfin);
1410
         fclose(pfin);
1408
      }
1411
      }
1409
      // If stopped, start the acquisition
1412
      // If stopped, start the acquisition
1410
      else if(!acqStarted)
1413
      else if(!acqStarted)
1411
      {
1414
      {
1412
         printf("Running a voltage scan...\n");
1415
         printf("Running a voltage scan...\n");
1413
 
1416
 
1414
         // Check the steps
1417
         // Check the steps
1415
         minVoltage = vOutStart->widgetNE[0]->GetNumber();
1418
         minVoltage = vOutStart->widgetNE[0]->GetNumber();
1416
         maxVoltage = vOutStop->widgetNE[0]->GetNumber();
1419
         maxVoltage = vOutStop->widgetNE[0]->GetNumber();
1417
         stepVoltage = vOutStep->widgetNE[0]->GetNumber();
1420
         stepVoltage = vOutStep->widgetNE[0]->GetNumber();
1418
 
1421
 
1419
         if(stepVoltage == 0.)
1422
         if(stepVoltage == 0.)
1420
            repetition = 1;
1423
            repetition = 1;
1421
         else
1424
         else
1422
         {
1425
         {
1423
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1426
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1424
            if( (maxVoltage > minVoltage) && (stepVoltage > 0) )
1427
            if( (maxVoltage > minVoltage) && (stepVoltage > 0) )
1425
               repetition = ((maxVoltage - minVoltage)/stepVoltage)+1;
1428
               repetition = ((maxVoltage - minVoltage)/stepVoltage)+1;
1426
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1429
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1427
            else if( (maxVoltage < minVoltage) && (stepVoltage < 0) )
1430
            else if( (maxVoltage < minVoltage) && (stepVoltage < 0) )
1428
               repetition = ((minVoltage - maxVoltage)/stepVoltage)-1;
1431
               repetition = ((minVoltage - maxVoltage)/stepVoltage)-1;
1429
            // Example: min = 70, max = 70 (no scan)
1432
            // Example: min = 70, max = 70 (no scan)
1430
            else if( maxVoltage == minVoltage )
1433
            else if( maxVoltage == minVoltage )
1431
               repetition = 1;
1434
               repetition = 1;
1432
            // If step is not correctly set, stop the acqusition
1435
            // If step is not correctly set, stop the acqusition
1433
            else
1436
            else
1434
            {
1437
            {
1435
               // TODO
1438
               // TODO
1436
               printf("Stopping current voltage scan...\n");
1439
               printf("Stopping current voltage scan...\n");
1437
               gROOT->SetInterrupt();
1440
               gROOT->SetInterrupt();
1438
               measProgress->widgetTB[0]->SetText("Start acquisition");
1441
               measProgress->widgetTB[0]->SetText("Start acquisition");
1439
               acqStarted = false;
1442
               acqStarted = false;
1440
               repetition = 0;
1443
               repetition = 0;
1441
            }
1444
            }
1442
         }
1445
         }
1443
 
1446
 
1444
         if(DBGSIG) printf("StartAcq(): Voltage repetition (%lf,%lf,%lf) = %d\n", minVoltage, maxVoltage, stepVoltage, repetition);
1447
         if(DBGSIG) printf("StartAcq(): Voltage repetition (%lf,%lf,%lf) = %d\n", minVoltage, maxVoltage, stepVoltage, repetition);
1445
 
1448
 
1446
         i = 0;
1449
         i = 0;
1447
 
1450
 
1448
         // TODO - Setting button text and acqStarted do not work!
1451
         // TODO - Setting button text and acqStarted do not work!
1449
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1452
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1450
         acqStarted = true;
1453
         acqStarted = true;
1451
         progVal = 0.00;
1454
         progVal = 0.00;
1452
         measProgress->widgetPB->SetPosition(progVal);
1455
         measProgress->widgetPB->SetPosition(progVal);
1453
         gVirtualX->Update(1);
1456
         gVirtualX->Update(1);
1454
 
1457
 
1455
         clkt0 = clock();
1458
         clkt0 = clock();
1456
         timet0 = time(NULL);
1459
         timet0 = time(NULL);
1457
 
1460
 
1458
         while(1)
1461
         while(1)
1459
         {
1462
         {
1460
            if( (repetition > 0) && (i == repetition) ) break;
1463
            if( (repetition > 0) && (i == repetition) ) break;
1461
            else if( (repetition < 0) && (i == -repetition) ) break;
1464
            else if( (repetition < 0) && (i == -repetition) ) break;
1462
            else if( repetition == 0 ) break;
1465
            else if( repetition == 0 ) break;
1463
 
1466
 
1464
            progVal = (float)(100.00/abs(repetition))*i;
1467
            progVal = (float)(100.00/abs(repetition))*i;
1465
            measProgress->widgetPB->SetPosition(progVal);
1468
            measProgress->widgetPB->SetPosition(progVal);
1466
 
1469
 
1467
            TimeEstimate(clkt0, timet0, progVal, cmd, singlewait*abs(repetition));
1470
            TimeEstimate(clkt0, timet0, progVal, cmd, singlewait*abs(repetition));
1468
            measProgress->widgetTE->SetText(cmd);
1471
            measProgress->widgetTE->SetText(cmd);
1469
 
1472
 
1470
            gVirtualX->Update(1);
1473
            gVirtualX->Update(1);
1471
       
1474
       
1472
            fflush(stdout);
1475
            fflush(stdout);
1473
            currentVoltage = minVoltage + stepVoltage*i;
1476
            currentVoltage = minVoltage + stepVoltage*i;
1474
            sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), currentVoltage);
1477
            sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), currentVoltage);
1475
#if WORKSTAT == 'I'
1478
#if WORKSTAT == 'I'
1476
            retTemp = system(cmd);
1479
            retTemp = system(cmd);
1477
#else
1480
#else
1478
            printf("Cmd: %s\n",cmd);
1481
            printf("Cmd: %s\n",cmd);
1479
#endif
1482
#endif
1480
            fflush(stdout);
1483
            fflush(stdout);
1481
       
1484
       
1482
            printf("Waiting for voltage change...\n");
1485
            printf("Waiting for voltage change...\n");
1483
            sleep(singlewait);
1486
            sleep(singlewait);
1484
            vOut->widgetNE[0]->SetNumber(currentVoltage);
1487
            vOut->widgetNE[0]->SetNumber(currentVoltage);
1485
            gVirtualX->Update(1);
1488
            gVirtualX->Update(1);
1486
            printf("Continuing...\n");
1489
            printf("Continuing...\n");
1487
       
1490
       
1488
            // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<<
1491
            // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<<
1489
            RunMeas((void*)0, i, scanon); // TODO
1492
            RunMeas((void*)0, i, scanon); // TODO
1490
            fflush(stdout);
1493
            fflush(stdout);
1491
 
1494
 
1492
            i++;
1495
            i++;
1493
         }
1496
         }
1494
 
1497
 
1495
         // Set output back to off
1498
         // Set output back to off
1496
         fflush(stdout);
1499
         fflush(stdout);
1497
         printf("Measurement finished, returning to starting voltage...\n");
1500
         printf("Measurement finished, returning to starting voltage...\n");
1498
         sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), minVoltage);
1501
         sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), minVoltage);
1499
         vOut->widgetNE[0]->SetNumber(minVoltage);
1502
         vOut->widgetNE[0]->SetNumber(minVoltage);
1500
#if WORKSTAT == 'I'
1503
#if WORKSTAT == 'I'
1501
         retTemp = system(cmd);
1504
         retTemp = system(cmd);
1502
#else
1505
#else
1503
         printf("Cmd: %s\n",cmd);
1506
         printf("Cmd: %s\n",cmd);
1504
#endif
1507
#endif
1505
         fflush(stdout);
1508
         fflush(stdout);
1506
       
1509
       
1507
         progVal = 100.00;
1510
         progVal = 100.00;
1508
         measProgress->widgetPB->SetPosition(progVal);
1511
         measProgress->widgetPB->SetPosition(progVal);
1509
         printf("\n");
1512
         printf("\n");
1510
 
1513
 
1511
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1514
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1512
         pfin = fopen(cmd,"w");
1515
         pfin = fopen(cmd,"w");
1513
         fprintf(pfin, "%s: Voltage scan finished.", timeStamp->widgetTE->GetText());
1516
         fprintf(pfin, "%s: Voltage scan finished.", timeStamp->widgetTE->GetText());
1514
         fclose(pfin);
1517
         fclose(pfin);
1515
 
1518
 
1516
         measProgress->widgetTB[0]->SetText("Start acquisition");
1519
         measProgress->widgetTB[0]->SetText("Start acquisition");
1517
         acqStarted = false;
1520
         acqStarted = false;
1518
      }
1521
      }
1519
   }
1522
   }
1520
   // Surface scan
1523
   // Surface scan
1521
   else if( (pscan == 1) && (vscan == 0) && (ascan == 0) )
1524
   else if( (pscan == 1) && (vscan == 0) && (ascan == 0) )
1522
   {
1525
   {
1523
      // If already started, stop the acquisition
1526
      // If already started, stop the acquisition
1524
      if(acqStarted)
1527
      if(acqStarted)
1525
      {
1528
      {
1526
         printf("Stopping current surface scan...\n");
1529
         printf("Stopping current surface scan...\n");
1527
         gROOT->SetInterrupt();
1530
         gROOT->SetInterrupt();
1528
         measProgress->widgetTB[0]->SetText("Start acquisition");
1531
         measProgress->widgetTB[0]->SetText("Start acquisition");
1529
         acqStarted = false;
1532
         acqStarted = false;
1530
 
1533
 
1531
         // Write information to the finish_sig.txt value
1534
         // Write information to the finish_sig.txt value
1532
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1535
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1533
         pfin = fopen(cmd,"w");
1536
         pfin = fopen(cmd,"w");
1534
         fprintf(pfin, "%s: Surface scan stopped.", timeStamp->widgetTE->GetText());
1537
         fprintf(pfin, "%s: Surface scan stopped.", timeStamp->widgetTE->GetText());
1535
         fclose(pfin);
1538
         fclose(pfin);
1536
      }
1539
      }
1537
      // If stopped, start the acquisition
1540
      // If stopped, start the acquisition
1538
      else if(!acqStarted)
1541
      else if(!acqStarted)
1539
      {
1542
      {
1540
         printf("Running a surface scan...\n");
1543
         printf("Running a surface scan...\n");
1541
 
1544
 
1542
         minXpos = xPosMin->widgetNE[0]->GetNumber();
1545
         minXpos = xPosMin->widgetNE[0]->GetNumber();
1543
         maxXpos = xPosMax->widgetNE[0]->GetNumber();
1546
         maxXpos = xPosMax->widgetNE[0]->GetNumber();
1544
         stepXpos = xPosStep->widgetNE[0]->GetNumber();
1547
         stepXpos = xPosStep->widgetNE[0]->GetNumber();
1545
         minYpos = yPosMin->widgetNE[0]->GetNumber();
1548
         minYpos = yPosMin->widgetNE[0]->GetNumber();
1546
         maxYpos = yPosMax->widgetNE[0]->GetNumber();
1549
         maxYpos = yPosMax->widgetNE[0]->GetNumber();
1547
         stepYpos = yPosStep->widgetNE[0]->GetNumber();
1550
         stepYpos = yPosStep->widgetNE[0]->GetNumber();
1548
         minZpos = zPosMin->widgetNE[0]->GetNumber();
1551
         minZpos = zPosMin->widgetNE[0]->GetNumber();
1549
         maxZpos = zPosMax->widgetNE[0]->GetNumber();
1552
         maxZpos = zPosMax->widgetNE[0]->GetNumber();
1550
         stepZpos = zPosStep->widgetNE[0]->GetNumber();
1553
         stepZpos = zPosStep->widgetNE[0]->GetNumber();
1551
 
1554
 
1552
         // Setting repetition for Z axis scan
1555
         // Setting repetition for Z axis scan
1553
         if(zscan == 1)
1556
         if(zscan == 1)
1554
         {
1557
         {
1555
            if(stepZpos == 0.)
1558
            if(stepZpos == 0.)
1556
               repetZ = 1;
1559
               repetZ = 1;
1557
&n