Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
FCALPrimaryGeneratorAction.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 // $Id: FCALPrimaryGeneratorAction.cc 84371 2014-10-14 12:51:18Z 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 #include "G4AutoLock.hh"
46 
47 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
48 
49 
50 // Migration to MT: there is a single input file that is read by all threads.
51 // The idea is that the events are read by a single thread and processed
52 // by all threads. Threads ask for the next ID to be processed. When
53 // events are all processed we start over from the beginning of the file
54 namespace {
55  G4bool isFileRead = false;
56  G4Mutex mFileRead = G4MUTEX_INITIALIZER;
57  //Primary kinematics
58  G4DataVector fX;
59  G4DataVector fY;
60  G4DataVector fZ;
61  G4DataVector fCosX;
62  G4DataVector fCosY;
63  G4DataVector fCosZ;
64  size_t nextEventId = 0;
65  G4Mutex mNextEventId = G4MUTEX_INITIALIZER;
66 
67  size_t GetNextId() {
68  G4AutoLock l(&mNextEventId);
69  if ( nextEventId >= fX.size() ) //file data are over, restart file
70  {
71  G4Exception("FCALPrimaryGeneratorAction::GeneratePrimaries","lAr002",
72  JustWarning,"Data file with kinematics is over, restart it");
73  nextEventId=0;
74  }
75  return nextEventId++;
76  }
77 
78  void ReadKinematicFromFile(G4double energy) {
79  //Only one thread shoud read input file
80  G4AutoLock l(&mFileRead);
81  if ( isFileRead ) return;
82  // Read Kinematics from file
83  G4String file_name = "data-tracks/tracks-80GeV.dat";
84  if (energy < 30*GeV)
85  file_name = "data-tracks/tracks-20GeV.dat";
86  else if (energy < 50*GeV)
87  file_name = "data-tracks/tracks-40GeV.dat";
88  else if (energy < 70*GeV)
89  file_name = "data-tracks/tracks-60GeV.dat";
90  else if (energy < 90*GeV)
91  file_name = "data-tracks/tracks-80GeV.dat";
92  else if (energy < 150*GeV)
93  file_name = "data-tracks/tracks-120GeV.dat";
94  else
95  file_name = "data-tracks/tracks-200GeV.dat";
96  std::ifstream Traks_file(file_name);
97  if(!Traks_file)
98  {
100  ed << "Failed to open file " << file_name << G4endl;
101  G4Exception("FCALPrimaryGeneratorAction::FCALPrimaryGeneratorAction()",
102  "lAr001",FatalException,ed);
103  }
104  G4double xx=0,yy=0,zz=0,c1=0,c2=0,c3=0;
105  G4int iev = 0;
106  while(!(Traks_file.eof())) {
107  Traks_file >> iev >> xx >> yy >> zz >> c1 >> c2 >> c3;
108  fX.push_back(xx*cm);
109  fY.push_back(yy*cm);
110  fZ.push_back(zz*cm);
111  fCosX.push_back(c1);
112  fCosY.push_back(c2);
113  fCosZ.push_back(c3);
114  }
115  G4cout << "Read " << fX.size() << " events from file " << file_name << G4endl;
116  isFileRead= true;
117  Traks_file.close();
118  return;
119  }
120 }
121 
122 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
123 
125  fVerbosity(0)
126 {
127  particleGun = new G4ParticleGun();
128 
129  // default Particle
130  G4String particleName;
132  G4ParticleDefinition* particle = particleTable->FindParticle(particleName="e-");
134 
135  // default Energy
137 }
138 
139 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
140 
142 {
143  delete particleGun;
144 }
145 
146 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
147 
149 {
150  //this function is called at the begining of event
151  ReadKinematicFromFile(particleGun->GetParticleEnergy());
152 
153  //Get next event to be processed
154  size_t nEvent = GetNextId();
155  particleGun->SetParticlePosition(G4ThreeVector(fX[nEvent],fY[nEvent],fZ[nEvent]));
157  fCosY[nEvent],
158  -1.0*fCosZ[nEvent]));
159 
161 
162  if (fVerbosity)
163  {
164  G4cout<< " Event "<<anEvent->GetEventID()<< " Generated Vertex : "
165  <<anEvent->GetEventID() <<" (x,y,z)=(" << fX[nEvent] << ","
166  <<fY[nEvent] << "," << fZ[nEvent]<< ") (cosX,cosY,cosZ)=("
167  << -1.*fCosX[nEvent] << "," << fCosY[nEvent]
168  <<"," << -1.*fCosZ[nEvent] << ")"<<G4endl;
169  }
170 
171 }
172 
173 //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo....
174 
175 
G4ParticleDefinition * FindParticle(G4int PDGEncoding)
CLHEP::Hep3Vector G4ThreeVector
Double_t xx
std::ostringstream G4ExceptionDescription
Definition: G4Exception.hh:45
static G4ParticleTable * GetParticleTable()
G4int GetEventID() const
Definition: G4Event.hh:151
#define G4endl
Definition: G4ios.hh:61
Double_t zz
void SetParticlePosition(G4ThreeVector aPosition)
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
#define G4MUTEX_INITIALIZER
Definition: G4Threading.hh:88
void SetParticleDefinition(G4ParticleDefinition *aParticleDefinition)
TCanvas * c2
Definition: plot_hist.C:75
double energy
Definition: plottest35.C:25
void G4Exception(const char *originOfException, const char *exceptionCode, G4ExceptionSeverity severity, const char *description)
Definition: G4Exception.hh:65
int G4int
Definition: G4Types.hh:78
G4double GetParticleEnergy() const
virtual void GeneratePrimaryVertex(G4Event *evt)
G4GLOB_DLL std::ostream G4cout
static constexpr double cm
Definition: G4SIunits.hh:119
void SetParticleEnergy(G4double aKineticEnergy)
static constexpr double GeV
Definition: G4SIunits.hh:217
void SetParticleMomentumDirection(G4ParticleMomentum aMomentumDirection)
std::mutex G4Mutex
Definition: G4Threading.hh:84