]> 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 cb2001b8315abc2d112d8e546acdebd3c2d21d3b..93c93eb165b9c617f07ac73cdf99e500dce85e4a 100644 (file)
@@ -64,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);
@@ -93,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);
@@ -103,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)");
@@ -141,7 +141,8 @@ TProfile prof("prof","prof",10,0.5,5);
 #include "TTree.h"
 #include "TStopwatch.h"
 #include "TVector3.h"
-#include "Getline.h"
+#include "TGeoManager.h"
+//#include "Getline.h"
 //
 //ALIROOT includes
 //
@@ -165,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"
 
 
@@ -187,48 +194,85 @@ 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()
-// {
-//   //
-//   // Default constructor - never used
-//   //
-//   Reset();
-// }
-
 ////////////////////////////////////////////////////////////////////////
 AliRecInfoMaker::AliRecInfoMaker(const char* fnGenTracks,
-                  const char* fnCmp,
-                  const char* fnGalice,
-                  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
@@ -252,7 +296,7 @@ AliRecInfoMaker::AliRecInfoMaker(const char* fnGenTracks,
   //
   fLoader = AliRunLoader::Open(fnGalice);
   if (gAlice){
-    //delete gAlice->GetRunLoader();
+    //delete AliRunLoader::Instance();
     delete gAlice;
     gAlice = 0x0;
   }
@@ -275,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;
   }
@@ -293,7 +395,8 @@ AliRecInfoMaker::~AliRecInfoMaker()
 Int_t AliRecInfoMaker::SetIO()
 {
   //
-  // 
+  // SetIO  - Create the input trees
+  //
   CreateTreeCmp();
   if (!fTreeCmp) return 1;
   fParamTPC = GetTPCParam();
@@ -421,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;
@@ -591,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;
   }
   
@@ -642,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");
@@ -686,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);
@@ -697,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) {
@@ -938,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;
@@ -954,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;;
     //
@@ -1015,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);
@@ -1030,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();
     }
   }