Subversion Repositories f9daq

Rev

Rev 146 | Rev 172 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 146 Rev 167
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
sleep(1);
600
sleep(1);
601
 
601
 
602
            // Start making a scope measurement
602
            // Start making a scope measurement
603
/*          if( (gScopeDaq->scopeUseType == 2) && (sCamaclink->IsDown()) )
603
/*          if( (gScopeDaq->scopeUseType == 2) && (sCamaclink->IsDown()) )
604
            {
604
            {
605
               StartScopeAcq();
605
               StartScopeAcq();
606
               evtmeas.measdata = gScopeDaq->measubuf;
606
               evtmeas.measdata = gScopeDaq->measubuf;
607
            }
607
            }
608
            scope_data->Fill();*/ // TODO
608
            scope_data->Fill();*/ // TODO
609
 
609
 
610
            // Start filling the histogram (only in normal single scan)
610
            // Start filling the histogram (only in normal single scan)
611
            if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
611
            if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
612
            {
612
            {
613
               liveHist->Fill(evtdata.adcdata[0]);
613
               liveHist->Fill(evtdata.adcdata[0]);
614
               if( n == (neve*liven)/10 )
614
               if( n == (neve*liven)/10 )
615
               {
615
               {
616
                  gCanvas->cd();
616
                  gCanvas->cd();
617
                  liveHist->Draw("");
617
                  liveHist->Draw("");
618
                  gCanvas->Modified();
618
                  gCanvas->Modified();
619
                  gCanvas->Update();
619
                  gCanvas->Update();
620
                  liven++;
620
                  liven++;
621
               }
621
               }
622
            }
622
            }
623
           
623
           
624
            nc += evtheader.nrch;
624
            nc += evtheader.nrch;
625
            nb -= evtheader.nrch;
625
            nb -= evtheader.nrch;
626
         }
626
         }
627
 
627
 
628
         MyTimer();
628
         MyTimer();
629
         allEvt = n;
629
         allEvt = n;
630
         if (gSystem->ProcessEvents()) printf("Run Interrupted\n");
630
         if (gSystem->ProcessEvents()) printf("Run Interrupted\n");
631
 
631
 
632
         if( acqStarted && (n == (neve*zProg)/10) && (!vscan && !pscan && !zscan && !ascan) )
632
         if( acqStarted && (n == (neve*zProg)/10) && (!vscan && !pscan && !zscan && !ascan) )
633
         {
633
         {
634
            // Progress the progress bar
634
            // Progress the progress bar
635
            progVal = (float)zProg*10;
635
            progVal = (float)zProg*10;
636
            measProgress->widgetPB->SetPosition(progVal);
636
            measProgress->widgetPB->SetPosition(progVal);
637
 
637
 
638
            // Calculate the remaining time
638
            // Calculate the remaining time
639
            TimeEstimate(clkt0, timet0, progVal, ctemp, 0);
639
            TimeEstimate(clkt0, timet0, progVal, ctemp, 0);
640
            printf("End time: %s\n", ctemp);
640
            printf("End time: %s\n", ctemp);
641
            measProgress->widgetTE->SetText(ctemp);
641
            measProgress->widgetTE->SetText(ctemp);
642
 
642
 
643
            gVirtualX->Update(1);
643
            gVirtualX->Update(1);
644
            zProg++;
644
            zProg++;
645
         }
645
         }
646
      }
646
      }
647
 
647
 
648
      printf("Number of gathered events: %d\n", allEvt);
648
      printf("Number of gathered events: %d\n", allEvt);
649
      measProgress->widgetTB[0]->SetText("Start acquisition");
649
      measProgress->widgetTB[0]->SetText("Start acquisition");
650
      acqStarted = false;
650
      acqStarted = false;
651
 
651
 
652
      gDaq->stop();
652
      gDaq->stop();
653
   }
653
   }
654
 
654
 
655
   printf("End of Run neve=%d\n",neve);
655
   printf("End of Run neve=%d\n",neve);
656
 
656
 
657
   header_data->Write();
657
   header_data->Write();
658
   meas_data->Write();
658
   meas_data->Write();
659
//   scope_data->Write(); // TODO
659
//   scope_data->Write(); // TODO
660
   delete header_data;
660
   delete header_data;
661
   delete meas_data;
661
   delete meas_data;
662
   delete scope_data;
662
   delete scope_data;
663
 
663
 
664
   // Remove the histogram
664
   // Remove the histogram
665
   if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
665
   if(liveUpdate && (!vscan && !pscan && !zscan && !ascan))
666
      delete liveHist;
666
      delete liveHist;
667
 
667
 
668
 
668
 
669
   outroot->Close();
669
   outroot->Close();
670
}
670
}
671
 
671
 
672
int TGAppMainFrame::MyTimer()
672
int TGAppMainFrame::MyTimer()
673
{
673
{
674
   char cmd[100];
674
   char cmd[100];
675
   GetTime(-1, cmd);
675
   GetTime(-1, cmd);
676
   if (timeStamp) timeStamp->widgetTE->SetText(cmd);
676
   if (timeStamp) timeStamp->widgetTE->SetText(cmd);
677
   return 0;
677
   return 0;
678
}
678
}
679
 
679
 
680
// Additional functions -------------------------------------
680
// Additional functions -------------------------------------
681
 
681
 
682
// Settings pane connections --------------------------------
682
// Settings pane connections --------------------------------
683
 
683
 
684
// Enable or disable scans
684
// Enable or disable scans
685
void TGAppMainFrame::EnableScan(int type)
685
void TGAppMainFrame::EnableScan(int type)
686
{
686
{
687
   // Voltage scan
687
   // Voltage scan
688
   if(type == 0)
688
   if(type == 0)
689
   {
689
   {
690
      if(scansOn->widgetChBox[type]->IsOn())
690
      if(scansOn->widgetChBox[type]->IsOn())
691
      {
691
      {
692
         vOutStart->widgetNE[0]->SetState(kTRUE);
692
         vOutStart->widgetNE[0]->SetState(kTRUE);
693
         vOutStop->widgetNE[0]->SetState(kTRUE);
693
         vOutStop->widgetNE[0]->SetState(kTRUE);
694
         vOutStep->widgetNE[0]->SetState(kTRUE);
694
         vOutStep->widgetNE[0]->SetState(kTRUE);
695
      }
695
      }
696
      else
696
      else
697
      {
697
      {
698
         vOutStart->widgetNE[0]->SetState(kFALSE);
698
         vOutStart->widgetNE[0]->SetState(kFALSE);
699
         vOutStop->widgetNE[0]->SetState(kFALSE);
699
         vOutStop->widgetNE[0]->SetState(kFALSE);
700
         vOutStep->widgetNE[0]->SetState(kFALSE);
700
         vOutStep->widgetNE[0]->SetState(kFALSE);
701
      }
701
      }
702
   }
702
   }
703
   // Surface (X, Y axis) scan
703
   // Surface (X, Y axis) scan
704
   else if(type == 1)
704
   else if(type == 1)
705
   {
705
   {
706
      if(scansOn->widgetChBox[type]->IsOn())
706
      if(scansOn->widgetChBox[type]->IsOn())
707
      {
707
      {
708
         xPosMin->widgetNE[0]->SetState(kTRUE);
708
         xPosMin->widgetNE[0]->SetState(kTRUE);
709
         xPosMax->widgetNE[0]->SetState(kTRUE);
709
         xPosMax->widgetNE[0]->SetState(kTRUE);
710
         xPosStep->widgetNE[0]->SetState(kTRUE);
710
         xPosStep->widgetNE[0]->SetState(kTRUE);
711
         yPosMin->widgetNE[0]->SetState(kTRUE);
711
         yPosMin->widgetNE[0]->SetState(kTRUE);
712
         yPosMax->widgetNE[0]->SetState(kTRUE);
712
         yPosMax->widgetNE[0]->SetState(kTRUE);
713
         yPosStep->widgetNE[0]->SetState(kTRUE);
713
         yPosStep->widgetNE[0]->SetState(kTRUE);
714
      }
714
      }
715
      else
715
      else
716
      {
716
      {
717
         xPosMin->widgetNE[0]->SetState(kFALSE);
717
         xPosMin->widgetNE[0]->SetState(kFALSE);
718
         xPosMax->widgetNE[0]->SetState(kFALSE);
718
         xPosMax->widgetNE[0]->SetState(kFALSE);
719
         xPosStep->widgetNE[0]->SetState(kFALSE);
719
         xPosStep->widgetNE[0]->SetState(kFALSE);
720
         yPosMin->widgetNE[0]->SetState(kFALSE);
720
         yPosMin->widgetNE[0]->SetState(kFALSE);
721
         yPosMax->widgetNE[0]->SetState(kFALSE);
721
         yPosMax->widgetNE[0]->SetState(kFALSE);
722
         yPosStep->widgetNE[0]->SetState(kFALSE);
722
         yPosStep->widgetNE[0]->SetState(kFALSE);
723
      }
723
      }
724
   }
724
   }
725
   // Z axis scan
725
   // Z axis scan
726
   else if(type == 2)
726
   else if(type == 2)
727
   {
727
   {
728
      if(scansOn->widgetChBox[type]->IsOn())
728
      if(scansOn->widgetChBox[type]->IsOn())
729
      {
729
      {
730
         zPosMin->widgetNE[0]->SetState(kTRUE);
730
         zPosMin->widgetNE[0]->SetState(kTRUE);
731
         zPosMax->widgetNE[0]->SetState(kTRUE);
731
         zPosMax->widgetNE[0]->SetState(kTRUE);
732
         zPosStep->widgetNE[0]->SetState(kTRUE);
732
         zPosStep->widgetNE[0]->SetState(kTRUE);
733
      }
733
      }
734
      else
734
      else
735
      {
735
      {
736
         zPosMin->widgetNE[0]->SetState(kFALSE);
736
         zPosMin->widgetNE[0]->SetState(kFALSE);
737
         zPosMax->widgetNE[0]->SetState(kFALSE);
737
         zPosMax->widgetNE[0]->SetState(kFALSE);
738
         zPosStep->widgetNE[0]->SetState(kFALSE);
738
         zPosStep->widgetNE[0]->SetState(kFALSE);
739
      }
739
      }
740
   }
740
   }
741
   // Incidence angle scan
741
   // Incidence angle scan
742
   else if(type == 3)
742
   else if(type == 3)
743
   {
743
   {
744
      if(scansOn->widgetChBox[type]->IsOn())
744
      if(scansOn->widgetChBox[type]->IsOn())
745
      {
745
      {
746
         rotPosMin->widgetNE[0]->SetState(kTRUE);
746
         rotPosMin->widgetNE[0]->SetState(kTRUE);
747
         rotPosMax->widgetNE[0]->SetState(kTRUE);
747
         rotPosMax->widgetNE[0]->SetState(kTRUE);
748
         rotPosStep->widgetNE[0]->SetState(kTRUE);
748
         rotPosStep->widgetNE[0]->SetState(kTRUE);
749
      }
749
      }
750
      else
750
      else
751
      {
751
      {
752
         rotPosMin->widgetNE[0]->SetState(kFALSE);
752
         rotPosMin->widgetNE[0]->SetState(kFALSE);
753
         rotPosMax->widgetNE[0]->SetState(kFALSE);
753
         rotPosMax->widgetNE[0]->SetState(kFALSE);
754
         rotPosStep->widgetNE[0]->SetState(kFALSE);
754
         rotPosStep->widgetNE[0]->SetState(kFALSE);
755
      }
755
      }
756
   }
756
   }
757
}
757
}
758
 
758
 
759
// Apply the upper voltage limit from settings pane to main window
759
// Apply the upper voltage limit from settings pane to main window
760
void TGAppMainFrame::VoltageLimit()
760
void TGAppMainFrame::VoltageLimit()
761
{
761
{
762
   vOut->widgetNE[0]->SetLimitValues(0, vHardlimit->widgetNE[0]->GetNumber() );
762
   vOut->widgetNE[0]->SetLimitValues(0, vHardlimit->widgetNE[0]->GetNumber() );
763
}
763
}
764
 
764
 
765
// Select the table position units to be used (1 = 0.3595 micron)
765
// Select the table position units to be used (1 = 0.3595 micron)
766
void TGAppMainFrame::ChangeUnits(int type)
766
void TGAppMainFrame::ChangeUnits(int type)
767
{
767
{
768
   int pos[12], poslim[3], chng = 0;
768
   int pos[12], poslim[3], chng = 0;
769
   double micro[12], microlim[3];
769
   double micro[12], microlim[3];
770
 
770
 
771
   TGNumberEntry *posEntries[12];
771
   TGNumberEntry *posEntries[12];
772
   posEntries[0] = (TGNumberEntry*)xPos->widgetNE[0];
772
   posEntries[0] = (TGNumberEntry*)xPos->widgetNE[0];
773
   posEntries[1] = (TGNumberEntry*)yPos->widgetNE[0];
773
   posEntries[1] = (TGNumberEntry*)yPos->widgetNE[0];
774
   posEntries[2] = (TGNumberEntry*)zPos->widgetNE[0];
774
   posEntries[2] = (TGNumberEntry*)zPos->widgetNE[0];
775
   posEntries[3] = (TGNumberEntry*)xPosMin->widgetNE[0];
775
   posEntries[3] = (TGNumberEntry*)xPosMin->widgetNE[0];
776
   posEntries[4] = (TGNumberEntry*)xPosMax->widgetNE[0];
776
   posEntries[4] = (TGNumberEntry*)xPosMax->widgetNE[0];
777
   posEntries[5] = (TGNumberEntry*)xPosStep->widgetNE[0];
777
   posEntries[5] = (TGNumberEntry*)xPosStep->widgetNE[0];
778
   posEntries[6] = (TGNumberEntry*)yPosMin->widgetNE[0];
778
   posEntries[6] = (TGNumberEntry*)yPosMin->widgetNE[0];
779
   posEntries[7] = (TGNumberEntry*)yPosMax->widgetNE[0];
779
   posEntries[7] = (TGNumberEntry*)yPosMax->widgetNE[0];
780
   posEntries[8] = (TGNumberEntry*)yPosStep->widgetNE[0];
780
   posEntries[8] = (TGNumberEntry*)yPosStep->widgetNE[0];
781
   posEntries[9] = (TGNumberEntry*)zPosMin->widgetNE[0];
781
   posEntries[9] = (TGNumberEntry*)zPosMin->widgetNE[0];
782
   posEntries[10] = (TGNumberEntry*)zPosMax->widgetNE[0];
782
   posEntries[10] = (TGNumberEntry*)zPosMax->widgetNE[0];
783
   posEntries[11] = (TGNumberEntry*)zPosStep->widgetNE[0];
783
   posEntries[11] = (TGNumberEntry*)zPosStep->widgetNE[0];
784
 
784
 
785
   // Table position values
785
   // Table position values
786
   if(type == 0)
786
   if(type == 0)
787
   {
787
   {
788
      // Check if we had microns before
788
      // Check if we had microns before
789
      if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo)
789
      if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo)
790
         chng = 1;
790
         chng = 1;
791
 
791
 
792
      // Change to table position values   
792
      // Change to table position values   
793
      if(chng == 1)
793
      if(chng == 1)
794
      {
794
      {
795
         for(int i = 0; i < 12; i++)
795
         for(int i = 0; i < 12; i++)
796
         {
796
         {
797
            if(posEntries[i]->GetNumber() == 0.0)
797
            if(posEntries[i]->GetNumber() == 0.0)
798
               pos[i] = 0;
798
               pos[i] = 0;
799
            else
799
            else
800
               pos[i] = (int)posEntries[i]->GetNumber()/lenconversion;
800
               pos[i] = (int)posEntries[i]->GetNumber()/lenconversion;
801
         }
801
         }
802
 
802
 
803
         poslim[0] = -100;
803
         poslim[0] = -100;
804
         poslim[1] = 215000;
804
         poslim[1] = 215000;
805
         poslim[2] = 375000;
805
         poslim[2] = 375000;
806
 
806
 
807
         for(int i = 0; i < 12; i++)
807
         for(int i = 0; i < 12; i++)
808
         {
808
         {
809
            posEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger);
809
            posEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger);
810
            if( (i > 8) || (i == 2) ) // limits for Z axis (longer table)
810
            if( (i > 8) || (i == 2) ) // limits for Z axis (longer table)
811
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[2]);
811
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[2]);
812
            else
812
            else
813
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[1]);
813
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, poslim[0], poslim[1]);
814
 
