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