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
=== modified file 'src/common_cpp/Utils/TOFCalibrationMap.cc'
--- src/common_cpp/Utils/TOFCalibrationMap.cc 2017-05-01 14:37:25 +0000
+++ src/common_cpp/Utils/TOFCalibrationMap.cc 2018-07-26 10:02:12 +0000
@@ -134,15 +134,29 @@
134 bool loaded;134 bool loaded;
135 if (!fromDB) {135 if (!fromDB) {
136// std::cout << "#### initializing from FILE ####" << std::endl;136// std::cout << "#### initializing from FILE ####" << std::endl;
137 std::string xMapT0File = std::string(pMAUS_ROOT_DIR) + t0_file.asString();137 std::string xMapT0File = t0_file.asString();
138 std::string xMapTWFile = std::string(pMAUS_ROOT_DIR) + tw_file.asString();138 std::string xMapTWFile = tw_file.asString();
139 std::string xMapTriggerFile = std::string(pMAUS_ROOT_DIR) + trigger_file.asString();139 std::string xMapTriggerFile = trigger_file.asString();
140 // Load the calibration constants.140 // Load the calibration constants.
141 loaded = this->Initialize(xMapT0File, xMapTWFile, xMapTriggerFile);141 // VP: make the file look up a bit smarter. Don't look into
142 // MAUS_ROOT_DIR is relative or absolute path is given
143 if (t0_file.asString().at(0) != '.' && t0_file.asString().at(0) != '/') {
144 xMapT0File = (std::string(pMAUS_ROOT_DIR) + "/") + xMapT0File;
145 xMapTWFile = (std::string(pMAUS_ROOT_DIR) + "/") + xMapTWFile;
146 xMapTriggerFile = (std::string(pMAUS_ROOT_DIR) + "/") + xMapTriggerFile;
147 }
148
149 Squeak::mout(Squeak::info) << "Will load TOF calibration constants from files:" << endl
150 << xMapT0File << endl
151 << xMapTWFile << endl
152 << xMapTriggerFile << endl;
153
154 loaded = this->Initialize(xMapT0File, xMapTWFile, xMapTriggerFile);
155
142 } else {156 } else {
143// std::cout << "#### initializing from CDB ####" << std::endl;157// std::cout << "#### initializing from CDB ####" << std::endl;
144 // get calib from DB instead of file, the above line is replaced by the one below158 // get calib from DB instead of file, the above line is replaced by the one below
145 loaded = this->InitializeFromCDB();159 loaded = this->InitializeFromCDB();
146 }160 }
147 if (!loaded)161 if (!loaded)
148 return false;162 return false;
@@ -157,6 +171,8 @@
157 LoadTWFile(twFile) &&171 LoadTWFile(twFile) &&
158 LoadTriggerFile(triggerFile);172 LoadTriggerFile(triggerFile);
159173
174 // this->Print();
175
160 return status;176 return status;
161}177}
162178
@@ -210,14 +226,23 @@
210 int reff;226 int reff;
211 double p0;227 double p0;
212 TOFChannelKey key;228 TOFChannelKey key;
229 int nkeys = 0;
213 try {230 try {
214 while (!stream.eof()) {231 char temp[255];
215 stream >> key >> p0 >> reff;232 while (stream.getline(temp, 255)) {
233 stringstream ss(temp);
234
235 ss >> key >> p0 >> reff;
236 // Squeak::mout(Squeak::info)<<key<<endl;
216237
217 int n = FindTOFChannelKey(key);238 int n = FindTOFChannelKey(key);
239 if (n == NOCALIB) // unknown channel in the calibration file, gracefully ignore
240 continue;
218 _t0[n] = p0;241 _t0[n] = p0;
219 _reff[n] = reff;242 _reff[n] = reff;
220 // std::cout << key << " pos:" << n << " t0:" << p0 << " reff:" << reff << std::endl;243 nkeys++;
244 // Squeak::mout(Squeak::info) << key << " pos:" << n
245 // << " t0:" << p0 << " reff:" << reff << std::endl;
221 }246 }
222 } catch (MAUS::Exceptions::Exception e) {247 } catch (MAUS::Exceptions::Exception e) {
223 Squeak::mout(Squeak::error)248 Squeak::mout(Squeak::error)
@@ -226,6 +251,8 @@
226 return false;251 return false;
227 }252 }
228253
254 Squeak::mout(Squeak::info) << "Loaded TOF T0 constants for " << nkeys << " channels." << endl;
255
229 return true;256 return true;
230}257}
231258
@@ -240,17 +267,24 @@
240267
241 double p0, p1, p2, p3;268 double p0, p1, p2, p3;
242 TOFChannelKey key;269 TOFChannelKey key;
270 int nkeys = 0;
243 try {271 try {
244 while (!stream.eof()) {272 char temp[255];
245 stream >> key >> p0 >> p1 >> p2 >> p3;273 while (stream.getline(temp, 255)) {
274 stringstream ss(temp);
275 ss >> key >> p0 >> p1 >> p2 >> p3;
246276
247 int n = FindTOFChannelKey(key);277 int n = FindTOFChannelKey(key);
278 if (n == NOCALIB) // unknown channel in the calibration file, gracefully ignore
279 continue;
248 _twPar[n].resize(4);280 _twPar[n].resize(4);
249 _twPar[n][0] = p0;281 _twPar[n][0] = p0;
250 _twPar[n][1] = p1;282 _twPar[n][1] = p1;
251 _twPar[n][2] = p2;283 _twPar[n][2] = p2;
252 _twPar[n][3] = p3;284 _twPar[n][3] = p3;
253 // std::cout<< key << " pos:" << n << " p0:" << p0 << " p1:" << p1 << std::endl;285 // Squeak::mout(Squeak::info) << key << " pos:" << n
286 // << " p0:" << p0 << " p1:" << p1 << std::endl;
287 nkeys++;
254 }288 }
255 } catch (MAUS::Exceptions::Exception e) {289 } catch (MAUS::Exceptions::Exception e) {
256 Squeak::mout(Squeak::error)290 Squeak::mout(Squeak::error)
@@ -259,6 +293,8 @@
259 return false;293 return false;
260 }294 }
261295
296 Squeak::mout(Squeak::info) << "Loaded TOF TW constants for " << nkeys << " channels." << endl;
297
262 return true;298 return true;
263}299}
264300
@@ -272,13 +308,17 @@
272 }308 }
273 TOFPixelKey Pkey;309 TOFPixelKey Pkey;
274 double dt;310 double dt;
311 int nkeys = 0;
275 try {312 try {
276 while (!stream.eof()) {313 char temp[255];
277 stream >> Pkey >> dt;314 while (stream.getline(temp, 255)) {
315 stringstream ss(temp);
316 ss >> Pkey >> dt;
278317
279 _Tkey.push_back(Pkey);318 _Tkey.push_back(Pkey);
280 _Trt0.push_back(dt);319 _Trt0.push_back(dt);
281 // std::cout<< Pkey << " dt:" << dt << std::endl;320 nkeys++;
321 // Squeak::mout(Squeak::info) << Pkey << " dt:" << dt << std::endl;
282 }322 }
283 } catch (MAUS::Exceptions::Exception e) {323 } catch (MAUS::Exceptions::Exception e) {
284 Squeak::mout(Squeak::error)324 Squeak::mout(Squeak::error)
@@ -289,6 +329,9 @@
289 // Use the last readed pixel key to set the number of the trigger station.329 // Use the last readed pixel key to set the number of the trigger station.
290 _triggerStation = Pkey.station();330 _triggerStation = Pkey.station();
291331
332 Squeak::mout(Squeak::info) << "Loaded TOF trigger delay constants for "
333 << nkeys << " pixels." << endl;
334
292 return true;335 return true;
293}336}
294337
@@ -348,7 +391,8 @@
348 double p2 = _twPar[n][2]/x;391 double p2 = _twPar[n][2]/x;
349 double p3 =_twPar[n][3]/x2;392 double p3 =_twPar[n][3]/x2;
350 double dt_tw = p1 + p2 + p3;393 double dt_tw = p1 + p2 + p3;
351 if (_twPar[n][0] && _twPar[n][1] && _twPar[n][2] && _twPar[n][3])394 if ( _twPar[n][0] || _twPar[n][1] || _twPar[n][2] || _twPar[n][3] )
395 // when all 4 parameters 0, this channel was not calibrated
352 return dt_tw;396 return dt_tw;
353 }397 }
354398
@@ -362,8 +406,8 @@
362 double tw = TW(Pkey, adc);406 double tw = TW(Pkey, adc);
363 double t0 = T0(Pkey, reffSlab);407 double t0 = T0(Pkey, reffSlab);
364 double trt0 = TriggerT0(TrKey);408 double trt0 = TriggerT0(TrKey);
365 // std::cout << "TOFCalibrationMap -> "<< Pkey << " " << TrKey << " tw = " << tw;409 // Squeak::mout(Squeak::info) << "TOFCalibrationMap -> "<< Pkey << " " << TrKey << " tw = " << tw
366 // std::cout << " t0 = " << t0 << " trt0 = " << trt0 << std::endl;410 // << " t0 = " << t0 << " trt0 = " << trt0 << std::endl;
367 if (tw == NOCALIB || t0 == NOCALIB || trt0 == NOCALIB) {411 if (tw == NOCALIB || t0 == NOCALIB || trt0 == NOCALIB) {
368 return NOCALIB;412 return NOCALIB;
369 }413 }

Subscribers

People subscribed via source and target branches