]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCCalibCE.cxx
Fix in documentation
[u/mrichter/AliRoot.git] / TPC / AliTPCCalibCE.cxx
index 4842f327eb96f7a862ba77a5e762a11944c60b21..febf42af3f03b55a02180b48ed671132f96cb1cb 100644 (file)
  * provided "as is" without express or implied warranty.                  *
  **************************************************************************/
 
-
-
-
-
-
-
 /* $Id$ */
 
-
-
-//Root includes
-#include <TObjArray.h>
-#include <TH1F.h>
-#include <TH2S.h>
-#include <TString.h>
-#include <TVectorF.h>
-#include <TVectorD.h>
-#include <TMatrixD.h>
-#include <TMath.h>
-#include <TGraph.h>
-#include <TString.h>
-
-#include <TDirectory.h>
-#include <TSystem.h>
-#include <TFile.h>
-
-//AliRoot includes
-#include "AliRawReader.h"
-#include "AliRawReaderRoot.h"
-#include "AliRawReaderDate.h"
-#include "AliRawEventHeaderBase.h"
-#include "AliTPCRawStream.h"
-#include "AliTPCcalibDB.h"
-#include "AliTPCCalROC.h"
-#include "AliTPCCalPad.h"
-#include "AliTPCROC.h"
-#include "AliTPCParam.h"
-#include "AliTPCCalibCE.h"
-#include "AliMathBase.h"
-#include "TTreeStream.h"
-
-//date
-#include "event.h"
-ClassImp(AliTPCCalibCE)
-
-//////////////////////////////////////////////////////////////////////////////////////
-//          Implementation of the TPC Central Electrode calibration
-//
-//   Origin: Jens Wiechula, Marian Ivanov   J.Wiechula@gsi.de, Marian.Ivanov@cern.ch
-// 
+////////////////////////////////////////////////////////////////////////////////////////
+//                                                                                    //
+//             Implementation of the TPC Central Electrode calibration                //
+//                                                                                    //
+//   Origin: Jens Wiechula, Marian Ivanov   J.Wiechula@gsi.de, Marian.Ivanov@cern.ch  //
+//                                                                                    //
+////////////////////////////////////////////////////////////////////////////////////////
 //
 //
 // *************************************************************************************
@@ -299,6 +258,43 @@ END_HTML */
 //////////////////////////////////////////////////////////////////////////////////////
 
 
+//Root includes
+#include <TObjArray.h>
+#include <TH1F.h>
+#include <TH2S.h>
+#include <TString.h>
+#include <TVectorF.h>
+#include <TVectorD.h>
+#include <TMatrixD.h>
+#include <TMath.h>
+#include <TGraph.h>
+#include <TString.h>
+
+#include <TDirectory.h>
+#include <TSystem.h>
+#include <TFile.h>
+
+//AliRoot includes
+#include "AliRawReader.h"
+#include "AliRawReaderRoot.h"
+#include "AliRawReaderDate.h"
+#include "AliRawEventHeaderBase.h"
+#include "AliTPCRawStream.h"
+#include "AliTPCRawStreamFast.h"
+#include "AliTPCcalibDB.h"
+#include "AliTPCCalROC.h"
+#include "AliTPCCalPad.h"
+#include "AliTPCROC.h"
+#include "AliTPCParam.h"
+#include "AliTPCCalibCE.h"
+#include "AliMathBase.h"
+#include "TTreeStream.h"
+
+//date
+#include "event.h"
+ClassImp(AliTPCCalibCE)
+
+
 AliTPCCalibCE::AliTPCCalibCE() :
     TObject(),
     fFirstTimeBin(650),
@@ -315,18 +311,23 @@ AliTPCCalibCE::AliTPCCalibCE() :
     fLastSector(-1),
     fOldRCUformat(kTRUE),
     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),
@@ -355,7 +356,7 @@ AliTPCCalibCE::AliTPCCalibCE() :
     fVTime0OffsetCounter(72),
     fVMeanQ(72),
     fVMeanQCounter(72),
