]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFClusterFinder.cxx
Sergey: bug fix with storing cluster id's
[u/mrichter/AliRoot.git] / TOF / AliTOFClusterFinder.cxx
index cd78f2e4dc842322fe1724c129990654e7e7aac8..7d281b8ec5b43ac11bff11deef1f98866162a342 100644 (file)
  **************************************************************************/
 
 /* 
-$Log$
+$Log: AliTOFClusterFinder.cxx,v $
+Revision 1.31  2007/11/24 14:53:19  zampolli
+Status flag implemented as UChar_t
+
 Revision 1.30  2007/10/04 13:08:52  arcelli
 updates to comply with AliTOFGeometryV5 becoming AliTOFGeometry
 
@@ -25,7 +28,9 @@ Revision 1.28  2007/05/31 16:06:05  arcelli
 move instance of AliRawStream outside loop on DDL
 
 Revision 1.27  2007/05/02 16:31:49  arcelli
-Add methods to handle single event reconstruction. retrieval of Calib info moved to AliTOFReconstructor ctor, and passed via a pointer to AliTOFcalib
+Add methods to handle single event reconstruction.  retrieval of Calib
+info moved to AliTOFReconstructor ctor, and passed via a pointer to
+AliTOFcalib
 
 Revision 1.26  2007/04/30 19:02:24  arcelli
 hopefully the last refinements for correct type conversion in calibration
@@ -37,7 +42,8 @@ Revision 1.24  2007/04/27 11:19:31  arcelli
 updates for the new decoder
 
 Revision 1.23  2007/04/23 16:51:39  decaro
-Digits-to-raw_data conversion: correction for a more real description (A.De Caro, R.Preghenella)
+Digits-to-raw_data conversion: correction for a more real description
+(A.De Caro, R.Preghenella)
 
 Revision 1.22  2007/04/19 17:26:32  arcelli
 Fix a bug (add some debug printout
@@ -55,7 +61,8 @@ Revision 1.18  2007/03/06 16:31:20  arcelli
 Add Uncorrected TOF Time signal
 
 Revision 1.17  2007/02/28 18:09:11  arcelli
-Add protection against failed retrieval of the CDB cal object, now Reconstruction exits with AliFatal
+Add protection against failed retrieval of the CDB cal object,
+now Reconstruction exits with AliFatal
 
 Revision 1.16  2007/02/20 15:57:00  decaro
 Raw data update: to read the TOF raw data defined in UNPACKED mode
@@ -96,32 +103,33 @@ Revision 0.01  2005/07/25 A. De Caro
 //                                                            //
 ////////////////////////////////////////////////////////////////
 
+#include "Riostream.h"
 
 #include "TClonesArray.h"
 #include "TStopwatch.h"
 #include "TTree.h"
-#include <TGeoManager.h>
-#include <AliGeomManager.h>
+//#include <TGeoManager.h>
 #include <TGeoMatrix.h>
-#include <TGeoPhysicalNode.h>
-#include "AliAlignObj.h"
+//#include <TGeoPhysicalNode.h>
 
 #include "AliDAQ.h"
 #include "AliLoader.h"
 #include "AliLog.h"
 #include "AliRawReader.h"
 #include "AliRunLoader.h"
+//#include "AliAlignObj.h"
+#include <AliGeomManager.h>
 
 #include "AliTOFcalib.h"
-#include "AliTOFChannelOnline.h"
+#include "AliTOFChannelOnlineArray.h"
+#include "AliTOFChannelOnlineStatusArray.h"
 #include "AliTOFChannelOffline.h"
 #include "AliTOFClusterFinder.h"
 #include "AliTOFcluster.h"
 #include "AliTOFdigit.h"
 #include "AliTOFGeometry.h"
 #include "AliTOFrawData.h"
-#include "AliTOFRawStream.h"
-#include "Riostream.h"
+//#include "AliTOFRawStream.h"
 
 //extern TFile *gFile;
 
@@ -137,13 +145,15 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
   fNumberOfTofClusters(0),
   fVerbose(0),
   fDecoderVersion(0),
-  fTOFcalib(calib)
+  fTOFcalib(calib),
+  fTOFRawStream(AliTOFRawStream())
 {
 //
 // Constructor
 //
 
 }
+
 //______________________________________________________________________________
 
 AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *calib):
@@ -156,7 +166,8 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *c
   fNumberOfTofClusters(0),
   fVerbose(0),
   fDecoderVersion(0),
-  fTOFcalib(calib)
+  fTOFcalib(calib),
+  fTOFRawStream(AliTOFRawStream())
 {
 //
 // Constructor
@@ -166,35 +177,37 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *c
 
 //------------------------------------------------------------------------
 AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
-  :TObject(),
+  :TObject(source),
   fRunLoader(0),
   fTOFLoader(0),
   fTreeD(0),
   fTreeR(0),
-  fDigits(new TClonesArray("AliTOFdigit", 4000)),
-  fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
+  fDigits(source.fDigits),
+  fRecPoints(source.fRecPoints),
   fNumberOfTofClusters(0),
   fVerbose(0),
-  fDecoderVersion(0),
-  fTOFcalib(0)
+  fDecoderVersion(source.fDecoderVersion),
+  fTOFcalib(source.fTOFcalib),
+  fTOFRawStream(source.fTOFRawStream)
 {
   // copy constructor
-  this->fDigits=source.fDigits;
-  this->fRecPoints=source.fRecPoints;
-  this->fDecoderVersion=source.fDecoderVersion;
-  this->fTOFcalib=source.fTOFcalib;
-
 }
 
 //------------------------------------------------------------------------
 AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &source)
 {
   // ass. op.
-  this->fDigits=source.fDigits;
-  this->fRecPoints=source.fRecPoints;
-  this->fVerbose=source.fVerbose;
-  this->fDecoderVersion=source.fDecoderVersion;
-  this->fTOFcalib=source.fTOFcalib;
+
+  if (this == &source)
+    return *this;
+
+  TObject::operator=(source);  
+  fDigits=source.fDigits;
+  fRecPoints=source.fRecPoints;
+  fVerbose=source.fVerbose;
+  fDecoderVersion=source.fDecoderVersion;
+  fTOFcalib=source.fTOFcalib;
+  fTOFRawStream=source.fTOFRawStream;
   return *this;
 
 }
@@ -232,6 +245,8 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
   TStopwatch stopwatch;
   stopwatch.Start();
 
+  Int_t inholes = 0;
+
   fRunLoader->GetEvent(iEvent);
 
   fTreeD = fTOFLoader->TreeD();
@@ -246,7 +261,9 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
     return;
   }
 
-  TClonesArray *digits = new TClonesArray("AliTOFdigit",10000);
+  TClonesArray staticdigits("AliTOFdigit",10000);
+  staticdigits.Clear();
+  TClonesArray *digits =&staticdigits;
   branch->SetAddress(&digits);
 
   ResetRecpoint();
@@ -277,7 +294,18 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
     dig[3]=d->GetPadz();
     dig[4]=d->GetPadx();
 
-    //    AliDebug(2,Form(" %2i  %1i  %2i  %1i  %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
+    /* check valid index */
+    if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
+
+    // Do not reconstruct anything in the holes
+    if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
+      if (dig[1]==2) { // plate with holes
+       inholes++;
+       continue;
+      }
+    }
+
+    AliDebug(2,Form(" %2d  %1d  %2d  %1d  %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
 
     parTOF[0] = d->GetTdc(); //the TDC signal
     parTOF[1] = d->GetToT(); //the ToT signal
@@ -290,10 +318,10 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
     GetClusterPars(dig, posClus,covClus);
     AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],d->GetTracks(),dig,parTOF,status,ii);
     InsertCluster(tofCluster);
