]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFClusterFinder.cxx
Shadowed declarations: suppression
[u/mrichter/AliRoot.git] / TOF / AliTOFClusterFinder.cxx
index a96570318857d36dc9a85eec6cef89c90b37ac96..75c8f50e0a4bbb90a51bfd49cec55d451489478a 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
+
+Revision 1.29  2007/10/03 10:42:33  arcelli
+updates to handle new AliTOFcluster, inheriting form AliCluster3D
+
+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
+
 Revision 1.26  2007/04/30 19:02:24  arcelli
 hopefully the last refinements for correct type conversion in calibration
 
@@ -84,29 +99,33 @@ Revision 0.01  2005/07/25 A. De Caro
 //                                                            //
 ////////////////////////////////////////////////////////////////
 
+#include "Riostream.h"
 
 #include "TClonesArray.h"
-//#include "TFile.h"
 #include "TStopwatch.h"
 #include "TTree.h"
+//#include <TGeoManager.h>
+#include <TGeoMatrix.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 "AliTOFCal.h"
 #include "AliTOFcalib.h"
-#include "AliTOFChannel.h"
+#include "AliTOFChannelOnline.h"
+#include "AliTOFChannelOnlineStatus.h"
+#include "AliTOFChannelOffline.h"
 #include "AliTOFClusterFinder.h"
 #include "AliTOFcluster.h"
 #include "AliTOFdigit.h"
 #include "AliTOFGeometry.h"
-#include "AliTOFGeometryV5.h"
 #include "AliTOFrawData.h"
 #include "AliTOFRawStream.h"
-#include "Riostream.h"
 
 //extern TFile *gFile;
 
@@ -117,7 +136,6 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
   fTOFLoader(0),
   fTreeD(0),
   fTreeR(0),
-  fTOFGeometry(new AliTOFGeometryV5()),
   fDigits(new TClonesArray("AliTOFdigit", 4000)),
   fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
   fNumberOfTofClusters(0),
@@ -129,8 +147,6 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliTOFcalib *calib):
 // Constructor
 //
 
-  AliInfo("V5 TOF Geometry is taken as the default");
-
 }
 //______________________________________________________________________________
 
@@ -139,7 +155,6 @@ AliTOFClusterFinder::AliTOFClusterFinder(AliRunLoader* runLoader, AliTOFcalib *c
   fTOFLoader(runLoader->GetLoader("TOFLoader")),
   fTreeD(0),
   fTreeR(0),
-  fTOFGeometry(new AliTOFGeometryV5()),
   fDigits(new TClonesArray("AliTOFdigit", 4000)),
   fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
   fNumberOfTofClusters(0),
@@ -160,7 +175,6 @@ AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
   fTOFLoader(0),
   fTreeD(0),
   fTreeR(0),
-  fTOFGeometry(new AliTOFGeometryV5()),
   fDigits(new TClonesArray("AliTOFdigit", 4000)),
   fRecPoints(new TClonesArray("AliTOFcluster", 4000)),
   fNumberOfTofClusters(0),
@@ -171,7 +185,6 @@ AliTOFClusterFinder::AliTOFClusterFinder(const AliTOFClusterFinder &source)
   // copy constructor
   this->fDigits=source.fDigits;
   this->fRecPoints=source.fRecPoints;
-  this->fTOFGeometry=source.fTOFGeometry;
   this->fDecoderVersion=source.fDecoderVersion;
   this->fTOFcalib=source.fTOFcalib;
 
@@ -183,7 +196,6 @@ AliTOFClusterFinder& AliTOFClusterFinder::operator=(const AliTOFClusterFinder &s
   // ass. op.
   this->fDigits=source.fDigits;
   this->fRecPoints=source.fRecPoints;
-  this->fTOFGeometry=source.fTOFGeometry;
   this->fVerbose=source.fVerbose;
   this->fDecoderVersion=source.fDecoderVersion;
   this->fTOFcalib=source.fTOFcalib;
@@ -212,8 +224,6 @@ AliTOFClusterFinder::~AliTOFClusterFinder()
       fRecPoints=0;
     }
 
-  delete fTOFGeometry;
-
 }
 //______________________________________________________________________________
 
