]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCkineGrid.cxx
Moved from AliTransbit to AliL3Transbit.
[u/mrichter/AliRoot.git] / TPC / AliTPCkineGrid.cxx
CommitLineData
33049b0a 1/**************************************************************************
2 * Copyright(c) 2001-2002, 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$Log$
18*/
19
20////////////////////////////////////////////////////////////////////////
21// Class used by TPC tracking parameterization to handle to tracking
22// parameters (efficiencies, etc...) on a kinematic grid [pt,eta].
23// User has to provide the grid steps and the values of the parameter
24// in the points of the grid. The function GetValueAt(pt,eta) returns
25// the result of a linear interpolation at the point [pt,eta].
26//
27// Origin: Andrea Dainese, Padova - e-mail: andrea.dainese@pd.infn.it
28////////////////////////////////////////////////////////////////////////
29
30#include <iostream.h>
31#include <TMatrixD.h>
32#include <TArrayD.h>
33#include "AliTPCkineGrid.h"
34
35ClassImp(AliTPCkineGrid)
36
37//------------------------------------------------------------------------
38AliTPCkineGrid::AliTPCkineGrid() {
39//------------------------------------------------------------------------
40// Default constructor
41//------------------------------------------------------------------------
42 fNpt = 0;
43 fNeta = 0;
44 fPt = 0;
45 fEta = 0;
46 fParams = 0;
47}
48//------------------------------------------------------------------------
49AliTPCkineGrid::AliTPCkineGrid(Int_t npt,Int_t neta,
50 Double_t* pt,Double_t* eta) {
51//------------------------------------------------------------------------
52// Standard constructor
53//------------------------------------------------------------------------
54 fNpt = npt;
55 fNeta = neta;
56
57 fPt = new TArrayD(fNpt);
58 fEta = new TArrayD(fNeta);
59
60 for(Int_t i=0; i<npt; i++) (*fPt)[i] = pt[i];
61 for(Int_t i=0; i<neta; i++) (*fEta)[i] = eta[i];
62
63 fParams = new TMatrixD(fNpt,fNeta);
64}
65//-------------------------------------------------------------------------
66AliTPCkineGrid::AliTPCkineGrid(const AliTPCkineGrid& grid) {
67//-------------------------------------------------------------------------
68// Copy constructor
69//-------------------------------------------------------------------------
70 fNpt = grid.fNpt;
71 fNeta = grid.fNeta;
72 fPt = new TArrayD(fNpt);
73 for(Int_t i=0; i<fNpt; i++) (*fPt)[i] = grid.fPt->At(i);
74 fEta = new TArrayD(fNeta);
75 for(Int_t i=0; i<fNeta; i++) (*fEta)[i] = grid.fEta->At(i);
76
77 fParams = new TMatrixD(fNpt,fNeta);
78 for(Int_t i=0; i<fNpt; i++) {
79 for(Int_t j=0; j<fNeta; j++) (*fParams)(i,j)=(*grid.fParams)(i,j);
80 }
81}
82//--------------------------------------------------------------------------
83AliTPCkineGrid::~AliTPCkineGrid() {
84//--------------------------------------------------------------------------
85// Destructor
86//--------------------------------------------------------------------------
87 delete fPt;
88 delete fEta;
89 delete fParams;
90}
91//--------------------------------------------------------------------------
92void AliTPCkineGrid::GetArrayEta(Double_t* eta) const {
93//--------------------------------------------------------------------------
94// This functions returns an array with the eta points
95//--------------------------------------------------------------------------
96 for(Int_t i=0;i<fNeta;i++) eta[i] = fEta->At(i);
97 return;
98}
99//--------------------------------------------------------------------------
100void AliTPCkineGrid::GetArrayPt(Double_t* pt) const {
101//--------------------------------------------------------------------------
102// This functions returns an array with the pt points
103//--------------------------------------------------------------------------
104 for(Int_t i=0;i<fNpt;i++) pt[i] = fPt->At(i);
105 return;
106}
107//--------------------------------------------------------------------------
108Int_t AliTPCkineGrid::GetBin(Double_t pt,Double_t eta) const {
109//--------------------------------------------------------------------------
110// This functions tells in which bin of the grid a certain point falls
111//--------------------------------------------------------------------------
112
113 Int_t etaBin=0,ptBin=0,bin=0;
114 eta = TMath::Abs(eta);
115
116 /* this is how bins are numbered
117
118 ... ... .
119 ---+---+---
120 ^ 6 | 7 | 8
121 | ---+---+---
122 3 | 4 | 5
123 Pt ---+---+---
124 0 | 1 | 2
125
126 eta ->
127 */
128
129 if(eta < fEta->At(0)) {
130 etaBin = 0;
131 } else if(eta > fEta->At(fNeta-1)) {
132 etaBin = fNeta;
133 } else {
134 for(Int_t i=0; i<fNeta; i++) {
135 if(eta < fEta->At(i)) {
136 etaBin = i;
137 break;
138 }
139 }
140 }
141 if(pt < fPt->At(0)) {
142 ptBin = 0;
143 } else if(pt > fPt->At(fNpt-1)) {
144 ptBin = fNpt;
145 } else {
146 for(Int_t i=0; i<fNpt; i++) {
147 if(pt < fPt->At(i)) {
148 ptBin = i;
149 break;
150 }
151 }
152 }
153
154 bin = ptBin*(fNeta+1) + etaBin;
155
156 return bin;
157}
158//--------------------------------------------------------------------------
159Double_t AliTPCkineGrid::GetParam(Int_t i) const {
160//--------------------------------------------------------------------------
161// This functions allows to get parameters using only one index
162//--------------------------------------------------------------------------
163 Int_t ipt = (Int_t)i/fNeta;
164 Int_t ieta = i-ipt*fNeta;
165 return GetParam(ipt,ieta);
166}
167//--------------------------------------------------------------------------
168Double_t AliTPCkineGrid::GetValueAt(Double_t pt,Double_t eta) const {
169//--------------------------------------------------------------------------
170// This functions makes a linear interpolation at the point [pt,eta]
171//--------------------------------------------------------------------------
172
173 // determine the points to be used in the interpolation:
174 //
175 // eta
176 eta = TMath::Abs(eta);
177 Int_t etaLow=0,etaUp=0;
178 if(eta < fEta->At(0)) {
179 etaLow = 0;
180 etaUp = 1;
181 } else if(eta >= fEta->At(fNeta-1)) {
182 etaLow = fNeta-2;
183 etaUp = fNeta-1;
184 } else {
185 for(Int_t i=0; i<fNeta; i++) {
186 if(eta < fEta->At(i)) {
187 etaLow = i-1;
188 etaUp = i;
189 break;
190 }
191 }
192 }
193 //
194 // pt
195 Int_t ptLow=0,ptUp=0;
196 if(pt < fPt->At(0)) {
197 ptLow = 0;
198 ptUp = 1;
199 } else if(pt >= fPt->At(fNpt-1)) {
200 ptLow = fNpt-2;
201 ptUp = fNpt-1;
202 } else {
203 for(Int_t i=0; i<fNpt; i++) {
204 if(pt < fPt->At(i)) {
205 ptLow = i-1;
206 ptUp = i;
207 break;
208 }
209 }
210 }
211
212 //cerr<<" Pt = ("<<ptLow<<","<<ptUp<<") Eta = ("<<etaLow<<","<<etaUp<<")\n";
213
214 Double_t intValue=0,intValueEtaLow=0,intValueEtaUp=0;
215 // interpolate, at etaLow, between ptLow and ptUp
216 intValueEtaLow = (*fParams)(ptLow,etaLow)+
217 ((*fParams)(ptUp,etaLow)-(*fParams)(ptLow,etaLow))/
218 (fPt->At(ptUp)-fPt->At(ptLow))*(pt-fPt->At(ptLow));
219 // interpolate, at etaUp, between ptLow and ptUp
220 intValueEtaUp = (*fParams)(ptLow,etaUp)+
221 ((*fParams)(ptUp,etaUp)-(*fParams)(ptLow,etaUp))/
222 (fPt->At(ptUp)-fPt->At(ptLow))*(pt-fPt->At(ptLow));
223 // interpolate, at pt, between etaLow and etaUp
224 intValue = intValueEtaLow+
225 (intValueEtaUp-intValueEtaLow)/
226 (fEta->At(etaUp)-fEta->At(etaLow))*(eta-fEta->At(etaLow));
227
228 if(intValue<0.) intValue=0.;
229 return intValue;
230}
231//--------------------------------------------------------------------------
232void AliTPCkineGrid::SetParam(Int_t i,Double_t par) {
233//--------------------------------------------------------------------------
234// This functions allows to set parameters using only one index
235//--------------------------------------------------------------------------
236 Int_t ipt = (Int_t)i/fNeta;
237 Int_t ieta = i-ipt*fNeta;
238 SetParam(ipt,ieta,par);
239
240 return;
241}
242
243
244
245
246
247
248
249
250
251
252
253
254
255