]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSClusterFinderSSD.cxx
Fixed message format and debug level
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderSSD.cxx
CommitLineData
b0f5e3fc 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 **************************************************************************/
04366a57 15///////////////////////////////////////////////////////////////////////////////
16// **************************************************************************//
17// * The package was revised and changed by Boris Batiounia in the time //
18// * period of March - June 2001 //
19// **************************************************************************//
20///////////////////////////////////////////////////////////////////////////////
f77f13c8 21
4ae5bbc4 22#include <Riostream.h>
eb08b98f 23#include <TArrayI.h>
f77f13c8 24
e8189707 25#include "AliITS.h"
f77f13c8 26#include "AliITSClusterFinderSSD.h"
27#include "AliITSMapA1.h"
41b19549 28#include "AliITSRawClusterSSD.h"
3c9a27a7 29#include "AliITSRecPoint.h"
e8189707 30#include "AliITSclusterSSD.h"
f77f13c8 31#include "AliITSdigitSSD.h"
32#include "AliITSgeom.h"
e8189707 33#include "AliITSpackageSSD.h"
aacedc3e 34#include "AliITSresponseSSD.h"
35#include "AliITSsegmentationSSD.h"
f77f13c8 36#include "AliLog.h"
37#include "AliRun.h"
b669392e 38
114da3a4 39const Bool_t AliITSClusterFinderSSD::fgkSIDEP=kTRUE;
40const Bool_t AliITSClusterFinderSSD::fgkSIDEN=kFALSE;
b0f5e3fc 41
42ClassImp(AliITSClusterFinderSSD)
43
f239b2fe 44//____________________________________________________________________
b0f5e3fc 45//
46// Constructor
fe15e140 47//______________________________________________________________________
aacedc3e 48AliITSClusterFinderSSD::AliITSClusterFinderSSD():
49AliITSClusterFinder(),
aacedc3e 50fClusterP(0),
51fNClusterP(0),
52fClusterN(0),
53fNClusterN(0),
54fPackages(0),
55fNPackages(0),
56fDigitsIndexP(0),
57fNDigitsP(0),
58fDigitsIndexN(0),
59fNDigitsN(0),
60fPitch(0.0),
61fTanP(0.0),
62fTanN(0.0),
63fPNsignalRatio(0.0),
64fSFF(0),
65fSFB(0){
fe15e140 66 //Default constructor
aacedc3e 67}
68//______________________________________________________________________
69AliITSClusterFinderSSD::AliITSClusterFinderSSD(AliITSsegmentation *seg,
70 TClonesArray *digits):
71AliITSClusterFinder(seg,0),
aacedc3e 72fClusterP(0),
73fNClusterP(0),
74fClusterN(0),
75fNClusterN(0),
76fPackages(0),
77fNPackages(0),
78fDigitsIndexP(0),
79fNDigitsP(0),
80fDigitsIndexN(0),
81fNDigitsN(0),
82fPitch(0.0),
83fTanP(0.0),
84fTanN(0.0),
85fPNsignalRatio(0.0),
86fSFF(0),
87fSFB(0){
88 //Standard constructor
fe15e140 89
aacedc3e 90 SetDigits(digits);
91 SetMap(new AliITSMapA1(GetSeg(),Digits()));
aacedc3e 92 fClusterP = new TClonesArray ("AliITSclusterSSD",200);
93 fNClusterP = 0;
94 fClusterN = new TClonesArray ("AliITSclusterSSD",200);
fe15e140 95 fNClusterN = 0;
aacedc3e 96 fPackages = new TClonesArray ("AliITSpackageSSD",200); //packages
fe15e140 97 fNPackages = 0;
aacedc3e 98 fDigitsIndexP = new TArrayI(300);
fe15e140 99 fNDigitsP = 0;
aacedc3e 100 fDigitsIndexN = new TArrayI(300);
fe15e140 101 fNDigitsN = 0;
aacedc3e 102 fPitch = GetSeg()->Dpx(0);
103 fPNsignalRatio= 7./8.; // warning: hard-wired number
b0f5e3fc 104}
fe15e140 105//______________________________________________________________________}
106AliITSClusterFinderSSD::AliITSClusterFinderSSD(AliITSsegmentation *seg,
aacedc3e 107 AliITSresponse *res):
108AliITSClusterFinder(seg,res),
aacedc3e 109fClusterP(0),
110fNClusterP(0),
111fClusterN(0),
112fNClusterN(0),
113fPackages(0),
114fNPackages(0),
115fDigitsIndexP(0),
116fNDigitsP(0),
117fDigitsIndexN(0),
118fNDigitsN(0),
119fPitch(0.0),
120fTanP(0.0),
121fTanN(0.0),
122fPNsignalRatio(0.0),
123fSFF(0),
124fSFB(0){
fe15e140 125 //Standard constructor
126
fe15e140 127 fClusterP = new TClonesArray ("AliITSclusterSSD",200);
128 fNClusterP = 0;
129 fClusterN = new TClonesArray ("AliITSclusterSSD",200);
130 fNClusterN = 0;
131 fPackages = new TClonesArray ("AliITSpackageSSD",200); //packages
132 fNPackages = 0;
133 fDigitsIndexP = new TArrayI(300);
134 fNDigitsP = 0;
135 fDigitsIndexN = new TArrayI(300);
136 fNDigitsN = 0;
aacedc3e 137 fPitch = GetSeg()->Dpx(0);
fe15e140 138 fPNsignalRatio= 7./8.; // warning: hard-wired number
139}
04366a57 140
141//______________________________________________________________________
142AliITSClusterFinderSSD::AliITSClusterFinderSSD(const AliITSClusterFinderSSD &source) : AliITSClusterFinder(source) {
143 // Copy constructor
144 // Copies are not allowed. The method is protected to avoid misuse.
145 Fatal("AliITSClusterFinderSSD","Copy constructor not allowed\n");
146}
147
148//______________________________________________________________________
149AliITSClusterFinderSSD& AliITSClusterFinderSSD::operator=(const AliITSClusterFinderSSD& /* source */){
150 // Assignment operator
151 // Assignment is not allowed. The method is protected to avoid misuse.
152 Fatal("= operator","Assignment operator not allowed\n");
153 return *this;
154}
155
fe15e140 156//______________________________________________________________________
157AliITSClusterFinderSSD::~AliITSClusterFinderSSD(){
158 // Default destructor
3c9a27a7 159
b0f5e3fc 160 delete fClusterP;
161 delete fClusterN;
162 delete fPackages;
163 delete fDigitsIndexP;
164 delete fDigitsIndexN;
165}
fe15e140 166//______________________________________________________________________
167void AliITSClusterFinderSSD::InitReconstruction(){
168 // initialization of the cluster finder
f239b2fe 169
fe15e140 170 register Int_t i; //iterator
b0f5e3fc 171
fe15e140 172 for (i=0;i<fNClusterP;i++) fClusterP->RemoveAt(i);
173 fNClusterP =0;
174 for (i=0;i<fNClusterN;i++) fClusterN->RemoveAt(i);
175 fNClusterN=0;
176 for (i=0;i<fNPackages;i++) fPackages->RemoveAt(i);
177 fNPackages = 0;
178 fNDigitsP = 0;
179 fNDigitsN = 0;
bf3f2830 180 Float_t stereoP,stereoN;
aacedc3e 181 GetSeg()->Angles(stereoP,stereoN);
bf3f2830 182 CalcStepFactor(stereoP,stereoN);
f77f13c8 183 AliDebug(1,Form("fSFF = %d fSFB = %d",fSFF,fSFB));
b0f5e3fc 184}
fe15e140 185//______________________________________________________________________
186void AliITSClusterFinderSSD::FindRawClusters(Int_t module){
187 // This function findes out all clusters belonging to one module
188 // 1. Zeroes all space after previous module reconstruction
189 // 2. Finds all neighbouring digits, create clusters
190 // 3. If necesery, resolves for each group of neighbouring digits
191 // how many clusters creates it.
192 // 4. Colculate the x and z coordinate
193 Int_t lay, lad, detect;
194 AliITSgeom *geom = fITS->GetITSgeom();
195
aacedc3e 196 SetModule(module);
197 geom->GetModuleId(GetModule(),lay, lad, detect);
198 if ( lay == 6 ) ((AliITSsegmentationSSD*)GetSeg())->SetLayer(6);
199 if ( lay == 5 ) ((AliITSsegmentationSSD*)GetSeg())->SetLayer(5);
fe15e140 200
201 InitReconstruction(); //ad. 1
aacedc3e 202 Map()->FillMap();
fe15e140 203 FillDigitsIndex();
204 SortDigits();
205 FindNeighbouringDigits(); //ad. 2
206 //SeparateOverlappedClusters(); //ad. 3
207 ClustersToPackages(); //ad. 4
aacedc3e 208 Map()->ClearMap();
b0f5e3fc 209}
fe15e140 210//______________________________________________________________________
211void AliITSClusterFinderSSD::FindNeighbouringDigits(){
212 //If there are any digits on this side, create 1st Cluster,
213 // add to it this digit, and increment number of clusters
214 register Int_t i;
215
216 if ((fNDigitsP>0 ) && (fNDigitsN > 0 )) {
217 Int_t currentstripNo;
218 Int_t *dbuffer = new Int_t [300]; //buffer for strip numbers
219 Int_t dnumber; //curent number of digits in buffer
220 TArrayI &lDigitsIndexP = *fDigitsIndexP;
221 TArrayI &lDigitsIndexN = *fDigitsIndexN;
222 TObjArray &lDigits = *(Digits());
223 TClonesArray &lClusterP = *fClusterP;
224 TClonesArray &lClusterN = *fClusterN;
225 //process P side
226 dnumber = 1;
227 dbuffer[0]=lDigitsIndexP[0];
228 //If next digit is a neigh. of previous, adds to last clust. this digit
229 for (i=1; i<fNDigitsP; i++) {
230 //reads new digit
231 currentstripNo = ((AliITSdigitSSD*)lDigits[lDigitsIndexP[i]])->
232 GetStripNumber();
233 //check if it is a neighbour of a previous one
234 if((((AliITSdigitSSD*)lDigits[lDigitsIndexP[i-1]])->
235 GetStripNumber())
236 == (currentstripNo-1) ) dbuffer[dnumber++]=lDigitsIndexP[i];
237 else{
238 //create a new one side cluster
239 new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,
240 Digits(),
241 fgkSIDEP);
242 dbuffer[0]=lDigitsIndexP[i];
243 dnumber = 1;
244 } // end if else
245 } // end loop over fNDigitsP
246 new(lClusterP[fNClusterP++]) AliITSclusterSSD(dnumber,dbuffer,
247 Digits(),fgkSIDEP);
248 //process N side
249 //for comments, see above
250 dnumber = 1;
251 dbuffer[0]=lDigitsIndexN[0];
252 //If next digit is a neigh. of previous, adds to last clust. this digit
253 for (i=1; i<fNDigitsN; i++) {
254 currentstripNo = ((AliITSdigitSSD*)(lDigits[lDigitsIndexN[i]]))->
b0f5e3fc 255 GetStripNumber();
fe15e140 256 if ( (((AliITSdigitSSD*)lDigits[lDigitsIndexN[i-1]])->
aacedc3e 257 GetStripNumber())
fe15e140 258 == (currentstripNo-1) ) dbuffer[dnumber++]=lDigitsIndexN[i];
259 else {
260 new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,
aacedc3e 261 Digits(),
262 fgkSIDEN);
fe15e140 263 dbuffer[0]=lDigitsIndexN[i];
264 dnumber = 1;
265 } // end if else
266 } // end loop over fNDigitsN
267 new(lClusterN[fNClusterN++]) AliITSclusterSSD(dnumber,dbuffer,
aacedc3e 268 Digits(),fgkSIDEN);
fe15e140 269 delete [] dbuffer;
270
271 } // end condition on NDigits
272
f77f13c8 273 AliDebug(1,Form("\n Found clusters: fNClusterP = %d fNClusterN =%d",fNClusterP,fNClusterN));
fe15e140 274}
275//______________________________________________________________________
276void AliITSClusterFinderSSD::SeparateOverlappedClusters(){
277 // overlapped clusters separation
278 register Int_t i; //iterator
aacedc3e 279 Double_t factor=0.75; // How many percent must be lower signal
fe15e140 280 // on the middle one digit
281 // from its neighbours
282 Int_t signal0; //signal on the strip before the current one
283 Int_t signal1; //signal on the current one signal
284 Int_t signal2; //signal on the strip after the current one
285 TArrayI *splitlist; // List of splits
286 Int_t numerofsplits=0; // number of splits
287 Int_t initPsize = fNClusterP; //initial size of the arrays
288 Int_t initNsize = fNClusterN; //we have to keep it because it will grow
289 // in this function and it doasn't make
290 // sense to pass through it again
291 splitlist = new TArrayI(300);
292
293 for (i=0;i<initPsize;i++){
294 if (( ((AliITSclusterSSD*)(*fClusterP)[i])->
295 GetNumOfDigits())==1) continue;
296 if (( ((AliITSclusterSSD*)(*fClusterP)[i])->
297 GetNumOfDigits())==2) continue;
b0f5e3fc 298 Int_t nj=(((AliITSclusterSSD*)(*fClusterP)[i])->GetNumOfDigits()-1);
fe15e140 299 for (Int_t j=1; j<nj; j++){
b0f5e3fc 300 signal1=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j);
301 signal0=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j-1);
302 signal2=((AliITSclusterSSD*)(*fClusterP)[i])->GetDigitSignal(j+1);
303 //if signal is less then factor*signal of its neighbours
fe15e140 304 if ( (signal1<(factor*signal0)) && (signal1<(factor*signal2)) ){
305 (*splitlist)[numerofsplits++]=j;
306 } // end if
307 } // end loop over number of digits
308 //split this cluster if necessary
309 if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,fgkSIDEP);
310 numerofsplits=0;
311 //in signed places (splitlist)
312 } // end loop over clusters on Pside
313
314 for (i=0;i<initNsize;i++) {
315 if (( ((AliITSclusterSSD*)(*fClusterN)[i])->
316 GetNumOfDigits())==1) continue;
317 if (( ((AliITSclusterSSD*)(*fClusterN)[i])->
318 GetNumOfDigits())==2) continue;
319 Int_t nj=(((AliITSclusterSSD*)(*fClusterN)[i])->GetNumOfDigits()-1);
320 for (Int_t j=1; j<nj; j++){
b0f5e3fc 321 signal1=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j);
322 signal0=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j-1);
323 signal2=((AliITSclusterSSD*)(*fClusterN)[i])->GetDigitSignal(j+1);
324 //if signal is less then factor*signal of its neighbours
325 if ( (signal1<(factor*signal0)) && (signal1<(factor*signal2)) )
fe15e140 326 (*splitlist)[numerofsplits++]=j;
327 } // end loop over number of digits
328 //split this cluster into more clusters
329 if(numerofsplits>0) SplitCluster(splitlist,numerofsplits,i,fgkSIDEN);
330 numerofsplits=0;
331 //in signed places (splitlist)
332 } // end loop over clusters on Nside
333
334 delete splitlist;
b0f5e3fc 335}
fe15e140 336//______________________________________________________________________
337void AliITSClusterFinderSSD::SplitCluster(TArrayI *list, Int_t nsplits,
338 Int_t index, Bool_t side){
339 //This function splits one side cluster into more clusters
340 //number of splits is defined by "nsplits"
341 //Place of splits are defined in the TArray "list"
342 // For further optimisation: Replace this function by two
343 // specialised ones (each for one side)
344 // save one "if"
345 //For comlete comments see AliITSclusterSSD::SplitCluster
346 register Int_t i; //iterator
347 AliITSclusterSSD* curentcluster;
348 Int_t *tmpdigits = new Int_t[100];
bf3f2830 349 Int_t nn;
fe15e140 350
351 // side true means P side
352 if (side) {
353 curentcluster =((AliITSclusterSSD*)((*fClusterP)[index])) ;
354 for (i = nsplits; i>0 ;i--) {
bf3f2830 355 nn=curentcluster->SplitCluster((*list)[(i-1)],tmpdigits);
356 new ((*fClusterP)[fNClusterP]) AliITSclusterSSD(nn,tmpdigits,
fe15e140 357 Digits(),side);
358 ( (AliITSclusterSSD*)((*fClusterP)[fNClusterP]) )->
f239b2fe 359 SetLeftNeighbour(kTRUE);
fe15e140 360 //if left cluster had neighbour on the right before split
361 //new should have it too
362 if ( curentcluster->GetRightNeighbour() )
363 ( (AliITSclusterSSD*)((*fClusterP)[fNClusterP]) )->
f239b2fe 364 SetRightNeighbour(kTRUE);
fe15e140 365 else curentcluster->SetRightNeighbour(kTRUE);
366 fNClusterP++;
367 } // end loop over nplits
368 } else {
369 curentcluster =((AliITSclusterSSD*)((*fClusterN)[index]));
370 for (i = nsplits; i>0 ;i--) {
bf3f2830 371 nn=curentcluster->SplitCluster((*list)[(i-1)],tmpdigits);
372 new ((*fClusterN)[fNClusterN]) AliITSclusterSSD(nn,tmpdigits,
fe15e140 373 Digits(),side);
374 ((AliITSclusterSSD*)((*fClusterN)[fNClusterN]))->
f239b2fe 375 SetRightNeighbour(kTRUE);
fe15e140 376 if (curentcluster->GetRightNeighbour())
377 ( (AliITSclusterSSD*)( (*fClusterN)[fNClusterN]) )->
f239b2fe 378 SetRightNeighbour(kTRUE);
fe15e140 379 else curentcluster->SetRightNeighbour(kTRUE);
380 fNClusterN++;
381 } // end loop over nplits
382 } // end if side
383 delete []tmpdigits;
b0f5e3fc 384}
fe15e140 385//______________________________________________________________________
386Int_t AliITSClusterFinderSSD::SortDigitsP(Int_t start, Int_t end){
387 // sort digits on the P side
388 Int_t right;
389 Int_t left;
390
391 if (start != (end - 1) ){
392 left=this->SortDigitsP(start,(start+end)/2);
393 right=this->SortDigitsP((start+end)/2,end);
394 return (left || right);
395 }else{
396 left = ((AliITSdigitSSD*)((*(Digits()))[(*fDigitsIndexP)[start]]))->
397 GetStripNumber();
398 right= ((AliITSdigitSSD*)((*(Digits()))[(*fDigitsIndexP)[end]]))->
399 GetStripNumber();
400 if( left > right ){
401 Int_t tmp = (*fDigitsIndexP)[start];
402 (*fDigitsIndexP)[start]=(*fDigitsIndexP)[end];
403 (*fDigitsIndexP)[end]=tmp;
404 return 1;
405 }else return 0;
406 } // end if
b0f5e3fc 407}
fe15e140 408//______________________________________________________________________
409Int_t AliITSClusterFinderSSD::SortDigitsN(Int_t start, Int_t end){
410 // sort digits on the N side
411 Int_t right;
412 Int_t left;
413
414 if (start != (end - 1)){
aacedc3e 415 left=this->SortDigitsN(start,(start+end)/2);
416 right=this->SortDigitsN((start+end)/2,end);
417 return (left || right);
fe15e140 418 }else{
aacedc3e 419 left =((AliITSdigitSSD*)((*(Digits()))[(*fDigitsIndexN)[start]]))->
420 GetStripNumber();
421 right=((AliITSdigitSSD*)((*(Digits()))[(*fDigitsIndexN)[end]]))->
422 GetStripNumber();
423 if ( left > right ){
424 Int_t tmp = (*fDigitsIndexN)[start];
425 (*fDigitsIndexN)[start]=(*fDigitsIndexN)[end];
426 (*fDigitsIndexN)[end]=tmp;
427 return 1;
428 }else return 0;
fe15e140 429 } // end if
b0f5e3fc 430}
fe15e140 431//______________________________________________________________________
432void AliITSClusterFinderSSD::FillDigitsIndex(){
433 //Fill the indexes of the clusters belonging to a given ITS module
bf3f2830 434 Int_t pns=0, nns=0;
fe15e140 435 Int_t tmp,bit,k;
bf3f2830 436 Int_t noentries;
fe15e140 437 Int_t i;
438
aacedc3e 439 noentries = NDigits();
fe15e140 440
bf3f2830 441 Int_t* psidx = new Int_t [noentries*sizeof(Int_t)];
442 Int_t* nsidx = new Int_t [noentries*sizeof(Int_t)];
443 if (fDigitsIndexP==NULL) fDigitsIndexP = new TArrayI(noentries);
444 if (fDigitsIndexN==NULL) fDigitsIndexN = new TArrayI(noentries);
fe15e140 445
446 AliITSdigitSSD *dig;
447
bf3f2830 448 for ( i = 0 ; i< noentries; i++ ) {
aacedc3e 449 dig = (AliITSdigitSSD*)GetDigit(i);
450 if(dig->IsSideP()) {
451 bit=1;
452 tmp=dig->GetStripNumber();
453 // I find this totally unnecessary - it's just a
454 // CPU consuming double check
455 for( k=0;k<pns;k++){
456 if (tmp==psidx[k]){
f77f13c8 457 AliDebug(1,"Such a digit exists");
aacedc3e 458 bit=0;
459 } // end if
460 } // end for k
461 // end comment
462 if(bit) {
463 fDigitsIndexP->AddAt(i,fNDigitsP++);
464 psidx[pns++]=tmp;
465 } // end if bit
466 } else {
467 bit=1;
468 tmp=dig->GetStripNumber();
469 // same as above
470 for( k=0;k<nns;k++){
471 if (tmp==nsidx[k]){
f77f13c8 472 AliDebug(1,"Such a digit exists");
aacedc3e 473 bit=0;
474 } // end if
475 } // for k
476 // end comment
477 if (bit) {
478 fDigitsIndexN->AddAt(i,fNDigitsN++);
479 nsidx[nns++] =tmp;
480 } // end if bit
481 } // end if
fe15e140 482 } // end for i
483
bf3f2830 484 delete [] psidx;
485 delete [] nsidx;
fe15e140 486
f77f13c8 487 AliDebug(1,Form("Digits: P = %d N = %d",fNDigitsP,fNDigitsN));
b0f5e3fc 488}
fe15e140 489//______________________________________________________________________
490void AliITSClusterFinderSSD::SortDigits(){
491 // sort digits
492 Int_t i;
493
494 if(fNDigitsP>1) for (i=0;i<fNDigitsP-1;i++)
aacedc3e 495 if (SortDigitsP(0,(fNDigitsP-1-i))==0) break;
fe15e140 496 if(fNDigitsN>1) for (i=0;i<fNDigitsN-1;i++)
aacedc3e 497 if(SortDigitsN(0,(fNDigitsN-1-i))==0) break;
b0f5e3fc 498}
fe15e140 499//______________________________________________________________________
aacedc3e 500void AliITSClusterFinderSSD::FillClIndexArrays(Int_t* arrayP,Int_t *arrayN)
501 const{
fe15e140 502 // fill cluster index array
503 register Int_t i;
f239b2fe 504
fe15e140 505 for (i=0; i<fNClusterP;i++) arrayP[i]=i;
506 for (i=0; i<fNClusterN;i++) arrayN[i]=i;
b0f5e3fc 507}
fe15e140 508//______________________________________________________________________
509void AliITSClusterFinderSSD::SortClusters(Int_t* arrayP, Int_t *arrayN){
510 // sort clusters
511 Int_t i;
512
513 if(fNClusterP>1) for (i=0;i<fNClusterP-1;i++)
aacedc3e 514 if (SortClustersP(0,(fNClusterP-1),arrayP)==0) break;
515 if(fNClusterN>1) for (i=0;i<fNClusterN-1;i++)
516 if (SortClustersN(0,(fNClusterN-1),arrayN)==0) break;
b0f5e3fc 517}
fe15e140 518//______________________________________________________________________
519Int_t AliITSClusterFinderSSD::SortClustersP(Int_t start, Int_t end,
520 Int_t *array){
521 //Sort P side clusters
522 Int_t right;
523 Int_t left;
524
525 if (start != (end - 1) ) {
aacedc3e 526 left=this->SortClustersP(start,(start+end)/2,array);
527 right=this->SortClustersP((start+end)/2,end,array);
528 return (left || right);
fe15e140 529 } else {
aacedc3e 530 left =((AliITSclusterSSD*)((*fClusterP)[array[start]]))->
531 GetDigitStripNo(0);
532 right=((AliITSclusterSSD*)((*fClusterP)[array[ end ]]))->
533 GetDigitStripNo(0);
534 if(left>right) {
535 Int_t tmp = array[start];
536 array[start]=array[end];
537 array[end]=tmp;
538 return 1;
539 } else return 0;
fe15e140 540 } // end if
b0f5e3fc 541}
fe15e140 542//______________________________________________________________________
543Int_t AliITSClusterFinderSSD::SortClustersN(Int_t start, Int_t end,
aacedc3e 544 Int_t *array){
fe15e140 545 //Sort N side clusters
546 Int_t right;
547 Int_t left;
548
549 if (start != (end - 1) ) {
aacedc3e 550 left=this->SortClustersN(start,(start+end)/2,array);
551 right=this->SortClustersN((start+end)/2,end,array);
552 return (left || right);
fe15e140 553 } else {
aacedc3e 554 left =((AliITSclusterSSD*)((*fClusterN)[array[start]]))->
555 GetDigitStripNo(0);
556 right=((AliITSclusterSSD*)((*fClusterN)[array[ end ]]))->
557 GetDigitStripNo(0);
558 if( left > right) {
559 Int_t tmp = array[start];
560 array[start]=array[end];
561 array[end]=tmp;
562 return 1;
563 } else return 0;
fe15e140 564 } // end if
b0f5e3fc 565}
fe15e140 566//______________________________________________________________________
567void AliITSClusterFinderSSD::ClustersToPackages(){
568 // fill packages
f239b2fe 569
fe15e140 570 Int_t *oneSclP = new Int_t[fNClusterP];//I want to have sorted 1 S clusters
571 Int_t *oneSclN = new Int_t[fNClusterN];//I can not sort it in TClonesArray
572 //so, I create table of indexes and
573 //sort it
574 //I do not use TArrayI on purpose
575 //MB: well, that's not true that one
576 //cannot sort objs in TClonesArray
577 AliITSclusterSSD *currentP;
578 AliITSclusterSSD *currentN;
579 Int_t j1, j2;
580
581 //Fills in One Side Clusters Index Array
582 FillClIndexArrays(oneSclP,oneSclN);
583 //Sorts filled Arrays
584 //SortClusters(oneSclP,oneSclN);
585
586 fNPackages=1;
587 new ((*fPackages)[0]) AliITSpackageSSD(fClusterP,fClusterN);
588
589 //This part was includede by Boris Batiounia in March 2001.
590 // Take all recpoint pairs (x coordinates) in both P and N sides
591 // to calculate z coordinates of the recpoints
592
593 for (j1=0;j1<fNClusterP;j1++) {
594 currentP = GetPSideCluster(oneSclP[j1]);
595 Double_t xP = currentP->GetPosition();
aacedc3e 596 Double_t signalP = currentP->GetTotalSignal();
fe15e140 597 for (j2=0;j2<fNClusterN;j2++) {
598 currentN = GetNSideCluster(oneSclN[j2]);
599 Double_t xN = currentN->GetPosition();
aacedc3e 600 Double_t signalN = currentN->GetTotalSignal();
fe15e140 601 CreateNewRecPoint(xP,1,xN,1,signalP,signalN,currentP,currentN,
aacedc3e 602 0.75);
fe15e140 603 } // end for j2
604 } // end for j1
605
606 delete [] oneSclP;
607 delete [] oneSclN;
b0f5e3fc 608}
fe15e140 609//______________________________________________________________________
aacedc3e 610Bool_t AliITSClusterFinderSSD::CreateNewRecPoint(Double_t P,Double_t dP,
611 Double_t N, Double_t dN,
612 Double_t SigP,Double_t SigN,
fe15e140 613 AliITSclusterSSD *clusterP,
614 AliITSclusterSSD *clusterN,
615 Stat_t prob){
616 // create the recpoints
aacedc3e 617 const Double_t kADCtoKeV = 2.16;
fe15e140 618 // 50 ADC units -> 30000 e-h pairs; 1e-h pair -> 3.6e-3 KeV;
619 // 1 ADC unit -> (30000/50)*3.6e-3 = 2.16 KeV
aacedc3e 620 const Double_t kconv = 1.0e-4;
621 const Double_t kRMSx = 20.0*kconv;
622 const Double_t kRMSz = 800.0*kconv;
fe15e140 623 Int_t n=0;
624 Int_t *tr;
bf3f2830 625 Int_t ntracks;
fe15e140 626
627 if (GetCrossing(P,N)) {
aacedc3e 628 //GetCrossingError(dP,dN);
629 dP = dN = prob = 0.0; // to remove unused variable warning.
630 AliITSRawClusterSSD cnew;
631 Int_t nstripsP=clusterP->GetNumOfDigits();
632 Int_t nstripsN=clusterN->GetNumOfDigits();
633 Double_t signal = 0;
634 Double_t dedx = 0;
635 if(SigP>SigN) {
636 signal = SigP;
637 dedx = SigP*kADCtoKeV;
638 }else{
639 signal = SigN;
640 dedx = SigN*kADCtoKeV;
641 } // end if SigP>SigN
642 tr = (Int_t*) clusterP->GetTracks(n);
643 ntracks = clusterP->GetNTracks();
644 cnew.SetSignalP(SigP);
645 cnew.SetSignalN(SigN);
646 cnew.SetMultiplicity(nstripsP);
647 cnew.SetMultN(nstripsN);
648 cnew.SetQErr(TMath::Abs(SigP-SigN));
649 cnew.SetNTrack(ntracks);
650 fITS->AddCluster(2,&cnew);
651 AliITSRecPoint rnew;
652 rnew.SetX(P*kconv);
653 rnew.SetZ(N*kconv);
654 rnew.SetQ(signal);
655 rnew.SetdEdX(dedx);
656 rnew.SetSigmaX2( kRMSx* kRMSx);
657 rnew.SetSigmaZ2( kRMSz* kRMSz);
658 rnew.fTracks[0]=tr[0];
659 rnew.fTracks[1]=tr[1];
660 rnew.fTracks[2]=tr[2];
661 fITS->AddRecPoint(rnew);
662 return kTRUE;
fe15e140 663 } // end if
664 return kFALSE;
b0f5e3fc 665}
fe15e140 666//______________________________________________________________________
aacedc3e 667void AliITSClusterFinderSSD::CalcStepFactor(Double_t Psteo, Double_t Nsteo){
fe15e140 668 // calculate the step factor for matching clusters
669 // 95 is the pitch, 4000 - dimension along z ?
aacedc3e 670 Double_t dz=GetSeg()->Dz();
fe15e140 671
672 fSFF = ( (Int_t) (Psteo*dz/fPitch ) );// +1;
673 fSFB = ( (Int_t) (Nsteo*dz/fPitch ) );// +1;
b0f5e3fc 674}
fe15e140 675//______________________________________________________________________
676AliITSclusterSSD* AliITSClusterFinderSSD::GetPSideCluster(Int_t idx){
677 // get P side clusters
678
679 if((idx<0)||(idx>=fNClusterP)){
aacedc3e 680 Info("GetPSideCluster","0<index=%d<=%d out of range",idx,fNClusterP);
681 return 0;
fe15e140 682 }else{
aacedc3e 683 return (AliITSclusterSSD*)((*fClusterP)[idx]);
fe15e140 684 } // end if
b0f5e3fc 685}
fe15e140 686//______________________________________________________________________
687AliITSclusterSSD* AliITSClusterFinderSSD::GetNSideCluster(Int_t idx){
688 // get N side clusters
689
690 if((idx<0)||(idx>=fNClusterN)){
aacedc3e 691 Info("GetNSideCluster","0<index=%d >= %d out of range",idx,fNClusterN);
692 return 0;
fe15e140 693 }else{
aacedc3e 694 return (AliITSclusterSSD*)((*fClusterN)[idx]);
fe15e140 695 } // end if
b0f5e3fc 696}
fe15e140 697//______________________________________________________________________
aacedc3e 698Bool_t AliITSClusterFinderSSD::GetCrossing (Double_t &P, Double_t &N){
fe15e140 699 // get crossing
700 // This function was rivised and changed by Boris Batiounia in March 2001
aacedc3e 701 Double_t dx = GetSeg()->Dx(); // detector size in x direction, microns
702 Double_t dz = GetSeg()->Dz(); // detector size in z direction, microns
703 Double_t xL; // x local coordinate
704 Double_t zL; // z local coordinate
705 Double_t x; // x = xL + dx/2
706 Double_t z; // z = zL + dz/2
707 Double_t xP; // x coordinate in the P side from the first P strip
708 Double_t xN; // x coordinate in the N side from the first N strip
bf3f2830 709 Float_t stereoP,stereoN;
fe15e140 710
aacedc3e 711 GetSeg()->Angles(stereoP,stereoN);
bf3f2830 712 fTanP=TMath::Tan(stereoP);
713 fTanN=TMath::Tan(stereoN);
aacedc3e 714 Double_t kP = fTanP; // Tangent of 0.0075 mrad
715 Double_t kN = fTanN; // Tangent of 0.0275 mrad
b0f5e3fc 716 P *= fPitch;
717 N *= fPitch;
6298ec22 718
fd61217e 719 xP = N; // change the mistake for the P/N
720 xN = P; // coordinates correspondence in this function
6298ec22 721
bf3f2830 722 x = xP + kP*(dz*kN-xP+xN)/(kP+kN);
723 z = (dz*kN-xP+xN)/(kP+kN);
724 xL = x - dx/2;
725 zL = z - dz/2;
fd61217e 726 P = xL;
727 N = zL;
728
bf3f2830 729 if(TMath::Abs(xL) > dx/2 || TMath::Abs(zL) > dz/2) return kFALSE;
6298ec22 730
fd61217e 731 // Check that xL and zL are inside the detector for the
732 // correspondent xP and xN coordinates
b0f5e3fc 733
734 return kTRUE;
735}
fe15e140 736//______________________________________________________________________
aacedc3e 737void AliITSClusterFinderSSD::GetCrossingError(Double_t& dP, Double_t& dN){
fe15e140 738 // get crossing error
aacedc3e 739 Double_t dz, dx;
fe15e140 740
741 dz = TMath::Abs(( dP + dN )*fPitch/(fTanP + fTanN) );
742 dx = fPitch*(TMath::Abs(dP*(1 - fTanP/(fTanP + fTanN))) +
aacedc3e 743 TMath::Abs(dN *fTanP/(fTanP + fTanN) ));
fe15e140 744 dN = dz;
745 dP = dx;
b0f5e3fc 746}