]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCclustererMI.cxx
Changes for HLT: (Jacek Otwinowski)
[u/mrichter/AliRoot.git] / TPC / AliTPCclustererMI.cxx
index 82d5ee2542700692b84565e15e480555fbc89ee8..9907b5cc721a399fbd5a597385f18a2592aa8fe4 100644 (file)
 //-------------------------------------------------------
 //          Implementation of the TPC clusterer
 //
+//  1. The Input data for reconstruction - Options
+//      1.a Simulated data  - TTree - invoked Digits2Clusters()
+//      1.b Raw data        - Digits2Clusters(AliRawReader* rawReader); 
+//
+//  2. The Output data
+//      2.a TTree with clusters - if  SetOutput(TTree * tree) invoked
+//      2.b TObjArray           - Faster option for HLT
+//      2.c TClonesArray        - Faster option for HLT (smaller memory consumption), activate with fBClonesArray flag
+//
+//  3. Reconstruction setup
+//     see AliTPCRecoParam for list of parameters 
+//     The reconstruction parameterization taken from the 
+//     AliTPCReconstructor::GetRecoParam()
+//     Possible to setup it in reconstruction macro  AliTPCReconstructor::SetRecoParam(...)
+//     
+//
+//
 //   Origin: Marian Ivanov 
 //-------------------------------------------------------
 
-#include "AliTPCReconstructor.h"
-#include "AliTPCclustererMI.h"
-#include "AliTPCclusterMI.h"
-#include <TObjArray.h>
+#include "Riostream.h"
+#include <TF1.h>
 #include <TFile.h>
-#include "TGraph.h"
-#include "TF1.h"
-#include "TRandom.h"
-#include "AliMathBase.h"
+#include <TGraph.h>
+#include <TH1F.h>
+#include <TObjArray.h>
+#include <TClonesArray.h>
+#include <TRandom.h>
+#include <TTree.h>
+#include <TTreeStream.h>
 
-#include "AliTPCClustersArray.h"
-#include "AliTPCClustersRow.h"
 #include "AliDigits.h"
-#include "AliSimDigits.h"
-#include "AliTPCParam.h"
-#include "AliTPCRecoParam.h"
-#include "AliRawReader.h"
-#include "AliTPCRawStream.h"
+#include "AliLoader.h"
+#include "AliLog.h"
+#include "AliMathBase.h"
 #include "AliRawEventHeaderBase.h"
+#include "AliRawReader.h"
 #include "AliRunLoader.h"
-#include "AliLoader.h"
-#include "Riostream.h"
-#include <TTree.h>
-#include "AliTPCcalibDB.h"
+#include "AliSimDigits.h"
 #include "AliTPCCalPad.h"
 #include "AliTPCCalROC.h"
-#include "TTreeStream.h"
-#include "AliLog.h"
-
+#include "AliTPCClustersArray.h"
+#include "AliTPCClustersRow.h"
+#include "AliTPCParam.h"
+#include "AliTPCRawStream.h"
+#include "AliTPCRecoParam.h"
+#include "AliTPCReconstructor.h"
+#include "AliTPCcalibDB.h"
+#include "AliTPCclusterInfo.h"
+#include "AliTPCclusterMI.h"
+#include "AliTPCTransform.h"
+#include "AliTPCclustererMI.h"
 
 ClassImp(AliTPCclustererMI)
 
@@ -57,7 +77,8 @@ ClassImp(AliTPCclustererMI)
 
 AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoParam * recoParam):
   fBins(0),
-  fResBins(0),
+  fSigBins(0),
+  fNSigBins(0),
   fLoop(0),
   fMaxBin(0),
   fMaxTime(0),
@@ -70,28 +91,29 @@ AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoPar
   fPadLength(0),
   fZWidth(0),
   fPedSubtraction(kFALSE),
-  fIsOldRCUFormat(kFALSE),
   fEventHeader(0),
   fTimeStamp(0),
   fEventType(0),
   fInput(0),
   fOutput(0),
+  fOutputArray(0),
+  fOutputClonesArray(0),
   fRowCl(0),
   fRowDig(0),
   fParam(0),
   fNcluster(0),
-  fAmplitudeHisto(0),
+  fNclusters(0),
   fDebugStreamer(0),
