File indexing completed on 2025-01-18 09:16:57
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032 #include <fstream>
0033 #include <cstdlib>
0034
0035 #include "FCALPrimaryGeneratorAction.hh"
0036
0037 #include "G4SystemOfUnits.hh"
0038 #include "G4Event.hh"
0039 #include "G4ParticleGun.hh"
0040 #include "G4ParticleTable.hh"
0041 #include "G4ParticleDefinition.hh"
0042 #include "Randomize.hh"
0043 #include "G4DataVector.hh"
0044 #include "G4AutoLock.hh"
0045
0046
0047
0048
0049
0050
0051
0052
0053 namespace {
0054 G4bool isFileRead = false;
0055 G4Mutex mFileRead = G4MUTEX_INITIALIZER;
0056
0057 G4DataVector fX;
0058 G4DataVector fY;
0059 G4DataVector fZ;
0060 G4DataVector fCosX;
0061 G4DataVector fCosY;
0062 G4DataVector fCosZ;
0063 size_t nextEventId = 0;
0064 G4Mutex mNextEventId = G4MUTEX_INITIALIZER;
0065
0066 size_t GetNextId() {
0067 G4AutoLock l(&mNextEventId);
0068 if ( nextEventId >= fX.size() )
0069 {
0070 G4Exception("FCALPrimaryGeneratorAction::GeneratePrimaries","lAr002",
0071 JustWarning,"Data file with kinematics is over, restart it");
0072 nextEventId=0;
0073 }
0074 return nextEventId++;
0075 }
0076
0077 void ReadKinematicFromFile(G4double energy) {
0078
0079 G4AutoLock l(&mFileRead);
0080 if ( isFileRead ) return;
0081
0082 G4String file_name = "data-tracks/tracks-80GeV.dat";
0083 if (energy < 30*GeV)
0084 file_name = "data-tracks/tracks-20GeV.dat";
0085 else if (energy < 50*GeV)
0086 file_name = "data-tracks/tracks-40GeV.dat";
0087 else if (energy < 70*GeV)
0088 file_name = "data-tracks/tracks-60GeV.dat";
0089 else if (energy < 90*GeV)
0090 file_name = "data-tracks/tracks-80GeV.dat";
0091 else if (energy < 150*GeV)
0092 file_name = "data-tracks/tracks-120GeV.dat";
0093 else
0094 file_name = "data-tracks/tracks-200GeV.dat";
0095 std::ifstream Traks_file(file_name);
0096 if(!Traks_file)
0097 {
0098 G4ExceptionDescription ed;
0099 ed << "Failed to open file " << file_name << G4endl;
0100 G4Exception("FCALPrimaryGeneratorAction::FCALPrimaryGeneratorAction()",
0101 "lAr001",FatalException,ed);
0102 }
0103 G4double xx=0,yy=0,zz=0,c1=0,c2=0,c3=0;
0104 G4int iev = 0;
0105 while(!(Traks_file.eof())) {
0106 Traks_file >> iev >> xx >> yy >> zz >> c1 >> c2 >> c3;
0107 fX.push_back(xx*cm);
0108 fY.push_back(yy*cm);
0109 fZ.push_back(zz*cm);
0110 fCosX.push_back(c1);
0111 fCosY.push_back(c2);
0112 fCosZ.push_back(c3);
0113 }
0114 G4cout << "Read " << fX.size() << " events from file " << file_name << G4endl;
0115 isFileRead= true;
0116 Traks_file.close();
0117 return;
0118 }
0119 }
0120
0121
0122
0123 FCALPrimaryGeneratorAction::FCALPrimaryGeneratorAction() :
0124 fVerbosity(0)
0125 {
0126 particleGun = new G4ParticleGun();
0127
0128
0129 G4String particleName;
0130 G4ParticleTable* particleTable = G4ParticleTable::GetParticleTable();
0131 G4ParticleDefinition* particle = particleTable->FindParticle(particleName="e-");
0132 particleGun->SetParticleDefinition(particle);
0133
0134
0135 particleGun->SetParticleEnergy(20*GeV);
0136 }
0137
0138
0139
0140 FCALPrimaryGeneratorAction::~FCALPrimaryGeneratorAction()
0141 {
0142 delete particleGun;
0143 }
0144
0145
0146
0147 void FCALPrimaryGeneratorAction::GeneratePrimaries(G4Event* anEvent)
0148 {
0149
0150 ReadKinematicFromFile(particleGun->GetParticleEnergy());
0151
0152
0153 size_t nEvent = GetNextId();
0154 particleGun->SetParticlePosition(G4ThreeVector(fX[nEvent],fY[nEvent],fZ[nEvent]));
0155 particleGun->SetParticleMomentumDirection(G4ThreeVector(-1.0*fCosX[nEvent],
0156 fCosY[nEvent],
0157 -1.0*fCosZ[nEvent]));
0158
0159 particleGun->GeneratePrimaryVertex(anEvent);
0160
0161 if (fVerbosity)
0162 {
0163 G4cout<< " Event "<<anEvent->GetEventID()<< " Generated Vertex : "
0164 <<anEvent->GetEventID() <<" (x,y,z)=(" << fX[nEvent] << ","
0165 <<fY[nEvent] << "," << fZ[nEvent]<< ") (cosX,cosY,cosZ)=("
0166 << -1.*fCosX[nEvent] << "," << fCosY[nEvent]
0167 <<"," << -1.*fCosZ[nEvent] << ")"<<G4endl;
0168 }
0169
0170 }
0171
0172
0173
0174