]> git.uio.no Git - u/mrichter/AliRoot.git/blobdiff - HBTAN/AliHBTPositionRandomizer.cxx
Streamline the different messages output by the code using the AliLog, Remove warning...
[u/mrichter/AliRoot.git] / HBTAN / AliHBTPositionRandomizer.cxx
index 3a79697c6a6ee58a638341e9c4e3e263c6ec948a..affe33d0cf7a707943bd7f6ebe54734105517b71 100644 (file)
@@ -1,4 +1,20 @@
-#include "AliHBTPositionRandomizer.h"
+/**************************************************************************
+ * Copyright(c) 1998-1999, ALICE Experiment at CERN, All rights reserved. *
+ *                                                                        *
+ * Author: The ALICE Off-line Project.                                    *
+ * Contributors are mentioned in the code where appropriate.              *
+ *                                                                        *
+ * Permission to use, copy, modify and distribute this software and its   *
+ * documentation strictly for non-commercial purposes is hereby granted   *
+ * without fee, provided that the above copyright notice appears in all   *
+ * copies and that both the copyright notice and this permission notice   *
+ * appear in the supporting documentation. The authors make no claims     *
+ * about the suitability of this software for any purpose. It is          *
+ * provided "as is" without express or implied warranty.                  *
+ **************************************************************************/
+
+/* $Id $ */
+
 //___________________________________________________
 ////////////////////////////////////////////////////////////////////////////////
 // 
 ////////////////////////////////////////////////////////////////////////////////
 
 #include <TRandom.h>
-#include "AliHBTRun.h"
-#include "AliHBTEvent.h"
-#include "AliHBTParticle.h"
+
+#include "AliAOD.h"
+#include "AliHBTPositionRandomizer.h"
+#include "AliLog.h"
+#include "AliVAODParticle.h"
 
 
 ClassImp(AliHBTPositionRandomizer)
 
+const Int_t AliHBTPositionRandomizer::fgkNumberOfPids = 10;
+
 /*********************************************************************/
 
 AliHBTPositionRandomizer::AliHBTPositionRandomizer():
  fReader(0x0),
- fRandomizer(0x0),
- fModel(0),
+ fDefaultRandomizer(0x0),
+ fRandomizers(0x0),
+ fNPid(0),
+ fPids(0x0),
  fAddToExistingPos(kFALSE),
  fOnlyParticlesFromVertex(kFALSE),
+ fRandomizeTracks(kFALSE),
  fVX(0.0),
  fVY(0.0),
  fVZ(0.0)
@@ -33,27 +56,32 @@ AliHBTPositionRandomizer::AliHBTPositionRandomizer():
 }
 /*********************************************************************/
 
-AliHBTPositionRandomizer::AliHBTPositionRandomizer(AliHBTReader* reader):
+AliHBTPositionRandomizer::AliHBTPositionRandomizer(AliReader* reader):
  fReader(reader),
- fRandomizer(new AliHBTRndmGaussBall(8.0)),
- fModel(0),
+ fRandomizers(new TObjArray(fgkNumberOfPids)),
+ fNPid(1),
+ fPids(new Int_t[fgkNumberOfPids]),
  fAddToExistingPos(kFALSE),
  fOnlyParticlesFromVertex(kFALSE),
+ fRandomizeTracks(kFALSE),
  fVX(0.0),
  fVY(0.0),
  fVZ(0.0)
 {
 //constructor
+ fRandomizers->AddAt(new AliHBTRndmGaussBall(8.0,0.0,0.0),0);
 } 
 /*********************************************************************/
 
 AliHBTPositionRandomizer::AliHBTPositionRandomizer(const AliHBTPositionRandomizer& in):
- AliHBTReader(in),
+ AliReader(in),
  fReader(),
- fRandomizer(0x0),
- fModel(0),
+ fRandomizers(0x0),
+ fNPid(0),
+ fPids(0x0),
  fAddToExistingPos(kFALSE),
  fOnlyParticlesFromVertex(kFALSE),
+ fRandomizeTracks(kFALSE),
  fVX(0.0),
  fVY(0.0),
  fVZ(0.0)