-  fRecoParam(0)
+  fRecoParam(0),
+  fBDumpSignal(kFALSE),
+  fBClonesArray(kFALSE)
 {
   //
   // COSNTRUCTOR
   // param     - tpc parameters for given file
   // recoparam - reconstruction parameters 
   //
-  fIsOldRCUFormat = kFALSE;
   fInput =0;
-  fOutput=0;
   fParam = par;
   if (recoParam) {
     fRecoParam = recoParam;
@@ -101,13 +123,18 @@ AliTPCclustererMI::AliTPCclustererMI(const AliTPCParam* par, const AliTPCRecoPar
     if (!fRecoParam)  fRecoParam = AliTPCRecoParam::GetLowFluxParam();
   }
   fDebugStreamer = new TTreeSRedirector("TPCsignal.root");
-  fAmplitudeHisto = 0;
+  //  Int_t nPoints = fRecoParam->GetLastBin()-fRecoParam->GetFirstBin();
+  fRowCl= new AliTPCClustersRow();
+  fRowCl->SetClass("AliTPCclusterMI");
+  fRowCl->SetArray(1);
+
 }
 //______________________________________________________________
 AliTPCclustererMI::AliTPCclustererMI(const AliTPCclustererMI &param)
               :TObject(param),
   fBins(0),
-  fResBins(0),
+  fSigBins(0),
+  fNSigBins(0),
   fLoop(0),
   fMaxBin(0),
   fMaxTime(0),
@@ -120,19 +147,22 @@ AliTPCclustererMI::AliTPCclustererMI(const AliTPCclustererMI &param)
   fPadLength(0),
   fZWidth(0),
   fPedSubtraction(kFALSE),
-  fIsOldRCUFormat(kFALSE),
   fEventHeader(0),
   fTimeStamp(0),
   fEventType(0),
   fInput(0),
   fOutput(0),
+  fOutputArray(0),
+  fOutputClonesArray(0),
   fRowCl(0),
   fRowDig(0),
   fParam(0),
   fNcluster(0),
-  fAmplitudeHisto(0),
+  fNclusters(0),
   fDebugStreamer(0),
-  fRecoParam(0)
+  fRecoParam(0),
+  fBDumpSignal(kFALSE),
+  fBClonesArray(kFALSE)
 {
   //
   // dummy
@@ -150,9 +180,18 @@ AliTPCclustererMI & AliTPCclustererMI::operator =(const AliTPCclustererMI & para
 }
 //______________________________________________________________
 AliTPCclustererMI::~AliTPCclustererMI(){
-  DumpHistos();
-  if (fAmplitudeHisto) delete fAmplitudeHisto;
+  //
+  //
+  //
   if (fDebugStreamer) delete fDebugStreamer;
+  if (fOutputArray){
+    //fOutputArray->Delete();
+    delete fOutputArray;
+  }
+  if (fOutputClonesArray){
+    fOutputClonesArray->Delete();
+    delete fOutputClonesArray;
+  }
 }
 
 void AliTPCclustererMI::SetInput(TTree * tree)
@@ -171,8 +210,11 @@ void AliTPCclustererMI::SetInput(TTree * tree)
 void AliTPCclustererMI::SetOutput(TTree * tree) 
 {
   //
+  // Set the output tree
+  // If not set the ObjArray used - Option for HLT 
   //
-  fOutput= tree;  
+  if (!tree) return;
+  fOutput= tree;
   AliTPCClustersRow clrow;
   AliTPCClustersRow *pclrow=&clrow;  
   clrow.SetClass("AliTPCclusterMI");
@@ -181,6 +223,21 @@ void AliTPCclustererMI::SetOutput(TTree * tree)
 }
 
 
+void AliTPCclustererMI::FillRow(){
+  //
+  // fill the output container - 
+  // 2 Options possible
+  //          Tree       
+  //          TObjArray
+  //
+  if (fOutput) fOutput->Fill();
+  if (!fOutput && !fBClonesArray){
+    //
+    if (!fOutputArray) fOutputArray = new TObjArray(fParam->GetNRowsTotal());
+    if (fRowCl && fRowCl->GetArray()->GetEntriesFast()>0) fOutputArray->AddAt(fRowCl->Clone(), fRowCl->GetID());
+  }
+}
+
 Float_t  AliTPCclustererMI::GetSigmaY2(Int_t iz){
   // sigma y2 = in digits  - we don't know the angle
   Float_t z = iz*fParam->GetZWidth()+fParam->GetNTBinsL1()*fParam->GetZWidth();
@@ -196,7 +253,7 @@ Float_t  AliTPCclustererMI::GetSigmaZ2(Int_t iz){
   //sigma z2 = in digits - angle estimated supposing vertex constraint
   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);
+  Float_t angular = fPadLength*(fParam->GetZLength(fSector)-z)/(fRx*fZWidth);
   angular*=angular;
   angular/=12.;
   Float_t sres = fParam->GetZSigma()/fZWidth;
@@ -220,10 +277,8 @@ AliTPCclusterMI &c)
   // set pointers to data
   //Int_t dummy[5] ={0,0,0,0,0};
   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];
   }
   //build matrix with virtual charge
   Float_t sigmay2= GetSigmaY2(j0);
@@ -311,19 +366,12 @@ AliTPCclusterMI &c)
     meanj +=j0;
     //set cluster parameters
     c.SetQ(sumw);
-    c.SetY(meani*fPadWidth); 
-    c.SetZ(meanj*fZWidth); 
+    c.SetPad(meani-2.5);
+    c.SetTimeBin(meanj-3);
     c.SetSigmaY2(mi2);
     c.SetSigmaZ2(mj2);
-    AddCluster(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] -= vmatrix[di+2][dj+2];
-       if (resmatrix[di+2][dj]<0) resmatrix[di+2][dj]=0;
-      }
-    resmatrix[2][0] =0;
-
+    c.SetType(0);
+    AddCluster(c,(Float_t*)vmatrix,k);
     return;     
   }
   //
@@ -347,18 +395,16 @@ AliTPCclusterMI &c)
   meanj +=j0;
   //set cluster parameters
   c.SetQ(sumu);
-  c.SetY(meani*fPadWidth); 
-  c.SetZ(meanj*fZWidth); 
+  c.SetPad(meani-2.5);
+  c.SetTimeBin(meanj-3);
   c.SetSigmaY2(mi2);
   c.SetSigmaZ2(mj2);
   c.SetType(Char_t(overlap)+1);
-  AddCluster(c);
+  AddCluster(c,(Float_t*)vmatrix,k);
 
   //unfolding 2
   meani-=i0;
   meanj-=j0;
-  if (gDebug>4)
-    printf("%f\t%f\n", vmatrix2[2][2], vmatrix[2][2]);
 }
 
 
@@ -486,8 +532,6 @@ void AliTPCclustererMI::UnfoldCluster(Float_t * matrix2[7], Float_t recmatrix[5]
          }
       }
   }
-  if (gDebug>4) 
-    printf("%f\n", recmatrix[2][2]);
   
 }
 
@@ -510,58 +554,91 @@ Float_t AliTPCclustererMI::FitMax(Float_t vmatrix[5][5], Float_t y, Float_t z, F
   return max;
 }
 
