Example #1
0
int main(int argc, char** argv)   {
  string gdml = argv[1];
  string setup = argv[2];
  const char* args[] = {"cmd"};
  for(int i=1; i<argc;++i)   {
    if ( argv[i][0]=='-' )     {
      string n = argv[i]+1;
      if ( ::strncmp(n.c_str(),"gdml",4) == 0 )
        gdml = get_arg(argc,argv,++i);
      else if ( ::strncmp(n.c_str(),"guisetup",3) == 0 )
        setup = get_arg(argc,argv,++i);
    }
  }
  if ( gdml.empty() || setup.empty() )  {
    cout << " usage: g4gdmlDisplay -gdml <file-name> -guisetup <g4 macro>" << endl;
    return EINVAL;
  }

  G4RunManager * run = new G4RunManager;
  run->SetUserInitialization(new Geant4GDMLDetector(gdml));
  run->SetUserInitialization(new EmptyPhysicsList());
  //
  // Initialize G4 kernel
  run->Initialize();
  //
  // Initialize visualization
  G4VisManager* vis = new G4VisExecutive;
  vis->Initialize();
  //
  // Get the pointer to the User Interface manager
  G4UImanager* uiman = G4UImanager::GetUIpointer();
  G4UIExecutive* ui = new G4UIExecutive(1,(char**)args);
  uiman->ApplyCommand("/control/execute "+setup);
  ui->SessionStart();
  // end ...
  delete ui;
  delete vis;
  delete run;
  return 0;
}
Example #2
0
int main(int argc, char **argv)
{
   G4String macro = "";
   G4bool showAll = false;
   for (G4int i = 1; i < argc; i++) {
      if (G4String(argv[i]) == "-m") macro = argv[++i];
      else if (G4String(argv[i]) == "-a") showAll = true;
      else {
         PrintUsage();
         return 1;
      }
   }

   // Remove?
   // Choose the Random engine
   CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
   G4int seed = time(0);
   G4cout << "\nseed = " << seed << G4endl;
   CLHEP::HepRandom::setTheSeed(seed);
   G4Random::setTheSeed(seed);

   // Construct the default run manager
   //

#ifdef G4MULTITHREADED
   G4MTRunManager *runManager = new G4MTRunManager();
   runManager->SetNumberOfThreads(G4Threading::G4GetNumberOfCores());
   //runManager->SetNumberOfThreads(1);
#else
   G4RunManager *runManager = new G4RunManager();
#endif

   // Set mandatory initialization classes
   //
   // Detector construction
   runManager->SetUserInitialization(new BIDetectorConstruction());
   G4cout << "Here" << G4endl;
   // Physics list
   //G4VModularPhysicsList *physicsList = new FTFP_BERT;
   //G4VModularPhysicsList *physicsList = new QGSP_BERT_HP;
   G4VModularPhysicsList *physicsList = new Shielding;
   //G4VModularPhysicsList *physicsList = new BIPhysicsList;
   physicsList->SetVerboseLevel(0);
   //physicsList->SetCutValue(1.*um, "proton");
   //physicsList->SetCuts();
   //physicsList->SetDefaultCutValue(100.*um);
   runManager->SetUserInitialization(physicsList);

   // Primary generator action and User action intialization
   runManager->SetUserInitialization(new BIActionInitialization());

   // Initialize G4 kernel
   //
   runManager->Initialize();

#ifdef G4VIS_USE
   // Initialize visualization
   G4VisManager *visManager = new G4VisExecutive;
   visManager->Initialize();
   
   if (!showAll) { //Show only proton
      G4TrajectoryParticleFilter *filterp = new G4TrajectoryParticleFilter;
      filterp->Add("proton");
      visManager->RegisterModel(filterp);
   }
#endif

   // Get the pointer to the User Interface manager
   G4UImanager *UImanager = G4UImanager::GetUIpointer();

   if (macro != "") {
      // batch mode
      G4String command = "/control/execute ";
      UImanager->ApplyCommand(command + macro);
   } else {
      // interactive mode : define UI session
#ifdef G4UI_USE
      G4UIExecutive *ui = new G4UIExecutive(argc, argv);
#ifdef G4VIS_USE
      UImanager->ApplyCommand("/control/execute init_vis.mac");
#else
      UImanager->ApplyCommand("/control/execute init.mac");
#endif
      if (ui->IsGUI()) {
         UImanager->ApplyCommand("/control/execute icons.mac");
      }
      ui->SessionStart();
      delete ui;
#endif
   }

   // Job termination
   // Free the store: user actions, physics_list and detector_description are
   // owned and deleted by the run manager, so they should not be deleted
   // in the main() program !

#ifdef G4VIS_USE
   delete visManager;
#endif

   delete runManager;

   return 0;
}
Example #3
0
int main(int argc,char** argv)
{

    time_t lt;
    lt = time(NULL);
    ptr = gmtime(&lt);
    printf(asctime(ptr)); // Greenwich Mean time (GMT)
    printf(ctime(&lt)); //local time

    CLHEP::HepRandom::setTheEngine(new CLHEP::RanecuEngine);
    G4long seed = time(NULL);
    CLHEP::HepRandom::setTheSeed(seed);

    G4RunManager* runManager = new G4RunManager;

    ProDetectorConstruction* detectorCon = new ProDetectorConstruction();
    runManager->SetUserInitialization(detectorCon);

    PhysicsList* physics = new PhysicsList();
    runManager->SetUserInitialization(physics);

    ProAnalysis * anly = new ProAnalysis();

    // UserAction classes - optional
    G4VUserPrimaryGeneratorAction* generator = new ProPrimaryGeneratorAction(detectorCon);
    runManager->SetUserAction(generator);

    ProRunAction* RunAct = new ProRunAction(anly);
    runManager->SetUserAction(RunAct);
    ProEventAction* EvAct = new ProEventAction(RunAct,anly);
    runManager->SetUserAction(EvAct);

    runManager->Initialize();

#ifdef G4VIS_USE
    G4VisManager* visManager = new G4VisExecutive;
    visManager->Initialize();
#endif

    G4UImanager* uiManager = G4UImanager::GetUIpointer();

    if(argc != 1){
        G4String command = "/control/execute ";
        G4String fileName = argv[1];
        uiManager->ApplyCommand(command+fileName);
    }
    else {
#ifdef G4UI_USE
        G4UIExecutive* ui = new G4UIExecutive(argc,argv);
#ifdef G4VIS_USE
        uiManager->ApplyCommand("/control/execute vis.mac");
#endif
        ui->SessionStart();
        delete ui;
#endif
    }

//*******************************************************************

    G4cout<<" This is a Collimator Test which let neutrons having 180MeV "
          <<" pass through collimator, and two collimator detectors are "
          <<" used to record neutrons information" <<G4endl;
//*******************************************************************

#ifdef G4VIS_USE
    delete visManager;
#endif

    delete anly;
    delete runManager;

    return 0;
}