]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDCalibraFillHisto.cxx
AliDCSClient "multiSplit" option added in the DCS configuration
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFillHisto.cxx
index cffb941b6a0cbc725263560a7cbcf6d00dcaf169..57b1063b7f528d819e6b32021ce47e4964c68b17 100644 (file)
@@ -42,6 +42,7 @@
 #include <TCanvas.h>
 #include <TGraphErrors.h>
 #include <TObjArray.h>
+#include <TObject.h>
 #include <TH1F.h>
 #include <TH2I.h>
 #include <TH2.h>
 #include <TROOT.h>
 #include <TTreeStream.h>
 #include <TVectorD.h>
+#include <TF1.h>
 
 #include "AliLog.h"
 #include "AliCDBManager.h"
-#include "AliRawReader.h"
-#include "AliRawReaderDate.h"
 
 #include "AliTRDCalibraFillHisto.h"
+#include "AliTRDCalibraFit.h"
 #include "AliTRDCalibraMode.h"
 #include "AliTRDCalibraVector.h"
+#include "AliTRDCalibraVdriftLinearFit.h"
 #include "AliTRDcalibDB.h"
 #include "AliTRDCommonParam.h"
 #include "AliTRDmcmTracklet.h"
 #include "AliTRDpadPlane.h"
 #include "AliTRDcluster.h"
 #include "AliTRDtrack.h"
-#include "AliTRDRawStream.h"
+#include "AliTRDRawStreamV2.h"
+#include "AliRawReader.h"
+#include "AliRawReaderDate.h"
 #include "AliTRDgeometry.h"
+#include "./Cal/AliTRDCalROC.h"
+#include "./Cal/AliTRDCalDet.h"
 
 #ifdef ALI_DATE
 #include "event.h"
 #endif
 
+
 ClassImp(AliTRDCalibraFillHisto)
 
 AliTRDCalibraFillHisto* AliTRDCalibraFillHisto::fgInstance = 0;
@@ -113,6 +120,7 @@ void AliTRDCalibraFillHisto::Terminate()
   }
 
 }
+
 //______________________________________________________________________________________
 AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
   :TObject()
@@ -160,8 +168,12 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
   ,fPH2d(0x0)
   ,fPRF2d(0x0)
   ,fCH2d(0x0)
-  ,fLinearFitterArray(0)
-  ,fLinearFitterHistoArray(0)
+  ,fLinearFitterArray(540)
+  ,fLinearVdriftFit(0x0)
+  ,fCalDetGain(0x0)
+  ,fCalROCGain(0x0)
+  ,fCalDetT0(0x0)
+  ,fCalROCT0(0x0)
 {
   //
   // Default constructor
@@ -175,9 +187,9 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto()
   fNumberUsedCh[1]       = 0;
   fNumberUsedPh[0]       = 0;
   fNumberUsedPh[1]       = 0;
-
+  
   fGeo = new AliTRDgeometry();
+
 }
 
 //______________________________________________________________________________________
@@ -211,24 +223,28 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
   ,fNumberBinPRF(c.fNumberBinPRF)
   ,fNgroupprf(c.fNgroupprf)
   ,fListClusters(new TObjArray())
-  ,fPar0(c.fPar0)
-  ,fPar1(c.fPar1)
-  ,fPar2(c.fPar2)
-  ,fPar3(c.fPar3)
-  ,fPar4(c.fPar4)
-  ,fAmpTotal(c.fAmpTotal)
-  ,fPHPlace(c.fPHPlace)
-  ,fPHValue(c.fPHValue)
+  ,fPar0(0x0)
+  ,fPar1(0x0)
+  ,fPar2(0x0)
+  ,fPar3(0x0)
+  ,fPar4(0x0)
+  ,fAmpTotal(0x0)
+  ,fPHPlace(0x0)
+  ,fPHValue(0x0)
   ,fGoodTracklet(c.fGoodTracklet)
   ,fGoodTrack(c.fGoodTrack)
-  ,fEntriesCH(c.fEntriesCH)
-  ,fEntriesLinearFitter(fEntriesLinearFitter)
+  ,fEntriesCH(0x0)
+  ,fEntriesLinearFitter(0x0)
   ,fCalibraVector(0x0)
   ,fPH2d(0x0)
   ,fPRF2d(0x0)
   ,fCH2d(0x0)
-  ,fLinearFitterArray(0)
-  ,fLinearFitterHistoArray(0)
+  ,fLinearFitterArray(540)
+  ,fLinearVdriftFit(0x0)
+  ,fCalDetGain(0x0)
+  ,fCalROCGain(0x0)
+  ,fCalDetT0(0x0)
+  ,fCalROCT0(0x0)
 {
   //
   // Copy constructor
@@ -247,29 +263,19 @@ AliTRDCalibraFillHisto::AliTRDCalibraFillHisto(const AliTRDCalibraFillHisto &c)
     fCH2d = new TH2I(*c.fCH2d);
     fCH2d->SetDirectory(0);
   }
-  if(c.fLinearFitterOn){
-    fLinearFitterArray.Expand(540);
-    for (Int_t cb = 0; cb < 540; cb++){
-      const TLinearFitter *linearFitter = (TLinearFitter*)c.fLinearFitterArray.UncheckedAt(cb);
-      if ( linearFitter != 0x0 ) fLinearFitterArray.AddAt(new TLinearFitter(*linearFitter), cb);
-    }
-  }
-  if(c.fLinearFitterDebugOn){
-    fLinearFitterHistoArray.Expand(540);
-    for (Int_t cb = 0; cb < 540; cb++){
-      const TH2F *linearfitterhisto = (TH2F*)c.fLinearFitterHistoArray.UncheckedAt(cb);
-      if ( linearfitterhisto != 0x0 ){
-       TH2F *hNew = new TH2F(*linearfitterhisto);
-       hNew->SetDirectory(0);
-       fLinearFitterHistoArray.AddAt(hNew,cb);
-      }
-    }
+  if(c.fLinearVdriftFit){
+    fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit(*c.fLinearVdriftFit);
   }
+
+  if(c.fCalDetGain)  fCalDetGain   = new AliTRDCalDet(*c.fCalDetGain);
+  if(c.fCalDetT0)    fCalDetT0     = new AliTRDCalDet(*c.fCalDetT0);
+  if(c.fCalROCGain)  fCalROCGain   = new AliTRDCalROC(*c.fCalROCGain);
+  if(c.fCalROCT0)    fCalROCT0     = new AliTRDCalROC(*c.fCalROCT0);
+
   if (fGeo) {
     delete fGeo;
   }
   fGeo = new AliTRDgeometry();
-
 }
 
 //____________________________________________________________________________________
@@ -282,6 +288,11 @@ AliTRDCalibraFillHisto::~AliTRDCalibraFillHisto()
   ClearHistos();
   if ( fDebugStreamer ) delete fDebugStreamer;
 
+  if ( fCalDetGain )  delete fCalDetGain;
+  if ( fCalDetT0 )    delete fCalDetT0;
+  if ( fCalROCGain )  delete fCalROCGain;
+  if ( fCalROCT0 )    delete fCalROCT0; 
+
   if (fGeo) {
     delete fGeo;
   }
@@ -321,8 +332,9 @@ void AliTRDCalibraFillHisto::ClearHistos()
     delete fPRF2d;
     fPRF2d = 0x0;
   }
-
+  
 }
+
 //____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
 Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
 {
@@ -332,6 +344,34 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
   // Init the calibration mode (Nz, Nrphi), the 2D histograms if fHisto2d = kTRUE, 
   //
 
+  Init2Dhistostrack();
+  
+  //Init the tracklet parameters
+  fPar0 = new Double_t[fTimeMax];
+  fPar1 = new Double_t[fTimeMax];
+  fPar2 = new Double_t[fTimeMax];
+  fPar3 = new Double_t[fTimeMax];
+  fPar4 = new Double_t[fTimeMax];
+  
+  for(Int_t k = 0; k < fTimeMax; k++){
+    fPar0[k] = 0.0;
+    fPar1[k] = 0.0;
+    fPar2[k] = 0.0;
+    fPar3[k] = 0.0;
+    fPar4[k] = 0.0;
+  }
+  return kTRUE;
+}
+
+//____________Functions for initialising the AliTRDCalibraFillHisto in the code_________
+Bool_t AliTRDCalibraFillHisto::Init2Dhistostrack()
+{
+  //
+  // For the offline tracking
+  // This function will be called in the function AliReconstruction::Run() 
+  // Init the calibration mode (Nz, Nrphi), the 2D histograms if fHisto2d = kTRUE, 
+  //
+
   // DB Setting
   // Get cal
   AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
@@ -349,24 +389,20 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
   fTimeMax = cal->GetNumberOfTimeBins();
   fSf      = parCom->GetSamplingFrequency();
   fRelativeScale = 20;
-
-  //Init the tracklet parameters
-  fPar0 = new Double_t[fTimeMax];
-  fPar1 = new Double_t[fTimeMax];
-  fPar2 = new Double_t[fTimeMax];
-  fPar3 = new Double_t[fTimeMax];
-  fPar4 = new Double_t[fTimeMax];
-  
-  for(Int_t k = 0; k < fTimeMax; k++){
-    fPar0[k] = 0.0;
-    fPar1[k] = 0.0;
-    fPar2[k] = 0.0;
-    fPar3[k] = 0.0;
-    fPar4[k] = 0.0;
-  }
-  
-  //If vector method On initialised all the stuff
-  if(fVector2d){
+  //calib object from database used for reconstruction
+  if(fCalDetGain) delete fCalDetGain;
+  fCalDetGain  = new AliTRDCalDet(*(cal->GetGainFactorDet()));
+  if(fCalDetT0)   delete fCalDetT0;
+  fCalDetT0   = new AliTRDCalDet(*(cal->GetT0Det()));
+
+  // Calcul Xbins Chambd0, Chamb2
+  Int_t Ntotal0 = CalculateTotalNumberOfBins(0);
+  Int_t Ntotal1 = CalculateTotalNumberOfBins(1);
+  Int_t Ntotal2 = CalculateTotalNumberOfBins(2);
+
+  // If vector method On initialised all the stuff
+  if(fVector2d){   
     fCalibraVector = new AliTRDCalibraVector();
     fCalibraVector->SetNumberBinCharge(fNumberBinCharge);
     fCalibraVector->SetTimeMax(fTimeMax);
@@ -378,6 +414,27 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
       fCalibraVector->SetNumberBinPRF(fNumberBinPRF);
       fCalibraVector->SetPRFRange(1.5);
     }
+    for(Int_t k = 0; k < 3; k++){
+      fCalibraVector->SetDetCha0(k,fCalibraMode->GetDetChamb0(k));
+      fCalibraVector->SetDetCha2(k,fCalibraMode->GetDetChamb2(k));
+    }
+    TString namech("Nz");
+    namech += fCalibraMode->GetNz(0);
+    namech += "Nrphi";
+    namech += fCalibraMode->GetNrphi(0);
+    fCalibraVector->SetNameCH((const char* ) namech);
+    TString nameph("Nz");
+    nameph += fCalibraMode->GetNz(1);
+    nameph += "Nrphi";
+    nameph += fCalibraMode->GetNrphi(1);
+    fCalibraVector->SetNamePH((const char* ) nameph);
+    TString nameprf("Nz");
+    nameprf += fCalibraMode->GetNz(2);
+    nameprf += "Nrphi";
+    nameprf += fCalibraMode->GetNrphi(2);
+    nameprf += "Ngp";
+    nameprf += fNgroupprf;
+    fCalibraVector->SetNamePRF((const char* ) nameprf);
   }
  
   // Create the 2D histos corresponding to the pad groupCalibration mode
@@ -387,8 +444,6 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
                 ,fCalibraMode->GetNz(0)
                 ,fCalibraMode->GetNrphi(0)));
     