-void AliTPCclustererMI::AddCluster(AliTPCclusterMI &c){
+void AliTPCclustererMI::AddCluster(AliTPCclusterMI &c, Float_t * matrix, Int_t pos){
   //
-  // transform cluster to the global coordinata
-  // add the cluster to the array
   //
-  Float_t meani = c.GetY()/fPadWidth;
-  Float_t meanj = c.GetZ()/fZWidth;
+  // Transform cluster to the rotated global coordinata
+  // Assign labels to the cluster
+  // add the cluster to the array
+  // for more details - See  AliTPCTranform::Transform(x,i,0,1) 
+  Float_t meani = c.GetPad();
+  Float_t meanj = c.GetTimeBin();
 
-  Int_t ki = TMath::Nint(meani-3);
+  Int_t ki = TMath::Nint(meani);
   if (ki<0) ki=0;
   if (ki>=fMaxPad) ki = fMaxPad-1;
-  Int_t kj = TMath::Nint(meanj-3);
+  Int_t kj = TMath::Nint(meanj);
   if (kj<0) kj=0;
   if (kj>=fMaxTime-3) kj=fMaxTime-4;
-  // ki and kj shifted to "real" coordinata
+  // ki and kj shifted as integers coordinata
   if (fRowDig) {
     c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,0)-2,0);
     c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,1)-2,1);
     c.SetLabel(fRowDig->GetTrackIDFast(kj,ki,2)-2,2);
   }
   
-  
+  c.SetRow(fRow);
+  c.SetDetector(fSector);
   Float_t s2 = c.GetSigmaY2();
   Float_t w=fParam->GetPadPitchWidth(fSector);
-  
   c.SetSigmaY2(s2*w*w);
   s2 = c.GetSigmaZ2(); 
-  w=fZWidth;
-  c.SetSigmaZ2(s2*w*w);
-  c.SetY((meani - 2.5 - 0.5*fMaxPad)*fParam->GetPadPitchWidth(fSector));
-  if (!fRecoParam->GetBYMirror()){
-    if (fSector%36>17){
-      c.SetY(-(meani - 2.5 - 0.5*fMaxPad)*fParam->GetPadPitchWidth(fSector));
-    }
+  c.SetSigmaZ2(s2*fZWidth*fZWidth);
+  //
+  //
+  //
+  AliTPCTransform *transform = AliTPCcalibDB::Instance()->GetTransform() ;
+  if (!transform) {
+    AliFatal("Tranformations not in calibDB");
+  }
+  Double_t x[3]={c.GetRow(),c.GetPad(),c.GetTimeBin()};
+  Int_t i[1]={fSector};
+  transform->Transform(x,i,0,1);
+  c.SetX(x[0]);
+  c.SetY(x[1]);
+  c.SetZ(x[2]);
+  //
+  //
+  if (fSector%36>17){
+    c.SetY(-c.GetY());
   }
-  c.SetZ(fZWidth*(meanj-3)); 
-  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.);
     c.SetType(-(c.GetType()+3));  //edge clusters
   }
   if (fLoop==2) c.SetType(100);
+  if (!AcceptCluster(&c)) return;
 
-  TClonesArray * arr = fRowCl->GetArray();
-  // AliTPCclusterMI * cl = 
-  new ((*arr)[fNcluster]) AliTPCclusterMI(c);
+  // select output 
+  TClonesArray * arr = 0;
+  AliTPCclusterMI * cl = 0;
+
+  if(fBClonesArray==kFALSE) {
+     arr = fRowCl->GetArray();
+     cl = new ((*arr)[fNcluster]) AliTPCclusterMI(c);
+  } else {
+     cl = new ((*fOutputClonesArray)[fNclusters+fNcluster]) AliTPCclusterMI(c);
+  }
+
+  // if (fRecoParam->DumpSignal() &&matrix ) {
+//     Int_t nbins=0;
+//     Float_t *graph =0;
+//     if (fRecoParam->GetCalcPedestal() && cl->GetMax()>fRecoParam->GetDumpAmplitudeMin() &&fBDumpSignal){
+//       nbins = fMaxTime;
+//       graph = &(fBins[fMaxTime*(pos/fMaxTime)]);
+//     }
+//     AliTPCclusterInfo * info = new AliTPCclusterInfo(matrix,nbins,graph);
+//     cl->SetInfo(info);
+//   }
+  if (!fRecoParam->DumpSignal()) {
+    cl->SetInfo(0);
+  }
+  
+  if (AliTPCReconstructor::StreamLevel()>1) {
+     (*fDebugStreamer)<<"Clusters"<<
+       "Cl.="<<cl<<
+       "\n";
+  }
 
   fNcluster++;
 }
@@ -579,20 +656,14 @@ void AliTPCclustererMI::Digits2Clusters()
     return;
   }
  
-  if (!fOutput) {
-    Error("Digits2Clusters", "output tree not initialised");
-    return;
-  }
-
   AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
   AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
-
   AliSimDigits digarr, *dummy=&digarr;
   fRowDig = dummy;
   fInput->GetBranch("Segment")->SetAddress(&dummy);
   Stat_t nentries = fInput->GetEntries();
   
-  fMaxTime=fParam->GetMaxTBin()+6; // add 3 virtual time bins before and 3   after
+  fMaxTime=fRecoParam->GetLastBin()+6; // add 3 virtual time bins before and 3   after
     
   Int_t nclusters  = 0;
 
@@ -606,13 +677,9 @@ void AliTPCclustererMI::Digits2Clusters()
     AliTPCCalROC * gainROC = gainTPC->GetCalROC(fSector);  // pad gains per given sector
     AliTPCCalROC * noiseROC   = noiseTPC->GetCalROC(fSector); // noise per given sector
     //
-    AliTPCClustersRow *clrow= new AliTPCClustersRow();
-    fRowCl = clrow;
-    clrow->SetClass("AliTPCclusterMI");
-    clrow->SetArray(1);
 
-    clrow->SetID(digarr.GetID());
-    fOutput->GetBranch("Segment")->SetAddress(&clrow);
+    fRowCl->SetID(digarr.GetID());
+    if (fOutput) fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
     fRx=fParam->GetPadRowRadii(fSector,row);
     
     
