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