-    // Calcul the number of Xbins
-    Int_t Ntotal0 = CalculateTotalNumberOfBins(0);
     // Create the 2D histo
     if (fHisto2d) {
       CreateCH2d(Ntotal0);
@@ -403,6 +458,7 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
     for(Int_t k = 0; k < Ntotal0; k++){
       fEntriesCH[k] = 0;
     }
+    
   }
   if (fPH2dOn) {
 
@@ -410,8 +466,6 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
                 ,fCalibraMode->GetNz(1)
                 ,fCalibraMode->GetNrphi(1)));
     
-    // Calcul the number of Xbins
-    Int_t Ntotal1 = CalculateTotalNumberOfBins(1);
     // Create the 2D histo
     if (fHisto2d) {
       CreatePH2d(Ntotal1);
@@ -427,16 +481,13 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
     }
   }
   if (fLinearFitterOn) {
-    fLinearFitterArray.Expand(540);
+    //fLinearFitterArray.Expand(540);
     fLinearFitterArray.SetName("ArrayLinearFitters");
     fEntriesLinearFitter = new Int_t[540];
     for(Int_t k = 0; k < 540; k++){
       fEntriesLinearFitter[k] = 0;
     }
-    if(fLinearFitterDebugOn) {
-      fLinearFitterHistoArray.Expand(540);
-      fLinearFitterHistoArray.SetName("ArrayHistos");
-    }
+    fLinearVdriftFit = new AliTRDCalibraVdriftLinearFit();
   }
 
   if (fPRF2dOn) {
@@ -444,9 +495,6 @@ Bool_t AliTRDCalibraFillHisto::Init2Dhistos()
     AliInfo(Form("The pad calibration mode for the PRF calibration: Nz %d, and Nrphi %d"
                 ,fCalibraMode->GetNz(2)
                 ,fCalibraMode->GetNrphi(2)));
-    
-    // Calcul the number of Xbins
-    Int_t Ntotal2 = CalculateTotalNumberOfBins(2);
     // Create the 2D histo
     if (fHisto2d) {
       CreatePRF2d(Ntotal2);
@@ -470,7 +518,7 @@ Bool_t AliTRDCalibraFillHisto::ResetTrack()
   //
   
   fDetectorAliTRDtrack = kFALSE;
-  fGoodTrack           = kTRUE;
+  //fGoodTrack           = kTRUE;
   return kTRUE;
 
 }
@@ -493,7 +541,16 @@ void AliTRDCalibraFillHisto::ResetfVariables()
     fPar4[k] = 0.0;
   }
 
-    
+  ResetfVariablestrack();
+  
+}
+//____________Offine tracking in the AliTRDtracker_____________________________
+void AliTRDCalibraFillHisto::ResetfVariablestrack()
+{
+  //
+  // Reset values per tracklet
+  //
+
   //Reset good tracklet
   fGoodTracklet = kTRUE;
 
@@ -512,7 +569,152 @@ void AliTRDCalibraFillHisto::ResetfVariables()
       fAmpTotal[k] = 0.0;
     }
   }
+}
+//____________Offline tracking in the AliTRDtracker____________________________
+Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDtrack *t)
+{
+  //
+  // For the offline tracking
+  // This function will be called in the function
+  // AliTRDtracker::FollowBackPropagation() in the loop over the clusters
+  // of TRD tracks 
+  // Fill the 2D histos or the vectors with the info of the clusters at
+  // the end of a detectors if the track is "good"
+  //
+
+
+  
+  AliTRDcluster *cl = 0x0;
+  Int_t index0 = 0;
+  Int_t index1 = 0;
+  
+  // reset if good track
+  fGoodTrack = kTRUE;
+
+  
+  // loop over the clusters
+  while((cl = t->GetCluster(index1))){
+
+    // Localisation of the detector
+    Int_t detector = cl->GetDetector();
+
+   
+    // Fill the infos for the previous clusters if not the same
+    // detector anymore but this time it should be the same track
+    if ((detector != fDetectorPreviousTrack) && 
+       (index0 != index1)) {
+      
+      fNumberTrack++;   
+         
+      //printf("detector %d, fPreviousdetector %d, plane %d, planeprevious %d, index0 %d, index1 %d la\n",detector,fDetectorPreviousTrack,GetPlane(detector),GetPlane(fDetectorPreviousTrack),index0,index1);
+
+      //If the same track, then look if the previous detector is in
+      //the same plane, if yes: not a good track
+      //FollowBack
+      //if (fDetectorAliTRDtrack && 
+      // (GetPlane(detector) <= GetPlane(fDetectorPreviousTrack))) {
+      //Follow
+      if ((GetPlane(detector) >= GetPlane(fDetectorPreviousTrack))) {
+       fGoodTrack = kFALSE;
+      }
+      
+      // Fill only if the track doesn't touch a masked pad or doesn't
+      // appear in the middle (fGoodTrack)
+      if (fGoodTrack && fGoodTracklet) {
+       
+       // drift velocity unables to cut bad tracklets 
+       Bool_t  pass = FindP1TrackPHtrack(t,index0,index1);
+       
+       // Gain calibration
+       if (fCH2dOn) {
+         FillTheInfoOfTheTrackCH();
+       }
+       
+       // PH calibration
+       if (fPH2dOn) {
+         FillTheInfoOfTheTrackPH();    
+       }
+       
+       if(pass && fPRF2dOn) HandlePRFtrack(t,index0,index1);
+       
+       
+      } // if a good track
+      // reset stuff     
+      ResetfVariablestrack();
+      index0 = index1;
+   
+    } // Fill at the end the charge
+    
+    // Calcul the position of the detector and take the calib objects
+    if (detector != fDetectorPreviousTrack) {
+      
+      //Localise the detector
+      LocalisationDetectorXbins(detector);
+      
+      // Get cal
+      AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
+      if (!cal) {
+       AliInfo("Could not get calibDB");
+       return kFALSE;
+      }
+      
+      // Get calib objects
+      if( fCalROCGain ) delete fCalROCGain;
+      fCalROCGain = new AliTRDCalROC(*(cal->GetGainFactorROC(detector)));
+      if( fCalROCT0 )   delete fCalROCT0;
+      fCalROCT0   = new AliTRDCalROC(*(cal->GetT0ROC(detector)));
+      
+    }
+    
+    // Reset the detectbjobsor
+    fDetectorPreviousTrack = detector;
+
+    // Store the info bis of the tracklet
+    Int_t *rowcol   = CalculateRowCol(cl);
+    CheckGoodTracklet(detector,rowcol);
+    Int_t     group[2] = {0,0};
+    if(fCH2dOn)  group[0]  = CalculateCalibrationGroup(0,rowcol);
+    if(fPH2dOn)  group[1]  = CalculateCalibrationGroup(1,rowcol);
+    StoreInfoCHPHtrack(cl,t,index1,group,rowcol);
+         
+    index1++;
+
+  } // while on clusters
+
+  // Fill the last plane
+  if( index0 != index1 ){
+
+    //printf("fPreviousdetector %d, planeprevious %d, index0 %d, index1 %d li\n",fDetectorPreviousTrack,GetPlane(fDetectorPreviousTrack),index0,index1);
+    
+    fNumberTrack++; 
+    
+    if (fGoodTrack && fGoodTracklet) {
+      
+      // drift velocity unables to cut bad tracklets 
+      Bool_t  pass = FindP1TrackPHtrack(t,index0,index1);
+      
+      // Gain calibration
+      if (fCH2dOn) {
+       FillTheInfoOfTheTrackCH();
+      }
+      
+      // PH calibration
+      if (fPH2dOn) {
+       FillTheInfoOfTheTrackPH();    
+      }
+      
+      if(pass && fPRF2dOn) HandlePRFtrack(t,index0,index1);
+          
+    } // if a good track
+    
+  }
 
+  // reset stuff     
+  ResetfVariablestrack();
+   
+  return kTRUE;
+  
 }
 //____________Offline tracking in the AliTRDtracker____________________________
 Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *t)
@@ -528,7 +730,7 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *
 
   // Localisation of the detector
   Int_t detector = cl->GetDetector();
