// // ******************************************************************** // * License and Disclaimer * // * * // * The Geant4 software is copyright of the Copyright Holders of * // * the Geant4 Collaboration. It is provided under the terms and * // * conditions of the Geant4 Software License, included in the file * // * LICENSE and available at http://cern.ch/geant4/license . These * // * include a list of copyright holders. * // * * // * Neither the authors of this software system, nor their employing * // * institutes,nor the agencies providing financial support for this * // * work make any representation or warranty, express or implied, * // * regarding this software system or assume any liability for its * // * use. Please see the license in the file LICENSE and URL above * // * for the full disclaimer and the limitation of liability. * // * * // * This code implementation is the result of the scientific and * // * technical work of the GEANT4 collaboration. * // * By using, copying, modifying or distributing the software (or * // * any work based on the software) you agree to acknowledge its * // * use in resulting scientific publications, and indicate your * // * acceptance of all terms of the Geant4 Software license. * // ******************************************************************** // // /// \file optical/LXe/src/LXePrimaryGeneratorAction.cc /// \brief Implementation of the LXePrimaryGeneratorAction class // // #include "PrimaryGeneratorAction.hh" #include "G4Event.hh" #include "G4ParticleGun.hh" #include "G4ParticleTable.hh" #include "G4ParticleDefinition.hh" #include "G4SystemOfUnits.hh" #include "globals.hh" #include #include #include using namespace std; atomic ParGenNumber (0); //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... PrimaryGeneratorAction::PrimaryGeneratorAction(const char *inputfile) { G4int n_particle = 1; fParticleGun = new G4ParticleGun(n_particle); // Read the cry input file std::ifstream inputFile; inputFile.open(inputfile,std::ios::in); char buffer[1000]; if (inputFile.fail()) { if( *inputfile !=0) //....only complain if a filename was given G4cout << "PrimaryGeneratorAction: Failed to open CRY input file= " << inputfile << G4endl; InputState=-1; }else { std::string setupString(""); while ( !inputFile.getline(buffer,1000).eof()) { setupString.append(buffer); setupString.append(" "); } // CRYSetup *setup=new CRYSetup(setupString,"../data"); CRYSetup *setup=new CRYSetup(setupString,"/Users/sdevip/work/cry/data"); gen = new CRYGenerator(setup); // set random number generator RNGWrapper::set(CLHEP::HepRandom::getTheEngine(),&CLHEP::HepRandomEngine::flat); setup->setRandomFunction(RNGWrapper::rng); InputState=0; } // create a vector to store the CRY particle properties vect=new std::vector; // Create the table containing all particle names particleTable = G4ParticleTable::GetParticleTable(); // Create the messenger file gunMessenger = new PrimaryGeneratorMessenger(this); } //....oooOO0OOooo........oooOO0OOooo........oooOO0OOooo........oooOO0OOooo...... PrimaryGeneratorAction::~PrimaryGeneratorAction() { G4cout<<"ParGenNumber "<clear(); gen->genEvent(vect); /*/....debug output G4cout << "\nEvent=" << anEvent->GetEventID() << " " << "CRY generated nparticles=" << vect->size() << G4endl; */ for ( unsigned j=0; jsize(); j++) { ParGenNumber=ParGenNumber+1; particleName=CRYUtils::partName((*vect)[j]->id()); //------------------------------------------------------------------------------- /* //....debug output cout << " " << particleName << " " << "charge=" << (*vect)[j]->charge() << " " << setprecision(4) << "energy (MeV)=" << (*vect)[j]->ke()*MeV << " " << "pos (m)" << G4ThreeVector((*vect)[j]->x(), (*vect)[j]->y(), (*vect)[j]->z()) << " " << "direction cosines " << G4ThreeVector((*vect)[j]->u(), (*vect)[j]->v(), (*vect)[j]->w()) << " " << endl; */ //------------------------------------------------------------------------------- fParticleGun->SetParticleDefinition(particleTable->FindParticle((*vect)[j]->PDGid())); fParticleGun->SetParticleEnergy((*vect)[j]->ke()*MeV); G4double pox =((*vect)[j]->x()*10); G4double poy =((*vect)[j]->y()*10); G4double poz =(((*vect)[j]->z()+25.1)); fParticleGun->SetParticlePosition(G4ThreeVector(pox*m, poy*m , poz*m)); //debug postion // cout<SetParticleMomentumDirection(G4ThreeVector((*vect)[j]->u(), (*vect)[j]->v(), (*vect)[j]->w())); fParticleGun->SetParticleTime((*vect)[j]->t()); fParticleGun->GeneratePrimaryVertex(anEvent); delete (*vect)[j]; } } //20200404 void PrimaryGeneratorAction::InputCRY() { InputState=1; } void PrimaryGeneratorAction::UpdateCRY(std::string* MessInput) { CRYSetup *setup=new CRYSetup(*MessInput,"/Users/sdevip/work/cry/data"); gen = new CRYGenerator(setup); // set random number generator RNGWrapper::set(CLHEP::HepRandom::getTheEngine(),&CLHEP::HepRandomEngine::flat); setup->setRandomFunction(RNGWrapper::rng); InputState=0; } //----------------------------------------------------------------------------// void PrimaryGeneratorAction::CRYFromFile(G4String newValue) { // Read the cry input file std::ifstream inputFile; inputFile.open(newValue,std::ios::in); char buffer[1000]; if (inputFile.fail()) { G4cout << "Failed to open input file " << newValue << G4endl; G4cout << "Make sure to define the cry library on the command line" << G4endl; InputState=-1; }else{ std::string setupString(""); while ( !inputFile.getline(buffer,1000).eof()) { setupString.append(buffer); setupString.append(" "); } CRYSetup *setup=new CRYSetup(setupString,"/Users/sdevip/work/cry/data"); gen = new CRYGenerator(setup); // set random number generator RNGWrapper::set(CLHEP::HepRandom::getTheEngine(),&CLHEP::HepRandomEngine::flat); setup->setRandomFunction(RNGWrapper::rng); InputState=0; } }