MpdHypYPtGenerator.cxx 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // -------------------------------------------------------------------------
  2. // ----- CbmAnaHypYPtGenerator source file -----
  3. // ----- Created 03/10/04 by E. Kryshen -----
  4. // ----- Updated 10/02/10 by A. Zinchenko for MPD (with name change) -----
  5. // -------------------------------------------------------------------------
  6. #include "TRandom.h"
  7. #include "MpdHypYPtGenerator.h"
  8. #include "FairPrimaryGenerator.h"
  9. #include "TParticlePDG.h"
  10. #include "TDatabasePDG.h"
  11. #include "TF1.h"
  12. #include "TMath.h"
  13. // ------------------------------------------------------------------------
  14. MpdHypYPtGenerator::MpdHypYPtGenerator():FairGenerator()
  15. {
  16. // Default constructor
  17. fPDGType = -1;
  18. fMult = 0;
  19. }
  20. // ------------------------------------------------------------------------
  21. MpdHypYPtGenerator::MpdHypYPtGenerator(Int_t pdgid, Int_t mult, Double_t yield)
  22. :FairGenerator(), fPDGType(pdgid), fMult(mult), fYield(yield)
  23. {
  24. // Constructor. Set default distributions
  25. SetDistributionPt();
  26. SetDistributionY();
  27. SetRangePt();
  28. }
  29. // ------------------------------------------------------------------------
  30. Bool_t MpdHypYPtGenerator::Init()
  31. {
  32. // Initialize generator
  33. // Check for particle type
  34. TDatabasePDG* pdgBase = TDatabasePDG::Instance();
  35. TParticlePDG *particle = pdgBase->GetParticle(fPDGType);
  36. if (! particle) {
  37. Fatal("CbmAnaHypYPtGenerator","PDG code %d not defined.",fPDGType);
  38. return kFALSE;
  39. }
  40. fPDGMass = particle->Mass();
  41. //gRandom->SetSeed(0);
  42. fDistPt = new TF1("distPt","x*exp(-sqrt(x*x+[1]*[1])/[0])",fPtMin,fPtMax);
  43. fDistPt->SetParameters(fT,fPDGMass,fY0,fSigma);
  44. Info("Init","pdg=%i y0=%4.2f sigma_y=%4.2f T_pt=%6.4f",fPDGType,fY0,fSigma,fT);
  45. return kTRUE;
  46. }
  47. // ------------------------------------------------------------------------
  48. Bool_t MpdHypYPtGenerator::ReadEvent(FairPrimaryGenerator* primGen)
  49. {
  50. Double_t phi, pt, y, mt, px, py, pz;
  51. Double_t aaa = gRandom->Rndm();
  52. if (fYield > 0 && gRandom->Rndm() > fYield) return kTRUE;
  53. // Generate particles
  54. for (Int_t k = 0; k < fMult; k++) {
  55. phi = gRandom->Uniform(0,TMath::TwoPi());
  56. pt = fDistPt->GetRandom(fPtMin,fPtMax);
  57. px = pt*TMath::Cos(phi);
  58. py = pt*TMath::Sin(phi);
  59. y = gRandom->Gaus(fY0,fSigma);
  60. mt = TMath::Sqrt(fPDGMass*fPDGMass + pt*pt);
  61. pz = mt * TMath::SinH(y);
  62. Info("ReadEvent","Particle generated: pdg=%i pt=%f y=%f\n",fPDGType,pt,y);
  63. primGen->AddTrack(fPDGType, px, py, pz, 0, 0, 0);
  64. }
  65. return kTRUE;
  66. }
  67. // ------------------------------------------------------------------------
  68. ClassImp(MpdHypYPtGenerator)