Geant4.10
 All Data Structures 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 68716 2013-04-05 09:13:43Z 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 #include "G4DataVector.hh"
45 
46 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
47 
49  isFileRead(false),fVerbosity(0),nEvent(0)
50 {
51  fX = new G4DataVector();
52  fY = new G4DataVector();
53  fZ = new G4DataVector();
54  fCosX = new G4DataVector();
55  fCosY = new G4DataVector();
56  fCosZ = new G4DataVector();
57 
58  particleGun = new G4ParticleGun();
59 
60  // default Particle
61  G4String particleName;
63  G4ParticleDefinition* particle = particleTable->FindParticle(particleName="e-");
64  particleGun->SetParticleDefinition(particle);
65 
66  // default Energy
67  particleGun->SetParticleEnergy(20*GeV);
68 }
69 
70 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
71 
73 {
74  delete particleGun;
75  delete fX;
76  delete fY;
77  delete fZ;
78  delete fCosX;
79  delete fCosY;
80  delete fCosZ;
81 }
82 
83 
84 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
85 
86 void FCALPrimaryGeneratorAction::ReadKinematicFromFile(G4double energy)
87 {
88  // Read Kinematics from file
89  G4String file_name = "data-tracks/tracks-80GeV.dat";
90  if (energy < 30*GeV)
91  file_name = "data-tracks/tracks-20GeV.dat";
92  else if (energy < 50*GeV)
93  file_name = "data-tracks/tracks-40GeV.dat";
94  else if (energy < 70*GeV)
95  file_name = "data-tracks/tracks-60GeV.dat";
96  else if (energy < 90*GeV)
97  file_name = "data-tracks/tracks-80GeV.dat";
98  else if (energy < 150*GeV)
99  file_name = "data-tracks/tracks-120GeV.dat";
100  else
101  file_name = "data-tracks/tracks-200GeV.dat";
102 
103  std::ifstream Traks_file(file_name);
104  if(!Traks_file)
105  {
107  ed << "Failed to open file " << file_name << G4endl;
108  G4Exception("FCALPrimaryGeneratorAction::FCALPrimaryGeneratorAction()",
109  "lAr001",FatalException,ed);
110  }
111  G4double xx=0,yy=0,zz=0,c1=0,c2=0,c3=0;
112  G4int iev = 0;
113  while(!(Traks_file.eof())) {
114  Traks_file >> iev >> xx >> yy >> zz >> c1 >> c2 >> c3;
115  fX->push_back(xx*cm);
116  fY->push_back(yy*cm);
117  fZ->push_back(zz*cm);
118  fCosX->push_back(c1);
119  fCosY->push_back(c2);
120  fCosZ->push_back(c3);
121  }
122  G4cout << "Read " << fX->size() << " events from file " << file_name << G4endl;
123  isFileRead= true;
124  Traks_file.close();
125  return;
126 }
127 
128 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
129 
131 {
132  //this function is called at the begining of event
133  if (!isFileRead)
134  ReadKinematicFromFile(particleGun->GetParticleEnergy());
135 
136  if (nEvent >= fX->size()) //file data are over, restart file
137  {
138  G4Exception("FCALPrimaryGeneratorAction::GeneratePrimaries","lAr002",
139  JustWarning,"Data file with kinematics is over, restart it");
140  nEvent=0;
141  }
142 
143  particleGun->SetParticlePosition(G4ThreeVector(fX->at(nEvent),fY->at(nEvent),fZ->at(nEvent)));
144  particleGun->SetParticleMomentumDirection(G4ThreeVector(-1.0*fCosX->at(nEvent),
145  fCosY->at(nEvent),
146  -1.0*fCosZ->at(nEvent)));
147  nEvent++;
148 
149  particleGun->GeneratePrimaryVertex(anEvent);
150 
151  if (fVerbosity)
152  {
153  G4cout << "--------------------------------------------" << G4endl;
154  G4cout << " Event, X,Y,Z Generated Vertex : " << G4endl;
155  G4cout << anEvent->GetEventID() << " " << (*fX)[nEvent] << " " <<
156  (*fY)[nEvent] << " " << (*fZ)[nEvent]<< G4endl;
157  G4cout << -1.*(*fCosX)[nEvent] << " " << (*fCosY)[nEvent] <<
158  " " << -1.*(*fCosZ)[nEvent] << G4endl;
159  G4cout << "--------------------------------------------" << G4endl;
160  }
161 
162 }
163 
164 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
165 
166 
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
std::ostringstream G4ExceptionDescription
Definition: globals.hh:76
CLHEP::Hep3Vector G4ThreeVector
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
int G4int
Definition: G4Types.hh:78
virtual void GeneratePrimaryVertex(G4Event *evt)
G4int GetEventID() const
Definition: G4Event.hh:140
double precision function energy(A, Z)
Definition: dpm25nuc6.f:4106
void SetParticlePosition(G4ThreeVector aPosition)
G4GLOB_DLL std::ostream G4cout
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *comments)
Definition: G4Exception.cc:41
void SetParticleEnergy(G4double aKineticEnergy)
static G4ParticleTable * GetParticleTable()
#define G4endl
Definition: G4ios.hh:61
double G4double
Definition: G4Types.hh:76
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
G4double GetParticleEnergy() const
tuple c1
Definition: plottest35.py:14