]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUClusterPix.cxx
Merge branch 'master' of https://git.cern.ch/reps/AliRoot
[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     return kTRUE;
101   }
102   //
103   Double_t lxyz[3] = {0, 0, 0};
104   if (IsFrameTrk()) {
105     const TGeoHMatrix *mt = GetTracking2LocalMatrix();
106     if (!mt) return kFALSE;
107     Double_t txyz[3] = {GetX(), GetY(), GetZ()};
108     mt->LocalToMaster(txyz,lxyz);
109   }
110   else {
111     lxyz[0] = GetX(); lxyz[1] = GetY(); lxyz[2] = GetZ();
112   }
113   //
114   TGeoHMatrix *ml = GetMatrix();
115   if (!ml) return kFALSE;
116   Double_t gxyz[3] = {0, 0, 0};
117   ml->LocalToMaster(lxyz,gxyz);
118   xyz[0] = gxyz[0]; xyz[1] = gxyz[1]; xyz[2] = gxyz[2];
119   return kTRUE;
120 }
121
122 //______________________________________________________________________________
123 Bool_t AliITSUClusterPix::GetGlobalCov(Float_t cov[6]) const
124 {
125   // Get the global covariance matrix of the cluster coordinates
126   // All the needed information is taken only
127   // from TGeo.
128   // Note: regardless on in which frame the coordinates are, the errors are always in tracking frame
129   //
130   return AliCluster::GetGlobalCov(cov);
131 }
132
133 //______________________________________________________________________________
134 Bool_t AliITSUClusterPix::GetXRefPlane(Float_t &xref) const
135 {
136   // Get the distance between the origin and the ref.plane.
137   // All the needed information is taken only from TGeo.
138   return AliCluster::GetXRefPlane(xref);
139 }
140
141 //______________________________________________________________________________
142 void AliITSUClusterPix::GoToFrameGlo()
143 {
144   // convert to global frame
145   if (IsFrameGlo()) return;
146   double loc[3],glo[3];
147   //
148   if (IsFrameTrk()) {
149     double curr[3]={GetX(),GetY(),GetZ()};
150     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
151     ResetBit(kFrameTrk);
152   }
153   else {
154     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
155     ResetBit(kFrameLoc);
156   }
157   GetMatrix()->LocalToMaster(loc,glo);
158   SetX(glo[0]);  
159   SetY(glo[1]); 
160   SetZ(glo[2]);
161   SetBit(kFrameGlo);
162   //
163 }
164
165 //______________________________________________________________________________
166 void AliITSUClusterPix::GoToFrameLoc()
167 {
168   // convert to local frame
169   if (IsFrameLoc()) return;
170   //
171   double loc[3],glo[3];
172   if (IsFrameTrk()) {
173     double curr[3]={GetX(),GetY(),GetZ()};
174     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
175     ResetBit(kFrameTrk);
176   }
177   else {
178     glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
179     GetMatrix()->MasterToLocal(glo,loc);
180     ResetBit(kFrameLoc);
181   }
182   SetBit(kFrameLoc);
183   SetX(loc[0]); 
184   SetY(loc[1]); 
185   SetZ(loc[2]);
186   //
187 }
188
189 //______________________________________________________________________________
190 void AliITSUClusterPix::GetLocalXYZ(Float_t xyz[3]) const
191 {
192   // get local coordinates
193   if (IsFrameLoc()) {
194     xyz[0] = GetX(); xyz[1] = 0; xyz[2] = GetZ();
195     return;
196   }
197   double loc[3],glo[3];
198   if (IsFrameTrk()) {
199     double curr[3]={GetX(),GetY(),GetZ()};
200     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
201   }
202   else {
203     glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
204     GetMatrix()->MasterToLocal(glo,loc);
205   }
206   for (int i=3;i--;) xyz[i] = loc[i];
207   //
208 }
209
210 //______________________________________________________________________________
211 void AliITSUClusterPix::GoToFrameTrk()
212 {
213   // convert to tracking frame
214   if (IsFrameTrk()) return;
215   //
216   double loc[3],trk[3];
217   if (IsFrameGlo()) {
218     double glo[3]={GetX(),GetY(),GetZ()};
219     GetMatrix()->MasterToLocal(glo,loc);
220     ResetBit(kFrameGlo);
221   }
222   else {
223     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
224     ResetBit(kFrameLoc);    
225   }
226   // now in local frame
227   GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
228   SetBit(kFrameTrk);
229   SetX(trk[0]);  
230   SetY(trk[1]); 
231   SetZ(trk[2]);
232   //
233 }
234
235 //______________________________________________________________________________
236 void AliITSUClusterPix::GetTrackingXYZ(Float_t xyz[3]) const
237 {
238   // convert to tracking frame
239   if (IsFrameTrk()) {
240     xyz[0] = GetX(); xyz[1] = GetY(); xyz[2] = GetZ();
241     return;
242   }
243   //
244   double loc[3],trk[3];
245   if (IsFrameGlo()) {
246     double glo[3]={GetX(),GetY(),GetZ()};
247     GetMatrix()->MasterToLocal(glo,loc);
248   }
249   else {
250     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
251   }
252   // now in local frame
253   GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
254   for (int i=3;i--;) xyz[i] = trk[i];
255   //
256 }
257
258 //______________________________________________________________________________
259 Int_t AliITSUClusterPix::Compare(const TObject* obj)  const
260 {
261   // compare clusters accodring to specific mode
262   const AliITSUClusterPix* px = (const AliITSUClusterPix*)obj;
263   float xyz[3],xyz1[3];
264   if (fgMode & kSortIdLocXZ) { // sorting in local frame
265     if (GetVolumeId()==px->GetVolumeId()) {
266       GetLocalXYZ(xyz);
267       px->GetLocalXYZ(xyz1);
268       if (xyz[0]<xyz1[0]) return -1; // sort in X
269       if (xyz[0]>xyz1[0]) return  1;
270       if (xyz[2]<xyz1[2]) return -1; // then in Z
271       if (xyz[2]>xyz1[2]) return  1;
272       return 0;
273     }
274     return int(GetVolumeId())-int(px->GetVolumeId());
275   }
276   if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
277     if (GetVolumeId()==px->GetVolumeId()) {
278       GetTrackingXYZ(xyz);
279       px->GetTrackingXYZ(xyz1);
280       if (xyz[1]<xyz1[1]) return -1; // sort in Y
281       if (xyz[1]>xyz1[1]) return  1;
282       if (xyz[2]<xyz1[2]) return -1; // then in Z
283       if (xyz[2]>xyz1[2]) return  1;
284       return 0;    
285     }
286     return int(GetVolumeId())-int(px->GetVolumeId());    
287   }
288   AliFatal(Form("Unknown modr for sorting: %d",fgMode));
289   return 0;
290 }
291
292 //______________________________________________________________________________
293 Bool_t AliITSUClusterPix::IsEqual(const TObject* obj)  const
294 {
295   // compare clusters accodring to specific mode
296   const AliITSUClusterPix* px = (const AliITSUClusterPix*)obj;
297   const Float_t kTol = 1e-5;
298   float xyz[3],xyz1[3];
299   if (fgMode & kSortIdLocXZ) { // sorting in local frame
300     if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
301     GetLocalXYZ(xyz);
302     px->GetLocalXYZ(xyz1);
303     return (Abs(xyz[0]-xyz1[0])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
304   }
305   if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
306     if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
307     GetTrackingXYZ(xyz);
308     px->GetTrackingXYZ(xyz1);
309     return (Abs(xyz[1]-xyz1[1])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
310   }
311   AliFatal(Form("Unknown modr for sorting: %d",fgMode));
312   return kFALSE;
313 }
314
315 //______________________________________________________________________________
316 Bool_t AliITSUClusterPix::HasCommonTrack(const AliCluster* cl) const
317 {
318   // check if clusters have common tracks
319   int lbi,lbj;
320   for (int i=0;i<3;i++) {
321     if ((lbi=GetLabel(i))<0) break;
322     for (int j=0;j<3;j++) {
323       if ((lbj=cl->GetLabel(j))<0) break;
324       if (lbi==lbj) return kTRUE;
325     }
326   }
327   return kFALSE;
328 }