]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFClusterFinderV1.cxx
Fix for bug #71737 DELETE_ARRAY reported by Coverity
[u/mrichter/AliRoot.git] / TOF / AliTOFClusterFinderV1.cxx
index a0792a60269e188ba30f610733a4446d0cc630c2..d3036a279792c0add31c152702f85814a455adb7 100644 (file)
@@ -56,72 +56,117 @@ Revision 0.01  2008/05/10 A. De Caro
 #include "AliTOFdigit.h"
 #include "AliTOFDigitMap.h"
 #include "AliTOFrawData.h"
+#include "AliTOFReconstructor.h"
+#include "AliTOFRecoParam.h"
 
 ClassImp(AliTOFClusterFinderV1)
 
 //_____________________________________________________________________________
 AliTOFClusterFinderV1::AliTOFClusterFinderV1(AliTOFcalib *calib):
+  TTask("AliTOFClusterFinderV1",""),
   fRunLoader(0),
   fDigits(new TClonesArray("AliTOFdigit", 4000)),
   fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
   fNumberOfTofClusters(0),
   fNumberOfTofDigits(0),
-  fMaxDeltaTime(2),
+  fkRecoParam(0),//AliTOFReconstructor::GetRecoParam()),
+  fMaxDeltaTime(0),//fkRecoParam->GetMaxDeltaTime()),
   fVerbose(0),
   fDecoderVersion(0),
   fTOFcalib(calib),
   fTOFdigitMap(new AliTOFDigitMap()),
   fTOFGeometry(new AliTOFGeometry()),
-  fTOFdigits(0),
-  fTOFRawStream(AliTOFRawStream())
+  fTOFdigits(new TTree()),
+  fTOFRawStream(AliTOFRawStream()),
+  fCalibrateTOFtimes(1)
 {
 //
 // Constructor
 //
 
+  if (AliTOFReconstructor::GetRecoParam()) {
+    fkRecoParam = AliTOFReconstructor::GetRecoParam();
+    fMaxDeltaTime = fkRecoParam->GetMaxDeltaTime();
+  }
+  else
+    fMaxDeltaTime = 2;
+
+  TString validity = (TString)fTOFcalib->GetOfflineValidity();
+  if (validity.CompareTo("valid")==0) {
+    AliInfo(Form(" validity = %s - Using offline calibration parameters", validity.Data()));
+  } else {
+    AliInfo(Form(" validity = %s - Using online calibration parameters", validity.Data()));
+  }
+
 }
 
 //_____________________________________________________________________________
 AliTOFClusterFinderV1::AliTOFClusterFinderV1(AliRunLoader* runLoader, AliTOFcalib *calib):
+  TTask("AliTOFClusterFinderV1",""),
   fRunLoader(runLoader),
   fDigits(new TClonesArray("AliTOFdigit", 4000)),
   fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
   fNumberOfTofClusters(0),
   fNumberOfTofDigits(0),
-  fMaxDeltaTime(2),
+  fkRecoParam(0),//AliTOFReconstructor::GetRecoParam()),
+  fMaxDeltaTime(0),//fkRecoParam->GetMaxDeltaTime()),
   fVerbose(0),
   fDecoderVersion(0),
   fTOFcalib(calib),
   fTOFdigitMap(new AliTOFDigitMap()),
   fTOFGeometry(new AliTOFGeometry()),
-  fTOFdigits(0),
-  fTOFRawStream(AliTOFRawStream())
+  fTOFdigits(new TTree()),
+  fTOFRawStream(AliTOFRawStream()),
+  fCalibrateTOFtimes(1)
 {
 //
 // Constructor
 //
 
+  if (AliTOFReconstructor::GetRecoParam()) {
+    fkRecoParam = AliTOFReconstructor::GetRecoParam();
+    fMaxDeltaTime = fkRecoParam->GetMaxDeltaTime();
+  }
+  else
+    fMaxDeltaTime = 2;
+
+  TString validity = (TString)fTOFcalib->GetOfflineValidity();
+  if (validity.CompareTo("valid")==0) {
+    AliInfo(Form(" validity = %s - Using offline calibration parameters", validity.Data()));
+  } else {
+    AliInfo(Form(" validity = %s - Using online calibration parameters", validity.Data()));
+  }
+
 }
 //_____________________________________________________________________________
 
 AliTOFClusterFinderV1::AliTOFClusterFinderV1(const AliTOFClusterFinderV1 &source)