-
   // Fill the infos for the previous clusters if not the same
   // detector anymore or if not the same track
   if (((detector != fDetectorPreviousTrack) || (!fDetectorAliTRDtrack)) && 
@@ -538,8 +740,12 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *
     
     // If the same track, then look if the previous detector is in
     // the same plane, if yes: not a good track
+    //FollowBack
     if (fDetectorAliTRDtrack && 
-        (GetPlane(detector) <= GetPlane(fDetectorPreviousTrack))) {
+       (GetPlane(detector) <= GetPlane(fDetectorPreviousTrack))) {
+    //Follow
+    //if (fDetectorAliTRDtrack && 
+    //    (GetPlane(detector) >= GetPlane(fDetectorPreviousTrack))) {
       fGoodTrack = kFALSE;
     }
 
@@ -566,12 +772,27 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *
     } // if a good track
     
     ResetfVariables();
+    if(!fDetectorAliTRDtrack) fGoodTrack = kTRUE;
     
   } // Fill at the end the charge
   
-  // Calcul the position of the detector
+  // Calcul the position of the detector and take the calib objects
   if (detector != fDetectorPreviousTrack) {
+    //Localise the detector
     LocalisationDetectorXbins(detector);
+    
+    // Get cal
+    AliTRDcalibDB *cal = AliTRDcalibDB::Instance();
+    if (!cal) {
+      AliInfo("Could not get calibDB");
+      return kFALSE;
+    }
+    
+    // Get calib objects
+    if( fCalROCGain ) delete fCalROCGain;
+    fCalROCGain = new AliTRDCalROC(*(cal->GetGainFactorROC(detector)));
+    if( fCalROCT0 )   delete fCalROCT0;
+    fCalROCT0   = new AliTRDCalROC(*(cal->GetT0ROC(detector)));
   }
  
   // Reset the detector
@@ -586,7 +807,7 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *
   fPar1[time] = t->GetZ();
   fPar2[time] = t->GetSnp();
   fPar3[time] = t->GetTgl();
-  fPar4[time] = t->Get1Pt();
+  fPar4[time] = t->GetSigned1Pt();
 
   // Store the info bis of the tracklet
   Int_t *rowcol   = CalculateRowCol(cl);
@@ -594,7 +815,7 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistograms(AliTRDcluster *cl, AliTRDtrack *
   Int_t     group[2] = {0,0};
   if(fCH2dOn)  group[0]  = CalculateCalibrationGroup(0,rowcol);
   if(fPH2dOn)  group[1]  = CalculateCalibrationGroup(1,rowcol);
-  StoreInfoCHPH(cl,t,group);
+  StoreInfoCHPH(cl,t,group,rowcol);
    
   return kTRUE;
   
@@ -611,6 +832,7 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistogramcm(AliTRDmcmTracklet *trk)
   
   // Localisation of the Xbins involved
   Int_t idect = trk->GetDetector();
+  fDetectorPreviousTrack = idect;
   LocalisationDetectorXbins(idect);
 
   // Get the parameter object
@@ -622,7 +844,13 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistogramcm(AliTRDmcmTracklet *trk)
    
   // Reset
   ResetfVariables();
+
+  // Get calib objects
+  if( fCalROCGain ) delete fCalROCGain;
+  fCalROCGain = new AliTRDCalROC(*(cal->GetGainFactorROC(idect)));
+  if( fCalROCT0 )   delete fCalROCT0;
+  fCalROCT0   = new AliTRDCalROC(*(cal->GetT0ROC(idect)));
+   
   // Row of the tracklet and position in the pad groups
   Int_t *rowcol  = new Int_t[2];
   rowcol[0]     = trk->GetRow();
@@ -698,9 +926,9 @@ Bool_t AliTRDCalibraFillHisto::UpdateHistogramcm(AliTRDmcmTracklet *trk)
                  fPRF2d->Fill((1.0-xcenter),(fCalibraMode->GetXbins(2)+group[2]+0.5),ymax);
                }
                if (fVector2d) {
-                 fCalibraVector->UpdateVectorPRF(fCalibraMode->GetXbins(2)+group[2],xcenter,ycenter);
-                 fCalibraVector->UpdateVectorPRF(fCalibraMode->GetXbins(2)+group[2],-(xcenter+1.0),yminus);
-                 fCalibraVector->UpdateVectorPRF(fCalibraMode->GetXbins(2)+group[2],(1.0-xcenter),ymax);
+                 fCalibraVector->UpdateVectorPRF(idect,group[2],xcenter,ycenter);
+                 fCalibraVector->UpdateVectorPRF(idect,group[2],-(xcenter+1.0),yminus);
+                 fCalibraVector->UpdateVectorPRF(idect,group[2],(1.0-xcenter),ymax);
                }
              }//in the drift region 
            }//in the middle
@@ -754,7 +982,7 @@ Int_t *AliTRDCalibraFillHisto::CalculateRowCol(AliTRDcluster *cl) const
   //Double_t offsettilt      = padplane->GetTiltOffset(offsetz);
   //Int_t    col             = padplane->GetPadColNumber(pos[1] + offsettilt,offsetz);
   //Int_t    col             = padplane->GetPadColNumber(pos[1]+offsettilt);
-  Int_t    col               = cl->GetPad(); 
+  Int_t    col               = cl->GetPadCol(); 
 
   //return
   rowcol[0]     = row;
@@ -853,7 +1081,7 @@ Int_t AliTRDCalibraFillHisto::CalculateTotalNumberOfBins(Int_t i)
   fCalibraMode->ModePadFragmentation(0,0,0,i);
   fCalibraMode->SetDetChamb0(i);
   Ntotal += 6 * 4 * 18 * fCalibraMode->GetDetChamb0(i);
-  AliInfo(Form("Total number of Xbins: %d",Ntotal));
+  AliInfo(Form("Total number of Xbins: %d for i %d",Ntotal,i));
   return Ntotal;
 
 }
@@ -889,7 +1117,7 @@ Bool_t AliTRDCalibraFillHisto::LocalisationDetectorXbins(Int_t detector)
 
 }
 //_____________________________________________________________________________
