]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUClusterPix.cxx
Don't return failure flag (negative chi2) in RefitTrack if all clusters
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUClusterPix.cxx
1 #include "AliITSUClusterPix.h"
2 #include "AliITSUGeomTGeo.h"
3 #include "AliLog.h"
4 #include <TGeoMatrix.h>
5 #include <TString.h>
6
7 using namespace TMath;
8
9 ClassImp(AliITSUClusterPix)
10
11 AliITSUGeomTGeo* AliITSUClusterPix::fgGeom = 0;
12 UInt_t           AliITSUClusterPix::fgMode = 0;
13
14 //_____________________________________________________
15 AliITSUClusterPix::AliITSUClusterPix()
16   : fCharge(0)
17   , fRecoInfo(0)
18   , fNxNzN(0)
19 {
20   // default constructor
21 }
22
23 //_____________________________________________________
24 AliITSUClusterPix::~AliITSUClusterPix()
25 {
26   // default destructor
27 }
28
29 //_____________________________________________________
30 AliITSUClusterPix::AliITSUClusterPix(const AliITSUClusterPix& cluster) 
31   :AliCluster(cluster)
32   ,fCharge(cluster.fCharge)
33   ,fRecoInfo(cluster.fRecoInfo)
34   ,fNxNzN(cluster.fNxNzN)
35 {
36   // copy constructor
37 }
38
39 //______________________________________________________________________________
40 AliITSUClusterPix& AliITSUClusterPix::operator=(const AliITSUClusterPix& cluster)
41 {
42   // = op
43   if(&cluster == this) return *this;
44   fNxNzN = cluster.fNxNzN;
45   fCharge = cluster.fCharge;
46   fRecoInfo = cluster.fRecoInfo;
47   TObject::operator=(cluster);
48   AliCluster::operator=(cluster);
49   return *this;
50 }
51
52 //______________________________________________________________________________
53 const TGeoHMatrix*  AliITSUClusterPix::GetTracking2LocalMatrix() const
54 {
55   // get tracking to local matrix (sensor!!!)
56   return (TGeoHMatrix*)fgGeom->GetMatrixT2L(GetVolumeId());
57 }
58
59 //______________________________________________________________________________
60 TGeoHMatrix* AliITSUClusterPix::GetMatrix(Bool_t ) const
61 {
62   // get module matrix (sensor!)
63   return (TGeoHMatrix*)fgGeom->GetMatrixSens(GetVolumeId());
64 }
65
66 //______________________________________________________________________________
67 void AliITSUClusterPix::Print(Option_t* option) const
68 {
69   // Print cluster information.
70   TString str = option; 
71   str.ToLower();
72   printf("Cl.in mod %5d, nx:%3d nz:%3d n:%d |Err^2:%.3e %.3e %+.3e |",GetVolumeId(),GetNx(),GetNz(),
73          GetNPix(),GetSigmaY2(),GetSigmaZ2(),GetSigmaYZ());
74   printf("XYZ: (%+.4e %+.4e %+.4e ",GetX(),GetY(),GetZ());
75   if      (IsFrameLoc()) printf("LOC)");
76   else if (IsFrameGlo()) printf("GLO)");
77   else if (IsFrameTrk()) printf("TRK)");
78   if (str.Contains("glo") && !IsFrameGlo() && fgGeom) {
79     Float_t g[3];
80     GetGlobalXYZ(g);
81     printf(" (%+.4e %+.4e %+.4e GLO)",g[0],g[1],g[2]);
82   }
83   printf(" MClb:");
84   for (int i=0;i<3;i++) printf(" %5d",GetLabel(i));
85   if (TestBit(kSplit)) printf(" Spl");
86   printf("\n");
87   //
88 }
89
90 //______________________________________________________________________________
91 Bool_t AliITSUClusterPix::GetGlobalXYZ(Float_t xyz[3]) const
92 {
93   // Get the global coordinates of the cluster
94   // All the needed information is taken only
95   // from TGeo.
96   if (IsFrameGlo()) {
97     xyz[0] = GetX();
98     xyz[1] = GetY();
99     xyz[2] = GetZ();
100   }
101   //
102   Double_t lxyz[3] = {0, 0, 0};
103   if (IsFrameTrk()) {
104     const TGeoHMatrix *mt = GetTracking2LocalMatrix();
105     if (!mt) return kFALSE;
106     Double_t txyz[3] = {GetX(), GetY(), GetZ()};
107     mt->LocalToMaster(txyz,lxyz);
108   }
109   else {
110     lxyz[0] = GetX(); lxyz[1] = GetY(); lxyz[2] = GetZ();
111   }
112   //
113   TGeoHMatrix *ml = GetMatrix();
114   if (!ml) return kFALSE;
115   Double_t gxyz[3] = {0, 0, 0};
116   ml->LocalToMaster(lxyz,gxyz);
117   xyz[0] = gxyz[0]; xyz[1] = gxyz[1]; xyz[2] = gxyz[2];
118   return kTRUE;
119 }
120
121 //______________________________________________________________________________
122 Bool_t AliITSUClusterPix::GetGlobalCov(Float_t cov[6]) const
123 {
124   // Get the global covariance matrix of the cluster coordinates
125   // All the needed information is taken only
126   // from TGeo.
127   // Note: regardless on in which frame the coordinates are, the errors are always in tracking frame
128   //
129   return AliCluster::GetGlobalCov(cov);
130 }
131
132 //______________________________________________________________________________
133 Bool_t AliITSUClusterPix::GetXRefPlane(Float_t &xref) const
134 {
135   // Get the distance between the origin and the ref.plane.
136   // All the needed information is taken only from TGeo.
137   return AliCluster::GetXRefPlane(xref);
138 }
139
140 //______________________________________________________________________________
141 void AliITSUClusterPix::GoToFrameGlo()
142 {
143   // convert to global frame
144   if (IsFrameGlo()) return;
145   double loc[3],glo[3];
146   //
147   if (IsFrameTrk()) {
148     double curr[3]={GetX(),GetY(),GetZ()};
149     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
150     ResetBit(kFrameTrk);
151   }
152   else {
153     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
154     ResetBit(kFrameLoc);
155   }
156   GetMatrix()->LocalToMaster(loc,glo);
157   SetX(glo[0]);  
158   SetY(glo[1]); 
159   SetZ(glo[2]);
160   SetBit(kFrameGlo);
161   //
162 }
163
164 //______________________________________________________________________________
165 void AliITSUClusterPix::GoToFrameLoc()
166 {
167   // convert to local frame
168   if (IsFrameLoc()) return;
169   //
170   double loc[3],glo[3];
171   if (IsFrameTrk()) {
172     double curr[3]={GetX(),GetY(),GetZ()};
173     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
174     ResetBit(kFrameTrk);
175   }
176   else {
177     glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
178     GetMatrix()->MasterToLocal(glo,loc);
179     ResetBit(kFrameLoc);
180   }
181   SetBit(kFrameLoc);
182   SetX(loc[0]); 
183   SetY(loc[1]); 
184   SetZ(loc[2]);
185   //
186 }
187
188 //______________________________________________________________________________
189 void AliITSUClusterPix::GetLocalXYZ(Float_t xyz[3]) const
190 {
191   // get local coordinates
192   if (IsFrameLoc()) {
193     xyz[0] = GetX(); xyz[1] = 0; xyz[2] = GetZ();
194     return;
195   }
196   double loc[3],glo[3];
197   if (IsFrameTrk()) {
198     double curr[3]={GetX(),GetY(),GetZ()};
199     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
200   }
201   else {
202     glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
203     GetMatrix()->MasterToLocal(glo,loc);
204   }
205   for (int i=3;i--;) xyz[i] = loc[i];
206   //
207 }
208
209 //______________________________________________________________________________
210 void AliITSUClusterPix::GoToFrameTrk()
211 {
212   // convert to tracking frame
213   if (IsFrameTrk()) return;
214   //
215   double loc[3],trk[3];
216   if (IsFrameGlo()) {
217     double glo[3]={GetX(),GetY(),GetZ()};
218     GetMatrix()->MasterToLocal(glo,loc);
219     ResetBit(kFrameGlo);
220   }
221   else {
222     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
223     ResetBit(kFrameLoc);    
224   }
225   // now in local frame
226   GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
227   SetBit(kFrameTrk);
228   SetX(trk[0]);  
229   SetY(trk[1]); 
230   SetZ(trk[2]);
231   //
232 }
233
234 //______________________________________________________________________________
235 void AliITSUClusterPix::GetTrackingXYZ(Float_t xyz[3]) const
236 {
237   // convert to tracking frame
238   if (IsFrameTrk()) {
239     xyz[0] = GetX(); xyz[1] = GetY(); xyz[2] = GetZ();
240     return;
241   }
242   //
243   double loc[3],trk[3];
244   if (IsFrameGlo()) {
245     double glo[3]={GetX(),GetY(),GetZ()};
246     GetMatrix()->MasterToLocal(glo,loc);
247   }
248   else {
249     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
250   }
251   // now in local frame
252   GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
253   for (int i=3;i--;) xyz[i] = trk[i];
254   //
255 }
256
257 //______________________________________________________________________________
258 Int_t AliITSUClusterPix::Compare(const TObject* obj)  const
259 {
260   // compare clusters accodring to specific mode
261   const AliITSUClusterPix* px = (const AliITSUClusterPix*)obj;
262   float xyz[3],xyz1[3];
263   if (fgMode & kSortIdLocXZ) { // sorting in local frame
264     if (GetVolumeId()==px->GetVolumeId()) {
265       GetLocalXYZ(xyz);
266       px->GetLocalXYZ(xyz1);
267       if (xyz[0]<xyz1[0]) return -1; // sort in X
268       if (xyz[0]>xyz1[0]) return  1;
269       if (xyz[2]<xyz1[2]) return -1; // then in Z
270       if (xyz[2]>xyz1[2]) return  1;
271       return 0;
272     }
273     return int(GetVolumeId())-int(px->GetVolumeId());
274   }
275   if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
276     if (GetVolumeId()==px->GetVolumeId()) {
277       GetTrackingXYZ(xyz);
278       px->GetTrackingXYZ(xyz1);
279       if (xyz[1]<xyz1[1]) return -1; // sort in Y
280       if (xyz[1]>xyz1[1]) return  1;
281       if (xyz[2]<xyz1[2]) return -1; // then in Z
282       if (xyz[2]>xyz1[2]) return  1;
283       return 0;    
284     }
285     return int(GetVolumeId())-int(px->GetVolumeId());    
286   }
287   AliFatal(Form("Unknown modr for sorting: %d",fgMode));
288   return 0;
289 }
290
291 //______________________________________________________________________________
292 Bool_t AliITSUClusterPix::IsEqual(const TObject* obj)  const
293 {
294   // compare clusters accodring to specific mode
295   const AliITSUClusterPix* px = (const AliITSUClusterPix*)obj;
296   const Float_t kTol = 1e-5;
297   float xyz[3],xyz1[3];
298   if (fgMode & kSortIdLocXZ) { // sorting in local frame
299     if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
300     GetLocalXYZ(xyz);
301     px->GetLocalXYZ(xyz1);
302     return (Abs(xyz[0]-xyz1[0])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
303   }
304   if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
305     if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
306     GetTrackingXYZ(xyz);
307     px->GetTrackingXYZ(xyz1);
308     return (Abs(xyz[1]-xyz1[1])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
309   }
310   AliFatal(Form("Unknown modr for sorting: %d",fgMode));
311   return kFALSE;
312 }
313
314 //______________________________________________________________________________
315 Bool_t AliITSUClusterPix::HasCommonTrack(const AliCluster* cl) const
316 {
317   // check if clusters have common tracks
318   int lbi,lbj;
319   for (int i=0;i<3;i++) {
320     if ((lbi=GetLabel(i))<0) break;
321     for (int j=0;j<3;j++) {
322       if ((lbj=cl->GetLabel(j))<0) break;
323       if (lbi==lbj) return kTRUE;
324     }
325   }
326   return kFALSE;
327 }