]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TPC/AliTPCClusterParam.cxx
Correct assignment of clusters to the catgeory ALL, which was in fact wrongly filled...
[u/mrichter/AliRoot.git] / TPC / AliTPCClusterParam.cxx
index 4b044d26b4169c0778ee6c1ce569d61cf684c62c..ab29b113138ea56e09ff2e6ae433227c4a52b1f7 100644 (file)
@@ -91,12 +91,15 @@ AliTPCClusterParam::SetInstance(param);
 #include <TVectorF.h>
 #include <TLinearFitter.h>
 #include <TH1F.h>
+#include <TH3F.h>
 #include <TProfile2D.h>
 #include <TVectorD.h>
 #include <TObjArray.h>
 #include "AliTPCcalibDB.h"
 #include "AliTPCParam.h"
 
+#include "AliMathBase.h"
+
 ClassImp(AliTPCClusterParam)
 
 
@@ -147,6 +150,8 @@ AliTPCClusterParam::AliTPCClusterParam():
   TObject(),
   fRatio(0),
   fQNorm(0),
+  fQNormCorr(0),
+  fQNormHis(0),
   fQpadTnorm(0),           // q pad normalization - Total charge
   fQpadMnorm(0)            // q pad normalization - Max charge
   //
@@ -159,12 +164,15 @@ AliTPCClusterParam::AliTPCClusterParam():
   //
   fPosYcor[0]   = 0;   fPosYcor[1]   = 0;   fPosYcor[2]   = 0; 
   fPosZcor[0]   = 0;   fPosZcor[1]   = 0;   fPosZcor[2]   = 0; 
+  fErrorRMSSys[0]=0;   fErrorRMSSys[1]=0; 
 }
 
 AliTPCClusterParam::AliTPCClusterParam(const AliTPCClusterParam& param):
   TObject(param),
   fRatio(0),
   fQNorm(0),
+  fQNormCorr(0),
+  fQNormHis(0),
   fQpadTnorm(new TVectorD(*(param.fQpadTnorm))),           // q pad normalization - Total charge
   fQpadMnorm(new TVectorD(*(param.fQpadMnorm)))            // q pad normalization - Max charge
 
@@ -174,6 +182,7 @@ AliTPCClusterParam::AliTPCClusterParam(const AliTPCClusterParam& param):
   //
   memcpy(this, &param,sizeof(AliTPCClusterParam));
   if (param.fQNorm) fQNorm = (TObjArray*) param.fQNorm->Clone();
