Geant4  9.6.p02
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
FCALPrimaryGeneratorAction.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 // $Id: FCALPrimaryGeneratorAction.cc 69896 2013-05-17 09:57:59Z gcosmo $
27 //
28 //
29 
30 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
31 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
32 
33 #include <fstream>
34 #include <cstdlib>
35 
37 
38 #include "G4SystemOfUnits.hh"
39 #include "G4Event.hh"
40 #include "G4ParticleGun.hh"
41 #include "G4ParticleTable.hh"
42 #include "G4ParticleDefinition.hh"
43 #include "Randomize.hh"
44 
45 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
46 
48 {
49  X = new G4double[5001];
50  Y = new G4double[5001];
51  Z = new G4double[5001];
52  Cos_X = new G4double[5001];
53  Cos_Y = new G4double[5001];
54  Cos_Z = new G4double[5001];
55 
56 
57  G4int Nparticles = 1;
58  particleGun = new G4ParticleGun(Nparticles);
59 
60  // default Particle
61  G4String particleName;
63  G4ParticleDefinition* particle = particleTable->FindParticle(particleName="e+");
64  particleGun->SetParticleDefinition(particle);
65 
66 
67  // default Energy
68  particleGun->SetParticleEnergy(80*GeV);
69 
70  // Read Kinematics from file
71  G4int InEvent = 0;
72  G4String file_name = "data-tracks/tracks-80GeV.dat";
73  std::ifstream Traks_file(file_name);
74  if(!Traks_file) G4cerr << "WARNING: Failed to open file " << file_name << G4endl;
75  Traks_file.seekg(0);
76 
77  while(!(Traks_file.eof())) {
78  InEvent++;
79  Traks_file >> Ievent >> X[InEvent] >> Y[InEvent] >> Z[InEvent]
80  >> Cos_X[InEvent] >> Cos_Y[InEvent] >> Cos_Z[InEvent];
81  };
82 
83  Nevent = 0;
84 }
85 
86 
87 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
88 
90 {
91  delete particleGun;
92  delete [] X;
93  delete [] Y;
94  delete [] Z;
95  delete [] Cos_X;
96  delete [] Cos_Y;
97  delete [] Cos_Z;
98 
99 }
100 
101 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
102 
104 {
105  //this function is called at the begining of event
106 
107  Nevent++;
108 
109  particleGun->SetParticlePosition(G4ThreeVector(X[Nevent]*cm,Y[Nevent]*cm,Z[Nevent]*cm));
110  particleGun->SetParticleMomentumDirection(G4ThreeVector(-Cos_X[Nevent],Cos_Y[Nevent],-Cos_Z[Nevent]));
111 
112 
113  particleGun->GeneratePrimaryVertex(anEvent);
114 
115  G4cout << "--------------------------------------------" << G4endl;
116  G4cout << " Event, X,Y,Z Generated Vertex : " << G4endl;
117  G4cout << Nevent << " " << X[Nevent] << " " << Y[Nevent] << " " << Z[Nevent]<< G4endl;
118  G4cout << "--------------------------------------------" << G4endl;
119 
120 
121 }
122 
123 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
124 
125