2 // Class AliRsnPIDIndex
4 // Sorts the indexes of all tracks in an AliRsnEvent
5 // for a fast retrieval of them according to charge and PID.
7 // authors: Martin Vala (martin.vala@cern.ch)
8 // Alberto Pulvirenti (alberto.pulvirenti@ct.infn.it)
13 #include "AliRsnEvent.h"
14 #include "AliRsnPIDIndex.h"
16 ClassImp(AliRsnPIDIndex)
18 //_____________________________________________________________________________
19 AliRsnPIDIndex::AliRsnPIDIndex(Int_t num)
22 // Default constructor.
23 // Reset all arrays to the size specified in the argument (default = 1000).
26 Int_t imethod, icharge, ipid, i;
28 for (imethod = 0; imethod < AliRsnDaughter::kMethods; imethod++)
30 for (icharge = 0; icharge < 2; icharge++)
32 for (ipid = 0; ipid <= AliPID::kSPECIES; ipid++)
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);
42 //_____________________________________________________________________________
43 AliRsnPIDIndex::AliRsnPIDIndex(const AliRsnPIDIndex & copy) :
48 // Duplicates all arrays.
51 Int_t imethod, icharge, ipid, i, size;
53 for (imethod = 0; imethod < AliRsnDaughter::kMethods; imethod++)
55 for (icharge = 0; icharge < 2; icharge++)
57 for (ipid = 0; ipid <= AliPID::kSPECIES; ipid++)
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);
70 //_____________________________________________________________________________
71 AliRsnPIDIndex& AliRsnPIDIndex::operator= (const AliRsnPIDIndex & copy)
74 // Assignment operator.
75 // Duplicates all arrays.
78 Int_t imethod, icharge, ipid, k, size;
80 for (imethod = 0; imethod < AliRsnDaughter::kMethods; imethod++)
82 for (icharge = 0; icharge < 2; icharge++)
84 for (ipid = 0; ipid <= AliPID::kSPECIES; ipid++)
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);
89 for (k = 0; k < size; k++) {
90 fIndex[imethod][icharge][ipid].AddAt(copy.fIndex[imethod][icharge][ipid].At(k), k);
100 //_____________________________________________________________________________
101 AliRsnPIDIndex::~AliRsnPIDIndex()
109 //_____________________________________________________________________________
110 void AliRsnPIDIndex::ResetAll(Int_t num)
113 // Resets all arrays to a given size, and storing '-1' in all values
116 Int_t imethod, icharge, ipid, i;
118 for (imethod = 0; imethod < AliRsnDaughter::kMethods; imethod++)
120 for (icharge = 0; icharge < 2; icharge++)
122 for (ipid = 0; ipid <= AliPID::kSPECIES; ipid++)
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);
132 //_____________________________________________________________________________
133 void AliRsnPIDIndex::Print(Option_t* /*option*/) const
136 // Prints AliRsnPIDIndex info
141 for (l = 0; l < AliRsnDaughter::kMethods; l++) {
142 for (i = 0; i < 2; i++) {
143 for (j = 0; j <= AliPID::kSPECIES; j++) {
144 AliInfo(Form(" [%d][%d][%d] %d %d",l, i, j, fIndex[l][i][j].GetSize(), fNumOfIndex[l][i][j]));
150 //_____________________________________________________________________________
151 void AliRsnPIDIndex::AddIndex
152 (const Int_t index, AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
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)
161 Int_t iMethod = (Int_t)meth;
162 Int_t iCharge = ChargeIndex(sign);
163 Int_t iType = (Int_t)type;
165 // since AliPID kUnknown = 10 and kSPECIES = 5, the PID is "unknown"
166 // a correction in the storage index must be done
167 if (type == AliPID::kUnknown) iType = (Int_t)AliPID::kSPECIES;
169 // debug message (can this be removed?)
170 AliDebug(AliLog::kDebug+1,Form("Adding index=%d method=%d sign='%c', pidType=%d",index,meth,sign,type));
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;
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));
180 // insert the index in the array and increment the counter of occupied slots
181 fIndex[iMethod][iCharge][iType].AddAt(index, fNumOfIndex[iMethod][iCharge][iType]);
182 fNumOfIndex[iMethod][iCharge][iType]++;
185 //_____________________________________________________________________________
186 void AliRsnPIDIndex::SetCorrectIndexSize()
189 // Removes in every array the unused slots, to compress its size.
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]);
202 //_____________________________________________________________________________
203 TArrayI* AliRsnPIDIndex::GetTracksArray
204 (AliRsnDaughter::EPIDMethod meth, Char_t sign, AliPID::EParticleType type)
207 // Returns the array of indexes of tracks whose charge
208 // and PID correspond to the passed arguments:
210 // 2) sign of particle ('+' or '-')
211 // 3) PID of particle (from AliRsnPID::EType)
212 // Otherwise returns null pointer.
215 Int_t iMethod = (Int_t)meth;
216 Int_t iCharge = ChargeIndex(sign);
217 Int_t iType = (Int_t)type;
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;
224 if (iMethod < 0 || iMethod >= AliRsnDaughter::kMethods)
226 AliError("Unrecognized PID method");
229 if (iCharge < 0 || iCharge > 1)
231 AliError(Form("Charge index (%d) out of range", iCharge));
234 if (iType < 0 || iType > AliPID::kSPECIES)
236 AliError(Form("PID index(%d) out of range", iType));
240 return &fIndex[iMethod][iCharge][iType];
243 //_____________________________________________________________________________
244 TArrayI* AliRsnPIDIndex::GetCharged(Char_t sign)
247 // Returns the array of indexes of tracks whose charge
248 // corresponds to the passed argument
249 // Otherwise returns a null pointer.
252 return GetTracksArray(AliRsnDaughter::kNoPID, sign, AliPID::kUnknown);
255 //_____________________________________________________________________________
256 Int_t AliRsnPIDIndex::ChargeIndex(Char_t sign) const
259 // Returns the array index corresponding to charge.
260 // The inverse operation (returning '+' or '-' depending on charge)
261 // is done by 'AliRsnDaughter::GetChargeC()' method.
264 if (sign == '+') return 0;
265 else if (sign == '-') return 1;
266 else if (sign == '0') return 2;
268 AliError(Form("Character '%c' not recognized as charge sign", sign));
273 //_____________________________________________________________________________
274 void AliRsnPIDIndex::FillFromEvent(AliRsnEvent* const event)
277 // Scans a whole event and fills the arrays depending
278 // on the identification of all tracks with all methods.
281 Int_t numOfTracks = event->GetMultiplicity();
283 // first, reset all arrays to the multiplicity,
284 // in order to avoid 'out of range' errors
285 ResetAll(numOfTracks);
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
291 AliRsnDaughter daughter;
292 for (i = 0; i < numOfTracks; i++)
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);
300 // assign current index to right slot for NoPID (essentially the charge)
301 AddIndex(i,AliRsnDaughter::kNoPID,daughter.ChargeC(),AliPID::kUnknown);
303 // assign current index to right slot for realistic PID
304 AddIndex(i, AliRsnDaughter::kRealistic, daughter.ChargeC(), daughter.RealisticPID());
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());
311 // at the end, compress all arrays to the correct size
312 SetCorrectIndexSize();