]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCclustererMI.cxx
Remove obsolete class AliTPCclusterLMI (Marian)
[u/mrichter/AliRoot.git] / TPC / AliTPCclustererMI.cxx
index 237673da77c02f21ef0583d7f77e823052a484eb..e6e54bb8c933420b57ca8667e6dbb7a524d8c6fa 100644 (file)
 //   Origin: Marian Ivanov 
 //-------------------------------------------------------
 
+#include "AliTPCReconstructor.h"
 #include "AliTPCclustererMI.h"
 #include "AliTPCclusterMI.h"
 #include <TObjArray.h>
 #include <TFile.h>
+#include "TGraph.h"
+#include "TF1.h"
+#include "TRandom.h"
+#include "AliMathBase.h"
+
 #include "AliTPCClustersArray.h"
 #include "AliTPCClustersRow.h"
-#include "AliTPCRawStream.h"
 #include "AliDigits.h"
 #include "AliSimDigits.h"
 #include "AliTPCParam.h"
+#include "AliTPCRecoParam.h"
 #include "AliRawReader.h"
 #include "AliTPCRawStream.h"
 #include "AliRunLoader.h"
 #include "AliLoader.h"
 #include "Riostream.h"
 #include <TTree.h>
+#include "AliTPCcalibDB.h"
+#include "AliTPCCalPad.h"
+#include "AliTPCCalROC.h"
+#include "TTreeStream.h"
+#include "AliLog.h"
+
 
 ClassImp(AliTPCclustererMI)
 
 
 
-AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par)
+  AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoParam * recoParam)
 {
+  fIsOldRCUFormat = kFALSE;
   fInput =0;
   fOutput=0;
   fParam = par;
+  if (recoParam) {
+    fRecoParam = recoParam;
+  }else{
+    //set default parameters if not specified
+    fRecoParam = AliTPCReconstructor::GetRecoParam();
+    if (!fRecoParam)  fRecoParam = AliTPCRecoParam::GetLowFluxParam();
+  }
+  fDebugStreamer = new TTreeSRedirector("TPCsignal.root");
+  fAmplitudeHisto = 0;
 }
