]> git.uio.no Git - u/mrichter/AliRoot.git/blob - MFT/AliMFTCluster.cxx
MFT classes modified to include MUON+MFT tracks in ESD&AOD. Clusterization algorithm...
[u/mrichter/AliRoot.git] / MFT / AliMFTCluster.cxx
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 //====================================================================================================================================================
17 //
18 //      Class for the description of the clusters of the ALICE Muon Forward Tracker
19 //
20 //      Contact author: antonio.uras@cern.ch
21 //
22 //====================================================================================================================================================
23
24 #include "TObject.h"
25 #include "AliMUONRawCluster.h"
26 #include "AliMUONVCluster.h"
27 #include "AliMFTDigit.h"
28 #include "TMath.h"
29 #include "AliMFTCluster.h"
30
31 ClassImp(AliMFTCluster)
32
33 //====================================================================================================================================================
34
35 AliMFTCluster::AliMFTCluster():
36   TObject(),
37   fX(0), 
38   fY(0), 
39   fZ(0),
40   fErrX(0), 
41   fErrY(0), 
42   fErrZ(0),
43   fNElectrons(0),
44   fNMCTracks(0),
45   fPlane(-1),
46   fDetElemID(-1),
47   fSize(0),
48   fTrackChi2(0),
49   fLocalChi2(0),
50   fDigitsInCluster(0),
51   fIsClusterEditable(kTRUE)
52 {
53
54   // default constructor
55
56   for (Int_t iTrack=0; iTrack<fNMaxMCTracks; iTrack++) fMCLabel[iTrack] = -1;
57
58   fDigitsInCluster = new TClonesArray("AliMFTDigit", fNMaxDigitsPerCluster);
59   fDigitsInCluster -> SetOwner(kTRUE);
60 }
61
62 //====================================================================================================================================================
63
64 AliMFTCluster::AliMFTCluster(const AliMFTCluster& cluster): 
65   TObject(cluster),
66   fX(cluster.fX), 
67   fY(cluster.fY), 
68   fZ(cluster.fZ),
69   fErrX(cluster.fErrX), 
70   fErrY(cluster.fErrY), 
71   fErrZ(cluster.fErrZ),
72   fNElectrons(cluster.fNElectrons),
73   fNMCTracks(cluster.fNMCTracks),
74   fPlane(cluster.fPlane),
75   fDetElemID(cluster.fDetElemID),
76   fSize(cluster.fSize),
77   fTrackChi2(cluster.fTrackChi2),
78   fLocalChi2(cluster.fLocalChi2),
79   fDigitsInCluster(NULL),
80   fIsClusterEditable(cluster.fIsClusterEditable)
81 {
82
83   // copy constructor
84   for (Int_t iTrack=0; iTrack<fNMaxMCTracks; iTrack++) fMCLabel[iTrack] = (cluster.fMCLabel)[iTrack];
85   printf("checkpoint1 : cluster.fDigitsInCluster = %p\n",cluster.fDigitsInCluster);
86   if (cluster.fDigitsInCluster) {
87     printf("checkpoint2\n");
88     fDigitsInCluster = new TClonesArray(*(cluster.fDigitsInCluster));
89     fDigitsInCluster -> SetOwner(kTRUE);
90   }
91   else {
92     printf("checkpoint3\n");
93     fDigitsInCluster = new TClonesArray("AliMFTDigit", fNMaxDigitsPerCluster);
94     fDigitsInCluster -> SetOwner(kTRUE);
95   }    
96   printf("checkpoint4\n");
97  
98 }
99
100 //====================================================================================================================================================
101
102 AliMFTCluster::AliMFTCluster(const AliMFTCluster& cluster, const Bool_t copyDigits): 
103   TObject(cluster),
104   fX(cluster.fX), 
105   fY(cluster.fY), 
106   fZ(cluster.fZ),
107   fErrX(cluster.fErrX), 
108   fErrY(cluster.fErrY), 
109   fErrZ(cluster.fErrZ),
110   fNElectrons(cluster.fNElectrons),
111   fNMCTracks(cluster.fNMCTracks),
112   fPlane(cluster.fPlane),
113   fDetElemID(cluster.fDetElemID),
114   fSize(cluster.fSize),
115   fTrackChi2(cluster.fTrackChi2),
116   fLocalChi2(cluster.fLocalChi2),
117   fDigitsInCluster(NULL),
118   fIsClusterEditable(cluster.fIsClusterEditable)
119 {
120
121   // copy constructor with option for reading digits
122
123   for (Int_t iTrack=0; iTrack<fNMaxMCTracks; iTrack++) fMCLabel[iTrack] = (cluster.fMCLabel)[iTrack];
124   printf("checkpoint1\n");
125   if (copyDigits) {
126     fDigitsInCluster = new TClonesArray(*(cluster.fDigitsInCluster));
127     fDigitsInCluster -> SetOwner(kTRUE);
128   }
129   else {
130     fDigitsInCluster = new TClonesArray("AliMFTDigit", fNMaxDigitsPerCluster);
131     fDigitsInCluster -> SetOwner(kTRUE);
132   }
133     
134   printf("checkpoint2\n");
135  
136 }
137
138 //====================================================================================================================================================
139
140 AliMFTCluster& AliMFTCluster::operator=(const AliMFTCluster& cluster) {
141
142   // Asignment operator
143
144   // check assignement to self
145   if (this == &cluster) return *this;
146
147   // base class assignement
148   TObject::operator=(cluster);
149   
150   // clear memory
151   Clear("");
152   
153   fX                 = cluster.fX; 
154   fY                 = cluster.fY; 
155   fZ                 = cluster.fZ;
156   fErrX              = cluster.fErrX; 
157   fErrY              = cluster.fErrY; 
158   fErrZ              = cluster.fErrZ;
159   fNElectrons        = cluster.fNElectrons;
160   fNMCTracks         = cluster.fNMCTracks;
161   fPlane             = cluster.fPlane;
162   fDetElemID         = cluster.fDetElemID;
163   fSize              = cluster.fSize;
164   fTrackChi2         = cluster.fTrackChi2;
165   fLocalChi2         = cluster.fLocalChi2;
166   fIsClusterEditable = cluster.fIsClusterEditable;
167
168   for (Int_t iTrack=0; iTrack<fNMaxMCTracks; iTrack++) fMCLabel[iTrack] = (cluster.fMCLabel)[iTrack];
169   fDigitsInCluster      = new TClonesArray(*(cluster.fDigitsInCluster));
170   fDigitsInCluster->SetOwner(kTRUE);
171
172   return *this;
173
174 }
175
176 //====================================================================================================================================================
177
178 Double_t AliMFTCluster::GetDistanceFromPixel(AliMFTDigit *pixel) {
179
180   // the distance is expressed in units of pixels!!!
181   // useful to decide if the pixel is compatible with the current digits array
182
183   Double_t distance = -1;
184
185   if (!fSize) return distance;
186
187   if (pixel->GetDetElemID()!=fDetElemID || pixel->GetPlane()!=fPlane) return 9999.;
188
189   for (Int_t iDigit=0; iDigit<fDigitsInCluster->GetEntries(); iDigit++) {
190     AliMFTDigit *tmpDig = (AliMFTDigit*) fDigitsInCluster->At(iDigit);
191     Int_t distX = TMath::Abs(tmpDig->GetPixelX() - pixel->GetPixelX());
192     Int_t distY = TMath::Abs(tmpDig->GetPixelY() - pixel->GetPixelY());
193     if (distX<=1 &&  distY<=1) return 0;
194     if (!iDigit) distance = TMath::Sqrt(distX*distX + distY*distY);
195     else         distance = TMath::Min(distance, TMath::Sqrt(distX*distX + distY*distY));
196   }
197
198   return distance;
199
200 }
201
202 //====================================================================================================================================================
203
204 Bool_t AliMFTCluster::AddPixel(AliMFTDigit *pixel) {
205
206   if (!fIsClusterEditable || fSize>=fNMaxDigitsPerCluster) return kFALSE;
207   if (fSize && (pixel->GetPlane()!=fPlane || pixel->GetDetElemID()!=fDetElemID)) return kFALSE;
208
209   new ((*fDigitsInCluster)[fDigitsInCluster->GetEntries()]) AliMFTDigit(*pixel);
210
211   if (!fSize) {
212     SetPlane(pixel->GetPlane());
213     SetDetElemID(pixel->GetDetElemID());
214   }
215
216   fSize++;
217
218   return kTRUE;
219
220 }
221
222 //====================================================================================================================================================
223
224 void AliMFTCluster::TerminateCluster() {
225
226   Double_t xCenters[fNMaxDigitsPerCluster] = {0};
227   Double_t yCenters[fNMaxDigitsPerCluster] = {0};
228   Double_t nElectrons = 0.;
229
230   for (Int_t iDigit=0; iDigit<fDigitsInCluster->GetEntries(); iDigit++) {
231     AliMFTDigit *tmpDig = (AliMFTDigit*) fDigitsInCluster->At(iDigit);
232     xCenters[iDigit] = tmpDig->GetPixelCenterX();
233     yCenters[iDigit] = tmpDig->GetPixelCenterY();
234     nElectrons      += tmpDig->GetNElectrons();
235     for (Int_t iTrack=0; iTrack<tmpDig->GetNMCTracks(); iTrack++) AddMCLabel(tmpDig->GetMCLabel(iTrack));
236   }
237
238   SetX(TMath::Mean(fDigitsInCluster->GetEntries(), xCenters));
239   SetY(TMath::Mean(fDigitsInCluster->GetEntries(), yCenters));
240   SetZ(((AliMFTDigit*) fDigitsInCluster->At(0))->GetPixelCenterZ());
241
242   Double_t minErrX = ((AliMFTDigit*) fDigitsInCluster->At(0))->GetPixelWidthX() / TMath::Sqrt(12.);
243   Double_t minErrY = ((AliMFTDigit*) fDigitsInCluster->At(0))->GetPixelWidthY() / TMath::Sqrt(12.);
244   Double_t minErrZ = ((AliMFTDigit*) fDigitsInCluster->At(0))->GetPixelWidthZ() / TMath::Sqrt(12.);
245   SetErrX( TMath::Max(TMath::RMS(fDigitsInCluster->GetEntries(), xCenters), minErrX) );
246   SetErrY( TMath::Max(TMath::RMS(fDigitsInCluster->GetEntries(), yCenters), minErrY) );
247   SetErrZ( minErrZ );
248     
249   SetNElectrons(nElectrons);
250
251   fIsClusterEditable = kFALSE;
252
253 }
254   
255 //====================================================================================================================================================
256
257 void AliMFTCluster::AddMCLabel(Int_t label) { 
258
259   if (fNMCTracks>=fNMaxMCTracks) return; 
260
261   for (Int_t iTrack=0; iTrack<fNMCTracks; iTrack++) if (label==fMCLabel[iTrack]) return;
262
263   fMCLabel[fNMCTracks++]=label; 
264
265 }
266
267 //====================================================================================================================================================
268
269 AliMUONRawCluster* AliMFTCluster::CreateMUONCluster() {
270
271   AliMUONRawCluster *cluster = new AliMUONRawCluster();
272   
273   cluster->SetXYZ(GetX(), GetY(), GetZ());
274   cluster->SetErrXY(GetErrX(),GetErrY());
275   cluster->SetDetElemId(100);   // to get the cluster compatible with the AliMUONTrack::AddTrackParamAtCluster(...) method
276
277   return cluster;
278
279 }
280
281 //====================================================================================================================================================