ROOT logo
//========================================================================
// Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. 
//                                                                        
// Author: The ALICE Off-line Project.                                    
// Contributors are mentioned in the code where appropriate.              
//                                                                        
// Permission to use, copy, modify and distribute this software and its   
// documentation strictly for non-commercial purposes is hereby granted   
// without fee, provided that the above copyright notice appears in all   
// copies and that both the copyright notice and this permission notice   
// appear in the supporting documentation. The authors make no claims     
// about the suitability of this software for any purpose. It is          
// provided "as is" without express or implied warranty.                  
//========================================================================  
//                        
//                       Class AliEMCALTrack 
//                      ---------------------
//    A class implementing a track which is propagated to EMCAL and 
//    matches and EMCAL cluster. 
//    This track object will not update Kalman parameters, but it 
//    allows for track propagation and suitable energy loss correction,
//    even in an environment with a variable magnetic field, which is not
//    well managed in the AliExternalTrackParam class.
// ------------------------------------------------------------------------
// author: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
//=========================================================================

#include "Riostream.h"

#include "TVector3.h"

#include "AliLog.h"
#include "AliESDtrack.h" 

#include "AliEMCALTrack.h"

Bool_t AliEMCALTrack::fgUseOuterParams = kTRUE;
Bool_t AliEMCALTrack::fgCorrectForEL   = kFALSE;
Bool_t AliEMCALTrack::fgSortByPt       = kTRUE;