+
+AliTPCclustererMI::~AliTPCclustererMI(){
+  DumpHistos();
+  if (fAmplitudeHisto) delete fAmplitudeHisto;
+  if (fDebugStreamer) delete fDebugStreamer;
+}
+
 void AliTPCclustererMI::SetInput(TTree * tree)
 {
   //
@@ -76,7 +105,7 @@ void AliTPCclustererMI::SetOutput(TTree * tree)
 
 Float_t  AliTPCclustererMI::GetSigmaY2(Int_t iz){
   // sigma y2 = in digits  - we don't know the angle
-  Float_t z = iz*fParam->GetZWidth();
+  Float_t z = iz*fParam->GetZWidth()+fParam->GetNTBinsL1()*fParam->GetZWidth();
   Float_t sd2 = (z*fParam->GetDiffL()*fParam->GetDiffL())/
     (fPadWidth*fPadWidth);
   Float_t sres = 0.25;
@@ -87,7 +116,7 @@ Float_t  AliTPCclustererMI::GetSigmaY2(Int_t iz){
 
 Float_t  AliTPCclustererMI::GetSigmaZ2(Int_t iz){
   //sigma z2 = in digits - angle estimated supposing vertex constraint
-  Float_t z = iz*fZWidth;
+  Float_t z = iz*fZWidth+fParam->GetNTBinsL1()*fParam->GetZWidth();
   Float_t sd2 = (z*fParam->GetDiffL()*fParam->GetDiffL())/(fZWidth*fZWidth);
   Float_t angular = fPadLength*(fParam->GetZLength()-z)/(fRx*fZWidth);
   angular*=angular;
@@ -98,7 +127,7 @@ Float_t  AliTPCclustererMI::GetSigmaZ2(Int_t iz){
   return res;
 }
 
-void AliTPCclustererMI::MakeCluster(Int_t k,Int_t max,Int_t *bins, UInt_t m,
+void AliTPCclustererMI::MakeCluster(Int_t k,Int_t max,Float_t *bins, UInt_t /*m*/,
 AliTPCclusterMI &c) 
 {
   Int_t i0=k/max;  //central pad
@@ -106,8 +135,8 @@ AliTPCclusterMI &c)
 
   // set pointers to data
   //Int_t dummy[5] ={0,0,0,0,0};
-  Int_t * matrix[5]; //5x5 matrix with digits  - indexing i = 0 ..4  j = -2..2
-  Int_t * resmatrix[5];
+  Float_t * matrix[5]; //5x5 matrix with digits  - indexing i = 0 ..4  j = -2..2
+  Float_t * resmatrix[5];
   for (Int_t di=-2;di<=2;di++){
     matrix[di+2]  =  &bins[k+di*max];
     resmatrix[di+2]  =  &fResBins[k+di*max];
@@ -119,7 +148,7 @@ AliTPCclusterMI &c)
   Float_t vmatrix[5][5];
   vmatrix[2][2] = matrix[2][0];
   c.SetType(0);
-  c.SetMax(Short_t(vmatrix[2][2])); // write maximal amplitude
+  c.SetMax((UShort_t)(vmatrix[2][2])); // write maximal amplitude
   for (Int_t di =-1;di <=1;di++)
     for (Int_t dj =-1;dj <=1;dj++){
       Float_t amp = matrix[di+2][dj];
@@ -187,8 +216,10 @@ AliTPCclusterMI &c)
   
   //
   if ( ( (ry<0.6) || (rz<0.6) ) && fLoop==2) return;
-  if ( (ry <1.2) && (rz<1.2) ) {
-    //if cluster looks like expected 
+  if ( (ry <1.2) && (rz<1.2) || (!fRecoParam->GetDoUnfold())) {
+    //
+    //if cluster looks like expected or Unfolding not switched on
+    //standard COG is used
     //+1.2 deviation from expected sigma accepted
     //    c.fMax = FitMax(vmatrix,meani,meanj,TMath::Sqrt(sigmay2),TMath::Sqrt(sigmaz2));
 
@@ -204,7 +235,7 @@ AliTPCclusterMI &c)
     //remove cluster data from data
     for (Int_t di=-2;di<=2;di++)
       for (Int_t dj=-2;dj<=2;dj++){
-       resmatrix[di+2][dj] -= Int_t(vmatrix[di+2][dj+2]);
+       resmatrix[di+2][dj] -= vmatrix[di+2][dj+2];
        if (resmatrix[di+2][dj]<0) resmatrix[di+2][dj]=0;
       }
     resmatrix[2][0] =0;
@@ -214,8 +245,8 @@ AliTPCclusterMI &c)
   //unfolding when neccessary  
   //
   
-  Int_t * matrix2[7]; //7x7 matrix with digits  - indexing i = 0 ..6  j = -3..3
-  Int_t dummy[7]={0,0,0,0,0,0};
+  Float_t * matrix2[7]; //7x7 matrix with digits  - indexing i = 0 ..6  j = -3..3
+  Float_t dummy[7]={0,0,0,0,0,0};
   for (Int_t di=-3;di<=3;di++){
     matrix2[di+3] =  &bins[k+di*max];
     if ((k+di*max)<3)  matrix2[di+3] = &dummy[3];
@@ -247,7 +278,7 @@ AliTPCclusterMI &c)
 
 
 
-void AliTPCclustererMI::UnfoldCluster(Int_t * matrix2[7], Float_t recmatrix[5][5], Float_t & meani, Float_t & meanj, 
+void AliTPCclustererMI::UnfoldCluster(Float_t * matrix2[7], Float_t recmatrix[5][5], Float_t & meani, Float_t & meanj, 
                                      Float_t & sumu, Float_t & overlap )
 {
   //
@@ -425,9 +456,12 @@ void AliTPCclustererMI::AddCluster(AliTPCclusterMI &c){
   c.SetSigmaZ2(s2*w*w);
   c.SetY((meani - 2.5 - 0.5*fMaxPad)*fParam->GetPadPitchWidth(fSector));
   c.SetZ(fZWidth*(meanj-3)); 
-  c.SetZ(c.GetZ()   - 3.*fParam->GetZSigma()); // PASA delay 
+  c.SetZ(c.GetZ() - 3.*fParam->GetZSigma() + fParam->GetNTBinsL1()*fParam->GetZWidth()); // PASA delay + L1 delay
   c.SetZ(fSign*(fParam->GetZLength() - c.GetZ()));
-  
+  c.SetX(fRx);
+  c.SetDetector(fSector);
+  c.SetRow(fRow);
+
   if (ki<=1 || ki>=fMaxPad-1 || kj==1 || kj==fMaxTime-2) {
     //c.SetSigmaY2(c.GetSigmaY2()*25.);
     //c.SetSigmaZ2(c.GetSigmaZ2()*4.);
@@ -460,6 +494,8 @@ void AliTPCclustererMI::Digits2Clusters()
     return;
   }
 
+  AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
+
   AliSimDigits digarr, *dummy=&digarr;
   fRowDig = dummy;
   fInput->GetBranch("Segment")->SetAddress(&dummy);
@@ -468,15 +504,17 @@ void AliTPCclustererMI::Digits2Clusters()
   fMaxTime=fParam->GetMaxTBin()+6; // add 3 virtual time bins before and 3   after
     
   Int_t nclusters  = 0;
-  
+
   for (Int_t n=0; n<nentries; n++) {
     fInput->GetEvent(n);
-    Int_t row;
-    if (!fParam->AdjustSectorRow(digarr.GetID(),fSector,row)) {
+    if (!fParam->AdjustSectorRow(digarr.GetID(),fSector,fRow)) {
       cerr<<"AliTPC warning: invalid segment ID ! "<<digarr.GetID()<<endl;
       continue;
     }
-        
+    Int_t row = fRow;
+    AliTPCCalROC * gainROC = gainTPC->GetCalROC(fSector);  // pad gains per given sector
+    
+    //
     AliTPCClustersRow *clrow= new AliTPCClustersRow();
     fRowCl = clrow;
     clrow->SetClass("AliTPCclusterMI");
@@ -503,16 +541,18 @@ void AliTPCclustererMI::Digits2Clusters()
     
     
     fMaxBin=fMaxTime*(fMaxPad+6);  // add 3 virtual pads  before and 3 after
-    fBins    =new Int_t[fMaxBin];
-    fResBins =new Int_t[fMaxBin];  //fBins with residuals after 1 finder loop 
-    memset(fBins,0,sizeof(Int_t)*fMaxBin);
+    fBins    =new Float_t[fMaxBin];
+    fResBins =new Float_t[fMaxBin];  //fBins with residuals after 1 finder loop 
+    memset(fBins,0,sizeof(Float_t)*fMaxBin);
+    memset(fResBins,0,sizeof(Float_t)*fMaxBin);
     
     if (digarr.First()) //MI change
       do {
-       Short_t dig=digarr.CurrentDigit();
+       Float_t dig=digarr.CurrentDigit();
        if (dig<=fParam->GetZeroSup()) continue;
        Int_t j=digarr.CurrentRow()+3, i=digarr.CurrentColumn()+3;
-       fBins[i*fMaxTime+j]=dig;
+       Float_t gain = gainROC->GetValue(row,digarr.CurrentColumn());
+       fBins[i*fMaxTime+j]=dig/gain;
       } while (digarr.Next());
     digarr.ExpandTrackBuffer();
 
@@ -525,13 +565,16 @@ void AliTPCclustererMI::Digits2Clusters()
     delete[] fResBins;  
   }  
 
-  Info("Digits2Clusters", "Number of found clusters : %d\n", nclusters);
+  Info("Digits2Clusters", "Number of found clusters : %d", nclusters);
 }
 
 void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
 {
 //-----------------------------------------------------------------
-// This is a cluster finder for raw data.
+// This is a cluster finder for the TPC raw data.
+// The method assumes NO ordering of the altro channels.
+// The pedestal subtraction can be switched on and off
+// using an option of the TPC reconstructor
 //-----------------------------------------------------------------
 
   if (!fOutput) {
@@ -539,11 +582,10 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
     return;
   }
 
-  rawReader->Reset();
-  AliTPCRawStream input(rawReader);
-
   fRowDig = NULL;
 
+  AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
+
   Int_t nclusters  = 0;
   
   fMaxTime = fParam->GetMaxTBin() + 6; // add 3 virtual time bins before and 3 after
@@ -553,125 +595,167 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
   fZWidth = fParam->GetZWidth();
   Int_t zeroSup = fParam->GetZeroSup();
 
-  fBins = NULL;
-  Int_t** splitRows = new Int_t* [kNS*2];
-  Int_t** splitRowsRes = new Int_t* [kNS*2];
-  for (Int_t iSector = 0; iSector < kNS*2; iSector++)
-    splitRows[iSector] = NULL;
-  Int_t iSplitRow = -1;
-
-  Bool_t next = kTRUE;
-  while (next) {
-    next = input.Next();
-
-    // when the sector or row number has changed ...
-    if (input.IsNewRow() || !next) {
-
-      // ... find clusters in the previous pad row, and ...
-      if (fBins) {
-       if ((iSplitRow < 0) || splitRows[fSector + kNS*iSplitRow]) {
-         fRowCl = new AliTPCClustersRow;
-         fRowCl->SetClass("AliTPCclusterMI");
-         fRowCl->SetArray(1);
-         fRowCl->SetID(fParam->GetIndex(fSector, input.GetPrevRow()));
-         fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
-
-         FindClusters();
-
-         fOutput->Fill();
-         delete fRowCl;    
-         nclusters += fNcluster;    
-         delete[] fBins;
-         delete[] fResBins;
-         if (iSplitRow >= 0) splitRows[fSector + kNS*iSplitRow] = NULL;
-
-       } else if (iSplitRow >= 0) {
-         splitRows[fSector + kNS*iSplitRow] = fBins;
-         splitRowsRes[fSector + kNS*iSplitRow] = fResBins;
-       }
-      }
+  Float_t** allBins = NULL;
+  Float_t** allBinsRes = NULL;
 
-      if (!next) break;
+  // Loop over sectors
+  for(fSector = 0; fSector < kNS; fSector++) {
 
-      // ... prepare for the next pad row
-      fSector = input.GetSector();
-      Int_t iRow = input.GetRow();
-      fRx = fParam->GetPadRowRadii(fSector, iRow);
+    AliTPCCalROC * gainROC = gainTPC->GetCalROC(fSector);  // pad gains per given sector
+    Int_t nRows = 0;
+    Int_t nDDLs = 0, indexDDL = 0;
+    if (fSector < kNIS) {
+      nRows = fParam->GetNRowLow();
+      fSign = (fSector < kNIS/2) ? 1 : -1;
+      nDDLs = 2;
+      indexDDL = fSector * 2;
+    }
+    else {
+      nRows = fParam->GetNRowUp();
+      fSign = ((fSector-kNIS) < kNOS/2) ? 1 : -1;
+      nDDLs = 4;
+      indexDDL = (fSector-kNIS) * 4 + kNIS * 2;
+    }
+
+    allBins = new Float_t*[nRows];
+    allBinsRes = new Float_t*[nRows];
+
+    for (Int_t iRow = 0; iRow < nRows; iRow++) {
+      Int_t maxPad;
+      if (fSector < kNIS)
+       maxPad = fParam->GetNPadsLow(iRow);
+      else
+       maxPad = fParam->GetNPadsUp(iRow);
+      
+      Int_t maxBin = fMaxTime*(maxPad+6);  // add 3 virtual pads  before and 3 after
+      allBins[iRow] = new Float_t[maxBin];
+      allBinsRes[iRow] = new Float_t[maxBin];
+      memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
+      memset(allBinsRes[iRow],0,sizeof(Float_t)*maxBin);
+    }
+    
+    // Loas the raw data for corresponding DDLs
+    rawReader->Reset();
+    AliTPCRawStream input(rawReader);
+    input.SetOldRCUFormat(fIsOldRCUFormat);
+    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
     
-      iSplitRow = -1;
-      if (fSector < kNIS) {
-       fMaxPad = fParam->GetNPadsLow(iRow);
-       fSign = (fSector < kNIS/2) ? 1 : -1;
-       if (iRow == 30) iSplitRow = 0;
-      } else {
-       fMaxPad = fParam->GetNPadsUp(iRow);
-       fSign = ((fSector-kNIS) < kNOS/2) ? 1 : -1;
-       if (iRow == 27) iSplitRow = 0;
-       else if (iRow == 76) iSplitRow = 1;
+    // Begin loop over altro data
+    while (input.Next()) {
+
+      if (input.GetSector() != fSector)
+       AliFatal(Form("Sector index mismatch ! Expected (%d), but got (%d) !",fSector,input.GetSector()));
+
+      
+      Int_t iRow = input.GetRow();
+      if (iRow < 0 || iRow >= nRows)
+       AliFatal(Form("Pad-row index (%d) outside the range (%d -> %d) !",
+                     iRow, 0, nRows -1));
+
+      Int_t iPad = input.GetPad() + 3;
+
+      Int_t maxPad;
+      if (fSector < kNIS)
+       maxPad = fParam->GetNPadsLow(iRow);
+      else
+       maxPad = fParam->GetNPadsUp(iRow);
+
+      if (input.GetPad() < 0 || input.GetPad() >= maxPad)
+       AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
+                     input.GetPad(), 0, maxPad -1));
+
+      Int_t iTimeBin = input.GetTime() + 3;
+      if ( input.GetTime() < 0 || input.GetTime() >= fParam->GetMaxTBin())
+       AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
+                     input.GetTime(), 0, fParam->GetMaxTBin() -1));
+
+      Int_t maxBin = fMaxTime*(maxPad+6);  // add 3 virtual pads  before and 3 after
+
+      if (((iPad*fMaxTime+iTimeBin) >= maxBin) ||
+         ((iPad*fMaxTime+iTimeBin) < 0))
+       AliFatal(Form("Index outside the allowed range"
+                     " Sector=%d Row=%d Pad=%d Timebin=%d"
+                     " (Max.index=%d)",fSector,iRow,iPad,iTimeBin,maxBin));
+
+      Float_t signal = input.GetSignal();
+      //      if (!fPedSubtraction && signal <= zeroSup) continue;
+      if (!fRecoParam->GetCalcPedestal() && signal <= zeroSup) continue;
+
+      Float_t gain = gainROC->GetValue(iRow,input.GetPad());
+      allBins[iRow][iPad*fMaxTime+iTimeBin] = signal/gain;
+      allBins[iRow][iPad*fMaxTime+0] = 1;  // pad with signal
+    } // End of the loop over altro data
+
+    // Now loop over rows and perform pedestal subtraction
+    //    if (fPedSubtraction) {
+    if (fRecoParam->GetCalcPedestal()) {
+      for (Int_t iRow = 0; iRow < nRows; iRow++) {
+       Int_t maxPad;
+       if (fSector < kNIS)
+         maxPad = fParam->GetNPadsLow(iRow);
+       else
+         maxPad = fParam->GetNPadsUp(iRow);
+
+       for (Int_t iPad = 0; iPad < maxPad + 6; iPad++) {
+         if (allBins[iRow][iPad*fMaxTime+0] !=1) continue;  // no data
+         Float_t *p = &allBins[iRow][iPad*fMaxTime+3];
+         //Float_t pedestal = TMath::Median(fMaxTime, p);      
+         Int_t id[3] = {fSector, iRow, iPad-3};
+         Float_t pedestal = ProcesSignal(p, fMaxTime, id);
+         for (Int_t iTimeBin = 0; iTimeBin < fMaxTime; iTimeBin++) {
+           allBins[iRow][iPad*fMaxTime+iTimeBin] -= pedestal;
+           if (iTimeBin < AliTPCReconstructor::GetRecoParam()->GetFirstBin())  
+             allBins[iRow][iPad*fMaxTime+iTimeBin] = 0;
+           if (iTimeBin > AliTPCReconstructor::GetRecoParam()->GetLastBin())  
+             allBins[iRow][iPad*fMaxTime+iTimeBin] = 0;
+           if (allBins[iRow][iPad*fMaxTime+iTimeBin] < zeroSup)
+             allBins[iRow][iPad*fMaxTime+iTimeBin] = 0;
+         }
+       }
       }
-      fPadLength = fParam->GetPadPitchLength(fSector, iRow);
+    }
+
+    // Now loop over rows and find clusters
+    for (fRow = 0; fRow < nRows; fRow++) {
+      fRowCl = new AliTPCClustersRow;
+      fRowCl->SetClass("AliTPCclusterMI");
+      fRowCl->SetArray(1);
+      fRowCl->SetID(fParam->GetIndex(fSector, fRow));
+      fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
+
+      fRx = fParam->GetPadRowRadii(fSector, fRow);
+      fPadLength = fParam->GetPadPitchLength(fSector, fRow);
       fPadWidth  = fParam->GetPadPitchWidth();
-    
+      if (fSector < kNIS)
+       fMaxPad = fParam->GetNPadsLow(fRow);
+      else
+       fMaxPad = fParam->GetNPadsUp(fRow);
       fMaxBin = fMaxTime*(fMaxPad+6);  // add 3 virtual pads  before and 3 after
-      if ((iSplitRow < 0) || !splitRows[fSector + kNS*iSplitRow]) {
-       fBins    = new Int_t[fMaxBin];
-       fResBins = new Int_t[fMaxBin];  //fBins with residuals after 1 finder loop 
-       memset(fBins, 0, sizeof(Int_t)*fMaxBin);
-      } else {
-       fBins    = splitRows[fSector + kNS*iSplitRow];
-       fResBins = splitRowsRes[fSector + kNS*iSplitRow];
-      }
+
+      fBins = allBins[fRow];
+      fResBins = allBinsRes[fRow];
+
+      FindClusters();
+
+      fOutput->Fill();
+      delete fRowCl;    
+      nclusters += fNcluster;    
+    } // End of loop to find clusters
+
+    for (Int_t iRow = 0; iRow < nRows; iRow++) {
+      delete [] allBins[iRow];
+      delete [] allBinsRes[iRow];
     }
 
-    // fill fBins with digits data
-    if (input.GetSignal() <= zeroSup) continue;
-    Int_t i = input.GetPad() + 3;
-    Int_t j = input.GetTime() + 3;
-    fBins[i*fMaxTime+j] = input.GetSignal();
-  }
+    delete [] allBins;
+    delete [] allBinsRes;
 
-  // find clusters in split rows that were skipped until now.
-  // this can happen if the rows were not splitted 
-  for (fSector = 0; fSector < kNS; fSector++)
-    for (Int_t iSplit = 0; iSplit < 2; iSplit++)
-      if (splitRows[fSector + kNS*iSplit]) {
-
-       Int_t iRow = -1;
-       if (fSector < kNIS) {
-         iRow = 30;
-         fMaxPad = fParam->GetNPadsLow(iRow);
-         fSign = (fSector < kNIS/2) ? 1 : -1;
-       } else {
-         if (iSplit == 0) iRow = 27; else iRow = 76;
-         fMaxPad = fParam->GetNPadsUp(iRow);
-         fSign = ((fSector-kNIS) < kNOS/2) ? 1 : -1;
-       }
-       fRx = fParam->GetPadRowRadii(fSector, iRow);
-       fPadLength = fParam->GetPadPitchLength(fSector, iRow);
-       fPadWidth  = fParam->GetPadPitchWidth();
-
-       fMaxBin = fMaxTime*(fMaxPad+6);  // add 3 virtual pads  before and 3 after
-       fBins    = splitRows[fSector + kNS*iSplit];
-       fResBins = splitRowsRes[fSector + kNS*iSplit];
-
-       fRowCl = new AliTPCClustersRow;
-       fRowCl->SetClass("AliTPCclusterMI");
-       fRowCl->SetArray(1);
-       fRowCl->SetID(fParam->GetIndex(fSector, iRow));
-       fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
-
-       FindClusters();
-
-       fOutput->Fill();
-       delete fRowCl;    
-       nclusters += fNcluster;    
-       delete[] fBins;
-       delete[] fResBins;
-      }
+  } // End of loop over sectors
 
-  delete[] splitRows;
-  delete[] splitRowsRes;
   Info("Digits2Clusters", "Number of found clusters : %d\n", nclusters);
+
 }
 
 void AliTPCclustererMI::FindClusters()
@@ -687,7 +771,7 @@ void AliTPCclustererMI::FindClusters()
       amp0 = (amp1*amp1/amp2)*TMath::Exp(-1./sigma2);  
       if (gDebug>4) printf("\n%f\n",amp0);
     }  
-    fBins[i+2*fMaxTime] = Int_t(amp0);    
+    fBins[i+2*fMaxTime] = amp0;    
     amp0 = 0;
     amp1 = fBins[(fMaxPad+2)*fMaxTime+i];
     if (amp1>0){
@@ -697,7 +781,7 @@ void AliTPCclustererMI::FindClusters()
       amp0 = (amp1*amp1/amp2)*TMath::Exp(-1./sigma2);          
       if (gDebug>4) printf("\n%f\n",amp0);
     }        
-    fBins[(fMaxPad+3)*fMaxTime+i] = Int_t(amp0);           
+    fBins[(fMaxPad+3)*fMaxTime+i] = amp0;           
   }
 
 //  memcpy(fResBins,fBins, fMaxBin*2);
@@ -706,8 +790,8 @@ void AliTPCclustererMI::FindClusters()
   fNcluster=0;
   //first loop - for "gold cluster" 
   fLoop=1;
-  Int_t *b=&fBins[-1]+2*fMaxTime;
-  Int_t crtime = Int_t((fParam->GetZLength()-1.05*fRx)/fZWidth-5);
+  Float_t *b=&fBins[-1]+2*fMaxTime;
+  Int_t crtime = Int_t((fParam->GetZLength()-fRecoParam->GetCtgRange()*fRx)/fZWidth-fParam->GetNTBinsL1()-5);
 
   for (Int_t i=2*fMaxTime; i<fMaxBin-2*fMaxTime; i++) {
     b++;
@@ -741,3 +825,258 @@ void AliTPCclustererMI::FindClusters()
   }
   */
 }
+
+
+Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t id[3]){
+  //
+  // process signal on given pad - + streaming of additional information in special mode
+  //
+  // id[0] - sector
+  // id[1] - row
+  // id[2] - pad  
+  Int_t offset =100;
+  Float_t kMin =fRecoParam->GetDumpAmplitudeMin();   // minimal signal to be dumped
+  Double_t median = TMath::Median(nchannels-offset, &(signal[offset]));
+  if (AliLog::GetDebugLevel("","AliTPCclustererMI")==0) return median;
+  //
+
+  Double_t mean   = TMath::Mean(nchannels-offset, &(signal[offset]));
+  Double_t rms    = TMath::RMS(nchannels-offset, &(signal[offset]));
+  Double_t *dsignal = new Double_t[nchannels];
+  Double_t *dtime   = new Double_t[nchannels];
+  Float_t max    =  0;
+  Float_t maxPos =  0;
+  for (Int_t i=0; i<nchannels; i++){
+    dtime[i] = i;
+    dsignal[i] = signal[i];
+    if (signal[i]>max && i <fMaxTime-100) {  // temporary remove spike signals at the end
+      max = signal[i];
+      maxPos = i;
+    }    
+  }
+  
+  Double_t mean06=0, mean09=0;
+  Double_t rms06=0, rms09=0; 
+  AliMathBase::EvaluateUni(nchannels-offset, &(dsignal[offset]), mean06, rms06, int(0.6*(nchannels-offset)));
+  AliMathBase::EvaluateUni(nchannels-offset, &(dsignal[offset]), mean09, rms09, int(0.9*(nchannels-offset)));
+  //
+  //
+  UInt_t uid[3] = {UInt_t(id[0]),UInt_t(id[1]),UInt_t(id[2])};
+  if (uid[0]< AliTPCROC::Instance()->GetNSectors() 
+      && uid[1]<  AliTPCROC::Instance()->GetNRows(uid[0])  && 
+      uid[2] < AliTPCROC::Instance()->GetNPads(uid[0], uid[1])){
+    if (!fAmplitudeHisto){
+      fAmplitudeHisto = new TObjArray(72);
+    }
+    TObjArray  * sectorArray = (TObjArray*)fAmplitudeHisto->UncheckedAt(uid[0]);
+    if (!sectorArray){
+      Int_t npads = AliTPCROC::Instance()->GetNChannels(uid[0]);
+      sectorArray = new TObjArray(npads);
+      fAmplitudeHisto->AddAt(sectorArray, uid[0]);
+    }
+    Int_t position =  uid[2]+ AliTPCROC::Instance()->GetRowIndexes(uid[0])[uid[1]];
+    TH1F * histo = (TH1F*)sectorArray->UncheckedAt(position);
+    if (!histo){
+      char hname[100];
+      sprintf(hname,"Amp_%d_%d_%d",uid[0],uid[1],uid[2]);
+      TFile * backup = gFile;
+      fDebugStreamer->GetFile()->cd();
+      histo = new TH1F(hname, hname, 100, 5,100);
+      //histo->SetDirectory(0);     // histogram not connected to directory -(File)
+      sectorArray->AddAt(histo, position);
+      if (backup) backup->cd();
+    }
+    for (Int_t i=0; i<nchannels; i++){
+      if (signal[i]>0) histo->Fill(signal[i]);
+    }
+  }
+  //
+  TGraph * graph;
+  Bool_t random = (gRandom->Rndm()<0.0001);
+  if (max-median>kMin || rms06>2.*fParam->GetZeroSup() || random){
+    graph =new TGraph(nchannels, dtime, dsignal);
+    if (rms06>2.*fParam->GetZeroSup() || random)
+      (*fDebugStreamer)<<"SignalN"<<    //noise pads - or random sample of pads
+       "Sector="<<uid[0]<<
+       "Row="<<uid[1]<<
+       "Pad="<<uid[2]<<
+       "Graph.="<<graph<<
+       "Max="<<max<<
+       "MaxPos="<<maxPos<<
+       //
+       "Median="<<median<<
+       "Mean="<<mean<<
+       "RMS="<<rms<<      
+       "Mean06="<<mean06<<
+       "RMS06="<<rms06<<
+       "Mean09="<<mean09<<
+       "RMS09="<<rms09<<
+       "\n";
+    if (max-median>kMin) 
+      (*fDebugStreamer)<<"SignalB"<<     // pads with signal
+       "Sector="<<uid[0]<<
+       "Row="<<uid[1]<<
+       "Pad="<<uid[2]<<
+       "Graph.="<<graph<<
+       "Max="<<max<<
+       "MaxPos="<<maxPos<<     
+       //
+       "Median="<<median<<
+       "Mean="<<mean<<
+       "RMS="<<rms<<      
+       "Mean06="<<mean06<<
+       "RMS06="<<rms06<<
+       "Mean09="<<mean09<<
+       "RMS09="<<rms09<<
+       "\n";
+    delete graph;
+  }
+  
+  (*fDebugStreamer)<<"Signal"<<
+    "Sector="<<uid[0]<<
+    "Row="<<uid[1]<<
+    "Pad="<<uid[2]<<
+    "Max="<<max<<
+    "MaxPos="<<maxPos<<
+    //
+    "Median="<<median<<
+    "Mean="<<mean<<
+    "RMS="<<rms<<      
+    "Mean06="<<mean06<<
+    "RMS06="<<rms06<<
+    "Mean09="<<mean09<<
+    "RMS09="<<rms09<<
+    "\n";
+  //
+  //
+  //  Central Electrode signal analysis  
+  //
+  Double_t ceQmax  =0, ceQsum=0, ceTime=0;
+  Double_t cemean  = mean06, cerms=rms06 ;
+  Int_t    cemaxpos= 0;
+  Double_t ceThreshold=5.*cerms;
+  Double_t ceSumThreshold=8.*cerms;
+  const Int_t    cemin=5;  // range for the analysis of the ce signal +- channels from the peak
+  const Int_t    cemax=5;
+  if (max-mean06>ceThreshold)   for (Int_t i=nchannels-2; i>1; i--){
+    if ( (dsignal[i]-mean06)>ceThreshold && dsignal[i]>=dsignal[i+1] && dsignal[i]>=dsignal[i-1] ){
+      cemaxpos=i;
+      break;
+    }
+  }
+  if (cemaxpos!=0){
+      for (Int_t i=cemaxpos-cemin; i<cemaxpos+cemax; i++){
+         if (i>0 && i<nchannels){
+             Double_t val=dsignal[i]- cemean;
+             ceTime+=val*dtime[i];
+             ceQsum+=val;
+             if (val>ceQmax) ceQmax=val;
+         }
+      }
+      if (ceQmax&&ceQsum>ceSumThreshold) {
+         ceTime/=ceQsum;
+         (*fDebugStreamer)<<"Signalce"<<
+             "Sector="<<uid[0]<<
+             "Row="<<uid[1]<<
+             "Pad="<<uid[2]<<
+             "Max="<<ceQmax<<
+             "Qsum="<<ceQsum<<
+             "Time="<<ceTime<<
+             //
+             "\n";
+      }
+  }
+  // end of ce signal analysis
+  //
+
+  //
+  //  Gating grid signal analysis  
+  //
+  Double_t ggQmax  =0, ggQsum=0, ggTime=0;
+  Double_t ggmean  = mean06, ggrms=rms06 ;
+  Int_t    ggmaxpos= 0;
+  Double_t ggThreshold=5.*ggrms;
+  Double_t ggSumThreshold=8.*ggrms;
+  const Int_t    ggmin=5;  // range for the analysis of the gg signal +- channels from the peak
+  const Int_t    ggmax=5;
+  if (max-mean06>ggThreshold)   for (Int_t i=1; i<nchannels-1; i++){
+    if ( (dsignal[i]-mean06)>ggThreshold && dsignal[i]>=dsignal[i+1] && dsignal[i]>=dsignal[i-1] ){
+      ggmaxpos=i;
+      break;
+    }
+  }
+  if (ggmaxpos!=0){
+      for (Int_t i=ggmaxpos-ggmin; i<ggmaxpos+ggmax; i++){
+         if (i>0 && i<nchannels && dsignal[i]>0){
+             Double_t val=dsignal[i]- ggmean;
+             ggTime+=val*dtime[i];
+             ggQsum+=val;
+             if (val>ggQmax) ggQmax=val;
+         }
+      }
+      if (ggQmax&&ggQsum>ggSumThreshold) {
+         ggTime/=ggQsum;
+         (*fDebugStreamer)<<"Signalgg"<<
+             "Sector="<<uid[0]<<
+             "Row="<<uid[1]<<
+             "Pad="<<uid[2]<<
+             "Max="<<ggQmax<<
+             "Qsum="<<ggQsum<<
+             "Time="<<ggTime<<
+             //
+             "\n";
+      }
+  }
+  // end of gg signal analysis
+      
+
+  delete [] dsignal;
+  delete [] dtime;
+  if (rms06>fRecoParam->GetMaxNoise()) return 1024+median; // sign noisy channel in debug mode
+  return median;
+}
+
+
+
+void AliTPCclustererMI::DumpHistos(){
+  if (!fAmplitudeHisto) return;
+  for (UInt_t isector=0; isector<AliTPCROC::Instance()->GetNSectors(); isector++){
+    TObjArray * array = (TObjArray*)fAmplitudeHisto->UncheckedAt(isector);
+    if (!array) continue;
+    for (UInt_t ipad = 0; ipad <(UInt_t)array->GetEntriesFast(); ipad++){
+      TH1F * histo = (TH1F*) array->UncheckedAt(ipad);
+      if (!histo) continue;
+      if (histo->GetEntries()<100) continue;
+      histo->Fit("gaus","q");
+      Float_t mean =  histo->GetMean();
+      Float_t rms  =  histo->GetRMS();
+      Float_t gmean = histo->GetFunction("gaus")->GetParameter(1);
+      Float_t gsigma = histo->GetFunction("gaus")->GetParameter(2);
+      Float_t max = histo->GetFunction("gaus")->GetParameter(0);
+
+      // get pad number
+      UInt_t row=0, pad =0;
+      const UInt_t *indexes = AliTPCROC::Instance()->GetRowIndexes(isector);
+      for (UInt_t irow=0; irow< AliTPCROC::Instance()->GetNRows(isector); irow++){
+       if (indexes[irow]<ipad){
+         row = irow;
+         pad = ipad-indexes[irow];
+       }
+      }      
+      Int_t rpad = pad - (AliTPCROC::Instance()->GetNPads(isector,row))/2;
+      //
+      (*fDebugStreamer)<<"Fit"<<
+       "Sector="<<isector<<
+       "Row="<<row<<
+       "Pad="<<pad<<
+       "RPad="<<rpad<<
+       "Max="<<max<<
+       "Mean="<<mean<<
+       "RMS="<<rms<<      
+       "GMean="<<gmean<<
+       "GSigma="<<gsigma<<
+       "\n";
+      if (array->UncheckedAt(ipad)) fDebugStreamer->StoreObject(array->UncheckedAt(ipad));
+    }
+  }
+}