2 // Class AliRsnDaughter
4 // Interface to candidate daughters of a resonance (tracks).
5 // Points to the source of information, which is generally an AliVParticle-derived object
6 // and contains few internal data-members to store "on fly" some important information
7 // for the computations required during resonance analysis.
9 // Since the package revision, this object is not supposed to be stacked in memory
10 // but created "on fly" during analysis and used just for computations, as an interface.
12 // authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
13 // M. Vala (martin.vala@cern.ch)
16 #include <Riostream.h>
18 #include <TParticle.h>
23 #include "AliESDtrack.h"
24 #include "AliAODEvent.h"
25 #include "AliAODVertex.h"
26 #include "AliAODTrack.h"
28 #include "AliRsnDaughter.h"
30 ClassImp(AliRsnDaughter)
32 AliRsnDaughter::EPIDMethod AliRsnDaughter::fgPIDMethod = AliRsnDaughter::kRealistic;
34 //_____________________________________________________________________________
35 AliRsnDaughter::AliRsnDaughter(AliVParticle *ref, TParticle *refMC) :
44 // Default constructor.
48 //_____________________________________________________________________________
49 AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter ©) :
52 fKinkIndex(copy.fKinkIndex),
53 fParticle(copy.fParticle),
54 fMotherPDG(copy.fMotherPDG),
55 fStatus(copy.fStatus),
60 // Pointers are NOT duplicated.
64 //_____________________________________________________________________________
65 AliRsnDaughter& AliRsnDaughter::operator=(const AliRsnDaughter ©)
68 // Assignment operator.
71 (TObject)(*this) = (TObject)copy;
74 fKinkIndex = copy.fKinkIndex;
75 fParticle = copy.fParticle;
76 fMotherPDG = copy.fMotherPDG;
77 fStatus = copy.fStatus;
84 //_____________________________________________________________________________
85 AliRsnDaughter::~AliRsnDaughter()
89 // Since pointers do not allocate new objects, nothing is done.
93 //_____________________________________________________________________________
94 void AliRsnDaughter::RotateP
95 (Double_t angle, Double_t &x, Double_t &y, Bool_t isDegrees)
98 // Rotate the transverse momentum by an angle (in DEGREES)
99 // around Z axis (does not change the Z component).
100 // Rotated values are stored in the two arguments passed by reference.
103 if (isDegrees) angle *= TMath::DegToRad();
105 Double_t s = TMath::Sin(angle);
106 Double_t c = TMath::Cos(angle);
112 //_____________________________________________________________________________
113 Double_t AliRsnDaughter::AngleTo(AliRsnDaughter d, Bool_t outInDegrees)
116 // Compute angle between the vector momentum of this
117 // and the one of argument.
120 Double_t arg, dot, ptot2 = P2() * d.P2();
125 dot = Px()*d.Px() + Py()*d.Py() + Pz()*d.Pz();
126 arg = dot / TMath::Sqrt(ptot2);
127 if (arg > 1.0) arg = 1.0;
128 if (arg < -1.0) arg = -1.0;
129 if (outInDegrees) return TMath::ACos(arg) * TMath::RadToDeg();
130 else return TMath::ACos(arg);
134 //_____________________________________________________________________________
135 Int_t AliRsnDaughter::GetID() const
138 // Return reference index, using the "GetID" method
139 // of the possible source object.
142 AliESDtrack *esd = dynamic_cast<AliESDtrack*>(fRef);
143 if (esd) return esd->GetID();
145 AliAODTrack *aod = dynamic_cast<AliAODTrack*>(fRef);
146 if (aod) return aod->GetID();
151 //_____________________________________________________________________________
152 AliPID::EParticleType AliRsnDaughter::RealisticPID() const
155 // Return the "realistic" PID of this track,
156 // i.e. the particle species to which corresponds the largest PID probability.
159 AliPID::EParticleType pid = AliPID::kElectron;
160 Double_t prob = fPID[0];
163 for (i = 1; i < AliPID::kSPECIES; i++) {
164 if (fPID[i] > prob) {
166 pid = (AliPID::EParticleType)i;
173 //_____________________________________________________________________________
174 AliPID::EParticleType AliRsnDaughter::PerfectPID() const
177 // Return the "perfect" PID of this track,
178 // reading it from the MC information, if available.
181 if (!fParticle) return AliPID::kUnknown;
183 Int_t absPDG = TMath::Abs(fParticle->GetPdgCode());
186 return AliPID::kElectron;
188 return AliPID::kMuon;
190 return AliPID::kPion;
192 return AliPID::kKaon;
194 return AliPID::kProton;
196 AliDebug(2, Form("PDG code = %d not recognized. Return 'AliPID::kUnknown'", absPDG));
197 return AliPID::kUnknown;
201 //_____________________________________________________________________________
202 AliPID::EParticleType AliRsnDaughter::PIDType(Double_t &prob) const
205 // Return the PID type according to the selected method
206 // in the argument passed by reference, the probability is stored.
207 // It will be realistic for realistic PID and 1 for perfect PID.
210 AliPID::EParticleType pid = AssignedPID();
213 if (fgPIDMethod == kRealistic) prob = fPID[(Int_t)pid];
218 //_____________________________________________________________________________
219 AliPID::EParticleType AliRsnDaughter::AssignedPID() const
222 // Return the PID type according to the selected method
223 // in the argument passed by reference, the probability is stored.
224 // It will be realistic for realistic PID and 1 for perfect PID.
227 switch (fgPIDMethod) {
229 return AliPID::kUnknown;
233 return RealisticPID();
235 AliWarning("PID method not properly set. Returning realistic PID");
236 return RealisticPID();
240 //_____________________________________________________________________________
241 Bool_t AliRsnDaughter::CombineWithPriors(Double_t *priors)
244 // Combine current PID weights (assumed to be them) with prior probs
250 // multiply weights and priors
251 for (i = 0; i < AliPID::kSPECIES; i++) {
252 fPID[i] = priors[i] * fRef->PID()[i];
255 if (sum <= (Double_t) 0.) {
256 AliError(Form("Sum of weights = %f <= 0", sum));
261 for (i = 0; i < AliPID::kSPECIES; i++) fPID[i] /= sum;
266 //_____________________________________________________________________________
267 AliESDtrack* AliRsnDaughter::GetRefESD()
270 // Return a reference in format of ESD track
273 return dynamic_cast<AliESDtrack *>(fRef);
276 //_____________________________________________________________________________
277 void AliRsnDaughter::FindMotherPDG(AliStack *stack)
280 // Searches the stack to find the mother and retrieve its PDG code.
283 if (!stack || !fParticle) return;
285 Int_t mLabel = fParticle->GetFirstMother();
290 TParticle *mum = stack->Particle(mLabel);
291 if (mum) fMotherPDG = mum->GetPdgCode();
296 //_____________________________________________________________________________
297 inline Double_t AliRsnDaughter::GetMCEnergy(Double_t mass)
300 // Uses the argument to compute 4-momentum energy
303 if (!fParticle) return 0.0;
305 Double_t p2 = fParticle->Px()*fParticle->Px();
306 p2 += fParticle->Py()*fParticle->Py();
307 p2 += fParticle->Pz()*fParticle->Pz();
309 return TMath::Sqrt(mass*mass + p2);
312 //_____________________________________________________________________________
313 void AliRsnDaughter::FindKinkIndex(AliESDtrack *esdTrack)
316 // Assign kink index from an ESD track
320 for (i = 0; i < 3; i++) ik[i] = esdTrack->GetKinkIndex(i);
322 if (ik[0] < 0 || ik[1] < 0 || ik[2] < 0) {
325 else if (ik[0] > 0 || ik[1] > 0 || ik[2] > 0) {
331 //_____________________________________________________________________________
332 void AliRsnDaughter::FindKinkIndex(AliAODEvent *event)
335 // Assign kink index from an AOD event
338 Int_t iv, id, nD, nV = event->GetNumberOfVertices();
339 for (iv = 0; iv < nV; iv++) {
340 AliAODVertex *v = event->GetVertex(iv);
341 AliAODVertex::AODVtx_t type = (AliAODVertex::AODVtx_t)v->GetType();
342 if (type != AliAODVertex::kKink) continue;
343 AliAODTrack *mother = (AliAODTrack*)v->GetParent();
344 if (mother == (AliAODTrack*)fRef) {
348 nD = v->GetNDaughters();
349 for (id = 0; id < nD; id++) {
350 AliAODTrack *son = (AliAODTrack*)v->GetDaughter(id);
351 if (son == (AliAODTrack*)fRef) {
362 //_____________________________________________________________________________
363 void AliRsnDaughter::Reset()
366 // Reset this track to meaningless values
377 //_____________________________________________________________________________
378 void AliRsnDaughter::Print(Option_t *option) const
381 // Prints the values of data members, using the options:
383 // - V --> DCA vertex
384 // - C --> electric charge
386 // - I --> identification (PID, probability and mass)
387 // - W --> PID weights
388 // - M --> Montecarlo (from AliRsnMCInfo)
389 // - L --> index & label
391 // - ALL --> All oprions switched on
393 // Index and label are printed by default.
399 if (opt.Contains("L") || opt.Contains("ALL")) {
400 cout << ".......Index : " << GetID() << endl;
401 cout << ".......Label : " << GetLabel() << endl;
403 if (opt.Contains("P") || opt.Contains("ALL")) {
404 cout << ".......Px, Py, Pz, Pt : " << Px() << ' ' << Py() << ' ' << Pz() << ' ' << Pt() << endl;
406 if (opt.Contains("A") || opt.Contains("ALL")) {
407 cout << ".......Phi, Theta : " << Phi() << ' ' << Theta() << endl;
409 if (opt.Contains("V") || opt.Contains("ALL")) {
410 cout << ".......Vx, Vy, Vz : " << Xv() << ' ' << Yv() << ' ' << Zv() << endl;
412 if (opt.Contains("I") || opt.Contains("ALL")) {
413 AliPID::EParticleType type;
415 type = PIDType(prob);
416 cout << ".......PID & prob : " << AliPID::ParticleName(type) << ' ' << prob << endl;
418 if (opt.Contains("C") || opt.Contains("ALL")) {
419 cout << ".......Charge : " << Charge() << endl;
421 if (opt.Contains("F") || opt.Contains("ALL")) {
422 cout << ".......Flags : " << fStatus << endl;
424 if (opt.Contains("W") || opt.Contains("ALL")) {
425 cout << ".......Weights : ";
427 for (i = 0; i < AliPID::kSPECIES; i++) cout << fPID[i] << ' ';
430 if (opt.Contains("M") || opt.Contains("ALL")) {
432 cout << ".......PDG code : " << fParticle->GetPdgCode() << endl;
433 cout << ".......Mother (label) : " << fParticle->GetFirstMother() << endl;
434 cout << ".......Mother (PDG code): " << fMotherPDG << endl;
436 cout << ".......MC info not present" << endl;
441 //_____________________________________________________________________________
442 AliPID::EParticleType AliRsnDaughter::InternalType(Int_t pdg)
444 // Return the internal enum value corresponding to the PDG
445 // code passed as argument, if possible.
446 // Otherwise, returns 'AliPID::kSPECIES' by default.
449 AliPID::EParticleType value;
450 Int_t absPDG = TMath::Abs(pdg);
454 value = AliPID::kElectron;
457 value = AliPID::kMuon;
460 value = AliPID::kPion;
463 value = AliPID::kKaon;
466 value = AliPID::kProton;
469 value = AliPID::kUnknown;