2 // Class AliRsnPIDIndex
4 // It sorts the indexes of all tracks in an AliRsnEvent
5 // for a fast retrieval of them according to charge and PID.
7 // author: M. Vala (email: martin.vala@cern.ch)
13 #include "AliESDtrack.h"
14 #include "AliESDtrackCuts.h"
16 #include "AliRsnPIDIndex.h"
18 ClassImp(AliRsnPIDIndex)
20 //_____________________________________________________________________________
21 AliRsnPIDIndex::AliRsnPIDIndex(Int_t num)
24 // Default constructor
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);
39 //_____________________________________________________________________________
40 AliRsnPIDIndex::AliRsnPIDIndex(const AliRsnPIDIndex & copy)
45 // Creates new instances of all collections
46 // to store a copy of all objects.
49 Int_t l, i, j, k, size;
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);
65 //_____________________________________________________________________________
66 AliRsnPIDIndex& AliRsnPIDIndex::operator= (const AliRsnPIDIndex & copy)
69 // Assignment operator.
70 // Creates new instances of all collections
71 // to store a copy of all objects.
74 Int_t l, i, j, k, size;
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);
93 AliRsnPIDIndex::~AliRsnPIDIndex()
100 //_____________________________________________________________________________
101 void AliRsnPIDIndex::ResetAll(Int_t num)
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);
120 //_____________________________________________________________________________
121 void AliRsnPIDIndex::Print(Option_t* /*option*/) const
124 // Prints AliRsnPIDIndex info
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]));
137 //_____________________________________________________________________________
138 void AliRsnPIDIndex::AddIndex(const Int_t index, AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
141 // Adds index to corresponding TArrayI
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]++;
155 //_____________________________________________________________________________
156 void AliRsnPIDIndex::SetCorrectIndexSize()
159 // Sets Correct sizes to all TArrayI
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]);
172 //_____________________________________________________________________________
173 TArrayI* AliRsnPIDIndex::GetTracksArray(AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
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.
183 Int_t iMethod = (Int_t)meth;
184 Int_t icharge = ChargeIndex(sign);
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;
193 return &fIndex[iMethod][icharge][itype];
196 //_____________________________________________________________________________
197 TArrayI* AliRsnPIDIndex::GetCharged(Char_t sign)
200 // Returns the array of indexes of tracks whose charge
201 // corresponds to the passed argument
202 // Otherwise returns a null pointer.
204 return GetTracksArray(AliRsnDaughter::kNoPID, sign, AliPID::kUnknown);
208 //_____________________________________________________________________________
209 Int_t AliRsnPIDIndex::ChargeIndex(Char_t sign) const
212 // Returns the array index corresponding to charge
215 if (sign == '+') return 0;
216 else if (sign == '-') return 1;
218 AliError(Form("Character '%c' not recognized as charge sign", sign));
223 //_____________________________________________________________________________
224 Char_t AliRsnPIDIndex::IndexCharge(Short_t sign) const
227 // Returns the array index corresponding to charge
230 if (sign == 1) return '+';
231 else if (sign == -1) return '-';
233 AliError(Form("Charge is different the 0(+) and 1(-) value is '%d'...", sign));
238 //_____________________________________________________________________________
239 void AliRsnPIDIndex::FillFromEvent(AliRsnEvent* event, AliESDtrackCuts *cuts)
242 // Fills indexes from event
245 Int_t numOfTracks = event->GetMultiplicity();
246 AliRsnDaughter daughter;
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
254 AliESDtrack *track = daughter.GetRefESD();
255 if (track) if (!cuts->IsSelected(track)) continue;
257 daughter.CombineWithPriors(fPrior);
258 // daughter.Print("ALL");
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());
268 //_____________________________________________________________________________
269 void AliRsnPIDIndex::SetPriorProbability(AliPID::EParticleType type, Double_t p)
272 // Sets the prior probability for Realistic PID, for a
273 // given particle species.
276 if (type >= 0 && type < (Int_t)AliPID::kSPECIES) {
282 //_____________________________________________________________________________
283 void AliRsnPIDIndex::DumpPriors()
286 // Print all prior probabilities
290 for (i = 0; i < AliPID::kSPECIES; i++) {
291 AliInfo(Form("Prior probability for %10s = %3.5f", AliPID::ParticleName((AliPID::EParticleType)i), fPrior[i]));
295 //_____________________________________________________________________________
296 void AliRsnPIDIndex::GetPriorProbability(Double_t *out)
300 for (i=0; i<AliPID::kSPECIES; i++) {
306 //_____________________________________________________________________________
307 void AliRsnPIDIndex::SetPriorProbability(Double_t *out)
311 for (i=0;i<AliPID::kSPECIES;i++) {