]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - ITS/AliITSClusterFinderV2SSD.cxx
technial fix to suppress the warning
[u/mrichter/AliRoot.git] / ITS / AliITSClusterFinderV2SSD.cxx
index 057582daa538a433b03b26df73d05b5042224876..9c4c91c8edc7b7d5645dbdc193358cda796636b2 100644 (file)
 //                                                                        //
 ///////////////////////////////////////////////////////////////////////////
 
+#include "AliITSClusterFinderV2SSD.h"
+
 #include <Riostream.h>
-#include "AliLog.h"
+#include <TGeoGlobalMagField.h>
 
-#include "AliITSClusterFinderV2SSD.h"
+#include "AliLog.h"
+#include "AliMagF.h"
 #include "AliITSRecPoint.h"
+#include "AliITSRecPointContainer.h"
 #include "AliITSgeomTGeo.h"
-#include "AliITSDetTypeRec.h"
 #include "AliRawReader.h"
 #include "AliITSRawStreamSSD.h"
 #include <TClonesArray.h>
+#include <TCollection.h>
 #include "AliITSdigitSSD.h"
 #include "AliITSReconstructor.h"
 #include "AliITSCalibrationSSD.h"
@@ -64,15 +68,37 @@ const Float_t AliITSClusterFinderV2SSD::fgkCosmic2008StripShifts[16][9] =
 ClassImp(AliITSClusterFinderV2SSD)
 
 
-AliITSClusterFinderV2SSD::AliITSClusterFinderV2SSD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),
-                                                                            fLastSSD1(AliITSgeomTGeo::GetModuleIndex(6,1,1)-1)
+  AliITSClusterFinderV2SSD::AliITSClusterFinderV2SSD(AliITSDetTypeRec* dettyp):AliITSClusterFinder(dettyp),fLastSSD1(AliITSgeomTGeo::GetModuleIndex(6,1,1)-1), fLorentzShiftP(0), fLorentzShiftN(0)
 {
 //Default constructor
+  static AliITSRecoParam *repa = NULL;  
+  if(!repa){
+    repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
+    if(!repa){
+      repa = AliITSRecoParam::GetHighFluxParam();
+      AliWarning("Using default AliITSRecoParam class");
+    }
+  }
 
+  if (repa->GetCorrectLorentzAngleSSD()) {
+    AliMagF* field = dynamic_cast<AliMagF*>(TGeoGlobalMagField::Instance()->GetField()); 
+    if (field == 0) {
+      AliError("Cannot get magnetic field from TGeoGlobalMagField");
+    }
+    else {
+      Float_t bField = field->SolenoidField();
+      // NB: spatial shift has opposite sign for lay 5 and 6, but strip numbering also changes direction, so no sign-change 
+      // Shift due to ExB on drift N-side, units: strip width 
+      fLorentzShiftP = -repa->GetTanLorentzAngleElectronsSSD() * 150.e-4/95.e-4 * bField / 5.0;
+      // Shift due to ExB on drift P-side, units: strip width 
+      fLorentzShiftN = -repa->GetTanLorentzAngleHolesSSD() * 150.e-4/95.e-4 * bField / 5.0;
+      AliDebug(1,Form("bField %f Lorentz Shift P-side %f N-side %f",bField,fLorentzShiftN,fLorentzShiftP));
+    }
+  }
 }
  
 //______________________________________________________________________
-AliITSClusterFinderV2SSD::AliITSClusterFinderV2SSD(const AliITSClusterFinderV2SSD &cf) : AliITSClusterFinder(cf),                                              fLastSSD1(cf.fLastSSD1)
+AliITSClusterFinderV2SSD::AliITSClusterFinderV2SSD(const AliITSClusterFinderV2SSD &cf) : AliITSClusterFinder(cf), fLastSSD1(cf.fLastSSD1), fLorentzShiftP(cf.fLorentzShiftP), fLorentzShiftN(cf.fLorentzShiftN)
 {
   // Copy constructor
 }
