]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG1/AliComparisonRes.cxx
Removed obsolete classes
[u/mrichter/AliRoot.git] / PWG1 / AliComparisonRes.cxx
index 70593fe8a931f7b47d948a682ddc6a729a846a21..61ce53a54f68017be6a85cae26bbc9430688c261 100644 (file)
@@ -4,54 +4,50 @@
 // it keeps selection cuts used during comparison. The comparison 
 // information is stored in the ROOT histograms. Analysis of these 
 // histograms can be done by using Analyse() class function. The result of 
-// the analysis (histograms) are stored in the output picture_res.root file.
-//  
+// the analysis (histograms/graphs) are stored in the folder which is
+// a data member of AliComparisonRes.
+//
 // Author: J.Otwinowski 04/02/2008 
 //------------------------------------------------------------------------------
 
 /*
-  //after running analysis, read the file, and get component
-  gSystem->Load("libPWG1.so");
+  // after running comparison task, read the file, and get component
+  gROOT->LoadMacro("$ALICE_ROOT/PWG1/Macros/LoadMyLibs.C");
+  LoadMyLibs();
+
   TFile f("Output.root");
-  AliComparisonRes * comp = (AliComparisonRes*)f.Get("AliComparisonRes");
+  //AliComparisonRes * compObj = (AliComparisonRes*)f.Get("AliComparisonRes");
+  AliComparisonRes * compObj = (AliComparisonRes*)cOutput->FindObject("AliComparisonRes");
+  // analyse comparison data
+  compObj->Analyse();
 
-  // analyse comparison data (output stored in pictures_res.root)
-  comp->Analyse();
-  
-  // paramtetrisation of the TPC track length (for information only) 
-  TF1 fl("fl","((min(250./(abs(x+0.000001)),250)-90))",0,2);  // TPC track length function
-  TF1 fl2("fl2","[0]/((min(250./(abs(x+0.000001)),250)-90))^[1]",0,2);
-  fl2.SetParameter(1,1);
-  fl2.SetParameter(0,1);
-*/
+  // the output histograms/graphs will be stored in the folder "folderRes" 
+  compObj->GetAnalysisFolder()->ls("*");
 
-#include <iostream>
+  // user can save whole comparison object (or only folder with anlysed histograms) 
+  // in the seperate output file (e.g.)
+  TFile fout("Analysed_Res.root","recreate");
+  compObj->Write(); // compObj->GetAnalysisFolder()->Write();
+  fout.Close();
+
+*/
 
-#include "TFile.h"
-#include "TCint.h"
-#include "TH3F.h"
-#include "TH2F.h"
-#include "TF1.h"
-#include "TProfile.h"
-#include "TProfile2D.h"
-#include "TGraph2D.h"
 #include "TCanvas.h"
-#include "TGraph.h"
+#include "TH1.h"
+#include "TAxis.h"
 
-#include "AliESDEvent.h"   
-#include "AliESD.h"
-#include "AliESDfriend.h"
-#include "AliESDfriendTrack.h"
-#include "AliRecInfoCuts.h" 
-#include "AliMCInfoCuts.h" 
+#include "AliComparisonRes.h" 
+#include "AliESDRecInfo.h" 
+#include "AliESDVertex.h"
+#include "AliESDtrack.h"
 #include "AliLog.h" 
-
-#include "AliMathBase.h"
-#include "AliTreeDraw.h" 
-
 #include "AliMCInfo.h" 
-#include "AliESDRecInfo.h" 
-#include "AliComparisonRes.h" 
+#include "AliMCInfoCuts.h" 
+#include "AliRecInfoCuts.h" 
+#include "AliTracker.h" 
+#include "AliTreeDraw.h" 
 
 using namespace std;
 
@@ -59,246 +55,357 @@ ClassImp(AliComparisonRes)
 
 //_____________________________________________________________________________
 AliComparisonRes::AliComparisonRes():
-  TNamed("AliComparisonRes","AliComparisonRes"),
+  AliComparisonObject("AliComparisonRes"),
+  fResolHisto(0),
+  fPullHisto(0),
 
-  // Resolution 
-  fPtResolLPT(0),        // pt resolution - low pt
-  fPtResolHPT(0),        // pt resolution - high pt 
-  fPtPullLPT(0),         // pt resolution - low pt
-  fPtPullHPT(0),         // pt resolution - high pt 
-  //
-  // Resolution constrained param
-  //
-  fCPhiResolTan(0),  // angular resolution -  constrained
-  fCTanResolTan(0),  // angular resolution -  constrained
-  fCPtResolTan(0),   // pt resolution      -  constrained
-  fCPhiPullTan(0),   // angular resolution -  constrained
-  fCTanPullTan(0),   // angular resolution -  constrained
-  fCPtPullTan(0),    // pt resolution      -  constrained
   // Cuts 
   fCutsRC(0),  
-  fCutsMC(0)  
-{
-  InitHisto();
-  InitCuts();
-}
+  fCutsMC(0),  
 
