]> git.uio.no Git - u/mrichter/AliRoot.git/blame - PWG2/RESONANCES/AliRsnPIDIndex.cxx
fix for bug #70582 (change from L. Molnar)
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPIDIndex.cxx
CommitLineData
06351446 1//
e0baff8c 2// Class AliRsnPIDIndex
06351446 3//
4fbb2459 4// Sorts the indexes of all tracks in an AliRsnEvent
06351446 5// for a fast retrieval of them according to charge and PID.
6//
4fbb2459 7// authors: Martin Vala (martin.vala@cern.ch)
8// Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
06351446 9//
10
06351446 11#include "AliLog.h"
12
4fbb2459 13#include "AliRsnEvent.h"
06351446 14#include "AliRsnPIDIndex.h"
15
aec0ec32 16ClassImp(AliRsnPIDIndex)
06351446 17
18//_____________________________________________________________________________
4fbb2459 19AliRsnPIDIndex::AliRsnPIDIndex(Int_t num)
06351446 20{
21//
4fbb2459 22// Default constructor.
23// Reset all arrays to the size specified in the argument (default = 1000).
06351446 24//
5eb970a4 25
4fbb2459 26 Int_t imethod, icharge, ipid, i;
27
28 for (imethod = 0; imethod < AliRsnDaughter::kMethods; imethod++)
29 {
30 for (icharge = 0; icharge < 2; icharge++)
31 {
32 for (ipid = 0; ipid <= AliPID::kSPECIES; ipid++)
33 {
34 fNumOfIndex[imethod][icharge][ipid] = 0;
35 fIndex[imethod][icharge][ipid].Set(num);
36 for (i = 0; i < num; i++) fIndex[imethod][icharge][ipid].AddAt(-1, i);
5eb970a4 37 }
06351446 38 }
aec0ec32 39 }
06351446 40}
41
42//_____________________________________________________________________________
4fbb2459 43AliRsnPIDIndex::AliRsnPIDIndex(const AliRsnPIDIndex & copy) :
44 TObject(copy)
06351446 45{
46//
47// Copy constructor.
4fbb2459 48// Duplicates all arrays.
06351446 49//
50
4fbb2459 51 Int_t imethod, icharge, ipid, i, size;
52
53 for (imethod = 0; imethod < AliRsnDaughter::kMethods; imethod++)
54 {
55 for (icharge = 0; icharge < 2; icharge++)
56 {
57 for (ipid = 0; ipid <= AliPID::kSPECIES; ipid++)
58 {
59 fNumOfIndex[imethod][icharge][ipid] = copy.fNumOfIndex[imethod][icharge][ipid];
60 size = copy.fIndex[imethod][icharge][ipid].GetSize();
61 fIndex[imethod][icharge][ipid].Set(size);
62 for (i = 0; i < size; i++) {
63 fIndex[imethod][icharge][ipid].AddAt(copy.fIndex[imethod][icharge][ipid].At(i), i);
5eb970a4 64 }
aec0ec32 65 }
06351446 66 }
aec0ec32 67 }
06351446 68}
69
70//_____________________________________________________________________________
71AliRsnPIDIndex& AliRsnPIDIndex::operator= (const AliRsnPIDIndex & copy)
72{
73//
74// Assignment operator.
4fbb2459 75// Duplicates all arrays.
06351446 76//
77
4fbb2459 78 Int_t imethod, icharge, ipid, k, size;
79
80 for (imethod = 0; imethod < AliRsnDaughter::kMethods; imethod++)
81 {
82 for (icharge = 0; icharge < 2; icharge++)
83 {
84 for (ipid = 0; ipid <= AliPID::kSPECIES; ipid++)
85 {
86 fNumOfIndex[imethod][icharge][ipid] = copy.fNumOfIndex[imethod][icharge][ipid];
87 size = copy.fIndex[imethod][icharge][ipid].GetSize();
88 fIndex[imethod][icharge][ipid].Set(size);
5eb970a4 89 for (k = 0; k < size; k++) {
4fbb2459 90 fIndex[imethod][icharge][ipid].AddAt(copy.fIndex[imethod][icharge][ipid].At(k), k);
5eb970a4 91 }
aec0ec32 92 }
06351446 93 }
aec0ec32 94 }
06351446 95
aec0ec32 96 // return this object
97 return (*this);
06351446 98}
99
4fbb2459 100//_____________________________________________________________________________
06351446 101AliRsnPIDIndex::~AliRsnPIDIndex()
102{
103//
104// Destructor.
105// Does nothing.
106//
107}
4fbb2459 108
06351446 109//_____________________________________________________________________________
5eb970a4 110void AliRsnPIDIndex::ResetAll(Int_t num)
06351446 111{
112//
4fbb2459 113// Resets all arrays to a given size, and storing '-1' in all values
06351446 114//
5eb970a4 115
4fbb2459 116 Int_t imethod, icharge, ipid, i;
117
118 for (imethod = 0; imethod < AliRsnDaughter::kMethods; imethod++)
119 {
120 for (icharge = 0; icharge < 2; icharge++)
121 {
122 for (ipid = 0; ipid <= AliPID::kSPECIES; ipid++)
123 {
124 fNumOfIndex[imethod][icharge][ipid] = 0;
125 fIndex[imethod][icharge][ipid].Set(num);
126 for (i = 0; i < num; i++) fIndex[imethod][icharge][ipid].AddAt(-1, i);
5eb970a4 127 }
06351446 128 }
aec0ec32 129 }
06351446 130}
131
132//_____________________________________________________________________________
5eb970a4 133void AliRsnPIDIndex::Print(Option_t* /*option*/) const
06351446 134{
135//
5eb970a4 136// Prints AliRsnPIDIndex info
06351446 137//
4fbb2459 138
5eb970a4 139 Int_t i, j, l;
140
141 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
142 for (i = 0; i < 2; i++) {
143 for (j = 0; j <= AliPID::kSPECIES; j++) {
9477aa42 144 AliInfo(Form(" [%d][%d][%d] %d %d",l, i, j, fIndex[l][i][j].GetSize(), fNumOfIndex[l][i][j]));
5eb970a4 145 }
146 }
147 }
06351446 148}
149
150//_____________________________________________________________________________
4fbb2459 151void AliRsnPIDIndex::AddIndex
152(const Int_t index, AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
06351446 153{
154//
4fbb2459 155// Adds one index (1st arg) to the corresponding array defined by:
156// - PID method (2nd arg)
157// - charge (3rd arg)
158// - pid type (4th arg)
06351446 159//
160
5eb970a4 161 Int_t iMethod = (Int_t)meth;
162 Int_t iCharge = ChargeIndex(sign);
4fbb2459 163 Int_t iType = (Int_t)type;
164
165 // since AliPID kUnknown = 10 and kSPECIES = 5, the PID is "unknown"
166 // a correction in the storage index must be done
5eb970a4 167 if (type == AliPID::kUnknown) iType = (Int_t)AliPID::kSPECIES;
4fbb2459 168
169 // debug message (can this be removed?)
5eb970a4 170 AliDebug(AliLog::kDebug+1,Form("Adding index=%d method=%d sign='%c', pidType=%d",index,meth,sign,type));
4fbb2459 171
172 // check indexes before storing
173 if (iMethod < 0 || iMethod >= AliRsnDaughter::kMethods) return;
174 if (iCharge < 0 || iCharge > 1) return;
175 if (iType < 0 || iType > AliPID::kSPECIES) return;
176
177 // debug to know if adding was successful
178 AliDebug(AliLog::kDebug+1,Form("Adding succeeded for index=%d method=%d sign='%c', pidType=%d",index,meth,sign,type));
179
180 // insert the index in the array and increment the counter of occupied slots
5eb970a4 181 fIndex[iMethod][iCharge][iType].AddAt(index, fNumOfIndex[iMethod][iCharge][iType]);
182 fNumOfIndex[iMethod][iCharge][iType]++;
06351446 183}
184
185//_____________________________________________________________________________
186void AliRsnPIDIndex::SetCorrectIndexSize()
187{
188//
4fbb2459 189// Removes in every array the unused slots, to compress its size.
06351446 190//
191
5eb970a4 192 Int_t i, j, l;
193 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
194 for (i = 0; i < 2; i++) {
195 for (j = 0; j <= AliPID::kSPECIES; j++) {
196 fIndex[l][i][j].Set(fNumOfIndex[l][i][j]);
197 }
06351446 198 }
aec0ec32 199 }
06351446 200}
201
202//_____________________________________________________________________________
4fbb2459 203TArrayI* AliRsnPIDIndex::GetTracksArray
204(AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
06351446 205{
206//
207// Returns the array of indexes of tracks whose charge
208// and PID correspond to the passed arguments:
4fbb2459 209// 1) PID method
210// 2) sign of particle ('+' or '-')
211// 3) PID of particle (from AliRsnPID::EType)
06351446 212// Otherwise returns null pointer.
213//
214
5eb970a4 215 Int_t iMethod = (Int_t)meth;
4fbb2459 216 Int_t iCharge = ChargeIndex(sign);
217 Int_t iType = (Int_t)type;
218
219 // since AliPID kUnknown = 10 and kSPECIES = 5, the PID is "unknown"
220 // a correction in the storage index must be done
221 if (type == AliPID::kUnknown) iType = (Int_t)AliPID::kSPECIES;
222
223 // check indexes
224 if (iMethod < 0 || iMethod >= AliRsnDaughter::kMethods)
225 {
226 AliError("Unrecognized PID method");
227 return 0x0;
228 }
229 if (iCharge < 0 || iCharge > 1)
230 {
231 AliError(Form("Charge index (%d) out of range", iCharge));
232 return 0x0;
233 }
234 if (iType < 0 || iType > AliPID::kSPECIES)
235 {
236 AliError(Form("PID index(%d) out of range", iType));
237 return 0x0;
aec0ec32 238 }
06351446 239
4fbb2459 240 return &fIndex[iMethod][iCharge][iType];
06351446 241}
242
243//_____________________________________________________________________________
aec0ec32 244TArrayI* AliRsnPIDIndex::GetCharged(Char_t sign)
06351446 245{
246//
247// Returns the array of indexes of tracks whose charge
248// corresponds to the passed argument
249// Otherwise returns a null pointer.
250//
251
4fbb2459 252 return GetTracksArray(AliRsnDaughter::kNoPID, sign, AliPID::kUnknown);
06351446 253}
254
255//_____________________________________________________________________________
aec0ec32 256Int_t AliRsnPIDIndex::ChargeIndex(Char_t sign) const
06351446 257{
258//
4fbb2459 259// Returns the array index corresponding to charge.
260// The inverse operation (returning '+' or '-' depending on charge)
261// is done by 'AliRsnDaughter::GetChargeC()' method.
06351446 262//
263
aec0ec32 264 if (sign == '+') return 0;
265 else if (sign == '-') return 1;
4fbb2459 266 else if (sign == '0') return 2;
5eb970a4 267 else {
aec0ec32 268 AliError(Form("Character '%c' not recognized as charge sign", sign));
269 return -1;
270 }
06351446 271}
5eb970a4 272
273//_____________________________________________________________________________
4fbb2459 274void AliRsnPIDIndex::FillFromEvent(AliRsnEvent* const event)
5eb970a4 275{
276//
4fbb2459 277// Scans a whole event and fills the arrays depending
278// on the identification of all tracks with all methods.
5eb970a4 279//
280
281 Int_t numOfTracks = event->GetMultiplicity();
5eb970a4 282
4fbb2459 283 // first, reset all arrays to the multiplicity,
284 // in order to avoid 'out of range' errors
285 ResetAll(numOfTracks);
5eb970a4 286
4fbb2459 287 // now loop on tracks using a unique AliRsnDaughter object
288 // which will point to one track at a time, and allows
289 // to recovery the informations to classify it
5eb970a4 290 Int_t i;
4fbb2459 291 AliRsnDaughter daughter;
292 for (i = 0; i < numOfTracks; i++)
293 {
294 // link the cursor to current track
295 // this method recoveries the true PID and
296 // combines weights with prior probabilities (defined in AliRsnEvent)
297 // to obtain realistic PID
298 event->SetDaughter(daughter, i);
5eb970a4 299
4fbb2459 300 // assign current index to right slot for NoPID (essentially the charge)
301 AddIndex(i,AliRsnDaughter::kNoPID,daughter.ChargeC(),AliPID::kUnknown);
5eb970a4 302
4fbb2459 303 // assign current index to right slot for realistic PID
304 AddIndex(i, AliRsnDaughter::kRealistic, daughter.ChargeC(), daughter.RealisticPID());
5eb970a4 305
4fbb2459 306 // if MC info is present, assign current index to right slot for true PID
307 if (daughter.GetParticle())
308 AddIndex(i, AliRsnDaughter::kPerfect, daughter.ChargeC(), daughter.PerfectPID());
5eb970a4 309 }
310
4fbb2459 311 // at the end, compress all arrays to the correct size
312 SetCorrectIndexSize();
5eb970a4 313}