Fixes to calls for MeanMaterialBudget (now in AliTracker) (From Jouri Belikov)
[u/mrichter/AliRoot.git] / EMCAL / AliEMCALTrack.cxx
CommitLineData
fe17d4cb 1//========================================================================
2// Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved.
3//
4// Author: The ALICE Off-line Project.
5// Contributors are mentioned in the code where appropriate.
6//
7// Permission to use, copy, modify and distribute this software and its
8// documentation strictly for non-commercial purposes is hereby granted
9// without fee, provided that the above copyright notice appears in all
10// copies and that both the copyright notice and this permission notice
11// appear in the supporting documentation. The authors make no claims
12// about the suitability of this software for any purpose. It is
13// provided "as is" without express or implied warranty.
14//========================================================================
15//
16// Class AliEMCALTrack
17// ---------------------
18// A class implementing a track which is propagated to EMCAL and
19// matches and EMCAL cluster.
20// This track object will not update Kalman parameters, but it
21// allows for track propagation and suitable energy loss correction,
22// even in an environment with a variable magnetic field, which is not
23// well managed in the AliExternalTrackParam class.
24// ------------------------------------------------------------------------
25// author: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
26//=========================================================================
27
28#include "Riostream.h"
29
c61f0e70 30#include "TVector3.h"
31
fe17d4cb 32#include "AliLog.h"
33#include "AliTracker.h"
34#include "AliESDtrack.h"
35
36#include "AliEMCALTrack.h"
37
38Bool_t AliEMCALTrack::fgUseOuterParams = kTRUE;
c61f0e70 39Bool_t AliEMCALTrack::fgCorrectForEL = kFALSE;
40Bool_t AliEMCALTrack::fgSortByPt = kTRUE;
fe17d4cb 41
42ClassImp(AliEMCALTrack)
43//
44//------------------------------------------------------------------------------
45//
46AliEMCALTrack::AliEMCALTrack()
47 : AliExternalTrackParam(),
48 fClusterIndex(-1),
c61f0e70 49 fClusterDist(1000.0), // default: extremely large distance
50 fMass(0.13957018), // default: pion mass
fe17d4cb 51 fSeedIndex(-1),
52 fSeedLabel(-1)
53{
54 //
55 // Default constructor.
56 // Sets to meaningless values the indexes corresponding to
57 // ESD seed track and matched cluster.
58 //
59}
60//
61//------------------------------------------------------------------------------
62//
fe17d4cb 63AliEMCALTrack::AliEMCALTrack(const AliESDtrack& t)
64 : AliExternalTrackParam(),
65 fClusterIndex(-1),
66 fClusterDist(1000.0),
67 fMass(t.GetMass()),
68 fSeedIndex(-1),
69 fSeedLabel(t.GetLabel())
70{
71 //
72 // Constructor from AliESDtrack
73 //
74
75 // parameters are chosen according to static variable fUseOuterParams
76 Double_t alpha, x, params[5], cov[15];
77 if (fgUseOuterParams) {
78 t.GetOuterExternalParameters(alpha, x, params);
79 t.GetOuterExternalCovariance(cov);
80 }
81 else {
82 alpha = t.GetAlpha();
83 t.GetExternalParameters(x, params);
84 t.GetExternalCovariance(cov);
85 }
86
87 if (alpha < -TMath::Pi()) alpha += TMath::TwoPi();
88 else if (alpha >= TMath::Pi()) alpha -= TMath::TwoPi();
89
90 // set this accordingly
91 Set(x, alpha, params, cov);
c61f0e70 92}
93//
94//------------------------------------------------------------------------------
95//
96AliEMCALTrack::AliEMCALTrack(const AliEMCALTrack& t)
97 : AliExternalTrackParam(t),
98 fClusterIndex(t.fClusterIndex),
99 fClusterDist(t.fClusterDist),
100 fMass(t.fMass),
101 fSeedIndex(t.fSeedIndex),
102 fSeedLabel(t.fSeedLabel)
103{
104 //
105 // Copy constructor.
106 //
107}
fe17d4cb 108//
109//------------------------------------------------------------------------------
110//
111AliEMCALTrack& AliEMCALTrack::operator=(const AliEMCALTrack &t)
112{
113 //
114 // Assignment operator
115 // Works like copy constructor
116 //
117
118 fClusterIndex = t.fClusterIndex;
119 fClusterDist = t.fClusterDist;
120
121 fMass = t.fMass;
122
123 fSeedIndex = t.fSeedIndex;
124 fSeedLabel = t.fSeedLabel;
125
126 return *this;
127}
128//
129//------------------------------------------------------------------------------
130//
131Int_t AliEMCALTrack::Compare(const TObject *obj) const
132{
133 //
c61f0e70 134 // Compare tracks.
135 // How tracks are compared depends on the static flag
136 // "fSortByPt" (boolean):
137 // true => tracks are compared w.r. to their transverse momentum
138 // false => tracks are compared w.r. to their distance from cluster
fe17d4cb 139 //
140
141 AliEMCALTrack *that = (AliEMCALTrack*)obj;
142
c61f0e70 143 Double_t thisP[3], thisVal, thatP[3], thatVal;
144
145 if (fgSortByPt) {
146 this->GetPxPyPz(thisP);
147 that->GetPxPyPz(thatP);
148 thisVal = TMath::Sqrt(thisP[0]*thisP[0] + thisP[1]*thisP[1]);
149 thatVal = TMath::Sqrt(thatP[0]*thatP[0] + thatP[1]*thatP[1]);
150 }
151 else {
152 thisVal = this->GetClusterDist();
153 thatVal = that->GetClusterDist();
154 }
fe17d4cb 155
c61f0e70 156 if (thisVal > thatVal) return 1;
157 else if (thisVal < thatVal) return -1;
158 else return 0;
fe17d4cb 159}
160//
161//------------------------------------------------------------------------------
162//
163Double_t AliEMCALTrack::GetBz() const
164{
165 //
c61f0e70 166 // Returns Z-component of the magnetic field in kG.
167 // In case it B is not constant, its value is returned
168 // at the current position of the track (local X,Y,Z)
fe17d4cb 169 //
170
c61f0e70 171 // if magnetic field is constant...
172 if (AliTracker::UniformField()) return AliTracker::GetBz();
fe17d4cb 173
c61f0e70 174 // ...else:
175 Double_t r[3];
176 GetXYZ(r);
177 return AliTracker::GetBz(r);
fe17d4cb 178}
179//
180//------------------------------------------------------------------------------
181//
c61f0e70 182Bool_t AliEMCALTrack::PropagateTo(Double_t xk, Double_t d, Double_t x0)
fe17d4cb 183{
184 //
185 // Propagates a track to the plane defined by x='xk'.
c61f0e70 186 // Second parameter is the width (in units of rad. length) crossed by the track.
187 // Third parameter is the reference radiation length used.
fe17d4cb 188 // Track propagation includes computing energy loss (modifies curvature)
c61f0e70 189 // and multiple scattering perturbation (alters covariance matrix), if requested.
fe17d4cb 190 // Method returns kFALSE when something goes wrong with computations.
191 //
c61f0e70 192 // An additional operation (thanks to Yuri Belikov) is done to check
193 // when the track crosses a sector boundary. If this happens,
194 // the local track reference frame is adjusted accordingly.
195 //
196
197 Double_t y;
198 Double_t field = GetBz();
199 Double_t width = TMath::Pi() / 9.0; // width of TPC/TRD/EMCAL sector (= 20 deg)
200 Double_t ymax = TMath::Abs(xk * TMath::Tan(0.5 * width)); // max allowed Y in local coords at distance xk
201
202 // first check: try to compute the local 'y' at the distance 'xk':
203 // if this attempt fails, the propagation cannot be done
204 if (!GetYAt(xk, field, y)) return kFALSE;
205
206 // if is -ymax < y < ymax ==> 'direct' propagation is done;
207 if (TMath::Abs(y) <= ymax) return SimplePropagation(xk, d, x0);
208
209 // otherwise, try change a sector to find one where the propagation is ok
210 Int_t i, incr, istart, nloops;
211 Double_t alpha = GetAlpha();
212 incr = (y > ymax) ? 1 : -1;
213 if (alpha < 0.0) alpha += TMath::TwoPi();
214 istart = (Int_t)(alpha / width);
215 for (i = istart, nloops = 0; nloops < 18; i += incr, nloops++) {
216 if (i == 18) i = 0;
217 if (i == -1) i = 17;
218 alpha = ((Double_t)i + 0.5) * width;
219 if (Rotate(alpha)) {
220 if (GetYAt(xk, field, y)) {
221 if (TMath::Abs(y) <= ymax) {
b0001dd8 222 AliDebug(1,Form("Required change from sector %d to sector %d to succeed in propagation", istart, i));
c61f0e70 223 return SimplePropagation(xk, d, x0);
224 }
225 }
226 }
227 }
228
229 // if the routine exits from the loop and reaches this point,
230 // it means that none of the rotations succeeded
231 AliWarning("Track propagation fails in every sector. Impossible to propagate.");
232 return kFALSE;
233}
234//
235//------------------------------------------------------------------------------
236//
237Double_t AliEMCALTrack::StraightPropagateTo(Double_t xk, Double_t &x, Double_t &y, Double_t &z)
238{
239 //
240 // Does propagation with a straight line approximation.
241 // This operation does not update track parameters, but it returns a point
242 // in space, according to this propagation, which is stored in
243 // the arguments #2, #3 and #4
244 //
245
246 Double_t oldX = GetX(), oldY = GetY(), oldZ = GetZ();
247 Double_t newPos[3];
248
249 newPos[0] = xk;
250 newPos[1] = oldY * xk / oldX;
251 newPos[2] = oldZ * xk / oldX;
252
253 Double_t cs = TMath::Cos(GetAlpha()), sn = TMath::Sin(GetAlpha());
254 x = newPos[0]*cs - newPos[1]*sn;
255 y = newPos[0]*sn + newPos[1]*cs;
256 z = newPos[2];
257
258 return newPos[1];
259}
260//
261//------------------------------------------------------------------------------
262//
263Bool_t AliEMCALTrack::PropagateToGlobal(Double_t x, Double_t y, Double_t z, Double_t d, Double_t x0)
264{
265 //
266 // Propagate to a point specified with its global XYZ coordinates.
267 // Here, the correct value of the 'X' parameter to be sent to "PropagateTo" is computed.
268 //
269
270 TVector3 vc(x, y, z);
271 Double_t width = 20.0; // width of TPC/TRD/EMCAL sector
272 Double_t phi = vc.Phi() * TMath::RadToDeg();
273 if (phi < 0.0) phi += 360.0;
274
275 Int_t isector = (Int_t)(phi / width);
276 Double_t rotation = ((Double_t)isector + 0.5) * width;
69d7454f 277 vc.RotateZ(-rotation * TMath::DegToRad());
c61f0e70 278
279 return PropagateTo(vc.X(), d, x0);
280}
281//
282//------------------------------------------------------------------------------
283//
284Bool_t AliEMCALTrack::SimplePropagation(Double_t xk, Double_t d, Double_t x0)
285{
286 //
287 // Recall base class method for track propagation.
288 //
fe17d4cb 289
290 Double_t field = GetBz();
291
c61f0e70 292 // propagation...
fe17d4cb 293 if (!AliExternalTrackParam::PropagateTo(xk, field)) return kFALSE;
c61f0e70 294
295 // EL correction is computed only if requested...
296 if (!fgCorrectForEL) return kTRUE;
c3c15772 297 return AliExternalTrackParam::CorrectForMeanMaterial(d, x0, GetMass());
c61f0e70 298}