-//_____________________________________________________________________________
-AliComparisonRes::~AliComparisonRes(){
-  
-  // Resolution histograms
-  if(fPtResolLPT) delete  fPtResolLPT; fPtResolLPT=0;     
-  if(fPtResolHPT) delete  fPtResolHPT; fPtResolHPT=0;    
-  if(fPtPullLPT)  delete  fPtPullLPT;  fPtPullLPT=0;    
-  if(fPtPullHPT)  delete  fPtPullHPT;  fPtPullHPT=0;   
-
-  // Resolution histograms (constrained param)
-  if(fCPhiResolTan) delete fCPhiResolTan; fCPhiResolTan=0;
-  if(fCTanResolTan) delete fCTanResolTan; fCTanResolTan=0;
-  if(fCPtResolTan)  delete fCPtResolTan;  fCPtResolTan=0; 
-  if(fCPhiPullTan)  delete fCPhiPullTan;  fCPhiPullTan=0;
-  if(fCTanPullTan)  delete fCTanPullTan;  fCTanPullTan=0;
-  if(fCPtPullTan)   delete fCPtPullTan;   fCPtPullTan=0;
+  // histogram folder 
+  fAnalysisFolder(0)
+{
+  //Init();
 }
 
 //_____________________________________________________________________________
-void AliComparisonRes::InitHisto(){
+AliComparisonRes::AliComparisonRes(Char_t* name="AliComparisonRes", Char_t* title="AliComparisonRes",Int_t analysisMode=0,Bool_t hptGenerator=kFALSE):
+//AliComparisonRes::AliComparisonRes(Char_t* name, Char_t* title,Int_t analysisMode,Bool_t hptGenerator):
+  AliComparisonObject(name,title),
+  fResolHisto(0),
+  fPullHisto(0),
 
-  // Init histograms
-  fCPhiResolTan = new TH2F("CPhiResolTan","CPhiResolTan",50, -2,2,200,-0.025,0.025);   
-  fCPhiResolTan->SetXTitle("tan(#theta)");
-  fCPhiResolTan->SetYTitle("#Delta#phi");
+  // Cuts 
+  fCutsRC(0),  
+  fCutsMC(0),  
 
-  fCTanResolTan = new TH2F("CTanResolTan","CTanResolTan",50, -2,2,200,-0.025,0.025);
-  fCTanResolTan->SetXTitle("tan(#theta)");
-  fCTanResolTan->SetYTitle("#Delta#theta");
+  // histogram folder 
+  fAnalysisFolder(0)
+{
+  // named constructor 
+  // 
+  SetAnalysisMode(analysisMode);
+  SetHptGenerator(hptGenerator);
 
-  fCPtResolTan=new TH2F("CPtResol","CPtResol",50, -2,2,200,-0.2,0.2);    
-  fCPtResolTan->SetXTitle("Tan(#theta)");
-  fCPtResolTan->SetYTitle("#Deltap_{t}/p_{t}");
+  Init();
+}
 
-  fCPhiPullTan = new TH2F("CPhiPullTan","CPhiPullTan",50, -2,2,200,-5,5);   
-  fCPhiPullTan->SetXTitle("Tan(#theta)");
-  fCPhiPullTan->SetYTitle("#Delta#phi/#Sigma");
+//_____________________________________________________________________________
+AliComparisonRes::~AliComparisonRes()
+{
+  // destructor
+   
+  if(fResolHisto) delete fResolHisto; fResolHisto=0;     
+  if(fPullHisto)  delete fPullHisto;  fPullHisto=0;     
 
-  fCTanPullTan = new TH2F("CTanPullTan","CTanPullTan",50, -2,2,200,-5,5);
-  fCTanPullTan->SetXTitle("Tan(#theta)");
-  fCTanPullTan->SetYTitle("#Delta#theta/#Sigma");
+  if(fCutsRC) delete fCutsRC; fCutsRC=0;
+  if(fCutsMC) delete fCutsMC; fCutsMC=0;
 
-  fCPtPullTan=new TH2F("CPtPull","CPtPull",50, -2,2,200,-5,5);    
-  fCPtPullTan->SetXTitle("Tan(#theta)");
-  fCPtPullTan->SetYTitle("(1/mcp_{t}-1/p_{t})/#Sigma");
+  if(fAnalysisFolder) delete fAnalysisFolder; fAnalysisFolder=0;
+}
 
-  fPtResolLPT = new TH2F("Pt_resol_lpt","pt resol",10, 0.1,3,200,-0.2,0.2);
-  fPtResolLPT->SetXTitle("p_{t}");
-  fPtResolLPT->SetYTitle("#Deltap_{t}/p_{t}");
+//_____________________________________________________________________________
+void AliComparisonRes::Init(){
 
-  fPtResolHPT = new TH2F("Pt_resol_hpt","pt resol",10, 2,100,200,-0.3,0.3);  
-  fPtResolHPT->SetXTitle("p_{t}");
-  fPtResolHPT->SetYTitle("#Deltap_{t}/p_{t}");
+  //
+  // histogram bining
+  //
 
-  fPtPullLPT = new TH2F("Pt_pull_lpt","pt pool",10, 0.1,3,200,-6,6);
-  fPtPullLPT->SetXTitle("p_{t}");
-  fPtPullLPT->SetYTitle("#Deltap_{t}/#Sigma");
+  // set pt bins
+   Int_t nPtBins = 31;
+   Double_t binsPt[32] = {0.,0.05,0.1,0.15,0.2,0.25,0.3,0.35,0.4,0.45,0.5,0.55,0.6,0.7,0.8,0.9,1.0,1.2,1.4,1.6,1.8,2.0,2.25,2.5,2.75,3.,3.5,4.,5.,6.,8.,10.};
+  Double_t ptMin = 0., ptMax = 10.; 
 
-  fPtPullHPT = new TH2F("Pt_pull_hpt","pt pool",10, 2,100,200,-6,6);  
-  fPtPullHPT->SetXTitle("p_{t}");
-  fPtPullHPT->SetYTitle("#Deltap_{t}/#Sigma");
-}
 
-//_____________________________________________________________________________
-void AliComparisonRes::InitCuts()
-{
-
- /*
-    fCutsRC = new AliRecInfoCuts();
-  if(fCutsRC) {
-    fCutsRC->SetPtRange(0.15,200.0);
-    fCutsRC->SetMaxAbsTanTheta(1.0);
-    fCutsRC->SetMinNClustersTPC(10);
-    fCutsRC->SetMinTPCsignalN(50);
-  } else {
-    AliDebug(AliLog::kError, "ERROR: Cannot create AliRecInfoCuts object");
-    return;
+  if(IsHptGenerator() == kTRUE) {
+    nPtBins = 100;
+    ptMin = 0.; ptMax = 100.; 
   }
 
-  fCutsMC = new AliMCInfoCuts();
-  if(fCutsMC) {
-    fCutsMC->SetMinRowsWithDigits(50);
-    fCutsMC->SetMaxR(0.1);
-    fCutsMC->SetMaxVz(10.);
-    fCutsMC->SetRangeTPCSignal(0.5,1.4);
-  } else {
-  AliDebug(AliLog::kError, "ERROR: Cannot AliMCInfoCuts object");
-  return;
-  }
- */
+  // res_y:res_z:res_phi,res_lambda:res_1pt:y:z:eta:phi:pt
+  Int_t binsResolHisto[10]={100,100,100,100,100,50,100,30,144,nPtBins};
+  Double_t minResolHisto[10]={-1.,-1.,-0.03,-0.03,-0.2,-0.03,-20.,-1.5,0.,ptMin};
+  Double_t maxResolHisto[10]={ 1., 1., 0.03, 0.03, 0.2, 0.03, 20., 1.5,2.*TMath::Pi(), ptMax};
+
+
+  fResolHisto = new THnSparseF("fResolHisto","res_y:res_z:res_phi:res_lambda:res_1pt:y:z:eta:phi:pt",10,binsResolHisto,minResolHisto,maxResolHisto);
+  if(!IsHptGenerator()) fResolHisto->SetBinEdges(9,binsPt);
+
+  fResolHisto->GetAxis(0)->SetTitle("res_y (cm)");
+  fResolHisto->GetAxis(1)->SetTitle("res_z (cm)");
+  fResolHisto->GetAxis(2)->SetTitle("res_phi (rad)");
+  fResolHisto->GetAxis(3)->SetTitle("res_lambda (rad)");
+  fResolHisto->GetAxis(4)->SetTitle("res_1pt (GeV/c)^{-1}");
+  fResolHisto->GetAxis(5)->SetTitle("y (cm)");
+  fResolHisto->GetAxis(6)->SetTitle("z (cm)");
+  fResolHisto->GetAxis(7)->SetTitle("eta");
+  fResolHisto->GetAxis(8)->SetTitle("phi (rad)");
+  fResolHisto->GetAxis(9)->SetTitle("pt (GeV/c)");
+  fResolHisto->Sumw2();
+
+  //pull_y:pull_z:pull_lambda:pull_phi:pull_1pt:y:z:eta:phi:pt
+  Int_t binsPullHisto[10]={100,100,100,100,100,50,100,30,144,nPtBins};
+  Double_t minPullHisto[10]={-5.,-5.,-5.,-5.,-5.,-0.03, -20.,-1.5, 0., ptMin};
+  Double_t maxPullHisto[10]={ 5., 5., 5., 5., 5., 0.03, 20., 1.5, 2.*TMath::Pi(),ptMax};
+
+  fPullHisto = new THnSparseF("fPullHisto","pull_y:pull_z:pull_phi:pull_lambda:pull_1pt:y:z:eta:phi:pt",10,binsPullHisto,minPullHisto,maxPullHisto);
+  if(!IsHptGenerator()) fPullHisto->SetBinEdges(9,binsPt);
+  
+  fPullHisto->GetAxis(0)->SetTitle("res_y (cm)");
+  fPullHisto->GetAxis(1)->SetTitle("res_z (cm)");
+  fPullHisto->GetAxis(2)->SetTitle("res_phi (rad)");
+  fPullHisto->GetAxis(3)->SetTitle("res_lambda (rad)");
+  fPullHisto->GetAxis(4)->SetTitle("res_1pt (GeV/c)^{-1}");
+  fPullHisto->GetAxis(5)->SetTitle("y (rad)");
+  fPullHisto->GetAxis(6)->SetTitle("z (rad)");
+  fPullHisto->GetAxis(7)->SetTitle("eta");
+  fPullHisto->GetAxis(8)->SetTitle("phi (rad)");
+  fPullHisto->GetAxis(9)->SetTitle("pt (GeV/c)");
+  fPullHisto->Sumw2();
+
   // Init cuts 
   if(!fCutsMC) 
     AliDebug(AliLog::kError, "ERROR: Cannot find AliMCInfoCuts object");
   if(!fCutsRC) 
     AliDebug(AliLog::kError, "ERROR: Cannot find AliRecInfoCuts object");
+
+  // init folder
+  fAnalysisFolder = CreateFolder("folderRes","Analysis Resolution Folder");
 }
 
 //_____________________________________________________________________________
-void AliComparisonRes::Process(AliMCInfo* infoMC, AliESDRecInfo *infoRC)
+void AliComparisonRes::ProcessTPC(AliMCInfo* const infoMC, AliESDRecInfo *const infoRC)
 {
   // Fill resolution comparison information 
+  AliExternalTrackParam *track = 0;
+  Double_t field      = AliTracker::GetBz(); // nominal Bz field [kG]
+  Double_t kMaxD      = 123456.0; // max distance
+  AliESDVertex vertexMC;  // MC primary vertex
+
+  Double_t dca[2], cov[3]; // dca_xy, dca_z, sigma_xy, sigma_xy_z, sigma_z
+
+  Float_t delta1PtTPC, deltaYTPC, deltaZTPC, deltaPhiTPC, deltaLambdaTPC; 
+  Float_t pull1PtTPC, pullYTPC, pullZTPC, pullPhiTPC, pullLambdaTPC; 
+  //Float_t delta1Pt2TPC, deltaY1PtTPC, deltaZ1PtTPC, deltaPhi1PtTPC, deltaTheta1PtTPC; 
 
+  Float_t mceta =  infoMC->GetParticle().Eta();
+  Float_t mcphi =  infoMC->GetParticle().Phi();
+  if(mcphi<0) mcphi += 2.*TMath::Pi();
   Float_t mcpt = infoMC->GetParticle().Pt();
-  Bool_t isPrim = infoMC->GetParticle().R() < fCutsMC->GetMaxR() && 
-                  TMath::Abs(infoMC->GetParticle().Vz()) < fCutsMC->GetMaxVz() ;
 
-  // Check selection cuts
+  // distance to Prim. vertex 
+  const Double_t* dv = infoMC->GetVDist(); 
+  Bool_t isPrim = TMath::Sqrt(dv[0]*dv[0] + dv[1]*dv[1])<fCutsMC->GetMaxR() && TMath::Abs(dv[2])<fCutsMC->GetMaxVz();
+
+  // Only 5 charged particle species (e,mu,pi,K,p)
   if (fCutsMC->IsPdgParticle(TMath::Abs(infoMC->GetParticle().GetPdgCode())) == kFALSE) return; 
   if (!isPrim) return;
-  if (infoRC->GetStatus(1)==0) return;
+  //if (infoRC->GetStatus(1)!=3) return; // TPC refit
   if (!infoRC->GetESDtrack()) return;  
   if (infoRC->GetESDtrack()->GetTPCNcls()<fCutsRC->GetMinNClustersTPC()) return;
-  
-  Float_t deltaPt= (mcpt-infoRC->GetESDtrack()->Pt())/mcpt;  
-  Float_t pullPt= (1/mcpt-infoRC->GetESDtrack()->OneOverPt())/TMath::Sqrt(infoRC->GetESDtrack()->GetSigma1Pt2());  
-
-  // Fill histograms
-  fPtResolLPT->Fill(mcpt,deltaPt);
-  fPtResolHPT->Fill(mcpt,deltaPt);
-  fPtPullLPT->Fill(mcpt,pullPt);
-  fPtPullHPT->Fill(mcpt,pullPt);  
-}
-
-Long64_t AliComparisonRes::Merge(TCollection* list) 
-{
-  // Merge list of objects (needed by PROOF)
 
-  if (!list)
-  return 0;
-
-  if (list->IsEmpty())
-  return 1;
+  // calculate and set prim. vertex
+  vertexMC.SetXv( infoMC->GetParticle().Vx() - dv[0] );
+  vertexMC.SetYv( infoMC->GetParticle().Vy() - dv[1] );
+  vertexMC.SetZv( infoMC->GetParticle().Vz() - dv[2] );
 
-  TIterator* iter = list->MakeIterator();
-  TObject* obj = 0;
-
-  // collection of generated histograms
-  Int_t count=0;
-  while((obj = iter->Next()) != 0) 
+  // calculate track parameters at vertex
+  const AliExternalTrackParam *innerTPC =  0;
+  if ((innerTPC = infoRC->GetESDtrack()->GetTPCInnerParam()) != 0)
   {
-  AliComparisonRes* entry = dynamic_cast<AliComparisonRes*>(obj);
-  if (entry == 0) { 
-    Error("Add","Attempt to add object of class: %s to a %s",
-       obj->ClassName(),this->ClassName());
-    return -1;
+    if ((track = new AliExternalTrackParam(*infoRC->GetESDtrack()->GetTPCInnerParam())) != 0 )
+    {
+      Bool_t bDCAStatus = track->PropagateToDCA(&vertexMC,field,kMaxD,dca,cov);
+
+      // Fill parametrisation histograms (only TPC track)
+      if(bDCAStatus) 
+      {
+          // select primaries
+          if(TMath::Abs(dca[0])<fCutsRC->GetMaxDCAToVertexXY() && TMath::Abs(dca[1])<fCutsRC->GetMaxDCAToVertexZ()) 
+         { 
+
+            deltaYTPC= track->GetY()-infoMC->GetParticle().Vy();
+            deltaZTPC = track->GetZ()-infoMC->GetParticle().Vz();
+            deltaLambdaTPC = TMath::ATan2(track->Pz(),track->Pt())-TMath::ATan2(infoMC->GetParticle().Pz(),infoMC->GetParticle().Pt());
+            deltaPhiTPC = TMath::ATan2(track->Py(),track->Px())-TMath::ATan2(infoMC->GetParticle().Py(),infoMC->GetParticle().Px());
+           delta1PtTPC = (track->OneOverPt()-1./mcpt)*mcpt;
+
+            pullYTPC= (track->GetY()-infoMC->GetParticle().Vy()) / TMath::Sqrt(track->GetSigmaY2());
+            pullZTPC = (track->GetZ()-infoMC->GetParticle().Vz()) / TMath::Sqrt(track->GetSigmaZ2());
+            pullLambdaTPC = deltaLambdaTPC / TMath::Sqrt(track->GetSigmaTgl2());
+            pullPhiTPC = deltaPhiTPC / TMath::Sqrt(track->GetSigmaSnp2()); 
+           pull1PtTPC = (track->OneOverPt()-1./mcpt) / TMath::Sqrt(track->GetSigma1Pt2());
+
+            Double_t vResolHisto[10] = {deltaYTPC,deltaZTPC,deltaPhiTPC,deltaLambdaTPC,delta1PtTPC,infoMC->GetParticle().Vy(),infoMC->GetParticle().Vz(),mceta,mcphi,mcpt};
+           fResolHisto->Fill(vResolHisto);
+
+            Double_t vPullHisto[10] = {pullYTPC,pullZTPC,pullPhiTPC,pullLambdaTPC,pull1PtTPC,infoMC->GetParticle().Vy(),infoMC->GetParticle().Vz(),mceta,mcphi,mcpt};
+           fPullHisto->Fill(vPullHisto);
+         }
+
+          /*
+            delta1Pt2TPC = (1/mcpt-innerTPC->OneOverPt())/TMath::Power(1+1/mcpt,2);       
+            deltaY1PtTPC= (infoMC->GetParticle().Vy()-innerTPC->GetY()) / (0.2+1/mcpt);
+            deltaZ1PtTPC = (infoMC->GetParticle().Vz()-innerTPC->GetZ()) / (0.2+1/mcpt);
+            deltaPhi1PtTPC = deltaPhiTPC   / (0.1+1/mcpt);
+            deltaTheta1PtTPC = deltaLambdaTPC / (0.1+1/mcpt);
+
+           fPhiEtaPtTPC->Fill(TMath::ATan2(innerTPC->Py(),innerTPC->Px()), innerTPC->Eta(), innerTPC->Pt()); 
+
+            f1Pt2ResolS1PtTPC->Fill(s1mcpt,delta1Pt2TPC);
+            fYResolS1PtTPC->Fill(s1mcpt,deltaY1PtTPC);
+            fZResolS1PtTPC->Fill(s1mcpt,deltaZ1PtTPC);
+            fPhiResolS1PtTPC->Fill(s1mcpt,deltaPhi1PtTPC);
+            fThetaResolS1PtTPC->Fill(s1mcpt,deltaTheta1PtTPC);
+
+            fPtResolPtTPC->Fill(mcpt,deltaPtTPC);
+            fPtPullPtTPC->Fill(mcpt,pullPtTPC);
+            fPhiResolEtaTPC->Fill(eta,deltaPhiTPC);
+            fPhiPullEtaTPC->Fill(eta,pullPhiTPC);
+            fLambdaResolEtaTPC->Fill(eta,deltaLambdaTPC);
+            fLambdaPullEtaTPC->Fill(eta,pullLambdaTPC);
+          */
+       }
+    delete track;
+    }
   }
+}
 
-  fPtResolLPT->Add(entry->fPtResolLPT);
-  fPtResolHPT->Add(entry->fPtResolHPT);
-  fPtPullLPT->Add(entry->fPtPullLPT);
-  fPtPullHPT->Add(entry->fPtPullHPT);
-
-  // Resolution histograms (constrained param)
-  fCPhiResolTan->Add(entry->fCPhiResolTan);
-  fCTanResolTan->Add(entry->fCTanResolTan);
-  fCPtResolTan->Add(entry->fCPtResolTan);
-  fCPhiPullTan->Add(entry->fCPhiPullTan);
-  fCTanPullTan->Add(entry->fCTanPullTan);
-  fCPtPullTan->Add(entry->fCPtPullTan);
-
-  count++;
-  }
+//_____________________________________________________________________________
+void AliComparisonRes::ProcessTPCITS(AliMCInfo* const infoMC, AliESDRecInfo *const infoRC)
+{
+  Int_t clusterITS[200];
+  Float_t dca[2], cov[3]; // dca_xy, dca_z, sigma_xy, sigma_xy_z, sigma_z
 
-return count;
-}
+  Float_t delta1PtTPC, deltaYTPC, deltaZTPC, deltaPhiTPC, deltaLambdaTPC; 
+  Float_t pull1PtTPC, pullYTPC, pullZTPC, pullPhiTPC, pullLambdaTPC; 
 
+  Float_t mceta =  infoMC->GetParticle().Eta();
+  Float_t mcphi =  infoMC->GetParticle().Phi();
+  if(mcphi<0) mcphi += 2.*TMath::Pi();
+  Float_t mcpt = infoMC->GetParticle().Pt();
 
+  // distance to Prim. vertex 
+  const Double_t* dv = infoMC->GetVDist(); 
+  Bool_t isPrim = TMath::Sqrt(dv[0]*dv[0] + dv[1]*dv[1])<fCutsMC->GetMaxR() && TMath::Abs(dv[2])<fCutsMC->GetMaxVz();
 
+  // Only 5 charged particle species (e,mu,pi,K,p)
+  if (fCutsMC->IsPdgParticle(TMath::Abs(infoMC->GetParticle().GetPdgCode())) == kFALSE) return; 
+  if (!isPrim) return;
+  if (infoRC->GetStatus(1)!=3) return; // TPC refit
+  if (!infoRC->GetESDtrack()) return;  
+  if (infoRC->GetESDtrack()->GetTPCNcls()<fCutsRC->GetMinNClustersTPC()) return;
 
+  infoRC->GetESDtrack()->GetImpactParameters(dca,cov);
+
+  // select primaries
+  if(TMath::Abs(dca[0])<fCutsRC->GetMaxDCAToVertexXY() && TMath::Abs(dca[1])<fCutsRC->GetMaxDCAToVertexZ()) 
+  { 
+    deltaYTPC= infoRC->GetESDtrack()->GetY()-infoMC->GetParticle().Vy();
+    deltaZTPC = infoRC->GetESDtrack()->GetZ()-infoMC->GetParticle().Vz();
+    deltaLambdaTPC = TMath::ATan2(infoRC->GetESDtrack()->Pz(),infoRC->GetESDtrack()->Pt())-TMath::ATan2(infoMC->GetParticle().Pz(),infoMC->GetParticle().Pt());
+    deltaPhiTPC = TMath::ATan2(infoRC->GetESDtrack()->Py(),infoRC->GetESDtrack()->Px())-TMath::ATan2(infoMC->GetParticle().Py(),infoMC->GetParticle().Px());
+    delta1PtTPC = (infoRC->GetESDtrack()->OneOverPt()-1./mcpt)*mcpt;
+
+    pullYTPC= (infoRC->GetESDtrack()->GetY()-infoMC->GetParticle().Vy()) / TMath::Sqrt(infoRC->GetESDtrack()->GetSigmaY2());
+    pullZTPC = (infoRC->GetESDtrack()->GetZ()-infoMC->GetParticle().Vz()) / TMath::Sqrt(infoRC->GetESDtrack()->GetSigmaZ2());
+    pullLambdaTPC = deltaLambdaTPC / TMath::Sqrt(infoRC->GetESDtrack()->GetSigmaTgl2());
+    pullPhiTPC = deltaPhiTPC / TMath::Sqrt(infoRC->GetESDtrack()->GetSigmaSnp2()); 
+    pull1PtTPC = (infoRC->GetESDtrack()->OneOverPt()-1./mcpt) / TMath::Sqrt(infoRC->GetESDtrack()->GetSigma1Pt2());
+
+    Double_t vResolHisto[10] = {deltaYTPC,deltaZTPC,deltaPhiTPC,deltaLambdaTPC,delta1PtTPC,infoMC->GetParticle().Vy(),infoMC->GetParticle().Vz(),mceta,mcphi,mcpt};
+    Double_t vPullHisto[10] = {pullYTPC,pullZTPC,pullPhiTPC,pullLambdaTPC,pull1PtTPC,infoMC->GetParticle().Vy(),infoMC->GetParticle().Vz(),mceta,mcphi,mcpt};
+
+    // TPC and ITS clusters in the system
+    if(infoRC->GetESDtrack()->GetITSclusters(clusterITS)>fCutsRC->GetMinNClustersITS()) 
+    {
+      fResolHisto->Fill(vResolHisto);
+      fPullHisto->Fill(vPullHisto);
+    }
+  }
+}
 
 //_____________________________________________________________________________
-void AliComparisonRes::ProcessConstrained(AliMCInfo* infoMC, AliESDRecInfo *infoRC)
+void AliComparisonRes::ProcessConstrained(AliMCInfo* const infoMC, AliESDRecInfo *const infoRC)
 {
   // Fill resolution comparison information (constarained parameters) 
-  
+  //
+  AliExternalTrackParam *track = 0;
+  Double_t field      = AliTracker::GetBz(); // nominal Bz field [kG]
+  Double_t kMaxD      = 123456.0; // max distance
+  AliESDVertex vertexMC;  // MC primary vertex
+
+  Double_t dca[2], cov[3]; // dca_xy, dca_z, sigma_xy, sigma_xy_z, sigma_z
+
+  Float_t delta1PtTPC, deltaYTPC, deltaZTPC, deltaPhiTPC, deltaLambdaTPC; 
+  Float_t pull1PtTPC, pullYTPC, pullZTPC, pullPhiTPC, pullLambdaTPC; 
+
+  Float_t mceta =  infoMC->GetParticle().Eta();
+  Float_t mcphi =  infoMC->GetParticle().Phi();
+  if(mcphi<0) mcphi += 2.*TMath::Pi();
   Float_t mcpt = infoMC->GetParticle().Pt();
-  Float_t tantheta = TMath::Tan(infoMC->GetParticle().Theta()-TMath::Pi()*0.5);
-  Bool_t isPrim = infoMC->GetParticle().R()<fCutsMC->GetMaxR() && TMath::Abs(infoMC->GetParticle().Vz())<fCutsMC->GetMaxVz();
-  
+
+  // distance to Prim. vertex 
+  const Double_t* dv = infoMC->GetVDist(); 
+  Bool_t isPrim = TMath::Sqrt(dv[0]*dv[0] + dv[1]*dv[1])<fCutsMC->GetMaxR() && TMath::Abs(dv[2])<fCutsMC->GetMaxVz();
+
+  // calculate and set prim. vertex
+  vertexMC.SetXv( infoMC->GetParticle().Vx() - dv[0] );
+  vertexMC.SetYv( infoMC->GetParticle().Vy() - dv[1] );
+  vertexMC.SetZv( infoMC->GetParticle().Vz() - dv[2] );
+
   // Check selection cuts
   if (fCutsMC->IsPdgParticle(TMath::Abs(infoMC->GetParticle().GetPdgCode())) == kFALSE) return; 
   if (!isPrim) return;
-  if (infoRC->GetStatus(1)!=3) return;
+  if (infoRC->GetStatus(1)!=3) return; // TPC refit
   if (!infoRC->GetESDtrack()) return;  
   if (infoRC->GetESDtrack()->GetTPCNcls()<fCutsRC->GetMinNClustersTPC()) return;
-  if (!infoRC->GetESDtrack()->GetConstrainedParam()) return;
-  
+
   // constrained parameters resolution
   const AliExternalTrackParam * cparam = infoRC->GetESDtrack()->GetConstrainedParam();
-  Float_t deltaCPt= (mcpt-cparam->Pt())/mcpt;  
-  Float_t pullCPt= (1/mcpt-cparam->OneOverPt())/
-    TMath::Sqrt(cparam->GetSigma1Pt2());          
-  Float_t deltaPhi = TMath::ATan2(cparam->Py(),cparam->Px())-
-    TMath::ATan2(infoMC->GetParticle().Py(),infoMC->GetParticle().Px());
-  Float_t pullPhi = deltaPhi/TMath::Sqrt(cparam->GetSigmaSnp2()); 
-
-  Float_t deltaTan = TMath::ATan2(cparam->Pz(),cparam->Pt())-TMath::ATan2(infoMC->GetParticle().Pz(),infoMC->GetParticle().Pt());
-  Float_t pullTan = deltaPhi/TMath::Sqrt(cparam->GetSigmaSnp2()); 
-
-  // Fill histograms
-  fCPtResolTan->Fill(tantheta,deltaCPt);
-  fCPtPullTan->Fill(tantheta,pullCPt);
-  fCPhiResolTan->Fill(tantheta,deltaPhi);
-  fCPhiPullTan->Fill(tantheta,pullPhi);
-  fCTanResolTan->Fill(tantheta,deltaTan);
-  fCTanPullTan->Fill(tantheta,pullTan);
+  if(!cparam) return;
+
+  if ((track = new AliExternalTrackParam(*cparam)) != 0)
+  {
+    Bool_t bDCAStatus = track->PropagateToDCA(&vertexMC,field,kMaxD,dca,cov);
+    if(bDCAStatus) {
+      if(TMath::Abs(dca[0])<fCutsRC->GetMaxDCAToVertexXY() && TMath::Abs(dca[1])<fCutsRC->GetMaxDCAToVertexZ())
+      {
+        deltaYTPC= track->GetY()-infoMC->GetParticle().Vy();
+        deltaZTPC = track->GetZ()-infoMC->GetParticle().Vz();
+        deltaLambdaTPC = TMath::ATan2(track->Pz(),track->Pt())-TMath::ATan2(infoMC->GetParticle().Pz(),infoMC->GetParticle().Pt());
+        deltaPhiTPC = TMath::ATan2(track->Py(),track->Px())-TMath::ATan2(infoMC->GetParticle().Py(),infoMC->GetParticle().Px());
+        delta1PtTPC = (track->OneOverPt()-1./mcpt)*mcpt;
+
+        pullYTPC= (track->GetY()-infoMC->GetParticle().Vy()) / TMath::Sqrt(track->GetSigmaY2());
+        pullZTPC = (track->GetZ()-infoMC->GetParticle().Vz()) / TMath::Sqrt(track->GetSigmaZ2());
+        pullLambdaTPC = deltaLambdaTPC / TMath::Sqrt(track->GetSigmaTgl2());
+        pullPhiTPC = deltaPhiTPC / TMath::Sqrt(track->GetSigmaSnp2()); 
+        pull1PtTPC = (track->OneOverPt()-1./mcpt) / TMath::Sqrt(track->GetSigma1Pt2());
+
+        Double_t vResolHisto[10] = {deltaYTPC,deltaZTPC,deltaPhiTPC,deltaLambdaTPC,delta1PtTPC,infoMC->GetParticle().Vy(),infoMC->GetParticle().Vz(),mceta,mcphi,mcpt};
+        fResolHisto->Fill(vResolHisto);
+
+        Double_t vPullHisto[10] = {pullYTPC,pullZTPC,pullPhiTPC,pullLambdaTPC,pull1PtTPC,infoMC->GetParticle().Vy(),infoMC->GetParticle().Vz(),mceta,mcphi,mcpt};
+        fPullHisto->Fill(vPullHisto);
+      }
+    }
+  delete track;
+  }
 }
  
 //_____________________________________________________________________________
-void AliComparisonRes::Exec(AliMCInfo* infoMC, AliESDRecInfo *infoRC){
+void AliComparisonRes::Exec(AliMCInfo* const infoMC, AliESDRecInfo* const infoRC){
   
   // Process comparison information 
-  Process(infoMC,infoRC);
-  ProcessConstrained(infoMC,infoRC);
-
+  if(GetAnalysisMode() == 0) ProcessTPC(infoMC,infoRC);
+  else if(GetAnalysisMode() == 1) ProcessTPCITS(infoMC,infoRC);
+  else if(GetAnalysisMode() == 2) ProcessConstrained(infoMC,infoRC);
+  else {
+    printf("ERROR: AnalysisMode %d \n",fAnalysisMode);
+    return;
+  }
 }
 
 //_____________________________________________________________________________
@@ -315,44 +422,149 @@ TH1F* AliComparisonRes::MakeResol(TH2F * his, Int_t integ, Bool_t type){
 
 //_____________________________________________________________________________
 void AliComparisonRes::Analyse(){
-  // Analyse comparison information and store output histograms 
-  // in the "pictures_res.root" file 
-  
-  AliComparisonRes * comp=this;
-  TH1F *hiss=0;
-
-  TFile *fp = new TFile("pictures_res.root","recreate");
-  fp->cd();
+  // Analyse comparison information and store output histograms
+  // in the folder "folderRes"
+  //
+  TH1::AddDirectory(kFALSE);
+  TH1F *h=0;
+  TH2F *h2D=0;
+  TObjArray *aFolderObj = new TObjArray;
 
+  // write results in the folder 
   TCanvas * c = new TCanvas("Phi resol Tan","Phi resol Tan");
   c->cd();
+
+  char name[256];
+  char res_title[256] = {"res_y:res_z:res_lambda:res_phi:res_1pt:y:z:eta:phi:pt"} ;
+  char pull_title[256] = {"pull_y:pull_z:pull_lambda:pull_phi:pull_1pt:y:z:eta:phi:pt"};
+
+  for(Int_t i=0; i<5; i++) 
+  {
+    for(Int_t j=5; j<10; j++) 
+    {
+      if(j==7) fResolHisto->GetAxis(9)->SetRangeUser(0.2,10.); // pt threshold
+      if(j==9) fResolHisto->GetAxis(7)->SetRangeUser(-0.9,0.9); // eta window
+
+      h2D = (TH2F*)fResolHisto->Projection(i,j);
+      h = AliComparisonRes::MakeResol(h2D,1,0);
+      sprintf(name,"h_res_%d_vs_%d",i,j);
+      h->SetName(name);
+      h->SetTitle(res_title);
+
+      aFolderObj->Add(h);
+
+      h = AliComparisonRes::MakeResol(h2D,1,1);
+      sprintf(name,"h_mean_res_%d_vs_%d",i,j);
+      h->SetName(name);
+      h->SetTitle(res_title);
+
+      aFolderObj->Add(h);
+
+      if(j==7) fResolHisto->GetAxis(9)->SetRangeUser(0.0,10.);
+      if(j==9) fResolHisto->GetAxis(7)->SetRangeUser(-1.5,1.5);
+
+      //
+      if(j==7) fPullHisto->GetAxis(9)->SetRangeUser(0.2,10.);
+      if(j==9) fPullHisto->GetAxis(7)->SetRangeUser(-0.9,0.9);
+
+      h2D = (TH2F*)fPullHisto->Projection(i,j);
+      h = AliComparisonRes::MakeResol(h2D,1,0);
+      sprintf(name,"h_pull_%d_vs_%d",i,j);
+      h->SetName(name);
+      h->SetTitle(pull_title);
+
+      aFolderObj->Add(h);
+
+      h = AliComparisonRes::MakeResol(h2D,1,1);
+      sprintf(name,"h_mean_pull_%d_vs_%d",i,j);
+      h->SetName(name);
+      h->SetTitle(pull_title);
+
+      aFolderObj->Add(h);
+
+      if(j==7) fPullHisto->GetAxis(9)->SetRangeUser(0.0,10.);
+      if(j==9) fPullHisto->GetAxis(7)->SetRangeUser(-1.5,1.5);
+    }
+  }
+
+  // export objects to analysis folder
+  fAnalysisFolder = ExportToFolder(aFolderObj);
+
+  // delete only TObjArray
+  if(aFolderObj) delete aFolderObj;
+}
+
+//_____________________________________________________________________________
+TFolder* AliComparisonRes::ExportToFolder(TObjArray * array) 
+{
+  // recreate folder avery time and export objects to new one
   //
-  hiss = comp->MakeResol(comp->fCPtResolTan,1,0);
-  hiss->SetXTitle("Tan(#theta)");
-  hiss->SetYTitle("#sigmap_{t}/p_{t}");
-  hiss->Draw(); 
-  hiss->Write("CptResolTan");
-  //
-  hiss = comp->MakeResol(comp->fCPhiResolTan,1,0);
-  hiss->SetXTitle("Tan(#theta)");
-  hiss->SetYTitle("#sigma#phi (rad)");
-  hiss->Draw();
-  hiss->Write("PhiResolTan");
-  //
-  hiss = comp->MakeResol(comp->fCTanResolTan,1,0);
-  hiss->SetXTitle("Tan(#theta)");
-  hiss->SetYTitle("#sigma#theta (rad)");
-  hiss->Draw();
-  hiss->Write("ThetaResolTan");
-  //
-  hiss = comp->MakeResol(comp->fCPtPullTan,1,0);
-  hiss->SetXTitle("Tan(#theta)");
-  hiss->SetYTitle("1/mcp_{t}-1/p_{t}/#Sigma(1/p_{t})");
-  hiss->Draw();
-  hiss->Write("CptPullTan");
+  AliComparisonRes * comp=this;
+  TFolder *folder = comp->GetAnalysisFolder();
+
+  TString name, title;
+  TFolder *newFolder = 0;
+  Int_t i = 0;
+  Int_t size = array->GetSize();
+
+  if(folder) { 
+     // get name and title from old folder
+     name = folder->GetName();  
+     title = folder->GetTitle();  
+
+        // delete old one
+     delete folder;
+
+        // create new one
+     newFolder = CreateFolder(name.Data(),title.Data());
+     newFolder->SetOwner();
+
+        // add objects to folder
+     while(i < size) {
+          newFolder->Add(array->At(i));
+          i++;
+        }
+  }
 
-  fp->Close();
+return newFolder;
 }
 
+//_____________________________________________________________________________
+Long64_t AliComparisonRes::Merge(TCollection* const list) 
+{
+  // Merge list of objects (needed by PROOF)
+
+  if (!list)
+  return 0;
 
+  if (list->IsEmpty())
+  return 1;
 
+  TIterator* iter = list->MakeIterator();
+  TObject* obj = 0;
+
+  // collection of generated histograms
+  Int_t count=0;
+  while((obj = iter->Next()) != 0) 
+  {
+  AliComparisonRes* entry = dynamic_cast<AliComparisonRes*>(obj);
+  if (entry == 0) continue; 
+
+  fResolHisto->Add(entry->fResolHisto);
+  fPullHisto->Add(entry->fPullHisto);
+
+  count++;
+  }
+
+return count;
+}
+
+//_____________________________________________________________________________
+TFolder* AliComparisonRes::CreateFolder(TString name,TString title) { 
+// create folder for analysed histograms
+//
+TFolder *folder = 0;
+  folder = new TFolder(name.Data(),title.Data());
+
+  return folder;
+}