]> git.uio.no Git - u/mrichter/AliRoot.git/blame - TPC/AliTPCRF1D.cxx
Bug fix
[u/mrichter/AliRoot.git] / TPC / AliTPCRF1D.cxx
CommitLineData
4c039060 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
88cb7938 16/* $Id$ */
19364939 17
4c039060 18
8c555625 19//-----------------------------------------------------------------------------
73042f01 20//
8c555625 21//
22//
23// Origin: Marian Ivanov, Uni. of Bratislava, ivanov@fmph.uniba.sk
24//
25// Declaration of class AliTPCRF1D
26//
27//-----------------------------------------------------------------------------
cc80f89e 28
73042f01 29//
30
19364939 31#include <Riostream.h>
a1e17193 32#include <TCanvas.h>
33#include <TClass.h>
34#include <TF2.h>
35#include <TH1.h>
36#include <TMath.h>
37#include <TPad.h>
2a336e15 38#include <TString.h>
a1e17193 39#include <TStyle.h>
40
41#include "AliTPCRF1D.h"
8c555625 42
73042f01 43extern TStyle * gStyle;
44
45Int_t AliTPCRF1D::fgNRF=100; //default number of interpolation points
46Float_t AliTPCRF1D::fgRFDSTEP=0.01; //default step in cm
8c555625 47
48static Double_t funGauss(Double_t *x, Double_t * par)
49{
cc80f89e 50 //Gauss function -needde by the generic function object
8c555625 51 return TMath::Exp(-(x[0]*x[0])/(2*par[0]*par[0]));
52}
53
54static Double_t funCosh(Double_t *x, Double_t * par)
55{
cc80f89e 56 //Cosh function -needde by the generic function object
8c555625 57 return 1/TMath::CosH(3.14159*x[0]/(2*par[0]));
58}
59
60static Double_t funGati(Double_t *x, Double_t * par)
61{
cc80f89e 62 //Gati function -needde by the generic function object
73042f01 63 Float_t k3=par[1];
64 Float_t k3R=TMath::Sqrt(k3);
65 Float_t k2=(TMath::Pi()/2)*(1-k3R/2.);
66 Float_t k1=k2*k3R/(4*TMath::ATan(k3R));
8c555625 67 Float_t l=x[0]/par[0];
73042f01 68 Float_t tan2=TMath::TanH(k2*l);
8c555625 69 tan2*=tan2;
73042f01 70 Float_t res = k1*(1-tan2)/(1+k3*tan2);
8c555625 71 return res;
72}
73
8c555625 74///////////////////////////////////////////////////////////////////////////
75///////////////////////////////////////////////////////////////////////////
76
8c555625 77ClassImp(AliTPCRF1D)
78
79
80AliTPCRF1D::AliTPCRF1D(Bool_t direct,Int_t np,Float_t step)
179c6296 81 :TObject(),
82 fNRF(0),
83 fDSTEPM1(0.),
84 fcharge(0),
85 forigsigma(0.),
86 fpadWidth(3.5),
87 fkNorm(0.5),
88 fInteg(0.),
89 fGRF(0),
90 fSigma(0.),
91 fOffset(0.),
92 fDirect(kFALSE),
93 fPadDistance(0.)
8c555625 94{
cc80f89e 95 //default constructor for response function object
8c555625 96 fDirect=direct;
73042f01 97 if (np!=0)fNRF = np;
98 else (fNRF=fgNRF);
8c555625 99 fcharge = new Float_t[fNRF];
73042f01 100 if (step>0) fDSTEPM1=1./step;
101 else fDSTEPM1 = 1./fgRFDSTEP;
712976a6 102 for(Int_t i=0;i<5;i++) funParam[i]=0.;
8c555625 103}
104
179c6296 105AliTPCRF1D::AliTPCRF1D(const AliTPCRF1D &prf)
106 :TObject(prf),
107 fNRF(0),
108 fDSTEPM1(0.),
109 fcharge(0),
110 forigsigma(0.),
111 fpadWidth(3.5),
112 fkNorm(0.5),
113 fInteg(0.),
114 fGRF(0),
115 fSigma(0.),
116 fOffset(0.),
117 fDirect(kFALSE),
118 fPadDistance(0.)
73042f01 119{
176aff27 120
73042f01 121 //
122 memcpy(this, &prf, sizeof(prf));
123 fcharge = new Float_t[fNRF];
124 memcpy(fcharge,prf.fcharge, fNRF);
2a336e15 125 fGRF = new TF1(*(prf.fGRF));
126 //PH Change the name (add 0 to the end)
127 TString s(fGRF->GetName());
128 s+="0";
129 fGRF->SetName(s.Data());
712976a6 130 for(Int_t i=0;i<5;i++) funParam[i]=0.;
73042f01 131}
132
133AliTPCRF1D & AliTPCRF1D::operator = (const AliTPCRF1D &prf)
134{
135 //
136 if (fcharge) delete fcharge;
137 if (fGRF) delete fGRF;
138 memcpy(this, &prf, sizeof(prf));
139 fcharge = new Float_t[fNRF];
140 memcpy(fcharge,prf.fcharge, fNRF);
141 fGRF = new TF1(*(prf.fGRF));
2a336e15 142 //PH Change the name (add 0 to the end)
143 TString s(fGRF->GetName());
144 s+="0";
145 fGRF->SetName(s.Data());
73042f01 146 return (*this);
147}
148
149
8c555625 150
151AliTPCRF1D::~AliTPCRF1D()
152{
73042f01 153 //
cc80f89e 154 if (fcharge!=0) delete [] fcharge;
8c555625 155 if (fGRF !=0 ) fGRF->Delete();
156}
157
158Float_t AliTPCRF1D::GetRF(Float_t xin)
159{
cc80f89e 160 //function which return response
161 //for the charge in distance xin
8c555625 162 //return linear aproximation of RF
bfb1cfbd 163 Float_t x = (xin-fOffset)*fDSTEPM1+fNRF/2;
8c555625 164 Int_t i1=Int_t(x);
165 if (x<0) i1-=1;
166 Float_t res=0;
bfb1cfbd 167 if (i1+1<fNRF &&i1>0)
8c555625 168 res = fcharge[i1]*(Float_t(i1+1)-x)+fcharge[i1+1]*(x-Float_t(i1));
169 return res;
170}
171
172Float_t AliTPCRF1D::GetGRF(Float_t xin)
173{
cc80f89e 174 //function which returnoriginal charge distribution
175 //this function is just normalised for fKnorm
8c555625 176 if (fGRF != 0 )
177 return fkNorm*fGRF->Eval(xin)/fInteg;
178 else
179 return 0.;
180}
181
182
183void AliTPCRF1D::SetParam( TF1 * GRF,Float_t padwidth,
184 Float_t kNorm, Float_t sigma)
185{
cc80f89e 186 //adjust parameters of the original charge distribution
187 //and pad size parameters
8c555625 188 fpadWidth = padwidth;
189 fGRF = GRF;
190 fkNorm = kNorm;
191 if (sigma==0) sigma= fpadWidth/TMath::Sqrt(12.);
192 forigsigma=sigma;
193 fDSTEPM1 = 10/TMath::Sqrt(sigma*sigma+fpadWidth*fpadWidth/12);
194 sprintf(fType,"User");
195 // Update();
196}
197
198
199void AliTPCRF1D::SetGauss(Float_t sigma, Float_t padWidth,
200 Float_t kNorm)
201{
cc80f89e 202 //
203 // set parameters for Gauss generic charge distribution
204 //
8c555625 205 fpadWidth = padWidth;
206 fkNorm = kNorm;
207 if (fGRF !=0 ) fGRF->Delete();
2a336e15 208 fGRF = new TF1("funGauss",funGauss,-5,5,1);
8c555625 209 funParam[0]=sigma;
210 forigsigma=sigma;
211 fGRF->SetParameters(funParam);
212 fDSTEPM1 = 10./TMath::Sqrt(sigma*sigma+fpadWidth*fpadWidth/12);
cc80f89e 213 //by default I set the step as one tenth of sigma
8c555625 214 sprintf(fType,"Gauss");
215}
216
217void AliTPCRF1D::SetCosh(Float_t sigma, Float_t padWidth,
218 Float_t kNorm)
219{
cc80f89e 220 //
221 // set parameters for Cosh generic charge distribution
222 //
8c555625 223 fpadWidth = padWidth;
224 fkNorm = kNorm;
225 if (fGRF !=0 ) fGRF->Delete();
2a336e15 226 fGRF = new TF1("funCosh", funCosh, -5.,5.,2);
8c555625 227 funParam[0]=sigma;
228 fGRF->SetParameters(funParam);
229 forigsigma=sigma;
230 fDSTEPM1 = 10./TMath::Sqrt(sigma*sigma+fpadWidth*fpadWidth/12);
231 //by default I set the step as one tenth of sigma
8c555625 232 sprintf(fType,"Cosh");
233}
234
235void AliTPCRF1D::SetGati(Float_t K3, Float_t padDistance, Float_t padWidth,
236 Float_t kNorm)
237{
cc80f89e 238 //
239 // set parameters for Gati generic charge distribution
240 //
8c555625 241 fpadWidth = padWidth;
242 fkNorm = kNorm;
243 if (fGRF !=0 ) fGRF->Delete();
2a336e15 244 fGRF = new TF1("funGati", funGati, -5.,5.,2);
8c555625 245 funParam[0]=padDistance;
246 funParam[1]=K3;
247 fGRF->SetParameters(funParam);
248 forigsigma=padDistance;
249 fDSTEPM1 = 10./TMath::Sqrt(padDistance*padDistance+fpadWidth*fpadWidth/12);
250 //by default I set the step as one tenth of sigma
8c555625 251 sprintf(fType,"Gati");
252}
253
bfb1cfbd 254
255
73042f01 256void AliTPCRF1D::DrawRF(Float_t x1,Float_t x2,Int_t N)
8c555625 257{
cc80f89e 258 //
259 //Draw prf in selected region <x1,x2> with nuber of diviision = n
260 //
8c555625 261 char s[100];
262 TCanvas * c1 = new TCanvas("canRF","Pad response function",700,900);
263 c1->cd();
264 TPad * pad1 = new TPad("pad1RF","",0.05,0.55,0.95,0.95,21);
265 pad1->Draw();
266 TPad * pad2 = new TPad("pad2RF","",0.05,0.05,0.95,0.45,21);
267 pad2->Draw();
268
269 sprintf(s,"RF response function for %1.2f cm pad width",
270 fpadWidth);
271 pad1->cd();
272 TH1F * hRFo = new TH1F("hRFo","Original charge distribution",N+1,x1,x2);
273 pad2->cd();
274 gStyle->SetOptFit(1);
275 gStyle->SetOptStat(0);
276 TH1F * hRFc = new TH1F("hRFc",s,N+1,x1,x2);
277 Float_t x=x1;
278 Float_t y1;
279 Float_t y2;
280
281 for (Float_t i = 0;i<N+1;i++)
282 {
283 x+=(x2-x1)/Float_t(N);
284 y1 = GetRF(x);
285 hRFc->Fill(x,y1);
286 y2 = GetGRF(x);
287 hRFo->Fill(x,y2);
288 };
289 pad1->cd();
290 hRFo->Fit("gaus");
291 pad2->cd();
292 hRFc->Fit("gaus");
293}
294
295void AliTPCRF1D::Update()
296{
cc80f89e 297 //
298 //update fields with interpolated values for
299 //PRF calculation
300
301 //at the begining initialize to 0
8c555625 302 for (Int_t i =0; i<fNRF;i++) fcharge[i] = 0;
303 if ( fGRF == 0 ) return;
304 fInteg = fGRF->Integral(-5*forigsigma,5*forigsigma,funParam,0.00001);
305 if ( fInteg == 0 ) fInteg = 1;
306 if (fDirect==kFALSE){
307 //integrate charge over pad for different distance of pad
308 for (Int_t i =0; i<fNRF;i++)
309 { //x in cm fpadWidth in cm
310 Float_t x = (Float_t)(i-fNRF/2)/fDSTEPM1;
311 Float_t x1=TMath::Max(x-fpadWidth/2,-5*forigsigma);
312 Float_t x2=TMath::Min(x+fpadWidth/2,5*forigsigma);
313 fcharge[i] =
314 fkNorm*fGRF->Integral(x1,x2,funParam,0.0001)/fInteg;
315 };
316 }
317 else{
318 for (Int_t i =0; i<fNRF;i++)
319 { //x in cm fpadWidth in cm
320 Float_t x = (Float_t)(i-fNRF/2)/fDSTEPM1;
321 fcharge[i] = fkNorm*fGRF->Eval(x);
322 };
323 }
324 fSigma = 0;
325 Float_t sum =0;
326 Float_t mean=0;
327 for (Float_t x =-fNRF/fDSTEPM1; x<fNRF/fDSTEPM1;x+=1/fDSTEPM1)
328 { //x in cm fpadWidth in cm
329 Float_t weight = GetRF(x+fOffset);
330 fSigma+=x*x*weight;
331 mean+=x*weight;
332 sum+=weight;
333 };
334 if (sum>0){
335 mean/=sum;
336 fSigma = TMath::Sqrt(fSigma/sum-mean*mean);
337 }
338 else fSigma=0;
339}
340
341void AliTPCRF1D::Streamer(TBuffer &R__b)
342{
cc80f89e 343 // Stream an object of class AliTPCRF1D.
8c555625 344 if (R__b.IsReading()) {
2ab0c725 345 AliTPCRF1D::Class()->ReadBuffer(R__b, this);
8c555625 346 //read functions
8c555625 347
2a336e15 348 if (strncmp(fType,"Gauss",3)==0) {delete fGRF; fGRF = new TF1("funGauss",funGauss,-5.,5.,4);}
349 if (strncmp(fType,"Cosh",3)==0) {delete fGRF; fGRF = new TF1("funCosh",funCosh,-5.,5.,4);}
350 if (strncmp(fType,"Gati",3)==0) {delete fGRF; fGRF = new TF1("funGati",funGati,-5.,5.,4);}
2ab0c725 351 if (fGRF) fGRF->SetParameters(funParam);
8c555625 352
353 } else {
2ab0c725 354 AliTPCRF1D::Class()->WriteBuffer(R__b, this);
8c555625 355 }
356}
bfb1cfbd 357
358
359Double_t AliTPCRF1D::Gamma4(Double_t x, Double_t p0, Double_t p1){
360 //
361 // Gamma 4 Time response function of ALTRO
362 //
363 if (x<0) return 0;
364 Double_t g1 = TMath::Exp(-4.*x/p1);
365 Double_t g2 = TMath::Power(x/p1,4);
366 return p0*g1*g2;
367}
8c555625 368