@@ -160,6 +186,9 @@ void AliITSClusterFinderV2SSD::FindClustersSSD(TClonesArray *alldigits) {
   cout<<endl;
   cout<<endl;
   */
+  Int_t layer = 4;
+  if (fModule>fLastSSD1) 
+    layer = 5;
 
   //--------------------------------------------------------
   // start 1D-clustering from the first digit in the digits array
@@ -219,7 +248,14 @@ void AliITSClusterFinderV2SSD::FindClustersSSD(TClonesArray *alldigits) {
 
        if(flag5) {
          //cout<<"here1"<<endl;
-         c[*n].SetY(y/q);
+         Float_t dLorentz = 0;
+         if (!flag) { // P-side is neg clust
+           dLorentz = fLorentzShiftN;
+         }
+         else { // N-side is p clust
+           dLorentz = fLorentzShiftP;
+         }
+         c[*n].SetY(y/q+dLorentz);
          c[*n].SetQ(q);
          c[*n].SetNd(nd);
         CheckLabels2(milab);
@@ -230,14 +266,14 @@ void AliITSClusterFinderV2SSD::FindClustersSSD(TClonesArray *alldigits) {
 
           //Split suspiciously big cluster
           if (nd>4&&nd<25) {
-            c[*n].SetY(y/q-0.25*nd);
+            c[*n].SetY(y/q-0.25*nd+dLorentz);
             c[*n].SetQ(0.5*q);
             (*n)++;
             if (*n==kMax) {
               Error("FindClustersSSD","Too many 1D clusters !");
               return;
             }
-            c[*n].SetY(y/q+0.25*nd);
+            c[*n].SetY(y/q+0.25*nd+dLorentz);
             c[*n].SetQ(0.5*q);
             c[*n].SetNd(nd);
             c[*n].SetLabels(milab);
@@ -309,8 +345,15 @@ void AliITSClusterFinderV2SSD::FindClustersSSD(TClonesArray *alldigits) {
   if(flag5) {
 
     // cout<<"here2"<<endl;
-
-    c[*n].SetY(y/q);
+    Float_t dLorentz = 0;
+    if (!flag) { // P-side is neg clust
+      dLorentz = fLorentzShiftN;
+    }
+    else { // N-side is p clust
+      dLorentz = fLorentzShiftP;
+    }
+    
+    c[*n].SetY(y/q + dLorentz);
     c[*n].SetQ(q);
     c[*n].SetNd(nd);
     c[*n].SetLabels(lab);
@@ -319,14 +362,14 @@ void AliITSClusterFinderV2SSD::FindClustersSSD(TClonesArray *alldigits) {
       
       //Split suspiciously big cluster
       if (nd>4 && nd<25) {
-       c[*n].SetY(y/q-0.25*nd);
+       c[*n].SetY(y/q-0.25*nd + dLorentz);
        c[*n].SetQ(0.5*q);
        (*n)++;
        if (*n==kMax) {
          Error("FindClustersSSD","Too many 1D clusters !");
          return;
        }
-       c[*n].SetY(y/q+0.25*nd);
+       c[*n].SetY(y/q+0.25*nd + dLorentz);
        c[*n].SetQ(0.5*q);
        c[*n].SetNd(nd);
        c[*n].SetLabels(lab);
@@ -349,31 +392,40 @@ void AliITSClusterFinderV2SSD::FindClustersSSD(TClonesArray *alldigits) {
   // Note2: if there are no Pside digits nn=0 (bad strips!!) (same for Nside)
   //
   //  cout<<nn<<" Pside and "<<np<<" Nside clusters"<<endl;
-  FindClustersSSD(neg, nn, pos, np);
-  //
+  
+  AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();   
+  if (nn*np > 0) { 
+    TClonesArray* clusters = rpc->UncheckedGetClusters(fModule);
+    clusters->Clear();
+    FindClustersSSD(neg, nn, pos, np, clusters);
+    TIter itr(clusters);
+    AliITSRecPoint *irp;
+    while ((irp = (AliITSRecPoint*)itr.Next()))  fDetTypeRec->AddRecPoint(*irp);
+  }
   //-----------------------------------------------------
-
 }
 
 
-void AliITSClusterFinderV2SSD::RawdataToClusters(AliRawReader* rawReader,TClonesArray** clusters){
+void AliITSClusterFinderV2SSD::RawdataToClusters(AliRawReader* rawReader){
 
-    //------------------------------------------------------------
+  //------------------------------------------------------------
   // This function creates ITS clusters from raw data
   //------------------------------------------------------------
+  fNClusters = 0;
   rawReader->Reset();
   AliITSRawStreamSSD inputSSD(rawReader);
-  FindClustersSSD(&inputSSD,clusters);
+  FindClustersSSD(&inputSSD);
   
 }
 
-void AliITSClusterFinderV2SSD::FindClustersSSD(AliITSRawStreamSSD* input, 
-                                       TClonesArray** clusters
+
+void AliITSClusterFinderV2SSD::FindClustersSSD(AliITSRawStreamSSD* input
 {
   //------------------------------------------------------------
   // Actual SSD cluster finder for raw data
   //------------------------------------------------------------
 
+  AliITSRecPointContainer* rpc = AliITSRecPointContainer::Instance();
   static AliITSRecoParam *repa = NULL;
   if(!repa){
     repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
@@ -382,361 +434,288 @@ void AliITSClusterFinderV2SSD::FindClustersSSD(AliITSRawStreamSSD* input,
       AliWarning("Using default AliITSRecoParam class");
     }
   }
-
+  if (fRawID2ClusID) { // RS: reset references from 1D clusters to rawID's
+    fRawIDRef[0].Reset();
+    fRawIDRef[1].Reset();
+  }
   Int_t nClustersSSD = 0;
-  const Int_t kMax = 1000;
-  Ali1Dcluster clusters1D[2][kMax];
-  Int_t nClusters[2] = {0, 0};
-  Int_t lab[3]={-2,-2,-2};
-  Float_t q = 0.;
-  Float_t y = 0.;
-  Int_t nDigits = 0;
-  Float_t gain=0;
-  Float_t noise=0.;
-  //  Float_t pedestal=0.;
-  Float_t oldnoise=0.;
-  AliITSCalibrationSSD* cal=NULL;
-
-  Int_t matrix[12][1536];
-  Int_t iddl=-1;
-  Int_t iad=-1;
-  Int_t oddl = -1;
-  Int_t oad = -1;
-  Int_t oadc = -1;
-  Int_t ostrip = -1;
-  Int_t osignal = 65535;
-  Int_t n=0;
-  Bool_t next=0;
-
-  // read raw data input stream
+  const Int_t kNADC = 12;
+  const Int_t kMaxADCClusters = 1000;
+
+  Int_t strips[kNADC][2][kMaxADCClusters][3]; // [ADC],[side],[istrip], [0]=istrip [1]=signal [2]=rawID (for embedding, RS)
+  Int_t nStrips[kNADC][2];
+
+  for( int i=0; i<kNADC; i++ ){
+    nStrips[i][0] = 0;
+    nStrips[i][1] = 0;
+  }
+
+  Int_t ddl = -1;
+  Int_t ad = -1;
+  
+  //*
+  //* Loop over modules DDL+AD
+  //*
+  int countRW = 0; //RS
+  if (fRawID2ClusID) fRawID2ClusID->Reset(); //RS if array was provided, we shall store the rawID -> ClusterID
+
   while (kTRUE) {
+
+    bool next = input->Next();
     
-    // reset signal matrix
-    for(Int_t i=0; i<12; i++) { for(Int_t j=0; j<1536; j++) { matrix[i][j] = 65535;} }
-    
-    if((osignal!=65535)&&(ostrip>0)&&(ostrip<1536)) { 
-      n++;
-      matrix[oadc][ostrip] = osignal; // recover data from previous occurence of input->Next() 
+    //* 
+    //* Continue if corrupted input
+    //*
+
+    if( (!next)&&(input->flag) ){
+     AliWarning(Form("ITSClustersFinderSSD: Corrupted data: warning from RawReader"));
+      continue; 
     }
-    
-    // buffer data for ddl=iddl and ad=iad
-    while(kTRUE) {
-        
-      next = input->Next();
-      if((!next)&&(input->flag)) continue;
-      Int_t ddl=input->GetDDL(); 
-      Int_t ad=input->GetAD();
-      Int_t adc = input->GetADC(); adc = (adc<6)? adc : adc - 2;
-      Int_t strip = input->GetStrip();
-      if(input->GetSideFlag()) strip=1535-strip;
-      Int_t signal = input->GetSignal();
-
-      if((ddl==iddl)&&(ad==iad)&&(strip>0)&&(strip<1536)) {n++; matrix[adc][strip] = signal;}
-      else {if ((strip<1536) && (strip>0)) {oddl=iddl; oad=iad; oadc = adc; ostrip = strip; osignal=signal; iddl=ddl; iad=ad; break;}}
+
+    Int_t newDDL = input->GetDDL(); 
+    Int_t newAD = input->GetAD();
+
+    if( next ){
+      if( newDDL<0 || newDDL>15 ){
+       AliWarning(Form("ITSClustersFinderSSD: Corrupted data: wrong DDL number (%d)",newDDL));
+       continue;
+      }
       
-      if(!next)  {oddl=iddl; oad=iad; oadc = adc; ostrip = strip; osignal=signal; iddl=ddl; iad=ad; break;}
-      //break;
+      if( newAD<1 || newAD>9 ){
+       AliWarning(Form("ITSClustersFinderSSD: Corrupted data: wrong AD number (%d)",newAD));
+       continue;
+      }
     }
-    
-    // No SSD data
-    if(!next && oddl<0) break;
-    
-    if(n==0) continue; // first occurence
-    n=0; //osignal=0;
 
-    Float_t dStrip = 0;
-    if (repa->GetUseCosmicRunShiftsSSD()) {  // Special condition for 2007/2008 cosmic data
-      dStrip = fgkCosmic2008StripShifts[oddl][oad-1];
-    }
-    if (TMath::Abs(dStrip) > 1.5)
-      AliError(Form("Indexing error ? oddl = %d, dStrip %f\n",oddl,dStrip));
-    // fill 1Dclusters
-    for(Int_t iadc=0; iadc<12; iadc++) {  // loop over ADC index for ddl=oddl and ad=oad
-      
-      Int_t iimod = (oad - 1)  * 12 + iadc;
-      Int_t iModule = AliITSRawStreamSSD::GetModuleNumber(oddl,iimod);
-      if(iModule==-1) continue;
-      cal = (AliITSCalibrationSSD*)GetResp(iModule);
+    bool newModule = ( !next || ddl!= newDDL || ad!=newAD );
 
-      Bool_t first = 0;
-      Bool_t flag5 = 0;
-      
-      /*
-      for(Int_t istrip=0; istrip<768; istrip++) { // P-side
-       Int_t signal = matrix[iadc][istrip];
-       pedestal = cal->GetPedestalP(istrip);
-       matrix[iadc][istrip]=signal-(Int_t)pedestal;
-      } 
-      */
+    if( newModule && ddl>=0 && ad>=0 ){ 
 
-      /*
-      Float_t cmode=0;
-      for(Int_t l=0; l<6; l++) {
-       cmode=0;
-       for(Int_t n=20; n<108; n++) cmode+=matrix[iadc][l*128+n];
-       cmode/=88.;
-       for(Int_t n=0; n<128; n++) matrix[iadc][l*128+n]-=(Int_t)cmode;
+      //*
+      //* Reconstruct the previous block of 12 modules --- actual clusterfinder
+      //* 
+      //cout<<endl;
+      for( int adc = 0; adc<kNADC; adc++ ){
        
-      }
-      */
+       //* 1D clusterfinder
 
-      Int_t istrip=0;
-      for(istrip=0; istrip<768; istrip++) { // P-side
+       Ali1Dcluster clusters1D[2][kMaxADCClusters]; // per ADC, per side
+       Int_t nClusters1D[2] = {0,0};
+       //int nstat[2] = {0,0};
+       fModule = AliITSRawStreamSSD::GetModuleNumber(ddl, (ad - 1)  * 12 + adc );
        
-       Int_t signal = TMath::Abs(matrix[iadc][istrip]);
+       if( fModule<0 ){
+//       AliWarning(Form("ITSClustersFinderSSD: Corrupted data: module (ddl %d ad %d adc %d) not found in the map",ddl,ad,adc));
+//CM channels are always present even everything is suppressed 
+         continue;
+       }
        
-       oldnoise = noise;
-       noise = cal->GetNoiseP(istrip); if(noise<1.) signal = 65535;
-       if(signal<3*noise) signal = 65535; // in case ZS was not done in hw do it now
+       Int_t layer = 4;
+       if (fModule>fLastSSD1) 
+         layer = 5;
+
+       AliITSCalibrationSSD* cal = (AliITSCalibrationSSD*)fDetTypeRec->GetCalibrationModel(fModule);
+       if( !cal ){
+         AliWarning(Form("ITSClustersFinderSSD: No calibration found for module (ddl %d ad %d adc %d)",ddl,ad,adc));       
+         continue;
+       }
 
-       //        if(cal->IsPChannelBad(istrip)) signal=0;
+       Float_t dStrip = 0;
 
-       if (signal!=65535) {
-         gain = cal->GetGainP(istrip);
-         signal = (Int_t) ( signal * gain ); // signal is corrected for gain
-         if(signal>fgkThreshold*noise) flag5=1;
-         signal = (Int_t) cal->ADCToKeV( signal ); // signal is  converted in KeV 
-         
-         q += signal;    // add digit to current cluster
-         y += istrip * signal;   
-         nDigits++;
-         first=1;
+       if( repa->GetUseCosmicRunShiftsSSD()) {  // Special condition for 2007/2008 cosmic data
+         dStrip = fgkCosmic2008StripShifts[ddl][ad-1];
+         if (TMath::Abs(dStrip) > 1.5){
+           AliWarning(Form("Indexing error in Cosmic calibration: ddl = %d, dStrip %f\n",ddl,dStrip));
+           dStrip = 0;
+         }     
        }
        
-       else if(first) {
+       for( int side=0; side<=1; side++ ){
+
+         Int_t lab[3]={-2,-2,-2};
+         Float_t q = 0.;
+         Float_t y = 0.;
+         Int_t nDigits = 0;
+         Int_t ostrip = -2;
+         Bool_t snFlag = 0;
+
+         Float_t dLorentz = 0;
+         if (side==0) { // P-side is neg clust
+           dLorentz = fLorentzShiftN;
+         }
+         else { // N-side is pos clust
+           dLorentz = fLorentzShiftP;
+         }
          
-         if ( (nDigits>0) && flag5 ) {
+         Int_t n = nStrips[adc][side];
+         for( int istr = 0; istr<n+1; istr++ ){
            
-           Ali1Dcluster& cluster = clusters1D[0][nClusters[0]++];
-
-           if(q!=0) cluster.SetY(y/q + dStrip);
-           else cluster.SetY(istrip + dStrip -1);
-
-           cluster.SetQ(q);
-           cluster.SetNd(nDigits);
-           cluster.SetLabels(lab);
+           bool stripOK = 1;
+           Int_t strip=0, rwID = 0;
+           Float_t signal=0.0, noise=0.0, gain=0.0;
            
-           if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
-             
-             //Split suspiciously big cluster
-             if (nDigits > 4&&nDigits < 25) {
-               if(q!=0) cluster.SetY(y/q + dStrip - 0.25*nDigits);
-               else cluster.SetY(istrip-1 + dStrip - 0.25*nDigits);
-               cluster.SetQ(0.5*q);
-               if (nClusters[0] == kMax) {
-                 Error("FindClustersSSD", "Too many 1D clusters !");
-                 return;
+           if( istr<n ){
+             strip = strips[adc][side][istr][0];
+             signal = strips[adc][side][istr][1];
+             rwID   = strips[adc][side][istr][2]; // RS
+             //cout<<"strip "<<adc<<" / "<<side<<": "<<strip<<endl;
+
+             if( cal ){
+               noise = side ?cal->GetNoiseN(strip) :cal->GetNoiseP(strip); 
+               gain = side ?cal->GetGainN(strip) :cal->GetGainP(strip);         
+               stripOK = ( noise>=1. && signal>=3.0*noise 
+                           //&& !cal->IsPChannelBad(strip) 
+                           );
+             }
+           } else stripOK = 0; // end of data
+
+           bool newCluster = ( (abs(strip-ostrip)!=1) || !stripOK );     
+               
+           if( newCluster ){
+
+             //* Store the previous cluster
+
+             if( nDigits>0 && q>0 && snFlag ){
+
+               if (nClusters1D[side] >= kMaxADCClusters-1 ) {
+                 AliWarning("HLT ClustersFinderSSD: Too many 1D clusters !");
+               }else {
+                 
+                 Ali1Dcluster &cluster = clusters1D[side][nClusters1D[side]++];
+                 cluster.SetY( y / q + dStrip + dLorentz);
+                 cluster.SetQ(q);
+                 cluster.SetNd(nDigits);
+                 cluster.SetLabels(lab);
+                 //cout<<"cluster 1D side "<<side<<": y= "<<y<<" q= "<<q<<" d="<<dStrip<<" Y="<<cluster.GetY()<<endl;
+                 //Split suspiciously big cluster
+
+                 if( repa->GetUseUnfoldingInClusterFinderSSD()
+                     && nDigits > 4 && nDigits < 25 
+                     ){
+                   cluster.SetY(y/q + dStrip - 0.25*nDigits + dLorentz);           
+                   cluster.SetQ(0.5*q);          
+                   Ali1Dcluster& cluster2 = clusters1D[side][nClusters1D[side]++];
+                   cluster2.SetY(y/q + dStrip + 0.25*nDigits + dLorentz);          
+                   cluster2.SetQ(0.5*q);
+                   cluster2.SetNd(nDigits);
+                   cluster2.SetLabels(lab);      
+                 } // unfolding is on          
                }
-               Ali1Dcluster& cluster2 = clusters1D[0][nClusters[0]++];
-               if(q!=0) cluster2.SetY(y/q + dStrip + 0.25*nDigits);
-               else cluster2.SetY(istrip-1 + dStrip + 0.25*nDigits);
-               cluster2.SetQ(0.5*q);
-               cluster2.SetNd(nDigits);
-               cluster2.SetLabels(lab);
              }
-           } // unfolding is on            
-         }
-         
-         y = q = 0.;
-         nDigits = 0;
-         first=0;
-         flag5=0;
-       }
-       
-      } // loop over strip on P-side
-      
-      // if last strip does have signal
-      if(first) {
-       
-         if ( (nDigits>0) && flag5 ) {
-         
-         Ali1Dcluster& cluster = clusters1D[0][nClusters[0]++];
-
-         if(q!=0) cluster.SetY(y/q + dStrip);
-         else cluster.SetY(istrip - 1 + dStrip);
+             y = q = 0.;
+             nDigits = 0;
+             snFlag = 0;
+
+           } //* End store the previous cluster
+
+           if( stripOK ){ // add new signal to the cluster
+//           signal = (Int_t) (signal * gain); // signal is corrected for gain
+             if( signal>fgkThreshold*noise) snFlag = 1;
+             signal = signal * gain; // signal is corrected for gain
+//           if( cal ) signal = (Int_t) cal->ADCToKeV( signal ); // signal is  converted in KeV          
+             if( cal ) signal = cal->ADCToKeV( signal ); // signal is  converted in KeV          
+             q += signal;        // add digit to current cluster
+             y += strip * signal;        
+             nDigits++;
+             //nstat[side]++;
+             ostrip = strip;
+             if (fRawID2ClusID) fRawIDRef[side].AddReference(nClusters1D[side],rwID);
 
-         cluster.SetQ(q);
-         cluster.SetNd(nDigits);
-         cluster.SetLabels(lab);
-         
-         if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
-           
-           //Split suspiciously big cluster
-           if (nDigits > 4&&nDigits < 25) {
-             if(q!=0) cluster.SetY(y/q + dStrip - 0.25*nDigits);
-             else cluster.SetY(istrip-1 + dStrip - 0.25*nDigits);
-             cluster.SetQ(0.5*q);
-             if (nClusters[0] == kMax) {
-               Error("FindClustersSSD", "Too many 1D clusters !");
-               return;
-             }
-             Ali1Dcluster& cluster2 = clusters1D[0][nClusters[0]++];
-             if(q!=0) cluster2.SetY(y/q + dStrip + 0.25*nDigits);
-             else cluster2.SetY(istrip-1 + dStrip + 0.25*nDigits);
-             cluster2.SetQ(0.5*q);
-             cluster2.SetNd(nDigits);
-             cluster2.SetLabels(lab);
            }
-         } // unfolding is on    
-         
-       }
-       y = q = 0.;
-       nDigits = 0;
-       first=0;
-       flag5=0;
-      }
-      
-      /*
-      for(Int_t istrip=768; istrip<1536; istrip++) { // P-side
-       Int_t signal = matrix[iadc][istrip];
-       pedestal = cal->GetPedestalN(1535-istrip);
-       matrix[iadc][istrip]=signal-(Int_t)pedestal;
-      }        
-      */
-
-      /*
-      for(Int_t l=6; l<12; l++) {
-       Float_t cmode=0;
-       for(Int_t n=20; n<108; n++) cmode+=matrix[iadc][l*128+n];
-       cmode/=88.;
-       for(Int_t n=0; n<128; n++) matrix[iadc][l*128+n]-=(Int_t)cmode;
-      }
-      */
+         } //* end loop over strips
 
-      oldnoise = 0.;
-      noise = 0.;
-      Int_t strip=0;
-      for(Int_t iistrip=768; iistrip<1536; iistrip++) { // N-side
+       } //* end loop over ADC sides
        
-       Int_t signal = TMath::Abs(matrix[iadc][iistrip]);
-       strip = 1535-iistrip;
 
-       oldnoise = noise;
-       noise = cal->GetNoiseN(strip); if(noise<1.) signal=65535;
-
-       //        if(cal->IsNChannelBad(strip)) signal=0;
-
-       if(signal<3*noise) signal = 65535; // in case ZS was not done in hw do it now
-
-       if (signal!=65535) {
-         gain = cal->GetGainN(strip);
-         signal = (Int_t) ( signal * gain); // signal is corrected for gain
-         if(signal>fgkThreshold*noise) flag5=1;
-         signal = (Int_t) cal->ADCToKeV( signal ); // signal is  converted in KeV 
-         
-         // add digit to current cluster
-         q += signal;
-         y += strip * signal;
-         nDigits++;
-         first=1;
+       //* 2D clusterfinder
+       if( nClusters1D[0] && nClusters1D[1] && fModule>=0 ){
+           TClonesArray* clusters = rpc->UncheckedGetClusters(fModule);
+              FindClustersSSD( clusters1D[0], nClusters1D[0], clusters1D[1], nClusters1D[1], clusters); 
+           Int_t nClustersn = clusters->GetEntriesFast();
+              nClustersSSD += nClustersn;
        }
 
-       else if(first) {
-         
-         if ( (nDigits>0) && flag5 ) {
-           
-           Ali1Dcluster& cluster = clusters1D[1][nClusters[1]++];
-
-           if(q!=0) cluster.SetY(y/q - dStrip);
-           else cluster.SetY(strip+1 - dStrip);
+       //cout<<"SG: "<<ddl<<" "<<ad<<" "<<adc<<": strips "<<nstat[0]<<"+"<<nstat[1]<<", clusters 1D= "<<nClusters1D[0]<<" + "<<nClusters1D[1]<<", 2D= "<<clusters.size()<<endl;
 
-           cluster.SetQ(q);
-           cluster.SetNd(nDigits);
-           cluster.SetLabels(lab);
-           
-           if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
-
-             //Split suspiciously big cluster
-             if (nDigits > 4&&nDigits < 25) {
-               cluster.SetY(y/q - dStrip - 0.25*nDigits);
-               cluster.SetQ(0.5*q);
-               if (nClusters[1] == kMax) {
-                 Error("FindClustersSSD", "Too many 1D clusters !");
-                 return;
-               }
-               Ali1Dcluster& cluster2 = clusters1D[1][nClusters[1]++];
-               cluster2.SetY(y/q - dStrip + 0.25*nDigits);
-               cluster2.SetQ(0.5*q);
-               cluster2.SetNd(nDigits);
-               cluster2.SetLabels(lab);
-             }       
-           } // unfolding is on
-         } 
-
-         y = q = 0.;
-         nDigits = 0;
-         first=0;        
-       flag5=0;
-       }
-       
-      } // loop over strips on N-side
+      }//* end loop over adc
+      
+    }//* end of reconstruction of previous block of 12 modules
+    
+    if( newModule ){
+      
+      //*
+      //* Clean up arrays and set new module
+      //* 
+      
+      for( int i=0; i<kNADC; i++ ){
+       nStrips[i][0] = 0;
+       nStrips[i][1] = 0;
+      }     
+      ddl = newDDL;
+      ad = newAD;
+    } 
+    
 
-      if(first) {
-       
-         if ( (nDigits>0) && flag5 ) {
-         
-         Ali1Dcluster& cluster = clusters1D[1][nClusters[1]++];
-         
-         if(q!=0) cluster.SetY(y/q - dStrip);
-         else cluster.SetY(strip - dStrip + 1);
+    //*
+    //* Exit main loop when there is no more input
+    //* 
 
-         cluster.SetQ(q);
-         cluster.SetNd(nDigits);
-         cluster.SetLabels(lab);
-         
-         if(repa->GetUseUnfoldingInClusterFinderSSD()==kTRUE) {
-           
-           //Split suspiciously big cluster
-           if (nDigits > 4&&nDigits < 25) {
-             if(q!=0) cluster.SetY(y/q - dStrip - 0.25*nDigits);
-             else cluster.SetY(strip+1 - dStrip - 0.25*nDigits);
-             cluster.SetQ(0.5*q);
-             if (nClusters[1] == kMax) {
-               Error("FindClustersSSD", "Too many 1D clusters !");
-               return;
-             }
-             Ali1Dcluster& cluster2 = clusters1D[1][nClusters[1]++];
-             if(q!=0) cluster2.SetY(y/q - dStrip + 0.25*nDigits);
-             else cluster2.SetY(strip+1 - dStrip + 0.25*nDigits);
-             cluster2.SetQ(0.5*q);
-             cluster2.SetNd(nDigits);
-             cluster2.SetLabels(lab);
-           }
-         } // unfolding is on      
-       }
+    if( !next ) break;
+    
+    //* 
+    //* Fill the current strip information
+    //* 
+
+    Int_t adc = input->GetADC(); 
+    if( adc<0 || adc>=kNADC+2 || (adc>5&&adc<8) ){
+      AliWarning(Form("HLT ClustersFinderSSD: Corrupted data: wrong adc number (%d)", adc));
+      continue;
+    }
 
-       y = q = 0.;
-       nDigits = 0;
-       first=0;          
-       flag5=0;
-      }
-      
-      // create recpoints
-      if((nClusters[0])&&(nClusters[1])) {
-       
-       clusters[iModule] = new TClonesArray("AliITSRecPoint");
-       fModule = iModule;
-       FindClustersSSD(&clusters1D[0][0], nClusters[0], 
-                       &clusters1D[1][0], nClusters[1], clusters[iModule]);
-       Int_t nClustersn = clusters[iModule]->GetEntriesFast();
-       nClustersSSD += nClustersn;
-      }
+    if( adc>7 ) adc-= 2; // shift ADC numbers 8-13 to 6-11
+    
+    Bool_t side = input->GetSideFlag();
+    Int_t strip = input->GetStrip();
+    Int_t signal = input->GetSignal();
+    
 
-      nClusters[0] = nClusters[1] = 0;
-      y = q = 0.;
-      nDigits = 0;
+    //cout<<"SSD: "<<ddl<<" "<<ad<<" "<<adc<<" "<<side<<" "<<strip<<" : "<<signal<<endl;
 
-    } // loop over adc
+    if( strip>767 ){    
+      AliWarning(Form("HLT ClustersFinderSSD: Corrupted data: wrong strip number (ddl %d ad %d adc %d side %d, strip %d", 
+                     ddl, ad, adc, side,strip) );
+      continue;
+    }
+    if (strip < 0) continue;
+    
+    int &n = nStrips[adc][side];
+    if( n >0 ){
+      Int_t oldStrip = strips[adc][side][n-1][0];
+
+      if( strip==oldStrip ){
+       AliWarning(Form("HLT ClustersFinderSSD: Corrupted data: duplicated signal: ddl %d ad %d adc %d, side %d, strip %d", 
+                       ddl, ad, adc, side, strip ));
+       continue;
+      }
+    }
+    strips[adc][side][n][0] = strip;
+    strips[adc][side][n][1] = signal;    
+    strips[adc][side][n][2] = countRW;    
+    n++;
 
-    if(!next) break;
-  }
+    //cout<<"SSD: "<<input->GetDDL()<<" "<<input->GetAD()<<" "
+    //<<input->GetADC()<<" "<<input->GetSideFlag()<<" "<<((int)input->GetStrip())<<" "<<strip<<" : "<<input->GetSignal()<<endl;
+    //
+    countRW++; //RS
+  } //* End main loop over the input
   
-  Info("FindClustersSSD", "found clusters in ITS SSD: %d", nClustersSSD);
+  AliDebug(1,Form("found clusters in ITS SSD: %d", nClustersSSD));
 }
 
+
 void AliITSClusterFinderV2SSD::
-FindClustersSSD(Ali1Dcluster* neg, Int_t nn, 
-               Ali1Dcluster* pos, Int_t np,
+FindClustersSSD(const Ali1Dcluster* neg, Int_t nn, 
+               const Ali1Dcluster* pos, Int_t np,
                TClonesArray *clusters) {
   //------------------------------------------------------------
   // Actual SSD cluster finder
@@ -744,9 +723,21 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
 
   const TGeoHMatrix *mT2L=AliITSgeomTGeo::GetTracking2LocalMatrix(fModule);
 
-  TClonesArray &cl=*clusters;
+  //---------------------------------------
+  // load recoparam
+  // 
+  static AliITSRecoParam *repa = NULL;  
+  if(!repa){
+    repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
+    if(!repa){
+      repa = AliITSRecoParam::GetHighFluxParam();
+      AliWarning("Using default AliITSRecoParam class");
+    }
+  }
+
+//  TClonesArray &cl=*clusters;
   
-  AliITSsegmentationSSD *seg = dynamic_cast<AliITSsegmentationSSD*>(fDetTypeRec->GetSegmentationModel(2));
+  AliITSsegmentationSSD *seg = static_cast<AliITSsegmentationSSD*>(fDetTypeRec->GetSegmentationModel(2));
   if (fModule>fLastSSD1) 
     seg->SetLayer(6);
   else 
@@ -772,8 +763,8 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
 
   if ((np*nn) > fgPairsSize) {
 
-    if (fgPairs) delete [] fgPairs;
-    fgPairsSize = 4*np*nn;
+    delete [] fgPairs;
+    fgPairsSize = 2*np*nn;
     fgPairs = new Short_t[fgPairsSize];
   }
   memset(fgPairs,0,sizeof(Short_t)*np*nn);
@@ -781,6 +772,7 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
   //
   // find available pairs
   //
+  Int_t ncross = 0;
   for (Int_t i=0; i<np; i++) {
     Float_t yp=pos[i].GetY(); 
     if ( (pos[i].GetQ()>0) && (pos[i].GetQ()<3) ) continue;
@@ -792,18 +784,36 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
       seg->GetPadCxz(yn, yp, xt, zt);
       //cout<<yn<<" "<<yp<<" "<<xt<<" "<<zt<<endl;
       
-      if (TMath::Abs(xt)<hwSSD+0.01)
-      if (TMath::Abs(zt)<hlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
-       negativepair[i*10+cnegative[i]] =j;  //index
-       positivepair[j*10+cpositive[j]] =i;
-       cnegative[i]++;  //counters
-       cpositive[j]++; 
-       fgPairs[i*nn+j]=100;
+      if (TMath::Abs(xt)<hwSSD)
+      if (TMath::Abs(zt)<hlSSD) {
+       Int_t in = i*10+cnegative[i];
+       Int_t ip = j*10+cpositive[j];
+       if ((in < 10*np) && (ip < 10*nn)) {
+         negativepair[in] =j;  //index
+         positivepair[ip] =i;
+         cnegative[i]++;  //counters
+         cpositive[j]++;
+         ncross++;     
+         fgPairs[i*nn+j]=100;
+       }
+       else
+         AliError(Form("Index out of range: ip=%d, in=%d",ip,in));
       }
     }
   }
 
-  //
+  if (!ncross) {
+    delete [] cnegative;
+    delete [] cused1;
+    delete [] negativepair;
+    delete [] cpositive;
+    delete [] cused2;
+    delete [] positivepair;
+    return;
+  }
+//why not to allocate memorey here?  if(!clusters) clusters = new TClonesArray("AliITSRecPoint", ncross);
+  
+  /* //
   // try to recover points out of but close to the module boundaries 
   //
   for (Int_t i=0; i<np; i++) {
@@ -823,14 +833,21 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
        // tag 1Dcluster (eventually will produce low quality recpoint)
        if (cnegative[i]==0) pos[i].SetNd(100);  // not available pair
        if (cpositive[j]==0) neg[j].SetNd(100);  // not available pair
-       negativepair[i*10+cnegative[i]] =j;  //index
-       positivepair[j*10+cpositive[j]] =i;
-       cnegative[i]++;  //counters
-       cpositive[j]++; 
-       fgPairs[i*nn+j]=100;
+       Int_t in = i*10+cnegative[i];
+       Int_t ip = j*10+cpositive[j];
+       if ((in < 10*np) && (ip < 10*nn)) {
+         negativepair[in] =j;  //index
+         positivepair[ip] =i;
+         cnegative[i]++;  //counters
+         cpositive[j]++;       
+         fgPairs[i*nn+j]=100;
+       }
+       else
+         AliError(Form("Index out of range: ip=%d, in=%d",ip,in));
       }
     }
   }
+  */
 
   //
   Float_t lp[6];
@@ -838,15 +855,6 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
   Double_t ratio;
   
 
-  static AliITSRecoParam *repa = NULL;
-  if(!repa){
-    repa = (AliITSRecoParam*) AliITSReconstructor::GetRecoParam();
-    if(!repa){
-      repa = AliITSRecoParam::GetHighFluxParam();
-      AliWarning("Using default AliITSRecoParam class");
-    }
-  }
-
   if(repa->GetUseChargeMatchingInClusterFinderSSD()==kTRUE) {
 
 
@@ -904,66 +912,47 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
        milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
        Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fModule]};
 
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
+       lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+       lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
        // out-of-diagonal element of covariance matrix
        if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
        else if ( (info[0]>1) && (info[1]>1) ) { 
-         lp[2]=0.0016*0.0016;  //SigmaY2
-         lp[3]=0.08*0.08;  //SigmaZ2
-         lp[5]=-0.00006;
+         lp[2]=2.63e-06;    // 0.0016*0.0016;  //SigmaY2
+         lp[3]=0.0065;      // 0.08*0.08;   //SigmaZ2
+         lp[5]=-6.48e-05;
        }
        else {
-         lp[3]=0.0093*0.0093;
-         if (info[0]==1) { lp[5]=-0.00014;}
-         else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
+         lp[2]=4.80e-06;      // 0.00219*0.00219
+         lp[3]=0.0093;        // 0.0964*0.0964;
+         if (info[0]==1) {
+           lp[5]=-0.00014;
+         }
+         else { 
+           lp[2]=2.79e-06;    // 0.0017*0.0017; 
+           lp[3]=0.00935;     // 0.967*0.967;
+           lp[5]=-4.32e-05;
+         }
        }
 
        AliITSRecPoint * cl2;
-       
-       if(clusters){  // Note clusters != 0 when method is called for rawdata
-         
-         
-         cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
+       cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);
          
-         cl2->SetChargeRatio(ratio);           
-         cl2->SetType(1);
-         fgPairs[ip*nn+j]=1;
-
-         if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
-           cl2->SetType(2);
-           fgPairs[ip*nn+j]=2;
-         }
-
-         if(pos[ip].GetQ()==0) cl2->SetType(3);
-         if(neg[j].GetQ()==0) cl2->SetType(4);
+    cl2->SetChargeRatio(ratio);        
+    cl2->SetType(1);
+    fgPairs[ip*nn+j]=1;
 
-         cused1[ip]++;
-         cused2[j]++;
-         
-       }
-       else{ // Note clusters == 0 when method is called for digits
-         
-         cl2 = new AliITSRecPoint(milab,lp,info);      
-         
-         cl2->SetChargeRatio(ratio);           
-         cl2->SetType(1);
-         fgPairs[ip*nn+j]=1;
-
-         if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
-           cl2->SetType(2);
-           fgPairs[ip*nn+j]=2;
-         }
+    if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
+      cl2->SetType(2);
+      fgPairs[ip*nn+j]=2;
+    }
 
-         if(pos[ip].GetQ()==0) cl2->SetType(3);
-         if(neg[j].GetQ()==0) cl2->SetType(4);
+    if(pos[ip].GetQ()==0) cl2->SetType(3);
+    if(neg[j].GetQ()==0) cl2->SetType(4);
 
-         cused1[ip]++;
-         cused2[j]++;
+    cused1[ip]++;
+    cused2[j]++;
 
-         fDetTypeRec->AddRecPoint(*cl2);
-       }
-       ncl++;
+       ncl++;
       }
     }
     
@@ -1014,25 +1003,30 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
            milab[3]=(((ip<<10) + in)<<10) + idet; // pos|neg|det
            Int_t info[3] = {pos[ip].GetNd(),neg[in].GetNd(),fNlayer[fModule]};
            
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
+       lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+       lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
        // out-of-diagonal element of covariance matrix
        if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
        else if ( (info[0]>1) && (info[1]>1) ) { 
-         lp[2]=0.0016*0.0016;  //SigmaY2
-         lp[3]=0.08*0.08;  //SigmaZ2
-         lp[5]=-0.00006;
+         lp[2]=2.63e-06;    // 0.0016*0.0016;  //SigmaY2
+         lp[3]=0.0065;      // 0.08*0.08;   //SigmaZ2
+         lp[5]=-6.48e-05;
        }
        else {
-         lp[3]=0.0093*0.0093;
-         if (info[0]==1) { lp[5]=-0.00014;}
-         else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
+         lp[2]=4.80e-06;      // 0.00219*0.00219
+         lp[3]=0.0093;        // 0.0964*0.0964;
+         if (info[0]==1) {
+           lp[5]=-0.00014;
+         }
+         else { 
+           lp[2]=2.79e-06;    // 0.0017*0.0017; 
+           lp[3]=0.00935;     // 0.967*0.967;
+           lp[5]=-4.32e-05;
+         }
        }
 
-           AliITSRecPoint * cl2;
-           if(clusters){
-             
-             cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
+       AliITSRecPoint * cl2;
+             cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);
              cl2->SetChargeRatio(ratio);       
              cl2->SetType(5);
              fgPairs[ip*nn+in] = 5;
@@ -1040,19 +1034,6 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
                cl2->SetType(6);
                fgPairs[ip*nn+in] = 6;
              }     
-           }
-           else{
-             cl2 = new AliITSRecPoint(milab,lp,info);
-             cl2->SetChargeRatio(ratio);       
-             cl2->SetType(5);
-             fgPairs[ip*nn+in] = 5;
-             if ((pos[ip].GetNd()+neg[in].GetNd())>6){ //multi cluster
-               cl2->SetType(6);
-               fgPairs[ip*nn+in] = 6;
-             }
-             
-             fDetTypeRec->AddRecPoint(*cl2);
-           }
            ncl++;
          }
          
@@ -1090,24 +1071,30 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
            milab[3]=(((ip2<<10) + in)<<10) + idet; // pos|neg|det
            Int_t info[3] = {pos[ip2].GetNd(),neg[in].GetNd(),fNlayer[fModule]};
            
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
+       lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+       lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
        // out-of-diagonal element of covariance matrix
        if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
        else if ( (info[0]>1) && (info[1]>1) ) { 
-         lp[2]=0.0016*0.0016;  //SigmaY2
-         lp[3]=0.08*0.08;  //SigmaZ2
-         lp[5]=-0.00006;
+         lp[2]=2.63e-06;    // 0.0016*0.0016;  //SigmaY2
+         lp[3]=0.0065;      // 0.08*0.08;   //SigmaZ2
+         lp[5]=-6.48e-05;
        }
        else {
-         lp[3]=0.0093*0.0093;
-         if (info[0]==1) { lp[5]=-0.00014;}
-         else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
+         lp[2]=4.80e-06;      // 0.00219*0.00219
+         lp[3]=0.0093;        // 0.0964*0.0964;
+         if (info[0]==1) {
+           lp[5]=-0.00014;
+         }
+         else { 
+           lp[2]=2.79e-06;    // 0.0017*0.0017; 
+           lp[3]=0.00935;     // 0.967*0.967;
+           lp[5]=-4.32e-05;
+         }
        }
 
            AliITSRecPoint * cl2;
-           if(clusters){
-             cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
+             cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);
              
              cl2->SetChargeRatio(ratio);       
              cl2->SetType(5);
@@ -1116,19 +1103,6 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
                cl2->SetType(6);
                fgPairs[ip2*nn+in] =6;
              }
-           }
-           else{
-             cl2 = new AliITSRecPoint(milab,lp,info);
-             cl2->SetChargeRatio(ratio);       
-             cl2->SetType(5);
-             fgPairs[ip2*nn+in] =5;
-             if ((pos[ip2].GetNd()+neg[in].GetNd())>6){ //multi cluster
-               cl2->SetType(6);
-               fgPairs[ip2*nn+in] =6;
-             }
-             
-             fDetTypeRec->AddRecPoint(*cl2);
-           }
            ncl++;
          }
          
@@ -1199,24 +1173,30 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
          milab[3]=(((ip<<10) + jn)<<10) + idet; // pos|neg|det
          Int_t info[3] = {pos[ip].GetNd(),neg[jn].GetNd(),fNlayer[fModule]};
 
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
+       lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+       lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
        // out-of-diagonal element of covariance matrix
        if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
        else if ( (info[0]>1) && (info[1]>1) ) { 
-         lp[2]=0.0016*0.0016;  //SigmaY2
-         lp[3]=0.08*0.08;  //SigmaZ2
-         lp[5]=-0.00006;
+         lp[2]=2.63e-06;    // 0.0016*0.0016;  //SigmaY2
+         lp[3]=0.0065;      // 0.08*0.08;   //SigmaZ2
+         lp[5]=-6.48e-05;
        }
        else {
-         lp[3]=0.0093*0.0093;
-         if (info[0]==1) { lp[5]=-0.00014;}
-         else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
+         lp[2]=4.80e-06;      // 0.00219*0.00219
+         lp[3]=0.0093;        // 0.0964*0.0964;
+         if (info[0]==1) {
+           lp[5]=-0.00014;
+         }
+         else { 
+           lp[2]=2.79e-06;    // 0.0017*0.0017; 
+           lp[3]=0.00935;     // 0.967*0.967;
+           lp[5]=-4.32e-05;
+         }
        }
 
          AliITSRecPoint * cl2;
-         if(clusters){
-           cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
+           cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);
 
            cl2->SetChargeRatio(ratio);         
            cl2->SetType(7);
@@ -1225,20 +1205,6 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
              cl2->SetType(8);
              fgPairs[ip*nn+jn]=8;
            }
-
-         }
-         else{
-           cl2 = new AliITSRecPoint(milab,lp,info);
-           cl2->SetChargeRatio(ratio);         
-           cl2->SetType(7);
-           fgPairs[ip*nn+jn] =7;
-           if ((pos[ip].GetNd()+neg[jn].GetNd())>6){ //multi cluster
-             cl2->SetType(8);
-             fgPairs[ip*nn+jn]=8;
-           }
-
-           fDetTypeRec->AddRecPoint(*cl2);
-         }
          ncl++;
        }
        //
