00001 #include "BDSGlobalConstants.hh"
00002
00003 #include "BDSRfCavity.hh"
00004 #include "G4Box.hh"
00005 #include "G4Tubs.hh"
00006 #include "G4VisAttributes.hh"
00007 #include "G4LogicalVolume.hh"
00008 #include "G4VPhysicalVolume.hh"
00009 #include "G4UserLimits.hh"
00010 #include "G4TransportationManager.hh"
00011
00012
00013 #include "G4MagIntegratorDriver.hh"
00014
00015 #include "G4ExplicitEuler.hh"
00016
00017
00018 #include <map>
00019
00020
00021
00022 typedef std::map<G4String,int> LogVolCountMap;
00023 extern LogVolCountMap* LogVolCount;
00024
00025 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00026 extern LogVolMap* LogVol;
00027
00028
00029
00030 BDSRfCavity::BDSRfCavity (G4String aName,G4double aLength, G4double bpRad,
00031 G4double grad, G4String aTunnelMaterial, G4String aMaterial):
00032 BDSMultipole(aName ,aLength, bpRad, bpRad, SetVisAttributes(), aTunnelMaterial, aMaterial),
00033 itsStepper(NULL),itsField(NULL),fChordFinder(NULL),fStepper(NULL),fIntgrDriver(NULL),fieldManager(NULL)
00034 {
00035 itsGrad = grad;
00036 itsType = "rfcavity";
00037
00038 if (!(*LogVolCount)[itsName])
00039 {
00040
00041
00042
00043 BuildDefaultMarkerLogicalVolume();
00044
00045
00046
00047
00048 itsBPFieldMgr=NULL;
00049 BuildBeampipe();
00050
00051
00052
00053
00054 BuildDefaultOuterLogicalVolume(itsLength);
00055
00056
00057
00058
00059 if(BDSGlobalConstants::Instance()->GetSensitiveComponents()){
00060 SetMultipleSensitiveVolumes(itsOuterLogicalVolume);
00061 }
00062
00063
00064
00065
00066 itsVisAttributes=SetVisAttributes();
00067 itsVisAttributes->SetForceSolid(true);
00068 itsOuterLogicalVolume->SetVisAttributes(itsVisAttributes);
00069
00070
00071
00072
00073 (*LogVolCount)[itsName]=1;
00074 (*LogVol)[itsName]=itsMarkerLogicalVolume;
00075 BuildMarkerFieldAndStepper();
00076 }
00077 else
00078 {
00079 (*LogVolCount)[itsName]++;
00080 itsMarkerLogicalVolume=(*LogVol)[itsName];
00081 }
00082 }
00083
00084
00085 G4VisAttributes* BDSRfCavity::SetVisAttributes()
00086 {
00087 itsVisAttributes=new G4VisAttributes(G4Colour(0.25,0.25,0.5));
00088 return itsVisAttributes;
00089 }
00090
00091
00092 void BDSRfCavity::BuildMarkerFieldAndStepper()
00093 {
00094
00095 G4int nvar = 8;
00096
00097
00098 G4ThreeVector Efield(0.,0.,itsGrad * megavolt / m);
00099 itsField=new G4UniformElectricField(Efield);
00100
00101 G4EqMagElectricField* fEquation = new G4EqMagElectricField(itsField);
00102
00103 fieldManager = new G4FieldManager();
00104
00105 fStepper = new G4ExplicitEuler( fEquation, nvar );
00106
00107
00108 G4double fMinStep = BDSGlobalConstants::Instance()->GetChordStepMinimum();
00109
00110
00111 fieldManager->SetDetectorField(itsField );
00112
00113 delete fChordFinder;
00114
00115 fIntgrDriver = new G4MagInt_Driver(fMinStep,
00116 fStepper,
00117 fStepper->GetNumberOfVariables() );
00118
00119 fChordFinder = new G4ChordFinder(fIntgrDriver);
00120
00121 fChordFinder->SetDeltaChord(BDSGlobalConstants::Instance()->GetDeltaChord());
00122 fieldManager->SetChordFinder( fChordFinder );
00123
00124
00125 itsInnerBPLogicalVolume->SetFieldManager(fieldManager,false);
00126
00127 }
00128
00129
00130 BDSRfCavity::~BDSRfCavity()
00131 {
00132 delete itsVisAttributes;
00133 delete itsField;
00134 delete itsStepper;
00135 }