]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG1/TRD/AliTRDresolution.cxx
full resolution monitoring for clusters, tracklets and trackIN
[u/mrichter/AliRoot.git] / PWG1 / TRD / AliTRDresolution.cxx
index 9d912522714cc13cc7c87b6772b606cd6652fe4b..7756e82c4609b0d253c15d4ffda683ac62c42ae9 100644 (file)
 ////////////////////////////////////////////////////////////////////////////
 
 #include <TSystem.h>
-
+#include <TStyle.h>
 #include <TROOT.h>
 #include <TObjArray.h>
 #include <TH3.h>
 #include <TH2.h>
 #include <TH1.h>
+#include <THnSparse.h>
 #include <TF1.h>
 #include <TCanvas.h>
 #include <TGaxis.h>
@@ -62,6 +63,7 @@
 #include <TLegend.h>
 #include <TGraphErrors.h>
 #include <TGraphAsymmErrors.h>
+#include <TLinearFitter.h>
 #include <TMath.h>
 #include <TMatrixT.h>
 #include <TVectorT.h>
 #include <TDatabasePDG.h>
 
 #include "AliPID.h"
+#include "AliLog.h"
 #include "AliESDtrack.h"
+#include "AliMathBase.h"
+#include "AliTrackPointArray.h"
 
 #include "AliTRDresolution.h"
 #include "AliTRDgeometry.h"
+#include "AliTRDtransform.h"
 #include "AliTRDpadPlane.h"
 #include "AliTRDcluster.h"
 #include "AliTRDseedV1.h"
 #include "AliTRDReconstructor.h"
 #include "AliTRDrecoParam.h"
 #include "AliTRDpidUtil.h"
+#include "AliTRDinfoGen.h"
 
 #include "info/AliTRDclusterInfo.h"
 
 ClassImp(AliTRDresolution)
