// PosGen_PointPosGen_Point.cc // Contact person:Matthew Mottram // See PosGen_Point.hh for more details //———————————————————————// #include #include #include using namespace std; #include #include #include using namespace CLHEP; using namespace RAT; void PosGen_Point::GeneratePosition( G4ThreeVector& argResult ) { //select random index const unsigned int k = static_cast< unsigned int>( G4UniformRand() * fPositions.size() ); argResult = fPositions[k]; } void PosGen_Point::SetState( G4String newValues ) { newValues = util_strip_default( newValues ); // leave only numerical values if( newValues.length() == 0 ) // No numerical values found, print help { RAT::info << "Current state of this GLG4PosGen_Point:\n\"" << GetState() << "\"\n"; RAT::detail << "Format of argument to GLG4PosGen_Point::SetState: \n\"x y z\" with all inputs in [mm]" << endl; return; } stringstream streamValues( newValues ); double x,y,z; streamValues >> x >> y >> z; fPositions.push_back( G4ThreeVector( x, y, z ) ); if( streamValues.fail() ) { RAT::warn << "Incorrect usage for PosGen_Point::SetState, not enough parameters." << endl; return; } if( !streamValues.eof() ) RAT::warn << "Incorrect usage for PosGen_Point::SetState, extra arguments ignored" << endl; } G4String PosGen_Point::GetState() const { stringstream result; for( vector< G4ThreeVector >::const_iterator iTer = fPositions.begin(); iTer != fPositions.end(); ++iTer ) result << iTer->x() << iTer->y() << iTer->z() << ", "; return result.str(); }