/home/cern/BDSIM_new/src/BDSSkewSextupole.cc

00001 /* BDSIM code.    Version 1.0
00002    Author: Grahame A. Blair, Royal Holloway, Univ. of London.
00003    Last modified 24.7.2002
00004    Copyright (c) 2002 by G.A.Blair.  ALL RIGHTS RESERVED. 
00005 
00006    Modified 22.03.05 by J.C.Carter, Royal Holloway, Univ. of London.
00007    Changed StringFromInt to BDSGlobals version
00008 */
00009 #include "BDSGlobalConstants.hh" // must be first in include list
00010 
00011 #include "BDSSkewSextupole.hh"
00012 #include "G4Box.hh"
00013 #include "G4Tubs.hh"
00014 #include "G4VisAttributes.hh"
00015 #include "G4LogicalVolume.hh"
00016 #include "G4VPhysicalVolume.hh"
00017 #include "G4UserLimits.hh"
00018 #include "G4TransportationManager.hh"
00019 
00020 #include <map>
00021 
00022 //============================================================
00023 
00024 typedef std::map<G4String,int> LogVolCountMap;
00025 extern LogVolCountMap* LogVolCount;
00026 
00027 typedef std::map<G4String,G4LogicalVolume*> LogVolMap;
00028 extern LogVolMap* LogVol;
00029 
00030 extern BDSMaterials* theMaterials;
00031 //============================================================
00032 
00033 BDSSkewSextupole::BDSSkewSextupole(G4String& aName,G4double aLength, 
00034                                    G4double bpRad,G4double FeRad,
00035                                    G4double BDblPrime):
00036   BDSMultipole(aName,aLength, bpRad, FeRad,SetVisAttributes()),
00037   itsBDblPrime(BDblPrime)
00038 {
00039   if (!(*LogVolCount)[itsName])
00040     {
00041       BuildBPFieldAndStepper();
00042       BuildBPFieldMgr(itsStepper,itsMagField);
00043       BuildDefaultMarkerLogicalVolume();
00044 
00045       BuildBeampipe(itsLength);
00046 
00047       BuildDefaultOuterLogicalVolume(itsLength);
00048 
00049       SetSensitiveVolume(itsBeampipeLogicalVolume);// for synchrotron
00050       //SetSensitiveVolume(itsOuterLogicalVolume);// for laserwire
00051 
00052       if(BDSGlobals->GetIncludeIronMagFields())
00053         {
00054           G4double polePos[4];
00055           G4double Bfield[3];
00056 
00057           polePos[0]=-BDSGlobals->GetMagnetPoleRadius()*sin(pi/6);
00058           polePos[1]=BDSGlobals->GetMagnetPoleRadius()*cos(pi/6);
00059           polePos[2]=0.;
00060           polePos[3]=-999.;//flag to use polePos rather than local track
00061                            //coordinate in GetFieldValue            
00062             
00063           itsMagField->GetFieldValue(polePos,Bfield);
00064           G4double BFldIron=
00065             sqrt(Bfield[0]*Bfield[0]+Bfield[1]*Bfield[1])*
00066             BDSGlobals->GetMagnetPoleSize()/
00067             (BDSGlobals->GetComponentBoxSize()/2-
00068              BDSGlobals->GetMagnetPoleRadius());
00069           // Magnetic flux from a pole is divided in two directions
00070           BFldIron/=2.;
00071 
00072           BuildOuterFieldManager(6, BFldIron,pi/6);
00073         }
00074 
00075 
00076       (*LogVolCount)[itsName]=1;
00077       (*LogVol)[itsName]=itsMarkerLogicalVolume;
00078     }
00079   else
00080     {
00081       (*LogVolCount)[itsName]++;
00082       if(BDSGlobals->GetSynchRadOn()&& BDSGlobals->GetSynchRescale())
00083         {
00084           // with synchrotron radiation, the rescaled magnetic field
00085           // means elements with the same name must have different
00086           //logical volumes, becuase they have different fields
00087           itsName+=BDSGlobals->StringFromInt((*LogVolCount)[itsName]);
00088           BuildBPFieldAndStepper();
00089           BuildBPFieldMgr(itsStepper,itsMagField);
00090           BuildDefaultMarkerLogicalVolume();
00091           
00092           BuildBeampipe(itsLength);
00093           BuildDefaultOuterLogicalVolume(itsLength);
00094 
00095           SetSensitiveVolume(itsBeampipeLogicalVolume);// for synchrotron
00096           //SetSensitiveVolume(itsOuterLogicalVolume);// for laserwire      
00097           (*LogVol)[itsName]=itsMarkerLogicalVolume;
00098         }
00099       else
00100         {
00101           itsMarkerLogicalVolume=(*LogVol)[itsName];
00102         }      
00103     }
00104   
00105 }
00106 
00107 
00108 G4VisAttributes* BDSSkewSextupole::SetVisAttributes()
00109 {
00110   itsVisAttributes=new G4VisAttributes(G4Colour(1,1,0));
00111   return itsVisAttributes;
00112 }
00113 
00114 
00115 void BDSSkewSextupole::BuildBPFieldAndStepper()
00116 {
00117   // set up the magnetic field and stepper
00118   itsMagField=new BDSSkewSextMagField(itsBDblPrime);
00119   itsEqRhs=new G4Mag_UsualEqRhs(itsMagField);
00120   
00121   itsStepper=new BDSSkewSextStepper(itsEqRhs);
00122   itsStepper->SetBDblPrime(itsBDblPrime);
00123 
00124 }
00125 
00126 BDSSkewSextupole::~BDSSkewSextupole()
00127 {
00128   delete itsVisAttributes;
00129   delete itsMarkerLogicalVolume;
00130   delete itsOuterLogicalVolume;
00131   delete itsPhysiComp;
00132   delete itsMagField;
00133   delete itsEqRhs;
00134   delete itsStepper;
00135 }

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