-
+    
   }
 
-  AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
+  AliInfo(Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
 
   CalibrateRecPoint();
   FillRecPoint();
@@ -306,9 +334,8 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
 
   AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
               stopwatch.RealTime(),stopwatch.CpuTime()));
+  if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
 
-  digits->Delete();
-  delete digits;
 }
 
 //______________________________________________________________________________
@@ -322,6 +349,8 @@ void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree
   TStopwatch stopwatch;
   stopwatch.Start();
 
+  Int_t inholes = 0;
+
   ///  fRunLoader->GetEvent(iEvent);
 
   if (digitsTree == 0x0)
@@ -335,7 +364,9 @@ void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree
     return;
   }
 
-  TClonesArray *digits = new TClonesArray("AliTOFdigit",10000);
+  TClonesArray staticdigits("AliTOFdigit",10000);
+  staticdigits.Clear();
+  TClonesArray *digits = & staticdigits;
   branch->SetAddress(&digits);
 
   ResetRecpoint();
@@ -360,7 +391,18 @@ void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree
     dig[3]=d->GetPadz();
     dig[4]=d->GetPadx();
 
-    //    AliDebug(2,Form(" %2i  %1i  %2i  %1i  %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
+    /* check valid index */
+    if (dig[0]==-1||dig[1]==-1||dig[2]==-1||dig[3]==-1||dig[4]==-1) continue;
+
+    // Do not reconstruct anything in the holes
+    if (dig[0]==13 || dig[0]==14 || dig[0]==15 ) { // sectors with holes
+      if (dig[1]==2) { // plate with holes
+       inholes++;
+       continue;
+      }
+    }
+
+    //    AliDebug(2,Form(" %2d  %1d  %2d  %1d  %2d ",dig[0],dig[1],dig[2],dig[3],dig[4]));
 
     parTOF[0] = d->GetTdc(); //the TDC signal
     parTOF[1] = d->GetToT(); //the ToT signal
