]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - TRD/qaRec/AliTRDresolution.cxx
fix warnings (thanks to Federico)
[u/mrichter/AliRoot.git] / TRD / qaRec / AliTRDresolution.cxx
index 980b9ecb1cd85f6857dbf2c495ef11975c5fc920..a022e4f7471583799955052cd94da3eeca168004 100644 (file)
@@ -257,7 +257,7 @@ TH1* AliTRDresolution::PlotTracklet(const AliTRDtrackV1 *track)
     dy   = y0-dx*dydx - fTracklet->GetY();
     fTracklet->GetCovAt(x, cov);
     fTracklet->GetCovRef(covR);
-    h->Fill(dydx, dy/TMath::Sqrt(cov[0] + covR[0]));
+    h->Fill(dydx, dy/*/TMath::Sqrt(cov[0] + covR[0])*/);
   }
   return h;
 }
@@ -287,7 +287,7 @@ TH1* AliTRDresolution::PlotTrackletPhi(const AliTRDtrackV1 *track)
 
 
 //________________________________________________________
-TH1* AliTRDresolution::PlotResolution(const AliTRDtrackV1 *track)
+TH1* AliTRDresolution::PlotMC(const AliTRDtrackV1 *track)
 {
   if(!HasMCdata()){ 
     AliWarning("No MC defined. Results will not be available.");
@@ -302,9 +302,9 @@ TH1* AliTRDresolution::PlotResolution(const AliTRDtrackV1 *track)
   UChar_t s;
   Int_t pdg = fMC->GetPDG(), det=-1;
   Int_t label = fMC->GetLabel();
-  Double_t x, y, z;
-  Float_t p, pt, x0, y0, z0, dx, dy, dz, dydx, dzdx;
-  Double_t covR[3];
+  Double_t x, y, z, pt, dydx, dzdx;
+  Float_t p, pt0, x0, y0, z0, dx, dy, dz, dydx0, dzdx0;
+  Double_t covR[3]/*, cov[3]*/;
 
   if(fDebugLevel>=1){
     Double_t DX[12], DY[12], DZ[12], DPt[12], COV[12][15];
@@ -328,61 +328,62 @@ TH1* AliTRDresolution::PlotResolution(const AliTRDtrackV1 *track)
 
   AliTRDseedV1 *fTracklet = 0x0;  
   for(Int_t ily=0; ily<AliTRDgeometry::kNlayer; ily++){
-    if(!(fTracklet = fTrack->GetTracklet(ily)) ||
-       !fTracklet->IsOK()) continue;
+    if(!(fTracklet = fTrack->GetTracklet(ily)))/* ||
+       !fTracklet->IsOK())*/ continue;
 
     det = fTracklet->GetDetector();
     x0  = fTracklet->GetX0();
     //radial shift with respect to the MC reference (radial position of the pad plane)
     x= fTracklet->GetX();
+    if(!fMC->GetDirections(x0, y0, z0, dydx0, dzdx0, pt0, s)) continue;
+    // MC track position at reference radial position
     dx  = x0 - x;
-    if(!fMC->GetDirections(x0, y0, z0, dydx, dzdx, pt, s)) continue;
     if(fDebugLevel>=1){
       (*fDebugStream) << "MC"
         << "det="     << det
         << "pdg="     << pdg
-        << "pt="      << pt
-        << "x0="      << x0
-        << "y0="      << y0
-        << "z0="      << z0
-        << "dydx="    << dydx
-        << "dzdx="    << dzdx
+        << "pt="      << pt0
+        << "x="       << x0
+        << "y="       << y0
+        << "z="       << z0
+        << "dydx="    << dydx0
+        << "dzdx="    << dzdx0
         << "\n";
     }
-    // MC track position at reference radial position
-    Float_t yt = y0 - dx*dydx;
-    Float_t zt = z0 - dx*dzdx;
-    p = pt*(1.+dzdx*dzdx); // pt -> p
+    Float_t yt = y0 - dx*dydx0;
+    Float_t zt = z0 - dx*dzdx0;
+    p = pt0*(1.+dzdx0*dzdx0); // pt -> p
 
     // add Kalman residuals for y, z and pt
-    Float_t yr = fTracklet->GetYref(0) - dx*fTracklet->GetYref(1);
-    dy = yt - yr;
-    Float_t zr = fTracklet->GetZref(0) - dx*fTracklet->GetZref(1);
-    dz = zt - zr;
-    Float_t tgl = fTracklet->GetTgl();
-    Float_t dpt = pt - fTracklet->GetMomentum()/(1.+tgl*tgl);
+    dx = fTracklet->GetX0() - x;
+    y  = fTracklet->GetYref(0) - dx*fTracklet->GetYref(1);
+    dy = yt - y;
+    z  = fTracklet->GetZref(0) - dx*fTracklet->GetZref(1);
+    dz = zt - z;
+    dzdx = fTracklet->GetTgl();
+    pt = fTracklet->GetMomentum()/(1.+dzdx*dzdx);
     fTracklet->GetCovRef(covR);
 
-    ((TH2I*)fContainer->At(kMCtrackY))->Fill(dydx, dy);
-    ((TH2I*)fContainer->At(kMCtrackYPull))->Fill(dydx, dy/TMath::Sqrt(covR[0]));
+    ((TH2I*)fContainer->At(kMCtrackY))->Fill(dydx0, dy);
+    ((TH2I*)fContainer->At(kMCtrackYPull))->Fill(dydx0, dy/TMath::Sqrt(covR[0]));
     if(ily==0){
-      ((TH2I*)fContainer->At(kMCtrackZIn))->Fill(dzdx, dz);
-      ((TH2I*)fContainer->At(kMCtrackZInPull))->Fill(dzdx, dz/TMath::Sqrt(covR[2]));
+      ((TH2I*)fContainer->At(kMCtrackZIn))->Fill(dzdx0, dz);
+      ((TH2I*)fContainer->At(kMCtrackZInPull))->Fill(dzdx0, dz/TMath::Sqrt(covR[2]));
     } else if(ily==AliTRDgeometry::kNlayer-1) {
-      ((TH2I*)fContainer->At(kMCtrackZOut))->Fill(dzdx, dz);
-      ((TH2I*)fContainer->At(kMCtrackZOutPull))->Fill(dzdx, dz/TMath::Sqrt(covR[2]));
+      ((TH2I*)fContainer->At(kMCtrackZOut))->Fill(dzdx0, dz);
+      ((TH2I*)fContainer->At(kMCtrackZOutPull))->Fill(dzdx0, dz/TMath::Sqrt(covR[2]));
     }
-    if(pdg!=kElectron && pdg!=kPositron) ((TH2I*)fContainer->At(kMCtrackPt))->Fill(1./pt, dpt);
+    if(pdg!=kElectron && pdg!=kPositron) ((TH2I*)fContainer->At(kMCtrackPt))->Fill(1./pt0, pt-pt0);
     // Fill Debug stream for Kalman track
     if(fDebugLevel>=1){
-      Float_t dydxr = fTracklet->GetYref(1);
+      dydx = fTracklet->GetYref(1);
       (*fDebugStream) << "MCtrack"
+        << "pt="      << pt
         << "x="       << x
-        << "dpt="     << dpt
-        << "dy="      << dy
-        << "dz="      << dz
-        << "dydxr="   << dydxr
-        << "dzdxr="   << tgl
+        << "y="       << y
+        << "z="       << z
+        << "dydx="    << dydx
+        << "dzdx="    << dzdx
         << "s2y="     << covR[0]
         << "s2z="     << covR[2]
         << "\n";
@@ -390,39 +391,43 @@ TH1* AliTRDresolution::PlotResolution(const AliTRDtrackV1 *track)
 
     // recalculate tracklet based on the MC info
     AliTRDseedV1 tt(*fTracklet);
-    tt.SetZref(0, z0);
-    tt.SetZref(1, dzdx); 
+    tt.SetZref(0, z0 - (x0-tt.GetX0())*dzdx0);
+    tt.SetZref(1, dzdx0); 
     tt.Fit(kTRUE);
-    x= tt.GetX(); // the true one 
+    x= tt.GetX();y= tt.GetY();z= tt.GetZ();
+    dydx = tt.GetYfit(1);
     dx = x0 - x;
-    yt = y0 - dx*dydx;
+    yt = y0 - dx*dydx0;
+    zt = z0 - dx*dzdx0;
     Bool_t rc = tt.IsRowCross(); 
     
     // add tracklet residuals for y and dydx
-    Float_t yf = tt.GetY();
-    dy = yt - yf; dz = 100.;
-    Float_t dphi   = (tt.GetYfit(1) - dydx);
-    dphi /= 1.- tt.GetYfit(1)*dydx;
-    Double_t s2y = tt.GetS2Y(), s2z = tt.GetS2Z();
     if(!rc){
-      ((TH2I*)fContainer->At(kMCtrackletY))->Fill(dydx, dy);
-      if(s2y>0.) ((TH2I*)fContainer->At(kMCtrackletYPull))->Fill(dydx, dy/TMath::Sqrt(s2y));
-      ((TH2I*)fContainer->At(kMCtrackletPhi))->Fill(dydx, dphi*TMath::RadToDeg());
+      dy    = yt-y;
+
+      Float_t dphi  = (dydx - dydx0);
+      dphi /= 1.- dydx*dydx0;
+
+      ((TH2I*)fContainer->At(kMCtrackletY))->Fill(dydx0, dy);
+      if(tt.GetS2Y()>0.) ((TH2I*)fContainer->At(kMCtrackletYPull))->Fill(dydx0, dy/TMath::Sqrt(tt.GetS2Y()));
+      ((TH2I*)fContainer->At(kMCtrackletPhi))->Fill(dydx0, dphi*TMath::RadToDeg());
     } else {
       // add tracklet residuals for z
-      dz = tt.GetZ() - (z0 - dx*dzdx) ;
-      ((TH2I*)fContainer->At(kMCtrackletZ))->Fill(dzdx, dz);
-      if(s2z>0.) ((TH2I*)fContainer->At(kMCtrackletZPull))->Fill(dzdx, dz/TMath::Sqrt(s2z));
+      dz = zt-z;
+      ((TH2I*)fContainer->At(kMCtrackletZ))->Fill(dzdx0, dz);
+      if(tt.GetS2Z()>0.) ((TH2I*)fContainer->At(kMCtrackletZPull))->Fill(dzdx0, dz/TMath::Sqrt(tt.GetS2Z()));
     }
   
     // Fill Debug stream for tracklet
     if(fDebugLevel>=1){
+      Float_t s2y = tt.GetS2Y();
+      Float_t s2z = tt.GetS2Z();
       (*fDebugStream) << "MCtracklet"
         << "rc="    << rc
         << "x="     << x
-        << "dy="    << dy
-        << "dz="    << dz
-        << "dphi="  << dphi
+        << "y="     << y
+        << "z="     << z
+        << "dydx="  << dydx
         << "s2y="   << s2y
         << "s2z="   << s2z
         << "\n";
@@ -437,18 +442,16 @@ TH1* AliTRDresolution::PlotResolution(const AliTRDtrackV1 *track)
     fTracklet->ResetClusterIter(kFALSE);
     while((c = fTracklet->PrevCluster())){
       Float_t  q = TMath::Abs(c->GetQ());
-      //AliTRDseedV1::GetClusterXY(c,x,y);
-      x = c->GetX(); y = c->GetY(); z = c->GetZ();
-      Float_t xc = x;
-      Float_t yc = y;
-      Float_t zc = z;
-      dx = x0 - xc; 
-      yt = y0 - dx*dydx;
-      zt = z0 - dx*dzdx;
-      dy = yt - (yc - tilt*(zc-zt));
+      AliTRDseedV1::GetClusterXY(c,x,y);
+      //x = c->GetX(); y = c->GetY();
+      z = c->GetZ();
+      dx = x0 - x; 
+      yt = y0 - dx*dydx0;
+      zt = z0 - dx*dzdx0;
+      dy = yt - (y - tilt*(z-zt));
 
       // Fill Histograms
-      if(q>20. && q<250.) ((TH2I*)fContainer->At(kMCcluster))->Fill(dydx, dy);
+      if(q>20. && q<250.) ((TH2I*)fContainer->At(kMCcluster))->Fill(dydx0, dy);
 
       // Fill calibration container
       Float_t d = zr0 - zt;
@@ -458,7 +461,7 @@ TH1* AliTRDresolution::PlotResolution(const AliTRDtrackV1 *track)
       fMCcl->Add(clInfo);
       clInfo->SetCluster(c);
       clInfo->SetMC(pdg, label);
-      clInfo->SetGlobalPosition(yt, zt, dydx, dzdx);
+      clInfo->SetGlobalPosition(yt, zt, dydx0, dzdx0);
       clInfo->SetResolution(dy);
       clInfo->SetAnisochronity(d);
       clInfo->SetDriftLength(dx-.5*AliTRDgeometry::CamHght());
@@ -491,7 +494,7 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
     ax = g->GetHistogram()->GetYaxis();
     y[0] = -0.5; y[1] = 2.5;
     ax->SetRangeUser(y[0], y[1]);
-    ax->SetTitle("Cluster-Track Pools #sigma/#mu [mm]");
+    ax->SetTitle("Cluster-Track Pulls #sigma/#mu [mm]");
     ax = g->GetHistogram()->GetXaxis();
     ax->SetTitle("tg(#phi)");
     if(!(g = (TGraphErrors*)fGraphM->At(ifig))) break;
@@ -505,7 +508,7 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
     g->Draw("apl");
     ax = g->GetHistogram()->GetYaxis();
     ax->SetRangeUser(-.5, 3.);
-    ax->SetTitle("Tracklet-Track Y-Pools #sigma/#mu [mm]");
+    ax->SetTitle("Tracklet-Track Y-Pulls #sigma/#mu [mm]");
     ax = g->GetHistogram()->GetXaxis();
     ax->SetTitle("tg(#phi)");
     if(!(g = (TGraphErrors*)fGraphM->At(ifig))) break;
@@ -531,9 +534,9 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
   case kMCcluster:
     if(!(g = (TGraphErrors*)fGraphS->At(ifig))) break;
     ax = g->GetHistogram()->GetYaxis();
-    y[0] = -.05; y[1] = 0.6;
+    y[0] = -50.; y[1] = 600.;
     ax->SetRangeUser(y[0], y[1]);
-    ax->SetTitle("Y_{cluster} #sigma/#mu [mm]");
+    ax->SetTitle("Y_{cluster} #sigma/#mu [#mum]");
     ax = g->GetHistogram()->GetXaxis();
     ax->SetRangeUser(-.3, .3);
     ax->SetTitle("tg(#phi)");
@@ -547,9 +550,9 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
   case kMCtrackletY:
     if(!(g = (TGraphErrors*)fGraphS->At(ifig))) break;
     ax = g->GetHistogram()->GetYaxis();
-    y[0] = -.05; y[1] = 0.25;
+    y[0] = -50.; y[1] = 250.;
     ax->SetRangeUser(y[0], y[1]);
-    ax->SetTitle("Y_{tracklet} #sigma/#mu [mm]");
+    ax->SetTitle("Y_{tracklet} #sigma/#mu [#mum]");
     ax = g->GetHistogram()->GetXaxis();
     ax->SetRangeUser(-.2, .2);
     ax->SetTitle("tg(#phi)");
@@ -563,8 +566,8 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
   case kMCtrackletZ:
     if(!(g = (TGraphErrors*)fGraphS->At(ifig))) break;
     ax = g->GetHistogram()->GetYaxis();
-    ax->SetRangeUser(-.5, 1.);
-    ax->SetTitle("Z_{tracklet} #sigma/#mu [mm]");
+    ax->SetRangeUser(-50., 700.);
+    ax->SetTitle("Z_{tracklet} #sigma/#mu [#mum]");
     ax = g->GetHistogram()->GetXaxis();
     ax->SetTitle("tg(#theta)");
     g->Draw("apl");
@@ -586,9 +589,9 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
   case kMCtrackY:
     if(!(g = (TGraphErrors*)fGraphS->At(ifig))) break;
     ax = g->GetHistogram()->GetYaxis();
-    y[0] = -.05; y[1] = 0.25;
+    y[0] = -50.; y[1] = 200.;
     ax->SetRangeUser(y[0], y[1]);
-    ax->SetTitle("Y_{track} #sigma/#mu [mm]");
+    ax->SetTitle("Y_{track} #sigma/#mu [#mum]");
     ax = g->GetHistogram()->GetXaxis();
     ax->SetRangeUser(-.2, .2);
     ax->SetTitle("tg(#phi)");
@@ -600,10 +603,11 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
     b->SetLineColor(0); b->Draw();
     return kTRUE;
   case kMCtrackZIn:
+  case kMCtrackZOut:
     if(!(g = (TGraphErrors*)fGraphS->At(ifig))) break;
     ax = g->GetHistogram()->GetYaxis();
-    ax->SetRangeUser(-.5, 2.);
-    ax->SetTitle("Z_{track} #sigma/#mu [mm]");
+    ax->SetRangeUser(-500., 2000.);
+    ax->SetTitle(Form("Z_{track}^{%s} #sigma/#mu [#mum]", ifig==kMCtrackZIn ? "in" : "out"));
     ax = g->GetHistogram()->GetXaxis();
     ax->SetTitle("tg(#theta)");
     g->Draw("apl");
@@ -621,6 +625,19 @@ Bool_t AliTRDresolution::GetRefFigure(Int_t ifig)
     if(!(g = (TGraphErrors*)fGraphM->At(ifig))) break;
     g->Draw("pl");
     return kTRUE;
+  case kMCtrackletYPull:
+  case kMCtrackletZPull:
+  case kMCtrackYPull:
+  case kMCtrackZInPull:
+  case kMCtrackZOutPull:
+    if(!(g = (TGraphErrors*)fGraphS->At(ifig))) break;
+    ax = g->GetHistogram()->GetYaxis();
+    ax->SetRangeUser(-.5, 2.);
+    ax->SetTitle("MC Pulls");
+    g->Draw("apl");
+    if(!(g = (TGraphErrors*)fGraphM->At(ifig))) break;
+    g->Draw("pl");
+    return kTRUE;
   }
   AliInfo(Form("Reference plot [%d] missing result", ifig));
   return kFALSE;
@@ -636,7 +653,7 @@ Bool_t AliTRDresolution::PostProcess()
     return kFALSE;
   }
   fNRefFigures = fContainer->GetEntriesFast();
-  TGraphErrors *gm = 0x0, *gs = 0x0;
+  TGraphErrors *gm= 0x0, *gs= 0x0;
   if(!fGraphS){ 
     fGraphS = new TObjArray(fNRefFigures);
     fGraphS->SetOwner();
@@ -662,224 +679,55 @@ Bool_t AliTRDresolution::PostProcess()
     }
   }
 
-  TH2I *h2 = 0x0;
-  TH1D *h = 0x0;
-
-  // define models
+  // DEFINE MODELS
+  // simple gauss
   TF1 f("f1", "gaus", -.5, .5);  
-
+  // gauss on a constant background
   TF1 fb("fb", "[0]*exp(-0.5*((x-[1])/[2])**2)+[3]", -.5, .5);
-
+  // gauss on a gauss background
   TF1 fc("fc", "[0]*exp(-0.5*((x-[1])/[2])**2)+[3]*exp(-0.5*((x-[4])/[5])**2)", -.5, .5);
 
-  TCanvas *c = 0x0;
-  if(IsVisual()) c = new TCanvas("c", Form("%s Visual", GetName()), 500, 500);
-  char opt[5];
-  sprintf(opt, "%c%c", IsVerbose() ? ' ' : 'Q', IsVisual() ? ' ': 'N');
 
-
-  //PROCESS RESIDUAL DISTRIBUTIONS
+  //PROCESS EXPERIMENTAL DISTRIBUTIONS
 
   // Clusters residuals
-  h2 = (TH2I *)(fContainer->At(kCluster));
-  gm = (TGraphErrors*)fGraphM->At(kCluster);
-  gs = (TGraphErrors*)fGraphS->At(kCluster);
-  for(Int_t ibin = 1; ibin <= h2->GetNbinsX(); ibin++){
-    Double_t phi = h2->GetXaxis()->GetBinCenter(ibin);
-    h = h2->ProjectionY("py", ibin, ibin);
-    if(h->GetEntries()<100) continue;
-    AdjustF1(h, &f);
-
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&f, opt, "", -0.5, 0.5);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
-    
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, 10.*f.GetParameter(1));
-    gm->SetPointError(ip, 0., 10.*f.GetParError(1));
-    gs->SetPoint(ip, phi, 10.*f.GetParameter(2));
-    gs->SetPointError(ip, 0., 10.*f.GetParError(2));
-  }
+  Process(kCluster, &f);
 
   // Tracklet y residuals
-  h2 = (TH2I *)(fContainer->At(kTrackletY));
-  gm = (TGraphErrors*)fGraphM->At(kTrackletY);
-  gs = (TGraphErrors*)fGraphS->At(kTrackletY);
-  for(Int_t ibin = 1; ibin <= h2->GetNbinsX(); ibin++){
-    Double_t phi = h2->GetXaxis()->GetBinCenter(ibin);
-    h = h2->ProjectionY("py", ibin, ibin);
-    if(h->GetEntries()<100) continue;
-    AdjustF1(h, &f);
-
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&f, opt, "", -0.5, 0.5);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
-    
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, 10.*f.GetParameter(1));
-    gm->SetPointError(ip, 0., 10.*f.GetParError(1));
-    gs->SetPoint(ip, phi, 10.*f.GetParameter(2));
-    gs->SetPointError(ip, 0., 10.*f.GetParError(2));
-  }
+  Process(kTrackletY, &f);
 
   // Tracklet phi residuals
