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 ///////////////////////////////////////////////////////////////////////////
22 //////////////////////////////////////////////////////////////////////////
25 #include "AliITSClusterFinderSDD.h"
26 #include "AliITSMapA1.h"
27 #include "AliITSRawClusterSDD.h"
28 #include "AliITSRecPoint.h"
29 #include "AliITSdigitSDD.h"
30 #include "AliITSDetTypeRec.h"
31 #include "AliITSresponseSDD.h"
32 #include "AliITSCalibrationSDD.h"
33 #include "AliITSsegmentationSDD.h"
36 ClassImp(AliITSClusterFinderSDD)
38 //______________________________________________________________________
39 AliITSClusterFinderSDD::AliITSClusterFinderSDD():
40 AliITSClusterFinder(),
50 // default constructor
52 //______________________________________________________________________
53 AliITSClusterFinderSDD::AliITSClusterFinderSDD(AliITSDetTypeRec* dettyp,
56 AliITSClusterFinder(dettyp),
66 // standard constructor
70 SetCutAmplitude(fDetTypeRec->GetITSgeom()->GetStartSDD());
73 SetMinPeak((Int_t)(((AliITSCalibrationSDD*)GetResp(fDetTypeRec->GetITSgeom()->GetStartSDD()))->
74 GetNoiseAfterElectronics()*5));
80 SetMap(new AliITSMapA1(GetSeg(),Digits(),fCutAmplitude));
82 //______________________________________________________________________
83 void AliITSClusterFinderSDD::SetCutAmplitude(Int_t mod,Double_t nsigma){
84 // set the signal threshold for cluster finder
85 Double_t baseline,noise,noiseAfterEl;
87 GetResp(mod)->GetNoiseParam(noise,baseline);
88 noiseAfterEl = ((AliITSCalibrationSDD*)GetResp(mod))->GetNoiseAfterElectronics();
89 fCutAmplitude = (Int_t)((baseline + nsigma*noiseAfterEl));
91 //______________________________________________________________________
92 void AliITSClusterFinderSDD::Find1DClusters(){
95 // retrieve the parameters
96 Int_t fNofMaps = GetSeg()->Npz();
97 Int_t fMaxNofSamples = GetSeg()->Npx();
98 Int_t fNofAnodes = fNofMaps/2;
100 Double_t fTimeStep = GetSeg()->Dpx(dummy);
101 Double_t fSddLength = GetSeg()->Dx();
102 Double_t fDriftSpeed = GetResp(fModule)->GetDriftSpeed();
103 Double_t anodePitch = GetSeg()->Dpz(dummy);
107 Map()->SetThreshold(fCutAmplitude);
112 GetResp(fModule)->GetNoiseParam(noise,baseline);
114 Int_t nofFoundClusters = 0;
116 Double_t **dfadc = new Double_t*[fNofAnodes];
117 for(i=0;i<fNofAnodes;i++) dfadc[i] = new Double_t[fMaxNofSamples];
123 for(k=0;k<fNofAnodes;k++) {
124 idx = j*fNofAnodes+k;
125 // signal (fadc) & derivative (dfadc)
127 for(l=0; l<fMaxNofSamples; l++) {
128 fadc2=(Double_t)Map()->GetSignal(idx,l);
129 if(l>0) fadc1=(Double_t)Map()->GetSignal(idx,l-1);
130 if(l>0) dfadc[k][l-1] = fadc2-fadc1;
134 for(k=0;k<fNofAnodes;k++) {
135 AliDebug(5,Form("Anode: %d, Wing: %d",k+1,j+1));
136 idx = j*fNofAnodes+k;
140 while(it <= fMaxNofSamples-3) {
144 Double_t fadcmax = 0.;
145 Double_t dfadcmax = 0.;
152 if(id>=fMaxNofSamples) break;
153 fadc=(float)Map()->GetSignal(idx,id);
154 if(fadc > fadcmax) { fadcmax = fadc; imax = id;}
155 if(fadc > (float)fCutAmplitude)lthrt++;
156 if(dfadc[k][id] > dfadcmax) {
157 dfadcmax = dfadc[k][id];
162 if(Map()->TestHit(idx,imax) == kEmpty) {it++; continue;}
165 if(tstart < 0) tstart = 0;
167 if(lthrt >= lthrmint && lthra >= lthrmina) ilcl = 1;
170 Int_t tstop = tstart;
171 Double_t dfadcmin = 10000.;
173 for(ij=0; ij<20; ij++) {
174 if(tstart+ij > 255) { tstop = 255; break; }
175 fadc=(float)Map()->GetSignal(idx,tstart+ij);
176 if((dfadc[k][tstart+ij] < dfadcmin) &&
177 (fadc > fCutAmplitude)) {
179 if(tstop > 255) tstop = 255;
180 dfadcmin = dfadc[k][it+ij];
184 Double_t clusterCharge = 0.;
185 Double_t clusterAnode = k+0.5;
186 Double_t clusterTime = 0.;
187 Int_t clusterMult = 0;
188 Double_t clusterPeakAmplitude = 0.;
189 Int_t its,peakpos = -1;
190 Double_t n, baseline;
191 GetResp(fModule)->GetNoiseParam(n,baseline);
192 for(its=tstart; its<=tstop; its++) {
193 fadc=(float)Map()->GetSignal(idx,its);
194 if(fadc>baseline) fadc -= baseline;
196 clusterCharge += fadc;
197 // as a matter of fact we should take the peak
199 // to get the list of tracks !!!
200 if(fadc > clusterPeakAmplitude) {
201 clusterPeakAmplitude = fadc;
202 //peakpos=Map()->GetHitIndex(idx,its);
203 Int_t shift = (int)(fTimeCorr/fTimeStep);
204 if(its>shift && its<(fMaxNofSamples-shift))
205 peakpos = Map()->GetHitIndex(idx,its+shift);
206 else peakpos = Map()->GetHitIndex(idx,its);
207 if(peakpos<0) peakpos =Map()->GetHitIndex(idx,its);
209 clusterTime += fadc*its;
210 if(fadc > 0) clusterMult++;
212 clusterTime /= (clusterCharge/fTimeStep); // ns
213 if(clusterTime>fTimeCorr) clusterTime -=fTimeCorr;
218 Double_t clusteranodePath = (clusterAnode - fNofAnodes/2)*
220 Double_t clusterDriftPath = clusterTime*fDriftSpeed;
221 clusterDriftPath = fSddLength-clusterDriftPath;
222 if(clusterCharge <= 0.) break;
223 AliITSRawClusterSDD clust(j+1,//i
224 clusterAnode,clusterTime,//ff
226 clusterPeakAmplitude, //f
228 0.,0.,clusterDriftPath,//fff
229 clusteranodePath, //f
232 fDetTypeRec->AddCluster(1,&clust);
240 for(i=0;i<fNofAnodes;i++) delete[] dfadc[i];
245 //______________________________________________________________________
246 void AliITSClusterFinderSDD::Find1DClustersE(){
248 // retrieve the parameters
249 Int_t fNofMaps = GetSeg()->Npz();
250 Int_t fMaxNofSamples = GetSeg()->Npx();
251 Int_t fNofAnodes = fNofMaps/2;
253 Double_t fTimeStep = GetSeg()->Dpx( dummy );
254 Double_t fSddLength = GetSeg()->Dx();
255 Double_t fDriftSpeed = GetResp(fModule)->GetDriftSpeed();
256 Double_t anodePitch = GetSeg()->Dpz( dummy );
257 Double_t n, baseline;
258 GetResp(fModule)->GetNoiseParam( n, baseline );
261 Map()->SetThreshold( fCutAmplitude );
265 // cout << "Search cluster... "<< endl;
266 for( Int_t j=0; j<2; j++ ){
267 for( Int_t k=0; k<fNofAnodes; k++ ){
268 Int_t idx = j*fNofAnodes+k;
274 Double_t charge = 0.;
276 Double_t anode = k+0.5;
278 for( Int_t l=0; l<fMaxNofSamples; l++ ){
279 Double_t fadc = (Double_t)Map()->GetSignal( idx, l );
281 if( on == kFALSE && l<fMaxNofSamples-4){
282 // star RawCluster (reset var.)
283 Double_t fadc1 = (Double_t)Map()->GetSignal( idx, l+1 );
284 if( fadc1 < fadc ) continue;
294 if( fadc > baseline ) fadc -= baseline;
301 Int_t shift = (Int_t)(fTimeCorr/fTimeStep + 0.5);
302 if( l > shift && l < (fMaxNofSamples-shift) )
303 peakpos = Map()->GetHitIndex( idx, l+shift );
305 peakpos = Map()->GetHitIndex( idx, l );
306 if( peakpos < 0) peakpos = Map()->GetHitIndex(idx,l);
311 // min # of timesteps for a RawCluster
312 // Found a RawCluster...
314 time /= (charge/fTimeStep); // ns
315 // time = lmax*fTimeStep; // ns
316 if( time > fTimeCorr ) time -= fTimeCorr; // ns
317 Double_t anodePath =(anode-fNofAnodes/2)*anodePitch;
318 Double_t driftPath = time*fDriftSpeed;
319 driftPath = fSddLength-driftPath;
320 AliITSRawClusterSDD clust(j+1,anode,time,charge,
324 start, stop, 1, k, k );
325 fDetTypeRec->AddCluster( 1, &clust );
326 if(AliDebugLevel()>=5) clust.PrintInfo();
330 } // end if on==kTRUE
335 AliDebug(3,Form("# Rawclusters %d",nClu));
338 //_______________________________________________________________________
339 Int_t AliITSClusterFinderSDD::SearchPeak(Double_t *spect,Int_t xdim,Int_t zdim,
340 Int_t *peakX, Int_t *peakZ,
341 Double_t *peakAmp, Double_t minpeak ){
342 // search peaks on a 2D cluster
343 Int_t npeak = 0; // # peaks
346 for( Int_t z=1; z<zdim-1; z++ ){
347 for( Int_t x=1; x<xdim-2; x++ ){
348 Double_t sxz = spect[x*zdim+z];
349 Double_t sxz1 = spect[(x+1)*zdim+z];
350 Double_t sxz2 = spect[(x-1)*zdim+z];
351 // search a local max. in s[x,z]
352 if( sxz < minpeak || sxz1 <= 0 || sxz2 <= 0 ) continue;
353 if( sxz >= spect[(x+1)*zdim+z ] && sxz >= spect[(x-1)*zdim+z ] &&
354 sxz >= spect[x*zdim +z+1] && sxz >= spect[x*zdim +z-1] &&
355 sxz >= spect[(x+1)*zdim+z+1] && sxz >= spect[(x+1)*zdim+z-1] &&
356 sxz >= spect[(x-1)*zdim+z+1] && sxz >= spect[(x-1)*zdim+z-1] ){
360 peakAmp[npeak] = sxz;
365 // search groups of peaks with same amplitude.
366 Int_t *flag = new Int_t[npeak];
367 for( i=0; i<npeak; i++ ) flag[i] = 0;
368 for( i=0; i<npeak; i++ ){
369 for( j=0; j<npeak; j++ ){
371 if( flag[j] > 0 ) continue;
372 if( peakAmp[i] == peakAmp[j] &&
373 TMath::Abs(peakX[i]-peakX[j])<=1 &&
374 TMath::Abs(peakZ[i]-peakZ[j])<=1 ){
375 if( flag[i] == 0) flag[i] = i+1;
380 // make average of peak groups
381 for( i=0; i<npeak; i++ ){
383 if( flag[i] <= 0 ) continue;
384 for( j=0; j<npeak; j++ ){
386 if( flag[j] != flag[i] ) continue;
387 peakX[i] += peakX[j];
388 peakZ[i] += peakZ[j];
391 for( Int_t k=j; k<npeak; k++ ){
392 peakX[k] = peakX[k+1];
393 peakZ[k] = peakZ[k+1];
394 peakAmp[k] = peakAmp[k+1];
407 //______________________________________________________________________
408 void AliITSClusterFinderSDD::PeakFunc( Int_t xdim, Int_t zdim, Double_t *par,
409 Double_t *spe, Double_t *integral){
410 // function used to fit the clusters
411 // par -> parameters..
412 // par[0] number of peaks.
413 // for each peak i=1, ..., par[0]
419 Int_t electronics = GetResp(fModule)->GetElectronics(); // 1 = PASCAL, 2 = OLA
420 const Int_t knParam = 5;
421 Int_t npeak = (Int_t)par[0];
423 memset( spe, 0, sizeof( Double_t )*zdim*xdim );
426 for( Int_t i=0; i<npeak; i++ ){
427 if( integral != 0 ) integral[i] = 0.;
428 Double_t sigmaA2 = par[k+4]*par[k+4]*2.;
429 Double_t t2 = par[k+3]; // PASCAL
430 if( electronics == 2 ) { t2 *= t2; t2 *= 2; } // OLA
431 for( Int_t z=0; z<zdim; z++ ){
432 for( Int_t x=0; x<xdim; x++ ){
433 Double_t z2 = (z-par[k+2])*(z-par[k+2])/sigmaA2;
435 Double_t signal = 0.;
436 if( electronics == 1 ){ // PASCAL
437 x2 = (x-par[k+1]+t2)/t2;
438 signal = (x2>0.) ? par[k]*x2*exp(-x2+1.-z2) :0.0; // RCCR2
439 // signal =(x2>0.) ? par[k]*x2*x2*exp(-2*x2+2.-z2 ):0.0;//RCCR
440 }else if( electronics == 2 ) { // OLA
441 x2 = (x-par[k+1])*(x-par[k+1])/t2;
442 signal = par[k] * exp( -x2 - z2 );
444 Warning("PeakFunc","Wrong SDD Electronics = %d",
447 } // end if electronicx
448 spe[x*zdim+z] += signal;
449 if( integral != 0 ) integral[i] += signal;
456 //__________________________________________________________________________
457 Double_t AliITSClusterFinderSDD::ChiSqr( Int_t xdim, Int_t zdim, Double_t *spe,
458 Double_t *speFit ) const{
459 // EVALUATES UNNORMALIZED CHI-SQUARED
461 for( Int_t z=0; z<zdim; z++ ){
462 for( Int_t x=1; x<xdim-1; x++ ){
463 Int_t index = x*zdim+z;
464 Double_t tmp = spe[index] - speFit[index];
470 //_______________________________________________________________________
471 void AliITSClusterFinderSDD::Minim( Int_t xdim, Int_t zdim, Double_t *param,
472 Double_t *prm0,Double_t *steprm,
473 Double_t *chisqr,Double_t *spe,
476 Int_t k, nnn, mmm, i;
477 Double_t p1, delta, d1, chisq1, p2, chisq2, t, p3, chisq3, a, b, p0, chisqt;
478 const Int_t knParam = 5;
479 Int_t npeak = (Int_t)param[0];
480 for( k=1; k<(npeak*knParam+1); k++ ) prm0[k] = param[k];
481 for( k=1; k<(npeak*knParam+1); k++ ){
485 // ENSURE THAT STEP SIZE IS SENSIBLY LARGER THAN MACHINE ROUND OFF
486 if( TMath::Abs( p1 ) > 1.0E-6 )
487 if ( TMath::Abs( delta/p1 ) < 1.0E-4 ) delta = p1/1000;
488 else delta = (Double_t)1.0E-4;
489 // EVALUATE CHI-SQUARED AT FIRST TWO SEARCH POINTS
490 PeakFunc( xdim, zdim, param, speFit );
491 chisq1 = ChiSqr( xdim, zdim, spe, speFit );
494 PeakFunc( xdim, zdim, param, speFit );
495 chisq2 = ChiSqr( xdim, zdim, spe, speFit );
496 if( chisq1 < chisq2 ){
497 // REVERSE DIRECTION OF SEARCH IF CHI-SQUARED IS INCREASING
507 do { // INCREMENT param(K) UNTIL CHI-SQUARED STARTS TO INCREASE
510 mmm = nnn - (nnn/5)*5; // multiplo de 5
513 // INCREASE STEP SIZE IF STEPPING TOWARDS MINIMUM IS TOO SLOW
517 // Constrain paramiters
518 Int_t kpos = (k-1) % knParam;
521 if( param[k] <= 20 ) param[k] = fMinPeak;
524 if( TMath::Abs( param[k] - prm0[k] ) > 1.5 ) param[k] = prm0[k];
527 if( TMath::Abs( param[k] - prm0[k] ) > 1. ) param[k] = prm0[k];
530 if( param[k] < .5 ) param[k] = .5;
533 if( param[k] < .288 ) param[k] = .288;// 1/sqrt(12) = 0.288
534 if( param[k] > zdim*.5 ) param[k] = zdim*.5;
537 PeakFunc( xdim, zdim, param, speFit );
538 chisq3 = ChiSqr( xdim, zdim, spe, speFit );
539 if( chisq3 < chisq2 && nnn < 50 ){
546 // FIND MINIMUM OF PARABOLA DEFINED BY LAST THREE POINTS
547 a = chisq1*(p2-p3)+chisq2*(p3-p1)+chisq3*(p1-p2);
548 b = chisq1*(p2*p2-p3*p3)+chisq2*(p3*p3-p1*p1)+chisq3*(p1*p1-p2*p2);
549 if( a!=0 ) p0 = (Double_t)(0.5*b/a);
551 //--IN CASE OF NEARLY EQUAL CHI-SQUARED AND TOO SMALL STEP SIZE PREVENT
552 // ERRONEOUS EVALUATION OF PARABOLA MINIMUM
553 //---NEXT TWO LINES CAN BE OMITTED FOR HIGHER PRECISION MACHINES
554 //dp = (Double_t) max (TMath::Abs(p3-p2), TMath::Abs(p2-p1));
555 //if( TMath::Abs( p2-p0 ) > dp ) p0 = p2;
557 // Constrain paramiters
558 Int_t kpos = (k-1) % knParam;
561 if( param[k] <= 20 ) param[k] = fMinPeak;
564 if( TMath::Abs( param[k] - prm0[k] ) > 1.5 ) param[k] = prm0[k];
567 if( TMath::Abs( param[k] - prm0[k] ) > 1. ) param[k] = prm0[k];
570 if( param[k] < .5 ) param[k] = .5;
573 if( param[k] < .288 ) param[k] = .288; // 1/sqrt(12) = 0.288
574 if( param[k] > zdim*.5 ) param[k] = zdim*.5;
577 PeakFunc( xdim, zdim, param, speFit );
578 chisqt = ChiSqr( xdim, zdim, spe, speFit );
579 // DO NOT ALLOW ERRONEOUS INTERPOLATION
580 if( chisqt <= *chisqr ) *chisqr = chisqt;
581 else param[k] = prm0[k];
582 // OPTIMIZE SEARCH STEP FOR EVENTUAL NEXT CALL OF MINIM
583 steprm[k] = (param[k]-prm0[k])/5;
584 if( steprm[k] >= d1 ) steprm[k] = d1/5;
586 // EVALUATE FIT AND CHI-SQUARED FOR OPTIMIZED PARAMETERS
587 PeakFunc( xdim, zdim, param, speFit );
588 *chisqr = ChiSqr( xdim, zdim, spe, speFit );
591 //_________________________________________________________________________
592 Int_t AliITSClusterFinderSDD::NoLinearFit( Int_t xdim, Int_t zdim,
593 Double_t *param, Double_t *spe,
594 Int_t *niter, Double_t *chir ){
595 // fit method from Comput. Phys. Commun 46(1987) 149
596 const Double_t kchilmt = 0.01; // relative accuracy
597 const Int_t knel = 3; // for parabolic minimization
598 const Int_t knstop = 50; // Max. iteration number
599 const Int_t knParam = 5;
600 Int_t npeak = (Int_t)param[0];
601 // RETURN IF NUMBER OF DEGREES OF FREEDOM IS NOT POSITIVE
602 if( (xdim*zdim - npeak*knParam) <= 0 ) return( -1 );
603 Double_t degFree = (xdim*zdim - npeak*knParam)-1;
604 Int_t n, k, iterNum = 0;
605 Double_t *prm0 = new Double_t[npeak*knParam+1];
606 Double_t *step = new Double_t[npeak*knParam+1];
607 Double_t *schi = new Double_t[npeak*knParam+1];
609 sprm[0] = new Double_t[npeak*knParam+1];
610 sprm[1] = new Double_t[npeak*knParam+1];
611 sprm[2] = new Double_t[npeak*knParam+1];
612 Double_t chi0, chi1, reldif, a, b, prmin, dp;
613 Double_t *speFit = new Double_t[ xdim*zdim ];
614 PeakFunc( xdim, zdim, param, speFit );
615 chi0 = ChiSqr( xdim, zdim, spe, speFit );
617 for( k=1; k<(npeak*knParam+1); k++) prm0[k] = param[k];
618 for( k=1 ; k<(npeak*knParam+1); k+=knParam ){
619 step[k] = param[k] / 20.0 ;
620 step[k+1] = param[k+1] / 50.0;
621 step[k+2] = param[k+2] / 50.0;
622 step[k+3] = param[k+3] / 20.0;
623 step[k+4] = param[k+4] / 20.0;
629 Minim( xdim, zdim, param, prm0, step, &chi1, spe, speFit );
630 reldif = ( chi1 > 0 ) ? ((Double_t) TMath::Abs( chi1-chi0)/chi1 ) : 0;
632 if( reldif < (float) kchilmt ){
633 *chir = (chi1>0) ? (float) TMath::Sqrt (chi1/degFree) :0;
638 if( (reldif < (float)(5*kchilmt)) && (iterNum > knstop) ){
639 *chir = (chi1>0) ?(float) TMath::Sqrt (chi1/degFree):0;
644 if( iterNum > 5*knstop ){
645 *chir = (chi1>0) ?(float) TMath::Sqrt (chi1/degFree):0;
650 if( iterNum <= knel ) continue;
651 n = iterNum - (iterNum/knel)*knel; // EXTRAPOLATION LIMIT COUNTER N
652 if( n > 3 || n == 0 ) continue;
654 for( k=1; k<(npeak*knParam+1); k++ ) sprm[n-1][k] = param[k];
655 if( n != 3 ) continue;
656 // -EVALUATE EXTRAPOLATED VALUE OF EACH PARAMETER BY FINDING MINIMUM OF
657 // PARABOLA DEFINED BY LAST THREE CALLS OF MINIM
658 for( k=1; k<(npeak*knParam+1); k++ ){
659 Double_t tmp0 = sprm[0][k];
660 Double_t tmp1 = sprm[1][k];
661 Double_t tmp2 = sprm[2][k];
662 a = schi[0]*(tmp1-tmp2) + schi[1]*(tmp2-tmp0);
663 a += (schi[2]*(tmp0-tmp1));
664 b = schi[0]*(tmp1*tmp1-tmp2*tmp2);
665 b += (schi[1]*(tmp2*tmp2-tmp0*tmp0)+(schi[2]*
666 (tmp0*tmp0-tmp1*tmp1)));
667 if ((double)a < 1.0E-6) prmin = 0;
668 else prmin = (float) (0.5*b/a);
670 if( TMath::Abs(prmin-tmp2) > TMath::Abs(dp) ) prmin = tmp2+dp;
672 step[k] = dp/10; // OPTIMIZE SEARCH STEP
685 //______________________________________________________________________
686 void AliITSClusterFinderSDD::ResolveClusters(){
687 // The function to resolve clusters if the clusters overlapping exists
689 // get number of clusters for this module
690 Int_t nofClusters = NClusters();
691 nofClusters -= fNclusters;
692 Int_t fNofMaps = GetSeg()->Npz();
693 Int_t fNofAnodes = fNofMaps/2;
694 //Int_t fMaxNofSamples = GetSeg()->Npx();
696 Double_t fTimeStep = GetSeg()->Dpx( dummy );
697 Double_t fSddLength = GetSeg()->Dx();
698 Double_t fDriftSpeed = GetResp(fModule)->GetDriftSpeed();
699 Double_t anodePitch = GetSeg()->Dpz( dummy );
700 Double_t n, baseline;
701 GetResp(fModule)->GetNoiseParam( n, baseline );
702 Int_t electronics =GetResp(fModule)->GetElectronics(); // 1 = PASCAL, 2 = OLA
704 for( Int_t j=0; j<nofClusters; j++ ){
705 // get cluster information
706 AliITSRawClusterSDD *clusterJ=(AliITSRawClusterSDD*) Cluster(j);
707 Int_t astart = clusterJ->Astart();
708 Int_t astop = clusterJ->Astop();
709 Int_t tstart = clusterJ->Tstartf();
710 Int_t tstop = clusterJ->Tstopf();
711 Int_t wing = (Int_t)clusterJ->W();
713 astart += fNofAnodes;
716 Int_t xdim = tstop-tstart+3;
717 Int_t zdim = astop-astart+3;
718 if( xdim > 50 || zdim > 30 ) {
719 Warning("ResolveClusters","xdim: %d , zdim: %d ",xdim,zdim);
722 Double_t *sp = new Double_t[ xdim*zdim+1 ];
723 memset( sp, 0, sizeof(Double_t)*(xdim*zdim+1) );
725 // make a local map from cluster region
726 for( Int_t ianode=astart; ianode<=astop; ianode++ ){
727 for( Int_t itime=tstart; itime<=tstop; itime++ ){
728 Double_t fadc = Map()->GetSignal( ianode, itime );
729 if( fadc > baseline ) fadc -= (Double_t)baseline;
731 Int_t index = (itime-tstart+1)*zdim+(ianode-astart+1);
736 // search peaks on cluster
737 const Int_t kNp = 150;
740 Double_t peakAmp1[kNp];
741 Int_t npeak = SearchPeak(sp,xdim,zdim,peakX1,peakZ1,peakAmp1,fMinPeak);
743 // if multiple peaks, split cluster
745 // cout << "npeak " << npeak << endl;
746 // clusterJ->PrintInfo();
747 Double_t *par = new Double_t[npeak*5+1];
748 par[0] = (Double_t)npeak;
749 // Initial parameters in cell dimentions
751 for( i=0; i<npeak; i++ ){
752 par[k1] = peakAmp1[i];
753 par[k1+1] = peakX1[i]; // local time pos. [timebin]
754 par[k1+2] = peakZ1[i]; // local anode pos. [anodepitch]
755 if( electronics == 1 ) par[k1+3] = 2.; // PASCAL
756 else if(electronics==2) par[k1+3] = 0.7;//tau [timebin] OLA
757 par[k1+4] = .4; // sigma [anodepich]
762 NoLinearFit( xdim, zdim, par, sp, &niter, &chir );
767 Double_t peakAmp[kNp];
768 Double_t integral[kNp];
769 //get integrals => charge for each peak
770 PeakFunc( xdim, zdim, par, sp, integral );
772 for( i=0; i<npeak; i++ ){
773 peakAmp[i] = par[k1];
774 peakX[i] = par[k1+1];
775 peakZ[i] = par[k1+2];
777 sigma[i] = par[k1+4];
780 // calculate parameter for new clusters
781 for( i=0; i<npeak; i++ ){
782 AliITSRawClusterSDD clusterI( *clusterJ );
784 Int_t newAnode = peakZ1[i]-1 + astart;
786 // Int_t newiTime = peakX1[i]-1 + tstart;
787 // Int_t shift = (Int_t)(fTimeCorr/fTimeStep + 0.5);
788 // if( newiTime > shift && newiTime < (fMaxNofSamples-shift) )
790 // Int_t peakpos = Map()->GetHitIndex(newAnode,newiTime+shift );
791 // clusterI.SetPeakPos( peakpos );
793 clusterI.SetPeakAmpl( peakAmp1[i] );
794 Double_t newAnodef = peakZ[i] - 0.5 + astart;
795 Double_t newiTimef = peakX[i] - 1 + tstart;
796 if( wing == 2 ) newAnodef -= fNofAnodes;
797 Double_t anodePath = (newAnodef - fNofAnodes/2)*anodePitch;
798 newiTimef *= fTimeStep;
799 if( newiTimef > fTimeCorr ) newiTimef -= fTimeCorr;
800 if( electronics == 1 ){
801 // newiTimef *= 0.999438; // PASCAL
802 // newiTimef += (6./fDriftSpeed - newiTimef/3000.);
803 }else if( electronics == 2 )
804 newiTimef *= 0.99714; // OLA
806 Int_t timeBin = (Int_t)(newiTimef/fTimeStep+0.5);
807 Int_t peakpos = Map()->GetHitIndex( newAnode, timeBin );
809 for( Int_t ii=0; ii<3; ii++ ) {
810 peakpos = Map()->GetHitIndex( newAnode, timeBin+ii );
811 if( peakpos > 0 ) break;
812 peakpos = Map()->GetHitIndex( newAnode, timeBin-ii );
813 if( peakpos > 0 ) break;
818 //Warning("ResolveClusters",
819 // "Digit not found for cluster");
820 //if(AliDebugLevel()>=3) clusterI.PrintInfo();
823 clusterI.SetPeakPos( peakpos );
824 Double_t driftPath = fSddLength - newiTimef * fDriftSpeed;
825 Double_t sign = ( wing == 1 ) ? -1. : 1.;
826 clusterI.SetX( driftPath*sign * 0.0001 );
827 clusterI.SetZ( anodePath * 0.0001 );
828 clusterI.SetAnode( newAnodef );
829 clusterI.SetTime( newiTimef );
830 clusterI.SetAsigma( sigma[i]*anodePitch );
831 clusterI.SetTsigma( tau[i]*fTimeStep );
832 clusterI.SetQ( integral[i] );
834 fDetTypeRec->AddCluster( 1, &clusterI );
836 Clusters()->RemoveAt( j );
838 } else { // something odd
839 Warning( "ResolveClusters",
840 "--- Peak not found!!!! minpeak=%d ,cluster peak= %f"
842 fMinPeak, clusterJ->PeakAmpl(),GetModule());
843 clusterJ->PrintInfo();
844 Warning( "ResolveClusters"," xdim= %d zdim= %d", xdim-2, zdim-2 );
848 Clusters()->Compress();
849 // Map()->ClearMap();
851 //________________________________________________________________________
852 void AliITSClusterFinderSDD::GroupClusters(){
855 Double_t fTimeStep = GetSeg()->Dpx(dummy);
856 // get number of clusters for this module
857 Int_t nofClusters = NClusters();
858 nofClusters -= fNclusters;
859 AliITSRawClusterSDD *clusterI;
860 AliITSRawClusterSDD *clusterJ;
861 Int_t *label = new Int_t [nofClusters];
863 for(i=0; i<nofClusters; i++) label[i] = 0;
864 for(i=0; i<nofClusters; i++) {
865 if(label[i] != 0) continue;
866 for(j=i+1; j<nofClusters; j++) {
867 if(label[j] != 0) continue;
868 clusterI = (AliITSRawClusterSDD*) Cluster(i);
869 clusterJ = (AliITSRawClusterSDD*) Cluster(j);
871 if(clusterI->T() < fTimeStep*60) fDAnode = 4.2; // TB 3.2
872 if(clusterI->T() < fTimeStep*10) fDAnode = 1.5; // TB 1.
873 Bool_t pair = clusterI->Brother(clusterJ,fDAnode,fDTime);
875 if(AliDebugLevel()>=4){
876 clusterI->PrintInfo();
877 clusterJ->PrintInfo();
878 } // end if AliDebugLevel
879 clusterI->Add(clusterJ);
881 Clusters()->RemoveAt(j);
886 Clusters()->Compress();
891 //________________________________________________________________________
892 void AliITSClusterFinderSDD::SelectClusters(){
893 // get number of clusters for this module
894 Int_t nofClusters = NClusters();
896 nofClusters -= fNclusters;
898 for(i=0; i<nofClusters; i++) {
899 AliITSRawClusterSDD *clusterI =(AliITSRawClusterSDD*) Cluster(i);
902 if(clusterI->Anodes() != 0.) {
903 wy = ((Double_t) clusterI->Samples())/clusterI->Anodes();
905 Int_t amp = (Int_t) clusterI->PeakAmpl();
906 Int_t cha = (Int_t) clusterI->Q();
907 if(amp < fMinPeak) rmflg = 1;
908 if(cha < fMinCharge) rmflg = 1;
909 if(wy < fMinNCells) rmflg = 1;
910 //if(wy > fMaxNCells) rmflg = 1;
911 if(rmflg) Clusters()->RemoveAt(i);
913 Clusters()->Compress();
917 //______________________________________________________________________
918 void AliITSClusterFinderSDD::GetRecPoints(){
921 // get number of clusters for this module
922 Int_t nofClusters = NClusters();
923 nofClusters -= fNclusters;
924 const Double_t kconvGeV = 1.e-6; // GeV -> KeV
925 const Double_t kconv = 1.0e-4;
926 const Double_t kRMSx = 38.0*kconv; // microns->cm ITS TDR Table 1.3
927 const Double_t kRMSz = 28.0*kconv; // microns->cm ITS TDR Table 1.3
929 Int_t ix, iz, idx=-1;
930 AliITSdigitSDD *dig=0;
931 Int_t ndigits=NDigits();
932 for(i=0; i<nofClusters; i++) {
933 AliITSRawClusterSDD *clusterI = (AliITSRawClusterSDD*)Cluster(i);
934 if(!clusterI) Error("SDD: GetRecPoints","i clusterI ",i,clusterI);
935 if(clusterI) idx=clusterI->PeakPos();
936 if(idx>ndigits) Error("SDD: GetRecPoints","idx ndigits",idx,ndigits);
937 // try peak neighbours - to be done
938 if(idx&&idx<= ndigits) dig =(AliITSdigitSDD*)GetDigit(idx);
941 GetSeg()->GetPadIxz(clusterI->X(),clusterI->Z(),ix,iz);
942 dig = (AliITSdigitSDD*)Map()->GetHit(iz-1,ix-1);
943 // if null try neighbours
944 if (!dig) dig = (AliITSdigitSDD*)Map()->GetHit(iz-1,ix);
945 if (!dig) dig = (AliITSdigitSDD*)Map()->GetHit(iz-1,ix+1);
946 if (!dig) printf("SDD: cannot assign the track number!\n");
949 rnew.SetX(clusterI->X());
950 rnew.SetZ(clusterI->Z());
951 rnew.SetQ(clusterI->Q()); // in KeV - should be ADC
952 rnew.SetdEdX(kconvGeV*clusterI->Q());
953 rnew.SetSigmaX2(kRMSx*kRMSx);
954 rnew.SetSigmaZ2(kRMSz*kRMSz);
956 if(dig) rnew.fTracks[0]=dig->GetTrack(0);
957 if(dig) rnew.fTracks[1]=dig->GetTrack(1);
958 if(dig) rnew.fTracks[2]=dig->GetTrack(2);
960 fDetTypeRec->AddRecPoint(rnew);
962 // Map()->ClearMap();
964 //______________________________________________________________________
965 void AliITSClusterFinderSDD::FindRawClusters(Int_t mod){
975 //_______________________________________________________________________
976 void AliITSClusterFinderSDD::PrintStatus() const{
977 // Print SDD cluster finder Parameters
979 cout << "**************************************************" << endl;
980 cout << " Silicon Drift Detector Cluster Finder Parameters " << endl;
981 cout << "**************************************************" << endl;
982 cout << "Number of Clusters: " << fNclusters << endl;
983 cout << "Anode Tolerance: " << fDAnode << endl;
984 cout << "Time Tolerance: " << fDTime << endl;
985 cout << "Time correction (electronics): " << fTimeCorr << endl;
986 cout << "Cut Amplitude (threshold): " << fCutAmplitude << endl;
987 cout << "Minimum Amplitude: " << fMinPeak << endl;
988 cout << "Minimum Charge: " << fMinCharge << endl;
989 cout << "Minimum number of cells/clusters: " << fMinNCells << endl;
990 cout << "Maximum number of cells/clusters: " << fMaxNCells << endl;
991 cout << "**************************************************" << endl;