-void AliTRDCalibraFillHisto::StoreInfoCHPH(AliTRDcluster *cl, AliTRDtrack *t, Int_t *group)
+void AliTRDCalibraFillHisto::StoreInfoCHPH(AliTRDcluster *cl, AliTRDtrack *t, Int_t *group, Int_t *rowcol)
 {
   //
   // Store the infos in fAmpTotal, fPHPlace and fPHValue
@@ -898,10 +1126,24 @@ void AliTRDCalibraFillHisto::StoreInfoCHPH(AliTRDcluster *cl, AliTRDtrack *t, In
   // Charge in the cluster
   Float_t  q        = TMath::Abs(cl->GetQ());
   Int_t    time     = cl->GetLocalTimeBin();
-   
+
+  //Correct for the gain coefficient used in the database for reconstruction
+  Float_t correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(rowcol[1],rowcol[0]);
+  Float_t correcttheT0   = fCalDetT0->GetValue(fDetectorPreviousTrack)+fCalROCT0->GetValue(rowcol[1],rowcol[0]);
+    
+  // we substract correcttheT0 in AliTRDclusterizerV1::MakeClusters (line 458)
+  Int_t timec            = Arrondi((Double_t)(time+correcttheT0));
+  if((correcttheT0+0.5)==(int(correcttheT0+0.5))) {
+    timec++;
+  }
+  if( timec < 0 ) return;
+
+
   // Correction due to the track angle
   Float_t correction    = 1.0;
   Float_t normalisation = 6.67;
+  // we divide with gain in AliTRDclusterizerV1::Transform...
+  if( correctthegain > 0 ) normalisation /= correctthegain;
   if ((q >0) && (t->GetNdedx() > 0)) {
     correction = t->GetClusterdQdl((t->GetNdedx() - 1)) / (normalisation);
   }
@@ -913,97 +1155,203 @@ void AliTRDCalibraFillHisto::StoreInfoCHPH(AliTRDcluster *cl, AliTRDtrack *t, In
 
   // Fill the fPHPlace and value
   if (fPH2dOn) {
-    fPHPlace[time] = group[1];
-    fPHValue[time] = correction;
+    fPHPlace[timec] = group[1];
+    fPHValue[timec] = correction;
+  }
+  
+}
+//_____________________________________________________________________________
+void AliTRDCalibraFillHisto::StoreInfoCHPHtrack(AliTRDcluster *cl, AliTRDtrack *t, Int_t index, Int_t *group, Int_t *rowcol)
+{
+  //
+  // Store the infos in fAmpTotal, fPHPlace and fPHValue
+  //
+  
+  // Charge in the cluster
+  Float_t  q        = TMath::Abs(cl->GetQ());
+  Int_t    time     = cl->GetLocalTimeBin();
+   
+  //Correct for the gain coefficient used in the database for reconstruction
+  Float_t correctthegain = fCalDetGain->GetValue(fDetectorPreviousTrack)*fCalROCGain->GetValue(rowcol[1],rowcol[0]);
+  Float_t correcttheT0   = fCalDetT0->GetValue(fDetectorPreviousTrack)+fCalROCT0->GetValue(rowcol[1],rowcol[0]);
+    
+  // we substract correcttheT0 in AliTRDclusterizerV1::MakeClusters (line 458)
+  Int_t timec            = Arrondi((Double_t)(time+correcttheT0));
+  if((correcttheT0+0.5)==(int(correcttheT0+0.5))) {
+    timec++;
+  }
+  if( timec < 0 ) return;
+
+  // Correction due to the track angle
+  Float_t correction    = 1.0;
+  Float_t normalisation = 6.67;
+  // we divide with gain in AliTRDclusterizerV1::Transform...
+  if( correctthegain > 0 ) normalisation /= correctthegain;
+  if (q >0) {
+    correction = t->GetClusterdQdl(index) / (normalisation);
+  }
+
+  // Fill the fAmpTotal with the charge
+  if (fCH2dOn) {
+    fAmpTotal[(Int_t) group[0]] += correction;
+  }
+
+  // Fill the fPHPlace and value
+  if (fPH2dOn) {
+    fPHPlace[timec] = group[1];
+    fPHValue[timec] = correction;
   }
   
 }
 //_____________________________________________________________________
-Bool_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDRawStream *rawStream)
+Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliTRDRawStreamV2 *rawStream, Bool_t nocheck)
 {
   //
-  // Event Processing loop - AliTRDRawStream
+  // Event Processing loop - AliTRDRawStreamV2
+  // 0 timebin problem
+  // 1 no input
+  // 2 input
   //
 
-  Bool_t withInput = kFALSE;
+  Int_t withInput = 1;
 
   Int_t phvalue[36];
   //Int_t row[36];
   //Int_t col[36];
   for(Int_t k = 0; k < 36; k++){
-    phvalue[k] = 0;
+    phvalue[k] = 10;
     //row[k]     = -1;
     //col[36]    = -1;
   }
   fDetectorPreviousTrack = -1;
   Int_t nbtimebin = 0;                                           
 
-  while (rawStream->Next()) {
-
-    Int_t idetector = rawStream->GetDet();                            //  current detector
-    if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
-      if(TMath::Mean(nbtimebin,phvalue)>0.0){
-       withInput = kTRUE;
-       for(Int_t k = 0; k < nbtimebin; k++){
-         UpdateDAQ(fDetectorPreviousTrack,0,0,k,phvalue[k],nbtimebin);
-         phvalue[k] = 0;
+  if(!nocheck){
+  
+    fTimeMax = 0;
+  
+    while (rawStream->Next()) {
+      
+      Int_t idetector = rawStream->GetDet();                            //  current detector
+      if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
+       if(TMath::Mean(fTimeMax,phvalue)>20.0){
+         withInput = 2;
+         for(Int_t k = 0; k < fTimeMax; k++){
+           UpdateDAQ(fDetectorPreviousTrack,0,0,k,phvalue[k],fTimeMax);
+           phvalue[k] = 10;
+           //row[k]     = -1;
+           //col[k]     = -1;
+         }
+       }
+      }
+      fDetectorPreviousTrack = idetector;
+      nbtimebin         = rawStream->GetNumberOfTimeBins();              //  number of time bins read from data
+      if(nbtimebin == 0) return 0;
+      if((fTimeMax != 0) && (nbtimebin != fTimeMax)) return 0;
+      fTimeMax          = nbtimebin;
+      Int_t iTimeBin    = rawStream->GetTimeBin();                       //  current time bin
+      //row[iTimeBin]   = rawStream->GetRow();                           //  current row
+      //col[iTimeBin]   = rawStream->GetCol();                           //  current col     
+      Int_t *signal     = rawStream->GetSignals();                       //  current ADC signal
+      //printf("detector %d, nbtimebin %d, iTimeBin %d\n",fDetectorPreviousTrack,nbtimebin,iTimeBin);
+      
+      Int_t fin     = TMath::Min(fTimeMax,(iTimeBin+3));
+      Int_t n       = 0;
+      for(Int_t itime = iTimeBin; itime < fin; itime++){
+       // should extract baseline here!
+       if(signal[n]>13) phvalue[itime] = signal[n];
+       //printf("signal is %d for %d\n",signal[n],n);
+       n++;
+      }
+    }
+  
+    // fill the last one
+    if(fDetectorPreviousTrack != -1){
+      if(TMath::Mean(fTimeMax,phvalue)>20.0){
+       withInput = 2;
+       for(Int_t k = 0; k < fTimeMax; k++){
+         UpdateDAQ(fDetectorPreviousTrack,0,0,k,phvalue[k],fTimeMax);
+         phvalue[k] = 10;
          //row[k]     = -1;
          //col[k]     = -1;
        }
       }
     }
-    fDetectorPreviousTrack = idetector;
-    nbtimebin         = rawStream->GetNumberOfTimeBins();              //  number of time bins read from data
-    Int_t iTimeBin    = rawStream->GetTimeBin();                       //  current time bin
-    //row[iTimeBin]   = rawStream->GetRow();                           //  current row
-    //col[iTimeBin]   = rawStream->GetCol();                           //  current col     
-    Int_t *signal     = rawStream->GetSignals();                       //  current ADC signal
-        
-    Int_t fin     = TMath::Min(nbtimebin,(iTimeBin+3));
-    Int_t n       = 0;
-    for(Int_t itime = iTimeBin; itime < fin; itime++){
-      // should extract baseline here!
-      if(signal[n]>5.0) phvalue[itime] = signal[n];
-      n++;
-    }
+    
   }
-  
-  // fill the last one
-  if(fDetectorPreviousTrack != -1){
-      if(TMath::Mean(nbtimebin,phvalue)>0.0){
-       withInput = kTRUE;
+  else{
+
+    while (rawStream->Next()) {
+
+      Int_t idetector = rawStream->GetDet();                            //  current detector
+      if((fDetectorPreviousTrack != idetector) && (fDetectorPreviousTrack != -1)){
+       if(TMath::Mean(nbtimebin,phvalue)>20.0){
+         withInput = 2;
+         for(Int_t k = 0; k < nbtimebin; k++){
+           UpdateDAQ(fDetectorPreviousTrack,0,0,k,phvalue[k],nbtimebin);
+           phvalue[k] = 10;
+           //row[k]     = -1;
+           //col[k]     = -1;
+         }
+       }
+      }
+      fDetectorPreviousTrack = idetector;
+      nbtimebin         = rawStream->GetNumberOfTimeBins();              //  number of time bins read from data
+      Int_t iTimeBin    = rawStream->GetTimeBin();                       //  current time bin
+      //row[iTimeBin]   = rawStream->GetRow();                           //  current row
+      //col[iTimeBin]   = rawStream->GetCol();                           //  current col     
+      Int_t *signal     = rawStream->GetSignals();                       //  current ADC signal
+      //printf("detector %d, nbtimebin %d, iTimeBin %d\n",fDetectorPreviousTrack,nbtimebin,iTimeBin);
+
+      Int_t fin     = TMath::Min(nbtimebin,(iTimeBin+3));
+      Int_t n       = 0;
+      for(Int_t itime = iTimeBin; itime < fin; itime++){
+       // should extract baseline here!
+       if(signal[n]>13) phvalue[itime] = signal[n];
+       //printf("signal is %d for %d\n",signal[n],n);
+       n++;
+      }
+    }
+    
+    // fill the last one
+    if(fDetectorPreviousTrack != -1){
+      if(TMath::Mean(nbtimebin,phvalue)>20.0){
+       withInput = 2;
        for(Int_t k = 0; k < nbtimebin; k++){
          UpdateDAQ(fDetectorPreviousTrack,0,0,k,phvalue[k],nbtimebin);
-         phvalue[k] = 0;
+         phvalue[k] = 10;
          //row[k]     = -1;
          //col[k]     = -1;
        }
       }
+    }
   }
   
   return withInput;
-  
+
 }
 //_____________________________________________________________________
-Bool_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader)
+Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(AliRawReader *rawReader, Bool_t nocheck)
 {
   //
   //  Event processing loop - AliRawReader
   //
 
 
-  AliTRDRawStream rawStream(rawReader);
+  AliTRDRawStreamV2 rawStream(rawReader);
 
   rawReader->Select("TRD");
 
-  return ProcessEventDAQ(&rawStream);
+  return ProcessEventDAQ(&rawStream, nocheck);
 }
 //_________________________________________________________________________
-Bool_t AliTRDCalibraFillHisto::ProcessEventDAQ(
+Int_t AliTRDCalibraFillHisto::ProcessEventDAQ(
 #ifdef ALI_DATE
-                                  eventHeaderStruct *event
+                                              eventHeaderStruct *event,
+                                              Bool_t nocheck
 #else
-                                  eventHeaderStruct* /*event*/
+                                              eventHeaderStruct* /*event*/,
+                                              Bool_t /*nocheck*/
            
 #endif 
                                   )
@@ -1013,7 +1361,7 @@ Bool_t AliTRDCalibraFillHisto::ProcessEventDAQ(
   //
 #ifdef ALI_DATE
     AliRawReader *rawReader = new AliRawReaderDate((void*)event);
-    Bool_t result=ProcessEventDAQ(rawReader);
+    Int_t result=ProcessEventDAQ(rawReader, nocheck);
     delete rawReader;
     return result;
 #else
@@ -1047,54 +1395,19 @@ Bool_t AliTRDCalibraFillHisto::UpdateDAQ(Int_t det, Int_t /*row*/, Int_t /*col*/
   
   //fPH2d->Fill((Float_t) timebin/fSf,(fCalibraMode->GetXbins(1)+posc*fCalibraMode->GetNfragZ(1)+posr)+0.5,(Float_t) signal);   
   
-  ((TProfile2D *)GetPH2d(nbtimebins,fSf,kTRUE))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
+  ((TProfile2D *)GetPH2d(nbtimebins,fSf))->Fill((Float_t) timebin/fSf,det+0.5,(Float_t) signal);
   
   return kTRUE;
   
 }
-//____________Functions for plotting the 2D____________________________________
-
-//_____________________________________________________________________________
-void AliTRDCalibraFillHisto::Plot2d()
-{
-  //
-  // Plot the 2D histos 
-  //
-  if (fPH2dOn) {
-    TCanvas *cph2d = new TCanvas("cph2d","",50,50,600,800);
-    cph2d->cd();
-    fPH2d->Draw("LEGO");
-  }
-  if (fCH2dOn) {
-    TCanvas *cch2d = new TCanvas("cch2d","",50,50,600,800);
-    cch2d->cd();
-    fCH2d->Draw("LEGO");
-  }
-  if (fPRF2dOn) {
-    TCanvas *cPRF2d = new TCanvas("cPRF2d","",50,50,600,800);
-    cPRF2d->cd();
-    fPRF2d->Draw("LEGO");
-  }
-
-}
-//_____________________Reset____________________________________________________
-//_______________________________________________________________________________
-void AliTRDCalibraFillHisto::ResetLinearFitter()
-{
-  fLinearFitterArray.SetOwner();
-  fLinearFitterArray.Clear();
-  fLinearFitterHistoArray.SetOwner();
-  fLinearFitterHistoArray.Clear();
-}
 //____________Write_____________________________________________________
 //_____________________________________________________________________
 void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
 {
-    //
-    //  Write infos to file
-    //
-
+  //
+  //  Write infos to file
+  //
+  
   //For debugging
   if ( fDebugStreamer ) {
     delete fDebugStreamer;
@@ -1120,52 +1433,30 @@ void AliTRDCalibraFillHisto::Write2d(const Char_t *filename, Bool_t append)
   
   TStopwatch stopwatch;
   stopwatch.Start();
+  if(fVector2d) {
+    f.WriteTObject(fCalibraVector);
+  }
 
   if (fCH2dOn ) {
     if (fHisto2d) {
       f.WriteTObject(fCH2d);
     }
-    if (fVector2d) {
-      TString name("Nz");
-      name += fCalibraMode->GetNz(0);
-      name += "Nrphi";
-      name += fCalibraMode->GetNrphi(0);
-      TTree *treeCH2d = fCalibraVector->ConvertVectorCTTreeHisto(fCalibraVector->GetVectorCH(),fCalibraVector->GetPlaCH(),"treeCH2d",(const char *) name);
-       f.WriteTObject(treeCH2d);
-    }
   }
   if (fPH2dOn ) {
     if (fHisto2d) {
       f.WriteTObject(fPH2d);
     }
-    if (fVector2d) {
-      TString name("Nz");
-      name += fCalibraMode->GetNz(1);
-      name += "Nrphi";
-      name += fCalibraMode->GetNrphi(1);
-      TTree *treePH2d = fCalibraVector->ConvertVectorPTreeHisto(fCalibraVector->GetVectorPH(),fCalibraVector->GetPlaPH(),"treePH2d",(const char *) name);
-      f.WriteTObject(treePH2d);
-    }
   }
   if (fPRF2dOn) {
     if (fHisto2d) {
        f.WriteTObject(fPRF2d);
     }
-    if (fVector2d) {
-      TString name("Nz");
-      name += fCalibraMode->GetNz(2);
-      name += "Nrphi";
-      name += fCalibraMode->GetNrphi(2);
-      name += "Ngp";
-      name += fNgroupprf;
-      TTree *treePRF2d = fCalibraVector->ConvertVectorPTreeHisto(fCalibraVector->GetVectorPRF(),fCalibraVector->GetPlaPRF(),"treePRF2d",(const char *) name);
-      f.WriteTObject(treePRF2d);
-    }
   }
-  if(fLinearFitterOn && fLinearFitterDebugOn){
-    f.WriteTObject(&fLinearFitterHistoArray);
+  if(fLinearFitterOn){
+    AnalyseLinearFitter();
+    f.WriteTObject(fLinearVdriftFit);
   }
-  
+   
   f.Close();
   
   if ( backup ) backup->cd();
@@ -1186,7 +1477,7 @@ Double_t *AliTRDCalibraFillHisto::StatH(TH2 *h, Int_t i)
   // [3] : maximal number of entries found
   // [4] : calibration group number of the max
   // [5] : mean number of entries found
-  // [6] : mean relativ error
+  // [6] : mean relative error
   //
 
   Double_t *info = new Double_t[7];
@@ -1503,7 +1794,6 @@ void AliTRDCalibraFillHisto::CreatePH2d(Int_t nn)
   fPH2d->SetStats(0);
 
 }
-
 //_____________________________________________________________________________
 void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
 {
@@ -1525,6 +1815,7 @@ void AliTRDCalibraFillHisto::CreateCH2d(Int_t nn)
   fCH2d->Sumw2();
 
 }
+
 //____________Offine tracking in the AliTRDtracker_____________________________
 void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH()
 {
@@ -1537,8 +1828,10 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH()
   Int_t nb            =  0;   // Nombre de zones traversees
   Int_t fd            = -1;   // Premiere zone non nulle
   Float_t totalcharge = 0.0;  // Total charge for the supermodule histo
+
+  
   
-  
   // See if the track goes through different zones
   for (Int_t k = 0; k < fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0); k++) {
     if (fAmpTotal[k] > 0.0) {
@@ -1550,7 +1843,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH()
     }
   }
 
+  
   switch (nb)
     { 
     case 1:
@@ -1561,7 +1854,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH()
        //fCH2d->Fill(fAmpTotal[fd]/fRelativeScale,fCalibraMode->GetXbins(0)+fd+0.5);
       }
       if (fVector2d) {
-       fCalibraVector->UpdateVectorCH(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/fRelativeScale);
+       fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/fRelativeScale);
       }
       break;
     case 2:
@@ -1574,7 +1867,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH()
            //fCH2d->Fill(fAmpTotal[fd]/fRelativeScale,fCalibraMode->GetXbins(0)+fd+0.5);
          }
          if (fVector2d) {
-           fCalibraVector->UpdateVectorCH(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/fRelativeScale);
+           fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/fRelativeScale);
          }
          fNumberUsedCh[1]++;
          fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
@@ -1585,7 +1878,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH()
            //fCH2d->Fill(fAmpTotal[fd+1]/fRelativeScale,fCalibraMode->GetXbins(0)+fd+1.5);
          }
          if (fVector2d) {
-           fCalibraVector->UpdateVectorCH(fCalibraMode->GetXbins(0)+fd+1,fAmpTotal[fd+1]/fRelativeScale);
+           fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+1,fAmpTotal[fd+1]/fRelativeScale);
          }
          fNumberUsedCh[1]++;
          fEntriesCH[fCalibraMode->GetXbins(0)+fd+1]++;
@@ -1602,7 +1895,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH()
                  //fCH2d->Fill(fAmpTotal[fd]/fRelativeScale,fCalibraMode->GetXbins(0)+fd+0.5);
                }
                if (fVector2d) {
-                 fCalibraVector->UpdateVectorCH(fCalibraMode->GetXbins(0)+fd,fAmpTotal[fd]/fRelativeScale);
+                 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd,fAmpTotal[fd]/fRelativeScale);
                }
                fNumberUsedCh[1]++;
                fEntriesCH[fCalibraMode->GetXbins(0)+fd]++;