-  :TObject(source),
+  :TTask(source),
    fRunLoader(0),
    fDigits(source.fDigits),
    fRecPoints(source.fRecPoints),
    fNumberOfTofClusters(0),
    fNumberOfTofDigits(0),
-   fMaxDeltaTime(2),
+   fkRecoParam(0),//AliTOFReconstructor::GetRecoParam()),
+   fMaxDeltaTime(0),//fkRecoParam->GetMaxDeltaTime()),
    fVerbose(0),
    fDecoderVersion(source.fDecoderVersion),
    fTOFcalib(source.fTOFcalib),
    fTOFdigitMap(new AliTOFDigitMap()),
    fTOFGeometry(new AliTOFGeometry()),
    fTOFdigits(source.fTOFdigits),
-   fTOFRawStream(source.fTOFRawStream)
-
+   fTOFRawStream(source.fTOFRawStream),
+   fCalibrateTOFtimes(1)
 {
   // copy constructor
+
+  if (AliTOFReconstructor::GetRecoParam()) {
+    fkRecoParam = AliTOFReconstructor::GetRecoParam();
+    fMaxDeltaTime = fkRecoParam->GetMaxDeltaTime();
+  }
+  else
+    fMaxDeltaTime = 2;
+
 }
 //_____________________________________________________________________________
 
@@ -142,6 +187,7 @@ AliTOFClusterFinderV1& AliTOFClusterFinderV1::operator=(const AliTOFClusterFinde
   fTOFGeometry=source.fTOFGeometry;
   fTOFdigits=source.fTOFdigits;
   fTOFRawStream=source.fTOFRawStream;
+  fCalibrateTOFtimes=source.fCalibrateTOFtimes;
   return *this;
 
 }
@@ -173,6 +219,12 @@ AliTOFClusterFinderV1::~AliTOFClusterFinderV1()
 
   delete fTOFdigits;
 
+  if (fTofClusters || fNumberOfTofClusters) {
+    for (Int_t ii=0; ii<fNumberOfTofClusters; ii++)
+      if (fTofClusters[ii]) fTofClusters[ii]->Delete();
+    fNumberOfTofClusters = 0;
+  }
+
 }
 //_____________________________________________________________________________
 
