1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
18 ////////////////////////////////////////////////////////////////////////////
20 // Base Class used to find //
21 // the reconstructed points for ITS Upgrade //
23 ////////////////////////////////////////////////////////////////////////////
25 #include "AliITSUpgradeClusterFinder.h"
26 #include "AliITSRawStreamSPD.h"
29 #include <TObjString.h>
32 AliITSUpgradeClusterFinder::AliITSUpgradeClusterFinder() :
35 fClusterTypeFlag(kTRUE),
36 fFindClusterType(kFALSE),
37 fClusterTypeOrigCol(0),
38 fClusterTypeOrigRow(0),
39 fColSum(0),fRowSum(0),
41 fClusterWidthMaxCol(0),
42 fClusterWidthMinCol(0),
43 fClusterWidthMaxRow(0),
44 fClusterWidthMinRow(0),
47 fChargeArray = new TObjArray();
51 for(int il=0; il<10;il++) fLabels[il]=-5;
54 //___________________________________________________________________________________
55 AliITSUpgradeClusterFinder::~AliITSUpgradeClusterFinder() {}
56 //___________________________________________________________________________________
57 void AliITSUpgradeClusterFinder::StartEvent() {
60 //___________________________________________________________________________________
61 Int_t AliITSUpgradeClusterFinder::ProcessHitOnline(Int_t layer, UInt_t col, UInt_t row, UShort_t charge, Int_t label[3]) {
63 return ProcessHit(layer,col,row, charge, label);
66 printf("ERROR: UpgradeClusterFinder::ProcessHitOnline: Out of bounds: layer,col,row, charge = %d,%d,%d,%d\n",layer ,col,row,charge);
70 //___________________________________________________________________________________
71 Int_t AliITSUpgradeClusterFinder::ProcessHit(Int_t layer , UInt_t col, UInt_t row, UShort_t charge, Int_t label[3]) {
74 printf("ERROR: UpgradeClusterFinder::ProcessHit: Out of bounds: layer ,col,row, charge, label(0,1,2)= %d,%d,%d,%d,(%d,%d,%d)\n",layer ,col,row,charge,label[0],label[1],label[2]);
78 // do we need to perform clustering on previous module?
79 if (fOldModule!=-1 && (Int_t)layer!=fOldModule) {
80 fChargeArray->AddLast(new TObjString(Form("%i %i %i %i %i %i",col,row,charge,label[0],label[1],label[2])));
81 DoModuleClustering(fOldModule,charge);
85 fChargeArray->AddLast(new TObjString(Form("%i %i %i %i %i %i",col,row,charge,label[0],label[1],label[2])));
88 fHitCol[fNhitsLeft]=col;
89 fHitRow[fNhitsLeft]=row;
90 fHits[col][row]=kTRUE;
91 fTmpLabel[0]=label[0];
92 fTmpLabel[1]=label[1];
93 fTmpLabel[2]=label[2];
97 //___________________________________________________________________________________
98 void AliITSUpgradeClusterFinder::FinishEvent() {
100 DoModuleClustering(fOldModule,fCharge);
103 //___________________________________________________________________________________
104 UInt_t AliITSUpgradeClusterFinder::GetClusterCount(Int_t layer) {
106 printf("ERROR: UpgradeClusterFinder::GetClusterCount: Module out of bounds: layer = %d\n",layer);
109 return fClusterList[layer].GetNrEntries();
111 //___________________________________________________________________________________
112 Float_t AliITSUpgradeClusterFinder::GetClusterMeanCol(Int_t layer, UInt_t index) {
114 printf("ERROR: UpgradeClusterFinder::GetClusterMeanCol: Module out of bounds: layer = %d\n",layer);
117 return fClusterList[layer].GetColIndex(index);
119 //___________________________________________________________________________________
120 Float_t AliITSUpgradeClusterFinder::GetClusterMeanRow(Int_t layer, UInt_t index) {
122 printf("ERROR: UpgradeClusterFinder::GetClusterMeanRow: Module out of bounds: layer = %d\n",layer);
125 return fClusterList[layer].GetRowIndex(index);
127 //___________________________________________________________________________________
128 UInt_t AliITSUpgradeClusterFinder::GetClusterSize(Int_t layer, UInt_t index) {
130 printf("ERROR: UpgradeClusterFinder::GetClusterSize: Module out of bounds: layer = %d\n",layer);
133 return fClusterList[layer].GetSizeIndex(index);
135 //___________________________________________________________________________________
136 UInt_t AliITSUpgradeClusterFinder::GetClusterWidthZ(Int_t layer, UInt_t index) {
138 printf("ERROR: UpgradeClusterFinder::GetClusterWidthZ: Module out of bounds: layer = %d\n",layer);
141 return fClusterList[layer].GetWidthZIndex(index);
143 //___________________________________________________________________________________
144 UInt_t AliITSUpgradeClusterFinder::GetClusterWidthPhi(Int_t layer, UInt_t index) {
146 printf("ERROR: UpgradeClusterFinder::GetClusterWidthPhi: Module out of bounds: layer = %d\n",layer);
149 return fClusterList[layer].GetWidthPhiIndex(index);
151 //___________________________________________________________________________________
152 UInt_t AliITSUpgradeClusterFinder::GetClusterType(Int_t layer, UInt_t index) {
154 printf("ERROR: UpgradeClusterFinder::GetClusterType: Module out of bounds: layer = %d\n",layer);
157 return fClusterList[layer].GetTypeIndex(index);
159 //___________________________________________________________________________________
160 void AliITSUpgradeClusterFinder::PrintAllClusters() {
161 for (Int_t layer=0; layer<6; layer++) {
162 PrintClusters(layer);
165 //___________________________________________________________________________________
166 void AliITSUpgradeClusterFinder::PrintClusters(Int_t layer) {
168 printf("ERROR: UpgradeClusterFinder::PrintClusters: Out of bounds: layer = %d\n",layer);
171 if(fClusterList[layer].GetNrEntries()==0) {
172 printf("no cluster list entries. Exiting... \n");
175 for (UInt_t c=0; c<fClusterList[layer].GetNrEntries(); c++) {
176 printf("layer %d , z,y=%f,%f , size=%d , type=%d labels=%d %d %d (label printout to be implemented...)\n",layer,fClusterList[layer].GetColIndex(c),fClusterList[layer].GetRowIndex(c),fClusterList[layer].GetSizeIndex(c),fClusterList[layer].GetTypeIndex(c),999,999,999);
179 //___________________________________________________________________________________
180 void AliITSUpgradeClusterFinder::NewEvent() {
181 for (Int_t i=0; i<6; i++) {
182 fClusterList[i].Clear();
187 //___________________________________________________________________________________
188 void AliITSUpgradeClusterFinder::NewModule() {
190 memset(fHits,0,999*999*sizeof(Bool_t));
192 //___________________________________________________________________________________
193 Int_t AliITSUpgradeClusterFinder::DoModuleClustering(Int_t Layer, UShort_t charge) {
194 UInt_t maxHits=fNhitsLeft;
195 for (UInt_t hit=0; hit<maxHits; hit++) {
196 if (fClusterTypeFlag) fFindClusterType = kTRUE;
198 fClusterWidthMinCol = fHitCol[hit];
199 fClusterWidthMinRow = fHitRow[hit];
200 fClusterWidthMaxCol = fHitCol[hit];
201 fClusterWidthMaxRow = fHitRow[hit];
204 fClusterTypeOrigCol = fHitCol[hit];
205 fClusterTypeOrigRow = fHitRow[hit];
206 memset(fClusterTypeArea,0,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
209 UInt_t size = FindClusterRecu(fClusterTypeOrigCol,fClusterTypeOrigRow,charge);
212 fCharge=GetPixelCharge(fColSum,fRowSum);
213 AddLabelIndex(fColSum,fRowSum);
216 if(size==2) printf("DoModuleClustering, size 2, labels : %i %i %i \n",fLabels[0],fLabels[1],fLabels[2]);
217 fClusterList[Layer].Insert((Float_t)fColSum/size, (Float_t)fRowSum/size, size, GetClusterWidthZ(), GetClusterWidthPhi(), GetClusterType(size), fCharge,fLabels);
219 for(Int_t i=0; i<10; i++) fLabels[i]=-5;
221 if (fNhitsLeft==0) break;
225 //___________________________________________________________________________________
226 UInt_t AliITSUpgradeClusterFinder::FindClusterRecu(Int_t col, Int_t row, UShort_t charge) {
227 if (col<0 || !fHits[col][row]) {return 0;}
228 fHits[col][row]=kFALSE;
234 if (col>fClusterWidthMaxCol) fClusterWidthMaxCol = col;
235 if (col<fClusterWidthMinCol) fClusterWidthMinCol = col;
236 if (row>fClusterWidthMaxRow) fClusterWidthMaxRow = row;
237 if (row<fClusterWidthMaxRow) fClusterWidthMinRow = row;
239 if (fFindClusterType) {
240 Short_t diffz = fClusterTypeOrigCol - col;
241 Short_t diffy = row - fClusterTypeOrigRow;
242 if (diffz>=kMAXCLUSTERTYPESIDEZ || diffy>=kMAXCLUSTERTYPESIDEY) {
243 fFindClusterType=kFALSE;
247 ShiftClusterTypeArea(kSHIFTRIGHT);
251 ShiftClusterTypeArea(kSHIFTDOWN);
254 fClusterTypeArea[diffz][diffy] = kTRUE;
258 size+=FindClusterRecu(col ,row-1,charge);
259 fCharge+=GetPixelCharge(col,row-1);
260 AddLabelIndex(col,row-1);
262 size+=FindClusterRecu(col-1,row ,charge);
263 fCharge+=GetPixelCharge(col-1,row);
264 AddLabelIndex(col-1,row);
266 size+=FindClusterRecu(col ,row+1,charge);
267 fCharge+=GetPixelCharge(col,row+1);
268 AddLabelIndex(col,row+1);
270 size+=FindClusterRecu(col+1,row ,charge );
271 fCharge+=GetPixelCharge(col+1,row);
272 AddLabelIndex(col+1,row);
275 size+=FindClusterRecu(col-1,row-1,charge);
276 fCharge+=GetPixelCharge(col-1,row-1);
277 AddLabelIndex(col-1,row-1);
279 size+=FindClusterRecu(col-1,row+1,charge);
280 fCharge+=GetPixelCharge(col-1,row+1);
281 AddLabelIndex(col-1,row+1);
283 size+=FindClusterRecu(col+1,row-1,charge);
284 fCharge+=GetPixelCharge(col+1,row-1);
285 AddLabelIndex(col+1,row-1);
287 size+=FindClusterRecu(col+1,row+1,charge);
288 fCharge+=GetPixelCharge(col+1,row+1);
289 AddLabelIndex(col+1,row+1);
293 //___________________________________________________________________________________
294 void AliITSUpgradeClusterFinder::ShiftClusterTypeArea(UInt_t direction) {
295 if (direction == kSHIFTRIGHT) {
296 fClusterTypeOrigCol++;
297 Bool_t tmpClusterTypeArea[kMAXCLUSTERTYPESIDEZ][kMAXCLUSTERTYPESIDEY];
298 memset(tmpClusterTypeArea,0,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
299 for (UInt_t z=0; z<kMAXCLUSTERTYPESIDEZ; z++) {
300 for (UInt_t y=0; y<kMAXCLUSTERTYPESIDEY; y++) {
301 if (fClusterTypeArea[z][y]) {
302 if (z==kMAXCLUSTERTYPESIDEZ-1) {
303 fFindClusterType=kFALSE;
307 tmpClusterTypeArea[z+1][y] = kTRUE;
312 memcpy(fClusterTypeArea,tmpClusterTypeArea,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
314 else if (direction == kSHIFTDOWN) {
315 fClusterTypeOrigRow--;
316 Bool_t tmpClusterTypeArea[kMAXCLUSTERTYPESIDEZ][kMAXCLUSTERTYPESIDEY];
317 memset(tmpClusterTypeArea,0,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
318 for (UInt_t z=0; z<kMAXCLUSTERTYPESIDEZ; z++) {
319 for (UInt_t y=0; y<kMAXCLUSTERTYPESIDEY; y++) {
320 if (fClusterTypeArea[z][y]) {
321 if (y==kMAXCLUSTERTYPESIDEY-1) {
322 fFindClusterType=kFALSE;
326 tmpClusterTypeArea[z][y+1] = kTRUE;
331 memcpy(fClusterTypeArea,tmpClusterTypeArea,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
337 //___________________________________________________________________________________
338 UShort_t AliITSUpgradeClusterFinder::GetCharge(Int_t layer,UInt_t index ) {
339 return fClusterList[layer].GetCharge(index);
341 //___________________________________________________________________________________
342 Int_t * AliITSUpgradeClusterFinder::GetLabels(Int_t layer,UInt_t index) {
343 return fClusterList[layer].GetLabels(index);
346 //___________________________________________________________________________________
347 UInt_t AliITSUpgradeClusterFinder::GetClusterWidthZ() {
348 return fClusterWidthMaxCol-fClusterWidthMinCol+1;
350 //___________________________________________________________________________________
351 UInt_t AliITSUpgradeClusterFinder::GetClusterWidthPhi() {
352 return fClusterWidthMaxRow-fClusterWidthMinRow+1;
354 //___________________________________________________________________________________
355 UInt_t AliITSUpgradeClusterFinder::GetClusterType(UInt_t size) {
357 if (!fFindClusterType || size>4)
367 fClusterTypeArea[0][1] &&
368 fClusterTypeArea[0][0] )
373 fClusterTypeArea[1][0] &&
374 fClusterTypeArea[0][0] )
381 fClusterTypeArea[0][2] &&
382 fClusterTypeArea[0][1] &&
383 fClusterTypeArea[0][0] )
387 // X and equivalent...
391 fClusterTypeArea[0][0] &&
392 fClusterTypeArea[0][1] &&
393 (fClusterTypeArea[1][1] ||
394 fClusterTypeArea[1][0])
398 fClusterTypeArea[1][0] &&
399 fClusterTypeArea[1][1] &&
400 (fClusterTypeArea[0][1] ||
401 fClusterTypeArea[0][0])
409 fClusterTypeArea[2][0] &&
410 fClusterTypeArea[1][0] &&
411 fClusterTypeArea[0][0] )
419 fClusterTypeArea[0][3] &&
420 fClusterTypeArea[0][2] &&
421 fClusterTypeArea[0][1] &&
422 fClusterTypeArea[0][0] )
428 fClusterTypeArea[1][1] &&
429 fClusterTypeArea[1][0] &&
430 fClusterTypeArea[0][1] &&
431 fClusterTypeArea[0][0] )
436 // X and equivalent...
440 fClusterTypeArea[1][0] &&
441 fClusterTypeArea[1][1] &&
442 fClusterTypeArea[1][2] &&
443 fClusterTypeArea[0][0]
447 fClusterTypeArea[1][0] &&
448 fClusterTypeArea[1][1] &&
449 fClusterTypeArea[1][2] &&
450 fClusterTypeArea[0][2]
454 fClusterTypeArea[0][0] &&
455 fClusterTypeArea[0][1] &&
456 fClusterTypeArea[0][2] &&
457 fClusterTypeArea[1][0]
461 fClusterTypeArea[0][0] &&
462 fClusterTypeArea[0][1] &&
463 fClusterTypeArea[0][2] &&
464 fClusterTypeArea[1][2]
472 // X and equivalent...
476 fClusterTypeArea[1][0] &&
477 fClusterTypeArea[1][1] &&
478 fClusterTypeArea[1][2] &&
479 fClusterTypeArea[0][1]
483 fClusterTypeArea[0][0] &&
484 fClusterTypeArea[0][1] &&
485 fClusterTypeArea[0][2] &&
486 fClusterTypeArea[1][1]
493 // XXX and equivalent...
497 fClusterTypeArea[2][0] &&
498 fClusterTypeArea[2][1] &&
499 fClusterTypeArea[1][1] &&
500 fClusterTypeArea[0][1]
504 fClusterTypeArea[0][0] &&
505 fClusterTypeArea[2][1] &&
506 fClusterTypeArea[1][1] &&
507 fClusterTypeArea[0][1]
511 fClusterTypeArea[2][1] &&
512 fClusterTypeArea[2][0] &&
513 fClusterTypeArea[1][0] &&
514 fClusterTypeArea[0][0]
518 fClusterTypeArea[0][1] &&
519 fClusterTypeArea[2][0] &&
520 fClusterTypeArea[1][0] &&
521 fClusterTypeArea[0][0]
528 // XXX and equivalent...
532 fClusterTypeArea[1][0] &&
533 fClusterTypeArea[2][1] &&
534 fClusterTypeArea[1][1] &&
535 fClusterTypeArea[0][1]
539 fClusterTypeArea[1][1] &&
540 fClusterTypeArea[2][0] &&
541 fClusterTypeArea[1][0] &&
542 fClusterTypeArea[0][0]
549 // X and equivalent...
553 fClusterTypeArea[0][0] &&
554 fClusterTypeArea[1][1]
558 fClusterTypeArea[1][0] &&
559 fClusterTypeArea[0][1]
567 // X and equivalent...
571 fClusterTypeArea[0][0] &&
572 fClusterTypeArea[0][1] &&
573 fClusterTypeArea[1][2]
577 fClusterTypeArea[1][0] &&
578 fClusterTypeArea[1][1] &&
579 fClusterTypeArea[0][2]
583 fClusterTypeArea[1][0] &&
584 fClusterTypeArea[0][1] &&
585 fClusterTypeArea[0][2]
589 fClusterTypeArea[0][0] &&
590 fClusterTypeArea[1][1] &&
591 fClusterTypeArea[1][2]
598 // X and equivalent...
602 fClusterTypeArea[0][0] &&
603 fClusterTypeArea[1][0] &&
604 fClusterTypeArea[2][1]
608 fClusterTypeArea[0][1] &&
609 fClusterTypeArea[1][1] &&
610 fClusterTypeArea[2][0]
614 fClusterTypeArea[0][0] &&
615 fClusterTypeArea[1][1] &&
616 fClusterTypeArea[2][1]
620 fClusterTypeArea[0][1] &&
621 fClusterTypeArea[1][0] &&
622 fClusterTypeArea[2][0]
633 //___________________________________________________________________________________________________
635 UInt_t AliITSUpgradeClusterFinder::GetPixelCharge(UInt_t col, UInt_t row){
637 for(Int_t entry =0; entry < fChargeArray->GetEntries(); entry++){
638 TObjString *s = (TObjString*)fChargeArray->At(entry);
639 TString name = s->GetString();
640 if(!name.Contains(Form("%i %i",col,row)))
642 TObjArray *array = name.Tokenize(" ");
643 TString charge = ((TObjString*)array->At(2))->String();
645 rowS = ((TObjString*)array->At(0))->String();
646 colS = ((TObjString*)array->At(1))->String();
654 //____________________________________________________
656 void AliITSUpgradeClusterFinder::AddLabelIndex(UInt_t col, UInt_t row){
658 for(Int_t entry =0; entry < fChargeArray->GetEntries(); entry++){
659 TObjString *s = (TObjString*)fChargeArray->At(entry);
660 TString name = s->GetString();
661 if(!name.Contains(Form("%i %i",col,row)))
663 TObjArray *array = name.Tokenize(" ");
666 for(Int_t i=0; i<3; i++){
667 index[i]=((TObjString*)array->At(3+i))->String();
668 label[i]=index[i].Atoi();
675 //____________________________________________________
677 void AliITSUpgradeClusterFinder::SetLabels(Int_t label[3]){
680 Bool_t isAssigned[3]={kFALSE,kFALSE,kFALSE};
682 for(Int_t i=0; i<10; i++){
683 for(Int_t k=0; k<3; k++){
684 //printf(" fLabels[%i]=%i label[%i]=%i \n",i,fLabels[i],k,label[k]);
685 if(fLabels[i]!=label[k] && label[k]>-1 && fLabels[i]<0) {
687 // printf("assignign...\n.");
688 printf("Assignign fLabels[%i]=%i label[%i]=%i \n",i,fLabels[i],k,label[k]);
689 fLabels[i+k]=label[k];