1 #include "AliITSUClusterPix.h"
2 #include "AliITSUGeomTGeo.h"
4 #include <TGeoMatrix.h>
9 ClassImp(AliITSUClusterPix)
11 AliITSUGeomTGeo* AliITSUClusterPix::fgGeom = 0;
12 UInt_t AliITSUClusterPix::fgMode = 0;
14 //_____________________________________________________
15 AliITSUClusterPix::AliITSUClusterPix()
19 #ifdef _ClusterTopology_
26 // default constructor
27 #ifdef _ClusterTopology_
28 memset(fPattern,0,kMaxPatternBytes*sizeof(UChar_t));
33 //_____________________________________________________
34 AliITSUClusterPix::~AliITSUClusterPix()
39 //_____________________________________________________
40 AliITSUClusterPix::AliITSUClusterPix(const AliITSUClusterPix& 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)
53 #ifdef _ClusterTopology_
54 memcpy(fPattern,cluster.fPattern,kMaxPatternBytes*sizeof(UChar_t));
58 //______________________________________________________________________________
59 AliITSUClusterPix& AliITSUClusterPix::operator=(const AliITSUClusterPix& cluster)
62 if(&cluster == this) return *this;
63 fNxNzN = cluster.fNxNzN;
64 fCharge = cluster.fCharge;
65 fRecoInfo = cluster.fRecoInfo;
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;
75 TObject::operator=(cluster);
76 AliCluster::operator=(cluster);
80 //______________________________________________________________________________
81 const TGeoHMatrix* AliITSUClusterPix::GetTracking2LocalMatrix() const
83 // get tracking to local matrix (sensor!!!)
84 return (TGeoHMatrix*)fgGeom->GetMatrixT2L(GetVolumeId());
87 //______________________________________________________________________________
88 TGeoHMatrix* AliITSUClusterPix::GetMatrix(Bool_t ) const
90 // get chip matrix (sensor!)
91 return (TGeoHMatrix*)fgGeom->GetMatrixSens(GetVolumeId());
94 //______________________________________________________________________________
95 void AliITSUClusterPix::Print(Option_t* option) const
97 // Print cluster information.
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) {
109 printf(" (%+.4e %+.4e %+.4e GLO)",g[0],g[1],g[2]);
112 for (int i=0;i<3;i++) printf(" %5d",GetLabel(i));
113 if (TestBit(kSplit)) printf(" Spl");
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)");
125 for (int ir=0;ir<nr;ir++) {
126 for (int ic=0;ic<nc;ic++) printf("%c",TestPixel(ir,ic) ? '+':'-');
134 #ifdef _ClusterTopology_
135 //______________________________________________________________________________
136 void AliITSUClusterPix::ResetPattern()
138 // reset pixels pattern
139 memset(fPattern,0,kMaxPatternBytes*sizeof(UChar_t));
142 //______________________________________________________________________________
143 Bool_t AliITSUClusterPix::TestPixel(UShort_t row,UShort_t col) const
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
150 return (fPattern[bytn]&(0x1<<bitn))!=0;
154 //______________________________________________________________________________
155 void AliITSUClusterPix::SetPixel(UShort_t row,UShort_t col, Bool_t fired)
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
162 if (nbits>=kMaxPatternBits) exit(1);
163 if (fired) fPattern[bytn] |= (0x1<<bitn);
164 else fPattern[bytn] &= (0xff ^ (0x1<<bitn));
168 //______________________________________________________________________________
169 void AliITSUClusterPix::SetPatternRowSpan(UShort_t nr, Bool_t truncated)
171 // set pattern span in rows, flag if truncated
172 fPatternNRows = kSpanMask&nr;
173 if (truncated) fPatternNRows |= kTruncateMask;
176 //______________________________________________________________________________
177 void AliITSUClusterPix::SetPatternColSpan(UShort_t nc, Bool_t truncated)
179 // set pattern span in columns, flag if truncated
180 fPatternNCols = kSpanMask&nc;
181 if (truncated) fPatternNCols |= kTruncateMask;
186 //______________________________________________________________________________
187 Bool_t AliITSUClusterPix::GetGlobalXYZ(Float_t xyz[3]) const
189 // Get the global coordinates of the cluster
190 // All the needed information is taken only
191 // from TGeo (single precision).
199 Double_t lxyz[3] = {0, 0, 0};
201 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
202 if (!mt) return kFALSE;
203 Double_t txyz[3] = {GetX(), GetY(), GetZ()};
204 mt->LocalToMaster(txyz,lxyz);
207 lxyz[0] = GetX(); lxyz[1] = GetY(); lxyz[2] = GetZ();
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];
218 //______________________________________________________________________________
219 Bool_t AliITSUClusterPix::GetGlobalXYZ(Double_t xyz[3]) const
221 // Get the global coordinates of the cluster
222 // All the needed information is taken only
223 // from TGeo (double precision).
231 Double_t lxyz[3] = {0, 0, 0};
233 const TGeoHMatrix *mt = GetTracking2LocalMatrix();
234 if (!mt) return kFALSE;
235 Double_t txyz[3] = {GetX(), GetY(), GetZ()};
236 mt->LocalToMaster(txyz,lxyz);
239 lxyz[0] = GetX(); lxyz[1] = GetY(); lxyz[2] = GetZ();
242 TGeoHMatrix *ml = GetMatrix();
243 if (!ml) return kFALSE;
244 ml->LocalToMaster(lxyz,xyz);
249 //______________________________________________________________________________
250 Bool_t AliITSUClusterPix::GetGlobalCov(Float_t cov[6]) const
252 // Get the global covariance matrix of the cluster coordinates
253 // All the needed information is taken only
255 // Note: regardless on in which frame the coordinates are, the errors are always in tracking frame
257 return AliCluster::GetGlobalCov(cov);
260 //______________________________________________________________________________
261 Bool_t AliITSUClusterPix::GetXRefPlane(Float_t &xref) const
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);
268 //______________________________________________________________________________
269 void AliITSUClusterPix::GoToFrameGlo()
271 // convert to global frame
272 if (IsFrameGlo()) return;
273 double loc[3],glo[3];
276 double curr[3]={GetX(),GetY(),GetZ()};
277 GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
281 loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
284 GetMatrix()->LocalToMaster(loc,glo);
292 //______________________________________________________________________________
293 void AliITSUClusterPix::GoToFrameLoc()
295 // convert to local frame
296 if (IsFrameLoc()) return;
298 double loc[3],glo[3];
300 double curr[3]={GetX(),GetY(),GetZ()};
301 GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
305 glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
306 GetMatrix()->MasterToLocal(glo,loc);
316 //______________________________________________________________________________
317 void AliITSUClusterPix::GetLocalXYZ(Float_t xyz[3]) const
319 // get local coordinates
321 xyz[0] = GetX(); xyz[1] = 0; xyz[2] = GetZ();
324 double loc[3],glo[3];
326 double curr[3]={GetX(),GetY(),GetZ()};
327 GetTracking2LocalMatrix()->LocalToMaster(curr,loc);
330 glo[0] = GetX(); glo[1] = GetY(); glo[2] = GetZ();
331 GetMatrix()->MasterToLocal(glo,loc);
333 for (int i=3;i--;) xyz[i] = loc[i];
337 //______________________________________________________________________________
338 void AliITSUClusterPix::GoToFrameTrk()
340 // convert to tracking frame
341 if (IsFrameTrk()) return;
343 double loc[3],trk[3];
345 double glo[3]={GetX(),GetY(),GetZ()};
346 GetMatrix()->MasterToLocal(glo,loc);
350 loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
353 // now in local frame
354 GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
362 //______________________________________________________________________________
363 void AliITSUClusterPix::GetTrackingXYZ(Float_t xyz[3]) const
365 // convert to tracking frame
367 xyz[0] = GetX(); xyz[1] = GetY(); xyz[2] = GetZ();
371 double loc[3],trk[3];
373 double glo[3]={GetX(),GetY(),GetZ()};
374 GetMatrix()->MasterToLocal(glo,loc);
377 loc[0] = GetX(); loc[1] = GetY(); loc[2] = GetZ();
379 // now in local frame
380 GetTracking2LocalMatrix()->MasterToLocal(loc,trk);
381 for (int i=3;i--;) xyz[i] = trk[i];
385 //______________________________________________________________________________
386 Int_t AliITSUClusterPix::Compare(const TObject* obj) const
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()) {
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;
401 return int(GetVolumeId())-int(px->GetVolumeId());
403 if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
404 if (GetVolumeId()==px->GetVolumeId()) {
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;
413 return int(GetVolumeId())-int(px->GetVolumeId());
415 AliFatal(Form("Unknown modr for sorting: %d",fgMode));
419 //______________________________________________________________________________
420 Bool_t AliITSUClusterPix::IsEqual(const TObject* obj) const
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;
429 px->GetLocalXYZ(xyz1);
430 return (Abs(xyz[0]-xyz1[0])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
432 if (fgMode & kSortIdTrkYZ) { // sorting in tracking frame
433 if (GetVolumeId()!=px->GetVolumeId()) return kFALSE;
435 px->GetTrackingXYZ(xyz1);
436 return (Abs(xyz[1]-xyz1[1])<kTol && Abs(xyz[2]-xyz1[2])<kTol) ? kTRUE : kFALSE;
438 AliFatal(Form("Unknown modr for sorting: %d",fgMode));
442 //______________________________________________________________________________
443 Bool_t AliITSUClusterPix::HasCommonTrack(const AliCluster* cl) const
445 // check if clusters have common tracks
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;