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