]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCPreprocessorOffline.cxx
Add three particle correlation loop for correction of auto-correlaton bias
[u/mrichter/AliRoot.git] / TPC / AliTPCPreprocessorOffline.cxx
index e34be992ccf7b058f7f62203f7c1efe09987bc6c..54a595c20f02e679ab7a8d4844ee62c3e32de64a 100644 (file)
@@ -75,6 +75,7 @@
 #include "AliTPCParamSR.h"
 #include "AliTPCcalibTimeGain.h"
 #include "AliTPCcalibGainMult.h"
+#include "AliTPCcalibAlign.h"
 #include "AliSplineFit.h"
 #include "AliTPCComposedCorrection.h"
 #include "AliTPCExBTwist.h"
 #include "TChain.h"
 #include "TCut.h"
 #include "AliTrackerBase.h"
+#include "AliTracker.h"
 #include "AliTPCPreprocessorOffline.h"
+#include "AliTPCCorrectionFit.h"
 
-
+using std::endl;
+using std::cout;
 ClassImp(AliTPCPreprocessorOffline)
 
 AliTPCPreprocessorOffline::AliTPCPreprocessorOffline():
   TNamed("TPCPreprocessorOffline","TPCPreprocessorOffline"),
   fMinEntries(500),                      // minimal number of entries for fit
-  startRun(0),                         // start Run - used to make fast selection in THnSparse
-  endRun(0),                           // end   Run - used to make fast selection in THnSparse
-  startTime(0),                        // startTime - used to make fast selection in THnSparse
-  endTime(0),                          // endTime   - used to make fast selection in THnSparse
-  ocdbStorage(""),                   // path to the OCDB storage
+  fStartRun(0),                         // start Run - used to make fast selection in THnSparse
+  fEndRun(0),                           // end   Run - used to make fast selection in THnSparse
+  fStartTime(0),                        // fStartTime - used to make fast selection in THnSparse
+  fEndTime(0),                          // fEndTime   - used to make fast selection in THnSparse
+  fOCDBstorage(0),                       // OCDB storage
   fVdriftArray(new TObjArray),
   fTimeDrift(0),
   fGraphMIP(0),                // graph time dependence of MIP
@@ -111,7 +115,12 @@ AliTPCPreprocessorOffline::AliTPCPreprocessorOffline():
   fSwitchOnValidation(kFALSE), // flag to switch on validation of OCDB parameters
   fMinGain(2.0),
   fMaxGain(3.0),