-  h2 = (TH2I *)(fContainer->At(kTrackletPhi));
-  gm = (TGraphErrors*)fGraphM->At(kTrackletPhi);
-  gs = (TGraphErrors*)fGraphS->At(kTrackletPhi);
-  for(Int_t ibin = 1; ibin <= h2->GetNbinsX(); ibin++){
-    Double_t phi = h2->GetXaxis()->GetBinCenter(ibin);
-    h = h2->ProjectionY("py", ibin, ibin);
-    if(h->GetEntries()<100) continue;
-    AdjustF1(h, &f);
+  Process(kTrackletPhi, &f);
 
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&f, opt, "", -0.5, 0.5);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
-    
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, 10.*f.GetParameter(1));
-    gm->SetPointError(ip, 0., 10.*f.GetParError(1));
-    gs->SetPoint(ip, phi, 10.*f.GetParameter(2));
-    gs->SetPointError(ip, 0., 10.*f.GetParError(2));
-  }
+  if(!HasMCdata()) return kTRUE;
 
-  if(!HasMCdata()){
-    if(c) delete c;
-    return kTRUE;
-  }
 
   //PROCESS MC RESIDUAL DISTRIBUTIONS
 
   // cluster y resolution
-  h2 = (TH2I*)fContainer->At(kMCcluster);
-  gm = (TGraphErrors*)fGraphM->At(kMCcluster);
-  gs = (TGraphErrors*)fGraphS->At(kMCcluster);
-  for(Int_t iphi=1; iphi<=h2->GetNbinsX(); iphi++){
-    h = h2->ProjectionY("py", iphi, iphi);
-    if(h->GetEntries()<100) continue;
-    AdjustF1(h, &f);
-
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&f, opt, "", -0.5, 0.5);
-    if(IsVerbose()){
-      printf("phi[%d] mean[%e] sigma[%e]\n\n", iphi, 10.*f.GetParameter(1), 10.*f.GetParameter(2));
-    }
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
+  Process(kMCcluster, &f, 1.e4);
 