-    fEvent(-1),
+//    fEvent(-1),
     fDebugStreamer(0x0),
     fDebugLevel(0)
 {
@@ -381,18 +382,23 @@ AliTPCCalibCE::AliTPCCalibCE(const AliTPCCalibCE &sig) :
     fLastSector(-1),
     fOldRCUformat(kTRUE),
     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(sig.fMeanT0rms),
+    fMeanQrms(sig.fMeanQrms),
+    fMeanRMSrms(sig.fMeanRMSrms),
     fHistoTmean(72),
     fParamArrayEventPol1(72),
     fParamArrayEventPol2(72),
@@ -421,7 +427,7 @@ AliTPCCalibCE::AliTPCCalibCE(const AliTPCCalibCE &sig) :
     fVTime0OffsetCounter(72),
     fVMeanQ(72),
     fVMeanQCounter(72),
-    fEvent(-1),
+//    fEvent(-1),
     fDebugStreamer(0x0),
     fDebugLevel(sig.fDebugLevel)
 {
@@ -525,6 +531,7 @@ AliTPCCalibCE::~AliTPCCalibCE()
     //
 
     fCalRocArrayT0.Delete();
+    fCalRocArrayT0Err.Delete();
     fCalRocArrayQ.Delete();
     fCalRocArrayRMS.Delete();
     fCalRocArrayOutliers.Delete();
@@ -547,6 +554,7 @@ AliTPCCalibCE::~AliTPCCalibCE()
 
     if ( fDebugStreamer) delete fDebugStreamer;
 //    if ( fHTime0 ) delete fHTime0;
+//    delete fROC;
     delete fParam;
 }
 //_____________________________________________________________________
@@ -561,6 +569,10 @@ Int_t AliTPCCalibCE::Update(const Int_t icsector,
     // no extra analysis necessary. Assumes knowledge of the signal shape!
     // assumes that it is looped over consecutive time bins of one pad
     //
+
+  if (icRow<0) return 0;
+  if (icPad<0) return 0;
+  if (icTimeBin<0) return 0;
     if ( (icTimeBin>fLastTimeBin) || (icTimeBin<fFirstTimeBin)   ) return 0;
 
     Int_t iChannel  = fROC->GetRowIndexes(icsector)[icRow]+icPad; //  global pad position in sector
@@ -736,7 +748,7 @@ void AliTPCCalibCE::FindCESignal(TVectorD &param, Float_t &qSum, const TVectorF
     qSum     = ceQsum;
 }
 //_____________________________________________________________________
-Bool_t AliTPCCalibCE::IsPeak(Int_t pos, Int_t tminus, Int_t tplus)
+Bool_t AliTPCCalibCE::IsPeak(Int_t pos, Int_t tminus, Int_t tplus) const
 {
     //
     // Check if 'pos' is a Maximum. Consider 'tminus' timebins before
@@ -758,7 +770,7 @@ void AliTPCCalibCE::FindLocalMaxima(TVectorF &maxima)
     //
     // Find local maxima on the pad signal and Histogram them
     //
-    Float_t ceThreshold = 5.*fPadNoise;  // threshold for the signal
+  Float_t ceThreshold = 5.*TMath::Max(fPadNoise,Float_t(1.));  // threshold for the signal
     Int_t   count       = 0;
     Int_t   tminus      = 2;
     Int_t   tplus       = 3;
@@ -785,11 +797,9 @@ void AliTPCCalibCE::ProcessPad()
     FindLocalMaxima(maxima);
     if ( (fNevents == 0) || (fOldRunNumber!=fRunNumber) ) return;  // return because we don't have Time0 info for the CE yet
 
-
-
     TVectorD param(3);
-    Float_t  Qsum;
-    FindCESignal(param, Qsum, maxima);
+    Float_t  qSum;
+    FindCESignal(param, qSum, maxima);
 
     Double_t meanT  = param[1];
     Double_t sigmaT = param[2];
@@ -798,7 +808,7 @@ void AliTPCCalibCE::ProcessPad()
     (*GetPadTimesEvent(fCurrentSector,kTRUE)).GetMatrixArray()[fCurrentChannel] = meanT;
 
     //Fill Q histogram
-    GetHistoQ(fCurrentSector,kTRUE)->Fill( TMath::Sqrt(Qsum), fCurrentChannel );
+    GetHistoQ(fCurrentSector,kTRUE)->Fill( TMath::Sqrt(qSum), fCurrentChannel );
 
     //Fill RMS histogram
     GetHistoRMS(fCurrentSector,kTRUE)->Fill( sigmaT, fCurrentChannel );
@@ -808,7 +818,7 @@ void AliTPCCalibCE::ProcessPad()
     if ( fDebugLevel>0 ){
        (*GetPadPedestalEvent(fCurrentSector,kTRUE)).GetMatrixArray()[fCurrentChannel]=fPadPedestal;
        (*GetPadRMSEvent(fCurrentSector,kTRUE)).GetMatrixArray()[fCurrentChannel]=sigmaT;
-       (*GetPadQEvent(fCurrentSector,kTRUE)).GetMatrixArray()[fCurrentChannel]=Qsum;
+       (*GetPadQEvent(fCurrentSector,kTRUE)).GetMatrixArray()[fCurrentChannel]=qSum;
     }
 
     ResetPad();
@@ -835,8 +845,8 @@ void AliTPCCalibCE::EndEvent()
     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:0
-    Double_t time0SideCount[2];  //time0 counter for side A:0 and C:0
+    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];
@@ -848,11 +858,17 @@ void AliTPCCalibCE::EndEvent()
        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 ){
       //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)*2/3 ){
+          hMeanT->Reset();
+          continue;
+        }
 
        Double_t entries = hMeanT->GetEntries();
        Double_t sum     = 0;
@@ -860,7 +876,7 @@ void AliTPCCalibCE::EndEvent()
         Int_t ibin=0;
        for ( ibin=0; ibin<hMeanT->GetNbinsX(); ++ibin){
            sum+=arr[ibin];
-            if ( sum>=(entries/2) ) break;
+            if ( sum>=(entries/2.) ) break;
        }
        Int_t delta = 4;
         Int_t firstBin = fFirstTimeBin+ibin-delta;
@@ -876,8 +892,9 @@ void AliTPCCalibCE::EndEvent()
             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
 
@@ -895,20 +912,20 @@ void AliTPCCalibCE::EndEvent()
        vMeanQ->GetMatrixArray()[fNevents]=meanQ;
 
        for ( UInt_t iChannel=0; iChannel<fROC->GetNChannels(iSec); ++iChannel ){
-           Float_t Time  = (*vTimes).GetMatrixArray()[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);
+               calIroc->SetValue(iChannel, time);
+                if ( time == 0 ) calIrocOutliers.SetValue(iChannel,1);
 
            } else {
-               calOroc->SetValue(iChannel, Time);
-                if ( Time == 0 ) calOrocOutliers.SetValue(iChannel,1);
+               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 );
+               GetHistoT0(iSec,kTRUE)->Fill( time-time0Side[(iSec/18)%2],iChannel );
 
 
 
@@ -925,8 +942,8 @@ void AliTPCCalibCE::EndEvent()
                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;
@@ -944,10 +961,10 @@ void AliTPCCalibCE::EndEvent()
 //             for (Int_t i=fFirstTimeBin; i<fLastTimeBin+1; ++i)
 //                 h1->Fill(i,fPadSignal(i));
 
-               Double_t T0Sec = 0;
+               Double_t t0Sec = 0;
                if (fVTime0OffsetCounter.GetMatrixArray()[iSec]>0)
-                   T0Sec = fVTime0Offset.GetMatrixArray()[iSec]/fVTime0OffsetCounter.GetMatrixArray()[iSec];
-               Double_t T0Side = time0Side[(iSec/18)%2];
+                   t0Sec = fVTime0Offset.GetMatrixArray()[iSec]/fVTime0OffsetCounter.GetMatrixArray()[iSec];
+               Double_t t0Side = time0Side[(iSec/18)%2];
                (*fDebugStreamer) << "DataPad" <<
                    "Event=" << fNevents <<
                    "RunNumber=" << fRunNumber <<
@@ -957,11 +974,11 @@ void AliTPCCalibCE::EndEvent()
                    "Pad="   << pad <<
                    "PadC="  << padc <<
                    "PadSec="<< channel <<
-                   "Time0Sec="  << T0Sec <<
-                   "Time0Side=" << T0Side <<
-                   "Time="  << Time <<
-                   "RMS="   << RMS <<
-                   "Sum="   << Q <<
+                   "Time0Sec="  << t0Sec <<
+                   "Time0Side=" << t0Side <<
+                   "Time="  << time <<
+                   "RMS="   << rms <<
+                   "Sum="   << q <<
                     "MeanQ=" << meanQ <<
                    //              "hist.=" << h1 <<
                    "\n";
@@ -971,7 +988,6 @@ void AliTPCCalibCE::EndEvent()
            }
            //-----------------------------  Debug end  ------------------------------
        }// end channel loop
