1 #include "AliITSUClusterPix.h"
2 #include "AliITSUGeomTGeo.h"
4 #include <TGeoMatrix.h>
11 ClassImp(AliITSUClusterPix)
13 AliITSUGeomTGeo* AliITSUClusterPix::fgGeom = 0;
14 UInt_t AliITSUClusterPix::fgMode = 0;
16 //_____________________________________________________
17 AliITSUClusterPix::AliITSUClusterPix()
21 #ifdef _ClusterTopology_
28 // default constructor
29 #ifdef _ClusterTopology_
30 memset(fPattern,0,kMaxPatternBytes*sizeof(UChar_t));
35 //_____________________________________________________
36 AliITSUClusterPix::~AliITSUClusterPix()
41 //_____________________________________________________
42 AliITSUClusterPix::AliITSUClusterPix(const AliITSUClusterPix& cluster)
44 ,fCharge(cluster.fCharge)
45 ,fRecoInfo(cluster.fRecoInfo)
46 ,fNxNzN(cluster.fNxNzN)
47 #ifdef _ClusterTopology_
48 ,fPatternNRows(cluster.fPatternNRows)
49 ,fPatternNCols(cluster.fPatternNCols)
50 ,fPatternMinRow(cluster.fPatternMinRow)
51 ,fPatternMinCol(cluster.fPatternMinCol)
55 #ifdef _ClusterTopology_
56 memcpy(fPattern,cluster.fPattern,kMaxPatternBytes*sizeof(UChar_t));
60 //______________________________________________________________________________
61 AliITSUClusterPix& AliITSUClusterPix::operator=(const AliITSUClusterPix& cluster)
64 if(&cluster == this) return *this;
65 fNxNzN = cluster.fNxNzN;
66 fCharge = cluster.fCharge;
67 fRecoInfo = cluster.fRecoInfo;
69 #ifdef _ClusterTopology_
70 memcpy(fPattern,cluster.fPattern,kMaxPatternBytes*sizeof(UChar_t));
71 fPatternNRows = cluster.fPatternNRows;
72 fPatternNCols = cluster.fPatternNCols;
73 fPatternMinRow = cluster.fPatternMinRow;
74 fPatternMinCol = cluster.fPatternMinCol;
77 TObject::operator=(cluster);
78 AliCluster::operator=(cluster);
82 //______________________________________________________________________________
83 const TGeoHMatrix* AliITSUClusterPix::GetTracking2LocalMatrix() const
85 // get tracking to local matrix (sensor!!!)
86 return (TGeoHMatrix*)fgGeom->GetMatrixT2L(GetVolumeId());
89 //______________________________________________________________________________
90 TGeoHMatrix* AliITSUClusterPix::GetMatrix(Bool_t ) const
92 // get chip matrix (sensor!)
93 return (TGeoHMatrix*)fgGeom->GetMatrixSens(GetVolumeId());
96 //______________________________________________________________________________
97 void AliITSUClusterPix::Print(Option_t* option) const
99 // Print cluster information.
100 TString str = option;
102 printf("Cl.in mod %5d, nx:%3d nz:%3d n:%d |Err^2:%.3e %.3e %+.3e |",GetVolumeId(),GetNx(),GetNz(),
103 GetNPix(),GetSigmaY2(),GetSigmaZ2(),GetSigmaYZ());
104 printf("XYZ: (%+.4e %+.4e %+.4e ",GetX(),GetY(),GetZ());
105 if (IsFrameLoc()) printf("LOC)");
106 else if (IsFrameGlo()) printf("GLO)");
107 else if (IsFrameTrk()) printf("TRK)");
108 if (str.Contains("glo") && !IsFrameGlo() && fgGeom) {
111 printf(" (%+.4e %+.4e %+.4e GLO)",g[0],g[1],g[2]);
114 for (int i=0;i<3;i++) printf(" %5d",GetLabel(i));
115 if (TestBit(kSplit)) printf(" Spl");
118 #ifdef _ClusterTopology_
119 if (str.Contains("p")) { // print pattern
120 int nr = GetPatternRowSpan();
121 int nc = GetPatternColSpan();
122 printf("Pattern: %d rows from %d",nr,fPatternMinRow);
123 if (IsPatternRowsTruncated()) printf("(truncated)");
124 printf(", %d columns from %d",nc,fPatternMinCol);
125 if (IsPatternColsTruncated()) printf("(truncated)");
127 for (int ir=0;ir<nr;ir++) {
128 for (int ic=0;ic<nc;ic++) printf("%c",TestPixel(ir,ic) ? '+':'-');
136 #ifdef _ClusterTopology_
137 //______________________________________________________________________________
138 void AliITSUClusterPix::ResetPattern()
140 // reset pixels pattern
141 memset(fPattern,0,kMaxPatternBytes*sizeof(UChar_t));
144 //______________________________________________________________________________
145 Bool_t AliITSUClusterPix::TestPixel(UShort_t row,UShort_t col) const
147 // test if pixel at relative row,col is fired
148 int nbits = row*GetPatternColSpan()+col;
149 if (nbits>=kMaxPatternBits) return kFALSE;
150 int bytn = nbits>>3; // 1/8
152 return (fPattern[bytn]&(0x1<<bitn))!=0;
156 //______________________________________________________________________________
157 void AliITSUClusterPix::SetPixel(UShort_t row,UShort_t col, Bool_t fired)
159 // test if pixel at relative row,col is fired
160 int nbits = row*GetPatternColSpan()+col;
161 if (nbits>=kMaxPatternBits) return;
162 int bytn = nbits>>3; // 1/8
164 if (nbits>=kMaxPatternBits) exit(1);
165 if (fired) fPattern[bytn] |= (0x1<<bitn);
166 else fPattern[bytn] &= (0xff ^ (0x1<<bitn));
170 //______________________________________________________________________________
171 void AliITSUClusterPix::SetPatternRowSpan(UShort_t nr, Bool_t truncated)
173 // set pattern span in rows, flag if truncated
174 fPatternNRows = kSpanMask&nr;
175 if (truncated) fPatternNRows |= kTruncateMask;
178 //______________________________________________________________________________
179 void AliITSUClusterPix::SetPatternColSpan(UShort_t nc, Bool_t truncated)
181 // set pattern span in columns, flag if truncated
182 fPatternNCols = kSpanMask&nc;
183 if (truncated) fPatternNCols |= kTruncateMask;
188 //______________________________________________________________________________
189 Bool_t AliITSUClusterPix::GetGlobalXYZ(Float_t xyz[3]) const
191 // Get the global coordinates of the cluster
192 // All the needed information is taken only
193 // from TGeo (single precision).
201 Double_t lxyz[3] = {0, 0, 0};
203 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
204 if (!mt) return kFALSE;
205 Double_t txyz[3] = {GetX(), GetY(), GetZ()};
206 mt->LocalToMaster(txyz,lxyz);
209 lxyz[0] = GetX(); lxyz[1] = GetY(); lxyz[2] = GetZ();
212 TGeoHMatrix *ml = GetMatrix();
213 if (!ml) return kFALSE;
214 Double_t gxyz[3] = {0, 0, 0};
215 ml->LocalToMaster(lxyz,gxyz);
216 xyz[0] = gxyz[0]; xyz[1] = gxyz[1]; xyz[2] = gxyz[2];
220 //______________________________________________________________________________
221 Bool_t AliITSUClusterPix::GetGlobalXYZ(Double_t xyz[3]) const
223 // Get the global coordinates of the cluster
224 // All the needed information is taken only
225 // from TGeo (double precision).
233 Double_t lxyz[3] = {0, 0, 0};
235 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
236 if (!mt) return kFALSE;
237 Double_t txyz[3] = {GetX(), GetY(), GetZ()};
238 mt->LocalToMaster(txyz,lxyz);
241 lxyz[0] = GetX(); lxyz[1] = GetY(); lxyz[2] = GetZ();
244 TGeoHMatrix *ml = GetMatrix();
245 if (!ml) return kFALSE;
246 ml->LocalToMaster(lxyz,xyz);
251 //______________________________________________________________________________
252 Bool_t AliITSUClusterPix::GetGlobalCov(Float_t cov[6]) const
254 // Get the global covariance matrix of the cluster coordinates
255 // All the needed information is taken only
257 // Note: regardless on in which frame the coordinates are, the errors are always in tracking frame
259 return AliCluster::GetGlobalCov(cov);
262 //______________________________________________________________________________
263 Bool_t AliITSUClusterPix::GetXRefPlane(Float_t &xref) const
265 // Get the distance between the origin and the ref.plane.
266 // All the needed information is taken only from TGeo.
267 return AliCluster::GetXRefPlane(xref);
270 //______________________________________________________________________________
271 void AliITSUClusterPix::GoToFrameGlo()
273 // convert to global frame
274 if (IsFrameGlo()) return;
275 double loc[3],glo[3];
278 double curr[3]={GetX(),GetY(),GetZ()};
279 GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
283 loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
286 GetMatrix()->LocalToMaster(loc,glo);
294 //______________________________________________________________________________
295 void AliITSUClusterPix::GoToFrameLoc()
297 // convert to local frame
298 if (IsFrameLoc()) return;
300 double loc[3],glo[3];
302 double curr[3]={GetX(),GetY(),GetZ()};
303 GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
307 glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
308 GetMatrix()->MasterToLocal(glo,loc);
318 //______________________________________________________________________________
319 void AliITSUClusterPix::GetLocalXYZ(Float_t xyz[3]) const
321 // get local coordinates
323 xyz[0] = GetX(); xyz[1] = 0; xyz[2] = GetZ();
326 double loc[3],glo[3];
328 double curr[3]={GetX(),GetY(),GetZ()};
329 GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
332 glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
333 GetMatrix()->MasterToLocal(glo,loc);
335 for (int i=3;i--;) xyz[i] = loc[i];
339 //______________________________________________________________________________
340 void AliITSUClusterPix::GoToFrameTrk()
342 // convert to tracking frame
343 if (IsFrameTrk()) return;
345 double loc[3],trk[3];
347 double glo[3]={GetX(),GetY(),GetZ()};
348 GetMatrix()->MasterToLocal(glo,loc);
352 loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
355 // now in local frame
356 GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
364 //______________________________________________________________________________
365 void AliITSUClusterPix::GetTrackingXYZ(Float_t xyz[3]) const
367 // convert to tracking frame
369 xyz[0] = GetX(); xyz[1] = GetY(); xyz[2] = GetZ();
373 double loc[3],trk[3];
375 double glo[3]={GetX(),GetY(),GetZ()};
376 GetMatrix()->MasterToLocal(glo,loc);
379 loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
381 // now in local frame
382 GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
383 for (int i=3;i--;) xyz[i] = trk[i];
387 //______________________________________________________________________________
388 Int_t AliITSUClusterPix::Compare(const TObject* obj) const
390 // compare clusters accodring to specific mode
391 const AliITSUClusterPix* px = (const AliITSUClusterPix*)obj;
392 float xyz[3],xyz1[3];
393 if (fgMode & kSortIdLocXZ) { // sorting in local frame
394 if (GetVolumeId()==px->GetVolumeId()) {
396 px->GetLocalXYZ(xyz1);
397 if (xyz[0]<xyz1[0]) return -1; // sort in X
398 if (xyz[0]>xyz1[0]) return 1;
399 if (xyz[2]<xyz1[2]) return -1; // then in Z
400 if (xyz[2]>xyz1[2]) return 1;
403 return int(GetVolumeId())-int(px->GetVolumeId());
405 if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
406 if (GetVolumeId()==px->GetVolumeId()) {
408 px->GetTrackingXYZ(xyz1);
409 if (xyz[1]<xyz1[1]) return -1; // sort in Y
410 if (xyz[1]>xyz1[1]) return 1;
411 if (xyz[2]<xyz1[2]) return -1; // then in Z
412 if (xyz[2]>xyz1[2]) return 1;
415 return int(GetVolumeId())-int(px->GetVolumeId());
417 AliFatal(Form("Unknown modr for sorting: %d",fgMode));
421 //______________________________________________________________________________
422 Bool_t AliITSUClusterPix::IsEqual(const TObject* obj) const
424 // compare clusters accodring to specific mode
425 const AliITSUClusterPix* px = (const AliITSUClusterPix*)obj;
426 const Float_t kTol = 1e-5;
427 float xyz[3],xyz1[3];
428 if (fgMode & kSortIdLocXZ) { // sorting in local frame
429 if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
431 px->GetLocalXYZ(xyz1);
432 return (Abs(xyz[0]-xyz1[0])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
434 if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
435 if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
437 px->GetTrackingXYZ(xyz1);
438 return (Abs(xyz[1]-xyz1[1])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
440 AliFatal(Form("Unknown modr for sorting: %d",fgMode));
444 //______________________________________________________________________________
445 Bool_t AliITSUClusterPix::HasCommonTrack(const AliCluster* cl) const
447 // check if clusters have common tracks
449 for (int i=0;i<3;i++) {
450 if ((lbi=GetLabel(i))<0) break;
451 for (int j=0;j<3;j++) {
452 if ((lbj=cl->GetLabel(j))<0) break;
453 if (lbi==lbj) return kTRUE;