]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HLT/MUON/AliHLTMUONTrack.cxx
ee0b4f99a2a8ad9e2c58c5f791360c2e988c43a3
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONTrack.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: AliHLTMUONTrack.cxx 37131 2009-11-23 11:08:09Z aszostak $
18
19 ///
20 /// @file   AliHLTMUONTrack.cxx
21 /// @author Indranil Das <indra.ehep@gmail.com> and Artur Szostak <artursz@iafrica.com>
22 /// @date   10 March 2010
23 /// @brief  Implementation of the AliHLTMUONTrack class.
24 ///
25 /// The track class is used to store converted track data from dHLT raw internal
26 /// data blocks as a ROOT object. This allows storing these in ROOT files.
27 ///
28
29 #include "AliHLTMUONTrack.h"
30 #include "AliHLTMUONRecHit.h"
31 #include "AliHLTMUONTriggerRecord.h"
32 #include "AliLog.h"
33 #include "mapping/AliMpDEManager.h"
34 #include <cstring>
35 #include <iostream>
36 #include <iomanip>
37
38 ClassImp(AliHLTMUONTrack);
39
40
41 std::ostream& operator << (
42                 std::ostream& stream,
43                 const AliHLTMUONTrack& track
44         )
45 {
46 /// Stream operator for std::ostream classes.
47 /// \param stream  The output stream object being written to.
48 /// \param track  The track object to print to the stream.
49 /// \returns  the stream object that was written to, <i>stream</i>.
50
51         stream  << "ID: " << track.fId
52                 << "; sign: " << track.fSign
53                 << "; p = (" << track.Px()
54                 << ", " << track.Py()
55                 << ", " << track.Pz()
56                 << "); chi^2: " << track.fChi2;
57         return stream;
58 }
59
60
61 AliHLTMUONTrack::AliHLTMUONTrack(
62                 Int_t id, Int_t sign,
63                 Float_t px, Float_t py, Float_t pz,
64                 Float_t invmom, Float_t thetaX, Float_t thetaY,
65                 Float_t x, Float_t y, Float_t z,
66                 Float_t chi2,
67                 const AliHLTMUONTriggerRecord* trigrec,
68                 const AliHLTMUONRecHit* hits[16]
69         ) :
70         TObject(),
71         fId(id),
72         fSign(sign),
73         fInverseBendingMomentum(invmom),
74         fThetaX(thetaX),
75         fThetaY(thetaY),
76         fMomentum(px, py, pz),
77         fVertexDCA(x, y, z),
78         fChi2(chi2),
79         fTrigRec(trigrec)
80 {
81 /// Default constructor.
82 /// @param id       The track ID number which must be unique for any event.
83 /// @param sign     The particle's sign: -1, 1 or 0 if unknown.
84 /// @param px       X component of the particle's momentum (GeV/c).
85 /// @param py       Y component of the particle's momentum (GeV/c).
86 /// @param pz       Z component of the particle's momentum (GeV/c).
87 /// @param invmom   Inverse bending momentum (GeV/c).
88 /// @param thetaX   The non-bending plane slope of the fitted track.
89 /// @param thetaY   The bending plane slope of the fitted track.
90 /// @param x        X coordinate of the particle's distance of closest
91 ///                 approach (DCA) position (cm).
92 /// @param y        Y coordinate of the particle's DCA position (cm).
93 /// @param z        Z coordinate of the particle's DCA position (cm).
94 /// @param chi2     The chi squared of the track fit.
95 /// @param trigrec  Corresponding trigger record used as a seed to find
96 ///                 this track.
97 /// @param hits     The array of 16 hit coordinates found for the track.
98 ///                 If NULL then then all hit coordinates are set to empty.
99
100         if (sign < -1 or 1 < sign)
101         {
102                 AliError(Form("Trying to set the sign to %d. This is outside the"
103                         " valid range of [-1..1]", sign
104                 ));
105                 fSign = 0;
106         }
107         
108         // Copy individual hit pointers if hits were set.
109         if (hits != NULL)
110         {
111                 for (int i = 0; i < 16; ++i)
112                 {
113                         fHit[i] = hits[i];
114                 }
115         }
116         else
117         {
118                 for (int i = 0; i < 16; ++i)
119                 {
120                         fHit[i] = NULL;
121                 }
122         }
123 }
124
125
126 const AliHLTMUONRecHit* AliHLTMUONTrack::Hit(Int_t i) const
127 {
128 /// Returns the i'th hit.
129 /// \param i  The number of the hit to return. Must be a value in the range [0..15].
130 /// \returns  A pointer to the hit object else NULL if it does not exist.
131
132         if (0 <= i and i <= 15) return fHit[i];
133         AliError(Form("Hit index number %d is not in the valid range [0..15].", int(i)));
134         return NULL;
135 }
136
137
138 const AliHLTMUONRecHit* AliHLTMUONTrack::HitByChamber(Int_t chamber) const
139 {
140 /// Returns the first hit found for the specified chamber.
141 /// \param chamber  The chamber to return the hit for. Must be a value in the range [1..14].
142 /// \returns  A pointer to the hit object else NULL if it does not exist.
143
144         if (not (1 <= chamber and chamber <= 14))
145         {
146                 AliError(Form(
147                         "Chamber number %d is not in the valid range [1..14].",
148                         int(chamber)
149                 ));
150                 return NULL;
151         }
152         
153         const AliHLTMUONRecHit* hit = NULL;
154         for (int i = 0; i < 16; ++i)
155         {
156                 if (fHit[i] == NULL) continue;
157                 if (fHit[i]->Chamber(false) == chamber)
158                 {
159                         hit = fHit[i];
160                         break;
161                 }
162         }
163         return hit;
164 }
165
166
167 void AliHLTMUONTrack::Print(Option_t* option) const
168 {
169 /// Prints the track information to standard output (screen).
170 /// \param option  Can be one of the following:
171 ///           - "compact" - prints in a compact format.
172 ///           - "detail" - prints track information in a more detailed format.
173 ///           - "all" - prints a full dump of the track object.
174
175         using namespace std;
176         
177         if (    option == NULL or strcmp(option, "") == 0 or
178                 strcmp(option, "compact") == 0
179            )
180         {
181                 cout << *this << endl;
182         }
183         else if (strcmp(option, "detail") == 0)
184         {
185                 cout << "Track ID = " << fId << "; sign = ";
186                 if (fSign != 0)
187                         cout << fSign;
188                 else
189                         cout << "unknown";
190                 cout << "; momentum: (px = " << Px()
191                         << " GeV/c, py = " << Py()
192                         << " GeV/c, pz = " << Pz()
193                         << " GeV/c); vertex DCA: (x = " << X()
194                         << " cm, y = " << Y()
195                         << " cm, z = " << Z()
196                         << " cm); chi^2 = " << fChi2 << endl;
197                 
198                 streamsize w = cout.width();
199                 ios::fmtflags f = cout.flags();
200                 cout << setw(9) << "Hit no."
201                         << setw(9) << "Chamber"
202                         << setw(0) << "  Pos:"
203                         << setw(8) << "X (cm)"
204                         << setw(12) << "Y (cm)"
205                         << setw(12) << "Z (cm)" << endl;
206                 for (int i = 0; i < 16; i++)
207                 {
208                         cout << setw(9) << i;
209                         if (fHit[i] != NULL)
210                         {
211                                 cout << setw(9) << fHit[i]->Chamber(false)
212                                         << setw(14) << fHit[i]->X()
213                                         << setw(12) << fHit[i]->Y()
214                                         << setw(12) << fHit[i]->Z();
215                         }
216                         else
217                         {
218                                 cout << setw(9) << "-"
219                                         << setw(14) << "-"
220                                         << setw(12) << "-"
221                                         << setw(12) << "-";
222                         }
223                         cout << endl;
224                 }
225                 cout.width(w); // reset the field width to previous value.
226                 cout.flags(f); // reset the flags to previous values.
227         }
228         else if (strcmp(option, "all") == 0)
229         {
230                 cout << "Track ID = " << fId << "; sign = ";
231                 if (fSign != 0)
232                         cout << fSign;
233                 else
234                         cout << "unknown";
235                 cout << "; momentum: (px = " << Px()
236                         << " GeV/c, py = " << Py()
237                         << " GeV/c, pz = " << Pz()
238                         << " GeV/c); vertex DCA: (x = " << X()
239                         << " cm, y = " << Y()
240                         << " cm, z = " << Z()
241                         << " cm); chi^2 = " << fChi2 << endl;
242                 cout << "Inverse bending momentum = " << fInverseBendingMomentum
243                         << "; non-bending plane slope = " << fThetaX
244                         << "; bending plane slope = " << fThetaY << endl;
245                 
246                 streamsize w = cout.width();
247                 ios::fmtflags f = cout.flags();
248                 cout.width(w); // reset the field width to previous value.
249                 cout.flags(f); // reset the flags to previous values.
250                 
251                 for (int i = 0; i < 16; i++)
252                 {
253                         cout << "======== Hit " << i << " ========" << endl;
254                         if (fHit[i] != NULL)
255                                 fHit[i]->Print("all");
256                         else
257                                 cout << "No hit found." << endl;
258                 }
259                 
260                 cout << "===== Trigger Record =====" << endl;
261                 if (fTrigRec != NULL)
262                         fTrigRec->Print("all");
263                 else
264                         cout << "No trigger record associated with track." << endl;
265         }
266         else
267         {
268                 AliError("Unknown option specified. Can only be one of 'compact',"
269                         " 'detail' or 'all'."
270                 );
271         }
272 }
273
274
275 Int_t AliHLTMUONTrack::Compare(const TObject* obj) const
276 {
277 /// We compare this object with 'obj' first by track ID, then by sign, then
278 /// by momentum, then by DCA vertex and finally by chi2.
279 /// \param obj  This is the object to compare to. It must be of type AliHLTMUONTrack.
280 /// \returns  -1 if 'this' is smaller than 'obj', 1 if greater and zero if both
281 ///      objects are the same.
282
283         if (obj->IsA() == AliHLTMUONTrack::Class())
284         {
285                 const AliHLTMUONTrack* t =
286                         static_cast<const AliHLTMUONTrack*>(obj);
287                 if (fId < t->fId) return -1;
288                 if (fId > t->fId) return 1;
289                 if (fSign < t->fSign) return -1;
290                 if (fSign > t->fSign) return 1;
291                 if (Px() < t->Px()) return -1;
292                 if (Px() > t->Px()) return 1;
293                 if (Py() < t->Py()) return -1;
294                 if (Py() > t->Py()) return 1;
295                 if (Pz() < t->Pz()) return -1;
296                 if (Pz() > t->Pz()) return 1;
297                 if (X() < t->X()) return -1;
298                 if (X() > t->X()) return 1;
299                 if (Y() < t->Y()) return -1;
300                 if (Y() > t->Y()) return 1;
301                 if (Z() < t->Z()) return -1;
302                 if (Z() > t->Z()) return 1;
303                 if (fChi2 < t->fChi2) return -1;
304                 if (fChi2 > t->fChi2) return 1;
305                 return 0;
306         }
307         else
308         {
309                 AliError(Form("Do not know how to compare %s to %s.",
310                         this->ClassName(),
311                         obj->ClassName()
312                 ));
313                 return -999;
314         }
315 }
316
317
318 bool AliHLTMUONTrack::operator == (const AliHLTMUONTrack& track) const
319 {
320 /// Comparison operator.
321 /// \param track  The track object to compare to.
322 /// \returns  true if 'this' object is identical to 'track' else false.
323
324         for (int i = 0; i < 16; i++)
325         {
326                 if (fHit[i] != track.fHit[i]) return false;
327         }
328         
329         return  fId == track.fId and fSign == track.fSign
330                 and fInverseBendingMomentum == track.fInverseBendingMomentum
331                 and fThetaX == track.fThetaX and fThetaY == track.fThetaY
332                 and fMomentum == track.fMomentum and fVertexDCA == track.fVertexDCA
333                 and fChi2 == track.fChi2 and fTrigRec == track.fTrigRec;
334 }