some inspiration:
void myRunAction::BeginOfRunAction(const G4Run* aRun) {
G4AnalysisManager* analysisManager = G4AnalysisManager::Instance();
char fileName[65];
sprintf(fileName, "Somethingsomething_run%04d",aRun->GetRunID());
analysisManager->SetFileName(G4String(fileName));
analysisManager->OpenFile();
}