FairRoot/PandaRoot
PndBoxGenerator.cxx
Go to the documentation of this file.
1 // -------------------------------------------------------------------------
2 // ----- PndBoxGenerator source file -----
3 // ----- Created 22/05/07 by S.Spataro -----
4 // -------------------------------------------------------------------------
5 
6 
7 #include "TRandom.h"
8 #include "TMath.h"
9 #include "PndBoxGenerator.h"
10 #include "FairPrimaryGenerator.h"
11 #include "TParticlePDG.h"
12 #include "TDatabasePDG.h"
13 
14 // ------------------------------------------------------------------------
16  fPDGType(0),fMult(0),fPDGMass(0),fPtMin(0),fPtMax(0),
17  fPhiMin(0),fPhiMax(0),fEtaMin(0),fEtaMax(0),fYMin(0),fYMax(0),
18  fPMin(0),fPMax(0),fThetaMin(0),fThetaMax(0),fX(0),fY(0),fZ(0),
19  fX1(0),fY1(0),fX2(0),fY2(0),
20  fEtaRangeIsSet(0),fYRangeIsSet(0),fThetaRangeIsSet(0),
21  fCosThetaIsSet(0),fInversePIsSet(0),fPtRangeIsSet(0),fPRangeIsSet(0),
22  fPointVtxIsSet(0), fBoxVtxIsSet(0)
23 {
24  // Default constructor
25 }
26 
27 // ------------------------------------------------------------------------
29  fPDGType(pdgid),fMult(mult),fPDGMass(0),fPtMin(0),fPtMax(0),
30  fPhiMin(0),fPhiMax(0), fEtaMin(0),fEtaMax(0),fYMin(0),fYMax(0),
31  fPMin(0),fPMax(0),fThetaMin(0),fThetaMax(0),fX(0),fY(0),fZ(0),
32  fX1(0),fY1(0),fX2(0),fY2(0),
33  fEtaRangeIsSet(0),fYRangeIsSet(0),fThetaRangeIsSet(0),
34  fCosThetaIsSet(0),fInversePIsSet(0),fPtRangeIsSet(0),fPRangeIsSet(0),
35  fPointVtxIsSet(0), fBoxVtxIsSet(0)
36 
37 {
38  // Constructor. Set default kinematics limits
39  SetPhiRange ();
40 }
41 // ------------------------------------------------------------------------
43 {
44  // Initialize generator
45 
46  if (fPhiMax-fPhiMin>360)
47  Fatal("Init()","PndBoxGenerator: phi range is too wide: %f<phi<%f",
50  Fatal("Init()","PndBoxGenerator: Cannot set P and Pt ranges simultaneously");
52  Fatal("Init()","PndBoxGenerator: Cannot set P and Y ranges simultaneously");
53  if ( (fThetaRangeIsSet && fYRangeIsSet) ||
56  Fatal("Init()","PndBoxGenerator: Cannot set Y, Theta or Eta ranges simultaneously");
58  Fatal("Init()","PndBoxGenerator: Cannot set point and box vertices simultaneously");
59  if (fInversePIsSet && ( ( fPRangeIsSet && ( fPMin==0 || fPMax==0 ) ) || ( fPRangeIsSet && ( fPtMin==0 || fPtMax==0 ) ) ) )
60  Fatal("Init()","PndBoxGenerator: Cannot use P == 0 as limit for inverse momentum distribution");
61 
62  // Check for particle type
63  TDatabasePDG* pdgBase = TDatabasePDG::Instance();
64  TParticlePDG *particle = pdgBase->GetParticle(fPDGType);
65  if (! particle) Fatal("PndBoxGenerator","PDG code %d not defined.",fPDGType);
66  fPDGMass = particle->Mass();
67  return kTRUE;
68 }
69 
70 // ------------------------------------------------------------------------
72 {
73  // Generate one event: produce primary particles emitted from one vertex.
74  // Primary particles are distributed uniformly along
75  // those kinematics variables which were limitted by setters.
76  // if SetCosTheta() function is used, the distribution will be uniform in cos(theta)
77 
78  Double32_t pabs, phi, pt, theta=0, eta, y, mt, px, py, pz, pinv=0;
79 
80  // Generate particles
81  for (Int_t k = 0; k < fMult; k++) {
82  phi = gRandom->Uniform(fPhiMin,fPhiMax) * TMath::DegToRad();
83 
84  if (fPRangeIsSet ) {
85  if (fInversePIsSet)
86  {
87  pinv = gRandom->Uniform(1./fPMax, 1./fPMin);
88  pabs = 1./pinv;
89  }
90  else
91  {
92  pabs = gRandom->Uniform(fPMin,fPMax);
93  }
94  }
95  else if (fPtRangeIsSet) {
96  if (fInversePIsSet)
97  {
98  pinv = gRandom->Uniform(1./fPtMax, 1./fPtMin);
99  pt = 1./pinv;
100  }
101  else
102  {
103  pt = gRandom->Uniform(fPtMin,fPtMax);
104  }
105  }
106 
107  if (fThetaRangeIsSet) {
108  if (fCosThetaIsSet)
109  theta = acos(gRandom->Uniform(cos(fThetaMin* TMath::DegToRad()),cos(fThetaMax* TMath::DegToRad())));
110  else
111  theta = gRandom->Uniform(fThetaMin,fThetaMax) * TMath::DegToRad();
112  }
113  else if (fEtaRangeIsSet) {
114  eta = gRandom->Uniform(fEtaMin,fEtaMax);
115  theta = 2*TMath::ATan(TMath::Exp(-eta));
116  }
117  else if (fYRangeIsSet) {
118  y = gRandom->Uniform(fYMin,fYMax);
119  mt = TMath::Sqrt(fPDGMass*fPDGMass + pt*pt);
120  pz = mt * TMath::SinH(y);
121  }
122 
124  if (fPRangeIsSet ) {
125  pz = pabs*TMath::Cos(theta);
126  pt = pabs*TMath::Sin(theta);
127  }
128  else if (fPtRangeIsSet)
129  pz = pt/TMath::Tan(theta);
130  }
131 
132  px = pt*TMath::Cos(phi);
133  py = pt*TMath::Sin(phi);
134 
135  if (fBoxVtxIsSet) {
136  fX = gRandom->Uniform(fX1,fX2);
137  fY = gRandom->Uniform(fY1,fY2);
138  }
139 
140  if (fDebug)
141  printf("BoxGen: kf=%d, p=(%.2f, %.2f, %.2f) GeV, x=(%.1f, %.1f, %.1f) cm\n",
142  fPDGType, px, py, pz, fX, fY, fZ);
143 
144  primGen->AddTrack(fPDGType, px, py, pz, fX, fY, fZ);
145  }
146  return kTRUE;
147 
148 }
149 // ------------------------------------------------------------------------
150 
151 
friend F32vec4 acos(const F32vec4 &a)
Definition: P4_F32vec4.h:113
printf("RealTime=%f seconds, CpuTime=%f seconds\n", rtime, ctime)
friend F32vec4 cos(const F32vec4 &a)
Definition: P4_F32vec4.h:112
Double32_t fYMax
Double32_t fPtMin
Double32_t fPhiMin
static T Sqrt(const T &x)
Definition: PndCAMath.h:37
Double32_t fEtaMin
Double32_t fPMax
static T Sin(const T &x)
Definition: PndCAMath.h:42
Double_t fX
Definition: PndCaloDraw.cxx:34
float Tan(float x)
Definition: PndCAMath.h:165
static T Cos(const T &x)
Definition: PndCAMath.h:43
Double_t fZ
Definition: PndCaloDraw.cxx:34
Double_t fThetaMin
Definition: run_full.C:19
Double32_t fPhiMax
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 fPDGMass
Double32_t fThetaMin
Double32_t fPMin
virtual Bool_t ReadEvent(FairPrimaryGenerator *primGen)
Double32_t fEtaMax
Double_t fPMax
Definition: run_full.C:18
Double_t fY
Definition: PndCaloDraw.cxx:34
Double32_t fYMin
ClassImp(PndAnaContFact)
TParticlePDG * eta
Double_t y
Double_t fThetaMax
Definition: run_full.C:21
Double32_t fPtMax
Double_t mult
void SetPhiRange(Double32_t phimin=0, Double32_t phimax=360)
double pz[39]
Definition: pipisigmas.h:14