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