VMC Examples Version 6.6
Loading...
Searching...
No Matches
Ex06PrimaryGenerator.cxx
Go to the documentation of this file.
1//------------------------------------------------
2// The Virtual Monte Carlo examples
3// Copyright (C) 2007 - 2014 Ivana Hrivnacova
4// All rights reserved.
5//
6// For the licensing terms see geant4_vmc/LICENSE.
7// Contact: root-vmc@cern.ch
8//-------------------------------------------------
9
10/// \file Ex06PrimaryGenerator.cxx
11/// \brief Implementation of the class
12///
13/// Geant4 ExampleN06 adapted to Virtual Monte Carlo \n
14/// Id: ExN06PrimaryGeneratorAction.cc,v 1.3 2004/04/02 11:54:29 maire Exp \n
15/// GEANT4 tag Name: geant4-07-00-cand-01
16///
17/// \date 16/05/2005
18/// \author I. Hrivnacova; IPN, Orsay
19
20#include <TDatabasePDG.h>
21#include <TMath.h>
22#include <TPDGCode.h>
23#include <TParticlePDG.h>
24#include <TVector3.h>
25#include <TVirtualMC.h>
26#include <TVirtualMCStack.h>
27
29
30/// \cond CLASSIMP
32 /// \endcond
33
34 //_____________________________________________________________________________
36 : TObject(),
37 fStack(stack),
38 fPdg(kPositron),
39 fKinEnergy(500.e-06),
40 fDirX(1.),
41 fDirY(0.),
42 fDirZ(0.),
43 fPolAngle(0.),
44 fNofPrimaries(1)
45{
46 /// Standard constructor
47 /// \param stack The VMC stack
48}
49
50//_____________________________________________________________________________
52 const Ex06PrimaryGenerator& origin, TVirtualMCStack* stack)
53 : TObject(origin),
54 fStack(stack),
55 fPdg(origin.fPdg),
56 fKinEnergy(origin.fKinEnergy),
57 fDirX(origin.fDirX),
58 fDirY(origin.fDirY),
59 fDirZ(origin.fDirZ),
60 fPolAngle(origin.fPolAngle),
61 fNofPrimaries(origin.fNofPrimaries)
62{
63 /// Copy constructor (for clonig on worker thread in MT mode).
64 /// \param origin The source object (on master).
65 /// \param stack The VMC stack
66}
67
68//_____________________________________________________________________________
70 : TObject(),
71 fStack(0),
72 fPdg(0),
73 fKinEnergy(0.),
74 fDirX(0.),
75 fDirY(0.),
76 fDirZ(0.),
77 fPolAngle(0.),
78 fNofPrimaries(0)
79{
80 /// Default constructor
81}
82
83//_____________________________________________________________________________
88
89//
90// private methods
91//
92
93#include <Riostream.h>
94//_____________________________________________________________________________
96{
97 /// Add one primary particle to the user stack
98 /// (derived from TVirtualMCStack).
99
100 // Track ID (filled by stack)
101 Int_t ntr;
102
103 // Option: to be tracked
104 Int_t toBeDone = 1;
105
106 // Particle type
107 Int_t pdg = fPdg;
108 TParticlePDG* particlePDG = TDatabasePDG::Instance()->GetParticle(fPdg);
109
110 // Position
111 Double_t vx = 0.;
112 Double_t vy = 0.;
113 Double_t vz = 0.;
114 Double_t tof = 0.;
115
116 // Energy (in GeV)
117 Double_t kinEnergy = fKinEnergy;
118 Double_t mass = particlePDG->Mass();
119 // Double_t mass = 0.51099906*1e-03;
120 Double_t e = mass + kinEnergy;
121
122 // Particle momentum
123 Double_t p0, px, py, pz;
124 p0 = sqrt(e * e - mass * mass);
125 px = p0 * fDirX;
126 py = p0 * fDirY;
127 pz = p0 * fDirZ;
128
129 // Polarization
130 TVector3 polar;
131 if (fPdg == 50000050) {
132 TVector3 normal(1., 0., 0.);
133 TVector3 kphoton = TVector3(fDirX, fDirY, fDirZ);
134 TVector3 product = normal.Cross(kphoton);
135 Double_t modul2 = product * product;
136
137 TVector3 e_perpend(0., 0., 1.);
138 if (modul2 > 0.) e_perpend = (1. / sqrt(modul2)) * product;
139 TVector3 e_paralle = e_perpend.Cross(kphoton);
140
141 polar = TMath::Cos(fPolAngle * TMath::DegToRad()) * e_paralle +
142 TMath::Sin(fPolAngle * TMath::DegToRad()) * e_perpend;
143 }
144 // else
145 // Warning("GeneratePrimary",
146 // "The primary particle is not an opticalphoton");
147
148 // Add particle to stack
149 fStack->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof,
150 polar.X(), polar.Y(), polar.Z(), kPPrimary, ntr, 1., 0);
151}
152
153//
154// public methods
155//
156
157//_____________________________________________________________________________
159{
160 /// Fill the user stack (derived from TVirtualMCStack) with primary particle
161
162 for (Int_t i = 0; i < fNofPrimaries; i++) GeneratePrimary();
163}
164
165//_____________________________________________________________________________
167 Double_t dirX, Double_t dirY, Double_t dirZ)
168{
169 /// Set normalized direction
170 /// \param dirX The new direction - x component
171 /// \param dirY The new direction - y component
172 /// \param dirZ The new direction - z component
173
174 Double_t norm = TMath::Sqrt(dirX * dirX + dirY * dirY + dirZ * dirZ);
175
176 fDirX = dirX / norm;
177 fDirY = dirY / norm;
178 fDirZ = dirZ / norm;
179}
Definition of the Ex06PrimaryGenerator class.
The primary generator.
Double_t fDirY
Particle direction - y component.
Double_t fDirZ
Particle direction - z component.
void SetDirection(Double_t dirX, Double_t dirY, Double_t dirZ)
TVirtualMCStack * fStack
VMC stack.
Double_t fPolAngle
Particle polarization angle.
Int_t fNofPrimaries
Number of primary particles.
Int_t fPdg
Particle PDG encoding.
Double_t fKinEnergy
Particle kinetic energy.
Double_t fDirX
Particle direction - x component.