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 "AliESDEvent.h"
19 #include "AliAODEvent.h"
20 #include "AliMCEvent.h"
22 #include "AliGenEventHeader.h"
24 #include "AliRsnEvent.h"
28 //_____________________________________________________________________________
29 AliRsnEvent::AliRsnEvent(AliVEvent *ref, AliMCEvent *refMC) :
35 // Default constructor.
36 // Set the prior probabilities to some default values
46 //_____________________________________________________________________________
47 AliRsnEvent::AliRsnEvent(const AliRsnEvent &event) :
51 fPIDDefESD(event.fPIDDefESD)
58 //_____________________________________________________________________________
59 AliRsnEvent& AliRsnEvent::operator= (const AliRsnEvent & event)
62 // Works in the same way as the copy constructor.
65 (TObject)(*this) = (TObject)event;
67 fRefMC = event.fRefMC;
68 fPIDDefESD = event.fPIDDefESD;
73 //_____________________________________________________________________________
74 AliRsnEvent::~AliRsnEvent()
81 //_____________________________________________________________________________
82 void AliRsnEvent::SetDaughter(AliRsnDaughter &out, Int_t i)
85 // Return a track stored here in format of AliRsnDaughter.
86 // and finds in the reference event the informations to set
87 // the proprietary data members of AliRsnDaughter
90 // retrieve reference particle from reference event
91 // if it is found, by defaul track can be used (good)
92 AliVParticle *ref = (AliVParticle*)fRef->GetTrack(i);
97 // if MC info is present, retrieve from it
100 Int_t label = TMath::Abs(ref->GetLabel());
101 refMC = fRefMC->Stack()->Particle(label);
102 out.SetParticle(refMC);
103 out.FindMotherPDG(fRefMC->Stack());
106 // if fRef is MC event return
107 AliMCEvent *mc = dynamic_cast<AliMCEvent *>(fRef);
110 // dynamic reference to true nature of referenced event
112 AliESDEvent *esd = dynamic_cast<AliESDEvent*>(fRef);
113 AliAODEvent *aod = dynamic_cast<AliAODEvent*>(fRef);
116 // retrieve vertex and set impact parameters
117 Double_t dx = out.Xv(), dy = out.Yv(), dz = out.Zv();
118 const AliVVertex *v = fRef->GetPrimaryVertex();
124 // if reference is an MC event, no primary vertex is supplied
125 // but it is possible to retrieve it from header
127 fRefMC->GenEventHeader()->PrimaryVertex(fvertex);
132 out.SetDr(TMath::Sqrt(dx*dx + dy*dy));
135 // compute PID probabilities by combining
136 // the PID weights in the source with priors
137 // and eventually using the PIDDefESD
138 // (the AliRsnDaughter objec knows how to manage the latter)
139 out.CombineWithPriors(fPrior, &fPIDDefESD);
142 AliESDtrack *esdTrack = esd->GetTrack(i);
143 out.FindKinkIndex(esdTrack);
145 out.FindKinkIndex(aod);
149 //_____________________________________________________________________________
150 AliRsnDaughter AliRsnEvent::GetDaughter(Int_t i)
153 // Return an AliRsnDaughter taken from this event,
154 // with all additional data members well set.
163 //_____________________________________________________________________________
164 Int_t AliRsnEvent::GetMultiplicity()
167 // Returns event multiplicity
169 AliDebug(AliLog::kDebug+2,"<-");
171 AliDebug(AliLog::kDebug+2,"->");
172 return fRef->GetNumberOfTracks();
175 //_____________________________________________________________________________
176 Double_t AliRsnEvent::GetVz()
179 // Return Z coord of primary vertex
181 AliDebug(AliLog::kDebug+2,"<-");
182 return fRef->GetPrimaryVertex()->GetZ();
183 AliDebug(AliLog::kDebug+2,"->");
186 //_____________________________________________________________________________
187 AliRsnDaughter AliRsnEvent::GetLeadingParticle
188 (Double_t ptMin, AliPID::EParticleType type)
191 // Searches the collection of all particles with given PID type and charge,
192 // and returns the one with largest momentum, provided that it is greater than 1st argument.
193 // If one specifies AliRsnPID::kUnknown as type or AliRsnDaughter::kNoPID as method,
194 // the check is done over all particles irrespectively of their PID.
195 // If the sign argument is '+' or '-', the check is done over the particles of that charge,
196 // otherwise it is done irrespectively of the charge.
199 Int_t i, nTracks = fRef->GetNumberOfTracks();
200 AliRsnDaughter output;
202 for (i = 0; i < nTracks; i++) {
203 AliRsnDaughter track = GetDaughter(i);
204 if (!AcceptTrackPID(&track, type)) continue;
205 if (track.Pt() < ptMin) continue;
206 if (!output.IsOK() || track.Pt() > output.Pt()) {
215 //_________________________________________________________________________________________________
216 Double_t AliRsnEvent::GetAverageMomentum(Int_t &count, AliPID::EParticleType type)
219 // Loops on the list of tracks and computes average total momentum.
222 Int_t i, nTracks = fRef->GetNumberOfTracks();
223 Double_t pmean = 0.0;
225 for (i = 0, count = 0; i < nTracks; i++) {
226 AliRsnDaughter track = GetDaughter(i);
227 if (!AcceptTrackPID(&track, type)) continue;
232 if (count > 0) pmean /= (Double_t)count;
238 //_____________________________________________________________________________
239 Bool_t AliRsnEvent::GetAngleDistr
240 (Double_t &angleMean, Double_t &angleRMS, AliRsnDaughter leading)
243 // Takes the leading particle and computes the mean and RMS
244 // of the distribution of directions of all other tracks
245 // with respect to the direction of leading particle.
248 if (!leading.IsOK()) return kFALSE;
250 Int_t i, count, nTracks = fRef->GetNumberOfTracks();
251 Double_t angle, angle2Mean = 0.0;
253 angleMean = angle2Mean = 0.0;
255 for (i = 0, count = 0; i < nTracks; i++) {
256 AliRsnDaughter trk = GetDaughter(i);
257 if (trk.GetID() == leading.GetID()) continue;
259 angle = leading.AngleTo(trk);
262 angle2Mean += angle * angle;
266 if (!count) return kFALSE;
268 angleMean /= (Double_t)count;
269 angle2Mean /= (Double_t)count;
270 angleRMS = TMath::Sqrt(angle2Mean - angleMean * angleMean);
275 //_____________________________________________________________________________
276 void AliRsnEvent::SetPriorProbability(Double_t *const out)
279 // Set all prior probabilities at once, using an assayr of values.
284 for (i = 0; i < AliPID::kSPECIES; i++) {
289 //_____________________________________________________________________________
290 void AliRsnEvent::DumpPriors()
293 // Print all prior probabilities.
294 // Printout is done using AliInfo, so this will not appear when
295 // the GlobalLogLevel is set to higher level errors.
300 for (i = 0; i < AliPID::kSPECIES; i++) {
301 AliInfo(Form("Prior probability for %10s = %3.5f", AliPID::ParticleName((AliPID::EParticleType)i), fPrior[i]));
305 //_____________________________________________________________________________
306 void AliRsnEvent::GetPriorProbability(Double_t *out) const
309 // Stores in the passed argument all the values.
314 for (i = 0; i < AliPID::kSPECIES; i++) {
320 //_____________________________________________________________________________
321 Bool_t AliRsnEvent::AcceptTrackPID(AliRsnDaughter * const d, AliPID::EParticleType type)
325 // Checks if the track PID (according to method in use) corresponds
326 // to the required identification species.
327 // If the second argument is "kUnknown", answer of this method is always YES.
330 if (type == AliPID::kUnknown) return kTRUE;
332 return (d->AssignedPID() == type);