814
 
815
            posEntries[i]->SetNumber(pos[i]);
815
            posEntries[i]->SetNumber(pos[i]);
816
         }
816
         }
817
      }
817
      }
818
   }
818
   }
819
   // Microns
819
   // Microns
820
   else if(type == 1)
820
   else if(type == 1)
821
   {
821
   {
822
      // Check if we had table position values before
822
      // Check if we had table position values before
823
      if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger)
823
      if(posEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger)
824
         chng = 1;
824
         chng = 1;
825
 
825
 
826
      // Change to microns   
826
      // Change to microns   
827
      if(chng == 1)
827
      if(chng == 1)
828
      {
828
      {
829
         for(int i = 0; i < 12; i++)
829
         for(int i = 0; i < 12; i++)
830
         {
830
         {
831
            if(posEntries[i]->GetNumber() == 0.0)
831
            if(posEntries[i]->GetNumber() == 0.0)
832
               micro[i] = 0.;
832
               micro[i] = 0.;
833
            else
833
            else
834
               micro[i] = (double)posEntries[i]->GetNumber()*lenconversion;
834
               micro[i] = (double)posEntries[i]->GetNumber()*lenconversion;
835
         }
835
         }
836
   
836
   
837
         microlim[0] = (double)-100*lenconversion;
837
         microlim[0] = (double)-100*lenconversion;
838
         microlim[1] = (double)215000*lenconversion;
838
         microlim[1] = (double)215000*lenconversion;
839
         microlim[2] = (double)375000*lenconversion;
839
         microlim[2] = (double)375000*lenconversion;
840
   
840
   
841
         for(int i = 0; i < 12; i++)
841
         for(int i = 0; i < 12; i++)
842
         {
842
         {
843
            posEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo);
843
            posEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo);
844
            if( (i > 8) || (i == 2) ) // limits for Z axis (longer table)
844
            if( (i > 8) || (i == 2) ) // limits for Z axis (longer table)
845
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[2]);
845
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[2]);
846
            else
846
            else
847
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[1]);
847
               posEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, microlim[0], microlim[1]);
848
   
848
   
849
            posEntries[i]->SetNumber(micro[i]);
849
            posEntries[i]->SetNumber(micro[i]);
850
         }
850
         }
851
      }
851
      }
852
   }
852
   }
853
}
853
}
854
 
854
 
855
// Select the rotation units to be used (1 = 6.3281/3600 degrees)
855
// Select the rotation units to be used (1 = 6.3281/3600 degrees)
856
void TGAppMainFrame::ChangeUnitsRot(int type)
856
void TGAppMainFrame::ChangeUnitsRot(int type)
857
{
857
{
858
   int rot[4], rotlim[2], chng = 0;
858
   int rot[4], rotlim[2], chng = 0;
859
   double deg[4], deglim[2];
859
   double deg[4], deglim[2];
860
 
860
 
861
   TGNumberEntry *rotEntries[4];
861
   TGNumberEntry *rotEntries[4];
862
   rotEntries[0] = (TGNumberEntry*)rotPos->widgetNE[0];
862
   rotEntries[0] = (TGNumberEntry*)rotPos->widgetNE[0];
863
   rotEntries[1] = (TGNumberEntry*)rotPosMin->widgetNE[0];
863
   rotEntries[1] = (TGNumberEntry*)rotPosMin->widgetNE[0];
864
   rotEntries[2] = (TGNumberEntry*)rotPosMax->widgetNE[0];
864
   rotEntries[2] = (TGNumberEntry*)rotPosMax->widgetNE[0];
865
   rotEntries[3] = (TGNumberEntry*)rotPosStep->widgetNE[0];
865
   rotEntries[3] = (TGNumberEntry*)rotPosStep->widgetNE[0];
866
 
866
 
867
   // Rotation values
867
   // Rotation values
868
   if(type == 0)
868
   if(type == 0)
869
   {
869
   {
870
      // Check if we had degrees before
870
      // Check if we had degrees before
871
      if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo)
871
      if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESRealTwo)
872
         chng = 1;
872
         chng = 1;
873
 
873
 
874
      // Change to rotation values   
874
      // Change to rotation values   
875
      if(chng == 1)
875
      if(chng == 1)
876
      {
876
      {
877
         for(int i = 0; i < 4; i++)
877
         for(int i = 0; i < 4; i++)
878
         {
878
         {
879
            if(rotEntries[i]->GetNumber() == 0.0)
879
            if(rotEntries[i]->GetNumber() == 0.0)
880
               rot[i] = 0;
880
               rot[i] = 0;
881
            else
881
            else
882
               rot[i] = (int)rotEntries[i]->GetNumber()/rotconversion;
882
               rot[i] = (int)rotEntries[i]->GetNumber()/rotconversion;
883
         }
883
         }
884
 
884
 
885
         rotlim[0] = (int)-180/rotconversion;
885
         rotlim[0] = (int)-180/rotconversion;
886
         rotlim[1] = (int)180/rotconversion;
886
         rotlim[1] = (int)180/rotconversion;
887
 
887
 
888
         for(int i = 0; i < 4; i++)
888
         for(int i = 0; i < 4; i++)
889
         {
889
         {
890
            rotEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger);
890
            rotEntries[i]->SetNumStyle(TGNumberFormat::kNESInteger);
891
            rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, rotlim[0], rotlim[1]);
891
            rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, rotlim[0], rotlim[1]);
892
 
892
 
893
            rotEntries[i]->SetNumber(rot[i]);
893
            rotEntries[i]->SetNumber(rot[i]);
894
         }
894
         }
895
      }
895
      }
896
   }
896
   }
897
   // Degree
897
   // Degree
898
   else if(type == 1)
898
   else if(type == 1)
899
   {
899
   {
900
      // Check if we had table position values before
900
      // Check if we had table position values before
901
      if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger)
901
      if(rotEntries[0]->GetNumStyle() == TGNumberFormat::kNESInteger)
902
         chng = 1;
902
         chng = 1;
903
 
903
 
904
      // Change to degrees   
904
      // Change to degrees   
905
      if(chng == 1)
905
      if(chng == 1)
906
      {
906
      {
907
         for(int i = 0; i < 4; i++)
907
         for(int i = 0; i < 4; i++)
908
         {
908
         {
909
            if(rotEntries[i]->GetNumber() == 0)
909
            if(rotEntries[i]->GetNumber() == 0)
910
               deg[i] = 0.;
910
               deg[i] = 0.;
911
            else
911
            else
912
               deg[i] = (double)rotEntries[i]->GetNumber()*rotconversion;
912
               deg[i] = (double)rotEntries[i]->GetNumber()*rotconversion;
913
         }
913
         }
914
   
914
   
915
         deglim[0] = -180.;
915
         deglim[0] = -180.;
916
         deglim[1] = 180.;
916
         deglim[1] = 180.;
917
   
917
   
918
         for(int i = 0; i < 4; i++)
918
         for(int i = 0; i < 4; i++)
919
         {
919
         {
920
            rotEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo);
920
            rotEntries[i]->SetNumStyle(TGNumberFormat::kNESRealTwo);
921
            rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, deglim[0], deglim[1]);
921
            rotEntries[i]->SetLimits(TGNumberFormat::kNELLimitMinMax, deglim[0], deglim[1]);
922
   
922
   
923
            rotEntries[i]->SetNumber(deg[i]);
923
            rotEntries[i]->SetNumber(deg[i]);
924
         }
924
         }
925
      }
925
      }
926
   }
926
   }
927
}
927
}
928
 
928
 
929
// Enable display canvas to have a live update of histogram
929
// Enable display canvas to have a live update of histogram
930
void TGAppMainFrame::EnableLiveUpdate()
930
void TGAppMainFrame::EnableLiveUpdate()
931
{
931
{
932
   liveUpdate = liveDisp->widgetChBox[0]->IsDown();
932
   liveUpdate = liveDisp->widgetChBox[0]->IsDown();
933
}
933
}
934
 
934
 
935
// Settings pane connections --------------------------------
935
// Settings pane connections --------------------------------
936
 
936
 
937
// Main measurement window connections ----------------------
937
// Main measurement window connections ----------------------
938
 
938
 
939
// Get the currently selected channel
939
// Get the currently selected channel
940
int TGAppMainFrame::GetChannel()
940
int TGAppMainFrame::GetChannel()
941
{
941
{
942
   int selectedOutput;
942
   int selectedOutput;
943
   if(vOutCh->widgetCB->GetSelected() < 8) selectedOutput = (vOutCh->widgetCB->GetSelected())+1;
943
   if(vOutCh->widgetCB->GetSelected() < 8) selectedOutput = (vOutCh->widgetCB->GetSelected())+1;
944
   else if( (vOutCh->widgetCB->GetSelected() >= 8) && (vOutCh->widgetCB->GetSelected() < 16) ) selectedOutput = (vOutCh->widgetCB->GetSelected())+93;
944
   else if( (vOutCh->widgetCB->GetSelected() >= 8) && (vOutCh->widgetCB->GetSelected() < 16) ) selectedOutput = (vOutCh->widgetCB->GetSelected())+93;
945
   else selectedOutput = 1;
945
   else selectedOutput = 1;
946
 
946
 
947
   return selectedOutput;
947
   return selectedOutput;
948
}
948
}
949
 
949
 
950
// Set, get or reset the output voltage
950
// Set, get or reset the output voltage
951
void TGAppMainFrame::VoltOut(int opt)
951
void TGAppMainFrame::VoltOut(int opt)
952
{
952
{
953
   char cmd[256];
953
   char cmd[256];
954
 
954
 
955
   // Set the selected voltage
955
   // Set the selected voltage
956
   if(opt == 0)
956
   if(opt == 0)
957
   {
957
   {
958
      int outOn;
958
      int outOn;
959
      float outputVoltage;
959
      float outputVoltage;
960
     
960
     
961
      outputVoltage = vOut->widgetNE[0]->GetNumber();
961
      outputVoltage = vOut->widgetNE[0]->GetNumber();
962
   
962
   
963
      if(vOutOpt->widgetChBox[1]->IsOn()) outOn = 1;
963
      if(vOutOpt->widgetChBox[1]->IsOn()) outOn = 1;
964
      else outOn = 0;
964
      else outOn = 0;
965
     
965
     
966
      fflush(stdout);
966
      fflush(stdout);
967
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s %d", rootdir, GetChannel(), outputVoltage, outOn);
967
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s %d", rootdir, GetChannel(), outputVoltage, outOn);
968
#if WORKSTAT == 'I'
968
#if WORKSTAT == 'I'
969
      retTemp = system(cmd);
969
      retTemp = system(cmd);
970
#else
970
#else
971
      printf("Cmd: %s\n",cmd);
971
      printf("Cmd: %s\n",cmd);
972
#endif
972
#endif
973
      fflush(stdout);
973
      fflush(stdout);
974
   }
974
   }
975
   // Get current voltage
975
   // Get current voltage
976
   else if(opt == 1)
976
   else if(opt == 1)
977
   {
977
   {
978
      fflush(stdout);
978
      fflush(stdout);
979
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -g > %s/settings/curvolt.txt", rootdir, GetChannel(), rootdir);
979
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -g > %s/settings/curvolt.txt", rootdir, GetChannel(), rootdir);
980
#if WORKSTAT == 'I'
980
#if WORKSTAT == 'I'
981
      retTemp = system(cmd);
981
      retTemp = system(cmd);
982
#else
982
#else
983
      printf("Cmd: %s\n",cmd);
983
      printf("Cmd: %s\n",cmd);
984
#endif
984
#endif
985
      fflush(stdout);
985
      fflush(stdout);
986
 
986
 
987
#if WORKSTAT == 'I'
987
#if WORKSTAT == 'I'
988
      FILE* fvolt;
988
      FILE* fvolt;
989
      double dtemp;
989
      double dtemp;
990
      char ctemp[24];
990
      char ctemp[24];
991
      sprintf(cmd, "%s/settings/curvolt.txt", rootdir);
991
      sprintf(cmd, "%s/settings/curvolt.txt", rootdir);
992
      fvolt = fopen(cmd, "r");
992
      fvolt = fopen(cmd, "r");
993
     
993
     
994
      if(fvolt != NULL)
994
      if(fvolt != NULL)
995
      {
995
      {
996
         sprintf(cmd, "WIENER-CRATE-MIB::outputVoltage.u%d = Opaque: Float: %s V\n", GetChannel()-1, "%lf" );
996
         sprintf(cmd, "WIENER-CRATE-MIB::outputVoltage.u%d = Opaque: Float: %s V\n", GetChannel()-1, "%lf" );
997
         retTemp = fscanf(fvolt, cmd, &dtemp);
997
         retTemp = fscanf(fvolt, cmd, &dtemp);
998
         vOut->widgetNE[0]->SetNumber(dtemp);
998
         vOut->widgetNE[0]->SetNumber(dtemp);
999
         sprintf(cmd, "WIENER-CRATE-MIB::outputSwitch.u%d = INTEGER: %s\n", GetChannel()-1, "%s" );
999
         sprintf(cmd, "WIENER-CRATE-MIB::outputSwitch.u%d = INTEGER: %s\n", GetChannel()-1, "%s" );
1000
         retTemp = fscanf(fvolt, cmd, ctemp);
1000
         retTemp = fscanf(fvolt, cmd, ctemp);
1001
         if( strcmp(ctemp, "On(1)") == 0 )
1001
         if( strcmp(ctemp, "On(1)") == 0 )
1002
            vOutOpt->widgetChBox[1]->SetState(kButtonDown);
1002
            vOutOpt->widgetChBox[1]->SetState(kButtonDown);
1003
         else if( strcmp(ctemp, "Off(0)") == 0 )
1003
         else if( strcmp(ctemp, "Off(0)") == 0 )
1004
            vOutOpt->widgetChBox[1]->SetState(kButtonUp);
1004
            vOutOpt->widgetChBox[1]->SetState(kButtonUp);
1005
      }
1005
      }
1006
   
1006
   
1007
      fclose(fvolt);
1007
      fclose(fvolt);
1008
#endif
1008
#endif
1009
   }
1009
   }
1010
   // Reset output voltage (if stuck in interlock)
1010
   // Reset output voltage (if stuck in interlock)
1011
   else if(opt == 2)
1011
   else if(opt == 2)
1012
   {
1012
   {
1013
      vOut->widgetNE[0]->SetNumber(0.000);
1013
      vOut->widgetNE[0]->SetNumber(0.000);
1014
      vOutOpt->widgetChBox[1]->SetState(kButtonUp);
1014
      vOutOpt->widgetChBox[1]->SetState(kButtonUp);
1015
 
1015
 
1016
      fflush(stdout);
1016
      fflush(stdout);
1017
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -r %d", rootdir, GetChannel());
1017
      sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -r %d", rootdir, GetChannel());
1018
#if WORKSTAT == 'I'
1018
#if WORKSTAT == 'I'
1019
      retTemp = system(cmd);
1019
      retTemp = system(cmd);
1020
#else
1020
#else
1021
      printf("Cmd: %s\n",cmd);
1021
      printf("Cmd: %s\n",cmd);
1022
#endif
1022
#endif
1023
      fflush(stdout);
1023
      fflush(stdout);
1024
   }
1024
   }
1025
}
1025
}
1026
 
1026
 
1027
// Set output voltage polarity to negative
1027
// Set output voltage polarity to negative
1028
void TGAppMainFrame::NegativePolarity()
1028
void TGAppMainFrame::NegativePolarity()
1029
{
1029
{
1030
   double newHardlimit;
1030
   double newHardlimit;
1031
   int polar = 0;  // 0 = positive, 1 = negative
1031
   int polar = 0;  // 0 = positive, 1 = negative
1032
 
1032
 
1033
   if(vOutOpt->widgetChBox[0]->IsOn())
1033
   if(vOutOpt->widgetChBox[0]->IsOn())
1034
      polar = 1;
1034
      polar = 1;
1035
   else
1035
   else
1036
      polar = 0;
1036
      polar = 0;
1037
 
1037
 
1038
   // Set hard limit to the negative version of what it was before
1038
   // Set hard limit to the negative version of what it was before
1039
   if( (vHardlimit->widgetNE[0]->GetNumber() > 0.) && (polar == 1) )
1039
   if( (vHardlimit->widgetNE[0]->GetNumber() > 0.) && (polar == 1) )
1040
      newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber());
1040
      newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber());