@@ -1615,7 +1908,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackCH()
                fNumberUsedCh[1]++;
                fEntriesCH[fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0)]++;
                if (fVector2d) {
-                 fCalibraVector->UpdateVectorCH(fCalibraMode->GetXbins(0)+fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/fRelativeScale);
+                 fCalibraVector->UpdateVectorCH(fDetectorPreviousTrack,fd+fCalibraMode->GetNfragZ(0),fAmpTotal[fd+fCalibraMode->GetNfragZ(0)]/fRelativeScale);
                }
              }
            }
@@ -1661,6 +1954,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
     }
   }
 
+  
   switch(nb)
     {
     case 1:
@@ -1670,7 +1964,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
          fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
        }
        if (fVector2d) {
-         fCalibraVector->UpdateVectorPH((fCalibraMode->GetXbins(1)+fd1),i,fPHValue[i]);
+         fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
        }
       }
       break;
@@ -1686,7 +1980,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
              fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
            }
            if (fVector2d) {
-             fCalibraVector->UpdateVectorPH((fCalibraMode->GetXbins(1)+fd1),i,fPHValue[i]);
+             fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
            }
          }
        }
@@ -1698,7 +1992,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
              fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
            }
          if (fVector2d) {
-           fCalibraVector->UpdateVectorPH((fCalibraMode->GetXbins(1)+fd2),i,fPHValue[i]);
+           fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
          }
          }
        }
@@ -1717,7 +2011,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
                  fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
                }
                if (fVector2d) {
-                 fCalibraVector->UpdateVectorPH((fCalibraMode->GetXbins(1)+fd1),i,fPHValue[i]);
+                 fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
                }
              }
            }
@@ -1729,7 +2023,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
                  fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
                }
                if (fVector2d) {
-                 fCalibraVector->UpdateVectorPH((fCalibraMode->GetXbins(1)+fd2),i,fPHValue[i]);
+                 fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
                }
              }
            }
@@ -1748,7 +2042,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
                  fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd1)+0.5,(Float_t) fPHValue[i]);
                }
                if (fVector2d) {
-                 fCalibraVector->UpdateVectorPH((fCalibraMode->GetXbins(1)+fd1),i,fPHValue[i]);
+                 fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd1,i,fPHValue[i]);
                }
              }
            }
@@ -1760,7 +2054,7 @@ void AliTRDCalibraFillHisto::FillTheInfoOfTheTrackPH()
                  fPH2d->Fill((Float_t) i/fSf,(fCalibraMode->GetXbins(1)+fd2)+0.5,(Float_t) fPHValue[i]);
                }
                if (fVector2d) {
-                 fCalibraVector->UpdateVectorPH((fCalibraMode->GetXbins(1)+fd2),i,fPHValue[i]);
+                 fCalibraVector->UpdateVectorPH(fDetectorPreviousTrack,fd2,i,fPHValue[i]);
                }
              }
            }
@@ -1779,7 +2073,8 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPH()
   // This function will be called in the functions UpdateHistogram... 
   // to fill the find the parameter P1 of a track for the drift velocity  calibration
   //
-  
+
+   
   //Number of points: if less than 3 return kFALSE
   Int_t Npoints = fListClusters->GetEntriesFast();
   if(Npoints <= 2) return kFALSE;
@@ -1824,7 +2119,10 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPH()
     if(k==0) rowp                     = row;
     if(row != rowp) crossrow          = 1;
     //Take in the middle of the chamber
+    //FollowBack
     if(time > (Int_t) 10) {
+    //Follow
+    //if(time < (Int_t) 11) {
       z   = cl->GetZ();
       y   = cl->GetY();  
       snp = fPar2[time];
@@ -1833,7 +2131,10 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPH()
     linearFitterTracklet.AddPoint(&timeis,ycluster,1);
     nbli++;
   }