-
-UChar_t const AliTRDresolution::fgNhistos[kNviews] = {
-  2, 2, 5, 5,
-  2, 5, 12, 2, 14
+//ClassImp(AliTRDresolution::AliTRDresolutionProjection)
+
+Int_t const   AliTRDresolution::fgkNbins[kNdim] = {
+  Int_t(kNbunchCross)/*bc*/,
+  180/*phi*/,
+  50/*eta*/,
+  50/*dy*/,
+  40/*dphi*/,
+  50/*dz*/,
+  Int_t(kNcharge)*AliPID::kSPECIES+1/*chg*species*/,
+  kNpt/*pt*/
+};  //! no of bins/projection
+Double_t const AliTRDresolution::fgkMin[kNdim] = {
+  -0.5,
+  -TMath::Pi(),
+  -1.,
+  -1.5,
+  -10.,
+  -2.5,
+  -AliPID::kSPECIES-0.5,
+  -0.5
+};    //! low limits for projections
+Double_t const AliTRDresolution::fgkMax[kNdim] = {
+  Int_t(kNbunchCross)-0.5,
+  TMath::Pi(),
+  1.,
+  1.5,
+  10.,
+  2.5,
+  AliPID::kSPECIES+0.5,
+  kNpt-0.5
+};    //! high limits for projections
+Char_t const *AliTRDresolution::fgkTitle[kNdim] = {
+  "bunch cross",
+  "#phi [rad]",
+  "#eta",
+  "#Deltay [cm]",
+  "#Delta#phi [deg]",
+  "#Deltaz [cm]",
+  "chg*spec*rc",
+  "bin_p_{t}"
+};  //! title of projection
+
+const Int_t AliTRDresolution::fgkNproj[kNclasses] = {
+  48, 72, 8, 5,
+  2, 5, 11, 11, 11
 };
-UChar_t const AliTRDresolution::fgNproj[kNviews] = {
-  2, 2, 5, 5,
-  4, 7, 12, 2, 14
-};
-Char_t const * AliTRDresolution::fgPerformanceName[kNviews] = {
-     "Charge"
-    ,"Cluster2Track"
+Char_t const * AliTRDresolution::fgPerformanceName[kNclasses] = {
+    "Cluster2Track"
     ,"Tracklet2Track"
-    ,"Tracklet2TPC" 
+    ,"Tracklet2TRDin" 
+    ,"Tracklet2TRDout" 
     ,"Cluster2MC"
     ,"Tracklet2MC"
-    ,"TPC2MC"
-    ,"TOF/HMPID2MC"
+    ,"TRDin2MC"
+    ,"TRDout2MC"
     ,"TRD2MC"
 };
-UChar_t const AliTRDresolution::fgNcomp[kNprojs] = {
-  1, 1, //2, 
-  1, 1, //2, 
-  1, 1, 1, 1, 1, //5, 
-  1, 1, 1, 1, 1, 1, 1, //5,
-// MC
-  1, 1, 1, 1,    //4, 
-  1, 1, 1, 1, 1, //5, 
-  1, 1, 1, 1, 1, 1, 1, 1, 11, 11, 11, 11, //12, 
-  1, 1, //2, 
-  1, 1, 1, 1, 1, 1, 1, 1, 66, 66, 66, 66, 66, 66 //14
-};
-Char_t const *AliTRDresolution::fgAxTitle[kNprojs][4] = {
-  // Charge
-  {"Impv", "x [cm]", "I_{mpv}", "x/x_{0}"}
- ,{"dI/Impv", "x/x_{0}", "#delta I/I_{mpv}", "x[cm]"}
-  // Clusters to Kalman
- ,{"Cluster2Track residuals", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y} [#mum]"}
- ,{"Cluster2Track  pulls", "tg(#phi)", "#mu_{y}", "#sigma_{y}"}
-  // TRD tracklet to Kalman fit
- ,{"Tracklet2Track Y residuals", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y} [#mum]"}
- ,{"Tracklet2Track Y pulls", "tg(#phi)", "#mu_{y}", "#sigma_{y}"}
- ,{"Tracklet2Track Z residuals", "tg(#theta)", "#mu_{z} [#mum]", "#sigma_{z} [#mum]"}
- ,{"Tracklet2Track Z pulls", "tg(#theta)", "#mu_{z}", "#sigma_{z}"}
- ,{"Tracklet2Track Phi residuals", "tg(#phi)", "#mu_{#phi} [mrad]", "#sigma_{#phi} [mrad]"}
-  // TPC track 2 first TRD tracklet
- ,{"Tracklet2Track Y residuals @ TRDin", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y} [#mum]"}
- ,{"Tracklet2Track Y pulls @ TRDin", "tg(#phi)", "#mu_{y}", "#sigma_{y}"}
- ,{"Tracklet2Track Z residuals @ TRDin", "tg(#theta)", "#mu_{z} [#mum]", "#sigma_{z} [#mum]"}
- ,{"Tracklet2Track Z pulls @ TRDin", "tg(#theta)", "#mu_{z}", "#sigma_{z}"}
- ,{"Tracklet2Track Phi residuals @ TRDin", "tg(#phi)", "#mu_{#phi} [mrad]", "#sigma_{#phi} [mrad]"}
-  // MC cluster
- ,{"MC Cluster Y resolution (p_{t}<1 GeV/c)", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y} [#mum]"}
- ,{"MC Cluster Y resolution (1<p_{t}<2 GeV/c)", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y} [#mum]"}
- ,{"MC Cluster Y resolution (p_{t}>3 GeV/c)", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y} [#mum]"}
- ,{"MC Cluster Y pulls", "tg(#phi)", "#mu_{y}", "#sigma_{y}"}
-  // MC tracklet
- ,{"MC Tracklet Y resolution (p_{t}<1 GeV/c)", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y} [#mum]"}
- ,{"MC Tracklet Y resolution (1<p_{t}<2 GeV/c)", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y} [#mum]"}
- ,{"MC Tracklet Y resolution (p_{t}>3 GeV/c)", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y}[#mum]"}
- ,{"MC Tracklet Y pulls", "tg(#phi)", "#mu_{y}", "#sigma_{y}"}
- ,{"MC Tracklet Cross Z resolution", "tg(#theta)", "#mu_{z} [#mum]", "#sigma_{z} [#mum]"}
- ,{"MC Tracklet Cross Z pulls", "tg(#theta)", "#mu_{z}", "#sigma_{z}"}
- ,{"MC Tracklet Phi resolution", "tg(#phi)", "#mu_{#phi} [mrad]", "#sigma_{#phi} [mrad]"}
-  // MC track TPC
- ,{"Y resolution @ TRDin", "tg(#phi)", "#mu_{y} [#mum]", "#sigma_{y}[#mum]"}
- ,{"Y pulls @ TRDin", "tg(#phi)", "#mu_{y}", "#sigma_{y}"}
- ,{"Z resolution @ TRDin", "tg(#theta)", "#mu_{z} [#mum]", "#sigma_{z} [#mum]"}
- ,{"Z pulls @ TRDin", "tg(#theta)", "#mu_{z}", "#sigma_{z}"}
- ,{"Phi resolution @ TRDin", "tg(#phi)", "#mu_{#phi} [mrad]", "#sigma_{#phi} [mrad]"}
- ,{"SNP pulls @ TRDin", "tg(#phi)", "#mu_{snp}", "#sigma_{snp}"}
- ,{"Theta resolution @ TRDin", "tg(#theta)", "#mu_{#theta} [mrad]", "#sigma_{#theta} [mrad]"}
- ,{"TGL pulls @ TRDin", "tg(#theta)", "#mu_{tgl}", "#sigma_{tgl}"}
- ,{"P_{t} resolution @ TRDin", "p_{t}^{MC} [GeV/c]", "(p_{t}^{REC}-p_{t}^{MC})/p_{t}^{MC} [%]", "MC: #sigma^{TPC}(#Deltap_{t}/p_{t}^{MC}) [%]"}
- ,{"1/P_{t} pulls @ TRDin", "1/p_{t}^{MC} [c/GeV]", "1/p_{t}^{REC}-1/p_{t}^{MC}", "MC PULL: #sigma_{1/p_{t}}^{TPC}"}
- ,{"P resolution @ TRDin", "p^{MC} [GeV/c]", "(p^{REC}-p^{MC})/p^{MC} [%]", "MC: #sigma^{TPC}(#Deltap/p^{MC}) [%]"}
- ,{"P pulls @ TRDin", "p^{MC} [GeV/c]", "1/p^{REC}-1/p^{MC}", "MC PULL: #sigma^{TPC}(#Deltap/#sigma_{p})"}
-  // MC track TOF
- ,{"PosZ", "tg(#theta)", "MC: #mu_{z}^{TOF} [#mum]", "MC: #sigma_{z}^{TOF} [#mum]"}
- ,{"PullsZ", "tg(#theta)", "MC PULL: #mu_{z}^{TOF}", "MC PULL: #sigma_{z}^{TOF}"}
-  // MC track in TRD
- ,{"TRD track MC Y resolution", "tg(#phi)", "#mu_{y}^{Trk} [#mum]", "#sigma_{y}^{Trk} [#mum]"}
- ,{"TRD track MC Y pulls", "tg(#phi)", "#mu_{y}^{Trk}", "#sigma_{y}^{Trk}"}
- ,{"TRD track MC Z resolution", "tg(#theta)", "#mu_{z}^{Trk} [#mum]", "#sigma_{z}^{Trk} [#mum]"}
- ,{"TRD track MC Z pulls", "tg(#theta)", "#mu_{z}^{Trk}", "#sigma_{z}^{Trk}"}
- ,{"TRD track MC Phi resolution", "tg(#phi)", "#mu_{#phi}^{Trk} [mrad]", "#sigma_{#phi}^{Trk} [mrad]"}
- ,{"TRD track MC SNP pulls", "tg(#phi)", "#mu_{snp}^{Trk}", "#sigma_{snp}^{Trk}"}
- ,{"TRD track MC Theta resolution", "tg(#theta)", "#mu_{#theta}^{Trk} [mrad]", "#sigma_{#theta}^{Trk} [mrad]"}
- ,{"TRD track MC TGL pulls", "tg(#theta)", "#mu_{tgl}^{Trk}", "#sigma_{tgl}^{Trk}"}
- ,{"P_{t} resolution TRD Layer", "p_{t} [GeV/c]", "(p_{t}^{REC}-p_{t}^{MC})/p_{t}^{MC} [%]", "#sigma(#Deltap_{t}/p_{t}^{MC}) [%]"}
- ,{"1/P_{t} pulls TRD Layer", "1/p_{t}^{MC} [c/GeV]", "1/p_{t}^{REC} - 1/p_{t}^{MC}", "#sigma_{1/p_{t}}"}
- ,{"P resolution TRD Layer", "p [GeV/c]", "(p^{REC}-p^{MC})/p^{MC} [%]", "#sigma(#Deltap/p^{MC}) [%]"}
- ,{"[SA] P_{t} resolution TRD Layer", "p_{t}^{MC} [GeV/c]", "(p_{t}^{REC}-p_{t}^{MC})/p_{t}^{MC} [%]", "MC: #sigma^{Trk}(#Deltap_{t}/p_{t}^{MC}) [%]"}
- ,{"[SA] 1/P_{t} pulls TRD Layer", "1/p_{t}^{MC} [c/GeV]", "1/p_{t}^{REC}-1/p_{t}^{MC}", "MC PULL: #sigma_{1/p_{t}}^{Trk}"}
- ,{"[SA] P resolution TRD Layer", "p^{MC} [GeV/c]", "(p^{REC}-p^{MC})/p^{MC} [%]", "MC: #sigma^{Trk}(#Deltap/p^{MC}) [%]"}
-};
+Float_t AliTRDresolution::fgPtBin[kNpt+1];
 
 //________________________________________________________
 AliTRDresolution::AliTRDresolution()
-  :AliTRDrecoTask("resolution", "Spatial and momentum TRD resolution checker")
-  ,fStatus(0)
+  :AliTRDrecoTask()
   ,fIdxPlot(0)
   ,fIdxFrame(0)
-  ,fReconstructor(NULL)
-  ,fGeo(NULL)
+  ,fPtThreshold(1.)
+  ,fDyRange(0.75)
+  ,fProj(NULL)
   ,fDBPDG(NULL)
-  ,fGraphS(NULL)
-  ,fGraphM(NULL)
   ,fCl(NULL)
-  ,fTrklt(NULL)
   ,fMCcl(NULL)
-  ,fMCtrklt(NULL)
 {
   //
   // Default constructor
   //
+  SetNameTitle("TRDresolution", "TRD spatial and momentum resolution");
+  MakePtSegmentation();
 }
 
-AliTRDresolution::AliTRDresolution(char* name)
-  :AliTRDrecoTask(name, "Spatial and momentum TRD resolution checker")
-  ,fStatus(0)
+//________________________________________________________
+AliTRDresolution::AliTRDresolution(char* name, Bool_t xchange)
+  :AliTRDrecoTask(name, "TRD spatial and momentum resolution")
   ,fIdxPlot(0)
   ,fIdxFrame(0)
-  ,fReconstructor(NULL)
-  ,fGeo(NULL)
+  ,fPtThreshold(1.)
+  ,fDyRange(0.75)
+  ,fProj(NULL)
   ,fDBPDG(NULL)
-  ,fGraphS(NULL)
-  ,fGraphM(NULL)
   ,fCl(NULL)
-  ,fTrklt(NULL)
   ,fMCcl(NULL)
-  ,fMCtrklt(NULL)
 {
   //
   // Default constructor
   //
 
-  fReconstructor = new AliTRDReconstructor();
-  fReconstructor->SetRecoParam(AliTRDrecoParam::GetLowFluxParam());
-  fGeo = new AliTRDgeometry();
-
   InitFunctorList();
-
-  DefineOutput(1, TObjArray::Class()); // cluster2track
-  DefineOutput(2, TObjArray::Class()); // tracklet2track
-  DefineOutput(3, TObjArray::Class()); // cluster2mc
-  DefineOutput(4, TObjArray::Class()); // tracklet2mc
+  MakePtSegmentation();
+  if(xchange){
+    SetUseExchangeContainers();
+    DefineOutput(kClToTrk, TObjArray::Class()); // cluster2track
+    DefineOutput(kClToMC, TObjArray::Class()); // cluster2mc
+  }
 }
 
 //________________________________________________________
@@ -241,15 +203,9 @@ AliTRDresolution::~AliTRDresolution()
   // Destructor
   //
 
-  if(fGraphS){fGraphS->Delete(); delete fGraphS;}
-  if(fGraphM){fGraphM->Delete(); delete fGraphM;}
-  delete fGeo;
-  delete fReconstructor;
-  if(gGeoManager) delete gGeoManager;
+  if(fProj){fProj->Delete(); delete fProj;}
   if(fCl){fCl->Delete(); delete fCl;}
-  if(fTrklt){fTrklt->Delete(); delete fTrklt;}
   if(fMCcl){fMCcl->Delete(); delete fMCcl;}
-  if(fMCtrklt){fMCtrklt->Delete(); delete fMCtrklt;}
 }
 
 
@@ -257,85 +213,63 @@ AliTRDresolution::~AliTRDresolution()
 void AliTRDresolution::UserCreateOutputObjects()
 {
   // spatial resolution
-  OpenFile(1, "RECREATE");
-
-  fContainer = Histos();
-
-  fCl = new TObjArray();
-  fCl->SetOwner(kTRUE);
-  fTrklt = new TObjArray();
-  fTrklt->SetOwner(kTRUE);
-  fMCcl = new TObjArray();
-  fMCcl->SetOwner(kTRUE);
-  fMCtrklt = new TObjArray();
-  fMCtrklt->SetOwner(kTRUE);
+
+  AliTRDrecoTask::UserCreateOutputObjects();
+  if(UseExchangeContainers()) InitExchangeContainers();
 }
 
 //________________________________________________________
-void AliTRDresolution::UserExec(Option_t *opt)
+void AliTRDresolution::InitExchangeContainers()
 {
-  //
-  // Execution part
-  //
-
-  fCl->Delete();
-  fTrklt->Delete();
-  fMCcl->Delete();
-  fMCtrklt->Delete();
-
-  AliTRDrecoTask::Exec(opt);
+// Init containers for subsequent tasks (AliTRDclusterResolution)
 
-  PostData(1, fCl);
-  PostData(2, fTrklt);
-  PostData(3, fMCcl);
-  PostData(4, fMCtrklt);
+  fCl = new TObjArray(200); fCl->SetOwner(kTRUE);
+  fMCcl = new TObjArray(); fMCcl->SetOwner(kTRUE);
+  PostData(kClToTrk, fCl);
+  PostData(kClToMC, fMCcl);
 }
 
 //________________________________________________________
-TH1* AliTRDresolution::PlotCharge(const AliTRDtrackV1 *track)
+void AliTRDresolution::UserExec(Option_t *opt)
 {
   //
-  // Plots the charge distribution
+  // Execution part
   //
 
-  if(track) fkTrack = track;
-  if(!fkTrack){
-    AliDebug(2, "No Track defined.");
-    return NULL;
-  }
-  TObjArray *arr = NULL;
-  if(!(arr = ((TObjArray*)fContainer->At(kCharge)))){
-    AliWarning("No output container defined.");
-    return NULL;
-  }
-  TH3S* h = NULL;
-
-  AliTRDseedV1 *fTracklet = NULL;  
-  AliTRDcluster *c = NULL;
-  for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
-    if(!(fTracklet = fkTrack->GetTracklet(ily))) continue;
-    if(!fTracklet->IsOK()) continue;
-    Float_t x0 = fTracklet->GetX0();
-    Float_t dq, dl;
-    for(Int_t itb=AliTRDseedV1::kNtb; itb--;){
-      if(!(c = fTracklet->GetClusters(itb))){ 
-        if(!(c = fTracklet->GetClusters(AliTRDseedV1::kNtb+itb))) continue;
-      }
-      dq = fTracklet->GetdQdl(itb, &dl);
-      dl /= 0.15; // dl/dl0, dl0 = 1.5 mm for nominal vd
-      (h = (TH3S*)arr->At(0))->Fill(dl, x0-c->GetX(), dq);
-    }
+  if(fCl) fCl->Delete();
+  if(fMCcl) fMCcl->Delete();
+  AliTRDrecoTask::UserExec(opt);
+}
 
-//     if(!HasMCdata()) continue;
-//     UChar_t s;
-//     Float_t pt0, y0, z0, dydx0, dzdx0;
-//     if(!fMC->GetDirections(x0, y0, z0, dydx0, dzdx0, pt0, s)) continue;
+//________________________________________________________
+Bool_t AliTRDresolution::Pulls(Double_t* /*dyz[2]*/, Double_t* /*cov[3]*/, Double_t /*tilt*/) const
+{
+// Helper function to calculate pulls in the yz plane 
+// using proper tilt rotation
+// Uses functionality defined by AliTRDseedV1.
 
-  }
-  return h;
+  return kTRUE;
+/*
+  Double_t t2(tilt*tilt);
+  // exit door until a bug fix is found for AliTRDseedV1::GetCovSqrt
+
+  // rotate along pad
+  Double_t cc[3];
+  cc[0] = cov[0] - 2.*tilt*cov[1] + t2*cov[2]; 
+  cc[1] = cov[1]*(1.-t2) + tilt*(cov[0] - cov[2]);
+  cc[2] = t2*cov[0] + 2.*tilt*cov[1] + cov[2];
+  // do sqrt
+  Double_t sqr[3]={0., 0., 0.}; 
+  if(AliTRDseedV1::GetCovSqrt(cc, sqr)) return kFALSE;
+  Double_t invsqr[3]={0., 0., 0.}; 
+  if(AliTRDseedV1::GetCovInv(sqr, invsqr)<1.e-40) return kFALSE;
+  Double_t tmp(dyz[0]);
+  dyz[0] = invsqr[0]*tmp + invsqr[1]*dyz[1];
+  dyz[1] = invsqr[1]*tmp + invsqr[2]*dyz[1];
+  return kTRUE;
+*/
 }
 
-
 //________________________________________________________
 TH1* AliTRDresolution::PlotCluster(const AliTRDtrackV1 *track)
 {
@@ -345,91 +279,106 @@ TH1* AliTRDresolution::PlotCluster(const AliTRDtrackV1 *track)
 
   if(track) fkTrack = track;
   if(!fkTrack){
-    AliDebug(2, "No Track defined.");
+    AliDebug(4, "No Track defined.");
+    return NULL;
+  }
+  if(TMath::Abs(fkESD->GetTOFbc()) > 1){
+    AliDebug(4, Form("Track with BC_index[%d] not used.", fkESD->GetTOFbc()));
+    return NULL;
+  }
+  if(fPt<fPtThreshold){
+    AliDebug(4, Form("Track with pt[%6.4f] under threshold.", fPt));
     return NULL;
   }
-  TObjArray *arr = NULL;
-  if(!(arr = ((TObjArray*)fContainer->At(kCluster)))){
+  THnSparse *H(NULL);
+  if(!fContainer || !(H = ((THnSparse*)fContainer->At(kCluster)))){
     AliWarning("No output container defined.");
     return NULL;
   }
-  ULong_t status = fkESD ? fkESD->GetStatus():0;
 
-  Double_t covR[7], cov[3];
-  Float_t x0, y0, z0, dy, dz, dydx, dzdx;
-  AliTRDseedV1 *fTracklet(NULL);  
+  AliTRDgeometry *geo(AliTRDinfoGen::Geometry());
+  Double_t val[kNdim]; //Float_t exb, vd, t0, s2, dl, dt;
+  TObjArray     *clInfoArr(NULL);
+  AliTRDseedV1  *fTracklet(NULL);
+  AliTRDcluster *c(NULL), *cc(NULL);
   for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
     if(!(fTracklet = fkTrack->GetTracklet(ily))) continue;
     if(!fTracklet->IsOK()) continue;
-    x0 = fTracklet->GetX0();
-
-    // retrive the track angle with the chamber
-    y0   = fTracklet->GetYref(0);
-    z0   = fTracklet->GetZref(0);
-    dydx = fTracklet->GetYref(1);
-    dzdx = fTracklet->GetZref(1);
-    fTracklet->GetCovRef(covR);
-    Float_t tilt(fTracklet->GetTilt());
-    AliTRDcluster *c = NULL;
-    fTracklet->ResetClusterIter(kFALSE);
-    while((c = fTracklet->PrevCluster())){
-      Float_t xc = c->GetX();
-      Float_t yc = c->GetY();
-      Float_t zc = c->GetZ();
-      Float_t dx = x0 - xc; 
-      Float_t yt = y0 - dx*dydx;
-      Float_t zt = z0 - dx*dzdx; 
-      // calculate residuals using tilt correction
-//       yc -= tilt*(zc-zt); 
-//       dy = yt - yc;
-
-      // calculate residuals using correct covariance matrix
-      cov[0] = c->GetSigmaY2();
-      cov[1] = c->GetSigmaYZ();
-      cov[2] = c->GetSigmaZ2();
-      // do rotation
-      Double_t sy2(cov[0]), sz2(cov[2]);
-      Double_t t2 = tilt*tilt;
-      Double_t correction = 1./(1. + t2);
-      cov[0] = (sy2+t2*sz2)*correction;
-      cov[1] = tilt*(sz2 - sy2)*correction;
-      cov[2] = (t2*sy2+sz2)*correction;
-      // do inversion
-      Double_t r00=cov[0]+covR[0], r01=cov[1]+covR[1], r11=cov[2]+covR[2];
-      Double_t det=r00*r11 - r01*r01;
-      Double_t tmp=r00; r00=r11/det; r11=tmp/det;
-      dy = (yc - yt)*TMath::Sqrt(r00);
-      dz = (zc - zt)*TMath::Sqrt(r11);
-
-      ((TH2I*)arr->At(0))->Fill(dydx, dy/*, dz*/);
-      ((TH2I*)arr->At(1))->Fill(dydx, dy/TMath::Sqrt(cov[0] /*+ sx2*/ + sy2));
+    //fTracklet->GetCalibParam(exb, vd, t0, s2, dl, dt);
+    val[kBC]  = ily;
+    val[kPhi] = fPhi;
+    val[kEta] = fEta;
+    val[kPt]  = TMath::ATan(fTracklet->GetYref(1))*TMath::RadToDeg();
+    Float_t corr = 1./TMath::Sqrt(1.+fTracklet->GetYref(1)*fTracklet->GetYref(1)+fTracklet->GetZref(1)*fTracklet->GetZref(1));
+    Int_t row0(-1);
+    Float_t padCorr(fTracklet->GetTilt()*fTracklet->GetPadLength());
+    fTracklet->ResetClusterIter(kTRUE);
+    while((c = fTracklet->NextCluster())){
+      Float_t xc(c->GetX()),
+              q(c->GetQ());
+      Int_t tb(c->GetLocalTimeBin());
+      if(row0<0) row0 = c->GetPadRow();
+
+      val[kYrez] = c->GetY() + padCorr*(c->GetPadRow() - row0) -fTracklet->GetYat(xc);
+      val[kPrez] = fTracklet->GetX0()-xc;
+      val[kZrez] = 0.; Int_t ic(0);
+      if((cc = fTracklet->GetClusters(tb-1))) {val[kZrez] += cc->GetQ(); ic++;}
+      if((cc = fTracklet->GetClusters(tb-2))) {val[kZrez] += cc->GetQ(); ic++;}
+      if(ic) val[kZrez] /= (ic*q);
+      val[kSpeciesChgRC]= fTracklet->IsRowCross()?0.:(TMath::Max(q*corr, Float_t(3.)));
+      H->Fill(val);
+/*      // tilt rotation of covariance for clusters
+      Double_t sy2(c->GetSigmaY2()), sz2(c->GetSigmaZ2());
+      cov[0] = (sy2+t2*sz2)*corr;
+      cov[1] = tilt*(sz2 - sy2)*corr;
+      cov[2] = (t2*sy2+sz2)*corr;
+      // sum with track covariance
+      cov[0]+=covR[0]; cov[1]+=covR[1]; cov[2]+=covR[2];
+      Double_t dyz[2]= {dy[1], dz[1]};
+      Pulls(dyz, cov, tilt);*/
   
+      // Get z-position with respect to anode wire
+      Float_t yt(fTracklet->GetYref(0)-val[kZrez]*fTracklet->GetYref(1)),
+              zt(fTracklet->GetZref(0)-val[kZrez]*fTracklet->GetZref(1));
+      Int_t istk = geo->GetStack(c->GetDetector());
+      AliTRDpadPlane *pp = geo->GetPadPlane(ily, istk);
+      Float_t rowZ = pp->GetRow0();
+      Float_t d  = rowZ - zt + pp->GetAnodeWireOffset();
+      d -= ((Int_t)(2 * d)) / 2.0;
+      if (d > 0.25) d  = 0.5 - d;
+
+      AliTRDclusterInfo *clInfo(NULL);
+      clInfo = new AliTRDclusterInfo;
+      clInfo->SetCluster(c);
+      //Float_t covF[] = {cov[0], cov[1], cov[2]};
+      clInfo->SetGlobalPosition(yt, zt, fTracklet->GetYref(1), fTracklet->GetZref(1)/*, covF*/);
+      clInfo->SetResolution(val[kYrez]);
+      clInfo->SetAnisochronity(d);
+      clInfo->SetDriftLength(val[kZrez]);
+      clInfo->SetTilt(fTracklet->GetTilt());
+      if(fCl) fCl->Add(clInfo);
+      //else AliDebug(1, "Cl exchange container missing. Activate by calling \"InitExchangeContainers()\"");
+
       if(DebugLevel()>=2){
-        // Get z-position with respect to anode wire
-        Int_t istk = fGeo->GetStack(c->GetDetector());
-        AliTRDpadPlane *pp = fGeo->GetPadPlane(ily, istk);
-        Float_t row0 = pp->GetRow0();
-        Float_t d  =  row0 - zt + pp->GetAnodeWireOffset();
-        d -= ((Int_t)(2 * d)) / 2.0;
-        if (d > 0.25) d  = 0.5 - d;
-
-        AliTRDclusterInfo *clInfo = new AliTRDclusterInfo;
-        fCl->Add(clInfo);
-        clInfo->SetCluster(c);
-        Float_t covRL[] = {cov[0], cov[1], cov[2]};
-        clInfo->SetGlobalPosition(yt, zt, dydx, dzdx, covRL);
-        clInfo->SetResolution(dy);
-        clInfo->SetAnisochronity(d);
-        clInfo->SetDriftLength(dx);
-        clInfo->SetTilt(tilt);
-        (*DebugStream()) << "ClusterREC"
-          <<"status="  << status
-          <<"clInfo.=" << clInfo
-          << "\n";
+        if(!clInfoArr){ 
+          clInfoArr=new TObjArray(AliTRDseedV1::kNclusters);
+          clInfoArr->SetOwner(kFALSE);
+        }
+        clInfoArr->Add(clInfo);
       }
     }
+    if(DebugLevel()>=2 && clInfoArr){
+      ULong_t status = fkESD->GetStatus();
+      (*DebugStream()) << "cluster"
+        <<"status="  << status
+        <<"clInfo.=" << clInfoArr
+        << "\n";
+      clInfoArr->Clear();
+    }
   }
-  return (TH2I*)arr->At(0);
+  if(clInfoArr) delete clInfoArr;
+
+  return NULL;//H->Projection(kEta, kPhi);
 }
 
 
@@ -446,54 +395,95 @@ TH1* AliTRDresolution::PlotTracklet(const AliTRDtrackV1 *track)
 // reference position. 
   if(track) fkTrack = track;
   if(!fkTrack){
-    AliDebug(2, "No Track defined.");
+    AliDebug(4, "No Track defined.");
     return NULL;
   }
-  TObjArray *arr = NULL;
-  if(!(arr = (TObjArray*)fContainer->At(kTrackTRD ))){
+  if(TMath::Abs(fkESD->GetTOFbc())>1){
+    AliDebug(4, Form("Track with BC_index[%d] not used.", fkESD->GetTOFbc()));
+    return NULL;
+  }
+  THnSparse *H(NULL);
+  if(!fContainer || !(H = (THnSparse*)fContainer->At(kTracklet))){
     AliWarning("No output container defined.");
     return NULL;
   }
-
-  Double_t cov[3], covR[7]/*, sqr[3], inv[3]*/;
-  Float_t x, dx, dy, dz;
-  AliTRDseedV1 *fTracklet = NULL;  
-  for(Int_t il=AliTRDgeometry::kNlayer; il--;){
+//  return NULL;
+  Double_t val[kNdim+1];
+  AliTRDseedV1 *fTracklet(NULL);
+  for(Int_t il(0); il<AliTRDgeometry::kNlayer; il++){
     if(!(fTracklet = fkTrack->GetTracklet(il))) continue;
     if(!fTracklet->IsOK()) continue;
-    x    = fTracklet->GetX();
-    dx   = fTracklet->GetX0() - x;
-    // compute dy^2 and dz^2
-    dy   = fTracklet->GetYref(0)-dx*fTracklet->GetYref(1) - fTracklet->GetY();
-    dz   = fTracklet->GetZref(0)-dx*fTracklet->GetZref(1) - fTracklet->GetZ();
-    // compute covariance matrix
-    fTracklet->GetCovAt(x, cov);
-    fTracklet->GetCovRef(covR);
-    cov[0] += covR[0]; cov[1] += covR[1]; cov[2] += covR[2]; 
-/*  // Correct PULL calculation by considering off  
-    // diagonal elements in the covariance matrix
-    // compute square root matrix
-    if(AliTRDseedV1::GetCovInv(cov, inv)==0.) continue;
-    if(AliTRDseedV1::GetCovSqrt(inv, sqr)<0.) continue;
-    Double_t y = sqr[0]*dy+sqr[1]*dz;
-    Double_t z = sqr[1]*dy+sqr[2]*dz;
-    ((TH3*)h)->Fill(y, z, fTracklet->GetYref(1));*/
-
-    ((TH2I*)arr->At(0))->Fill(fTracklet->GetYref(1), dy);
-    ((TH2I*)arr->At(1))->Fill(fTracklet->GetYref(1), dy/TMath::Sqrt(cov[0]));
-    ((TH2I*)arr->At(4))->Fill(fTracklet->GetYref(1), TMath::ATan((fTracklet->GetYref(1)-fTracklet->GetYfit(1))/(1-fTracklet->GetYref(1)*fTracklet->GetYfit(1))));
-    if(!fTracklet->IsRowCross()) continue;
-    ((TH2I*)arr->At(2))->Fill(fTracklet->GetZref(1), dz);
-    ((TH2I*)arr->At(3))->Fill(fTracklet->GetZref(1), dz/TMath::Sqrt(cov[2]));
-  }
-
-
-  return (TH2I*)arr->At(0);
+    val [kBC] = il; 
+    val[kPhi] = fPhi;
+    val[kEta] = fEta;
+    val[kSpeciesChgRC]= fSpecies;
+    val[kPt]  = GetPtBin(fTracklet->GetMomentum());
+    Double_t dyt(fTracklet->GetYref(0) - fTracklet->GetYfit(0)),
+             dzt(fTracklet->GetZref(0) - fTracklet->GetZfit(0)),
+             dydx(fTracklet->GetYfit(1)),
+             tilt(fTracklet->GetTilt());
+    // correct for tilt rotation
+    val[kYrez] = dyt - dzt*tilt;
+    val[kZrez] = dzt + dyt*tilt;
+    dydx+= tilt*fTracklet->GetZref(1);
+    val[kPrez] = TMath::ATan((fTracklet->GetYref(1) - dydx)/(1.+ fTracklet->GetYref(1)*dydx)) * TMath::RadToDeg();
+    if(fTracklet->IsRowCross()){
+      val[kSpeciesChgRC]= 0.;
+//      val[kPrez] = fkTrack->Charge(); // may be better defined
+    }/* else {
+      Float_t exb, vd, t0, s2, dl, dt;
+      fTracklet->GetCalibParam(exb, vd, t0, s2, dl, dt);
+      val[kZrez] = TMath::ATan((fTracklet->GetYref(1) - exb)/(1+fTracklet->GetYref(1)*exb));
+    }*/
+    val[kNdim] = fTracklet->GetdQdl();
+    if(DebugLevel()>=1) H->Fill(val);
+
+//     // compute covariance matrix
+//     fTracklet->GetCovAt(x, cov);
+//     fTracklet->GetCovRef(covR);
+//     cov[0] += covR[0]; cov[1] += covR[1]; cov[2] += covR[2]; 
+//     Double_t dyz[2]= {dy[1], dz[1]};
+//     Pulls(dyz, cov, tilt);
+//     ((TH3S*)arr->At(1))->Fill(sgm[fSegmentLevel], dyz[0], dyz[1]);
+//     ((TH3S*)arr->At(3))->Fill(tht, dyz[1], rc);
+
+    if(DebugLevel()>=3){
+      Bool_t rc(fTracklet->IsRowCross());
+      UChar_t err(fTracklet->GetErrorMsg());
+      Double_t x(fTracklet->GetX()),
+               pt(fTracklet->GetPt()),
+               yt(fTracklet->GetYref(0)),
+               zt(fTracklet->GetZref(0)),
+               phi(fTracklet->GetYref(1)),
+               tht(fTracklet->GetZref(1));
+      Int_t ncl(fTracklet->GetN()),
+            det(fTracklet->GetDetector());
+      (*DebugStream()) << "tracklet"
+        <<"pt="  << pt
+        <<"x="   << x
+        <<"yt="  << yt
+        <<"zt="  << zt
+        <<"phi=" << phi
+        <<"tht=" << tht
+        <<"det=" << det
+        <<"n="   << ncl
+        <<"dy0=" << dyt
+        <<"dz0=" << dzt
+        <<"dy="  << val[kYrez]
+        <<"dz="  << val[kZrez]
+        <<"dphi="<< val[kPrez]
+        <<"dQ  ="<< val[kNdim]
+        <<"rc="  << rc
+        <<"err=" << err
+        << "\n";
+    }
+  }
+  return NULL;//H->Projection(kEta, kPhi);
 }
 
 
 //________________________________________________________
-TH1* AliTRDresolution::PlotTrackTPC(const AliTRDtrackV1 *track)
+TH1* AliTRDresolution::PlotTrackIn(const AliTRDtrackV1 *track)
 {
 // Store resolution/pulls of Kalman before updating with the TRD information 
 // at the radial position of the first tracklet. The following points are used 
@@ -503,85 +493,87 @@ TH1* AliTRDresolution::PlotTrackTPC(const AliTRDtrackV1 *track)
 // 
 // Additionally the momentum resolution/pulls are calculated for usage in the 
 // PID calculation. 
-
+  //printf("AliTRDresolution::PlotTrackIn() :: track[%p]\n", (void*)track);
+  
   if(track) fkTrack = track;
   if(!fkTrack){
-    AliDebug(2, "No Track defined.");
+    AliDebug(4, "No Track defined.");
     return NULL;
   }
-  AliExternalTrackParam *tin = NULL;
-  if(!(tin = fkTrack->GetTrackLow())){
-    AliWarning("Track did not entered TRD fiducial volume.");
+  //fkTrack->Print();
+  // check container
+  THnSparseI *H=(THnSparseI*)fContainer->At(kTrackIn);
+  if(!H){
+    AliError(Form("Missing container @ %d", Int_t(kTrackIn)));
     return NULL;
   }
-  TH1 *h = NULL;
-  
-  Double_t x = tin->GetX();
-  AliTRDseedV1 *tracklet = NULL;  
-  for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
-    if(!(tracklet = fkTrack->GetTracklet(ily))) continue;
-    break;
-  }
-  if(!tracklet || TMath::Abs(x-tracklet->GetX())>1.e-3){
-    AliWarning("Tracklet did not match TRD entrance.");
+  // check input track status
+  AliExternalTrackParam *tin(NULL);
+  if(!(tin = fkTrack->GetTrackIn())){
+    AliError("Track did not entered TRD fiducial volume.");
     return NULL;
   }
-  const Int_t kNPAR(5);
-  Double_t parR[kNPAR]; memcpy(parR, tin->GetParameter(), kNPAR*sizeof(Double_t));
-  Double_t covR[3*kNPAR]; memcpy(covR, tin->GetCovariance(), 3*kNPAR*sizeof(Double_t));
-  Double_t cov[3]; tracklet->GetCovAt(x, cov);
-
-  // define sum covariances
-  TMatrixDSym COV(kNPAR); TVectorD PAR(kNPAR);
-  Double_t *pc = &covR[0], *pp = &parR[0];
-  for(Int_t ir=0; ir<kNPAR; ir++, pp++){
-    PAR(ir) = (*pp);
-    for(Int_t ic = 0; ic<=ir; ic++,pc++){ 
-      COV(ir,ic) = (*pc); COV(ic,ir) = (*pc);
-    }
+  // check first tracklet
+  AliTRDseedV1 *fTracklet(fkTrack->GetTracklet(0));
+  if(!fTracklet){
+    AliDebug(3, "No Tracklet in ly[0]. Skip track.");
+    return NULL;
   }
-  PAR[4] = TMath::Abs(PAR[4]); // remove sign of pt !!
-  //COV.Print(); PAR.Print();
-
-  //TODO Double_t dydx =  TMath::Sqrt(1.-parR[2]*parR[2])/parR[2]; 
-  Double_t dy = parR[0] - tracklet->GetY(); 
-  TObjArray *arr = (TObjArray*)fContainer->At(kTrackTPC);
-  ((TH2I*)arr->At(0))->Fill(tracklet->GetYref(1), dy);
-  ((TH2I*)arr->At(1))->Fill(tracklet->GetYref(1), dy/TMath::Sqrt(COV(0,0)+cov[0]));
-  if(tracklet->IsRowCross()){
-    Double_t dz = parR[1] - tracklet->GetZ(); 
-    ((TH2I*)arr->At(2))->Fill(tracklet->GetZref(1), dz);
-    ((TH2I*)arr->At(3))->Fill(tracklet->GetZref(1), dz/TMath::Sqrt(COV(1,1)+cov[2]));
+  // check radial position
+  Double_t x = tin->GetX();
+  if(TMath::Abs(x-fTracklet->GetX())>1.e-3){
+    AliDebug(1, Form("Tracklet did not match Track. dx[cm]=%+4.1f", x-fTracklet->GetX()));
+    return NULL;
   }
-  Double_t dphi = TMath::ASin(PAR[2])-TMath::ATan(tracklet->GetYfit(1));  ((TH2I*)arr->At(4))->Fill(tracklet->GetYref(1), dphi);
-
-
-  // register reference histo for mini-task
-  h = (TH2I*)arr->At(0);
-
-  if(DebugLevel()>=1){
+  //printf("USE y[%+f] dydx[%+f]\n", fTracklet->GetYfit(0), fTracklet->GetYfit(1));
+
+  Int_t bc(TMath::Abs(fkESD->GetTOFbc())%2);
+  const Double_t *parR(tin->GetParameter());
+  Double_t dyt(parR[0] - fTracklet->GetYfit(0)), dzt(parR[1] - fTracklet->GetZfit(0)),
+            phit(fTracklet->GetYfit(1)),
+            tilt(fTracklet->GetTilt());
+
+  // correct for tilt rotation
+  Double_t dy  = dyt - dzt*tilt,
+           dz  = dzt + dyt*tilt;
+  phit       += tilt*parR[3];
+  Double_t dphi = TMath::ASin(parR[2])-TMath::ATan(phit);
+
+  Double_t val[kNdim];
+  val[kBC]          = bc;
+  val[kPhi]         = fPhi;
+  val[kEta]         = fEta;
+  val[kSpeciesChgRC]= fTracklet->IsRowCross()?0:fSpecies;
+  val[kPt]          = GetPtBin(fPt);
+  val[kYrez]        = dy;
+  val[kZrez]        = dz;
+  val[kPrez]        = dphi*TMath::RadToDeg();
+  H->Fill(val);
+  if(DebugLevel()>=3){
     (*DebugStream()) << "trackIn"
-      << "x="       << x
-      << "P="       << &PAR
-      << "C="       << &COV
-      << "\n";
-
-    Double_t y = tracklet->GetY(); 
-    Double_t z = tracklet->GetZ(); 
-    (*DebugStream()) << "trackletIn"
-      << "y="       << y
-      << "z="       << z
-      << "Vy="      << cov[0]
-      << "Cyz="     << cov[1]
-      << "Vz="      << cov[2]
+      <<"tracklet.="  << fTracklet
+      <<"trackIn.="   << tin
       << "\n";
   }
 
+  if(!HasMCdata()) return NULL; // H->Projection(kEta, kPhi);
+  if(!(H = (THnSparseI*)fContainer->At(kMCtrackIn))) {
+    AliError(Form("Missing container @ %d", Int_t(kMCtrackIn)));
+    return NULL;
+  }
 
-  if(!HasMCdata()) return h;
+  // get MC info
   UChar_t s;
-  Float_t dx, pt0, x0=tracklet->GetX0(), y0, z0, dydx0, dzdx0;
-  if(!fkMC->GetDirections(x0, y0, z0, dydx0, dzdx0, pt0, s)) return h;
+  Float_t pt0, eta, x0=fTracklet->GetX0(), y0, z0, dydx0, dzdx0;
+  if(!fkMC->GetDirections(x0, y0, z0, dydx0, dzdx0, pt0, eta, s)) return NULL;
+  dyt = y0 - fTracklet->GetYfit(0);
+  dzt = z0 - fTracklet->GetZfit(0);
+  phit= fTracklet->GetYfit(1) + tilt*dzdx0;
+  Float_t phi = TMath::ATan2(y0, x0);
+  dy  = dyt - dzt*tilt;
+  dz  = dzt + dyt*tilt;
+  dphi= TMath::ASin(dydx0)-TMath::ATan(phit);
+
   Int_t pdg = fkMC->GetPDG(),
         sIdx(AliTRDpidUtil::Pdg2Pid(TMath::Abs(pdg))+1), // species index
         sign(0);
@@ -589,56 +581,34 @@ TH1* AliTRDresolution::PlotTrackTPC(const AliTRDtrackV1 *track)
   TParticlePDG *ppdg(fDBPDG->GetParticle(pdg));
   if(ppdg) sign = ppdg->Charge() > 0. ? 1 : -1;
 
-  // translate to reference radial position
-  dx = x0 - x; y0 -= dx*dydx0; z0 -= dx*dzdx0;
-  Float_t norm = 1./TMath::Sqrt(1.+dydx0*dydx0); // 1/sqrt(1+tg^2(phi))
-  //Fill MC info
-  TVectorD PARMC(kNPAR);
-  PARMC[0]=y0; PARMC[1]=z0;
-  PARMC[2]=dydx0*norm; PARMC[3]=dzdx0*norm;
-  PARMC[4]=1./pt0;
-
-//   TMatrixDSymEigen eigen(COV);
-//   TVectorD evals = eigen.GetEigenValues();
-//   TMatrixDSym evalsm(kNPAR);
-//   for(Int_t ir=0; ir<kNPAR; ir++) for(Int_t ic=0; ic<kNPAR; ic++) evalsm(ir,ic) = (ir==ic ? evals(ir): 0.);
-//   TMatrixD evecs = eigen.GetEigenVectors();
-//   TMatrixD sqrcov(evecs, TMatrixD::kMult, TMatrixD(evalsm, TMatrixD::kMult, evecs.T()));
-  
-  // fill histos
-  arr = (TObjArray*)fContainer->At(kMCtrackTPC);
-  // y resolution/pulls
-  ((TH2I*)arr->At(0))->Fill(dydx0, PARMC[0]-PAR[0]);
-  ((TH2I*)arr->At(1))->Fill(dydx0, (PARMC[0]-PAR[0])/TMath::Sqrt(COV(0,0)));
-  // z resolution/pulls
-  ((TH2I*)arr->At(2))->Fill(dzdx0, PARMC[1]-PAR[1]);
-  ((TH2I*)arr->At(3))->Fill(dzdx0, (PARMC[1]-PAR[1])/TMath::Sqrt(COV(1,1)));
-  // phi resolution/snp pulls
-  ((TH2I*)arr->At(4))->Fill(dydx0, TMath::ASin(PARMC[2])-TMath::ASin(PAR[2]));
-  ((TH2I*)arr->At(5))->Fill(dydx0, (PARMC[2]-PAR[2])/TMath::Sqrt(COV(2,2)));
-  // theta resolution/tgl pulls
-  ((TH2I*)arr->At(6))->Fill(dzdx0, TMath::ATan((PARMC[3]-PAR[3])/(1-PARMC[3]*PAR[3])));
-  ((TH2I*)arr->At(7))->Fill(dzdx0, (PARMC[3]-PAR[3])/TMath::Sqrt(COV(3,3)));
-  // pt resolution\\1/pt pulls\\p resolution/pull
-  ((TH3S*)arr->At(8))->Fill(pt0, PARMC[4]/PAR[4]-1., sign*sIdx);
-  ((TH3S*)arr->At(9))->Fill(PARMC[4], (PARMC[4]-PAR[4])/TMath::Sqrt(COV(4,4)), sign*sIdx);
-
-  Double_t p0 = TMath::Sqrt(1.+ PARMC[3]*PARMC[3])*pt0, p;
-  p = TMath::Sqrt(1.+ PAR[3]*PAR[3])/PAR[4];
-  Float_t sp = 
-    p*p*PAR[4]*PAR[4]*COV(4,4)
-   +2.*PAR[3]*COV(3,4)/PAR[4]
-   +PAR[3]*PAR[3]*COV(3,3)/p/p/PAR[4]/PAR[4]/PAR[4]/PAR[4];
-  ((TH3S*)arr->At(10))->Fill(p0, p/p0-1., sign*sIdx);
-  if(sp>0.) ((TH3S*)arr->At(11))->Fill(p0, (p0-p)/TMath::Sqrt(sp), sign*sIdx);
-
-  // fill debug for MC 
-  if(DebugLevel()>=1){
-    (*DebugStream()) << "trackInMC"
-      << "P="   << &PARMC
-      << "\n";
-  }
-  return h;
+
+  val[kBC]          = (bc>=kNbunchCross)?(kNbunchCross-1):bc;
+  val[kPhi]         = phi;
+  val[kEta]         = eta;
+  val[kSpeciesChgRC]= fTracklet->IsRowCross()?0:sign*(sIdx+1);
+  val[kPt]          = GetPtBin(pt0);
+  val[kYrez]        = dy;
+  val[kZrez]        = dz;
+  val[kPrez]        = dphi*TMath::RadToDeg();
+  H->Fill(val);
+
+  return NULL; //H->Projection(kEta, kPhi);
+}
+
+//________________________________________________________
+TH1* AliTRDresolution::PlotTrackOut(const AliTRDtrackV1 *track)
+{
+// Store resolution/pulls of Kalman after last update with the TRD information 
+// at the radial position of the first tracklet. The following points are used 
+// for comparison  
+//  - the (y,z,snp) of the first TRD tracklet
+//  - the (y, z, snp, tgl, pt) of the MC track reference
+// 
+// Additionally the momentum resolution/pulls are calculated for usage in the 
+// PID calculation. 
+
+  if(track) fkTrack = track;
+  return NULL;
 }
 
 //________________________________________________________
@@ -649,66 +619,92 @@ TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
   //
 
   if(!HasMCdata()){ 
-    AliWarning("No MC defined. Results will not be available.");
+    AliDebug(2, "No MC defined. Results will not be available.");
     return NULL;
   }
   if(track) fkTrack = track;
   if(!fkTrack){
-    AliDebug(2, "No Track defined.");
+    AliDebug(4, "No Track defined.");
+    return NULL;
+  }
+  if(!fContainer){
+    AliWarning("No output container defined.");
     return NULL;
   }
   // retriev track characteristics
   Int_t pdg = fkMC->GetPDG(),
         sIdx(AliTRDpidUtil::Pdg2Pid(TMath::Abs(pdg))+1), // species index
         sign(0),
-        det(-1),
-        label(fkMC->GetLabel());
+        sgm[3],
+        label(fkMC->GetLabel()),
+        fSegmentLevel(0);
   if(!fDBPDG) fDBPDG=TDatabasePDG::Instance();
   TParticlePDG *ppdg(fDBPDG->GetParticle(pdg));
   if(ppdg) sign = ppdg->Charge() > 0. ? 1 : -1;
-  Bool_t kBarrel = Bool_t(fkESD->GetStatus() & AliESDtrack::kTRDin);
 
   TObjArray *arr(NULL);TH1 *h(NULL);
+  AliTRDgeometry *geo(AliTRDinfoGen::Geometry());
+  AliTRDseedV1 *fTracklet(NULL); TObjArray *clInfoArr(NULL);
   UChar_t s;
   Double_t xAnode, x, y, z, pt, dydx, dzdx, dzdl;
   Float_t pt0, x0, y0, z0, dx, dy, dz, dydx0, dzdx0;
   Double_t covR[7]/*, cov[3]*/;
-
-  if(DebugLevel()>=1){
-    TVectorD dX(12), dY(12), dZ(12), Pt(12), dPt(12), cCOV(12*15);
-    fkMC->PropagateKalman(&dX, &dY, &dZ, &Pt, &dPt, &cCOV);
-    (*DebugStream()) << "MCkalman"
-      << "pdg=" << pdg
-      << "dx="  << &dX
-      << "dy="  << &dY
-      << "dz="  << &dZ
-      << "pt="  << &Pt
-      << "dpt=" << &dPt
-      << "cov=" << &cCOV
-      << "\n";
+  
+  if(DebugLevel()>=3){
+    // get first detector
+    Int_t det = -1;
+    for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
+      if(!(fTracklet = fkTrack->GetTracklet(ily))) continue;
+      det = fTracklet->GetDetector();
+      break;
+    }
+    if(det>=0){
+      TVectorD X(12), Y(12), Z(12), dX(12), dY(12), dZ(12), vPt(12), dPt(12), budget(12), cCOV(12*15);
+      Double_t m(-1.);
+      m = fkTrack->GetMass();
+      if(fkMC->PropagateKalman(&X, &Y, &Z, &dX, &dY, &dZ, &vPt, &dPt, &budget, &cCOV, m)){
+        (*DebugStream()) << "MCkalman"
+          << "pdg=" << pdg
+          << "det=" << det
+          << "x="   << &X
+          << "y="   << &Y
+          << "z="   << &Z
+          << "dx="  << &dX
+          << "dy="  << &dY
+          << "dz="  << &dZ
+          << "pt="  << &vPt
+          << "dpt=" << &dPt
+          << "bgt=" << &budget
+          << "cov=" << &cCOV
+          << "\n";
+      }
+    }
   }
-
-  AliTRDReconstructor rec;
-  AliTRDseedV1 *fTracklet(NULL); TObjArray *clInfoArr(NULL);
   for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
     if(!(fTracklet = fkTrack->GetTracklet(ily)))/* ||
        !fTracklet->IsOK())*/ continue;
 
-    det = fTracklet->GetDetector();
+    sgm[2] = fTracklet->GetDetector();
+    sgm[0] = AliTRDgeometry::GetSector(sgm[2]);
+    sgm[1] = sgm[0] * AliTRDgeometry::kNstack + AliTRDgeometry::GetStack(sgm[2]);
+    Double_t tilt(fTracklet->GetTilt())
+            ,t2(tilt*tilt)
+            ,corr(1./(1. + t2))
+            ,cost(TMath::Sqrt(corr));
     x0  = fTracklet->GetX0();
     //radial shift with respect to the MC reference (radial position of the pad plane)
     x= fTracklet->GetX();
-    if(!fkMC->GetDirections(x0, y0, z0, dydx0, dzdx0, pt0, s)) continue;
+    Bool_t rc(fTracklet->IsRowCross()); Float_t eta;
+    if(!fkMC->GetDirections(x0, y0, z0, dydx0, dzdx0, pt0, eta, s)) continue;
     xAnode  = fTracklet->GetX0();
 
     // MC track position at reference radial position
     dx  = x0 - x;
-    if(DebugLevel()>=1){
+    if(DebugLevel()>=4){
       (*DebugStream()) << "MC"
-        << "det="     << det
+        << "det="     << sgm[2]
         << "pdg="     << pdg
         << "sgn="     << sign
-        << "barrel="  << kBarrel
         << "pt="      << pt0
         << "x="       << x0
         << "y="       << y0
@@ -733,13 +729,13 @@ TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
     pt = TMath::Abs(fTracklet->GetPt());
     fTracklet->GetCovRef(covR);
 
-    arr = (TObjArray*)fContainer->At(kMCtrackTRD);
+    arr = (TObjArray*)((TObjArray*)fContainer->At(kMCtrack))->At(ily);
     // y resolution/pulls
-    ((TH2I*)arr->At(0))->Fill(dydx0, dy);
-    ((TH2I*)arr->At(1))->Fill(dydx0, dy/TMath::Sqrt(covR[0]));
+    if(pt0>fPtThreshold) ((TH3S*)arr->At(0))->Fill(dydx0, dy, sgm[fSegmentLevel]);
+    ((TH3S*)arr->At(1))->Fill(sgm[fSegmentLevel], dy/TMath::Sqrt(covR[0]), dz/TMath::Sqrt(covR[2]));
     // z resolution/pulls
-    ((TH2I*)arr->At(2))->Fill(dzdx0, dz);
-    ((TH2I*)arr->At(3))->Fill(dzdx0, dz/TMath::Sqrt(covR[2]));
+    ((TH2S*)arr->At(2))->Fill(dzdx0, dz);
+    ((TH3S*)arr->At(3))->Fill(dzdx0, dz/TMath::Sqrt(covR[2]), 0);
     // phi resolution/ snp pulls
     Double_t dtgp = (dydx - dydx0)/(1.- dydx*dydx0);
     ((TH2I*)arr->At(4))->Fill(dydx0, TMath::ATan(dtgp));
@@ -754,18 +750,12 @@ TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
     // pt resolution  \\ 1/pt pulls \\ p resolution for PID
     Double_t p0 = TMath::Sqrt(1.+ dzdl0*dzdl0)*pt0,
              p  = TMath::Sqrt(1.+ dzdl*dzdl)*pt;
-    if(kBarrel){
-      ((TH3S*)((TObjArray*)arr->At(8))->At(ily))->Fill(pt0, pt/pt0-1., sign*sIdx);
-      ((TH3S*)((TObjArray*)arr->At(9))->At(ily))->Fill(1./pt0, (1./pt-1./pt0)/TMath::Sqrt(covR[6]), sign*sIdx);
-      ((TH3S*)((TObjArray*)arr->At(10))->At(ily))->Fill(p0, p/p0-1., sign*sIdx);
-    } else {
-      ((TH3S*)((TObjArray*)arr->At(11))->At(ily))->Fill(pt0, pt/pt0-1., sign*sIdx);
-      ((TH3S*)((TObjArray*)arr->At(12))->At(ily))->Fill(1./pt0, (1./pt-1./pt0)/TMath::Sqrt(covR[6]), sign*sIdx);
-      ((TH3S*)((TObjArray*)arr->At(13))->At(ily))->Fill(p0, p/p0-1., sign*sIdx);
-    }
+    ((TH3S*)((TObjArray*)arr->At(8)))->Fill(pt0, pt/pt0-1., sign*sIdx);
+    ((TH3S*)((TObjArray*)arr->At(9)))->Fill(1./pt0, (1./pt-1./pt0)/TMath::Sqrt(covR[6]), sign*sIdx);
+    ((TH3S*)((TObjArray*)arr->At(10)))->Fill(p0, p/p0-1., sign*sIdx);
 
     // Fill Debug stream for Kalman track
-    if(DebugLevel()>=1){
+    if(DebugLevel()>=4){
       (*DebugStream()) << "MCtrack"
         << "pt="      << pt
         << "x="       << x
@@ -782,35 +772,29 @@ TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
     AliTRDseedV1 tt(*fTracklet);
     tt.SetZref(0, z0 - (x0-xAnode)*dzdx0);
     tt.SetZref(1, dzdx0); 
-    tt.SetReconstructor(&rec);
-    tt.Fit(kTRUE, kTRUE);
+    tt.SetReconstructor(AliTRDinfoGen::Reconstructor());
+    tt.Fit(1);
     x= tt.GetX();y= tt.GetY();z= tt.GetZ();
     dydx = tt.GetYfit(1);
     dx = x0 - x;
     ymc = y0 - dx*dydx0;
     zmc = z0 - dx*dzdx0;
-    Bool_t rc = tt.IsRowCross(); 
-    
+    dy = y-ymc;
+    dz = z-zmc;
+    Float_t dphi  = (dydx - dydx0);
+    dphi /= (1.- dydx*dydx0);
+
     // add tracklet residuals for y and dydx
     arr = (TObjArray*)fContainer->At(kMCtracklet);
-    if(!rc){
-      dy    = y-ymc;
-
-      Float_t dphi  = (dydx - dydx0);
-      dphi /= (1.- dydx*dydx0);
-
-      ((TH3S*)arr->At(0))->Fill(dydx0, dy, pt0);
-      if(tt.GetS2Y()>0.) ((TH2I*)arr->At(1))->Fill(dydx0, dy/TMath::Sqrt(tt.GetS2Y()));
-      ((TH2I*)arr->At(4))->Fill(dydx0, TMath::ATan(dphi));
-    } else {
-      // add tracklet residuals for z
-      dz = z-zmc;
-      ((TH2I*)arr->At(2))->Fill(dzdl0, dz);
-      if(tt.GetS2Z()>0.) ((TH2I*)arr->At(3))->Fill(dzdl0, dz/TMath::Sqrt(tt.GetS2Z()));
-    }
+
+    if(pt0>fPtThreshold) ((TH3S*)arr->At(0))->Fill(dydx0, dy, sgm[fSegmentLevel]);
+    if(tt.GetS2Y()>0. && tt.GetS2Z()>0.) ((TH3S*)arr->At(1))->Fill(sgm[fSegmentLevel], dy/TMath::Sqrt(tt.GetS2Y()), dz/TMath::Sqrt(tt.GetS2Z()));
+    ((TH3S*)arr->At(2))->Fill(dzdl0, dz, rc);
+    if(tt.GetS2Z()>0.) ((TH3S*)arr->At(3))->Fill(dzdl0, dz/TMath::Sqrt(tt.GetS2Z()), rc);
+    ((TH2I*)arr->At(4))->Fill(dydx0, TMath::ATan(dphi));
   
     // Fill Debug stream for tracklet
-    if(DebugLevel()>=1){
+    if(DebugLevel()>=4){
       Float_t s2y = tt.GetS2Y();
       Float_t s2z = tt.GetS2Z();
       (*DebugStream()) << "MCtracklet"
@@ -824,26 +808,26 @@ TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
         << "\n";
     }
 
-    Int_t istk = AliTRDgeometry::GetStack(det); 
-    AliTRDpadPlane *pp = fGeo->GetPadPlane(ily, istk);
+    AliTRDpadPlane *pp = geo->GetPadPlane(ily, AliTRDgeometry::GetStack(sgm[2]));
     Float_t zr0 = pp->GetRow0() + pp->GetAnodeWireOffset();
-    Float_t tilt = fTracklet->GetTilt();
     //Double_t exb = AliTRDCommonParam::Instance()->GetOmegaTau(1.5);
 
     arr = (TObjArray*)fContainer->At(kMCcluster);
     AliTRDcluster *c = NULL;
-    fTracklet->ResetClusterIter(kFALSE);
-    while((c = fTracklet->PrevCluster())){
+    tt.ResetClusterIter(kFALSE);
+    while((c = tt.PrevCluster())){
       Float_t  q = TMath::Abs(c->GetQ());
-      x = c->GetX(); y = c->GetY();z = c->GetZ();
+      x = c->GetX();//+fXcorr[c->GetDetector()][c->GetLocalTimeBin()]; y = c->GetY();z = c->GetZ();
       dx = x0 - x; 
       ymc= y0 - dx*dydx0;
       zmc= z0 - dx*dzdx0;
-      dy = (y - tilt*(z-zmc)) - ymc;
+      dy = cost*(y - ymc - tilt*(z-zmc));
+      dz = cost*(z - zmc + tilt*(y-ymc));
+      
       // Fill Histograms
-      if(q>20. && q<250.){ 
-        ((TH3S*)arr->At(0))->Fill(dydx0, dy, pt0);
-        ((TH2I*)arr->At(1))->Fill(dydx0, dy/TMath::Sqrt(c->GetSigmaY2()));
+      if(q>20. && q<250. && pt0>fPtThreshold && c->IsInChamber()){ 
+        ((TH3S*)arr->At(0))->Fill(dydx0, dy, sgm[fSegmentLevel]);
+        ((TH3S*)arr->At(1))->Fill(sgm[fSegmentLevel], dy/TMath::Sqrt(c->GetSigmaY2()), dz/TMath::Sqrt(c->GetSigmaZ2()));
       }
 
       // Fill calibration container
@@ -856,16 +840,20 @@ TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
       clInfo->SetGlobalPosition(ymc, zmc, dydx0, dzdx0);
       clInfo->SetResolution(dy);
       clInfo->SetAnisochronity(d);
-      clInfo->SetDriftLength(dx-.5*AliTRDgeometry::CamHght());
+      clInfo->SetDriftLength(dx);
       clInfo->SetTilt(tilt);
-      fMCcl->Add(clInfo);
-      if(DebugLevel()>=2){ 
-        if(!clInfoArr) clInfoArr=new TObjArray(AliTRDseedV1::kNclusters);
+      if(fMCcl) fMCcl->Add(clInfo);
+      else AliDebug(1, "MCcl exchange container missing. Activate by calling \"InitExchangeContainers()\"");
+      if(DebugLevel()>=5){ 
+        if(!clInfoArr){ 
+          clInfoArr=new TObjArray(AliTRDseedV1::kNclusters);
+          clInfoArr->SetOwner(kFALSE);
+        }
         clInfoArr->Add(clInfo);
       }
     }
     // Fill Debug Tree
-    if(DebugLevel()>=2 && clInfoArr){
+    if(DebugLevel()>=5 && clInfoArr){
       (*DebugStream()) << "MCcluster"
         <<"clInfo.=" << clInfoArr
         << "\n";
@@ -877,6 +865,44 @@ TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
 }
 
 
+//__________________________________________________________________________
+Int_t AliTRDresolution::GetPtBin(Float_t pt)
+{
+// Find pt bin according to local pt segmentation
+  Int_t ipt(-1);
+  while(ipt<AliTRDresolution::kNpt){
+    if(pt<fgPtBin[ipt+1]) break;
+    ipt++;
+  }
+  return ipt;
+}
+
+//________________________________________________________
+Float_t AliTRDresolution::GetMeanStat(TH1 *h, Float_t cut, Option_t *opt)
+{
+// return mean number of entries/bin of histogram "h"
+// if option "opt" is given the following values are accepted:
+//   "<" : consider only entries less than "cut"
+//   ">" : consider only entries greater than "cut"
+
+  //Int_t dim(h->GetDimension());
+  Int_t nbx(h->GetNbinsX()), nby(h->GetNbinsY()), nbz(h->GetNbinsZ());
+  Double_t sum(0.); Int_t n(0);
+  for(Int_t ix(1); ix<=nbx; ix++)
+    for(Int_t iy(1); iy<=nby; iy++)
+      for(Int_t iz(1); iz<=nbz; iz++){
+        if(strcmp(opt, "")==0){sum += h->GetBinContent(ix, iy, iz); n++;}
+        else{
+          if(strcmp(opt, "<")==0) {
+            if(h->GetBinContent(ix, iy, iz)<cut) {sum += h->GetBinContent(ix, iy, iz); n++;}
+          } else if(strcmp(opt, ">")==0){
+            if(h->GetBinContent(ix, iy, iz)>cut) {sum += h->GetBinContent(ix, iy, iz); n++;}
+          } else {sum += h->GetBinContent(ix, iy, iz); n++;}
+        }
+      }
+  return n>0?sum/n:0.;
+}
+
 //________________________________________________________
 Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
 {
@@ -884,377 +910,456 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
   // Get the reference figures
   //
 
-  Float_t xy[4] = {0., 0., 0., 0.};
   if(!gPad){
     AliWarning("Please provide a canvas to draw results.");
     return kFALSE;
   }
-  Int_t first(2),     // first particle species to be drawn
-        nspecies(7); // last particle species to be drawn
-  TList *l = NULL; TVirtualPad *pad=NULL;
+/*  Int_t selection[100], n(0), selStart(0); // 
+  Int_t ly0(0), dly(5);
+  TList *l(NULL); TVirtualPad *pad(NULL); */
   switch(ifig){
-  case kCharge:
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    ((TVirtualPad*)l->At(0))->cd();
-    ((TGraphAsymmErrors*)((TObjArray*)fGraphM->At(kCharge))->At(0))->Draw("apl");
-    ((TVirtualPad*)l->At(1))->cd();
-    ((TGraphErrors*)((TObjArray*)fGraphS->At(kCharge))->At(0))->Draw("apl");
-    break;
-  case kCluster:
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0] = -.3; xy[1] = -200.; xy[2] = .3; xy[3] = 1000.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kCluster, 0)) break;
-    xy[0] = -.3; xy[1] = -0.5; xy[2] = .3; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kCluster, 1)) break;
-    return kTRUE;
-  case kTrackTRD :
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0] = -.3; xy[1] = -500.; xy[2] = .3; xy[3] = 1500.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kTrackTRD , 0)) break;
-    xy[0] = -.3; xy[1] = -0.5; xy[2] = .3; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kTrackTRD , 1)) break;
-    return kTRUE;
-  case 3: // kTrackTRD  z
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0] = -1.; xy[1] = -1000.; xy[2] = 1.; xy[3] = 4000.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kTrackTRD , 2)) break;
-    xy[0] = -1.; xy[1] = -0.5; xy[2] = 1.; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kTrackTRD , 3)) break;
-    return kTRUE;
-  case 4: // kTrackTRD  phi
-    xy[0] = -.3; xy[1] = -5.; xy[2] = .3; xy[3] = 50.;
-    if(GetGraphPlot(&xy[0], kTrackTRD , 4)) return kTRUE;
+  case 0:
     break;
-  case 5: // kTrackTPC y
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0] = -.3; xy[1] = -500.; xy[2] = .3; xy[3] = 1500.;
-    pad = ((TVirtualPad*)l->At(0)); pad->cd();
-    pad->SetMargin(0.1, 0.1, 0.1, 0.01);
-    if(!GetGraphPlot(&xy[0], kTrackTPC, 0)) break;
-    xy[0] = -.3; xy[1] = -0.5; xy[2] = .3; xy[3] = 2.5;
-    pad=((TVirtualPad*)l->At(1)); pad->cd();
-    pad->SetMargin(0.1, 0.1, 0.1, 0.01);
-    if(!GetGraphPlot(&xy[0], kTrackTPC, 1)) break;
-    return kTRUE;
-  case 6: // kTrackTPC z
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0] = -1.; xy[1] = -1000.; xy[2] = 1.; xy[3] = 4000.;
-    pad = ((TVirtualPad*)l->At(0)); pad->cd();
-    pad->SetMargin(0.1, 0.1, 0.1, 0.01);
-    if(!GetGraphPlot(&xy[0], kTrackTPC, 2)) break;
-    xy[0] = -1.; xy[1] = -0.5; xy[2] = 1.; xy[3] = 2.5;
-    pad = ((TVirtualPad*)l->At(1)); pad->cd();
-    pad->SetMargin(0.1, 0.1, 0.1, 0.01);
-    if(!GetGraphPlot(&xy[0], kTrackTPC, 3)) break;
-    return kTRUE;
-  case 7: // kTrackTPC phi
-    xy[0] = -.3; xy[1] = -5.; xy[2] = .3; xy[3] = 50.;
-    if(GetGraphPlot(&xy[0], kTrackTPC, 4)) return kTRUE;
-    break;
-  case 8: // kMCcluster pt <2 GeV/c
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-.3; xy[1]=-50.; xy[2]=.3; xy[3]=650.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCcluster, 0)) break;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCcluster, 1)) break;
-    return kTRUE;
-  case 9: // kMCcluster pt > 3 GeV/c
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-.3; xy[1]=-50.; xy[2]=.3; xy[3]=650.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCcluster, 2)) break;
-    xy[0] = -.3; xy[1] = -0.5; xy[2] = .3; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCcluster, 3)) break;
-    return kTRUE;
-  case 10: //kMCtracklet [y] pt < 3 GeV/c
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-.2; xy[1]=-50.; xy[2]=.2; xy[3] =250.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtracklet, 0)) break;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtracklet, 1)) break;
-    return kTRUE;
-  case 11: //kMCtracklet [y] pt > 3 GeV/c
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-.2; xy[1]=-50.; xy[2]=.2; xy[3] =250.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtracklet, 2)) break;
-    xy[0] = -.2; xy[1] = -0.5; xy[2] = .2; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtracklet, 3)) break;
-    return kTRUE;
-  case 12: //kMCtracklet [z]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-1.; xy[1]=-100.; xy[2]=1.; xy[3] =2500.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtracklet, 4)) break;
-    xy[0] = -1.; xy[1] = -0.5; xy[2] = 1.; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtracklet, 5)) break;
-    return kTRUE;
-  case 13: //kMCtracklet [phi]
-    xy[0]=-.3; xy[1]=-3.; xy[2]=.3; xy[3] =25.;
-    if(!GetGraphPlot(&xy[0], kMCtracklet, 6)) break;
-    return kTRUE;
-  case 14: //kMCtrackTRD [y]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-.2; xy[1]=-50.; xy[2]=.2; xy[3] =400.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTRD, 0)) break;
-    xy[0] = -.2; xy[1] = -0.5; xy[2] = .2; xy[3] = 3.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTRD, 1)) break;
-    return kTRUE;
-  case 15: //kMCtrackTRD [z]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-1.; xy[1]=-700.; xy[2]=1.; xy[3] =1500.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTRD, 2)) break;
-    xy[0] = -1.; xy[1] = -0.5; xy[2] = 1.; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTRD, 3)) break;
-    return kTRUE;
-  case 16: //kMCtrackTRD [phi/snp]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-.2; xy[1]=-0.2; xy[2]=.2; xy[3] =2.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTRD, 4)) break;
-    xy[0] = -.2; xy[1] = -0.5; xy[2] = .2; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTRD, 5)) break;
-    return kTRUE;
-  case 17: //kMCtrackTRD [theta/tgl]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-1.; xy[1]=-0.5; xy[2]=1.; xy[3] =5.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTRD, 6)) break;
-    xy[0] = -.2; xy[1] = -0.5; xy[2] = .2; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTRD, 7)) break;
-    return kTRUE;
-  case 18: //kMCtrackTRD [pt]
-    xy[0] = 0.4; xy[1] = -.7; xy[2] = 12.; xy[3] = 4.;
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    pad = (TVirtualPad*)l->At(0); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 8, first, nspecies)) break;
-    pad->Modified(); pad->Update(); pad->SetLogx();
-    pad = (TVirtualPad*)l->At(1); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 8, 55+first, nspecies, kTRUE)) break;
-    pad->Modified(); pad->Update(); pad->SetLogx();
-    return kTRUE;
-  case 19: //kMCtrackTRD [1/pt] pulls
-    xy[0] = 0.; xy[1] = -1.; xy[2] = 2.; xy[3] = 3.5;
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    pad = (TVirtualPad*)l->At(0); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 9, first, nspecies)) break;
-    pad = (TVirtualPad*)l->At(1); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 9, 55+first, nspecies, kTRUE)) break;
-    return kTRUE;
-  case 20: //kMCtrackTRD [p]
-    xy[0] = 0.4; xy[1] = -.7; xy[2] = 12.; xy[3] = 4.;
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    pad = (TVirtualPad*)l->At(0); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 10, first, nspecies)) break;
-    pad->Modified(); pad->Update(); pad->SetLogx();
-    pad = (TVirtualPad*)l->At(1); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 10, 55+first, nspecies, kTRUE)) break;
-    pad->Modified(); pad->Update(); pad->SetLogx();
-    return kTRUE;
-  case 21: //kMCtrackTRD - SA [pt]
-    xy[0] = 0.; xy[1] = -5.; xy[2] = 12.; xy[3] = 7.;
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    pad = (TVirtualPad*)l->At(0); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 11, first, nspecies)) break;
-    pad->SetLogx();
-    pad = (TVirtualPad*)l->At(1); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 11, 55+first, nspecies, kTRUE)) break;
-    pad->SetLogx();
-    return kTRUE;
-  case 22: //kMCtrackTRD - SA [1/pt] pulls
-    xy[0] = 0.; xy[1] = -1.5; xy[2] = 2.; xy[3] = 2.;
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    pad = (TVirtualPad*)l->At(0); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 12, first, nspecies)) break;
-    pad = (TVirtualPad*)l->At(1); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 12, 55+first, nspecies, kTRUE)) break;
-    return kTRUE;
-  case 23: //kMCtrackTRD - SA [p]
-    xy[0] = 0.; xy[1] = -7.5; xy[2] = 12.; xy[3] = 10.5;
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    pad = (TVirtualPad*)l->At(0); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 13, first, nspecies)) break;
-    pad->SetLogx();
-    pad = (TVirtualPad*)l->At(1); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrack(&xy[0], 13, 55+first, nspecies, kTRUE)) break;
-    pad->SetLogx();
-    return kTRUE;
-  case 24: // kMCtrackTPC [y]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-.25; xy[1]=-50.; xy[2]=.25; xy[3] =800.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTPC, 0)) break;
-    xy[0] = -.25; xy[1] = -0.5; xy[2] = .25; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTPC, 1)) break;
-    return kTRUE;
-  case 25: // kMCtrackTPC [z]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-1.; xy[1]=-500.; xy[2]=1.; xy[3] =800.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTPC, 2)) break;
-    xy[0] = -1.; xy[1] = -0.5; xy[2] = 1.; xy[3] = 2.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTPC, 3)) break;
-    return kTRUE;
-  case 26: // kMCtrackTPC [phi|snp]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-.25; xy[1]=-0.5; xy[2]=.25; xy[3] =2.5;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTPC, 4)) break;
-    xy[0] = -.25; xy[1] = -0.5; xy[2] = .25; xy[3] = 1.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTPC, 5)) break;
-    return kTRUE;
-  case 27: // kMCtrackTPC [theta|tgl]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0]=-1.; xy[1]=-1.; xy[2]=1.; xy[3] =4.;
-    ((TVirtualPad*)l->At(0))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTPC, 6)) break;
-    xy[0] = -1.; xy[1] = -0.5; xy[2] = 1.; xy[3] = 1.5;
-    ((TVirtualPad*)l->At(1))->cd();
-    if(!GetGraphPlot(&xy[0], kMCtrackTPC, 7)) break;
-    return kTRUE;
-  case 28: // kMCtrackTPC [pt]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0] = 0.4; xy[1] = -.8; xy[2] = 12.; xy[3] = 6.;
-    pad=(TVirtualPad*)l->At(0); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrackTPC(xy, 8, first, nspecies)) break;
-    pad->SetLogx();
-    xy[0]=0.; xy[1]=-0.5; xy[2]=2.; xy[3] =3.;
-    pad = (TVirtualPad*)l->At(1); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrackTPC(xy, 9, first, nspecies, kTRUE)) break;
-    return kTRUE;
-  case 29: // kMCtrackTPC [p]
-    gPad->Divide(2, 1, 1.e-5, 1.e-5); l=gPad->GetListOfPrimitives(); 
-    xy[0] = 0.4; xy[1] = -.8; xy[2] = 8.; xy[3] = 6.;
-    pad = ((TVirtualPad*)l->At(0));pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrackTPC(xy, 10, first, nspecies)) break;
-    pad->SetLogx();
-    xy[0]=0.; xy[1]=-0.5; xy[2]=8.; xy[3] =2.5;
-    pad = ((TVirtualPad*)l->At(1)); pad->cd();
-    pad->SetMargin(0.125, 0.015, 0.1, 0.015);
-    if(!GetGraphTrackTPC(xy, 11, first, nspecies, kTRUE)) break;
-    return kTRUE;
-  case 30:  // kMCtrackTOF [z]
-    return kTRUE;
   }
   AliWarning(Form("Reference plot [%d] missing result", ifig));
   return kFALSE;
 }
 
