]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/AliTRDCalibraFit.cxx
Adding possibility to use custom Gain map for dEdx calculation (Marian)
[u/mrichter/AliRoot.git] / TRD / AliTRDCalibraFit.cxx
index 842f6e8a5047d58aa984444ee53a339e6951b47a..e2c48d16b7aa93fcaf55a7d612b0ac217a3783f0 100644 (file)
@@ -130,8 +130,9 @@ AliTRDCalibraFit::AliTRDCalibraFit()
   ,fMethod(0)
   ,fBeginFitCharge(3.5)
   ,fFitPHPeriode(1)
-  ,fTakeTheMaxPH(kFALSE)
-  ,fT0Shift(0.124797)
+  ,fTakeTheMaxPH(kTRUE)
+  ,fT0Shift0(0.124797)
+  ,fT0Shift1(0.267451)
   ,fRangeFitPRF(1.0)
   ,fAccCDB(kFALSE)
   ,fMinEntries(800)
@@ -188,7 +189,8 @@ AliTRDCalibraFit::AliTRDCalibraFit(const AliTRDCalibraFit &c)
 ,fBeginFitCharge(c.fBeginFitCharge)
 ,fFitPHPeriode(c.fFitPHPeriode)
 ,fTakeTheMaxPH(c.fTakeTheMaxPH)
-,fT0Shift(c.fT0Shift)
+,fT0Shift0(c.fT0Shift0)
+,fT0Shift1(c.fT0Shift1)
 ,fRangeFitPRF(c.fRangeFitPRF)
 ,fAccCDB(c.fAccCDB)
 ,fMinEntries(c.fMinEntries)
@@ -245,7 +247,7 @@ AliTRDCalibraFit::AliTRDCalibraFit(const AliTRDCalibraFit &c)
     AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
     Int_t detector         = ((AliTRDFitInfo *)c.fVectorFit.UncheckedAt(k))->GetDetector();
     Int_t ntotal = 1;
-    if (GetChamber(detector) == 2) {
+    if (GetStack(detector) == 2) {
       ntotal = 1728;
     }
     else {
@@ -264,7 +266,7 @@ AliTRDCalibraFit::AliTRDCalibraFit(const AliTRDCalibraFit &c)
     AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
     Int_t detector         = ((AliTRDFitInfo *)c.fVectorFit2.UncheckedAt(k))->GetDetector();
     Int_t ntotal = 1;
-    if (GetChamber(detector) == 2) {
+    if (GetStack(detector) == 2) {
       ntotal = 1728;
     }
     else {
@@ -314,6 +316,28 @@ void AliTRDCalibraFit::Destroy()
     fgInstance = 0x0;
   }
 
+}
+//__________________________________________________________________________________
+void AliTRDCalibraFit::RangeChargeIntegration(Float_t vdrift, Float_t t0, Int_t &begin, Int_t &peak, Int_t &end)
+{
+  //
+  // From the drift velocity and t0
+  // return the position of the peak and maximum negative slope
+  //
+  
+  const Float_t kDrWidth = AliTRDgeometry::DrThick();    // drift region
+  Double_t widbins = 0.1;                                // 0.1 mus
+
+  //peak and maxnegslope in mus
+  Double_t begind = t0*widbins + fT0Shift0;
+  Double_t peakd  = t0*widbins + fT0Shift1;
+  Double_t maxnegslope = (kDrWidth + vdrift*peakd)/vdrift; 
+
+  // peak and maxnegslope in timebin
+  begin = TMath::Nint(begind*widbins);
+  peak  = TMath::Nint(peakd*widbins);
+  end   = TMath::Nint(maxnegslope*widbins); 
+
 }
 //____________Functions fit Online CH2d________________________________________
 Bool_t AliTRDCalibraFit::AnalyseCH(TH2I *ch)
@@ -450,9 +474,9 @@ Bool_t AliTRDCalibraFit::AnalyseCH(AliTRDCalibraVector *calvect)
     Bool_t something = kTRUE;
     if(!calvect->GetCHEntries(fCountDet)) something = kFALSE;
     if(something){
-      TString name("CH");
-      name += idect;
-      projch  = calvect->ConvertVectorCHHisto(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0)))),(const char *) name);
+      TString tname("CH");
+      tname += idect;
+      projch  = calvect->ConvertVectorCHHisto(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(0)*fCalibraMode->GetNfragRphi(0)))),(const char *) tname);
       projch->SetDirectory(0);
       for (Int_t k = 0; k < calvect->GetNumberBinCharge(); k++) {
         nentries += projch->GetBinContent(k+1);
@@ -638,9 +662,9 @@ Bool_t AliTRDCalibraFit::AnalysePH(AliTRDCalibraVector *calvect)
     Bool_t something = kTRUE;
     if(!calvect->GetPHEntries(fCountDet)) something = kFALSE;
     if(something){
-      TString name("PH");
-      name += idect;
-      projph  = CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPHTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) name)));
+      TString tname("PH");
+      tname += idect;
+      projph  = CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPHTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname)));
       projph->SetDirectory(0);
     }
     //printf("The number of entries for the group %d is %d\n",idect,fEntriesCurrent);
