]> git.uio.no Git - u/mrichter/AliRoot.git/blame - ITS/AliITSClusterFinderSDD.cxx
The access to several data members was changed from public to protected. The digitisa...
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderSDD.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 **************************************************************************/
a1f090e0 15#include <iostream.h>
78a228db 16#include <TFile.h>
a1f090e0 17#include <TMath.h>
18#include <math.h>
b0f5e3fc 19
20#include "AliITSClusterFinderSDD.h"
e8189707 21#include "AliITSMapA1.h"
22#include "AliITS.h"
78a228db 23#include "AliITSdigit.h"
24#include "AliITSRawCluster.h"
25#include "AliITSRecPoint.h"
26#include "AliITSsegmentation.h"
5dd4cc39 27#include "AliITSresponseSDD.h"
b0f5e3fc 28#include "AliRun.h"
29
b0f5e3fc 30ClassImp(AliITSClusterFinderSDD)
31
42da2935 32//______________________________________________________________________
33AliITSClusterFinderSDD::AliITSClusterFinderSDD(AliITSsegmentation *seg,
34 AliITSresponse *response,
35 TClonesArray *digits,
36 TClonesArray *recp){
37 // standard constructor
78a228db 38
b48af428 39 fSegmentation = seg;
40 fResponse = response;
41 fDigits = digits;
42 fClusters = recp;
43 fNclusters = fClusters->GetEntriesFast();
b0f5e3fc 44 SetCutAmplitude();
45 SetDAnode();
46 SetDTime();
b0f5e3fc 47 SetMinPeak();
78a228db 48 SetMinNCells();
49 SetMaxNCells();
50 SetTimeCorr();
a1f090e0 51 SetMinCharge();
b48af428 52 fMap = new AliITSMapA1(fSegmentation,fDigits,fCutAmplitude);
b0f5e3fc 53}
42da2935 54//______________________________________________________________________
55AliITSClusterFinderSDD::AliITSClusterFinderSDD(){
56 // default constructor
b0f5e3fc 57
b48af428 58 fSegmentation = 0;
59 fResponse = 0;
60 fDigits = 0;
61 fClusters = 0;
62 fNclusters = 0;
63 fMap = 0;
64 fCutAmplitude = 0;
b0f5e3fc 65 SetDAnode();
66 SetDTime();
b0f5e3fc 67 SetMinPeak();
78a228db 68 SetMinNCells();
69 SetMaxNCells();
70 SetTimeCorr();
a1f090e0 71 SetMinCharge();
b0f5e3fc 72}
42da2935 73//____________________________________________________________________________
74AliITSClusterFinderSDD::~AliITSClusterFinderSDD(){
e8189707 75 // destructor
76
77 if(fMap) delete fMap;
e8189707 78}
42da2935 79//______________________________________________________________________
80void AliITSClusterFinderSDD::SetCutAmplitude(Float_t nsigma){
81 // set the signal threshold for cluster finder
82 Float_t baseline,noise,noise_after_el;
83
84 fResponse->GetNoiseParam(noise,baseline);
85 noise_after_el = ((AliITSresponseSDD*)fResponse)->GetNoiseAfterElectronics();
b48af428 86 fCutAmplitude = (Int_t)((baseline + nsigma*noise_after_el));
5dd4cc39 87}
42da2935 88//______________________________________________________________________
89void AliITSClusterFinderSDD::Find1DClusters(){
90 // find 1D clusters
b48af428 91 static AliITS *iTS = (AliITS*)gAlice->GetModule("ITS");
a1f090e0 92
42da2935 93 // retrieve the parameters
b48af428 94 Int_t fNofMaps = fSegmentation->Npz();
42da2935 95 Int_t fMaxNofSamples = fSegmentation->Npx();
b48af428 96 Int_t fNofAnodes = fNofMaps/2;
97 Int_t dummy = 0;
98 Float_t fTimeStep = fSegmentation->Dpx(dummy);
99 Float_t fSddLength = fSegmentation->Dx();
100 Float_t fDriftSpeed = fResponse->DriftSpeed();
101 Float_t anodePitch = fSegmentation->Dpz(dummy);
42da2935 102
103 // map the signal
104 fMap->SetThreshold(fCutAmplitude);
105 fMap->FillMap();
a1f090e0 106
42da2935 107 Float_t noise;
108 Float_t baseline;
109 fResponse->GetNoiseParam(noise,baseline);
a1f090e0 110
42da2935 111 Int_t nofFoundClusters = 0;
112 Int_t i;
113 Float_t **dfadc = new Float_t*[fNofAnodes];
114 for(i=0;i<fNofAnodes;i++) dfadc[i] = new Float_t[fMaxNofSamples];
b48af428 115 Float_t fadc = 0.;
42da2935 116 Float_t fadc1 = 0.;
117 Float_t fadc2 = 0.;
118 Int_t j,k,idx,l,m;
119 for(j=0;j<2;j++) {
120 for(k=0;k<fNofAnodes;k++) {
121 idx = j*fNofAnodes+k;
122 // signal (fadc) & derivative (dfadc)
123 dfadc[k][255]=0.;
124 for(l=0; l<fMaxNofSamples; l++) {
125 fadc2=(Float_t)fMap->GetSignal(idx,l);
126 if(l>0) fadc1=(Float_t)fMap->GetSignal(idx,l-1);
127 if(l>0) dfadc[k][l-1] = fadc2-fadc1;
128 } // samples
129 } // anodes
130
131 for(k=0;k<fNofAnodes;k++) {
132 //cout << "Anode: " << k+1 << ", Wing: " << j+1 << endl;
133 idx = j*fNofAnodes+k;
b48af428 134 Int_t imax = 0;
42da2935 135 Int_t imaxd = 0;
b48af428 136 Int_t it = 0;
42da2935 137 while(it <= fMaxNofSamples-3) {
b48af428 138 imax = it;
42da2935 139 imaxd = it;
140 // maximum of signal
b48af428 141 Float_t fadcmax = 0.;
42da2935 142 Float_t dfadcmax = 0.;
b48af428 143 Int_t lthrmina = 1;
144 Int_t lthrmint = 3;
145 Int_t lthra = 1;
146 Int_t lthrt = 0;
42da2935 147 for(m=0;m<20;m++) {
148 Int_t id = it+m;
149 if(id>=fMaxNofSamples) break;
150 fadc=(float)fMap->GetSignal(idx,id);
151 if(fadc > fadcmax) { fadcmax = fadc; imax = id;}
152 if(fadc > (float)fCutAmplitude) {
153 lthrt++;
154 } // end if
155 if(dfadc[k][id] > dfadcmax) {
156 dfadcmax = dfadc[k][id];
b48af428 157 imaxd = id;
42da2935 158 } // end if
159 } // end for m
160 it = imaxd;
161 if(fMap->TestHit(idx,imax) == kEmpty) {it++; continue;}
162 // cluster charge
163 Int_t tstart = it-2;
164 if(tstart < 0) tstart = 0;
165 Bool_t ilcl = 0;
166 if(lthrt >= lthrmint && lthra >= lthrmina) ilcl = 1;
167 if(ilcl) {
168 nofFoundClusters++;
b48af428 169 Int_t tstop = tstart;
42da2935 170 Float_t dfadcmin = 10000.;
171 Int_t ij;
172 for(ij=0; ij<20; ij++) {
173 if(tstart+ij > 255) { tstop = 255; break; }
174 fadc=(float)fMap->GetSignal(idx,tstart+ij);
175 if((dfadc[k][tstart+ij] < dfadcmin) &&
176 (fadc > fCutAmplitude)) {
177 tstop = tstart+ij+5;
178 if(tstop > 255) tstop = 255;
179 dfadcmin = dfadc[k][it+ij];
180 } // end if
181 } // end for ij
182
183 Float_t clusterCharge = 0.;
b48af428 184 Float_t clusterAnode = k+0.5;
185 Float_t clusterTime = 0.;
186 Int_t clusterMult = 0;
42da2935 187 Float_t clusterPeakAmplitude = 0.;
b48af428 188 Int_t its,peakpos = -1;
42da2935 189 Float_t n, baseline;
190 fResponse->GetNoiseParam(n,baseline);
191 for(its=tstart; its<=tstop; its++) {
192 fadc=(float)fMap->GetSignal(idx,its);
b48af428 193 if(fadc>baseline) fadc -= baseline;
194 else fadc = 0.;
42da2935 195 clusterCharge += fadc;
196 // as a matter of fact we should take the peak
197 // pos before FFT
198 // to get the list of tracks !!!
199 if(fadc > clusterPeakAmplitude) {
200 clusterPeakAmplitude = fadc;
201 //peakpos=fMap->GetHitIndex(idx,its);
b48af428 202 Int_t shift = (int)(fTimeCorr/fTimeStep);
42da2935 203 if(its>shift && its<(fMaxNofSamples-shift))
b48af428 204 peakpos = fMap->GetHitIndex(idx,its+shift);
205 else peakpos = fMap->GetHitIndex(idx,its);
206 if(peakpos<0) peakpos =fMap->GetHitIndex(idx,its);
42da2935 207 } // end if
208 clusterTime += fadc*its;
209 if(fadc > 0) clusterMult++;
210 if(its == tstop) {
211 clusterTime /= (clusterCharge/fTimeStep); // ns
b48af428 212 if(clusterTime>fTimeCorr) clusterTime -=fTimeCorr;
42da2935 213 //ns
214 } // end if
215 } // end for its
216
217 Float_t clusteranodePath = (clusterAnode - fNofAnodes/2)*
b48af428 218 anodePitch;
42da2935 219 Float_t clusterDriftPath = clusterTime*fDriftSpeed;
220 clusterDriftPath = fSddLength-clusterDriftPath;
221 if(clusterCharge <= 0.) break;
b48af428 222 AliITSRawClusterSDD clust(j+1,//i
223 clusterAnode,clusterTime,//ff
224 clusterCharge, //f
225 clusterPeakAmplitude, //f
226 peakpos, //i
227 0.,0.,clusterDriftPath,//fff
228 clusteranodePath, //f
229 clusterMult, //i
230 0,0,0,0,0,0,0);//7*i
42da2935 231 iTS->AddCluster(1,&clust);
232 it = tstop;
233 } // ilcl
234 it++;
235 } // while (samples)
236 } // anodes
237 } // detectors (2)
238 //fMap->ClearMap();
239
240 for(i=0;i<fNofAnodes;i++) delete[] dfadc[i];
241 delete [] dfadc;
a1f090e0 242
42da2935 243 return;
a1f090e0 244}
42da2935 245//______________________________________________________________________
246void AliITSClusterFinderSDD::Find1DClustersE(){
24a1c341 247 // find 1D clusters
42da2935 248 static AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
249 // retrieve the parameters
250 Int_t fNofMaps = fSegmentation->Npz();
251 Int_t fMaxNofSamples = fSegmentation->Npx();
252 Int_t fNofAnodes = fNofMaps/2;
253 Int_t dummy=0;
254 Float_t fTimeStep = fSegmentation->Dpx( dummy );
255 Float_t fSddLength = fSegmentation->Dx();
256 Float_t fDriftSpeed = fResponse->DriftSpeed();
257 Float_t anodePitch = fSegmentation->Dpz( dummy );
258 Float_t n, baseline;
259 fResponse->GetNoiseParam( n, baseline );
260 // map the signal
261 fMap->SetThreshold( fCutAmplitude );
262 fMap->FillMap();
263 Int_t nClu = 0;
264 // cout << "Search cluster... "<< endl;
265 for( Int_t j=0; j<2; j++ ){
266 for( Int_t k=0; k<fNofAnodes; k++ ){
267 Int_t idx = j*fNofAnodes+k;
268 Bool_t on = kFALSE;
269 Int_t start = 0;
270 Int_t nTsteps = 0;
271 Float_t fmax = 0.;
272 Int_t lmax = 0;
273 Float_t charge = 0.;
274 Float_t time = 0.;
275 Float_t anode = k+0.5;
276 Int_t peakpos = -1;
277 for( Int_t l=0; l<fMaxNofSamples; l++ ){
278 Float_t fadc = (Float_t)fMap->GetSignal( idx, l );
279 if( fadc > 0.0 ){
280 if( on == kFALSE && l<fMaxNofSamples-4){
281 // star RawCluster (reset var.)
282 Float_t fadc1 = (Float_t)fMap->GetSignal( idx, l+1 );
283 if( fadc1 < fadc ) continue;
284 start = l;
285 fmax = 0.;
286 lmax = 0;
287 time = 0.;
288 charge = 0.;
289 on = kTRUE;
290 nTsteps = 0;
291 } // end if on...
292 nTsteps++ ;
293 if( fadc > baseline ) fadc -= baseline;
294 else fadc=0.;
295 charge += fadc;
296 time += fadc*l;
297 if( fadc > fmax ){
298 fmax = fadc;
299 lmax = l;
300 Int_t shift = (Int_t)(fTimeCorr/fTimeStep + 0.5);
301 if( l > shift && l < (fMaxNofSamples-shift) )
302 peakpos = fMap->GetHitIndex( idx, l+shift );
303 else
304 peakpos = fMap->GetHitIndex( idx, l );
305 if( peakpos < 0) peakpos = fMap->GetHitIndex( idx, l );
306 } // end if fadc
307 }else{ // end fadc>0
308 if( on == kTRUE ){
309 if( nTsteps > 2 ){
310 // min # of timesteps for a RawCluster
311 // Found a RawCluster...
312 Int_t stop = l-1;
313 time /= (charge/fTimeStep); // ns
314 // time = lmax*fTimeStep; // ns
315 if( time > fTimeCorr ) time -= fTimeCorr; // ns
316 Float_t anodePath = (anode - fNofAnodes/2)*anodePitch;
317 Float_t driftPath = time*fDriftSpeed;
318 driftPath = fSddLength-driftPath;
319 AliITSRawClusterSDD clust(j+1,anode,time,charge,
320 fmax, peakpos,0.,0.,
321 driftPath,anodePath,
322 nTsteps,start,stop,
323 start, stop, 1, k, k );
324 iTS->AddCluster( 1, &clust );
325 // clust.PrintInfo();
326 nClu++;
327 } // end if nTsteps
328 on = kFALSE;
329 } // end if on==kTRUE
330 } // end if fadc>0
331 } // samples
a1f090e0 332 } // anodes
42da2935 333 } // wings
334 // cout << "# Rawclusters " << nClu << endl;
335 return;
a1f090e0 336}
42da2935 337//_______________________________________________________________________
338Int_t AliITSClusterFinderSDD::SearchPeak(Float_t *spect,Int_t xdim,Int_t zdim,
339 Int_t *peakX, Int_t *peakZ,
340 Float_t *peakAmp, Float_t minpeak ){
341 // search peaks on a 2D cluster
342 Int_t npeak = 0; // # peaks
56fff130 343 Int_t i,j;
42da2935 344 // search peaks
345 for( Int_t z=1; z<zdim-1; z++ ){
346 for( Int_t x=2; x<xdim-3; x++ ){
347 Float_t sxz = spect[x*zdim+z];
348 Float_t sxz1 = spect[(x+1)*zdim+z];
349 Float_t sxz2 = spect[(x-1)*zdim+z];
350 // search a local max. in s[x,z]
351 if( sxz < minpeak || sxz1 <= 0 || sxz2 <= 0 ) continue;
352 if( sxz >= spect[(x+1)*zdim+z ] && sxz >= spect[(x-1)*zdim+z ] &&
353 sxz >= spect[x*zdim +z+1] && sxz >= spect[x*zdim +z-1] &&
354 sxz >= spect[(x+1)*zdim+z+1] && sxz >= spect[(x+1)*zdim+z-1] &&
355 sxz >= spect[(x-1)*zdim+z+1] && sxz >= spect[(x-1)*zdim+z-1] ){
356 // peak found
357 peakX[npeak] = x;
358 peakZ[npeak] = z;
359 peakAmp[npeak] = sxz;
360 npeak++;
361 } // end if ....
362 } // end for x
363 } // end for z
364 // search groups of peaks with same amplitude.
365 Int_t *flag = new Int_t[npeak];
366 for( i=0; i<npeak; i++ ) flag[i] = 0;
367 for( i=0; i<npeak; i++ ){
368 for( j=0; j<npeak; j++ ){
369 if( i==j) continue;
370 if( flag[j] > 0 ) continue;
371 if( peakAmp[i] == peakAmp[j] &&
372 TMath::Abs(peakX[i]-peakX[j])<=1 &&
373 TMath::Abs(peakZ[i]-peakZ[j])<=1 ){
374 if( flag[i] == 0) flag[i] = i+1;
375 flag[j] = flag[i];
376 } // end if ...
377 } // end for j
378 } // end for i
379 // make average of peak groups
380 for( i=0; i<npeak; i++ ){
381 Int_t nFlag = 1;
382 if( flag[i] <= 0 ) continue;
383 for( j=0; j<npeak; j++ ){
384 if( i==j ) continue;
385 if( flag[j] != flag[i] ) continue;
386 peakX[i] += peakX[j];
387 peakZ[i] += peakZ[j];
388 nFlag++;
389 npeak--;
390 for( Int_t k=j; k<npeak; k++ ){
391 peakX[k] = peakX[k+1];
392 peakZ[k] = peakZ[k+1];
393 peakAmp[k] = peakAmp[k+1];
394 flag[k] = flag[k+1];
395 } // end for k
396 j--;
397 } // end for j
398 if( nFlag > 1 ){
399 peakX[i] /= nFlag;
400 peakZ[i] /= nFlag;
401 } // end fi nFlag
402 } // end for i
403 delete [] flag;
404 return( npeak );
a1f090e0 405}
42da2935 406//______________________________________________________________________
407void AliITSClusterFinderSDD::PeakFunc( Int_t xdim, Int_t zdim, Float_t *par,
408 Float_t *spe, Float_t *integral){
24a1c341 409 // function used to fit the clusters
410 // par -> paramiters..
411 // par[0] number of peaks.
412 // for each peak i=1, ..., par[0]
413 // par[i] = Ampl.
414 // par[i+1] = xpos
415 // par[i+2] = zpos
416 // par[i+3] = tau
417 // par[i+4] = sigma.
24a1c341 418 Int_t electronics = fResponse->Electronics(); // 1 = PASCAL, 2 = OLA
419 const Int_t knParam = 5;
420 Int_t npeak = (Int_t)par[0];
42da2935 421
24a1c341 422 memset( spe, 0, sizeof( Float_t )*zdim*xdim );
42da2935 423
24a1c341 424 Int_t k = 1;
42da2935 425 for( Int_t i=0; i<npeak; i++ ){
24a1c341 426 if( integral != 0 ) integral[i] = 0.;
427 Float_t sigmaA2 = par[k+4]*par[k+4]*2.;
428 Float_t T2 = par[k+3]; // PASCAL
429 if( electronics == 2 ) { T2 *= T2; T2 *= 2; } // OLA
42da2935 430 for( Int_t z=0; z<zdim; z++ ){
431 for( Int_t x=0; x<xdim; x++ ){
24a1c341 432 Float_t z2 = (z-par[k+2])*(z-par[k+2])/sigmaA2;
433 Float_t x2 = 0.;
434 Float_t signal = 0.;
42da2935 435 if( electronics == 1 ){ // PASCAL
24a1c341 436 x2 = (x-par[k+1]+T2)/T2;
42da2935 437 signal = (x2>0.) ? par[k]*x2*exp(-x2+1.-z2) :0.0; // RCCR2
438 // signal =(x2>0.) ? par[k]*x2*x2*exp(-2*x2+2.-z2 ):0.0;//RCCR
439 }else if( electronics == 2 ) { // OLA
440 x2 = (x-par[k+1])*(x-par[k+1])/T2;
441 signal = par[k] * exp( -x2 - z2 );
442 } else {
443 cout << "Wrong SDD Electronics =" << electronics << endl;
444 // exit( 1 );
445 } // end if electronicx
24a1c341 446 spe[x*zdim+z] += signal;
447 if( integral != 0 ) integral[i] += signal;
42da2935 448 } // end for x
449 } // end for z
24a1c341 450 k += knParam;
42da2935 451 } // end for i
24a1c341 452 return;
a1f090e0 453}
42da2935 454//__________________________________________________________________________
455Float_t AliITSClusterFinderSDD::ChiSqr( Int_t xdim, Int_t zdim, Float_t *spe,
456 Float_t *speFit ){
457 // EVALUATES UNNORMALIZED CHI-SQUARED
458 Float_t chi2 = 0.;
459 for( Int_t z=0; z<zdim; z++ ){
460 for( Int_t x=1; x<xdim-1; x++ ){
461 Int_t index = x*zdim+z;
462 Float_t tmp = spe[index] - speFit[index];
463 chi2 += tmp*tmp;
464 } // end for x
465 } // end for z
466 return( chi2 );
a1f090e0 467}
42da2935 468//_______________________________________________________________________
469void AliITSClusterFinderSDD::Minim( Int_t xdim, Int_t zdim, Float_t *param,
470 Float_t *prm0,Float_t *steprm,
471 Float_t *chisqr,Float_t *spe,
472 Float_t *speFit ){
473 //
474 Int_t k, nnn, mmm, i;
475 Float_t p1, delta, d1, chisq1, p2, chisq2, t, p3, chisq3, a, b, p0, chisqt;
476 const Int_t knParam = 5;
477 Int_t npeak = (Int_t)param[0];
478 for( k=1; k<(npeak*knParam+1); k++ ) prm0[k] = param[k];
479 for( k=1; k<(npeak*knParam+1); k++ ){
480 p1 = param[k];
481 delta = steprm[k];
482 d1 = delta;
483 // ENSURE THAT STEP SIZE IS SENSIBLY LARGER THAN MACHINE ROUND OFF
484 if( fabs( p1 ) > 1.0E-6 )
485 if ( fabs( delta/p1 ) < 1.0E-4 ) delta = p1/1000;
486 else delta = (Float_t)1.0E-4;
487 // EVALUATE CHI-SQUARED AT FIRST TWO SEARCH POINTS
488 PeakFunc( xdim, zdim, param, speFit );
489 chisq1 = ChiSqr( xdim, zdim, spe, speFit );
490 p2 = p1+delta;
491 param[k] = p2;
492 PeakFunc( xdim, zdim, param, speFit );
493 chisq2 = ChiSqr( xdim, zdim, spe, speFit );
494 if( chisq1 < chisq2 ){
495 // REVERSE DIRECTION OF SEARCH IF CHI-SQUARED IS INCREASING
496 delta = -delta;
497 t = p1;
498 p1 = p2;
499 p2 = t;
500 t = chisq1;
501 chisq1 = chisq2;
502 chisq2 = t;
503 } // end if
504 i = 1; nnn = 0;
505 do { // INCREMENT param(K) UNTIL CHI-SQUARED STARTS TO INCREASE
506 nnn++;
507 p3 = p2 + delta;
508 mmm = nnn - (nnn/5)*5; // multiplo de 5
509 if( mmm == 0 ){
a1f090e0 510 d1 = delta;
42da2935 511 // INCREASE STEP SIZE IF STEPPING TOWARDS MINIMUM IS TOO SLOW
512 delta *= 5;
513 } // end if
514 param[k] = p3;
515 // Constrain paramiters
516 Int_t kpos = (k-1) % knParam;
517 switch( kpos ){
518 case 0 :
519 if( param[k] <= 20 ) param[k] = fMinPeak;
520 case 1 :
521 if( fabs( param[k] - prm0[k] ) > 1.5 ) param[k] = prm0[k];
522 case 2 :
523 if( fabs( param[k] - prm0[k] ) > 1. ) param[k] = prm0[k];
524 case 3 :
525 if( param[k] < .5 ) param[k] = .5;
526 case 4 :
527 if( param[k] < .288 ) param[k] = .288; // 1/sqrt(12) = 0.288
528 }; // end switch
529 PeakFunc( xdim, zdim, param, speFit );
530 chisq3 = ChiSqr( xdim, zdim, spe, speFit );
531 if( chisq3 < chisq2 && nnn < 50 ){
532 p1 = p2;
533 p2 = p3;
534 chisq1 = chisq2;
535 chisq2 = chisq3;
536 }else i=0;
a1f090e0 537 } while( i );
42da2935 538 // FIND MINIMUM OF PARABOLA DEFINED BY LAST THREE POINTS
539 a = chisq1*(p2-p3)+chisq2*(p3-p1)+chisq3*(p1-p2);
540 b = chisq1*(p2*p2-p3*p3)+chisq2*(p3*p3-p1*p1)+chisq3*(p1*p1-p2*p2);
541 if( a!=0 ) p0 = (Float_t)(0.5*b/a);
542 else p0 = 10000;
543 //--IN CASE OF NEARLY EQUAL CHI-SQUARED AND TOO SMALL STEP SIZE PREVENT
544 // ERRONEOUS EVALUATION OF PARABOLA MINIMUM
545 //---NEXT TWO LINES CAN BE OMITTED FOR HIGHER PRECISION MACHINES
546 //dp = (Float_t) max (fabs(p3-p2), fabs(p2-p1));
547 //if( fabs( p2-p0 ) > dp ) p0 = p2;
548 param[k] = p0;
549 // Constrain paramiters
550 Int_t kpos = (k-1) % knParam;
551 switch( kpos ){
552 case 0 :
553 if( param[k] <= 20 ) param[k] = fMinPeak;
554 case 1 :
555 if( fabs( param[k] - prm0[k] ) > 1.5 ) param[k] = prm0[k];
556 case 2 :
557 if( fabs( param[k] - prm0[k] ) > 1. ) param[k] = prm0[k];
558 case 3 :
559 if( param[k] < .5 ) param[k] = .5;
560 case 4 :
561 if( param[k] < .288 ) param[k] = .288; // 1/sqrt(12) = 0.288
562 }; // end switch
a1f090e0 563 PeakFunc( xdim, zdim, param, speFit );
42da2935 564 chisqt = ChiSqr( xdim, zdim, spe, speFit );
565 // DO NOT ALLOW ERRONEOUS INTERPOLATION
566 if( chisqt <= *chisqr ) *chisqr = chisqt;
567 else param[k] = prm0[k];
568 // OPTIMIZE SEARCH STEP FOR EVENTUAL NEXT CALL OF MINIM
569 steprm[k] = (param[k]-prm0[k])/5;
570 if( steprm[k] >= d1 ) steprm[k] = d1/5;
571 } // end for k
572 // EVALUATE FIT AND CHI-SQUARED FOR OPTIMIZED PARAMETERS
573 PeakFunc( xdim, zdim, param, speFit );
574 *chisqr = ChiSqr( xdim, zdim, spe, speFit );
575 return;
a1f090e0 576}
42da2935 577//_________________________________________________________________________
578Int_t AliITSClusterFinderSDD::NoLinearFit( Int_t xdim, Int_t zdim,
579 Float_t *param, Float_t *spe,
580 Int_t *niter, Float_t *chir ){
581 // fit method from Comput. Phys. Commun 46(1987) 149
582 const Float_t kchilmt = 0.01; // relative accuracy
583 const Int_t knel = 3; // for parabolic minimization
584 const Int_t knstop = 50; // Max. iteration number
585 const Int_t knParam = 5;
586 Int_t npeak = (Int_t)param[0];
587 // RETURN IF NUMBER OF DEGREES OF FREEDOM IS NOT POSITIVE
588 if( (xdim*zdim - npeak*knParam) <= 0 ) return( -1 );
589 Float_t degFree = (xdim*zdim - npeak*knParam)-1;
590 Int_t n, k, iterNum = 0;
591 Float_t *prm0 = new Float_t[npeak*knParam+1];
592 Float_t *step = new Float_t[npeak*knParam+1];
593 Float_t *schi = new Float_t[npeak*knParam+1];
594 Float_t *sprm[3];
595 sprm[0] = new Float_t[npeak*knParam+1];
596 sprm[1] = new Float_t[npeak*knParam+1];
597 sprm[2] = new Float_t[npeak*knParam+1];
598 Float_t chi0, chi1, reldif, a, b, prmin, dp;
599 Float_t *speFit = new Float_t[ xdim*zdim ];
600 PeakFunc( xdim, zdim, param, speFit );
601 chi0 = ChiSqr( xdim, zdim, spe, speFit );
602 chi1 = chi0;
603 for( k=1; k<(npeak*knParam+1); k++) prm0[k] = param[k];
604 for( k=1 ; k<(npeak*knParam+1); k+=knParam ){
605 step[k] = param[k] / 20.0 ;
a1f090e0 606 step[k+1] = param[k+1] / 50.0;
42da2935 607 step[k+2] = param[k+2] / 50.0;
a1f090e0 608 step[k+3] = param[k+3] / 20.0;
609 step[k+4] = param[k+4] / 20.0;
42da2935 610 } // end for k
611 Int_t out = 0;
612 do{
613 iterNum++;
a1f090e0 614 chi0 = chi1;
24a1c341 615 Minim( xdim, zdim, param, prm0, step, &chi1, spe, speFit );
a1f090e0 616 reldif = ( chi1 > 0 ) ? ((Float_t) fabs( chi1-chi0)/chi1 ) : 0;
42da2935 617 // EXIT conditions
618 if( reldif < (float) kchilmt ){
619 *chir = (chi1>0) ? (float) TMath::Sqrt (chi1/degFree) :0;
620 *niter = iterNum;
621 out = 0;
622 break;
623 } // end if
624 if( (reldif < (float)(5*kchilmt)) && (iterNum > knstop) ){
625 *chir = (chi1>0) ?(float) TMath::Sqrt (chi1/degFree):0;
626 *niter = iterNum;
627 out = 0;
628 break;
629 } // end if
630 if( iterNum > 5*knstop ){
631 *chir = (chi1>0) ?(float) TMath::Sqrt (chi1/degFree):0;
632 *niter = iterNum;
633 out = 1;
634 break;
635 } // end if
24a1c341 636 if( iterNum <= knel ) continue;
24a1c341 637 n = iterNum - (iterNum/knel)*knel; // EXTRAPOLATION LIMIT COUNTER N
a1f090e0 638 if( n > 3 || n == 0 ) continue;
639 schi[n-1] = chi1;
24a1c341 640 for( k=1; k<(npeak*knParam+1); k++ ) sprm[n-1][k] = param[k];
a1f090e0 641 if( n != 3 ) continue;
42da2935 642 // -EVALUATE EXTRAPOLATED VALUE OF EACH PARAMETER BY FINDING MINIMUM OF
643 // PARABOLA DEFINED BY LAST THREE CALLS OF MINIM
644 for( k=1; k<(npeak*knParam+1); k++ ){
645 Float_t tmp0 = sprm[0][k];
646 Float_t tmp1 = sprm[1][k];
647 Float_t tmp2 = sprm[2][k];
648 a = schi[0]*(tmp1-tmp2) + schi[1]*(tmp2-tmp0);
649 a += (schi[2]*(tmp0-tmp1));
650 b = schi[0]*(tmp1*tmp1-tmp2*tmp2);
651 b += (schi[1]*(tmp2*tmp2-tmp0*tmp0)+(schi[2]*
652 (tmp0*tmp0-tmp1*tmp1)));
653 if ((double)a < 1.0E-6) prmin = 0;
654 else prmin = (float) (0.5*b/a);
655 dp = 5*(tmp2-tmp0);
656 if (fabs(prmin-tmp2) > fabs(dp)) prmin = tmp2+dp;
657 param[k] = prmin;
658 step[k] = dp/10; // OPTIMIZE SEARCH STEP
659 } // end for k
660 } while( kTRUE );
661 delete [] prm0;
662 delete [] step;
663 delete [] schi;
664 delete [] sprm[0];
665 delete [] sprm[1];
666 delete [] sprm[2];
667 delete [] speFit;
668 return( out );
a1f090e0 669}
42da2935 670//______________________________________________________________________
671void AliITSClusterFinderSDD::ResolveClustersE(){
672 // The function to resolve clusters if the clusters overlapping exists
24a1c341 673 Int_t i;
42da2935 674 static AliITS *iTS = (AliITS*)gAlice->GetModule( "ITS" );
675 // get number of clusters for this module
676 Int_t nofClusters = fClusters->GetEntriesFast();
677 nofClusters -= fNclusters;
678 Int_t fNofMaps = fSegmentation->Npz();
679 Int_t fNofAnodes = fNofMaps/2;
680 Int_t fMaxNofSamples = fSegmentation->Npx();
681 Int_t dummy=0;
682 Double_t fTimeStep = fSegmentation->Dpx( dummy );
683 Double_t fSddLength = fSegmentation->Dx();
684 Double_t fDriftSpeed = fResponse->DriftSpeed();
685 Double_t anodePitch = fSegmentation->Dpz( dummy );
686 Float_t n, baseline;
687 fResponse->GetNoiseParam( n, baseline );
688 Int_t electronics = fResponse->Electronics(); // 1 = PASCAL, 2 = OLA
689 // fill Map of signals
690 fMap->FillMap();
691 for( Int_t j=0; j<nofClusters; j++ ){
692 // get cluster information
693 AliITSRawClusterSDD *clusterJ=(AliITSRawClusterSDD*) fClusters->At(j);
694 Int_t astart = clusterJ->Astart();
695 Int_t astop = clusterJ->Astop();
696 Int_t tstart = clusterJ->Tstartf();
697 Int_t tstop = clusterJ->Tstopf();
698 Int_t wing = (Int_t)clusterJ->W();
699 if( wing == 2 ){
700 astart += fNofAnodes;
701 astop += fNofAnodes;
702 } // end if
703 Int_t xdim = tstop-tstart+3;
704 Int_t zdim = astop-astart+3;
705 Float_t *sp = new Float_t[ xdim*zdim+1 ];
706 memset( sp, 0, sizeof(Float_t)*(xdim*zdim+1) );
707 // make a local map from cluster region
708 for( Int_t ianode=astart; ianode<=astop; ianode++ ){
709 for( Int_t itime=tstart; itime<=tstop; itime++ ){
710 Float_t fadc = fMap->GetSignal( ianode, itime );
711 if( fadc > baseline ) fadc -= (Double_t)baseline;
712 else fadc = 0.;
713 Int_t index = (itime-tstart+1)*zdim+(ianode-astart+1);
714 sp[index] = fadc;
715 } // time loop
716 } // anode loop
717 // search peaks on cluster
718 const Int_t kNp = 150;
719 Int_t peakX1[kNp];
720 Int_t peakZ1[kNp];
721 Float_t peakAmp1[kNp];
722 Int_t npeak = SearchPeak(sp,xdim,zdim,peakX1,peakZ1,peakAmp1,fMinPeak);
723 // if multiple peaks, split cluster
724 if( npeak >= 1 ){
725 // cout << "npeak " << npeak << endl;
726 // clusterJ->PrintInfo();
727 Float_t *par = new Float_t[npeak*5+1];
728 par[0] = (Float_t)npeak;
729 // Initial paramiters in cell dimentions
730 Int_t k1 = 1;
731 for( i=0; i<npeak; i++ ){
732 par[k1] = peakAmp1[i];
733 par[k1+1] = peakX1[i]; // local time pos. [timebin]
734 par[k1+2] = peakZ1[i]; // local anode pos. [anodepitch]
735 if( electronics == 1 )
736 par[k1+3] = 2.; // PASCAL
737 else if( electronics == 2 )
738 par[k1+3] = 0.7; // tau [timebin] OLA
739 par[k1+4] = .4; // sigma [anodepich]
740 k1+=5;
741 } // end for i
742 Int_t niter;
743 Float_t chir;
744 NoLinearFit( xdim, zdim, par, sp, &niter, &chir );
745 Float_t peakX[kNp];
746 Float_t peakZ[kNp];
747 Float_t sigma[kNp];
748 Float_t tau[kNp];
749 Float_t peakAmp[kNp];
750 Float_t integral[kNp];
751 //get integrals => charge for each peak
752 PeakFunc( xdim, zdim, par, sp, integral );
753 k1 = 1;
754 for( i=0; i<npeak; i++ ){
755 peakAmp[i] = par[k1];
756 peakX[i] = par[k1+1];
757 peakZ[i] = par[k1+2];
758 tau[i] = par[k1+3];
759 sigma[i] = par[k1+4];
760 k1+=5;
761 } // end for i
762 // calculate paramiter for new clusters
763 for( i=0; i<npeak; i++ ){
764 AliITSRawClusterSDD clusterI( *clusterJ );
765 Int_t newAnode = peakZ1[i]-1 + astart;
766 Int_t newiTime = peakX1[i]-1 + tstart;
767 Int_t shift = (Int_t)(fTimeCorr/fTimeStep + 0.5);
768 if(newiTime>shift&&newiTime<(fMaxNofSamples-shift)) shift = 0;
769 Int_t peakpos = fMap->GetHitIndex( newAnode, newiTime+shift );
770 clusterI.SetPeakPos( peakpos );
771 clusterI.SetPeakAmpl( peakAmp1[i] );
772 Float_t newAnodef = peakZ[i] - 0.5 + astart;
773 Float_t newiTimef = peakX[i] - 1 + tstart;
774 if( wing == 2 ) newAnodef -= fNofAnodes;
775 Float_t anodePath = (newAnodef - fNofAnodes/2)*anodePitch;
776 newiTimef *= fTimeStep;
777 if( newiTimef > fTimeCorr ) newiTimef -= fTimeCorr;
778 if( electronics == 1 ){
779 newiTimef *= 0.999438; // PASCAL
780 newiTimef += (6./fDriftSpeed - newiTimef/3000.);
781 }else if( electronics == 2 )
782 newiTimef *= 0.99714; // OLA
783 Float_t driftPath = fSddLength - newiTimef * fDriftSpeed;
784 Float_t sign = ( wing == 1 ) ? -1. : 1.;
785 clusterI.SetX( driftPath*sign * 0.0001 );
786 clusterI.SetZ( anodePath * 0.0001 );
787 clusterI.SetAnode( newAnodef );
788 clusterI.SetTime( newiTimef );
789 clusterI.SetAsigma( sigma[i]*anodePitch );
790 clusterI.SetTsigma( tau[i]*fTimeStep );
791 clusterI.SetQ( integral[i] );
792 // clusterI.PrintInfo();
793 iTS->AddCluster( 1, &clusterI );
794 } // end for i
795 fClusters->RemoveAt( j );
796 delete [] par;
797 } else cout <<" --- Peak not found!!!! minpeak=" << fMinPeak<<
798 " cluster peak=" << clusterJ->PeakAmpl() << endl << endl;
799 delete [] sp;
800 } // cluster loop
801 fClusters->Compress();
802 fMap->ClearMap();
a1f090e0 803}
42da2935 804//________________________________________________________________________
805void AliITSClusterFinderSDD::GroupClusters(){
806 // group clusters
807 Int_t dummy=0;
808 Float_t fTimeStep = fSegmentation->Dpx(dummy);
809 // get number of clusters for this module
810 Int_t nofClusters = fClusters->GetEntriesFast();
811 nofClusters -= fNclusters;
812 AliITSRawClusterSDD *clusterI;
813 AliITSRawClusterSDD *clusterJ;
814 Int_t *label = new Int_t [nofClusters];
815 Int_t i,j;
816 for(i=0; i<nofClusters; i++) label[i] = 0;
817 for(i=0; i<nofClusters; i++) {
818 if(label[i] != 0) continue;
819 for(j=i+1; j<nofClusters; j++) {
820 if(label[j] != 0) continue;
821 clusterI = (AliITSRawClusterSDD*) fClusters->At(i);
822 clusterJ = (AliITSRawClusterSDD*) fClusters->At(j);
823 // 1.3 good
824 if(clusterI->T() < fTimeStep*60) fDAnode = 4.2; // TB 3.2
825 if(clusterI->T() < fTimeStep*10) fDAnode = 1.5; // TB 1.
826 Bool_t pair = clusterI->Brother(clusterJ,fDAnode,fDTime);
827 if(!pair) continue;
828 // clusterI->PrintInfo();
829 // clusterJ->PrintInfo();
830 clusterI->Add(clusterJ);
831 label[j] = 1;
832 fClusters->RemoveAt(j);
833 j=i; // <- Ernesto
834 } // J clusters
835 label[i] = 1;
836 } // I clusters
837 fClusters->Compress();
838
839 delete [] label;
840 return;
b0f5e3fc 841}
42da2935 842//________________________________________________________________________
843void AliITSClusterFinderSDD::SelectClusters(){
844 // get number of clusters for this module
845 Int_t nofClusters = fClusters->GetEntriesFast();
b0f5e3fc 846
42da2935 847 nofClusters -= fNclusters;
848 Int_t i;
849 for(i=0; i<nofClusters; i++) {
850 AliITSRawClusterSDD *clusterI =(AliITSRawClusterSDD*) fClusters->At(i);
851 Int_t rmflg = 0;
852 Float_t wy = 0.;
853 if(clusterI->Anodes() != 0.) {
854 wy = ((Float_t) clusterI->Samples())/clusterI->Anodes();
855 } // end if
856 Int_t amp = (Int_t) clusterI->PeakAmpl();
857 Int_t cha = (Int_t) clusterI->Q();
858 if(amp < fMinPeak) rmflg = 1;
859 if(cha < fMinCharge) rmflg = 1;
860 if(wy < fMinNCells) rmflg = 1;
861 //if(wy > fMaxNCells) rmflg = 1;
862 if(rmflg) fClusters->RemoveAt(i);
863 } // I clusters
864 fClusters->Compress();
865 return;
b0f5e3fc 866}
42da2935 867//__________________________________________________________________________
868void AliITSClusterFinderSDD::ResolveClusters(){
869 // The function to resolve clusters if the clusters overlapping exists
870/* AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
871 // get number of clusters for this module
872 Int_t nofClusters = fClusters->GetEntriesFast();
873 nofClusters -= fNclusters;
874 //cout<<"Resolve Cl: nofClusters, fNclusters ="<<nofClusters<<","
875 // <<fNclusters<<endl;
876 Int_t fNofMaps = fSegmentation->Npz();
877 Int_t fNofAnodes = fNofMaps/2;
878 Int_t dummy=0;
879 Double_t fTimeStep = fSegmentation->Dpx(dummy);
880 Double_t fSddLength = fSegmentation->Dx();
881 Double_t fDriftSpeed = fResponse->DriftSpeed();
882 Double_t anodePitch = fSegmentation->Dpz(dummy);
883 Float_t n, baseline;
884 fResponse->GetNoiseParam(n,baseline);
885 Float_t dzz_1A = anodePitch * anodePitch / 12;
886 // fill Map of signals
a1f090e0 887 fMap->FillMap();
42da2935 888 Int_t j,i,ii,ianode,anode,itime;
889 Int_t wing,astart,astop,tstart,tstop,nanode;
890 Double_t fadc,ClusterTime;
891 Double_t q[400],x[400],z[400]; // digit charges and coordinates
892 for(j=0; j<nofClusters; j++) {
893 AliITSRawClusterSDD *clusterJ=(AliITSRawClusterSDD*) fClusters->At(j);
894 Int_t ndigits = 0;
895 astart=clusterJ->Astart();
896 astop=clusterJ->Astop();
897 tstart=clusterJ->Tstartf();
898 tstop=clusterJ->Tstopf();
899 nanode=clusterJ->Anodes(); // <- Ernesto
900 wing=(Int_t)clusterJ->W();
901 if(wing == 2) {
902 astart += fNofAnodes;
903 astop += fNofAnodes;
904 } // end if
905 // cout<<"astart,astop,tstart,tstop ="<<astart<<","<<astop<<","
906 // <<tstart<<","<<tstop<<endl;
907 // clear the digit arrays
908 for(ii=0; ii<400; ii++) {
909 q[ii] = 0.;
910 x[ii] = 0.;
911 z[ii] = 0.;
912 } // end for ii
913
914 for(ianode=astart; ianode<=astop; ianode++) {
915 for(itime=tstart; itime<=tstop; itime++) {
916 fadc=fMap->GetSignal(ianode,itime);
917 if(fadc>baseline) {
918 fadc-=(Double_t)baseline;
919 q[ndigits] = fadc*(fTimeStep/160); // KeV
920 anode = ianode;
921 if(wing == 2) anode -= fNofAnodes;
922 z[ndigits] = (anode + 0.5 - fNofAnodes/2)*anodePitch;
923 ClusterTime = itime*fTimeStep;
924 if(ClusterTime > fTimeCorr) ClusterTime -= fTimeCorr;// ns
925 x[ndigits] = fSddLength - ClusterTime*fDriftSpeed;
926 if(wing == 1) x[ndigits] *= (-1);
927 // cout<<"ianode,itime,fadc ="<<ianode<<","<<itime<<","
928 // <<fadc<<endl;
929 // cout<<"wing,anode,ndigits,charge ="<<wing<<","
930 // <<anode<<","<<ndigits<<","<<q[ndigits]<<endl;
931 ndigits++;
932 continue;
933 } // end if
934 fadc=0;
935 // cout<<"fadc=0, ndigits ="<<ndigits<<endl;
936 } // time loop
937 } // anode loop
938 // cout<<"for new cluster ndigits ="<<ndigits<<endl;
939 // Fit cluster to resolve for two separate ones --------------------
940 Double_t qq=0., xm=0., zm=0., xx=0., zz=0., xz=0.;
941 Double_t dxx=0., dzz=0., dxz=0.;
942 Double_t scl = 0., tmp, tga, elps = -1.;
943 Double_t xfit[2], zfit[2], qfit[2];
944 Double_t pitchz = anodePitch*1.e-4; // cm
945 Double_t pitchx = fTimeStep*fDriftSpeed*1.e-4; // cm
946 Double_t sigma2;
947 Int_t nfhits;
948 Int_t nbins = ndigits;
949 Int_t separate = 0;
950 // now, all lengths are in microns
951 for (ii=0; ii<nbins; ii++) {
952 qq += q[ii];
953 xm += x[ii]*q[ii];
954 zm += z[ii]*q[ii];
955 xx += x[ii]*x[ii]*q[ii];
956 zz += z[ii]*z[ii]*q[ii];
957 xz += x[ii]*z[ii]*q[ii];
958 } // end for ii
959 xm /= qq;
960 zm /= qq;
961 xx /= qq;
962 zz /= qq;
963 xz /= qq;
964 dxx = xx - xm*xm;
965 dzz = zz - zm*zm;
966 dxz = xz - xm*zm;
967
968 // shrink the cluster in the time direction proportionaly to the
969 // dxx/dzz, which lineary depends from the drift path
a1f090e0 970 // new Ernesto........
42da2935 971 if( nanode == 1 ){
972 dzz = dzz_1A; // for one anode cluster dzz = anode**2/12
973 scl = TMath::Sqrt( 7.2/(-0.57*xm*1.e-3+71.8) );
974 } // end if
975 if( nanode == 2 ){
976 scl = TMath::Sqrt( (-0.18*xm*1.e-3+21.3)/(-0.57*xm*1.e-3+71.8) );
977 } // end if
978 if( nanode == 3 ){
979 scl = TMath::Sqrt( (-0.5*xm*1.e-3+34.5)/(-0.57*xm*1.e-3+71.8) );
980 } // end if
981 if( nanode > 3 ){
982 scl = TMath::Sqrt( (1.3*xm*1.e-3+49.)/(-0.57*xm*1.e-3+71.8) );
983 } // end if
984 // cout<<"1 microns: zm,dzz,xm,dxx,dxz,qq ="<<zm<<","<<dzz<<","
985 // <<xm<<","<<dxx<<","<<dxz<<","<<qq<<endl;
986 // old Boris.........
987 // tmp=29730. - 585.*fabs(xm/1000.);
988 // scl=TMath::Sqrt(tmp/130000.);
a1f090e0 989
42da2935 990 xm *= scl;
991 xx *= scl*scl;
992 xz *= scl;
993
994 dxx = xx - xm*xm;
995 // dzz = zz - zm*zm;
996 dxz = xz - xm*zm;
997 // cout<<"microns: zm,dzz,xm,dxx,xz,dxz,qq ="<<zm<<","<<dzz<<","
998 // <<xm<<","<<dxx<<","<<xz<<","<<dxz<<","<<qq<<endl;
999 // if(dzz < 7200.) dzz=7200.;//for one anode cluster dzz = anode**2/12
a1f090e0 1000
42da2935 1001 if (dxx < 0.) dxx=0.;
1002 // the data if no cluster overlapping (the coordunates are in cm)
1003 nfhits = 1;
1004 xfit[0] = xm*1.e-4;
1005 zfit[0] = zm*1.e-4;
1006 qfit[0] = qq;
1007 // if(nbins < 7) cout<<"**** nbins ="<<nbins<<endl;
a1f090e0 1008
42da2935 1009 if (nbins >= 7) {
1010 if (dxz==0.) tga=0.;
1011 else {
1012 tmp=0.5*(dzz-dxx)/dxz;
1013 tga = (dxz<0.) ? tmp-TMath::Sqrt(tmp*tmp+1) :
1014 tmp+TMath::Sqrt(tmp*tmp+1);
1015 } // end if dxz
1016 elps=(tga*tga*dxx-2*tga*dxz+dzz)/(dxx+2*tga*dxz+tga*tga*dzz);
1017 // change from microns to cm
1018 xm *= 1.e-4;
1019 zm *= 1.e-4;
1020 zz *= 1.e-8;
1021 xx *= 1.e-8;
1022 xz *= 1.e-8;
1023 dxz *= 1.e-8;
1024 dxx *= 1.e-8;
1025 dzz *= 1.e-8;
1026 // cout<<"cm: zm,dzz,xm,dxx,xz,dxz,qq ="<<zm<<","<<dzz<<","
1027 // <<xm<<","<<dxx<<","<<xz<<","<<dxz<<","<<qq<<endl;
1028 for (i=0; i<nbins; i++) {
1029 x[i] = x[i] *= scl;
1030 x[i] = x[i] *= 1.e-4;
1031 z[i] = z[i] *= 1.e-4;
1032 } // end for i
1033 // cout<<"!!! elps ="<<elps<<endl;
1034 if (elps < 0.3) { // try to separate hits
1035 separate = 1;
1036 tmp=atan(tga);
1037 Double_t cosa=cos(tmp),sina=sin(tmp);
1038 Double_t a1=0., x1=0., xxx=0.;
1039 for (i=0; i<nbins; i++) {
1040 tmp=x[i]*cosa + z[i]*sina;
1041 if (q[i] > a1) {
1042 a1=q[i];
1043 x1=tmp;
1044 } // end if
1045 xxx += tmp*tmp*tmp*q[i];
1046 } // end for i
1047 xxx /= qq;
1048 Double_t z12=-sina*xm + cosa*zm;
1049 sigma2=(sina*sina*xx-2*cosa*sina*xz+cosa*cosa*zz) - z12*z12;
1050 xm=cosa*xm + sina*zm;
1051 xx=cosa*cosa*xx + 2*cosa*sina*xz + sina*sina*zz;
1052 Double_t x2=(xx - xm*x1 - sigma2)/(xm - x1);
1053 Double_t r=a1*2*TMath::ACos(-1.)*sigma2/(qq*pitchx*pitchz);
1054 for (i=0; i<33; i++) { // solve a system of equations
1055 Double_t x1_old=x1, x2_old=x2, r_old=r;
1056 Double_t c11=x1-x2;
1057 Double_t c12=r;
1058 Double_t c13=1-r;
1059 Double_t c21=x1*x1 - x2*x2;
1060 Double_t c22=2*r*x1;
1061 Double_t c23=2*(1-r)*x2;
1062 Double_t c31=3*sigma2*(x1-x2) + x1*x1*x1 - x2*x2*x2;
1063 Double_t c32=3*r*(sigma2 + x1*x1);
1064 Double_t c33=3*(1-r)*(sigma2 + x2*x2);
1065 Double_t f1=-(r*x1 + (1-r)*x2 - xm);
1066 Double_t f2=-(r*(sigma2+x1*x1)+(1-r)*(sigma2+x2*x2)- xx);
1067 Double_t f3=-(r*x1*(3*sigma2+x1*x1)+(1-r)*x2*
1068 (3*sigma2+x2*x2)-xxx);
1069 Double_t d=c11*c22*c33+c21*c32*c13+c12*c23*c31-
1070 c31*c22*c13 - c21*c12*c33 - c32*c23*c11;
1071 if (d==0.) {
1072 cout<<"*********** d=0 ***********\n";
1073 break;
1074 } // end if
1075 Double_t dr=f1*c22*c33 + f2*c32*c13 + c12*c23*f3 -
1076 f3*c22*c13 - f2*c12*c33 - c32*c23*f1;
1077 Double_t d1=c11*f2*c33 + c21*f3*c13 + f1*c23*c31 -
1078 c31*f2*c13 - c21*f1*c33 - f3*c23*c11;
1079 Double_t d2=c11*c22*f3 + c21*c32*f1 + c12*f2*c31 -
1080 c31*c22*f1 - c21*c12*f3 - c32*f2*c11;
1081 r += dr/d;
1082 x1 += d1/d;
1083 x2 += d2/d;
1084 if (fabs(x1-x1_old) > 0.0001) continue;
1085 if (fabs(x2-x2_old) > 0.0001) continue;
1086 if (fabs(r-r_old)/5 > 0.001) continue;
1087 a1=r*qq*pitchx*pitchz/(2*TMath::ACos(-1.)*sigma2);
1088 Double_t a2=a1*(1-r)/r;
1089 qfit[0]=a1; xfit[0]=x1*cosa - z12*sina; zfit[0]=x1*sina +
1090 z12*cosa;
1091 qfit[1]=a2; xfit[1]=x2*cosa - z12*sina; zfit[1]=x2*sina +
1092 z12*cosa;
1093 nfhits=2;
1094 break; // Ok !
1095 } // end for i
1096 if (i==33) cerr<<"No more iterations ! "<<endl;
1097 } // end of attempt to separate overlapped clusters
1098 } // end of nbins cut
1099 if(elps < 0.) cout<<" elps=-1 ="<<elps<<endl;
1100 if(elps >0. && elps< 0.3 && nfhits == 1) cout<<" small elps, nfh=1 ="
1101 <<elps<<","<<nfhits<<endl;
1102 if(nfhits == 2) cout<<" nfhits=2 ="<<nfhits<<endl;
1103 for (i=0; i<nfhits; i++) {
1104 xfit[i] *= (1.e+4/scl);
1105 if(wing == 1) xfit[i] *= (-1);
1106 zfit[i] *= 1.e+4;
1107 // cout<<" --------- i,xfiti,zfiti,qfiti ="<<i<<","
1108 // <<xfit[i]<<","<<zfit[i]<<","<<qfit[i]<<endl;
1109 } // end for i
1110 Int_t ncl = nfhits;
1111 if(nfhits == 1 && separate == 1) {
1112 cout<<"!!!!! no separate"<<endl;
1113 ncl = -2;
1114 } // end if
1115 if(nfhits == 2) {
1116 cout << "Split cluster: " << endl;
1117 clusterJ->PrintInfo();
1118 cout << " in: " << endl;
1119 for (i=0; i<nfhits; i++) {
1120 // AliITSRawClusterSDD *clust = new AliITSRawClusterSDD(wing,
1121 -1,-1,(Float_t)qfit[i],ncl,0,0,
1122 (Float_t)xfit[i],
1123 (Float_t)zfit[i],0,0,0,0,
1124 tstart,tstop,astart,astop);
1125 // AliITSRawClusterSDD *clust = new AliITSRawClusterSDD(wing,-1,
1126 // -1,(Float_t)qfit[i],0,0,0,
1127 // (Float_t)xfit[i],
1128 // (Float_t)zfit[i],0,0,0,0,
1129 // tstart,tstop,astart,astop,ncl);
1130 // ???????????
1131 // if(wing == 1) xfit[i] *= (-1);
1132 Float_t Anode = (zfit[i]/anodePitch+fNofAnodes/2-0.5);
1133 Float_t Time = (fSddLength - xfit[i])/fDriftSpeed;
1134 Float_t clusterPeakAmplitude = clusterJ->PeakAmpl();
1135 Float_t peakpos = clusterJ->PeakPos();
1136 Float_t clusteranodePath = (Anode - fNofAnodes/2)*anodePitch;
1137 Float_t clusterDriftPath = Time*fDriftSpeed;
1138 clusterDriftPath = fSddLength-clusterDriftPath;
1139 AliITSRawClusterSDD *clust = new AliITSRawClusterSDD(wing,Anode,
1140 Time,qfit[i],
1141 clusterPeakAmplitude,peakpos,
1142 0.,0.,clusterDriftPath,
1143 clusteranodePath,clusterJ->Samples()/2
a1f090e0 1144 ,tstart,tstop,0,0,0,astart,astop);
42da2935 1145 clust->PrintInfo();
1146 iTS->AddCluster(1,clust);
1147 // cout<<"new cluster added: tstart,tstop,astart,astop,x,ncl ="
1148 // <<tstart<<","<<tstop<<","<<astart<<","<<astop<<","<<xfit[i]
1149 // <<","<<ncl<<endl;
1150 delete clust;
1151 }// nfhits loop
1152 fClusters->RemoveAt(j);
1153 } // if nfhits = 2
1154} // cluster loop
1155fClusters->Compress();
1156fMap->ClearMap();
1157*/
1158 return;
a1f090e0 1159}
42da2935 1160//______________________________________________________________________
1161void AliITSClusterFinderSDD::GetRecPoints(){
1162 // get rec points
1163 static AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
1164 // get number of clusters for this module
1165 Int_t nofClusters = fClusters->GetEntriesFast();
1166 nofClusters -= fNclusters;
1167 const Float_t kconvGeV = 1.e-6; // GeV -> KeV
1168 const Float_t kconv = 1.0e-4;
1169 const Float_t kRMSx = 38.0*kconv; // microns->cm ITS TDR Table 1.3
1170 const Float_t kRMSz = 28.0*kconv; // microns->cm ITS TDR Table 1.3
1171 Int_t i;
1172 Int_t ix, iz, idx=-1;
1173 AliITSdigitSDD *dig=0;
1174 Int_t ndigits=fDigits->GetEntriesFast();
1175 for(i=0; i<nofClusters; i++) {
1176 AliITSRawClusterSDD *clusterI = (AliITSRawClusterSDD*)fClusters->At(i);
1177 if(!clusterI) Error("SDD: GetRecPoints","i clusterI ",i,clusterI);
1178 if(clusterI) idx=clusterI->PeakPos();
1179 if(idx>ndigits) Error("SDD: GetRecPoints","idx ndigits",idx,ndigits);
1180 // try peak neighbours - to be done
1181 if(idx&&idx<= ndigits) dig =(AliITSdigitSDD*)fDigits->UncheckedAt(idx);
1182 if(!dig) {
1183 // try cog
1184 fSegmentation->GetPadIxz(clusterI->X(),clusterI->Z(),ix,iz);
1185 dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix-1);
1186 // if null try neighbours
1187 if (!dig) dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix);
1188 if (!dig) dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix+1);
1189 if (!dig) printf("SDD: cannot assign the track number!\n");
1190 } // end if !dig
1191 AliITSRecPoint rnew;
1192 rnew.SetX(clusterI->X());
1193 rnew.SetZ(clusterI->Z());
1194 rnew.SetQ(clusterI->Q()); // in KeV - should be ADC
1195 rnew.SetdEdX(kconvGeV*clusterI->Q());
1196 rnew.SetSigmaX2(kRMSx*kRMSx);
1197 rnew.SetSigmaZ2(kRMSz*kRMSz);
1198 if(dig) rnew.fTracks[0]=dig->fTracks[0];
1199 if(dig) rnew.fTracks[1]=dig->fTracks[1];
1200 if(dig) rnew.fTracks[2]=dig->fTracks[2];
1201 //printf("SDD: i %d track1 track2 track3 %d %d %d x y %f %f\n",
1202 // i,rnew.fTracks[0],rnew.fTracks[1],rnew.fTracks[2],c
1203 // lusterI->X(),clusterI->Z());
1204 iTS->AddRecPoint(rnew);
1205 } // I clusters
1206 fMap->ClearMap();
b0f5e3fc 1207}
42da2935 1208//______________________________________________________________________
1209void AliITSClusterFinderSDD::FindRawClusters(Int_t mod){
1210 // find raw clusters
b0f5e3fc 1211
a1f090e0 1212 Find1DClustersE();
b0f5e3fc 1213 GroupClusters();
1214 SelectClusters();
a1f090e0 1215 ResolveClustersE();
b0f5e3fc 1216 GetRecPoints();
1217}
42da2935 1218//_______________________________________________________________________
1219void AliITSClusterFinderSDD::Print(){
1220 // Print SDD cluster finder Parameters
1221
1222 cout << "**************************************************" << endl;
1223 cout << " Silicon Drift Detector Cluster Finder Parameters " << endl;
1224 cout << "**************************************************" << endl;
1225 cout << "Number of Clusters: " << fNclusters << endl;
1226 cout << "Anode Tolerance: " << fDAnode << endl;
1227 cout << "Time Tolerance: " << fDTime << endl;
1228 cout << "Time correction (electronics): " << fTimeCorr << endl;
1229 cout << "Cut Amplitude (threshold): " << fCutAmplitude << endl;
1230 cout << "Minimum Amplitude: " << fMinPeak << endl;
1231 cout << "Minimum Charge: " << fMinCharge << endl;
1232 cout << "Minimum number of cells/clusters: " << fMinNCells << endl;
1233 cout << "Maximum number of cells/clusters: " << fMaxNCells << endl;
1234 cout << "**************************************************" << endl;
a1f090e0 1235}