@@ -66,10 +94,11 @@ AliHBTPositionRandomizer::~AliHBTPositionRandomizer()
 {
   //dtor
   delete fReader;
-  delete fRandomizer;
+  delete fRandomizers;
+  delete [] fPids;
 }
 /*********************************************************************/
-const AliHBTPositionRandomizer& AliHBTPositionRandomizer::operator=(const AliHBTPositionRandomizer& in)
+AliHBTPositionRandomizer& AliHBTPositionRandomizer::operator=(const AliHBTPositionRandomizer& in)
 {
   //assigment operator
   in.Copy(*this);
@@ -77,98 +106,150 @@ const AliHBTPositionRandomizer& AliHBTPositionRandomizer::operator=(const AliHBT
 }
 /*********************************************************************/
 
-AliHBTEvent* AliHBTPositionRandomizer::GetParticleEvent() 
+AliAOD* AliHBTPositionRandomizer::GetEventSim() const
 {
  // gets from fReader and randomizes current particle event
- if (fReader == 0x0) return 0x0;
- AliHBTEvent *e =  fReader->GetParticleEvent();
- if (e->IsRandomized() == kFALSE) Randomize(e);
+ if (fReader == 0x0) 
+  {
+    Error("GetEventSim","Reader is null");
+    return 0x0;
+  } 
+ AliAOD *e =  fReader->GetEventSim();
+ if (e) 
+   if (e->IsRandomized() == kFALSE) 
+     Randomize(e);
  return e;
 }
 /*********************************************************************/
 
-AliHBTEvent* AliHBTPositionRandomizer::GetTrackEvent() 
+AliAOD* AliHBTPositionRandomizer::GetEventRec() const
 {
  // gets from fReader and randomizes current track event
- if (fReader == 0x0) return 0x0;
- AliHBTEvent *e =  fReader->GetTrackEvent();
- if (e->IsRandomized() == kFALSE) Randomize(e);
+ if (fReader == 0x0) 
+  {
+    Error("GetEventRec","Reader is null");
+    return 0x0;
+  }  
+ AliAOD *e =  fReader->GetEventRec();
+ if (fRandomizeTracks && e) if (e->IsRandomized() == kFALSE) Randomize(e);
  return e;
 }
 /*********************************************************************/
 
-Int_t AliHBTPositionRandomizer::Read(AliHBTRun* particles, AliHBTRun *tracks)
-{
-  //Reads all available events and randomizes them
-  if (fReader == 0x0) return 1;
-  Info("Randomize(AliHBTRun*)","");
-  Int_t err = fReader->Read(particles,tracks);
-  if (err) return err;
-  Randomize(particles);
-  return 0;
-}
-/*********************************************************************/
-
-AliHBTEvent* AliHBTPositionRandomizer::GetParticleEvent(Int_t n)
+AliAOD* AliHBTPositionRandomizer::GetEventSim(Int_t n)
 {
 //returns event n
  if (fReader == 0x0) return 0x0;
- AliHBTEvent *e =  fReader->GetParticleEvent(n);
+ AliAOD *e =  fReader->GetEventSim(n);
  if (e->IsRandomized() == kFALSE) Randomize(e);
  return e;
 }
 
 /*********************************************************************/
-
-void AliHBTPositionRandomizer::Randomize(AliHBTRun* run) const
-{
-// randomizes postions of all particles in the run
-  if (run == 0x0) return;
-  Info("Randomize(AliHBTRun*)","");
-  for (Int_t i = 0; i < run->GetNumberOfEvents(); i++)
-   {
-     Randomize(run->GetEvent(i));
-   }
-}
-/*********************************************************************/
-void AliHBTPositionRandomizer::Randomize(AliHBTEvent* event) const
+void AliHBTPositionRandomizer::Randomize(AliAOD* event) const
 {
 // randomizes postions of all particles in the event
   static const Double_t kfmtocm = 1.e-13;
-  Info("Randomize(AliHBTEvent*)","");
+  AliDebug(5," ");
   if (event == 0x0) return;
 
   for (Int_t i = 0; i < event->GetNumberOfParticles(); i++)
    {
-     AliHBTParticle* p = event->GetParticle(i);
+     AliVAODParticle* p = event->GetParticle(i);
      Double_t x,y,z,t=0.0;
-     fRandomizer->Randomize(x,y,z,p);
-     p->SetProductionVertex(x*kfmtocm,y*kfmtocm,z*kfmtocm,t*kfmtocm);
+     AliHBTRndm* r = GetRandomizer(p->GetPdgCode());
+     r->Randomize(x,y,z,t,p);
+     
+     Double_t nx = x*kfmtocm;
+     Double_t ny = y*kfmtocm;
+     Double_t nz = z*kfmtocm;
+     Double_t nt = t*kfmtocm;
+     
+     if (fAddToExistingPos)
+      {
+       nx += p->Vx();
+       ny += p->Vy();
+       nz += p->Vz();
+       nt += p->T();
+      }
+     p->SetProductionVertex(nx,ny,nz,nt); 
    }
   event->SetRandomized();
 }
 /*********************************************************************/
 
-void AliHBTPositionRandomizer::SetGaussianBall(Double_t r)
+AliHBTRndm* AliHBTPositionRandomizer::GetRandomizer(Int_t pdg) const
+{
+  //returns randomizer for a given pdg 
+  Int_t idx = GetRandomizerIndex(pdg);//in most of cases 
+  if (idx < 0) idx = 0;//if not found return a default one
+  return (AliHBTRndm*)fRandomizers->At(idx);
+}
+/*********************************************************************/
+Int_t AliHBTPositionRandomizer::GetRandomizerIndex(Int_t pdg) const
+{
+  //returns randomizer index for a given pdg 
+
+  if (pdg == 0) return 0;
+  
+  for (Int_t i=1; i < fNPid; i++)
+   {
+     if (fPids[i] == pdg) 
+      return i;
+   }
+   
+  return -1;
+}
+/*********************************************************************/
+
+void AliHBTPositionRandomizer::SetRandomizer(Int_t pid, AliHBTRndm* rndm)
+{
+ //sets the randomizer for a given particle type
+  if (rndm == 0x0)
+   {
+     Error("SetRandomizer","Randomizer is null");
+     return;
+   }
+   
+  Int_t idx = GetRandomizerIndex(pid);
+  if (idx >= 0) 
+   {
+     delete fRandomizers->At(idx);
+     fRandomizers->AddAt(rndm,idx);
+   }  
+  
+  if (fNPid == fgkNumberOfPids)
+   {
+     Error("SetRandomizer","There is no more space in the array");
+     return;
+   }
+
+  fPids[fNPid] = pid;
+  fRandomizers->AddAt(rndm,fNPid);
+  fNPid++;
+}
+/*********************************************************************/
+
+void AliHBTPositionRandomizer::SetGaussianBall(Int_t pid, Double_t r, Double_t meantime, Double_t sigmatime)
 {
  //Sets Gaussian Ball Model
-  SetGaussianBall(r,r,r);
+  SetGaussianBall(pid,r,r,r,meantime,sigmatime);
 }
 /*********************************************************************/
 
-void AliHBTPositionRandomizer::SetGaussianBall(Double_t rx, Double_t ry, Double_t rz)
+void AliHBTPositionRandomizer::SetGaussianBall(Int_t pid, Double_t rx, Double_t ry, Double_t rz, Double_t meantime, Double_t sigmatime)
 {
  //Sets Gaussian Ball Model
-  delete fRandomizer;
-  fRandomizer = new AliHBTRndmGaussBall(rx,ry,rz);
+  AliHBTRndm* rndm = new AliHBTRndmGaussBall(rx,ry,rz,meantime,sigmatime);
+  SetRandomizer(pid,rndm);
 }
 /*********************************************************************/
 
-void AliHBTPositionRandomizer::SetCyllinderSurface(Double_t r, Double_t l)
+void AliHBTPositionRandomizer::SetCyllinderSurface(Int_t pid, Double_t r, Double_t l)
 {
  //Sets Cylinder Surface Model
-  delete fRandomizer;
-  fRandomizer = new  AliHBTRndmCyllSurf(r,l);
+  AliHBTRndm* rndm = new  AliHBTRndmCyllSurf(r,l);
+  SetRandomizer(pid,rndm);
 }
 /*********************************************************************/
 
@@ -179,6 +260,15 @@ void AliHBTPositionRandomizer::SetEventVertex(Double_t x, Double_t y,Double_t z)
   fVY = y;
   fVZ = z;
 }
