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