]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnEvent.cxx
Fix MC info for pairs + added monitoring values to daughter (M.Vala)
[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
4fbb2459 33#include "AliGenEventHeader.h"
f34f960b 34
35#include "AliRsnCutSet.h"
0dffcc8a 36#include "AliRsnEvent.h"
37
aec0ec32 38ClassImp(AliRsnEvent)
0dffcc8a 39
7c2974c8 40//_____________________________________________________________________________
a378358c 41AliRsnEvent::AliRsnEvent(AliVEvent *ref, AliVEvent *refMC) :
2a1c7696 42 fRef(ref),
43 fRefMC(refMC),
44 fLeading(-1),
b63357a0 45 fPID(0x0),
46 fAODList(0x0)
2f769150 47{
06351446 48//
4fbb2459 49// Default constructor.
06351446 50//
0dffcc8a 51}
7c2974c8 52
53//_____________________________________________________________________________
aec0ec32 54AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
2a1c7696 55 TObject(event),
56 fRef(event.fRef),
57 fRefMC(event.fRefMC),
58 fLeading(event.fLeading),
b63357a0 59 fPID(event.fPID),
60 fAODList(event.fAODList)
2f769150 61{
06351446 62//
0dffcc8a 63// Copy constructor.
06351446 64//
2f769150 65}
7c2974c8 66
67//_____________________________________________________________________________
9477aa42 68AliRsnEvent& AliRsnEvent::operator= (const AliRsnEvent & event)
0dffcc8a 69{
06351446 70//
71// Works in the same way as the copy constructor.
72//
aec0ec32 73
f34f960b 74 TObject::operator=(event);
2a1c7696 75 fRef = event.fRef;
76 fRefMC = event.fRefMC;
77 fLeading = event.fLeading;
c865cb1d 78 fPID = event.fPID;
b63357a0 79 fAODList = event.fAODList;
5eb970a4 80
2a1c7696 81 return (*this);
0dffcc8a 82}
7c2974c8 83
5faf5a07 84//_____________________________________________________________________________
85AliRsnEvent::~AliRsnEvent()
86{
87//
f34f960b 88// Destructor (does nothing since there are not owned pointers)
5faf5a07 89//
5faf5a07 90}
91
06351446 92//_____________________________________________________________________________
f34f960b 93void AliRsnEvent::SetDaughter(AliRsnDaughter &out, Int_t index, Bool_t fromMC)
06351446 94{
95//
f34f960b 96// Assigns to the first argument the reference to the i-th track in the ref event.
97// What assignment method to be used will depend on the index and on the type of input.
98// If the last argument is kTRUE and an MC is referenced, then both fRef and fRefMC will
99// point to the MC particle (pure MC analysis)
06351446 100//
2a1c7696 101
f34f960b 102 // by default the daughter is reset
103 // and assigned the used index
d7712d44 104 out.Reset();
f34f960b 105 out.SetRsnID(index);
d7712d44 106 out.SetOwnerEvent(this);
d7712d44 107
f34f960b 108 // check input type
109 if (!InputOK()) return;
110 Bool_t inputESD = IsESD();
111
cceb9957 112
f34f960b 113 Int_t trueIndex;
114 AliRsnDaughter::ERefType type;
115 if (!ConvertAbsoluteIndex(index, trueIndex, type)) {
116 AliError(Form("Failed to convert absolute index %d", index));
117 return;
118 }
119 switch (type) {
120 case AliRsnDaughter::kTrack:
cceb9957 121 if (inputESD) {
122 SetDaughterESDtrack(out, trueIndex);
123
124 } else {
125 SetDaughterAODtrack(out, trueIndex);
126 }
f34f960b 127 break;
128 case AliRsnDaughter::kV0:
129 if (inputESD) SetDaughterESDv0(out, trueIndex); else SetDaughterAODv0(out, trueIndex);
130 break;
131 case AliRsnDaughter::kCascade:
132 if (inputESD) SetDaughterESDcascade(out, trueIndex); else SetDaughterAODcascade(out, trueIndex);
133 break;
134 default:
135 AliError("Unrecognized daughter type");
136 return;
137 }
cceb9957 138
139 // if it is pure MC, the index tells what particle
140 // to be read in the stack of MC particles, otherwise
141 // it is converted into a real collection index
142 if (fromMC) out.SetRef(out.GetRefMC());
7356f978 143}
144
145//_____________________________________________________________________________
f34f960b 146AliRsnDaughter AliRsnEvent::GetDaughter(Int_t i, Bool_t fromMC)
7356f978 147{
148//
f34f960b 149// Returns a daughter set using same criteria as SetDaughter
7356f978 150//
151
f34f960b 152 AliRsnDaughter d;
153 SetDaughter(d, i, fromMC);
154 return d;
155}
7356f978 156
f34f960b 157//_____________________________________________________________________________
158void AliRsnEvent::SetDaughterESDtrack(AliRsnDaughter &out, Int_t i)
159{
160//
161// Setup the first argument to the track identified by the index.
162// When available, adds the MC information and references.
163// ---
164// Version #1: ESD tracks
165//
166
167 AliESDEvent *esd = (AliESDEvent*)fRef;
168
169 if (i >= 0 && i < esd->GetNumberOfTracks()) {
170 AliESDtrack *track = esd->GetTrack(i);
171 if (track) {
172 out.SetRef(track);
173 out.SetGood();
174 // if MC is present, assign label and retrieve corresponding particle
175 if (fRefMC) {
176 out.SetLabel(TMath::Abs(track->GetLabel()));
177 if (!SetMCInfoESD(out)) {
178 AliWarning("Failed assignment of MC info");
179 }
180 }
181 } else {
182 AliWarning("Null track");
183 }
184 } else {
185 AliWarning(Form("Overflow: required index = %d, max = %d", i, esd->GetNumberOfTracks()));
7356f978 186 }
e0baff8c 187}
188
2e521c29 189//_____________________________________________________________________________
f34f960b 190void AliRsnEvent::SetDaughterAODtrack(AliRsnDaughter &out, Int_t i)
2e521c29 191{
192//
f34f960b 193// Setup the first argument to the track identified by the index.
194// When available, adds the MC information and references.
195// ---
196// Version #2: AOD tracks
2e521c29 197//
198
f34f960b 199 AliAODEvent *aod = (AliAODEvent*)fRef;
2a1c7696 200
f34f960b 201 if (i >= 0 && i < aod->GetNumberOfTracks()) {
202 AliAODTrack *track = aod->GetTrack(i);
203 if (track) {
204 out.SetRef(track);
205 out.SetGood();
206 // if MC is present, assign label and retrieve corresponding particle
207 if (fRefMC) {
208 out.SetLabel(TMath::Abs(track->GetLabel()));
209 if (!SetMCInfoAOD(out)) {
210 AliWarning("Failed assignment of MC info");
211 }
212 }
213 } else {
214 AliWarning("Null track");
2a1c7696 215 }
f34f960b 216 } else {
217 AliWarning(Form("Overflow: required index = %d, max = %d", i, aod->GetNumberOfTracks()));
2a1c7696 218 }
f34f960b 219}
220
221//_____________________________________________________________________________
222void AliRsnEvent::SetDaughterESDv0(AliRsnDaughter &out, Int_t i)
223{
224//
225// Setup the first argument to the track identified by the index.
226// When available, adds the MC information and references.
227// ---
228// Version #3: ESD v0
229//
2a1c7696 230
f34f960b 231 if (i >= 0 && i < fRef->GetNumberOfV0s()) {
232 AliESDEvent *ev = GetRefESD();
233 AliESDv0 *v0 = ev->GetV0(i);
234 if (v0) {
235 out.SetRef(v0);
236 out.SetGood();
237 // if MC is present, retrieve the label of V0 from those of daughters
238 if (fRefMC) {
239 AliMCEvent *mc = (AliMCEvent*)fRefMC;
240 AliESDtrack *tp = ev->GetTrack(v0->GetPindex());
241 AliESDtrack *tn = ev->GetTrack(v0->GetNindex());
242 if (mc && tp && tn) {
243 Int_t lp = TMath::Abs(tp->GetLabel());
244 Int_t ln = TMath::Abs(tn->GetLabel());
245 TParticle *pp = mc->Stack()->Particle(lp);
246 TParticle *pn = mc->Stack()->Particle(ln);
247 if (pp && pn) {
248 // if their first mothers are the same, the V0 is true
249 // otherwise label remains '-1' --> fake V0
250 if (pp->GetFirstMother() == pn->GetFirstMother() && pp->GetFirstMother() >= 0) {
251 out.SetLabel(pp->GetFirstMother());
252 SetMCInfoESD(out);
253 }
254 }
255 }
256 }
2a1c7696 257 }
f34f960b 258 }
259}
260
261//_____________________________________________________________________________
262void AliRsnEvent::SetDaughterAODv0(AliRsnDaughter &out, Int_t i)
263{
264//
265// Setup the first argument to the track identified by the index.
266// When available, adds the MC information and references.
267// ---
268// Version #4: AOD v0
269//
2a1c7696 270
f34f960b 271 if (i >= 0 && i < fRef->GetNumberOfV0s()) {
272 AliAODEvent *ev = (AliAODEvent*)fRef;
273 AliAODv0 *v0 = ev->GetV0(i);
274 if (v0) {
275 out.SetRef(v0);
276 out.SetGood();
277 if (fRefMC) {
278 AliAODEvent *mc = (AliAODEvent*)fRefMC;
279 TClonesArray *mcArray = (TClonesArray*)mc->GetList()->FindObject(AliAODMCParticle::StdBranchName());
280 AliAODTrack *tp = (AliAODTrack*)v0->GetDaughter(0);
281 AliAODTrack *tn = (AliAODTrack*)v0->GetDaughter(1);
282 if (mcArray && tp && tn) {
283 Int_t lp = TMath::Abs(tp->GetLabel());
284 Int_t ln = TMath::Abs(tn->GetLabel());
285 AliAODMCParticle *pp = (AliAODMCParticle*)mcArray->At(lp);
286 AliAODMCParticle *pn = (AliAODMCParticle*)mcArray->At(ln);
287 if (pp && pn) {
288 // if their first mothers are the same, the V0 is true
289 // otherwise label remains '-1' --> fake V0
290 if (pp->GetMother() == pn->GetMother() && pp->GetMother() >= 0) {
291 out.SetLabel(pp->GetMother());
292 SetMCInfoAOD(out);
293 }
294 }
2a1c7696 295 }
2a1c7696 296 }
a378358c 297 }
2a1c7696 298 }
f34f960b 299}
2a1c7696 300
f34f960b 301//_____________________________________________________________________________
302void AliRsnEvent::SetDaughterESDcascade(AliRsnDaughter &out, Int_t i)
303{
304//
305// Setup the first argument to the track identified by the index.
306// When available, adds the MC information and references.
307// ---
308// Version #3: ESD cascade
309//
310
311 if (i >= 0 && i < fRef->GetNumberOfCascades()) {
312 AliESDEvent *ev = GetRefESD();
313 AliESDcascade *casc = ev->GetCascade(i);
314 if (casc) {
315 out.SetRef(casc);
316 out.SetGood();
317 if (fRefMC) {
318
319 }
320 }
321 }
2e521c29 322}
323
15d5fd02 324//_____________________________________________________________________________
f34f960b 325void AliRsnEvent::SetDaughterAODcascade(AliRsnDaughter &out, Int_t i)
15d5fd02 326{
327//
f34f960b 328// Setup the first argument to the track identified by the index.
329// When available, adds the MC information and references.
330// ---
331// Version #4: AOD cascade
15d5fd02 332//
2a1c7696 333
f34f960b 334 if (i >= 0 && i < fRef->GetNumberOfCascades()) {
335 AliAODEvent *ev = GetRefAOD();
336 AliAODv0 *casc = ev->GetCascade(i);
337 if (casc) {
338 out.SetRef(casc);
339 out.SetGood();
340 if (fRefMC) {
341
342 }
343 }
344 }
15d5fd02 345}
346
7356f978 347//_____________________________________________________________________________
f34f960b 348Bool_t AliRsnEvent::SetMCInfoESD(AliRsnDaughter &out)
7356f978 349{
350//
f34f960b 351// Using the label assigned to the daughter, searches for the MC informations:
352// -- MC reference
353// -- mother
7356f978 354//
355
f34f960b 356 // if label makes no sense --> failed
357 Int_t label = out.GetLabel();
358 if (label < 0 || !fRefMC) return kFALSE;
359
360 // get number of particles
361 Int_t nMC = fRefMC->GetNumberOfTracks();
362
363 // if label too large --> failed
364 if (label >= nMC) {
365 AliWarning(Form("Stack overflow: track label = %d -- stack maximum = %d", label, nMC));
366 return kFALSE;
367 }
368
369 // retrieve particle
370 AliMCEvent *mc = (AliMCEvent*)fRefMC;
371 AliMCParticle *mcPart = (AliMCParticle*)mc->GetTrack(label);
372
373 // if particle = NULL --> failed
374 if (!mcPart) {
375 AliWarning(Form("Stack discontinuity: label %d refers to a NULL object", label));
376 return kFALSE;
377 }
378 // otherwise --> success
379 out.SetRefMC(mcPart);
380
381 // if the particle is not primary, find the mother and get its PDG
382 Int_t imum = mcPart->Particle()->GetFirstMother();
383 if (imum >= 0 && imum < nMC) {
384 AliMCParticle *mcMother = (AliMCParticle*)mc->GetTrack(imum);
385 if (mcMother) {
386 out.SetMotherPDG(TMath::Abs(mcMother->Particle()->GetPdgCode()));
387 } else {
388 AliWarning(Form("Stack discontinuity: label mother %d refers to a NULL object", imum));
389 }
390 } else {
391 AliWarning(Form("Stack overflow: mother label = %d -- stack maximum = %d", imum, nMC));
392 }
393
394 return kTRUE;
7356f978 395}
396
2e521c29 397//_____________________________________________________________________________
f34f960b 398Bool_t AliRsnEvent::SetMCInfoAOD(AliRsnDaughter &out)
2e521c29 399{
400//
f34f960b 401// Using the label assigned to the daughter, searches for the MC informations:
402// -- MC reference
403// -- mother
2e521c29 404//
2a1c7696 405
f34f960b 406 // if label makes no sense --> failed
407 Int_t label = out.GetLabel();
408 if (label < 0 || !fRefMC) return kFALSE;
409
410 // retrieve particle
411 AliAODEvent *mc = (AliAODEvent*)fRefMC;
412 TClonesArray *mcArray = (TClonesArray*)mc->GetList()->FindObject(AliAODMCParticle::StdBranchName());
413
414 // get number of particles
415 Int_t nMC = mcArray->GetEntriesFast();
416
417 // if label too large --> failed
418 if (label >= nMC) {
419 AliWarning(Form("Stack overflow: track label = %d -- stack maximum = %d", label, nMC));
420 return kFALSE;
421 }
422
423 // if particle = NULL --> failed
424 AliAODMCParticle *mcPart = (AliAODMCParticle*)mcArray->At(label);
425 if (!mcPart) {
426 AliWarning(Form("Stack discontinuity: label %d refers to a NULL object", label));
427 return kFALSE;
428 }
429 // otherwise --> success
430 out.SetRefMC(mcPart);
431
432 // if the particle is not primary, find the mother and get its PDG
433 Int_t imum = mcPart->GetMother();
434 if (imum >= 0 && imum < nMC) {
435 AliAODMCParticle *mcMother = (AliAODMCParticle*)mcArray->At(imum);
436 if (mcMother) {
437 out.SetMotherPDG(TMath::Abs(mcMother->GetPdgCode()));
438 } else {
439 AliWarning(Form("Stack discontinuity: label mother %d refers to a NULL object", imum));
440 }
441 } else if (imum >= nMC) {
442 AliWarning(Form("Stack overflow: mother label = %d -- stack maximum = %d", imum, nMC));
443 }
444
445 return kTRUE;
2e521c29 446}
447
32992791 448//_____________________________________________________________________________
449Bool_t AliRsnEvent::ConvertAbsoluteIndex(Int_t index, Int_t &realIndex, AliRsnDaughter::ERefType &type)
450{
451//
452// Using the phylosophy of the absolute index, which loops over
453// all tracks, V0s and cascades, returns the result of a check
454// on it (first argument) based on this criterion:
455// 1) if the absolute ID is smaller than number of tracks,
456// return itself and the type 'track'
457// 2) if the absolute ID is larger than number of tracks, subtract it
458// and if the result is smaller than number of V0s,
459// return the corresponding V0 index and type
460// 3) if the absolute ID is larger than number of tracks + V0s, subtract them
461// and if the result is smaller than number of cascades,
462// return the corresponding cascade index and type
463// The results of this check are stored in the reference arguments, while the outcome of
464// the function is kTRUE if one of these checks was successful, otherwise it is kFALSE,
465// meaning that the absolute index reached the end.
466//
467
2a1c7696 468 Int_t nTracks = fRef->GetNumberOfTracks();
469 Int_t nV0s = fRef->GetNumberOfV0s();
470 Int_t nCascades = fRef->GetNumberOfCascades();
471
472 if (index < nTracks) {
473 realIndex = index;
474 type = AliRsnDaughter::kTrack;
475 return kTRUE;
476 } else if (index >= nTracks && index < nTracks + nV0s) {
477 realIndex = index - nTracks;
478 type = AliRsnDaughter::kV0;
479 return kTRUE;
480 } else if (index >= nTracks + nV0s && index < nTracks + nV0s + nCascades) {
481 realIndex = index - nTracks - nV0s;
482 type = AliRsnDaughter::kCascade;
483 return kTRUE;
484 }
485
486 realIndex = -1;
487 type = AliRsnDaughter::kNoType;
488 return kFALSE;
32992791 489}
490
7356f978 491//_____________________________________________________________________________
492Int_t AliRsnEvent::ConvertRealIndex(Int_t index, AliRsnDaughter::ERefType type)
493{
494//
495// Translates a pair made by index + object type into the corresponding
496// absolute index, which is set to -1 in case the real index overflows.
497//
498
499 Int_t nTracks = fRef->GetNumberOfTracks();
500 Int_t nV0s = fRef->GetNumberOfV0s();
501 Int_t nCascades = fRef->GetNumberOfCascades();
502
503 switch (type) {
504 case AliRsnDaughter::kTrack:
505 if (index >= 0 && index < nTracks)
506 return index;
507 else
508 return -1;
509 case AliRsnDaughter::kV0:
510 if (index >= 0 && index < nV0s)
511 return nTracks + index;
512 else
513 return -1;
514 case AliRsnDaughter::kCascade:
515 if (index >= 0 && index < nCascades)
516 return nTracks + nV0s + index;
517 else
518 return -1;
519 default:
520 return -1;
521 }
522}
523
7c2974c8 524//_____________________________________________________________________________
f34f960b 525Int_t AliRsnEvent::SelectLeadingParticle(AliRsnCutSet *cuts)
78b94cbd 526{
527//
528// Searches the collection of all particles with given PID type and charge,
529// and returns the one with largest momentum, provided that it is greater than 1st argument.
530// If one specifies AliRsnPID::kUnknown as type or AliRsnDaughter::kNoPID as method,
531// the check is done over all particles irrespectively of their PID.
532// If the sign argument is '+' or '-', the check is done over the particles of that charge,
533// otherwise it is done irrespectively of the charge.
534//
535
f34f960b 536 // check input type
537 Bool_t inputESD = IsESD();
538 if (!inputESD && !IsAOD()) {
539 AliError("Need to process ESD or AOD input");
540 return -1;
541 }
542
543 Double_t ptMax = 0.0;
2a1c7696 544 Int_t i, nTracks = fRef->GetNumberOfTracks();
f34f960b 545
2a1c7696 546 fLeading = -1;
547 AliRsnDaughter leading;
2a1c7696 548
549 for (i = 0; i < nTracks; i++) {
f34f960b 550 if (inputESD)
551 SetDaughterESDtrack(leading, i);
552 else
553 SetDaughterAODtrack(leading, i);
554 if (!leading.IsOK()) {
555 AliDebugClass(1, Form("Failed assignment of track %d", i));
556 continue;
2a1c7696 557 }
f34f960b 558 if (cuts && !cuts->IsSelected(&leading)) {
559 AliDebugClass(1, Form("Track %d didn't pass cuts", i));
560 continue;
2a1c7696 561 }
f34f960b 562 // check if it has largest momentum
563 if (leading.GetRef()->Pt() > ptMax) {
564 ptMax = leading.GetRef()->Pt();
565 fLeading = i;
32992791 566 }
2a1c7696 567 }
f34f960b 568
569 return fLeading;
a378358c 570}