+
+
+void AliHBTPositionRandomizer::SetEllipse(Int_t pid, Double_t rx, Double_t ryz)
+{
+//sets the ellipse randomization for the given pid
+  AliHBTRndm* rndm = new AliHBTRndmEllipse(rx,ryz);
+  SetRandomizer(pid,rndm);   
+}
+
 /*********************************************************************/
 //_____________________________________________________________________
 ///////////////////////////////////////////////////////////////////////
@@ -190,36 +280,61 @@ void AliHBTPositionRandomizer::SetEventVertex(Double_t x, Double_t y,Double_t z)
 AliHBTRndmGaussBall::AliHBTRndmGaussBall():
  fRx(0.0),
  fRy(0.0),
- fRz(0.0)
+ fRz(0.0),
+ fTmean(0.0),
+ fTsigma(0.0)
 {
   //constructor
 }
 /*********************************************************************/
 
-AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t r):
+AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t r, Double_t meantime, Double_t sigmatime):
  fRx(r),
  fRy(r),
- fRz(r)
+ fRz(r),
+ fTmean(meantime),
+ fTsigma(sigmatime)
 {
   //constructor
 }
 /*********************************************************************/
 
-AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t rx, Float_t ry, Float_t rz):
+AliHBTRndmGaussBall::AliHBTRndmGaussBall(Float_t rx, Float_t ry, Float_t rz, Double_t meantime, Double_t sigmatime):
  fRx(rx),
  fRy(ry),
