]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnDaughter.cxx
// Macro to generate and update OCDB entries for a given run:
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnDaughter.cxx
CommitLineData
e2bafbbc 1//
06351446 2// Class AliRsnDaughter
3//
5eb970a4 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.
8// ---
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.
06351446 11//
e0baff8c 12// authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
13// M. Vala (martin.vala@cern.ch)
e2bafbbc 14//
7c2974c8 15
16#include <Riostream.h>
a62a2d82 17#include <TParticle.h>
a62a2d82 18
5eb970a4 19#include "AliStack.h"
a62a2d82 20#include "AliESDtrack.h"
5eb970a4 21#include "AliAODEvent.h"
22#include "AliAODVertex.h"
7c2974c8 23#include "AliAODTrack.h"
7c2974c8 24
7a3ae0d2 25#include "AliRsnPIDDefESD.h"
a62a2d82 26#include "AliRsnDaughter.h"
27
28ClassImp(AliRsnDaughter)
29
61f55b30 30AliRsnDaughter::EPIDMethod AliRsnDaughter::fgPIDMethod = AliRsnDaughter::kRealistic;
e2bafbbc 31
7c2974c8 32//_____________________________________________________________________________
5eb970a4 33AliRsnDaughter::AliRsnDaughter(AliVParticle *ref, TParticle *refMC) :
4fbb2459 34 fOK((ref != 0)),
35 fKinkIndex(0),
36 fParticle(refMC),
37 fMotherPDG(0),
38 fStatus(0),
c4c5c13b 39 fPairIndex(0),
4fbb2459 40 fDr(0.0),
41 fDz(0.0),
42 fReqPID(AliPID::kUnknown),
43 fRef(ref)
2f769150 44{
06351446 45//
a62a2d82 46// Default constructor.
06351446 47//
7c2974c8 48}
49
50//_____________________________________________________________________________
51AliRsnDaughter::AliRsnDaughter(const AliRsnDaughter &copy) :
4fbb2459 52 TObject(copy),
53 fOK(copy.fOK),
54 fKinkIndex(copy.fKinkIndex),
55 fParticle(copy.fParticle),
56 fMotherPDG(copy.fMotherPDG),
57 fStatus(copy.fStatus),
c4c5c13b 58 fPairIndex(copy.fPairIndex),
4fbb2459 59 fDr(copy.fDr),
60 fDz(copy.fDz),
61 fReqPID(copy.fReqPID),
62 fRef(copy.fRef)
7c2974c8 63{
06351446 64//
7c2974c8 65// Copy constructor.
5eb970a4 66// Pointers are NOT duplicated.
06351446 67//
7c2974c8 68}
69
7c2974c8 70//_____________________________________________________________________________
71AliRsnDaughter& AliRsnDaughter::operator=(const AliRsnDaughter &copy)
72{
06351446 73//
7c2974c8 74// Assignment operator.
06351446 75//
76
5eb970a4 77 (TObject)(*this) = (TObject)copy;
06351446 78
5eb970a4 79 fOK = copy.fOK;
80 fKinkIndex = copy.fKinkIndex;
81 fParticle = copy.fParticle;
82 fMotherPDG = copy.fMotherPDG;
83 fStatus = copy.fStatus;
c4c5c13b 84 fPairIndex = copy.fPairIndex;
e79f56bd 85 fDr = copy.fDr;
86 fDz = copy.fDz;
aec0ec32 87
a2ee0d39 88 fReqPID = copy.fReqPID;
89
5eb970a4 90 fRef = copy.fRef;
aec0ec32 91
92 return (*this);
7c2974c8 93}
94
95//_____________________________________________________________________________
96AliRsnDaughter::~AliRsnDaughter()
97{
06351446 98//
5eb970a4 99// Destructor.
100// Since pointers do not allocate new objects, nothing is done.
06351446 101//
7c2974c8 102}
103
e0baff8c 104//_____________________________________________________________________________
5eb970a4 105void AliRsnDaughter::RotateP
9477aa42 106(Double_t angle, Double_t &x, Double_t &y, Bool_t isDegrees) const
e0baff8c 107{
108//
61f55b30 109// Rotate the transverse momentum by an angle (in DEGREES)
5eb970a4 110// around Z axis (does not change the Z component).
111// Rotated values are stored in the two arguments passed by reference.
e0baff8c 112//
113
61f55b30 114 if (isDegrees) angle *= TMath::DegToRad();
115
e0baff8c 116 Double_t s = TMath::Sin(angle);
117 Double_t c = TMath::Cos(angle);
5eb970a4 118
119 x = c*Px() - s*Py();
120 y = s*Px() + c*Py();
e0baff8c 121}
122
78b94cbd 123//_____________________________________________________________________________
5eb970a4 124Double_t AliRsnDaughter::AngleTo(AliRsnDaughter d, Bool_t outInDegrees)
78b94cbd 125{
126//
61f55b30 127// Compute angle between the vector momentum of this
78b94cbd 128// and the one of argument.
129//
130
5eb970a4 131 Double_t arg, dot, ptot2 = P2() * d.P2();
61f55b30 132
5eb970a4 133 if (ptot2 <= 0) {
78b94cbd 134 return 0.0;
5eb970a4 135 } else {
136 dot = Px()*d.Px() + Py()*d.Py() + Pz()*d.Pz();
78b94cbd 137 arg = dot / TMath::Sqrt(ptot2);
138 if (arg > 1.0) arg = 1.0;
139 if (arg < -1.0) arg = -1.0;
61f55b30 140 if (outInDegrees) return TMath::ACos(arg) * TMath::RadToDeg();
141 else return TMath::ACos(arg);
aec0ec32 142 }
7c2974c8 143}
144
06351446 145//_____________________________________________________________________________
5eb970a4 146Int_t AliRsnDaughter::GetID() const
06351446 147{
148//
5eb970a4 149// Return reference index, using the "GetID" method
150// of the possible source object.
06351446 151//
152
5eb970a4 153 AliESDtrack *esd = dynamic_cast<AliESDtrack*>(fRef);
154 if (esd) return esd->GetID();
aec0ec32 155
5eb970a4 156 AliAODTrack *aod = dynamic_cast<AliAODTrack*>(fRef);
157 if (aod) return aod->GetID();
158
159 return GetLabel();
160}
161
162//_____________________________________________________________________________
163AliPID::EParticleType AliRsnDaughter::RealisticPID() const
164{
165//
166// Return the "realistic" PID of this track,
167// i.e. the particle species to which corresponds the largest PID probability.
168//
169
170 AliPID::EParticleType pid = AliPID::kElectron;
171 Double_t prob = fPID[0];
172
173 Int_t i;
174 for (i = 1; i < AliPID::kSPECIES; i++) {
175 if (fPID[i] > prob) {
176 prob = fPID[i];
177 pid = (AliPID::EParticleType)i;
06351446 178 }
aec0ec32 179 }
180
5eb970a4 181 return pid;
06351446 182}
7c2974c8 183
184//_____________________________________________________________________________
5eb970a4 185AliPID::EParticleType AliRsnDaughter::PerfectPID() const
186{
187//
188// Return the "perfect" PID of this track,
189// reading it from the MC information, if available.
190//
191
192 if (!fParticle) return AliPID::kUnknown;
193
194 Int_t absPDG = TMath::Abs(fParticle->GetPdgCode());
195 switch (absPDG) {
4fbb2459 196 case 11:
197 return AliPID::kElectron;
198 case 13:
199 return AliPID::kMuon;
200 case 211:
201 return AliPID::kPion;
202 case 321:
203 return AliPID::kKaon;
204 case 2212:
205 return AliPID::kProton;
206 default:
207 AliDebug(2, Form("PDG code = %d not recognized. Return 'AliPID::kUnknown'", absPDG));
208 return AliPID::kUnknown;
5eb970a4 209 }
210}
211
212//_____________________________________________________________________________
213AliPID::EParticleType AliRsnDaughter::PIDType(Double_t &prob) const
7c2974c8 214{
06351446 215//
e2bafbbc 216// Return the PID type according to the selected method
217// in the argument passed by reference, the probability is stored.
218// It will be realistic for realistic PID and 1 for perfect PID.
219//
220
5eb970a4 221 AliPID::EParticleType pid = AssignedPID();
222
223 prob = 1.0;
224 if (fgPIDMethod == kRealistic) prob = fPID[(Int_t)pid];
225
226 return pid;
227}
228
229//_____________________________________________________________________________
230AliPID::EParticleType AliRsnDaughter::AssignedPID() const
231{
232//
233// Return the PID type according to the selected method
234// in the argument passed by reference, the probability is stored.
235// It will be realistic for realistic PID and 1 for perfect PID.
236//
237
238 switch (fgPIDMethod) {
4fbb2459 239 case kNoPID:
240 return AliPID::kUnknown;
241 case kPerfect:
242 return PerfectPID();
243 case kRealistic:
244 return RealisticPID();
245 default:
246 AliWarning("PID method not properly set. Returning realistic PID");
247 return RealisticPID();
5eb970a4 248 }
249}
250
251//_____________________________________________________________________________
4fbb2459 252Bool_t AliRsnDaughter::CombineWithPriors(const Double_t *priors, AliRsnPIDDefESD *pidDef)
5eb970a4 253{
254//
255// Combine current PID weights (assumed to be them) with prior probs
256//
257
258 Int_t i;
259 Double_t sum = 0.0;
260
7a3ae0d2 261 // get PID weights according to definition
262 // if the reference is not ESD or the pidDef is null
263 // of it is not null but is requires the ESD pid,
264 // the standard PID value is used, otherwise
4fbb2459 265 if (pidDef && GetRefESD()) {
266 pidDef->ComputeWeights(GetRefESD(), fPID);
267 } else {
268 if (fRef->PID())
269 for (i = 0; i < AliPID::kSPECIES; i++) fPID[i] = fRef->PID()[i];
270 else if (fParticle) {
271 // if the PID() returns 0x0, this is a MC particle
272 // and we set the weight corresponding to its species to 1
273 // and the others to zero
274 for (i = 0; i < AliPID::kSPECIES; i++) fPID[i] = 0.0;
275 i = (Int_t)AliRsnDaughter::InternalType(TMath::Abs(fParticle->GetPdgCode()));
276 fPID[i] = 1.0;
277 }
7a3ae0d2 278 }
279
5eb970a4 280 // multiply weights and priors
281 for (i = 0; i < AliPID::kSPECIES; i++) {
7a3ae0d2 282 fPID[i] *= priors[i];
5eb970a4 283 sum += fPID[i];
284 }
4fbb2459 285 if (sum <= 0.0) {
286 if (sum < 0.0) AliError(Form("Sum of weights = %f < 0", sum));
5eb970a4 287 return kFALSE;
288 }
289
290 // normalize
291 for (i = 0; i < AliPID::kSPECIES; i++) fPID[i] /= sum;
292
293 return kTRUE;
294}
295
296//_____________________________________________________________________________
4fbb2459 297void AliRsnDaughter::FindMotherPDG(AliStack *const stack)
5eb970a4 298{
299//
300// Searches the stack to find the mother and retrieve its PDG code.
301//
302
303 if (!stack || !fParticle) return;
304
4fbb2459 305 const Int_t mLabel = fParticle->GetFirstMother();
5eb970a4 306 if (mLabel < 0) {
307 fMotherPDG = 0;
4fbb2459 308 } else {
5eb970a4 309 TParticle *mum = stack->Particle(mLabel);
310 if (mum) fMotherPDG = mum->GetPdgCode();
311 else fMotherPDG = 0;
312 }
313}
314
315//_____________________________________________________________________________
fafdc821 316Double_t AliRsnDaughter::GetMCEnergy(Double_t mass)
5eb970a4 317{
318//
319// Uses the argument to compute 4-momentum energy
320//
321
322 if (!fParticle) return 0.0;
323
324 Double_t p2 = fParticle->Px()*fParticle->Px();
325 p2 += fParticle->Py()*fParticle->Py();
326 p2 += fParticle->Pz()*fParticle->Pz();
327
328 return TMath::Sqrt(mass*mass + p2);
329}
330
331//_____________________________________________________________________________
4fbb2459 332void AliRsnDaughter::FindKinkIndex(const AliESDtrack *esdTrack)
5eb970a4 333{
334//
335// Assign kink index from an ESD track
336//
337
338 Int_t i, ik[3];
339 for (i = 0; i < 3; i++) ik[i] = esdTrack->GetKinkIndex(i);
e79f56bd 340
5eb970a4 341 if (ik[0] < 0 || ik[1] < 0 || ik[2] < 0) {
342 SetKinkMother();
4fbb2459 343 } else if (ik[0] > 0 || ik[1] > 0 || ik[2] > 0) {
5eb970a4 344 SetKinkDaughter();
4fbb2459 345 } else SetNoKink();
5eb970a4 346}
347
348//_____________________________________________________________________________
4fbb2459 349void AliRsnDaughter::FindKinkIndex(AliAODEvent *const event)
5eb970a4 350{
351//
352// Assign kink index from an AOD event
353//
354
355 Int_t iv, id, nD, nV = event->GetNumberOfVertices();
356 for (iv = 0; iv < nV; iv++) {
357 AliAODVertex *v = event->GetVertex(iv);
358 AliAODVertex::AODVtx_t type = (AliAODVertex::AODVtx_t)v->GetType();
359 if (type != AliAODVertex::kKink) continue;
360 AliAODTrack *mother = (AliAODTrack*)v->GetParent();
361 if (mother == (AliAODTrack*)fRef) {
362 SetKinkMother();
363 return;
364 } else {
365 nD = v->GetNDaughters();
366 for (id = 0; id < nD; id++) {
367 AliAODTrack *son = (AliAODTrack*)v->GetDaughter(id);
368 if (son == (AliAODTrack*)fRef) {
369 SetKinkDaughter();
370 return;
371 }
aec0ec32 372 }
5eb970a4 373 }
aec0ec32 374 }
5eb970a4 375
376 SetNoKink();
377}
378
379//_____________________________________________________________________________
380void AliRsnDaughter::Reset()
381{
382//
383// Reset this track to meaningless values
384//
385
386 fOK = kFALSE;
387 fKinkIndex = 0;
388 fParticle = 0x0;
389 fMotherPDG = 0;
390 fStatus = 0;
391 fRef = 0x0;
e2bafbbc 392}
393
7c2974c8 394//_____________________________________________________________________________
4fbb2459 395void AliRsnDaughter::Print(Option_t * const option) const
4c2fda1e 396{
06351446 397//
7c2974c8 398// Prints the values of data members, using the options:
399// - P --> momentum
400// - V --> DCA vertex
401// - C --> electric charge
402// - F --> flags
403// - I --> identification (PID, probability and mass)
404// - W --> PID weights
e79f56bd 405// - M --> Montecarlo
e2bafbbc 406// - L --> index & label
0ef90328 407// - A --> angles
7c2974c8 408// - ALL --> All oprions switched on
4c2fda1e 409//
7c2974c8 410// Index and label are printed by default.
06351446 411//
4c2fda1e 412
aec0ec32 413 TString opt(option);
414 opt.ToUpper();
415
5eb970a4 416 if (opt.Contains("L") || opt.Contains("ALL")) {
417 cout << ".......Index : " << GetID() << endl;
418 cout << ".......Label : " << GetLabel() << endl;
aec0ec32 419 }
5eb970a4 420 if (opt.Contains("P") || opt.Contains("ALL")) {
aec0ec32 421 cout << ".......Px, Py, Pz, Pt : " << Px() << ' ' << Py() << ' ' << Pz() << ' ' << Pt() << endl;
422 }
5eb970a4 423 if (opt.Contains("A") || opt.Contains("ALL")) {
0ef90328 424 cout << ".......Phi, Theta : " << Phi() << ' ' << Theta() << endl;
425 }
5eb970a4 426 if (opt.Contains("V") || opt.Contains("ALL")) {
aec0ec32 427 cout << ".......Vx, Vy, Vz : " << Xv() << ' ' << Yv() << ' ' << Zv() << endl;
428 }
5eb970a4 429 if (opt.Contains("I") || opt.Contains("ALL")) {
430 AliPID::EParticleType type;
aec0ec32 431 Double_t prob;
432 type = PIDType(prob);
5eb970a4 433 cout << ".......PID & prob : " << AliPID::ParticleName(type) << ' ' << prob << endl;
aec0ec32 434 }
5eb970a4 435 if (opt.Contains("C") || opt.Contains("ALL")) {
436 cout << ".......Charge : " << Charge() << endl;
aec0ec32 437 }
5eb970a4 438 if (opt.Contains("F") || opt.Contains("ALL")) {
439 cout << ".......Flags : " << fStatus << endl;
aec0ec32 440 }
5eb970a4 441 if (opt.Contains("W") || opt.Contains("ALL")) {
aec0ec32 442 cout << ".......Weights : ";
443 Int_t i;
5eb970a4 444 for (i = 0; i < AliPID::kSPECIES; i++) cout << fPID[i] << ' ';
aec0ec32 445 cout << endl;
446 }
5eb970a4 447 if (opt.Contains("M") || opt.Contains("ALL")) {
448 if (fParticle) {
449 cout << ".......PDG code : " << fParticle->GetPdgCode() << endl;
450 cout << ".......Mother (label) : " << fParticle->GetFirstMother() << endl;
451 cout << ".......Mother (PDG code): " << fMotherPDG << endl;
452 } else {
aec0ec32 453 cout << ".......MC info not present" << endl;
7c2974c8 454 }
aec0ec32 455 }
4c2fda1e 456}
7c2974c8 457
7c2974c8 458//_____________________________________________________________________________
5eb970a4 459AliPID::EParticleType AliRsnDaughter::InternalType(Int_t pdg)
4fbb2459 460{
06351446 461//
5eb970a4 462// Return the internal enum value corresponding to the PDG
463// code passed as argument, if possible.
464// Otherwise, returns 'AliPID::kSPECIES' by default.
06351446 465//
4fbb2459 466
5eb970a4 467 AliPID::EParticleType value;
468 Int_t absPDG = TMath::Abs(pdg);
469
470 switch (absPDG) {
4fbb2459 471 case 11:
472 value = AliPID::kElectron;
473 break;
474 case 13:
475 value = AliPID::kMuon;
476 break;
477 case 211:
478 value = AliPID::kPion;
479 break;
480 case 321:
481 value = AliPID::kKaon;
482 break;
483 case 2212:
484 value = AliPID::kProton;
485 break;
486 default:
487 value = AliPID::kUnknown;
aec0ec32 488 }
5eb970a4 489 return value;
e2bafbbc 490}
4fbb2459 491
492//_____________________________________________________________________________
493const char* AliRsnDaughter::MethodName(EPIDMethod method)
494{
495//
496// Returns a string with the method name
497//
498
499 switch (method)
500 {
501 case kNoPID:
502 return "No PID";
503 case kRealistic:
504 return "Realistic";
505 case kPerfect:
506 return "Perfect";
507 default:
508 return "Unknown";
509 }
510}