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 for the description of the clusters of the ALICE Muon Forward Tracker
//
//      Contact author: antonio.uras@cern.ch
//
//====================================================================================================================================================

#include "TObject.h"
#include "AliMUONRawCluster.h"
#include "AliMUONVCluster.h"
#include "AliMFTDigit.h"
#include "TMath.h"
#include "AliMFTCluster.h"

ClassImp(AliMFTCluster)

//====================================================================================================================================================

AliMFTCluster::AliMFTCluster():
  TObject(),
  fX(0), 
  fY(0), 
  fZ(0),
  fErrX(0), 
  fErrY(0), 
  fErrZ(0),
  fNElectrons(0),
  fNMCTracks(0),
  fPlane(-1),
  fDetElemID(-1),
  fSize(0),
  fTrackChi2(0),
  fLocalChi2(0),
  fDigitsInCluster(0),
  fIsClusterEditable(kTRUE),
  fIsClusterFront(kTRUE)
{

  // default constructor

  for (Int_t iTrack=0; iTrack<fNMaxMCTracks; iTrack++) fMCLabel[iTrack] = -1;

  fDigitsInCluster = new TClonesArray("AliMFTDigit", fNMaxDigitsPerCluster);
  fDigitsInCluster -> SetOwner(kTRUE);
}

//====================================================================================================================================================

AliMFTCluster::AliMFTCluster(const AliMFTCluster& cluster): 
  TObject(cluster),
  fX(cluster.fX), 
  fY(cluster.fY), 
  fZ(cluster.fZ),
  fErrX(cluster.fErrX), 
  fErrY(cluster.fErrY), 
  fErrZ(cluster.fErrZ),
  fNElectrons(cluster.fNElectrons),
  fNMCTracks(cluster.fNMCTracks),
  fPlane(cluster.fPlane),
  fDetElemID(cluster.fDetElemID),
  fSize(cluster.fSize),
  fTrackChi2(cluster.fTrackChi2),
  fLocalChi2(cluster.fLocalChi2),
  fDigitsInCluster(NULL),
  fIsClusterEditable(cluster.fIsClusterEditable),
  fIsClusterFront(cluster.fIsClusterFront)
{

  // copy constructor
  for (Int_t iTrack=0; iTrack<fNMaxMCTracks; iTrack++) fMCLabel[iTrack] = (cluster.fMCLabel)[iTrack];
  if (cluster.fDigitsInCluster) {
    fDigitsInCluster = new TClonesArray(*(cluster.fDigitsInCluster));
    fDigitsInCluster -> SetOwner(kTRUE);
  }
  else {
    fDigitsInCluster = new TClonesArray("AliMFTDigit", fNMaxDigitsPerCluster);
    fDigitsInCluster -> SetOwner(kTRUE);
  }    
 
}

//====================================================================================================================================================

AliMFTCluster& AliMFTCluster::operator=(const AliMFTCluster& cluster) {

  // Asignment operator

  // check assignement to self
  if (this == &cluster) return *this;

  // base class assignement
  TObject::operator=(cluster);
  
  // clear memory
  Clear("");
  
  fX                 = cluster.fX; 
  fY                 = cluster.fY; 
  fZ                 = cluster.fZ;
  fErrX              = cluster.fErrX; 
  fErrY              = cluster.fErrY; 
  fErrZ              = cluster.fErrZ;
  fNElectrons        = cluster.fNElectrons;
  fNMCTracks         = cluster.fNMCTracks;
  fPlane             = cluster.fPlane;
  fDetElemID         = cluster.fDetElemID;
  fSize              = cluster.fSize;
  fTrackChi2         = cluster.fTrackChi2;
  fLocalChi2         = cluster.fLocalChi2;
  fIsClusterEditable = cluster.fIsClusterEditable;
  fIsClusterFront    = cluster.fIsClusterFront;

  for (Int_t iTrack=0; iTrack<fNMaxMCTracks; iTrack++) fMCLabel[iTrack] = (cluster.fMCLabel)[iTrack];
  fDigitsInCluster      = new TClonesArray(*(cluster.fDigitsInCluster));
  fDigitsInCluster->SetOwner(kTRUE);

  return *this;

}

//====================================================================================================================================================

