00001 #include "BDSDebug.hh"
00002 #include "BDSGlobalConstants.hh"
00003 #include "BDSCollimatorBase.hh"
00004 #include "BDSMaterials.hh"
00005 #include "BDSUtilities.hh"
00006
00007 #include "G4Box.hh"
00008 #include "G4VisAttributes.hh"
00009 #include "G4LogicalVolume.hh"
00010 #include "G4PVPlacement.hh"
00011 #include "G4SubtractionSolid.hh"
00012 #include "G4UserLimits.hh"
00013
00014 #include <map>
00015
00016 class BDSTiltOffset;
00017
00018 BDSCollimatorBase::BDSCollimatorBase(G4String name,
00019 G4double length,
00020 G4double outerDiameterIn,
00021 G4String type,
00022 G4double xApertureIn,
00023 G4double yApertureIn,
00024 G4String collimatorMaterialIn,
00025 G4String vacuumMaterialIn,
00026 BDSTiltOffset tiltOffset):
00027 BDSAcceleratorComponent(name, length, 0, type, tiltOffset),
00028 outerDiameter(outerDiameterIn),
00029 xAperture(xApertureIn),
00030 yAperture(yApertureIn),
00031 collimatorMaterial(collimatorMaterialIn),
00032 vacuumMaterial(vacuumMaterialIn)
00033 {
00034 if(outerDiameter==0)
00035 {outerDiameter = BDSGlobalConstants::Instance()->GetOuterDiameter();}
00036
00037 if ( (xAperture > 0.5*outerDiameter) || (yAperture > 0.5*outerDiameter) )
00038 {
00039 G4cerr << __METHOD_NAME__ << "half aperture bigger than diameter!" << G4endl;
00040 G4cerr << "Outer diameter is " << outerDiameter << " mm for component named: \""
00041 << name << "\"" << G4endl;
00042 exit(1);
00043 }
00044
00045 if (collimatorMaterialIn == "")
00046 {
00047 G4cout << __METHOD_NAME__ << "Warning - no material set for collimator - using copper" << G4endl;
00048 collimatorMaterial = "Copper";
00049 }
00050
00051 collimatorSolid = NULL;
00052 }
00053
00054 void BDSCollimatorBase::BuildContainerLogicalVolume()
00055 {
00056 containerSolid = new G4Box(name + "_container_solid",
00057 outerDiameter*0.5,
00058 outerDiameter*0.5,
00059 chordLength*0.5);
00060
00061 containerLogicalVolume = new G4LogicalVolume(containerSolid,
00062 emptyMaterial,
00063 name + "_container_lv");
00064 }
00065
00066 void BDSCollimatorBase::Build()
00067 {
00068 BDSAcceleratorComponent::Build();
00069
00070
00071 G4VSolid* outerSolid = new G4Box(name + "_outer_solid",
00072 outerDiameter * 0.5 - lengthSafety,
00073 outerDiameter * 0.5 - lengthSafety,
00074 chordLength*0.5 - lengthSafety);
00075
00076
00077 G4bool buildVacuumAndAperture = (BDS::IsFinite(xAperture) && BDS::IsFinite(yAperture));
00078 if(buildVacuumAndAperture)
00079 {
00080 BuildInnerCollimator();
00081
00082 collimatorSolid = new G4SubtractionSolid(name + "_collimator_solid",
00083 outerSolid,
00084 innerSolid);
00085 }
00086 else
00087 {collimatorSolid = outerSolid;}
00088
00089 G4Material* material = BDSMaterials::Instance()->GetMaterial(collimatorMaterial);
00090 G4LogicalVolume* collimatorLV = new G4LogicalVolume(collimatorSolid,
00091 material,
00092 name + "_collimator_lv");
00093
00094
00095 G4VisAttributes* collimatorVisAttr = new G4VisAttributes(G4Colour(0.3,0.4,0.2));
00096 collimatorLV->SetVisAttributes(collimatorVisAttr);
00097
00098 #ifndef NOUSERLIMITS
00099 collimatorLV->SetUserLimits(BDSGlobalConstants::Instance()->GetDefaultUserLimits());
00100 #endif
00101
00102
00103 RegisterLogicalVolume(collimatorLV);
00104 RegisterSensitiveVolume(collimatorLV);
00105
00106 new G4PVPlacement(0,
00107 (G4ThreeVector)0,
00108 collimatorLV,
00109 name + "_collimator_pv",
00110 containerLogicalVolume,
00111 false,
00112 0,
00113 BDSGlobalConstants::Instance()->GetCheckOverlaps());
00114
00115 if (buildVacuumAndAperture)
00116 {
00117 G4Material* vMaterial = BDSMaterials::Instance()->GetMaterial(vacuumMaterial);
00118 G4LogicalVolume* vacuumLV = new G4LogicalVolume(vacuumSolid,
00119 vMaterial,
00120 name + "_vacuum_lv");
00121
00122 vacuumLV->SetVisAttributes(BDSGlobalConstants::Instance()->GetInvisibleVisAttr());
00123 RegisterLogicalVolume(vacuumLV);
00124 #ifndef NOUSERLIMITS
00125 vacuumLV->SetUserLimits(BDSGlobalConstants::Instance()->GetDefaultUserLimits());
00126 #endif
00127
00128 new G4PVPlacement(0,
00129 (G4ThreeVector)0,
00130 vacuumLV,
00131 name + "_vacuum_pv",
00132 containerLogicalVolume,
00133 false,
00134 0,
00135 BDSGlobalConstants::Instance()->GetCheckOverlaps());
00136 }
00137 }
00138
00139 BDSCollimatorBase::~BDSCollimatorBase()
00140 {;}
00141