Esempio n. 1
0
 template <> Geant4Handle<Geant4Sensitive>::Geant4Handle(Geant4Kernel& kernel, const string& type_name,
                                                         const string& detector, bool /* shared */) {
   try {
     Geant4Context* ctxt = kernel.workerContext();
     TypeName typ = TypeName::split(type_name);
     Detector& description = kernel.detectorDescription();
     DetElement det = description.detector(detector);
     Geant4Sensitive* object = PluginService::Create<Geant4Sensitive*>(typ.first, ctxt, typ.second, &det, &description);
     if (object) {
       value = object;
       return;
     }
   }
   catch (const exception& e) {
     printout(ERROR, "Geant4Handle<Geant4Sensitive>", "Exception: %s", e.what());
   }
   catch (...) {
     printout(ERROR, "Geant4Handle<Geant4Sensitive>", "Exception: Unknown exception");
   }
   except("Geant4Handle<Geant4Sensitive>", 
          "Failed to create sensitive object of type %s for detector %s!",
          type_name.c_str(), detector.c_str());
 }
Esempio n. 2
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;
}