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