]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/UPGRADE/AliITSUpgradeClusterFinder.cxx
fix for coding conventions
[u/mrichter/AliRoot.git] / ITS / UPGRADE / AliITSUpgradeClusterFinder.cxx
CommitLineData
1d9af2d5 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
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 **************************************************************************/
15
16/* $Id$ */
17
18////////////////////////////////////////////////////////////////////////////
19// //
20// Base Class used to find //
21// the reconstructed points for ITS Upgrade //
22// //
23////////////////////////////////////////////////////////////////////////////
24
25#include "AliITSUpgradeClusterFinder.h"
6ea6235b 26#include "AliITSsegmentationUpgrade.h"
27#include "AliITSRecPoint.h"
28#include "AliITSDigitUpgrade.h"
1d9af2d5 29#include "AliITSRawStreamSPD.h"
30#include "AliLog.h"
31#include <string.h>
32#include <TObjString.h>
6ea6235b 33#include <TClonesArray.h>
34#include <TTree.h>
35#include <TMath.h>
1d9af2d5 36
37AliITSUpgradeClusterFinder::AliITSUpgradeClusterFinder() :
38 fNhitsLeft(0),
39 fOldModule(-1),
40 fClusterTypeFlag(kTRUE),
41 fFindClusterType(kFALSE),
42 fClusterTypeOrigCol(0),
43 fClusterTypeOrigRow(0),
44 fColSum(0),fRowSum(0),
45 fCharge(0),
46 fClusterWidthMaxCol(0),
47 fClusterWidthMinCol(0),
48 fClusterWidthMaxRow(0),
49 fClusterWidthMinRow(0),
6ea6235b 50 fChargeArray(0x0),
51 fRecPoints(0x0)
1d9af2d5 52{
b86a9a14 53 //
54 // Default constructor
55 //
56
1d9af2d5 57 fChargeArray = new TObjArray();
6ea6235b 58 fRecPoints = new TClonesArray("AliITSRecPoint",3000);
1d9af2d5 59 fTmpLabel[0]=-5;
60 fTmpLabel[1]=-5;
61 fTmpLabel[2]=-5;
6ea6235b 62 for(int il=0; il<10;il++) fLabels[il]=-5;
1d9af2d5 63}
64
65//___________________________________________________________________________________
6ea6235b 66AliITSUpgradeClusterFinder::~AliITSUpgradeClusterFinder() {
67 if(fChargeArray) delete fChargeArray;
68 if(fRecPoints) delete fRecPoints;
69}
1d9af2d5 70//___________________________________________________________________________________
71void AliITSUpgradeClusterFinder::StartEvent() {
72 NewEvent();
73}
74//___________________________________________________________________________________
1d9af2d5 75Int_t AliITSUpgradeClusterFinder::ProcessHit(Int_t layer , UInt_t col, UInt_t row, UShort_t charge, Int_t label[3]) {
b86a9a14 76 //
77 // Adds one pixel to the cluster
78 //
1d9af2d5 79
80 if (layer>=6) {
6ea6235b 81 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]);
82 return 1;
1d9af2d5 83 }
84
85 // do we need to perform clustering on previous module?
86 if (fOldModule!=-1 && (Int_t)layer!=fOldModule) {
87 fChargeArray->AddLast(new TObjString(Form("%i %i %i %i %i %i",col,row,charge,label[0],label[1],label[2])));
88 DoModuleClustering(fOldModule,charge);
89 NewModule();
90 }
91 // add hit
92 fChargeArray->AddLast(new TObjString(Form("%i %i %i %i %i %i",col,row,charge,label[0],label[1],label[2])));
93
94 fOldModule=layer;
95 fHitCol[fNhitsLeft]=col;
96 fHitRow[fNhitsLeft]=row;
97 fHits[col][row]=kTRUE;
98 fTmpLabel[0]=label[0];
99 fTmpLabel[1]=label[1];
100 fTmpLabel[2]=label[2];
101 fNhitsLeft++;
102 return 0;
103}
104//___________________________________________________________________________________
105void AliITSUpgradeClusterFinder::FinishEvent() {
106 if (fNhitsLeft>0) {
107 DoModuleClustering(fOldModule,fCharge);
108 }
109}
110//___________________________________________________________________________________
b86a9a14 111UInt_t AliITSUpgradeClusterFinder::GetClusterCount(Int_t layer) const {
112 //
113 // number of clusters in the layer
114 //
1d9af2d5 115 if (layer>=6) {
116 printf("ERROR: UpgradeClusterFinder::GetClusterCount: Module out of bounds: layer = %d\n",layer);
117 return 0;
118 }
119 return fClusterList[layer].GetNrEntries();
120}
121//___________________________________________________________________________________
122Float_t AliITSUpgradeClusterFinder::GetClusterMeanCol(Int_t layer, UInt_t index) {
b86a9a14 123 //
124 // cluster position in terms of colums : mean column ID
125 //
1d9af2d5 126 if (layer>=6) {
127 printf("ERROR: UpgradeClusterFinder::GetClusterMeanCol: Module out of bounds: layer = %d\n",layer);
128 return 0;
129 }
130 return fClusterList[layer].GetColIndex(index);
131}
132//___________________________________________________________________________________
133Float_t AliITSUpgradeClusterFinder::GetClusterMeanRow(Int_t layer, UInt_t index) {
b86a9a14 134 //
135 // cluster position in terms of rows : mean row ID
136 //
1d9af2d5 137 if (layer>=6) {
138 printf("ERROR: UpgradeClusterFinder::GetClusterMeanRow: Module out of bounds: layer = %d\n",layer);
139 return 0;
140 }
141 return fClusterList[layer].GetRowIndex(index);
142}
143//___________________________________________________________________________________
144UInt_t AliITSUpgradeClusterFinder::GetClusterSize(Int_t layer, UInt_t index) {
b86a9a14 145 //
146 // total number of pixels of the cluster
147 //
1d9af2d5 148 if (layer>=6) {
149 printf("ERROR: UpgradeClusterFinder::GetClusterSize: Module out of bounds: layer = %d\n",layer);
150 return 0;
151 }
152 return fClusterList[layer].GetSizeIndex(index);
153}
154//___________________________________________________________________________________
155UInt_t AliITSUpgradeClusterFinder::GetClusterWidthZ(Int_t layer, UInt_t index) {
b86a9a14 156 //
157 // # pixels of the cluster in Z direction
158 //
159
1d9af2d5 160 if (layer>=6) {
161 printf("ERROR: UpgradeClusterFinder::GetClusterWidthZ: Module out of bounds: layer = %d\n",layer);
162 return 0;
163 }
164 return fClusterList[layer].GetWidthZIndex(index);
165}
166//___________________________________________________________________________________
167UInt_t AliITSUpgradeClusterFinder::GetClusterWidthPhi(Int_t layer, UInt_t index) {
b86a9a14 168 //
169 // # pixels of the cluster in phi direction (XY plane)
170 //
171
172 if (layer>=6) {
1d9af2d5 173 printf("ERROR: UpgradeClusterFinder::GetClusterWidthPhi: Module out of bounds: layer = %d\n",layer);
174 return 0;
175 }
176 return fClusterList[layer].GetWidthPhiIndex(index);
177}
178//___________________________________________________________________________________
179UInt_t AliITSUpgradeClusterFinder::GetClusterType(Int_t layer, UInt_t index) {
b86a9a14 180 //
181 // cluster shape
182 //
183
1d9af2d5 184 if (layer>=6) {
185 printf("ERROR: UpgradeClusterFinder::GetClusterType: Module out of bounds: layer = %d\n",layer);
186 return 0;
187 }
188 return fClusterList[layer].GetTypeIndex(index);
189}
190//___________________________________________________________________________________
191void AliITSUpgradeClusterFinder::PrintAllClusters() {
b86a9a14 192 //
193 // printout of the cluster information
194 //
195
1d9af2d5 196 for (Int_t layer=0; layer<6; layer++) {
197 PrintClusters(layer);
198 }
199}
200//___________________________________________________________________________________
201void AliITSUpgradeClusterFinder::PrintClusters(Int_t layer) {
b86a9a14 202 //
203 // printout of the cluster information
204 //
205
1d9af2d5 206 if (layer>=6) {
207 printf("ERROR: UpgradeClusterFinder::PrintClusters: Out of bounds: layer = %d\n",layer);
208 return;
209 }
210 if(fClusterList[layer].GetNrEntries()==0) {
211 printf("no cluster list entries. Exiting... \n");
212 return;
213 }
214 for (UInt_t c=0; c<fClusterList[layer].GetNrEntries(); c++) {
6ea6235b 215 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);
216 }
1d9af2d5 217}
218//___________________________________________________________________________________
219void AliITSUpgradeClusterFinder::NewEvent() {
b86a9a14 220 //
221 // Cleaning up and preparation for the clustering procedure
222 //
223
1d9af2d5 224 for (Int_t i=0; i<6; i++) {
225 fClusterList[i].Clear();
226 }
227 NewModule();
228 fOldModule = -1;
229}
230//___________________________________________________________________________________
231void AliITSUpgradeClusterFinder::NewModule() {
b86a9a14 232 //
233 // Initializations
234 //
235
1d9af2d5 236 fNhitsLeft=0;
237 memset(fHits,0,999*999*sizeof(Bool_t));
238}
239//___________________________________________________________________________________
240Int_t AliITSUpgradeClusterFinder::DoModuleClustering(Int_t Layer, UShort_t charge) {
b86a9a14 241 //
242 // Clustering and cluster-list container filling
243 //
244
1d9af2d5 245 UInt_t maxHits=fNhitsLeft;
246 for (UInt_t hit=0; hit<maxHits; hit++) {
247 if (fClusterTypeFlag) fFindClusterType = kTRUE;
248
249 fClusterWidthMinCol = fHitCol[hit];
250 fClusterWidthMinRow = fHitRow[hit];
251 fClusterWidthMaxCol = fHitCol[hit];
252 fClusterWidthMaxRow = fHitRow[hit];
253
254
255 fClusterTypeOrigCol = fHitCol[hit];
256 fClusterTypeOrigRow = fHitRow[hit];
257 memset(fClusterTypeArea,0,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
258 fColSum=0;
259 fRowSum=0;
260 UInt_t size = FindClusterRecu(fClusterTypeOrigCol,fClusterTypeOrigRow,charge);
261
262 if(size==1){
263 fCharge=GetPixelCharge(fColSum,fRowSum);
264 AddLabelIndex(fColSum,fRowSum);
265 }
266 if (size>0) {
b86a9a14 267 if(size>1) AliInfo(Form("DoModuleClustering, size %i , labels : %i %i %i \n",size,fLabels[0],fLabels[1],fLabels[2]));
1d9af2d5 268 fClusterList[Layer].Insert((Float_t)fColSum/size, (Float_t)fRowSum/size, size, GetClusterWidthZ(), GetClusterWidthPhi(), GetClusterType(size), fCharge,fLabels);
269 fCharge=0;
270 for(Int_t i=0; i<10; i++) fLabels[i]=-5;
271 }
272 if (fNhitsLeft==0) break;
273 }
274 return 0;
275}
276//___________________________________________________________________________________
277UInt_t AliITSUpgradeClusterFinder::FindClusterRecu(Int_t col, Int_t row, UShort_t charge) {
b86a9a14 278 //
279 // Pixel selection for the clusters (adjiacent pixels or pixels at the corners)
280 //
281
282 if (col<0 || !fHits[col][row]) {return 0;}
1d9af2d5 283 fHits[col][row]=kFALSE;
284 fColSum+=col;
285 fRowSum+=row;
286 fNhitsLeft--;
287 UInt_t size=1;
288
289 if (col>fClusterWidthMaxCol) fClusterWidthMaxCol = col;
290 if (col<fClusterWidthMinCol) fClusterWidthMinCol = col;
291 if (row>fClusterWidthMaxRow) fClusterWidthMaxRow = row;
292 if (row<fClusterWidthMaxRow) fClusterWidthMinRow = row;
293
294 if (fFindClusterType) {
295 Short_t diffz = fClusterTypeOrigCol - col;
296 Short_t diffy = row - fClusterTypeOrigRow;
297 if (diffz>=kMAXCLUSTERTYPESIDEZ || diffy>=kMAXCLUSTERTYPESIDEY) {
298 fFindClusterType=kFALSE;
299 }
300 else {
301 if (diffz==-1) {
302 ShiftClusterTypeArea(kSHIFTRIGHT);
303 diffz=0;
304 }
305 if (diffy==-1) {
306 ShiftClusterTypeArea(kSHIFTDOWN);
307 diffy=0;
308 }
309 fClusterTypeArea[diffz][diffy] = kTRUE;
310 }
311 }
312 // straight:
313 size+=FindClusterRecu(col ,row-1,charge);
314 fCharge+=GetPixelCharge(col,row-1);
315 AddLabelIndex(col,row-1);
316
317 size+=FindClusterRecu(col-1,row ,charge);
318 fCharge+=GetPixelCharge(col-1,row);
319 AddLabelIndex(col-1,row);
320
321 size+=FindClusterRecu(col ,row+1,charge);
322 fCharge+=GetPixelCharge(col,row+1);
323 AddLabelIndex(col,row+1);
324
325 size+=FindClusterRecu(col+1,row ,charge );
326 fCharge+=GetPixelCharge(col+1,row);
327 AddLabelIndex(col+1,row);
328
329 // diagonal:
330 size+=FindClusterRecu(col-1,row-1,charge);
331 fCharge+=GetPixelCharge(col-1,row-1);
332 AddLabelIndex(col-1,row-1);
333
334 size+=FindClusterRecu(col-1,row+1,charge);
335 fCharge+=GetPixelCharge(col-1,row+1);
336 AddLabelIndex(col-1,row+1);
337
338 size+=FindClusterRecu(col+1,row-1,charge);
339 fCharge+=GetPixelCharge(col+1,row-1);
340 AddLabelIndex(col+1,row-1);
341
342 size+=FindClusterRecu(col+1,row+1,charge);
343 fCharge+=GetPixelCharge(col+1,row+1);
344 AddLabelIndex(col+1,row+1);
345
346 return size;
347}
348//___________________________________________________________________________________
349void AliITSUpgradeClusterFinder::ShiftClusterTypeArea(UInt_t direction) {
b86a9a14 350 //
351 // Cluster checks
352 //
353
1d9af2d5 354 if (direction == kSHIFTRIGHT) {
355 fClusterTypeOrigCol++;
356 Bool_t tmpClusterTypeArea[kMAXCLUSTERTYPESIDEZ][kMAXCLUSTERTYPESIDEY];
357 memset(tmpClusterTypeArea,0,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
358 for (UInt_t z=0; z<kMAXCLUSTERTYPESIDEZ; z++) {
359 for (UInt_t y=0; y<kMAXCLUSTERTYPESIDEY; y++) {
360 if (fClusterTypeArea[z][y]) {
361 if (z==kMAXCLUSTERTYPESIDEZ-1) {
362 fFindClusterType=kFALSE;
363 return;
364 }
365 else {
366 tmpClusterTypeArea[z+1][y] = kTRUE;
367 }
368 }
369 }
370 }
371 memcpy(fClusterTypeArea,tmpClusterTypeArea,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
372 }
373 else if (direction == kSHIFTDOWN) {
374 fClusterTypeOrigRow--;
375 Bool_t tmpClusterTypeArea[kMAXCLUSTERTYPESIDEZ][kMAXCLUSTERTYPESIDEY];
376 memset(tmpClusterTypeArea,0,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
377 for (UInt_t z=0; z<kMAXCLUSTERTYPESIDEZ; z++) {
378 for (UInt_t y=0; y<kMAXCLUSTERTYPESIDEY; y++) {
379 if (fClusterTypeArea[z][y]) {
380 if (y==kMAXCLUSTERTYPESIDEY-1) {
381 fFindClusterType=kFALSE;
382 return;
383 }
384 else {
385 tmpClusterTypeArea[z][y+1] = kTRUE;
386 }
387 }
388 }
389 }
390 memcpy(fClusterTypeArea,tmpClusterTypeArea,kMAXCLUSTERTYPESIDEZ*kMAXCLUSTERTYPESIDEY*sizeof(Bool_t));
391 }
392}
1d9af2d5 393//___________________________________________________________________________________
394UShort_t AliITSUpgradeClusterFinder::GetCharge(Int_t layer,UInt_t index ) {
395 return fClusterList[layer].GetCharge(index);
396}
397//___________________________________________________________________________________
398Int_t * AliITSUpgradeClusterFinder::GetLabels(Int_t layer,UInt_t index) {
6ea6235b 399 return fClusterList[layer].GetLabels(index);
1d9af2d5 400}
401
402//___________________________________________________________________________________
403UInt_t AliITSUpgradeClusterFinder::GetClusterWidthZ() {
404 return fClusterWidthMaxCol-fClusterWidthMinCol+1;
405}
406//___________________________________________________________________________________
407UInt_t AliITSUpgradeClusterFinder::GetClusterWidthPhi() {
408 return fClusterWidthMaxRow-fClusterWidthMinRow+1;
409}
410//___________________________________________________________________________________
411UInt_t AliITSUpgradeClusterFinder::GetClusterType(UInt_t size) {
6ea6235b 412 //
413 // Cluster shape
414 //
1d9af2d5 415 if (!fFindClusterType || size>4)
416 return 0;
417
418 // X
419 if (size==1)
420 return 1;
421
422 // X
423 // X
424 if (size==2 &&
425 fClusterTypeArea[0][1] &&
426 fClusterTypeArea[0][0] )
427 return 2;
428
429 // XX
430 if (size==2 &&
431 fClusterTypeArea[1][0] &&
432 fClusterTypeArea[0][0] )
433 return 3;
434
435 // X
436 // X
437 // X
438 if (size==3 &&
439 fClusterTypeArea[0][2] &&
440 fClusterTypeArea[0][1] &&
441 fClusterTypeArea[0][0] )
442 return 4;
443
444 // XX
445 // X and equivalent...
446 if (size==3 &&
447 (
448 (
449 fClusterTypeArea[0][0] &&
450 fClusterTypeArea[0][1] &&
451 (fClusterTypeArea[1][1] ||
452 fClusterTypeArea[1][0])
453 )
454 ||
455 (
456 fClusterTypeArea[1][0] &&
457 fClusterTypeArea[1][1] &&
458 (fClusterTypeArea[0][1] ||
459 fClusterTypeArea[0][0])
460 )
461 )
462 )
463 return 5;
464
465 // XXX
466 if (size==3 &&
467 fClusterTypeArea[2][0] &&
468 fClusterTypeArea[1][0] &&
469 fClusterTypeArea[0][0] )
470 return 6;
471
472 // X
473 // X
474 // X
475 // X
476 if (size==4 &&
477 fClusterTypeArea[0][3] &&
478 fClusterTypeArea[0][2] &&
479 fClusterTypeArea[0][1] &&
480 fClusterTypeArea[0][0] )
481 return 7;
482
483 // XX
484 // XX
485 if (size==4 &&
486 fClusterTypeArea[1][1] &&
487 fClusterTypeArea[1][0] &&
488 fClusterTypeArea[0][1] &&
489 fClusterTypeArea[0][0] )
490 return 8;
491
492 // XX
493 // X
494 // X and equivalent...
495 if (size==4 &&
496 (
497 (
498 fClusterTypeArea[1][0] &&
499 fClusterTypeArea[1][1] &&
500 fClusterTypeArea[1][2] &&
501 fClusterTypeArea[0][0]
502 )
503 ||
504 (
505 fClusterTypeArea[1][0] &&
506 fClusterTypeArea[1][1] &&
507 fClusterTypeArea[1][2] &&
508 fClusterTypeArea[0][2]
509 )
510 ||
511 (
512 fClusterTypeArea[0][0] &&
513 fClusterTypeArea[0][1] &&
514 fClusterTypeArea[0][2] &&
515 fClusterTypeArea[1][0]
516 )
517 ||
518 (
519 fClusterTypeArea[0][0] &&
520 fClusterTypeArea[0][1] &&
521 fClusterTypeArea[0][2] &&
522 fClusterTypeArea[1][2]
523 )
524 )
525 )
526 return 9;
527
528 // X
529 // XX
530 // X and equivalent...
531 if (size==4 &&
532 (
533 (
534 fClusterTypeArea[1][0] &&
535 fClusterTypeArea[1][1] &&
536 fClusterTypeArea[1][2] &&
537 fClusterTypeArea[0][1]
538 )
539 ||
540 (
541 fClusterTypeArea[0][0] &&
542 fClusterTypeArea[0][1] &&
543 fClusterTypeArea[0][2] &&
544 fClusterTypeArea[1][1]
545 )
546 )
547 )
548 return 10;
549
550 // X
551 // XXX and equivalent...
552 if (size==4 &&
553 (
554 (
555 fClusterTypeArea[2][0] &&
556 fClusterTypeArea[2][1] &&
557 fClusterTypeArea[1][1] &&
558 fClusterTypeArea[0][1]
559 )
560 ||
561 (
562 fClusterTypeArea[0][0] &&
563 fClusterTypeArea[2][1] &&
564 fClusterTypeArea[1][1] &&
565 fClusterTypeArea[0][1]
566 )
567 ||
568 (
569 fClusterTypeArea[2][1] &&
570 fClusterTypeArea[2][0] &&
571 fClusterTypeArea[1][0] &&
572 fClusterTypeArea[0][0]
573 )
574 ||
575 (
576 fClusterTypeArea[0][1] &&
577 fClusterTypeArea[2][0] &&
578 fClusterTypeArea[1][0] &&
579 fClusterTypeArea[0][0]
580 )
581 )
582 )
583 return 11;
584
585 // X
586 // XXX and equivalent...
587 if (size==4 &&
588 (
589 (
590 fClusterTypeArea[1][0] &&
591 fClusterTypeArea[2][1] &&
592 fClusterTypeArea[1][1] &&
593 fClusterTypeArea[0][1]
594 )
595 ||
596 (
597 fClusterTypeArea[1][1] &&
598 fClusterTypeArea[2][0] &&
599 fClusterTypeArea[1][0] &&
600 fClusterTypeArea[0][0]
601 )
602 )
603 )
604 return 12;
605
606 // X
607 // X and equivalent...
608 if (size==2 &&
609 (
610 (
611 fClusterTypeArea[0][0] &&
612 fClusterTypeArea[1][1]
613 )
614 ||
615 (
616 fClusterTypeArea[1][0] &&
617 fClusterTypeArea[0][1]
618 )
619 )
620 )
621 return 13;
622
623 // X
624 // X
625 // X and equivalent...
626 if (size==3 &&
627 (
628 (
629 fClusterTypeArea[0][0] &&
630 fClusterTypeArea[0][1] &&
631 fClusterTypeArea[1][2]
632 )
633 ||
634 (
635 fClusterTypeArea[1][0] &&
636 fClusterTypeArea[1][1] &&
637 fClusterTypeArea[0][2]
638 )
639 ||
640 (
641 fClusterTypeArea[1][0] &&
642 fClusterTypeArea[0][1] &&
643 fClusterTypeArea[0][2]
644 )
645 ||
646 (
647 fClusterTypeArea[0][0] &&
648 fClusterTypeArea[1][1] &&
649 fClusterTypeArea[1][2]
650 )
651 )
652 )
653 return 14;
654
655 // XX
656 // X and equivalent...
657 if (size==3 &&
658 (
659 (
660 fClusterTypeArea[0][0] &&
661 fClusterTypeArea[1][0] &&
662 fClusterTypeArea[2][1]
663 )
664 ||
665 (
666 fClusterTypeArea[0][1] &&
667 fClusterTypeArea[1][1] &&
668 fClusterTypeArea[2][0]
669 )
670 ||
671 (
672 fClusterTypeArea[0][0] &&
673 fClusterTypeArea[1][1] &&
674 fClusterTypeArea[2][1]
675 )
676 ||
677 (
678 fClusterTypeArea[0][1] &&
679 fClusterTypeArea[1][0] &&
680 fClusterTypeArea[2][0]
681 )
682 )
683 )
684 return 15;
685
686
687
688 return 0;
689}
690
691//___________________________________________________________________________________________________
1d9af2d5 692UInt_t AliITSUpgradeClusterFinder::GetPixelCharge(UInt_t col, UInt_t row){
6ea6235b 693 //
694 //...self explaining
695 //
1d9af2d5 696 Int_t q=0;
697 for(Int_t entry =0; entry < fChargeArray->GetEntries(); entry++){
698 TObjString *s = (TObjString*)fChargeArray->At(entry);
699 TString name = s->GetString();
700 if(!name.Contains(Form("%i %i",col,row)))
701 continue;
702 TObjArray *array = name.Tokenize(" ");
703 TString charge = ((TObjString*)array->At(2))->String();
704 TString rowS, colS;
705 rowS = ((TObjString*)array->At(0))->String();
706 colS = ((TObjString*)array->At(1))->String();
707 delete array;
708 q=charge.Atoi();
709 return q;
710
711 }
712 return q;
713}
714//____________________________________________________
715
716void AliITSUpgradeClusterFinder::AddLabelIndex(UInt_t col, UInt_t row){
6ea6235b 717 //
718 // Adding cluster labels
719 //
1d9af2d5 720
6ea6235b 721 for(Int_t entry =0; entry < fChargeArray->GetEntries(); entry++){
1d9af2d5 722 TObjString *s = (TObjString*)fChargeArray->At(entry);
723 TString name = s->GetString();
6ea6235b 724 if(!name.Contains(Form("%i %i",col,row)))
725 continue;
726 TObjArray *array = name.Tokenize(" ");
727 TString index[3];
728 Int_t label[3];
729 for(Int_t i=0; i<3; i++){
730 index[i]=((TObjString*)array->At(3+i))->String();
731 label[i]=index[i].Atoi();
1d9af2d5 732
6ea6235b 733 }
734 SetLabels(label);
735 delete array;
1d9af2d5 736 }
1d9af2d5 737}
738//____________________________________________________
739
740void AliITSUpgradeClusterFinder::SetLabels(Int_t label[3]){
6ea6235b 741 //
742 //
b86a9a14 743 //Set the MC lables to the cluster
6ea6235b 744
745 Bool_t isAssigned[3]={kFALSE,kFALSE,kFALSE};
746
747 for(Int_t i=0; i<10; i++){
748 for(Int_t k=0; k<3; k++){
749 if(fLabels[i]!=label[k] && label[k]>-1 && fLabels[i]<0) {
750 if(!isAssigned[k]) {
751 // printf("assignign...\n.");
752 // printf("Assignign fLabels[%i]=%i label[%i]=%i \n",i,fLabels[i],k,label[k]);
753 fLabels[i+k]=label[k];
754 isAssigned[k]=kTRUE;
755 }
756 }
757 }
758 }
759}
1d9af2d5 760
6ea6235b 761//____________________________________________________
762void AliITSUpgradeClusterFinder::MakeRecPointBranch(TTree *treeR){
763 //
764 // Creating the branch (see AliITSUpgradeReconstructor::Reconstruct)
765 //
766
767 if(!fRecPoints)fRecPoints = new TClonesArray("AliITSRecPoint",1000);
768 if (treeR) {
769 TBranch *branch = treeR->GetBranch("ITSRecPoints");
770 if (branch) return ;
771 else branch = treeR->Branch("ITSRecPoints",&fRecPoints);
772 }
773}
774//____________________________________________________
775void AliITSUpgradeClusterFinder::SetRecPointTreeAddress(TTree *treeR){
776 //
777 // Addressing the branch (see AliITSUpgradeReconstructor::Reconstruct)
778 //
779 if(!treeR) return;
780 if(!fRecPoints) fRecPoints = new TClonesArray("AliITSRecPoint",1000);
781
782 TBranch *branch;
783 branch = treeR->GetBranch("ITSRecPoints");
784 if (branch) {
785 branch->SetAddress(&fRecPoints);
786 } else AliError("No RecPoint branch available");
1d9af2d5 787
6ea6235b 788}
789//____________________________________________________
b86a9a14 790void AliITSUpgradeClusterFinder::DigitsToRecPoints(const TObjArray *digList) {
6ea6235b 791 //
792 // the clusterization is performed here
793 //
794 AliITSsegmentationUpgrade *segmentation2 = 0x0;
795 AliITSRecPoint recpnt;
796 if(!segmentation2) segmentation2 = new AliITSsegmentationUpgrade();
797 Int_t nClusters =0;
798 TClonesArray &lrecp = *fRecPoints;
799
800 for(Int_t ilayer=0; ilayer < 6 ;ilayer ++){
801 TClonesArray *pArrDig= (TClonesArray*)digList->At(ilayer);
802 StartEvent();
803 AliInfo(Form("layer %i with digit entries %i",ilayer,pArrDig->GetEntries()));
804 for(Int_t ientr =0; ientr < pArrDig->GetEntries() ; ientr++){
805 AliITSDigitUpgrade *dig = (AliITSDigitUpgrade*)pArrDig->At(ientr);
806 Int_t colz=dig->GetzPixelNumber();
807 Int_t rowx=dig->GetxPixelNumber();
808 Double_t hitcharge= (dig->GetNelectrons());
b86a9a14 809 ProcessHit(ilayer,colz, rowx,(Short_t)hitcharge,dig->GetTracks());
6ea6235b 810 }//ientr
811 FinishEvent();
812
813 for(UInt_t nClu = 0; nClu < GetClusterCount(ilayer); nClu++){
814 UShort_t charge = GetCharge(ilayer, nClu);
815 recpnt.SetQ(charge);
816 recpnt.SetLayer(ilayer);
817 Int_t *lab=GetLabels(ilayer,nClu);
818 for(Int_t l=0; l<3; l++) {recpnt.SetLabel(lab[l],l);}
819
820 Bool_t check2;
821 Double_t xcheck2=0.;
822 Double_t ycheck2=0.;
823 Double_t zcheck2=0.;
824 Double_t xzl2[2]={0.,0.};
b86a9a14 825 Double_t xPixC2,zPixC2=0.;
6ea6235b 826
b86a9a14 827 xPixC2 = GetClusterMeanRow(ilayer, nClu);
828 zPixC2 = GetClusterMeanCol(ilayer, nClu);
829 xzl2[0] = xPixC2*(segmentation2->GetCellSizeX(ilayer))+0.5*(segmentation2-> GetCellSizeX(ilayer));
830 xzl2[1] = zPixC2*(segmentation2->GetCellSizeZ(ilayer))+0.5*(segmentation2->GetCellSizeZ(ilayer))-(segmentation2->GetHalfLength(ilayer));
6ea6235b 831 check2 = segmentation2->DetToGlobal(ilayer,xzl2[0], xzl2[1],xcheck2,ycheck2,zcheck2);
832 recpnt.SetType(GetClusterType(ilayer,nClu ));
833 // recpnt.SetLocalCoord(xzl2[0],xzl2[1]); //temporary solution (no LocalToTrack Matrix)
834 //from global to tracking system coordinate
835 // global coordinate -> local coordinate getting alpha angle of the recpoint
836 Float_t xclg = xcheck2;//upgrade clusters global coordinate ( ITS official: GetX tracking coordinate)
837 Float_t yclg = ycheck2;
838 Float_t zclg = zcheck2;
839 Double_t phiclu1rad, phiclu1deg;
840 phiclu1rad=TMath::ATan2(yclg,xclg);//cluster phi angle (rad)
841 if (phiclu1rad<0) phiclu1rad+=TMath::TwoPi();//from 0 to 360
842 else if (phiclu1rad>=TMath::TwoPi()) phiclu1rad-=TMath::TwoPi();//
843
844 phiclu1deg=180.*phiclu1rad/TMath::Pi();// in deg
845 Int_t ladder;// virtual segmentation starting from the cluster phi
846
847 ladder=(Int_t)phiclu1deg/18;// in which ladder the cluster is
848 Double_t alpha= (ladder*18.+9.)*TMath::Pi()/180.;//angle at the center of the ladder (rad)
849
850 //alpha rotation
b86a9a14 851 Float_t xclu1Tr = xclg*TMath::Cos(alpha)-yclg*TMath::Sin(alpha);
6ea6235b 852 Float_t yclu1 = yclg*TMath::Cos(alpha)+xclg*TMath::Sin(alpha);
b86a9a14 853 Float_t xclu1 = TMath::Sqrt(xclu1Tr*xclu1Tr+yclu1*yclu1);
6ea6235b 854 Float_t zclu1 = zclg;
b86a9a14 855 Double_t phiTrk= (phiclu1rad-alpha);// cluster angle in the rotated system (rad)
6ea6235b 856
b86a9a14 857 yclu1=xclu1*phiTrk; // tracking system coordinate: r*phi
6ea6235b 858 recpnt.SetX(0.);
859 recpnt.SetY(yclu1);
860 recpnt.SetZ(zclu1);
861
862 Double_t xsize, zsize;
863 segmentation2->GetSegmentation(ilayer,xsize, zsize);
864 recpnt.SetSigmaY2(xsize/TMath::Sqrt(12)*xsize/TMath::Sqrt(12));
865 recpnt.SetSigmaZ2(zsize/TMath::Sqrt(12)*zsize/TMath::Sqrt(12));
866 new(lrecp[nClusters++]) AliITSRecPoint(recpnt);
867 //Int_t idx = fRecPoints->GetEntries();
868 AliInfo(Form("recpoint : Nelectrons %f (entry %i)",recpnt.GetQ(),fRecPoints->GetEntries()));
869 }//cluster list entries
870 }//ilayer
1d9af2d5 871}
872