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