/home/cern/BDSIM_new/src/BDSRfCavity.cc

00001 #include "BDSGlobalConstants.hh" // must be first in include list
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 extern BDSMaterials* theMaterials;
00029 //============================================================
00030 
00031 BDSRfCavity::BDSRfCavity (G4String aName,G4double aLength, G4double bpRad, 
00032                           G4double grad, G4String aMaterial):
00033   BDSMultipole(aName ,aLength, bpRad, bpRad, SetVisAttributes(), aMaterial)
00034 {
00035   itsGrad = grad;
00036   itsType = "rfcavity";
00037 
00038   if (!(*LogVolCount)[itsName])
00039     {
00040       //
00041       // build external volume
00042       // 
00043       BuildDefaultMarkerLogicalVolume();
00044 
00045       //
00046       // build beampipe (geometry + magnetic field)
00047       //
00048       itsBPFieldMgr=NULL;
00049       BuildBeampipe(itsLength);
00050 
00051       //
00052       // build cavity (geometry + electric field)
00053       //
00054       BuildDefaultOuterLogicalVolume(itsLength);
00055 
00056       //
00057       // define sensitive volumes for hit generation
00058       //
00059       SetSensitiveVolume(itsBeampipeLogicalVolume);// for laserwire
00060       //SetSensitiveVolume(itsOuterLogicalVolume);// for laserwire
00061 
00062       //
00063       // set visualization attributes
00064       //
00065       itsVisAttributes=SetVisAttributes();
00066       itsVisAttributes->SetForceSolid(true);
00067       itsOuterLogicalVolume->SetVisAttributes(itsVisAttributes);
00068 
00069       //
00070       // append marker logical volume to volume map
00071       //
00072       (*LogVolCount)[itsName]=1;
00073       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00074       BuildMarkerFieldAndStepper();
00075     }
00076   else
00077     {
00078       (*LogVolCount)[itsName]++;
00079       itsMarkerLogicalVolume=(*LogVol)[itsName];
00080     }
00081 }
00082 
00083 
00084 G4VisAttributes* BDSRfCavity::SetVisAttributes()
00085 {
00086   itsVisAttributes=new G4VisAttributes(G4Colour(0.25,0.25,0.5));
00087   return itsVisAttributes;
00088 }
00089 
00090 
00091 void BDSRfCavity::BuildMarkerFieldAndStepper()
00092 {
00093 
00094   G4int nvar = 8;
00095 
00096   // set up the magnetic field and stepper
00097   G4ThreeVector Efield(0.,0.,itsGrad * megavolt / m);
00098   itsField=new G4UniformElectricField(Efield);
00099 
00100   G4EqMagElectricField* fEquation = new G4EqMagElectricField(itsField);
00101 
00102   fieldManager = new G4FieldManager();
00103   
00104   fStepper = new G4ExplicitEuler( fEquation, nvar );
00105   //itsStepper = new G4ClassicalRK4( fEquation, nvar );
00106 
00107   G4double fMinStep     = BDSGlobals->GetChordStepMinimum();
00108  
00109 
00110   fieldManager->SetDetectorField(itsField );
00111 
00112   if(fChordFinder) delete fChordFinder;
00113 
00114   fIntgrDriver = new G4MagInt_Driver(fMinStep,
00115                                      fStepper,
00116                                      fStepper->GetNumberOfVariables() );
00117   
00118   fChordFinder = new G4ChordFinder(fIntgrDriver);
00119 
00120   fChordFinder->SetDeltaChord(BDSGlobals->GetDeltaChord());
00121   fieldManager->SetChordFinder( fChordFinder );
00122 
00123 
00124   itsInnerBPLogicalVolume->SetFieldManager(fieldManager,false);
00125 
00126 }
00127 
00128 
00129 BDSRfCavity::~BDSRfCavity()
00130 {
00131   if(itsVisAttributes) delete itsVisAttributes;
00132   if(itsMarkerLogicalVolume) delete itsMarkerLogicalVolume;
00133   if(itsOuterLogicalVolume) delete itsOuterLogicalVolume;
00134   if(itsPhysiComp) delete itsPhysiComp;
00135   if(itsField) delete itsField;
00136   //if(itsEqRhs) delete itsEqRhs;
00137   if(itsStepper) delete itsStepper;
00138 }

Generated on Wed Mar 5 17:25:22 2008 for BDSIM by  doxygen 1.5.3