@@ -240,7 +250,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();
@@ -259,10 +271,8 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
   Int_t nDigits = digits->GetEntriesFast();
   AliDebug(2,Form("Number of TOF digits: %d",nDigits));
 
-  Int_t ii, jj;
+  Int_t ii;
   Int_t dig[5]; //cluster detector indeces
-  Float_t g[3]; //cluster cartesian coord
-  Double_t h[3]; // the cluster spatial cyl. coordinates
   Int_t  parTOF[5]; //The TOF signal parameters
   Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
   for (ii=0; ii<nDigits; ii++) {
@@ -275,19 +285,16 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent)
 
     //    AliDebug(2,Form(" %2i  %1i  %2i  %1i  %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
 
-    for (jj=0; jj<3; jj++) g[jj] = 0.;
-    fTOFGeometry->GetPos(dig,g);
-
-    h[0] = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
-    h[1] = TMath::ATan2(g[1],g[0]);
-    h[2] = g[2];
-
     parTOF[0] = d->GetTdc(); //the TDC signal
     parTOF[1] = d->GetToT(); //the ToT signal
     parTOF[2] = d->GetAdc(); // the adc charge
     parTOF[3] = d->GetTdcND(); // non decalibrated sim time
     parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
-    AliTOFcluster *tofCluster = new AliTOFcluster(h,dig,parTOF,status,d->GetTracks(),ii);
+    Double_t posClus[3];
+    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);
     InsertCluster(tofCluster);
 
   }
@@ -306,8 +313,6 @@ 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()));
 
-  digits->Delete();
-  delete digits;
 }
 
 //______________________________________________________________________________
@@ -334,7 +339,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();
@@ -347,10 +354,8 @@ void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree
   Int_t nDigits = digits->GetEntriesFast();
   AliDebug(2,Form("Number of TOF digits: %d",nDigits));
 
-  Int_t ii, jj;
+  Int_t ii;
   Int_t dig[5]; //cluster detector indeces
-  Float_t g[3]; //cluster cartesian coord
-  Double_t h[3]; // the cluster spatial cyl. coordinates
   Int_t  parTOF[5]; //The TOF signal parameters
   Bool_t status=kTRUE; // assume all sim channels ok in the beginning...
   for (ii=0; ii<nDigits; ii++) {
@@ -363,19 +368,17 @@ void AliTOFClusterFinder::Digits2RecPoints(TTree* digitsTree, TTree* clusterTree
 
     //    AliDebug(2,Form(" %2i  %1i  %2i  %1i  %2i ",dig[0],dig[1],dig[2],dig[3],dig[4]));
 
-    for (jj=0; jj<3; jj++) g[jj] = 0.;
-    fTOFGeometry->GetPos(dig,g);
-
-    h[0] = TMath::Sqrt(g[0]*g[0]+g[1]*g[1]);
-    h[1] = TMath::ATan2(g[1],g[0]);
-    h[2] = g[2];
-
     parTOF[0] = d->GetTdc(); //the TDC signal
     parTOF[1] = d->GetToT(); //the ToT signal
     parTOF[2] = d->GetAdc(); // the adc charge
     parTOF[3] = d->GetTdcND(); // non decalibrated sim time
     parTOF[4] = d->GetTdc(); // raw time, == Tdc time for the moment
-    AliTOFcluster *tofCluster = new AliTOFcluster(h,dig,parTOF,status,d->GetTracks(),ii);
+    
+    Double_t posClus[3];
+    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);
     InsertCluster(tofCluster);
 
   }
@@ -391,8 +394,6 @@ 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()));
 
-  digits->Delete();
-  delete digits;
 }
 //______________________________________________________________________________
 
@@ -416,22 +417,20 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
 
   TClonesArray * clonesRawData;
 
-  Int_t ii = 0;
   Int_t dummy = -1;
 
   Int_t detectorIndex[5];
-  Float_t position[3];
-  Double_t cylindricalPosition[3];
   Int_t parTOF[5];
 
   ofstream ftxt;
   if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
 