1041
   else if( (vHardlimit->widgetNE[0]->GetNumber() < 0.) && (polar == 0) )
1041
   else if( (vHardlimit->widgetNE[0]->GetNumber() < 0.) && (polar == 0) )
1042
      newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber());
1042
      newHardlimit = -(vHardlimit->widgetNE[0]->GetNumber());
1043
   else if(vHardlimit->widgetNE[0]->GetNumber() == 0.)
1043
   else if(vHardlimit->widgetNE[0]->GetNumber() == 0.)
1044
      newHardlimit = 0.;
1044
      newHardlimit = 0.;
1045
   else
1045
   else
1046
      newHardlimit = vHardlimit->widgetNE[0]->GetNumber();
1046
      newHardlimit = vHardlimit->widgetNE[0]->GetNumber();
1047
 
1047
 
1048
   // Apropriately set the limit to the output voltage number entry
1048
   // Apropriately set the limit to the output voltage number entry
1049
   vHardlimit->widgetNE[0]->SetNumber(newHardlimit);
1049
   vHardlimit->widgetNE[0]->SetNumber(newHardlimit);
1050
 
1050
 
1051
   if(polar == 1)
1051
   if(polar == 1)
1052
      vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, newHardlimit, 0.);
1052
      vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, newHardlimit, 0.);
1053
   else if(polar == 0)
1053
   else if(polar == 0)
1054
      vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, 0., newHardlimit);
1054
      vOut->widgetNE[0]->SetLimits(TGNumberFormat::kNELLimitMinMax, 0., newHardlimit);
1055
}
1055
}
1056
 
1056
 
1057
// Set, get, home or reset the table position
1057
// Set, get, home or reset the table position
1058
void TGAppMainFrame::PositionSet(int opt)
1058
void TGAppMainFrame::PositionSet(int opt)
1059
{
1059
{
1060
   char cmd[1024];
1060
   char cmd[1024];
1061
 
1061
 
1062
   // Set the selected table position
1062
   // Set the selected table position
1063
   if(opt == 0)
1063
   if(opt == 0)
1064
   {
1064
   {
1065
      int positX, positY, positZ;
1065
      int positX, positY, positZ;
1066
 
1066
 
1067
      if(posUnits->widgetCB->GetSelected() == 0)
1067
      if(posUnits->widgetCB->GetSelected() == 0)
1068
      {
1068
      {
1069
         positX = xPos->widgetNE[0]->GetNumber();
1069
         positX = xPos->widgetNE[0]->GetNumber();
1070
         positY = yPos->widgetNE[0]->GetNumber();
1070
         positY = yPos->widgetNE[0]->GetNumber();
1071
         positZ = zPos->widgetNE[0]->GetNumber();
1071
         positZ = zPos->widgetNE[0]->GetNumber();
1072
      }
1072
      }
1073
      else if(posUnits->widgetCB->GetSelected() == 1)
1073
      else if(posUnits->widgetCB->GetSelected() == 1)
1074
      {
1074
      {
1075
         positX = (int)xPos->widgetNE[0]->GetNumber()/lenconversion;
1075
         positX = (int)xPos->widgetNE[0]->GetNumber()/lenconversion;
1076
         positY = (int)yPos->widgetNE[0]->GetNumber()/lenconversion;
1076
         positY = (int)yPos->widgetNE[0]->GetNumber()/lenconversion;
1077
         positZ = (int)zPos->widgetNE[0]->GetNumber()/lenconversion;
1077
         positZ = (int)zPos->widgetNE[0]->GetNumber()/lenconversion;
1078
      }
1078
      }
1079
 
1079
 
1080
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, positX, rootdir);
1080
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, positX, rootdir);
1081
#if WORKSTAT == 'I'
1081
#if WORKSTAT == 'I'
1082
      retTemp = system(cmd);
1082
      retTemp = system(cmd);
1083
#else
1083
#else
1084
      printf("Cmd: %s\n",cmd);
1084
      printf("Cmd: %s\n",cmd);
1085
#endif
1085
#endif
1086
 
1086
 
1087
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, positY, rootdir);
1087
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, positY, rootdir);
1088
#if WORKSTAT == 'I'
1088
#if WORKSTAT == 'I'
1089
      retTemp = system(cmd);
1089
      retTemp = system(cmd);
1090
#else
1090
#else
1091
      printf("Cmd: %s\n",cmd);
1091
      printf("Cmd: %s\n",cmd);
1092
#endif
1092
#endif
1093
 
1093
 
1094
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, positZ, rootdir);
1094
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, positZ, rootdir);
1095
#if WORKSTAT == 'I'
1095
#if WORKSTAT == 'I'
1096
      retTemp = system(cmd);
1096
      retTemp = system(cmd);
1097
#else
1097
#else
1098
      printf("Cmd: %s\n",cmd);
1098
      printf("Cmd: %s\n",cmd);
1099
#endif
1099
#endif
1100
   }
1100
   }
1101
   // Get current table position
1101
   // Get current table position
1102
   else if(opt == 1)
1102
   else if(opt == 1)
1103
   {
1103
   {
1104
      fflush(stdout);
1104
      fflush(stdout);
1105
   
1105
   
1106
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -p > %s/settings/curpos.txt", rootdir, rootdir);  // X-axis
1106
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -p > %s/settings/curpos.txt", rootdir, rootdir);  // X-axis
1107
      fflush(stdout);
1107
      fflush(stdout);
1108
#if WORKSTAT == 'I'
1108
#if WORKSTAT == 'I'
1109
      retTemp = system(cmd);
1109
      retTemp = system(cmd);
1110
#else
1110
#else
1111
      printf("Cmd: %s\n",cmd);
1111
      printf("Cmd: %s\n",cmd);
1112
#endif
1112
#endif
1113
   
1113
   
1114
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Y-axis
1114
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Y-axis
1115
      fflush(stdout);
1115
      fflush(stdout);
1116
#if WORKSTAT == 'I'
1116
#if WORKSTAT == 'I'
1117
      retTemp = system(cmd);
1117
      retTemp = system(cmd);
1118
#else
1118
#else
1119
      printf("Cmd: %s\n",cmd);
1119
      printf("Cmd: %s\n",cmd);
1120
#endif
1120
#endif
1121
   
1121
   
1122
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Z-axis
1122
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -p >> %s/settings/curpos.txt", rootdir, rootdir); // Z-axis
1123
      fflush(stdout);
1123
      fflush(stdout);
1124
#if WORKSTAT == 'I'
1124
#if WORKSTAT == 'I'
1125
      retTemp = system(cmd);
1125
      retTemp = system(cmd);
1126
#else
1126
#else
1127
      printf("Cmd: %s\n",cmd);
1127
      printf("Cmd: %s\n",cmd);
1128
#endif
1128
#endif
1129
 
1129
 
1130
#if WORKSTAT == 'I'
1130
#if WORKSTAT == 'I'
1131
      FILE* fpos;
1131
      FILE* fpos;
1132
      int itemp;
1132
      int itemp;
1133
      sprintf(cmd, "%s/settings/curpos.txt", rootdir);
1133
      sprintf(cmd, "%s/settings/curpos.txt", rootdir);
1134
      fpos = fopen(cmd, "r");
1134
      fpos = fopen(cmd, "r");
1135
     
1135
     
1136
      if(fpos != NULL)
1136
      if(fpos != NULL)
1137
      {
1137
      {
1138
         if(posUnits->widgetCB->GetSelected() == 0)
1138
         if(posUnits->widgetCB->GetSelected() == 0)
1139
         {
1139
         {
1140
            retTemp = fscanf(fpos, "%d\n", &itemp);
1140
            retTemp = fscanf(fpos, "%d\n", &itemp);
1141
            xPos->widgetNE[0]->SetNumber(itemp);
1141
            xPos->widgetNE[0]->SetNumber(itemp);
1142
            retTemp = fscanf(fpos, "%d\n", &itemp);
1142
            retTemp = fscanf(fpos, "%d\n", &itemp);
1143
            yPos->widgetNE[0]->SetNumber(itemp);
1143
            yPos->widgetNE[0]->SetNumber(itemp);
1144
            retTemp = fscanf(fpos, "%d\n", &itemp);
1144
            retTemp = fscanf(fpos, "%d\n", &itemp);
1145
            zPos->widgetNE[0]->SetNumber(itemp);
1145
            zPos->widgetNE[0]->SetNumber(itemp);
1146
         }
1146
         }
1147
         else if(posUnits->widgetCB->GetSelected() == 1)
1147
         else if(posUnits->widgetCB->GetSelected() == 1)
1148
         {
1148
         {
1149
            retTemp = fscanf(fpos, "%d\n", &itemp);
1149
            retTemp = fscanf(fpos, "%d\n", &itemp);
1150
            xPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1150
            xPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1151
            retTemp = fscanf(fpos, "%d\n", &itemp);
1151
            retTemp = fscanf(fpos, "%d\n", &itemp);
1152
            yPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1152
            yPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1153
            retTemp = fscanf(fpos, "%d\n", &itemp);
1153
            retTemp = fscanf(fpos, "%d\n", &itemp);
1154
            zPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1154
            zPos->widgetNE[0]->SetNumber((double)itemp*lenconversion);
1155
         }
1155
         }
1156
      }
1156
      }
1157
 
1157
 
1158
      fclose(fpos);
1158
      fclose(fpos);
1159
#endif
1159
#endif
1160
   }
1160
   }
1161
   // Home the table position
1161
   // Home the table position
1162
   else if(opt == 2)
1162
   else if(opt == 2)
1163
   {
1163
   {
1164
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -h", rootdir);    // X-axis
1164
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -h", rootdir);    // X-axis
1165
#if WORKSTAT == 'I'
1165
#if WORKSTAT == 'I'
1166
      retTemp = system(cmd);
1166
      retTemp = system(cmd);
1167
#else
1167
#else
1168
      printf("Cmd: %s\n",cmd);
1168
      printf("Cmd: %s\n",cmd);
1169
#endif
1169
#endif
1170
 
1170
 
1171
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -h", rootdir);    // Y-axis
1171
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -h", rootdir);    // Y-axis
1172
#if WORKSTAT == 'I'
1172
#if WORKSTAT == 'I'
1173
      retTemp = system(cmd);
1173
      retTemp = system(cmd);
1174
#else
1174
#else
1175
      printf("Cmd: %s\n",cmd);
1175
      printf("Cmd: %s\n",cmd);
1176
#endif
1176
#endif
1177
 
1177
 
1178
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -h", rootdir);    // Z-axis
1178
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -h", rootdir);    // Z-axis
1179
#if WORKSTAT == 'I'
1179
#if WORKSTAT == 'I'
1180
      retTemp = system(cmd);
1180
      retTemp = system(cmd);
1181
#else
1181
#else
1182
      printf("Cmd: %s\n",cmd);
1182
      printf("Cmd: %s\n",cmd);
1183
#endif
1183
#endif
1184
      PositionSet(1);
1184
      PositionSet(1);
1185
   }
1185
   }
1186
   // Reset the table position
1186
   // Reset the table position
1187
   else if(opt == 3)
1187
   else if(opt == 3)
1188
   {
1188
   {
1189
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -r && sudo %s/src/MIKRO/mikro_ctrl -n 1 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 1 -h", rootdir, rootdir, rootdir);        // X-axis
1189
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -r && sudo %s/src/MIKRO/mikro_ctrl -n 1 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 1 -h", rootdir, rootdir, rootdir);        // X-axis
1190
#if WORKSTAT == 'I'
1190
#if WORKSTAT == 'I'
1191
      printf("Positioning table reset, initialization and homing in progress. Please wait...\n");
1191
      printf("Positioning table reset, initialization and homing in progress. Please wait...\n");
1192
      retTemp = system(cmd);
1192
      retTemp = system(cmd);
1193
#else
1193
#else
1194
      printf("Cmd: %s\n",cmd);
1194
      printf("Cmd: %s\n",cmd);
1195
#endif
1195
#endif
1196
 
1196
 
1197
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -r && sudo %s/src/MIKRO/mikro_ctrl -n 2 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 2 -h", rootdir, rootdir, rootdir);        // Y-axis
1197
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -r && sudo %s/src/MIKRO/mikro_ctrl -n 2 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 2 -h", rootdir, rootdir, rootdir);        // Y-axis
1198
#if WORKSTAT == 'I'
1198
#if WORKSTAT == 'I'
1199
      retTemp = system(cmd);
1199
      retTemp = system(cmd);
1200
#else
1200
#else
1201
      printf("Cmd: %s\n",cmd);
1201
      printf("Cmd: %s\n",cmd);
1202
#endif
1202
#endif
1203
 
1203
 
1204
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -r && sudo %s/src/MIKRO/mikro_ctrl -n 3 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 3 -h", rootdir, rootdir, rootdir);        // Z-axis
1204
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -r && sudo %s/src/MIKRO/mikro_ctrl -n 3 -i 3 && sudo %s/src/MIKRO/mikro_ctrl -n 3 -h", rootdir, rootdir, rootdir);        // Z-axis
1205
#if WORKSTAT == 'I'
1205
#if WORKSTAT == 'I'
1206
      retTemp = system(cmd);
1206
      retTemp = system(cmd);
1207
      printf("Positioning table reset, initialization and homing complete.\n");
1207
      printf("Positioning table reset, initialization and homing complete.\n");
1208
#else
1208
#else
1209
      printf("Cmd: %s\n",cmd);
1209
      printf("Cmd: %s\n",cmd);
1210
#endif
1210
#endif
1211
      PositionSet(1);
1211
      PositionSet(1);
1212
   }
1212
   }
1213
}
1213
}
1214
 
1214
 
1215
// Set, get, home or reset the rotation platform
1215
// Set, get, home or reset the rotation platform
1216
void TGAppMainFrame::RotationSet(int opt)
1216
void TGAppMainFrame::RotationSet(int opt)
1217
{
1217
{
1218
   char cmd[1024];
1218
   char cmd[1024];
1219
 
1219
 
1220
   // Set the selected rotation
1220
   // Set the selected rotation
1221
   if(opt == 0)
1221
   if(opt == 0)
1222
   {
1222
   {
1223
      int positAlpha;
1223
      int positAlpha;
1224
 
1224
 
1225
      if(rotUnits->widgetCB->GetSelected() == 0)
1225
      if(rotUnits->widgetCB->GetSelected() == 0)
1226
         positAlpha = rotPos->widgetNE[0]->GetNumber();
1226
         positAlpha = rotPos->widgetNE[0]->GetNumber();
1227
      else if(rotUnits->widgetCB->GetSelected() == 1)
1227
      else if(rotUnits->widgetCB->GetSelected() == 1)
1228
         positAlpha = rotPos->widgetNE[0]->GetNumber()/rotconversion;
1228
         positAlpha = rotPos->widgetNE[0]->GetNumber()/rotconversion;
1229
 
1229
 
1230
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, positAlpha, rootdir);
1230
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, positAlpha, rootdir);
1231
#if WORKSTAT == 'I'
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
   }
1236
   }
1237
   // Get current rotation
1237
   // Get current rotation
1238
   else if(opt == 1)
1238
   else if(opt == 1)