-    Double_t phi = h2->GetXaxis()->GetBinCenter(iphi);
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, 10.*f.GetParameter(1));
-    gm->SetPointError(ip, 0., 10.*f.GetParError(1));
-    gs->SetPoint(ip, phi, 10.*f.GetParameter(2));
-    gs->SetPointError(ip, 0., 10.*f.GetParError(2));
-  }
-
-  // tracklet y resolution
-  h2 = (TH2I*)fContainer->At(kMCtrackletY);
-  gm = (TGraphErrors*)fGraphM->At(kMCtrackletY);
-  gs = (TGraphErrors*)fGraphS->At(kMCtrackletY);
-  for(Int_t iphi=1; iphi<=h2->GetNbinsX(); iphi++){
-    h = h2->ProjectionY("py", iphi, iphi);
-    if(h->GetEntries()<100) continue;
-    AdjustF1(h, &f);
-
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&f, opt, "", -0.5, 0.5);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
-
-    Double_t phi = h2->GetXaxis()->GetBinCenter(iphi);
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, 10.*f.GetParameter(1));
-    gm->SetPointError(ip, 0., 10.*f.GetParError(1));
-    gs->SetPoint(ip, phi, 10.*f.GetParameter(2));
-    gs->SetPointError(ip, 0., 10.*f.GetParError(2));
-  }
-
-  // tracklet z resolution
-  h2 = (TH2I*)fContainer->At(kMCtrackletZ);
-  gm = (TGraphErrors*)fGraphM->At(kMCtrackletZ);
-  gs = (TGraphErrors*)fGraphS->At(kMCtrackletZ);
-  for(Int_t iphi=1; iphi<=h2->GetNbinsX(); iphi++){
-    h = h2->ProjectionY("py", iphi, iphi);
-    if(h->GetEntries()<100) continue;
-    AdjustF1(h, &fb);
-
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&fb, opt, "", -0.5, 0.5);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
-
-    Double_t phi = h2->GetXaxis()->GetBinCenter(iphi);
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, 10.*fb.GetParameter(1));
-    gm->SetPointError(ip, 0., 10.*fb.GetParError(1));
-    gs->SetPoint(ip, phi, 10.*fb.GetParameter(2));
-    gs->SetPointError(ip, 0., 10.*fb.GetParError(2));
-  }
-
-  //tracklet phi resolution
-  h2 = (TH2I*)fContainer->At(kMCtrackletPhi);
-  gm = (TGraphErrors*)fGraphM->At(kMCtrackletPhi);
-  gs = (TGraphErrors*)fGraphS->At(kMCtrackletPhi);
-  for(Int_t iphi=1; iphi<=h2->GetNbinsX(); iphi++){
-    h = h2->ProjectionY("py", iphi, iphi);
-    if(h->GetEntries()<100) continue;
-
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&f, opt, "", -0.5, 0.5);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
-
-    Double_t phi = h2->GetXaxis()->GetBinCenter(iphi);
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, f.GetParameter(1));
-    gm->SetPointError(ip, 0., f.GetParError(1));
-    gs->SetPoint(ip, phi, f.GetParameter(2));
-    gs->SetPointError(ip, 0., f.GetParError(2));
-  }
-
-  // track y resolution
-  h2 = (TH2I*)fContainer->At(kMCtrackY);
-  gm = (TGraphErrors*)fGraphM->At(kMCtrackY);
-  gs = (TGraphErrors*)fGraphS->At(kMCtrackY);
-  for(Int_t iphi=1; iphi<=h2->GetNbinsX(); iphi++){
-    h = h2->ProjectionY("py", iphi, iphi);
-    if(h->GetEntries()<100) continue;
-    AdjustF1(h, &f);
-
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&f, opt, "", -0.5, 0.5);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
+  // tracklet resolution
+  Process(kMCtrackletY, &f, 1.e4); // y
+  Process(kMCtrackletZ, &f, 1.e4); // z
+  Process(kMCtrackletPhi, &f); // phi
 