+  AliTOFRawStream tofInput(rawReader);
+
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
-    AliTOFRawStream tofInput(rawReader);
     if (fDecoderVersion) {
       AliInfo("Using New Decoder \n"); 
       tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
@@ -474,19 +473,18 @@ void AliTOFClusterFinder::Digits2RecPoints(AliRawReader *rawReader,
        else              ftxt << " " << detectorIndex[4];
       }
 
-      for (ii=0; ii<3; ii++) position[ii] =  0.;
-      fTOFGeometry->GetPos(detectorIndex, position);
-
-      cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
-      cylindricalPosition[1] = TMath::ATan2(position[1], position[0]);
-      cylindricalPosition[2] = position[2];
-
       parTOF[0] = tofRawDatum->GetTOF(); //TDC
       parTOF[1] = tofRawDatum->GetTOT(); // TOT
       parTOF[2] = tofRawDatum->GetTOT(); //ADC==TOF
       parTOF[3] = -1;//raw data: no track of undecalib sim time
       parTOF[4] = tofRawDatum->GetTOF(); // RAW time
-      AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex, parTOF);
+      Double_t posClus[3];
+      Double_t covClus[6];
+      UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
+      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);
       InsertCluster(tofCluster);
 
       if (fVerbose==2) {
@@ -550,21 +548,19 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
 
   TClonesArray * clonesRawData;
 
-  Int_t ii = 0;
   Int_t dummy = -1;
 
   Int_t detectorIndex[5] = {-1, -1, -1, -1, -1};
-  Float_t position[3];
-  Double_t cylindricalPosition[5];
   Int_t parTOF[5];
   ofstream ftxt;
   if (fVerbose==2) ftxt.open("TOFdigitsRead.txt",ios::app);
 
+  AliTOFRawStream tofInput(rawReader);
+
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
-    AliTOFRawStream tofInput(rawReader);
     if (fDecoderVersion) {
       AliInfo("Using New Decoder \n"); 
       tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
@@ -607,18 +603,18 @@ void AliTOFClusterFinder::Digits2RecPoints(Int_t iEvent, AliRawReader *rawReader
        else              ftxt << " " << detectorIndex[4];
       }
 
-      for (ii=0; ii<3; ii++) position[ii] =  0.;
-      fTOFGeometry->GetPos(detectorIndex, position);
-
-      cylindricalPosition[0] = TMath::Sqrt(position[0]*position[0] + position[1]*position[1]);
-      cylindricalPosition[1] = TMath::ATan2(position[1], position[0]);
-      cylindricalPosition[2] = position[2];
       parTOF[0] = tofRawDatum->GetTOF(); // TDC
       parTOF[1] = tofRawDatum->GetTOT(); // TOT
       parTOF[2] = tofRawDatum->GetTOT(); // raw data have ADC=TOT
       parTOF[3] = -1; //raw data: no track of the undecalib sim time
       parTOF[4] = tofRawDatum->GetTOF(); // Raw time == TDC
-      AliTOFcluster *tofCluster = new AliTOFcluster(cylindricalPosition, detectorIndex, parTOF);
+      Double_t posClus[3];
+      Double_t covClus[6];
+      UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
+      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);
       InsertCluster(tofCluster);
 
       if (fVerbose==2) {
@@ -668,7 +664,7 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
   stopwatch.Start();
 
   //const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
-  const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
+  const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
 
   fRunLoader->GetEvent(iEvent);
 
@@ -696,11 +692,12 @@ void AliTOFClusterFinder::Raw2Digits(Int_t iEvent, AliRawReader *rawReader)
   Int_t detectorIndex[5];
   Int_t digit[4];
 
+  AliTOFRawStream tofInput(rawReader);
+
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
-    AliTOFRawStream tofInput(rawReader);
     if (fDecoderVersion) {
       AliInfo("Using New Decoder \n"); 
       tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
@@ -760,7 +757,7 @@ void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
   TStopwatch stopwatch;
   stopwatch.Start();
 
-  const Int_t kDDL = fTOFGeometry->NDDL()*fTOFGeometry->NSectors();
+  const Int_t kDDL = AliTOFGeometry::NDDL()*AliTOFGeometry::NSectors();
 
   if (!digitsTree)
     {
@@ -783,11 +780,12 @@ void AliTOFClusterFinder::Raw2Digits(AliRawReader *rawReader, TTree* digitsTree)
   Int_t detectorIndex[5];
   Int_t digit[4];
 
+  AliTOFRawStream tofInput(rawReader);
+
   Int_t indexDDL = 0;
   for (indexDDL = 0; indexDDL < kDDL; indexDDL++) {
 
     rawReader->Reset();
-    AliTOFRawStream tofInput(rawReader);
     if (fDecoderVersion) {
       AliInfo("Using New Decoder \n"); 
       tofInput.LoadRawDataBuffers(indexDDL,fVerbose);
@@ -860,7 +858,7 @@ Int_t AliTOFClusterFinder::InsertCluster(AliTOFcluster *tofCluster) {
 
 Int_t AliTOFClusterFinder::FindClusterIndex(Double_t z) const {
   //--------------------------------------------------------------------
-  // This function returns the index of the nearest cluster 
+  // This function returns the index of the nearest cluster in z
   //--------------------------------------------------------------------
   if (fNumberOfTofClusters==0) return 0;
   if (z <= fTofClusters[0]->GetZ()) return 0;
@@ -887,7 +885,6 @@ void AliTOFClusterFinder::FillRecPoint()
   Int_t ii, jj;
 
   Int_t detectorIndex[5];
-  Double_t cylindricalPosition[3];
   Int_t parTOF[5];
   Int_t trackLabels[3];
   Int_t digitIndex = -1;
@@ -900,16 +897,17 @@ void AliTOFClusterFinder::FillRecPoint()
     digitIndex = fTofClusters[ii]->GetIndex();
     for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
     for(jj=0; jj<3; jj++) trackLabels[jj] = fTofClusters[ii]->GetLabel(jj);
-    cylindricalPosition[0] = fTofClusters[ii]->GetR();
-    cylindricalPosition[1] = fTofClusters[ii]->GetPhi();
-    cylindricalPosition[2] = fTofClusters[ii]->GetZ();
     parTOF[0] = fTofClusters[ii]->GetTDC(); // TDC
     parTOF[1] = fTofClusters[ii]->GetToT(); // TOT
     parTOF[2] = fTofClusters[ii]->GetADC(); // ADC=TOT
     parTOF[3] = fTofClusters[ii]->GetTDCND(); // TDCND
     parTOF[4] = fTofClusters[ii]->GetTDCRAW();//RAW
     status=fTofClusters[ii]->GetStatus();
-    new(lRecPoints[ii]) AliTOFcluster(cylindricalPosition, detectorIndex, parTOF,status,trackLabels,digitIndex);
+    Double_t posClus[3];
+    Double_t covClus[6];
+    UShort_t volIdClus=GetClusterVolIndex(detectorIndex);
+    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);
 
   } // loop on clusters
 
@@ -933,40 +931,80 @@ void AliTOFClusterFinder::CalibrateRecPoint()
   Int_t   tdcCorr;
   AliInfo(" Calibrating TOF Clusters: ")
   
-  AliTOFCal *calTOFArray = fTOFcalib->GetTOFCalArray();  
-
+  TObjArray *calTOFArrayOnline = fTOFcalib->GetTOFCalArrayOnline();  
+  TObjArray *calTOFArrayOnlinePulser = fTOFcalib->GetTOFCalArrayOnlinePulser();  
+  TObjArray *calTOFArrayOnlineNoise = fTOFcalib->GetTOFCalArrayOnlineNoise();  
+  TObjArray *calTOFArrayOnlineHW = fTOFcalib->GetTOFCalArrayOnlineHW();  
+  TObjArray *calTOFArrayOffline = fTOFcalib->GetTOFCalArrayOffline();
+  TString validity = (TString)fTOFcalib->GetOfflineValidity();
+  AliInfo(Form(" validity = %s",validity.Data()));
+  Int_t calibration = -1;
+  if (validity.CompareTo("valid")==0) {
+    AliInfo(" Using offline calibration parameters");
+    calibration = 1;
+  }
+  else {
+    AliInfo(" Using online calibration parameters");
+    calibration = 0 ;
+  }
   for (ii=0; ii<fNumberOfTofClusters; ii++) {
     digitIndex = fTofClusters[ii]->GetIndex();
     for(jj=0; jj<5; jj++) detectorIndex[jj] = fTofClusters[ii]->GetDetInd(jj);
 
-    Int_t index = fTOFcalib->GetIndex(detectorIndex);
+    Int_t index = AliTOFGeometry::GetIndex(detectorIndex);
      
-    AliTOFChannel * calChannel = calTOFArray->GetChannel(index);
+    AliTOFChannelOnlineStatus * calChannelOnlineStPulser = (AliTOFChannelOnlineStatus* )calTOFArrayOnlinePulser->At(index);
+    AliTOFChannelOnlineStatus * calChannelOnlineStNoise = (AliTOFChannelOnlineStatus* )calTOFArrayOnlineNoise->At(index);
+    AliTOFChannelOnlineStatus * calChannelOnlineStHW = (AliTOFChannelOnlineStatus* )calTOFArrayOnlineHW->At(index);
 
     // Get channel status 
-    Bool_t status=calChannel->GetStatus();
-    if(status)fTofClusters[ii]->SetStatus(!status); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
+    UChar_t statusPulser=calChannelOnlineStPulser->GetStatus();
+    UChar_t statusNoise=calChannelOnlineStNoise->GetStatus();
+    UChar_t statusHW=calChannelOnlineStHW->GetStatus();
+
+    //check the status, also unknow is fine!!!!!!!
+
+    UChar_t status = 0x0;
+    status |= statusPulser;
+    status |= statusNoise;
+    status |= statusHW;
+    // set status of the cluster to false if at least one of the three status (Pulser/Noise/HW) is bad
+    if((statusPulser & AliTOFChannelOnlineStatus::kTOFPulserBad)==(AliTOFChannelOnlineStatus::kTOFPulserBad)||(statusNoise & AliTOFChannelOnlineStatus::kTOFNoiseBad)==(AliTOFChannelOnlineStatus::kTOFNoiseBad)||(statusHW & AliTOFChannelOnlineStatus::kTOFHWBad)==(AliTOFChannelOnlineStatus::kTOFHWBad)){
+      AliDebug(2, Form(" Bad Status for channel %i",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 %i",index));
+    }
+    //    if((status & AliTOFChannelOnlineStatus::kTOFOnlineOk)!=(AliTOFChannelOnline::kTOFOnlineOk))fTofClusters[ii]->SetStatus(kFALSE); //odd convention, to avoid conflict with calibration objects currently in the db (temporary solution).
     // Get Rough channel online equalization 
-    Float_t roughDelay=calChannel->GetDelay();
-    AliDebug(2,Form(" channel delay = %f", roughDelay));
+    AliTOFChannelOnline * calChannelOnline = (AliTOFChannelOnline* )calTOFArrayOnline->At(index);
+    Double_t roughDelay=(Double_t)calChannelOnline->GetDelay();  // in ns
+    AliDebug(2,Form(" channel delay (ns) = %f", roughDelay));
     // Get Refined channel offline calibration parameters
-    Float_t par[6];
-    for (Int_t j = 0; j<6; j++){
-      par[j]=calChannel->GetSlewPar(j);
+    if (calibration ==1){
+      AliTOFChannelOffline * calChannelOffline = (AliTOFChannelOffline*)calTOFArrayOffline->At(index);
+      Double_t par[6];
+      for (Int_t j = 0; j<6; j++){
+       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()));
-    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));
-    timeCorr=par[0]+par[1]*tToT+par[2]*tToT*tToT+par[3]*tToT*tToT*tToT+par[4]*tToT*tToT*tToT*tToT+par[5]*tToT*tToT*tToT*tToT*tToT+roughDelay; // the time correction
+      AliDebug(2,Form(" The ToT and Time, uncorr (counts) = %i , %i", 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));
+      timeCorr=par[0]+par[1]*tToT+par[2]*tToT*tToT+par[3]*tToT*tToT*tToT+par[4]*tToT*tToT*tToT*tToT+par[5]*tToT*tToT*tToT*tToT*tToT; // the time correction (ns)
+    }
+    else {
+      timeCorr = roughDelay; // correction in ns
+    }
+    AliDebug(2,Form(" The ToT and Time, uncorr (ns)= %e, %e",fTofClusters[ii]->GetTDC()*AliTOFGeometry::TdcBinWidth()*1.E-3,fTofClusters[ii]->GetToT()*AliTOFGeometry::ToTBinWidth()));
     AliDebug(2,Form(" The time correction (ns) = %f", timeCorr));
     timeCorr=(Double_t)(fTofClusters[ii]->GetTDC())*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)
     fTofClusters[ii]->SetTDC(tdcCorr);
-    AliDebug(2,Form(" The channel time, corr (counts) = %i",fTofClusters[ii]->GetTDC()));
-
   } // loop on clusters
 
 }
@@ -1028,4 +1066,122 @@ void AliTOFClusterFinder::UnLoadClusters()
   fTOFLoader->UnloadRecPoints();
 
 }
-//______________________________________________________________________________
+//-------------------------------------------------------------------------
+UShort_t AliTOFClusterFinder::GetClusterVolIndex(Int_t *ind) const {
+
+  //First of all get the volume ID to retrieve the l2t transformation...
+  //
+  // Detector numbering scheme
+  Int_t nSector = 18;
+  Int_t nPlate  = 5;
+  Int_t nStripA = 15;
+  Int_t nStripB = 19;
+  Int_t nStripC = 19;
+
+  Int_t isector =ind[0];
+  if (isector >= nSector)
+    AliError(Form("Wrong sector number in TOF (%d) !",isector));
+  Int_t iplate = ind[1];
+  if (iplate >= nPlate)
+    AliError(Form("Wrong plate number in TOF (%d) !",iplate));
+  Int_t istrip = ind[2];
+
+  Int_t stripOffset = 0;
+  switch (iplate) {
+  case 0:
+    stripOffset = 0;
+    break;
+  case 1:
+    stripOffset = nStripC;
+    break;
+  case 2:
+    stripOffset = nStripC+nStripB;
+    break;
+  case 3:
+    stripOffset = nStripC+nStripB+nStripA;
+    break;
+  case 4:
+    stripOffset = nStripC+nStripB+nStripA+nStripB;
+    break;
+  default:
+    AliError(Form("Wrong plate number in TOF (%d) !",iplate));
+    break;
+  };
+
+  Int_t index= (2*(nStripC+nStripB)+nStripA)*isector +
+               stripOffset +
+               istrip;
+
+  UShort_t volIndex = AliGeomManager::LayerToVolUID(AliGeomManager::kTOF,index);
+  return volIndex;
+}
+//
+//-------------------------------------------------------------------------
+void AliTOFClusterFinder::GetClusterPars(Int_t *ind, Double_t* pos,Double_t* cov) const {
+
+  //First of all get the volume ID to retrieve the l2t transformation...
+  //
+  UShort_t volIndex = GetClusterVolIndex(ind);
+  //
+  //
+  //we now go in the system of the strip: determine the local coordinates
+  //
+  //
+  // 47---------------------------------------------------0  ^ z
+  // | | | | | | | | | | | | | | | | | | | | | | | | | | | 1 |
+  // -----------------------------------------------------   | y going outwards
+  // | | | | | | | | | | | | | | | | | | | | | | | | | | | 0 |  par[0]=0;
+
+  // -----------------------------------------------------   |
+  // x <-----------------------------------------------------
+
+  Float_t localX=(ind[4]-23.5)*2.5; 
+  Float_t localY=0; 
+  Float_t localZ=(ind[3]-0.5)*3.5; 
+
+  //move to the tracking ref system
+
+  Double_t lpos[3];
+  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];
+
+  //Get The cluster covariance in the track ref system
+  Double_t lcov[9];
+
+  //cluster covariance in the local system:
+  // sx2   0   0
+  // 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.;
+
+  //cluster covariance in the tracking system:
+  TGeoHMatrix m;
+  m.SetRotation(lcov);
+  m.Multiply(l2t);
+  m.MultiplyLeft(&l2t->Inverse());
+  Double_t *tcov = m.GetRotationMatrix();
+  cov[0] = tcov[0]; cov[1] = tcov[1]; cov[2] = tcov[2];
+  cov[3] = tcov[4]; cov[4] = tcov[5];
+  cov[5] = tcov[8];
+
+  return;
+
+}