Low-Energy Muon (LEM) Experiment  1.1.0
PTempCalibGui.cpp
Go to the documentation of this file.
1 /***************************************************************************
2 
3  PTempCalibGui.cpp
4 
5  Author: Andreas Suter
6  e-mail: andreas.suter@psi.ch
7 
8 ***************************************************************************/
9 
10 /***************************************************************************
11  * Copyright (C) 2010 by Andreas Suter *
12  * andreas.suter@psi.ch *
13  * *
14  * This program is free software; you can redistribute it and/or modify *
15  * it under the terms of the GNU General Public License as published by *
16  * the Free Software Foundation; either version 2 of the License, or *
17  * (at your option) any later version. *
18  * *
19  * This program is distributed in the hope that it will be useful, *
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
22  * GNU General Public License for more details. *
23  * *
24  * You should have received a copy of the GNU General Public License *
25  * along with this program; if not, write to the *
26  * Free Software Foundation, Inc., *
27  * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
28  ***************************************************************************/
29 
30 #include <iostream>
31 #include <fstream>
32 using namespace std;
33 
34 #include <TApplication.h>
35 #include <TGLabel.h>
36 #include <TGFileDialog.h>
37 #include <TObjArray.h>
38 #include <TObjString.h>
39 #include <TString.h>
40 #include <TColor.h>
41 #include <TAxis.h>
42 #include <TMath.h>
43 #include <TGMsgBox.h>
44 
45 #include "PTempCalibGui.h"
46 
47 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
48 
49 ClassImpQ(PRawData)
50 
51 //--------------------------------------------------------------------------
57 {
58  fDataPresent = false;
59  fNoOfEntries = 0;
60  fNoOfRawDataReadings = 0;
61  fCtrlCh = TString("undefined");
62  for (UInt_t i=0; i<TCG_NO_OF_RAW_DATA_CH; i++)
63  fRawDataCh[i] = TString("undefined");
64 
65  fStartDateTime.Set("1995-01-01 00:00:00");
66 }
67 
68 //--------------------------------------------------------------------------
74 {
75  for (UInt_t i=0; i<fDateTime.size(); i++)
76  delete fDateTime[i];
77  fDateTime.clear();
78  fTempMeasured.clear();
79  fPressure.clear();
80  fHeaterOutput.clear();
81  fSetPointTemp.clear();
82  fHeaterRange.clear();
83  fBH1Flow.clear();
84  for (UInt_t i=0; i<fRawData.size(); i++)
85  fRawData[i].clear();
86  fRawData.clear();
87 }
88 
89 //--------------------------------------------------------------------------
95 TString PRawData::GetRawDataCh(UInt_t idx)
96 {
97  TString str("");
98 
99  if (idx < TCG_NO_OF_RAW_DATA_CH)
100  str = fRawDataCh[idx];
101 
102  return str;
103 }
104 
105 //--------------------------------------------------------------------------
114 Int_t PRawData::MapChNo(UInt_t chNo)
115 {
116  Int_t idx = -1;
117 
118  TString chStr("");
119  switch (chNo) {
120  case 0:
121  chStr = "A";
122  break;
123  case 1:
124  chStr = "B";
125  break;
126  case 2:
127  if (fLakeShore == "340")
128  chStr = "C1";
129  else
130  chStr = "C";
131  break;
132  case 3:
133  if (fLakeShore == "340")
134  chStr = "C2";
135  else
136  chStr = "D1";
137  break;
138  case 4:
139  if (fLakeShore == "340")
140  chStr = "C3";
141  else
142  chStr = "D2";
143  break;
144  case 5:
145  if (fLakeShore == "340")
146  chStr = "C4";
147  else
148  chStr = "D3";
149  break;
150  case 6:
151  if (fLakeShore == "340")
152  chStr = "D1";
153  else
154  chStr = "D4";
155  break;
156  case 7:
157  if (fLakeShore == "340")
158  chStr = "D2";
159  else
160  chStr = "D5";
161  break;
162  case 8:
163  chStr = "D3";
164  break;
165  case 9:
166  chStr = "D4";
167  break;
168  default:
169  break;
170  }
171 
172  UInt_t noOfChs = TCG_NO_OF_RAW_DATA_CH;
173  if (fLakeShore == "336")
174  noOfChs -= 2;
175  for (UInt_t i=0; i<noOfChs; i++) {
176  if (fRawDataCh[i].BeginsWith(chStr)) {
177  idx = i;
178  break;
179  }
180  }
181 
182  return idx;
183 }
184 
185 //--------------------------------------------------------------------------
192 {
193  UInt_t type=0;
194 
195  if (fLakeShore == "340") {
196  if (idx < TCG_NO_OF_RAW_DATA_CH)
197  type = fRawDataSensorType[idx];
198  } else { // LS336
199  if (idx < TCG_NO_OF_RAW_DATA_CH-2)
200  type = fRawDataSensorType[idx];
201  }
202 
203  return type;
204 }
205 
206 //--------------------------------------------------------------------------
212 UInt_t PRawData::GetTime(UInt_t idx)
213 {
214  UInt_t time = 0;
215 
216  if (idx < fDateTime.size())
217  time = fDateTime[idx]->Get();
218 
219  return time;
220 }
221 
222 //--------------------------------------------------------------------------
228 Double_t PRawData::GetTempMeasured(UInt_t idx)
229 {
230  Double_t dval = 0.0;
231 
232  if (idx < fTempMeasured.size())
233  dval = fTempMeasured[idx];
234 
235  return dval;
236 }
237 
238 //--------------------------------------------------------------------------
244 Double_t PRawData::GetPressure(UInt_t idx)
245 {
246  Double_t dval = 0.0;
247 
248  if (idx < fPressure.size())
249  dval = fPressure[idx];
250 
251  return dval;
252 }
253 
254 //--------------------------------------------------------------------------
260 Double_t PRawData::GetHeaterOutput(UInt_t idx)
261 {
262  Double_t dval = 0.0;
263 
264  if (idx < fHeaterOutput.size())
265  dval = fHeaterOutput[idx];
266 
267  return dval;
268 }
269 
270 //--------------------------------------------------------------------------
276 Double_t PRawData::GetSetPointTemp(UInt_t idx)
277 {
278  Double_t dval = 0.0;
279 
280  if (idx < fSetPointTemp.size())
281  dval = fSetPointTemp[idx];
282 
283  return dval;
284 }
285 
286 //--------------------------------------------------------------------------
292 Double_t PRawData::GetHeaterRange(UInt_t idx)
293 {
294  Double_t dval = 0.0;
295 
296  if (idx < fHeaterRange.size())
297  dval = fHeaterRange[idx];
298 
299  return dval;
300 }
301 
302 //--------------------------------------------------------------------------
308 Double_t PRawData::GetBH1Flow(UInt_t idx)
309 {
310  Double_t dval = 0.0;
311 
312  if (idx < fBH1Flow.size())
313  dval = fBH1Flow[idx];
314 
315  return dval;
316 }
317 
318 //--------------------------------------------------------------------------
325 Double_t PRawData::GetRawData(UInt_t ch, UInt_t idx)
326 {
327  Double_t dval = 0.0;
328 
329  if (ch < fRawData.size())
330  if (idx < fRawData[ch].size())
331  dval = fRawData[ch][idx];
332 
333  return dval;
334 }
335 
336 //--------------------------------------------------------------------------
344 void PRawData::SetCtrlCh(const TString &str)
345 {
346  if (fLakeShore == "340") {
347  if (str.BeginsWith("A") || str.BeginsWith("B") ||
348  str.BeginsWith("C1") || str.BeginsWith("C2") || str.BeginsWith("C3") || str.BeginsWith("C4") ||
349  str.BeginsWith("D1") || str.BeginsWith("D2") || str.BeginsWith("D3") || str.BeginsWith("D4")) {
350  fCtrlCh = str;
351  } else {
352  cerr << endl << ">> **ERROR** LS340: Found Loop1 ctrl ch = '" << str.Data() << "', which is not allowed.";
353  cerr << endl << ">> Will ignore it!" << endl;
354  }
355  } else {
356  if (str.BeginsWith("A") || str.BeginsWith("B") ||
357  str.BeginsWith("C") || str.BeginsWith("D1") || str.BeginsWith("D2") || str.BeginsWith("D3") ||
358  str.BeginsWith("D4") || str.BeginsWith("D5")) {
359  fCtrlCh = str;
360  } else {
361  cerr << endl << ">> **ERROR** LS336: Found Loop1 ctrl ch = '" << str.Data() << "', which is not allowed.";
362  cerr << endl << ">> Will ignore it!" << endl;
363  }
364  }
365 }
366 
367 //--------------------------------------------------------------------------
376 void PRawData::SetRawDataCh(const TString &str, UInt_t idx)
377 {
378  if (fLakeShore == "340") {
379  if (idx < TCG_NO_OF_RAW_DATA_CH) {
380  if (str.BeginsWith("A") || str.BeginsWith("B") ||
381  str.BeginsWith("C1") || str.BeginsWith("C2") || str.BeginsWith("C3") || str.BeginsWith("C4") ||
382  str.BeginsWith("D1") || str.BeginsWith("D2") || str.BeginsWith("D3") || str.BeginsWith("D4")) {
383  fRawDataCh[idx] = str;
384  } else {
385  cerr << endl << ">> **ERROR** LS340: Found Raw Data Ch = '" << str.Data() << "', which is not allowed.";
386  cerr << endl << ">> Will ignore it!" << endl;
387  }
388  } else {
389  cerr << endl << ">> **ERROR** LS340: SetRawDataCh idx=" << idx << " out of range [0,9]";
390  cerr << endl << ">> Will ignore it!" << endl;
391  }
392  } else { // LS336
393  if (idx < TCG_NO_OF_RAW_DATA_CH-2) {
394  if (str.BeginsWith("A") || str.BeginsWith("B") ||
395  str.BeginsWith("C") || str.BeginsWith("D1") || str.BeginsWith("D2") ||
396  str.BeginsWith("D3") || str.BeginsWith("D4") || str.BeginsWith("D5")) {
397  fRawDataCh[idx] = str;
398  } else {
399  cerr << endl << ">> **ERROR** LS336: Found Raw Data Ch = '" << str.Data() << "', which is not allowed.";
400  cerr << endl << ">> Will ignore it!" << endl;
401  }
402  } else {
403  cerr << endl << ">> **ERROR** LS336: SetRawDataCh idx=" << idx << " out of range [0,7]";
404  cerr << endl << ">> Will ignore it!" << endl;
405  }
406  }
407 }
408 
409 //--------------------------------------------------------------------------
416 void PRawData::SetRawDataSensorType(UInt_t type, UInt_t idx)
417 {
418  if (idx < TCG_NO_OF_RAW_DATA_CH) {
419  fRawDataSensorType[idx] = type;
420  } else {
421  cerr << endl << ">> **ERROR** SetRawDataSensorType idx=" << idx << " out of range [0,9]";
422  cerr << endl << ">> Will ignore it!" << endl;
423  }
424 }
425 
426 //--------------------------------------------------------------------------
432 void PRawData::AddDateTime(TDatime *dt)
433 {
434  fDateTime.push_back(dt);
435 }
436 
437 //--------------------------------------------------------------------------
443 void PRawData::AddTempMeasured(Double_t temp)
444 {
445  fTempMeasured.push_back(temp);
446 }
447 
448 //--------------------------------------------------------------------------
454 void PRawData::AddPressure(Double_t pressure)
455 {
456  fPressure.push_back(pressure);
457 }
458 
459 //--------------------------------------------------------------------------
465 void PRawData::AddHeaterOutput(Double_t heaterOutput)
466 {
467  fHeaterOutput.push_back(heaterOutput);
468 }
469 
470 //--------------------------------------------------------------------------
476 void PRawData::AddSetPointTemp(Double_t setPoint)
477 {
478  fSetPointTemp.push_back(setPoint);
479 }
480 
481 //--------------------------------------------------------------------------
487 void PRawData::AddHeaterRange(Double_t heaterRange)
488 {
489  fHeaterRange.push_back(heaterRange);
490 }
491 
492 //--------------------------------------------------------------------------
498 void PRawData::AddBH1Flow(Double_t bh1Flow)
499 {
500  fBH1Flow.push_back(bh1Flow);
501 }
502 
503 //--------------------------------------------------------------------------
510 void PRawData::AddRawData(Double_t data, UInt_t ch)
511 {
512  if (ch >= fRawData.size())
513  fRawData.resize(ch+1);
514 
515  fRawData[ch].push_back(data);
516 }
517 
518 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
519 
520 ClassImpQ(PDrawRawData)
521 
522 //--------------------------------------------------------------------------
532 PDrawRawData::PDrawRawData(UInt_t w, UInt_t h, PRawData &rawData, EPRawCh xIdx, EPRawCh yIdx, const std::string lakeShore) : fLakeShore(lakeShore)
533 {
534  // create canvas
535  fCanvas = new TCanvas("fCanvas", "Draw Raw Data", w, h);
536 
537  // create graph
538  fGraph = new TGraph(rawData.GetSize());
539 
540  // fill graph
541  Double_t x=0.0, y=0.0;
542 
543  TString xAxisTitle("");
544  TString yAxisTitle("");
545 
546  for (UInt_t i=0; i<rawData.GetSize(); i++) {
547  if (rawData.GetStartTime() > rawData.GetTime(i))
548  continue;
549  if (xIdx == eDateTime) {
550  if (i==0)
551  xAxisTitle = "Time";
552  x = rawData.GetTime(i);
553  } else if (xIdx == eTempMeasured) {
554  if (i==0)
555  xAxisTitle = "T (K)";
556  x = rawData.GetTempMeasured(i);
557  } else if (xIdx == ePressure) {
558  if (i==0)
559  xAxisTitle = "p (bar)";
560  x = rawData.GetPressure(i);
561  } else if (xIdx == eHeaterOutput) {
562  if (i==0)
563  xAxisTitle = "Heater Output (%)";
564  x = rawData.GetHeaterOutput(i);
565  } else if (xIdx == eSetPointTemp) {
566  if (i==0)
567  xAxisTitle = "SP (K)";
568  x = rawData.GetSetPointTemp(i);
569  } else if (xIdx == eHeaterRange) {
570  if (i==0)
571  xAxisTitle = "Heater Range";
572  x = rawData.GetHeaterRange(i);
573  } else if (xIdx == eBH1Flow) {
574  if (i==0)
575  xAxisTitle = "BH1 Flow";
576  x = rawData.GetBH1Flow(i);
577  } else if (xIdx == eChA) {
578  if (i==0) {
579  xAxisTitle = "Raw Data Ch A ";
580  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(0)));
581  }
582  x = rawData.GetRawData(rawData.MapChNo(0), i);
583  } else if (xIdx == eChB) {
584  if (i==0) {
585  xAxisTitle = "Raw Data Ch B ";
586  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(1)));
587  }
588  x = rawData.GetRawData(rawData.MapChNo(0), i);
589  } else if (xIdx == eChC) {
590  if (i==0) {
591  xAxisTitle = "Raw Data Ch C ";
592  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(2)));
593  }
594  x = rawData.GetRawData(rawData.MapChNo(2), i);
595  } else if (xIdx == eChC1) {
596  if (i==0) {
597  xAxisTitle = "Raw Data Ch C1 ";
598  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(2)));
599  }
600  x = rawData.GetRawData(rawData.MapChNo(2), i);
601  } else if (xIdx == eChC2) {
602  if (i==0) {
603  xAxisTitle = "Raw Data Ch C2 ";
604  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(3)));
605  }
606  x = rawData.GetRawData(rawData.MapChNo(3), i);
607  } else if (xIdx == eChC3) {
608  if (i==0) {
609  xAxisTitle = "Raw Data Ch C3 ";
610  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(4)));
611  }
612  x = rawData.GetRawData(rawData.MapChNo(4), i);
613  } else if (xIdx == eChC4) {
614  if (i==0) {
615  xAxisTitle = "Raw Data Ch C4 ";
616  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(5)));
617  }
618  x = rawData.GetRawData(rawData.MapChNo(5), i);
619  } else if (xIdx == eChD1) {
620  if (fLakeShore == "340") {
621  if (i==0) {
622  xAxisTitle = "Raw Data Ch D1 ";
623  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(6)));
624  }
625  x = rawData.GetRawData(rawData.MapChNo(6), i);
626  } else { // LS336
627  if (i==0) {
628  xAxisTitle = "Raw Data Ch D1 ";
629  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(3)));
630  }
631  x = rawData.GetRawData(rawData.MapChNo(3), i);
632  }
633  } else if (xIdx == eChD2) {
634  if (fLakeShore == "340") {
635  if (i==0) {
636  xAxisTitle = "Raw Data Ch D2 ";
637  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(7)));
638  }
639  x = rawData.GetRawData(rawData.MapChNo(7), i);
640  } else { // LS336
641  if (i==0) {
642  xAxisTitle = "Raw Data Ch D2 ";
643  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(4)));
644  }
645  x = rawData.GetRawData(rawData.MapChNo(4), i);
646  }
647  } else if (xIdx == eChD3) {
648  if (fLakeShore == "340") {
649  if (i==0) {
650  xAxisTitle = "Raw Data Ch D3 ";
651  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(8)));
652  }
653  x = rawData.GetRawData(rawData.MapChNo(8), i);
654  } else { // LS336
655  if (i==0) {
656  xAxisTitle = "Raw Data Ch D3 ";
657  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(5)));
658  }
659  x = rawData.GetRawData(rawData.MapChNo(5), i);
660  }
661  } else if (xIdx == eChD4) {
662  if (fLakeShore == "340") {
663  if (i==0) {
664  xAxisTitle = "Raw Data Ch D4 ";
665  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(9)));
666  }
667  x = rawData.GetRawData(rawData.MapChNo(9), i);
668  } else { // LS336
669  if (i==0) {
670  xAxisTitle = "Raw Data Ch D4 ";
671  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(6)));
672  }
673  x = rawData.GetRawData(rawData.MapChNo(6), i);
674  }
675  } else if (xIdx == eChD5) { // LS336
676  if (i==0) {
677  xAxisTitle = "Raw Data Ch D5 ";
678  xAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(7)));
679  }
680  x = rawData.GetRawData(rawData.MapChNo(7), i);
681  } else {
682  x = 0.0;
683  }
684 
685  if (yIdx == eDateTime) {
686  if (i==0)
687  yAxisTitle = "Time";
688  y = rawData.GetTime(i);
689  } else if (yIdx == eTempMeasured) {
690  if (i==0)
691  yAxisTitle = "T (K)";
692  y = rawData.GetTempMeasured(i);
693  } else if (yIdx == ePressure) {
694  if (i==0)
695  yAxisTitle = "p (bar)";
696  y = rawData.GetPressure(i);
697  } else if (yIdx == eHeaterOutput) {
698  if (i==0)
699  yAxisTitle = "Heater Output (%)";
700  y = rawData.GetHeaterOutput(i);
701  } else if (yIdx == eSetPointTemp) {
702  if (i==0)
703  yAxisTitle = "SP (K)";
704  y = rawData.GetSetPointTemp(i);
705  } else if (yIdx == eHeaterRange) {
706  if (i==0)
707  yAxisTitle = "Heater Range";
708  y = rawData.GetHeaterRange(i);
709  } else if (yIdx == eBH1Flow) {
710  if (i==0)
711  yAxisTitle = "BH1 Flow";
712  y = rawData.GetBH1Flow(i);
713  } else if (yIdx == eChA) {
714  if (i==0) {
715  yAxisTitle = "Raw Data Ch A ";
716  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(0)));
717  }
718  y = rawData.GetRawData(rawData.MapChNo(0), i);
719  } else if (yIdx == eChB) {
720  if (i==0) {
721  yAxisTitle = "Raw Data Ch B ";
722  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(1)));
723  }
724  y = rawData.GetRawData(rawData.MapChNo(1), i);
725  } else if (yIdx == eChC) { // LS336
726  if (i==0) {
727  yAxisTitle = "Raw Data Ch C ";
728  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(2)));
729  }
730  y = rawData.GetRawData(rawData.MapChNo(2), i);
731  } else if (yIdx == eChC1) {
732  if (i==0) {
733  yAxisTitle = "Raw Data Ch C1 ";
734  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(2)));
735  }
736  y = rawData.GetRawData(rawData.MapChNo(2), i);
737  } else if (yIdx == eChC2) {
738  if (i==0) {
739  yAxisTitle = "Raw Data Ch C2 ";
740  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(3)));
741  }
742  y = rawData.GetRawData(rawData.MapChNo(3), i);
743  } else if (yIdx == eChC3) {
744  if (i==0) {
745  yAxisTitle = "Raw Data Ch C3 ";
746  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(4)));
747  }
748  y = rawData.GetRawData(rawData.MapChNo(4), i);
749  } else if (yIdx == eChC4) {
750  if (i==0) {
751  yAxisTitle = "Raw Data Ch C4 ";
752  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(5)));
753  }
754  y = rawData.GetRawData(rawData.MapChNo(5), i);
755  } else if (yIdx == eChD1) {
756  Int_t idx=6; // LS340
757  if (fLakeShore == "336")
758  idx=3;
759  if (i==0) {
760  yAxisTitle = "Raw Data Ch D1 ";
761  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(idx)));
762  }
763  y = rawData.GetRawData(rawData.MapChNo(idx), i);
764  } else if (yIdx == eChD2) {
765  Int_t idx=7; // LS340
766  if (fLakeShore == "336")
767  idx=4;
768  if (i==0) {
769  yAxisTitle = "Raw Data Ch D2 ";
770  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(idx)));
771  }
772  y = rawData.GetRawData(rawData.MapChNo(idx), i);
773  } else if (yIdx == eChD3) {
774  Int_t idx=8; // LS340
775  if (fLakeShore == "336")
776  idx=5;
777  if (i==0) {
778  yAxisTitle = "Raw Data Ch D3 ";
779  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(idx)));
780  }
781  y = rawData.GetRawData(rawData.MapChNo(idx), i);
782  } else if (yIdx == eChD4) {
783  Int_t idx=9; // LS340
784  if (fLakeShore == "336")
785  idx=6;
786  if (i==0) {
787  yAxisTitle = "Raw Data Ch D4 ";
788  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(idx)));
789  }
790  y = rawData.GetRawData(rawData.MapChNo(idx), i);
791  } else if (yIdx == eChD5) { // LS336
792  if (i==0) {
793  yAxisTitle = "Raw Data Ch D5 ";
794  yAxisTitle += GetUnits(rawData.GetRawDataSensorType(rawData.MapChNo(7)));
795  }
796  y = rawData.GetRawData(rawData.MapChNo(7), i);
797  } else {
798  y = 0.0;
799  }
800 
801  fGraph->SetPoint(i, x, y);
802  }
803 
804  if (xIdx == eDateTime) {
805  fGraph->GetXaxis()->SetTimeDisplay(1);
806  fGraph->GetXaxis()->SetTimeFormat("%H:%M");
807  }
808 
809  if (yIdx == eDateTime) {
810  fGraph->GetYaxis()->SetTimeDisplay(1);
811  fGraph->GetYaxis()->SetTimeFormat("%H:%M");
812  }
813 
814  fGraph->SetMarkerSize(1);
815  fGraph->SetMarkerColor(TColor::GetColor(0,0,255));
816  fGraph->SetMarkerStyle(21);
817  fGraph->SetLineColor(TColor::GetColor(0,0,255));
818 
819  // set x-axis title
820  fGraph->GetXaxis()->SetTitle(xAxisTitle);
821 
822  // set y-axis title
823  fGraph->GetYaxis()->SetTitle(yAxisTitle);
824 
825  // set title
826  TString title("Raw Calibration Data");
827  fGraph->SetTitle(title);
828 
829  fGraph->Draw("ap");
830 }
831 
832 //--------------------------------------------------------------------------
838 {
839  if (fGraph)
840  delete fGraph;
841 
842  if (fCanvas)
843  delete fCanvas;
844 }
845 
846 //--------------------------------------------------------------------------
852 {
853  fGraph->Draw();
854 }
855 
856 //--------------------------------------------------------------------------
862 TString PDrawRawData::GetUnits(UInt_t sensorType)
863 {
864  TString str("(??)");
865 
866  if ((sensorType == 1) || (sensorType == 2))
867  str = "(V)";
868  else
869  str = "(Ohm)";
870 
871  return str;
872 }
873 
874 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
875 
876 ClassImpQ(PDrawMeanRawData)
877 
878 //--------------------------------------------------------------------------
890 PDrawMeanRawData::PDrawMeanRawData(UInt_t w, UInt_t h,
891  vector<Double_t> &temp, vector<Double_t> &errTemp,
892  vector<Double_t> &data, vector<Double_t> &errData,
893  TString yLabel)
894 {
895  // create canvas
896  fCanvas = new TCanvas("fCanvas", "Draw Raw Data with Errors", w, h);
897 
898  // create graph
899  fGraph = new TGraphErrors(temp.size());
900 
901  // fill graph
902  TString xAxisTitle("T (K)");
903  TString yAxisTitle = yLabel;
904 
905  for (UInt_t i=0; i<temp.size(); i++) {
906  fGraph->SetPoint(i, temp[i], data[i]);
907  fGraph->SetPointError(i, errTemp[i], errData[i]);
908  }
909 
910  fGraph->SetMarkerSize(1);
911  fGraph->SetMarkerColor(TColor::GetColor(0,0,255));
912  fGraph->SetMarkerStyle(21);
913  fGraph->SetLineColor(TColor::GetColor(0,0,255));
914 
915  // set x-axis title
916  fGraph->GetXaxis()->SetTitle(xAxisTitle);
917 
918  // set y-axis title
919  fGraph->GetYaxis()->SetTitle(yAxisTitle);
920 
921  // set title
922  TString title("Raw Calibration Data with Errors");
923  fGraph->SetTitle(title);
924 
925  fGraph->Draw("ap");
926 }
927 
928 //--------------------------------------------------------------------------
934 {
935  if (fGraph)
936  delete fGraph;
937 
938  if (fCanvas)
939  delete fCanvas;
940 }
941 
942 //--------------------------------------------------------------------------
948 {
949  fGraph->Draw();
950 }
951 
952 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
953 
954 ClassImpQ(PCalibData)
955 
956 //--------------------------------------------------------------------------
962 {
963  Init();
964 }
965 
966 //--------------------------------------------------------------------------
972 {
973  fMeasured.clear();
974  fTemp.clear();
975 }
976 
977 //--------------------------------------------------------------------------
983 {
984  fValid = false;
985  fSensorModel = TString("");
986  fSerialNo = TString("");
987  fDataFormat = 0;
988  fSetPointLimit = 0.0;
989  fTempCoeff = 0;
990  fNoOfPoints = 0;
991 
992  fMeasured.clear();
993  fTemp.clear();
994 }
995 
996 //--------------------------------------------------------------------------
1002 Double_t PCalibData::GetMeasured(UInt_t idx)
1003 {
1004  if (idx >= fMeasured.size()) {
1005  cerr << endl << ">> **ERROR** PCalibData::GetMeasured(), idx=" << idx << ", only " << fMeasured.size() << " elements present!!";
1006  return 0;
1007  }
1008 
1009  return fMeasured[idx];
1010 }
1011 
1012 //--------------------------------------------------------------------------
1018 Double_t PCalibData::GetTemp(UInt_t idx)
1019 {
1020  if (idx >= fTemp.size()) {
1021  cerr << endl << ">> **ERROR** PCalibData::GetTemp(), idx=" << idx << ", only " << fTemp.size() << " elements present!!";
1022  return 0;
1023  }
1024 
1025  return fTemp[idx];
1026 }
1027 
1028 //--------------------------------------------------------------------------
1035 Double_t PCalibData::GetTemp(Double_t sensorVal)
1036 {
1037  // find the closest table value
1038  UInt_t idx = 0;
1039  Double_t logSensorVal=1.0;
1040  if ((fDataFormat == 4) || (fDataFormat == 5)) { // Log(Ohm)
1041  if (sensorVal > 0)
1042  logSensorVal = log10(sensorVal);
1043  }
1044 
1045  for (UInt_t i=0; i<fMeasured.size(); i++) {
1046  if ((fDataFormat == 4) || (fDataFormat == 5)) { // Log(Ohm)
1047  if (logSensorVal > fMeasured[i]) {
1048  idx = i;
1049  break;
1050  }
1051  } else {
1052  if (sensorVal > fMeasured[i]) {
1053  idx = i;
1054  break;
1055  }
1056  }
1057  }
1058 
1059  // linearly interpolate between two points
1060  Double_t temp = 0.0;
1061 
1062  if (idx > 0) {
1063  if (fDataFormat == 4) { // Log(Ohm)/K
1064  temp = fTemp[idx-1] + (fTemp[idx]-fTemp[idx-1]) * (logSensorVal-fMeasured[idx-1])/(fMeasured[idx]-fMeasured[idx-1]);
1065  } else if (fDataFormat == 5) { // Log(Ohm)/Log(K)
1066  temp = fTemp[idx-1] + (fTemp[idx]-fTemp[idx-1]) * (logSensorVal-fMeasured[idx-1])/(fMeasured[idx]-fMeasured[idx-1]);
1067  temp = pow(temp, 10.0);
1068  } else { // V/K, ...
1069  temp = fTemp[idx-1] + (fTemp[idx]-fTemp[idx-1]) * (sensorVal-fMeasured[idx-1])/(fMeasured[idx]-fMeasured[idx-1]);
1070  }
1071  }
1072 
1073  return temp;
1074 }
1075 
1076 //--------------------------------------------------------------------------
1082 void PCalibData::SetDataFormat(UInt_t ival)
1083 {
1084  if (ival > 5) {
1085  fValid = false;
1086  } else {
1087  fDataFormat = ival;
1088  }
1089 }
1090 
1091 //--------------------------------------------------------------------------
1097 void PCalibData::SetTempCoeff(UInt_t ival)
1098 {
1099  if (ival > 2) {
1100  fValid = false;
1101  } else {
1102  fTempCoeff = ival;
1103  }
1104 }
1105 
1106 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1107 
1108 ClassImpQ(PDrawRawData)
1109 
1110 //--------------------------------------------------------------------------
1118 PDrawCalibData::PDrawCalibData(UInt_t w, UInt_t h, PCalibData &calibData)
1119 {
1120  // create canvas
1121  fCanvas = new TCanvas("fCanvas", "Draw Calib Data", w, h);
1122  fCanvas->SetGridx();
1123  fCanvas->SetGridy();
1124 
1125  // create graph
1126  fGraph = new TGraph(calibData.GetMeasuredSize());
1127 
1128  // fill graph
1129  TString xAxisTitle("T (K)");
1130  TString yAxisTitle("");
1131  switch (calibData.GetDataFormat()) {
1132  case 1:
1133  yAxisTitle = TString("Sensor (mV)");
1134  break;
1135  case 2:
1136  yAxisTitle = TString("Sensor (V)");
1137  break;
1138  case 3:
1139  case 4:
1140  case 5:
1141  yAxisTitle = TString("Sensor (Ohm)");
1142  break;
1143  default:
1144  yAxisTitle = TString("Sensor (??)");
1145  break;
1146  }
1147 
1148  Double_t x, y = 0.0;
1149  for (UInt_t i=0; i<calibData.GetMeasuredSize(); i++) {
1150  if (calibData.GetDataFormat() == 4) {
1151  x = calibData.GetTemp(i);
1152  y = TMath::Power(10.0, calibData.GetMeasured(i));
1153  fCanvas->SetLogy();
1154  } else if (calibData.GetDataFormat() == 5) {
1155  x = TMath::Power(10.0, calibData.GetTemp(i));
1156  y = TMath::Power(10.0, calibData.GetMeasured(i));
1157  fCanvas->SetLogx();
1158  fCanvas->SetLogy();
1159  } else {
1160  x = calibData.GetTemp(i);
1161  y = calibData.GetMeasured(i);
1162  }
1163  fGraph->SetPoint(i, x, y);
1164  }
1165 
1166  fGraph->SetMarkerSize(1);
1167  fGraph->SetMarkerColor(TColor::GetColor(0,0,255));
1168  fGraph->SetMarkerStyle(21);
1169  fGraph->SetLineColor(TColor::GetColor(0,0,255));
1170 
1171  // set x-axis title
1172  fGraph->GetXaxis()->SetTitle(xAxisTitle);
1173 
1174  // set y-axis title
1175  fGraph->GetYaxis()->SetTitle(yAxisTitle);
1176 
1177  // set title
1178  TString title("Calibration Data - ");
1179  title += calibData.GetSensorModel();
1180  title += TString(" - ");
1181  title += calibData.GetSerialNo();
1182  fGraph->SetTitle(title);
1183 
1184  fGraph->Draw("ap");
1185 }
1186 
1187 //--------------------------------------------------------------------------
1193 {
1194  if (fGraph)
1195  delete fGraph;
1196 
1197  if (fCanvas)
1198  delete fCanvas;
1199 }
1200 
1201 //--------------------------------------------------------------------------
1207 {
1208  fGraph->Draw();
1209 }
1210 
1211 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1212 
1213 ClassImpQ(PSensorInfo)
1214 
1215 //--------------------------------------------------------------------------
1221 PSensorInfo::PSensorInfo(TGGroupFrame *frame)
1222 {
1223  TGCompositeFrame *f1 = new TGCompositeFrame(frame, TCG_WIDTH, 300, kHorizontalFrame);
1224 
1225  fChLabel = new TGLabel(f1, new TGString("Channel:"));
1226  f1->AddFrame(fChLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 0, 3, 3));
1227 
1228  fCh = new TGComboBox(f1);
1229  f1->AddFrame(fCh, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 0, 3, 3));
1230  fCh->AddEntry("A", 0);
1231  fCh->AddEntry("B", 1);
1232  fCh->AddEntry("C1", 2);
1233  fCh->AddEntry("C2", 3);
1234  fCh->AddEntry("C3", 4);
1235  fCh->AddEntry("C4", 5);
1236  fCh->AddEntry("D1", 6);
1237  fCh->AddEntry("D2", 7);
1238  fCh->AddEntry("D3", 8);
1239  fCh->AddEntry("D4", 9);
1240  fCh->Resize(160, 20);
1241 
1242  TGCompositeFrame *f2 = new TGCompositeFrame(frame, TCG_WIDTH, 300, kHorizontalFrame);
1243 
1244  fTypeLabel = new TGLabel(f2, new TGString("Sensor Type:"));
1245  f2->AddFrame(fTypeLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 0, 3, 3));
1246 
1247  fType = new TGComboBox(f2);
1248  f2->AddFrame(fType, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 0, 3, 3));
1249  fType->AddEntry("Special", 0);
1250  fType->AddEntry("Silicon Diode", 1);
1251  fType->AddEntry("GaAlAs Diode", 2);
1252  fType->AddEntry("Platinum 100 (250Ohm)", 3);
1253  fType->AddEntry("Platinum 100 (500Ohm)", 4);
1254  fType->AddEntry("Platinum 1000", 5);
1255  fType->AddEntry("Rhodium Iron", 6);
1256  fType->AddEntry("Carbon-Glass", 7);
1257  fType->AddEntry("Cernox", 8);
1258  fType->AddEntry("RuOx", 9);
1259  fType->AddEntry("Germanium", 10);
1260  fType->AddEntry("Capacitor", 11);
1261  fType->AddEntry("Thermocouple", 12);
1262  fType->Resize(160, 20);
1263 
1264  fType->Connect("Selected(Int_t)", "PSensorInfo", this, "TypeChanged(Int_t)");
1265 
1266  fType->Select(1, kFALSE); // Silicon Diode
1267 
1268  TGCompositeFrame *f3 = new TGCompositeFrame(frame, TCG_WIDTH, 300, kHorizontalFrame);
1269 
1270  fDataFormatLabel = new TGLabel(f3, new TGString("Data Format:"));
1271  f3->AddFrame(fDataFormatLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 0, 3, 3));
1272 
1273  fDataFormat = new TGComboBox(f3);
1274  f3->AddFrame(fDataFormat, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 0, 3, 3));
1275 
1276  fDataFormat->AddEntry("1: mV/K", 0);
1277  fDataFormat->AddEntry("2: V/K", 1);
1278 
1279  fDataFormat->Resize(160, 20);
1280 
1281  fDataFormat->Select(1, kFALSE); // V/K
1282 
1283  TGCompositeFrame *f4 = new TGCompositeFrame(frame, TCG_WIDTH, 300, kHorizontalFrame);
1284 
1285  fNameLabel = new TGLabel(f4, new TGString("Sensor Name:"));
1286  f4->AddFrame(fNameLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 0, 3, 3));
1287 
1288  fName = new TGTextEntry(f4);
1289  fName->Resize(160, fName->GetDefaultHeight());
1290  f4->AddFrame(fName, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 0, 3, 3));
1291 
1292  TGCompositeFrame *f5 = new TGCompositeFrame(frame, TCG_WIDTH, 300, kHorizontalFrame);
1293 
1294  fSerialNoLabel = new TGLabel(f5, new TGString("Serial No:"));
1295  f5->AddFrame(fSerialNoLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 0, 0, 3, 3));
1296 
1297  fSerialNo = new TGTextEntry(f5);
1298  fSerialNo->Resize(160, fSerialNo->GetDefaultHeight());
1299  f5->AddFrame(fSerialNo, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 0, 0, 3, 3));
1300 
1301  frame->AddFrame(f1, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1302  frame->AddFrame(f2, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1303  frame->AddFrame(f3, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1304  frame->AddFrame(f4, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1305  frame->AddFrame(f5, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1306 }
1307 
1308 //--------------------------------------------------------------------------
1314 {
1315 }
1316 
1317 //--------------------------------------------------------------------------
1323 {
1324  Int_t dataFormat = 2; // V/K
1325 
1326  switch (fType->GetSelected()) {
1327  case 0: // Special
1328  switch (fDataFormat->GetSelected()) {
1329  case 0: // mV/K
1330  dataFormat = 1;
1331  break;
1332  case 1: // V/K
1333  dataFormat = 2;
1334  break;
1335  case 2: // Ohm/K
1336  dataFormat = 3;
1337  break;
1338  case 3: // log(Ohm)/K
1339  dataFormat = 4;
1340  break;
1341  case 4: // log(Ohm)/log(K)
1342  dataFormat = 5;
1343  break;
1344  default:
1345  break;
1346  }
1347  break;
1348  case 1: // Silicon Diode
1349  case 2: // GaAlAs Diode
1350  switch (fDataFormat->GetSelected()) {
1351  case 0: // mV/K
1352  dataFormat = 1;
1353  break;
1354  case 1: // V/K
1355  dataFormat = 2;
1356  break;
1357  default:
1358  break;
1359  }
1360  break;
1361  case 3: // Platinum 100 (250Ohm)
1362  case 4: // Platinum 100 (500Ohm)
1363  case 5: // Platinum 1000
1364  case 6: // Rhodium Iron
1365  case 7: // Carbon-Glass
1366  case 8: // Cernox
1367  case 9: // RuOx
1368  case 10: // Germanium
1369  switch (fDataFormat->GetSelected()) {
1370  case 0: // Ohm/K
1371  dataFormat = 3;
1372  break;
1373  case 1: // log(Ohm)/K
1374  dataFormat = 4;
1375  break;
1376  case 2: // log(Ohm)/log(K)
1377  dataFormat = 5;
1378  break;
1379  default:
1380  break;
1381  }
1382  break;
1383  default:
1384  break;
1385  }
1386 
1387  return dataFormat;
1388 }
1389 
1390 //--------------------------------------------------------------------------
1397 {
1398  fDataFormat->RemoveAll();
1399 
1400  switch (idx) {
1401  case 0: // Special
1402  fDataFormat->AddEntry("1: mV/K", 0);
1403  fDataFormat->AddEntry("2: V/K", 1);
1404  fDataFormat->AddEntry("3: Ohm/K", 2);
1405  fDataFormat->AddEntry("4: log(Ohm)/K", 3);
1406  fDataFormat->AddEntry("5: log(Ohm)/log(K)", 4);
1407  fDataFormat->Select(1);
1408  break;
1409  case 1: // Silicon Diode
1410  case 2: // GaAlAs Diode
1411  fDataFormat->AddEntry("2: V/K", 0);
1412  fDataFormat->Select(0);
1413  break;
1414  case 3: // Platinum 100 (250Ohm)
1415  case 4: // Platinum 100 (500Ohm)
1416  case 5: // Platinum 1000
1417  case 6: // Rhodium Iron
1418  case 7: // Carbon-Glass
1419  case 8: // Cernox
1420  case 9: // RuOx
1421  case 10: // Germanium
1422  fDataFormat->AddEntry("3: Ohm/K", 0);
1423  fDataFormat->AddEntry("4: log(Ohm)/K", 1);
1424  fDataFormat->AddEntry("5: log(Ohm)/log(K)", 2);
1425  fDataFormat->Select(0);
1426  break;
1427  case 11: // Capacitor
1428  case 12: // Thermocoupler
1429  fDataFormat->AddEntry("1: mV/K", 0);
1430  fDataFormat->Select(0);
1431  break;
1432  default:
1433  break;
1434  }
1435 }
1436 
1437 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1438 
1439 ClassImpQ(PTempCalibSensors)
1440 
1441 //--------------------------------------------------------------------------
1447 PTempCalibSensors::PTempCalibSensors(const TGWindow *p, const std::string lakeShore) : fLakeShore(lakeShore)
1448 {
1449  fFrame = new TGCompositeFrame(p, 10, 10, kHorizontalFrame,
1450  TGFrame::GetWhitePixel());
1451  fCanvas = 0;
1452  fFrame->SetLayoutManager(new TGVerticalLayout(fFrame));
1453 
1454  TGGroupFrame *f;
1455  PSensorInfo *s;
1456  char name[32];
1457  UInt_t noOfChs = TCG_NO_OF_RAW_DATA_CH;
1458  if (fLakeShore == "336")
1459  noOfChs -= 2;
1460  for (UInt_t i=0; i<noOfChs; i++) {
1461  sprintf(name, "Sensor %d to be calibrated", i+1);
1462  f = new TGGroupFrame(fFrame, name, kVerticalFrame);
1463  fCalibSensorFrame.push_back(f);
1464  s = new PSensorInfo(f);
1465  f->AddFrame(s, new TGLayoutHints(kLHintsExpandX | kLHintsCenterY, 0, 0, 0, 0));
1466  fCalibSensorInfo.push_back(s);
1467  fFrame->AddFrame(fCalibSensorFrame[i], new TGLayoutHints(kLHintsExpandX | kLHintsTop, 0, 0, 0, 0));
1468  }
1469 
1470  fNoOfSensors = 0;
1471 }
1472 
1473 //--------------------------------------------------------------------------
1479 {
1480  fCalibSensorFrame.clear();
1481 }
1482 
1483 //--------------------------------------------------------------------------
1489 Int_t PTempCalibSensors::GetCh(UInt_t sensorIdx)
1490 {
1491  Int_t chNo = -1;
1492 
1493  if (sensorIdx <= fNoOfSensors)
1494  chNo = fCalibSensorInfo[sensorIdx-1]->GetCh();
1495 
1496  return chNo;
1497 }
1498 
1499 //--------------------------------------------------------------------------
1505 Int_t PTempCalibSensors::GetSensorType(UInt_t sensorIdx)
1506 {
1507  Int_t sensorType = -1;
1508 
1509  if (sensorIdx <= fNoOfSensors)
1510  sensorType = fCalibSensorInfo[sensorIdx-1]->GetSensorType();
1511 
1512  return sensorType;
1513 }
1514 
1515 //--------------------------------------------------------------------------
1521 Int_t PTempCalibSensors::GetDataFormat(UInt_t sensorIdx)
1522 {
1523  Int_t dataFormat = -1;
1524 
1525  if (sensorIdx <= fNoOfSensors)
1526  dataFormat = fCalibSensorInfo[sensorIdx-1]->GetDataFormat();
1527 
1528  return dataFormat;
1529 }
1530 
1531 //--------------------------------------------------------------------------
1537 TString PTempCalibSensors::GetSensorName(UInt_t sensorIdx)
1538 {
1539  TString sensorName("");
1540 
1541  if (sensorIdx <= fNoOfSensors)
1542  sensorName = fCalibSensorInfo[sensorIdx-1]->GetSensorName();
1543 
1544  return sensorName;
1545 }
1546 
1547 //--------------------------------------------------------------------------
1553 TString PTempCalibSensors::GetSerialNo(UInt_t sensorIdx)
1554 {
1555  TString serialNo("");
1556 
1557  if (sensorIdx <= fNoOfSensors)
1558  serialNo = fCalibSensorInfo[sensorIdx-1]->GetSerialNo();
1559 
1560  return serialNo;
1561 }
1562 
1563 //--------------------------------------------------------------------------
1568 void PTempCalibSensors::SetCanvas(TGCanvas *canvas)
1569 {
1570  fCanvas = canvas;
1571 }
1572 
1573 //--------------------------------------------------------------------------
1581 {
1582  UInt_t newSize = static_cast<UInt_t>(val);
1583 
1584  if (newSize > fCalibSensorFrame.size()) {
1585  cerr << endl << ">> **ERROR** Only " << fCalibSensorFrame.size() << " sensors possible (you requested " << newSize << "), will ignore request." << endl;
1586  return;
1587  }
1588 
1589  if (fNoOfSensors == 0) {
1590  for (UInt_t i=0; i<fCalibSensorFrame.size(); i++)
1591  fFrame->HideFrame(fCalibSensorFrame[i]);
1592  }
1593 
1594  if (newSize < fNoOfSensors) {
1595  for (UInt_t i=newSize; i<fCalibSensorFrame.size(); i++)
1596  fFrame->HideFrame(fCalibSensorFrame[i]);
1597  } else {
1598  for (UInt_t i=fNoOfSensors; i<newSize; i++)
1599  fFrame->ShowFrame(fCalibSensorFrame[i]);
1600  }
1601 
1602  fNoOfSensors = newSize;
1603 
1604  fCanvas->MapWindow();
1605 }
1606 
1607 //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1608 
1609 ClassImpQ(PTempCalibGui)
1610 
1611 //--------------------------------------------------------------------------
1619 PTempCalibGui::PTempCalibGui(const TGWindow *p, UInt_t w, UInt_t h, const std::string lakeShore)
1620 {
1621  fLakeShore = lakeShore;
1622  fRawData.SetLakeShore(lakeShore);
1623 
1624  // Create test main frame. A TGMainFrame is a top level window.
1625 
1626  fMain = new TGMainFrame(p, w, h);
1627 
1628  // use hierarchical cleaning
1629  fMain->SetCleanup(kDeepCleanup);
1630 
1631  fMain->Connect("CloseWindow()", "PTempCalibGui", this, "CloseWindow()");
1632 
1633  fFrame = new TGHorizontalFrame(fMain, TCG_WIDTH, TCG_HEIGHT, kFixedHeight | kFixedWidth);
1634 
1635  fMain->AddFrame(fFrame, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
1636 
1637  fMain->SetWindowName("Temperature Calibration");
1638 
1639  //--------- create Tab widget
1640  fTab = new TGTab(fMain, TCG_WIDTH, TCG_HEIGHT);
1641 
1642  //-----------------------------------------------------------------------------------
1643  // tab1
1644  //-----------------------------------------------------------------------------------
1645  TGCompositeFrame *tf = fTab->AddTab("Raw Data");
1646 
1647  // add tab1 frames
1648  TGCompositeFrame *f11 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1649  TGCompositeFrame *f12 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1650  TGCompositeFrame *f13 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1651  TGCompositeFrame *f14 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1652  TGCompositeFrame *f15 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1653 
1654  // fill tab1 frame1
1655  TGLabel *fileNameLabel1 = new TGLabel(f11, new TGString("File Name:"));
1656  fileNameLabel1->Resize(120, fileNameLabel1->GetDefaultHeight());
1657 
1658  fTab1FileName = new TGTextEntry(f11);
1659  fTab1FileName->Resize(210, fTab1FileName->GetDefaultHeight());
1660 
1661  fTab1BrowseButton = new TGTextButton(f11, "&Browse");
1662  fTab1BrowseButton->Connect("Clicked()", "PTempCalibGui", this, "DoBrowse()");
1663 
1664  f11->AddFrame(fileNameLabel1, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1665  f11->AddFrame(fTab1FileName, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1666  f11->AddFrame(fTab1BrowseButton, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 10, 20, 3, 3));
1667 
1668  // fill tab1 frame2
1669  TGLabel *startTimeLabel = new TGLabel(f12, new TGString("Start Time:"));
1670  startTimeLabel->Resize(120, startTimeLabel->GetDefaultHeight());
1671 
1672  fTab1StartTime = new TGTextEntry(f12);
1673  fTab1StartTime->SetText("1995-01-01 00:00:00");
1674  fTab1StartTime->Resize(210, fTab1StartTime->GetDefaultHeight());
1675 
1676  f12->AddFrame(startTimeLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1677  f12->AddFrame(fTab1StartTime, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1678 
1679  // fill tab1 frame3
1680  TGLabel *xLabel = new TGLabel(f13, new TGString("x-axis: "));
1681  xLabel->Resize(120, xLabel->GetDefaultHeight());
1682 
1683  fTab1XComboBox = new TGComboBox(f13);
1684 
1685  f13->AddFrame(xLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1686  f13->AddFrame(fTab1XComboBox, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1687 
1688  fTab1XComboBox->AddEntry("time", 0);
1689  fTab1XComboBox->AddEntry("measured temperature", 1);
1690  fTab1XComboBox->AddEntry("set point temperature", 2);
1691  fTab1XComboBox->AddEntry("pressure", 3);
1692  fTab1XComboBox->AddEntry("heater output", 4);
1693  fTab1XComboBox->AddEntry("heater range", 5);
1694  fTab1XComboBox->AddEntry("BH1 flow", 6);
1695  if (fLakeShore == "340") {
1696  fTab1XComboBox->AddEntry("raw data ch A", 7);
1697  fTab1XComboBox->AddEntry("raw data ch B", 8);
1698  fTab1XComboBox->AddEntry("raw data ch C1", 9);
1699  fTab1XComboBox->AddEntry("raw data ch C2", 10);
1700  fTab1XComboBox->AddEntry("raw data ch C3", 11);
1701  fTab1XComboBox->AddEntry("raw data ch C4", 12);
1702  fTab1XComboBox->AddEntry("raw data ch D1", 13);
1703  fTab1XComboBox->AddEntry("raw data ch D2", 14);
1704  fTab1XComboBox->AddEntry("raw data ch D3", 15);
1705  fTab1XComboBox->AddEntry("raw data ch D4", 16);
1706  } else { // LS336
1707  fTab1XComboBox->AddEntry("raw data ch A", 7);
1708  fTab1XComboBox->AddEntry("raw data ch B", 8);
1709  fTab1XComboBox->AddEntry("raw data ch C", 9);
1710  fTab1XComboBox->AddEntry("raw data ch D1", 10);
1711  fTab1XComboBox->AddEntry("raw data ch D2", 11);
1712  fTab1XComboBox->AddEntry("raw data ch D3", 12);
1713  fTab1XComboBox->AddEntry("raw data ch D4", 13);
1714  fTab1XComboBox->AddEntry("raw data ch D5", 14);
1715  }
1716  fTab1XComboBox->Resize(210, 20);
1717 
1718  // fill tab1 frame4
1719  TGLabel *yLabel = new TGLabel(f14, new TGString("y-axis: "));
1720  yLabel->Resize(120, yLabel->GetDefaultHeight());
1721 
1722  fTab1YComboBox = new TGComboBox(f14);
1723 
1724  f14->AddFrame(yLabel, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1725  f14->AddFrame(fTab1YComboBox, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1726 
1727  fTab1YComboBox->AddEntry("time", 0);
1728  fTab1YComboBox->AddEntry("measured temperature", 1);
1729  fTab1YComboBox->AddEntry("set point temperature", 2);
1730  fTab1YComboBox->AddEntry("pressure", 3);
1731  fTab1YComboBox->AddEntry("heater output", 4);
1732  fTab1YComboBox->AddEntry("heater range", 5);
1733  fTab1YComboBox->AddEntry("BH1 flow", 6);
1734  if (fLakeShore == "340") {
1735  fTab1YComboBox->AddEntry("raw data ch A", 7);
1736  fTab1YComboBox->AddEntry("raw data ch B", 8);
1737  fTab1YComboBox->AddEntry("raw data ch C1", 9);
1738  fTab1YComboBox->AddEntry("raw data ch C2", 10);
1739  fTab1YComboBox->AddEntry("raw data ch C3", 11);
1740  fTab1YComboBox->AddEntry("raw data ch C4", 12);
1741  fTab1YComboBox->AddEntry("raw data ch D1", 13);
1742  fTab1YComboBox->AddEntry("raw data ch D2", 14);
1743  fTab1YComboBox->AddEntry("raw data ch D3", 15);
1744  fTab1YComboBox->AddEntry("raw data ch D4", 16);
1745  } else { // LS336
1746  fTab1YComboBox->AddEntry("raw data ch A", 7);
1747  fTab1YComboBox->AddEntry("raw data ch B", 8);
1748  fTab1YComboBox->AddEntry("raw data ch C", 9);
1749  fTab1YComboBox->AddEntry("raw data ch D1", 10);
1750  fTab1YComboBox->AddEntry("raw data ch D2", 11);
1751  fTab1YComboBox->AddEntry("raw data ch D3", 12);
1752  fTab1YComboBox->AddEntry("raw data ch D4", 13);
1753  fTab1YComboBox->AddEntry("raw data ch D5", 14);
1754  }
1755  fTab1YComboBox->Resize(210, 20);
1756 
1757  // fill tab1 frame5
1758  fTab1DrawButton = new TGTextButton(f15, "&Draw");
1759  fTab1DrawButton->Connect("Clicked()", "PTempCalibGui", this, "DoDrawRawData()");
1760  f15->AddFrame(fTab1DrawButton, new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
1761 
1762  fTab1ExitButton = new TGTextButton(f15, "&Exit");
1763  fTab1ExitButton->Resize(200, fTab1ExitButton->GetDefaultHeight());
1764  fTab1ExitButton->Connect("Clicked()", "PTempCalibGui", this, "CloseWindow()");
1765  f15->AddFrame(fTab1ExitButton, new TGLayoutHints(kLHintsRight, 5, 5, 3, 4));
1766 
1767  // add tab1 frames to the master frame
1768  tf->AddFrame(f11, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1769  tf->AddFrame(f12, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1770  tf->AddFrame(f13, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1771  tf->AddFrame(f14, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1772  tf->AddFrame(f15, new TGLayoutHints(kLHintsBottom | kLHintsExpandX));
1773 
1774  //-----------------------------------------------------------------------------------
1775  // tab2
1776  //-----------------------------------------------------------------------------------
1777  tf = fTab->AddTab("Calibrate");
1778 
1779  // add tab2 frames
1780  TGCompositeFrame *f21 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1781  TGCompositeFrame *f22 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1782  TGCompositeFrame *f23 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1783  TGCompositeFrame *f24 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1784  TGCompositeFrame *f25 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1785  TGCompositeFrame *f26 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1786 
1787  // fill tab2 frame1
1788  TGLabel *channelCalibThermo = new TGLabel(f21, new TGString("Calib Thermo Channel:"));
1789 
1790  fTab2ChannelCalibThermoComboBox = new TGComboBox(f21);
1791 
1792  f21->AddFrame(channelCalibThermo, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1793  f21->AddFrame(fTab2ChannelCalibThermoComboBox, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 10, 20, 3, 3));
1794 
1795  if (fLakeShore == "340") {
1796  fTab2ChannelCalibThermoComboBox->AddEntry("A", 0);
1797  fTab2ChannelCalibThermoComboBox->AddEntry("B", 1);
1798  fTab2ChannelCalibThermoComboBox->AddEntry("C1", 2);
1799  fTab2ChannelCalibThermoComboBox->AddEntry("C2", 3);
1800  fTab2ChannelCalibThermoComboBox->AddEntry("C3", 4);
1801  fTab2ChannelCalibThermoComboBox->AddEntry("C4", 5);
1802  fTab2ChannelCalibThermoComboBox->AddEntry("D1", 6);
1803  fTab2ChannelCalibThermoComboBox->AddEntry("D2", 7);
1804  fTab2ChannelCalibThermoComboBox->AddEntry("D3", 8);
1805  fTab2ChannelCalibThermoComboBox->AddEntry("D4", 9);
1806  fTab2ChannelCalibThermoComboBox->Resize(210, 20);
1807  } else { // LS336
1808  fTab2ChannelCalibThermoComboBox->AddEntry("A", 0);
1809  fTab2ChannelCalibThermoComboBox->AddEntry("B", 1);
1810  fTab2ChannelCalibThermoComboBox->AddEntry("C", 2);
1811  fTab2ChannelCalibThermoComboBox->AddEntry("D1", 3);
1812  fTab2ChannelCalibThermoComboBox->AddEntry("D2", 4);
1813  fTab2ChannelCalibThermoComboBox->AddEntry("D3", 5);
1814  fTab2ChannelCalibThermoComboBox->AddEntry("D4", 6);
1815  fTab2ChannelCalibThermoComboBox->AddEntry("D5", 7);
1816  fTab2ChannelCalibThermoComboBox->Resize(210, 20);
1817  }
1818  // fill tab2 frame2
1819  TGLabel *serialNoCalibThermo = new TGLabel(f22, new TGString("Calib Thermo File:"));
1820 
1821  fTab2SerialNoCalibThermo = new TGTextEntry(f22);
1822  fTab2SerialNoCalibThermo->Resize(210, fTab2SerialNoCalibThermo->GetDefaultHeight());
1823 
1824  fTab2BrowseButton = new TGTextButton(f22, "&Browse");
1825  fTab2BrowseButton->Connect("Clicked()", "PTempCalibGui", this, "DoBrowse()");
1826 
1827  f22->AddFrame(serialNoCalibThermo, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1828  f22->AddFrame(fTab2SerialNoCalibThermo, new TGLayoutHints(kLHintsCenterX | kLHintsCenterY, 10, 20, 3, 3));
1829  f22->AddFrame(fTab2BrowseButton, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 10, 20, 3, 3));
1830 
1831  // fill tab2 frame3
1832  TGLabel *noOfThermoForCalib = new TGLabel(f23, new TGString("No of Thermo for Calibration:"));
1833 
1834  fNoThermoForCalib = new TGNumberEntry(f23, 2);
1835  fNoThermoForCalib->Connect("ValueSet(Long_t)", "PTempCalibGui", this, "NoOfThermoCalibChanged(Long_t)");
1836 
1837  f23->AddFrame(noOfThermoForCalib, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1838  f23->AddFrame(fNoThermoForCalib, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 10, 20, 3, 3));
1839 
1840  // fill tab2 frame4
1841  // Create TGCanvas and a canvas container which uses a PTempCalibSensors layout manager
1842  fTempCalibSensorsCanvas = new TGCanvas(f24, TCG_WIDTH, 240);
1843  fTempCalibSensorsContainer = new PTempCalibSensors(fTempCalibSensorsCanvas->GetViewPort(), fLakeShore);
1844  fTempCalibSensorsContainer->SetCanvas(fTempCalibSensorsCanvas);
1845  fTempCalibSensorsCanvas->SetContainer(fTempCalibSensorsContainer->GetFrame());
1846 
1847  // use hierarchical cleaning for container
1848  fTempCalibSensorsContainer->GetFrame()->SetCleanup(kDeepCleanup);
1849 
1850  this->Connect("NoOfThermoCalibChanged(Long_t)", "PTempCalibSensors", fTempCalibSensorsContainer, "SetNoOfSensors(Long_t)");
1851 
1852  f24->AddFrame(fTempCalibSensorsCanvas, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
1853 
1854  // fill tab2 frame5
1855  TGLabel *drawDataNo = new TGLabel(f25, new TGString("Draw Data No:"));
1856 
1857  fDrawDataNo = new TGNumberEntry(f25, 1);
1858 
1859  f25->AddFrame(drawDataNo, new TGLayoutHints(kLHintsLeft | kLHintsCenterY, 10, 20, 3, 3));
1860  f25->AddFrame(fDrawDataNo, new TGLayoutHints(kLHintsRight | kLHintsCenterY, 10, 20, 3, 3));
1861 
1862  // fill tab2 frame6
1863  fTab2CalibButton = new TGTextButton(f26, "&Calibrate");
1864  fTab2CalibButton->Connect("Clicked()", "PTempCalibGui", this, "DoCalibration()");
1865  f26->AddFrame(fTab2CalibButton, new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
1866 
1867  fTab2DrawButton = new TGTextButton(f26, "&Draw");
1868  fTab2DrawButton->Connect("Clicked()", "PTempCalibGui", this, "DoDrawWithErrors()");
1869  f26->AddFrame(fTab2DrawButton, new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
1870 
1871  fTab2ExitButton = new TGTextButton(f26, "&Exit");
1872  fTab2ExitButton->Resize(200, fTab2ExitButton->GetDefaultHeight());
1873  fTab2ExitButton->Connect("Clicked()", "PTempCalibGui", this, "CloseWindow()");
1874  f26->AddFrame(fTab2ExitButton, new TGLayoutHints(kLHintsRight, 5, 5, 3, 4));
1875 
1876  // add tab2 frames to the master frame
1877  tf->AddFrame(f21, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1878  tf->AddFrame(f22, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1879  tf->AddFrame(f23, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1880  tf->AddFrame(f24, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1881  tf->AddFrame(f25, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1882  tf->AddFrame(f26, new TGLayoutHints(kLHintsBottom | kLHintsExpandX));
1883 
1884  //-----------------------------------------------------------------------------------
1885  // tab3
1886  //-----------------------------------------------------------------------------------
1887  tf = fTab->AddTab("Plot");
1888 
1889  TGCompositeFrame *f31 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1890  TGCompositeFrame *f32 = new TGCompositeFrame(tf, TCG_WIDTH, 80, kHorizontalFrame);
1891 
1892  TGLabel *fileNameLabel3 = new TGLabel(f31, new TGString("File Name:"));
1893  fileNameLabel3->Resize(120, fileNameLabel3->GetDefaultHeight());
1894 
1895  fTab3FileName = new TGTextEntry(f31);
1896  fTab3FileName->Resize(210, fTab3FileName->GetDefaultHeight());
1897 
1898  fTab3BrowseButton = new TGTextButton(f31, "&Browse");
1899  fTab3BrowseButton->Connect("Clicked()", "PTempCalibGui", this, "DoBrowse()");
1900 
1901  f31->AddFrame(fileNameLabel3, new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
1902  f31->AddFrame(fTab3FileName, new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
1903  f31->AddFrame(fTab3BrowseButton, new TGLayoutHints(kLHintsRight, 5, 5, 3, 4));
1904 
1905  fTab3DrawButton = new TGTextButton(f32, "&Draw");
1906  fTab3DrawButton->Connect("Clicked()", "PTempCalibGui", this, "DoDrawCalibData()");
1907  f32->AddFrame(fTab3DrawButton, new TGLayoutHints(kLHintsLeft, 5, 5, 3, 4));
1908 
1909  fTab3ExitButton = new TGTextButton(f32, "&Exit");
1910  fTab3ExitButton->Resize(200, fTab3ExitButton->GetDefaultHeight());
1911  fTab3ExitButton->Connect("Clicked()", "PTempCalibGui", this, "CloseWindow()");
1912  f32->AddFrame(fTab3ExitButton, new TGLayoutHints(kLHintsRight, 5, 5, 3, 4));
1913 
1914  tf->AddFrame(f31, new TGLayoutHints(kLHintsTop | kLHintsExpandX));
1915  tf->AddFrame(f32, new TGLayoutHints(kLHintsBottom | kLHintsExpandX));
1916 
1917  fFrame->AddFrame(fTab, new TGLayoutHints(kLHintsExpandX | kLHintsExpandY, 0, 0, 2, 2));
1918 
1919  fTab->Connect("Selected(Int_t)", "PTempCalibGui", this, "DoTabSelected(Int_t)");
1920 
1921  fMain->MapSubwindows();
1922 
1923  // we need to use GetDefault...() to initialize the layout algorithm...
1924  fMain->Resize();
1925  fMain->MapWindow();
1926 // fMain->Print();
1927 }
1928 
1929 //--------------------------------------------------------------------------
1935 {
1936  if (fMain)
1937  delete fMain;
1938 }
1939 
1940 //--------------------------------------------------------------------------
1947 {
1948  // Got close message for this MainFrame. Terminates the application.
1949 
1950  gApplication->Terminate();
1951 }
1952 
1953 //--------------------------------------------------------------------------
1961 {
1962  const char *filetypes[] = { "All Files", "*",
1963  "Raw Data Files", "*.dat",
1964  0, 0 };
1965 
1966  static TString dir(".");
1967  TGFileInfo fi;
1968  fi.fFileTypes = filetypes;
1969  fi.fIniDir = StrDup(dir);
1970  new TGFileDialog(gClient->GetRoot(), fMain, kFDOpen, &fi);
1971  dir = fi.fIniDir;
1972 
1973  if (fi.fFilename) {
1974  switch (fTab->GetCurrent()) {
1975  case 0:
1976  fTab1FileName->SetText(fi.fFilename);
1977  LoadRawData(fi.fFilename);
1978  break;
1979  case 1:
1980  fTab2SerialNoCalibThermo->SetText(fi.fFilename);
1981  LoadCalibData(fi.fFilename);
1982  break;
1983  case 2:
1984  fTab3FileName->SetText(fi.fFilename);
1985  LoadCalibData(fi.fFilename);
1986  break;
1987  default:
1988  break;
1989  }
1990  }
1991 
1992 }
1993 
1994 //--------------------------------------------------------------------------
2001 {
2002  EPRawCh xIdx = eEmpty;
2003  EPRawCh yIdx = eEmpty;
2004 
2005  // get the proper x-axis
2006  switch (fTab1XComboBox->GetSelected()) {
2007  case -1:
2008  xIdx = eEmpty;
2009  break;
2010  case 0:
2011  xIdx = eDateTime;
2012  break;
2013  case 1:
2014  xIdx = eTempMeasured;
2015  break;
2016  case 2:
2017  xIdx = eSetPointTemp;
2018  break;
2019  case 3:
2020  xIdx = ePressure;
2021  break;
2022  case 4:
2023  xIdx = eHeaterOutput;
2024  break;
2025  case 5:
2026  xIdx = eHeaterRange;
2027  break;
2028  case 6:
2029  xIdx = eBH1Flow;
2030  break;
2031  case 7:
2032  xIdx = eChA;
2033  break;
2034  case 8:
2035  xIdx = eChB;
2036  break;
2037  case 9:
2038  if (fLakeShore == "340")
2039  xIdx = eChC1;
2040  else // LS336
2041  xIdx = eChC;
2042  break;
2043  case 10:
2044  if (fLakeShore == "340")
2045  xIdx = eChC2;
2046  else // LS336
2047  xIdx = eChD1;
2048  break;
2049  case 11:
2050  if (fLakeShore == "340")
2051  xIdx = eChC3;
2052  else // LS336
2053  xIdx = eChD2;
2054  break;
2055  case 12:
2056  if (fLakeShore == "340")
2057  xIdx = eChC4;
2058  else // LS336
2059  xIdx = eChD3;
2060  break;
2061  case 13:
2062  if (fLakeShore == "340")
2063  xIdx = eChD1;
2064  else // LS336
2065  xIdx = eChD4;
2066  break;
2067  case 14:
2068  if (fLakeShore == "340")
2069  xIdx = eChD2;
2070  else // LS336
2071  xIdx = eChD5;
2072  break;
2073  case 15:
2074  xIdx = eChD3;
2075  break;
2076  case 16:
2077  xIdx = eChD4;
2078  break;
2079  default:
2080  break;
2081  }
2082 
2083  // get the proper y-axis
2084  switch (fTab1YComboBox->GetSelected()) {
2085  case -1:
2086  yIdx = eEmpty;
2087  break;
2088  case 0:
2089  yIdx = eDateTime;
2090  break;
2091  case 1:
2092  yIdx = eTempMeasured;
2093  break;
2094  case 2:
2095  yIdx = eSetPointTemp;
2096  break;
2097  case 3:
2098  yIdx = ePressure;
2099  break;
2100  case 4:
2101  yIdx = eHeaterOutput;
2102  break;
2103  case 5:
2104  yIdx = eHeaterRange;
2105  break;
2106  case 6:
2107  yIdx = eBH1Flow;
2108  break;
2109  case 7:
2110  yIdx = eChA;
2111  break;
2112  case 8:
2113  yIdx = eChB;
2114  break;
2115  case 9:
2116  if (fLakeShore == "340")
2117  yIdx = eChC1;
2118  else // LS336
2119  yIdx = eChC;
2120  break;
2121  case 10:
2122  if (fLakeShore == "340")
2123  yIdx = eChC2;
2124  else // LS336
2125  yIdx = eChD1;
2126  break;
2127  case 11:
2128  if (fLakeShore == "340")
2129  yIdx = eChC3;
2130  else // LS336
2131  yIdx = eChD2;
2132  break;
2133  case 12:
2134  if (fLakeShore == "340")
2135  yIdx = eChC4;
2136  else // LS336
2137  yIdx = eChD3;
2138  break;
2139  case 13:
2140  if (fLakeShore == "340")
2141  yIdx = eChD1;
2142  else // LS336
2143  yIdx = eChD4;
2144  break;
2145  case 14:
2146  if (fLakeShore == "340")
2147  yIdx = eChD2;
2148  else // LS336
2149  yIdx = eChD5;
2150  break;
2151  case 15:
2152  yIdx = eChD3;
2153  break;
2154  case 16:
2155  yIdx = eChD4;
2156  break;
2157  default:
2158  break;
2159  }
2160 
2161  if ((xIdx == eEmpty) || (yIdx == eEmpty))
2162  return;
2163 
2164  if (!fRawData.IsDataPresent())
2165  return;
2166 
2167  // get start date time
2168  TString dateTimeStr = fTab1StartTime->GetDisplayText();
2169  fRawData.SetStartDateTime(dateTimeStr.Data());
2170 
2171  PDrawRawData *drawRawData = new PDrawRawData(600, 500, fRawData, xIdx, yIdx, fLakeShore);
2172  drawRawData->Show();
2173 }
2174 
2175 //--------------------------------------------------------------------------
2182 {
2183  // perform some test in order to make sure all necessary input is present
2184  if (!fRawData.IsDataPresent()) {
2185  new TGMsgBox(gClient->GetRoot(), fMain, "**ERROR**", "No Raw Data Set present. Go to 'Raw Data' Tab and select one.");
2186  return;
2187  }
2188 
2189  if (!fCalibData.IsValid()) {
2190  new TGMsgBox(gClient->GetRoot(), fMain, "**ERROR**", "No Calibration Table present. Go to 'Calibrate' Tab and select one.");
2191  return;
2192  }
2193 
2194  if (fTab2ChannelCalibThermoComboBox->GetSelected() == -1) {
2195  new TGMsgBox(gClient->GetRoot(), fMain, "**ERROR**", "Calibration Channel needs to be selected!");
2196  return;
2197  }
2198 
2199  for (UInt_t i=1; i<=fTempCalibSensorsContainer->GetNoOfSensors(); i++) {
2200  if (fTempCalibSensorsContainer->GetCh(i) == -1) {
2201  TString str("For Sensor ");
2202  str += i;
2203  str += " the channel assignment is missing! Needs to be done.";
2204  new TGMsgBox(gClient->GetRoot(), fMain, "**ERROR**", str.Data());
2205  return;
2206  }
2207  if (fTempCalibSensorsContainer->GetSensorType(i) == -1) {
2208  TString str("For Sensor ");
2209  str += i;
2210  str += " the sensor type assignment is missing! Needs to be done.";
2211  new TGMsgBox(gClient->GetRoot(), fMain, "**ERROR**", str.Data());
2212  return;
2213  }
2214  if (fTempCalibSensorsContainer->GetSensorName(i).IsWhitespace()) {
2215  TString str("For Sensor ");
2216  str += i;
2217  str += " the sensor name is missing! Needs to be done.";
2218  new TGMsgBox(gClient->GetRoot(), fMain, "**ERROR**", str.Data());
2219  return;
2220  }
2221  if (fTempCalibSensorsContainer->GetSerialNo(i).IsWhitespace()) {
2222  TString str("For Sensor ");
2223  str += i;
2224  str += " the serial number is missing! Needs to be done.";
2225  new TGMsgBox(gClient->GetRoot(), fMain, "**ERROR**", str.Data());
2226  return;
2227  }
2228  }
2229 
2230  // do the calibration
2231 
2232  UInt_t idxCalib = fRawData.MapChNo(fTab2ChannelCalibThermoComboBox->GetSelected());
2233 
2234  // get the indices of the to be calibrated sensors
2235  vector<Int_t> idx;
2236  for (UInt_t i=1; i<=fTempCalibSensorsContainer->GetNoOfSensors(); i++) {
2237  idx.push_back(fRawData.MapChNo(fTempCalibSensorsContainer->GetCh(i)));
2238  }
2239 
2240  // first calculate the averaged values for the calibrate and the to be calibrated sensors
2241  Double_t currentSP = 0.0;
2242 
2243  UInt_t count = 0;
2244  Double_t meanTemp = 0.0;
2245  Double_t meanCalib = 0.0;
2246  Double_t meanData[TCG_NO_OF_RAW_DATA_CH];
2247  for (UInt_t i=0; i<TCG_NO_OF_RAW_DATA_CH; i++) {
2248  meanData[i] = 0.0;
2249  }
2250 
2251  vector<Double_t> temp;
2252  vector<Double_t> calibData;
2253  vector< vector<Double_t> > data;
2254  data.resize(idx.size()); // resize to the number of to be calibrated sensors
2255 
2256  currentSP = fRawData.GetSetPointTemp(0);
2257  for (UInt_t i=0; i<fRawData.GetSize(); i++) {
2258  if (fRawData.GetTime(i) < fRawData.GetStartTime()) {
2259  currentSP = fRawData.GetSetPointTemp(i);
2260  continue;
2261  }
2262 
2263  if (currentSP == fRawData.GetSetPointTemp(i)) {
2264  count++;
2265  meanTemp += fRawData.GetTempMeasured(i);
2266  meanCalib += fRawData.GetRawData(idxCalib, i);
2267  for (UInt_t j=0; j<idx.size(); j++) {
2268  meanData[j] += fRawData.GetRawData(idx[j], i);
2269  }
2270  } else {
2271  // keep mean
2272  temp.push_back(meanTemp/count);
2273  calibData.push_back(meanCalib/count);
2274  for (UInt_t j=0; j<idx.size(); j++) {
2275  data[j].push_back(meanData[j]/count);
2276  }
2277 
2278  // reset count, mean, ...
2279  count = 1;
2280  meanTemp = fRawData.GetTempMeasured(i);
2281  meanCalib = fRawData.GetRawData(idxCalib, i);
2282  for (UInt_t j=0; j<idx.size(); j++) {
2283  meanData[j] = fRawData.GetRawData(idx[j], i);
2284  }
2285 
2286  currentSP = fRawData.GetSetPointTemp(i);
2287  }
2288 
2289  }
2290 
2291  // handle the last point
2292  temp.push_back(meanTemp/count);
2293  calibData.push_back(meanCalib/count);
2294  for (UInt_t j=0; j<idx.size(); j++) {
2295  data[j].push_back(meanData[j]/count);
2296  }
2297 
2298  vector<Double_t> calibTemp;
2299  for (UInt_t i=0; i<calibData.size(); i++) {
2300  calibTemp.push_back(fCalibData.GetTemp(calibData[i]));
2301  }
2302 
2303  // save the calibration tables for the to be calibrated sensors
2304  TString filename("");
2305  ofstream fout;
2306  TDatime dt;
2307  TString date("");
2308  TString dataFormat("");
2309  TString tempCoeff("");
2310  for (UInt_t i=0; i<data.size(); i++) {
2311  filename = fTempCalibSensorsContainer->GetSensorName(i+1) + ".340";
2312  fout.open(filename.Data(), ofstream::out);
2313  if (!fout.is_open()) {
2314  cerr << "**ERROR** couldn't open file: " << filename << "." << endl;
2315  return;
2316  }
2317 
2318  date = "";
2319  if (dt.GetYear()-2000 >= 10) {
2320  date += dt.GetYear()-2000;
2321  } else {
2322  date += "0";
2323  date += dt.GetYear()-2000;
2324  }
2325  if (dt.GetMonth() >= 10) {
2326  date += dt.GetMonth();
2327  } else {
2328  date += "0";
2329  date += dt.GetMonth();
2330  }
2331  if (dt.GetDay() >= 10) {
2332  date += dt.GetDay();
2333  } else {
2334  date += "0";
2335  date += dt.GetDay();
2336  }
2337 
2338  // get data format
2339  switch (fTempCalibSensorsContainer->GetDataFormat(i+1)) {
2340  case 1:
2341  dataFormat = "1 (mV/Kelvin)";
2342  break;
2343  case 2:
2344  dataFormat = "2 (Volts/Kelvin)";
2345  break;
2346  case 3:
2347  dataFormat = "3 (Ohms/Kelvin)";
2348  break;
2349  case 4:
2350  dataFormat = "4 (Log Ohms/Kelvin)";
2351  break;
2352  case 5:
2353  dataFormat = "5 (Log Ohms/Log Kelvin)";
2354  break;
2355  default:
2356  break;
2357  }
2358 
2359  // get temperature coefficient information
2360  switch (fTempCalibSensorsContainer->GetSensorType(i+1)) {
2361  case 0: // Special
2362  case 1: // Silicon Diode
2363  case 2: // GaAlAs Diode
2364  tempCoeff = "1 (Negative)";
2365  break;
2366  case 3: // Platinum 100 (250Ohm)
2367  case 4: // Platinum 100 (500Ohm)
2368  case 5: // Platinum 1000
2369  case 6: // Rhodium Iron
2370  tempCoeff = "2 (Positive)";
2371  break;
2372  case 7: // Carbon-Glass
2373  case 8: // Cernox
2374  case 9: // RuOx
2375  case 10: // Germanium
2376  tempCoeff = "1 (Negative)";
2377  break;
2378  case 11: // Capacitor
2379  case 12: // Thermocouple
2380  tempCoeff = "2 (Positive)";
2381  break;
2382  default:
2383  tempCoeff = "1 (Negative)";
2384  break;
2385  }
2386 
2387  // check number of break points
2388  UInt_t noOfBreakPoints = data[i].size();
2389  if (calibTemp[data[i].size()-1] < 325.0)
2390  noOfBreakPoints++;
2391  if (calibTemp[0] > 1.5)
2392  noOfBreakPoints++;
2393 
2394  // write header
2395  fout << "Sensor Model: " << fTempCalibSensorsContainer->GetSensorName(i+1).Data() << "/" << date.Data() << endl;
2396  fout << "Serial Number: " << fTempCalibSensorsContainer->GetSerialNo(i+1).Data() << endl;
2397  fout << "Data Format: " << dataFormat.Data() << endl;
2398  fout << "SetPoint Limit: 325. (Kelvin)" << endl;
2399  fout << "Temperature coefficient: " << tempCoeff.Data() << endl;
2400  fout << "Number of Breakpoints: " << noOfBreakPoints << endl;
2401  fout << endl;
2402  fout << "No. Units Temperature (K)" << endl;
2403  fout << endl;
2404 
2405  // add a point at SetPoint limit is needed (linear extrapolation)
2406  UInt_t size = data[i].size()-1;
2407  UInt_t offset = 1;
2408  if (calibTemp[size] < 325.0) {
2409  offset = 2;
2410  fout.width(3);
2411  fout << 1 << " ";
2412  fout.width(7);
2413  fout.precision(5);
2414  fout.setf(ios::fixed, ios::floatfield);
2415  fout << data[i][size-1] + (data[i][size]-data[i][size-1])*(325.0-calibTemp[size-1])/(calibTemp[size]-calibTemp[size-1]) << " ";
2416  fout.width(7);
2417  fout.precision(3);
2418  fout.setf(ios::fixed, ios::floatfield);
2419  fout << "325.000" << endl;
2420  }
2421 
2422  // write data
2423  for (UInt_t j=0; j<data[i].size(); j++) {
2424  fout.width(3);
2425  fout << j+offset << " ";
2426  fout.width(7);
2427  fout.precision(5);
2428  fout.setf(ios::fixed, ios::floatfield);
2429  fout << data[i][size-j] << " ";
2430  fout.width(7);
2431  fout.precision(3);
2432  fout.setf(ios::fixed, ios::floatfield);
2433  fout << calibTemp[size-j] << endl;
2434  }
2435 
2436  // add a point at 1.5K if needed
2437  if (calibTemp[0] > 1.5) {
2438  fout.width(3);
2439  fout << noOfBreakPoints << " ";
2440  fout.width(7);
2441  fout.precision(5);
2442  fout.setf(ios::fixed, ios::floatfield);
2443  fout << data[i][0] - (data[i][1]-data[i][0])*(calibTemp[1]-1.5)/(calibTemp[1]-calibTemp[0]) << " ";
2444  fout.width(7);
2445  fout.precision(3);
2446  fout.setf(ios::fixed, ios::floatfield);
2447  fout << "1.500" << endl;
2448  fout << endl;
2449  } else {
2450  fout << endl;
2451  }
2452 
2453  fout.close();
2454  }
2455 
2456  // clean up
2457  idx.clear();
2458  temp.clear();
2459  calibData.clear();
2460  for (UInt_t i=0; i<data.size(); i++)
2461  data[i].clear();
2462  data.clear();
2463  calibTemp.clear();
2464 
2465  // notification
2466  new TGMsgBox(gClient->GetRoot(), fMain, "**INFO**", "Calibration done ...", kMBIconAsterisk, kMBClose);
2467 }
2468 
2469 //--------------------------------------------------------------------------
2478 {
2479  if (!fRawData.IsDataPresent()) {
2480  new TGMsgBox(gClient->GetRoot(), fMain, "**ERROR**", "No Raw Data Set present. Go to 'Raw Data' Tab and select one.");
2481  return;
2482  }
2483 
2484  // check what data set to be drawn (0=calibration channel itself)
2485  Long_t drawNo = fDrawDataNo->GetIntNumber();
2486  Long_t calibMaxNo = fNoThermoForCalib->GetIntNumber();
2487 
2488  if (drawNo > calibMaxNo)
2489  return;
2490 
2491  Int_t chNo = 0; // 0=A, 1=B, 2=C1, ...
2492  if (drawNo == 0) {
2493  chNo = fTab2ChannelCalibThermoComboBox->GetSelected();
2494  } else {
2495  chNo = fTempCalibSensorsContainer->GetCh(drawNo);
2496  }
2497 
2498  Int_t rawChNo = fRawData.MapChNo(chNo);
2499 
2500  // for the chosen data set calculate mean and std deviation for both, sensor and temperature
2501  Double_t currentSP = 0.0;
2502 
2503  UInt_t count = 0;
2504  Double_t meanTemp = 0.0;
2505  Double_t sdvTemp = 0.0;
2506  Double_t meanData = 0.0;
2507  Double_t sdvData = 0.0;
2508 
2509  vector<Double_t> temp;
2510  vector<Double_t> errTemp;
2511  vector<Double_t> data;
2512  vector<Double_t> errData;
2513 
2514  currentSP = fRawData.GetSetPointTemp(0);
2515  for (UInt_t i=0; i<fRawData.GetSize(); i++) {
2516  if (fRawData.GetTime(i) < fRawData.GetStartTime()) {
2517  currentSP = fRawData.GetSetPointTemp(i);
2518  continue;
2519  }
2520 
2521  if (currentSP == fRawData.GetSetPointTemp(i)) {
2522  count++;
2523  meanTemp += fRawData.GetTempMeasured(i);
2524  meanData += fRawData.GetRawData(rawChNo, i);
2525  } else {
2526  // keep mean
2527  temp.push_back(meanTemp/count);
2528  data.push_back(meanData/count);
2529 
2530  // calculate standard deviation
2531  sdvTemp = 0.0;
2532  sdvData = 0.0;
2533  for (UInt_t j=i-count; j<i; j++) {
2534  sdvTemp += TMath::Power(fRawData.GetTempMeasured(j)-meanTemp/count, 2.0);
2535  sdvData += TMath::Power(fRawData.GetRawData(rawChNo, j)-meanData/count, 2.0);
2536  }
2537  if (count > 1) {
2538  errTemp.push_back(TMath::Sqrt(sdvTemp/(count-1)));
2539  errData.push_back(TMath::Sqrt(sdvData/(count-1)));
2540  } else {
2541  errTemp.push_back(0.0);
2542  errData.push_back(0.0);
2543  }
2544 
2545  // reset count, mean, ...
2546  count = 1;
2547  meanTemp = fRawData.GetTempMeasured(i);
2548  meanData = fRawData.GetRawData(rawChNo, i);
2549 
2550  currentSP = fRawData.GetSetPointTemp(i);
2551  }
2552 
2553  }
2554 
2555  // handle the last point
2556  // keep mean
2557  temp.push_back(meanTemp/count);
2558  data.push_back(meanData/count);
2559 
2560  // calculate standard deviation
2561  sdvTemp = 0.0;
2562  sdvData = 0.0;
2563  for (UInt_t j=fRawData.GetSize()-count; j<fRawData.GetSize(); j++) {
2564  sdvTemp += TMath::Power(fRawData.GetTempMeasured(j)-meanTemp/count, 2.0);
2565  sdvData += TMath::Power(fRawData.GetRawData(rawChNo, j)-meanData/count, 2.0);
2566  }
2567  if (count > 1) {
2568  errTemp.push_back(TMath::Sqrt(sdvTemp/(count-1)));
2569  errData.push_back(TMath::Sqrt(sdvData/(count-1)));
2570  } else {
2571  errTemp.push_back(0.0);
2572  errData.push_back(0.0);
2573  }
2574 
2575  TString units("");
2576  if ((fRawData.GetRawDataSensorType(chNo) == 1) || (fRawData.GetRawDataSensorType(chNo) == 2))
2577  units = " (V)";
2578  else
2579  units = " (Ohm)";
2580  TString ylabel("");
2581  switch (chNo) {
2582  case 0:
2583  ylabel = "A" + units;
2584  break;
2585  case 1:
2586  ylabel = "B" + units;
2587  break;
2588  case 2:
2589  if (fLakeShore == "340")
2590  ylabel = "C1" + units;
2591  else
2592  ylabel = "C" + units;
2593  break;
2594  case 3:
2595  if (fLakeShore == "340")
2596  ylabel = "C2" + units;
2597  else
2598  ylabel = "D1" + units;
2599  break;
2600  case 4:
2601  if (fLakeShore == "340")
2602  ylabel = "C3" + units;
2603  else
2604  ylabel = "D2" + units;
2605  break;
2606  case 5:
2607  if (fLakeShore == "340")
2608  ylabel = "C4" + units;
2609  else
2610  ylabel = "D3" + units;
2611  break;
2612  case 6:
2613  if (fLakeShore == "340")
2614  ylabel = "D1" + units;
2615  else
2616  ylabel = "D4" + units;
2617  break;
2618  case 7:
2619  if (fLakeShore == "340")
2620  ylabel = "D2" + units;
2621  else
2622  ylabel = "D5" + units;
2623  break;
2624  case 8:
2625  ylabel = "D3" + units;
2626  break;
2627  case 9:
2628  ylabel = "D4" + units;
2629  break;
2630  default:
2631  break;
2632  }
2633 
2634  PDrawMeanRawData *dataGraph = new PDrawMeanRawData(600, 500, temp, errTemp, data, errData, ylabel);
2635  dataGraph->Show();
2636 
2637  // clean up
2638  temp.clear();
2639  errTemp.clear();
2640  data.clear();
2641  errData.clear();
2642 }
2643 
2644 //--------------------------------------------------------------------------
2652 {
2653  if (!fCalibData.IsValid())
2654  return;
2655 
2656  PDrawCalibData *calibData = new PDrawCalibData(600, 500, fCalibData);
2657  calibData->Show();
2658 }
2659 
2660 //--------------------------------------------------------------------------
2667 {
2668  if (id == 1) {
2669  NoOfThermoCalibChanged(0);
2670  }
2671 }
2672 
2673 //--------------------------------------------------------------------------
2681 {
2682  Long_t no = fNoThermoForCalib->GetIntNumber();
2683 
2684  Emit("NoOfThermoCalibChanged(Long_t)", no);
2685 }
2686 
2687 //--------------------------------------------------------------------------
2693 void PTempCalibGui::LoadRawData(const char *filename)
2694 {
2695  ifstream ifs(filename, ifstream::in);
2696 
2697  char line[512];
2698  vector<TString> rawData;
2699  while (!ifs.eof()) {
2700  ifs.getline(line, 512);
2701  rawData.push_back(TString(line));
2702  }
2703  ifs.close();
2704 
2705  // find header
2706  UInt_t i=0;
2707  Bool_t error=false;
2708  TObjArray *tokens = 0;
2709  TObjString *ostr = 0;
2710  TString str;
2711  Int_t datetime[6] = {0, 0, 0, 0, 0, 0};
2712  TDatime *dt;
2713 
2714  do {
2715  // check if header is found, and if yes feed header info
2716  if (rawData[i].BeginsWith("%"))
2717  i = UpdateHeaderInfo(rawData, i);
2718 
2719  // feed data
2720  if (!rawData[i].IsWhitespace()) {
2721  tokens = rawData[i].Tokenize(",");
2722  Int_t noOfTok = 23;
2723  if (fLakeShore == "336")
2724  noOfTok -= 2;
2725  if (tokens->GetEntries() != noOfTok) {
2726  cerr << endl << ">> **ERROR** in line " << i << ", number of tokens should be " << noOfTok << ", found " << tokens->GetEntries();
2727  cerr << endl << ">> line = " << rawData[i].Data();
2728  cerr << endl << ">> Will quit reading ..." << endl;
2729  error = true;
2730  } else {
2731  // construct time
2732  // year
2733  ostr = dynamic_cast<TObjString*>(tokens->At(2));
2734  str = ostr->GetString();
2735  if (str.IsDigit()) {
2736  datetime[0] = str.Atoi();
2737  } else {
2738  cerr << endl << ">> **ERROR** in line " << i << ", expected the year, found " << str.Data();
2739  cerr << endl << ">> Will quit reading ..." << endl;
2740  error = true;
2741  }
2742  // month
2743  ostr = dynamic_cast<TObjString*>(tokens->At(0));
2744  str = ostr->GetString();
2745  if (str.IsDigit()) {
2746  datetime[1] = str.Atoi();
2747  } else {
2748  cerr << endl << ">> **ERROR** in line " << i << ", expected month, found " << str.Data();
2749  cerr << endl << ">> Will quit reading ..." << endl;
2750  error = true;
2751  }
2752  // day
2753  ostr = dynamic_cast<TObjString*>(tokens->At(1));
2754  str = ostr->GetString();
2755  if (str.IsDigit()) {
2756  datetime[2] = str.Atoi();
2757  } else {
2758  cerr << endl << ">> **ERROR** in line " << i << ", expected day, found " << str.Data();
2759  cerr << endl << ">> Will quit reading ..." << endl;
2760  error = true;
2761  }
2762  // hh
2763  ostr = dynamic_cast<TObjString*>(tokens->At(3));
2764  str = ostr->GetString();
2765  if (str.IsDigit()) {
2766  datetime[3] = str.Atoi();
2767  } else {
2768  cerr << endl << ">> **ERROR** in line " << i << ", expected hh, found " << str.Data();
2769  cerr << endl << ">> Will quit reading ..." << endl;
2770  error = true;
2771  }
2772  // mm
2773  ostr = dynamic_cast<TObjString*>(tokens->At(4));
2774  str = ostr->GetString();
2775  if (str.IsDigit()) {
2776  datetime[4] = str.Atoi();
2777  } else {
2778  cerr << endl << ">> **ERROR** in line " << i << ", expected mm, found " << str.Data();
2779  cerr << endl << ">> Will quit reading ..." << endl;
2780  error = true;
2781  }
2782  // ss
2783  ostr = dynamic_cast<TObjString*>(tokens->At(5));
2784  str = ostr->GetString();
2785  if (str.IsDigit()) {
2786  datetime[5] = str.Atoi();
2787  } else {
2788  cerr << endl << ">> **ERROR** in line " << i << ", expected ss, found " << str.Data();
2789  cerr << endl << ">> Will quit reading ..." << endl;
2790  error = true;
2791  }
2792  dt = new TDatime(datetime[0],datetime[1],datetime[2],datetime[3],datetime[4],datetime[5]);
2793  fRawData.AddDateTime(dt);
2794 
2795  // get measured temperature
2796  ostr = dynamic_cast<TObjString*>(tokens->At(7));
2797  str = ostr->GetString();
2798  if (str.IsFloat()) {
2799  fRawData.AddTempMeasured(str.Atof());
2800  } else {
2801  cerr << endl << ">> **ERROR** in line " << i << ", expected measured temperature, found " << str.Data();
2802  cerr << endl << ">> Will quit reading ..." << endl;
2803  error = true;
2804  }
2805 
2806  // get pressure
2807  ostr = dynamic_cast<TObjString*>(tokens->At(8));
2808  str = ostr->GetString();
2809  if (str.IsFloat()) {
2810  fRawData.AddPressure(str.Atof());
2811  } else {
2812  cerr << endl << ">> **ERROR** in line " << i << ", expected pressure, found " << str.Data();
2813  cerr << endl << ">> Will quit reading ..." << endl;
2814  error = true;
2815  }
2816 
2817  // get heater output
2818  ostr = dynamic_cast<TObjString*>(tokens->At(9));
2819  str = ostr->GetString();
2820  if (str.IsFloat()) {
2821  fRawData.AddHeaterOutput(str.Atof());
2822  } else {
2823  cerr << endl << ">> **ERROR** in line " << i << ", expected heater output, found " << str.Data();
2824  cerr << endl << ">> Will quit reading ..." << endl;
2825  error = true;
2826  }
2827 
2828  // get setpoint temperature
2829  ostr = dynamic_cast<TObjString*>(tokens->At(10));
2830  str = ostr->GetString();
2831  if (str.IsFloat()) {
2832  fRawData.AddSetPointTemp(str.Atof());
2833  } else {
2834  cerr << endl << ">> **ERROR** in line " << i << ", expected setpoint, found " << str.Data();
2835  cerr << endl << ">> Will quit reading ..." << endl;
2836  error = true;
2837  }
2838 
2839  // get heater range
2840  ostr = dynamic_cast<TObjString*>(tokens->At(11));
2841  str = ostr->GetString();
2842  if (str.IsFloat()) {
2843  fRawData.AddHeaterRange(str.Atof());
2844  } else {
2845  cerr << endl << ">> **ERROR** in line " << i << ", expected heater range, found " << str.Data();
2846  cerr << endl << ">> Will quit reading ..." << endl;
2847  error = true;
2848  }
2849 
2850  // get BH1 flow
2851  ostr = dynamic_cast<TObjString*>(tokens->At(12));
2852  str = ostr->GetString();
2853  if (str.IsFloat()) {
2854  fRawData.AddBH1Flow(str.Atof());
2855  } else {
2856  cerr << endl << ">> **ERROR** in line " << i << ", expected BH1 flow, found " << str.Data();
2857  cerr << endl << ">> Will quit reading ..." << endl;
2858  error = true;
2859  }
2860 
2861  // get Raw Data Readings
2862  UInt_t noOfChs = TCG_NO_OF_RAW_DATA_CH;
2863  if (fLakeShore == "336")
2864  noOfChs -= 2;
2865  for (UInt_t j=0; j<noOfChs; j++) {
2866  ostr = dynamic_cast<TObjString*>(tokens->At(13+j));
2867  str = ostr->GetString();
2868  if (str.IsFloat()) {
2869  fRawData.AddRawData(str.Atof(), j);
2870  } else {
2871  cerr << endl << ">> **ERROR** in line " << i << ", expected Raw Data Reading Entry " << j << ", found " << str.Data();
2872  cerr << endl << ">> Will quit reading ..." << endl;
2873  error = true;
2874  }
2875  }
2876  }
2877  }
2878 
2879  i++;
2880  } while ((i<rawData.size()) && !error);
2881 
2882  if (!error)
2883  fRawData.SetDataPresent(true);
2884 
2885  // clean up
2886  rawData.clear();
2887 }
2888 
2889 //--------------------------------------------------------------------------
2897 UInt_t PTempCalibGui::UpdateHeaderInfo(vector<TString> &rawData, UInt_t idx)
2898 {
2899  TObjArray *tokens = 0;
2900  TObjString *ostr = 0;
2901  TString str;
2902 
2903  // filter out the necessary informations
2904  do {
2905  if (rawData[idx].BeginsWith("% Number of Entries")) {
2906  tokens = rawData[idx].Tokenize(":");
2907  if (tokens->GetEntries() == 2) {
2908  ostr = dynamic_cast<TObjString*>(tokens->At(1));
2909  str = ostr->GetString();
2910  if (str.IsDigit()) {
2911  fRawData.SetNoOfEntries(str.Atoi());
2912  }
2913  }
2914  // clean up
2915  if (tokens) {
2916  delete tokens;
2917  tokens = 0;
2918  }
2919  } else if (rawData[idx].BeginsWith("% Number of Raw Data Reading")) {
2920  tokens = rawData[idx].Tokenize(":");
2921  if (tokens->GetEntries() == 2) {
2922  ostr = dynamic_cast<TObjString*>(tokens->At(1));
2923  str = ostr->GetString();
2924  if (str.IsDigit()) {
2925  fRawData.SetNoOfRawDataReadings(str.Atoi());
2926  }
2927  }
2928  // clean up
2929  if (tokens) {
2930  delete tokens;
2931  tokens = 0;
2932  }
2933  } else if (rawData[idx].BeginsWith("% First Raw Data Reading Entry")) {
2934  tokens = rawData[idx].Tokenize(":");
2935  if (tokens->GetEntries() == 2) {
2936  ostr = dynamic_cast<TObjString*>(tokens->At(1));
2937  str = ostr->GetString();
2938  if (str.IsDigit()) {
2939  fRawData.SetRawDataReadingOffset(str.Atoi());
2940  }
2941  }
2942  // clean up
2943  if (tokens) {
2944  delete tokens;
2945  tokens = 0;
2946  }
2947  } else if (rawData[idx].Contains("measured temperature of control channel")) {
2948  tokens = rawData[idx].Tokenize("=");
2949  if (tokens->GetEntries() == 2) {
2950  ostr = dynamic_cast<TObjString*>(tokens->At(1));
2951  str = ostr->GetString();
2952  str.Remove(TString::kLeading, ' ');
2953  fRawData.SetCtrlCh(str);
2954  }
2955  // clean up
2956  if (tokens) {
2957  delete tokens;
2958  tokens = 0;
2959  }
2960  } else if (rawData[idx].Contains("Raw Data Reading Entry")) {
2961  tokens = rawData[idx].Tokenize(" ");
2962  if (tokens->GetEntries() == 16) {
2963  ostr = dynamic_cast<TObjString*>(tokens->At(8)); // channel no
2964  str = ostr->GetString();
2965  if (str.IsDigit()) {
2966  UInt_t chNo = str.Atoi();
2967  UInt_t noOfChs = TCG_NO_OF_RAW_DATA_CH;
2968  if (fLakeShore == "336")
2969  noOfChs -= 2;
2970  if (chNo < noOfChs) {
2971  ostr = dynamic_cast<TObjString*>(tokens->At(11)); // channel label
2972  str = ostr->GetString();
2973  str.Remove(TString::kLeading, ' ');
2974  fRawData.SetRawDataCh(str, chNo);
2975  ostr = dynamic_cast<TObjString*>(tokens->At(15)); // sensor type
2976  str = ostr->GetString();
2977  if (str.IsDigit()) {
2978  fRawData.SetRawDataSensorType(str.Atoi(), chNo);
2979  }
2980  }
2981  }
2982  }
2983  // clean up
2984  if (tokens) {
2985  delete tokens;
2986  tokens = 0;
2987  }
2988  }
2989 
2990  idx++;
2991  } while (rawData[idx].BeginsWith("%"));
2992 
2993  // check that all the necessary informations are indeed present
2994  UInt_t noOfChs = TCG_NO_OF_RAW_DATA_CH;
2995  UInt_t noOfToks = 23;
2996  if (fLakeShore == "336") {
2997  noOfChs -= 2;
2998  noOfToks -= 2;
2999  }
3000  if (fRawData.GetNoOfEntries() != noOfToks) {
3001  cerr << endl << "**ERROR** UpdateHeaderInfo: Missing 'Number of Entries', something is wrong ..." << endl;
3002  } else if (fRawData.GetNoOfRawDataReadings() != noOfChs) {
3003  cerr << endl << "**ERROR** UpdateHeaderInfo: Missing 'Number of Raw Data Reading', something is wrong ..." << endl;
3004  } else if (fRawData.GetRawDataReadingOffset() != 14) {
3005  cerr << endl << "**ERROR** UpdateHeaderInfo: Missing 'First Raw Data Reading Entry', something is wrong ..." << endl;
3006  } else if (fRawData.GetCtrlCh() == "undefined") {
3007  cerr << endl << "**ERROR** UpdateHeaderInfo: Missing 'measured temperature of control channel', something is wrong ..." << endl;
3008  }
3009 
3010  for (UInt_t i=0; i<noOfChs; i++) {
3011  if (fRawData.GetRawDataCh(i) == "undefined") {
3012  cerr << endl << "**ERROR** UpdateHeaderInfo: Missing 'Raw Data Reading Entry " << i << "', something is wrong ..." << endl;
3013  }
3014  }
3015 
3016  return idx;
3017 }
3018 
3019 //--------------------------------------------------------------------------
3027 void PTempCalibGui::LoadCalibData(const char* filename)
3028 {
3029  ifstream ifs(filename, ifstream::in);
3030 
3031  char line[512];
3032  vector<TString> calibData;
3033  while (!ifs.eof()) {
3034  ifs.getline(line, 512);
3035  calibData.push_back(TString(line));
3036  }
3037  ifs.close();
3038 
3039  UInt_t noOfChs = TCG_NO_OF_RAW_DATA_CH;
3040  if (fLakeShore == "336")
3041  noOfChs -= 2;
3042  if (calibData.size() < noOfChs) {
3043  cerr << endl << ">> **ERROR** Couldn't read enough data from file " << filename << endl;
3044  return;
3045  }
3046 
3047  fCalibData.Init();
3048 
3049  TObjArray *tokens = 0;
3050  TObjArray *tokens1 = 0;
3051  TObjString *ostr = 0;
3052  TString str;
3053 
3054  // get header info
3055  // sensor model
3056  if (calibData[0].BeginsWith("Sensor Model:")) {
3057  tokens = calibData[0].Tokenize(":");
3058  ostr = dynamic_cast<TObjString*>(tokens->At(1));
3059  str = ostr->GetString();
3060  str.Remove(TString::kBoth, ' ');
3061  fCalibData.SetSensorModel(str);
3062  // clean up
3063  if (tokens) {
3064  delete tokens;
3065  tokens = 0;
3066  }
3067  } else {
3068  cerr << endl << ">> **ERROR** Expected line starting with 'Sensor Model', found " << calibData[0].Data() << endl;
3069  return;
3070  }
3071 
3072  // serial number
3073  if (calibData[1].BeginsWith("Serial Number:")) {
3074  tokens = calibData[1].Tokenize(":");
3075  ostr = dynamic_cast<TObjString*>(tokens->At(1));
3076  str = ostr->GetString();
3077  str.Remove(TString::kBoth, ' ');
3078  fCalibData.SetSerialNo(str);
3079  // clean up
3080  if (tokens) {
3081  delete tokens;
3082  tokens = 0;
3083  }
3084  } else {
3085  cerr << endl << ">> **ERROR** Expected line starting with 'Serial Number', found " << calibData[1].Data() << endl;
3086  return;
3087  }
3088 
3089  // data format
3090  if (calibData[2].BeginsWith("Data Format:")) {
3091  tokens = calibData[2].Tokenize(":");
3092  ostr = dynamic_cast<TObjString*>(tokens->At(1));
3093  str = ostr->GetString();
3094  tokens1 = str.Tokenize(" \t");
3095  if (tokens1->GetEntries() > 1) {
3096  ostr = dynamic_cast<TObjString*>(tokens1->At(0));
3097  str = ostr->GetString();
3098  if (str.IsDigit()) {
3099  fCalibData.SetDataFormat(str.Atoi());
3100  } else {
3101  cerr << endl << ">> **ERROR** Data Format is not given as a number! str = " << str.Data() << endl;
3102  }
3103  if (tokens1) {
3104  delete tokens1;
3105  tokens1 = 0;
3106  }
3107  } else {
3108  cerr << endl << ">> **ERROR** Data Format has a wrong format: " << calibData[2].Data() << endl;
3109  }
3110  // clean up
3111  if (tokens) {
3112  delete tokens;
3113  tokens = 0;
3114  }
3115  } else {
3116  cerr << endl << ">> **ERROR** Expected line starting with 'Data Format', found " << calibData[2].Data() << endl;
3117  return;
3118  }
3119 
3120  // set point limit
3121  if (calibData[3].BeginsWith("SetPoint Limit:")) {
3122  tokens = calibData[3].Tokenize(":");
3123  ostr = dynamic_cast<TObjString*>(tokens->At(1));
3124  str = ostr->GetString();
3125  tokens1 = str.Tokenize(" \t");
3126  if (tokens1->GetEntries() > 1) {
3127  ostr = dynamic_cast<TObjString*>(tokens1->At(0));
3128  str = ostr->GetString();
3129  if (str.IsFloat()) {
3130  fCalibData.SetSetPointLimit(str.Atof());
3131  } else {
3132  cerr << endl << ">> **ERROR** SetPoint Limit is not given as a float! str = " << str.Data() << endl;
3133  }
3134  if (tokens1) {
3135  delete tokens1;
3136  tokens1 = 0;
3137  }
3138  } else {
3139  cerr << endl << ">> **ERROR** SetPoint Limit has a wrong format: " << calibData[3].Data() << endl;
3140  }
3141  // clean up
3142  if (tokens) {
3143  delete tokens;
3144  tokens = 0;
3145  }
3146  } else {
3147  cerr << endl << ">> **ERROR** Expected line starting with 'SetPoint Limit', found " << calibData[3].Data() << endl;
3148  return;
3149  }
3150 
3151  // temperature coefficient
3152  if (calibData[4].BeginsWith("Temperature coefficient:")) {
3153  tokens = calibData[4].Tokenize(":");
3154  ostr = dynamic_cast<TObjString*>(tokens->At(1));
3155  str = ostr->GetString();
3156  tokens1 = str.Tokenize(" \t");
3157  if (tokens1->GetEntries() > 1) {
3158  ostr = dynamic_cast<TObjString*>(tokens1->At(0));
3159  str = ostr->GetString();
3160  if (str.IsDigit()) {
3161  fCalibData.SetTempCoeff(str.Atoi());
3162  } else {
3163  cerr << endl << ">> **ERROR** Temp. Coeff. is not given as a number! str = " << str.Data() << endl;
3164  }
3165  if (tokens1) {
3166  delete tokens1;
3167  tokens1 = 0;
3168  }
3169  } else {
3170  cerr << endl << ">> **ERROR** Temp. Coeff. has a wrong format: " << calibData[4].Data() << endl;
3171  }
3172  // clean up
3173  if (tokens) {
3174  delete tokens;
3175  tokens = 0;
3176  }
3177  } else {
3178  cerr << endl << ">> **ERROR** Expected line starting with 'Temperature coefficient', found " << calibData[4].Data() << endl;
3179  return;
3180  }
3181 
3182  // number of breakpoints
3183  if (calibData[5].BeginsWith("Number of Breakpoints:")) {
3184  tokens = calibData[5].Tokenize(":");
3185  ostr = dynamic_cast<TObjString*>(tokens->At(1));
3186  str = ostr->GetString();
3187  str.Remove(TString::kTrailing, '\n');
3188  str.Remove(TString::kTrailing, '\r');
3189  if (str.IsDigit()) {
3190  fCalibData.SetNoOfPoints(str.Atoi());
3191  } else {
3192  cerr << endl << ">> **ERROR** Number of Breakpoints is not given as a number! str = '" << str.Data() << "'" << endl;
3193  }
3194  // clean up
3195  if (tokens) {
3196  delete tokens;
3197  tokens = 0;
3198  }
3199  } else {
3200  cerr << endl << ">> **ERROR** Expected line starting with 'Number of Breakpoints', found " << calibData[5].Data() << endl;
3201  return;
3202  }
3203 
3204  // get data
3205  vector<Double_t> unit, temp;
3206 
3207  for (UInt_t i=9; i<calibData.size(); i++) {
3208  if (calibData[i].IsWhitespace())
3209  continue;
3210 
3211  tokens = calibData[i].Tokenize(" \t");
3212  if (tokens->GetEntries() != 3) {
3213  cerr << endl << ">> **ERROR** in line " << i << ". Expect 3 numbers." << endl;
3214  break;
3215  }
3216 
3217  ostr = dynamic_cast<TObjString*>(tokens->At(1));
3218  str = ostr->GetString();
3219  if (str.IsFloat()) {
3220  unit.push_back(str.Atof());
3221  } else {
3222  cerr << endl << ">> **ERROR** in line " << i << ". Units entry doesn't seem to be a float: " << str.Data() << endl;
3223  break;
3224  }
3225 
3226  ostr = dynamic_cast<TObjString*>(tokens->At(2));
3227  str = ostr->GetString();
3228  str.Remove(TString::kTrailing, '\n');
3229  str.Remove(TString::kTrailing, '\r');
3230  if (str.IsFloat()) {
3231  temp.push_back(str.Atof());
3232  } else {
3233  cerr << endl << ">> **ERROR** in line " << i << ". Temp. entry doesn't seem to be a float: " << str.Data() << endl;
3234  break;
3235  }
3236 
3237  if (tokens) {
3238  delete tokens;
3239  tokens = 0;
3240  }
3241  }
3242 
3243  if (tokens) {
3244  delete tokens;
3245  tokens = 0;
3246  }
3247 
3248  // check that the number of read data == 'Number of Breakpoints'
3249  if ((fCalibData.GetNoOfPoints() == unit.size()) && (fCalibData.GetNoOfPoints() == temp.size())) {
3250  fCalibData.SetValid(true);
3251  for (UInt_t i=0; i<unit.size(); i++) {
3252  fCalibData.AddMeasured(unit[unit.size()-i-1]);
3253  fCalibData.AddTemp(temp[unit.size()-i-1]);
3254  }
3255  } else {
3256  cerr << endl << ">> **ERROR** Found " << fCalibData.GetMeasuredSize() << " points, file claims " << fCalibData.GetNoOfPoints() << " should be present!" << endl;
3257  }
3258 
3259  // clean up
3260  unit.clear();
3261  temp.clear();
3262  calibData.clear();
3263 }
3264 
3265 //--------------------------------------------------------------------------
3266 // end
3267 //--------------------------------------------------------------------------
virtual Int_t GetSensorType(UInt_t sensorIdx)
virtual Double_t GetPressure(UInt_t idx)
virtual void SetRawDataSensorType(UInt_t type, UInt_t idx)
virtual ~PRawData()
#define TCG_HEIGHT
Definition: PTempCalibGui.h:53
virtual void DoDrawCalibData()
virtual void AddHeaterOutput(Double_t heaterOutput)
virtual void Show()
virtual void AddSetPointTemp(Double_t setPoint)
virtual void SetDataFormat(UInt_t ival)
virtual TString GetRawDataCh(UInt_t idx)
virtual UInt_t GetTime(UInt_t idx)
virtual void AddDateTime(TDatime *dt)
virtual UInt_t GetRawDataSensorType(UInt_t idx)
virtual Double_t GetTemp(UInt_t idx)
virtual TString GetSensorName(UInt_t sensorIdx)
virtual Double_t GetHeaterRange(UInt_t idx)
virtual void SetCanvas(TGCanvas *canvas)
virtual Int_t GetDataFormat()
virtual void DoTabSelected(Int_t id)
virtual void DoCalibration()
virtual Double_t GetTempMeasured(UInt_t idx)
virtual Double_t GetHeaterOutput(UInt_t idx)
virtual void DoDrawWithErrors()
virtual ~PTempCalibGui()
virtual void AddPressure(Double_t pressure)
virtual void Show()
virtual TString GetUnits(UInt_t idx)
virtual void SetCtrlCh(const TString &str)
EPRawCh
Definition: PTempCalibGui.h:59
virtual void Show()
virtual void AddTempMeasured(Double_t temp)
virtual TString GetSerialNo(UInt_t sensorIdx)
virtual ~PDrawMeanRawData()
virtual Int_t GetCh(UInt_t sensorIdx)
virtual ~PDrawCalibData()
virtual Double_t GetBH1Flow(UInt_t idx)
virtual ~PTempCalibSensors()
virtual Double_t GetRawData(UInt_t ch, UInt_t idx)
virtual UInt_t UpdateHeaderInfo(vector< TString > &rawData, UInt_t idx)
virtual void AddBH1Flow(Double_t bh1Flow)
virtual void SetNoOfSensors(Long_t)
virtual ~PCalibData()
virtual Int_t GetDataFormat(UInt_t sensorIdx)
virtual void LoadCalibData(const char *filename)
virtual void NoOfThermoCalibChanged(Long_t)
virtual Double_t GetMeasured(UInt_t idx)
virtual void AddHeaterRange(Double_t heaterRange)
virtual ~PSensorInfo()
virtual void AddRawData(Double_t data, UInt_t ch)
virtual void TypeChanged(Int_t)
virtual void DoBrowse()
virtual void CloseWindow()
virtual void SetRawDataCh(const TString &str, UInt_t idx)
virtual Int_t MapChNo(UInt_t chNo)
virtual void LoadRawData(const char *filename)
#define TCG_NO_OF_RAW_DATA_CH
Definition: PTempCalibGui.h:55
virtual Double_t GetSetPointTemp(UInt_t idx)
virtual void SetTempCoeff(UInt_t ival)
#define TCG_WIDTH
Definition: PTempCalibGui.h:52
virtual void Init()
virtual ~PDrawRawData()
virtual void DoDrawRawData()