1239
   {
1239
   {
1240
      fflush(stdout);
1240
      fflush(stdout);
1241
   
1241
   
1242
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -p > %s/settings/currot.txt", rootdir, rootdir);
1242
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -p > %s/settings/currot.txt", rootdir, rootdir);
1243
      fflush(stdout);
1243
      fflush(stdout);
1244
#if WORKSTAT == 'I'
1244
#if WORKSTAT == 'I'
1245
      retTemp = system(cmd);
1245
      retTemp = system(cmd);
1246
#else
1246
#else
1247
      printf("Cmd: %s\n",cmd);
1247
      printf("Cmd: %s\n",cmd);
1248
#endif
1248
#endif
1249
 
1249
 
1250
#if WORKSTAT == 'I'
1250
#if WORKSTAT == 'I'
1251
      FILE* frot;
1251
      FILE* frot;
1252
      int itemp;
1252
      int itemp;
1253
      sprintf(cmd, "%s/settings/currot.txt", rootdir);
1253
      sprintf(cmd, "%s/settings/currot.txt", rootdir);
1254
      frot = fopen(cmd, "r");
1254
      frot = fopen(cmd, "r");
1255
 
1255
 
1256
      if(frot != NULL)
1256
      if(frot != NULL)
1257
      {
1257
      {
1258
         retTemp = fscanf(frot, "%d\n", &itemp);
1258
         retTemp = fscanf(frot, "%d\n", &itemp);
1259
         if(rotUnits->widgetCB->GetSelected() == 0)
1259
         if(rotUnits->widgetCB->GetSelected() == 0)
1260
            rotPos->widgetNE[0]->SetNumber(itemp);
1260
            rotPos->widgetNE[0]->SetNumber(itemp);
1261
         else if(rotUnits->widgetCB->GetSelected() == 1)
1261
         else if(rotUnits->widgetCB->GetSelected() == 1)
1262
            rotPos->widgetNE[0]->SetNumber((double)itemp*rotconversion);
1262
            rotPos->widgetNE[0]->SetNumber((double)itemp*rotconversion);
1263
      }
1263
      }
1264
 
1264
 
1265
      fclose(frot);
1265
      fclose(frot);
1266
#endif
1266
#endif
1267
   }
1267
   }
1268
   // Home the rotation
1268
   // Home the rotation
1269
   else if(opt == 2)
1269
   else if(opt == 2)
1270
   {
1270
   {
1271
      // TODO: For now only set back to 0, not home!
1271
      // TODO: For now only set back to 0, not home!
1272
//      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -h", rootdir);
1272
//      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -h", rootdir);
1273
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v 0 -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, rootdir);
1273
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v 0 -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, rootdir);
1274
#if WORKSTAT == 'I'
1274
#if WORKSTAT == 'I'
1275
      retTemp = system(cmd);
1275
      retTemp = system(cmd);
1276
#else
1276
#else
1277
      printf("Cmd: %s\n",cmd);
1277
      printf("Cmd: %s\n",cmd);
1278
#endif
1278
#endif
1279
      RotationSet(1);
1279
      RotationSet(1);
1280
   }
1280
   }
1281
   // Reset the rotation
1281
   // Reset the rotation
1282
   else if(opt == 3)
1282
   else if(opt == 3)
1283
   {
1283
   {
1284
      // TODO: For now only set back to 0, not home!
1284
      // TODO: For now only set back to 0, not home!
1285
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -r && sudo %s/src/MIKRO/mikro_ctrl -n 4 -i 2 && sudo %s/src/MIKRO/mikro_ctrl -n 4 -h", rootdir, rootdir, rootdir);
1285
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -r && sudo %s/src/MIKRO/mikro_ctrl -n 4 -i 2 && sudo %s/src/MIKRO/mikro_ctrl -n 4 -h", rootdir, rootdir, rootdir);
1286
#if WORKSTAT == 'I'
1286
#if WORKSTAT == 'I'
1287
      printf("Rotation platform reset, initalization and homing in progress. Please wait...\n");
1287
      printf("Rotation platform reset, initalization and homing in progress. Please wait...\n");
1288
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v 0 -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, rootdir);
1288
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v 0 -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, rootdir);
1289
      retTemp = system(cmd);
1289
      retTemp = system(cmd);
1290
      sleep(15);        // wait for the motor to change position from wherever to 0
1290
      sleep(15);        // wait for the motor to change position from wherever to 0
1291
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -r && sudo %s/src/MIKRO/mikro_ctrl -n 4 -i 2", rootdir, rootdir);
1291
      sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -r && sudo %s/src/MIKRO/mikro_ctrl -n 4 -i 2", rootdir, rootdir);
1292
      retTemp = system(cmd);
1292
      retTemp = system(cmd);
1293
      printf("Rotation platform reset, initalization and homing complete.\n");
1293
      printf("Rotation platform reset, initalization and homing complete.\n");
1294
#else
1294
#else
1295
      printf("Cmd: %s\n",cmd);
1295
      printf("Cmd: %s\n",cmd);
1296
#endif
1296
#endif
1297
      RotationSet(1);
1297
      RotationSet(1);
1298
   }
1298
   }
1299
}
1299
}
1300
 
1300
 
1301
// File browser for selecting the save file
1301
// File browser for selecting the save file
1302
void TGAppMainFrame::SaveFile()
1302
void TGAppMainFrame::SaveFile()
1303
{
1303
{
1304
   TGFileInfo file_info;
1304
   TGFileInfo file_info;
1305
   const char *filetypes[] = {"Histograms",histextall,0,0};
1305
   const char *filetypes[] = {"Histograms",histextall,0,0};
1306
   char *cTemp;
1306
   char *cTemp;
1307
   file_info.fFileTypes = filetypes;
1307
   file_info.fFileTypes = filetypes;
1308
   cTemp = new char[1024];
1308
   cTemp = new char[1024];
1309
   sprintf(cTemp, "%s/results", rootdir);
1309
   sprintf(cTemp, "%s/results", rootdir);
1310
   file_info.fIniDir = StrDup(cTemp);
1310
   file_info.fIniDir = StrDup(cTemp);
1311
   new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDSave, &file_info);
1311
   new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDSave, &file_info);
1312
   delete[] cTemp;
1312
   delete[] cTemp;
1313
 
1313
 
1314
   if(file_info.fFilename != NULL)
1314
   if(file_info.fFilename != NULL)
1315
      fileName->widgetTE->SetText(file_info.fFilename);
1315
      fileName->widgetTE->SetText(file_info.fFilename);
1316
}
1316
}
1317
 
1317
 
1318
// Start the acquisition
1318
// Start the acquisition
1319
void TGAppMainFrame::StartAcq()
1319
void TGAppMainFrame::StartAcq()
1320
{
1320
{
1321
   // Variable that will initialize camac only once (for scans)
1321
   // Variable that will initialize camac only once (for scans)
1322
   int scanon = 0;
1322
   int scanon = 0;
1323
 
1323
 
1324
   // Determine the type of measurement to perform
1324
   // Determine the type of measurement to perform
1325
   int vscan = 0, pscan = 0, zscan = 0, ascan = 0;
1325
   int vscan = 0, pscan = 0, zscan = 0, ascan = 0;
1326
   if(scansOn->widgetChBox[0]->IsDown()) vscan = 1;
1326
   if(scansOn->widgetChBox[0]->IsDown()) vscan = 1;
1327
   if(scansOn->widgetChBox[1]->IsDown()) pscan = 1;
1327
   if(scansOn->widgetChBox[1]->IsDown()) pscan = 1;
1328
   if(scansOn->widgetChBox[2]->IsDown()) zscan = 1;
1328
   if(scansOn->widgetChBox[2]->IsDown()) zscan = 1;
1329
   if(scansOn->widgetChBox[3]->IsDown()) ascan = 1;
1329
   if(scansOn->widgetChBox[3]->IsDown()) ascan = 1;
1330
 
1330
 
1331
   char cmd[256];
1331
   char cmd[256];
1332
   int i, j, k;
1332
   int i, j, k;
1333
   float progVal;
1333
   float progVal;
1334
   FILE *pfin;
1334
   FILE *pfin;
1335
 
1335
 
1336
   // Variables for voltage scan
1336
   // Variables for voltage scan
1337
   float currentVoltage, minVoltage, maxVoltage, stepVoltage;
1337
   float currentVoltage, minVoltage, maxVoltage, stepVoltage;
1338
   int repetition;
1338
   int repetition;
1339
 
1339
 
1340
   // Variables for surface scan and Z axis scan
1340
   // Variables for surface scan and Z axis scan
1341
   float minXpos, maxXpos, stepXpos;
1341
   float minXpos, maxXpos, stepXpos;
1342
   float minYpos, maxYpos, stepYpos;
1342
   float minYpos, maxYpos, stepYpos;
1343
   float minZpos, maxZpos, stepZpos;
1343
   float minZpos, maxZpos, stepZpos;
1344
   int repetX, repetY, repetZ;
1344
   int repetX, repetY, repetZ;
1345
 
1345
 
1346
   // Variables for angle scan
1346
   // Variables for angle scan
1347
   float currentAlpha, minAlpha, maxAlpha, stepAlpha;
1347
   float currentAlpha, minAlpha, maxAlpha, stepAlpha;
1348
   int repetAlpha;
1348
   int repetAlpha;
1349
 
1349
 
1350
   // Only voltage scan
1350
   // Only voltage scan
1351
   if( (vscan == 1) && (pscan == 0) && (ascan == 0) )
1351
   if( (vscan == 1) && (pscan == 0) && (ascan == 0) )
1352
   { // TODO - include possibility to make voltage and angle scan at same time
1352
   { // TODO - include possibility to make voltage and angle scan at same time
1353
      // If already started, stop the acquisition
1353
      // If already started, stop the acquisition
1354
      if(acqStarted)
1354
      if(acqStarted)
1355
      {
1355
      {
1356
         printf("Stopping current voltage scan...\n");
1356
         printf("Stopping current voltage scan...\n");
1357
         gROOT->SetInterrupt();
1357
         gROOT->SetInterrupt();
1358
         measProgress->widgetTB[0]->SetText("Start acquisition");
1358
         measProgress->widgetTB[0]->SetText("Start acquisition");
1359
         acqStarted = false;
1359
         acqStarted = false;
1360
 
1360
 
1361
         // Write information to the finish_sig.txt value
1361
         // Write information to the finish_sig.txt value
1362
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1362
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1363
         pfin = fopen(cmd,"w");
1363
         pfin = fopen(cmd,"w");
1364
         fprintf(pfin, "%s: Voltage scan stopped.", timeStamp->widgetTE->GetText());
1364
         fprintf(pfin, "%s: Voltage scan stopped.", timeStamp->widgetTE->GetText());
1365
         fclose(pfin);
1365
         fclose(pfin);
1366
      }
1366
      }
1367
      // If stopped, start the acquisition
1367
      // If stopped, start the acquisition
1368
      else if(!acqStarted)
1368
      else if(!acqStarted)
1369
      {
1369
      {
1370
         printf("Running a voltage scan...\n");
1370
         printf("Running a voltage scan...\n");
1371
 
1371
 
1372
         // Check the steps
1372
         // Check the steps
1373
         minVoltage = vOutStart->widgetNE[0]->GetNumber();
1373
         minVoltage = vOutStart->widgetNE[0]->GetNumber();
1374
         maxVoltage = vOutStop->widgetNE[0]->GetNumber();
1374
         maxVoltage = vOutStop->widgetNE[0]->GetNumber();
1375
         stepVoltage = vOutStep->widgetNE[0]->GetNumber();
1375
         stepVoltage = vOutStep->widgetNE[0]->GetNumber();
1376
 
1376
 
1377
         if(stepVoltage == 0.)
1377
         if(stepVoltage == 0.)
1378
            repetition = 1;
1378
            repetition = 1;
1379
         else
1379
         else
1380
         {
1380
         {
1381
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1381
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1382
            if( (maxVoltage > minVoltage) && (stepVoltage > 0) )
1382
            if( (maxVoltage > minVoltage) && (stepVoltage > 0) )
1383
               repetition = ((maxVoltage - minVoltage)/stepVoltage)+1;
1383
               repetition = ((maxVoltage - minVoltage)/stepVoltage)+1;
1384
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1384
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1385
            else if( (maxVoltage < minVoltage) && (stepVoltage < 0) )
1385
            else if( (maxVoltage < minVoltage) && (stepVoltage < 0) )
1386
               repetition = ((minVoltage - maxVoltage)/stepVoltage)-1;
1386
               repetition = ((minVoltage - maxVoltage)/stepVoltage)-1;
1387
            // Example: min = 70, max = 70 (no scan)
1387
            // Example: min = 70, max = 70 (no scan)
1388
            else if( maxVoltage == minVoltage )
1388
            else if( maxVoltage == minVoltage )
1389
               repetition = 1;
1389
               repetition = 1;
1390
            // If step is not correctly set, stop the acqusition
1390
            // If step is not correctly set, stop the acqusition
1391
            else
1391
            else
1392
            {
1392
            {
1393
               // TODO
1393
               // TODO
1394
               printf("Stopping current voltage scan...\n");
1394
               printf("Stopping current voltage scan...\n");
1395
               gROOT->SetInterrupt();
1395
               gROOT->SetInterrupt();
1396
               measProgress->widgetTB[0]->SetText("Start acquisition");
1396
               measProgress->widgetTB[0]->SetText("Start acquisition");
1397
               acqStarted = false;
1397
               acqStarted = false;
1398
               repetition = 0;
1398
               repetition = 0;
1399
            }
1399
            }
1400
         }
1400
         }
1401
 
1401
 
1402
         if(DBGSIG) printf("StartAcq(): Voltage repetition (%lf,%lf,%lf) = %d\n", minVoltage, maxVoltage, stepVoltage, repetition);
1402
         if(DBGSIG) printf("StartAcq(): Voltage repetition (%lf,%lf,%lf) = %d\n", minVoltage, maxVoltage, stepVoltage, repetition);
1403
 
1403
 
1404
         i = 0;
1404
         i = 0;
1405
 
1405
 
1406
         // TODO - Setting button text and acqStarted do not work!
1406
         // TODO - Setting button text and acqStarted do not work!
1407
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1407
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1408
         acqStarted = true;
1408
         acqStarted = true;
1409
         progVal = 0.00;
1409
         progVal = 0.00;
1410
         measProgress->widgetPB->SetPosition(progVal);
1410
         measProgress->widgetPB->SetPosition(progVal);
1411
         gVirtualX->Update(1);
1411
         gVirtualX->Update(1);
1412
 
1412
 
1413
         clkt0 = clock();
1413
         clkt0 = clock();
1414
         timet0 = time(NULL);
1414
         timet0 = time(NULL);
1415
 
1415
 
1416
         while(1)
1416
         while(1)
1417
         {
1417
         {
1418
            if( (repetition > 0) && (i == repetition) ) break;
1418
            if( (repetition > 0) && (i == repetition) ) break;
1419
            else if( (repetition < 0) && (i == -repetition) ) break;
1419
            else if( (repetition < 0) && (i == -repetition) ) break;
1420
            else if( repetition == 0 ) break;
1420
            else if( repetition == 0 ) break;
1421
 
1421
 
1422
            progVal = (float)(100.00/abs(repetition))*i;
1422
            progVal = (float)(100.00/abs(repetition))*i;
1423
            measProgress->widgetPB->SetPosition(progVal);
1423
            measProgress->widgetPB->SetPosition(progVal);
1424
 
1424
 
1425
            TimeEstimate(clkt0, timet0, progVal, cmd, singlewait*abs(repetition));
1425
            TimeEstimate(clkt0, timet0, progVal, cmd, singlewait*abs(repetition));
1426
            measProgress->widgetTE->SetText(cmd);
1426
            measProgress->widgetTE->SetText(cmd);
1427
 
1427
 
1428
            gVirtualX->Update(1);
1428
            gVirtualX->Update(1);
1429
       
1429
       
1430
            fflush(stdout);
1430
            fflush(stdout);
1431
            currentVoltage = minVoltage + stepVoltage*i;
1431
            currentVoltage = minVoltage + stepVoltage*i;
1432
            sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), currentVoltage);
1432
            sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), currentVoltage);
1433
#if WORKSTAT == 'I'
1433
#if WORKSTAT == 'I'
1434
            retTemp = system(cmd);
1434
            retTemp = system(cmd);
1435
#else
1435
#else
1436
            printf("Cmd: %s\n",cmd);
1436
            printf("Cmd: %s\n",cmd);
1437
#endif
1437
#endif
1438
            fflush(stdout);
1438
            fflush(stdout);
1439
       
1439
       
1440
            printf("Waiting for voltage change...\n");
1440
            printf("Waiting for voltage change...\n");
1441
            sleep(singlewait);
1441
            sleep(singlewait);
1442
            vOut->widgetNE[0]->SetNumber(currentVoltage);
1442
            vOut->widgetNE[0]->SetNumber(currentVoltage);
1443
            gVirtualX->Update(1);
1443
            gVirtualX->Update(1);
1444
            printf("Continuing...\n");
1444
            printf("Continuing...\n");
1445
       
1445
       
1446
            // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<<
1446
            // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<<
1447
            RunMeas((void*)0, i, scanon); // TODO
1447
            RunMeas((void*)0, i, scanon); // TODO
1448
            fflush(stdout);
1448
            fflush(stdout);
1449
 
1449
 
1450
            i++;
1450
            i++;
1451
         }
1451
         }
1452
 
1452
 
1453
         // Set output back to off
1453
         // Set output back to off
1454
         fflush(stdout);
1454
         fflush(stdout);
1455
         printf("Measurement finished, returning to starting voltage...\n");
1455
         printf("Measurement finished, returning to starting voltage...\n");
1456
         sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), minVoltage);
