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