ECCE @ EIC Software
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
B5PrimaryGeneratorAction.cc
Go to the documentation of this file. Or view the newest version in sPHENIX GitHub for file B5PrimaryGeneratorAction.cc
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
29 
31 
32 #include "G4Event.hh"
33 #include "G4ParticleGun.hh"
34 #include "G4ParticleTable.hh"
35 #include "G4ParticleDefinition.hh"
36 #include "G4GenericMessenger.hh"
37 #include "G4SystemOfUnits.hh"
38 #include "Randomize.hh"
39 
40 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
41 
44  fParticleGun(nullptr), fMessenger(nullptr),
45  fPositron(nullptr), fMuon(nullptr), fPion(nullptr),
46  fKaon(nullptr), fProton(nullptr),
47  fMomentum(1000.*MeV),
48  fSigmaMomentum(50.*MeV),
49  fSigmaAngle(2.*deg),
50  fRandomizePrimary(true)
51 {
52  G4int nofParticles = 1;
53  fParticleGun = new G4ParticleGun(nofParticles);
54 
55  auto particleTable = G4ParticleTable::GetParticleTable();
56  fPositron = particleTable->FindParticle("e+");
57  fMuon = particleTable->FindParticle("mu+");
58  fPion = particleTable->FindParticle("pi+");
59  fKaon = particleTable->FindParticle("kaon+");
60  fProton = particleTable->FindParticle("proton");
61 
62  // default particle kinematics
65 
66  // define commands for this class
68 }
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
71 
73 {
74  delete fParticleGun;
75  delete fMessenger;
76 }
77 
78 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
79 
81 {
83  if (fRandomizePrimary) {
84  G4int i = (int)(5.*G4UniformRand());
85  switch(i) {
86  case 0:
87  particle = fPositron;
88  break;
89  case 1:
90  particle = fMuon;
91  break;
92  case 2:
93  particle = fPion;
94  break;
95  case 3:
96  particle = fKaon;
97  break;
98  default:
99  particle = fProton;
100  break;
101  }
103  }
104  else {
105  particle = fParticleGun->GetParticleDefinition();
106  }
107 
108  auto pp = fMomentum + (G4UniformRand()-0.5)*fSigmaMomentum;
109  auto mass = particle->GetPDGMass();
110  auto ekin = std::sqrt(pp*pp+mass*mass)-mass;
112 
113  auto angle = (G4UniformRand()-0.5)*fSigmaAngle;
115  G4ThreeVector(std::sin(angle),0.,std::cos(angle)));
116 
118 }
119 
120 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
121 
123 {
124  // Define /B5/generator command directory using generic messenger class
125  fMessenger
126  = new G4GenericMessenger(this,
127  "/B5/generator/",
128  "Primary generator control");
129 
130  // momentum command
131  auto& momentumCmd
132  = fMessenger->DeclarePropertyWithUnit("momentum", "GeV", fMomentum,
133  "Mean momentum of primaries.");
134  momentumCmd.SetParameterName("p", true);
135  momentumCmd.SetRange("p>=0.");
136  momentumCmd.SetDefaultValue("1.");
137  // ok
138  //momentumCmd.SetParameterName("p", true);
139  //momentumCmd.SetRange("p>=0.");
140 
141  // sigmaMomentum command
142  auto& sigmaMomentumCmd
143  = fMessenger->DeclarePropertyWithUnit("sigmaMomentum",
144  "MeV", fSigmaMomentum, "Sigma momentum of primaries.");
145  sigmaMomentumCmd.SetParameterName("sp", true);
146  sigmaMomentumCmd.SetRange("sp>=0.");
147  sigmaMomentumCmd.SetDefaultValue("50.");
148 
149  // sigmaAngle command
150  auto& sigmaAngleCmd
151  = fMessenger->DeclarePropertyWithUnit("sigmaAngle", "deg", fSigmaAngle,
152  "Sigma angle divergence of primaries.");
153  sigmaAngleCmd.SetParameterName("t", true);
154  sigmaAngleCmd.SetRange("t>=0.");
155  sigmaAngleCmd.SetDefaultValue("2.");
156 
157  // randomizePrimary command
158  auto& randomCmd
159  = fMessenger->DeclareProperty("randomizePrimary", fRandomizePrimary);
160  G4String guidance
161  = "Boolean flag for randomizing primary particle types.\n";
162  guidance
163  += "In case this flag is false, you can select the primary particle\n";
164  guidance += " with /gun/particle command.";
165  randomCmd.SetGuidance(guidance);
166  randomCmd.SetParameterName("flg", true);
167  randomCmd.SetDefaultValue("true");
168 }
169 
170 //..oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......