- fRz(rz)
+ fRz(rz),
+ fTmean(meantime),
+ fTsigma(sigmatime)
 {
   //constructor
 }
 /*********************************************************************/
 
-void AliHBTRndmGaussBall::Randomize(Double_t& x,Double_t& y,Double_t&z, AliHBTParticle*/*particle*/) const
+
+AliHBTRndmEllipse::AliHBTRndmEllipse(Float_t rmin, Float_t rmax):
+ fRmin(rmin),
+ fRmax(rmax)
+{
+     //constructor
+}
+
+/*********************************************************************/
+
+void AliHBTRndmGaussBall::Randomize(Double_t& x,Double_t& y,Double_t&z,Double_t&t, AliVAODParticle*/*particle*/) const
 {
 //randomizez gauss for each coordinate separately
   x = gRandom->Gaus(0.0,fRx);
   y = gRandom->Gaus(0.0,fRy);
   z = gRandom->Gaus(0.0,fRz);
+  
+  if (fTsigma == 0.0)
+   {
+     t = fTmean;
+     return;
+   }
+  
+  t = gRandom->Gaus(fTmean,fTsigma);
+    
 }
 /*********************************************************************/
 //_____________________________________________________________________
@@ -229,7 +344,7 @@ void AliHBTRndmGaussBall::Randomize(Double_t& x,Double_t& y,Double_t&z, AliHBTPa
 //                                                                   //
 ///////////////////////////////////////////////////////////////////////
 
-void AliHBTRndmCyllSurf::Randomize(Double_t& x,Double_t& y,Double_t&z, AliHBTParticle* particle) const
+void AliHBTRndmCyllSurf::Randomize(Double_t& x,Double_t& y,Double_t&z,Double_t&/*t*/, AliVAODParticle* particle) const
 {
 //Randomizes x,y,z
    Double_t r = fR + gRandom->Gaus(0.0, 1.0);
@@ -239,3 +354,18 @@ void AliHBTRndmCyllSurf::Randomize(Double_t& x,Double_t& y,Double_t&z, AliHBTPar
    y = sf*particle->Py();
    z = gRandom->Uniform(-fL,fL);
 }
+
+/*********************************************************************/
+/*********************************************************************/
+
+void AliHBTRndmEllipse::Randomize(Double_t& x, Double_t& y, Double_t& z,Double_t&/*t*/, AliVAODParticle*p) const
+{
+    // p=0; //workaround - fix this damn little thingy
+   double R;
+     double phi=p->Phi();
+     
+     R=fRmin+(fRmax-fRmin)*TMath::Sin(phi);
+     x=R*TMath::Sin(phi);
+     y=R*TMath::Cos(phi);
+     z=z;
+}