]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnMother.cxx
fix for Coverity (B.Hippolyte)
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnMother.cxx
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 implements a candidate resonance. It has two pointers to its
19 //  two candidate daughters, whose 4-momenta are combined to obtain the mother
20 //  invariant mass and other kinematical quantities.
21 //  This class contains also some methods used to compute kinematical relations
22 //  between the candidate resonance and other particles.
23 //
24 //  authors: A. Pulvirenti (alberto.pulvirenti@ct.infn.it)
25 //           M. Vala (martin.vala@cern.ch)
26 //
27 ////////////////////////////////////////////////////////////////////////////////
28
29 #include <Riostream.h>
30 #include <TVector3.h>
31
32 #include "AliAODMCParticle.h"
33 #include "AliMCParticle.h"
34 #include "AliRsnDaughter.h"
35 #include "AliRsnMother.h"
36
37 ClassImp(AliRsnMother)
38
39 //_____________________________________________________________________________
40 AliRsnMother::AliRsnMother() :
41    fSum(),
42    fSumMC()
43 {
44 //
45 // Constructor.
46 // Initializes all variables to meaningless values.
47 //
48
49    Int_t i;
50    for (i = 0; i < 2; i++) fDaughter[i] = 0x0;
51 }
52
53 //_____________________________________________________________________________
54 AliRsnMother::AliRsnMother(const AliRsnMother &obj) :
55    TObject(obj),
56    fSum(obj.fSum),
57    fSumMC(obj.fSumMC)
58 {
59 //
60 // Copy constructor.
61 // Does not duplicate pointers.
62 //
63
64    Int_t i;
65    for (i = 0; i < 2; i++) fDaughter[i] = obj.fDaughter[i];
66 }
67
68 //_____________________________________________________________________________
69 AliRsnMother& AliRsnMother::operator=(const AliRsnMother &obj)
70 {
71 //
72 // Assignment operator.
73 // Does not duplicate pointers.
74 //
75
76    Int_t i;
77
78    fSum = obj.fSum;
79    fSumMC = obj.fSumMC;
80
81    for (i = 0; i < 2; i++) fDaughter[i] = obj.fDaughter[i];
82
83    return (*this);
84 }
85
86 //_____________________________________________________________________________
87 AliRsnMother::~AliRsnMother()
88 {
89 //
90 // Desctructor.
91 // Does nothing, since pointers are not created in this class.
92 //
93 }
94
95 //_____________________________________________________________________________
96 Int_t AliRsnMother::CommonMother(Int_t &m0, Int_t &m1) const
97 {
98 //
99 // If MC info is available, checks if the two tracks in the pair have the same mother.
100 // If the mother label is the same, the function returns the PDG code of mother,
101 // otherwise it returns 0.
102 // The two arguments passed by reference contain the GEANT labels of the mother
103 // of the two particles to which the two daughters point. This is for being able 
104 // to check if they are really coming from a resonance (indexes >= 0) or not.
105 //
106
107    // if MC info is not available, the check can't be done
108    if (!fDaughter[0]->GetRefMC() || !fDaughter[1]->GetRefMC()) {
109       AliDebug(AliLog::kDebug, "MC Info absent --> cannot check common mother");
110       return 0;
111    }
112
113    // check that labels are the same
114    m0 = -1;
115    m1 = -2;
116    if (fDaughter[0]->IsESD() && fDaughter[1]->IsESD()) {
117       if (fDaughter[0]->GetRefMCESD() && fDaughter[1]->GetRefMCESD()) {
118          m0 = fDaughter[0]->GetRefMCESD()->Particle()->GetFirstMother();
119          m1 = fDaughter[1]->GetRefMCESD()->Particle()->GetFirstMother();
120       }
121    }
122    if (fDaughter[0]->IsAOD() && fDaughter[1]->IsAOD()) {
123       if (fDaughter[0]->GetRefMCAOD() && fDaughter[1]->GetRefMCAOD()) {
124          m0 = fDaughter[0]->GetRefMCAOD()->GetMother();
125          m1 = fDaughter[1]->GetRefMCAOD()->GetMother();
126       }
127    }
128    
129    // decide the answer depending on the two mother labels
130    if (m0 != m1) 
131       return 0;
132    else
133       return TMath::Abs(fDaughter[0]->GetMotherPDG());
134 }
135
136 //_____________________________________________________________________________
137 void AliRsnMother::SetDaughters
138 (AliRsnDaughter *d0, Double_t mass0, AliRsnDaughter *d1, Double_t mass1)
139 {
140 //
141 // Define both the two candidate daughters to use, and the mass hypothesis
142 // to be assigned to each of them. 
143 // This calls the 'SetMass()' function of each daughter, which defines
144 // their 4-momenta, and then sums them to obtain the total 4-momentum
145 // of the mother (and then invariant mass, also).
146 // The computation is done always for both the reconstructed and the MC,
147 // when it is available.
148 //
149
150    if (d0) fDaughter[0] = d0;
151    if (d1) fDaughter[1] = d1;
152
153    if (!d0 || !d1) return;
154
155    fDaughter[0]->SetMass(mass0);
156    fDaughter[1]->SetMass(mass1);
157
158    fSum   = fDaughter[0]->Prec() + fDaughter[1]->Prec();
159    fSumMC = fDaughter[0]->Psim() + fDaughter[1]->Psim();
160 }
161
162 //_____________________________________________________________________________
163 void AliRsnMother::ResetPair()
164 {
165 //
166 // Resets the mother, zeroing all data members.
167 //
168
169    Int_t i;
170    for (i = 0; i < 2; i++) fDaughter[i] = 0x0;
171
172    fSum  .SetXYZM(0.0, 0.0, 0.0, 0.0);
173    fSumMC.SetXYZM(0.0, 0.0, 0.0, 0.0);
174 }
175
176 //_____________________________________________________________________________
177 Double_t AliRsnMother::CosThetaStar(Bool_t first, Bool_t useMC)
178 {
179 //
180 // Computes the cosine of theta*, which is the angle of one of the daughters
181 // with respect to the total momentum of the resonance, in its rest frame.
182 // The arguments are needed to choose which of the daughters one want to use
183 // and if reconstructed or MC momentum must be used.
184 // [Contribution from Z. Feckova]
185 //
186
187    TLorentzVector mother    = (useMC ? fSumMC : fSum);
188    TLorentzVector daughter0 = (first ? fDaughter[0]->P(useMC) : fDaughter[1]->P(useMC));
189    TLorentzVector daughter1 = (first ? fDaughter[1]->P(useMC) : fDaughter[0]->P(useMC));
190    TVector3 momentumM(mother.Vect());
191    TVector3 normal(mother.Y() / momentumM.Mag(), -mother.X() / momentumM.Mag(), 0.0);
192
193    // Computes first the invariant mass of the mother
194    Double_t mass0      = fDaughter[0]->P(useMC).M();
195    Double_t mass1      = fDaughter[1]->P(useMC).M();
196    Double_t p0         = daughter0.Vect().Mag();
197    Double_t p1         = daughter1.Vect().Mag();
198    Double_t E0         = TMath::Sqrt(mass0 * mass0 + p0 * p0);
199    Double_t E1         = TMath::Sqrt(mass1 * mass1 + p1 * p1);
200    Double_t MotherMass = TMath::Sqrt((E0 + E1) * (E0 + E1) - (p0 * p0 + 2.0 * daughter0.Vect().Dot(daughter1.Vect()) + p1 * p1));
201    MotherMass = fSum.M();
202
203    // Computes components of beta
204    Double_t betaX = -mother.X() / mother.E();
205    Double_t betaY = -mother.Y() / mother.E();
206    Double_t betaZ = -mother.Z() / mother.E();
207
208    // Computes Lorentz transformation of the momentum of the first daughter
209    // into the rest frame of the mother and theta*
210    daughter0.Boost(betaX, betaY, betaZ);
211    TVector3 momentumD = daughter0.Vect();
212
213    Double_t cosThetaStar = normal.Dot(momentumD) / momentumD.Mag();
214
215    return cosThetaStar;
216 }
217
218 //_____________________________________________________________________________
219 void AliRsnMother::PrintInfo(const Option_t * /*option*/) const
220 {
221 //
222 // Print some info of the pair.
223 // The options are passed to the AliRsnDaughter::Print() method
224 //
225
226    AliInfo("======== BEGIN PAIR INFO ===========");
227    AliInfo("Track #1");
228    fDaughter[0]->Print();
229    AliInfo("Track #2");
230    fDaughter[1]->Print();
231    AliInfo("========= END PAIR INFO ===========");
232 }
233
234 //_____________________________________________________________________________
235 Bool_t AliRsnMother::CheckPair(Bool_t checkMC) const
236 {
237 //
238 // Checks that the pair is well initialized:
239 // - both daughters are good pointers
240 // - if MC is required, both daughters have a MC reference
241 //
242
243    if (!fDaughter[0] || !fDaughter[1]) {
244       AliError("One of the two tracks is NULL in this pair!");
245       return kFALSE;
246    }
247
248    if (checkMC) {
249       if (fDaughter[0]->GetRefMC() == 0x0 || fDaughter[1]->GetRefMC() == 0x0) {
250          AliError("Required MC info but not all MC refs are available");
251          return kFALSE;
252       }
253    }
254
255    return kTRUE;
256 }