@@ -372,12 +414,12 @@ void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree
     Double_t covClus[6];
     UShort_t volIdClus=GetClusterVolIndex(dig);
     GetClusterPars(dig,posClus,covClus);
-   AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],d->GetTracks(),dig,parTOF,status,ii);
+    AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],d->GetTracks(),dig,parTOF,status,ii);
     InsertCluster(tofCluster);
 
   }
 
-  AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
+  AliInfo(Form("Number of found clusters: %d", fNumberOfTofClusters));
 
   CalibrateRecPoint();
   FillRecPoint();
@@ -387,9 +429,8 @@ void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree
 
   AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
               stopwatch.RealTime(),stopwatch.CpuTime()));
+  if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
 
-  digits->Delete();
-  delete digits;
 }
 //______________________________________________________________________________
 
@@ -403,7 +444,8 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
   TStopwatch stopwatch;
   stopwatch.Start();
 
-  //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
+  Int_t inholes = 0;
+
   const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
 
   ResetRecpoint();
@@ -421,7 +463,9 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
   ofstream ftxt;
   if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
 
-  AliTOFRawStream tofInput(rawReader);
+  //AliTOFRawStream tofInput(rawReader);
+  fTOFRawStream.Clear();
+  fTOFRawStream.SetRawReader(rawReader);
 
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
@@ -429,17 +473,18 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
     rawReader->Reset();
     if (fDecoderVersion) {
       AliInfo("Using New Decoder \n"); 
-      tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
+      fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
     }
-    else tofInput.LoadRawData(indexDDL);
+    else fTOFRawStream.LoadRawData(indexDDL);
 
-    clonesRawData = (TClonesArray*)tofInput.GetRawData();
+    clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
 
     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
 
       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
 
-      if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
+      //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
+      if (tofRawDatum->GetTOF()==-1) continue;
 
       if (fVerbose==2) {
        if (indexDDL<10) ftxt << "  " << indexDDL;
@@ -452,8 +497,8 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
        ftxt << "  " << tofRawDatum->GetTDCchannel();
       }
 
-      tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
-                                   tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
+      fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
+                                        tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
       dummy = detectorIndex[3];
       detectorIndex[3] = detectorIndex[4];
       detectorIndex[4] = dummy;
@@ -469,6 +514,17 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
        else              ftxt << " " << detectorIndex[4];
       }
 
+    /* check valid index */
+    if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
+
+      // Do not reconstruct anything in the holes
+      if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
+       if (detectorIndex[1]==2) { // plate with holes
+         inholes++;
+         continue;
+       }
+      }
+
       parTOF[0] = tofRawDatum->GetTOF(); //TDC
       parTOF[1] = tofRawDatum->GetTOT(); // TOT
       parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
