Geant4 Cross Reference |
1 // 1 2 // ******************************************* 3 // * License and Disclaimer 4 // * 5 // * The Geant4 software is copyright of th 6 // * the Geant4 Collaboration. It is provided 7 // * conditions of the Geant4 Software License 8 // * LICENSE and available at http://cern.ch/ 9 // * include a list of copyright holders. 10 // * 11 // * Neither the authors of this software syst 12 // * institutes,nor the agencies providing fin 13 // * work make any representation or warran 14 // * regarding this software system or assum 15 // * use. Please see the license in the file 16 // * for the full disclaimer and the limitatio 17 // * 18 // * This code implementation is the result 19 // * technical work of the GEANT4 collaboratio 20 // * By using, copying, modifying or distri 21 // * any work based on the software) you ag 22 // * use in resulting scientific publicati 23 // * acceptance of all terms of the Geant4 Sof 24 // ******************************************* 25 // 26 // 27 // 28 29 //....oooOO0OOooo........oooOO0OOooo........oo 30 //....oooOO0OOooo........oooOO0OOooo........oo 31 32 #include <fstream> 33 #include <cstdlib> 34 35 #include "FCALPrimaryGeneratorAction.hh" 36 37 #include "G4SystemOfUnits.hh" 38 #include "G4Event.hh" 39 #include "G4ParticleGun.hh" 40 #include "G4ParticleTable.hh" 41 #include "G4ParticleDefinition.hh" 42 #include "Randomize.hh" 43 #include "G4DataVector.hh" 44 #include "G4AutoLock.hh" 45 46 //....oooOO0OOooo........oooOO0OOooo........oo 47 48 49 // Migration to MT: there is a single input fi 50 // The idea is that the events are read by a s 51 // by all threads. Threads ask for the next ID 52 // events are all processed we start over from 53 namespace { 54 G4bool isFileRead = false; 55 G4Mutex mFileRead = G4MUTEX_INITIALIZER; 56 //Primary kinematics 57 G4DataVector fX; 58 G4DataVector fY; 59 G4DataVector fZ; 60 G4DataVector fCosX; 61 G4DataVector fCosY; 62 G4DataVector fCosZ; 63 size_t nextEventId = 0; 64 G4Mutex mNextEventId = G4MUTEX_INITIALIZER 65 66 size_t GetNextId() { 67 G4AutoLock l(&mNextEventId); 68 if ( nextEventId >= fX.size() ) //file 69 { 70 G4Exception("FCALPrimaryGenera 71 JustWarning,"Data 72 nextEventId=0; 73 } 74 return nextEventId++; 75 } 76 77 void ReadKinematicFromFile(G4double energy 78 //Only one thread shoud read input fil 79 G4AutoLock l(&mFileRead); 80 if ( isFileRead ) return; 81 // Read Kinematics from file 82 G4String file_name = "data-tracks/trac 83 if (energy < 30*GeV) 84 file_name = "data-tracks/tracks-20 85 else if (energy < 50*GeV) 86 file_name = "data-tracks/tracks-40 87 else if (energy < 70*GeV) 88 file_name = "data-tracks/tracks-60 89 else if (energy < 90*GeV) 90 file_name = "data-tracks/tracks-80 91 else if (energy < 150*GeV) 92 file_name = "data-tracks/tracks-12 93 else 94 file_name = "data-tracks/tracks-20 95 std::ifstream Traks_file(file_name); 96 if(!Traks_file) 97 { 98 G4ExceptionDescription ed; 99 ed << "Failed to open file " << fi 100 G4Exception("FCALPrimaryGeneratorA 101 "lAr001",FatalExceptio 102 } 103 G4double xx=0,yy=0,zz=0,c1=0,c2=0,c3=0 104 G4int iev = 0; 105 while(!(Traks_file.eof())) { 106 Traks_file >> iev >> xx >> yy >> z 107 fX.push_back(xx*cm); 108 fY.push_back(yy*cm); 109 fZ.push_back(zz*cm); 110 fCosX.push_back(c1); 111 fCosY.push_back(c2); 112 fCosZ.push_back(c3); 113 } 114 G4cout << "Read " << fX.size() << " ev 115 isFileRead= true; 116 Traks_file.close(); 117 return; 118 } 119 } 120 121 //....oooOO0OOooo........oooOO0OOooo........oo 122 123 FCALPrimaryGeneratorAction::FCALPrimaryGenerat 124 fVerbosity(0) 125 { 126 particleGun = new G4ParticleGun(); 127 128 // default Particle 129 G4String particleName; 130 G4ParticleTable* particleTable = G4ParticleT 131 G4ParticleDefinition* particle = particleTab 132 particleGun->SetParticleDefinition(particle) 133 134 // default Energy 135 particleGun->SetParticleEnergy(20*GeV); 136 } 137 138 //....oooOO0OOooo........oooOO0OOooo........oo 139 140 FCALPrimaryGeneratorAction::~FCALPrimaryGenera 141 { 142 delete particleGun; 143 } 144 145 //....oooOO0OOooo........oooOO0OOooo........oo 146 147 void FCALPrimaryGeneratorAction::GeneratePrima 148 { 149 //this function is called at the begining of 150 ReadKinematicFromFile(particleGun->GetPartic 151 152 //Get next event to be processed 153 size_t nEvent = GetNextId(); 154 particleGun->SetParticlePosition(G4ThreeVe 155 particleGun->SetParticleMomentumDirection(G4 156 fCosY[nEvent], 157 -1.0*fCosZ[nEvent])); 158 159 particleGun->GeneratePrimaryVertex(anEvent); 160 161 if (fVerbosity) 162 { 163 G4cout<< " Event "<<anEvent->GetEvent 164 <<anEvent->GetEventID() <<" (x,y,z 165 <<fY[nEvent] << "," << fZ[nEvent]< 166 << -1.*fCosX[nEvent] << "," << fCo 167 <<"," << -1.*fCosZ[nEvent] << ")"< 168 } 169 170 } 171 172 //....oooOO0OOooo........oooOO0OOooo........oo 173 174 175