Merge lp:~vpec/maus/tof_calib_read into lp:maus/merge

Proposed by Viktor Pec
Status: Merged
Merged at revision: 748
Proposed branch: lp:~vpec/maus/tof_calib_read
Merge into: lp:maus/merge
Diff against target: 174 lines (+63/-19)
1 file modified
src/common_cpp/Utils/TOFCalibrationMap.cc (+63/-19)
To merge this branch: bzr merge lp:~vpec/maus/tof_calib_read
Reviewer Review Type Date Requested Status
MAUS Maintainers Pending
Review via email: mp+351344@code.launchpad.net

Commit message

Modifications to TOF reconstruction related code.

Description of the change

Some changes to TOF reconstruciton code - improved reading of calibration constants from files: smarter look up of the files specified in the job configuration and the loading now does not fail when there is a new line at the end of the input file. If relative path of the calibration files are given starting with '.', these paths are assumed relative to the current directory, relative path not starting with '.' will be assumed relative to MAUS_ROOT_DIR. Absolut path can be supplied too.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/common_cpp/Utils/TOFCalibrationMap.cc'
2--- src/common_cpp/Utils/TOFCalibrationMap.cc 2017-05-01 14:37:25 +0000
3+++ src/common_cpp/Utils/TOFCalibrationMap.cc 2018-07-26 10:02:12 +0000
4@@ -134,15 +134,29 @@
5 bool loaded;
6 if (!fromDB) {
7 // std::cout << "#### initializing from FILE ####" << std::endl;
8- std::string xMapT0File = std::string(pMAUS_ROOT_DIR) + t0_file.asString();
9- std::string xMapTWFile = std::string(pMAUS_ROOT_DIR) + tw_file.asString();
10- std::string xMapTriggerFile = std::string(pMAUS_ROOT_DIR) + trigger_file.asString();
11- // Load the calibration constants.
12- loaded = this->Initialize(xMapT0File, xMapTWFile, xMapTriggerFile);
13+ std::string xMapT0File = t0_file.asString();
14+ std::string xMapTWFile = tw_file.asString();
15+ std::string xMapTriggerFile = trigger_file.asString();
16+ // Load the calibration constants.
17+ // VP: make the file look up a bit smarter. Don't look into
18+ // MAUS_ROOT_DIR is relative or absolute path is given
19+ if (t0_file.asString().at(0) != '.' && t0_file.asString().at(0) != '/') {
20+ xMapT0File = (std::string(pMAUS_ROOT_DIR) + "/") + xMapT0File;
21+ xMapTWFile = (std::string(pMAUS_ROOT_DIR) + "/") + xMapTWFile;
22+ xMapTriggerFile = (std::string(pMAUS_ROOT_DIR) + "/") + xMapTriggerFile;
23+ }
24+
25+ Squeak::mout(Squeak::info) << "Will load TOF calibration constants from files:" << endl
26+ << xMapT0File << endl
27+ << xMapTWFile << endl
28+ << xMapTriggerFile << endl;
29+
30+ loaded = this->Initialize(xMapT0File, xMapTWFile, xMapTriggerFile);
31+
32 } else {
33 // std::cout << "#### initializing from CDB ####" << std::endl;
34- // get calib from DB instead of file, the above line is replaced by the one below
35- loaded = this->InitializeFromCDB();
36+ // get calib from DB instead of file, the above line is replaced by the one below
37+ loaded = this->InitializeFromCDB();
38 }
39 if (!loaded)
40 return false;
41@@ -157,6 +171,8 @@
42 LoadTWFile(twFile) &&
43 LoadTriggerFile(triggerFile);
44
45+ // this->Print();
46+
47 return status;
48 }
49
50@@ -210,14 +226,23 @@
51 int reff;
52 double p0;
53 TOFChannelKey key;
54+ int nkeys = 0;
55 try {
56- while (!stream.eof()) {
57- stream >> key >> p0 >> reff;
58+ char temp[255];
59+ while (stream.getline(temp, 255)) {
60+ stringstream ss(temp);
61+
62+ ss >> key >> p0 >> reff;
63+ // Squeak::mout(Squeak::info)<<key<<endl;
64
65 int n = FindTOFChannelKey(key);
66+ if (n == NOCALIB) // unknown channel in the calibration file, gracefully ignore
67+ continue;
68 _t0[n] = p0;
69 _reff[n] = reff;
70- // std::cout << key << " pos:" << n << " t0:" << p0 << " reff:" << reff << std::endl;
71+ nkeys++;
72+ // Squeak::mout(Squeak::info) << key << " pos:" << n
73+ // << " t0:" << p0 << " reff:" << reff << std::endl;
74 }
75 } catch (MAUS::Exceptions::Exception e) {
76 Squeak::mout(Squeak::error)
77@@ -226,6 +251,8 @@
78 return false;
79 }
80
81+ Squeak::mout(Squeak::info) << "Loaded TOF T0 constants for " << nkeys << " channels." << endl;
82+
83 return true;
84 }
85
86@@ -240,17 +267,24 @@
87
88 double p0, p1, p2, p3;
89 TOFChannelKey key;
90+ int nkeys = 0;
91 try {
92- while (!stream.eof()) {
93- stream >> key >> p0 >> p1 >> p2 >> p3;
94+ char temp[255];
95+ while (stream.getline(temp, 255)) {
96+ stringstream ss(temp);
97+ ss >> key >> p0 >> p1 >> p2 >> p3;
98
99 int n = FindTOFChannelKey(key);
100+ if (n == NOCALIB) // unknown channel in the calibration file, gracefully ignore
101+ continue;
102 _twPar[n].resize(4);
103 _twPar[n][0] = p0;
104 _twPar[n][1] = p1;
105 _twPar[n][2] = p2;
106 _twPar[n][3] = p3;
107- // std::cout<< key << " pos:" << n << " p0:" << p0 << " p1:" << p1 << std::endl;
108+ // Squeak::mout(Squeak::info) << key << " pos:" << n
109+ // << " p0:" << p0 << " p1:" << p1 << std::endl;
110+ nkeys++;
111 }
112 } catch (MAUS::Exceptions::Exception e) {
113 Squeak::mout(Squeak::error)
114@@ -259,6 +293,8 @@
115 return false;
116 }
117
118+ Squeak::mout(Squeak::info) << "Loaded TOF TW constants for " << nkeys << " channels." << endl;
119+
120 return true;
121 }
122
123@@ -272,13 +308,17 @@
124 }
125 TOFPixelKey Pkey;
126 double dt;
127+ int nkeys = 0;
128 try {
129- while (!stream.eof()) {
130- stream >> Pkey >> dt;
131+ char temp[255];
132+ while (stream.getline(temp, 255)) {
133+ stringstream ss(temp);
134+ ss >> Pkey >> dt;
135
136 _Tkey.push_back(Pkey);
137 _Trt0.push_back(dt);
138- // std::cout<< Pkey << " dt:" << dt << std::endl;
139+ nkeys++;
140+ // Squeak::mout(Squeak::info) << Pkey << " dt:" << dt << std::endl;
141 }
142 } catch (MAUS::Exceptions::Exception e) {
143 Squeak::mout(Squeak::error)
144@@ -289,6 +329,9 @@
145 // Use the last readed pixel key to set the number of the trigger station.
146 _triggerStation = Pkey.station();
147
148+ Squeak::mout(Squeak::info) << "Loaded TOF trigger delay constants for "
149+ << nkeys << " pixels." << endl;
150+
151 return true;
152 }
153
154@@ -348,7 +391,8 @@
155 double p2 = _twPar[n][2]/x;
156 double p3 =_twPar[n][3]/x2;
157 double dt_tw = p1 + p2 + p3;
158- if (_twPar[n][0] && _twPar[n][1] && _twPar[n][2] && _twPar[n][3])
159+ if ( _twPar[n][0] || _twPar[n][1] || _twPar[n][2] || _twPar[n][3] )
160+ // when all 4 parameters 0, this channel was not calibrated
161 return dt_tw;
162 }
163
164@@ -362,8 +406,8 @@
165 double tw = TW(Pkey, adc);
166 double t0 = T0(Pkey, reffSlab);
167 double trt0 = TriggerT0(TrKey);
168- // std::cout << "TOFCalibrationMap -> "<< Pkey << " " << TrKey << " tw = " << tw;
169- // std::cout << " t0 = " << t0 << " trt0 = " << trt0 << std::endl;
170+ // Squeak::mout(Squeak::info) << "TOFCalibrationMap -> "<< Pkey << " " << TrKey << " tw = " << tw
171+ // << " t0 = " << t0 << " trt0 = " << trt0 << std::endl;
172 if (tw == NOCALIB || t0 == NOCALIB || trt0 == NOCALIB) {
173 return NOCALIB;
174 }

Subscribers

People subscribed via source and target branches