@@ -480,7 +536,7 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
       Int_t lab[3]={-1,-1,-1};
       Bool_t status=kTRUE;
       GetClusterPars(detectorIndex,posClus,covClus);
-     AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],lab,detectorIndex,parTOF,status,-1);
+      AliTOFcluster *tofCluster = new AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],lab,detectorIndex,parTOF,status,-1);
       InsertCluster(tofCluster);
 
       if (fVerbose==2) {
@@ -501,7 +557,7 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
 
   if (fVerbose==2) ftxt.close();
 
-  AliInfo(Form("Number of found clusters: %i", fNumberOfTofClusters));
+  AliInfo(Form("Number of found clusters: %d", fNumberOfTofClusters));
 
   CalibrateRecPoint();
   FillRecPoint();
@@ -512,6 +568,7 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
 
   AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
                   stopwatch.RealTime(),stopwatch.CpuTime()));
+  if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
 
 }
 //______________________________________________________________________________
@@ -525,12 +582,13 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
   TStopwatch stopwatch;
   stopwatch.Start();
 
-  //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
+  Int_t inholes = 0;
+
   const Int_t kDDL = AliDAQ::NumberOfDdls("TOF");
 
   fRunLoader->GetEvent(iEvent);
 
-  AliDebug(2,Form(" Event number %2i ", iEvent));
+  AliDebug(2,Form(" Event number %2d ", iEvent));
 
   fTreeR = fTOFLoader->TreeR();
 
@@ -551,7 +609,9 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
   ofstream ftxt;
   if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
 
-  AliTOFRawStream tofInput(rawReader);
+  //AliTOFRawStream tofInput(rawReader);
+  fTOFRawStream.Clear();
+  fTOFRawStream.SetRawReader(rawReader);
 
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
@@ -559,17 +619,18 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
     rawReader->Reset();
     if (fDecoderVersion) {
       AliInfo("Using New Decoder \n"); 
-      tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
+      fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
     }
-    else tofInput.LoadRawData(indexDDL);
+    else fTOFRawStream.LoadRawData(indexDDL);
 
-    clonesRawData = (TClonesArray*)tofInput.GetRawData();
+    clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
 
     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
 
       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
 
-      if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
+      //if (tofRawDatum->GetTOT()==-1 || tofRawDatum->GetTOF()==-1) continue;
+      if (tofRawDatum->GetTOF()==-1) continue;
 
       if (fVerbose==2) {
        if (indexDDL<10) ftxt << "  " << indexDDL;
@@ -582,8 +643,8 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
        ftxt << "  " << tofRawDatum->GetTDCchannel();
       }
 
-      tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
-                                   tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
+      fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
+                                        tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
       dummy = detectorIndex[3];
       detectorIndex[3] = detectorIndex[4];
       detectorIndex[4] = dummy;
@@ -599,6 +660,17 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
        else              ftxt << " " << detectorIndex[4];
       }
 
+    /* check valid index */
+    if (detectorIndex[0]==-1||detectorIndex[1]==-1||detectorIndex[2]==-1||detectorIndex[3]==-1||detectorIndex[4]==-1) continue;
+
+      // Do not reconstruct anything in the holes
+      if (detectorIndex[0]==13 || detectorIndex[0]==14 || detectorIndex[0]==15 ) { // sectors with holes
+       if (detectorIndex[1]==2) { // plate with holes
+         inholes++;
+         continue;
+       }
+      }
+
       parTOF[0] = tofRawDatum->GetTOF(); // TDC
       parTOF[1] = tofRawDatum->GetTOT(); // TOT
       parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
@@ -631,7 +703,7 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
 
   if (fVerbose==2) ftxt.close();
 
-  AliInfo(Form("Number of found clusters: %i for event: %i", fNumberOfTofClusters, iEvent));
+  AliInfo(Form("Number of found clusters: %d for event: %d", fNumberOfTofClusters, iEvent));
 
   CalibrateRecPoint();
   FillRecPoint();
@@ -644,6 +716,7 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
   
   AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
               stopwatch.RealTime(),stopwatch.CpuTime()));
+  if (inholes) AliWarning(Form("Clusters in the TOF holes: %d",inholes));
 
 }
 //______________________________________________________________________________
