]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCCalibCE.cxx
AliTPCCalibCE.cxx.diff Add ctor with configuration options; Bug fixes
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibCE.cxx
index 6e1c4c81f36e433839f43b9d07e805ae3e045653..269a41de6e5ed621c815e87dcb952f306a23d924 100644 (file)
@@ -269,7 +269,7 @@ END_HTML */
 #include <TMath.h>
 #include <TGraph.h>
 #include <TString.h>
-
+#include <TMap.h>
 #include <TDirectory.h>
 #include <TSystem.h>
 #include <TFile.h>
@@ -362,6 +362,7 @@ AliTPCCalibCE::AliTPCCalibCE() :
     fVTime0OffsetCounter(72),
     fVMeanQ(72),
     fVMeanQCounter(72),
+    fCurrentCETimeRef(0),
 //    fEvent(-1),
     fDebugStreamer(0x0),
     fDebugLevel(0)
@@ -439,92 +440,189 @@ AliTPCCalibCE::AliTPCCalibCE(const AliTPCCalibCE &sig) :
     fVTime0OffsetCounter(72),
     fVMeanQ(72),
     fVMeanQCounter(72),
+    fCurrentCETimeRef(0),
 //    fEvent(-1),
     fDebugStreamer(0x0),
     fDebugLevel(sig.fDebugLevel)
 {
-    //
+  //
     // AliTPCSignal copy constructor
-    //
+  //
 
-    for (Int_t iSec = 0; iSec < 72; ++iSec){
-       const AliTPCCalROC *calQ   = (AliTPCCalROC*)sig.fCalRocArrayQ.UncheckedAt(iSec);
-       const AliTPCCalROC *calT0  = (AliTPCCalROC*)sig.fCalRocArrayT0.UncheckedAt(iSec);
-       const AliTPCCalROC *calRMS = (AliTPCCalROC*)sig.fCalRocArrayRMS.UncheckedAt(iSec);
-        const AliTPCCalROC *calOut = (AliTPCCalROC*)sig.fCalRocArrayOutliers.UncheckedAt(iSec);
+  for (Int_t iSec = 0; iSec < 72; ++iSec){
+    const AliTPCCalROC *calQ   = (AliTPCCalROC*)sig.fCalRocArrayQ.UncheckedAt(iSec);
+    const AliTPCCalROC *calT0  = (AliTPCCalROC*)sig.fCalRocArrayT0.UncheckedAt(iSec);
+    const AliTPCCalROC *calRMS = (AliTPCCalROC*)sig.fCalRocArrayRMS.UncheckedAt(iSec);
+    const AliTPCCalROC *calOut = (AliTPCCalROC*)sig.fCalRocArrayOutliers.UncheckedAt(iSec);
 
-       const TH2S *hQ   = (TH2S*)sig.fHistoQArray.UncheckedAt(iSec);
-       const TH2S *hT0  = (TH2S*)sig.fHistoT0Array.UncheckedAt(iSec);
-        const TH2S *hRMS = (TH2S*)sig.fHistoRMSArray.UncheckedAt(iSec);
+    const TH2S *hQ   = (TH2S*)sig.fHistoQArray.UncheckedAt(iSec);
+    const TH2S *hT0  = (TH2S*)sig.fHistoT0Array.UncheckedAt(iSec);
+    const TH2S *hRMS = (TH2S*)sig.fHistoRMSArray.UncheckedAt(iSec);
 
-       if ( calQ   != 0x0 ) fCalRocArrayQ.AddAt(new AliTPCCalROC(*calQ), iSec);
-       if ( calT0  != 0x0 ) fCalRocArrayT0.AddAt(new AliTPCCalROC(*calT0), iSec);
-       if ( calRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTPCCalROC(*calRMS), iSec);
-        if ( calOut != 0x0 ) fCalRocArrayOutliers.AddAt(new AliTPCCalROC(*calOut), iSec);
+    if ( calQ   != 0x0 ) fCalRocArrayQ.AddAt(new AliTPCCalROC(*calQ), iSec);
+    if ( calT0  != 0x0 ) fCalRocArrayT0.AddAt(new AliTPCCalROC(*calT0), iSec);
+    if ( calRMS != 0x0 ) fCalRocArrayRMS.AddAt(new AliTPCCalROC(*calRMS), iSec);
+    if ( calOut != 0x0 ) fCalRocArrayOutliers.AddAt(new AliTPCCalROC(*calOut), iSec);
 
-       if ( hQ != 0x0 ){
+    if ( hQ != 0x0 ){
 //         TDirectory *dir = hQ->GetDirectory();
 //         hQ->SetDirectory(0);
-           TH2S *hNew = new TH2S(*hQ);
-           hNew->SetDirectory(0);
-           fHistoQArray.AddAt(hNew,iSec);
+      TH2S *hNew = new TH2S(*hQ);
+      hNew->SetDirectory(0);
+      fHistoQArray.AddAt(hNew,iSec);
 //            hQ->SetDirectory(dir);
-       }
-       if ( hT0 != 0x0 ){
+    }
+    if ( hT0 != 0x0 ){
 //         TDirectory *dir = hT0->GetDirectory();
 //         hT0->SetDirectory(0);
-           TH2S *hNew = new TH2S(*hT0);
-           hNew->SetDirectory(0);
-           fHistoT0Array.AddAt(hNew,iSec);
+      TH2S *hNew = new TH2S(*hT0);
+      hNew->SetDirectory(0);
+      fHistoT0Array.AddAt(hNew,iSec);
 //            hT0->SetDirectory(dir);
-       }
-       if ( hRMS != 0x0 ){
+    }
+    if ( hRMS != 0x0 ){
 //         TDirectory *dir = hRMS->GetDirectory();
 //         hRMS->SetDirectory(0);
-           TH2S *hNew = new TH2S(*hRMS);
-           hNew->SetDirectory(0);
-           fHistoRMSArray.AddAt(hNew,iSec);
+      TH2S *hNew = new TH2S(*hRMS);
+      hNew->SetDirectory(0);
+      fHistoRMSArray.AddAt(hNew,iSec);
 //            hRMS->SetDirectory(dir);
-       }
     }
+  }
 
     //copy fit parameters event by event
-    TObjArray *arr=0x0;
-    for (Int_t iSec=0; iSec<72; ++iSec){
-       arr = (TObjArray*)sig.fParamArrayEventPol1.UncheckedAt(iSec);
-       if ( arr ){
-            TObjArray *arrEvents = new TObjArray(arr->GetSize());
-           fParamArrayEventPol1.AddAt(arrEvents, iSec);
-           for (Int_t iEvent=0; iEvent<arr->GetSize(); ++iEvent)
-               if ( TVectorD *vec=(TVectorD*)arr->UncheckedAt(iEvent) )
-                   arrEvents->AddAt(new TVectorD(*vec),iEvent);
-       }
-
-       arr = (TObjArray*)sig.fParamArrayEventPol2.UncheckedAt(iSec);
-       if ( arr ){
-            TObjArray *arrEvents = new TObjArray(arr->GetSize());
-           fParamArrayEventPol2.AddAt(arrEvents, iSec);
-           for (Int_t iEvent=0; iEvent<arr->GetSize(); ++iEvent)
-               if ( TVectorD *vec=(TVectorD*)arr->UncheckedAt(iEvent) )
-                   arrEvents->AddAt(new TVectorD(*vec),iEvent);
-       }
+  TObjArray *arr=0x0;
+  for (Int_t iSec=0; iSec<72; ++iSec){
+    arr = (TObjArray*)sig.fParamArrayEventPol1.UncheckedAt(iSec);
+    if ( arr ){
+      TObjArray *arrEvents = new TObjArray(arr->GetSize());
+      fParamArrayEventPol1.AddAt(arrEvents, iSec);
+      for (Int_t iEvent=0; iEvent<arr->GetSize(); ++iEvent)
+        if ( TVectorD *vec=(TVectorD*)arr->UncheckedAt(iEvent) )
+          arrEvents->AddAt(new TVectorD(*vec),iEvent);
+    }
 
-       TVectorF *vMeanTime = (TVectorF*)sig.fTMeanArrayEvent.UncheckedAt(iSec);
-       TVectorF *vMeanQ    = (TVectorF*)sig.fQMeanArrayEvent.UncheckedAt(iSec);
-       if ( vMeanTime )
-           fTMeanArrayEvent.AddAt(new TVectorF(*vMeanTime), iSec);
-       if ( vMeanQ )
-           fQMeanArrayEvent.AddAt(new TVectorF(*vMeanQ), iSec);
+    arr = (TObjArray*)sig.fParamArrayEventPol2.UncheckedAt(iSec);
+    if ( arr ){
+      TObjArray *arrEvents = new TObjArray(arr->GetSize());
+      fParamArrayEventPol2.AddAt(arrEvents, iSec);
+      for (Int_t iEvent=0; iEvent<arr->GetSize(); ++iEvent)
+        if ( TVectorD *vec=(TVectorD*)arr->UncheckedAt(iEvent) )
+          arrEvents->AddAt(new TVectorD(*vec),iEvent);
     }
 
+    TVectorF *vMeanTime = (TVectorF*)sig.fTMeanArrayEvent.UncheckedAt(iSec);
+    TVectorF *vMeanQ    = (TVectorF*)sig.fQMeanArrayEvent.UncheckedAt(iSec);
+    if ( vMeanTime )
+      fTMeanArrayEvent.AddAt(new TVectorF(*vMeanTime), iSec);
+    if ( vMeanQ )
+      fQMeanArrayEvent.AddAt(new TVectorF(*vMeanQ), iSec);
+  }
 
-    fVEventTime.ResizeTo(sig.fVEventTime);
-    fVEventNumber.ResizeTo(sig.fVEventNumber);
-    fVEventTime.SetElements(sig.fVEventTime.GetMatrixArray());
-    fVEventNumber.SetElements(sig.fVEventNumber.GetMatrixArray());
 
-    fParam->Update();
+  fVEventTime.ResizeTo(sig.fVEventTime);
+  fVEventNumber.ResizeTo(sig.fVEventNumber);
+  fVEventTime.SetElements(sig.fVEventTime.GetMatrixArray());
+  fVEventNumber.SetElements(sig.fVEventNumber.GetMatrixArray());
+
+  fParam->Update();
 }
+//_____________________________________________________________________
+AliTPCCalibCE::AliTPCCalibCE(const TMap *config) :
+  TObject(),
+  fFirstTimeBin(650),
+  fLastTimeBin(1000),
+  fNbinsT0(200),
+  fXminT0(-5),
+  fXmaxT0(5),
+  fNbinsQ(200),
+  fXminQ(1),
+  fXmaxQ(40),
+  fNbinsRMS(100),
+  fXminRMS(0.1),
+  fXmaxRMS(5.1),
+  fPeakMinus(2),
+  fPeakPlus(3),
+  fNoiseThresholdMax(5.),
+  fNoiseThresholdSum(8.),
+  fIsZeroSuppressed(kFALSE),
+  fLastSector(-1),
+  fSecRejectRatio(.4),
+  fROC(AliTPCROC::Instance()),
+  fMapping(NULL),
+  fParam(new  AliTPCParam),
+  fPedestalTPC(0x0),
+  fPadNoiseTPC(0x0),
+  fPedestalROC(0x0),
+  fPadNoiseROC(0x0),
+  fCalRocArrayT0(72),
+  fCalRocArrayT0Err(72),
+  fCalRocArrayQ(72),
+  fCalRocArrayRMS(72),
+  fCalRocArrayOutliers(72),
+  fHistoQArray(72),
+  fHistoT0Array(72),
+  fHistoRMSArray(72),
+  fMeanT0rms(0),
+  fMeanQrms(0),
+  fMeanRMSrms(0),
+  fHistoTmean(72),
+  fParamArrayEventPol1(72),
+  fParamArrayEventPol2(72),
+  fTMeanArrayEvent(72),
+  fQMeanArrayEvent(72),
+  fVEventTime(10),
+  fVEventNumber(10),
+  fNevents(0),
+  fTimeStamp(0),
+  fEventId(-1),
+  fRunNumber(-1),
+  fOldRunNumber(-1),
+  fPadTimesArrayEvent(72),
+  fPadQArrayEvent(72),
+  fPadRMSArrayEvent(72),
+  fPadPedestalArrayEvent(72),
+  fCurrentChannel(-1),
+  fCurrentSector(-1),
+  fCurrentRow(-1),
+  fMaxPadSignal(-1),
+  fMaxTimeBin(-1),
+  fPadSignal(1024),
+  fPadPedestal(0),
+  fPadNoise(0),
+  fVTime0Offset(72),
+  fVTime0OffsetCounter(72),
+  fVMeanQ(72),
+  fVMeanQCounter(72),
+  fCurrentCETimeRef(0),
+  //  fEvent(-1),
+  fDebugStreamer(0x0),
+  fDebugLevel(0)
+{
+  //
+  // constructor which uses a tmap as input to set some specific parameters
+  //
+  if (config->GetValue("FirstTimeBin")) fFirstTimeBin = ((TObjString*)config->GetValue("FirstTimeBin"))->GetString().Atoi();
+  if (config->GetValue("LastTimeBin")) fLastTimeBin = ((TObjString*)config->GetValue("LastTimeBin"))->GetString().Atoi();
+  if (config->GetValue("NbinsT0")) fNbinsT0 = ((TObjString*)config->GetValue("NbinsT0"))->GetString().Atoi();
+  if (config->GetValue("XminT0")) fXminT0 = ((TObjString*)config->GetValue("XminT0"))->GetString().Atof();
+  if (config->GetValue("XmaxT0")) fXmaxT0 = ((TObjString*)config->GetValue("XmaxT0"))->GetString().Atof();
+  if (config->GetValue("NbinsQ")) fNbinsQ = ((TObjString*)config->GetValue("NbinsQ"))->GetString().Atoi();
+  if (config->GetValue("XminQ")) fXminQ = ((TObjString*)config->GetValue("XminQ"))->GetString().Atof();
+  if (config->GetValue("XmaxQ")) fXmaxQ = ((TObjString*)config->GetValue("XmaxQ"))->GetString().Atof();
+  if (config->GetValue("NbinsRMS")) fNbinsRMS = ((TObjString*)config->GetValue("NbinsRMS"))->GetString().Atoi();
+  if (config->GetValue("XminRMS")) fXminRMS = ((TObjString*)config->GetValue("XminRMS"))->GetString().Atof();
+  if (config->GetValue("XmaxRMS")) fXmaxRMS = ((TObjString*)config->GetValue("XmaxRMS"))->GetString().Atof();
+  if (config->GetValue("PeakMinus")) fPeakMinus = ((TObjString*)config->GetValue("PeakMinus"))->GetString().Atoi();
+  if (config->GetValue("PeakPlus")) fPeakPlus = ((TObjString*)config->GetValue("PeakPlus"))->GetString().Atoi();
+  if (config->GetValue("NoiseThresholdMax")) fNoiseThresholdMax = ((TObjString*)config->GetValue("NoiseThresholdMax"))->GetString().Atof();
+  if (config->GetValue("NoiseThresholdSum")) fNoiseThresholdSum = ((TObjString*)config->GetValue("NoiseThresholdSum"))->GetString().Atof();
+  if (config->GetValue("IsZeroSuppressed")) fIsZeroSuppressed = (Bool_t)((TObjString*)config->GetValue("IsZeroSuppressed"))->GetString().Atoi();
+  if (config->GetValue("SecRejectRatio")) fSecRejectRatio = ((TObjString*)config->GetValue("SecRejectRatio"))->GetString().Atof();
+
+  fParam->Update();
+}
+
 //_____________________________________________________________________
 AliTPCCalibCE& AliTPCCalibCE::operator = (const  AliTPCCalibCE &source)
 {
@@ -577,230 +675,252 @@ Int_t AliTPCCalibCE::Update(const Int_t icsector,
                                const Int_t icTimeBin,
                                const Float_t csignal)
 {
-    //
-    // Signal filling methode on the fly pedestal and Time offset correction if necessary.
-    // no extra analysis necessary. Assumes knowledge of the signal shape!
-    // assumes that it is looped over consecutive time bins of one pad
-    //
-
-    //temp
-//    if (icsector<36) return 0;
-//    if (icsector%36>17) return 0;
+  //
+  // Signal filling methode on the fly pedestal and Time offset correction if necessary.
+  // no extra analysis necessary. Assumes knowledge of the signal shape!
+  // assumes that it is looped over consecutive time bins of one pad
+  //
 
+  //temp
 
   if (icRow<0) return 0;
   if (icPad<0) return 0;
   if (icTimeBin<0) return 0;
-    if ( (icTimeBin>fLastTimeBin) || (icTimeBin<fFirstTimeBin)   ) return 0;
+  if ( (icTimeBin>fLastTimeBin) || (icTimeBin<fFirstTimeBin)   ) return 0;
 
-    Int_t iChannel  = fROC->GetRowIndexes(icsector)[icRow]+icPad; //  global pad position in sector
+  Int_t iChannel  = fROC->GetRowIndexes(icsector)[icRow]+icPad; //  global pad position in sector
 
-    //init first pad and sector in this event
-    if ( fCurrentChannel == -1 ) {
-       fCurrentChannel = iChannel;
-       fCurrentSector  = icsector;
-        fCurrentRow     = icRow;
-    }
+  //init first pad and sector in this event
+  if ( fCurrentChannel == -1 ) {
+    fLastSector=-1;
+    fCurrentChannel = iChannel;
+    fCurrentSector  = icsector;
+    fCurrentRow     = icRow;
+  }
 
-    //process last pad if we change to a new one
-    if ( iChannel != fCurrentChannel ){
-        ProcessPad();
-       fCurrentChannel = iChannel;
-       fCurrentSector  = icsector;
-        fCurrentRow     = icRow;
-    }
+  //process last pad if we change to a new one
+  if ( iChannel != fCurrentChannel ){
+    ProcessPad();
+    fLastSector=fCurrentSector;
+    fCurrentChannel = iChannel;
+    fCurrentSector  = icsector;
+    fCurrentRow     = icRow;
+  }
 
-    //fill signals for current pad
-    fPadSignal.GetMatrixArray()[icTimeBin]=csignal;
-    if ( csignal > fMaxPadSignal ){
-       fMaxPadSignal = csignal;
-       fMaxTimeBin   = icTimeBin;
-    }
-    return 0;
+  //fill signals for current pad
+  fPadSignal.GetMatrixArray()[icTimeBin]=csignal;
+  if ( csignal > fMaxPadSignal ){
+    fMaxPadSignal = csignal;
+    fMaxTimeBin   = icTimeBin;
+  }
+  return 0;
 }
 //_____________________________________________________________________
 void AliTPCCalibCE::FindPedestal(Float_t part)
 {
-    //
+  //
     // find pedestal and noise for the current pad. Use either database or
     // truncated mean with part*100%
-    //
-    Bool_t noPedestal = kTRUE;
+  //
+  Bool_t noPedestal = kTRUE;
 
     //use pedestal database if set
-    if (fPedestalTPC&&fPadNoiseTPC){
+  if (fPedestalTPC&&fPadNoiseTPC){
         //only load new pedestals if the sector has changed
-       if ( fCurrentSector!=fLastSector ){
-           fPedestalROC = fPedestalTPC->GetCalROC(fCurrentSector);
-            fPadNoiseROC = fPadNoiseTPC->GetCalROC(fCurrentSector);
-           fLastSector=fCurrentSector;
-       }
-
-       if ( fPedestalROC&&fPadNoiseROC ){
-           fPadPedestal = fPedestalROC->GetValue(fCurrentChannel)*(Float_t)(!fIsZeroSuppressed);
-           fPadNoise    = fPadNoiseROC->GetValue(fCurrentChannel);
-            noPedestal   = kFALSE;
-       }
+    if ( fCurrentSector!=fLastSector ){
+      fPedestalROC = fPedestalTPC->GetCalROC(fCurrentSector);
+      fPadNoiseROC = fPadNoiseTPC->GetCalROC(fCurrentSector);
+    }
 
+    if ( fPedestalROC&&fPadNoiseROC ){
+      fPadPedestal = fPedestalROC->GetValue(fCurrentChannel)*(Float_t)(!fIsZeroSuppressed);
+      fPadNoise    = fPadNoiseROC->GetValue(fCurrentChannel);
+      noPedestal   = kFALSE;
     }
 
+  }
+
     //if we are not running with pedestal database, or for the current sector there is no information
     //available, calculate the pedestal and noise on the fly
-    if ( noPedestal ) {
-       fPadPedestal = 0;
-       fPadNoise    = 0;
-        if ( fIsZeroSuppressed ) return;
-       const Int_t kPedMax = 100;  //maximum pedestal value
-       Float_t  max    =  0;
-       Float_t  maxPos =  0;
-       Int_t    median =  -1;
-       Int_t    count0 =  0;
-       Int_t    count1 =  0;
-       //
-       Float_t padSignal=0;
-        //
-       UShort_t histo[kPedMax];
-       memset(histo,0,kPedMax*sizeof(UShort_t));
+  if ( noPedestal ) {
+    fPadPedestal = 0;
+    fPadNoise    = 0;
+    if ( fIsZeroSuppressed ) return;
+    const Int_t kPedMax = 100;  //maximum pedestal value
+    Float_t  max    =  0;
+    Float_t  maxPos =  0;
+    Int_t    median =  -1;
+    Int_t    count0 =  0;
+    Int_t    count1 =  0;
+    //
+    Float_t padSignal=0;
+    //
+    UShort_t histo[kPedMax];
+    memset(histo,0,kPedMax*sizeof(UShort_t));
 
         //fill pedestal histogram
-       for (Int_t i=fFirstTimeBin; i<=fLastTimeBin; ++i){
-            padSignal = fPadSignal.GetMatrixArray()[i];
-           if (padSignal<=0) continue;
-           if (padSignal>max && i>10) {
-               max = padSignal;
-               maxPos = i;
-           }
-           if (padSignal>kPedMax-1) continue;
-           histo[int(padSignal+0.5)]++;
-           count0++;
-       }
+    for (Int_t i=fFirstTimeBin; i<=fLastTimeBin; ++i){
+      padSignal = fPadSignal.GetMatrixArray()[i];
+      if (padSignal<=0) continue;
+      if (padSignal>max && i>10) {
+        max = padSignal;
+        maxPos = i;
+      }
+      if (padSignal>kPedMax-1) continue;
+      histo[int(padSignal+0.5)]++;
+      count0++;
+    }
        //find median
-       for (Int_t i=1; i<kPedMax; ++i){
-           if (count1<count0*0.5) median=i;
-           count1+=histo[i];
-       }
+    for (Int_t i=1; i<kPedMax; ++i){
+      if (count1<count0*0.5) median=i;
+      count1+=histo[i];
+    }
        // truncated mean
-       //
-       Float_t count=histo[median] ,mean=histo[median]*median,  rms=histo[median]*median*median ;
-       //
-       for (Int_t idelta=1; idelta<10; ++idelta){
-           if (median-idelta<=0) continue;
-           if (median+idelta>kPedMax) continue;
-           if (count<part*count1){
-               count+=histo[median-idelta];
-               mean +=histo[median-idelta]*(median-idelta);
-               rms  +=histo[median-idelta]*(median-idelta)*(median-idelta);
-               count+=histo[median+idelta];
-               mean +=histo[median+idelta]*(median+idelta);
-               rms  +=histo[median+idelta]*(median+idelta)*(median+idelta);
-           }
-       }
-       if ( count > 0 ) {
-           mean/=count;
-           rms    = TMath::Sqrt(TMath::Abs(rms/count-mean*mean));
-           fPadPedestal = mean;
-           fPadNoise    = rms;
-       } 
+    //
+    Float_t count=histo[median] ,mean=histo[median]*median,  rms=histo[median]*median*median ;
+    //
+    for (Int_t idelta=1; idelta<10; ++idelta){
+      if (median-idelta<=0) continue;
+      if (median+idelta>kPedMax) continue;
+      if (count<part*count1){
+        count+=histo[median-idelta];
+        mean +=histo[median-idelta]*(median-idelta);
+        rms  +=histo[median-idelta]*(median-idelta)*(median-idelta);
+        count+=histo[median+idelta];
+        mean +=histo[median+idelta]*(median+idelta);
+        rms  +=histo[median+idelta]*(median+idelta)*(median+idelta);
+      }
+    }
+    if ( count > 0 ) {
+      mean/=count;
+      rms    = TMath::Sqrt(TMath::Abs(rms/count-mean*mean));
+      fPadPedestal = mean;
+      fPadNoise    = rms;
     }
+  }
 }
 //_____________________________________________________________________
+void AliTPCCalibCE::UpdateCETimeRef()
+{
+  // Find the time reference of the last valid CE signal in sector
+  // for irocs of the A-Side the reference of the corresponging OROC is returned
+  // the reason are the non reflective bands on the A-Side, which make the reference very uncertain
+  if ( fLastSector == fCurrentSector ) return;
+  Int_t sector=fCurrentSector; 
+  if ( sector < 18 ) sector+=36;
+  fCurrentCETimeRef=0;
+  TVectorF *vtRef = GetTMeanEvents(sector);
+  if ( !vtRef ) return; 
+  Int_t vtRefSize= vtRef->GetNrows();
+  if ( vtRefSize < fNevents+1 ) vtRef->ResizeTo(vtRefSize+100);
+  else vtRefSize=fNevents; 
+  while ( (*vtRef)[vtRefSize]==0 && vtRefSize>=0 ) --vtRefSize;
+  fCurrentCETimeRef=(*vtRef)[vtRefSize];
+  AliDebug(3,Form("Sector: %02d - T0 ref: %.2f",fCurrentSector,fCurrentCETimeRef)); 
+} 
+//_____________________________________________________________________
 void AliTPCCalibCE::FindCESignal(TVectorD &param, Float_t &qSum, const TVectorF maxima)
 {
-    //
+  //
     //  Find position, signal width and height of the CE signal (last signal)
     //  param[0] = Qmax, param[1] = mean time, param[2] = rms;
     //  maxima: array of local maxima of the pad signal use the one closest to the mean CE position
-    //
+  //
 
-    Float_t ceQmax  =0, ceQsum=0, ceTime=0, ceRMS=0;
-    Int_t   cemaxpos       = 0;
-    Float_t ceSumThreshold = fNoiseThresholdSum*fPadNoise;  // threshold for the signal sum
-    const Int_t    kCemin  = 4;             // range for the analysis of the ce signal +- channels from the peak
-    const Int_t    kCemax  = 7;
+  Float_t ceQmax  =0, ceQsum=0, ceTime=0, ceRMS=0;
+  Int_t   cemaxpos       = 0;
+  Float_t ceSumThreshold = fNoiseThresholdSum*fPadNoise;  // threshold for the signal sum
+  const Int_t    kCemin  = 4;             // range for the analysis of the ce signal +- channels from the peak
+  const Int_t    kCemax  = 7;
 
-    Float_t minDist  = 25;  //initial minimum distance betweek roc mean ce signal and pad ce signal
+  Float_t minDist  = 25;  //initial minimum distance betweek roc mean ce signal and pad ce signal
 
     // find maximum closest to the sector mean from the last event
-    for ( Int_t imax=0; imax<maxima.GetNrows(); ++imax){
+  for ( Int_t imax=0; imax<maxima.GetNrows(); ++imax){
         // get sector mean of last event
-       Float_t tmean = (*GetTMeanEvents(fCurrentSector))[fNevents-1];
-           if ( TMath::Abs( tmean-maxima[imax] ) < minDist ) {
-               minDist  = tmean-maxima[imax];
-                cemaxpos = (Int_t)maxima[imax];
-           }
+    Float_t tmean = fCurrentCETimeRef;
+    if ( TMath::Abs( tmean-maxima[imax] ) < minDist ) {
+      minDist  = tmean-maxima[imax];
+      cemaxpos = (Int_t)maxima[imax];
     }
+  }
 
-    if (cemaxpos!=0){
-        ceQmax = fPadSignal.GetMatrixArray()[cemaxpos]-fPadPedestal;
-       for (Int_t i=cemaxpos-kCemin; i<cemaxpos+kCemax; ++i){
-           if ( (i>fFirstTimeBin) && (i<fLastTimeBin) ){
-               Float_t signal = fPadSignal.GetMatrixArray()[i]-fPadPedestal;
-               if (signal>0) {
-                   ceTime+=signal*(i+0.5);
-                   ceRMS +=signal*(i+0.5)*(i+0.5);
-                   ceQsum+=signal;
-               }
-           }
-       }
-    }
-    if (ceQmax&&ceQsum>ceSumThreshold) {
-       ceTime/=ceQsum;
-       ceRMS  = TMath::Sqrt(TMath::Abs(ceRMS/ceQsum-ceTime*ceTime));
-       fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime;   // mean time for each sector
-       fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
-
-       //Normalise Q to pad area of irocs
-       Float_t norm = fParam->GetPadPitchWidth(fCurrentSector)*fParam->GetPadPitchLength(fCurrentSector,fCurrentRow);
-
-       ceQsum/=norm;
-       fVMeanQ.GetMatrixArray()[fCurrentSector]+=ceQsum;
-        fVMeanQCounter.GetMatrixArray()[fCurrentSector]++;
-    } else {
-       ceQmax=0;
-       ceTime=0;
-       ceRMS =0;
-       ceQsum=0;
+  if (cemaxpos!=0){
+    ceQmax = fPadSignal.GetMatrixArray()[cemaxpos]-fPadPedestal;
+    for (Int_t i=cemaxpos-kCemin; i<cemaxpos+kCemax; ++i){
+      if ( (i>fFirstTimeBin) && (i<fLastTimeBin) ){
+        Float_t signal = fPadSignal.GetMatrixArray()[i]-fPadPedestal;
+        if (signal>0) {
+          ceTime+=signal*(i+0.5);
+          ceRMS +=signal*(i+0.5)*(i+0.5);
+          ceQsum+=signal;
+        }
+      }
     }
-    param[0] = ceQmax;
-    param[1] = ceTime;
-    param[2] = ceRMS;
-    qSum     = ceQsum;
+  }
+  if (ceQmax&&ceQsum>ceSumThreshold) {
+    ceTime/=ceQsum;
+    ceRMS  = TMath::Sqrt(TMath::Abs(ceRMS/ceQsum-ceTime*ceTime));
+    fVTime0Offset.GetMatrixArray()[fCurrentSector]+=ceTime;   // mean time for each sector
+    fVTime0OffsetCounter.GetMatrixArray()[fCurrentSector]++;
+
+  //Normalise Q to the 'cell-size': The wire density is the same in the IROC and OROC, therefore the
+  //                                the pick-up signal should scale with the pad area. In addition
+  //                                the signal should decrease with the wire distance (4mm in IROC, 6mm in OROC),
+  //                                ratio 2/3. The pad area we express in cm2. We normalise the signal
+  //                                to the OROC signal (factor 2/3 for the IROCs).  
+    Float_t norm = fParam->GetPadPitchWidth(fCurrentSector)*fParam->GetPadPitchLength(fCurrentSector,fCurrentRow);
+    if ( fCurrentSector<fParam->GetNInnerSector() ) norm*=3./2.;
+
+    ceQsum/=norm;
+    fVMeanQ.GetMatrixArray()[fCurrentSector]+=ceQsum;
+    fVMeanQCounter.GetMatrixArray()[fCurrentSector]++;
+  } else {
+    ceQmax=0;
+    ceTime=0;
+    ceRMS =0;
+    ceQsum=0;
+  }
+  param[0] = ceQmax;
+  param[1] = ceTime;
+  param[2] = ceRMS;
+  qSum     = ceQsum;
 }
 //_____________________________________________________________________
 Bool_t AliTPCCalibCE::IsPeak(Int_t pos, Int_t tminus, Int_t tplus) const
 {
-    //
+  //
     // Check if 'pos' is a Maximum. Consider 'tminus' timebins before
     // and 'tplus' timebins after 'pos'
-    //
-    if ( (pos-tminus)<fFirstTimeBin || (pos+tplus)>fLastTimeBin ) return kFALSE;
-    for (Int_t iTime = pos; iTime>pos-tminus; --iTime)
-       if ( fPadSignal[iTime-1] >= fPadSignal[iTime] ) return kFALSE;
-    for (Int_t iTime = pos, iTime2=pos; iTime<pos+tplus; ++iTime, ++iTime2){
-       if ( (iTime==pos) && (fPadSignal[iTime+1]==fPadSignal[iTime]) ) // allow two timebins with same adc value
-           ++iTime2;
-       if ( fPadSignal[iTime2+1] >= fPadSignal[iTime2] ) return kFALSE;
-    }
-    return kTRUE;
+  //
+  if ( (pos-tminus)<fFirstTimeBin || (pos+tplus)>fLastTimeBin ) return kFALSE;
+  for (Int_t iTime = pos; iTime>pos-tminus; --iTime)
+    if ( fPadSignal[iTime-1] >= fPadSignal[iTime] ) return kFALSE;
+  for (Int_t iTime = pos, iTime2=pos; iTime<pos+tplus; ++iTime, ++iTime2){
+    if ( (iTime==pos) && (fPadSignal[iTime+1]==fPadSignal[iTime]) ) // allow two timebins with same adc value
+      ++iTime2;
+    if ( fPadSignal[iTime2+1] >= fPadSignal[iTime2] ) return kFALSE;
+  }
+  return kTRUE;
 }
 //_____________________________________________________________________
 void AliTPCCalibCE::FindLocalMaxima(TVectorF &maxima)
 {
-    //
+  //
     // Find local maxima on the pad signal and Histogram them
-    //
+  //
   Float_t ceThreshold = fNoiseThresholdMax*TMath::Max(fPadNoise,Float_t(1.));  // threshold for the signal
-    Int_t   count       = 0;
+  Int_t   count       = 0;
 //    Int_t   tminus      = 2;
 //    Int_t   tplus       = 3;
-    for (Int_t i=fLastTimeBin-fPeakPlus-1; i>=fFirstTimeBin+fPeakMinus; --i){
-       if ( (fPadSignal[i]-fPadPedestal)>ceThreshold && IsPeak(i,fPeakMinus,fPeakPlus) ){
-         if (count<maxima.GetNrows()){
-           maxima.GetMatrixArray()[count++]=i;
-           GetHistoTmean(fCurrentSector,kTRUE)->Fill(i);
-         }
-       }
+  for (Int_t i=fLastTimeBin-fPeakPlus-1; i>=fFirstTimeBin+fPeakMinus; --i){
+    if ( (fPadSignal[i]-fPadPedestal)>ceThreshold && IsPeak(i,fPeakMinus,fPeakPlus) ){
+      if (count<maxima.GetNrows()){
+        maxima.GetMatrixArray()[count++]=i;
+        GetHistoTmean(fCurrentSector,kTRUE)->Fill(i);
+      }
     }
+  }
 }
 //_____________________________________________________________________
 void AliTPCCalibCE::ProcessPad()
@@ -816,8 +936,8 @@ void AliTPCCalibCE::ProcessPad()
     FindLocalMaxima(maxima);
     if ( (fNevents == 0) || (fOldRunNumber!=fRunNumber) ) return;  // return because we don't have Time0 info for the CE yet
 
-    if ( !GetTMeanEvents(fCurrentSector) ) return; //return if we don't have time 0 info, eg if only one side has laser
-
+    UpdateCETimeRef();                       // update the time refenrence for the current sector
+    if ( fCurrentCETimeRef==0 ) return;      //return if we don't have time 0 info, eg if only one side has laser
     TVectorD param(3);
     Float_t  qSum;
     FindCESignal(param, qSum, maxima);
@@ -847,238 +967,238 @@ void AliTPCCalibCE::ProcessPad()
 //_____________________________________________________________________
 void AliTPCCalibCE::EndEvent()
 {
-    //
-    //  Process data of current pad
-    //  The Functions 'SetTimeStamp' and 'SetRunNumber'  should be called
-    //  before the EndEvent function to set the event timestamp and number!!!
-    //  This is automatically done if the ProcessEvent(AliRawReader *rawReader)
-    //  function was called
-    //
+  //  Process data of current pad
+  //  The Functions 'SetTimeStamp' and 'SetRunNumber'  should be called
+  //  before the EndEvent function to set the event timestamp and number!!!
+  //  This is automatically done if the ProcessEvent(AliRawReader *rawReader)
+  //  function was called
 
-    //check if last pad has allready been processed, if not do so
-    if ( fMaxTimeBin>-1 ) ProcessPad();
+  //check if last pad has allready been processed, if not do so
+  if ( fMaxTimeBin>-1 ) ProcessPad();
 
-    AliDebug(3, Form("EndEvent() - Start; Event: %05d", fNevents));
+  AliDebug(3, Form("EndEvent() - Start; Event: %05d", fNevents));
 
-    TVectorD param(3);
-    TMatrixD dummy(3,3);
+  TVectorD param(3);
+  TMatrixD dummy(3,3);
 //    TVectorF vMeanTime(72);
 //    TVectorF vMeanQ(72);
-    AliTPCCalROC *calIroc=new AliTPCCalROC(0);
-    AliTPCCalROC *calOroc=new AliTPCCalROC(36);
-
-    //find mean time0 offset for side A and C
-    Double_t time0Side[2];       //time0 for side A:0 and C:1
-    Double_t time0SideCount[2];  //time0 counter for side A:0 and C:1
-    time0Side[0]=0;time0Side[1]=0;time0SideCount[0]=0;time0SideCount[1]=0;
-    for ( Int_t iSec = 0; iSec<72; ++iSec ){
-       time0Side[(iSec/18)%2] += fVTime0Offset.GetMatrixArray()[iSec];
-       time0SideCount[(iSec/18)%2] += fVTime0OffsetCounter.GetMatrixArray()[iSec];
-    }
-    if ( time0SideCount[0] >0  )
-       time0Side[0]/=time0SideCount[0];
-    if ( time0SideCount[1] >0 )
-       time0Side[1]/=time0SideCount[1];
+  AliTPCCalROC *calIroc=new AliTPCCalROC(0);
+  AliTPCCalROC *calOroc=new AliTPCCalROC(36);
+
+  //find mean time0 offset for side A and C
+  //use only orocs due to the better statistics
+  Double_t time0Side[2];       //time0 for side A:0 and C:1
+  Double_t time0SideCount[2];  //time0 counter for side A:0 and C:1
+  time0Side[0]=0;time0Side[1]=0;time0SideCount[0]=0;time0SideCount[1]=0;
+  for ( Int_t iSec = 36; iSec<72; ++iSec ){
+    time0Side[(iSec/18)%2] += fVTime0Offset.GetMatrixArray()[iSec];
+    time0SideCount[(iSec/18)%2] += fVTime0OffsetCounter.GetMatrixArray()[iSec];
+  }
+  if ( time0SideCount[0] >0  )
+    time0Side[0]/=time0SideCount[0];
+  if ( time0SideCount[1] >0 )
+    time0Side[1]/=time0SideCount[1];
     // end find time0 offset
-
-    Int_t nSecMeanT=0;
-    //loop over all ROCs, fill CE Time histogram corrected for the mean Time0 of each ROC
-    for ( Int_t iSec = 0; iSec<72; ++iSec ){
-       AliDebug(4,Form("Processing sector '%02d'\n",iSec));
-      //find median and then calculate the mean around it
-       TH1S *hMeanT    = GetHistoTmean(iSec); //histogram with local maxima position information
-       if ( !hMeanT ) continue;
-        //continue if not enough data is filled in the meanT histogram. This is the case if we do not have a laser event.
-       if ( hMeanT->GetEntries() < fROC->GetNChannels(iSec)*fSecRejectRatio ){
-           hMeanT->Reset();
-           AliDebug(3,Form("Skipping sec. '%02d': Not enough statistics\n",iSec));
-          continue;
-        }
-
-       Double_t entries = hMeanT->GetEntries();
-       Double_t sum     = 0;
-       Short_t *arr     = hMeanT->GetArray()+1;
-        Int_t ibin=0;
-       for ( ibin=0; ibin<hMeanT->GetNbinsX(); ++ibin){
-           sum+=arr[ibin];
-            if ( sum>=(entries/2.) ) break;
-       }
-       Int_t delta = 4;
-        Int_t firstBin = fFirstTimeBin+ibin-delta;
-       Int_t lastBin  = fFirstTimeBin+ibin+delta;
-        if ( firstBin<fFirstTimeBin ) firstBin=fFirstTimeBin;
-        if ( lastBin>fLastTimeBin   ) lastBin =fLastTimeBin;
-       Float_t median =AliMathBase::GetCOG(arr+ibin-delta,2*delta,firstBin,lastBin);
-
+  AliDebug(3,Form("time0Side/time0SideCount: A=%.2f/%.2f, C=%.2f/%.2f",time0Side[0],time0SideCount[0],time0Side[1],time0SideCount[1]));
+  Int_t nSecMeanT=0;
+  //loop over all ROCs, fill CE Time histogram corrected for the mean Time0 of each ROC
+  for ( Int_t iSec = 0; iSec<72; ++iSec ){
+    AliDebug(4,Form("Processing sector '%02d'\n",iSec));
+    //find median and then calculate the mean around it
+    TH1S *hMeanT    = GetHistoTmean(iSec); //histogram with local maxima position information
+    if ( !hMeanT ) continue;
+    //continue if not enough data is filled in the meanT histogram. This is the case if we do not have a laser event.
+    if ( hMeanT->GetEffectiveEntries() < fROC->GetNChannels(iSec)*fSecRejectRatio ){
+      hMeanT->Reset();
+      AliDebug(3,Form("Skipping sec. '%02d': Not enough statistics\n",iSec));
+      continue;
+    }
+    
+    Double_t entries = hMeanT->GetEffectiveEntries();
+    Double_t sum     = 0;
+    Short_t *arr     = hMeanT->GetArray()+1;
+    Int_t ibin=0;
+    for ( ibin=0; ibin<hMeanT->GetNbinsX(); ++ibin){
+      sum+=arr[ibin];
+      if ( sum>=(entries/2.) ) break;
+    }
+    Int_t delta = 4;
+    Int_t firstBin = fFirstTimeBin+ibin-delta;
+    Int_t lastBin  = fFirstTimeBin+ibin+delta;
+    if ( firstBin<fFirstTimeBin ) firstBin=fFirstTimeBin;
+    if ( lastBin>fLastTimeBin   ) lastBin =fLastTimeBin;
+    Float_t median =AliMathBase::GetCOG(arr+ibin-delta,2*delta,firstBin,lastBin);
+    
        // check boundaries for ebye info of mean time
-       TVectorF *vMeanTime=GetTMeanEvents(iSec,kTRUE);
-        Int_t vSize=vMeanTime->GetNrows();
-       if ( vSize < fNevents+1 )
-            vMeanTime->ResizeTo(vSize+100);
-
-       vMeanTime->GetMatrixArray()[fNevents]=median;
-        nSecMeanT++;
-      // end find median
-        
-       TVectorF *vTimes = GetPadTimesEvent(iSec);
-       if ( !vTimes ) continue;                     //continue if no time information for this sector is available
-
-
-       AliTPCCalROC calIrocOutliers(0);
-       AliTPCCalROC calOrocOutliers(36);
-
-        // calculate mean Q of the sector
-       Float_t meanQ = 0;
-       if ( fVMeanQCounter.GetMatrixArray()[iSec]>0 ) meanQ=fVMeanQ.GetMatrixArray()[iSec]/fVMeanQCounter.GetMatrixArray()[iSec];
-       TVectorF *vMeanQ=GetQMeanEvents(iSec,kTRUE);
-       if ( vSize < fNevents+1 )           // vSize is the same as for vMeanTime!
-            vMeanQ->ResizeTo(vSize+100);
-
-       vMeanQ->GetMatrixArray()[fNevents]=meanQ;
-
-       for ( UInt_t iChannel=0; iChannel<fROC->GetNChannels(iSec); ++iChannel ){
-           Float_t time  = (*vTimes).GetMatrixArray()[iChannel];
+    TVectorF *vMeanTime=GetTMeanEvents(iSec,kTRUE);
+    Int_t vSize=vMeanTime->GetNrows();
+    if ( vSize < fNevents+1 ){
+      vMeanTime->ResizeTo(vSize+100);
+    }
+    
+    vMeanTime->GetMatrixArray()[fNevents]=median;
+    nSecMeanT++;
+    // end find median
+    
+    TVectorF *vTimes = GetPadTimesEvent(iSec);
+    if ( !vTimes ) continue;                     //continue if no time information for this sector is available
+    
+    AliTPCCalROC calIrocOutliers(0);
+    AliTPCCalROC calOrocOutliers(36);
+    
+    // calculate mean Q of the sector
+    TVectorF *vMeanQ=GetQMeanEvents(iSec,kTRUE);
+    vSize=vMeanQ->GetNrows();
+    if ( vSize < fNevents+1 ){
+      vMeanQ->ResizeTo(vSize+100);
+    }   
+    Float_t meanQ = 0;
+    if ( fVMeanQCounter.GetMatrixArray()[iSec]>0 ) meanQ=fVMeanQ.GetMatrixArray()[iSec]/fVMeanQCounter.GetMatrixArray()[iSec];
+    vMeanQ->GetMatrixArray()[fNevents]=meanQ;
+   
+    for ( UInt_t iChannel=0; iChannel<fROC->GetNChannels(iSec); ++iChannel ){
+      Float_t time  = (*vTimes).GetMatrixArray()[iChannel];
 
            //set values for temporary roc calibration class
-           if ( iSec < 36 ) {
-               calIroc->SetValue(iChannel, time);
-                if ( time == 0 ) calIrocOutliers.SetValue(iChannel,1);
+      if ( iSec < 36 ) {
+        calIroc->SetValue(iChannel, time);
+        if ( time == 0 ) calIrocOutliers.SetValue(iChannel,1);
 
-           } else {
-               calOroc->SetValue(iChannel, time);
-                if ( time == 0 ) calOrocOutliers.SetValue(iChannel,1);
-           }
+      } else {
+        calOroc->SetValue(iChannel, time);
+        if ( time == 0 ) calOrocOutliers.SetValue(iChannel,1);
+      }
 
-           if ( (fNevents>0) && (fOldRunNumber==fRunNumber) )
-               GetHistoT0(iSec,kTRUE)->Fill( time-time0Side[(iSec/18)%2],iChannel );
+      if ( (fNevents>0) && (fOldRunNumber==fRunNumber) )
+        GetHistoT0(iSec,kTRUE)->Fill( time-time0Side[(iSec/18)%2],iChannel );
 
 
 
            //-------------------------------  Debug start  ------------------------------
-           if ( fDebugLevel>0 ){
-               if ( !fDebugStreamer ) {
+      if ( fDebugLevel>0 ){
+        if ( !fDebugStreamer ) {
                         //debug stream
-                   TDirectory *backup = gDirectory;
-                   fDebugStreamer = new TTreeSRedirector("debugCalibCE.root");
-                   if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
-               }
+          TDirectory *backup = gDirectory;
+          fDebugStreamer = new TTreeSRedirector("debugCalibCE.root");
+          if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
+        }
 
-               Int_t row=0;
-               Int_t pad=0;
-               Int_t padc=0;
+        Int_t row=0;
+        Int_t pad=0;
+        Int_t padc=0;
 
-               Float_t q   = (*GetPadQEvent(iSec))[iChannel];
-                Float_t rms = (*GetPadRMSEvent(iSec))[iChannel];
+        Float_t q   = (*GetPadQEvent(iSec))[iChannel];
+        Float_t rms = (*GetPadRMSEvent(iSec))[iChannel];
 
-               UInt_t channel=iChannel;
-               Int_t sector=iSec;
+        UInt_t channel=iChannel;
+        Int_t sector=iSec;
 
-               while ( channel > (fROC->GetRowIndexes(sector)[row]+fROC->GetNPads(sector,row)-1) ) row++;
-               pad = channel-fROC->GetRowIndexes(sector)[row];
-               padc = pad-(fROC->GetNPads(sector,row)/2);
+        while ( channel > (fROC->GetRowIndexes(sector)[row]+fROC->GetNPads(sector,row)-1) ) row++;
+        pad = channel-fROC->GetRowIndexes(sector)[row];
+        padc = pad-(fROC->GetNPads(sector,row)/2);
 
 //             TH1F *h1 = new TH1F(Form("hSignalD%d.%d.%d",sector,row,pad),
 //                                 Form("hSignalD%d.%d.%d",sector,row,pad),
 //                                 fLastTimeBin-fFirstTimeBin,
 //                                 fFirstTimeBin,fLastTimeBin);
 //             h1->SetDirectory(0);
-//
+        //
 //             for (Int_t i=fFirstTimeBin; i<fLastTimeBin+1; ++i)
 //                 h1->Fill(i,fPadSignal(i));
 
-               Double_t t0Sec = 0;
-               if (fVTime0OffsetCounter.GetMatrixArray()[iSec]>0)
-                   t0Sec = fVTime0Offset.GetMatrixArray()[iSec]/fVTime0OffsetCounter.GetMatrixArray()[iSec];
-               Double_t t0Side = time0Side[(iSec/18)%2];
-               (*fDebugStreamer) << "DataPad" <<
-                   "Event=" << fNevents <<
-                   "RunNumber=" << fRunNumber <<
-                   "TimeStamp="   << fTimeStamp <<
-                   "Sector="<< sector <<
-                   "Row="   << row<<
-                   "Pad="   << pad <<
-                   "PadC="  << padc <<
-                   "PadSec="<< channel <<
-                   "Time0Sec="  << t0Sec <<
-                   "Time0Side=" << t0Side <<
-                   "Time="  << time <<
-                   "RMS="   << rms <<
-                   "Sum="   << q <<
-                    "MeanQ=" << meanQ <<
+        Double_t t0Sec = 0;
+        if (fVTime0OffsetCounter.GetMatrixArray()[iSec]>0)
+          t0Sec = fVTime0Offset.GetMatrixArray()[iSec]/fVTime0OffsetCounter.GetMatrixArray()[iSec];
+        Double_t t0Side = time0Side[(iSec/18)%2];
+        (*fDebugStreamer) << "DataPad" <<
+            "Event=" << fNevents <<
+            "RunNumber=" << fRunNumber <<
+            "TimeStamp="   << fTimeStamp <<
+            "Sector="<< sector <<
+            "Row="   << row<<
+            "Pad="   << pad <<
+            "PadC="  << padc <<
+            "PadSec="<< channel <<
+            "Time0Sec="  << t0Sec <<
+            "Time0Side=" << t0Side <<
+            "Time="  << time <<
+            "RMS="   << rms <<
+            "Sum="   << q <<
+            "MeanQ=" << meanQ <<
                    //              "hist.=" << h1 <<
-                   "\n";
+            "\n";
 
                //              delete h1;
 
-           }
+      }
            //-----------------------------  Debug end  ------------------------------
-       }// end channel loop
-
-       TVectorD paramPol1(3);
-       TVectorD paramPol2(6);
-       TMatrixD matPol1(3,3);
-       TMatrixD matPol2(6,6);
-       Float_t  chi2Pol1=0;
-       Float_t  chi2Pol2=0;
-
-       if ( (fNevents>0) && (fOldRunNumber==fRunNumber) ){
-           if ( iSec < 36 ){
-               calIroc->GlobalFit(&calIrocOutliers,0,paramPol1,matPol1,chi2Pol1,0);
-               calIroc->GlobalFit(&calIrocOutliers,0,paramPol2,matPol2,chi2Pol2,1);
-           } else {
-               calOroc->GlobalFit(&calOrocOutliers,0,paramPol1,matPol1,chi2Pol1,0);
-               calOroc->GlobalFit(&calOrocOutliers,0,paramPol2,matPol2,chi2Pol2,1);
-           }
+    }// end channel loop
+
+    TVectorD paramPol1(3);
+    TVectorD paramPol2(6);
+    TMatrixD matPol1(3,3);
+    TMatrixD matPol2(6,6);
+    Float_t  chi2Pol1=0;
+    Float_t  chi2Pol2=0;
+
+    if ( (fNevents>0) && (fOldRunNumber==fRunNumber) ){
+      if ( iSec < 36 ){
+        calIroc->GlobalFit(&calIrocOutliers,0,paramPol1,matPol1,chi2Pol1,0);
+        calIroc->GlobalFit(&calIrocOutliers,0,paramPol2,matPol2,chi2Pol2,1);
+      } else {
+        calOroc->GlobalFit(&calOrocOutliers,0,paramPol1,matPol1,chi2Pol1,0);
+        calOroc->GlobalFit(&calOrocOutliers,0,paramPol2,matPol2,chi2Pol2,1);
+      }
 
-           GetParamArrayPol1(iSec,kTRUE)->AddAtAndExpand(new TVectorD(paramPol1), fNevents);
-           GetParamArrayPol2(iSec,kTRUE)->AddAtAndExpand(new TVectorD(paramPol2), fNevents);
-       }
+      GetParamArrayPol1(iSec,kTRUE)->AddAtAndExpand(new TVectorD(paramPol1), fNevents);
+      GetParamArrayPol2(iSec,kTRUE)->AddAtAndExpand(new TVectorD(paramPol2), fNevents);
+    }
 
        //-------------------------------  Debug start  ------------------------------
-       if ( fDebugLevel>0 ){
-           if ( !fDebugStreamer ) {
+    if ( fDebugLevel>0 ){
+      if ( !fDebugStreamer ) {
                //debug stream
-               TDirectory *backup = gDirectory;
-               fDebugStreamer = new TTreeSRedirector("debugCalibCE.root");
-               if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
-           }
-           (*fDebugStreamer) << "DataRoc" <<
+        TDirectory *backup = gDirectory;
+        fDebugStreamer = new TTreeSRedirector("debugCalibCE.root");
+        if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
+      }
+      (*fDebugStreamer) << "DataRoc" <<
 //             "Event=" << fEvent <<
-               "RunNumber=" << fRunNumber <<
-               "TimeStamp="   << fTimeStamp <<
-               "Sector="<< iSec <<
-               "hMeanT.=" << hMeanT <<
-               "median=" << median <<
-               "paramPol1.=" << &paramPol1 <<
-               "paramPol2.=" << &paramPol2 <<
-               "matPol1.="   << &matPol1 <<
-               "matPol2.="   << &matPol2 <<
-               "chi2Pol1="   << chi2Pol1 <<
-                "chi2Pol2="   << chi2Pol2 <<
-               "\n";
-       }
+          "RunNumber=" << fRunNumber <<
+          "TimeStamp="   << fTimeStamp <<
+          "Sector="<< iSec <<
+          "hMeanT.=" << hMeanT <<
+          "median=" << median <<
+          "paramPol1.=" << &paramPol1 <<
+          "paramPol2.=" << &paramPol2 <<
+          "matPol1.="   << &matPol1 <<
+          "matPol2.="   << &matPol2 <<
+          "chi2Pol1="   << chi2Pol1 <<
+          "chi2Pol2="   << chi2Pol2 <<
+          "\n";
+    }
        //-------------------------------  Debug end  ------------------------------
-        hMeanT->Reset();
-    }// end sector loop
+    hMeanT->Reset();
+  }// end sector loop
     //return if no sector has a valid mean time
-    if ( nSecMeanT == 0 ) return;
+  if ( nSecMeanT == 0 ) return;
     
     
 //    fTMeanArrayEvent.AddAtAndExpand(new TVectorF(vMeanTime),fNevents);
 //    fQMeanArrayEvent.AddAtAndExpand(new TVectorF(vMeanQ),fNevents);
-    if ( fVEventTime.GetNrows() < fNevents+1 ) {
-       fVEventTime.ResizeTo((Int_t)(fVEventTime.GetNrows()+100));
-       fVEventNumber.ResizeTo((Int_t)(fVEventNumber.GetNrows()+100));
-    }
-    fVEventTime.GetMatrixArray()[fNevents] = fTimeStamp;
-    fVEventNumber.GetMatrixArray()[fNevents] = fEventId;
+  if ( fVEventTime.GetNrows() < fNevents+1 ) {
+    fVEventTime.ResizeTo((Int_t)(fVEventTime.GetNrows()+100));
+    fVEventNumber.ResizeTo((Int_t)(fVEventNumber.GetNrows()+100));
+  }
+  fVEventTime.GetMatrixArray()[fNevents] = fTimeStamp;
+  fVEventNumber.GetMatrixArray()[fNevents] = fEventId;
 
-    fNevents++;
-    fOldRunNumber = fRunNumber;
+  fNevents++;
+  fOldRunNumber = fRunNumber;
 
-    delete calIroc;
-    delete calOroc;
-    AliDebug(3, Form("EndEvent() - End; Event: %05d", fNevents));
+  delete calIroc;
+  delete calOroc;
+  AliDebug(3, Form("EndEvent() - End; Event: %05d", fNevents));
 }
 //_____________________________________________________________________
 Bool_t AliTPCCalibCE::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
@@ -1620,77 +1740,80 @@ void AliTPCCalibCE::Merge(AliTPCCalibCE *ce)
 //_____________________________________________________________________
 TGraph *AliTPCCalibCE::MakeGraphTimeCE(Int_t sector, Int_t xVariable, Int_t fitType, Int_t fitParameter)
 {
-    //
-    // Make graph from fit parameters of pol1 fit, pol2 fit, mean arrival time or mean Q for ROC 'sector'
-    // xVariable:    0-event time, 1-event id, 2-internal event counter
-    // fitType:      0-pol1 fit, 1-pol2 fit, 2-mean time, 3-mean Q
-    // fitParameter: fit parameter ( 0-2 for pol1 ([0]+[1]*x+[2]*y),
-    //                               0-5 for pol2 ([0]+[1]*x+[2]*y+[3]*x*x+[4]*y*y+[5]*x*y),
-    //                               not used for mean time and mean Q )
-    // for an example see class description at the beginning
-    //
+  //
+  // Make graph from fit parameters of pol1 fit, pol2 fit, mean arrival time or mean Q for ROC 'sector'
+  // xVariable:    0-event time, 1-event id, 2-internal event counter
+  // fitType:      0-pol1 fit, 1-pol2 fit, 2-mean time, 3-mean Q
+  // fitParameter: fit parameter ( 0-2 for pol1 ([0]+[1]*x+[2]*y),
+  //                               0-5 for pol2 ([0]+[1]*x+[2]*y+[3]*x*x+[4]*y*y+[5]*x*y),
+  //                               not used for mean time and mean Q )
+  // for an example see class description at the beginning
+  //
 
-    Double_t *x = new Double_t[fNevents];
-    Double_t *y = new Double_t[fNevents];
+  Double_t *x = new Double_t[fNevents];
+  Double_t *y = new Double_t[fNevents];
 
-    TVectorD *xVar = 0x0;
-    TObjArray *aType = 0x0;
-    Int_t npoints=0;
+  TVectorD *xVar = 0x0;
+  TObjArray *aType = 0x0;
+  Int_t npoints=0;
 
     // sanity checks
-    if ( (sector<0) || (sector>71) )      return 0x0;
-    if ( (xVariable<0) || (xVariable>2) ) return 0x0;
-    if ( (fitType<0) || (fitType>3) )     return 0x0;
-    if ( fitType==0 ){
-       if ( (fitParameter<0) || (fitParameter>2) ) return 0x0;
-       aType = &fParamArrayEventPol1;
-       if ( aType->At(sector)==0x0 ) return 0x0;
-    }
-    else if ( fitType==1 ){
-       if ( (fitParameter<0) || (fitParameter>5) ) return 0x0;
-       aType = &fParamArrayEventPol2;
-       if ( aType->At(sector)==0x0 ) return 0x0;
-    }
+  if ( !GetHistoT0(sector) )            return 0x0; //Sector has not been filled 
+  if ( (sector<0) || (sector>71) )      return 0x0;
+  if ( (xVariable<0) || (xVariable>2) ) return 0x0;
+  if ( (fitType<0) || (fitType>3) )     return 0x0;
+  if ( !GetTMeanEvents(sector) )        return 0x0; //no mean time information available
+  
+  if ( fitType==0 ){
+    if ( (fitParameter<0) || (fitParameter>2) ) return 0x0;
+    aType = &fParamArrayEventPol1;
+    if ( aType->At(sector)==0x0 ) return 0x0;
+  }
+  else if ( fitType==1 ){
+    if ( (fitParameter<0) || (fitParameter>5) ) return 0x0;
+    aType = &fParamArrayEventPol2;
+    if ( aType->At(sector)==0x0 ) return 0x0;
+  }
 
 
-    if ( xVariable == 0 ) xVar = &fVEventTime;
-    if ( xVariable == 1 ) xVar = &fVEventNumber;
-    if ( xVariable == 2 ) {
-       xVar = new TVectorD(fNevents);
-       for ( Int_t i=0;i<fNevents; ++i) (*xVar)[i]=i;
-    }
+  if ( xVariable == 0 ) xVar = &fVEventTime;
+  if ( xVariable == 1 ) xVar = &fVEventNumber;
+  if ( xVariable == 2 ) {
+    xVar = new TVectorD(fNevents);
+    for ( Int_t i=0;i<fNevents; ++i) (*xVar)[i]=i;
+  }
 
-    for (Int_t ievent =0; ievent<fNevents; ++ievent){
-       if ( fitType<2 ){
-           TObjArray *events = (TObjArray*)(aType->At(sector));
-            if ( events->GetSize()<=ievent ) break;
-           TVectorD *v = (TVectorD*)(events->At(ievent));
-           if ( (v!=0x0) && ((*xVar)[ievent]>0) ) { x[npoints]=(*xVar)[ievent]; y[npoints]=(*v)[fitParameter]; npoints++;}
-       } else if (fitType == 2) {
-            Double_t xValue=(*xVar)[ievent];
-           Double_t yValue=(*GetTMeanEvents(sector))[ievent];
-           if ( yValue>0 && xValue>0 ) { x[npoints]=xValue; y[npoints]=yValue;npoints++;}
-       }else if (fitType == 3) {
-            Double_t xValue=(*xVar)[ievent];
-            Double_t yValue=(*GetQMeanEvents(sector))[ievent];
-           if ( yValue>0 && xValue>0 ) { x[npoints]=xValue; y[npoints]=yValue;npoints++;}
-       }
+  for (Int_t ievent =0; ievent<fNevents; ++ievent){
+    if ( fitType<2 ){
+      TObjArray *events = (TObjArray*)(aType->At(sector));
+      if ( events->GetSize()<=ievent ) break;
+      TVectorD *v = (TVectorD*)(events->At(ievent));
+      if ( (v!=0x0) && ((*xVar)[ievent]>0) ) { x[npoints]=(*xVar)[ievent]; y[npoints]=(*v)[fitParameter]; npoints++;}
+    } else if (fitType == 2) {
+      Double_t xValue=(*xVar)[ievent];
+      Double_t yValue=(*GetTMeanEvents(sector))[ievent];
+      if ( yValue>0 && xValue>0 ) { x[npoints]=xValue; y[npoints]=yValue;npoints++;}
+    }else if (fitType == 3) {
+      Double_t xValue=(*xVar)[ievent];
+      Double_t yValue=(*GetQMeanEvents(sector))[ievent];
+      if ( yValue>0 && xValue>0 ) { x[npoints]=xValue; y[npoints]=yValue;npoints++;}
     }
+  }
 
-    TGraph *gr = new TGraph(npoints);
+  TGraph *gr = new TGraph(npoints);
     //sort xVariable increasing
-    Int_t    *sortIndex = new Int_t[npoints];
-    TMath::Sort(npoints,x,sortIndex);
-    for (Int_t i=0;i<npoints;++i){
-       gr->SetPoint(i,x[sortIndex[i]],y[sortIndex[i]]);
-    }
+  Int_t    *sortIndex = new Int_t[npoints];
+  TMath::Sort(npoints,x,sortIndex);
+  for (Int_t i=0;i<npoints;++i){
+    gr->SetPoint(i,x[sortIndex[i]],y[sortIndex[i]]);
+  }
 
 
-    if ( xVariable == 2 ) delete xVar;
-    delete x;
-    delete y;
-    delete sortIndex;
-    return gr;
+  if ( xVariable == 2 ) delete xVar;
+  delete x;
+  delete y;
+  delete sortIndex;
+  return gr;
 }
 //_____________________________________________________________________
 void AliTPCCalibCE::Analyse()