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