@@ -659,7 +732,6 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
   TStopwatch stopwatch;
   stopwatch.Start();
 
-  //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
   const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
 
   fRunLoader->GetEvent(iEvent);
@@ -679,7 +751,7 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
 
   fRunLoader->GetEvent(iEvent);
 
-  AliDebug(2,Form(" Event number %2i ", iEvent));
+  AliDebug(2,Form(" Event number %2d ", iEvent));
 
   TClonesArray * clonesRawData;
 
@@ -688,7 +760,9 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
   Int_t detectorIndex[5];
   Int_t digit[4];
 
-  AliTOFRawStream tofInput(rawReader);
+  //AliTOFRawStream tofInput(rawReader);
+  fTOFRawStream.Clear();
+  fTOFRawStream.SetRawReader(rawReader);
 
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
@@ -696,27 +770,28 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
     rawReader->Reset();
     if (fDecoderVersion) {
       AliInfo("Using New Decoder \n"); 
-      tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
+      fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
     }
-    else tofInput.LoadRawData(indexDDL);
+    else fTOFRawStream.LoadRawData(indexDDL);
 
-    clonesRawData = (TClonesArray*)tofInput.GetRawData();
+    clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
 
     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
 
       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
 
-      if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
+      //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
+      if (tofRawDatum->GetTOF()==-1) continue;
 
-      tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
-                                   tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
+      fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
+                                        tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
       dummy = detectorIndex[3];
       detectorIndex[3] = detectorIndex[4];
       detectorIndex[4] = dummy;
 
-      digit[0] = tofInput.GetTofBin();
-      digit[1] = tofInput.GetToTbin();
-      digit[2] = tofInput.GetToTbin();
+      digit[0] = fTOFRawStream.GetTofBin();
+      digit[1] = fTOFRawStream.GetToTbin();
+      digit[2] = fTOFRawStream.GetToTbin();
       digit[3] = -1;
 
       Int_t tracknum[3]={-1,-1,-1};
@@ -735,7 +810,9 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
 
   fTOFLoader = fRunLoader->GetLoader("TOFLoader");
   fTOFLoader->WriteDigits("OVERWRITE");
-  
+
+  delete tofDigits;
+
   AliDebug(1, Form("Execution time to read TOF raw data and to write TOF clusters : R:%.2fs C:%.2fs",
                   stopwatch.RealTime(),stopwatch.CpuTime()));
 
@@ -765,10 +842,6 @@ void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
   Int_t bufsize = 32000;
   digitsTree->Branch("TOF", &tofDigits, bufsize);
 
-  ///  fRunLoader->GetEvent(iEvent);
-
-  ///  AliDebug(2,Form(" Event number %2i ", iEvent));
-
   TClonesArray * clonesRawData;
 
   Int_t dummy = -1;
@@ -776,7 +849,9 @@ void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
   Int_t detectorIndex[5];
   Int_t digit[4];
 
-  AliTOFRawStream tofInput(rawReader);
+  //AliTOFRawStream tofInput(rawReader);
+  fTOFRawStream.Clear();
+  fTOFRawStream.SetRawReader(rawReader);
 
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
@@ -784,27 +859,28 @@ void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
     rawReader->Reset();
     if (fDecoderVersion) {
       AliInfo("Using New Decoder \n"); 
-      tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
+      fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
     }
-    else tofInput.LoadRawData(indexDDL);
+    else fTOFRawStream.LoadRawData(indexDDL);
 
