]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TOF/AliTOFcalib.cxx
Fix for TOF new calib task for CPass
[u/mrichter/AliRoot.git] / TOF / AliTOFcalib.cxx
index e8aa6ab9cee58bfb4bdceab7ee23ca14cd24e9eb..e24882ed110b0c9a10b41f7028112f654ca68434 100644 (file)
@@ -84,6 +84,7 @@ author: Chiara Zampolli, zampolli@bo.infn.it
 #include "TF1.h"
 #include "TFile.h"
 #include "TH1F.h"
+#include "TH1C.h"
 #include "TH2F.h"
 //#include "TList.h"
 //#include "TROOT.h"
@@ -93,6 +94,7 @@ author: Chiara Zampolli, zampolli@bo.infn.it
 #include "TProfile.h"
 #include "TGrid.h"
 #include "TMath.h"
+#include "TMap.h"
 
 #include "AliCDBEntry.h"
 #include "AliCDBRunRange.h"
@@ -105,16 +107,27 @@ author: Chiara Zampolli, zampolli@bo.infn.it
 #include "AliLog.h"
 
 #include "AliTOFcalib.h"
+#include "AliTOFChannelOnlineArray.h"
 #include "AliTOFChannelOnline.h"
 #include "AliTOFChannelOnlineStatus.h"
+#include "AliTOFChannelOnlineStatusArray.h"
 #include "AliTOFChannelOffline.h"
 #include "AliTOFGeometry.h"
 #include "AliTOFRecoParam.h"
+#include "AliTOFDeltaBCOffset.h"
+#include "AliTOFCTPLatency.h"
+#include "AliTOFT0Fill.h"
+#include "AliTOFRunParams.h"
+#include "AliLHCClockPhase.h"
+#include "AliTOFResponseParams.h"
+#include "AliESDEvent.h"
+#include "AliESDtrack.h"
+#include "TRandom.h"
 
 class TROOT;
 class TStyle;
 
-extern TROOT *gROOT;
+//extern TROOT *gROOT;
 extern TStyle *gStyle;
 
 ClassImp(AliTOFcalib)
@@ -128,35 +141,83 @@ AliTOFcalib::AliTOFcalib():
   fTOFCalOnlineNoise(0x0),
   fTOFCalOnlineHW(0x0),
   fTOFCalOffline(0x0),
+  fCal(0x0),
+  fStatus(0x0),
   fTOFSimToT(0x0),
   fkValidity(0x0),
   fTree(0x0),
   fChain(0x0),
   fNruns(0),
   fFirstRun(0),
-  fLastRun(AliCDBRunRange::Infinity())
+  fLastRun(AliCDBRunRange::Infinity()),
+  fConfigMap(new TMap),
+  fDeltaBCOffset(NULL),
+  fCTPLatency(NULL),
+  fT0Fill(NULL),
+  fRunParams(NULL),
+  fLHCClockPhase(NULL),
+  fResponseParams(NULL),
+  fReadoutEfficiency(NULL),
+  fProblematic(NULL),
+  fInitFlag(kFALSE),
+  fRemoveMeanT0(kTRUE),
+  fUseLHCClockPhase(kFALSE),
+  fCalibrateTOFsignal(kTRUE),
+  fCorrectTExp(kFALSE),
+  fRunParamsSpecificVersion(-1)
 { 
   //TOF Calibration Class ctor
   fNChannels = AliTOFGeometry::NSectors()*(2*(AliTOFGeometry::NStripC()+AliTOFGeometry::NStripB())+AliTOFGeometry::NStripA())*AliTOFGeometry::NpadZ()*AliTOFGeometry::NpadX();
+
+  gRandom->SetSeed(123456789);
 }
 //____________________________________________________________________________ 
 
 AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
-  TTask("AliTOFcalib",""),
+  TTask(calib),
   fNChannels(calib.fNChannels),
   fTOFCalOnline(0x0),
   fTOFCalOnlinePulser(0x0),
   fTOFCalOnlineNoise(0x0),
   fTOFCalOnlineHW(0x0),
   fTOFCalOffline(0x0),
+  fCal(calib.fCal),
+  fStatus(calib.fStatus),
   fTOFSimToT(calib.fTOFSimToT),
   fkValidity(calib.fkValidity),
   fTree(calib.fTree),
   fChain(calib.fChain),
   fNruns(calib.fNruns),
   fFirstRun(calib.fFirstRun),
-  fLastRun(calib.fLastRun)
+  fLastRun(calib.fLastRun),
+  fConfigMap(calib.fConfigMap),
+  fDeltaBCOffset(NULL),
+  fCTPLatency(NULL),
+  fT0Fill(NULL),
+  fRunParams(NULL),
+  fLHCClockPhase(NULL),
+  fResponseParams(NULL),
+  fReadoutEfficiency(NULL),
+  fProblematic(NULL),
+  fInitFlag(calib.fInitFlag),
+  fRemoveMeanT0(calib.fRemoveMeanT0),
+  fUseLHCClockPhase(calib.fUseLHCClockPhase),
+  fCalibrateTOFsignal(calib.fCalibrateTOFsignal),
+  fCorrectTExp(calib.fCorrectTExp),
+  fRunParamsSpecificVersion(calib.fRunParamsSpecificVersion)
 {
+
+  fTOFCalOnline = new TObjArray(fNChannels);
+  fTOFCalOnlinePulser = new TObjArray(fNChannels);
+  fTOFCalOnlineNoise = new TObjArray(fNChannels);
+  fTOFCalOnlineHW = new TObjArray(fNChannels);
+  fTOFCalOffline = new TObjArray(fNChannels);
+  fTOFCalOnline->SetOwner();
+  fTOFCalOnlinePulser->SetOwner();
+  fTOFCalOnlineNoise->SetOwner();
+  fTOFCalOnlineHW->SetOwner();
+  fTOFCalOffline->SetOwner();
+
   //TOF Calibration Class copy ctor
   for (Int_t iarray = 0; iarray<fNChannels; iarray++){
     AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
@@ -169,8 +230,17 @@ AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
     fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
     fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
     fTOFCalOffline->AddAt(calChOffline,iarray);
-
   }
+
+  if (calib.fDeltaBCOffset) fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
+  if (calib.fCTPLatency) fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
+  if (calib.fT0Fill) fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
+  if (calib.fRunParams) fRunParams = new AliTOFRunParams(*calib.fRunParams);
+  if (calib.fResponseParams) fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
+  if (calib.fReadoutEfficiency) fReadoutEfficiency = new TH1F(*calib.fReadoutEfficiency);
+  if (calib.fProblematic) fProblematic = new TH1C(*calib.fProblematic);
+
+  gRandom->SetSeed(123456789);
 }
 
 //____________________________________________________________________________ 