@@ -909,9 +933,9 @@ Bool_t AliTRDCalibraFit::AnalysePRF(AliTRDCalibraVector *calvect)
     Bool_t something = kTRUE;
     if(!calvect->GetPRFEntries(fCountDet)) something = kFALSE;
     if(something){
-      TString name("PRF");
-      name += idect;
-      projprf  = CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) name)));
+      TString tname("PRF");
+      tname += idect;
+      projprf  = CorrectTheError((TGraphErrors *) (calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname)));
       projprf->SetDirectory(0);
     }
     // This detector has not enough statistics or was off
@@ -1004,9 +1028,9 @@ Bool_t AliTRDCalibraFit::AnalysePRFMarianFit(AliTRDCalibraVector *calvect)
     Bool_t something = kTRUE;
     if(!calvect->GetPRFEntries(fCountDet)) something = kFALSE;
     if(something){
-      TString name("PRF");
-      name += idect;
-      projprftree  = calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) name);
+      TString tname("PRF");
+      tname += idect;
+      projprftree  = calvect->ConvertVectorPRFTGraphErrors(fCountDet,(idect-(fCount-(fCalibraMode->GetNfragZ(1)*fCalibraMode->GetNfragRphi(1)))),(const char *) tname);
       nbins   = projprftree->GetN();
       arrayx  = (Double_t *)projprftree->GetX();
       arraye  = (Double_t *)projprftree->GetEX();