-    Double_t phi = h2->GetXaxis()->GetBinCenter(iphi);
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, 10.*f.GetParameter(1));
-    gm->SetPointError(ip, 0., 10.*f.GetParError(1));
-    gs->SetPoint(ip, phi, 10.*f.GetParameter(2));
-    gs->SetPointError(ip, 0., 10.*f.GetParError(2));
-  }
-
-  // track z resolution
-  h2 = (TH2I*)fContainer->At(kMCtrackZIn);
-  gm = (TGraphErrors*)fGraphM->At(kMCtrackZIn);
-  gs = (TGraphErrors*)fGraphS->At(kMCtrackZIn);
-  for(Int_t iphi=1; iphi<=h2->GetNbinsX(); iphi++){
-    h = h2->ProjectionY("pz", iphi, iphi);
-    if(h->GetEntries()<70) continue;
-    AdjustF1(h, &f);
+  // tracklet pulls
+  Process(kMCtrackletYPull, &f); // y
+  Process(kMCtrackletZPull, &f); // z
 
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&f, opt, "", -0.5, 0.5);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
+  // track resolution
+  Process(kMCtrackY, &f, 1.e4);    // y
+  Process(kMCtrackZIn, &f, 1.e4);  // z towards TPC
+  Process(kMCtrackZOut, &f, 1.e4); // z towards TOF
 
