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