-Char_t const *fgParticle[11]={
-  " p bar", " K -", " #pi -", " #mu -", " e -",
-  " No PID",
-  " e +", " #mu +", " #pi +", " K +", " p",
-};
-const Color_t fgColorS[11]={
-kOrange, kOrange-3, kMagenta+1, kViolet, kRed,
-kGray,
-kRed, kViolet, kMagenta+1, kOrange-3, kOrange
-};
-const Color_t fgColorM[11]={
-kCyan-5, kAzure-4, kBlue-7, kBlue+2, kViolet+10,
-kBlack,
-kViolet+10, kBlue+2, kBlue-7, kAzure-4, kCyan-5
-};
-const Marker_t fgMarker[11]={
-30, 30, 26, 25, 24,
-28,
-20, 21, 22, 29, 29
-};
+
 //________________________________________________________
-Bool_t AliTRDresolution::PostProcess()
+void AliTRDresolution::MakePtSegmentation(Float_t pt0, Float_t dpt)
 {
-  //fContainer = dynamic_cast<TObjArray*>(GetOutputData(0));
-  if (!fContainer) {
-    AliError("ERROR: list not available");
-    return kFALSE;
+// Build pt segments
+  for(Int_t j(0); j<=kNpt; j++){
+    pt0+=(TMath::Exp(j*j*dpt)-1.);
+    fgPtBin[j]=pt0;
   }
-  Int_t nc(0);
-  TGraph *gm= NULL, *gs= NULL;
-  if(!fGraphS && !fGraphM){ 
-    TObjArray *aM(NULL), *aS(NULL);
-    Int_t n = fContainer->GetEntriesFast();
-    fGraphS = new TObjArray(n); fGraphS->SetOwner();
-    fGraphM = new TObjArray(n); fGraphM->SetOwner();
-    for(Int_t ig=0; ig<n; ig++){
-      fGraphM->AddAt(aM = new TObjArray(fgNproj[ig]), ig);
-      fGraphS->AddAt(aS = new TObjArray(fgNproj[ig]), ig);
-
-      for(Int_t ic=0; ic<fgNproj[ig]; ic++){
-        //printf("g[%d] c[%d] n[%d]\n", ig, ic, fgNcomp[nc]);
-        if(fgNcomp[nc]>1){
-          TObjArray *agS(NULL), *agM(NULL);
-          aS->AddAt(agS = new TObjArray(fgNcomp[nc]), ic); 
-          aM->AddAt(agM = new TObjArray(fgNcomp[nc]), ic); 
-          for(Int_t is=fgNcomp[nc]; is--;){
-            agS->AddAt(gs = new TGraphErrors(), is);
-            Int_t is0(is%11);
-            gs->SetMarkerStyle(fgMarker[is0]);
-            gs->SetMarkerColor(fgColorS[is0]);
-            gs->SetLineColor(fgColorS[is0]);
-            gs->SetNameTitle(Form("s_%d%02d%02d", ig, ic, is), fgParticle[is0]);
-
-            agM->AddAt(gm = new TGraphErrors(), is);
-            gm->SetMarkerStyle(fgMarker[is0]);
-            gm->SetMarkerColor(fgColorM[is0]);
-            gm->SetLineColor(fgColorM[is0]);
-            gm->SetNameTitle(Form("m_%d%02d%02d", ig, ic, is), fgParticle[is0]);
-          }
-        } else {
-          aS->AddAt(gs = new TGraphErrors(), ic);
-          gs->SetMarkerStyle(23);
-          gs->SetMarkerColor(kRed);
-          gs->SetLineColor(kRed);
-          gs->SetNameTitle(Form("s_%d%02d", ig, ic), "");
-  
-          aM->AddAt(gm = ig ? (TGraph*)new TGraphErrors() : (TGraph*)new TGraphAsymmErrors(), ic);
-          gm->SetLineColor(kBlack);
-          gm->SetMarkerStyle(7);
-          gm->SetMarkerColor(kBlack);
-          gm->SetNameTitle(Form("m_%d%02d", ig, ic), "");
-        }
-        nc+=fgNcomp[ic];
+}
+
+//________________________________________________________
+void AliTRDresolution::MakeSummary()
+{
+// Build summary plots
+
+  if(!fProj){
+    AliError("Missing results");
+    return;
+  }  
+  TVirtualPad *p(NULL); TCanvas *cOut(NULL);
+  TObjArray *arr(NULL); TH2 *h2(NULL);
+
+  // cluster resolution
+  // define palette
+  gStyle->SetPalette(1);
+  const Int_t nClViews(8);
+  const Char_t *vClName[nClViews] = {"HClY", "HClYn", "HClYp", "HClQn", "HClQp", "HClYXTCp", "HClYXTCn", "HClYXPh"};
+  if((arr = (TObjArray*)fProj->At(kCluster))){
+    for(Int_t iview(0); iview<nClViews; iview++){
+      cOut = new TCanvas(Form("TRDsummary%s_Cl%02d", GetName(), iview), "Cluster Resolution", 1024, 768);
+      cOut->Divide(3,2, 2.e-3, 2.e-3);
+      for(Int_t iplot(0); iplot<6; iplot++){
+        p=cOut->cd(iplot+1);    p->SetRightMargin(0.1572581);p->SetTopMargin(0.08262712);
+        if(!(h2 = (TH2*)arr->FindObject(Form("%s%d_2D", vClName[iview], iplot)))) continue;
+        h2->Draw("colz");
       }
+      cOut->SaveAs(Form("%s.gif", cOut->GetName()));
+      //delete cOut;
     }
   }
 
-/*  printf("\n\n\n"); fGraphS->ls();
-  printf("\n\n\n"); fGraphM->ls();*/
-  
+  // tracklet systematic
+  const Int_t nTrkltViews(10);
+  const Char_t *vTrkltName[nTrkltViews] = {"HTrkltY", "HTrkltYn", "HTrkltYp", "HTrkltPhn", "HTrkltPhp", "HTrkltZ", "HTrkltQn", "HTrkltQp", "HTrkltPn", "HTrkltPp"};
+  if((arr = (TObjArray*)fProj->At(kTracklet))){
+    for(Int_t iview(0); iview<nTrkltViews; iview++){
+      cOut = new TCanvas(Form("TRDsummary%s_Trklt%02d", GetName(), iview), "Tracklet Resolution", 1024, 768);
+      cOut->Divide(3,2, 2.e-3, 2.e-3);
+      for(Int_t iplot(0); iplot<6; iplot++){
+        p=cOut->cd(iplot+1); p->SetRightMargin(0.1572581); p->SetTopMargin(0.08262712);
+        if(!(h2 = (TH2*)arr->FindObject(Form("%s%d_2D", vTrkltName[iview], iplot)))) continue;
+        h2->Draw("colz");
+      }
+      cOut->SaveAs(Form("%s.gif", cOut->GetName()));
+      //delete cOut;
+    }
+  }
+  // trackIn systematic
+  const Char_t *hname[] = {"HTrkInY", "HTrkInYn", "HTrkInYp", "HTrkInZ", "HTrkInPhn", "HTrkInPhp"};
+  if((arr = (TObjArray*)fProj->At(kTrackIn))){
+    cOut = new TCanvas(Form("TRDsummary%s_TrkIn", GetName()), "Track IN Resolution", 1024, 768);
+    cOut->Divide(3,2, 2.e-3, 2.e-3);
+    for(Int_t iplot(0); iplot<6; iplot++){
+      p=cOut->cd(iplot+1);    p->SetRightMargin(0.1572581);p->SetTopMargin(0.08262712);
+        if(!(h2 = (TH2*)arr->FindObject(Form("%s_2D", hname[iplot])))) continue;
+        h2->Draw("colz");
+    }
+    cOut->SaveAs(Form("%s.gif", cOut->GetName()));
+    //delete cOut;
+  }
+  gStyle->SetPalette(1);
+}
+
+//________________________________________________________
+void AliTRDresolution::GetRange(TH2 *h2, Char_t mod, Float_t *range)
+{
+// Returns the range of the bulk of data in histogram h2. Removes outliers. 
+// The "range" vector should be initialized with 2 elements
+// Option "mod" can be any of
+//   - 0 : gaussian like distribution 
+//   - 1 : tailed distribution 
+
+  Int_t nx(h2->GetNbinsX())
+      , ny(h2->GetNbinsY())
+      , n(nx*ny);
+  Double_t *data=new Double_t[n];
+  for(Int_t ix(1), in(0); ix<=nx; ix++){
+    for(Int_t iy(1); iy<=ny; iy++)
+      data[in++] = h2->GetBinContent(ix, iy);
+  }
+  Double_t mean, sigm;
+  AliMathBase::EvaluateUni(n, data, mean, sigm, Int_t(n*.8));
+
+  range[0]=mean-3.*sigm; range[1]=mean+3.*sigm;
+  if(mod==1) range[0]=TMath::Max(Float_t(1.e-3), range[0]); 
+  AliDebug(2, Form("h[%s] range0[%f %f]", h2->GetName(), range[0], range[1]));
+  TH1S h1("h1SF0", "", 100, range[0], range[1]);
+  h1.FillN(n,data,0);
+  delete [] data;
+  switch(mod){
+  case 0:// gaussian distribution  
+  {
+    TF1 fg("fg", "gaus", mean-3.*sigm, mean+3.*sigm);
+    h1.Fit(&fg, "QN");
+    mean=fg.GetParameter(1); sigm=fg.GetParameter(2);
+    range[0] = mean-2.5*sigm;range[1] = mean+2.5*sigm;
+    AliDebug(2, Form("     rangeG[%f %f]", range[0], range[1]));
+    break;
+  }
+  case 1:// tailed distribution  
+  {  
+    Int_t bmax(h1.GetMaximumBin());
+    Int_t jBinMin(1), jBinMax(100);
+    for(Int_t ibin(bmax); ibin--;){
+      if(h1.GetBinContent(ibin)<1.){
+        jBinMin=ibin; break;
+      }
+    }
+    for(Int_t ibin(bmax); ibin++;){
+      if(h1.GetBinContent(ibin)<1.){
+        jBinMax=ibin; break;
+      }
+    }
+    range[0]=h1.GetBinCenter(jBinMin); range[1]=h1.GetBinCenter(jBinMax);
+    AliDebug(2, Form("     rangeT[%f %f]", range[0], range[1]));
+    break;
+  }
+  }
+
+  return;
+}
+
+
+//________________________________________________________
+Bool_t AliTRDresolution::MakeProjectionCluster()
+{
+// Analyse cluster
+  const Int_t kNcontours(9);
+  const Int_t kNstat(300);
+  Int_t cidx = kCluster;
+  if(fProj && fProj->At(cidx)) return kTRUE;
+  if(!fContainer){
+    AliError("Missing data container.");
+    return kFALSE;
+  }
+  THnSparse *H(NULL);
+  if(!(H = (THnSparse*)fContainer->At(cidx))){
+    AliError(Form("Missing/Wrong data @ %d.", cidx));
+    return kFALSE;
+  }
+  Int_t ndim(H->GetNdimensions());
+  Int_t coord[kNdim]; memset(coord, 0, sizeof(Int_t) * kNdim); Double_t v = 0.;
+  TAxis *aa[kNdim], *as(NULL), *apt(NULL); memset(aa, 0, sizeof(TAxis*) * kNdim);
+  for(Int_t id(0); id<ndim; id++) aa[id] = H->GetAxis(id);
+  if(ndim > kPt) apt = H->GetAxis(kPt);
+  if(ndim > kSpeciesChgRC) as  = H->GetAxis(kSpeciesChgRC);
+  // build list of projections
+  const Int_t nsel(12), npsel(5);
+  // define rebinning strategy
+  const Int_t nEtaPhi(4); Int_t rebinEtaPhiX[nEtaPhi] = {1, 2, 5, 1}, rebinEtaPhiY[nEtaPhi] = {2, 1, 1, 5};
+  AliTRDresolutionProjection hp[fgkNproj[cidx]], *php[nsel][npsel]; memset(php, 0, nsel*npsel*sizeof(AliTRDresolutionProjection*));
+  Int_t ih(0), isel(-1), np[nsel]; memset(np, 0, nsel*sizeof(Int_t));
+  for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
+    isel++; // new selection
+    hp[ih].Build(Form("HClY%d", ily), Form("Clusters :: r-#phi residuals ly%d", ily), kEta, kPhi, kYrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HClYn%d", ily), Form("Clusters[-]:: r-#phi residuals ly%d", ily), kEta, kPhi, kYrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HClQn%d", ily), Form("Clusters[-]:: r-#phi residuals ly%d", ily), kEta, kPhi, kSpeciesChgRC, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HClYXTCn%d", ily), Form("Clusters[-]:: r-#phi(x,TC) residuals ly%d", ily), kPrez, kZrez, kYrez, aa);
+//    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HClYXPh%d", ily), Form("Clusters :: r-#phi(x,#Phi) residuals ly%d", ily), kPrez, kPt, kYrez, aa);
+//    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    isel++; // new selection
+      php[isel][np[isel]++] = &hp[ih-5]; // relink HClY
+    hp[ih].Build(Form("HClYp%d", ily), Form("Clusters[+]:: r-#phi residuals ly%d", ily), kEta, kPhi, kYrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HClQp%d", ily), Form("Clusters[+]:: r-#phi residuals ly%d", ily), kEta, kPhi, kSpeciesChgRC, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HClYXTCp%d", ily), Form("Clusters[+]:: r-#phi(x,TC) residuals ly%d", ily), kPrez, kZrez, kYrez, aa);
+//    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+      php[isel][np[isel]++] = &hp[ih-4]; // relink HClYXPh
+  }
+
+  Int_t ly(0), ch(0), rcBin(as?as->FindBin(0.):-1), chBin(apt?apt->FindBin(0.):-1);
+  for (Long64_t ib(0); ib < H->GetNbins(); ib++) {
+    v = H->GetBinContent(ib, coord); if(v<1.) continue;
+    ly = coord[kBC]-1;
+    // RC selection
+    if(rcBin>0 && coord[kSpeciesChgRC] == rcBin) continue;
+
+    // charge selection
+    ch = 0; // [-] track
+    if(chBin>0 && coord[kPt] > chBin) ch = 1;  // [+] track
+
+    isel = ly*2+ch;
+    for(Int_t jh(0); jh<np[isel]; jh++) php[isel][jh]->Increment(coord, v);
+  }
+
+  if(!fProj){
+    AliInfo("Building array of projections ...");
+    fProj = new TObjArray(kNclasses); fProj->SetOwner(kTRUE);
+  }
+  TObjArray *arr(NULL);
+  fProj->AddAt(arr = new TObjArray(fgkNproj[cidx]), cidx);
+
+  TH2 *h2(NULL);
+  for(; ih--; ){
+    Int_t mid(1), nstat(kNstat);
+    if(strchr(hp[ih].fH->GetName(), 'Q')){ mid=2; /*nstat=300;*/}
+    if(!(h2 = hp[ih].Projection2D(nstat, kNcontours, mid))) continue;
+    arr->AddAt(h2, ih);
+  }
+
+  return kTRUE;
+}
+
+//________________________________________________________
+Bool_t AliTRDresolution::MakeProjectionTracklet()
+{
+// Analyse tracklet
+  const Int_t kNcontours(9);
+  const Int_t kNstat(100);
+  Int_t cidx = kTracklet;
+  if(fProj && fProj->At(cidx)) return kTRUE;
+  if(!fContainer){
+    AliError("Missing data container.");
+    return kFALSE;
+  }
+  THnSparse *H(NULL);
+  if(!(H = (THnSparse*)fContainer->At(cidx))){
+    AliError(Form("Missing/Wrong data @ %d.", cidx));
+    return kFALSE;
+  }
+  Int_t ndim(H->GetNdimensions());
+  Int_t coord[kNdim+1]; memset(coord, 0, sizeof(Int_t) * (kNdim+1)); Double_t v = 0.;
+  TAxis *aa[kNdim+1], *as(NULL); memset(aa, 0, sizeof(TAxis*) * (kNdim+1));
+  for(Int_t id(0); id<ndim; id++) aa[id] = H->GetAxis(id);
+  if(ndim > kSpeciesChgRC) as = H->GetAxis(kSpeciesChgRC);
+  // build list of projections
+  const Int_t nsel(18), npsel(6);
+  // define rebinning strategy
+  const Int_t nEtaPhi(4); Int_t rebinEtaPhiX[nEtaPhi] = {1, 2, 5, 1}, rebinEtaPhiY[nEtaPhi] = {2, 1, 1, 5};
+  AliTRDresolutionProjection hp[fgkNproj[cidx]], *php[nsel][npsel]; memset(php, 0, nsel*npsel*sizeof(AliTRDresolutionProjection*));
+  Int_t ih(0), isel(-1), np[nsel]; memset(np, 0, nsel*sizeof(Int_t));
+  for(Int_t ily(0); ily<AliTRDgeometry::kNlayer; ily++){
+    isel++; // new selection
+    hp[ih].Build(Form("HTrkltY%d", ily), Form("Tracklets   :: r-#phi residuals ly%d", ily), kEta, kPhi, kYrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltYn%d", ily), Form("Tracklets[-]:: r-#phi residuals ly%d", ily), kEta, kPhi, kYrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltPhn%d", ily), Form("Tracklets[-]:: #Delta#phi residuals ly%d", ily), kEta, kPhi, kPrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltPn%d", ily), Form("Tracklets[-]:: Momentum distribution ly%d", ily), kEta, kPhi, kPt, aa);
+    hp[ih].SetShowRange(6.,12.);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltYPn%d", ily), Form("Tracklets[-]:: r-#phi/p_{t} residuals ly%d", ily), kPt, kPhi, kYrez, aa);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltQn%d", ily), Form("Tracklets[-]:: dQdl ly%d", ily), kEta, kPhi, kNdim, aa);
+    hp[ih].SetShowRange(700.,1100.);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    isel++; // new selection
+    php[isel][np[isel]++] = &hp[ih-6]; // relink first histo
+    hp[ih].Build(Form("HTrkltYp%d", ily), Form("Tracklets[+]:: r-#phi residuals ly%d", ily), kEta, kPhi, kYrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltPhp%d", ily), Form("Tracklets[+]:: #Delta#phi residuals ly%d", ily), kEta, kPhi, kPrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltPp%d", ily), Form("Tracklets[+]:: Momentum distribution ly%d", ily), kEta, kPhi, kPt, aa);
+    hp[ih].SetShowRange(6.,12.);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltYPp%d", ily), Form("Tracklets[+]:: r-#phi/p_{t} residuals ly%d", ily), kPt, kPhi, kYrez, aa);
+      php[isel][np[isel]++] = &hp[ih++];
+    hp[ih].Build(Form("HTrkltQp%d", ily), Form("Tracklets[+]:: dQdl ly%d", ily), kEta, kPhi, kNdim, aa);
+    hp[ih].SetShowRange(700.,1100.);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+    isel++; // new selection
+    hp[ih].Build(Form("HTrkltZ%d", ily), Form("Tracklets[RC]:: z residuals ly%d", ily), kEta, kPhi, kZrez, aa);
+    hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+      php[isel][np[isel]++] = &hp[ih++];
+  }
+
+  Int_t ly(0), ch(0), rcBin(as?as->FindBin(0.):-1);
+  for (Long64_t ib(0); ib < H->GetNbins(); ib++) {
+    v = H->GetBinContent(ib, coord);
+    if(v<1.) continue;
+    ly = coord[kBC]-1; // layer selection
+    // charge selection
+    ch = 0; // [-] track
+    if(rcBin>0){ // debug mode in which species are also saved
+      if(coord[kSpeciesChgRC] > rcBin) ch = 1;  // [+] track
+      else if(coord[kSpeciesChgRC] == rcBin) ch = 2;  // [RC] track
+    }
+    isel = ly*3+ch;
+    for(Int_t jh(0); jh<np[isel]; jh++) php[isel][jh]->Increment(coord, v);
+  }
+
+  if(!fProj){
+    AliInfo("Building array of projections ...");
+    fProj = new TObjArray(kNclasses); fProj->SetOwner(kTRUE);
+  }
+  TObjArray *arr(NULL);
+  fProj->AddAt(arr = new TObjArray(fgkNproj[cidx]), cidx);
+
+  TH2 *h2(NULL);
+  for(; ih--; ){
+    Int_t mid(0), nstat(kNstat);
+    if(strchr(hp[ih].fH->GetName(), 'Q')){ mid=2; /*nstat=300;*/}
+    if(!(h2 = hp[ih].Projection2D(nstat, kNcontours, mid))) continue;
+    arr->AddAt(h2, ih);
+  }
+  return kTRUE;
+}
+
+//________________________________________________________
+Bool_t AliTRDresolution::MakeProjectionTrackIn()
+{
+// Analyse track in
+
+  const Int_t kNcontours(9);
+  const Int_t kNstat(30);
+
+  Int_t cidx = kTrackIn;
+  if(fProj && fProj->At(cidx)) return kTRUE;
+  if(!fContainer){
+    AliError("Missing data container.");
+    return kFALSE;
+  }
+  THnSparse *H(NULL);
+  if(!(H = (THnSparse*)fContainer->At(cidx))){
+    AliError(Form("Missing/Wrong data @ %d.", Int_t(cidx)));
+    return kFALSE;
+  }
+
+  Int_t coord[kNdim]; memset(coord, 0, sizeof(Int_t) * kNdim); Double_t v = 0.;
+  Int_t ndim(H->GetNdimensions());
+  TAxis *aa[kNdim+1], *as(NULL); memset(aa, 0, sizeof(TAxis*) * (kNdim+1));
+  for(Int_t id(0); id<ndim; id++) aa[id] = H->GetAxis(id);
+  if(ndim > kSpeciesChgRC) as = H->GetAxis(kSpeciesChgRC);
+  // build list of projections
+  const Int_t nsel(3), npsel(4);
+  // define rebinning strategy
+  const Int_t nEtaPhi(4); Int_t rebinEtaPhiX[nEtaPhi] = {1, 2, 5, 1}, rebinEtaPhiY[nEtaPhi] = {2, 1, 1, 5};
+  const Int_t nPtPhi(2); Int_t rebinPtPhiX[nEtaPhi] = {1, 1}, rebinPtPhiY[nEtaPhi] = {2, 5};
+  AliTRDresolutionProjection hp[fgkNproj[cidx]], *php[nsel][npsel]; memset(php, 0, nsel*npsel*sizeof(AliTRDresolutionProjection*));
+  Int_t ih(0), isel(-1), np[nsel]; memset(np, 0, nsel*sizeof(Int_t));
+  // define list of projections
+  isel++;  // negative tracks
+  hp[ih].Build("HTrkInY", "TrackIn :: r-#phi residuals", kEta, kPhi, kYrez, aa);
+  hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+    php[isel][np[isel]++] = &hp[ih++];
+  hp[ih].Build("HTrkInYn", "TrackIn[-]:: r-#phi residuals", kEta, kPhi, kYrez, aa);
+  hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+    php[isel][np[isel]++] = &hp[ih++];
+  hp[ih].Build("HTrkInPhn", "TrackIn[-]:: #Delta#phi residuals", kEta, kPhi, kPrez, aa);
+  hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+    php[isel][np[isel]++] = &hp[ih++];
+  hp[ih].Build("HTrkInYPn", "TrackIn[-]:: r-#phi/p_{t} residuals", kPt, kPhi, kYrez, aa);
+  hp[ih].SetRebinStrategy(nPtPhi, rebinPtPhiX, rebinPtPhiY);
+    php[isel][np[isel]++] = &hp[ih++];
+  isel++; // positive tracks
+  php[isel][np[isel]++] = &hp[ih-4]; // relink first histo
+  hp[ih].Build("HTrkInYp", "TrackIn[+]:: r-#phi residuals", kEta, kPhi, kYrez, aa);
+  hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+    php[isel][np[isel]++] = &hp[ih++];
+  hp[ih].Build("HTrkInPhp", "TrackIn[+]:: #Delta#phi residuals", kEta, kPhi, kPrez, aa);
+  hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+    php[isel][np[isel]++] = &hp[ih++];
+  hp[ih].Build("HTrkInYPp", "TrackIn[+]:: r-#phi/p_{t} residuals", kPt, kPhi, kYrez, aa);
+  hp[ih].SetRebinStrategy(nPtPhi, rebinPtPhiX, rebinPtPhiY);
+    php[isel][np[isel]++] = &hp[ih++];
+  isel++; // RC tracks
+  hp[ih].Build("HTrkInZ", "TrackIn[RC]:: z residuals", kEta, kPhi, kZrez, aa);
+  hp[ih].SetRebinStrategy(nEtaPhi, rebinEtaPhiX, rebinEtaPhiY);
+    php[isel][np[isel]++] = &hp[ih++];
+
+  // fill projections
+  Int_t ch(0), rcBin(as?as->FindBin(0.):-1);
+  for (Long64_t ib(0); ib < H->GetNbins(); ib++) {
+    v = H->GetBinContent(ib, coord);
+    if(v<1.) continue;
+    if(coord[kBC]>1) continue; // bunch cross cut
+    // charge selection
+    ch = 0; // [-] track
+    if(rcBin>0){ // debug mode in which species are also saved
+      if(coord[kSpeciesChgRC] > rcBin) ch = 1;  // [+] track
+      else if(coord[kSpeciesChgRC] == rcBin) ch = 2;  // [RC] track
+    }
+    for(Int_t jh(0); jh<np[ch]; jh++) php[ch][jh]->Increment(coord, v);
+  }
+  if(!fProj){
+    AliInfo("Building array of projections ...");
+    fProj = new TObjArray(kNclasses); fProj->SetOwner(kTRUE);
+  }
+  TObjArray *arr(NULL);
+  fProj->AddAt(arr = new TObjArray(fgkNproj[cidx]), cidx);
+
+  TH2 *h2(NULL);
+  for(; ih--; ){
+    if(!(h2 = hp[ih].Projection2D(kNstat, kNcontours/*, mid*/))) continue;
+    arr->AddAt(h2, ih);
+  }
+  return kTRUE;
+}
+
+
+
+//________________________________________________________
+Bool_t AliTRDresolution::PostProcess()
+{
+// Fit, Project, Combine, Extract values from the containers filled during execution
+
+  if (!fContainer) {
+    AliError("ERROR: list not available");
+    return kFALSE;
+  }
 
   // DEFINE MODELS
   // simple gauss
@@ -1265,26 +1370,18 @@ Bool_t AliTRDresolution::PostProcess()
   TF1 fpt("fPt", "landau", -0.1, 0.2);  
 
   //PROCESS EXPERIMENTAL DISTRIBUTIONS
-  // Charge resolution
-  //Process3DL(kCharge, 0, &fl); 
   // Clusters residuals
-  Process2D(kCluster, 0, &fg, 1.e4); 
-  Process2D(kCluster, 1, &fg); 
-  fNRefFigures = 1;
+  if(!MakeProjectionCluster()) return kFALSE;
+  fNRefFigures = 3;
   // Tracklet residual/pulls
-  Process2D(kTrackTRD , 0, &fg, 1.e4); 
-  Process2D(kTrackTRD , 1, &fg); 
-  Process2D(kTrackTRD , 2, &fg, 1.e4); 
-  Process2D(kTrackTRD , 3, &fg); 
-  Process2D(kTrackTRD , 4, &fg, 1.e3); 
-  fNRefFigures = 4;
-  // TPC track residual/pulls
-  Process2D(kTrackTPC, 0, &fg, 1.e4); 
-  Process2D(kTrackTPC, 1, &fg); 
-  Process2D(kTrackTPC, 2, &fg, 1.e4); 
-  Process2D(kTrackTPC, 3, &fg); 
-  Process2D(kTrackTPC, 4, &fg, 1.e3); 
+  if(!MakeProjectionTracklet()) return kFALSE;
   fNRefFigures = 7;
+  // TRDin residual/pulls
+  if(!MakeProjectionTrackIn()) return kFALSE;
+  fNRefFigures = 11;
+  // TRDout residual/pulls
+//  if(!MakeProjectionTrackOut()) return kFALSE;
+  fNRefFigures = 15;
 
   if(!HasMCdata()) return kTRUE;
 
@@ -1292,66 +1389,35 @@ Bool_t AliTRDresolution::PostProcess()
   //PROCESS MC RESIDUAL DISTRIBUTIONS
 
   // CLUSTER Y RESOLUTION/PULLS
-  Process3Drange(kMCcluster, 0, 0, &fg, 1.e4, 1, 1);
-  Process3Drange(kMCcluster, 0, 1, &fg, 1.e4, 2, 2);
-  Process3Drange(kMCcluster, 0, 2, &fg, 1.e4, 3, 12);
-  Process2D(kMCcluster, 1, &fg, 1., 3);
-  fNRefFigures = 10;
+//  if(!MakeProjectionClusterMC()) return kFALSE;
+  fNRefFigures = 17;
 
   // TRACKLET RESOLUTION/PULLS
-  Process3Drange(kMCtracklet, 0, 0, &fg, 1.e4, 1, 1); // y
-  Process3Drange(kMCtracklet, 0, 1, &fg, 1.e4, 2, 2); // y
-  Process3Drange(kMCtracklet, 0, 2, &fg, 1.e4, 3, 12); // y
-  Process2D(kMCtracklet, 1, &fg, 1., 3);       // y pulls
-  Process2D(kMCtracklet, 2, &fg, 1.e4, 4); // z
-  Process2D(kMCtracklet, 3, &fg, 1., 5);       // z pulls
-  Process2D(kMCtracklet, 4, &fg, 1.e3, 6); // phi
-  fNRefFigures = 14;
+//  if(!MakeProjectionTrackletMC()) return kFALSE;
+  fNRefFigures = 21;
 
   // TRACK RESOLUTION/PULLS
-  Process2D(kMCtrackTRD, 0, &fg, 1.e4);   // y
-  Process2D(kMCtrackTRD, 1, &fg);         // y PULL
-  Process2D(kMCtrackTRD, 2, &fg, 1.e4);   // z
-  Process2D(kMCtrackTRD, 3, &fg);         // z PULL
-  Process2D(kMCtrackTRD, 4, &fg, 1.e3);   // phi
-  Process2D(kMCtrackTRD, 5, &fg);         // snp PULL
-  Process2D(kMCtrackTRD, 6, &fg, 1.e3);   // theta
-  Process2D(kMCtrackTRD, 7, &fg);         // tgl PULL
-  Process4D(kMCtrackTRD, 8, &fg, 1.e2);   // pt resolution
-  Process4D(kMCtrackTRD, 8, &fpt, 1.e2, 4);// pt resolution e1- @ L0
-  Process4D(kMCtrackTRD, 8, &fpt, 1.e2, 6);// pt resolution e1+ @ L0
-  Process4D(kMCtrackTRD, 8, &fpt, 1.e2, 55+4);// pt resolution e1- @ L5
-  Process4D(kMCtrackTRD, 8, &fpt, 1.e2, 55+6);// pt resolution e1+ @ L5
-  Process4D(kMCtrackTRD, 9, &fg);         // 1/pt pulls
-  Process4D(kMCtrackTRD, 10, &fg, 1.e2);  // p resolution
-  Process4D(kMCtrackTRD, 10, &fpt, 1.e2, 4);// p resolution e1- @ L0
-  Process4D(kMCtrackTRD, 10, &fpt, 1.e2, 6);// p resolution e1+ @ L0
-  Process4D(kMCtrackTRD, 10, &fpt, 1.e2, 55+4);// p resolution e1- @ L5
-  Process4D(kMCtrackTRD, 10, &fpt, 1.e2, 55+6);// p resolution e1+ @ L5
-  Process4D(kMCtrackTRD, 11, &fg, 1.e2);   // pt resolution stand alone
-  Process4D(kMCtrackTRD, 12, &fg);         // 1/pt pulls  stand alone
-  Process4D(kMCtrackTRD, 13, &fg, 1.e2);  // p resolution  stand alone
-  fNRefFigures = 24;
-
-  // TRACK TPC RESOLUTION/PULLS
-  Process2D(kMCtrackTPC, 0, &fg, 1.e4);// y resolution
-  Process2D(kMCtrackTPC, 1, &fg);      // y pulls
-  Process2D(kMCtrackTPC, 2, &fg, 1.e4);// z resolution
-  Process2D(kMCtrackTPC, 3, &fg);      // z pulls
-  Process2D(kMCtrackTPC, 4, &fg, 1.e3);// phi resolution
-  Process2D(kMCtrackTPC, 5, &fg);      // snp pulls
-  Process2D(kMCtrackTPC, 6, &fg, 1.e3);// theta resolution
-  Process2D(kMCtrackTPC, 7, &fg);      // tgl pulls
-  Process3D(kMCtrackTPC, 8, &fg, 1.e2);// pt resolution
-  Process3D(kMCtrackTPC, 9, &fg);      // 1/pt pulls
-  Process3D(kMCtrackTPC, 10, &fg, 1.e2);// p resolution
-  Process3D(kMCtrackTPC, 11, &fg);      // p pulls
-  fNRefFigures = 30;
-
-  // TRACK HMPID RESOLUTION/PULLS
-  Process2D(kMCtrackTOF, 0, &fg, 1.e4); // z towards TOF
-  Process2D(kMCtrackTOF, 1, &fg);       // z towards TOF
-  fNRefFigures = 31;
+/*  Process3Darray(kMCtrack, 0, &fg, 1.e4);   // y
+  Process3DlinkedArray(kMCtrack, 1, &fg);   // y PULL
+  Process3Darray(kMCtrack, 2, &fg, 1.e4);   // z
+  Process3Darray(kMCtrack, 3, &fg);         // z PULL
+  Process2Darray(kMCtrack, 4, &fg, 1.e3);   // phi
+  Process2Darray(kMCtrack, 5, &fg);         // snp PULL
+  Process2Darray(kMCtrack, 6, &fg, 1.e3);   // theta
+  Process2Darray(kMCtrack, 7, &fg);         // tgl PULL
+  Process3Darray(kMCtrack, 8, &fg, 1.e2);   // pt resolution
+  Process3Darray(kMCtrack, 9, &fg);         // 1/pt pulls
+  Process3Darray(kMCtrack, 10, &fg, 1.e2);  // p resolution*/
+//  if(!MakeProjectionTrackMC(kMCtrack)) return kFALSE;
+  fNRefFigures+=16;
+
+  // TRACK TRDin RESOLUTION/PULLS
+//  if(!MakeProjectionTrackMC(kMCtrackIn)) return kFALSE;
+  fNRefFigures+=8;
+
+  // TRACK TRDout RESOLUTION/PULLS
+//  if(!MakeProjectionTrackMC(kMCtrackOut)) return kFALSE;
+  fNRefFigures+=8;
 
   return kTRUE;
 }
@@ -1395,863 +1461,506 @@ void AliTRDresolution::AdjustF1(TH1 *h, TF1 *f)
 }
 
 //________________________________________________________
-TObjArray* AliTRDresolution::Histos()
+TObjArray* AliTRDresolution::BuildMonitorContainerCluster(const char* name, Bool_t expand, Float_t range)
 {
-  //
-  // Define histograms
-  //
-
-  if(fContainer) return fContainer;
-
-  fContainer  = new TObjArray(kNviews);
-  //fContainer->SetOwner(kTRUE);
-  TH1 *h(NULL);
-  TObjArray *arr(NULL);
-
-  // binnings for plots containing momentum or pt
-  const Int_t kNpt(14), kNphi(48), kNdy(60);
-  Float_t Phi=-.48, Dy=-.3, Pt=0.1;
-  Float_t binsPhi[kNphi+1], binsDy[kNdy+1], binsPt[kNpt+1];
-  for(Int_t i=0; i<kNphi+1; i++,Phi+=.02) binsPhi[i]=Phi;
-  for(Int_t i=0; i<kNdy+1; i++,Dy+=.01) binsDy[i]=Dy;
-  for(Int_t i=0;i<kNpt+1; i++,Pt=TMath::Exp(i*.15)-1.) binsPt[i]=Pt;
-
-  // cluster to track residuals/pulls
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kCharge]), kCharge);
-  arr->SetName("Charge");
-  if(!(h = (TH3S*)gROOT->FindObject("hCharge"))){
-    h = new TH3S("hCharge", "Charge Resolution", 20, 1., 2., 24, 0., 3.6, 100, 0., 500.);
-    h->GetXaxis()->SetTitle("dx/dx_{0}");
-    h->GetYaxis()->SetTitle("x_{d} [cm]");
-    h->GetZaxis()->SetTitle("dq/dx [ADC/cm]");
-  } else h->Reset();
-  arr->AddAt(h, 0);
-
-  // cluster to track residuals/pulls
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kCluster]), kCluster);
-  arr->SetName("Cl");
-  if(!(h = (TH2I*)gROOT->FindObject("hCl"))){
-    h = new TH2I("hCl", "Cluster Residuals", 21, -.33, .33, 100, -.5, .5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 0);
-  if(!(h = (TH2I*)gROOT->FindObject("hClpull"))){
-    h = new TH2I("hClpull", "Cluster Pulls", 21, -.33, .33, 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y/#sigma_{y}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 1);
-
-  // tracklet to track residuals/pulls in y direction
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kTrackTRD ]), kTrackTRD );
-  arr->SetName("Trklt");
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkltY"))){
-    h = new TH2I("hTrkltY", "Tracklet Y Residuals", 21, -.33, .33, 100, -.5, .5);
-    h->GetXaxis()->SetTitle("#tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y [cm]");
-    h->GetZaxis()->SetTitle("entries");
+// Build performance histograms for AliTRDcluster.vs TRD track or MC
+//  - y reziduals/pulls
+
+  TObjArray *arr = new TObjArray(2);
+  arr->SetName(name); arr->SetOwner();
+  TH1 *h(NULL); char hname[100], htitle[300];
+
+  // tracklet resolution/pull in y direction
+  snprintf(hname, 100, "%s_%s_Y", GetNameId(), name);
+  snprintf(htitle, 300, "Y res for \"%s\" @ %s;tg(#phi);#Delta y [cm];%s", GetNameId(), name, "Detector");
+  Float_t rr = range<0.?fDyRange:range;
+  if(!(h = (TH3S*)gROOT->FindObject(hname))){
+    Int_t nybins=50;
+    if(expand) nybins*=2;
+    h = new TH3S(hname, htitle, 
+                 48, -.48, .48,            // phi
+                 60, -rr, rr,              // dy
+                 nybins, -0.5, nybins-0.5);// segment
   } else h->Reset();
   arr->AddAt(h, 0);
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkltYpull"))){
-    h = new TH2I("hTrkltYpull", "Tracklet Y Pulls", 21, -.33, .33, 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("#tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y/#sigma_{y}");
-    h->GetZaxis()->SetTitle("entries");
+  snprintf(hname, 100, "%s_%s_YZpull", GetNameId(), name);
+  snprintf(htitle, 300, "YZ pull for \"%s\" @ %s;%s;#Delta y  / #sigma_{y};#Delta z  / #sigma_{z}", GetNameId(), name, "Detector");
+  if(!(h = (TH3S*)gROOT->FindObject(hname))){
+    h = new TH3S(hname, htitle, 540, -0.5, 540-0.5, 100, -4.5, 4.5, 100, -4.5, 4.5);
   } else h->Reset();
   arr->AddAt(h, 1);
-  // tracklet to track residuals/pulls in z direction
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkltZ"))){
-    h = new TH2I("hTrkltZ", "Tracklet Z Residuals", 50, -1., 1., 100, -1.5, 1.5);
-    h->GetXaxis()->SetTitle("#tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 2);
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkltZpull"))){
-    h = new TH2I("hTrkltZpull", "Tracklet Z Pulls", 50, -1., 1., 100, -5.5, 5.5);
-    h->GetXaxis()->SetTitle("#tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z/#sigma_{z}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 3);
-  // tracklet to track phi residuals
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkltPhi"))){
-    h = new TH2I("hTrkltPhi", "Tracklet #phi Residuals", 21, -.33, .33, 100, -.5, .5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta phi [rad]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 4);
 
+  return arr;
+}
 
-  // tracklet to TPC track residuals/pulls in y direction
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kTrackTPC]), kTrackTPC);
-  arr->SetName("TrkTPC");
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkTPCY"))){
-    h = new TH2I("hTrkTPCY", "Track[TPC] Y Residuals", 21, -.33, .33, 100, -.5, .5);
-    h->GetXaxis()->SetTitle("#tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 0);
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkTPCYpull"))){
-    h = new TH2I("hTrkTPCYpull", "Track[TPC] Y Pulls", 21, -.33, .33, 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("#tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y/#sigma_{y}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 1);
-  // tracklet to TPC track residuals/pulls in z direction
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkTPCZ"))){
-    h = new TH2I("hTrkTPCZ", "Track[TPC] Z Residuals", 50, -1., 1., 100, -1.5, 1.5);
-    h->GetXaxis()->SetTitle("#tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z [cm]");
-    h->GetZaxis()->SetTitle("entries");
+//________________________________________________________
+TObjArray* AliTRDresolution::BuildMonitorContainerTracklet(const char* name, Bool_t expand)
+{
+// Build performance histograms for AliExternalTrackParam.vs TRD tracklet
+//  - y reziduals/pulls
+//  - z reziduals/pulls
+//  - phi reziduals
+  TObjArray *arr = BuildMonitorContainerCluster(name, expand, 0.05); 
+  arr->Expand(5);
+  TH1 *h(NULL); char hname[100], htitle[300];
+
+  // tracklet resolution/pull in z direction
+  snprintf(hname, 100, "%s_%s_Z", GetNameId(), name);
+  snprintf(htitle, 300, "Z res for \"%s\" @ %s;tg(#theta);#Delta z [cm]", GetNameId(), name);
+  if(!(h = (TH2S*)gROOT->FindObject(hname))){
+    h = new TH2S(hname, htitle, 50, -1., 1., 100, -.05, .05);
   } else h->Reset();
   arr->AddAt(h, 2);
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkTPCZpull"))){
-    h = new TH2I("hTrkTPCZpull", "Track[TPC] Z Pulls", 50, -1., 1., 100, -5.5, 5.5);
-    h->GetXaxis()->SetTitle("#tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z/#sigma_{z}");
-    h->GetZaxis()->SetTitle("entries");
+  snprintf(hname, 100, "%s_%s_Zpull", GetNameId(), name);
+  snprintf(htitle, 300, "Z pull for \"%s\" @ %s;tg(#theta);#Delta z  / #sigma_{z};row cross", GetNameId(), name);
+  if(!(h = (TH3S*)gROOT->FindObject(hname))){
+    h = new TH3S(hname, htitle, 50, -1., 1., 100, -5.5, 5.5, 2, -0.5, 1.5);
+    h->GetZaxis()->SetBinLabel(1, "no RC");
+    h->GetZaxis()->SetBinLabel(2, "RC");
   } else h->Reset();
   arr->AddAt(h, 3);
-  // tracklet to TPC track phi residuals
-  if(!(h = (TH2I*)gROOT->FindObject("hTrkTPCPhi"))){
-    h = new TH2I("hTrkTPCPhi", "Track[TPC] #phi Residuals", 21, -.33, .33, 100, -.5, .5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta phi [rad]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 4);
-
-
-  // Resolution histos
-  if(!HasMCdata()) return fContainer;
-
-  // cluster y resolution [0]
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kMCcluster]), kMCcluster);
-  arr->SetName("McCl");
-  if(!(h = (TH3S*)gROOT->FindObject("hMcCl"))){
-    h = new TH3S("hMcCl", 
-    "Cluster Resolution;tg(#phi);#Delta y [cm];p_{t} [GeV/c]", 
-    kNphi, binsPhi, kNdy, binsDy, kNpt, binsPt);
-  } else h->Reset();
-  arr->AddAt(h, 0);
-  if(!(h = (TH2I*)gROOT->FindObject("hMcClPull"))){
-    h = new TH2I("hMcClPull", "Cluster Pulls", 48, -.48, .48, 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Deltay/#sigma_{y}");
-    h->GetZaxis()->SetTitle("p_{t} [GeV/c]");
-  } else h->Reset();
-  arr->AddAt(h, 1);
 
-
-  // TRACKLET RESOLUTION
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kMCtracklet]), kMCtracklet);
-  arr->SetName("McTrklt");
-  // tracklet y resolution
-  if(!(h = (TH3S*)gROOT->FindObject("hMcTrkltY"))){
-    h = new TH3S("hMcTrkltY", 
-    "Tracklet Y Resolution;tg(#phi);#Delta y [cm];p_{t} [GeV/c]", 
-    kNphi, binsPhi, kNdy, binsDy, kNpt, binsPt);
-  } else h->Reset();
-  arr->AddAt(h, 0);
-  // tracklet y pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkltYPull"))){
-    h = new TH2I("hMcTrkltYPull", "Tracklet Pulls (Y)", 48, -.48, .48, 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y / #sigma_{y}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 1);
-  // tracklet z resolution
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkltZ"))){
-    h = new TH2I("hMcTrkltZ", "Tracklet Resolution (Z)", 100, -1., 1., 100, -1., 1.);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 2);
-  // tracklet z pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkltZPull"))){
-    h = new TH2I("hMcTrkltZPull", "Tracklet Pulls (Z)", 100, -1., 1., 100, -3.5, 3.5);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z / #sigma_{z}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 3);
-  // tracklet phi resolution
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkltPhi"))){
-    h = new TH2I("hMcTrkltPhi", "Tracklet Resolution (#Phi)", 48, -.48, .48, 100, -.15, .15);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta #phi [rad]");
-    h->GetZaxis()->SetTitle("entries");
+  // tracklet to track phi resolution
+  snprintf(hname, 100, "%s_%s_PHI", GetNameId(), name);
+  snprintf(htitle, 300, "#Phi res for \"%s\" @ %s;tg(#phi);#Delta #phi [rad];%s", GetNameId(), name, "Detector");
+  Int_t nsgms=540;
+  if(!(h = (TH3S*)gROOT->FindObject(hname))){
+    h = new TH3S(hname, htitle, 48, -.48, .48, 100, -.5, .5, nsgms, -0.5, nsgms-0.5);
   } else h->Reset();
   arr->AddAt(h, 4);
 
