HGCal Test Beam  03a93d6239a951948e06fb3ef8dae4cbdebfad30
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PrimaryGeneratorAction.cc
Go to the documentation of this file.
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 //
27 // $Id$
28 //
29 //
30 
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
32 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
33 
34 #include "HGCal/TBStandaloneSimulator/interface/PrimaryGeneratorAction.hh"
35 #include "HGCal/TBStandaloneSimulator/interface/DetectorConstruction.hh"
36 #include "HGCal/TBStandaloneSimulator/interface/PrimaryGeneratorMessenger.hh"
37 
38 #include "G4RunManager.hh"
39 #include "G4Event.hh"
40 #include "G4ParticleGun.hh"
41 #include "G4ParticleTable.hh"
42 #include "G4ParticleDefinition.hh"
43 #include "G4SystemOfUnits.hh"
44 #include "Randomize.hh"
45 
46 #include "HGCal/TBStandaloneSimulator/interface/HepMCG4AsciiReader.hh"
47 #include "HGCal/TBStandaloneSimulator/interface/HepMCG4PythiaInterface.hh"
48 
49 #define PI 3.1415926535
50 
51 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
52 
53 PrimaryGeneratorAction::PrimaryGeneratorAction(G4int mod, double eta)
54 {
55  // A hack to avoid compiler warning
56  int hack = CLHEP::HepRandomGenActive;
57  hack = mod;
58 
59  model_ = hack;
60  eta_ = eta;
61  G4int n_particle = 1;
62 
63  // default generator is particle gun.
64  currentGenerator = particleGun = new G4ParticleGun(n_particle);
65  currentGeneratorName = "particleGun";
66  hepmcAscii = new HepMCG4AsciiReader();
67  pythiaGen = 0;
68  gentypeMap["particleGun"] = particleGun;
69  gentypeMap["hepmcAscii"] = hepmcAscii;
70  gentypeMap["pythia"] = pythiaGen;
71 
72  Detector = (DetectorConstruction*)
73  G4RunManager::GetRunManager()->GetUserDetectorConstruction();
74 
75  //create a messenger for this class
76  gunMessenger = new PrimaryGeneratorMessenger(this);
77 
78  // default particle kinematics
79 
80  G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
81  G4String particleName;
82  G4ParticleDefinition* particle
83  = particleTable->FindParticle(particleName = "e-");
84  particleGun->SetParticleDefinition(particle);
85  particleGun->SetParticleMomentumDirection(G4ThreeVector(0., 0., 1.));
86  particleGun->SetParticleEnergy(10.*GeV);
87  particleGun->SetParticlePosition(G4ThreeVector(0.*cm, 0.*cm, 0.*cm));
88 
89  rndmFlag = "off";
90 }
91 
92 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
93 
94 PrimaryGeneratorAction::~PrimaryGeneratorAction()
95 {
96  delete particleGun;
97  delete hepmcAscii;
98  delete pythiaGen;
99  delete gunMessenger;
100 }
101 
102 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
103 
104 void PrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
105 {
106  // //this function is called at the begining of event
107  // //
108  // G4double z0 = -0.5*(Detector->GetWorldSizeZ());
109  // if (model_ == 2) z0 = 0;
110  // G4double x0 = 0.*cm, y0 = 0.*cm;
111  // //smear within 1cm...
112  // if (model_ == 2) z0 = (G4RandGauss::shoot(0.,5.))*cm;
113  // else if (model_ == 4) {
114  // x0 = (G4RandFlat::shoot(0.,460)-170)*mm;
115  // //y0 = (G4RandFlat::shoot(0.,10.)-5)*mm;
116  // }
117  // else if (model_ == 3) {
118  // //x0 = (G4RandFlat::shoot(0.,30)-15)*mm;
119  // //y0 = (G4RandFlat::shoot(0.,30.)-15)*mm;
120  // //update to cover full hexagon
121  // //size=6.4mm
122  // x0 = (G4RandFlat::shoot(0.,24.)-12)*mm;
123  // y0 = (G4RandFlat::shoot(0.,24.)-12)*mm;
124  // }
125 
126  // particleGun->SetParticlePosition(G4ThreeVector(x0,y0,z0));
127  // G4cout << " -- Gun position set to: " << x0 << "," << y0 << "," << z0 << G4endl;
128 
129  // G4double theta0 = 2*atan(exp(-1*eta_));
130  // G4double phi0 = (G4RandFlat::shoot(0.,2*PI));
131  // if (model_ == 2) particleGun->SetParticleMomentumDirection(G4ThreeVector(cos(phi0)*sin(theta0), sin(phi0)*sin(theta0), cos(theta0)));
132 
133  if(currentGenerator) {
134  currentGenerator->GeneratePrimaryVertex(anEvent);
135  } else
136  G4Exception("PrimaryGeneratorAction::GeneratePrimaries",
137  "PrimaryGeneratorAction001", FatalException,
138  "generator is not instanciated." );
139 }
140 
141 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo......
142