1 /**************************************************************************
2 * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
4 * Author: The ALICE Off-line Project. *
5 * Contributors are mentioned in the code where appropriate. *
7 * Permission to use, copy, modify and distribute this software and its *
8 * documentation strictly for non-commercial purposes is hereby granted *
9 * without fee, provided that the above copyright notice appears in all *
10 * copies and that both the copyright notice and this permission notice *
11 * appear in the supporting documentation. The authors make no claims *
12 * about the suitability of this software for any purpose. It is *
13 * provided "as is" without express or implied warranty. *
14 **************************************************************************/
17 // *** Class AliRsnPIDIndex ***
19 // It sorts the indexes of all tracks in an AliRsnEvent
20 // for a fast retrieval of them according to charge and PID.
22 // author: M. Vala (email: martin.vala@cern.ch)
29 #include "AliRsnPIDIndex.h"
31 ClassImp (AliRsnPIDIndex)
33 //_____________________________________________________________________________
34 AliRsnPIDIndex::AliRsnPIDIndex (Int_t num)
37 // Default constructor
40 for (i = 0; i < 2; i++) {
41 for (j = 0; j < AliRsnPID::kSpecies+1; j++) {
42 fNumOfIndex[i][j] = 0;
43 fIndex[i][j].Set(num);
44 for (k = 0; k < num; k++) fIndex[i][j].AddAt(-1, k);
49 //_____________________________________________________________________________
50 AliRsnPIDIndex::AliRsnPIDIndex (const AliRsnPIDIndex & copy)
55 // Creates new instances of all collections
56 // to store a copy of all objects.
60 for (i = 0; i < 2; i++) {
61 for (j = 0; j < AliRsnPID::kSpecies+1; j++) {
62 fNumOfIndex[i][j] = copy.fNumOfIndex[i][j];
63 size = copy.fIndex[i][j].GetSize();
64 fIndex[i][j].Set(size);
65 for (k = 0; k < size; k++) {
66 fIndex[i][j].AddAt(copy.fIndex[i][j].At(k), k);
72 //_____________________________________________________________________________
73 AliRsnPIDIndex& AliRsnPIDIndex::operator= (const AliRsnPIDIndex & copy)
76 // Assignment operator.
77 // Creates new instances of all collections
78 // to store a copy of all objects.
82 for (i = 0; i < 2; i++) {
83 for (j = 0; j < AliRsnPID::kSpecies+1; j++) {
84 fNumOfIndex[i][j] = copy.fNumOfIndex[i][j];
85 size = copy.fIndex[i][j].GetSize();
86 fIndex[i][j].Set(size);
87 for (k = 0; k < size; k++) {
88 fIndex[i][j].AddAt(copy.fIndex[i][j].At(k), k);
97 AliRsnPIDIndex::~AliRsnPIDIndex()
105 //_____________________________________________________________________________
106 void AliRsnPIDIndex::Print (Option_t * option) const
109 // Prints AliRsnPIDIndex info
112 for (i = 0; i < 2; i++) {
113 for (j = 0; j < AliRsnPID::kSpecies + 1; j++) {
114 AliInfo (Form (" [%d][%d] %d %d", i, j, fIndex[i][j].GetSize(), fNumOfIndex[i][j]));
119 //_____________________________________________________________________________
120 void AliRsnPIDIndex::AddIndex (const Int_t index, Char_t sign, AliRsnPID::EType type)
123 // Adds index to corresponding TArrayI
125 Int_t iCharge = ChargeIndex(sign);
126 Int_t iType = (Int_t)type;
127 fIndex[iCharge][iType].AddAt(index, fNumOfIndex[iCharge][iType]);
128 fNumOfIndex[iCharge][iType]++;
131 //_____________________________________________________________________________
132 void AliRsnPIDIndex::AddIndex(const Int_t index, Short_t sign, Int_t type)
135 // Adds index to corresponding TArrayI
138 fIndex[sign][type].AddAt (index, fNumOfIndex[sign][type]);
139 fNumOfIndex[sign][type]++;
142 //_____________________________________________________________________________
143 void AliRsnPIDIndex::SetCorrectIndexSize()
146 // Sets Correct sizes to all TArrayI
150 for (i = 0; i < 2; i++) {
151 for (j = 0; j < AliRsnPID::kSpecies + 1; j++) {
152 fIndex[i][j].Set(fNumOfIndex[i][j]);
157 //_____________________________________________________________________________
158 TArrayI* AliRsnPIDIndex::GetTracksArray (Char_t sign, AliRsnPID::EType type)
161 // Returns the array of indexes of tracks whose charge
162 // and PID correspond to the passed arguments:
163 // 1) sign of particle ('+' or '-')
164 // 2) PID of particle (from AliRsnPID::EType)
165 // Otherwise returns null pointer.
168 Int_t icharge = ChargeIndex (sign);
169 if (icharge < 0) return (TArrayI *) 0x0;
170 if (type < AliRsnPID::kElectron || type > AliRsnPID::kSpecies) {
171 AliError (Form ("Index %d out of range", type));
172 return (TArrayI *) 0x0;
175 return &fIndex[icharge][type];
178 //_____________________________________________________________________________
179 TArrayI* AliRsnPIDIndex::GetCharged (Char_t sign)
182 // Returns the array of indexes of tracks whose charge
183 // corresponds to the passed argument
184 // Otherwise returns a null pointer.
187 // check that argument is meaningful
188 Int_t icharge = ChargeIndex (sign);
189 if (icharge < 0) return (TArrayI *)0x0;
191 // count total number of tracks with that charge
192 // and create output object of appropriate size
194 for (i = 0; i <= AliRsnPID::kSpecies; i++) total += fIndex[icharge][i].GetSize();
195 TArrayI *output = new TArrayI(total);
198 Int_t j, counter = 0;
199 for (i = 0; i <= AliRsnPID::kSpecies; i++) {
200 for (j = 0; j < fIndex[icharge][i].GetSize(); j++) {
201 output->AddAt (fIndex[icharge][i].At(j), counter++);
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));