-    clonesRawData = (TClonesArray*)tofInput.GetRawData();
+    clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
 
     for (Int_t iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
 
       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
 
-      if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
+      //if (!tofRawDatum->GetTOT() || !tofRawDatum->GetTOF()) continue;
+      if (tofRawDatum->GetTOF()==-1) continue;
 
-      tofInput.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
-                                   tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
+      fTOFRawStream.EquipmentId2VolumeId(indexDDL, tofRawDatum->GetTRM(), tofRawDatum->GetTRMchain(),
+                                        tofRawDatum->GetTDC(), tofRawDatum->GetTDCchannel(), detectorIndex);
       dummy = detectorIndex[3];
       detectorIndex[3] = detectorIndex[4];
       detectorIndex[4] = dummy;
 
-      digit[0] = tofInput.GetTofBin();
-      digit[1] = tofInput.GetToTbin();
-      digit[2] = tofInput.GetToTbin();
+      digit[0] = fTOFRawStream.GetTofBin();
+      digit[1] = fTOFRawStream.GetToTbin();
+      digit[2] = fTOFRawStream.GetToTbin();
       digit[3] = -1;
 
       Int_t tracknum[3]={-1,-1,-1};
@@ -821,7 +897,9 @@ void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
 
   digitsTree->Fill();
 
-  AliDebug(1, Form("Got %d digits: ", tofDigits->GetEntries()));
+  delete tofDigits;
+
+  AliDebug(1, Form("Got %d digits: ", fDigits->GetEntries()));
   AliDebug(1, Form("Execution time to read TOF raw data and fill TOF digit tree : R:%.2fs C:%.2fs",
                   stopwatch.RealTime(),stopwatch.CpuTime()));
 
@@ -905,6 +983,19 @@ void AliTOFClusterFinder::FillRecPoint()
     GetClusterPars(detectorIndex,posClus,covClus);
     new(lRecPoints[ii]) AliTOFcluster(volIdClus,posClus[0],posClus[1],posClus[2],covClus[0],covClus[1],covClus[2],covClus[3],covClus[4],covClus[5],trackLabels,detectorIndex, parTOF,status,digitIndex);
 
+    AliDebug(2, Form(" %4d  %4d  %f %f %f  %f %f %f %f %f %f  %3d %3d %3d  %2d %1d %2d %1d %2d  %4d %3d %3d %4d %4d  %1d  %4d", 
+                    ii, volIdClus, posClus[0], posClus[1], posClus[2],
+                    fTofClusters[ii]->GetSigmaX2(),
+                    fTofClusters[ii]->GetSigmaXY(),
+                    fTofClusters[ii]->GetSigmaXZ(),
+                    fTofClusters[ii]->GetSigmaY2(),
+                    fTofClusters[ii]->GetSigmaYZ(),
+                    fTofClusters[ii]->GetSigmaZ2(),
+                    trackLabels[0], trackLabels[1], trackLabels[2],
+                    detectorIndex[0], detectorIndex[1], detectorIndex[2], detectorIndex[3], detectorIndex[4],
+                    parTOF[0], parTOF[1], parTOF[2], parTOF[3], parTOF[4],
+                    status, digitIndex));
+
   } // loop on clusters
 
 }
@@ -927,7 +1018,8 @@ void AliTOFClusterFinder::CalibrateRecPoint()
   Int_t   tdcCorr;
   AliInfo(" Calibrating TOF Clusters: ")
   
-  TObjArray *calTOFArrayOnline = fTOFcalib->GetTOFCalArrayOnline();  
+  AliTOFChannelOnlineArray *calDelay = fTOFcalib->GetTOFOnlineDelay();  
+  AliTOFChannelOnlineStatusArray *calStatus = fTOFcalib->GetTOFOnlineStatus();  
   TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
   TString validity = (TString)fTOFcalib->GetOfflineValidity();
   AliInfo(Form(" validity = %s",validity.Data()));
@@ -946,13 +1038,23 @@ void AliTOFClusterFinder::CalibrateRecPoint()
 
     Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
      
-    AliTOFChannelOnline * calChannelOnline = (AliTOFChannelOnline* )calTOFArrayOnline->At(index);
+    UChar_t statusPulser=calStatus->GetPulserStatus(index);
+    UChar_t statusNoise=calStatus->GetNoiseStatus(index);
+    UChar_t statusHW=calStatus->GetHWStatus(index);
+    UChar_t status=calStatus->GetStatus(index);
 
