G4VPhysicalVolume * GeantDetectorConstruction::Construct()
{
    // World
    G4double worldSize = 5 * ( std::abs( gOptions->GetDetZ_cm() * cm ) + std::abs( gOptions->GetPartZ_cm() * cm ) ) ;
    G4Box * worldSolid = new G4Box("WorldS", worldSize, worldSize, worldSize);
    G4LogicalVolume * worldLV = new G4LogicalVolume( worldSolid, G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic"), "World");
    G4VPhysicalVolume * worldPV = new G4PVPlacement( 0, G4ThreeVector(0,0,0), worldLV, "WorldPV", 0, false, 0, true);

    // Scatterer plane
    G4Box * scatPlaneSolid = new G4Box("scatPlaneSolid", worldSize, worldSize, gOptions->GetScatThick_um() * um / 2  );
    G4Material * scatMat =  G4NistManager::Instance()->FindOrBuildMaterial("G4_Si");
    G4cout << "Scatterer material: " << scatMat->GetName() << " Radiation length = "<< scatMat->GetRadlen() / cm << " cm"<< G4endl;
    G4LogicalVolume * scatPlaneLV = new G4LogicalVolume( scatPlaneSolid, scatMat, "scatPlaneLV");
    new G4PVPlacement( 0, G4ThreeVector(0,0,0), scatPlaneLV, "scatPlanePV", worldLV, false, 0, true);

    // Detector plane
    G4Box * detPlaneSolid = new G4Box("detPlaneSolid", worldSize, worldSize, 1 * um );
    G4LogicalVolume * detPlaneLV = new G4LogicalVolume( detPlaneSolid, G4NistManager::Instance()->FindOrBuildMaterial("G4_Galactic"), "detPlaneLV");
    new G4PVPlacement( 0, G4ThreeVector( 0, 0, ( gOptions->GetDetZ_cm() + detPlaneSolid->GetZHalfLength() ) * cm ), detPlaneLV, "DetPlanePV", worldLV, false, 0, true);
    fDetPlaneSD = new GeantTrackerSD( 0 );
    SetSensitiveDetector( detPlaneLV, fDetPlaneSD );

    return worldPV;
}
void BuildMaterialTables() 
{
#ifdef DAGGEOMETRY_DEBUG
  std::cout << "==> FluDAG BuildMaterialTables()" << std::endl;
#endif

  //some terminal printout also
  std::cout << "\t* Storing information..." << std::endl;

  //The logic is the folloing:
  //Get the Material Table and:
  // 1) For materials with density <= 1.00e-10*g/cm3 assign vacuum
  // 2) For each single element material build a material equivalent
  // 3) For the rest:
  //   3.a) Build materials for each not already known element
  //   3.b) Build the compound out of them

  // initialize with predefined materials
  initmat = InitFlukaMat();
#ifdef DAGGEOMETRY_DEBUG
  std::cout << "end init predef mat  "  << std::endl;
#endif
  //Get the Material Table and iterate
  const G4MaterialTable* matTable = DagG4Material::GetMaterialTable();
  for (MatTableIterator i = matTable->begin(); i != matTable->end(); i++) {

    //Get some basic material information
    G4Material* material = (*i);
    DString matName = material->GetName();
    const G4double matDensity = material->GetDensity();
    const int nMatElements  = material->GetNumberOfElements();
#ifdef DAGGEOMETRY_DEBUG
    std::cout << " treating material " << matName    << std::endl;
#endif

    std::cout << " mat " << matName 
	   << ": dens. = " << matDensity/(g/cm3) << "g/cm3"
	   << ", nElem = " << nMatElements << std::endl;

    // 1) For materials with density <= 1.00e-10*g/cm3 assign vacuum
    //    FlukaMaterial* is  in that case
    if (matDensity <= 1.00e-10*g/cm3) {
#ifdef DAGGEOMETRY_DEBUG
    std::cout << " vacuum?  "<< matDensity    << std::endl;
#endif
      DString elemName("VACUUM");
      FlukaMaterial *flukamat = FlukaMaterial::GetFlukaMaterial(elemName);
      G4FlukaMaterialMap[material] = flukamat;
      std::cout << "\t\t  Stored as " << flukamat->GetRealName() << std::endl;
    }
    // 2) For each single element material build a material equivalent
    else if (nMatElements == 1) {
#ifdef DAGGEOMETRY_DEBUG
    std::cout << " single element "     << std::endl;
#endif
      
      FlukaMaterial *flukamat = 
	BuildFlukaMaterialFromElement(material->GetElement(0),
				      matDensity);
      
      G4FlukaMaterialMap[material] = flukamat;
      std::cout << "  Stored as " << flukamat->GetRealName() << std::endl;
      
    } //else if (material->GetNumberOfElements() == 1)
    
    // 3) For the rest:
    //   3.a) Build materials for each not already known element
    //   3.b) Build the compound out of them
    else {
#ifdef DAGGEOMETRY_DEBUG
      std::cout << " not  vacuum : call Comp. "<< matDensity/(g/cm3)   << std::endl;
#endif
      FlukaCompound* flukacomp = 
	BuildFlukaCompoundFromMaterial(material);
      G4FlukaCompoundMap[material] = flukacomp;
      std::cout << "\t\t  Stored as " << flukacomp->GetRealName() << std::endl;
    } //else for case 3)
  } //for (materials)
  
#ifdef DAGGEOMETRY_DEBUG
  std::cout << "<== Flugg FGeometryInit::BuildMaterialTables()" << std::endl;
#endif
}