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