+  if (param.fQNormHis) fQNormHis = (TObjArray*) param.fQNormHis->Clone();
   //
   if (param.fPosQTnorm[0]){
     fPosQTnorm[0] = new TVectorD(*(param.fPosQTnorm[0]));
@@ -204,6 +213,7 @@ AliTPCClusterParam & AliTPCClusterParam::operator=(const AliTPCClusterParam& par
   if (this != &param) {
     memcpy(this, &param,sizeof(AliTPCClusterParam));
     if (param.fQNorm) fQNorm = (TObjArray*) param.fQNorm->Clone();
+    if (param.fQNormHis) fQNormHis = (TObjArray*) param.fQNormHis->Clone();
     if (param.fPosQTnorm[0]){
       fPosQTnorm[0] = new TVectorD(*(param.fPosQTnorm[0]));
       fPosQTnorm[1] = new TVectorD(*(param.fPosQTnorm[1]));
@@ -232,7 +242,10 @@ AliTPCClusterParam::~AliTPCClusterParam(){
   // destructor
   //
   if (fQNorm) fQNorm->Delete();
+  if (fQNormCorr) delete fQNormCorr;
+  if (fQNormHis) fQNormHis->Delete();
   delete fQNorm;
+  delete fQNormHis;
   if (fPosQTnorm[0]){
     delete fPosQTnorm[0];
     delete fPosQTnorm[1];
@@ -259,24 +272,24 @@ void AliTPCClusterParam::FitResol0(TTree * tree, Int_t dim, Int_t type, Float_t
   // Fit z - angular dependence of resolution 
   //
   // Int_t dim=0, type=0;
-  char varVal[100];
-  sprintf(varVal,"Resol:AngleM:Zm");
-  char varErr[100];
-  sprintf(varErr,"Sigma:AngleS:Zs");
-  char varCut[100];
-  sprintf(varCut,"Dim==%d&&Pad==%d&&QMean<0",dim,type);
-  //
-  Int_t entries = tree->Draw(varVal,varCut);
+  TString varVal;
+  varVal="Resol:AngleM:Zm";
+  TString varErr;
+  varErr="Sigma:AngleS:Zs";
+  TString varCut;
+  varCut=Form("Dim==%d&&Pad==%d&&QMean<0",dim,type);
+  //
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[10000], py[10000], pz[10000];
   Float_t ex[10000], ey[10000], ez[10000];
   //
-  tree->Draw(varErr,varCut);  
+  tree->Draw(varErr.Data(),varCut);  
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     ex[ipoint]= tree->GetV3()[ipoint];
     ey[ipoint]= tree->GetV2()[ipoint];
     ez[ipoint]= tree->GetV1()[ipoint];
   } 
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV3()[ipoint];
     py[ipoint]= tree->GetV2()[ipoint];
@@ -312,24 +325,24 @@ void AliTPCClusterParam::FitResol0Par(TTree * tree, Int_t dim, Int_t type, Float
   // Fit z - angular dependence of resolution 
   //
   // Int_t dim=0, type=0;
 char varVal[100];
-  sprintf(varVal,"Resol:AngleM:Zm");
 char varErr[100];
-  sprintf(varErr,"Sigma:AngleS:Zs");
 char varCut[100];
-  sprintf(varCut,"Dim==%d&&Pad==%d&&QMean<0",dim,type);
-  //
-  Int_t entries = tree->Draw(varVal,varCut);
TString varVal;
+  varVal="Resol:AngleM:Zm";
TString varErr;
+  varErr="Sigma:AngleS:Zs";
TString varCut;
+  varCut=Form("Dim==%d&&Pad==%d&&QMean<0",dim,type);
+  //
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[10000], py[10000], pz[10000];
   Float_t ex[10000], ey[10000], ez[10000];
   //
-  tree->Draw(varErr,varCut);  
+  tree->Draw(varErr.Data(),varCut);  
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     ex[ipoint]= tree->GetV3()[ipoint];
     ey[ipoint]= tree->GetV2()[ipoint];
     ez[ipoint]= tree->GetV1()[ipoint];
   } 
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV3()[ipoint];
     py[ipoint]= tree->GetV2()[ipoint];
@@ -377,24 +390,24 @@ void AliTPCClusterParam::FitResol1(TTree * tree, Int_t dim, Float_t *param0, Flo
   // Fit z - angular dependence of resolution - pad length scaling 
   //
   // Int_t dim=0, type=0;
 char varVal[100];
-  sprintf(varVal,"Resol:AngleM*sqrt(Length):Zm/Length");
 char varErr[100];
-  sprintf(varErr,"Sigma:AngleS:Zs");
 char varCut[100];
-  sprintf(varCut,"Dim==%d&&QMean<0",dim);
-  //
-  Int_t entries = tree->Draw(varVal,varCut);
TString varVal;
+  varVal="Resol:AngleM*sqrt(Length):Zm/Length";
TString varErr;
+  varErr="Sigma:AngleS:Zs";
TString varCut;
+  varCut=Form("Dim==%d&&QMean<0",dim);
+  //
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[10000], py[10000], pz[10000];
   Float_t ex[10000], ey[10000], ez[10000];
   //
-  tree->Draw(varErr,varCut);  
+  tree->Draw(varErr.Data(),varCut);  
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     ex[ipoint]= tree->GetV3()[ipoint];
     ey[ipoint]= tree->GetV2()[ipoint];
     ez[ipoint]= tree->GetV1()[ipoint];
   } 
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV3()[ipoint];
     py[ipoint]= tree->GetV2()[ipoint];
@@ -429,27 +442,27 @@ void AliTPCClusterParam::FitResolQ(TTree * tree, Int_t dim, Int_t type, Float_t
   // Fit z - angular dependence of resolution - Q scaling 
   //
   // Int_t dim=0, type=0;
 char varVal[100];
-  sprintf(varVal,"Resol:AngleM/sqrt(QMean):Zm/QMean");
TString varVal;
+  varVal="Resol:AngleM/sqrt(QMean):Zm/QMean";
   char varVal0[100];
-  sprintf(varVal0,"Resol:AngleM:Zm");
+  snprintf(varVal0,100,"Resol:AngleM:Zm");
   //
 char varErr[100];
-  sprintf(varErr,"Sigma:AngleS:Zs");
 char varCut[100];
-  sprintf(varCut,"Dim==%d&&Pad==%d&&QMean>0",dim,type);
TString varErr;
+  varErr="Sigma:AngleS:Zs";
TString varCut;
+  varCut=Form("Dim==%d&&Pad==%d&&QMean>0",dim,type);
   //
-  Int_t entries = tree->Draw(varVal,varCut);
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[20000], py[20000], pz[20000], pu[20000], pt[20000];
   Float_t ex[20000], ey[20000], ez[20000];
   //
-  tree->Draw(varErr,varCut);  
+  tree->Draw(varErr.Data(),varCut);  
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     ex[ipoint]= tree->GetV3()[ipoint];
     ey[ipoint]= tree->GetV2()[ipoint];
     ez[ipoint]= tree->GetV1()[ipoint];
   } 
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV3()[ipoint];
     py[ipoint]= tree->GetV2()[ipoint];
@@ -496,27 +509,27 @@ void AliTPCClusterParam::FitResolQPar(TTree * tree, Int_t dim, Int_t type, Float
   // Fit z - angular dependence of resolution - Q scaling  - parabolic correction
   //
   // Int_t dim=0, type=0;
 char varVal[100];
-  sprintf(varVal,"Resol:AngleM/sqrt(QMean):Zm/QMean");
TString varVal;
+  varVal="Resol:AngleM/sqrt(QMean):Zm/QMean";
   char varVal0[100];
-  sprintf(varVal0,"Resol:AngleM:Zm");
+  snprintf(varVal0,100,"Resol:AngleM:Zm");
   //
 char varErr[100];
-  sprintf(varErr,"Sigma:AngleS:Zs");
 char varCut[100];
-  sprintf(varCut,"Dim==%d&&Pad==%d&&QMean>0",dim,type);
TString varErr;
+  varErr="Sigma:AngleS:Zs";
TString varCut;
+  varCut=Form("Dim==%d&&Pad==%d&&QMean>0",dim,type);
   //
-  Int_t entries = tree->Draw(varVal,varCut);
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[20000], py[20000], pz[20000], pu[20000], pt[20000];
   Float_t ex[20000], ey[20000], ez[20000];
   //
-  tree->Draw(varErr,varCut);  
+  tree->Draw(varErr.Data(),varCut);  
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     ex[ipoint]= tree->GetV3()[ipoint];
     ey[ipoint]= tree->GetV2()[ipoint];
     ez[ipoint]= tree->GetV1()[ipoint];
   } 
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV3()[ipoint];
     py[ipoint]= tree->GetV2()[ipoint];
@@ -576,24 +589,24 @@ void AliTPCClusterParam::FitRMS0(TTree * tree, Int_t dim, Int_t type, Float_t *p
   // Fit z - angular dependence of resolution 
   //
   // Int_t dim=0, type=0;
 char varVal[100];
-  sprintf(varVal,"RMSm:AngleM:Zm");
 char varErr[100];
-  sprintf(varErr,"sqrt((1./(100.*sqrt(12.))^2)+RMSe0^2):AngleS:Zs");
 char varCut[100];
-  sprintf(varCut,"Dim==%d&&Pad==%d&&QMean<0",dim,type);
-  //
-  Int_t entries = tree->Draw(varVal,varCut);
TString varVal;
+  varVal="RMSm:AngleM:Zm";
TString varErr;
+  varErr="sqrt((1./(100.*sqrt(12.))^2)+RMSe0^2):AngleS:Zs";
TString varCut;
+  varCut=Form("Dim==%d&&Pad==%d&&QMean<0",dim,type);
+  //
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[10000], py[10000], pz[10000];
   Float_t ex[10000], ey[10000], ez[10000];
   //
-  tree->Draw(varErr,varCut);  
+  tree->Draw(varErr.Data(),varCut);  
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     ex[ipoint]= tree->GetV3()[ipoint];
     ey[ipoint]= tree->GetV2()[ipoint];
     ez[ipoint]= tree->GetV1()[ipoint];
   } 
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV3()[ipoint];
     py[ipoint]= tree->GetV2()[ipoint];
@@ -628,24 +641,24 @@ void AliTPCClusterParam::FitRMS1(TTree * tree, Int_t dim, Float_t *param0, Float
   // Fit z - angular dependence of resolution - pad length scaling 
   //
   // Int_t dim=0, type=0;
 char varVal[100];
-  sprintf(varVal,"RMSm:AngleM*Length:Zm");
 char varErr[100];
-  sprintf(varErr,"sqrt((1./(100.*sqrt(12.))^2)+RMSe0^2):AngleS:Pad");
 char varCut[100];
-  sprintf(varCut,"Dim==%d&&QMean<0",dim);
-  //
-  Int_t entries = tree->Draw(varVal,varCut);
TString varVal;
+  varVal="RMSm:AngleM*Length:Zm";
TString varErr;
+  varErr="sqrt((1./(100.*sqrt(12.))^2)+RMSe0^2):AngleS:Pad";
TString varCut;
+  varCut=Form("Dim==%d&&QMean<0",dim);
+  //
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[10000], py[10000], pz[10000];
   Float_t type[10000], ey[10000], ez[10000];
   //
-  tree->Draw(varErr,varCut);  
+  tree->Draw(varErr.Data(),varCut);  
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     type[ipoint] = tree->GetV3()[ipoint];
     ey[ipoint]   = tree->GetV2()[ipoint];
     ez[ipoint]   = tree->GetV1()[ipoint];
   } 
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV3()[ipoint];
     py[ipoint]= tree->GetV2()[ipoint];
@@ -683,27 +696,27 @@ void AliTPCClusterParam::FitRMSQ(TTree * tree, Int_t dim, Int_t type, Float_t *p
   // Fit z - angular dependence of resolution - Q scaling 
   //
   // Int_t dim=0, type=0;
 char varVal[100];
-  sprintf(varVal,"RMSm:AngleM/sqrt(QMean):Zm/QMean");
TString varVal;
+  varVal="RMSm:AngleM/sqrt(QMean):Zm/QMean";
   char varVal0[100];
-  sprintf(varVal0,"RMSm:AngleM:Zm");
+  snprintf(varVal0,100,"RMSm:AngleM:Zm");
   //
 char varErr[100];
-  sprintf(varErr,"sqrt((1./(100.*sqrt(12.))^2)+RMSe0^2):AngleS:Zs");
 char varCut[100];
-  sprintf(varCut,"Dim==%d&&Pad==%d&&QMean>0",dim,type);
TString varErr;
+  varErr="sqrt((1./(100.*sqrt(12.))^2)+RMSe0^2):AngleS:Zs";
TString varCut;
+  varCut=Form("Dim==%d&&Pad==%d&&QMean>0",dim,type);
   //
-  Int_t entries = tree->Draw(varVal,varCut);
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[20000], py[20000], pz[20000], pu[20000], pt[20000];
   Float_t ex[20000], ey[20000], ez[20000];
   //
-  tree->Draw(varErr,varCut);  
+  tree->Draw(varErr.Data(),varCut);  
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     ex[ipoint]= tree->GetV3()[ipoint];
     ey[ipoint]= tree->GetV2()[ipoint];
     ez[ipoint]= tree->GetV1()[ipoint];
   } 
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV3()[ipoint];
     py[ipoint]= tree->GetV2()[ipoint];
@@ -751,16 +764,16 @@ void AliTPCClusterParam::FitRMSSigma(TTree * tree, Int_t dim, Int_t type, Float_
   // Fit z - angular dependence of resolution - Q scaling 
   //
   // Int_t dim=0, type=0;
-  char varVal[100];
-  sprintf(varVal,"RMSs:RMSm");
+  TString varVal;
+  varVal="RMSs:RMSm";
   //
 char varCut[100];
-  sprintf(varCut,"Dim==%d&&Pad==%d&&QMean<0",dim,type);
TString varCut;
+  varCut=Form("Dim==%d&&Pad==%d&&QMean<0",dim,type);
   //
-  Int_t entries = tree->Draw(varVal,varCut);
+  Int_t entries = tree->Draw(varVal.Data(),varCut);
   Float_t px[20000], py[20000];
   //
-  tree->Draw(varVal,varCut);
+  tree->Draw(varVal.Data(),varCut);
   for (Int_t ipoint=0; ipoint<entries; ipoint++){
     px[ipoint]= tree->GetV2()[ipoint];
     py[ipoint]= tree->GetV1()[ipoint];
@@ -780,7 +793,7 @@ void AliTPCClusterParam::FitRMSSigma(TTree * tree, Int_t dim, Int_t type, Float_
 
 
 
-Float_t  AliTPCClusterParam::GetError0(Int_t dim, Int_t type, Float_t z, Float_t angle){
+Float_t  AliTPCClusterParam::GetError0(Int_t dim, Int_t type, Float_t z, Float_t angle) const {
   //
   //
   //
@@ -793,7 +806,7 @@ Float_t  AliTPCClusterParam::GetError0(Int_t dim, Int_t type, Float_t z, Float_t
 }
 
 
-Float_t  AliTPCClusterParam::GetError0Par(Int_t dim, Int_t type, Float_t z, Float_t angle){
+Float_t  AliTPCClusterParam::GetError0Par(Int_t dim, Int_t type, Float_t z, Float_t angle) const {
   //
   //
   //
@@ -810,7 +823,7 @@ Float_t  AliTPCClusterParam::GetError0Par(Int_t dim, Int_t type, Float_t z, Floa
 
 
 
-Float_t  AliTPCClusterParam::GetError1(Int_t dim, Int_t type, Float_t z, Float_t angle){
+Float_t  AliTPCClusterParam::GetError1(Int_t dim, Int_t type, Float_t z, Float_t angle) const {
   //
   //
   //
@@ -825,7 +838,7 @@ Float_t  AliTPCClusterParam::GetError1(Int_t dim, Int_t type, Float_t z, Float_t
   return value;
 }
 
-Float_t  AliTPCClusterParam::GetErrorQ(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean){
+Float_t  AliTPCClusterParam::GetErrorQ(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean) const {
   //
   //
   //
@@ -841,7 +854,7 @@ Float_t  AliTPCClusterParam::GetErrorQ(Int_t dim, Int_t type, Float_t z, Float_t
 
 }
 
-Float_t  AliTPCClusterParam::GetErrorQPar(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean){
+Float_t  AliTPCClusterParam::GetErrorQPar(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean) const {
   //
   //
   //
@@ -860,7 +873,7 @@ Float_t  AliTPCClusterParam::GetErrorQPar(Int_t dim, Int_t type, Float_t z, Floa
 
 }
 
-Float_t  AliTPCClusterParam::GetErrorQParScaled(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean){
+Float_t  AliTPCClusterParam::GetErrorQParScaled(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean) const {
   //
   //
   //
@@ -881,7 +894,7 @@ Float_t  AliTPCClusterParam::GetErrorQParScaled(Int_t dim, Int_t type, Float_t z
 
 }
 
-Float_t  AliTPCClusterParam::GetRMS0(Int_t dim, Int_t type, Float_t z, Float_t angle){
+Float_t  AliTPCClusterParam::GetRMS0(Int_t dim, Int_t type, Float_t z, Float_t angle) const {
   //
   // calculate mean RMS of cluster - z,angle - parameters for each pad and dimension separatelly
   //
@@ -893,7 +906,7 @@ Float_t  AliTPCClusterParam::GetRMS0(Int_t dim, Int_t type, Float_t z, Float_t a
   return value;
 }
 
-Float_t  AliTPCClusterParam::GetRMS1(Int_t dim, Int_t type, Float_t z, Float_t angle){
+Float_t  AliTPCClusterParam::GetRMS1(Int_t dim, Int_t type, Float_t z, Float_t angle) const {
   //
   // calculate mean RMS of cluster - z,angle - pad length scalling
   //
@@ -912,7 +925,7 @@ Float_t  AliTPCClusterParam::GetRMS1(Int_t dim, Int_t type, Float_t z, Float_t a
   return value;
 }
 
-Float_t  AliTPCClusterParam::GetRMSQ(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean){
+Float_t  AliTPCClusterParam::GetRMSQ(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean) const {
   //
   // calculate mean RMS of cluster - z,angle, Q dependence
   //
@@ -926,7 +939,7 @@ Float_t  AliTPCClusterParam::GetRMSQ(Int_t dim, Int_t type, Float_t z, Float_t a
   return value;
 }
 
-Float_t  AliTPCClusterParam::GetRMSSigma(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean){
+Float_t  AliTPCClusterParam::GetRMSSigma(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean) const {
   //
   // calculates RMS of signal shape fluctuation
   //
@@ -936,7 +949,7 @@ Float_t  AliTPCClusterParam::GetRMSSigma(Int_t dim, Int_t type, Float_t z, Float
   return value;
 }
 
-Float_t  AliTPCClusterParam::GetShapeFactor(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean, Float_t rmsL, Float_t rmsM){
+Float_t  AliTPCClusterParam::GetShapeFactor(Int_t dim, Int_t type, Float_t z, Float_t angle, Float_t Qmean, Float_t rmsL, Float_t rmsM) const {
   //
   // calculates vallue - sigma distortion contribution
   //
@@ -1143,19 +1156,19 @@ void AliTPCClusterParam::Test(TTree * tree, const char *output){
       char hcut1[300];
       char hexp1[300];
       //
-      sprintf(hname1,"Delta0 Dir %d Pad %d",idim,ipad);
-      sprintf(hcut1,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad);
-      sprintf(hexp1,"(Resol-AliTPCClusterParam::SGetError0(Dim,Pad,Zm,AngleM))/Resol>>%s",hname1);
+      snprintf(hname1,300,"Delta0 Dir %d Pad %d",idim,ipad);
+      snprintf(hcut1,300,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad);
+      snprintf(hexp1,300,"(Resol-AliTPCClusterParam::SGetError0(Dim,Pad,Zm,AngleM))/Resol>>%s",hname1);
       TH1F  his1DRel0(hname1, hname1, 100,-0.2, 0.2);
-      sprintf(hname1,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad);
+      snprintf(hname1,300,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad);
       tree->Draw(hexp1,hcut1,"");
       his1DRel0.Write();
       //
-      sprintf(hname1,"Delta0Par Dir %d Pad %d",idim,ipad);
-      sprintf(hcut1,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad);
-      sprintf(hexp1,"(Resol-AliTPCClusterParam::SGetError0Par(Dim,Pad,Zm,AngleM))/Resol>>%s",hname1);
+      snprintf(hname1,300,"Delta0Par Dir %d Pad %d",idim,ipad);
+      snprintf(hcut1,300,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad);
+      snprintf(hexp1,300,"(Resol-AliTPCClusterParam::SGetError0Par(Dim,Pad,Zm,AngleM))/Resol>>%s",hname1);
       TH1F  his1DRel0Par(hname1, hname1, 100,-0.2, 0.2);
-      sprintf(hname1,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad);
+      snprintf(hname1,300,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad);
       tree->Draw(hexp1,hcut1,"");
       his1DRel0Par.Write();
       //
@@ -1170,19 +1183,19 @@ void AliTPCClusterParam::Test(TTree * tree, const char *output){
       char hcut1[300];
       char hexp1[300];
       //
-      sprintf(hname1,"2DDelta0 Dir %d Pad %d",idim,ipad);
-      sprintf(hcut1,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad);
-      sprintf(hexp1,"(Resol-AliTPCClusterParam::SGetError0(Dim,Pad,Zm,AngleM))/Resol:AngleM:Zm>>%s",hname1);
+      snprintf(hname1,300,"2DDelta0 Dir %d Pad %d",idim,ipad);
+      snprintf(hcut1,300,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad);
+      snprintf(hexp1,300,"(Resol-AliTPCClusterParam::SGetError0(Dim,Pad,Zm,AngleM))/Resol:AngleM:Zm>>%s",hname1);
       TProfile2D  profDRel0(hname1, hname1, 6,0,250,6,0,1);
-      sprintf(hname1,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad);
+      snprintf(hname1,300,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad);
       tree->Draw(hexp1,hcut1,"");
       profDRel0.Write();
       //
-      sprintf(hname1,"2DDelta0Par Dir %d Pad %d",idim,ipad);
-      sprintf(hcut1,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad);
-      sprintf(hexp1,"(Resol-AliTPCClusterParam::SGetError0Par(Dim,Pad,Zm,AngleM))/Resol:AngleM:Zm>>%s",hname1);
+      snprintf(hname1,300,"2DDelta0Par Dir %d Pad %d",idim,ipad);
+      snprintf(hcut1,300,"Dim==%d&&QMean<0&&Pad==%d",idim,ipad);
+      snprintf(hexp1,300,"(Resol-AliTPCClusterParam::SGetError0Par(Dim,Pad,Zm,AngleM))/Resol:AngleM:Zm>>%s",hname1);
       TProfile2D profDRel0Par(hname1, hname1,6,0,250,6,0,1);
-      sprintf(hname1,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad);
+      snprintf(hname1,300,"Dim==%d&&QMean<0&&Pad=%d",idim,ipad);
       tree->Draw(hexp1,hcut1,"");
       profDRel0Par.Write();
       //
@@ -1318,7 +1331,7 @@ Float_t AliTPCClusterParam::Qnorm(Int_t ipad, Int_t itype, Float_t dr, Float_t t
   // type - 0 Qtot 1 Qmax
   // ipad - 0 (0.75 cm) ,1 (1 cm), 2 (1.5 cm)
   //
-  //expession formula - TString *strq0 = toolkit.FitPlane(chain,"dedxQ.fElements[2]","dr++ty++tz++dr*ty++dr*tz++ty*tz++ty^2++tz^2","IPad==0",chi2,npoints,param,covar,0,100000);
+  //expession formula - TString *strq0 = toolkit.FitPlane(chain,"dedxQ.fElements[2]","dr++ty++tz++dr*ty++dr*tz++++dr*dr++ty*tz++ty^2++tz^2","IPad==0",chi2,npoints,param,covar,0,100000);
 
   if (fQNorm==0) return 0;
   TVectorD * norm = (TVectorD*)fQNorm->At(3*itype+ipad);
@@ -1341,7 +1354,34 @@ Float_t AliTPCClusterParam::Qnorm(Int_t ipad, Int_t itype, Float_t dr, Float_t t
 
 
 
-void AliTPCClusterParam::SetQnorm(Int_t ipad, Int_t itype, TVectorD * norm){
+Float_t AliTPCClusterParam::QnormHis(Int_t ipad, Int_t itype, Float_t dr, Float_t p2, Float_t p3){
+  // get Q normalization
+  // type - 0 Qtot 1 Qmax
+  // ipad - 0 (0.75 cm) ,1 (1 cm), 2 (1.5 cm)
+  //
+
+  if (fQNormHis==0) return 0;
+  TH3F * norm = (TH3F*)fQNormHis->At(4*itype+ipad);
+  if (!norm) return 1;
+  p2=TMath::Abs(p2);
+  dr=TMath::Min(dr,Float_t(norm->GetXaxis()->GetXmax()-norm->GetXaxis()->GetBinWidth(0)));
+  dr=TMath::Max(dr,Float_t(norm->GetXaxis()->GetXmin()+norm->GetXaxis()->GetBinWidth(0)));
+  //
+  p2=TMath::Min(p2,Float_t(norm->GetYaxis()->GetXmax()-norm->GetYaxis()->GetBinWidth(0)));
+  p2=TMath::Max(p2,Float_t(norm->GetYaxis()->GetXmin()+norm->GetYaxis()->GetBinWidth(0)));
+  //
+  p3=TMath::Min(p3,Float_t(norm->GetZaxis()->GetXmax()-norm->GetZaxis()->GetBinWidth(0)));
+  p3=TMath::Max(p3,Float_t(norm->GetZaxis()->GetXmin()+norm->GetZaxis()->GetBinWidth(0)));
+  //
+  Double_t res = norm->GetBinContent(norm->FindBin(dr,p2,p3));
+  if (res==0) res = norm->GetBinContent(norm->FindBin(0.5,0.5,0.5));  // This is just hack - to be fixed entries without 
+
+  return res;
+}
+
+
+
+void AliTPCClusterParam::SetQnorm(Int_t ipad, Int_t itype, const TVectorD *const norm){
   //
   // set normalization
   //
@@ -1353,6 +1393,50 @@ void AliTPCClusterParam::SetQnorm(Int_t ipad, Int_t itype, TVectorD * norm){
   fQNorm->AddAt(new TVectorD(*norm), itype*3+ipad);
 }
 
+void AliTPCClusterParam::ResetQnormCorr(){
+  //
+  //
+  //
+  if (!fQNormCorr) fQNormCorr= new TMatrixD(12,6);
+  for (Int_t irow=0;irow<12; irow++)
+    for (Int_t icol=0;icol<6; icol++){
+      (*fQNormCorr)(irow,icol)=1.;             // default - no correction
+      if (irow>5) (*fQNormCorr)(irow,icol)=0.; // default - no correction
+    } 
+}
+
+void AliTPCClusterParam::SetQnormCorr(Int_t ipad, Int_t itype, Int_t corrType, Float_t val){
+  //
+  // ipad        - pad type
+  // itype       - 0- qtot 1-qmax
+  // corrType    - 0 - s0y corr     - eff. PRF corr
+  //             - 1 - s0z corr     - eff. TRF corr
+  //             - 2 - d0y          - eff. diffusion correction y
+  //             - 3 - d0z          - eff. diffusion correction
+  //             - 4 - eff length   - eff.length - wire pitch + x diffsion
+  //             - 5 - pad type normalization
+  if (!fQNormCorr) {
+    ResetQnormCorr();
+  }
+  //
+  // eff shap parameterization matrix
+  //
+  // rows
+  // itype*3+ipad  - itype=0 qtot itype=1 qmax ipad=0
+  // 
+  if (itype<2) (*fQNormCorr)(itype*3+ipad, corrType) *= val;  // multiplicative correction
+  if (itype>=2) (*fQNormCorr)(itype*3+ipad, corrType)+= val;  // additive       correction  
+}
+
+Double_t  AliTPCClusterParam::GetQnormCorr(Int_t ipad, Int_t itype, Int_t corrType) const{
+  //
+  // see AliTPCClusterParam::SetQnormCorr
+  //
+  if (!fQNormCorr) return 0;
+  return  (*fQNormCorr)(itype*3+ipad, corrType);
+}
+
+
 Float_t AliTPCClusterParam::QnormPos(Int_t ipad,Bool_t isMax, Float_t pad, Float_t time, Float_t z, Float_t sy2, Float_t sz2, Float_t qm, Float_t qt){
   //
   // Make Q normalization as function of following parameters
@@ -1514,20 +1598,26 @@ Double_t  AliTPCClusterParam::GaussConvolution(Double_t x0, Double_t x1, Double_
   //TF1 f1("f1","AliTPCClusterParam::GaussConvolution(x,0,1,0,0.1,0.1)",-2,2)
   //TF2 f2("f2","AliTPCClusterParam::GaussConvolution(x,y,1,1,0.1,0.1)",-2,2,-2,2)
   //
-  const Float_t kEpsilon = 0.0001;
+  const Double_t kEpsilon = 0.0001;
+  const Double_t twoPi = TMath::TwoPi();
+  const Double_t hnorm = 0.5/TMath::Sqrt(twoPi);
+  const Double_t sqtwo = TMath::Sqrt(2.);
+
   if ((TMath::Abs(k0)+TMath::Abs(k1))<kEpsilon*(s0+s1)){
     // small angular effect
-    Double_t val = (TMath::Gaus(x0,0,s0)*TMath::Gaus(x1,0,s1))/(s0*s1*2.*TMath::Pi());
+    Double_t val = TMath::Gaus(x0,0,s0)*TMath::Gaus(x1,0,s1)/(s0*s1*twoPi);
     return val;
   }
   Double_t sigma2 = k1*k1*s0*s0+k0*k0*s1*s1;
-  Double_t exp0 = TMath::Exp(-(k1*x0-k0*x1)*(k1*x0-k0*x1)/(2*sigma2));
-  //
-  Double_t sigmaErf =  2*s0*s1*TMath::Sqrt(2*sigma2);                       
-  Double_t erf0 = TMath::Erf( (k0*s1*s1*(k0-2*x0)+k1*s0*s0*(k1-2*x1))/sigmaErf);
-  Double_t erf1 = TMath::Erf( (k0*s1*s1*(k0+2*x0)+k1*s0*s0*(k1+2*x1))/sigmaErf);
-  Double_t norm = 1./TMath::Sqrt(sigma2);
-  norm/=2.*TMath::Sqrt(2.*TMath::Pi());
+  Double_t sigma = TMath::Sqrt(sigma2);
+  Double_t exp0 = TMath::Exp(-(k1*x0-k0*x1)*(k1*x0-k0*x1)/(2.*sigma2));
+  //
+  Double_t sigmaErf =  1./(2.*s0*s1*sqtwo*sigma);
+  Double_t k0s1s1 = 2.*k0*s1*s1;
+  Double_t k1s0s0 = 2.*k1*s0*s0;
+  Double_t erf0 = AliMathBase::ErfFast((sigma2-k0s1s1*x0-k1s0s0*x1)*sigmaErf);
+  Double_t erf1 = AliMathBase::ErfFast((sigma2+k0s1s1*x0+k1s0s0*x1)*sigmaErf);
+  Double_t norm = hnorm/sigma;
   Double_t val  = norm*exp0*(erf0+erf1);
   return val;
 }
@@ -1586,7 +1676,7 @@ Double_t  AliTPCClusterParam::GaussConvolutionGamma4(Double_t x0, Double_t x1, D
   return val/sum;
 }
 
-Double_t  AliTPCClusterParam::QmaxCorrection(Int_t sector, Int_t row, Float_t cpad, Float_t ctime, Float_t ky, Float_t kz, Float_t rmsy0, Float_t rmsz0, Float_t tau){
+Double_t  AliTPCClusterParam::QmaxCorrection(Int_t sector, Int_t row, Float_t cpad, Float_t ctime, Float_t ky, Float_t kz, Float_t rmsy0, Float_t rmsz0, Float_t effPad, Float_t effDiff){
   //
   //
   // cpad      - pad (y) coordinate
@@ -1594,8 +1684,9 @@ Double_t  AliTPCClusterParam::QmaxCorrection(Int_t sector, Int_t row, Float_t cp
   // ky        - dy/dx
   // kz        - dz/dx
   // rmsy0     - RF width in pad units
-  // rmsz0     - RF width in pad units
-  // tau       - correction for the assymetric TRF shape - decay length 
+  // rmsz0     - RF width in time bin  units
+  // effLength - contibution of PRF and diffusion
+  // effDiff   - overwrite diffusion
 
   // Response function aproximated by convolution of gaussian with angular effect (integral=1)
   //  
@@ -1608,13 +1699,19 @@ Double_t  AliTPCClusterParam::QmaxCorrection(Int_t sector, Int_t row, Float_t cp
   AliTPCParam * param   = AliTPCcalibDB::Instance()->GetParameters(); 
   Double_t padLength= param->GetPadPitchLength(sector,row);
   Double_t padWidth = param->GetPadPitchWidth(sector);
-  // diffusion in pad units
-  Double_t diffT=TMath::Sqrt(ctime*param->GetZWidth())*param->GetDiffT()/padWidth;
-  Double_t diffL=TMath::Sqrt(ctime*param->GetZWidth())*param->GetDiffL()/padWidth;
+  Double_t zwidth   = param->GetZWidth();
+  Double_t effLength= padLength+(param->GetWWPitch(0)+TMath::Sqrt(ctime*zwidth)*param->GetDiffT())*effPad;
+
+  // diffusion in pad, time bin  units
+  Double_t diffT=TMath::Sqrt(ctime*zwidth)*param->GetDiffT()/padWidth;
+  Double_t diffL=TMath::Sqrt(ctime*zwidth)*param->GetDiffL()/zwidth;
+  diffT*=effDiff;  //
+  diffL*=effDiff;  //
   //
   // transform angular effect to pad units
-  Double_t pky   = ky*padLength/padWidth;
-  Double_t pkz   = kz*padLength/padWidth;
+  //
+  Double_t pky   = ky*effLength/padWidth;
+  Double_t pkz   = kz*effLength/zwidth;
   // position in pad unit
   Double_t py = (cpad+0.5)-TMath::Nint(cpad+0.5);
   Double_t pz = (ctime+0.5)-TMath::Nint(ctime+0.5);
@@ -1622,10 +1719,12 @@ Double_t  AliTPCClusterParam::QmaxCorrection(Int_t sector, Int_t row, Float_t cp
   //
   Double_t sy = TMath::Sqrt(rmsy0*rmsy0+diffT*diffT);
   Double_t sz = TMath::Sqrt(rmsz0*rmsz0+diffL*diffL); 
-  return GaussConvolutionGamma4(py,pz, pky,pkz,sy,sz,tau);
+  //return GaussConvolutionGamma4(py,pz, pky,pkz,sy,sz,tau);
+  Double_t length = padLength*TMath::Sqrt(1+ky*ky+kz*kz);
+  return GaussConvolution(py,pz, pky,pkz,sy,sz)*length;
 }
 
-Double_t  AliTPCClusterParam::QtotCorrection(Int_t sector, Int_t row, Float_t cpad, Float_t ctime, Float_t ky, Float_t kz, Float_t rmsy0, Float_t rmsz0,  Float_t qtot, Float_t thr, Float_t tau){
+Double_t  AliTPCClusterParam::QtotCorrection(Int_t sector, Int_t row, Float_t cpad, Float_t ctime, Float_t ky, Float_t kz, Float_t rmsy0, Float_t rmsz0,  Float_t qtot, Float_t thr, Float_t effPad, Float_t effDiff){
   //
   //
   // cpad      - pad (y) coordinate
@@ -1633,10 +1732,11 @@ Double_t  AliTPCClusterParam::QtotCorrection(Int_t sector, Int_t row, Float_t cp
   // ky        - dy/dx
   // kz        - dz/dx
   // rmsy0     - RF width in pad units
-  // rmsz0     - RF width in pad units
+  // rmsz0     - RF width in time bin  units
   // qtot      - the sum of signal in cluster - without thr correction
   // thr       - threshold
-  // tau       - correction for the assymetric TRF shape - decay length 
+  // effLength - contibution of PRF and diffusion
+  // effDiff   - overwrite diffusion
 
   // Response function aproximated by convolution of gaussian with angular effect (integral=1)
   //  
@@ -1649,14 +1749,18 @@ Double_t  AliTPCClusterParam::QtotCorrection(Int_t sector, Int_t row, Float_t cp
   AliTPCParam * param   = AliTPCcalibDB::Instance()->GetParameters(); 
   Double_t padLength= param->GetPadPitchLength(sector,row);
   Double_t padWidth = param->GetPadPitchWidth(sector);
+  Double_t zwidth   = param->GetZWidth();
+  Double_t effLength= padLength+(param->GetWWPitch(0)+TMath::Sqrt(ctime*zwidth)*param->GetDiffT())*effPad;
   //
   // diffusion in pad units
-  Double_t diffT=TMath::Sqrt(ctime*param->GetZWidth())*param->GetDiffT()/padWidth;
-  Double_t diffL=TMath::Sqrt(ctime*param->GetZWidth())*param->GetDiffL()/padWidth;
-  //
-  // transform angular effect to pad units
-  Double_t pky   = ky*padLength/padWidth;
-  Double_t pkz   = kz*padLength/padWidth;
+  Double_t diffT=TMath::Sqrt(ctime*zwidth)*param->GetDiffT()/padWidth;
+  Double_t diffL=TMath::Sqrt(ctime*zwidth)*param->GetDiffL()/zwidth;
+  diffT*=effDiff;  //
+  diffL*=effDiff;  //
+  //
+  // transform angular effect to pad units 
+  Double_t pky   = ky*effLength/padWidth;
+  Double_t pkz   = kz*effLength/zwidth;
   // position in pad unit
   //  
   Double_t py = (cpad+0.5)-TMath::Nint(cpad+0.5);
@@ -1671,21 +1775,25 @@ Double_t  AliTPCClusterParam::QtotCorrection(Int_t sector, Int_t row, Float_t cp
   //
   Double_t corr =1;
   Double_t qnorm=qtot;
-  for (Float_t iy=-2;iy<=2;iy++)
-    for (Float_t iz=-2;iz<=2;iz++){
-      Double_t val = GaussConvolutionGamma4(py-iy,pz-iz, pky,pkz, sy,sz,tau);      
+  for (Float_t iy=-3;iy<=3;iy+=1.)
+    for (Float_t iz=-4;iz<=4;iz+=1.){
+      //      Double_t val = GaussConvolutionGamma4(py-iy,pz-iz, pky,pkz, sy,sz,tau);      
+      Double_t val = GaussConvolution(py-iy,pz-iz, pky,pkz, sy,sz);      
       Double_t qlocal =qnorm*val;
-      if (TMath::Abs(iy)<2&&TMath::Abs(iz)<2){
-       sumThr+=qlocal;   // using Virtual charge in cluster finder
+      if (TMath::Abs(iy)<1.5&&TMath::Abs(iz)<1.5){
+       sumThr+=qlocal;   // Virtual charge used in cluster finder
       }
       else{
-       if (qlocal>thr) sumThr+=qlocal;
+       if (qlocal>thr && TMath::Abs(iz)<2.5&&TMath::Abs(iy)<2.5) sumThr+=qlocal;
       }
       sumAll+=qlocal;
     }
-  if (sumAll>0&&sumThr>0) corr=(sumThr)/sumAll;
+  if (sumAll>0&&sumThr>0) {
+    corr=(sumThr)/sumAll;
+  }
   //
-  return corr;
+  Double_t length = padLength*TMath::Sqrt(1+ky*ky+kz*kz);
+  return corr*length;
 }