]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HLT/MUON/AliHLTMUONTrack.cxx
Protection against division by 0
[u/mrichter/AliRoot.git] / HLT / MUON / AliHLTMUONTrack.cxx
CommitLineData
00d81682 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
38ClassImp(AliHLTMUONTrack);
39
40
41std::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
61AliHLTMUONTrack::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}
117
118
119const AliHLTMUONRecHit* AliHLTMUONTrack::Hit(Int_t i) const
120{
121/// Returns the i'th hit.
122/// \param i The number of the hit to return. Must be a value in the range [0..15].
123/// \returns A pointer to the hit object else NULL if it does not exist.
124
125 if (0 <= i and i <= 15) return fHit[i];
126 AliError(Form("Hit index number %d is not in the valid range [0..15].", int(i)));
127 return NULL;
128}
129
130
131const AliHLTMUONRecHit* AliHLTMUONTrack::HitByChamber(Int_t chamber) const
132{
133/// Returns the first hit found for the specified chamber.
134/// \param chamber The chamber to return the hit for. Must be a value in the range [1..14].
135/// \returns A pointer to the hit object else NULL if it does not exist.
136
137 if (not (1 <= chamber and chamber <= 14))
138 {
139 AliError(Form(
140 "Chamber number %d is not in the valid range [1..14].",
141 int(chamber)
142 ));
143 return NULL;
144 }
145
146 const AliHLTMUONRecHit* hit = NULL;
147 for (int i = 0; i < 16; ++i)
148 {
149 if (fHit[i] == NULL) continue;
150 if (fHit[i]->Chamber(false) == chamber)
151 {
152 hit = fHit[i];
153 break;
154 }
155 }
156 return hit;
157}
158
159
160void AliHLTMUONTrack::Print(Option_t* option) const
161{
162/// Prints the track information to standard output (screen).
163/// \param option Can be one of the following:
164/// - "compact" - prints in a compact format.
165/// - "detail" - prints track information in a more detailed format.
166/// - "all" - prints a full dump of the track object.
167
168 using namespace std;
169
170 if ( option == NULL or strcmp(option, "") == 0 or
171 strcmp(option, "compact") == 0
172 )
173 {
174 cout << *this << endl;
175 }
176 else if (strcmp(option, "detail") == 0)
177 {
178 cout << "Track ID = " << fId << "; sign = ";
179 if (fSign != 0)
180 cout << fSign;
181 else
182 cout << "unknown";
183 cout << "; momentum: (px = " << Px()
184 << " GeV/c, py = " << Py()
185 << " GeV/c, pz = " << Pz()
186 << " GeV/c); vertex DCA: (x = " << X()
187 << " cm, y = " << Y()
188 << " cm, z = " << Z()
189 << " cm); chi^2 = " << fChi2 << endl;
190
191 streamsize w = cout.width();
192 ios::fmtflags f = cout.flags();
193 cout << setw(9) << "Hit no."
194 << setw(9) << "Chamber"
195 << setw(0) << " Pos:"
196 << setw(8) << "X (cm)"
197 << setw(12) << "Y (cm)"
198 << setw(12) << "Z (cm)" << endl;
199 for (int i = 0; i < 16; i++)
200 {
201 cout << setw(9) << i;
202 if (fHit[i] != NULL)
203 {
204 cout << setw(9) << fHit[i]->Chamber(false)
205 << setw(14) << fHit[i]->X()
206 << setw(12) << fHit[i]->Y()
207 << setw(12) << fHit[i]->Z();
208 }
209 else
210 {
211 cout << setw(9) << "-"
212 << setw(14) << "-"
213 << setw(12) << "-"
214 << setw(12) << "-";
215 }
216 cout << endl;
217 }
218 cout.width(w); // reset the field width to previous value.
219 cout.flags(f); // reset the flags to previous values.
220 }
221 else if (strcmp(option, "all") == 0)
222 {
223 cout << "Track ID = " << fId << "; sign = ";
224 if (fSign != 0)
225 cout << fSign;
226 else
227 cout << "unknown";
228 cout << "; momentum: (px = " << Px()
229 << " GeV/c, py = " << Py()
230 << " GeV/c, pz = " << Pz()
231 << " GeV/c); vertex DCA: (x = " << X()
232 << " cm, y = " << Y()
233 << " cm, z = " << Z()
234 << " cm); chi^2 = " << fChi2 << endl;
235 cout << "Inverse bending momentum = " << fInverseBendingMomentum
236 << "; non-bending plane slope = " << fThetaX
237 << "; bending plane slope = " << fThetaY << endl;
238
239 streamsize w = cout.width();
240 ios::fmtflags f = cout.flags();
241 cout.width(w); // reset the field width to previous value.
242 cout.flags(f); // reset the flags to previous values.
243
244 for (int i = 0; i < 16; i++)
245 {
246 cout << "======== Hit " << i << " ========" << endl;
247 if (fHit[i] != NULL)
248 fHit[i]->Print("all");
249 else
250 cout << "No hit found." << endl;
251 }
252
253 cout << "===== Trigger Record =====" << endl;
254 if (fTrigRec != NULL)
255 fTrigRec->Print("all");
256 else
257 cout << "No trigger record associated with track." << endl;
258 }
259 else
260 {
261 AliError("Unknown option specified. Can only be one of 'compact',"
262 " 'detail' or 'all'."
263 );
264 }
265}
266
267
268Int_t AliHLTMUONTrack::Compare(const TObject* obj) const
269{
270/// We compare this object with 'obj' first by track ID, then by sign, then
271/// by momentum, then by DCA vertex and finally by chi2.
272/// \param obj This is the object to compare to. It must be of type AliHLTMUONTrack.
273/// \returns -1 if 'this' is smaller than 'obj', 1 if greater and zero if both
274/// objects are the same.
275
276 if (obj->IsA() == AliHLTMUONTrack::Class())
277 {
278 const AliHLTMUONTrack* t =
279 static_cast<const AliHLTMUONTrack*>(obj);
280 if (fId < t->fId) return -1;
281 if (fId > t->fId) return 1;
282 if (fSign < t->fSign) return -1;
283 if (fSign > t->fSign) return 1;
284 if (Px() < t->Px()) return -1;
285 if (Px() > t->Px()) return 1;
286 if (Py() < t->Py()) return -1;
287 if (Py() > t->Py()) return 1;
288 if (Pz() < t->Pz()) return -1;
289 if (Pz() > t->Pz()) return 1;
290 if (X() < t->X()) return -1;
291 if (X() > t->X()) return 1;
292 if (Y() < t->Y()) return -1;
293 if (Y() > t->Y()) return 1;
294 if (Z() < t->Z()) return -1;
295 if (Z() > t->Z()) return 1;
296 if (fChi2 < t->fChi2) return -1;
297 if (fChi2 > t->fChi2) return 1;
298 return 0;
299 }
300 else
301 {
302 AliError(Form("Do not know how to compare %s to %s.",
303 this->ClassName(),
304 obj->ClassName()
305 ));
306 return -999;
307 }
308}
309
310
311bool AliHLTMUONTrack::operator == (const AliHLTMUONTrack& track) const
312{
313/// Comparison operator.
314/// \param track The track object to compare to.
315/// \returns true if 'this' object is identical to 'track' else false.
316
317 bool matched = true;
318 for (int i = 0; i < 16; i++){
319 if(fHit[i] != track.fHit[i])
320 matched = false;
321 }
322
323 return fId == track.fId and fSign == track.fSign
324 and fMomentum == track.fMomentum
325 and fChi2 == track.fChi2 and fTrigRec == track.fTrigRec
326 and matched;
327
328}
329