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