@@ -1275,24 +1241,30 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
          milab[3]=(((ip<<10) + jn2)<<10) + idet; // pos|neg|det
          Int_t info[3] = {pos[ip].GetNd(),neg[jn2].GetNd(),fNlayer[fModule]};
 
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
+       lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+       lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
        // out-of-diagonal element of covariance matrix
        if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
        else if ( (info[0]>1) && (info[1]>1) ) { 
-         lp[2]=0.0016*0.0016;  //SigmaY2
-         lp[3]=0.08*0.08;  //SigmaZ2
-         lp[5]=-0.00006;
+         lp[2]=2.63e-06;    // 0.0016*0.0016;  //SigmaY2
+         lp[3]=0.0065;      // 0.08*0.08;   //SigmaZ2
+         lp[5]=-6.48e-05;
        }
        else {
-         lp[3]=0.0093*0.0093;
-         if (info[0]==1) { lp[5]=-0.00014;}
-         else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
+         lp[2]=4.80e-06;      // 0.00219*0.00219
+         lp[3]=0.0093;        // 0.0964*0.0964;
+         if (info[0]==1) {
+           lp[5]=-0.00014;
+         }
+         else { 
+           lp[2]=2.79e-06;    // 0.0017*0.0017; 
+           lp[3]=0.00935;     // 0.967*0.967;
+           lp[5]=-4.32e-05;
+         }
        }
 
          AliITSRecPoint * cl2;
