549.1.34
by Yordan Karadzhov
merge with the trunk |
1 |
/* This file is part of MAUS: http://micewww.pp.rl.ac.uk:8080/projects/maus
|
2 |
*
|
|
3 |
* MAUS is free software: you can redistribute it and/or modify
|
|
4 |
* it under the terms of the GNU General Public License as published by
|
|
5 |
* the Free Software Foundation, either version 3 of the License, or
|
|
6 |
* (at your option) any later version.
|
|
7 |
*
|
|
8 |
* MAUS is distributed in the hope that it will be useful,
|
|
9 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
10 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
11 |
* GNU General Public License for more details.
|
|
12 |
*
|
|
13 |
* You should have received a copy of the GNU General Public License
|
|
14 |
* along with MAUS. If not, see <http://www.gnu.org/licenses/>.
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
||
18 |
#ifndef _MAUS_TOFCALIBRATIONMAP_HH_
|
|
19 |
#define _MAUS_TOFCALIBRATIONMAP_HH_
|
|
20 |
||
21 |
||
663.6.294
by Durga Rajaram
tofcalib python reducer |
22 |
#include <Python.h> |
549.1.34
by Yordan Karadzhov
merge with the trunk |
23 |
#include <stdint.h> |
24 |
#include <stdlib.h> |
|
25 |
#include <string> |
|
26 |
#include <vector> |
|
27 |
#include <iostream> |
|
28 |
#include <sstream> |
|
29 |
#include <fstream> |
|
663.6.170
by Durga Rajaram
tof calibrations and cabling from cdb |
30 |
#include <algorithm> |
31 |
#include <cctype> |
|
32 |
#include <functional> |
|
549.1.34
by Yordan Karadzhov
merge with the trunk |
33 |
|
34 |
#include "json/json.h" |
|
35 |
#include "Utils/TOFChannelMap.hh" |
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
36 |
#include "Utils/Exception.hh" |
549.1.34
by Yordan Karadzhov
merge with the trunk |
37 |
#include "Interface/Squeak.hh" |
38 |
#include "src/common_cpp/Utils/JsonWrapper.hh" |
|
39 |
||
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
40 |
namespace MAUS { |
41 |
||
549.1.34
by Yordan Karadzhov
merge with the trunk |
42 |
/** Identifier for a single TOF pixel.
|
43 |
* This class is used to hold and manage all the information needed
|
|
44 |
* to identifiy one pixel in the TOF detectors.
|
|
45 |
*/
|
|
46 |
class TOFPixelKey { |
|
47 |
||
48 |
public: |
|
49 |
TOFPixelKey() |
|
50 |
:_station(-999), _slabX(-999), _slabY(-999), _detector("unknown") {} |
|
51 |
||
52 |
TOFPixelKey(int st, int slX, int slY, string d) |
|
53 |
:_station(st), _slabX(slX), _slabY(slY), _detector(d) {} |
|
54 |
||
600.1.150
by Peter Lane
Mass substitution of Squeal->Exception, squeal->exception, squee->exception. |
55 |
explicit TOFPixelKey(string keyStr) throw(Exception); |
549.1.34
by Yordan Karadzhov
merge with the trunk |
56 |
|
57 |
virtual ~TOFPixelKey() {} |
|
58 |
||
59 |
bool operator==( TOFPixelKey key ); |
|
60 |
bool operator!=( TOFPixelKey key ); |
|
61 |
||
62 |
friend ostream& operator<<( ostream& stream, TOFPixelKey key ); |
|
600.1.150
by Peter Lane
Mass substitution of Squeal->Exception, squeal->exception, squee->exception. |
63 |
friend istream& operator>>( istream& stream, TOFPixelKey &key ) throw(Exception); |
549.1.34
by Yordan Karadzhov
merge with the trunk |
64 |
|
65 |
string detector() {return _detector;} |
|
66 |
||
67 |
/** This function converts the DAQChannelKey into string.
|
|
68 |
* \return String identifier.
|
|
69 |
*/
|
|
70 |
string str(); |
|
71 |
||
72 |
int station() {return _station;} |
|
73 |
int slabX() {return _slabX;} |
|
74 |
int slabY() {return _slabY;} |
|
75 |
||
76 |
void SetStation(int xStation) {_station = xStation;} |
|
77 |
void SetSlabX(int xSlab) {_slabX = xSlab;} |
|
78 |
void SetSlabY(int xSlab) {_slabY = xSlab;} |
|
79 |
void SetDetector(string xDetector) {_detector = xDetector;} |
|
80 |
||
549.1.56
by Yordan Karadzhov
cpp style corrections |
81 |
/* This function creates unique integer identifier.
|
549.1.34
by Yordan Karadzhov
merge with the trunk |
82 |
* \return Integer identifier.
|
549.1.56
by Yordan Karadzhov
cpp style corrections |
83 |
*
|
84 |
int make_TOFPixelKey_id() {return _station*1e6 + _slabY*1e3 + _slabX;}
|
|
549.1.34
by Yordan Karadzhov
merge with the trunk |
85 |
*/
|
86 |
private: |
|
87 |
||
88 |
/// TOF station number.
|
|
89 |
int _station; |
|
90 |
||
91 |
/** Number of the horizontal Slab. ATTENTION : according to the convention used in
|
|
92 |
* the cabling file the horizontal slabs are always in plane 0.
|
|
93 |
*/
|
|
94 |
int _slabX; |
|
95 |
||
96 |
/** Number of the vertical Slab. ATTENTION : according to the convention used in
|
|
97 |
* the cabling file the vertical slabs are always in plane 1.
|
|
98 |
*/
|
|
99 |
int _slabY; |
|
100 |
||
101 |
/// Name of the detector.
|
|
102 |
string _detector; |
|
103 |
};
|
|
104 |
||
105 |
/** Complete map of all calibration constants needed in order to reconstruct the time
|
|
106 |
* measured by the TOF detectors. This class is used to hold and manage calibration
|
|
107 |
* constants and to calculate the calibration corrections. The algorithm, used to calibrate
|
|
108 |
* the time measurements, is described in MICE Note 251 "TOF Detectors Time Calibration".
|
|
109 |
* http://mice.iit.edu/micenotes/public/pdf/MICE0251/MICE0251.pdf
|
|
110 |
*/
|
|
111 |
class TOFCalibrationMap { |
|
112 |
public: |
|
113 |
||
663.6.170
by Durga Rajaram
tof calibrations and cabling from cdb |
114 |
TOFCalibrationMap(); |
549.1.34
by Yordan Karadzhov
merge with the trunk |
115 |
virtual ~TOFCalibrationMap(); |
116 |
||
117 |
/** Initialize the calibration map by using the text files provided in
|
|
118 |
* ConfigurationDefaults.py
|
|
119 |
* \param[in] json_configuration Json document containing the configuration.
|
|
120 |
* \returns true if all text files are loaded successfully.
|
|
121 |
*/
|
|
122 |
bool InitializeFromCards(Json::Value configJSON); |
|
123 |
||
663.6.170
by Durga Rajaram
tof calibrations and cabling from cdb |
124 |
/// Get calibrations from CDB
|
125 |
bool InitializeFromCDB(); |
|
549.1.34
by Yordan Karadzhov
merge with the trunk |
126 |
|
127 |
/** Initialize the map by using the provided text files.
|
|
128 |
* \param[in] t0File name of the text file containing the t0 calibration constants.
|
|
129 |
* \param[in] twFile name of the text file containing the TimeWalk calibration constants.
|
|
130 |
* \param[in] triggerFile name of the text file containing the trigger delay calibration
|
|
131 |
* constants.
|
|
132 |
* \returns true if all text files are loaded successfully.
|
|
133 |
*/
|
|
134 |
bool Initialize(std::string t0File, std::string twFile, std::string triggerFile); |
|
135 |
||
136 |
/** Return the T0 correction for the channel coded by the key.
|
|
137 |
* \param[in] key the channel of the measurement.
|
|
138 |
* \param[out] r the number of the refference pixel in the slab.
|
|
139 |
* The refference pixel is the pixel where the T0 calibration constant for this channel
|
|
140 |
* has been calculated.
|
|
141 |
* \returns the value of the T0 correction for this channel and sets the number of the
|
|
142 |
* refference pixel. If no calibration for this channel the function returns NOCALIB (-99999).
|
|
143 |
*/
|
|
144 |
double T0(TOFChannelKey key, int &r); |
|
145 |
||
146 |
/** Return the Trigger delay correction for the pixel coded by the key.
|
|
147 |
* \param[in] key the pixel of the hit that gives the trigger.
|
|
148 |
* \returns the value of the trigger delay correction. If no calibration for this pixel the
|
|
149 |
* function returns NOCALIB (-99999).
|
|
150 |
*/
|
|
151 |
double TriggerT0(TOFPixelKey key); |
|
152 |
||
153 |
/** Calculate the TimeWalk correction for the channel coded by the key and for given adc value.
|
|
154 |
* \param[in] key the channel of the measurement.
|
|
155 |
* \param[in] adc the measured value of the amplitude of the signal.
|
|
156 |
* \returns the value of the time-walk correction. If no calibration for this channel the function
|
|
157 |
* returns NOCALIB (-99999).
|
|
158 |
*/
|
|
159 |
double TW(TOFChannelKey key, int adc ); |
|
160 |
||
161 |
/** Calculate the combined correction for the channel coded by Pkey, trigger
|
|
162 |
* pixel coded by the Tkey and for given adc value.
|
|
163 |
* \param[in] Pkey the channel of the measurement.
|
|
164 |
* \param[in] Tkey the pixel of the hit that gives the trigger.
|
|
165 |
* \param[in] adc the measured value of the amplitude of the signal.
|
|
166 |
*/
|
|
167 |
double dT(TOFChannelKey Pkey, TOFPixelKey Tkey, int adc); |
|
168 |
||
169 |
/** Return the data member Name.
|
|
170 |
*/
|
|
171 |
std::string Name() const {return _name;} |
|
172 |
||
173 |
/** Return the data member _triggerStation.
|
|
174 |
*/
|
|
175 |
int TriggerStationNumber() const {return _triggerStation;} |
|
176 |
||
177 |
/** Print the calibration map;
|
|
178 |
* To be used only for debugging.
|
|
179 |
*/
|
|
180 |
void Print(); |
|
663.6.221
by Durga Rajaram
Fix TOF tdc-conversion-factor; better error-handling |
181 |
bool InitializePyMod(); |
663.6.170
by Durga Rajaram
tof calibrations and cabling from cdb |
182 |
void GetCalib(std::string devname, std::string caltype, std::string fromdate); |
549.1.34
by Yordan Karadzhov
merge with the trunk |
183 |
void SetTriggerStation(int station) {_triggerStation = station;} |
184 |
enum { |
|
185 |
/** This value is returned when the correction can not be calculated.
|
|
186 |
*/
|
|
187 |
NOCALIB = -99999 |
|
188 |
};
|
|
189 |
||
190 |
private: |
|
191 |
||
192 |
/** Make one TOFChannelKey for each channel of the detector.
|
|
193 |
* All TOFChannelKeys are held in the data member _Pkey.
|
|
194 |
* ATTENTION : The detector configuration is HARDCODED !!!!
|
|
195 |
* TO BE IMPROVED !!!!
|
|
196 |
*/
|
|
197 |
int MakeTOFChannelKeys(); |
|
198 |
||
199 |
/** Load T0 constants from text file.
|
|
200 |
*/
|
|
201 |
bool LoadT0File(std::string t0File); |
|
202 |
||
203 |
/** Load Trigger delay constants from text file.
|
|
204 |
*/
|
|
205 |
bool LoadTWFile(std::string twFile); |
|
206 |
||
207 |
/** Load TimeWalk constants from text file.
|
|
208 |
*/
|
|
209 |
bool LoadTriggerFile(std::string triggerFile); |
|
210 |
||
211 |
/** Find the position of the PMT key in the data member _Pkey.
|
|
212 |
*/
|
|
213 |
int FindTOFChannelKey(TOFChannelKey key); |
|
214 |
||
215 |
/** Find the position of the trigger key in the data member _Tkey.
|
|
216 |
*/
|
|
217 |
int FindTOFPixelKey(TOFPixelKey key); |
|
218 |
||
219 |
/** This vector holds one TOFChannelKey for each channel of the detector.
|
|
220 |
*/
|
|
221 |
std::vector<TOFChannelKey> _Pkey; |
|
222 |
||
223 |
/** This vector holds the TimeWalk constants. IMPORTANT - the order of the entries
|
|
224 |
* here is the same as the order of the entries in _Pkey.
|
|
225 |
* This is used when the constants are read.
|
|
226 |
*/
|
|
227 |
std::vector< std::vector<double> > _twPar; |
|
228 |
||
229 |
/** This vector holds the T0 constants. IMPORTANT - the order of the entries here is
|
|
230 |
* the same as the order of the entries in _Pkey.
|
|
231 |
* This is used when the constants are read.
|
|
232 |
*/
|
|
233 |
std::vector<double> _t0; |
|
234 |
||
235 |
/** This vector holds the number of the refference bar. IMPORTANT - the order of
|
|
236 |
* the entries here is the same as the order of the entries in _Pkey.
|
|
237 |
* This is used when the constants are read.
|
|
238 |
*/
|
|
239 |
std::vector<int>_reff; |
|
240 |
||
241 |
/** This vector holds one TOFPixelKey for each calibrated pixel of the trigger station.
|
|
242 |
* IMPORTANT - uncalibrated pixels are not presented here.
|
|
243 |
*/
|
|
244 |
std::vector<TOFPixelKey> _Tkey; |
|
245 |
||
246 |
/** This vector holds the Trigger delay constants. IMPORTANT - the order of
|
|
247 |
* the entries here is the same as the order of the entries in _Tkey.
|
|
248 |
* This is used when the constants are read.
|
|
249 |
*/
|
|
250 |
std::vector<double> _Trt0; |
|
251 |
||
252 |
/** Number of the trigger station. It is automatically set during the initialization.
|
|
253 |
*/
|
|
254 |
int _triggerStation; |
|
255 |
||
663.6.170
by Durga Rajaram
tof calibrations and cabling from cdb |
256 |
/** Name of the calibration as in the CDB.
|
549.1.34
by Yordan Karadzhov
merge with the trunk |
257 |
*/
|
258 |
std::string _name; |
|
663.6.170
by Durga Rajaram
tof calibrations and cabling from cdb |
259 |
std::stringstream t0str, twstr, trigstr; |
260 |
std::string _tof_station, _tof_calibdate; |
|
549.1.34
by Yordan Karadzhov
merge with the trunk |
261 |
|
262 |
/** Flags for switching On and Off of the different types of calibration corrections.
|
|
263 |
*/
|
|
264 |
bool _do_timeWalk_correction; |
|
265 |
bool _do_triggerDelay_correction; |
|
266 |
bool _do_t0_correction; |
|
663.6.170
by Durga Rajaram
tof calibrations and cabling from cdb |
267 |
|
268 |
PyObject* _calib_mod; |
|
269 |
PyObject* _tcalib; |
|
270 |
PyObject* _get_calib_func; |
|
271 |
bool LoadT0Calib(); |
|
272 |
bool LoadTWCalib(); |
|
273 |
bool LoadTriggerCalib(); |
|
663.6.221
by Durga Rajaram
Fix TOF tdc-conversion-factor; better error-handling |
274 |
bool pymod_ok; |
549.1.34
by Yordan Karadzhov
merge with the trunk |
275 |
};
|
600.1.151
by Peter Lane
Changed all instances of Squeal to Exception. Compiling reverse merge with trunk. |
276 |
}
|
277 |
||
549.1.34
by Yordan Karadzhov
merge with the trunk |
278 |
#endif
|
279 |
||
280 |