]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnEvent.cxx
Add new version of macros for RSN analysis
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnEvent.cxx
CommitLineData
7356f978 1/**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3 * *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
6 * *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
15
16////////////////////////////////////////////////////////////////////////////////
17//
18// This class works as generic interface to an event.
19// Its main purpose is to provide a unique reference which includes all the
20// facilities available in the AliVEvent generic base class, plus all info
21// which could be needed during analysis, which are not in AliVEvent but
22// need to be accessed from ESD or AOD objects, usually in different ways.
23// When MC is available, it is properly taken into account.
24//
25// authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
26// M. Vala (martin.vala@cern.ch)
27//
28////////////////////////////////////////////////////////////////////////////////
29
30#include <Riostream.h>
4fbb2459 31#include <TArrayF.h>
0dffcc8a 32
7c2974c8 33#include "AliLog.h"
5eb970a4 34#include "AliVEvent.h"
5eb970a4 35#include "AliMCEvent.h"
36#include "AliStack.h"
4fbb2459 37#include "AliGenEventHeader.h"
a378358c 38#include "AliESDtrackCuts.h"
d7712d44 39#include "AliESDUtils.h"
40#include "AliMultiplicity.h"
41#include "AliRsnCutPID.h"
0dffcc8a 42#include "AliRsnEvent.h"
43
aec0ec32 44ClassImp(AliRsnEvent)
0dffcc8a 45
7c2974c8 46//_____________________________________________________________________________
a378358c 47AliRsnEvent::AliRsnEvent(AliVEvent *ref, AliVEvent *refMC) :
2a1c7696 48 fRef(ref),
49 fRefMC(refMC),
50 fLeading(-1),
51 fLocalID(-1)
2f769150 52{
06351446 53//
4fbb2459 54// Default constructor.
06351446 55//
0dffcc8a 56}
7c2974c8 57
58//_____________________________________________________________________________
aec0ec32 59AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
2a1c7696 60 TObject(event),
61 fRef(event.fRef),
62 fRefMC(event.fRefMC),
63 fLeading(event.fLeading),
64 fLocalID(event.fLocalID)
2f769150 65{
06351446 66//
0dffcc8a 67// Copy constructor.
06351446 68//
2f769150 69}
7c2974c8 70
71//_____________________________________________________________________________
9477aa42 72AliRsnEvent& AliRsnEvent::operator= (const AliRsnEvent & event)
0dffcc8a 73{
06351446 74//
75// Works in the same way as the copy constructor.
76//
aec0ec32 77
2a1c7696 78 (TObject)(*this) = (TObject)event;
79 fRef = event.fRef;
80 fRefMC = event.fRefMC;
81 fLeading = event.fLeading;
82 fLocalID = event.fLocalID;
5eb970a4 83
2a1c7696 84 return (*this);
0dffcc8a 85}
7c2974c8 86
5faf5a07 87//_____________________________________________________________________________
88AliRsnEvent::~AliRsnEvent()
89{
90//
91// Destructor.
92// Dereferences global pointer, if needed.
93//
94
2a1c7696 95 //if (gRsnCurrentEvent == this) gRsnCurrentEvent = 0;
96 //if (gRsnMixedEvent == this) gRsnMixedEvent = 0;
5faf5a07 97}
98
06351446 99//_____________________________________________________________________________
2dab9030 100Bool_t AliRsnEvent::SetDaughter(AliRsnDaughter &out, Int_t i, AliRsnDaughter::ERefType type)
06351446 101{
102//
2dab9030 103// Using the second and third arguments, retrieves the i-th object in the
a378358c 104// appropriate sample (tracks or V0s) and sets the first reference object
2dab9030 105// in order to point to that.
106// If a MonteCarlo information is provided, sets the useful informations from there,
107// and in case of a V0, sets the 'label' data member only when the two daughters
108// of the V0 point to the same mother.
109// Returns kFALSE whenever the operation fails (out of range, NULL references).
06351446 110//
2a1c7696 111
7356f978 112 Bool_t ok = kFALSE;
d7712d44 113
114 out.Reset();
115 out.SetOwnerEvent(this);
2a1c7696 116
7356f978 117 if (IsESD() && type == AliRsnDaughter::kTrack) ok = SetDaughterESDtrack (out, i);
118 if (IsAOD() && type == AliRsnDaughter::kTrack) ok = SetDaughterAODtrack (out, i);
119 if (IsESD() && type == AliRsnDaughter::kV0) ok = SetDaughterESDv0 (out, i);
120 if (IsAOD() && type == AliRsnDaughter::kV0) ok = SetDaughterAODv0 (out, i);
121 if (IsESD() && type == AliRsnDaughter::kCascade) ok = SetDaughterESDcascade(out, i);
122 if (IsAOD() && type == AliRsnDaughter::kCascade) ok = SetDaughterAODcascade(out, i);
d7712d44 123
7356f978 124 return ok;
125}
126
127//_____________________________________________________________________________
128Bool_t AliRsnEvent::SetDaughterAbs(AliRsnDaughter &out, Int_t absIndex)
129{
130//
131// Sets the first argument daughter using the absolute index, which
132// runs continuously from tracks, to V0s, to cascades.
133// In case the conversion to real index fails, the track is flagged as bad.
134// Additionally, sets the daughter internal 'fRsnID' member to this index.
135//
136
137 Int_t index;
138 AliRsnDaughter::ERefType type;
d7712d44 139
140 out.SetRsnID(absIndex);
7356f978 141
d7712d44 142 if (ConvertAbsoluteIndex(absIndex, index, type))
143 return SetDaughter(out, index, type);
144 else {
7356f978 145 out.Reset();
7356f978 146 return kFALSE;
147 }
e0baff8c 148}
149
2e521c29 150//_____________________________________________________________________________
a378358c 151Bool_t AliRsnEvent::SetDaughterMC(AliRsnDaughter &out, Int_t label)
2e521c29 152{
153//
154// Using the second argument, retrieves the i-th object in the
a378358c 155// MC sample (if present) and assigns the track using only that,
156// so that it is considered both as main reference and MC reference.
157// (used for MC-only analysis).
2e521c29 158//
159
2a1c7696 160 if (!fRefMC) {
a378358c 161 out.SetBad();
162 return kFALSE;
2a1c7696 163 }
164
165 // try to convert into both types
166 Int_t imum;
167 AliMCEvent *esd = GetRefMCESD();
168 AliAODEvent *aod = GetRefMCAOD();
169
170 // ESD
171 if (esd) {
172 // if the MC track exists, assign it
173 AliMCParticle *track = (AliMCParticle*)fRef->GetTrack(label);
174 if (!track) {
175 out.SetBad();
176 return kFALSE;
177 }
178 out.SetRef(track);
179 out.SetRefMC(track);
180 out.SetLabel(label);
181 out.SetGood();
182
183 // search for its mother in stack
184 imum = track->GetMother();
185 if (imum >= 0 && imum < esd->Stack()->GetNtrack()) {
186 TParticle *mum = esd->Stack()->Particle(imum);
187 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));
188 }
189 }
190
191 // AOD
192 if (aod) {
193 // checks that array of MC particles exists
194 TClonesArray *mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
195 if (!mcArray) {
196 out.SetBad();
197 return kFALSE;
198 }
199
200 // in this case one has to loop over the sample to find the good one
201 TObjArrayIter next(mcArray);
202 AliAODMCParticle *part = 0x0;
203 while ((part = (AliAODMCParticle*)next())) {
204 if (TMath::Abs(part->GetLabel()) == label) {
205 // if the MC track exists, assign it
206 out.SetRef(part);
207 out.SetRefMC(part);
208 out.SetLabel(label);
209 out.SetGood();
210
211 // search for the mother
212 imum = part->GetMother();
213 if (imum >= 0 && imum < mcArray->GetEntriesFast()) {
214 AliAODMCParticle *mum = (AliAODMCParticle*)mcArray->At(imum);
215 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));
216 }
217 break;
218 }
a378358c 219 }
2a1c7696 220 return kTRUE;
221 }
d7712d44 222
223 out.SetOwnerEvent(this);
2a1c7696 224
225 return kFALSE;
2e521c29 226}
227
15d5fd02 228//_____________________________________________________________________________
2dab9030 229AliRsnDaughter AliRsnEvent::GetDaughter(Int_t i, AliRsnDaughter::ERefType type)
15d5fd02 230{
231//
a378358c 232// Returns a daughter set using same criteria as SetDaughter
15d5fd02 233//
2a1c7696 234
235 AliRsnDaughter d;
236 SetDaughter(d, i, type);
237 return d;
15d5fd02 238}
239
7356f978 240//_____________________________________________________________________________
241AliRsnDaughter AliRsnEvent::GetDaughterAbs(Int_t absIndex)
242{
243//
244// Returns a daughter set using same criteria as SetDaughter
245//
246
247 AliRsnDaughter d;
248 SetDaughterAbs(d, absIndex);
249 return d;
250}
251
2e521c29 252//_____________________________________________________________________________
253AliRsnDaughter AliRsnEvent::GetDaughterMC(Int_t i)
254{
255//
a378358c 256// Returns a daughter set using same criteria as SetDaughterMC
2e521c29 257//
2a1c7696 258
259 AliRsnDaughter d;
260 SetDaughterMC(d, i);
261 return d;
2e521c29 262}
263
32992791 264//_____________________________________________________________________________
265Int_t AliRsnEvent::GetAbsoluteSum()
266{
267//
268// Utility method that returns the sum of all daughter-like objects:
269// tracks, V0s and cascades
270//
271
2a1c7696 272 Int_t total = 0;
273
274 total += fRef->GetNumberOfTracks();
275 total += fRef->GetNumberOfV0s();
276 total += fRef->GetNumberOfCascades();
277
278 return total;
32992791 279}
280
281//_____________________________________________________________________________
282Bool_t AliRsnEvent::ConvertAbsoluteIndex(Int_t index, Int_t &realIndex, AliRsnDaughter::ERefType &type)
283{
284//
285// Using the phylosophy of the absolute index, which loops over
286// all tracks, V0s and cascades, returns the result of a check
287// on it (first argument) based on this criterion:
288// 1) if the absolute ID is smaller than number of tracks,
289// return itself and the type 'track'
290// 2) if the absolute ID is larger than number of tracks, subtract it
291// and if the result is smaller than number of V0s,
292// return the corresponding V0 index and type
293// 3) if the absolute ID is larger than number of tracks + V0s, subtract them
294// and if the result is smaller than number of cascades,
295// return the corresponding cascade index and type
296// The results of this check are stored in the reference arguments, while the outcome of
297// the function is kTRUE if one of these checks was successful, otherwise it is kFALSE,
298// meaning that the absolute index reached the end.
299//
300
2a1c7696 301 Int_t nTracks = fRef->GetNumberOfTracks();
302 Int_t nV0s = fRef->GetNumberOfV0s();
303 Int_t nCascades = fRef->GetNumberOfCascades();
304
305 if (index < nTracks) {
306 realIndex = index;
307 type = AliRsnDaughter::kTrack;
308 return kTRUE;
309 } else if (index >= nTracks && index < nTracks + nV0s) {
310 realIndex = index - nTracks;
311 type = AliRsnDaughter::kV0;
312 return kTRUE;
313 } else if (index >= nTracks + nV0s && index < nTracks + nV0s + nCascades) {
314 realIndex = index - nTracks - nV0s;
315 type = AliRsnDaughter::kCascade;
316 return kTRUE;
317 }
318
319 realIndex = -1;
320 type = AliRsnDaughter::kNoType;
321 return kFALSE;
32992791 322}
323
7356f978 324//_____________________________________________________________________________
325Int_t AliRsnEvent::ConvertRealIndex(Int_t index, AliRsnDaughter::ERefType type)
326{
327//
328// Translates a pair made by index + object type into the corresponding
329// absolute index, which is set to -1 in case the real index overflows.
330//
331
332 Int_t nTracks = fRef->GetNumberOfTracks();
333 Int_t nV0s = fRef->GetNumberOfV0s();
334 Int_t nCascades = fRef->GetNumberOfCascades();
335
336 switch (type) {
337 case AliRsnDaughter::kTrack:
338 if (index >= 0 && index < nTracks)
339 return index;
340 else
341 return -1;
342 case AliRsnDaughter::kV0:
343 if (index >= 0 && index < nV0s)
344 return nTracks + index;
345 else
346 return -1;
347 case AliRsnDaughter::kCascade:
348 if (index >= 0 && index < nCascades)
349 return nTracks + nV0s + index;
350 else
351 return -1;
352 default:
353 return -1;
354 }
355}
356
7c2974c8 357//_____________________________________________________________________________
d7712d44 358Int_t AliRsnEvent::GetMultiplicityFromESDCuts()
7c2974c8 359{
06351446 360//
d7712d44 361// Returns event multiplicity as the number of
362// tracks passing the standard quality cuts.
06351446 363//
a378358c 364
d7712d44 365 if (!fRef) return -1;
2a1c7696 366
367 AliESDEvent *esd = GetRefESD();
d7712d44 368 if (esd)
369 return AliESDtrackCuts::GetReferenceMultiplicity(esd, kTRUE);
370 else {
371 AliWarning("Invoked multicplicity estimation from AliESDtrackCuts with null ESD");
372 return -1;
373 }
7c2974c8 374}
375
7356f978 376//_____________________________________________________________________________
3fe8af3d 377Float_t AliRsnEvent::GetMultiplicityFromSPD()
7356f978 378{
379//
d7712d44 380// Returns event multiplicity computed from SPD.
7356f978 381//
382
3fe8af3d 383 if (!fRef) return -1.0;
7356f978 384
d7712d44 385 AliESDEvent *esd = GetRefESD();
386 if (esd) {
387 const AliMultiplicity *mult = esd->GetMultiplicity();
388 Float_t nClusters[6] = {0.0,0.0,0.0,0.0,0.0,0.0};
389 for(Int_t ilay = 0; ilay < 6; ilay++) nClusters[ilay] = (Float_t)mult->GetNumberOfITSClusters(ilay);
390 return AliESDUtils::GetCorrSPD2(nClusters[1], GetVz());
391 }
392 else {
393 AliWarning("Cannot compute SPD multiplicity without a well initialized ESD event");
3fe8af3d 394 return -1.0;
d7712d44 395 }
78b94cbd 396}
397
398//_____________________________________________________________________________
2dab9030 399Int_t AliRsnEvent::SelectLeadingParticle
400(Double_t ptMin, AliRsnCutPID *cutPID)
78b94cbd 401{
402//
403// Searches the collection of all particles with given PID type and charge,
404// and returns the one with largest momentum, provided that it is greater than 1st argument.
405// If one specifies AliRsnPID::kUnknown as type or AliRsnDaughter::kNoPID as method,
406// the check is done over all particles irrespectively of their PID.
407// If the sign argument is '+' or '-', the check is done over the particles of that charge,
408// otherwise it is done irrespectively of the charge.
409//
410
2a1c7696 411 Int_t i, nTracks = fRef->GetNumberOfTracks();
412 fLeading = -1;
413 AliRsnDaughter leading;
414 leading.SetBad();
415
416 for (i = 0; i < nTracks; i++) {
417 AliRsnDaughter track = GetDaughter(i);
418 if (cutPID) if (!cutPID->IsSelected(&track)) continue;
419 const AliVParticle *ref = track.GetRef();
420 if (ref->Pt() < ptMin) continue;
421 //double pt = track.P().Perp();
422 //Printf("track %d %g", i, pt);
423 if (!leading.IsOK() || ref->Pt() > ptMin) {
424 fLeading = i;
425 //leading = track;
426 ptMin = ref->Pt();
427 }
428 }
429 return fLeading;
78b94cbd 430}
431
5eb970a4 432//_________________________________________________________________________________________________
2dab9030 433Double_t AliRsnEvent::GetAverageMomentum(Int_t &count, AliRsnCutPID *cutPID)
78b94cbd 434{
435//
436// Loops on the list of tracks and computes average total momentum.
437//
438
2a1c7696 439 Int_t i, nTracks = fRef->GetNumberOfTracks();
440 Double_t pmean = 0.0;
5eb970a4 441
2a1c7696 442 for (i = 0, count = 0; i < nTracks; i++) {
443 AliRsnDaughter track = GetDaughter(i);
444 if (cutPID) if (!cutPID->IsSelected(&track)) continue;
5f1c287d 445 pmean += track.Prec().Mag();
2a1c7696 446 count++;
447 }
15d5fd02 448
2a1c7696 449 if (count > 0) pmean /= (Double_t)count;
450 else pmean = 0.0;
5eb970a4 451
2a1c7696 452 return pmean;
78b94cbd 453}
454
455//_____________________________________________________________________________
5eb970a4 456Bool_t AliRsnEvent::GetAngleDistr
245cd328 457(Double_t &angleMean, Double_t &angleRMS, AliRsnDaughter *leading)
78b94cbd 458{
459//
460// Takes the leading particle and computes the mean and RMS
461// of the distribution of directions of all other tracks
462// with respect to the direction of leading particle.
463//
464
245cd328 465 if (!leading) return kFALSE;
466 if (!leading->IsOK()) return kFALSE;
15d5fd02 467
2a1c7696 468 Int_t i, count, nTracks = fRef->GetNumberOfTracks();
469 Double_t angle, angle2Mean = 0.0;
15d5fd02 470
2a1c7696 471 angleMean = angle2Mean = 0.0;
15d5fd02 472
2a1c7696 473 for (i = 0, count = 0; i < nTracks; i++) {
474 AliRsnDaughter trk = GetDaughter(i);
245cd328 475 if (trk.GetID() == leading->GetID()) continue;
15d5fd02 476
245cd328 477 angle = leading->Prec().Angle(trk.Prec().Vect());
15d5fd02 478
2a1c7696 479 angleMean += angle;
480 angle2Mean += angle * angle;
481 count++;
482 }
15d5fd02 483
2a1c7696 484 if (!count) return kFALSE;
15d5fd02 485
2a1c7696 486 angleMean /= (Double_t)count;
487 angle2Mean /= (Double_t)count;
488 angleRMS = TMath::Sqrt(angle2Mean - angleMean * angleMean);
15d5fd02 489
2a1c7696 490 return kTRUE;
96e9d35d 491}
a378358c 492
493//_____________________________________________________________________________
32992791 494Bool_t AliRsnEvent::SetDaughterESDtrack(AliRsnDaughter &out, Int_t i)
a378358c 495{
496//
497// Setup the first argument to the track identified by the index.
498// When available, adds the MC information and references.
499// ---
500// Version #1: ESD tracks
501//
2a1c7696 502
503 // check 1: index in good range
504 if (i < 0 || i >= fRef->GetNumberOfTracks()) {
505 out.SetBad();
506 return kFALSE;
507 }
508
509 // check 2: not NULL object
510 AliVTrack *track = (AliVTrack*)fRef->GetTrack(i);
511 if (!track) {
512 out.SetBad();
513 return kFALSE;
514 }
515
516 // assign references of reconstructed track
517 Int_t label = TMath::Abs(track->GetLabel());
518 out.SetRef(track);
519 out.SetLabel(label);
520 out.SetGood();
521
522 // assign MC info, if available
523 return SetMCInfoESD(out);
a378358c 524}
525
526//_____________________________________________________________________________
32992791 527Bool_t AliRsnEvent::SetDaughterAODtrack(AliRsnDaughter &out, Int_t i)
a378358c 528{
529//
530// Setup the first argument to the track identified by the index.
531// When available, adds the MC information and references.
532// ---
533// Version #2: AOD tracks
534//
2a1c7696 535
536 // check 1: index in good range
537 if (i < 0 || i >= fRef->GetNumberOfTracks()) {
538 out.SetBad();
539 return kFALSE;
540 }
541
542 // check 2: not NULL object
543 AliVTrack *track = (AliVTrack*)fRef->GetTrack(i);
544 if (!track) {
545 out.SetBad();
546 return kFALSE;
547 }
548
549 // assign references of reconstructed track
550 Int_t label = TMath::Abs(track->GetLabel());
551 out.SetRef(track);
552 out.SetLabel(label);
553 out.SetGood();
554
555 // assign MC info, if available
556 return SetMCInfoAOD(out);
a378358c 557}
558
559//_____________________________________________________________________________
32992791 560Bool_t AliRsnEvent::SetDaughterESDv0(AliRsnDaughter &out, Int_t i)
a378358c 561{
562//
563// Setup the first argument to the track identified by the index.
564// When available, adds the MC information and references.
565// ---
566// Version #3: ESD v0
567//
568
2a1c7696 569 // check 1: index in good range
570 if (i > fRef->GetNumberOfV0s()) {
571 out.SetBad();
572 return 1;
573 }
574
575 // check 2: not NULL object
576 AliESDEvent *ev = GetRefESD();
577 AliESDv0 *v0 = ev->GetV0(i);
578 if (!v0) {
579 out.SetBad();
580 return 2;
581 }
582
583 // assign references of reconstructed track
584 out.SetRef(v0);
585 out.SetGood();
7356f978 586 out.SetLabel(-1);
2a1c7696 587
588 // this time, assigning label is not trivial,
589 // it is done only if MC is present and both
590 // daughters come from a true particle
591 AliMCEvent *mc = GetRefMCESD();
592 AliESDtrack *tp = ev->GetTrack(v0->GetPindex());
593 AliESDtrack *tn = ev->GetTrack(v0->GetNindex());
594 if (mc && tp && tn) {
595 Int_t lp = TMath::Abs(tp->GetLabel());
596 Int_t ln = TMath::Abs(tn->GetLabel());
597 TParticle *pp = mc->Stack()->Particle(lp);
598 TParticle *pn = mc->Stack()->Particle(ln);
599 // if their first mothers are the same, the V0 is true
600 // otherwise no label can be assigned
7356f978 601 if (pp->GetFirstMother() == pn->GetFirstMother() && pp->GetFirstMother() >= 0) out.SetLabel(pp->GetFirstMother());
2a1c7696 602 }
603
604 // assign MC info, if available
605 return SetMCInfoESD(out);
a378358c 606}
607
608//_____________________________________________________________________________
32992791 609Bool_t AliRsnEvent::SetDaughterAODv0(AliRsnDaughter &out, Int_t i)
a378358c 610{
611//
612// Setup the first argument to the track identified by the index.
613// When available, adds the MC information and references.
614// ---
615// Version #4: AOD v0
616//
617
2a1c7696 618 // check 1: index in good range
619 if (i > fRef->GetNumberOfV0s()) {
620 out.SetBad();
621 return kFALSE;
622 }
623
624 // check 2: not NULL object
625 AliAODEvent *ev = GetRefAOD();
626 AliAODv0 *v0 = ev->GetV0(i);
627 if (!v0) {
628 out.SetBad();
629 return kFALSE;
630 }
631
632 TClonesArray *mcArray = (TClonesArray*)ev->GetList()->FindObject(AliAODMCParticle::StdBranchName());
633 if (!mcArray) {
634 out.SetBad();
635 return kFALSE;
636 }
637
638 // assign references of reconstructed track
639 out.SetRef(v0);
640 out.SetGood();
641 out.SetLabel(-1);
642
643 // this time, assigning label is not trivial,
644 // it is done only if MC is present and both
645 // daughters come from a true particle
646 AliAODTrack *tp = ev->GetTrack(v0->GetPosID());
647 AliAODTrack *tn = ev->GetTrack(v0->GetNegID());
648 if (mcArray && tp && tn) {
245cd328 649 Int_t lp = TMath::Abs(tp->GetLabel());
650 Int_t ln = TMath::Abs(tn->GetLabel());
2a1c7696 651 // loop on array to find MC daughters
652 AliAODMCParticle *pp = 0x0, *pn = 0x0;
653 TObjArrayIter next(mcArray);
654 AliAODMCParticle *part = 0x0;
655 while ((part = (AliAODMCParticle*)next())) {
245cd328 656 if (TMath::Abs(part->GetLabel()) == lp) pp = part;
657 if (TMath::Abs(part->GetLabel()) == ln) pn = part;
2a1c7696 658 }
659 // assign a MC reference and a label only to true V0s
7356f978 660 if (pp->GetMother() == pn->GetMother() && pp->GetMother() >= 0) out.SetLabel(pp->GetMother());
2a1c7696 661 }
662
663 // assign MC info, if available
664 return SetMCInfoAOD(out);
32992791 665}
666
667//_____________________________________________________________________________
5faf5a07 668Bool_t AliRsnEvent::SetDaughterESDcascade(AliRsnDaughter &, Int_t)
32992791 669{
670//
671// Setup the first argument to the track identified by the index.
672// When available, adds the MC information and references.
673// ---
674// Version #3: ESD cascade
675//
676
2a1c7696 677 return kTRUE;
32992791 678}
679
680//_____________________________________________________________________________
5faf5a07 681Bool_t AliRsnEvent::SetDaughterAODcascade(AliRsnDaughter &, Int_t)
32992791 682{
683//
684// Setup the first argument to the track identified by the index.
685// When available, adds the MC information and references.
686// ---
687// Version #4: AOD cascade
688//
689
2a1c7696 690 return kTRUE;
32992791 691}
692
693//_____________________________________________________________________________
694Bool_t AliRsnEvent::SetMCInfoESD(AliRsnDaughter &out)
695{
696//
697// Using the label assigned to the daughter, searches for the MC informations:
698// -- MC reference
699// -- mother
700//
701
2a1c7696 702 Int_t label = out.GetLabel();
2a1c7696 703
704 // if no MC reference is available, exit here (successfully)
705 AliMCEvent *mc = GetRefMCESD();
706 if (!mc) return kTRUE;
707 Int_t nMC = mc->GetNumberOfTracks();
7356f978 708
709 // debug message for fakes
710 if (label < 0) {
711 AliDebug(AliLog::kDebug + 1, "Fake object (fake track or false V0)");
712 return kFALSE;
713 }
2a1c7696 714
715 // assign MC reference, being aware of eventual
716 // overflows in the array (sometimes happened)
7356f978 717 if (label >= nMC) {
2a1c7696 718 AliWarning(Form("Stack overflow: track label = %d -- stack maximum = %d", label, nMC));
719 return kFALSE;
720 }
721 AliMCParticle *mcPart = (AliMCParticle*)mc->GetTrack(label);
722 if (!mcPart) {
723 AliWarning(Form("Stack discontinuity: label %d refers to a NULL object", label));
724 return kFALSE;
725 }
726 out.SetRefMC(mcPart);
727
728 // if this is a primary track, exit here (successfully)
729 Int_t imum = mcPart->Particle()->GetFirstMother();
7356f978 730 if (imum < 0) {
731 out.SetMotherPDG(0);
732 return kTRUE;
733 }
2a1c7696 734
735 // if didn't stop there, search for the mother
736 if (imum >= nMC) {
737 AliWarning(Form("Stack overflow: track mother label = %d -- stack maximum = %d", label, nMC));
738 return kFALSE;
739 }
740 AliMCParticle *mcMother = (AliMCParticle*)mc->GetTrack(imum);
741 if (!mcMother) {
7356f978 742 AliWarning(Form("Stack discontinuity: label mother %d refers to a NULL object", imum));
2a1c7696 743 return kFALSE;
744 }
745 out.SetMotherPDG(TMath::Abs(mcMother->Particle()->GetPdgCode()));
746
747 return kTRUE;
32992791 748}
749
750//_____________________________________________________________________________
751Bool_t AliRsnEvent::SetMCInfoAOD(AliRsnDaughter &out)
752{
753//
754// Using the label assigned to the daughter, searches for the MC informations:
755// -- MC reference
756// -- mother
757//
758
2a1c7696 759 Int_t label = out.GetLabel();
7356f978 760
761 // debug message for fakes
762 if (label < 0) {
763 AliDebug(AliLog::kDebug + 1, "Fake object (fake track or false V0)");
764 return kFALSE;
765 }
2a1c7696 766
767 // if no MC reference is available, exit here (successfully)
768 AliAODEvent *mc = GetRefMCAOD();
769 if (!mc) return kTRUE;
770
771 // loop on particles using the track label as reference
772 // and then assign also the mother type, if found
773 TClonesArray *mcArray = (TClonesArray*)mc->GetList()->FindObject(AliAODMCParticle::StdBranchName());
774 if (!mcArray) return kFALSE;
775 TObjArrayIter next(mcArray);
776 AliAODMCParticle *part = 0x0;
777 while ((part = (AliAODMCParticle*)next())) {
778 if (TMath::Abs(part->GetLabel()) == label) {
779 out.SetRefMC(part);
7356f978 780 out.SetMotherPDG(0);
2a1c7696 781 Int_t imum = part->GetMother();
782 if (imum >= 0 && imum <= mcArray->GetEntriesFast()) {
783 AliAODMCParticle *mum = (AliAODMCParticle*)mcArray->At(imum);
784 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));
7356f978 785 return kTRUE;
2a1c7696 786 } else {
787 AliWarning(Form("Array overflow: track mother label = %d -- stack maximum = %d", imum, mcArray->GetEntriesFast()));
788 return kFALSE;
789 }
790
791 // if a MC reference is found, there is no need to go on with the loop
792 break;
32992791 793 }
2a1c7696 794 }
795
796 return kTRUE;
a378358c 797}