-         if(clusters){
-           cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
+           cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);
 
 
            cl2->SetChargeRatio(ratio);         
@@ -1302,21 +1274,6 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
              cl2->SetType(8);
              fgPairs[ip*nn+jn2]=8;
            }
-           
-         }
-         else{
-           cl2 = new AliITSRecPoint(milab,lp,info);
-           cl2->SetChargeRatio(ratio);         
-           fgPairs[ip*nn+jn2]=7;
-           cl2->SetType(7);
-           if ((pos[ip].GetNd()+neg[jn2].GetNd())>6){ //multi cluster
-             cl2->SetType(8);
-             fgPairs[ip*nn+jn2]=8;
-           }
-
-           fDetTypeRec->AddRecPoint(*cl2);
-         }
-
          ncl++;
        }
        cused1[ip]++;
@@ -1415,24 +1372,30 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
        milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
        Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fModule]};
 
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
+       lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+       lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
        // out-of-diagonal element of covariance matrix
        if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
        else if ( (info[0]>1) && (info[1]>1) ) { 
-         lp[2]=0.0016*0.0016;  //SigmaY2
-         lp[3]=0.08*0.08;  //SigmaZ2
-         lp[5]=-0.00006;
+         lp[2]=2.63e-06;    // 0.0016*0.0016;  //SigmaY2
+         lp[3]=0.0065;      // 0.08*0.08;   //SigmaZ2
+         lp[5]=-6.48e-05;
        }
        else {
-         lp[3]=0.0093*0.0093;
-         if (info[0]==1) { lp[5]=-0.00014;}
-         else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
+         lp[2]=4.80e-06;      // 0.00219*0.00219
+         lp[3]=0.0093;        // 0.0964*0.0964;
+         if (info[0]==1) {
+           lp[5]=-0.00014;
+         }
+         else { 
+           lp[2]=2.79e-06;    // 0.0017*0.0017; 
+           lp[3]=0.00935;     // 0.967*0.967;
+           lp[5]=-4.32e-05;
+         }
        }
 
        AliITSRecPoint * cl2;
