2 // *** Class AliRsnEvent ***
4 // A container for a collection of AliRsnDaughter objects from an event.
5 // Contains also the primary vertex, useful for some cuts.
6 // In order to retrieve easily the tracks which have been identified
7 // as a specific type and charge, there is an array of indexes which
8 // allows to avoid to loop on all tracks and have only the neede ones.
10 // authors: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
11 // M. Vala (email: martin.vala@cern.ch)
17 #include "AliVEvent.h"
18 #include "AliMCEvent.h"
20 #include "AliGenEventHeader.h"
21 #include "AliAODEvent.h"
22 #include "AliRsnCutPID.h"
23 #include "AliESDtrackCuts.h"
25 #include "AliRsnEvent.h"
29 //_____________________________________________________________________________
30 AliRsnEvent::AliRsnEvent(AliVEvent *ref, AliVEvent *refMC) :
36 // Default constructor.
40 //_____________________________________________________________________________
41 AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
45 fLeading(event.fLeading)
52 //_____________________________________________________________________________
53 AliRsnEvent& AliRsnEvent::operator= (const AliRsnEvent & event)
56 // Works in the same way as the copy constructor.
59 (TObject)(*this) = (TObject)event;
61 fRefMC = event.fRefMC;
62 fLeading = event.fLeading;
67 //_____________________________________________________________________________
68 Bool_t AliRsnEvent::SetDaughter(AliRsnDaughter &out, Int_t i, AliRsnDaughter::ERefType type)
71 // Using the second and third arguments, retrieves the i-th object in the
72 // appropriate sample (tracks or V0s) and sets the first reference object
73 // in order to point to that.
74 // If a MonteCarlo information is provided, sets the useful informations from there,
75 // and in case of a V0, sets the 'label' data member only when the two daughters
76 // of the V0 point to the same mother.
77 // Returns kFALSE whenever the operation fails (out of range, NULL references).
82 if (IsESD() && type == AliRsnDaughter::kTrack) result = SetDaughterESDtrack(out, i);
83 if (IsAOD() && type == AliRsnDaughter::kTrack) result = SetDaughterAODtrack(out, i);
84 if (IsESD() && type == AliRsnDaughter::kV0 ) result = SetDaughterESDv0 (out, i);
85 if (IsAOD() && type == AliRsnDaughter::kV0 ) result = SetDaughterAODv0 (out, i);
90 //_____________________________________________________________________________
91 Bool_t AliRsnEvent::SetDaughterMC(AliRsnDaughter &out, Int_t label)
94 // Using the second argument, retrieves the i-th object in the
95 // MC sample (if present) and assigns the track using only that,
96 // so that it is considered both as main reference and MC reference.
97 // (used for MC-only analysis).
106 // try to convert into both types
108 AliMCEvent *esd = GetRefMCESD();
109 AliAODEvent *aod = GetRefMCAOD();
114 // if the MC track exists, assign it
115 AliMCParticle *track = (AliMCParticle*)fRef->GetTrack(label);
126 // search for its mother in stack
127 imum = track->GetMother();
128 if (imum >= 0 && imum < esd->Stack()->GetNtrack())
130 TParticle *mum = esd->Stack()->Particle(imum);
131 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));
138 // checks that array of MC particles exists
139 TClonesArray *mcArray = (TClonesArray*)aod->GetList()->FindObject(AliAODMCParticle::StdBranchName());
146 // in this case one has to loop over the sample to find the good one
147 TObjArrayIter next(mcArray);
148 AliAODMCParticle *part = 0x0;
149 while ( (part = (AliAODMCParticle*)next()) )
151 if (TMath::Abs(part->GetLabel()) == label)
153 // if the MC track exists, assign it
159 // search for the mother
160 imum = part->GetMother();
161 if (imum >= 0 && imum < mcArray->GetEntriesFast())
163 AliAODMCParticle *mum = (AliAODMCParticle*)mcArray->At(imum);
164 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));
175 //_____________________________________________________________________________
176 AliRsnDaughter AliRsnEvent::GetDaughter(Int_t i, AliRsnDaughter::ERefType type)
179 // Returns a daughter set using same criteria as SetDaughter
183 SetDaughter(d, i, type);
187 //_____________________________________________________________________________
188 AliRsnDaughter AliRsnEvent::GetDaughterMC(Int_t i)
191 // Returns a daughter set using same criteria as SetDaughterMC
199 //_____________________________________________________________________________
200 Int_t AliRsnEvent::GetMultiplicity(AliESDtrackCuts *cuts)
203 // Returns event multiplicity as the number of tracks.
204 // If the argument is not NULL, returns instead the
205 // number of tracks passing the cuts hereby defined.
210 AliESDEvent *esd = GetRefESD();
211 if (cuts && esd) return cuts->CountAcceptedTracks(esd);
212 else return fRef->GetNumberOfTracks();
215 //_____________________________________________________________________________
216 Double_t AliRsnEvent::GetVz()
219 // Return Z coord of primary vertex
222 return fRef->GetPrimaryVertex()->GetZ();
225 //_____________________________________________________________________________
226 Int_t AliRsnEvent::SelectLeadingParticle
227 (Double_t ptMin, AliRsnCutPID *cutPID)
230 // Searches the collection of all particles with given PID type and charge,
231 // and returns the one with largest momentum, provided that it is greater than 1st argument.
232 // If one specifies AliRsnPID::kUnknown as type or AliRsnDaughter::kNoPID as method,
233 // the check is done over all particles irrespectively of their PID.
234 // If the sign argument is '+' or '-', the check is done over the particles of that charge,
235 // otherwise it is done irrespectively of the charge.
238 Int_t i, nTracks = fRef->GetNumberOfTracks();
240 AliRsnDaughter leading;
243 for (i = 0; i < nTracks; i++)
245 AliRsnDaughter track = GetDaughter(i);
246 if (cutPID) if (!cutPID->IsSelected(&track)) continue;
247 const AliVParticle *ref = track.GetRef();
248 if (ref->Pt() < ptMin) continue;
249 //double pt = track.P().Perp();
250 //Printf("track %d %g", i, pt);
251 if (!leading.IsOK() || ref->Pt() > ptMin)
261 //_________________________________________________________________________________________________
262 Double_t AliRsnEvent::GetAverageMomentum(Int_t &count, AliRsnCutPID *cutPID)
265 // Loops on the list of tracks and computes average total momentum.
268 Int_t i, nTracks = fRef->GetNumberOfTracks();
269 Double_t pmean = 0.0;
271 for (i = 0, count = 0; i < nTracks; i++) {
272 AliRsnDaughter track = GetDaughter(i);
273 if (cutPID) if (!cutPID->IsSelected(&track)) continue;
274 pmean += track.P().Mag();
278 if (count > 0) pmean /= (Double_t)count;
284 //_____________________________________________________________________________
285 Bool_t AliRsnEvent::GetAngleDistr
286 (Double_t &angleMean, Double_t &angleRMS, AliRsnDaughter leading)
289 // Takes the leading particle and computes the mean and RMS
290 // of the distribution of directions of all other tracks
291 // with respect to the direction of leading particle.
294 if (!leading.IsOK()) return kFALSE;
296 Int_t i, count, nTracks = fRef->GetNumberOfTracks();
297 Double_t angle, angle2Mean = 0.0;
299 angleMean = angle2Mean = 0.0;
301 for (i = 0, count = 0; i < nTracks; i++) {
302 AliRsnDaughter trk = GetDaughter(i);
303 if (trk.GetID() == leading.GetID()) continue;
305 angle = leading.P().Angle(trk.P().Vect());
308 angle2Mean += angle * angle;
312 if (!count) return kFALSE;
314 angleMean /= (Double_t)count;
315 angle2Mean /= (Double_t)count;
316 angleRMS = TMath::Sqrt(angle2Mean - angleMean * angleMean);
321 //_____________________________________________________________________________
322 Int_t AliRsnEvent::SetDaughterESDtrack(AliRsnDaughter &out, Int_t i)
325 // Setup the first argument to the track identified by the index.
326 // When available, adds the MC information and references.
328 // Version #1: ESD tracks
331 // check 1: index in good range
332 if (i < 0 || i >= fRef->GetNumberOfTracks())
338 // check 2: not NULL object
339 AliVTrack *track = (AliVTrack*)fRef->GetTrack(i);
346 // assign references of reconstructed track
347 Int_t label = TMath::Abs(track->GetLabel());
352 // search for MC track, if available
353 AliMCEvent *mc = GetRefMCESD();
356 // loop on particles using the track label as reference
357 // and then assign also the mother type, if found
358 AliStack *stack = mc->Stack();
359 if (label >= 0 && label < stack->GetNtrack())
361 TParticle *part = stack->Particle(label);
364 Int_t imum = part->GetFirstMother();
365 if (imum >= 0 && imum <= stack->GetNtrack())
367 TParticle *mum = stack->Particle(imum);
368 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));
380 //_____________________________________________________________________________
381 Int_t AliRsnEvent::SetDaughterAODtrack(AliRsnDaughter &out, Int_t i)
384 // Setup the first argument to the track identified by the index.
385 // When available, adds the MC information and references.
387 // Version #2: AOD tracks
390 // check 1: index in good range
391 if (i < 0 || i >= fRef->GetNumberOfTracks())
397 // check 2: not NULL object
398 AliVTrack *track = (AliVTrack*)fRef->GetTrack(i);
405 // assign references of reconstructed track
406 Int_t label = TMath::Abs(track->GetLabel());
411 // search for MC track, if available
412 AliAODEvent *mc = GetRefMCAOD();
415 // loop on particles using the track label as reference
416 // and then assign also the mother type, if found
417 TClonesArray *mcArray = (TClonesArray*)mc->GetList()->FindObject(AliAODMCParticle::StdBranchName());
418 if(!mcArray) return 0;
419 TObjArrayIter next(mcArray);
420 AliAODMCParticle *part = 0x0;
421 while ( (part = (AliAODMCParticle*)next()) )
423 if (TMath::Abs(part->GetLabel()) == label)
426 Int_t imum = part->GetMother();
427 if (imum >= 0 && imum <= mcArray->GetEntriesFast())
429 AliAODMCParticle *mum = (AliAODMCParticle*)mcArray->At(imum);
430 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));
439 //_____________________________________________________________________________
440 Int_t AliRsnEvent::SetDaughterESDv0(AliRsnDaughter &out, Int_t i)
443 // Setup the first argument to the track identified by the index.
444 // When available, adds the MC information and references.
446 // Version #3: ESD v0
449 // check 1: index in good range
450 if (i > fRef->GetNumberOfV0s())
456 // check 2: not NULL object
457 AliESDEvent *ev = GetRefESD();
458 AliESDv0 *v0 = ev->GetV0(i);
465 // assign references of reconstructed track
469 // this time, assigning label is not trivial,
470 // it is done only if MC is present and both
471 // daughters come from a true particle
472 AliMCEvent *mc = GetRefMCESD();
473 AliESDtrack *tp = ev->GetTrack(v0->GetPindex());
474 AliESDtrack *tn = ev->GetTrack(v0->GetNindex());
477 Int_t lp = TMath::Abs(tp->GetLabel());
478 Int_t ln = TMath::Abs(tn->GetLabel());
479 TParticle *pp = mc->Stack()->Particle(lp);
480 TParticle *pn = mc->Stack()->Particle(ln);
481 // if their first mothers are the same, the V0 is true
482 // otherwise no label can be assigned
483 if (pp->GetFirstMother() == pn->GetFirstMother()) out.SetLabel(pp->GetFirstMother());
489 //_____________________________________________________________________________
490 Int_t AliRsnEvent::SetDaughterAODv0(AliRsnDaughter &out, Int_t i)
493 // Setup the first argument to the track identified by the index.
494 // When available, adds the MC information and references.
496 // Version #4: AOD v0
499 // check 1: index in good range
500 if (i > fRef->GetNumberOfV0s())
506 // check 2: not NULL object
507 AliAODEvent *ev = GetRefAOD();
508 AliAODv0 *v0 = ev->GetV0(i);
515 // assign references of reconstructed track
520 // this time, assigning label is not trivial,
521 // it is done only if MC is present and both
522 // daughters come from a true particle
523 TClonesArray *mcArray = (TClonesArray*)ev->GetList()->FindObject(AliAODMCParticle::StdBranchName());
524 AliAODTrack *tp = ev->GetTrack(v0->GetPosID());
525 AliAODTrack *tn = ev->GetTrack(v0->GetNegID());
526 if (mcArray && tp && tn)
528 Int_t lp = TMath::Abs(tp->GetLabel());
529 Int_t ln = TMath::Abs(tn->GetLabel());
530 // loop on array to find MC daughters
531 AliAODMCParticle *pp = 0x0, *pn = 0x0;
532 TObjArrayIter next(mcArray);
533 AliAODMCParticle *part = 0x0;
534 while ( (part = (AliAODMCParticle*)next()) )
536 if (TMath::Abs(part->GetLabel()) == lp) pp = (AliAODMCParticle*)mcArray->IndexOf(part);
537 if (TMath::Abs(part->GetLabel()) == ln) pn = (AliAODMCParticle*)mcArray->IndexOf(part);
539 // assign a MC reference and a label only to true V0s
540 if (pp->GetMother() == pn->GetMother())
542 AliAODMCParticle *mcv0 = (AliAODMCParticle*)mcArray->At(pp->GetMother());
544 out.SetLabel(pp->GetMother());
545 Int_t imum = mcv0->GetMother();
546 if (imum >= 0 && imum <= mcArray->GetEntriesFast())
548 AliAODMCParticle *mum = (AliAODMCParticle*)mcArray->At(imum);
549 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));