ClassImp(AliEMCALTrack)
//
//------------------------------------------------------------------------------
//
AliEMCALTrack::AliEMCALTrack() 
  : AliExternalTrackParam(),
    fClusterIndex(-1),
    fClusterDist(1000.0),          // default: extremely large distance
    fMass(0.13957018),             // default: pion mass
    fSeedIndex(-1),
    fSeedLabel(-1)
{
	//
	// Default constructor.
	// Sets to meaningless values the indexes corresponding to
	// ESD seed track and matched cluster.
	//

}
//
//------------------------------------------------------------------------------
//
AliEMCALTrack::AliEMCALTrack(const AliESDtrack& t) 
  : AliExternalTrackParam(),
    fClusterIndex(-1),
    fClusterDist(1000.0),
    fMass(t.GetMass(kTRUE)),
    fSeedIndex(-1),
    fSeedLabel(t.GetLabel())
{
	//
	// Constructor from AliESDtrack
	//

	// parameters are chosen according to static variable fUseOuterParams
	Double_t alpha=0., x=0., params[5], cov[15];
	if (fgUseOuterParams) {
	  if(t.GetOuterParam()){
	    t.GetOuterExternalParameters(alpha, x, params);
	    t.GetOuterExternalCovariance(cov);
	  }
	  else{ // no outer param available leave the default as is
	    return;
	  }
	}
	else {
		alpha = t.GetAlpha();
		t.GetExternalParameters(x, params);
		t.GetExternalCovariance(cov);
	}
	
	if (alpha < -TMath::Pi()) alpha += TMath::TwoPi();
	else if (alpha >= TMath::Pi()) alpha -= TMath::TwoPi();
	
	// set this accordingly
	Set(x, alpha, params, cov);
}
//
//------------------------------------------------------------------------------
//
AliEMCALTrack::AliEMCALTrack(const AliEMCALTrack& t) 
  : AliExternalTrackParam(t),
    fClusterIndex(t.fClusterIndex),
    fClusterDist(t.fClusterDist),
    fMass(t.fMass),
    fSeedIndex(t.fSeedIndex),
    fSeedLabel(t.fSeedLabel)
{
	//
	// Copy constructor.
	//
}
//
//------------------------------------------------------------------------------
//
AliEMCALTrack& AliEMCALTrack::operator=(const AliEMCALTrack &source)
{ // assignment operator; use copy ctor
  if (&source == this) return *this;

  new (this) AliEMCALTrack(source);
  return *this;
}
//
//------------------------------------------------------------------------------
//
Int_t AliEMCALTrack::Compare(const TObject *obj) const 
{
	//
	// Compare tracks.
	// How tracks are compared depends on the static flag
	// "fSortByPt" (boolean):
	// true  => tracks are compared w.r. to their transverse momentum
	// false => tracks are compared w.r. to their distance from cluster
	//
	
	AliEMCALTrack *that = (AliEMCALTrack*)obj;
	
	Double_t thisP[3], thisVal=0., thatP[3], thatVal=0.;
	
	if (fgSortByPt) {
		this->GetPxPyPz(thisP);
		that->GetPxPyPz(thatP);	
		thisVal = TMath::Sqrt(thisP[0]*thisP[0] + thisP[1]*thisP[1]);
		thatVal = TMath::Sqrt(thatP[0]*thatP[0] + thatP[1]*thatP[1]);
	}
	else {
		thisVal = this->GetClusterDist();
		thatVal = that->GetClusterDist();
	}
	
	if (thisVal > thatVal) return 1;
	else if (thisVal < thatVal) return -1;
	else return 0;
}
//
//------------------------------------------------------------------------------
//
Bool_t AliEMCALTrack::PropagateTo(Double_t xk, Double_t d, Double_t x0)
{
	//
	// Propagates a track to the plane defined by x='xk'.
	// Second parameter is the width (in units of rad. length) crossed by the track.
	// Third parameter is the reference radiation length used.
	// Track propagation includes computing energy loss (modifies curvature)
	// and multiple scattering perturbation (alters covariance matrix), if requested.
	// Method returns kFALSE when something goes wrong with computations.
	//
	// An additional operation (thanks to Yuri Belikov) is done to check
	// when the track crosses a sector boundary. If this happens, 
	// the local track reference frame is adjusted accordingly.
	//
		
	Double_t y=0.;
	Double_t field = GetBz();
	Double_t width = TMath::Pi() / 9.0; // width of TPC/TRD/EMCAL sector (= 20 deg)
	Double_t ymax  = TMath::Abs(xk * TMath::Tan(0.5 * width)); // max allowed Y in local coords at distance xk
	
	// first check: try to compute the local 'y' at the distance 'xk':
	// if this attempt fails, the propagation cannot be done
	if (!GetYAt(xk, field, y)) return kFALSE;
	
	// if is -ymax < y < ymax ==> 'direct' propagation is done;
	if (TMath::Abs(y) <= ymax) return SimplePropagation(xk, d, x0);
	
	// otherwise, try change a sector to find one where the propagation is ok
	Int_t    i=0, incr=0, istart=0, nloops=0;
	Double_t alpha = GetAlpha();
	incr = (y > ymax) ? 1 : -1;
	if (alpha < 0.0) alpha += TMath::TwoPi();
	istart = (Int_t)(alpha / width);
	for (i = istart, nloops = 0; nloops < 18; i += incr, nloops++) {
		if (i == 18) i = 0;
		if (i == -1) i = 17;
		alpha = ((Double_t)i + 0.5) * width;
		if (Rotate(alpha)) {
			if (GetYAt(xk, field, y)) {
				if (TMath::Abs(y) <= ymax) {
				  AliDebug(1,Form("Required change from sector %d to sector %d to succeed in propagation", istart, i));
					return SimplePropagation(xk, d, x0);
				}
			}
		}
	}
	
	// if the routine exits from the loop and reaches this point,
	// it means that none of the rotations succeeded
	AliWarning("Track propagation fails in every sector. Impossible to propagate.");
	return kFALSE;
}
//
//------------------------------------------------------------------------------
//
Double_t AliEMCALTrack::StraightPropagateTo(Double_t xk, Double_t &x, Double_t &y, Double_t &z)
{
	//
	// Does propagation with a straight line approximation.
	// This operation does not update track parameters, but it returns a point
	// in space, according to this propagation, which is stored in
	// the arguments #2, #3 and #4
	//
	
	Double_t oldX = GetX(), oldY = GetY(), oldZ = GetZ();
	Double_t newPos[3];
	
	newPos[0] = xk;
	newPos[1] = oldY * xk / oldX;
	newPos[2] = oldZ * xk / oldX;
	
	Double_t cs = TMath::Cos(GetAlpha()), sn = TMath::Sin(GetAlpha());
	x = newPos[0]*cs - newPos[1]*sn;
	y = newPos[0]*sn + newPos[1]*cs;
	z = newPos[2];
	
	return newPos[1];
}
//
//------------------------------------------------------------------------------
//
Bool_t AliEMCALTrack::PropagateToGlobal(Double_t x, Double_t y, Double_t z, Double_t d, Double_t x0)
{
	//
	// Propagate to a point specified with its global XYZ coordinates.
	// Here, the correct value of the 'X' parameter to be sent to "PropagateTo" is computed.
	//
	
	TVector3 vc(x, y, z);
	Double_t width = 20.0; // width of TPC/TRD/EMCAL sector
	Double_t phi   = vc.Phi() * TMath::RadToDeg();
	if (phi < 0.0) phi += 360.0;
	
	Int_t    isector = (Int_t)(phi / width);
	Double_t rotation = ((Double_t)isector + 0.5) * width;
	vc.RotateZ(-rotation * TMath::DegToRad());
	
	return PropagateTo(vc.X(), d, x0);
}
//
//------------------------------------------------------------------------------
//
Bool_t AliEMCALTrack::SimplePropagation(Double_t xk, Double_t d, Double_t x0)
{
  //
  // Recall base class method for track propagation.
  //
  
  Double_t field[3];

  GetBxByBz(field);
	
  // propagation...
  if (!AliExternalTrackParam::PropagateToBxByBz(xk, field)) return kFALSE;
  
  // EL correction is computed only if requested...
  if (!fgCorrectForEL) return kTRUE;
  return AliExternalTrackParam::CorrectForMeanMaterial(d, x0, GetMass());
}
 AliEMCALTrack.cxx:1
 AliEMCALTrack.cxx:2
 AliEMCALTrack.cxx:3
 AliEMCALTrack.cxx:4
 AliEMCALTrack.cxx:5
 AliEMCALTrack.cxx:6
 AliEMCALTrack.cxx:7
 AliEMCALTrack.cxx:8
 AliEMCALTrack.cxx:9
 AliEMCALTrack.cxx:10
 AliEMCALTrack.cxx:11
 AliEMCALTrack.cxx:12
 AliEMCALTrack.cxx:13
 AliEMCALTrack.cxx:14
 AliEMCALTrack.cxx:15
 AliEMCALTrack.cxx:16
 AliEMCALTrack.cxx:17
 AliEMCALTrack.cxx:18
 AliEMCALTrack.cxx:19
 AliEMCALTrack.cxx:20
 AliEMCALTrack.cxx:21
 AliEMCALTrack.cxx:22
 AliEMCALTrack.cxx:23
 AliEMCALTrack.cxx:24
 AliEMCALTrack.cxx:25
 AliEMCALTrack.cxx:26
 AliEMCALTrack.cxx:27
 AliEMCALTrack.cxx:28
 AliEMCALTrack.cxx:29
 AliEMCALTrack.cxx:30
 AliEMCALTrack.cxx:31
 AliEMCALTrack.cxx:32
 AliEMCALTrack.cxx:33
 AliEMCALTrack.cxx:34
 AliEMCALTrack.cxx:35
 AliEMCALTrack.cxx:36
 AliEMCALTrack.cxx:37
 AliEMCALTrack.cxx:38
 AliEMCALTrack.cxx:39
 AliEMCALTrack.cxx:40
 AliEMCALTrack.cxx:41
 AliEMCALTrack.cxx:42
 AliEMCALTrack.cxx:43
 AliEMCALTrack.cxx:44
 AliEMCALTrack.cxx:45
 AliEMCALTrack.cxx:46
 AliEMCALTrack.cxx:47
 AliEMCALTrack.cxx:48
 AliEMCALTrack.cxx:49
 AliEMCALTrack.cxx:50
 AliEMCALTrack.cxx:51
 AliEMCALTrack.cxx:52
 AliEMCALTrack.cxx:53
 AliEMCALTrack.cxx:54
 AliEMCALTrack.cxx:55
 AliEMCALTrack.cxx:56
 AliEMCALTrack.cxx:57
 AliEMCALTrack.cxx:58
 AliEMCALTrack.cxx:59
 AliEMCALTrack.cxx:60
 AliEMCALTrack.cxx:61
 AliEMCALTrack.cxx:62
 AliEMCALTrack.cxx:63
 AliEMCALTrack.cxx:64
 AliEMCALTrack.cxx:65
 AliEMCALTrack.cxx:66
 AliEMCALTrack.cxx:67
 AliEMCALTrack.cxx:68
 AliEMCALTrack.cxx:69
 AliEMCALTrack.cxx:70
 AliEMCALTrack.cxx:71
 AliEMCALTrack.cxx:72
 AliEMCALTrack.cxx:73
 AliEMCALTrack.cxx:74
 AliEMCALTrack.cxx:75
 AliEMCALTrack.cxx:76
 AliEMCALTrack.cxx:77
 AliEMCALTrack.cxx:78
 AliEMCALTrack.cxx:79
 AliEMCALTrack.cxx:80
 AliEMCALTrack.cxx:81
 AliEMCALTrack.cxx:82
 AliEMCALTrack.cxx:83
 AliEMCALTrack.cxx:84
 AliEMCALTrack.cxx:85
 AliEMCALTrack.cxx:86
 AliEMCALTrack.cxx:87
 AliEMCALTrack.cxx:88
 AliEMCALTrack.cxx:89
 AliEMCALTrack.cxx:90
 AliEMCALTrack.cxx:91
 AliEMCALTrack.cxx:92
 AliEMCALTrack.cxx:93
 AliEMCALTrack.cxx:94
 AliEMCALTrack.cxx:95
 AliEMCALTrack.cxx:96
 AliEMCALTrack.cxx:97
 AliEMCALTrack.cxx:98
 AliEMCALTrack.cxx:99
 AliEMCALTrack.cxx:100
 AliEMCALTrack.cxx:101
 AliEMCALTrack.cxx:102
 AliEMCALTrack.cxx:103
 AliEMCALTrack.cxx:104
 AliEMCALTrack.cxx:105
 AliEMCALTrack.cxx:106
 AliEMCALTrack.cxx:107
 AliEMCALTrack.cxx:108
 AliEMCALTrack.cxx:109
 AliEMCALTrack.cxx:110
 AliEMCALTrack.cxx:111
 AliEMCALTrack.cxx:112
 AliEMCALTrack.cxx:113
 AliEMCALTrack.cxx:114
 AliEMCALTrack.cxx:115
 AliEMCALTrack.cxx:116
 AliEMCALTrack.cxx:117
 AliEMCALTrack.cxx:118
 AliEMCALTrack.cxx:119
 AliEMCALTrack.cxx:120
 AliEMCALTrack.cxx:121
 AliEMCALTrack.cxx:122
 AliEMCALTrack.cxx:123
 AliEMCALTrack.cxx:124
 AliEMCALTrack.cxx:125
 AliEMCALTrack.cxx:126
 AliEMCALTrack.cxx:127
 AliEMCALTrack.cxx:128
 AliEMCALTrack.cxx:129
 AliEMCALTrack.cxx:130
 AliEMCALTrack.cxx:131
 AliEMCALTrack.cxx:132
 AliEMCALTrack.cxx:133
 AliEMCALTrack.cxx:134
 AliEMCALTrack.cxx:135
 AliEMCALTrack.cxx:136
 AliEMCALTrack.cxx:137
 AliEMCALTrack.cxx:138
 AliEMCALTrack.cxx:139
 AliEMCALTrack.cxx:140
 AliEMCALTrack.cxx:141
 AliEMCALTrack.cxx:142
 AliEMCALTrack.cxx:143
 AliEMCALTrack.cxx:144
 AliEMCALTrack.cxx:145
 AliEMCALTrack.cxx:146
 AliEMCALTrack.cxx:147
 AliEMCALTrack.cxx:148
 AliEMCALTrack.cxx:149
 AliEMCALTrack.cxx:150
 AliEMCALTrack.cxx:151
 AliEMCALTrack.cxx:152
 AliEMCALTrack.cxx:153
 AliEMCALTrack.cxx:154
 AliEMCALTrack.cxx:155
 AliEMCALTrack.cxx:156
 AliEMCALTrack.cxx:157
 AliEMCALTrack.cxx:158
 AliEMCALTrack.cxx:159
 AliEMCALTrack.cxx:160
 AliEMCALTrack.cxx:161
 AliEMCALTrack.cxx:162
 AliEMCALTrack.cxx:163
 AliEMCALTrack.cxx:164
 AliEMCALTrack.cxx:165
 AliEMCALTrack.cxx:166
 AliEMCALTrack.cxx:167
 AliEMCALTrack.cxx:168
 AliEMCALTrack.cxx:169
 AliEMCALTrack.cxx:170
 AliEMCALTrack.cxx:171
 AliEMCALTrack.cxx:172
 AliEMCALTrack.cxx:173
 AliEMCALTrack.cxx:174
 AliEMCALTrack.cxx:175
 AliEMCALTrack.cxx:176
 AliEMCALTrack.cxx:177
 AliEMCALTrack.cxx:178
 AliEMCALTrack.cxx:179
 AliEMCALTrack.cxx:180
 AliEMCALTrack.cxx:181
 AliEMCALTrack.cxx:182
 AliEMCALTrack.cxx:183
 AliEMCALTrack.cxx:184
 AliEMCALTrack.cxx:185
 AliEMCALTrack.cxx:186
 AliEMCALTrack.cxx:187
 AliEMCALTrack.cxx:188
 AliEMCALTrack.cxx:189
 AliEMCALTrack.cxx:190
 AliEMCALTrack.cxx:191
 AliEMCALTrack.cxx:192
 AliEMCALTrack.cxx:193
 AliEMCALTrack.cxx:194
 AliEMCALTrack.cxx:195
 AliEMCALTrack.cxx:196
 AliEMCALTrack.cxx:197
 AliEMCALTrack.cxx:198
 AliEMCALTrack.cxx:199
 AliEMCALTrack.cxx:200
 AliEMCALTrack.cxx:201
 AliEMCALTrack.cxx:202
 AliEMCALTrack.cxx:203
 AliEMCALTrack.cxx:204
 AliEMCALTrack.cxx:205
 AliEMCALTrack.cxx:206
 AliEMCALTrack.cxx:207
 AliEMCALTrack.cxx:208
 AliEMCALTrack.cxx:209
 AliEMCALTrack.cxx:210
 AliEMCALTrack.cxx:211
 AliEMCALTrack.cxx:212
 AliEMCALTrack.cxx:213
 AliEMCALTrack.cxx:214
 AliEMCALTrack.cxx:215
 AliEMCALTrack.cxx:216
 AliEMCALTrack.cxx:217
 AliEMCALTrack.cxx:218
 AliEMCALTrack.cxx:219
 AliEMCALTrack.cxx:220
 AliEMCALTrack.cxx:221
 AliEMCALTrack.cxx:222
 AliEMCALTrack.cxx:223
 AliEMCALTrack.cxx:224
 AliEMCALTrack.cxx:225
 AliEMCALTrack.cxx:226
 AliEMCALTrack.cxx:227
 AliEMCALTrack.cxx:228
 AliEMCALTrack.cxx:229
 AliEMCALTrack.cxx:230
 AliEMCALTrack.cxx:231
 AliEMCALTrack.cxx:232
 AliEMCALTrack.cxx:233
 AliEMCALTrack.cxx:234
 AliEMCALTrack.cxx:235
 AliEMCALTrack.cxx:236
 AliEMCALTrack.cxx:237
 AliEMCALTrack.cxx:238
 AliEMCALTrack.cxx:239
 AliEMCALTrack.cxx:240
 AliEMCALTrack.cxx:241
 AliEMCALTrack.cxx:242
 AliEMCALTrack.cxx:243
 AliEMCALTrack.cxx:244
 AliEMCALTrack.cxx:245
 AliEMCALTrack.cxx:246
 AliEMCALTrack.cxx:247
 AliEMCALTrack.cxx:248
 AliEMCALTrack.cxx:249
 AliEMCALTrack.cxx:250
 AliEMCALTrack.cxx:251
 AliEMCALTrack.cxx:252
 AliEMCALTrack.cxx:253
 AliEMCALTrack.cxx:254
 AliEMCALTrack.cxx:255
 AliEMCALTrack.cxx:256
 AliEMCALTrack.cxx:257
 AliEMCALTrack.cxx:258
 AliEMCALTrack.cxx:259
 AliEMCALTrack.cxx:260
 AliEMCALTrack.cxx:261
 AliEMCALTrack.cxx:262
 AliEMCALTrack.cxx:263
 AliEMCALTrack.cxx:264
 AliEMCALTrack.cxx:265
 AliEMCALTrack.cxx:266
 AliEMCALTrack.cxx:267
 AliEMCALTrack.cxx:268
 AliEMCALTrack.cxx:269
 AliEMCALTrack.cxx:270
 AliEMCALTrack.cxx:271
 AliEMCALTrack.cxx:272
 AliEMCALTrack.cxx:273
 AliEMCALTrack.cxx:274
 AliEMCALTrack.cxx:275
 AliEMCALTrack.cxx:276