1456
         sprintf(cmd, "%s/src/mpod/mpod_voltage.sh -o %d -v %f -s 1", rootdir, GetChannel(), minVoltage);
1457
         vOut->widgetNE[0]->SetNumber(minVoltage);
1457
         vOut->widgetNE[0]->SetNumber(minVoltage);
1458
#if WORKSTAT == 'I'
1458
#if WORKSTAT == 'I'
1459
         retTemp = system(cmd);
1459
         retTemp = system(cmd);
1460
#else
1460
#else
1461
         printf("Cmd: %s\n",cmd);
1461
         printf("Cmd: %s\n",cmd);
1462
#endif
1462
#endif
1463
         fflush(stdout);
1463
         fflush(stdout);
1464
       
1464
       
1465
         progVal = 100.00;
1465
         progVal = 100.00;
1466
         measProgress->widgetPB->SetPosition(progVal);
1466
         measProgress->widgetPB->SetPosition(progVal);
1467
         printf("\n");
1467
         printf("\n");
1468
 
1468
 
1469
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1469
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1470
         pfin = fopen(cmd,"w");
1470
         pfin = fopen(cmd,"w");
1471
         fprintf(pfin, "%s: Voltage scan finished.", timeStamp->widgetTE->GetText());
1471
         fprintf(pfin, "%s: Voltage scan finished.", timeStamp->widgetTE->GetText());
1472
         fclose(pfin);
1472
         fclose(pfin);
1473
 
1473
 
1474
         measProgress->widgetTB[0]->SetText("Start acquisition");
1474
         measProgress->widgetTB[0]->SetText("Start acquisition");
1475
         acqStarted = false;
1475
         acqStarted = false;
1476
      }
1476
      }
1477
   }
1477
   }
1478
   // Surface scan
1478
   // Surface scan
1479
   else if( (pscan == 1) && (vscan == 0) && (ascan == 0) )
1479
   else if( (pscan == 1) && (vscan == 0) && (ascan == 0) )
1480
   {
1480
   {
1481
      // If already started, stop the acquisition
1481
      // If already started, stop the acquisition
1482
      if(acqStarted)
1482
      if(acqStarted)
1483
      {
1483
      {
1484
         printf("Stopping current surface scan...\n");
1484
         printf("Stopping current surface scan...\n");
1485
         gROOT->SetInterrupt();
1485
         gROOT->SetInterrupt();
1486
         measProgress->widgetTB[0]->SetText("Start acquisition");
1486
         measProgress->widgetTB[0]->SetText("Start acquisition");
1487
         acqStarted = false;
1487
         acqStarted = false;
1488
 
1488
 
1489
         // Write information to the finish_sig.txt value
1489
         // Write information to the finish_sig.txt value
1490
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1490
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1491
         pfin = fopen(cmd,"w");
1491
         pfin = fopen(cmd,"w");
1492
         fprintf(pfin, "%s: Surface scan stopped.", timeStamp->widgetTE->GetText());
1492
         fprintf(pfin, "%s: Surface scan stopped.", timeStamp->widgetTE->GetText());
1493
         fclose(pfin);
1493
         fclose(pfin);
1494
      }
1494
      }
1495
      // If stopped, start the acquisition
1495
      // If stopped, start the acquisition
1496
      else if(!acqStarted)
1496
      else if(!acqStarted)
1497
      {
1497
      {
1498
         printf("Running a surface scan...\n");
1498
         printf("Running a surface scan...\n");
1499
 
1499
 
1500
         minXpos = xPosMin->widgetNE[0]->GetNumber();
1500
         minXpos = xPosMin->widgetNE[0]->GetNumber();
1501
         maxXpos = xPosMax->widgetNE[0]->GetNumber();
1501
         maxXpos = xPosMax->widgetNE[0]->GetNumber();
1502
         stepXpos = xPosStep->widgetNE[0]->GetNumber();
1502
         stepXpos = xPosStep->widgetNE[0]->GetNumber();
1503
         minYpos = yPosMin->widgetNE[0]->GetNumber();
1503
         minYpos = yPosMin->widgetNE[0]->GetNumber();
1504
         maxYpos = yPosMax->widgetNE[0]->GetNumber();
1504
         maxYpos = yPosMax->widgetNE[0]->GetNumber();
1505
         stepYpos = yPosStep->widgetNE[0]->GetNumber();
1505
         stepYpos = yPosStep->widgetNE[0]->GetNumber();
1506
         minZpos = zPosMin->widgetNE[0]->GetNumber();
1506
         minZpos = zPosMin->widgetNE[0]->GetNumber();
1507
         maxZpos = zPosMax->widgetNE[0]->GetNumber();
1507
         maxZpos = zPosMax->widgetNE[0]->GetNumber();
1508
         stepZpos = zPosStep->widgetNE[0]->GetNumber();
1508
         stepZpos = zPosStep->widgetNE[0]->GetNumber();
1509
 
1509
 
1510
         // Setting repetition for Z axis scan
1510
         // Setting repetition for Z axis scan
1511
         if(zscan == 1)
1511
         if(zscan == 1)
1512
         {
1512
         {
1513
            if(stepZpos == 0.)
1513
            if(stepZpos == 0.)
1514
               repetZ = 1;
1514
               repetZ = 1;
1515
            else
1515
            else
1516
            {
1516
            {
1517
               // Example: min = 40, max = 70, step = 5 (in increasing steps)
1517
               // Example: min = 40, max = 70, step = 5 (in increasing steps)
1518
               if( (maxZpos > minZpos) && (stepZpos > 0) )
1518
               if( (maxZpos > minZpos) && (stepZpos > 0) )
1519
                  repetZ = ((maxZpos - minZpos)/stepZpos)+1;
1519
                  repetZ = ((maxZpos - minZpos)/stepZpos)+1;
1520
               // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1520
               // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1521
               else if( (maxZpos < minZpos) && (stepZpos < 0) )
1521
               else if( (maxZpos < minZpos) && (stepZpos < 0) )
1522
                  repetZ = ((minZpos - maxZpos)/stepZpos)-1;
1522
                  repetZ = ((minZpos - maxZpos)/stepZpos)-1;
1523
               // Example: min = 70, max = 70 (no scan)
1523
               // Example: min = 70, max = 70 (no scan)
1524
               else if( maxZpos == minZpos )
1524
               else if( maxZpos == minZpos )
1525
                  repetZ = 1;
1525
                  repetZ = 1;
1526
               // If step is not correctly set, stop the acqusition
1526
               // If step is not correctly set, stop the acqusition
1527
               else
1527
               else
1528
               {
1528
               {
1529
                  // TODO
1529
                  // TODO
1530
                  printf("Stopping current surface scan (Z step error)...\n");
1530
                  printf("Stopping current surface scan (Z step error)...\n");
1531
                  gROOT->SetInterrupt();
1531
                  gROOT->SetInterrupt();
1532
                  measProgress->widgetTB[0]->SetText("Start acquisition");
1532
                  measProgress->widgetTB[0]->SetText("Start acquisition");
1533
                  acqStarted = false;
1533
                  acqStarted = false;
1534
                  repetZ = 0;
1534
                  repetZ = 0;
1535
               }
1535
               }
1536
            }
1536
            }
1537
         }
1537
         }
1538
         else
1538
         else
1539
         {
1539
         {
1540
            minZpos = zPos->widgetNE[0]->GetNumber();
1540
            minZpos = zPos->widgetNE[0]->GetNumber();
1541
            repetZ = 1;
1541
            repetZ = 1;
1542
         }
1542
         }
1543
 
1543
 
1544
         // Setting repetition for X axis
1544
         // Setting repetition for X axis
1545
         if(stepXpos == 0.)
1545
         if(stepXpos == 0.)
1546
            repetX = 1;
1546
            repetX = 1;
1547
         else
1547
         else
1548
         {
1548
         {
1549
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1549
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1550
            if( (maxXpos > minXpos) && (stepXpos > 0) )
1550
            if( (maxXpos > minXpos) && (stepXpos > 0) )
1551
               repetX = ((maxXpos - minXpos)/stepXpos)+1;
1551
               repetX = ((maxXpos - minXpos)/stepXpos)+1;
1552
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1552
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1553
            else if( (maxXpos < minXpos) && (stepXpos < 0) )
1553
            else if( (maxXpos < minXpos) && (stepXpos < 0) )
1554
               repetX = ((minXpos - maxXpos)/stepXpos)-1;
1554
               repetX = ((minXpos - maxXpos)/stepXpos)-1;
1555
            // Example: min = 70, max = 70 (no scan)
1555
            // Example: min = 70, max = 70 (no scan)
1556
            else if( maxXpos == minXpos )
1556
            else if( maxXpos == minXpos )
1557
               repetX = 1;
1557
               repetX = 1;
1558
            // If step is not correctly set, stop the acqusition
1558
            // If step is not correctly set, stop the acqusition
1559
            else
1559
            else
1560
            {
1560
            {
1561
               // TODO
1561
               // TODO
1562
               printf("Stopping current surface scan (X step error)...\n");
1562
               printf("Stopping current surface scan (X step error)...\n");
1563
               gROOT->SetInterrupt();
1563
               gROOT->SetInterrupt();
1564
               measProgress->widgetTB[0]->SetText("Start acquisition");
1564
               measProgress->widgetTB[0]->SetText("Start acquisition");
1565
               acqStarted = false;
1565
               acqStarted = false;
1566
               repetX = 0;
1566
               repetX = 0;
1567
            }
1567
            }
1568
         }
1568
         }
1569
         // Setting repetition for Y axis
1569
         // Setting repetition for Y axis
1570
         if(stepYpos == 0.)
1570
         if(stepYpos == 0.)
1571
            repetY = 1;
1571
            repetY = 1;
1572
         else
1572
         else
1573
         {
1573
         {
1574
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1574
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1575
            if( (maxYpos > minYpos) && (stepYpos > 0) )
1575
            if( (maxYpos > minYpos) && (stepYpos > 0) )
1576
               repetY = ((maxYpos - minYpos)/stepYpos)+1;
1576
               repetY = ((maxYpos - minYpos)/stepYpos)+1;
1577
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1577
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1578
            else if( (maxYpos < minYpos) && (stepYpos < 0) )
1578
            else if( (maxYpos < minYpos) && (stepYpos < 0) )
1579
               repetY = ((minYpos - maxYpos)/stepYpos)-1;
1579
               repetY = ((minYpos - maxYpos)/stepYpos)-1;
1580
            // Example: min = 70, max = 70 (no scan)
1580
            // Example: min = 70, max = 70 (no scan)
1581
            else if( maxYpos == minYpos )
1581
            else if( maxYpos == minYpos )
1582
               repetY = 1;
1582
               repetY = 1;
1583
            // If step is not correctly set, stop the acqusition
1583
            // If step is not correctly set, stop the acqusition
1584
            else
1584
            else
1585
            {
1585
            {
1586
               // TODO
1586
               // TODO
1587
               printf("Stopping current surface scan (Y step error)...\n");
1587
               printf("Stopping current surface scan (Y step error)...\n");
1588
               gROOT->SetInterrupt();
1588
               gROOT->SetInterrupt();
1589
               measProgress->widgetTB[0]->SetText("Start acquisition");
1589
               measProgress->widgetTB[0]->SetText("Start acquisition");
1590
               acqStarted = false;
1590
               acqStarted = false;
1591
               repetY = 0;
1591
               repetY = 0;
1592
            }
1592
            }
1593
         }
1593
         }
1594
 
1594
 
1595
         if(DBGSIG) printf("StartAcq(): X axis repetition (%lf,%lf,%lf) = %d\n", minXpos, maxXpos, stepXpos, repetX);
1595
         if(DBGSIG) printf("StartAcq(): X axis repetition (%lf,%lf,%lf) = %d\n", minXpos, maxXpos, stepXpos, repetX);
1596
         if(DBGSIG) printf("StartAcq(): Y axis repetition (%lf,%lf,%lf) = %d\n", minYpos, maxYpos, stepYpos, repetY);
1596
         if(DBGSIG) printf("StartAcq(): Y axis repetition (%lf,%lf,%lf) = %d\n", minYpos, maxYpos, stepYpos, repetY);
1597
         if(DBGSIG) printf("StartAcq(): Z axis repetition (%lf,%lf,%lf) = %d\n", minZpos, maxZpos, stepZpos, repetZ);
1597
         if(DBGSIG) printf("StartAcq(): Z axis repetition (%lf,%lf,%lf) = %d\n", minZpos, maxZpos, stepZpos, repetZ);
1598
 
1598
 
1599
         i = 0; j = 0; k = 0;
1599
         i = 0; j = 0; k = 0;
1600
 
1600
 
1601
         // TODO - Setting button text and acqStarted do not work!
1601
         // TODO - Setting button text and acqStarted do not work!
1602
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1602
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1603
         acqStarted = true;
1603
         acqStarted = true;
1604
         progVal = 0.00;
1604
         progVal = 0.00;
1605
         measProgress->widgetPB->SetPosition(progVal);
1605
         measProgress->widgetPB->SetPosition(progVal);
1606
         gVirtualX->Update(1);
1606
         gVirtualX->Update(1);
1607
 
1607
 
1608
         clkt0 = clock();
1608
         clkt0 = clock();
1609
         timet0 = time(NULL);
1609
         timet0 = time(NULL);
1610
 
1610
 
1611
         // Scan over Z axis
1611
         // Scan over Z axis
1612
         while(1)
1612
         while(1)
1613
         {
1613
         {
1614
            if( (repetZ > 0) && (k == repetZ) ) break;
1614
            if( (repetZ > 0) && (k == repetZ) ) break;
1615
            else if( (repetZ < 0) && (k == -repetZ) ) break;
1615
            else if( (repetZ < 0) && (k == -repetZ) ) break;
1616
            else if( repetZ == 0 ) break;
1616
            else if( repetZ == 0 ) break;
1617
 
1617
 
1618
            fflush(stdout);
1618
            fflush(stdout);
1619
            // Z-axis change
1619
            // Z-axis change
1620
            if( posUnits->widgetCB->GetSelected() == 0)
1620
            if( posUnits->widgetCB->GetSelected() == 0)
1621
               sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)(minZpos + stepZpos*k), rootdir);
1621
               sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)(minZpos + stepZpos*k), rootdir);
1622
            else if( posUnits->widgetCB->GetSelected() == 1)
1622
            else if( posUnits->widgetCB->GetSelected() == 1)
1623
               sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)((minZpos + stepZpos*k)/lenconversion), rootdir);
1623
               sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)((minZpos + stepZpos*k)/lenconversion), rootdir);
1624
#if WORKSTAT == 'I'
1624
#if WORKSTAT == 'I'
1625
            retTemp = system(cmd);
1625
            retTemp = system(cmd);
1626
#else
1626
#else
1627
            printf("Cmd: %s\n",cmd);
1627
            printf("Cmd: %s\n",cmd);
1628
#endif
1628
#endif
1629
            fflush(stdout);
1629
            fflush(stdout);
1630
     
1630
     
1631
            printf("Next Z position...\n");
1631
            printf("Next Z position...\n");
1632
            sleep(2*doublewait);
1632
            sleep(2*doublewait);
1633
            zPos->widgetNE[0]->SetNumber(minZpos + stepZpos*k);
1633
            zPos->widgetNE[0]->SetNumber(minZpos + stepZpos*k);
1634
            fflush(stdout);
1634
            fflush(stdout);
1635
 
1635
 
1636
            // Scan over Y axis
1636
            // Scan over Y axis
1637
            while(1)
1637
            while(1)
1638
            {
1638
            {
1639
               if( (repetY > 0) && (j == repetY) ) break;
1639
               if( (repetY > 0) && (j == repetY) ) break;
1640
               else if( (repetY < 0) && (j == -repetY) ) break;
1640
               else if( (repetY < 0) && (j == -repetY) ) break;
1641
               else if( repetY == 0 ) break;
1641
               else if( repetY == 0 ) break;
1642
 
1642
 
1643
               fflush(stdout);
1643
               fflush(stdout);
1644
               // Y-axis change
1644
               // Y-axis change
1645
               if( posUnits->widgetCB->GetSelected() == 0)
1645
               if( posUnits->widgetCB->GetSelected() == 0)
1646
                  sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)(minYpos + stepYpos*j), rootdir);
