00001
00002
00003
00004
00005 #include "BDSGlobalConstants.hh"
00006 #include "BDSCollimator.hh"
00007 #include "G4VisAttributes.hh"
00008 #include "G4LogicalVolume.hh"
00009 #include "G4VPhysicalVolume.hh"
00010 #include "G4PVPlacement.hh"
00011 #include "G4UserLimits.hh"
00012 #include "G4TransportationManager.hh"
00013
00014 #include "G4SDManager.hh"
00015 #include "G4UserLimits.hh"
00016 #include "parser/gmad.h"
00017 #include <map>
00018
00019
00020
00021
00022
00023 typedef std::map<G4String,int> LogVolCountMap;
00024 extern LogVolCountMap* LogVolCount;
00025
00026 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00027 extern LogVolMap* LogVol;
00028
00029 extern BDSMaterials* theMaterials;
00030
00031
00032 BDSCollimator::BDSCollimator (G4String aName,G4double aLength,G4double bpRad,
00033 G4double xAper,G4double yAper, G4int type,
00034 G4Material *CollimatorMaterial, G4double outR):
00035 BDSAcceleratorComponent(aName,
00036 aLength,bpRad,xAper,yAper,
00037 SetVisAttributes()),
00038 itsCollimatorMaterial(CollimatorMaterial), itsOuterR(outR)
00039 {
00040 if(type==_RCOL) itsType="rcol";
00041 if(type==_ECOL) itsType="ecol";
00042 if ( (*LogVolCount)[itsName]==0)
00043 {
00044 itsMarkerLogicalVolume=
00045 new G4LogicalVolume(
00046 new G4Box(itsName,
00047 BDSGlobals->GetComponentBoxSize()/2,
00048 BDSGlobals->GetComponentBoxSize()/2,
00049 itsLength/2),
00050 theMaterials->GetMaterial("Vacuum"),
00051 itsName);
00052 BuildInnerCollimator();
00053
00054 itsSolidLogVol->SetVisAttributes(SetVisAttributes());
00055
00056
00057 G4VisAttributes* VisAtt1 =
00058 new G4VisAttributes(G4Colour(0., 0., 0.));
00059 VisAtt1->SetForceSolid(true);
00060 itsInnerLogVol->SetVisAttributes(VisAtt1);
00061
00062 (*LogVolCount)[itsName]=1;
00063 (*LogVol)[itsName]=itsMarkerLogicalVolume;
00064 }
00065 else
00066 {
00067 (*LogVolCount)[itsName]++;
00068 itsMarkerLogicalVolume=(*LogVol)[itsName];
00069 }
00070 }
00071
00072
00073 G4VisAttributes* BDSCollimator::SetVisAttributes()
00074 {
00075 itsVisAttributes=new G4VisAttributes(G4Colour(0.3,0.4,0.2));
00076 itsVisAttributes->SetForceSolid(true);
00077 return itsVisAttributes;
00078 }
00079
00080
00081 void BDSCollimator::BuildInnerCollimator()
00082 {
00083
00084
00085
00086 if(itsXAper <= 0) itsXAper = BDSGlobals->GetComponentBoxSize()/2;
00087 if(itsYAper <= 0) itsYAper = BDSGlobals->GetComponentBoxSize()/2;
00088
00089 if(itsOuterR==0) itsOuterR = BDSGlobals->GetComponentBoxSize()/2;
00090
00091 itsSolidLogVol=
00092 new G4LogicalVolume(new G4Box(itsName+"_solid",
00093 itsOuterR,
00094 itsOuterR,
00095 itsLength/2),
00096
00097 itsCollimatorMaterial,
00098 itsName+"_solid");
00099
00100 if(itsType == "rcol")
00101 {
00102 itsInnerLogVol=
00103 new G4LogicalVolume(new G4Box(itsName+"_inner",
00104 itsXAper,
00105 itsYAper,
00106 itsLength/2),
00107 theMaterials->GetMaterial("Vacuum"),
00108 itsName+"_inner");
00109 }
00110
00111 if(itsType == "ecol")
00112 {
00113 itsInnerLogVol=
00114 new G4LogicalVolume(new G4EllipticalTube(itsName+"_inner",
00115 itsXAper,
00116 itsYAper,
00117 itsLength/2),
00118 theMaterials->GetMaterial("Vacuum"),
00119 itsName+"_inner");
00120 }
00121
00122 itsPhysiComp2 =
00123 new G4PVPlacement(
00124 0,
00125 0,
00126 itsInnerLogVol,
00127 itsName+"_combined",
00128 itsSolidLogVol,
00129 false,
00130 0);
00131
00132 SetSensitiveVolume(itsSolidLogVol);
00133
00134 itsSolidLogVol->
00135 SetUserLimits(new G4UserLimits(DBL_MAX,DBL_MAX,DBL_MAX,
00136 BDSGlobals-> GetThresholdCutCharged()));
00137
00138 itsPhysiComp =
00139 new G4PVPlacement(
00140 0,
00141 0,
00142 itsSolidLogVol,
00143 itsName+"_solid",
00144 itsMarkerLogicalVolume,
00145 false,
00146 0);
00147 }
00148
00149
00150 BDSCollimator::~BDSCollimator()
00151 {
00152 if(itsVisAttributes) delete itsVisAttributes;
00153 if(itsUserLimits) delete itsUserLimits;
00154
00155 if(itsMarkerLogicalVolume)delete itsMarkerLogicalVolume;
00156 if(itsSolidLogVol)delete itsSolidLogVol;
00157 if(itsInnerLogVol)delete itsInnerLogVol;
00158
00159 if(itsPhysiComp) delete itsPhysiComp;
00160 if(itsPhysiComp2) delete itsPhysiComp2;
00161 }