/scratch0/jsnuveri/BDSIM/BDSIMgit/bdsim/src/BDSKicker.cc

00001 #include "BDSGlobalConstants.hh" 
00002 #include "BDSKicker.hh"
00003 
00004 #include "BDSBeamPipeFactory.hh"
00005 #include "BDSDipoleStepper.hh"
00006 #include "BDSMagnet.hh"
00007 #include "BDSMagnetOuterInfo.hh"
00008 #include "BDSMagnetType.hh"
00009 #include "BDSSbendMagField.hh"
00010 
00011 #include "G4FieldManager.hh"
00012 #include "G4LogicalVolume.hh"
00013 #include "G4Mag_UsualEqRhs.hh"
00014 #include "G4UserLimits.hh"
00015 #include "G4VisAttributes.hh"
00016 #include "G4VPhysicalVolume.hh"
00017 #include "G4PVPlacement.hh"
00018 
00019 class BDSTiltOffset;
00020 
00021 BDSKicker::BDSKicker(G4String           name,
00022                      G4double           length,
00023                      G4double           bField,
00024                      G4double           bGrad,
00025                      G4double           angle,
00026                      G4bool             verticalKicker,
00027                      BDSBeamPipeInfo*   beamPipeInfo,
00028                      BDSMagnetOuterInfo magnetOuterInfo,
00029                      BDSTiltOffset      tiltOffset):
00030   BDSMagnet(BDSMagnetType::hkicker, name, length,
00031             beamPipeInfo, magnetOuterInfo, tiltOffset),
00032   itsBField(bField),
00033   itsBGrad(bGrad),
00034   itsKickAngle(angle),
00035   isVerticalKicker(verticalKicker)
00036 {
00037   if (verticalKicker)
00038     {itsType = BDSMagnetType::vkicker;}
00039 }
00040 
00041 void BDSKicker::Build()
00042 {
00043   BDSMagnet::Build();
00044   if(BDSGlobalConstants::Instance()->GetIncludeIronMagFields())
00045     {
00046       G4double polePos[4];
00047       G4double Bfield[3];
00048       
00049       //coordinate in GetFieldValue
00050       polePos[0]=0.;
00051       polePos[1]=BDSGlobalConstants::Instance()->GetMagnetPoleRadius();
00052       polePos[2]=0.;
00053       polePos[3]=-999.;//flag to use polePos rather than local track
00054       
00055       itsMagField->GetFieldValue(polePos,Bfield);
00056       G4double BFldIron=
00057         sqrt(Bfield[0]*Bfield[0]+Bfield[1]*Bfield[1])*
00058         BDSGlobalConstants::Instance()->GetMagnetPoleSize()/
00059         (BDSGlobalConstants::Instance()->GetComponentBoxSize()/2-
00060          BDSGlobalConstants::Instance()->GetMagnetPoleRadius());
00061       
00062       // Magnetic flux from a pole is divided in two directions
00063       BFldIron/=2.;
00064       
00065       BuildOuterFieldManager(2, BFldIron,0);
00066     }
00067 }
00068 
00069 void BDSKicker::BuildBeampipe()
00070 {
00071   // have to distinguish if it's a vertical or horizontal kicker
00072   // but without rotating the aperture model - ie input parameters aper1
00073   // still represents horizontal
00074 
00075   G4double kickerAper1, kickerAper2;
00076   if (isVerticalKicker)
00077     {
00078       kickerAper1 = beamPipeInfo->aper2; //vertical is rotated in the end during placement
00079       kickerAper2 = beamPipeInfo->aper1; //so build aperture otherway - sway 1,2 - x,y
00080     }
00081   else
00082     {
00083       kickerAper1 = beamPipeInfo->aper1;
00084       kickerAper2 = beamPipeInfo->aper2;
00085     }
00086   
00087   beampipe =
00088     BDSBeamPipeFactory::Instance()->CreateBeamPipe(beamPipeInfo->beamPipeType,
00089                                                    name,
00090                                                    chordLength,
00091                                                    kickerAper1,
00092                                                    kickerAper2,
00093                                                    beamPipeInfo->aper3,
00094                                                    beamPipeInfo->aper4,
00095                                                    beamPipeInfo->vacuumMaterial,
00096                                                    beamPipeInfo->beamPipeThickness,
00097                                                    beamPipeInfo->beamPipeMaterial);
00098 
00099   //manually do BeamPipeCommonTasks here as rotation in placement can be different
00100 
00101   // SET FIELD
00102   beampipe->GetVacuumLogicalVolume()->SetFieldManager(itsBPFieldMgr,false);
00103 
00104   // register logical volumes using geometry component base class
00105   RegisterLogicalVolumes(beampipe->GetAllLogicalVolumes());
00106 
00107   if(BDSGlobalConstants::Instance()->GetSensitiveBeamPipe())
00108     {RegisterSensitiveVolumes(beampipe->GetAllSensitiveVolumes());}
00109 
00110   // if it's a vertical kicker, rotate the beam pipe by 90 degrees
00111   // this also rotates the dipole stepper in the vacuum volume
00112   G4RotationMatrix* kickerRotation = new G4RotationMatrix();
00113   if (isVerticalKicker)
00114     {kickerRotation->rotateZ(CLHEP::pi*0.5);}
00115 
00116   // place beampipe
00117   itsPhysiComp = new G4PVPlacement(kickerRotation,                        // rotation
00118                                    (G4ThreeVector)0,                      // at (0,0,0)
00119                                    beampipe->GetContainerLogicalVolume(), // its logical volume
00120                                    name + "_beampipe_pv",                 // its name
00121                                    containerLogicalVolume,                // its mother  volume
00122                                    false,                                 // no boolean operation
00123                                    0, BDSGlobalConstants::Instance()->GetCheckOverlaps());// copy number
00124 
00125   // record extent of geometry
00126   if (isVerticalKicker){
00127     SetExtentX(beampipe->GetExtentY());
00128     SetExtentY(beampipe->GetExtentX());
00129   }
00130   else {
00131     SetExtentX(beampipe->GetExtentX());
00132     SetExtentY(beampipe->GetExtentY());
00133   }
00134   SetExtentZ(beampipe->GetExtentZ());
00135 } 
00136 
00137 void BDSKicker::BuildBPFieldAndStepper()
00138 {
00139   // set up the magnetic field and stepper
00140   G4ThreeVector Bfield(0.,-itsBField,0.); // note the - sign...
00141   itsMagField=new BDSSbendMagField(Bfield,chordLength,itsKickAngle);
00142   
00143   itsEqRhs=new G4Mag_UsualEqRhs(itsMagField);  
00144   
00145   BDSDipoleStepper* dipoleStepper = new BDSDipoleStepper(itsEqRhs);
00146   dipoleStepper->SetBField(-itsBField); // note the - sign...
00147   dipoleStepper->SetBGrad(itsBGrad);
00148   itsStepper = dipoleStepper;
00149 }

Generated on 28 Jun 2015 for BDSIM by  doxygen 1.4.7