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
113 for (i = 0; i < 2; i++) {
114 for (j = 0; j < AliRsnPID::kSpecies + 1; j++) {
115 AliInfo (Form (" [%d][%d] %d %d", i, j, fIndex[i][j].GetSize(), fNumOfIndex[i][j]));
120 //_____________________________________________________________________________
121 void AliRsnPIDIndex::AddIndex (const Int_t index, Char_t sign, AliRsnPID::EType type)
124 // Adds index to corresponding TArrayI
126 Int_t iCharge = ChargeIndex(sign);
127 Int_t iType = (Int_t)type;
128 fIndex[iCharge][iType].AddAt(index, fNumOfIndex[iCharge][iType]);
129 fNumOfIndex[iCharge][iType]++;
132 //_____________________________________________________________________________
133 void AliRsnPIDIndex::AddIndex(const Int_t index, Short_t sign, Int_t type)
136 // Adds index to corresponding TArrayI
139 fIndex[sign][type].AddAt (index, fNumOfIndex[sign][type]);
140 fNumOfIndex[sign][type]++;
143 //_____________________________________________________________________________
144 void AliRsnPIDIndex::SetCorrectIndexSize()
147 // Sets Correct sizes to all TArrayI
151 for (i = 0; i < 2; i++) {
152 for (j = 0; j < AliRsnPID::kSpecies + 1; j++) {
153 fIndex[i][j].Set(fNumOfIndex[i][j]);
158 //_____________________________________________________________________________
159 TArrayI* AliRsnPIDIndex::GetTracksArray (Char_t sign, AliRsnPID::EType type)
162 // Returns the array of indexes of tracks whose charge
163 // and PID correspond to the passed arguments:
164 // 1) sign of particle ('+' or '-')
165 // 2) PID of particle (from AliRsnPID::EType)
166 // Otherwise returns null pointer.
169 Int_t icharge = ChargeIndex (sign);
170 if (icharge < 0) return (TArrayI *) 0x0;
171 if (type < AliRsnPID::kElectron || type > AliRsnPID::kSpecies) {
172 AliError (Form ("Index %d out of range", type));
173 return (TArrayI *) 0x0;
176 return &fIndex[icharge][type];
179 //_____________________________________________________________________________
180 TArrayI* AliRsnPIDIndex::GetCharged (Char_t sign)
183 // Returns the array of indexes of tracks whose charge
184 // corresponds to the passed argument
185 // Otherwise returns a null pointer.
188 // check that argument is meaningful
189 Int_t icharge = ChargeIndex (sign);
190 if (icharge < 0) return (TArrayI *)0x0;
192 // count total number of tracks with that charge
193 // and create output object of appropriate size
195 for (i = 0; i <= AliRsnPID::kSpecies; i++) total += fIndex[icharge][i].GetSize();
196 TArrayI *output = new TArrayI(total);
199 Int_t j, counter = 0;
200 for (i = 0; i <= AliRsnPID::kSpecies; i++) {
201 for (j = 0; j < fIndex[icharge][i].GetSize(); j++) {
202 output->AddAt (fIndex[icharge][i].At(j), counter++);
209 //_____________________________________________________________________________
210 Int_t AliRsnPIDIndex::ChargeIndex (Char_t sign) const
213 // Returns the array index corresponding to charge
216 if (sign == '+') return 0;
217 else if (sign == '-') return 1;
219 AliError (Form ("Character '%c' not recognized as charge sign", sign));