Package upgrade.
[u/mrichter/AliRoot.git] / PWG2 / RESONANCES / AliRsnPIDIndex.cxx
CommitLineData
06351446 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
31ClassImp (AliRsnPIDIndex)
32
33//_____________________________________________________________________________
34AliRsnPIDIndex::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//_____________________________________________________________________________
50AliRsnPIDIndex::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//_____________________________________________________________________________
73AliRsnPIDIndex& 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
97AliRsnPIDIndex::~AliRsnPIDIndex()
98{
99//
100// Destructor.
101// Does nothing.
102//
103}
104
105//_____________________________________________________________________________
106void AliRsnPIDIndex::Print (Option_t * option) const
107{
108//
109// Prints AliRsnPIDIndex info
110//
111 Int_t i, j;
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]));
115 }
116 }
117}
118
119//_____________________________________________________________________________
120void AliRsnPIDIndex::AddIndex (const Int_t index, Char_t sign, AliRsnPID::EType type)
121{
122//
123// Adds index to corresponding TArrayI
124//
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]++;
129}
130
131//_____________________________________________________________________________
132void AliRsnPIDIndex::AddIndex(const Int_t index, Short_t sign, Int_t type)
133{
134//
135// Adds index to corresponding TArrayI
136//
137
138 fIndex[sign][type].AddAt (index, fNumOfIndex[sign][type]);
139 fNumOfIndex[sign][type]++;
140}
141
142//_____________________________________________________________________________
143void AliRsnPIDIndex::SetCorrectIndexSize()
144{
145//
146// Sets Correct sizes to all TArrayI
147//
148
149 Int_t i, j;
150 for (i = 0; i < 2; i++) {
151 for (j = 0; j < AliRsnPID::kSpecies + 1; j++) {
152 fIndex[i][j].Set(fNumOfIndex[i][j]);
153 }
154 }
155}
156
157//_____________________________________________________________________________
158TArrayI* AliRsnPIDIndex::GetTracksArray (Char_t sign, AliRsnPID::EType type)
159{
160//
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.
166//
167
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;
173 }
174
175 return &fIndex[icharge][type];
176}
177
178//_____________________________________________________________________________
179TArrayI* AliRsnPIDIndex::GetCharged (Char_t sign)
180{
181//
182// Returns the array of indexes of tracks whose charge
183// corresponds to the passed argument
184// Otherwise returns a null pointer.
185//
186
187 // check that argument is meaningful
188 Int_t icharge = ChargeIndex (sign);
189 if (icharge < 0) return (TArrayI *)0x0;
190
191 // count total number of tracks with that charge
192 // and create output object of appropriate size
193 Int_t i, total = 0;
194 for (i = 0; i <= AliRsnPID::kSpecies; i++) total += fIndex[icharge][i].GetSize();
195 TArrayI *output = new TArrayI(total);
196
197 // add all indexes
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++);
202 }
203 }
204
205 return output;
206}
207
208//_____________________________________________________________________________
209Int_t AliRsnPIDIndex::ChargeIndex (Char_t sign) const
210{
211//
212// Returns the array index corresponding to charge
213//
214
215 if (sign == '+') return 0;
216 else if (sign == '-') return 1;
217 else {
218 AliError (Form ("Character '%c' not recognized as charge sign", sign));
219 return -1;
220 }
221}