-  fMaxVdriftCorr(0.03)
+  fMaxVdriftCorr(0.03),
+  fNtracksVdrift(0),
+  fMinTracksVdrift(0),
+  fNeventsVdrift(0),
+  fMinEventsVdrift(0),
+  fCalibrationStatus(0)
 {
   //
   // default constructor
@@ -140,33 +149,33 @@ void AliTPCPreprocessorOffline::GetRunRange(AliTPCcalibTime * const  timeDrift){
     TH1D* histoTime=addHist->Projection(0);
     printf("%s\t%f\t%d\t%d\n",histo->GetName(), histo->GetEntries(),histo->FindFirstBinAbove(0),histo->FindLastBinAbove(0));
 
-    if (startRun<=0){ 
-      startRun=histo->FindFirstBinAbove(0);
-      endRun  =histo->FindLastBinAbove(0);
+    if (fStartRun<=0){ 
+      fStartRun=histo->FindFirstBinAbove(0);
+      fEndRun  =histo->FindLastBinAbove(0);
     }else{
-      startRun=TMath::Min(histo->FindFirstBinAbove(0),startRun);
-      endRun  =TMath::Max(histo->FindLastBinAbove(0),endRun);
+      fStartRun=TMath::Min(histo->FindFirstBinAbove(0),fStartRun);
+      fEndRun  =TMath::Max(histo->FindLastBinAbove(0),fEndRun);
     }
-    if (startTime==0){ 
-      startTime=histoTime->FindFirstBinAbove(0);
-      endTime  =histoTime->FindLastBinAbove(0);
+    if (fStartTime==0){ 
+      fStartTime=histoTime->FindFirstBinAbove(0);
+      fEndTime  =histoTime->FindLastBinAbove(0);
     }else{
-      startTime=TMath::Min(histoTime->FindFirstBinAbove(0),startTime);
-      endTime  =TMath::Max(histoTime->FindLastBinAbove(0),endTime);
+      fStartTime=TMath::Min(histoTime->FindFirstBinAbove(0),fStartTime);
+      fEndTime  =TMath::Max(histoTime->FindLastBinAbove(0),fEndTime);
     }
     delete histo;
     delete histoTime;
   }}
-  if (startRun<0) startRun=0;
-  if (endRun<0) endRun=100000000;
-  printf("Run range  :\t%d-%d\n", startRun, endRun);
-  printf("Time range :\t%d-%d\n", startTime, endTime);
+  if (fStartRun<0) fStartRun=0;
+  if (fEndRun<0) fEndRun=100000000;
+  printf("Run range  :\t%d-%d\n", fStartRun, fEndRun);
+  printf("Time range :\t%d-%d\n", fStartTime, fEndTime);
 
 }
 
 
 
-void AliTPCPreprocessorOffline::CalibTimeVdrift(const Char_t* file, Int_t ustartRun, Int_t uendRun, TString pocdbStorage){
+void AliTPCPreprocessorOffline::CalibTimeVdrift(const Char_t* file, Int_t ustartRun, Int_t uendRun, AliCDBStorage* pocdbStorage){
   //
   // make calibration of the drift velocity
   // Input parameters:
@@ -174,9 +183,12 @@ void AliTPCPreprocessorOffline::CalibTimeVdrift(const Char_t* file, Int_t ustart
   //      ustartRun, uendrun     - run validity period 
   //      pocdbStorage           - path to hte OCDB storage
   //                             - if empty - local storage 'pwd' uesed
-  if (pocdbStorage.Length()>0) ocdbStorage=pocdbStorage;
-  else
-  ocdbStorage="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
+  if (pocdbStorage) fOCDBstorage=pocdbStorage;
+  else {
+    TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB"; 
+    fOCDBstorage=AliCDBManager::Instance()->GetStorage(localStorage.Data());
+  }
+
   //
   // 1. Initialization and run range setting
   TFile fcalib(file);
@@ -188,15 +200,21 @@ void AliTPCPreprocessorOffline::CalibTimeVdrift(const Char_t* file, Int_t ustart
   }
   if(!fTimeDrift) return;
 
-  startRun=ustartRun;
-  endRun=ustartRun; 
+  //extract statistics
+  fNtracksVdrift = TMath::Nint(fTimeDrift->GetResHistoTPCITS(0)->GetEntries());
+  //if we have 0 ITS TPC matches it means we have no ITS tracks and we try to use TPC-TOF matching for calibration
+  if (fNtracksVdrift==0) fNtracksVdrift=TMath::Nint(fTimeDrift->GetResHistoTPCTOF(0)->GetEntries());
+  fNeventsVdrift = TMath::Nint(fTimeDrift->GetTPCVertexHisto(0)->GetEntries());
+
+  fStartRun=ustartRun;
+  fEndRun=ustartRun; 
   TObjArray *hisArray =fTimeDrift->GetHistoDrift();  
   GetRunRange(fTimeDrift);
   for (Int_t i=0; i<hisArray->GetEntriesFast(); i++){
     THnSparse* addHist=(THnSparse*)hisArray->At(i);
     if (!addHist) continue;
-    if (startTime<endTime) addHist->GetAxis(0)->SetRange(startTime-1,endTime+1);
-    if (startRun<endRun) addHist->GetAxis(3)->SetRange(startRun-1,endRun+1);
+    if (fStartTime<fEndTime) addHist->GetAxis(0)->SetRange(fStartTime-1,fEndTime+1);
+    if (fStartRun<fEndRun) addHist->GetAxis(3)->SetRange(fStartRun-1,fEndRun+1);
   }
   //
   //
@@ -206,6 +224,7 @@ void AliTPCPreprocessorOffline::CalibTimeVdrift(const Char_t* file, Int_t ustart
   AddAlignmentGraphs(fVdriftArray,fTimeDrift);
   AddHistoGraphs(fVdriftArray,fTimeDrift,fMinEntries);
   AddLaserGraphs(fVdriftArray,fTimeDrift);
+  
   //
   // 3. Append QA plots
   //
@@ -232,10 +251,10 @@ void AliTPCPreprocessorOffline::CalibTimeVdrift(const Char_t* file, Int_t ustart
   // 5. update of OCDB
   //
   //
-  UpdateOCDBDrift(ustartRun,uendRun,ocdbStorage);
+  UpdateOCDBDrift(ustartRun,uendRun,fOCDBstorage);
 }
 
-void AliTPCPreprocessorOffline::UpdateOCDBDrift( Int_t ustartRun, Int_t uendRun,  const char* storagePath ){
+void AliTPCPreprocessorOffline::UpdateOCDBDrift( Int_t ustartRun, Int_t uendRun,  AliCDBStorage* storage ){
   //
   // Update OCDB 
   //
@@ -247,8 +266,7 @@ void AliTPCPreprocessorOffline::UpdateOCDBDrift( Int_t ustartRun, Int_t uendRun,
   metaData->SetComment("Calibration of the time dependence of the drift velocity");
   AliCDBId* id1=NULL;
   id1=new AliCDBId("TPC/Calib/TimeDrift", ustartRun, uendRun);
-  AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
-  gStorage->Put(fVdriftArray, (*id1), metaData);
+  storage->Put(fVdriftArray, (*id1), metaData);
 }
 
 Bool_t AliTPCPreprocessorOffline::ValidateTimeGain()
@@ -263,16 +281,27 @@ Bool_t AliTPCPreprocessorOffline::ValidateTimeGain()
   TGraphErrors *gr = (TGraphErrors*)fGainArray->FindObject("TGRAPHERRORS_MEAN_GAIN_BEAM_ALL");
   if (!gr) {
     gr = (TGraphErrors*)fGainArray->FindObject("TGRAPHERRORS_MEAN_GAIN_COSMIC_ALL");
-    if (!gr) return kFALSE;
+    if (!gr) 
+    { 
+      fCalibrationStatus |= kCalibFailedTimeGain;
+      return kFALSE;
+    }
     Printf("Assuming given run is a cosmic run. Using gain calibration from Fermi-plateau muons.");
   }
-  if(gr->GetN()<1) return kFALSE;
+  if(gr->GetN()<1) 
+  { 
+    fCalibrationStatus |= kCalibFailedTimeGain;
+    return kFALSE;
+  }
 
   // check whether gain in the range
   for(Int_t iPoint=0; iPoint<gr->GetN(); iPoint++) 
   {
     if(gr->GetY()[iPoint] < minGain || gr->GetY()[iPoint] > maxGain)  
+    { 
+      fCalibrationStatus |= kCalibFailedTimeGain;
       return kFALSE;
+    }
   }
 
 return kTRUE;
@@ -290,19 +319,43 @@ Bool_t AliTPCPreprocessorOffline::ValidateTimeDrift()
 
   TGraphErrors* gr = (TGraphErrors*)fVdriftArray->FindObject("ALIGN_ITSB_TPC_DRIFTVD");
   Printf("ALIGN_ITSB_TPC_DRIFTVD graph = %p",gr);
+  if (!gr)
+  {
+    gr = (TGraphErrors*)fVdriftArray->FindObject("ALIGN_TOFB_TPC_DRIFTVD");
+    Printf("ALIGN_TOFB_TPC_DRIFTVD graph = %p",gr);
+  }
+
+  if(!gr) 
+  {
+    fCalibrationStatus|=kCalibFailedTimeDrift;
+    return kFALSE;
+  }
+  
+  // for now we validate even with low statistics
+  ////check if we have enough statistics
+  //if (fNtracksVdrift<fMinTracksVdrift) 
+  //{
+  //  fCalibrationStatus|=kCalibFailedTimeDrift;
+  //  return kFALSE;
+  //}
 
-  if(!gr) return kFALSE;
   if(gr->GetN()<1)  { 
     Printf("ALIGN_ITSB_TPC_DRIFTVD number of points = %d",gr->GetN());
-    return kFALSE;
+    {
+      fCalibrationStatus|=kCalibFailedTimeDrift;
+      return kFALSE;
+    }
   }
 
   // check whether drift velocity corrections in the range
   for(Int_t iPoint = 0; iPoint<gr->GetN(); iPoint++) 
   {
-    Printf("Y value from the graph: %f",TMath::Abs(gr->GetY()[iPoint]));
+    //Printf("Y value from the graph: %f",TMath::Abs(gr->GetY()[iPoint]));
     if(TMath::Abs(gr->GetY()[iPoint]) > maxVDriftCorr)  
+    {
+      fCalibrationStatus|=kCalibFailedTimeDrift;
       return kFALSE;
+    }
   }
 
 return kTRUE;
@@ -329,8 +382,7 @@ void AliTPCPreprocessorOffline::UpdateDriftParam(AliTPCParam *param, TObjArray *
   metaData->SetComment("Updated calibration of nominal time 0");
   AliCDBId* id1=NULL;
   id1=new AliCDBId("TPC/Calib/Parameters", lstartRun, AliCDBRunRange::Infinity());
-  AliCDBStorage* gStorage = AliCDBManager::Instance()->GetStorage(ocdbStorage);
-  gStorage->Put(param, (*id1), metaData);
+  fOCDBstorage->Put(param, (*id1), metaData);
 
 }
 
@@ -494,9 +546,9 @@ void AliTPCPreprocessorOffline::AddAlignmentGraphs(  TObjArray * vdriftArray, Al
   arrayTRD=timeDrift->GetAlignTRDTPC();
   arrayTOF=timeDrift->GetAlignTOFTPC();
 
-  if (arrayITS->GetEntries()>0) mstatITS= AliTPCcalibDButil::MakeStatRelKalman(arrayITS,0.9,50,fMaxVdriftCorr);
-  if (arrayTOF->GetEntries()>0) mstatTOF= AliTPCcalibDButil::MakeStatRelKalman(arrayTOF,0.9,1000,fMaxVdriftCorr);
-  if (arrayTRD->GetEntries()>0) mstatTRD= AliTPCcalibDButil::MakeStatRelKalman(arrayTRD,0.9,50,fMaxVdriftCorr);
+  if (arrayITS->GetEntries()>0) mstatITS= AliTPCcalibDButil::MakeStatRelKalman(arrayITS,0.7,50,fMaxVdriftCorr);
+  if (arrayTOF->GetEntries()>0) mstatTOF= AliTPCcalibDButil::MakeStatRelKalman(arrayTOF,0.7,1000,fMaxVdriftCorr);
+  if (arrayTRD->GetEntries()>0) mstatTRD= AliTPCcalibDButil::MakeStatRelKalman(arrayTRD,0.7,50,fMaxVdriftCorr);
   //
   TObjArray * arrayITSP= AliTPCcalibDButil::SmoothRelKalman(arrayITS,*mstatITS, 0, 5.);
   TObjArray * arrayITSM= AliTPCcalibDButil::SmoothRelKalman(arrayITS,*mstatITS, 1, 5.);
@@ -820,11 +872,14 @@ void AliTPCPreprocessorOffline::MakeDefaultPlots(TObjArray * const arr, TObjArra
 
 
 
-void AliTPCPreprocessorOffline::CalibTimeGain(const Char_t* fileName, Int_t startRunNumber, Int_t endRunNumber,  TString  pocdbStorage){
+void AliTPCPreprocessorOffline::CalibTimeGain(const Char_t* fileName, Int_t startRunNumber, Int_t endRunNumber,  AliCDBStorage* pocdbStorage){
   //
   // Update OCDB gain
   //
-  if (pocdbStorage.Length()==0) pocdbStorage+="local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
+  if (pocdbStorage==0) {
+    TString localStorage = "local://"+gSystem->GetFromPipe("pwd")+"/OCDB";
+    pocdbStorage = AliCDBManager::Instance()->GetStorage(localStorage.Data());
+  }
 
   //
   // 1. Read gain values
@@ -838,6 +893,7 @@ void AliTPCPreprocessorOffline::CalibTimeGain(const Char_t* fileName, Int_t star
   AnalyzeAttachment(startRunNumber,endRunNumber);
   AnalyzePadRegionGain();
   AnalyzeGainMultiplicity();
+  AnalyzeGainChamberByChamber();
   //
   // 3. Make control plots
   //
@@ -854,7 +910,7 @@ void AliTPCPreprocessorOffline::CalibTimeGain(const Char_t* fileName, Int_t star
   //
   // 5. Update OCDB
   //
-  UpdateOCDBGain( startRunNumber, endRunNumber, pocdbStorage.Data());
+  UpdateOCDBGain( startRunNumber, endRunNumber, pocdbStorage);
 }
 
 void AliTPCPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
@@ -873,8 +929,8 @@ void AliTPCPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
     fGainMult   = ( AliTPCcalibGainMult *)fcalib.Get("calibGainMult");
   }
   if (!fGainMult){
-    TFile fcalibMult("TPCMultObjects.root");
-    fGainMult   = ( AliTPCcalibGainMult *)fcalibMult.Get("calibGainMult");
+    TFile calibMultFile("TPCMultObjects.root");
+    fGainMult   = ( AliTPCcalibGainMult *)calibMultFile.Get("calibGainMult");
   }
   TH1 * hisT=0;
   Int_t firstBinA =0, lastBinA=0;
@@ -897,8 +953,6 @@ void AliTPCPreprocessorOffline::ReadGainGlobal(const Char_t* fileName){
 
 }
 
-
-
 Bool_t AliTPCPreprocessorOffline::AnalyzeGain(Int_t startRunNumber, Int_t endRunNumber, Int_t minEntriesGaussFit,  Float_t FPtoMIPratio){
   //
   // Analyze gain - produce the calibration graphs
@@ -1143,8 +1197,29 @@ Bool_t AliTPCPreprocessorOffline::AnalyzeGainMultiplicity() {
 
 }
 
+Bool_t AliTPCPreprocessorOffline::AnalyzeGainChamberByChamber(){
+  //
+  // get chamber by chamber gain
+  //
+  if (!fGainMult) return kFALSE;
+  TGraphErrors *grShort  = fGainMult->GetGainPerChamber(0);
+  TGraphErrors *grMedium = fGainMult->GetGainPerChamber(1);
+  TGraphErrors *grLong   = fGainMult->GetGainPerChamber(2);
+  if (grShort==0x0 || grMedium==0x0 || grLong==0x0) {
+    delete grShort;
+    delete grMedium;
+    delete grLong;
+    return kFALSE;
+  }
 
-void AliTPCPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, const Char_t *storagePath){
+  fGainArray->AddLast(grShort);
+  fGainArray->AddLast(grMedium);
+  fGainArray->AddLast(grLong);
+
+  return kTRUE;
+}
+
+void AliTPCPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRunNumber, AliCDBStorage *storage){
   //
   // Update OCDB entry
   //
@@ -1155,8 +1230,7 @@ void AliTPCPreprocessorOffline::UpdateOCDBGain(Int_t startRunNumber, Int_t endRu
   metaData->SetAliRootVersion("05-24-00"); //root version
   metaData->SetComment("Calibration of the time dependence of the gain due to pressure and temperature changes.");
   AliCDBId id1("TPC/Calib/TimeGain", startRunNumber, endRunNumber);
-  AliCDBStorage * gStorage = AliCDBManager::Instance()->GetStorage(storagePath);
-  gStorage->Put(fGainArray, id1, metaData);    
+  storage->Put(fGainArray, id1, metaData);    
 }
 
 void AliTPCPreprocessorOffline::MakeQAPlot(Float_t  FPtoMIPratio) {
@@ -1217,7 +1291,7 @@ void AliTPCPreprocessorOffline::MakeQAPlot(Float_t  FPtoMIPratio) {
 
 void AliTPCPreprocessorOffline::MakeFitTime(){
   //
-  // mak aligment fit - store results in the file
+  // make aligment fit - store results in the file
   //
   const Int_t kMinEntries=1000;
   MakeChainTime();
@@ -1256,7 +1330,7 @@ void AliTPCPreprocessorOffline::MakeFitTime(){
   fstringFast+="dITS*FAlignRot1++";
   fstringFast+="dITS*FAlignRot2++";
   
-  TCut cutFit="entries>10&&abs(mean)>0.00001";
+  TCut cutFit="entries>10&&abs(mean)>0.00001&&rms>0";
   fAlignTree->SetAlias("err","rms");
 
   TString *strDeltaITS = TStatToolkit::FitPlaneConstrain(fAlignTree,"mean:err", fstringFast.Data(),cutFit, chi2,npoints,param,covar,-1,0, npointsMax, 1);
@@ -1278,14 +1352,24 @@ void AliTPCPreprocessorOffline::MakeFitTime(){
 
 
 void AliTPCPreprocessorOffline::MakeChainTime(){
+  //
+  //
   //
   TFile f("CalibObjects.root");
+  
   //  const char *cdtype[7]={"ITS","TRD","Vertex","TOF","TPC","TPC0","TPC1"};
   //const char *cptype[5]={"dy","dz","dsnp","dtheta","d1pt"}; 
   const char * hname[5]={"dy","dz","dsnp","dtheta","d1pt"};
   Int_t run=0;
-  AliTPCcalibTime  *calibTime= (AliTPCcalibTime*) f.Get("calibTime");
+  AliTPCcalibTime  *calibTime = 0;
+  TObjArray * array = (TObjArray*)f.Get("TPCCalib");
+  if (array){
+    calibTime = (AliTPCcalibTime *)array->FindObject("calibTime");
+  } else {
+    calibTime = (AliTPCcalibTime*)f.Get("calibTime");
+  }
   if (!calibTime) return;
+  AliTPCCorrectionFit::CreateAlignMaps(AliTracker::GetBz(), run);
   TTreeSRedirector *pcstream = new TTreeSRedirector("meanITSVertex.root");
   //
   Int_t ihis=0;
@@ -1294,7 +1378,7 @@ void AliTPCPreprocessorOffline::MakeChainTime(){
     his->GetAxis(1)->SetRangeUser(-1.1,1.1);
     his->GetAxis(2)->SetRange(0,1000000);
     his->GetAxis(3)->SetRangeUser(-0.35,0.35);
-    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("ITS%s",hname[ihis]),run,85.,ihis,5);
+    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("ITS%s",hname[ihis]),run,85.,ihis,3);
   }
   ihis=1;
   his = calibTime->GetResHistoTPCITS(ihis);
@@ -1302,7 +1386,7 @@ void AliTPCPreprocessorOffline::MakeChainTime(){
     his->GetAxis(1)->SetRangeUser(-1.1,1.1);
     his->GetAxis(2)->SetRange(0,1000000);
     his->GetAxis(3)->SetRangeUser(-0.35,0.35);
-    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("ITS%s",hname[ihis]),run,85.,ihis,5);
+    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("ITS%s",hname[ihis]),run,85.,ihis,3);
   }
   ihis=2;
   his = calibTime->GetResHistoTPCITS(ihis);
@@ -1310,7 +1394,7 @@ void AliTPCPreprocessorOffline::MakeChainTime(){
     his->GetAxis(1)->SetRangeUser(-1.1,1.1);
     his->GetAxis(2)->SetRange(0,1000000);
     his->GetAxis(3)->SetRangeUser(-0.35,0.35);
-    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("ITS%s",hname[ihis]),run,85.,ihis,5);
+    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("ITS%s",hname[ihis]),run,85.,ihis,3);
   }
   ihis=0;
   his = calibTime->GetResHistoTPCvertex(ihis);
@@ -1318,7 +1402,7 @@ void AliTPCPreprocessorOffline::MakeChainTime(){
     his->GetAxis(1)->SetRangeUser(-1.1,1.1);
     his->GetAxis(2)->SetRange(0,1000000);
     his->GetAxis(3)->SetRangeUser(-0.35,0.35);
-    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("Vertex%s",hname[ihis]),run,0.,ihis,5);
+    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("Vertex%s",hname[ihis]),run,0.,ihis,3);
   }
   ihis=2;
   his = calibTime->GetResHistoTPCvertex(ihis);
@@ -1326,7 +1410,7 @@ void AliTPCPreprocessorOffline::MakeChainTime(){
     his->GetAxis(1)->SetRangeUser(-1.1,1.1);
     his->GetAxis(2)->SetRange(0,1000000);
     his->GetAxis(3)->SetRangeUser(-0.35,0.35);
-    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("Vertex%s",hname[ihis]),run,0.,ihis,5);
+    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("Vertex%s",hname[ihis]),run,0.,ihis,3);
 
   }
   ihis=1;
@@ -1335,7 +1419,7 @@ void AliTPCPreprocessorOffline::MakeChainTime(){
     his->GetAxis(1)->SetRangeUser(-1.1,1.1);
     his->GetAxis(2)->SetRange(0,1000000);
     his->GetAxis(3)->SetRangeUser(-0.35,0.35);
-    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("Vertex%s",hname[ihis]),run,0.,ihis,5);
+    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("Vertex%s",hname[ihis]),run,0.,ihis,3);
 
   }
   ihis=0;
@@ -1344,7 +1428,7 @@ void AliTPCPreprocessorOffline::MakeChainTime(){
     his->GetAxis(1)->SetRangeUser(-1.1,1.1);
     his->GetAxis(2)->SetRange(0,1000000);
     his->GetAxis(3)->SetRangeUser(-0.35,0.35);
-    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("TOF%s",hname[ihis]),run,0.,ihis,10);
+    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("TOF%s",hname[ihis]),run,0.,ihis,3);
 
   }
   ihis=0;
@@ -1353,7 +1437,7 @@ void AliTPCPreprocessorOffline::MakeChainTime(){
     his->GetAxis(1)->SetRangeUser(-1.1,1.1);
     his->GetAxis(2)->SetRange(0,1000000);
     his->GetAxis(3)->SetRangeUser(-0.35,0.35);
-    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("TRD%s",hname[ihis]),run,0.,ihis,10);
+    AliTPCCorrection::MakeDistortionMap(his,pcstream, Form("TRD%s",hname[ihis]),run,0.,ihis,3);
 
   }
   delete pcstream;
@@ -1374,6 +1458,46 @@ Double_t AliTPCPreprocessorOffline::EvalAt(Double_t phi, Double_t refX, Double_t
 }
 
 
+Double_t AliTPCPreprocessorOffline::EvalAtPar(Double_t phi0, Double_t snp, Double_t refX, Double_t theta, Int_t corr, Int_t ptype, Int_t nsteps){
+  //
+  // Fit the distortion along the line with the parabolic model
+  // Parameters:
+  //  phi0 - phi at the entrance of the TPC
+  //  snp  - local inclination angle at the entrance of the TPC
+  //  refX - ref X where the distortion is evanluated
+  //  theta
+  //  
+  static TLinearFitter fitter(3,"pol2"); 
+  fitter.ClearPoints();
+  if (nsteps<3) nsteps=3;
+  Double_t deltaX=(245-85)/(nsteps);
+  for (Int_t istep=0; istep<(nsteps+1); istep++){
+    //
+    Double_t localX =85.+deltaX*istep;
+    Double_t localPhi=phi0+deltaX*snp*istep;
+    Double_t sector = 9*localPhi/TMath::Pi();
+    if (sector<0) sector+=18;
+    Double_t y=AliTPCCorrection::GetCorrSector(sector,localX,theta,1,corr);
+    Double_t dlocalX=AliTPCCorrection::GetCorrSector(sector,localX,theta,0,corr);
+    Double_t x[1]={localX-dlocalX};
+    fitter.AddPoint(x,y);
+  }
+  fitter.Eval();
+  Double_t par[3];
+  par[0]=fitter.GetParameter(0);
+  par[1]=fitter.GetParameter(1);
+  par[2]=fitter.GetParameter(2);
+
+  if (ptype==0) return par[0]+par[1]*refX+par[2]*refX*refX;
+  if (ptype==2) return par[1]+2*par[2]*refX;
+  if (ptype==4) return par[2];
+  return 0;
+}
+
+
+
+
+
 
 void AliTPCPreprocessorOffline::MakePrimitivesTime(){
   //
@@ -1566,6 +1690,21 @@ void AliTPCPreprocessorOffline::CreateAlignTime(TString fstring, TVectorD paramC
   f->Close();
 }
 
+//_____________________________________________________________________________
+Int_t AliTPCPreprocessorOffline::GetStatus()
+{
+  //get the calibration status
+  // 0 means OK
+  // positive numbers invalidate for unknown reasons.
+  // negative numbers invalidate with a known reason (e.g. low statistics).
+  // the returned integer has one bit set for every component that failed.
 
+  Bool_t enoughStatistics = (fNtracksVdrift>fMinTracksVdrift && fNeventsVdrift>fMinEventsVdrift);
+  
+  if (!enoughStatistics) 
+  {
+    fCalibrationStatus=-TMath::Abs(fCalibrationStatus);
+  }
 
-
+  return fCalibrationStatus;
+}