]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG1/AliAnalysisTaskV0QA.cxx
code rules violation fixed (A.Marin)
[u/mrichter/AliRoot.git] / PWG1 / AliAnalysisTaskV0QA.cxx
1 //------------------------------------------------
2 // Implementation of AliAnalysisTaskV0QA class.
3 // Calculates the "on the fly" V0 method efficiency 
4 // for Gamma, K0s, lambda, antilambda
5 // Needs MC information
6 // Author: A. Marin  Revision 18/10/09
7 //-------------------------------------------------
8 #define AliAnalysisTaskV0QA_cxx
9
10 #include "Riostream.h"
11
12 #include "TChain.h"
13 #include "TH1.h"
14 #include "TH2.h"
15
16
17 //#include "TLorentzVector.h"
18
19 #include "AliAnalysisTask.h"
20 #include "AliTrackReference.h"
21 #include "AliKFParticle.h"
22 #include "AliKFVertex.h"
23 #include "AliVertexerTracks.h"
24 #include "AliESDEvent.h"
25 #include "AliESDInputHandler.h"
26 #include "AliMCEvent.h"
27 #include "AliMCEventHandler.h"
28 #include "AliStack.h"
29 #include "AliESD.h"
30 #include "AliLog.h"
31
32 #include "AliAnalysisTaskV0QA.h"
33
34 ClassImp(AliAnalysisTaskV0QA)
35
36 //________________________________________________________________________
37 AliAnalysisTaskV0QA::AliAnalysisTaskV0QA(const char *name) :AliAnalysisTask(name,""), 
38 fESD(0), 
39 fStack(0),
40 fMCtruth(0),
41 fChain(0),
42 fOutputContainer(0),
43 fSparseV0(0),
44 fSparseK0(0),
45 fSparseL(0),
46 fSparseAL(0),
47 fnEv(0),
48 fnConvGamGeant(-1),
49 fgConvGamGeantIndex(0),
50 feNegConvGamGeantIndex(0),
51 fePosConvGamGeantIndex(0),
52 feNegConvGamGeantLength(0),
53 fePosConvGamGeantLength(0),
54 feNegConvGamSingleRecIndex(0),
55 fePosConvGamSingleRecIndex(0),
56 feNegConvGamV0RecIndex(0),
57 fePosConvGamV0RecIndex(0),
58 fConvGamV0RecIndexPos(0),
59 fConvGamV0RecIndexNeg(0),
60 fgDim(50),
61 fnDecayLGeant(-1),
62 flDecayLGeantIndex(0),
63 fpiNegDecayLGeantIndex(0),
64 fpPosDecayLGeantIndex(0),
65 fpiNegDecayLGeantLength(0),
66 fpPosDecayLGeantLength(0),
67 fpiNegDecayLSingleRecIndex(0),
68 fpPosDecayLSingleRecIndex(0),
69 fpiNegDecayLV0RecIndex(0),
70 fpPosDecayLV0RecIndex(0),
71 fDecayLV0RecIndexPos(0),
72 fDecayLV0RecIndexNeg(0),
73 fnDecayALGeant(-1),
74 falDecayALGeantIndex(0),
75 fpiPosDecayALGeantIndex(0),
76 fapNegDecayALGeantIndex(0),
77 fpiPosDecayALGeantLength(0),
78 fapNegDecayALGeantLength(0),
79 fpiPosDecayALSingleRecIndex(0),
80 fapNegDecayALSingleRecIndex(0),
81 fpiPosDecayALV0RecIndex(0),
82 fapNegDecayALV0RecIndex(0),
83 fDecayALV0RecIndexPos(0),
84 fDecayALV0RecIndexNeg(0),
85 fnDecayK0Geant(-1),
86 fK0DecayK0GeantIndex(0),
87 fpiNegDecayK0GeantIndex(0),
88 fpiPosDecayK0GeantIndex(0),
89 fpiNegDecayK0GeantLength(0),
90 fpiPosDecayK0GeantLength(0),
91 fpiNegDecayK0SingleRecIndex(0),
92 fpiPosDecayK0SingleRecIndex(0),
93 fpiNegDecayK0V0RecIndex(0),
94 fpiPosDecayK0V0RecIndex(0),
95 fDecayK0V0RecIndexPos(0),
96 fDecayK0V0RecIndexNeg(0),
97 fpiPosK0Index(-1),
98 fpiNegK0Index(-1),
99 fnTracksPrim(-1),
100 ftpcRefit(0),
101 fitsRefit(0),
102 ftrdRefit(0),
103 ftrdOut(0),
104 fValueL(0),
105 fValueAL(0),
106 fValueK0(0),
107 fValueV0(0),
108 fxminV0(0),
109 fxmaxV0(0),
110 fbinsV0(0),
111 fDim(37),
112 fRefTPC(0),
113 fclRefsN(0),
114 fclRefsP(0)
115
116  {
117   // Constructor.
118   // Input slot #0 works with an Ntuple
119   DefineInput(0, TChain::Class());
120   // Output slot #0 writes into a TH1 container
121   //  DefineOutput(0,TObjArray::Class());
122   DefineOutput(0,TList::Class());
123
124   // Reconstructed arrays
125
126   fnEv=0;
127   fDim=37; 
128   fValueK0 = new Double_t[fDim];
129   fValueL = new Double_t[fDim];
130   fValueAL = new Double_t[fDim];
131   fValueV0 = new Double_t[fDim];
132   fxminV0 = new Double_t[fDim];
133   fxmaxV0 = new Double_t[fDim];
134   fbinsV0 = new Int_t[fDim];
135
136
137   fgDim=50; 
138   fgConvGamGeantIndex = new Int_t[fgDim];
139   feNegConvGamGeantIndex = new Int_t[fgDim];
140   fePosConvGamGeantIndex = new Int_t[fgDim];
141   feNegConvGamGeantLength = new Float_t[fgDim];
142   fePosConvGamGeantLength = new Float_t[fgDim];
143
144   feNegConvGamSingleRecIndex = new Int_t[fgDim];
145   fePosConvGamSingleRecIndex = new Int_t[fgDim];
146
147   feNegConvGamV0RecIndex = new Int_t[fgDim];
148   fePosConvGamV0RecIndex = new Int_t[fgDim];
149
150   fConvGamV0RecIndexPos = new Int_t[fgDim];
151   fConvGamV0RecIndexNeg = new Int_t[fgDim];
152
153   // Lambda to proton pi-
154   flDecayLGeantIndex = new Int_t[fgDim];
155   fpiNegDecayLGeantIndex = new Int_t[fgDim];
156   fpPosDecayLGeantIndex = new Int_t[fgDim];
157   fpiNegDecayLGeantLength = new Float_t[fgDim];
158   fpPosDecayLGeantLength = new Float_t[fgDim];
159
160   fpiNegDecayLSingleRecIndex = new Int_t[fgDim];
161   fpPosDecayLSingleRecIndex = new Int_t[fgDim];
162
163   fpiNegDecayLV0RecIndex = new Int_t[fgDim];
164   fpPosDecayLV0RecIndex = new Int_t[fgDim];
165
166   fDecayLV0RecIndexPos = new Int_t[fgDim];
167   fDecayLV0RecIndexNeg = new Int_t[fgDim];
168
169   //K0S to pi+ pi-
170   fK0DecayK0GeantIndex = new Int_t[fgDim];
171   fpiNegDecayK0GeantIndex = new Int_t[fgDim];
172   fpiPosDecayK0GeantIndex = new Int_t[fgDim];
173   fpiNegDecayK0GeantLength = new Float_t[fgDim];
174   fpiPosDecayK0GeantLength = new Float_t[fgDim];
175
176   fpiNegDecayK0SingleRecIndex = new Int_t[fgDim];
177   fpiPosDecayK0SingleRecIndex = new Int_t[fgDim];
178
179   fpiNegDecayK0V0RecIndex = new Int_t[fgDim];
180   fpiPosDecayK0V0RecIndex = new Int_t[fgDim];
181
182   fDecayK0V0RecIndexPos = new Int_t[fgDim];
183   fDecayK0V0RecIndexNeg = new Int_t[fgDim];
184
185   //Antilambda to antiproton piplus
186   falDecayALGeantIndex = new Int_t[fgDim];
187   fpiPosDecayALGeantIndex = new Int_t[fgDim];
188   fapNegDecayALGeantIndex = new Int_t[fgDim];
189   fpiPosDecayALGeantLength = new Float_t[fgDim];
190   fapNegDecayALGeantLength = new Float_t[fgDim];
191
192   fpiPosDecayALSingleRecIndex = new Int_t[fgDim];
193   fapNegDecayALSingleRecIndex = new Int_t[fgDim];
194
195   fpiPosDecayALV0RecIndex = new Int_t[fgDim];
196   fapNegDecayALV0RecIndex = new Int_t[fgDim];
197
198   fDecayALV0RecIndexPos = new Int_t[fgDim];
199   fDecayALV0RecIndexNeg = new Int_t[fgDim];
200
201
202  
203   fclRefsP = new TClonesArray("AliTrackReference");
204   fclRefsN = new TClonesArray("AliTrackReference");
205
206   //  SetESDtrackCuts();
207
208
209   AliLog::SetGlobalLogLevel(AliLog::kError);
210
211 }
212
213 //________________________________________________________________________
214 void AliAnalysisTaskV0QA::ConnectInputData(Option_t *) {
215   printf("   ConnectInputData %s\n", GetName());
216   // Connect Input Data
217   
218   AliESDInputHandler* esdH = (AliESDInputHandler*) ((AliAnalysisManager::GetAnalysisManager())->GetInputEventHandler());
219   fESD = esdH->GetEvent();
220   
221   fChain = (TChain*)GetInputData(0);
222
223 }
224
225 //_____________________________________________________
226 AliAnalysisTaskV0QA::~AliAnalysisTaskV0QA()
227 {
228   // Remove all pointers
229
230
231   delete [] fclRefsP;
232   delete [] fclRefsN;
233
234
235   delete [] fValueK0;
236   delete [] fValueL;
237   delete [] fValueAL;
238   delete [] fValueV0;
239   delete [] fbinsV0;
240   delete [] fxminV0;
241   delete [] fxmaxV0;
242
243   delete [] fgConvGamGeantIndex;
244   delete [] feNegConvGamGeantIndex;
245   delete [] fePosConvGamGeantIndex;
246
247   delete [] feNegConvGamSingleRecIndex;
248   delete [] fePosConvGamSingleRecIndex;
249
250   delete [] feNegConvGamV0RecIndex;
251   delete [] fePosConvGamV0RecIndex;
252   delete [] fConvGamV0RecIndexPos;
253   delete [] fConvGamV0RecIndexNeg;
254
255   delete [] flDecayLGeantIndex;
256   delete [] fpiNegDecayLGeantIndex;
257   delete [] fpPosDecayLGeantIndex;
258
259   delete [] fpiNegDecayLGeantLength;
260   delete [] fpPosDecayLGeantLength;
261   delete [] fpiNegDecayLSingleRecIndex;
262   delete [] fpPosDecayLSingleRecIndex;
263
264   delete [] fpiNegDecayLV0RecIndex;
265   delete [] fpPosDecayLV0RecIndex;
266   delete [] fDecayLV0RecIndexPos;
267   delete [] fDecayLV0RecIndexNeg;
268
269   delete [] falDecayALGeantIndex;
270   delete [] fpiPosDecayALGeantIndex;
271   delete [] fapNegDecayALGeantIndex;
272
273   delete [] fpiPosDecayALGeantLength;
274   delete [] fapNegDecayALGeantLength;
275   delete [] fpiPosDecayALSingleRecIndex;
276   delete [] fapNegDecayALSingleRecIndex;
277
278   delete [] fpiPosDecayALV0RecIndex;
279   delete [] fapNegDecayALV0RecIndex;
280   delete [] fDecayALV0RecIndexPos;
281   delete [] fDecayALV0RecIndexNeg;
282
283
284   delete [] fpiNegDecayK0GeantIndex;
285   delete [] fpiPosDecayK0GeantIndex;
286
287   delete [] fpiNegDecayK0GeantLength;
288   delete [] fpiPosDecayK0GeantLength;
289   delete [] fpiNegDecayK0SingleRecIndex;
290   delete [] fpiPosDecayK0SingleRecIndex;
291
292   delete [] fpiNegDecayK0V0RecIndex;
293   delete [] fpiPosDecayK0V0RecIndex;
294
295   delete [] fDecayK0V0RecIndexPos;
296   delete [] fDecayK0V0RecIndexNeg;
297
298 }
299
300
301 //________________________________________________________________________
302 void AliAnalysisTaskV0QA::CreateOutputObjects() {
303   // Create Ouptut objects
304
305   for(Int_t d=0;d<fDim;d++){
306     fbinsV0[d]=70;
307   }
308   fxminV0[0]=   0;     // 1/sqrt(pt) Gamma geant
309   fxmaxV0[0]=   8;
310
311
312   fxminV0[1]=-2.5;   // eta Gamma Geant
313   fxmaxV0[1]= 1.5;
314
315
316   fxminV0[2]=-2*TMath::Pi();   // phi Gamma geant
317   fxmaxV0[2]= TMath::Pi();
318
319
320   fxminV0[3]=   0;     // r geant
321   fxmaxV0[3]= 200;
322
323
324   fxminV0[4]=-250;   // z geant
325   fxmaxV0[4]= 250;
326
327
328   fxminV0[5]=   0;     // 1/sqrt(pt) Geant Pos
329   fxmaxV0[5]=   8;
330
331
332   fxminV0[6]=-2.5;   // eta geant Pos
333   fxmaxV0[6]= 1.5;
334
335
336   fxminV0[7]=-2*TMath::Pi();   // phi Geant Pos
337   fxmaxV0[7]= TMath::Pi();
338
339   
340   fxminV0[8]=0;   // Track Length TPC Geant Pos
341   fxmaxV0[8]= 200;
342
343
344   fxminV0[9]=   0;     // 1/sqrt(pt) Geant Neg
345   fxmaxV0[9]=   8;
346
347
348   fxminV0[10]=-2.5;   // eta Geant Neg
349   fxmaxV0[10]= 1.5;
350
351
352   fxminV0[11]=-2*TMath::Pi();   // phi Geant Neg
353   fxmaxV0[11]= TMath::Pi();
354
355
356   fxminV0[12]=0;   // Track Length TPC Geant Neg
357   fxmaxV0[12]= 200;
358
359
360
361   //-----------Rec single variables
362
363   fxminV0[13]=   -0.5;     // (pt-ptGeant)/ptGeant rec Pos
364   fxmaxV0[13]=   0.5;
365
366
367   fxminV0[14]=-2.5;   // eta  rec Pos
368   fxmaxV0[14]= 1.5;
369
370
371   fxminV0[15]=-2*TMath::Pi();   // phi rec Pos
372   fxmaxV0[15]= TMath::Pi();
373
374
375   fxminV0[16]=   0;     // Impact parameter rec Pos
376   fxmaxV0[16]=   100;
377
378
379   fxminV0[17]=   0;     // nsigmas Impact parameter rec Pos
380   fxmaxV0[17]=   100;
381
382
383
384   fxminV0[18]=   -1;     // Ncls ITS rec Pos
385   fxmaxV0[18]=   6;
386
387
388   fxminV0[19]=   -1;     // Ncls TPC rec Pos
389   fxmaxV0[19]=   180;
390
391
392   fxminV0[20]=   -2;     // Status Single  TPC rec Pos
393   fxmaxV0[20]=   2;
394
395
396   fxminV0[21]=   -0.5;     // (pt-ptGeant)/ptGeant rec Neg
397   fxmaxV0[21]=   0.5;
398
399
400   fxminV0[22]=-2.5;   // eta  rec Neg
401   fxmaxV0[22]= 1.5;
402
403
404   fxminV0[23]=-2*TMath::Pi();   // phi rec Neg
405   fxmaxV0[23]= TMath::Pi();
406
407
408   fxminV0[24]=   0;     // Impact parameter rec Neg
409   fxmaxV0[24]=   100;
410
411
412   fxminV0[25]=   0;     // Sigmas Impact parameter rec Neg
413   fxmaxV0[25]=   100;
414
415
416
417   fxminV0[26]=   -1;     // Ncls ITS rec Neg
418   fxmaxV0[26]=   6;
419
420
421   fxminV0[27]=   -1;     // Ncls TPC rec Neg
422   fxmaxV0[27]=   180;
423
424
425   fxminV0[28]=   -2;     // Status Single  TPC rec Neg
426   fxmaxV0[28]=   2;
427
428   // ------------------Rec V0 variables
429
430
431
432   fxminV0[29]=   -0.5;     // (pt-ptGeant)/ptGeant rec V0 Pos
433   fxmaxV0[29]=   0.5;
434
435
436   fxminV0[30]=-2.5;   // eta  rec V0 Pos
437   fxmaxV0[30]= 1.5;
438
439
440   fxminV0[31]=-2*TMath::Pi();   // phi rec V0 Pos
441   fxmaxV0[31]= TMath::Pi();
442
443
444   fxminV0[32]=   -2;     // Status V0 TPC rec Pos
445   fxmaxV0[32]=   2;
446
447
448
449
450   fxminV0[33]=   -0.5;     // 1/sqrt(pt) rec V0 Neg
451   fxmaxV0[33]=   0.5;
452
453
454   fxminV0[34]=-2.5;   // eta  rec V0 Neg
455   fxmaxV0[34]= 1.5;
456
457
458   fxminV0[35]=-2*TMath::Pi();   // phi rec V0 Neg
459   fxmaxV0[35]= TMath::Pi();
460
461
462
463   fxminV0[36]=   -2;     // Status V0 TPC rec Neg
464   fxmaxV0[36]=   2;
465
466
467
468   TString  axisName[37]={"ptGammaGeant", 
469                          "etaGammaGeant",
470                          "phiGammaGeant",
471                          "rGeant",
472                          "zGeant",
473                          "ptEPlusGeant",  
474                          "etaEPlusGeant",
475                          "phiEPlusGeant",
476                          "TPCTrackLengthEPlusGeant",
477                          "ptEMinusGeant", 
478                          "etaEMinusGeant",
479                          "phiEMinusGeant",
480                          "TPCTrackLengthEMinusGeant",
481                          "ptResEPlusRecSingle", 
482                          "etaEPlusRecSingle",
483                          "phiEPlusRecSingle",
484                          "bXYZEPlusRecSingle",
485                          "sigbXYZEPlusRecSingle",
486                          "NclsITSEPlusRecSingle",
487                          "NclsTPCEPlusRecSingle",
488                          "statusRecSinglePos",
489                          "ptResEMinusRecSingle", 
490                          "etaEMinusRecSingle",
491                          "phiEMinusRecSingle",
492                          "bXYZEMinusRecSingle",
493                          "sigbXYZEMinusRecSingle",
494                          "NclsITSEMinusRecSingle",
495                          "NclsTPCEMinusRecSingle",
496                          "statusRecSingleNeg",
497                          "ptResEPlusRecV0", 
498                          "etaEPlusRecV0",
499                          "phiEPlusRecV0",
500                          "statusV0SinglePos",
501                          "ptResEMinusRecV0", 
502                          "etaEMinusRecV0",
503                          "phiEMinusRecV0",
504                          "statusV0SingleNeg"};
505
506
507   fSparseV0= new THnSparseF("sparseV0","sparseV0",fDim,fbinsV0,fxminV0,fxmaxV0);
508
509   for (Int_t iaxis=0; iaxis<fDim; iaxis++){
510    fSparseV0->GetAxis(iaxis)->SetName(axisName[iaxis]);
511    fSparseV0->GetAxis(iaxis)->SetTitle(axisName[iaxis]);
512   }
513
514   TString  axisNameK0[37]={"ptK0Geant", 
515                          "etaK0Geant",
516                          "phiK0Geant",
517                          "rGeant",
518                          "zGeant",
519                          "ptPiPlusGeant",  
520                          "etaPiPlusGeant",
521                          "phiPiPlusGeant",
522                          "TPCTrackLengthPiPlusGeant",
523                          "ptPiMinusGeant", 
524                          "etaPiMinusGeant",
525                          "phiPiMinusGeant",
526                          "TPCTrackLengthPiMinusGeant",
527                          "ptResPiPlusRecSingle", 
528                          "etaPiPlusRecSingle",
529                          "phiPiPlusRecSingle",
530                          "bXYZPiPlusRecSingle",
531                          "sigbXYZPiPlusRecSingle",
532                          "NclsITSPiPlusRecSingle",
533                          "NclsTPCPiPlusRecSingle",
534                          "statusRecSinglePos",
535                          "ptResPiMinusRecSingle", 
536                          "etaPiMinusRecSingle",
537                          "phiPiMinusRecSingle",
538                          "bXYZPiMinusRecSingle",
539                          "sigbXYZPiMinusRecSingle",
540                          "NclsITSPiMinusRecSingle",
541                          "NclsTPCPiMinusRecSingle",
542                          "statusRecSingleNeg",
543                          "ptResPiPlusRecV0", 
544                          "etaPiPlusRecV0",
545                          "phiPiPlusRecV0",
546                          "statusRecV0Pos",
547                          "ptResPiMinusRecV0", 
548                          "etaPiMinusRecV0",
549                          "phiPiMinusRecV0",
550                          "statusRecV0Neg"};
551
552
553
554   fSparseK0= new THnSparseF("sparseK0","sparseK0",fDim,fbinsV0,fxminV0,fxmaxV0);
555   for (Int_t iaxis=0; iaxis<fDim; iaxis++){
556    fSparseK0->GetAxis(iaxis)->SetName(axisNameK0[iaxis]);
557    fSparseK0->GetAxis(iaxis)->SetTitle(axisNameK0[iaxis]);
558   }
559
560   TString  axisNameL[37]={"ptLGeant", 
561                          "etaLGeant",
562                          "phiLGeant",
563                          "rGeant",
564                          "zGeant",
565                          "ptPPlusGeant",  
566                          "etaPPlusGeant",
567                          "phiPPlusGeant",
568                          "TPCTrackLengthPPlusGeant",
569                          "ptPiMinusGeant", 
570                          "etaPiMinusGeant",
571                          "phiPiMinusGeant",
572                          "TPCTrackLengthPiMinusGeant",
573                          "ptResPPlusRecSingle", 
574                          "etaPPlusRecSingle",
575                          "phiPPlusRecSingle",
576                          "bXYZPPlusRecSingle",
577                          "sigbXYZPPlusRecSingle",
578                          "NclsITSPPlusRecSingle",
579                          "NclsTPCPPlusRecSingle",
580                          "statusRecSinglePos",
581                          "ptResPiMinusRecSingle", 
582                          "etaPiMinusRecSingle",
583                          "phiPiMinusRecSingle",
584                          "bXYZPiMinusRecSingle",
585                          "sigbXYZPiMinusRecSingle",
586                          "NclsITSPiMinusRecSingle",
587                          "NclsTPCPiMinusRecSingle",
588                          "statusRecSingleNeg",
589                          "ptResPPlusRecV0", 
590                          "etaPPlusRecV0",
591                          "phiPPlusRecV0",
592                          "statusRecV0Pos",
593                          "ptResPiMinusRecV0", 
594                          "etaPiMinusRecV0",
595                          "phiPiMinusRecV0",
596                          "statusRecV0Neg"};
597
598
599   fSparseL= new THnSparseF("sparseL","sparseL",fDim,fbinsV0,fxminV0,fxmaxV0);
600   for (Int_t iaxis=0; iaxis<fDim; iaxis++){
601    fSparseL->GetAxis(iaxis)->SetName(axisNameL[iaxis]);
602    fSparseL->GetAxis(iaxis)->SetTitle(axisNameL[iaxis]);
603   }
604
605   TString  axisNameAL[37]={"ptALGeant", 
606                          "etaALGeant",
607                          "phiALGeant",
608                          "rGeant",
609                          "zGeant",
610                          "ptPiPluusGeant",  
611                          "etaPiPlusGeant",
612                          "phiPiPlusGeant",
613                          "TPCTrackLengthPiPlusGeant",
614                          "ptAPMinusGeant", 
615                          "etaAPMinusGeant",
616                          "phiAPMinusGeant",
617                          "TPCTrackLengthAPMinusGeant",
618                          "ptResPiPlusRecSingle", 
619                          "etaPiPlusRecSingle",
620                          "phiPiPlusRecSingle",
621                          "bXYZPiPlusRecSingle",
622                          "sigbXYZPiPlusRecSingle",
623                          "NclsITSPiPlusRecSingle",
624                          "NclsTPCPiPlusRecSingle",
625                          "statusRecSinglePos",
626                          "ptResAPMinusRecSingle", 
627                          "etaAPMinusRecSingle",
628                          "phiAPMinusRecSingle",
629                          "bXYZAPMinusRecSingle",
630                          "sigbXYZAPMinusRecSingle",
631                          "NclsITSAPMinusRecSingle",
632                          "NclsTPCAPMinusRecSingle",
633                          "statusRecSingleNeg",
634                          "ptResPiPlusRecV0", 
635                          "etaPiPlusRecV0",
636                          "phiPiPlusRecV0",
637                          "statusRecV0Pos",
638                          "ptResAPMinusRecV0", 
639                          "etaAPMinusRecV0",
640                          "phiAPMinusRecV0",
641                          "statusRecV0Neg"};
642
643
644   fSparseAL= new THnSparseF("sparseAL","sparseAL",fDim,fbinsV0,fxminV0,fxmaxV0);
645   for (Int_t iaxis=0; iaxis<fDim; iaxis++){
646    fSparseAL->GetAxis(iaxis)->SetName(axisNameAL[iaxis]);
647    fSparseAL->GetAxis(iaxis)->SetTitle(axisNameAL[iaxis]);
648   }
649
650   // create output container
651  
652   fOutputContainer = new TList() ;
653   fOutputContainer->SetName(GetName()) ;
654
655
656   fOutputContainer->Add(fSparseV0);
657   fOutputContainer->Add(fSparseK0);
658   fOutputContainer->Add(fSparseL);
659   fOutputContainer->Add(fSparseAL);
660   
661 }
662
663 //________________________________________________________________________
664 void AliAnalysisTaskV0QA::Exec(Option_t *) {
665   // Execution of the Task
666
667   if (!fESD) {
668     cout<< "not a tree"<< endl;
669     return;
670   }
671
672   fnEv++;
673
674
675   //Get MC data 
676   fMCtruth = (AliMCEventHandler*)((AliAnalysisManager::GetAnalysisManager())->GetMCtruthEventHandler());
677
678   //  Double_t vertex[3];
679   Double_t maxVertex=150.;
680   Double_t maxEta=1.2;
681   Double_t lineCutZRSlope=0.662486;
682   Double_t lineCutZValue=7.;
683   Int_t elecGIndex=-1;
684   Int_t posiGIndex=-1;
685   Int_t pPosLIndex=-1;
686   Int_t piNegLIndex=-1;
687
688   Int_t apNegALIndex=-1;
689   Int_t piPosALIndex=-1;
690
691   fnConvGamGeant=-1;
692   fnDecayK0Geant=-1;
693   fnDecayLGeant=-1;
694   fnDecayALGeant=-1;
695
696   for(Int_t i=0; i<fgDim;i++){
697     fgConvGamGeantIndex[i] = -1;
698     feNegConvGamGeantIndex[i] = -1;
699     fePosConvGamGeantIndex[i] = -1;
700     
701     feNegConvGamSingleRecIndex[i] = -1;
702     fePosConvGamSingleRecIndex[i] = -1;
703
704     feNegConvGamV0RecIndex[i] = -1;
705     fePosConvGamV0RecIndex[i] = -1;
706     fConvGamV0RecIndexPos[i] = -1;
707     fConvGamV0RecIndexNeg[i] = -1;
708
709
710     fK0DecayK0GeantIndex[i] = -1;
711     fpiNegDecayK0GeantIndex[i] = -1;
712     fpiPosDecayK0GeantIndex[i] = -1;
713     
714     fpiNegDecayK0SingleRecIndex[i] = -1;
715     fpiPosDecayK0SingleRecIndex[i] = -1;
716
717     fpiNegDecayK0V0RecIndex[i] = -1;
718     fpiPosDecayK0V0RecIndex[i] = -1;
719     fDecayK0V0RecIndexPos[i] = -1;
720     fDecayK0V0RecIndexNeg[i] = -1;
721
722
723     flDecayLGeantIndex[i] = -1;
724     fpiNegDecayLGeantIndex[i] = -1;
725     fpPosDecayLGeantIndex[i] = -1;
726     
727     fpiNegDecayLSingleRecIndex[i] = -1;
728     fpPosDecayLSingleRecIndex[i] = -1;
729
730     fpiNegDecayLV0RecIndex[i] = -1;
731     fpPosDecayLV0RecIndex[i] = -1;
732     fDecayLV0RecIndexPos[i] = -1;
733     fDecayLV0RecIndexNeg[i] = -1;
734
735     // Antilambda
736     falDecayALGeantIndex[i] = -1;
737     fpiPosDecayALGeantIndex[i] = -1;
738     fapNegDecayALGeantIndex[i] = -1;
739     
740     fpiPosDecayALSingleRecIndex[i] = -1;
741     fapNegDecayALSingleRecIndex[i] = -1;
742
743     fpiPosDecayALV0RecIndex[i] = -1;
744     fapNegDecayALV0RecIndex[i] = -1;
745     fDecayALV0RecIndexPos[i] = -1;
746     fDecayALV0RecIndexNeg[i] = -1;
747
748
749   }
750
751   Int_t doMC=1;
752
753   AliKFVertex primVtx(*(fESD->GetPrimaryVertex()));
754   fnTracksPrim=primVtx.GetNContributors();
755
756
757   if(fMCtruth && fnTracksPrim>0){
758
759    fStack = fMCtruth->MCEvent()->Stack();
760
761
762    if ( doMC){
763
764     for (Int_t iTracks = 0; iTracks < fMCtruth->MCEvent()->GetNumberOfTracks(); iTracks++) {
765       
766
767      TParticle* particle = fStack->Particle(iTracks);
768
769
770
771      if (!particle) {
772        Printf("ERROR: Could not receive particle %d (mc loop)", iTracks);
773        continue;
774      }
775      
776      if(particle->Pt()<0.050) continue;
777      if(TMath::Abs(particle->Eta())> 1.2) continue;
778
779      
780      if (particle->GetPdgCode()== 22){
781        
782        
783        if(particle->GetMother(0) >-1 && fStack->Particle(particle->GetMother(0))->GetPdgCode() == 22){
784          continue; // no photon as mothers!
785        }
786        
787        if(particle->GetMother(0) >= fStack->GetNprimary()){
788          continue; // the gamma has a mother, and it is not a primary particle
789        }
790        
791        TParticle* ePos = NULL;
792        TParticle* eNeg = NULL;
793        elecGIndex=-1;
794        posiGIndex=-1;
795   
796        if(particle->GetNDaughters() >= 2){
797          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
798            TParticle *tmpDaughter = fStack->Particle(daughterIndex);
799            if(tmpDaughter->GetUniqueID() == 5){
800              if(tmpDaughter->GetPdgCode() == 11){
801                eNeg = tmpDaughter;
802                elecGIndex=daughterIndex;
803              }
804              else if(tmpDaughter->GetPdgCode() == -11){
805                ePos = tmpDaughter;
806                posiGIndex=daughterIndex;
807              }
808            }
809          }
810        }
811        
812        
813        if(ePos == NULL || eNeg == NULL){ // means we do not have two daughters from pair production
814          continue;
815        }
816        
817        if(TMath::Abs(ePos->Eta())> maxEta || TMath::Abs(eNeg->Eta())> maxEta){
818          continue;
819        }        
820        
821        if(ePos->R()> maxVertex ){
822          continue; // cuts on distance from collision point
823        }
824       
825       
826        if( (TMath::Abs(ePos->Vz()) * lineCutZRSlope - lineCutZValue)  > ePos->R() ){
827          continue;               // line cut to exclude regions where we do not reconstruct
828        }                
829
830        
831        // Looking at the existance of TPC references
832
833        TParticle* ePosTPC;
834        fMCtruth->MCEvent()->GetParticleAndTR(posiGIndex,ePosTPC,fclRefsP);
835
836        AliMCParticle *mcParticlePos = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(posiGIndex));
837        if(!mcParticlePos) continue;
838
839        Int_t counter; 
840        Float_t tpcTrackLengthePos = mcParticlePos->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counter,3.0); 
841
842  
843
844        int nPointsP =  fclRefsP->GetEntries();
845
846        if (fRefTPC) delete fRefTPC;
847        fRefTPC = new TObjArray();
848
849        for(int iPoint=0; iPoint<nPointsP; iPoint++) {
850          AliTrackReference *ref = (AliTrackReference*)fclRefsP->At(iPoint);
851          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
852        }
853
854        fRefTPC->Sort();
855
856        for(int i=0; i<fRefTPC->GetEntries(); i++) {
857          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
858          fLabelsTPC[i] = ref->GetTrack();
859        }
860        int labelPosRefs=0;
861        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
862          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
863          if (aRef->GetTrack() != posiGIndex ) break;                    
864          ++labelPosRefs;
865        }
866      
867
868
869
870        TParticle* eNegTPC;
871        fMCtruth->MCEvent()->GetParticleAndTR(elecGIndex,eNegTPC,fclRefsN);
872
873        AliMCParticle *mcParticleNeg = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(elecGIndex));
874        if(!mcParticleNeg) continue;
875
876        Int_t counterN; 
877        Float_t tpcTrackLengtheNeg = mcParticleNeg->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counterN,3.0); 
878        int nPointsN =  fclRefsN->GetEntries();
879
880        if (fRefTPC) delete fRefTPC;
881        fRefTPC = new TObjArray();
882
883        for(int iPoint=0; iPoint<nPointsN; iPoint++) {
884          AliTrackReference *ref = (AliTrackReference*)fclRefsN->At(iPoint);
885          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
886        }
887
888        fRefTPC->Sort();
889
890        for(int i=0; i<fRefTPC->GetEntries(); i++) {
891          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
892          fLabelsTPC[i] = ref->GetTrack();
893        }
894        int labelNegRefs=0;
895        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
896          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
897          if (aRef->GetTrack() != elecGIndex ) break;                    
898          ++labelNegRefs;
899        }
900
901
902        
903        if ( labelNegRefs==0 || labelPosRefs==0) continue; // if e+/e- do not have a TPC ref continue;
904        ////////////////////////////////////////////////////////////////////
905        
906        
907        fnConvGamGeant++;
908        fgConvGamGeantIndex[fnConvGamGeant]=iTracks;
909        feNegConvGamGeantIndex[fnConvGamGeant] = elecGIndex;
910        fePosConvGamGeantIndex[fnConvGamGeant] = posiGIndex;
911        
912        feNegConvGamGeantLength[fnConvGamGeant] = tpcTrackLengtheNeg;
913        fePosConvGamGeantLength[fnConvGamGeant] = tpcTrackLengthePos;
914
915      }
916
917      
918      TParticle* piPos = NULL;
919      TParticle* piNeg = NULL;
920      fpiPosK0Index=-1;
921      fpiNegK0Index=-1;
922
923      if (particle->GetPdgCode()== 310){          // k0short
924        if(particle->GetNDaughters() == 2){
925          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
926            TParticle *tmpDaughter = fStack->Particle(daughterIndex);
927            if(tmpDaughter->GetPdgCode() == 211){
928              piPos= tmpDaughter;
929              fpiPosK0Index=daughterIndex;
930            }
931            else if(tmpDaughter->GetPdgCode() == -211){
932              piNeg = tmpDaughter;
933              fpiNegK0Index=daughterIndex;
934            }
935          }
936        }
937
938        if(piPos == NULL || piNeg == NULL){ // means we do not have two daughters from K0short decay
939          continue;
940        }
941        
942        if(TMath::Abs(piPos->Eta())> maxEta || TMath::Abs(piNeg->Eta())> maxEta){
943          continue;
944        }        
945        
946        if(piPos->R()> maxVertex ){
947          continue; // cuts on distance from collision point
948        }
949       
950       
951        if( (TMath::Abs(piPos->Vz()) * lineCutZRSlope - lineCutZValue)  > piPos->R() ){
952          continue;               // line cut to exclude regions where we do not reconstruct
953        }                
954
955       // Looking at the existance of TPC references
956
957        TParticle* ePosTPC;
958        fMCtruth->MCEvent()->GetParticleAndTR(fpiPosK0Index,ePosTPC,fclRefsP);
959
960        AliMCParticle *mcParticlePos = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(fpiPosK0Index));
961        if(!mcParticlePos) continue;
962
963        Int_t counter; 
964        Float_t tpcTrackLengthePos = mcParticlePos->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counter,3.0); 
965  
966
967        int nPointsP =  fclRefsP->GetEntries();
968        if (fRefTPC) delete fRefTPC;
969        fRefTPC = new TObjArray();
970
971        for(int iPoint=0; iPoint<nPointsP; iPoint++) {
972          AliTrackReference *ref = (AliTrackReference*)fclRefsP->At(iPoint);
973          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
974        }
975
976        fRefTPC->Sort();
977
978        for(int i=0; i<fRefTPC->GetEntries(); i++) {
979          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
980          fLabelsTPC[i] = ref->GetTrack();
981        }
982        int labelPosRefs=0;
983        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
984          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
985          if (aRef->GetTrack() != fpiPosK0Index ) break;                 
986          ++labelPosRefs;
987        }
988      
989
990
991
992        TParticle* eNegTPC;
993        fMCtruth->MCEvent()->GetParticleAndTR(fpiNegK0Index,eNegTPC,fclRefsN);
994
995        AliMCParticle *mcParticleNeg = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(fpiNegK0Index));
996        if(!mcParticleNeg) continue;
997
998        Int_t counterN; 
999        Float_t tpcTrackLengtheNeg = mcParticleNeg->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counterN,3.0); 
1000
1001        int nPointsN =  fclRefsN->GetEntries();
1002        if (fRefTPC) delete fRefTPC;
1003        fRefTPC = new TObjArray();
1004
1005        for(int iPoint=0; iPoint<nPointsN; iPoint++) {
1006          AliTrackReference *ref = (AliTrackReference*)fclRefsN->At(iPoint);
1007          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1008        }
1009
1010        fRefTPC->Sort();
1011
1012        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1013          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1014          fLabelsTPC[i] = ref->GetTrack();
1015        }
1016        int labelNegRefs=0;
1017        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1018          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1019          if (aRef->GetTrack() != fpiNegK0Index ) break;                 
1020          ++labelNegRefs;
1021        }
1022        
1023        if ( labelNegRefs==0 || labelPosRefs==0) continue; // if pi+/pi- do not have a TPC ref continue;
1024        ////////////////////////////////////////////////////////////////////
1025        
1026        fnDecayK0Geant++;
1027
1028        fK0DecayK0GeantIndex[fnDecayK0Geant]=iTracks;
1029        fpiNegDecayK0GeantIndex[fnDecayK0Geant]=fpiNegK0Index;
1030        fpiPosDecayK0GeantIndex[fnDecayK0Geant]=fpiPosK0Index;
1031        fpiNegDecayK0GeantLength[fnDecayK0Geant]=tpcTrackLengtheNeg;
1032        fpiPosDecayK0GeantLength[fnDecayK0Geant]=tpcTrackLengthePos;
1033       
1034      }    
1035
1036
1037      TParticle* pPos = NULL;
1038      TParticle* piNegL = NULL;
1039      pPosLIndex=-1;
1040      piNegLIndex=-1;
1041
1042  
1043      if (particle->GetPdgCode()== 3122){        //lambda
1044       
1045        if(particle->GetNDaughters() == 2){
1046          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
1047            TParticle *tmpDaughter = fStack->Particle(daughterIndex);
1048            if(tmpDaughter->GetPdgCode() == 2212){
1049              pPos= tmpDaughter;
1050              pPosLIndex=daughterIndex;
1051            }
1052            else if(tmpDaughter->GetPdgCode() == -211){
1053              piNegL = tmpDaughter;
1054              piNegLIndex=daughterIndex;
1055            }
1056          }
1057        }
1058
1059        if(pPos == NULL || piNegL == NULL){ // means we do not have two daughters from lambda decay
1060          continue;
1061        }
1062
1063        if(TMath::Abs(pPos->Eta())> maxEta || TMath::Abs(piNegL->Eta())> maxEta){
1064          continue;
1065        }        
1066        
1067        if(pPos->R()> maxVertex ){
1068          continue; // cuts on distance from collision point
1069        }
1070       
1071       
1072        if( (TMath::Abs(pPos->Vz()) * lineCutZRSlope - lineCutZValue)  > pPos->R() ){
1073          continue;               // line cut to exclude regions where we do not reconstruct
1074        }
1075
1076
1077      // Looking at the existance of TPC references
1078
1079        TParticle* ePosTPC;
1080        fMCtruth->MCEvent()->GetParticleAndTR(pPosLIndex,ePosTPC,fclRefsP);
1081
1082        AliMCParticle *mcParticlePos = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(pPosLIndex));
1083        if(!mcParticlePos) continue;
1084
1085        Int_t counter; 
1086        Float_t tpcTrackLengthePos = mcParticlePos->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counter,3.0); 
1087  
1088
1089        int nPointsP =  fclRefsP->GetEntries();
1090        if (fRefTPC) delete fRefTPC;
1091        fRefTPC = new TObjArray();
1092
1093        for(int iPoint=0; iPoint<nPointsP; iPoint++) {
1094          AliTrackReference *ref = (AliTrackReference*)fclRefsP->At(iPoint);
1095          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1096        }
1097
1098        fRefTPC->Sort();
1099
1100        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1101          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1102          fLabelsTPC[i] = ref->GetTrack();
1103        }
1104        int labelPosRefs=0;
1105        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1106          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1107          if (aRef->GetTrack() != pPosLIndex ) break;                    
1108          ++labelPosRefs;
1109        }
1110      
1111
1112
1113
1114        TParticle* eNegTPC;
1115        fMCtruth->MCEvent()->GetParticleAndTR(piNegLIndex,eNegTPC,fclRefsN);
1116
1117        AliMCParticle *mcParticleNeg = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(piNegLIndex));
1118        if(!mcParticleNeg) continue;
1119
1120        Int_t counterN; 
1121        Float_t tpcTrackLengtheNeg = mcParticleNeg->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counterN,3.0); 
1122
1123        int nPointsN =  fclRefsN->GetEntries();
1124        if (fRefTPC) delete fRefTPC;
1125        fRefTPC = new TObjArray();
1126
1127        for(int iPoint=0; iPoint<nPointsN; iPoint++) {
1128          AliTrackReference *ref = (AliTrackReference*)fclRefsN->At(iPoint);
1129          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1130        }
1131
1132        fRefTPC->Sort();
1133
1134        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1135          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1136          fLabelsTPC[i] = ref->GetTrack();
1137        }
1138        int labelNegRefs=0;
1139        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1140          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1141          if (aRef->GetTrack() != piNegLIndex ) break;                   
1142          ++labelNegRefs;
1143        }
1144        
1145        if ( labelNegRefs==0 || labelPosRefs==0) continue; // if proton/pi- do not have a TPC ref continue;
1146        ////////////////////////////////////////////////////////////////////
1147      
1148        fnDecayLGeant++;
1149
1150        flDecayLGeantIndex[fnDecayLGeant]=iTracks;
1151      
1152        fpiNegDecayLGeantIndex[fnDecayLGeant]=piNegLIndex;
1153        fpPosDecayLGeantIndex[fnDecayLGeant]=pPosLIndex;
1154
1155        fpiNegDecayLGeantLength[fnDecayLGeant]=tpcTrackLengtheNeg;
1156        fpPosDecayLGeantLength[fnDecayLGeant]=tpcTrackLengthePos;
1157
1158      
1159      }
1160
1161      /////////////////////////////////////////////////////
1162
1163      // AntiLambda    
1164      TParticle* apNeg = NULL;
1165      TParticle* piPosAL = NULL;
1166      apNegALIndex=-1;
1167      piPosALIndex=-1;
1168
1169  
1170      if (particle->GetPdgCode()== -3122){        //antilambda
1171
1172        if(particle->GetNDaughters() == 2){
1173          for(Int_t daughterIndex=particle->GetFirstDaughter();daughterIndex<=particle->GetLastDaughter();daughterIndex++){
1174            TParticle *tmpDaughter = fStack->Particle(daughterIndex);
1175            if(tmpDaughter->GetPdgCode() == -2212){
1176              apNeg= tmpDaughter;
1177              apNegALIndex=daughterIndex;
1178            }
1179            else if(tmpDaughter->GetPdgCode() == 211){
1180              piPosAL = tmpDaughter;
1181              piPosALIndex=daughterIndex;
1182            }
1183          }
1184        }
1185
1186        if(apNeg == NULL || piPosAL == NULL){ // means we do not have two daughters from antilambda decay
1187          continue;
1188        }
1189
1190        if(TMath::Abs(apNeg->Eta())> maxEta || TMath::Abs(piPosAL->Eta())> maxEta){
1191          continue;
1192        }        
1193        
1194        if(apNeg->R()> maxVertex ){
1195          continue; // cuts on distance from collision point
1196        }
1197       
1198       
1199        if( (TMath::Abs(apNeg->Vz()) * lineCutZRSlope - lineCutZValue)  > apNeg->R() ){
1200          continue;               // line cut to exclude regions where we do not reconstruct
1201        }
1202
1203
1204      // Looking at the existance of TPC references
1205
1206        TParticle* ePosTPC;
1207        fMCtruth->MCEvent()->GetParticleAndTR(piPosALIndex,ePosTPC,fclRefsP);
1208
1209        AliMCParticle *mcParticlePos = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(piPosALIndex));
1210        if(!mcParticlePos) continue;
1211
1212        Int_t counter; 
1213        Float_t tpcTrackLengthePos = mcParticlePos->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counter,3.0); 
1214
1215        int nPointsP =  fclRefsP->GetEntries();
1216        if (fRefTPC) delete fRefTPC;
1217        fRefTPC = new TObjArray();
1218
1219        for(int iPoint=0; iPoint<nPointsP; iPoint++) {
1220          AliTrackReference *ref = (AliTrackReference*)fclRefsP->At(iPoint);
1221          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1222        }
1223
1224        fRefTPC->Sort();
1225
1226        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1227          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1228          fLabelsTPC[i] = ref->GetTrack();
1229        }
1230        int labelPosRefs=0;
1231        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1232          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1233          if (aRef->GetTrack() != piPosALIndex ) break;                  
1234          ++labelPosRefs;
1235        }
1236      
1237
1238        TParticle* eNegTPC;
1239        fMCtruth->MCEvent()->GetParticleAndTR(apNegALIndex,eNegTPC,fclRefsN);
1240
1241        AliMCParticle *mcParticleNeg = (AliMCParticle*) (fMCtruth->MCEvent()->GetTrack(apNegALIndex));
1242        if(!mcParticleNeg) continue;
1243
1244        Int_t counterN; 
1245        Float_t tpcTrackLengtheNeg = mcParticleNeg->GetTPCTrackLength(fESD->GetMagneticField(),0.05,counterN,3.0); 
1246
1247        int nPointsN =  fclRefsN->GetEntries();
1248        if (fRefTPC) delete fRefTPC;
1249        fRefTPC = new TObjArray();
1250
1251        for(int iPoint=0; iPoint<nPointsN; iPoint++) {
1252          AliTrackReference *ref = (AliTrackReference*)fclRefsN->At(iPoint);
1253          if (ref->DetectorId() == AliTrackReference::kTPC) fRefTPC->Add(new AliTrackReference(*ref));    
1254        }
1255
1256        fRefTPC->Sort();
1257
1258        for(int i=0; i<fRefTPC->GetEntries(); i++) {
1259          AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[i]; 
1260          fLabelsTPC[i] = ref->GetTrack();
1261        }
1262        int labelNegRefs=0;
1263        for(int iPoint=GetTPCReference(iTracks);iPoint<fRefTPC->GetEntries();iPoint++){
1264          AliTrackReference* aRef = (AliTrackReference*)(*fRefTPC)[iPoint];
1265          if (aRef->GetTrack() != apNegALIndex ) break;                  
1266          ++labelNegRefs;
1267        }
1268
1269
1270        
1271        if ( labelNegRefs==0 || labelPosRefs==0) continue; // if proton/pi- do not have a TPC ref continue;
1272        ////////////////////////////////////////////////////////////////////
1273      
1274        fnDecayALGeant++;
1275        falDecayALGeantIndex[fnDecayALGeant]=iTracks;
1276      
1277        fpiPosDecayALGeantIndex[fnDecayALGeant]=piPosALIndex;
1278        fapNegDecayALGeantIndex[fnDecayALGeant]=apNegALIndex;
1279
1280        fpiPosDecayALGeantLength[fnDecayALGeant]=tpcTrackLengthePos;
1281        fapNegDecayALGeantLength[fnDecayALGeant]=tpcTrackLengtheNeg;
1282
1283      
1284      }  // AntiLambda    
1285
1286     } //track loop 
1287    }    
1288
1289   }
1290
1291
1292   AliKFParticle::SetField(fESD->GetMagneticField());
1293
1294   const AliESDVertex *pvertex = fESD->GetPrimaryVertex();
1295   Double_t xyzVtx[3];
1296   pvertex->GetXYZ(xyzVtx);
1297
1298   if(fnTracksPrim>0) {
1299
1300     InspectListOfChargedParticles();
1301     InspectListOfV0s();
1302
1303
1304     if(fnConvGamGeant>-1){
1305       FillHnSparseGamma();
1306     }
1307
1308     if(fnDecayK0Geant>-1){
1309       FillHnSparseK0();
1310     }
1311
1312     if(fnDecayLGeant>-1){
1313       FillHnSparseL();
1314     }
1315
1316     if(fnDecayALGeant>-1){
1317       FillHnSparseAL();
1318     }
1319
1320   }
1321
1322  
1323   PostData(0,fOutputContainer );
1324   
1325
1326 }
1327
1328 void AliAnalysisTaskV0QA::Terminate(Option_t *) {
1329   // Draw some histogram at the end.
1330
1331 }
1332
1333
1334 Int_t AliAnalysisTaskV0QA::GetTPCReference(Int_t label) {
1335   // Get TPC References
1336
1337   int start = TMath::BinarySearch(fRefTPC->GetEntries(), fLabelsTPC, label);
1338
1339   while (start >= 0) {
1340     AliTrackReference *ref = (AliTrackReference*)(*fRefTPC)[start];
1341     if (ref->GetTrack() != label) return start+1;
1342     start--;
1343   }
1344
1345   return 0;
1346 }
1347
1348
1349
1350
1351
1352 void AliAnalysisTaskV0QA::InspectListOfChargedParticles(){
1353   // Look at the list of particles for the single track reconstruction
1354
1355   for(Int_t iTracks = 0; iTracks < fESD->GetNumberOfTracks(); iTracks++){
1356
1357     AliESDtrack* curTrack = fESD->GetTrack(iTracks);
1358
1359     if(!curTrack){
1360       continue;
1361     }
1362
1363
1364 //     if( !(curTrack->GetStatus() & AliESDtrack::kTPCrefit)){
1365 //       continue;
1366 //     }
1367
1368
1369     Int_t labelMC = TMath::Abs(curTrack->GetLabel());
1370
1371     if ( labelMC > fStack->GetNtrack() ) continue;
1372
1373
1374     TParticle* curParticle = fStack->Particle(labelMC);
1375     if(curParticle->GetMother(0)==-1){
1376       continue;
1377     }
1378
1379      
1380     if(TMath::Abs(curParticle->GetPdgCode()) == 11){ // e+/e-
1381       
1382       if( fStack->Particle(curParticle->GetMother(0))->GetPdgCode()==22 ){  // e+/e- from gamma
1383         if( curParticle->GetUniqueID()!=5 ){ // e+/e- from gamma conversion
1384           continue;
1385         }
1386
1387         for(Int_t iGamConv=0;iGamConv<fnConvGamGeant+1;iGamConv++ ){
1388           if(curTrack->GetSign()>0){
1389             if (labelMC== fePosConvGamGeantIndex[iGamConv]){
1390               fePosConvGamSingleRecIndex[iGamConv]=iTracks;
1391             }
1392           }else{
1393             if (labelMC== feNegConvGamGeantIndex[iGamConv]){
1394               feNegConvGamSingleRecIndex[iGamConv]=iTracks;
1395             }
1396           }
1397         } // loop over geant converted gammas
1398
1399       }
1400     } // condition to select reconstructed electrons
1401   
1402
1403
1404     if(TMath::Abs(curParticle->GetPdgCode()) == 211 || TMath::Abs(curParticle->GetPdgCode())==2212 ){ // pi+/pi-
1405       
1406       if( fStack->Particle(curParticle->GetMother(0))->GetPdgCode()==310 || 
1407           fStack->Particle(curParticle->GetMother(0))->GetPdgCode()==3122 || 
1408           fStack->Particle(curParticle->GetMother(0))->GetPdgCode()==-3122 ){  // pi+/proton/pi- from K0/Lambda
1409
1410         for(Int_t iK0Dec=0;iK0Dec<fnDecayK0Geant+1;iK0Dec++ ){
1411           if(curTrack->GetSign()>0){
1412             if (labelMC== fpiPosDecayK0GeantIndex[iK0Dec]){
1413               fpiPosDecayK0SingleRecIndex[iK0Dec]=iTracks;
1414             }
1415           }else{
1416             if (labelMC== fpiNegDecayK0GeantIndex[iK0Dec]){
1417               fpiNegDecayK0SingleRecIndex[iK0Dec]=iTracks;
1418             }
1419           }
1420         } // loop over geant decay K0
1421
1422         for(Int_t iLDec=0;iLDec<fnDecayLGeant+1;iLDec++ ){
1423           if(curTrack->GetSign()>0){
1424             if (labelMC== fpPosDecayLGeantIndex[iLDec]){
1425               fpPosDecayLSingleRecIndex[iLDec]=iTracks;
1426             }
1427           }else{
1428             if (labelMC== fpiNegDecayLGeantIndex[iLDec]){
1429               fpiNegDecayLSingleRecIndex[iLDec]=iTracks;
1430             }
1431           }
1432         } // loop over geant decay Lambda
1433
1434         for(Int_t iALDec=0;iALDec<fnDecayALGeant+1;iALDec++ ){
1435           if(curTrack->GetSign()<0){
1436             if (labelMC== fapNegDecayALGeantIndex[iALDec]){
1437               fapNegDecayALSingleRecIndex[iALDec]=iTracks;
1438             }
1439           }else{
1440             if (labelMC== fpiPosDecayALGeantIndex[iALDec]){
1441               fpiPosDecayALSingleRecIndex[iALDec]=iTracks;
1442             }
1443           }
1444         } // loop over geant decay antiLambda
1445       }
1446     } // condition to select reconstructed electrons
1447    } // all reconstructed track
1448
1449
1450 }
1451
1452 void AliAnalysisTaskV0QA::InspectListOfV0s(){
1453   // Look at the list of particles for the V0 reconstruction
1454
1455   AliESDtrack* trackPos= NULL;
1456   AliESDtrack* trackNeg= NULL;
1457   Int_t grandMotherPos=-1;
1458   Int_t grandMotherNeg=-1;
1459   Int_t motherPos=-1;
1460   Int_t motherNeg=-1;
1461   Int_t pIndex=-1;
1462   Int_t nIndex=-1;
1463
1464   for(Int_t iV0MI = 0; iV0MI < fESD->GetNumberOfV0s(); iV0MI++) {
1465
1466     AliESDv0 * fV0MIs = fESD->GetV0(iV0MI);
1467     
1468
1469     if ( !fV0MIs->GetOnFlyStatus() ){
1470         continue;
1471     }
1472     if(fnTracksPrim<=0) {
1473       continue;
1474     }
1475
1476
1477     AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
1478     AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
1479
1480
1481     if ( trackPosTest->GetSign() == trackNegTest->GetSign()){
1482      continue;
1483     }
1484
1485     //To avoid ghosts
1486
1487 //     if( !(trackPosTest->GetStatus() & AliESDtrack::kTPCrefit)){
1488 //       continue;
1489 //     }
1490
1491 //     if( !(trackNegTest->GetStatus() & AliESDtrack::kTPCrefit)){
1492 //       continue;
1493 //     }
1494
1495     if( trackPosTest->GetSign() ==1){
1496       trackPos =fESD->GetTrack(fV0MIs->GetPindex());
1497       trackNeg =fESD->GetTrack(fV0MIs->GetNindex());
1498       pIndex=fV0MIs->GetPindex();
1499       nIndex=fV0MIs->GetNindex();
1500     }
1501
1502     if( trackPosTest->GetSign() ==-1){
1503       trackPos =fESD->GetTrack(fV0MIs->GetNindex());
1504       trackNeg =fESD->GetTrack(fV0MIs->GetPindex());
1505       pIndex=fV0MIs->GetNindex();
1506       nIndex=fV0MIs->GetPindex();
1507
1508     }
1509
1510     Int_t labelNeg=TMath::Abs(trackNeg->GetLabel());
1511     if(labelNeg > fStack->GetNtrack() ) continue;
1512     TParticle * particleNeg= fStack->Particle(labelNeg);
1513
1514     Int_t labelPos=TMath::Abs(trackPos->GetLabel());
1515     if(labelPos > fStack->GetNtrack() ) continue;
1516     TParticle * particlePos= fStack->Particle(labelPos);
1517
1518
1519     if(particlePos->GetMother(0)>-1){
1520       grandMotherPos=fStack->Particle(particlePos->GetMother(0))->GetMother(0);
1521       motherPos=particlePos->GetMother(0);
1522     }
1523     
1524     if(particleNeg->GetMother(0)>-1){
1525       grandMotherNeg=fStack->Particle(particleNeg->GetMother(0))->GetMother(0);
1526       motherNeg=particleNeg->GetMother(0);
1527     }
1528
1529     if(motherPos == motherNeg &&  motherPos!=-1 ){
1530       if( particlePos->GetPdgCode() ==-11  &&   particleNeg->GetPdgCode()==11 ){
1531         for(Int_t iGamConv=0;iGamConv<fnConvGamGeant+1;iGamConv++ ){
1532           if (labelPos== fePosConvGamGeantIndex[iGamConv]){
1533             fePosConvGamV0RecIndex[iGamConv]=pIndex;
1534             fConvGamV0RecIndexPos[iGamConv]=iV0MI;
1535           }
1536           if (labelNeg== feNegConvGamGeantIndex[iGamConv]){
1537             feNegConvGamV0RecIndex[iGamConv]=nIndex;
1538             fConvGamV0RecIndexNeg[iGamConv]=iV0MI;
1539           }
1540
1541         } // loop over geant converted gammas
1542       }
1543
1544       if( particlePos->GetPdgCode()==211  &&   particleNeg->GetPdgCode()==-211 ){
1545         for(Int_t iK0Dec=0;iK0Dec<fnDecayK0Geant+1;iK0Dec++ ){
1546           if (labelPos== fpiPosDecayK0GeantIndex[iK0Dec]){
1547             fpiPosDecayK0V0RecIndex[iK0Dec]=pIndex;
1548             fDecayK0V0RecIndexPos[iK0Dec]=iV0MI;
1549           }
1550           if (labelNeg== fpiNegDecayK0GeantIndex[iK0Dec]){
1551             fpiNegDecayK0V0RecIndex[iK0Dec]=nIndex;
1552             fDecayK0V0RecIndexNeg[iK0Dec]=iV0MI;
1553           }
1554
1555         } // loop over geant K0
1556       }
1557
1558       if( particlePos->GetPdgCode()==2212  && particleNeg->GetPdgCode()==-211 ){
1559         for(Int_t iLDec=0;iLDec<fnDecayLGeant+1;iLDec++ ){
1560           if (labelPos== fpPosDecayLGeantIndex[iLDec]){
1561             fpPosDecayLV0RecIndex[iLDec]=pIndex;
1562             fDecayLV0RecIndexPos[iLDec]=iV0MI;
1563           }
1564           if (labelNeg== fpiNegDecayLGeantIndex[iLDec]){
1565             fpiNegDecayLV0RecIndex[iLDec]=nIndex;
1566             fDecayLV0RecIndexNeg[iLDec]=iV0MI;
1567           }
1568
1569         } // loop over geant Lambda
1570       }
1571
1572       if( particleNeg->GetPdgCode()==-2212  && particlePos->GetPdgCode()==211 ){
1573         for(Int_t iALDec=0;iALDec<fnDecayALGeant+1;iALDec++ ){
1574           if (labelNeg== fapNegDecayALGeantIndex[iALDec]){
1575             fapNegDecayALV0RecIndex[iALDec]=nIndex;
1576             fDecayALV0RecIndexNeg[iALDec]=iV0MI;
1577           }
1578           if (labelPos== fpiPosDecayALGeantIndex[iALDec]){
1579             fpiPosDecayALV0RecIndex[iALDec]=pIndex;
1580             fDecayALV0RecIndexPos[iALDec]=iV0MI;
1581           }
1582
1583         } // loop over geant antiLambda
1584       }
1585
1586
1587     }
1588     
1589   }
1590   for(Int_t iGamConv=0;iGamConv<fnConvGamGeant+1;iGamConv++ ){
1591     if ( fConvGamV0RecIndexNeg[iGamConv]!=  fConvGamV0RecIndexPos[iGamConv]){
1592       fePosConvGamV0RecIndex[iGamConv]=-1;
1593       feNegConvGamV0RecIndex[iGamConv]=-1; 
1594       fConvGamV0RecIndexNeg[iGamConv]=-1;
1595       fConvGamV0RecIndexPos[iGamConv]=-1;
1596
1597     }
1598   }
1599
1600   for(Int_t iLDec=0;iLDec<fnDecayLGeant+1;iLDec++ ){
1601     if(fDecayLV0RecIndexPos[iLDec] !=  fDecayLV0RecIndexNeg[iLDec]){
1602       fpiNegDecayLV0RecIndex[iLDec]=-1;
1603       fpPosDecayLV0RecIndex[iLDec]=-1;
1604       fDecayLV0RecIndexNeg[iLDec]=-1;
1605       fDecayLV0RecIndexPos[iLDec]=-1;
1606     }
1607   }
1608
1609   for(Int_t iALDec=0;iALDec<fnDecayALGeant+1;iALDec++ ){
1610     if(fDecayALV0RecIndexPos[iALDec] !=  fDecayALV0RecIndexNeg[iALDec]){
1611       fpiPosDecayALV0RecIndex[iALDec]=-1;
1612       fapNegDecayALV0RecIndex[iALDec]=-1;
1613       fDecayALV0RecIndexNeg[iALDec]=-1;
1614       fDecayALV0RecIndexPos[iALDec]=-1;
1615     }
1616   }
1617
1618   for(Int_t iK0Dec=0;iK0Dec<fnDecayK0Geant+1;iK0Dec++ ){
1619     if(fDecayK0V0RecIndexPos[iK0Dec] !=  fDecayK0V0RecIndexNeg[iK0Dec]){
1620       fpiNegDecayK0V0RecIndex[iK0Dec]=-1;
1621       fpiPosDecayK0V0RecIndex[iK0Dec]=-1;
1622       fDecayK0V0RecIndexNeg[iK0Dec]=-1;
1623       fDecayK0V0RecIndexPos[iK0Dec]=-1;
1624     }
1625   }
1626   
1627
1628 }
1629 void AliAnalysisTaskV0QA::FillHnSparseGamma()
1630 {
1631   // Fill THnSparse Gamma
1632
1633   Double_t massE=0.00051099892;
1634   Double_t ppSgl[3];
1635   Double_t pmSgl[3];
1636   Float_t bPosSgl[2];
1637   Float_t bNegSgl[2];
1638   Float_t bPosCov[3];
1639   Float_t bNegCov[3];
1640   
1641   Double_t ppV0[3];
1642   Double_t pmV0[3];
1643   Double_t xrG[3];
1644   
1645   TLorentzVector posSglTrack;
1646   TLorentzVector negSglTrack;
1647   Double_t posPt,posEta,posPhi;
1648   Double_t negPt,negEta,negPhi;
1649
1650   TLorentzVector posV0Track;
1651   TLorentzVector negV0Track;
1652   Double_t posV0Pt,posV0Eta,posV0Phi;
1653   Double_t negV0Pt,negV0Eta,negV0Phi;
1654   
1655   Float_t nClsITSPos=-1;
1656   Float_t nClsITSNeg=-1;
1657
1658   Float_t nClsTPCPos=-1;
1659   Float_t nClsTPCNeg=-1;
1660
1661   Int_t statusSingPos=-1;
1662   Int_t statusSingNeg=-1;
1663
1664   Int_t statusV0Pos=-1;
1665   Int_t statusV0Neg=-1;
1666
1667
1668   for(Int_t i=0;i<fnConvGamGeant+1;i++){
1669     TParticle* gamPart = fStack->Particle(fgConvGamGeantIndex[i]);
1670     TParticle* ePosPart = fStack->Particle(fePosConvGamGeantIndex[i]);
1671     TParticle* eNegPart = fStack->Particle(feNegConvGamGeantIndex[i]);
1672     if (fePosConvGamSingleRecIndex[i]!=-1){
1673       AliESDtrack * ePosSglTrack = fESD->GetTrack(fePosConvGamSingleRecIndex[i]);
1674       ePosSglTrack->GetPxPyPz(ppSgl); 
1675       posSglTrack.SetXYZM(ppSgl[0],ppSgl[1],ppSgl[2],massE);
1676       posPt  = posSglTrack.Pt();
1677       posEta = posSglTrack.Eta();
1678       posPhi = posSglTrack.Phi();
1679       ePosSglTrack->GetImpactParameters(bPosSgl,bPosCov);
1680       nClsITSPos=ePosSglTrack->GetNcls(0);
1681       nClsTPCPos=ePosSglTrack->GetNcls(1);
1682       statusSingPos=1;
1683     }else{
1684       posPt  = 1000000;
1685       posEta = -2.;
1686       posPhi = -2*TMath::Pi();
1687       bPosSgl[0]=-100.;
1688       bPosSgl[1]=-100.;
1689       bPosCov[0]=-100;
1690       bPosCov[2]=-100;
1691       nClsITSPos=-1;
1692       nClsTPCPos=-1;
1693       statusSingPos=-1;
1694     }
1695     
1696     if (feNegConvGamSingleRecIndex[i]!=-1){
1697       AliESDtrack * eNegSglTrack = fESD->GetTrack(feNegConvGamSingleRecIndex[i]);
1698       eNegSglTrack->GetPxPyPz(pmSgl); 
1699       negSglTrack.SetXYZM(pmSgl[0],pmSgl[1],pmSgl[2],massE);
1700       negPt  = negSglTrack.Pt();
1701       negEta = negSglTrack.Eta();
1702       negPhi = negSglTrack.Phi();
1703       eNegSglTrack->GetImpactParameters(bNegSgl,bNegCov);
1704       nClsITSNeg=eNegSglTrack->GetNcls(0);
1705       nClsTPCNeg=eNegSglTrack->GetNcls(1);
1706       statusSingNeg=1;
1707     }else{
1708       negPt  = 1000000;
1709       negEta = -2.;
1710       negPhi = -2*TMath::Pi();
1711       bNegSgl[0]=-100.;
1712       bNegSgl[1]=-100.;
1713       bNegCov[0]=-100;
1714       bNegCov[2]=-100;
1715       nClsITSNeg=-1;
1716       nClsTPCNeg=-1;
1717       statusSingNeg=-1;
1718     }
1719
1720     posV0Pt  = 1000000;
1721     posV0Eta = -2.;
1722     posV0Phi = -2*TMath::Pi();
1723     negV0Pt  = 1000000;
1724     negV0Eta = -2.;
1725     negV0Phi = -2*TMath::Pi();
1726     
1727     if(fConvGamV0RecIndexPos[i]!=-1){
1728       AliESDv0 * fV0MIs = fESD->GetV0(fConvGamV0RecIndexPos[i]);
1729       AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
1730       AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
1731
1732       if (fePosConvGamV0RecIndex[i]!=-1 ){
1733         //      AliESDtrack * ePosV0Track = fESD->GetTrack(ePosConvGamV0RecIndex[i]);
1734         if ( trackPosTest->GetSign()==1 ) {
1735           fV0MIs->GetPPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
1736         }else{
1737           fV0MIs->GetNPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
1738         }
1739         posV0Track.SetXYZM(ppV0[0],ppV0[1],ppV0[2],massE);
1740
1741         posV0Pt  = posV0Track.Pt();
1742         posV0Eta = posV0Track.Eta();
1743         posV0Phi = posV0Track.Phi();
1744         statusV0Pos=1;
1745       }else{
1746         posV0Pt  = 1000000;
1747         posV0Eta = -2.;
1748         posV0Phi = -2*TMath::Pi();
1749         statusV0Pos=-1;
1750       }
1751       
1752       if (feNegConvGamV0RecIndex[i]!=-1 ){
1753         //      AliESDtrack * eNegV0Track = fESD->GetTrack(eNegConvGamV0RecIndex[i]);
1754         if ( trackNegTest->GetSign()==-1 ) {
1755           fV0MIs->GetNPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
1756         }else{
1757           fV0MIs->GetPPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
1758         }
1759         negV0Track.SetXYZM(pmV0[0],pmV0[1],pmV0[2],massE);
1760         
1761         negV0Pt  = negV0Track.Pt();
1762         negV0Eta = negV0Track.Eta();
1763         negV0Phi = negV0Track.Phi();
1764         statusV0Neg=1;
1765       }else{
1766         negV0Pt  = 1000000;
1767         negV0Eta = -2.;
1768         negV0Phi = -2*TMath::Pi();
1769         statusV0Neg=-1;
1770       }
1771     }
1772     
1773     xrG[0] = ePosPart->Vx();
1774     xrG[1] = ePosPart->Vy();
1775     xrG[2] = ePosPart->Vz();
1776     
1777     //--------- Geant variables ----------------------
1778     fValueV0[0] = 1./TMath::Sqrt(gamPart->Pt());
1779     fValueV0[1] = gamPart->Eta();
1780
1781     Double_t tmpGPhi=gamPart->Phi();
1782     if( gamPart->Phi()>TMath::Pi()){
1783       tmpGPhi=gamPart->Phi()-2*TMath::Pi();
1784     }
1785     fValueV0[2] = tmpGPhi;
1786
1787     fValueV0[3] = TMath::Sqrt(xrG[0]*xrG[0]+xrG[1]*xrG[1]);
1788     fValueV0[4] = xrG[2];
1789  
1790
1791     fValueV0[5] = 1./TMath::Sqrt(ePosPart->Pt());
1792     fValueV0[6] = ePosPart->Eta();
1793
1794     Double_t tmpPPhi=ePosPart->Phi();
1795     if( ePosPart->Phi()>TMath::Pi()){
1796       tmpPPhi = ePosPart->Phi()-2*TMath::Pi();
1797     }
1798      fValueV0[7] = tmpPPhi;
1799      fValueV0[8] = fePosConvGamGeantLength[i];
1800
1801     fValueV0[9] = 1./TMath::Sqrt(eNegPart->Pt());
1802     fValueV0[10] = eNegPart->Eta();
1803
1804     Double_t tmpNPhi=eNegPart->Phi();
1805     if( eNegPart->Phi()>TMath::Pi()){
1806       tmpNPhi = eNegPart->Phi()-2*TMath::Pi();
1807     }
1808     fValueV0[11] = tmpNPhi;
1809     fValueV0[12] = feNegConvGamGeantLength[i];    
1810
1811     //---- Single track variables----------------------
1812
1813     fValueV0[13] = (posPt-ePosPart->Pt())/ePosPart->Pt();
1814     fValueV0[14] = posEta;
1815     fValueV0[15] = posPhi;
1816     fValueV0[16] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] );
1817     fValueV0[17] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] )/TMath::Sqrt(bPosCov[0]*bPosCov[0]+bPosCov[2]*bPosCov[2]);
1818     fValueV0[18] = nClsITSPos;
1819     fValueV0[19] = nClsTPCPos;
1820     fValueV0[20] = statusSingPos;
1821
1822
1823     fValueV0[21] = (negPt-eNegPart->Pt())/eNegPart->Pt();
1824     fValueV0[22] = negEta;
1825     fValueV0[23] = negPhi;
1826     fValueV0[24] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] );
1827     fValueV0[25] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] )/TMath::Sqrt(bNegCov[0]*bNegCov[0]+bNegCov[2]*bNegCov[2]);
1828
1829     fValueV0[26] = nClsITSNeg;
1830     fValueV0[27] = nClsTPCNeg;
1831     fValueV0[28] = statusSingNeg;
1832
1833     
1834     //---- V0 track variables----------------------
1835
1836     fValueV0[29] = (posV0Pt-ePosPart->Pt())/ePosPart->Pt();
1837     fValueV0[30] = posV0Eta;
1838     fValueV0[31] = posV0Phi;
1839     fValueV0[32] = statusV0Pos;
1840
1841     fValueV0[33] = (negV0Pt-eNegPart->Pt())/eNegPart->Pt();
1842     fValueV0[34] = negV0Eta;
1843     fValueV0[35] = negV0Phi;
1844     fValueV0[36] = statusV0Neg;
1845
1846     fSparseV0->Fill(fValueV0);
1847   }
1848
1849
1850 }
1851
1852 void AliAnalysisTaskV0QA::FillHnSparseK0()
1853 {
1854   // Fill THnSparse K0
1855
1856   Double_t massPi=0.13957018;
1857   Double_t ppSgl[3];
1858   Double_t pmSgl[3];
1859   Float_t bPosSgl[2];
1860   Float_t bNegSgl[2];
1861   Float_t bPosCov[3];
1862   Float_t bNegCov[3];
1863   
1864   Double_t ppV0[3];
1865   Double_t pmV0[3];
1866   Double_t xrG[3];
1867   
1868   TLorentzVector posSglTrack;
1869   TLorentzVector negSglTrack;
1870   Double_t posPt,posEta,posPhi;
1871   Double_t negPt,negEta,negPhi;
1872
1873   TLorentzVector posV0Track;
1874   TLorentzVector negV0Track;
1875   Double_t posV0Pt,posV0Eta,posV0Phi;
1876   Double_t negV0Pt,negV0Eta,negV0Phi;
1877   
1878   Float_t nClsITSPos=-1;
1879   Float_t nClsITSNeg=-1;
1880
1881   Float_t nClsTPCPos=-1;
1882   Float_t nClsTPCNeg=-1;
1883
1884   Int_t statusSingPos=-1;
1885   Int_t statusSingNeg=-1;
1886
1887   Int_t statusV0Pos=-1;
1888   Int_t statusV0Neg=-1;
1889   
1890   for(Int_t i=0;i<fnDecayK0Geant+1;i++){
1891     TParticle* k0Part = fStack->Particle(fK0DecayK0GeantIndex[i]);
1892     TParticle* ePosPart = fStack->Particle(fpiPosDecayK0GeantIndex[i]);
1893     TParticle* eNegPart = fStack->Particle(fpiNegDecayK0GeantIndex[i]);
1894     if (fpiPosDecayK0SingleRecIndex[i]!=-1){
1895       AliESDtrack * ePosSglTrack = fESD->GetTrack(fpiPosDecayK0SingleRecIndex[i]);
1896       ePosSglTrack->GetPxPyPz(ppSgl); 
1897       posSglTrack.SetXYZM(ppSgl[0],ppSgl[1],ppSgl[2],massPi);
1898       posPt  = posSglTrack.Pt();
1899       posEta = posSglTrack.Eta();
1900       posPhi = posSglTrack.Phi();
1901       ePosSglTrack->GetImpactParameters(bPosSgl,bPosCov);
1902       nClsITSPos=ePosSglTrack->GetNcls(0);
1903       nClsTPCPos=ePosSglTrack->GetNcls(1);
1904       statusSingPos=1;
1905     }else{
1906       posPt  = 1000000;
1907       posEta = -2.;
1908       posPhi = -2*TMath::Pi();
1909       bPosSgl[0]=-100.;
1910       bPosSgl[1]=-100.;
1911       bPosCov[0]=-100;
1912       bPosCov[2]=-100;
1913
1914       nClsITSPos=-1;
1915       nClsTPCPos=-1;
1916       statusSingPos=-1;
1917     }
1918
1919     if (fpiNegDecayK0SingleRecIndex[i]!=-1){
1920       AliESDtrack * eNegSglTrack = fESD->GetTrack(fpiNegDecayK0SingleRecIndex[i]);
1921       eNegSglTrack->GetPxPyPz(pmSgl); 
1922       negSglTrack.SetXYZM(pmSgl[0],pmSgl[1],pmSgl[2],massPi);
1923       negPt  = negSglTrack.Pt();
1924       negEta = negSglTrack.Eta();
1925       negPhi = negSglTrack.Phi();
1926       eNegSglTrack->GetImpactParameters(bNegSgl,bNegCov);
1927       nClsITSNeg=eNegSglTrack->GetNcls(0);
1928       nClsTPCNeg=eNegSglTrack->GetNcls(1);
1929       statusSingNeg=1;
1930     }else{
1931       negPt  = 1000000;
1932       negEta = -2.;
1933       negPhi = -2*TMath::Pi();
1934       bNegSgl[0]=-100.;
1935       bNegSgl[1]=-100.;
1936       bNegCov[0]=-100;
1937       bNegCov[2]=-100;
1938       nClsITSNeg=-1;
1939       nClsTPCNeg=-1;
1940       statusSingNeg=-1;
1941     }
1942
1943     posV0Pt  = 1000000;
1944     posV0Eta = -2.;
1945     posV0Phi = -2*TMath::Pi();
1946     negV0Pt  = 1000000;
1947     negV0Eta = -2.;
1948     negV0Phi = -2*TMath::Pi();
1949
1950     if(fDecayK0V0RecIndexPos[i]!=-1){
1951       AliESDv0 * fV0MIs = fESD->GetV0(fDecayK0V0RecIndexPos[i]);
1952       AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
1953       AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
1954
1955       if (fpiPosDecayK0V0RecIndex[i]!=-1 ){
1956         //      AliESDtrack * ePosV0Track = fESD->GetTrack(piPosDecayK0V0RecIndex[i]);
1957         if ( trackPosTest->GetSign()==1 ) {
1958           fV0MIs->GetPPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
1959         }else{
1960           fV0MIs->GetNPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
1961         }
1962         posV0Track.SetXYZM(ppV0[0],ppV0[1],ppV0[2],massPi);
1963
1964         posV0Pt  = posV0Track.Pt();
1965         posV0Eta = posV0Track.Eta();
1966         posV0Phi = posV0Track.Phi();
1967         statusV0Pos=1;
1968       }else{
1969         posV0Pt  = 1000000;
1970         posV0Eta = -2.;
1971         posV0Phi = -2*TMath::Pi();
1972         statusV0Pos=-1;
1973       }
1974       
1975       if (fpiNegDecayK0V0RecIndex[i]!=-1 ){
1976         //      AliESDtrack * eNegV0Track = fESD->GetTrack(piNegDecayK0V0RecIndex[i]);
1977         if ( trackNegTest->GetSign()==-1 ) {
1978           fV0MIs->GetNPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
1979         }else{
1980           fV0MIs->GetPPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
1981         }
1982         negV0Track.SetXYZM(pmV0[0],pmV0[1],pmV0[2],massPi);
1983         
1984         negV0Pt  = negV0Track.Pt();
1985         negV0Eta = negV0Track.Eta();
1986         negV0Phi = negV0Track.Phi();
1987         statusV0Neg=1;
1988       }else{
1989         negV0Pt  = 1000000;
1990         negV0Eta = -2.;
1991         negV0Phi = -2*TMath::Pi();
1992         statusV0Neg=-1;
1993       }
1994     }
1995
1996     xrG[0] = ePosPart->Vx();
1997     xrG[1] = ePosPart->Vy();
1998     xrG[2] = ePosPart->Vz();
1999     
2000     
2001     //--------- Geant variables ----------------------
2002     fValueK0[0] = 1./TMath::Sqrt(k0Part->Pt());
2003     fValueK0[1] = k0Part->Eta();
2004
2005     Double_t tmpGPhi=k0Part->Phi();
2006     if( k0Part->Phi()>TMath::Pi()){
2007       tmpGPhi=k0Part->Phi()-2*TMath::Pi();
2008     }
2009     fValueK0[2] = tmpGPhi;
2010
2011     fValueK0[3] = TMath::Sqrt(xrG[0]*xrG[0]+xrG[1]*xrG[1]);
2012     fValueK0[4] = xrG[2];
2013  
2014
2015     fValueK0[5] = 1./TMath::Sqrt(ePosPart->Pt());
2016     fValueK0[6] = ePosPart->Eta();
2017
2018     Double_t tmpPPhi=ePosPart->Phi();
2019     if( ePosPart->Phi()>TMath::Pi()){
2020       tmpPPhi = ePosPart->Phi()-2*TMath::Pi();
2021     }
2022      fValueK0[7] = tmpPPhi;
2023      fValueK0[8] = fpiPosDecayK0GeantLength[i];
2024
2025     fValueK0[9] = 1./TMath::Sqrt(eNegPart->Pt());
2026     fValueK0[10] = eNegPart->Eta();
2027
2028     Double_t tmpNPhi=eNegPart->Phi();
2029     if( eNegPart->Phi()>TMath::Pi()){
2030       tmpNPhi = eNegPart->Phi()-2*TMath::Pi();
2031     }
2032     fValueK0[11] = tmpNPhi;
2033     fValueK0[12] = fpiNegDecayK0GeantLength[i];    
2034     //---- Single track variables----------------------
2035
2036     fValueK0[13] = (posPt-ePosPart->Pt())/ePosPart->Pt() ;
2037     fValueK0[14] = posEta;
2038     fValueK0[15] = posPhi;
2039     fValueK0[16] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] );
2040     fValueK0[17] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] )/TMath::Sqrt(bPosCov[0]*bPosCov[0]+bPosCov[2]*bPosCov[2]);
2041    
2042     fValueK0[18] = nClsITSPos;
2043     fValueK0[19] = nClsTPCPos;
2044     fValueK0[20] = statusSingPos;
2045
2046     fValueK0[21] = (negPt-eNegPart->Pt())/eNegPart->Pt();
2047     fValueK0[22] = negEta;
2048     fValueK0[23] = negPhi;
2049     fValueK0[24] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0]+  bNegSgl[1]* bNegSgl[1] );
2050     fValueK0[25] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0]+  bNegSgl[1]* bNegSgl[1] )/TMath::Sqrt(bNegCov[0]*bNegCov[0]+bNegCov[2]*bNegCov[2]);
2051     fValueK0[26] = nClsITSNeg;
2052     fValueK0[27] = nClsTPCNeg;
2053     fValueK0[28] = statusSingNeg;
2054
2055     
2056     //---- V0 track variables----------------------
2057
2058     fValueK0[29] = (posV0Pt-ePosPart->Pt())/ePosPart->Pt();
2059     fValueK0[30] = posV0Eta;
2060     fValueK0[31] = posV0Phi;
2061     fValueK0[32] = statusV0Pos;
2062
2063     fValueK0[33] = (negV0Pt-eNegPart->Pt())/eNegPart->Pt();
2064     fValueK0[34] = negV0Eta;
2065     fValueK0[35] = negV0Phi;
2066     fValueK0[36] = statusV0Neg;
2067
2068     fSparseK0->Fill(fValueK0);
2069   }
2070   
2071
2072 }
2073 void AliAnalysisTaskV0QA::FillHnSparseL()
2074 {
2075   // Fill THnSparse Lambda
2076
2077   Double_t massPi=0.13957018;
2078   Double_t massP=0.93827203;
2079
2080
2081   Double_t ppSgl[3];
2082   Double_t pmSgl[3];
2083   Float_t bPosSgl[2];
2084   Float_t bNegSgl[2];
2085   Float_t bPosCov[3];
2086   Float_t bNegCov[3];
2087   
2088   Double_t ppV0[3];
2089   Double_t pmV0[3];
2090   Double_t xrG[3];
2091   
2092   TLorentzVector posSglTrack;
2093   TLorentzVector negSglTrack;
2094   Double_t posPt,posEta,posPhi;
2095   Double_t negPt,negEta,negPhi;
2096
2097   TLorentzVector posV0Track;
2098   TLorentzVector negV0Track;
2099   Double_t posV0Pt,posV0Eta,posV0Phi;
2100   Double_t negV0Pt,negV0Eta,negV0Phi;
2101   
2102   Float_t nClsITSPos=-1;
2103   Float_t nClsITSNeg=-1;
2104
2105   Float_t nClsTPCPos=-1;
2106   Float_t nClsTPCNeg=-1;
2107
2108   Int_t statusSingPos=-1;
2109   Int_t statusSingNeg=-1;
2110
2111   Int_t statusV0Pos=-1;
2112   Int_t statusV0Neg=-1;
2113
2114   for(Int_t i=0;i<fnDecayLGeant+1;i++){
2115     TParticle* lPart = fStack->Particle(flDecayLGeantIndex[i]);
2116     TParticle* ePosPart = fStack->Particle(fpPosDecayLGeantIndex[i]);
2117     TParticle* eNegPart = fStack->Particle(fpiNegDecayLGeantIndex[i]);
2118     if (fpPosDecayLSingleRecIndex[i]!=-1){
2119       AliESDtrack * ePosSglTrack = fESD->GetTrack(fpPosDecayLSingleRecIndex[i]);
2120       ePosSglTrack->GetPxPyPz(ppSgl); 
2121       posSglTrack.SetXYZM(ppSgl[0],ppSgl[1],ppSgl[2],massP);
2122       posPt  = posSglTrack.Pt();
2123       posEta = posSglTrack.Eta();
2124       posPhi = posSglTrack.Phi();
2125       ePosSglTrack->GetImpactParameters(bPosSgl,bPosCov);
2126       nClsITSPos=ePosSglTrack->GetNcls(0);
2127       nClsTPCPos=ePosSglTrack->GetNcls(1);
2128       statusSingPos=1;
2129     }else{
2130       posPt  = 1000000;
2131       posEta = -2.;
2132       posPhi = -2*TMath::Pi();
2133       bPosSgl[0]=-100.;
2134       bPosSgl[1]=-100.;
2135       bPosCov[0]=-100;
2136       bPosCov[2]=-100;
2137       nClsITSPos=-1;
2138       nClsTPCPos=-1;
2139       statusSingPos=-1;
2140     }
2141     
2142     if (fpiNegDecayLSingleRecIndex[i]!=-1){
2143       AliESDtrack * eNegSglTrack = fESD->GetTrack(fpiNegDecayLSingleRecIndex[i]);
2144       eNegSglTrack->GetPxPyPz(pmSgl); 
2145       negSglTrack.SetXYZM(pmSgl[0],pmSgl[1],pmSgl[2],massPi);
2146       negPt  = negSglTrack.Pt();
2147       negEta = negSglTrack.Eta();
2148       negPhi = negSglTrack.Phi();
2149       eNegSglTrack->GetImpactParameters(bNegSgl,bNegCov);
2150       nClsITSNeg=eNegSglTrack->GetNcls(0);
2151       nClsTPCNeg=eNegSglTrack->GetNcls(1);
2152       statusSingNeg=1;
2153     }else{
2154       negPt  = 1000000;
2155       negEta = -2.;
2156       negPhi = -2*TMath::Pi();
2157       bNegSgl[0]=-100.;
2158       bNegSgl[1]=-100.;
2159       bNegCov[0]=-100;
2160       bNegCov[2]=-100;
2161       nClsITSNeg=-1;
2162       nClsTPCNeg=-1;
2163       statusSingNeg=-1;
2164     }
2165
2166     posV0Pt  = 1000000;
2167     posV0Eta = -2.;
2168     posV0Phi = -2*TMath::Pi();
2169     negV0Pt  = 1000000;
2170     negV0Eta = -2.;
2171     negV0Phi = -2*TMath::Pi();
2172     
2173     if(fDecayLV0RecIndexPos[i]!=-1){
2174       AliESDv0 * fV0MIs = fESD->GetV0(fDecayLV0RecIndexPos[i]);
2175       AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
2176       AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
2177
2178       if (fpPosDecayLV0RecIndex[i]!=-1 ){
2179         //      AliESDtrack * ePosV0Track = fESD->GetTrack(pPosDecayLV0RecIndex[i]);
2180         if ( trackPosTest->GetSign()==1 ) {
2181           fV0MIs->GetPPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2182         }else{
2183           fV0MIs->GetNPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2184         }
2185         posV0Track.SetXYZM(ppV0[0],ppV0[1],ppV0[2],massP);
2186
2187         posV0Pt  = posV0Track.Pt();
2188         posV0Eta = posV0Track.Eta();
2189         posV0Phi = posV0Track.Phi();
2190         statusV0Pos=1;
2191       }else{
2192         posV0Pt  = 1000000;
2193         posV0Eta = -2.;
2194         posV0Phi = -2*TMath::Pi();
2195         statusV0Pos=-1;
2196       }
2197       
2198       if (fpiNegDecayLV0RecIndex[i]!=-1 ){
2199         //      AliESDtrack * eNegV0Track = fESD->GetTrack(piNegDecayLV0RecIndex[i]);
2200         if ( trackNegTest->GetSign()==-1 ) {
2201           fV0MIs->GetNPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2202         }else{
2203           fV0MIs->GetPPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2204         }
2205         negV0Track.SetXYZM(pmV0[0],pmV0[1],pmV0[2],massPi);
2206         
2207         negV0Pt  = negV0Track.Pt();
2208         negV0Eta = negV0Track.Eta();
2209         negV0Phi = negV0Track.Phi();
2210         statusV0Neg=1;
2211       }else{
2212         negV0Pt  = 1000000;
2213         negV0Eta = -2.;
2214         negV0Phi = -2*TMath::Pi();
2215         statusV0Neg=-1;
2216       }
2217     }
2218     
2219     xrG[0] = ePosPart->Vx();
2220     xrG[1] = ePosPart->Vy();
2221     xrG[2] = ePosPart->Vz();
2222     
2223     //--------- Geant variables ----------------------
2224     fValueL[0] = 1./TMath::Sqrt(lPart->Pt());
2225     fValueL[1] = lPart->Eta();
2226
2227     Double_t tmpGPhi=lPart->Phi();
2228     if( lPart->Phi()>TMath::Pi()){
2229       tmpGPhi=lPart->Phi()-2*TMath::Pi();
2230     }
2231     fValueL[2] = tmpGPhi;
2232
2233     fValueL[3] = TMath::Sqrt(xrG[0]*xrG[0]+xrG[1]*xrG[1]);
2234     fValueL[4] = xrG[2];
2235  
2236
2237     fValueL[5] = 1./TMath::Sqrt(ePosPart->Pt());
2238     fValueL[6] = ePosPart->Eta();
2239
2240     Double_t tmpPPhi=ePosPart->Phi();
2241     if( ePosPart->Phi()>TMath::Pi()){
2242       tmpPPhi = ePosPart->Phi()-2*TMath::Pi();
2243     }
2244      fValueL[7] = tmpPPhi;
2245      fValueL[8] = fpPosDecayLGeantLength[i];
2246
2247     fValueL[9] = 1./TMath::Sqrt(eNegPart->Pt());
2248     fValueL[10] = eNegPart->Eta();
2249
2250     Double_t tmpNPhi=eNegPart->Phi();
2251     if( eNegPart->Phi()>TMath::Pi()){
2252       tmpNPhi = eNegPart->Phi()-2*TMath::Pi();
2253     }
2254     fValueL[11] = tmpNPhi;
2255     fValueL[12] = fpiNegDecayLGeantLength[i];    
2256     //---- Single track variables----------------------
2257
2258     fValueL[13] = (posPt-ePosPart->Pt())/ePosPart->Pt();
2259     fValueL[14] = posEta;
2260     fValueL[15] = posPhi;
2261     fValueL[16] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1]);
2262     fValueL[17] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] )/TMath::Sqrt(bPosCov[0]*bPosCov[0]+bPosCov[2]*bPosCov[2]);   
2263     fValueL[18] = nClsITSPos;
2264     fValueL[19] = nClsTPCPos;
2265     fValueL[20] = statusSingPos;
2266
2267     fValueL[21] = (negPt-eNegPart->Pt())/eNegPart->Pt() ;
2268     fValueL[22] = negEta;
2269     fValueL[23] = negPhi;
2270     fValueL[24] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] );
2271     fValueL[25] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] )/TMath::Sqrt(bNegCov[0]*bNegCov[0]+bNegCov[2]*bNegCov[2]);
2272     fValueL[26] = nClsITSNeg;
2273     fValueL[27] = nClsTPCNeg;
2274     fValueL[28] = statusSingNeg;
2275
2276
2277     
2278     //---- V0 track variables----------------------
2279
2280     fValueL[29] = (posV0Pt-ePosPart->Pt())/ePosPart->Pt();
2281     fValueL[30] = posV0Eta;
2282     fValueL[31] = posV0Phi;
2283     fValueL[32] = statusV0Pos;
2284
2285
2286     fValueL[33] = (negV0Pt-eNegPart->Pt())/eNegPart->Pt();
2287     fValueL[34] = negV0Eta;
2288     fValueL[35] = negV0Phi;
2289     fValueL[36] = statusV0Neg;
2290
2291     fSparseL->Fill(fValueL);
2292   }
2293
2294
2295 }
2296
2297 void AliAnalysisTaskV0QA::FillHnSparseAL()
2298 {
2299   // Fill THnSparse Antilambda
2300
2301   Double_t massPi=0.13957018;
2302   Double_t massP=0.93827203;
2303
2304
2305   Double_t ppSgl[3];
2306   Double_t pmSgl[3];
2307   Float_t bPosSgl[2];
2308   Float_t bNegSgl[2];
2309   Float_t bPosCov[3];
2310   Float_t bNegCov[3];
2311   
2312   Double_t ppV0[3];
2313   Double_t pmV0[3];
2314   Double_t xrG[3];
2315   
2316   TLorentzVector posSglTrack;
2317   TLorentzVector negSglTrack;
2318   Double_t posPt,posEta,posPhi;
2319   Double_t negPt,negEta,negPhi;
2320
2321   TLorentzVector posV0Track;
2322   TLorentzVector negV0Track;
2323   Double_t posV0Pt,posV0Eta,posV0Phi;
2324   Double_t negV0Pt,negV0Eta,negV0Phi;
2325   
2326   Float_t nClsITSPos=-1;
2327   Float_t nClsITSNeg=-1;
2328
2329   Float_t nClsTPCPos=-1;
2330   Float_t nClsTPCNeg=-1;
2331
2332   Int_t statusSingPos=-1;
2333   Int_t statusSingNeg=-1;
2334
2335   Int_t statusV0Pos=-1;
2336   Int_t statusV0Neg=-1;
2337
2338
2339   for(Int_t i=0;i<fnDecayALGeant+1;i++){
2340     TParticle* alPart = fStack->Particle(falDecayALGeantIndex[i]);
2341     TParticle* eNegPart = fStack->Particle(fapNegDecayALGeantIndex[i]);
2342     TParticle* ePosPart = fStack->Particle(fpiPosDecayALGeantIndex[i]);
2343     if (fpiPosDecayALSingleRecIndex[i]!=-1){
2344       AliESDtrack * ePosSglTrack = fESD->GetTrack(fpiPosDecayALSingleRecIndex[i]);
2345       ePosSglTrack->GetPxPyPz(ppSgl); 
2346       posSglTrack.SetXYZM(ppSgl[0],ppSgl[1],ppSgl[2],massPi);
2347       posPt  = posSglTrack.Pt();
2348       posEta = posSglTrack.Eta();
2349       posPhi = posSglTrack.Phi();
2350       ePosSglTrack->GetImpactParameters(bPosSgl,bPosCov);
2351       nClsITSPos=ePosSglTrack->GetNcls(0);
2352       nClsTPCPos=ePosSglTrack->GetNcls(1);
2353       statusSingPos=1;
2354     }else{
2355       posPt  = 1000000;
2356       posEta = -2.;
2357       posPhi = -2*TMath::Pi();
2358       bPosSgl[0]=-100.;
2359       bPosSgl[1]=-100.;
2360       bPosCov[0]=-100;
2361       bPosCov[2]=-100;
2362       nClsITSPos=-1;
2363       nClsTPCPos=-1;
2364       statusSingPos=-1;
2365     }
2366     
2367     if (fapNegDecayALSingleRecIndex[i]!=-1){
2368       AliESDtrack * eNegSglTrack = fESD->GetTrack(fapNegDecayALSingleRecIndex[i]);
2369       eNegSglTrack->GetPxPyPz(pmSgl); 
2370       negSglTrack.SetXYZM(pmSgl[0],pmSgl[1],pmSgl[2],massP);
2371       negPt  = negSglTrack.Pt();
2372       negEta = negSglTrack.Eta();
2373       negPhi = negSglTrack.Phi();
2374       eNegSglTrack->GetImpactParameters(bNegSgl,bNegCov);
2375       nClsITSNeg=eNegSglTrack->GetNcls(0);
2376       nClsTPCNeg=eNegSglTrack->GetNcls(1);
2377       statusSingNeg=1;
2378     }else{
2379       negPt  = 1000000;
2380       negEta = -2.;
2381       negPhi = -2*TMath::Pi();
2382       bNegSgl[0]=-100.;
2383       bNegSgl[1]=-100.;
2384       bNegCov[0]=-100;
2385       bNegCov[2]=-100;
2386       nClsITSNeg=-1;
2387       nClsTPCNeg=-1;
2388       statusSingNeg=-1;
2389     }
2390
2391     posV0Pt  = 1000000;
2392     posV0Eta = -2.;
2393     posV0Phi = -2*TMath::Pi();
2394     negV0Pt  = 1000000;
2395     negV0Eta = -2.;
2396     negV0Phi = -2*TMath::Pi();
2397     
2398     if(fDecayALV0RecIndexPos[i]!=-1){
2399       AliESDv0 * fV0MIs = fESD->GetV0(fDecayALV0RecIndexPos[i]);
2400       AliESDtrack* trackPosTest = fESD->GetTrack(fV0MIs->GetPindex());
2401       AliESDtrack* trackNegTest = fESD->GetTrack(fV0MIs->GetNindex());
2402
2403       if (fpiPosDecayALV0RecIndex[i]!=-1 ){
2404         //      AliESDtrack * ePosV0Track = fESD->GetTrack(piPosDecayALV0RecIndex[i]);
2405         if ( trackPosTest->GetSign()==1 ) {
2406           fV0MIs->GetPPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2407         }else{
2408           fV0MIs->GetNPxPyPz(ppV0[0],ppV0[1],ppV0[2]);
2409         }
2410         posV0Track.SetXYZM(ppV0[0],ppV0[1],ppV0[2],massPi);
2411
2412         posV0Pt  = posV0Track.Pt();
2413         posV0Eta = posV0Track.Eta();
2414         posV0Phi = posV0Track.Phi();
2415         statusV0Pos=1;
2416       }else{
2417         posV0Pt  = 1000000;
2418         posV0Eta = -2.;
2419         posV0Phi = -2*TMath::Pi();
2420         statusV0Pos=-1;
2421       }
2422       
2423       if (fapNegDecayALV0RecIndex[i]!=-1 ){
2424         //      AliESDtrack * eNegV0Track = fESD->GetTrack(apNegDecayALV0RecIndex[i]);
2425         if ( trackNegTest->GetSign()==-1 ) {
2426           fV0MIs->GetNPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2427         }else{
2428           fV0MIs->GetPPxPyPz(pmV0[0],pmV0[1],pmV0[2]);
2429         }
2430         negV0Track.SetXYZM(pmV0[0],pmV0[1],pmV0[2],massP);
2431         
2432         negV0Pt  = negV0Track.Pt();
2433         negV0Eta = negV0Track.Eta();
2434         negV0Phi = negV0Track.Phi();
2435         statusV0Neg=1;
2436       }else{
2437         negV0Pt  = 1000000;
2438         negV0Eta = -2.;
2439         negV0Phi = -2*TMath::Pi();
2440         statusV0Neg=-1;
2441       }
2442     }
2443     
2444     xrG[0] = ePosPart->Vx();
2445     xrG[1] = ePosPart->Vy();
2446     xrG[2] = ePosPart->Vz();
2447     
2448     //--------- Geant variables ----------------------
2449     fValueAL[0] = 1./TMath::Sqrt(alPart->Pt());
2450     fValueAL[1] = alPart->Eta();
2451
2452     Double_t tmpGPhi=alPart->Phi();
2453     if( alPart->Phi()>TMath::Pi()){
2454       tmpGPhi=alPart->Phi()-2*TMath::Pi();
2455     }
2456     fValueAL[2] = tmpGPhi;
2457
2458     fValueAL[3] = TMath::Sqrt(xrG[0]*xrG[0]+xrG[1]*xrG[1]);
2459     fValueAL[4] = xrG[2];
2460  
2461
2462     fValueAL[5] = 1./TMath::Sqrt(ePosPart->Pt());
2463     fValueAL[6] = ePosPart->Eta();
2464
2465     Double_t tmpPPhi=ePosPart->Phi();
2466     if( ePosPart->Phi()>TMath::Pi()){
2467       tmpPPhi = ePosPart->Phi()-2*TMath::Pi();
2468     }
2469      fValueAL[7] = tmpPPhi;
2470      fValueAL[8] = fpiPosDecayALGeantLength[i];
2471
2472     fValueAL[9] = 1./TMath::Sqrt(eNegPart->Pt());
2473     fValueAL[10] = eNegPart->Eta();
2474
2475     Double_t tmpNPhi=eNegPart->Phi();
2476     if( eNegPart->Phi()>TMath::Pi()){
2477       tmpNPhi = eNegPart->Phi()-2*TMath::Pi();
2478     }
2479     fValueAL[11] = tmpNPhi;
2480     fValueAL[12] = fapNegDecayALGeantLength[i];    
2481     //---- Single track variables----------------------
2482
2483     fValueAL[13] = (posPt-ePosPart->Pt())/ePosPart->Pt();
2484     fValueAL[14] = posEta;
2485     fValueAL[15] = posPhi;
2486     fValueAL[16] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1]);
2487     fValueAL[17] = TMath::Sqrt( bPosSgl[0]* bPosSgl[0] +  bPosSgl[1]* bPosSgl[1] )/TMath::Sqrt(bPosCov[0]*bPosCov[0]+bPosCov[2]*bPosCov[2]);   
2488     fValueAL[18] = nClsITSPos;
2489     fValueAL[19] = nClsTPCPos;
2490     fValueAL[20] = statusSingPos;
2491
2492     fValueAL[21] = (negPt-eNegPart->Pt())/eNegPart->Pt() ;
2493     fValueAL[22] = negEta;
2494     fValueAL[23] = negPhi;
2495     fValueAL[24] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] );
2496     fValueAL[25] = TMath::Sqrt( bNegSgl[0]* bNegSgl[0] +  bNegSgl[1]* bNegSgl[1] )/TMath::Sqrt(bNegCov[0]*bNegCov[0]+bNegCov[2]*bNegCov[2]);
2497     fValueAL[26] = nClsITSNeg;
2498     fValueAL[27] = nClsTPCNeg;
2499     fValueAL[28] = statusSingNeg;
2500
2501
2502     
2503     //---- V0 track variables----------------------
2504
2505     fValueAL[29] = (posV0Pt-ePosPart->Pt())/ePosPart->Pt();
2506     fValueAL[30] = posV0Eta;
2507     fValueAL[31] = posV0Phi;
2508     fValueAL[32] = statusV0Pos;
2509
2510
2511     fValueAL[33] = (negV0Pt-eNegPart->Pt())/eNegPart->Pt();
2512     fValueAL[34] = negV0Eta;
2513     fValueAL[35] = negV0Phi;
2514     fValueAL[36] = statusV0Neg;
2515
2516     fSparseAL->Fill(fValueAL);
2517   }
2518 }
2519
2520
2521 // void AliAnalysisTaskV0QA::SetESDtrackCuts()
2522 // {
2523
2524 //   fEsdTrackCuts = new AliESDtrackCuts("AliESDtrackCuts");
2525
2526 //   fEsdTrackCuts->SetRequireTPCRefit(kTRUE);
2527 //   fEsdTrackCuts->SetAcceptKinkDaughters(kFALSE);
2528
2529
2530
2531 // }