1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
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 **************************************************************************/
16 ////////////////////////////////////////////////////////////////////////////////
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.
25 // authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
26 // M. Vala (martin.vala@cern.ch)
28 ////////////////////////////////////////////////////////////////////////////////
30 #include <Riostream.h>
33 #include "AliGenEventHeader.h"
35 #include "AliRsnCutSet.h"
36 #include "AliRsnEvent.h"
40 //_____________________________________________________________________________
41 AliRsnEvent::AliRsnEvent(AliVEvent *ref, AliVEvent *refMC) :
49 // Default constructor.
53 //_____________________________________________________________________________
54 AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
58 fLeading(event.fLeading),
60 fAODList(event.fAODList)
67 //_____________________________________________________________________________
68 AliRsnEvent &AliRsnEvent::operator= (const AliRsnEvent &event)
71 // Works in the same way as the copy constructor.
74 TObject::operator=(event);
78 fRefMC = event.fRefMC;
79 fLeading = event.fLeading;
81 fAODList = event.fAODList;
86 //_____________________________________________________________________________
87 AliRsnEvent::~AliRsnEvent()
90 // Destructor (does nothing since there are not owned pointers)
94 //_____________________________________________________________________________
95 void AliRsnEvent::SetDaughter(AliRsnDaughter &out, Int_t index, Bool_t fromMC)
98 // Assigns to the first argument the reference to the i-th track in the ref event.
99 // What assignment method to be used will depend on the index and on the type of input.
100 // If the last argument is kTRUE and an MC is referenced, then both fRef and fRefMC will
101 // point to the MC particle (pure MC analysis)
104 // by default the daughter is reset
105 // and assigned the used index
108 out.SetOwnerEvent(this);
111 if (!InputOK()) return;
112 Bool_t inputESD = IsESD();
114 // if it is pure MC, the index tells what particle
115 // to be read in the stack of MC particles, otherwise
116 // it is converted into a real collection index
119 Bool_t ok = (inputESD ? SetMCInfoESD(out) : SetMCInfoAOD(out));
122 out.SetRef(out.GetRefMC());
126 AliRsnDaughter::ERefType type;
127 if (!ConvertAbsoluteIndex(index, trueIndex, type)) {
128 AliError(Form("Failed to convert absolute index %d", index));
132 case AliRsnDaughter::kTrack:
133 if (inputESD) SetDaughterESDtrack(out, trueIndex); else SetDaughterAODtrack(out, trueIndex);
135 case AliRsnDaughter::kV0:
136 if (inputESD) SetDaughterESDv0(out, trueIndex); else SetDaughterAODv0(out, trueIndex);
138 case AliRsnDaughter::kCascade:
139 if (inputESD) SetDaughterESDcascade(out, trueIndex); else SetDaughterAODcascade(out, trueIndex);
142 AliError("Unrecognized daughter type");
148 //_____________________________________________________________________________
149 AliRsnDaughter AliRsnEvent::GetDaughter(Int_t i, Bool_t fromMC)
152 // Returns a daughter set using same criteria as SetDaughter
156 SetDaughter(d, i, fromMC);
160 //_____________________________________________________________________________
161 void AliRsnEvent::SetDaughterESDtrack(AliRsnDaughter &out, Int_t i)
164 // Setup the first argument to the track identified by the index.
165 // When available, adds the MC information and references.
167 // Version #1: ESD tracks
170 AliESDEvent *esd = (AliESDEvent *)fRef;
172 if (i >= 0 && i < esd->GetNumberOfTracks()) {
173 AliESDtrack *track = esd->GetTrack(i);
177 // if MC is present, assign label and retrieve corresponding particle
179 out.SetLabel(TMath::Abs(track->GetLabel()));
180 if (!SetMCInfoESD(out)) {
181 AliWarning("Failed assignment of MC info");
185 AliWarning("Null track");
188 AliWarning(Form("Overflow: required index = %d, max = %d", i, esd->GetNumberOfTracks()));
192 //_____________________________________________________________________________
193 void AliRsnEvent::SetDaughterAODtrack(AliRsnDaughter &out, Int_t i)
196 // Setup the first argument to the track identified by the index.
197 // When available, adds the MC information and references.
199 // Version #2: AOD tracks
202 AliAODEvent *aod = (AliAODEvent *)fRef;
204 if (i >= 0 && i < aod->GetNumberOfTracks()) {
205 AliAODTrack *track = aod->GetTrack(i);
209 // if MC is present, assign label and retrieve corresponding particle
211 out.SetLabel(TMath::Abs(track->GetLabel()));
212 if (!SetMCInfoAOD(out)) {
213 AliWarning("Failed assignment of MC info");
217 AliWarning("Null track");
220 AliWarning(Form("Overflow: required index = %d, max = %d", i, aod->GetNumberOfTracks()));
224 //_____________________________________________________________________________
225 void AliRsnEvent::SetDaughterESDv0(AliRsnDaughter &out, Int_t i)
228 // Setup the first argument to the track identified by the index.
229 // When available, adds the MC information and references.
231 // Version #3: ESD v0
234 if (i >= 0 && i < fRef->GetNumberOfV0s()) {
235 AliESDEvent *ev = GetRefESD();
236 AliESDv0 *v0 = ev->GetV0(i);
240 // if MC is present, retrieve the label of V0 from those of daughters
242 AliMCEvent *mc = (AliMCEvent *)fRefMC;
243 AliESDtrack *tp = ev->GetTrack(v0->GetPindex());
244 AliESDtrack *tn = ev->GetTrack(v0->GetNindex());
245 if (mc && tp && tn) {
246 Int_t lp = TMath::Abs(tp->GetLabel());
247 Int_t ln = TMath::Abs(tn->GetLabel());
248 TParticle *pp = mc->Stack()->Particle(lp);
249 TParticle *pn = mc->Stack()->Particle(ln);
251 // if their first mothers are the same, the V0 is true
252 // otherwise label remains '-1' --> fake V0
253 if (pp->GetFirstMother() == pn->GetFirstMother() && pp->GetFirstMother() >= 0) {
254 out.SetLabel(pp->GetFirstMother());
256 TParticle *mom = mc->Stack()->Particle(pn->GetFirstMother());
257 if(mom->GetPdgCode() == 310) {
258 //take the mother of the k0s which is a k0 (311)
259 out.SetLabel(mom->GetFirstMother());
270 //_____________________________________________________________________________
271 void AliRsnEvent::SetDaughterAODv0(AliRsnDaughter &out, Int_t i)
274 // Setup the first argument to the track identified by the index.
275 // When available, adds the MC information and references.
277 // Version #4: AOD v0
280 if (i >= 0 && i < fRef->GetNumberOfV0s()) {
281 AliAODEvent *ev = (AliAODEvent *)fRef;
282 AliAODv0 *v0 = ev->GetV0(i);
287 AliAODEvent *mc = (AliAODEvent *)fRefMC;
288 TClonesArray *mcArray = (TClonesArray *)mc->GetList()->FindObject(AliAODMCParticle::StdBranchName());
289 AliAODTrack *tp = (AliAODTrack *)v0->GetDaughter(0);
290 AliAODTrack *tn = (AliAODTrack *)v0->GetDaughter(1);
291 if (mcArray && tp && tn) {
292 Int_t lp = TMath::Abs(tp->GetLabel());
293 Int_t ln = TMath::Abs(tn->GetLabel());
294 AliAODMCParticle *pp = (AliAODMCParticle *)mcArray->At(lp);
295 AliAODMCParticle *pn = (AliAODMCParticle *)mcArray->At(ln);
297 // if their first mothers are the same, the V0 is true
298 // otherwise label remains '-1' --> fake V0
299 if (pp->GetMother() == pn->GetMother() && pp->GetMother() >= 0) {
300 out.SetLabel(pp->GetMother());
310 //_____________________________________________________________________________
311 void AliRsnEvent::SetDaughterESDcascade(AliRsnDaughter &out, Int_t i)
314 // Setup the first argument to the track identified by the index.
315 // When available, adds the MC information and references.
317 // Version #3: ESD cascade
320 if (i >= 0 && i < fRef->GetNumberOfCascades()) {
321 AliESDEvent *ev = GetRefESD();
322 AliESDcascade *casc = ev->GetCascade(i);
333 //_____________________________________________________________________________
334 void AliRsnEvent::SetDaughterAODcascade(AliRsnDaughter &out, Int_t i)
337 // Setup the first argument to the track identified by the index.
338 // When available, adds the MC information and references.
340 // Version #4: AOD cascade
343 if (i >= 0 && i < fRef->GetNumberOfCascades()) {
344 AliAODEvent *ev = GetRefAOD();
345 AliAODv0 *casc = ev->GetCascade(i);
356 //_____________________________________________________________________________
357 Bool_t AliRsnEvent::SetMCInfoESD(AliRsnDaughter &out)
360 // Using the label assigned to the daughter, searches for the MC informations:
365 // if label makes no sense --> failed
366 Int_t label = out.GetLabel();
367 if (label < 0 || !fRefMC) return kFALSE;
369 // get number of particles
370 Int_t nMC = fRefMC->GetNumberOfTracks();
372 // if label too large --> failed
374 AliWarning(Form("Stack overflow: track label = %d -- stack maximum = %d", label, nMC));
379 AliMCEvent *mc = (AliMCEvent *)fRefMC;
380 AliMCParticle *mcPart = (AliMCParticle *)mc->GetTrack(label);
382 // if particle = NULL --> failed
384 AliWarning(Form("Stack discontinuity: label %d refers to a NULL object", label));
387 // otherwise --> success
388 out.SetRefMC(mcPart);
390 // if the particle is not primary, find the mother and get its PDG
391 Int_t imum = mcPart->Particle()->GetFirstMother();
392 if (imum >= 0 && imum < nMC) {
393 AliMCParticle *mcMother = (AliMCParticle *)mc->GetTrack(imum);
395 out.SetMotherPDG(mcMother->Particle()->GetPdgCode());
397 AliWarning(Form("Stack discontinuity: label mother %d refers to a NULL object", imum));
400 AliWarning(Form("Stack overflow: mother label = %d -- stack maximum = %d", imum, nMC));
406 //_____________________________________________________________________________
407 Bool_t AliRsnEvent::SetMCInfoAOD(AliRsnDaughter &out)
410 // Using the label assigned to the daughter, searches for the MC informations:
415 // if label makes no sense --> failed
416 Int_t label = out.GetLabel();
417 if (label < 0 || !fRefMC) return kFALSE;
420 AliAODEvent *mc = (AliAODEvent *)fRefMC;
421 TClonesArray *mcArray = (TClonesArray *)mc->GetList()->FindObject(AliAODMCParticle::StdBranchName());
423 // get number of particles
424 Int_t nMC = mcArray->GetEntriesFast();
426 // if label too large --> failed
428 AliWarning(Form("Stack overflow: track label = %d -- stack maximum = %d", label, nMC));
432 // if particle = NULL --> failed
433 AliAODMCParticle *mcPart = (AliAODMCParticle *)mcArray->At(label);
435 AliWarning(Form("Stack discontinuity: label %d refers to a NULL object", label));
438 // otherwise --> success
439 out.SetRefMC(mcPart);
441 // if the particle is not primary, find the mother and get its PDG
442 Int_t imum = mcPart->GetMother();
443 if (imum >= 0 && imum < nMC) {
444 AliAODMCParticle *mcMother = (AliAODMCParticle *)mcArray->At(imum);
446 out.SetMotherPDG(mcMother->GetPdgCode());
448 AliWarning(Form("Stack discontinuity: label mother %d refers to a NULL object", imum));
450 } else if (imum >= nMC) {
451 AliWarning(Form("Stack overflow: mother label = %d -- stack maximum = %d", imum, nMC));
457 //_____________________________________________________________________________
458 Bool_t AliRsnEvent::ConvertAbsoluteIndex(Int_t index, Int_t &realIndex, AliRsnDaughter::ERefType &type)
461 // Using the phylosophy of the absolute index, which loops over
462 // all tracks, V0s and cascades, returns the result of a check
463 // on it (first argument) based on this criterion:
464 // 1) if the absolute ID is smaller than number of tracks,
465 // return itself and the type 'track'
466 // 2) if the absolute ID is larger than number of tracks, subtract it
467 // and if the result is smaller than number of V0s,
468 // return the corresponding V0 index and type
469 // 3) if the absolute ID is larger than number of tracks + V0s, subtract them
470 // and if the result is smaller than number of cascades,
471 // return the corresponding cascade index and type
472 // The results of this check are stored in the reference arguments, while the outcome of
473 // the function is kTRUE if one of these checks was successful, otherwise it is kFALSE,
474 // meaning that the absolute index reached the end.
477 Int_t nTracks = fRef->GetNumberOfTracks();
478 Int_t nV0s = fRef->GetNumberOfV0s();
479 Int_t nCascades = fRef->GetNumberOfCascades();
481 if (index < nTracks) {
483 type = AliRsnDaughter::kTrack;
485 } else if (index >= nTracks && index < nTracks + nV0s) {
486 realIndex = index - nTracks;
487 type = AliRsnDaughter::kV0;
489 } else if (index >= nTracks + nV0s && index < nTracks + nV0s + nCascades) {
490 realIndex = index - nTracks - nV0s;
491 type = AliRsnDaughter::kCascade;
496 type = AliRsnDaughter::kNoType;
500 //_____________________________________________________________________________
501 Int_t AliRsnEvent::ConvertRealIndex(Int_t index, AliRsnDaughter::ERefType type)
504 // Translates a pair made by index + object type into the corresponding
505 // absolute index, which is set to -1 in case the real index overflows.
508 Int_t nTracks = fRef->GetNumberOfTracks();
509 Int_t nV0s = fRef->GetNumberOfV0s();
510 Int_t nCascades = fRef->GetNumberOfCascades();
513 case AliRsnDaughter::kTrack:
514 if (index >= 0 && index < nTracks)
518 case AliRsnDaughter::kV0:
519 if (index >= 0 && index < nV0s)
520 return nTracks + index;
523 case AliRsnDaughter::kCascade:
524 if (index >= 0 && index < nCascades)
525 return nTracks + nV0s + index;
533 //_____________________________________________________________________________
534 Int_t AliRsnEvent::SelectLeadingParticle(AliRsnCutSet *cuts)
537 // Searches the collection of all particles with given PID type and charge,
538 // and returns the one with largest momentum, provided that it is greater than 1st argument.
539 // If one specifies AliRsnPID::kUnknown as type or AliRsnDaughter::kNoPID as method,
540 // the check is done over all particles irrespectively of their PID.
541 // If the sign argument is '+' or '-', the check is done over the particles of that charge,
542 // otherwise it is done irrespectively of the charge.
546 Bool_t inputESD = IsESD();
547 if (!inputESD && !IsAOD()) {
548 AliError("Need to process ESD or AOD input");
552 Double_t ptMax = 0.0;
553 Int_t i, nTracks = fRef->GetNumberOfTracks();
556 AliRsnDaughter leading;
558 for (i = 0; i < nTracks; i++) {
560 SetDaughterESDtrack(leading, i);
562 SetDaughterAODtrack(leading, i);
563 if (!leading.IsOK()) {
564 AliDebugClass(1, Form("Failed assignment of track %d", i));
567 if (cuts && !cuts->IsSelected(&leading)) {
568 AliDebugClass(1, Form("Track %d didn't pass cuts", i));
571 // check if it has largest momentum
572 if (leading.GetRef()->Pt() > ptMax) {
573 ptMax = leading.GetRef()->Pt();