-  if(((AliTRDcluster *) fListClusters->At(0))->GetLocalTimeBin() <= 10) snpright = 0;
+  //FollowBack
+  if(((AliTRDcluster *) fListClusters->At(0))->GetLocalTimeBin() < 10) snpright = 0;
+  //Follow
+  //if(((AliTRDcluster *) fListClusters->At(0))->GetLocalTimeBin() >= 11) snpright = 0;
   if(nbli <= 2) return kFALSE; 
   
   // Do the straight line fit now
@@ -1853,7 +2154,7 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPH()
     if ( !fDebugStreamer ) {
       //debug stream
       TDirectory *backup = gDirectory;
-      fDebugStreamer = new TTreeSRedirector("TRDdebugCalibra.root");
+      fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
       if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
     } 
     
@@ -1893,7 +2194,7 @@ Bool_t AliTRDCalibraFillHisto::FindP1TrackPH()
       Double_t x = tnp-dzdx*tnt; 
       (GetLinearFitter(detector,kTRUE))->AddPoint(&x,dydt);
       if(fLinearFitterDebugOn) {
-       ((TH2F *) GetLinearFitterHisto(detector,kTRUE))->Fill(tnp,pars[1]);
+       fLinearVdriftFit->Update(detector,x,pars[1]);
       }
       fEntriesLinearFitter[detector]++;
     }
@@ -1909,7 +2210,7 @@ Bool_t AliTRDCalibraFillHisto::HandlePRF()
   // For the offline tracking
   // Fit the tracklet with a line and take the position as reference for the PRF
   //
-  
+
   //Number of points
   Int_t Npoints  = fListClusters->GetEntriesFast();                         // number of total points
   Int_t Nb3pc    = 0;                                                       // number of three pads clusters used for fit 
@@ -1957,7 +2258,7 @@ Bool_t AliTRDCalibraFillHisto::HandlePRF()
     if(echec) continue;
     //if no echec: calculate with the position of the pad
     // Position of the cluster
-    Double_t       padPosition = xcenter +  cl->GetPad();
+    Double_t       padPosition = xcenter +  cl->GetPadCol();
     padPositions[k]            = padPosition;
     Nb3pc++;
     fitter.AddPoint(&time, padPosition,1);
@@ -1979,7 +2280,7 @@ Bool_t AliTRDCalibraFillHisto::HandlePRF()
     Short_t  *signals      = cl->GetSignals();              // signal
     Double_t     time      = cl->GetLocalTimeBin();         // time bin
     Float_t padPosTracklet = line[0]+line[1]*time;          // reconstruct position from fit
-    Float_t padPos         = cl->GetPad();                  // middle pad
+    Float_t padPos         = cl->GetPadCol();               // middle pad
     Double_t dpad          = padPosTracklet - padPos;       // reconstruct position relative to middle pad from fit 
     Float_t ycenter        = 0.0;                           // relative center charge
     Float_t ymin           = 0.0;                           // relative left charge
@@ -2001,7 +2302,7 @@ Bool_t AliTRDCalibraFillHisto::HandlePRF()
     //calibration group
     Int_t    *rowcol       = CalculateRowCol(cl);                       // calcul col and row pad of the cluster
     Int_t     grouplocal   = CalculateCalibrationGroup(2,rowcol);       // calcul the corresponding group
-    Int_t     caligroup    = fCalibraMode->GetXbins(2)+ grouplocal;     // calcul the corresponidng group
+    Int_t     caligroup    = fCalibraMode->GetXbins(2)+ grouplocal;     // calcul the corresponding group
     Double_t  snp          = fPar2[(Int_t)time];                        // sin angle in xy plan
     Float_t   xcl          = cl->GetY();                                // y cluster
     Float_t   qcl          = cl->GetQ();                                // charge cluster 
@@ -2026,7 +2327,7 @@ Bool_t AliTRDCalibraFillHisto::HandlePRF()
       if ( !fDebugStreamer ) {
        //debug stream
        TDirectory *backup = gDirectory;
-       fDebugStreamer = new TTreeSRedirector("TRDdebugCalibra.root");
+       fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
        if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
       }     
       