Double_t AliMFTCluster::GetDistanceFromPixel(AliMFTDigit *pixel) {

  // the distance is expressed in units of pixels!!!
  // useful to decide if the pixel is compatible with the current digits array

  Double_t distance = -1;

  if (!fSize) return distance;

  if (pixel->GetDetElemID()!=fDetElemID || pixel->GetPlane()!=fPlane) return 9999.;

  for (Int_t iDigit=0; iDigit<fDigitsInCluster->GetEntries(); iDigit++) {
    AliMFTDigit *tmpDig = (AliMFTDigit*) fDigitsInCluster->At(iDigit);
    Int_t distX = TMath::Abs(tmpDig->GetPixelX() - pixel->GetPixelX());
    Int_t distY = TMath::Abs(tmpDig->GetPixelY() - pixel->GetPixelY());
    if (distX<=1 &&  distY<=1) return 0;
    if (!iDigit) distance = TMath::Sqrt(distX*distX + distY*distY);
    else         distance = TMath::Min(distance, TMath::Sqrt(distX*distX + distY*distY));
  }

  return distance;

}

//====================================================================================================================================================

Bool_t AliMFTCluster::AddPixel(AliMFTDigit *pixel) {

  if (!fIsClusterEditable || fSize>=fNMaxDigitsPerCluster) return kFALSE;
  if (fSize && (pixel->GetPlane()!=fPlane || pixel->GetDetElemID()!=fDetElemID)) return kFALSE;

  new ((*fDigitsInCluster)[fDigitsInCluster->GetEntries()]) AliMFTDigit(*pixel);

  if (!fSize) {
    SetPlane(pixel->GetPlane());
    SetDetElemID(pixel->GetDetElemID());
  }

  fSize++;

  return kTRUE;

}

//====================================================================================================================================================

void AliMFTCluster::TerminateCluster() {

  Double_t xCenters[fNMaxDigitsPerCluster] = {0};
  Double_t yCenters[fNMaxDigitsPerCluster] = {0};
  Double_t nElectrons = 0.;

  for (Int_t iDigit=0; iDigit<fDigitsInCluster->GetEntries(); iDigit++) {
    AliMFTDigit *tmpDig = (AliMFTDigit*) fDigitsInCluster->At(iDigit);
    xCenters[iDigit] = tmpDig->GetPixelCenterX();
    yCenters[iDigit] = tmpDig->GetPixelCenterY();
    nElectrons      += tmpDig->GetNElectrons();
    for (Int_t iTrack=0; iTrack<tmpDig->GetNMCTracks(); iTrack++) AddMCLabel(tmpDig->GetMCLabel(iTrack));
  }

  SetX(TMath::Mean(fDigitsInCluster->GetEntries(), xCenters));
  SetY(TMath::Mean(fDigitsInCluster->GetEntries(), yCenters));
  SetZ(((AliMFTDigit*) fDigitsInCluster->At(0))->GetPixelCenterZ());

  Double_t minErrX = ((AliMFTDigit*) fDigitsInCluster->At(0))->GetPixelWidthX() / TMath::Sqrt(12.);
  Double_t minErrY = ((AliMFTDigit*) fDigitsInCluster->At(0))->GetPixelWidthY() / TMath::Sqrt(12.);
  Double_t minErrZ = ((AliMFTDigit*) fDigitsInCluster->At(0))->GetPixelWidthZ() / TMath::Sqrt(12.);
  SetErrX( TMath::Max(TMath::RMS(fDigitsInCluster->GetEntries(), xCenters), minErrX) );
  SetErrY( TMath::Max(TMath::RMS(fDigitsInCluster->GetEntries(), yCenters), minErrY) );
  SetErrZ( minErrZ );
    
  SetNElectrons(nElectrons);

  fIsClusterEditable = kFALSE;

}
  
//====================================================================================================================================================

void AliMFTCluster::AddMCLabel(Int_t label) { 

  if (fNMCTracks>=fNMaxMCTracks) return; 

  for (Int_t iTrack=0; iTrack<fNMCTracks; iTrack++) if (label==fMCLabel[iTrack]) return;

  fMCLabel[fNMCTracks++]=label; 

}

//====================================================================================================================================================

AliMUONRawCluster* AliMFTCluster::CreateMUONCluster() {

  AliMUONRawCluster *cluster = new AliMUONRawCluster();
  
  cluster->SetXYZ(GetX(), GetY(), GetZ());
  cluster->SetErrXY(GetErrX(),GetErrY());
  cluster->SetDetElemId(100);   // to get the cluster compatible with the AliMUONTrack::AddTrackParamAtCluster(...) method

  return cluster;

}

