VMC Examples
Version 6.8
Toggle main menu visibility
Loading...
Searching...
No Matches
examples
A01
src
A01PrimaryGenerator.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 A01PrimaryGenerator.cxx
11
/// \brief Implementation of the A01PrimaryGenerator class
12
///
13
/// Geant4 example A01 adapted to Virtual Monte Carlo \n
14
///
15
/// \date 12/05/2012
16
/// \author I. Hrivnacova; IPN, Orsay
17
18
#include <Riostream.h>
19
#include <TDatabasePDG.h>
20
#include <TPDGCode.h>
21
#include <TParticlePDG.h>
22
#include <TRandom.h>
23
#include <TVector3.h>
24
#include <TVirtualMC.h>
25
#include <TVirtualMCApplication.h>
26
#include <TVirtualMCStack.h>
27
28
#include "
A01PrimaryGenerator.h
"
29
30
/// \cond CLASSIMP
31
ClassImp(
A01PrimaryGenerator
)
32
/// \endcond
33
34
//_____________________________________________________________________________
35
A01PrimaryGenerator
::
A01PrimaryGenerator
(
TVirtualMCStack
* stack)
36
:
TObject
(),
37
fStack
(stack),
38
fNofPrimaries
(1),
39
fDefaultParticle
(kMuonPlus),
40
fMomentum
(1.),
// 1 GeV
41
fSigmaMomentum
(50.e-03),
// 50 MeV;
42
fSigmaAngle
(2.),
// 2 deg
43
fRandomizePrimary
(true)
44
{
45
/// Standard constructor
46
/// \param stack The VMC stack
47
}
48
49
//_____________________________________________________________________________
50
A01PrimaryGenerator::A01PrimaryGenerator
(
51
const
A01PrimaryGenerator
& origin,
TVirtualMCStack
* stack)
52
:
TObject
(origin),
53
fStack
(stack),
54
fNofPrimaries
(origin.
fNofPrimaries
),
55
fDefaultParticle
(origin.
fDefaultParticle
),
56
fMomentum
(origin.
fMomentum
),
57
fSigmaMomentum
(origin.
fSigmaMomentum
),
58
fSigmaAngle
(origin.
fSigmaAngle
),
59
fRandomizePrimary
(origin.
fRandomizePrimary
)
60
{
61
/// Copy constructor (for clonig on worker thread in MT mode).
62
/// \param origin The source object (on master).
63
/// \param stack The VMC stack
64
}
65
66
//_____________________________________________________________________________
67
A01PrimaryGenerator::A01PrimaryGenerator
()
68
:
TObject
(),
69
fStack
(0),
70
fNofPrimaries
(0),
71
fDefaultParticle
(kMuonPlus),
72
fMomentum
(1.),
// 1 GeV
73
fSigmaMomentum
(50.e-03),
// 50 MeV;
74
fSigmaAngle
(2.),
// 2 deg
75
fRandomizePrimary
(true)
76
{
77
/// Default constructor
78
}
79
80
//_____________________________________________________________________________
81
A01PrimaryGenerator::~A01PrimaryGenerator
()
82
{
83
/// Destructor
84
}
85
86
//
87
// public methods
88
//
89
90
//_____________________________________________________________________________
91
void
A01PrimaryGenerator::GeneratePrimaries
()
92
{
93
/// Fill the user stack (derived from TVirtualMCStack) with primary particles.
94
/// All primaries in one event have the same properties.
95
96
// Track ID (filled by stack)
97
Int_t ntr;
98
99
// Option: to be tracked
100
Int_t toBeDone = 1;
101
102
Int_t pdg =
fDefaultParticle
;
103
if
(
fRandomizePrimary
) {
104
// Int_t i = (Int_t)(2.*gMC->GetRandom()->Rndm());
105
// Int_t i = (Int_t)(2.*0.3);
106
static
Int_t counter = 0;
107
Int_t i = (counter++) % 5;
108
switch
(i) {
109
case
0:
110
pdg = kPositron;
111
break
;
112
case
1:
113
pdg = kMuonPlus;
114
break
;
115
case
2:
116
pdg = kPiPlus;
117
break
;
118
case
3:
119
pdg = kKPlus;
120
break
;
121
case
4:
122
pdg = kProton;
123
break
;
124
default
:
125
pdg = kPositron;
126
break
;
127
}
128
}
129
130
// Polarization
131
Double_t polx = 0.;
132
Double_t poly = 0.;
133
Double_t polz = 0.;
134
135
// Position
136
Double_t vx = 0;
137
Double_t vy = 0.;
138
Double_t vz = -800.0;
//- 8.*m;
139
Double_t tof = 0.;
140
141
// Particle momentum
142
TDatabasePDG* databasePDG = TDatabasePDG::Instance();
143
TParticlePDG* particlePDG = databasePDG->GetParticle(pdg);
144
Double_t mass = particlePDG->Mass();
145
// Double_t pp = fMomentum + (gMC->GetRandom()->Rndm()-0.5)*fSigmaMomentum;
146
Double_t pp =
fMomentum
+ (0.3 - 0.5) *
fSigmaMomentum
;
147
Double_t e = TMath::Sqrt(pp * pp + mass * mass);
148
149
// Double_t angle = (gMC->GetRandom()->Rndm()-0.5)*fSigmaAngle;
150
Double_t angle = (0.3 - 0.5) *
fSigmaAngle
;
151
Double_t px, py, pz;
152
px = pp * TMath::Sin(angle * TMath::DegToRad());
153
py = 0.;
154
pz = pp * TMath::Cos(angle * TMath::DegToRad());
155
156
for
(Int_t i = 0; i <
fNofPrimaries
; i++) {
157
// Add particle to stack
158
fStack
->PushTrack(toBeDone, -1, pdg, px, py, pz, e, vx, vy, vz, tof, polx,
159
poly, polz, kPPrimary, ntr, 1., 0);
160
}
161
}
A01PrimaryGenerator.h
Definition of the A01PrimaryGenerator class.
A01PrimaryGenerator
The primary generator.
Definition
A01PrimaryGenerator.h:34
A01PrimaryGenerator::~A01PrimaryGenerator
virtual ~A01PrimaryGenerator()
Definition
A01PrimaryGenerator.cxx:81
A01PrimaryGenerator::fStack
TVirtualMCStack * fStack
VMC stack.
Definition
A01PrimaryGenerator.h:63
A01PrimaryGenerator::fNofPrimaries
Int_t fNofPrimaries
Number of primary particles.
Definition
A01PrimaryGenerator.h:64
A01PrimaryGenerator::fMomentum
Double_t fMomentum
Default particle momentum.
Definition
A01PrimaryGenerator.h:66
A01PrimaryGenerator::fSigmaAngle
Double_t fSigmaAngle
The sigma of particle direction.
Definition
A01PrimaryGenerator.h:68
A01PrimaryGenerator::fSigmaMomentum
Double_t fSigmaMomentum
The sigma of particle momentum.
Definition
A01PrimaryGenerator.h:67
A01PrimaryGenerator::A01PrimaryGenerator
A01PrimaryGenerator(TVirtualMCStack *stack)
Definition
A01PrimaryGenerator.cxx:35
A01PrimaryGenerator::fRandomizePrimary
Bool_t fRandomizePrimary
Option to randomize primary particle type.
Definition
A01PrimaryGenerator.h:69
A01PrimaryGenerator::fDefaultParticle
Int_t fDefaultParticle
Default particle PDG.
Definition
A01PrimaryGenerator.h:65
A01PrimaryGenerator::A01PrimaryGenerator
A01PrimaryGenerator()
Definition
A01PrimaryGenerator.cxx:67
A01PrimaryGenerator::GeneratePrimaries
virtual void GeneratePrimaries()
Definition
A01PrimaryGenerator.cxx:91
TObject
TVirtualMCStack
Generated on
for VMC Examples by
1.17.0