Bug Corrected
[u/mrichter/AliRoot.git] / HBTAN / AliHBTPositionRandomizer.cxx
CommitLineData
88cb7938 1#include "AliHBTPositionRandomizer.h"
abe00f6f 2//___________________________________________________
3////////////////////////////////////////////////////////////////////////////////
4//
5// class AliHBTPositionRandomizer
6//
7// These class randomizes particle vertex positions
8// Piotr.Skowronski@cern.ch
9//
10////////////////////////////////////////////////////////////////////////////////
11
88cb7938 12#include <TRandom.h>
415b66b5 13#include "AliAOD.h"
14#include "AliVAODParticle.h"
88cb7938 15
16
17ClassImp(AliHBTPositionRandomizer)
18
19/*********************************************************************/
20
21AliHBTPositionRandomizer::AliHBTPositionRandomizer():
22 fReader(0x0),
23 fRandomizer(0x0),
24 fModel(0),
25 fAddToExistingPos(kFALSE),
26 fOnlyParticlesFromVertex(kFALSE),
3a3bc78a 27 fRandomizeTracks(kFALSE),
88cb7938 28 fVX(0.0),
29 fVY(0.0),
30 fVZ(0.0)
31{
32//constructor
33}
34/*********************************************************************/
35
415b66b5 36AliHBTPositionRandomizer::AliHBTPositionRandomizer(AliReader* reader):
88cb7938 37 fReader(reader),
38 fRandomizer(new AliHBTRndmGaussBall(8.0)),
39 fModel(0),
40 fAddToExistingPos(kFALSE),
41 fOnlyParticlesFromVertex(kFALSE),
3a3bc78a 42 fRandomizeTracks(kFALSE),
88cb7938 43 fVX(0.0),
44 fVY(0.0),
45 fVZ(0.0)
46{
47//constructor
48}
49/*********************************************************************/
50
abe00f6f 51AliHBTPositionRandomizer::AliHBTPositionRandomizer(const AliHBTPositionRandomizer& in):
415b66b5 52 AliReader(in),
abe00f6f 53 fReader(),
54 fRandomizer(0x0),
55 fModel(0),
56 fAddToExistingPos(kFALSE),
57 fOnlyParticlesFromVertex(kFALSE),
3a3bc78a 58 fRandomizeTracks(kFALSE),
abe00f6f 59 fVX(0.0),
60 fVY(0.0),
61 fVZ(0.0)
62{
63 //cpy constructor
64 in.Copy(*this);
65}
66/*********************************************************************/
67AliHBTPositionRandomizer::~AliHBTPositionRandomizer()
68{
69 //dtor
70 delete fReader;
71 delete fRandomizer;
72}
73/*********************************************************************/
34914285 74AliHBTPositionRandomizer& AliHBTPositionRandomizer::operator=(const AliHBTPositionRandomizer& in)
abe00f6f 75{
76 //assigment operator
77 in.Copy(*this);
78 return *this;
79}
80/*********************************************************************/
81
1c654289 82AliAOD* AliHBTPositionRandomizer::GetEventSim() const
efaf00f8 83{
84 // gets from fReader and randomizes current particle event
1c654289 85 if (fReader == 0x0)
86 {
87 Error("GetEventSim","Reader is null");
88 return 0x0;
89 }
415b66b5 90 AliAOD *e = fReader->GetEventSim();
efaf00f8 91 if (e->IsRandomized() == kFALSE) Randomize(e);
92 return e;
93}
94/*********************************************************************/
95
1c654289 96AliAOD* AliHBTPositionRandomizer::GetEventRec() const
efaf00f8 97{
98 // gets from fReader and randomizes current track event
1c654289 99 if (fReader == 0x0)
100 {
101 Error("GetEventRec","Reader is null");
102 return 0x0;
103 }
415b66b5 104 AliAOD *e = fReader->GetEventRec();
3a3bc78a 105 if (fRandomizeTracks) if (e->IsRandomized() == kFALSE) Randomize(e);
efaf00f8 106 return e;
107}
108/*********************************************************************/
109
415b66b5 110AliAOD* AliHBTPositionRandomizer::GetEventSim(Int_t n)
88cb7938 111{
112//returns event n
113 if (fReader == 0x0) return 0x0;
415b66b5 114 AliAOD *e = fReader->GetEventSim(n);
88cb7938 115 if (e->IsRandomized() == kFALSE) Randomize(e);
116 return e;
117}
118
119/*********************************************************************/
415b66b5 120void AliHBTPositionRandomizer::Randomize(AliAOD* event) const
88cb7938 121{
122// randomizes postions of all particles in the event
abe00f6f 123 static const Double_t kfmtocm = 1.e-13;
415b66b5 124 if (AliVAODParticle::GetDebug() > 5) Info("Randomize(AliAOD*)","");
88cb7938 125 if (event == 0x0) return;
126
127 for (Int_t i = 0; i < event->GetNumberOfParticles(); i++)
128 {
415b66b5 129 AliVAODParticle* p = event->GetParticle(i);
88cb7938 130 Double_t x,y,z,t=0.0;
131 fRandomizer->Randomize(x,y,z,p);
3a3bc78a 132
133 Double_t nx = x*kfmtocm;
134 Double_t ny = y*kfmtocm;
135 Double_t nz = z*kfmtocm;
136 Double_t nt = t*kfmtocm;
137
138 if (fAddToExistingPos)
139 {
140 nx += p->Vx();
141 ny += p->Vy();
142 nz += p->Vz();
143 nt += p->T();
144 }
145 p->SetProductionVertex(nx,ny,nz,nt);
88cb7938 146 }
147 event->SetRandomized();
148}
149/*********************************************************************/
150
151void AliHBTPositionRandomizer::SetGaussianBall(Double_t r)
152{
abe00f6f 153 //Sets Gaussian Ball Model
88cb7938 154 SetGaussianBall(r,r,r);
155}
156/*********************************************************************/
157
158void AliHBTPositionRandomizer::SetGaussianBall(Double_t rx, Double_t ry, Double_t rz)
159{
abe00f6f 160 //Sets Gaussian Ball Model
88cb7938 161 delete fRandomizer;
162 fRandomizer = new AliHBTRndmGaussBall(rx,ry,rz);
163}
164/*********************************************************************/
165
166void AliHBTPositionRandomizer::SetCyllinderSurface(Double_t r, Double_t l)
167{
abe00f6f 168 //Sets Cylinder Surface Model
88cb7938 169 delete fRandomizer;
170 fRandomizer = new AliHBTRndmCyllSurf(r,l);
171}
172/*********************************************************************/
173
174void AliHBTPositionRandomizer::SetEventVertex(Double_t x, Double_t y,Double_t z)
175{
176//sets event vertex position
177 fVX = x;
178 fVY = y;
179 fVZ = z;
180}
181/*********************************************************************/
182//_____________________________________________________________________
183///////////////////////////////////////////////////////////////////////
184// //
185// class AliHBTRndmGaussBall //
186// //
187///////////////////////////////////////////////////////////////////////
188
189AliHBTRndmGaussBall::AliHBTRndmGaussBall():
190 fRx(0.0),
191 fRy(0.0),
192 fRz(0.0)
193{
194 //constructor
195}
196/*********************************************************************/
197
198AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t r):
199 fRx(r),
200 fRy(r),
201 fRz(r)
202{
203 //constructor
204}
205/*********************************************************************/
206
207AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t rx, Float_t ry, Float_t rz):
208 fRx(rx),
209 fRy(ry),
210 fRz(rz)
211{
212 //constructor
213}
214/*********************************************************************/
215
415b66b5 216void AliHBTRndmGaussBall::Randomize(Double_t& x,Double_t& y,Double_t&z, AliVAODParticle*/*particle*/) const
88cb7938 217{
218//randomizez gauss for each coordinate separately
219 x = gRandom->Gaus(0.0,fRx);
220 y = gRandom->Gaus(0.0,fRy);
221 z = gRandom->Gaus(0.0,fRz);
222}
223/*********************************************************************/
224//_____________________________________________________________________
225///////////////////////////////////////////////////////////////////////
226// //
227// class AliHBTRndmGaussBall //
228// //
229///////////////////////////////////////////////////////////////////////
230
415b66b5 231void AliHBTRndmCyllSurf::Randomize(Double_t& x,Double_t& y,Double_t&z, AliVAODParticle* particle) const
88cb7938 232{
abe00f6f 233//Randomizes x,y,z
568f8a1a 234 Double_t r = fR + gRandom->Gaus(0.0, 1.0);
bed069a4 235 Double_t sf = r/particle->Pt();//scaling factor for position transformation ->
88cb7938 236 //we move direction of string momentum but legth defined by r
bed069a4 237 x = sf*particle->Px();
238 y = sf*particle->Py();
88cb7938 239 z = gRandom->Uniform(-fL,fL);
88cb7938 240}