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