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