]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/UPGRADE/AliITSUClusterPix.cxx
fix typo
[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 #ifdef _ClusterTopology_
20   ,fPatternNRows(0)
21   ,fPatternNCols(0)
22   ,fPatternMinRow(0)
23   ,fPatternMinCol(0)
24 #endif
25 {
26   // default constructor
27 #ifdef _ClusterTopology_
28   memset(fPattern,0,kMaxPatternBytes*sizeof(UChar_t));
29 #endif
30
31 }
32
33 //_____________________________________________________
34 AliITSUClusterPix::~AliITSUClusterPix()
35 {
36   // default destructor
37 }
38
39 //_____________________________________________________
40 AliITSUClusterPix::AliITSUClusterPix(const AliITSUClusterPix& cluster) 
41   :AliCluster(cluster)
42   ,fCharge(cluster.fCharge)
43   ,fRecoInfo(cluster.fRecoInfo)
44   ,fNxNzN(cluster.fNxNzN)
45 #ifdef _ClusterTopology_
46   ,fPatternNRows(cluster.fPatternNRows)
47   ,fPatternNCols(cluster.fPatternNCols)
48   ,fPatternMinRow(cluster.fPatternMinRow)
49   ,fPatternMinCol(cluster.fPatternMinCol)
50 #endif
51 {
52   // copy constructor
53 #ifdef _ClusterTopology_
54   memcpy(fPattern,cluster.fPattern,kMaxPatternBytes*sizeof(UChar_t));
55 #endif
56 }
57
58 //______________________________________________________________________________
59 AliITSUClusterPix& AliITSUClusterPix::operator=(const AliITSUClusterPix& cluster)
60 {
61   // = op
62   if(&cluster == this) return *this;
63   fNxNzN = cluster.fNxNzN;
64   fCharge = cluster.fCharge;
65   fRecoInfo = cluster.fRecoInfo;
66   //
67 #ifdef _ClusterTopology_
68   memcpy(fPattern,cluster.fPattern,kMaxPatternBytes*sizeof(UChar_t));
69   fPatternNRows = cluster.fPatternNRows;
70   fPatternNCols = cluster.fPatternNCols;
71   fPatternMinRow = cluster.fPatternMinRow;
72   fPatternMinCol = cluster.fPatternMinCol;
73 #endif
74   //
75   TObject::operator=(cluster);
76   AliCluster::operator=(cluster);
77   return *this;
78 }
79
80 //______________________________________________________________________________
81 const TGeoHMatrix*  AliITSUClusterPix::GetTracking2LocalMatrix() const
82 {
83   // get tracking to local matrix (sensor!!!)
84   return (TGeoHMatrix*)fgGeom->GetMatrixT2L(GetVolumeId());
85 }
86
87 //______________________________________________________________________________
88 TGeoHMatrix* AliITSUClusterPix::GetMatrix(Bool_t ) const
89 {
90   // get chip matrix (sensor!)
91   return (TGeoHMatrix*)fgGeom->GetMatrixSens(GetVolumeId());
92 }
93
94 //______________________________________________________________________________
95 void AliITSUClusterPix::Print(Option_t* option) const
96 {
97   // Print cluster information.
98   TString str = option; 
99   str.ToLower();
100   printf("Cl.in mod %5d, nx:%3d nz:%3d n:%d |Err^2:%.3e %.3e %+.3e |",GetVolumeId(),GetNx(),GetNz(),
101          GetNPix(),GetSigmaY2(),GetSigmaZ2(),GetSigmaYZ());
102   printf("XYZ: (%+.4e %+.4e %+.4e ",GetX(),GetY(),GetZ());
103   if      (IsFrameLoc()) printf("LOC)");
104   else if (IsFrameGlo()) printf("GLO)");
105   else if (IsFrameTrk()) printf("TRK)");
106   if (str.Contains("glo") && !IsFrameGlo() && fgGeom) {
107     Float_t g[3];
108     GetGlobalXYZ(g);
109     printf(" (%+.4e %+.4e %+.4e GLO)",g[0],g[1],g[2]);
110   }
111   printf(" MClb:");
112   for (int i=0;i<3;i++) printf(" %5d",GetLabel(i));
113   if (TestBit(kSplit)) printf(" Spl");
114   printf("\n");
115   //
116 #ifdef _ClusterTopology_
117   if (str.Contains("p")) { // print pattern
118     int nr = GetPatternRowSpan();
119     int nc = GetPatternColSpan();    
120     printf("Pattern: %d rows from %d",nr,fPatternMinRow);
121     if (IsPatternRowsTruncated()) printf("(truncated)");
122     printf(", %d columns from %d",nc,fPatternMinCol);
123     if (IsPatternColsTruncated()) printf("(truncated)");
124     printf("\n");
125     for (int ir=0;ir<nr;ir++) {
126       for (int ic=0;ic<nc;ic++) printf("%c",TestPixel(ir,ic) ? '+':'-');
127       printf("\n");
128     }
129   }
130 #endif
131   //
132 }
133
134 #ifdef _ClusterTopology_
135 //______________________________________________________________________________
136 void AliITSUClusterPix::ResetPattern()
137 {
138   // reset pixels pattern
139   memset(fPattern,0,kMaxPatternBytes*sizeof(UChar_t));
140 }
141
142 //______________________________________________________________________________
143 Bool_t AliITSUClusterPix::TestPixel(UShort_t row,UShort_t col) const
144 {
145   // test if pixel at relative row,col is fired
146   int nbits = row*GetPatternColSpan()+col;
147   if (nbits>=kMaxPatternBits) return kFALSE;
148   int bytn = nbits>>3; // 1/8  
149   int bitn = nbits%8;
150   return (fPattern[bytn]&(0x1<<bitn))!=0;
151   //
152 }
153
154 //______________________________________________________________________________
155 void AliITSUClusterPix::SetPixel(UShort_t row,UShort_t col, Bool_t fired) 
156 {
157   // test if pixel at relative row,col is fired
158   int nbits = row*GetPatternColSpan()+col;
159   if (nbits>=kMaxPatternBits) return;
160   int bytn = nbits>>3; // 1/8  
161   int bitn = nbits%8;
162   if (nbits>=kMaxPatternBits) exit(1);
163   if (fired) fPattern[bytn] |= (0x1<<bitn);
164   else       fPattern[bytn] &= (0xff ^ (0x1<<bitn));
165   //
166 }
167
168 //______________________________________________________________________________
169 void AliITSUClusterPix::SetPatternRowSpan(UShort_t nr, Bool_t truncated)
170 {
171   // set pattern span in rows, flag if truncated
172   fPatternNRows = kSpanMask&nr;
173   if (truncated) fPatternNRows |= kTruncateMask; 
174 }
175
176 //______________________________________________________________________________
177 void AliITSUClusterPix::SetPatternColSpan(UShort_t nc, Bool_t truncated)
178 {
179   // set pattern span in columns, flag if truncated
180   fPatternNCols = kSpanMask&nc;
181   if (truncated) fPatternNCols |= kTruncateMask; 
182 }
183
184 #endif
185
186 //______________________________________________________________________________
187 Bool_t AliITSUClusterPix::GetGlobalXYZ(Float_t xyz[3]) const
188 {
189   // Get the global coordinates of the cluster
190   // All the needed information is taken only
191   // from TGeo (single precision).
192   if (IsFrameGlo()) {
193     xyz[0] = GetX();
194     xyz[1] = GetY();
195     xyz[2] = GetZ();
196     return kTRUE;
197   }
198   //
199   Double_t lxyz[3] = {0, 0, 0};
200   if (IsFrameTrk()) {
201     const TGeoHMatrix *mt = GetTracking2LocalMatrix();
202     if (!mt) return kFALSE;
203     Double_t txyz[3] = {GetX(), GetY(), GetZ()};
204     mt->LocalToMaster(txyz,lxyz);
205   }
206   else {
207     lxyz[0] = GetX(); lxyz[1] = GetY(); lxyz[2] = GetZ();
208   }
209   //
210   TGeoHMatrix *ml = GetMatrix();
211   if (!ml) return kFALSE;
212   Double_t gxyz[3] = {0, 0, 0};
213   ml->LocalToMaster(lxyz,gxyz);
214   xyz[0] = gxyz[0]; xyz[1] = gxyz[1]; xyz[2] = gxyz[2];
215   return kTRUE;
216 }
217
218 //______________________________________________________________________________
219 Bool_t AliITSUClusterPix::GetGlobalXYZ(Double_t xyz[3]) const
220 {
221   // Get the global coordinates of the cluster
222   // All the needed information is taken only
223   // from TGeo (double precision).
224   if (IsFrameGlo()) {
225     xyz[0] = GetX();
226     xyz[1] = GetY();
227     xyz[2] = GetZ();
228     return kTRUE;
229   }
230   //
231   Double_t lxyz[3] = {0, 0, 0};
232   if (IsFrameTrk()) {
233     const TGeoHMatrix *mt = GetTracking2LocalMatrix();
234     if (!mt) return kFALSE;
235     Double_t txyz[3] = {GetX(), GetY(), GetZ()};
236     mt->LocalToMaster(txyz,lxyz);
237   }
238   else {
239     lxyz[0] = GetX(); lxyz[1] = GetY(); lxyz[2] = GetZ();
240   }
241   //
242   TGeoHMatrix *ml = GetMatrix();
243   if (!ml) return kFALSE;
244   ml->LocalToMaster(lxyz,xyz);
245   return kTRUE;
246 }
247
248
249 //______________________________________________________________________________
250 Bool_t AliITSUClusterPix::GetGlobalCov(Float_t cov[6]) const
251 {
252   // Get the global covariance matrix of the cluster coordinates
253   // All the needed information is taken only
254   // from TGeo.
255   // Note: regardless on in which frame the coordinates are, the errors are always in tracking frame
256   //
257   return AliCluster::GetGlobalCov(cov);
258 }
259
260 //______________________________________________________________________________
261 Bool_t AliITSUClusterPix::GetXRefPlane(Float_t &xref) const
262 {
263   // Get the distance between the origin and the ref.plane.
264   // All the needed information is taken only from TGeo.
265   return AliCluster::GetXRefPlane(xref);
266 }
267
268 //______________________________________________________________________________
269 void AliITSUClusterPix::GoToFrameGlo()
270 {
271   // convert to global frame
272   if (IsFrameGlo()) return;
273   double loc[3],glo[3];
274   //
275   if (IsFrameTrk()) {
276     double curr[3]={GetX(),GetY(),GetZ()};
277     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
278     ResetBit(kFrameTrk);
279   }
280   else {
281     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
282     ResetBit(kFrameLoc);
283   }
284   GetMatrix()->LocalToMaster(loc,glo);
285   SetX(glo[0]);  
286   SetY(glo[1]); 
287   SetZ(glo[2]);
288   SetBit(kFrameGlo);
289   //
290 }
291
292 //______________________________________________________________________________
293 void AliITSUClusterPix::GoToFrameLoc()
294 {
295   // convert to local frame
296   if (IsFrameLoc()) return;
297   //
298   double loc[3],glo[3];
299   if (IsFrameTrk()) {
300     double curr[3]={GetX(),GetY(),GetZ()};
301     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
302     ResetBit(kFrameTrk);
303   }
304   else {
305     glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
306     GetMatrix()->MasterToLocal(glo,loc);
307     ResetBit(kFrameLoc);
308   }
309   SetBit(kFrameLoc);
310   SetX(loc[0]); 
311   SetY(loc[1]); 
312   SetZ(loc[2]);
313   //
314 }
315
316 //______________________________________________________________________________
317 void AliITSUClusterPix::GetLocalXYZ(Float_t xyz[3]) const
318 {
319   // get local coordinates
320   if (IsFrameLoc()) {
321     xyz[0] = GetX(); xyz[1] = 0; xyz[2] = GetZ();
322     return;
323   }
324   double loc[3],glo[3];
325   if (IsFrameTrk()) {
326     double curr[3]={GetX(),GetY(),GetZ()};
327     GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
328   }
329   else {
330     glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
331     GetMatrix()->MasterToLocal(glo,loc);
332   }
333   for (int i=3;i--;) xyz[i] = loc[i];
334   //
335 }
336
337 //______________________________________________________________________________
338 void AliITSUClusterPix::GoToFrameTrk()
339 {
340   // convert to tracking frame
341   if (IsFrameTrk()) return;
342   //
343   double loc[3],trk[3];
344   if (IsFrameGlo()) {
345     double glo[3]={GetX(),GetY(),GetZ()};
346     GetMatrix()->MasterToLocal(glo,loc);
347     ResetBit(kFrameGlo);
348   }
349   else {
350     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
351     ResetBit(kFrameLoc);    
352   }
353   // now in local frame
354   GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
355   SetBit(kFrameTrk);
356   SetX(trk[0]);  
357   SetY(trk[1]); 
358   SetZ(trk[2]);
359   //
360 }
361
362 //______________________________________________________________________________
363 void AliITSUClusterPix::GetTrackingXYZ(Float_t xyz[3]) const
364 {
365   // convert to tracking frame
366   if (IsFrameTrk()) {
367     xyz[0] = GetX(); xyz[1] = GetY(); xyz[2] = GetZ();
368     return;
369   }
370   //
371   double loc[3],trk[3];
372   if (IsFrameGlo()) {
373     double glo[3]={GetX(),GetY(),GetZ()};
374     GetMatrix()->MasterToLocal(glo,loc);
375   }
376   else {
377     loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
378   }
379   // now in local frame
380   GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
381   for (int i=3;i--;) xyz[i] = trk[i];
382   //
383 }
384
385 //______________________________________________________________________________
386 Int_t AliITSUClusterPix::Compare(const TObject* obj)  const
387 {
388   // compare clusters accodring to specific mode
389   const AliITSUClusterPix* px = (const AliITSUClusterPix*)obj;
390   float xyz[3],xyz1[3];
391   if (fgMode & kSortIdLocXZ) { // sorting in local frame
392     if (GetVolumeId()==px->GetVolumeId()) {
393       GetLocalXYZ(xyz);
394       px->GetLocalXYZ(xyz1);
395       if (xyz[0]<xyz1[0]) return -1; // sort in X
396       if (xyz[0]>xyz1[0]) return  1;
397       if (xyz[2]<xyz1[2]) return -1; // then in Z
398       if (xyz[2]>xyz1[2]) return  1;
399       return 0;
400     }
401     return int(GetVolumeId())-int(px->GetVolumeId());
402   }
403   if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
404     if (GetVolumeId()==px->GetVolumeId()) {
405       GetTrackingXYZ(xyz);
406       px->GetTrackingXYZ(xyz1);
407       if (xyz[1]<xyz1[1]) return -1; // sort in Y
408       if (xyz[1]>xyz1[1]) return  1;
409       if (xyz[2]<xyz1[2]) return -1; // then in Z
410       if (xyz[2]>xyz1[2]) return  1;
411       return 0;    
412     }
413     return int(GetVolumeId())-int(px->GetVolumeId());    
414   }
415   AliFatal(Form("Unknown modr for sorting: %d",fgMode));
416   return 0;
417 }
418
419 //______________________________________________________________________________
420 Bool_t AliITSUClusterPix::IsEqual(const TObject* obj)  const
421 {
422   // compare clusters accodring to specific mode
423   const AliITSUClusterPix* px = (const AliITSUClusterPix*)obj;
424   const Float_t kTol = 1e-5;
425   float xyz[3],xyz1[3];
426   if (fgMode & kSortIdLocXZ) { // sorting in local frame
427     if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
428     GetLocalXYZ(xyz);
429     px->GetLocalXYZ(xyz1);
430     return (Abs(xyz[0]-xyz1[0])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
431   }
432   if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
433     if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
434     GetTrackingXYZ(xyz);
435     px->GetTrackingXYZ(xyz1);
436     return (Abs(xyz[1]-xyz1[1])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
437   }
438   AliFatal(Form("Unknown modr for sorting: %d",fgMode));
439   return kFALSE;
440 }
441
442 //______________________________________________________________________________
443 Bool_t AliITSUClusterPix::HasCommonTrack(const AliCluster* cl) const
444 {
445   // check if clusters have common tracks
446   int lbi,lbj;
447   for (int i=0;i<3;i++) {
448     if ((lbi=GetLabel(i))<0) break;
449     for (int j=0;j<3;j++) {
450       if ((lbj=cl->GetLabel(j))<0) break;
451       if (lbi==lbj) return kTRUE;
452     }
453   }
454   return kFALSE;
455 }