-       if(clusters){
-         cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
+         cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);
                  
          cl2->SetChargeRatio(ratio);           
          cl2->SetType(10);
@@ -1443,21 +1406,6 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
          }
          cused1[ip]++;
          cused2[j]++;      
-       }
-       else{
-         cl2 = new AliITSRecPoint(milab,lp,info);
-         cl2->SetChargeRatio(ratio);           
-         cl2->SetType(10);
-         fgPairs[ip*nn+j]=10;
-         if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
-           cl2->SetType(11);
-           fgPairs[ip*nn+j]=11;
-         }
-         cused1[ip]++;
-         cused2[j]++;      
-         
-         fDetTypeRec->AddRecPoint(*cl2);
-       }      
        ncl++;
        
       } // 2X2
@@ -1547,24 +1495,50 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
        milab[3]=(((ip<<10) + j)<<10) + idet; // pos|neg|det
        Int_t info[3] = {pos[ip].GetNd(),neg[j].GetNd(),fNlayer[fModule]};
 
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
+       lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+       lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
        // out-of-diagonal element of covariance matrix
        if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
        else if ( (info[0]>1) && (info[1]>1) ) { 
-         lp[2]=0.0016*0.0016;  //SigmaY2
-         lp[3]=0.08*0.08;  //SigmaZ2
-         lp[5]=-0.00006;
+         lp[2]=2.63e-06;    // 0.0016*0.0016;  //SigmaY2
+         lp[3]=0.0065;      // 0.08*0.08;   //SigmaZ2
+         lp[5]=-6.48e-05;
        }
        else {
-         lp[3]=0.0093*0.0093;
-         if (info[0]==1) { lp[5]=-0.00014;}
-         else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
+         lp[2]=4.80e-06;      // 0.00219*0.00219
+         lp[3]=0.0093;        // 0.0964*0.0964;
+         if (info[0]==1) {
+           lp[5]=-0.00014;
+         }
+         else { 
+           lp[2]=2.79e-06;    // 0.0017*0.0017; 
+           lp[3]=0.00935;     // 0.967*0.967;
+           lp[5]=-4.32e-05;
+         }
+       }
+       // 
+       if (fRawID2ClusID) { // set rawID <-> clusterID correspondence for embedding
+         const int kMaxRefRW = 200;
+         UInt_t nrefsRW,refsRW[kMaxRefRW];
+         nrefsRW = fRawIDRef[0].GetReferences(j,refsRW,kMaxRefRW); // n-side
+         for (int ir=nrefsRW;ir--;) {
+           int rwid = (int)refsRW[ir];
+           if (fRawID2ClusID->GetSize()<=rwid) fRawID2ClusID->Set( (rwid+10)<<1 );
+           (*fRawID2ClusID)[rwid] = fNClusters+1; // RS: store clID+1 as a reference to the cluster
+         }
+         //
+         nrefsRW = fRawIDRef[1].GetReferences(ip,refsRW,kMaxRefRW); // p-side
+         for (int ir=nrefsRW;ir--;) {
+           int rwid = (int)refsRW[ir];
+           if (fRawID2ClusID->GetSize()<=rwid) fRawID2ClusID->Set( (rwid+10)<<1 );
+           (*fRawID2ClusID)[rwid] = fNClusters+1; // RS: store clID+1 as a reference to the cluster
+         }
+         //
+         milab[0] = fNClusters+1;  // RS: assign id as cluster label
        }
 
        AliITSRecPoint * cl2;
