]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnPIDIndex.cxx
removed obsolete commented methods
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPIDIndex.cxx
1 //
2 // Class AliRsnPIDIndex
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"
13 #include "AliESDtrack.h"
14 #include "AliESDtrackCuts.h"
15
16 #include "AliRsnPIDIndex.h"
17
18 ClassImp(AliRsnPIDIndex)
19
20 //_____________________________________________________________________________
21 AliRsnPIDIndex::AliRsnPIDIndex(Int_t num)
22 {
23 //
24 // Default constructor
25 //
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       }
35     }
36   }
37 }
38
39 //_____________________________________________________________________________
40 AliRsnPIDIndex::AliRsnPIDIndex(const AliRsnPIDIndex & copy)
41     : TObject(copy)
42 {
43 //
44 // Copy constructor.
45 // Creates new instances of all collections
46 // to store a copy of all objects.
47 //
48
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         }
60       }
61     }
62   }
63 }
64
65 //_____________________________________________________________________________
66 AliRsnPIDIndex& 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
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         }
85       }
86     }
87   }
88
89   // return this object
90   return (*this);
91 }
92
93 AliRsnPIDIndex::~AliRsnPIDIndex()
94 {
95 //
96 // Destructor.
97 // Does nothing.
98 //
99 }
100 //_____________________________________________________________________________
101 void AliRsnPIDIndex::ResetAll(Int_t num)
102 {
103 //
104 // Resets All
105 //
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       }
116     }
117   }
118 }
119
120 //_____________________________________________________________________________
121 void AliRsnPIDIndex::Print(Option_t* /*option*/) const
122 {
123 //
124 // Prints AliRsnPIDIndex info
125 //
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   }
135 }
136
137 //_____________________________________________________________________________
138 void AliRsnPIDIndex::AddIndex(const Int_t index, AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType  type)
139 {
140 //
141 // Adds index to corresponding TArrayI
142 //
143
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
153 }
154
155 //_____________________________________________________________________________
156 void AliRsnPIDIndex::SetCorrectIndexSize()
157 {
158 //
159 // Sets Correct sizes to all TArrayI
160 //
161
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       }
168     }
169   }
170 }
171
172 //_____________________________________________________________________________
173 TArrayI* AliRsnPIDIndex::GetTracksArray(AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
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
183   Int_t iMethod = (Int_t)meth;
184   Int_t icharge = ChargeIndex(sign);
185   Int_t itype   = 0;
186   if (icharge < 0) return (TArrayI *) 0x0;
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));
190     return (TArrayI *) 0x0;
191   }
192
193   return &fIndex[iMethod][icharge][itype];
194 }
195
196 //_____________________________________________________________________________
197 TArrayI* AliRsnPIDIndex::GetCharged(Char_t sign)
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 //
204   return GetTracksArray(AliRsnDaughter::kNoPID, sign, AliPID::kUnknown);
205
206 }
207
208 //_____________________________________________________________________________
209 Int_t AliRsnPIDIndex::ChargeIndex(Char_t sign) const
210 {
211 //
212 // Returns the array index corresponding to charge
213 //
214
215   if (sign == '+') return 0;
216   else if (sign == '-') return 1;
217   else {
218     AliError(Form("Character '%c' not recognized as charge sign", sign));
219     return -1;
220   }
221 }
222
223 //_____________________________________________________________________________
224 Char_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 //_____________________________________________________________________________
239 void 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 //_____________________________________________________________________________
269 void 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 //_____________________________________________________________________________
283 void 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 //_____________________________________________________________________________
296 void 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 //_____________________________________________________________________________
307 void 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