FairRoot/PandaRoot
PndGasGenerator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndGasGenerator source file -----
3 // ----- Created 02/04/09 by F. Uhlig -----
4 // -------------------------------------------------------------------------
5 
6 
7 #include "PndGasGenerator.h"
8 
9 #include "FairPrimaryGenerator.h"
10 
11 #include "TRandom.h"
12 #include "TMath.h"
13 #include "TF1.h"
14 #include "TParticlePDG.h"
15 #include "TDatabasePDG.h"
16 
17 // ------------------------------------------------------------------------
19  fPDGType(0),fMult(0),fPDGMass(0),
20  fPhiMin(0),fPhiMax(0),
21  fPMin(0),fPMax(0),fThetaMin(0),fThetaMax(0),fX(0),fY(0),fZ(0),
22  fThetaRangeIsSet(0),
23  fCosThetaIsSet(0),fPRangeIsSet(0),
24  fZMin(0.), fZMax(10.), fDensityProfile(NULL)
25 {
26  // Default constructor
27 }
28 
29 // ------------------------------------------------------------------------
31  fPDGType(pdgid),fMult(mult),fPDGMass(0),
32  fPMin(0),fPMax(0),fX(0),fY(0),fZ(0),
33  fThetaRangeIsSet(0),
34  fCosThetaIsSet(0),fPRangeIsSet(0),
35  fZMin(0.), fZMax(10.), fDensityProfile(NULL)
36 {
37  // Constructor. Set default kinematics limits
38  SetPhiRange ();
39 }
40 
41 // ------------------------------------------------------------------------
43 {
44  // Initialize generator
45 
46  if (fPhiMax-fPhiMin>360)
47  Fatal("Init()","PndGasGenerator: phi range is too wide: %f<phi<%f",
49 
50  // Check for particle type
51  TDatabasePDG* pdgBase = TDatabasePDG::Instance();
52  TParticlePDG *particle = pdgBase->GetParticle(fPDGType);
53  if (! particle) Fatal("PndGasGenerator","PDG code %d not defined.",fPDGType);
54  fPDGMass = particle->Mass();
55 
56  // create the density profile histogram used later to get the random
57  // z position
58  fDensityProfile = new TF1("Density Profile","exp(-0.5*((x)/4)**2)",fZMin,fZMax);
59  return kTRUE;
60 }
61 
62 // ------------------------------------------------------------------------
64 {
65  // Generate one event: produce primary particles emitted from one vertex.
66  // Primary particles are distributed uniformly along
67  // those kinematics variables which were limitted by setters.
68  // if SetCosTheta() function is used, the distribution will be uniform in cos(theta)
69 
70  Double32_t pabs, phi, pt, theta=0, px, py, pz;
71  //Double32_t eta, pinv, y, mt=0; //[R.K. 01/2017] unused variable?
72 
73  // Generate particles
74  for (Int_t k = 0; k < fMult; k++) {
75 
76  phi = gRandom->Uniform(fPhiMin,fPhiMax) * TMath::DegToRad();
77 
78  pabs = gRandom->Uniform(fPMin,fPMax);
79 
80 
81  if (fCosThetaIsSet) {
82  theta = acos(gRandom->Uniform(cos(fThetaMin* TMath::DegToRad()),cos(fThetaMax* TMath::DegToRad())));
83  } else {
84  theta = gRandom->Uniform(fThetaMin,fThetaMax) * TMath::DegToRad();
85  }
86 
87 
88 
89  pz = pabs*TMath::Cos(theta);
90  pt = pabs*TMath::Sin(theta);
91 
92  px = pt*TMath::Cos(phi);
93  py = pt*TMath::Sin(phi);
94 
95  // Random 2D point in a circle of radius r (simple beamprofile)
96  gRandom->Circle(fX, fY, fRadius);
97 
98  // calculate fZ according to some (probability) density function of the gas
99  fZ=fDensityProfile->GetRandom();
100 
101  if (fDebug)
102  printf("GasGen: kf=%d, p=(%.2f, %.2f, %.2f) GeV, x=(%.1f, %.1f, %.1f) cm\n",
103  fPDGType, px, py, pz, fX, fY, fZ);
104 
105 
106 
107  primGen->AddTrack(fPDGType, px, py, pz, fX, fY, fZ);
108 
109 
110 
111  }
112  return kTRUE;
113 
114 }
115 // ------------------------------------------------------------------------
116 
117 
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
Double32_t fPDGMass
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
Double32_t fPhiMax
static T Sin(const T &x)
Definition: PndCAMath.h:42
Double_t fX
Definition: PndCaloDraw.cxx:34
static T Cos(const T &x)
Definition: PndCAMath.h:43
Double_t fZ
Definition: PndCaloDraw.cxx:34
Double32_t fPMax
Double_t fThetaMin
Definition: run_full.C:19
Double_t fPMin
Definition: run_full.C:16
FairPrimaryGenerator * primGen
Definition: sim_emc_apd.C:81
TString pt(TString pts, TString exts="px py pz")
Definition: invexp.C:133
const int particle
Double32_t fThetaMax
Double32_t fZMin
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Double32_t fPMin
Double32_t fRadius
Double32_t fThetaMin
Double_t fPMax
Definition: run_full.C:18
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
Double_t fY
Definition: PndCaloDraw.cxx:34
ClassImp(PndAnaContFact)
Double_t fThetaMax
Definition: run_full.C:21
Double32_t fPhiMin
Double_t mult
double pz[39]
Definition: pipisigmas.h:14
Double32_t fZMax