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