1646
                  sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)(minYpos + stepYpos*j), rootdir);
1647
               else if( posUnits->widgetCB->GetSelected() == 1)
1647
               else if( posUnits->widgetCB->GetSelected() == 1)
1648
                  sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)((minYpos + stepYpos*j)/lenconversion), rootdir);
1648
                  sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)((minYpos + stepYpos*j)/lenconversion), rootdir);
1649
#if WORKSTAT == 'I'
1649
#if WORKSTAT == 'I'
1650
               retTemp = system(cmd);
1650
               retTemp = system(cmd);
1651
#else
1651
#else
1652
               printf("Cmd: %s\n",cmd);
1652
               printf("Cmd: %s\n",cmd);
1653
#endif
1653
#endif
1654
               fflush(stdout);
1654
               fflush(stdout);
1655
     
1655
     
1656
               printf("Next Y position...\n");
1656
               printf("Next Y position...\n");
1657
               sleep(2*doublewait);
1657
               sleep(2*doublewait);
1658
               yPos->widgetNE[0]->SetNumber(minYpos + stepYpos*j);
1658
               yPos->widgetNE[0]->SetNumber(minYpos + stepYpos*j);
1659
               fflush(stdout);
1659
               fflush(stdout);
1660
 
1660
 
1661
               // Scan over X axis
1661
               // Scan over X axis
1662
               while(1)
1662
               while(1)
1663
               {
1663
               {
1664
                  if( (repetX > 0) && (i == repetX) ) break;
1664
                  if( (repetX > 0) && (i == repetX) ) break;
1665
                  else if( (repetX < 0) && (i == -repetX) ) break;
1665
                  else if( (repetX < 0) && (i == -repetX) ) break;
1666
                  else if( repetX == 0 ) break;
1666
                  else if( repetX == 0 ) break;
1667
 
1667
 
1668
                  progVal = (float)(100.00/(abs(repetX)*abs(repetY)*abs(repetZ)))*(k*abs(repetX)*abs(repetY) + j*abs(repetX) + i);
1668
                  progVal = (float)(100.00/(abs(repetX)*abs(repetY)*abs(repetZ)))*(k*abs(repetX)*abs(repetY) + j*abs(repetX) + i);
1669
                  measProgress->widgetPB->SetPosition(progVal);
1669
                  measProgress->widgetPB->SetPosition(progVal);
1670
 
1670
 
1671
                  TimeEstimate(clkt0, timet0, progVal, cmd, doublewait*((abs(repetX)+2)*abs(repetY)+2)*abs(repetZ));
1671
                  TimeEstimate(clkt0, timet0, progVal, cmd, doublewait*((abs(repetX)+2)*abs(repetY)+2)*abs(repetZ));
1672
                  measProgress->widgetTE->SetText(cmd);
1672
                  measProgress->widgetTE->SetText(cmd);
1673
 
1673
 
1674
                  gVirtualX->Update(1);
1674
                  gVirtualX->Update(1);
1675
 
1675
 
1676
                  // X-axis change
1676
                  // X-axis change
1677
                  if( posUnits->widgetCB->GetSelected() == 0)
1677
                  if( posUnits->widgetCB->GetSelected() == 0)
1678
                     sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)(minXpos + stepXpos*i), rootdir);
1678
                     sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)(minXpos + stepXpos*i), rootdir);
1679
                  else if( posUnits->widgetCB->GetSelected() == 1)
1679
                  else if( posUnits->widgetCB->GetSelected() == 1)
1680
                     sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)((minXpos + stepXpos*i)/lenconversion), rootdir);
1680
                     sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)((minXpos + stepXpos*i)/lenconversion), rootdir);
1681
#if WORKSTAT == 'I'
1681
#if WORKSTAT == 'I'
1682
                  retTemp = system(cmd);
1682
                  retTemp = system(cmd);
1683
#else
1683
#else
1684
                  printf("Cmd: %s\n",cmd);
1684
                  printf("Cmd: %s\n",cmd);
1685
#endif
1685
#endif
1686
                  fflush(stdout);
1686
                  fflush(stdout);
1687
       
1687
       
1688
                  printf("Next X position...\n");
1688
                  printf("Next X position...\n");
1689
                  fflush(stdout);
1689
                  fflush(stdout);
1690
     
1690
     
1691
                  printf("Waiting for position change...\n");
1691
                  printf("Waiting for position change...\n");
1692
                  sleep(doublewait);
1692
                  sleep(doublewait);
1693
                  xPos->widgetNE[0]->SetNumber(minXpos + stepXpos*i);
1693
                  xPos->widgetNE[0]->SetNumber(minXpos + stepXpos*i);
1694
                  printf("Continuing...\n");
1694
                  printf("Continuing...\n");
1695
     
1695
     
1696
               // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<<
1696
               // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<<
1697
                  RunMeas((void*)0, (j*repetX + i), scanon);
1697
                  RunMeas((void*)0, (j*repetX + i), scanon);
1698
     
1698
     
1699
                  fflush(stdout);
1699
                  fflush(stdout);
1700
 
1700
 
1701
                  i++;
1701
                  i++;
1702
               }
1702
               }
1703
 
1703
 
1704
               i = 0;
1704
               i = 0;
1705
               printf("\n");
1705
               printf("\n");
1706
 
1706
 
1707
               j++;
1707
               j++;
1708
            }
1708
            }
1709
 
1709
 
1710
            j = 0;
1710
            j = 0;
1711
 
1711
 
1712
            k++;
1712
            k++;
1713
         }
1713
         }
1714
printf("Time = %d\n", (int)time(NULL));
1714
printf("Time = %d\n", (int)time(NULL));
1715
 
1715
 
1716
         fflush(stdout);
1716
         fflush(stdout);
1717
         printf("Measurement finished, returning to starting position...\n");
1717
         printf("Measurement finished, returning to starting position...\n");
1718
         // X-axis return
1718
         // X-axis return
1719
         if( posUnits->widgetCB->GetSelected() == 0)
1719
         if( posUnits->widgetCB->GetSelected() == 0)
1720
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)minXpos, rootdir);
1720
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)minXpos, rootdir);
1721
         else if( posUnits->widgetCB->GetSelected() == 1)
1721
         else if( posUnits->widgetCB->GetSelected() == 1)
1722
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)(minXpos/lenconversion), rootdir);
1722
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 1 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 1 -c m", rootdir, (int)(minXpos/lenconversion), rootdir);
1723
#if WORKSTAT == 'I'
1723
#if WORKSTAT == 'I'
1724
         retTemp = system(cmd);
1724
         retTemp = system(cmd);
1725
#else
1725
#else
1726
         printf("Cmd: %s\n",cmd);
1726
         printf("Cmd: %s\n",cmd);
1727
#endif
1727
#endif
1728
         fflush(stdout);
1728
         fflush(stdout);
1729
 
1729
 
1730
         // Y-axis return
1730
         // Y-axis return
1731
         if( posUnits->widgetCB->GetSelected() == 0)
1731
         if( posUnits->widgetCB->GetSelected() == 0)
1732
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)minYpos, rootdir);
1732
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)minYpos, rootdir);
1733
         else if( posUnits->widgetCB->GetSelected() == 1)
1733
         else if( posUnits->widgetCB->GetSelected() == 1)
1734
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)(minYpos/lenconversion), rootdir);
1734
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 2 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 2 -c m", rootdir, (int)(minYpos/lenconversion), rootdir);
1735
#if WORKSTAT == 'I'
1735
#if WORKSTAT == 'I'
1736
         retTemp = system(cmd);
1736
         retTemp = system(cmd);
1737
#else
1737
#else
1738
         printf("Cmd: %s\n",cmd);
1738
         printf("Cmd: %s\n",cmd);
1739
#endif
1739
#endif
1740
 
1740
 
1741
         // Z-axis return
1741
         // Z-axis return
1742
         if( posUnits->widgetCB->GetSelected() == 0)
1742
         if( posUnits->widgetCB->GetSelected() == 0)
1743
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)minZpos, rootdir);
1743
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)minZpos, rootdir);
1744
         else if( posUnits->widgetCB->GetSelected() == 1)
1744
         else if( posUnits->widgetCB->GetSelected() == 1)
1745
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)(minZpos/lenconversion), rootdir);
1745
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 3 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 3 -c m", rootdir, (int)(minZpos/lenconversion), rootdir);
1746
#if WORKSTAT == 'I'
1746
#if WORKSTAT == 'I'
1747
         retTemp = system(cmd);
1747
         retTemp = system(cmd);
1748
#else
1748
#else
1749
         printf("Cmd: %s\n",cmd);
1749
         printf("Cmd: %s\n",cmd);
1750
#endif
1750
#endif
1751
         xPos->widgetNE[0]->SetNumber(minXpos);
1751
         xPos->widgetNE[0]->SetNumber(minXpos);
1752
         yPos->widgetNE[0]->SetNumber(minYpos);
1752
         yPos->widgetNE[0]->SetNumber(minYpos);
1753
         zPos->widgetNE[0]->SetNumber(minZpos);
1753
         zPos->widgetNE[0]->SetNumber(minZpos);
1754
 
1754
 
1755
         progVal = 100.00;
1755
         progVal = 100.00;
1756
         measProgress->widgetPB->SetPosition(progVal);
1756
         measProgress->widgetPB->SetPosition(progVal);
1757
         printf("\n");
1757
         printf("\n");
1758
 
1758
 
1759
         // Write information to the finish_sig.txt value
1759
         // Write information to the finish_sig.txt value
1760
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1760
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1761
         pfin = fopen(cmd,"w");
1761
         pfin = fopen(cmd,"w");
1762
         fprintf(pfin, "%s: Surface scan finished.", timeStamp->widgetTE->GetText());
1762
         fprintf(pfin, "%s: Surface scan finished.", timeStamp->widgetTE->GetText());
1763
         fclose(pfin);
1763
         fclose(pfin);
1764
 
1764
 
1765
         measProgress->widgetTB[0]->SetText("Start acquisition");
1765
         measProgress->widgetTB[0]->SetText("Start acquisition");
1766
         acqStarted = false;
1766
         acqStarted = false;
1767
      }
1767
      }
1768
   }
1768
   }
1769
   // Only angle scan
1769
   // Only angle scan
1770
   if( (ascan == 1) && (pscan == 0) && (vscan == 0) )
1770
   if( (ascan == 1) && (pscan == 0) && (vscan == 0) )
1771
   {
1771
   {
1772
      // If already started, stop the acquisition
1772
      // If already started, stop the acquisition
1773
      if(acqStarted)
1773
      if(acqStarted)
1774
      {
1774
      {
1775
         printf("Stopping current angle scan...\n");
1775
         printf("Stopping current angle scan...\n");
1776
         gROOT->SetInterrupt();
1776
         gROOT->SetInterrupt();
1777
         measProgress->widgetTB[0]->SetText("Start acquisition");
1777
         measProgress->widgetTB[0]->SetText("Start acquisition");
1778
         acqStarted = false;
1778
         acqStarted = false;
1779
 
1779
 
1780
         // Write information to the finish_sig.txt value
1780
         // Write information to the finish_sig.txt value
1781
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1781
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1782
         pfin = fopen(cmd,"w");
1782
         pfin = fopen(cmd,"w");
1783
         fprintf(pfin, "%s: Angle scan stopped.", timeStamp->widgetTE->GetText());
1783
         fprintf(pfin, "%s: Angle scan stopped.", timeStamp->widgetTE->GetText());
1784
         fclose(pfin);
1784
         fclose(pfin);
1785
      }
1785
      }
1786
      // If stopped, start the acquisition
1786
      // If stopped, start the acquisition
1787
      else if(!acqStarted)
1787
      else if(!acqStarted)
1788
      {
1788
      {
1789
         printf("Running an incidence angle scan...\n");
1789
         printf("Running an incidence angle scan...\n");
1790
 
1790
 
1791
         // Check the steps
1791
         // Check the steps
1792
         minAlpha = rotPosMin->widgetNE[0]->GetNumber();
1792
         minAlpha = rotPosMin->widgetNE[0]->GetNumber();
1793
         maxAlpha = rotPosMax->widgetNE[0]->GetNumber();
1793
         maxAlpha = rotPosMax->widgetNE[0]->GetNumber();
1794
         stepAlpha = rotPosStep->widgetNE[0]->GetNumber();
1794
         stepAlpha = rotPosStep->widgetNE[0]->GetNumber();
1795
 
1795
 
1796
         if(stepAlpha == 0.)
1796
         if(stepAlpha == 0.)
1797
            repetAlpha = 1;
1797
            repetAlpha = 1;
1798
         else
1798
         else
1799
         {
1799
         {
1800
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1800
            // Example: min = 40, max = 70, step = 5 (in increasing steps)
1801
            if( (maxAlpha > minAlpha) && (stepAlpha > 0) )
1801
            if( (maxAlpha > minAlpha) && (stepAlpha > 0) )
1802
               repetAlpha = ((maxAlpha - minAlpha)/stepAlpha)+1;
1802
               repetAlpha = ((maxAlpha - minAlpha)/stepAlpha)+1;
1803
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1803
            // Example: min = 70, max = 40, step = -5 (in decreasing steps)
1804
            else if( (maxAlpha < minAlpha) && (stepAlpha < 0) )
1804
            else if( (maxAlpha < minAlpha) && (stepAlpha < 0) )
1805
               repetAlpha = ((minAlpha - maxAlpha)/stepAlpha)-1;
1805
               repetAlpha = ((minAlpha - maxAlpha)/stepAlpha)-1;
1806
            // Example: min = 70, max = 70 (no scan)
1806
            // Example: min = 70, max = 70 (no scan)
1807
            else if( maxAlpha == minAlpha )
1807
            else if( maxAlpha == minAlpha )
1808
               repetAlpha = 1;
1808
               repetAlpha = 1;
1809
            // If step is not correctly set, stop the acqusition
1809
            // If step is not correctly set, stop the acqusition
1810
            else
1810
            else
1811
            {
1811
            {
1812
               // TODO
1812
               // TODO
1813
               printf("Stopping current incidence angle scan...\n");
1813
               printf("Stopping current incidence angle scan...\n");
1814
               gROOT->SetInterrupt();
1814
               gROOT->SetInterrupt();
1815
               measProgress->widgetTB[0]->SetText("Start acquisition");
1815
               measProgress->widgetTB[0]->SetText("Start acquisition");
1816
               acqStarted = false;
1816
               acqStarted = false;
1817
               repetAlpha = 0;
1817
               repetAlpha = 0;
1818
            }
1818
            }
1819
         }
1819
         }
1820
 
1820
 
1821
         if(DBGSIG) printf("StartAcq(): Angle repetition (%lf,%lf,%lf) = %d\n", minAlpha, maxAlpha, stepAlpha, repetAlpha);
1821
         if(DBGSIG) printf("StartAcq(): Angle repetition (%lf,%lf,%lf) = %d\n", minAlpha, maxAlpha, stepAlpha, repetAlpha);
1822
 
1822
 
1823
         int angleWait = TMath::Ceil(abs(rotPos->widgetNE[0]->GetNumber()-minAlpha)*15/(rotPos->widgetNE[0]->GetNumMax()));
1823
         int angleWait = TMath::Ceil(abs(rotPos->widgetNE[0]->GetNumber()-minAlpha)*15/(rotPos->widgetNE[0]->GetNumMax()));
1824
         if(rotUnits->widgetCB->GetSelected() == 1)
1824
         if(rotUnits->widgetCB->GetSelected() == 1)
1825
         {
1825
         {
1826
            minAlpha = minAlpha/rotconversion;
1826
            minAlpha = minAlpha/rotconversion;
1827
            maxAlpha = maxAlpha/rotconversion;
1827
            maxAlpha = maxAlpha/rotconversion;
1828
            stepAlpha = stepAlpha/rotconversion;
1828
            stepAlpha = stepAlpha/rotconversion;
1829
         }
1829
         }
1830
 
1830
 
1831
         i = 0;
1831
         i = 0;
1832
 
1832
 
1833
         // TODO - Setting button text and acqStarted do not work!
1833
         // TODO - Setting button text and acqStarted do not work!
1834
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1834
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1835
         acqStarted = true;
1835
         acqStarted = true;
1836
         progVal = 0.00;
1836
         progVal = 0.00;
1837
         measProgress->widgetPB->SetPosition(progVal);
1837
         measProgress->widgetPB->SetPosition(progVal);
1838
         gVirtualX->Update(1);
1838
         gVirtualX->Update(1);
1839
 
1839
 
1840
         clkt0 = clock();
1840
         clkt0 = clock();
1841
         timet0 = time(NULL);
1841
         timet0 = time(NULL);
1842
 
1842
 
1843
         // Setting angle to initial position
1843
         // Setting angle to initial position
1844
         sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)minAlpha, rootdir);
1844
         sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)minAlpha, rootdir);
