]> git.uio.no Git - u/mrichter/AliRoot.git/blob - HBTAN/AliHBTPositionRandomizer.cxx
TPCNoiseMapComponent included into build (Kelly)
[u/mrichter/AliRoot.git] / HBTAN / AliHBTPositionRandomizer.cxx
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
16 /* $Id$ */
17
18 //___________________________________________________
19 ////////////////////////////////////////////////////////////////////////////////
20 // 
21 // class AliHBTPositionRandomizer
22 //
23 // These class randomizes particle vertex positions
24 // Piotr.Skowronski@cern.ch
25 //
26 ////////////////////////////////////////////////////////////////////////////////
27
28 #include <TMath.h>
29 #include <TRandom.h>
30
31 #include "AliAOD.h"
32 #include "AliHBTPositionRandomizer.h"
33 #include "AliLog.h"
34 #include "AliVAODParticle.h"
35
36
37 ClassImp(AliHBTPositionRandomizer)
38
39 const Int_t AliHBTPositionRandomizer::fgkNumberOfPids = 10;
40
41 /*********************************************************************/
42
43 AliHBTPositionRandomizer::AliHBTPositionRandomizer():
44  fReader(0x0),
45  fDefaultRandomizer(0x0),
46  fRandomizers(0x0),
47  fNPid(0),
48  fPids(0x0),
49  fAddToExistingPos(kFALSE),
50  fOnlyParticlesFromVertex(kFALSE),
51  fRandomizeTracks(kFALSE),
52  fVX(0.0),
53  fVY(0.0),
54  fVZ(0.0)
55 {
56 //constructor
57 }
58 /*********************************************************************/
59
60 AliHBTPositionRandomizer::AliHBTPositionRandomizer(AliReader* reader):
61  fReader(reader),
62  fDefaultRandomizer(0x0),
63  fRandomizers(new TObjArray(fgkNumberOfPids)),
64  fNPid(1),
65  fPids(new Int_t[fgkNumberOfPids]),
66  fAddToExistingPos(kFALSE),
67  fOnlyParticlesFromVertex(kFALSE),
68  fRandomizeTracks(kFALSE),
69  fVX(0.0),
70  fVY(0.0),
71  fVZ(0.0)
72 {
73 //constructor
74  fRandomizers->AddAt(new AliHBTRndmGaussBall(8.0,0.0,0.0),0);
75
76 /*********************************************************************/
77
78 AliHBTPositionRandomizer::AliHBTPositionRandomizer(const AliHBTPositionRandomizer& in):
79  AliReader(in),
80  fReader(),
81  fDefaultRandomizer(0x0),
82  fRandomizers(0x0),
83  fNPid(0),
84  fPids(0x0),
85  fAddToExistingPos(kFALSE),
86  fOnlyParticlesFromVertex(kFALSE),
87  fRandomizeTracks(kFALSE),
88  fVX(0.0),
89  fVY(0.0),
90  fVZ(0.0)
91 {
92   //cpy constructor
93   in.Copy(*this);
94 }
95 /*********************************************************************/
96 AliHBTPositionRandomizer::~AliHBTPositionRandomizer()
97 {
98   //dtor
99   delete fReader;
100   delete fRandomizers;
101   delete [] fPids;
102 }
103 /*********************************************************************/
104 AliHBTPositionRandomizer& AliHBTPositionRandomizer::operator=(const AliHBTPositionRandomizer& in)
105 {
106   //assigment operator
107   in.Copy(*this);
108   return *this;
109 }
110 /*********************************************************************/
111
112 AliAOD* AliHBTPositionRandomizer::GetEventSim() const
113 {
114  // gets from fReader and randomizes current particle event
115  if (fReader == 0x0) 
116   {
117     Error("GetEventSim","Reader is null");
118     return 0x0;
119   } 
120  AliAOD *e =  fReader->GetEventSim();
121  if (e) 
122    if (e->IsRandomized() == kFALSE) 
123      Randomize(e);
124  return e;
125 }
126 /*********************************************************************/
127
128 AliAOD* AliHBTPositionRandomizer::GetEventRec() const
129 {
130  // gets from fReader and randomizes current track event
131  if (fReader == 0x0) 
132   {
133     Error("GetEventRec","Reader is null");
134     return 0x0;
135   }  
136  AliAOD *e =  fReader->GetEventRec();
137  if (fRandomizeTracks && e) if (e->IsRandomized() == kFALSE) Randomize(e);
138  return e;
139 }
140 /*********************************************************************/
141
142 AliAOD* AliHBTPositionRandomizer::GetEventSim(Int_t n)
143 {
144 //returns event n
145  if (fReader == 0x0) return 0x0;
146  AliAOD *e =  fReader->GetEventSim(n);
147  if (e->IsRandomized() == kFALSE) Randomize(e);
148  return e;
149 }
150
151 /*********************************************************************/
152 void AliHBTPositionRandomizer::Randomize(AliAOD* event) const
153 {
154 // randomizes postions of all particles in the event
155   static const Double_t kfmtocm = 1.e-13;
156   AliDebug(5," ");
157   if (event == 0x0) return;
158
159   for (Int_t i = 0; i < event->GetNumberOfParticles(); i++)
160    {
161      AliVAODParticle* p = event->GetParticle(i);
162      Double_t x,y,z,t=0.0;
163      AliHBTRndm* r = GetRandomizer(p->GetPdgCode());
164      r->Randomize(x,y,z,t,p);
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); 
179    }
180   event->SetRandomized();
181 }
182 /*********************************************************************/
183
184 AliHBTRndm* 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 /*********************************************************************/
192 Int_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
208 void 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
236 void AliHBTPositionRandomizer::SetGaussianBall(Int_t pid, Double_t r, Double_t meantime, Double_t sigmatime)
237 {
238  //Sets Gaussian Ball Model
239   SetGaussianBall(pid,r,r,r,meantime,sigmatime);
240 }
241 /*********************************************************************/
242
243 void AliHBTPositionRandomizer::SetGaussianBall(Int_t pid, Double_t rx, Double_t ry, Double_t rz, Double_t meantime, Double_t sigmatime)
244 {
245  //Sets Gaussian Ball Model
246   AliHBTRndm* rndm = new AliHBTRndmGaussBall(rx,ry,rz,meantime,sigmatime);
247   SetRandomizer(pid,rndm);
248 }
249 /*********************************************************************/
250
251 void AliHBTPositionRandomizer::SetCyllinderSurface(Int_t pid, Double_t r, Double_t l)
252 {
253  //Sets Cylinder Surface Model
254   AliHBTRndm* rndm = new  AliHBTRndmCyllSurf(r,l);
255   SetRandomizer(pid,rndm);
256 }
257 /*********************************************************************/
258
259 void 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 }
266
267
268 void AliHBTPositionRandomizer::SetEllipse(Int_t pid, Double_t rx, Double_t ryz)
269 {
270 //sets the ellipse randomization for the given pid
271   AliHBTRndm* rndm = new AliHBTRndmEllipse(rx,ryz);
272   SetRandomizer(pid,rndm);   
273 }
274
275 /*********************************************************************/
276 //_____________________________________________________________________
277 ///////////////////////////////////////////////////////////////////////
278 //                                                                   //
279 //  class AliHBTRndmGaussBall                                        //
280 //                                                                   //
281 ///////////////////////////////////////////////////////////////////////
282
283 AliHBTRndmGaussBall::AliHBTRndmGaussBall():
284  fRx(0.0),
285  fRy(0.0),
286  fRz(0.0),
287  fTmean(0.0),
288  fTsigma(0.0)
289 {
290   //constructor
291 }
292 /*********************************************************************/
293
294 AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t r, Double_t meantime, Double_t sigmatime):
295  fRx(r),
296  fRy(r),
297  fRz(r),
298  fTmean(meantime),
299  fTsigma(sigmatime)
300 {
301   //constructor
302 }
303 /*********************************************************************/
304
305 AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t rx, Float_t ry, Float_t rz, Double_t meantime, Double_t sigmatime):
306  fRx(rx),
307  fRy(ry),
308  fRz(rz),
309  fTmean(meantime),
310  fTsigma(sigmatime)
311 {
312   //constructor
313 }
314 /*********************************************************************/
315
316
317 AliHBTRndmEllipse::AliHBTRndmEllipse(Float_t rmin, Float_t rmax):
318  fRmin(rmin),
319  fRmax(rmax)
320 {
321      //constructor
322 }
323
324 /*********************************************************************/
325
326 void AliHBTRndmGaussBall::Randomize(Double_t& x,Double_t& y,Double_t&z,Double_t&t, AliVAODParticle*/*particle*/) const
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);
332   
333   if (fTsigma == 0.0)
334    {
335      t = fTmean;
336      return;
337    }
338   
339   t = gRandom->Gaus(fTmean,fTsigma);
340     
341 }
342 /*********************************************************************/
343 //_____________________________________________________________________
344 ///////////////////////////////////////////////////////////////////////
345 //                                                                   //
346 //  class AliHBTRndmGaussBall                                        //
347 //                                                                   //
348 ///////////////////////////////////////////////////////////////////////
349
350 void AliHBTRndmCyllSurf::Randomize(Double_t& x,Double_t& y,Double_t&z,Double_t&/*t*/, AliVAODParticle* particle) const
351 {
352 //Randomizes x,y,z
353    Double_t r = fR + gRandom->Gaus(0.0, 1.0);
354    Double_t sf = r/particle->Pt();//scaling factor for position transformation ->
355                              //we move direction of string momentum but legth defined by r
356    x = sf*particle->Px();
357    y = sf*particle->Py();
358    z = gRandom->Uniform(-fL,fL);
359 }
360
361 /*********************************************************************/
362 /*********************************************************************/
363
364 void AliHBTRndmEllipse::Randomize(Double_t& x, Double_t& y, Double_t& z,Double_t&/*t*/, AliVAODParticle*p) const
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 }