+  return arr;
+}
 
-  // KALMAN TRACK RESOLUTION
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kMCtrackTRD]), kMCtrackTRD);
-  arr->SetName("McTrkTRD");
-  // Kalman track y resolution
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkY"))){
-    h = new TH2I("hMcTrkY", "Track Y Resolution", 48, -.48, .48, 100, -.2, .2);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 0);
-  // Kalman track y pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkYPull"))){
-    h = new TH2I("hMcTrkYPull", "Track Y Pulls", 48, -.48, .48, 100, -4., 4.);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y / #sigma_{y}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 1);
-  // Kalman track Z
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkZ"))){
-    h = new TH2I("hMcTrkZ", "Track Z Resolution", 100, -1., 1., 100, -1., 1.);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 2);
-  // Kalman track Z pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkZPull"))){
-    h = new TH2I("hMcTrkZPull", "Track Z Pulls", 100, -1., 1., 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z / #sigma_{z}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 3);
-  // Kalman track SNP
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkSNP"))){
-    h = new TH2I("hMcTrkSNP", "Track Phi Resolution", 60, -.3, .3, 100, -5e-3, 5e-3);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta #phi [rad]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 4);
-  // Kalman track SNP pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkSNPPull"))){
-    h = new TH2I("hMcTrkSNPPull", "Track SNP Pulls", 60, -.3, .3, 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta(sin(#phi)) / #sigma_{sin(#phi)}");
-    h->GetZaxis()->SetTitle("entries");
+//________________________________________________________
+TObjArray* AliTRDresolution::BuildMonitorContainerTrack(const char* name)
+{
+// Build performance histograms for AliExternalTrackParam.vs MC
+//  - y resolution/pulls
+//  - z resolution/pulls
+//  - phi resolution, snp pulls
+//  - theta resolution, tgl pulls
+//  - pt resolution, 1/pt pulls, p resolution
+
+  TObjArray *arr = BuildMonitorContainerTracklet(name); 
+  arr->Expand(11);
+  TH1 *h(NULL); char hname[100], htitle[300];
+  //TAxis *ax(NULL);
+
+  // snp pulls
+  snprintf(hname, 100, "%s_%s_SNPpull", GetNameId(), name);
+  snprintf(htitle, 300, "SNP pull for \"%s\" @ %s;tg(#phi);#Delta snp  / #sigma_{snp};entries", GetNameId(), name);
+  if(!(h = (TH2I*)gROOT->FindObject(hname))){
+    h = new TH2I(hname, htitle, 60, -.3, .3, 100, -4.5, 4.5);
   } else h->Reset();
   arr->AddAt(h, 5);
-  // Kalman track TGL
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTGL"))){
-    h = new TH2I("hMcTrkTGL", "Track Theta Resolution", 100, -1., 1., 100, -5e-3, 5e-3);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta#theta [rad]");
-    h->GetZaxis()->SetTitle("entries");
+
+  // theta resolution
+  snprintf(hname, 100, "%s_%s_THT", GetNameId(), name);
+  snprintf(htitle, 300, "#Theta res for \"%s\" @ %s;tg(#theta);#Delta #theta [rad];entries", GetNameId(), name);
+  if(!(h = (TH2I*)gROOT->FindObject(hname))){
+    h = new TH2I(hname, htitle, 100, -1., 1., 100, -5e-3, 5e-3);
   } else h->Reset();
   arr->AddAt(h, 6);
-  // Kalman track TGL pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTGLPull"))){
-    h = new TH2I("hMcTrkTGLPull", "Track TGL  Pulls", 100, -1., 1., 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta(tg(#theta)) / #sigma_{tg(#theta)}");
-    h->GetZaxis()->SetTitle("entries");
+  // tgl pulls
+  snprintf(hname, 100, "%s_%s_TGLpull", GetNameId(), name);
+  snprintf(htitle, 300, "TGL pull for \"%s\" @ %s;tg(#theta);#Delta tgl  / #sigma_{tgl};entries", GetNameId(), name);
+  if(!(h = (TH2I*)gROOT->FindObject(hname))){
+    h = new TH2I(hname, htitle, 100, -1., 1., 100, -4.5, 4.5);
   } else h->Reset();
   arr->AddAt(h, 7);
-
+  
   const Int_t kNdpt(150); 
   const Int_t kNspc = 2*AliPID::kSPECIES+1;
-  Float_t DPt=-.1, Spc=-5.5;
-  Float_t binsSpc[kNspc+1], binsDPt[kNdpt+1];
-  for(Int_t i=0; i<kNspc+1; i++,Spc+=1.) binsSpc[i]=Spc;
-  for(Int_t i=0; i<kNdpt+1; i++,DPt+=2.e-3) binsDPt[i]=DPt;
-  TObjArray *arr2 = NULL; TH3S* h3=NULL;
-  // Kalman track Pt resolution
-  arr->AddAt(arr2 = new TObjArray(AliTRDgeometry::kNlayer), 8);
-  arr2->SetName("Pt Resolution");
-  for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
-    if(!(h3 = (TH3S*)gROOT->FindObject(Form("hMcTrkPt%d", il)))){
-      h3 = new TH3S(Form("hMcTrkPt%d", il), "Track Pt Resolution;p_{t} [GeV/c];#Delta p_{t}/p_{t}^{MC};SPECIES", kNpt, binsPt, kNdpt, binsDPt, kNspc, binsSpc);
-    } else h3->Reset();
-    arr2->AddAt(h3, il);
-  }
-  // Kalman track Pt pulls
-  arr->AddAt(arr2 = new TObjArray(AliTRDgeometry::kNlayer), 9);
-  arr2->SetName("1/Pt Pulls");
-  for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
-    if(!(h3 = (TH3S*)gROOT->FindObject(Form("hMcTrkPtPulls%d", il)))){
-      h3 = new TH3S(Form("hMcTrkPtPulls%d", il), 
-      "Track 1/Pt Pulls;1/p_{t}^{MC} [c/GeV];#Delta(1/p_{t})/#sigma(1/p_{t});SPECIES", 
-      kNpt, 0., 2., 100, -4., 4., kNspc, -5.5, 5.5);
-    } else h3->Reset();
-    arr2->AddAt(h3, il);
-  }
-  // Kalman track P resolution
-  arr->AddAt(arr2 = new TObjArray(AliTRDgeometry::kNlayer), 10);
-  arr2->SetName("P Resolution");
-  for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
-    if(!(h3 = (TH3S*)gROOT->FindObject(Form("hMcTrkP%d", il)))){
-      h3 = new TH3S(Form("hMcTrkP%d", il), "Track P Resolution;p [GeV/c];#Delta p/p^{MC};SPECIES", kNpt, binsPt, kNdpt, binsDPt, kNspc, binsSpc);
-    } else h3->Reset();
-    arr2->AddAt(h3, il);
-  }
-  // TRD stand-alone track Pt resolution
-  arr->AddAt(arr2 = new TObjArray(AliTRDgeometry::kNlayer), 11);
-  arr2->SetName("Pt Resolution [SA]");
-  for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
-    if(!(h3 = (TH3S*)gROOT->FindObject(Form("hMcSATrkPt%d", il)))){
-      h3 = new TH3S(Form("hMcSATrkPt%d", il), 
-      "Track Pt Resolution;p_{t} [GeV/c];#Delta p_{t}/p_{t}^{MC};SPECIES", 
-      kNpt, binsPt, kNdpt, binsDPt, kNspc, binsSpc);
-    } else h3->Reset();
-    arr2->AddAt(h3, il);
-  }
-  // TRD stand-alone track Pt pulls
-  arr->AddAt(arr2 = new TObjArray(AliTRDgeometry::kNlayer), 12);
-  arr2->SetName("1/Pt Pulls [SA]");
-  for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
-    if(!(h3 = (TH3S*)gROOT->FindObject(Form("hMcSATrkPtPulls%d", il)))){
-      h3 = new TH3S(Form("hMcSATrkPtPulls%d", il), 
-      "Track 1/Pt Pulls;1/p_{t}^{MC} [c/GeV];#Delta(1/p_{t})/#sigma(1/p_{t});SPECIES", 
-      kNpt, 0., 2., 100, -4., 4., kNspc, -5.5, 5.5);
-    } else h3->Reset();
-    arr2->AddAt(h3, il);
-  }
-  // TRD stand-alone track P resolution
-  arr->AddAt(arr2 = new TObjArray(AliTRDgeometry::kNlayer), 13);
-  arr2->SetName("P Resolution [SA]");
-  for(Int_t il=0; il<AliTRDgeometry::kNlayer; il++){
-    if(!(h3 = (TH3S*)gROOT->FindObject(Form("hMcSATrkP%d", il)))){
-      h3 = new TH3S(Form("hMcSATrkP%d", il), 
-      "Track P Resolution;p [GeV/c];#Delta p/p^{MC};SPECIES", 
-      kNpt, binsPt, kNdpt, binsDPt, kNspc, binsSpc);
-    } else h3->Reset();
-    arr2->AddAt(h3, il);
-  }
-
-  // TPC TRACK RESOLUTION
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kMCtrackTPC]), kMCtrackTPC);
-  arr->SetName("McTrkTPC");
-  // Kalman track Y
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTPCY"))){
-    h = new TH2I("hMcTrkTPCY", "Track[TPC] Y Resolution", 60, -.3, .3, 100, -.5, .5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 0);
-  // Kalman track Y pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTPCYPull"))){
-    h = new TH2I("hMcTrkTPCYPull", "Track[TPC] Y Pulls", 60, -.3, .3, 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta y / #sigma_{y}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 1);
-  // Kalman track Z
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTPCZ"))){
-    h = new TH2I("hMcTrkTPCZ", "Track[TPC] Z Resolution", 100, -1., 1., 100, -1., 1.);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 2);
-  // Kalman track Z pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTPCZPull"))){
-    h = new TH2I("hMcTrkTPCZPull", "Track[TPC] Z Pulls", 100, -1., 1., 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z / #sigma_{z}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 3);
-  // Kalman track SNP
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTPCSNP"))){
-    h = new TH2I("hMcTrkTPCSNP", "Track[TPC] Phi Resolution", 60, -.3, .3, 100, -5e-3, 5e-3);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta #phi [rad]");
-    h->GetZaxis()->SetTitle("entries");
+  Float_t lPt=0.1, lDPt=-.1, lSpc=-5.5;
+  Float_t binsPt[kNpt+1], binsSpc[kNspc+1], binsDPt[kNdpt+1];
+  for(Int_t i=0;i<kNpt+1; i++,lPt=TMath::Exp(i*.15)-1.) binsPt[i]=lPt;
+  for(Int_t i=0; i<kNspc+1; i++,lSpc+=1.) binsSpc[i]=lSpc;
+  for(Int_t i=0; i<kNdpt+1; i++,lDPt+=2.e-3) binsDPt[i]=lDPt;
+
+  // Pt resolution
+  snprintf(hname, 100, "%s_%s_Pt", GetNameId(), name);
+  snprintf(htitle, 300, "#splitline{P_{t} res for}{\"%s\" @ %s};p_{t} [GeV/c];#Delta p_{t}/p_{t}^{MC};SPECIES", GetNameId(), name);
+  if(!(h = (TH3S*)gROOT->FindObject(hname))){
+    h = new TH3S(hname, htitle, 
+                 kNpt, binsPt, kNdpt, binsDPt, kNspc, binsSpc);
+    //ax = h->GetZaxis();
+    //for(Int_t ib(1); ib<=ax->GetNbins(); ib++) ax->SetBinLabel(ib, fgParticle[ib-1]);
   } else h->Reset();
-  arr->AddAt(h, 4);
-  // Kalman track SNP pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTPCSNPPull"))){
-    h = new TH2I("hMcTrkTPCSNPPull", "Track[TPC] SNP Pulls", 60, -.3, .3, 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#phi)");
-    h->GetYaxis()->SetTitle("#Delta(sin(#phi)) / #sigma_{sin(#phi)}");
-    h->GetZaxis()->SetTitle("entries");
+  arr->AddAt(h, 8);
+  // 1/Pt pulls
+  snprintf(hname, 100, "%s_%s_1Pt", GetNameId(), name);
+  snprintf(htitle, 300, "#splitline{1/P_{t} pull for}{\"%s\" @ %s};1/p_{t}^{MC} [c/GeV];#Delta(1/p_{t})/#sigma(1/p_{t});SPECIES", GetNameId(), name);
+  if(!(h = (TH3S*)gROOT->FindObject(hname))){
+    h = new TH3S(hname, htitle, 
+                 kNpt, 0., 2., 100, -4., 4., kNspc, -5.5, 5.5);
+    //ax = h->GetZaxis();
+    //for(Int_t ib(1); ib<=ax->GetNbins(); ib++) ax->SetBinLabel(ib, fgParticle[ib-1]);
   } else h->Reset();
-  arr->AddAt(h, 5);
-  // Kalman track TGL
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTPCTGL"))){
-    h = new TH2I("hMcTrkTPCTGL", "Track[TPC] Theta Resolution", 100, -1., 1., 100, -5e-3, 5e-3);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta#theta [rad]");
-    h->GetZaxis()->SetTitle("entries");
+  arr->AddAt(h, 9);
+  // P resolution
+  snprintf(hname, 100, "%s_%s_P", GetNameId(), name);
+  snprintf(htitle, 300, "P res for \"%s\" @ %s;p [GeV/c];#Delta p/p^{MC};SPECIES", GetNameId(), name);
+  if(!(h = (TH3S*)gROOT->FindObject(hname))){
+    h = new TH3S(hname, htitle, 
+                 kNpt, binsPt, kNdpt, binsDPt, kNspc, binsSpc);
+    //ax = h->GetZaxis();
+    //for(Int_t ib(1); ib<=ax->GetNbins(); ib++) ax->SetBinLabel(ib, fgParticle[ib-1]);
   } else h->Reset();
-  arr->AddAt(h, 6);
-  // Kalman track TGL pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTPCTGLPull"))){
-    h = new TH2I("hMcTrkTPCTGLPull", "Track[TPC] TGL  Pulls", 100, -1., 1., 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta(tg(#theta)) / #sigma_{tg(#theta)}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 7);
-  // Kalman track Pt resolution
-  if(!(h3 = (TH3S*)gROOT->FindObject("hMcTrkTPCPt"))){
-    h3 = new TH3S("hMcTrkTPCPt", 
-    "TRDin Pt Resolution;p_{t} [GeV/c];#Delta p_{t}/p_{t}^{MC};SPECIES", 
-    kNpt, binsPt, kNdpt, binsDPt, kNspc, binsSpc);
-  } else h3->Reset();
-  arr->AddAt(h3, 8);
-  // Kalman track Pt pulls
-  if(!(h3 = (TH3S*)gROOT->FindObject("hMcTrkTPCPtPulls"))){
-    h3 = new TH3S("hMcTrkTPCPtPulls", 
-    "Track[TPC] 1/Pt Pulls;1/p_{t}^{MC} [c/GeV];#Delta(1/p_{t})/#sigma(1/p_{t});SPECIES", 
-    kNpt, 0., 2., 100, -4., 4., kNspc, -5.5, 5.5);
-  } else h3->Reset();
-  arr->AddAt(h3, 9);
-  // Kalman track P resolution
-  if(!(h3 = (TH3S*)gROOT->FindObject("hMcTrkTPCP"))){
-    h3 = new TH3S("hMcTrkTPCP", 
-    "TRDin P Resolution;p [GeV/c];#Delta p/p^{MC};SPECIES", 
-    kNpt, binsPt, kNdpt, binsDPt, kNspc, binsSpc);
-  } else h3->Reset();
-  arr->AddAt(h3, 10);
-  // Kalman track P pulls
-  if(!(h3 = (TH3S*)gROOT->FindObject("hMcTrkTPCPPulls"))){
-    h3 = new TH3S("hMcTrkTPCPPulls", 
-    "TRDin P Pulls;p^{MC} [GeV/c];#Deltap/#sigma_{p};SPECIES", 
-    kNpt, 0., 12., 100, -5., 5., kNspc, -5.5, 5.5);
-  } else h3->Reset();
-  arr->AddAt(h3, 11);
-
-
-
-  // Kalman track Z resolution [TOF]
-  fContainer->AddAt(arr = new TObjArray(fgNhistos[kMCtrackTOF]), kMCtrackTOF);
-  arr->SetName("McTrkTOF");
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTOFZ"))){
-    h = new TH2I("hMcTrkTOFZ", "Track[TOF] Z Resolution", 100, -1., 1., 100, -1., 1.);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z [cm]");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 0);
-  // Kalman track Z pulls
-  if(!(h = (TH2I*)gROOT->FindObject("hMcTrkTOFZPull"))){
-    h = new TH2I("hMcTrkTOFZPull", "Track[TOF] Z Pulls", 100, -1., 1., 100, -4.5, 4.5);
-    h->GetXaxis()->SetTitle("tg(#theta)");
-    h->GetYaxis()->SetTitle("#Delta z / #sigma_{z}");
-    h->GetZaxis()->SetTitle("entries");
-  } else h->Reset();
-  arr->AddAt(h, 1);
+  arr->AddAt(h, 10);
 
-  return fContainer;
+  return arr;
 }
 
+
 //________________________________________________________
-Bool_t AliTRDresolution::Process(TH2 * const h2, TF1 *f, Float_t k, TGraphErrors **g)
+TObjArray* AliTRDresolution::Histos()
 {
   //
-  // Do the processing
+  // Define histograms
   //
 
-  Char_t pn[10]; sprintf(pn, "p%03d", fIdxPlot);
-  Int_t n = 0;
-  if((n=g[0]->GetN())) for(;n--;) g[0]->RemovePoint(n);
-  if((n=g[1]->GetN())) for(;n--;) g[1]->RemovePoint(n);
+  if(fContainer) return fContainer;
 
-  for(Int_t ibin = 1; ibin <= h2->GetNbinsX(); ibin++){
-    Double_t x = h2->GetXaxis()->GetBinCenter(ibin);
-    TH1D *h = h2->ProjectionY(pn, ibin, ibin);
-    if(h->GetEntries()<100) continue;
-    //AdjustF1(h, f);
+  fContainer  = new TObjArray(kNclasses); fContainer->SetOwner(kTRUE);
+  THnSparse *H(NULL);
+  const Int_t nhn(100); Char_t hn[nhn]; TString st;
+
+  //++++++++++++++++++++++
+  // cluster to tracklet residuals/pulls
+  snprintf(hn, nhn, "h%s", fgPerformanceName[kCluster]);
+  if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
+    const Char_t *clTitle[kNdim] = {"layer", fgkTitle[kPhi], fgkTitle[kEta], fgkTitle[kYrez], "#Deltax [cm]", "Q</Q", "Q/angle", "#Phi [deg]"};
+    const Int_t clNbins[kNdim]   = {AliTRDgeometry::kNlayer, fgkNbins[kPhi], fgkNbins[kEta], fgkNbins[kYrez], 33, 10, 30, 15};
+    const Double_t clMin[kNdim]  = {-0.5, fgkMin[kPhi], fgkMin[kEta], fgkMin[kYrez]/10., 0., 0.1, -2., -45},
+                   clMax[kNdim]  = {AliTRDgeometry::kNlayer-0.5, fgkMax[kPhi], fgkMax[kEta], fgkMax[kYrez]/10., 3.3, 2.1, 118., 45};
+    st = "cluster spatial&charge resolution;";
+    // define minimum info to be saved in non debug mode
+    Int_t ndim=DebugLevel()>=1?kNdim:4;
+    for(Int_t idim(0); idim<ndim; idim++){ st += clTitle[idim]; st+=";";}
+    H = new THnSparseI(hn, st.Data(), ndim, clNbins, clMin, clMax);
+  } else H->Reset();
+  fContainer->AddAt(H, kCluster);
+  //++++++++++++++++++++++
+  // tracklet to TRD track
+  snprintf(hn, nhn, "h%s", fgPerformanceName[kTracklet]);
+  if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
+    Char_t *trTitle[kNdim+1]; memcpy(trTitle, fgkTitle, kNdim*sizeof(Char_t*));
+    Int_t trNbins[kNdim+1]; memcpy(trNbins, fgkNbins, kNdim*sizeof(Int_t));
+    Double_t trMin[kNdim+1]; memcpy(trMin, fgkMin, kNdim*sizeof(Double_t));
+    Double_t trMax[kNdim+1]; memcpy(trMax, fgkMax, kNdim*sizeof(Double_t));
+    // set specific fields
+    trTitle[kBC]=StrDup("layer"); trNbins[kBC] = AliTRDgeometry::kNlayer; trMin[kBC] = -0.5; trMax[kBC] = AliTRDgeometry::kNlayer-0.5;
+    trTitle[kNdim]=StrDup("dq/dl [a.u.]"); trNbins[kNdim] = 30; trMin[kNdim] = 100.; trMax[kNdim] = 3100;
+
+    st = "tracklet spatial&charge resolution;";
+    // define minimum info to be saved in non debug mode
+    Int_t ndim=DebugLevel()>=1?(kNdim+1):4;
+    for(Int_t idim(0); idim<ndim; idim++){ st += trTitle[idim]; st+=";";}
+    H = new THnSparseI(hn, st.Data(), ndim, trNbins, trMin, trMax);
+  } else H->Reset();
+  fContainer->AddAt(H, kTracklet);
+  //++++++++++++++++++++++
+  // tracklet to TRDin
+  snprintf(hn, nhn, "h%s", fgPerformanceName[kTrackIn]);
+  if(!(H = (THnSparseI*)gROOT->FindObject(hn))){
+    st = "r-#phi/z/angular residuals @ TRD entry;";
+    // define minimum info to be saved in non debug mode
+    Int_t ndim=DebugLevel()>=1?kNdim:7;
+    for(Int_t idim(0); idim<ndim; idim++){ st += fgkTitle[idim]; st+=";";}
+    H = new THnSparseI(hn, st.Data(), ndim, fgkNbins, fgkMin, fgkMax);
+  } else H->Reset();
+  fContainer->AddAt(H, kTrackIn);
+  // tracklet to TRDout
+//  fContainer->AddAt(BuildMonitorContainerTracklet("TrkOUT"), kTrackOut);
 
-    h->Fit(f, "QN");
-    
-    Int_t ip = g[0]->GetN();
-    g[0]->SetPoint(ip, x, k*f->GetParameter(1));
-    g[0]->SetPointError(ip, 0., k*f->GetParError(1));
-    g[1]->SetPoint(ip, x, k*f->GetParameter(2));
-    g[1]->SetPointError(ip, 0., k*f->GetParError(2));
-    
-/*  
-    g[0]->SetPoint(ip, x, k*h->GetMean());
-    g[0]->SetPointError(ip, 0., k*h->GetMeanError());
-    g[1]->SetPoint(ip, x, k*h->GetRMS());
-    g[1]->SetPointError(ip, 0., k*h->GetRMSError());*/
-  }
-  fIdxPlot++;
-  return kTRUE;
-}
 
-//________________________________________________________
-Bool_t AliTRDresolution::Process2D(ETRDresolutionPlot plot, Int_t idx, TF1 *f, Float_t k, Int_t gidx)
-{
-  //
-  // Do the processing
-  //
+  // Resolution histos
+  if(!HasMCdata()) return fContainer;
+
+  // cluster resolution 
+  fContainer->AddAt(BuildMonitorContainerCluster("MCcl"),  kMCcluster);
 
-  if(!fContainer || !fGraphS || !fGraphM) return kFALSE;
+  // tracklet resolution
+  fContainer->AddAt(BuildMonitorContainerTracklet("MCtracklet"), kMCtracklet);
 
-  // retrive containers
-  TH2I *h2 = idx<0 ? (TH2I*)(fContainer->At(plot)) : (TH2I*)((TObjArray*)(fContainer->At(plot)))->At(idx);
-  if(!h2) return kFALSE;
+  // track resolution
+  TObjArray *arr(NULL);
+  fContainer->AddAt(arr = new TObjArray(AliTRDgeometry::kNlayer), kMCtrack);
+  arr->SetName("MCtrk");
+  for(Int_t il(0); il<AliTRDgeometry::kNlayer; il++) arr->AddAt(BuildMonitorContainerTrack(Form("MCtrk_Ly%d", il)), il);
 
-  TGraphErrors *g[2];
-  if(gidx<0) gidx=idx;
-  if(!(g[0] = gidx<0 ? (TGraphErrors*)fGraphM->At(plot) : (TGraphErrors*)((TObjArray*)(fGraphM->At(plot)))->At(gidx))) return kFALSE;
+  // TRDin TRACK RESOLUTION
+  fContainer->AddAt(H, kMCtrackIn);
 
-  if(!(g[1] = gidx<0 ? (TGraphErrors*)fGraphS->At(plot) : (TGraphErrors*)((TObjArray*)(fGraphS->At(plot)))->At(gidx))) return kFALSE;
+  // TRDout TRACK RESOLUTION
+  fContainer->AddAt(BuildMonitorContainerTrack("MCtrkOUT"), kMCtrackOut);
 
-  return Process(h2, f, k, g);
+  return fContainer;
 }
 
 //________________________________________________________
-Bool_t AliTRDresolution::Process3D(ETRDresolutionPlot plot, Int_t idx, TF1 *f, Float_t k)
+Bool_t AliTRDresolution::Process(TH2* const h2, TGraphErrors **g, Int_t stat)
 {
-  //
-  // Do the processing
-  //
-
-  if(!fContainer || !fGraphS || !fGraphM) return kFALSE;
+// Robust function to process sigma/mean for 2D plot dy(x)
+// For each x bin a gauss fit is performed on the y projection and the range
+// with the minimum chi2/ndf is choosen
 
-  // retrive containers
-  TH3S *h3 = idx<0 ? (TH3S*)(fContainer->At(plot)) : (TH3S*)((TObjArray*)(fContainer->At(plot)))->At(idx);
-  if(!h3) return kFALSE;
+  if(!h2) {
+    if(AliLog::GetDebugLevel("PWG1", "AliTRDresolution")>0) printf("D-AliTRDresolution::Process() : NULL pointer input container.\n");
+    return kFALSE;
+  }
+  if(!Int_t(h2->GetEntries())){
+    if(AliLog::GetDebugLevel("PWG1", "AliTRDresolution")>0) printf("D-AliTRDresolution::Process() : Empty h[%s - %s].\n", h2->GetName(), h2->GetTitle());
+    return kFALSE;
+  }
+  if(!g || !g[0]|| !g[1]) {
+    if(AliLog::GetDebugLevel("PWG1", "AliTRDresolution")>0) printf("D-AliTRDresolution::Process() : NULL pointer output container.\n");
+    return kFALSE;
+  }
+  // prepare
+  TAxis *ax(h2->GetXaxis()), *ay(h2->GetYaxis());
+  Float_t ymin(ay->GetXmin()), ymax(ay->GetXmax()), dy(ay->GetBinWidth(1)), y0(0.), y1(0.);
+  TF1 f("f", "gaus", ymin, ymax);
+  Int_t n(0);
+  if((n=g[0]->GetN())) for(;n--;) g[0]->RemovePoint(n);
+  if((n=g[1]->GetN())) for(;n--;) g[1]->RemovePoint(n);
+  TH1D *h(NULL);
+  if((h=(TH1D*)gROOT->FindObject("py"))) delete h;
+  Double_t x(0.), y(0.), ex(0.), ey(0.), sy(0.), esy(0.);
+  
 
-  TObjArray *gm, *gs;
-  if(!(gm = (TObjArray*)((TObjArray*)(fGraphM->At(plot)))->At(idx))) return kFALSE;
-  if(!(gs = (TObjArray*)((TObjArray*)(fGraphS->At(plot)))->At(idx))) return kFALSE;
-  TGraphErrors *g[2];
+  // do actual loop
+  Float_t chi2OverNdf(0.);
+  for(Int_t ix = 1, np=0; ix<=ax->GetNbins(); ix++){
+    x = ax->GetBinCenter(ix); ex= ax->GetBinWidth(ix)*0.288; // w/sqrt(12)
+    ymin = ay->GetXmin(); ymax = ay->GetXmax();
 
-  TAxis *az = h3->GetZaxis();
-  for(Int_t iz=1; iz<=az->GetNbins(); iz++){
-    if(!(g[0] = (TGraphErrors*)gm->At(iz-1))) return kFALSE;
-    if(!(g[1] = (TGraphErrors*)gs->At(iz-1))) return kFALSE;
-    az->SetRange(iz, iz);
-    if(!Process((TH2*)h3->Project3D("yx"), f, k, g)) return kFALSE;
+    h = h2->ProjectionY("py", ix, ix);
+    if((n=(Int_t)h->GetEntries())<stat){
+      if(AliLog::GetDebugLevel("PWG1", "AliTRDresolution")>1) printf("I-AliTRDresolution::Process() : Low statistics @ x[%f] stat[%d]=%d [%d].\n", x, ix, n, stat);
+      continue;
+    }
+    // looking for a first order mean value
+    f.SetParameter(1, 0.); f.SetParameter(2, 3.e-2);
+    h->Fit(&f, "QNW");
+    chi2OverNdf = f.GetChisquare()/f.GetNDF();
+    printf("x[%f] range[%f %f] chi2[%f] ndf[%d] chi2/ndf[%f]\n", x, ymin, ymax, f.GetChisquare(),f.GetNDF(),chi2OverNdf);
+    y = f.GetParameter(1); y0 = y-4*dy; y1 = y+4*dy;
+    ey  = f.GetParError(1);
+    sy = f.GetParameter(2); esy = f.GetParError(2);
+//     // looking for the best chi2/ndf value
+//     while(ymin<y0 && ymax>y1){
+//       f.SetParameter(1, y);
+//       f.SetParameter(2, sy);
+//       h->Fit(&f, "QNW", "", y0, y1);
+//       printf("   range[%f %f] chi2[%f] ndf[%d] chi2/ndf[%f]\n", y0, y1, f.GetChisquare(),f.GetNDF(),f.GetChisquare()/f.GetNDF());
+//       if(f.GetChisquare()/f.GetNDF() < Chi2OverNdf){
+//         chi2OverNdf = f.GetChisquare()/f.GetNDF();
+//         y  = f.GetParameter(1); ey  = f.GetParError(1);
+//         sy = f.GetParameter(2); esy = f.GetParError(2);
+//         printf("    set y[%f] sy[%f] chi2/ndf[%f]\n", y, sy, chi2OverNdf);
+//       }
+//       y0-=dy; y1+=dy;
+//     }
+    g[0]->SetPoint(np, x, y);
+    g[0]->SetPointError(np, ex, ey);
+    g[1]->SetPoint(np, x, sy);
+    g[1]->SetPointError(np, ex, esy);
+    np++;
   }
-
   return kTRUE;
 }
 
+
 //________________________________________________________
-Bool_t AliTRDresolution::Process3Drange(ETRDresolutionPlot plot, Int_t hidx, Int_t gidx, TF1 *f, Float_t k, Int_t zbin0, Int_t zbin1)
+Bool_t AliTRDresolution::Process(TH2 * const h2, TF1 *f, Float_t k, TGraphErrors **g)
 {
   //
   // Do the processing
   //
 
-  if(!fContainer || !fGraphS || !fGraphM) return kFALSE;
-
-  // retrive containers
-  TH3S *h3 = hidx<0 ? (TH3S*)(fContainer->At(plot)) : (TH3S*)((TObjArray*)(fContainer->At(plot)))->At(hidx);
-  if(!h3) return kFALSE;
-
-  TGraphErrors *g[2];
-  if(!(g[0] = (TGraphErrors*)((TObjArray*)(fGraphM->At(plot)))->At(gidx))) return kFALSE;
-  if(!(g[1] = (TGraphErrors*)((TObjArray*)(fGraphS->At(plot)))->At(gidx))) return kFALSE;
+  Char_t pn[10]; snprintf(pn, 10, "p%03d", fIdxPlot);
+  Int_t n = 0;
+  if((n=g[0]->GetN())) for(;n--;) g[0]->RemovePoint(n);
+  if((n=g[1]->GetN())) for(;n--;) g[1]->RemovePoint(n);
+  if(Int_t(h2->GetEntries())){ 
+    AliDebug(4, Form("%s: g[%s %s]", pn, g[0]->GetName(), g[0]->GetTitle()));
+  } else {
+    AliDebug(2, Form("%s: g[%s %s]: Missing entries.", pn, g[0]->GetName(), g[0]->GetTitle()));
+    fIdxPlot++;
+    return kTRUE;
+  }
 
-  TAxis *az = h3->GetZaxis();
-  az->SetRange(zbin0, zbin1);
-  if(!Process((TH2*)h3->Project3D("yx"), f, k, g)) return kFALSE;
+  const Int_t kINTEGRAL=1;
+  for(Int_t ibin = 0; ibin < Int_t(h2->GetNbinsX()/kINTEGRAL); ibin++){
+    Int_t abin(ibin*kINTEGRAL+1),bbin(abin+kINTEGRAL-1),mbin(abin+Int_t(kINTEGRAL/2));
+    Double_t x = h2->GetXaxis()->GetBinCenter(mbin);
+    TH1D *h = h2->ProjectionY(pn, abin, bbin);
+    if((n=(Int_t)h->GetEntries())<150){ 
+      AliDebug(4, Form("  x[%f] range[%d %d] stat[%d] low statistics !", x, abin, bbin, n));
+      continue;
+    }
+    h->Fit(f, "QN");
+    Int_t ip = g[0]->GetN();
+    AliDebug(4, Form("  x_%d[%f] range[%d %d] stat[%d] M[%f] Sgm[%f]", ip, x, abin, bbin, n, f->GetParameter(1), f->GetParameter(2)));
+    g[0]->SetPoint(ip, x, k*f->GetParameter(1));
+    g[0]->SetPointError(ip, 0., k*f->GetParError(1));
+    g[1]->SetPoint(ip, x, k*f->GetParameter(2));
+    g[1]->SetPointError(ip, 0., k*f->GetParError(2));
+/*  
+    g[0]->SetPoint(ip, x, k*h->GetMean());
+    g[0]->SetPointError(ip, 0., k*h->GetMeanError());
+    g[1]->SetPoint(ip, x, k*h->GetRMS());
+    g[1]->SetPointError(ip, 0., k*h->GetRMSError());*/
+  }
+  fIdxPlot++;
   return kTRUE;
 }
 
-//________________________________________________________
-Bool_t AliTRDresolution::Process3DL(ETRDresolutionPlot plot, Int_t idx, TF1 *f, Float_t k)
+
+//____________________________________________________________________
+Bool_t AliTRDresolution::FitTrack(const Int_t np, AliTrackPoint *points, Float_t param[10])
 {
-  //
-  // Do the processing
-  //
+//
+// Fit track with a staight line using the "np" clusters stored in the array "points".
+// The following particularities are stored in the clusters from points:
+//   1. pad tilt as cluster charge
+//   2. pad row cross or vertex constrain as fake cluster with cluster type 1
+// The parameters of the straight line fit are stored in the array "param" in the following order :
+//     param[0] - x0 reference radial position
+//     param[1] - y0 reference r-phi position @ x0
+//     param[2] - z0 reference z position @ x0
+//     param[3] - slope dy/dx
+//     param[4] - slope dz/dx
+//
+// Attention :
+// Function should be used to refit tracks for B=0T
+//
 
-  if(!fContainer || !fGraphS || !fGraphM) return kFALSE;
-
-  // retrive containers
-  TH3S *h3 = (TH3S*)((TObjArray*)fContainer->At(plot))->At(idx);
-  if(!h3) return kFALSE;
-
-  TGraphAsymmErrors *gm; 
-  TGraphErrors *gs;
-  if(!(gm = (TGraphAsymmErrors*)((TObjArray*)fGraphM->At(plot))->At(0))) return kFALSE;
-  if(!(gs = (TGraphErrors*)((TObjArray*)fGraphS->At(plot)))) return kFALSE;
-
-  Float_t x, r, mpv, xM, xm;
-  TAxis *ay = h3->GetYaxis();
-  for(Int_t iy=1; iy<=h3->GetNbinsY(); iy++){
-    ay->SetRange(iy, iy);
-    x = ay->GetBinCenter(iy);
-    TH2F *h2=(TH2F*)h3->Project3D("zx");
-    TAxis *ax = h2->GetXaxis();
-    for(Int_t ix=1; ix<=h2->GetNbinsX(); ix++){
-      r = ax->GetBinCenter(ix);
-      TH1D *h1 = h2->ProjectionY("py", ix, ix);
-      if(h1->Integral()<50) continue;
-      h1->Fit(f, "QN");
-
-      GetLandauMpvFwhm(f, mpv, xm, xM);
-      Int_t ip = gm->GetN();
-      gm->SetPoint(ip, x, k*mpv);
-      gm->SetPointError(ip, 0., 0., k*xm, k*xM);
-      gs->SetPoint(ip, r, k*(xM-xm)/mpv);
-      gs->SetPointError(ip, 0., 0.);
-    }
+  if(np<40){
+    if(AliLog::GetDebugLevel("PWG1", "AliTRDresolution")>1) printf("D-AliTRDresolution::FitTrack: Not enough clusters to fit a track [%d].\n", np);
+    return kFALSE;
   }
+  TLinearFitter yfitter(2, "pol1"), zfitter(2, "pol1");
 
-  return kTRUE;
-}
-
-//________________________________________________________
-Bool_t AliTRDresolution::Process4D(ETRDresolutionPlot plot, Int_t idx, TF1 *f, Float_t k, Int_t n)
-{
-  //
-  // Do the processing
-  //
+  Double_t x0(0.);
+  for(Int_t ip(0); ip<np; ip++) x0+=points[ip].GetX();
+  x0/=Float_t(np);
 
-  if(!fContainer || !fGraphS || !fGraphM) return kFALSE;
-  //printf("Process4D : processing plot[%d] idx[%d]\n", plot, idx);
-
-  // retrive containers
-  TObjArray *arr = (TObjArray*)((TObjArray*)(fContainer->At(plot)))->At(idx);
-  if(!arr) return kFALSE;
-
-  TObjArray *gm, *gs;
-  if(!(gm = (TObjArray*)((TObjArray*)(fGraphM->At(plot)))->At(idx))) return kFALSE;
-  if(!(gs = (TObjArray*)((TObjArray*)(fGraphS->At(plot)))->At(idx))) return kFALSE;
-
-  TGraphErrors *g[2];
-
-  TH3S *h3(NULL);
-  for(Int_t ix=0, in=0; ix<arr->GetEntriesFast(); ix++){
-    if(!(h3 = (TH3S*)arr->At(ix))) return kFALSE;
-    TAxis *az = h3->GetZaxis();
-    //printf("  process ix[%d] bins[%d] in[%d]\n", ix, az->GetNbins(), in);
-    for(Int_t iz=1; iz<=az->GetNbins(); iz++, in++){
-      if(n>=0 && n!=in) continue;
-      if(!(g[0] = (TGraphErrors*)gm->At(in))) return kFALSE;
-      if(!(g[1] = (TGraphErrors*)gs->At(in))) return kFALSE;
-      //printf("    g0[%s] g1[%s]\n", g[0]->GetName(), g[1]->GetName());
-      az->SetRange(iz, iz);
-      if(!Process((TH2*)h3->Project3D("yx"), f, k, g)) return kFALSE;
-    }
+  Double_t x, y, z, dx, tilt(0.);
+  for(Int_t ip(0); ip<np; ip++){
+    x = points[ip].GetX(); z = points[ip].GetZ();
+    dx = x - x0;
+    zfitter.AddPoint(&dx, z, points[ip].GetClusterType()?1.e-3:1.);
+  }
+  if(zfitter.Eval() != 0) return kFALSE;
+
+  Double_t z0    = zfitter.GetParameter(0);
+  Double_t dzdx  = zfitter.GetParameter(1);
+  for(Int_t ip(0); ip<np; ip++){
+    if(points[ip].GetClusterType()) continue;
+    x    = points[ip].GetX();
+    dx   = x - x0;
+    y    = points[ip].GetY();
+    z    = points[ip].GetZ();
+    tilt = points[ip].GetCharge();
+    y -= tilt*(-dzdx*dx + z - z0);
+    Float_t xyz[3] = {x, y, z}; points[ip].SetXYZ(xyz);
+    yfitter.AddPoint(&dx, y, 1.);
   }
+  if(yfitter.Eval() != 0) return kFALSE;
+  Double_t y0   = yfitter.GetParameter(0);
+  Double_t dydx = yfitter.GetParameter(1);
 
+  param[0] = x0; param[1] = y0; param[2] = z0; param[3] = dydx; param[4] = dzdx;
+  if(AliLog::GetDebugLevel("PWG1", "AliTRDresolution")>3) printf("D-AliTRDresolution::FitTrack: x0[%f] y0[%f] z0[%f] dydx[%f] dzdx[%f].\n", x0, y0, z0, dydx, dzdx);
   return kTRUE;
 }
 
-//________________________________________________________
-Bool_t AliTRDresolution::GetGraphPlot(Float_t *bb, ETRDresolutionPlot ip, Int_t idx)
+//____________________________________________________________________
+Bool_t AliTRDresolution::FitTracklet(const Int_t ly, const Int_t np, const AliTrackPoint *points, const Float_t param[10], Float_t par[3])
 {
-  //
-  // Get the graphs
-  //
+//
+// Fit tracklet with a staight line using the coresponding subset of clusters out of the total "np" clusters stored in the array "points".
+// See function FitTrack for the data stored in the "clusters" array
 
-  if(!fGraphS || !fGraphM) return kFALSE;
-
-  //printf("plotting task[%d] gidx[%d]\n", ip, idx);
-  TGraphErrors *gm = idx<0 ? (TGraphErrors*)fGraphM->At(ip) : (TGraphErrors*)((TObjArray*)(fGraphM->At(ip)))->At(idx);
-  if(!gm) return kFALSE;
-  TGraphErrors *gs = idx<0 ? (TGraphErrors*)fGraphS->At(ip) : (TGraphErrors*)((TObjArray*)(fGraphS->At(ip)))->At(idx);
-  if(!gs) return kFALSE;
-  //printf("gs[%s] gm[%s]\n", gs->GetName(), gm->GetName());
-  gs->Draw("apl"); gm->Draw("pl");
-  //return kTRUE;
-  // titles look up
-  Int_t nref = 0;
-  for(Int_t jp=0; jp<(Int_t)ip; jp++) nref+=fgNproj[jp];
-  UChar_t jdx = idx<0?0:idx;
-  for(Int_t jc=0; jc<TMath::Min(jdx,fgNproj[ip]-1); jc++) nref++;
-  const Char_t **at = fgAxTitle[nref];
+// The parameters of the straight line fit are stored in the array "param" in the following order :
+//     par[0] - x0 reference radial position
+//     par[1] - y0 reference r-phi position @ x0
+//     par[2] - slope dy/dx
+//
+// Attention :
+// Function should be used to refit tracks for B=0T
+//
 
-  Int_t n(0);
-  if((n=gm->GetN())) {
-    PutTrendValue(Form("%s_%s", fgPerformanceName[ip], at[0]), gm->GetMean(2));
-    PutTrendValue(Form("%s_%sRMS", fgPerformanceName[ip], at[0]), gm->GetRMS(2));
-  }
-
-  if((n=gs->GetN())){
-    gs->Sort(&TGraph::CompareY);
-    PutTrendValue(Form("%s_%sSigMin", fgPerformanceName[ip], at[0]), gs->GetY()[0]);
-    PutTrendValue(Form("%s_%sSigMax", fgPerformanceName[ip], at[0]), gs->GetY()[n-1]);
-    gs->Sort(&TGraph::CompareX); 
-  }
-
-  // axis range
-  TAxis *ax(NULL); TH1 *hf(NULL);
-  hf = gs->GetHistogram();
-  hf->SetTitle(at[0]);
-  ax = hf->GetXaxis();
-  ax->SetRangeUser(bb[0], bb[2]);
-  ax->SetTitle(at[1]);ax->CenterTitle();
-
-  ax = hf->GetYaxis();
-  ax->SetRangeUser(bb[1], bb[3]);
-  ax->SetTitleOffset(1.1);
-  ax->SetTitle(at[2]);ax->CenterTitle();
-
-  TGaxis *gax = NULL;
-  gax = new TGaxis(bb[2], bb[1], bb[2], bb[3], bb[1], bb[3], 510, "+U");
-  gax->SetLineColor(kRed);gax->SetLineWidth(2);gax->SetTextColor(kRed);
-  //gax->SetVertical();
-  gax->CenterTitle(); gax->SetTitleOffset(.7);
-  gax->SetTitle(at[3]); gax->Draw();
-
-  // bounding box
-  TBox *b = new TBox(-.15, bb[1], .15, bb[3]);
-  b->SetFillStyle(3002);b->SetLineColor(0);
-  b->SetFillColor(ip<=Int_t(kMCcluster)?kGreen:kBlue);
-  b->Draw();
-  return kTRUE;
-}
+  TLinearFitter yfitter(2, "pol1");
+
+  // grep data for tracklet
+  Double_t x0(0.), x[60], y[60], dy[60];
+  Int_t nly(0);
+  for(Int_t ip(0); ip<np; ip++){
+    if(points[ip].GetClusterType()) continue;
+    if(points[ip].GetVolumeID() != ly) continue;
+    Float_t xt(points[ip].GetX())
+           ,yt(param[1] + param[3] * (xt - param[0]));
+    x[nly] = xt;
+    y[nly] = points[ip].GetY();
+    dy[nly]= y[nly]-yt;
+    x0    += xt;
+    nly++;
+  }
+  if(nly<10){
+    if(AliLog::GetDebugLevel("PWG1", "AliTRDresolution")>1) printf("D-AliTRDresolution::FitTracklet: Not enough clusters to fit a tracklet [%d].\n", nly);
+    return kFALSE;
+  }
+  // set radial reference for fit
+  x0 /= Float_t(nly);
 
-//________________________________________________________
-Bool_t AliTRDresolution::GetGraphTrack(Float_t *bb, Int_t idx, Int_t first, Int_t n, Bool_t kLEG)
-{
-  //
-  // Get the graphs
-  //
+  // find tracklet core
+  Double_t mean(0.), sig(1.e3);
+  AliMathBase::EvaluateUni(nly, dy, mean, sig, 0);
 
-  if(!fGraphS || !fGraphM) return kFALSE;
-
-  // axis titles look up
-  Int_t nref(0);
-  for(Int_t jp=0; jp<Int_t(kMCtrackTRD); jp++) nref+=fgNproj[jp];
-  nref+=idx;
-  const Char_t **at = fgAxTitle[nref];
-  //printf("nref[%d] ax[%s] x[%f %f] y[%f %f]\n", nref, at[0], bb[0], bb[2], bb[1], bb[3]);
-
-  TLegend *legM(NULL), *legS(NULL);
-  if(kLEG){
-    legM=new TLegend(.35, .6, .65, .9);
-    legM->SetHeader("Mean");
-    legM->SetBorderSize(1);
-    legM->SetFillColor(0);
-    legS=new TLegend(.65, .6, .95, .9);
-    legS->SetHeader("Sigma");
-    legS->SetBorderSize(1);
-    legS->SetFillColor(0);
-  }
-  Int_t layer(first/11);
-  TH1S *h1(NULL);
-  h1 = new TH1S(Form("h1TF_%02d", fIdxFrame++), Form("%s %d;%s;%s", at[0], layer, at[1], at[2]), 2, bb[0], bb[2]);
-  h1->SetMinimum(bb[1]);h1->SetMaximum(bb[3]);
-  h1->SetLineColor(kBlack); h1->SetLineWidth(1);h1->SetLineStyle(2); 
-  // axis range
-  TAxis *ax = h1->GetXaxis();
-  ax->CenterTitle();ax->SetMoreLogLabels();ax->SetTitleOffset(1.2);
-  ax = h1->GetYaxis();
-  ax->SetRangeUser(bb[1], bb[3]);
-  ax->CenterTitle(); ax->SetTitleOffset(1.4);
-  h1->Draw();
-//   TGaxis *gax = NULL;
-//   gax = new TGaxis(bb[2], bb[1], bb[2], bb[3], bb[1], bb[3], 510, "+U");
-//   gax->SetLineColor(kRed);gax->SetLineWidth(2);gax->SetTextColor(kRed);
-//   //gax->SetVertical();
-//   gax->CenterTitle(); //gax->SetTitleOffset(.5);gax->SetTitleSize(.06);
-//   gax->SetTitle(at[3]); gax->Draw();
-
-  TGraphErrors *gm = NULL, *gs = NULL;
-  TObjArray *a0 = NULL, *a1 = NULL;
-  a0 = (TObjArray*)((TObjArray*)fGraphM->At(kMCtrackTRD))->At(idx);
-  a1 = (TObjArray*)((TObjArray*)fGraphS->At(kMCtrackTRD))->At(idx);
-  Int_t nn(0), m(n/2);
-  for(Int_t is=first, is0=0; is<first+n; is++, is0++){
-    if(is0==m) continue; // no PID tracks
-    if(is0==m-1||is0==m+1) continue; // electron tracks
-    if(!(gs =  (TGraphErrors*)a1->At(is))) return kFALSE;
-    if(!(gm =  (TGraphErrors*)a0->At(is))) return kFALSE;
-
-    if((nn=gs->GetN())){
-      gs->Draw("pc"); if(legS) legS->AddEntry(gs, gs->GetTitle(), "pl");
-      gs->Sort(&TGraph::CompareY);
-      PutTrendValue(Form("%s_%sSigMin%s", fgPerformanceName[kMCtrackTRD], at[0], AliPID::ParticleShortName(is0)), gs->GetY()[0]);
-      PutTrendValue(Form("%s_%sSigMax%s", fgPerformanceName[kMCtrackTRD], at[0], AliPID::ParticleShortName(is0)), gs->GetY()[nn-1]);
-      gs->Sort(&TGraph::CompareX); 
-    }
-    if(gm->GetN()){
-      gm->Draw("pc");if(legM) legM->AddEntry(gm, gm->GetTitle(), "pl");
-      PutTrendValue(Form("%s_%s_%s", fgPerformanceName[kMCtrackTRD], at[0], AliPID::ParticleShortName(is0)), gm->GetMean(2));
-      PutTrendValue(Form("%s_%s_%sRMS", fgPerformanceName[kMCtrackTRD], at[0], AliPID::ParticleShortName(is0)), gm->GetRMS(2));
-    }
+  // simple cluster error parameterization
+  Float_t kSigCut = TMath::Sqrt(5.e-4 + param[3]*param[3]*0.018);
+
+  // fit tracklet core
+  for(Int_t jly(0); jly<nly; jly++){
+    if(TMath::Abs(dy[jly]-mean)>kSigCut) continue;
+    Double_t dx(x[jly]-x0);
+    yfitter.AddPoint(&dx, y[jly], 1.);
   }
-  if(kLEG){legM->Draw();legS->Draw();}
+  if(yfitter.Eval() != 0) return kFALSE;
+  par[0] = x0;
+  par[1] = yfitter.GetParameter(0);
+  par[2] = yfitter.GetParameter(1);
   return kTRUE;
 }
 
-
-//________________________________________________________
-Bool_t AliTRDresolution::GetGraphTrackTPC(Float_t *bb, Int_t idx, Int_t ist, Int_t n, Bool_t kLEG)
+//____________________________________________________________________
+Bool_t AliTRDresolution::UseTrack(const Int_t np, const AliTrackPoint *points, Float_t param[10])
 {
-  //
-  // Get the graphs
-  //
-
-  if(!fGraphS || !fGraphM) return kFALSE;
-
-  // axis titles look up
-  Int_t nref = 0;
-  for(Int_t jp=0; jp<Int_t(kMCtrackTPC); jp++) nref+=fgNproj[jp];
-  nref+=idx;
-  const Char_t **at = fgAxTitle[nref];
-
-  TLegend *legM(NULL), *legS(NULL);
-  if(kLEG){
-    legM=new TLegend(.35, .6, .65, .9);
-    legM->SetHeader("Mean");
-    legM->SetBorderSize(1);
-    legM->SetFillColor(0);
-    legS=new TLegend(.65, .6, .95, .9);
-    legS->SetHeader("Sigma");
-    legS->SetBorderSize(1);
-    legS->SetFillColor(0);
-  }
-  TH1S *h1(NULL);
-  h1 = new TH1S(Form("h1TF_%02d", fIdxFrame++), at[0], 2, bb[0], bb[2]);
-  h1->SetMinimum(bb[1]);h1->SetMaximum(bb[3]);
-  h1->SetLineColor(kBlack); h1->SetLineWidth(1);h1->SetLineStyle(2); 
-  // axis range
-  TAxis *ax = h1->GetXaxis();
-  ax->SetTitle(at[1]);ax->CenterTitle();ax->SetMoreLogLabels();ax->SetTitleOffset(1.2);
-  ax = h1->GetYaxis();
-  ax->SetRangeUser(bb[1], bb[3]);
-  ax->SetTitleOffset(1.4);//ax->SetTitleSize(.06);
-  ax->SetTitle(at[2]);ax->CenterTitle();
-  h1->Draw();
-//   TGaxis *gax = NULL;
-//   gax = new TGaxis(bb[2], bb[1], bb[2], bb[3], bb[1], bb[3], 510, "+U");
-//   gax->SetLineColor(kRed);gax->SetLineWidth(2);gax->SetTextColor(kRed);
-//   //gax->SetVertical();
-//   gax->CenterTitle(); //gax->SetTitleOffset(.5);gax->SetTitleSize(.06);
-//   gax->SetTitle(at[3]); gax->Draw();
-
-  Int_t nn(0), m(n/2);
-  TGraphErrors *gm = NULL, *gs = NULL;
-  TObjArray *a0 = NULL, *a1 = NULL;
-  a0 = (TObjArray*)((TObjArray*)fGraphM->At(kMCtrackTPC))->At(idx);
-  a1 = (TObjArray*)((TObjArray*)fGraphS->At(kMCtrackTPC))->At(idx);
-  for(Int_t is=ist, is0=0; is<ist+n; is++, is0++){
-    if(is0==m) continue; // no PID tracks
-    //if(is0==m-1||is0==m+1) continue; // electron tracks
-    if(!(gs =  (TGraphErrors*)a1->At(is))) return kFALSE;
-    if(!(gm =  (TGraphErrors*)a0->At(is))) return kFALSE;
-    if((nn=gs->GetN())){
-      gs->Draw("pl");if(legS) legS->AddEntry(gs, gs->GetTitle(), "pl");
-      gs->Sort(&TGraph::CompareY);
-      PutTrendValue(Form("%s_%sSigMin%s", fgPerformanceName[kMCtrackTPC], at[0], AliPID::ParticleShortName(is0)), gs->GetY()[0]);
-      PutTrendValue(Form("%s_%sSigMax%s", fgPerformanceName[kMCtrackTPC], at[0], AliPID::ParticleShortName(is0)), gs->GetY()[nn-1]);
-      gs->Sort(&TGraph::CompareX); 
-    }
-    if(gm->GetN()){
-      gm->Draw("pl"); if(legM) legM->AddEntry(gm, gm->GetTitle(), "pl");
-      PutTrendValue(Form("%s_%s_%s", fgPerformanceName[kMCtrackTPC], at[0], AliPID::ParticleShortName(is0)), gm->GetMean(2));
-      PutTrendValue(Form("%s_%s_%sRMS", fgPerformanceName[kMCtrackTPC], at[0], AliPID::ParticleShortName(is0)), gm->GetRMS(2));
-    }
+//
+// Global selection mechanism of tracksbased on cluster to fit residuals
+// The parameters are the same as used ni function FitTrack().
+
+  const Float_t kS(0.6), kM(0.2);
+  TH1S h("h1", "", 100, -5.*kS, 5.*kS);
+  Float_t dy, dz, s, m;
+  for(Int_t ip(0); ip<np; ip++){
+    if(points[ip].GetClusterType()) continue;
+    Float_t x0(points[ip].GetX())
+          ,y0(param[1] + param[3] * (x0 - param[0]))
+          ,z0(param[2] + param[4] * (x0 - param[0]));
+    dy=points[ip].GetY() - y0; h.Fill(dy);
+    dz=points[ip].GetZ() - z0;
   }
-  if(kLEG) {legM->Draw(); legS->Draw();}
+  TF1 fg("fg", "gaus", -5.*kS, 5.*kS);
+  fg.SetParameter(1, 0.);
+  fg.SetParameter(2, 2.e-2);
+  h.Fit(&fg, "QN");
+  m=fg.GetParameter(1); s=fg.GetParameter(2);
+  if(s>kS || TMath::Abs(m)>kM) return kFALSE;
   return kTRUE;
 }
 
@@ -2281,9 +1990,177 @@ void AliTRDresolution::GetLandauMpvFwhm(TF1 * const f, Float_t &mpv, Float_t &xm
 }
 
 
+// #include "TFile.h"
+// //________________________________________________________
+// Bool_t AliTRDresolution::LoadCorrection(const Char_t *file)
+// {
+//   if(!file){
+//     AliWarning("Use cluster position as in reconstruction.");
+//     SetLoadCorrection();
+//     return kTRUE;
+//   }
+//   TDirectory *cwd(gDirectory);
+//   TString fileList;
+//   FILE *filePtr = fopen(file, "rt");
+//   if(!filePtr){
+//     AliWarning(Form("Couldn't open correction list \"%s\". Use cluster position as in reconstruction.", file));
+//     SetLoadCorrection();
+//     return kFALSE;
+//   }
+//   TH2 *h2 = new TH2F("h2", ";time [time bins];detector;dx [#mum]", 30, -0.5, 29.5, AliTRDgeometry::kNdet, -0.5, AliTRDgeometry::kNdet-0.5);
+//   while(fileList.Gets(filePtr)){
+//     if(!TFile::Open(fileList.Data())) {
+//       AliWarning(Form("Couldn't open \"%s\"", fileList.Data()));
+//       continue;
+//     } else AliInfo(Form("\"%s\"", fileList.Data()));
+// 
+//     TTree *tSys = (TTree*)gFile->Get("tSys");
+//     h2->SetDirectory(gDirectory); h2->Reset("ICE");
+//     tSys->Draw("det:t>>h2", "dx", "goff");
+//     for(Int_t idet(0); idet<AliTRDgeometry::kNdet; idet++){
+//       for(Int_t it(0); it<30; it++) fXcorr[idet][it]+=(1.e-4*h2->GetBinContent(it+1, idet+1));
+//     }
+//     h2->SetDirectory(cwd);
+//     gFile->Close();
+//   }
+//   cwd->cd();
+// 
+//   if(AliLog::GetDebugLevel("PWG1", "AliTRDresolution")>=2){
+//     for(Int_t il(0); il<184; il++) printf("-"); printf("\n");
+//     printf("DET|");for(Int_t it(0); it<30; it++) printf(" tb%02d|", it); printf("\n");
+//     for(Int_t il(0); il<184; il++) printf("-"); printf("\n");
+//     FILE *fout = fopen("TRD.ClusterCorrection.txt", "at");
+//     fprintf(fout, "  static const Double_t dx[AliTRDgeometry::kNdet][30]={\n");
+//     for(Int_t idet(0); idet<AliTRDgeometry::kNdet; idet++){
+//       printf("%03d|", idet);
+//       fprintf(fout, "    {");
+//       for(Int_t it(0); it<30; it++){
+//         printf("%+5.0f|", 1.e4*fXcorr[idet][it]);
+//         fprintf(fout, "%+6.4f%c", fXcorr[idet][it], it==29?' ':',');
+//       }
+//       printf("\n");
+//       fprintf(fout, "}%c\n", idet==AliTRDgeometry::kNdet-1?' ':',');
+//     }
+//     fprintf(fout, "  };\n");
+//   }
+//   SetLoadCorrection();
+//   return kTRUE;
+// }
+
+//________________________________________________________
+AliTRDresolution::AliTRDresolutionProjection::AliTRDresolutionProjection()
+  :fH(NULL)
+  ,fNrebin(NULL)
+  ,fRebinX(NULL)
+  ,fRebinY(NULL)
+{
+  // constructor
+  memset(fAx, 0, 3*sizeof(Int_t));
+  fRange[0] = 0.;fRange[1] = 0.;
+}
+
+//________________________________________________________
+AliTRDresolution::AliTRDresolutionProjection::~AliTRDresolutionProjection()
+{
+  // destructor
+  if(fH) delete fH;
+}
+
 //________________________________________________________
-void AliTRDresolution::SetRecoParam(AliTRDrecoParam *r)
+void AliTRDresolution::AliTRDresolutionProjection::Build(const Char_t *n, const Char_t *t, Int_t ix, Int_t iy, Int_t iz, TAxis *aa[])
 {
+// check and build (if neccessary) projection determined by axis "ix", "iy" and "iz"
+  if(!aa[ix] || !aa[ix] || !aa[iz]) return;
+  TAxis *ax(aa[ix]), *ay(aa[iy]), *az(aa[iz]);
+  fH = new TH3I(n, Form("%s;%s;%s;%s", t, ax->GetTitle(), ay->GetTitle(), az->GetTitle()),
+    ax->GetNbins(), ax->GetXmin(), ax->GetXmax(),
+    ay->GetNbins(), ay->GetXmin(), ay->GetXmax(),
+    az->GetNbins(), az->GetXmin(), az->GetXmax());
+  fAx[0] = ix; fAx[1] = iy; fAx[2] = iz;
+  fRange[0] = az->GetXmin()/3.; fRange[1] = az->GetXmax()/3.;
+}
 
-  fReconstructor->SetRecoParam(r);
+//________________________________________________________
+void AliTRDresolution::AliTRDresolutionProjection::Increment(Int_t bin[], Double_t v)
+{
+// increment bin with value "v" pointed by general coord in "bin"
+  if(!fH) return;
+  fH->AddBinContent(
+        fH->GetBin(bin[fAx[0]],bin[fAx[1]],bin[fAx[2]]), v);
 }
+
+//________________________________________________________
+TH2* AliTRDresolution::AliTRDresolutionProjection::Projection2D(const Int_t nstat, const Int_t ncol, const Int_t mid)
+{
+// build the 2D projection and adjust binning
+
+  if(!fH) return NULL;
+  TAxis *ax(fH->GetXaxis()), *ay(fH->GetYaxis()), *az(fH->GetZaxis());
+  TH2 *h2s = (TH2*)fH->Project3D("yx");
+  //printf("%s[%s] :: X[%d]  Y[%d] \n", h2s->GetName(), h2s->GetTitle(), h2s->GetNbinsX(), h2s->GetNbinsY());
+  Int_t irebin(0), dxBin(1), dyBin(1);
+  while(irebin<fNrebin && (AliTRDresolution::GetMeanStat(h2s, .5, ">")<nstat)){
+    h2s->Rebin2D(fRebinX[irebin], fRebinY[irebin]);
+    dxBin*=fRebinX[irebin];dyBin*=fRebinY[irebin];
+    //printf("   ireb[%d] rex[%2d] rey[%2d]\n", irebin, dxBin, dyBin);
+    irebin++;
+  }
+  Int_t nx(h2s->GetNbinsX()), ny(h2s->GetNbinsY());
+  if(h2s) delete h2s;
+
+  // start projection
+  TH1 *h(NULL);
+  Float_t dz=(fRange[1]-fRange[1])/ncol;
+  TH2 *h2 = new TH2F(Form("%s_2D", fH->GetName()),
+            Form("%s;%s;%s;%s", fH->GetTitle(), ax->GetTitle(), ay->GetTitle(), az->GetTitle()),
+            nx, ax->GetXmin(), ax->GetXmax(), ny, ay->GetXmin(), ay->GetXmax());
+  h2->SetContour(ncol);
+  h2->GetZaxis()->CenterTitle();
+  h2->GetZaxis()->SetRangeUser(fRange[0], fRange[1]);
+  //printf("%s[%s] nx[%d] ny[%d]\n", h2->GetName(), h2->GetTitle(), nx, ny);
+  for(Int_t iy(0); iy<ny; iy++){
+    for(Int_t ix(0); ix<nx; ix++){
+      h = fH->ProjectionZ(Form("%s_z", h2->GetName()), ix*dxBin+1, (ix+1)*dxBin+1, iy*dyBin+1, (iy+1)*dyBin+1);
+      Int_t ne(h->Integral());
+      if(ne<nstat/2){
+        h2->SetBinContent(ix+1, iy+1, -999);
+        h2->SetBinError(ix+1, iy+1, 1.);
+      }else{
+        Float_t v(h->GetMean()), ve(h->GetRMS());
+        if(mid==1){
+          TF1 fg("fg", "gaus", az->GetXmin(), az->GetXmax());
+          fg.SetParameter(0, Float_t(ne)); fg.SetParameter(1, v); fg.SetParameter(2, ve);
+          h->Fit(&fg, "WQ");
+          v = fg.GetParameter(1); ve = fg.GetParameter(2);
+        } else if (mid==2) {
+          TF1 fl("fl", "landau", az->GetXmin(), az->GetXmax());
+          fl.SetParameter(0, Float_t(ne)); fl.SetParameter(1, v); fl.SetParameter(2, ve);
+          h->Fit(&fl, "WQ");
+          v = fl.GetMaximumX(); ve = fl.GetParameter(2);
+/*          TF1 fgle("gle", "[0]*TMath::Landau(x, [1], [2], 1)*TMath::Exp(-[3]*x/[1])", az->GetXmin(), az->GetXmax());
+          fgle.SetParameter(0, fl.GetParameter(0));
+          fgle.SetParameter(1, fl.GetParameter(1));
+          fgle.SetParameter(2, fl.GetParameter(2));
+          fgle.SetParameter(3, 1.);fgle.SetParLimits(3, 0., 5.);
+          h->Fit(&fgle, "WQ");
+          v = fgle.GetMaximumX(); ve = fgle.GetParameter(2);*/
+        }
+        if(v<fRange[0]) h2->SetBinContent(ix+1, iy+1, fRange[0]+0.1*dz);
+        else h2->SetBinContent(ix+1, iy+1, v);
+        h2->SetBinError(ix+1, iy+1, ve);
+      }
+    }
+  }
+  if(h) delete h;
+  return h2;
+}
+
+void AliTRDresolution::AliTRDresolutionProjection::SetRebinStrategy(Int_t n, Int_t rebx[], Int_t reby[])
+{
+// define rebinning strategy for this projection
+  fNrebin = n;
+  fRebinX = new Int_t[n]; memcpy(fRebinX, rebx, n*sizeof(Int_t));
+  fRebinY = new Int_t[n]; memcpy(fRebinY, reby, n*sizeof(Int_t));
+}
+
+