Reintroduced SDigitization, and Digitization from SDigits, along with
[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;
2bd89e94 705 if(xdim > 50 || zdim > 30) { cout << "Warning: xdim: " << xdim << ", zdim: " << zdim << endl; continue; }
42da2935 706 Float_t *sp = new Float_t[ xdim*zdim+1 ];
707 memset( sp, 0, sizeof(Float_t)*(xdim*zdim+1) );
708 // make a local map from cluster region
709 for( Int_t ianode=astart; ianode<=astop; ianode++ ){
710 for( Int_t itime=tstart; itime<=tstop; itime++ ){
711 Float_t fadc = fMap->GetSignal( ianode, itime );
712 if( fadc > baseline ) fadc -= (Double_t)baseline;
713 else fadc = 0.;
714 Int_t index = (itime-tstart+1)*zdim+(ianode-astart+1);
715 sp[index] = fadc;
716 } // time loop
717 } // anode loop
718 // search peaks on cluster
719 const Int_t kNp = 150;
720 Int_t peakX1[kNp];
721 Int_t peakZ1[kNp];
722 Float_t peakAmp1[kNp];
723 Int_t npeak = SearchPeak(sp,xdim,zdim,peakX1,peakZ1,peakAmp1,fMinPeak);
724 // if multiple peaks, split cluster
725 if( npeak >= 1 ){
726 // cout << "npeak " << npeak << endl;
727 // clusterJ->PrintInfo();
728 Float_t *par = new Float_t[npeak*5+1];
729 par[0] = (Float_t)npeak;
730 // Initial paramiters in cell dimentions
731 Int_t k1 = 1;
732 for( i=0; i<npeak; i++ ){
733 par[k1] = peakAmp1[i];
734 par[k1+1] = peakX1[i]; // local time pos. [timebin]
735 par[k1+2] = peakZ1[i]; // local anode pos. [anodepitch]
736 if( electronics == 1 )
737 par[k1+3] = 2.; // PASCAL
738 else if( electronics == 2 )
739 par[k1+3] = 0.7; // tau [timebin] OLA
740 par[k1+4] = .4; // sigma [anodepich]
741 k1+=5;
742 } // end for i
743 Int_t niter;
744 Float_t chir;
745 NoLinearFit( xdim, zdim, par, sp, &niter, &chir );
746 Float_t peakX[kNp];
747 Float_t peakZ[kNp];
748 Float_t sigma[kNp];
749 Float_t tau[kNp];
750 Float_t peakAmp[kNp];
751 Float_t integral[kNp];
752 //get integrals => charge for each peak
753 PeakFunc( xdim, zdim, par, sp, integral );
754 k1 = 1;
755 for( i=0; i<npeak; i++ ){
756 peakAmp[i] = par[k1];
757 peakX[i] = par[k1+1];
758 peakZ[i] = par[k1+2];
759 tau[i] = par[k1+3];
760 sigma[i] = par[k1+4];
761 k1+=5;
762 } // end for i
763 // calculate paramiter for new clusters
764 for( i=0; i<npeak; i++ ){
765 AliITSRawClusterSDD clusterI( *clusterJ );
766 Int_t newAnode = peakZ1[i]-1 + astart;
767 Int_t newiTime = peakX1[i]-1 + tstart;
768 Int_t shift = (Int_t)(fTimeCorr/fTimeStep + 0.5);
769 if(newiTime>shift&&newiTime<(fMaxNofSamples-shift)) shift = 0;
770 Int_t peakpos = fMap->GetHitIndex( newAnode, newiTime+shift );
771 clusterI.SetPeakPos( peakpos );
772 clusterI.SetPeakAmpl( peakAmp1[i] );
773 Float_t newAnodef = peakZ[i] - 0.5 + astart;
774 Float_t newiTimef = peakX[i] - 1 + tstart;
775 if( wing == 2 ) newAnodef -= fNofAnodes;
776 Float_t anodePath = (newAnodef - fNofAnodes/2)*anodePitch;
777 newiTimef *= fTimeStep;
778 if( newiTimef > fTimeCorr ) newiTimef -= fTimeCorr;
779 if( electronics == 1 ){
780 newiTimef *= 0.999438; // PASCAL
781 newiTimef += (6./fDriftSpeed - newiTimef/3000.);
782 }else if( electronics == 2 )
783 newiTimef *= 0.99714; // OLA
784 Float_t driftPath = fSddLength - newiTimef * fDriftSpeed;
785 Float_t sign = ( wing == 1 ) ? -1. : 1.;
786 clusterI.SetX( driftPath*sign * 0.0001 );
787 clusterI.SetZ( anodePath * 0.0001 );
788 clusterI.SetAnode( newAnodef );
789 clusterI.SetTime( newiTimef );
790 clusterI.SetAsigma( sigma[i]*anodePitch );
791 clusterI.SetTsigma( tau[i]*fTimeStep );
792 clusterI.SetQ( integral[i] );
793 // clusterI.PrintInfo();
794 iTS->AddCluster( 1, &clusterI );
795 } // end for i
796 fClusters->RemoveAt( j );
797 delete [] par;
798 } else cout <<" --- Peak not found!!!! minpeak=" << fMinPeak<<
2bd89e94 799 " cluster peak=" << clusterJ->PeakAmpl() <<
800 " npeak=" << npeak << endl << endl;
42da2935 801 delete [] sp;
802 } // cluster loop
803 fClusters->Compress();
804 fMap->ClearMap();
a1f090e0 805}
42da2935 806//________________________________________________________________________
807void AliITSClusterFinderSDD::GroupClusters(){
808 // group clusters
809 Int_t dummy=0;
810 Float_t fTimeStep = fSegmentation->Dpx(dummy);
811 // get number of clusters for this module
812 Int_t nofClusters = fClusters->GetEntriesFast();
813 nofClusters -= fNclusters;
814 AliITSRawClusterSDD *clusterI;
815 AliITSRawClusterSDD *clusterJ;
816 Int_t *label = new Int_t [nofClusters];
817 Int_t i,j;
818 for(i=0; i<nofClusters; i++) label[i] = 0;
819 for(i=0; i<nofClusters; i++) {
820 if(label[i] != 0) continue;
821 for(j=i+1; j<nofClusters; j++) {
822 if(label[j] != 0) continue;
823 clusterI = (AliITSRawClusterSDD*) fClusters->At(i);
824 clusterJ = (AliITSRawClusterSDD*) fClusters->At(j);
825 // 1.3 good
826 if(clusterI->T() < fTimeStep*60) fDAnode = 4.2; // TB 3.2
827 if(clusterI->T() < fTimeStep*10) fDAnode = 1.5; // TB 1.
828 Bool_t pair = clusterI->Brother(clusterJ,fDAnode,fDTime);
829 if(!pair) continue;
830 // clusterI->PrintInfo();
831 // clusterJ->PrintInfo();
832 clusterI->Add(clusterJ);
833 label[j] = 1;
834 fClusters->RemoveAt(j);
835 j=i; // <- Ernesto
836 } // J clusters
837 label[i] = 1;
838 } // I clusters
839 fClusters->Compress();
840
841 delete [] label;
842 return;
b0f5e3fc 843}
42da2935 844//________________________________________________________________________
845void AliITSClusterFinderSDD::SelectClusters(){
846 // get number of clusters for this module
847 Int_t nofClusters = fClusters->GetEntriesFast();
b0f5e3fc 848
42da2935 849 nofClusters -= fNclusters;
850 Int_t i;
851 for(i=0; i<nofClusters; i++) {
852 AliITSRawClusterSDD *clusterI =(AliITSRawClusterSDD*) fClusters->At(i);
853 Int_t rmflg = 0;
854 Float_t wy = 0.;
855 if(clusterI->Anodes() != 0.) {
856 wy = ((Float_t) clusterI->Samples())/clusterI->Anodes();
857 } // end if
858 Int_t amp = (Int_t) clusterI->PeakAmpl();
859 Int_t cha = (Int_t) clusterI->Q();
860 if(amp < fMinPeak) rmflg = 1;
861 if(cha < fMinCharge) rmflg = 1;
862 if(wy < fMinNCells) rmflg = 1;
863 //if(wy > fMaxNCells) rmflg = 1;
864 if(rmflg) fClusters->RemoveAt(i);
865 } // I clusters
866 fClusters->Compress();
867 return;
b0f5e3fc 868}
42da2935 869//__________________________________________________________________________
870void AliITSClusterFinderSDD::ResolveClusters(){
871 // The function to resolve clusters if the clusters overlapping exists
872/* AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
873 // get number of clusters for this module
874 Int_t nofClusters = fClusters->GetEntriesFast();
875 nofClusters -= fNclusters;
876 //cout<<"Resolve Cl: nofClusters, fNclusters ="<<nofClusters<<","
877 // <<fNclusters<<endl;
878 Int_t fNofMaps = fSegmentation->Npz();
879 Int_t fNofAnodes = fNofMaps/2;
880 Int_t dummy=0;
881 Double_t fTimeStep = fSegmentation->Dpx(dummy);
882 Double_t fSddLength = fSegmentation->Dx();
883 Double_t fDriftSpeed = fResponse->DriftSpeed();
884 Double_t anodePitch = fSegmentation->Dpz(dummy);
885 Float_t n, baseline;
886 fResponse->GetNoiseParam(n,baseline);
887 Float_t dzz_1A = anodePitch * anodePitch / 12;
888 // fill Map of signals
a1f090e0 889 fMap->FillMap();
42da2935 890 Int_t j,i,ii,ianode,anode,itime;
891 Int_t wing,astart,astop,tstart,tstop,nanode;
892 Double_t fadc,ClusterTime;
893 Double_t q[400],x[400],z[400]; // digit charges and coordinates
894 for(j=0; j<nofClusters; j++) {
895 AliITSRawClusterSDD *clusterJ=(AliITSRawClusterSDD*) fClusters->At(j);
896 Int_t ndigits = 0;
897 astart=clusterJ->Astart();
898 astop=clusterJ->Astop();
899 tstart=clusterJ->Tstartf();
900 tstop=clusterJ->Tstopf();
901 nanode=clusterJ->Anodes(); // <- Ernesto
902 wing=(Int_t)clusterJ->W();
903 if(wing == 2) {
904 astart += fNofAnodes;
905 astop += fNofAnodes;
906 } // end if
907 // cout<<"astart,astop,tstart,tstop ="<<astart<<","<<astop<<","
908 // <<tstart<<","<<tstop<<endl;
909 // clear the digit arrays
910 for(ii=0; ii<400; ii++) {
911 q[ii] = 0.;
912 x[ii] = 0.;
913 z[ii] = 0.;
914 } // end for ii
915
916 for(ianode=astart; ianode<=astop; ianode++) {
917 for(itime=tstart; itime<=tstop; itime++) {
918 fadc=fMap->GetSignal(ianode,itime);
919 if(fadc>baseline) {
920 fadc-=(Double_t)baseline;
921 q[ndigits] = fadc*(fTimeStep/160); // KeV
922 anode = ianode;
923 if(wing == 2) anode -= fNofAnodes;
924 z[ndigits] = (anode + 0.5 - fNofAnodes/2)*anodePitch;
925 ClusterTime = itime*fTimeStep;
926 if(ClusterTime > fTimeCorr) ClusterTime -= fTimeCorr;// ns
927 x[ndigits] = fSddLength - ClusterTime*fDriftSpeed;
928 if(wing == 1) x[ndigits] *= (-1);
929 // cout<<"ianode,itime,fadc ="<<ianode<<","<<itime<<","
930 // <<fadc<<endl;
931 // cout<<"wing,anode,ndigits,charge ="<<wing<<","
932 // <<anode<<","<<ndigits<<","<<q[ndigits]<<endl;
933 ndigits++;
934 continue;
935 } // end if
936 fadc=0;
937 // cout<<"fadc=0, ndigits ="<<ndigits<<endl;
938 } // time loop
939 } // anode loop
940 // cout<<"for new cluster ndigits ="<<ndigits<<endl;
941 // Fit cluster to resolve for two separate ones --------------------
942 Double_t qq=0., xm=0., zm=0., xx=0., zz=0., xz=0.;
943 Double_t dxx=0., dzz=0., dxz=0.;
944 Double_t scl = 0., tmp, tga, elps = -1.;
945 Double_t xfit[2], zfit[2], qfit[2];
946 Double_t pitchz = anodePitch*1.e-4; // cm
947 Double_t pitchx = fTimeStep*fDriftSpeed*1.e-4; // cm
948 Double_t sigma2;
949 Int_t nfhits;
950 Int_t nbins = ndigits;
951 Int_t separate = 0;
952 // now, all lengths are in microns
953 for (ii=0; ii<nbins; ii++) {
954 qq += q[ii];
955 xm += x[ii]*q[ii];
956 zm += z[ii]*q[ii];
957 xx += x[ii]*x[ii]*q[ii];
958 zz += z[ii]*z[ii]*q[ii];
959 xz += x[ii]*z[ii]*q[ii];
960 } // end for ii
961 xm /= qq;
962 zm /= qq;
963 xx /= qq;
964 zz /= qq;
965 xz /= qq;
966 dxx = xx - xm*xm;
967 dzz = zz - zm*zm;
968 dxz = xz - xm*zm;
969
970 // shrink the cluster in the time direction proportionaly to the
971 // dxx/dzz, which lineary depends from the drift path
a1f090e0 972 // new Ernesto........
42da2935 973 if( nanode == 1 ){
974 dzz = dzz_1A; // for one anode cluster dzz = anode**2/12
975 scl = TMath::Sqrt( 7.2/(-0.57*xm*1.e-3+71.8) );
976 } // end if
977 if( nanode == 2 ){
978 scl = TMath::Sqrt( (-0.18*xm*1.e-3+21.3)/(-0.57*xm*1.e-3+71.8) );
979 } // end if
980 if( nanode == 3 ){
981 scl = TMath::Sqrt( (-0.5*xm*1.e-3+34.5)/(-0.57*xm*1.e-3+71.8) );
982 } // end if
983 if( nanode > 3 ){
984 scl = TMath::Sqrt( (1.3*xm*1.e-3+49.)/(-0.57*xm*1.e-3+71.8) );
985 } // end if
986 // cout<<"1 microns: zm,dzz,xm,dxx,dxz,qq ="<<zm<<","<<dzz<<","
987 // <<xm<<","<<dxx<<","<<dxz<<","<<qq<<endl;
988 // old Boris.........
989 // tmp=29730. - 585.*fabs(xm/1000.);
990 // scl=TMath::Sqrt(tmp/130000.);
a1f090e0 991
42da2935 992 xm *= scl;
993 xx *= scl*scl;
994 xz *= scl;
995
996 dxx = xx - xm*xm;
997 // dzz = zz - zm*zm;
998 dxz = xz - xm*zm;
999 // cout<<"microns: zm,dzz,xm,dxx,xz,dxz,qq ="<<zm<<","<<dzz<<","
1000 // <<xm<<","<<dxx<<","<<xz<<","<<dxz<<","<<qq<<endl;
1001 // if(dzz < 7200.) dzz=7200.;//for one anode cluster dzz = anode**2/12
a1f090e0 1002
42da2935 1003 if (dxx < 0.) dxx=0.;
1004 // the data if no cluster overlapping (the coordunates are in cm)
1005 nfhits = 1;
1006 xfit[0] = xm*1.e-4;
1007 zfit[0] = zm*1.e-4;
1008 qfit[0] = qq;
1009 // if(nbins < 7) cout<<"**** nbins ="<<nbins<<endl;
a1f090e0 1010
42da2935 1011 if (nbins >= 7) {
1012 if (dxz==0.) tga=0.;
1013 else {
1014 tmp=0.5*(dzz-dxx)/dxz;
1015 tga = (dxz<0.) ? tmp-TMath::Sqrt(tmp*tmp+1) :
1016 tmp+TMath::Sqrt(tmp*tmp+1);
1017 } // end if dxz
1018 elps=(tga*tga*dxx-2*tga*dxz+dzz)/(dxx+2*tga*dxz+tga*tga*dzz);
1019 // change from microns to cm
1020 xm *= 1.e-4;
1021 zm *= 1.e-4;
1022 zz *= 1.e-8;
1023 xx *= 1.e-8;
1024 xz *= 1.e-8;
1025 dxz *= 1.e-8;
1026 dxx *= 1.e-8;
1027 dzz *= 1.e-8;
1028 // cout<<"cm: zm,dzz,xm,dxx,xz,dxz,qq ="<<zm<<","<<dzz<<","
1029 // <<xm<<","<<dxx<<","<<xz<<","<<dxz<<","<<qq<<endl;
1030 for (i=0; i<nbins; i++) {
1031 x[i] = x[i] *= scl;
1032 x[i] = x[i] *= 1.e-4;
1033 z[i] = z[i] *= 1.e-4;
1034 } // end for i
1035 // cout<<"!!! elps ="<<elps<<endl;
1036 if (elps < 0.3) { // try to separate hits
1037 separate = 1;
1038 tmp=atan(tga);
1039 Double_t cosa=cos(tmp),sina=sin(tmp);
1040 Double_t a1=0., x1=0., xxx=0.;
1041 for (i=0; i<nbins; i++) {
1042 tmp=x[i]*cosa + z[i]*sina;
1043 if (q[i] > a1) {
1044 a1=q[i];
1045 x1=tmp;
1046 } // end if
1047 xxx += tmp*tmp*tmp*q[i];
1048 } // end for i
1049 xxx /= qq;
1050 Double_t z12=-sina*xm + cosa*zm;
1051 sigma2=(sina*sina*xx-2*cosa*sina*xz+cosa*cosa*zz) - z12*z12;
1052 xm=cosa*xm + sina*zm;
1053 xx=cosa*cosa*xx + 2*cosa*sina*xz + sina*sina*zz;
1054 Double_t x2=(xx - xm*x1 - sigma2)/(xm - x1);
1055 Double_t r=a1*2*TMath::ACos(-1.)*sigma2/(qq*pitchx*pitchz);
1056 for (i=0; i<33; i++) { // solve a system of equations
1057 Double_t x1_old=x1, x2_old=x2, r_old=r;
1058 Double_t c11=x1-x2;
1059 Double_t c12=r;
1060 Double_t c13=1-r;
1061 Double_t c21=x1*x1 - x2*x2;
1062 Double_t c22=2*r*x1;
1063 Double_t c23=2*(1-r)*x2;
1064 Double_t c31=3*sigma2*(x1-x2) + x1*x1*x1 - x2*x2*x2;
1065 Double_t c32=3*r*(sigma2 + x1*x1);
1066 Double_t c33=3*(1-r)*(sigma2 + x2*x2);
1067 Double_t f1=-(r*x1 + (1-r)*x2 - xm);
1068 Double_t f2=-(r*(sigma2+x1*x1)+(1-r)*(sigma2+x2*x2)- xx);
1069 Double_t f3=-(r*x1*(3*sigma2+x1*x1)+(1-r)*x2*
1070 (3*sigma2+x2*x2)-xxx);
1071 Double_t d=c11*c22*c33+c21*c32*c13+c12*c23*c31-
1072 c31*c22*c13 - c21*c12*c33 - c32*c23*c11;
1073 if (d==0.) {
1074 cout<<"*********** d=0 ***********\n";
1075 break;
1076 } // end if
1077 Double_t dr=f1*c22*c33 + f2*c32*c13 + c12*c23*f3 -
1078 f3*c22*c13 - f2*c12*c33 - c32*c23*f1;
1079 Double_t d1=c11*f2*c33 + c21*f3*c13 + f1*c23*c31 -
1080 c31*f2*c13 - c21*f1*c33 - f3*c23*c11;
1081 Double_t d2=c11*c22*f3 + c21*c32*f1 + c12*f2*c31 -
1082 c31*c22*f1 - c21*c12*f3 - c32*f2*c11;
1083 r += dr/d;
1084 x1 += d1/d;
1085 x2 += d2/d;
1086 if (fabs(x1-x1_old) > 0.0001) continue;
1087 if (fabs(x2-x2_old) > 0.0001) continue;
1088 if (fabs(r-r_old)/5 > 0.001) continue;
1089 a1=r*qq*pitchx*pitchz/(2*TMath::ACos(-1.)*sigma2);
1090 Double_t a2=a1*(1-r)/r;
1091 qfit[0]=a1; xfit[0]=x1*cosa - z12*sina; zfit[0]=x1*sina +
1092 z12*cosa;
1093 qfit[1]=a2; xfit[1]=x2*cosa - z12*sina; zfit[1]=x2*sina +
1094 z12*cosa;
1095 nfhits=2;
1096 break; // Ok !
1097 } // end for i
1098 if (i==33) cerr<<"No more iterations ! "<<endl;
1099 } // end of attempt to separate overlapped clusters
1100 } // end of nbins cut
1101 if(elps < 0.) cout<<" elps=-1 ="<<elps<<endl;
1102 if(elps >0. && elps< 0.3 && nfhits == 1) cout<<" small elps, nfh=1 ="
1103 <<elps<<","<<nfhits<<endl;
1104 if(nfhits == 2) cout<<" nfhits=2 ="<<nfhits<<endl;
1105 for (i=0; i<nfhits; i++) {
1106 xfit[i] *= (1.e+4/scl);
1107 if(wing == 1) xfit[i] *= (-1);
1108 zfit[i] *= 1.e+4;
1109 // cout<<" --------- i,xfiti,zfiti,qfiti ="<<i<<","
1110 // <<xfit[i]<<","<<zfit[i]<<","<<qfit[i]<<endl;
1111 } // end for i
1112 Int_t ncl = nfhits;
1113 if(nfhits == 1 && separate == 1) {
1114 cout<<"!!!!! no separate"<<endl;
1115 ncl = -2;
1116 } // end if
1117 if(nfhits == 2) {
1118 cout << "Split cluster: " << endl;
1119 clusterJ->PrintInfo();
1120 cout << " in: " << endl;
1121 for (i=0; i<nfhits; i++) {
1122 // AliITSRawClusterSDD *clust = new AliITSRawClusterSDD(wing,
1123 -1,-1,(Float_t)qfit[i],ncl,0,0,
1124 (Float_t)xfit[i],
1125 (Float_t)zfit[i],0,0,0,0,
1126 tstart,tstop,astart,astop);
1127 // AliITSRawClusterSDD *clust = new AliITSRawClusterSDD(wing,-1,
1128 // -1,(Float_t)qfit[i],0,0,0,
1129 // (Float_t)xfit[i],
1130 // (Float_t)zfit[i],0,0,0,0,
1131 // tstart,tstop,astart,astop,ncl);
1132 // ???????????
1133 // if(wing == 1) xfit[i] *= (-1);
1134 Float_t Anode = (zfit[i]/anodePitch+fNofAnodes/2-0.5);
1135 Float_t Time = (fSddLength - xfit[i])/fDriftSpeed;
1136 Float_t clusterPeakAmplitude = clusterJ->PeakAmpl();
1137 Float_t peakpos = clusterJ->PeakPos();
1138 Float_t clusteranodePath = (Anode - fNofAnodes/2)*anodePitch;
1139 Float_t clusterDriftPath = Time*fDriftSpeed;
1140 clusterDriftPath = fSddLength-clusterDriftPath;
1141 AliITSRawClusterSDD *clust = new AliITSRawClusterSDD(wing,Anode,
1142 Time,qfit[i],
1143 clusterPeakAmplitude,peakpos,
1144 0.,0.,clusterDriftPath,
1145 clusteranodePath,clusterJ->Samples()/2
a1f090e0 1146 ,tstart,tstop,0,0,0,astart,astop);
42da2935 1147 clust->PrintInfo();
1148 iTS->AddCluster(1,clust);
1149 // cout<<"new cluster added: tstart,tstop,astart,astop,x,ncl ="
1150 // <<tstart<<","<<tstop<<","<<astart<<","<<astop<<","<<xfit[i]
1151 // <<","<<ncl<<endl;
1152 delete clust;
1153 }// nfhits loop
1154 fClusters->RemoveAt(j);
1155 } // if nfhits = 2
1156} // cluster loop
1157fClusters->Compress();
1158fMap->ClearMap();
1159*/
1160 return;
a1f090e0 1161}
42da2935 1162//______________________________________________________________________
1163void AliITSClusterFinderSDD::GetRecPoints(){
1164 // get rec points
1165 static AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
1166 // get number of clusters for this module
1167 Int_t nofClusters = fClusters->GetEntriesFast();
1168 nofClusters -= fNclusters;
1169 const Float_t kconvGeV = 1.e-6; // GeV -> KeV
1170 const Float_t kconv = 1.0e-4;
1171 const Float_t kRMSx = 38.0*kconv; // microns->cm ITS TDR Table 1.3
1172 const Float_t kRMSz = 28.0*kconv; // microns->cm ITS TDR Table 1.3
1173 Int_t i;
1174 Int_t ix, iz, idx=-1;
1175 AliITSdigitSDD *dig=0;
1176 Int_t ndigits=fDigits->GetEntriesFast();
1177 for(i=0; i<nofClusters; i++) {
1178 AliITSRawClusterSDD *clusterI = (AliITSRawClusterSDD*)fClusters->At(i);
1179 if(!clusterI) Error("SDD: GetRecPoints","i clusterI ",i,clusterI);
1180 if(clusterI) idx=clusterI->PeakPos();
1181 if(idx>ndigits) Error("SDD: GetRecPoints","idx ndigits",idx,ndigits);
1182 // try peak neighbours - to be done
1183 if(idx&&idx<= ndigits) dig =(AliITSdigitSDD*)fDigits->UncheckedAt(idx);
1184 if(!dig) {
1185 // try cog
1186 fSegmentation->GetPadIxz(clusterI->X(),clusterI->Z(),ix,iz);
1187 dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix-1);
1188 // if null try neighbours
1189 if (!dig) dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix);
1190 if (!dig) dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix+1);
1191 if (!dig) printf("SDD: cannot assign the track number!\n");
1192 } // end if !dig
1193 AliITSRecPoint rnew;
1194 rnew.SetX(clusterI->X());
1195 rnew.SetZ(clusterI->Z());
1196 rnew.SetQ(clusterI->Q()); // in KeV - should be ADC
1197 rnew.SetdEdX(kconvGeV*clusterI->Q());
1198 rnew.SetSigmaX2(kRMSx*kRMSx);
1199 rnew.SetSigmaZ2(kRMSz*kRMSz);
1200 if(dig) rnew.fTracks[0]=dig->fTracks[0];
1201 if(dig) rnew.fTracks[1]=dig->fTracks[1];
1202 if(dig) rnew.fTracks[2]=dig->fTracks[2];
1203 //printf("SDD: i %d track1 track2 track3 %d %d %d x y %f %f\n",
1204 // i,rnew.fTracks[0],rnew.fTracks[1],rnew.fTracks[2],c
1205 // lusterI->X(),clusterI->Z());
1206 iTS->AddRecPoint(rnew);
1207 } // I clusters
1208 fMap->ClearMap();
b0f5e3fc 1209}
42da2935 1210//______________________________________________________________________
1211void AliITSClusterFinderSDD::FindRawClusters(Int_t mod){
1212 // find raw clusters
b0f5e3fc 1213
a1f090e0 1214 Find1DClustersE();
b0f5e3fc 1215 GroupClusters();
1216 SelectClusters();
a1f090e0 1217 ResolveClustersE();
b0f5e3fc 1218 GetRecPoints();
1219}
42da2935 1220//_______________________________________________________________________
1221void AliITSClusterFinderSDD::Print(){
1222 // Print SDD cluster finder Parameters
1223
1224 cout << "**************************************************" << endl;
1225 cout << " Silicon Drift Detector Cluster Finder Parameters " << endl;
1226 cout << "**************************************************" << endl;
1227 cout << "Number of Clusters: " << fNclusters << endl;
1228 cout << "Anode Tolerance: " << fDAnode << endl;
1229 cout << "Time Tolerance: " << fDTime << endl;
1230 cout << "Time correction (electronics): " << fTimeCorr << endl;
1231 cout << "Cut Amplitude (threshold): " << fCutAmplitude << endl;
1232 cout << "Minimum Amplitude: " << fMinPeak << endl;
1233 cout << "Minimum Charge: " << fMinCharge << endl;
1234 cout << "Minimum number of cells/clusters: " << fMinNCells << endl;
1235 cout << "Maximum number of cells/clusters: " << fMaxNCells << endl;
1236 cout << "**************************************************" << endl;
a1f090e0 1237}