-    // Get channel status 
-    UChar_t status=calChannelOnline->GetStatus();
-    if((status & AliTOFChannelOnline::kTOFOnlineOk)!=(AliTOFChannelOnline::kTOFOnlineOk))fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
+    //check the status, also unknown is fine!!!!!!!
+
+    AliDebug(2, Form(" Status for channel %d = %d",index, (Int_t)status));
+    if((statusPulser & AliTOFChannelOnlineStatusArray::kTOFPulserBad)==(AliTOFChannelOnlineStatusArray::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatusArray::kTOFNoiseBad)==(AliTOFChannelOnlineStatusArray::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatusArray::kTOFHWBad)==(AliTOFChannelOnlineStatusArray::kTOFHWBad)){
+      AliDebug(2, Form(" Bad Status for channel %d",index));
+      fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
+    }
+    else {
+      AliDebug(2, Form(" Good Status for channel %d",index));
+    }
     // Get Rough channel online equalization 
-    Double_t roughDelay=(Double_t)calChannelOnline->GetDelay();  // in ns
+    Double_t roughDelay=(Double_t)calDelay->GetDelay(index);  // in ns
     AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
     // Get Refined channel offline calibration parameters
     if (calibration ==1){
@@ -962,7 +1064,7 @@ void AliTOFClusterFinder::CalibrateRecPoint()
        par[j]=(Double_t)calChannelOffline->GetSlewPar(j);
      } 
       AliDebug(2,Form(" Calib Pars = %f, %f, %f, %f, %f, %f ",par[0],par[1],par[2],par[3],par[4],par[5]));
-      AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %i , %i", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
+      AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %d , %d", fTofClusters[ii]->GetToT(),fTofClusters[ii]->GetTDC()));
       tToT = (Double_t)(fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth());    
       tToT*=1.E-3; //ToT in ns
       AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,tToT));
@@ -1108,24 +1210,28 @@ void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov
   // -----------------------------------------------------   |
   // x <-----------------------------------------------------
 
-  Float_t localX=(ind[4]-23.5)*2.5; 
-  Float_t localY=0; 
-  Float_t localZ=(ind[3]-0.5)*3.5; 
-
+  /*
+  Float_t localX = (ind[4]-23.5)*AliTOFGeometry::XPad();
+  Float_t localY = 0;
+  Float_t localZ = (ind[3]- 0.5)*AliTOFGeometry::ZPad();
+  */
+  Float_t localX = (ind[4]-AliTOFGeometry::NpadX()/2)*AliTOFGeometry::XPad()+AliTOFGeometry::XPad()/2.;
+  Float_t localY = 0;
+  Float_t localZ = (ind[3]-AliTOFGeometry::NpadZ()/2)*AliTOFGeometry::ZPad()+AliTOFGeometry::ZPad()/2.;
   //move to the tracking ref system
 
   Double_t lpos[3];
-  lpos[0]=localX;
-  lpos[1]=localY;
-  lpos[2]=localZ; 
+  lpos[0] = localX;
+  lpos[1] = localY;
+  lpos[2] = localZ; 
 
   const TGeoHMatrix *l2t= AliGeomManager::GetTracking2LocalMatrix(volIndex);
   // Get The position in the track ref system
   Double_t tpos[3];
   l2t->MasterToLocal(lpos,tpos);
-  pos[0]=tpos[0];
-  pos[1]=tpos[1];
-  pos[2]=tpos[2];
+  pos[0] = tpos[0];
+  pos[1] = tpos[1];
+  pos[2] = tpos[2];
 
   //Get The cluster covariance in the track ref system
   Double_t lcov[9];
@@ -1135,15 +1241,15 @@ void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov
   // 0     0   0
   // 0     0   sz2
 
-  lcov[0]=2.5*2.5/12.;
-  lcov[1]=0;
-  lcov[2]=0;
-  lcov[3]=0;
-  lcov[4]=0;
-  lcov[5]=0;
-  lcov[6]=0;
-  lcov[7]=0;
-  lcov[8]=3.5*3.5/12.;
+  lcov[0] = AliTOFGeometry::XPad()*AliTOFGeometry::XPad()/12.;
+  lcov[1] = 0;
+  lcov[2] = 0;
+  lcov[3] = 0;
+  lcov[4] = 0;
+  lcov[5] = 0;
+  lcov[6] = 0;
+  lcov[7] = 0;
+  lcov[8] = AliTOFGeometry::ZPad()*AliTOFGeometry::ZPad()/12.;
 
   //cluster covariance in the tracking system:
   TGeoHMatrix m;