]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - PWG1/AliRecInfoMaker.cxx
Correct formula for phi, in case of current local X <0, in GetLocalXat and GetPhiZat
[u/mrichter/AliRoot.git] / PWG1 / AliRecInfoMaker.cxx
index f1c76f7ee8877611ab90956c915eaa31dab585e9..93c93eb165b9c617f07ac73cdf99e500dce85e4a 100644 (file)
@@ -31,13 +31,14 @@ Usage:
 
 gSystem->Load("libPWG1.so");
 //
-AliRecInfoMaker *t2 = new AliRecInfoMaker("genTracks.root","cmpESDTracks.root","galice.root",-1,0,0);
+AliRecInfoMaker *t2 = new AliRecInfoMaker("genTracks.root","cmpESDTracks.root","galice.root",0,0);
 t2->Exec();
 
 
 TFile f("cmpESDTracks.root");
-AliTreeDraw comp;
 TTree * tree = (TTree*)f.Get("ESDcmpTracks");
+
+AliTreeDraw comp;
 comp.SetTree(tree)
 
 
@@ -63,13 +64,13 @@ TCut cchi2("cchi2","fESDtrack.fITSchi2MIP[0]<7.&&fESDtrack.fITSchi2MIP[1]<5.&&fE
 
 //
 //example
-comp.fTree->SetAlias("radius","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)");
-comp.fTree->SetAlias("direction","MC.fParticle.fVx*MC.fParticle.fPx+MC.fParticle.fVy*MC.fParticle.fPy");
-comp.fTree->SetAlias("decaydir","MC.fTRdecay.fX*MC.fTRdecay.fPx+MC.fTRdecay.fY*MC.fTRdecay.fPy");
-comp.fTree->SetAlias("theta","MC.fTrackRef.Theta()");
-comp.fTree->SetAlias("primdca","sqrt(RC.fITStrack.fD[0]**2+RC.fITStrack.fD[1]**2)");
-comp.fTree->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
-comp.fTree->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
+comp.T()->SetAlias("radius","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)");
+comp.T()->SetAlias("direction","MC.fParticle.fVx*MC.fParticle.fPx+MC.fParticle.fVy*MC.fParticle.fPy");
+comp.T()->SetAlias("decaydir","MC.fTRdecay.fX*MC.fTRdecay.fPx+MC.fTRdecay.fY*MC.fTRdecay.fPy");
+comp.T()->SetAlias("theta","MC.fTrackRef.Theta()");
+comp.T()->SetAlias("primdca","sqrt(RC.fITStrack.fD[0]**2+RC.fITStrack.fD[1]**2)");
+comp.T()->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
+comp.T()->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
 
 
 TH1F his("his","his",100,0,20);
@@ -92,7 +93,7 @@ comp.fRes->Draw();
 comp.Eff("fTPCinP0[3]","fRowsWithDigits>120"+cteta1+cpos1+cprim,"fTPCOn&&fITSOn&&fESDtrack.fITSFakeRatio>0.1",10,0.2,1.5)
 comp.fRes->Draw();
 
-comp.fTree->Draw("fESDtrack.fITSsignal/fESDtrack.fTPCsignal","fITSOn&&fTPCOn&&fESDtrack.fITSFakeRatio==0") 
+comp.T()->Draw("fESDtrack.fITSsignal/fESDtrack.fTPCsignal","fITSOn&&fTPCOn&&fESDtrack.fITSFakeRatio==0") 
 
 TH1F his("his","his",100,0,20);
 TH1F hpools("hpools","hpools",100,-7,7);
@@ -102,21 +103,21 @@ TH2F * hdedx1 = new TH2F("dEdx1","dEdx1",100, 0,2,200,0,550); hdedx1->SetMarkerC
 TH2F * hdedx2 = new TH2F("dEdx2","dEdx2",100, 0,2,200,0,550); hdedx2->SetMarkerColor(3);
 TH2F * hdedx3 = new TH2F("dEdx3","dEdx3",100, 0,2,200,0,550); hdedx3->SetMarkerColor(2);
 
-comp.fTree->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx0","fITSOn&&abs(fPdg)==211&&fITStrack.fN==6"+cprim) 
-comp.fTree->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx1","fITSOn&&abs(fPdg)==2212&&fITStrack.fN==6"+cprim) 
-comp.fTree->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx2","fITSOn&&abs(fPdg)==321&&fITStrack.fN==6"+cprim) 
-comp.fTree->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx3","fITSOn&&abs(fPdg)==11&&fITStrack.fN==6"+cprim) 
+comp.T()->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx0","fITSOn&&abs(fPdg)==211&&fITStrack.fN==6"+cprim) 
+comp.T()->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx1","fITSOn&&abs(fPdg)==2212&&fITStrack.fN==6"+cprim) 
+comp.T()->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx2","fITSOn&&abs(fPdg)==321&&fITStrack.fN==6"+cprim) 
+comp.T()->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx3","fITSOn&&abs(fPdg)==11&&fITStrack.fN==6"+cprim) 
 
 
-comp.fTree->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx0","fTRDOn&&abs(fPdg)==211&&fTRDtrack.fN>40&&fStatus[2]>1") 
-comp.fTree->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx1","fTRDOn&&abs(fPdg)==2212&&fTRDtrack.fN>40&&fStatus[2]>1") 
-comp.fTree->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx2","fTRDOn&&abs(fPdg)==321&&fTRDtrack.fN>40&&fStatus[2]>1") 
-comp.fTree->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx3","fTRDOn&&abs(fPdg)==11&&fTRDtrack.fN>40&&fStatus[2]>1") 
+comp.T()->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx0","fTRDOn&&abs(fPdg)==211&&fTRDtrack.fN>40&&fStatus[2]>1") 
+comp.T()->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx1","fTRDOn&&abs(fPdg)==2212&&fTRDtrack.fN>40&&fStatus[2]>1") 
+comp.T()->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx2","fTRDOn&&abs(fPdg)==321&&fTRDtrack.fN>40&&fStatus[2]>1") 
+comp.T()->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx3","fTRDOn&&abs(fPdg)==11&&fTRDtrack.fN>40&&fStatus[2]>1") 
 
-comp.fTree->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx0","fTPCOn&&abs(fPdg)==211&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
-comp.fTree->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx1","fTPCOn&&abs(fPdg)==2212&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
-comp.fTree->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx2","fTPCOn&&abs(fPdg)==321&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
-comp.fTree->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx3","fTPCOn&&abs(fPdg)==11&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
+comp.T()->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx0","fTPCOn&&abs(fPdg)==211&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
+comp.T()->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx1","fTPCOn&&abs(fPdg)==2212&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
+comp.T()->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx2","fTPCOn&&abs(fPdg)==321&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
+comp.T()->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx3","fTPCOn&&abs(fPdg)==11&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
 
 hdedx3->SetXTitle("P(GeV/c)");
 hdedx3->SetYTitle("dEdx(unit)");
@@ -138,45 +139,26 @@ TProfile prof("prof","prof",10,0.5,5);
 #include "Rtypes.h"
 #include "TFile.h"
 #include "TTree.h"
-#include "TChain.h"
-#include "TCut.h"
-#include "TString.h"
-#include "TBenchmark.h"
 #include "TStopwatch.h"
-#include "TParticle.h"
-#include "TSystem.h"
-#include "TTimer.h"
 #include "TVector3.h"
-#include "TPad.h"
-#include "TCanvas.h"
-#include "TH1F.h"
-#include "TH2F.h"
-#include "TF1.h"
-#include "TText.h"
-#include "Getline.h"
-#include "TStyle.h"
+#include "TGeoManager.h"
+//#include "Getline.h"
+//
 //ALIROOT includes
+//
 #include "AliRun.h"
-#include "AliStack.h"
 #include "AliESDtrack.h"
-#include "AliSimDigits.h"
 #include "AliTPCParam.h"
 #include "AliTPC.h"
-#include "AliTPCLoader.h"
-#include "AliDetector.h"
 #include "AliTrackReference.h"
-#include "AliRun.h"
 #include "AliTPCParamSR.h"
 #include "AliTracker.h"
-#include "AliComplexCluster.h"
-#include "AliMagF.h"
+#include "AliESDEvent.h"
 #include "AliESD.h"
 #include "AliESDfriend.h"
 #include "AliESDtrack.h"
 #include "AliTPCseed.h"
 #include "AliITStrackMI.h"
-#include "AliTRDtrack.h"
-#include "AliHelix.h"
 #include "AliESDVertex.h"
 #include "AliExternalTrackParam.h"
 #include "AliESDkink.h"
@@ -184,8 +166,14 @@ TProfile prof("prof","prof",10,0.5,5);
 #include "AliV0.h"
 //
 #include "AliTreeDraw.h"
-#include "AliGenInfo.h"
-#include "AliRecInfo.h"
+#include "AliMCInfo.h"
+#include "AliGenKinkInfo.h"
+#include "AliGenV0Info.h"
+
+
+#include "AliESDRecInfo.h"
+#include "AliESDRecV0Info.h"
+#include "AliESDRecKinkInfo.h"
 #include "AliRecInfoMaker.h"
 
 
@@ -196,6 +184,9 @@ ClassImp(AliRecInfoMaker)
 
 
 AliTPCParam * AliRecInfoMaker::GetTPCParam(){
+  //
+  // create TPC param
+  //
   AliTPCParamSR * par = new AliTPCParamSR;
   par->Update();
   return par;
@@ -203,46 +194,96 @@ AliTPCParam * AliRecInfoMaker::GetTPCParam(){
 
 
 
-void MakeAliases(AliTreeDraw&comp)
+void  AliRecInfoMaker::MakeAliases(TTree * tree)
 {
   //
   // aliases definition
   //
-  comp.T()->SetAlias("radius","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)");
-  comp.T()->SetAlias("direction","MC.fParticle.fVx*MC.fParticle.fPx+MC.fParticle.fVy*MC.fParticle.fPy");
-  comp.T()->SetAlias("decaydir","MC.fTRdecay.fX*MC.fTRdecay.fPx+MC.fTRdecay.fY*MC.fTRdecay.fPy");
-  comp.T()->SetAlias("theta","MC.fTrackRef.Theta()");
-  comp.T()->SetAlias("primdca","sqrt(RC.fITStrack.fD[0]**2+RC.fITStrack.fD[1]**2)");
-  comp.T()->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
-  comp.T()->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
+  tree->SetAlias("radius","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)");
+  tree->SetAlias("direction","MC.fParticle.fVx*MC.fParticle.fPx+MC.fParticle.fVy*MC.fParticle.fPy");
+  tree->SetAlias("decaydir","MC.fTRdecay.fX*MC.fTRdecay.fPx+MC.fTRdecay.fY*MC.fTRdecay.fPy");
+  tree->SetAlias("theta","MC.fTrackRef.Theta()");
+  tree->SetAlias("primdca","sqrt(RC.fITStrack.fD[0]**2+RC.fITStrack.fD[1]**2)");
+  tree->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
+  tree->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
   
-  comp.T()->SetAlias("trddedx","(RC.fESDtrack.fTRDsignals[0]+RC.fESDtrack.fTRDsignals[1]+RC.fESDtrack.fTRDsignals[2]+RC.fESDtrack.fTRDsignals[3]+RC.fESDtrack.fTRDsignals[4]+RC.fESDtrack.fTRDsignals[5])/6.");
+  tree->SetAlias("trddedx","(RC.fESDtrack.fTRDsignals[0]+RC.fESDtrack.fTRDsignals[1]+RC.fESDtrack.fTRDsignals[2]+RC.fESDtrack.fTRDsignals[3]+RC.fESDtrack.fTRDsignals[4]+RC.fESDtrack.fTRDsignals[5])/6.");
   
-  comp.T()->SetAlias("dtofmc2","fESDtrack.fTrackTime[2]-(10^12*MC.fTOFReferences[0].fTime)");
-  comp.T()->SetAlias("dtofrc2","(fESDtrack.fTrackTime[2]-fESDtrack.fTOFsignal)");
-
-  comp.T()->SetAlias("psum","fESDtrack.fTOFr[4]+fESDtrack.fTOFr[3]+fESDtrack.fTOFr[2]+fESDtrack.fTOFr[1]+fESDtrack.fTOFr[0]");
-  comp.T()->SetAlias("P0","fESDtrack.fTOFr[0]/psum");
-  comp.T()->SetAlias("P1","fESDtrack.fTOFr[1]/psum");
-  comp.T()->SetAlias("P2","fESDtrack.fTOFr[2]/psum");
-  comp.T()->SetAlias("P3","fESDtrack.fTOFr[3]/psum");
-  comp.T()->SetAlias("P4","fESDtrack.fTOFr[4]/psum");
-  comp.T()->SetAlias("MaxP","max(max(max(P0,P1),max(P2,P3)),P4)");
+  tree->SetAlias("dtofmc2","fESDtrack.fTrackTime[2]-(10^12*MC.fTOFReferences[0].fTime)");
+  tree->SetAlias("dtofrc2","(fESDtrack.fTrackTime[2]-fESDtrack.fTOFsignal)");
+
+  tree->SetAlias("psum","fESDtrack.fTOFr[4]+fESDtrack.fTOFr[3]+fESDtrack.fTOFr[2]+fESDtrack.fTOFr[1]+fESDtrack.fTOFr[0]");
+  tree->SetAlias("P0","fESDtrack.fTOFr[0]/psum");
+  tree->SetAlias("P1","fESDtrack.fTOFr[1]/psum");
+  tree->SetAlias("P2","fESDtrack.fTOFr[2]/psum");
+  tree->SetAlias("P3","fESDtrack.fTOFr[3]/psum");
+  tree->SetAlias("P4","fESDtrack.fTOFr[4]/psum");
+  tree->SetAlias("MaxP","max(max(max(P0,P1),max(P2,P3)),P4)");
 }
 
 
-////////////////////////////////////////////////////////////////////////
-AliRecInfoMaker::AliRecInfoMaker()
-{
-  Reset();
-}
-
 ////////////////////////////////////////////////////////////////////////
 AliRecInfoMaker::AliRecInfoMaker(const char* fnGenTracks,
-                  const char* fnCmp,
-                  const char* fnGalice, Int_t direction,
-                  Int_t nEvents, Int_t firstEvent)
+                                const char* fnCmp,
+                                const char* fnGalice,
+                                Int_t nEvents, Int_t firstEvent):
+  
+  fEventNr(0),                 //! current event number
+  fNEvents(0),                 //! number of events to process
+  fFirstEventNr(0),            //! first event to process
+  fFileCmp(0),                //! output file with cmp tracks
+  fTreeCmp(0),                //! output tree with cmp tracks
+  fTreeCmpKinks(0),                //! output tree with cmp Kinks
+  fTreeCmpV0(0),                //! output tree with cmp V0
+  //
+  fFileGenTracks(0),                //! input files with generated tracks   
+  fTreeGenTracks(0),           //! tree with generated tracks
+  fTreeGenKinks(0),            // tree with gen kinks
+  fTreeGenV0(0),            // tree with gen V0
+  //
+  fLoader(0),         //! pointer to the run loader
+  //
+  fIndexRecTracks(0),         //! index of particle label in the TreeT_ESD
+  fFakeRecTracks(0),          //! number of fake tracks
+  fMultiRecTracks(0),         //! number of multiple reconstructions
+  //
+  fIndexRecKinks(0),         //! index of particle label in treeesd
+  fMultiRecKinks(0),         //! number of multiple reconstructions
+  fSignedKinks(0),           //! indicator that kink was not fake
+  //
+  fIndexRecV0(0),         //! index of particle label in treeesd
+  fMultiRecV0(0),         //! number of multiple reconstructions
+  fSignedV0(0),                //! indicator that kink was not fake
+  //
+  fRecArray(0),           // container with rec infos
+  fEvent(0),             //!event
+  fESDfriend(0),              //!event friend
+  //
+  fParamTPC(0),         //! AliTPCParam
+  fNParticles(0),              //! number of particles in the input tree genTracks
+  fDebug(0),                   //! debug flag  
+  fNextTreeGenEntryToRead(0),    //! last entry already read from genTracks tree
+  fNextKinkToRead(0),            //! last entry already read from genKinks tree
+  fNextV0ToRead(0),            //! last entry already read from genV0 tree
+  //
+  fMCInfo(0),           //! MC information writen per particle
+  fGenKinkInfo(0),      //! MC information writen per Kink
+  fGenV0Info(0),      //! MC information writen per Kink
+  fRecInfo(0),          //! Rec. information writen per particle
+  fFriend(0),          //! friend track
+  fRecKinkInfo(0),    //! reconstructed kink info
+  fRecV0Info(0)    //! reconstructed kink info
 {
+  // AliRecInfoMaker - connencts the MC information with reconstructed information
+  // fnGenTracks  - file with MC to be created before using AliGenInfoMaker
+  // fnCmp        - file name  to be created  
+  // fnGalice     - file with Loaders - usualy galice.root 
+  //  
+  // nEvent       - number of event s to be analyzed
+  // AliRecInfoMaker *t2 = new AliRecInfoMaker("genTracks.root","cmpESDTracks.root","galice.root",0,0);
+  //
+
+
   Reset();
   //  fFnGenTracks = fnGenTracks;
   //  fFnCmp = fnCmp;
@@ -252,11 +293,10 @@ AliRecInfoMaker::AliRecInfoMaker(const char* fnGenTracks,
   fFirstEventNr = firstEvent;
   fEventNr = firstEvent;
   fNEvents = nEvents;
-  fDirection = direction;
   //
   fLoader = AliRunLoader::Open(fnGalice);
   if (gAlice){
-    //delete gAlice->GetRunLoader();
+    //delete AliRunLoader::Instance();
     delete gAlice;
     gAlice = 0x0;
   }
@@ -279,15 +319,73 @@ AliRecInfoMaker::AliRecInfoMaker(const char* fnGenTracks,
     fEventNr = nall-firstEvent;
     cerr<<"restricted number of events availaible"<<endl;
   }
-  AliMagF * magf = gAlice->Field();
-  AliTracker::SetFieldMap(magf,0);
+  TGeoManager::Import("geometry.root");
+
 
 }
+////////////////////////////////////////////////////////////////////////
+AliRecInfoMaker::AliRecInfoMaker(const AliRecInfoMaker& /*info*/):
+  
+  fEventNr(0),                 //! current event number
+  fNEvents(0),                 //! number of events to process
+  fFirstEventNr(0),            //! first event to process
+  fFileCmp(0),                //! output file with cmp tracks
+  fTreeCmp(0),                //! output tree with cmp tracks
+  fTreeCmpKinks(0),                //! output tree with cmp Kinks
+  fTreeCmpV0(0),                //! output tree with cmp V0
+  //
+  fFileGenTracks(0),                //! input files with generated tracks   
+  fTreeGenTracks(0),           //! tree with generated tracks
+  fTreeGenKinks(0),            // tree with gen kinks
+  fTreeGenV0(0),            // tree with gen V0
+  //
+  fLoader(0),         //! pointer to the run loader
+  //
+  fIndexRecTracks(0),         //! index of particle label in the TreeT_ESD
+  fFakeRecTracks(0),          //! number of fake tracks
+  fMultiRecTracks(0),         //! number of multiple reconstructions
+  //
+  fIndexRecKinks(0),         //! index of particle label in treeesd
+  fMultiRecKinks(0),         //! number of multiple reconstructions
+  fSignedKinks(0),           //! indicator that kink was not fake
+  //
+  fIndexRecV0(0),         //! index of particle label in treeesd
+  fMultiRecV0(0),         //! number of multiple reconstructions
+  fSignedV0(0),                //! indicator that kink was not fake
+  //
+  fRecArray(0),           // container with rec infos
+  fEvent(0),             //!event
+  fESDfriend(0),              //!event friend
+  //
+  fParamTPC(0),         //! AliTPCParam
+  fNParticles(0),              //! number of particles in the input tree genTracks
+  fDebug(0),                   //! debug flag  
+  fNextTreeGenEntryToRead(0),    //! last entry already read from genTracks tree
+  fNextKinkToRead(0),            //! last entry already read from genKinks tree
+  fNextV0ToRead(0),            //! last entry already read from genV0 tree
+  //
+  fMCInfo(0),           //! MC information writen per particle
+  fGenKinkInfo(0),      //! MC information writen per Kink
+  fGenV0Info(0),      //! MC information writen per Kink
+  fRecInfo(0),          //! Rec. information writen per particle
+  fFriend(0),          //! friend track
+  fRecKinkInfo(0),    //! reconstructed kink info
+  fRecV0Info(0)    //! reconstructed kink info
+{
+  //
+  // Dummy copu constructor
+  //
+}
+
+
 
 
 ////////////////////////////////////////////////////////////////////////
 AliRecInfoMaker::~AliRecInfoMaker()
 {
+  //
+  // Destructor
+  //
   if (fLoader) {
     delete fLoader;
   }
@@ -297,7 +395,8 @@ AliRecInfoMaker::~AliRecInfoMaker()
 Int_t AliRecInfoMaker::SetIO()
 {
   //
-  // 
+  // SetIO  - Create the input trees
+  //
   CreateTreeCmp();
   if (!fTreeCmp) return 1;
   fParamTPC = GetTPCParam();
@@ -321,41 +420,22 @@ Int_t AliRecInfoMaker::SetIO(Int_t eventNr)
   //
  
   TTree* tree = (TTree*) f.Get("esdTree");
-  if (!tree) { 
-    Char_t ename[100]; 
-    sprintf(ename,"%d",eventNr);
-    fEvent = (AliESD*)f.Get(ename);
-    if (!fEvent){
-      sprintf(ename,"ESD%d",eventNr);
-      fEvent = (AliESD*)f.Get(ename);
-    }
-  }
-  else{
-    tree->SetBranchStatus("*",1);
-    tree->SetBranchAddress("ESD", &fEvent);
-    tree->SetBranchAddress("ESDfriend.",&fESDfriend);
+  tree->SetBranchStatus("*",1);
+  fEvent = new AliESDEvent;
+  
+  if (tree->GetBranch("ESD")){
+    //    tree->SetBranchAddress("ESD", &fEvent);
+    // tree->SetBranchAddress("ESDfriend.",&fESDfriend);
+    // tree->GetEntry(eventNr);
+    // fEvent->SetESDfriend(fESDfriend);    
+  }else{
+    fEvent->ReadFromTree(tree);
+    fESDfriend = (AliESDfriend*)fEvent->FindListObject("AliESDfriend"); 
     tree->GetEntry(eventNr);
-    fEvent->SetESDfriend(fESDfriend);    
-  }
-
-
-  /*
-  Char_t ename[100]; 
-  sprintf(ename,"%d",eventNr);
-  fEvent = (AliESD*)f.Get(ename);
-  if (!fEvent){
-    sprintf(ename,"ESD%d",eventNr);
-    fEvent = (AliESD*)f.Get(ename);
-  }
+    fEvent->SetESDfriend(fESDfriend); 
+  }    
   
-  TTree* tree = (TTree*) f.Get("esdTree");
-  if (!tree) {
-    Error("CheckESD", "no ESD tree found");
-    return kFALSE;
-  }
-  tree->SetBranchAddress("ESD", &fEvent);
-  tree->GetEntry(eventNr);
-  */
+
 
   if (!fEvent) return 1;
 
@@ -367,6 +447,9 @@ Int_t AliRecInfoMaker::SetIO(Int_t eventNr)
 ////////////////////////////////////////////////////////////////////////
 void AliRecInfoMaker::Reset()
 {
+  //
+  // Reset the class
+  //
   fEventNr = 0;
   fNEvents = 0;
   fTreeCmp = 0;
@@ -383,6 +466,9 @@ void AliRecInfoMaker::Reset()
 ////////////////////////////////////////////////////////////////////////
 Int_t AliRecInfoMaker::Exec(Int_t nEvents, Int_t firstEventNr)
 {
+  //
+  // Exec comparison for subrange of events
+  //
   fNEvents = nEvents;
   fFirstEventNr = firstEventNr;
   return Exec();
@@ -391,6 +477,9 @@ Int_t AliRecInfoMaker::Exec(Int_t nEvents, Int_t firstEventNr)
 ////////////////////////////////////////////////////////////////////////
 Int_t AliRecInfoMaker::Exec()
 {
+  //
+  // Exec comparison
+  //
   TStopwatch timer;
   timer.Start();
 
@@ -435,8 +524,8 @@ Int_t AliRecInfoMaker::Exec()
 
     if (fDebug>2) cout<<"\tStart loop over tree genTracks"<<endl;
     if (TreeGenLoop(eventNr)>0) return 1;
-    BuildKinkInfo0(eventNr);
-    //BuildV0Info(eventNr); // no V0 info for a moment
+    //BuildKinkInfo0(eventNr);
+    BuildV0Info(eventNr); // no V0 info for a moment
     fRecArray->Delete();
 
     if (fDebug>2) cout<<"\tEnd loop over tree genTracks"<<endl;
@@ -513,6 +602,9 @@ Bool_t AliRecInfoMaker::ConnectGenTree()
 ////////////////////////////////////////////////////////////////////////
 void AliRecInfoMaker::CreateTreeCmp() 
 {
+  //
+  // Create file and tree with comparison information 
+  //
   fFileCmp = TFile::Open(fFnCmp,"RECREATE");
   if (!fFileCmp) {
     cerr<<"Error in CreateTreeCmp: cannot open file "<<fFnCmp<<endl;
@@ -548,9 +640,14 @@ void AliRecInfoMaker::CreateTreeCmp()
   fTreeCmpKinks->AutoSave(); 
   fTreeCmpV0->AutoSave(); 
 }
+
 ////////////////////////////////////////////////////////////////////////
 void AliRecInfoMaker::CloseOutputFile()  
 {
+  //
+  // Close output file
+  //
+
   if (!fFileCmp) {
     cerr<<"File "<<fFnCmp<<" not found as an open file."<<endl;
     return;
@@ -568,6 +665,10 @@ void AliRecInfoMaker::CloseOutputFile()
 TVector3 AliRecInfoMaker::TR2Local(AliTrackReference *trackRef,
                            AliTPCParam *paramTPC) {
 
+  //
+  // Transform position to the local coord frame
+  //
+  
   Float_t x[3] = { trackRef->X(),trackRef->Y(),trackRef->Z()};
   Int_t index[4];
   paramTPC->Transform0to1(x,index);
@@ -593,12 +694,14 @@ Int_t AliRecInfoMaker::TreeTLoop()
   //
   // load kinks to the memory
   for (Int_t i=0; i<nKinks;i++){
-    AliESDkink * kink =fEvent->GetKink(i);
+    //    AliESDkink * kink =
+    fEvent->GetKink(i);
     fSignedKinks[i]=0;
   }
   //
   for (Int_t i=0; i<nV0MIs;i++){
-    AliV0 * v0MI = (AliV0*)fEvent->GetV0(i);
+    //AliV0 * v0MI = 
+    (AliV0*)fEvent->GetV0(i);
     fSignedV0[i]=0;
   }
   
@@ -606,7 +709,6 @@ Int_t AliRecInfoMaker::TreeTLoop()
   //
   AliESDtrack * track=0;
   for (Int_t iEntry=0; iEntry<nEntries;iEntry++){
-    //track = (AliESDtrack*)fTracks->UncheckedAt(iEntry);
     track = (AliESDtrack*)fEvent->GetTrack(iEntry);
     //
     Int_t label = track->GetLabel();
@@ -645,27 +747,34 @@ Int_t AliRecInfoMaker::TreeTLoop()
   }  
   // --sort reconstructed V0
   //
-//   AliV0 * v0MI=0;
-//   for (Int_t iEntry=0; iEntry<nV0MIs;iEntry++){
-//     v0MI = (AliV0*)fEvent->GetV0(iEntry);
-//     if (!v0MI) continue;
-//     //
-//     Int_t label0 = TMath::Abs(v0MI->GetLabel(0));
-//     Int_t label1 = TMath::Abs(v0MI->GetLabel(1));
-//     //
-//     for (Int_t i=0;i<2;i++){
-//       Int_t absLabel =  TMath::Abs(v0MI->GetLabel(i));
-//       if (absLabel < fNParticles) {
-//     if (fMultiRecV0[absLabel]>0){
-//       if (fMultiRecV0[absLabel]<20)
-//         fIndexRecV0[absLabel*20+fMultiRecV0[absLabel]] =  iEntry;   
-//     }
-//     else      
-//       fIndexRecV0[absLabel*20] =  iEntry;
-//     fMultiRecV0[absLabel]++;
-//       }
-//     }
-//   }  
+  AliV0 * v0MI=0;
+  for (Int_t iEntry=0; iEntry<nV0MIs;iEntry++){
+    v0MI = (AliV0*)fEvent->GetV0(iEntry);
+    if (!v0MI) continue;
+    //
+    //
+    //
+    //Int_t label0 = TMath::Abs(v0MI->GetLabel(0));
+    //Int_t label1 = TMath::Abs(v0MI->GetLabel(1));
+    AliESDtrack * trackn = fEvent->GetTrack((v0MI->GetNindex()));
+    AliESDtrack * trackp = fEvent->GetTrack((v0MI->GetPindex()));
+    Int_t labels[2]={-1,-1};
+    labels[0] = (trackn==0) ? -1 : TMath::Abs(trackn->GetLabel()); 
+    labels[1] = (trackp==0) ? -1 : TMath::Abs(trackp->GetLabel()); 
+    //
+    for (Int_t i=0;i<2;i++){
+      Int_t absLabel =  TMath::Abs(labels[i]);
+      if (absLabel < fNParticles) {
+       if (fMultiRecV0[absLabel]>0){
+         if (fMultiRecV0[absLabel]<20)
+           fIndexRecV0[absLabel*20+fMultiRecV0[absLabel]] =  iEntry;   
+       }
+       else      
+         fIndexRecV0[absLabel*20] =  iEntry;
+       fMultiRecV0[absLabel]++;
+      }
+    }
+  }  
 
 
   printf("Time spended in TreeTLoop\n");
@@ -689,7 +798,7 @@ Int_t AliRecInfoMaker::TreeGenLoop(Int_t eventNr)
   cerr<<"fNParticles, nParticlesTR, fNextTreeGenEntryToRead: "<<fNParticles<<" "
       <<nParticlesTR<<" "<<fNextTreeGenEntryToRead<<endl;
   TBranch * branch = fTreeCmp->GetBranch("RC");
-  TBranch * branchF = fTreeCmp->GetBranch("F");
+  //  TBranch * branchF = fTreeCmp->GetBranch("F");
   
   branch->SetAddress(&fRecInfo); // set all pointers
   fRecArray = new TObjArray(fNParticles);
@@ -700,7 +809,8 @@ Int_t AliRecInfoMaker::TreeGenLoop(Int_t eventNr)
     fTreeGenTracks->GetEntry(entry);
     entry++;
     if (eventNr < fMCInfo->fEventNr) continue;
-    if (eventNr > fMCInfo->fEventNr) continue;;
+    if (eventNr > fMCInfo->fEventNr) continue;
+    if (fMCInfo->GetCharge()==0) continue;
     //
     fNextTreeGenEntryToRead = entry-1;
     if (fDebug > 2 && fMCInfo->fLabel < 10) {
@@ -715,7 +825,6 @@ Int_t AliRecInfoMaker::TreeGenLoop(Int_t eventNr)
     local.GetXYZ(fRecInfo->fTRLocalCoord);     
     //
     if (fIndexRecTracks[fMCInfo->fLabel*20] >= 0) {
-      //track= (AliESDtrack*)fTracks->UncheckedAt(fIndexRecTracks[fMCInfo->fLabel*4]);
       track= (AliESDtrack*)fEvent->GetTrack(fIndexRecTracks[fMCInfo->fLabel*20]);
       //
       //
@@ -776,17 +885,16 @@ Int_t AliRecInfoMaker::TreeGenLoop(Int_t eventNr)
       fRecInfo->fFake     = fFakeRecTracks[fMCInfo->fLabel];
       fRecInfo->fMultiple = fMultiRecTracks[fMCInfo->fLabel];
       //
-      fRecInfo->Update(fMCInfo,fParamTPC,kTRUE, fEvent);          
+      fRecInfo->Update(fMCInfo,fParamTPC,kTRUE);          
     }
     else{
       fRecInfo->SetESDtrack(&dummytrack);
-      fRecInfo->Update(fMCInfo,fParamTPC,kFALSE, fEvent);
+      fRecInfo->Update(fMCInfo,fParamTPC,kFALSE);
     }
     fRecArray->AddAt(new AliESDRecInfo(*fRecInfo),fMCInfo->fLabel);
     fTreeCmp->Fill();
   }
   fTreeCmp->AutoSave();
-  //fTracks->Delete();
   printf("Time spended in TreeGenLoop\n");
   timer.Print();
   if (fDebug > 2) cerr<<"end of TreeGenLoop"<<endl;
@@ -943,6 +1051,8 @@ Int_t AliRecInfoMaker::BuildV0Info(Int_t eventNr)
 // loop over all entries for a given event, find corresponding 
 // rec. track and store in the fTreeCmp
 //
+  static TDatabasePDG pdgtable;
+
   TStopwatch timer;
   timer.Start();
   Int_t entry = fNextV0ToRead;
@@ -959,6 +1069,7 @@ Int_t AliRecInfoMaker::BuildV0Info(Int_t eventNr)
   while (entry < nParticlesTR) {
     fTreeGenV0->GetEntry(entry);
     entry++;
+    fRecV0Info->Reset();  //reset all variables
     if (eventNr < fGenV0Info->GetMinus().fEventNr) continue;
     if (eventNr > fGenV0Info->GetMinus().fEventNr) continue;;
     //
@@ -1020,6 +1131,9 @@ Int_t AliRecInfoMaker::BuildV0Info(Int_t eventNr)
          fRecV0Info->fV0its->Update(vertex);
        }
       }
+      //
+      // ????
+      // 
       if (TMath::Abs(fGenV0Info->GetMinus().fPdg)==11 &&TMath::Abs(fGenV0Info->GetPlus().fPdg)==11){
        if (fRecV0Info->fDist2>10){
          fRecV0Info->Update(vertex);
@@ -1035,57 +1149,95 @@ Int_t AliRecInfoMaker::BuildV0Info(Int_t eventNr)
     Int_t label =  TMath::Min(fGenV0Info->GetMinus().fLabel,fGenV0Info->GetPlus().fLabel);
     Int_t label2 = TMath::Max(fGenV0Info->GetMinus().fLabel,fGenV0Info->GetPlus().fLabel);    
     AliV0 *v0MI=0;
+    AliV0 *v0MIOff=0;
     fRecV0Info->fRecStatus   =0;
     fRecV0Info->fMultiple    = fMultiRecV0[label];
-    fRecV0Info->fV0Multiple=0;
+    fRecV0Info->fV0MultipleOn=0;
+    fRecV0Info->fV0MultipleOff=0;
     //
     if (fMultiRecV0[label]>0 || fMultiRecV0[label2]>0){
 
       //      for (Int_t j=0;j<TMath::Min(fMultiRecV0s[label],100);j++){
-     //  for (Int_t j=TMath::Min(fMultiRecV0[label],Short_t(20))-1;j>=0;j--){
-//     Int_t index = fIndexRecV0[label*20+j];
-//     if (index<0) continue;
-//     AliV0 *v0MI2  = (AliV0*)fEvent->GetV0(index);
-//     if (TMath::Abs(v0MI2->GetLabel(0))==label &&TMath::Abs(v0MI2->GetLabel(1))==label2) {
-//       v0MI =v0MI2;
-//       fRecV0Info->fV0Multiple++;
-//       fSignedV0[index]=1;
-//     }
-//     if (TMath::Abs(v0MI2->GetLabel(1))==label &&TMath::Abs(v0MI2->GetLabel(0))==label2) {
-//       v0MI =v0MI2;
-//       fRecV0Info->fV0Multiple++;
-//       fSignedV0[index]=1;
-//     }
-//       }
+      for (Int_t j=TMath::Min(fMultiRecV0[label],Short_t(20))-1;j>=0;j--){
+       Int_t index = fIndexRecV0[label*20+j];
+       if (index<0) continue;
+       AliV0 *v0MI2  = (AliV0*)fEvent->GetV0(index);
+       // get track labels
+       AliESDtrack * trackn = fEvent->GetTrack((v0MI2->GetNindex()));
+       AliESDtrack * trackp = fEvent->GetTrack((v0MI2->GetPindex()));
+       Int_t vlabeln = (trackn==0) ? -1 : trackn->GetLabel(); 
+       Int_t vlabelp = (trackp==0) ? -1 : trackp->GetLabel(); 
+       fRecV0Info->fLab[0]=TMath::Abs(vlabelp);
+       fRecV0Info->fLab[1]=TMath::Abs(vlabeln); 
+       //
+       if (TMath::Abs(vlabeln)==label &&TMath::Abs(vlabelp)==label2) {
+         if (v0MI2->GetOnFlyStatus()) {
+           v0MI =v0MI2;
+           fRecV0Info->fV0MultipleOn++;
+         }else  {
+           v0MIOff = v0MI2;
+           fRecV0Info->fV0MultipleOff++;
+         }
+         fSignedV0[index]=1;
+       }
+       if (TMath::Abs(vlabelp)==label &&TMath::Abs(vlabeln)==label2) {
+         if (v0MI2->GetOnFlyStatus()){
+           v0MI =v0MI2;
+           fRecV0Info->fV0MultipleOn++;
+         }else  {
+           v0MIOff = v0MI2;
+           fRecV0Info->fV0MultipleOff++;
+         }
+         fSignedV0[index]=1;
+       }
+      }
     }
     if (v0MI){
-      fRecV0Info->fV0rec = v0MI;
+      new (fRecV0Info->fV0rec) AliV0(*v0MI);
       fRecV0Info->fRecStatus=1;
     }
-
+    if (v0MIOff){
+      new (fRecV0Info->fV0recOff) AliV0(*v0MIOff);
+      fRecV0Info->fRecStatus=1;
+    }
+    Int_t mpdg = fGenV0Info->GetMother().GetPdgCode();
+    Float_t mass = ( pdgtable.GetParticle(mpdg)==0) ? 0 :pdgtable.GetParticle(mpdg)->Mass();
+    fRecV0Info->UpdateKF(*esdvertex,
+                        fGenV0Info->GetPlus().GetPdg(),
+                        fGenV0Info->GetMinus().GetPdg(),
+                        mass);
     fTreeCmpV0->Fill();
   }
   //
   // write fake v0s
-
+  //
   Int_t nV0MIs = fEvent->GetNumberOfV0s();
   for (Int_t i=0;i<nV0MIs;i++){
     if (fSignedV0[i]==0){
       AliV0 *v0MI  = (AliV0*)fEvent->GetV0(i);
       if (!v0MI) continue;
+      fRecV0Info->Reset();  //reset all variables
       //
-      fRecV0Info->fV0rec = v0MI;
+      new (fRecV0Info->fV0rec) AliV0(*v0MI);
       fRecV0Info->fV0Status  =-10;
       fRecV0Info->fRecStatus =-2;
       //
- //      AliESDRecInfo*  fRecInfo1 = (AliESDRecInfo*)fRecArray->At(TMath::Abs(v0MI->GetLabel(0)));
-//       AliESDRecInfo*  fRecInfo2 = (AliESDRecInfo*)fRecArray->At(TMath::Abs(v0MI->GetLabel(1)));
-//       if (fRecInfo1 && fRecInfo2){
-//     fRecV0Info->fT1 = (*fRecInfo1);
-//     fRecV0Info->fT2 = (*fRecInfo2);
-//     fRecV0Info->fRecStatus =-1;
-//       }
+      AliESDtrack * trackn = fEvent->GetTrack((v0MI->GetNindex()));
+      AliESDtrack * trackp = fEvent->GetTrack((v0MI->GetPindex()));
+      Int_t vlabeln = (trackn==0) ? -1 : trackn->GetLabel(); 
+      Int_t vlabelp = (trackp==0) ? -1 : trackp->GetLabel(); 
+      fRecV0Info->fLab[0]=TMath::Abs(vlabelp);
+      fRecV0Info->fLab[1]=TMath::Abs(vlabeln);      
+      if (TMath::Abs(fRecV0Info->fLab[0] - fRecV0Info->fLab[1])<2) continue;
+      AliESDRecInfo*  fRecInfo1 = (AliESDRecInfo*)fRecArray->At(TMath::Abs(vlabeln));
+      AliESDRecInfo*  fRecInfo2 = (AliESDRecInfo*)fRecArray->At(TMath::Abs(vlabelp));
+      if (fRecInfo1 && fRecInfo2){
+       fRecV0Info->fT1 = (*fRecInfo1);
+       fRecV0Info->fT2 = (*fRecInfo2);
+       fRecV0Info->fRecStatus =-1;
+      }
       fRecV0Info->Update(vertex);
+      fRecV0Info->UpdateKF(*esdvertex,211,211,0.49767);
       fTreeCmpV0->Fill();
     }
   }