]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/AliHLTMUONTriggerRecord.cxx
Changing to using char** rather than const char** for main() due to coverty warning.
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONTriggerRecord.cxx
CommitLineData
753896cd 1/**************************************************************************
1d8ae082 2 * This file is property of and copyright by the ALICE HLT Project *
753896cd 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 *
1d8ae082 13 * about the suitability of this software for any purpose. It is *
753896cd 14 * provided "as is" without express or implied warranty. *
15 **************************************************************************/
16
1d8ae082 17// $Id$
753896cd 18
450e0b36 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///
753896cd 28
29#include "AliHLTMUONTriggerRecord.h"
30#include "AliLog.h"
31#include "mapping/AliMpDEManager.h"
32#include <cstring>
33#include <iostream>
34#include <iomanip>
35using namespace std;
36
37ClassImp(AliHLTMUONTriggerRecord);
38
39
40std::ostream& operator << (
41 std::ostream& stream,
42 const AliHLTMUONTriggerRecord& trigrec
43 )
44{
450e0b36 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'.
753896cd 49
50 stream << "ID: " << trigrec.fId
51 << "; sign: " << trigrec.fSign
52 << "; p = (" << trigrec.Px()
53 << ", " << trigrec.Py()
54 << ", " << trigrec.Pz()
55 << ")";
56 return stream;
57}
58
59
60AliHLTMUONTriggerRecord::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 ) :
92aebaf3 65 TObject(),
66 fId(id),
67 fSign(sign),
68 fMomentum(px, py, pz),
69 fSourceDDL(sourceDDL),
753896cd 70 fZmiddle(zf), fQBL(qbl)
71{
450e0b36 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
753896cd 84 if (sign < -1 or 1 < sign)
85 {
86 AliError(Form("Trying to set the sign to %d. This is outside the"
87 " valid range of [-1..1]", sign
88 ));
89 fSign = 0;
90 }
91
92 // Fill the debugging information to invalid values by default.
93 for (int i = 0; i < 4; i++)
94 {
95 fDetElemId[i] = -1;
462e3880 96 for (int j = 0; j < 3; j++)
97 {
98 fPatternX[i][j] = -1;
99 fPatternY[i][j] = -1;
100 }
753896cd 101 }
102}
103
104
105const TVector3& AliHLTMUONTriggerRecord::Hit(Int_t chamber) const
106{
450e0b36 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.
753896cd 111
112 if (11 <= chamber and chamber <= 14) return fHit[chamber - 11];
113
114 AliError(Form(
115 "Chamber number %d is not in the valid range [11..14].",
116 int(chamber)
117 ));
118 return fHit[0];
119}
120
121
122Int_t AliHLTMUONTriggerRecord::DetElemId(Int_t chamber) const
123{
450e0b36 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.
753896cd 129
130 if (11 <= chamber and chamber <= 14) return fDetElemId[chamber - 11];
131
132 AliError(Form(
133 "Chamber number %d is not in the valid range [11..14].",
134 int(chamber)
135 ));
136 return fDetElemId[0];
137}
138
139
462e3880 140Int_t AliHLTMUONTriggerRecord::PatternX(Int_t chamber, Int_t board) const
753896cd 141{
450e0b36 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].
462e3880 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.
450e0b36 147/// \returns X bit pattern of the hit.
753896cd 148
462e3880 149 if (chamber < 11 or 14 < chamber)
150 {
151 AliError(Form(
152 "Chamber number %d is not in the valid range [11..14].",
153 int(chamber)
154 ));
155 return 0;
156 }
157 if (board < 0 or 2 < board)
158 {
159 AliError(Form(
160 "Board number %d is not in the valid range [0..2].",
161 int(board)
162 ));
163 return 0;
164 }
753896cd 165
462e3880 166 return fPatternX[chamber - 11][board];
753896cd 167}
168
169
462e3880 170Int_t AliHLTMUONTriggerRecord::PatternY(Int_t chamber, Int_t board) const
753896cd 171{
450e0b36 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].
462e3880 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.
450e0b36 177/// \returns Y bit pattern of the hit.
753896cd 178
462e3880 179 if (chamber < 11 or 14 < chamber)
180 {
181 AliError(Form(
182 "Chamber number %d is not in the valid range [11..14].",
183 int(chamber)
184 ));
185 return 0;
186 }
187 if (board < 0 or 2 < board)
188 {
189 AliError(Form(
190 "Board number %d is not in the valid range [0..2].",
191 int(board)
192 ));
193 return 0;
194 }
753896cd 195
462e3880 196 return fPatternY[chamber - 11][board];
753896cd 197}
198
199
200void AliHLTMUONTriggerRecord::SetHit(Int_t chamber, Float_t x, Float_t y, Float_t z)
201{
450e0b36 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.
753896cd 208
209 if (11 <= chamber and chamber <= 14)
210 {
211 fHit[chamber - 11].SetXYZ(x, y, z);
212 }
213 else
214 {
215 AliError(Form(
216 "Chamber number %d is not in the valid range [11..14].",
217 int(chamber)
218 ));
219 }
220}
221
222
462e3880 223void 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 if (11 <= chamber and chamber <= 14)
228 {
229 fHit[chamber - 11].SetXYZ(x, y, z);
230 fDetElemId[chamber - 11] = detElemId;
231 }
232 else
233 {
234 AliError(Form(
235 "Chamber number %d is not in the valid range [11..14].",
236 int(chamber)
237 ));
238 }
239}
240
241
753896cd 242void AliHLTMUONTriggerRecord::SetHitDebugInfo(
462e3880 243 Int_t chamber, UShort_t patternX[3], UShort_t patternY[3]
753896cd 244 )
245{
450e0b36 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.
462e3880 251/// @param patternX The X bit patterns from the local board.
252/// @param patternY The Y bit patterns from the local board.
753896cd 253
254 if (11 <= chamber and chamber <= 14)
255 {
462e3880 256 for (int i = 0; i < 3; i++)
257 {
258 fPatternX[chamber - 11][i] = patternX[i];
259 fPatternY[chamber - 11][i] = patternY[i];
260 }
753896cd 261 }
262 else
263 {
264 AliError(Form(
265 "Chamber number %d is not in the valid range [11..14].",
266 int(chamber)
267 ));
268 }
269}
270
271
462e3880 272void AliHLTMUONTriggerRecord::SetDebugInfo(Float_t zmiddle, Float_t bfieldintegral)
273{
274 // Sets the trigger record debug information.
275
276 fZmiddle = zmiddle;
277 fQBL = bfieldintegral;
278}
279
280
753896cd 281void AliHLTMUONTriggerRecord::Print(Option_t* option) const
282{
450e0b36 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.
753896cd 288
450e0b36 289 using namespace std;
290
753896cd 291 if ( option == NULL or strcmp(option, "") == 0 or
292 strcmp(option, "compact") == 0
293 )
294 {
295 cout << *this << endl;
296 }
297 else if (strcmp(option, "detail") == 0)
298 {
299 cout << "Trigger record ID = " << fId << "; sign = ";
300 if (fSign != 0)
301 cout << fSign;
302 else
303 cout << "unknown";
304 cout << "; momentum: (px = " << Px()
305 << " GeV/c, py = " << Py()
306 << " GeV/c, pz = " << Pz()
307 << " GeV/c)" << endl;
308 cout << "Used Zmiddle = " << fZmiddle << " cm and QBL = "
309 << fQBL << " T.m for the momentum calculation." << endl;
310 }
311 else if (strcmp(option, "all") == 0)
312 {
313 cout << "Trigger record ID = " << fId << "; sign = ";
314 if (fSign != 0)
315 cout << fSign;
316 else
317 cout << "unknown";
318 cout << "; momentum: (px = " << Px()
319 << " GeV/c, py = " << Py()
320 << " GeV/c, pz = " << Pz()
321 << " GeV/c)" << endl;
322 cout << "Used Zmiddle = " << fZmiddle << " cm and QBL = "
323 << fQBL << " T.m for the momentum calculation." << endl;
324
325 streamsize w = cout.width();
326 ios::fmtflags f = cout.flags();
327 cout << setw(9) << "Chamber" << setw(0) << " Hit:"
328 << setw(8) << "X (cm)"
329 << setw(12) << "Y (cm)"
330 << setw(12) << "Z (cm)"
462e3880 331 << setw(12) << "DetElemID" << endl;
753896cd 332 for (int i = 0; i < 4; i++)
333 {
bc5cb6d6 334 cout << setw(9) << i+11;
335 if (fDetElemId[i] != -1)
336 {
337 cout << setw(14) << fHit[i].X()
338 << setw(12) << fHit[i].Y()
339 << setw(12) << fHit[i].Z()
340 << setw(12) << fDetElemId[i]
341 << endl;
342 }
343 else
344 {
345 cout << setw(14) << "-"
346 << setw(12) << "-"
347 << setw(12) << "-"
348 << setw(12) << "-"
349 << endl;
350 }
462e3880 351 }
352 cout << setw(9) << "Chamber"
353 << setw(18+17*2) << "X bit patterns for local boards"
354 << setw(18+17*2) << "Y bit patterns for local boards"
355 << endl;
356 cout << setw(9+18) << "Next"
357 << setw(17) << "Central"
358 << setw(17) << "Previous"
359 << setw(18) << "Next"
360 << setw(17) << "Central"
361 << setw(17) << "Previous"
362 << endl;
363 for (int i = 0; i < 4; i++)
364 {
365 cout << setw(9) << i+11 << " ";
366 for (int k = 0; k < 3; ++k)
753896cd 367 {
462e3880 368 if (k != 0) cout << "|";
369 if (fPatternX[i][2-k] != -1)
370 {
371 // Print the X pattern as a bit pattern.
372 for (Int_t j = 15; j >= 0; j--)
373 cout << (((fPatternX[i][2-k] & (1 << j)) > 0) ? "1" : "0");
374 }
375 else
376 {
377 cout << "----------------";
378 }
753896cd 379 }
462e3880 380 cout << " ";
381 for (int k = 0; k < 3; ++k)
753896cd 382 {
462e3880 383 if (k != 0) cout << "|";
384 if (fPatternY[i][2-k] != -1)
385 {
386 // Print the Y pattern as a bit pattern.
387 for (Int_t j = 15; j >= 0; j--)
388 cout << (((fPatternY[i][2-k] & (1 << j)) > 0) ? "1" : "0");
389 }
390 else
391 {
392 cout << "----------------";
393 }
753896cd 394 }
395 cout << endl;
396 }
397 cout.width(w); // reset the field width to previous value.
398 cout.flags(f); // reset the flags to previous values.
399 }
400 else
401 {
402 AliError("Unknown option specified. Can only be one of 'compact',"
403 " 'detail' or 'all'."
404 );
405 }
406}
407
408
409Int_t AliHLTMUONTriggerRecord::Compare(const TObject* obj) const
410{
450e0b36 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.
753896cd 416
417 if (obj->IsA() == AliHLTMUONTriggerRecord::Class())
418 {
419 const AliHLTMUONTriggerRecord* tr =
420 static_cast<const AliHLTMUONTriggerRecord*>(obj);
421 if (fId < tr->fId) return -1;
422 if (fId > tr->fId) return 1;
423 if (fSign < tr->fSign) return -1;
424 if (fSign > tr->fSign) return 1;
425 if (Px() < tr->Px()) return -1;
426 if (Px() > tr->Px()) return 1;
427 if (Py() < tr->Py()) return -1;
428 if (Py() > tr->Py()) return 1;
429 if (Pz() < tr->Pz()) return -1;
430 if (Pz() > tr->Pz()) return 1;
431 return 0;
432 }
433 else
434 {
435 AliError(Form("Do not know how to compare %s to %s.",
436 this->ClassName(),
437 obj->ClassName()
438 ));
439 return -999;
440 }
441}
442
443
444bool AliHLTMUONTriggerRecord::operator == (const AliHLTMUONTriggerRecord& trigrec) const
445{
450e0b36 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.
753896cd 449
450 return fId == trigrec.fId and fSign == trigrec.fSign
451 and fMomentum == trigrec.fMomentum
452 and fHit[0] == trigrec.fHit[0] and fHit[1] == trigrec.fHit[1]
453 and fHit[2] == trigrec.fHit[2] and fHit[3] == trigrec.fHit[3];
454}