<commit_before>/**************************************************************************
 * 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.                  *
 **************************************************************************/

//-------------------------------------------------------------------------
//                Implementation of the ITS track class
//
//          Origin: <NAME>, CERN, <EMAIL>
//-------------------------------------------------------------------------

#include <TMatrixD.h>

#include <TMath.h>
#include <iostream.h>

#include "AliCluster.h"
#include "../TPC/AliTPCtrack.h"
#include "AliITStrackV2.h"

ClassImp(AliITStrackV2)

const Int_t kWARN=1;

//____________________________________________________________________________
AliITStrackV2::AliITStrackV2(const AliTPCtrack& t) throw (const Char_t *) {
  //------------------------------------------------------------------
  //Convertion TPC track -> ITS track
  //------------------------------------------------------------------
  SetLabel(t.GetLabel());
  SetChi2(0.);
  SetNumberOfClusters(0);
  fdEdx  = 0.;
  fAlpha = t.GetAlpha();
  if      (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
  else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();

  //Convertion of the track parameters
  Double_t x,p[5]; t.GetExternalParameters(x,p);
  fX=x;    x=kConversionConstant;
  fP0=p[0]; 
  fP1=p[1]; 
  fP2=p[2];
  fP3=p[3];
  fP4=p[4]/x; 

  //Convertion of the covariance matrix
  Double_t c[15]; t.GetExternalCovariance(c);

  fC00=c[0 ];
  fC10=c[1 ];   fC11=c[2 ];
  fC20=c[3 ];   fC21=c[4 ];   fC22=c[5 ];
  fC30=c[6 ];   fC31=c[7 ];   fC32=c[8 ];   fC33=c[9 ];
  fC40=c[10]/x; fC41=c[11]/x; fC42=c[12]/x; fC43=c[13]/x; fC44=c[14]/x/x;

  if (!Invariant()) throw "AliITStrackV2: conversion failed !\n";
}

//____________________________________________________________________________
AliITStrackV2::AliITStrackV2(const AliITStrackV2& t) : AliKalmanTrack(t) {
  //------------------------------------------------------------------
  //Copy constructor
  //------------------------------------------------------------------
  fX=t.fX;
  fAlpha=t.fAlpha;
  fdEdx=t.fdEdx;

  fP0=t.fP0; fP1=t.fP1; fP2=t.fP2; fP3=t.fP3; fP4=t.fP4;

  fC00=t.fC00;
  fC10=t.fC10;  fC11=t.fC11;
  fC20=t.fC20;  fC21=t.fC21;  fC22=t.fC22;
  fC30=t.fC30;  fC31=t.fC31;  fC32=t.fC32;  fC33=t.fC33;
  fC40=t.fC40;  fC41=t.fC41;  fC42=t.fC42;  fC43=t.fC43;  fC44=t.fC44;

  Int_t n=GetNumberOfClusters();
  for (Int_t i=0; i<n; i++) fIndex[i]=t.fIndex[i];
}

//_____________________________________________________________________________
Int_t AliITStrackV2::Compare(const TObject *o) const {
  //-----------------------------------------------------------------
  // This function compares tracks according to the their curvature
  //-----------------------------------------------------------------
  AliTPCtrack *t=(AliTPCtrack*)o;
  Double_t co=TMath::Abs(t->Get1Pt());
  Double_t c =TMath::Abs(Get1Pt());
  if (c>co) return 1;
  else if (c<co) return -1;
  return 0;
}

//_____________________________________________________________________________
void AliITStrackV2::GetExternalCovariance(Double_t cc[15]) const {
  //-------------------------------------------------------------------------
  // This function returns an external representation of the covriance matrix.
  //   (See comments in AliTPCtrack.h about external track representation)
  //-------------------------------------------------------------------------
  Double_t a=kConvConst;

  cc[0 ]=fC00;
  cc[1 ]=fC10;   cc[2 ]=fC11;
  cc[3 ]=fC20;   cc[4 ]=fC21;   cc[5 ]=fC22;
  cc[6 ]=fC30;   cc[7 ]=fC31;   cc[8 ]=fC32;   cc[9 ]=fC33;
  cc[10]=fC40*a; cc[11]=fC41*a; cc[12]=fC42*a; cc[13]=fC43*a; cc[14]=fC44*a*a;
}

//____________________________________________________________________________
Int_t AliITStrackV2::PropagateToVertex(Double_t x0,Double_t rho,Double_t pm) {
  //------------------------------------------------------------------
  //This function propagates a track to the minimal distance from the origin
  //------------------------------------------------------------------
  Double_t xv=fP2*(fX*fP2 - fP0*TMath::Sqrt(1.- fP2*fP2)); //linear approxim.
  Propagate(fAlpha,xv,0.,0.,pm);   
  return 0;
}

//____________________________________________________________________________
Int_t AliITStrackV2::
GetGlobalXYZat(Double_t xk, Double_t &x, Double_t &y, Double_t &z) const {
  //------------------------------------------------------------------
  //This function returns a track position in the global system
  //------------------------------------------------------------------
  Double_t dx=xk-fX;
  Double_t f1=fP2, f2=f1 + fP4*dx;
  if (TMath::Abs(f2) >= 0.99999) {
     Int_t n=GetNumberOfClusters();
    if (n>kWARN) cerr<<n<<" AliITStrackV2 warning: Propagation failed !\n";
    return 0;
  }

  Double_t r1=sqrt(1.- f1*f1), r2=sqrt(1.- f2*f2);
  
  Double_t yk = fP0 + dx*(f1+f2)/(r1+r2);
  Double_t zk = fP1 + dx*(f1+f2)/(f1*r2 + f2*r1)*fP3;

  Double_t cs=TMath::Cos(fAlpha), sn=TMath::Sin(fAlpha);
  x = xk*cs - yk*sn;
  y = xk*sn + yk*cs;
  z = zk;

  return 1;
}

//_____________________________________________________________________________
Double_t AliITStrackV2::GetPredictedChi2(const AliCluster *c) const 
{
  //-----------------------------------------------------------------
  // This function calculates a predicted chi2 increment.
  //-----------------------------------------------------------------
  Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
  r00+=fC00; r01+=fC10; r11+=fC11;

  Double_t det=r00*r11 - r01*r01;
  if (TMath::Abs(det) < 1.e-10) {
    Int_t n=GetNumberOfClusters();
    if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
    return 1e10;
  }
  Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
  
  Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
  
  return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
}

//_____________________________________________________________________________
Double_t AliITStrackV2::GetPredictedChi2(const AliCluster *c,Double_t *m,
Double_t x0, Double_t pm=0.139) const {
  //-----------------------------------------------------------------
  // This function calculates a chi2 increment with a vertex contraint 
  //-----------------------------------------------------------------
  TVectorD x(5); x(0)=fP0; x(1)=fP1; x(2)=fP2; x(3)=fP3; x(4)=fP4;
  TMatrixD C(5,5);
  C(0,0)=fC00; 
  C(1,0)=fC10; C(1,1)=fC11; 
  C(2,0)=fC20; C(2,1)=fC21; C(2,2)=fC22;
  C(3,0)=fC30; C(3,1)=fC31; C(3,2)=fC32; C(3,3)=fC33;<commit_msg>Default argument initialised only in the header file<commit_after>/**************************************************************************
 * 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.                  *
 **************************************************************************/

//-------------------------------------------------------------------------
//                Implementation of the ITS track class
//
//          Origin: <NAME>, CERN, <EMAIL>
//-------------------------------------------------------------------------

#include <TMatrixD.h>

#include <TMath.h>
#include <iostream.h>

#include "AliCluster.h"
#include "../TPC/AliTPCtrack.h"
#include "AliITStrackV2.h"

ClassImp(AliITStrackV2)

const Int_t kWARN=1;

//____________________________________________________________________________
AliITStrackV2::AliITStrackV2(const AliTPCtrack& t) throw (const Char_t *) {
  //------------------------------------------------------------------
  //Convertion TPC track -> ITS track
  //------------------------------------------------------------------
  SetLabel(t.GetLabel());
  SetChi2(0.);
  SetNumberOfClusters(0);
  fdEdx  = 0.;
  fAlpha = t.GetAlpha();
  if      (fAlpha < -TMath::Pi()) fAlpha += 2*TMath::Pi();
  else if (fAlpha >= TMath::Pi()) fAlpha -= 2*TMath::Pi();

  //Convertion of the track parameters
  Double_t x,p[5]; t.GetExternalParameters(x,p);
  fX=x;    x=kConversionConstant;
  fP0=p[0]; 
  fP1=p[1]; 
  fP2=p[2];
  fP3=p[3];
  fP4=p[4]/x; 

  //Convertion of the covariance matrix
  Double_t c[15]; t.GetExternalCovariance(c);

  fC00=c[0 ];
  fC10=c[1 ];   fC11=c[2 ];
  fC20=c[3 ];   fC21=c[4 ];   fC22=c[5 ];
  fC30=c[6 ];   fC31=c[7 ];   fC32=c[8 ];   fC33=c[9 ];
  fC40=c[10]/x; fC41=c[11]/x; fC42=c[12]/x; fC43=c[13]/x; fC44=c[14]/x/x;

  if (!Invariant()) throw "AliITStrackV2: conversion failed !\n";
}

//____________________________________________________________________________
AliITStrackV2::AliITStrackV2(const AliITStrackV2& t) : AliKalmanTrack(t) {
  //------------------------------------------------------------------
  //Copy constructor
  //------------------------------------------------------------------
  fX=t.fX;
  fAlpha=t.fAlpha;
  fdEdx=t.fdEdx;

  fP0=t.fP0; fP1=t.fP1; fP2=t.fP2; fP3=t.fP3; fP4=t.fP4;

  fC00=t.fC00;
  fC10=t.fC10;  fC11=t.fC11;
  fC20=t.fC20;  fC21=t.fC21;  fC22=t.fC22;
  fC30=t.fC30;  fC31=t.fC31;  fC32=t.fC32;  fC33=t.fC33;
  fC40=t.fC40;  fC41=t.fC41;  fC42=t.fC42;  fC43=t.fC43;  fC44=t.fC44;

  Int_t n=GetNumberOfClusters();
  for (Int_t i=0; i<n; i++) fIndex[i]=t.fIndex[i];
}

//_____________________________________________________________________________
Int_t AliITStrackV2::Compare(const TObject *o) const {
  //-----------------------------------------------------------------
  // This function compares tracks according to the their curvature
  //-----------------------------------------------------------------
  AliTPCtrack *t=(AliTPCtrack*)o;
  Double_t co=TMath::Abs(t->Get1Pt());
  Double_t c =TMath::Abs(Get1Pt());
  if (c>co) return 1;
  else if (c<co) return -1;
  return 0;
}

//_____________________________________________________________________________
void AliITStrackV2::GetExternalCovariance(Double_t cc[15]) const {
  //-------------------------------------------------------------------------
  // This function returns an external representation of the covriance matrix.
  //   (See comments in AliTPCtrack.h about external track representation)
  //-------------------------------------------------------------------------
  Double_t a=kConvConst;

  cc[0 ]=fC00;
  cc[1 ]=fC10;   cc[2 ]=fC11;
  cc[3 ]=fC20;   cc[4 ]=fC21;   cc[5 ]=fC22;
  cc[6 ]=fC30;   cc[7 ]=fC31;   cc[8 ]=fC32;   cc[9 ]=fC33;
  cc[10]=fC40*a; cc[11]=fC41*a; cc[12]=fC42*a; cc[13]=fC43*a; cc[14]=fC44*a*a;
}

//____________________________________________________________________________
Int_t AliITStrackV2::PropagateToVertex(Double_t x0,Double_t rho,Double_t pm) {
  //------------------------------------------------------------------
  //This function propagates a track to the minimal distance from the origin
  //------------------------------------------------------------------
  Double_t xv=fP2*(fX*fP2 - fP0*TMath::Sqrt(1.- fP2*fP2)); //linear approxim.
  Propagate(fAlpha,xv,0.,0.,pm);   
  return 0;
}

//____________________________________________________________________________
Int_t AliITStrackV2::
GetGlobalXYZat(Double_t xk, Double_t &x, Double_t &y, Double_t &z) const {
  //------------------------------------------------------------------
  //This function returns a track position in the global system
  //------------------------------------------------------------------
  Double_t dx=xk-fX;
  Double_t f1=fP2, f2=f1 + fP4*dx;
  if (TMath::Abs(f2) >= 0.99999) {
     Int_t n=GetNumberOfClusters();
    if (n>kWARN) cerr<<n<<" AliITStrackV2 warning: Propagation failed !\n";
    return 0;
  }

  Double_t r1=sqrt(1.- f1*f1), r2=sqrt(1.- f2*f2);
  
  Double_t yk = fP0 + dx*(f1+f2)/(r1+r2);
  Double_t zk = fP1 + dx*(f1+f2)/(f1*r2 + f2*r1)*fP3;

  Double_t cs=TMath::Cos(fAlpha), sn=TMath::Sin(fAlpha);
  x = xk*cs - yk*sn;
  y = xk*sn + yk*cs;
  z = zk;

  return 1;
}

//_____________________________________________________________________________
Double_t AliITStrackV2::GetPredictedChi2(const AliCluster *c) const 
{
  //-----------------------------------------------------------------
  // This function calculates a predicted chi2 increment.
  //-----------------------------------------------------------------
  Double_t r00=c->GetSigmaY2(), r01=0., r11=c->GetSigmaZ2();
  r00+=fC00; r01+=fC10; r11+=fC11;

  Double_t det=r00*r11 - r01*r01;
  if (TMath::Abs(det) < 1.e-10) {
    Int_t n=GetNumberOfClusters();
    if (n>4) cerr<<n<<" AliKalmanTrack warning: Singular matrix !\n";
    return 1e10;
  }
  Double_t tmp=r00; r00=r11; r11=tmp; r01=-r01;
  
  Double_t dy=c->GetY() - fP0, dz=c->GetZ() - fP1;
  
  return (dy*r00*dy + 2*r01*dy*dz + dz*r11*dz)/det;
}

//_____________________________________________________________________________
Double_t AliITStrackV2::GetPredictedChi2(const AliCluster *c,Double_t *m,
Double_t x0, Double_t pm) const {
  //-----------------------------------------------------------------
  // This function calculates a chi2 increment with a vertex contraint 
  //-----------------------------------------------------------------
  TVectorD x(5); x(0)=fP0; x(1)=fP1; x(2)=fP2; x(3)=fP3; x(4)=fP4;
  TMatrixD C(5,5);
  C(0,0)=fC00; 
  C(1,0)=fC10; C(1,1)=fC11; 
  C(2,0)=fC20; C(2,1)=fC21; C(2,2)=fC22;
  C(3,0)=fC30; C(3,1)=fC31; C(3,2)=fC32; C(3,3)=fC33;
{'fraction_non_alphanumeric': 0.304111610436649, 'fraction_numerical': 0.05137836206318331, 'mean_word_length': 1.8856202825624153, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5247030', 'n_tokens_mistral': 5293, 'n_tokens_neox': 4927, 'n_words': 998}