]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnPIDIndex.cxx
New classes required for revision of package
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPIDIndex.cxx
CommitLineData
06351446 1//
e0baff8c 2// Class AliRsnPIDIndex
06351446 3//
4// It sorts the indexes of all tracks in an AliRsnEvent
5// for a fast retrieval of them according to charge and PID.
6//
7// author: M. Vala (email: martin.vala@cern.ch)
8//
9
10#include <TObject.h>
11
12#include "AliLog.h"
5eb970a4 13#include "AliESDtrack.h"
14#include "AliESDtrackCuts.h"
06351446 15
16#include "AliRsnPIDIndex.h"
17
aec0ec32 18ClassImp(AliRsnPIDIndex)
06351446 19
20//_____________________________________________________________________________
aec0ec32 21AliRsnPIDIndex::AliRsnPIDIndex(Int_t num)
06351446 22{
23//
24// Default constructor
25//
5eb970a4 26 Int_t i, j, k, l;
27
28 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
29 for (i = 0; i < 2; i++) {
30 for (j = 0; j <= AliPID::kSPECIES; j++) {
31 fNumOfIndex[l][i][j] = 0;
32 fIndex[l][i][j].Set(num);
33 for (k = 0; k < num; k++) fIndex[l][i][j].AddAt(-1, k);
34 }
06351446 35 }
aec0ec32 36 }
06351446 37}
38
39//_____________________________________________________________________________
aec0ec32 40AliRsnPIDIndex::AliRsnPIDIndex(const AliRsnPIDIndex & copy)
41 : TObject(copy)
06351446 42{
43//
44// Copy constructor.
45// Creates new instances of all collections
46// to store a copy of all objects.
47//
48
5eb970a4 49 Int_t l, i, j, k, size;
50
51 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
52 for (i = 0; i < 2; i++) {
53 for (j = 0; j <= AliPID::kSPECIES; j++) {
54 fNumOfIndex[l][i][j] = copy.fNumOfIndex[l][i][j];
55 size = copy.fIndex[l][i][j].GetSize();
56 fIndex[l][i][j].Set(size);
57 for (k = 0; k < size; k++) {
58 fIndex[l][i][j].AddAt(copy.fIndex[l][i][j].At(k), k);
59 }
aec0ec32 60 }
06351446 61 }
aec0ec32 62 }
06351446 63}
64
65//_____________________________________________________________________________
66AliRsnPIDIndex& AliRsnPIDIndex::operator= (const AliRsnPIDIndex & copy)
67{
68//
69// Assignment operator.
70// Creates new instances of all collections
71// to store a copy of all objects.
72//
73
5eb970a4 74 Int_t l, i, j, k, size;
75
76 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
77 for (i = 0; i < 2; i++) {
78 for (j = 0; j < AliPID::kSPECIES; j++) {
79 fNumOfIndex[l][i][j] = copy.fNumOfIndex[l][i][j];
80 size = copy.fIndex[l][i][j].GetSize();
81 fIndex[l][i][j].Set(size);
82 for (k = 0; k < size; k++) {
83 fIndex[l][i][j].AddAt(copy.fIndex[l][i][j].At(k), k);
84 }
aec0ec32 85 }
06351446 86 }
aec0ec32 87 }
06351446 88
aec0ec32 89 // return this object
90 return (*this);
06351446 91}
92
93AliRsnPIDIndex::~AliRsnPIDIndex()
94{
95//
96// Destructor.
97// Does nothing.
98//
99}
06351446 100//_____________________________________________________________________________
5eb970a4 101void AliRsnPIDIndex::ResetAll(Int_t num)
06351446 102{
103//
5eb970a4 104// Resets All
06351446 105//
5eb970a4 106
107 Int_t i, j, k, l;
108
109 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
110 for (i = 0; i < 2; i++) {
111 for (j = 0; j <= AliPID::kSPECIES; j++) {
112 fNumOfIndex[l][i][j] = 0;
113 fIndex[l][i][j].Set(num);
114 for (k = 0; k < num; k++) fIndex[l][i][j].AddAt(-1, k);
115 }
06351446 116 }
aec0ec32 117 }
06351446 118}
119
120//_____________________________________________________________________________
5eb970a4 121void AliRsnPIDIndex::Print(Option_t* /*option*/) const
06351446 122{
123//
5eb970a4 124// Prints AliRsnPIDIndex info
06351446 125//
5eb970a4 126 Int_t i, j, l;
127
128 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
129 for (i = 0; i < 2; i++) {
130 for (j = 0; j <= AliPID::kSPECIES; j++) {
131 AliInfo(Form(" [%d][%d][%d] %d %d",l, i, j, fIndex[l][i][j].GetSize(), fNumOfIndex[i][j]));
132 }
133 }
134 }
06351446 135}
136
137//_____________________________________________________________________________
5eb970a4 138void AliRsnPIDIndex::AddIndex(const Int_t index, AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
06351446 139{
140//
141// Adds index to corresponding TArrayI
142//
143
5eb970a4 144 Int_t iMethod = (Int_t)meth;
145 Int_t iCharge = ChargeIndex(sign);
146 Int_t iType = (Int_t)type;
147 // in AliPID kUnknown = 10 and kSPECIES = 5!
148 if (type == AliPID::kUnknown) iType = (Int_t)AliPID::kSPECIES;
149 AliDebug(AliLog::kDebug+1,Form("Adding index=%d method=%d sign='%c', pidType=%d",index,meth,sign,type));
150 fIndex[iMethod][iCharge][iType].AddAt(index, fNumOfIndex[iMethod][iCharge][iType]);
151 fNumOfIndex[iMethod][iCharge][iType]++;
152
06351446 153}
154
155//_____________________________________________________________________________
156void AliRsnPIDIndex::SetCorrectIndexSize()
157{
158//
159// Sets Correct sizes to all TArrayI
160//
161
5eb970a4 162 Int_t i, j, l;
163 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
164 for (i = 0; i < 2; i++) {
165 for (j = 0; j <= AliPID::kSPECIES; j++) {
166 fIndex[l][i][j].Set(fNumOfIndex[l][i][j]);
167 }
06351446 168 }
aec0ec32 169 }
06351446 170}
171
172//_____________________________________________________________________________
5eb970a4 173TArrayI* AliRsnPIDIndex::GetTracksArray(AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
06351446 174{
175//
176// Returns the array of indexes of tracks whose charge
177// and PID correspond to the passed arguments:
178// 1) sign of particle ('+' or '-')
179// 2) PID of particle (from AliRsnPID::EType)
180// Otherwise returns null pointer.
181//
182
5eb970a4 183 Int_t iMethod = (Int_t)meth;
aec0ec32 184 Int_t icharge = ChargeIndex(sign);
5eb970a4 185 Int_t itype = 0;
aec0ec32 186 if (icharge < 0) return (TArrayI *) 0x0;
5eb970a4 187 if (type == AliPID::kUnknown) itype = (Int_t)AliPID::kSPECIES; else itype = (Int_t)type;
188 if (itype < 0 || itype > (Int_t)AliPID::kSPECIES) {
189 AliError(Form("Index %d out of range", itype));
aec0ec32 190 return (TArrayI *) 0x0;
191 }
06351446 192
5eb970a4 193 return &fIndex[iMethod][icharge][itype];
06351446 194}
195
196//_____________________________________________________________________________
aec0ec32 197TArrayI* AliRsnPIDIndex::GetCharged(Char_t sign)
06351446 198{
199//
200// Returns the array of indexes of tracks whose charge
201// corresponds to the passed argument
202// Otherwise returns a null pointer.
203//
5eb970a4 204 return GetTracksArray(AliRsnDaughter::kNoPID, sign, AliPID::kUnknown);
06351446 205
06351446 206}
207
208//_____________________________________________________________________________
aec0ec32 209Int_t AliRsnPIDIndex::ChargeIndex(Char_t sign) const
06351446 210{
211//
212// Returns the array index corresponding to charge
213//
214
aec0ec32 215 if (sign == '+') return 0;
216 else if (sign == '-') return 1;
5eb970a4 217 else {
aec0ec32 218 AliError(Form("Character '%c' not recognized as charge sign", sign));
219 return -1;
220 }
06351446 221}
5eb970a4 222
223//_____________________________________________________________________________
224Char_t AliRsnPIDIndex::IndexCharge(Short_t sign) const
225{
226 //
227 // Returns the array index corresponding to charge
228 //
229
230 if (sign == 1) return '+';
231 else if (sign == -1) return '-';
232 else {
233 AliError(Form("Charge is different the 0(+) and 1(-) value is '%d'...", sign));
234 return '+';
235 }
236}
237
238//_____________________________________________________________________________
239void AliRsnPIDIndex::FillFromEvent(AliRsnEvent* event, AliESDtrackCuts *cuts)
240{
241//
242// Fills indexes from event
243//
244
245 Int_t numOfTracks = event->GetMultiplicity();
246 AliRsnDaughter daughter;
247 Int_t i;
248 for (i=0;i<numOfTracks;i++) {
249 daughter = event->GetDaughter(i);
250 // if ESD track cuts are specified,
251 // and if the reference is an ESD track
252 // skip all tracks not passing the cut
253 if (cuts) {
254 AliESDtrack *track = daughter.GetRefESD();
255 if (track) if (!cuts->IsSelected(track)) continue;
256 }
257 daughter.CombineWithPriors(fPrior);
258// daughter.Print("ALL");
259
260 AddIndex(i,AliRsnDaughter::kNoPID,IndexCharge(daughter.Charge()),AliPID::kUnknown);
261 AddIndex(i,AliRsnDaughter::kRealistic,IndexCharge(daughter.Charge()),(AliPID::EParticleType)daughter.RealisticPID());
262 if (daughter.GetParticle())
263 AddIndex(i,AliRsnDaughter::kPerfect,IndexCharge(daughter.Charge()),(AliPID::EParticleType)daughter.PerfectPID());
264 }
265}
266
267
268//_____________________________________________________________________________
269void AliRsnPIDIndex::SetPriorProbability(AliPID::EParticleType type, Double_t p)
270{
271 //
272 // Sets the prior probability for Realistic PID, for a
273 // given particle species.
274 //
275
276 if (type >= 0 && type < (Int_t)AliPID::kSPECIES) {
277 fPrior[type] = p;
278 }
279
280}
281
282//_____________________________________________________________________________
283void AliRsnPIDIndex::DumpPriors()
284{
285 //
286 // Print all prior probabilities
287 //
288
289 Int_t i;
290 for (i = 0; i < AliPID::kSPECIES; i++) {
291 AliInfo(Form("Prior probability for %10s = %3.5f", AliPID::ParticleName((AliPID::EParticleType)i), fPrior[i]));
292 }
293}
294
295//_____________________________________________________________________________
296void AliRsnPIDIndex::GetPriorProbability(Double_t *out)
297{
298
299 Int_t i;
300 for (i=0; i<AliPID::kSPECIES; i++) {
301 out[i] = fPrior[i];
302 }
303
304}
305
306//_____________________________________________________________________________
307void AliRsnPIDIndex::SetPriorProbability(Double_t *out)
308{
309
310 Int_t i;
311 for (i=0;i<AliPID::kSPECIES;i++) {
312 fPrior[i] = out[i];
313 }
314
315}
316