]> git.uio.no Git - u/mrichter/AliRoot.git/blame - HBTAN/AliHBTPositionRandomizer.cxx
New OCDB configuration entry for HighVoltage (updated DP names)
[u/mrichter/AliRoot.git] / HBTAN / AliHBTPositionRandomizer.cxx
CommitLineData
e201f2eb 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
37b09b91 16/* $Id$ */
e201f2eb 17
abe00f6f 18//___________________________________________________
19////////////////////////////////////////////////////////////////////////////////
20//
21// class AliHBTPositionRandomizer
22//
23// These class randomizes particle vertex positions
24// Piotr.Skowronski@cern.ch
25//
26////////////////////////////////////////////////////////////////////////////////
27
37b09b91 28#include <TMath.h>
88cb7938 29#include <TRandom.h>
e201f2eb 30
415b66b5 31#include "AliAOD.h"
e201f2eb 32#include "AliHBTPositionRandomizer.h"
33#include "AliLog.h"
415b66b5 34#include "AliVAODParticle.h"
88cb7938 35
36
37ClassImp(AliHBTPositionRandomizer)
38
a296aa84 39const Int_t AliHBTPositionRandomizer::fgkNumberOfPids = 10;
40
88cb7938 41/*********************************************************************/
42
43AliHBTPositionRandomizer::AliHBTPositionRandomizer():
44 fReader(0x0),
a296aa84 45 fDefaultRandomizer(0x0),
46 fRandomizers(0x0),
47 fNPid(0),
48 fPids(0x0),
88cb7938 49 fAddToExistingPos(kFALSE),
50 fOnlyParticlesFromVertex(kFALSE),
3a3bc78a 51 fRandomizeTracks(kFALSE),
88cb7938 52 fVX(0.0),
53 fVY(0.0),
54 fVZ(0.0)
55{
56//constructor
57}
58/*********************************************************************/
59
415b66b5 60AliHBTPositionRandomizer::AliHBTPositionRandomizer(AliReader* reader):
88cb7938 61 fReader(reader),
a296aa84 62 fRandomizers(new TObjArray(fgkNumberOfPids)),
63 fNPid(1),
64 fPids(new Int_t[fgkNumberOfPids]),
88cb7938 65 fAddToExistingPos(kFALSE),
66 fOnlyParticlesFromVertex(kFALSE),
3a3bc78a 67 fRandomizeTracks(kFALSE),
88cb7938 68 fVX(0.0),
69 fVY(0.0),
70 fVZ(0.0)
71{
72//constructor
a296aa84 73 fRandomizers->AddAt(new AliHBTRndmGaussBall(8.0,0.0,0.0),0);
88cb7938 74}
75/*********************************************************************/
76
abe00f6f 77AliHBTPositionRandomizer::AliHBTPositionRandomizer(const AliHBTPositionRandomizer& in):
415b66b5 78 AliReader(in),
abe00f6f 79 fReader(),
a296aa84 80 fRandomizers(0x0),
81 fNPid(0),
82 fPids(0x0),
abe00f6f 83 fAddToExistingPos(kFALSE),
84 fOnlyParticlesFromVertex(kFALSE),
3a3bc78a 85 fRandomizeTracks(kFALSE),
abe00f6f 86 fVX(0.0),
87 fVY(0.0),
88 fVZ(0.0)
89{
90 //cpy constructor
91 in.Copy(*this);
92}
93/*********************************************************************/
94AliHBTPositionRandomizer::~AliHBTPositionRandomizer()
95{
96 //dtor
97 delete fReader;
a296aa84 98 delete fRandomizers;
99 delete [] fPids;
abe00f6f 100}
101/*********************************************************************/
34914285 102AliHBTPositionRandomizer& AliHBTPositionRandomizer::operator=(const AliHBTPositionRandomizer& in)
abe00f6f 103{
104 //assigment operator
105 in.Copy(*this);
106 return *this;
107}
108/*********************************************************************/
109
1c654289 110AliAOD* AliHBTPositionRandomizer::GetEventSim() const
efaf00f8 111{
112 // gets from fReader and randomizes current particle event
1c654289 113 if (fReader == 0x0)
114 {
115 Error("GetEventSim","Reader is null");
116 return 0x0;
117 }
415b66b5 118 AliAOD *e = fReader->GetEventSim();
6c15cd50 119 if (e)
120 if (e->IsRandomized() == kFALSE)
121 Randomize(e);
efaf00f8 122 return e;
123}
124/*********************************************************************/
125
1c654289 126AliAOD* AliHBTPositionRandomizer::GetEventRec() const
efaf00f8 127{
128 // gets from fReader and randomizes current track event
1c654289 129 if (fReader == 0x0)
130 {
131 Error("GetEventRec","Reader is null");
132 return 0x0;
133 }
415b66b5 134 AliAOD *e = fReader->GetEventRec();
6c15cd50 135 if (fRandomizeTracks && e) if (e->IsRandomized() == kFALSE) Randomize(e);
efaf00f8 136 return e;
137}
138/*********************************************************************/
139
415b66b5 140AliAOD* AliHBTPositionRandomizer::GetEventSim(Int_t n)
88cb7938 141{
142//returns event n
143 if (fReader == 0x0) return 0x0;
415b66b5 144 AliAOD *e = fReader->GetEventSim(n);
88cb7938 145 if (e->IsRandomized() == kFALSE) Randomize(e);
146 return e;
147}
148
149/*********************************************************************/
415b66b5 150void AliHBTPositionRandomizer::Randomize(AliAOD* event) const
88cb7938 151{
152// randomizes postions of all particles in the event
abe00f6f 153 static const Double_t kfmtocm = 1.e-13;
e201f2eb 154 AliDebug(5," ");
88cb7938 155 if (event == 0x0) return;
156
157 for (Int_t i = 0; i < event->GetNumberOfParticles(); i++)
158 {
415b66b5 159 AliVAODParticle* p = event->GetParticle(i);
88cb7938 160 Double_t x,y,z,t=0.0;
a296aa84 161 AliHBTRndm* r = GetRandomizer(p->GetPdgCode());
162 r->Randomize(x,y,z,t,p);
3a3bc78a 163
164 Double_t nx = x*kfmtocm;
165 Double_t ny = y*kfmtocm;
166 Double_t nz = z*kfmtocm;
167 Double_t nt = t*kfmtocm;
168
169 if (fAddToExistingPos)
170 {
171 nx += p->Vx();
172 ny += p->Vy();
173 nz += p->Vz();
174 nt += p->T();
175 }
176 p->SetProductionVertex(nx,ny,nz,nt);
88cb7938 177 }
178 event->SetRandomized();
179}
180/*********************************************************************/
181
a296aa84 182AliHBTRndm* AliHBTPositionRandomizer::GetRandomizer(Int_t pdg) const
183{
184 //returns randomizer for a given pdg
185 Int_t idx = GetRandomizerIndex(pdg);//in most of cases
186 if (idx < 0) idx = 0;//if not found return a default one
187 return (AliHBTRndm*)fRandomizers->At(idx);
188}
189/*********************************************************************/
190Int_t AliHBTPositionRandomizer::GetRandomizerIndex(Int_t pdg) const
191{
192 //returns randomizer index for a given pdg
193
194 if (pdg == 0) return 0;
195
196 for (Int_t i=1; i < fNPid; i++)
197 {
198 if (fPids[i] == pdg)
199 return i;
200 }
201
202 return -1;
203}
204/*********************************************************************/
205
206void AliHBTPositionRandomizer::SetRandomizer(Int_t pid, AliHBTRndm* rndm)
207{
208 //sets the randomizer for a given particle type
209 if (rndm == 0x0)
210 {
211 Error("SetRandomizer","Randomizer is null");
212 return;
213 }
214
215 Int_t idx = GetRandomizerIndex(pid);
216 if (idx >= 0)
217 {
218 delete fRandomizers->At(idx);
219 fRandomizers->AddAt(rndm,idx);
220 }
221
222 if (fNPid == fgkNumberOfPids)
223 {
224 Error("SetRandomizer","There is no more space in the array");
225 return;
226 }
227
228 fPids[fNPid] = pid;
229 fRandomizers->AddAt(rndm,fNPid);
230 fNPid++;
231}
232/*********************************************************************/
233
234void AliHBTPositionRandomizer::SetGaussianBall(Int_t pid, Double_t r, Double_t meantime, Double_t sigmatime)
88cb7938 235{
abe00f6f 236 //Sets Gaussian Ball Model
a296aa84 237 SetGaussianBall(pid,r,r,r,meantime,sigmatime);
88cb7938 238}
239/*********************************************************************/
240
a296aa84 241void AliHBTPositionRandomizer::SetGaussianBall(Int_t pid, Double_t rx, Double_t ry, Double_t rz, Double_t meantime, Double_t sigmatime)
88cb7938 242{
abe00f6f 243 //Sets Gaussian Ball Model
a296aa84 244 AliHBTRndm* rndm = new AliHBTRndmGaussBall(rx,ry,rz,meantime,sigmatime);
245 SetRandomizer(pid,rndm);
88cb7938 246}
247/*********************************************************************/
248
a296aa84 249void AliHBTPositionRandomizer::SetCyllinderSurface(Int_t pid, Double_t r, Double_t l)
88cb7938 250{
abe00f6f 251 //Sets Cylinder Surface Model
a296aa84 252 AliHBTRndm* rndm = new AliHBTRndmCyllSurf(r,l);
253 SetRandomizer(pid,rndm);
88cb7938 254}
255/*********************************************************************/
256
257void AliHBTPositionRandomizer::SetEventVertex(Double_t x, Double_t y,Double_t z)
258{
259//sets event vertex position
260 fVX = x;
261 fVY = y;
262 fVZ = z;
263}
94a709e1 264
265
a296aa84 266void AliHBTPositionRandomizer::SetEllipse(Int_t pid, Double_t rx, Double_t ryz)
94a709e1 267{
a296aa84 268//sets the ellipse randomization for the given pid
269 AliHBTRndm* rndm = new AliHBTRndmEllipse(rx,ryz);
270 SetRandomizer(pid,rndm);
94a709e1 271}
272
88cb7938 273/*********************************************************************/
274//_____________________________________________________________________
275///////////////////////////////////////////////////////////////////////
276// //
277// class AliHBTRndmGaussBall //
278// //
279///////////////////////////////////////////////////////////////////////
280
281AliHBTRndmGaussBall::AliHBTRndmGaussBall():
282 fRx(0.0),
283 fRy(0.0),
a296aa84 284 fRz(0.0),
285 fTmean(0.0),
286 fTsigma(0.0)
88cb7938 287{
288 //constructor
289}
290/*********************************************************************/
291
a296aa84 292AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t r, Double_t meantime, Double_t sigmatime):
88cb7938 293 fRx(r),
294 fRy(r),
a296aa84 295 fRz(r),
296 fTmean(meantime),
297 fTsigma(sigmatime)
88cb7938 298{
299 //constructor
300}
301/*********************************************************************/
302
a296aa84 303AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t rx, Float_t ry, Float_t rz, Double_t meantime, Double_t sigmatime):
88cb7938 304 fRx(rx),
305 fRy(ry),
a296aa84 306 fRz(rz),
307 fTmean(meantime),
308 fTsigma(sigmatime)
88cb7938 309{
310 //constructor
311}
312/*********************************************************************/
313
94a709e1 314
315AliHBTRndmEllipse::AliHBTRndmEllipse(Float_t rmin, Float_t rmax):
316 fRmin(rmin),
317 fRmax(rmax)
318{
319 //constructor
320}
321
322/*********************************************************************/
323
a296aa84 324void AliHBTRndmGaussBall::Randomize(Double_t& x,Double_t& y,Double_t&z,Double_t&t, AliVAODParticle*/*particle*/) const
88cb7938 325{
326//randomizez gauss for each coordinate separately
327 x = gRandom->Gaus(0.0,fRx);
328 y = gRandom->Gaus(0.0,fRy);
329 z = gRandom->Gaus(0.0,fRz);
a296aa84 330
331 if (fTsigma == 0.0)
332 {
1a1e58ac 333 t = fTmean;
a296aa84 334 return;
335 }
336
337 t = gRandom->Gaus(fTmean,fTsigma);
338
88cb7938 339}
340/*********************************************************************/
341//_____________________________________________________________________
342///////////////////////////////////////////////////////////////////////
343// //
344// class AliHBTRndmGaussBall //
345// //
346///////////////////////////////////////////////////////////////////////
347
a296aa84 348void AliHBTRndmCyllSurf::Randomize(Double_t& x,Double_t& y,Double_t&z,Double_t&/*t*/, AliVAODParticle* particle) const
88cb7938 349{
abe00f6f 350//Randomizes x,y,z
568f8a1a 351 Double_t r = fR + gRandom->Gaus(0.0, 1.0);
bed069a4 352 Double_t sf = r/particle->Pt();//scaling factor for position transformation ->
88cb7938 353 //we move direction of string momentum but legth defined by r
bed069a4 354 x = sf*particle->Px();
355 y = sf*particle->Py();
88cb7938 356 z = gRandom->Uniform(-fL,fL);
88cb7938 357}
94a709e1 358
359/*********************************************************************/
360/*********************************************************************/
361
a296aa84 362void AliHBTRndmEllipse::Randomize(Double_t& x, Double_t& y, Double_t& z,Double_t&/*t*/, AliVAODParticle*p) const
94a709e1 363{
364 // p=0; //workaround - fix this damn little thingy
365 double R;
366 double phi=p->Phi();
367
368 R=fRmin+(fRmax-fRmin)*TMath::Sin(phi);
369 x=R*TMath::Sin(phi);
370 y=R*TMath::Cos(phi);
371 z=z;
372}