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