]> git.uio.no Git - u/mrichter/AliRoot.git/blob - PWG2/RESONANCES/AliRsnPIDIndex.cxx
Removed warnings
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPIDIndex.cxx
1 /**************************************************************************
2  * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
3  *                                                                        *
4  * Author: The ALICE Off-line Project.                                    *
5  * Contributors are mentioned in the code where appropriate.              *
6  *                                                                        *
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  **************************************************************************/
15
16 //
17 // *** Class AliRsnPIDIndex ***
18 //
19 // It sorts the indexes of all tracks in an AliRsnEvent
20 // for a fast retrieval of them according to charge and PID.
21 //
22 // author: M. Vala (email: martin.vala@cern.ch)
23 //
24
25 #include <TObject.h>
26
27 #include "AliLog.h"
28
29 #include "AliRsnPIDIndex.h"
30
31 ClassImp (AliRsnPIDIndex)
32
33 //_____________________________________________________________________________
34 AliRsnPIDIndex::AliRsnPIDIndex (Int_t num)
35 {
36 //
37 // Default constructor
38 //
39     Int_t i, j, k;
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);
45         }
46     }
47 }
48
49 //_____________________________________________________________________________
50 AliRsnPIDIndex::AliRsnPIDIndex (const AliRsnPIDIndex & copy)
51     : TObject (copy)
52 {
53 //
54 // Copy constructor.
55 // Creates new instances of all collections
56 // to store a copy of all objects.
57 //
58
59     Int_t i, j, k, size;
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);
67             }
68         }
69     }
70 }
71
72 //_____________________________________________________________________________
73 AliRsnPIDIndex& AliRsnPIDIndex::operator= (const AliRsnPIDIndex & copy)
74 {
75 //
76 // Assignment operator.
77 // Creates new instances of all collections
78 // to store a copy of all objects.
79 //
80
81     Int_t i, j, k, size;
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);
89             }
90         }
91     }
92
93     // return this object
94     return (*this);
95 }
96
97 AliRsnPIDIndex::~AliRsnPIDIndex()
98 {
99 //
100 // Destructor.
101 // Does nothing.
102 //
103 }
104
105 //_____________________________________________________________________________
106 void AliRsnPIDIndex::Print (Option_t * option) const
107 {
108 //
109 // Prints AliRsnPIDIndex info
110 //
111     Int_t i, j;
112     if (!option) return;
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]));
116         }
117     }
118 }
119
120 //_____________________________________________________________________________
121 void AliRsnPIDIndex::AddIndex (const Int_t index, Char_t sign, AliRsnPID::EType type)
122 {
123 //
124 // Adds index to corresponding TArrayI
125 //
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]++;
130 }
131
132 //_____________________________________________________________________________
133 void AliRsnPIDIndex::AddIndex(const Int_t index, Short_t sign, Int_t type)
134 {
135 //
136 // Adds index to corresponding TArrayI
137 //
138
139     fIndex[sign][type].AddAt (index, fNumOfIndex[sign][type]);
140     fNumOfIndex[sign][type]++;
141 }
142
143 //_____________________________________________________________________________
144 void AliRsnPIDIndex::SetCorrectIndexSize()
145 {
146 //
147 // Sets Correct sizes to all TArrayI
148 //
149
150     Int_t i, j;
151     for (i = 0; i < 2; i++) {
152         for (j = 0; j < AliRsnPID::kSpecies + 1; j++) {
153             fIndex[i][j].Set(fNumOfIndex[i][j]);
154         }
155     }
156 }
157
158 //_____________________________________________________________________________
159 TArrayI* AliRsnPIDIndex::GetTracksArray (Char_t sign, AliRsnPID::EType type)
160 {
161 //
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.
167 //
168
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;
174     }
175
176     return &fIndex[icharge][type];
177 }
178
179 //_____________________________________________________________________________
180 TArrayI* AliRsnPIDIndex::GetCharged (Char_t sign)
181 {
182 //
183 // Returns the array of indexes of tracks whose charge
184 // corresponds to the passed argument
185 // Otherwise returns a null pointer.
186 //
187
188     // check that argument is meaningful
189     Int_t icharge = ChargeIndex (sign);
190     if (icharge < 0) return (TArrayI *)0x0;
191
192     // count total number of tracks with that charge
193     // and create output object of appropriate size
194     Int_t i, total = 0;
195     for (i = 0; i <= AliRsnPID::kSpecies; i++) total += fIndex[icharge][i].GetSize();
196     TArrayI *output = new TArrayI(total);
197
198     // add all indexes
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++);
203         }
204     }
205
206     return output;
207 }
208
209 //_____________________________________________________________________________
210 Int_t AliRsnPIDIndex::ChargeIndex (Char_t sign) const
211 {
212 //
213 // Returns the array index corresponding to charge
214 //
215
216     if (sign == '+') return 0;
217     else if (sign == '-') return 1;
218     else {
219         AliError (Form ("Character '%c' not recognized as charge sign", sign));
220         return -1;
221     }
222 }