-       if(clusters){
-         cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
+         cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);
                  
          cl2->SetChargeRatio(ratio);           
          cl2->SetType(12);
@@ -1575,22 +1549,8 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
          }
          cused1[ip]++;
          cused2[j]++;      
-       }
-       else{
-         cl2 = new AliITSRecPoint(milab,lp,info);
-         cl2->SetChargeRatio(ratio);           
-         cl2->SetType(12);
-         fgPairs[ip*nn+j]=12;
-         if ((pos[ip].GetNd()+neg[j].GetNd())>6){ //multi cluster
-           cl2->SetType(13);
-           fgPairs[ip*nn+j]=13;
-         }
-         cused1[ip]++;
-         cused2[j]++;      
-         
-         fDetTypeRec->AddRecPoint(*cl2);
-       }      
-       ncl++;
+         ncl++;
+         fNClusters++;
        
       } // manyXmany
     } // loop over Pside 1Dclusters
@@ -1619,8 +1579,8 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
       Float_t xt, zt;
       seg->GetPadCxz(yn, yp, xt, zt);
       
-      if (TMath::Abs(xt)<hwSSD+0.01)
-      if (TMath::Abs(zt)<hlSSD+0.01*(neg[j].GetNd()+pos[i].GetNd())) {
+      if (TMath::Abs(xt)<hwSSD)
+      if (TMath::Abs(zt)<hlSSD) {
        xbest=xt; zbest=zt; 
 
         qbest=0.5*(pos[i].GetQ()+neg[j].GetQ());
@@ -1642,275 +1602,250 @@ FindClustersSSD(Ali1Dcluster* neg, Int_t nn,
        milab[3]=(((i<<10) + j)<<10) + idet; // pos|neg|det
        Int_t info[3] = {pos[i].GetNd(),neg[j].GetNd(),fNlayer[fModule]};
 
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
+       lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+       lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
        // out-of-diagonal element of covariance matrix
        if( (info[0]==1) && (info[1]==1) ) lp[5]=-0.00012;
        else if ( (info[0]>1) && (info[1]>1) ) { 
-         lp[2]=0.0016*0.0016;  //SigmaY2
-         lp[3]=0.08*0.08;  //SigmaZ2
-         lp[5]=-0.00006;
+         lp[2]=2.63e-06;    // 0.0016*0.0016;  //SigmaY2
+         lp[3]=0.0065;      // 0.08*0.08;   //SigmaZ2
+         lp[5]=-6.48e-05;
        }
        else {
-         lp[3]=0.0093*0.0093;
-         if (info[0]==1) { lp[5]=-0.00014;}
-         else { lp[2]=0.0017*0.0017; lp[5]=-0.00004;}
+         lp[2]=4.80e-06;      // 0.00219*0.00219
+         lp[3]=0.0093;        // 0.0964*0.0964;
+         if (info[0]==1) {
+           lp[5]=-0.00014;
+         }
+         else { 
+           lp[2]=2.79e-06;    // 0.0017*0.0017; 
+           lp[3]=0.00935;     // 0.967*0.967;
+           lp[5]=-4.32e-05;
+         }
        }
 
        AliITSRecPoint * cl2;
-       if(clusters){
-         cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);
+         cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);
 
          cl2->SetChargeRatio(ratio);
          cl2->SetType(100+cpositive[j]+cnegative[i]);    
 
          if(pos[i].GetQ()==0) cl2->SetType(200+cpositive[j]+cnegative[i]);
          if(neg[j].GetQ()==0) cl2->SetType(300+cpositive[j]+cnegative[i]);
-
-       }
-       else{
-         cl2 = new AliITSRecPoint(milab,lp,info);
-         cl2->SetChargeRatio(ratio);
-         cl2->SetType(100+cpositive[j]+cnegative[i]);
-         
-         if(pos[i].GetQ()==0) cl2->SetType(200+cpositive[j]+cnegative[i]);
-         if(neg[j].GetQ()==0) cl2->SetType(300+cpositive[j]+cnegative[i]);
-
-         fDetTypeRec->AddRecPoint(*cl2);
-       }
        ncl++;
       }
     }
   }
 
 
