]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/AliRecInfoMaker.cxx
Updated calibration object (ZEM values for centrality selection added)
[u/mrichter/AliRoot.git] / PWG1 / AliRecInfoMaker.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
7  * Permission to use, copy, modify and distribute this software and its   *
8  * documentation strictly for non-commercial purposes is hereby granted   *
9  * without fee, provided that the above copyright notice appears in all   *
10  * copies and that both the copyright notice and this permission notice   *
11  * appear in the supporting documentation. The authors make no claims     *
12  * about the suitability of this software for any purpose. It is          *
13  * provided "as is" without express or implied warranty.                  *
14  **************************************************************************/
15
16
17 ///////////////////////////////////////////////////////////////////////////////
18 //                                                                           //
19 //  Time Projection Chamber                                                  //
20 //  Comparison macro for ESD                                                 //
21 //  responsible: 
22 //  marian.ivanov@cern.ch                                                    //
23 //
24 //
25
26 /* 
27 marian.ivanov@cern.ch 
28 Usage:
29  
30
31
32 gSystem->Load("libPWG1.so");
33 //
34 AliRecInfoMaker *t2 = new AliRecInfoMaker("genTracks.root","cmpESDTracks.root","galice.root",0,0);
35 t2->Exec();
36
37
38 TFile f("cmpESDTracks.root");
39 TTree * tree = (TTree*)f.Get("ESDcmpTracks");
40
41 AliTreeDraw comp;
42 comp.SetTree(tree)
43
44
45
46 //
47 //some cuts definition
48 TCut cprim("cprim","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)<0.01&&abs(MC.fVDist[2])<0.01")
49 //TCut cprim("cprim","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)<0.5&&abs(MC.fVDist[2])<0.5")
50 //TCut citsin("citsin","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)<3.9");
51 TCut citsin("citsin","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)<5");
52 TCut csec("csec","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)>0.5");
53
54
55 TCut crec("crec","fReconstructed==1");
56 TCut cteta1("cteta1","abs(MC.fParticle.Theta()/3.1415-0.5)<0.25");
57 TCut cteta05("cteta05","abs(MC.fParticle.Theta()/3.1415-0.5)<0.1");
58
59 TCut cpos1("cpos1","abs(MC.fParticle.fVz/sqrt(MC.fParticle.fVx*MC.fParticle.fVx+MC.fParticle.fVy*MC.fParticle.fVy))<1");
60 TCut csens("csens","abs(sqrt(fVDist[0]**2+fVDist[1]**2)-170)<50");
61 TCut cmuon("cmuon","abs(MC.fParticle.fPdgCode==-13)");
62 TCut cchi2("cchi2","fESDtrack.fITSchi2MIP[0]<7.&&fESDtrack.fITSchi2MIP[1]<5.&&fESDtrack.fITSchi2MIP[2]<7.&&fESDtrack.fITSchi2MIP[3]<7.5&&fESDtrack.fITSchi2MIP[4]<6.")
63
64
65 //
66 //example
67 comp.fTree->SetAlias("radius","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)");
68 comp.fTree->SetAlias("direction","MC.fParticle.fVx*MC.fParticle.fPx+MC.fParticle.fVy*MC.fParticle.fPy");
69 comp.fTree->SetAlias("decaydir","MC.fTRdecay.fX*MC.fTRdecay.fPx+MC.fTRdecay.fY*MC.fTRdecay.fPy");
70 comp.fTree->SetAlias("theta","MC.fTrackRef.Theta()");
71 comp.fTree->SetAlias("primdca","sqrt(RC.fITStrack.fD[0]**2+RC.fITStrack.fD[1]**2)");
72 comp.fTree->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
73 comp.fTree->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
74
75
76 TH1F his("his","his",100,0,20);
77 TH1F hpools("hpools","hpools",100,-7,7);
78 TH1F hfake("hfake","hfake",1000,0,150);
79 TProfile profp0("profp0","profp0",20,-0.4,0.9)
80
81 comp.DrawXY("fTPCinP0[3]","fTPCDelta[4]/fTPCinP1[3]","fReconstructed==1"+cprim,"1",4,0.2,1.5,-0.06,0.06)
82 comp.fRes->Draw();
83 comp.fMean->Draw();  
84
85 comp.DrawXY("fITSinP0[3]","fITSDelta[4]/fITSinP1[3]","fReconstructed==1&&fITSOn"+cprim,"1",4,0.2,1.5,-0.06,0.06)
86 comp.fRes->Draw();
87
88 comp.Eff("fTPCinP0[3]","fRowsWithDigits>120"+cteta1+cpos1+cprim,"fTPCOn",20,0.2,1.5)
89 comp.fRes->Draw();
90
91 comp.Eff("fTPCinP0[3]","fRowsWithDigits>120"+cteta1+cpos1+cprim,"fTPCOn&&fITSOn&&fESDtrack.fITSFakeRatio<0.1",10,0.2,1.5)
92 comp.fRes->Draw();
93 comp.Eff("fTPCinP0[3]","fRowsWithDigits>120"+cteta1+cpos1+cprim,"fTPCOn&&fITSOn&&fESDtrack.fITSFakeRatio>0.1",10,0.2,1.5)
94 comp.fRes->Draw();
95
96 comp.fTree->Draw("fESDtrack.fITSsignal/fESDtrack.fTPCsignal","fITSOn&&fTPCOn&&fESDtrack.fITSFakeRatio==0") 
97
98 TH1F his("his","his",100,0,20);
99 TH1F hpools("hpools","hpools",100,-7,7);
100
101 TH2F * hdedx0 = new TH2F("dEdx0","dEdx0",100, 0,2,200,0,550); hdedx0->SetMarkerColor(1);
102 TH2F * hdedx1 = new TH2F("dEdx1","dEdx1",100, 0,2,200,0,550); hdedx1->SetMarkerColor(4);
103 TH2F * hdedx2 = new TH2F("dEdx2","dEdx2",100, 0,2,200,0,550); hdedx2->SetMarkerColor(3);
104 TH2F * hdedx3 = new TH2F("dEdx3","dEdx3",100, 0,2,200,0,550); hdedx3->SetMarkerColor(2);
105
106 comp.fTree->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx0","fITSOn&&abs(fPdg)==211&&fITStrack.fN==6"+cprim) 
107 comp.fTree->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx1","fITSOn&&abs(fPdg)==2212&&fITStrack.fN==6"+cprim) 
108 comp.fTree->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx2","fITSOn&&abs(fPdg)==321&&fITStrack.fN==6"+cprim) 
109 comp.fTree->Draw("fESDtrack.fITSsignal:MC.fParticle.P()>>dEdx3","fITSOn&&abs(fPdg)==11&&fITStrack.fN==6"+cprim) 
110
111
112 comp.fTree->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx0","fTRDOn&&abs(fPdg)==211&&fTRDtrack.fN>40&&fStatus[2]>1") 
113 comp.fTree->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx1","fTRDOn&&abs(fPdg)==2212&&fTRDtrack.fN>40&&fStatus[2]>1") 
114 comp.fTree->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx2","fTRDOn&&abs(fPdg)==321&&fTRDtrack.fN>40&&fStatus[2]>1") 
115 comp.fTree->Draw("fESDtrack.fTRDsignal:MC.fParticle.P()>>dEdx3","fTRDOn&&abs(fPdg)==11&&fTRDtrack.fN>40&&fStatus[2]>1") 
116
117 comp.fTree->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx0","fTPCOn&&abs(fPdg)==211&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
118 comp.fTree->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx1","fTPCOn&&abs(fPdg)==2212&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
119 comp.fTree->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx2","fTPCOn&&abs(fPdg)==321&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
120 comp.fTree->Draw("fESDtrack.fTPCsignal:fTPCinP0[4]>>dEdx3","fTPCOn&&abs(fPdg)==11&&fESDtrack.fTPCncls>180&&fESDtrack.fTPCsignal>10"+cteta1); 
121
122 hdedx3->SetXTitle("P(GeV/c)");
123 hdedx3->SetYTitle("dEdx(unit)");
124 hdedx3->Draw(); hdedx1->Draw("same"); hdedx2->Draw("same"); hdedx0->Draw("same");
125
126 comp.DrawXY("fITSinP0[3]","fITSPools[4]","fReconstructed==1&&fPdg==-211&&fITSOn"+cprim,"1",4,0.2,1.0,-8,8)
127
128 TProfile prof("prof","prof",10,0.5,5);
129
130
131
132
133 */
134
135
136 #include <stdio.h>
137 #include <string.h>
138 //ROOT includes
139 #include "Rtypes.h"
140 #include "TFile.h"
141 #include "TTree.h"
142 #include "TStopwatch.h"
143 #include "TVector3.h"
144 #include "Getline.h"
145 //
146 //ALIROOT includes
147 //
148 #include "AliRun.h"
149 #include "AliESDtrack.h"
150 #include "AliTPCParam.h"
151 #include "AliTPC.h"
152 #include "AliTrackReference.h"
153 #include "AliTPCParamSR.h"
154 #include "AliTracker.h"
155 #include "AliESDEvent.h"
156 #include "AliESD.h"
157 #include "AliESDfriend.h"
158 #include "AliESDtrack.h"
159 #include "AliTPCseed.h"
160 #include "AliITStrackMI.h"
161 #include "AliESDVertex.h"
162 #include "AliExternalTrackParam.h"
163 #include "AliESDkink.h"
164 #include "AliESDv0.h"
165 #include "AliV0.h"
166 //
167 #include "AliTreeDraw.h"
168 #include "AliGenInfo.h"
169 #include "AliRecInfo.h"
170 #include "AliRecInfoMaker.h"
171
172
173
174 ClassImp(AliRecInfoMaker)
175
176
177
178
179 AliTPCParam * AliRecInfoMaker::GetTPCParam(){
180   //
181   // create TPC param
182   //
183   AliTPCParamSR * par = new AliTPCParamSR;
184   par->Update();
185   return par;
186 }
187
188
189
190 void MakeAliases(AliTreeDraw&comp)
191 {
192   //
193   // aliases definition
194   //
195   comp.T()->SetAlias("radius","TMath::Sqrt(MC.fVDist[0]**2+MC.fVDist[1]**2)");
196   comp.T()->SetAlias("direction","MC.fParticle.fVx*MC.fParticle.fPx+MC.fParticle.fVy*MC.fParticle.fPy");
197   comp.T()->SetAlias("decaydir","MC.fTRdecay.fX*MC.fTRdecay.fPx+MC.fTRdecay.fY*MC.fTRdecay.fPy");
198   comp.T()->SetAlias("theta","MC.fTrackRef.Theta()");
199   comp.T()->SetAlias("primdca","sqrt(RC.fITStrack.fD[0]**2+RC.fITStrack.fD[1]**2)");
200   comp.T()->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
201   comp.T()->SetAlias("trdchi2","fTRDtrack.fChi2/fTRDtrack.fN");
202   
203   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.");
204   
205   comp.T()->SetAlias("dtofmc2","fESDtrack.fTrackTime[2]-(10^12*MC.fTOFReferences[0].fTime)");
206   comp.T()->SetAlias("dtofrc2","(fESDtrack.fTrackTime[2]-fESDtrack.fTOFsignal)");
207
208   comp.T()->SetAlias("psum","fESDtrack.fTOFr[4]+fESDtrack.fTOFr[3]+fESDtrack.fTOFr[2]+fESDtrack.fTOFr[1]+fESDtrack.fTOFr[0]");
209   comp.T()->SetAlias("P0","fESDtrack.fTOFr[0]/psum");
210   comp.T()->SetAlias("P1","fESDtrack.fTOFr[1]/psum");
211   comp.T()->SetAlias("P2","fESDtrack.fTOFr[2]/psum");
212   comp.T()->SetAlias("P3","fESDtrack.fTOFr[3]/psum");
213   comp.T()->SetAlias("P4","fESDtrack.fTOFr[4]/psum");
214   comp.T()->SetAlias("MaxP","max(max(max(P0,P1),max(P2,P3)),P4)");
215 }
216
217
218 // ////////////////////////////////////////////////////////////////////////
219 // AliRecInfoMaker::AliRecInfoMaker()
220 // {
221 //   //
222 //   // Default constructor - never used
223 //   //
224 //   Reset();
225 // }
226
227 ////////////////////////////////////////////////////////////////////////
228 AliRecInfoMaker::AliRecInfoMaker(const char* fnGenTracks,
229                    const char* fnCmp,
230                    const char* fnGalice,
231                    Int_t nEvents, Int_t firstEvent)
232 {
233   // AliRecInfoMaker - connencts the MC information with reconstructed information
234   // fnGenTracks  - file with MC to be created before using AliGenInfoMaker
235   // fnCmp        - file name  to be created  
236   // fnGalice     - file with Loaders - usualy galice.root 
237   //  
238   // nEvent       - number of event s to be analyzed
239   // AliRecInfoMaker *t2 = new AliRecInfoMaker("genTracks.root","cmpESDTracks.root","galice.root",0,0);
240   //
241
242
243   Reset();
244   //  fFnGenTracks = fnGenTracks;
245   //  fFnCmp = fnCmp;
246   sprintf(fFnGenTracks,"%s",fnGenTracks);
247   sprintf(fFnCmp,"%s",fnCmp);
248
249   fFirstEventNr = firstEvent;
250   fEventNr = firstEvent;
251   fNEvents = nEvents;
252   //
253   fLoader = AliRunLoader::Open(fnGalice);
254   if (gAlice){
255     //delete gAlice->GetRunLoader();
256     delete gAlice;
257     gAlice = 0x0;
258   }
259   if (fLoader->LoadgAlice()){
260     cerr<<"Error occured while l"<<endl;
261   }
262   Int_t nall = fLoader->GetNumberOfEvents();
263   if (nEvents==0) {
264     nEvents =nall;
265     fNEvents=nall;
266     fFirstEventNr=0;
267   }    
268
269   if (nall<=0){
270     cerr<<"no events available"<<endl;
271     fEventNr = 0;
272     return;
273   }
274   if (firstEvent+nEvents>nall) {
275     fEventNr = nall-firstEvent;
276     cerr<<"restricted number of events availaible"<<endl;
277   }
278   AliMagF * magf = gAlice->Field();
279   AliTracker::SetFieldMap(magf,0);
280
281 }
282
283
284 ////////////////////////////////////////////////////////////////////////
285 AliRecInfoMaker::~AliRecInfoMaker()
286 {
287   if (fLoader) {
288     delete fLoader;
289   }
290 }
291
292 //////////////////////////////////////////////////////////////
293 Int_t AliRecInfoMaker::SetIO()
294 {
295   //
296   // 
297   CreateTreeCmp();
298   if (!fTreeCmp) return 1;
299   fParamTPC = GetTPCParam();
300   //
301   if (!ConnectGenTree()) {
302     cerr<<"Cannot connect tree with generated tracks"<<endl;
303     return 1;
304   }
305   return 0;
306 }
307
308 //////////////////////////////////////////////////////////////
309
310 Int_t AliRecInfoMaker::SetIO(Int_t eventNr)
311 {
312   //
313   // 
314   // SET INPUT
315   //
316   TFile f("AliESDs.root");
317   //
318  
319   TTree* tree = (TTree*) f.Get("esdTree");
320   tree->SetBranchStatus("*",1);
321   fEvent = new AliESDEvent;
322   
323   if (tree->GetBranch("ESD")){
324     //    tree->SetBranchAddress("ESD", &fEvent);
325     // tree->SetBranchAddress("ESDfriend.",&fESDfriend);
326     // tree->GetEntry(eventNr);
327     // fEvent->SetESDfriend(fESDfriend);    
328   }else{
329     fEvent->ReadFromTree(tree);
330     fESDfriend = (AliESDfriend*)fEvent->FindListObject("AliESDfriend"); 
331     tree->GetEntry(eventNr);
332     fEvent->SetESDfriend(fESDfriend); 
333   }    
334   
335
336
337   if (!fEvent) return 1;
338
339   return 0;
340 }
341
342
343
344 ////////////////////////////////////////////////////////////////////////
345 void AliRecInfoMaker::Reset()
346 {
347   //
348   // Reset the class
349   //
350   fEventNr = 0;
351   fNEvents = 0;
352   fTreeCmp = 0;
353   fTreeCmpKinks =0;
354   fTreeCmpV0 =0;
355   //  fFnCmp = "cmpTracks.root";
356   fFileGenTracks = 0;
357   fDebug = 0;
358   //
359   fParamTPC = 0;
360   fEvent =0;
361 }
362
363 ////////////////////////////////////////////////////////////////////////
364 Int_t AliRecInfoMaker::Exec(Int_t nEvents, Int_t firstEventNr)
365 {
366   //
367   // Exec comparison for subrange of events
368   //
369   fNEvents = nEvents;
370   fFirstEventNr = firstEventNr;
371   return Exec();
372 }
373
374 ////////////////////////////////////////////////////////////////////////
375 Int_t AliRecInfoMaker::Exec()
376 {
377   //
378   // Exec comparison
379   //
380   TStopwatch timer;
381   timer.Start();
382
383   if (SetIO()==1) 
384     return 1;
385    
386   fNextTreeGenEntryToRead = 0;
387   fNextKinkToRead = 0;
388   fNextV0ToRead   =0;
389   cerr<<"fFirstEventNr, fNEvents: "<<fFirstEventNr<<" "<<fNEvents<<endl;
390   for (Int_t eventNr = fFirstEventNr; eventNr < fFirstEventNr+fNEvents;
391        eventNr++) {
392     fEventNr = eventNr;
393     SetIO(fEventNr);
394     fNParticles = gAlice->GetEvent(fEventNr);    
395
396     fIndexRecTracks = new Short_t[fNParticles*20];  //write at maximum 4 tracks corresponding to particle
397     fIndexRecKinks  = new Short_t[fNParticles*20];  //write at maximum 20 tracks corresponding to particle
398     fIndexRecV0  = new Short_t[fNParticles*20];  //write at maximum 20 tracks corresponding to particle
399
400     fFakeRecTracks = new Short_t[fNParticles];
401     fMultiRecTracks = new Short_t[fNParticles];
402     fMultiRecKinks = new Short_t[fNParticles];
403     fMultiRecV0 = new Short_t[fNParticles];
404
405     for (Int_t i = 0; i<fNParticles; i++) {
406       for (Int_t j=0;j<20;j++){
407         fIndexRecTracks[20*i+j] = -1;
408         fIndexRecKinks[20*i+j]  = -1;
409         fIndexRecV0[20*i+j]  = -1;
410       }
411       fFakeRecTracks[i] = 0;
412       fMultiRecTracks[i] = 0;
413       fMultiRecKinks[i] = 0;
414       fMultiRecV0[i] = 0;      
415     }
416   
417     cout<<"Start to process event "<<fEventNr<<endl;
418     cout<<"\tfNParticles = "<<fNParticles<<endl;
419     if (fDebug>2) cout<<"\tStart loop over TreeT"<<endl;
420     if (TreeTLoop()>0) return 1;
421
422     if (fDebug>2) cout<<"\tStart loop over tree genTracks"<<endl;
423     if (TreeGenLoop(eventNr)>0) return 1;
424     BuildKinkInfo0(eventNr);
425     //BuildV0Info(eventNr); // no V0 info for a moment
426     fRecArray->Delete();
427
428     if (fDebug>2) cout<<"\tEnd loop over tree genTracks"<<endl;
429
430     delete [] fIndexRecTracks;
431     delete [] fIndexRecKinks;
432     delete [] fIndexRecV0;
433     delete [] fFakeRecTracks;
434     delete [] fMultiRecTracks;
435     delete [] fMultiRecKinks;
436     delete [] fMultiRecV0;
437   }
438
439   CloseOutputFile();
440
441   cerr<<"Exec finished"<<endl;
442   timer.Stop();
443   timer.Print();
444   return 0;
445
446 }
447 ////////////////////////////////////////////////////////////////////////
448 Bool_t AliRecInfoMaker::ConnectGenTree()
449 {
450 //
451 // connect all branches from the genTracksTree
452 // use the same variables as for the new cmp tree, it may work
453 //
454   fFileGenTracks = TFile::Open(fFnGenTracks,"READ");
455   if (!fFileGenTracks) {
456     cerr<<"Error in ConnectGenTree: cannot open file "<<fFnGenTracks<<endl;
457     return kFALSE;
458   }
459   fTreeGenTracks = (TTree*)fFileGenTracks->Get("genTracksTree");
460   if (!fTreeGenTracks) {
461     cerr<<"Error in ConnectGenTree: cannot find genTracksTree in the file "
462         <<fFnGenTracks<<endl;
463     return kFALSE;
464   }
465   //
466   fMCInfo = new AliMCInfo;
467   fTreeGenTracks->SetBranchAddress("MC",&fMCInfo);
468   //
469   //
470   fTreeGenKinks = (TTree*)fFileGenTracks->Get("genKinksTree");
471   if (!fTreeGenKinks) {
472     cerr<<"Error in ConnectGenTree: cannot find genTracksTree in the file "
473         <<fFnGenTracks<<endl;
474     //return kFALSE;
475   }
476   else{
477     fGenKinkInfo = new AliGenKinkInfo;
478     fTreeGenKinks->SetBranchAddress("MC",&fGenKinkInfo);
479   }
480
481   fTreeGenV0 = (TTree*)fFileGenTracks->Get("genV0Tree");
482   if (!fTreeGenV0) {
483     cerr<<"Error in ConnectGenTree: cannot find genTracksTree in the file "
484         <<fFnGenTracks<<endl;
485     //return kFALSE;
486   }
487   else{
488     fGenV0Info = new AliGenV0Info;
489     fTreeGenV0->SetBranchAddress("MC",&fGenV0Info);
490   }
491   //
492   if (fDebug > 1) {
493     cout<<"Number of gen. tracks with TR: "<<fTreeGenTracks->GetEntries()<<endl;
494   }
495   return kTRUE;
496 }
497
498
499 ////////////////////////////////////////////////////////////////////////
500 void AliRecInfoMaker::CreateTreeCmp() 
501 {
502   //
503   // Create file and tree with comparison information 
504   //
505   fFileCmp = TFile::Open(fFnCmp,"RECREATE");
506   if (!fFileCmp) {
507     cerr<<"Error in CreateTreeCmp: cannot open file "<<fFnCmp<<endl;
508     return;
509   }
510   //
511   //
512   fTreeCmp    = new TTree("ESDcmpTracks","ESDcmpTracks");
513   fMCInfo = new AliMCInfo;
514   fRecInfo = new AliESDRecInfo;
515   AliESDtrack * esdTrack = new AliESDtrack; 
516   //  AliITStrackMI * itsTrack = new AliITStrackMI;  
517   fTreeCmp->Branch("MC","AliMCInfo",&fMCInfo,256000);
518   fTreeCmp->Branch("RC","AliESDRecInfo",&fRecInfo,256000);
519   //  fTreeCmp->Branch("ITS","AliITStrackMI",&itsTrack);
520   delete esdTrack;
521   //
522   //
523   fTreeCmpKinks    = new TTree("ESDcmpKinks","ESDcmpKinks"); 
524   fGenKinkInfo     = new AliGenKinkInfo;
525   fRecKinkInfo     = new AliESDRecKinkInfo;
526   fTreeCmpKinks->Branch("MC.","AliGenKinkInfo",&fGenKinkInfo,256000);
527   fTreeCmpKinks->Branch("RC.","AliESDRecKinkInfo",&fRecKinkInfo,256000);
528   //
529   //
530   fTreeCmpV0       = new TTree("ESDcmpV0","ESDcmpV0"); 
531   fGenV0Info     = new AliGenV0Info;
532   fRecV0Info     = new AliESDRecV0Info;
533   fTreeCmpV0->Branch("MC.","AliGenV0Info",   &fGenV0Info,256000);
534   fTreeCmpV0->Branch("RC.","AliESDRecV0Info",&fRecV0Info,256000);
535   //
536   fTreeCmp->AutoSave(); 
537   fTreeCmpKinks->AutoSave(); 
538   fTreeCmpV0->AutoSave(); 
539 }
540
541 ////////////////////////////////////////////////////////////////////////
542 void AliRecInfoMaker::CloseOutputFile()  
543 {
544   //
545   // Close output file
546   //
547
548   if (!fFileCmp) {
549     cerr<<"File "<<fFnCmp<<" not found as an open file."<<endl;
550     return;
551   }
552   fFileCmp->cd();
553   fTreeCmp->Write();    
554   delete fTreeCmp;
555   
556   fFileCmp->Close();
557   delete fFileCmp;
558   return;
559 }
560 ////////////////////////////////////////////////////////////////////////
561
562 TVector3 AliRecInfoMaker::TR2Local(AliTrackReference *trackRef,
563                             AliTPCParam *paramTPC) {
564
565   //
566   // Transform position to the local coord frame
567   //
568   
569   Float_t x[3] = { trackRef->X(),trackRef->Y(),trackRef->Z()};
570   Int_t index[4];
571   paramTPC->Transform0to1(x,index);
572   paramTPC->Transform1to2Ideal(x,index);
573   return TVector3(x);
574 }
575 ////////////////////////////////////////////////////////////////////////
576
577 Int_t AliRecInfoMaker::TreeTLoop()
578 {
579   //
580   // loop over all ESD reconstructed tracks and store info in memory
581   //
582   // + loop over all reconstructed kinks
583   TStopwatch  timer;
584   timer.Start();
585   //  
586   Int_t nEntries = (Int_t)fEvent->GetNumberOfTracks();  
587   Int_t nKinks = (Int_t) fEvent->GetNumberOfKinks();
588   Int_t nV0MIs = (Int_t) fEvent->GetNumberOfV0s();
589   fSignedKinks = new Short_t[nKinks];
590   fSignedV0    = new Short_t[nV0MIs];
591   //
592   // load kinks to the memory
593   for (Int_t i=0; i<nKinks;i++){
594     AliESDkink * kink =fEvent->GetKink(i);
595     fSignedKinks[i]=0;
596   }
597   //
598   for (Int_t i=0; i<nV0MIs;i++){
599     AliV0 * v0MI = (AliV0*)fEvent->GetV0(i);
600     fSignedV0[i]=0;
601   }
602   
603   //
604   //
605   AliESDtrack * track=0;
606   for (Int_t iEntry=0; iEntry<nEntries;iEntry++){
607     track = (AliESDtrack*)fEvent->GetTrack(iEntry);
608     //
609     Int_t label = track->GetLabel();
610     Int_t absLabel = abs(label);
611     if (absLabel < fNParticles) {
612       //      fIndexRecTracks[absLabel] =  iEntry;
613       if (label < 0) fFakeRecTracks[absLabel]++;      
614       if (fMultiRecTracks[absLabel]>0){
615         if (fMultiRecTracks[absLabel]<20)
616           fIndexRecTracks[absLabel*20+fMultiRecTracks[absLabel]] =  iEntry;     
617       }
618       else      
619         fIndexRecTracks[absLabel*20] =  iEntry;
620       fMultiRecTracks[absLabel]++;
621     }
622   }
623   // sort reconstructed kinks  
624   //
625   AliESDkink * kink=0;
626   for (Int_t iEntry=0; iEntry<nKinks;iEntry++){
627     kink = (AliESDkink*)fEvent->GetKink(iEntry);
628     if (!kink) continue;
629     //
630     Int_t label0 = TMath::Abs(kink->GetLabel(0));
631     Int_t label1 = TMath::Abs(kink->GetLabel(1));
632     Int_t absLabel = TMath::Min(label0,label1);
633     if (absLabel < fNParticles) {
634       if (fMultiRecKinks[absLabel]>0){
635         if (fMultiRecKinks[absLabel]<20)
636           fIndexRecKinks[absLabel*20+fMultiRecKinks[absLabel]] =  iEntry;       
637       }
638       else      
639         fIndexRecKinks[absLabel*20] =  iEntry;
640       fMultiRecKinks[absLabel]++;
641     }
642   }  
643   // --sort reconstructed V0
644   //
645 //   AliV0 * v0MI=0;
646 //   for (Int_t iEntry=0; iEntry<nV0MIs;iEntry++){
647 //     v0MI = (AliV0*)fEvent->GetV0(iEntry);
648 //     if (!v0MI) continue;
649 //     //
650 //     Int_t label0 = TMath::Abs(v0MI->GetLabel(0));
651 //     Int_t label1 = TMath::Abs(v0MI->GetLabel(1));
652 //     //
653 //     for (Int_t i=0;i<2;i++){
654 //       Int_t absLabel =  TMath::Abs(v0MI->GetLabel(i));
655 //       if (absLabel < fNParticles) {
656 //      if (fMultiRecV0[absLabel]>0){
657 //        if (fMultiRecV0[absLabel]<20)
658 //          fIndexRecV0[absLabel*20+fMultiRecV0[absLabel]] =  iEntry;   
659 //      }
660 //      else      
661 //        fIndexRecV0[absLabel*20] =  iEntry;
662 //      fMultiRecV0[absLabel]++;
663 //       }
664 //     }
665 //   }  
666
667
668   printf("Time spended in TreeTLoop\n");
669   timer.Print();
670   
671   if (fDebug > 2) cerr<<"end of TreeTLoop"<<endl;  
672   return 0;
673 }
674
675 ////////////////////////////////////////////////////////////////////////
676 Int_t AliRecInfoMaker::TreeGenLoop(Int_t eventNr)
677 {
678 //
679 // loop over all entries for a given event, find corresponding 
680 // rec. track and store in the fTreeCmp
681 //
682   TStopwatch timer;
683   timer.Start();
684   Int_t entry = fNextTreeGenEntryToRead;
685   Double_t nParticlesTR = fTreeGenTracks->GetEntriesFast();
686   cerr<<"fNParticles, nParticlesTR, fNextTreeGenEntryToRead: "<<fNParticles<<" "
687       <<nParticlesTR<<" "<<fNextTreeGenEntryToRead<<endl;
688   TBranch * branch = fTreeCmp->GetBranch("RC");
689   TBranch * branchF = fTreeCmp->GetBranch("F");
690   
691   branch->SetAddress(&fRecInfo); // set all pointers
692   fRecArray = new TObjArray(fNParticles);
693   AliESDtrack dummytrack;  //
694   AliESDfriendTrack dummytrackF;  //
695
696   while (entry < nParticlesTR) {
697     fTreeGenTracks->GetEntry(entry);
698     entry++;
699     if (eventNr < fMCInfo->fEventNr) continue;
700     if (eventNr > fMCInfo->fEventNr) continue;;
701     //
702     fNextTreeGenEntryToRead = entry-1;
703     if (fDebug > 2 && fMCInfo->fLabel < 10) {
704       cerr<<"Fill track with a label "<<fMCInfo->fLabel<<endl;
705     }
706     //    if (fMCInfo->fNTPCRef<1) continue; // not TPCref
707     //
708     fRecInfo->Reset();
709     AliESDtrack * track=0;
710     fRecInfo->fReconstructed =0;
711     TVector3 local = TR2Local(&(fMCInfo->fTrackRef),fParamTPC);
712     local.GetXYZ(fRecInfo->fTRLocalCoord);      
713     //
714     if (fIndexRecTracks[fMCInfo->fLabel*20] >= 0) {
715       track= (AliESDtrack*)fEvent->GetTrack(fIndexRecTracks[fMCInfo->fLabel*20]);
716       //
717       //
718       // find nearest track if multifound
719       //Int_t sign = Int_t(track->GetSign()*fMCInfo->fCharge);
720       //
721       Int_t status = 0;
722       if  ((track->GetStatus()&AliESDtrack::kITSrefit)>0) status++;
723       if  ((track->GetStatus()&AliESDtrack::kTPCrefit)>0) status++;
724       if  ((track->GetStatus()&AliESDtrack::kTRDrefit)>0) status++;
725
726       //
727       if (fIndexRecTracks[fMCInfo->fLabel*20+1]>0){
728         //
729         Double_t p[3];
730         track->GetInnerPxPyPz(p);
731         Float_t maxp = p[0]*p[0]+p[1]*p[1]+p[2]*p[2];
732         //
733         for (Int_t i=1;i<20;i++){
734           if (fIndexRecTracks[fMCInfo->fLabel*20+i]>=0){
735             AliESDtrack * track2 = (AliESDtrack*)fEvent->GetTrack(fIndexRecTracks[fMCInfo->fLabel*20+i]);
736             if (!track2) continue;
737             //Int_t sign2 = track->GetSign()*fMCInfo->fCharge; //           
738             //if (sign2<0) continue;
739             track2->GetInnerPxPyPz(p);
740             Float_t mom = p[0]*p[0]+p[1]*p[1]+p[2]*p[2];
741             /*
742             if (sign<0){
743               sign = sign2;
744               track = track2;
745               maxp = mom;
746               continue;
747             }
748             */
749             //
750             Int_t status2 = 0;
751             if  ((track2->GetStatus()&AliESDtrack::kITSrefit)>0) status2++;
752             if  ((track2->GetStatus()&AliESDtrack::kTPCrefit)>0) status2++;
753             if  ((track2->GetStatus()&AliESDtrack::kTRDrefit)>0) status2++;
754             if (status2<status) continue;
755             //
756             if (mom<maxp) continue;
757             maxp = mom;
758             track = track2;
759             //
760           }
761         }
762       } 
763       //
764       if (track) {
765         fRecInfo->SetESDtrack(track);
766       }else{
767         fRecInfo->SetESDtrack(&dummytrack);
768       }
769       //
770
771       fRecInfo->fReconstructed = 1;
772       fRecInfo->fFake     = fFakeRecTracks[fMCInfo->fLabel];
773       fRecInfo->fMultiple = fMultiRecTracks[fMCInfo->fLabel];
774       //
775       fRecInfo->Update(fMCInfo,fParamTPC,kTRUE);          
776     }
777     else{
778       fRecInfo->SetESDtrack(&dummytrack);
779       fRecInfo->Update(fMCInfo,fParamTPC,kFALSE);
780     }
781     fRecArray->AddAt(new AliESDRecInfo(*fRecInfo),fMCInfo->fLabel);
782     fTreeCmp->Fill();
783   }
784   fTreeCmp->AutoSave();
785   printf("Time spended in TreeGenLoop\n");
786   timer.Print();
787   if (fDebug > 2) cerr<<"end of TreeGenLoop"<<endl;
788
789   return 0;
790 }
791
792
793
794 ////////////////////////////////////////////////////////////////////////
795 ////////////////////////////////////////////////////////////////////////
796 ////////////////////////////////////////////////////////////////////////
797 Int_t AliRecInfoMaker::BuildKinkInfo0(Int_t eventNr)
798 {
799 //
800 // loop over all entries for a given event, find corresponding 
801 // rec. track and store in the fTreeCmp
802 //
803   TStopwatch timer;
804   timer.Start();
805   Int_t entry = fNextKinkToRead;
806   Double_t nParticlesTR = fTreeGenKinks->GetEntriesFast();
807   cerr<<"fNParticles, nParticlesTR, fNextKinkToRead: "<<fNParticles<<" "
808       <<nParticlesTR<<" "<<fNextKinkToRead<<endl;
809   //
810   TBranch * branch = fTreeCmpKinks->GetBranch("RC.");
811   branch->SetAddress(&fRecKinkInfo); // set all pointers
812   
813   //
814   while (entry < nParticlesTR) {
815     fTreeGenKinks->GetEntry(entry);
816     entry++;
817     if (eventNr < fGenKinkInfo->GetMinus().fEventNr) continue;
818     if (eventNr > fGenKinkInfo->GetMinus().fEventNr) continue;;
819     //
820     fNextKinkToRead = entry-1;
821     //
822     //
823     AliESDRecInfo*  fRecInfo1 = (AliESDRecInfo*)fRecArray->At(fGenKinkInfo->GetMinus().fLabel);
824     AliESDRecInfo*  fRecInfo2 = (AliESDRecInfo*)fRecArray->At(fGenKinkInfo->GetPlus().fLabel);
825     fRecKinkInfo->fT1 = (*fRecInfo1);
826     fRecKinkInfo->fT2 = (*fRecInfo2);
827     fRecKinkInfo->fStatus =0;
828     if (fRecInfo1 && fRecInfo1->fTPCOn) fRecKinkInfo->fStatus+=1;
829     if (fRecInfo2 && fRecInfo2->fTPCOn) fRecKinkInfo->fStatus+=2;
830     if (fRecKinkInfo->fStatus==3&&fRecInfo1->fSign!=fRecInfo2->fSign) fRecKinkInfo->fStatus*=-1;
831     
832     if (fRecKinkInfo->fStatus==3){
833       fRecKinkInfo->Update();    
834     }
835     Int_t label =  TMath::Min(fGenKinkInfo->GetMinus().fLabel,fGenKinkInfo->GetPlus().fLabel);
836     Int_t label2 = TMath::Max(fGenKinkInfo->GetMinus().fLabel,fGenKinkInfo->GetPlus().fLabel);
837     
838     AliESDkink *kink=0;
839     fRecKinkInfo->fRecStatus   =0;
840     fRecKinkInfo->fMultiple    = fMultiRecKinks[label];
841     fRecKinkInfo->fKinkMultiple=0;
842     //
843     if (fMultiRecKinks[label]>0){
844
845       //      for (Int_t j=0;j<TMath::Min(fMultiRecKinks[label],100);j++){
846       for (Int_t j=TMath::Min(fMultiRecKinks[label],Short_t(20))-1;j>=0;j--){
847         Int_t index = fIndexRecKinks[label*20+j];
848         //AliESDkink *kink2  = (AliESDkink*)fKinks->At(index);
849         AliESDkink *kink2  = (AliESDkink*)fEvent->GetKink(index);
850         if (TMath::Abs(kink2->GetLabel(0))==label &&TMath::Abs(kink2->GetLabel(1))==label2) {
851           fRecKinkInfo->fKinkMultiple++;
852           fSignedKinks[index]=1;
853           Int_t c0=0;
854           if (kink){
855             //      if (kink->fTRDOn) c0++;
856             //if (kink->fITSOn) c0++;
857             if (kink->GetStatus(2)>0) c0++;
858             if (kink->GetStatus(0)>0) c0++;
859           }
860           Int_t c2=0;
861           //      if (kink2->fTRDOn) c2++;
862           //if (kink2->fITSOn) c2++;
863           if (kink2->GetStatus(2)>0) c2++;
864           if (kink2->GetStatus(0)>0) c2++;
865
866           if (c2<c0) continue;
867           kink =kink2;
868         }
869         if (TMath::Abs(kink2->GetLabel(1))==label &&TMath::Abs(kink2->GetLabel(0))==label2) {
870           fRecKinkInfo->fKinkMultiple++;
871           fSignedKinks[index]=1;
872           Int_t c0=0;
873           if (kink){
874             //if (kink->fTRDOn) c0++;
875             //if (kink->fITSOn) c0++;
876             if (kink->GetStatus(2)>0) c0++;
877             if (kink->GetStatus(0)>0) c0++;
878
879           }
880           Int_t c2=0;
881           //      if (kink2->fTRDOn) c2++;
882           //if (kink2->fITSOn) c2++;
883           if (kink2->GetStatus(2)>0) c2++;
884           if (kink2->GetStatus(0)>0) c2++;
885
886           if (c2<c0) continue;
887           kink =kink2;
888         }
889       }
890     }
891     if (kink){
892       fRecKinkInfo->fKink = *kink;
893       fRecKinkInfo->fRecStatus=1;
894     }
895     fTreeCmpKinks->Fill();
896   }
897   //  Int_t nkinks = fKinks->GetEntriesFast();
898   Int_t nkinks = fEvent->GetNumberOfKinks();
899   for (Int_t i=0;i<nkinks;i++){
900     if (fSignedKinks[i]==0){
901       //      AliESDkink *kink  = (AliESDkink*)fKinks->At(i);
902       AliESDkink *kink  = (AliESDkink*)fEvent->GetKink(i);
903       if (!kink) continue;
904       //
905       fRecKinkInfo->fKink = *kink;
906       fRecKinkInfo->fRecStatus =-2;
907       //
908       AliESDRecInfo*  fRecInfo1 = (AliESDRecInfo*)fRecArray->At(TMath::Abs(kink->GetLabel(0)));
909       AliESDRecInfo*  fRecInfo2 = (AliESDRecInfo*)fRecArray->At(TMath::Abs(kink->GetLabel(1)));
910       if (fRecInfo1 && fRecInfo2){
911         fRecKinkInfo->fT1 = (*fRecInfo1);
912         fRecKinkInfo->fT2 = (*fRecInfo2);
913         fRecKinkInfo->fRecStatus =-1;
914       }
915       fTreeCmpKinks->Fill();
916     }
917   }
918
919
920   fTreeCmpKinks->AutoSave();
921   printf("Time spended in BuilKinkInfo Loop\n");
922   timer.Print();
923   if (fDebug > 2) cerr<<"end of BuildKinkInfo Loop"<<endl;
924   return 0;
925 }
926
927
928
929 ////////////////////////////////////////////////////////////////////////
930 ////////////////////////////////////////////////////////////////////////
931 ////////////////////////////////////////////////////////////////////////
932
933
934
935 Int_t AliRecInfoMaker::BuildV0Info(Int_t eventNr)
936 {
937 //
938 // loop over all entries for a given event, find corresponding 
939 // rec. track and store in the fTreeCmp
940 //
941   TStopwatch timer;
942   timer.Start();
943   Int_t entry = fNextV0ToRead;
944   Double_t nParticlesTR = fTreeGenV0->GetEntriesFast();
945   cerr<<"fNParticles, nParticlesTR, fNextV0ToRead: "<<fNParticles<<" "
946       <<nParticlesTR<<" "<<fNextV0ToRead<<endl;
947   //
948   TBranch * branch = fTreeCmpV0->GetBranch("RC.");
949   branch->SetAddress(&fRecV0Info); // set all pointers
950   const AliESDVertex * esdvertex = fEvent->GetVertex();
951   Float_t vertex[3]= {esdvertex->GetXv(), esdvertex->GetYv(),esdvertex->GetZv()};
952   
953   //
954   while (entry < nParticlesTR) {
955     fTreeGenV0->GetEntry(entry);
956     entry++;
957     if (eventNr < fGenV0Info->GetMinus().fEventNr) continue;
958     if (eventNr > fGenV0Info->GetMinus().fEventNr) continue;;
959     //
960     fNextV0ToRead = entry-1;
961     //
962     //
963     AliESDRecInfo*  fRecInfo1 = (AliESDRecInfo*)fRecArray->At(fGenV0Info->GetMinus().fLabel);
964     AliESDRecInfo*  fRecInfo2 = (AliESDRecInfo*)fRecArray->At(fGenV0Info->GetPlus().fLabel);
965     if (fGenV0Info->GetMinus().fCharge*fGenV0Info->GetPlus().fCharge>0) continue;  // interactions
966     if (!fRecInfo1 || !fRecInfo2) continue;
967     fRecV0Info->fT1 = (*fRecInfo1);
968     fRecV0Info->fT2 = (*fRecInfo2);
969     fRecV0Info->fV0Status =0;
970     if (fRecInfo1 && fRecInfo1->fStatus[1]>0) fRecV0Info->fV0Status+=1;
971     if (fRecInfo2 && fRecInfo2->fStatus[1]>0) fRecV0Info->fV0Status+=2;
972
973     if (fRecV0Info->fV0Status==3&&fRecInfo1->fSign==fRecInfo2->fSign) fRecV0Info->fV0Status*=-1;
974
975
976     if (abs(fRecV0Info->fV0Status)==3){
977       fRecV0Info->Update(vertex);
978       {
979         //
980         // TPC V0 Info
981         Double_t x,alpha, param[5],cov[15];
982         if ( fRecV0Info->fT1.GetESDtrack()->GetInnerParam() && fRecV0Info->fT2.GetESDtrack()->GetInnerParam()){
983           fRecV0Info->fT1.GetESDtrack()->GetInnerExternalParameters(alpha,x,param);
984           fRecV0Info->fT1.GetESDtrack()->GetInnerExternalCovariance(cov);
985           AliExternalTrackParam paramP(x,alpha,param,cov);
986           //
987           fRecV0Info->fT2.GetESDtrack()->GetInnerExternalParameters(alpha,x,param);
988           fRecV0Info->fT2.GetESDtrack()->GetInnerExternalCovariance(cov);
989           AliExternalTrackParam paramM(x,alpha,param,cov);
990           //
991           fRecV0Info->fV0tpc->SetParamN(paramM);
992           fRecV0Info->fV0tpc->SetParamP(paramP);
993           Double_t pid1[5],pid2[5];
994           fRecV0Info->fT1.GetESDtrack()->GetESDpid(pid1);
995           fRecV0Info->fT1.GetESDtrack()->GetESDpid(pid2);
996           //
997           //fRecV0Info->fV0tpc.UpdatePID(pid1,pid2);
998           fRecV0Info->fV0tpc->Update(vertex);
999         
1000           //
1001           //
1002           fRecV0Info->fT1.GetESDtrack()->GetExternalParameters(x,param);
1003           fRecV0Info->fT1.GetESDtrack()->GetExternalCovariance(cov);
1004           alpha = fRecV0Info->fT1.GetESDtrack()->GetAlpha();
1005           new (&paramP) AliExternalTrackParam(x,alpha,param,cov);
1006           //
1007           fRecV0Info->fT2.GetESDtrack()->GetExternalParameters(x,param);
1008           fRecV0Info->fT2.GetESDtrack()->GetExternalCovariance(cov);
1009           alpha = fRecV0Info->fT2.GetESDtrack()->GetAlpha();
1010           new (&paramM) AliExternalTrackParam(x,alpha,param,cov);
1011           //
1012           fRecV0Info->fV0its->SetParamN(paramM);
1013           fRecV0Info->fV0its->SetParamP(paramP);
1014           //      fRecV0Info->fV0its.UpdatePID(pid1,pid2);
1015           fRecV0Info->fV0its->Update(vertex);
1016         }
1017       }
1018       if (TMath::Abs(fGenV0Info->GetMinus().fPdg)==11 &&TMath::Abs(fGenV0Info->GetPlus().fPdg)==11){
1019         if (fRecV0Info->fDist2>10){
1020           fRecV0Info->Update(vertex);
1021         }
1022         if (fRecV0Info->fDist2>10){
1023           fRecV0Info->Update(vertex);
1024         }
1025       }
1026     }   
1027     //
1028     // take the V0 from reconstruction
1029  
1030     Int_t label =  TMath::Min(fGenV0Info->GetMinus().fLabel,fGenV0Info->GetPlus().fLabel);
1031     Int_t label2 = TMath::Max(fGenV0Info->GetMinus().fLabel,fGenV0Info->GetPlus().fLabel);    
1032     AliV0 *v0MI=0;
1033     fRecV0Info->fRecStatus   =0;
1034     fRecV0Info->fMultiple    = fMultiRecV0[label];
1035     fRecV0Info->fV0Multiple=0;
1036     //
1037     if (fMultiRecV0[label]>0 || fMultiRecV0[label2]>0){
1038
1039       //      for (Int_t j=0;j<TMath::Min(fMultiRecV0s[label],100);j++){
1040      //  for (Int_t j=TMath::Min(fMultiRecV0[label],Short_t(20))-1;j>=0;j--){
1041 //      Int_t index = fIndexRecV0[label*20+j];
1042 //      if (index<0) continue;
1043 //      AliV0 *v0MI2  = (AliV0*)fEvent->GetV0(index);
1044 //      if (TMath::Abs(v0MI2->GetLabel(0))==label &&TMath::Abs(v0MI2->GetLabel(1))==label2) {
1045 //        v0MI =v0MI2;
1046 //        fRecV0Info->fV0Multiple++;
1047 //        fSignedV0[index]=1;
1048 //      }
1049 //      if (TMath::Abs(v0MI2->GetLabel(1))==label &&TMath::Abs(v0MI2->GetLabel(0))==label2) {
1050 //        v0MI =v0MI2;
1051 //        fRecV0Info->fV0Multiple++;
1052 //        fSignedV0[index]=1;
1053 //      }
1054 //       }
1055     }
1056     if (v0MI){
1057       fRecV0Info->fV0rec = v0MI;
1058       fRecV0Info->fRecStatus=1;
1059     }
1060
1061     fTreeCmpV0->Fill();
1062   }
1063   //
1064   // write fake v0s
1065
1066   Int_t nV0MIs = fEvent->GetNumberOfV0s();
1067   for (Int_t i=0;i<nV0MIs;i++){
1068     if (fSignedV0[i]==0){
1069       AliV0 *v0MI  = (AliV0*)fEvent->GetV0(i);
1070       if (!v0MI) continue;
1071       //
1072       fRecV0Info->fV0rec = v0MI;
1073       fRecV0Info->fV0Status  =-10;
1074       fRecV0Info->fRecStatus =-2;
1075       //
1076  //      AliESDRecInfo*  fRecInfo1 = (AliESDRecInfo*)fRecArray->At(TMath::Abs(v0MI->GetLabel(0)));
1077 //       AliESDRecInfo*  fRecInfo2 = (AliESDRecInfo*)fRecArray->At(TMath::Abs(v0MI->GetLabel(1)));
1078 //       if (fRecInfo1 && fRecInfo2){
1079 //      fRecV0Info->fT1 = (*fRecInfo1);
1080 //      fRecV0Info->fT2 = (*fRecInfo2);
1081 //      fRecV0Info->fRecStatus =-1;
1082 //       }
1083       fRecV0Info->Update(vertex);
1084       fTreeCmpV0->Fill();
1085     }
1086   }
1087
1088
1089
1090   fTreeCmpV0->AutoSave();
1091   printf("Time spended in BuilV0Info Loop\n");
1092   timer.Print();
1093   if (fDebug > 2) cerr<<"end of BuildV0Info Loop"<<endl;
1094   return 0;
1095 }
1096 ////////////////////////////////////////////////////////////////////////
1097 ////////////////////////////////////////////////////////////////////////
1098
1099