//====================================================================================================================================================
 AliMFTCluster.cxx:1
 AliMFTCluster.cxx:2
 AliMFTCluster.cxx:3
 AliMFTCluster.cxx:4
 AliMFTCluster.cxx:5
 AliMFTCluster.cxx:6
 AliMFTCluster.cxx:7
 AliMFTCluster.cxx:8
 AliMFTCluster.cxx:9
 AliMFTCluster.cxx:10
 AliMFTCluster.cxx:11
 AliMFTCluster.cxx:12
 AliMFTCluster.cxx:13
 AliMFTCluster.cxx:14
 AliMFTCluster.cxx:15
 AliMFTCluster.cxx:16
 AliMFTCluster.cxx:17
 AliMFTCluster.cxx:18
 AliMFTCluster.cxx:19
 AliMFTCluster.cxx:20
 AliMFTCluster.cxx:21
 AliMFTCluster.cxx:22
 AliMFTCluster.cxx:23
 AliMFTCluster.cxx:24
 AliMFTCluster.cxx:25
 AliMFTCluster.cxx:26
 AliMFTCluster.cxx:27
 AliMFTCluster.cxx:28
 AliMFTCluster.cxx:29
 AliMFTCluster.cxx:30
 AliMFTCluster.cxx:31
 AliMFTCluster.cxx:32
 AliMFTCluster.cxx:33
 AliMFTCluster.cxx:34
 AliMFTCluster.cxx:35
 AliMFTCluster.cxx:36
 AliMFTCluster.cxx:37
 AliMFTCluster.cxx:38
 AliMFTCluster.cxx:39
 AliMFTCluster.cxx:40
 AliMFTCluster.cxx:41
 AliMFTCluster.cxx:42
 AliMFTCluster.cxx:43
 AliMFTCluster.cxx:44
 AliMFTCluster.cxx:45
 AliMFTCluster.cxx:46
 AliMFTCluster.cxx:47
 AliMFTCluster.cxx:48
 AliMFTCluster.cxx:49
 AliMFTCluster.cxx:50
 AliMFTCluster.cxx:51
 AliMFTCluster.cxx:52
 AliMFTCluster.cxx:53
 AliMFTCluster.cxx:54
 AliMFTCluster.cxx:55
 AliMFTCluster.cxx:56
 AliMFTCluster.cxx:57
 AliMFTCluster.cxx:58
 AliMFTCluster.cxx:59
 AliMFTCluster.cxx:60
 AliMFTCluster.cxx:61
 AliMFTCluster.cxx:62
 AliMFTCluster.cxx:63
 AliMFTCluster.cxx:64
 AliMFTCluster.cxx:65
 AliMFTCluster.cxx:66
 AliMFTCluster.cxx:67
 AliMFTCluster.cxx:68
 AliMFTCluster.cxx:69
 AliMFTCluster.cxx:70
 AliMFTCluster.cxx:71
 AliMFTCluster.cxx:72
 AliMFTCluster.cxx:73
 AliMFTCluster.cxx:74
 AliMFTCluster.cxx:75
 AliMFTCluster.cxx:76
 AliMFTCluster.cxx:77
 AliMFTCluster.cxx:78
 AliMFTCluster.cxx:79
 AliMFTCluster.cxx:80
 AliMFTCluster.cxx:81
 AliMFTCluster.cxx:82
 AliMFTCluster.cxx:83
 AliMFTCluster.cxx:84
 AliMFTCluster.cxx:85
 AliMFTCluster.cxx:86
 AliMFTCluster.cxx:87
 AliMFTCluster.cxx:88
 AliMFTCluster.cxx:89
 AliMFTCluster.cxx:90
 AliMFTCluster.cxx:91
 AliMFTCluster.cxx:92
 AliMFTCluster.cxx:93
 AliMFTCluster.cxx:94
 AliMFTCluster.cxx:95
 AliMFTCluster.cxx:96
 AliMFTCluster.cxx:97
 AliMFTCluster.cxx:98
 AliMFTCluster.cxx:99
 AliMFTCluster.cxx:100
 AliMFTCluster.cxx:101
 AliMFTCluster.cxx:102
 AliMFTCluster.cxx:103
 AliMFTCluster.cxx:104
 AliMFTCluster.cxx:105
 AliMFTCluster.cxx:106
 AliMFTCluster.cxx:107
 AliMFTCluster.cxx:108
 AliMFTCluster.cxx:109
 AliMFTCluster.cxx:110
 AliMFTCluster.cxx:111
 AliMFTCluster.cxx:112
 AliMFTCluster.cxx:113
 AliMFTCluster.cxx:114
 AliMFTCluster.cxx:115
 AliMFTCluster.cxx:116
 AliMFTCluster.cxx:117
 AliMFTCluster.cxx:118
 AliMFTCluster.cxx:119
 AliMFTCluster.cxx:120
 AliMFTCluster.cxx:121
 AliMFTCluster.cxx:122
 AliMFTCluster.cxx:123
 AliMFTCluster.cxx:124
 AliMFTCluster.cxx:125
 AliMFTCluster.cxx:126
 AliMFTCluster.cxx:127
 AliMFTCluster.cxx:128
 AliMFTCluster.cxx:129
 AliMFTCluster.cxx:130
 AliMFTCluster.cxx:131
 AliMFTCluster.cxx:132
 AliMFTCluster.cxx:133
 AliMFTCluster.cxx:134
 AliMFTCluster.cxx:135
 AliMFTCluster.cxx:136
 AliMFTCluster.cxx:137
 AliMFTCluster.cxx:138
 AliMFTCluster.cxx:139
 AliMFTCluster.cxx:140
 AliMFTCluster.cxx:141
 AliMFTCluster.cxx:142
 AliMFTCluster.cxx:143
 AliMFTCluster.cxx:144
 AliMFTCluster.cxx:145
 AliMFTCluster.cxx:146
 AliMFTCluster.cxx:147
 AliMFTCluster.cxx:148
 AliMFTCluster.cxx:149
 AliMFTCluster.cxx:150
 AliMFTCluster.cxx:151
 AliMFTCluster.cxx:152
 AliMFTCluster.cxx:153
 AliMFTCluster.cxx:154
 AliMFTCluster.cxx:155
 AliMFTCluster.cxx:156
 AliMFTCluster.cxx:157
 AliMFTCluster.cxx:158
 AliMFTCluster.cxx:159
 AliMFTCluster.cxx:160
 AliMFTCluster.cxx:161
 AliMFTCluster.cxx:162
 AliMFTCluster.cxx:163
 AliMFTCluster.cxx:164
 AliMFTCluster.cxx:165
 AliMFTCluster.cxx:166
 AliMFTCluster.cxx:167
 AliMFTCluster.cxx:168
 AliMFTCluster.cxx:169
 AliMFTCluster.cxx:170
 AliMFTCluster.cxx:171
 AliMFTCluster.cxx:172
 AliMFTCluster.cxx:173
 AliMFTCluster.cxx:174
 AliMFTCluster.cxx:175
 AliMFTCluster.cxx:176
 AliMFTCluster.cxx:177
 AliMFTCluster.cxx:178
 AliMFTCluster.cxx:179
 AliMFTCluster.cxx:180
 AliMFTCluster.cxx:181
 AliMFTCluster.cxx:182
 AliMFTCluster.cxx:183
 AliMFTCluster.cxx:184
 AliMFTCluster.cxx:185
 AliMFTCluster.cxx:186
 AliMFTCluster.cxx:187
 AliMFTCluster.cxx:188
 AliMFTCluster.cxx:189
 AliMFTCluster.cxx:190
 AliMFTCluster.cxx:191
 AliMFTCluster.cxx:192
 AliMFTCluster.cxx:193
 AliMFTCluster.cxx:194
 AliMFTCluster.cxx:195
 AliMFTCluster.cxx:196
 AliMFTCluster.cxx:197
 AliMFTCluster.cxx:198
 AliMFTCluster.cxx:199
 AliMFTCluster.cxx:200
 AliMFTCluster.cxx:201
 AliMFTCluster.cxx:202
 AliMFTCluster.cxx:203
 AliMFTCluster.cxx:204
 AliMFTCluster.cxx:205
 AliMFTCluster.cxx:206
 AliMFTCluster.cxx:207
 AliMFTCluster.cxx:208
 AliMFTCluster.cxx:209
 AliMFTCluster.cxx:210
 AliMFTCluster.cxx:211
 AliMFTCluster.cxx:212
 AliMFTCluster.cxx:213
 AliMFTCluster.cxx:214
 AliMFTCluster.cxx:215
 AliMFTCluster.cxx:216
 AliMFTCluster.cxx:217
 AliMFTCluster.cxx:218
 AliMFTCluster.cxx:219
 AliMFTCluster.cxx:220
 AliMFTCluster.cxx:221
 AliMFTCluster.cxx:222
 AliMFTCluster.cxx:223
 AliMFTCluster.cxx:224
 AliMFTCluster.cxx:225
 AliMFTCluster.cxx:226
 AliMFTCluster.cxx:227
 AliMFTCluster.cxx:228
 AliMFTCluster.cxx:229
 AliMFTCluster.cxx:230
 AliMFTCluster.cxx:231
 AliMFTCluster.cxx:232
 AliMFTCluster.cxx:233
 AliMFTCluster.cxx:234
 AliMFTCluster.cxx:235
 AliMFTCluster.cxx:236
 AliMFTCluster.cxx:237
 AliMFTCluster.cxx:238
 AliMFTCluster.cxx:239
 AliMFTCluster.cxx:240
 AliMFTCluster.cxx:241
 AliMFTCluster.cxx:242