@@ -633,9 +700,9 @@ void AliTPCclustererMI::Digits2Clusters()
     
     fMaxBin=fMaxTime*(fMaxPad+6);  // add 3 virtual pads  before and 3 after
     fBins    =new Float_t[fMaxBin];
-    fResBins =new Float_t[fMaxBin];  //fBins with residuals after 1 finder loop 
+    fSigBins =new Int_t[fMaxBin];
+    fNSigBins = 0;
     memset(fBins,0,sizeof(Float_t)*fMaxBin);
-    memset(fResBins,0,sizeof(Float_t)*fMaxBin);
     
     if (digarr.First()) //MI change
       do {
@@ -643,17 +710,19 @@ void AliTPCclustererMI::Digits2Clusters()
        if (dig<=fParam->GetZeroSup()) continue;
        Int_t j=digarr.CurrentRow()+3, i=digarr.CurrentColumn()+3;
        Float_t gain = gainROC->GetValue(row,digarr.CurrentColumn());
-       fBins[i*fMaxTime+j]=dig/gain;
+       Int_t bin = i*fMaxTime+j;
+       fBins[bin]=dig/gain;
+       fSigBins[fNSigBins++]=bin;
       } while (digarr.Next());
     digarr.ExpandTrackBuffer();
 
     FindClusters(noiseROC);
-
-    fOutput->Fill();
-    delete clrow;    
+    FillRow();
+    fRowCl->GetArray()->Clear();    
     nclusters+=fNcluster;    
-    delete[] fBins;      
-    delete[] fResBins;  
+
+    delete[] fBins;
+    delete[] fSigBins;
   }  
 
   Info("Digits2Clusters", "Number of found clusters : %d", nclusters);
@@ -668,27 +737,27 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
 // using an option of the TPC reconstructor
 //-----------------------------------------------------------------
 
-  if (!fOutput) {
-    Error("Digits2Clusters", "output tree not initialised");
-    return;
-  }
 
   fRowDig = NULL;
   AliTPCROC * roc = AliTPCROC::Instance();
   AliTPCCalPad * gainTPC = AliTPCcalibDB::Instance()->GetPadGainFactor();
   AliTPCCalPad * pedestalTPC = AliTPCcalibDB::Instance()->GetPedestals();
   AliTPCCalPad * noiseTPC = AliTPCcalibDB::Instance()->GetPadNoise();
-  AliTPCRawStream input(rawReader);
+  AliTPCAltroMapping** mapping =AliTPCcalibDB::Instance()->GetMapping();
+  //
+  AliTPCRawStream input(rawReader,(AliAltroMapping**)mapping);
   fEventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
   if (fEventHeader){
     fTimeStamp = fEventHeader->Get("Timestamp");  
     fEventType = fEventHeader->Get("Type");  
   }
 
-
-  Int_t nclusters  = 0;
+  // creaate one TClonesArray for all clusters
+  if(fBClonesArray && !fOutputClonesArray) fOutputClonesArray = new TClonesArray("AliTPCclusterMI",1000);
+  // reset counter
+  fNclusters  = 0;
   
-  fMaxTime = fParam->GetMaxTBin() + 6; // add 3 virtual time bins before and 3 after
+  fMaxTime = fRecoParam->GetLastBin() + 6; // add 3 virtual time bins before and 3 after
   const Int_t kNIS = fParam->GetNInnerSector();
   const Int_t kNOS = fParam->GetNOuterSector();
   const Int_t kNS = kNIS + kNOS;
@@ -698,27 +767,26 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
   //alocate memory for sector - maximal case
   //
   Float_t** allBins = NULL;
-  Float_t** allBinsRes = NULL;
+  Int_t** allSigBins = NULL;
+  Int_t*  allNSigBins = NULL;
   Int_t nRowsMax = roc->GetNRows(roc->GetNSector()-1);
   Int_t nPadsMax = roc->GetNPads(roc->GetNSector()-1,nRowsMax-1);
   allBins = new Float_t*[nRowsMax];
-  allBinsRes = new Float_t*[nRowsMax];
+  allSigBins = new Int_t*[nRowsMax];
+  allNSigBins = new Int_t[nRowsMax];
   for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
     //
     Int_t maxBin = fMaxTime*(nPadsMax+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);