-  //---------------------------------------------------------
-  // recover crosses of good 1D clusters with bad strips on the other side
-  // Note1: at first iteration skip modules with a bad side (or almost), (would produce too many fake!) 
-  // Note2: for modules with a bad side see below 
-  
-  AliITSCalibrationSSD* cal = (AliITSCalibrationSSD*)GetResp(fModule);
-  Int_t countPbad=0, countNbad=0;
-  for(Int_t ib=0; ib<768; ib++) {
-    if(cal->IsPChannelBad(ib)) countPbad++;
-    if(cal->IsNChannelBad(ib)) countNbad++;
-  }
-  //  AliInfo(Form("module %d has %d P- and %d N-bad strips",fModule,countPbad,countNbad));
 
-  if( (countPbad<100) && (countNbad<100) ) { // no bad side!!
+  if(repa->GetUseBadChannelsInClusterFinderSSD()==kTRUE) {
+    
+    //---------------------------------------------------------
+    // recover crosses of good 1D clusters with bad strips on the other side
+    // Note1: at first iteration skip modules with a bad side (or almost), (would produce too many fake!) 
+    // Note2: for modules with a bad side see below 
+    
+    AliITSCalibrationSSD* cal = (AliITSCalibrationSSD*)GetResp(fModule);
+    Int_t countPbad=0, countNbad=0;
+    for(Int_t ib=0; ib<768; ib++) {
+      if(cal->IsPChannelBad(ib)) countPbad++;
+      if(cal->IsNChannelBad(ib)) countNbad++;
+    }
+    //  AliInfo(Form("module %d has %d P- and %d N-bad strips",fModule,countPbad,countNbad));
     
-    for (Int_t i=0; i<np; i++) { // loop over Nside 1Dclusters with no crosses
-      if(cnegative[i]) continue; // if intersecting Pside clusters continue;
+    if( (countPbad<100) && (countNbad<100) ) { // no bad side!!
       
-      //      for(Int_t ib=0; ib<768; ib++) { // loop over all Pstrips
-      for(Int_t ib=15; ib<753; ib++) { // loop over all Pstrips
+      for (Int_t i=0; i<np; i++) { // loop over Nside 1Dclusters with no crosses
+       if(cnegative[i]) continue; // if intersecting Pside clusters continue;
        
-       if(cal->IsPChannelBad(ib)) { // check if strips is bad
-         Float_t yN=pos[i].GetY();     
-         Float_t xt, zt;
-         seg->GetPadCxz(1.*ib, yN, xt, zt);    
+       //      for(Int_t ib=0; ib<768; ib++) { // loop over all Pstrips
+       for(Int_t ib=15; ib<753; ib++) { // loop over all Pstrips
          
-         //----------
-         // bad Pstrip is crossing the Nside 1Dcluster -> create recpoint
-         // 
-         if ( (TMath::Abs(xt)<hwSSD+0.01) && (TMath::Abs(zt)<hlSSD+0.01) ) {
-           Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
-           mT2L->MasterToLocal(loc,trk);
-           lp[0]=trk[1];
-           lp[1]=trk[2];        
-           lp[4]=pos[i].GetQ(); //Q
-           for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
-           for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = pos[i].GetLabel(ilab);         
-           CheckLabels2(milab);
-           milab[3]=( (i<<10) << 10 ) + idet; // pos|neg|det
-           Int_t info[3] = {pos[i].GetNd(),0,fNlayer[fModule]};
+         if(cal->IsPChannelBad(ib)) { // check if strips is bad
+           Float_t yN=pos[i].GetY();   
+           Float_t xt, zt;
+           seg->GetPadCxz(1.*ib, yN, xt, zt);  
            
-           // out-of-diagonal element of covariance matrix
-           if (info[0]==1) lp[5]=0.0065;
-           else lp[5]=0.0093;
-
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
-       lp[5]=-0.00012; // out-of-diagonal element of covariance matrix
-       
-           AliITSRecPoint * cl2;
-           if(clusters){
-             cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);            
-             cl2->SetChargeRatio(1.);
+           //----------
+           // bad Pstrip is crossing the Nside 1Dcluster -> create recpoint
+           // 
+           if ( (TMath::Abs(xt)<hwSSD) && (TMath::Abs(zt)<hlSSD) ) {
+             Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
+             mT2L->MasterToLocal(loc,trk);
+             lp[0]=trk[1];
+             lp[1]=trk[2];        
+             lp[4]=pos[i].GetQ(); //Q
+             for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
+             for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = pos[i].GetLabel(ilab);       
+             CheckLabels2(milab);
+             milab[3]=( (i<<10) << 10 ) + idet; // pos|neg|det
+             Int_t info[3] = {pos[i].GetNd(),0,fNlayer[fModule]};
+             
+             lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+             lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
+             lp[5]=-0.00012; // out-of-diagonal element of covariance matrix
+             if (info[0]>1) {
+               lp[2]=4.80e-06;
+               lp[3]=0.0093;
+               lp[5]=0.00014;
+             }
+                     
+             AliITSRecPoint * cl2;
+               cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);         
+               cl2->SetChargeRatio(1.);
              cl2->SetType(50);   
-           }
-           else{
-             cl2 = new AliITSRecPoint(milab,lp,info);
-             cl2->SetChargeRatio(1.);
-             cl2->SetType(50);
-             fDetTypeRec->AddRecPoint(*cl2);
-           }
-           ncl++;
-         } // cross is within the detector
-         //
-         //--------------
+             ncl++;
+           } // cross is within the detector
+           //
+           //--------------
+           
+         } // bad Pstrip
          
-       } // bad Pstrip
+       } // end loop over Pstrips
        
-      } // end loop over Pstrips
+      } // end loop over Nside 1D clusters
       
-    } // end loop over Nside 1D clusters
+      for (Int_t j=0; j<nn; j++) { // loop over Pside 1D clusters with no crosses
+       if(cpositive[j]) continue;
+       
+       //      for(Int_t ib=0; ib<768; ib++) { // loop over all Nside strips
+       for(Int_t ib=15; ib<753; ib++) { // loop over all Nside strips
+         
+         if(cal->IsNChannelBad(ib)) { // check if strip is bad
+           Float_t yP=neg[j].GetY();   
+           Float_t xt, zt;
+           seg->GetPadCxz(yP, 1.*ib, xt, zt);  
+           
+           //----------
+           // bad Nstrip is crossing the Pside 1Dcluster -> create recpoint
+           // 
+           if ( (TMath::Abs(xt)<hwSSD) && (TMath::Abs(zt)<hlSSD) ) {
+             Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
+             mT2L->MasterToLocal(loc,trk);
+             lp[0]=trk[1];
+             lp[1]=trk[2];        
+             lp[4]=neg[j].GetQ(); //Q
+             for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
+             for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = neg[j].GetLabel(ilab);       
+             CheckLabels2(milab);
+             milab[3]=( j << 10 ) + idet; // pos|neg|det
+             Int_t info[3]={0,(Int_t)neg[j].GetNd(),fNlayer[fModule]};
+             
+             lp[2]=4.968e-06;     // 0.00223*0.00223;  //SigmaY2
+             lp[3]=0.012;         // 0.110*0.110;  //SigmaZ2
+             lp[5]=-0.00012; // out-of-diagonal element of covariance matrix
+             if (info[0]>1) {
+               lp[2]=2.79e-06;
+               lp[3]=0.00935;
+               lp[5]=-4.32e-05;
+             }
+             
+             AliITSRecPoint * cl2;
+               cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);         
+               cl2->SetChargeRatio(1.);
+               cl2->SetType(60);         
+             ncl++;
+           } // cross is within the detector
+           //
+           //--------------
+           
+         } // bad Nstrip
+       } // end loop over Nstrips
+      } // end loop over Pside 1D clusters
+      
+    } // no bad sides 
+    
+    //---------------------------------------------------------
     