-       hMeanT->Reset();
 
        TVectorD paramPol1(3);
        TVectorD paramPol2(6);
@@ -992,7 +1008,6 @@ void AliTPCCalibCE::EndEvent()
            GetParamArrayPol1(iSec,kTRUE)->AddAtAndExpand(new TVectorD(paramPol1), fNevents);
            GetParamArrayPol2(iSec,kTRUE)->AddAtAndExpand(new TVectorD(paramPol2), fNevents);
        }
-//     printf("events: %d -- size: %d\n",fNevents,GetParamArrayPol1(iSec)->GetSize());
 
        //-------------------------------  Debug start  ------------------------------
        if ( fDebugLevel>0 ){
@@ -1003,7 +1018,7 @@ void AliTPCCalibCE::EndEvent()
                if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
            }
            (*fDebugStreamer) << "DataRoc" <<
-               "Event=" << fEvent <<
+//             "Event=" << fEvent <<
                "RunNumber=" << fRunNumber <<
                "TimeStamp="   << fTimeStamp <<
                "Sector="<< iSec <<
@@ -1018,8 +1033,12 @@ void AliTPCCalibCE::EndEvent()
                "\n";
        }
        //-------------------------------  Debug end  ------------------------------
+        hMeanT->Reset();
     }// end sector loop
