]> git.uio.no Git - u/mrichter/AliRoot.git/blob - ITS/AliITSclustererV2.cxx
AliIT
[u/mrichter/AliRoot.git] / ITS / AliITSclustererV2.cxx
1 //-------------------------------------------------------------------------
2 //            Implementation of the ITS clusterer V2 class
3 //
4 //          Origin: Iouri Belikov, CERN, Jouri.Belikov@cern.ch
5 //-------------------------------------------------------------------------
6
7
8 #include "AliRun.h"
9
10 #include "AliITSclustererV2.h"
11 #include "AliITSclusterV2.h"
12 #include "AliITSDetTypeRec.h"
13 #include "AliRawReader.h"
14 #include "AliITSRawStreamSPD.h"
15 #include "AliITSRawStreamSDD.h"
16 #include "AliITSRawStreamSSD.h"
17
18 #include <TFile.h>
19 #include <TTree.h>
20 #include <TClonesArray.h>
21 #include "AliITSgeomTGeo.h"
22 #include "AliITSdigitSPD.h"
23 #include "AliITSdigitSDD.h"
24 #include "AliITSdigitSSD.h"
25 #include "AliMC.h"
26
27 ClassImp(AliITSclustererV2)
28
29 extern AliRun *gAlice;
30
31 AliITSclustererV2::AliITSclustererV2():
32 fNModules(0),
33 fEvent(0),
34 fI(0),
35 fLastSPD1(0),
36 fNySPD(0),
37 fNzSPD(0),
38 fYpitchSPD(0),
39 fZ1pitchSPD(0),
40 fZ2pitchSPD(0),
41 fHwSPD(0),
42 fHlSPD(0),
43 fNySDD(0),
44 fNzSDD(0),
45 fYpitchSDD(0),
46 fZpitchSDD(0),
47 fHwSDD(0),
48 fHlSDD(0),
49 fYoffSDD(0),
50 fLastSSD1(0),
51 fYpitchSSD(0),
52 fHwSSD(0),
53 fHlSSD(0),
54 fTanP(0),
55 fTanN(0){
56    //default constructor
57  }
58 AliITSclustererV2::AliITSclustererV2(const Char_t *geom):
59 fNModules(AliITSgeomTGeo::GetNModules()),
60 fEvent(0),
61 fI(0),
62 fLastSPD1(AliITSgeomTGeo::GetModuleIndex(2,1,1)-1),
63 fNySPD(256),
64 fNzSPD(160),
65 fYpitchSPD(0.0050),
66 fZ1pitchSPD(0.0425),
67 fZ2pitchSPD(0.0625),
68 fHwSPD(0.64),
69 fHlSPD(3.48),
70 fNySDD(256),
71 fNzSDD(256),
72 fYpitchSDD(0.01825),
73 fZpitchSDD(0.02940),
74 fHwSDD(3.5085),
75 fHlSDD(3.7632),
76 fYoffSDD(0.0425),
77 fLastSSD1(AliITSgeomTGeo::GetModuleIndex(6,1,1)-1),
78 fYpitchSSD(0.0095),
79 fHwSSD(3.65),
80 fHlSSD(2.00),
81 fTanP(0.0275),
82 fTanN(0.0075) {
83   //------------------------------------------------------------
84   // Standard constructor
85   //------------------------------------------------------------
86   if (geom) {
87     AliWarning("\"geom\" is actually a dummy argument !");
88   }
89   Int_t m;
90   for (m=0; m<fNModules; m++) {
91      Int_t lay,lad,det; AliITSgeomTGeo::GetModuleId(m,lay,lad,det);
92      const TGeoHMatrix *tm=AliITSgeomTGeo::GetTracking2LocalMatrix(m);
93      fYshift[m] = (tm->Inverse()).GetTranslation()[1];
94      fZshift[m] = (tm->Inverse()).GetTranslation()[2];
95      fNdet[m] = (lad-1)*AliITSgeomTGeo::GetNDetectors(lay) + (det-1);
96      fNlayer[m] = lay-1;
97   }
98
99   //SPD geometry  
100   fYSPD[0]=0.5*fYpitchSPD;
101   for (m=1; m<fNySPD; m++) fYSPD[m]=fYSPD[m-1]+fYpitchSPD; 
102   fZSPD[0]=fZ1pitchSPD;
103   for (m=1; m<fNzSPD; m++) {
104     Double_t dz=fZ1pitchSPD;
105     if (m==31 || m==32 || m==63  || m==64  || m==95 || m==96 || 
106         m==127 || m==128) dz=fZ2pitchSPD; 
107     fZSPD[m]=fZSPD[m-1]+dz;
108   }
109   for (m=0; m<fNzSPD; m++) {
110     Double_t dz=0.5*fZ1pitchSPD;
111     if (m==31 || m==32 || m==63  || m==64  || m==95 || m==96 || 
112         m==127 || m==128) dz=0.5*fZ2pitchSPD; 
113     fZSPD[m]-=dz;
114   }
115
116 }
117
118
119 Int_t AliITSclustererV2::Digits2Clusters(TTree *dTree, TTree *cTree) {
120   //------------------------------------------------------------
121   // This function creates ITS clusters
122   //------------------------------------------------------------
123   Int_t ncl=0;
124
125   if (!dTree) {
126     Error("Digits2Clusters","Can't get the tree with digits !");
127     return 1;
128   }
129
130   TClonesArray *digitsSPD=new TClonesArray("AliITSdigitSPD",3000);
131   dTree->SetBranchAddress("ITSDigitsSPD",&digitsSPD);
132   TClonesArray *digitsSDD=new TClonesArray("AliITSdigitSDD",3000);
133   dTree->SetBranchAddress("ITSDigitsSDD",&digitsSDD);
134   TClonesArray *digitsSSD=new TClonesArray("AliITSdigitSSD",3000);
135   dTree->SetBranchAddress("ITSDigitsSSD",&digitsSSD);
136
137   TClonesArray *clusters=new TClonesArray("AliITSclusterV2",1000);
138   TBranch *branch=cTree->GetBranch("Clusters");
139   if (!branch) cTree->Branch("Clusters",&clusters);
140   else branch->SetAddress(&clusters);
141
142   Int_t mmax=(Int_t)dTree->GetEntries();
143   if (mmax!=fNModules) {
144     Error("Digits2Clusters","Number of entries != number of modules !");
145     return 1;
146   }
147
148   for (fI=0; fI<mmax; fI++) {
149     dTree->GetEvent(fI);
150
151     if     (digitsSPD->GetEntriesFast()!=0) 
152       FindClustersSPD(digitsSPD,clusters);
153     else 
154       if(digitsSDD->GetEntriesFast()!=0) 
155         FindClustersSDD(digitsSDD,clusters);
156       else if(digitsSSD->GetEntriesFast()!=0) 
157         FindClustersSSD(digitsSSD,clusters);
158     
159     ncl+=clusters->GetEntriesFast();
160
161     cTree->Fill();
162
163     digitsSPD->Clear();
164     digitsSDD->Clear();
165     digitsSSD->Clear();
166     clusters->Clear();
167   }
168
169   //cTree->Write();
170
171   delete clusters;
172
173   delete digitsSPD;
174   delete digitsSDD;
175   delete digitsSSD;
176
177   //delete dTree;
178
179   Info("Digits2Clusters","Number of found clusters : %d",ncl);
180
181   return 0;
182 }
183
184 void AliITSclustererV2::Digits2Clusters(AliRawReader* rawReader) {
185   //------------------------------------------------------------
186   // This function creates ITS clusters from raw data
187   //------------------------------------------------------------
188   AliRunLoader* runLoader = AliRunLoader::GetRunLoader();
189   if (!runLoader) {
190     Error("Digits2Clusters", "no run loader found");
191     return;
192   }
193   runLoader->LoadKinematics();
194   AliLoader* itsLoader = runLoader->GetLoader("ITSLoader");
195   if (!itsLoader) {
196     Error("Digits2Clusters", "no loader for ITS found");
197     return;
198   }
199   if (!itsLoader->TreeR()) itsLoader->MakeTree("R");
200   TTree* cTree = itsLoader->TreeR();
201
202   TClonesArray *array=new TClonesArray("AliITSclusterV2",1000);
203   cTree->Branch("Clusters",&array);
204   delete array;
205
206   TClonesArray** clusters = new TClonesArray*[fNModules]; 
207   for (Int_t iModule = 0; iModule < fNModules; iModule++) {
208     clusters[iModule] = NULL;
209   }
210   // one TClonesArray per module
211
212   rawReader->Reset();
213   AliITSRawStreamSPD inputSPD(rawReader);
214   FindClustersSPD(&inputSPD, clusters);
215
216   rawReader->Reset();
217   AliITSRawStreamSDD inputSDD(rawReader);
218   FindClustersSDD(&inputSDD, clusters);
219
220   rawReader->Reset();
221   AliITSRawStreamSSD inputSSD(rawReader);
222   FindClustersSSD(&inputSSD, clusters);
223
224   // write all clusters to the tree
225   Int_t nClusters = 0;
226   for (Int_t iModule = 0; iModule < fNModules; iModule++) {
227     array = clusters[iModule];
228     if (!array) {
229       Error("Digits2Clusters", "data for module %d missing!", iModule);
230       array = new TClonesArray("AliITSclusterV2");
231     }
232     cTree->SetBranchAddress("Clusters", &array);
233     cTree->Fill();
234     nClusters += array->GetEntriesFast();
235     delete array;
236   }
237   itsLoader->WriteRecPoints("OVERWRITE");
238
239   delete[] clusters;
240
241   Info("Digits2Clusters", "total number of found clusters in ITS: %d\n", 
242        nClusters);
243 }
244
245 //**** Fast clusters *******************************
246 #include "TParticle.h"
247
248 //#include "AliITS.h"
249 #include "AliITSmodule.h"
250 #include "AliITSRecPoint.h"
251 #include "AliITSsimulationFastPoints.h"
252 #include "AliITSRecPoint.h"
253
254
255 static void CheckLabels(Int_t lab[3]) {
256   //------------------------------------------------------------
257   // Tries to find mother's labels
258   //------------------------------------------------------------
259   AliRunLoader *rl = AliRunLoader::GetRunLoader();
260   TTree *trK=(TTree*)rl->TreeK();
261
262   if(trK){
263     Int_t label=lab[0];
264     if (label>=0) {
265       TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
266       label=-3;
267       while (part->P() < 0.005) {
268         Int_t m=part->GetFirstMother();
269         if (m<0) {
270           Info("CheckLabels","Primary momentum: %f",part->P()); 
271           break;
272         }
273         if (part->GetStatusCode()>0) {
274           Info("CheckLabels","Primary momentum: %f",part->P()); 
275           break;
276         }
277         label=m;
278         part=(TParticle*)gAlice->GetMCApp()->Particle(label);
279       }
280       if      (lab[1]<0) lab[1]=label;
281       else if (lab[2]<0) lab[2]=label;
282       else ;//cerr<<"CheckLabels : No empty labels !\n";
283     }
284   }
285 }
286
287 /*
288 static void CheckLabels(Int_t lab[3]) {
289   //------------------------------------------------------------
290   // Tries to find mother's labels
291   //------------------------------------------------------------
292
293   if(lab[0]<0 && lab[1]<0 && lab[2]<0) return; // In case of no labels just exit
294
295   Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
296   for (Int_t i=0;i<3;i++){
297     Int_t label = lab[i];
298     if (label>=0 && label<ntracks) {
299       TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
300       if (part->P() < 0.005) {
301         Int_t m=part->GetFirstMother();
302         if (m<0) {      
303           continue;
304         }
305         if (part->GetStatusCode()>0) {
306           continue;
307         }
308         lab[i]=m;       
309       }
310     }    
311   }
312   
313 }
314 */
315 static void CheckLabels2(Int_t lab[10]) {
316   //------------------------------------------------------------
317   // Tries to find mother's labels
318   //------------------------------------------------------------
319   AliRunLoader *rl = AliRunLoader::GetRunLoader();
320   TTree *trK=(TTree*)rl->TreeK();
321
322   if(trK){
323     Int_t nlabels =0; 
324     for (Int_t i=0;i<10;i++) if (lab[i]>=0) nlabels++;
325     if(nlabels == 0) return; // In case of no labels just exit
326
327     Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
328
329     for (Int_t i=0;i<10;i++){
330       Int_t label = lab[i];
331       if (label>=0 && label<ntracks) {
332         TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
333         if (part->P() < 0.02) {
334           Int_t m=part->GetFirstMother();
335           if (m<0) {    
336             continue;
337           }
338           if (part->GetStatusCode()>0) {
339             continue;
340           }
341           lab[i]=m;       
342         }
343         else
344           if (part->P() < 0.12 && nlabels>3) {
345             lab[i]=-2;
346             nlabels--;
347           } 
348       }
349       else{
350         if ( (label>ntracks||label <0) && nlabels>3) {
351           lab[i]=-2;
352           nlabels--;
353         } 
354       }
355     }  
356     if (nlabels>3){
357       for (Int_t i=0;i<10;i++){
358         if (nlabels>3){
359           Int_t label = lab[i];
360           if (label>=0 && label<ntracks) {
361             TParticle *part=(TParticle*)gAlice->GetMCApp()->Particle(label);
362             if (part->P() < 0.1) {
363               lab[i]=-2;
364               nlabels--;
365             }
366           }
367         }
368       }
369     }
370
371     //compress labels -- if multi-times the same
372     Int_t lab2[10];
373     for (Int_t i=0;i<10;i++) lab2[i]=-2;
374     for (Int_t i=0;i<10  ;i++){
375       if (lab[i]<0) continue;
376       for (Int_t j=0;j<10 &&lab2[j]!=lab[i];j++){
377         if (lab2[j]<0) {
378           lab2[j]= lab[i];
379           break;
380         }
381       }
382     }
383     for (Int_t j=0;j<10;j++) lab[j]=lab2[j];
384   }
385 }
386
387 static void AddLabel(Int_t lab[10], Int_t label) {
388 // add label of the particle in the kine tree which originates this cluster
389 // (used for reconstruction of MC data only, for comparison purposes)
390   AliRunLoader *rl = AliRunLoader::GetRunLoader();
391   TTree *trK=(TTree*)rl->TreeK();
392
393   if(trK){
394     if(label<0) return; // In case of no label just exit
395
396     Int_t ntracks = gAlice->GetMCApp()->GetNtrack();
397     if (label>ntracks) return;
398     for (Int_t i=0;i<10;i++){
399       //    if (label<0) break;
400       if (lab[i]==label) break;
401       if (lab[i]<0) {
402         lab[i]= label;
403         break;
404       }
405     }
406   }
407 }
408
409 void AliITSclustererV2::RecPoints2Clusters
410 (const TClonesArray *points, Int_t idx, TClonesArray *clusters) {
411   //------------------------------------------------------------
412   // Conversion AliITSRecPoint -> AliITSclusterV2 for the ITS 
413   // subdetector indexed by idx 
414   //------------------------------------------------------------
415   TClonesArray &cl=*clusters;
416   Int_t ncl=points->GetEntriesFast();
417   for (Int_t i=0; i<ncl; i++) {
418     AliITSRecPoint *p = (AliITSRecPoint *)points->UncheckedAt(i);
419     Float_t lp[5];
420     lp[0]=-(-p->GetDetLocalX()+fYshift[idx]); if (idx<=fLastSPD1) lp[0]*=-1; //SPD1
421     lp[1]=  -p->GetZ()+fZshift[idx];
422     lp[2]=p->GetSigmaDetLocX2();
423     lp[3]=p->GetSigmaZ2();
424     lp[4]=p->GetQ()*36./23333.;  //electrons -> ADC
425     Int_t lab[4]; 
426     lab[0]=p->GetLabel(0); lab[1]=p->GetLabel(1); lab[2]=p->GetLabel(2);
427     lab[3]=fNdet[idx];
428     CheckLabels(lab);
429     Int_t dummy[3]={0,0,0};
430     new (cl[i]) AliITSclusterV2(lab,lp, dummy);
431   }  
432
433
434 //***********************************
435
436
437 void AliITSclustererV2:: 
438 FindCluster(Int_t k,Int_t maxz,AliBin *bins,Int_t &n,Int_t *idx) {
439   //------------------------------------------------------------
440   // returns an array of indices of digits belonging to the cluster
441   // (needed when the segmentation is not regular) 
442   //------------------------------------------------------------
443   if (n<200) idx[n++]=bins[k].GetIndex();
444   bins[k].Use();
445
446   if (bins[k-maxz].IsNotUsed()) FindCluster(k-maxz,maxz,bins,n,idx);
447   if (bins[k-1   ].IsNotUsed()) FindCluster(k-1   ,maxz,bins,n,idx);
448   if (bins[k+maxz].IsNotUsed()) FindCluster(k+maxz,maxz,bins,n,idx);
449   if (bins[k+1   ].IsNotUsed()) FindCluster(k+1   ,maxz,bins,n,idx);
450   /*
451   if (bins[k-maxz-1].IsNotUsed()) FindCluster(k-maxz-1,maxz,bins,n,idx);
452   if (bins[k-maxz+1].IsNotUsed()) FindCluster(k-maxz+1,maxz,bins,n,idx);
453   if (bins[k+maxz-1].IsNotUsed()) FindCluster(k+maxz-1,maxz,bins,n,idx);
454   if (bins[k+maxz+1].IsNotUsed()) FindCluster(k+maxz+1,maxz,bins,n,idx);
455   */
456 }
457
458 void AliITSclustererV2::
459 FindClustersSPD(const TClonesArray *digits, TClonesArray *clusters) {
460   //------------------------------------------------------------
461   // Actual SPD cluster finder
462   //------------------------------------------------------------
463   Int_t kNzBins = fNzSPD + 2;
464   const Int_t kMAXBIN=kNzBins*(fNySPD+2);
465
466   Int_t ndigits=digits->GetEntriesFast();
467   AliBin *bins=new AliBin[kMAXBIN];
468
469   Int_t k;
470   AliITSdigitSPD *d=0;
471   for (k=0; k<ndigits; k++) {
472      d=(AliITSdigitSPD*)digits->UncheckedAt(k);
473      Int_t i=d->GetCoord2()+1;   //y
474      Int_t j=d->GetCoord1()+1;
475      bins[i*kNzBins+j].SetIndex(k);
476      bins[i*kNzBins+j].SetMask(1);
477   }
478    
479   Int_t n=0; TClonesArray &cl=*clusters;
480   for (k=0; k<kMAXBIN; k++) {
481      if (!bins[k].IsNotUsed()) continue;
482      Int_t ni=0, idx[200];
483      FindCluster(k,kNzBins,bins,ni,idx);
484      if (ni==200) {
485         Info("FindClustersSPD","Too big cluster !"); 
486         continue;
487      }
488      Int_t milab[10];
489      for (Int_t ilab=0;ilab<10;ilab++){
490        milab[ilab]=-2;
491      }
492
493      d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
494      Int_t ymin=d->GetCoord2(),ymax=ymin;
495      Int_t zmin=d->GetCoord1(),zmax=zmin;
496
497      for (Int_t l=0; l<ni; l++) {
498         d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
499
500         if (ymin > d->GetCoord2()) ymin=d->GetCoord2();
501         if (ymax < d->GetCoord2()) ymax=d->GetCoord2();
502         if (zmin > d->GetCoord1()) zmin=d->GetCoord1();
503         if (zmax < d->GetCoord1()) zmax=d->GetCoord1();
504         // MI addition - find all labels in cluster
505         for (Int_t dlab=0;dlab<10;dlab++){
506           Int_t digitlab = (d->GetTracks())[dlab];
507           if (digitlab<0) continue;
508           AddLabel(milab,digitlab);       
509         }
510         if (milab[9]>0) CheckLabels2(milab);
511      }
512      CheckLabels2(milab);
513      //
514      //Int_t idy = (fNlayer[fI]==0)? 2:3; 
515      //for (Int_t iz=zmin; iz<=zmax;iz+=2)
516      //Int_t idy = (ymax-ymin)/4.; // max 2 clusters
517      Int_t idy = 0; // max 2 clusters
518      if (fNlayer[fI]==0 &&idy<3) idy=3;
519      if (fNlayer[fI]==1 &&idy<4) idy=4; 
520      Int_t idz =3;
521      for (Int_t iz=zmin; iz<=zmax;iz+=idz)
522        for (Int_t iy=ymin; iy<=ymax;iy+=idy){
523          //
524          Int_t ndigits =0;
525          Float_t y=0.,z=0.,q=0.;         
526          for (Int_t l=0; l<ni; l++) {
527            d=(AliITSdigitSPD*)digits->UncheckedAt(idx[l]);
528            if (zmax-zmin>=idz || ymax-ymin>=idy){
529              if (TMath::Abs( d->GetCoord2()-iy)>0.75*idy) continue;
530              if (TMath::Abs( d->GetCoord1()-iz)>0.75*idz) continue;
531            }
532            ndigits++;
533            Float_t qq=d->GetSignal();
534            y+=qq*fYSPD[d->GetCoord2()]; z+=qq*fZSPD[d->GetCoord1()]; q+=qq;   
535           
536          }     
537          if (ndigits==0) continue;
538          y/=q; z/=q;
539          y-=fHwSPD; z-=fHlSPD;
540          
541          Float_t lp[5];
542          lp[0]=-(-y+fYshift[fI]); if (fI<=fLastSPD1) lp[0]=-lp[0];
543          lp[1]=  -z+fZshift[fI];
544          // Float_t factor=TMath::Max(double(ni-3.),1.5);
545          Float_t factory=TMath::Max(ymax-ymin,1);
546          Float_t factorz=TMath::Max(zmax-zmin,1);
547          factory*= factory;
548          factorz*= factorz;     
549          //lp[2]= (fYpitchSPD*fYpitchSPD/12.)*factory;
550          //lp[3]= (fZ1pitchSPD*fZ1pitchSPD/12.)*factorz;
551          lp[2]= (fYpitchSPD*fYpitchSPD/12.);
552          lp[3]= (fZ1pitchSPD*fZ1pitchSPD/12.);
553          //lp[4]= q;
554          lp[4]= (zmax-zmin+1)*100 + (ymax-ymin+1);
555          
556          milab[3]=fNdet[fI];
557          d=(AliITSdigitSPD*)digits->UncheckedAt(idx[0]);
558          Int_t info[3] = {ymax-ymin+1,zmax-zmin+1,fNlayer[fI]};
559          new (cl[n]) AliITSclusterV2(milab,lp,info); n++;        
560        }
561   }
562   
563   delete [] bins;
564 }
565
566 void AliITSclustererV2::FindClustersSPD(AliITSRawStream* input, 
567                                         TClonesArray** clusters) 
568 {
569   //------------------------------------------------------------
570   // Actual SPD cluster finder for raw data
571   //------------------------------------------------------------
572
573   Int_t nClustersSPD = 0;
574   Int_t kNzBins = fNzSPD + 2;
575   Int_t kNyBins = fNySPD + 2;
576   Int_t kMaxBin = kNzBins * kNyBins;
577   AliBin *binsSPD = new AliBin[kMaxBin];
578   AliBin *binsSPDInit = new AliBin[kMaxBin];
579   AliBin *bins = NULL;
580
581   // read raw data input stream
582   while (kTRUE) {
583     Bool_t next = input->Next();
584     if (!next || input->IsNewModule()) {
585       Int_t iModule = input->GetPrevModuleID();
586
587       // when all data from a module was read, search for clusters
588       if (bins) { 
589         clusters[iModule] = new TClonesArray("AliITSclusterV2");
590         Int_t nClusters = 0;
591
592         for (Int_t iBin = 0; iBin < kMaxBin; iBin++) {
593           if (bins[iBin].IsUsed()) continue;
594           Int_t nBins = 0;
595           Int_t idxBins[200];
596           FindCluster(iBin, kNzBins, bins, nBins, idxBins);
597           if (nBins == 200) {
598             Error("FindClustersSPD", "SPD: Too big cluster !\n"); 
599             continue;
600           }
601
602           Int_t label[4]; 
603           label[0] = -2;
604           label[1] = -2;
605           label[2] = -2;
606 //        label[3] = iModule;
607           label[3] = fNdet[iModule];
608
609           Int_t ymin = (idxBins[0] / kNzBins) - 1;
610           Int_t ymax = ymin;
611           Int_t zmin = (idxBins[0] % kNzBins) - 1;
612           Int_t zmax = zmin;
613           for (Int_t idx = 0; idx < nBins; idx++) {
614             Int_t iy = (idxBins[idx] / kNzBins) - 1;
615             Int_t iz = (idxBins[idx] % kNzBins) - 1;
616             if (ymin > iy) ymin = iy;
617             if (ymax < iy) ymax = iy;
618             if (zmin > iz) zmin = iz;
619             if (zmax < iz) zmax = iz;
620           }
621
622           Int_t idy = 0; // max 2 clusters
623           if ((iModule <= fLastSPD1) &&idy<3) idy=3;
624           if ((iModule > fLastSPD1) &&idy<4) idy=4; 
625           Int_t idz =3;
626           for (Int_t iiz=zmin; iiz<=zmax;iiz+=idz)
627             for (Int_t iiy=ymin; iiy<=ymax;iiy+=idy){
628               //
629               Int_t ndigits =0;
630               Float_t y=0.,z=0.,q=0.;    
631               for (Int_t idx = 0; idx < nBins; idx++) {
632                 Int_t iy = (idxBins[idx] / kNzBins) - 1;
633                 Int_t iz = (idxBins[idx] % kNzBins) - 1;
634                 if (zmax-zmin>=idz || ymax-ymin>=idy){
635                   if (TMath::Abs(iy-iiy)>0.75*idy) continue;
636                   if (TMath::Abs(iz-iiz)>0.75*idz) continue;
637                 }
638                 ndigits++;
639                 Float_t qBin = bins[idxBins[idx]].GetQ();
640                 y += qBin * fYSPD[iy]; 
641                 z += qBin * fZSPD[iz]; 
642                 q += qBin;   
643               }
644               if (ndigits==0) continue;
645               y /= q; 
646               z /= q;
647               y -= fHwSPD; 
648               z -= fHlSPD;
649
650               Float_t hit[5];  // y, z, sigma(y)^2, sigma(z)^2, charge
651               hit[0] = -(-y+fYshift[iModule]); 
652               if (iModule <= fLastSPD1) hit[0] = -hit[0];
653               hit[1] = -z+fZshift[iModule];
654               hit[2] = fYpitchSPD*fYpitchSPD/12.;
655               hit[3] = fZ1pitchSPD*fZ1pitchSPD/12.;
656               //          hit[4] = q;
657               hit[4] = (zmax-zmin+1)*100 + (ymax-ymin+1);
658               //          CheckLabels(label);
659               Int_t info[3]={ymax-ymin+1,zmax-zmin+1,fNlayer[iModule]};
660               new (clusters[iModule]->AddrAt(nClusters)) 
661                 AliITSclusterV2(label, hit,info); 
662               nClusters++;
663             }
664         }
665
666         nClustersSPD += nClusters;
667         bins = NULL;
668       }
669
670       if (!next) break;
671       bins = binsSPD;
672       memcpy(binsSPD,binsSPDInit,sizeof(AliBin)*kMaxBin);
673     }
674
675     // fill the current digit into the bins array
676     Int_t index = (input->GetCoord2()+1) * kNzBins + (input->GetCoord1()+1);
677     bins[index].SetIndex(index);
678     bins[index].SetMask(1);
679     bins[index].SetQ(1);
680   }
681
682   delete [] binsSPDInit;
683   delete [] binsSPD;
684
685   Info("FindClustersSPD", "found clusters in ITS SPD: %d", nClustersSPD);
686 }
687
688
689 Bool_t AliITSclustererV2::IsMaximum(Int_t k,Int_t max,const AliBin *bins) {
690   //------------------------------------------------------------
691   //is this a local maximum ?
692   //------------------------------------------------------------
693   UShort_t q=bins[k].GetQ();
694   if (q==1023) return kFALSE;
695   if (bins[k-max].GetQ() > q) return kFALSE;
696   if (bins[k-1  ].GetQ() > q) return kFALSE; 
697   if (bins[k+max].GetQ() > q) return kFALSE; 
698   if (bins[k+1  ].GetQ() > q) return kFALSE; 
699   if (bins[k-max-1].GetQ() > q) return kFALSE;
700   if (bins[k+max-1].GetQ() > q) return kFALSE; 
701   if (bins[k+max+1].GetQ() > q) return kFALSE; 
702   if (bins[k-max+1].GetQ() > q) return kFALSE;
703   return kTRUE; 
704 }
705
706 void AliITSclustererV2::
707 FindPeaks(Int_t k,Int_t max,AliBin *b,Int_t *idx,UInt_t *msk,Int_t& n) {
708   //------------------------------------------------------------
709   //find local maxima
710   //------------------------------------------------------------
711   if (n<31)
712   if (IsMaximum(k,max,b)) {
713     idx[n]=k; msk[n]=(2<<n);
714     n++;
715   }
716   b[k].SetMask(0);
717   if (b[k-max].GetMask()&1) FindPeaks(k-max,max,b,idx,msk,n);
718   if (b[k-1  ].GetMask()&1) FindPeaks(k-1  ,max,b,idx,msk,n);
719   if (b[k+max].GetMask()&1) FindPeaks(k+max,max,b,idx,msk,n);
720   if (b[k+1  ].GetMask()&1) FindPeaks(k+1  ,max,b,idx,msk,n);
721 }
722
723 void AliITSclustererV2::
724 MarkPeak(Int_t k, Int_t max, AliBin *bins, UInt_t m) {
725   //------------------------------------------------------------
726   //mark this peak
727   //------------------------------------------------------------
728   UShort_t q=bins[k].GetQ();
729
730   bins[k].SetMask(bins[k].GetMask()|m); 
731
732   if (bins[k-max].GetQ() <= q)
733      if ((bins[k-max].GetMask()&m) == 0) MarkPeak(k-max,max,bins,m);
734   if (bins[k-1  ].GetQ() <= q)
735      if ((bins[k-1  ].GetMask()&m) == 0) MarkPeak(k-1  ,max,bins,m);
736   if (bins[k+max].GetQ() <= q)
737      if ((bins[k+max].GetMask()&m) == 0) MarkPeak(k+max,max,bins,m);
738   if (bins[k+1  ].GetQ() <= q)
739      if ((bins[k+1  ].GetMask()&m) == 0) MarkPeak(k+1  ,max,bins,m);
740 }
741
742 void AliITSclustererV2::
743 MakeCluster(Int_t k,Int_t max,AliBin *bins,UInt_t m,AliITSclusterV2 &c) {
744   //------------------------------------------------------------
745   //make cluster using digits of this peak
746   //------------------------------------------------------------
747   Float_t q=(Float_t)bins[k].GetQ();
748   Int_t i=k/max, j=k-i*max;
749
750   c.SetQ(c.GetQ()+q);
751   c.SetY(c.GetY()+i*q); 
752   c.SetZ(c.GetZ()+j*q); 
753   c.SetSigmaY2(c.GetSigmaY2()+i*i*q);
754   c.SetSigmaZ2(c.GetSigmaZ2()+j*j*q);
755
756   bins[k].SetMask(0xFFFFFFFE);
757   
758   if (bins[k-max].GetMask() == m) MakeCluster(k-max,max,bins,m,c);
759   if (bins[k-1  ].GetMask() == m) MakeCluster(k-1  ,max,bins,m,c);
760   if (bins[k+max].GetMask() == m) MakeCluster(k+max,max,bins,m,c);
761   if (bins[k+1  ].GetMask() == m) MakeCluster(k+1  ,max,bins,m,c);
762 }
763
764 void AliITSclustererV2::
765 FindClustersSDD(AliBin* bins[2], Int_t nMaxBin, Int_t nzBins, 
766                 const TClonesArray *digits, TClonesArray *clusters) {
767   //------------------------------------------------------------
768   // Actual SDD cluster finder
769   //------------------------------------------------------------
770   Int_t ncl=0; TClonesArray &cl=*clusters;
771   for (Int_t s=0; s<2; s++)
772     for (Int_t i=0; i<nMaxBin; i++) {
773       if (bins[s][i].IsUsed()) continue;
774       Int_t idx[32]; UInt_t msk[32]; Int_t npeaks=0;
775       FindPeaks(i, nzBins, bins[s], idx, msk, npeaks);
776
777       if (npeaks>30) continue;
778       if (npeaks==0) continue;
779
780       Int_t k,l;
781       for (k=0; k<npeaks-1; k++){//mark adjacent peaks
782         if (idx[k] < 0) continue; //this peak is already removed
783         for (l=k+1; l<npeaks; l++) {
784            if (idx[l] < 0) continue; //this peak is already removed
785            Int_t ki=idx[k]/nzBins, kj=idx[k] - ki*nzBins;
786            Int_t li=idx[l]/nzBins, lj=idx[l] - li*nzBins;
787            Int_t di=TMath::Abs(ki - li);
788            Int_t dj=TMath::Abs(kj - lj);
789            if (di>1 || dj>1) continue;
790            if (bins[s][idx[k]].GetQ() > bins[s][idx[l]].GetQ()) {
791               msk[l]=msk[k];
792               idx[l]*=-1;
793            } else {
794               msk[k]=msk[l];
795               idx[k]*=-1;
796               break;
797            } 
798         }
799       }
800
801       for (k=0; k<npeaks; k++) {
802         MarkPeak(TMath::Abs(idx[k]), nzBins, bins[s], msk[k]);
803       }
804         
805       for (k=0; k<npeaks; k++) {
806          if (idx[k] < 0) continue; //removed peak
807          AliITSclusterV2 c;
808          MakeCluster(idx[k], nzBins, bins[s], msk[k], c);
809          //mi change
810          Int_t milab[10];
811          for (Int_t ilab=0;ilab<10;ilab++){
812            milab[ilab]=-2;
813          }
814          Int_t maxi=0,mini=0,maxj=0,minj=0;
815          //AliBin *bmax=&bins[s][idx[k]];
816          //Float_t max = TMath::Max(TMath::Abs(bmax->GetQ())/5.,3.);
817          Float_t max=3;
818          for (Int_t di=-2; di<=2;di++)
819            for (Int_t dj=-3;dj<=3;dj++){
820              Int_t index = idx[k]+di+dj*nzBins;
821              if (index<0) continue;
822              if (index>=nMaxBin) continue;
823              AliBin *b=&bins[s][index];
824              if (TMath::Abs(b->GetQ())>max){
825                if (di>maxi) maxi=di;
826                if (di<mini) mini=di;
827                if (dj>maxj) maxj=dj;
828                if (dj<minj) minj=dj;
829                //
830                if(digits) {
831                  if (TMath::Abs(di)<2&&TMath::Abs(dj)<2){
832                    AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
833                    for (Int_t itrack=0;itrack<10;itrack++){
834                      Int_t track = (d->GetTracks())[itrack];
835                      if (track>=0) {
836                        AddLabel(milab, track); 
837                      }
838                    }
839                  }
840                }
841              }
842            }
843          
844          /* 
845             Float_t s2 = c.GetSigmaY2()/c.GetQ() - c.GetY()*c.GetY();
846             Float_t w=par->GetPadPitchWidth(sec);
847             c.SetSigmaY2(s2);
848             if (s2 != 0.) {
849             c.SetSigmaY2(c.GetSigmaY2()*0.108);
850             if (sec<par->GetNInnerSector()) c.SetSigmaY2(c.GetSigmaY2()*2.07);
851             }    
852             s2 = c.GetSigmaZ2()/c.GetQ() - c.GetZ()*c.GetZ();
853             w=par->GetZWidth();
854             c.SetSigmaZ2(s2);
855             
856             if (s2 != 0.) {
857             c.SetSigmaZ2(c.GetSigmaZ2()*0.169);
858             if (sec<par->GetNInnerSector()) c.SetSigmaZ2(c.GetSigmaZ2()*1.77);
859             }
860          */
861
862          Float_t y=c.GetY(),z=c.GetZ(), q=c.GetQ();
863          y/=q; z/=q;
864          //
865          //Float_t s2 = c.GetSigmaY2()/c.GetQ() - y*y;
866          // c.SetSigmaY2(s2);
867          //s2 = c.GetSigmaZ2()/c.GetQ() - z*z;
868          //c.SetSigmaZ2(s2);
869          //
870          y=(y-0.5)*fYpitchSDD;
871          y-=fHwSDD;
872          y-=fYoffSDD;  //delay ?
873          if (s) y=-y;
874
875          z=(z-0.5)*fZpitchSDD;
876          z-=fHlSDD;
877
878          y=-(-y+fYshift[fI]);
879          z=  -z+fZshift[fI];
880
881          q/=12.7;  //this WAS consistent with SSD. To be reassessed 
882                    // 23-MAR-2007
883          Float_t hit[5] = {y, z, 0.0030*0.0030, 0.0020*0.0020, q};
884          Int_t  info[3] = {maxj-minj+1, maxi-mini+1, fNlayer[fI]};
885
886          if (c.GetQ() < 20.) continue; //noise cluster
887          
888          if (digits) {    
889            //      AliBin *b=&bins[s][idx[k]];
890            //      AliITSdigitSDD* d=(AliITSdigitSDD*)digits->UncheckedAt(b->GetIndex());
891            {
892              //Int_t lab[3];
893              //lab[0]=(d->GetTracks())[0];
894              //lab[1]=(d->GetTracks())[1];
895              //lab[2]=(d->GetTracks())[2];
896              //CheckLabels(lab);
897              CheckLabels2(milab); 
898            }
899          }
900          milab[3]=fNdet[fI];
901
902          AliITSclusterV2 *cc = new (cl[ncl]) AliITSclusterV2(milab,hit,info);
903          cc->SetType(npeaks); 
904          ncl++;
905       }
906     }
907 }
908
909 void AliITSclustererV2::
910 FindClustersSDD(const TClonesArray *digits, TClonesArray *clusters) {
911   //------------------------------------------------------------
912   // Actual SDD cluster finder
913   //------------------------------------------------------------
914   Int_t kNzBins = fNzSDD + 2;
915   const Int_t kMAXBIN=kNzBins*(fNySDD+2);
916
917   AliBin *bins[2];
918   bins[0]=new AliBin[kMAXBIN];
919   bins[1]=new AliBin[kMAXBIN];
920
921   AliITSdigitSDD *d=0;
922   Int_t i, ndigits=digits->GetEntriesFast();
923   for (i=0; i<ndigits; i++) {
924      d=(AliITSdigitSDD*)digits->UncheckedAt(i);
925      Int_t y=d->GetCoord2()+1;   //y
926      Int_t z=d->GetCoord1()+1;   //z
927      Int_t q=d->GetSignal();
928      if (q<3) continue;
929
930      if (z <= fNzSDD) {
931        bins[0][y*kNzBins+z].SetQ(q);
932        bins[0][y*kNzBins+z].SetMask(1);
933        bins[0][y*kNzBins+z].SetIndex(i);
934      } else {
935        z-=fNzSDD; 
936        bins[1][y*kNzBins+z].SetQ(q);
937        bins[1][y*kNzBins+z].SetMask(1);
938        bins[1][y*kNzBins+z].SetIndex(i);
939      }
940   }
941   
942   FindClustersSDD(bins, kMAXBIN, kNzBins, digits, clusters);
943
944   delete[] bins[0];
945   delete[] bins[1];
946
947 }
948
949 void AliITSclustererV2::FindClustersSDD(AliITSRawStream* input, 
950                                         TClonesArray** clusters) 
951 {
952   //------------------------------------------------------------
953   // Actual SDD cluster finder for raw data
954   //------------------------------------------------------------
955   Int_t nClustersSDD = 0;
956   Int_t kNzBins = fNzSDD + 2;
957   Int_t kMaxBin = kNzBins * (fNySDD+2);
958   AliBin *binsSDDInit = new AliBin[kMaxBin];
959   AliBin *binsSDD1 = new AliBin[kMaxBin];
960   AliBin *binsSDD2 = new AliBin[kMaxBin];
961   AliBin *bins[2] = {NULL, NULL};
962
963   // read raw data input stream
964   while (kTRUE) {
965     Bool_t next = input->Next();
966     if (!next || input->IsNewModule()) {
967       Int_t iModule = input->GetPrevModuleID();
968
969       // when all data from a module was read, search for clusters
970       if (bins[0]) { 
971         clusters[iModule] = new TClonesArray("AliITSclusterV2");
972         fI = iModule;
973         FindClustersSDD(bins, kMaxBin, kNzBins, NULL, clusters[iModule]);
974         Int_t nClusters = clusters[iModule]->GetEntriesFast();
975         nClustersSDD += nClusters;
976         bins[0] = bins[1] = NULL;
977       }
978
979       if (!next) break;
980       bins[0]=binsSDD1;
981       bins[1]=binsSDD2;
982       memcpy(binsSDD1,binsSDDInit,sizeof(AliBin)*kMaxBin);
983       memcpy(binsSDD2,binsSDDInit,sizeof(AliBin)*kMaxBin);
984     }
985
986     // fill the current digit into the bins array
987     if(input->GetSignal()>=3) {
988       Int_t iz = input->GetCoord1()+1;
989       Int_t side = ((iz <= fNzSDD) ? 0 : 1);
990       iz -= side*fNzSDD;
991       Int_t index = (input->GetCoord2()+1) * kNzBins + iz;
992       bins[side][index].SetQ(input->GetSignal());
993       bins[side][index].SetMask(1);
994       bins[side][index].SetIndex(index);
995     }
996   }
997
998   delete[] binsSDD1;
999   delete[] binsSDD2;
1000   delete[] binsSDDInit;
1001
1002   Info("FindClustersSDD", "found clusters in ITS SDD: %d", nClustersSDD);
1003 }
1004
1005
1006
1007 void AliITSclustererV2::
1008 FindClustersSSD(Ali1Dcluster* neg, Int_t nn, 
1009                 Ali1Dcluster* pos, Int_t np,
1010                 TClonesArray *clusters) {
1011   //------------------------------------------------------------
1012   // Actual SSD cluster finder
1013   //------------------------------------------------------------
1014   TClonesArray &cl=*clusters;
1015   //
1016   Float_t tanp=fTanP, tann=fTanN;
1017   if (fI>fLastSSD1) {tann=fTanP; tanp=fTanN;}
1018   Int_t idet=fNdet[fI];
1019   Int_t ncl=0;
1020   //
1021   Int_t negativepair[30000];
1022   Int_t cnegative[3000];  
1023   Int_t cused1[3000];
1024   Int_t positivepair[30000];
1025   Int_t cpositive[3000];
1026   Int_t cused2[3000];
1027   for (Int_t i=0;i<3000;i++) {cnegative[i]=0; cused1[i]=0;}
1028   for (Int_t i=0;i<3000;i++) {cpositive[i]=0; cused2[i]=0;}
1029   for (Int_t i=0;i<30000;i++){negativepair[i]=positivepair[i]=0;}
1030   static Short_t pairs[1000][1000];
1031   memset(pairs,0,sizeof(Short_t)*1000000);
1032 //   Short_t ** pairs = new Short_t*[1000];
1033 //   for (Int_t i=0; i<1000; i++) {
1034 //     pairs[i] = new Short_t[1000];
1035 //     memset(pairs[i],0,sizeof(Short_t)*1000);
1036 //   }  
1037   //
1038   // find available pairs
1039   //
1040   for (Int_t i=0; i<np; i++) {
1041     Float_t yp=pos[i].GetY()*fYpitchSSD; 
1042     if (pos[i].GetQ()<3) continue;
1043     for (Int_t j=0; j<nn; j++) {
1044       if (neg[j].GetQ()<3) continue;
1045       Float_t yn=neg[j].GetY()*fYpitchSSD;
1046       Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1047       Float_t yt=yn + tann*zt;
1048       zt-=fHlSSD; yt-=fHwSSD;
1049       if (TMath::Abs(yt)<fHwSSD+0.01)
1050       if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1051         negativepair[i*10+cnegative[i]] =j;  //index
1052         positivepair[j*10+cpositive[j]] =i;
1053         cnegative[i]++;  //counters
1054         cpositive[j]++; 
1055         pairs[i][j]=100;
1056       }
1057     }
1058   }
1059   //
1060   for (Int_t i=0; i<np; i++) {
1061     Float_t yp=pos[i].GetY()*fYpitchSSD; 
1062     if (pos[i].GetQ()<3) continue;
1063     for (Int_t j=0; j<nn; j++) {
1064       if (neg[j].GetQ()<3) continue;
1065       if (cpositive[j]&&cnegative[i]) continue;
1066       Float_t yn=neg[j].GetY()*fYpitchSSD;
1067       Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1068       Float_t yt=yn + tann*zt;
1069       zt-=fHlSSD; yt-=fHwSSD;
1070       if (TMath::Abs(yt)<fHwSSD+0.1)
1071       if (TMath::Abs(zt)<fHlSSD+0.15) {
1072         if (cnegative[i]==0) pos[i].SetNd(100);  // not available pair
1073         if (cpositive[j]==0) neg[j].SetNd(100);  // not available pair
1074         negativepair[i*10+cnegative[i]] =j;  //index
1075         positivepair[j*10+cpositive[j]] =i;
1076         cnegative[i]++;  //counters
1077         cpositive[j]++; 
1078         pairs[i][j]=100;
1079       }
1080     }
1081   }
1082   //
1083   Float_t lp[5];
1084   Int_t milab[10];
1085   Double_t ratio;
1086   
1087   //
1088   // sign gold tracks
1089   //
1090   for (Int_t ip=0;ip<np;ip++){
1091     Float_t ybest=1000,zbest=1000,qbest=0;
1092     //
1093     // select gold clusters
1094     if ( (cnegative[ip]==1) && cpositive[negativepair[10*ip]]==1){ 
1095       Float_t yp=pos[ip].GetY()*fYpitchSSD; 
1096       Int_t j = negativepair[10*ip];      
1097       ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1098       //
1099       Float_t yn=neg[j].GetY()*fYpitchSSD;
1100       Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1101       Float_t yt=yn + tann*zt;
1102       zt-=fHlSSD; yt-=fHwSSD;
1103       ybest=yt; zbest=zt; 
1104       qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1105       lp[0]=-(-ybest+fYshift[fI]);
1106       lp[1]=  -zbest+fZshift[fI];
1107       lp[2]=0.0025*0.0025;  //SigmaY2
1108       lp[3]=0.110*0.110;  //SigmaZ2
1109       
1110       lp[4]=qbest;        //Q
1111       for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1112       for (Int_t ilab=0;ilab<3;ilab++){
1113         milab[ilab] = pos[ip].GetLabel(ilab);
1114         milab[ilab+3] = neg[j].GetLabel(ilab);
1115       }
1116       //
1117       CheckLabels2(milab);
1118       milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1119       Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1120       AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1121       ncl++;
1122       cl2->SetChargeRatio(ratio);       
1123       cl2->SetType(1);
1124       pairs[ip][j]=1;
1125       if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1126         cl2->SetType(2);
1127         pairs[ip][j]=2;
1128       }
1129       cused1[ip]++;
1130       cused2[j]++;
1131     }
1132   }
1133     
1134   for (Int_t ip=0;ip<np;ip++){
1135     Float_t ybest=1000,zbest=1000,qbest=0;
1136     //
1137     //
1138     // select "silber" cluster
1139     if ( cnegative[ip]==1 && cpositive[negativepair[10*ip]]==2){
1140       Int_t in  = negativepair[10*ip];
1141       Int_t ip2 = positivepair[10*in];
1142       if (ip2==ip) ip2 =  positivepair[10*in+1];
1143       Float_t pcharge = pos[ip].GetQ()+pos[ip2].GetQ();
1144       if (TMath::Abs(pcharge-neg[in].GetQ())<10){
1145         //
1146         // add first pair
1147         if (pairs[ip][in]==100){  //
1148           Float_t yp=pos[ip].GetY()*fYpitchSSD; 
1149           Float_t yn=neg[in].GetY()*fYpitchSSD;
1150           Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1151           Float_t yt=yn + tann*zt;
1152           zt-=fHlSSD; yt-=fHwSSD;
1153           ybest =yt;  zbest=zt; 
1154           qbest =pos[ip].GetQ();
1155           lp[0]=-(-ybest+fYshift[fI]);
1156           lp[1]=  -zbest+fZshift[fI];
1157           lp[2]=0.0025*0.0025;  //SigmaY2
1158           lp[3]=0.110*0.110;  //SigmaZ2
1159           
1160           lp[4]=qbest;        //Q
1161           for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1162           for (Int_t ilab=0;ilab<3;ilab++){
1163             milab[ilab] = pos[ip].GetLabel(ilab);
1164             milab[ilab+3] = neg[in].GetLabel(ilab);
1165           }
1166           //
1167           CheckLabels2(milab);
1168           ratio = (pos[ip].GetQ()-neg[in].GetQ())/(pos[ip].GetQ()+neg[in].GetQ());
1169           milab[3]=(((ip<<10) + in)<<10) + idet; // pos|neg|det
1170           Int_t info[3] = {pos[ip].GetNd(),neg[in].GetNd(),fNlayer[fI]};
1171           AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1172           ncl++;
1173           cl2->SetChargeRatio(ratio);           
1174           cl2->SetType(5);
1175           pairs[ip][in] = 5;
1176           if ((pos[ip].GetNd()+neg[in].GetNd())>6){ //multi cluster
1177             cl2->SetType(6);
1178             pairs[ip][in] = 6;
1179           }
1180         }
1181         //
1182         // add second pair
1183         
1184         //      if (!(cused1[ip2] || cused2[in])){  //
1185         if (pairs[ip2][in]==100){
1186           Float_t yp=pos[ip2].GetY()*fYpitchSSD;
1187           Float_t yn=neg[in].GetY()*fYpitchSSD;
1188           Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1189           Float_t yt=yn + tann*zt;
1190           zt-=fHlSSD; yt-=fHwSSD;
1191           ybest =yt;  zbest=zt; 
1192           qbest =pos[ip2].GetQ();
1193           lp[0]=-(-ybest+fYshift[fI]);
1194           lp[1]=  -zbest+fZshift[fI];
1195           lp[2]=0.0025*0.0025;  //SigmaY2
1196           lp[3]=0.110*0.110;  //SigmaZ2
1197           
1198           lp[4]=qbest;        //Q
1199           for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1200           for (Int_t ilab=0;ilab<3;ilab++){
1201             milab[ilab] = pos[ip2].GetLabel(ilab);
1202             milab[ilab+3] = neg[in].GetLabel(ilab);
1203           }
1204           //
1205           CheckLabels2(milab);
1206           ratio = (pos[ip2].GetQ()-neg[in].GetQ())/(pos[ip2].GetQ()+neg[in].GetQ());
1207           milab[3]=(((ip2<<10) + in)<<10) + idet; // pos|neg|det
1208           Int_t info[3] = {pos[ip2].GetNd(),neg[in].GetNd(),fNlayer[fI]};
1209           AliITSclusterV2 *cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1210           ncl++;
1211           cl2->SetChargeRatio(ratio);           
1212           cl2->SetType(5);
1213           pairs[ip2][in] =5;
1214           if ((pos[ip2].GetNd()+neg[in].GetNd())>6){ //multi cluster
1215             cl2->SetType(6);
1216             pairs[ip2][in] =6;
1217           }
1218         }       
1219         cused1[ip]++;
1220         cused1[ip2]++;
1221         cused2[in]++;
1222       }
1223     }    
1224   }
1225   
1226   //  
1227   for (Int_t jn=0;jn<nn;jn++){
1228     if (cused2[jn]) continue;
1229     Float_t ybest=1000,zbest=1000,qbest=0;
1230     // select "silber" cluster
1231     if ( cpositive[jn]==1 && cnegative[positivepair[10*jn]]==2){
1232       Int_t ip  = positivepair[10*jn];
1233       Int_t jn2 = negativepair[10*ip];
1234       if (jn2==jn) jn2 =  negativepair[10*ip+1];
1235       Float_t pcharge = neg[jn].GetQ()+neg[jn2].GetQ();
1236       //
1237       if (TMath::Abs(pcharge-pos[ip].GetQ())<10){
1238         //
1239         // add first pair
1240         //      if (!(cused1[ip]||cused2[jn])){
1241         if (pairs[ip][jn]==100){
1242           Float_t yn=neg[jn].GetY()*fYpitchSSD; 
1243           Float_t yp=pos[ip].GetY()*fYpitchSSD;
1244           Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1245           Float_t yt=yn + tann*zt;
1246           zt-=fHlSSD; yt-=fHwSSD;
1247           ybest =yt;  zbest=zt; 
1248           qbest =neg[jn].GetQ();
1249           lp[0]=-(-ybest+fYshift[fI]);
1250           lp[1]=  -zbest+fZshift[fI];
1251           lp[2]=0.0025*0.0025;  //SigmaY2
1252           lp[3]=0.110*0.110;  //SigmaZ2
1253           
1254           lp[4]=qbest;        //Q
1255           for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1256           for (Int_t ilab=0;ilab<3;ilab++){
1257             milab[ilab] = pos[ip].GetLabel(ilab);
1258             milab[ilab+3] = neg[jn].GetLabel(ilab);
1259           }
1260           //
1261           CheckLabels2(milab);
1262           ratio = (pos[ip].GetQ()-neg[jn].GetQ())/(pos[ip].GetQ()+neg[jn].GetQ());
1263           milab[3]=(((ip<<10) + jn)<<10) + idet; // pos|neg|det
1264           Int_t info[3] = {pos[ip].GetNd(),neg[jn].GetNd(),fNlayer[fI]};
1265           AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1266           ncl++;
1267           cl2->SetChargeRatio(ratio);           
1268           cl2->SetType(7);
1269           pairs[ip][jn] =7;
1270           if ((pos[ip].GetNd()+neg[jn].GetNd())>6){ //multi cluster
1271             cl2->SetType(8);
1272             pairs[ip][jn]=8;
1273           }
1274         }
1275         //
1276         // add second pair
1277         //      if (!(cused1[ip]||cused2[jn2])){
1278         if (pairs[ip][jn2]==100){
1279           Float_t yn=neg[jn2].GetY()*fYpitchSSD; 
1280           Double_t yp=pos[ip].GetY()*fYpitchSSD; 
1281           Double_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1282           Double_t yt=yn + tann*zt;
1283           zt-=fHlSSD; yt-=fHwSSD;
1284           ybest =yt;  zbest=zt; 
1285           qbest =neg[jn2].GetQ();
1286           lp[0]=-(-ybest+fYshift[fI]);
1287           lp[1]=  -zbest+fZshift[fI];
1288           lp[2]=0.0025*0.0025;  //SigmaY2
1289           lp[3]=0.110*0.110;  //SigmaZ2
1290           
1291           lp[4]=qbest;        //Q
1292           for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1293           for (Int_t ilab=0;ilab<3;ilab++){
1294             milab[ilab] = pos[ip].GetLabel(ilab);
1295             milab[ilab+3] = neg[jn2].GetLabel(ilab);
1296           }
1297           //
1298           CheckLabels2(milab);
1299           ratio = (pos[ip].GetQ()-neg[jn2].GetQ())/(pos[ip].GetQ()+neg[jn2].GetQ());
1300           milab[3]=(((ip<<10) + jn2)<<10) + idet; // pos|neg|det
1301           Int_t info[3] = {pos[ip].GetNd(),neg[jn2].GetNd(),fNlayer[fI]};
1302           AliITSclusterV2* cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1303           ncl++;
1304           cl2->SetChargeRatio(ratio);           
1305           pairs[ip][jn2]=7;
1306           cl2->SetType(7);
1307           if ((pos[ip].GetNd()+neg[jn2].GetNd())>6){ //multi cluster
1308             cl2->SetType(8);
1309             pairs[ip][jn2]=8;
1310           }
1311         }
1312         cused1[ip]++;
1313         cused2[jn]++;
1314         cused2[jn2]++;
1315       }
1316     }    
1317   }
1318   
1319   for (Int_t ip=0;ip<np;ip++){
1320     Float_t ybest=1000,zbest=1000,qbest=0;
1321     //
1322     // 2x2 clusters
1323     //
1324     if ( (cnegative[ip]<5) && cpositive[negativepair[10*ip]]<5){ 
1325       Float_t minchargediff =4.;
1326       Int_t j=-1;
1327       for (Int_t di=0;di<cnegative[ip];di++){
1328         Int_t   jc = negativepair[ip*10+di];
1329         Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1330         if (TMath::Abs(chargedif)<minchargediff){
1331           j =jc;
1332           minchargediff = TMath::Abs(chargedif);
1333         }
1334       }
1335       if (j<0) continue;  // not proper cluster      
1336       Int_t count =0;
1337       for (Int_t di=0;di<cnegative[ip];di++){
1338         Int_t   jc = negativepair[ip*10+di];
1339         Float_t chargedif = pos[ip].GetQ()-neg[jc].GetQ();
1340         if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1341       }
1342       if (count>1) continue;  // more than one "proper" cluster for positive
1343       //
1344       count =0;
1345       for (Int_t dj=0;dj<cpositive[j];dj++){
1346         Int_t   ic  = positivepair[j*10+dj];
1347         Float_t chargedif = pos[ic].GetQ()-neg[j].GetQ();
1348         if (TMath::Abs(chargedif)<minchargediff+3.) count++;
1349       }
1350       if (count>1) continue;  // more than one "proper" cluster for negative
1351       
1352       Int_t jp = 0;
1353       
1354       count =0;
1355       for (Int_t dj=0;dj<cnegative[jp];dj++){
1356         Int_t   ic = positivepair[jp*10+dj];
1357         Float_t chargedif = pos[ic].GetQ()-neg[jp].GetQ();
1358         if (TMath::Abs(chargedif)<minchargediff+4.) count++;
1359       }
1360       if (count>1) continue;   
1361       if (pairs[ip][j]<100) continue;
1362       //
1363       //almost gold clusters
1364       Float_t yp=pos[ip].GetY()*fYpitchSSD; 
1365       Float_t yn=neg[j].GetY()*fYpitchSSD;
1366       Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1367       Float_t yt=yn + tann*zt;
1368       zt-=fHlSSD; yt-=fHwSSD;
1369       ybest=yt; zbest=zt; 
1370       qbest=0.5*(pos[ip].GetQ()+neg[j].GetQ());
1371       lp[0]=-(-ybest+fYshift[fI]);
1372       lp[1]=  -zbest+fZshift[fI];
1373       lp[2]=0.0025*0.0025;  //SigmaY2
1374       lp[3]=0.110*0.110;  //SigmaZ2     
1375       lp[4]=qbest;        //Q
1376       for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1377       for (Int_t ilab=0;ilab<3;ilab++){
1378         milab[ilab] = pos[ip].GetLabel(ilab);
1379         milab[ilab+3] = neg[j].GetLabel(ilab);
1380       }
1381       //
1382       CheckLabels2(milab);
1383       ratio = (pos[ip].GetQ()-neg[j].GetQ())/(pos[ip].GetQ()+neg[j].GetQ());
1384       milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
1385       Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1386       AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info);
1387       ncl++;
1388       cl2->SetChargeRatio(ratio);       
1389       cl2->SetType(10);
1390       pairs[ip][j]=10;
1391       if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
1392         cl2->SetType(11);
1393         pairs[ip][j]=11;
1394       }
1395       cused1[ip]++;
1396       cused2[j]++;      
1397     }
1398
1399   }
1400   
1401   //  
1402   for (Int_t i=0; i<np; i++) {
1403     Float_t ybest=1000,zbest=1000,qbest=0;
1404     Float_t yp=pos[i].GetY()*fYpitchSSD; 
1405     if (pos[i].GetQ()<3) continue;
1406     for (Int_t j=0; j<nn; j++) {
1407     //    for (Int_t di = 0;di<cpositive[i];di++){
1408     //  Int_t j = negativepair[10*i+di];
1409       if (neg[j].GetQ()<3) continue;
1410       if (cused2[j]||cused1[i]) continue;      
1411       if (pairs[i][j]>0 &&pairs[i][j]<100) continue;
1412       ratio = (pos[i].GetQ()-neg[j].GetQ())/(pos[i].GetQ()+neg[j].GetQ());      
1413       Float_t yn=neg[j].GetY()*fYpitchSSD;
1414       Float_t zt=(2*fHlSSD*tanp + yp - yn)/(tann+tanp);
1415       Float_t yt=yn + tann*zt;
1416       zt-=fHlSSD; yt-=fHwSSD;
1417       if (TMath::Abs(yt)<fHwSSD+0.01)
1418       if (TMath::Abs(zt)<fHlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
1419         ybest=yt; zbest=zt; 
1420         qbest=0.5*(pos[i].GetQ()+neg[j].GetQ());
1421         lp[0]=-(-ybest+fYshift[fI]);
1422         lp[1]=  -zbest+fZshift[fI];
1423         lp[2]=0.0025*0.0025;  //SigmaY2
1424         lp[3]=0.110*0.110;  //SigmaZ2
1425
1426         lp[4]=qbest;        //Q
1427         for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
1428         for (Int_t ilab=0;ilab<3;ilab++){
1429           milab[ilab] = pos[i].GetLabel(ilab);
1430           milab[ilab+3] = neg[j].GetLabel(ilab);
1431         }
1432         //
1433         CheckLabels2(milab);
1434         milab[3]=(((i<<10) + j)<<10) + idet; // pos|neg|det
1435         Int_t info[3] = {pos[i].GetNd(),neg[j].GetNd(),fNlayer[fI]};
1436         AliITSclusterV2 * cl2 = new (cl[ncl]) AliITSclusterV2(milab,lp,info); 
1437         ncl++;
1438         cl2->SetChargeRatio(ratio);
1439         cl2->SetType(100+cpositive[j]+cnegative[i]);
1440         //cl2->SetType(0);
1441         /*
1442           if (pairs[i][j]<100){
1443           printf("problem:- %d\n", pairs[i][j]);
1444           }
1445           if (cnegative[i]<2&&cpositive[j]<2){
1446           printf("problem:- %d\n", pairs[i][j]);
1447           }
1448         */
1449       }
1450     }
1451   }
1452
1453 //   for (Int_t i=0; i<1000; i++) delete [] pairs[i];
1454 //   delete [] pairs;
1455
1456 }
1457
1458
1459 void AliITSclustererV2::
1460 FindClustersSSD(const TClonesArray *alldigits, TClonesArray *clusters) {
1461   //------------------------------------------------------------
1462   // Actual SSD cluster finder
1463   //------------------------------------------------------------
1464   Int_t smaxall=alldigits->GetEntriesFast();
1465   if (smaxall==0) return;
1466   TObjArray *digits = new TObjArray;
1467   for (Int_t i=0;i<smaxall; i++){
1468     AliITSdigitSSD *d=(AliITSdigitSSD*)alldigits->UncheckedAt(i);
1469     if (d->GetSignal()<3) continue;
1470     digits->AddLast(d);
1471   }
1472   Int_t smax = digits->GetEntriesFast();
1473   if (smax==0) return;
1474   
1475   const Int_t MAX=1000;
1476   Int_t np=0, nn=0; 
1477   Ali1Dcluster pos[MAX], neg[MAX];
1478   Float_t y=0., q=0., qmax=0.; 
1479   Int_t lab[4]={-2,-2,-2,-2};
1480   
1481   AliITSdigitSSD *d=(AliITSdigitSSD*)digits->UncheckedAt(0);
1482   q += d->GetSignal();
1483   y += d->GetCoord2()*d->GetSignal();
1484   qmax=d->GetSignal();
1485   lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
1486   Int_t curr=d->GetCoord2();
1487   Int_t flag=d->GetCoord1();
1488   Int_t *n=&nn;
1489   Ali1Dcluster *c=neg;
1490   Int_t nd=1;
1491   Int_t milab[10];
1492   for (Int_t ilab=0;ilab<10;ilab++){
1493     milab[ilab]=-2;
1494   }
1495   milab[0]=d->GetTrack(0); milab[1]=d->GetTrack(1); milab[2]=d->GetTrack(2);
1496
1497   for (Int_t s=1; s<smax; s++) {
1498       d=(AliITSdigitSSD*)digits->UncheckedAt(s);      
1499       Int_t strip=d->GetCoord2();
1500       if ((strip-curr) > 1 || flag!=d->GetCoord1()) {
1501          c[*n].SetY(y/q);
1502          c[*n].SetQ(q);
1503          c[*n].SetNd(nd);
1504          CheckLabels2(milab);
1505          c[*n].SetLabels(milab);
1506          //Split suspiciously big cluster
1507          /*
1508          if (nd>10&&nd<16){
1509            c[*n].SetY(y/q-0.3*nd);
1510            c[*n].SetQ(0.5*q);
1511            (*n)++;
1512            if (*n==MAX) {
1513              Error("FindClustersSSD","Too many 1D clusters !");
1514               return;
1515            }
1516            c[*n].SetY(y/q-0.0*nd);
1517            c[*n].SetQ(0.5*q);
1518            c[*n].SetNd(nd);
1519            (*n)++;
1520            if (*n==MAX) {
1521              Error("FindClustersSSD","Too many 1D clusters !");
1522               return;
1523            }
1524            //
1525            c[*n].SetY(y/q+0.3*nd);
1526            c[*n].SetQ(0.5*q);
1527            c[*n].SetNd(nd);
1528            c[*n].SetLabels(milab);
1529          }
1530          else{
1531          */
1532          if (nd>4&&nd<25) {
1533            c[*n].SetY(y/q-0.25*nd);
1534            c[*n].SetQ(0.5*q);
1535            (*n)++;
1536            if (*n==MAX) {
1537              Error("FindClustersSSD","Too many 1D clusters !");
1538              return;
1539            }
1540            c[*n].SetY(y/q+0.25*nd);
1541            c[*n].SetQ(0.5*q);
1542            c[*n].SetNd(nd);
1543            c[*n].SetLabels(milab);
1544          }       
1545          (*n)++;
1546          if (*n==MAX) {
1547           Error("FindClustersSSD","Too many 1D clusters !");
1548           return;
1549          }
1550          y=q=qmax=0.;
1551          nd=0;
1552          lab[0]=lab[1]=lab[2]=-2;
1553          //
1554          for (Int_t ilab=0;ilab<10;ilab++){
1555            milab[ilab]=-2;
1556          }
1557          //
1558          if (flag!=d->GetCoord1()) { n=&np; c=pos; }
1559       }
1560       flag=d->GetCoord1();
1561       q += d->GetSignal();
1562       y += d->GetCoord2()*d->GetSignal();
1563       nd++;
1564       if (d->GetSignal()>qmax) {
1565          qmax=d->GetSignal();
1566          lab[0]=d->GetTrack(0); lab[1]=d->GetTrack(1); lab[2]=d->GetTrack(2);
1567       }
1568       for (Int_t ilab=0;ilab<10;ilab++) {
1569         if (d->GetTrack(ilab)>=0) AddLabel(milab, (d->GetTrack(ilab))); 
1570       }
1571       curr=strip;
1572   }
1573   c[*n].SetY(y/q);
1574   c[*n].SetQ(q);
1575   c[*n].SetNd(nd);
1576   c[*n].SetLabels(lab);
1577   //Split suspiciously big cluster
1578   if (nd>4 && nd<25) {
1579      c[*n].SetY(y/q-0.25*nd);
1580      c[*n].SetQ(0.5*q);
1581      (*n)++;
1582      if (*n==MAX) {
1583         Error("FindClustersSSD","Too many 1D clusters !");
1584         return;
1585      }
1586      c[*n].SetY(y/q+0.25*nd);
1587      c[*n].SetQ(0.5*q);
1588      c[*n].SetNd(nd);
1589      c[*n].SetLabels(lab);
1590   }
1591   (*n)++;
1592   if (*n==MAX) {
1593      Error("FindClustersSSD","Too many 1D clusters !");
1594      return;
1595   }
1596
1597   FindClustersSSD(neg, nn, pos, np, clusters);
1598 }
1599
1600 void AliITSclustererV2::FindClustersSSD(AliITSRawStream* input, 
1601                                         TClonesArray** clusters) 
1602 {
1603   //------------------------------------------------------------
1604   // Actual SSD cluster finder for raw data
1605   //------------------------------------------------------------
1606   Int_t nClustersSSD = 0;
1607   const Int_t MAX = 1000;
1608   Ali1Dcluster clusters1D[2][MAX];
1609   Int_t nClusters[2] = {0, 0};
1610   Int_t lab[3]={-2,-2,-2};
1611   Float_t q = 0.;
1612   Float_t y = 0.;
1613   Int_t nDigits = 0;
1614   Int_t prevStrip = -1;
1615   Int_t prevFlag = -1;
1616   Int_t prevModule = -1;
1617
1618   // read raw data input stream
1619   while (kTRUE) {
1620     Bool_t next = input->Next();
1621
1622     if(input->GetSignal()<3 && next) continue;
1623     // check if a new cluster starts
1624     Int_t strip = input->GetCoord2();
1625     Int_t flag = input->GetCoord1();
1626     if ((!next || (input->GetModuleID() != prevModule)||
1627          (strip-prevStrip > 1) || (flag != prevFlag)) &&
1628         (nDigits > 0)) {
1629       if (nClusters[prevFlag] == MAX) {
1630         Error("FindClustersSSD", "Too many 1D clusters !");
1631         return;
1632       }
1633       Ali1Dcluster& cluster = clusters1D[prevFlag][nClusters[prevFlag]++];
1634       cluster.SetY(y/q);
1635       cluster.SetQ(q);
1636       cluster.SetNd(nDigits);
1637       cluster.SetLabels(lab);
1638
1639       //Split suspiciously big cluster
1640       if (nDigits > 4&&nDigits < 25) {
1641         cluster.SetY(y/q - 0.25*nDigits);
1642         cluster.SetQ(0.5*q);
1643         if (nClusters[prevFlag] == MAX) {
1644           Error("FindClustersSSD", "Too many 1D clusters !");
1645           return;
1646         }
1647         Ali1Dcluster& cluster2 = clusters1D[prevFlag][nClusters[prevFlag]++];
1648         cluster2.SetY(y/q + 0.25*nDigits);
1649         cluster2.SetQ(0.5*q);
1650         cluster2.SetNd(nDigits);
1651         cluster2.SetLabels(lab);
1652       }
1653       y = q = 0.;
1654       nDigits = 0;
1655     }
1656
1657     if (!next || (input->GetModuleID() != prevModule)) {
1658       Int_t iModule = prevModule;
1659
1660       // when all data from a module was read, search for clusters
1661       if (prevFlag >= 0) {
1662         clusters[iModule] = new TClonesArray("AliITSclusterV2");
1663         fI = iModule;
1664         FindClustersSSD(&clusters1D[0][0], nClusters[0], 
1665                         &clusters1D[1][0], nClusters[1], clusters[iModule]);
1666         Int_t nClusters = clusters[iModule]->GetEntriesFast();
1667         nClustersSSD += nClusters;
1668       }
1669
1670       if (!next) break;
1671       nClusters[0] = nClusters[1] = 0;
1672       y = q = 0.;
1673       nDigits = 0;
1674     }
1675
1676     // add digit to current cluster
1677     q += input->GetSignal();
1678     y += strip * input->GetSignal();
1679     nDigits++;
1680     prevStrip = strip;
1681     prevFlag = flag;
1682     prevModule = input->GetModuleID();
1683
1684   }
1685
1686   Info("FindClustersSSD", "found clusters in ITS SSD: %d", nClustersSSD);
1687 }
1688