]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnEvent.cxx
Fixed sprintf, so that the pointer address is printed correctly
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnEvent.cxx
CommitLineData
06351446 1//
2// *** Class AliRsnEvent ***
3//
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.
9//
10// authors: A. Pulvirenti (email: alberto.pulvirenti@ct.infn.it)
11// M. Vala (email: martin.vala@cern.ch)
12//
0dffcc8a 13
4fbb2459 14#include <TArrayF.h>
0dffcc8a 15
7c2974c8 16#include "AliLog.h"
5eb970a4 17#include "AliVEvent.h"
5eb970a4 18#include "AliMCEvent.h"
19#include "AliStack.h"
4fbb2459 20#include "AliGenEventHeader.h"
2dab9030 21#include "AliRsnCutPID.h"
7c2974c8 22
0dffcc8a 23#include "AliRsnEvent.h"
24
aec0ec32 25ClassImp(AliRsnEvent)
0dffcc8a 26
7c2974c8 27//_____________________________________________________________________________
5eb970a4 28AliRsnEvent::AliRsnEvent(AliVEvent *ref, AliMCEvent *refMC) :
2dab9030 29 fRef(ref),
30 fRefMC(refMC),
31 fLeading(-1)
2f769150 32{
06351446 33//
4fbb2459 34// Default constructor.
06351446 35//
0dffcc8a 36}
7c2974c8 37
38//_____________________________________________________________________________
aec0ec32 39AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
2dab9030 40 TObject(event),
41 fRef(event.fRef),
42 fRefMC(event.fRefMC),
43 fLeading(event.fLeading)
2f769150 44{
06351446 45//
0dffcc8a 46// Copy constructor.
06351446 47//
2f769150 48}
7c2974c8 49
50//_____________________________________________________________________________
9477aa42 51AliRsnEvent& AliRsnEvent::operator= (const AliRsnEvent & event)
0dffcc8a 52{
06351446 53//
54// Works in the same way as the copy constructor.
55//
aec0ec32 56
5eb970a4 57 (TObject)(*this) = (TObject)event;
2dab9030 58 fRef = event.fRef;
59 fRefMC = event.fRefMC;
60 fLeading = event.fLeading;
5eb970a4 61
aec0ec32 62 return (*this);
0dffcc8a 63}
7c2974c8 64
65//_____________________________________________________________________________
66AliRsnEvent::~AliRsnEvent()
2f769150 67{
06351446 68//
7c2974c8 69// Destructor.
06351446 70//
06351446 71}
72
73//_____________________________________________________________________________
2dab9030 74Bool_t AliRsnEvent::SetDaughter(AliRsnDaughter &out, Int_t i, AliRsnDaughter::ERefType type)
06351446 75{
76//
2dab9030 77// Using the second and third arguments, retrieves the i-th object in the
78// appropriate sample (tracks or V0s) and sets the firs reference object
79// in order to point to that.
80// If a MonteCarlo information is provided, sets the useful informations from there,
81// and in case of a V0, sets the 'label' data member only when the two daughters
82// of the V0 point to the same mother.
83// Returns kFALSE whenever the operation fails (out of range, NULL references).
06351446 84//
06351446 85
2dab9030 86 Int_t label;
87
5eb970a4 88 // retrieve reference particle from reference event
4fbb2459 89 // if it is found, by defaul track can be used (good)
2dab9030 90 if (type == AliRsnDaughter::kTrack)
91 {
92 if (i >= fRef->GetNumberOfTracks())
93 {
94 out.SetBad();
95 return kFALSE;
96 }
97 AliVTrack *track = (AliVTrack*)fRef->GetTrack(i);
98 label = TMath::Abs(track->GetLabel());
99 if (!track)
100 {
101 out.SetBad();
102 return kFALSE;
103 }
104 else
105 {
106 out.SetRef(track);
107 out.SetLabel(label);
108 if (fRefMC)
109 {
110 if (label < fRefMC->GetNumberOfTracks())
111 {
112 AliMCParticle *part = (AliMCParticle*)fRefMC->GetTrack(label);
113 out.SetRefMC(part);
114 }
115 }
116 out.SetGood();
117 }
4fbb2459 118 }
2dab9030 119 else if (type == AliRsnDaughter::kV0)
120 {
121 if (i > fRef->GetNumberOfV0s())
122 {
123 out.SetBad();
124 return kFALSE;
125 }
126 AliESDv0 *esdV = 0x0;
127 AliAODv0 *aodV = 0x0;
128 Int_t lp, ln;
129 AliVTrack *tp = 0x0, *tn = 0x0;
130 if (IsESD()) esdV = GetRefESD()->GetV0(i);
131 if (IsAOD()) aodV = GetRefAOD()->GetV0(i);
132 if (!esdV && !aodV)
133 {
134 out.SetBad();
135 return kFALSE;
136 }
137 else
138 {
139 if (esdV) out.SetRef(esdV); else out.SetRef(aodV);
140 // retrieve the V0 daughters, which must be done differently with ESD and AOD v0s
141 if (esdV)
142 {
143 // get the 2 daughters of the V0
144 AliESDEvent *ev = dynamic_cast<AliESDEvent*>(fRef);
145 tp = ev->GetTrack(esdV->GetPindex());
146 tn = ev->GetTrack(esdV->GetNindex());
147 }
148 else if (aodV)
149 {
150 // get the 2 daughters of the V0
151 AliAODEvent *ev = dynamic_cast<AliAODEvent*>(fRef);
152 tp = ev->GetTrack(aodV->GetPosID());
153 tn = ev->GetTrack(aodV->GetNegID());
154 }
155
156 // now, if we have a MC, use the two track objects
157 // to retrieve the true particle which generated the V0
158 // using their labels; by default they are a false V0 with label -1
159 label = -1;
160 if (tp && tn && fRefMC)
161 {
162 lp = TMath::Abs(tp->GetLabel());
163 ln = TMath::Abs(tn->GetLabel());
164 // if labels are meaningful, retrieve corresponding particles
165 TParticle *pp = fRefMC->Stack()->Particle(lp);
166 TParticle *pn = fRefMC->Stack()->Particle(ln);
167 // if their first mothers are the same, the V0 is true
168 // otherwise no label can be assigned
169 if (pp->GetFirstMother() == pn->GetFirstMother()) label = pp->GetFirstMother();
170 }
171 out.SetLabel(label);
172 out.SetGood();
9477aa42 173 }
9477aa42 174 }
2dab9030 175
176 // finally, in case we have a MC, searches for the mother, in order to store
177 // its PDG code into the output AliRsnDaughter
178 if (fRefMC)
179 {
180 label = out.GetLabel();
181 AliStack *stack = fRefMC->Stack();
182 if (label >= 0 && label < stack->GetNtrack())
183 {
184 TParticle *part = stack->Particle(label);
185 if (part)
186 {
187 Int_t imum = part->GetFirstMother();
188 if (imum >= 0 && imum <= stack->GetNtrack())
189 {
190 TParticle *mum = stack->Particle(imum);
191 if (mum) out.SetMotherPDG(TMath::Abs(mum->GetPdgCode()));
192 }
193 }
194 }
aec0ec32 195 }
2dab9030 196
197 return kTRUE;
e0baff8c 198}
199
15d5fd02 200//_____________________________________________________________________________
2dab9030 201AliRsnDaughter AliRsnEvent::GetDaughter(Int_t i, AliRsnDaughter::ERefType type)
15d5fd02 202{
203//
5eb970a4 204// Return an AliRsnDaughter taken from this event,
205// with all additional data members well set.
15d5fd02 206//
207
5eb970a4 208 AliRsnDaughter out;
2dab9030 209 SetDaughter(out, i, type);
15d5fd02 210
5eb970a4 211 return out;
15d5fd02 212}
213
7c2974c8 214//_____________________________________________________________________________
5eb970a4 215Int_t AliRsnEvent::GetMultiplicity()
7c2974c8 216{
06351446 217//
5eb970a4 218// Returns event multiplicity
06351446 219//
5eb970a4 220 AliDebug(AliLog::kDebug+2,"<-");
221 if (!fRef) return 0;
222 AliDebug(AliLog::kDebug+2,"->");
223 return fRef->GetNumberOfTracks();
7c2974c8 224}
225
226//_____________________________________________________________________________
5eb970a4 227Double_t AliRsnEvent::GetVz()
78b94cbd 228{
229//
5eb970a4 230// Return Z coord of primary vertex
78b94cbd 231//
2dab9030 232
5eb970a4 233 AliDebug(AliLog::kDebug+2,"<-");
234 return fRef->GetPrimaryVertex()->GetZ();
235 AliDebug(AliLog::kDebug+2,"->");
78b94cbd 236}
237
238//_____________________________________________________________________________
2dab9030 239Int_t AliRsnEvent::SelectLeadingParticle
240(Double_t ptMin, AliRsnCutPID *cutPID)
78b94cbd 241{
242//
243// Searches the collection of all particles with given PID type and charge,
244// and returns the one with largest momentum, provided that it is greater than 1st argument.
245// If one specifies AliRsnPID::kUnknown as type or AliRsnDaughter::kNoPID as method,
246// the check is done over all particles irrespectively of their PID.
247// If the sign argument is '+' or '-', the check is done over the particles of that charge,
248// otherwise it is done irrespectively of the charge.
249//
250
5eb970a4 251 Int_t i, nTracks = fRef->GetNumberOfTracks();
2dab9030 252 fLeading = -1;
253 AliRsnDaughter leading;
254 leading.SetBad();
5eb970a4 255
256 for (i = 0; i < nTracks; i++) {
257 AliRsnDaughter track = GetDaughter(i);
2dab9030 258 if (cutPID) if (!cutPID->IsSelected(&track)) continue;
259 if (track.P().Perp() < ptMin) continue;
260 if (!leading.IsOK() || track.P().Perp() > leading.P().Perp())
261 {
262 fLeading = i;
263 leading = track;
78b94cbd 264 }
78b94cbd 265 }
266
2dab9030 267 return fLeading;
78b94cbd 268}
269
5eb970a4 270//_________________________________________________________________________________________________
2dab9030 271Double_t AliRsnEvent::GetAverageMomentum(Int_t &count, AliRsnCutPID *cutPID)
78b94cbd 272{
273//
274// Loops on the list of tracks and computes average total momentum.
275//
276
5eb970a4 277 Int_t i, nTracks = fRef->GetNumberOfTracks();
78b94cbd 278 Double_t pmean = 0.0;
5eb970a4 279
280 for (i = 0, count = 0; i < nTracks; i++) {
281 AliRsnDaughter track = GetDaughter(i);
2dab9030 282 if (cutPID) if (!cutPID->IsSelected(&track)) continue;
283 pmean += track.P().Mag();
5eb970a4 284 count++;
78b94cbd 285 }
15d5fd02 286
5eb970a4 287 if (count > 0) pmean /= (Double_t)count;
288 else pmean = 0.0;
289
78b94cbd 290 return pmean;
291}
292
293//_____________________________________________________________________________
5eb970a4 294Bool_t AliRsnEvent::GetAngleDistr
295(Double_t &angleMean, Double_t &angleRMS, AliRsnDaughter leading)
78b94cbd 296{
297//
298// Takes the leading particle and computes the mean and RMS
299// of the distribution of directions of all other tracks
300// with respect to the direction of leading particle.
301//
302
5eb970a4 303 if (!leading.IsOK()) return kFALSE;
15d5fd02 304
5eb970a4 305 Int_t i, count, nTracks = fRef->GetNumberOfTracks();
306 Double_t angle, angle2Mean = 0.0;
15d5fd02 307
78b94cbd 308 angleMean = angle2Mean = 0.0;
15d5fd02 309
5eb970a4 310 for (i = 0, count = 0; i < nTracks; i++) {
311 AliRsnDaughter trk = GetDaughter(i);
312 if (trk.GetID() == leading.GetID()) continue;
15d5fd02 313
2dab9030 314 angle = leading.P().Angle(trk.P().Vect());
15d5fd02 315
78b94cbd 316 angleMean += angle;
317 angle2Mean += angle * angle;
318 count++;
319 }
15d5fd02 320
78b94cbd 321 if (!count) return kFALSE;
15d5fd02 322
78b94cbd 323 angleMean /= (Double_t)count;
324 angle2Mean /= (Double_t)count;
9477aa42 325 angleRMS = TMath::Sqrt(angle2Mean - angleMean * angleMean);
15d5fd02 326
78b94cbd 327 return kTRUE;
328}