-    Double_t phi = h2->GetXaxis()->GetBinCenter(iphi);
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, phi, 10.*f.GetParameter(1));
-    gm->SetPointError(ip, 0., 10.*f.GetParError(1));
-    gs->SetPoint(ip, phi, 10.*f.GetParameter(2));
-    gs->SetPointError(ip, 0., 10.*f.GetParError(2));
-  }
+  // track pulls
+  Process(kMCtrackYPull, &f);    // y
+  Process(kMCtrackZInPull, &f);  // z towards TPC
+  Process(kMCtrackZOutPull, &f); // z towards TOF
 
   // track Pt resolution
-  h2 = (TH2I*)fContainer->At(kMCtrackPt);
+  TH2I *h2 = (TH2I*)fContainer->At(kMCtrackPt);
   TAxis *ax = h2->GetXaxis();
   gm = (TGraphErrors*)fGraphM->At(kMCtrackPt);
   gs = (TGraphErrors*)fGraphS->At(kMCtrackPt);
@@ -887,7 +735,7 @@ Bool_t AliTRDresolution::PostProcess()
   TF1 fl("fl", "landau", -4., 15.);
   TF1 fgl("fgl", "gaus(0)+landau(3)", -5., 20.);
   for(Int_t ip=1; ip<=ax->GetNbins(); ip++){
-    h = h2->ProjectionY("ppt", ip, ip);
+    TH1D *h = h2->ProjectionY("ppt", ip, ip);
     if(h->GetEntries()<70) continue;
 
     h->Fit(&fg, "QN", "", -1.5, 1.5);
@@ -899,22 +747,19 @@ Bool_t AliTRDresolution::PostProcess()
     fgl.SetParameter(4, fl.GetParameter(1));
     fgl.SetParameter(5, fl.GetParameter(2));
 
-    if(IsVisual()){c->cd(); c->SetLogy();}
-    h->Fit(&fgl, opt, "", -5., 20.);
-    if(IsVisual()){c->Modified(); c->Update(); gSystem->Sleep(500);}
+    h->Fit(&fgl, "NQ", "", -5., 20.);
 
     Float_t invpt = ax->GetBinCenter(ip);
-    Int_t ip = gm->GetN();
-    gm->SetPoint(ip, invpt, fgl.GetParameter(1));
-    gm->SetPointError(ip, 0., fgl.GetParError(1));
-    gs->SetPoint(ip, invpt, fgl.GetParameter(2)*invpt);
-    gs->SetPointError(ip, 0., fgl.GetParError(2));
+    Int_t jp = gm->GetN();
+    gm->SetPoint(jp, invpt, fgl.GetParameter(1));
+    gm->SetPointError(jp, 0., fgl.GetParError(1));
+    gs->SetPoint(jp, invpt, fgl.GetParameter(2)*invpt);
+    gs->SetPointError(jp, 0., fgl.GetParError(2));
     // fgl.GetParameter(4) // Landau MPV
     // fgl.GetParameter(5) // Landau Sigma
   }
 
 
