Esempio n. 1
0
/// Initialize the simulation
int Geant4Exec::initialize(Geant4Kernel& kernel) {
  // Construct the default run manager
  G4RunManager& runManager = kernel.runManager();
  //
  // Initialize G4 engine
  //
  kernel.executePhase("initialize",0);
  runManager.Initialize();
  return 1;
}
Esempio n. 2
0
/// Run the simulation
int Geant4Exec::run(Geant4Kernel& kernel) {
  Property& p = kernel.property("UI");
  string value = p.value<string>();

  kernel.executePhase("start",0);
  if ( !value.empty() )  {
    Geant4Action* ui = kernel.globalAction(value);
    if ( ui )  {
      Geant4Call* c = dynamic_cast<Geant4Call*>(ui);
      if ( c )  {
        (*c)(0);
        kernel.executePhase("stop",0);
        return 1;
      }
      ui->except("++ Geant4Exec: Failed to start UI interface.");
    }
    throw runtime_error(format("Geant4Exec","++ Failed to locate UI interface %s.",value.c_str()));
  }
  long nevt = kernel.property("NumEvents").value<long>();
  kernel.runManager().BeamOn(nevt);
  kernel.executePhase("stop",0);
  return 1;
}
Esempio n. 3
0
/// Configure the simulation
int Geant4Exec::configure(Geant4Kernel& kernel) {
  Geometry::LCDD& lcdd = kernel.lcdd();
  Geant4Context* ctx = kernel.workerContext();
  Geant4Random* rndm = Geant4Random::instance(false);
  
  if ( !rndm )  {
    rndm = new Geant4Random(ctx, "Geant4Random");
    /// Initialize the engine etc.
    rndm->initialize();
  }
  Geant4Random::setMainInstance(rndm);
  kernel.executePhase("configure",0);

  // Construct the default run manager
  G4RunManager& runManager = kernel.runManager();

  // Check if the geometry was loaded
  if (lcdd.sensitiveDetectors().size() <= 1) {
    printout(WARNING, "Geant4Exec", "+++ Only %d subdetectors present. "
             "You sure you loaded the geometry properly?",
             int(lcdd.sensitiveDetectors().size()));
  }

  // Get the detector constructed
  Geant4DetectorConstructionSequence* user_det = kernel.detectorConstruction(false);
  if ( 0 == user_det && kernel.isMultiThreaded() )   {
    throw runtime_error("Panic! No valid detector construction sequencer present. [Mandatory MT]");
  }
  if ( 0 == user_det && !kernel.isMultiThreaded() )   {
    user_det = Geant4Compatibility().buildDefaultDetectorConstruction(kernel);
  }
  Geant4UserDetectorConstruction* det_seq = new Geant4UserDetectorConstruction(ctx,user_det);
  runManager.SetUserInitialization(det_seq);

  // Get the physics list constructed
  Geant4PhysicsListActionSequence* phys_seq = kernel.physicsList(false);
  if ( 0 == phys_seq )   {
    string phys_model = "QGSP_BERT";
    phys_seq = kernel.physicsList(true);
    phys_seq->property("extends").set(phys_model);
  }
  G4VUserPhysicsList* physics = phys_seq->extensionList();
  if (0 == physics) {
    throw runtime_error("Panic! No valid user physics list present!");
  }
#if 0
  /// Not here: Use seperate object to do this!
  printout(INFO, "Geant4Exec", "+++ PhysicsList RangeCut: %f", phys_seq->m_rangecut );
  physics->SetDefaultCutValue(phys_seq->m_rangecut);
  physics->SetCuts();
  if( DEBUG == printLevel() ) physics->DumpCutValuesTable();
#endif
  runManager.SetUserInitialization(physics);

  // Construct the remaining user initialization in multi-threaded mode
  Geant4UserInitializationSequence* user_init = kernel.userInitialization(false);
  if ( 0 == user_init && kernel.isMultiThreaded() )   {
    throw runtime_error("Panic! No valid user initialization sequencer present. [Mandatory MT]");
  }
  else if ( 0 == user_init && !kernel.isMultiThreaded() )  {
    // Use default actions registered to the default kernel. Will do the right thing...
    user_init = kernel.userInitialization(true);
  }
  Geant4UserActionInitialization* init = new Geant4UserActionInitialization(ctx,user_init);
  runManager.SetUserInitialization(init);
  return 1;
}