1845
         if(rotUnits->widgetCB->GetSelected() == 0)
1845
         if(rotUnits->widgetCB->GetSelected() == 0)
1846
            rotPos->widgetNE[0]->SetNumber(minAlpha);
1846
            rotPos->widgetNE[0]->SetNumber(minAlpha);
1847
         else if(rotUnits->widgetCB->GetSelected() == 1)
1847
         else if(rotUnits->widgetCB->GetSelected() == 1)
1848
            rotPos->widgetNE[0]->SetNumber(minAlpha*rotconversion);
1848
            rotPos->widgetNE[0]->SetNumber(minAlpha*rotconversion);
1849
#if WORKSTAT == 'I'
1849
#if WORKSTAT == 'I'
1850
            retTemp = system(cmd);
1850
            retTemp = system(cmd);
1851
#else
1851
#else
1852
            printf("Cmd: %s\n",cmd);
1852
            printf("Cmd: %s\n",cmd);
1853
#endif
1853
#endif
1854
            fflush(stdout);
1854
            fflush(stdout);
1855
       
1855
       
1856
            printf("Waiting for %ds for rotation platform to move into starting position...\n", angleWait);
1856
            printf("Waiting for %ds for rotation platform to move into starting position...\n", angleWait);
1857
            sleep(angleWait);
1857
            sleep(angleWait);
1858
 
1858
 
1859
         while(1)
1859
         while(1)
1860
         {
1860
         {
1861
            if( (repetAlpha > 0) && (i == repetAlpha) ) break;
1861
            if( (repetAlpha > 0) && (i == repetAlpha) ) break;
1862
            else if( (repetAlpha < 0) && (i == -repetAlpha) ) break;
1862
            else if( (repetAlpha < 0) && (i == -repetAlpha) ) break;
1863
            else if( repetAlpha == 0 ) break;
1863
            else if( repetAlpha == 0 ) break;
1864
 
1864
 
1865
            progVal = (float)(100.00/abs(repetAlpha))*i;
1865
            progVal = (float)(100.00/abs(repetAlpha))*i;
1866
            measProgress->widgetPB->SetPosition(progVal);
1866
            measProgress->widgetPB->SetPosition(progVal);
1867
 
1867
 
1868
            TimeEstimate(clkt0, timet0, progVal, cmd, singlewait*abs(repetAlpha));
1868
            TimeEstimate(clkt0, timet0, progVal, cmd, singlewait*abs(repetAlpha));
1869
            measProgress->widgetTE->SetText(cmd);
1869
            measProgress->widgetTE->SetText(cmd);
1870
 
1870
 
1871
            gVirtualX->Update(1);
1871
            gVirtualX->Update(1);
1872
       
1872
       
1873
            fflush(stdout);
1873
            fflush(stdout);
1874
            currentAlpha = minAlpha + stepAlpha*i;
1874
            currentAlpha = minAlpha + stepAlpha*i;
1875
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)currentAlpha, rootdir);
1875
            sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)currentAlpha, rootdir);
1876
#if WORKSTAT == 'I'
1876
#if WORKSTAT == 'I'
1877
            retTemp = system(cmd);
1877
            retTemp = system(cmd);
1878
#else
1878
#else
1879
            printf("Cmd: %s\n",cmd);
1879
            printf("Cmd: %s\n",cmd);
1880
#endif
1880
#endif
1881
            fflush(stdout);
1881
            fflush(stdout);
1882
       
1882
       
1883
            printf("Waiting for angle change...\n");
1883
            printf("Waiting for angle change...\n");
1884
            sleep(singlewait);
1884
            sleep(singlewait);
1885
            if(rotUnits->widgetCB->GetSelected() == 0)
1885
            if(rotUnits->widgetCB->GetSelected() == 0)
1886
               rotPos->widgetNE[0]->SetNumber(currentAlpha);
1886
               rotPos->widgetNE[0]->SetNumber(currentAlpha);
1887
            else if(rotUnits->widgetCB->GetSelected() == 1)
1887
            else if(rotUnits->widgetCB->GetSelected() == 1)
1888
               rotPos->widgetNE[0]->SetNumber(currentAlpha*rotconversion);
1888
               rotPos->widgetNE[0]->SetNumber(currentAlpha*rotconversion);
1889
            gVirtualX->Update(1);
1889
            gVirtualX->Update(1);
1890
            printf("Continuing...\n");
1890
            printf("Continuing...\n");
1891
       
1891
       
1892
            // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<<
1892
            // Here comes function to start histogramming <<<<<<<<<<<<<<<<<<<<<<<<
1893
            RunMeas((void*)0, i, scanon); // TODO
1893
            RunMeas((void*)0, i, scanon); // TODO
1894
            fflush(stdout);
1894
            fflush(stdout);
1895
 
1895
 
1896
            i++;
1896
            i++;
1897
         }
1897
         }
1898
       
1898
       
1899
         // Set angle back to original position
1899
         // Set angle back to original position
1900
         fflush(stdout);
1900
         fflush(stdout);
1901
         printf("Measurement finished, returning to starting incidence angle...\n");
1901
         printf("Measurement finished, returning to starting incidence angle...\n");
1902
         sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)minAlpha, rootdir);
1902
         sprintf(cmd, "sudo %s/src/MIKRO/mikro_ctrl -n 4 -v %d -s la && %s/src/MIKRO/mikro_ctrl -n 4 -c m", rootdir, (int)minAlpha, rootdir);
1903
         if(rotUnits->widgetCB->GetSelected() == 0)
1903
         if(rotUnits->widgetCB->GetSelected() == 0)
1904
            rotPos->widgetNE[0]->SetNumber(minAlpha);
1904
            rotPos->widgetNE[0]->SetNumber(minAlpha);
1905
         else if(rotUnits->widgetCB->GetSelected() == 1)
1905
         else if(rotUnits->widgetCB->GetSelected() == 1)
1906
            rotPos->widgetNE[0]->SetNumber(minAlpha*rotconversion);
1906
            rotPos->widgetNE[0]->SetNumber(minAlpha*rotconversion);
1907
#if WORKSTAT == 'I'
1907
#if WORKSTAT == 'I'
1908
         retTemp = system(cmd);
1908
         retTemp = system(cmd);
1909
#else
1909
#else
1910
         printf("Cmd: %s\n",cmd);
1910
         printf("Cmd: %s\n",cmd);
1911
#endif
1911
#endif
1912
         fflush(stdout);
1912
         fflush(stdout);
1913
       
1913
       
1914
         progVal = 100.00;
1914
         progVal = 100.00;
1915
         measProgress->widgetPB->SetPosition(progVal);
1915
         measProgress->widgetPB->SetPosition(progVal);
1916
         printf("\n");
1916
         printf("\n");
1917
 
1917
 
1918
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1918
         sprintf(cmd, "%s/dbg/finish_sig.txt", rootdir);
1919
         pfin = fopen(cmd,"w");
1919
         pfin = fopen(cmd,"w");
1920
         fprintf(pfin, "%s: Incidence angle scan finished.", timeStamp->widgetTE->GetText());
1920
         fprintf(pfin, "%s: Incidence angle scan finished.", timeStamp->widgetTE->GetText());
1921
         fclose(pfin);
1921
         fclose(pfin);
1922
 
1922
 
1923
         measProgress->widgetTB[0]->SetText("Start acquisition");
1923
         measProgress->widgetTB[0]->SetText("Start acquisition");
1924
         acqStarted = false;
1924
         acqStarted = false;
1925
      }
1925
      }
1926
   }
1926
   }
1927
   // Normal single measurement
1927
   // Normal single measurement
1928
   else if( (vscan == 0) && (pscan == 0) && (ascan == 0) )
1928
   else if( (vscan == 0) && (pscan == 0) && (ascan == 0) )
1929
   {
1929
   {
1930
      // Set the start button to stop and enable stopping of measurement
1930
      // Set the start button to stop and enable stopping of measurement
1931
      if(acqStarted)
1931
      if(acqStarted)
1932
      {
1932
      {
1933
         printf("Stopping current single scan...\n");
1933
         printf("Stopping current single scan...\n");
1934
         gROOT->SetInterrupt();
1934
         gROOT->SetInterrupt();
1935
         measProgress->widgetTB[0]->SetText("Start acquisition");
1935
         measProgress->widgetTB[0]->SetText("Start acquisition");
1936
         acqStarted = false;
1936
         acqStarted = false;
1937
      }
1937
      }
1938
      else if(!acqStarted)
1938
      else if(!acqStarted)
1939
      {
1939
      {
1940
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1940
         measProgress->widgetTB[0]->SetText("Stop acquisition");
1941
         acqStarted = true;
1941
         acqStarted = true;
1942
 
1942
 
1943
         printf("Running a single scan...\n");
1943
         printf("Running a single scan...\n");
1944
         clkt0 = clock();
1944
         clkt0 = clock();
1945
         timet0 = time(NULL);
1945
         timet0 = time(NULL);
1946
         RunMeas((void*)0, 0, scanon);
1946
         RunMeas((void*)0, 0, scanon);
1947
         printf("Measurement finished...\n");
1947
         printf("Measurement finished...\n");
1948
         printf("\n");
1948
         printf("\n");
1949
 
1949
 
1950
         measProgress->widgetTB[0]->SetText("Start acquisition");
1950
         measProgress->widgetTB[0]->SetText("Start acquisition");
1951
         acqStarted = false;
1951
         acqStarted = false;
1952
      }
1952
      }
1953
   }
1953
   }
1954
}
1954
}
1955
 
1955
 
1956
// Main measurement window connections ----------------------
1956
// Main measurement window connections ----------------------
1957
 
1957
 
1958
// Histogram file selection pane connections ----------------
1958
// Histogram file selection pane connections ----------------
1959
 
1959
 
1960
// File browser for opening histograms
1960
// File browser for opening histograms
1961
void TGAppMainFrame::SelectDirectory()
1961
void TGAppMainFrame::SelectDirectory()
1962
{
1962
{
1963
   int i = fileList->GetNumberOfEntries();
1963
   int i = fileList->GetNumberOfEntries();
1964
   char *cTemp;
1964
//   char *cTemp;
1965
 
1965
 
1966
   TGFileInfo file_info;
1966
   TGFileInfo file_info;
1967
   const char *filetypes[] = {"Histograms",histextall,0,0};
1967
   const char *filetypes[] = {"Histograms",histextall,0,0};
1968
   file_info.fFileTypes = filetypes;
1968
   file_info.fFileTypes = filetypes;
1969
   cTemp = new char[1024];
1969
//   cTemp = new char[1024];
1970
   sprintf(cTemp, "%s/results", rootdir);
1970
//   sprintf(cTemp, "%s/results", rootdir);
1971
   file_info.fIniDir = StrDup(cTemp);
1971
//   file_info.fIniDir = StrDup(cTemp);
-
 
1972
   file_info.fIniDir = StrDup(currentOpenDir);
1972
   file_info.fMultipleSelection = kTRUE;
1973
   file_info.fMultipleSelection = kTRUE;
1973
   new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info);
1974
   new TGFileDialog(gClient->GetDefaultRoot(), fMain, kFDOpen, &file_info);
1974
   delete[] cTemp;
1975
//   delete[] cTemp;
1975
 
1976
 
1976
   TList *files = file_info.fFileNamesList;
1977
   TList *files = file_info.fFileNamesList;
1977
   if(files)
1978
   if(files)
1978
   {
1979
   {
1979
      TSystemFile *file;
1980
      TSystemFile *file;
1980
      TString fname;
1981
      TString fname;
1981
      TIter next(files);
1982
      TIter next(files);
1982
      while(file=(TSystemFile*)next())
1983
      while(file=(TSystemFile*)next())
1983
      {
1984
      {
1984
         fname = file->GetName();
1985
         fname = file->GetName();
-
 
1986
         remove_from_last((char*)fname.Data(), '/', currentOpenDir);
1985
         fileList->AddEntry(fname.Data(), i);
1987
         fileList->AddEntry(fname.Data(), i);
1986
         i++;
1988
         i++;
1987
      }
1989
      }
1988
   }
1990
   }
1989
   fileList->Layout();
1991
   fileList->Layout();
1990
}
1992
}
1991
 
1993
 
1992
// Toggle multiple selection in filelist or delete all entries
1994
// Toggle multiple selection in filelist or delete all entries
1993
void TGAppMainFrame::ListMultiSelect(int opt)
1995
void TGAppMainFrame::ListMultiSelect(int opt)
1994
{
1996
{
1995
   // Enable multiselect
1997
   // Enable multiselect
1996
   if(opt == 0)
1998
   if(opt == 0)
1997
   {
1999
   {
1998
      fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn()));
2000
      fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn()));
1999
 
2001
 
2000
      if(multiSelect->widgetChBox[1]->IsDown())
2002
      if(multiSelect->widgetChBox[1]->IsDown())
2001
         multiSelect->widgetChBox[1]->SetState(kButtonUp);
2003
         multiSelect->widgetChBox[1]->SetState(kButtonUp);
2002
   }
2004
   }
2003
   else if(opt == 1)
2005
   else if(opt == 1)
2004
   {
2006
   {
2005
      if(multiSelect->widgetChBox[1]->IsDown())
2007
      if(multiSelect->widgetChBox[1]->IsDown())
2006
      {
2008
      {
2007
         multiSelect->widgetChBox[0]->SetState(kButtonDown);
2009
         multiSelect->widgetChBox[0]->SetState(kButtonDown);
2008
         fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn()));
2010
         fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn()));
2009
         for(int i = 0; i < fileList->GetNumberOfEntries(); i++)
2011
         for(int i = 0; i < fileList->GetNumberOfEntries(); i++)
2010
            fileList->Select(i,kTRUE);
2012
            fileList->Select(i,kTRUE);
2011
      }
2013
      }
2012
      else if(!multiSelect->widgetChBox[1]->IsDown())
2014
      else if(!multiSelect->widgetChBox[1]->IsDown())
2013
      {
2015
      {
2014
         multiSelect->widgetChBox[0]->SetState(kButtonUp);
2016
         multiSelect->widgetChBox[0]->SetState(kButtonUp);
2015
         fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn()));
2017
         fileList->SetMultipleSelections((multiSelect->widgetChBox[0]->IsOn()));
2016
         for(int i = 0; i < fileList->GetNumberOfEntries(); i++)
2018
         for(int i = 0; i < fileList->GetNumberOfEntries(); i++)
2017
            fileList->Select(i,kFALSE);
2019
            fileList->Select(i,kFALSE);
2018
      }
2020
      }
2019
   }
2021
   }
2020
}
2022
}
2021
 
2023
 