-  if(c) delete c;
   return kTRUE;
 }
 
@@ -1011,7 +856,7 @@ TObjArray* AliTRDresolution::Histos()
 
   // tracklet y resolution [0]
   if(!(h = (TH2I*)gROOT->FindObject("hMCtrkltY"))){
-    h = new TH2I("hMCtrkltY", "Tracklet Resolution (Y)", 31, -.48, .48, 100, -.5, .5);
+    h = new TH2I("hMCtrkltY", "Tracklet Resolution (Y)", 31, -.48, .48, 100, -.2, .2);
     h->GetXaxis()->SetTitle("tg(#phi)");
     h->GetYaxis()->SetTitle("#Delta y [cm]");
     h->GetZaxis()->SetTitle("entries");
@@ -1038,7 +883,7 @@ TObjArray* AliTRDresolution::Histos()
 
   // tracklet y resolution [0]
   if(!(h = (TH2I*)gROOT->FindObject("hMCtrkltZPull"))){
-    h = new TH2I("hMCtrkltZ", "Tracklet Pulls (Z)", 31, -.48, .48, 100, -3.5, 3.5);
+    h = new TH2I("hMCtrkltZPull", "Tracklet Pulls (Z)", 31, -.48, .48, 100, -3.5, 3.5);
     h->GetXaxis()->SetTitle("tg(#theta)");
     h->GetYaxis()->SetTitle("#Delta z / #sigma_{z}");
     h->GetZaxis()->SetTitle("entries");
@@ -1056,7 +901,7 @@ TObjArray* AliTRDresolution::Histos()
 
   // Kalman track y resolution
   if(!(h = (TH2I*)gROOT->FindObject("hMCtrkY"))){
-    h = new TH2I("hMCtrkY", "Kalman Track Resolution (Y)", 31, -.48, .48, 100, -.5, .5);
+    h = new TH2I("hMCtrkY", "Kalman Track Resolution (Y)", 31, -.48, .48, 100, -.2, .2);
     h->GetXaxis()->SetTitle("tg(#phi)");
     h->GetYaxis()->SetTitle("#Delta y [cm]");
     h->GetZaxis()->SetTitle("entries");
@@ -1074,7 +919,7 @@ TObjArray* AliTRDresolution::Histos()
 
   // Kalman track Z resolution
   if(!(h = (TH2I*)gROOT->FindObject("hMCtrkZIn"))){
-    h = new TH2I("hMCtrkZIn", "Kalman Track Resolution (Zin)", 20, -1., 1., 100, -1.5, 1.5);
+    h = new TH2I("hMCtrkZIn", "Kalman Track Resolution (Zin)", 20, -1., 1., 100, -1., 1.);
     h->GetXaxis()->SetTitle("tg(#theta)");
     h->GetYaxis()->SetTitle("#Delta z [cm]");
     h->GetZaxis()->SetTitle("entries");
@@ -1083,7 +928,7 @@ TObjArray* AliTRDresolution::Histos()
 
   // Kalman track Z resolution
   if(!(h = (TH2I*)gROOT->FindObject("hMCtrkZOut"))){
-    h = new TH2I("hMCtrkZOut", "Kalman Track Resolution (Zout)", 20, -1., 1., 100, -1.5, 1.5);
+    h = new TH2I("hMCtrkZOut", "Kalman Track Resolution (Zout)", 20, -1., 1., 100, -1., 1.);
     h->GetXaxis()->SetTitle("tg(#theta)");
     h->GetYaxis()->SetTitle("#Delta z [cm]");
     h->GetZaxis()->SetTitle("entries");
@@ -1121,6 +966,43 @@ TObjArray* AliTRDresolution::Histos()
 }
 
 
+//________________________________________________________
+Bool_t AliTRDresolution::Process(ETRDresolutionPlot plot, TF1 *f, Float_t k)
+{
+  if(!fContainer || !fGraphS || !fGraphM) return kFALSE;
+  Bool_t kBUILD = kFALSE;
+  if(!f){ 
+    f = new TF1("f1", "gaus", -.5, .5);
+    kBUILD = kTRUE;
+  }
+
+  TH2I *h2 = 0x0;
+  if(!(h2 = (TH2I *)(fContainer->At(plot)))) return kFALSE;
+  TGraphErrors *gm = 0x0, *gs = 0x0;
+  if(!(gm=(TGraphErrors*)fGraphM->At(plot))) return kFALSE;
+  if(gm->GetN()) for(Int_t ip=gm->GetN(); ip--;) gm->RemovePoint(ip);
+  if(!(gs=(TGraphErrors*)fGraphS->At(plot))) return kFALSE;
+  if(gs->GetN()) for(Int_t ip=gs->GetN(); ip--;) gs->RemovePoint(ip);
+  Char_t pn[10]; sprintf(pn, "p%02d", plot);
+  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);
+
+    h->Fit(f, "QN");
+    
+    Int_t ip = gm->GetN();
+    gm->SetPoint(ip, x, k*f->GetParameter(1));
+    gm->SetPointError(ip, 0., k*f->GetParError(1));
+    gs->SetPoint(ip, x, k*f->GetParameter(2));
+    gs->SetPointError(ip, 0., k*f->GetParError(2));
+  }
+
+  if(kBUILD) delete f;
+  return kTRUE;
+}
+
 //________________________________________________________
 void AliTRDresolution::SetRecoParam(AliTRDrecoParam *r)
 {