+    allSigBins[iRow] = new Int_t[maxBin];
+    allNSigBins[iRow]=0;
   }
   //
   // Loop over sectors
   //
   for(fSector = 0; fSector < kNS; fSector++) {
 
-    AliTPCCalROC * gainROC    = gainTPC->GetCalROC(fSector);  // pad gains per given sector
-    AliTPCCalROC * pedestalROC = pedestalTPC->GetCalROC(fSector);  // pedestal per given sector
-    AliTPCCalROC * noiseROC   = noiseTPC->GetCalROC(fSector);  // noise per given sector
     Int_t nRows = 0;
     Int_t nDDLs = 0, indexDDL = 0;
     if (fSector < kNIS) {
@@ -734,6 +802,23 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
       indexDDL = (fSector-kNIS) * 4 + kNIS * 2;
     }
 
+    // load the raw data for corresponding DDLs
+    rawReader->Reset();
+    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
+
+    // select only good sector 
+    input.Next();
+    if(input.GetSector() != fSector) continue;
+
+    AliTPCCalROC * gainROC    = gainTPC->GetCalROC(fSector);  // pad gains per given sector
+    AliTPCCalROC * pedestalROC = pedestalTPC->GetCalROC(fSector);  // pedestal per given sector
+    AliTPCCalROC * noiseROC   = noiseTPC->GetCalROC(fSector);  // noise per given sector
+    //check the presence of the calibration
+    if (!noiseROC ||!pedestalROC ) {
+      AliError(Form("Missing calibration per sector\t%d\n",fSector));
+      continue;
+    }
+    
     for (Int_t iRow = 0; iRow < nRows; iRow++) {
       Int_t maxPad;
       if (fSector < kNIS)
@@ -743,32 +828,38 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
       
       Int_t maxBin = fMaxTime*(maxPad+6);  // add 3 virtual pads  before and 3 after
       memset(allBins[iRow],0,sizeof(Float_t)*maxBin);
+      allNSigBins[iRow] = 0;
     }
     
-    // Loas the raw data for corresponding DDLs
-    rawReader->Reset();
-    input.SetOldRCUFormat(fIsOldRCUFormat);
-    rawReader->Select("TPC",indexDDL,indexDDL+nDDLs-1);
     Int_t digCounter=0;
     // Begin loop over altro data
     Bool_t calcPedestal = fRecoParam->GetCalcPedestal();
     Float_t gain =1;
     Int_t lastPad=-1;
+
+    input.Reset();
     while (input.Next()) {
-      digCounter++;
       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) !",
+      if (iRow < 0){
+       continue;
+      }
+
+      if (iRow < 0 || iRow >= nRows){
+       AliError(Form("Pad-row index (%d) outside the range (%d -> %d) !",
                      iRow, 0, nRows -1));
+       continue;
+      }
       //pad
       Int_t iPad = input.GetPad();
-      if (iPad < 0 || iPad >= nPadsMax)
-       AliFatal(Form("Pad index (%d) outside the range (%d -> %d) !",
+      if (iPad < 0 || iPad >= nPadsMax) {
+       AliError(Form("Pad index (%d) outside the range (%d -> %d) !",
                      iPad, 0, nPadsMax-1));
+       continue;
+      }
       if (iPad!=lastPad){
        gain    = gainROC->GetValue(iRow,iPad);
        lastPad = iPad;
@@ -776,26 +867,37 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
       iPad+=3;
       //time
       Int_t iTimeBin = input.GetTime();
-      if ( iTimeBin < 0 || iTimeBin >= fParam->GetMaxTBin())
+      if ( iTimeBin < fRecoParam->GetFirstBin() || iTimeBin >= fRecoParam->GetLastBin()){
+       continue;
        AliFatal(Form("Timebin index (%d) outside the range (%d -> %d) !",
                      iTimeBin, 0, iTimeBin -1));
+      }
       iTimeBin+=3;
+
       //signal
       Float_t signal = input.GetSignal();
       if (!calcPedestal && signal <= zeroSup) continue;      
+
       if (!calcPedestal) {
-       allBins[iRow][iPad*fMaxTime+iTimeBin] = signal/gain;
+       Int_t bin = iPad*fMaxTime+iTimeBin;
+       allBins[iRow][bin] = signal/gain;
+       allSigBins[iRow][allNSigBins[iRow]++] = bin;
       }else{
        allBins[iRow][iPad*fMaxTime+iTimeBin] = signal;
       }
-      allBins[iRow][iPad*fMaxTime+0]=1.;  // pad with signal
+      allBins[iRow][iPad*fMaxTime+0]+=1.;  // pad with signal
+
+      // Temporary
+      digCounter++;
     } // End of the loop over altro data
     //
     //
+    //
+    //
     // Now loop over rows and perform pedestal subtraction
     if (digCounter==0) continue;
-    //    if (fPedSubtraction) {
-    if (calcPedestal) {
+    //    if (calcPedestal) {
+    if (kTRUE) {
       for (Int_t iRow = 0; iRow < nRows; iRow++) {
        Int_t maxPad;
        if (fSector < kNIS)
@@ -804,6 +906,15 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
          maxPad = fParam->GetNPadsUp(iRow);
 
        for (Int_t iPad = 3; iPad < maxPad + 3; iPad++) {
+         //
+         // Temporary fix for data production - !!!! MARIAN
+         // The noise calibration should take mean and RMS - currently the Gaussian fit used
+         // In case of double peak  - the pad should be rejected
+         //
+         // Line mean - if more than given digits over threshold - make a noise calculation
+         // and pedestal substration
+         if (!calcPedestal && allBins[iRow][iPad*fMaxTime+0]<50) continue;
+         //
          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);      
@@ -819,26 +930,65 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
          
          //
          for (Int_t iTimeBin = 0; iTimeBin < fMaxTime; iTimeBin++) {
-           allBins[iRow][iPad*fMaxTime+iTimeBin] -= pedestalEvent;
+           Int_t bin = iPad*fMaxTime+iTimeBin;
+           allBins[iRow][bin] -= pedestalEvent;
            if (iTimeBin < AliTPCReconstructor::GetRecoParam()->GetFirstBin())  
-             allBins[iRow][iPad*fMaxTime+iTimeBin] = 0;
+             allBins[iRow][bin] = 0;
            if (iTimeBin > AliTPCReconstructor::GetRecoParam()->GetLastBin())  
-             allBins[iRow][iPad*fMaxTime+iTimeBin] = 0;
+             allBins[iRow][bin] = 0;
            if (allBins[iRow][iPad*fMaxTime+iTimeBin] < zeroSup)
-             allBins[iRow][iPad*fMaxTime+iTimeBin] = 0;
-           if (allBins[iRow][iPad*fMaxTime+iTimeBin] < 3.0*rmsEvent)   // 3 sigma cut on RMS
-             allBins[iRow][iPad*fMaxTime+iTimeBin] = 0;            
+             allBins[iRow][bin] = 0;
+           if (allBins[iRow][bin] < 3.0*rmsEvent)   // 3 sigma cut on RMS
+             allBins[iRow][bin] = 0;
+           if (allBins[iRow][bin]) allSigBins[iRow][allNSigBins[iRow]++] = bin;
          }
        }
       }
     }
+
+    if (AliTPCReconstructor::StreamLevel()>3) {
+      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 = 3; iPad < maxPad + 3; iPad++) {
+         for (Int_t iTimeBin = 0; iTimeBin < fMaxTime; iTimeBin++) {
+           Int_t bin = iPad*fMaxTime+iTimeBin;
+           Float_t signal = allBins[iRow][bin];
+           if (AliTPCReconstructor::StreamLevel()>3 && signal>3) {
+             Double_t x[]={iRow,iPad-3,iTimeBin-3};
+             Int_t i[]={fSector};
+             AliTPCTransform trafo;
+             trafo.Transform(x,i,0,1);
+             Double_t gx[3]={x[0],x[1],x[2]};
+             trafo.RotatedGlobal2Global(fSector,gx);
+             
+             (*fDebugStreamer)<<"Digits"<<
+               "sec="<<fSector<<
+               "row="<<iRow<<
+               "pad="<<iPad<<
+               "time="<<iTimeBin<<
+               "sig="<<signal<<
+               "x="<<x[0]<<
+               "y="<<x[1]<<
+               "z="<<x[2]<<      
+               "gx="<<gx[0]<<
+               "gy="<<gx[1]<<
+               "gz="<<gx[2]<<
+               "\n";
+           }
+         }
+       }
+      }
+    }
+
     // 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);
+      if (fOutput) fOutput->GetBranch("Segment")->SetAddress(&fRowCl);
 
       fRx = fParam->GetPadRowRadii(fSector, fRow);
       fPadLength = fParam->GetPadPitchLength(fSector, fRow);
@@ -850,25 +1000,37 @@ void AliTPCclustererMI::Digits2Clusters(AliRawReader* rawReader)
       fMaxBin = fMaxTime*(fMaxPad+6);  // add 3 virtual pads  before and 3 after
 
       fBins = allBins[fRow];
-      fResBins = allBinsRes[fRow];
+      fSigBins = allSigBins[fRow];
+      fNSigBins = allNSigBins[fRow];
 
       FindClusters(noiseROC);
 
-      fOutput->Fill();
-      delete fRowCl;    
-      nclusters += fNcluster;    
+      FillRow();
+      if(fBClonesArray == kFALSE) fRowCl->GetArray()->Clear();    
+      fNclusters += fNcluster;    
+
     } // End of loop to find clusters
   } // End of loop over sectors