@@ -1314,8 +1338,8 @@ AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectVdrift(TObjArray *vectorFit, Bool
     }
     else {
       Int_t   count = 0;
-      Int_t rowMax    = fGeo->GetRowMax(GetPlane(detector),GetChamber(detector),GetSector(detector));
-      Int_t colMax    = fGeo->GetColMax(GetPlane(detector));
+      Int_t rowMax    = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+      Int_t colMax    = fGeo->GetColMax(GetLayer(detector));
       for (Int_t row = 0; row < rowMax; row++) {
        for (Int_t col = 0; col < colMax; col++) {
          value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
@@ -1358,8 +1382,8 @@ AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectGain(TObjArray *vectorFit, Double
     }
     else{
       Int_t   count = 0;
-      Int_t rowMax    = fGeo->GetRowMax(GetPlane(detector),GetChamber(detector),GetSector(detector));
-      Int_t colMax    = fGeo->GetColMax(GetPlane(detector));
+      Int_t rowMax    = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+      Int_t colMax    = fGeo->GetColMax(GetLayer(detector));
       for (Int_t row = 0; row < rowMax; row++) {
        for (Int_t col = 0; col < colMax; col++) {
          value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
@@ -1399,8 +1423,8 @@ AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectT0(TObjArray *vectorFit, Bool_t p
       min = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[0];
     }
     else{
-      Int_t rowMax    = fGeo->GetRowMax(GetPlane(detector),GetChamber(detector),GetSector(detector));
-      Int_t colMax    = fGeo->GetColMax(GetPlane(detector));
+      Int_t rowMax    = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+      Int_t colMax    = fGeo->GetColMax(GetLayer(detector));
       for (Int_t row = 0; row < rowMax; row++) {
        for (Int_t col = 0; col < colMax; col++) {
          value = ((AliTRDFitInfo *) vectorFit->At(k))->GetCoef()[(Int_t)(col*rowMax+row)];
@@ -1435,8 +1459,8 @@ AliTRDCalDet *AliTRDCalibraFit::CreateDetObjectLorentzAngle(TObjArray *vectorFit
   for (Int_t k = 0; k < loop; k++) {
     detector  = ((AliTRDFitInfo *) vectorFit->At(k))->GetDetector();
     /*
-      Int_t rowMax    = fGeo->GetRowMax(GetPlane(detector),GetChamber(detector),GetSector(detector));
-      Int_t colMax    = fGeo->GetColMax(GetPlane(detector));
+      Int_t rowMax    = fGeo->GetRowMax(GetLayer(detector),GetStack(detector),GetSector(detector));
+      Int_t colMax    = fGeo->GetColMax(GetLayer(detector));
       Float_t min  = 100.0;
       for (Int_t row = 0; row < rowMax; row++) {
       for (Int_t col = 0; col < colMax; col++) {
@@ -1744,15 +1768,32 @@ void AliTRDCalibraFit::SetBeginFitCharge(Float_t beginFitCharge)
 }
 
 //_____________________________________________________________________________
-void AliTRDCalibraFit::SetT0Shift(Float_t t0Shift) 
+void AliTRDCalibraFit::SetT0Shift0(Float_t t0Shift) 
+{ 
+  //
+  // The t0 calculated with the maximum positif slope is shift from t0Shift0
+  // You can here set t0Shift0
+  //
+
+  if (t0Shift > 0) {
+    fT0Shift0 = t0Shift; 
+  } 
+  else {
+    AliInfo("t0Shift0 must be strict positif!");
+  }
+
+}
+
+//_____________________________________________________________________________
+void AliTRDCalibraFit::SetT0Shift1(Float_t t0Shift) 
 { 
   //
-  // The t0 calculated with the maximum positif slope is shift from t0Shift
-  // You can here set t0Shift
+  // The t0 calculated with the maximum of the amplification region is shift from t0Shift1
+  // You can here set t0Shift1
   //
 
   if (t0Shift > 0) {
-    fT0Shift = t0Shift; 
+    fT0Shift1 = t0Shift; 
   } 
   else {
     AliInfo("t0Shift must be strict positif!");
@@ -1821,7 +1862,7 @@ Bool_t AliTRDCalibraFit::FillVectorFit()
   AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
 
   Int_t ntotal = 1;
-  if (GetChamber(fCountDet) == 2) {
+  if (GetStack(fCountDet) == 2) {
     ntotal = 1728;
   }
   else {
@@ -1853,7 +1894,7 @@ Bool_t AliTRDCalibraFit::FillVectorFit2()
   AliTRDFitInfo *fitInfo = new AliTRDFitInfo();
 
   Int_t ntotal = 1;
-  if (GetChamber(fCountDet) == 2) {
+  if (GetStack(fCountDet) == 2) {
     ntotal = 1728;
   }
   else {
@@ -2118,10 +2159,10 @@ void AliTRDCalibraFit::InitfCountDetAndfCount(Int_t i)
     fCount    = fCalibraMode->GetXbins(i);
     fCountDet--;
     // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
-    fCalibraMode->ModePadCalibration((Int_t) GetChamber(fCountDet),i);
-    fCalibraMode->ModePadFragmentation((Int_t) GetPlane(fCountDet)
-                                      ,(Int_t) GetChamber(fCountDet)
-                                      ,(Int_t) GetSector(fCountDet),i);
+    fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
+    fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
+                                     ,(Int_t) GetStack(fCountDet)
+                                     ,(Int_t) GetSector(fCountDet),i);
   }
 }
 //_______________________________________________________________________________
@@ -2170,10 +2211,10 @@ void AliTRDCalibraFit::CalculDect1Dect2(Int_t i)
     fCalibraMode->CalculXBins(fCountDet,i);
     fDect1 = fCalibraMode->GetXbins(i);
     // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
-    fCalibraMode->ModePadCalibration((Int_t) GetChamber(fCountDet),i);
-    fCalibraMode->ModePadFragmentation((Int_t) GetPlane(fCountDet)
-                                      ,(Int_t) GetChamber(fCountDet)
-                                      ,(Int_t) GetSector(fCountDet),i);
+    fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
+    fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
+                                     ,(Int_t) GetStack(fCountDet)
+                                     ,(Int_t) GetSector(fCountDet),i);
     // Set for the next detector
     fDect2 = fDect1 + fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i);
   }
@@ -2207,10 +2248,10 @@ void AliTRDCalibraFit::UpdatefCountDetAndfCount(Int_t idect, Int_t i)
      // On en est au detector
      fCountDet += 1;
      // Determination of fNnZ, fNnRphi, fNfragZ and fNfragRphi
-     fCalibraMode->ModePadCalibration((Int_t) GetChamber(fCountDet),i);
-     fCalibraMode->ModePadFragmentation((Int_t) GetPlane(fCountDet)
-                               ,(Int_t) GetChamber(fCountDet)
-                          ,(Int_t) GetSector(fCountDet),i);
+     fCalibraMode->ModePadCalibration((Int_t) GetStack(fCountDet),i);
+     fCalibraMode->ModePadFragmentation((Int_t) GetLayer(fCountDet)
+                                      ,(Int_t) GetStack(fCountDet)
+                                       ,(Int_t) GetSector(fCountDet),i);
      // Set for the next detector
      fCount += fCalibraMode->GetNfragZ(i)*fCalibraMode->GetNfragRphi(i);
      // calib objects
@@ -2249,9 +2290,9 @@ Bool_t AliTRDCalibraFit::NotEnoughStatisticCH(Int_t idect)
     // Calcul the coef from the database choosen
     CalculChargeCoefMean(kFALSE);
 
-    //chamber 2, not chamber 2
+    //stack 2, not stack 2
     Int_t factor = 0;
-    if(GetChamber(fCountDet) == 2) factor = 12;
+    if(GetStack(fCountDet) == 2) factor = 12;
     else factor = 16;
     
     // Fill the fCurrentCoefDetector with negative value to say: not fitted
@@ -2291,9 +2332,9 @@ Bool_t AliTRDCalibraFit::NotEnoughStatisticPH(Int_t idect)
     CalculVdriftCoefMean();
     CalculT0CoefMean();
   
-    //chamber 2 and not chamber 2
+    //stack 2 and not stack 2
     Int_t factor = 0;
-    if(GetChamber(fCountDet) == 2) factor = 12;
+    if(GetStack(fCountDet) == 2) factor = 12;
     else factor = 16;
 
 
@@ -2339,9 +2380,9 @@ Bool_t AliTRDCalibraFit::NotEnoughStatisticPRF(Int_t idect)
     
     CalculPRFCoefMean();
     
-    // chamber 2 and not chamber 2
+    // stack 2 and not stack 2
     Int_t factor = 0;
-    if(GetChamber(fCountDet) == 2) factor = 12;
+    if(GetStack(fCountDet) == 2) factor = 12;
     else factor = 16;
 
     
@@ -2375,7 +2416,7 @@ Bool_t AliTRDCalibraFit::NotEnoughStatisticLinearFitter()
   CalculVdriftLorentzCoef();
 
   Int_t factor = 0;
-  if(GetChamber(fCountDet) == 2) factor = 1728;
+  if(GetStack(fCountDet) == 2) factor = 1728;
   else factor = 2304;
     
     
@@ -2409,7 +2450,7 @@ Bool_t AliTRDCalibraFit::FillInfosFitCH(Int_t idect)
   if (fDebugLevel != 1) {
     
     Int_t factor = 0;
-    if(GetChamber(fCountDet) == 2) factor = 12;
+    if(GetStack(fCountDet) == 2) factor = 12;
     else factor = 16; 
     
     for (Int_t k = fCalibraMode->GetRowMin(0); k < fCalibraMode->GetRowMax(0); k++) {
@@ -2436,7 +2477,7 @@ Bool_t AliTRDCalibraFit::FillInfosFitPH(Int_t idect)
   if (fDebugLevel != 1) {
 
     Int_t factor = 0;
-    if(GetChamber(fCountDet) == 2) factor = 12;
+    if(GetStack(fCountDet) == 2) factor = 12;
     else factor = 16; 
     
     for (Int_t k = fCalibraMode->GetRowMin(1); k < fCalibraMode->GetRowMax(1); k++) {
@@ -2460,7 +2501,7 @@ Bool_t AliTRDCalibraFit::FillInfosFitPRF(Int_t idect)
   if (fDebugLevel != 1) {
 
     Int_t factor = 0;
-    if(GetChamber(fCountDet) == 2) factor = 12;
+    if(GetStack(fCountDet) == 2) factor = 12;
     else factor = 16; 
     
     // Pointer to the branch
@@ -2484,7 +2525,7 @@ Bool_t AliTRDCalibraFit::FillInfosFitLinearFitter()
   //
   
   Int_t factor = 0;
-  if(GetChamber(fCountDet) == 2) factor = 1728;
+  if(GetStack(fCountDet) == 2) factor = 1728;
   else factor = 2304; 
   
   // Pointer to the branch
@@ -2533,7 +2574,7 @@ void AliTRDCalibraFit::FillFillCH(Int_t idect)
     Float_t gfs        = fCurrentCoef[1]; 
     Float_t gfE        = fCurrentCoefE;
     
-    (*fDebugStreamer) << "GAIN" <<
+    (*fDebugStreamer) << "FillFillCH" <<
       "detector=" << detector <<
       "caligroup=" << caligroup <<
       "rowmin=" << rowmin <<
@@ -2590,7 +2631,7 @@ void AliTRDCalibraFit::FillFillPH(Int_t idect)
    
 
 
-      (* fDebugStreamer) << "PH"<<
+      (* fDebugStreamer) << "FillFillPH"<<
        "detector="<<detector<<
        "caligroup="<<caligroup<<
        "rowmin="<<rowmin<<
@@ -2634,7 +2675,7 @@ void AliTRDCalibraFit::FillFillPRF(Int_t idect)
       } 
       
       Int_t   detector     = fCountDet;
-      Int_t   plane        = GetPlane(fCountDet);
+      Int_t   layer        = GetLayer(fCountDet);
       Int_t   caligroup    = idect;
       Short_t rowmin       = fCalibraMode->GetRowMin(2);
       Short_t rowmax       = fCalibraMode->GetRowMax(2);
@@ -2644,9 +2685,9 @@ void AliTRDCalibraFit::FillFillPRF(Int_t idect)
       Float_t wids         = fCurrentCoef[1]; 
       Float_t widfE        = fCurrentCoefE;
 
-      (* fDebugStreamer) << "PRF"<<
+      (* fDebugStreamer) << "FillFillPRF"<<
        "detector="<<detector<<
-       "plane="<<plane<<
+       "layer="<<layer<<
        "caligroup="<<caligroup<<
        "rowmin="<<rowmin<<
        "rowmax="<<rowmax<<
@@ -2688,13 +2729,13 @@ void AliTRDCalibraFit::FillFillLinearFitter()
     } 
     
     //Debug: comparaison of the different methods (okey for first time but not for iterative procedure)
-    AliTRDpadPlane *padplane = fGeo->GetPadPlane(GetPlane(fCountDet),GetChamber(fCountDet));
+    AliTRDpadPlane *padplane = fGeo->GetPadPlane(GetLayer(fCountDet),GetStack(fCountDet));
     Float_t rowmd            = (padplane->GetRow0()+padplane->GetRowEnd())/2.;
-    Float_t r                = AliTRDgeometry::GetTime0(GetPlane(fCountDet)); 
+    Float_t r                = AliTRDgeometry::GetTime0(GetLayer(fCountDet)); 
     Float_t tiltangle        = padplane->GetTiltingAngle();
     Int_t   detector         = fCountDet;
-    Int_t   chamber          = GetChamber(fCountDet);
-    Int_t   plane            = GetChamber(fCountDet);
+    Int_t   stack            = GetStack(fCountDet);
+    Int_t   layer            = GetLayer(fCountDet);
     Float_t vf               = fCurrentCoef[0]; 
     Float_t vs               = fCurrentCoef[1]; 
     Float_t vfE              = fCurrentCoefE;
@@ -2702,10 +2743,10 @@ void AliTRDCalibraFit::FillFillLinearFitter()
     Float_t elorentzangler   = fCurrentCoefE2;
     Float_t lorentzangles    = fCurrentCoef2[1];
    
-    (* fDebugStreamer) << "LinearFitter"<<
+    (* fDebugStreamer) << "FillFillLinearFitter"<<
       "detector="<<detector<<
-      "chamber="<<chamber<<
-      "plane="<<plane<<
+      "stack="<<stack<<
+      "layer="<<layer<<
       "rowmd="<<rowmd<<
       "r="<<r<<
       "tiltangle="<<tiltangle<<
@@ -2746,12 +2787,12 @@ Bool_t AliTRDCalibraFit::CalculT0CoefMean()
        fCurrentCoef2[1] = fCalDet2->GetValue(fCountDet);
       }
       else{
-       for(Int_t row = 0; row < fGeo->GetRowMax(GetPlane(fCountDet),GetChamber(fCountDet),GetSector(fCountDet)); row++){
-         for(Int_t col = 0; col < fGeo->GetColMax(GetPlane(fCountDet)); col++){
+       for(Int_t row = 0; row < fGeo->GetRowMax(GetLayer(fCountDet),GetStack(fCountDet),GetSector(fCountDet)); row++){
+         for(Int_t col = 0; col < fGeo->GetColMax(GetLayer(fCountDet)); col++){
            fCurrentCoef2[1] += (Float_t) (fCalROC2->GetValue(col,row)+fCalDet2->GetValue(fCountDet));
          }
        }
-       fCurrentCoef2[1] = fCurrentCoef2[1] / ((fGeo->GetRowMax(GetPlane(fCountDet),GetChamber(fCountDet),GetSector(fCountDet)))*(fGeo->GetColMax(GetPlane(fCountDet))));
+       fCurrentCoef2[1] = fCurrentCoef2[1] / ((fGeo->GetRowMax(GetLayer(fCountDet),GetStack(fCountDet),GetSector(fCountDet)))*(fGeo->GetColMax(GetLayer(fCountDet))));
       }
     }
   }
@@ -2844,12 +2885,12 @@ Bool_t AliTRDCalibraFit::CalculVdriftLorentzCoef()
   return kTRUE;
 }
 //_____________________________________________________________________________
-Float_t AliTRDCalibraFit::GetPRFDefault(Int_t plane) const
+Float_t AliTRDCalibraFit::GetPRFDefault(Int_t layer) const
 {
   //
   // Default width of the PRF if there is no database as reference
   //
-  switch(plane)
+  switch(layer)
     {
       // default database
       //case 0:  return 0.515;
@@ -2909,7 +2950,7 @@ void AliTRDCalibraFit::SetCalROC(Int_t i)
       {
       case 0:
        if(fCalROC) delete fCalROC;
-       fCalROC = new AliTRDCalROC(GetPlane(fCountDet),GetChamber(fCountDet)); 
+       fCalROC = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet)); 
        for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
          fCalROC->SetValue(k,1.0);
        }
@@ -2917,8 +2958,8 @@ void AliTRDCalibraFit::SetCalROC(Int_t i)
       case 1:
        if(fCalROC)  delete fCalROC;
        if(fCalROC2) delete fCalROC2;
-       fCalROC  = new AliTRDCalROC(GetPlane(fCountDet),GetChamber(fCountDet));
-       fCalROC2 = new AliTRDCalROC(GetPlane(fCountDet),GetChamber(fCountDet));
+       fCalROC  = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
+       fCalROC2 = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet));
        for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
          fCalROC->SetValue(k,1.0);
          fCalROC2->SetValue(k,0.0);
@@ -2926,8 +2967,8 @@ void AliTRDCalibraFit::SetCalROC(Int_t i)
        break;
       case 2:
        if(fCalROC) delete fCalROC;
-       value = GetPRFDefault(GetPlane(fCountDet));
-       fCalROC = new AliTRDCalROC(GetPlane(fCountDet),GetChamber(fCountDet)); 
+       value = GetPRFDefault(GetLayer(fCountDet));
+       fCalROC = new AliTRDCalROC(GetLayer(fCountDet),GetStack(fCountDet)); 
        for(Int_t k = 0; k < fCalROC->GetNchannels(); k++){
          fCalROC->SetValue(k,value);
        }
@@ -3060,9 +3101,16 @@ void AliTRDCalibraFit::FitPente(TH1* projPH)
   if((l3P1dr != 0.0) && (l3P2dr != 0.0)){
     fCurrentCoefE += (l3P1drE/l3P1dr + l3P2drE/l3P2dr)*fPhd[2]; 
   }
-  Float_t fPhdt0 = 0.0;
-  if(fTakeTheMaxPH) fPhdt0 = fPhd[1];
-  else fPhdt0 = fPhd[0];
+  Float_t fPhdt0  = 0.0;
+  Float_t t0Shift = 0.0;
+  if(fTakeTheMaxPH) {
+    fPhdt0 = fPhd[1];
+    t0Shift = fT0Shift1;
+  }
+  else {
+    fPhdt0 = fPhd[0];
+    t0Shift = fT0Shift0;
+  }
 
   if ((fPhd[2] > fPhd[0]) && 
       (fPhd[2] > fPhd[1]) && 
@@ -3072,7 +3120,7 @@ void AliTRDCalibraFit::FitPente(TH1* projPH)
     fNumberFitSuccess++;
 
     if (fPhdt0 >= 0.0) {
-      fCurrentCoef2[0] = (fPhdt0 - fT0Shift) / widbins;
+      fCurrentCoef2[0] = (fPhdt0 - t0Shift) / widbins;
       if (fCurrentCoef2[0] < -1.0) {
         fCurrentCoef2[0] = fCurrentCoef2[1];
       }
@@ -3581,9 +3629,16 @@ void AliTRDCalibraFit::FitLagrangePoly(TH1* projPH)
     fPhd[2] = placeminimum;
   }
   
-  Float_t fPhdt0 = 0.0;
-  if(fTakeTheMaxPH) fPhdt0 = fPhd[1];
-  else fPhdt0 = fPhd[0];
+  Float_t fPhdt0  = 0.0;
+  Float_t t0Shift = 0.0;
+  if(fTakeTheMaxPH) {
+    fPhdt0 = fPhd[1];
+    t0Shift = fT0Shift1;
+  }
+  else {
+    fPhdt0 = fPhd[0];
+    t0Shift = fT0Shift0;
+  }
 
   if ((fPhd[2] > fPhd[0]) && 
       (fPhd[2] > fPhd[1]) && 
@@ -3592,7 +3647,7 @@ void AliTRDCalibraFit::FitLagrangePoly(TH1* projPH)
     fCurrentCoef[0] = (kDrWidth) / (fPhd[2]-fPhd[1]);
     fNumberFitSuccess++;
     if (fPhdt0 >= 0.0) {
-      fCurrentCoef2[0] = (fPhdt0 - fT0Shift) / widbins;
+      fCurrentCoef2[0] = (fPhdt0 - t0Shift) / widbins;
       if (fCurrentCoef2[0] < -1.0) {
         fCurrentCoef2[0] = fCurrentCoef2[1];
       }
@@ -3751,7 +3806,7 @@ Bool_t AliTRDCalibraFit::FitPRFGausMI(Double_t *arraye, Double_t *arraym, Double
   }
 }
 //_____________________________________________________________________________
-Double_t AliTRDCalibraFit::FitGausMI(Double_t *arraye, Double_t *arraym, Double_t *arrayme, Int_t nBins, Float_t xMin, Float_t xMax, TVectorD *param, Bool_t kError)
+Double_t AliTRDCalibraFit::FitGausMI(Double_t *arraye, Double_t *arraym, Double_t *arrayme, Int_t nBins, Float_t xMin, Float_t xMax, TVectorD *param, Bool_t bError)
 {
   //
   // Fit methode for the sigma of the pad response function
@@ -3792,7 +3847,7 @@ Double_t AliTRDCalibraFit::FitGausMI(Double_t *arraye, Double_t *arraym, Double_
        errorm   = 0.0;
        errorn   = 0.0;
        error    = 0.0;
-       if(!kError){
+       if(!bError){
          if((valueI + 0.01) > 0.0) errorm = TMath::Log((valueI + 0.01)/valueI);
          if((valueI - 0.01) > 0.0) errorn = TMath::Log((valueI - 0.01)/valueI);
          error = TMath::Max(TMath::Abs(errorm),TMath::Abs(errorn));
@@ -3818,12 +3873,12 @@ Double_t AliTRDCalibraFit::FitGausMI(Double_t *arraye, Double_t *arraym, Double_
       } 
       
       Int_t    detector     = fCountDet;
-      Int_t    plane        = GetPlane(fCountDet);
+      Int_t    layer        = GetLayer(fCountDet);
       Int_t    group        = ibin;    
      
       (* fDebugStreamer) << "FitGausMIFill"<<
        "detector="<<detector<<
-       "plane="<<plane<<
+       "layer="<<layer<<
        "nbins="<<nBins<<
        "group="<<group<<
        "entriesI="<<entriesI<<
@@ -3833,7 +3888,7 @@ Double_t AliTRDCalibraFit::FitGausMI(Double_t *arraye, Double_t *arraym, Double_
        "errorm="<<errorm<<
        "errorn="<<errorn<<
        "error="<<error<<
-       "kError="<<kError<<
+       "bError="<<bError<<
        "\n";  
     }
 
@@ -3871,12 +3926,12 @@ Double_t AliTRDCalibraFit::FitGausMI(Double_t *arraye, Double_t *arraym, Double_
       } 
       
       Int_t    detector     = fCountDet;
-      Int_t    plane        = GetPlane(fCountDet);
+      Int_t    layer        = GetLayer(fCountDet);
            
      
       (* fDebugStreamer) << "FitGausMIFit"<<
        "detector="<<detector<<
-       "plane="<<plane<<
+       "layer="<<layer<<
        "nbins="<<nBins<<
        "errorsigma="<<chi2<<
        "mean="<<(*param)[1]<<
@@ -3887,7 +3942,7 @@ Double_t AliTRDCalibraFit::FitGausMI(Double_t *arraye, Double_t *arraym, Double_
   }
 
   if((chi2/(*param)[2]) > 0.1){
-    if(kError){
+    if(bError){
       chi2 = FitGausMI(arraye,arraym,arrayme,nBins,xMin,xMax,param,kFALSE);
     }
     else return -4.0;
@@ -4000,7 +4055,7 @@ void AliTRDCalibraFit::FitTnpRange(Double_t *arraye, Double_t *arraym, Double_t
       } 
       
       Int_t    detector     = fCountDet;
-      Int_t    plane        = GetPlane(fCountDet);
+      Int_t    layer        = GetLayer(fCountDet);
       Int_t    nbtotal      = total;  
       Int_t    group        = k;    
       Float_t  low          = lowedge;
@@ -4009,9 +4064,9 @@ void AliTRDCalibraFit::FitTnpRange(Double_t *arraye, Double_t *arraym, Double_t
       Float_t  wid          = fCurrentCoef[0];
       Float_t  widfE        = fCurrentCoefE;
 
-      (* fDebugStreamer) << "FitTnpRangeFill"<<
+      (* fDebugStreamer) << "FitTnpRange0"<<
        "detector="<<detector<<
-       "plane="<<plane<<
+       "layer="<<layer<<
        "nbtotal="<<nbtotal<<
        "group="<<group<<
        "low="<<low<<
@@ -4081,14 +4136,14 @@ void AliTRDCalibraFit::FitTnpRange(Double_t *arraye, Double_t *arraym, Double_t
       } 
       
       Int_t    detector     = fCountDet;
-      Int_t    plane        = GetPlane(fCountDet);
+      Int_t    layer        = GetLayer(fCountDet);
       Int_t    nbtotal      = total;
       Double_t colsize[6]   = {0.635,0.665,0.695,0.725,0.755,0.785};  
-      Double_t sigmax       = TMath::Sqrt(TMath::Abs(pars0[2]))*10000*colsize[plane];      
+      Double_t sigmax       = TMath::Sqrt(TMath::Abs(pars0[2]))*10000*colsize[layer];      
 
-      (* fDebugStreamer) << "FitTnpRangeFit"<<
+      (* fDebugStreamer) << "FitTnpRange1"<<
        "detector="<<detector<<
-       "plane="<<plane<<
+       "layer="<<layer<<
        "nbtotal="<<nbtotal<<
        "par0="<<pars0[0]<<
        "par1="<<pars0[1]<<
@@ -4479,10 +4534,10 @@ void AliTRDCalibraFit::NormierungCharge()
     Int_t    detector = ((AliTRDFitInfo *) fVectorFit.At(k))->GetDetector();
     Float_t *coef     = ((AliTRDFitInfo *) fVectorFit.At(k))->GetCoef();
     //printf("detector %d coef[0] %f\n",detector,coef[0]);
-    if (GetChamber(detector) == 2) {
+    if (GetStack(detector) == 2) {
       total = 1728;
     }
-    if (GetChamber(detector) != 2) {
+    if (GetStack(detector) != 2) {
       total = 2304;
     }
     for (Int_t j = 0; j < total; j++) {
@@ -4510,7 +4565,7 @@ void AliTRDCalibraFit::NormierungCharge()
       fDebugStreamer = new TTreeSRedirector("TRDDebugFit.root");
       if ( backup ) backup->cd();  //we don't want to be cd'd to the debug streamer
     } 
-    (* fDebugStreamer) << "ScaleFactor"<<
+    (* fDebugStreamer) << "NormierungCharge"<<
       "scalefactor="<<scalefactor<<
       "\n";  
     }
@@ -4624,7 +4679,7 @@ TH1F *AliTRDCalibraFit::CorrectTheError(TGraphErrors *hist)
 //
 
 //_____________________________________________________________________________
-Int_t AliTRDCalibraFit::GetPlane(Int_t d) const
+Int_t AliTRDCalibraFit::GetLayer(Int_t d) const
 {
   //
   // Reconstruct the plane number from the detector number
@@ -4635,14 +4690,14 @@ Int_t AliTRDCalibraFit::GetPlane(Int_t d) const
 }
 
 //_____________________________________________________________________________
-Int_t AliTRDCalibraFit::GetChamber(Int_t d) const
+Int_t AliTRDCalibraFit::GetStack(Int_t d) const
 {
   //
-  // Reconstruct the chamber number from the detector number
+  // Reconstruct the stack number from the detector number
   //
-  Int_t fgkNplan = 6;
+  const Int_t kNlayer = 6;
 
-  return ((Int_t) (d % 30) / fgkNplan);
+  return ((Int_t) (d % 30) / kNlayer);
 
 }