@@ -2178,26 +2479,476 @@ Bool_t AliTRDCalibraFillHisto::HandlePRF()
       }
     }
     if (fHisto2d && !echec) {
-      fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
-      if(ymin > 0.0) {
+      if(TMath::Abs(dpad) < 1.5) {
+       fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
+       fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
+      }
+      if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
        fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
        fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
       }
-      if(ymax > 0.0) {
+      if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
        fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
        fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
       }
     }
     //Not equivalent anymore here!
     if (fVector2d && !echec) {
-      fCalibraVector->UpdateVectorPRF(caligroup,shift+dpad,ycenter);
-      if(ymin > 0.0) {
-       fCalibraVector->UpdateVectorPRF(caligroup,shift-(dpad+1.0),ymin);
-       fCalibraVector->UpdateVectorPRF(caligroup,shift+(dpad+1.0),ymin);
+      if(TMath::Abs(dpad) < 1.5) {
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
+      }
+      if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
       }
-      if(ymax > 0.0) {
-       fCalibraVector->UpdateVectorPRF(caligroup,shift+1.0-dpad,ymax);
-       fCalibraVector->UpdateVectorPRF(caligroup,shift-1.0+dpad,ymax);
+      if((ymax > 0.0)  && (TMath::Abs(dpad-1.0) < 1.5)) {
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
+      }
+    }
+  }
+  return kTRUE;
+  
+}
+//____________Offine tracking in the AliTRDtracker_____________________________
+Bool_t AliTRDCalibraFillHisto::FindP1TrackPHtrack(AliTRDtrack *t, Int_t index0, Int_t index1)
+{
+  //
+  // For the offline tracking
+  // This function will be called in the functions UpdateHistogram... 
+  // to fill the find the parameter P1 of a track for the drift velocity  calibration
+  //
+
+    
+  //Number of points: if less than 3 return kFALSE
+  Int_t Npoints = index1-index0;
+  if(Npoints <= 2) return kFALSE;
+
+  //Variables
+  TLinearFitter linearFitterTracklet  = TLinearFitter(2,"pol1");            // TLinearFitter per tracklet
+  Double_t snp                        = 0.0;                                // sin angle in the plan yx track
+  Double_t y                          = 0.0;                                // y clusters in the middle of the chamber
+  Double_t z                          = 0.0;                                // z cluster  in the middle of the chamber
+  Double_t dydt                       = 0.0;                                // dydt tracklet after straight line fit
+  Double_t tnp                        = 0.0;                                // tan angle in the plan xy track
+  Double_t tgl                        = 0.0;                                // dz/dl and not dz/dx!  
+  Double_t errorpar                   = 0.0;                                // error after straight line fit on dy/dt
+  Double_t pointError                 = 0.0;                                // error after straight line fit 
+  Int_t    detector                   = ((AliTRDcluster *) t->GetCluster(index0))->GetDetector(); //detector
+  //Int_t    snpright                   = 1;                                  // if we took in the middle snp
+  Int_t    crossrow                   = 0;                                  // if it crosses a pad row
+  Double_t  tiltingangle              = 0;                                  // tiltingangle of the pad
+  Float_t   dzdx                      = 0;                                  // dz/dx now from dz/dl
+  Int_t     nbli                      = 0;                                  // number linear fitter points
+  AliTRDpadPlane *padplane            = fGeo->GetPadPlane(GetPlane(detector),GetChamber(detector));
+
+  linearFitterTracklet.StoreData(kFALSE);
+  linearFitterTracklet.ClearPoints();
+  
+  //if more than one row
+  Int_t    rowp                       = -1;                              // if it crosses a pad row
+
+  //tiltingangle
+  tiltingangle                        = padplane->GetTiltingAngle();
+  Float_t  tnt                        = TMath::Tan(tiltingangle/180.*TMath::Pi()); // tan tiltingangle
+
+  //Fill with points
+  for(Int_t k = 0; k < Npoints; k++){
+    
+    AliTRDcluster *cl                 = (AliTRDcluster *) t->GetCluster(k+index0);
+    Double_t ycluster                 = cl->GetY();
+    Int_t time                        = cl->GetLocalTimeBin();
+    Double_t timeis                   = time/fSf;
+    //See if cross two pad rows
+    Int_t    row                      = padplane->GetPadRowNumber(cl->GetZ());
+    if(k==0) rowp                     = row;
+    if(row != rowp) crossrow          = 1;
+    //Take in the middle of the chamber
+    //FollowBack
+    //if(time > (Int_t) 10) {
+    //Follow
+    if(time < (Int_t) 11) {
+      z   = cl->GetZ();
+      y   = cl->GetY();  
+    }
+    linearFitterTracklet.AddPoint(&timeis,ycluster,1);
+    nbli++;
+  }
+
+  // take now the snp, tnp and tgl from the track
+  snp = t->GetSnpPlane(GetPlane(detector));
+  tgl = t->GetTglPlane(GetPlane(detector));
+
+  //FollowBack
+  //if(((AliTRDcluster *) t->GetCluster(index0))->GetLocalTimeBin() < 10) snpright = 0;
+  //Follow
+  //if(((AliTRDcluster *) t->GetCluster(index0))->GetLocalTimeBin() >= 11) snpright = 0;
+  if(nbli <= 2) return kFALSE; 
+  
+  // Do the straight line fit now
+  TVectorD pars;
+  linearFitterTracklet.Eval();
+  linearFitterTracklet.GetParameters(pars);
+  pointError  =  TMath::Sqrt(linearFitterTracklet.GetChisquare()/nbli);
+  errorpar    =  linearFitterTracklet.GetParError(1)*pointError;
+  dydt  = pars[1]; 
+  if( TMath::Abs(snp) <  1.){
+    tnp = snp / (TMath::Sqrt(1-(snp*snp)));
+  } 
+  dzdx = tgl*TMath::Sqrt(1+tnp*tnp);
+
+  if(fDebugLevel > 0){
+    if ( !fDebugStreamer ) {
+      //debug stream
+      TDirectory *backup = gDirectory;
+      fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
+      if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
+    } 
+    
+        
+    (* fDebugStreamer) << "VDRIFT"<<
+      //"snpright="<<snpright<<
+      "Npoints="<<Npoints<<
+      "nbli="<<nbli<<
+      "detector="<<detector<<
+      "snp="<<snp<<
+      "tnp="<<tnp<<
+      "tgl="<<tgl<<
+      "tnt="<<tnt<<
+      "y="<<y<<
+      "z="<<z<<
+      "dydt="<<dydt<<
+      "dzdx="<<dzdx<<
+      "crossrow="<<crossrow<<
+      "errorpar="<<errorpar<<
+      "pointError="<<pointError<<
+      "\n";     
+
+  }
+  
+  if(Npoints < fNumberClusters) return kFALSE;
+  //if(snpright == 0) return kFALSE;
+  if(pointError >= 0.1) return kFALSE;
+  if(crossrow == 1) return kFALSE;
+  
+  if(fLinearFitterOn){
+    //Add to the linear fitter of the detector
+    if( TMath::Abs(snp) <  1.){
+      Double_t x = tnp-dzdx*tnt; 
+      (GetLinearFitter(detector,kTRUE))->AddPoint(&x,dydt);
+      if(fLinearFitterDebugOn) {
+       fLinearVdriftFit->Update(detector,x,pars[1]);
+      }
+      fEntriesLinearFitter[detector]++;
+    }
+  }
+  //AliInfo("End of FindP1TrackPH with success!")
+  return kTRUE;
+
+}
+//____________Offine tracking in the AliTRDtracker_____________________________
+Bool_t AliTRDCalibraFillHisto::HandlePRFtrack(AliTRDtrack *t, Int_t index0, Int_t index1)
+{
+  //
+  // For the offline tracking
+  // Fit the tracklet with a line and take the position as reference for the PRF
+  //
+
+  //Number of points
+  Int_t Npoints  = index1-index0;                                           // number of total points
+  Int_t Nb3pc    = 0;                                                       // number of three pads clusters used for fit 
+  Int_t detector = ((AliTRDcluster *) t->GetCluster(index0))->GetDetector(); // detector
+
+  // To see the difference due to the fit
+  Double_t *padPositions;
+  padPositions = new Double_t[Npoints];
+  for(Int_t k = 0; k < Npoints; k++){
+    padPositions[k] = 0.0;
+  } 
+
+
+  //Find the position by a fit
+  TLinearFitter fitter(2,"pol1");
+  fitter.StoreData(kFALSE);
+  fitter.ClearPoints();
+  for(Int_t k = 0;  k < Npoints; k++){
+    //Take the cluster
+    AliTRDcluster *cl  = (AliTRDcluster *) t->GetCluster(k+index0);
+    Short_t  *signals  = cl->GetSignals();
+    Double_t     time  = cl->GetLocalTimeBin();
+    //Calculate x if possible 
+    Float_t xcenter    = 0.0;    
+    Bool_t  echec      = kTRUE;   
+    if((time<=7) || (time>=21)) continue; 
+    // Center 3 balanced: position with the center of the pad
+    if ((((Float_t) signals[3]) > 0.0) && 
+       (((Float_t) signals[2]) > 0.0) && 
+       (((Float_t) signals[4]) > 0.0)) {
+      echec = kFALSE;
+      // Security if the denomiateur is 0 
+      if ((((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) / 
+          ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))) != 1.0) {
+       xcenter = 0.5 * (TMath::Log((Float_t) (((Float_t) signals[4]) / ((Float_t) signals[2]))))
+         / (TMath::Log(((Float_t) (((Float_t) signals[3]) * ((Float_t) signals[3]))) 
+                       / ((Float_t) (((Float_t) signals[2]) * ((Float_t) signals[4])))));
+      }
+      else {
+       echec = kTRUE;
+      }
+    }
+    if(TMath::Abs(xcenter) > 0.5) echec = kTRUE;
+    if(echec) continue;
+    //if no echec: calculate with the position of the pad
+    // Position of the cluster
+    Double_t       padPosition = xcenter +  cl->GetPadCol();
+    padPositions[k]            = padPosition;
+    Nb3pc++;
+    fitter.AddPoint(&time, padPosition,1);
+  }//clusters loop
+
+  //printf("Nb3pc %d, Npoints %d\n",Nb3pc,Npoints);
+  if(Nb3pc < 3) return kFALSE;
+  fitter.Eval();
+  TVectorD line(2);
+  fitter.GetParameters(line);
+  Float_t  pointError  = -1.0;
+  pointError  =  TMath::Sqrt(fitter.GetChisquare()/Nb3pc);
+  
+  // Take the tgl and snp with the track t now
+  Double_t  tgl = t->GetTglPlane(GetPlane(detector)); //dz/dl and not dz/dx
+  Double_t  snp = t->GetSnpPlane(GetPlane(detector)); // sin angle in xy plan
+  Float_t  dzdx = 0.0;                                // dzdx
+  Float_t  tnp  = 0.0;
+  if(TMath::Abs(snp) < 1.0){
+    tnp = snp / (TMath::Sqrt(1-snp*snp));
+    dzdx = tgl*TMath::Sqrt(1+tnp*tnp);
+  }
+
+
+  // Now fill the PRF  
+  for(Int_t k = 0;  k < Npoints; k++){
+    //Take the cluster
+    AliTRDcluster *cl      = (AliTRDcluster *) t->GetCluster(k+index0);
+    Short_t  *signals      = cl->GetSignals();              // signal
+    Double_t     time      = cl->GetLocalTimeBin();         // time bin
+    Float_t padPosTracklet = line[0]+line[1]*time;          // reconstruct position from fit
+    Float_t padPos         = cl->GetPadCol();               // middle pad
+    Double_t dpad          = padPosTracklet - padPos;       // reconstruct position relative to middle pad from fit 
+    Float_t ycenter        = 0.0;                           // relative center charge
+    Float_t ymin           = 0.0;                           // relative left charge
+    Float_t ymax           = 0.0;                           // relative right charge
+  
+
+
+    //Requiere simply two pads clusters at least
+    if(((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[2]) > 0.0)) ||
+       ((((Float_t) signals[3]) > 0.0) && (((Float_t) signals[4]) > 0.0))){
+      Float_t sum     = ((Float_t) signals[2]) + ((Float_t) signals[3]) + ((Float_t) signals[4]);
+      if(sum > 0.0) ycenter = ((Float_t) signals[3])/ sum;
+      if(sum > 0.0) ymin    = ((Float_t) signals[2])/ sum;
+      if(sum > 0.0) ymax    = ((Float_t) signals[4])/ sum; 
+    }
+    
+    //calibration group
+    Int_t    *rowcol       = CalculateRowCol(cl);                       // calcul col and row pad of the cluster
+    Int_t     grouplocal   = CalculateCalibrationGroup(2,rowcol);       // calcul the corresponding group
+    Int_t     caligroup    = fCalibraMode->GetXbins(2)+ grouplocal;     // calcul the corresponding group
+    Float_t   xcl          = cl->GetY();                                // y cluster
+    Float_t   qcl          = cl->GetQ();                                // charge cluster 
+    Int_t     plane        = GetPlane(detector);                        // plane 
+    Int_t     chamber      = GetChamber(detector);                      // chamber  
+    Double_t  xdiff        = dpad;                                      // reconstructed position constant
+    Double_t  x            = dpad;                                      // reconstructed position moved
+    Float_t   Ep           = pointError;                                // error of fit
+    Float_t   signal1      = (Float_t)signals[1];                       // signal at the border
+    Float_t   signal3      = (Float_t)signals[3];                       // signal
+    Float_t   signal2      = (Float_t)signals[2];                       // signal
+    Float_t   signal4      = (Float_t)signals[4];                       // signal
+    Float_t   signal5      = (Float_t)signals[5];                       // signal at the border
+   
+   
+
+    if(fDebugLevel > 0){
+      if ( !fDebugStreamer ) {
+       //debug stream
+       TDirectory *backup = gDirectory;
+       fDebugStreamer = new TTreeSRedirector("TRDdebugCalibraFill.root");
+       if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
+      }     
+      
+      (* fDebugStreamer) << "PRF0"<<
+       "caligroup="<<caligroup<<
+       "detector="<<detector<<
+       "plane="<<plane<<
+       "chamber="<<chamber<<
+       "Npoints="<<Npoints<<
+       "Np="<<Nb3pc<<
+       "Ep="<<Ep<<
+       "snp="<<snp<<
+       "tnp="<<tnp<<    
+       "tgl="<<tgl<<  
+       "dzdx="<<dzdx<<  
+               "padPos="<<padPos<<
+       "padPosition="<<padPositions[k]<<
+       "padPosTracklet="<<padPosTracklet<<
+       "x="<<x<<
+       "ycenter="<<ycenter<<
+       "ymin="<<ymin<<
+       "ymax="<<ymax<<
+       "xcl="<<xcl<<
+       "qcl="<<qcl<< 
+       "signal1="<<signal1<<    
+       "signal2="<<signal2<<
+       "signal3="<<signal3<<
+       "signal4="<<signal4<<
+       "signal5="<<signal5<<
+       "time="<<time<<
+       "\n";     
+      x = xdiff;
+      Int_t type=0;
+      Float_t y = ycenter;
+      (* fDebugStreamer) << "PRFALL"<<
+       "caligroup="<<caligroup<<
+       "detector="<<detector<<
+       "plane="<<plane<<
+       "chamber="<<chamber<<
+       "Npoints="<<Npoints<<
+       "Np="<<Nb3pc<<
+       "Ep="<<Ep<<
+       "type="<<type<<
+       "snp="<<snp<<
+       "tnp="<<tnp<<
+       "tgl="<<tgl<<  
+       "dzdx="<<dzdx<< 
+       "padPos="<<padPos<<
+       "padPosition="<<padPositions[k]<<
+       "padPosTracklet="<<padPosTracklet<<
+       "x="<<x<<
+       "y="<<y<<           
+       "xcl="<<xcl<<
+       "qcl="<<qcl<<
+       "signal1="<<signal1<<
+       "signal2="<<signal2<<
+       "signal3="<<signal3<<
+       "signal4="<<signal4<<
+       "signal5="<<signal5<<
+       "time="<<time<<
+       "\n";
+      x=-(xdiff+1);
+      y = ymin;
+      type=-1;
+      (* fDebugStreamer) << "PRFALL"<<
+       "caligroup="<<caligroup<<
+       "detector="<<detector<<
+       "plane="<<plane<<
+       "chamber="<<chamber<<
+       "Npoints="<<Npoints<<
+       "Np="<<Nb3pc<<
+       "Ep="<<Ep<<
+       "type="<<type<<
+       "snp="<<snp<<
+       "tnp="<<tnp<<
+       "tgl="<<tgl<<  
+       "dzdx="<<dzdx<< 
+       "padPos="<<padPos<<
+       "padPosition="<<padPositions[k]<<
+       "padPosTracklet="<<padPosTracklet<<
+       "x="<<x<<
+       "y="<<y<<
+       "xcl="<<xcl<<
+       "qcl="<<qcl<<
+       "signal1="<<signal1<<
+       "signal2="<<signal2<<
+       "signal3="<<signal3<<
+       "signal4="<<signal4<<
+       "signal5="<<signal5<<
+       "time="<<time<<
+       "\n";
+      x=1-xdiff;
+      y = ymax;
+      type=1;
+      
+      (* fDebugStreamer) << "PRFALL"<<
+       "caligroup="<<caligroup<<
+       "detector="<<detector<<
+       "plane="<<plane<<
+       "chamber="<<chamber<<
+       "Npoints="<<Npoints<<
+       "Np="<<Nb3pc<<
+       "Ep="<<Ep<<
+       "type="<<type<<
+       "snp="<<snp<<
+       "tnp="<<tnp<<   
+       "tgl="<<tgl<<  
+       "dzdx="<<dzdx<< 
+       "padPos="<<padPos<<
+       "padPosition="<<padPositions[k]<<
+       "padPosTracklet="<<padPosTracklet<<
+       "x="<<x<<
+       "y="<<y<<
+       "xcl="<<xcl<<
+       "qcl="<<qcl<<
+       "signal1="<<signal1<<
+       "signal2="<<signal2<<
+       "signal3="<<signal3<<
+       "signal4="<<signal4<<
+       "signal5="<<signal5<<
+       "time="<<time<<
+       "\n";
+      
+    }
+    
+    // some cuts
+    if(Npoints < fNumberClusters) continue;
+    if(Nb3pc <= 5) continue;
+    if((time >= 21) || (time < 7)) continue;
+    if(TMath::Abs(snp) >= 1.0) continue;
+    if(qcl < 80) continue; 
+    
+    Bool_t echec   = kFALSE;
+    Double_t shift = 0.0;
+    //Calculate the shift in x coresponding to this tnp
+    if(fNgroupprf != 0.0){
+      shift      = -3.0*(fNgroupprf-1)-1.5;
+      Double_t limithigh  = -0.2*(fNgroupprf-1);
+      if((tnp < (-0.2*fNgroupprf)) || (tnp > (0.2*fNgroupprf))) echec = kTRUE;
+      else{
+       while(tnp > limithigh){
+         limithigh += 0.2;
+         shift += 3.0;
+       }
+      }
+    }
+    if (fHisto2d && !echec) {
+      if(TMath::Abs(dpad) < 1.5) {
+       fPRF2d->Fill(shift+dpad,(caligroup+0.5),ycenter);
+       fPRF2d->Fill(shift-dpad,(caligroup+0.5),ycenter);
+      }
+      if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
+       fPRF2d->Fill(shift-(dpad+1.0),(caligroup+0.5),ymin);
+       fPRF2d->Fill(shift+(dpad+1.0),(caligroup+0.5),ymin);
+      }
+      if((ymax > 0.0) && (TMath::Abs(dpad-1.0) < 1.5)) {
+       fPRF2d->Fill(shift+1.0-dpad,(caligroup+0.5),ymax);
+       fPRF2d->Fill(shift-1.0+dpad,(caligroup+0.5),ymax);
+      }
+    }
+    //Not equivalent anymore here!
+    if (fVector2d && !echec) {
+      if(TMath::Abs(dpad) < 1.5) {
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+dpad,ycenter);
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-dpad,ycenter);
+      }
+      if((ymin > 0.0) && (TMath::Abs(dpad+1.0) < 1.5)) {
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-(dpad+1.0),ymin);
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+(dpad+1.0),ymin);
+      }
+      if((ymax > 0.0)  && (TMath::Abs(dpad-1.0) < 1.5)) {
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift+1.0-dpad,ymax);
+       fCalibraVector->UpdateVectorPRF(fDetectorPreviousTrack,grouplocal,shift-1.0+dpad,ymax);
       }
     }
   }