@@ -178,26 +248,71 @@ AliTOFcalib::AliTOFcalib(const AliTOFcalib & calib):
 AliTOFcalib& AliTOFcalib::operator=(const AliTOFcalib &calib)
 {
   //TOF Calibration Class assignment operator
-  this->fNChannels = calib.fNChannels;
-  this->fTOFSimToT = calib.fTOFSimToT;
-  this->fkValidity = calib.fkValidity;
-  this->fTree = calib.fTree;
-  this->fChain = calib.fChain;
-  this->fNruns = calib.fNruns;
-  this->fFirstRun = calib.fFirstRun;
-  this->fLastRun = calib.fLastRun;
+
+  if (this == &calib)
+    return *this;
+  
+  TTask::operator=(calib);
+  fNChannels = calib.fNChannels;
+  fCal = calib.fCal;
+  fStatus = calib.fStatus;
+  fTOFSimToT = calib.fTOFSimToT;
+  fkValidity = calib.fkValidity;
+  fTree = calib.fTree;
+  fChain = calib.fChain;
+  fNruns = calib.fNruns;
+  fFirstRun = calib.fFirstRun;
+  fLastRun = calib.fLastRun;
   for (Int_t iarray = 0; iarray<fNChannels; iarray++){
     AliTOFChannelOnline * calChOnline = (AliTOFChannelOnline*)calib.fTOFCalOnline->At(iarray);
     AliTOFChannelOffline * calChOffline = (AliTOFChannelOffline*)calib.fTOFCalOffline->At(iarray);
     AliTOFChannelOnlineStatus * calChOnlineStPulser = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlinePulser->At(iarray);
     AliTOFChannelOnlineStatus * calChOnlineStNoise = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineNoise->At(iarray);
     AliTOFChannelOnlineStatus * calChOnlineStHW = (AliTOFChannelOnlineStatus*)calib.fTOFCalOnlineHW->At(iarray);
-    this->fTOFCalOnline->AddAt(calChOnline,iarray);
-    this->fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
-    this->fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
-    this->fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
-    this->fTOFCalOffline->AddAt(calChOffline,iarray);
+    fTOFCalOnline->AddAt(calChOnline,iarray);
+    fTOFCalOnlinePulser->AddAt(calChOnlineStPulser,iarray);
+    fTOFCalOnlineNoise->AddAt(calChOnlineStNoise,iarray);
+    fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
+    fTOFCalOffline->AddAt(calChOffline,iarray);
+  }
+
+  if (calib.fDeltaBCOffset) {
+    if (fDeltaBCOffset) *fDeltaBCOffset = *calib.fDeltaBCOffset;
+    else fDeltaBCOffset = new AliTOFDeltaBCOffset(*calib.fDeltaBCOffset);
+  }
+
+  if (calib.fCTPLatency) {
+    if (fCTPLatency) *fCTPLatency = *calib.fCTPLatency;
+    else fCTPLatency = new AliTOFCTPLatency(*calib.fCTPLatency);
+  }
+
+  if (calib.fT0Fill) {
+    if (fT0Fill) *fT0Fill = *calib.fT0Fill;
+    else fT0Fill = new AliTOFT0Fill(*calib.fT0Fill);
   }
+  if (calib.fRunParams) {
+    if (fRunParams) *fRunParams = *calib.fRunParams;
+    else fRunParams = new AliTOFRunParams(*calib.fRunParams);
+  }
+  if (calib.fResponseParams) {
+    if (fResponseParams) *fResponseParams = *calib.fResponseParams;
+    else fResponseParams = new AliTOFResponseParams(*calib.fResponseParams);
+  }
+  if (calib.fReadoutEfficiency) {
+    if (fReadoutEfficiency) *fReadoutEfficiency = *calib.fReadoutEfficiency;
+    else fReadoutEfficiency = new TH1F(*calib.fReadoutEfficiency);
+  }
+  if (calib.fProblematic) {
+    if (fProblematic) *fProblematic = *calib.fProblematic;
+    else fProblematic = new TH1C(*calib.fProblematic);
+  }
+  fInitFlag = calib.fInitFlag;
+  fRemoveMeanT0 = calib.fRemoveMeanT0;
+  fUseLHCClockPhase = calib.fUseLHCClockPhase;
+  fCalibrateTOFsignal = calib.fCalibrateTOFsignal;
+  fCorrectTExp = calib.fCorrectTExp;
+  fRunParamsSpecificVersion = calib.fRunParamsSpecificVersion;
+
   return *this;
 }
 
@@ -222,9 +337,26 @@ AliTOFcalib::~AliTOFcalib()
     if (fTOFCalOffline){
       delete fTOFCalOffline;
     }
+    if (fCal){
+      delete fCal;
+    }
+    if (fStatus){
+      delete fStatus;
+    }
+    if (fConfigMap){
+      delete fConfigMap;
+    }
+    if (fDeltaBCOffset) delete fDeltaBCOffset;
+    if (fCTPLatency) delete fCTPLatency;
+    if (fT0Fill) delete fT0Fill;
+    if (fRunParams) delete fRunParams;
+    if (fResponseParams) delete fResponseParams;
+    if (fReadoutEfficiency) delete fReadoutEfficiency;
+    if (fProblematic) delete fProblematic;
   }
   if (fTree!=0x0) delete fTree;
   if (fChain!=0x0) delete fChain;
+
 }
 //_____________________________________________________________________________
 void AliTOFcalib::CreateCalArrays(){
@@ -253,17 +385,146 @@ void AliTOFcalib::CreateCalArrays(){
     fTOFCalOnlineHW->AddAt(calChOnlineStHW,iarray);
     fTOFCalOffline->AddAt(calChOffline,iarray);
   }
+  fCal = new AliTOFChannelOnlineArray(fNChannels);
+  fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
 }
 //_____________________________________________________________________________