-  
+
   for (Int_t iRow = 0; iRow < nRowsMax; iRow++) {
     delete [] allBins[iRow];
-    delete [] allBinsRes[iRow];
+    delete [] allSigBins[iRow];
   }  
   delete [] allBins;
-  delete [] allBinsRes;
+  delete [] allSigBins;
+  delete [] allNSigBins;
   
-  Info("Digits2Clusters", "File  %s Event\t%d\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), nclusters);
+  if (rawReader->GetEventId() && fOutput ){
+    Info("Digits2Clusters", "File  %s Event\t%d\tNumber of found clusters : %d\n", fOutput->GetName(),*(rawReader->GetEventId()), fNclusters);
+  }
+  
+  if(rawReader->GetEventId()) {
+    Info("Digits2Clusters", "Event\t%d\tNumber of found clusters : %d\n",*(rawReader->GetEventId()), fNclusters);
+  }
 
+  if(fBClonesArray) {
+    //Info("Digits2Clusters", "Number of found clusters : %d\n",fOutputClonesArray->GetEntriesFast());
+  }
 }
 
 void AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
@@ -877,65 +1039,45 @@ void AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
   //
   // add virtual charge at the edge   
   //
-  if (0) for (Int_t i=0; i<fMaxTime; i++){
-    Float_t amp1 = fBins[i+3*fMaxTime]; 
-    Float_t amp0 =0;
-    if (amp1>0){
-      Float_t amp2 = fBins[i+4*fMaxTime];
-      if (amp2==0) amp2=0.5;
-      Float_t sigma2 = GetSigmaY2(i);          
-      amp0 = (amp1*amp1/amp2)*TMath::Exp(-1./sigma2);  
-      if (gDebug>4) printf("\n%f\n",amp0);
-    }  
-    fBins[i+2*fMaxTime] = amp0;    
-    amp0 = 0;
-    amp1 = fBins[(fMaxPad+2)*fMaxTime+i];
-    if (amp1>0){
-      Float_t amp2 = fBins[i+(fMaxPad+1)*fMaxTime];
-      if (amp2==0) amp2=0.5;
-      Float_t sigma2 = GetSigmaY2(i);          
-      amp0 = (amp1*amp1/amp2)*TMath::Exp(-1./sigma2);          
-      if (gDebug>4) printf("\n%f\n",amp0);
-    }        
-    fBins[(fMaxPad+3)*fMaxTime+i] = amp0;           
+  Double_t kMaxDumpSize = 500000;
+  if (!fOutput) {
+    fBDumpSignal =kFALSE;
+  }else{
+    if (fRecoParam->GetCalcPedestal() && fOutput->GetZipBytes()< kMaxDumpSize) fBDumpSignal =kTRUE;   //dump signal flag
   }
-  memcpy(fResBins,fBins, fMaxBin*sizeof(Float_t));
-  //
-  //
-  //
+   
   fNcluster=0;
   fLoop=1;
-  Float_t *b=&fBins[-1]+2*fMaxTime;
-  Int_t crtime = Int_t((fParam->GetZLength()-fRecoParam->GetCtgRange()*fRx)/fZWidth-fParam->GetNTBinsL1()-5);
+  Int_t crtime = Int_t((fParam->GetZLength(fSector)-fRecoParam->GetCtgRange()*fRx)/fZWidth-fParam->GetNTBinsL1()-5);
   Float_t minMaxCutAbs       = fRecoParam->GetMinMaxCutAbs();
   Float_t minLeftRightCutAbs = fRecoParam->GetMinLeftRightCutAbs();
   Float_t minUpDownCutAbs    = fRecoParam->GetMinUpDownCutAbs();
   Float_t minMaxCutSigma       = fRecoParam->GetMinMaxCutSigma();
   Float_t minLeftRightCutSigma = fRecoParam->GetMinLeftRightCutSigma();
   Float_t minUpDownCutSigma    = fRecoParam->GetMinUpDownCutSigma();
-  for (Int_t i=2*fMaxTime; i<fMaxBin-2*fMaxTime; i++) {
-    b++;
-    if (i%fMaxTime<crtime) {
-      Int_t delta = -(i%fMaxTime)+crtime;
-      b+=delta;
-      i+=delta;
-      continue; 
-    }
+  for (Int_t iSig = 0; iSig < fNSigBins; iSig++) {
+    Int_t i = fSigBins[iSig];
+    if (i%fMaxTime<=crtime) continue;
+    Float_t *b = &fBins[i];
     //absolute custs
-    if (b[0]<minMaxCutAbs) continue;   //threshold form maxima  
+    if (b[0]<minMaxCutAbs) continue;   //threshold for maxima  
+    //
+    if (b[-1]+b[1]+b[-fMaxTime]+b[fMaxTime]<=0) continue;  // cut on isolated clusters 
     if (b[-1]+b[1]<=0) continue;               // cut on isolated clusters
     if (b[-fMaxTime]+b[fMaxTime]<=0) continue; // cut on isolated clusters
-    if ((b[0]+b[-1]+b[1])<minUpDownCutAbs) continue;   //threshold for up town TRF 
+    //
+    if ((b[0]+b[-1]+b[1])<minUpDownCutAbs) continue;   //threshold for up down  (TRF) 
     if ((b[0]+b[-fMaxTime]+b[fMaxTime])<minLeftRightCutAbs) continue;   //threshold for left right (PRF)    
     if (!IsMaximum(*b,fMaxTime,b)) continue;
     //
     Float_t noise = noiseROC->GetValue(fRow, i/fMaxTime);
+    if (noise>fRecoParam->GetMaxNoise()) continue;
     // sigma cuts
     if (b[0]<minMaxCutSigma*noise) continue;   //threshold form maxima  
     if ((b[0]+b[-1]+b[1])<minUpDownCutSigma*noise) continue;   //threshold for up town TRF 
     if ((b[0]+b[-fMaxTime]+b[fMaxTime])<minLeftRightCutSigma*noise) continue;   //threshold for left right (PRF)    
   
-    AliTPCclusterMI c;
+    AliTPCclusterMI c;   // default cosntruction  without info
     Int_t dummy=0;
     MakeCluster(i, fMaxTime, fBins, dummy,c);
     
@@ -943,6 +1085,22 @@ void AliTPCclustererMI::FindClusters(AliTPCCalROC * noiseROC)
   }
 }
 
+Bool_t AliTPCclustererMI::AcceptCluster(AliTPCclusterMI *cl){
+  //
+  // Currently hack to filter digital noise (15.06.2008)
+  // To be parameterized in the AliTPCrecoParam
+  // More inteligent way  to be used in future
+  // Acces to the proper pedestal file needed
+  //
+  if (cl->GetMax()<400) return kTRUE;
+  Double_t ratio = cl->GetQ()/cl->GetMax();
+  if (cl->GetMax()>700){
+    if ((ratio - int(ratio)>0.8)) return kFALSE;
+  }
+  if ((ratio - int(ratio)<0.95)) return kTRUE;
+  return kFALSE;
+}
+
 
 Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t id[3], Double_t &rmsEvent, Double_t &pedestalEvent){
   //
@@ -955,7 +1113,6 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
   //
   // ESTIMATE pedestal and the noise
   // 
-  Int_t offset =100;
   const Int_t kPedMax = 100;
   Float_t  max    =  0;
   Float_t  maxPos =  0;
@@ -967,7 +1124,8 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
   Int_t    firstBin = AliTPCReconstructor::GetRecoParam()->GetFirstBin();
   //
   UShort_t histo[kPedMax];
-  memset(histo,0,kPedMax*sizeof(UShort_t));
+  //memset(histo,0,kPedMax*sizeof(UShort_t));
+  for (Int_t i=0; i<kPedMax; i++) histo[i]=0;
   for (Int_t i=0; i<fMaxTime; i++){
     if (signal[i]<=0) continue;
     if (signal[i]>max && i>firstBin) {
@@ -985,9 +1143,9 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
   }
   // truncated mean  
   //
-  Double_t count10=histo[median] ,mean=histo[median]*median,  rms=histo[median]*median*median ;
-  Double_t count06=histo[median] ,mean06=histo[median]*median,  rms06=histo[median]*median*median ;
-  Double_t count09=histo[median] ,mean09=histo[median]*median,  rms09=histo[median]*median*median ;
+  Float_t count10=histo[median] ,mean=histo[median]*median,  rms=histo[median]*median*median ;
+  Float_t count06=histo[median] ,mean06=histo[median]*median,  rms06=histo[median]*median*median ;
+  Float_t count09=histo[median] ,mean09=histo[median]*median,  rms09=histo[median]*median*median ;
   //
   for (Int_t idelta=1; idelta<10; idelta++){
     if (median-idelta<=0) continue;
@@ -1017,12 +1175,18 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
       rms  +=histo[median+idelta]*(median+idelta)*(median+idelta);
     }
   }
-  mean  /=count10;
-  mean06/=count06;
-  mean09/=count09;
-  rms    = TMath::Sqrt(TMath::Abs(rms/count10-mean*mean));
-  rms06    = TMath::Sqrt(TMath::Abs(rms06/count06-mean06*mean06));
- rms09    = TMath::Sqrt(TMath::Abs(rms09/count09-mean09*mean09));
+  if (count10) {
+    mean  /=count10;
+    rms    = TMath::Sqrt(TMath::Abs(rms/count10-mean*mean));
+  }
+  if (count06) {
+    mean06/=count06;
+    rms06    = TMath::Sqrt(TMath::Abs(rms06/count06-mean06*mean06));
+  }
+  if (count09) {
+    mean09/=count09;
+    rms09    = TMath::Sqrt(TMath::Abs(rms09/count09-mean09*mean09));
+  }
   rmsEvent = rms09;
   //
   pedestalEvent = median;
@@ -1054,36 +1218,6 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
   //
   // fill pedestal histogram
   //
-  AliTPCROC * roc = AliTPCROC::Instance();
-  if (!fAmplitudeHisto){
-    fAmplitudeHisto = new TObjArray(72);
-  }  
-  //
-  if (uid[0]<roc->GetNSectors() 
-      && uid[1]< roc->GetNRows(uid[0])  && 
-      uid[2] <roc->GetNPads(uid[0], uid[1])){
-    TObjArray  * sectorArray = (TObjArray*)fAmplitudeHisto->UncheckedAt(uid[0]);
-    if (!sectorArray){
-      Int_t npads =roc->GetNChannels(uid[0]);
-      sectorArray = new TObjArray(npads);
-      fAmplitudeHisto->AddAt(sectorArray, uid[0]);
-    }
-    Int_t position =  uid[2]+roc->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++){
-      histo->Fill(signal[i]);
-    }
-  }
   //
   //
   //