@@ -2242,13 +2993,13 @@ Int_t AliTRDCalibraFillHisto::GetSector(Int_t d) const
 
 }
 //_____________________________________________________________________
-TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency, Bool_t force)
+TProfile2D* AliTRDCalibraFillHisto::GetPH2d(Int_t nbtimebin, Float_t samplefrequency)
 {
     //
     // return pointer to fPH2d TProfile2D
-    // if force is true create a new TProfile2D if it doesn't exist allready
+    // create a new TProfile2D if it doesn't exist allready
     //
-    if ( !force || fPH2d )
+    if ( fPH2d )
        return fPH2d;
 
     // Some parameters
@@ -2286,44 +3037,19 @@ TLinearFitter* AliTRDCalibraFillHisto::GetLinearFitter(Int_t detector, Bool_t fo
     // return pointer to TLinearFitter Calibration
     // if force is true create a new TLinearFitter if it doesn't exist allready
     //
-    if ( !force || fLinearFitterArray.UncheckedAt(detector) )
-       return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
-
-    // if we are forced and TLinearFitter doesn't yet exist create it
 
-    // new TLinearFitter
-    TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
-    fLinearFitterArray.AddAt(linearfitter,detector);
-    return linearfitter;
-}
-//_____________________________________________________________________
-TH2F* AliTRDCalibraFillHisto::GetLinearFitterHisto(Int_t detector, Bool_t force)
-{
-    //
-    // return pointer to TH2F histo 
-    // if force is true create a new histo if it doesn't exist allready
-    //
-    if ( !force || fLinearFitterHistoArray.UncheckedAt(detector) )
-       return (TH2F*)fLinearFitterHistoArray.UncheckedAt(detector);
+  if ((!force) || (fLinearFitterArray.UncheckedAt(detector))){
+    return (TLinearFitter*)fLinearFitterArray.UncheckedAt(detector);
+  }
 
-    // if we are forced and TLinearFitter doesn't yes exist create it
+  // if we are forced and TLinearFitter doesn't yet exist create it
 
-    // new TH2F
-    TString name("LFDV");
-    name += detector;
-    
-    TH2F *lfdv = new TH2F((const Char_t *)name,(const Char_t *) name
-                         ,100,-1.0,1.0,100
-                         ,-2.0,2.0);
-    lfdv->SetXTitle("tan(phi_{track})");
-    lfdv->SetYTitle("dy/dt");
-    lfdv->SetZTitle("Number of clusters");
-    lfdv->SetStats(0);
-    lfdv->SetDirectory(0);
-
-    fLinearFitterHistoArray.AddAt(lfdv,detector);
-    return lfdv;
+  // new TLinearFitter
+  TLinearFitter *linearfitter = new TLinearFitter(2,"pol1");
+  fLinearFitterArray.AddAt(linearfitter,detector);
+  return linearfitter;
 }
+
 //_____________________________________________________________________
 void  AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
 {
@@ -2342,3 +3068,47 @@ void  AliTRDCalibraFillHisto::FillCH2d(Int_t x, Float_t y)
   fCH2d->GetArray()[place]++;
 
 }
+
+//____________________________________________________________________________
+void AliTRDCalibraFillHisto::AnalyseLinearFitter()
+{
+  //
+  // Analyse array of linear fitter because can not be written
+  // Store two arrays: one with the param the other one with the error param + number of entries
+  //
+
+  for(Int_t k = 0; k < 540; k++){
+    TLinearFitter *linearfitter = GetLinearFitter(k);
+    if((linearfitter!=0) && (fEntriesLinearFitter[k]>10)){
+      TVectorD  *par  = new TVectorD(2);
+      TVectorD   pare = TVectorD(2);
+      TVectorD  *parE = new TVectorD(3);
+      linearfitter->Eval();
+      linearfitter->GetParameters(*par);
+      linearfitter->GetErrors(pare);
+      Float_t  ppointError =  TMath::Sqrt(TMath::Abs(linearfitter->GetChisquare())/fEntriesLinearFitter[k]);
+      (*parE)[0] = pare[0]*ppointError;
+      (*parE)[1] = pare[1]*ppointError;
+      (*parE)[2] = (Double_t) fEntriesLinearFitter[k];
+      ((TObjArray *)fLinearVdriftFit->GetPArray())->AddAt(par,k);
+      ((TObjArray *)fLinearVdriftFit->GetEArray())->AddAt(parE,k);
+    }
+  }
+}
+//________________________________________________________________________________
+Int_t AliTRDCalibraFillHisto::Arrondi(Double_t x) const
+{
+   // Partie entiere of the (x+0.5)
+   
+  int i;
+  if (x >= (-0.5)) {
+    i = int(x + 0.5);
+    //if (x + 0.5 == Float_t(i) && i & 1) i--;
+  } else {
+    i = int(x - 0.5);
+    //if (x - 0.5 == Float_t(i) && i & 1) i++;
+    if((x-0.5)==i) i++;
+
+  }
+  return i;
+}