Fixing warnings
[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;
96 fPatternX[i] = -1;
97 fPatternY[i] = -1;
98 }
99}
100
101
102const TVector3& AliHLTMUONTriggerRecord::Hit(Int_t chamber) const
103{
450e0b36 104/// Returns the hit on the specified chamber.
105/// \param chamber The chamber for which to fetch the hit. Valid values
106/// are in the range [11..14].
107/// \returns The 3D corrdinate of the hit.
753896cd 108
109 if (11 <= chamber and chamber <= 14) return fHit[chamber - 11];
110
111 AliError(Form(
112 "Chamber number %d is not in the valid range [11..14].",
113 int(chamber)
114 ));
115 return fHit[0];
116}
117
118
119Int_t AliHLTMUONTriggerRecord::DetElemId(Int_t chamber) const
120{
450e0b36 121/// Returns the detector element ID for the specified chamber associated
122/// to the hit on that chamber.
123/// @param chamber The chamber for which to fetch the detector element ID.
124/// Valid values are in the range [11..14].
125/// \returns The detector element ID or -1 if not known.
753896cd 126
127 if (11 <= chamber and chamber <= 14) return fDetElemId[chamber - 11];
128
129 AliError(Form(
130 "Chamber number %d is not in the valid range [11..14].",
131 int(chamber)
132 ));
133 return fDetElemId[0];
134}
135
136
137Int_t AliHLTMUONTriggerRecord::PatternX(Int_t chamber) const
138{
450e0b36 139/// Returns the raw data X pattern of the hit on the specified chamber.
140/// \param chamber The chamber for which to fetch the bit pattern.
141/// Valid values are in the range [11..14].
142/// \returns X bit pattern of the hit.
753896cd 143
144 if (11 <= chamber and chamber <= 14) return fPatternX[chamber - 11];
145
146 AliError(Form(
147 "Chamber number %d is not in the valid range [11..14].",
148 int(chamber)
149 ));
150 return fPatternX[0];
151}
152
153
154Int_t AliHLTMUONTriggerRecord::PatternY(Int_t chamber) const
155{
450e0b36 156/// Returns the raw data Y pattern of the hit on the specified chamber.
157/// \param chamber The chamber for which to fetch the bit pattern.
158/// Valid values are in the range [11..14].
159/// \returns Y bit pattern of the hit.
753896cd 160
161 if (11 <= chamber and chamber <= 14) return fPatternY[chamber - 11];
162
163 AliError(Form(
164 "Chamber number %d is not in the valid range [11..14].",
165 int(chamber)
166 ));
167 return fPatternY[0];
168}
169
170
171void AliHLTMUONTriggerRecord::SetHit(Int_t chamber, Float_t x, Float_t y, Float_t z)
172{
450e0b36 173/// Fills the hit coordinate on the specified chamber.
174/// @param chamber The chamber for which to set the hit. Valid values
175/// are in the range [11..14].
176/// @param x The X coordinate of the hit in centimetres.
177/// @param y The Y coordinate of the hit in centimetres.
178/// @param z The Z coordinate of the hit in centimetres.
753896cd 179
180 if (11 <= chamber and chamber <= 14)
181 {
182 fHit[chamber - 11].SetXYZ(x, y, z);
183 }
184 else
185 {
186 AliError(Form(
187 "Chamber number %d is not in the valid range [11..14].",
188 int(chamber)
189 ));
190 }
191}
192
193
194void AliHLTMUONTriggerRecord::SetHitDebugInfo(
195 Int_t chamber,
196 Int_t detElemId, UShort_t patternX, UShort_t patternY
197 )
198{
450e0b36 199/// Fills the debugging information corresponding to the hit on the specified chamber.
200/// Sets the debugging information for the hit on the specified chamber.
201/// @param chamber The chamber for which to set the debugging information.
202/// Valid values are in the range [11..14].
203/// @param detElemId The detector element ID.
204/// @param patterX The X bit pattern from the local board.
205/// @param patterY The Y bit pattern from the local board.
753896cd 206
207 if (11 <= chamber and chamber <= 14)
208 {
209 fDetElemId[chamber - 11] = detElemId;
210 fPatternX[chamber - 11] = patternX;
211 fPatternY[chamber - 11] = patternY;
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
223void AliHLTMUONTriggerRecord::Print(Option_t* option) const
224{
450e0b36 225/// Prints the trigger record to standard output (screen).
226/// \param option Can be one of the following:
227/// - "compact" - prints in a compact format.
228/// - "detail" - prints track information in a more detailed format.
229/// - "all" - prints a full dump of the track object.
753896cd 230
450e0b36 231 using namespace std;
232
753896cd 233 if ( option == NULL or strcmp(option, "") == 0 or
234 strcmp(option, "compact") == 0
235 )
236 {
237 cout << *this << endl;
238 }
239 else if (strcmp(option, "detail") == 0)
240 {
241 cout << "Trigger record ID = " << fId << "; sign = ";
242 if (fSign != 0)
243 cout << fSign;
244 else
245 cout << "unknown";
246 cout << "; momentum: (px = " << Px()
247 << " GeV/c, py = " << Py()
248 << " GeV/c, pz = " << Pz()
249 << " GeV/c)" << endl;
250 cout << "Used Zmiddle = " << fZmiddle << " cm and QBL = "
251 << fQBL << " T.m for the momentum calculation." << endl;
252 }
253 else if (strcmp(option, "all") == 0)
254 {
255 cout << "Trigger record ID = " << fId << "; sign = ";
256 if (fSign != 0)
257 cout << fSign;
258 else
259 cout << "unknown";
260 cout << "; momentum: (px = " << Px()
261 << " GeV/c, py = " << Py()
262 << " GeV/c, pz = " << Pz()
263 << " GeV/c)" << endl;
264 cout << "Used Zmiddle = " << fZmiddle << " cm and QBL = "
265 << fQBL << " T.m for the momentum calculation." << endl;
266
267 streamsize w = cout.width();
268 ios::fmtflags f = cout.flags();
269 cout << setw(9) << "Chamber" << setw(0) << " Hit:"
270 << setw(8) << "X (cm)"
271 << setw(12) << "Y (cm)"
272 << setw(12) << "Z (cm)"
273 << setw(12) << "DetElemID"
274 << setw(18) << "X bit pattern"
275 << setw(18) << "Y bit pattern" << endl;
276 for (int i = 0; i < 4; i++)
277 {
278 cout << setw(9) << i+11
279 << setw(14) << fHit[i].X()
280 << setw(12) << fHit[i].Y()
281 << setw(12) << fHit[i].Z()
282 << setw(12) << fDetElemId[i];
283 if (fPatternX[i] != -1)
284 {
285 // Print the X pattern as a bit pattern.
286 cout << " ";
287 for (Int_t j = 15; j >= 0; j--)
288 cout << (((fPatternX[i] & (1 << j)) > 0) ? "1" : "0");
289 }
290 else
291 {
292 cout << " ----------------";
293 }
294 if (fPatternY[i] != -1)
295 {
296 // Print the Y pattern as a bit pattern.
297 cout << " ";
298 for (Int_t j = 15; j >= 0; j--)
299 cout << (((fPatternY[i] & (1 << j)) > 0) ? "1" : "0");
300 }
301 else
302 {
303 cout << " ----------------";
304 }
305 cout << endl;
306 }
307 cout.width(w); // reset the field width to previous value.
308 cout.flags(f); // reset the flags to previous values.
309 }
310 else
311 {
312 AliError("Unknown option specified. Can only be one of 'compact',"
313 " 'detail' or 'all'."
314 );
315 }
316}
317
318
319Int_t AliHLTMUONTriggerRecord::Compare(const TObject* obj) const
320{
450e0b36 321/// We compare this object with 'obj' first by trigger record ID, then
322/// by sign and finally by momentum.
323/// \param obj This is the object to compare to. It must be of type AliHLTMUONTriggerRecord.
324/// \returns -1 if 'this' is smaller than 'obj', 1 if greater and zero if both
325/// objects are the same.
753896cd 326
327 if (obj->IsA() == AliHLTMUONTriggerRecord::Class())
328 {
329 const AliHLTMUONTriggerRecord* tr =
330 static_cast<const AliHLTMUONTriggerRecord*>(obj);
331 if (fId < tr->fId) return -1;
332 if (fId > tr->fId) return 1;
333 if (fSign < tr->fSign) return -1;
334 if (fSign > tr->fSign) return 1;
335 if (Px() < tr->Px()) return -1;
336 if (Px() > tr->Px()) return 1;
337 if (Py() < tr->Py()) return -1;
338 if (Py() > tr->Py()) return 1;
339 if (Pz() < tr->Pz()) return -1;
340 if (Pz() > tr->Pz()) return 1;
341 return 0;
342 }
343 else
344 {
345 AliError(Form("Do not know how to compare %s to %s.",
346 this->ClassName(),
347 obj->ClassName()
348 ));
349 return -999;
350 }
351}
352
353
354bool AliHLTMUONTriggerRecord::operator == (const AliHLTMUONTriggerRecord& trigrec) const
355{
450e0b36 356/// Compares the trigger record 'trigrec' to this one.
357/// \param trigrec The trigger record object to compare to.
358/// \returns true if 'this' object is identical to 'trigrec' else false.
753896cd 359
360 return fId == trigrec.fId and fSign == trigrec.fSign
361 and fMomentum == trigrec.fMomentum
362 and fHit[0] == trigrec.fHit[0] and fHit[1] == trigrec.fHit[1]
363 and fHit[2] == trigrec.fHit[2] and fHit[3] == trigrec.fHit[3];
364}