-
+    //return if no sector has a valid mean time
+    if ( nSecMeanT == 0 ) return;
+    
+    
 //    fTMeanArrayEvent.AddAtAndExpand(new TVectorF(vMeanTime),fNevents);
 //    fQMeanArrayEvent.AddAtAndExpand(new TVectorF(vMeanQ),fNevents);
     if ( fVEventTime.GetNrows() < fNevents+1 ) {
@@ -1036,6 +1055,58 @@ void AliTPCCalibCE::EndEvent()
     delete calOroc;
 }
 //_____________________________________________________________________
+Bool_t AliTPCCalibCE::ProcessEventFast(AliTPCRawStreamFast *rawStreamFast)
+{
+  //
+  // Event Processing loop - AliTPCRawStreamFast
+  //
+  ResetEvent();
+  Bool_t withInput = kFALSE;
+  while ( rawStreamFast->NextDDL() ){
+      while ( rawStreamFast->NextChannel() ){
+         Int_t isector  = rawStreamFast->GetSector();                       //  current sector
+         Int_t iRow     = rawStreamFast->GetRow();                          //  current row
+         Int_t iPad     = rawStreamFast->GetPad();                          //  current pad
+
+         while ( rawStreamFast->NextBunch() ){
+            Int_t startTbin = (Int_t)rawStreamFast->GetStartTimeBin();
+            Int_t endTbin = (Int_t)rawStreamFast->GetEndTimeBin();
+            for (Int_t iTimeBin = startTbin; iTimeBin < endTbin; iTimeBin++){
+                 Float_t signal=(Float_t)rawStreamFast->GetSignals()[iTimeBin-startTbin];
+                 Update(isector,iRow,iPad,iTimeBin+1,signal);
+                 withInput = kTRUE;
+             }
+         }
+      }
+  }
+  if (withInput){
+      EndEvent();
+  }
+  return withInput;
+}
+//_____________________________________________________________________
+Bool_t AliTPCCalibCE::ProcessEventFast(AliRawReader *rawReader)
+{
+  //
+  //  Event processing loop using the fast raw stream algorithm- AliRawReader
+  //
+
+  //printf("ProcessEventFast - raw reader\n");
+
+  AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
+  if (eventHeader){
+      fTimeStamp   = eventHeader->Get("Timestamp");
+      fRunNumber = eventHeader->Get("RunNb");
+  }
+  fEventId = *rawReader->GetEventId();
+
+  AliTPCRawStreamFast *rawStreamFast = new AliTPCRawStreamFast(rawReader, (AliAltroMapping**)fMapping);
+  Bool_t res=ProcessEventFast(rawStreamFast);
+  delete rawStreamFast;
+  return res;
+
+}
+//_____________________________________________________________________
 Bool_t AliTPCCalibCE::ProcessEvent(AliTPCRawStream *rawStream)
 {
   //
@@ -1075,7 +1146,7 @@ Bool_t AliTPCCalibCE::ProcessEvent(AliRawReader *rawReader)
   //
 
 
-    AliTPCRawStream rawStream(rawReader);
+  AliTPCRawStream rawStream(rawReader,(AliAltroMapping**)fMapping);
     AliRawEventHeaderBase* eventHeader = (AliRawEventHeaderBase*)rawReader->GetEventHeader();
     if (eventHeader){
        fTimeStamp   = eventHeader->Get("Timestamp");
@@ -1173,7 +1244,7 @@ TH1S* AliTPCCalibCE::GetHisto(Int_t sector, TObjArray *arr,
     sprintf(name,"hCalib%s%.2d",type,sector);
     sprintf(title,"%s calibration histogram sector %.2d",type,sector);
 
-    // new histogram with calib information. One value for each pad!
+    // new histogram with calib information. One value for each pad!
     TH1S* hist = new TH1S(name,title,
                          fLastTimeBin-fFirstTimeBin,fFirstTimeBin,fLastTimeBin);
     hist->SetDirectory(0);
@@ -1191,7 +1262,7 @@ TH1S* AliTPCCalibCE::GetHistoTmean(Int_t sector, Bool_t force)
     return GetHisto(sector, arr, "LastTmean", force);
 }
 //_____________________________________________________________________
-TVectorF* AliTPCCalibCE::GetVectSector(Int_t sector, TObjArray *arr, UInt_t size, Bool_t force)
+TVectorF* AliTPCCalibCE::GetVectSector(Int_t sector, TObjArray *arr, UInt_t size, Bool_t force) const
 {
     //
     // return pointer to Pad Info from 'arr' for the current event and sector
@@ -1269,7 +1340,7 @@ TVectorF* AliTPCCalibCE::GetQMeanEvents(Int_t sector, Bool_t force)
     return GetVectSector(sector,arr,100,force);
 }
 //_____________________________________________________________________
-AliTPCCalROC* AliTPCCalibCE::GetCalRoc(Int_t sector, TObjArray* arr, Bool_t force)
+AliTPCCalROC* AliTPCCalibCE::GetCalRoc(Int_t sector, TObjArray* arr, Bool_t force) const
 {
     //
     // return pointer to ROC Calibration
@@ -1289,13 +1360,23 @@ AliTPCCalROC* AliTPCCalibCE::GetCalRoc(Int_t sector, TObjArray* arr, Bool_t forc
 AliTPCCalROC* AliTPCCalibCE::GetCalRocT0(Int_t sector, Bool_t force)
 {
     //
-    // return pointer to Carge ROC Calibration
+    // return pointer to Time 0 ROC Calibration
     // if force is true create a new histogram if it doesn't exist allready
     //
     TObjArray *arr = &fCalRocArrayT0;
     return GetCalRoc(sector, arr, force);
 }
 //_____________________________________________________________________
+AliTPCCalROC* AliTPCCalibCE::GetCalRocT0Err(Int_t sector, Bool_t force)
+{
+    //
+    // return pointer to the error of Time 0 ROC Calibration
+    // if force is true create a new histogram if it doesn't exist allready
+    //
+    TObjArray *arr = &fCalRocArrayT0Err;
+    return GetCalRoc(sector, arr, force);
+}
+//_____________________________________________________________________
 AliTPCCalROC* AliTPCCalibCE::GetCalRocQ(Int_t sector, Bool_t force)
 {
     //
@@ -1326,7 +1407,7 @@ AliTPCCalROC* AliTPCCalibCE::GetCalRocOutliers(Int_t sector, Bool_t force)
     return GetCalRoc(sector, arr, force);
 }
 //_____________________________________________________________________
-TObjArray* AliTPCCalibCE::GetParamArray(Int_t sector, TObjArray* arr, Bool_t force)
+TObjArray* AliTPCCalibCE::GetParamArray(Int_t sector, TObjArray* arr, Bool_t force) const
 {
     //
     // return pointer to TObjArray of fit parameters
@@ -1473,8 +1554,8 @@ void AliTPCCalibCE::Merge(AliTPCCalibCE *ce)
             arrPol2->Expand(fNevents+nCEevents);
        }
        if ( vMeanTimeCE && vMeanQCE ){
-           vMeanTime = GetTMeanEvents(iSec);
-           vMeanQCE  = GetQMeanEvents(iSec);
+           vMeanTime = GetTMeanEvents(iSec,kTRUE);
+           vMeanQ    = GetQMeanEvents(iSec,kTRUE);
            vMeanTime->ResizeTo(fNevents+nCEevents);
            vMeanQ->ResizeTo(fNevents+nCEevents);
        }
@@ -1599,21 +1680,27 @@ void AliTPCCalibCE::Analyse()
     TVectorD paramRMS(3);
     TMatrixD dummy(3,3);
 
+    Float_t channelCounter=0;
+    fMeanT0rms=0;
+    fMeanQrms=0;
+    fMeanRMSrms=0;
+
     for (Int_t iSec=0; iSec<72; ++iSec){
        TH2S *hT0 = GetHistoT0(iSec);
         if (!hT0 ) continue;
 
-       AliTPCCalROC *rocQ   = GetCalRocQ  (iSec,kTRUE);
-       AliTPCCalROC *rocT0  = GetCalRocT0 (iSec,kTRUE);
-       AliTPCCalROC *rocRMS = GetCalRocRMS(iSec,kTRUE);
-        AliTPCCalROC *rocOut = GetCalRocOutliers(iSec,kTRUE);
+       AliTPCCalROC *rocQ     = GetCalRocQ  (iSec,kTRUE);
+       AliTPCCalROC *rocT0    = GetCalRocT0 (iSec,kTRUE);
+       AliTPCCalROC *rocT0Err = GetCalRocT0Err (iSec,kTRUE);
+       AliTPCCalROC *rocRMS   = GetCalRocRMS(iSec,kTRUE);
+        AliTPCCalROC *rocOut   = GetCalRocOutliers(iSec,kTRUE);
 
        TH2S *hQ   = GetHistoQ(iSec);
        TH2S *hRMS = GetHistoRMS(iSec);
 
-       Short_t *array_hQ   = hQ->GetArray();
-       Short_t *array_hT0  = hT0->GetArray();
-       Short_t *array_hRMS = hRMS->GetArray();
+       Short_t *arrayhQ   = hQ->GetArray();
+       Short_t *arrayhT0  = hT0->GetArray();
+       Short_t *arrayhRMS = hRMS->GetArray();
 
         UInt_t nChannels = fROC->GetNChannels(iSec);
 
@@ -1629,18 +1716,22 @@ void AliTPCCalibCE::Analyse()
            Float_t cogTime0 = -1000;
            Float_t cogQ     = -1000;
            Float_t cogRMS   = -1000;
-            Float_t cogOut   = 0;
+           Float_t cogOut   = 0;
+            Float_t rms      = 0;
+            Float_t rmsT0    = 0;
 
 
            Int_t offsetQ = (fNbinsQ+2)*(iChannel+1)+1;
            Int_t offsetT0 = (fNbinsT0+2)*(iChannel+1)+1;
            Int_t offsetRMS = (fNbinsRMS+2)*(iChannel+1)+1;
 
-           cogQ     = AliMathBase::GetCOG(array_hQ+offsetQ,fNbinsQ,fXminQ,fXmaxQ);
-           cogTime0 = AliMathBase::GetCOG(array_hT0+offsetT0,fNbinsT0,fXminT0,fXmaxT0);
-            cogRMS   = AliMathBase::GetCOG(array_hRMS+offsetRMS,fNbinsRMS,fXminRMS,fXmaxRMS);
-
-
+           cogQ     = AliMathBase::GetCOG(arrayhQ+offsetQ,fNbinsQ,fXminQ,fXmaxQ,&rms);
+            fMeanQrms+=rms;
+           cogTime0 = AliMathBase::GetCOG(arrayhT0+offsetT0,fNbinsT0,fXminT0,fXmaxT0,&rmsT0);
+            fMeanT0rms+=rmsT0;
+            cogRMS   = AliMathBase::GetCOG(arrayhRMS+offsetRMS,fNbinsRMS,fXminRMS,fXmaxRMS,&rms);
+            fMeanRMSrms+=rms;
+            channelCounter++;
 
            /*
              //outlier specifications
@@ -1653,6 +1744,7 @@ void AliTPCCalibCE::Analyse()
 */
                    rocQ->SetValue(iChannel, cogQ*cogQ);
            rocT0->SetValue(iChannel, cogTime0);
+           rocT0Err->SetValue(iChannel, rmsT0);
            rocRMS->SetValue(iChannel, cogRMS);
            rocOut->SetValue(iChannel, cogOut);
 
@@ -1686,6 +1778,11 @@ void AliTPCCalibCE::Analyse()
        }
 
     }
+    if ( channelCounter>0 ){
+       fMeanT0rms/=channelCounter;
+       fMeanQrms/=channelCounter;
+       fMeanRMSrms/=channelCounter;
+    }
     if ( fDebugStreamer ) fDebugStreamer->GetFile()->Write();
 //    delete fDebugStreamer;
 //    fDebugStreamer = 0x0;