Line data Source code
1 : /**************************************************************************
2 : * This file is property of and copyright by the ALICE HLT Project *
3 : * All rights reserved. *
4 : * *
5 : * Primary Authors: *
6 : * Artur Szostak <artursz@iafrica.com> *
7 : * *
8 : * Permission to use, copy, modify and distribute this software and its *
9 : * documentation strictly for non-commercial purposes is hereby granted *
10 : * without fee, provided that the above copyright notice appears in all *
11 : * copies and that both the copyright notice and this permission notice *
12 : * appear in the supporting documentation. The authors make no claims *
13 : * about the suitability of this software for any purpose. It is *
14 : * provided "as is" without express or implied warranty. *
15 : **************************************************************************/
16 :
17 : // $Id$
18 :
19 : ///
20 : /// @file AliHLTMUONTriggerRecord.cxx
21 : /// @author Artur Szostak <artursz@iafrica.com>
22 : /// @date 29 Sep 2007
23 : /// @brief Implementation of the AliHLTMUONTriggerRecord class.
24 : ///
25 : /// Code for the trigger record structure containing data corresponding to the
26 : /// L0 trigger local board output.
27 : ///
28 :
29 : #include "AliHLTMUONTriggerRecord.h"
30 : #include "AliLog.h"
31 : #include "AliMpDEManager.h"
32 : #include <cstring>
33 : #include <iostream>
34 : #include <iomanip>
35 : using namespace std;
36 :
37 6 : ClassImp(AliHLTMUONTriggerRecord);
38 :
39 :
40 : std::ostream& operator << (
41 : std::ostream& stream,
42 : const AliHLTMUONTriggerRecord& trigrec
43 : )
44 : {
45 : /// Stream operator for std::ostream classes.
46 : /// \param stream The output stream object being written to.
47 : /// \param trigrec The trigger record object to print to the stream.
48 : /// \returns Returns 'stream'.
49 :
50 0 : stream << "ID: " << trigrec.fId
51 0 : << "; sign: " << trigrec.fSign
52 0 : << "; p = (" << trigrec.Px()
53 0 : << ", " << trigrec.Py()
54 0 : << ", " << trigrec.Pz()
55 0 : << ")";
56 0 : return stream;
57 : }
58 :
59 :
60 0 : AliHLTMUONTriggerRecord::AliHLTMUONTriggerRecord(
61 : Int_t id, Int_t sign,
62 : Float_t px, Float_t py, Float_t pz,
63 : Int_t sourceDDL, Float_t zf, Float_t qbl
64 : ) :
65 0 : TObject(),
66 0 : fId(id),
67 0 : fSign(sign),
68 0 : fMomentum(px, py, pz),
69 0 : fSourceDDL(sourceDDL),
70 0 : fZmiddle(zf), fQBL(qbl)
71 0 : {
72 : /// Constructor for creating a new trigger record.
73 : /// @param id The trigger record ID number unique for an event.
74 : /// @param sign The particle's sign. Must be -1, 1 or 0 if the sign is unknown.
75 : /// @param px X component of the particle's momentum.
76 : /// @param py Y component of the particle's momentum.
77 : /// @param pz Z component of the particle's momentum.
78 : /// @param sourceDDL The DDL from which this trigger record originates.
79 : /// @param zf The Z coordinate of the middle of the magnetic field assumed
80 : /// during momentum calculation.
81 : /// @param qbl The integrated magnetic field strength assumed during momentum
82 : /// calculation.
83 :
84 0 : if (sign < -1 or 1 < sign)
85 : {
86 0 : AliError(Form("Trying to set the sign to %d. This is outside the"
87 : " valid range of [-1..1]", sign
88 : ));
89 0 : fSign = 0;
90 0 : }
91 :
92 : // Fill the debugging information to invalid values by default.
93 0 : for (int i = 0; i < 4; i++)
94 : {
95 0 : fDetElemId[i] = -1;
96 0 : for (int j = 0; j < 3; j++)
97 : {
98 0 : fPatternX[i][j] = -1;
99 0 : fPatternY[i][j] = -1;
100 : }
101 : }
102 0 : }
103 :
104 :
105 : const TVector3& AliHLTMUONTriggerRecord::Hit(Int_t chamber) const
106 : {
107 : /// Returns the hit on the specified chamber.
108 : /// \param chamber The chamber for which to fetch the hit. Valid values
109 : /// are in the range [11..14].
110 : /// \returns The 3D corrdinate of the hit.
111 :
112 0 : if (11 <= chamber and chamber <= 14) return fHit[chamber - 11];
113 :
114 0 : AliError(Form(
115 : "Chamber number %d is not in the valid range [11..14].",
116 : int(chamber)
117 : ));
118 0 : return fHit[0];
119 0 : }
120 :
121 :
122 : Int_t AliHLTMUONTriggerRecord::DetElemId(Int_t chamber) const
123 : {
124 : /// Returns the detector element ID for the specified chamber associated
125 : /// to the hit on that chamber.
126 : /// @param chamber The chamber for which to fetch the detector element ID.
127 : /// Valid values are in the range [11..14].
128 : /// \returns The detector element ID or -1 if not known.
129 :
130 0 : if (11 <= chamber and chamber <= 14) return fDetElemId[chamber - 11];
131 :
132 0 : AliError(Form(
133 : "Chamber number %d is not in the valid range [11..14].",
134 : int(chamber)
135 : ));
136 0 : return fDetElemId[0];
137 0 : }
138 :
139 :
140 : Int_t AliHLTMUONTriggerRecord::PatternX(Int_t chamber, Int_t board) const
141 : {
142 : /// Returns the raw data X pattern of the hit on the specified chamber.
143 : /// \param chamber The chamber for which to fetch the bit pattern.
144 : /// Valid values are in the range [11..14].
145 : /// \param board The board for which to fetch the bit pattern in the range [0..2].
146 : /// 0 indicates the previous board, 1 the central and 2 the next board.
147 : /// \returns X bit pattern of the hit.
148 :
149 0 : if (chamber < 11 or 14 < chamber)
150 : {
151 0 : AliError(Form(
152 : "Chamber number %d is not in the valid range [11..14].",
153 : int(chamber)
154 : ));
155 0 : return 0;
156 : }
157 0 : if (board < 0 or 2 < board)
158 : {
159 0 : AliError(Form(
160 : "Board number %d is not in the valid range [0..2].",
161 : int(board)
162 : ));
163 0 : return 0;
164 : }
165 :
166 0 : return fPatternX[chamber - 11][board];
167 0 : }
168 :
169 :
170 : Int_t AliHLTMUONTriggerRecord::PatternY(Int_t chamber, Int_t board) const
171 : {
172 : /// Returns the raw data Y pattern of the hit on the specified chamber.
173 : /// \param chamber The chamber for which to fetch the bit pattern.
174 : /// Valid values are in the range [11..14].
175 : /// \param board The board for which to fetch the bit pattern in the range [0..2].
176 : /// 0 indicates the previous board, 1 the central and 2 the next board.
177 : /// \returns Y bit pattern of the hit.
178 :
179 0 : if (chamber < 11 or 14 < chamber)
180 : {
181 0 : AliError(Form(
182 : "Chamber number %d is not in the valid range [11..14].",
183 : int(chamber)
184 : ));
185 0 : return 0;
186 : }
187 0 : if (board < 0 or 2 < board)
188 : {
189 0 : AliError(Form(
190 : "Board number %d is not in the valid range [0..2].",
191 : int(board)
192 : ));
193 0 : return 0;
194 : }
195 :
196 0 : return fPatternY[chamber - 11][board];
197 0 : }
198 :
199 :
200 : void AliHLTMUONTriggerRecord::SetHit(Int_t chamber, Float_t x, Float_t y, Float_t z)
201 : {
202 : /// Fills the hit coordinate on the specified chamber.
203 : /// @param chamber The chamber for which to set the hit. Valid values
204 : /// are in the range [11..14].
205 : /// @param x The X coordinate of the hit in centimetres.
206 : /// @param y The Y coordinate of the hit in centimetres.
207 : /// @param z The Z coordinate of the hit in centimetres.
208 :
209 0 : if (11 <= chamber and chamber <= 14)
210 : {
211 0 : fHit[chamber - 11].SetXYZ(x, y, z);
212 0 : }
213 : else
214 : {
215 0 : AliError(Form(
216 : "Chamber number %d is not in the valid range [11..14].",
217 : int(chamber)
218 : ));
219 : }
220 0 : }
221 :
222 :
223 : void AliHLTMUONTriggerRecord::SetHit(Int_t chamber, Float_t x, Float_t y, Float_t z, Int_t detElemId)
224 : {
225 : // Sets the hit with the detection element ID.
226 :
227 0 : if (11 <= chamber and chamber <= 14)
228 : {
229 0 : fHit[chamber - 11].SetXYZ(x, y, z);
230 0 : fDetElemId[chamber - 11] = detElemId;
231 0 : }
232 : else
233 : {
234 0 : AliError(Form(
235 : "Chamber number %d is not in the valid range [11..14].",
236 : int(chamber)
237 : ));
238 : }
239 0 : }
240 :
241 :
242 : void AliHLTMUONTriggerRecord::SetHitDebugInfo(
243 : Int_t chamber, UShort_t patternX[3], UShort_t patternY[3]
244 : )
245 : {
246 : /// Fills the debugging information corresponding to the hit on the specified chamber.
247 : /// Sets the debugging information for the hit on the specified chamber.
248 : /// @param chamber The chamber for which to set the debugging information.
249 : /// Valid values are in the range [11..14].
250 : /// @param detElemId The detector element ID.
251 : /// @param patternX The X bit patterns from the local board.
252 : /// @param patternY The Y bit patterns from the local board.
253 :
254 0 : if (11 <= chamber and chamber <= 14)
255 : {
256 0 : for (int i = 0; i < 3; i++)
257 : {
258 0 : fPatternX[chamber - 11][i] = patternX[i];
259 0 : fPatternY[chamber - 11][i] = patternY[i];
260 : }
261 0 : }
262 : else
263 : {
264 0 : AliError(Form(
265 : "Chamber number %d is not in the valid range [11..14].",
266 : int(chamber)
267 : ));
268 : }
269 0 : }
270 :
271 :
272 : void AliHLTMUONTriggerRecord::SetDebugInfo(Float_t zmiddle, Float_t bfieldintegral)
273 : {
274 : // Sets the trigger record debug information.
275 :
276 0 : fZmiddle = zmiddle;
277 0 : fQBL = bfieldintegral;
278 0 : }
279 :
280 :
281 : void AliHLTMUONTriggerRecord::Print(Option_t* option) const
282 : {
283 : /// Prints the trigger record to standard output (screen).
284 : /// \param option Can be one of the following:
285 : /// - "compact" - prints in a compact format.
286 : /// - "detail" - prints track information in a more detailed format.
287 : /// - "all" - prints a full dump of the track object.
288 :
289 : using namespace std;
290 :
291 0 : if ( option == NULL or strcmp(option, "") == 0 or
292 0 : strcmp(option, "compact") == 0
293 : )
294 : {
295 0 : cout << *this << endl;
296 0 : }
297 0 : else if (strcmp(option, "detail") == 0)
298 : {
299 0 : cout << "Trigger record ID = " << fId << "; sign = ";
300 0 : if (fSign != 0)
301 0 : cout << fSign;
302 : else
303 0 : cout << "unknown";
304 0 : cout << "; momentum: (px = " << Px()
305 0 : << " GeV/c, py = " << Py()
306 0 : << " GeV/c, pz = " << Pz()
307 0 : << " GeV/c)" << endl;
308 0 : cout << "Used Zmiddle = " << fZmiddle << " cm and QBL = "
309 0 : << fQBL << " T.m for the momentum calculation." << endl;
310 0 : }
311 0 : else if (strcmp(option, "all") == 0)
312 : {
313 0 : cout << "Trigger record ID = " << fId << "; sign = ";
314 0 : if (fSign != 0)
315 0 : cout << fSign;
316 : else
317 0 : cout << "unknown";
318 0 : cout << "; momentum: (px = " << Px()
319 0 : << " GeV/c, py = " << Py()
320 0 : << " GeV/c, pz = " << Pz()
321 0 : << " GeV/c)" << endl;
322 0 : cout << "Used Zmiddle = " << fZmiddle << " cm and QBL = "
323 0 : << fQBL << " T.m for the momentum calculation." << endl;
324 :
325 0 : streamsize w = cout.width();
326 0 : ios::fmtflags f = cout.flags();
327 0 : cout << setw(9) << "Chamber" << setw(0) << " Hit:"
328 0 : << setw(8) << "X (cm)"
329 0 : << setw(12) << "Y (cm)"
330 0 : << setw(12) << "Z (cm)"
331 0 : << setw(12) << "DetElemID" << endl;
332 0 : for (int i = 0; i < 4; i++)
333 : {
334 0 : cout << setw(9) << i+11;
335 0 : if (fDetElemId[i] != -1)
336 : {
337 0 : cout << setw(14) << fHit[i].X()
338 0 : << setw(12) << fHit[i].Y()
339 0 : << setw(12) << fHit[i].Z()
340 0 : << setw(12) << fDetElemId[i]
341 0 : << endl;
342 0 : }
343 : else
344 : {
345 0 : cout << setw(14) << "-"
346 0 : << setw(12) << "-"
347 0 : << setw(12) << "-"
348 0 : << setw(12) << "-"
349 0 : << endl;
350 : }
351 : }
352 0 : cout << setw(9) << "Chamber"
353 0 : << setw(18+17*2) << "X bit patterns for local boards"
354 0 : << setw(18+17*2) << "Y bit patterns for local boards"
355 0 : << endl;
356 0 : cout << setw(9+18) << "Next"
357 0 : << setw(17) << "Central"
358 0 : << setw(17) << "Previous"
359 0 : << setw(18) << "Next"
360 0 : << setw(17) << "Central"
361 0 : << setw(17) << "Previous"
362 0 : << endl;
363 0 : for (int i = 0; i < 4; i++)
364 : {
365 0 : cout << setw(9) << i+11 << " ";
366 0 : for (int k = 0; k < 3; ++k)
367 : {
368 0 : if (k != 0) cout << "|";
369 0 : if (fPatternX[i][2-k] != -1)
370 : {
371 : // Print the X pattern as a bit pattern.
372 0 : for (Int_t j = 15; j >= 0; j--)
373 0 : cout << (((fPatternX[i][2-k] & (1 << j)) > 0) ? "1" : "0");
374 0 : }
375 : else
376 : {
377 0 : cout << "----------------";
378 : }
379 : }
380 0 : cout << " ";
381 0 : for (int k = 0; k < 3; ++k)
382 : {
383 0 : if (k != 0) cout << "|";
384 0 : if (fPatternY[i][2-k] != -1)
385 : {
386 : // Print the Y pattern as a bit pattern.
387 0 : for (Int_t j = 15; j >= 0; j--)
388 0 : cout << (((fPatternY[i][2-k] & (1 << j)) > 0) ? "1" : "0");
389 0 : }
390 : else
391 : {
392 0 : cout << "----------------";
393 : }
394 : }
395 0 : cout << endl;
396 : }
397 0 : cout.width(w); // reset the field width to previous value.
398 0 : cout.flags(f); // reset the flags to previous values.
399 0 : }
400 : else
401 : {
402 0 : AliError("Unknown option specified. Can only be one of 'compact',"
403 : " 'detail' or 'all'."
404 : );
405 : }
406 0 : }
407 :
408 :
409 : Int_t AliHLTMUONTriggerRecord::Compare(const TObject* obj) const
410 : {
411 : /// We compare this object with 'obj' first by trigger record ID, then
412 : /// by sign and finally by momentum.
413 : /// \param obj This is the object to compare to. It must be of type AliHLTMUONTriggerRecord.
414 : /// \returns -1 if 'this' is smaller than 'obj', 1 if greater and zero if both
415 : /// objects are the same.
416 :
417 0 : if (obj->IsA() == AliHLTMUONTriggerRecord::Class())
418 : {
419 : const AliHLTMUONTriggerRecord* tr =
420 0 : static_cast<const AliHLTMUONTriggerRecord*>(obj);
421 0 : if (fId < tr->fId) return -1;
422 0 : if (fId > tr->fId) return 1;
423 0 : if (fSign < tr->fSign) return -1;
424 0 : if (fSign > tr->fSign) return 1;
425 0 : if (Px() < tr->Px()) return -1;
426 0 : if (Px() > tr->Px()) return 1;
427 0 : if (Py() < tr->Py()) return -1;
428 0 : if (Py() > tr->Py()) return 1;
429 0 : if (Pz() < tr->Pz()) return -1;
430 0 : if (Pz() > tr->Pz()) return 1;
431 0 : return 0;
432 : }
433 : else
434 : {
435 0 : AliError(Form("Do not know how to compare %s to %s.",
436 : this->ClassName(),
437 : obj->ClassName()
438 : ));
439 0 : return -999;
440 : }
441 0 : }
442 :
443 :
444 : bool AliHLTMUONTriggerRecord::operator == (const AliHLTMUONTriggerRecord& trigrec) const
445 : {
446 : /// Compares the trigger record 'trigrec' to this one.
447 : /// \param trigrec The trigger record object to compare to.
448 : /// \returns true if 'this' object is identical to 'trigrec' else false.
449 :
450 0 : return fId == trigrec.fId and fSign == trigrec.fSign
451 0 : and fMomentum == trigrec.fMomentum
452 0 : and fHit[0] == trigrec.fHit[0] and fHit[1] == trigrec.fHit[1]
453 0 : and fHit[2] == trigrec.fHit[2] and fHit[3] == trigrec.fHit[3];
454 : }
|