@@ -187,6 +239,7 @@ void AliTOFClusterFinderV1::Digits2RecPoints(TTree* digitsTree, TTree* clusterTr
 
   Int_t inholes = 0;
 
+  fDigits->Clear();
   TClonesArray &aDigits = *fDigits;
 
   if (digitsTree == 0x0)
@@ -203,7 +256,7 @@ void AliTOFClusterFinderV1::Digits2RecPoints(TTree* digitsTree, TTree* clusterTr
   TClonesArray *digits = &staticDigits;
   branch->SetAddress(&digits);
   digitsTree->GetEvent(0);
-  AliInfo(Form("Number of TOF digits: %d", digits->GetEntriesFast()));
+  AliDebug(1,Form("Number of TOF digits: %d", digits->GetEntriesFast()));
 
   AliTOFdigit *tofDigit;
 
@@ -219,15 +272,14 @@ void AliTOFClusterFinderV1::Digits2RecPoints(TTree* digitsTree, TTree* clusterTr
 
   Bool_t status = kTRUE;
 
-  AliInfo(" Calibrating TOF Digits: ");
+  AliDebug(1," Calibrating TOF Digits");
+  /*
   TString validity = (TString)fTOFcalib->GetOfflineValidity();
-  AliInfo(Form(" validity = %s", validity.Data()));
   if (validity.CompareTo("valid")==0) {
-    AliInfo(" ...using offline calibration parameters");
-  }
-  else {
-    AliInfo(" ...using online calibration parameters");
-  }
+    AliInfo(Form(" validity = %s - Using offline calibration parameters", validity.Data()));
+  } else
+    AliInfo(Form(" validity = %s - Using online calibration parameters", validity.Data()));
+  */
 
   Int_t ii = 0;
   for (ii=0; ii<digits->GetEntriesFast(); ii++) {
@@ -245,6 +297,7 @@ void AliTOFClusterFinderV1::Digits2RecPoints(TTree* digitsTree, TTree* clusterTr
       }
     }
 
+    tdcCorr = tofDigit->GetTdc();
     status = MakeSlewingCorrection(detectorIndex, tofDigit->GetToT(), tofDigit->GetTdc(), tdcCorr);
 
     for (jj=0; jj<4; jj++) info[jj] = -1;
@@ -278,7 +331,7 @@ void AliTOFClusterFinderV1::Digits2RecPoints(TTree* digitsTree, TTree* clusterTr
   FillRecPoint();
   clusterTree->Fill();
 
-  AliInfo(Form("Number of found TOF clusters: %d", fNumberOfTofClusters));
+  AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
 
   ResetRecpoint();
 
@@ -286,8 +339,8 @@ void AliTOFClusterFinderV1::Digits2RecPoints(TTree* digitsTree, TTree* clusterTr
 
   ResetDigits();
 
-  AliInfo(Form("Execution time to read TOF digits and to write TOF clusters : R:%.4fs C:%.4fs",
-              stopwatch.RealTime(),stopwatch.CpuTime()));
+  AliDebug(1,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));
 
@@ -310,7 +363,7 @@ void AliTOFClusterFinderV1::Digits2RecPoints(AliRawReader *rawReader, TTree *clu
 
   Raw2Digits(rawReader, fTOFdigits);
 
-  AliDebug(2,Form("Number of TOF digits: %d", fNumberOfTofDigits));
+  AliDebug(1,Form("Number of TOF digits: %d", fNumberOfTofDigits));
   ResetRecpoint();
 
   Int_t bufsize = 32000;
@@ -319,7 +372,7 @@ void AliTOFClusterFinderV1::Digits2RecPoints(AliRawReader *rawReader, TTree *clu
 
   clustersTree->Fill();
 
-  AliInfo(Form("Number of found clusters: %d", fNumberOfTofClusters));
+  AliDebug(1,Form("Number of found clusters: %d", fNumberOfTofClusters));
 
   ResetRecpoint();
 
@@ -327,8 +380,8 @@ void AliTOFClusterFinderV1::Digits2RecPoints(AliRawReader *rawReader, TTree *clu
 
   ResetDigits();
 
-  AliInfo(Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
-                  stopwatch.RealTime(),stopwatch.CpuTime()));
+  AliDebug(1,Form("Execution time to read TOF raw data and to write TOF clusters : R:%.4fs C:%.4fs",
+                 stopwatch.RealTime(),stopwatch.CpuTime()));
 
 }
 
@@ -372,29 +425,28 @@ void AliTOFClusterFinderV1::Raw2Digits(AliRawReader *rawReader, TTree* digitsTre
 
   Bool_t status = kTRUE;
 
-  AliInfo(" Calibrating TOF Digits: ");
+  /*
   TString validity = (TString)fTOFcalib->GetOfflineValidity();
-  AliInfo(Form(" validity = %s", validity.Data()));
   if (validity.CompareTo("valid")==0) {
-    AliInfo(" ...using offline calibration parameters");
-  }
-  else {
-    AliInfo(" ...using online calibration parameters");
-  }
+    AliInfo(Form(" validity = %s - Using offline calibration parameters", validity.Data()));
+  } else
+    AliInfo(Form(" validity = %s - Using online calibration parameters", validity.Data()));
+  */
+
+  if (fDecoderVersion)
+    AliInfo("Using New Decoder");
 
   Int_t indexDDL = 0;
   Int_t iRawData = 0;
   for (indexDDL=0; indexDDL<kDDL; indexDDL++) {
 
     rawReader->Reset();
-    if (fDecoderVersion) {
-      AliInfo("Using New Decoder \n"); 
+    if (fDecoderVersion)
       fTOFRawStream.LoadRawDataBuffers(indexDDL,fVerbose);
-    }
     else fTOFRawStream.LoadRawData(indexDDL);
 
     clonesRawData = (TClonesArray*)fTOFRawStream.GetRawData();
-    if (clonesRawData->GetEntriesFast()!=0) AliInfo(Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
+    if (clonesRawData->GetEntriesFast()!=0) AliDebug(2,Form(" TOF raw data number = %3d", clonesRawData->GetEntriesFast()));
     for (iRawData = 0; iRawData<clonesRawData->GetEntriesFast(); iRawData++) {
 
       AliTOFrawData *tofRawDatum = (AliTOFrawData*)clonesRawData->UncheckedAt(iRawData);
@@ -409,6 +461,8 @@ void AliTOFClusterFinderV1::Raw2Digits(AliRawReader *rawReader, TTree* digitsTre
       dummy = detectorIndex[3];
       detectorIndex[3] = detectorIndex[4];//padz
       detectorIndex[4] = dummy;//padx
+
+      tdcCorr = tofRawDatum->GetTOF();
       status = MakeSlewingCorrection(detectorIndex, tofRawDatum->GetTOT(), tofRawDatum->GetTOF(), tdcCorr);
 
       digit[0] = tdcCorr;
@@ -420,6 +474,9 @@ void AliTOFClusterFinderV1::Raw2Digits(AliRawReader *rawReader, TTree* digitsTre
       detectorIndex[3] = detectorIndex[4];//padx
       detectorIndex[4] = dummy;//padz
 
+      /* 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
@@ -493,80 +550,103 @@ void AliTOFClusterFinderV1::FillRecPoint()
   // i.e. fRecPoints
   //
 
-  Int_t dummy4_1 = -1;
-  Int_t dummy3_1 = -1;
-  Int_t dummy2_1 = -1;
-  Int_t dummy    = -1;
+  Int_t dummy4 = -1;
+  Int_t dummy3 = -1;
+  Int_t dummy2 = -1;
+  Int_t dummy  = -1;
 
   for(Int_t iPlate=AliTOFGeometry::NPlates()-1; iPlate>=0; iPlate--) {
     for(Int_t iStrip=AliTOFGeometry::NStrip(iPlate)-1; iStrip>=0; iStrip--) {
       //for (Int_t iSector=AliTOFGeometry::NSectors()-1; iSector>=0; iSector--) {
       for (Int_t iSector=0; iSector<AliTOFGeometry::NSectors(); iSector++) {
 
+
+       if (fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))
+         AliDebug(1,Form(" Number of TOF digits in (%2d,%1d,%2d) -> %d",
+                         iSector,iPlate,iStrip,fTOFdigitMap->FilledCellsInStrip(iSector,iPlate,iStrip)));
+
        if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
        FindClustersWithoutTOT(iSector, iPlate, iStrip); // clusters coming from digits without TOT measurement
 
+       if (fMaxDeltaTime>0) {
 
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
-       FindClustersPerStrip(iSector, iPlate, iStrip, 4); // 4 pads clusters
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         //if (fTOFdigitMap->FilledCellsInStrip(iSector,iPlate,iStrip)>=4)
+         FindClustersPerStrip(iSector, iPlate, iStrip, 4); // 4 pads clusters
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
 
-       dummy4_1 = fNumberOfTofClusters;
-       FindClustersPerStrip(iSector, iPlate, iStrip, 4); // 4 pads clusters
-       if (fNumberOfTofClusters!=dummy4_1)
-         AliDebug(2, Form(" (4): n1= %5d, n2 = %5", dummy4_1, fNumberOfTofClusters));
+         dummy4 = fNumberOfTofClusters;
+         FindClustersPerStrip(iSector, iPlate, iStrip, 4); // 4 pads clusters
+         if (fNumberOfTofClusters!=dummy4)
+           AliDebug(2, Form(" (4): n1= %5d, n2 = %5", dummy4, fNumberOfTofClusters));
 
 
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
-       FindClustersPerStrip(iSector, iPlate, iStrip, 3); // 3 pads clusters
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         FindClustersPerStrip(iSector, iPlate, iStrip, 3); // 3 pads clusters
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
 
-       dummy3_1 = fNumberOfTofClusters;
-       FindClustersPerStrip(iSector, iPlate, iStrip, 3); // 3 pads clusters
-       if (fNumberOfTofClusters!=dummy3_1)
-         AliDebug(2, Form(" (3): n1= %5d, n2 = %5", dummy3_1, fNumberOfTofClusters));
+         dummy3 = fNumberOfTofClusters;
+         FindClustersPerStrip(iSector, iPlate, iStrip, 3); // 3 pads clusters
+         if (fNumberOfTofClusters!=dummy3)
+           AliDebug(2, Form(" (3): n1= %5d, n2 = %5", dummy3, fNumberOfTofClusters));
 
 
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
-       FindClustersPerStrip(iSector, iPlate, iStrip, 2); // 2 pads clusters
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         FindClustersPerStrip(iSector, iPlate, iStrip, 2); // 2 pads clusters
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
 
-       dummy2_1 = fNumberOfTofClusters;
-       FindClustersPerStrip(iSector, iPlate, iStrip, 2); // 2 pads clusters
-       if (fNumberOfTofClusters!=dummy2_1)
-         AliDebug(2, Form(" (2): n1= %5d, n2 =%5", dummy2_1, fNumberOfTofClusters));
+         dummy2 = fNumberOfTofClusters;
+         FindClustersPerStrip(iSector, iPlate, iStrip, 2); // 2 pads clusters
+         if (fNumberOfTofClusters!=dummy2)
+           AliDebug(2, Form(" (2): n1= %5d, n2 =%5", dummy2, fNumberOfTofClusters));
 
 
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
-       dummy = fNumberOfTofClusters;
-       FindClusters34(iSector, iPlate, iStrip); // 3 pads clusters between 4 hit pads
-       if (fNumberOfTofClusters!=dummy)
-         AliDebug(2, Form(" (3 between 4): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         dummy = fNumberOfTofClusters;
+         FindClusters34(iSector, iPlate, iStrip); // 3 pads clusters between 4 hit pads
+         if (fNumberOfTofClusters!=dummy)
+           AliDebug(2, Form(" (3 between 4): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
 
 
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
-       dummy = fNumberOfTofClusters;
-       FindClusters23(iSector, iPlate, iStrip); // 2 pads clusters between 3 hit pads
-       if (fNumberOfTofClusters!=dummy)
-         AliDebug(2, Form(" (2 between 3): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         dummy = fNumberOfTofClusters;
+         FindClusters23(iSector, iPlate, iStrip); // 2 pads clusters between 3 hit pads
+         if (fNumberOfTofClusters!=dummy)
+           AliDebug(2, Form(" (2 between 3): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
 
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
-       dummy = fNumberOfTofClusters;
-       FindClusters24(iSector, iPlate, iStrip); // 2 pads clusters between 4 hit pads
-       if (fNumberOfTofClusters!=dummy)
-         AliDebug(2, Form(" (2 between 4): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         dummy = fNumberOfTofClusters;
+         FindClusters24(iSector, iPlate, iStrip); // 2 pads clusters between 4 hit pads
+         if (fNumberOfTofClusters!=dummy)
+           AliDebug(2, Form(" (2 between 4): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
 
 
-       if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
-       dummy = fNumberOfTofClusters;
-       FindOnePadClusterPerStrip(iSector, iPlate, iStrip); // 1 pad clusters
-       if (fNumberOfTofClusters!=dummy)
-         AliDebug(2,Form(" (1): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         dummy = fNumberOfTofClusters;
+         FindOnePadClusterPerStrip(iSector, iPlate, iStrip); // 1 pad clusters
+         if (fNumberOfTofClusters!=dummy)
+           AliDebug(2,Form(" (1): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
+
+         if (fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip)>0)
+           AliDebug(2, Form(" (1): number of clusters = %5d (remaining digit %2d), -%2d %1d %2d-",
+                            fNumberOfTofClusters, fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip),
+                            iSector, iPlate, iStrip));
+
+       }
+       else {
+         if (!(fTOFdigitMap->StripDigitCheck(iSector,iPlate,iStrip))) continue;
+         dummy = fNumberOfTofClusters;
+         FindOnePadClusterPerStrip(iSector, iPlate, iStrip); // 1 pad clusters
+         if (fNumberOfTofClusters!=dummy)
+           AliDebug(2,Form(" (1): n1 = %5d, n2 = %5d", fNumberOfTofClusters, dummy));
+
+         if (fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip)>0)
+           AliDebug(2, Form(" (1): number of clusters = %5d (remaining digit %2d), -%2d %1d %2d-",
+                            fNumberOfTofClusters, fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip),
+                            iSector, iPlate, iStrip));
+
+       }
 
-       if (fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip)>0)
-         AliDebug(2, Form(" (1): number of clusters = %5d (remaining digit %2d), -%2d %1d %2d-",
-                          fNumberOfTofClusters, fTOFdigitMap->DigitInStrip(iSector,iPlate,iStrip),
-                          iSector, iPlate, iStrip));
 
       }
     }
@@ -663,7 +743,7 @@ void AliTOFClusterFinderV1::FindOnePadClusterPerStrip(Int_t nSector,
   //
 
   const Int_t kMaxNumberOfTracksPerDigit = 3;
-  const Int_t kMaxNumberOfDigitsPerVolume = 3;
+  const Int_t kMaxNumberOfDigitsPerVolume = 10;
 
   Int_t jj = 0;
 
@@ -685,7 +765,7 @@ void AliTOFClusterFinderV1::FindOnePadClusterPerStrip(Int_t nSector,
   Bool_t status = kTRUE; //assume all sim channels ok in the beginning...
 
   Int_t tracks[kMaxNumberOfTracksPerDigit];
-  for (jj=0; jj<3; jj++) tracks[jj] = -1;
+  for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
 
   Int_t dummyCounter=-1;
 
@@ -784,7 +864,7 @@ void AliTOFClusterFinderV1::FindClustersWithoutTOT(Int_t nSector,
   //
 
   const Int_t kMaxNumberOfTracksPerDigit = 3;
-  const Int_t kMaxNumberOfDigitsPerVolume = 3;
+  const Int_t kMaxNumberOfDigitsPerVolume = 10;
 
   Int_t jj = 0;
 
@@ -805,7 +885,7 @@ void AliTOFClusterFinderV1::FindClustersWithoutTOT(Int_t nSector,
 
   Bool_t status = kTRUE; //assume all sim channels ok in the beginning...
   Int_t tracks[kMaxNumberOfTracksPerDigit];
-  for (jj=0; jj<3; jj++) tracks[jj] = -1;
+  for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
 
   Int_t dummyCounter=-1;
 
@@ -906,7 +986,7 @@ void AliTOFClusterFinderV1::FindClusters34(Int_t nSector,
 
   const Int_t kMaxNumberOfInterestingPads = 4;
   const Int_t kMaxNumberOfTracksPerDigit = 3;
-  const Int_t kMaxNumberOfDigitsPerVolume = 3;
+  const Int_t kMaxNumberOfDigitsPerVolume = 10;
 
   Int_t ii = 0;
 
@@ -968,7 +1048,7 @@ void AliTOFClusterFinderV1::FindClusters34(Int_t nSector,
   Double_t covClus[6];
   for (jj=0; jj<6; jj++) covClus[jj] = 0.;
   Int_t tracks[kMaxNumberOfTracksPerDigit];
-  for (jj=0; jj<3; jj++) tracks[jj] = -1;
+  for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
   Int_t dummyCounter=-1;
   Bool_t alreadyStored = kFALSE;
 
@@ -1342,12 +1422,16 @@ void AliTOFClusterFinderV1::FindClusters34(Int_t nSector,
 
   } // loop on iPad
 
-  for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
+  for (ii=0; ii<kMaxNumberOfInterestingPads; ii++) {
     for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) {
-      delete selectedDigit[ii][jj];
+      delete [] selectedDigit[ii][jj];
       selectedDigit[ii][jj] = 0x0;
     }
-
+    delete [] selectedDigit[ii];
+    selectedDigit[ii] = 0x0;
+  }
+  delete [] selectedDigit;
+  selectedDigit = 0x0;
 
 }
 //_____________________________________________________________________________
@@ -1366,7 +1450,7 @@ void AliTOFClusterFinderV1::FindClusters23(Int_t nSector,
 
   const Int_t kMaxNumberOfInterestingPads = 4;
   const Int_t kMaxNumberOfTracksPerDigit = 3;
-  const Int_t kMaxNumberOfDigitsPerVolume = 3;
+  const Int_t kMaxNumberOfDigitsPerVolume = 10;
 
   Int_t ii = 0;
 
@@ -1428,7 +1512,7 @@ void AliTOFClusterFinderV1::FindClusters23(Int_t nSector,
   Double_t covClus[6];
   for (jj=0; jj<6; jj++) covClus[jj] = 0.;
   Int_t tracks[kMaxNumberOfTracksPerDigit];
-  for (jj=0; jj<3; jj++) tracks[jj] = -1;
+  for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
   Int_t dummyCounter=-1;
   Bool_t alreadyStored = kFALSE;
 
@@ -1744,12 +1828,16 @@ void AliTOFClusterFinderV1::FindClusters23(Int_t nSector,
 
   } // loop on iPad
 
-  for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
+  for (ii=0; ii<kMaxNumberOfInterestingPads; ii++) {
     for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) {
-      delete selectedDigit[ii][jj];
+      delete [] selectedDigit[ii][jj];
       selectedDigit[ii][jj] = 0x0;
     }
-
+    delete [] selectedDigit[ii];
+    selectedDigit[ii] = 0x0;
+  }
+  delete [] selectedDigit;
+  selectedDigit = 0x0;
 
 }
 //_____________________________________________________________________________
@@ -1768,7 +1856,7 @@ void AliTOFClusterFinderV1::FindClusters24(Int_t nSector,
 
   const Int_t kMaxNumberOfInterestingPads = 4;
   const Int_t kMaxNumberOfTracksPerDigit = 3;
-  const Int_t kMaxNumberOfDigitsPerVolume = 3;
+  const Int_t kMaxNumberOfDigitsPerVolume = 10;
 
   Int_t ii = 0;
 
@@ -1830,7 +1918,7 @@ void AliTOFClusterFinderV1::FindClusters24(Int_t nSector,
   Double_t covClus[6];
   for (jj=0; jj<6; jj++) covClus[jj] = 0.;
   Int_t tracks[kMaxNumberOfTracksPerDigit];
-  for (jj=0; jj<3; jj++) tracks[jj] = -1;
+  for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
   Int_t dummyCounter=-1;
   Bool_t alreadyStored = kFALSE;
 
@@ -2147,12 +2235,16 @@ void AliTOFClusterFinderV1::FindClusters24(Int_t nSector,
 
   } // loop on iPad
 
-  for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
+  for (ii=0; ii<kMaxNumberOfInterestingPads; ii++) {
     for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) {
-      delete selectedDigit[ii][jj];
+      delete [] selectedDigit[ii][jj];
       selectedDigit[ii][jj] = 0x0;
     }
-
+    delete [] selectedDigit[ii];
+    selectedDigit[ii] = 0x0;
+  }
+  delete [] selectedDigit;
+  selectedDigit = 0x0;
 
 }
 //_____________________________________________________________________________
@@ -2181,7 +2273,7 @@ void AliTOFClusterFinderV1::FindClustersPerStrip(Int_t nSector,
 
   const Int_t kMaxNumberOfInterestingPads = 4;
   const Int_t kMaxNumberOfTracksPerDigit = 3;
-  const Int_t kMaxNumberOfDigitsPerVolume = 3;
+  const Int_t kMaxNumberOfDigitsPerVolume = 10;
 
   Int_t ii = 0;
 
@@ -2243,7 +2335,7 @@ void AliTOFClusterFinderV1::FindClustersPerStrip(Int_t nSector,
   Double_t covClus[6];
   for (jj=0; jj<6; jj++) covClus[jj] = 0.;
   Int_t tracks[kMaxNumberOfTracksPerDigit];
-  for (jj=0; jj<3; jj++) tracks[jj] = -1;
+  for (jj=0; jj<kMaxNumberOfTracksPerDigit; jj++) tracks[jj] = -1;
   Int_t dummyCounter=-1;
   Bool_t alreadyStored = kFALSE;
 
@@ -2430,19 +2522,32 @@ void AliTOFClusterFinderV1::FindClustersPerStrip(Int_t nSector,
 
     AliDebug(1,Form(" e adesso %1d", interestingCounter+1));
 
+    Int_t adesso1 = -1;
+    Int_t adesso2 = -1;
+    Int_t adesso3 = -1;
+    Int_t adesso4 = -1;
+
     switch(interestingCounter+1) {
 
     case 2:
 
-      for (Int_t adesso1=0; adesso1<interestingCounter+1; adesso1++) {
+      //for (adesso1=0; adesso1<interestingCounter+1; adesso1++) {
+      adesso1 = 0;
        for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
          if (selectedDigit[adesso1][firstIndex]==0x0) continue;
 
-         for (Int_t adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
+         //for (adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
+         adesso2 = 1;
            for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
              if (selectedDigit[adesso2][secondIndex]==0x0) continue;
 
-             if (TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso2][secondIndex]->GetTDC())>fMaxDeltaTime) continue;
+             if (TMath::Abs(selectedDigit[adesso1][firstIndex]->GetTDC()-selectedDigit[adesso2][secondIndex]->GetTDC())>fMaxDeltaTime) {
+               AliDebug(1,Form(" selD1[%d][%d]->GetTDC()=%d selD2[%d][%d]->GetTDC()=%d -- %d ",
+                               adesso1,firstIndex,(Int_t)selectedDigit[adesso1][firstIndex]->GetTDC(),
+                               adesso2,secondIndex,(Int_t)selectedDigit[adesso2][secondIndex]->GetTDC(),
+                               fMaxDeltaTime));
+               continue;
+             }
 
              AliDebug(1, Form(" %1d %1d (0x%x) %1d %1d (0x%x)", adesso1, firstIndex,selectedDigit[adesso1][firstIndex],
                               adesso2, secondIndex,selectedDigit[adesso2][secondIndex]));
@@ -2568,25 +2673,28 @@ void AliTOFClusterFinderV1::FindClustersPerStrip(Int_t nSector,
 
 
            } // close loop on second digit
-         } // close loop on adesso2
+           //} // close loop on adesso2
 
        } // close loop on first digit
-      } // close loop on adesso1
+         //} // close loop on adesso1
 
 
       break;
 
     case 3:
 
-      for (Int_t adesso1=0; adesso1<interestingCounter+1; adesso1++) {
+      //for (adesso1=0; adesso1<interestingCounter+1; adesso1++) {
+      adesso1 = 0;
        for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
          if (selectedDigit[adesso1][firstIndex]==0x0) continue;
 
-         for (Int_t adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
+         //for (adesso2=adesso1+1; adesso2<interestingCounter+1; adesso2++) {
+         adesso2 = 1;
            for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
              if (selectedDigit[adesso2][secondIndex]==0x0) continue;
 
-             for (Int_t adesso3=adesso2+1; adesso3<interestingCounter+1; adesso3++) {
+             //for (adesso3=adesso2+1; adesso3<interestingCounter+1; adesso3++) {
+             adesso3 = 2;
                for (Int_t thirdIndex=0; thirdIndex<kMaxNumberOfDigitsPerVolume; thirdIndex++) {
                  if (selectedDigit[adesso3][thirdIndex]==0x0) continue;
 
@@ -2753,32 +2861,32 @@ void AliTOFClusterFinderV1::FindClustersPerStrip(Int_t nSector,
 
 
                } // close loop on third digit
-             } // close loop on adesso3
+               //} // close loop on adesso3
 
            } // close loop on second digit
-         } // close loop on adesso2
+           //} // close loop on adesso2
 
        } // close loop on first digit
-      } // close loop on adesso1
+       //} // close loop on adesso1
 
 
       break;
 
     case 4:
 
-      Int_t adesso1 = 0;
+      adesso1 = 0;
       for (Int_t firstIndex=0; firstIndex<kMaxNumberOfDigitsPerVolume; firstIndex++) {
        if (selectedDigit[adesso1][firstIndex]==0x0) continue;
 
-       Int_t adesso2 = 1;
+       adesso2 = 1;
        for (Int_t secondIndex=0; secondIndex<kMaxNumberOfDigitsPerVolume; secondIndex++) {
          if (selectedDigit[adesso2][secondIndex]==0x0) continue;
 
-         Int_t adesso3 = 2;
+         adesso3 = 2;
          for (Int_t thirdIndex=0; thirdIndex<kMaxNumberOfDigitsPerVolume; thirdIndex++) {
            if (selectedDigit[adesso3][thirdIndex]==0x0) continue;
 
-           Int_t adesso4 = 3;
+           adesso4 = 3;
            for (Int_t fourthIndex=0; fourthIndex<kMaxNumberOfDigitsPerVolume; fourthIndex++) {
              if (selectedDigit[adesso4][fourthIndex]==0x0) continue;
 
@@ -3008,11 +3116,16 @@ void AliTOFClusterFinderV1::FindClustersPerStrip(Int_t nSector,
 
   } // loop on iPad
 
-  for (ii=0; ii<kMaxNumberOfInterestingPads; ii++)
+  for (ii=0; ii<kMaxNumberOfInterestingPads; ii++) {
     for (jj=0; jj<kMaxNumberOfDigitsPerVolume; jj++) {
-      delete selectedDigit[ii][jj];
+      delete [] selectedDigit[ii][jj];
       selectedDigit[ii][jj] = 0x0;
     }
+    delete [] selectedDigit[ii];
+    selectedDigit[ii] = 0x0;
+  }
+  delete [] selectedDigit;
+  selectedDigit = 0x0;
 
 }
 //_____________________________________________________________________________
@@ -3479,6 +3592,9 @@ Bool_t AliTOFClusterFinderV1::MakeSlewingCorrection(Int_t *detectorIndex,
   else
     AliDebug(2, Form(" Good Status for channel %d",index));
 
+
+  if (fCalibrateTOFtimes) { // AdC
+
   // Get Rough channel online equalization 
   Double_t roughDelay = (Double_t)calDelay->GetDelay(index);  // in ns
   AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
@@ -3505,8 +3621,11 @@ Bool_t AliTOFClusterFinderV1::MakeSlewingCorrection(Int_t *detectorIndex,
   timeCorr = (Double_t)(tofDigitTdc)*AliTOFGeometry::TdcBinWidth()*1.E-3-timeCorr;//redefine the time
   timeCorr *= 1.E3;
   AliDebug(2,Form(" The channel time, corr (ps)= %e",timeCorr ));
-  tdcCorr = (Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
+  //tdcCorr = (Int_t)(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
+  tdcCorr = TMath::Nint(timeCorr/AliTOFGeometry::TdcBinWidth()); //the corrected time (tdc counts)
   
+  } // AdC
+
   return output;
 
 }
@@ -3621,7 +3740,8 @@ void AliTOFClusterFinderV1::AverageCalculations(Int_t number, Float_t *interesti
                                                Int_t *parTOF, Double_t *posClus, Bool_t &check)
 {
   //
-  //
+  // Calculates the mean values for cluster position (x,y,z),
+  //  TOF charge and time
   //
 
   Double_t tofAverage = 0.;