Some small corrections
[u/mrichter/AliRoot.git] / FASTSIM / AliMUONFastTracking.cxx
CommitLineData
6255180c 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
d53fc881 16/*
17$Log$
e6e76983 18Revision 1.10 2006/01/27 09:51:37 morsch
19Some small corrections to avoid infinite loops at high momenta.
20(A. de Falco)
21
9a226b7e 22Revision 1.9 2004/02/03 16:45:20 morsch
23Unique name for functions (TF1).
24
c6ba3ff4 25Revision 1.8 2004/01/27 18:02:38 hristov
26Removing some warning (Sun)
27
15a060e4 28Revision 1.7 2003/11/13 14:21:57 morsch
29Coding Rule violation corrections.
30
041f7f97 31Revision 1.6 2003/08/12 15:16:25 morsch
32Saver initialisation of fFitp array. (Lenaic COUEDEL)
33
1e68a0c5 34Revision 1.5 2003/08/05 16:14:20 morsch
35Some problems with too big fluctuations corrected. (A. de Falco)
36
d53fc881 37Revision 1.2 2003/01/08 10:29:33 morsch
38Path to data file changed.
39
40Revision 1.1 2003/01/06 10:13:33 morsch
41First commit.
42
43*/
6255180c 44
041f7f97 45//-------------------------------------------------------------------------
46// Class AliMUONFastTracking
47//
48// Manager for the fast simulation of tracking in the muon spectrometer
49// This class reads the lookup tables containing the parameterization
50// of the deltap, deltatheta, deltaphi for different background levels
51// and provides the related smeared parameters.
52// Used by AliFastMuonTrackingEff, AliFastMuonTrackingAcc,
53// AliFastMuonTrackingRes.
54//-------------------------------------------------------------------------
55
6255180c 56#include "AliMUONFastTracking.h"
57#include "AliMUONFastTrackingEntry.h"
6255180c 58#include <TSpline.h>
59#include <TFile.h>
6255180c 60#include <TH3.h>
61#include <TF1.h>
62#include <TRandom.h>
63#include <stdlib.h>
64#include <stdio.h>
65#include <string.h>
66#include <Riostream.h>
67
68ClassImp(AliMUONFastTracking)
69
041f7f97 70
6255180c 71AliMUONFastTracking* AliMUONFastTracking::fgMUONFastTracking=NULL;
72
73static Double_t FitP(Double_t *x, Double_t *par){
74 Double_t dx = x[0] - par[0];
75 Double_t dx2 = x[0] - par[4];
76 Double_t sigma = par[1] * ( 1 + par[2] * dx);
77 if (sigma == 0) {
78
79 return 0.;
80 }
81 Double_t fasymm = TMath::Exp(-0.5 * dx * dx / (sigma * sigma));
82 Double_t sigma2 = par[1] * par[5];
83 Double_t fgauss = TMath::Exp(-0.5 * dx2 * dx2 / (sigma2 * sigma2));
d53fc881 84 Double_t value = fasymm + par[3] * fgauss;
9a226b7e 85 return TMath::Abs(value);
6255180c 86}
87
4ef9f58b 88AliMUONFastTracking::AliMUONFastTracking(const AliMUONFastTracking & ft):TObject()
041f7f97 89{
90// Copy constructor
91 ft.Copy(*this);
92}
93
94
6255180c 95AliMUONFastTracking* AliMUONFastTracking::Instance()
96{
97// Set random number generator
98 if (fgMUONFastTracking) {
99 return fgMUONFastTracking;
100 } else {
101 fgMUONFastTracking = new AliMUONFastTracking();
102 return fgMUONFastTracking;
103 }
104}
105
4ef9f58b 106AliMUONFastTracking::AliMUONFastTracking()
6255180c 107{
041f7f97 108//
109// constructor
110//
1e68a0c5 111 for (Int_t i = 0; i<20;i++) {
112 for (Int_t j = 0; j<20; j++) {
113 for (Int_t k = 0; k<20; k++) {
114 fFitp[i][j][k] = 0x0;
115 }
116 }
117 }
118
d53fc881 119 fClusterFinder = kOld;
6255180c 120 fPrintLevel = 1;
121 // read binning; temporarily put by hand
122 Float_t pmin = 0, pmax = 200;
123 Int_t nbinp = 10;
124 Float_t thetamin = 2, thetamax = 9;
125 Int_t nbintheta=10;
126 Float_t phimin = -180, phimax =180;
127 Int_t nbinphi=10;
128 //--------------------------------------
129
130 fNbinp = nbinp;
131 fPmin = pmin;
132 fPmax = pmax;
133
134 fNbintheta = nbintheta;
135 fThetamin = thetamin;
136 fThetamax = thetamax;
137
138 fNbinphi = nbinphi;
139 fPhimin = phimin;
140 fPhimax = phimax;
141
142 fDeltaP = (fPmax-fPmin)/fNbinp;
143 fDeltaTheta = (fThetamax-fThetamin)/fNbintheta;
144 fDeltaPhi = (fPhimax-fPhimin)/fNbinphi;
145}
146
147void AliMUONFastTracking::Init(Float_t bkg)
148{
149 //
150 // Initialization
151 //
152 for (Int_t ip=0; ip< fNbinp; ip++){
153 for (Int_t itheta=0; itheta< fNbintheta; itheta++){
154 for (Int_t iphi=0; iphi< fNbinphi; iphi++){
155 fCurrentEntry[ip][itheta][iphi] = new AliMUONFastTrackingEntry;
156 for (Int_t ibkg=0; ibkg<4; ibkg++){
157 fEntry[ip][itheta][iphi][ibkg] = new AliMUONFastTrackingEntry;
158 }
159 }
160 }
161 }
162
163 char filename [100];
d53fc881 164 if (fClusterFinder==kOld) sprintf (filename,"$(ALICE_ROOT)/FASTSIM/data/MUONtrackLUT.root");
041f7f97 165 else sprintf (filename,"$(ALICE_ROOT)/FASTSIM/data/MUONtrackLUT-AZ.root");
d53fc881 166
6255180c 167 TFile *file = new TFile(filename);
168 ReadLUT(file);
169 SetBackground(bkg);
d53fc881 170 UseSpline(0);
6255180c 171}
172
173
174void AliMUONFastTracking::ReadLUT(TFile* file)
175{
041f7f97 176 //
177 // read the lookup tables from file
178 //
6255180c 179 TH3F *heff[5][3], *hacc[5][3], *hmeanp, *hsigmap, *hsigma1p, *hchi2p;
180 TH3F *hnormg2, *hmeang2, *hsigmag2, *hmeantheta, *hsigmatheta, *hchi2theta;
181 TH3F *hmeanphi, *hsigmaphi, *hchi2phi;
182 char tag[40], tag2[40];
183
d53fc881 184 printf ("Reading parameters from LUT file %s...\n",file->GetName());
185
041f7f97 186 const Float_t kBkg[4] = {0, 0.5, 1, 2};
6255180c 187 for (Int_t ibkg=0; ibkg<4; ibkg++) {
041f7f97 188 sprintf (tag,"BKG%g",kBkg[ibkg]);
6255180c 189 file->cd(tag);
190 for (Int_t isplp = 0; isplp<kSplitP; isplp++) {
191 for (Int_t ispltheta = 0; ispltheta<kSplitTheta; ispltheta++) {
192 sprintf (tag2,"heff[%d][%d]",isplp,ispltheta);
193 heff[isplp][ispltheta] = (TH3F*)gDirectory->Get(tag2);
194 sprintf (tag2,"hacc[%d][%d]",isplp,ispltheta);
195 hacc[isplp][ispltheta] = (TH3F*)gDirectory->Get(tag2);
196 }
197 }
198 hmeanp = (TH3F*)gDirectory->Get("hmeanp");
199 hsigmap = (TH3F*)gDirectory->Get("hsigmap");
200 hsigma1p = (TH3F*)gDirectory->Get("hsigma1p");
201 hchi2p = (TH3F*)gDirectory->Get("hchi2p");
202 hnormg2 = (TH3F*)gDirectory->Get("hnormg2");
203 hmeang2 = (TH3F*)gDirectory->Get("hmeang2");
204 hsigmag2 = (TH3F*)gDirectory->Get("hsigmag2");
205 hmeantheta = (TH3F*)gDirectory->Get("hmeantheta");
206 hsigmatheta = (TH3F*)gDirectory->Get("hsigmatheta");
207 hchi2theta = (TH3F*)gDirectory->Get("hchi2theta");
208 hmeanphi = (TH3F*)gDirectory->Get("hmeanphi");
209 hsigmaphi = (TH3F*)gDirectory->Get("hsigmaphi");
210 hchi2phi = (TH3F*)gDirectory->Get("hchi2phi");
211
6255180c 212 for (Int_t ip=0; ip<fNbinp ;ip++) {
213 for (Int_t itheta=0; itheta<fNbintheta ;itheta++) {
214 for (Int_t iphi=0; iphi<fNbinphi ;iphi++) {
215 Float_t p = fPmin + fDeltaP * (ip + 0.5);
216 Float_t theta = fThetamin + fDeltaTheta * (itheta + 0.5);
217 Float_t phi = fPhimin + fDeltaPhi * (iphi + 0.5);
218
4ef9f58b 219 fEntry[ip][itheta][iphi][ibkg]->SetP(p);
220 fEntry[ip][itheta][iphi][ibkg]->SetMeanp(hmeanp->GetBinContent(ip+1,itheta+1,iphi+1));
221 fEntry[ip][itheta][iphi][ibkg]->SetSigmap(TMath::Abs(hsigmap->GetBinContent(ip+1,itheta+1,iphi+1)));
222 fEntry[ip][itheta][iphi][ibkg]->SetSigma1p(hsigma1p->GetBinContent(ip+1,itheta+1,iphi+1));
223 fEntry[ip][itheta][iphi][ibkg]->SetChi2p(hchi2p->GetBinContent(ip+1,itheta+1,iphi+1));
224 fEntry[ip][itheta][iphi][ibkg]->SetNormG2(hnormg2->GetBinContent(ip+1,itheta+1,iphi+1));
225 fEntry[ip][itheta][iphi][ibkg]->SetMeanG2(hmeang2->GetBinContent(ip+1,itheta+1,iphi+1));
226 if (ibkg == 0) fEntry[ip][itheta][iphi][ibkg]->SetSigmaG2(9999);
227 else fEntry[ip][itheta][iphi][ibkg]->SetSigmaG2(hsigmag2->GetBinContent(ip+1,itheta+1,iphi+1));
228 fEntry[ip][itheta][iphi][ibkg]->SetTheta(theta);
229 fEntry[ip][itheta][iphi][ibkg]->SetMeantheta(hmeantheta->GetBinContent(ip+1,itheta+1,iphi+1));
230 fEntry[ip][itheta][iphi][ibkg]->SetSigmatheta(TMath::Abs(hsigmatheta->GetBinContent(ip+1,itheta+1,iphi+1)));
231 fEntry[ip][itheta][iphi][ibkg]->SetChi2theta(hchi2theta->GetBinContent(ip+1,itheta+1,iphi+1));
232 fEntry[ip][itheta][iphi][ibkg]->SetPhi(phi);
233 fEntry[ip][itheta][iphi][ibkg]->SetMeanphi(hmeanphi->GetBinContent(ip+1,itheta+1,iphi+1));
234 fEntry[ip][itheta][iphi][ibkg]->SetSigmaphi(TMath::Abs(hsigmaphi->GetBinContent(ip+1,itheta+1,iphi+1)));
235 fEntry[ip][itheta][iphi][ibkg]->SetChi2phi(hchi2phi->GetBinContent(ip+1,itheta+1,iphi+1));
6255180c 236 for (Int_t i=0; i<kSplitP; i++) {
237 for (Int_t j=0; j<kSplitTheta; j++) {
4ef9f58b 238 fEntry[ip][itheta][iphi][ibkg]->SetAcc(i,j,hacc[i][j]->GetBinContent(ip+1,itheta+1,iphi+1));
239 fEntry[ip][itheta][iphi][ibkg]->SetEff(i,j,heff[i][j]->GetBinContent(ip+1,itheta+1,iphi+1));
6255180c 240 }
241 }
242 } // iphi
243 } // itheta
244 } // ip
245 } // ibkg
246
247 TGraph *graph = new TGraph(3);
248 TF1 *f = new TF1("f","[0]+[1]*x");
249
250 for (Int_t ip=0; ip< fNbinp; ip++){
251 for (Int_t itheta=0; itheta< fNbintheta; itheta++){
252 for (Int_t iphi=0; iphi< fNbinphi; iphi++){
4ef9f58b 253 graph->SetPoint(0,0.5,fEntry[ip][itheta][iphi][1]->GetSigmaG2());
254 graph->SetPoint(1,1,fEntry[ip][itheta][iphi][2]->GetSigmaG2());
255 graph->SetPoint(2,2,fEntry[ip][itheta][iphi][3]->GetSigmaG2());
6255180c 256 graph->Fit("f","q");
4ef9f58b 257 fEntry[ip][itheta][iphi][0]->SetSigmaG2(f->Eval(0));
6255180c 258 }
259 }
260 }
261 f->Delete();
262 graph->Delete();
263 printf ("parameters read. \n");
264}
265
266void AliMUONFastTracking::GetBinning(Int_t &nbinp, Float_t &pmin, Float_t &pmax,
267 Int_t &nbintheta, Float_t &thetamin,
268 Float_t &thetamax,
041f7f97 269 Int_t &nbinphi, Float_t &phimin, Float_t &phimax) const
6255180c 270{
041f7f97 271 //
272 // gets the binning for the discrete parametrizations in the lookup table
273 //
6255180c 274 nbinp = fNbinp;
275 pmin = fPmin;
276 pmax = fPmax;
277 nbintheta = fNbintheta;
278 thetamin = fThetamin;
279 thetamax = fThetamax;
280 nbinphi = fNbinphi;
281 phimin = fPhimin;
282 phimax = fPhimax;
283}
284
285
286void AliMUONFastTracking::GetIpIthetaIphi(Float_t p, Float_t theta, Float_t phi,
287 Int_t charge, Int_t &ip, Int_t &itheta,
041f7f97 288 Int_t &iphi) const
6255180c 289{
041f7f97 290 //
291 // gets the id of the cells in the LUT for a given (p,theta,phi, charge)
292 //
6255180c 293 if (charge < 0) phi = -phi;
294 ip = Int_t (( p - fPmin ) / fDeltaP);
295 itheta = Int_t (( theta - fThetamin ) / fDeltaTheta);
296 iphi = Int_t (( phi - fPhimin ) / fDeltaPhi);
297
1e68a0c5 298
d53fc881 299 if (ip< 0) ip = 0;
300 if (ip>= fNbinp) ip = fNbinp-1;
301 if (itheta< 0) itheta = 0;
302 if (itheta>= fNbintheta) itheta = fNbintheta-1;
6255180c 303
d53fc881 304 if (iphi< 0) iphi = 0;
305 if (iphi>= fNbinphi) iphi = fNbinphi-1;
6255180c 306}
307
308void AliMUONFastTracking::GetSplit(Int_t ip, Int_t itheta,
041f7f97 309 Int_t &nSplitP, Int_t &nSplitTheta) const
310{
311 //
312 // the first cell is splitted in more bins for theta and momentum
313 // parameterizations. Get the number of divisions for the splitted bins
314 //
6255180c 315 if (ip==0) nSplitP = 5;
316 else nSplitP = 2;
317 if (itheta==0) nSplitTheta = 3;
318 else nSplitTheta = 1;
319}
320
321Float_t AliMUONFastTracking::Efficiency(Float_t p, Float_t theta,
322 Float_t phi, Int_t charge){
041f7f97 323 //
324 // gets the tracking efficiency
325 //
6255180c 326 Int_t ip=0, itheta=0, iphi=0;
327 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
328 Int_t nSplitP, nSplitTheta;
329 GetSplit(ip,itheta,nSplitP,nSplitTheta);
330
331 Float_t dp = p - fPmin;
332 Int_t ibinp = Int_t(nSplitP*(dp - fDeltaP * Int_t(dp / fDeltaP))/fDeltaP);
333 Float_t dtheta = theta - fThetamin;
334 Int_t ibintheta = Int_t(nSplitTheta*(dtheta - fDeltaTheta * Int_t(dtheta / fDeltaTheta))/fDeltaTheta);
4ef9f58b 335 Float_t eff = fCurrentEntry[ip][itheta][iphi]->GetEff(ibinp,ibintheta);
6255180c 336 return eff;
337}
338
339Float_t AliMUONFastTracking::Acceptance(Float_t p, Float_t theta,
340 Float_t phi, Int_t charge){
041f7f97 341 //
342 // gets the geometrical acceptance
343 //
6255180c 344 if (theta<fThetamin || theta>fThetamax) return 0;
345
346 Int_t ip=0, itheta=0, iphi=0;
347 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
348 Int_t nSplitP, nSplitTheta;
349 GetSplit(ip,itheta,nSplitP,nSplitTheta);
350 // central value and corrections with spline
351
352 Float_t dp = p - fPmin;
353 Int_t ibinp = Int_t(nSplitP*(dp - fDeltaP * Int_t(dp / fDeltaP))/fDeltaP);
354 Float_t dtheta = theta - fThetamin;
355 Int_t ibintheta = Int_t(nSplitTheta*(dtheta - fDeltaTheta * Int_t(dtheta / fDeltaTheta))/fDeltaTheta);
4ef9f58b 356 Float_t acc = fCurrentEntry[ip][itheta][iphi]->GetAcc(ibinp,ibintheta);
6255180c 357 return acc;
358}
359
360Float_t AliMUONFastTracking::MeanP(Float_t p, Float_t theta,
041f7f97 361 Float_t phi, Int_t charge) const
6255180c 362{
041f7f97 363 //
364 // gets the mean value of the prec-pgen distribution
365 //
6255180c 366 Int_t ip=0, itheta=0, iphi=0;
367 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
4ef9f58b 368 return fCurrentEntry[ip][itheta][iphi]->GetMeanp();
6255180c 369}
370
371Float_t AliMUONFastTracking::SigmaP(Float_t p, Float_t theta,
041f7f97 372 Float_t phi, Int_t charge) const
6255180c 373{
041f7f97 374 //
375 // gets the width of the prec-pgen distribution
376 //
6255180c 377 Int_t ip=0, itheta=0, iphi=0;
378 Int_t index;
379 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
380 // central value and corrections with spline
4ef9f58b 381 Float_t sigmap = fCurrentEntry[ip][itheta][iphi]->GetSigmap();
6255180c 382 if (!fSpline) return sigmap;
383 // corrections vs p, theta, phi
384 index = iphi + fNbinphi * itheta;
385 Double_t xmin,ymin,xmax,ymax;
386 Float_t frac1 = fSplineSigmap[index][0]->Eval(p)/sigmap;
387
388 if (p>fPmax-fDeltaP/2.) {
4ef9f58b 389 Float_t s1 = fCurrentEntry[fNbinp-1][itheta][iphi]->GetSigmap();
390 Float_t s2 = fCurrentEntry[fNbinp-2][itheta][iphi]->GetSigmap();
391 Float_t s3 = fCurrentEntry[fNbinp-3][itheta][iphi]->GetSigmap();
6255180c 392 Float_t p1 = fDeltaP * (fNbinp - 1 + 0.5) + fPmin;
393 Float_t p2 = fDeltaP * (fNbinp - 2 + 0.5) + fPmin;
394 Float_t p3 = fDeltaP * (fNbinp - 3 + 0.5) + fPmin;
395 Float_t p12 = p1 * p1, p22 = p2 * p2, p32 = p3 * p3;
396 Float_t d = p12*p2 + p1*p32 + p22*p3 - p32*p2 - p3*p12 - p22*p1;
397 Float_t a = (s1*p2 + p1*s3 + s2*p3 - s3*p2 - p3*s1 - s2*p1) / d;
398 Float_t b = (p12*s2 + s1*p32 + p22*s3 - p32*s2 - s3*p12 - p22*s1)/d;
399 Float_t c = (p12*p2*s3 + p1*p32*s2 + p22*p3*s1
400 - p32*p2*s1 - p3*p12*s2 - p22*p1*s3) / d;
401 Float_t sigma = a * p * p + b * p + c;
402 frac1 = sigma/sigmap;
403 }
404 index = iphi + fNbinphi * ip;
405 fSplineEff[index][1]->GetKnot(0,xmin,ymin);
406 fSplineEff[index][1]->GetKnot(9,xmax,ymax);
407 if (theta>xmax) theta = xmax;
408 Float_t frac2 = fSplineSigmap[index][1]->Eval(theta)/sigmap;
409 index = itheta + fNbintheta * ip;
410 fSplineEff[index][2]->GetKnot(0,xmin,ymin);
411 fSplineEff[index][2]->GetKnot(9,xmax,ymax);
412 if (phi>xmax) phi = xmax;
413 Float_t frac3 = fSplineSigmap[index][2]->Eval(phi)/sigmap;
414 Float_t sigmatot = sigmap * frac1 * frac2 * frac3;
415 if (sigmatot<0) sigmatot = sigmap;
416 return sigmatot;
417}
418
419Float_t AliMUONFastTracking::Sigma1P(Float_t p, Float_t theta,
041f7f97 420 Float_t phi, Int_t charge) const
6255180c 421{
041f7f97 422 //
423 // gets the width correction of the prec-pgen distribution (see FitP)
424 //
6255180c 425 Int_t ip=0, itheta=0, iphi=0;
426 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
427 if (p>fPmax) {
428 // linear extrapolation of sigmap for p out of range
4ef9f58b 429 Float_t s1 = fCurrentEntry[fNbinp-1][itheta][iphi]->GetSigma1p();
430 Float_t s2 = fCurrentEntry[fNbinp-2][itheta][iphi]->GetSigma1p();
6255180c 431 Float_t p1 = fDeltaP * (fNbinp - 1 + 0.5) + fPmin;
432 Float_t p2 = fDeltaP * (fNbinp - 2 + 0.5) + fPmin;
433 Float_t sigma = 1./(p1-p2) * ( (s1-s2)*p + (s2-s1)*p1 + s1*(p1-p2) );
434 return sigma;
435 }
4ef9f58b 436 else return fCurrentEntry[ip][itheta][iphi]->GetSigma1p();
6255180c 437}
438
439Float_t AliMUONFastTracking::NormG2(Float_t p, Float_t theta,
041f7f97 440 Float_t phi, Int_t charge) const
6255180c 441{
041f7f97 442 //
443 // gets the relative normalization of the background
444 // (gaussian) component in the prec-pgen distribution
445 //
6255180c 446 Int_t ip=0, itheta=0, iphi=0;
447 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
448 if (p>fPmax) {
449 // linear extrapolation of sigmap for p out of range
4ef9f58b 450 Float_t s1 = fCurrentEntry[fNbinp-1][itheta][iphi]->GetNormG2();
451 Float_t s2 = fCurrentEntry[fNbinp-2][itheta][iphi]->GetNormG2();
6255180c 452 Float_t p1 = fDeltaP * (fNbinp - 1 + 0.5) + fPmin;
453 Float_t p2 = fDeltaP * (fNbinp - 2 + 0.5) + fPmin;
454 Float_t norm = 1./(p1-p2) * ( (s1-s2)*p + (s2-s1)*p1 + s1*(p1-p2) );
455 return norm;
456 }
4ef9f58b 457 else return fCurrentEntry[ip][itheta][iphi]->GetNormG2();
6255180c 458}
459
460Float_t AliMUONFastTracking::MeanG2(Float_t p, Float_t theta,
041f7f97 461 Float_t phi, Int_t charge) const
6255180c 462{
041f7f97 463 //
464 // gets the mean value of the background
465 // (gaussian) component in the prec-pgen distribution
466 //
6255180c 467 Int_t ip=0, itheta=0, iphi=0;
468 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
469 if (p>fPmax) {
470 // linear extrapolation of sigmap for p out of range
4ef9f58b 471 Float_t s1 = fCurrentEntry[fNbinp-1][itheta][iphi]->GetMeanG2();
472 Float_t s2 = fCurrentEntry[fNbinp-2][itheta][iphi]->GetMeanG2();
6255180c 473 Float_t p1 = fDeltaP * (fNbinp - 1 + 0.5) + fPmin;
474 Float_t p2 = fDeltaP * (fNbinp - 2 + 0.5) + fPmin;
475 Float_t norm = 1./(p1-p2) * ( (s1-s2)*p + (s2-s1)*p1 + s1*(p1-p2) );
476 return norm;
477 }
4ef9f58b 478 else return fCurrentEntry[ip][itheta][iphi]->GetMeanG2();
6255180c 479}
480
481Float_t AliMUONFastTracking::SigmaG2(Float_t p, Float_t theta,
041f7f97 482 Float_t phi, Int_t charge) const
6255180c 483{
041f7f97 484 //
485 // gets the width of the background
486 // (gaussian) component in the prec-pgen distribution
487 //
6255180c 488 Int_t ip=0, itheta=0, iphi=0;
489 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
490 if (p>fPmax) {
491 // linear extrapolation of sigmap for p out of range
4ef9f58b 492 Float_t s1 = fCurrentEntry[fNbinp-1][itheta][iphi]->GetSigmaG2();
493 Float_t s2 = fCurrentEntry[fNbinp-2][itheta][iphi]->GetSigmaG2();
6255180c 494 Float_t p1 = fDeltaP * (fNbinp - 1 + 0.5) + fPmin;
495 Float_t p2 = fDeltaP * (fNbinp - 2 + 0.5) + fPmin;
496 Float_t sigma = 1./(p1-p2) * ( (s1-s2)*p + (s2-s1)*p1 + s1*(p1-p2) );
497 return sigma;
498 }
4ef9f58b 499 else return fCurrentEntry[ip][itheta][iphi]->GetSigmaG2();
6255180c 500}
501
502
503Float_t AliMUONFastTracking::MeanTheta(Float_t p, Float_t theta,
041f7f97 504 Float_t phi, Int_t charge) const
6255180c 505{
041f7f97 506 //
507 // gets the mean value of the thetarec-thetagen distribution
508 //
6255180c 509 Int_t ip=0, itheta=0, iphi=0;
510 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
4ef9f58b 511 return fCurrentEntry[ip][itheta][iphi]->GetMeantheta();
6255180c 512}
513
041f7f97 514Float_t AliMUONFastTracking::SigmaTheta(Float_t p, Float_t theta,
515 Float_t phi, Int_t charge) const
516{
517 //
518 // gets the width of the thetarec-thetagen distribution
519 //
6255180c 520 Int_t ip=0, itheta=0, iphi=0;
521 Int_t index;
522 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
523 // central value and corrections with spline
4ef9f58b 524 Float_t sigmatheta = fCurrentEntry[ip][itheta][iphi]->GetSigmatheta();
6255180c 525 if (!fSpline) return sigmatheta;
526 // corrections vs p, theta, phi
527 index = iphi + fNbinphi * itheta;
528 Double_t xmin,ymin,xmax,ymax;
529 Float_t frac1 = fSplineSigmatheta[index][0]->Eval(p)/sigmatheta;
530 if (p>fPmax-fDeltaP/2.) {
531 // linear extrapolation of sigmap for p out of range
4ef9f58b 532 Float_t s1 = fCurrentEntry[fNbinp-1][itheta][iphi]->GetSigmatheta();
533 Float_t s2 = fCurrentEntry[fNbinp-2][itheta][iphi]->GetSigmatheta();
6255180c 534 Float_t p1 = fDeltaP * (fNbinp - 1 + 0.5) + fPmin;
535 Float_t p2 = fDeltaP * (fNbinp - 2 + 0.5) + fPmin;
536 Float_t sigma = 1./(p1-p2) * ( (s1-s2)*p + (s2-s1)*p1 + s1*(p1-p2) );
537 frac1=sigma/sigmatheta;
538 }
539 index = iphi + fNbinphi * ip;
540 fSplineEff[index][1]->GetKnot(0,xmin,ymin);
541 fSplineEff[index][1]->GetKnot(9,xmax,ymax);
542 if (theta>xmax) theta = xmax;
543 Float_t frac2 = fSplineSigmatheta[index][1]->Eval(theta)/sigmatheta;
544 index = itheta + fNbintheta * ip;
545 fSplineEff[index][2]->GetKnot(0,xmin,ymin);
546 fSplineEff[index][2]->GetKnot(9,xmax,ymax);
547 if (phi>xmax) phi = xmax;
548 Float_t frac3 = fSplineSigmatheta[index][2]->Eval(phi)/sigmatheta;
549 return sigmatheta * frac1 * frac2 * frac3;
550}
551
552
553Float_t AliMUONFastTracking::MeanPhi(Float_t p, Float_t theta,
041f7f97 554 Float_t phi, Int_t charge) const
555{
556 //
557 // gets the mean value of the phirec-phigen distribution
558 //
6255180c 559 Int_t ip=0, itheta=0, iphi=0;
560 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
4ef9f58b 561 return fCurrentEntry[ip][itheta][iphi]->GetMeanphi();
6255180c 562}
563
564Float_t AliMUONFastTracking::SigmaPhi(Float_t p, Float_t theta,
565 Float_t phi, Int_t charge){
041f7f97 566 //
567 // gets the width of the phirec-phigen distribution
568 //
6255180c 569 Int_t ip=0, itheta=0, iphi=0;
570 Int_t index;
571 GetIpIthetaIphi(p,theta,phi,charge,ip,itheta,iphi);
572 // central value and corrections with spline
4ef9f58b 573 Float_t sigmaphi = fCurrentEntry[ip][itheta][iphi]->GetSigmaphi();
6255180c 574 if (!fSpline) return sigmaphi;
575 // corrections vs p, theta, phi
576 index = iphi + fNbinphi * itheta;
577 Float_t frac1 = fSplineSigmaphi[index][0]->Eval(p)/sigmaphi;
578 Double_t xmin,ymin,xmax,ymax;
579 if (p>fPmax-fDeltaP/2.) {
4ef9f58b 580 Float_t s1 = fCurrentEntry[fNbinp-1][itheta][iphi]->GetSigmaphi();
581 Float_t s2 = fCurrentEntry[fNbinp-2][itheta][iphi]->GetSigmaphi();
6255180c 582 Float_t p1 = fDeltaP * (fNbinp - 1 + 0.5) + fPmin;
583 Float_t p2 = fDeltaP * (fNbinp - 2 + 0.5) + fPmin;
584 Float_t sigma = 1./(p1-p2) * ( (s1-s2)*p + (s2-s1)*p1 + s1*(p1-p2) );
585 frac1 = sigma/sigmaphi;
586 }
587
588 index = iphi + fNbinphi * ip;
589 fSplineEff[index][1]->GetKnot(0,xmin,ymin);
590 fSplineEff[index][1]->GetKnot(9,xmax,ymax);
591 if (theta>xmax) theta = xmax;
592 Float_t frac2 = fSplineSigmaphi[index][1]->Eval(theta)/sigmaphi;
593 index = itheta + fNbintheta * ip;
594 fSplineEff[index][2]->GetKnot(0,xmin,ymin);
595 fSplineEff[index][2]->GetKnot(9,xmax,ymax);
596 if (phi>xmax) phi = xmax;
597 Float_t frac3 = fSplineSigmaphi[index][2]->Eval(phi)/sigmaphi;
598 return sigmaphi * frac1 * frac2 * frac3;
599}
600
601void AliMUONFastTracking::SetSpline(){
041f7f97 602 //
603 // sets the spline functions for a smooth behaviour of the parameters
604 // when going from one cell to another
605 //
6255180c 606 printf ("Setting spline functions...");
607 char splname[40];
608 Double_t x[20][3];
609 Double_t x2[50][3];
610 Int_t nbins[3] = {fNbinp, fNbintheta, fNbinphi};
611 Double_t xspl[20],yeff[50],ysigmap[20],ysigma1p[20];
612 Double_t yacc[50], ysigmatheta[20],ysigmaphi[20];
613 Double_t xsp2[50];
614 // let's calculate the x axis for p, theta, phi
615
616 Int_t i, ispline, ivar;
617 for (i=0; i< fNbinp; i++) x[i][0] = fPmin + fDeltaP * (i + 0.5);
618 for (i=0; i< fNbintheta; i++) x[i][1] = fThetamin + fDeltaTheta * (i + 0.5);
619 for (i=0; i< fNbinphi; i++) x[i][2] = fPhimin + fDeltaPhi * (i + 0.5);
620
621 for (i=0; i< 5 * fNbinp; i++) x2[i][0] = fPmin + fDeltaP * (i + 0.5)/5.;
622 for (i=0; i< 5 * fNbintheta; i++) x2[i][1] = fThetamin + fDeltaTheta * (i + 0.5)/5.;
623 for (i=0; i< 5 * fNbinphi; i++) x2[i][2] = fPhimin + fDeltaPhi * (i + 0.5)/5.;
624
625 // splines in p
626 ivar = 0;
627 for (i=0; i<nbins[ivar]; i++) xspl[i] = x[i][ivar];
628 for (i=0; i<5 * nbins[ivar]; i++) xsp2[i] = x2[i][ivar];
629 ispline=0;
630 for (Int_t itheta=0; itheta< fNbintheta; itheta++){
631 for (Int_t iphi=0; iphi< fNbinphi; iphi++){
632 for (Int_t ip=0; ip<fNbinp; ip++) {
4ef9f58b 633 ysigmap[ip] = fCurrentEntry[ip][itheta][iphi]->GetSigmap();
634 ysigma1p[ip] = fCurrentEntry[ip][itheta][iphi]->GetSigma1p();
635 ysigmatheta[ip] = fCurrentEntry[ip][itheta][iphi]->GetSigmatheta();
636 ysigmaphi[ip] = fCurrentEntry[ip][itheta][iphi]->GetSigmaphi();
6255180c 637 }
638 if (fPrintLevel>3) cout << " creating new spline " << splname << endl;
639 sprintf (splname,"fSplineEff[%d][%d]",ispline,ivar);
640 fSplineEff[ispline][ivar] = new TSpline3(splname,xsp2,yeff,5 * nbins[ivar]);
641 sprintf (splname,"fSplineAcc[%d][%d]",ispline,ivar);
642 fSplineAcc[ispline][ivar] = new TSpline3(splname,xsp2,yacc,5 * nbins[ivar]);
643 sprintf (splname,"fSplineSigmap[%d][%d]",ispline,ivar);
644 fSplineSigmap[ispline][ivar] = new TSpline3(splname,xspl,ysigmap,nbins[ivar]);
645 sprintf (splname,"fSplineSigma1p[%d][%d]",ispline,ivar);
646 fSplineSigma1p[ispline][ivar] = new TSpline3(splname,xspl,ysigma1p,nbins[ivar]);
647 sprintf (splname,"fSplineSigmatheta[%d][%d]",ispline,ivar);
648 fSplineSigmatheta[ispline][ivar] = new TSpline3(splname,xspl,ysigmatheta,nbins[ivar]);
649 sprintf (splname,"fSplineSigmaphi[%d][%d]",ispline,ivar);
650 fSplineSigmaphi[ispline][ivar] = new TSpline3(splname,xspl,ysigmaphi,nbins[ivar]);
651 ispline++;
652 }
653 }
654
655 ivar = 1;
656 for (i=0; i<nbins[ivar]; i++) xspl[i] = x[i][ivar];
657 ispline=0;
658 for (Int_t ip=0; ip<fNbinp; ip++) {
659 for (Int_t iphi=0; iphi< fNbinphi; iphi++){
660 for (Int_t itheta=0; itheta< fNbintheta; itheta++){
661 // for efficiency and acceptance let's take the central value
4ef9f58b 662 ysigmap[itheta] = fCurrentEntry[ip][itheta][iphi]->GetSigmap();
663 ysigma1p[itheta] = fCurrentEntry[ip][itheta][iphi]->GetSigma1p();
664 ysigmatheta[itheta] = fCurrentEntry[ip][itheta][iphi]->GetSigmatheta();
665 ysigmaphi[itheta] = fCurrentEntry[ip][itheta][iphi]->GetSigmaphi();
6255180c 666 }
667 if (fPrintLevel>3) cout << " creating new spline " << splname << endl;
668 sprintf (splname,"fSplineEff[%d][%d]",ispline,ivar);
669 fSplineEff[ispline][ivar] = new TSpline3(splname,xspl,yeff, nbins[ivar]);
670 sprintf (splname,"fSplineAcc[%d][%d]",ispline,ivar);
671 fSplineAcc[ispline][ivar] = new TSpline3(splname,xspl,yacc, nbins[ivar]);
672 sprintf (splname,"fSplineSigmap[%d][%d]",ispline,ivar);
673 fSplineSigmap[ispline][ivar] = new TSpline3(splname,xspl,ysigmap,nbins[ivar]);
674 sprintf (splname,"fSplineSigma1p[%d][%d]",ispline,ivar);
675 fSplineSigma1p[ispline][ivar] = new TSpline3(splname,xspl,ysigma1p,nbins[ivar]);
676 sprintf (splname,"fSplineSigmatheta[%d][%d]",ispline,ivar);
677 fSplineSigmatheta[ispline][ivar] = new TSpline3(splname,xspl,ysigmatheta,nbins[ivar]);
678 sprintf (splname,"fSplineSigmaphi[%d][%d]",ispline,ivar);
679 fSplineSigmaphi[ispline][ivar] = new TSpline3(splname,xspl,ysigmaphi,nbins[ivar]);
680 ispline++;
681 }
682 }
683
684 ivar = 2;
685 for (i=0; i<nbins[ivar]; i++) xspl[i] = x[i][ivar];
686 ispline=0;
687 for (Int_t ip=0; ip<fNbinp; ip++) {
688 for (Int_t itheta=0; itheta< fNbintheta; itheta++){
689 for (Int_t iphi=0; iphi< fNbinphi; iphi++){
690 // for efficiency and acceptance let's take the central value
4ef9f58b 691 ysigmap[iphi] = fCurrentEntry[ip][itheta][iphi]->GetSigmap();
692 ysigma1p[iphi] = fCurrentEntry[ip][itheta][iphi]->GetSigma1p();
693 ysigmatheta[iphi] = fCurrentEntry[ip][itheta][iphi]->GetSigmatheta();
694 ysigmaphi[iphi] = fCurrentEntry[ip][itheta][iphi]->GetSigmaphi();
6255180c 695 }
696 if (fPrintLevel>3) cout << " creating new spline " << splname << endl;
697 sprintf (splname,"fSplineEff[%d][%d]",ispline,ivar);
698 fSplineEff[ispline][ivar] = new TSpline3(splname,xspl,yeff, nbins[ivar]);
699 sprintf (splname,"fSplineAcc[%d][%d]",ispline,ivar);
700 fSplineAcc[ispline][ivar] = new TSpline3(splname,xspl,yacc, nbins[ivar]);
701 sprintf (splname,"fSplineSigmap[%d][%d]",ispline,ivar);
702 fSplineSigmap[ispline][ivar] = new TSpline3(splname,xspl,ysigmap,nbins[ivar]);
703 sprintf (splname,"fSplineSigma1p[%d][%d]",ispline,ivar);
704 fSplineSigma1p[ispline][ivar] = new TSpline3(splname,xspl,ysigma1p,nbins[ivar]);
705 sprintf (splname,"fSplineSigmatheta[%d][%d]",ispline,ivar);
706 fSplineSigmatheta[ispline][ivar] = new TSpline3(splname,xspl,ysigmatheta,nbins[ivar]);
707 sprintf (splname,"fSplineSigmaphi[%d][%d]",ispline,ivar);
708 fSplineSigmaphi[ispline][ivar] = new TSpline3(splname,xspl,ysigmaphi,nbins[ivar]);
709 ispline++;
710 }
711 }
712 printf ("...done\n");
713}
714
6255180c 715void AliMUONFastTracking::SetBackground(Float_t bkg){
041f7f97 716 //
6255180c 717 // linear interpolation of the parameters in the LUT between 2 values where
718 // the background has been actually calculated
041f7f97 719 //
6255180c 720 if (bkg>2) printf ("WARNING: unsafe extrapolation!\n");
721 fBkg = bkg;
722
041f7f97 723 Float_t bkgLevel[4] = {0, 0.5, 1, 2}; // bkg values for which LUT is calculated
6255180c 724 Int_t ibkg;
041f7f97 725 for (ibkg=0; ibkg<4; ibkg++) if ( bkg < bkgLevel[ibkg]) break;
6255180c 726 if (ibkg == 4) ibkg--;
727 if (ibkg == 0) ibkg++;
728
041f7f97 729 Float_t x0 = bkgLevel[ibkg-1];
730 Float_t x1 = bkgLevel[ibkg];
6255180c 731 Float_t x = (bkg - x0) / (x1 - x0);
732
733 Float_t y0, y1;
734
735 for (Int_t ip=0; ip< fNbinp; ip++){
736 for (Int_t itheta=0; itheta< fNbintheta; itheta++){
737 for (Int_t iphi=0; iphi< fNbinphi; iphi++){
4ef9f58b 738 fCurrentEntry[ip][itheta][iphi]->SetP(fEntry[ip][itheta][iphi][ibkg]->GetP());
739 fCurrentEntry[ip][itheta][iphi]->SetTheta(fEntry[ip][itheta][iphi][ibkg]->GetTheta());
740 fCurrentEntry[ip][itheta][iphi]->SetPhi(fEntry[ip][itheta][iphi][ibkg]->GetPhi());
741 fCurrentEntry[ip][itheta][iphi]->SetChi2p(-1);
742 fCurrentEntry[ip][itheta][iphi]->SetChi2theta(-1);
743 fCurrentEntry[ip][itheta][iphi]->SetChi2phi(-1);
744
745 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetMeanp();
746 y1 = fEntry[ip][itheta][iphi][ibkg]->GetMeanp();
747 fCurrentEntry[ip][itheta][iphi] ->SetMeanp((y1 - y0) * x + y0);
748 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetMeantheta();
749 y1 = fEntry[ip][itheta][iphi][ibkg]->GetMeantheta();
750 fCurrentEntry[ip][itheta][iphi] ->SetMeantheta((y1 - y0) * x +y0);
751 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetMeanphi();
752 y1 = fEntry[ip][itheta][iphi][ibkg]->GetMeanphi();
753 fCurrentEntry[ip][itheta][iphi] ->SetMeanphi((y1 - y0) * x + y0);
754 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetSigmap();
755 y1 = fEntry[ip][itheta][iphi][ibkg]->GetSigmap();
756 fCurrentEntry[ip][itheta][iphi] ->SetSigmap((y1 - y0) * x + y0);
757 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetSigmatheta();
758 y1 = fEntry[ip][itheta][iphi][ibkg]->GetSigmatheta();
759 fCurrentEntry[ip][itheta][iphi] ->SetSigmatheta((y1 - y0) * x+y0);
760 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetSigmaphi();
761 y1 = fEntry[ip][itheta][iphi][ibkg]->GetSigmaphi();
762 fCurrentEntry[ip][itheta][iphi] ->SetSigmaphi((y1 - y0) * x + y0);
763 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetSigma1p();
764 y1 = fEntry[ip][itheta][iphi][ibkg]->GetSigma1p();
765 fCurrentEntry[ip][itheta][iphi] ->SetSigma1p((y1 - y0) * x + y0);
766 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetNormG2();
767 y1 = fEntry[ip][itheta][iphi][ibkg]->GetNormG2();
768 fCurrentEntry[ip][itheta][iphi] ->SetNormG2((y1 - y0) * x + y0);
769 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetMeanG2();
770 y1 = fEntry[ip][itheta][iphi][ibkg]->GetMeanG2();
771 fCurrentEntry[ip][itheta][iphi] ->SetMeanG2((y1 - y0) * x + y0);
6255180c 772
4ef9f58b 773 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetSigmaG2();
774 y1 = fEntry[ip][itheta][iphi][ibkg]->GetSigmaG2();
775 fCurrentEntry[ip][itheta][iphi] ->SetSigmaG2((y1 - y0) * x + y0);
6255180c 776 for (Int_t i=0; i<kSplitP; i++) {
777 for (Int_t j=0; j<kSplitTheta; j++) {
4ef9f58b 778 fCurrentEntry[ip][itheta][iphi]->SetAcc(i,j,fEntry[ip][itheta][iphi][ibkg]->GetAcc(i,j));
779 y0 = fEntry[ip][itheta][iphi][ibkg-1]->GetEff(i,j);
780 y1 = fEntry[ip][itheta][iphi][ibkg]->GetEff(i,j);
781 fCurrentEntry[ip][itheta][iphi]->SetEff(i,j, (y1 - y0) * x + y0);
6255180c 782 }
783 }
784 }
785 }
786 }
787 SetSpline();
788}
789
d53fc881 790TF1* AliMUONFastTracking::GetFitP(Int_t ip,Int_t itheta,Int_t iphi) {
041f7f97 791 // gets the correct prec-pgen distribution for a given LUT cell
c6ba3ff4 792 if (!fFitp[ip][itheta][iphi]) {
793 char name[256];
794 sprintf(name, "fit_%d_%d_%d", ip, itheta, iphi);
795 fFitp[ip][itheta][iphi] = new TF1(name ,FitP,-20.,20.,6);
d53fc881 796 fFitp[ip][itheta][iphi]->SetNpx(500);
1e68a0c5 797 fFitp[ip][itheta][iphi]->SetParameters(0.,0.,0.,0.,0.,0.);
d53fc881 798 }
799 return fFitp[ip][itheta][iphi];
800}
6255180c 801
041f7f97 802AliMUONFastTracking& AliMUONFastTracking::operator=(const AliMUONFastTracking& rhs)
803{
804// Assignment operator
805 rhs.Copy(*this);
806 return *this;
807}
808
15a060e4 809void AliMUONFastTracking::Copy(TObject&) const
041f7f97 810{
811 //
812 // Copy
813 //
814 Fatal("Copy","Not implemented!\n");
815}
6255180c 816
817
818
819
820
821
822
823