2022
// Navigation buttons for the filelist (<<, >>) and double click
2024
// Navigation buttons for the filelist (<<, >>) and double click
2023
void TGAppMainFrame::FileListNavigation(int opt)
2025
void TGAppMainFrame::FileListNavigation(int opt)
2024
{
2026
{
2025
   unsigned int nrfiles = fileList->GetNumberOfEntries();
2027
   unsigned int nrfiles = fileList->GetNumberOfEntries();
2026
   int curSel;
2028
   int curSel;
2027
   TList *files;
2029
   TList *files;
2028
   if( nrfiles > 0 )
2030
   if( nrfiles > 0 )
2029
   {
2031
   {
2030
      if(opt < -1)
2032
      if(opt < -1)
2031
      {
2033
      {
2032
         // turn off multiple selection and select first file on list
2034
         // turn off multiple selection and select first file on list
2033
         if(multiSelect->widgetChBox[0]->IsOn())
2035
         if(multiSelect->widgetChBox[0]->IsOn())
2034
         {
2036
         {
2035
            fileList->SetMultipleSelections(kFALSE);
2037
            fileList->SetMultipleSelections(kFALSE);
2036
            multiSelect->widgetChBox[0]->SetState(kButtonUp);
2038
            multiSelect->widgetChBox[0]->SetState(kButtonUp);
2037
            multiSelect->widgetChBox[1]->SetState(kButtonUp);
2039
            multiSelect->widgetChBox[1]->SetState(kButtonUp);
2038
 
2040
 
2039
            fileList->Select(0,kTRUE);
2041
            fileList->Select(0,kTRUE);
2040
         }
2042
         }
2041
         else
2043
         else
2042
         {
2044
         {
2043
            // if nothing is selected, curSel will be -1
2045
            // if nothing is selected, curSel will be -1
2044
            curSel = fileList->GetSelected();
2046
            curSel = fileList->GetSelected();
2045
            // go to next file on list
2047
            // go to next file on list
2046
            if(opt == -3)
2048
            if(opt == -3)
2047
            {
2049
            {
2048
               if( (curSel == (int)(nrfiles-1)) || (curSel == -1) )
2050
               if( (curSel == (int)(nrfiles-1)) || (curSel == -1) )
2049
                  fileList->Select(0);
2051
                  fileList->Select(0);
2050
               else
2052
               else
2051
                  fileList->Select(curSel+1);
2053
                  fileList->Select(curSel+1);
2052
            }
2054
            }
2053
            // go to previous file on list
2055
            // go to previous file on list
2054
            else if(opt == -2)
2056
            else if(opt == -2)
2055
            {
2057
            {
2056
               if( (curSel == 0) || (curSel == -1) )
2058
               if( (curSel == 0) || (curSel == -1) )
2057
                  fileList->Select(nrfiles-1);
2059
                  fileList->Select(nrfiles-1);
2058
               else
2060
               else
2059
                  fileList->Select(curSel-1);
2061
                  fileList->Select(curSel-1);
2060
            }
2062
            }
2061
         }
2063
         }
2062
      }
2064
      }
2063
   }
2065
   }
2064
 
2066
 
2065
   UpdateHistogram(0);
2067
   UpdateHistogram(0);
2066
}
2068
}
2067
 
2069
 
2068
// Open the header edit window when pressing on editHeader button
2070
// Open the header edit window when pressing on editHeader button
2069
void TGAppMainFrame::HeaderEdit()
2071
void TGAppMainFrame::HeaderEdit()
2070
{
2072
{
2071
   bool createTab = true;
2073
   bool createTab = true;
2072
   int tabid = -1;
2074
   int tabid = -1;
2073
 
2075
 
2074
   for(int i = 0; i < fTab->GetNumberOfTabs(); i++)
2076
   for(int i = 0; i < fTab->GetNumberOfTabs(); i++)
2075
   {
2077
   {
2076
      if(strcmp("File header editor", fTab->GetTabTab(i)->GetString() ) == 0)
2078
      if(strcmp("File header editor", fTab->GetTabTab(i)->GetString() ) == 0)
2077
      {
2079
      {
2078
         createTab = false;
2080
         createTab = false;
2079
         tabid = i;
2081
         tabid = i;
2080
      }
2082
      }
2081
     
2083
     
2082
      if(DBGSIG > 1) printf("HeaderEdit(): Name of tab = %s\n", fTab->GetTabTab(i)->GetString() );
2084
      if(DBGSIG > 1) printf("HeaderEdit(): Name of tab = %s\n", fTab->GetTabTab(i)->GetString() );
2083
   }
2085
   }
2084
 
2086
 
2085
   unsigned int nrfiles = fileList->GetNumberOfEntries();
2087
   unsigned int nrfiles = fileList->GetNumberOfEntries();
2086
   if(nrfiles > 0)
2088
   if(nrfiles > 0)
2087
      HeaderEditTab(fTab, createTab, &tabid);
2089
      HeaderEditTab(fTab, createTab, &tabid);
2088
}
2090
}
2089
 
2091
 
2090
// Clear the histogram file selection list and dark run analysis selection
2092
// Clear the histogram file selection list and dark run analysis selection
2091
void TGAppMainFrame::ClearHistogramList()
2093
void TGAppMainFrame::ClearHistogramList()
2092
{
2094
{
2093
   fileList->RemoveAll();
2095
   fileList->RemoveAll();
2094
   darkRun->widgetTE->Clear();
2096
   darkRun->widgetTE->Clear();
2095
}
2097
}
2096
 
2098
 
2097
// Histogram file selection pane connections ----------------
2099
// Histogram file selection pane connections ----------------
2098
 
2100
 
2099
// Histogram controls pane connections ----------------------
2101
// Histogram controls pane connections ----------------------
2100
 
2102
 
2101
// Readjust the histogram range after changing ADC, TDC, Y range or logarithmic scale (opt: 0 = normal redraw, 1 = export, 2 = redraw when changing which channel to display) 
2103
// Readjust the histogram range after changing ADC, TDC, Y range or logarithmic scale (opt: 0 = normal redraw, 1 = export, 2 = redraw when changing which channel to display) 
2102
void TGAppMainFrame::UpdateHistogram(int opt)
2104
void TGAppMainFrame::UpdateHistogram(int opt)
2103
{
2105
{
2104
   if(DBGSIG > 1)
2106
   if(DBGSIG > 1)
2105
   {
2107
   {
2106
      printf("UpdateHistogram(): Clearing the TList\n");
2108
      printf("UpdateHistogram(): Clearing the TList\n");
2107
      gDirectory->GetList()->Delete();
2109
      gDirectory->GetList()->Delete();
2108
      gObjectTable->Print();
2110
      gObjectTable->Print();
2109
   }
2111
   }
2110
 
2112
 
2111
   // Do not do normal histogram update if we have multiple files selected
2113
   // Do not do normal histogram update if we have multiple files selected
2112
   if( (opt == 0) && (multiSelect->widgetChBox[0]->IsDown()) )
2114
   if( (opt == 0) && (multiSelect->widgetChBox[0]->IsDown()) )
2113
   {
2115
   {
2114
      printf("UpdateHistogram(): To preview changes done to a histogram, please deselect the \"Multiple files select\" option.");
2116
      printf("UpdateHistogram(): To preview changes done to a histogram, please deselect the \"Multiple files select\" option.");
2115
      return;
2117
      return;
2116
   }
2118
   }
2117
 
2119
 
2118
   // Do not update histogram if we are on the same channel
2120
   // Do not update histogram if we are on the same channel
2119
   if( ((opt == 2) && (selChannel != (int)selectCh->widgetNE[0]->GetNumber())) || (opt < 2) )
2121
   if( ((opt == 2) && (selChannel != (int)selectCh->widgetNE[0]->GetNumber())) || (opt < 2) )
2120
   {
2122
   {
2121
      unsigned int nrfiles = fileList->GetNumberOfEntries();
2123
      unsigned int nrfiles = fileList->GetNumberOfEntries();
2122
      TCanvas *gCanvas;
2124
      TCanvas *gCanvas;
2123
      char exportname[512];
2125
      char exportname[512];
2124
      char cTemp[512];
2126
      char cTemp[512];
2125
   
2127
   
2126
      if(opt == 1)
2128
      if(opt == 1)
2127
         gCanvas = analysisCanvas->GetCanvas();
2129
         gCanvas = analysisCanvas->GetCanvas();
2128
   
2130
   
2129
      if(nrfiles > 0)
2131
      if(nrfiles > 0)
2130
      {
2132
      {
2131
         TList *files;
2133
         TList *files;
2132
         files = new TList();
2134
         files = new TList();
2133
         fileList->GetSelectedEntries(files);
2135
         fileList->GetSelectedEntries(files);
2134
         
2136
         
2135
         if(files)
2137
         if(files)
2136
         {
2138
         {
2137
            for(int i = 0; i < (int)nrfiles; i++)
2139
            for(int i = 0; i < (int)nrfiles; i++)
2138
            {
2140
            {
2139
               if(files->At(i))
2141
               if(files->At(i))
2140
               {
2142
               {
2141
                  if(DBGSIG)
2143
                  if(DBGSIG)
2142
                     printf("UpdateHistogram(): Filename: %s\n", files->At(i)->GetTitle());
2144
                     printf("UpdateHistogram(): Filename: %s\n", files->At(i)->GetTitle());
2143
                  if(opt == 1)
2145
                  if(opt == 1)
2144
                     remove_ext((char*)files->At(i)->GetTitle(), cTemp);
2146
                     remove_ext((char*)files->At(i)->GetTitle(), cTemp);
2145
                  if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) )
2147
                  if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DADC) )
2146
                  {
2148
                  {
2147
                     sprintf(exportname, "%s_adc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber());
2149
                     sprintf(exportname, "%s_adc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber());
2148
                     DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, opt);
2150
                     DisplayHistogram( (char*)(files->At(i)->GetTitle()), 0, opt);
2149
                  }
2151
                  }
2150
                  else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) )
2152
                  else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_1DTDC) )
2151
                  {
2153
                  {
2152
                     sprintf(exportname, "%s_tdc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber());
2154
                     sprintf(exportname, "%s_tdc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber());
2153
                     DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1, opt);
2155
                     DisplayHistogram( (char*)(files->At(i)->GetTitle()), 1, opt);
2154
                  }
2156
                  }
2155
                  else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) )
2157
                  else if( fMenuHisttype->IsEntryChecked(M_ANALYSIS_HISTTYPE_2D) )
2156
                  {
2158
                  {
2157
                     sprintf(exportname, "%s_adctdc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber());
2159
                     sprintf(exportname, "%s_adctdc%d.pdf", cTemp, (int)selectCh->widgetNE[0]->GetNumber());
2158
                     DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2, opt);
2160
                     DisplayHistogram( (char*)(files->At(i)->GetTitle()), 2, opt);
2159
                  }
2161
                  }
2160
   
2162
   
2161
                  if(opt == 1)
2163
                  if(opt == 1)
2162
                  {
2164
                  {
2163
                     gCanvas->SaveAs(exportname);
2165
                     gCanvas->SaveAs(exportname);
2164
                     delete inroot;
2166
                     delete inroot;
2165
                  }
2167
                  }
2166
               }
2168
               }
2167
            }
2169
            }
2168
         }
2170
         }
2169
      }
2171
      }
2170
      selChannel = selectCh->widgetNE[0]->GetNumber();
2172
      selChannel = selectCh->widgetNE[0]->GetNumber();
2171
   }
2173
   }
2172
 
2174
 
2173
   if(DBGSIG > 1)
2175
   if(DBGSIG > 1)
2174
   {
2176
   {
2175
      printf("UpdateHistogram(): After drawing histograms (connections)\n");
2177
      printf("UpdateHistogram(): After drawing histograms (connections)\n");
2176
      gObjectTable->Print();
2178
      gObjectTable->Print();
2177
   }
2179
   }
2178
}
2180
}
2179
 
2181
 
2180
// Options for histogram (logarithmic scale, clean plots)
2182
// Options for histogram (logarithmic scale, clean plots)
2181
void TGAppMainFrame::HistogramOptions(int opt)
2183
void TGAppMainFrame::HistogramOptions(int opt)
2182
{
2184
{
2183
   // Logarithmic scale
2185
   // Logarithmic scale
2184
   if(opt == 0)
2186
   if(opt == 0)
2185
      UpdateHistogram(0);
2187
      UpdateHistogram(0);
2186
   // Clean plots
2188
   // Clean plots
2187
   else if(opt == 1)
2189
   else if(opt == 1)
2188
   {
2190
   {
2189
      cleanPlots = histOpt->widgetChBox[1]->IsDown();
2191
      cleanPlots = histOpt->widgetChBox[1]->IsDown();
2190
      UpdateHistogram(0);
2192
      UpdateHistogram(0);
2191
   }
2193
   }
2192
}
2194
}
2193
 
2195
 
2194
// Changing the histogram type to display
2196
// Changing the histogram type to display
2195
void TGAppMainFrame::ChangeHisttype(int type)
2197
void TGAppMainFrame::ChangeHisttype(int type)
2196
{
2198
{
2197
   TGTextButton *pressedB = new TGTextButton();
2199
   TGTextButton *pressedB = new TGTextButton();
2198
   int menuID = 0;
2200
   int menuID = 0;
2199
   unsigned int nrfiles = fileList->GetNumberOfEntries();
2201
   unsigned int nrfiles = fileList->GetNumberOfEntries();
2200
 
2202
 
2201
   // ADC histogram
2203
   // ADC histogram
2202
   if(type == 0)
2204
   if(type == 0)
2203
   {
2205
   {
2204
      pressedB = plotType->widgetTB[0];
2206
      pressedB = plotType->widgetTB[0];
2205
      menuID = M_ANALYSIS_HISTTYPE_1DADC;
2207
      menuID = M_ANALYSIS_HISTTYPE_1DADC;
2206
 
2208
 
2207
      plotType->widgetTB[1]->SetDown(kFALSE);
2209
      plotType->widgetTB[1]->SetDown(kFALSE);
2208
      plotType->widgetTB[2]->SetDown(kFALSE);
2210
      plotType->widgetTB[2]->SetDown(kFALSE);
2209
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC);
2211
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC);
2210
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D);
2212
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D);
2211
   }
2213
   }
2212
   // TDC histogram
2214
   // TDC histogram
2213
   else if(type == 1)
2215
   else if(type == 1)
2214
   {
2216
   {
2215
      pressedB = plotType->widgetTB[1];
2217
      pressedB = plotType->widgetTB[1];
2216
      menuID = M_ANALYSIS_HISTTYPE_1DTDC;
2218
      menuID = M_ANALYSIS_HISTTYPE_1DTDC;
2217
 
2219
 
2218
      plotType->widgetTB[0]->SetDown(kFALSE);
2220
      plotType->widgetTB[0]->SetDown(kFALSE);
2219
      plotType->widgetTB[2]->SetDown(kFALSE);
2221
      plotType->widgetTB[2]->SetDown(kFALSE);
2220
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC);
2222
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC);
2221
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D);
2223
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_2D);
2222
   }
2224
   }
2223
   // ADC vs. TDC histogram
2225
   // ADC vs. TDC histogram
2224
   else if(type == 2)
2226
   else if(type == 2)
2225
   {
2227
   {
2226
      pressedB = plotType->widgetTB[2];
2228
      pressedB = plotType->widgetTB[2];
2227
      menuID = M_ANALYSIS_HISTTYPE_2D;
2229
      menuID = M_ANALYSIS_HISTTYPE_2D;
2228
 
2230
 
2229
      plotType->widgetTB[0]->SetDown(kFALSE);
2231
      plotType->widgetTB[0]->SetDown(kFALSE);
2230
      plotType->widgetTB[1]->SetDown(kFALSE);
2232
      plotType->widgetTB[1]->SetDown(kFALSE);
2231
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC);
2233
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DADC);
2232
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC);
2234
      fMenuHisttype->UnCheckEntry(M_ANALYSIS_HISTTYPE_1DTDC);
2233
   }
2235
   }
2234
 
2236
 
2235
   if( fMenuHisttype->IsEntryChecked(menuID) )
2237
   if( fMenuHisttype->IsEntryChecked(menuID) )
2236
   {
2238
   {
2237
      pressedB->SetDown(kFALSE);
2239
      pressedB->SetDown(kFALSE);
2238
      fMenuHisttype->UnCheckEntry(menuID);
2240
      fMenuHisttype->UnCheckEntry(menuID);
2239
   }
2241
   }
2240
   else if( !fMenuHisttype->IsEntryChecked(menuID) )
2242
   else if( !fMenuHisttype->IsEntryChecked(menuID) )
2241
   {
2243
   {
2242
      pressedB->SetDown(kTRUE);
2244
      pressedB->SetDown(kTRUE);
2243
      fMenuHisttype->CheckEntry(menuID);
2245
      fMenuHisttype->CheckEntry(menuID);
2244
   }
2246
   }
2245
 
2247
 
2246
   UpdateHistogram(0);
2248
   UpdateHistogram(0);
2247
}
2249
}
2248
 
2250
 
2249
// Histogram controls pane connections ----------------------
2251
// Histogram controls pane connections ----------------------
2250
 
2252