]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSClusterFinderSDD.cxx
Fixed type from Float_t to Int_t for thres.
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderSDD.cxx
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  **************************************************************************/
15
16 #include <TFile.h>
17
18 #include "AliITSClusterFinderSDD.h"
19 #include "AliITSMapA1.h"
20 #include "AliITS.h"
21 #include "AliITSdigit.h"
22 #include "AliITSRawCluster.h"
23 #include "AliITSRecPoint.h"
24 #include "AliITSsegmentation.h"
25 #include "AliITSresponse.h"
26 #include "AliRun.h"
27
28
29
30 ClassImp(AliITSClusterFinderSDD)
31
32 //----------------------------------------------------------
33 AliITSClusterFinderSDD::AliITSClusterFinderSDD
34 (AliITSsegmentation *seg, AliITSresponse *response, TClonesArray *digits, TClonesArray *recp)   
35 {
36   // constructor
37
38     fSegmentation=seg;
39     fResponse=response;
40     fDigits=digits;
41     fClusters=recp;
42     fNclusters= fClusters->GetEntriesFast();
43     SetCutAmplitude();
44     SetDAnode();
45     SetDTime();
46     SetMinPeak();
47     SetMinNCells();
48     SetMaxNCells();
49     SetTimeCorr();
50     fMap=new AliITSMapA1(fSegmentation,fDigits,fCutAmplitude);
51
52 }
53
54 //_____________________________________________________________________________
55 AliITSClusterFinderSDD::AliITSClusterFinderSDD()
56 {
57   // constructor
58     fSegmentation=0;
59     fResponse=0;
60     fDigits=0;
61     fClusters=0;
62     fNclusters=0;
63     fMap=0;
64     SetCutAmplitude();
65     SetDAnode();
66     SetDTime();
67     SetMinPeak();
68     SetMinNCells();
69     SetMaxNCells();
70     SetTimeCorr();
71
72 }
73
74 //_____________________________________________________________________________
75 AliITSClusterFinderSDD::~AliITSClusterFinderSDD()
76 {
77     // destructor
78
79     if(fMap) delete fMap;
80
81 }
82 //__________________________________________________________________________
83 AliITSClusterFinderSDD::AliITSClusterFinderSDD(const AliITSClusterFinderSDD &source){
84   //     Copy Constructor 
85   if(&source == this) return;
86   this->fClusters = source.fClusters ;
87   this->fNclusters = source.fNclusters ;
88   this->fMap = source.fMap ;
89   this->fCutAmplitude = source.fCutAmplitude ;
90   this->fDAnode = source.fDAnode ;
91   this->fDTime = source.fDTime ;
92   this->fTimeCorr = source.fTimeCorr ;
93   this->fMinPeak = source.fMinPeak ;
94   this->fMinNCells = source.fMinNCells ;
95   this->fMaxNCells = source.fMaxNCells ;
96   return;
97 }
98
99 //_________________________________________________________________________
100 AliITSClusterFinderSDD& 
101   AliITSClusterFinderSDD::operator=(const AliITSClusterFinderSDD &source) {
102   //    Assignment operator
103   if(&source == this) return *this;
104   this->fClusters = source.fClusters ;
105   this->fNclusters = source.fNclusters ;
106   this->fMap = source.fMap ;
107   this->fCutAmplitude = source.fCutAmplitude ;
108   this->fDAnode = source.fDAnode ;
109   this->fDTime = source.fDTime ;
110   this->fTimeCorr = source.fTimeCorr ;
111   this->fMinPeak = source.fMinPeak ;
112   this->fMinNCells = source.fMinNCells ;
113   this->fMaxNCells = source.fMaxNCells ;
114   return *this;
115 }
116
117
118 //_____________________________________________________________________________
119
120 void AliITSClusterFinderSDD::Find1DClusters()
121 {
122   // find 1D clusters
123
124     AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
125
126    // retrieve the parameters 
127    Int_t fNofMaps = fSegmentation->Npz();
128    Int_t fMaxNofSamples = fSegmentation->Npx();
129    Int_t fNofAnodes = fNofMaps/2;
130    Int_t dummy=0;
131    Float_t fTimeStep = fSegmentation->Dpx(dummy);
132    Float_t fSddLength = fSegmentation->Dx();
133    Float_t fDriftSpeed = fResponse->DriftSpeed();
134    
135    Float_t anodePitch = fSegmentation->Dpz(dummy);
136    // map the signal
137    fMap->SetThreshold(fCutAmplitude);
138    fMap->FillMap();
139
140    Float_t noise;
141    Float_t baseline;
142    fResponse->GetNoiseParam(noise,baseline);
143
144    Float_t maxadc = fResponse->MaxAdc();    
145    Float_t topValue = fResponse->MagicValue();
146    Float_t norm = maxadc/topValue;
147
148    Int_t nofFoundClusters = 0;
149    Int_t i;
150    Float_t **dfadc = new Float_t*[fNofAnodes];
151    for(i=0;i<fNofAnodes;i++) dfadc[i] = new Float_t[fMaxNofSamples];
152    Float_t fadc, fadc1, fadc2;
153    Int_t j,k,idx,l,m;
154    for(j=0;j<2;j++) {
155      for(k=0;k<fNofAnodes;k++) {
156        idx = j*fNofAnodes+k;
157        // signal (fadc) & derivative (dfadc)
158        for(l=0; l<fMaxNofSamples; l++) {
159          fadc2=(Float_t)fMap->GetSignal(idx,l);
160          if(l>0) fadc1=(Float_t)fMap->GetSignal(idx,l-1);
161          if(l>0) dfadc[k][l-1] = fadc2-fadc1;
162        } // samples
163      } // anodes
164     
165      for(k=0;k<fNofAnodes;k++) {
166        //cout << "Anode: " << k+1 << ", Wing: " << j+1 << endl;
167        idx = j*fNofAnodes+k;
168  
169        Int_t imax = 0;
170        Int_t imaxd = 0;
171        Int_t it=0;
172        while(it <= fMaxNofSamples-3) {
173         
174          imax = it;
175          imaxd = it;
176          // maximum of signal     
177         
178          Float_t fadcmax = 0.;
179          Float_t dfadcmax = 0.;
180          Int_t lthrmina = 1;
181          //     if(it >= 60) lthrmina = 2;
182          //      if(it >= 100) lthrmina = 3;
183          Int_t lthrmint = 2;
184          //if(it >= 60) lthrmint = 3;
185          //if(it >= 100) lthrmint = 4;
186
187          Int_t lthra = 1;
188          Int_t lthrt = 0;
189         
190          for(m=0;m<20;m++) {
191            Int_t id = it+m;
192            if(id>=fMaxNofSamples) break;
193            fadc=(float)fMap->GetSignal(idx,id);
194            if(fadc > fadcmax) { fadcmax = fadc; imax = id;}
195            if(fadc > (float)fCutAmplitude) { 
196              lthrt++; 
197            }
198
199            if(dfadc[k][id] > dfadcmax) {
200              dfadcmax = dfadc[k][id];
201              imaxd = id;
202            }
203          }
204          it = imaxd;
205         
206          if(fMap->TestHit(idx,imax) == kEmpty) {it++; continue;}
207
208          // cluster charge
209          Int_t tstart = it-1;
210         
211          Bool_t ilcl = 0;
212          if(lthrt >= lthrmint && lthra >= lthrmina) ilcl = 1;
213          //printf("ilcl %d\n",ilcl);
214
215          Float_t b,n;
216          fResponse->GetNoiseParam(n,b);
217
218          if(ilcl) {
219            nofFoundClusters++;
220            Int_t tstop = tstart;
221            Float_t dfadcmin = 10000.;
222            Int_t ij;
223            for(ij=0; ij<20; ij++) {
224              if(dfadc[k][it+ij] < dfadcmin) {
225                tstop = it+ij+1;
226                dfadcmin = dfadc[k][it+ij];
227              }
228            }
229
230            Float_t clusterCharge = 0.;
231            Float_t clusterAnode = k+0.5;
232            Float_t clusterTime = 0.;
233            Float_t clusterMult = 0.;
234            Float_t clusterPeakAmplitude = 0.;
235            Int_t its,peakpos=-1;
236            Float_t n, baseline;
237            fResponse->GetNoiseParam(n,baseline);
238            for(its=tstart; its<=tstop; its++) {
239              fadc=(float)fMap->GetSignal(idx,its);
240              if(fadc>baseline)
241                fadc-=baseline;
242              else
243                fadc=0.;
244              clusterCharge += fadc;
245              // as a matter of fact we should take the peak pos before FFT
246              // to get the list of tracks !!!
247              if(fadc > clusterPeakAmplitude) {
248                clusterPeakAmplitude = fadc;
249                //peakpos=fMap->GetHitIndex(idx,its);
250                Int_t shift=(int)(fTimeCorr/fTimeStep);
251                if(its>shift && its<(fMaxNofSamples-shift)) peakpos=fMap->GetHitIndex(idx,its+shift);
252                else peakpos=fMap->GetHitIndex(idx,its);
253                if(peakpos<0) peakpos=fMap->GetHitIndex(idx,its);
254              }
255              clusterTime += fadc*its;
256              clusterMult++;
257              if(its == tstop) {
258                // charge from ADC back to nA 
259                //clusterCharge /= norm;
260                if(clusterCharge <= 0.) printf("clusterCharge %f norm %f\n",clusterCharge,norm);
261                clusterTime /= (clusterCharge/fTimeStep);   // ns
262                clusterCharge *= (fTimeStep/160.);          // keV
263                if(clusterTime > fTimeCorr) clusterTime -= fTimeCorr;   // ns
264              }
265            }
266            // cout << "Anode: " << k << ", tstart: " << tstart << ", tstop: " << tstop << ", Charge: " << clusterCharge << endl;
267
268            Float_t clusteranodePath = (clusterAnode - fNofAnodes/2)*anodePitch;
269            Float_t clusterDriftPath = clusterTime*fDriftSpeed;
270            clusterDriftPath = fSddLength-clusterDriftPath;
271
272            if(clusterCharge <= 0.) break;
273
274            AliITSRawClusterSDD *clust = new AliITSRawClusterSDD(j+1,clusterAnode,clusterTime,clusterCharge,clusterPeakAmplitude,peakpos,0.,0.,clusterDriftPath,clusteranodePath,clusterMult);
275            iTS->AddCluster(1,clust);
276            it = tstop;
277         } // ilcl
278         
279         it++;
280         
281       } // while (samples)
282     } // anodes
283   } // detectors (2)
284
285
286    //fMap->ClearMap(); 
287   
288   for(i=0;i<fNofAnodes;i++) delete[] dfadc[i];
289   delete [] dfadc;
290
291   return;
292
293 }
294
295 //_____________________________________________________________________________
296 void  AliITSClusterFinderSDD::GroupClusters()
297 {
298   // group clusters
299   Int_t dummy=0;
300   Float_t fTimeStep = fSegmentation->Dpx(dummy);
301
302
303   // get number of clusters for this module
304   Int_t nofClusters = fClusters->GetEntriesFast();
305   nofClusters -= fNclusters;
306
307   AliITSRawClusterSDD *clusterI;
308   AliITSRawClusterSDD *clusterJ;
309
310   Int_t *label = new Int_t [nofClusters];
311   Int_t i,j;
312   for(i=0; i<nofClusters; i++) label[i] = 0;
313   for(i=0; i<nofClusters; i++) { 
314     if(label[i] != 0) continue;
315     for(j=i+1; j<nofClusters; j++) { 
316       if(label[j] != 0) continue;
317       clusterI = (AliITSRawClusterSDD*) fClusters->At(i);
318       clusterJ = (AliITSRawClusterSDD*) fClusters->At(j);
319       // 1.3 good
320       if(clusterI->T() < fTimeStep*60) fDAnode = 3.2;
321       if(clusterI->T() < fTimeStep*10) fDAnode = 1.2;
322       Bool_t pair = clusterI->Brother(clusterJ,fDAnode,fDTime);
323       if(!pair) continue;
324       //      clusterI->PrintInfo();
325       //      clusterJ->PrintInfo();
326       clusterI->Add(clusterJ);
327       label[j] = 1;
328       fClusters->RemoveAt(j);
329     } // J clusters  
330     label[i] = 1;
331   } // I clusters
332   fClusters->Compress();
333   
334   delete [] label;
335   return;
336
337 }
338
339 //_____________________________________________________________________________
340
341 void AliITSClusterFinderSDD::SelectClusters()
342 {
343   // get number of clusters for this module
344   Int_t nofClusters = fClusters->GetEntriesFast();
345   nofClusters -= fNclusters;
346
347   Int_t i;
348   for(i=0; i<nofClusters; i++) { 
349     AliITSRawClusterSDD *clusterI = (AliITSRawClusterSDD*) fClusters->At(i);
350     Int_t rmflg = 0;
351     Float_t wy = 0.;
352     if(clusterI->Anodes() != 0.) {
353       wy = ((Float_t) clusterI->Samples())/clusterI->Anodes();
354     }
355     Float_t amp = clusterI->PeakAmpl();
356     if(amp < fMinPeak) rmflg = 1;  
357     if(wy < fMinNCells) rmflg = 1;
358     //if(wy > fMaxNCells) rmflg = 1;
359     if(rmflg) fClusters->RemoveAt(i);
360   } // I clusters
361   fClusters->Compress();
362   return;
363
364 }
365
366 //_____________________________________________________________________________
367
368 void AliITSClusterFinderSDD::GetRecPoints()
369 {
370   // get rec points
371
372   AliITS *iTS=(AliITS*)gAlice->GetModule("ITS");
373
374   // get number of clusters for this module
375   Int_t nofClusters = fClusters->GetEntriesFast();
376   nofClusters -= fNclusters;
377
378   const Float_t kconvGeV = 1.e-6; // GeV -> KeV
379   const Float_t kconv = 1.0e-4; 
380   const Float_t kRMSx = 38.0*kconv; // microns->cm ITS TDR Table 1.3
381   const Float_t kRMSz = 28.0*kconv; // microns->cm ITS TDR Table 1.3
382
383
384   Int_t i;
385   Int_t ix, iz, idx=-1;
386   AliITSdigitSDD *dig=0;
387 //  Int_t maxt=fSegmentation->Npx();
388   Int_t ndigits=fDigits->GetEntriesFast();
389   for(i=0; i<nofClusters; i++) { 
390     AliITSRawClusterSDD *clusterI = (AliITSRawClusterSDD*)fClusters->At(i);
391     if(!clusterI) Error("SDD: GetRecPoints","i clusterI ",i,clusterI);
392     if(clusterI) idx=clusterI->PeakPos();
393     if(idx>ndigits) Error("SDD: GetRecPoints","idx ndigits",idx,ndigits);
394     // try peak neighbours - to be done 
395     if(idx && idx <= ndigits) dig = (AliITSdigitSDD*)fDigits->UncheckedAt(idx);
396     if(!dig) {
397         // try cog
398         fSegmentation->GetPadIxz(clusterI->X(),clusterI->Z(),ix,iz);
399         dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix-1);
400         // if null try neighbours
401         if (!dig) dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix); 
402         if (!dig) dig = (AliITSdigitSDD*)fMap->GetHit(iz-1,ix+1); 
403         if (!dig) printf("SDD: cannot assign the track number!\n");
404     }
405
406     AliITSRecPoint rnew;
407     rnew.SetX(clusterI->X());
408     rnew.SetZ(clusterI->Z());
409     rnew.SetQ(clusterI->Q());   // in KeV - should be ADC
410     rnew.SetdEdX(kconvGeV*clusterI->Q());
411     rnew.SetSigmaX2(kRMSx*kRMSx);
412     rnew.SetSigmaZ2(kRMSz*kRMSz);
413     if(dig) rnew.fTracks[0]=dig->fTracks[0];
414     if(dig) rnew.fTracks[1]=dig->fTracks[1];
415     if(dig) rnew.fTracks[2]=dig->fTracks[2];
416     //printf("SDD: i %d track1 track2 track3 %d %d %d x y %f %f\n",i,rnew.fTracks[0],rnew.fTracks[1],rnew.fTracks[2],clusterI->X(),clusterI->Z());
417     iTS->AddRecPoint(rnew);
418   } // I clusters
419
420   fMap->ClearMap();
421 }
422
423 //_____________________________________________________________________________
424
425 void AliITSClusterFinderSDD::FindRawClusters()
426 {
427   // find raw clusters
428     Find1DClusters();
429     GroupClusters();
430     SelectClusters();
431     GetRecPoints();
432 }