-void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
+void AliTOFcalib::CreateCalObjects(){
+
+  // creating arrays for online/offline calibration objs
+
+  fTOFCalOffline = new TObjArray(fNChannels);
+  fTOFCalOffline->SetOwner();
+  for (Int_t iarray = 0; iarray<fNChannels; iarray++){
+    AliTOFChannelOffline * calChOffline = new AliTOFChannelOffline();
+    fTOFCalOffline->AddAt(calChOffline,iarray);
+  }
+  fCal = new AliTOFChannelOnlineArray(fNChannels);
+  fStatus = new AliTOFChannelOnlineStatusArray(fNChannels);
+}
+//_____________________________________________________________________________
+void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
 {
   //Write calibration parameters to the CDB
   SetFirstRun(minrun);
   SetLastRun(maxrun);
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "ParOnline" ;  // to be consistent with TOFPreprocessor
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "Config" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
+  AliDebug(2,Form("Writing TOF configuration map for online calib on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
+  AliCDBId id(out,fFirstRun,fLastRun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Chiara Zampolli");
+  if (!fConfigMap) {
+    // deve uscire!!
+  }
+  man->Put(fConfigMap,id,md);
+  delete md;
+}
+//_____________________________________________________________________________
+
+void AliTOFcalib::WriteConfigMapOnCDB(const Char_t *sel)
+{
+  //Write calibration parameters to the CDB with infinite validity
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "Config" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
+  AliCDBRunRange runrange(fFirstRun,fLastRun);
+  AliDebug(2,Form("Writing TOF config map for online calib on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
+  AliCDBId id(out,runrange);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Chiara Zampolli");
+  if (!fConfigMap) {
+    // deve uscire!!
+  }
+  man->Put(fConfigMap,id,md);
+  delete md;
+}
+//_____________________________________________________________________________
+void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
+{
+  //Write calibration parameters to the CDB -------> new calib objs!!!!!
+  SetFirstRun(minrun);
+  SetLastRun(maxrun);
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "ParOnlineDelay" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
+  AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
+  AliCDBId id(out,fFirstRun,fLastRun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Chiara Zampolli");
+  if (!fCal) {
+    // deve uscire!!
+  }
+  man->Put(fCal,id,md);
+  delete md;
+}
+//_____________________________________________________________________________
+void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
+{
+  //Write calibration parameters to the CDB -------> new calib objs!!!!!
+  SetFirstRun(minrun);
+  SetLastRun(maxrun);
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "Status" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
+  AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
+  AliCDBId id(out,fFirstRun,fLastRun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Chiara Zampolli");
+  if (!fStatus) {
+    // deve uscire!!
+  }
+  man->Put(fStatus,id,md);
+  delete md;
+}
+//_____________________________________________________________________________
+
+void AliTOFcalib::WriteParOnlineDelayOnCDB(const Char_t *sel)
+{
+  //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "ParOnlineDelay" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
+  AliCDBRunRange runrange(fFirstRun,fLastRun);
+  AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
+  AliCDBId id(out,runrange);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Chiara Zampolli");
+  if (!fCal) {
+    // deve uscire!!
+  }
+  man->Put(fCal,id,md);
+  delete md;
+}
+//_____________________________________________________________________________
+
+void AliTOFcalib::WriteParOnlineStatusOnCDB(const Char_t *sel)
+{
+  //Write calibration parameters to the CDB with infinite validity -------> new calib objs!!!!!
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "Status" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
+  AliCDBRunRange runrange(fFirstRun,fLastRun);
+  AliDebug(2,Form("Writing TOF online status calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
+  AliCDBId id(out,runrange);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Chiara Zampolli");
+  if (!fStatus) {
+    // deve uscire!!
+  }
+  man->Put(fStatus,id,md);
+  delete md;
+}
+//_____________________________________________________________________________
+void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
+{
+  //Write calibration parameters to the CDB
+  SetFirstRun(minrun);
+  SetLastRun(maxrun);
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "ParOnline" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
   AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
   AliCDBId id(out,fFirstRun,fLastRun);
   AliCDBMetaData *md = new AliCDBMetaData();
@@ -275,15 +536,14 @@ void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
   delete md;
 }
 //_____________________________________________________________________________
-void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
+void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
 {
   //Write calibration parameters from pulser to the CDB
   SetFirstRun(minrun);
   SetLastRun(maxrun);
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "Pulser" ;  // to be consistent with TOFPreprocessor
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "Pulser" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
   AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
   AliCDBId id(out,fFirstRun,fLastRun);
   AliCDBMetaData *md = new AliCDBMetaData();
@@ -295,15 +555,14 @@ void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel, Int_t minrun, Int_t max
   delete md;
 }
 //_____________________________________________________________________________
-void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
+void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
 {
   //Write calibration parameters from noise to the CDB
   SetFirstRun(minrun);
   SetLastRun(maxrun);
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "Noise" ;  // to be consistent with TOFPreprocessor
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "Noise" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
   AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
   AliCDBId id(out,fFirstRun,fLastRun);
   AliCDBMetaData *md = new AliCDBMetaData();
@@ -315,15 +574,14 @@ void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel, Int_t minrun, Int_t maxr
   delete md;
 }
 //_____________________________________________________________________________
-void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
+void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun)
 {
   //Write calibration parameters from hardware to the CDB
   SetFirstRun(minrun);
   SetLastRun(maxrun);
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "HW" ;  // to be consistent with TOFPreprocessor
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "HW" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
   AliDebug(2,Form("Writing TOF online calib obj from hardware on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
   AliCDBId id(out,fFirstRun,fLastRun);
   AliCDBMetaData *md = new AliCDBMetaData();
@@ -336,13 +594,12 @@ void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun)
 }
 //_____________________________________________________________________________
 
-void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel)
+void AliTOFcalib::WriteParOnlineOnCDB(const Char_t *sel)
 {
   //Write calibration parameters to the CDB with infinite validity
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "ParOnline" ;  // to be consistent with TOFPreprocessor
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "ParOnline" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBRunRange runrange(fFirstRun,fLastRun);
   AliDebug(2,Form("Writing TOF online calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
   AliCDBId id(out,runrange);
@@ -356,13 +613,12 @@ void AliTOFcalib::WriteParOnlineOnCDB(Char_t *sel)
 }
 //_____________________________________________________________________________
 
-void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel)
+void AliTOFcalib::WriteParOnlinePulserOnCDB(const Char_t *sel)
 {
   //Write calibration parameters from pulser to the CDB with infinite validity
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "Pulser" ;  // to be consistent with TOFPreprocessor
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "Pulser" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBRunRange runrange(fFirstRun,fLastRun);
   AliDebug(2,Form("Writing TOF online calib obj from pulser on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
   AliCDBId id(out,runrange);
@@ -376,13 +632,12 @@ void AliTOFcalib::WriteParOnlinePulserOnCDB(Char_t *sel)
 }
 //_____________________________________________________________________________
 
-void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel)
+void AliTOFcalib::WriteParOnlineNoiseOnCDB(const Char_t *sel)
 {
   //Write calibration parameters from noise to the CDB with infinite validity
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "Noise" ;  // to be consistent with TOFPreprocessor
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "Noise" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBRunRange runrange(fFirstRun,fLastRun);
   AliDebug(2,Form("Writing TOF online calib obj from noise on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
   AliCDBId id(out,runrange);
@@ -396,13 +651,12 @@ void AliTOFcalib::WriteParOnlineNoiseOnCDB(Char_t *sel)
 }
 //_____________________________________________________________________________
 
-void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel)
+void AliTOFcalib::WriteParOnlineHWOnCDB(const Char_t *sel)
 {
   //Write calibration parameters from hardware to the CDB with infinite validity
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "HW" ;  // to be consistent with TOFPreprocessor
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "HW" ;  // to be consistent with TOFPreprocessor
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBRunRange runrange(fFirstRun,fLastRun);
   AliDebug(2,Form("Writing TOF online calib obj from harware on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
   AliCDBId id(out,runrange);
@@ -416,15 +670,14 @@ void AliTOFcalib::WriteParOnlineHWOnCDB(Char_t *sel)
 }
 //_____________________________________________________________________________
 
-void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
+void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity, Int_t minrun, Int_t maxrun)
 {
   //Write calibration parameters to the CDB
   SetFirstRun(minrun);
   SetLastRun(maxrun);
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "ParOffline" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "ParOffline" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",fFirstRun,fLastRun));
   AliCDBId id(out,fFirstRun,fLastRun);
   AliCDBMetaData *md = new AliCDBMetaData();
@@ -435,13 +688,12 @@ void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity, Int_
 }
 //_____________________________________________________________________________
 
-void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity)
+void AliTOFcalib::WriteParOfflineOnCDB(const Char_t *sel, const Char_t *validity)
 {
   //Write calibration parameters to the CDB with infinite validity
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "ParOffline" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "ParOffline" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBRunRange runrange(fFirstRun,fLastRun);
   AliDebug(2,Form("Writing TOF offline calib obj on CDB with run range [%i, %i] ",runrange.GetFirstRun(),runrange.GetLastRun()));
   AliCDBId id(out,runrange);
@@ -453,13 +705,81 @@ void AliTOFcalib::WriteParOfflineOnCDB(Char_t *sel, const Char_t *validity)
 }
 //_____________________________________________________________________________
 
-Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun)
+Bool_t AliTOFcalib::ReadConfigMapFromCDB(const Char_t *sel, Int_t nrun)
+{
+  //Read calibration parameters from the CDB
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "Config" ;
+  TString out(Form("%s/%s",sel,sel1));
+  AliCDBEntry *entry = man->Get(out,nrun);
+  if (!entry) { 
+    AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
+    exit(0);  
+  }
+  if(!entry->GetObject()){
+    AliFatal("Exiting, no CDB object (ConfigMap) found!!!");
+    exit(0);  
+  }  
+  
+  fConfigMap =(TMap*)entry->GetObject();
+
+  return kTRUE; 
+   
+}
+//_____________________________________________________________________________
+
+Bool_t AliTOFcalib::ReadParOnlineDelayFromCDB(const Char_t *sel, Int_t nrun)
+{
+  //Read calibration parameters from the CDB -------> new calib objs!!!!!
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "ParOnlineDelay" ;
+  TString out(Form("%s/%s",sel,sel1));
+  AliCDBEntry *entry = man->Get(out,nrun);
+  if (!entry) { 
+    AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
+    exit(0);  
+  }
+  if(!entry->GetObject()){
+    AliFatal("Exiting, no CDB object (ParOnlineDelay) found!!!");
+    exit(0);  
+  }  
+  
+  fCal =(AliTOFChannelOnlineArray*)entry->GetObject();
+
+  return kTRUE; 
+   
+}
+//_____________________________________________________________________________
+
+Bool_t AliTOFcalib::ReadParOnlineStatusFromCDB(const Char_t *sel, Int_t nrun)
+{
+  //Read calibration parameters from the CDB -------> new calib objs!!!!!
+  AliCDBManager *man = AliCDBManager::Instance();
+  const Char_t *sel1 = "Status" ;
+  TString out(Form("%s/%s",sel,sel1));
+  AliCDBEntry *entry = man->Get(out,nrun);
+  if (!entry) { 
+    AliFatal("Exiting, no CDB object (Status) found!!!");
+    exit(0);  
+  }
+  if(!entry->GetObject()){
+    AliFatal("Exiting, no CDB object (Status) found!!!");
+    exit(0);  
+  }  
+  
+  fStatus =(AliTOFChannelOnlineStatusArray*)entry->GetObject();
+
+  return kTRUE; 
+   
+}
+//_____________________________________________________________________________
+
+Bool_t AliTOFcalib::ReadParOnlineFromCDB(const Char_t *sel, Int_t nrun)
 {
   //Read calibration parameters from the CDB
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "ParOnline" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "ParOnline" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBEntry *entry = man->Get(out,nrun);
   if (!entry) { 
     AliFatal("Exiting, no CDB object (ParOnline) found!!!");
@@ -477,13 +797,12 @@ Bool_t AliTOFcalib::ReadParOnlineFromCDB(Char_t *sel, Int_t nrun)
 }
 //_____________________________________________________________________________
 
-Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(Char_t *sel, Int_t nrun)
+Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(const Char_t *sel, Int_t nrun)
 {
   //Read calibration parameters from pulser from the CDB
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "Pulser" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "Pulser" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBEntry *entry = man->Get(out,nrun);
   if (!entry) { 
     AliFatal("Exiting, no CDB object (Pulser) found!!!");
@@ -501,13 +820,12 @@ Bool_t AliTOFcalib::ReadParOnlinePulserFromCDB(Char_t *sel, Int_t nrun)
 }
 //_____________________________________________________________________________
 
-Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(Char_t *sel, Int_t nrun)
+Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(const Char_t *sel, Int_t nrun)
 {
   //Read calibration parameters from noise from the CDB
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "Noise" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "Noise" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBEntry *entry = man->Get(out,nrun);
   if (!entry) { 
     AliFatal("Exiting, no CDB object (Noise) found!!!");
@@ -525,13 +843,12 @@ Bool_t AliTOFcalib::ReadParOnlineNoiseFromCDB(Char_t *sel, Int_t nrun)
 }
 //_____________________________________________________________________________
 
-Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(Char_t *sel, Int_t nrun)
+Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(const Char_t *sel, Int_t nrun)
 {
   //Read calibration parameters from hardware from the CDB
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "HW" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "HW" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBEntry *entry = man->Get(out,nrun);
   if (!entry) { 
     AliFatal("Exiting, no CDB object (HW map) found!!!");
@@ -549,13 +866,12 @@ Bool_t AliTOFcalib::ReadParOnlineHWFromCDB(Char_t *sel, Int_t nrun)
 }
 //_____________________________________________________________________________
 
-Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
+Bool_t AliTOFcalib::ReadParOfflineFromCDB(const Char_t *sel, Int_t nrun)
 {
   //Read calibration parameters from the CDB
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "ParOffline" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "ParOffline" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBEntry *entry = man->Get(out,nrun);
   if (!entry) { 
     AliFatal("Exiting, no CDB object (ParOffline) found!!!");
@@ -573,14 +889,13 @@ Bool_t AliTOFcalib::ReadParOfflineFromCDB(Char_t *sel, Int_t nrun)
    
 }
 //_____________________________________________________________________________
-void AliTOFcalib::WriteSimHistoOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
+void AliTOFcalib::WriteSimHistoOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TH1F *histo){
   //Write Sim miscalibration parameters to the CDB
 
   fTOFSimToT=histo;
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "SimHisto" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "SimHisto" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBMetaData *mdhisto = new AliCDBMetaData();
   mdhisto->SetResponsible("Chiara Zampolli");
   AliCDBId id(out,minrun,maxrun);
@@ -588,16 +903,15 @@ void AliTOFcalib::WriteSimHistoOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, TH
   delete mdhisto;
 }
 //_____________________________________________________________________________
-Bool_t AliTOFcalib::ReadSimHistoFromCDB(Char_t *sel, Int_t nrun)
+Bool_t AliTOFcalib::ReadSimHistoFromCDB(const Char_t *sel, Int_t nrun)
 {
   //Read miscalibration parameters from the CDB
   AliCDBManager *man = AliCDBManager::Instance();
 
   // The Tot Histo
 
-  Char_t *sel1 = "SimHisto" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "SimHisto" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBEntry *entry = man->Get(out,nrun);
   if (!entry) { 
     AliFatal("Exiting, no CDB object (SimHisto) found!!!");
@@ -612,39 +926,58 @@ Bool_t AliTOFcalib::ReadSimHistoFromCDB(Char_t *sel, Int_t nrun)
   return kTRUE;
 }
 //_____________________________________________________________________________
-void AliTOFcalib::WriteRecParOnCDB(Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
+void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, AliTOFRecoParam *param){
   //Write reconstruction parameters to the CDB
 
   AliCDBManager *man = AliCDBManager::Instance();
   AliCDBMetaData *md = new AliCDBMetaData();
   md->SetResponsible("Silvia Arcelli");
-  Char_t *sel1 = "RecPar" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "RecoParam" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBId id(out,minrun,maxrun);
-  man->Put(param,id,md);
+
+  TObjArray *arr=new TObjArray(1);
+  arr->AddLast(param);
+  man->Put(arr,id,md);
+  //man->Put(param,id,md);
   delete md;
 }
 //_____________________________________________________________________________
-AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(Char_t *sel, Int_t nrun)
+void AliTOFcalib::WriteRecParOnCDB(const Char_t *sel, Int_t minrun, Int_t maxrun, TObjArray *arr){
+  //Write reconstruction parameters to the CDB
+
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Silvia Arcelli");
+  const Char_t *sel1 = "RecoParam" ;
+  TString out(Form("%s/%s",sel,sel1));
+  AliCDBId id(out,minrun,maxrun);
+  man->Put(arr,id,md);
+  delete md;
+}
+//_____________________________________________________________________________
+AliTOFRecoParam * AliTOFcalib::ReadRecParFromCDB(const Char_t *sel, Int_t nrun, Int_t eventType)
 {
   //Read reconstruction parameters from the CDB
   AliCDBManager *man = AliCDBManager::Instance();
-  Char_t *sel1 = "RecPar" ;
-  Char_t  out[100];
-  sprintf(out,"%s/%s",sel,sel1); 
+  const Char_t *sel1 = "RecoParam" ;
+  TString out(Form("%s/%s",sel,sel1));
   AliCDBEntry *entry = man->Get(out,nrun);
   if (!entry) { 
-    AliFatal("Exiting, no CDB object (RecPar) found!!!");
+    AliFatal("Exiting, no CDB object (RecoParam) found!!!");
     exit(0);  
   }  
   if(!entry->GetObject()){
-    AliFatal("Exiting, no CDB object (RecPar) found!!!");
+    AliFatal("Exiting, no CDB object (RecoParam) found!!!");
     exit(0);  
   }  
 
-  AliTOFRecoParam *param=(AliTOFRecoParam*)entry->GetObject();
+  TObjArray *array = (TObjArray*)entry->GetObject();
+  AliTOFRecoParam *param=0x0;
+  if (eventType>=0 || eventType<array->GetEntries())
+    param=(AliTOFRecoParam*)array->At(eventType);
   return param;
+
 }
 //-----------------------------------------------------------------------------
 // Calibration methods
@@ -661,19 +994,17 @@ void AliTOFcalib::CreateTreeFromCDB(Int_t minrun, Int_t maxrun){
   fTree->Branch("nentries",&nentries,"nentries/I");
   fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
   AliCDBManager *man = AliCDBManager::Instance();
-  AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT");
+  AliCDBStorage *aStorage = man->GetStorage("local://$ALICE_ROOT/OCDB");
   for (Int_t irun = minrun;irun<=maxrun;irun++){
     AliCDBEntry *entry = aStorage->Get("TOF/RefData/TreeForCalib",irun);
     if (!entry){
       AliInfo(Form("No entry found for run %i",irun));
     }
     else{
-      TTree *tree = new TTree();
-      tree = (TTree*)entry->GetObject();
+      TTree *tree = (TTree*)entry->GetObject();
       tree->SetBranchAddress("nentries",&nentries);
       tree->SetBranchAddress("TOFentries",p);      
       fTree->CopyEntries(tree);
-      delete tree;
       fNruns++;
     }
   }
@@ -695,10 +1026,10 @@ void AliTOFcalib::CreateTreeFromGrid(Int_t minrun, Int_t maxrun){
   AliInfo("connected to alien");
   TGrid::Connect("alien://");
   
-  Char_t filename[100];
+  TString filename;
   for (Int_t irun = minrun;irun<=maxrun;irun++){
-    sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
-    TFile *filegrid = TFile::Open(filename,"READ");
+    filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
+    TFile *filegrid = TFile::Open(filename.Data(),"READ");
     TTree *tree = (TTree*)filegrid->Get("T");
     tree->SetBranchAddress("nentries",&nentries);
     tree->SetBranchAddress("TOFentries",p);      
@@ -722,10 +1053,10 @@ void AliTOFcalib::CreateTreeFromFile(Int_t minrun, Int_t maxrun){
   fTree->SetDirectory(0);
   fTree->Branch("nentries",&nentries,"nentries/I");
   fTree->Branch("TOFentries",p,"TOFentries[nentries]/F");
-  Char_t filename[100];
+  TString filename;
   for (Int_t irun = minrun;irun<=maxrun;irun++){
-    sprintf(filename,"$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
-    TFile *file = new TFile(filename,"READ");
+    filename = Form("$ALICE_ROOT/TOF/RefData/TreeForCalib/fileout_%i.root",irun);
+    TFile *file = new TFile(filename.Data(),"READ");
     TTree *tree = (TTree*)file->Get("T");
     tree->SetBranchAddress("nentries",&nentries);
     tree->SetBranchAddress("TOFentries",p);      
@@ -749,10 +1080,10 @@ void AliTOFcalib::CreateChainFromGrid(Int_t minrun, Int_t maxrun){
   AliInfo("connected to alien");
   TGrid::Connect("alien://");
   
-  Char_t filename[100];
+  TString filename;
   for (Int_t irun = minrun;irun<=maxrun;irun++){
-    sprintf(filename,"alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
-    fChain->Add(filename);
+    filename = Form("alien:///alice/cern.ch/user/c/czampolli/TOFCalibReference_%i.root",irun);
+    fChain->Add(filename.Data());
     fNruns++;    
   }
   
@@ -834,7 +1165,9 @@ Int_t AliTOFcalib::Calibrate(Int_t ichmin, Int_t ichmax, Option_t *optionSave, O
     }
   }
   nusefulbins = FindBins(hToT,&binsProfile[0]);
-  meantime/=ntracksTotal;
+  if (ntracksTotal != 0){
+         meantime/=ntracksTotal;
+  }
   AliDebug(2, Form("meantime = %f",meantime));
   
   for (Int_t j=1;j<=nusefulbins;j++) {
@@ -1110,7 +1443,7 @@ Int_t AliTOFcalib::Calibrate(Int_t nch, Int_t *ch, Option_t *optionSave, Option_
       ntracksTotal+=nentries/3;
     }
     if (ntracksTotal < MEANENTRIES) {
-      AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",i,ntracksTotal));
+      AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",i,ntracksTotal));
       continue;
     }
   
@@ -1226,12 +1559,11 @@ Int_t AliTOFcalib::CalibrateFromProfile(Int_t ich, Option_t *optionSave, Option_
   }
 
   if (ntracksTotal < MEANENTRIES) {  
-    AliInfo(Form(" Too small mean number of entires per channel (mean number = %f) not calibrating and exiting.....",ntracksTotal));
+    AliInfo(Form(" Too small mean number of entires per channel (mean number = %d) not calibrating and exiting.....",ntracksTotal));
     return 2;
   }
 
-  TH1F * hProf = new TH1F();
-  hProf = Profile(ich);
+  TH1F * hProf = Profile(ich);
   hProf->Fit("pol5",optionFit,"",0,4);
   TF1 * calibfunc = (TF1*)hProf->GetFunction("pol5");
   Float_t par[6];    
@@ -1325,7 +1657,7 @@ Int_t AliTOFcalib::Calibrate(Option_t *optionSave, Option_t *optionFit){
       ntracksTotal+=nentries/3;
     }
     if (ntracksTotal < MEANENTRIES) {
-      AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %f), not calibrating channel and continuing.....",ii,ntracksTotal));
+      AliInfo(Form(" Too small mean number of entires in channel %i (number of tracks = %d), not calibrating channel and continuing.....",ii,ntracksTotal));
       continue;
     }
     Float_t meantime=0;
@@ -1427,9 +1759,9 @@ TH1F* AliTOFcalib::Profile(Int_t ich)
   Float_t minToT = 0; //ns
   Float_t maxToT = 5.; //ns
   Float_t deltaToT = (maxToT-minToT)/knbinToT;
-  Double_t mTime[knbinToT+1],mToT[knbinToT+1],meanTime[knbinToT+1], meanTime2[knbinToT+1],vToT[knbinToT+1], vToT2[knbinToT+1],meanToT[knbinToT+1],meanToT2[knbinToT+1],vTime[knbinToT+1],vTime2[knbinToT+1],xlow[knbinToT+1],sigmaTime[knbinToT+1];
+  Double_t mTime[knbinToT+1],mToT[knbinToT+1],meanTime[knbinToT+1], meanTime2[knbinToT+1],vToT[knbinToT+1], vToT2[knbinToT+1],meanToT[knbinToT+1],meanToT2[knbinToT+1],vTime[knbinToT+1],vTime2[knbinToT+1],sigmaTime[knbinToT+1];
   Int_t n[knbinToT+1], nentrx[knbinToT+1];
-  Double_t sigmaToT[knbinToT+1];
+  //Double_t xlow[knbinToT+1],sigmaToT[knbinToT+1];  // not used for the time being
   for (Int_t i = 0; i < knbinToT+1 ; i++){
     mTime[i]=0;
     mToT[i]=0;
@@ -1442,9 +1774,9 @@ TH1F* AliTOFcalib::Profile(Int_t ich)
     meanToT2[i]=0;
     vTime[i]=0;
     vTime2[i]=0;
-    xlow[i]=0;
+    //xlow[i]=0;
     sigmaTime[i]=0;
-    sigmaToT[i]=0;
+    //sigmaToT[i]=0;
     n[i]=0;
     nentrx[i]=0;
   }
@@ -1500,12 +1832,12 @@ TH1F* AliTOFcalib::Profile(Int_t ich)
           *(meanToT2[usefulBins]-meanToT[usefulBins]
             *meanToT[usefulBins]/n[usefulBins]))< 0) {
        AliError(" too small radical" );
-       sigmaToT[usefulBins]=0;
+       //sigmaToT[usefulBins]=0;
       }
       else{       
-       sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
-                            *(meanToT2[usefulBins]-meanToT[usefulBins]
-                            *meanToT[usefulBins]/n[usefulBins]));
+       //sigmaToT[usefulBins]=TMath::Sqrt(1./n[usefulBins]/n[usefulBins]
+       //                   *(meanToT2[usefulBins]-meanToT[usefulBins]
+       //                   *meanToT[usefulBins]/n[usefulBins]));
       }
       usefulBins++;
     }
@@ -1561,3 +1893,721 @@ Int_t AliTOFcalib::FindBins(TH1F* h, Double_t *binsProfile) const{
   }
   return nusefulbins;
 }
+
+
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::CreateDeltaBCOffset()
+{
+  /*
+   * create deltaBC offset
+   */
+
+  if (fDeltaBCOffset) {
+    AliWarning("DeltaBCOffset object already defined, cannot create a new one");
+    return;
+  }
+  fDeltaBCOffset = new AliTOFDeltaBCOffset();
+}
+  
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::CreateCTPLatency()
+{
+  /*
+   * create CTP latency
+   */
+
+  if (fCTPLatency) {
+    AliWarning("CTPLatency object already defined, cannot create a new one");
+    return;
+  }
+  fCTPLatency = new AliTOFCTPLatency();
+}
+  
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::CreateT0Fill()
+{
+  /*
+   * create event-time
+   */
+
+  if (fT0Fill) {
+    AliWarning("T0Fill object already defined, cannot create a new one");
+    return;
+  }
+  fT0Fill = new AliTOFT0Fill();
+}
+  
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::CreateRunParams()
+{
+  /*
+   * create run params
+   */
+
+  if (fRunParams) {
+    AliWarning("RunParams object already defined, cannot create a new one");
+    return;
+  }
+  fRunParams = new AliTOFRunParams();
+}
+  
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::WriteDeltaBCOffsetOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
+{
+  /*
+   * deltaBC offset on CDB 
+   */
+  
+  if (!fDeltaBCOffset) return;
+  AliCDBId id(Form("%s/DeltaBCOffset", sel), minrun, maxrun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Roberto Preghenella");
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->Put(fDeltaBCOffset, id, md);
+  AliDebug(2,Form("DeltaBCOffset written on CDB with run range [%i, %i] ",minrun ,maxrun));
+  delete md;
+}
+
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::WriteCTPLatencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
+{
+  /*
+   * write CTP latency on CDB 
+   */
+  
+  if (!fCTPLatency) return;
+  AliCDBId id(Form("%s/CTPLatency", sel), minrun, maxrun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Roberto Preghenella");
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->Put(fCTPLatency, id, md);
+  AliDebug(2,Form("CTPLatency written on CDB with run range [%i, %i] ",minrun ,maxrun));
+  delete md;
+}
+
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::WriteT0FillOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
+{
+  /*
+   * write event-time on CDB 
+   */
+  
+  if (!fT0Fill) return;
+  AliCDBId id(Form("%s/T0Fill", sel), minrun, maxrun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Roberto Preghenella");
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->Put(fT0Fill, id, md);
+  AliDebug(2,Form("T0Fill written on CDB with run range [%i, %i] ",minrun ,maxrun));
+  delete md;
+}
+
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::WriteRunParamsOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
+{
+  /*
+   * write run params on CDB 
+   */
+  
+  if (!fRunParams) return;
+  AliCDBId id(Form("%s/RunParams", sel), minrun, maxrun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Roberto Preghenella");
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->Put(fRunParams, id, md);
+  AliDebug(2,Form("RunParams written on CDB with run range [%i, %i] ",minrun ,maxrun));
+  delete md;
+}
+
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::WriteReadoutEfficiencyOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
+{
+  /*
+   * write readout efficiency on CDB 
+   */
+  
+  if (!fReadoutEfficiency) return;
+  AliCDBId id(Form("%s/ReadoutEfficiency", sel), minrun, maxrun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Roberto Preghenella");
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->Put(fReadoutEfficiency, id, md);
+  AliDebug(2,Form("ReadoutEfficiency written on CDB with run range [%i, %i] ",minrun ,maxrun));
+  delete md;
+}
+
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::WriteProblematicOnCDB(const Char_t *sel , Int_t minrun, Int_t maxrun)
+{
+  /*
+   * write problematic on CDB 
+   */
+  
+  if (!fProblematic) return;
+  AliCDBId id(Form("%s/Problematic", sel), minrun, maxrun);
+  AliCDBMetaData *md = new AliCDBMetaData();
+  md->SetResponsible("Roberto Preghenella");
+  AliCDBManager *man = AliCDBManager::Instance();
+  man->Put(fProblematic, id, md);
+  AliDebug(2,Form("Problematic written on CDB with run range [%i, %i] ",minrun ,maxrun));
+  delete md;
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::ReadDeltaBCOffsetFromCDB(const Char_t *sel , Int_t nrun)
+{
+  /*
+   * read deltaBC offset from CDB
+   */
+  
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBEntry *entry = man->Get(Form("%s/DeltaBCOffset", sel),nrun);
+  if (!entry) { 
+    AliFatal("No DeltaBCOffset entry found in CDB");
+    exit(0);  
+  }
+  fDeltaBCOffset =(AliTOFDeltaBCOffset *)entry->GetObject();
+  if(!fDeltaBCOffset){
+    AliFatal("No DeltaBCOffset object found in CDB entry");
+    exit(0);  
+  }  
+  return kTRUE; 
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::ReadCTPLatencyFromCDB(const Char_t *sel , Int_t nrun)
+{
+  /*
+   * read CTP latency from CDB
+   */
+  
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBEntry *entry = man->Get(Form("%s/CTPLatency", sel),nrun);
+  if (!entry) { 
+    AliFatal("No CTPLatency entry found in CDB");
+    exit(0);  
+  }
+  fCTPLatency =(AliTOFCTPLatency *)entry->GetObject();
+  if(!fCTPLatency){
+    AliFatal("No CTPLatency object found in CDB entry");
+    exit(0);  
+  }  
+  return kTRUE; 
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::ReadT0FillFromCDB(const Char_t *sel , Int_t nrun)
+{
+  /*
+   * read event-time from CDB
+   */
+  
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBEntry *entry = man->Get(Form("%s/T0Fill", sel),nrun);
+  if (!entry) { 
+    AliFatal("No T0Fill entry found in CDB");
+    exit(0);  
+  }
+  fT0Fill =(AliTOFT0Fill *)entry->GetObject();
+  if(!fT0Fill){
+    AliFatal("No T0Fill object found in CDB entry");
+    exit(0);  
+  }  
+  return kTRUE; 
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::ReadRunParamsFromCDB(const Char_t *sel , Int_t nrun)
+{
+  /*
+   * read run params from CDB
+   */
+  
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBEntry *entry = man->Get(Form("%s/RunParams", sel),nrun, fRunParamsSpecificVersion);
+  if (!entry) { 
+    AliFatal("No RunParams entry found in CDB");
+    exit(0);  
+  }
+  fRunParams =(AliTOFRunParams *)entry->GetObject();
+  if(!fRunParams){
+    AliFatal("No RunParams object found in CDB entry");
+    exit(0);  
+  }  
+  return kTRUE; 
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::ReadLHCClockPhaseFromCDB(const Char_t *sel , Int_t nrun)
+{
+  /*
+   * read LHC clock-phase from CDB
+   */
+  
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBEntry *entry = man->Get(Form("%s/LHCClockPhase", sel),nrun);
+  if (!entry) { 
+    AliFatal("No LHCClockPhase entry found in CDB");
+    exit(0);  
+  }
+  fLHCClockPhase =(AliLHCClockPhase *)entry->GetObject();
+  if(!fRunParams){
+    AliFatal("No LHCClockPhase object found in CDB entry");
+    exit(0);  
+  }  
+  return kTRUE; 
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::ReadReadoutEfficiencyFromCDB(const Char_t *sel , Int_t nrun)
+{
+  /*
+   * read readout efficiency from CDB
+   */
+  
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBEntry *entry = man->Get(Form("%s/ReadoutEfficiency", sel),nrun);
+  if (!entry) { 
+    AliFatal("No ReadoutEfficiency entry found in CDB");
+    exit(0);  
+  }
+  fReadoutEfficiency = (TH1F *)entry->GetObject();
+  if(!fReadoutEfficiency){
+    AliFatal("No ReadoutEfficiency object found in CDB entry");
+    exit(0);  
+  }  
+  return kTRUE; 
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::ReadProblematicFromCDB(const Char_t *sel , Int_t nrun)
+{
+  /*
+   * read problematic from CDB
+   */
+  
+  AliCDBManager *man = AliCDBManager::Instance();
+  AliCDBEntry *entry = man->Get(Form("%s/Problematic", sel),nrun);
+  if (!entry) { 
+    AliFatal("No Problematic entry found in CDB");
+    exit(0);  
+  }
+  fProblematic = (TH1C *)entry->GetObject();
+  if(!fProblematic){
+    AliFatal("No Problematic object found in CDB entry");
+    exit(0);  
+  }  
+  return kTRUE; 
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t 
+AliTOFcalib::Init(Int_t run)
+{
+  /*
+   * init
+   */
+
+  if (fInitFlag) {
+    AliWarning("the class was already initialized, re-initialize it");
+    fInitFlag = kFALSE;
+  }
+  
+  /* read channel status array */
+  if (!ReadParOnlineStatusFromCDB("TOF/Calib", run)) {
+    AliError("cannot get \"Status\" object from OCDB");
+    return kFALSE;
+  }
+  /* get par offline array */
+  if (!ReadParOfflineFromCDB("TOF/Calib", run)) {
+    AliError("cannot get \"ParOffline\" object from OCDB");
+    return kFALSE;
+  }
+  /* get deltaBC offset obj */
+  if (!ReadDeltaBCOffsetFromCDB("TOF/Calib", run)) {
+    AliError("cannot get \"DeltaBCOffset\" object from OCDB");
+    return kFALSE;
+  }
+  /* get CTP latency obj */
+  if (!ReadCTPLatencyFromCDB("TOF/Calib", run)) {
+    AliError("cannot get \"CTPLatency\" object from OCDB");
+    return kFALSE;
+  }
+  /* get run params obj */
+  if (!ReadRunParamsFromCDB("TOF/Calib", run)) {
+    AliError("cannot get \"RunParams\" object from OCDB");
+    return kFALSE;
+  }
+  /* get LHC clock-phase obj */
+  if (!ReadLHCClockPhaseFromCDB("GRP/Calib", run)) {
+    AliError("cannot get \"LHCClockPhase\" object from OCDB");
+    return kFALSE;
+  }
+  /* get readout efficiency obj */
+  if (!ReadReadoutEfficiencyFromCDB("TOF/Calib", run)) {
+    AliError("cannot get \"ReadoutEfficiency\" object from OCDB");
+    return kFALSE;
+  }
+  /* get readout efficiency obj */
+  if (!ReadProblematicFromCDB("TOF/Calib", run)) {
+    AliError("cannot get \"Problematic\" object from OCDB");
+    return kFALSE;
+  }
+  /* get response params */
+  TFile *responseFile = TFile::Open("$ALICE_ROOT/TOF/data/AliTOFresponsePar.root");
+  if (!responseFile || !responseFile->IsOpen()) {
+    AliError("cannot open \"ResponseParams\" local file");
+    return kFALSE;
+  }
+  fResponseParams = (AliTOFResponseParams *)responseFile->Get("ResponseParams");
+  if (!fResponseParams) {
+    AliError("cannot get \"ResponseParams\" object from local file");
+    return kFALSE;
+  }
+  responseFile->Close();
+
+  /* check whether to use the clock phase */
+  if (fRunParams->GetUseLHCClockPhase())
+    fUseLHCClockPhase = kTRUE;
+  if (fUseLHCClockPhase)
+    AliInfo("calibration using BPTX LHC clock-phase");
+
+  /* all done */
+  fInitFlag = kTRUE;
+  return kTRUE;
+
+}
+
+//----------------------------------------------------------------------------
+
+Double_t
+AliTOFcalib::GetTimeCorrection(Int_t index, Double_t tot, Int_t deltaBC, Int_t l0l1, UInt_t timestamp)
+{
+  /*
+   * get time correction
+   */
+
+  if (!fInitFlag) {
+    AliError("class not yet initialized. Initialize it before.");
+    return 0.;
+  }
+
+  /* deal with L0-L1 orbit crossing (negative values) */
+  if (l0l1 < 0) l0l1 += 3564;
+
+  /* get calibration params */
+  AliTOFChannelOffline *parOffline = (AliTOFChannelOffline *)fTOFCalOffline->At(index);
+  Int_t deltaBCOffset = fDeltaBCOffset->GetDeltaBCOffset();
+  Float_t ctpLatency = fCTPLatency->GetCTPLatency();
+  Float_t tdcLatencyWindow = fStatus->GetLatencyWindow(index) * 1.e3;
+  Float_t timezero = fRunParams->EvalT0(timestamp);
+  Float_t clockphase = fLHCClockPhase->GetPhase(timestamp);
+  /* check whether to remove mean T0.
+   * useful when one wants to compute mean T0 */
+  if (!fRemoveMeanT0) timezero = 0.;
+  /* check whether to use the clock phase */
+  if (fUseLHCClockPhase) timezero -= 1.e3 * clockphase;
+
+  /* compute correction */
+  Double_t corr = 0.;
+  /* deltaBC correction */
+  deltaBC = deltaBCOffset; /* inhibit deltaBC correction for the time being */
+  corr += (deltaBC - deltaBCOffset) * AliTOFGeometry::BunchCrossingBinWidth();
+  /* L0-L1 latency correction */
+  corr -= l0l1 * AliTOFGeometry::BunchCrossingBinWidth();
+  /* CTP latency correction */
+  corr -= ctpLatency;
+  /* TDC latency window correction */
+  corr += tdcLatencyWindow;
+  /* time-zero correction */
+  corr += timezero;
+  /* time calibration correction */
+  if (tot < AliTOFGeometry::SlewTOTMin()) 
+    tot = AliTOFGeometry::SlewTOTMin();
+  if (tot > AliTOFGeometry::SlewTOTMax()) 
+    tot = AliTOFGeometry::SlewTOTMax();
+  for (Int_t islew = 0; islew < 6; islew++)
+    corr += parOffline->GetSlewPar(islew) * TMath::Power(tot, islew) * 1.e3;
+
+  /* return correction */
+  return corr;
+}
+
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::CalibrateESD(AliESDEvent *event)
+{
+  /*
+   * calibrate ESD
+   */
+
+  if (!fInitFlag) {
+    AliError("class not yet initialized. Initialize it before.");
+    return;
+  }
+
+  Int_t index, l0l1, deltaBC;
+  Double_t time, tot, corr;
+  UInt_t timestamp = event->GetTimeStamp();
+
+  // calibrating TOF hits
+
+  AliESDTOFHit* hit = NULL;
+  AliESDtrack* track = NULL;
+  TClonesArray* esdTOFhits = event->GetESDTOFHits();
+  if (esdTOFhits) { // new TOF data structure
+    for (Int_t ihit = 0; ihit < esdTOFhits->GetEntriesFast(); ihit++) {
+      
+      /* get track */
+      hit = (AliESDTOFHit*)esdTOFhits->At(ihit);
+      //if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
+      if (!hit) continue;
+      
+      /* calibrate TOF signal */
+      if (fCalibrateTOFsignal) {
+       /* get info */
+       index = hit->GetTOFchannel();
+       time = hit->GetTimeRaw();
+       tot = hit->GetTOT();
+       l0l1 = hit->GetL0L1Latency();
+       deltaBC = hit->GetDeltaBC();
+       /* get correction */
+       corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
+       /* apply correction */
+       time -= corr;
+       /* set new TOF signal */
+       hit->SetTime(time);
+      }
+      
+    }
+  }
+  else { // old TOF data structure
+
+    for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
+   
+      /* get track */
+      track = event->GetTrack(itrk);
+      if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
+      
+      /* calibrate TOF signal */
+      if (fCalibrateTOFsignal) {
+       /* get info */
+       index = track->GetTOFCalChannel();
+       time = track->GetTOFsignalRaw();
+       tot = track->GetTOFsignalToT();
+       l0l1 = track->GetTOFL0L1();
+       deltaBC = track->GetTOFDeltaBC();
+       /* get correction */
+       corr = GetTimeCorrection(index, tot, deltaBC, l0l1, timestamp);
+       /* apply correction */
+       time -= corr;
+       /* set new TOF signal */
+       track->SetTOFsignal(time);
+      }
+    }
+    
+    if (fCorrectTExp) 
+      CalibrateTExp(event);
+  }
+  
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::IsChannelEnabled(Int_t index, Bool_t checkEfficiency, Bool_t checkProblematic)
+{
+  /*
+   * is channel enabled
+   */
+
+  if (!fInitFlag) {
+    AliError("class not yet initialized. Initialize it before.");
+    return kTRUE;
+  }
+
+  /* check bad status */
+  if (fStatus->GetPulserStatus(index) == AliTOFChannelOnlineStatusArray::kTOFPulserBad) return kFALSE;
+  if (fStatus->GetNoiseStatus(index) == AliTOFChannelOnlineStatusArray::kTOFNoiseBad) return kFALSE;
+  if (fStatus->GetHWStatus(index) == AliTOFChannelOnlineStatusArray::kTOFHWBad) return kFALSE;
+  if (checkEfficiency && !IsChannelEfficient(index)) return kFALSE;
+  if (checkProblematic && IsChannelProblematic(index)) return kFALSE;
+  
+  /* good status */
+  return kTRUE;
+
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::IsChannelEfficient(Int_t index)
+{
+  /*
+   * is channel efficient
+   */
+
+  if (!fInitFlag) {
+    AliError("class not yet initialized. Initialize it before.");
+    return kTRUE;
+  }
+
+  /* check efficiency */
+  if (fReadoutEfficiency->GetBinContent(index + 1) < 0.95) return kFALSE;
+  return kTRUE;
+
+}
+
+//----------------------------------------------------------------------------
+
+Bool_t
+AliTOFcalib::IsChannelProblematic(Int_t index)
+{
+  /*
+   * is channel problematic
+   */
+
+  if (!fInitFlag) {
+    AliError("class not yet initialized. Initialize it before.");
+    return kTRUE;
+  }
+
+  /* check problematic */
+  if (fProblematic->GetBinContent(index + 1) != 0) return kTRUE;
+  return kFALSE;
+
+}
+
+//----------------------------------------------------------------------------
+
+void
+AliTOFcalib::CalibrateTExp(AliESDEvent *event) const
+{
+  /*
+   * calibrate TExp
+   */
+
+  /* check if new TOF data structure, crash in case */
+  TClonesArray* esdTOFhits = event->GetESDTOFHits();
+  if (esdTOFhits) { 
+    AliFatal("This method is DEPRECATED, doing NOTHING");
+    return ;
+  }
+
+  if (!fInitFlag) {
+    AliError("class not yet initialized. Initialize it before.");
+    return;
+  }
+
+  /* loop over tracks */
+  AliESDtrack *track = NULL;
+  Double_t texp[AliPID::kSPECIESC];
+  for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
+
+    /* get track */
+    track = event->GetTrack(itrk);
+    if (!track || !(track->GetStatus() & AliESDtrack::kTOFout)) continue;
+
+    /* get integrated times */
+    track->GetIntegratedTimes(texp,AliPID::kSPECIESC);
+    /* loop over particle types and correct expected time */
+    for (Int_t ipart = 0; ipart < AliPID::kSPECIES; ipart++)
+      texp[ipart] += fResponseParams->EvalTExpCorr(ipart, track->P());
+    /* set integrated times */
+    track->SetIntegratedTimes(texp);
+
+  }
+
+}
+
+//----------------------------------------------------------------------------
+
+Double_t
+AliTOFcalib::TuneForMC(AliESDEvent *event, Double_t resolution)
+{
+  /*
+   * tune for MC
+   */
+
+  /* check if new TOF data structure, crash in case */
+  TClonesArray* esdTOFhits = event->GetESDTOFHits();
+  if (esdTOFhits) { 
+    AliFatal("This method is DEPRECATED, doing NOTHING");
+    return 0.;
+  }
+
+  /* get vertex spread and define T0-spread */
+  Double_t diamond2 = TMath::Abs(event->GetSigma2DiamondZ());
+  Double_t t0spread = TMath::Sqrt(diamond2) / 2.99792457999999984e-02;
+  /* generate random startTime */
+  Double_t startTime = gRandom->Gaus(0., t0spread);
+  /* define extra smearing for resolution */
+  Double_t defaultResolution = 80.;
+  Double_t extraSmearing = 0.;
+  if (resolution > defaultResolution)
+    extraSmearing = TMath::Sqrt(resolution * resolution - defaultResolution * defaultResolution);
+
+  /* loop over tracks */
+  AliESDtrack *track = NULL;
+  Double_t time;
+  for (Int_t itrk = 0; itrk < event->GetNumberOfTracks(); itrk++) {
+    /* get track */
+    track = event->GetTrack(itrk);
+    if (!track) continue;
+    /* check TOF match */
+    if (!track->IsOn(AliESDtrack::kTOFout)) continue;
+    /* check if channel is enabled */
+    if (!IsChannelEnabled(track->GetTOFCalChannel())) {
+      /* reset TOF status */
+      track->ResetStatus(AliESDtrack::kTOFin);
+      track->ResetStatus(AliESDtrack::kTOFout);
+      track->ResetStatus(AliESDtrack::kTOFmismatch);
+      track->ResetStatus(AliESDtrack::kTOFpid);
+    }
+    /* get original time and manipulate it */
+    time = track->GetTOFsignal();
+    time += startTime; /* add start time */
+    time += gRandom->Gaus(0., extraSmearing); /* extra smearing */
+    time -= 25.; /* remove 25 ps to center the signal */
+    track->SetTOFsignal(time);
+  }
+
+  return startTime;
+}