-    for (Int_t j=0; j<nn; j++) { // loop over Pside 1D clusters with no crosses
-      if(cpositive[j]) continue;
+    else if( (countPbad>700) && (countNbad<100) ) { // bad Pside!!
       
-      //      for(Int_t ib=0; ib<768; ib++) { // loop over all Nside strips
-      for(Int_t ib=15; ib<753; ib++) { // loop over all Nside strips
+      for (Int_t i=0; i<np; i++) { // loop over Nside 1Dclusters with no crosses
+       if(cnegative[i]) continue; // if intersecting Pside clusters continue;
        
-       if(cal->IsNChannelBad(ib)) { // check if strip is bad
-         Float_t yP=neg[j].GetY();     
-         Float_t xt, zt;
-         seg->GetPadCxz(yP, 1.*ib, xt, zt);    
+       Float_t xt, zt;
+       Float_t yN=pos[i].GetY();       
+       Float_t yP=0.;
+       if (seg->GetLayer()==5) yP = yN + (7.6/1.9);
+       else yP = yN - (7.6/1.9);
+       seg->GetPadCxz(yP, yN, xt, zt); 
+       
+       if ( (TMath::Abs(xt)<hwSSD) && (TMath::Abs(zt)<hlSSD) ) {
+         Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
+         mT2L->MasterToLocal(loc,trk);
+         lp[0]=trk[1];
+         lp[1]=trk[2];        
+         lp[4]=pos[i].GetQ(); //Q
+         for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
+         for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = pos[i].GetLabel(ilab);   
+         CheckLabels2(milab);
+         milab[3]=( (i<<10) << 10 ) + idet; // pos|neg|det
+         Int_t info[3] = {(Int_t)pos[i].GetNd(),0,fNlayer[fModule]};
          
-         //----------
-         // bad Nstrip is crossing the Pside 1Dcluster -> create recpoint
-         // 
-         if ( (TMath::Abs(xt)<hwSSD+0.01) && (TMath::Abs(zt)<hlSSD+0.01) ) {
-           Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
-           mT2L->MasterToLocal(loc,trk);
-           lp[0]=trk[1];
-           lp[1]=trk[2];        
-           lp[4]=neg[j].GetQ(); //Q
-           for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
-           for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = neg[j].GetLabel(ilab);         
-           CheckLabels2(milab);
-           milab[3]=( j << 10 ) + idet; // pos|neg|det
-           Int_t info[3] = {0.,neg[j].GetNd(),fNlayer[fModule]};
+         lp[2]=0.00098;    // 0.031*0.031;  //SigmaY2
+         lp[3]=1.329;      // 1.15*1.15;  //SigmaZ2
+         lp[5]=-0.0359;
+         if(info[0]>1) lp[2]=0.00097;
 
-       lp[2]=0.0022*0.0022;  //SigmaY2
-       lp[3]=0.110*0.110;  //SigmaZ2
-       lp[5]=-0.00012; // out-of-diagonal element of covariance matrix
-       
-           AliITSRecPoint * cl2;
-           if(clusters){
-             cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);            
-             cl2->SetChargeRatio(1.);
-             cl2->SetType(60);   
-           }
-           else{
-             cl2 = new AliITSRecPoint(milab,lp,info);
-             cl2->SetChargeRatio(1.);
-             cl2->SetType(60);
-             fDetTypeRec->AddRecPoint(*cl2);
-           }
-           ncl++;
-         } // cross is within the detector
-         //
-         //--------------
-         
-       } // bad Nstrip
-      } // end loop over Nstrips
-    } // end loop over Pside 1D clusters
+         AliITSRecPoint * cl2;
+           cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);     
+           cl2->SetChargeRatio(1.);
+           cl2->SetType(70);     
+         ncl++;
+       } // cross is within the detector
+       //
+       //--------------
+       
+      } // end loop over Nside 1D clusters
+      
+    } // bad Pside module
     
-  } // no bad sides 
-
-  //---------------------------------------------------------
-
-  else if( (countPbad>700) && (countNbad<100) ) { // bad Pside!!
-
-    for (Int_t i=0; i<np; i++) { // loop over Nside 1Dclusters with no crosses
-      if(cnegative[i]) continue; // if intersecting Pside clusters continue;
+    else if( (countNbad>700) && (countPbad<100) ) { // bad Nside!!
       
-      Float_t xt, zt;
-      Float_t yN=pos[i].GetY();        
-      Float_t yP=0.;
-      if (seg->GetLayer()==5) yP = yN + (7.6/1.9);
-      else yP = yN - (7.6/1.9);
-      seg->GetPadCxz(yP, yN, xt, zt);  
+      for (Int_t j=0; j<nn; j++) { // loop over Pside 1D clusters with no crosses
+       if(cpositive[j]) continue;
+       
+       Float_t xt, zt;
+       Float_t yP=neg[j].GetY();       
+       Float_t yN=0.;
+       if (seg->GetLayer()==5) yN = yP - (7.6/1.9);
+       else yN = yP + (7.6/1.9);
+       seg->GetPadCxz(yP, yN, xt, zt); 
+       
+       if ( (TMath::Abs(xt)<hwSSD) && (TMath::Abs(zt)<hlSSD) ) {
+         Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
+         mT2L->MasterToLocal(loc,trk);
+         lp[0]=trk[1];
+         lp[1]=trk[2];        
+         lp[4]=neg[j].GetQ(); //Q
+         for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
+         for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = neg[j].GetLabel(ilab);   
+         CheckLabels2(milab);
+         milab[3]=( j << 10 ) + idet; // pos|neg|det
+         Int_t info[3] = {0,(Int_t)neg[j].GetNd(),fNlayer[fModule]};
          
-      if ( (TMath::Abs(xt)<hwSSD+0.01) && (TMath::Abs(zt)<hlSSD+0.01) ) {
-       Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
-       mT2L->MasterToLocal(loc,trk);
-       lp[0]=trk[1];
-       lp[1]=trk[2];        
-       lp[4]=pos[i].GetQ(); //Q
-       for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
-       for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = pos[i].GetLabel(ilab);     
-       CheckLabels2(milab);
-       milab[3]=( (i<<10) << 10 ) + idet; // pos|neg|det
-       Int_t info[3] = {pos[i].GetNd(),0.,fNlayer[fModule]};
-
-       lp[2]=0.031*0.031;  //SigmaY2
-       lp[3]=1.15*1.15;  //SigmaZ2
-       lp[5]=-0.036;
-
-       AliITSRecPoint * cl2;
-       if(clusters){
-         cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);        
-         cl2->SetChargeRatio(1.);
-         cl2->SetType(70);       
-       }
-       else{
-         cl2 = new AliITSRecPoint(milab,lp,info);
-         cl2->SetChargeRatio(1.);
-         cl2->SetType(70);
-         fDetTypeRec->AddRecPoint(*cl2);
-       }
-       ncl++;
-      } // cross is within the detector
-      //
-      //--------------
+         lp[2]=7.27e-05;   // 0.0085*0.0085;  //SigmaY2
+         lp[3]=1.33;       // 1.15*1.15;  //SigmaZ2
+         lp[5]=0.00931;
+         if(info[1]>1) lp[2]=6.91e-05;
+         
+         AliITSRecPoint * cl2;
+           cl2 = new ((*clusters)[ncl]) AliITSRecPoint(milab,lp,info);     
+           cl2->SetChargeRatio(1.);
+           cl2->SetType(80);     
+         ncl++;
+       } // cross is within the detector
+       //
+       //--------------
+       
+      } // end loop over Pside 1D clusters
       
-    } // end loop over Nside 1D clusters
+    } // bad Nside module
     
-  } // bad Pside module
-  
-  else if( (countNbad>700) && (countPbad<100) ) { // bad Nside!!
+    //---------------------------------------------------------
     
-    for (Int_t j=0; j<nn; j++) { // loop over Pside 1D clusters with no crosses
-      if(cpositive[j]) continue;
-      
-      Float_t xt, zt;
-      Float_t yP=neg[j].GetY();        
-      Float_t yN=0.;
-      if (seg->GetLayer()==5) yN = yP - (7.6/1.9);
-      else yN = yP + (7.6/1.9);
-      seg->GetPadCxz(yP, yN, xt, zt);  
-      
-      if ( (TMath::Abs(xt)<hwSSD+0.01) && (TMath::Abs(zt)<hlSSD+0.01) ) {
-       Double_t loc[3]={xt,0.,zt},trk[3]={0.,0.,0.};
-       mT2L->MasterToLocal(loc,trk);
-       lp[0]=trk[1];
-       lp[1]=trk[2];        
-       lp[4]=neg[j].GetQ(); //Q
-       for (Int_t ilab=0;ilab<10;ilab++) milab[ilab]=-2;
-       for (Int_t ilab=0;ilab<3;ilab++) milab[ilab] = neg[j].GetLabel(ilab);     
-       CheckLabels2(milab);
-       milab[3]=( j << 10 ) + idet; // pos|neg|det
-       Int_t info[3] = {0.,neg[j].GetNd(),fNlayer[fModule]};
-
-       lp[2]=0.0085*0.0085;  //SigmaY2
-       lp[3]=1.15*1.15;  //SigmaZ2
-       lp[5]=0.0093;
-
-       AliITSRecPoint * cl2;
-       if(clusters){
-         cl2 = new (cl[ncl]) AliITSRecPoint(milab,lp,info);        
-         cl2->SetChargeRatio(1.);
-         cl2->SetType(80);       
-       }
-       else{
-         cl2 = new AliITSRecPoint(milab,lp,info);
-         cl2->SetChargeRatio(1.);
-         cl2->SetType(80);
-         fDetTypeRec->AddRecPoint(*cl2);
-       }
-       ncl++;
-      } // cross is within the detector
-      //
-      //--------------
-      
-    } // end loop over Pside 1D clusters
+  } // use bad channels
     
-  } // bad Nside module
-  
-  //---------------------------------------------------------
-  
   //cout<<ncl<<" clusters for this module"<<endl;
 
   delete [] cnegative;