@@ -1094,154 +1228,31 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
     dtime[i] = i;
     dsignal[i] = 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
-       "TimeStamp="<<fTimeStamp<<
-       "EventType="<<fEventType<<
-       "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 &&maxPos>AliTPCReconstructor::GetRecoParam()->GetFirstBin()) 
-      (*fDebugStreamer)<<"SignalB"<<     // pads with signal
-       "TimeStamp="<<fTimeStamp<<
-       "EventType="<<fEventType<<
-       "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;
-  }
-  
-  //
-  //
-  //  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    kCemin=5;  // range for the analysis of the ce signal +- channels from the peak
-  const Int_t    kCemax=5;
-  for (Int_t i=nchannels-2; i>nchannels/2; i--){
-    if ( (dsignal[i]-mean06)>ceThreshold && dsignal[i]>=dsignal[i+1] && dsignal[i]>=dsignal[i-1] ){
-      cemaxpos=i;
-      break;
-    }
-  }
-  if (cemaxpos!=0){
-    ceQmax = 0;
-    Int_t cemaxpos2=0;
-    for (Int_t i=cemaxpos-20; i<cemaxpos+5; i++){
-      if (i<0 || i>nchannels-1) continue;
-      Double_t val=dsignal[i]- cemean;
-      if (val>ceQmax){
-       cemaxpos2=i;
-       ceQmax = val;
-      }
-    }
-    cemaxpos = cemaxpos2;
-    for (Int_t i=cemaxpos-kCemin; i<cemaxpos+kCemax; i++){
-      if (i>0 && i<nchannels&&dsignal[i]- cemean>0){
-       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"<<
-       "TimeStamp="<<fTimeStamp<<
-       "EventType="<<fEventType<<
-       "Sector="<<uid[0]<<
-       "Row="<<uid[1]<<
-       "Pad="<<uid[2]<<
-       "Max="<<ceQmax<<
-       "Qsum="<<ceQsum<<
-       "Time="<<ceTime<<
-       "RMS06="<<rms06<<
-       //
-       "\n";
-    }
-  }
-  // end of ce signal analysis
-  //
 
+  TGraph * graph=0;
   //
-  //  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;
-
-  for (Int_t i=1; i<nchannels/4; i++){
-    if ( (dsignal[i]-mean06)>ggThreshold && dsignal[i]>=dsignal[i+1] && dsignal[i]>=dsignal[i-1] &&
-        (dsignal[i]+dsignal[i+1]+dsignal[i-1]-3*mean06)>ggSumThreshold){
-      ggmaxpos=i;
-      if (dsignal[i-1]>dsignal[i+1]) ggmaxpos=i-1;
-      break;
-    }
-  }
-  if (ggmaxpos!=0){
-      for (Int_t i=ggmaxpos-1; i<ggmaxpos+3; i++){       
-         if (i>0 && i<nchannels && dsignal[i]-ggmean>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"<<
-           "TimeStamp="<<fTimeStamp<<
-           "EventType="<<fEventType<<
-             "Sector="<<uid[0]<<
-             "Row="<<uid[1]<<
-             "Pad="<<uid[2]<<
-             "Max="<<ggQmax<<
-             "Qsum="<<ggQsum<<
-             "Time="<<ggTime<<
-             "RMS06="<<rms06<<
-             //
-             "\n";
-      }
-  }
-  // end of gg signal analysis
-      
+  // Big signals dumping
+  //    
+  if (max-median>kMin &&maxPos>AliTPCReconstructor::GetRecoParam()->GetFirstBin()) 
+    (*fDebugStreamer)<<"SignalB"<<     // pads with signal
+      "TimeStamp="<<fTimeStamp<<
+      "EventType="<<fEventType<<
+      "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;  
 
   delete [] dsignal;
   delete [] dtime;
@@ -1254,51 +1265,5 @@ Double_t AliTPCclustererMI::ProcesSignal(Float_t *signal, Int_t nchannels, Int_t
 
 
 
-void AliTPCclustererMI::DumpHistos(){
-  //
-  // Dump histogram information
-  //
-  if (!fAmplitudeHisto) return;
-  AliTPCROC * roc = AliTPCROC::Instance();
-  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 =roc->GetRowIndexes(isector);
-      for (UInt_t irow=0; irow<roc->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"<<
-       "TimeStamp="<<fTimeStamp<<
-       "EventType="<<fEventType<<
-       "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));
-    }
-  }
-}
+
+